Some cleaning up

dev-mp
Piotr Dziwinski 2014-09-07 19:26:06 +02:00
parent f0b38721e0
commit 6a1ceba8c0
17 changed files with 64 additions and 60 deletions

View File

@ -146,14 +146,14 @@ CApplication::CApplication()
m_kmodState = 0; m_kmodState = 0;
m_mouseButtonsState = 0; m_mouseButtonsState = 0;
m_trackedKeys = 0; m_trackedKeys = 0;
m_dataPath = GetSystemUtils()->GetDataPath(); m_dataPath = GetSystemUtils()->GetDataPath();
m_langPath = GetSystemUtils()->GetLangPath(); m_langPath = GetSystemUtils()->GetLangPath();
m_savePath = GetSystemUtils()->GetSaveDir(); m_savePath = GetSystemUtils()->GetSaveDir();
m_runSceneName = ""; m_runSceneName = "";
m_runSceneRank = 0; m_runSceneRank = 0;
m_sceneTest = false; m_sceneTest = false;
m_language = LANGUAGE_ENV; m_language = LANGUAGE_ENV;
@ -389,7 +389,7 @@ bool CApplication::Create()
bool defaultValues = false; bool defaultValues = false;
GetLogger()->Info("Creating CApplication\n"); GetLogger()->Info("Creating CApplication\n");
boost::filesystem::path dataPath(m_dataPath); boost::filesystem::path dataPath(m_dataPath);
if (! (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) ) if (! (boost::filesystem::exists(dataPath) && boost::filesystem::is_directory(dataPath)) )
{ {
@ -400,13 +400,13 @@ bool CApplication::Create()
m_exitCode = 1; m_exitCode = 1;
return false; return false;
} }
boost::filesystem::create_directories(m_savePath); boost::filesystem::create_directories(m_savePath);
boost::filesystem::create_directories(m_savePath+"/mods"); boost::filesystem::create_directories(m_savePath+"/mods");
LoadModsFromDir(m_dataPath+"/mods"); LoadModsFromDir(m_dataPath+"/mods");
LoadModsFromDir(m_savePath+"/mods"); LoadModsFromDir(m_savePath+"/mods");
CResourceManager::AddLocation(m_dataPath, false); CResourceManager::AddLocation(m_dataPath, false);
CResourceManager::SetSaveLocation(m_savePath); CResourceManager::SetSaveLocation(m_savePath);
CResourceManager::AddLocation(m_savePath, true); CResourceManager::AddLocation(m_savePath, true);

View File

@ -29,7 +29,7 @@ template<> CPauseManager* CSingleton<CPauseManager>::m_instance = nullptr;
CPauseManager::CPauseManager() CPauseManager::CPauseManager()
{ {
m_sound = CApplication::GetInstancePointer()->GetSound(); m_sound = CApplication::GetInstancePointer()->GetSound();
m_pause = PAUSE_NONE; m_pause = PAUSE_NONE;
} }
@ -40,24 +40,28 @@ CPauseManager::~CPauseManager()
void CPauseManager::SetPause(PauseType pause) void CPauseManager::SetPause(PauseType pause)
{ {
if(pause != PAUSE_NONE) { if (pause != PAUSE_NONE)
if(m_pause != pause) { {
if (m_pause != pause)
{
CLogger::GetInstancePointer()->Info("Game paused - %s\n", GetPauseName(pause).c_str()); CLogger::GetInstancePointer()->Info("Game paused - %s\n", GetPauseName(pause).c_str());
CRobotMain::GetInstancePointer()->StartPauseMusic(pause); CRobotMain::GetInstancePointer()->StartPauseMusic(pause);
} }
m_pause = pause; m_pause = pause;
} else }
else
ClearPause(); ClearPause();
} }
void CPauseManager::ClearPause() void CPauseManager::ClearPause()
{ {
if(m_pause != PAUSE_NONE) { if(m_pause != PAUSE_NONE)
{
CLogger::GetInstancePointer()->Info("Game resumed\n"); CLogger::GetInstancePointer()->Info("Game resumed\n");
m_sound->StopPauseMusic(); m_sound->StopPauseMusic();
} }
m_pause = PAUSE_NONE; m_pause = PAUSE_NONE;
} }

View File

@ -132,10 +132,10 @@ public:
//! Returns the data path (containing textures, levels, helpfiles, etc) //! Returns the data path (containing textures, levels, helpfiles, etc)
virtual std::string GetDataPath(); virtual std::string GetDataPath();
//! Returns the translations path //! Returns the translations path
virtual std::string GetLangPath(); virtual std::string GetLangPath();
//! Returns the save dir location //! Returns the save dir location
virtual std::string GetSaveDir(); virtual std::string GetSaveDir();
}; };

