git » fp-git.git » commit f45c898

new animation library

author ecalot
2005-01-07 03:30:22 UTC
committer ecalot
2005-01-07 03:30:22 UTC
parent 79efc44b85d095bf6c1262504b5754703f4b3a1d

new animation library

FP/src/Makefile +28 -11
FP/src/conf/anims.conf +21 -0
FP/src/conf/awk/anims_conf.awk +157 -0
FP/src/conf/awk/walls_conf.awk +39 -6
FP/src/include/.cvsignore +1 -0
FP/src/include/anims.h +67 -0
FP/src/res/anims.c +88 -0

diff --git a/FP/src/Makefile b/FP/src/Makefile
index f3fe810..b86989c 100644
--- a/FP/src/Makefile
+++ b/FP/src/Makefile
@@ -47,7 +47,7 @@ LINKERRELEASE =
 #Binary code files
 OBJFILES      = main.o kernel.o resources.o dat.o disk.o compress.o \
                 output.o maps.o config.o room.o titles.o \
-                input.o kid.o states.o tiles.o walls.o
+                input.o kid.o states.o tiles.o walls.o anims.o
 EXEFILE       = bin/freeprince
 
 GENERATEDRESHEADERS = include/res_conf_parts.h include/res_conf_files.h\
@@ -58,6 +58,8 @@ GENERATEDSTAHEADERS = include/states_conf_static.h include/states_conf_propertie
 
 GENERATEDTILHEADERS = include/tiles_conf_types.h include/tiles_conf_groups.h
 
+GENERATEDOTHHEADERS = include/walls_conf.h include/anims_conf.h
+
 #Use this to temporary remove an option
 OPTIONS       = $(INCLUDE) $(DEFINES) $(RELEASE)
 LINKEROPTIONS = $(LINKERRELEASE)
@@ -96,9 +98,9 @@ checkawk:
 
 clean:
 	$(INFO) Erasing temporary object files...
-	$(REMOVER) $(OBJFILES) $(EXEFILE)\
-	           $(GENERATEDRESHEADERS) $(GENERATEDSTAHEADERS) $(GENERATEDTILHEADERS)\
-						 $(SRC2) include/walls_conf.h
+	$(REMOVER) $(OBJFILES) $(EXEFILE) $(GENERATEDRESHEADERS)\
+	           $(GENERATEDSTAHEADERS) $(GENERATEDTILHEADERS)\
+	           $(SRC2) $(GENERATEDOTHHEADERS)
 
 build: clean $(EXEFILE)
 
@@ -106,6 +108,9 @@ all: build
 
 install: download build
 
+headers: $(GENERATEDRESHEADERS) $(GENERATEDSTAHEADERS) $(GENERATEDTILHEADERS)\
+         $(GENERATEDOTHHEADERS)
+
 download:
 	$(MAKEDIR) bin
 	$(INFO) Downloading data art files...
@@ -143,17 +148,19 @@ dat.o: res/dat.c include/disk.h include/dat.h
 	$(INFO) Compiling resource dat editing library...
 	$(CC) -c res/dat.c $(OPTIONS)
 
-kernel.o: ker/kernel.c include/kernel.h include/resources.h include/res_conf.h include/output.h
+kernel.o: ker/kernel.c include/kernel.h include/resources.h\
+          include/res_conf.h include/output.h
 	$(INFO) Compiling main kernel...
 	$(CC) -c ker/kernel.c $(OPTIONS)
 
-room.o: ker/room.c include/room.h include/resources.h include/res_conf.h include/walls_conf.h
+room.o: ker/room.c include/room.h include/resources.h include/res_conf.h\
+        include/walls_conf.h
 	$(INFO) Compiling kernel room object...
 	$(CC) -c ker/room.c $(OPTIONS)
 
 kid.o: ker/kid.c include/kid.h include/resources.h include/res_conf.h\
-       include/states.h include/states_conf.h $(GENERATEDRESHEADERS)\
-			 $(GENERATEDTILHEADERS) include/res_conf.h\
+       include/states.h $(GENERATEDRESHEADERS)\
+			 $(GENERATEDSTAHEADERS) $(GENERATEDTILHEADERS) include/res_conf.h\
        include/types.h include/tiles.h include/tiles_conf.h
 	$(INFO) Compiling kernel kid object...
 	$(CC) -c ker/kid.c $(OPTIONS)
