author | ecalot
<ecalot> 2005-01-25 03:51:54 UTC |
committer | ecalot
<ecalot> 2005-01-25 03:51:54 UTC |
parent | 38d6355a4d781e17ce8d37e45add572dc74dd4cb |
FP/src/include/kernel.h | +1 | -1 |
FP/src/include/output.h | +9 | -1 |
FP/src/ker/kernel.c | +3 | -3 |
FP/src/out/output.c | +34 | -27 |
stuff/modtools/font/test.c | +1 | -1 |
diff --git a/FP/src/include/kernel.h b/FP/src/include/kernel.h index ce464db..abb2968 100644 --- a/FP/src/include/kernel.h +++ b/FP/src/include/kernel.h @@ -43,7 +43,7 @@ kernel.h: Princed Resources : Resource Handler headers #define hasFlag(a) (optionflag&(a)) #define setFlag(a) optionflag|=(a) -#define FP_VERSION "0.3-pre-alpha-win-brendon" +#define FP_VERSION "0.3-pre-alpha-ushuaia" int kernel(int optionflag,int level); /* level=-1 is default diff --git a/FP/src/include/output.h b/FP/src/include/output.h index 73c9329..fb28fc1 100644 --- a/FP/src/include/output.h +++ b/FP/src/include/output.h @@ -53,8 +53,16 @@ typedef struct tPalette{ /* Text Primitives*/ void outputDrawText(int x, int y, const char *fmt, ...); -void outputDrawMessage(const char* fmt, ...); +void outputDrawMessage(int frames, const char* fmt, ...); +/* This function will print in the default message space + * the given message. + * This message will be displayed a specified number of updates. + * if frames is 5, then the message will last for 5 outputUpdates() + * if frames is 0 (infinity), the the message will be displayed + * until outputClearLastMessage() is called. + */ + /* Sound */ void outputPlayWav(tMemory sound); /* Starts the reproduction of the sample and returns */ void outputPlayMid(tMemory music); /* Starts the music reproduction and returns */ diff --git a/FP/src/ker/kernel.c b/FP/src/ker/kernel.c index ee655c2..db97c0b 100644 --- a/FP/src/ker/kernel.c +++ b/FP/src/ker/kernel.c @@ -122,10 +122,10 @@ int playgame(int optionflag,int level) { printf("Kernel/playgame: cheat: Pass to level %d\n",level); break; case showVersion: - outputDrawMessage("FreePrince v"FP_VERSION"\n"); + outputDrawMessage(24,"FreePrince v"FP_VERSION"\n"); break; case showScreens: - outputDrawMessage("S%d L%d R%d A%d B%d\n", + outputDrawMessage(24,"S%d L%d R%d A%d B%d\n", room.id, room.links[eLeft], room.links[eRight], @@ -134,7 +134,7 @@ int playgame(int optionflag,int level) { ); break; case showMoreScreens: - outputDrawMessage("S%d AL%d AR%d BL%d BR%d\n", + outputDrawMessage(24,"S%d AL%d AR%d BL%d BR%d\n", room.id, room.corners[0], room.corners[1], diff --git a/FP/src/out/output.c b/FP/src/out/output.c index bd819a6..da667bb 100644 --- a/FP/src/out/output.c +++ b/FP/src/out/output.c @@ -50,6 +50,8 @@ output.c: Free Prince : Output Devices Handler /* Main screen object */ SDL_Surface *screen; +/* Text functions */ + #define CHAR_SIZE 12 typedef struct _valid_chars { @@ -120,12 +122,25 @@ unsigned int outputGetTextHeight (const char *txt) return font->h; } -#define OUTPUT_TEXT_CENTERED_X -1 +static char messageBuffer[512]=""; +static unsigned int messageFrames=0; + +/* If vsnprintf is allowed in the standard use it */ +#if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98 +/* ISO/IEC 9899:1999 */ +#define fillBuffer(buffer,fmt,ap) va_start (ap, fmt);\ + vsnprintf (buffer, sizeof(buffer), fmt, ap);\ + va_end (ap) +#else +/* ANSI X3.159-1989 (`ANSI C') and ISO/IEC 9899:1999 (`ISO C99') */ +#define fillBuffer(buffer,fmt,ap) va_start (ap, fmt);\ + vsprintf (buffer, fmt, ap);\ + va_end (ap) +#endif /* Text Primitives*/ -void outputvDrawText(int x, int y, const char *fmt, va_list ap) +void outputsDrawText(int x, int y, const char *buffer) { - char buffer[1024]; unsigned char *s; SDL_Rect from, to; int current_x; @@ -135,24 +150,8 @@ void outputvDrawText(int x, int y, const char *fmt, va_list ap) return; } - if (fmt == NULL) return; - memset (buffer, 0, sizeof(buffer)); - - /* If vsnprintf is allowed in the standard use it */ -#if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98 - /* ISO/IEC 9899:1999 */ - vsnprintf (buffer, sizeof(buffer), fmt, ap); -#else - /* ANSI X3.159-1989 (`ANSI C') and ISO/IEC 9899:1999 (`ISO C99') */ - vsprintf (buffer, fmt, ap); -#endif - s = (unsigned char*)buffer; - if (x==OUTPUT_TEXT_CENTERED_X) { - current_x = (DEF_SCREEN_WIDTH-outputGetTextWidth(buffer))/2; - } else { - current_x = x; - } + current_x = x; while ((*s) != '\0') { if (valid_chars[*s].is_valid) { from.x = valid_chars[*s].x; @@ -175,23 +174,26 @@ void outputvDrawText(int x, int y, const char *fmt, va_list ap) void outputDrawText(int x, int y, const char *fmt, ...) { va_list ap; - va_start (ap, fmt); - outputvDrawText(x,y,fmt,ap); - va_end (ap); + char buffer[512]; + fillBuffer(buffer,fmt,ap); + outputsDrawText(x,y,buffer); } -void outputDrawMessage(const char* fmt, ...) +void outputDrawMessage(int frames, const char* fmt, ...) { va_list ap; - va_start (ap, fmt); - outputvDrawText(OUTPUT_TEXT_CENTERED_X,DEF_SCREEN_HEIGHT-CHAR_SIZE,fmt,ap); - va_end (ap); + fillBuffer(messageBuffer,fmt,ap); + if (frames) frames++; /* if not infinite, increase by one */ + messageFrames=frames; } void outputClearLastMessage() { + messageBuffer[0]=0; } +/* End of text functions */ + /* Sound */ void outputPlayWav(tMemory sound) {} /* Starts the reproduction of the sample and returns */ void outputPlayMid(tMemory music) {} /* Starts the music reproduction and returns */ @@ -336,6 +338,11 @@ void outputClearScreen() void outputUpdateScreen() { + /* check out for messages */ + if (messageFrames==1) outputClearLastMessage(); + if (messageFrames) messageFrames--; + outputsDrawText((DEF_SCREEN_WIDTH-outputGetTextWidth(messageBuffer))/2,DEF_SCREEN_HEIGHT-CHAR_SIZE,messageBuffer); + SDL_Flip(screen); } diff --git a/stuff/modtools/font/test.c b/stuff/modtools/font/test.c index 39d7d84..f1a5670 100644 --- a/stuff/modtools/font/test.c +++ b/stuff/modtools/font/test.c @@ -14,7 +14,7 @@ int main (int argc, char *argv[]) outputDrawText (55, 20, "ABCD 123456 &/$# 000", 26); - outputDrawMessage ("hola, que %s.", "tal"); + outputDrawMessage (36,"hola, que %s.", "tal"); outputUpdateScreen();