Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
RenderObjClass.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12#ifndef TT_INCLUDE__RENDEROBJCLASS_H
13#define TT_INCLUDE__RENDEROBJCLASS_H
14
15#include "Matrix3D.h"
16#include "Vector3.h"
17#include "AABoxClass.h"
18#include "SphereClass.h"
19#include "engine_vector.h"
20#include "Persist.h"
21#include "engine_string.h"
22
23class AABoxClass;
24class AABoxCollisionTestClass;
25class AABoxIntersectionTestClass;
26class CameraClass;
27class DecalGeneratorClass;
28class HAnimClass;
29class HAnimComboClass;
30class HTreeClass;
31class IntersectionClass;
32class IntersectionResultClass;
33class OBBoxCollisionTestClass;
34class OBBoxIntersectionTestClass;
35class RayCollisionTestClass;
36class RenderInfoClass;
37class SceneClass;
38class SpecialRenderInfoClass;
39class SphereClass;
40class MaterialInfoClass;
41class RenderObjClass;
42
43class RenderObjClass : public RefCountClass, public PersistClass, public MultiListObjectClass
44{
45
46
47protected:
48 mutable unsigned long Bits; // 0018 0030
49 Matrix3D Transform; // 001C 0034
50 mutable SphereClass CachedBoundingSphere; // 004C 0064
51 mutable AABoxClass CachedBoundingBox; // 005C 0074
52 float NativeScreenSize; // 0074 008C
53 mutable bool IsTransformIdentity; // 0078 0090
54 SceneClass* Scene; // 007C 0094
55 RenderObjClass* Container; // 0080 0098
56 void* User_Data; // 0084 009C
57
58
59public:
60
61 enum AnimMode {
62 ANIM_MODE_MANUAL = 0,
63 ANIM_MODE_LOOP,
64 ANIM_MODE_ONCE,
65 };
66 enum {
67 COLLISION_TYPE_MASK = 0xff,
68 IS_VISIBLE = 0x100,
69 IS_NOT_HIDDEN = 0x200,
70 IS_NOT_ANIMATION_HIDDEN = 0x400,
71 IS_FORCE_VISIBLE = 0x800,
72 BOUNDING_VOLUMES_VALID = 0x2000,
73 IS_TRANSLUCENT = 0x4000,
74 SUBOBJS_MATCH_LOD = 0x10000,
75 SUBOBJ_TRANSFORMS_DIRTY = 0x20000,
76 HAS_USER_LIGHTING = 0x40000,
77 IS_REALLY_VISIBLE = 0x700,
78 IS_NOT_HIDDEN_AT_ALL = 0x600,
79 DEFAULT_BITS = 0x601,
80 };
81
82 enum
83 {
84 CLASSID_UNKNOWN = 0xFFFFFFFF,
85 CLASSID_MESH = 0,
86 CLASSID_HMODEL,
87 CLASSID_DISTLOD,
88 CLASSID_PREDLODGROUP,
89 CLASSID_TILEMAP,
90 CLASSID_IMAGE3D, // Obsolete
91 CLASSID_LINE3D,
92 CLASSID_BITMAP2D, // Obsolete
93 CLASSID_CAMERA,
94 CLASSID_DYNAMESH,
95 CLASSID_DYNASCREENMESH,
96 CLASSID_TEXTDRAW,
97 CLASSID_FOG,
98 CLASSID_LAYERFOG,
99 CLASSID_LIGHT,
100 CLASSID_PARTICLEEMITTER,
101 CLASSID_PARTICLEBUFFER,
102 CLASSID_SCREENPOINTGROUP,
103 CLASSID_VIEWPOINTGROUP,
104 CLASSID_WORLDPOINTGROUP,
105 CLASSID_TEXT2D,
106 CLASSID_TEXT3D,
107 CLASSID_NULL,
108 CLASSID_COLLECTION,
109 CLASSID_FLARE,
110 CLASSID_HLOD,
111 CLASSID_AABOX,
112 CLASSID_OBBOX,
113 CLASSID_SEGLINE,
114 CLASSID_SPHERE,
115 CLASSID_RING,
116 CLASSID_BOUNDFOG,
117 CLASSID_DAZZLE,
118 CLASSID_SOUND,
119 CLASSID_SEGLINETRAIL,
120 CLASSID_LAND,
121 CLASSID_RENEGADE_TERRAIN,
122 // New classes!
123 CLASSID_USERCLIPPLANECAMERA,
124 CLASSID_PLANEREFLECTIONCAMERA,
125 CLASSID_SCENEUI,
126 CLASSID_DEBUGVECTOR,
127 CLASSID_LAST = 0x0000FFFF
128 };
129
130 RenderObjClass();
131 RenderObjClass(const RenderObjClass& src);
132 RenderObjClass& operator=(const RenderObjClass& that);
133 virtual ~RenderObjClass() {}
134
135 virtual RenderObjClass* Clone () const = 0;
136 virtual int Class_ID () const { return CLASSID_UNKNOWN; }
137 virtual const char* Get_Name () const { return "UNNAMED"; }
138 virtual void Set_Name (const char*) { }
139 virtual const char* Get_Base_Model_Name () const { return NULL; }
140 virtual void Set_Base_Model_Name (const char*) { }
141 virtual int Get_Num_Polys () const { return 0; }
142 virtual void Render (RenderInfoClass&) = 0;
143 virtual void Special_Render (SpecialRenderInfoClass&) { }
144 virtual void On_Frame_Update () { }
145 virtual void Restart () { }
146 virtual void Add (SceneClass*);
147 virtual void Remove ();
148 virtual SceneClass* Get_Scene ();
149 virtual SceneClass* Peek_Scene () { return Scene; }
150 virtual void Set_Container (RenderObjClass*);
151 virtual RenderObjClass* Get_Container () const;
152 virtual void Validate_Transform () const;
153 virtual void Set_Transform (const Matrix3D&);
154 virtual void Set_Position (const Vector3&);
155 const Matrix3D & Get_Transform(void) const;
156 const Matrix3D & Get_Transform(bool& is_transform_identity) const;
157 const Matrix3D & Get_Transform_No_Validity_Check(void) const;
158 const Matrix3D & Get_Transform_No_Validity_Check(bool& is_transform_identity) const;
159 bool Is_Transform_Identity() const;
160 bool Is_Transform_Identity_No_Validity_Check() const;
161 Vector3 Get_Position(void) const;
162 virtual void Notify_Added (SceneClass*);
163 virtual void Notify_Removed (SceneClass*);
164 virtual int Get_Num_Sub_Objects () const { return 0; }
165 virtual RenderObjClass* Get_Sub_Object (int index) const { return NULL; }
166 virtual int Add_Sub_Object (RenderObjClass*) { return 0; }
167 virtual int Remove_Sub_Object (RenderObjClass*) { return 0; }
168 virtual RenderObjClass* Get_Sub_Object_By_Name (const char* name) const;
169 virtual int Get_Num_Sub_Objects_On_Bone (int boneIndex) const { return 0; }
170 virtual RenderObjClass* Get_Sub_Object_On_Bone (int index, int boneIndex) const { return NULL; }
171 virtual int Get_Sub_Object_Bone_Index (RenderObjClass* object) const { return 0; }
172 virtual int Add_Sub_Object_To_Bone (RenderObjClass*, int boneIndex) { return 0; }
173 virtual int Add_Sub_Object_To_Bone (RenderObjClass*, const char*);
174 virtual int Remove_Sub_Objects_From_Bone (const char* boneName);
175 virtual void Update_Sub_Object_Transforms ();
176 virtual void Set_Animation () { }
177 virtual void Set_Animation (HAnimClass*, float, int anim_mode = ANIM_MODE_MANUAL) { }
178 virtual void Set_Animation (HAnimClass*, float, HAnimClass*, float, float) { }
179 virtual void Set_Animation (HAnimComboClass*) { }
180 virtual HAnimClass* Peek_Animation () { return NULL; }
181 virtual int Get_Num_Bones () { return 0; }
182 virtual const char* Get_Bone_Name (int boneIndex) { return NULL; }
183 virtual int Get_Bone_Index (const char* boneName) { return 0; }
184 virtual const Matrix3D& Get_Bone_Transform (const char* boneName) { return Get_Transform(); }
185 virtual const Matrix3D& Get_Bone_Transform (int boneIndex) { return Get_Transform(); }
186 virtual void Capture_Bone (int boneIndex) { }
187 virtual void Release_Bone (int boneIndex) { }
188 virtual bool Is_Bone_Captured (int boneIndex) const { return false; }
189 virtual void Control_Bone (int boneIndex, const Matrix3D&, bool b = false) { }
190 virtual const HTreeClass * Get_HTree(void) const { return NULL; }
191 virtual bool Cast_Ray (RayCollisionTestClass&) { return false; }
192 virtual bool Cast_AABox (AABoxCollisionTestClass&) { return false; }
193 virtual bool Cast_OBBox (OBBoxCollisionTestClass&) { return false; }
194 virtual bool Intersect_AABox (AABoxIntersectionTestClass&) { return false; }
195 virtual bool Intersect_OBBox (OBBoxIntersectionTestClass&) { return false; }
196 virtual bool Intersect (IntersectionClass*, IntersectionResultClass*);
197 virtual bool Intersect_Sphere (IntersectionClass*, IntersectionResultClass*);
198 virtual bool Intersect_Sphere_Quick (IntersectionClass*, IntersectionResultClass*);
199 virtual const SphereClass& Get_Bounding_Sphere () const;
200 virtual const AABoxClass& Get_Bounding_Box () const;
201 virtual void Get_Obj_Space_Bounding_Sphere (SphereClass&) const;
202 virtual void Get_Obj_Space_Bounding_Box (AABoxClass&) const;
203 virtual void Update_Obj_Space_Bounding_Volumes () { }
204 static const float AT_MIN_LOD;
205 static const float AT_MAX_LOD;
206 virtual void Prepare_LOD (CameraClass&);
207 virtual void Recalculate_Static_LOD_Factors () { }
208 virtual void Increment_LOD () { }
209 virtual void Decrement_LOD () { }
210 virtual float Get_Cost () const;
211 virtual float Get_Value () const { return AT_MIN_LOD; }
212 virtual float Get_Post_Increment_Value () const { return AT_MAX_LOD; }
213 virtual void Set_LOD_Level (int) { }
214 virtual int Get_LOD_Level () const { return 0; }
215 virtual int Get_LOD_Count () const { return 1; }
216 virtual void Set_LOD_Bias (float) { }
217 virtual int Calculate_Cost_Value_Arrays (float, float*, float*) const;
218 virtual RenderObjClass * Get_Current_LOD () { Add_Ref(); return this; }
219 virtual bool Build_Dependency_List (DynamicVectorClass<StringClass> &file_list, bool recursive=true);
220 virtual bool Build_Texture_List (DynamicVectorClass<StringClass> &texture_file_list, bool recursive=true);
221 virtual void Create_Decal (DecalGeneratorClass*) { }
222 virtual void Delete_Decal (uint32) { }
223 virtual MaterialInfoClass* Get_Material_Info () { return NULL; }
224 virtual void Set_User_Data (void* value, bool) { User_Data = value; };
225 virtual void* Get_User_Data () { return User_Data; };
226 virtual int Get_Num_Snap_Points () { return 0; }
227 virtual void Get_Snap_Point (int, Vector3*) { }
228 virtual float Get_Screen_Size (CameraClass&);
229 virtual void Scale (float) { };
230 virtual void Scale (float, float, float) { };
231 virtual int Get_Sort_Level () const { return 0;}
232 virtual void Set_Sort_Level (int) { }
233 virtual int Is_Really_Visible () { return ((Bits & IS_REALLY_VISIBLE) == IS_REALLY_VISIBLE); }
234 virtual int Is_Not_Hidden_At_All () { return ((Bits & IS_NOT_HIDDEN_AT_ALL) == IS_NOT_HIDDEN_AT_ALL); }
235 virtual int Is_Visible () const { return (Bits & IS_VISIBLE); }
236 virtual void Set_Visible (int onoff) { if (onoff) { Bits |= IS_VISIBLE; } else { Bits &= ~IS_VISIBLE; } }
237 virtual int Is_Hidden () const { return !(Bits & IS_NOT_HIDDEN); }
238 virtual void Set_Hidden (int onoff) { if (onoff) { Bits &= ~IS_NOT_HIDDEN; } else { Bits |= IS_NOT_HIDDEN; } }
239 virtual int Is_Animation_Hidden () const { return !(Bits & IS_NOT_ANIMATION_HIDDEN); }
240 virtual void Set_Animation_Hidden (int onoff) { if (onoff) { Bits &= ~IS_NOT_ANIMATION_HIDDEN; } else { Bits |= IS_NOT_ANIMATION_HIDDEN; } }
241 virtual int Is_Force_Visible () const { return Bits & IS_FORCE_VISIBLE; }
242 virtual void Set_Force_Visible (int onoff) { if (onoff) { Bits |= IS_FORCE_VISIBLE; } else { Bits &= ~IS_FORCE_VISIBLE; } }
243 virtual int Has_User_Lighting () const { return Bits & HAS_USER_LIGHTING; }
244 virtual void Set_Has_User_Lighting (bool onoff) { if (onoff) { Bits |= HAS_USER_LIGHTING; } else { Bits &= ~HAS_USER_LIGHTING; } }
245 virtual int Is_Translucent () const { return Bits & IS_TRANSLUCENT; }
246 virtual void Set_Translucent (int onoff) { if (onoff) { Bits |= IS_TRANSLUCENT; } else { Bits &= ~IS_TRANSLUCENT; } }
247 virtual int Get_Collision_Type () const { return (Bits & COLLISION_TYPE_MASK); }
248 virtual void Set_Collision_Type (int type) { Bits &= ~COLLISION_TYPE_MASK; Bits |= (type & COLLISION_TYPE_MASK) | 1; }
249 virtual bool Is_Complete () { return false; }
250 virtual bool Is_In_Scene () { return Scene != NULL; }
251 virtual float Get_Native_Screen_Size () const { return NativeScreenSize; }
252 virtual void Set_Native_Screen_Size (float screensize) { NativeScreenSize = screensize; }
253 virtual const PersistFactoryClass& Get_Factory () const;
254 virtual bool Save (ChunkSaveClass& oSave);
255 virtual bool Load (ChunkLoadClass& oLoad);
256 virtual void Save_User_Lighting (ChunkSaveClass&);
257 virtual void Load_User_Lighting (ChunkLoadClass&);
258 virtual void Add_Dependencies_To_List (DynamicVectorClass<StringClass> &file_list, bool textures_only = false);
259 virtual void Update_Cached_Bounding_Volumes () const;
260 virtual void Update_Sub_Object_Bits ();
261 void Set_Sub_Objects_Match_LOD(int onoff) { if (onoff) { Bits |= SUBOBJS_MATCH_LOD; } else { Bits &= ~SUBOBJS_MATCH_LOD; } }
262 int Is_Sub_Objects_Match_LOD_Enabled(void) { return Bits & SUBOBJS_MATCH_LOD; }
263 void Set_Sub_Object_Transforms_Dirty(bool onoff) { if (onoff) { Bits |= SUBOBJ_TRANSFORMS_DIRTY; } else { Bits &= ~SUBOBJ_TRANSFORMS_DIRTY; } }
264 bool Are_Sub_Object_Transforms_Dirty(void);
265 bool Bounding_Volumes_Valid(void) const;
266 void Invalidate_Cached_Bounding_Volumes(void) const { Bits &= ~BOUNDING_VOLUMES_VALID; }
267 void Validate_Cached_Bounding_Volumes(void) const { Bits |= BOUNDING_VOLUMES_VALID; }
268 void Save_Sub_Object_User_Lighting(ChunkSaveClass & csave,RenderObjClass * sub_obj,int bone_index);
269 void Load_Sub_Object_User_Lighting(ChunkLoadClass & cload);
270 void Set_User_Lighting_Flag(); //Set the HAS_USER_LIGHTING flag appropriatly for this renderobj, intended to be called during vertex solve.
271
272 void Register_For_Rendering(bool hint_static = false);
273
274}; // 0088 00A0
275
276TT_INLINE const SphereClass & RenderObjClass::Get_Bounding_Sphere(void) const
277{
278 if (!Bounding_Volumes_Valid()) {
279 Update_Cached_Bounding_Volumes();
280 }
281 return CachedBoundingSphere;
282}
283TT_INLINE const AABoxClass & RenderObjClass::Get_Bounding_Box(void) const
284{
285 if (!Bounding_Volumes_Valid()) {
286 Update_Cached_Bounding_Volumes();
287 }
288 return CachedBoundingBox;
289}
290TT_INLINE float Bound_Degrees(float angle)
291{
292 while (angle > 359) angle -= 360;
293 while (angle < 0) angle += 360;
294 return angle;
295}
296TT_INLINE const Matrix3D & RenderObjClass::Get_Transform(void) const
297{
298 Validate_Transform();
299 return Transform;
300}
301TT_INLINE const Matrix3D & RenderObjClass::Get_Transform(bool &is_transform_identity) const
302{
303 Validate_Transform();
304 is_transform_identity=IsTransformIdentity;
305 return Transform;
306}
307TT_INLINE bool RenderObjClass::Is_Transform_Identity() const
308{
309 Validate_Transform();
310 return IsTransformIdentity;
311}
312TT_INLINE const Matrix3D & RenderObjClass::Get_Transform_No_Validity_Check(void) const
313{
314 return Transform;
315}
316TT_INLINE const Matrix3D & RenderObjClass::Get_Transform_No_Validity_Check(bool& is_transform_identity) const
317{
318 is_transform_identity=IsTransformIdentity;
319 return Transform;
320}
321TT_INLINE bool RenderObjClass::Is_Transform_Identity_No_Validity_Check() const
322{
323 return IsTransformIdentity;
324}
325
326typedef RefMultiListClass<RenderObjClass> RefRenderObjListClass;
327typedef RefMultiListIterator<RenderObjClass> RefRenderObjListIterator;
328
329typedef MultiListClass<RenderObjClass> NonRefRenderObjListClass;
330typedef MultiListIterator<RenderObjClass> NonRefRenderObjListIterator;
331
332#endif