rendobj.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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:: /Commando/Code/ww3d2/rendobj.h $*
  25. * *
  26. * Org Author:: Greg Hjelstrom *
  27. * *
  28. * Author : Kenny Mitchell *
  29. * *
  30. * $Modtime:: 06/27/02 9:23a $*
  31. * *
  32. * $Revision:: 14 $*
  33. * *
  34. * 06/27/02 KM Shader system classid addition *
  35. * 07/01/02 KM Coltype enum change to avoid MAX conflicts *
  36. *---------------------------------------------------------------------------------------------*
  37. * Functions: *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #if defined(_MSC_VER)
  40. #pragma once
  41. #endif
  42. #ifndef RENDOBJ_H
  43. #define RENDOBJ_H
  44. #include "always.h"
  45. #include "refcount.h"
  46. #include "sphere.h"
  47. #include "coltype.h"
  48. #include "aabox.h"
  49. #include "persist.h"
  50. #include "multilist.h"
  51. #include "robjlist.h"
  52. #include <float.h>
  53. class Vector3;
  54. class Matrix3D;
  55. class MaterialInfoClass;
  56. class TextureClass;
  57. class SceneClass;
  58. class HTreeClass;
  59. class HAnimClass;
  60. class HAnimComboClass;
  61. class HCompressedAnimClass;
  62. class RayCollisionTestClass;
  63. class AABoxCollisionTestClass;
  64. class OBBoxCollisionTestClass;
  65. class AABoxIntersectionTestClass;
  66. class OBBoxIntersectionTestClass;
  67. class CameraClass;
  68. class SphereClass;
  69. class AABoxClass;
  70. class RenderInfoClass;
  71. class SpecialRenderInfoClass;
  72. class IntersectionClass;
  73. class IntersectionResultClass;
  74. class DecalGeneratorClass;
  75. class RenderObjProxyClass;
  76. class StringClass;
  77. template<class T> class DynamicVectorClass;
  78. // "unreferenced formal parameter"
  79. #pragma warning(disable : 4100)
  80. #ifdef DEFINE_W3DANIMMODE_NAMES
  81. static const char* TheAnimModeNames[] =
  82. {
  83. "MANUAL",
  84. "LOOP",
  85. "ONCE",
  86. "LOOP_PINGPONG",
  87. "LOOP_BACKWARDS",
  88. "ONCE_BACKWARDS",
  89. NULL
  90. };
  91. #endif
  92. //////////////////////////////////////////////////////////////////////////////////
  93. // RenderObjClass
  94. // This is the interface for all objects that get rendered by WW3D.
  95. //
  96. // Render object RTTI: If you really need to typecast a render object
  97. // pointer that you got from the asset manager, the class id mechanism
  98. // can be used to check what you really have. User class id's can come
  99. // after CLASSID_LAST.
  100. //
  101. // Cloning: All RenderObj's need to be able to clone themselves. This function
  102. // should create a new and separate RenderObj of the correct type and return a
  103. // RenderObj pointer to it. The implementation of this function will be
  104. // to simply call your copy constructor; its basically a virtual copy constructor.
  105. //
  106. // Rendering: If the render object is in a scene that is rendered and is determined
  107. // to be visible by that scene, it will receive a Render call. The argument
  108. // to the call will contain both the camera being used and the low level rendering
  109. // interface. In addition, the Special_Render function is for all "non-normal"
  110. // types of rendering. Some examples of this are: G-Buffer rendering (rendering
  111. // object ID's), shadow rendering (just use black, etc) and whatever else we
  112. // come up with. Basically it will be a function with a big switch statement
  113. // to handle all of these extra operations. This means the main render code
  114. // path is not cluttered with these checks while not forcing every object to
  115. // implement millions of separate special render functions. (Many objects just
  116. // pass the render calls onto their sub-objects).
  117. //
  118. // VertexProcessors: Vertex processors are classes that are not actually 'rendered'
  119. // They insert into the system an object that performs operations on all of
  120. // the subsequent vertices that are processed. Lights and Fogs are types of
  121. // vertex processors.
  122. //
  123. // "Scene Graph": A scene is organized as a list of render objects. There is no
  124. // implied hierarchical structure to a scene. RenderObjects can contain other
  125. // render objects (they follow the 'Composite' pattern) which is how hierarchical
  126. // objects are built. Hierarchical models are render objects that just
  127. // contain other render objects and apply hierarchical transforms to them.
  128. // Hierarchical Models can be inserted inside of other hierarchical models.
  129. //
  130. // Predictive LOD: The predictive LOD system selects LODs for the visible objects
  131. // so that the various resources (polys, vertices, etc.) do not pass given
  132. // budgets - the goal is to achieve a constant frame rate. This interface
  133. // includes things that are needed for this optimization process. Objects which
  134. // do not support changing their LOD should report that they have 1 LOD and
  135. // should report their cost to the LOD optimization system.
  136. //
  137. // Dependency Generation: Render objects are composed of one or more W3D and
  138. // texture files. This set of interfaces provides access to that dependency list.
  139. //
  140. //////////////////////////////////////////////////////////////////////////////////
  141. // This is a small abstract class which a render object may have a pointer to. If present, its
  142. // Pre_Render and Post_Render calls will be called before and after the Render() call of this
  143. // render object. Applications using WW3D may create concrete classes deriving from this for
  144. // application-specific pre- and post- render processing. (the return value from Pre_Render
  145. // determines whether to perform the Render() call - if false, Render() will not be called).
  146. class RenderHookClass
  147. {
  148. public:
  149. RenderHookClass(void) { }
  150. virtual ~RenderHookClass(void) { }
  151. virtual bool Pre_Render(RenderObjClass *robj, RenderInfoClass &rinfo) = 0;
  152. virtual void Post_Render(RenderObjClass *robj, RenderInfoClass &rinfo) = 0;
  153. private:
  154. // Enforce no-copy semantics, for this and derived classes. This is done by making these
  155. // private and not having definitions for them.
  156. RenderHookClass(const RenderHookClass & src);
  157. RenderHookClass & operator=(const RenderHookClass & src);
  158. };
  159. // RenderObjClass definition
  160. class RenderObjClass : public RefCountClass , public PersistClass, public MultiListObjectClass
  161. {
  162. public:
  163. //Integer flag placed at the start of structure pointed to by
  164. //User_Data to signal that it points at custom mesh material settings.
  165. //Added for 'Generals' - MW
  166. enum {USER_DATA_MATERIAL_OVERRIDE = 0x01234567};
  167. //This strucutre is used to pass custom rendering parameters into the W3D
  168. //mesh renderer so it can override settings which are usually shared across
  169. //all instances of a model - typically material settings like alpha, texture
  170. //animation, texture uv scrolling, etc. Added for 'Generals' -MW
  171. struct Material_Override
  172. { Material_Override(void) : Struct_ID(USER_DATA_MATERIAL_OVERRIDE),customUVOffset(0,0) {}
  173. int Struct_ID; //ID used to identify this structure from a pointer to it.
  174. Vector2 customUVOffset;
  175. };
  176. //
  177. // Note: It is very important that these values NEVER CHANGE. That means
  178. // when adding a new class id, it should be added to the end of the enum.
  179. //
  180. enum
  181. {
  182. CLASSID_UNKNOWN = 0xFFFFFFFF,
  183. CLASSID_MESH = 0,
  184. CLASSID_HMODEL,
  185. CLASSID_DISTLOD,
  186. CLASSID_PREDLODGROUP,
  187. CLASSID_TILEMAP,
  188. CLASSID_IMAGE3D, // Obsolete
  189. CLASSID_LINE3D,
  190. CLASSID_BITMAP2D, // Obsolete
  191. CLASSID_CAMERA,
  192. CLASSID_DYNAMESH,
  193. CLASSID_DYNASCREENMESH,
  194. CLASSID_TEXTDRAW,
  195. CLASSID_FOG,
  196. CLASSID_LAYERFOG,
  197. CLASSID_LIGHT,
  198. CLASSID_PARTICLEEMITTER,
  199. CLASSID_PARTICLEBUFFER,
  200. CLASSID_SCREENPOINTGROUP,
  201. CLASSID_VIEWPOINTGROUP,
  202. CLASSID_WORLDPOINTGROUP,
  203. CLASSID_TEXT2D,
  204. CLASSID_TEXT3D,
  205. CLASSID_NULL,
  206. CLASSID_COLLECTION,
  207. CLASSID_FLARE,
  208. CLASSID_HLOD,
  209. CLASSID_AABOX,
  210. CLASSID_OBBOX,
  211. CLASSID_SEGLINE,
  212. CLASSID_SPHERE,
  213. CLASSID_RING,
  214. CLASSID_BOUNDFOG,
  215. CLASSID_DAZZLE,
  216. CLASSID_SOUND,
  217. CLASSID_SEGLINETRAIL,
  218. CLASSID_LAND,
  219. CLASSID_SHDMESH, // mesh class that uses the scaleable shader system
  220. CLASSID_LAST = 0x0000FFFF
  221. };
  222. RenderObjClass(void);
  223. RenderObjClass(const RenderObjClass & src);
  224. RenderObjClass & RenderObjClass::operator = (const RenderObjClass &);
  225. virtual ~RenderObjClass(void) { if (RenderHook) delete RenderHook; }
  226. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  227. // Render Object Interface - Cloning and Identification
  228. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  229. virtual RenderObjClass * Clone(void) const = 0;
  230. virtual int Class_ID(void) const { return CLASSID_UNKNOWN; }
  231. virtual const char * Get_Name(void) const { return "UNNAMED"; }
  232. virtual void Set_Name(const char * name) { }
  233. virtual const char * Get_Base_Model_Name (void) const { return NULL; }
  234. virtual void Set_Base_Model_Name (const char *name) { }
  235. virtual int Get_Num_Polys(void) const { return 0; }
  236. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  237. // Render Object Interface - Rendering
  238. //
  239. // Render - this object should render its polygons. Typically called from a SceneClass
  240. // Special_Render - all special-case rendering goes here to avoid polluting the main render pipe (e.g. VIS)
  241. // On_Frame_Update - render objects can register for an On_Frame_Update call; the scene will call this once
  242. // per frame if they do so.
  243. // Restart - This interface is used to facilitate model recycling. If a render object is "Restarted" it should
  244. // put itself back into a state as if it has never been rendered (e.g. particle emitters
  245. // should reset their "emitted particle counts" so they can be re-used.)
  246. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  247. virtual void Render(RenderInfoClass & rinfo) = 0;
  248. virtual void Special_Render(SpecialRenderInfoClass & rinfo) { }
  249. virtual void On_Frame_Update() { }
  250. virtual void Restart(void) { }
  251. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  252. // Render Object Interface - "Scene Graph"
  253. // Some of the functions in this group are non-virtual as they are meant
  254. // to be never overriden or are supposed to be implemented in terms of
  255. // the other virtual functions. We want to keep the virtual interface
  256. // as small as possible
  257. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  258. virtual void Add(SceneClass * scene);
  259. virtual void Remove(void);
  260. virtual SceneClass * Get_Scene(void);
  261. virtual SceneClass * Peek_Scene(void) { return Scene; }
  262. virtual void Set_Container(RenderObjClass * con);
  263. virtual void Validate_Transform(void) const;
  264. #define GET_CONTAINER_INLINE
  265. #ifdef GET_CONTAINER_INLINE
  266. // srj sez: this is called a ton and never overridden, so inline it
  267. inline RenderObjClass * Get_Container(void) const { return Container; }
  268. #else
  269. virtual RenderObjClass * Get_Container(void) const;
  270. #endif
  271. virtual void Set_Transform(const Matrix3D &m);
  272. virtual void Set_Position(const Vector3 &v);
  273. const Matrix3D & Get_Transform(void) const;
  274. const Matrix3D & Get_Transform(bool& is_transform_identity) const;
  275. const Matrix3D & Get_Transform_No_Validity_Check(void) const;
  276. const Matrix3D & Get_Transform_No_Validity_Check(bool& is_transform_identity) const;
  277. bool Is_Transform_Identity() const;
  278. bool Is_Transform_Identity_No_Validity_Check() const;
  279. Vector3 Get_Position(void) const;
  280. virtual void Notify_Added(SceneClass * scene);
  281. virtual void Notify_Removed(SceneClass * scene);
  282. virtual int Get_Num_Sub_Objects(void) const { return 0; }
  283. virtual RenderObjClass * Get_Sub_Object(int index) const { return NULL; }
  284. virtual int Add_Sub_Object(RenderObjClass * subobj) { return 0; }
  285. virtual int Remove_Sub_Object(RenderObjClass * robj) { return 0; }
  286. virtual RenderObjClass * Get_Sub_Object_By_Name(const char * name, int *index=NULL) const;
  287. virtual int Get_Num_Sub_Objects_On_Bone(int boneindex) const { return 0; }
  288. virtual RenderObjClass * Get_Sub_Object_On_Bone(int index,int boneindex) const { return NULL; }
  289. virtual int Get_Sub_Object_Bone_Index(RenderObjClass * subobj) const { return 0; }
  290. virtual int Get_Sub_Object_Bone_Index(int LodIndex, int ModelIndex) const { return 0; }
  291. virtual int Add_Sub_Object_To_Bone(RenderObjClass * subobj,int bone_index) { return 0; }
  292. virtual int Add_Sub_Object_To_Bone(RenderObjClass * subobj,const char * bname);
  293. virtual int Remove_Sub_Objects_From_Bone(int boneindex);
  294. virtual int Remove_Sub_Objects_From_Bone(const char * bname);
  295. // This is public only so objects can recursively call this on their sub-objects
  296. virtual void Update_Sub_Object_Transforms(void);
  297. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  298. // Render Object Interface - Hierarchical Animation
  299. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  300. enum AnimMode
  301. {
  302. ANIM_MODE_MANUAL = 0,
  303. ANIM_MODE_LOOP,
  304. ANIM_MODE_ONCE,
  305. ANIM_MODE_LOOP_PINGPONG,
  306. ANIM_MODE_LOOP_BACKWARDS, //make sure only backwards playing animations after this one
  307. ANIM_MODE_ONCE_BACKWARDS,
  308. };
  309. virtual void Set_Animation( void ) { }
  310. virtual void Set_Animation( HAnimClass * motion,
  311. float frame, int anim_mode = ANIM_MODE_MANUAL) { }
  312. virtual void Set_Animation( HAnimClass * motion0,
  313. float frame0,
  314. HAnimClass * motion1,
  315. float frame1,
  316. float percentage) { }
  317. virtual void Set_Animation( HAnimComboClass * anim_combo) { }
  318. virtual HAnimClass * Peek_Animation( void ) { return NULL; }
  319. virtual int Get_Num_Bones(void) { return 0; }
  320. virtual const char * Get_Bone_Name(int bone_index) { return NULL; }
  321. virtual int Get_Bone_Index(const char * bonename) { return 0; }
  322. virtual const Matrix3D & Get_Bone_Transform(const char * bonename) { return Get_Transform(); }
  323. virtual const Matrix3D & Get_Bone_Transform(int boneindex) { return Get_Transform(); }
  324. virtual void Capture_Bone(int bindex) { }
  325. virtual void Release_Bone(int bindex) { }
  326. virtual bool Is_Bone_Captured(int bindex) const { return false; }
  327. virtual void Control_Bone(int bindex,const Matrix3D & objtm,bool world_space_translation = false) { }
  328. virtual const HTreeClass * Get_HTree(void) const { return NULL; }
  329. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  330. // Render Object Interface - Collision Detection
  331. // Cast_Ray - intersects a ray with the render object
  332. // Cast_AABox - intersects a swept AABox with the render object
  333. // Cast_OBBox - intersects a swept OBBox with the render object
  334. // Intersect_AABox - boolean test for intersection between an AABox and the renderobj
  335. // Intersect_OBBox - boolean test for intersection between an OBBox and the renderobj
  336. // Intersect - tests a ray for intersection with the render object
  337. // Intersect_Sphere - tests a ray for intersection with the bounding spheres
  338. // Intersect_Sphere_Quick - tests a ray for intersection with bounding spheres
  339. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  340. virtual bool Cast_Ray(RayCollisionTestClass & raytest) { return false; }
  341. virtual bool Cast_AABox(AABoxCollisionTestClass & boxtest) { return false; }
  342. virtual bool Cast_OBBox(OBBoxCollisionTestClass & boxtest) { return false; }
  343. virtual bool Intersect_AABox(AABoxIntersectionTestClass & boxtest) { return false; }
  344. virtual bool Intersect_OBBox(OBBoxIntersectionTestClass & boxtest) { return false; }
  345. virtual bool Intersect(IntersectionClass *Intersection, IntersectionResultClass *Final_Result);
  346. virtual bool Intersect_Sphere(IntersectionClass *Intersection, IntersectionResultClass *Final_Result);
  347. virtual bool Intersect_Sphere_Quick(IntersectionClass *Intersection, IntersectionResultClass *Final_Result);
  348. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  349. // Render Object Interface - Bounding Volumes
  350. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  351. virtual const SphereClass & Get_Bounding_Sphere(void) const;
  352. virtual const AABoxClass & Get_Bounding_Box(void) const;
  353. virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
  354. virtual void Get_Obj_Space_Bounding_Box(AABoxClass & box) const;
  355. virtual void Update_Obj_Space_Bounding_Volumes(void) { };
  356. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  357. // Render Object Interface - Predictive LOD
  358. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  359. // Two constants for Value queries, which are returned instead of the
  360. // current Value in certain cases. They are usually used as sentinels.
  361. // AT_MIN_LOD is a very large positive number, AT_MAX_LOD is negative.
  362. static const float AT_MIN_LOD;
  363. static const float AT_MAX_LOD;
  364. virtual void Prepare_LOD(CameraClass &camera);
  365. virtual void Recalculate_Static_LOD_Factors(void) { }
  366. virtual void Increment_LOD(void) { }
  367. virtual void Decrement_LOD(void) { }
  368. virtual float Get_Cost(void) const;
  369. virtual float Get_Value(void) const { return AT_MIN_LOD; }
  370. virtual float Get_Post_Increment_Value(void) const { return AT_MAX_LOD; }
  371. virtual void Set_LOD_Level(int lod) { }
  372. virtual int Get_LOD_Level(void) const { return 0; }
  373. virtual int Get_LOD_Count(void) const { return 1; }
  374. virtual void Set_LOD_Bias(float bias) { }
  375. virtual int Calculate_Cost_Value_Arrays(float screen_area, float *values, float *costs) const;
  376. virtual RenderObjClass * Get_Current_LOD(void) { Add_Ref(); return this; }
  377. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  378. // Render Object Interface - Dependency Generation
  379. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  380. //
  381. // Note: The strings contained in these lists need to be freed by the caller.
  382. // They should be freed using the delete operator.
  383. //
  384. // Be aware, these lists WILL contain duplicate entries.
  385. //
  386. virtual bool Build_Dependency_List (DynamicVectorClass<StringClass> &file_list, bool recursive=true);
  387. virtual bool Build_Texture_List (DynamicVectorClass<StringClass> &texture_file_list, bool recursive=true);
  388. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  389. // Render Object Interface - Decals
  390. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  391. virtual void Create_Decal(DecalGeneratorClass * generator) { }
  392. virtual void Delete_Decal(uint32 decal_id) { }
  393. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  394. // Render Object Interface - Attributes, Options, Properties, etc
  395. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  396. virtual MaterialInfoClass * Get_Material_Info(void) { return NULL; }
  397. virtual void Set_User_Data(void *value, bool recursive = false) { User_Data = value; };
  398. virtual void * Get_User_Data() { return User_Data; };
  399. virtual int Get_Num_Snap_Points(void) { return 0; }
  400. virtual void Get_Snap_Point(int index,Vector3 * set) { }
  401. // virtual float Calculate_Texture_Reduction_Factor(float norm_screensize);
  402. // virtual void Set_Texture_Reduction_Factor(float trf);
  403. virtual float Get_Screen_Size(CameraClass &camera);
  404. virtual void Scale(float scale) { };
  405. virtual void Scale(float scalex, float scaley, float scalez) { };
  406. virtual void Set_ObjectScale(float scale) { ObjectScale=scale;} //set's a scale factor that's factored into transform matrix. {ScaleFactor=scale; };
  407. const float Get_ObjectScale( void ) const { return ObjectScale; };
  408. void Set_ObjectColor(unsigned int color) { ObjectColor=color;} //the color that was used to modify the asset for player team color (for Generals). -MW
  409. const unsigned int Get_ObjectColor( void ) const { return ObjectColor; };
  410. virtual int Get_Sort_Level(void) const { return 0; /* SORT_LEVEL_NONE */ }
  411. virtual void Set_Sort_Level(int level) { }
  412. virtual int Is_Really_Visible(void) { return ((Bits & IS_REALLY_VISIBLE) == IS_REALLY_VISIBLE); }
  413. virtual int Is_Not_Hidden_At_All(void) { return ((Bits & IS_NOT_HIDDEN_AT_ALL) == IS_NOT_HIDDEN_AT_ALL); }
  414. virtual int Is_Visible(void) const { return (Bits & IS_VISIBLE); }
  415. virtual void Set_Visible(int onoff) { if (onoff) { Bits |= IS_VISIBLE; } else { Bits &= ~IS_VISIBLE; } }
  416. // The cheatSpy has been put on ice until later... perhaps the next patch? - M Lorenzen
  417. // virtual int Is_VisibleWithCheatSpy(void) const { return ((Bits&=~0x80) & (IS_VISIBLE); }
  418. // virtual void Set_VisibleWithCheatSpy(int onoff) { if (onoff) { Bits |= IS_VISIBLE|0x80; } else { Bits &= ~IS_VISIBLE; } }
  419. virtual int Is_Hidden(void) const { return !(Bits & IS_NOT_HIDDEN); }
  420. virtual void Set_Hidden(int onoff) { if (onoff) { Bits &= ~IS_NOT_HIDDEN; } else { Bits |= IS_NOT_HIDDEN; } }
  421. virtual int Is_Animation_Hidden(void) const { return !(Bits & IS_NOT_ANIMATION_HIDDEN); }
  422. virtual void Set_Animation_Hidden(int onoff) { if (onoff) { Bits &= ~IS_NOT_ANIMATION_HIDDEN; } else { Bits |= IS_NOT_ANIMATION_HIDDEN; } }
  423. virtual int Is_Force_Visible(void) const { return Bits & IS_FORCE_VISIBLE; }
  424. virtual void Set_Force_Visible(int onoff) { if (onoff) { Bits |= IS_FORCE_VISIBLE; } else { Bits &= ~IS_FORCE_VISIBLE; } }
  425. virtual int Is_Translucent(void) const { return Bits & IS_TRANSLUCENT; }
  426. virtual void Set_Translucent(int onoff) { if (onoff) { Bits |= IS_TRANSLUCENT; } else { Bits &= ~IS_TRANSLUCENT; } }
  427. virtual int Is_Alpha(void) const { return Bits & IS_ALPHA; }
  428. virtual void Set_Alpha(int onoff) { if (onoff) { Bits |= IS_ALPHA; } else { Bits &= ~IS_ALPHA; } }
  429. virtual int Is_Additive(void) const { return Bits & IS_ADDITIVE; }
  430. virtual void Set_Additive(int onoff) { if (onoff) { Bits |= IS_ADDITIVE; } else { Bits &= ~IS_ADDITIVE; } }
  431. virtual int Get_Collision_Type(void) const { return (Bits & COLL_TYPE_MASK); }
  432. virtual void Set_Collision_Type(int type) { Bits &= ~COLL_TYPE_MASK; Bits |= (type & COLL_TYPE_MASK) | COLL_TYPE_ALL; }
  433. virtual bool Is_Complete(void) { return false; }
  434. virtual bool Is_In_Scene(void) { return Scene != NULL; }
  435. virtual float Get_Native_Screen_Size(void) const { return NativeScreenSize; }
  436. virtual void Set_Native_Screen_Size(float screensize) { NativeScreenSize = screensize; }
  437. void Set_Sub_Objects_Match_LOD(int onoff) { if (onoff) { Bits |= SUBOBJS_MATCH_LOD; } else { Bits &= ~SUBOBJS_MATCH_LOD; } }
  438. int Is_Sub_Objects_Match_LOD_Enabled(void) { return Bits & SUBOBJS_MATCH_LOD; }
  439. void Set_Sub_Object_Transforms_Dirty(bool onoff) { if (onoff) { Bits |= SUBOBJ_TRANSFORMS_DIRTY; } else { Bits &= ~SUBOBJ_TRANSFORMS_DIRTY; } }
  440. bool Are_Sub_Object_Transforms_Dirty(void) { return (Bits & SUBOBJ_TRANSFORMS_DIRTY) != 0; }
  441. void Set_Ignore_LOD_Cost(bool onoff) { if (onoff) { Bits |= IGNORE_LOD_COST; } else { Bits &= ~IGNORE_LOD_COST; } }
  442. bool Is_Ignoring_LOD_Cost(void) { return (Bits & IGNORE_LOD_COST) != 0; }
  443. void Set_Is_Self_Shadowed() { Bits|=IS_SELF_SHADOWED; }
  444. void Unset_Is_Self_Shadowed() { Bits&=~IS_SELF_SHADOWED; }
  445. int Is_Self_Shadowed() const { return (Bits&IS_SELF_SHADOWED); }
  446. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  447. // Persistant object save-load interface
  448. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  449. virtual const PersistFactoryClass & Get_Factory (void) const;
  450. virtual bool Save (ChunkSaveClass &csave);
  451. virtual bool Load (ChunkLoadClass &cload);
  452. // Application-specific render hook:
  453. RenderHookClass * Get_Render_Hook(void) { return RenderHook; }
  454. void Set_Render_Hook(RenderHookClass *hook) { if (RenderHook) delete RenderHook; RenderHook = hook; }
  455. protected:
  456. virtual void Add_Dependencies_To_List (DynamicVectorClass<StringClass> &file_list, bool textures_only = false);
  457. virtual void Update_Cached_Bounding_Volumes(void) const;
  458. virtual void Update_Sub_Object_Bits(void);
  459. bool Bounding_Volumes_Valid(void) const { return (Bits & BOUNDING_VOLUMES_VALID) != 0; }
  460. void Invalidate_Cached_Bounding_Volumes(void) const { Bits &= ~BOUNDING_VOLUMES_VALID; }
  461. void Validate_Cached_Bounding_Volumes(void) const { Bits |= BOUNDING_VOLUMES_VALID; }
  462. enum
  463. {
  464. COLL_TYPE_MASK = 0x000000FF,
  465. IS_VISIBLE = 0x00000100,
  466. IS_NOT_HIDDEN = 0x00000200,
  467. IS_NOT_ANIMATION_HIDDEN = 0x00000400,
  468. IS_FORCE_VISIBLE = 0x00000800,
  469. BOUNDING_VOLUMES_VALID = 0x00002000,
  470. IS_TRANSLUCENT = 0x00004000, // is additive or alpha blended on any poly
  471. IGNORE_LOD_COST = 0x00008000, // used to define if we should ignore object from LOD calculations
  472. SUBOBJS_MATCH_LOD = 0x00010000, // force sub-objects to have same LOD level
  473. SUBOBJ_TRANSFORMS_DIRTY = 0x00020000, // my sub-objects need me to update their transform
  474. IS_ALPHA = 0x00040000, // added for Generals so we can default these meshes not to cast shadows. -MW
  475. IS_ADDITIVE = 0x00100000, //added for Generals so we quickly determine what type of blending is on the mesh. -MW
  476. IS_SELF_SHADOWED = 0x00080000, // the mesh is self shadowed
  477. IS_CHEATER = 0x00100000,// the new cheat spy code uses these bits, since nothing else now does
  478. IS_REALLY_VISIBLE = IS_VISIBLE | IS_NOT_HIDDEN | IS_NOT_ANIMATION_HIDDEN,
  479. IS_NOT_HIDDEN_AT_ALL = IS_NOT_HIDDEN | IS_NOT_ANIMATION_HIDDEN,
  480. DEFAULT_BITS = COLL_TYPE_ALL | IS_NOT_HIDDEN | IS_NOT_ANIMATION_HIDDEN,
  481. };
  482. mutable unsigned long Bits;
  483. Matrix3D Transform;
  484. float ObjectScale; //user applied scaling factor inside Transform matrix.
  485. unsigned int ObjectColor; //user applied coloring to the asset/prototype used to make this robj. - For Generals -MW
  486. mutable SphereClass CachedBoundingSphere;
  487. mutable AABoxClass CachedBoundingBox;
  488. float NativeScreenSize; // The screen size at which the object was designed to be viewed (used in texture resizing).
  489. mutable bool IsTransformIdentity;
  490. SceneClass * Scene;
  491. RenderObjClass * Container;
  492. void * User_Data;
  493. RenderHookClass * RenderHook;
  494. friend class SceneClass;
  495. friend class RenderObjProxyClass;
  496. };
  497. WWINLINE const SphereClass & RenderObjClass::Get_Bounding_Sphere(void) const
  498. {
  499. if (!(Bits & BOUNDING_VOLUMES_VALID)) {
  500. Update_Cached_Bounding_Volumes();
  501. }
  502. return CachedBoundingSphere;
  503. }
  504. WWINLINE const AABoxClass & RenderObjClass::Get_Bounding_Box(void) const
  505. {
  506. if (!(Bits & BOUNDING_VOLUMES_VALID)) {
  507. Update_Cached_Bounding_Volumes();
  508. }
  509. return CachedBoundingBox;
  510. }
  511. /**************************************************************************
  512. * Bound_Degrees -- Bounds a degree value between 0 and 360. *
  513. * *
  514. * INPUT: *
  515. * *
  516. * OUTPUT: *
  517. * *
  518. * WARNINGS: *
  519. * *
  520. * HISTORY: *
  521. * 09/22/1997 PWG : Created. *
  522. *========================================================================*/
  523. WWINLINE float Bound_Degrees(float angle)
  524. {
  525. while (angle > 359) angle -= 360;
  526. while (angle < 0) angle += 360;
  527. return angle;
  528. }
  529. /***********************************************************************************************
  530. * RenderObjClass::Get_Transform -- returns the transform for the object *
  531. * *
  532. * If the transform is invalid (a container has been moved or animated) then the transform *
  533. * will be recalculated. *
  534. * *
  535. * INPUT: *
  536. * *
  537. * OUTPUT: *
  538. * *
  539. * WARNINGS: *
  540. * *
  541. * HISTORY: *
  542. * 2/25/99 GTH : Created. *
  543. *=============================================================================================*/
  544. WWINLINE const Matrix3D & RenderObjClass::Get_Transform(void) const
  545. {
  546. Validate_Transform();
  547. return Transform;
  548. }
  549. WWINLINE const Matrix3D & RenderObjClass::Get_Transform(bool &is_transform_identity) const
  550. {
  551. Validate_Transform();
  552. is_transform_identity=IsTransformIdentity;
  553. return Transform;
  554. }
  555. WWINLINE bool RenderObjClass::Is_Transform_Identity() const
  556. {
  557. Validate_Transform();
  558. return IsTransformIdentity;
  559. }
  560. // Warning: Be sure to call this function only if the transform is known to be valid!
  561. WWINLINE const Matrix3D & RenderObjClass::Get_Transform_No_Validity_Check(void) const
  562. {
  563. return Transform;
  564. }
  565. // Warning: Be sure to call this function only if the transform is known to be valid!
  566. WWINLINE const Matrix3D & RenderObjClass::Get_Transform_No_Validity_Check(bool& is_transform_identity) const
  567. {
  568. is_transform_identity=IsTransformIdentity;
  569. return Transform;
  570. }
  571. // Warning: Be sure to call this function only if the transform is known to be valid!
  572. WWINLINE bool RenderObjClass::Is_Transform_Identity_No_Validity_Check() const
  573. {
  574. return IsTransformIdentity;
  575. }
  576. #endif