vehicleBlocker.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "T3D/vehicles/vehicleBlocker.h"
  24. #include "core/stream/bitStream.h"
  25. #include "scene/sceneRenderState.h"
  26. #include "scene/sceneManager.h"
  27. #include "math/mathIO.h"
  28. #include "console/consoleTypes.h"
  29. IMPLEMENT_CO_NETOBJECT_V1(VehicleBlocker);
  30. ConsoleDocClass( VehicleBlocker,
  31. "@brief Legacy class from Tribes, originally used for blocking Vehicle objects.\n\n"
  32. "@note This is no longer useful and should be deprecated soon.\n\n"
  33. "@internal\n"
  34. );
  35. //--------------------------------------------------------------------------
  36. //--------------------------------------------------------------------------
  37. VehicleBlocker::VehicleBlocker()
  38. {
  39. mNetFlags.set(Ghostable | ScopeAlways);
  40. mTypeMask = VehicleBlockerObjectType;
  41. mConvexList = new Convex;
  42. }
  43. VehicleBlocker::~VehicleBlocker()
  44. {
  45. delete mConvexList;
  46. mConvexList = NULL;
  47. }
  48. //--------------------------------------------------------------------------
  49. void VehicleBlocker::initPersistFields()
  50. {
  51. addField("dimensions", TypePoint3F, Offset(mDimensions, VehicleBlocker));
  52. Parent::initPersistFields();
  53. }
  54. //--------------------------------------------------------------------------
  55. bool VehicleBlocker::onAdd()
  56. {
  57. if(!Parent::onAdd())
  58. return false;
  59. mObjBox.minExtents.set(-mDimensions.x, -mDimensions.y, 0);
  60. mObjBox.maxExtents.set( mDimensions.x, mDimensions.y, mDimensions.z);
  61. resetWorldBox();
  62. setRenderTransform(mObjToWorld);
  63. addToScene();
  64. return true;
  65. }
  66. void VehicleBlocker::onRemove()
  67. {
  68. mConvexList->nukeList();
  69. removeFromScene();
  70. Parent::onRemove();
  71. }
  72. U32 VehicleBlocker::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
  73. {
  74. U32 retMask = Parent::packUpdate(con, mask, stream);
  75. mathWrite(*stream, getTransform());
  76. mathWrite(*stream, getScale());
  77. mathWrite(*stream, mDimensions);
  78. return retMask;
  79. }
  80. void VehicleBlocker::unpackUpdate(NetConnection *con, BitStream *stream)
  81. {
  82. Parent::unpackUpdate(con, stream);
  83. MatrixF mat;
  84. Point3F scale;
  85. Box3F objBox;
  86. mathRead(*stream, &mat);
  87. mathRead(*stream, &scale);
  88. mathRead(*stream, &mDimensions);
  89. mObjBox.minExtents.set(-mDimensions.x, -mDimensions.y, 0);
  90. mObjBox.maxExtents.set( mDimensions.x, mDimensions.y, mDimensions.z);
  91. setScale(scale);
  92. setTransform(mat);
  93. }
  94. void VehicleBlocker::buildConvex(const Box3F& box, Convex* convex)
  95. {
  96. // These should really come out of a pool
  97. mConvexList->collectGarbage();
  98. if (box.isOverlapped(getWorldBox()) == false)
  99. return;
  100. // Just return a box convex for the entire shape...
  101. Convex* cc = 0;
  102. CollisionWorkingList& wl = convex->getWorkingList();
  103. for (CollisionWorkingList* itr = wl.wLink.mNext; itr != &wl; itr = itr->wLink.mNext)
  104. {
  105. if (itr->mConvex->getType() == BoxConvexType &&
  106. itr->mConvex->getObject() == this) {
  107. cc = itr->mConvex;
  108. break;
  109. }
  110. }
  111. if (cc)
  112. return;
  113. // Create a new convex.
  114. BoxConvex* cp = new BoxConvex;
  115. mConvexList->registerObject(cp);
  116. convex->addToWorkingList(cp);
  117. cp->init(this);
  118. mObjBox.getCenter(&cp->mCenter);
  119. cp->mSize.x = mObjBox.len_x() / 2.0f;
  120. cp->mSize.y = mObjBox.len_y() / 2.0f;
  121. cp->mSize.z = mObjBox.len_z() / 2.0f;
  122. }