📄 tilemod.c
字号:
/******************************************************************************//* *//* TILE MODIFIERS *//* *//******************************************************************************/#include "gameinc.h"#include "tilemod.h"#ifdef RAINE_DEBUG#include "debug.h"#endifUINT8 tile_8x8_map[8 * 8];static struct TILE_INFO tile_8x8_template ={ 1, TILE_TYPE_8x8, 8, 8, tile_8x8_map, NULL, 0, 0,};UINT8 tile_16x16_map[16 * 16];UINT8 tile_32x32_map[32 * 32];static struct TILE_INFO tile_16x16_template ={ 1, TILE_TYPE_16x16, 16, 16, tile_16x16_map, NULL, 0, 0,};static struct TILE_INFO tile_32x32_template ={ 1, TILE_TYPE_32x32, 32, 32, tile_32x32_map, NULL, 0, 0,};static void do_rotate(TILE_INFO *tile, UINT32 rotate){ UINT32 count,size,x,y,ta,tb,tc; UINT8 *src,*buffer; if(!rotate) return; x = tile->width; y = tile->height; count = tile->count; size = x * y; src = tile->data; if(!(buffer=AllocateMem(size))) return; for(tc=0;tc<count;tc++){ memcpy(buffer, src, size); switch(rotate){ case 1: for(tb=0; tb<y; tb++){ for(ta=0; ta<x; ta++){ src[ ta + (tb*x) ] = buffer[ (((x-1)-ta)*y) + tb ]; } } break; case 2: for(tb=0; tb<y; tb++){ for(ta=0; ta<x; ta++){ src[ ta + (tb*x) ] = buffer[ ((x-1)-ta) + (((y-1)-tb)*x) ]; } } break; case 3: for(tb=0; tb<y; tb++){ for(ta=0; ta<x; ta++){ src[ ta + (tb*x) ] = buffer[ (ta*y) + ((y-1)-tb) ]; } } break; } src += size; } FreeMem(buffer);}static void do_flip(TILE_INFO *tile, UINT32 flip){ UINT32 count,size,x,y,ta,tb,tc; UINT8 *src,*buffer; if(!flip) return; x = tile->width; y = tile->height; count = tile->count; size = x * y; src = tile->data; if(!(buffer=AllocateMem(size))) return; for(tc=0;tc<count;tc++){ memcpy(buffer, src, size); switch(flip){ case 1: for(tb=0; tb<y; tb++){ for(ta=0; ta<x; ta++){ src[ ta + (tb*x) ] = buffer[ ((x-1)-ta) + (tb*x) ]; } } break; case 2: for(tb=0; tb<y; tb++){ for(ta=0; ta<x; ta++){ src[ ta + (tb*x) ] = buffer[ ta + (((y-1)-tb)*x) ]; } } break; case 3: for(tb=0; tb<y; tb++){ for(ta=0; ta<x; ta++){ src[ ta + (tb*x) ] = buffer[ ((x-1)-ta) + (((y-1)-tb)*x) ]; } } break; } src += size; } FreeMem(buffer);}void Rotate8x8(UINT8 *source, UINT32 count){ UINT8 *TMP,*SRC; UINT32 ta,tb,tc; if(!(TMP=AllocateMem(0x40))) return; SRC=source; for(tc=0;tc<count;tc++){ for(tb=0;tb<0x40;tb++){ TMP[tb]=SRC[tb]; } for(tb=0;tb<8;tb++){ for(ta=0;ta<8;ta++){ SRC[ta+(tb<<3)]=TMP[(ta<<3)+tb]; } } SRC+=0x40; } FreeMem(TMP);}void Rotate8x8_4bpp(UINT8 *source, UINT32 count){ UINT8 TMP[0x40],TMP2[0x40],*SRC; UINT32 ta,tb,tc; SRC=source; for(tc=0;tc<count;tc++){ for(tb=0;tb<0x40;tb+=2){ TMP[tb+0]=(SRC[tb>>1]>>4)&15; TMP[tb+1]=(SRC[tb>>1]>>0)&15; } for(tb=0;tb<8;tb++){ for(ta=0;ta<8;ta++){ TMP2[ta+(tb<<3)]=TMP[(ta<<3)+tb]; } } for(tb=0;tb<0x40;tb+=2){ SRC[tb>>1]=(TMP2[tb+0]&15)<<4; SRC[tb>>1]|=(TMP2[tb+1]&15)<<0; } SRC+=0x20; }}void Rotate16x16(UINT8 *source, UINT32 count){ UINT8 *TMP,*SRC; UINT32 ta,tb,tc; if(!(TMP=AllocateMem(0x100))){return;} SRC=source; for(tc=0;tc<count;tc++){ for(tb=0;tb<0x100;tb++){ TMP[tb]=SRC[tb]; } for(tb=0;tb<16;tb++){ for(ta=0;ta<16;ta++){ SRC[ta+(tb<<4)]=TMP[(ta<<4)+tb]; } } SRC+=0x100; } FreeMem(TMP);}void Flip8x8_X(UINT8 *source, UINT32 count){ UINT8 *TMP,*SRC; UINT32 ta,tb,tc; if(!(TMP=AllocateMem(0x40))){return;} SRC=source; for(tc=0;tc<count;tc++){ for(tb=0;tb<0x40;tb++){ TMP[tb]=SRC[tb]; } for(tb=0;tb<8;tb++){ for(ta=0;ta<8;ta++){ SRC[ta+(tb<<3)]=TMP[(ta)+((7-tb)<<3)]; } } SRC+=0x40; } FreeMem(TMP);}void Flip8x8_4bpp_X(UINT8 *source, UINT32 count){ UINT8 TMP[0x40],TMP2[0x40],*SRC; UINT32 ta,tb,tc; SRC=source; for(tc=0;tc<count;tc++){ for(tb=0;tb<0x40;tb+=2){ TMP[tb+0]=(SRC[tb>>1]>>4)&15; TMP[tb+1]=(SRC[tb>>1]>>0)&15; } for(tb=0;tb<8;tb++){ for(ta=0;ta<8;ta++){ TMP2[ta+(tb<<3)]=TMP[(ta)+((7-tb)<<3)]; } } for(tb=0;tb<0x40;tb+=2){ SRC[tb>>1]=(TMP2[tb+0]&15)<<4; SRC[tb>>1]|=(TMP2[tb+1]&15)<<0; } SRC+=0x20; }}void Flip16x16_X(UINT8 *source, UINT32 count){ UINT8 *TMP,*SRC; UINT32 ta,tb,tc; if(!(TMP=AllocateMem(0x100))){return;} SRC=source; for(tc=0;tc<count;tc++){ for(tb=0;tb<0x100;tb++){ TMP[tb]=SRC[tb]; } for(tb=0;tb<16;tb++){ for(ta=0;ta<16;ta++){ SRC[ta+(tb<<4)]=TMP[(ta)+((15-tb)<<4)]; } } SRC+=0x100; } FreeMem(TMP);}void Flip8x8_Y(UINT8 *source, UINT32 count){ UINT8 *TMP,*SRC; UINT32 ta,tb,tc; if(!(TMP=AllocateMem(0x40))){return;} SRC=source; for(tc=0;tc<count;tc++){ for(tb=0;tb<0x40;tb++){ TMP[tb]=SRC[tb]; } for(tb=0;tb<8;tb++){ for(ta=0;ta<8;ta++){ SRC[ta+(tb<<3)]=TMP[(7-ta)+((tb)<<3)]; } } SRC+=0x40; } FreeMem(TMP);}void Flip16x16_Y(UINT8 *source, UINT32 count){ UINT8 *TMP,*SRC; UINT32 ta,tb,tc; if(!(TMP=AllocateMem(0x100))){return;} SRC=source; for(tc=0;tc<count;tc++){ for(tb=0;tb<0x100;tb++){ TMP[tb]=SRC[tb]; } for(tb=0;tb<16;tb++){ for(ta=0;ta<16;ta++){ SRC[ta+(tb<<4)]=TMP[(15-ta)+((tb)<<4)]; } } SRC+=0x100; } FreeMem(TMP);}void CountColours(UINT8 *source, UINT32 count){ UINT32 ta,tb; tb=0; for(ta=0;ta<count;ta++){ if((source[ta]&0x20)!=0)tb++; }#ifdef RAINE_DEBUG print_debug("64 Colour Bytes: $%08x\n",tb);#endif}UINT8 check_tile_solid(UINT8 *src, UINT32 size){ UINT32 i, a, b; for(i = 0, a = 0, b = 0; i < size; i++){ if(src[i]) a = 1; else b = 1; } if((!a) && (b)) return 0; // Draw Nothing if( (a) && (b)) return 1; // Draw Transparent if( (a) && (!b)) return 2; // Draw Solid return 0;}UINT8 *MakeSolidTileMap(UINT8 *source, UINT32 count, UINT32 size){ UINT32 ta,tb,tc; UINT8 *map; if(!(map=AllocateMem(count)))return(NULL); // Apparently tiles are 16x16 per default... (hope so !) tile_list[tile_list_count].count = count; tile_list[tile_list_count].type = TILE_TYPE_16x16; tile_list[tile_list_count].width = 16; tile_list[tile_list_count].height = 16; tile_list[tile_list_count].data = source; tile_list[tile_list_count].mask = map; tile_list[tile_list_count].rotate = 0; tile_list[tile_list_count].flip = 0; tile_list_count++; tb=0; for(ta=0;ta<count;ta++){ map[ta]=1; // This tile is solid! for(tc=0;tc<size;tc++,tb++){ if(source[tb]==0)map[ta]=0; // This tile is not solid! } } return(map);}char *tile_type[TILE_TYPE_MAX] ={ " X x Y (Nbpp)", " 8 x 8 (8bpp)", "16 x 16 (8bpp)", "32 x 32 (8bpp)",};void check_tile_rotation(void){ UINT32 i,j,k; /*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -