zopc.h

Go to the documentation of this file.
00001 #ifndef ZOPC_H
00002 #define ZOPC_H
00003 
00014 #ifndef PIXEL
00015 #error Pixel format must be specified.
00016 #endif
00017 
00018 #ifndef MAX_LINES
00019 #error Height of target area must be specified
00020 #endif
00021 
00022 #ifndef FIFO_H
00023 #include "fifo.h"
00024 #endif
00025 
00026 #ifndef OPC_H
00027 #include "opc.h"
00028 #endif
00029 
00030 #ifndef ZOPC_NAME
00031 #define ZOPC_NAME           ZOPC
00032 #endif
00033 
00034 #ifndef ZOPC_NAMING
00035 #define ZOPC_NAMING(label)  ppConcat(ZOPC_,label)
00036 #endif
00037 
00038 #ifndef ZTYPE
00039 #define ZTYPE   uint16
00040 #endif
00041 
00042 #ifndef POOL_SIZE
00043 #define POOL_SIZE MAX_LINES * 10
00044 #endif
00045 
00046 typedef struct ZOPC_NAMING(span)
00047 {
00048     ZTYPE   z;      /* Z value of drawn data must be less than this to show through */
00049     ZTYPE   len;    /* Length of span */
00050 } ZOPC_NAMING(span);
00051 typedef struct ZOPC_NAMING(line)
00052 {
00053     ZOPC_NAMING(span)*  span;   /* Spans used on this line */
00054     size_t              count;  /* Count of spans */
00055 } ZOPC_NAMING(line);
00056 
00057 typedef struct ZOPC_NAME
00058 {
00059     OPC opc;                                /* OPC based definition of render buffer */
00060     ZOPC_NAMING(line)*  yspan[MAX_LINES];   /* Per row definitions of Z based clip, from opc.top to opc.bottom-1 */
00061     FIFO_decl(ZOPC_NAMING(span),POOL_SIZE, fifo); /* Pool of Z runs */
00062 } ZOPC_NAME;
00063 /*
00064 Heap management:
00065 
00066 Heap is a FIFO queue.  Each time we add something new, we consume data from 
00067 one end of the FIFO and release data from the other end as we re-allocate it.
00068 
00069 We add lines from the top of the Z buffer to the bottom, each time.  
00070 
00071 Unaffected lines are copied verbatim, and affected lines are modified, merging 
00072 any new spans that are added to them, and merging adjecent spans of the same 
00073 Z value into one span.
00074 
00075 We only run out of heap if allocation collides with existing data.  We never 
00076 fragment the heap because we re-process all lines each time.  
00077 
00078 This is set up to manage a few shapes to protect some regions of the screen 
00079 from drawing, with the list occasionally modified, such that a character can 
00080 pass behind a rock or tree on-screen without worrying about redrawing the 
00081 rocks/trees the character is behind every time the character animates/moves, 
00082 or for slapping up a GUI overlay without repaining the (potentially large) 
00083 overlay every time a control under it animates or changes state.
00084 
00085 Generally there will be ONE instance of this, protecting/masking shapes 
00086 just before they're rendered to the screen.  
00087 
00088 If you are constantly re-assigning Z, or want truly arbitrary shapes, use 
00089 a "real" Z buffer.
00090 
00091 Sorry about the odd parameter placement of 'z' in many of these, but these 
00092 are properly 2D primitives with a 'depth' beaten in, not 3D primitives.
00093  */
00094 
00095 void ZOPC_NAMING(init)( ZOPC_NAME* zl, void* origin, int pitch, const Rect* clip );
00096 void ZOPC_NAMING(clear)( ZOPC_NAME* zl );
00097 /* Copy only a range of Z from Z list OPC to dst. */
00098 void ZOPC_NAMING(blit)( const OPC* dst, int x, int y, ZOPC_NAME* zl, int zBegin, int zEnd );
00099 
00100 /*void ZOPC_NAMING(add_span)( ZOPC_NAME* zl, int z, int x, int y, int wide ); */
00101 /*void ZOPC_NAMING(ovr_span)( ZOPC_NAME* zl, int z, int x, int y, int wide ); */
00102 /*void ZOPC_NAMING(del_span)( ZOPC_NAME* zl, int x, int y, int wide ); */
00103 
00104 /* Add a shape, respecting Z already present */
00105 void ZOPC_NAMING(add_Rect)( ZOPC_NAME* zl, int z, const Rect* rect );
00106 void ZOPC_NAMING(add_OPC)( ZOPC_NAME* zl, int z, const OPC* shape, PIXEL transparent );
00107 void ZOPC_NAMING(add_OPCShape)( ZOPC_NAME* zl, int z, const OPCShape* shape );
00108 
00109 /* Add a shape, replacing any Z already present */
00110 void ZOPC_NAMING(rep_Rect)( ZOPC_NAME* zl, int z, const Rect* rect );
00111 void ZOPC_NAMING(rep_OPC)( ZOPC_NAME* zl, int z, const OPC* shape, PIXEL transparent );
00112 void ZOPC_NAMING(rep_OPCShape)( ZOPC_NAME* zl, int z, const OPCShape* shape );
00113 
00114 /* Clear a shape, revert region under it to 'infinite distance' */
00115 void ZOPC_NAMING(del_Rect)( ZOPC_NAME* zl, const Rect* rect );
00116 void ZOPC_NAMING(del_OPC)( ZOPC_NAME* zl, const OPC* shape, PIXEL transparent );
00117 void ZOPC_NAMING(del_OPCShape)( ZOPC_NAME* zl, const OPCShape* shape );
00118 
00119 /* Various OPC primitives using Z */
00120 void ZOPC_NAMING(HLine)( const ZOPC_NAME* dst, int z, int x, int y, int wide, OPC_NAMING(Pixel) color );
00121 void ZOPC_NAMING(VLine)( const ZOPC_NAME* dst, int z, int x, int y, int high, OPC_NAMING(Pixel) color );
00122 void ZOPC_NAMING(HCopy)( const ZOPC_NAME* dst, int z, int x, int y, int wide, const OPC_NAMING(Pixel)* src );
00123 void ZOPC_NAMING(Blit)( const ZOPC_NAME* dst, int z, const Rect* rdst, const OPC* src, int sx, int sy );
00124 void ZOPC_NAMING(Stamp)( const ZOPC_NAME* dst, int dz, int dx, int dy, const OPC* src );
00125 void ZOPC_NAMING(Fill)( const ZOPC_NAME* dst, int z, const Rect* rdst, OPC_NAMING(Pixel) color );
00126 void ZOPC_NAMING(Shape)( const ZOPC_NAME* dst, int z, const OPCShape* shape, int x, int y );
00127 void ZOPC_NAMING(Shape_Mask)( const ZOPC_NAME* dst, int z, const OPCShape* shape, int x, int y, OPC_NAMING(Pixel) color );
00128 
00129 #endif /* ZOPC_H */

Generated on Fri Jan 2 15:28:35 2009 for Squat by  doxygen 1.5.6