mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-26 04:11:18 +00:00
Put some mutex on CONS_Printf etc. hahaha
This commit is contained in:
parent
e20dccafd4
commit
e950efa5fc
3 changed files with 164 additions and 6 deletions
153
src/console.c
153
src/console.c
|
@ -31,6 +31,7 @@
|
|||
#include "i_video.h"
|
||||
#include "z_zone.h"
|
||||
#include "i_system.h"
|
||||
#include "i_threads.h"
|
||||
#include "d_main.h"
|
||||
#include "m_menu.h"
|
||||
#include "filesrch.h"
|
||||
|
@ -45,6 +46,16 @@
|
|||
|
||||
#define MAXHUDLINES 20
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
I_mutex con_mutex;
|
||||
|
||||
# define Lock_state() I_lock_mutex(&con_mutex)
|
||||
# define Unlock_state() I_unlock_mutex(con_mutex)
|
||||
#else/*HAVE_THREADS*/
|
||||
# define Lock_state()
|
||||
# define Unlock_state()
|
||||
#endif/*HAVE_THREADS*/
|
||||
|
||||
static boolean con_started = false; // console has been initialised
|
||||
boolean con_startup = false; // true at game startup, screen need refreshing
|
||||
static boolean con_forcepic = true; // at startup toggle console translucency when first off
|
||||
|
@ -170,6 +181,8 @@ static void CONS_hudlines_Change(void)
|
|||
{
|
||||
INT32 i;
|
||||
|
||||
Lock_state();
|
||||
|
||||
// Clear the currently displayed lines
|
||||
for (i = 0; i < con_hudlines; i++)
|
||||
con_hudtime[i] = 0;
|
||||
|
@ -181,6 +194,8 @@ static void CONS_hudlines_Change(void)
|
|||
|
||||
con_hudlines = cons_hudlines.value;
|
||||
|
||||
Unlock_state();
|
||||
|
||||
CONS_Printf(M_GetText("Number of console HUD lines is now %d\n"), con_hudlines);
|
||||
}
|
||||
|
||||
|
@ -188,12 +203,16 @@ static void CONS_hudlines_Change(void)
|
|||
//
|
||||
static void CONS_Clear_f(void)
|
||||
{
|
||||
Lock_state();
|
||||
|
||||
memset(con_buffer, 0, CON_BUFFERSIZE);
|
||||
|
||||
con_cx = 0;
|
||||
con_cy = con_totallines-1;
|
||||
con_line = &con_buffer[con_cy*con_width];
|
||||
con_scrollup = 0;
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
// Choose english keymap
|
||||
|
@ -369,20 +388,29 @@ void CON_Init(void)
|
|||
for (i = 0; i < NUMINPUTS; i++)
|
||||
bindtable[i] = NULL;
|
||||
|
||||
Lock_state();
|
||||
|
||||
// clear all lines
|
||||
memset(con_buffer, 0, CON_BUFFERSIZE);
|
||||
|
||||
// make sure it is ready for the loading screen
|
||||
con_width = 0;
|
||||
|
||||
Unlock_state();
|
||||
|
||||
CON_RecalcSize();
|
||||
|
||||
CON_SetupColormaps();
|
||||
|
||||
Lock_state();
|
||||
|
||||
//note: CON_Ticker should always execute at least once before D_Display()
|
||||
con_clipviewtop = -1; // -1 does not clip
|
||||
|
||||
con_hudlines = atoi(cons_hudlines.defaultvalue);
|
||||
|
||||
Unlock_state();
|
||||
|
||||
// setup console input filtering
|
||||
CON_InputInit();
|
||||
|
||||
|
@ -391,15 +419,23 @@ void CON_Init(void)
|
|||
COM_AddCommand("cls", CONS_Clear_f);
|
||||
//COM_AddCommand("english", CONS_English_f);
|
||||
// set console full screen for game startup MAKE SURE VID_Init() done !!!
|
||||
Lock_state();
|
||||
|
||||
con_destlines = vid.height;
|
||||
con_curlines = vid.height;
|
||||
|
||||
Unlock_state();
|
||||
|
||||
if (!dedicated)
|
||||
{
|
||||
Lock_state();
|
||||
|
||||
con_started = true;
|
||||
con_startup = true; // need explicit screen refresh until we are in Doom loop
|
||||
consoletoggle = false;
|
||||
|
||||
Unlock_state();
|
||||
|
||||
CV_RegisterVar(&cons_msgtimeout);
|
||||
CV_RegisterVar(&cons_hudlines);
|
||||
CV_RegisterVar(&cons_speed);
|
||||
|
@ -411,19 +447,27 @@ void CON_Init(void)
|
|||
}
|
||||
else
|
||||
{
|
||||
Lock_state();
|
||||
|
||||
con_started = true;
|
||||
con_startup = false; // need explicit screen refresh until we are in Doom loop
|
||||
consoletoggle = true;
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
}
|
||||
// Console input initialization
|
||||
//
|
||||
static void CON_InputInit(void)
|
||||
{
|
||||
Lock_state();
|
||||
|
||||
// prepare the first prompt line
|
||||
memset(inputlines, 0, sizeof (inputlines));
|
||||
inputline = 0;
|
||||
input_cur = input_sel = input_len = 0;
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
@ -439,6 +483,8 @@ static void CON_RecalcSize(void)
|
|||
char *tmp_buffer;
|
||||
char *string;
|
||||
|
||||
Lock_state();
|
||||
|
||||
switch (cv_constextsize.value)
|
||||
{
|
||||
case V_NOSCALEPATCH:
|
||||
|
@ -476,11 +522,18 @@ static void CON_RecalcSize(void)
|
|||
|
||||
// check for change of video width
|
||||
if (conw == con_width)
|
||||
{
|
||||
Unlock_state();
|
||||
return; // didn't change
|
||||
}
|
||||
|
||||
Unlock_state();
|
||||
|
||||
tmp_buffer = Z_Malloc(CON_BUFFERSIZE, PU_STATIC, NULL);
|
||||
string = Z_Malloc(CON_BUFFERSIZE, PU_STATIC, NULL); // BP: it is a line but who know
|
||||
|
||||
Lock_state();
|
||||
|
||||
oldcon_width = con_width;
|
||||
oldnumlines = con_totallines;
|
||||
oldcon_cy = con_cy;
|
||||
|
@ -501,6 +554,8 @@ static void CON_RecalcSize(void)
|
|||
con_line = &con_buffer[con_cy*con_width];
|
||||
con_scrollup = 0;
|
||||
|
||||
Unlock_state();
|
||||
|
||||
// re-arrange console text buffer to keep text
|
||||
if (oldcon_width) // not the first time
|
||||
{
|
||||
|
@ -525,7 +580,11 @@ static void CON_RecalcSize(void)
|
|||
|
||||
static void CON_ChangeHeight(void)
|
||||
{
|
||||
INT32 minheight = 20 * con_scalefactor; // 20 = 8+8+4
|
||||
INT32 minheight;
|
||||
|
||||
Lock_state();
|
||||
|
||||
minheight = 20 * con_scalefactor; // 20 = 8+8+4
|
||||
|
||||
// toggle console in
|
||||
con_destlines = (cons_height.value*vid.height)/100;
|
||||
|
@ -535,13 +594,19 @@ static void CON_ChangeHeight(void)
|
|||
con_destlines = vid.height;
|
||||
|
||||
con_destlines &= ~0x3; // multiple of text row height
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
// Handles Console moves in/out of screen (per frame)
|
||||
//
|
||||
static void CON_MoveConsole(void)
|
||||
{
|
||||
const fixed_t conspeed = FixedDiv(cons_speed.value*vid.fdupy, FRACUNIT);
|
||||
fixed_t conspeed;
|
||||
|
||||
Lock_state();
|
||||
|
||||
conspeed = FixedDiv(cons_speed.value*vid.fdupy, FRACUNIT);
|
||||
|
||||
// instant
|
||||
if (!cons_speed.value)
|
||||
|
@ -563,6 +628,8 @@ static void CON_MoveConsole(void)
|
|||
if (con_curlines < con_destlines)
|
||||
con_curlines = con_destlines;
|
||||
}
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
INT32 CON_ShiftChar(INT32 ch)
|
||||
|
@ -587,27 +654,44 @@ void CON_ClearHUD(void)
|
|||
{
|
||||
INT32 i;
|
||||
|
||||
Lock_state();
|
||||
|
||||
for (i = 0; i < con_hudlines; i++)
|
||||
con_hudtime[i] = 0;
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
// Force console to move out immediately
|
||||
// note: con_ticker will set consoleready false
|
||||
void CON_ToggleOff(void)
|
||||
{
|
||||
Lock_state();
|
||||
|
||||
if (!con_destlines)
|
||||
{
|
||||
Unlock_state();
|
||||
return;
|
||||
}
|
||||
|
||||
con_destlines = 0;
|
||||
con_curlines = 0;
|
||||
CON_ClearHUD();
|
||||
con_forcepic = 0;
|
||||
con_clipviewtop = -1; // remove console clipping of view
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
boolean CON_Ready(void)
|
||||
{
|
||||
return consoleready;
|
||||
boolean ready;
|
||||
Lock_state();
|
||||
{
|
||||
ready = consoleready;
|
||||
}
|
||||
Unlock_state();
|
||||
return ready;
|
||||
}
|
||||
|
||||
// Console ticker: handles console move in/out, cursor blinking
|
||||
|
@ -615,7 +699,11 @@ boolean CON_Ready(void)
|
|||
void CON_Ticker(void)
|
||||
{
|
||||
INT32 i;
|
||||
INT32 minheight = 20 * con_scalefactor; // 20 = 8+8+4
|
||||
INT32 minheight;
|
||||
|
||||
Lock_state();
|
||||
|
||||
minheight = 20 * con_scalefactor; // 20 = 8+8+4
|
||||
|
||||
// cursor blinking
|
||||
con_tick++;
|
||||
|
@ -673,6 +761,8 @@ void CON_Ticker(void)
|
|||
if (con_hudtime[i] < 0)
|
||||
con_hudtime[i] = 0;
|
||||
}
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -684,32 +774,51 @@ void CON_Ticker(void)
|
|||
|
||||
static void CON_InputClear(void)
|
||||
{
|
||||
Lock_state();
|
||||
|
||||
memset(inputlines[inputline], 0, CON_MAXPROMPTCHARS);
|
||||
input_cur = input_sel = input_len = 0;
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
static void CON_InputSetString(const char *c)
|
||||
{
|
||||
Lock_state();
|
||||
|
||||
memset(inputlines[inputline], 0, CON_MAXPROMPTCHARS);
|
||||
strcpy(inputlines[inputline], c);
|
||||
input_cur = input_sel = input_len = strlen(c);
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
static void CON_InputAddString(const char *c)
|
||||
{
|
||||
size_t csize = strlen(c);
|
||||
|
||||
Lock_state();
|
||||
|
||||
if (input_len + csize > CON_MAXPROMPTCHARS-1)
|
||||
{
|
||||
Unlock_state();
|
||||
return;
|
||||
}
|
||||
if (input_cur != input_len)
|
||||
memmove(&inputlines[inputline][input_cur+csize], &inputlines[inputline][input_cur], input_len-input_cur);
|
||||
memcpy(&inputlines[inputline][input_cur], c, csize);
|
||||
input_len += csize;
|
||||
input_sel = (input_cur += csize);
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
static void CON_InputDelSelection(void)
|
||||
{
|
||||
size_t start, end, len;
|
||||
|
||||
Lock_state();
|
||||
|
||||
if (input_cur > input_sel)
|
||||
{
|
||||
start = input_sel;
|
||||
|
@ -728,27 +837,39 @@ static void CON_InputDelSelection(void)
|
|||
|
||||
input_len -= len;
|
||||
input_sel = input_cur = start;
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
static void CON_InputAddChar(char c)
|
||||
{
|
||||
if (input_len >= CON_MAXPROMPTCHARS-1)
|
||||
return;
|
||||
|
||||
Lock_state();
|
||||
|
||||
if (input_cur != input_len)
|
||||
memmove(&inputlines[inputline][input_cur+1], &inputlines[inputline][input_cur], input_len-input_cur);
|
||||
inputlines[inputline][input_cur++] = c;
|
||||
inputlines[inputline][++input_len] = 0;
|
||||
input_sel = input_cur;
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
static void CON_InputDelChar(void)
|
||||
{
|
||||
if (!input_cur)
|
||||
return;
|
||||
|
||||
Lock_state();
|
||||
|
||||
if (input_cur != input_len)
|
||||
memmove(&inputlines[inputline][input_cur-1], &inputlines[inputline][input_cur], input_len-input_cur);
|
||||
inputlines[inputline][--input_len] = 0;
|
||||
input_sel = --input_cur;
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -1174,6 +1295,8 @@ static void CON_Print(char *msg)
|
|||
S_StartSound(NULL, sfx_radio);
|
||||
}
|
||||
|
||||
Lock_state();
|
||||
|
||||
if (!(*msg & 0x80))
|
||||
{
|
||||
con_line[con_cx++] = '\x80';
|
||||
|
@ -1234,7 +1357,12 @@ static void CON_Print(char *msg)
|
|||
}
|
||||
|
||||
if (*msg == '\0')
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(con_mutex);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// printable character
|
||||
for (l = 0; l < (con_width-11) && msg[l] > ' '; l++)
|
||||
|
@ -1252,6 +1380,8 @@ static void CON_Print(char *msg)
|
|||
for (; l > 0; l--)
|
||||
con_line[con_cx++] = *(msg++);
|
||||
}
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
||||
void CON_LogMessage(const char *msg)
|
||||
|
@ -1283,6 +1413,7 @@ void CONS_Printf(const char *fmt, ...)
|
|||
{
|
||||
va_list argptr;
|
||||
static char *txt = NULL;
|
||||
boolean startup;
|
||||
|
||||
if (txt == NULL)
|
||||
txt = malloc(8192);
|
||||
|
@ -1315,11 +1446,16 @@ void CONS_Printf(const char *fmt, ...)
|
|||
CON_LogMessage(txt);
|
||||
#endif
|
||||
|
||||
Lock_state();
|
||||
|
||||
// make sure new text is visible
|
||||
con_scrollup = 0;
|
||||
startup = con_startup;
|
||||
|
||||
Unlock_state();
|
||||
|
||||
// if not in display loop, force screen update
|
||||
if (con_startup)
|
||||
if (startup)
|
||||
{
|
||||
#if (defined (_WINDOWS)) || (defined (__OS2__) && !defined (HAVE_SDL))
|
||||
patch_t *con_backpic = W_CachePatchName("KARTKREW", PU_CACHE);
|
||||
|
@ -1633,8 +1769,13 @@ static void CON_DrawConsole(void)
|
|||
//
|
||||
void CON_Drawer(void)
|
||||
{
|
||||
Lock_state();
|
||||
|
||||
if (!con_started || !graphics_started)
|
||||
{
|
||||
Unlock_state();
|
||||
return;
|
||||
}
|
||||
|
||||
if (con_recalc)
|
||||
CON_RecalcSize();
|
||||
|
@ -1644,4 +1785,6 @@ void CON_Drawer(void)
|
|||
else if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_CUTSCENE || gamestate == GS_CREDITS
|
||||
|| gamestate == GS_VOTING || gamestate == GS_EVALUATION || gamestate == GS_WAITINGPLAYERS)
|
||||
CON_DrawHudlines();
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include "d_event.h"
|
||||
#include "command.h"
|
||||
#include "i_threads.h"
|
||||
|
||||
#ifdef _WII
|
||||
void CON_InitWii(void);
|
||||
|
@ -21,6 +22,10 @@ void CON_Init(void);
|
|||
|
||||
boolean CON_Responder(event_t *ev);
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
extern I_mutex con_mutex;
|
||||
#endif
|
||||
|
||||
// set true when screen size has changed, to adapt console
|
||||
extern boolean con_recalc;
|
||||
|
||||
|
|
12
src/d_main.c
12
src/d_main.c
|
@ -266,7 +266,17 @@ void D_ProcessEvents(void)
|
|||
continue; // menu ate the event
|
||||
|
||||
// console input
|
||||
if (CON_Responder(ev))
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&con_mutex);
|
||||
#endif
|
||||
{
|
||||
eaten = CON_Responder(ev);
|
||||
}
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(con_mutex);
|
||||
#endif
|
||||
|
||||
if (eaten)
|
||||
continue; // ate the event
|
||||
|
||||
G_Responder(ev);
|
||||
|
|
Loading…
Reference in a new issue