static puzzle data!
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
#include "../game/Log.h"
|
||||
|
||||
#include "bx/string.h"
|
||||
#include <bx/file.h>
|
||||
#include <cstdint>
|
||||
|
||||
@@ -19,18 +22,21 @@ namespace Generated
|
||||
|
||||
template <typename T> bool WriteT(const char* _4cc, const T& data)
|
||||
{
|
||||
Writer.write(_4cc, 4, &Err);
|
||||
if (!Err.isOk()) return false;
|
||||
if (!Write(_4cc, 4)) return false;
|
||||
|
||||
uint32_t hash = data.Hash;
|
||||
Writer.write(&hash, sizeof(hash), &Err);
|
||||
if (!Write(&hash, sizeof(hash))) return false;
|
||||
|
||||
uint32_t size = sizeof(T);
|
||||
Writer.write(&size, sizeof(size), &Err);
|
||||
return Err.isOk() && Save(&data, 1, *this);
|
||||
if (!Write(&size, sizeof(size))) return false;
|
||||
|
||||
return Save(&data, 1, *this);
|
||||
}
|
||||
|
||||
bool Write(const void* data, uint32_t size)
|
||||
{
|
||||
Writer.write(data, size, &Err);
|
||||
if (!Err.isOk()) LOG_ERROR("Write error: %s", Err.getMessage().getCPtr());
|
||||
return Err.isOk();
|
||||
}
|
||||
|
||||
@@ -56,9 +62,47 @@ namespace Generated
|
||||
bool Read(void* data, uint32_t size)
|
||||
{
|
||||
Reader.read(data, size, &Err);
|
||||
if (!Err.isOk()) LOG_ERROR("Read error: %s", Err.getMessage().getCPtr());
|
||||
return Err.isOk();
|
||||
}
|
||||
|
||||
template <typename T> bool ReadT(const char* _4cc, T& data)
|
||||
{
|
||||
char magic[5]{0};
|
||||
if (!Read(magic, 4)) return false;
|
||||
|
||||
bx::StringView given{_4cc, 4};
|
||||
bx::StringView loaded{magic, 4};
|
||||
if (bx::strCmp(given, loaded) != 0)
|
||||
{
|
||||
LOG_ERROR("Magic mismatch! %s != %s", _4cc, magic);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t hash = 0;
|
||||
if (!Read(&hash, sizeof(hash))) return false;
|
||||
if (data.Hash != hash)
|
||||
{
|
||||
LOG_ERROR("Hash mismatch! %u != %u", data.Hash, hash);
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t size = 0;
|
||||
if (!Read(&size, sizeof(size))) return false;
|
||||
if (sizeof(T) != size)
|
||||
{
|
||||
LOG_ERROR("Size mismatch! %u != %u", sizeof(T), size);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Load(&data, 1, *this))
|
||||
{
|
||||
LOG_ERROR("Failed to load: %s", Err.getMessage().getCPtr());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Finish()
|
||||
{
|
||||
Reader.close();
|
||||
|
||||
Reference in New Issue
Block a user