54d11f1e91
* cpu performance optimizations: - mapped buffer explicit writes - render queue sorting - object update system - primitive intersections - job system - spinlock _mm_pause() * intrin.h -> emmintrin.h * linux build fix scoped_lock * shader material structure compaction * job system update * explicit writes in font renderer and entity update * removed previous frame transform component, from now on it's only stored object in gpu buffers * don't get instance buffer descriptor index inside render loop * subset gpu data update explicit write * job system: multiple queues, work stealing
107 lines
2.2 KiB
C++
107 lines
2.2 KiB
C++
#include "wiArchive.h"
|
|
#include "wiHelper.h"
|
|
|
|
namespace wi
|
|
{
|
|
|
|
// this should always be only INCREMENTED and only if a new serialization is implemeted somewhere!
|
|
static constexpr uint64_t __archiveVersion = 75;
|
|
// this is the version number of which below the archive is not compatible with the current version
|
|
static constexpr uint64_t __archiveVersionBarrier = 22;
|
|
|
|
// version history is logged in ArchiveVersionHistory.txt file!
|
|
|
|
Archive::Archive()
|
|
{
|
|
CreateEmpty();
|
|
}
|
|
Archive::Archive(const std::string& fileName, bool readMode) : fileName(fileName), readMode(readMode)
|
|
{
|
|
if (!fileName.empty())
|
|
{
|
|
directory = wi::helper::GetDirectoryFromPath(fileName);
|
|
if (readMode)
|
|
{
|
|
if (wi::helper::FileRead(fileName, DATA))
|
|
{
|
|
data_ptr = DATA.data();
|
|
(*this) >> version;
|
|
if (version < __archiveVersionBarrier)
|
|
{
|
|
wi::helper::messageBox("The archive version (" + std::to_string(version) + ") is no longer supported!", "Error!");
|
|
Close();
|
|
}
|
|
if (version > __archiveVersion)
|
|
{
|
|
wi::helper::messageBox("The archive version (" + std::to_string(version) + ") is higher than the program's (" + std::to_string(__archiveVersion) + ")!", "Error!");
|
|
Close();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CreateEmpty();
|
|
}
|
|
}
|
|
}
|
|
|
|
Archive::Archive(const uint8_t* data)
|
|
{
|
|
data_ptr = data;
|
|
SetReadModeAndResetPos(true);
|
|
}
|
|
|
|
void Archive::CreateEmpty()
|
|
{
|
|
version = __archiveVersion;
|
|
DATA.resize(128); // starting size
|
|
data_ptr = DATA.data();
|
|
SetReadModeAndResetPos(false);
|
|
}
|
|
|
|
void Archive::SetReadModeAndResetPos(bool isReadMode)
|
|
{
|
|
readMode = isReadMode;
|
|
pos = 0;
|
|
|
|
if (readMode)
|
|
{
|
|
(*this) >> version;
|
|
}
|
|
else
|
|
{
|
|
(*this) << version;
|
|
}
|
|
}
|
|
|
|
void Archive::Close()
|
|
{
|
|
if (!readMode && !fileName.empty())
|
|
{
|
|
SaveFile(fileName);
|
|
}
|
|
DATA.clear();
|
|
}
|
|
|
|
bool Archive::SaveFile(const std::string& fileName)
|
|
{
|
|
return wi::helper::FileWrite(fileName, data_ptr, pos);
|
|
}
|
|
|
|
bool Archive::SaveHeaderFile(const std::string& fileName, const std::string& dataName)
|
|
{
|
|
return wi::helper::Bin2H(data_ptr, pos, fileName, dataName.c_str());
|
|
}
|
|
|
|
const std::string& Archive::GetSourceDirectory() const
|
|
{
|
|
return directory;
|
|
}
|
|
|
|
const std::string& Archive::GetSourceFileName() const
|
|
{
|
|
return fileName;
|
|
}
|
|
|
|
}
|