Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

SpanBuffer.c File Reference

#include <Assert.h>
#include "SpanBuffer.h"
#include "Ram.h"

Go to the source code of this file.

Compounds

struct  SpanBuffer_Span

Defines

#define geErrorLog_AddString(Error, xx, yy)

Typedefs

typedef SpanBuffer_Span SpanBuffer_Span

Functions

void SpanBuffer_Destroy (void)
void SpanBuffer_Clear (void)
geBoolean SpanBuffer_Create (int Width, int Height, int MaxSpans)
int SpanBuffer_ClipAndAdd (int Line, int LeftStart, int Width)

Variables

SpanBuffer_Span ** SpanBuffer_Lines
SpanBuffer_SpanSpanBuffer_Spares
int SpanBuffer_FirstSpare
int SpanBuffer_LineCount
int SpanBuffer_MaxSpares
SpanBuffer_ClipSegmentSpanBuffer_Segments


Define Documentation

#define geErrorLog_AddString Error,
xx,
yy   ) 
 

Definition at line 31 of file SpanBuffer.c.


Typedef Documentation

typedef struct SpanBuffer_Span SpanBuffer_Span
 

Definition at line 39 of file SpanBuffer.c.

Referenced by SpanBuffer_ClipAndAdd(), and SpanBuffer_Create().


Function Documentation

void SpanBuffer_Clear void   ) 
 

Definition at line 70 of file SpanBuffer.c.

References NULL, SpanBuffer_FirstSpare, SpanBuffer_LineCount, and SpanBuffer_Lines.

Referenced by SoftDrv_BeginWorld(), and SpanBuffer_Create().

00071 { 
00072         int i;
00073         assert(SpanBuffer_Lines!=NULL);
00074 
00075         for (i=0; i<SpanBuffer_LineCount; i++) 
00076                 {
00077                         SpanBuffer_Lines[i] = NULL;
00078                 }       
00079         SpanBuffer_FirstSpare = 0;
00080 }

int SpanBuffer_ClipAndAdd int  Line,
int  LeftStart,
int  Width
 

Definition at line 145 of file SpanBuffer.c.

References SpanBuffer_ClipSegment::LeftOffset, SpanBuffer_Span::Max, SpanBuffer_Span::Min, SpanBuffer_Span::Next, NULL, SpanBuffer_FirstSpare, SpanBuffer_LineCount, SpanBuffer_Lines, SpanBuffer_MaxSpares, SpanBuffer_Segments, SpanBuffer_Span, SpanBuffer_Spares, and SpanBuffer_ClipSegment::Width.

00146 {
00147         SpanBuffer_Span *LastSpan;
00148         SpanBuffer_Span *NewSpan;
00149         SpanBuffer_Span *Span;
00150         SpanBuffer_ClipSegment *Segment;
00151         int Left = LeftStart;
00152         int Right = LeftStart + Width -1;  
00153         int SegmentCount = 0;
00154         #pragma message("fix this off by one problem here and in the engine!")
00155         if (Line>=SpanBuffer_LineCount)
00156                 return 0;
00157 
00158         assert( Line >= 0 );
00159         assert( Line< SpanBuffer_LineCount );
00160         assert( Width >= 0 ); 
00161         assert( LeftStart >=0 );
00162 
00163         Segment  = &(SpanBuffer_Segments[0]);
00164         LastSpan = NULL;
00165         Span     = SpanBuffer_Lines[Line];
00166 
00167         while (Span)
00168                 {
00169                         if (Left < Span->Min)
00170                                 {   // new span starts to left of this span
00171                                         if (Right<Span->Min)  
00172                                                 {       // new span ends to left of this span
00173                                                         break;
00174                                                 }
00175                                         else
00176                                                 {       // new span ends in or to the right of this span
00177                                                         Segment->LeftOffset = Left - LeftStart;
00178                                                         Segment->Width = Span->Min - Left;
00179                                                         SegmentCount++;
00180                                                         Segment++;
00181                                                         // Stretch Span to Left. 
00182                                                         Span->Min = Left;
00183                                                         if (LastSpan)
00184                                                                 {
00185                                                                         if (LastSpan->Max+1 == Span->Min)
00186                                                                                 {       // collapse LastSpan with Span
00187                                                                                         LastSpan->Max = Span->Max;
00188                                                                                         LastSpan->Next = Span->Next;
00189                                                                                         Span = LastSpan;
00190                                                                                         // *Span is lost for this frame
00191                                                                                 }
00192                                                                 }
00193                                                 }
00194                                 }
00195                         if (Left <= Span->Max)
00196                                 {
00197                                         Left = Span->Max + 1;
00198                                         if (Left > Right)
00199                                                 return SegmentCount;
00200                                 }
00201                         LastSpan = Span;
00202                         Span = Span->Next;
00203                 }
00204 
00205         // add span
00206         Segment->LeftOffset = Left - LeftStart;
00207         Segment->Width = Right - Left + 1;
00208         SegmentCount++;
00209 
00210 
00211         if (LastSpan)
00212                 {
00213                         if (LastSpan->Max+1 == Left)
00214                                 {       // stretch LastSpan 
00215                                         LastSpan->Max = Right;
00216                                 }
00217                         else
00218                                 {
00219                                         if (SpanBuffer_FirstSpare<SpanBuffer_MaxSpares)
00220                                                 NewSpan = &(SpanBuffer_Spares[SpanBuffer_FirstSpare++]);
00221                                         else
00222                                                 return SegmentCount;
00223                                         NewSpan->Min   = Left;
00224                                         NewSpan->Max   = Right;
00225                                         NewSpan->Next  = Span;
00226                                         LastSpan->Next = NewSpan;
00227                                 }       
00228                 }
00229         else
00230                 {
00231                         if (SpanBuffer_FirstSpare<SpanBuffer_MaxSpares)
00232                                 NewSpan = &(SpanBuffer_Spares[SpanBuffer_FirstSpare++]);
00233                         else
00234                                 return SegmentCount;
00235                         NewSpan->Min   = Left;
00236                         NewSpan->Max   = Right;
00237                         NewSpan->Next  = Span;
00238                         SpanBuffer_Lines[Line] = NewSpan;
00239                 }
00240 
00241 
00242         return SegmentCount;
00243 }       

