AddEntityUpdate.cpp 1.1 KB

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