X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FWorld.cpp;h=e8b665c992366ca2b5f2ecc0efd63447a2f8d73d;hb=549646ac3e5bede5e77031f773649edf8de83608;hp=94cd092f88c03a7fd40562342231e06c6bb00dfc;hpb=55dbd6b35a39888f245e247d2e140f141f918178;p=blank.git diff --git a/src/world/World.cpp b/src/world/World.cpp index 94cd092..e8b665c 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -1,8 +1,7 @@ #include "World.hpp" #include "WorldCollision.hpp" -#include "../graphics/BlockLighting.hpp" -#include "../graphics/DirectionalLighting.hpp" +#include "../graphics/Viewport.hpp" #include #include @@ -235,7 +234,7 @@ Chunk &World::PlayerChunk() { return chunks.ForceLoad(player->ChunkCoords()); } -Chunk &World::Next(const Chunk &to, const glm::tvec3 &dir) { +Chunk &World::Next(const Chunk &to, const glm::ivec3 &dir) { const Chunk::Pos tgt_pos = to.Position() + dir; return chunks.ForceLoad(tgt_pos); } @@ -258,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); } @@ -295,10 +301,11 @@ void World::Resolve(Entity &e, std::vector &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())); @@ -309,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()) {