|
|
@@ -126,6 +126,7 @@ void Dimension::tickEntities()
|
|
|
this->currentDayTime
|
|
|
-= dayDuration + nightDuration + nightTransitionDuration * 2;
|
|
|
}
|
|
|
+ entityCs.lock();
|
|
|
for (auto entity : *entities)
|
|
|
{
|
|
|
if (!entity->isRemoved()
|
|
|
@@ -144,6 +145,7 @@ void Dimension::tickEntities()
|
|
|
entity->tick(this);
|
|
|
index++;
|
|
|
}
|
|
|
+ entityCs.unlock();
|
|
|
}
|
|
|
|
|
|
void Dimension::thread()
|
|
|
@@ -171,6 +173,7 @@ void Dimension::thread()
|
|
|
{
|
|
|
Chunk* removedChunk = removedChunks.z(0);
|
|
|
removedChunksCs.unlock();
|
|
|
+ Array<Framework::Punkt> chunksToSave;
|
|
|
Text filePath = Game::INSTANCE->getWorldDirectory() + "/dim/"
|
|
|
+ getDimensionId() + "/";
|
|
|
filePath.appendHex(removedChunk->getCenter().x);
|
|
|
@@ -181,13 +184,34 @@ void Dimension::thread()
|
|
|
d.setDatei(filePath);
|
|
|
d.erstellen();
|
|
|
d.open(Datei::Style::schreiben);
|
|
|
- removedChunk->save(&d);
|
|
|
+ removedChunk->save(&d, chunksToSave);
|
|
|
char addr[8];
|
|
|
getAddrOfWorld(removedChunk->getCenter(), addr);
|
|
|
map->removeMap(addr, 8);
|
|
|
d.close();
|
|
|
removedChunksCs.lock();
|
|
|
removedChunks.remove(0);
|
|
|
+ while (chunksToSave.getEintragAnzahl() > 0)
|
|
|
+ {
|
|
|
+ Punkt cPos = chunksToSave.get(0);
|
|
|
+ chunksToSave.remove(0);
|
|
|
+ Chunk* c = zChunk(cPos);
|
|
|
+ if (c)
|
|
|
+ {
|
|
|
+ Text filePath = Game::INSTANCE->getWorldDirectory()
|
|
|
+ + "/dim/" + getDimensionId() + "/";
|
|
|
+ filePath.appendHex(cPos.x);
|
|
|
+ filePath += "_";
|
|
|
+ filePath.appendHex(cPos.y);
|
|
|
+ filePath += ".chunk";
|
|
|
+ Datei d;
|
|
|
+ d.setDatei(filePath);
|
|
|
+ d.erstellen();
|
|
|
+ d.open(Datei::Style::schreiben);
|
|
|
+ c->save(&d, chunksToSave);
|
|
|
+ d.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
removedChunksCs.unlock();
|
|
|
if (priorizedLightUpdateQueue.getEintragAnzahl())
|
|
|
@@ -411,7 +435,9 @@ void Dimension::sendBlockInfo(Framework::Vec3<int> location)
|
|
|
|
|
|
void Dimension::addEntity(Entity* entity)
|
|
|
{
|
|
|
+ entityCs.lock();
|
|
|
entities->add(entity);
|
|
|
+ entityCs.unlock();
|
|
|
}
|
|
|
|
|
|
void Dimension::setChunk(Chunk* chunk, Punkt center)
|
|
|
@@ -433,6 +459,10 @@ void Dimension::setChunk(Chunk* chunk, Punkt center)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ for (Entity* entity : old->getEntitiesInChunk())
|
|
|
+ {
|
|
|
+ removeEntity(entity->getId());
|
|
|
+ }
|
|
|
}
|
|
|
chunks->set(addr, 8, chunk);
|
|
|
if (chunk)
|
|
|
@@ -488,6 +518,10 @@ void Dimension::setChunk(Chunk* chunk, Punkt center)
|
|
|
{
|
|
|
Game::INSTANCE->zGenerator()->postprocessChunk(chunk);
|
|
|
chunk->setAdded();
|
|
|
+ for (Entity* entity : chunk->getEntitiesInChunk())
|
|
|
+ {
|
|
|
+ addEntity(dynamic_cast<Entity*>(entity->getThis()));
|
|
|
+ }
|
|
|
cs.lock();
|
|
|
int index = 0;
|
|
|
for (ArrayIterator<RequestQueue> iterator = waitingRequests.begin();
|
|
|
@@ -543,6 +577,7 @@ void Dimension::save(Text worldDir) const
|
|
|
d.schreibe((char*)&nextStructureId, 8);
|
|
|
d.schreibe((char*)¤tDayTime, 8);
|
|
|
d.close();
|
|
|
+ Array<Framework::Punkt> otherChunks;
|
|
|
for (auto chunk = chunkList.begin(); chunk; chunk++)
|
|
|
{
|
|
|
if (!chunk._) continue;
|
|
|
@@ -553,42 +588,33 @@ void Dimension::save(Text worldDir) const
|
|
|
filePath.appendHex(chunk->getCenter().y);
|
|
|
filePath += ".chunk";
|
|
|
file->setDatei(filePath);
|
|
|
- if (file->open(Datei::Style::schreiben)) chunk->save(file);
|
|
|
+ if (file->open(Datei::Style::schreiben)) chunk->save(file, otherChunks);
|
|
|
file->close();
|
|
|
file->release();
|
|
|
char addr[8];
|
|
|
getAddrOfWorld(chunk->getCenter(), addr);
|
|
|
map->saveMap(addr, 8);
|
|
|
}
|
|
|
- Text filePath = worldDir + "/dim/" + dimensionId + "/entities";
|
|
|
- Datei* file = new Datei();
|
|
|
- file->setDatei(filePath);
|
|
|
- if (file->open(Datei::Style::schreiben))
|
|
|
+ // since all chunks were saved otherChunks can be ignored
|
|
|
+ entityCs.lock();
|
|
|
+ for (Entity* entity : *entities)
|
|
|
{
|
|
|
- for (Entity* entity : *entities)
|
|
|
+ if (entity->zType()->getId() == EntityTypeEnum::PLAYER)
|
|
|
{
|
|
|
- if (entity->zType()->getId() != EntityTypeEnum::PLAYER)
|
|
|
+ Datei pFile;
|
|
|
+ pFile.setDatei(
|
|
|
+ worldDir + "/player/"
|
|
|
+ + Game::INSTANCE->getPlayerId(((Player*)entity)->getName()));
|
|
|
+ pFile.erstellen();
|
|
|
+ if (pFile.open(Datei::Style::schreiben))
|
|
|
{
|
|
|
- if (!entity->isRemoved())
|
|
|
- {
|
|
|
- int type = entity->zType()->getId();
|
|
|
- file->schreibe((char*)&type, 4);
|
|
|
- Game::INSTANCE->zEntityType(type)->saveEntity(entity, file);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Datei pFile;
|
|
|
- pFile.setDatei(worldDir + "/player/"
|
|
|
- + Game::INSTANCE->getPlayerId(
|
|
|
- ((Player*)entity)->getName()));
|
|
|
- if (pFile.open(Datei::Style::schreiben))
|
|
|
- Game::INSTANCE->zEntityType(EntityTypeEnum::PLAYER)
|
|
|
- ->saveEntity(entity, &pFile);
|
|
|
+ Game::INSTANCE->zEntityType(EntityTypeEnum::PLAYER)
|
|
|
+ ->saveEntity(entity, &pFile);
|
|
|
+ pFile.close();
|
|
|
}
|
|
|
}
|
|
|
- file->close();
|
|
|
}
|
|
|
+ entityCs.unlock();
|
|
|
for (MultiblockStructure* structure : structures)
|
|
|
{
|
|
|
saveStructure(structure);
|
|
|
@@ -678,12 +704,18 @@ void Dimension::removeOldChunks()
|
|
|
structurCs.unlock();
|
|
|
}
|
|
|
|
|
|
-Entity* Dimension::zEntity(int id)
|
|
|
+Entity* Dimension::zEntity(int id) const
|
|
|
{
|
|
|
+ entityCs.lock();
|
|
|
for (auto entity : *entities)
|
|
|
{
|
|
|
- if (!entity->isRemoved() && entity->getId() == id) return entity;
|
|
|
+ if (!entity->isRemoved() && entity->getId() == id)
|
|
|
+ {
|
|
|
+ entityCs.unlock();
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
}
|
|
|
+ entityCs.unlock();
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -692,6 +724,7 @@ Entity* Dimension::zNearestEntity(
|
|
|
{
|
|
|
Entity* result = 0;
|
|
|
float sqDist = 0;
|
|
|
+ entityCs.lock();
|
|
|
for (auto entity : *entities)
|
|
|
{
|
|
|
if (!entity->isRemoved() && filter(entity))
|
|
|
@@ -704,21 +737,25 @@ Entity* Dimension::zNearestEntity(
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ entityCs.unlock();
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
void Dimension::removeEntity(int id)
|
|
|
{
|
|
|
int index = 0;
|
|
|
+ entityCs.lock();
|
|
|
for (auto entity : *entities)
|
|
|
{
|
|
|
if (entity->getId() == id)
|
|
|
{
|
|
|
entities->remove(index);
|
|
|
+ entityCs.unlock();
|
|
|
return;
|
|
|
}
|
|
|
index++;
|
|
|
}
|
|
|
+ entityCs.unlock();
|
|
|
}
|
|
|
|
|
|
void Dimension::removeSubscriptions(Entity* zEntity)
|