From 8d35484a205ee22c86ef4c64445bb173c5e7a1bc Mon Sep 17 00:00:00 2001 From: OmniaX Date: Sun, 15 Sep 2024 08:55:06 +0200 Subject: [PATCH] Changed screen redraw rate. HUGE performance improvement --- build.nr | 2 +- extra/config/testMachine.dvm | 2 +- extra/dragon/cmos.dr | Bin 128 -> 128 bytes src/gui/RawTextRenderer.cpp | 16 ++++++++-------- src/gui/Renderer.cpp | 9 +++------ src/hardware/VirtualDisplay.cpp | 6 +++++- src/hardware/VirtualDisplay.hpp | 4 ++++ src/runtime/DragonRuntime.cpp | 7 +++++++ 8 files changed, 29 insertions(+), 17 deletions(-) diff --git a/build.nr b/build.nr index 6e2eace..9851ace 100644 --- a/build.nr +++ b/build.nr @@ -1 +1 @@ -1613 +1614 diff --git a/extra/config/testMachine.dvm b/extra/config/testMachine.dvm index 877a95b..59a1e9a 100644 --- a/extra/config/testMachine.dvm +++ b/extra/config/testMachine.dvm @@ -4,7 +4,7 @@ CMOS = dragon/cmos.dr cpuext = extmov, extalu fixed_clock = false -clock_rate_sec = 644 +clock_rate_sec = 2000 memory_extension_pages = 16 SingleColor_foreground = #009900FF diff --git a/extra/dragon/cmos.dr b/extra/dragon/cmos.dr index 85b346b3e721d290328b7a371b411108501a56c5..229d29c8f8ace132654b867c3d00654c97d9810d 100644 GIT binary patch literal 128 RcmWf4`2U~%0>eN7MgWZ|11(parent.getWindowWidth() * parent.getWindowHeight()); - m_texture = SDL_CreateTexture(parent.getSDLRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, parent.getWindowWidth(), parent.getWindowHeight()); + m_texture = SDL_CreateTexture(parent.getSDLRenderer(), SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, parent.getWindowWidth(), parent.getWindowHeight()); m_windowWidth = parent.getWindowWidth(); m_windowHeight = parent.getWindowHeight(); setTypeName("dragon::Renderer"); @@ -34,7 +34,7 @@ namespace dragon { m_pixels = ostd::Utils::resizeArray(m_pixels, m_parent->getWindowWidth() * m_parent->getWindowHeight()); SDL_DestroyTexture(m_texture); - m_texture = SDL_CreateTexture(m_parent->getSDLRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, m_parent->getWindowWidth(), m_parent->getWindowHeight()); + m_texture = SDL_CreateTexture(m_parent->getSDLRenderer(), SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, m_parent->getWindowWidth(), m_parent->getWindowHeight()); m_windowWidth = m_parent->getWindowWidth(); m_windowHeight = m_parent->getWindowHeight(); updateBuffer(); @@ -45,10 +45,7 @@ namespace dragon void Renderer::updateBuffer(void) { if (isInvalid()) return; - ostd::Timer timer; - timer.start(true, "DISPLAY_PROFILER", ostd::eTimeUnits::Milliseconds); SDL_UpdateTexture(m_texture, NULL, m_pixels, m_windowWidth * 4); - timer.end(true); } void Renderer::displayBuffer(void) @@ -66,7 +63,7 @@ namespace dragon for (uint32_t x = 0; x < m_windowWidth; x++) { int32_t index = CONVERT_2D_1D(x, y, m_windowWidth); - m_pixels[index] = color.asInteger(); + m_pixels[index] = color.asInteger(ostd::Color::eColorFormat::ARGB); } } } diff --git a/src/hardware/VirtualDisplay.cpp b/src/hardware/VirtualDisplay.cpp index 6f6abac..3ae9e6d 100644 --- a/src/hardware/VirtualDisplay.cpp +++ b/src/hardware/VirtualDisplay.cpp @@ -71,7 +71,11 @@ namespace dragon } } - m_renderer.updateBuffer(); + if (m_redrawScreen) + { + m_renderer.updateBuffer(); + m_redrawScreen = false; + } m_renderer.displayBuffer(); } diff --git a/src/hardware/VirtualDisplay.hpp b/src/hardware/VirtualDisplay.hpp index 7c38b04..07a8fd4 100644 --- a/src/hardware/VirtualDisplay.hpp +++ b/src/hardware/VirtualDisplay.hpp @@ -57,6 +57,8 @@ namespace dragon void onFixedUpdate(void) override; void onSlowUpdate(void) override; + inline void redrawScreen(void) { m_redrawScreen = true; } + private: void single_text_add_char_to_line(char c); void single_text_add_char_to_buffer(char c); @@ -80,6 +82,8 @@ namespace dragon std::vector m_text16_palettes; data::IBiosVideoPalette* m_text16_Currentpalette { nullptr }; uint8_t m_currentPaletteID { 0 }; + + bool m_redrawScreen { true }; }; } } \ No newline at end of file diff --git a/src/runtime/DragonRuntime.cpp b/src/runtime/DragonRuntime.cpp index f1c9fce..e0d231f 100644 --- a/src/runtime/DragonRuntime.cpp +++ b/src/runtime/DragonRuntime.cpp @@ -346,6 +346,7 @@ namespace dragon { double clock_speed_us = 1000000.0 / machine_config.clock_rate_sec; double acc = 0; + double acc2 = 0; uint64_t avg_count = 0; uint64_t _time = 0; double avg_tot = 0; @@ -377,8 +378,14 @@ namespace dragon // out.fg(ostd::ConsoleColors::Red).p(s_avgInstTime).nl().reset(); acc = 0; } + if (acc2 == 100) + { + vDisplay.redrawScreen(); + acc2 = 0; + } _time = clock_timer.endCount(); acc++; + acc2++; if (_time < clock_speed_us && fixed_clock) ostd::Utils::sleep(clock_speed_us - _time, ostd::eTimeUnits::Microseconds); }