diff --git a/include/eepp/ui/models/filesystemmodel.hpp b/include/eepp/ui/models/filesystemmodel.hpp index f7605375a..cfc9f93fa 100644 --- a/include/eepp/ui/models/filesystemmodel.hpp +++ b/include/eepp/ui/models/filesystemmodel.hpp @@ -104,26 +104,29 @@ class EE_API FileSystemModel : public Model { Int64 findChildRowFromName( const std::string& name, const FileSystemModel& model, bool forceRefresh = false ); + ~Node(); + private: friend class FileSystemModel; Node() {} - FileSystemModel::Node createChild( const std::string& childName, - const FileSystemModel& model ); + Node* createChild( const std::string& childName, const FileSystemModel& model ); friend class FileSystemModel; std::string mName; std::string mMimeType; Node* mParent{ nullptr }; FileInfo mInfo; - std::vector mChildren; + std::vector mChildren; bool mHasTraversed{ false }; bool mInfoDirty{ true }; bool mSelected{ false }; ModelIndex index( const FileSystemModel& model, int column ) const; + void cleanChildren(); + void traverseIfNeeded( const FileSystemModel& ); void refreshIfNeeded( const FileSystemModel& ); diff --git a/include/eepp/window/joystickmanager.hpp b/include/eepp/window/joystickmanager.hpp index 2a891902b..d10c9d46e 100644 --- a/include/eepp/window/joystickmanager.hpp +++ b/include/eepp/window/joystickmanager.hpp @@ -14,7 +14,7 @@ class EE_API JoystickManager { virtual ~JoystickManager(); /** @return The number of joysticks attached to the system */ - virtual Uint32 getCount(); + Uint32 getCount(); /** Update the states of all joysticks */ virtual void update() = 0; diff --git a/projects/linux/ee.includes b/projects/linux/ee.includes index 0be4a23df..ef2b6688f 100644 --- a/projects/linux/ee.includes +++ b/projects/linux/ee.includes @@ -3,10 +3,8 @@ ../../src/thirdparty ../../include/eepp/thirdparty ../../src/thirdparty/efsw/include +../../src/thirdparty/efsw/src ../../src/thirdparty/libvorbis/include -/usr/include/freetype2/ ../../src/thirdparty/mbedtls/include -../../include/eepp/ui/tools -../../include/eepp/ui -../../src/eepp/ui +/usr/include/freetype2/ /usr/lib64/gcc/x86_64-suse-linux/10/include diff --git a/src/eepp/core/debug.cpp b/src/eepp/core/debug.cpp index f9dac4643..df3eaeede 100644 --- a/src/eepp/core/debug.cpp +++ b/src/eepp/core/debug.cpp @@ -33,7 +33,7 @@ void eeREPORT_ASSERT( const char* File, int Line, const char* Exp ) { printf( "ASSERT: %s file:%s line:%d", Exp, File, Line ); } -#if defined( EE_COMPILER_GCC ) && defined( EE_32BIT ) && !defined( EE_ARM ) +#if defined( EE_COMPILER_GCC ) && !defined( EE_ARM ) asm( "int3" ); #else assert( false ); diff --git a/src/eepp/ui/models/filesystemmodel.cpp b/src/eepp/ui/models/filesystemmodel.cpp index acf9f0979..6f6059888 100644 --- a/src/eepp/ui/models/filesystemmodel.cpp +++ b/src/eepp/ui/models/filesystemmodel.cpp @@ -37,7 +37,7 @@ const std::string& FileSystemModel::Node::fullPath() const { const FileSystemModel::Node& FileSystemModel::Node::getChild( const size_t& index ) { eeASSERT( index < mChildren.size() ); - return mChildren[index]; + return *mChildren[index]; } void FileSystemModel::Node::invalidate() { @@ -51,8 +51,8 @@ FileSystemModel::Node* FileSystemModel::Node::findChildName( const std::string& if ( forceRefresh ) refreshIfNeeded( model ); for ( auto& child : mChildren ) { - if ( child.getName() == name ) - return &child; + if ( child->getName() == name ) + return child; } return nullptr; } @@ -63,7 +63,7 @@ Int64 FileSystemModel::Node::findChildRowFromInternalData( void* internalData, if ( forceRefresh ) refreshIfNeeded( model ); for ( size_t i = 0; i < mChildren.size(); i++ ) { - if ( &mChildren[i] == internalData ) { + if ( mChildren[i] == internalData ) { return i; } } @@ -76,18 +76,22 @@ Int64 FileSystemModel::Node::findChildRowFromName( const std::string& name, if ( forceRefresh ) refreshIfNeeded( model ); for ( size_t i = 0; i < mChildren.size(); i++ ) { - if ( mChildren[i].getName() == name ) { + if ( mChildren[i]->getName() == name ) { return i; } } return -1; } -FileSystemModel::Node FileSystemModel::Node::createChild( const std::string& childName, - const FileSystemModel& model ) { +FileSystemModel::Node::~Node() { + cleanChildren(); +} + +FileSystemModel::Node* FileSystemModel::Node::createChild( const std::string& childName, + const FileSystemModel& model ) { std::string childPath( mInfo.getDirectoryPath() + childName ); FileInfo file( childPath ); - auto child = Node( std::move( file ), this ); + auto child = eeNew( Node, ( std::move( file ), this ) ); if ( model.getDisplayConfig().ignoreHidden && file.isHidden() ) return {}; @@ -102,18 +106,24 @@ ModelIndex FileSystemModel::Node::index( const FileSystemModel& model, int colum if ( !mParent ) return {}; for ( size_t row = 0; row < mParent->mChildren.size(); ++row ) { - if ( &mParent->mChildren[row] == this ) + if ( mParent->mChildren[row] == this ) return model.createIndex( row, column, const_cast( this ) ); } eeASSERT( false ); return {}; } +void FileSystemModel::Node::cleanChildren() { + for ( size_t i = 0; i < mChildren.size(); ++i ) + eeDelete( mChildren[i] ); + mChildren.clear(); +} + void FileSystemModel::Node::traverseIfNeeded( const FileSystemModel& model ) { if ( !mInfo.isDirectory() || mHasTraversed ) return; mHasTraversed = true; - mChildren.clear(); + cleanChildren(); auto files = FileSystem::filesInfoGetInPath( mInfo.getFilepath(), true, model.getDisplayConfig().sortByName, @@ -126,7 +136,7 @@ void FileSystemModel::Node::traverseIfNeeded( const FileSystemModel& model ) { ( file.isDirectory() || file.linksToDirectory() ) ) || model.getMode() == Mode::FilesAndDirectories ) { if ( file.isDirectory() || file.linksToDirectory() || patterns.empty() ) { - mChildren.emplace_back( Node( std::move( file ), this ) ); + mChildren.emplace_back( eeNew( Node, ( std::move( file ), this ) ) ); } else { accepted = false; if ( patterns.size() ) { @@ -140,7 +150,7 @@ void FileSystemModel::Node::traverseIfNeeded( const FileSystemModel& model ) { accepted = true; } if ( accepted ) - mChildren.emplace_back( Node( std::move( file ), this ) ); + mChildren.emplace_back( eeNew( Node, ( std::move( file ), this ) ) ); } } } @@ -241,7 +251,8 @@ const FileSystemModel::Node& FileSystemModel::node( const ModelIndex& index ) co FileSystemModel::Node& FileSystemModel::nodeRef( const ModelIndex& index ) const { if ( !index.isValid() ) return *mRoot; - return *(Node*)index.internalData(); + Node* node = static_cast( index.internalData() ); + return *node; } size_t FileSystemModel::rowCount( const ModelIndex& index ) const { @@ -380,7 +391,7 @@ ModelIndex FileSystemModel::index( int row, int column, const ModelIndex& parent const_cast( node ).refreshIfNeeded( *this ); if ( static_cast( row ) >= node.mChildren.size() ) return {}; - return createIndex( row, column, &node.mChildren[row] ); + return createIndex( row, column, node.mChildren[row] ); } UIIcon* FileSystemModel::iconFor( const Node& node, const ModelIndex& index ) const { @@ -423,8 +434,8 @@ void FileSystemModel::setPreviouslySelectedIndex( const ModelIndex& previouslySe size_t FileSystemModel::getFileIndex( Node* parent, const FileInfo& file ) { std::vector files; - for ( const auto& nodeFile : parent->mChildren ) { - files.emplace_back( nodeFile.info() ); + for ( Node* nodeFile : parent->mChildren ) { + files.emplace_back( nodeFile->info() ); } files.emplace_back( file ); @@ -484,12 +495,13 @@ void FileSystemModel::handleFileEvent( const FileEvent& event ) { Lock l( resourceLock() ); if ( Log::instance() && Log::instance()->getLogLevelThreshold() == LogLevel::Debug ) { - Log::debug( - "DIR ( %s ) FILE ( %s ) has event %s", event.directory.c_str(), + std::string txt = + "DIR ( " + event.directory + " ) FILE ( " + ( ( event.oldFilename.empty() ? "" : "from file " + event.oldFilename + " to " ) + - event.filename ) - .c_str(), - getFileSystemEventTypeName( event.type ).c_str() ); + event.filename ) + + " ) has event " + getFileSystemEventTypeName( event.type ); + eeASSERT( event.directory[0] == '/' ); + Log::debug( txt ); } switch ( event.type ) { @@ -511,18 +523,17 @@ void FileSystemModel::handleFileEvent( const FileEvent& event ) { if ( childNodeExists ) return; - Node childNode = parent->createChild( file.getFileName(), *this ); + Node* childNode = parent->createChild( file.getFileName(), *this ); - if ( !childNode.getName().empty() ) { + if ( !childNode->getName().empty() ) { size_t pos = getFileIndex( parent, file ); beginInsertRows( parent->index( *this, 0 ), pos, pos ); if ( pos >= parent->mChildren.size() ) { - parent->mChildren.emplace_back( std::move( childNode ) ); + parent->mChildren.emplace_back( childNode ); } else { - parent->mChildren.insert( parent->mChildren.begin() + pos, - std::move( childNode ) ); + parent->mChildren.insert( parent->mChildren.begin() + pos, childNode ); } endInsertRows(); @@ -570,6 +581,7 @@ void FileSystemModel::handleFileEvent( const FileEvent& event ) { beginDeleteRows( index.parent(), index.row(), index.row() ); + eeDelete( parent->mChildren[index.row()] ); parent->mChildren.erase( parent->mChildren.begin() + index.row() ); endDeleteRows(); @@ -650,14 +662,14 @@ void FileSystemModel::handleFileEvent( const FileEvent& event ) { } ); } ); + eeDelete( parent->mChildren[index.row()] ); parent->mChildren.erase( parent->mChildren.begin() + index.row() ); - Node childNode = parent->createChild( file.getFileName(), *this ); + Node* childNode = parent->createChild( file.getFileName(), *this ); if ( pos >= parent->mChildren.size() ) { - parent->mChildren.emplace_back( std::move( childNode ) ); + parent->mChildren.emplace_back( childNode ); } else { - parent->mChildren.insert( parent->mChildren.begin() + pos, - std::move( childNode ) ); + parent->mChildren.insert( parent->mChildren.begin() + pos, childNode ); } if ( pos != SIZE_MAX ) diff --git a/src/eepp/window/backend/SDL2/joystickmanagersdl2.cpp b/src/eepp/window/backend/SDL2/joystickmanagersdl2.cpp index 6f9fd0401..222640ac4 100644 --- a/src/eepp/window/backend/SDL2/joystickmanagersdl2.cpp +++ b/src/eepp/window/backend/SDL2/joystickmanagersdl2.cpp @@ -5,10 +5,18 @@ namespace EE { namespace Window { namespace Backend { namespace SDL2 { +void closeSubsystem() { + if ( SDL_WasInit( SDL_INIT_JOYSTICK ) ) + SDL_QuitSubSystem( SDL_INIT_JOYSTICK ); +} + JoystickManagerSDL::JoystickManagerSDL() : JoystickManager(), mAsyncInit( &JoystickManagerSDL::openAsync, this ) {} -JoystickManagerSDL::~JoystickManagerSDL() {} +JoystickManagerSDL::~JoystickManagerSDL() { + closeSubsystem(); + mInit = false; +} void JoystickManagerSDL::update() { if ( mInit ) { @@ -40,11 +48,8 @@ void JoystickManagerSDL::open() { } void JoystickManagerSDL::close() { - if ( SDL_WasInit( SDL_INIT_JOYSTICK ) ) { - SDL_QuitSubSystem( SDL_INIT_JOYSTICK ); - - mInit = false; - } + closeSubsystem(); + mInit = false; } void JoystickManagerSDL::create( const Uint32& index ) { diff --git a/src/eepp/window/joystickmanager.cpp b/src/eepp/window/joystickmanager.cpp index 83c0aa51f..fe3b0b762 100644 --- a/src/eepp/window/joystickmanager.cpp +++ b/src/eepp/window/joystickmanager.cpp @@ -10,10 +10,8 @@ JoystickManager::JoystickManager() : mInit( false ), mCount( 0 ) { } JoystickManager::~JoystickManager() { - for ( Uint32 i = 0; i < getCount(); i++ ) + for ( Uint32 i = 0; i < mCount; i++ ) eeSAFE_DELETE( mJoysticks[i] ); - - close(); } Uint32 JoystickManager::getCount() { diff --git a/src/tools/codeeditor/codeeditor.cpp b/src/tools/codeeditor/codeeditor.cpp index b71e519e1..99d1056b8 100644 --- a/src/tools/codeeditor/codeeditor.cpp +++ b/src/tools/codeeditor/codeeditor.cpp @@ -1985,13 +1985,16 @@ FontTrueType* App::loadFont( const std::string& name, std::string fontPath, } void App::init( const std::string& file, const Float& pidelDensity ) { + DisplayManager* displayManager = Engine::instance()->getDisplayManager(); + Display* currentDisplay = displayManager->getDisplayIndex( 0 ); + mDisplayDPI = currentDisplay->getDPI(); + loadConfig(); - DisplayManager* displayManager = Engine::instance()->getDisplayManager(); - Display* currentDisplay = displayManager->getDisplayIndex( - mConfig.window.displayIndex < displayManager->getDisplayCount() - ? mConfig.window.displayIndex - : 0 ); + currentDisplay = displayManager->getDisplayIndex( mConfig.window.displayIndex < + displayManager->getDisplayCount() + ? mConfig.window.displayIndex + : 0 ); mDisplayDPI = currentDisplay->getDPI(); mResPath = Sys::getProcessPath(); diff --git a/src/tools/codeeditor/codeeditor.hpp b/src/tools/codeeditor/codeeditor.hpp index 61c71605e..286a54eef 100644 --- a/src/tools/codeeditor/codeeditor.hpp +++ b/src/tools/codeeditor/codeeditor.hpp @@ -99,7 +99,7 @@ class App : public UICodeEditorSplitter::Client { std::map mKeybindingsInvert; std::string mConfigPath; std::string mKeybindingsPath; - Float mDisplayDPI; + Float mDisplayDPI{ 96 }; std::string mResPath; AutoCompleteModule* mAutoCompleteModule{ nullptr }; LinterModule* mLinterModule{ nullptr };