|
|
@@ -5,10 +5,10 @@
|
|
|
|
|
|
#include "ChunkMap.h"
|
|
|
#include "Constants.h"
|
|
|
-#include "File.h"
|
|
|
#include "DimensionMap.h"
|
|
|
#include "Entity.h"
|
|
|
#include "EntityType.h"
|
|
|
+#include "File.h"
|
|
|
#include "Game.h"
|
|
|
#include "NoBlock.h"
|
|
|
#include "Player.h"
|
|
|
@@ -337,40 +337,39 @@ void Dimension::entityTickLoop()
|
|
|
zm.measureEnd();
|
|
|
double seconds = zm.getSekunden();
|
|
|
zm.measureStart();
|
|
|
- entityCs.lock();
|
|
|
- chunkCs.lock();
|
|
|
- auto iterator = entities->begin();
|
|
|
- auto end = entities->end();
|
|
|
- while (iterator != end)
|
|
|
{
|
|
|
- if (!iterator->isRemoved())
|
|
|
- {
|
|
|
- iterator->prepareTick(this, seconds);
|
|
|
- iterator++;
|
|
|
- }
|
|
|
- else
|
|
|
+ Framework::CriticalLock lock({&entityCs, &chunkCs});
|
|
|
+ auto iterator = entities->begin();
|
|
|
+ auto end = entities->end();
|
|
|
+ while (iterator != end)
|
|
|
{
|
|
|
- auto chunk = zChunk(
|
|
|
- Game::getChunkCenter((int)iterator->getPosition().x,
|
|
|
- (int)iterator->getPosition().y));
|
|
|
- if (chunk)
|
|
|
+ if (!iterator->isRemoved())
|
|
|
{
|
|
|
- chunk->onEntityLeaves(iterator, 0);
|
|
|
+ iterator->prepareTick(this, seconds);
|
|
|
+ iterator++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ auto chunk = zChunk(
|
|
|
+ Game::getChunkCenter((int)iterator->getPosition().x,
|
|
|
+ (int)iterator->getPosition().y));
|
|
|
+ if (chunk)
|
|
|
+ {
|
|
|
+ chunk->onEntityLeaves(iterator, 0);
|
|
|
+ }
|
|
|
+ iterator.remove();
|
|
|
}
|
|
|
- iterator.remove();
|
|
|
}
|
|
|
- }
|
|
|
- int index = 0;
|
|
|
- for (auto entity : *entities)
|
|
|
- {
|
|
|
- if (!entity->isRemoved())
|
|
|
+ int index = 0;
|
|
|
+ for (auto entity : *entities)
|
|
|
{
|
|
|
- entity->tick(this, seconds);
|
|
|
+ if (!entity->isRemoved())
|
|
|
+ {
|
|
|
+ entity->tick(this, seconds);
|
|
|
+ }
|
|
|
+ index++;
|
|
|
}
|
|
|
- index++;
|
|
|
- }
|
|
|
- chunkCs.unlock();
|
|
|
- entityCs.unlock();
|
|
|
+ } // end of LOCK entityCs, chunkCs
|
|
|
ausgleich += 1.0 / 30 - seconds;
|
|
|
if (ausgleich > 0) Sleep((int)(ausgleich * 1000));
|
|
|
}
|
|
|
@@ -607,7 +606,7 @@ void Dimension::save(Text worldDir) const
|
|
|
{
|
|
|
File d;
|
|
|
d.setFile(Game::INSTANCE->getWorldDirectory() + "/dim/" + Text(dimensionId)
|
|
|
- + "/meta.dim");
|
|
|
+ + "/meta.dim");
|
|
|
d.create();
|
|
|
d.open(File::Style::write);
|
|
|
d.write((char*)&nextStructureId, 8);
|