vehicleBlocker.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. if( !mObjBox.isValidBox() )
  62. {
  63. Con::errorf("VehicleBlocker::onAdd - Fail - No valid object box");
  64. return false;
  65. }
  66. resetWorldBox();
  67. setRenderTransform(mObjToWorld);
  68. addToScene();
  69. return true;
  70. }
  71. void VehicleBlocker::onRemove()
  72. {
  73. mConvexList->nukeList();
  74. removeFromScene();
  75. Parent::onRemove();
  76. }
  77. U32 VehicleBlocker::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
  78. {
  79. U32 retMask = Parent::packUpdate(con, mask, stream);
  80. mathWrite(*stream, getTransform());
  81. mathWrite(*stream, getScale());
  82. mathWrite(*stream, mDimensions);
  83. return retMask;
  84. }
  85. void VehicleBlocker::unpackUpdate(NetConnection *con, BitStream *stream)
  86. {
  87. Parent::unpackUpdate(con, stream);
  88. MatrixF mat;
  89. Point3F scale;
  90. Box3F objBox;
  91. mathRead(*stream, &mat);
  92. mathRead(*stream, &scale);
  93. mathRead(*stream, &mDimensions);
  94. mObjBox.minExtents.set(-mDimensions.x, -mDimensions.y, 0);
  95. mObjBox.maxExtents.set( mDimensions.x, mDimensions.y, mDimensions.z);
  96. setScale(scale);
  97. setTransform(mat);
  98. }
  99. void VehicleBlocker::buildConvex(const Box3F& box, Convex* convex)
  100. {
  101. // These should really come out of a pool
  102. mConvexList->collectGarbage();
  103. if (box.isOverlapped(getWorldBox()) == false)
  104. return;
  105. // Just return a box convex for the entire shape...
  106. Convex* cc = 0;
  107. CollisionWorkingList& wl = convex->getWorkingList();
  108. for (CollisionWorkingList* itr = wl.wLink.mNext; itr != &wl; itr = itr->wLink.mNext)
  109. {
  110. if (itr->mConvex->getType() == BoxConvexType &&
  111. itr->mConvex->getObject() == this) {
  112. cc = itr->mConvex;
  113. break;
  114. }
  115. }
  116. if (cc)
  117. return;
  118. // Create a new convex.
  119. BoxConvex* cp = new BoxConvex;
  120. mConvexList->registerObject(cp);
  121. convex->addToWorkingList(cp);
  122. cp->init(this);
  123. mObjBox.getCenter(&cp->mCenter);
  124. cp->mSize.x = mObjBox.len_x() / 2.0f;
  125. cp->mSize.y = mObjBox.len_y() / 2.0f;
  126. cp->mSize.z = mObjBox.len_z() / 2.0f;
  127. }