W3DDependencyModelDraw.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. ** Command & Conquer Generals(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. //-------------------------------------------------------------------------------------------------
  38. W3DDependencyModelDrawModuleData::W3DDependencyModelDrawModuleData()
  39. {
  40. }
  41. //-------------------------------------------------------------------------------------------------
  42. W3DDependencyModelDrawModuleData::~W3DDependencyModelDrawModuleData()
  43. {
  44. }
  45. //-------------------------------------------------------------------------------------------------
  46. void W3DDependencyModelDrawModuleData::buildFieldParse(MultiIniFieldParse& p)
  47. {
  48. W3DModelDrawModuleData::buildFieldParse(p);
  49. static const FieldParse dataFieldParse[] =
  50. {
  51. { "AttachToBoneInContainer", INI::parseAsciiString, NULL, offsetof(W3DDependencyModelDrawModuleData, m_attachToDrawableBoneInContainer) },
  52. { 0, 0, 0, 0 }
  53. };
  54. p.add(dataFieldParse);
  55. }
  56. //-------------------------------------------------------------------------------------------------
  57. //-------------------------------------------------------------------------------------------------
  58. W3DDependencyModelDraw::W3DDependencyModelDraw( Thing *thing, const ModuleData* moduleData ) : W3DModelDraw( thing, moduleData )
  59. {
  60. m_dependencyCleared = FALSE;
  61. }
  62. //-------------------------------------------------------------------------------------------------
  63. W3DDependencyModelDraw::~W3DDependencyModelDraw()
  64. {
  65. }
  66. //-------------------------------------------------------------------------------------------------
  67. // All this does is stop the call path if we haven't been cleared to draw yet
  68. void W3DDependencyModelDraw::doDrawModule(const Matrix3D* transformMtx)
  69. {
  70. if( m_dependencyCleared )
  71. {
  72. // We've been cleared by the thing we were waiting to draw, so we can draw.
  73. W3DModelDraw::doDrawModule( transformMtx );
  74. m_dependencyCleared = FALSE;
  75. }
  76. }
  77. //-------------------------------------------------------------------------------------------------
  78. void W3DDependencyModelDraw::notifyDrawModuleDependencyCleared( )
  79. {
  80. m_dependencyCleared = TRUE;
  81. }
  82. // ------------------------------------------------------------------------------------------------
  83. void W3DDependencyModelDraw::adjustTransformMtx(Matrix3D& mtx) const
  84. {
  85. W3DModelDraw::adjustTransformMtx(mtx);
  86. // We have an additional adjustment to make, we want to use a bone in our container if there is one
  87. const Object *me = getDrawable()->getObject();
  88. const W3DDependencyModelDrawModuleData *md = getW3DDependencyModelDrawModuleData();
  89. if( md->m_attachToDrawableBoneInContainer.isNotEmpty()
  90. && me
  91. && me->getContainedBy()
  92. && !me->getContainedBy()->getContain()->isEnclosingContainerFor(me)
  93. )
  94. {
  95. // If we are currently "riding on", then our client position is determined by the client position of
  96. // a particular bone in our container object. Our logic position is updated by OpenContain.
  97. const Drawable *theirDrawable = me->getContainedBy()->getDrawable();
  98. if( theirDrawable )
  99. {
  100. Matrix3D theirBoneMtx;
  101. if( theirDrawable->getCurrentWorldspaceClientBonePositions( md->m_attachToDrawableBoneInContainer.str(), theirBoneMtx ) )
  102. {
  103. mtx = theirBoneMtx;
  104. }
  105. else
  106. {
  107. DEBUG_LOG(("m_attachToDrawableBoneInContainer %s not found\n",getW3DDependencyModelDrawModuleData()->m_attachToDrawableBoneInContainer.str()));
  108. }
  109. }
  110. }
  111. }
  112. // ------------------------------------------------------------------------------------------------
  113. /** CRC */
  114. // ------------------------------------------------------------------------------------------------
  115. void W3DDependencyModelDraw::crc( Xfer *xfer )
  116. {
  117. // extend base class
  118. W3DModelDraw::crc( xfer );
  119. } // end crc
  120. // ------------------------------------------------------------------------------------------------
  121. /** Xfer method
  122. * Version Info:
  123. * 1: Initial version */
  124. // ------------------------------------------------------------------------------------------------
  125. void W3DDependencyModelDraw::xfer( Xfer *xfer )
  126. {
  127. // version
  128. XferVersion currentVersion = 1;
  129. XferVersion version = currentVersion;
  130. xfer->xferVersion( &version, currentVersion );
  131. // extend base class
  132. W3DModelDraw::xfer( xfer );
  133. // Dependency status
  134. xfer->xferBool( &m_dependencyCleared );
  135. } // end xfer
  136. // ------------------------------------------------------------------------------------------------
  137. /** Load post process */
  138. // ------------------------------------------------------------------------------------------------
  139. void W3DDependencyModelDraw::loadPostProcess( void )
  140. {
  141. // extend base class
  142. W3DModelDraw::loadPostProcess();
  143. } // end loadPostProcess