geBoolean SpanBuffer_Create int  Width,
int  Height,
int  MaxSpans
 

Definition at line 82 of file SpanBuffer.c.

References GE_ERR_MEMORY_RESOURCE, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, geRam_Allocate, geRam_Free, NULL, SpanBuffer_Clear(), SpanBuffer_Destroy(), SpanBuffer_LineCount, SpanBuffer_Lines, SpanBuffer_MaxSpares, SpanBuffer_Segments, SpanBuffer_Span, and SpanBuffer_Spares.

Referenced by SoftDrv_Init().

00083 {
00084         assert( Width > 0 );
00085         assert( Height > 0 );
00086         assert( MaxSpans > 0 );
00087 
00088         SpanBuffer_Destroy();
00089 
00090         SpanBuffer_MaxSpares = MaxSpans;
00091         SpanBuffer_LineCount = Height;
00092 
00093         SpanBuffer_Lines = geRam_Allocate(sizeof(SpanBuffer_Span *) * Height);
00094         if (SpanBuffer_Lines == NULL)
00095                 {
00096                         geErrorLog_AddString( GE_ERR_MEMORY_RESOURCE,"Unable to create span buffer table",NULL);
00097                         return GE_FALSE;
00098                 }
00099 
00100         SpanBuffer_Spares = geRam_Allocate(sizeof(SpanBuffer_Span) * MaxSpans);
00101         if (SpanBuffer_Lines == NULL)
00102                 {
00103                         geErrorLog_AddString(GE_ERR_MEMORY_RESOURCE ,"Unable to create spare span list",NULL);
00104                         geRam_Free(SpanBuffer_Lines);
00105                         SpanBuffer_Lines = NULL;
00106                         return GE_FALSE;
00107                 }
00108 
00109         SpanBuffer_Segments = geRam_Allocate(sizeof(SpanBuffer_ClipSegment) * (Width/2) );
00110         if (SpanBuffer_Segments == NULL )
00111                 {
00112                         geErrorLog_AddString( GE_ERR_MEMORY_RESOURCE,"Unable to create span buffer clip segment list",NULL);
00113                         geRam_Free(SpanBuffer_Lines); 
00114                         SpanBuffer_Lines = NULL;
00115                         geRam_Free(SpanBuffer_Spares);
00116                         SpanBuffer_Spares = NULL;
00117                         return GE_FALSE;
00118                 }
00119         SpanBuffer_Clear();
00120         return GE_TRUE;
00121 }

void SpanBuffer_Destroy void   ) 
 

Definition at line 55 of file SpanBuffer.c.

References geRam_Free, NULL, SpanBuffer_Lines, SpanBuffer_Segments, and SpanBuffer_Spares.

Referenced by SoftDrv_Shutdown(), and SpanBuffer_Create().

00056 {
00057         if ( SpanBuffer_Lines != NULL )
00058                 geRam_Free(SpanBuffer_Lines);
00059         SpanBuffer_Lines = NULL;
00060 
00061         if ( SpanBuffer_Spares != NULL )
00062                 geRam_Free(SpanBuffer_Spares);
00063         SpanBuffer_Spares = NULL;
00064 
00065         if ( SpanBuffer_Segments != NULL )
00066                 geRam_Free(SpanBuffer_Segments);
00067         SpanBuffer_Segments = NULL;
00068 }


Variable Documentation

int SpanBuffer_FirstSpare [static]
 

Definition at line 49 of file SpanBuffer.c.

Referenced by SpanBuffer_Clear(), and SpanBuffer_ClipAndAdd().

int SpanBuffer_LineCount [static]
 

Definition at line 50 of file SpanBuffer.c.

Referenced by SpanBuffer_Clear(), SpanBuffer_ClipAndAdd(), and SpanBuffer_Create().

SpanBuffer_Span** SpanBuffer_Lines [static]
 

Definition at line 47 of file SpanBuffer.c.

Referenced by SpanBuffer_Clear(), SpanBuffer_ClipAndAdd(), SpanBuffer_Create(), and SpanBuffer_Destroy().

int SpanBuffer_MaxSpares [static]
 

Definition at line 51 of file SpanBuffer.c.

Referenced by SpanBuffer_ClipAndAdd(), and SpanBuffer_Create().

SpanBuffer_ClipSegment* SpanBuffer_Segments
 

Definition at line 52 of file SpanBuffer.c.

Referenced by SpanBuffer_ClipAndAdd(), SpanBuffer_Create(), and SpanBuffer_Destroy().

SpanBuffer_Span* SpanBuffer_Spares [static]
 

Definition at line 48 of file SpanBuffer.c.

Referenced by SpanBuffer_ClipAndAdd(), SpanBuffer_Create(), and SpanBuffer_Destroy().


Generated on Tue Sep 30 12:38:09 2003 for GTestAndEngine by doxygen 1.3.2