|
@@ -240,14 +240,13 @@ void Chunk::notifyObservers(NetworkMessage* msg)
|
|
{
|
|
{
|
|
Array<int> remove;
|
|
Array<int> remove;
|
|
int index = 0;
|
|
int index = 0;
|
|
- for (int id : observers)
|
|
|
|
|
|
+ for (InformationObserver* observer : observers)
|
|
{
|
|
{
|
|
- Entity* zE = Game::INSTANCE->zEntity(id);
|
|
|
|
- if (!zE)
|
|
|
|
|
|
+ if (!observer->sendMessage(
|
|
|
|
+ dynamic_cast<NetworkMessage*>(msg->getThis())))
|
|
|
|
+ {
|
|
remove.add(index, 0);
|
|
remove.add(index, 0);
|
|
- else
|
|
|
|
- Game::INSTANCE->sendMessage(
|
|
|
|
- dynamic_cast<NetworkMessage*>(msg->getThis()), zE);
|
|
|
|
|
|
+ }
|
|
index++;
|
|
index++;
|
|
}
|
|
}
|
|
for (int i : remove)
|
|
for (int i : remove)
|
|
@@ -257,13 +256,14 @@ void Chunk::notifyObservers(NetworkMessage* msg)
|
|
|
|
|
|
void Chunk::addObserver(Entity* zEntity, DoLaterHandler& laterHandler)
|
|
void Chunk::addObserver(Entity* zEntity, DoLaterHandler& laterHandler)
|
|
{
|
|
{
|
|
- for (int id : observers)
|
|
|
|
|
|
+ for (InformationObserver* observer : observers)
|
|
{
|
|
{
|
|
- if (id == zEntity->getId()) return;
|
|
|
|
|
|
+ if (observer->getEntityId() == zEntity->getId()) return;
|
|
}
|
|
}
|
|
int id = zEntity->getId();
|
|
int id = zEntity->getId();
|
|
- observers.add(id);
|
|
|
|
- laterHandler.addTodo([this, id]() {
|
|
|
|
|
|
+ InformationObserver* observer = new InformationObserver(id);
|
|
|
|
+ observers.add(observer);
|
|
|
|
+ laterHandler.addTodo([this, id, observer]() {
|
|
InMemoryBuffer buffer;
|
|
InMemoryBuffer buffer;
|
|
buffer.schreibe("\4", 1);
|
|
buffer.schreibe("\4", 1);
|
|
buffer.schreibe((char*)&location.x, 4);
|
|
buffer.schreibe((char*)&location.x, 4);
|
|
@@ -280,6 +280,17 @@ void Chunk::addObserver(Entity* zEntity, DoLaterHandler& laterHandler)
|
|
Entity* e = Game::INSTANCE->zEntity(id);
|
|
Entity* e = Game::INSTANCE->zEntity(id);
|
|
if (e)
|
|
if (e)
|
|
{
|
|
{
|
|
|
|
+ Punkt p = location;
|
|
|
|
+ int dimId = dimensionId;
|
|
|
|
+ msg->setOnAfterSend([this, p, dimId, observer]() {
|
|
|
|
+ // check if chunk is still loaded
|
|
|
|
+ if (Game::INSTANCE->zDimension(dimId)
|
|
|
|
+ && Game::INSTANCE->zDimension(dimId)->zChunk(p) == this)
|
|
|
|
+ {
|
|
|
|
+ // send all waiting messages to the observer
|
|
|
|
+ observer->setReady();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
Game::INSTANCE->sendMessage(msg, e);
|
|
Game::INSTANCE->sendMessage(msg, e);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -290,9 +301,9 @@ void Chunk::addObserver(Entity* zEntity, DoLaterHandler& laterHandler)
|
|
void Chunk::removeObserver(Entity* zEntity)
|
|
void Chunk::removeObserver(Entity* zEntity)
|
|
{
|
|
{
|
|
int index = 0;
|
|
int index = 0;
|
|
- for (int id : observers)
|
|
|
|
|
|
+ for (InformationObserver* observer : observers)
|
|
{
|
|
{
|
|
- if (id == zEntity->getId())
|
|
|
|
|
|
+ if (observer->getEntityId() == zEntity->getId())
|
|
{
|
|
{
|
|
observers.remove(index);
|
|
observers.remove(index);
|
|
return;
|
|
return;
|
|
@@ -424,7 +435,8 @@ void Chunk::instantiateBlock(Framework::Vec3<int> location)
|
|
->createBlockAt(
|
|
->createBlockAt(
|
|
{location.x + this->location.x - CHUNK_SIZE / 2,
|
|
{location.x + this->location.x - CHUNK_SIZE / 2,
|
|
location.y + this->location.y - CHUNK_SIZE / 2,
|
|
location.y + this->location.y - CHUNK_SIZE / 2,
|
|
- location.z}, dimensionId,
|
|
|
|
|
|
+ location.z},
|
|
|
|
+ dimensionId,
|
|
0));
|
|
0));
|
|
}
|
|
}
|
|
|
|
|