Clear MeshChunks on Dimension leave.

master
Auri 2020-11-07 15:55:39 -08:00
parent 50af55beee
commit e0b8651b8a
5 changed files with 19 additions and 3 deletions

View File

@ -85,6 +85,7 @@ DimensionPtr LocalWorld::getActiveDimension() {
}
void LocalWorld::setActiveDimension(DimensionPtr dim) {
this->activeDimension->deactivate();
this->activeDimension = dim.l();
}

View File

@ -19,6 +19,20 @@
LocalDimension::LocalDimension(SubgamePtr game, LocalWorld& world, const std::string& identifier, unsigned int ind) :
Dimension(game, static_cast<World&>(world), identifier, ind), meshGenStream(std::make_shared<MeshGenStream>(game, *this)) {}
/**
* Deactivates a dimension, cleaning up all mesh chunks.
* Called on the active dimension when the player leaves it.
*/
void LocalDimension::deactivate() {
while (!renderElems.empty()) {
auto chunk = renderElems.front();
renderRefs.erase(chunk->getPos());
renderElems.pop_front();
}
}
void LocalDimension::update(double delta) {
finishMeshes();
@ -283,4 +297,4 @@ bool LocalDimension::getAdjacentExists(glm::vec3 pos, bool updateAdjacents) {
if (chunk == nullptr) return false;
if (updateAdjacents) attemptMeshChunk(chunk, false, false);
return true;
}
}

View File

@ -25,6 +25,7 @@ public:
LocalDimension(SubgamePtr game, LocalWorld& world, const std::string& identifier, unsigned int ind);
void deactivate();
void update(double delta) override;
void setChunk(std::shared_ptr<Chunk> chunk) override;

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -10,10 +10,10 @@ zepha.register_entity("zeus:default:test", {
self.object.anims:set_anim("walk")
self.object.anims:play()
zepha.after(function()
-- zepha.after(function()
-- local in_desert = self.object.dimension.identifier == 'zeus:world:endless_desert'
-- player:set_dimension(in_desert and "zeus:world:default" or "zeus:world:endless_desert")
end, 2)
-- end, 2)
end,
on_update = function(self, delta)
self.object.pos = self.object.pos +