CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

csgeom/vtpool.h

Go to the documentation of this file.
00001 /*
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 
00028 #include "csgeom/vector3.h"
00029 
00034 class csVertexArrayPool
00035 {
00036 public:
00038   virtual ~csVertexArrayPool () { }
00039 
00044   virtual csVector3* GetVertexArray (int n) = 0;
00045 
00050   virtual void FreeVertexArray (csVector3* ar, int n) = 0;
00051 };
00052 
00058 class csDefaultVertexArrayPool : public csVertexArrayPool
00059 {
00060 public:
00061   csDefaultVertexArrayPool ();
00062 
00067   virtual csVector3* GetVertexArray (int n)
00068   {
00069     return new csVector3[n];
00070   }
00071 
00073   virtual void FreeVertexArray (csVector3* ar, int)
00074   {
00075     delete[] ar;
00076   }
00077 
00079   CS_DECLARE_STATIC_CLASSVAR_REF(default_pool,GetDefaultPool,csDefaultVertexArrayPool)
00080 };
00081 
00088 class csStackedVertexArrayPool : public csVertexArrayPool
00089 {
00090 private:
00091   csVector3* pool;
00092   int lastn, maxn;
00093 
00094 public:
00096   csStackedVertexArrayPool (int maxn)
00097   {
00098     csStackedVertexArrayPool::maxn = maxn;
00099     lastn = 0;
00100     pool = new csVector3[maxn];
00101   }
00102 
00104   virtual ~csStackedVertexArrayPool ()
00105   {
00106     delete[] pool;
00107   }
00108 
00110   virtual csVector3* GetVertexArray (int n)
00111   {
00112     if (lastn+n > maxn) return 0;
00113     lastn += n;
00114     return pool+lastn-n;
00115   }
00116 
00118   virtual void FreeVertexArray (csVector3* ar, int n)
00119   {
00120     if (ar == pool+lastn-n) lastn -= n;
00121   }
00122 
00124   void Clear ()
00125   {
00126     lastn = 0;
00127   }
00128 };
00129 
00135 class csPooledVertexArrayPool : public csVertexArrayPool
00136 {
00137 private:
00138   struct PoolEl
00139   {
00140     PoolEl* next;
00141     int n;      // Number of vertices.
00142     csVector3 first_vertex;
00143   };
00144   // For all common number of vertices there are specific pools.
00145   PoolEl* pool[6];      // For sizes 3, 4, 5, 6, 7, and 8.
00146   PoolEl* miscpool;     // For all other sizes.
00147 
00148 public:
00150   csPooledVertexArrayPool ();
00151 
00153   virtual ~csPooledVertexArrayPool ();
00154 
00156   virtual csVector3* GetVertexArray (int n);
00157 
00159   virtual void FreeVertexArray (csVector3* ar, int n);
00160 
00162   CS_DECLARE_STATIC_CLASSVAR_REF(default_pool,GetDefaultPool,csPooledVertexArrayPool)
00163 };
00164 
00167 #endif // __CS_VTPOOL_H__

Generated for Crystal Space by doxygen 1.2.18