View File

@ -25,7 +25,7 @@
void CSystemUtilsLinux::Init() void CSystemUtilsLinux::Init()
{ {
m_zenityAvailable = true; m_zenityAvailable = true;
if (system("zenity --version") != 0) if (system("zenity --version >& /dev/null") != 0)
{ {
m_zenityAvailable = false; m_zenityAvailable = false;
GetLogger()->Warn("Zenity not available, will fallback to console users dialogs.\n"); 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 CSystemUtilsLinux::GetSaveDir()
{ {
std::string savegameDir; std::string savegameDir;
// Determine savegame dir according to XDG Base Directory Specification // Determine savegame dir according to XDG Base Directory Specification
char *envXDG_DATA_HOME = getenv("XDG_CONFIG_DATA"); char *envXDG_DATA_HOME = getenv("XDG_CONFIG_DATA");
if (envXDG_DATA_HOME == NULL) if (envXDG_DATA_HOME == NULL)
@ -118,6 +118,6 @@ std::string CSystemUtilsLinux::GetSaveDir()
savegameDir = std::string(envXDG_DATA_HOME) + "/colobot"; savegameDir = std::string(envXDG_DATA_HOME) + "/colobot";
} }
GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str()); GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
return savegameDir; return savegameDir;
} }

View File

@ -101,6 +101,6 @@ std::string CSystemUtilsMacOSX::GetSaveDir()
{ {
std::string savegameDir = m_ASPath; std::string savegameDir = m_ASPath;
GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str()); GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
return savegameDir; return savegameDir;
} }

View File

@ -114,7 +114,7 @@ std::wstring CSystemUtilsWindows::UTF8_Decode(const std::string& str)
std::string CSystemUtilsWindows::GetSaveDir() std::string CSystemUtilsWindows::GetSaveDir()
{ {
std::string savegameDir; std::string savegameDir;
char* envUSERPROFILE = getenv("USERPROFILE"); char* envUSERPROFILE = getenv("USERPROFILE");
if (envUSERPROFILE == NULL) if (envUSERPROFILE == NULL)
{ {
@ -125,6 +125,6 @@ std::string CSystemUtilsWindows::GetSaveDir()
savegameDir = std::string(envUSERPROFILE) + "\\colobot"; savegameDir = std::string(envUSERPROFILE) + "\\colobot";
} }
GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str()); GetLogger()->Trace("Saved game files are going to %s\n", savegameDir.c_str());
return savegameDir; return savegameDir;
} }

View File

@ -25,9 +25,9 @@ class CInputStream : public std::istream
public: public:
CInputStream(); CInputStream();
virtual ~CInputStream(); virtual ~CInputStream();
void open(const std::string &filename); void open(const std::string &filename);
void close(); void close();
bool is_open(); bool is_open();
size_t size(); size_t size();
}; };

View File

