vehicleBlocker.cpp 4.6 KB

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