Generate crack textures dynamically on the texture atlas,

Note: Atlas does not discard unused textures yet.
master
aurailus 2019-05-01 14:49:39 -07:00
parent 84cff00a3c
commit 20a9eaa298
18 changed files with 294 additions and 234 deletions

View File

@ -3,13 +3,10 @@ set (CMAKE_CXX_STANDARD 14)
set (PROJECT_NAME "Zeus")
#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,undefined")
#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-recover=address")
project (${PROJECT_NAME})
#Include all of the library headers
#This should be refactored in the future to use a GLOB with standardized folders
include_directories (
lib/glew/include/GL
lib/glfw_linux/include
@ -24,26 +21,23 @@ include_directories (
)
#Include all of the dynamic libraries
set (ZEUS_LIBRARIES
${OPENGL_gl_LIBRARY} #opengl
glfw #glfw
libGLEW.so #glew
pthread #std::thread
lua #sol2
dl z #gzip
enet #enet
noise #libnoise
${OPENGL_gl_LIBRARY} #opengl
glfw #glfw
libGLEW.so #glew
pthread #std::thread
lua #sol2
dl z #gzip
enet #enet
noise #libnoise
)
#Include 'Packages', I don't understand how this works
find_package (OpenGL REQUIRED)
find_package (glfw3 REQUIRED)
link_directories (lib/glew/lib)
#Configure Main Executable
add_subdirectory(src)
set(MAIN_EXEC_NAME "ZeusApp")
@ -53,7 +47,6 @@ target_link_libraries(${MAIN_EXEC_NAME} zeusCore)
target_link_libraries(${MAIN_EXEC_NAME} ${ZEUS_LIBRARIES})
#Configure Test Executable
add_subdirectory(test)
set(TEST_EXEC_NAME "ZeusTest")

View File

@ -1,126 +1,131 @@
set(ZEUS_SRC_FILES
game/graph/Mesh.cpp
game/graph/Mesh.h
game/entity/Entity.cpp
game/entity/Entity.h
game/graph/Shader.cpp
game/graph/Shader.h
game/graph/window/Window.cpp
game/graph/window/Window.h
game/graph/Camera.cpp
game/graph/Camera.h
game/graph/Texture.cpp
game/graph/Texture.h
game/scene/world/graph/MeshGenerator.cpp
game/scene/world/graph/MeshGenerator.h
util/Timer.cpp
util/Timer.h
def/block/BlockAtlas.cpp
def/block/BlockAtlas.h
def/block/BlockDef.cpp
def/block/BlockDef.h
def/block/graph/MeshPart.cpp
def/block/graph/MeshPart.h
def/block/graph/MeshMod.h
game/scene/world/graph/MeshVertex.h
def/block/graph/BlockModel.cpp
def/block/graph/BlockModel.h
game/scene/world/LocalWorld.cpp
game/scene/world/LocalWorld.h
world/chunk/BlockChunk.cpp
world/chunk/BlockChunk.h
game/scene/world/graph/MeshChunk.cpp
game/scene/world/graph/MeshChunk.h
game/scene/GameScene.cpp
game/scene/GameScene.h
game/graph/Renderer.cpp
game/graph/Renderer.h
api/LuaApi.cpp
api/LuaApi.h
api/func/LModuleRegister.cpp
api/func/LModuleRegister.h
game/entity/hud/TextEntity.cpp
game/entity/hud/TextEntity.h
game/entity/hud/DebugGui.cpp
game/entity/hud/DebugGui.h
game/scene/world/Player.cpp
game/scene/world/Player.h
util/Ray.cpp
util/Ray.h
game/Game.cpp
game/Game.h
game/graph/scene/SceneManager.cpp
game/graph/scene/SceneManager.h
game/graph/scene/Scene.h
game/ClientState.h
game/scene/MenuScene.cpp
game/scene/MenuScene.h
server/Server.cpp
server/Server.h
util/net/Packet.cpp
util/net/Packet.h
server/player/ServerPlayer.cpp
server/player/ServerPlayer.h
game/scene/net/ServerConnection.cpp
game/scene/net/ServerConnection.h
def/gen/MapGen.cpp
def/gen/MapGen.h
util/net/NetHandler.cpp
util/net/NetHandler.h
game/entity/hud/GameGui.cpp
game/entity/hud/GameGui.h
util/net/Serializer.cpp
util/net/Serializer.h
server/conn/ConnectionList.cpp
server/conn/ConnectionList.h
server/conn/ServerPeer.h
util/net/PacketChannel.h
game/entity/world/PlayerEntity.cpp
game/entity/world/PlayerEntity.h
game/entity/hud/GraphEntity.cpp
game/entity/hud/GraphEntity.h
game/entity/hud/TextureRect.cpp
game/entity/hud/TextureRect.h
def/gen/MapGenJob.h
util/Interp.h
def/gen/NoiseSample.cpp
def/gen/NoiseSample.h
game/graph/frustum/Frustum.cpp
game/graph/frustum/Frustum.h
game/graph/frustum/FrustumPlane.cpp
game/graph/frustum/FrustumPlane.h
game/graph/frustum/FrustumAABB.cpp
game/graph/frustum/FrustumAABB.h
server/world/ServerWorld.cpp
server/world/ServerWorld.h
server/world/WorldGenStream.cpp
server/world/WorldGenStream.h
game/scene/world/WorldInterpolationStream.cpp
game/scene/world/WorldInterpolationStream.h
util/TransPos.h
game/scene/world/MeshGenStream.cpp
game/scene/world/MeshGenStream.h
util/Vec.h
world/Dimension.cpp
world/Dimension.h
world/region/Region.h
game/entity/world/WireframeEntity.cpp
game/entity/world/WireframeEntity.h
def/block/graph/SelectionBox.h
game/graph/drawable/Drawable.h
game/graph/drawable/DrawableGroup.cpp
game/graph/drawable/DrawableGroup.h
game/graph/window/InputManager.cpp
game/graph/window/InputManager.h
game/entity/world/BlockModelEntity.cpp
game/entity/world/BlockModelEntity.h
def/texture/TextureAtlas.cpp
def/texture/TextureAtlas.h
def/texture/AtlasRef.cpp
def/texture/AtlasRef.h
world/region/MapBlock.h def/GameDefs.cpp
def/GameDefs.h
api/func/LModuleUtil.cpp
api/func/LModuleUtil.h world/region/Region.cpp world/region/MapBlock.cpp game/entity/hud/StatGraph.cpp game/entity/hud/StatGraph.h util/Util.h)
game/graph/Mesh.cpp
game/graph/Mesh.h
game/entity/Entity.cpp
game/entity/Entity.h
game/graph/Shader.cpp
game/graph/Shader.h
game/graph/window/Window.cpp
game/graph/window/Window.h
game/graph/Camera.cpp
game/graph/Camera.h
game/graph/Texture.cpp
game/graph/Texture.h
game/scene/world/graph/MeshGenerator.cpp
game/scene/world/graph/MeshGenerator.h
util/Timer.cpp
util/Timer.h
def/block/BlockAtlas.cpp
def/block/BlockAtlas.h
def/block/BlockDef.cpp
def/block/BlockDef.h
def/block/graph/MeshPart.cpp
def/block/graph/MeshPart.h
def/block/graph/MeshMod.h
game/scene/world/graph/MeshVertex.h
def/block/graph/BlockModel.cpp
def/block/graph/BlockModel.h
game/scene/world/LocalWorld.cpp
game/scene/world/LocalWorld.h
world/chunk/BlockChunk.cpp
world/chunk/BlockChunk.h
game/scene/world/graph/MeshChunk.cpp
game/scene/world/graph/MeshChunk.h
game/scene/GameScene.cpp
game/scene/GameScene.h
game/graph/Renderer.cpp
game/graph/Renderer.h
api/LuaApi.cpp
api/LuaApi.h
api/func/LModuleRegister.cpp
api/func/LModuleRegister.h
game/entity/hud/TextEntity.cpp
game/entity/hud/TextEntity.h
game/entity/hud/DebugGui.cpp
game/entity/hud/DebugGui.h
game/scene/world/Player.cpp
game/scene/world/Player.h
util/Ray.cpp
util/Ray.h
game/Game.cpp
game/Game.h
game/graph/scene/SceneManager.cpp
game/graph/scene/SceneManager.h
game/graph/scene/Scene.h
game/ClientState.h
game/scene/MenuScene.cpp
game/scene/MenuScene.h
server/Server.cpp
server/Server.h
util/net/Packet.cpp
util/net/Packet.h
server/player/ServerPlayer.cpp
server/player/ServerPlayer.h
game/scene/net/ServerConnection.cpp
game/scene/net/ServerConnection.h
def/gen/MapGen.cpp
def/gen/MapGen.h
util/net/NetHandler.cpp
util/net/NetHandler.h
game/entity/hud/GameGui.cpp
game/entity/hud/GameGui.h
util/net/Serializer.cpp
util/net/Serializer.h
server/conn/ConnectionList.cpp
server/conn/ConnectionList.h
server/conn/ServerPeer.h
util/net/PacketChannel.h
game/entity/world/PlayerEntity.cpp
game/entity/world/PlayerEntity.h
game/entity/hud/GraphEntity.cpp
game/entity/hud/GraphEntity.h
game/entity/hud/TextureRect.cpp
game/entity/hud/TextureRect.h
def/gen/MapGenJob.h
util/Interp.h
def/gen/NoiseSample.cpp
def/gen/NoiseSample.h
game/graph/frustum/Frustum.cpp
game/graph/frustum/Frustum.h
game/graph/frustum/FrustumPlane.cpp
game/graph/frustum/FrustumPlane.h
game/graph/frustum/FrustumAABB.cpp
game/graph/frustum/FrustumAABB.h
server/world/ServerWorld.cpp
server/world/ServerWorld.h
server/world/WorldGenStream.cpp
server/world/WorldGenStream.h
game/scene/world/WorldInterpolationStream.cpp
game/scene/world/WorldInterpolationStream.h
util/TransPos.h
game/scene/world/MeshGenStream.cpp
game/scene/world/MeshGenStream.h
util/Vec.h
world/Dimension.cpp
world/Dimension.h
world/region/Region.h
game/entity/world/WireframeEntity.cpp
game/entity/world/WireframeEntity.h
def/block/graph/SelectionBox.h
game/graph/drawable/Drawable.h
game/graph/drawable/DrawableGroup.cpp
game/graph/drawable/DrawableGroup.h
game/graph/window/InputManager.cpp
game/graph/window/InputManager.h
game/entity/world/BlockModelEntity.cpp
game/entity/world/BlockModelEntity.h
def/texture/TextureAtlas.cpp
def/texture/TextureAtlas.h
def/texture/AtlasRef.h
world/region/MapBlock.h def/GameDefs.cpp
def/GameDefs.h
api/func/LModuleUtil.cpp
api/func/LModuleUtil.h
world/region/Region.cpp
world/region/MapBlock.cpp
game/entity/hud/StatGraph.cpp
game/entity/hud/StatGraph.h
util/Util.h
)
add_library (zeusCore ${ZEUS_SRC_FILES})

