13#ifndef TT_INCLUDE__PHYSICSSCENECLASS_H
14#define TT_INCLUDE__PHYSICSSCENECLASS_H
18#include "SceneClass.h"
19#include "VisTableMgrClass.h"
20#include "VisTableClass.h"
21#include "WidgetUserClass.h"
24#include "AABTreeCull.h"
31class LightEnvironmentClass;
32class PhysDecalSysClass;
34class CameraShakeSystemClass;
35class StaticAABTreeCullClass;
36class StaticLightCullClass;
37class PhysGridCullClass;
38class DynamicAABTreeCullClass;
39class AABTreeCullSystemClass;
40class GridCullSystemClass;
45class VisRenderContextClass;
49class VisSectorStatsClass;
50class VisOptProgressClass;
53class PhysicsSceneClass :
54 public SceneClass,
public WidgetUserClass
57 PhysicsSceneClass(
void);
58 virtual ~PhysicsSceneClass(
void);
59 static PhysicsSceneClass * Get_Instance(
void) {
return TheScene; }
60 void Update(
float dt,
int frameid);
61 void Pre_Render_Processing(CameraClass & camera);
62 void Post_Render_Processing(
void);
63 void Add_Dynamic_Object(PhysClass * newobj);
64 void Add_Static_Object(StaticPhysClass * newtile,
int cull_node_id = -1);
65 void Add_Dynamic_Light(LightPhysClass * light);
66 void Add_Static_Light(LightPhysClass * newlight,
int cull_node_id = -1);
67 void Remove_Object(PhysClass * obj);
68 void Remove_All(
void);
69 void Delayed_Remove_Object(PhysClass * obj);
70 void Process_Release_List(
void);
71 bool Contains(PhysClass * obj);
72 RefMultiListIterator<PhysClass> Get_Dynamic_Object_Iterator(
void);
73 RefMultiListIterator<PhysClass> Get_Static_Object_Iterator(
void);
74 RefMultiListIterator<PhysClass> Get_Static_Anim_Object_Iterator(
void);
75 RefMultiListIterator<PhysClass> Get_Static_Light_Iterator(
void);
76 MultiListIterator<TexProjectClass> Get_Static_Projector_Iterator(
void);
77 MultiListIterator<TexProjectClass> Get_Dynamic_Projector_Iterator(
void);
78 StaticPhysClass *Get_Static_Object_By_ID(uint32
id);
79 void Add_To_Dirty_Cull_List(PhysClass *obj);
80 void Remove_From_Dirty_Cull_List(PhysClass *obj);
81 bool Is_In_Dirty_Cull_List(PhysClass *obj);
83 LIGHTING_MODE_NONE = 0,
84 LIGHTING_MODE_SURRENDER,
87 int Get_Lighting_Mode(
void) {
return LightingMode;}
88 void Set_Lighting_Mode(
int mode) {LightingMode = mode;}
89 virtual void Set_Ambient_Light(
const Vector3 &color) {SceneAmbientLight = color;}
90 virtual const Vector3 &Get_Ambient_Light(
void) {
return SceneAmbientLight;}
91 void Set_Lighting_LOD_Cutoff(
float intensity);
92 float Get_Lighting_LOD_Cutoff(
void);
93 bool Is_Sun_Light_Enabled(
void);
94 void Enable_Sun_Light(
bool onoff);
95 LightClass *Get_Sun_Light(
void);
96 void Set_Sun_Light_Orientation(
float rotation,
float elevation);
97 void Get_Sun_Light_Orientation(
float * set_rotation,
float * set_elevation);
98 void Get_Sun_Light_Vector(Vector3 * set_vector);
99 void Compute_Static_Lighting(LightEnvironmentClass *light_env,
const Vector3 & obj_center,
bool use_sun,
int vis_object_id);
100 void Invalidate_Lighting_Caches(
const AABoxClass & bounds);
101 void Set_Collision_Region(
const AABoxClass & bounds,
int colgroup);
102 void Release_Collision_Region(
void);
103 SCRIPTS_API
bool Cast_Ray(PhysRayCollisionTestClass & raytest,
bool use_collision_region =
false);
104 SCRIPTS_API
bool Cast_AABox(PhysAABoxCollisionTestClass & boxtest,
bool use_collision_region =
false);
105 SCRIPTS_API
bool Cast_OBBox(PhysOBBoxCollisionTestClass & boxtest,
bool use_collision_region =
false);
106 bool Intersection_Test(PhysAABoxIntersectionTestClass & boxtest,
bool use_collision_region =
false);
107 bool Intersection_Test(PhysOBBoxIntersectionTestClass & boxtest,
bool use_collision_region =
false);
108 bool Intersection_Test(PhysMeshIntersectionTestClass & meshtest,
bool use_collision_region =
false);
109 bool Intersection_Test(
const AABoxClass & box,
int collision_group,
int collision_type,
bool use_collision_region =
false);
110 bool Intersection_Test(
const OBBoxClass & box,
int collision_group,
int collision_type,
bool use_collision_region =
false);
111 void Force_Dynamic_Objects_Awake(
const AABoxClass & box);
112 void Collect_Objects(
const Vector3 & point,
bool static_objs,
bool dynamic_objs,MultiListClass<PhysClass> * list);
113 void Collect_Objects(
const AABoxClass & box,
bool static_objs,
bool dynamic_objs,MultiListClass<PhysClass> * list);
114 SCRIPTS_API
void Collect_Objects(
const OBBoxClass & box,
bool static_objs,
bool dynamic_objs,MultiListClass<PhysClass> * list);
115 void Collect_Objects(
const FrustumClass & frustum,
bool static_objs,
bool dynamic_objs,MultiListClass<PhysClass> * list);
116 void Collect_Collideable_Objects(
const AABoxClass & box,
int colgroup,
bool static_objs,
bool dynamic_objs,MultiListClass<PhysClass> * list);
117 void Collect_Collideable_Objects(
const OBBoxClass & box,
int colgroup,
bool static_objs,
bool dynamic_objs,MultiListClass<PhysClass> * list);
118 void Collect_Lights(
const Vector3 & point,
bool static_lights,
bool dynamic_lights,MultiListClass<PhysClass> * list);
119 void Collect_Lights(
const AABoxClass & bounds,
bool static_lights,
bool dynamic_lights,MultiListClass<PhysClass> * list);
120 StaticPhysClass *Find_Static_Object(
int instance_id);
122 COLLISION_GROUP_WORLD = 0x0F,
123 MAX_COLLISION_GROUP = 0x1F,
124 NUM_COLLISION_FLAGS = 1024,
125 COLLISION_FLAG_SHIFT = 5,
127 void Enable_Collision_Detection(
int group0,
int group1);
128 void Disable_Collision_Detection(
int group0,
int group1);
129 void Enable_All_Collision_Detections(
int group);
130 void Disable_All_Collision_Detections(
int group);
131 bool Do_Groups_Collide(
int group0,
int group1);
132 void Re_Partition_Static_Objects(
void);
133 void Re_Partition_Static_Lights(
void);
134 void Re_Partition_Static_Projectors(
void);
135 void Re_Partition_Dynamic_Culling_System(
void);
136 void Re_Partition_Dynamic_Culling_System(DynamicVectorClass<AABoxClass> & virtual_occludees);
137 void Update_Culling_System_Bounding_Boxes(
void);
138 bool Verify_Culling_Systems(StringClass & set_error_report);
139 void Enable_Vis(
bool onoff);
140 void Invert_Vis(
bool onoff);
141 void Set_Vis_Quick_And_Dirty(
bool onoff);
142 void Enable_Vis_Sector_Display(
bool onoff);
143 void Enable_Vis_Sector_History_Display(
bool onoff);
144 void Enable_Vis_Sector_Fallback(
bool onoff);
145 void Enable_Backface_Occluder_Debug(
bool onoff);
146 bool Is_Vis_Enabled(
void);
147 bool Is_Vis_Inverted(
void);
148 bool Is_Vis_Quick_And_Dirty(
void);
149 bool Is_Vis_Sector_Display_Enabled(
void);
150 bool Is_Vis_Sector_History_Display_Enabled(
void);
151 bool Is_Vis_Sector_Missing(
void);
152 bool Is_Vis_Sector_Fallback_Enabled(
void);
153 bool Is_Backface_Occluder_Debug_Enabled(
void);
154 void Lock_Vis_Sample_Point(
bool onoff);
155 bool Is_Vis_Sample_Point_Locked(
void);
156 void Compute_Vis_Sample_Point(
const CameraClass & camera,Vector3 * set_point);
157 VisTableClass *Get_Vis_Table(
int vis_sector_id);
158 VisTableClass *Get_Vis_Table(
const Vector3 & point);
159 VisTableClass *Get_Vis_Table(
const CameraClass & camera);
160 VisTableClass *Get_Vis_Table_For_Rendering(
const CameraClass & camera);
161 virtual void On_Vis_Occluders_Rendered(VisRenderContextClass & context,VisSampleClass & sample) {}
163 VIS_GRID_DISPLAY_NONE = 0,
164 VIS_GRID_DISPLAY_ACTUAL_BOXES,
165 VIS_GRID_DISPLAY_CENTERS,
166 VIS_GRID_DISPLAY_OCCUPIED
168 void Set_Vis_Grid_Display_Mode(
int mode);
169 int Get_Vis_Grid_Display_Mode(
void);
170 void Vis_Grid_Debug_Reset_Node(
void);
171 bool Vis_Grid_Debug_Enter_Parent(
void);
172 bool Vis_Grid_Debug_Enter_Sibling(
void);
173 bool Vis_Grid_Debug_Enter_Front_Child(
void);
174 bool Vis_Grid_Debug_Enter_Back_Child(
void);
175 uint32 Get_Dynamic_Object_Vis_ID(
const AABoxClass & obj_bounds,
int * node_id = NULL);
176 void Debug_Display_Dynamic_Vis_Node(
int node_id);
177 virtual void Reset_Vis(
bool doitnow =
false);
178 void Validate_Vis(
void);
179 int Allocate_Vis_Object_ID(
int count = 1);
180 int Allocate_Vis_Sector_ID(
int count = 1);
181 int Get_Vis_Table_Size(
void);
182 int Get_Vis_Table_Count(
void);
183 int Get_Static_Light_Count(
void);
184 void Generate_Vis_For_Light(
int light_index);
185 void Export_Vis_Data(ChunkSaveClass & csave);
186 void Import_Vis_Data(ChunkLoadClass & cload);
187 void Show_Vis_Window(
bool onoff);
188 bool Is_Vis_Window_Visible(
void);
190 void Enable_Static_Projectors(
bool onoff);
191 bool Are_Static_Projectors_Enabled(
void);
192 void Set_Static_Shadow_Resolution(uint res);
193 uint Get_Static_Shadow_Resolution();
194 void Enable_Dynamic_Projectors(
bool onoff);
195 bool Are_Dynamic_Projectors_Enabled(
void);
196 void Set_Dynamic_Shadow_Resolution(uint res);
197 uint Get_Dynamic_Shadow_Resolution();
198 void Add_Static_Texture_Projector(TexProjectClass* newprojector);
199 void Remove_Static_Texture_Projector(TexProjectClass* projector);
200 void Add_Dynamic_Texture_Projector(TexProjectClass* newprojector);
201 void Remove_Dynamic_Texture_Projector(TexProjectClass* projector);
202 void Remove_Texture_Projector(TexProjectClass* projector);
203 bool Contains(TexProjectClass* projector);
207 SHADOW_MODE_NONE = 0,
209 SHADOW_MODE_BLOBS_PLUS,
210 SHADOW_MODE_HARDWARE,
214 void Set_Shadow_Mode(ShadowEnum shadow_mode);
215 ShadowEnum Get_Shadow_Mode(
void);
216 void Set_Shadow_Attenuation(
float znear,
float zfar);
217 void Get_Shadow_Attenuation(
float * set_znear,
float * set_zfar);
218 void Set_Shadow_Normal_Intensity(
float normal_intensity);
219 float Get_Shadow_Normal_Intensity(
void);
220 void Set_Shadow_Resolution(
unsigned int res);
221 unsigned int Get_Shadow_Resolution(
void);
222 void Set_Max_Simultaneous_Shadows(
unsigned int count);
223 unsigned int Get_Max_Simultaneous_Shadows(
void);
224 CameraClass *Get_Shadow_Camera(
void);
225 SpecialRenderInfoClass *Get_Shadow_Render_Context();
226 MaterialPassClass *Get_Shadow_Material_Pass(
void);
227 void Invalidate_Static_Shadow_Projectors(
void);
228 void Generate_Static_Shadow_Projectors(
void);
229 void Generate_Static_Directional_Shadow(StaticAnimPhysClass& obj,
const Vector3& light_dir);
230 void Generate_Vis_Statistics_Report(DynamicVectorClass<VisSectorStatsClass> & report);
231 void Optimize_Visibility_Data(VisOptProgressClass & progress_status);
232 VisSampleClass Update_Vis(
const Matrix3D & camera,VisDirBitsType direction_bits);
233 VisSampleClass Update_Vis(
const Vector3 & sample_point,
const Matrix3D & camera,VisDirBitsType direction_bits,CameraClass * alternate_camera = NULL,
int user_vis_id = -1);
235 int Create_Decal(
const Matrix3D &tm,
const char *texture_name,
float radius,
bool is_permanent =
false,
bool apply_to_translucent_polys =
false,PhysClass *only_this_obj = NULL);
236 bool Remove_Decal(uint32
id);
237 void Shatter_Mesh(MeshClass * mesh,
const Vector3 & impact_point,
const Vector3 & impact_normal,
const Vector3 & impact_velocity);
238 void Add_Camera_Shake(
const Vector3 & position,
float radius = 50.0f,
float duration = 1.5f,
float power = 1.0f);
239 void Apply_Camera_Shakes( CameraClass & camera );
240 bool Is_Vis_Reset_Needed (
void)
const {
return VisResetNeeded; }
241 void Vis_Reset_Needed(
bool needed) { VisResetNeeded = needed; }
242 void Save_Level_Static_Data(ChunkSaveClass & csave);
243 void Load_Level_Static_Data(ChunkLoadClass & cload);
244 void Post_Load_Level_Static_Data(
void);
245 void Save_Level_Static_Objects(ChunkSaveClass & csave);
246 void Load_Level_Static_Objects(ChunkLoadClass & cload);
247 void Post_Load_Level_Static_Objects(
void);
248 void Save_Level_Dynamic_Data(ChunkSaveClass & csave);
249 void Load_Level_Dynamic_Data(ChunkLoadClass & cload);
250 void Post_Load_Level_Dynamic_Data(
void);
251 void Set_Polygon_Budgets(
int static_count,
int dynamic_count);
252 void Get_Polygon_Budgets(
int * static_count,
int * dynamic_count);
254 void Refresh_Polygon_Budgets();
256 void Set_Update_Only_Visible_Objects(
bool b) { UpdateOnlyVisibleObjects=b; }
257 bool Get_Update_Only_Visible_Objects() {
return UpdateOnlyVisibleObjects; }
258 virtual void Add_Render_Object(RenderObjClass * obj);
259 virtual void Remove_Render_Object(RenderObjClass * obj);
260 virtual SceneIterator *Create_Iterator(
bool) {
return NULL;}
261 virtual void Destroy_Iterator(SceneIterator *) {}
262 virtual void Register(RenderObjClass * obj,RegType for_what);
263 virtual void Unregister(RenderObjClass * obj,RegType for_what);
264 SCRIPTS_API
void Get_Level_Extents (Vector3 &min, Vector3 &max);
265 void Enable_Debug_Display(
bool onoff) { DebugDisplayEnabled = onoff; }
266 bool Is_Debug_Display_Enabled(
void) {
return DebugDisplayEnabled; }
267 void Enable_Projector_Debug_Display(
bool onoff) { ProjectorDebugDisplayEnabled = onoff; }
268 bool Is_Projector_Debug_Display_Enabled(
void) {
return ProjectorDebugDisplayEnabled; }
269 void Enable_Dirty_Cull_Debug_Display(
bool onoff) { DirtyCullDebugDisplayEnabled = onoff; }
270 bool Is_Dirty_Cull_Debug_Display_Enabled(
void) {
return DirtyCullDebugDisplayEnabled; }
271 void Enable_Lighting_Debug_Display(
bool onoff) { LightingDebugDisplayEnabled = onoff; }
272 bool Is_Lighting_Debug_Display_Enabled(
void) {
return LightingDebugDisplayEnabled; }
273 const Vector3 &Get_Last_Camera_Position(
void) {
return LastCameraPosition; }
280 int CullNodesAccepted;
281 int CullNodesTriviallyAccepted;
282 int CullNodesRejected;
284 void Per_Frame_Statistics_Update(
void);
285 const StatsStruct &Get_Statistics(
void);
286 float Compute_Vis_Mesh_Ram(
void);
288 virtual void Customized_Render(RenderInfoClass & rinfo);
289 void Render_Objects(RenderInfoClass& rinfo,RefMultiListClass<PhysClass> * static_ws_list,RefMultiListClass<PhysClass> * static_list,RefMultiListClass<PhysClass> * dyn_list);
290 void Render_Object(RenderInfoClass & context,PhysClass * obj);
291 void Render_Backface_Occluders(RenderInfoClass & context,RefMultiListClass<PhysClass> * static_ws_list,RefMultiListClass<PhysClass> * static_list);
292 void Optimize_LODs(CameraClass & camera,RefMultiListClass<PhysClass> * dyn_obj_list,RefMultiListClass<PhysClass> * static_obj_list,RefMultiListClass<PhysClass> * static_ws_mesh_list);
293 void Release_Vis_Resources(
void);
294 virtual void Internal_Vis_Reset(
void);
295 CameraClass *Get_Vis_Camera(
void);
296 void Vis_Render_And_Scan(VisRenderContextClass & context,VisSampleClass & sample);
297 void Merge_Vis_Sector_IDs(uint32 id0,uint32 id1);
298 void Merge_Vis_Object_IDs(uint32 id0,uint32 id1);
300 void Release_Projector_Resources(
void);
302 void Apply_Projectors(
const CameraClass & camera);
303 void Apply_Projector_To_Objects(TexProjectClass * tex_proj,
const CameraClass & camera);
304 float Compute_Projector_Attenuation(TexProjectClass * dynamic_projector,
const Vector3 & view_pos,
const Vector3 & view_dir);
306 void Allocate_Decal_Resources(
void);
307 void Release_Decal_Resources(
void);
309 void Save_LDD_Variables(ChunkSaveClass & csave);
310 void Save_Static_Objects(ChunkSaveClass & csave);
311 void Save_Dynamic_Objects(ChunkSaveClass & csave);
312 void Save_Static_Lights(ChunkSaveClass & csave);
313 void Save_Static_Object_States(ChunkSaveClass & csave);
314 void Load_LDD_Variables(ChunkLoadClass & cload);
315 void Load_Static_Objects(ChunkLoadClass & cload);
316 void Load_Dynamic_Objects(ChunkLoadClass & cload);
317 void Load_Static_Lights(ChunkLoadClass & cload);
318 void Load_Static_Object_States(ChunkLoadClass & cload);
319 void Internal_Add_Dynamic_Object(PhysClass * newobj);
320 void Internal_Add_Static_Object(StaticPhysClass * newtile);
321 void Internal_Add_Static_Light(LightPhysClass * newlight);
322 void Reset_Sun_Light(
void);
323 void Load_Sun_Light(ChunkLoadClass & cload);
324 void Save_Sun_Light(ChunkSaveClass & csave);
325 void Add_Collected_Objects_To_List(
bool static_objs,
bool dynamic_objs,MultiListClass<PhysClass> * list);
326 void Add_Collected_Collideable_Objects_To_List(
int colgroup,
bool static_objs,
bool dynamic_objs,MultiListClass<PhysClass> * list);
327 void Add_Collected_Lights_To_List(
bool static_lights,
bool dynamic_lights,MultiListClass<PhysClass> * list);
328 RefMultiListClass<PhysClass> VisibleStaticObjectList;
329 RefMultiListClass<PhysClass> VisibleWSMeshList;
330 RefMultiListClass<PhysClass> VisibleDynamicObjectList;
331 MultiListClass<TexProjectClass> ActiveTextureProjectors;
333 Vector3 LastCameraPosition;
335 bool DebugDisplayEnabled;
336 bool ProjectorDebugDisplayEnabled;
337 bool DirtyCullDebugDisplayEnabled;
338 bool LightingDebugDisplayEnabled;
339 StatsStruct LastValidStats;
340 StatsStruct CurrentStats;
341 bool StaticProjectorsDirty;
344 VIS_RENDER_WIDTH = 256,
345 VIS_RENDER_HEIGHT = 256
349 bool VisQuickAndDirty;
351 bool VisSectorDisplayEnabled;
352 bool VisSectorHistoryEnabled;
353 int VisGridDisplayMode;
354 bool VisSectorMissing;
355 bool VisSectorFallbackEnabled;
356 bool BackfaceDebugEnabled;
357 bool VisSamplePointLocked;
358 Vector3 LockedVisSamplePoint;
359 CameraClass *VisCamera;
360 VisTableClass *CurrentVisTable;
361 bool StaticProjectorsEnabled;
362 bool DynamicProjectorsEnabled;
363 ShadowEnum ShadowMode;
364 float ShadowAttenStart;
365 float ShadowAttenEnd;
366 float ShadowNormalIntensity;
367 TextureClass *ShadowBlobTexture;
368 SpecialRenderInfoClass *ShadowRenderContext;
369 CameraClass *ShadowCamera;
370 MaterialPassClass *ShadowMaterialPass;
373 PhysDecalSysClass *DecalSystem;
374 PathfindClass *Pathfinder;
375 CameraShakeSystemClass *CameraShakeSystem;
376 RefMultiListClass<RenderObjClass> UpdateList;
377 RefMultiListClass<RenderObjClass> VertexProcList;
378 RefMultiListClass<PhysClass> ReleaseList;
379 MaterialPassClass *HighlightMaterialPass;
380 StaticAABTreeCullClass *StaticCullingSystem;
381 StaticLightCullClass *StaticLightingSystem;
382 PhysGridCullClass *DynamicCullingSystem;
383 DynamicAABTreeCullClass *DynamicObjVisSystem;
384 TypedAABTreeCullSystemClass<TexProjectClass> *StaticProjectorCullingSystem;
385 TypedGridCullSystemClass<TexProjectClass> *DynamicProjectorCullingSystem;
386 VisTableMgrClass VisTableManager;
388 Vector3 SceneAmbientLight;
392 LightClass *SunLight;
393 static bool AllowCollisionFlags[NUM_COLLISION_FLAGS];
394 int DynamicPolyBudget;
395 int StaticPolyBudget;
396 RefMultiListClass<PhysClass> ObjList;
397 RefMultiListClass<PhysClass> StaticObjList;
398 RefMultiListClass<PhysClass> StaticLightList;
399 MultiListClass<TexProjectClass> StaticProjectorList;
400 MultiListClass<TexProjectClass> DynamicProjectorList;
401 RefMultiListClass<PhysClass> DirtyCullList;
402 RefMultiListClass<PhysClass> TimestepList;
403 RefMultiListClass<PhysClass> StaticAnimList;
404 MultiListClass<PhysClass> CollisionRegionList;
405 bool UpdateOnlyVisibleObjects;
407 unsigned CurrentFrameNumber;
410 SCRIPTS_API
static REF_DECL(PhysicsSceneClass*, TheScene);
412 static PhysicsSceneClass *TheScene;
415 friend class VisOptimizationContextClass;
417 float mapStaticPolyBudget;
418 float mapDynamicPolyBudget;