| author | ecalot
<ecalot> 2004-08-15 00:03:31 UTC |
| committer | ecalot
<ecalot> 2004-08-15 00:03:31 UTC |
| parent | 2b76202a246f56879ddbeeaf89b3fad56753ac28 |
| FP/src/conf/files.conf | +17 | -0 |
| FP/src/conf/mods.conf | +4 | -0 |
| FP/src/conf/parts.conf | +6 | -0 |
| FP/src/conf/resources.conf | +9 | -0 |
| FP/src/conf/types.conf | +5 | -0 |
| FP/src/include/resources.h | +1 | -10 |
| FP/src/res/maps.c | +4 | -4 |
| FP/src/res/resources.c | +70 | -165 |
diff --git a/FP/src/conf/files.conf b/FP/src/conf/files.conf new file mode 100644 index 0000000..9c638e1 --- /dev/null +++ b/FP/src/conf/files.conf @@ -0,0 +1,17 @@ +#files! + +LEVEL levels.dat +KID kid.dat +PRINCE prince.dat +VDUNGEON vdungeon.dat +PCSOUND ibmsnd1.dat ibmsnd2.dat +TITLES titles.dat + + + + + + + + + diff --git a/FP/src/conf/mods.conf b/FP/src/conf/mods.conf new file mode 100644 index 0000000..dcc3734 --- /dev/null +++ b/FP/src/conf/mods.conf @@ -0,0 +1,4 @@ +LEFT 0x00 +RIGHT 0x01 +INVERT 0x02 +NORMAL 0x00 diff --git a/FP/src/conf/parts.conf b/FP/src/conf/parts.conf new file mode 100644 index 0000000..d91286c --- /dev/null +++ b/FP/src/conf/parts.conf @@ -0,0 +1,6 @@ +# this is the distribution the resource number will have + +mods 8 +size 8 +from 12 +type 3 diff --git a/FP/src/conf/resources.conf b/FP/src/conf/resources.conf new file mode 100644 index 0000000..ac25664 --- /dev/null +++ b/FP/src/conf/resources.conf @@ -0,0 +1,9 @@ +#resources are +# type LVL: 1 (the first level) +# type IMG: 1 (palette) n (frames) +# type PAL: undefined yet + +#define type file resources +MAP LVL LEVEL 2000 +ANIM_JUMP IMG KID 400 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 + diff --git a/FP/src/conf/types.conf b/FP/src/conf/types.conf new file mode 100644 index 0000000..e2073ba --- /dev/null +++ b/FP/src/conf/types.conf @@ -0,0 +1,5 @@ +#headers + +IMG +LVL +PAL diff --git a/FP/src/include/resources.h b/FP/src/include/resources.h index f724a65..4a849ae 100644 --- a/FP/src/include/resources.h +++ b/FP/src/include/resources.h @@ -77,14 +77,6 @@ typedef struct { void** pFrames; }tData; -#define RES_MOD_RIGHT 0x00010000 -#define RES_MOD_LEFT 0x00000000 -#define RES_MOD_MAP 0x00020000 -#define res_modIsRight(a) ((a)&0x0001) -#define res_modIsMap(a) ((a)&0x0002) -#define res_modGetId(a) ((a)&0xffff) -#define res_modGetMask(a) ((a)>>16) - tData* resLoad(long id); /* Function for getting data previously loaded into memory. All id's are * defined in data.h generated by the resource manager and indexer. @@ -102,7 +94,6 @@ void resInit(); void resStop(); /* Resource handling includes */ -#include "res_data.h" -#include "res_types.h" +#include "res_conf.h" #endif diff --git a/FP/src/res/maps.c b/FP/src/res/maps.c index 7193ca3..f5a29b1 100644 --- a/FP/src/res/maps.c +++ b/FP/src/res/maps.c @@ -67,11 +67,11 @@ void maps_getGuard(int pantalla,int *p,int *b,int *skill,int *color,tDirection * } */ /* Publics */ -void* mapLoadLevel(tMemory* level) { +void* mapLoadLevel(tMemory level) { tMap* map=(tMap*)malloc(sizeof(tMap)); - memcpy(map->fore,level->array+MAPS_BLOCK_OFFSET_WALL,30*24); - memcpy(map->back,level->array+MAPS_BLOCK_OFFSET_BACK,30*24); - memcpy(map->start,level->array+MAPS_BLOCK_OFFSET_START_POSITION,3); + memcpy(map->fore,level.array+MAPS_BLOCK_OFFSET_WALL,30*24); + memcpy(map->back,level.array+MAPS_BLOCK_OFFSET_BACK,30*24); + memcpy(map->start,level.array+MAPS_BLOCK_OFFSET_START_POSITION,3); /* memcpy(slevel(links),level.data+MAPS_BLOCK_OFFSET_LINKS,4*24);*/ return (void*)map; } diff --git a/FP/src/res/resources.c b/FP/src/res/resources.c index 4187bce..9eb048e 100644 --- a/FP/src/res/resources.c +++ b/FP/src/res/resources.c @@ -39,6 +39,7 @@ resources.c: Princed Resources : DAT Extractor #include "freeprince.h" #include "resources.h" #include "output.h" +#include "maps.h" #include "compress.h" @@ -53,73 +54,6 @@ resources.c: Princed Resources : DAT Extractor * Resource creation */ -tData* res_createData(int nFrames,int type) { - tData* result; - result=(tData*)malloc(sizeof(tData)); - - switch (type) { - case RES_TYPE_IMG: - result->type=eImages;/*res_getVirtualTypeFromReal(res_getIdxType);*/ - nFrames--; - break; - case RES_TYPE_LVL: - result->type=eLevel;/*res_getVirtualTypeFromReal(res_getIdxType);*/ - break; - } - - result->pFrames=(void**)malloc(nFrames*sizeof(void*)); - result->frames=nFrames; - return result; -} - -/* Using the type and the array data this function will return the resources in void* fromat */ -void res_createFrames(tMemory data,int type,void** returnValue,int number,int mask) { - tMemory* result; - static tImage image; - static tPalette palette; - palette.colors=16; /* TODO: detect when it is 2 colors */ - palette.color=(tColor*)image.pal; - - switch (type) { - case RES_TYPE_IMG: - if (!number) { - if (data.size!=100) { - printf("Fatal error: res_createFrames: invalid palette\n"); - exit(1); - } - memcpy(image.pal,data.array+5,16*3); - printf("res_createFrames: Remembering palette\n"); - return; - } else { - number--; - } - mExpandGraphic(data.array,&image,data.size); - /* TODO: the result must be an object created in output module: */ - result=(void*)outputLoadBitmap( - image.pix,image.widthInBytes*image.height,palette,image.height,image.width, - res_modIsRight(mask), - 1 - ); - - printf("res_createFrames: Allocating frame[%d]=? (image type %d)\n",number,type); - break; - case RES_TYPE_SND_MIDI: - case RES_TYPE_SND_WAVE: - case RES_TYPE_IMG_PALETTED: - result=(tMemory*)malloc(sizeof(tMemory)); /* both sides are void* :) */ - /* TODO: data->array must be copied or it wont be available after the file is closed */ - *result=data; - printf("res_createFrames: Allocating resource[%d]\n",number); - - break; - case RES_TYPE_LVL: - (tMemory*)result=mapLoadLevel(data); - break; - } - - returnValue[number]=(void*)result; -} - /* * Functions made to get data from the DAT files using some optimizations */ @@ -128,14 +62,14 @@ int res_getDataById(int id,int maxItems,tMemory* result) { /* This function looks for a data resource in a dat file optimizing the search knowing * that the id's starts in 0 */ - +/* TODO: use static to remember where it is */ long int gotId; int indexNumber; /* main loop */ for (indexNumber=0;indexNumber<maxItems;indexNumber++) { gotId=mReadFileInDatFile( - (indexNumber+id-DATA_START_ITEMS)%maxItems, + (indexNumber+id)%maxItems, &(result->array), (unsigned long *)&(result->size)); if (gotId==id) break; @@ -145,45 +79,8 @@ int res_getDataById(int id,int maxItems,tMemory* result) { return (gotId==id); /* 1 if the id was found, 0 if not */ } -int res_getDataByArray(short int* id,int maxItems,void** result,int ids,int type,int mask) { - /* This function looks for a data resource in a dat file optimizing the search knowing - * that the id's starts in 0 - */ - - long int gotId; - int indexNumber; - int i=0; - int old=-1; - tMemory data; - - /* main loop */ - while((old!=i)&&(i!=ids)) { - old=i; - printf("res_getDataByArray: Starting resource cycling\n"); - for (indexNumber=0;(indexNumber<maxItems)&&(i!=ids);indexNumber++) { - gotId=mReadFileInDatFile( - indexNumber, - &(data.array), - (unsigned long *)&(data.size) - ); - if (gotId==id[i]) { - res_createFrames(data,type,result,i,mask); - i++; - } - } - } - - printf("Done!\n"); - - /* Return value */ - return i; -} - -#define res_getIdxFile1 ((char*)(index.array+1)) -#define res_getIdxFile2 ((char*)(index.array+15)) -#define res_getIdxType (((short int*)(index.array+31))[0]) -#define res_getIdxTotal (((short int*)(index.array+29))[0]) -#define res_getIdxFrames ((short int*)(index.array+33)) +static const short res_list[]=RES_LIST; +static const char* res_file[]=RES_FILES; /** * Public functions @@ -193,76 +90,84 @@ tData* resLoad(long id) { /* Initialize abstract variables to read this new DAT file */ unsigned short int numberOfItems; tData* result; - int i; - char file1[25]; - /*char file2[25];*/ - short int* frames; - short int type; - int nFrames; - tMemory index; - - /* READ INDEX */ - if (!mReadBeginDatFile(&numberOfItems,"index.dat")) return NULL; - if (!res_getDataById(res_modGetId(id),DATA_END_ITEMS,&index)) { - printf("Fatal Error: resLoad: index could not be read!\n"); - return NULL; - } - printf("file1='%s'. file2='%s' type='%d'. frames='%d'.\n", - res_getIdxFile1, - res_getIdxFile2, - res_getIdxType, - res_getIdxTotal - ); - - nFrames=res_getIdxTotal; - frames=(short int*)malloc(nFrames*sizeof(short int)); - type=res_getIdxType; - for (i=0;i<nFrames;i++) { - frames[i]=res_getIdxFrames[i]; - } - - strncpy(file1,res_getIdxFile1,14); + tMemory raw; + int mask=res_get_part_mods(id); + int total=res_get_part_size(id); + int from=res_get_part_from(id); + int type=res_get_part_type(id); - mReadCloseDatFile(); - - /* READ FILE */ - - for (i=0;i<nFrames;i++) { - printf("frames[%d]=%d\n",i,frames[i]); - } + switch (type) { + case RES_TYPE_LVL: + if (total!=2) { + printf("Fatal Error: resLoad: invalid level define!\n"); + return NULL; + } + mask+=res_list[from+1]; + if (!mReadBeginDatFile(&numberOfItems,res_file[res_list[from]])) { + printf("Fatal Error: resLoad: level file not found!\n"); + return NULL; + } + if(!res_getDataById(mask,numberOfItems,&raw)) { + printf("Fatal Error: resLoad: level not found!\n"); + return NULL; + } + mReadCloseDatFile(); + return (tData*)mapLoadLevel(raw); /* transform from raw to a loaded map */ + case RES_TYPE_IMG: { + tMemory palette; + tImage image; + tPalette pal; + + result=(tData*)malloc(sizeof(tData)); + result->frames=total-2; /* drop filename and palette */ + result->pFrames=(void**)malloc(result->frames*sizeof(void*)); + if (!mReadBeginDatFile(&numberOfItems,res_file[res_list[from]])) { + printf("Fatal Error: resLoad: level file not found!\n"); + return NULL; + } + if(!res_getDataById(res_list[from+1],numberOfItems,&palette)) { + printf("Fatal Error: resLoad: palette not found!\n"); + return NULL; + } + if (palette.size!=100) { + printf("Fatal error: resLoad: invalid palette\n"); + return NULL; + } + pal.colors=16; /* TODO: detect when it is 2 colors */ + pal.color=(tColor*)(palette.array+5); /*memcpy(image.pal,data.array+5,16*3);*/ + for (total=0;total<result->frames;total++) { + if(!res_getDataById(res_list[from+2+total],numberOfItems,&raw)) { + printf("Fatal Error: resLoad: image not found!\n"); + return NULL; + } - if (!mReadBeginDatFile(&numberOfItems,file1)) { - printf("Fatal Error: resLoad: resource file not found!\n"); - free(frames); - return NULL; - } + /* expand raw image into an image structure */ + mExpandGraphic(raw.array,&image,raw.size); - /* Create a tData object with pFrames empty*/ - result=res_createData(nFrames,type); + /* convert image structure into blittable output surfaces */ + result->pFrames[total]=(void*)outputLoadBitmap( + image.pix,image.widthInBytes*image.height,pal,image.height,image.width, + (mask&(RES_MODS_LEFT))==(RES_MODS_LEFT),1 + ); - /* Fill pFrames into tData object */ - if (!res_getDataByArray(frames,numberOfItems,result->pFrames,nFrames,type,res_modGetMask(id))) { - printf("Fatal Error: resLoad: resource file invalid!\n"); - free(frames); - free(result->pFrames); - free(result); - return NULL; + /* free intermediate image data */ + free(image.pix); + + } + mReadCloseDatFile(); + return result; + } } - - mReadCloseDatFile(); - free(frames); - /* printf("resLoad: returning result pointer 0x%p\n",result); */ - return result; } void resFree(tData* res) { - if (res->type==eImages) { +/* if (res->type==eImages) { while (res->frames) { outputFreeBitmap(res->pFrames[--(res->frames)]); } } printf("ResFree activated\n"); free(res->pFrames); - free(res); + free(res);*/ }