W3DGameClient.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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: W3DGameClient.cpp /////////////////////////////////////////////////
  24. //
  25. // W3DImplementaion of the GameClient. If there were a client/server
  26. // architecture, this game interface could be thought of as the "client"
  27. // that the user uses to interact with the logic of the game world which
  28. // would be known as the "server"
  29. //
  30. // Author: Colin Day, April 2001
  31. //
  32. ///////////////////////////////////////////////////////////////////////////////
  33. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  34. #include <stdlib.h>
  35. // USER INCLUDES //////////////////////////////////////////////////////////////
  36. #include "Common/ThingTemplate.h"
  37. #include "Common/ThingFactory.h"
  38. #include "Common/ModuleFactory.h"
  39. #include "Common/RandomValue.h"
  40. #include "Common/GlobalData.h"
  41. #include "Common/GameLOD.h"
  42. #include "GameClient/Drawable.h"
  43. #include "GameClient/GameClient.h"
  44. #include "GameClient/ParticleSys.h"
  45. #include "GameClient/RayEffect.h"
  46. #include "W3DDevice/GameClient/W3DAssetManager.h"
  47. #include "W3DDevice/GameClient/W3DGameClient.h"
  48. #include "W3DDevice/GameClient/W3DStatusCircle.h"
  49. #include "W3DDevice/GameClient/W3DScene.h"
  50. #include "W3DDevice/GameClient/W3DShadow.h"
  51. #include "W3DDevice/GameClient/heightmap.h"
  52. #include "WW3D2/Part_emt.h"
  53. #include "WW3D2/HAnim.h"
  54. #include "WW3D2/HTree.h"
  55. #include "WW3D2/AnimObj.h" ///< @todo superhack for demo, remove!
  56. //-------------------------------------------------------------------------------------------------
  57. //-------------------------------------------------------------------------------------------------
  58. W3DGameClient::W3DGameClient()
  59. {
  60. } // end W3DGameClient
  61. //-------------------------------------------------------------------------------------------------
  62. //-------------------------------------------------------------------------------------------------
  63. W3DGameClient::~W3DGameClient()
  64. {
  65. } // end ~W3DGameClient
  66. //-------------------------------------------------------------------------------------------------
  67. /** Initialize resources for the w3d game client */
  68. //-------------------------------------------------------------------------------------------------
  69. void W3DGameClient::init( void )
  70. {
  71. // extending initialization routine
  72. GameClient::init();
  73. } // end init
  74. //-------------------------------------------------------------------------------------------------
  75. /** Per frame udpate, note we are extending functionality */
  76. //-------------------------------------------------------------------------------------------------
  77. void W3DGameClient::update( void )
  78. {
  79. // call base
  80. GameClient::update();
  81. } // end update
  82. //-------------------------------------------------------------------------------------------------
  83. /** Reset this device client system. Note we are extending reset functionality from
  84. * the device independent client */
  85. //-------------------------------------------------------------------------------------------------
  86. void W3DGameClient::reset( void )
  87. {
  88. // call base class
  89. GameClient::reset();
  90. } // end reset
  91. //-------------------------------------------------------------------------------------------------
  92. /** allocate a new drawable using the thing template for initialization.
  93. * if we want to have the thing manager actually contain the pools of
  94. * object and drawable storage it seems OK to have it be friends with the
  95. * GameLogic/Client for those purposes, or we could put the allocation pools
  96. * in the GameLogic and GameClient themselves */
  97. //-------------------------------------------------------------------------------------------------
  98. Drawable *W3DGameClient::friend_createDrawable( const ThingTemplate *tmplate,
  99. DrawableStatus statusBits )
  100. {
  101. Drawable *draw = NULL;
  102. // sanity
  103. if( tmplate == NULL )
  104. return NULL;
  105. draw = newInstance(Drawable)( tmplate, statusBits );
  106. return draw;
  107. }
  108. //-------------------------------------------------------------------------------------------------
  109. //-------------------------------------------------------------------------------------------------
  110. void W3DGameClient::addScorch(const Coord3D *pos, Real radius, Scorches type)
  111. {
  112. if (TheTerrainRenderObject)
  113. {
  114. Vector3 loc(pos->x, pos->y, pos->z);
  115. TheTerrainRenderObject->addScorch(loc, radius, type);
  116. }
  117. }
  118. //-------------------------------------------------------------------------------------------------
  119. /** create an effect that requires a start and end location */
  120. //-------------------------------------------------------------------------------------------------
  121. void W3DGameClient::createRayEffectByTemplate( const Coord3D *start,
  122. const Coord3D *end,
  123. const ThingTemplate* tmpl )
  124. {
  125. Drawable *draw = TheThingFactory->newDrawable(tmpl);
  126. if( draw )
  127. {
  128. Coord3D pos;
  129. // add to world, the location of the drawable is at the midpoint of laser
  130. pos.x = (end->x - start->x) * 0.5f + start->x;
  131. pos.y = (end->y - start->y) * 0.5f + start->y;
  132. pos.z = (end->z - start->z) * 0.5f + start->z;
  133. draw->setPosition( &pos );
  134. // add this ray effect to the list of ray effects
  135. TheRayEffects->addRayEffect( draw, start, end );
  136. } // end if
  137. } // end createRayEffectByTemplate
  138. //-------------------------------------------------------------------------------------------------
  139. /** Tell all the drawables what time of day it is now */
  140. //-------------------------------------------------------------------------------------------------
  141. void W3DGameClient::setTimeOfDay( TimeOfDay tod )
  142. {
  143. GameClient::setTimeOfDay(tod);
  144. //tell cloud/water plane to update its lighting/texture
  145. if (TheWaterRenderObj)
  146. TheWaterRenderObj->setTimeOfDay(tod);
  147. if (TheW3DShadowManager)
  148. TheW3DShadowManager->setTimeOfDay(tod);
  149. //tell the display to update its lighting
  150. TheDisplay->setTimeOfDay( tod );
  151. } // end setTimeOfDay
  152. //-------------------------------------------------------------------------------------------------
  153. //-------------------------------------------------------------------------------------------------
  154. void W3DGameClient::setTeamColor(Int red, Int green, Int blue)
  155. {
  156. W3DStatusCircle::setColor(red, green, blue);
  157. } // end setTeamColor
  158. //-------------------------------------------------------------------------------------------------
  159. /** temporary entry point for adjusting LOD for development testing. */
  160. //-------------------------------------------------------------------------------------------------
  161. void W3DGameClient::adjustLOD( Int adj )
  162. {
  163. if (TheGlobalData == NULL)
  164. return;
  165. TheWritableGlobalData->m_textureReductionFactor += adj;
  166. if (TheWritableGlobalData->m_textureReductionFactor > 4)
  167. TheWritableGlobalData->m_textureReductionFactor = 4; //16x less resolution is probably enough.
  168. if (TheWritableGlobalData->m_textureReductionFactor < 0)
  169. TheWritableGlobalData->m_textureReductionFactor = 0;
  170. if (WW3D::Get_Texture_Reduction() != TheWritableGlobalData->m_textureReductionFactor)
  171. { WW3D::Set_Texture_Reduction(TheWritableGlobalData->m_textureReductionFactor,6);
  172. TheGameLODManager->setCurrentTextureReduction(TheWritableGlobalData->m_textureReductionFactor);
  173. }
  174. //I commented this out because we're no longer using terrain LOD. So I
  175. //stole this function and keys to adjust the texture resolution instead. -MW
  176. // if( TheTerrainRenderObject )
  177. // TheTerrainRenderObject->adjustTerrainLOD( adj );
  178. } // end adjustLOD