Skip to content

Instantly share code, notes, and snippets.

@zturtleman
Last active August 29, 2015 14:03
Show Gist options
  • Save zturtleman/1a16197add4e4234432e to your computer and use it in GitHub Desktop.
Save zturtleman/1a16197add4e4234432e to your computer and use it in GitHub Desktop.
ioq3 dynamic client console width / reflow client console buffer (WIP)
diff --git a/code/client/cl_console.c b/code/client/cl_console.c
index a3d4d32..08ede9a 100644
--- a/code/client/cl_console.c
+++ b/code/client/cl_console.c
@@ -29,7 +29,7 @@ int g_console_field_width = 78;
#define NUM_CON_TIMES 4
-#define CON_TEXTSIZE 32768
+#define CON_TEXTSIZE (32768*2)
typedef struct {
qboolean initialized;
@@ -270,10 +270,11 @@ If the line width has changed, reformat the buffer.
*/
void Con_CheckResize (void)
{
- int i, j, width, oldwidth, oldtotallines, numlines, numchars;
- short tbuf[CON_TEXTSIZE];
+ int i, width;
+ char consoleBuffer[1024];
+ unsigned int size;
- width = (SCREEN_WIDTH / SMALLCHAR_WIDTH) - 2;
+ width = (cls.glconfig.vidWidth / SMALLCHAR_WIDTH) - 2;
if (width == con.linewidth)
return;
@@ -283,47 +284,37 @@ void Con_CheckResize (void)
width = DEFAULT_CONSOLE_WIDTH;
con.linewidth = width;
con.totallines = CON_TEXTSIZE / con.linewidth;
+ con.current = con.totallines - 1;
+ con.display = con.current;
for(i=0; i<CON_TEXTSIZE; i++)
con.text[i] = (ColorIndex(COLOR_WHITE)<<8) | ' ';
}
else
{
- oldwidth = con.linewidth;
con.linewidth = width;
- oldtotallines = con.totallines;
con.totallines = CON_TEXTSIZE / con.linewidth;
- numlines = oldtotallines;
-
- if (con.totallines < numlines)
- numlines = con.totallines;
-
- numchars = oldwidth;
-
- if (con.linewidth < numchars)
- numchars = con.linewidth;
+ con.current = con.totallines - 1;
+ con.display = con.current;
- Com_Memcpy (tbuf, con.text, CON_TEXTSIZE * sizeof(short));
for(i=0; i<CON_TEXTSIZE; i++)
con.text[i] = (ColorIndex(COLOR_WHITE)<<8) | ' ';
- for (i=0 ; i<numlines ; i++)
+ CON_LogSaveReadPos();
+
+ // rewrap the console text
+ while ( ( size = CON_LogRead( consoleBuffer, sizeof (consoleBuffer)-1 ) ) > 0 )
{
- for (j=0 ; j<numchars ; j++)
- {
- con.text[(con.totallines - 1 - i) * con.linewidth + j] =
- tbuf[((con.current - i + oldtotallines) %
- oldtotallines) * oldwidth + j];
- }
+ consoleBuffer[size] = '\0';
+ CL_ConsolePrint( consoleBuffer );
}
+ CON_LogRestoreReadPos();
+
Con_ClearNotify ();
}
-
- con.current = con.totallines - 1;
- con.display = con.current;
}
/*
@@ -440,13 +431,13 @@ void CL_ConsolePrint( char *txt ) {
}
if (!con.initialized) {
+ con.initialized = qtrue;
con.color[0] =
con.color[1] =
con.color[2] =
con.color[3] = 1.0f;
con.linewidth = -1;
Con_CheckResize ();
- con.initialized = qtrue;
}
color = ColorIndex(COLOR_WHITE);
diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h
index 414b341..de5801d 100644
--- a/code/qcommon/qcommon.h
+++ b/code/qcommon/qcommon.h
@@ -1138,6 +1138,19 @@ dialogResult_t Sys_Dialog( dialogType_t type, const char *message, const char *t
qboolean Sys_WritePIDFile( void );
+/*
+==============================================================
+
+CONSOLE LOG ACCESS
+
+==============================================================
+*/
+
+unsigned int CON_LogRead( char *out, unsigned int outSize );
+void CON_LogSaveReadPos( void );
+void CON_LogRestoreReadPos( void );
+
+
/* This is based on the Adaptive Huffman algorithm described in Sayood's Data
* Compression book. The ranks are not actually stored, but implicitly defined
* by the location of a node within a doubly-linked list */
diff --git a/code/renderergl1/tr_cmds.c b/code/renderergl1/tr_cmds.c
index 00b819a..4eacb76 100644
--- a/code/renderergl1/tr_cmds.c
+++ b/code/renderergl1/tr_cmds.c
@@ -456,7 +456,11 @@ void RE_EndFrame( int *frontEndMsec, int *backEndMsec ) {
}
cmd = R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd ) {
- return;
+ R_IssuePendingRenderCommands();
+ cmd = R_GetCommandBuffer( sizeof( *cmd ) );
+ if ( !cmd ) {
+ return;
+ }
}
cmd->commandId = RC_SWAP_BUFFERS;
diff --git a/code/renderergl1/tr_local.h b/code/renderergl1/tr_local.h
index 66c13d4..1793abb 100644
--- a/code/renderergl1/tr_local.h
+++ b/code/renderergl1/tr_local.h
@@ -1458,7 +1458,7 @@ RENDERER BACK END COMMAND QUEUE
=============================================================
*/
-#define MAX_RENDER_COMMANDS 0x40000
+#define MAX_RENDER_COMMANDS 0x60000
typedef struct {
byte cmds[MAX_RENDER_COMMANDS];
diff --git a/code/renderergl2/tr_cmds.c b/code/renderergl2/tr_cmds.c
index 139a343..0aee7a3 100644
--- a/code/renderergl2/tr_cmds.c
+++ b/code/renderergl2/tr_cmds.c
@@ -528,7 +528,11 @@ void RE_EndFrame( int *frontEndMsec, int *backEndMsec ) {
}
cmd = R_GetCommandBuffer( sizeof( *cmd ) );
if ( !cmd ) {
- return;
+ R_IssuePendingRenderCommands();
+ cmd = R_GetCommandBuffer( sizeof( *cmd ) );
+ if ( !cmd ) {
+ return;
+ }
}
cmd->commandId = RC_SWAP_BUFFERS;
diff --git a/code/renderergl2/tr_local.h b/code/renderergl2/tr_local.h
index 7bfa876..63b21d1 100644
--- a/code/renderergl2/tr_local.h
+++ b/code/renderergl2/tr_local.h
@@ -2346,7 +2346,7 @@ RENDERER BACK END COMMAND QUEUE
=============================================================
*/
-#define MAX_RENDER_COMMANDS 0x40000
+#define MAX_RENDER_COMMANDS 0x60000
typedef struct {
byte cmds[MAX_RENDER_COMMANDS];
diff --git a/code/sys/con_log.c b/code/sys/con_log.c
index c3a4a5b..f040f29 100644
--- a/code/sys/con_log.c
+++ b/code/sys/con_log.c
@@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
static char consoleLog[ MAX_LOG ];
static unsigned int writePos = 0;
static unsigned int readPos = 0;
+static unsigned int savedReadPos = 0;
/*
==================
@@ -127,3 +128,23 @@ unsigned int CON_LogRead( char *out, unsigned int outSize )
return outSize;
}
+
+/*
+==================
+CON_LogSaveReadPos
+==================
+*/
+void CON_LogSaveReadPos( void )
+{
+ savedReadPos = readPos;
+}
+
+/*
+==================
+CON_LogRestoreReadPos
+==================
+*/
+void CON_LogRestoreReadPos( void )
+{
+ readPos = savedReadPos;
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment