mudgangster

Tiny, scriptable MUD client
Log | Files | Refs | README

commit d763a3550a385b9c0c55c215613842e5019067a0
parent 33577cc2ae781b48b73a27381c2c5cef48ceac62
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun,  3 May 2020 01:03:59 +0300

Optimise rendering

Diffstat:
Msrc/input.cc | 4++++
Msrc/textbox.cc | 6+++++-
Msrc/ui.cc | 4++--
Msrc/win32.cc | 16++++++++++++----
4 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/input.cc b/src/input.cc @@ -7,6 +7,8 @@ #include "script.h" #include "ui.h" +#include "platform_ui.h" + static Span< char > history[ MAX_INPUT_HISTORY ] = { }; static size_t history_head = 0; static size_t history_count = 0; @@ -152,5 +154,7 @@ void input_draw() { } } + platform_make_dirty( left, top, width, height ); + dirty = false; } diff --git a/src/textbox.cc b/src/textbox.cc @@ -350,7 +350,9 @@ void textbox_draw( TextBox * tb ) { // bg // TODO: top/bottom spacing seems to be inconsistent here, try with large spacing - ui_fill_rect( tb->x + left, tb->y + top - top_spacing, fw, fh + bot_spacing, Colour( bg ), bold_bg ); + if( bg != BLACK ) { + ui_fill_rect( tb->x + left, tb->y + top - top_spacing, fw, fh + bot_spacing, Colour( bg ), bold_bg ); + } // fg ui_draw_char( tb->x + left, tb->y + top, glyph.ch, Colour( fg ), bold_fg, bold ); @@ -360,5 +362,7 @@ void textbox_draw( TextBox * tb ) { rows_drawn += line_rows; } + platform_make_dirty( tb->x, tb->y, tb->w, tb->h ); + tb->dirty = false; } diff --git a/src/ui.cc b/src/ui.cc @@ -36,7 +36,6 @@ void ui_term() { void ui_fill_rect( int left, int top, int width, int height, Colour colour, bool bold ) { platform_fill_rect( left, top, width, height, colour, bold ); - platform_make_dirty( left, top, width, height ); } void ui_draw_char( int left, int top, char c, Colour colour, bool bold, bool force_bold_font ) { @@ -197,7 +196,6 @@ void ui_draw_char( int left, int top, char c, Colour colour, bool bold, bool for } platform_draw_char( left, top, c, colour, bold, force_bold_font ); - platform_make_dirty( left, top, fw, line_height ); } void ui_clear_status() { @@ -236,6 +234,8 @@ void ui_draw_status() { ui_draw_char( x, y, sc.c, sc.fg, sc.bold ); } + platform_make_dirty( 0, window_height - PADDING * 4 - fh * 2, window_width, fh + PADDING * 2 ); + status_dirty = false; } diff --git a/src/win32.cc b/src/win32.cc @@ -149,6 +149,8 @@ static COLORREF get_colour( Colour colour, bool bold ) { } void platform_fill_rect( int left, int top, int width, int height, Colour colour, bool bold ) { + ZoneScoped; + // TODO: preallocate these HBRUSH brush = CreateSolidBrush( get_colour( colour, bold ) ); RECT r = { left, top, left + width, top + height }; @@ -157,12 +159,16 @@ void platform_fill_rect( int left, int top, int width, int height, Colour colour } void platform_draw_char( int left, int top, char c, Colour colour, bool bold, bool force_bold_font ) { + ZoneScoped; + SelectObject( UI.back_buffer, ( bold || force_bold_font ? Style.font.bold : Style.font.regular ) ); SetTextColor( UI.back_buffer, get_colour( colour, bold ) ); TextOutA( UI.back_buffer, left, top + SPACING, &c, 1 ); } void platform_make_dirty( int left, int top, int width, int height ) { + ZoneScoped; + RECT r = { left, top, left + width, top + height }; InvalidateRect( UI.hwnd, &r, FALSE ); } @@ -241,6 +247,8 @@ void platform_set_clipboard( const char * str, size_t len ) { } LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { + ZoneScoped; + switch( msg ) { case WM_CREATE: { UI.hdc = GetDC( hwnd ); @@ -531,10 +539,10 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin Style = { }; WNDCLASSEX wc = { }; - wc.cbSize = sizeof( WNDCLASSEX ); - wc.lpfnWndProc = WndProc; - wc.hInstance = hInstance; - wc.hCursor = LoadCursor( NULL, IDC_ARROW ); + wc.cbSize = sizeof( WNDCLASSEX ); + wc.lpfnWndProc = WndProc; + wc.hInstance = hInstance; + wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.lpszClassName = WINDOW_CLASSNAME; wc.hbrBackground = CreateSolidBrush( RGB( 0x1a, 0x1a, 0x1a ) );