@@ -183,7 +190,7 @@ config.o: res/config.c include/resources.h include/res_conf.h
 	$(INFO) Compiling resource configuration module...
 	$(CC) -c res/config.c $(OPTIONS)
 
-states.o: ker/states.c include/states.h include/states_conf.h\
+states.o: ker/states.c include/states.h\
           include/resources.h include/res_conf.h include/types.h\
 					include/tiles.h include/tiles_conf.h $(GENERATEDRESHEADERS)\
 					$(GENERATEDSTAHEADERS) $(GENERATEDTILHEADERS)
@@ -198,6 +205,11 @@ walls.o: res/walls.c include/walls.h include/walls_conf.h
 	$(INFO) Compiling wall algorithm module...
 	$(CC) -c res/walls.c $(OPTIONS)
 
+anims.o: res/anims.c include/anims.h include/anims_conf.h\
+         $(GENERATEDRESHEADERS) $(GENERATEDSTAHEADERS)
+	$(INFO) Compiling animation loader module...
+	$(CC) -c res/anims.c $(OPTIONS)
+	
 #AWK scripts: header generation
 include/res_conf.h: $(GENERATEDRESHEADERS)
 
@@ -223,9 +235,9 @@ include/res_conf_resources.h: conf/resources.conf conf/awk/res_conf_resources.aw
 
 include/states_conf.h: $(GENERATEDSTAHEADERS)
 
-include/states_conf_static.h: conf/states.conf conf/awk/states_conf_static.awk
+include/states_conf_static.h: conf/awk/states_conf_static.awk
 	$(INFO) Creating states list configuration file...
-	$(AWK) -f conf/awk/states_conf_static.awk conf/states.conf>include/states_conf_static.h
+	$(AWK) -f conf/awk/states_conf_static.awk conf/states/*.conf>include/states_conf_static.h
 
 include/states_conf_properties.h: conf/statesproperties.conf conf/awk/states_conf_properties.awk
 	$(INFO) Creating states condition properties configuration file...
@@ -249,3 +261,8 @@ include/walls_conf.h: conf/walls.conf conf/awk/walls_conf.awk
 	$(INFO) Creating wall algorithm randomization file...
 	$(AWK) -f conf/awk/walls_conf.awk conf/walls.conf>include/walls_conf.h
 
+include/anims_conf.h: conf/anims.conf conf/awk/anims_conf.awk
+	$(INFO) Linking animation indexes to the source...
+	$(AWK) -f conf/awk/anims_conf.awk conf/anims.conf>include/anims_conf.h
+
+
diff --git a/FP/src/conf/anims.conf b/FP/src/conf/anims.conf
new file mode 100644
index 0000000..30ee550
--- /dev/null
+++ b/FP/src/conf/anims.conf
@@ -0,0 +1,21 @@
+
+
+#Note that fixedimg with layer bottom means that state animations will be
+#drawn over them leaving the fixedimage as a background. Layer top will
+#be drawn over the state animation.
+
+ANIMATION presentation 1000
+	#frame type     file   pal resId Layer  x  y
+	0      FIXEDIMG PALACE 200 201   bottom        #princess room
+	0      FIXEDIMG PALACE 240 241   bottom 98 124 #bed
+	0      FIXEDIMG PALACE 240 241   top    98 124 #pillar
+	#frame type     file   state
+	0      STATE    PV     jaffar
+	#frame type     file     id
+	#0     MIDI     MIDISND1 100
+	#0     WAV      DIGISND1 100
+	#0     SPEAKER  IBM_SND1 100
+	0      SPEAKER  PCSOUND  100
+
+	
+ANIMATION level1 200
diff --git a/FP/src/conf/awk/anims_conf.awk b/FP/src/conf/awk/anims_conf.awk
new file mode 100644
index 0000000..b6a5c8f
--- /dev/null
+++ b/FP/src/conf/awk/anims_conf.awk
@@ -0,0 +1,157 @@
+#   Princed V3 - Prince of Persia Level Editor for PC Version
+#   Copyright (C) 2003 Princed Development Team
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#   The authors of this program may be contacted at http://forum.princed.com.ar
+
+# anims_conf.awk: FreePrince : walls.conf parser
+# \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
+# Copyright 2005 Princed Development Team
+#  Created: 5 Jan 2005
+#
+#  Author: Enrique Calot <ecalot.cod@princed.com.ar>
+#
+# Note:
+#  DO NOT remove this copyright notice
+#
+
+BEGIN {
+}
+
+###########################
+# PART 1                  #
+# Parse input into memory #
+###########################
+
+#comments
+/^[[:space:]]*#/ {
+	halt
+}
+
+#animation cathegories
+/^[[:space:]]*ANIMATION[[:space:]]/ {
+	$2=toupper($2)
+	animcount++
+	animation["name" animcount]=$2
+	animation["size" animcount]=$3
+	animation["startf" animcount]=totalfixedimg
+	animation["startt" animcount]=totalstate
+	animation["starto" animcount]=totalsound
+	halt
+}
+
+#tables
+#fixed images
+/^[[:space:]]*[[:digit:]]+[[:space:]]+FIXEDIMG[[:space:]]/ {
+	totalfixedimg++
+	f["frame" totalfixedimg]=$1/1
+	f["file" totalfixedimg]=toupper($3)
+	f["pal" totalfixedimg]=$4/1
+	f["res" totalfixedimg]=$5/1
+	f["layer" totalfixedimg]=toupper($6)
+	f["x" totalfixedimg]=$7/1
+	f["y" totalfixedimg]=$8/1
+	animation["sizef" animcount]++
+	halt
+}
+
+#states
+/^[[:space:]]*[[:digit:]]+[[:space:]]+STATE[[:space:]]/ {
+	totalstate++
+	t["frame" totalstate]=$1/1
+	t["file" totalstate]=toupper($3)
+	t["state" totalstate]=toupper($4)
+	animation["sizet" animcount]++
+	halt
+}
+
+#sounds
+/^[[:space:]]*[[:digit:]]+[[:space:]]+(MIDI|WAV|SPEAKER)[[:space:]]/ {
+	totalsound++
+	o["frame" totalsound]=$1/1
+	o["file" totalsound]=toupper($3)
+	o["type" totalsound]=tolower($2)
+	animation["sizeo" animcount]++
+	halt
+}
+
+##########################
+# PART 2                 #
+# Generate output        #
+##########################
+
+END {
+	#avoid empty records
+	if (!totalfixedimg) {
+		printf("Semantic error in line at anims.conf: At least one FIXEDIMG is needed.\n")>"/dev/stderr"
+		exit 30
+	}
+	if (!totalstate) {
+		printf("Semantic error in anims.conf: At least one STATE is needed.\n")>"/dev/stderr"
+		exit 31
+	}
+	if (!totalsound) {
+		printf("Semantic error in anims.conf: At least one SOUND is needed.\n")>"/dev/stderr"
+		exit 32
+	}
+
+	#static defines
+	printf("#define ANIMS_LAYERTYPE_TOP     0\n")
+	printf("#define ANIMS_LAYERTYPE_BOTTOM  1\n")
+	printf("\n")
+	
+	#output fixedimg table
+	coma=""
+	printf("#define ANIMS_FIXEDIMG {")
+	for (i=1;i<=totalfixedimg;i++) {
+		printf("%s\\\n\t{/*frame*/ %d,/*file*/ RES_FILE_%s, /*pal*/ %d, /*res*/ %d, /*layer*/ ANIMS_LAYERTYPE_%s, /*x,y*/ %d,%d}",coma,f["frame" i],f["file" i],f["pal" i],f["res" i],f["layer" i],f["x" i],f["y" i])
+		coma=","
+	}
+	printf("\\\n}\n\n")
+
+	#output state mark table
+	coma=""
+	printf("#define ANIMS_STATE {")
+	for (i=1;i<=totalstate;i++) {
+		printf("%s\\\n\t{/*frame*/ %d,/*file*/ RES_FILE_%s, /*state*/ STATE_MARKS_%s}",coma,t["frame" i],t["file" i],t["state" i])
+		coma=","
+	}
+	printf("\\\n}\n\n")
+	
+	#output sound table
+	coma=""
+	printf("#define ANIMS_SOUND {")
+	for (i=1;i<=totalsound;i++) {
+		printf("%s\\\n\t{/*frame*/ %d,/*file*/ RES_FILE_%s, /*type*/ anims_enum_%s}",coma,o["frame" i],o["file" i],o["type" i])
+		coma=","
+	}
+	printf("\\\n}\n\n")
+	
+	#the index table
+	coma=""
+	printf("#define ANIMS_TABLE {")
+	for (i=1;i<=animcount;i++) {
+		printf("%s\\\n\t{/*fixedimg*/ %d,%d, /*state*/ %d,%d, /*sound*/ %d,%d, /*animsize*/ %d}",coma,animation["startf" i],animation["sizef" i],animation["startt" i],animation["sizet" i],animation["starto" i],animation["sizeo" i],animation["size" i])
+		coma=","
+	}
+	printf("\\\n}\n\n")
+
+	#finally write the animation ids
+	for (i=1;i<=animcount;i++) {
+		printf("#define ANIMS_ID_%s %d\n",animation["name" i],i-1)
+	}
+}
+
diff --git a/FP/src/conf/awk/walls_conf.awk b/FP/src/conf/awk/walls_conf.awk
index 87fa189..b8c1685 100644
--- a/FP/src/conf/awk/walls_conf.awk
+++ b/FP/src/conf/awk/walls_conf.awk
@@ -1,4 +1,32 @@
-#!/usr/bin/awk
+#   Princed V3 - Prince of Persia Level Editor for PC Version
+#   Copyright (C) 2003 Princed Development Team
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+#   The authors of this program may be contacted at http://forum.princed.com.ar
+
+# walls_conf.awk: FreePrince : walls.conf parser
+# \xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
+# Copyright 2005 Princed Development Team
+#  Created: 1 Jan 2005
+#
+#  Author: Enrique Calot <ecalot.cod@princed.com.ar>
+#
+# Note:
+#  DO NOT remove this copyright notice
+#
 
 BEGIN {
 	env=-1
@@ -73,7 +101,7 @@ function additem(base) {
 }
 
 #parse items 
-/[[:space:]]*LINE[[:space:]]/ {
+/^[[:space:]]*LINE[[:space:]]/ {
 	if (currentenvironment && currenttable) {
 		for (i=2;i<=NF;i++) {
 			if ($i ~ /\*/) {
@@ -90,10 +118,12 @@ function additem(base) {
 	
 	} else {
 		#syntax error: items out of place
+		printf("Syntax error in line %d at walls.conf: LINE outside a table.\n",NR)>"/dev/stderr"
+		exit 40
 	}
 }
 
-/[[:space:]]*PLACE[[:space:]]/ {
+/^[[:space:]]*PLACE[[:space:]]/ {
 	if (currentenvironment && currenttable) {
 		maxtt=0
 		for (i=2;i<=NF;i++) {
@@ -104,13 +134,16 @@ function additem(base) {
 		total=maxtt
 	} else {
 		#syntax error: items out of place
+		printf("Syntax error in line %d at walls.conf: PLACE outside a table.\n",NR)>"/dev/stderr"
+		exit 41
 	}
 }
 
 
-#the end
-
-#calculate bits
+##########################
+# PART 2                 #
+# Calculate bits         #
+##########################
 
 func getbits(k) {
 	i=0
diff --git a/FP/src/include/.cvsignore b/FP/src/include/.cvsignore
index 899580d..3a64585 100644
--- a/FP/src/include/.cvsignore
+++ b/FP/src/include/.cvsignore
@@ -9,3 +9,4 @@ states_conf_flags.h
 tiles_conf_types.h
 tiles_conf_groups.h
 walls_conf.h
+anims_conf.h
diff --git a/FP/src/include/anims.h b/FP/src/include/anims.h
new file mode 100644
index 0000000..2d6562c
--- /dev/null
+++ b/FP/src/include/anims.h
@@ -0,0 +1,67 @@
+/*  Princed V3 - Prince of Persia Level Editor for PC Version
+    Copyright (C) 2003 Princed Development Team
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    The authors of this program may be contacted at http://forum.princed.com.ar
+*/
+
+/*
+anims.h: FreePrince : Animation functions
+\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
+ Copyright 2005 Princed Development Team
+  Created: 5 Jan 2005
+
+  Author: Enrique Calot <ecalot.cod@princed.com.ar>
+
+ Note:
+  DO NOT remove this copyright notice
+*/
+
+#ifndef _ANIMS_H_
+#define _ANIMS_H_
+
+#include "res_conf.h"    /* RES_FILE_*    */
+#include "states_conf.h" /* STATES_MARK_* */
+#include "anims_conf.h"
+
+/* table types */
+typedef struct {
+	unsigned short frame;
+	unsigned char file;
+	unsigned short pal;
+	unsigned short res;
+	unsigned char layer;
+	unsigned short x;
+	unsigned short y;
+} animFixedimg;
+
+typedef struct {
+	unsigned short frame;
+	unsigned char file;
+	unsigned short state;
+} animState;
+
+typedef struct {
+	unsigned short frame;
+	unsigned char file;
+	enum {anims_enum_midi,anims_enum_wav,anims_enum_speaker} type;
+} animSound;
+
+int animStart(int animId);
+int animGetFrame(int* qf,int* qt,int* qo, animFixedimg* f,animState* t, animSound* o);
+
+#endif
+
diff --git a/FP/src/res/anims.c b/FP/src/res/anims.c
new file mode 100644
index 0000000..30a181e
--- /dev/null
+++ b/FP/src/res/anims.c
@@ -0,0 +1,88 @@
+/*  Princed V3 - Prince of Persia Level Editor for PC Version
+    Copyright (C) 2003 Princed Development Team
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    The authors of this program may be contacted at http://forum.princed.com.ar
+*/
+
+/*
+anims.c: FreePrince : Animation handling library implementation
+\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
+ Copyright 2005 Princed Development Team
+  Created: 5 Jan 2005
+
+  Author: Enrique Calot <ecalot.cod@princed.com.ar>
+
+ Note:
+  DO NOT remove this copyright notice
+*/
+
+/* Read the static animation tables and return this information to
+ * the player module */
+
+#include "anims.h"
+
+/* private type: table of tables */
+typedef struct {
+	unsigned short fixedimgStart;
+	unsigned short fixedimgSize;
+	unsigned short stateStart;
+	unsigned short stateSize;
+	unsigned short soundStart;
+	unsigned short soundSize;
+	unsigned short animSize;
+} animTable;
+
+static animFixedimg fixedimg[]=ANIMS_FIXEDIMG;
+static animState state[]=ANIMS_STATE;
+static animSound sound[]=ANIMS_SOUND;
+static animTable table[]=ANIMS_TABLE;
+
+static animTable rec;
+static int frame;
+
+int animStart(int animId) {
+	rec=table[animId];
+	frame=0;
+	return rec.stateSize;
+}
+
+int animGetFrame(int* qf,int* qt,int* qo, animFixedimg* f,animState* t, animSound* o) {
+	*qf=0;
+	*qt=0;
+	*qo=0;
+	f=fixedimg+rec.fixedimgStart;
+	t=state+rec.stateStart;
+	o=sound+rec.soundStart;
+	while (rec.fixedimgSize&&fixedimg[rec.fixedimgStart].frame==frame) {
+		rec.fixedimgSize--;
+		rec.fixedimgStart++;
+		*qf++;
+	}
+	while (rec.stateSize&&state[rec.stateStart].frame==frame) {
+		rec.stateSize--;
+		rec.stateStart++;
+		*qf++;
+	}
+	while (rec.soundSize&&sound[rec.soundStart].frame==frame) {
+		rec.soundSize--;
+		rec.soundStart++;
+		*qf++;
+	}
+	frame++;
+	return frame!=rec.animSize;
+}
+