AddEntityUpdate.cpp 1.1 KB

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