commit bb58219652d7dc73ad24f2920d6623f216598339
parent b4eab5af3aaec8118546802632e50215944ed4e7
Author: Michael Savage <mikejsavage@gmail.com>
Date: Fri, 7 Sep 2018 14:22:06 +0300
Defer textbox redrawing
Diffstat:
7 files changed, 18 insertions(+), 37 deletions(-)
diff --git a/src/lua/handlers.lua b/src/lua/handlers.lua
@@ -139,9 +139,6 @@ local function handleChat( message )
end
end
- mud.drawMain()
- mud.drawChat()
-
action.doChatActions( noAnsi )
action.doChatAnsiActions( message )
@@ -219,8 +216,6 @@ local function handleData( data )
action.doAnsiActions( clean )
end
- mud.drawMain()
-
dataBuffer = ""
receiving = false
end
@@ -255,7 +250,6 @@ local function handleCommand( input, hide )
end
mud.send( input .. "\n" )
- mud.drawMain()
end
end
diff --git a/src/lua/main.lua b/src/lua/main.lua
@@ -12,8 +12,7 @@ require( "event" )
local script = require( "script" )
local handlers = require( "handlers" )
-local printMain, newlineMain, drawMain,
- printChat, newlineChat, drawChat,
+local printMain, newlineMain, printChat, newlineChat,
setHandlers, urgent, setStatus,
sock_connect, sock_send, sock_close,
get_time, set_font = ...
@@ -31,11 +30,8 @@ require( "chat" ).init( handlers.chat )
mud.printMain = printMain
mud.newlineMain = newlineMain
-mud.drawMain = drawMain
-
mud.printChat = printChat
mud.newlineChat = newlineChat
-mud.drawChat = drawChat
mud.urgent = urgent
mud.now = get_time
diff --git a/src/lua/utils.lua b/src/lua/utils.lua
@@ -141,14 +141,6 @@ local function genericPrint( message, main, chat )
end
end
end
-
- if main then
- mud.drawMain()
- end
-
- if chat then
- mud.drawChat()
- end
end
function mud.print( form, ... )
@@ -175,8 +167,6 @@ function mud.printr( str, fg, bg, bold )
mud.newlineMain()
end
end
-
- mud.drawMain()
end
function mud.enable( ... )
diff --git a/src/script.cc b/src/script.cc
@@ -151,11 +151,6 @@ extern "C" int mud_newlineMain( lua_State * L ) {
return 0;
}
-extern "C" int mud_drawMain( lua_State * L ) {
- ui_main_draw();
- return 0;
-}
-
extern "C" int mud_printChat( lua_State * L ) {
generic_print( ui_chat_print, L );
return 0;
@@ -166,11 +161,6 @@ extern "C" int mud_newlineChat( lua_State * L ) {
return 0;
}
-extern "C" int mud_drawChat( lua_State * L ) {
- ui_chat_draw();
- return 0;
-}
-
extern "C" int mud_setStatus( lua_State * L ) {
luaL_argcheck( L, lua_type( L, 1 ) == LUA_TTABLE, 1, "expected function" );
@@ -274,11 +264,8 @@ void script_init() {
lua_pushcfunction( lua, mud_printMain );
lua_pushcfunction( lua, mud_newlineMain );
- lua_pushcfunction( lua, mud_drawMain );
-
lua_pushcfunction( lua, mud_printChat );
lua_pushcfunction( lua, mud_newlineChat );
- lua_pushcfunction( lua, mud_drawChat );
lua_pushcfunction( lua, mud_setHandlers );
@@ -294,7 +281,7 @@ void script_init() {
lua_pushcfunction( lua, mud_set_font );
- pcall( 14, "Error running main.lua" );
+ pcall( 12, "Error running main.lua" );
}
void script_term() {
diff --git a/src/textbox.cc b/src/textbox.cc
@@ -49,6 +49,7 @@ void textbox_add( TextBox * tb, const char * str, size_t len, Colour fg, Colour
};
line->len += n;
+ tb->dirty = true;
}
void textbox_newline( TextBox * tb ) {
@@ -62,6 +63,8 @@ void textbox_newline( TextBox * tb ) {
tb->head++;
TextBox::Line * line = &tb->lines[ ( tb->head + tb->num_lines ) % tb->max_lines ];
line->len = 0;
+
+ tb->dirty = true;
}
void textbox_scroll( TextBox * tb, int offset ) {
@@ -71,6 +74,8 @@ void textbox_scroll( TextBox * tb, int offset ) {
else {
tb->scroll_offset = min( tb->scroll_offset + offset, tb->num_lines - 1 );
}
+
+ tb->dirty = true;
}
static size_t num_rows( size_t h ) {
@@ -128,7 +133,7 @@ static bool inside_selection( int col, int row, int start_col, int start_row, in
return false;
}
-void textbox_draw( const TextBox * tb ) {
+void textbox_draw( TextBox * tb ) {
if( tb->w == 0 || tb->h == 0 )
return;
@@ -192,4 +197,6 @@ void textbox_draw( const TextBox * tb ) {
lines_drawn++;
rows_drawn += line_rows;
}
+
+ tb->dirty = false;
}
diff --git a/src/textbox.h b/src/textbox.h
@@ -28,6 +28,8 @@ struct TextBox {
bool selecting;
int selection_start_col, selection_start_row;
int selection_end_col, selection_end_row;
+
+ bool dirty;
};
void textbox_init( TextBox * tb, size_t scrollback );
@@ -42,6 +44,6 @@ void textbox_page_up( TextBox * tb );
void textbox_set_pos( TextBox * tb, int x, int y );
void textbox_set_size( TextBox * tb, int w, int h );
-void textbox_draw( const TextBox * tb );
+void textbox_draw( TextBox * tb );
void textbox_destroy( TextBox * tb );
diff --git a/src/x11.cc b/src/x11.cc
@@ -744,6 +744,11 @@ void ui_handleXEvents() {
}
}
+ if( UI.main_text.dirty )
+ textbox_draw( &UI.main_text );
+ if( UI.chat_text.dirty )
+ textbox_draw( &UI.chat_text );
+
if( UI.dirty ) {
XCopyArea( UI.display, UI.back_buffer, UI.window, UI.gc, UI.dirty_left, UI.dirty_top, UI.dirty_right - UI.dirty_left, UI.dirty_bottom - UI.dirty_top, UI.dirty_left, UI.dirty_top );
UI.dirty = false;