serialization stuff
This commit is contained in:
@@ -105,9 +105,8 @@ namespace Game
|
||||
LOG("Loading %s", fullPath.getCPtr());
|
||||
|
||||
Generated::Deserializer ser;
|
||||
ser.Init(fullPath);
|
||||
Generated::PuzzleData dataBuf;
|
||||
if (ser.ReadT("PZZL", dataBuf))
|
||||
if (ser.Init(fullPath, "PZZL") && ser.ReadT(dataBuf))
|
||||
{
|
||||
if (dataBuf.ID >= BX_COUNTOF(Puzzles))
|
||||
{
|
||||
|
||||
@@ -42,8 +42,7 @@ namespace Puzzle
|
||||
void LoadStaticPuzzleData()
|
||||
{
|
||||
Deserializer ser;
|
||||
ser.Init("game/data/static/puzzle.dat");
|
||||
if (ser.ReadT("SPUZ", StaticData))
|
||||
if (ser.Init("game/data/static/puzzle.dat", "SPUZ") && ser.ReadT(StaticData))
|
||||
{
|
||||
LOG("Successfully loaded static puzzle data!");
|
||||
}
|
||||
@@ -54,8 +53,7 @@ namespace Puzzle
|
||||
{
|
||||
auto& data = GetStaticPuzzleData();
|
||||
Serializer ser;
|
||||
ser.Init("game/data/static/puzzle.dat");
|
||||
if (ser.WriteT("SPUZ", GetStaticPuzzleData()))
|
||||
if (ser.Init("game/data/static/puzzle.dat", "SPUZ") && ser.WriteT(GetStaticPuzzleData()))
|
||||
{
|
||||
LOG("Successfully saved static puzzle data!");
|
||||
}
|
||||
@@ -576,8 +574,7 @@ namespace Puzzle
|
||||
char path[128]{0};
|
||||
WritePuzzleFilePath(path, sizeof(path), obj.ID);
|
||||
Serializer ser;
|
||||
ser.Init(path);
|
||||
if (ser.WriteT("PZZL", obj))
|
||||
if (ser.Init(path, "PZZL") && ser.WriteT(obj))
|
||||
{
|
||||
LOG("Saved to %s", path);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "Serial.h"
|
||||
#include <cstdint>
|
||||
#include <imgui.h>
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#include "Global.h"
|
||||
#include "Log.h"
|
||||
#include "Serial.h"
|
||||
#include "bx/bx.h"
|
||||
#include "bx/file.h"
|
||||
#include "bx/filepath.h"
|
||||
|
||||
void SerializeStruct(void* data, uint64_t size, const char* path)
|
||||
{
|
||||
bx::Error err;
|
||||
bx::FilePath filePath{path};
|
||||
bx::FileWriter writer;
|
||||
if (writer.open(filePath, false, &err))
|
||||
{
|
||||
if (!writer.write(data, size, &err))
|
||||
{
|
||||
LOG_ERROR("Failed to write to file %s: %s", path, err.getMessage().getCPtr());
|
||||
writer.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Failed to open file %s: %s", path, err.getMessage().getCPtr());
|
||||
return;
|
||||
}
|
||||
LOG("Successful serialization");
|
||||
}
|
||||
|
||||
void DeserializeStruct(void* data, SerializationHeader& expectedHeader, const char* path)
|
||||
{
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#include <cstdint>
|
||||
|
||||
struct SerializationHeader
|
||||
{
|
||||
uint8_t _ID0 = 0;
|
||||
uint8_t _ID1 = 0;
|
||||
uint8_t _ID2 = 0;
|
||||
uint8_t _ID3 = 0;
|
||||
uint8_t HeaderVersion = 0;
|
||||
uint8_t VersionNum = 0;
|
||||
uint8_t Reserved0 = 0;
|
||||
uint8_t Reserved1 = 0;
|
||||
};
|
||||
|
||||
#define SER_HEADER(Version, FCC) \
|
||||
SerializationHeader __Header{ \
|
||||
FCC[0], \
|
||||
FCC[1], \
|
||||
FCC[2], \
|
||||
FCC[3], \
|
||||
1, \
|
||||
Version, \
|
||||
0, \
|
||||
0, \
|
||||
}; \
|
||||
bool VersionMatches(uint8_t headerVersion, uint8_t versionNum) \
|
||||
{ \
|
||||
return headerVersion == 1 && versionNum == Version; \
|
||||
}
|
||||
|
||||
void SerializeStruct(void* data, uint64_t size, const char* path);
|
||||
void DeserializeStruct(void* data, SerializationHeader& expectedHeader, const char* path);
|
||||
Reference in New Issue
Block a user