From d77e08306fcaa9943e282b4043b9ff21f947a0f2 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Fri, 6 Jun 2003 19:04:27 +0000 Subject: [PATCH] merge (non-physfs stuff) from physfs branch --- ChangeLog | 35 +++ arch/sdl/event.c | 9 +- console/.cvsignore | 3 + console/CON_console.c | 629 ++++++++++++++++++++++-------------------- console/DT_drawtext.c | 215 --------------- console/Makefile.am | 4 +- console/internal.c | 75 ----- console/internal.h | 13 - include/CON_console.h | 43 +-- include/console.h | 3 +- include/gr.h | 3 +- main/console.c | 79 ++++-- main/credits.c | 3 +- main/game.c | 5 +- main/gamecntl.c | 12 +- main/gamerend.c | 8 +- main/gauges.c | 18 +- main/hud.c | 29 +- main/kconfig.c | 6 +- main/newmenu.c | 12 +- main/playsave.c | 7 +- 21 files changed, 533 insertions(+), 678 deletions(-) create mode 100644 console/.cvsignore delete mode 100644 console/DT_drawtext.c delete mode 100644 console/internal.c delete mode 100644 console/internal.h diff --git a/ChangeLog b/ChangeLog index 9b203ddc..a59927f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +2003-06-06 Bradley Bell + + * console/.cvsignore: added .cvsignore + + * main/gauges.c: force cockpit redraw in opengl + + * main/gamerend.c: move ogl swap, so cockpit and console get + rendered properly + + * main/console.c: can't write to console after it's closed + +2003-06-05 Bradley Bell + + * arch/sdl/event.c, console/CON_console.c, console/Makefile.am, + console/internal.c, console/internal.h, include/CON_console.h, + include/console.h, main/console.c, main/gamecntl.c, main/hud.c: + finish console conversion away from SDL + +2003-06-04 Bradley Bell + + * console/CON_console.c, include/CON.console.h, include/console.h, + main/console.c, main/game.c: console conversion to native gr, + console resizing + + * include/gr.h, main/credits.c, main/kconfig.c, main/newmenu.c: + put prototype for gr_bm_bitblt in gr.h + +2003-06-03 Bradley Bell + + * console/CON_console.c, console/DT_drawtext.c, + console/Makefile.am, include/CON_console.h, include/DT_drawtext.h, + main/console.c: use native fonts for console + + * main/playsave.c: use shorts for short data + 2003-06-02 Bradley Bell * configure.ac, main/console.c: set console background, fix diff --git a/arch/sdl/event.c b/arch/sdl/event.c index 13a06ecb..1c14c4f4 100644 --- a/arch/sdl/event.c +++ b/arch/sdl/event.c @@ -1,4 +1,4 @@ -/* $Id: event.c,v 1.11 2003-06-02 05:56:37 btb Exp $ */ +/* $Id: event.c,v 1.12 2003-06-06 19:04:27 btb Exp $ */ /* * * SDL Event related stuff @@ -14,9 +14,6 @@ #include #include -#ifdef CONSOLE -#include "CON_console.h" -#endif extern void key_handler(SDL_KeyboardEvent *event); extern void mouse_button_handler(SDL_MouseButtonEvent *mbe); @@ -34,10 +31,6 @@ void event_poll() SDL_Event event; while (SDL_PollEvent(&event)) { -#ifdef CONSOLE - if(!CON_Events(&event)) - continue; -#endif switch(event.type) { case SDL_KEYDOWN: case SDL_KEYUP: diff --git a/console/.cvsignore b/console/.cvsignore new file mode 100644 index 00000000..e9955884 --- /dev/null +++ b/console/.cvsignore @@ -0,0 +1,3 @@ +.deps +Makefile +Makefile.in diff --git a/console/CON_console.c b/console/CON_console.c index 19613f90..9a5ac426 100644 --- a/console/CON_console.c +++ b/console/CON_console.c @@ -1,20 +1,30 @@ /* CON_console.c * Written By: Garrett Banuk * Code Cleanup and heavily extended by: Clemens Wacha + * Ported to use native Descent interfaces by: Bradley Bell * * This is free, just be sure to give us credit when using it * in any of your programs. */ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include #include -#include "SDL.h" -#include "SDL_image.h" + #include "CON_console.h" -#include "DT_drawtext.h" -#include "internal.h" + +#include "u_mem.h" +#include "gr.h" +#include "timer.h" + + +#define FG_COLOR grd_curcanv->cv_font_fg_color +#define get_msecs() approx_fsec_to_msec(timer_get_approx_seconds()) /* This contains a pointer to the "topmost" console. The console that @@ -24,131 +34,143 @@ static ConsoleInformation *Topmost; /* Takes keys from the keyboard and inputs them to the console If the event was not handled (i.e. WM events or unknown ctrl-shift sequences) the function returns the event for further processing. */ -SDL_Event* CON_Events(SDL_Event *event) { +int CON_Events(int event) +{ if(Topmost == NULL) return event; if(!CON_isVisible(Topmost)) return event; - if(event->type == SDL_KEYDOWN) { - if(event->key.keysym.mod & KMOD_CTRL) { - //CTRL pressed - switch(event->key.keysym.sym) { - case SDLK_a: - Cursor_Home(Topmost); - break; - case SDLK_e: - Cursor_End(Topmost); - break; - case SDLK_c: - Clear_Command(Topmost); - break; - case SDLK_l: - Clear_History(Topmost); + if(event & KEY_CTRLED) + { + //CTRL pressed + switch(event & ~KEY_CTRLED) + { + case KEY_A: + Cursor_Home(Topmost); + break; + case KEY_E: + Cursor_End(Topmost); + break; + case KEY_C: + Clear_Command(Topmost); + break; + case KEY_L: + Clear_History(Topmost); + CON_UpdateConsole(Topmost); + break; + default: + return event; + } + } + else if(event & KEY_ALTED) + { + //the console does not handle ALT combinations! + return event; + } + else + { + //first of all, check if the console hide key was pressed + if(event == Topmost->HideKey) + { + CON_Hide(Topmost); + return 0; + } + switch (event & 0xff) + { + case KEY_LSHIFT: + case KEY_RSHIFT: + return event; + case KEY_HOME: + if(event & KEY_SHIFTED) + { + Topmost->ConsoleScrollBack = Topmost->LineBuffer-1; CON_UpdateConsole(Topmost); - break; - default: - return event; + } else { + Cursor_Home(Topmost); } - } else if(event->key.keysym.mod & KMOD_ALT) { - //the console does not handle ALT combinations! - return event; - } else { - //first of all, check if the console hide key was pressed - if(event->key.keysym.sym == Topmost->HideKey) { - CON_Hide(Topmost); - return NULL; + break; + case KEY_END: + if(event & KEY_SHIFTED) + { + Topmost->ConsoleScrollBack = 0; + CON_UpdateConsole(Topmost); + } else { + Cursor_End(Topmost); } - switch (event->key.keysym.sym) { - case SDLK_HOME: - if(event->key.keysym.mod & KMOD_SHIFT) { - Topmost->ConsoleScrollBack = Topmost->LineBuffer-1; - CON_UpdateConsole(Topmost); - } else { - Cursor_Home(Topmost); - } - break; - case SDLK_END: - if(event->key.keysym.mod & KMOD_SHIFT) { - Topmost->ConsoleScrollBack = 0; - CON_UpdateConsole(Topmost); - } else { - Cursor_End(Topmost); - } - break; - case SDLK_PAGEUP: - Topmost->ConsoleScrollBack += CON_LINE_SCROLL; - if(Topmost->ConsoleScrollBack > Topmost->LineBuffer-1) - Topmost->ConsoleScrollBack = Topmost->LineBuffer-1; + break; + case KEY_PAGEUP: + Topmost->ConsoleScrollBack += CON_LINE_SCROLL; + if(Topmost->ConsoleScrollBack > Topmost->LineBuffer-1) + Topmost->ConsoleScrollBack = Topmost->LineBuffer-1; + CON_UpdateConsole(Topmost); + break; + case KEY_PAGEDOWN: + Topmost->ConsoleScrollBack -= CON_LINE_SCROLL; + if(Topmost->ConsoleScrollBack < 0) + Topmost->ConsoleScrollBack = 0; + CON_UpdateConsole(Topmost); + break; + case KEY_UP: + Command_Up(Topmost); + break; + case KEY_DOWN: + Command_Down(Topmost); + break; + case KEY_LEFT: + Cursor_Left(Topmost); + break; + case KEY_RIGHT: + Cursor_Right(Topmost); + break; + case KEY_BACKSP: + Cursor_BSpace(Topmost); + break; + case KEY_DELETE: + Cursor_Del(Topmost); + break; + case KEY_INSERT: + Topmost->InsMode = 1-Topmost->InsMode; + break; + case KEY_TAB: + CON_TabCompletion(Topmost); + break; + case KEY_ENTER: + if(strlen(Topmost->Command) > 0) { + CON_NewLineCommand(Topmost); + + // copy the input into the past commands strings + strcpy(Topmost->CommandLines[0], Topmost->Command); + + // display the command including the prompt + CON_Out(Topmost, "%s%s", Topmost->Prompt, Topmost->Command); CON_UpdateConsole(Topmost); - break; - case SDLK_PAGEDOWN: - Topmost->ConsoleScrollBack -= CON_LINE_SCROLL; - if(Topmost->ConsoleScrollBack < 0) - Topmost->ConsoleScrollBack = 0; - CON_UpdateConsole(Topmost); - break; - case SDLK_UP: - Command_Up(Topmost); - break; - case SDLK_DOWN: - Command_Down(Topmost); - break; - case SDLK_LEFT: - Cursor_Left(Topmost); - break; - case SDLK_RIGHT: - Cursor_Right(Topmost); - break; - case SDLK_BACKSPACE: - Cursor_BSpace(Topmost); - break; - case SDLK_DELETE: + + CON_Execute(Topmost, Topmost->Command); + //printf("Command: %s\n", Topmost->Command); + + Clear_Command(Topmost); + Topmost->CommandScrollBack = -1; + } + break; + case KEY_ESC: + //deactivate Console + CON_Hide(Topmost); + return 0; + default: + if(Topmost->InsMode) + Cursor_Add(Topmost, event); + else { + Cursor_Add(Topmost, event); Cursor_Del(Topmost); - break; - case SDLK_INSERT: - Topmost->InsMode = 1-Topmost->InsMode; - break; - case SDLK_TAB: - CON_TabCompletion(Topmost); - break; - case SDLK_RETURN: - if(strlen(Topmost->Command) > 0) { - CON_NewLineCommand(Topmost); - - // copy the input into the past commands strings - strcpy(Topmost->CommandLines[0], Topmost->Command); - - // display the command including the prompt - CON_Out(Topmost, "%s%s", Topmost->Prompt, Topmost->Command); - CON_UpdateConsole(Topmost); - - CON_Execute(Topmost, Topmost->Command); - //printf("Command: %s\n", Topmost->Command); - - Clear_Command(Topmost); - Topmost->CommandScrollBack = -1; - } - break; - case SDLK_ESCAPE: - //deactivate Console - CON_Hide(Topmost); - return NULL; - default: - if(Topmost->InsMode) - Cursor_Add(Topmost, event); - else { - Cursor_Add(Topmost, event); - Cursor_Del(Topmost); - } } } - return NULL; } - return event; + return 0; } +#if 0 /* CON_AlphaGL() -- sets the alpha channel of an SDL_Surface to the * specified value. Preconditions: the surface in question is RGBA. * 0 <= a <= 255, where 0 is transparent and 255 is opaque. */ @@ -230,6 +252,7 @@ void CON_AlphaGL(SDL_Surface *s, int alpha) { break; } } +#endif /* Updates the console buffer */ @@ -237,8 +260,8 @@ void CON_UpdateConsole(ConsoleInformation *console) { int loop; int loop2; int Screenlines; - SDL_Rect DestRect; - BitFont *CurrentFont = DT_FontPointer(console->FontNumber); + grs_canvas *canv_save; + short orig_color; if(!console) return; @@ -247,44 +270,60 @@ void CON_UpdateConsole(ConsoleInformation *console) { if(!CON_isVisible(console)) return; - Screenlines = console->ConsoleSurface->h / console->FontHeight; + Screenlines = console->ConsoleSurface->cv_h / (CON_LINE_SPACE + console->ConsoleSurface->cv_font->ft_h); + canv_save = grd_curcanv; + gr_set_current_canvas(console->ConsoleSurface); +#if 0 SDL_FillRect(console->ConsoleSurface, NULL, SDL_MapRGBA(console->ConsoleSurface->format, 0, 0, 0, console->ConsoleAlpha)); +#else + //gr_rect(0,0, +#endif +#if 0 if(console->OutputScreen->flags & SDL_OPENGLBLIT) SDL_SetAlpha(console->ConsoleSurface, 0, SDL_ALPHA_OPAQUE); +#endif /* draw the background image if there is one */ - if(console->BackgroundImage) { - DestRect.x = console->BackX; - DestRect.y = console->BackY; - DestRect.w = console->BackgroundImage->w; - DestRect.h = console->BackgroundImage->h; - SDL_BlitSurface(console->BackgroundImage, NULL, console->ConsoleSurface, &DestRect); - } + if(console->BackgroundImage) + gr_bitmap(0, 0, console->BackgroundImage); /* Draw the text from the back buffers, calculate in the scrollback from the user * this is a normal SDL software-mode blit, so we need to temporarily set the ColorKey * for the font, and then clear it when we're done. */ +#if 0 if((console->OutputScreen->flags & SDL_OPENGLBLIT) && (console->OutputScreen->format->BytesPerPixel > 2)) { Uint32 *pix = (Uint32 *) (CurrentFont->FontSurface->pixels); SDL_SetColorKey(CurrentFont->FontSurface, SDL_SRCCOLORKEY, *pix); } - +#endif //now draw text from last but second line to top for(loop = 0; loop < Screenlines-1 && loop < console->LineBuffer - console->ConsoleScrollBack; loop++) { if(console->ConsoleScrollBack != 0 && loop == 0) for(loop2 = 0; loop2 < (console->VChars / 5) + 1; loop2++) - DT_DrawText(CON_SCROLL_INDICATOR, console->ConsoleSurface, console->FontNumber, CON_CHAR_BORDER + (loop2*5*console->FontWidth), (Screenlines - loop - 2) * console->FontHeight); + { + orig_color = FG_COLOR; + gr_string(CON_CHAR_BORDER + (loop2*5*console->ConsoleSurface->cv_font->ft_w), (Screenlines - loop - 2) * (CON_LINE_SPACE + console->ConsoleSurface->cv_font->ft_h), CON_SCROLL_INDICATOR); + FG_COLOR = orig_color; + } else - DT_DrawText(console->ConsoleLines[console->ConsoleScrollBack + loop], console->ConsoleSurface, console->FontNumber, CON_CHAR_BORDER, (Screenlines - loop - 2) * console->FontHeight); + { + orig_color = FG_COLOR; + gr_string(CON_CHAR_BORDER, (Screenlines - loop - 2) * (CON_LINE_SPACE + console->ConsoleSurface->cv_font->ft_h), console->ConsoleLines[console->ConsoleScrollBack + loop]); + FG_COLOR = orig_color; + } } + gr_set_current_canvas(canv_save); + +#if 0 if(console->OutputScreen->flags & SDL_OPENGLBLIT) SDL_SetColorKey(CurrentFont->FontSurface, 0, 0); +#endif } void CON_UpdateOffset(ConsoleInformation* console) { @@ -301,8 +340,8 @@ void CON_UpdateOffset(ConsoleInformation* console) { break; case CON_OPENING: console->RaiseOffset += CON_OPENCLOSE_SPEED; - if(console->RaiseOffset >= console->ConsoleSurface->h) { - console->RaiseOffset = console->ConsoleSurface->h; + if(console->RaiseOffset >= console->ConsoleSurface->cv_h) { + console->RaiseOffset = console->ConsoleSurface->cv_h; console->Visible = CON_OPEN; } break; @@ -314,8 +353,8 @@ void CON_UpdateOffset(ConsoleInformation* console) { /* Draws the console buffer to the screen if the console is "visible" */ void CON_DrawConsole(ConsoleInformation *console) { - SDL_Rect DestRect; - SDL_Rect SrcRect; + grs_canvas *canv_save; + grs_bitmap *clip; if(!console) return; @@ -330,43 +369,43 @@ void CON_DrawConsole(ConsoleInformation *console) { /* Update the command line since it has a blinking cursor */ DrawCommandLine(); +#if 0 /* before drawing, make sure the alpha channel of the console surface is set * properly. (sigh) I wish we didn't have to do this every frame... */ if(console->OutputScreen->flags & SDL_OPENGLBLIT) CON_AlphaGL(console->ConsoleSurface, console->ConsoleAlpha); +#endif - SrcRect.x = 0; - SrcRect.y = console->ConsoleSurface->h - console->RaiseOffset; - SrcRect.w = console->ConsoleSurface->w; - SrcRect.h = console->RaiseOffset; + canv_save = grd_curcanv; + gr_set_current_canvas(&console->OutputScreen->sc_canvas); - /* Setup the rect the console is being blitted into based on the output screen */ - DestRect.x = console->DispX; - DestRect.y = console->DispY; - DestRect.w = console->ConsoleSurface->w; - DestRect.h = console->ConsoleSurface->h; + clip = gr_create_sub_bitmap(&console->ConsoleSurface->cv_bitmap, 0, console->ConsoleSurface->cv_h - console->RaiseOffset, console->ConsoleSurface->cv_w, console->RaiseOffset); - SDL_BlitSurface(console->ConsoleSurface, &SrcRect, console->OutputScreen, &DestRect); + gr_bitmap(console->DispX, console->DispY, clip); + gr_free_sub_bitmap(clip); +#if 0 if(console->OutputScreen->flags & SDL_OPENGLBLIT) SDL_UpdateRects(console->OutputScreen, 1, &DestRect); +#endif + + gr_set_current_canvas(canv_save); } /* Initializes the console */ -ConsoleInformation *CON_Init(const char *FontName, SDL_Surface *DisplayScreen, int lines, SDL_Rect rect) { +ConsoleInformation *CON_Init(grs_font *Font, grs_screen *DisplayScreen, int lines, int x, int y, int w, int h) +{ int loop; - SDL_Surface *Temp; ConsoleInformation *newinfo; /* Create a new console struct and init it. */ - if((newinfo = (ConsoleInformation *) malloc(sizeof(ConsoleInformation))) == NULL) { - PRINT_ERROR("Could not allocate the space for a new console info struct.\n"); + if((newinfo = (ConsoleInformation *) d_malloc(sizeof(ConsoleInformation))) == NULL) { + //PRINT_ERROR("Could not allocate the space for a new console info struct.\n"); return NULL; } newinfo->Visible = CON_CLOSED; - newinfo->WasUnicode = 0; newinfo->RaiseOffset = 0; newinfo->ConsoleLines = NULL; newinfo->CommandLines = NULL; @@ -374,7 +413,9 @@ ConsoleInformation *CON_Init(const char *FontName, SDL_Surface *DisplayScreen, i newinfo->ConsoleScrollBack = 0; newinfo->TotalCommands = 0; newinfo->BackgroundImage = NULL; +#if 0 newinfo->ConsoleAlpha = SDL_ALPHA_OPAQUE; +#endif newinfo->Offset = 0; newinfo->InsMode = 1; newinfo->CursorPos = 0; @@ -386,67 +427,58 @@ ConsoleInformation *CON_Init(const char *FontName, SDL_Surface *DisplayScreen, i CON_SetExecuteFunction(newinfo, Default_CmdFunction); CON_SetTabCompletion(newinfo, Default_TabFunction); - /* Load the consoles font */ - if(-1 == (newinfo->FontNumber = DT_LoadFont(FontName, TRANS_FONT))) { - PRINT_ERROR("Could not load the font "); - fprintf(stderr, "\"%s\" for the console!\n", FontName); - return NULL; - } - - newinfo->FontHeight = DT_FontHeight(newinfo->FontNumber); - newinfo->FontWidth = DT_FontWidth(newinfo->FontNumber); - /* make sure that the size of the console is valid */ - if(rect.w > newinfo->OutputScreen->w || rect.w < newinfo->FontWidth * 32) - rect.w = newinfo->OutputScreen->w; - if(rect.h > newinfo->OutputScreen->h || rect.h < newinfo->FontHeight) - rect.h = newinfo->OutputScreen->h; - if(rect.x < 0 || rect.x > newinfo->OutputScreen->w - rect.w) + if(w > newinfo->OutputScreen->sc_w || w < Font->ft_w * 32) + w = newinfo->OutputScreen->sc_w; + if(h > newinfo->OutputScreen->sc_h || h < Font->ft_h) + h = newinfo->OutputScreen->sc_h; + if(x < 0 || x > newinfo->OutputScreen->sc_w - w) newinfo->DispX = 0; else - newinfo->DispX = rect.x; - if(rect.y < 0 || rect.y > newinfo->OutputScreen->h - rect.h) + newinfo->DispX = x; + if(y < 0 || y > newinfo->OutputScreen->sc_h - h) newinfo->DispY = 0; else - newinfo->DispY = rect.y; + newinfo->DispY = y; /* load the console surface */ - Temp = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, newinfo->OutputScreen->format->BitsPerPixel, 0, 0, 0, 0); - if(Temp == NULL) { - PRINT_ERROR("Couldn't create the ConsoleSurface\n"); - return NULL; + newinfo->ConsoleSurface = gr_create_canvas(w, h); + + /* Load the consoles font */ + { + grs_canvas *canv_save; + + canv_save = grd_curcanv; + gr_set_current_canvas(newinfo->ConsoleSurface); + gr_set_curfont(Font); + gr_set_fontcolor(gr_getcolor(63,63,63), -1); + gr_set_current_canvas(canv_save); } - newinfo->ConsoleSurface = SDL_DisplayFormat(Temp); - SDL_FreeSurface(Temp); - SDL_FillRect(newinfo->ConsoleSurface, NULL, SDL_MapRGBA(newinfo->ConsoleSurface->format, 0, 0, 0, newinfo->ConsoleAlpha)); + /* Load the dirty rectangle for user input */ - Temp = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, newinfo->FontHeight, newinfo->OutputScreen->format->BitsPerPixel, 0, 0, 0, SDL_ALPHA_OPAQUE); - if(Temp == NULL) { - PRINT_ERROR("Couldn't create the InputBackground\n"); - return NULL; - } - newinfo->InputBackground = SDL_DisplayFormat(Temp); - SDL_FreeSurface(Temp); + newinfo->InputBackground = gr_create_bitmap(w, newinfo->ConsoleSurface->cv_font->ft_h); +#if 0 SDL_FillRect(newinfo->InputBackground, NULL, SDL_MapRGBA(newinfo->ConsoleSurface->format, 0, 0, 0, SDL_ALPHA_OPAQUE)); +#endif /* calculate the number of visible characters in the command line */ - newinfo->VChars = (rect.w - CON_CHAR_BORDER) / newinfo->FontWidth; + newinfo->VChars = (w - CON_CHAR_BORDER) / newinfo->ConsoleSurface->cv_font->ft_w; if(newinfo->VChars > CON_CHARS_PER_LINE) newinfo->VChars = CON_CHARS_PER_LINE; /* We would like to have a minumum # of lines to guarentee we don't create a memory error */ - if(rect.h / newinfo->FontHeight > lines) - newinfo->LineBuffer = rect.h / newinfo->FontHeight; + if(h / (CON_LINE_SPACE + newinfo->ConsoleSurface->cv_font->ft_h) > lines) + newinfo->LineBuffer = h / (CON_LINE_SPACE + newinfo->ConsoleSurface->cv_font->ft_h); else newinfo->LineBuffer = lines; - newinfo->ConsoleLines = (char **)malloc(sizeof(char *) * newinfo->LineBuffer); - newinfo->CommandLines = (char **)malloc(sizeof(char *) * newinfo->LineBuffer); + newinfo->ConsoleLines = (char **)d_malloc(sizeof(char *) * newinfo->LineBuffer); + newinfo->CommandLines = (char **)d_malloc(sizeof(char *) * newinfo->LineBuffer); for(loop = 0; loop <= newinfo->LineBuffer - 1; loop++) { - newinfo->ConsoleLines[loop] = (char *)calloc(CON_CHARS_PER_LINE, sizeof(char)); - newinfo->CommandLines[loop] = (char *)calloc(CON_CHARS_PER_LINE, sizeof(char)); + newinfo->ConsoleLines[loop] = (char *)d_calloc(CON_CHARS_PER_LINE, sizeof(char)); + newinfo->CommandLines[loop] = (char *)d_calloc(CON_CHARS_PER_LINE, sizeof(char)); } memset(newinfo->Command, 0, CON_CHARS_PER_LINE); memset(newinfo->LCommand, 0, CON_CHARS_PER_LINE); @@ -466,18 +498,13 @@ void CON_Show(ConsoleInformation *console) { if(console) { console->Visible = CON_OPENING; CON_UpdateConsole(console); - - console->WasUnicode = SDL_EnableUNICODE(-1); - SDL_EnableUNICODE(1); } } /* Hides the console (make it invisible) */ void CON_Hide(ConsoleInformation *console) { - if(console) { + if(console) console->Visible = CON_CLOSING; - SDL_EnableUNICODE(console->WasUnicode); - } } /* tells wether the console is visible or not */ @@ -489,7 +516,6 @@ int CON_isVisible(ConsoleInformation *console) { /* Frees all the memory loaded by the console */ void CON_Destroy(ConsoleInformation *console) { - DT_DestroyDrawText(); CON_Free(console); } @@ -502,15 +528,26 @@ void CON_Free(ConsoleInformation *console) { //CON_DestroyCommands(); for(i = 0; i <= console->LineBuffer - 1; i++) { - free(console->ConsoleLines[i]); - free(console->CommandLines[i]); + d_free(console->ConsoleLines[i]); + d_free(console->CommandLines[i]); } - free(console->ConsoleLines); - free(console->CommandLines); + d_free(console->ConsoleLines); + d_free(console->CommandLines); console->ConsoleLines = NULL; console->CommandLines = NULL; - free(console); + + gr_free_canvas(console->ConsoleSurface); + console->ConsoleSurface = NULL; + + if (console->BackgroundImage) + gr_free_bitmap(console->BackgroundImage); + console->BackgroundImage = NULL; + + gr_free_bitmap(console->InputBackground); + console->InputBackground = NULL; + + d_free(console); } @@ -568,20 +605,25 @@ void CON_NewLineCommand(ConsoleInformation *console) { /* Draws the command line the user is typing in to the screen */ /* completely rewritten by C.Wacha */ void DrawCommandLine() { - SDL_Rect rect; int x; int commandbuffer; - BitFont* CurrentFont; - static Uint32 LastBlinkTime = 0; /* Last time the consoles cursor blinked */ +#if 0 + grs_font* CurrentFont; +#endif + static unsigned int LastBlinkTime = 0; /* Last time the consoles cursor blinked */ static int LastCursorPos = 0; // Last Cursor Position static int Blink = 0; /* Is the cursor currently blinking */ + grs_canvas *canv_save; + short orig_color; if(!Topmost) return; commandbuffer = Topmost->VChars - strlen(Topmost->Prompt)-1; // -1 to make cursor visible - CurrentFont = DT_FontPointer(Topmost->FontNumber); +#if 0 + CurrentFont = Topmost->ConsoleSurface->cv_font; +#endif //Concatenate the left and right side to command strcpy(Topmost->Command, Topmost->LCommand); @@ -601,27 +643,30 @@ void DrawCommandLine() { //now display the result +#if 0 //once again we're drawing text, so in OpenGL context we need to temporarily set up //software-mode transparency. if(Topmost->OutputScreen->flags & SDL_OPENGLBLIT) { Uint32 *pix = (Uint32 *) (CurrentFont->FontSurface->pixels); SDL_SetColorKey(CurrentFont->FontSurface, SDL_SRCCOLORKEY, *pix); } +#endif + + canv_save = grd_curcanv; + gr_set_current_canvas(Topmost->ConsoleSurface); //first of all restore InputBackground - rect.x = 0; - rect.y = Topmost->ConsoleSurface->h - Topmost->FontHeight; - rect.w = Topmost->InputBackground->w; - rect.h = Topmost->InputBackground->h; - SDL_BlitSurface(Topmost->InputBackground, NULL, Topmost->ConsoleSurface, &rect); + gr_bitmap(0, Topmost->ConsoleSurface->cv_h - Topmost->ConsoleSurface->cv_font->ft_h, Topmost->InputBackground); //now add the text - DT_DrawText(Topmost->VCommand, Topmost->ConsoleSurface, Topmost->FontNumber, CON_CHAR_BORDER, Topmost->ConsoleSurface->h - Topmost->FontHeight); + orig_color = FG_COLOR; + gr_string(CON_CHAR_BORDER, Topmost->ConsoleSurface->cv_h - Topmost->ConsoleSurface->cv_font->ft_h, Topmost->VCommand); + FG_COLOR = orig_color; //at last add the cursor //check if the blink period is over - if(SDL_GetTicks() > LastBlinkTime) { - LastBlinkTime = SDL_GetTicks() + CON_BLINK_RATE; + if(get_msecs() > LastBlinkTime) { + LastBlinkTime = get_msecs() + CON_BLINK_RATE; if(Blink) Blink = 0; else @@ -631,22 +676,28 @@ void DrawCommandLine() { //check if cursor has moved - if yes display cursor anyway if(Topmost->CursorPos != LastCursorPos) { LastCursorPos = Topmost->CursorPos; - LastBlinkTime = SDL_GetTicks() + CON_BLINK_RATE; + LastBlinkTime = get_msecs() + CON_BLINK_RATE; Blink = 1; } if(Blink) { - x = CON_CHAR_BORDER + Topmost->FontWidth * (Topmost->CursorPos - Topmost->Offset + strlen(Topmost->Prompt)); + x = CON_CHAR_BORDER + Topmost->ConsoleSurface->cv_font->ft_w * (Topmost->CursorPos - Topmost->Offset + strlen(Topmost->Prompt)); + orig_color = FG_COLOR; if(Topmost->InsMode) - DT_DrawText(CON_INS_CURSOR, Topmost->ConsoleSurface, Topmost->FontNumber, x, Topmost->ConsoleSurface->h - Topmost->FontHeight); + gr_string(x, Topmost->ConsoleSurface->cv_h - Topmost->ConsoleSurface->cv_font->ft_h, CON_INS_CURSOR); else - DT_DrawText(CON_OVR_CURSOR, Topmost->ConsoleSurface, Topmost->FontNumber, x, Topmost->ConsoleSurface->h - Topmost->FontHeight); + gr_string(x, Topmost->ConsoleSurface->cv_h - Topmost->ConsoleSurface->cv_font->ft_h, CON_OVR_CURSOR); + FG_COLOR = orig_color; } + gr_set_current_canvas(canv_save); + +#if 0 if(Topmost->OutputScreen->flags & SDL_OPENGLBLIT) { SDL_SetColorKey(CurrentFont->FontSurface, 0, 0); } +#endif } /* Outputs text to the console (in game), up to CON_CHARS_PER_LINE chars can be entered */ @@ -687,6 +738,7 @@ void CON_Out(ConsoleInformation *console, const char *str, ...) { } +#if 0 /* Sets the alpha level of the console, 0 turns off alpha blending */ void CON_Alpha(ConsoleInformation *console, unsigned char alpha) { if(!console) @@ -704,161 +756,146 @@ void CON_Alpha(ConsoleInformation *console, unsigned char alpha) { // CON_UpdateConsole(console); } +#endif -/* Adds background image to the console, x and y based on consoles x and y */ -int CON_Background(ConsoleInformation *console, const char *image, int x, int y) { - SDL_Surface *temp; - SDL_Rect backgroundsrc, backgrounddest; - +/* Adds background image to the console, scaled to size of console*/ +int CON_Background(ConsoleInformation *console, grs_bitmap *image) +{ if(!console) return 1; /* Free the background from the console */ - if(image == NULL) { - if(console->BackgroundImage ==NULL) - SDL_FreeSurface(console->BackgroundImage); + if (image == NULL) { + if (console->BackgroundImage) + gr_free_bitmap(console->BackgroundImage); console->BackgroundImage = NULL; +#if 0 SDL_FillRect(console->InputBackground, NULL, SDL_MapRGBA(console->ConsoleSurface->format, 0, 0, 0, SDL_ALPHA_OPAQUE)); +#endif return 0; } /* Load a new background */ - temp = IMG_Load(image); - if(!temp) { - CON_Out(console, "Cannot load background %s.", image); - return 1; - } - - console->BackgroundImage = SDL_DisplayFormat(temp); - SDL_FreeSurface(temp); - console->BackX = x; - console->BackY = y; - - backgroundsrc.x = 0; - backgroundsrc.y = console->ConsoleSurface->h - console->FontHeight - console->BackY; - backgroundsrc.w = console->BackgroundImage->w; - backgroundsrc.h = console->InputBackground->h; - - backgrounddest.x = console->BackX; - backgrounddest.y = 0; - backgrounddest.w = console->BackgroundImage->w; - backgrounddest.h = console->FontHeight; + if (console->BackgroundImage) + gr_free_bitmap(console->BackgroundImage); + console->BackgroundImage = gr_create_bitmap(console->ConsoleSurface->cv_w, console->ConsoleSurface->cv_h); + gr_bitmap_scale_to(image, console->BackgroundImage); +#if 0 SDL_FillRect(console->InputBackground, NULL, SDL_MapRGBA(console->ConsoleSurface->format, 0, 0, 0, SDL_ALPHA_OPAQUE)); - SDL_BlitSurface(console->BackgroundImage, &backgroundsrc, console->InputBackground, &backgrounddest); +#endif + gr_bm_bitblt(console->BackgroundImage->bm_w, console->InputBackground->bm_h, 0, 0, 0, console->ConsoleSurface->cv_h - console->ConsoleSurface->cv_font->ft_h, console->BackgroundImage, console->InputBackground); return 0; } +/* Sets font info for the console */ +void CON_Font(ConsoleInformation *console, grs_font *font, int fg, int bg) +{ + grs_canvas *canv_save; + + canv_save = grd_curcanv; + gr_set_current_canvas(console->ConsoleSurface); + gr_set_curfont(font); + gr_set_fontcolor(fg, bg); + gr_set_current_canvas(canv_save); +} + /* takes a new x and y of the top left of the console window */ void CON_Position(ConsoleInformation *console, int x, int y) { if(!console) return; - if(x < 0 || x > console->OutputScreen->w - console->ConsoleSurface->w) + if(x < 0 || x > console->OutputScreen->sc_w - console->ConsoleSurface->cv_w) console->DispX = 0; else console->DispX = x; - if(y < 0 || y > console->OutputScreen->h - console->ConsoleSurface->h) + if(y < 0 || y > console->OutputScreen->sc_h - console->ConsoleSurface->cv_h) console->DispY = 0; else console->DispY = y; } +void gr_init_bitmap_alloc( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline); /* resizes the console, has to reset alot of stuff * returns 1 on error */ -int CON_Resize(ConsoleInformation *console, SDL_Rect rect) { - SDL_Surface *Temp; - SDL_Rect backgroundsrc, backgrounddest; - +int CON_Resize(ConsoleInformation *console, int x, int y, int w, int h) +{ if(!console) return 1; /* make sure that the size of the console is valid */ - if(rect.w > console->OutputScreen->w || rect.w < console->FontWidth * 32) - rect.w = console->OutputScreen->w; - if(rect.h > console->OutputScreen->h || rect.h < console->FontHeight) - rect.h = console->OutputScreen->h; - if(rect.x < 0 || rect.x > console->OutputScreen->w - rect.w) + if(w > console->OutputScreen->sc_w || w < console->ConsoleSurface->cv_font->ft_w * 32) + w = console->OutputScreen->sc_w; + if(h > console->OutputScreen->sc_h || h < console->ConsoleSurface->cv_font->ft_h) + h = console->OutputScreen->sc_h; + if(x < 0 || x > console->OutputScreen->sc_w - w) console->DispX = 0; else - console->DispX = rect.x; - if(rect.y < 0 || rect.y > console->OutputScreen->h - rect.h) + console->DispX = x; + if(y < 0 || y > console->OutputScreen->sc_h - h) console->DispY = 0; else - console->DispY = rect.y; + console->DispY = y; - /* load the console surface */ - SDL_FreeSurface(console->ConsoleSurface); - Temp = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, console->OutputScreen->format->BitsPerPixel, 0, 0, 0, 0); - if(Temp == NULL) { - PRINT_ERROR("Couldn't create the console->ConsoleSurface\n"); - return 1; - } - console->ConsoleSurface = SDL_DisplayFormat(Temp); - SDL_FreeSurface(Temp); + /* resize console surface */ + gr_free_bitmap_data(&console->ConsoleSurface->cv_bitmap); + gr_init_bitmap_alloc(&console->ConsoleSurface->cv_bitmap, BM_LINEAR, 0, 0, w, h, w); /* Load the dirty rectangle for user input */ - SDL_FreeSurface(console->InputBackground); - Temp = SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, console->FontHeight, console->OutputScreen->format->BitsPerPixel, 0, 0, 0, 0); - if(Temp == NULL) { - PRINT_ERROR("Couldn't create the input background\n"); - return 1; - } - console->InputBackground = SDL_DisplayFormat(Temp); - SDL_FreeSurface(Temp); + gr_free_bitmap(console->InputBackground); + console->InputBackground = gr_create_bitmap(w, console->ConsoleSurface->cv_font->ft_h); /* Now reset some stuff dependent on the previous size */ console->ConsoleScrollBack = 0; /* Reload the background image (for the input text area) in the console */ if(console->BackgroundImage) { - backgroundsrc.x = 0; - backgroundsrc.y = console->ConsoleSurface->h - console->FontHeight - console->BackY; - backgroundsrc.w = console->BackgroundImage->w; - backgroundsrc.h = console->InputBackground->h; - - backgrounddest.x = console->BackX; - backgrounddest.y = 0; - backgrounddest.w = console->BackgroundImage->w; - backgrounddest.h = console->FontHeight; - +#if 0 SDL_FillRect(console->InputBackground, NULL, SDL_MapRGBA(console->ConsoleSurface->format, 0, 0, 0, SDL_ALPHA_OPAQUE)); - SDL_BlitSurface(console->BackgroundImage, &backgroundsrc, console->InputBackground, &backgrounddest); +#endif + gr_bm_bitblt(console->BackgroundImage->bm_w, console->InputBackground->bm_h, 0, 0, 0, console->ConsoleSurface->cv_h - console->ConsoleSurface->cv_font->ft_h, console->BackgroundImage, console->InputBackground); } +#if 0 /* restore the alpha level */ CON_Alpha(console, console->ConsoleAlpha); +#endif return 0; } /* Transfers the console to another screen surface, and adjusts size */ -int CON_Transfer(ConsoleInformation* console, SDL_Surface* new_outputscreen, SDL_Rect rect) { +int CON_Transfer(ConsoleInformation *console, grs_screen *new_outputscreen, int x, int y, int w, int h) +{ if(!console) return 1; console->OutputScreen = new_outputscreen; - return( CON_Resize(console, rect) ); + return(CON_Resize(console, x, y, w, h)); } /* Sets the topmost console for input */ void CON_Topmost(ConsoleInformation *console) { - SDL_Rect rect; + grs_canvas *canv_save; + short orig_color; if(!console) return; // Make sure the blinking cursor is gone if(Topmost) { - rect.x = 0; - rect.y = Topmost->ConsoleSurface->h - Topmost->FontHeight; - rect.w = Topmost->InputBackground->w; - rect.h = Topmost->InputBackground->h; - SDL_BlitSurface(Topmost->InputBackground, NULL, Topmost->ConsoleSurface, &rect); - DT_DrawText(Topmost->VCommand, Topmost->ConsoleSurface, Topmost->FontNumber, CON_CHAR_BORDER, Topmost->ConsoleSurface->h - Topmost->FontHeight); + canv_save = grd_curcanv; + gr_set_current_canvas(Topmost->ConsoleSurface); + + gr_bitmap(0, Topmost->ConsoleSurface->cv_h - Topmost->ConsoleSurface->cv_font->ft_h, Topmost->InputBackground); + orig_color = FG_COLOR; + gr_string(CON_CHAR_BORDER, Topmost->ConsoleSurface->cv_h - Topmost->ConsoleSurface->cv_font->ft_h, Topmost->VCommand); + FG_COLOR = orig_color; + + gr_set_current_canvas(canv_save); } Topmost = console; } @@ -1001,10 +1038,12 @@ void Cursor_BSpace(ConsoleInformation *console) { } } -void Cursor_Add(ConsoleInformation *console, SDL_Event *event) { - if(strlen(Topmost->Command) < CON_CHARS_PER_LINE - 1 && event->key.keysym.unicode) { +void Cursor_Add(ConsoleInformation *console, int event) +{ + if(strlen(Topmost->Command) < CON_CHARS_PER_LINE - 1) + { Topmost->CursorPos++; - Topmost->LCommand[strlen(Topmost->LCommand)] = (char)event->key.keysym.unicode; + Topmost->LCommand[strlen(Topmost->LCommand)] = key_to_ascii(event); Topmost->LCommand[strlen(Topmost->LCommand)] = '\0'; } } diff --git a/console/DT_drawtext.c b/console/DT_drawtext.c deleted file mode 100644 index 872fbb03..00000000 --- a/console/DT_drawtext.c +++ /dev/null @@ -1,215 +0,0 @@ -/* DT_drawtext.c - * Written By: Garrett Banuk - * This is free, just be sure to give me credit when using it - * in any of your programs. - */ - -#include -#include -#include -#include "SDL.h" -#include "SDL_image.h" -#include "DT_drawtext.h" -#include "internal.h" - - -static BitFont *BitFonts = NULL; /* Linked list of fonts */ - - -/* sets the transparency value for the font in question. assumes that - * we're in an OpenGL context. */ -void DT_SetFontAlphaGL(int FontNumber, int a) { - unsigned char val; - BitFont *CurrentFont; - unsigned char r_targ, g_targ, b_targ; - int i, imax; - unsigned char *pix; - - /* get pointer to font */ - CurrentFont = DT_FontPointer(FontNumber); - if(CurrentFont == NULL) { - PRINT_ERROR("Setting font alpha for non-existent font!\n"); - return; - } - if(CurrentFont->FontSurface->format->BytesPerPixel == 2) { - PRINT_ERROR("16-bit SDL surfaces do not support alpha-blending under OpenGL\n"); - return; - } - if(a < SDL_ALPHA_TRANSPARENT) - val = SDL_ALPHA_TRANSPARENT; - else if(a > SDL_ALPHA_OPAQUE) - val = SDL_ALPHA_OPAQUE; - else - val = a; - - /* iterate over all pixels in the font surface. For each - * pixel that is (255,0,255), set its alpha channel - * appropriately. */ - imax = CurrentFont->FontSurface->h * (CurrentFont->FontSurface->w << 2); - pix = (unsigned char *)(CurrentFont->FontSurface->pixels); - r_targ = 255; /*pix[0]; */ - g_targ = 0; /*pix[1]; */ - b_targ = 255; /*pix[2]; */ - for(i = 3; i < imax; i += 4) - if(pix[i - 3] == r_targ && pix[i - 2] == g_targ && pix[i - 1] == b_targ) - pix[i] = val; - /* also make sure that alpha blending is disabled for the font - surface. */ - SDL_SetAlpha(CurrentFont->FontSurface, 0, SDL_ALPHA_OPAQUE); -} - -/* Loads the font into a new struct - * returns -1 as an error else it returns the number - * of the font for the user to use - */ -int DT_LoadFont(const char *BitmapName, int flags) { - int FontNumber = 0; - BitFont **CurrentFont = &BitFonts; - SDL_Surface *Temp; - - - while(*CurrentFont) { - CurrentFont = &((*CurrentFont)->NextFont); - FontNumber++; - } - - /* load the font bitmap */ - if(NULL == (Temp = IMG_Load(BitmapName))) { - PRINT_ERROR("Cannot load file "); - printf("%s\n", BitmapName); - return -1; - } - - /* Add a font to the list */ - *CurrentFont = (BitFont *) malloc(sizeof(BitFont)); - - (*CurrentFont)->FontSurface = SDL_DisplayFormat(Temp); - SDL_FreeSurface(Temp); - - (*CurrentFont)->CharWidth = (*CurrentFont)->FontSurface->w / 256; - (*CurrentFont)->CharHeight = (*CurrentFont)->FontSurface->h; - (*CurrentFont)->FontNumber = FontNumber; - (*CurrentFont)->NextFont = NULL; - - - /* Set font as transparent if the flag is set. The assumption we'll go on - * is that the first pixel of the font image will be the color we should treat - * as transparent. - */ - if(flags & TRANS_FONT) { - if(SDL_GetVideoSurface()->flags & SDL_OPENGLBLIT) - DT_SetFontAlphaGL(FontNumber, SDL_ALPHA_TRANSPARENT); - else - SDL_SetColorKey((*CurrentFont)->FontSurface, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB((*CurrentFont)->FontSurface->format, 255, 0, 255)); - } else if(SDL_GetVideoSurface()->flags & SDL_OPENGLBLIT) - DT_SetFontAlphaGL(FontNumber, SDL_ALPHA_OPAQUE); - - return FontNumber; -} - -/* Takes the font type, coords, and text to draw to the surface*/ -void DT_DrawText(const char *string, SDL_Surface *surface, int FontType, int x, int y) { - int loop; - int characters; - int current; - SDL_Rect SourceRect, DestRect; - BitFont *CurrentFont; - - CurrentFont = DT_FontPointer(FontType); - - /* see how many characters can fit on the screen */ - if(x > surface->w || y > surface->h) - return; - - if(strlen(string) < (surface->w - x) / CurrentFont->CharWidth) - characters = strlen(string); - else - characters = (surface->w - x) / CurrentFont->CharWidth; - - DestRect.x = x; - DestRect.y = y; - DestRect.w = CurrentFont->CharWidth; - DestRect.h = CurrentFont->CharHeight; - - SourceRect.y = 0; - SourceRect.w = CurrentFont->CharWidth; - SourceRect.h = CurrentFont->CharHeight; - - /* Now draw it */ - for(loop = 0; loop < characters; loop++) { - current = string[loop]; - if (current<0 || current > 255) - current = 0; - //SourceRect.x = string[loop] * CurrentFont->CharWidth; - SourceRect.x = current * CurrentFont->CharWidth; - SDL_BlitSurface(CurrentFont->FontSurface, &SourceRect, surface, &DestRect); - DestRect.x += CurrentFont->CharWidth; - } - /* if we're in OpenGL-mode, we need to manually update after blitting. */ - if(surface->flags & SDL_OPENGLBLIT) { - DestRect.x = x; - DestRect.w = characters * CurrentFont->CharWidth; - SDL_UpdateRects(surface, 1, &DestRect); - } -} - - -/* Returns the height of the font numbers character - * returns 0 if the fontnumber was invalid */ -int DT_FontHeight(int FontNumber) { - BitFont *CurrentFont; - - CurrentFont = DT_FontPointer(FontNumber); - if(CurrentFont) - return CurrentFont->CharHeight; - else - return 0; -} - -/* Returns the width of the font numbers charcter */ -int DT_FontWidth(int FontNumber) { - BitFont *CurrentFont; - - CurrentFont = DT_FontPointer(FontNumber); - if(CurrentFont) - return CurrentFont->CharWidth; - else - return 0; -} - -/* Returns a pointer to the font struct of the number - * returns NULL if theres an error - */ -BitFont *DT_FontPointer(int FontNumber) { - BitFont *CurrentFont = BitFonts; - BitFont *temp; - - while(CurrentFont) - if(CurrentFont->FontNumber == FontNumber) - return CurrentFont; - else { - temp = CurrentFont; - CurrentFont = CurrentFont->NextFont; - } - - return NULL; - -} - -/* removes all the fonts currently loaded */ -void DT_DestroyDrawText() { - BitFont *CurrentFont = BitFonts; - BitFont *temp; - - while(CurrentFont) { - temp = CurrentFont; - CurrentFont = CurrentFont->NextFont; - - SDL_FreeSurface(temp->FontSurface); - free(temp); - } - - BitFonts = NULL; -} - - diff --git a/console/Makefile.am b/console/Makefile.am index 347d55b4..2919c993 100644 --- a/console/Makefile.am +++ b/console/Makefile.am @@ -1,4 +1,4 @@ noinst_LIBRARIES = libconsole.a -INCLUDES = -I $(top_srcdir)/include +INCLUDES = -I $(top_srcdir)/include -I$(top_srcdir)/arch/include -libconsole_a_SOURCES = CON_console.c DT_drawtext.c internal.c +libconsole_a_SOURCES = CON_console.c diff --git a/console/internal.c b/console/internal.c deleted file mode 100644 index f32fe760..00000000 --- a/console/internal.c +++ /dev/null @@ -1,75 +0,0 @@ -/* internal.c - * Written By: Garrett Banuk - * This is free, just be sure to give me credit when using it - * in any of your programs. - */ - -/* internal.[c,h] are various routines used internally - * by SDL_console and DrawText. */ - -#include "SDL.h" - - -/* - * Return the pixel value at (x, y) - * NOTE: The surface must be locked before calling this! - */ -Uint32 DT_GetPixel(SDL_Surface *surface, int x, int y) { - int bpp = surface->format->BytesPerPixel; - /* Here p is the address to the pixel we want to retrieve */ - Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp; - - switch (bpp) { - case 1: - return *p; - case 2: - return *(Uint16 *) p; - case 3: - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - return p[0] << 16 | p[1] << 8 | p[2]; - else - return p[0] | p[1] << 8 | p[2] << 16; - case 4: - return *(Uint32 *) p; - default: - return 0; /* shouldn't happen, but avoids warnings */ - } -} - -/* - * Set the pixel at (x, y) to the given value - * NOTE: The surface must be locked before calling this! - */ -void DT_PutPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) { - int bpp = surface->format->BytesPerPixel; - /* Here p is the address to the pixel we want to set */ - Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp; - - switch (bpp) { - case 1: - *p = pixel; - break; - case 2: - *(Uint16 *) p = pixel; - break; - case 3: - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { - p[0] = (pixel >> 16) & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = pixel & 0xff; - } else { - p[0] = pixel & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = (pixel >> 16) & 0xff; - } - break; - case 4: - *(Uint32 *) p = pixel; - break; - default: - break; - } -} - - - diff --git a/console/internal.h b/console/internal.h deleted file mode 100644 index 84f0897f..00000000 --- a/console/internal.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _internal_h_ -#define _internal_h_ - - -#define PRINT_ERROR(X) fprintf(stderr, "ERROR in %s:%s(): %s\n", __FILE__, __FUNCTION__, X) - -Uint32 DT_GetPixel(SDL_Surface *surface, int x, int y); -void DT_PutPixel(SDL_Surface *surface, int x, int y, Uint32 pixel); - - -#endif /* _internal_h_ */ - - diff --git a/include/CON_console.h b/include/CON_console.h index 814d64f8..7c872458 100644 --- a/include/CON_console.h +++ b/include/CON_console.h @@ -17,11 +17,12 @@ Have Fun! \author Garett Banuk (Original Version) \author Clemens Wacha (Version 2.x, Documentation) \author Boris Lesner (Package Maintainer) +\author Bradley Bell (Descent Version) */ - -#include "SDL.h" +#include "gr.h" +#include "key.h" //! Cut the buffer line if it becomes longer than this #define CON_CHARS_PER_LINE 128 @@ -29,6 +30,8 @@ Have Fun! #define CON_BLINK_RATE 500 //! Border in pixels from the most left to the first letter #define CON_CHAR_BORDER 4 +//! Spacing in pixels between lines +#define CON_LINE_SPACE 1 //! Default prompt used at the commandline #define CON_DEFAULT_PROMPT "]" //! Scroll this many lines at a time (when pressing PGUP or PGDOWN) @@ -40,7 +43,7 @@ Have Fun! //! Cursor shown if we are in overwrite mode #define CON_OVR_CURSOR "|" //! Defines the default hide key (Hide() the console if pressed) -#define CON_DEFAULT_HIDEKEY SDLK_ESCAPE +#define CON_DEFAULT_HIDEKEY KEY_ESC //! Defines the opening/closing speed #define CON_OPENCLOSE_SPEED 25 @@ -58,7 +61,6 @@ extern "C" { /*! This is a struct for each consoles data */ typedef struct console_information_td { int Visible; //! enum that tells which visible state we are in CON_HIDE, CON_SHOW, CON_RAISE, CON_LOWER - int WasUnicode; //! stores the UNICODE value before the console was shown. On Hide() the UNICODE value is restored. int RaiseOffset; //! Offset used when scrolling in the console int HideKey; //! the key that can hide the console char **ConsoleLines; //! List of all the past lines @@ -66,10 +68,8 @@ extern "C" { int TotalConsoleLines; //! Total number of lines in the console int ConsoleScrollBack; //! How much the user scrolled back in the console int TotalCommands; //! Number of commands in the Back Commands - int FontNumber; //! This is the number of the font for the console int LineBuffer; //! The number of visible lines in the console (autocalculated) int VChars; //! The number of visible characters in one console line (autocalculated) - int BackX, BackY; //! Background images x and y coords char* Prompt; //! Prompt displayed in command line char Command[CON_CHARS_PER_LINE]; //! current command in command line = lcommand + rcommand char RCommand[CON_CHARS_PER_LINE]; //! left hand side of cursor @@ -78,25 +78,24 @@ extern "C" { int CursorPos; //! Current cursor position in CurrentCommand int Offset; //! CommandOffset (first visible char of command) - if command is too long to fit into console int InsMode; //! Insert or Overwrite characters? - SDL_Surface *ConsoleSurface; //! Surface of the console - SDL_Surface *OutputScreen; //! This is the screen to draw the console to - SDL_Surface *BackgroundImage; //! Background image for the console - SDL_Surface *InputBackground; //! Dirty rectangle to draw over behind the users background + grs_canvas *ConsoleSurface; //! Canvas of the console + grs_screen *OutputScreen; //! This is the screen to draw the console to + grs_bitmap *BackgroundImage; //! Background image for the console + grs_bitmap *InputBackground; //! Dirty rectangle to draw over behind the users background int DispX, DispY; //! The top left x and y coords of the console on the display screen +#if 0 unsigned char ConsoleAlpha; //! The consoles alpha level +#endif int CommandScrollBack; //! How much the users scrolled back in the command lines void(*CmdFunction)(struct console_information_td *console, char* command); //! The Function that is executed if you press in the console char*(*TabFunction)(char* command); //! The Function that is executed if you press in the console - - int FontHeight; - int FontWidth; } ConsoleInformation; /*! Takes keys from the keyboard and inputs them to the console if the console isVisible(). If the event was not handled (i.e. WM events or unknown ctrl- or alt-sequences) the function returns the event for further processing. */ - SDL_Event* CON_Events(SDL_Event *event); + int CON_Events(int event); /*! Makes the console visible */ void CON_Show(ConsoleInformation *console); /*! Hides the console */ @@ -108,13 +107,14 @@ extern "C" { /*! Draws the console to the screen if it isVisible()*/ void CON_DrawConsole(ConsoleInformation *console); /*! Initializes a new console */ - ConsoleInformation *CON_Init(const char *FontName, SDL_Surface *DisplayScreen, int lines, SDL_Rect rect); - /*! Frees DT_DrawText and calls CON_Free */ + ConsoleInformation *CON_Init(grs_font *Font, grs_screen *DisplayScreen, int lines, int x, int y, int w, int h); + /*! Calls CON_Free */ void CON_Destroy(ConsoleInformation *console); /*! Frees all the memory loaded by the console */ void CON_Free(ConsoleInformation *console); /*! printf for the console */ void CON_Out(ConsoleInformation *console, const char *str, ...); +#if 0 /*! Sets the alpha channel of an SDL_Surface to the specified value (0 - transparend, 255 - opaque). Use this function also for OpenGL. */ void CON_Alpha(ConsoleInformation *console, unsigned char alpha); @@ -122,14 +122,17 @@ extern "C" { Preconditions: the surface in question is RGBA. 0 <= a <= 255, where 0 is transparent and 255 opaque */ void CON_AlphaGL(SDL_Surface *s, int alpha); /*! Sets a background image for the console */ - int CON_Background(ConsoleInformation *console, const char *image, int x, int y); +#endif + int CON_Background(ConsoleInformation *console, grs_bitmap *image); + /*! Sets font info for the console */ + void CON_Font(ConsoleInformation *console, grs_font *font, int fg, int bg); /*! Changes current position of the console */ void CON_Position(ConsoleInformation *console, int x, int y); /*! Changes the size of the console */ - int CON_Resize(ConsoleInformation *console, SDL_Rect rect); + int CON_Resize(ConsoleInformation *console, int x, int y, int w, int h); /*! Beams a console to another screen surface. Needed if you want to make a Video restart in your program. This function first changes the OutputScreen Pointer then calls CON_Resize to adjust the new size. */ - int CON_Transfer(ConsoleInformation* console, SDL_Surface* new_outputscreen, SDL_Rect rect); + int CON_Transfer(ConsoleInformation* console, grs_screen* new_outputscreen, int x, int y, int w, int h); /*! Give focus to a console. Make it the "topmost" console. This console will receive events sent with CON_Events() */ void CON_Topmost(ConsoleInformation *console); @@ -181,7 +184,7 @@ extern "C" { /*! Internal: Called if you press BACKSPACE (deletes character left of cursor) */ void Cursor_BSpace(ConsoleInformation *console); /*! Internal: Called if you type in a character (add the char to the command) */ - void Cursor_Add(ConsoleInformation *console, SDL_Event *event); + void Cursor_Add(ConsoleInformation *console, int event); /*! Internal: Called if you press Ctrl-C (deletes the commandline) */ void Clear_Command(ConsoleInformation *console); diff --git a/include/console.h b/include/console.h index d4de7a84..8f443bdf 100644 --- a/include/console.h +++ b/include/console.h @@ -13,12 +13,13 @@ #define CON_DEBUG 2 int con_init(void); +void con_resize(void); void con_printf(int level, char *fmt, ...); void con_show(void); void con_draw(void); void con_update(void); - +int con_events(int key); /* CVar stuff */ typedef struct cvar_s diff --git a/include/gr.h b/include/gr.h index 5900fe4f..fefd853e 100644 --- a/include/gr.h +++ b/include/gr.h @@ -1,4 +1,4 @@ -/* $Id: gr.h,v 1.19 2003-03-19 22:44:15 btb Exp $ */ +/* $Id: gr.h,v 1.20 2003-06-06 19:04:27 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -262,6 +262,7 @@ void gr_free_sub_bitmap(grs_bitmap *bm); void gr_bm_pixel( grs_bitmap * bm, int x, int y, unsigned char color ); void gr_bm_upixel( grs_bitmap * bm, int x, int y, unsigned char color ); +void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest); void gr_bm_ubitblt( int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest); void gr_bm_ubitbltm(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest); diff --git a/main/console.c b/main/console.c index b9a9c27c..d2da003c 100644 --- a/main/console.c +++ b/main/console.c @@ -1,4 +1,4 @@ -/* $Id: console.c,v 1.13 2003-06-02 20:45:32 btb Exp $ */ +/* $Id: console.c,v 1.14 2003-06-06 19:04:27 btb Exp $ */ /* * * FIXME: put description here @@ -27,6 +27,9 @@ #include "console.h" #include "cmd.h" #include "gr.h" +#include "gamefont.h" +#include "pcx.h" +#include "cfile.h" #ifndef __MSDOS__ int text_console_enabled = 1; @@ -43,8 +46,8 @@ cvar_t con_threshold = {"con_threshold", "0",}; /* Private console stuff */ #define CON_NUM_LINES 40 -#define CON_LINE_LEN 40 #if 0 +#define CON_LINE_LEN 40 static char con_display[40][40]; static int con_line; /* Current display line */ #endif @@ -53,12 +56,22 @@ static int con_line; /* Current display line */ static int con_initialized; ConsoleInformation *Console; -extern SDL_Surface *screen; void con_parse(ConsoleInformation *console, char *command); #endif +/* ====== + * con_free - Free the console. + * ====== + */ +void con_free(void) +{ + if (con_initialized) + CON_Free(Console); + con_initialized = 0; +} + /* ====== * con_init - Initialise the console. * ====== @@ -71,22 +84,49 @@ int con_init(void) } #ifdef CONSOLE -void real_con_init(void) + +#define CON_BG_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx") +#define CON_BG_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx +#define CON_BG ((SWIDTH>=640)?CON_BG_HIRES:CON_BG_LORES) + +void con_background(char *filename) { - SDL_Rect Con_rect; + int pcx_error; + grs_bitmap bmp; + ubyte pal[256*3]; + + gr_init_bitmap_data(&bmp); + pcx_error = pcx_read_bitmap(filename, &bmp, BM_LINEAR, pal); + Assert(pcx_error == PCX_ERROR_NONE); + gr_remap_bitmap_good(&bmp, pal, -1, -1); + CON_Background(Console, &bmp); + gr_free_bitmap_data(&bmp); +} - Con_rect.x = Con_rect.y = 0; - Con_rect.w = 320; - Con_rect.h = 200; - Console = CON_Init("ConsoleFont.png", screen, CON_NUM_LINES, Con_rect); +void con_init_real(void) +{ + Console = CON_Init(SMALL_FONT, grd_curscreen, CON_NUM_LINES, 0, 0, SWIDTH, SHEIGHT / 2); Assert(Console); CON_SetExecuteFunction(Console, con_parse); - CON_Background(Console, "scores.pcx", 0, 0); + + con_background(CON_BG); con_initialized = 1; + + atexit(con_free); +} + +void con_resize(void) +{ + if (!con_initialized) + con_init_real(); + + CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1); + CON_Resize(Console, 0, 0, SWIDTH, SHEIGHT / 2); + con_background(CON_BG); } #endif @@ -104,14 +144,12 @@ void con_printf(int priority, char *fmt, ...) va_start (arglist, fmt); vsprintf (buffer, fmt, arglist); va_end (arglist); - if (text_console_enabled) { - va_start (arglist, fmt); - vprintf(fmt, arglist); - va_end (arglist); - } + if (text_console_enabled) + printf(buffer); #ifdef CONSOLE - CON_Out(Console, buffer); + if (con_initialized) + CON_Out(Console, buffer); #endif /* for (i=0; i #include -#include "CON_console.h" - #include "pstypes.h" #include "console.h" #include "inferno.h" @@ -1107,11 +1105,12 @@ int HandleSystemKey(int key) switch (key) { +#if 1 case KEY_SHIFTED + KEY_ESC: con_show(); break; -#if 0 +#else case KEY_SHIFTED + KEY_ESC: //quick exit #ifdef EDITOR if (! SafetyCheck()) break; @@ -2604,6 +2603,11 @@ void ReadControls() #endif #endif +#ifdef CONSOLE + if(!con_events(key)) + continue; +#endif + if (Player_is_dead) HandleDeathKey(key); diff --git a/main/gamerend.c b/main/gamerend.c index e25ba54d..9ba84d96 100644 --- a/main/gamerend.c +++ b/main/gamerend.c @@ -16,7 +16,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: gamerend.c,v 1.9 2003-06-02 01:55:03 btb Exp $"; +static char rcsid[] = "$Id: gamerend.c,v 1.10 2003-06-06 19:04:27 btb Exp $"; #endif #ifdef WINDOWS @@ -1381,9 +1381,6 @@ void game_render_frame_mono(void) #ifdef _3DFX _3dfx_BufferSwap(); #endif -#ifdef OGL - ogl_swap_buffers(); -#endif } } else { @@ -1428,6 +1425,9 @@ void game_render_frame_mono(void) con_update(); gr_update(); +#ifdef OGL + ogl_swap_buffers(); +#endif } void toggle_cockpit() diff --git a/main/gauges.c b/main/gauges.c index 78d9fc2e..34d596a1 100644 --- a/main/gauges.c +++ b/main/gauges.c @@ -13,13 +13,19 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. /* * $Source: /cvs/cvsroot/d2x/main/gauges.c,v $ - * $Revision: 1.6 $ - * $Author: bradleyb $ - * $Date: 2001-11-08 10:30:27 $ + * $Revision: 1.7 $ + * $Author: btb $ + * $Date: 2003-06-06 19:04:27 $ * * Inferno gauge drivers * * $Log: not supported by cvs2svn $ + * Revision 1.6.2.1 2003/06/06 10:00:31 btb + * force cockpit redraw in opengl + * + * Revision 1.6 2001/11/08 10:30:27 bradleyb + * Enabled shareware build, endlevel flythrough sequence + * * Revision 1.5 2001/11/04 09:00:25 bradleyb * Enable d1x-style hud_message * @@ -3310,6 +3316,8 @@ void show_HUD_names() #endif +extern int last_drawn_cockpit[2]; + //draw all the things on the HUD void draw_hud() { @@ -3318,8 +3326,8 @@ void draw_hud() if (Cockpit_mode==CM_STATUS_BAR){ //ogl needs to redraw every frame, at least currently. // init_cockpit(); - // last_drawn_cockpit[0]=-1; - // last_drawn_cockpit[1]=-1; + last_drawn_cockpit[0]=-1; + last_drawn_cockpit[1]=-1; init_gauges(); // vr_reset_display(); diff --git a/main/hud.c b/main/hud.c index a54b7f31..f0b6fd54 100644 --- a/main/hud.c +++ b/main/hud.c @@ -13,13 +13,19 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. /* * $Source: /cvs/cvsroot/d2x/main/hud.c,v $ - * $Revision: 1.5 $ + * $Revision: 1.6 $ * $Author: btb $ - * $Date: 2002-10-11 05:14:59 $ + * $Date: 2003-06-06 19:04:27 $ * * Routines for displaying HUD messages... * * $Log: not supported by cvs2svn $ + * Revision 1.5.2.1 2003/06/06 03:35:41 btb + * finish console conversion away from SDL + * + * Revision 1.5 2002/10/11 05:14:59 btb + * make hud_message work correctly + * * Revision 1.4 2002/10/10 19:08:15 btb * whitespace * @@ -340,10 +346,14 @@ int PlayerMessage=1; // (message might not be drawn if previous message was same) int HUD_init_message_va(char * format, va_list args) { - int temp, temp2; + int temp; char *message = NULL; char *last_message=NULL; +#if 0 + int temp2; char *cleanmessage; +#endif + char con_message[HUD_MESSAGE_LENGTH + 3]; Modex_hud_msg_count = 2; @@ -354,6 +364,7 @@ int HUD_init_message_va(char * format, va_list args) message = &HUD_messages[hud_last][0]; vsprintf(message,format,args); +#if 0 /* Produce a sanitised version and send it to the console */ cleanmessage = d_strdup(message); for (temp=0,temp2=0; message[temp]!=0; temp++) @@ -362,8 +373,18 @@ int HUD_init_message_va(char * format, va_list args) else temp++; /* Skip next character as well */ } cleanmessage[temp2] = 0; - con_printf(CON_NORMAL, "%s\n", message); + con_printf(CON_NORMAL, "%s\n", cleanmessage); d_free(cleanmessage); +#endif + + /* Produce a colorised version and send it to the console */ + if (HUD_color == -1) + HUD_color = BM_XRGB(0,28,0); + con_message[0] = CC_COLOR; + con_message[1] = HUD_color; + con_message[2] = '\0'; + strcat(con_message, message); + con_printf(CON_NORMAL, "%s\n", con_message); // Added by Leighton diff --git a/main/kconfig.c b/main/kconfig.c index a6a1b5ce..07cdbd65 100644 --- a/main/kconfig.c +++ b/main/kconfig.c @@ -1,4 +1,4 @@ -/* $Id: kconfig.c,v 1.19 2003-03-27 01:25:41 btb Exp $ */ +/* $Id: kconfig.c,v 1.20 2003-06-06 19:04:27 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -346,7 +346,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ #ifdef RCS -static char rcsid[] = "$Id: kconfig.c,v 1.19 2003-03-27 01:25:41 btb Exp $"; +static char rcsid[] = "$Id: kconfig.c,v 1.20 2003-06-06 19:04:27 btb Exp $"; #endif #ifdef WINDOWS @@ -2108,8 +2108,6 @@ void kc_change_invert( kc_item * item ) #include "screens.h" -extern void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest); - void kconfig(int n, char * title) { int i; diff --git a/main/newmenu.c b/main/newmenu.c index d5c9d354..44e989ed 100644 --- a/main/newmenu.c +++ b/main/newmenu.c @@ -1,4 +1,4 @@ -/* $Id: newmenu.c,v 1.19 2003-03-17 07:59:11 btb Exp $ */ +/* $Id: newmenu.c,v 1.20 2003-06-06 19:04:27 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -664,8 +664,6 @@ grs_bitmap nm_background,nm_background_save; #define MESSAGEBOX_TEXT_SIZE 300 // How many characters in messagebox #define MAX_TEXT_WIDTH 200 // How many pixels wide a input box can be -extern void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest); - ubyte MenuReordering=0; ubyte SurfingNet=0; char Pauseable_menu=0; @@ -805,6 +803,7 @@ void nm_draw_background(int x1, int y1, int x2, int y2 ) x2 = x1 + w - 1; y2 = y1 + h - 1; +#if 0 { grs_bitmap *tmp = gr_create_bitmap(w, h); @@ -817,6 +816,13 @@ void nm_draw_background(int x1, int y1, int x2, int y2 ) gr_bm_bitblt(w, h, x1, y1, 0, 0, tmp, &(grd_curcanv->cv_bitmap) ); gr_free_bitmap(tmp); } +#else + WIN(DDGRLOCK(dd_grd_curcanv)); + if (No_darkening) + gr_bm_bitblt(w, h, x1, y1, LHX(10), LHY(10), &nm_background, &(grd_curcanv->cv_bitmap) ); + else + gr_bm_bitblt(w, h, x1, y1, 0, 0, &nm_background, &(grd_curcanv->cv_bitmap) ); +#endif if (!No_darkening) { Gr_scanline_darkening_level = 2*7; diff --git a/main/playsave.c b/main/playsave.c index 76973662..1877f090 100644 --- a/main/playsave.c +++ b/main/playsave.c @@ -1,4 +1,4 @@ -/* $Id: playsave.c,v 1.12 2003-04-12 00:11:46 btb Exp $ */ +/* $Id: playsave.c,v 1.13 2003-06-06 19:04:27 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -312,7 +312,7 @@ typedef struct hli { ubyte level_num; } hli; -int n_highest_levels; +short n_highest_levels; hli highest_levels[MAX_MISSIONS]; @@ -533,7 +533,8 @@ int read_player_file() #endif FILE *file; int errno_ret = EZERO; - int id,player_file_version,i; + int id, i; + short player_file_version; int rewrite_it=0; int swap = 0; -- 2.39.2