From 6a1ceba8c0914691ebc873fd666e7cde1cffdb64 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 7 Sep 2014 19:26:06 +0200 Subject: Some cleaning up --- src/app/app.cpp | 12 +++---- src/app/pausemanager.cpp | 18 ++++++---- src/app/system.h | 4 +-- src/app/system_linux.cpp | 6 ++-- src/app/system_macosx.cpp | 2 +- src/app/system_windows.cpp | 4 +-- src/common/resources/inputstream.h | 4 +-- src/common/resources/inputstreambuffer.cpp | 8 ++--- src/common/resources/inputstreambuffer.h | 4 +-- src/common/resources/outputstream.h | 2 +- src/common/resources/outputstreambuffer.cpp | 4 +-- src/common/resources/outputstreambuffer.h | 2 -- src/common/resources/resourcemanager.cpp | 51 +++++++++++++++------------ src/common/resources/resourcestreambuffer.cpp | 0 src/common/resources/resourcestreambuffer.h | 0 src/common/resources/sndfile.cpp | 2 -- src/common/resources/sndfile.h | 1 - 17 files changed, 64 insertions(+), 60 deletions(-) delete mode 100644 src/common/resources/resourcestreambuffer.cpp delete mode 100644 src/common/resources/resourcestreambuffer.h diff --git a/src/app/app.cpp b/src/app/app.cpp index 628b7a9..80f178b 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -146,14 +146,14 @@ CApplication::CApplication() m_kmodState = 0; m_mouseButtonsState = 0; m_trackedKeys = 0; - + m_dataPath = GetSystemUtils()->GetDataPath(); m_langPath = GetSystemUtils()->GetLangPath(); m_savePath = GetSystemUtils()->GetSaveDir(); m_runSceneName = ""; m_runSceneRank = 0; - + m_sceneTest = false; m_language = LANGUAGE_ENV; @@ -389,7 +389,7 @@ bool CApplication::Create() bool defaultValues = false; GetLogger()->Info("Creating CApplication\n"); - + boost::filesystem::path dataPath(m_dataPath); if (! (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) ) { @@ -400,13 +400,13 @@ bool CApplication::Create() m_exitCode = 1; return false; } - + boost::filesystem::create_directories(m_savePath); boost::filesystem::create_directories(m_savePath+"/mods"); - + LoadModsFromDir(m_dataPath+"/mods"); LoadModsFromDir(m_savePath+"/mods"); - + CResourceManager::AddLocation(m_dataPath, false); CResourceManager::SetSaveLocation(m_savePath); CResourceManager::AddLocation(m_savePath, true); diff --git a/src/app/pausemanager.cpp b/src/app/pausemanager.cpp index d357bba..1135126 100644 --- a/src/app/pausemanager.cpp +++ b/src/app/pausemanager.cpp @@ -29,7 +29,7 @@ template<> CPauseManager* CSingleton::m_instance = nullptr; CPauseManager::CPauseManager() { m_sound = CApplication::GetInstancePointer()->GetSound(); - + m_pause = PAUSE_NONE; } @@ -40,24 +40,28 @@ CPauseManager::~CPauseManager() void CPauseManager::SetPause(PauseType pause) { - if(pause != PAUSE_NONE) { - if(m_pause != pause) { + if (pause != PAUSE_NONE) + { + if (m_pause != pause) + { CLogger::GetInstancePointer()->Info("Game paused - %s\n", GetPauseName(pause).c_str()); CRobotMain::GetInstancePointer()->StartPauseMusic(pause); } - + m_pause = pause; - } else + } + else ClearPause(); } void CPauseManager::ClearPause() { - if(m_pause != PAUSE_NONE) { + if(m_pause != PAUSE_NONE) + { CLogger::GetInstancePointer()->Info("Game resumed\n"); m_sound->StopPauseMusic(); } - + m_pause = PAUSE_NONE; } diff --git a/src/app/system.h b/src/app/system.h index 5177815..4b4440f 100644 --- a/src/app/system.h +++ b/src/app/system.h @@ -132,10 +132,10 @@ public: //! Returns the data path (containing textures, levels, helpfiles, etc) virtual std::string GetDataPath(); - + //! Returns the translations path virtual std::string GetLangPath(); - + //! Returns the save dir location virtual std::string GetSaveDir(); }; diff --git a/src/app/system_linux.cpp b/src/app/system_linux.cpp index 485d7c2..837c03e 100644 --- a/src/app/system_linux.cpp +++ b/src/app/system_linux.cpp @@ -25,7 +25,7 @@ void CSystemUtilsLinux::Init() { m_zenityAvailable = true; - if (system("zenity --version") != 0) + if (system("zenity --version >& /dev/null") != 0) { m_zenityAvailable = false; GetLogger()->Warn("Zenity not available, will fallback to console users dialogs.\n"); @@ -98,7 +98,7 @@ long long CSystemUtilsLinux::TimeStampExactDiff(SystemTimeStamp *before, SystemT std::string CSystemUtilsLinux::GetSaveDir() { std::string savegameDir; - + // Determine savegame dir according to XDG Base Directory Specification char *envXDG_DATA_HOME = getenv("XDG_CONFIG_DATA"); if (envXDG_DATA_HOME == NULL) @@ -118,6 +118,6 @@ std::string CSystemUtilsLinux::GetSaveDir() savegameDir = std::string(envXDG_DATA_HOME) + "/colobot"; } GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str()); - + return savegameDir; } diff --git a/src/app/system_macosx.cpp b/src/app/system_macosx.cpp index 06c67d3..fd29667 100644 --- a/src/app/system_macosx.cpp +++ b/src/app/system_macosx.cpp @@ -101,6 +101,6 @@ std::string CSystemUtilsMacOSX::GetSaveDir() { std::string savegameDir = m_ASPath; GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str()); - + return savegameDir; } diff --git a/src/app/system_windows.cpp b/src/app/system_windows.cpp index e35f83f..a300bc4 100644 --- a/src/app/system_windows.cpp +++ b/src/app/system_windows.cpp @@ -114,7 +114,7 @@ std::wstring CSystemUtilsWindows::UTF8_Decode(const std::string& str) std::string CSystemUtilsWindows::GetSaveDir() { std::string savegameDir; - + char* envUSERPROFILE = getenv("USERPROFILE"); if (envUSERPROFILE == NULL) { @@ -125,6 +125,6 @@ std::string CSystemUtilsWindows::GetSaveDir() savegameDir = std::string(envUSERPROFILE) + "\\colobot"; } GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str()); - + return savegameDir; } diff --git a/src/common/resources/inputstream.h b/src/common/resources/inputstream.h index 9d1c578..9573f2c 100644 --- a/src/common/resources/inputstream.h +++ b/src/common/resources/inputstream.h @@ -25,9 +25,9 @@ class CInputStream : public std::istream public: CInputStream(); virtual ~CInputStream(); - + void open(const std::string &filename); void close(); - bool is_open(); + bool is_open(); size_t size(); }; diff --git a/src/common/resources/inputstreambuffer.cpp b/src/common/resources/inputstreambuffer.cpp index b8710e9..cfa06fb 100644 --- a/src/common/resources/inputstreambuffer.cpp +++ b/src/common/resources/inputstreambuffer.cpp @@ -68,14 +68,14 @@ std::streambuf::int_type CInputStreamBuffer::underflow() { if (gptr() < egptr()) return traits_type::to_int_type(*gptr()); - + if (PHYSFS_eof(m_file)) return traits_type::eof(); - + PHYSFS_sint64 read_count = PHYSFS_read(m_file, m_buffer, sizeof(char), m_buffer_size); if (read_count <= 0) return traits_type::eof(); - + setg(m_buffer, m_buffer, m_buffer + read_count); return traits_type::to_int_type(*gptr()); @@ -98,7 +98,7 @@ std::streampos CInputStreamBuffer::seekoff(std::streamoff off, std::ios_base::se off argument is relative to way */ std::streamoff new_position; - + switch (way) { case std::ios_base::beg: diff --git a/src/common/resources/inputstreambuffer.h b/src/common/resources/inputstreambuffer.h index 93cb43c..384ebfb 100644 --- a/src/common/resources/inputstreambuffer.h +++ b/src/common/resources/inputstreambuffer.h @@ -25,7 +25,7 @@ class CInputStreamBuffer : public std::streambuf public: CInputStreamBuffer(size_t buffer_size = 512); virtual ~CInputStreamBuffer(); - + void open(const std::string &filename); void close(); bool is_open(); @@ -41,7 +41,7 @@ private: // copying not allowed CInputStreamBuffer(const CInputStreamBuffer &); CInputStreamBuffer &operator= (const CInputStreamBuffer &); - + PHYSFS_File *m_file; char *m_buffer; size_t m_buffer_size; diff --git a/src/common/resources/outputstream.h b/src/common/resources/outputstream.h index 4f4cd72..bedbbbd 100644 --- a/src/common/resources/outputstream.h +++ b/src/common/resources/outputstream.h @@ -25,7 +25,7 @@ class COutputStream : public std::ostream public: COutputStream(); virtual ~COutputStream(); - + void open(const std::string &filename); void close(); bool is_open(); diff --git a/src/common/resources/outputstreambuffer.cpp b/src/common/resources/outputstreambuffer.cpp index 22ed7cb..38979db 100644 --- a/src/common/resources/outputstreambuffer.cpp +++ b/src/common/resources/outputstreambuffer.cpp @@ -59,7 +59,7 @@ std::streambuf::int_type COutputStreamBuffer::overflow(std::streambuf::int_type { /* This function should be called when pptr() == epptr(). We use it also in sync() so we also have to write data if buffer is not full. */ - + if (pbase() == pptr()) // no data to write, sync() called with empty buffer return 0; @@ -68,7 +68,7 @@ std::streambuf::int_type COutputStreamBuffer::overflow(std::streambuf::int_type if (bytes_written <= 0) return traits_type::eof(); - pbump(-bytes_written); + pbump(-bytes_written); // write final char if (ch != traits_type::eof()) { bytes_written = PHYSFS_write(m_file, &ch, 1, 1); diff --git a/src/common/resources/outputstreambuffer.h b/src/common/resources/outputstreambuffer.h index 1d98791..1318530 100644 --- a/src/common/resources/outputstreambuffer.h +++ b/src/common/resources/outputstreambuffer.h @@ -25,7 +25,6 @@ class COutputStreamBuffer : public std::streambuf public: COutputStreamBuffer(size_t buffer_size = 512); virtual ~COutputStreamBuffer(); - void open(const std::string &filename); void close(); bool is_open(); @@ -38,7 +37,6 @@ private: // copying not allowed COutputStreamBuffer(const COutputStreamBuffer &); COutputStreamBuffer &operator= (const COutputStreamBuffer &); - PHYSFS_File *m_file; char *m_buffer; size_t m_buffer_size; diff --git a/src/common/resources/resourcemanager.cpp b/src/common/resources/resourcemanager.cpp index 0741c70..6459df0 100644 --- a/src/common/resources/resourcemanager.cpp +++ b/src/common/resources/resourcemanager.cpp @@ -22,6 +22,11 @@ #include +namespace +{ + const Uint32 PHYSFS_RWOPS_TYPE = 0xc010b04f; +} + CResourceManager::CResourceManager(const char *argv0) { @@ -53,7 +58,7 @@ bool CResourceManager::AddLocation(const std::string &location, bool prepend) CLogger::GetInstancePointer()->Error("Error while mounting \"%s\"\n", location.c_str()); } } - + return false; } @@ -67,7 +72,7 @@ bool CResourceManager::RemoveLocation(const std::string &location) CLogger::GetInstancePointer()->Error("Error while unmounting \"%s\"\n", location.c_str()); } } - + return false; } @@ -81,7 +86,7 @@ bool CResourceManager::SetSaveLocation(const std::string &location) CLogger::GetInstancePointer()->Error("Error while setting save location to \"%s\"\n", location.c_str()); } } - + return false; } @@ -94,13 +99,13 @@ SDL_RWops* CResourceManager::GetSDLFileHandler(const std::string &filename) CLogger::GetInstancePointer()->Error("Unable to allocate SDL_RWops for \"%s\"\n", filename.c_str()); return nullptr; } - + if (!PHYSFS_isInit()) { SDL_FreeRW(handler); return nullptr; } - + PHYSFS_File *file = PHYSFS_openRead(filename.c_str()); if (!file) { @@ -112,15 +117,15 @@ SDL_RWops* CResourceManager::GetSDLFileHandler(const std::string &filename) handler->read = SDLRead; handler->write = SDLWrite; handler->close = SDLClose; - handler->type = 0xc010b04f; + handler->type = PHYSFS_RWOPS_TYPE; handler->hidden.unknown.data1 = file; - + return handler; } CSNDFile* CResourceManager::GetSNDFileHandler(const std::string &filename) -{ +{ return new CSNDFile(filename); } @@ -133,15 +138,15 @@ bool CResourceManager::Exists(const std::string &filename) std::vector CResourceManager::ListFiles(const std::string &directory) { std::vector result; - + char **files = PHYSFS_enumerateFiles(directory.c_str()); - + for (char **i = files; *i != nullptr; i++) { result.push_back(*i); } - + PHYSFS_freeList(files); - + return result; } @@ -152,10 +157,10 @@ int CResourceManager::SDLClose(SDL_RWops *context) { PHYSFS_close(static_cast(context->hidden.unknown.data1)); SDL_FreeRW(context); - + return 0; } - + return 1; } @@ -166,10 +171,10 @@ int CResourceManager::SDLRead(SDL_RWops *context, void *ptr, int size, int maxnu { PHYSFS_File *file = static_cast(context->hidden.unknown.data1); SDL_memset(ptr, 0, size * maxnum); - + return PHYSFS_read(file, ptr, size, maxnum); } - + return 0; } @@ -186,37 +191,37 @@ int CResourceManager::SDLSeek(SDL_RWops *context, int offset, int whence) { PHYSFS_File *file = static_cast(context->hidden.unknown.data1); int position, result; - + switch (whence) { default: case RW_SEEK_SET: result = PHYSFS_seek(file, offset); return result > 0 ? offset : -1; - + case RW_SEEK_CUR: position = offset + PHYSFS_tell(file); result = PHYSFS_seek(file, position); return result > 0 ? position : -1; - + case RW_SEEK_END: position = PHYSFS_fileLength(file) - offset; result = PHYSFS_seek(file, position); - return result > 0 ? position : -1; + return result > 0 ? position : -1; } } - + return -1; } bool CResourceManager::CheckSDLContext(SDL_RWops *context) { - if (context->type != 0xc010b04f) + if (context->type != PHYSFS_RWOPS_TYPE) { SDL_SetError("Wrong kind of RWops"); return false; } - + return true; } diff --git a/src/common/resources/resourcestreambuffer.cpp b/src/common/resources/resourcestreambuffer.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/common/resources/resourcestreambuffer.h b/src/common/resources/resourcestreambuffer.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/common/resources/sndfile.cpp b/src/common/resources/sndfile.cpp index 3f5a60d..b71f06a 100644 --- a/src/common/resources/sndfile.cpp +++ b/src/common/resources/sndfile.cpp @@ -31,7 +31,6 @@ CSNDFile::CSNDFile(const std::string& filename) { m_last_error = "Resource system not started!"; } - if (m_file) { m_snd_file = sf_open_virtual(&snd_callbacks, SFM_READ, &m_file_info, m_file); @@ -99,7 +98,6 @@ sf_count_t CSNDFile::SNDRead(void *ptr, sf_count_t count, void *data) sf_count_t CSNDFile::SNDSeek(sf_count_t offset, int whence, void *data) { PHYSFS_File *file = static_cast(data); - switch(whence) { case SEEK_CUR: diff --git a/src/common/resources/sndfile.h b/src/common/resources/sndfile.h index 5ea6ccc..5fc00f4 100644 --- a/src/common/resources/sndfile.h +++ b/src/common/resources/sndfile.h @@ -38,7 +38,6 @@ private: static sf_count_t SNDRead(void *ptr, sf_count_t count, void *data); static sf_count_t SNDWrite(const void *ptr, sf_count_t count, void *data); static sf_count_t SNDTell(void *data); - SF_INFO m_file_info; SNDFILE *m_snd_file; PHYSFS_File *m_file; -- cgit v1.2.3-1-g7c22