git » fp-git.git » commit 7b151b7

Abstracted menu in kernel

author ecalot
2004-07-18 18:57:24 UTC
committer ecalot
2004-07-18 18:57:24 UTC
parent 6889018a637a232f6610c96f94a3efe87c7fcff9

Abstracted menu in kernel

FP/src/Makefile +9 -1
FP/src/include/output.h +1 -1
FP/src/include/titles.h +44 -0
FP/src/ker/kernel.c +55 -20
FP/src/ker/titles.c +45 -0
FP/src/main.c +2 -2
FP/src/out/output.c +1 -0

diff --git a/FP/src/Makefile b/FP/src/Makefile
index 2a89335..774acc1 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
+                output.o maps.o config.o drawscreen.o titles.o
 EXEFILE       = bin/freeprince
 
 #Use this to temporary remove an option
@@ -114,6 +114,14 @@ kernel.o: ker/kernel.c include/kernel.h include/resources.h include/output.h
 	$(INFO) Compiling main kernel...
 	$(CC) -c ker/kernel.c $(OPTIONS)
 
+drawscreen.o: ker/drawscreen.c
+	$(INFO) Compiling screen draw module...
+	$(CC) -c ker/drawscreen.c $(OPTIONS)
+
+titles.o: ker/titles.c
+	$(INFO) Compiling titles module...
+	$(CC) -c ker/titles.c $(OPTIONS)
+
 compress.o: res/compress.c include/compress.h include/memory.h \
             include/disk.h
 	$(INFO) Compiling resource compression module...
diff --git a/FP/src/include/output.h b/FP/src/include/output.h
index 2b02691..d51fb9d 100644
--- a/FP/src/include/output.h
+++ b/FP/src/include/output.h
@@ -38,7 +38,7 @@ output.h: Free Prince : Output Devices Handler
 #ifndef _OUTPUT_H_
 #define _OUTPUT_H_
 
