scene.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WW3D *
  23. * *
  24. * $Archive:: /VSS_Sync/ww3d2/scene.h $*
  25. * *
  26. * $Author:: Vss_sync $*
  27. * *
  28. * $Modtime:: 8/29/01 7:29p $*
  29. * *
  30. * $Revision:: 10 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef SCENE_H
  39. #define SCENE_H
  40. #include "always.h"
  41. #include "refcount.h"
  42. #include "vector3.h"
  43. #include "robjlist.h"
  44. #include "wwdebug.h"
  45. class RenderObjClass;
  46. class RenderInfoClass;
  47. class CameraClass;
  48. class ChunkLoadClass;
  49. class ChunkSaveClass;
  50. /*
  51. ** SceneIterator
  52. ** This object is used to iterate through the render objects
  53. ** in a scene.
  54. */
  55. class SceneIterator
  56. {
  57. public:
  58. virtual ~SceneIterator(void) { };
  59. virtual void First(void) = 0;
  60. virtual void Next(void) = 0;
  61. virtual bool Is_Done(void) = 0;
  62. virtual RenderObjClass * Current_Item(void) = 0;
  63. protected:
  64. SceneIterator(void) { };
  65. };
  66. /**
  67. ** SceneClass
  68. ** This is a bunch of render objects that define a 3D scene.
  69. ** The requirements of a SceneClass are:
  70. ** - The ablility to pass its renderobject's internal surrender representation
  71. ** to surrender when asked in the Render method.
  72. ** - The ability to add and remove render objects from the scene
  73. ** - The ability to create an iterator for the user which uses the
  74. ** SceneIterator interface and allows the user to iterate through
  75. ** all render objects or visible render objects in the scene.
  76. **
  77. ** The "registration" interface is used by certain render objects to enable
  78. ** extra processing. For example, particle emmitters/buffers need to be updated
  79. ** each frame regardless of whether they are visible so they are registered
  80. ** for "ON_FRAME_UPDATE" processing.
  81. */
  82. class SceneClass : public RefCountClass
  83. {
  84. public:
  85. SceneClass(void);
  86. virtual ~SceneClass(void);
  87. ///////////////////////////////////////////////////////////////////////////////////
  88. // RTTI information.
  89. ///////////////////////////////////////////////////////////////////////////////////
  90. enum {
  91. SCENE_ID_UNKOWN = 0xFFFFFFFF,
  92. SCENE_ID_SCENE = 0,
  93. SCENE_ID_SIMPLE,
  94. SCENE_ID_LAST = 0x0000FFFF,
  95. };
  96. virtual int Get_Scene_ID(void) const { return SCENE_ID_SCENE; }
  97. virtual void Add_Render_Object(RenderObjClass * obj);
  98. virtual void Remove_Render_Object(RenderObjClass * obj);
  99. virtual SceneIterator * Create_Iterator(bool onlyvisible = false) = 0;
  100. virtual void Destroy_Iterator(SceneIterator * it) = 0;
  101. virtual void Set_Ambient_Light(const Vector3 & color) { AmbientLight = color; }
  102. virtual const Vector3 & Get_Ambient_Light(void) { return AmbientLight; }
  103. ///////////////////////////////////////////////////////////////////////////////////
  104. // Fog methods
  105. ///////////////////////////////////////////////////////////////////////////////////
  106. virtual void Set_Fog_Enable(bool set) { FogEnabled = set; }
  107. virtual bool Get_Fog_Enable(void) { return FogEnabled; }
  108. virtual void Set_Fog_Color(const Vector3 & color) { FogColor = color; }
  109. virtual const Vector3 & Get_Fog_Color(void) { return FogColor; }
  110. virtual void Set_Fog_Range( float start, float end ) { FogStart = start; FogEnd = end; }
  111. virtual void Get_Fog_Range( float * start, float * end ) { *start = FogStart; *end = FogEnd; }
  112. ///////////////////////////////////////////////////////////////////////////////////
  113. // Render Modes
  114. ///////////////////////////////////////////////////////////////////////////////////
  115. enum PolyRenderType
  116. {
  117. POINT,
  118. LINE,
  119. FILL
  120. };
  121. void Set_Polygon_Mode(PolyRenderType mode) { PolyRenderMode = mode; }
  122. PolyRenderType Get_Polygon_Mode(void) { return PolyRenderMode; }
  123. ///////////////////////////////////////////////////////////////////////////////////
  124. // Second pass render mode is a debug feature which renders the whole scene twice.
  125. ///////////////////////////////////////////////////////////////////////////////////
  126. enum ExtraPassPolyRenderType
  127. {
  128. EXTRA_PASS_DISABLE,
  129. EXTRA_PASS_LINE,
  130. EXTRA_PASS_CLEAR_LINE
  131. };
  132. void Set_Extra_Pass_Polygon_Mode(ExtraPassPolyRenderType mode) { ExtraPassPolyRenderMode = mode; }
  133. ExtraPassPolyRenderType Get_Extra_Pass_Polygon_Mode(void) { return ExtraPassPolyRenderMode; }
  134. ///////////////////////////////////////////////////////////////////////////////////
  135. // Object processing registration
  136. ///////////////////////////////////////////////////////////////////////////////////
  137. enum RegType
  138. {
  139. ON_FRAME_UPDATE = 0,
  140. LIGHT,
  141. RELEASE,
  142. };
  143. virtual void Register(RenderObjClass * obj,RegType for_what) = 0;
  144. virtual void Unregister(RenderObjClass * obj,RegType for_what) = 0;
  145. ///////////////////////////////////////////////////////////////////////////////////
  146. // Point visibility - used by DazzleRenderObj when no custom handler is installed
  147. ///////////////////////////////////////////////////////////////////////////////////
  148. virtual float Compute_Point_Visibility( RenderInfoClass & rinfo,
  149. const Vector3 & point) { return 1.0f; }
  150. ///////////////////////////////////////////////////////////////////////////////////
  151. // Save-Load, records the fog, depth cue, etc settings into a chunk
  152. ///////////////////////////////////////////////////////////////////////////////////
  153. virtual void Save(ChunkSaveClass & csave);
  154. virtual void Load(ChunkLoadClass & cload);
  155. protected:
  156. virtual void Render(RenderInfoClass & rinfo); //Made virtual so we can override -MW
  157. Vector3 AmbientLight;
  158. PolyRenderType PolyRenderMode;
  159. ExtraPassPolyRenderType ExtraPassPolyRenderMode;
  160. bool FogEnabled;
  161. Vector3 FogColor;
  162. float FogStart;
  163. float FogEnd;
  164. friend class WW3D;
  165. /*
  166. ** Not implemented!
  167. */
  168. SceneClass (const SceneClass &);
  169. SceneClass & operator == (const SceneClass &);
  170. private:
  171. virtual void Customized_Render(RenderInfoClass & rinfo)=0;
  172. virtual void Pre_Render_Processing(RenderInfoClass & rinfo) {}
  173. virtual void Post_Render_Processing(RenderInfoClass & rinfo) {}
  174. };
  175. /**
  176. ** SimpleSceneClass
  177. ** This is an example of a simple way to implement a scene class which
  178. ** can be rendered by WW3D. Basically it stores a list of render objects
  179. ** When the Render function is called, it checks each object against the
  180. ** view frustum an marks it as visible or invisible. Then it performs
  181. ** some LOD calculations on all of the visible objects, then has each
  182. ** render object add its internal (surrender) representation to the
  183. ** internal (surrender) representation of the scene.
  184. */
  185. class SimpleSceneClass : public SceneClass
  186. {
  187. public:
  188. SimpleSceneClass(void);
  189. virtual ~SimpleSceneClass(void);
  190. virtual int Get_Scene_ID(void) { return SCENE_ID_SIMPLE; }
  191. virtual void Add_Render_Object(RenderObjClass * obj);
  192. virtual void Remove_Render_Object(RenderObjClass * obj);
  193. virtual void Remove_All_Render_Objects(void);
  194. virtual void Register(RenderObjClass * obj,RegType for_what);
  195. virtual void Unregister(RenderObjClass * obj,RegType for_what);
  196. virtual SceneIterator * Create_Iterator(bool onlyvisible = false);
  197. virtual void Destroy_Iterator(SceneIterator * it);
  198. // Set visibility status for my render objects. If not called explicitly
  199. // beforehand, will be called inside Render().
  200. virtual void Visibility_Check(CameraClass * camera);
  201. ///////////////////////////////////////////////////////////////////////////////////
  202. // Point visibility - used by DazzleRenderObj when no custom handler is installed
  203. ///////////////////////////////////////////////////////////////////////////////////
  204. virtual float Compute_Point_Visibility( RenderInfoClass & rinfo,
  205. const Vector3 & point);
  206. protected:
  207. // Has a visibility check been performed since scene was last rendered?
  208. bool Visibility_Checked;
  209. RefRenderObjListClass RenderList;
  210. RefRenderObjListClass UpdateList;
  211. RefRenderObjListClass LightList;
  212. RefRenderObjListClass ReleaseList;
  213. friend class SimpleSceneIterator;
  214. virtual void Customized_Render(RenderInfoClass & rinfo);
  215. virtual void Post_Render_Processing(RenderInfoClass& rinfo);
  216. };
  217. #endif