From 3ab12e75c1ae32ad667a94ec66389aeccc4df095 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Fri, 12 Dec 2014 00:08:43 -0800 Subject: [PATCH] preallocate the console --- include/console.h | 6 +++--- main/console.c | 24 ++++++------------------ 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/include/console.h b/include/console.h index 6bcb7b42..4c0df096 100644 --- a/include/console.h +++ b/include/console.h @@ -58,7 +58,7 @@ enum { CON_OPEN //! The console is open and visible }; -/*! This is a struct for each consoles data */ +/*! This is a struct for the console's 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 RaiseOffset; //! Offset used when scrolling in the console @@ -101,8 +101,8 @@ void CON_Hide(void); int CON_isVisible(void); /*! Draws the console to the screen if it isVisible()*/ void CON_DrawConsole(void); -/*! Initializes a new console */ -ConsoleInformation *CON_Init(grs_font *Font, grs_screen *DisplayScreen, int lines, int x, int y, int w, int h); +/*! Initializes the console */ +void CON_Init(grs_font *Font, grs_screen *DisplayScreen, int lines, int x, int y, int w, int h); /*! printf for the console */ void CON_Out(const char *str, ...); /*! Changes the size of the console */ diff --git a/main/console.c b/main/console.c index c34073d6..f5728bb4 100644 --- a/main/console.c +++ b/main/console.c @@ -29,10 +29,9 @@ #define get_msecs() approx_fsec_to_msec(timer_get_approx_seconds()) -static ConsoleInformation *Console; - -/* Pointer to our one console */ -static ConsoleInformation *console; +/* our one console */ +static ConsoleInformation Console; +#define console (&Console) /* Internals */ void CON_UpdateOffset(void); @@ -462,17 +461,11 @@ void CON_DrawConsole(void) { /* Initializes the console */ -ConsoleInformation *CON_Init(grs_font *Font, grs_screen *DisplayScreen, int lines, int x, int y, int w, int h) +void CON_Init(grs_font *Font, grs_screen *DisplayScreen, int lines, int x, int y, int w, int h) { int loop; - ConsoleInformation *newinfo; - + ConsoleInformation *newinfo = console; - /* Create a new console struct and init it. */ - 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->RaiseOffset = 0; newinfo->ConsoleLines = NULL; @@ -545,8 +538,6 @@ ConsoleInformation *CON_Init(grs_font *Font, grs_screen *DisplayScreen, int line CON_Out("Console initialised."); CON_NewLineConsole(); - - return newinfo; } /* Makes the console visible */ @@ -596,8 +587,6 @@ void CON_Free(void) { gr_free_bitmap(console->InputBackground); console->InputBackground = NULL; - - d_free(console); } @@ -1128,8 +1117,7 @@ void con_init(void) fake_font.ft_w = 5; fake_font.ft_h = 5; - Console = CON_Init(&fake_font, &fake_screen, CON_NUM_LINES, 0, 0, 320, 200); - console = Console; + CON_Init(&fake_font, &fake_screen, CON_NUM_LINES, 0, 0, 320, 200); cmd_init(); -- 2.39.2