WorldUpdate.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "WorldUpdate.h"
  2. WorldUpdate::WorldUpdate( int type, int dimensionId, Framework::Vec3<int> minAffected, Framework::Vec3<int> maxAffected )
  3. : ReferenceCounter(),
  4. affectedDimensionId( dimensionId ),
  5. minAffected( minAffected ),
  6. maxAffected( maxAffected ),
  7. type( type )
  8. {}
  9. void WorldUpdate::writeAndCheck( Framework::StreamWriter* zWriter )
  10. {
  11. zWriter->schreibe( (char*)&type, 4 );
  12. this->write( zWriter );
  13. zWriter->schreibe( (char*)&type, 4 );
  14. }
  15. int WorldUpdate::getAffectedDimension() const
  16. {
  17. return affectedDimensionId;
  18. }
  19. const Framework::Vec3<int>& WorldUpdate::getMinAffectedPoint() const
  20. {
  21. return minAffected;
  22. }
  23. const Framework::Vec3<int>& WorldUpdate::getMaxAffectedPoint() const
  24. {
  25. return maxAffected;
  26. }
  27. int WorldUpdate::getType() const
  28. {
  29. return type;
  30. }
  31. int WorldUpdate::distanceTo( int x, int y ) const
  32. {
  33. int xDist = MIN( abs( x - minAffected.x ), abs( x - maxAffected.x ) );
  34. int yDist = MIN( abs( y - minAffected.y ), abs( y - maxAffected.y ) );
  35. if( x >= minAffected.x && x <= maxAffected.x )
  36. xDist = 0;
  37. if( y >= minAffected.y && y <= maxAffected.y )
  38. yDist = 0;
  39. return MIN( xDist, yDist );
  40. }
  41. WorldUpdateType::WorldUpdateType( int id )
  42. : ReferenceCounter()
  43. {
  44. StaticRegistry<WorldUpdateType>::INSTANCE.registerT( this, id );
  45. }