00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_TREEOBJ_H__
00020 #define __CS_TREEOBJ_H__
00021
00022 #include "csutil/csvector.h"
00023 #include "csgeom/math3d.h"
00024 #include "csgeom/box.h"
00025 #include "csengine/polyint.h"
00026 #include "csengine/polytree.h"
00027
00028 class csObject;
00029 class csPolygonStubPool;
00030 class csPolygonInt;
00031 class csPolygonIntPool;
00032 class csPolygonTreeNode;
00033 class csPolyTreeBBox;
00034 class csThing;
00035
00041 class csPolygonStub
00042 {
00043 friend class csPolyTreeBBox;
00044 friend class csPolygonTreeNode;
00045 friend class csPolygonStubPool;
00046
00047 private:
00048
00049 csPolygonStub* next_tree, * prev_tree;
00050
00051 csPolygonStub* next_obj, * prev_obj;
00052
00053 csPolyTreeBBox* object;
00054
00055 csPolygonTreeNode* node;
00056
00057
00058 int ref_count;
00059
00060
00061 csPolygonIntArray polygons;
00062
00063 csPolygonIntPool* poly_pool;
00064
00065 public:
00067 csPolygonStub (csPolygonIntPool* pool) : next_tree (NULL),
00068 prev_tree (NULL), next_obj (NULL), prev_obj (NULL),
00069 object (NULL), node (NULL), ref_count (1), poly_pool (pool) { }
00070 ~csPolygonStub ()
00071 {
00072 RemoveStub ();
00073 }
00074
00075
00076 void IncRef () { ref_count++; }
00077
00078 void DecRef () { if (ref_count <= 0) CRASH; ref_count--; }
00079
00081 void RemoveStub ();
00082
00084 csPolyTreeBBox* GetObject () { return object; }
00085
00087 csPolygonIntArray& GetPolygonArray () { return polygons; }
00089 csPolygonInt** GetPolygons () { return polygons.GetPolygons (); }
00091 int GetPolygonCount () { return polygons.GetPolygonCount (); }
00092
00094 void* Visit (csThing* thing, csTreeVisitFunc* func, void* data)
00095 {
00096 return func (thing, polygons.GetPolygons (), polygons.GetPolygonCount (),
00097 false, data);
00098 }
00099
00101 void Initialize ()
00102 {
00103 polygons.Reset ();
00104 }
00105
00109 void RemoveData ();
00110 };
00111
00116 class csPolygonStubFactory
00117 {
00118 private:
00119
00120 csPolygonIntPool* poly_pool;
00121
00122 public:
00124 csPolygonStubFactory (csPolygonIntPool* pool) : poly_pool (pool) { }
00125
00127 csPolygonStub* Create ()
00128 {
00129 return new csPolygonStub (poly_pool);
00130 }
00131 };
00132
00141 class csPolygonStubPool
00142 {
00143 private:
00144 struct PoolObj
00145 {
00146 PoolObj* next;
00147 csPolygonStub* ps;
00148 };
00150 PoolObj* alloced;
00152 PoolObj* freed;
00153
00154 public:
00156 csPolygonStubPool () : alloced (NULL), freed (NULL) { }
00157
00159 ~csPolygonStubPool ();
00160
00165 csPolygonStub* Alloc (csPolygonStubFactory* factory);
00166
00174 void Free (csPolygonStub* ps);
00175
00177 void Dump ();
00178 };
00179
00180 #endif // __CS_TREEOBJ_H__