Update PhysicsFSWrapper and print version on startup.

This commit is contained in:
King_DuckZ 2016-11-11 02:36:10 +01:00
parent b5f7e30471
commit ce9eff82f1
3 changed files with 74 additions and 9 deletions

View file

@ -50,7 +50,8 @@ int main (int, char* parArgv[]) {
#else
std::srand(static_cast<unsigned int>(DEF_RANDOM_SEED));
#endif
std::cout << GameName << " v" << GameVersionMajor << "." << GameVersionMinor << std::endl;
std::cout << GameName << " v" << GameVersionMajor << "." << GameVersionMinor << '\n';
std::cout << "Built with PhysicsFS v" << cloonel::PhysicsFSWrapper::CompiledVersion() << ", using v" << cloonel::PhysicsFSWrapper::LinkedVersion() << '\n';
int retVal = 0;
cloonel::SDLMain sdlmain(GameName, cloonel::ushort2(DEF_WIN_WIDTH, DEF_WIN_HEIGHT), cloonel::ushort2(REFERENCE_WIDTH, REFERENCE_HEIGHT));

View file

@ -25,7 +25,19 @@
#include <cassert>
namespace cloonel {
uint32_t PhysicsFSWrapper::m_init_count = 0;
namespace {
///---------------------------------------------------------------------
///---------------------------------------------------------------------
std::string ver_to_string (const PHYSFS_Version& parVer) {
std::ostringstream oss;
oss << static_cast<int>(parVer.major) << '.'
<< static_cast<int>(parVer.minor) << '.'
<< static_cast<int>(parVer.patch);
return oss.str();
}
///---------------------------------------------------------------------
///---------------------------------------------------------------------
PHYSFS_File* OpenPhysFSFile (const char* parPath, PhysicsFSFile::OpenMode parMode) {
@ -45,11 +57,19 @@ namespace cloonel {
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
PhysicsFSWrapper::PhysicsFSWrapper (const char* parBasePath) {
if (IsInitialized()) {
assert(m_init_count > 0);
++m_init_count;
}
else {
assert(0 == m_init_count);
if (not PHYSFS_init(parBasePath)) {
std::ostringstream oss;
oss << "Error during PhysicsFS initialization: " << PHYSFS_getLastError();
throw std::runtime_error(oss.str());
}
m_init_count = 1;
}
}
///-------------------------------------------------------------------------
@ -57,10 +77,18 @@ namespace cloonel {
///are not checking in its return value as we can't throw anyways.
///-------------------------------------------------------------------------
PhysicsFSWrapper::~PhysicsFSWrapper() noexcept {
assert(m_init_count > 0 and IsInitialized());
if (m_init_count > 0) {
--m_init_count;
if (0 == m_init_count) {
const bool succeeded = static_cast<bool>(PHYSFS_deinit());
(void)succeeded;
#if defined(NDEBUG)
static_cast<void>(succeeded);
#endif
assert(succeeded);
}
}
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
@ -76,6 +104,34 @@ namespace cloonel {
}
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
std::string PhysicsFSWrapper::LinkedVersion() {
PHYSFS_Version ver;
PHYSFS_getLinkedVersion(&ver);
return ver_to_string(ver);
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
std::string PhysicsFSWrapper::CompiledVersion() {
PHYSFS_Version ver;
PHYSFS_VERSION(&ver);
return ver_to_string(ver);
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
bool PhysicsFSWrapper::IsInitialized() const noexcept {
const bool initialized = static_cast<bool>(PHYSFS_isInit());
return initialized;
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
@ -84,7 +140,7 @@ namespace cloonel {
{
if (not m_handle) {
std::ostringstream oss;
oss << "Error opening " << parDescCategory << " file: \"" <<
oss << "Error opening " << parDescCategory << " file: \"";
oss << parPath << "\": ";
oss << PHYSFS_getLastError();
throw std::runtime_error(oss.str());

View file

@ -21,6 +21,7 @@
#define idC54817CCCC0F454F931AE9082DFE9FDA
#include <cstdint>
#include <string>
#define DEF_PHYSICSFS_BUFFERED true
@ -31,6 +32,13 @@ namespace cloonel {
~PhysicsFSWrapper ( void ) noexcept;
void Append ( const char* parRelativePath, const char* parMountPoint );
bool IsInitialized ( void ) const noexcept;
static std::string LinkedVersion();
static std::string CompiledVersion();
private:
static uint32_t m_init_count;
};
class PhysicsFSFile {