|
treeobj.h00001 /* 00002 Copyright (C) 2000 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 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 // Linked list in every tree node. 00049 csPolygonStub* next_tree, * prev_tree; 00050 // Linked list in every csPolyTreeBBox. 00051 csPolygonStub* next_obj, * prev_obj; 00052 // Object where this stub lives. 00053 csPolyTreeBBox* object; 00054 // Tree node where this stub lives. 00055 csPolygonTreeNode* node; 00056 // Reference counter. This ref counter is managed by the 00057 // csPolygonStubPool. 00058 int ref_count; 00059 00060 // List of polygons. 00061 csPolygonIntArray polygons; 00062 // The pool that is used to create polygons. 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 // Increment the ref counter. 00076 void IncRef () { ref_count++; } 00077 // Decrement the ref counter. 00078 void DecRef () { if (ref_count <= 0) DEBUG_BREAK; 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 // The pool that is used to create polygons. 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__ Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |