git » fp-git.git » commit 802fd99

hooked level writing

author ecalot
2006-03-05 07:48:55 UTC
committer ecalot
2006-03-05 07:48:55 UTC
parent f57109302966a97fed1ea8d2beba7fc7055e7ec5

hooked level writing

PR/src/Makefile +5 -1
PR/src/include/common.h +1 -0
PR/src/include/other.h +2 -0
PR/src/include/palette.h +2 -0
PR/src/include/plv.h +5 -2
PR/src/include/reslist.h +3 -1
PR/src/include/types.h +3 -1
PR/src/lib/actions/export.c +3 -0
PR/src/lib/formats/plv.c +7 -7
PR/src/lib/object/image/image16.c +1 -1
PR/src/lib/object/image/image2.c +1 -1
PR/src/lib/object/image/image256.c +1 -1
PR/src/lib/object/image/image_common.c +1 -1
PR/src/lib/object/object.c +26 -4
PR/src/lib/xml/search.c +2 -1

diff --git a/PR/src/Makefile b/PR/src/Makefile
index 71b62bb..d04c3d0 100644
--- a/PR/src/Makefile
+++ b/PR/src/Makefile
@@ -56,7 +56,7 @@ XML      = .parse.o .search.o .unknown.o .translate.o .tree.o
 COMPRESS = .lzg_compress.o .lzg_uncompress.o .rle_compress.o .rle_uncompress.o .rlec_uncompress.o 
 LAYERS   = .dat.o .memory.o .list.o .reslist.o .pallist.o .disk.o .idlist.o .autodetect.o .stringformat.o .resourcematch.o
 FORMAT   = .bmp.o .mid.o .pal.o .wav.o .plv.o
-OBJECT   = .object.o .pop1_4bit.o .image.o .binary.o .sounds.o
+OBJECT   = .object.o .pop1_4bit.o .image.o .binary.o .sounds.o .level.o
 CONSOLE  = .main.o .filedir.o
 MAIN     = .pr.o
 
@@ -154,6 +154,10 @@ $(XMLFILE): xml/resources.xml
 	$(INFO) Compiling resource list module...
 	$(CC) $(OPTIONS) -c lib/layers/reslist.c -o $@
 
+.level.o: lib/object/level/level.c
+	$(INFO) Compiling level class module...
+	$(CC) $(OPTIONS) -c lib/object/level/level.c -o $@
+
 .sounds.o: lib/object/sound/sounds.c
 	$(INFO) Compiling sound list module...
 	$(CC) $(OPTIONS) -c lib/object/sound/sounds.c -o $@
