RayEffect.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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: RayEffect.cpp ////////////////////////////////////////////////////////////////////////////
  24. // Created: Colin Day, May 2001
  25. // Desc: Ray effect system manager
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "GameClient/RayEffect.h"
  30. #include "GameClient/Drawable.h"
  31. // PUBLIC DATA ////////////////////////////////////////////////////////////////////////////////////
  32. class RayEffectSystem *TheRayEffects = NULL;
  33. // PRIVATE METHODS ////////////////////////////////////////////////////////////////////////////////
  34. //-------------------------------------------------------------------------------------------------
  35. /** Find an effect entry given a drawable */
  36. //-------------------------------------------------------------------------------------------------
  37. RayEffectData *RayEffectSystem::findEntry( const Drawable *draw )
  38. {
  39. Int i;
  40. RayEffectData *effectData = NULL;
  41. // find the matching effect data entry
  42. for( i = 0; i < MAX_RAY_EFFECTS; i++ )
  43. {
  44. if( m_effectData[ i ].draw == draw )
  45. {
  46. effectData = &m_effectData[ i ];
  47. break; // exit for i
  48. } // end if
  49. } // end for i
  50. return effectData;
  51. } // end findEntry
  52. // PUBLIC METHODS /////////////////////////////////////////////////////////////////////////////////
  53. //-------------------------------------------------------------------------------------------------
  54. //-------------------------------------------------------------------------------------------------
  55. RayEffectSystem::RayEffectSystem( void )
  56. {
  57. init();
  58. } // end RayEffectSystem
  59. //-------------------------------------------------------------------------------------------------
  60. //-------------------------------------------------------------------------------------------------
  61. RayEffectSystem::~RayEffectSystem( void )
  62. {
  63. } // end ~RayEffectSystem
  64. //-------------------------------------------------------------------------------------------------
  65. /** initialize the system */
  66. //-------------------------------------------------------------------------------------------------
  67. void RayEffectSystem::init( void )
  68. {
  69. Int i;
  70. for( i = 0; i < MAX_RAY_EFFECTS; i++ )
  71. {
  72. m_effectData[ i ].draw = NULL;
  73. m_effectData[ i ].startLoc.zero();
  74. m_effectData[ i ].endLoc.zero();
  75. } // end for i
  76. } // end init
  77. //-------------------------------------------------------------------------------------------------
  78. /** Reset */
  79. //-------------------------------------------------------------------------------------------------
  80. void RayEffectSystem::reset( void )
  81. {
  82. // nothing dynamic going on here, just initialize it
  83. init();
  84. } // end reset
  85. //-------------------------------------------------------------------------------------------------
  86. /** add a ray effect entry for this drawable */
  87. //-------------------------------------------------------------------------------------------------
  88. void RayEffectSystem::addRayEffect( const Drawable *draw,
  89. const Coord3D *startLoc,
  90. const Coord3D *endLoc )
  91. {
  92. Int i;
  93. RayEffectData *effectData = NULL;
  94. // sanity
  95. if( draw == NULL || startLoc == NULL || endLoc == NULL )
  96. return;
  97. /** @todo this should be more intelligent and should not be limited
  98. to any kind of max ray effects, this is all a temporary hack system for
  99. the demo anyway right now though */
  100. // search for a free effect slot
  101. for( i = 0; i < MAX_RAY_EFFECTS; i++ )
  102. {
  103. if( m_effectData[ i ].draw == NULL )
  104. {
  105. effectData = &m_effectData[ i ];
  106. break; // exit for
  107. } // end if
  108. } // end for i
  109. // if no free slots we can't do it
  110. if( effectData == NULL )
  111. return;
  112. // add the data to the entry
  113. effectData->draw = draw;
  114. effectData->startLoc = *startLoc;
  115. effectData->endLoc = *endLoc;
  116. }
  117. //-------------------------------------------------------------------------------------------------
  118. /** given a drawable, remove its effect from the system */
  119. //-------------------------------------------------------------------------------------------------
  120. void RayEffectSystem::deleteRayEffect( const Drawable *draw )
  121. {
  122. RayEffectData *effectData = NULL;
  123. // sanity
  124. if( draw == NULL )
  125. return;
  126. // find the effect entry
  127. effectData = findEntry( draw );
  128. if( effectData )
  129. {
  130. // remove the data for this entry
  131. effectData->draw = NULL;
  132. } // end if
  133. } // end deleteRayEffect
  134. //-------------------------------------------------------------------------------------------------
  135. /** given a drawable, if it is in the ray effect system list retrieve
  136. * the ray effect data for its entry */
  137. //-------------------------------------------------------------------------------------------------
  138. void RayEffectSystem::getRayEffectData( const Drawable *draw,
  139. RayEffectData *effectData )
  140. {
  141. RayEffectData *entry = NULL;
  142. // sanity
  143. if( draw == NULL || effectData == NULL )
  144. return;
  145. // find the effect data entry
  146. entry = findEntry( draw );
  147. if( entry )
  148. {
  149. // data has been found, copy to parameter
  150. *effectData = *entry;
  151. } // end effectData
  152. } // end getRayEffectData