Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
PhysClass.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__PHYSCLASS_H
13#define TT_INCLUDE__PHYSCLASS_H
14
15#include "CullableClass.h"
16#include "engine_string.h"
17#include "PhysObserverClass.h"
18#include "RenderObjClass.h"
19#include "MaterialEffectClass.h"
20#include "PhysDefClass.h"
21class CollisionEventClass;
22class CombatPhysObserverClass;
23class ElevatorPhysClass;
24class HumanPhysClass;
25class LightEnvironmentClass;
26class MoveablePhysClass;
27class Phys3Class;
28class PhysAABoxCollisionTestClass;
29class PhysAABoxIntersectionTestClass;
30class PhysDefClass;
31class PhysMeshIntersectionTestClass;
32class PhysOBBoxCollisionTestClass;
33class PhysOBBoxIntersectionTestClass;
34class PhysRayCollisionTestClass;
35class ProjectileClass;
36class RenderInfoClass;
37class RenderObjClass;
38class RigidBodyClass;
39class SpecialRenderInfoClass;
40class StaticAnimPhysClass;
41class VehiclePhysClass;
42class DynamicPhysClass;
43class MotorVehicleClass;
44class WheeledVehicleClass;
45class MotorcycleClass;
46class TrackedVehicleClass;
47class VTOLVehicleClass;
48class StaticPhysClass;
49class DamageableStaticPhysClass;
50class DoorPhysClass;
51class DecorationPhysClass;
52class TimedDecorationPhysClass;
53class DynamicAnimPhysClass;
54class LightPhysClass;
55class RenderObjPhysClass;
56class AccessiblePhysClass;
57class LightEnvironmentClass;
58class Matrix3D;
59
60class PhysClass : public CullableClass, public PersistClass, public MultiListObjectClass
61{
62public:
63 PhysClass(void);
64 virtual ~PhysClass(void);
65 void Init(const PhysDefClass & def);
66 virtual void Definition_Changed(void) { }
67 bool Expire(void);
68 virtual bool Needs_Timestep(void) { return false; }
69 virtual void Timestep(float dt) = 0;
70 virtual void Post_Timestep_Process(void) { }
71 virtual const Matrix3D & Get_Transform(void) const = 0;
72 virtual void Set_Transform(const Matrix3D & m) = 0;
73 void Get_Position(Vector3 * set_pos) const { Get_Transform().Get_Translation(set_pos); }
74 void Set_Position(const Vector3 & pos) { Matrix3D tm = Get_Transform(); tm.Set_Translation(pos); Set_Transform(tm); }
75 float Get_Facing(void) const { return Get_Transform().Get_Z_Rotation(); }
76 void Set_Facing(float new_facing);
77 virtual bool Cast_Ray(PhysRayCollisionTestClass & raytest) { return false; }
78 virtual bool Cast_AABox(PhysAABoxCollisionTestClass & boxtest) { return false; }
79 virtual bool Cast_OBBox(PhysOBBoxCollisionTestClass & boxtest) { return false; }
80 virtual bool Intersection_Test(PhysAABoxIntersectionTestClass & test) { return false; }
81 virtual bool Intersection_Test(PhysOBBoxIntersectionTestClass & test) { return false; }
82 virtual bool Intersection_Test(PhysMeshIntersectionTestClass & test) { return false; }
83 virtual void Link_To_Carrier(PhysClass * carrier,RenderObjClass * carrier_sub_obj = NULL) { }
84 virtual RenderObjClass * Peek_Carrier_Sub_Object(void) { return NULL; }
85 virtual bool Push(const Vector3 & move) { return false; }
86 virtual bool Internal_Link_Rider(PhysClass * rider) { return false; }
87 virtual bool Internal_Unlink_Rider(PhysClass * rider) { return false; }
88 void Update_Cull_Box(void);
89 virtual void Set_Model(RenderObjClass * model);
90 void Set_Model_By_Name(const char * model_type_name);
91 RenderObjClass * Get_Model(void);
92 RenderObjClass * Peek_Model(void) { return Model; }
93 void Set_Name(const char * name);
94 const char * Get_Name(void);
95 uint32 Get_ID(void) const { return InstanceID; }
96 void Set_ID(uint32 id) { InstanceID = id; }
97 void Set_Vis_Object_ID(int new_id) { VisObjectID = new_id; }
98 virtual int Get_Vis_Object_ID(void) { return VisObjectID; }
99 virtual void Render(RenderInfoClass & rinfo);
100 virtual void Vis_Render(SpecialRenderInfoClass & rinfo);
101 void Invalidate_Static_Lighting_Cache(void);
102 LightEnvironmentClass * Get_Static_Lighting_Environment(void);
103 virtual void Render_Vis_Meshes(RenderInfoClass & rinfo) { }
104 virtual void Get_Shadow_Blob_Box(AABoxClass * set_obj_space_box);
105 virtual bool Is_Casting_Shadow(void) { return false; }
106 void Add_Effect_To_Me(MaterialEffectClass * effect);
107 void Remove_Effect_From_Me(MaterialEffectClass * effect);
108 bool Do_Any_Effects_Suppress_Shadows(void);
109 void Set_Visibility_Mode(Visibility_Mode_Type type) { Flags &= ~VISIBILITY_MODE_MASK; Flags |= ((uint)type << VISIBILITY_MODE_SHIFT) & VISIBILITY_MODE_MASK; }
110 Visibility_Mode_Type Get_Visibility_Mode() const { return (Visibility_Mode_Type)((Flags & VISIBILITY_MODE_MASK) >> VISIBILITY_MODE_SHIFT); }
111 void Set_Collision_Group(Collision_Group_Type group) { Flags &= ~(uint)COLLISION_MASK; Flags |= (uint)group & COLLISION_MASK; }
112 Collision_Group_Type Get_Collision_Group(void) const { return (Collision_Group_Type)(Flags & COLLISION_MASK); }
113 void Inc_Ignore_Counter(void);
114 void Dec_Ignore_Counter(void);
115 bool Is_Ignore_Me(void) const { return ((Flags & IGNORE_MASK) > 0); }
116 void Set_Immovable(bool onoff) { Set_Flag(IMMOVABLE,onoff); }
117 bool Is_Immovable(void) const { return Get_Flag(IMMOVABLE); }
118 void Set_Disabled(bool onoff) { Set_Flag(DISABLED,onoff); }
119 bool Is_Disabled(void) const { return Get_Flag(DISABLED); }
120 void Enable_Debug_Display(bool onoff) { (onoff ? Flags |= DEBUGDISPLAY : Flags &= ~DEBUGDISPLAY); }
121 bool Is_Debug_Display_Enabled(void) const;
122 void Enable_User_Control(bool onoff) { Set_Flag(USERCONTROL,onoff); Set_Flag(ASLEEP,false); }
123 bool Is_User_Control_Enabled(void) const { return Get_Flag(USERCONTROL); }
124 void Enable_Shadow_Generation(bool onoff) { Set_Flag(CASTSHADOW,onoff); }
125 bool Is_Shadow_Generation_Enabled(void) const { return Get_Flag(CASTSHADOW); }
126 void Enable_Force_Projection_Shadow(bool onoff) { Set_Flag(FORCE_PROJECTION_SHADOW,onoff); }
127 bool Is_Force_Projection_Shadow_Enabled(void) const { return Get_Flag(FORCE_PROJECTION_SHADOW); }
128 void Enable_Dont_Save(bool onoff) { Set_Flag(DONT_SAVE,onoff); }
129 bool Is_Dont_Save_Enabled(void) const { return Get_Flag(DONT_SAVE); }
130 bool Is_Asleep(void) const { return ((Flags & ASLEEP) == ASLEEP); }
131 void Force_Awake(void) { Set_Flag(ASLEEP,false); }
132 void Enable_Is_World_Space_Mesh(bool onoff) { Set_Flag(IS_WS_MESH,onoff); }
133 bool Is_World_Space_Mesh(void) { return Get_Flag(IS_WS_MESH); }
134 void Enable_Is_Pre_Lit(bool onoff) { Set_Flag(IS_PRE_LIT,onoff); }
135 bool Is_Pre_Lit(void); // { return Get_Flag(IS_PRE_LIT) | Model->Get_F; }
136 void Enable_Is_In_The_Sun(bool onoff) { Set_Flag(IS_IN_THE_SUN,onoff); }
137 bool Is_In_The_Sun(void) { return Get_Flag(IS_IN_THE_SUN); }
138 void Enable_Is_State_Dirty(bool onoff) { Set_Flag(IS_STATE_DIRTY,onoff); }
139 bool Is_State_Dirty(void) { return Get_Flag(IS_STATE_DIRTY); }
140 void Hide(bool onoff) { Set_Flag(HIDDEN,onoff); }
141 bool Is_Hidden(void) { return Get_Flag(HIDDEN); }
142 void Enable_Objects_Simulation(bool onoff) { Set_Flag(SIMULATION_DISABLED,!onoff); }
143 bool Is_Objects_Simulation_Enabled(void) const { return !Get_Flag(SIMULATION_DISABLED); }
144 bool Is_Object_Simulating(void) { return Is_Objects_Simulation_Enabled() && !Is_Simulation_Disabled(); }
145 void Set_Observer(PhysObserverClass * o) { Observer = o; }
146 PhysObserverClass * Get_Observer(void) { return Observer; }
147 CollisionReactionType Collision_Occurred(CollisionEventClass & event);
148 const PhysDefClass * Get_Definition(void) { return Definition; }
149 virtual DynamicPhysClass * As_DynamicPhysClass(void) { return NULL; }
150 virtual MoveablePhysClass * As_MoveablePhysClass(void) { return NULL; }
151 virtual Phys3Class * As_Phys3Class(void) { return NULL; }
152 virtual HumanPhysClass * As_HumanPhysClass(void) { return NULL; }
153 virtual RigidBodyClass * As_RigidBodyClass(void) { return NULL; }
154 virtual VehiclePhysClass * As_VehiclePhysClass(void) { return NULL; }
155 virtual MotorVehicleClass * As_MotorVehicleClass(void) { return NULL; }
156 virtual WheeledVehicleClass * As_WheeledVehicleClass(void) { return NULL; }
157 virtual MotorcycleClass * As_MotorcycleClass(void) { return NULL; }
158 virtual TrackedVehicleClass * As_TrackedVehicleClass(void) { return NULL; }
159 virtual VTOLVehicleClass * As_VTOLVehicleClass(void) { return NULL; }
160 virtual StaticPhysClass * As_StaticPhysClass(void) { return NULL; }
161 virtual StaticAnimPhysClass * As_StaticAnimPhysClass(void) { return NULL; }
162 virtual ElevatorPhysClass * As_ElevatorPhysClass(void) { return NULL; }
163 virtual DamageableStaticPhysClass * As_DamageableStaticPhysClass (void) { return NULL; }
164 virtual DoorPhysClass * As_DoorPhysClass(void) { return NULL; }
165 virtual DecorationPhysClass * As_DecorationPhysClass(void) { return NULL; }
166 virtual TimedDecorationPhysClass * As_TimedDecorationPhysClass(void) { return NULL; }
167 virtual DynamicAnimPhysClass * As_DynamicAnimPhysClass(void) { return NULL; }
168 virtual LightPhysClass * As_LightPhysClass(void) { return NULL; }
169 virtual RenderObjPhysClass * As_RenderObjPhysClass(void) { return NULL; }
170 virtual ProjectileClass * As_ProjectileClass(void) { return NULL; }
171 virtual AccessiblePhysClass * As_AccessiblePhysClass(void) { return NULL; }
172 virtual bool Save (ChunkSaveClass &csave);
173 virtual bool Load (ChunkLoadClass &cload);
174 virtual bool Is_Simulation_Disabled(void) { return false; }
175 virtual bool Is_Rendering_Disabled(void);
176 unsigned Get_Last_Visible_Frame() const { return LastVisibleFrame; }
177 void Set_Last_Visible_Frame(unsigned frame) { LastVisibleFrame=frame; }
178protected:
179 bool Get_Flag(unsigned int flag) const { return ((Flags & flag) == flag); }
180 void Set_Flag(unsigned int flag,bool onoff) { (onoff ? Flags |= flag : Flags &= ~flag); }
181 void Push_Effects(RenderInfoClass & rinfo);
182 void Pop_Effects(RenderInfoClass & rinfo);
183 virtual void Update_Sun_Status(void);
184 enum {
185 COLLISION_MASK = 0x0000001F, // bits for the collision group
186 IMMOVABLE = 0x00000100, // this object is immovable.
187 DISABLED = 0x00000200, // Some objects can be disabled (e.g. lights)
188 DEBUGDISPLAY = 0x00000400, // Render debugging aids (forces, impacts, etc)
189 USERCONTROL = 0x00000800, // Ignore physics, move according to controller directly
190 CASTSHADOW = 0x00001000, // Does this object cast a shadow?
191 FORCE_PROJECTION_SHADOW = 0x00002000, // When the shadow mode is BLOBS_PLUS, this object still uses a "proper" shadow
192 DONT_SAVE = 0x00004000, // Scene should never save this object (used for transient things like glass fragments)
193 ASLEEP = 0x00008000, // This object is not moving so its simulation was skipped
194 IS_WS_MESH = 0x00010000, // Enable the static-world-space-mesh rendering optimizations.
195 IS_PRE_LIT = 0x00020000, // Is this a light-mapped object that doesn't need static lights applied.
196 IS_IN_THE_SUN = 0x00040000, // Is this object illuminated by the sun?
197 IS_STATE_DIRTY = 0x00080000, // This object's state has changed.
198 STATIC_LIGHTING_DIRTY = 0x00100000, // This object's static lighting cache is dirty
199 FRICTION_DISABLED = 0x00200000, // Friction is disabled for this object (vehicles disable body-friction when their wheels are in contact)
200 SIMULATION_DISABLED = 0x00400000, // Turn on/off simulation for this object
201 HIDDEN = 0x00800000, // Turn off rendering for this object
202 VISIBILITY_MODE_SHIFT = 24, // shift count for the 'visibility mode'
203 VISIBILITY_MODE_MASK = 0x03000000, // mask for the 'visibility mode'
204 IGNORE_SHIFT = 28, // shift count for the 'ignore-me' counter
205 IGNORE_MASK = 0xF0000000, // mask for the 'ignore-me' counter
206 DEFAULT_FLAGS = 0,
207 };
208protected:
209 unsigned int Flags; // 0038 0050
210 RenderObjClass * Model; // 003C 0054
211 StringClass Name; // 0040 0058
212 uint32 InstanceID; // 0044 005C
213 uint32 VisObjectID; // 0048 0060
214 PhysObserverClass * Observer; // 004C 0064
215 const PhysDefClass * Definition; // 0050 0068
216 RefMultiListClass<MaterialEffectClass> MaterialEffectsOnMe; // 0054 006C
217 LightEnvironmentClass * StaticLightingCache; // 006C 006C 0088 0084
218 unsigned SunStatusLastUpdated; // 0070 0070 008C 0088
219 unsigned LastVisibleFrame; // 0074 0074 0090 008C
220
221 PhysClass(const PhysClass & src);
222 PhysClass & operator = (const PhysClass & src);
223}; // 0078 0078 0094 0090
224inline void PhysClass::Inc_Ignore_Counter(void)
225{
226 int count = (Flags & IGNORE_MASK) >> IGNORE_SHIFT;
227 count++;
228 Flags &= ~IGNORE_MASK;
229 Flags |= (count << IGNORE_SHIFT);
230}
231inline void PhysClass::Dec_Ignore_Counter(void)
232{
233 int count = (Flags & IGNORE_MASK) >> IGNORE_SHIFT;
234 count--;
235 Flags &= ~IGNORE_MASK;
236 Flags |= (count << IGNORE_SHIFT);
237}
238inline CollisionReactionType PhysClass::Collision_Occurred(CollisionEventClass & event)
239{
240 if (Observer) {
241 return Observer->Collision_Occurred(event);
242 } else {
243 return COLLISION_REACTION_DEFAULT;
244 }
245}
246inline void PhysClass::Update_Cull_Box(void)
247{
248 if (Model) {
249 Set_Cull_Box(Model->Get_Bounding_Box(),false);
250 }
251}
252inline void PhysClass::Add_Effect_To_Me(MaterialEffectClass * effect)
253{
254 MaterialEffectsOnMe.Add(effect);
255}
256inline void PhysClass::Remove_Effect_From_Me(MaterialEffectClass * effect)
257{
258 MaterialEffectsOnMe.Remove(effect);
259}
260inline bool PhysClass::Is_Pre_Lit(void)
261{
262 if (Model) {
263 return (Get_Flag(IS_PRE_LIT) | (Model->Has_User_Lighting() != 0));
264 } else {
265 return Get_Flag(IS_PRE_LIT);
266 }
267}
268
269#endif