00001
00002
00003
00004
00005
00006
00007
00008
00009
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
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
00021
00022 int x, y, w, h;
00023 int dxbeg, dybeg;
00024 int sxbeg, sybeg;
00025 RLE_PTR s;
00026
00027 SDL_Surface* dst = gamescreen;
00028
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
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
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
00086
00087
00088 for (y = 0; y < h; y++)
00089 {
00090
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
00097 for (x = sxbeg; x > 0; )
00098 {
00099 if (RLE_IS_EOL(c))
00100 goto next_line;
00101 else if (c > 0)
00102 {
00103
00104 if ((x - c) >= 0)
00105 {
00106
00107 x -= c;
00108 s += c;
00109 }
00110 else
00111 {
00112
00113 c -= x;
00114 s += x;
00115 break;
00116 }
00117 }
00118 else
00119 {
00120
00121 if ((x + c) >= 0) {
00122
00123 x += c;
00124 }
00125 else {
00126
00127 c += x;
00128 break;
00129 }
00130 }
00131
00132 c = *s++;
00133 }
00134
00135
00136 for (x = w; x > 0; )
00137 {
00138 if (RLE_IS_EOL(c))
00139 goto next_line;
00140 else if (c > 0)
00141 {
00142
00143 if ((x - c) >= 0)
00144 {
00145
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
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
00168 x += c;
00169 d = OFFSET_PIXEL_PTR(d, c);
00170 }
00171
00172 c = *s++;
00173 }
00174
00175
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
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
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
00198
00199
00200 int x, y, w, h;
00201 int dxbeg, dybeg;
00202 int sxbeg, sybeg;
00203 RLE_PTR s;
00204
00205 SDL_Surface* dst = gamescreen;
00206
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
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
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
00259
00260
00261 for (y = 0; y < h; y++)
00262 {
00263
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
00270 for (x = sxbeg; x > 0; ) {
00271 if (RLE_IS_EOL(c))
00272 goto next_line;
00273 else if (c > 0) {
00274
00275 if ((x - c) >= 0) {
00276
00277 x -= c;
00278 s += c;
00279 }
00280 else {
00281
00282 c -= x;
00283 s += x;
00284 break;
00285 }
00286 }
00287 else {
00288
00289 if ((x + c) >= 0) {
00290
00291 x += c;
00292 }
00293 else {
00294
00295 c += x;
00296 break;
00297 }
00298 }
00299
00300 c = *s++;
00301 }
00302
00303
00304 for (x = w; x > 0; ) {
00305 if (RLE_IS_EOL(c))
00306 goto next_line;
00307 else if (c > 0) {
00308
00309 if ((x - c) >= 0) {
00310
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
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
00329 x += c;
00330 d = OFFSET_PIXEL_PTR(d, -c);
00331 }
00332
00333 c = *s++;
00334 }
00335
00336
00337 while (!RLE_IS_EOL(c)) {
00338 if (c > 0)
00339 s += c;
00340 c = *s++;
00341 }
00342
00343 next_line: ;
00344 }
00345
00346
00347 }