Update PhysicsFSWrapper and print version on startup.
This commit is contained in:
parent
b5f7e30471
commit
ce9eff82f1
3 changed files with 74 additions and 9 deletions
|
@ -50,7 +50,8 @@ int main (int, char* parArgv[]) {
|
||||||
#else
|
#else
|
||||||
std::srand(static_cast<unsigned int>(DEF_RANDOM_SEED));
|
std::srand(static_cast<unsigned int>(DEF_RANDOM_SEED));
|
||||||
#endif
|
#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;
|
int retVal = 0;
|
||||||
cloonel::SDLMain sdlmain(GameName, cloonel::ushort2(DEF_WIN_WIDTH, DEF_WIN_HEIGHT), cloonel::ushort2(REFERENCE_WIDTH, REFERENCE_HEIGHT));
|
cloonel::SDLMain sdlmain(GameName, cloonel::ushort2(DEF_WIN_WIDTH, DEF_WIN_HEIGHT), cloonel::ushort2(REFERENCE_WIDTH, REFERENCE_HEIGHT));
|
||||||
|
|
|
@ -25,7 +25,19 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
namespace cloonel {
|
namespace cloonel {
|
||||||
|
uint32_t PhysicsFSWrapper::m_init_count = 0;
|
||||||
|
|
||||||
namespace {
|
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) {
|
PHYSFS_File* OpenPhysFSFile (const char* parPath, PhysicsFSFile::OpenMode parMode) {
|
||||||
|
@ -45,10 +57,18 @@ namespace cloonel {
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
PhysicsFSWrapper::PhysicsFSWrapper (const char* parBasePath) {
|
PhysicsFSWrapper::PhysicsFSWrapper (const char* parBasePath) {
|
||||||
if (not PHYSFS_init(parBasePath)) {
|
if (IsInitialized()) {
|
||||||
std::ostringstream oss;
|
assert(m_init_count > 0);
|
||||||
oss << "Error during PhysicsFS initialization: " << PHYSFS_getLastError();
|
++m_init_count;
|
||||||
throw std::runtime_error(oss.str());
|
}
|
||||||
|
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,9 +77,17 @@ namespace cloonel {
|
||||||
///are not checking in its return value as we can't throw anyways.
|
///are not checking in its return value as we can't throw anyways.
|
||||||
///-------------------------------------------------------------------------
|
///-------------------------------------------------------------------------
|
||||||
PhysicsFSWrapper::~PhysicsFSWrapper() noexcept {
|
PhysicsFSWrapper::~PhysicsFSWrapper() noexcept {
|
||||||
const bool succeeded = static_cast<bool>(PHYSFS_deinit());
|
assert(m_init_count > 0 and IsInitialized());
|
||||||
(void)succeeded;
|
if (m_init_count > 0) {
|
||||||
assert(succeeded);
|
--m_init_count;
|
||||||
|
if (0 == m_init_count) {
|
||||||
|
const bool succeeded = static_cast<bool>(PHYSFS_deinit());
|
||||||
|
#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) {
|
if (not m_handle) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "Error opening " << parDescCategory << " file: \"" <<
|
oss << "Error opening " << parDescCategory << " file: \"";
|
||||||
oss << parPath << "\": ";
|
oss << parPath << "\": ";
|
||||||
oss << PHYSFS_getLastError();
|
oss << PHYSFS_getLastError();
|
||||||
throw std::runtime_error(oss.str());
|
throw std::runtime_error(oss.str());
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#define idC54817CCCC0F454F931AE9082DFE9FDA
|
#define idC54817CCCC0F454F931AE9082DFE9FDA
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#define DEF_PHYSICSFS_BUFFERED true
|
#define DEF_PHYSICSFS_BUFFERED true
|
||||||
|
|
||||||
|
@ -31,6 +32,13 @@ namespace cloonel {
|
||||||
~PhysicsFSWrapper ( void ) noexcept;
|
~PhysicsFSWrapper ( void ) noexcept;
|
||||||
|
|
||||||
void Append ( const char* parRelativePath, const char* parMountPoint );
|
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 {
|
class PhysicsFSFile {
|
||||||
|
|
Loading…
Reference in a new issue