#include "InformationObserver.h" #include "Game.h" InformationObserver::InformationObserver(int entityId) : ReferenceCounter(), entityId(entityId), ready(false) {} InformationObserver::~InformationObserver() { cs.lock(); waitingMessages.leeren(); cs.unlock(); } int InformationObserver::getEntityId() const { return entityId; } bool InformationObserver::sendMessage(NetworkMessage* message) { cs.lock(); if (ready) { cs.unlock(); Entity* e = Game::INSTANCE->zEntity(entityId); if (e) { Game::INSTANCE->sendMessage(message, e); return 1; } else { message->release(); return 0; } } else { waitingMessages.add(message); cs.unlock(); return 1; } } void InformationObserver::setReady() { cs.lock(); ready = 1; Entity* e = Game::INSTANCE->zEntity(entityId); if (e) { for (NetworkMessage* msg : waitingMessages) { Game::INSTANCE->sendMessage(dynamic_cast(msg->getThis()), e); } } waitingMessages.leeren(); cs.unlock(); }