]> git.localhorst.tv Git - blank.git/blobdiff - src/world/World.cpp
tvec[234]<int> -> ivec[234]
[blank.git] / src / world / World.cpp
index d51520ef5b2828c1d22902e1e00902bccb504884..e8b665c992366ca2b5f2ecc0efd63447a2f8d73d 100644 (file)
@@ -1,8 +1,7 @@
 #include "World.hpp"
 
 #include "WorldCollision.hpp"
-#include "../graphics/BlockLighting.hpp"
-#include "../graphics/DirectionalLighting.hpp"
+#include "../graphics/Viewport.hpp"
 
 #include <iostream>
 #include <limits>
@@ -29,6 +28,7 @@ World::World(const Config &config)
 
        { // white block
                BlockType type(true, { 1.0f, 1.0f, 1.0f }, &blockShape);
+               type.label = "White Block";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -37,6 +37,7 @@ World::World(const Config &config)
        }
        { // white slab
                BlockType type(true, { 1.0f, 1.0f, 1.0f }, &slabShape);
+               type.label = "White Slab";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -45,6 +46,7 @@ World::World(const Config &config)
        }
        { // white stair
                BlockType type(true, { 1.0f, 1.0f, 1.0f }, &stairShape);
+               type.label = "White Stair";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -54,6 +56,7 @@ World::World(const Config &config)
 
        { // red block
                BlockType type(true, { 1.0f, 0.0f, 0.0f }, &blockShape);
+               type.label = "Red Block";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -62,6 +65,7 @@ World::World(const Config &config)
        }
        { // red slab
                BlockType type(true, { 1.0f, 0.0f, 0.0f }, &slabShape);
+               type.label = "Red Slab";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -70,6 +74,7 @@ World::World(const Config &config)
        }
        { // red stair
                BlockType type(true, { 1.0f, 0.0f, 0.0f }, &stairShape);
+               type.label = "Red Stair";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -79,6 +84,7 @@ World::World(const Config &config)
 
        { // green block
                BlockType type(true, { 0.0f, 1.0f, 0.0f }, &blockShape);
+               type.label = "Green Block";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -87,6 +93,7 @@ World::World(const Config &config)
        }
        { // green slab
                BlockType type(true, { 0.0f, 1.0f, 0.0f }, &slabShape);
+               type.label = "Green Slab";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -95,6 +102,7 @@ World::World(const Config &config)
        }
        { // green stair
                BlockType type(true, { 0.0f, 1.0f, 0.0f }, &stairShape);
+               type.label = "Green Stair";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -104,6 +112,7 @@ World::World(const Config &config)
 
        { // blue block
                BlockType type(true, { 0.0f, 0.0f, 1.0f }, &blockShape);
+               type.label = "Blue Block";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -112,6 +121,7 @@ World::World(const Config &config)
        }
        { // blue slab
                BlockType type(true, { 0.0f, 0.0f, 1.0f }, &slabShape);
+               type.label = "Blue Slab";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -120,6 +130,7 @@ World::World(const Config &config)
        }
        { // blue stair
                BlockType type(true, { 0.0f, 0.0f, 1.0f }, &stairShape);
+               type.label = "Blue Stair";
                type.block_light = true;
                type.collision = true;
                type.collide_block = true;
@@ -129,6 +140,7 @@ World::World(const Config &config)
 
        { // glowing yellow block
                BlockType type(true, { 1.0f, 1.0f, 0.0f }, &blockShape);
+               type.label = "Light";
                type.luminosity = 15;
                type.block_light = true;
                type.collision = true;
@@ -222,7 +234,7 @@ Chunk &World::PlayerChunk() {
        return chunks.ForceLoad(player->ChunkCoords());
 }
 
-Chunk &World::Next(const Chunk &to, const glm::tvec3<int> &dir) {
+Chunk &World::Next(const Chunk &to, const glm::ivec3 &dir) {
        const Chunk::Pos tgt_pos = to.Position() + dir;
        return chunks.ForceLoad(tgt_pos);
 }
@@ -245,6 +257,13 @@ void World::Update(int dt) {
                        Resolve(entity, col);
                }
        }
+       for (auto iter = entities.begin(), end = entities.end(); iter != end;) {
+               if (iter->CanRemove()) {
+                       iter = entities.erase(iter);
+               } else {
+                       ++iter;
+               }
+       }
        chunks.Rebase(player->ChunkCoords());
        chunks.Update(dt);
 }
@@ -282,10 +301,11 @@ void World::Resolve(Entity &e, std::vector<WorldCollision> &col) {
 }
 
 
-void World::Render(BlockLighting &chunk_prog, DirectionalLighting &entity_prog) {
-       chunk_prog.Activate();
+void World::Render(Viewport &viewport) {
+       viewport.WorldPosition(player->Transform(player->ChunkCoords()));
+
+       BlockLighting &chunk_prog = viewport.ChunkProgram();
        chunk_prog.SetFogDensity(fog_density);
-       chunk_prog.SetView(glm::inverse(player->Transform(player->ChunkCoords())));
 
        for (Chunk &chunk : chunks.Loaded()) {
                glm::mat4 m(chunk.Transform(player->ChunkCoords()));
@@ -296,10 +316,9 @@ void World::Render(BlockLighting &chunk_prog, DirectionalLighting &entity_prog)
                }
        }
 
-       entity_prog.Activate();
+       DirectionalLighting &entity_prog = viewport.EntityProgram();
        entity_prog.SetLightDirection(light_direction);
        entity_prog.SetFogDensity(fog_density);
-       entity_prog.SetView(glm::inverse(player->Transform(player->ChunkCoords())));
 
        for (Entity &entity : entities) {
                if (entity.HasShape()) {