View File

@ -5,9 +5,9 @@
#include "GameDefs.h"
GameDefs::GameDefs(std::string tex_path) {
textureAtlas = TextureAtlas(128);
textureAtlas = TextureAtlas(256);
textureAtlas.loadDirectory(std::move(tex_path));
// textureAtlas.loadFromDirectory("../res/tex/gui");
// textureAtlas.loadDirectory("../res/tex/gui");
blockAtlas = BlockAtlas();

View File

@ -35,7 +35,8 @@ MeshPart::MeshPart(std::vector<MeshVertex> vertices, std::vector<unsigned int> i
p3->nml = normal;
}
auto uv = atlas.getTextureUVs(texture);
this->texture = atlas.getTextureRef(texture);
auto uv = this->texture->uv;
//Iterate through the vertices to adjust the texture coordinates to fit the textureAtlas.
for (MeshVertex &vertex : this->vertices) {

View File

@ -24,6 +24,8 @@ struct MeshPart {
std::vector<MeshVertex> vertices;
std::vector<unsigned int> indices;
std::shared_ptr<AtlasRef> texture;
MeshMod meshMod;
float modValue;
};

View File

@ -1,5 +0,0 @@
//
// Created by aurailus on 17/04/19.
//
#include "AtlasRef.h"

View File

@ -10,16 +10,18 @@
#include <string>
struct AtlasRef {
int tileX;
int tileY;
int tileWidth;
int tileHeight;
int tileX = 0;
int tileY = 0;
int tileWidth = 0;
int tileHeight = 0;
glm::vec4 uv;
std::string name;
bool base = false;
int width;
int height;
glm::vec4 uv {};
std::string name = "";
int width = 0;
int height = 0;
};

View File

@ -40,7 +40,7 @@ TextureAtlas::TextureAtlas(unsigned int width, unsigned int height) :
}
void TextureAtlas::createMissingImage() {
auto *data = new unsigned char[16 * 4 * 16];
auto data = new unsigned char[16 * 4 * 16];
for (int i = 0; i < 16 * 16; i++) {
unsigned char m = 0;
@ -52,7 +52,7 @@ void TextureAtlas::createMissingImage() {
data[i * 4 + 3] = 255;
}
addImage(data, "_missing", 16, 16);
addImage(data, "_missing", true, 16, 16);
}
void TextureAtlas::loadDirectory(std::string dirStr) {
@ -66,7 +66,7 @@ void TextureAtlas::loadDirectory(std::string dirStr) {
if (!file.is_dir && strcmp(file.ext, ".png") == 0) {
int width, height;
unsigned char* data = stbi_load(file.path, &width, &height, nullptr, 4);
addImage(data, std::string(file.name).substr(0, std::string(file.name).size() - 4), width, height);
addImage(data, std::string(file.name).substr(0, std::string(file.name).size() - 4), true, width, height);
delete[] data;
}
@ -74,20 +74,33 @@ void TextureAtlas::loadDirectory(std::string dirStr) {
}
cf_dir_close(&dir);
std::string trypls("default_grass_top");
tryMakeGraphics(trypls);
trypls = "default_sand";
tryMakeGraphics(trypls);
trypls = "default_log_side";
tryMakeGraphics(trypls);
trypls = "default_leaves";
tryMakeGraphics(trypls);
trypls = "default_grass_float";
tryMakeGraphics(trypls);
trypls = "_missing";
tryMakeGraphics(trypls);
trypls = "default_leaves_puff";
tryMakeGraphics(trypls);
// std::string trypls("default_grass_top");
// generateCrackImage(trypls);
// trypls = "default_sand";
// generateCrackImage(trypls);
// trypls = "default_log_side";
// generateCrackImage(trypls);
// trypls = "default_leaves";
// generateCrackImage(trypls);
// trypls = "default_grass_float";
// generateCrackImage(trypls);
// trypls = "_missing";
// generateCrackImage(trypls);
// trypls = "default_leaves_puff";
// generateCrackImage(trypls);
}
void TextureAtlas::update() {
auto it = textures.cbegin();
// while (it != textures.cend()) {
// auto curr = it++;
//
// if (!curr->second->base && curr->second.unique()) {
// deleteImage(curr->second);
// textures.erase(curr);
// }
// }
}
glm::vec2 TextureAtlas::findImageSpace(int w, int h) {
@ -122,38 +135,65 @@ glm::vec2 TextureAtlas::findImageSpace(int w, int h) {
return glm::vec2(-1, -1);
}
std::shared_ptr<AtlasRef> TextureAtlas::addImage(unsigned char *data, std::string name, int texWidth, int texHeight) {
auto ref = std::make_shared<AtlasRef>();
std::shared_ptr<AtlasRef> TextureAtlas::addImage(unsigned char *data, std::string name, bool base, int texWidth, int texHeight) {
std::shared_ptr<AtlasRef> ref;
if (textures.count(name) != 0) {
deleteImage(textures[name]);
ref = textures[name];
}
else ref = std::make_shared<AtlasRef>();
ref->name = name;
ref->base = base;
ref->width = texWidth;
ref->height = texHeight;
auto tileWidth = static_cast<int>(std::ceil(texWidth / 16.0f));
auto tileHeight = static_cast<int>(std::ceil(texHeight / 16.0f));
ref->tileWidth = tileWidth;
ref->tileHeight = tileHeight;
if (tileWidth != ref->tileWidth || tileHeight != ref->tileHeight) {
ref->tileWidth = tileWidth;
ref->tileHeight = tileHeight;
auto space = findImageSpace(tileWidth, tileHeight);
auto space = findImageSpace(tileWidth, tileHeight);
if (space.x < 0) {
std::cerr << "Failed to find space in dynamic atlas." << std::endl;
return nullptr;
if (space.x < 0) {
std::cerr << "Failed to find space in dynamic atlas." << std::endl;
return nullptr;
}
ref->tileX = static_cast<int>(space.x);
ref->tileY = static_cast<int>(space.y);
ref->uv = {space.x / pageTileWidth, space.y / pageTileHeight,
(space.x * 16 + texWidth) / pageWidth, (space.y * 16 + texHeight) / pageHeight};
textures.insert({name, ref});
}
ref->tileX = static_cast<int>(space.x);
ref->tileY = static_cast<int>(space.y);
updateAtlas(static_cast<int>(space.x), static_cast<int>(space.y), texWidth, texHeight, data);
ref->uv = {space.x / pageTileWidth, space.y / pageTileHeight,
(space.x * 16 + texWidth) / pageWidth, (space.y * 16 + texHeight) / pageHeight};
textures.insert({name, ref});
updateAtlas(ref->tileX, ref->tileY, texWidth, texHeight, data);
return ref;
}
void TextureAtlas::deleteImage(std::shared_ptr<AtlasRef> ref) {
//For Debugging
// auto data = new unsigned char[ref->width * ref->height * 4];
//
// for (int i = 0; i < ref->width * ref->height * 4; i++) {
// data[i] = 0;
// }
//
// updateAtlas(ref->tileX, ref->tileY, ref->width, ref->height, data);
// delete[] data;
//
// for (auto i = ref->tileX; i < ref->tileX + ref->tileWidth; i++) {
// for (auto j = ref->tileY; j < ref->tileY + ref->tileHeight; j++) {
// empty[j * pageTileWidth + i] = true;
// }
// }
}
void TextureAtlas::updateAtlas(int tileX, int tileY, int texWidth, int texHeight, unsigned char *data) {
int baseX = tileX * 16;
int baseY = tileY * 16;
@ -167,8 +207,6 @@ void TextureAtlas::updateAtlas(int tileX, int tileY, int texWidth, int texHeight
atlasData[(baseX + xx + (baseY + yy) * pageWidth) * 4 + of] = data[(xx + yy * texWidth) * 4 + of];
}
t->loadFromBytes(atlasData, pageWidth, pageHeight);
}
TextureAtlas::RawTexData TextureAtlas::getSubImageBytes(std::string &name) {
@ -206,10 +244,10 @@ TextureAtlas::RawTexData TextureAtlas::getSubImageBytes(std::string &name) {
return data;
}
glm::vec4 TextureAtlas::tryMakeGraphics(std::string &name) {
std::shared_ptr<AtlasRef> TextureAtlas::generateCrackImage(std::string &name, unsigned short crackLevel) {
RawTexData base = getSubImageBytes(name);
std::string crackStr("default_crack_7");
std::string crackStr("default_crack_" + std::to_string(crackLevel));
RawTexData crack = getSubImageBytes(crackStr);
for (int i = 0; i < base.width * base.height; i++) {
@ -220,22 +258,23 @@ glm::vec4 TextureAtlas::tryMakeGraphics(std::string &name) {
base.data[i * 4 + 2] = static_cast<unsigned char>(base.data[i * 4 + 2] * (1 - alpha) + crack.data[i * 4 + 2] * alpha);
}
addImage(base.data, name + "_grayscale", base.width, base.height);
auto ref = addImage(base.data, name + "_crack_" + std::to_string(crackLevel), false, base.width, base.height);
delete [] base.data;
delete [] crack.data;
return textures[name + "_grayscale"]->uv;
return ref;
}
Texture &TextureAtlas::getAtlasTexture() {
return *t;
}
glm::vec4 TextureAtlas::getTextureUVs(std::string &name) {
std::shared_ptr<AtlasRef> TextureAtlas::getTextureRef(std::string &name) {
if (!textures.count(name)) {
return tryMakeGraphics(name);
// return tryMakeGraphics(name);
}
return textures[name]->uv;
return textures[name];
}
TextureAtlas::~TextureAtlas() = default;

View File

@ -20,12 +20,14 @@ public:
explicit TextureAtlas(unsigned int width, unsigned int height = 0);
void loadDirectory(std::string dirStr);
void update();
Texture& getAtlasTexture();
std::shared_ptr<AtlasRef> addImage(unsigned char *data, std::string name, int texWidth, int texHeight);
std::shared_ptr<AtlasRef> addImage(unsigned char *data, std::string name, bool base, int texWidth, int texHeight);
std::shared_ptr<AtlasRef> generateCrackImage(std::string &name, unsigned short crackLevel);
glm::vec4 getTextureUVs(std::string &name);
std::shared_ptr<AtlasRef> getTextureRef(std::string &name);
~TextureAtlas();
private:
@ -36,13 +38,14 @@ private:
};
RawTexData getSubImageBytes(std::string &name);
glm::vec4 tryMakeGraphics(std::string &name);
glm::vec2 findImageSpace(int w, int h);
void createMissingImage();
void updateAtlas(int tileX, int tileY, int texWidth, int texHeight, unsigned char *data);
void deleteImage(std::shared_ptr<AtlasRef> ref);
unsigned int pageWidth = 0;
unsigned int pageHeight = 0;
unsigned int pageTileWidth = 0;

View File

@ -19,12 +19,12 @@ void Game::start(char* path) {
int pid = fork();
if (pid == 0) {
char *arr[] = {
(char *) "xterm",
(char *) "-iconic",
(char *) "-e",
(char*) "xterm",
(char*) "-iconic",
(char*) "-e",
path,
(char *) "server",
(char *) nullptr};
(char*) "server",
(char*) nullptr};
execvp("xterm", arr);
} else {

View File

@ -10,24 +10,33 @@ BlockModelEntity::BlockModelEntity(GameDefs& defs) :
setMesh(m);
}
void BlockModelEntity::setModel(BlockModel &model) {
auto m = new Mesh();
void BlockModelEntity::setModel(unsigned int blockID, unsigned short crackLevel) {
if (blockID != this->blockID || crackLevel != this->crackLevel) {
this->blockID = blockID;
this->crackLevel = crackLevel;
std::vector<float> vertices;
std::vector<unsigned int> indices;
auto model = defs.blocks().getBlock(blockID).getModel();
auto m = new Mesh();
unsigned int indOffset = 0;
std::vector<float> vertices;
std::vector<unsigned int> indices;
addFaces(indOffset, vertices, indices, model.leftFaces);
addFaces(indOffset, vertices, indices, model.rightFaces);
addFaces(indOffset, vertices, indices, model.topFaces);
addFaces(indOffset, vertices, indices, model.bottomFaces);
addFaces(indOffset, vertices, indices, model.frontFaces);
addFaces(indOffset, vertices, indices, model.backFaces);
addFaces(indOffset, vertices, indices, model.noCulledFaces);
unsigned int indOffset = 0;
m->create(&vertices, &indices);
setMesh(m);
crackedFaces.clear();
std::cout << "Making model" << std::endl;
addFaces(indOffset, vertices, indices, model.leftFaces);
addFaces(indOffset, vertices, indices, model.rightFaces);
addFaces(indOffset, vertices, indices, model.topFaces);
addFaces(indOffset, vertices, indices, model.bottomFaces);
addFaces(indOffset, vertices, indices, model.frontFaces);
addFaces(indOffset, vertices, indices, model.backFaces);
addFaces(indOffset, vertices, indices, model.noCulledFaces);
m->create(&vertices, &indices);
setMesh(m);
}
}
void BlockModelEntity::clearModel() {
@ -36,14 +45,17 @@ void BlockModelEntity::clearModel() {
}
void BlockModelEntity::addFaces(unsigned int &indOffset, std::vector<float> &vertices, std::vector<unsigned int> &indices, std::vector<MeshPart> &meshParts) {
std::string tex("default_crack_" + std::to_string((int)std::round(n)));
n += 0.005f;
if (n > 7) n = 0;
auto uv = defs.textures().getTextureUVs(tex);
for (const MeshPart& mp : meshParts) {
glm::vec4 uv;
auto ref = defs.textures().generateCrackImage(mp.texture->name, crackLevel);
if (ref == nullptr) {
std::string missing("_missing");
uv = defs.textures().getTextureRef(missing)->uv;
}
uv = ref->uv;
crackedFaces.push_back(ref);
for (const MeshVertex &vertex : mp.vertices) {

View File

@ -14,12 +14,15 @@ class BlockModelEntity : public Entity {
public:
explicit BlockModelEntity(GameDefs &defs);
void setModel(BlockModel& model);
void setModel(unsigned int blockID, unsigned short crackLevel);
void clearModel();
private:
void addFaces(unsigned int &indOffset, std::vector<float> &vertices, std::vector<unsigned int> &indices, std::vector<MeshPart> &meshParts);
float n = 0;
std::vector<std::shared_ptr<AtlasRef>> crackedFaces;
unsigned int blockID;
unsigned int crackLevel;
GameDefs& defs;
};

View File

@ -46,7 +46,6 @@ void Texture::loadFromBytes(unsigned char* bytes, int width, int height) {
void Texture::updateTexture(int x, int y, int width, int height, unsigned char *bytes) {
glBindTexture(GL_TEXTURE_2D, textureID);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, bytes);
glBindTexture(GL_TEXTURE_2D, 0);
}

View File

@ -29,6 +29,8 @@ GameScene::GameScene(ClientState* state) : Scene(state),
void GameScene::update() {
defs.textures().update();
server.update(player);
playerChunkPos = TransPos::roundPos(*player.getPos() / glm::vec3(TransPos::CHUNK_SIZE));

View File

@ -5,7 +5,6 @@
#ifndef SRC_GAMEWORLD_H
#define SRC_GAMEWORLD_H
#include "../graph/scene/Scene.h"
#include "../graph/Renderer.h"
#include "../entity/hud/DebugGui.h"

View File

@ -27,6 +27,9 @@ void Player::update(InputManager &input, double delta, double mouseX, double mou
viewUpdate(mouseX, mouseY);
moveCollide();
crackLevel += 0.05f;
if (crackLevel >= 8) crackLevel = 0;
bool found = false;
glm::vec3 foundPos {};
@ -36,8 +39,7 @@ void Player::update(InputManager &input, double delta, double mouseX, double mou
auto at = world->getBlock(rayEnd);
if (at > 0) {
auto& def = defs->blocks().getBlock(at);
auto sBox = def.getSelectionBox();
auto sBox = defs->blocks().getBlock(at).getSelectionBox();
if (rayEnd.x >= pointedAt.x + sBox.a.x && rayEnd.y >= pointedAt.y + sBox.a.y && rayEnd.z >= pointedAt.z + sBox.a.z &&
rayEnd.x <= pointedAt.x + sBox.b.x && rayEnd.y <= pointedAt.y + sBox.b.y && rayEnd.z <= pointedAt.z + sBox.b.z) {
@ -49,7 +51,7 @@ void Player::update(InputManager &input, double delta, double mouseX, double mou
wireframe->updateMesh(box.a, box.b, 0.003f + ray.getLength() * 0.002f, glm::vec3(0.1));
wireframe->setPos(pointedAt);
blockBreak->setModel(def.getModel());
blockBreak->setModel(static_cast<unsigned int>(at), static_cast<u_short>(crackLevel));
blockBreak->setPos(pointedAt + glm::vec3(0, 0, 0));
if (!wireframe->isVisible()) wireframe->setVisible(true);

View File

@ -59,7 +59,9 @@ private:
BlockModelEntity *blockBreak;
SelectionBox box;
bool flying;
float crackLevel = 0;
bool flying = false;
};

View File

@ -3,6 +3,7 @@ set(ZEUS_TEST_FILES
tests/NetHandler.cpp
tests/Serializer.cpp
tests/LibNoise.cpp
tests/Dimension.cpp tests/List.cpp)
tests/Dimension.cpp
tests/List.cpp)
add_library (zeusTest ${ZEUS_TEST_FILES})