diff options
author | Paweł Kołodziejski | 2004-05-01 16:15:55 +0000 |
---|---|---|
committer | Paweł Kołodziejski | 2004-05-01 16:15:55 +0000 |
commit | 0af53f3c97075e380aab15bcc8dd7126b05bd9c4 (patch) | |
tree | a2f929125159a287518df2a70f11d58561dd954e /saga/sprite.cpp | |
parent | d84d93b5d0709e95dec412fe8c9b4e5c2dfa9e2e (diff) | |
download | scummvm-rg350-0af53f3c97075e380aab15bcc8dd7126b05bd9c4.tar.gz scummvm-rg350-0af53f3c97075e380aab15bcc8dd7126b05bd9c4.tar.bz2 scummvm-rg350-0af53f3c97075e380aab15bcc8dd7126b05bd9c4.zip |
indent
svn-id: r13715
Diffstat (limited to 'saga/sprite.cpp')
-rw-r--r-- | saga/sprite.cpp | 175 |
1 files changed, 39 insertions, 136 deletions
diff --git a/saga/sprite.cpp b/saga/sprite.cpp index 0339e5f00a..e47c175c02 100644 --- a/saga/sprite.cpp +++ b/saga/sprite.cpp @@ -20,21 +20,13 @@ * $Header$ * */ -/* - Description: - - Sprite management module - Notes: -*/ +// Sprite management module #include "reinherit.h" #include "yslib.h" -/* - * Uses the following modules: -\*--------------------------------------------------------------------------*/ #include "game_mod.h" #include "gfx_mod.h" #include "scene_mod.h" @@ -43,9 +35,6 @@ #include "text_mod.h" #include "font_mod.h" -/* - * Begin module component -\*--------------------------------------------------------------------------*/ #include "sprite_mod.h" #include "sprite.h" @@ -53,8 +42,7 @@ namespace Saga { static R_SPRITE_MODULE SpriteModule = { 0, 0, 0, 0 }; -int SPRITE_Init(void) -{ +int SPRITE_Init() { int result; if (SpriteModule.init) { @@ -63,12 +51,9 @@ int SPRITE_Init(void) R_printf(R_STDOUT, "Initializing sprite subsystem...\n"); - /* Load sprite module resource context - * \*------------------------------------------------------------- */ - result = GAME_GetFileContext(&SpriteModule.sprite_ctxt, - R_GAME_RESOURCEFILE, 0); + // Load sprite module resource context + result = GAME_GetFileContext(&SpriteModule.sprite_ctxt, R_GAME_RESOURCEFILE, 0); if (result != R_SUCCESS) { - return R_FAILURE; } @@ -84,8 +69,7 @@ int SPRITE_Init(void) return R_SUCCESS; } -int SPRITE_Shutdown(void) -{ +int SPRITE_Shutdown() { if (!SpriteModule.init) { return R_FAILURE; } @@ -97,28 +81,20 @@ int SPRITE_Shutdown(void) return R_SUCCESS; } -int SPRITE_LoadList(int resource_num, R_SPRITELIST ** sprite_list_p) -{ +int SPRITE_LoadList(int resource_num, R_SPRITELIST **sprite_list_p) { R_SPRITELIST *new_slist; - byte *spritelist_data; size_t spritelist_len; - const byte *read_p; - uint16 sprite_count; uint16 i; new_slist = (R_SPRITELIST *)malloc(sizeof *new_slist); if (new_slist == NULL) { - return R_MEM; } - if (RSC_LoadResource(SpriteModule.sprite_ctxt, - resource_num, - &spritelist_data, &spritelist_len) != R_SUCCESS) { - + if (RSC_LoadResource(SpriteModule.sprite_ctxt, resource_num, &spritelist_data, &spritelist_len) != R_SUCCESS) { return R_FAILURE; } @@ -128,18 +104,15 @@ int SPRITE_LoadList(int resource_num, R_SPRITELIST ** sprite_list_p) new_slist->sprite_count = sprite_count; - new_slist->offset_list = (R_SPRITELIST_OFFSET *)malloc(sprite_count * - sizeof *new_slist->offset_list); + new_slist->offset_list = (R_SPRITELIST_OFFSET *)malloc(sprite_count * sizeof *new_slist->offset_list); if (new_slist->offset_list == NULL) { free(new_slist); - return R_MEM; } for (i = 0; i < sprite_count; i++) { new_slist->offset_list[i].data_idx = 0; - new_slist->offset_list[i].offset = - ys_read_u16_le(read_p, &read_p); + new_slist->offset_list[i].offset = ys_read_u16_le(read_p, &read_p); } new_slist->slist_rn = resource_num; @@ -151,30 +124,21 @@ int SPRITE_LoadList(int resource_num, R_SPRITELIST ** sprite_list_p) return R_SUCCESS; } -int SPRITE_AppendList(int resource_num, R_SPRITELIST * spritelist) -{ +int SPRITE_AppendList(int resource_num, R_SPRITELIST *spritelist) { byte *spritelist_data; size_t spritelist_len; - const byte *read_p; - void *test_p; - uint16 old_sprite_count; uint16 new_sprite_count; uint16 sprite_count; - int i; if (spritelist->append_count >= (R_APPENDMAX - 1)) { - return R_FAILURE; } - if (RSC_LoadResource(SpriteModule.sprite_ctxt, - resource_num, - &spritelist_data, &spritelist_len) != R_SUCCESS) { - + if (RSC_LoadResource(SpriteModule.sprite_ctxt, resource_num, &spritelist_data, &spritelist_len) != R_SUCCESS) { return R_FAILURE; } @@ -185,8 +149,7 @@ int SPRITE_AppendList(int resource_num, R_SPRITELIST * spritelist) old_sprite_count = spritelist->sprite_count; new_sprite_count = spritelist->sprite_count + sprite_count; - test_p = realloc(spritelist->offset_list, - new_sprite_count * sizeof *spritelist->offset_list); + test_p = realloc(spritelist->offset_list, new_sprite_count * sizeof *spritelist->offset_list); if (test_p == NULL) { return R_MEM; } @@ -198,8 +161,7 @@ int SPRITE_AppendList(int resource_num, R_SPRITELIST * spritelist) for (i = old_sprite_count; i < spritelist->sprite_count; i++) { spritelist->offset_list[i].data_idx = spritelist->append_count; - spritelist->offset_list[i].offset = - ys_read_u16_le(read_p, &read_p); + spritelist->offset_list[i].offset = ys_read_u16_le(read_p, &read_p); } spritelist->sprite_data[spritelist->append_count] = spritelist_data; @@ -207,14 +169,11 @@ int SPRITE_AppendList(int resource_num, R_SPRITELIST * spritelist) return R_SUCCESS; } -int SPRITE_GetListLen(R_SPRITELIST * spritelist) -{ - +int SPRITE_GetListLen(R_SPRITELIST *spritelist) { return spritelist->sprite_count; } -int SPRITE_Free(R_SPRITELIST * spritelist) -{ +int SPRITE_Free(R_SPRITELIST *spritelist) { int i; for (i = 0; i <= spritelist->append_count; i++) { @@ -228,30 +187,19 @@ int SPRITE_Free(R_SPRITELIST * spritelist) return R_SUCCESS; } -int -SPRITE_Draw(R_SURFACE * ds, - R_SPRITELIST * sprite_list, int sprite_num, int spr_x, int spr_y) -{ - +int SPRITE_Draw(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int spr_x, int spr_y) { int offset; int offset_idx; - byte *sprite_p; - const byte *sprite_data_p; const byte *read_p; - int i, j; - byte *buf_row_p; byte *src_row_p; - int s_width; int s_height; - int clip_width; int clip_height; - int x_align; int y_align; @@ -286,32 +234,29 @@ SPRITE_Draw(R_SURFACE * ds, return 0; } - DecodeRLESprite(sprite_data_p, - 64000, SpriteModule.decode_buf, s_width * s_height); + DecodeRLESprite(sprite_data_p, 64000, SpriteModule.decode_buf, s_width * s_height); buf_row_p = ds->buf + ds->buf_pitch * spr_y; src_row_p = SpriteModule.decode_buf; - /* Clip to right side of surface */ + // Clip to right side of surface clip_width = s_width; if (s_width > (ds->buf_w - spr_x)) { clip_width = (ds->buf_w - spr_x); } - /* Clip to bottom side of surface */ + // Clip to bottom side of surface clip_height = s_height; if (s_height > (ds->buf_h - spr_y)) { clip_height = (ds->buf_h - spr_y); } for (i = 0; i < clip_height; i++) { - for (j = 0; j < clip_width; j++) { if (*(src_row_p + j) != 0) { *(buf_row_p + j + spr_x) = *(src_row_p + j); } } - buf_row_p += ds->buf_pitch; src_row_p += s_width; } @@ -319,51 +264,41 @@ SPRITE_Draw(R_SURFACE * ds, return R_SUCCESS; } -int -SPRITE_DrawOccluded(R_SURFACE * ds, - R_SPRITELIST * sprite_list, int sprite_num, int spr_x, int spr_y) -{ +int SPRITE_DrawOccluded(R_SURFACE *ds, R_SPRITELIST *sprite_list, int sprite_num, int spr_x, int spr_y) { int offset; int offset_idx; - byte *sprite_p; const byte *sprite_data_p; const byte *read_p; - int i; - int x, y; byte *dst_row_p; byte *src_row_p; byte *src_p; byte *dst_p; byte *mask_p; - int s_width; int s_height; int x_align; int y_align; - int z_lut[R_SPRITE_ZMAX]; int e_slope; - /* Clipinfo variables */ + // Clipinfo variables R_POINT spr_pt; R_RECT spr_src_rect; R_RECT spr_dst_rect; - R_CLIPINFO ci; - /* BG mask variables */ + // BG mask variables int mask_w; int mask_h; byte *mask_buf; size_t mask_buf_len; - byte *mask_row_p; int mask_z; - /* Z info variables */ + // Z info variables SCENE_ZINFO zinfo; int actor_z; @@ -376,16 +311,11 @@ SPRITE_DrawOccluded(R_SURFACE * ds, } if (sprite_num >= sprite_list->sprite_count) { - - R_printf(R_STDOUT, - "Invalid sprite number (%d) for sprite list %d.\n", - sprite_num, sprite_list->slist_rn); - + R_printf(R_STDOUT, "Invalid sprite number (%d) for sprite list %d.\n", sprite_num, sprite_list->slist_rn); return R_FAILURE; } - /* Get sprite data from list - * \*------------------------------------------------------------- */ + // Get sprite data from list offset = sprite_list->offset_list[sprite_num].offset; offset_idx = sprite_list->offset_list[sprite_num].data_idx; @@ -394,8 +324,8 @@ SPRITE_DrawOccluded(R_SURFACE * ds, read_p = sprite_p; - /* Read sprite dimensions -- should probably cache this stuff in - * sprite list */ + // Read sprite dimensions -- should probably cache this stuff in + // sprite list x_align = ys_read_s8(read_p, &read_p); y_align = ys_read_s8(read_p, &read_p); @@ -404,16 +334,13 @@ SPRITE_DrawOccluded(R_SURFACE * ds, sprite_data_p = read_p; - /* Create actor Z occlusion LUT - * \*---------------------------------------------------------------------- */ + // Create actor Z occlusion LUT SCENE_GetZInfo(&zinfo); e_slope = zinfo.end_slope; for (i = 0; i < R_SPRITE_ZMAX; i++) { - - z_lut[i] = - (int)(e_slope + ((137.0 - e_slope) / 14.0) * (15.0 - i)); + z_lut[i] = (int)(e_slope + ((137.0 - e_slope) / 14.0) * (15.0 - i)); } actor_z = spr_y; @@ -446,29 +373,21 @@ SPRITE_DrawOccluded(R_SURFACE * ds, return R_SUCCESS; } - DecodeRLESprite(sprite_data_p, - 64000, SpriteModule.decode_buf, s_width * s_height); + DecodeRLESprite(sprite_data_p, 64000, SpriteModule.decode_buf, s_width * s_height); - /* Finally, draw the occluded sprite - * \*---------------------------------------------------------------------- */ - src_row_p = SpriteModule.decode_buf + ci.src_draw_x + - (ci.src_draw_y * s_width); + // Finally, draw the occluded sprite + src_row_p = SpriteModule.decode_buf + ci.src_draw_x + (ci.src_draw_y * s_width); dst_row_p = ds->buf + ci.dst_draw_x + (ci.dst_draw_y * ds->buf_pitch); mask_row_p = mask_buf + ci.dst_draw_x + (ci.dst_draw_y * mask_w); for (y = 0; y < ci.draw_h; y++) { - src_p = src_row_p; dst_p = dst_row_p; mask_p = mask_row_p; - for (x = 0; x < ci.draw_w; x++) { - if (*src_p != 0) { - mask_z = *mask_p & R_SPRITE_ZMASK; - if (actor_z > z_lut[mask_z]) { *dst_p = *src_p; } @@ -482,36 +401,23 @@ SPRITE_DrawOccluded(R_SURFACE * ds, src_row_p += s_width; } /* - { - char buf[1024] = { 0 }; - - sprintf( buf, "dw: %d, dh: %d.", ci.draw_w, ci.draw_h ); - - TEXT_Draw( 2, - ds, - buf, - spr_x - x_align, spr_y - y_align, - 255, 0, - FONT_OUTLINE ); - } + { + char buf[1024] = { 0 }; + sprintf( buf, "dw: %d, dh: %d.", ci.draw_w, ci.draw_h ); + + TEXT_Draw(2, ds, buf, spr_x - x_align, spr_y - y_align, 255, 0, FONT_OUTLINE); + } */ return R_SUCCESS; } -int -DecodeRLESprite(const byte * inbuf, - size_t inbuf_len, byte * outbuf, size_t outbuf_len) -{ - +int DecodeRLESprite(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len) { int bg_runcount; int fg_runcount; - const byte *inbuf_ptr; byte *outbuf_ptr; - const byte *inbuf_end; byte *outbuf_end; - int c; inbuf_ptr = inbuf; @@ -526,7 +432,6 @@ DecodeRLESprite(const byte * inbuf, memset(outbuf, 0, outbuf_len); while ((inbuf_ptr < inbuf_end) && (outbuf_ptr < outbuf_end)) { - bg_runcount = *inbuf_ptr; if (inbuf_ptr < inbuf_end) inbuf_ptr++; @@ -539,7 +444,6 @@ DecodeRLESprite(const byte * inbuf, return 0; for (c = 0; c < bg_runcount; c++) { - *outbuf_ptr = (byte) 0; if (outbuf_ptr < outbuf_end) outbuf_ptr++; @@ -548,7 +452,6 @@ DecodeRLESprite(const byte * inbuf, } for (c = 0; c < fg_runcount; c++) { - *outbuf_ptr = *inbuf_ptr; if (inbuf_ptr < inbuf_end) inbuf_ptr++; |