| author | ecalot
<ecalot> 2004-07-21 23:23:09 UTC |
| committer | ecalot
<ecalot> 2004-07-21 23:23:09 UTC |
| parent | 09ae7da72c21b42cc8cc773411b62ad7c51cc48e |
| FP/src/include/input.h | +22 | -4 |
| FP/src/include/titles.h | +1 | -1 |
| FP/src/ker/kernel.c | +1 | -1 |
| FP/src/ker/titles.c | +58 | -11 |
| FP/src/out/input.c | +76 | -34 |
diff --git a/FP/src/include/input.h b/FP/src/include/input.h index 4bc0f6c..ec51435 100644 --- a/FP/src/include/input.h +++ b/FP/src/include/input.h @@ -33,25 +33,43 @@ input.h: Free Prince : Input devices handling #ifndef _INPUT_H_ #define _INPUT_H_ -typedef enum {none=0,quit,reload,passLevel,showUp,showLeft,showRight,showDown,moreTime,lessTime,addLive,addHitPoint,gotoTitles,kill,resurrect}tAction; +typedef enum {none=0,quit,load,reload,passLevel,showUp,showLeft,showRight,showDown,moreTime,lessTime,addLive,addHitPoint,gotoTitles,kill,resurrect,other}tAction; +/*#define inputIgnoreCtrl(a) (a&( ~(1<<1) ))*/ +/* TODO: use inputIgnore* for each Set* */ +#define inputSetShift(a,b) a=(a&( ~(1<<0) )) | ((b)<<0) +#define inputSetCtrl(a,b) a=(a&( ~(1<<1) )) | ((b)<<1) +#define inputSetUp(a,b) a=(a&( ~(1<<2) )) | ((b)<<2) +#define inputSetDown(a,b) a=(a&( ~(1<<3) )) | ((b)<<3) +#define inputSetLeft(a,b) a=(a&( ~(1<<4) )) | ((b)<<4) +#define inputSetRight(a,b) a=(a&( ~(1<<5) )) | ((b)<<5) + + +#define inputGetShift(a) ((a)&( (1<<0) )) +#define inputGetCtrl(a) ((a)&( (1<<1) )) +#define inputGetUp(a) ((a)&( (1<<2) )) +#define inputGetDown(a) ((a)&( (1<<3) )) +#define inputGetLeft(a) ((a)&( (1<<4) )) +#define inputGetRight(a) ((a)&( (1<<5) )) typedef struct { - int shiftPressed; +/* int shiftPressed; int controlPressed; int upPressed; int leftPressed; int rightPressed; - int downPressed; + int downPressed;*/ + unsigned char status; tAction actionPerformed; } tKey; -void inputInitKey(tKey* key); +tKey inputCreateKey(); int inputGetEvent(tKey* key); /* Saves the key status un key (either from the keyboard or joystick or whatever) * returns 1 if a time event is activated or 0 if an action was performed */ +int inputDelay(tKey* key,int ticks); void inputStopTimer(); void inputInitTimer(); diff --git a/FP/src/include/titles.h b/FP/src/include/titles.h index e079f57..7547387 100644 --- a/FP/src/include/titles.h +++ b/FP/src/include/titles.h @@ -34,7 +34,7 @@ titles.h: FreePrince : Titles, animation and presentation #ifndef _TITLES_H_ #define _TITLES_H_ -typedef enum {sQuit=0,sLoad=1,sStart}tMenuOption; +typedef enum {sQuit=0,sLoad=1,sStart,sNone}tMenuOption; tMenuOption showTitles(); /* Show the titles animation diff --git a/FP/src/ker/kernel.c b/FP/src/ker/kernel.c index de5cd02..a1a5e8f 100644 --- a/FP/src/ker/kernel.c +++ b/FP/src/ker/kernel.c @@ -118,7 +118,7 @@ int control(int optionflag,int level) { } else { location-=3; } - printf("up=%d\n",upIsPressed); + /*printf("up=%d\n",upIsPressed);*/ if (i>animation->frames-1) i =6; } diff --git a/FP/src/ker/titles.c b/FP/src/ker/titles.c index bed7c3d..a0fa51f 100644 --- a/FP/src/ker/titles.c +++ b/FP/src/ker/titles.c @@ -33,7 +33,37 @@ titles.c: FreePrince : Titles, animation and presentation #include "output.h" #include "titles.h" -#include <SDL/SDL.h> +#include "input.h" +#include <stdio.h> /* debug printf */ + +tMenuOption getAction(tKey key) { + switch(key.actionPerformed) { + case quit: + return sQuit; + case load: + return sLoad; + default: + return sStart; + } +} + +tMenuOption sleep(int ticks) { + /* Wait ticks or a key is pressed if an action is thrown process it */ + tKey key=inputCreateKey(); + while (ticks) { + ticks=inputDelay(&key,ticks); + if ( + /* there are ticks remaining (a non-temporal action was thrown) */ + ticks && + /* there is an action */ + key.actionPerformed!=none && + /* the action wasn't control key */ + !(inputGetCtrl(key.status) && key.actionPerformed==other) + ) + return getAction(key); /* return the results of this action */ + } + return sNone; +} tMenuOption showTitles() { /* Show the titles animation @@ -43,47 +73,64 @@ tMenuOption showTitles() { */ tData *main_title; - tData *main_text; - + /*tData *main_text;*/ + tMenuOption result; + main_title = resLoad(RES_IMG_MAIN_BACKGROUND); if (! main_title) { printf("The resource couldn't be loaded!\n"); return 1; } outputClearScreen(); + inputInitTimer(); /* The main background */ outputDrawBitmap(main_title->pFrames[0], 0, 0); outputUpdateScreen(); - SDL_Delay(1000); + result=sleep(12); + if (result!=sNone) return result; /* The presents */ outputDrawBitmap(main_title->pFrames[1], 100, 100); outputUpdateScreen(); - SDL_Delay(1050); + result=sleep(12); + if (result!=sNone) return result; /* The author*/ outputClearScreen(); outputDrawBitmap(main_title->pFrames[0], 0, 0); outputDrawBitmap(main_title->pFrames[2], 100, 100); outputUpdateScreen(); - SDL_Delay(1050); + result=sleep(12); + if (result!=sNone) return result; /* The game name*/ outputClearScreen(); outputDrawBitmap(main_title->pFrames[0], 0, 0); outputDrawBitmap(main_title->pFrames[3], 30, 70); outputDrawBitmap(main_title->pFrames[4], 30, 190); outputUpdateScreen(); - SDL_Delay(1050); + /*SDL_Delay(1050);*/ + result=sleep(12); + if (result!=sNone) return result; + /* + * The outputDraw doesn't support the text files yet + * main_text = resLoad(RES_IMG_TEXT_BACKGROUND); if (! main_text) { printf("The resource couldn't be loaded!\n"); - return 1; + exit(1); } + */ /* The presents */ + /* outputDrawBitmap(main_text->pFrames[0], 0, 0); outputDrawBitmap(main_text->pFrames[1], 0, 0); outputUpdateScreen(); - SDL_Delay(1050); - getchar(); - return sStart; + */ + while (1) { + result=sleep(1000); + if (result!=sNone) return result; + } + /*inputStopTimer(); + return sStart; + */ } diff --git a/FP/src/out/input.c b/FP/src/out/input.c index 1a80bcc..b3d8d70 100644 --- a/FP/src/out/input.c +++ b/FP/src/out/input.c @@ -35,66 +35,94 @@ input.c: FreePrince : Input interface #include "input.h" #include <stdio.h> /* only for the printf debug */ -void inputInitKey(tKey* key) { - key->shiftPressed=0; - key->controlPressed=0; - key->upPressed=0; - key->leftPressed=0; - key->rightPressed=0; - key->actionPerformed=none; +tKey inputCreateKey() { + tKey key; +/* inputSetshift(key->status,0); + inputSetcontrol(key->status,0); + inputSetup(key->status,0); + inputSetleft(key->status,0); + inputSetright(key->status,0);*/ + key.status=0; + key.actionPerformed=none; + return key; } -void editKey(tKey* key,SDLKey sdlkey,int status) { +int editAction(tKey* key,SDLKey k) { + key->actionPerformed=other; + /* Control actions */ + if (inputGetCtrl(key->status)) { + switch (k) { + case SDLK_l: + key->actionPerformed=load; + break; + case SDLK_q: + key->actionPerformed=quit; + break; + default: + break; + } + } + /* Shift actions */ + if (inputGetShift(key->status)) { + } + /* Normal actions */ + if (!(key->status)) { + } + return key->actionPerformed; +} + +int editKey(tKey* key, SDLKey sdlkey, int status) { switch (sdlkey) { /* keys */ case SDLK_UP: - key->upPressed=status; - key->downPressed=!status; + inputSetUp(key->status,status); + inputSetDown(key->status,0); break; case SDLK_DOWN: - key->downPressed=status; - key->upPressed=!status; + inputSetDown(key->status,status); + inputSetUp(key->status,0); break; case SDLK_RIGHT: - key->rightPressed=status; - key->leftPressed=!status; + inputSetRight(key->status,status); + inputSetLeft(key->status,0); break; case SDLK_LEFT: - key->leftPressed=status; - key->rightPressed=!status; + inputSetLeft(key->status,status); + inputSetRight(key->status,0); break; case SDLK_HOME: - key->upPressed=status; - key->leftPressed=status; - key->rightPressed=!status; + inputSetUp(key->status,status); + inputSetLeft(key->status,status); + inputSetRight(key->status,0); break; case SDLK_END: - key->downPressed=status; - key->leftPressed=status; - key->rightPressed=!status; + inputSetDown(key->status,status); + inputSetLeft(key->status,status); + inputSetRight(key->status,0); break; case SDLK_PAGEUP: - key->upPressed=status; - key->leftPressed=!status; - key->rightPressed=status; + inputSetUp(key->status,status); + inputSetLeft(key->status,0); + inputSetRight(key->status,status); break; case SDLK_PAGEDOWN: - key->downPressed=status; - key->leftPressed=!status; - key->rightPressed=status; + inputSetDown(key->status,status); + inputSetLeft(key->status,0); + inputSetRight(key->status,status); break; /* mods*/ case SDLK_RSHIFT: case SDLK_LSHIFT: - key->shiftPressed=status; + inputSetShift(key->status,status); break; case SDLK_RCTRL: case SDLK_LCTRL: - key->controlPressed=status; + inputSetCtrl(key->status,status); break; default: - break; - } + return 0; + } + return 1; } int inputGetEvent(tKey* key) { @@ -102,11 +130,15 @@ int inputGetEvent(tKey* key) { while(SDL_WaitEvent(&event)) { + printf("Event dropped: key status=%x action=%d\n",key->status,key->actionPerformed); + key->actionPerformed=none; switch (event.type) { case SDL_KEYDOWN: - /* if (editAction(key,event.key.keysym.sym)) return 0; */ + editKey(key,event.key.keysym.sym,1); + if (editAction(key,event.key.keysym.sym)) return 0; + break; case SDL_KEYUP: - editKey(key,event.key.keysym.sym,event.type==SDL_KEYDOWN); + editKey(key,event.key.keysym.sym,0); break; case SDL_USEREVENT: return 1; /* A new time cicle has started! */ @@ -144,3 +176,13 @@ void inputStopTimer() { SDL_RemoveTimer(timer); } + + +int inputDelay(tKey* key,int ticks) { + while(ticks&&inputGetEvent(key)) { + ticks--; + } + return ticks; +} + +