diff --git a/PR/src/include/common.h b/PR/src/include/common.h
index f88dc8d..d61a48e 100644
--- a/PR/src/include/common.h
+++ b/PR/src/include/common.h
@@ -92,6 +92,7 @@ typedef enum {
 	eResTypeMidi=4,
 	eResTypeBinary=5,
 	eResTypePop1Palette4bits=6,
+	eResTypePop1PaletteMono=12,
 	eResTypePcspeaker=7,
 	eResTypeText=8,
 	eResTypePop2Palette320colors=9,
diff --git a/PR/src/include/other.h b/PR/src/include/other.h
index c3b9acd..7528bae 100644
--- a/PR/src/include/other.h
+++ b/PR/src/include/other.h
@@ -40,4 +40,6 @@ int objBinaryWrite(void* o, const char* file, int optionflag, const char* backup
 void* objBinaryRead(const char* file,int *result);
 int objBinarySet(void* o,tResource* res);
 
+void* objLevelCreate(tBinary content,int number,const char* datfile,const char* name,const char* desc,const char* datAuthor,int *error); /* TODO: move to level.h */ 
+
 #endif
diff --git a/PR/src/include/palette.h b/PR/src/include/palette.h
index 541eaed..a72fa64 100644
--- a/PR/src/include/palette.h
+++ b/PR/src/include/palette.h
@@ -68,6 +68,8 @@ void* objPop1Palette4bitsRead(const char* file,int *result);
 int objPop1Palette4bitsSet(void* o,tResource* res);
 
 tColor* objPalette_pop1_4bitsGetColors(void* o);
+#define objPalette_pop1_monoGetColors(o) paletteGetColorArrayForColors(2)
+
 tColor* paletteGetColorArrayForColors(int colors);
 
 #endif
diff --git a/PR/src/include/plv.h b/PR/src/include/plv.h
index 4844741..e507ff5 100644
--- a/PR/src/include/plv.h
+++ b/PR/src/include/plv.h
@@ -62,8 +62,11 @@ plv.h: Princed Resources : PLV prince level files support headers
 #include "reslist.h"
 #include "common.h" /* for PR_VERSION */
 
-int mFormatImportPlv(tResource *res);
-int mFormatExportPlv(const unsigned char* data, const char *vFileext,unsigned long int size,unsigned char level, const char* filename, const char* desc, const char* title, const char* vDatAuthor,int optionflag, const char* backupExtension);
+/*int mFormatImportPlv(tResource *res);
+int mFormatExportPlv(const unsigned char* data, const char *vFileext,unsigned long int size,unsigned char level, const char* filename, const char* desc, const char* title, const char* vDatAuthor,int optionflag, const char* backupExtension);*/
+
+
+int writePlv(const char* file, tBinary content, int popversion, const char* datfile, int level, const char* filename, const char* desc, const char* title, const char* vDatAuthor, int optionflag,const char* backupExtension);
 
 /* Weekdays and months */
 #define DATE_WEEKDAYS "Sun\0Mon\0Tue\0Wed\0Thu\0Fri\0Sat"
diff --git a/PR/src/include/reslist.h b/PR/src/include/reslist.h
index 744b880..4a7b14e 100644
--- a/PR/src/include/reslist.h
+++ b/PR/src/include/reslist.h
@@ -48,7 +48,7 @@ typedef struct {
 }tObject;
 
 typedef struct {
-	unsigned short int value;
+	int                value;
 	char               index[5];
 	unsigned int       order;
 }tResourceId;
@@ -66,6 +66,8 @@ typedef struct {
 	char*              desc;
 	char*              name;
 	char*              path;
+	const char*        datfile;
+	const char*        datAuthor;
 	unsigned long      flags;
 }tResource;
 
diff --git a/PR/src/include/types.h b/PR/src/include/types.h
index 744b880..4a7b14e 100644
--- a/PR/src/include/types.h
+++ b/PR/src/include/types.h
@@ -48,7 +48,7 @@ typedef struct {
 }tObject;
 
 typedef struct {
-	unsigned short int value;
+	int                value;
 	char               index[5];
 	unsigned int       order;
 }tResourceId;
@@ -66,6 +66,8 @@ typedef struct {
 	char*              desc;
 	char*              name;
 	char*              path;
+	const char*        datfile;
+	const char*        datAuthor;
 	unsigned long      flags;
 }tResource;
 
diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c
index 3fdf900..810a4c3 100644
--- a/PR/src/lib/actions/export.c
+++ b/PR/src/lib/actions/export.c
@@ -109,6 +109,9 @@ int extract(const char* vFiledat,const char* vDirExt, tResourceList* r, int opti
 				/* get save file name (if unknown document is in the XML) */
 				getFileName(file,vDirExt,&res,vFiledat,vDatFileName,optionflag,backupExtension,format);
 
+				res.datfile=vFiledat;
+				res.datAuthor=vDatAuthor;
+
 				/* handle palette linking */
 				switch (res.type) { /* TODO: use if and elsif */
 					case eResTypePop1Palette4bits: { /* save and remember palette file */
diff --git a/PR/src/lib/formats/plv.c b/PR/src/lib/formats/plv.c
index 7e6f5c9..662bb35 100644
--- a/PR/src/lib/formats/plv.c
+++ b/PR/src/lib/formats/plv.c
@@ -88,7 +88,7 @@ char* getDate() {
 	return formated;
 }
 
-int mFormatExportPlv(const unsigned char* data, const char *vFileext,unsigned long int size,unsigned char level, const char* filename, const char* desc, const char* title, const char* vDatAuthor,int optionflag,const char* backupExtension) {
+int writePlv(const char* file, tBinary content, int popversion, const char* datfile, int level, const char* filename, const char* desc, const char* title, const char* vDatAuthor, int optionflag,const char* backupExtension) {
 	/* Plv files are saved as raw except you must ignore the checksum and add the plv constant file header */
 
 	/* Variables */
@@ -101,7 +101,7 @@ int mFormatExportPlv(const unsigned char* data, const char *vFileext,unsigned lo
 	static const char* author=PLV_DEFAULT_AUTHOR;
 	unsigned long int block2size;
 	const unsigned long int numberOfFieldPairs=9;
-	unsigned char version;
+	unsigned char version=popversion;
 
 	/* Get current time */
 	now=getDate();
@@ -119,20 +119,20 @@ int mFormatExportPlv(const unsigned char* data, const char *vFileext,unsigned lo
 	/* Writing file */
 
 	/* Safe open for writing mode */
-	ok=writeOpen(vFileext,&target,optionflag);
+	ok=writeOpen(file,&target,optionflag);
 
 	/* Write headers */
 	ok=ok&&fwrite(PLV_HEADER_A,PLV_HEADER_A_SIZE,1,target);
-	if (size==12025) version=2; else version=1;/* TODO: check if the checksum is included */
+	/*if (size==12025) version=2; else version=1; * TODO: check if the checksum is included */
 	ok=ok&&fwritechar(&version,target);
 	version=1;
 	ok=ok&&fwritechar(&version,target);
 	ok=ok&&fwritechar(&level,target);
 	ok=ok&&fwritelong(&numberOfFieldPairs,target);
-	ok=ok&&fwritelong(&size,target);
+	ok=ok&&fwritelong(&content.size,target);
 
 	/* Write block 1: raw data without ignoring checksum */
-	ok=ok&&fwrite(data,size,1,target);
+	ok=ok&&fwrite(content.data,content.size,1,target);
 
 	/* Write footers */
 	block2size=(
@@ -170,7 +170,7 @@ int mFormatExportPlv(const unsigned char* data, const char *vFileext,unsigned lo
 
 extern FILE* outputStream;
 
-int mFormatImportPlv(tResource *res) {
+int readPlv(tResource *res) {
 	/* declare variables */
 	unsigned char* pos;
 	unsigned char* posAux;
diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c
index 15a1e60..453c749 100644
--- a/PR/src/lib/object/image/image16.c
+++ b/PR/src/lib/object/image/image16.c
@@ -403,7 +403,7 @@ void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get lik
 
 	image->pal=palette;
 	bits=paletteGetBits(image->pal);
-	if (bits!=getCarry(image->type)) printf("error, palette mismatch\n");
+	if (bits && bits!=getCarry(image->type)) printf("error, palette mismatch (pal=%d bits=%d)\n",bits,getCarry(image->type));
 	image->bits=getCarry(image->type);
 	
 	return (void*)image;
diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c
index 15a1e60..453c749 100644
--- a/PR/src/lib/object/image/image2.c
+++ b/PR/src/lib/object/image/image2.c
@@ -403,7 +403,7 @@ void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get lik
 
 	image->pal=palette;
 	bits=paletteGetBits(image->pal);
-	if (bits!=getCarry(image->type)) printf("error, palette mismatch\n");
+	if (bits && bits!=getCarry(image->type)) printf("error, palette mismatch (pal=%d bits=%d)\n",bits,getCarry(image->type));
 	image->bits=getCarry(image->type);
 	
 	return (void*)image;
diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c
index 15a1e60..453c749 100644
--- a/PR/src/lib/object/image/image256.c
+++ b/PR/src/lib/object/image/image256.c
@@ -403,7 +403,7 @@ void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get lik
 
 	image->pal=palette;
 	bits=paletteGetBits(image->pal);
-	if (bits!=getCarry(image->type)) printf("error, palette mismatch\n");
+	if (bits && bits!=getCarry(image->type)) printf("error, palette mismatch (pal=%d bits=%d)\n",bits,getCarry(image->type));
 	image->bits=getCarry(image->type);
 	
 	return (void*)image;
diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c
index 15a1e60..453c749 100644
--- a/PR/src/lib/object/image/image_common.c
+++ b/PR/src/lib/object/image/image_common.c
@@ -403,7 +403,7 @@ void* objImageCreate(tBinary cont, tObject palette, int *error) { /* use get lik
 
 	image->pal=palette;
 	bits=paletteGetBits(image->pal);
-	if (bits!=getCarry(image->type)) printf("error, palette mismatch\n");
+	if (bits && bits!=getCarry(image->type)) printf("error, palette mismatch (pal=%d bits=%d)\n",bits,getCarry(image->type));
 	image->bits=getCarry(image->type);
 	
 	return (void*)image;
diff --git a/PR/src/lib/object/object.c b/PR/src/lib/object/object.c
index 6c5f4fa..eafcdbf 100644
--- a/PR/src/lib/object/object.c
+++ b/PR/src/lib/object/object.c
@@ -53,7 +53,7 @@ tObject getObject(tResource* r, int* error) {
 	o.type=r->type;
 	switch (o.type) {
 	case eResTypeLevel:
-		/*o.obj=objLevelCreate(r->content,r->number,vDatFileName,r->name,r->desc,r->datAuthor,error); */
+		o.obj=objLevelCreate(r->content,r->number,r->datfile,r->name,r->desc,r->datAuthor,error); 
 		break;
 	case eResTypeBinary: /* Binary files */
 	case eResTypeText: /* Text files */
@@ -114,14 +114,36 @@ int writeObject(tObject o, const char* file, int optionflag, const char* backupE
 	return error;
 }	
 
+/* Palette class methods */
+
+int paletteGetBits(tObject pal) {
+	switch (pal.type) {
+	case eResTypePop1Palette4bits: 
+		return 4;
+	case eResTypePop1PaletteMono: 
+		return 1;
+	default:
+		return 0;
+	}
+}
+			
+int paletteGetColors(tObject pal) {
+	switch (pal.type) {
+	case eResTypePop1Palette4bits: 
+		return 16;
+	case eResTypePop1PaletteMono: 
+		return 2;
+	default:
+		return 0;
+	}
+}
 
-int paletteGetBits(tObject pal) { return 4; }
-int paletteGetColors(tObject pal) { return 16; }
 tColor* paletteGetColorArray(tObject pal) {
 	switch (pal.type) {
 	case eResTypePop1Palette4bits: /* save and remember palette file */
 		return objPalette_pop1_4bitsGetColors(pal.obj);
-		break;
+	case eResTypePop1PaletteMono: /* save and remember palette file */
+		return objPalette_pop1_monoGetColors(pal.obj);
 	default:
 		return NULL;
 	}
diff --git a/PR/src/lib/xml/search.c b/PR/src/lib/xml/search.c
index 461bccb..9c5bd72 100644
--- a/PR/src/lib/xml/search.c
+++ b/PR/src/lib/xml/search.c
@@ -81,7 +81,8 @@ int xmlParseFileForResource(const char* vFile, const char* datFile, tResourceLis
 	else res.attribute.index[0]=0
 
 #define search_keepIdAttributesElse(attribute,idnum,idindex,idelse) \
-	res.attribute.value=(unsigned short int)ptoi(t->idnum);\
+	if (t->idnum && !strcmp(t->idnum,"monochrome")) res.attribute.value=-1;\
+	else res.attribute.value=(unsigned short int)ptoi(t->idnum);\
 	if (t->idindex) str5lowercpy(res.attribute.index,translateExt2Int(t->idindex));\
 	else str5lowercpy(res.attribute.index,t->idelse)