00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_LPPOOL_H__
00020 #define __CS_LPPOOL_H__
00021
00022 #include "csengine/light.h"
00023
00030 class csLightPatchPool
00031 {
00032 private:
00033 struct PoolObj
00034 {
00035 PoolObj* next;
00036 csLightPatch* lp;
00037 };
00039 PoolObj* alloced;
00041 PoolObj* freed;
00042
00043 public:
00045 csLightPatchPool () : alloced (NULL), freed (NULL) { }
00046
00048 ~csLightPatchPool ()
00049 {
00050 while (alloced)
00051 {
00052 PoolObj* n = alloced->next;
00053
00054
00055
00056
00057 delete alloced;
00058 alloced = n;
00059 }
00060 while (freed)
00061 {
00062 PoolObj* n = freed->next;
00063 delete freed->lp;
00064 delete freed;
00065 freed = n;
00066 }
00067 }
00068
00070 csLightPatch* Alloc ()
00071 {
00072 PoolObj* pnew;
00073 if (freed)
00074 {
00075 pnew = freed;
00076 freed = freed->next;
00077 }
00078 else
00079 {
00080 pnew = new PoolObj ();
00081 pnew->lp = new csLightPatch ();
00082 }
00083 pnew->next = alloced;
00084 alloced = pnew;
00085 return pnew->lp;
00086 }
00087
00093 void Free (csLightPatch* lp)
00094 {
00095 lp->RemovePatch ();
00096 if (alloced)
00097 {
00098 PoolObj* po = alloced;
00099 alloced = alloced->next;
00100 po->lp = lp;
00101 po->next = freed;
00102 freed = po;
00103 }
00104 else
00105 {
00106
00107 CS_ASSERT (false);
00108 }
00109 }
00110
00112 void Dump ()
00113 {
00114 int cnt;
00115 cnt = 0;
00116 PoolObj* po = alloced;
00117 while (po) { cnt++; po = po->next; }
00118 printf ("LightPatch pool: %d allocated, ", cnt);
00119 cnt = 0;
00120 po = freed;
00121 while (po) { cnt++; po = po->next; }
00122 printf ("%d freed.\n", cnt);
00123 }
00124 };
00125
00126 #endif // __CS_LPPOOL_H__