at least it works
This commit is contained in:
15
src/game.cpp
15
src/game.cpp
@@ -82,16 +82,21 @@ void Game::Setup(int w, int h) {
|
||||
m_cameras["Default"] = std::make_shared<Camera>(w, h);
|
||||
m_activeCamera = m_cameras["Default"];
|
||||
|
||||
BlockDictionary.Build();
|
||||
std::shared_ptr<CBlockDictionary> BlockDictionary = CBlockDictionary::GetInstance();
|
||||
|
||||
BlockDictionary->Build();
|
||||
|
||||
m_world = std::make_unique<World>();
|
||||
|
||||
Texture texture;
|
||||
m_world->TextureID = texture.LoadTextures(BlockDictionary.Textures);
|
||||
m_world->TextureID = texture.LoadTextures(BlockDictionary->Textures);
|
||||
|
||||
m_world->Chunks.push_back(std::make_shared<Chunk>(0, 0));
|
||||
m_world->Chunks.push_back(std::make_shared<Chunk>(1, 1));
|
||||
m_world->Chunks.push_back(std::make_shared<Chunk>(1, 3));
|
||||
for (int x = 0; x < 3; x++)
|
||||
for (int y = 0; y < 3; y++) {
|
||||
|
||||
m_world->Chunks.push_back(std::make_shared<Chunk>(x, y));
|
||||
|
||||
}
|
||||
|
||||
m_world->Shaders["Basic"] = std::make_shared<Shader>();
|
||||
m_world->Shaders["Basic"]->Load(GameConfig.ResourceBase + "shaders/simple");
|
||||
|
||||
@@ -17,19 +17,17 @@ Chunk::Chunk(int x, int z) {
|
||||
for (int z = 0; z < CHUNK_DEPTH; z++) {
|
||||
|
||||
// Grass on the top layer
|
||||
// if (y == CHUNK_HEIGHT - 1) {
|
||||
if (y == CHUNK_HEIGHT - 1) {
|
||||
|
||||
Voxels.push_back((uint8_t)EBlockType::Grass);
|
||||
|
||||
// } else {
|
||||
} else {
|
||||
|
||||
// Voxels.push_back((uint8_t)EBlockType::Dirt);
|
||||
|
||||
// }
|
||||
Voxels.push_back((uint8_t)EBlockType::Dirt);
|
||||
|
||||
}
|
||||
|
||||
std::cout << Voxels.size() << " voxels" << std::endl;
|
||||
}
|
||||
|
||||
m_mesh();
|
||||
|
||||
@@ -85,12 +83,8 @@ void Chunk::m_mesh() {
|
||||
std::vector<glm::vec3> tempVerts;
|
||||
std::vector<glm::vec3> tempUVs;
|
||||
|
||||
std::cout << x << " " << y << " " << z << std::endl;
|
||||
|
||||
uint8_t block = BlockAt(x, y, z);
|
||||
|
||||
std::cout << "Block ID " << (int)block << std::endl;
|
||||
|
||||
Voxel tmp({x, y, z}, BlockAt(x, y, z));
|
||||
|
||||
tmp.AddFace(EFaceType::Top);
|
||||
@@ -100,8 +94,10 @@ void Chunk::m_mesh() {
|
||||
tmp.AddFace(EFaceType::Front);
|
||||
tmp.AddFace(EFaceType::Back);
|
||||
|
||||
for (auto& uv : tempUVs)
|
||||
m_uvs.push_back(uv);
|
||||
tmp.GetMesh(tempVerts, tempUVs);
|
||||
|
||||
m_vertices.insert(m_vertices.end(), tempVerts.begin(), tempVerts.end());
|
||||
m_uvs.insert(m_uvs.end(), tempUVs.begin(), tempUVs.end());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ void Voxel::AddFace(EFaceType::Face face) {
|
||||
case EFaceType::Left:
|
||||
{
|
||||
|
||||
verts = CubeTopFace;
|
||||
verts = CubeLeftFace;
|
||||
uvs = CubeLeftFaceUVs;
|
||||
|
||||
break;
|
||||
@@ -86,17 +86,10 @@ void Voxel::AddFace(EFaceType::Face face) {
|
||||
verts = m_translateIntoChunk(verts, m_coordsInChunk);
|
||||
m_vertices.insert(m_vertices.end(), verts.begin(), verts.end());
|
||||
|
||||
std::cout << "Voxel ID " << (int)Block << std::endl;
|
||||
|
||||
std::shared_ptr<CBlockEntry> block = BlockDictionary.BlockEntries[Block];
|
||||
|
||||
std::cout << "Block Entries Size " << BlockDictionary.BlockEntries.size() << std::endl;
|
||||
|
||||
std::cout << "Block ID " << (int)block->ID << std::endl;
|
||||
std::cout << "Block Texture Count " << (int)block->FaceTextures.size() << std::endl;
|
||||
std::shared_ptr<CBlockEntry> block = CBlockDictionary::GetInstance()->BlockEntries[Block];
|
||||
|
||||
uint16_t tex = block->FaceTextures[(uint16_t)face];
|
||||
std::cout << "Texture ID " << (int)tex << std::endl;
|
||||
|
||||
std::vector<glm::vec3> uvws;
|
||||
|
||||
|
||||
@@ -4,6 +4,21 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::shared_ptr<CBlockDictionary> CBlockDictionary::Instance;
|
||||
|
||||
std::shared_ptr<CBlockDictionary> CBlockDictionary::GetInstance() {
|
||||
|
||||
if (!CBlockDictionary::Instance) {
|
||||
|
||||
CBlockDictionary::Instance = std::make_shared<CBlockDictionary>();
|
||||
|
||||
}
|
||||
|
||||
return CBlockDictionary::Instance;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CBlockDictionary::Build() {
|
||||
|
||||
RegisterTexture("dirt.png");
|
||||
@@ -15,8 +30,6 @@ void CBlockDictionary::Build() {
|
||||
RegisterBlock(EBlockType::Dirt, { EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt, EFaceTexture::Dirt });
|
||||
RegisterBlock(EBlockType::Grass, { EFaceTexture::Grass, EFaceTexture::Dirt, EFaceTexture::GrassSide, EFaceTexture::GrassSide, EFaceTexture::GrassSide, EFaceTexture::GrassSide });
|
||||
|
||||
std::cout << "Block Entries Size " << BlockEntries.size() << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void CBlockDictionary::RegisterTexture(std::string texture) {
|
||||
@@ -25,9 +38,8 @@ void CBlockDictionary::RegisterTexture(std::string texture) {
|
||||
|
||||
}
|
||||
|
||||
void CBlockDictionary::RegisterBlock(uint8_t block, std::vector<uint16_t> faceTextures) {
|
||||
void CBlockDictionary::RegisterBlock(EBlockType::Block block, std::vector<uint16_t> faceTextures) {
|
||||
|
||||
std::cout << "Block Entries Size " << BlockEntries.size() << std::endl;
|
||||
BlockEntries[block] = std::make_shared<CBlockEntry>((uint8_t)block, faceTextures);
|
||||
|
||||
}
|
||||
|
||||
@@ -44,6 +44,12 @@ public:
|
||||
// ie, import all the data used in the build from
|
||||
// files and that
|
||||
class CBlockDictionary {
|
||||
public:
|
||||
|
||||
static std::shared_ptr<CBlockDictionary> GetInstance();
|
||||
|
||||
static std::shared_ptr<CBlockDictionary> Instance;
|
||||
|
||||
public:
|
||||
|
||||
void Build();
|
||||
@@ -60,13 +66,11 @@ public:
|
||||
// Expects textures to be inserted in order, 0-...
|
||||
void RegisterTexture(std::string texture);
|
||||
|
||||
void RegisterBlock(uint8_t block, std::vector<uint16_t> faceTextures);
|
||||
void RegisterBlock(EBlockType::Block block, std::vector<uint16_t> faceTextures);
|
||||
|
||||
};
|
||||
|
||||
|
||||
static CBlockDictionary BlockDictionary;
|
||||
|
||||
// static std::vector<std::pair<int, std::string>> TextureIdsAndPaths {
|
||||
// {0, "dirt.png"},
|
||||
// {1, "grass_side.png"},
|
||||
|
||||
Reference in New Issue
Block a user