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_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);

View File

@ -29,7 +29,7 @@ template<> CPauseManager* CSingleton<CPauseManager>::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;
}

View File

@ -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();
};

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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();
};

View File

@ -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:

View File

@ -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;

View File

@ -25,7 +25,7 @@ class COutputStream : public std::ostream
public:
COutputStream();
virtual ~COutputStream();
void open(const std::string &filename);
void close();
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()
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);

View File

@ -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;

View File

@ -22,6 +22,11 @@
#include <physfs.h>
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<std::string> CResourceManager::ListFiles(const std::string &directory)
{
std::vector<std::string> 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<PHYSFS_File *>(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<PHYSFS_File *>(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<PHYSFS_File *>(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;
}

View File

@ -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<PHYSFS_File *>(data);
switch(whence)
{
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 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;