00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_SECTOR_H__
00020 #define __CS_SECTOR_H__
00021
00022 #include "csgeom/math3d.h"
00023 #include "csutil/csobject.h"
00024 #include "csutil/nobjvec.h"
00025 #include "csutil/refarr.h"
00026 #include "csutil/cscolor.h"
00027 #include "iutil/objref.h"
00028 #include "csengine/light.h"
00029 #include "csengine/meshobj.h"
00030 #include "csengine/rdrprior.h"
00031 #include "iengine/sector.h"
00032 #include "ivideo/graph3d.h"
00033 #ifdef CS_USE_NEW_RENDERER
00034 #include "ivideo/rndbuf.h"
00035 #include "ivideo/shader/shader.h"
00036 #endif
00037
00038 class csEngine;
00039 class csProgressPulse;
00040 class csSector;
00041 class csStatLight;
00042 class csMeshWrapper;
00043 class csKDTree;
00044 struct iPolygon3D;
00045 struct iStatLight;
00046 struct iVisibilityCuller;
00047 struct iRenderView;
00048 struct iMeshWrapper;
00049 struct iFrustumView;
00050
00052 class csSectorLightList : public csLightList
00053 {
00054 private:
00055 csSector* sector;
00056 csKDTree* kdtree;
00057
00058 public:
00060 csSectorLightList ();
00062 virtual ~csSectorLightList ();
00064 void SetSector (csSector* s) { sector = s; }
00065
00067 virtual void PrepareItem (iLight* light);
00069 virtual void FreeItem (iLight* item);
00070
00072 csKDTree* GetLightKDTree () const { return kdtree; }
00073 };
00074
00076 class csSectorMeshList : public csMeshList
00077 {
00078 private:
00079 csSector* sector;
00080
00081 public:
00083 csSectorMeshList ();
00085 virtual ~csSectorMeshList () { RemoveAll (); }
00087 void SetSector (csSector* sec) { sector = sec; }
00088
00090 virtual void PrepareItem (iMeshWrapper* item);
00092 virtual void FreeItem (iMeshWrapper* item);
00093 };
00094
00095
00096 SCF_VERSION (csSector, 0, 0, 2);
00097
00102 class csSector : public csObject
00103 {
00104 private:
00110 csSectorMeshList meshes;
00111
00112
00113 #ifdef CS_USE_NEW_RENDERER
00114
00115 int num_objects;
00116
00118 iMeshWrapper **objects;
00119 csGrowingArray<csRenderMesh*> draw_objects;
00120 csRef<iRender3D> r3d;
00121 csRef<iShaderManager> shmgr;
00122 #endif
00123
00128 csRenderQueueSet RenderQueues;
00129
00133 csVector references;
00134
00138 csRefArray<iSectorCallback> sector_cb_vector;
00139
00144 csSectorLightList lights;
00145
00150 csColor dynamic_ambient_color;
00151
00153 csEngine* engine;
00154
00155 #ifndef CS_USE_NEW_RENDERER
00156
00157 csFog fog;
00158 #endif // CS_USE_NEW_RENDERER
00159
00164 csRef<iVisibilityCuller> culler;
00165
00166 private:
00172 virtual ~csSector ();
00173
00174 public:
00179 static bool do_portals;
00180
00187 static int cfg_reflections;
00188
00196 static bool do_radiosity;
00197
00204 int draw_busy;
00205
00206 public:
00210 csSector (csEngine*);
00211
00216 void CleanupReferences ();
00217
00218
00219
00220
00221
00222 iMeshList* GetMeshes ()
00223 { return &meshes; }
00224
00228 void RegisterMeshToCuller (iMeshWrapper* mesh);
00229
00233 void UnregisterMeshToCuller (iMeshWrapper* mesh);
00234
00239 void PrepareMesh (iMeshWrapper* mesh);
00240
00245 void UnprepareMesh (iMeshWrapper* mesh);
00246
00252 void RelinkMesh (iMeshWrapper* mesh);
00253
00254
00255
00256
00257
00261 iLightList* GetLights ()
00262 { return &lights; }
00263
00264
00265
00266
00267 void SetSectorCallback (iSectorCallback* cb)
00268 {
00269 sector_cb_vector.Push (cb);
00270 }
00271
00272 void RemoveSectorCallback (iSectorCallback* cb)
00273 {
00274 int idx = sector_cb_vector.Find (cb);
00275 if (idx != -1)
00276 sector_cb_vector.Delete (idx);
00277 }
00278
00279 int GetSectorCallbackCount () const
00280 {
00281 return sector_cb_vector.Length ();
00282 }
00283
00284 iSectorCallback* GetSectorCallback (int idx) const
00285 {
00286 return sector_cb_vector.Get (idx);
00287 }
00288
00289
00290
00291
00292
00298 bool UseCullerPlugin (const char* plugname);
00299
00304 iVisibilityCuller* GetVisibilityCuller ();
00305
00306
00307
00308
00309
00313 void PrepareDraw (iRenderView* rview);
00314
00318 void Draw (iRenderView* rview);
00319 #ifdef CS_USE_NEW_RENDERER
00320
00321 void DrawZ (iRenderView* rview);
00323 void DrawShadow (iRenderView* rview, iLight *light);
00325 void DrawLight (iRenderView* rview, iLight *light, bool drawAfter = false);
00326 #endif
00327
00328
00329
00330
00331
00339 iPolygon3D* HitBeam (const csVector3& start, const csVector3& end,
00340 csVector3& isect);
00341
00348 csMeshWrapper* HitBeam (const csVector3& start, const csVector3& end,
00349 csVector3& intersect, iPolygon3D** polygonPtr, bool accurate = false);
00350
00357 void RealCheckFrustum (iFrustumView* lview);
00358
00363 void CheckFrustum (iFrustumView* lview);
00364
00375 iPolygon3D* IntersectSphere (csVector3& center, float radius,
00376 float* pr = NULL);
00377
00396 csSector* FollowSegment (csReversibleTransform& t, csVector3& new_position,
00397 bool& mirror, bool only_portals = false);
00398
00415 iPolygon3D* IntersectSegment (const csVector3& start,
00416 const csVector3& end, csVector3& isect,
00417 float* pr = NULL, bool only_portals = false,
00418 csMeshWrapper** p_mesh = NULL);
00419
00425 void CalculateSectorBBox (csBox3& bbox, bool do_meshes) const;
00426
00427
00428
00429
00430
00440 void ShineLights (csProgressPulse* = 0);
00441
00443 void ShineLights (iMeshWrapper*, csProgressPulse* = 0);
00444
00446 void SetDynamicAmbientLight(const csColor& color);
00447
00449 csKDTree* GetLightKDTree () const { return lights.GetLightKDTree (); }
00450
00451
00452
00453
00454
00456 csEngine* GetEngine () const { return engine; }
00457
00458 #ifndef CS_USE_NEW_RENDERER
00459
00460 bool HasFog () const { return fog.enabled; }
00461
00463 csFog& GetFog () { return fog; }
00464
00466 void SetFog (float density, const csColor& color)
00467 {
00468 fog.enabled = true;
00469 fog.density = density;
00470 fog.red = color.red;
00471 fog.green = color.green;
00472 fog.blue = color.blue;
00473 }
00474
00476 void DisableFog () { fog.enabled = false; }
00477 #endif // CS_USE_NEW_RENDERER
00478
00479 SCF_DECLARE_IBASE_EXT (csObject);
00480
00481
00482 struct ReferencedObject : public iReferencedObject
00483 {
00484 SCF_DECLARE_EMBEDDED_IBASE (csSector);
00485 virtual void AddReference (iReference* ref);
00486 virtual void RemoveReference (iReference* ref);
00487 } scfiReferencedObject;
00488 friend struct ReferencedObject;
00489
00490
00491 struct eiSector : public iSector
00492 {
00493 SCF_DECLARE_EMBEDDED_IBASE (csSector);
00494
00495 virtual csSector *GetPrivateObject ()
00496 { return (csSector*)scfParent; }
00497 virtual iObject *QueryObject()
00498 { return scfParent; }
00499 virtual int GetRecLevel () const
00500 { return scfParent->draw_busy; }
00501 virtual bool SetVisibilityCullerPlugin (const char *Name)
00502 { return scfParent->UseCullerPlugin (Name); }
00503 virtual iVisibilityCuller* GetVisibilityCuller ()
00504 { return scfParent->GetVisibilityCuller (); }
00505 virtual iMeshList* GetMeshes ()
00506 { return scfParent->GetMeshes (); }
00507 virtual iLightList* GetLights ()
00508 { return scfParent->GetLights (); }
00509 virtual void ShineLights ()
00510 { scfParent->ShineLights (); }
00511 virtual void ShineLights (iMeshWrapper* mesh)
00512 { scfParent->ShineLights (mesh); }
00513 virtual void SetDynamicAmbientLight(const csColor& color)
00514 { scfParent->SetDynamicAmbientLight(color); }
00515 virtual csColor GetDynamicAmbientLight() const
00516 { return scfParent->dynamic_ambient_color; }
00517 virtual void CalculateSectorBBox (csBox3& bbox, bool do_meshes) const
00518 { scfParent->CalculateSectorBBox (bbox, do_meshes); }
00519 #ifndef CS_USE_NEW_RENDERER
00520 virtual bool HasFog () const
00521 { return scfParent->HasFog (); }
00522 virtual csFog *GetFog () const
00523 { return &scfParent->fog; }
00524 virtual void SetFog (float density, const csColor& color)
00525 { scfParent->SetFog (density, color); }
00526 virtual void DisableFog ()
00527 { scfParent->DisableFog (); }
00528 #endif // CS_USE_NEW_RENDERER
00529 virtual iPolygon3D* HitBeam (const csVector3& start, const csVector3& end,
00530 csVector3& isect);
00531 virtual iMeshWrapper* HitBeam (const csVector3& start, const csVector3& end,
00532 csVector3& intersect, iPolygon3D** polygonPtr, bool accurate = false);
00533 virtual iSector* FollowSegment (csReversibleTransform& t,
00534 csVector3& new_position, bool& mirror, bool only_portals = false);
00535 virtual void Draw (iRenderView* rview)
00536 { scfParent->Draw (rview); }
00537 #ifdef CS_USE_NEW_RENDERER
00538 virtual void DrawZ (iRenderView* rview)
00539 { scfParent->DrawZ (rview); }
00540 virtual void DrawShadow (iRenderView* rview, iLight* light)
00541 { scfParent->DrawShadow (rview, light); }
00542 virtual void DrawLight (iRenderView* rview, iLight* light)
00543 { scfParent->DrawLight (rview, light); }
00544 #endif // CS_USE_NEW_RENDERER
00545 virtual void SetSectorCallback (iSectorCallback* cb)
00546 {
00547 scfParent->SetSectorCallback (cb);
00548 }
00549 virtual void RemoveSectorCallback (iSectorCallback* cb)
00550 {
00551 scfParent->RemoveSectorCallback (cb);
00552 }
00553 virtual int GetSectorCallbackCount () const
00554 {
00555 return scfParent->GetSectorCallbackCount ();
00556 }
00557 virtual iSectorCallback* GetSectorCallback (int idx) const
00558 {
00559 return scfParent->GetSectorCallback (idx);
00560 }
00561 virtual void CheckFrustum (iFrustumView* lview)
00562 {
00563 scfParent->CheckFrustum (lview);
00564 }
00565 } scfiSector;
00566 friend struct eiSector;
00567 };
00568
00570 class csSectorList : public iSectorList
00571 {
00572 private:
00573 csRefArrayObject<iSector> list;
00574
00575 public:
00576 SCF_DECLARE_IBASE;
00577 bool CleanupReferences;
00578
00580 csSectorList (bool CleanupReferences);
00582 virtual ~csSectorList () { RemoveAll (); }
00583
00585 virtual void FreeItem (iSector* item);
00586
00587 virtual int GetCount () const { return list.Length (); }
00588 virtual iSector *Get (int n) const { return list.Get (n); }
00589 virtual int Add (iSector *obj);
00590 virtual bool Remove (iSector *obj);
00591 virtual bool Remove (int n);
00592 virtual void RemoveAll ();
00593 virtual int Find (iSector *obj) const;
00594 virtual iSector *FindByName (const char *Name) const;
00595 };
00596
00597 #endif // __CS_SECTOR_H__