12#ifndef TT_INCLUDE__PHYSCLASS_H
13#define TT_INCLUDE__PHYSCLASS_H
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;
25class LightEnvironmentClass;
26class MoveablePhysClass;
28class PhysAABoxCollisionTestClass;
29class PhysAABoxIntersectionTestClass;
31class PhysMeshIntersectionTestClass;
32class PhysOBBoxCollisionTestClass;
33class PhysOBBoxIntersectionTestClass;
34class PhysRayCollisionTestClass;
39class SpecialRenderInfoClass;
40class StaticAnimPhysClass;
41class VehiclePhysClass;
42class DynamicPhysClass;
43class MotorVehicleClass;
44class WheeledVehicleClass;
46class TrackedVehicleClass;
47class VTOLVehicleClass;
49class DamageableStaticPhysClass;
51class DecorationPhysClass;
52class TimedDecorationPhysClass;
53class DynamicAnimPhysClass;
55class RenderObjPhysClass;
56class AccessiblePhysClass;
57class LightEnvironmentClass;
60class PhysClass :
public CullableClass,
public PersistClass,
public MultiListObjectClass
64 virtual ~PhysClass(
void);
65 void Init(
const PhysDefClass & def);
66 virtual void Definition_Changed(
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);
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; }
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);
185 COLLISION_MASK = 0x0000001F,
186 IMMOVABLE = 0x00000100,
187 DISABLED = 0x00000200,
188 DEBUGDISPLAY = 0x00000400,
189 USERCONTROL = 0x00000800,
190 CASTSHADOW = 0x00001000,
191 FORCE_PROJECTION_SHADOW = 0x00002000,
192 DONT_SAVE = 0x00004000,
194 IS_WS_MESH = 0x00010000,
195 IS_PRE_LIT = 0x00020000,
196 IS_IN_THE_SUN = 0x00040000,
197 IS_STATE_DIRTY = 0x00080000,
198 STATIC_LIGHTING_DIRTY = 0x00100000,
199 FRICTION_DISABLED = 0x00200000,
200 SIMULATION_DISABLED = 0x00400000,
202 VISIBILITY_MODE_SHIFT = 24,
203 VISIBILITY_MODE_MASK = 0x03000000,
205 IGNORE_MASK = 0xF0000000,
210 RenderObjClass * Model;
214 PhysObserverClass * Observer;
215 const PhysDefClass * Definition;
216 RefMultiListClass<MaterialEffectClass> MaterialEffectsOnMe;
217 LightEnvironmentClass * StaticLightingCache;
218 unsigned SunStatusLastUpdated;
219 unsigned LastVisibleFrame;
221 PhysClass(
const PhysClass & src);
222 PhysClass & operator = (
const PhysClass & src);
224inline void PhysClass::Inc_Ignore_Counter(
void)
226 int count = (Flags & IGNORE_MASK) >> IGNORE_SHIFT;
228 Flags &= ~IGNORE_MASK;
229 Flags |= (count << IGNORE_SHIFT);
231inline void PhysClass::Dec_Ignore_Counter(
void)
233 int count = (Flags & IGNORE_MASK) >> IGNORE_SHIFT;
235 Flags &= ~IGNORE_MASK;
236 Flags |= (count << IGNORE_SHIFT);
238inline CollisionReactionType PhysClass::Collision_Occurred(CollisionEventClass & event)
241 return Observer->Collision_Occurred(event);
243 return COLLISION_REACTION_DEFAULT;
246inline void PhysClass::Update_Cull_Box(
void)
249 Set_Cull_Box(Model->Get_Bounding_Box(),
false);
252inline void PhysClass::Add_Effect_To_Me(MaterialEffectClass * effect)
254 MaterialEffectsOnMe.Add(effect);
256inline void PhysClass::Remove_Effect_From_Me(MaterialEffectClass * effect)
258 MaterialEffectsOnMe.Remove(effect);
260inline bool PhysClass::Is_Pre_Lit(
void)
263 return (Get_Flag(IS_PRE_LIT) | (Model->Has_User_Lighting() != 0));
265 return Get_Flag(IS_PRE_LIT);