AddEntityUpdate.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. float gravityMultiplier = entity->getGravityMultiplier();
  30. zWriter->schreibe((char*)&gravityMultiplier, 4);
  31. float jumpSpeed = entity->getJumpSpeed();
  32. zWriter->schreibe((char*)&jumpSpeed, 4);
  33. bool special = !entity->hasDefaultModel();
  34. zWriter->schreibe((char*)&special, 1);
  35. if (special) entity->zSpecialModel()->writeTo(zWriter);
  36. }