W3DDependencyModelDraw.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: W3DDependencyModelDraw.cpp ////////////////////////////////////////////////////////////////////////////
  24. // Author: Graham Smallwood, October 2002
  25. // Desc: Draw module just like Model, except it can't draw unless somebody else explicitly says to, since they
  26. // have to draw first.
  27. //
  28. // This draw module can be used in a general case (although I don't see why), m_attachToDrawableBoneInContainer
  29. // is for the one present and main reason to use this module. Our transport needs to tell us it is okay to
  30. // draw after he draws.
  31. ///////////////////////////////////////////////////////////////////////////////////////////////////
  32. #include "Common/Xfer.h"
  33. #include "GameClient/Drawable.h"
  34. #include "GameLogic/Object.h"
  35. #include "GameLogic/Module/ContainModule.h"
  36. #include "W3DDevice/GameClient/Module/W3DDependencyModelDraw.h"
  37. #ifdef _INTERNAL
  38. // for occasional debugging...
  39. //#pragma optimize("", off)
  40. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  41. #endif
  42. //-------------------------------------------------------------------------------------------------
  43. W3DDependencyModelDrawModuleData::W3DDependencyModelDrawModuleData()
  44. {
  45. }
  46. //-------------------------------------------------------------------------------------------------
  47. W3DDependencyModelDrawModuleData::~W3DDependencyModelDrawModuleData()
  48. {
  49. }
  50. //-------------------------------------------------------------------------------------------------
  51. void W3DDependencyModelDrawModuleData::buildFieldParse(MultiIniFieldParse& p)
  52. {
  53. W3DModelDrawModuleData::buildFieldParse(p);
  54. static const FieldParse dataFieldParse[] =
  55. {
  56. { "AttachToBoneInContainer", INI::parseAsciiString, NULL, offsetof(W3DDependencyModelDrawModuleData, m_attachToDrawableBoneInContainer) },
  57. { 0, 0, 0, 0 }
  58. };
  59. p.add(dataFieldParse);
  60. }
  61. //-------------------------------------------------------------------------------------------------
  62. //-------------------------------------------------------------------------------------------------
  63. W3DDependencyModelDraw::W3DDependencyModelDraw( Thing *thing, const ModuleData* moduleData ) : W3DModelDraw( thing, moduleData )
  64. {
  65. m_dependencyCleared = FALSE;
  66. }
  67. //-------------------------------------------------------------------------------------------------
  68. W3DDependencyModelDraw::~W3DDependencyModelDraw()
  69. {
  70. }
  71. //-------------------------------------------------------------------------------------------------
  72. // All this does is stop the call path if we haven't been cleared to draw yet
  73. void W3DDependencyModelDraw::doDrawModule(const Matrix3D* transformMtx)
  74. {
  75. if( m_dependencyCleared )
  76. {
  77. // We've been cleared by the thing we were waiting to draw, so we can draw.
  78. W3DModelDraw::doDrawModule( transformMtx );
  79. m_dependencyCleared = FALSE;
  80. // A handy place to synchronize my drawable with container's
  81. Drawable *myDrawable = getDrawable();
  82. if ( ! myDrawable )
  83. return;
  84. const Object *me = myDrawable->getObject();
  85. if ( ! me )
  86. return;
  87. Drawable *theirDrawable = NULL;
  88. if( me->getContainedBy() && !me->getContainedBy()->getContain()->isEnclosingContainerFor(me) )
  89. theirDrawable = me->getContainedBy()->getDrawable();
  90. if( ! theirDrawable )
  91. return;
  92. myDrawable->imitateStealthLook( *theirDrawable );
  93. }
  94. }
  95. //-------------------------------------------------------------------------------------------------
  96. void W3DDependencyModelDraw::notifyDrawModuleDependencyCleared( )
  97. {
  98. m_dependencyCleared = TRUE;
  99. }
  100. // ------------------------------------------------------------------------------------------------
  101. void W3DDependencyModelDraw::adjustTransformMtx(Matrix3D& mtx) const
  102. {
  103. W3DModelDraw::adjustTransformMtx(mtx);
  104. // We have an additional adjustment to make, we want to use a bone in our container if there is one
  105. const Object *me = getDrawable()->getObject();
  106. const W3DDependencyModelDrawModuleData *md = getW3DDependencyModelDrawModuleData();
  107. if( md->m_attachToDrawableBoneInContainer.isNotEmpty()
  108. && me
  109. && me->getContainedBy()
  110. && !me->getContainedBy()->getContain()->isEnclosingContainerFor(me)
  111. )
  112. {
  113. // If we are currently "riding on", then our client position is determined by the client position of
  114. // a particular bone in our container object. Our logic position is updated by OpenContain.
  115. const Drawable *theirDrawable = me->getContainedBy()->getDrawable();
  116. if( theirDrawable )
  117. {
  118. Matrix3D theirBoneMtx;
  119. if( theirDrawable->getCurrentWorldspaceClientBonePositions( md->m_attachToDrawableBoneInContainer.str(), theirBoneMtx ) )
  120. {
  121. mtx = theirBoneMtx;
  122. }
  123. else
  124. {
  125. mtx = *theirDrawable->getTransformMatrix();//TransformMatrix();
  126. DEBUG_LOG(("m_attachToDrawableBoneInContainer %s not found\n",getW3DDependencyModelDrawModuleData()->m_attachToDrawableBoneInContainer.str()));
  127. }
  128. }
  129. }
  130. }
  131. // ------------------------------------------------------------------------------------------------
  132. /** CRC */
  133. // ------------------------------------------------------------------------------------------------
  134. void W3DDependencyModelDraw::crc( Xfer *xfer )
  135. {
  136. // extend base class
  137. W3DModelDraw::crc( xfer );
  138. } // end crc
  139. // ------------------------------------------------------------------------------------------------
  140. /** Xfer method
  141. * Version Info:
  142. * 1: Initial version */
  143. // ------------------------------------------------------------------------------------------------
  144. void W3DDependencyModelDraw::xfer( Xfer *xfer )
  145. {
  146. // version
  147. XferVersion currentVersion = 1;
  148. XferVersion version = currentVersion;
  149. xfer->xferVersion( &version, currentVersion );
  150. // extend base class
  151. W3DModelDraw::xfer( xfer );
  152. // Dependency status
  153. xfer->xferBool( &m_dependencyCleared );
  154. } // end xfer
  155. // ------------------------------------------------------------------------------------------------
  156. /** Load post process */
  157. // ------------------------------------------------------------------------------------------------
  158. void W3DDependencyModelDraw::loadPostProcess( void )
  159. {
  160. // extend base class
  161. W3DModelDraw::loadPostProcess();
  162. } // end loadPostProcess