AddEntityUpdate.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "AddEntityUpdate.h"
  2. #include "Dimension.h"
  3. #include "EntityType.h"
  4. #include "StaticRegistry.h"
  5. AddEntityUpdate::AddEntityUpdate(Entity* entity, int dimension)
  6. : WorldUpdate(WorldUpdateTypeEnum::ADD_ENTITY,
  7. dimension,
  8. entity->getPosition(),
  9. entity->getPosition()),
  10. entity(entity)
  11. {}
  12. AddEntityUpdate::~AddEntityUpdate()
  13. {
  14. entity->release();
  15. }
  16. void AddEntityUpdate::onUpdate(Dimension* zDimension)
  17. {
  18. zDimension->addEntity(dynamic_cast<Entity*>(entity->getThis()));
  19. }
  20. void AddEntityUpdate::write(Framework::StreamWriter* zWriter)
  21. {
  22. int id = entity->zType()->getId();
  23. zWriter->schreibe((char*)&id, 4);
  24. id = entity->getId();
  25. zWriter->schreibe((char*)&id, 4);
  26. Framework::Vec3<float> pos = entity->getPosition();
  27. zWriter->schreibe((char*)&pos.x, 4);
  28. zWriter->schreibe((char*)&pos.y, 4);
  29. zWriter->schreibe((char*)&pos.z, 4);
  30. float maxSpeed = entity->getMaxSpeed();
  31. zWriter->schreibe((char*)&maxSpeed, 4);
  32. bool special = !entity->hasDefaultModel();
  33. zWriter->schreibe((char*)&special, 1);
  34. if (special) entity->getSpecialModel().writeTo(zWriter);
  35. }