|
vtpool.h00001 /* 00002 Copyright (C) 2001 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_VTPOOL_H__ 00020 #define __CS_VTPOOL_H__ 00021 00022 #include "csgeom/vector3.h" 00023 00028 class csVertexArrayPool 00029 { 00030 public: 00032 virtual ~csVertexArrayPool () { } 00033 00038 virtual csVector3* GetVertexArray (int n) = 0; 00039 00044 virtual void FreeVertexArray (csVector3* ar, int n) = 0; 00045 }; 00046 00052 class csDefaultVertexArrayPool : public csVertexArrayPool 00053 { 00054 public: 00055 csDefaultVertexArrayPool (); 00056 00061 virtual csVector3* GetVertexArray (int n) 00062 { 00063 return new csVector3[n]; 00064 } 00065 00067 virtual void FreeVertexArray (csVector3* ar, int) 00068 { 00069 delete[] ar; 00070 } 00071 00073 CS_DECLARE_STATIC_CLASSVAR_REF(default_pool,GetDefaultPool,csDefaultVertexArrayPool) 00074 }; 00075 00082 class csStackedVertexArrayPool : public csVertexArrayPool 00083 { 00084 private: 00085 csVector3* pool; 00086 int lastn, maxn; 00087 00088 public: 00090 csStackedVertexArrayPool (int maxn) 00091 { 00092 csStackedVertexArrayPool::maxn = maxn; 00093 lastn = 0; 00094 pool = new csVector3[maxn]; 00095 } 00096 00098 virtual ~csStackedVertexArrayPool () 00099 { 00100 delete[] pool; 00101 } 00102 00104 virtual csVector3* GetVertexArray (int n) 00105 { 00106 if (lastn+n > maxn) return NULL; 00107 lastn += n; 00108 return pool+lastn-n; 00109 } 00110 00112 virtual void FreeVertexArray (csVector3* ar, int n) 00113 { 00114 if (ar == pool+lastn-n) lastn -= n; 00115 } 00116 00118 void Clear () 00119 { 00120 lastn = 0; 00121 } 00122 }; 00123 00129 class csPooledVertexArrayPool : public csVertexArrayPool 00130 { 00131 private: 00132 struct PoolEl 00133 { 00134 PoolEl* next; 00135 int n; // Number of vertices. 00136 csVector3 first_vertex; 00137 }; 00138 // For all common number of vertices there are specific pools. 00139 PoolEl* pool[6]; // For sizes 3, 4, 5, 6, 7, and 8. 00140 PoolEl* miscpool; // For all other sizes. 00141 00142 public: 00144 csPooledVertexArrayPool (); 00145 00147 virtual ~csPooledVertexArrayPool (); 00148 00150 virtual csVector3* GetVertexArray (int n); 00151 00153 virtual void FreeVertexArray (csVector3* ar, int n); 00154 00156 CS_DECLARE_STATIC_CLASSVAR_REF(default_pool,GetDefaultPool,csPooledVertexArrayPool) 00157 }; 00158 00159 #endif // __CS_VTPOOL_H__ Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |