diff --git a/src/engine/screen.cpp b/src/engine/screen.cpp index 6e0a01f93..451f38773 100644 --- a/src/engine/screen.cpp +++ b/src/engine/screen.cpp @@ -1603,10 +1603,15 @@ namespace fheroes2 void Display::release() { - _engine->clear(); + _preprocessing = nullptr; + _postprocessing = nullptr; + _cursor.reset(); + _engine->clear(); + _engine.reset(); clear(); + _renderSurface = nullptr; _prevRoi = {}; } diff --git a/src/fheroes2/game/fheroes2.cpp b/src/fheroes2/game/fheroes2.cpp index 062cc6fad..d3e4b4459 100644 --- a/src/fheroes2/game/fheroes2.cpp +++ b/src/fheroes2/game/fheroes2.cpp @@ -40,10 +40,7 @@ #pragma GCC diagnostic ignored "-Wswitch-default" #endif -#include -#include #include // IWYU pragma: keep -#include // Managing compiler warnings for SDL headers #if defined( __GNUC__ ) @@ -154,11 +151,9 @@ namespace fheroes2::engine().setTitle( GetCaption() ); - // Hide system cursor. - const int returnValue = SDL_ShowCursor( SDL_DISABLE ); - if ( returnValue < 0 ) { - ERROR_LOG( "Failed to hide system cursor. Error description: " << SDL_GetError() ) - } + auto & cursor = fheroes2::cursor(); + cursor.enableSoftwareEmulation( conf.isSoftwareEmulationEnabled() ); + cursor.show( false ); fheroes2::RenderProcessor & renderProcessor = fheroes2::RenderProcessor::instance(); @@ -173,7 +168,7 @@ namespace renderProcessor.startColorCycling(); // Update mouse cursor when switching between software emulation and OS mouse modes. - fheroes2::cursor().registerUpdater( Cursor::Refresh ); + cursor.registerUpdater( Cursor::Refresh ); #if !defined( MACOS_APP_BUNDLE ) const fheroes2::Image & appIcon = Compression::CreateImageFromZlib( 32, 32, iconImage, sizeof( iconImage ), true ); @@ -187,10 +182,7 @@ namespace ~DisplayInitializer() { fheroes2::RenderProcessor::instance().unregisterRenderers(); - - fheroes2::Display & display = fheroes2::Display::instance(); - display.subscribe( {}, {} ); - display.release(); + fheroes2::Display::instance().release(); } private: @@ -266,7 +258,7 @@ int main( int argc, char ** argv ) const System::CoreInitializer coreInitializer; - DEBUG_LOG( DBG_GAME, DBG_INFO, conf.String() ) + DEBUG_LOG( DBG_GAME, DBG_INFO, conf.getOptionsString() ) const DisplayInitializer displayInitializer; const DataInitializer dataInitializer; diff --git a/src/fheroes2/system/settings.cpp b/src/fheroes2/system/settings.cpp index f82c9eb15..2e4b3f40e 100644 --- a/src/fheroes2/system/settings.cpp +++ b/src/fheroes2/system/settings.cpp @@ -358,11 +358,9 @@ bool Settings::Read( const std::string & filePath ) if ( config.Exists( "cursor soft rendering" ) ) { if ( config.StrParams( "cursor soft rendering" ) == "on" ) { _gameOptions.SetModes( GAME_CURSOR_SOFT_EMULATION ); - fheroes2::cursor().enableSoftwareEmulation( true ); } else { _gameOptions.ResetModes( GAME_CURSOR_SOFT_EMULATION ); - fheroes2::cursor().enableSoftwareEmulation( false ); } } @@ -401,14 +399,14 @@ bool Settings::Save( const std::string_view fileName ) const return false; } - const std::string data = String(); + const std::string data = getOptionsString(); fileStream.putRaw( data.data(), data.size() ); return true; } -std::string Settings::String() const +std::string Settings::getOptionsString() const { std::ostringstream os; @@ -1026,6 +1024,11 @@ bool Settings::isBattleMovementAreaHighlightEnabled() const return _gameOptions.Modes( GAME_BATTLE_HIGHLIGHT_MOVEMENT_AREA ); } +bool Settings::isSoftwareEmulationEnabled() const +{ + return _gameOptions.Modes( GAME_CURSOR_SOFT_EMULATION ); +} + void Settings::switchToNextInterfaceType() { switch ( _interfaceType ) { diff --git a/src/fheroes2/system/settings.h b/src/fheroes2/system/settings.h index 9fddcc864..b42a0e05b 100644 --- a/src/fheroes2/system/settings.h +++ b/src/fheroes2/system/settings.h @@ -102,7 +102,7 @@ public: bool Read( const std::string & filePath ); bool Save( const std::string_view fileName ) const; - std::string String() const; + std::string getOptionsString() const; void setCurrentMapInfo( Maps::FileInfo fi ); @@ -219,6 +219,7 @@ public: bool isScreenScalingTypeNearest() const; bool isEvilInterfaceEnabled() const; bool isBattleMovementAreaHighlightEnabled() const; + bool isSoftwareEmulationEnabled() const; void setInterfaceType( const InterfaceType type ) {