]> git.localhorst.tv Git - blank.git/blobdiff - src/world/World.cpp
collect and load textures required by block types
[blank.git] / src / world / World.cpp
index aa347e7f654d5e374b621ad1e4efe55a3419fd43..3d3eb6c3d9ba11a6aebc685e01480dca6b6e773f 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "WorldCollision.hpp"
 #include "../app/Assets.hpp"
+#include "../app/TextureIndex.hpp"
 #include "../graphics/Format.hpp"
 #include "../graphics/Viewport.hpp"
 
 namespace blank {
 
 World::World(const Assets &assets, const Config &config, const WorldSave &save)
-: blockType()
-, blockShape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }})
-, stairShape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}, { 0.0f, 0.0f })
-, slabShape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.0f, 0.5f }})
+: block_type()
 , block_tex()
 , generate(config.gen)
-, chunks(config.load, blockType, generate, save)
+, chunks(config.load, block_type, generate, save)
 , player()
 , entities()
 , light_direction(config.light_direction)
 , fog_density(config.fog_density) {
-       BlockType::Faces block_fill = {  true,  true,  true,  true,  true,  true };
-       BlockType::Faces slab_fill  = { false,  true, false, false, false, false };
-       BlockType::Faces stair_fill = { false,  true, false, false, false,  true };
+       TextureIndex tex_index;
+       assets.LoadBlockTypes("default", block_type, tex_index);
 
        block_tex.Bind();
-       block_tex.Reserve(16, 16, 4, Format());
-       assets.LoadTexture("debug", block_tex, 0);
-       assets.LoadTexture("rock-1", block_tex, 1);
-       assets.LoadTexture("rock-2", block_tex, 2);
-       assets.LoadTexture("rock-3", block_tex, 3);
+       assets.LoadTextures(tex_index, block_tex);
        block_tex.FilterNearest();
 
-       { // white block
-               BlockType type(true, { 1.0f, 1.0f, 1.0f }, &blockShape);
-               type.texture = 1;
-               type.label = "White Block";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = block_fill;
-               blockType.Add(type);
-       }
-       { // white slab
-               BlockType type(true, { 1.0f, 1.0f, 1.0f }, &slabShape);
-               type.texture = 1;
-               type.label = "White Slab";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = slab_fill;
-               blockType.Add(type);
-       }
-       { // white stair
-               BlockType type(true, { 1.0f, 1.0f, 1.0f }, &stairShape);
-               type.texture = 1;
-               type.label = "White Stair";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = stair_fill;
-               blockType.Add(type);
-       }
-
-       { // red block
-               BlockType type(true, { 1.0f, 0.0f, 0.0f }, &blockShape);
-               type.texture = 3;
-               type.label = "Red Block";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = block_fill;
-               blockType.Add(type);
-       }
-       { // red slab
-               BlockType type(true, { 1.0f, 0.0f, 0.0f }, &slabShape);
-               type.texture = 3;
-               type.label = "Red Slab";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = slab_fill;
-               blockType.Add(type);
-       }
-       { // red stair
-               BlockType type(true, { 1.0f, 0.0f, 0.0f }, &stairShape);
-               type.texture = 3;
-               type.label = "Red Stair";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = stair_fill;
-               blockType.Add(type);
-       }
-
-       { // green block
-               BlockType type(true, { 0.0f, 1.0f, 0.0f }, &blockShape);
-               type.texture = 1;
-               type.label = "Green Block";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = block_fill;
-               blockType.Add(type);
-       }
-       { // green slab
-               BlockType type(true, { 0.0f, 1.0f, 0.0f }, &slabShape);
-               type.texture = 1;
-               type.label = "Green Slab";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = slab_fill;
-               blockType.Add(type);
-       }
-       { // green stair
-               BlockType type(true, { 0.0f, 1.0f, 0.0f }, &stairShape);
-               type.texture = 1;
-               type.label = "Green Stair";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = stair_fill;
-               blockType.Add(type);
-       }
-
-       { // blue block
-               BlockType type(true, { 0.0f, 0.0f, 1.0f }, &blockShape);
-               type.texture = 3;
-               type.label = "Blue Block";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = block_fill;
-               blockType.Add(type);
-       }
-       { // blue slab
-               BlockType type(true, { 0.0f, 0.0f, 1.0f }, &slabShape);
-               type.texture = 3;
-               type.label = "Blue Slab";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = slab_fill;
-               blockType.Add(type);
-       }
-       { // blue stair
-               BlockType type(true, { 0.0f, 0.0f, 1.0f }, &stairShape);
-               type.texture = 3;
-               type.label = "Blue Stair";
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = stair_fill;
-               blockType.Add(type);
-       }
-
-       { // glowing yellow block
-               BlockType type(true, { 1.0f, 1.0f, 0.0f }, &blockShape);
-               type.texture = 2;
-               type.label = "Light";
-               type.luminosity = 15;
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = block_fill;
-               blockType.Add(type);
-       }
-
-       { // the mysterious debug cube
-               BlockType type(true, { 1.0f, 1.0f, 1.0f }, &blockShape);
-               type.texture = 0;
-               type.label = "Debug Cube";
-               type.luminosity = 0;
-               type.block_light = true;
-               type.collision = true;
-               type.collide_block = true;
-               type.fill = block_fill;
-               blockType.Add(type);
-       }
-
        generate.Space(0);
        generate.Light(13);
        generate.Solids({ 1, 4, 7, 10 });
@@ -357,10 +202,7 @@ void World::Render(Viewport &viewport) {
        entity_prog.SetFogDensity(fog_density);
 
        for (Entity &entity : entities) {
-               if (entity.HasShape()) {
-                       entity_prog.SetM(entity.Transform(player->ChunkCoords()));
-                       entity.Draw();
-               }
+               entity.Render(entity.ChunkTransform(player->ChunkCoords()), entity_prog);
        }
 }