OpenMortal Apocalypse mirror
Sourceforge mirror
SourceForge.net Logo
      News | Info | Characters | Arenas | Screenshots | Forums | Download  
Developer: Making of | Character-HOWTO | AI Design | Submit a Character
Documentation: Main Page | Modules | Class Hierarchy | Class List | File List

DrawRle.h

Go to the documentation of this file.
00001 // This is not a real include file. It is used byt RlePack.cpp
00002 
00003 // At this point the following methods should be defined:
00004 
00005 // METHODNAME: The name of the drawing method
00006 // METHODNAME_FLIPT: The name of the flipped drawing method
00007 // PIXEL_PTR: type of pointer to the target surface pixels
00008 // PUT_PIXEL(p,c): Draw pixel of color c to pixel ptr type p
00009 // PITCH: This added to PIXEL_PTR type will result in the next scanline
00010 
00011 
00012 void METHODNAME_FLIP( SRleSprite* src, int dx, int dy )
00013 {
00014 #define RLE_PTR                 signed char*
00015 #define RLE_IS_EOL(c)           ((c) == 0)
00016 //#define PIXEL_PTR             unsigned char*
00017 #define OFFSET_PIXEL_PTR(p,x)   ((PIXEL_PTR) (p) + (x))
00018 #define INC_PIXEL_PTR(p)        ((p)++)
00019 #define DEC_PIXEL_PTR(p)        ((p)--)
00020 //#define PUT_PIXEL(p,c)            (*((unsigned char *)(p)) = (c))
00021 
00022     int x, y, w, h;     // width and height of visible area
00023     int dxbeg, dybeg;   // beginning in destination
00024     int sxbeg, sybeg;   // beginning in source
00025     RLE_PTR s;
00026 
00027     SDL_Surface* dst = gamescreen;
00028     // Clip to dst->clip_rect
00029     int dst_cl = dst->clip_rect.x;
00030     int dst_cr = dst->clip_rect.w + dst_cl - 1;
00031     int dst_ct = dst->clip_rect.y;
00032     int dst_cb = dst->clip_rect.h + dst_ct;
00033 
00034 //  if (dst->clip)
00035     if (1)
00036     {
00037         int tmp;
00038 
00039         dxbeg = dx;
00040         if ( dst_cl > dx ) dxbeg = dst_cl;
00041 
00042         tmp = dx + src->w - dst_cr;
00043         sxbeg = ((tmp < 0) ? 0 : tmp);
00044 
00045         tmp = dx + src->w;
00046         if (tmp > dst_cr ) tmp = dst_cr;
00047         w = tmp - dxbeg;
00048         if (w <= 0)
00049             return;
00050     
00051         tmp = dst_ct - dy;
00052         sybeg = ((tmp < 0) ? 0 : tmp);
00053         dybeg = sybeg + dy;
00054 
00055         tmp = dst_cb - dy;
00056         h = ((tmp > src->h) ? src->h : tmp) - sybeg;
00057         if (h <= 0)
00058             return;
00059     }
00060     else {
00061         w = src->w;
00062         h = src->h;
00063         sxbeg = 0;
00064         sybeg = 0;
00065         dxbeg = dx;
00066         dybeg = dy;
00067     }
00068 
00069     s = (RLE_PTR) (src->dat);
00070     dxbeg += w;
00071 
00072     // Clip top.
00073     for (y = sybeg - 1; y >= 0; y--) 
00074     {
00075         long c = *s++;
00076 
00077         while (!RLE_IS_EOL(c)) 
00078         {
00079             if (c > 0)
00080                 s += c;
00081             c = *s++;
00082         }
00083     }
00084 
00085     //@@@ bmp_select(dst);
00086 
00087     /* Visible part.  */
00088     for (y = 0; y < h; y++) 
00089     {
00090         //@@@ PIXEL_PTR d = OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y), dxbeg);
00091         PIXEL_PTR d = (PIXEL_PTR) dst->pixels;
00092         d += (dybeg+y)*PITCH;
00093         d = OFFSET_PIXEL_PTR( d, dxbeg );
00094         long c = *s++;
00095 
00096         // Clip left.
00097         for (x = sxbeg; x > 0; ) 
00098         {
00099             if (RLE_IS_EOL(c))
00100                 goto next_line;
00101             else if (c > 0) 
00102             {
00103                 // Run of solid pixels.
00104                 if ((x - c) >= 0) 
00105                 {
00106                     // Fully clipped.
00107                     x -= c;
00108                     s += c;
00109                 }
00110                 else 
00111                 {
00112                     // Visible on the right.
00113                     c -= x;
00114                     s += x;
00115                     break;
00116                 }
00117             }
00118             else 
00119             {
00120                 // Run of transparent pixels.
00121                 if ((x + c) >= 0) {
00122                     // Fully clipped.
00123                     x += c;
00124                 }
00125                 else {
00126                     // Visible on the right.
00127                     c += x;
00128                     break;
00129                 }
00130             }
00131 
00132             c = *s++;
00133         }
00134 
00135         /* Visible part.  */
00136         for (x = w; x > 0; ) 
00137         {
00138             if (RLE_IS_EOL(c))
00139                 goto next_line;
00140             else if (c > 0) 
00141             {
00142                 /* Run of solid pixels.  */
00143                 if ((x - c) >= 0) 
00144                 {
00145                     /* Fully visible.  */
00146                     x -= c;
00147                     for (c--; c >= 0; s++, DEC_PIXEL_PTR(d), c--) 
00148                     {
00149                         unsigned long col = (unsigned char) (*s);
00150                         PUT_PIXEL(d, col);
00151                     }
00152                 }
00153                 else 
00154                 {
00155                     /* Clipped on the right.  */
00156                     c -= x;
00157                     for (x--; x >= 0; s++, DEC_PIXEL_PTR(d), x--) 
00158                     {
00159                         unsigned long col = (unsigned char) (*s);
00160                         PUT_PIXEL(d, col);
00161                     }
00162                     break;
00163                 }
00164             }
00165             else 
00166             {
00167                 /* Run of transparent pixels.  */
00168                 x += c;
00169                 d = OFFSET_PIXEL_PTR(d, c);
00170             }
00171 
00172             c = *s++;
00173         }
00174 
00175         /* Clip right.  */
00176         while (!RLE_IS_EOL(c)) 
00177         {
00178             if (c > 0)
00179                 s += c;
00180             c = *s++;
00181         }
00182 
00183         next_line: ;
00184     }
00185 
00186    //@@@bmp_unwrite_line(dst);
00187 }
00188 
00189 void METHODNAME( SRleSprite* src, int dx, int dy )
00190 {
00191 #define RLE_PTR                 signed char*
00192 #define RLE_IS_EOL(c)           ((c) == 0)
00193 //#define PIXEL_PTR             unsigned char*
00194 #define OFFSET_PIXEL_PTR(p,x)   ((PIXEL_PTR) (p) + (x))
00195 #define INC_PIXEL_PTR(p)        ((p)++)
00196 #define DEC_PIXEL_PTR(p)        ((p)--)
00197 //#define PUT_PIXEL(p,c)            (*((unsigned char *)(p)) = (c))
00198 //#define PUT_PIXEL(p,c)         bmp_write8((unsigned long) (p), (c))
00199 
00200     int x, y, w, h;     // width and height of visible area
00201     int dxbeg, dybeg;   // beginning in destination
00202     int sxbeg, sybeg;   // beginning in source
00203     RLE_PTR s;
00204 
00205     SDL_Surface* dst = gamescreen;
00206     // Clip to dst->clip_rect
00207     int dst_cl = dst->clip_rect.x;
00208     int dst_cr = dst->clip_rect.w + dst_cl;
00209     int dst_ct = dst->clip_rect.y;
00210     int dst_cb = dst->clip_rect.h + dst_ct;
00211 
00212 // if (dst->clip)
00213     if (1)
00214     {
00215         int tmp;
00216 
00217         tmp = dst_cl - dx;
00218         sxbeg = ((tmp < 0) ? 0 : tmp);
00219         dxbeg = sxbeg + dx;
00220 
00221         tmp = dst_cr - dx;
00222         w = ((tmp > src->w) ? src->w : tmp) - sxbeg;
00223         if ( w<=0 ) return;
00224 
00225         tmp = dst_ct - dy;
00226         sybeg = ((tmp < 0) ? 0 : tmp);
00227         dybeg = sybeg + dy;
00228 
00229         tmp = dst_cb - dy;
00230         h = ((tmp > src->h) ? src->h : tmp) - sybeg;
00231         if ( h<=0 ) return;
00232     }
00233     else 
00234     {
00235         w = src->w;
00236         h = src->h;
00237         sxbeg = 0;
00238         sybeg = 0;
00239         dxbeg = dx;
00240         dybeg = dy;
00241     }
00242 
00243     s = (RLE_PTR) (src->dat);
00244 
00245     /* Clip top.  */
00246     for (y = sybeg - 1; y >= 0; y--) 
00247     {
00248         long c = *s++;
00249 
00250         while (!RLE_IS_EOL(c)) 
00251         {
00252             if (c > 0)
00253                 s += c;
00254             c = *s++;
00255         }
00256     }
00257 
00258     //@@@ bmp_select(dst);
00259 
00260     /* Visible part.  */
00261     for (y = 0; y < h; y++) 
00262     {
00263         //@@@ PIXEL_PTR d = OFFSET_PIXEL_PTR(bmp_write_line(dst, dybeg + y), dxbeg);
00264         PIXEL_PTR d = (PIXEL_PTR) dst->pixels;
00265         d += (dybeg+y)*PITCH;
00266         d = OFFSET_PIXEL_PTR( d, dxbeg );
00267         long c = *s++;
00268 
00269         /* Clip left.  */
00270         for (x = sxbeg; x > 0; ) {
00271             if (RLE_IS_EOL(c))
00272                 goto next_line;
00273             else if (c > 0) {
00274                 /* Run of solid pixels.  */
00275                 if ((x - c) >= 0) {
00276                     /* Fully clipped.  */
00277                     x -= c;
00278                     s += c;
00279                 }
00280                 else {
00281                     /* Visible on the right.  */
00282                     c -= x;
00283                     s += x;
00284                     break;
00285                 }
00286             }
00287             else {
00288                 /* Run of transparent pixels.  */
00289                 if ((x + c) >= 0) {
00290                     /* Fully clipped.  */
00291                     x += c;
00292                 }
00293                 else {
00294                     /* Visible on the right.  */
00295                     c += x;
00296                     break;
00297                 }
00298             }
00299 
00300             c = *s++;
00301         }
00302 
00303         /* Visible part.  */
00304         for (x = w; x > 0; ) {
00305             if (RLE_IS_EOL(c))
00306                 goto next_line;
00307             else if (c > 0) {
00308                 /* Run of solid pixels.  */
00309                 if ((x - c) >= 0) {
00310                     /* Fully visible.  */
00311                     x -= c;
00312                     for (c--; c >= 0; s++, INC_PIXEL_PTR(d), c--) {
00313                         unsigned long col = (unsigned char) (*s);
00314                         PUT_PIXEL(d, col);
00315                     }
00316                 }
00317                 else {
00318                     /* Clipped on the right.  */
00319                     c -= x;
00320                     for (x--; x >= 0; s++, INC_PIXEL_PTR(d), x--) {
00321                         unsigned long col = (unsigned char) (*s);
00322                         PUT_PIXEL(d, col);
00323                     }
00324                     break;
00325                 }
00326             }
00327             else {
00328                 /* Run of transparent pixels.  */
00329                 x += c;
00330                 d = OFFSET_PIXEL_PTR(d, -c);
00331             }
00332 
00333             c = *s++;
00334         }
00335 
00336         /* Clip right.  */
00337         while (!RLE_IS_EOL(c)) {
00338             if (c > 0)
00339                 s += c;
00340             c = *s++;
00341         }
00342 
00343 next_line: ;
00344     }
00345 
00346    //@@@bmp_unwrite_line(dst);
00347 }