Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

cbuffer.h

00001 /*
00002     Copyright (C) 1998 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_CBUFFER_H__
00020 #define __CS_CBUFFER_H__
00021 
00022 #include "csgeom/math2d.h"
00023 
00024 struct iGraphics2D;
00025 struct iGraphics3D;
00026 
00027 /*=================*
00028  * Coverage Buffer *
00029  *=================*/
00030 
00036 struct csCBufferSpan
00037 {
00039   int startx, endx;
00041   csCBufferSpan* next;
00042 };
00043 
00044 class csCBuffer;
00045 
00053 class csCBufferLine
00054 {
00055   friend class csCBuffer;
00056 
00057 private:
00059   csCBufferSpan* first_span;
00061   csCBufferSpan* last_span;
00063   csCBuffer* parent;
00064 
00065 private:
00067   csCBufferLine ();
00072   ~csCBufferLine ();
00073 
00075   void SetParent (csCBuffer* par) { parent = par; }
00076 
00080   void Initialize (int startx, int endx);
00081 
00083   bool IsFull () { return first_span == NULL; }
00084 
00086   void MakeFull ();
00087 
00092   bool TestSpan (int startx, int endx);
00093 
00098   bool InsertSpan (int startx, int endx);
00099 
00104   bool TestSingle (int x) { return TestSpan (x, x); }
00105 
00107   void Dump ();
00108 };
00109 
00114 class csCBuffer
00115 {
00116   friend class csCBufferLine;
00117 
00118 private:
00120   csCBufferLine* lines;
00122   int num_lines;
00124   int startx, endx;
00126   csCBufferSpan* first_unused;
00132   csCBufferLine vert_line;
00133 
00135   csCBufferSpan* AllocSpan ()
00136   {
00137     csCBufferSpan* s;
00138     if (first_unused)
00139     {
00140       s = first_unused;
00141       first_unused = first_unused->next;
00142     }
00143     else
00144       s = new csCBufferSpan ();
00145     return s;
00146   }
00148   void FreeSpan (csCBufferSpan* span)
00149   {
00150     span->next = first_unused;
00151     first_unused = span;
00152   }
00153 
00158   bool TestSpan (int s_spanx, int e_spanx, int y)
00159   {
00160     if (y < 0 || y >= num_lines) return false;
00161     return lines[y].TestSpan (s_spanx, e_spanx);
00162   }
00163 
00168   bool InsertSpan (int s_spanx, int e_spanx, int y)
00169   {
00170     if (y < 0 || y >= num_lines) return false;
00171     return lines[y].InsertSpan (s_spanx, e_spanx);
00172   }
00173 
00175   bool IsFull (int y)
00176   {
00177     if (y < 0 || y >= num_lines) return false;
00178     return lines[y].IsFull ();
00179   }
00180 
00181 public:
00183   csCBuffer (int sx, int ex, int n_lines);
00185   ~csCBuffer ();
00186 
00188   void Initialize ();
00189 
00191   bool IsFull () { return vert_line.IsFull (); }
00192 
00201   bool TestPolygon (csVector2* verts, int num_verts);
00202 
00211   bool InsertPolygon (csVector2* verts, int num_verts, bool negative = false);
00212 
00218   bool TestPoint (const csVector2& point);
00219 
00220 
00222   void DumpLine (int y) { lines[y].Dump (); }
00223 
00227   void GfxDump (iGraphics2D* ig2d, iGraphics3D* ig3d);
00228 };
00229 
00230 #endif // __CS_CBUFFER_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000