@ -68,14 +68,14 @@ std::streambuf::int_type CInputStreamBuffer::underflow()
{ {
if (gptr() < egptr()) if (gptr() < egptr())
return traits_type::to_int_type(*gptr()); return traits_type::to_int_type(*gptr());
if (PHYSFS_eof(m_file)) if (PHYSFS_eof(m_file))
return traits_type::eof(); return traits_type::eof();
PHYSFS_sint64 read_count = PHYSFS_read(m_file, m_buffer, sizeof(char), m_buffer_size); PHYSFS_sint64 read_count = PHYSFS_read(m_file, m_buffer, sizeof(char), m_buffer_size);
if (read_count <= 0) if (read_count <= 0)
return traits_type::eof(); return traits_type::eof();
setg(m_buffer, m_buffer, m_buffer + read_count); setg(m_buffer, m_buffer, m_buffer + read_count);
return traits_type::to_int_type(*gptr()); 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 */ off argument is relative to way */
std::streamoff new_position; std::streamoff new_position;
switch (way) switch (way)
{ {
case std::ios_base::beg: case std::ios_base::beg:

View File

@ -25,7 +25,7 @@ class CInputStreamBuffer : public std::streambuf
public: public:
CInputStreamBuffer(size_t buffer_size = 512); CInputStreamBuffer(size_t buffer_size = 512);
virtual ~CInputStreamBuffer(); virtual ~CInputStreamBuffer();
void open(const std::string &filename); void open(const std::string &filename);
void close(); void close();
bool is_open(); bool is_open();
@ -41,7 +41,7 @@ private:
// copying not allowed // copying not allowed
CInputStreamBuffer(const CInputStreamBuffer &); CInputStreamBuffer(const CInputStreamBuffer &);
CInputStreamBuffer &operator= (const CInputStreamBuffer &); CInputStreamBuffer &operator= (const CInputStreamBuffer &);
PHYSFS_File *m_file; PHYSFS_File *m_file;
char *m_buffer; char *m_buffer;
size_t m_buffer_size; size_t m_buffer_size;

View File

@ -25,7 +25,7 @@ class COutputStream : public std::ostream
public: public:
COutputStream(); COutputStream();
virtual ~COutputStream(); virtual ~COutputStream();
void open(const std::string &filename); void open(const std::string &filename);
void close(); void close();
bool is_open(); bool is_open();

View File

@ -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() /* 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. */ so we also have to write data if buffer is not full. */
if (pbase() == pptr()) // no data to write, sync() called with empty buffer if (pbase() == pptr()) // no data to write, sync() called with empty buffer
return 0; return 0;
@ -68,7 +68,7 @@ std::streambuf::int_type COutputStreamBuffer::overflow(std::streambuf::int_type
if (bytes_written <= 0) if (bytes_written <= 0)
return traits_type::eof(); return traits_type::eof();
pbump(-bytes_written); pbump(-bytes_written);
// write final char // write final char
if (ch != traits_type::eof()) { if (ch != traits_type::eof()) {
bytes_written = PHYSFS_write(m_file, &ch, 1, 1); bytes_written = PHYSFS_write(m_file, &ch, 1, 1);

View File

@ -25,7 +25,6 @@ class COutputStreamBuffer : public std::streambuf
public: public:
COutputStreamBuffer(size_t buffer_size = 512); COutputStreamBuffer(size_t buffer_size = 512);
virtual ~COutputStreamBuffer(); virtual ~COutputStreamBuffer();
void open(const std::string &filename); void open(const std::string &filename);
void close(); void close();
bool is_open(); bool is_open();
@ -38,7 +37,6 @@ private:
// copying not allowed // copying not allowed
COutputStreamBuffer(const COutputStreamBuffer &); COutputStreamBuffer(const COutputStreamBuffer &);
COutputStreamBuffer &operator= (const COutputStreamBuffer &); COutputStreamBuffer &operator= (const COutputStreamBuffer &);
PHYSFS_File *m_file; PHYSFS_File *m_file;
char *m_buffer; char *m_buffer;
size_t m_buffer_size; size_t m_buffer_size;

View File

@ -22,6 +22,11 @@
#include <physfs.h> #include <physfs.h>
namespace
{
const Uint32 PHYSFS_RWOPS_TYPE = 0xc010b04f;
}
CResourceManager::CResourceManager(const char *argv0) 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()); CLogger::GetInstancePointer()->Error("Error while mounting \"%s\"\n", location.c_str());
} }
} }
return false; return false;
} }
@ -67,7 +72,7 @@ bool CResourceManager::RemoveLocation(const std::string &location)
CLogger::GetInstancePointer()->Error("Error while unmounting \"%s\"\n", location.c_str()); CLogger::GetInstancePointer()->Error("Error while unmounting \"%s\"\n", location.c_str());
} }
} }
return false; 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()); CLogger::GetInstancePointer()->Error("Error while setting save location to \"%s\"\n", location.c_str());
} }
} }
return false; 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()); CLogger::GetInstancePointer()->Error("Unable to allocate SDL_RWops for \"%s\"\n", filename.c_str());
return nullptr; return nullptr;
} }
if (!PHYSFS_isInit()) if (!PHYSFS_isInit())
{ {
SDL_FreeRW(handler); SDL_FreeRW(handler);
return nullptr; return nullptr;
} }
PHYSFS_File *file = PHYSFS_openRead(filename.c_str()); PHYSFS_File *file = PHYSFS_openRead(filename.c_str());
if (!file) if (!file)
{ {
@ -112,15 +117,15 @@ SDL_RWops* CResourceManager::GetSDLFileHandler(const std::string &filename)
handler->read = SDLRead; handler->read = SDLRead;
handler->write = SDLWrite; handler->write = SDLWrite;
handler->close = SDLClose; handler->close = SDLClose;
handler->type = 0xc010b04f; handler->type = PHYSFS_RWOPS_TYPE;
handler->hidden.unknown.data1 = file; handler->hidden.unknown.data1 = file;
return handler; return handler;
} }
CSNDFile* CResourceManager::GetSNDFileHandler(const std::string &filename) CSNDFile* CResourceManager::GetSNDFileHandler(const std::string &filename)
{ {
return new CSNDFile(filename); return new CSNDFile(filename);
} }
@ -133,15 +138,15 @@ bool CResourceManager::Exists(const std::string &filename)
std::vector<std::string> CResourceManager::ListFiles(const std::string &directory) std::vector<std::string> CResourceManager::ListFiles(const std::string &directory)
{ {
std::vector<std::string> result; std::vector<std::string> result;
char **files = PHYSFS_enumerateFiles(directory.c_str()); char **files = PHYSFS_enumerateFiles(directory.c_str());
for (char **i = files; *i != nullptr; i++) { for (char **i = files; *i != nullptr; i++) {
result.push_back(*i); result.push_back(*i);
} }
PHYSFS_freeList(files); PHYSFS_freeList(files);
return result; return result;
} }
@ -152,10 +157,10 @@ int CResourceManager::SDLClose(SDL_RWops *context)
{ {
PHYSFS_close(static_cast<PHYSFS_File *>(context->hidden.unknown.data1)); PHYSFS_close(static_cast<PHYSFS_File *>(context->hidden.unknown.data1));
SDL_FreeRW(context); SDL_FreeRW(context);
return 0; return 0;
} }
return 1; return 1;
} }
@ -166,10 +171,10 @@ int CResourceManager::SDLRead(SDL_RWops *context, void *ptr, int size, int maxnu
{ {
PHYSFS_File *file = static_cast<PHYSFS_File *>(context->hidden.unknown.data1); PHYSFS_File *file = static_cast<PHYSFS_File *>(context->hidden.unknown.data1);
SDL_memset(ptr, 0, size * maxnum); SDL_memset(ptr, 0, size * maxnum);
return PHYSFS_read(file, ptr, size, maxnum); return PHYSFS_read(file, ptr, size, maxnum);
} }
return 0; return 0;
} }
@ -186,37 +191,37 @@ int CResourceManager::SDLSeek(SDL_RWops *context, int offset, int whence)
{ {
PHYSFS_File *file = static_cast<PHYSFS_File *>(context->hidden.unknown.data1); PHYSFS_File *file = static_cast<PHYSFS_File *>(context->hidden.unknown.data1);
int position, result; int position, result;
switch (whence) switch (whence)
{ {
default: default:
case RW_SEEK_SET: case RW_SEEK_SET:
result = PHYSFS_seek(file, offset); result = PHYSFS_seek(file, offset);
return result > 0 ? offset : -1; return result > 0 ? offset : -1;
case RW_SEEK_CUR: case RW_SEEK_CUR:
position = offset + PHYSFS_tell(file); position = offset + PHYSFS_tell(file);
result = PHYSFS_seek(file, position); result = PHYSFS_seek(file, position);
return result > 0 ? position : -1; return result > 0 ? position : -1;
case RW_SEEK_END: case RW_SEEK_END:
position = PHYSFS_fileLength(file) - offset; position = PHYSFS_fileLength(file) - offset;
result = PHYSFS_seek(file, position); result = PHYSFS_seek(file, position);
return result > 0 ? position : -1; return result > 0 ? position : -1;
} }
} }
return -1; return -1;
} }
bool CResourceManager::CheckSDLContext(SDL_RWops *context) bool CResourceManager::CheckSDLContext(SDL_RWops *context)
{ {
if (context->type != 0xc010b04f) if (context->type != PHYSFS_RWOPS_TYPE)
{ {
SDL_SetError("Wrong kind of RWops"); SDL_SetError("Wrong kind of RWops");
return false; return false;
} }
return true; return true;
} }

View File

@ -31,7 +31,6 @@ CSNDFile::CSNDFile(const std::string& filename)
{ {
m_last_error = "Resource system not started!"; m_last_error = "Resource system not started!";
} }
if (m_file) if (m_file)
{ {
m_snd_file = sf_open_virtual(&snd_callbacks, SFM_READ, &m_file_info, 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) sf_count_t CSNDFile::SNDSeek(sf_count_t offset, int whence, void *data)
{ {
PHYSFS_File *file = static_cast<PHYSFS_File *>(data); PHYSFS_File *file = static_cast<PHYSFS_File *>(data);
switch(whence) switch(whence)
{ {
case SEEK_CUR: case SEEK_CUR:

View File

@ -38,7 +38,6 @@ private:
static sf_count_t SNDRead(void *ptr, sf_count_t count, void *data); 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 SNDWrite(const void *ptr, sf_count_t count, void *data);
static sf_count_t SNDTell(void *data); static sf_count_t SNDTell(void *data);
SF_INFO m_file_info; SF_INFO m_file_info;
SNDFILE *m_snd_file; SNDFILE *m_snd_file;
PHYSFS_File *m_file; PHYSFS_File *m_file;