-#include <SDL/SDL.h>	/* SDL stuff */
+#include "resources.h"
 
 typedef struct tColor{
 	unsigned char r;
diff --git a/FP/src/include/titles.h b/FP/src/include/titles.h
new file mode 100644
index 0000000..e079f57
--- /dev/null
+++ b/FP/src/include/titles.h
@@ -0,0 +1,44 @@
+/*  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
+*/
+
+/*
+titles.h: FreePrince : Titles, animation and presentation
+\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
+ Copyright 2004 Princed Development Team
+  Created: 18 Jul 2004
+
+  Authores: Diego Essaya <dessaya.cod@princed.com.ar>
+	          Enrique Calot <ecalot.cod@princed.com.ar>
+
+ Note:
+  DO NOT remove this copyright notice
+*/
+
+#ifndef _TITLES_H_
+#define _TITLES_H_
+
+typedef enum {sQuit=0,sLoad=1,sStart}tMenuOption;
+
+tMenuOption showTitles();
+/* Show the titles animation
+ */
+
+#endif
+
diff --git a/FP/src/ker/kernel.c b/FP/src/ker/kernel.c
index ae1d7a3..2d738ca 100644
--- a/FP/src/ker/kernel.c
+++ b/FP/src/ker/kernel.c
@@ -36,26 +36,15 @@ kernel.c: FreePrince : Main Kernel
 #include "kernel.h"
 #include "resources.h"
 #include "output.h"
+#include "titles.h"
 
-int kernel(int optionflag,int level) {
-/* levels=-1 is default
- * levels from 0 to n is the level number
- *  
- * optionflag may be read using hasFlag(name_flag); Note that the variable
- * must be called optionflag
- */
-	
-	SDL_Event e;
+int control(int optionflag,int level) {
 	int i,location,direction,upIsPressed;
+	SDL_Event e;
 	tData* runningAnimation[4];
 	tData* animation;
 	tData* fondo;
-
-	if (outputInit()) {
-		fprintf(stderr, "Unable to initialize screen: %s\n", SDL_GetError());
-		exit(1);
-	}
-
+	
 	runningAnimation[0]=resLoad(RES_ANIM_RUN_LEFT);
 	runningAnimation[1]=resLoad(RES_ANIM_RUN_RIGHT);
 	runningAnimation[2]=resLoad(RES_ANIM_JUMPRUN_LEFT);
@@ -63,15 +52,15 @@ int kernel(int optionflag,int level) {
 	fondo=resLoad(RES_IMG_BACKGROUND);
 	if (!fondo) {
 		printf("The resource couldn't be loaded!\n");
-		exit(1);
+		return 1;
 	}
-/*
+	/*
 	printf("Resource number: %d. Frames: %d. Type: %d.\n",
 		RES_ANIM_RUN_LEFT,
 		runningAnimation->frames,
 		runningAnimation->type
 	);
-*/
+	*/
 	i=0;
 	location=160;
 	direction=0;
@@ -81,7 +70,7 @@ int kernel(int optionflag,int level) {
 		if (SDL_PollEvent(&e)) {
 			switch (e.type) {
 				case SDL_QUIT:
-					exit(1);
+					return 1;
 				case SDL_KEYDOWN:
 					/*fprintf(stderr, "The %s key was pressed! %d\n",
 					SDL_GetKeyName(e.key.keysym.sym),e.key.keysym.sym);*/
@@ -100,7 +89,7 @@ int kernel(int optionflag,int level) {
 							i=0;
 							break;
 						case SDLK_q:
-							exit(1);
+							return 1;
 							break;
 						default:
 							break;
@@ -132,10 +121,56 @@ int kernel(int optionflag,int level) {
 		if (i>animation->frames-1) i =6;
 	}
 
+	return 0;
+}
+
+/*
+ * Main function
+ */
+
+int kernel(int optionflag,int level) {
+/* levels=-1 is default
+ * levels from 0 to n is the level number
+ *  
+ * optionflag may be read using hasFlag(name_flag); Note that the variable
+ * must be called optionflag
+ */
+	
+	int menuOption;
+	int quit=0;
+	if (outputInit()) {
+		fprintf(stderr, "Unable to initialize screen: %s\n", SDL_GetError());
+		exit(1);
+	}
+
+	/*
+	 * Start main menu loop (story and titles)
+	 */
+	do {
+		if (level==-1) {
+			menuOption=showTitles();
+			switch (menuOption) {
+				case sLoad:
+					level=8; /* TODO: make read level function */
+					break;
+				case sStart:
+					level=1;
+					break;
+				case sQuit:
+					quit=1;
+					break;
+			}
+		}
+		if (!quit) {
+			quit=control(optionflag,level);
+		}
+	} while(!quit);
 	outputStop();
 	return 0;
 }
 
+
+
 #if 0
 #include <stdio.h>
 #include <SDL/SDL.h>
diff --git a/FP/src/ker/titles.c b/FP/src/ker/titles.c
new file mode 100644
index 0000000..a8782e4
--- /dev/null
+++ b/FP/src/ker/titles.c
@@ -0,0 +1,45 @@
+/*  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
+*/
+
+/*
+titles.c: FreePrince : Titles, animation and presentation
+\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf\xaf
+ Copyright 2004 Princed Development Team
+  Created: 18 Jul 2004
+
+  Authores: Diego Essaya <dessaya.cod@princed.com.ar>
+	          Enrique Calot <ecalot.cod@princed.com.ar>
+
+ Note:
+  DO NOT remove this copyright notice
+*/
+
+#include "output.h"
+#include "titles.h"
+
+tMenuOption showTitles() {
+/* Show the titles animation
+ * returns 0 if the user has finished the animations with quit
+ * returns 1 if the user has selected to load a saved game 
+ * returns 2 if the user has selected to start the game
+ */
+	return sStart;	
+}	
+
diff --git a/FP/src/main.c b/FP/src/main.c
index e7cf985..454fdd8 100644
--- a/FP/src/main.c
+++ b/FP/src/main.c
@@ -24,7 +24,7 @@ main.c: FreePrince : Main function - parsing
  Copyright 2004, 2003 Princed Development Team
   Created: 24 Mar 2004
 
-  Author: Endfhgfhgfhg <efghgfdht.cod@princed.com.ar>
+  Author: Enrique Calot <ecalot.cod@princed.com.ar>
 
  Note:
   DO NOT remove this copyright notice
@@ -76,7 +76,7 @@ int main (int argc, char **argv) {
 		}
 	} while (c!=-1);
 
-
+	/* TODO: traditional parsing: megahit (level) */
 	/* Check syntax, help and version screens */
 	
 	if (hasFlag(help_flag)) {
diff --git a/FP/src/out/output.c b/FP/src/out/output.c
index 350dd16..bf3cfc1 100644
--- a/FP/src/out/output.c
+++ b/FP/src/out/output.c
@@ -35,6 +35,7 @@ output.c: Free Prince : Output Devices Handler
   DO NOT remove this copyright notice
 */
 
+#include <SDL/SDL.h>
 #include <stdlib.h>    /* malloc */
 #include "resources.h" /* tMemory structure */
 #include "output.h"