AddEntityUpdate.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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, dimension, entity->getLocation()),
  8. entity(entity)
  9. {}
  10. AddEntityUpdate::~AddEntityUpdate()
  11. {
  12. entity->release();
  13. }
  14. void AddEntityUpdate::onUpdate(Dimension* zDimension)
  15. {
  16. zDimension->addEntity(dynamic_cast<Entity*>(entity->getThis()));
  17. }
  18. void AddEntityUpdate::write(Framework::StreamWriter* zWriter)
  19. {
  20. int id = entity->zType()->getId();
  21. zWriter->schreibe((char*)&id, 4);
  22. id = entity->getId();
  23. zWriter->schreibe((char*)&id, 4);
  24. Framework::Vec3<float> pos = entity->getPosition();
  25. zWriter->schreibe((char*)&pos.x, 4);
  26. zWriter->schreibe((char*)&pos.y, 4);
  27. zWriter->schreibe((char*)&pos.z, 4);
  28. float maxSpeed = entity->getMaxSpeed();
  29. zWriter->schreibe((char*)&maxSpeed, 4);
  30. bool special = !entity->hasDefaultModel();
  31. zWriter->schreibe((char*)&special, 1);
  32. if (special) entity->getSpecialModel().writeTo(zWriter);
  33. }