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/cscolor.h"
00026 #include "iutil/objref.h"
00027 #include "ivideo/graph3d.h"
00028 #include "csengine/light.h"
00029 #include "csengine/meshobj.h"
00030 #include "csengine/rdrprior.h"
00031 #include "iengine/sector.h"
00032
00033 class csEngine;
00034 class csProgressPulse;
00035 class csSector;
00036 class csStatLight;
00037 class csMeshWrapper;
00038 class csPolygon3D;
00039 struct iStatLight;
00040 struct iVisibilityCuller;
00041 struct iRenderView;
00042 struct iMeshWrapper;
00043 struct iFrustumView;
00044
00046 class csSectorLightList : public csLightList
00047 {
00048 private:
00049 csSector* sector;
00050
00051 public:
00053 csSectorLightList ();
00055 ~csSectorLightList ();
00057 void SetSector (csSector* s) { sector = s; }
00058
00060 virtual bool PrepareItem (csSome Item);
00062 virtual bool FreeItem (csSome Item);
00063 };
00064
00066 class csSectorMeshList : public csMeshList
00067 {
00068 private:
00069 csSector* sector;
00070
00071 public:
00073 csSectorMeshList ();
00075 ~csSectorMeshList ();
00077 void SetSector (csSector* sec) { sector = sec; }
00078
00080 virtual bool PrepareItem (csSome item);
00082 virtual bool FreeItem (csSome item);
00083 };
00084
00085
00086 SCF_VERSION (csSector, 0, 0, 2);
00087
00092 class csSector : public csObject
00093 {
00094 private:
00100 csSectorMeshList meshes;
00101
00106 csRenderQueueSet RenderQueues;
00107
00111 csVector references;
00112
00117 csSectorLightList lights;
00118
00120 csEngine* engine;
00121
00123 csFog fog;
00124
00129 iMeshWrapper* culler_mesh;
00130
00135 iVisibilityCuller* culler;
00136
00137 private:
00143 virtual ~csSector ();
00144
00145 public:
00150 static bool do_portals;
00151
00158 static int cfg_reflections;
00159
00167 static bool do_radiosity;
00168
00175 int draw_busy;
00176
00177 public:
00181 csSector (csEngine*);
00182
00187 void CleanupReferences ();
00188
00189
00190
00191
00192
00193 iMeshList* GetMeshes ()
00194 { return &(meshes.scfiMeshList); }
00195
00200 void PrepareMesh (iMeshWrapper* mesh);
00201
00206 void UnprepareMesh (iMeshWrapper* mesh);
00207
00213 void RelinkMesh (iMeshWrapper* mesh);
00214
00215
00216
00217
00218
00222 iLightList* GetLights ()
00223 { return &lights.scfiLightList; }
00224
00225
00226
00227
00228
00232 iMeshWrapper* GetCullerMesh () const { return culler_mesh; }
00233
00238 void UseCuller (const char* meshname);
00239
00244 iVisibilityCuller* GetVisibilityCuller () const { return culler; }
00245
00246
00247
00248
00249
00253 void Draw (iRenderView* rview);
00254
00255
00256
00257
00258
00266 csPolygon3D* HitBeam (const csVector3& start, const csVector3& end,
00267 csVector3& isect);
00268
00275 csMeshWrapper* HitBeam (const csVector3& start, const csVector3& end,
00276 csVector3& intersect, csPolygon3D** polygonPtr);
00277
00284 void RealCheckFrustum (iFrustumView* lview);
00285
00290 void CheckFrustum (iFrustumView* lview);
00291
00298 csObject** GetVisibleObjects (iFrustumView* lview, int& num_objects);
00299
00310 csPolygon3D* IntersectSphere (csVector3& center, float radius,
00311 float* pr = NULL);
00312
00331 csSector* FollowSegment (csReversibleTransform& t, csVector3& new_position,
00332 bool& mirror, bool only_portals = false);
00333
00350 csPolygon3D* IntersectSegment (const csVector3& start,
00351 const csVector3& end, csVector3& isect,
00352 float* pr = NULL, bool only_portals = false,
00353 csMeshWrapper** p_mesh = NULL);
00354
00360 void CalculateSectorBBox (csBox3& bbox, bool do_meshes) const;
00361
00362
00363
00364
00365
00375 void ShineLights (csProgressPulse* = 0);
00376
00378 void ShineLights (iMeshWrapper*, csProgressPulse* = 0);
00379
00380
00381
00382
00383
00385 csEngine* GetEngine () const { return engine; }
00386
00388 bool HasFog () const { return fog.enabled; }
00389
00391 csFog& GetFog () { return fog; }
00392
00394 void SetFog (float density, const csColor& color)
00395 {
00396 fog.enabled = true;
00397 fog.density = density;
00398 fog.red = color.red;
00399 fog.green = color.green;
00400 fog.blue = color.blue;
00401 }
00402
00404 void DisableFog () { fog.enabled = false; }
00405
00406 SCF_DECLARE_IBASE_EXT (csObject);
00407
00408
00409 struct ReferencedObject : public iReferencedObject
00410 {
00411 SCF_DECLARE_EMBEDDED_IBASE (csSector);
00412 virtual void AddReference (iReference* ref);
00413 virtual void RemoveReference (iReference* ref);
00414 } scfiReferencedObject;
00415 friend struct ReferencedObject;
00416
00417
00418 struct eiSector : public iSector
00419 {
00420 SCF_DECLARE_EMBEDDED_IBASE (csSector);
00421
00422 virtual csSector *GetPrivateObject ()
00423 { return (csSector*)scfParent; }
00424 virtual iObject *QueryObject()
00425 { return scfParent; }
00426 virtual int GetRecLevel () const
00427 { return scfParent->draw_busy; }
00428 virtual void SetVisibilityCuller (const char *Name)
00429 { scfParent->UseCuller (Name); }
00430 virtual iVisibilityCuller* GetVisibilityCuller () const
00431 { return scfParent->GetVisibilityCuller (); }
00432 virtual iMeshList* GetMeshes ()
00433 { return scfParent->GetMeshes (); }
00434 virtual iLightList* GetLights ()
00435 { return scfParent->GetLights (); }
00436 virtual void ShineLights ()
00437 { scfParent->ShineLights (); }
00438 virtual void ShineLights (iMeshWrapper* mesh)
00439 { scfParent->ShineLights (mesh); }
00440 virtual void CalculateSectorBBox (csBox3& bbox, bool do_meshes) const
00441 { scfParent->CalculateSectorBBox (bbox, do_meshes); }
00442 virtual bool HasFog () const
00443 { return scfParent->HasFog (); }
00444 virtual csFog *GetFog () const
00445 { return &scfParent->fog; }
00446 virtual void SetFog (float density, const csColor& color)
00447 { scfParent->SetFog (density, color); }
00448 virtual void DisableFog ()
00449 { scfParent->DisableFog (); }
00450 virtual iPolygon3D* HitBeam (const csVector3& start, const csVector3& end,
00451 csVector3& isect);
00452 virtual iMeshWrapper* HitBeam (const csVector3& start, const csVector3& end,
00453 csVector3& intersect, iPolygon3D** polygonPtr);
00454 virtual iSector* FollowSegment (csReversibleTransform& t,
00455 csVector3& new_position, bool& mirror, bool only_portals = false);
00456 virtual void Draw (iRenderView* rview)
00457 { scfParent->Draw (rview); }
00458 } scfiSector;
00459 friend struct eiSector;
00460 };
00461
00462 CS_DECLARE_OBJECT_VECTOR (csSectorListHelper, iSector);
00463
00464 class csSectorList : public csSectorListHelper
00465 {
00466 public:
00467 SCF_DECLARE_IBASE;
00468 bool CleanupReferences;
00469
00471 csSectorList (bool CleanupReferences);
00473 ~csSectorList ();
00474
00476 virtual bool FreeItem (csSome Item);
00477
00478 class SectorList : public iSectorList
00479 {
00480 public:
00481 SCF_DECLARE_EMBEDDED_IBASE (csSectorList);
00482
00483 virtual int GetCount () const;
00484 virtual iSector *Get (int n) const;
00485 virtual int Add (iSector *obj);
00486 virtual bool Remove (iSector *obj);
00487 virtual bool Remove (int n);
00488 virtual void RemoveAll ();
00489 virtual int Find (iSector *obj) const;
00490 virtual iSector *FindByName (const char *Name) const;
00491 } scfiSectorList;
00492 };
00493
00494 #endif // __CS_SECTOR_H__