scene.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. *** 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. virtual void Add_Render_Object(RenderObjClass * obj);
  88. virtual void Remove_Render_Object(RenderObjClass * obj);
  89. virtual SceneIterator * Create_Iterator(bool onlyvisible = false) = 0;
  90. virtual void Destroy_Iterator(SceneIterator * it) = 0;
  91. virtual void Set_Ambient_Light(const Vector3 & color) { AmbientLight = color; }
  92. virtual const Vector3 & Get_Ambient_Light(void) { return AmbientLight; }
  93. ///////////////////////////////////////////////////////////////////////////////////
  94. // Fog methods
  95. ///////////////////////////////////////////////////////////////////////////////////
  96. virtual void Set_Fog_Enable(bool set) { FogEnabled = set; }
  97. virtual bool Get_Fog_Enable(void) { return FogEnabled; }
  98. virtual void Set_Fog_Color(const Vector3 & color) { FogColor = color; }
  99. virtual const Vector3 & Get_Fog_Color(void) { return FogColor; }
  100. virtual void Set_Fog_Range( float start, float end ) { FogStart = start; FogEnd = end; }
  101. virtual void Get_Fog_Range( float * start, float * end ) { *start = FogStart; *end = FogEnd; }
  102. ///////////////////////////////////////////////////////////////////////////////////
  103. // Render Modes
  104. ///////////////////////////////////////////////////////////////////////////////////
  105. enum PolyRenderType
  106. {
  107. POINT,
  108. LINE,
  109. FILL
  110. };
  111. void Set_Polygon_Mode(PolyRenderType mode) { PolyRenderMode = mode; }
  112. PolyRenderType Get_Polygon_Mode(void) { return PolyRenderMode; }
  113. ///////////////////////////////////////////////////////////////////////////////////
  114. // Second pass render mode is a debug feature which renders the whole scene twice.
  115. ///////////////////////////////////////////////////////////////////////////////////
  116. enum ExtraPassPolyRenderType
  117. {
  118. EXTRA_PASS_DISABLE,
  119. EXTRA_PASS_LINE,
  120. EXTRA_PASS_CLEAR_LINE
  121. };
  122. void Set_Extra_Pass_Polygon_Mode(ExtraPassPolyRenderType mode) { ExtraPassPolyRenderMode = mode; }
  123. ExtraPassPolyRenderType Get_Extra_Pass_Polygon_Mode(void) { return ExtraPassPolyRenderMode; }
  124. ///////////////////////////////////////////////////////////////////////////////////
  125. // Object processing registration
  126. ///////////////////////////////////////////////////////////////////////////////////
  127. enum RegType
  128. {
  129. ON_FRAME_UPDATE = 0,
  130. LIGHT,
  131. RELEASE,
  132. };
  133. virtual void Register(RenderObjClass * obj,RegType for_what) = 0;
  134. virtual void Unregister(RenderObjClass * obj,RegType for_what) = 0;
  135. ///////////////////////////////////////////////////////////////////////////////////
  136. // Point visibility - used by DazzleRenderObj when no custom handler is installed
  137. ///////////////////////////////////////////////////////////////////////////////////
  138. virtual float Compute_Point_Visibility( RenderInfoClass & rinfo,
  139. const Vector3 & point) { return 1.0f; }
  140. ///////////////////////////////////////////////////////////////////////////////////
  141. // Save-Load, records the fog, depth cue, etc settings into a chunk
  142. ///////////////////////////////////////////////////////////////////////////////////
  143. virtual void Save(ChunkSaveClass & csave);
  144. virtual void Load(ChunkLoadClass & cload);
  145. protected:
  146. virtual void Render(RenderInfoClass & rinfo); //Made virtual so we can override -MW
  147. Vector3 AmbientLight;
  148. PolyRenderType PolyRenderMode;
  149. ExtraPassPolyRenderType ExtraPassPolyRenderMode;
  150. bool FogEnabled;
  151. Vector3 FogColor;
  152. float FogStart;
  153. float FogEnd;
  154. friend class WW3D;
  155. /*
  156. ** Not implemented!
  157. */
  158. SceneClass (const SceneClass &);
  159. SceneClass & operator == (const SceneClass &);
  160. private:
  161. virtual void Customized_Render(RenderInfoClass & rinfo)=0;
  162. virtual void Pre_Render_Processing(RenderInfoClass & rinfo) {}
  163. virtual void Post_Render_Processing(RenderInfoClass & rinfo) {}
  164. };
  165. /**
  166. ** SimpleSceneClass
  167. ** This is an example of a simple way to implement a scene class which
  168. ** can be rendered by WW3D. Basically it stores a list of render objects
  169. ** When the Render function is called, it checks each object against the
  170. ** view frustum an marks it as visible or invisible. Then it performs
  171. ** some LOD calculations on all of the visible objects, then has each
  172. ** render object add its internal (surrender) representation to the
  173. ** internal (surrender) representation of the scene.
  174. */
  175. class SimpleSceneClass : public SceneClass
  176. {
  177. public:
  178. SimpleSceneClass(void);
  179. virtual ~SimpleSceneClass(void);
  180. virtual void Add_Render_Object(RenderObjClass * obj);
  181. virtual void Remove_Render_Object(RenderObjClass * obj);
  182. virtual void Remove_All_Render_Objects(void);
  183. virtual void Register(RenderObjClass * obj,RegType for_what);
  184. virtual void Unregister(RenderObjClass * obj,RegType for_what);
  185. virtual SceneIterator * Create_Iterator(bool onlyvisible = false);
  186. virtual void Destroy_Iterator(SceneIterator * it);
  187. // Set visibility status for my render objects. If not called explicitly
  188. // beforehand, will be called inside Render().
  189. virtual void Visibility_Check(CameraClass * camera);
  190. ///////////////////////////////////////////////////////////////////////////////////
  191. // Point visibility - used by DazzleRenderObj when no custom handler is installed
  192. ///////////////////////////////////////////////////////////////////////////////////
  193. virtual float Compute_Point_Visibility( RenderInfoClass & rinfo,
  194. const Vector3 & point);
  195. protected:
  196. // Has a visibility check been performed since scene was last rendered?
  197. bool Visibility_Checked;
  198. RefRenderObjListClass RenderList;
  199. RefRenderObjListClass UpdateList;
  200. RefRenderObjListClass LightList;
  201. RefRenderObjListClass ReleaseList;
  202. friend class SimpleSceneIterator;
  203. virtual void Customized_Render(RenderInfoClass & rinfo);
  204. virtual void Post_Render_Processing(RenderInfoClass& rinfo);
  205. };
  206. #endif