Material loading works now
This commit is contained in:
+2
-2
@@ -114,8 +114,8 @@ target_precompile_headers(Engine
|
|||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
set(_CRT_SECURE_NO_WARNINGS)
|
set(_CRT_SECURE_NO_WARNINGS)
|
||||||
target_compile_options(Engine PUBLIC /Zi /MP14 /W4 /DEBUG "/WX-")
|
target_compile_options(Engine PUBLIC /std:c++20 /Zi /MP14 /W4 /DEBUG "/WX-")
|
||||||
target_compile_options(Editor PUBLIC /Zi /MP14 /W4 /DEBUG "/WX-")
|
target_compile_options(Editor PUBLIC /std:c++20 /Zi /MP14 /W4 /DEBUG "/WX-")
|
||||||
target_sources(Engine INTERFACE
|
target_sources(Engine INTERFACE
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Seele.natvis>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Seele.natvis>
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/Seele.natvis>
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/Seele.natvis>
|
||||||
|
|||||||
@@ -63,6 +63,6 @@ float4 fragmentMain(
|
|||||||
PointLight pointLight = pointLights[j];
|
PointLight pointLight = pointLights[j];
|
||||||
result += pointLight.illuminate(materialParams, brdf);
|
result += pointLight.illuminate(materialParams, brdf);
|
||||||
}
|
}
|
||||||
return float4(result, 1.0f);
|
return float4(result + float3(0.4f, 0.4f, 0), 0.7f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,20 @@ interface IBRDF
|
|||||||
struct BlinnPhong : IBRDF
|
struct BlinnPhong : IBRDF
|
||||||
{
|
{
|
||||||
float3 baseColor;
|
float3 baseColor;
|
||||||
float metallic = 0;
|
float metallic;
|
||||||
float3 normal = float3(0, 0, 1);
|
float3 normal;
|
||||||
float specular = 0.5;
|
float specular;
|
||||||
float roughness = 0.5;
|
float roughness;
|
||||||
float sheen = 1.f;
|
float sheen;
|
||||||
|
|
||||||
|
__init()
|
||||||
|
{
|
||||||
|
metallic = 0;
|
||||||
|
normal = float3(0, 0, 1);
|
||||||
|
specular = 0.5;
|
||||||
|
roughness = 0.5;
|
||||||
|
sheen = 1;
|
||||||
|
}
|
||||||
|
|
||||||
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
|
float3 evaluate(float3 viewDir_TS, float3 lightDir_TS, float3 lightColor)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ extern AssetRegistry* instance;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string outputPath = "C:/Users/Dynamitos/TrackClearGame";
|
std::string outputPath = "C:/Users/Dynamitos/TrackClearGame";
|
||||||
std::string cmakePath = "C:/Users/Dynamitos/TrackClearGame/cmake";
|
std::string cmakePath = "C:/Users/Dynamitos/TrackClearGame/cmake";
|
||||||
std::string gameName = "TrackClear";
|
std::string gameName = "TrackClear";
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ namespace Seele
|
|||||||
template<class F, class... Args>
|
template<class F, class... Args>
|
||||||
concept invocable = std::invocable<F, Args...>;
|
concept invocable = std::invocable<F, Args...>;
|
||||||
|
|
||||||
template<class T, class Archive>
|
template<class Archive, class T>
|
||||||
concept serializable = requires(const T t, Archive& a)
|
concept serializable = requires(const T& t, Archive& a)
|
||||||
{
|
{
|
||||||
t.save(a);
|
t.save(a);
|
||||||
} && requires(T t, Archive& a)
|
} && requires(T& t, Archive& a)
|
||||||
{
|
{
|
||||||
t.load(a);
|
t.load(a);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include "Array.h"
|
#include "Array.h"
|
||||||
#include "Pair.h"
|
#include "Pair.h"
|
||||||
|
#include "Serialization/Serialization.h"
|
||||||
|
|
||||||
namespace Seele
|
namespace Seele
|
||||||
{
|
{
|
||||||
template <typename K,
|
template <typename K,
|
||||||
@@ -397,6 +399,28 @@ public:
|
|||||||
{
|
{
|
||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
|
void save(ArchiveBuffer& buffer) const
|
||||||
|
{
|
||||||
|
buffer.writeBytes(&_size, sizeof(uint64));
|
||||||
|
for(const auto& [k, v] : *this)
|
||||||
|
{
|
||||||
|
Serialization::save(buffer, k);
|
||||||
|
Serialization::save(buffer, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void load(ArchiveBuffer& buffer)
|
||||||
|
{
|
||||||
|
uint64 len = 0;
|
||||||
|
buffer.readBytes(&len, sizeof(uint64));
|
||||||
|
for(uint64 i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
K k;
|
||||||
|
V v;
|
||||||
|
Serialization::load(buffer, k);
|
||||||
|
Serialization::load(buffer, v);
|
||||||
|
this->operator[](k) = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
void verifyTree()
|
void verifyTree()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ void Material::save(ArchiveBuffer& buffer) const
|
|||||||
MaterialInterface::save(buffer);
|
MaterialInterface::save(buffer);
|
||||||
Serialization::save(buffer, materialName);
|
Serialization::save(buffer, materialName);
|
||||||
Serialization::save(buffer, layout->getSetIndex());
|
Serialization::save(buffer, layout->getSetIndex());
|
||||||
Serialization::save2(buffer, brdf);
|
Serialization::save(buffer, codeExpressions);
|
||||||
|
Serialization::save(buffer, brdf);
|
||||||
const auto& bindings = layout->getBindings();
|
const auto& bindings = layout->getBindings();
|
||||||
Serialization::save(buffer, bindings.size());
|
Serialization::save(buffer, bindings.size());
|
||||||
for (const auto& binding : bindings)
|
for (const auto& binding : bindings)
|
||||||
@@ -74,7 +75,8 @@ void Material::load(ArchiveBuffer& buffer)
|
|||||||
Serialization::load(buffer, materialName);
|
Serialization::load(buffer, materialName);
|
||||||
uint32 setIndex;
|
uint32 setIndex;
|
||||||
Serialization::load(buffer, setIndex);
|
Serialization::load(buffer, setIndex);
|
||||||
Serialization::load2(buffer, brdf);
|
Serialization::load(buffer, codeExpressions);
|
||||||
|
Serialization::load(buffer, brdf);
|
||||||
uint64 numBindings;
|
uint64 numBindings;
|
||||||
Serialization::load(buffer, numBindings);
|
Serialization::load(buffer, numBindings);
|
||||||
layout = graphics->createDescriptorLayout();
|
layout = graphics->createDescriptorLayout();
|
||||||
|
|||||||
@@ -6,13 +6,41 @@
|
|||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
|
|
||||||
|
void ExpressionInput::save(ArchiveBuffer& buffer) const
|
||||||
|
{
|
||||||
|
Serialization::save(buffer, source);
|
||||||
|
Serialization::save(buffer, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExpressionInput::load(ArchiveBuffer& buffer)
|
||||||
|
{
|
||||||
|
Serialization::load(buffer, source);
|
||||||
|
Serialization::load(buffer, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExpressionOutput::save(ArchiveBuffer& buffer) const
|
||||||
|
{
|
||||||
|
Serialization::save(buffer, name);
|
||||||
|
Serialization::save(buffer, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExpressionOutput::load(ArchiveBuffer& buffer)
|
||||||
|
{
|
||||||
|
Serialization::load(buffer, name);
|
||||||
|
Serialization::load(buffer, type);
|
||||||
|
}
|
||||||
|
|
||||||
void ShaderExpression::save(ArchiveBuffer& buffer) const
|
void ShaderExpression::save(ArchiveBuffer& buffer) const
|
||||||
{
|
{
|
||||||
|
Serialization::save(buffer, inputs);
|
||||||
|
Serialization::save(buffer, output);
|
||||||
Serialization::save(buffer, key);
|
Serialization::save(buffer, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderExpression::load(ArchiveBuffer& buffer)
|
void ShaderExpression::load(ArchiveBuffer& buffer)
|
||||||
{
|
{
|
||||||
|
Serialization::load(buffer, inputs);
|
||||||
|
Serialization::load(buffer, output);
|
||||||
Serialization::load(buffer, key);
|
Serialization::load(buffer, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,86 +406,13 @@ void SampleExpression::load(ArchiveBuffer& buffer)
|
|||||||
ShaderExpression::load(buffer);
|
ShaderExpression::load(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Serialization::save(ArchiveBuffer& buffer, const PShaderExpression& parameter)
|
void MaterialNode::save(ArchiveBuffer& buffer) const
|
||||||
{
|
{
|
||||||
Serialization::save(buffer, parameter->getIdentifier());
|
Serialization::save(buffer, profile);
|
||||||
parameter->save(buffer);
|
Serialization::save(buffer, variables);
|
||||||
}
|
}
|
||||||
|
void MaterialNode::load(ArchiveBuffer& buffer)
|
||||||
void Serialization::load(ArchiveBuffer& buffer, PShaderExpression& parameter)
|
|
||||||
{
|
{
|
||||||
uint64 identifier = 0;
|
Serialization::load(buffer, profile);
|
||||||
Serialization::load(buffer, identifier);
|
Serialization::load(buffer, variables);
|
||||||
switch (identifier)
|
|
||||||
{
|
|
||||||
case FloatParameter::IDENTIFIER:
|
|
||||||
parameter = new FloatParameter();
|
|
||||||
break;
|
|
||||||
case VectorParameter::IDENTIFIER:
|
|
||||||
parameter = new VectorParameter();
|
|
||||||
break;
|
|
||||||
case TextureParameter::IDENTIFIER:
|
|
||||||
parameter = new TextureParameter();
|
|
||||||
break;
|
|
||||||
case SamplerParameter::IDENTIFIER:
|
|
||||||
parameter = new SamplerParameter();
|
|
||||||
break;
|
|
||||||
case CombinedTextureParameter::IDENTIFIER:
|
|
||||||
parameter = new CombinedTextureParameter();
|
|
||||||
break;
|
|
||||||
case ConstantExpression::IDENTIFIER:
|
|
||||||
parameter = new ConstantExpression();
|
|
||||||
break;
|
|
||||||
case AddExpression::IDENTIFIER:
|
|
||||||
parameter = new AddExpression();
|
|
||||||
break;
|
|
||||||
case SubExpression::IDENTIFIER:
|
|
||||||
parameter = new SubExpression();
|
|
||||||
break;
|
|
||||||
case MulExpression::IDENTIFIER:
|
|
||||||
parameter = new MulExpression();
|
|
||||||
break;
|
|
||||||
case SwizzleExpression::IDENTIFIER:
|
|
||||||
parameter = new SwizzleExpression();
|
|
||||||
break;
|
|
||||||
case SampleExpression::IDENTIFIER:
|
|
||||||
parameter = new SampleExpression();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw std::runtime_error("Unknown Identifier");
|
|
||||||
}
|
|
||||||
parameter->load(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Serialization::save(ArchiveBuffer& buffer, const PShaderParameter& parameter)
|
|
||||||
{
|
|
||||||
Serialization::save(buffer, parameter->getIdentifier());
|
|
||||||
parameter->save(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Serialization::load(ArchiveBuffer& buffer, PShaderParameter& parameter)
|
|
||||||
{
|
|
||||||
uint64 identifier = 0;
|
|
||||||
Serialization::load(buffer, identifier);
|
|
||||||
switch (identifier)
|
|
||||||
{
|
|
||||||
case FloatParameter::IDENTIFIER:
|
|
||||||
parameter = new FloatParameter();
|
|
||||||
break;
|
|
||||||
case VectorParameter::IDENTIFIER:
|
|
||||||
parameter = new VectorParameter();
|
|
||||||
break;
|
|
||||||
case TextureParameter::IDENTIFIER:
|
|
||||||
parameter = new TextureParameter();
|
|
||||||
break;
|
|
||||||
case SamplerParameter::IDENTIFIER:
|
|
||||||
parameter = new SamplerParameter();
|
|
||||||
break;
|
|
||||||
case CombinedTextureParameter::IDENTIFIER:
|
|
||||||
parameter = new CombinedTextureParameter();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw std::runtime_error("Unknown Identifier");
|
|
||||||
}
|
|
||||||
parameter->load(buffer);
|
|
||||||
}
|
}
|
||||||
@@ -20,11 +20,15 @@ struct ExpressionInput
|
|||||||
{
|
{
|
||||||
int source;
|
int source;
|
||||||
ExpressionType type = ExpressionType::UNKNOWN;
|
ExpressionType type = ExpressionType::UNKNOWN;
|
||||||
|
void save(ArchiveBuffer& buffer) const;
|
||||||
|
void load(ArchiveBuffer& buffer);
|
||||||
};
|
};
|
||||||
struct ExpressionOutput
|
struct ExpressionOutput
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
ExpressionType type = ExpressionType::UNKNOWN;
|
ExpressionType type = ExpressionType::UNKNOWN;
|
||||||
|
void save(ArchiveBuffer& buffer) const;
|
||||||
|
void load(ArchiveBuffer& buffer);
|
||||||
};
|
};
|
||||||
DECLARE_REF(ShaderExpression);
|
DECLARE_REF(ShaderExpression);
|
||||||
struct ShaderExpression
|
struct ShaderExpression
|
||||||
@@ -206,17 +210,97 @@ struct MaterialNode
|
|||||||
std::string profile;
|
std::string profile;
|
||||||
Map<std::string, PShaderExpression> variables;
|
Map<std::string, PShaderExpression> variables;
|
||||||
MaterialNode() {}
|
MaterialNode() {}
|
||||||
virtual ~MaterialNode() {}
|
~MaterialNode() {}
|
||||||
virtual std::string evaluate() const { return ""; }
|
|
||||||
void save(ArchiveBuffer& buffer) const;
|
void save(ArchiveBuffer& buffer) const;
|
||||||
void load(ArchiveBuffer& buffer);
|
void load(ArchiveBuffer& buffer);
|
||||||
};
|
};
|
||||||
DEFINE_REF(MaterialNode)
|
template<>
|
||||||
namespace Serialization
|
static void Serialization::save(ArchiveBuffer& buffer, const PShaderExpression& parameter)
|
||||||
{
|
{
|
||||||
void save(ArchiveBuffer& buffer, const PShaderExpression& parameter);
|
Serialization::save(buffer, parameter->getIdentifier());
|
||||||
void load(ArchiveBuffer& buffer, PShaderExpression& parameter);
|
parameter->save(buffer);
|
||||||
void save(ArchiveBuffer& buffer, const PShaderParameter& parameter);
|
}
|
||||||
void load(ArchiveBuffer& buffer, PShaderParameter& parameter);
|
|
||||||
} // namespace Serialization
|
template<>
|
||||||
|
static void Serialization::load(ArchiveBuffer& buffer, PShaderExpression& parameter)
|
||||||
|
{
|
||||||
|
uint64 identifier = 0;
|
||||||
|
Serialization::load(buffer, identifier);
|
||||||
|
switch (identifier)
|
||||||
|
{
|
||||||
|
case FloatParameter::IDENTIFIER:
|
||||||
|
parameter = new FloatParameter();
|
||||||
|
break;
|
||||||
|
case VectorParameter::IDENTIFIER:
|
||||||
|
parameter = new VectorParameter();
|
||||||
|
break;
|
||||||
|
case TextureParameter::IDENTIFIER:
|
||||||
|
parameter = new TextureParameter();
|
||||||
|
break;
|
||||||
|
case SamplerParameter::IDENTIFIER:
|
||||||
|
parameter = new SamplerParameter();
|
||||||
|
break;
|
||||||
|
case CombinedTextureParameter::IDENTIFIER:
|
||||||
|
parameter = new CombinedTextureParameter();
|
||||||
|
break;
|
||||||
|
case ConstantExpression::IDENTIFIER:
|
||||||
|
parameter = new ConstantExpression();
|
||||||
|
break;
|
||||||
|
case AddExpression::IDENTIFIER:
|
||||||
|
parameter = new AddExpression();
|
||||||
|
break;
|
||||||
|
case SubExpression::IDENTIFIER:
|
||||||
|
parameter = new SubExpression();
|
||||||
|
break;
|
||||||
|
case MulExpression::IDENTIFIER:
|
||||||
|
parameter = new MulExpression();
|
||||||
|
break;
|
||||||
|
case SwizzleExpression::IDENTIFIER:
|
||||||
|
parameter = new SwizzleExpression();
|
||||||
|
break;
|
||||||
|
case SampleExpression::IDENTIFIER:
|
||||||
|
parameter = new SampleExpression();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw std::runtime_error("Unknown Identifier");
|
||||||
|
}
|
||||||
|
parameter->load(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
static void Serialization::save(ArchiveBuffer& buffer, const PShaderParameter& parameter)
|
||||||
|
{
|
||||||
|
Serialization::save(buffer, parameter->getIdentifier());
|
||||||
|
parameter->save(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
static void Serialization::load(ArchiveBuffer& buffer, PShaderParameter& parameter)
|
||||||
|
{
|
||||||
|
uint64 identifier = 0;
|
||||||
|
Serialization::load(buffer, identifier);
|
||||||
|
switch (identifier)
|
||||||
|
{
|
||||||
|
case FloatParameter::IDENTIFIER:
|
||||||
|
parameter = new FloatParameter();
|
||||||
|
break;
|
||||||
|
case VectorParameter::IDENTIFIER:
|
||||||
|
parameter = new VectorParameter();
|
||||||
|
break;
|
||||||
|
case TextureParameter::IDENTIFIER:
|
||||||
|
parameter = new TextureParameter();
|
||||||
|
break;
|
||||||
|
case SamplerParameter::IDENTIFIER:
|
||||||
|
parameter = new SamplerParameter();
|
||||||
|
break;
|
||||||
|
case CombinedTextureParameter::IDENTIFIER:
|
||||||
|
parameter = new CombinedTextureParameter();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw std::runtime_error("Unknown Identifier");
|
||||||
|
}
|
||||||
|
parameter->load(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINE_REF(MaterialNode)
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
#include <nlohmann/json_fwd.hpp>
|
#include <nlohmann/json_fwd.hpp>
|
||||||
#include "Serialization/ArchiveBuffer.h"
|
#include "Serialization/Serialization.h"
|
||||||
|
|
||||||
namespace Seele
|
namespace Seele
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -33,151 +33,4 @@ private:
|
|||||||
uint64 position = 0;
|
uint64 position = 0;
|
||||||
Array<uint8> memory;
|
Array<uint8> memory;
|
||||||
};
|
};
|
||||||
namespace Serialization
|
|
||||||
{
|
|
||||||
template<std::integral T>
|
|
||||||
static void save(ArchiveBuffer& buffer, const T& type)
|
|
||||||
{
|
|
||||||
buffer.writeBytes(&type, sizeof(type));
|
|
||||||
}
|
|
||||||
template<std::integral T>
|
|
||||||
static void load(ArchiveBuffer& buffer, T& type)
|
|
||||||
{
|
|
||||||
buffer.readBytes(&type, sizeof(type));
|
|
||||||
}
|
|
||||||
template<std::floating_point T>
|
|
||||||
static void save(ArchiveBuffer& buffer, const T& type)
|
|
||||||
{
|
|
||||||
buffer.writeBytes(&type, sizeof(type));
|
|
||||||
}
|
|
||||||
template<std::floating_point T>
|
|
||||||
static void load(ArchiveBuffer& buffer, T& type)
|
|
||||||
{
|
|
||||||
buffer.readBytes(&type, sizeof(type));
|
|
||||||
}
|
|
||||||
template<enumeration T>
|
|
||||||
static void save(ArchiveBuffer& buffer, const T& type)
|
|
||||||
{
|
|
||||||
buffer.writeBytes(&type, sizeof(type));
|
|
||||||
}
|
|
||||||
template<enumeration T>
|
|
||||||
static void load(ArchiveBuffer& buffer, T& type)
|
|
||||||
{
|
|
||||||
buffer.readBytes(&type, sizeof(type));
|
|
||||||
}
|
|
||||||
template<typename T>
|
|
||||||
static void save2(ArchiveBuffer& buffer, const T& type) requires(serializable<T>)
|
|
||||||
{
|
|
||||||
type.save(buffer);
|
|
||||||
}
|
|
||||||
template<typename T>
|
|
||||||
static void load2(ArchiveBuffer& buffer, T& type) requires(serializable<T>)
|
|
||||||
{
|
|
||||||
type.load(buffer);
|
|
||||||
}
|
|
||||||
//template<class T>
|
|
||||||
//static void save(ArchiveBuffer& buffer, const T& type)
|
|
||||||
//{
|
|
||||||
// type->save(buffer);
|
|
||||||
//}
|
|
||||||
//template<class T>
|
|
||||||
//static void load(ArchiveBuffer& buffer, T& type)
|
|
||||||
//{
|
|
||||||
// type->load(buffer);
|
|
||||||
//}
|
|
||||||
static void save(ArchiveBuffer& buffer, const std::string& type)
|
|
||||||
{
|
|
||||||
uint64 length = type.size();
|
|
||||||
buffer.writeBytes(&length, sizeof(uint64));
|
|
||||||
buffer.writeBytes(type.data(), type.size() * sizeof(char));
|
|
||||||
}
|
|
||||||
static void load(ArchiveBuffer& buffer, std::string& type)
|
|
||||||
{
|
|
||||||
uint64 length = 0;
|
|
||||||
buffer.readBytes(&length, sizeof(uint64));
|
|
||||||
type.resize(length);
|
|
||||||
buffer.readBytes(type.data(), length * sizeof(char));
|
|
||||||
}
|
|
||||||
//template<typename T>
|
|
||||||
//static void save(ArchiveBuffer& buffer, const RefPtr<T>& ptr)
|
|
||||||
//{
|
|
||||||
// Serialization::save(buffer, *ptr.getHandle());
|
|
||||||
//}
|
|
||||||
//template<typename T>
|
|
||||||
//static void load(ArchiveBuffer& buffer, RefPtr<T>& ptr)
|
|
||||||
//{
|
|
||||||
// Serialization::load(buffer, *ptr.getHandle());
|
|
||||||
//}
|
|
||||||
template<std::integral T>
|
|
||||||
static void save(ArchiveBuffer& buffer, const Array<T>& type)
|
|
||||||
{
|
|
||||||
uint64 length = type.size();
|
|
||||||
buffer.writeBytes(&length, sizeof(uint64));
|
|
||||||
buffer.writeBytes(type.data(), sizeof(T) * type.size());
|
|
||||||
}
|
|
||||||
template<std::integral T>
|
|
||||||
static void load(ArchiveBuffer& buffer, Array<T>& type)
|
|
||||||
{
|
|
||||||
uint64 length = 0;
|
|
||||||
buffer.readBytes(&length, sizeof(uint64));
|
|
||||||
type.resize(length);
|
|
||||||
buffer.readBytes(type.data(), sizeof(T) * type.size());
|
|
||||||
}
|
|
||||||
template<std::floating_point T>
|
|
||||||
static void save(ArchiveBuffer& buffer, const Array<T>& type)
|
|
||||||
{
|
|
||||||
uint64 length = type.size();
|
|
||||||
buffer.writeBytes(&length, sizeof(uint64));
|
|
||||||
buffer.writeBytes(type.data(), sizeof(T) * type.size());
|
|
||||||
}
|
|
||||||
template<std::floating_point T>
|
|
||||||
static void load(ArchiveBuffer& buffer, Array<T>& type)
|
|
||||||
{
|
|
||||||
uint64 length = 0;
|
|
||||||
buffer.readBytes(&length, sizeof(uint64));
|
|
||||||
type.resize(length);
|
|
||||||
buffer.readBytes(type.data(), sizeof(T) * type.size());
|
|
||||||
}
|
|
||||||
template<std::integral T, size_t N>
|
|
||||||
static void save(ArchiveBuffer& buffer, const StaticArray<T, N>& type)
|
|
||||||
{
|
|
||||||
buffer.writeBytes(type.data(), sizeof(T) * N);
|
|
||||||
}
|
|
||||||
template<std::integral T, size_t N>
|
|
||||||
static void load(ArchiveBuffer& buffer, StaticArray<T, N>& type)
|
|
||||||
{
|
|
||||||
buffer.readBytes(type.data(), sizeof(T) * N);
|
|
||||||
}
|
|
||||||
template<std::floating_point T, size_t N>
|
|
||||||
static void save(ArchiveBuffer& buffer, const StaticArray<T, N>& type)
|
|
||||||
{
|
|
||||||
buffer.writeBytes(type.data(), sizeof(T) * N);
|
|
||||||
}
|
|
||||||
template<std::floating_point T, size_t N>
|
|
||||||
static void load(ArchiveBuffer& buffer, StaticArray<T, N>& type)
|
|
||||||
{
|
|
||||||
buffer.readBytes(type.data(), sizeof(T) * N);
|
|
||||||
}
|
|
||||||
template<typename T>
|
|
||||||
static void save(ArchiveBuffer& buffer, const Array<T>& type) requires (!std::is_integral_v<T> && !std::is_floating_point_v<T>)
|
|
||||||
{
|
|
||||||
uint64 length = type.size();
|
|
||||||
buffer.writeBytes(&length, sizeof(uint64));
|
|
||||||
for (const auto& x : type)
|
|
||||||
{
|
|
||||||
save(buffer, x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
template<typename T>
|
|
||||||
static void load(ArchiveBuffer& buffer, Array<T>& type)
|
|
||||||
{
|
|
||||||
uint64 length = 0;
|
|
||||||
buffer.readBytes(&length, sizeof(uint64));
|
|
||||||
type.resize(length);
|
|
||||||
for (auto& x : type)
|
|
||||||
{
|
|
||||||
load(buffer, x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace Serialization
|
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
target_sources(Engine
|
target_sources(Engine
|
||||||
PRIVATE
|
PRIVATE
|
||||||
ArchiveBuffer.h
|
ArchiveBuffer.h
|
||||||
ArchiveBuffer.cpp)
|
ArchiveBuffer.cpp
|
||||||
|
Serialization.h)
|
||||||
|
|
||||||
target_sources(Engine
|
target_sources(Engine
|
||||||
PUBLIC FILE_SET HEADERS
|
PUBLIC FILE_SET HEADERS
|
||||||
FILES
|
FILES
|
||||||
ArchiveBuffer.h)
|
ArchiveBuffer.h
|
||||||
|
Serialization.h)
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "ArchiveBuffer.h"
|
||||||
|
|
||||||
|
namespace Seele
|
||||||
|
{
|
||||||
|
namespace Serialization
|
||||||
|
{
|
||||||
|
template<std::integral T>
|
||||||
|
static void save(ArchiveBuffer& buffer, const T& type)
|
||||||
|
{
|
||||||
|
buffer.writeBytes(&type, sizeof(type));
|
||||||
|
}
|
||||||
|
template<std::integral T>
|
||||||
|
static void load(ArchiveBuffer& buffer, T& type)
|
||||||
|
{
|
||||||
|
buffer.readBytes(&type, sizeof(type));
|
||||||
|
}
|
||||||
|
template<std::floating_point T>
|
||||||
|
static void save(ArchiveBuffer& buffer, const T& type)
|
||||||
|
{
|
||||||
|
buffer.writeBytes(&type, sizeof(type));
|
||||||
|
}
|
||||||
|
template<std::floating_point T>
|
||||||
|
static void load(ArchiveBuffer& buffer, T& type)
|
||||||
|
{
|
||||||
|
buffer.readBytes(&type, sizeof(type));
|
||||||
|
}
|
||||||
|
template<enumeration T>
|
||||||
|
static void save(ArchiveBuffer& buffer, const T& type)
|
||||||
|
{
|
||||||
|
buffer.writeBytes(&type, sizeof(type));
|
||||||
|
}
|
||||||
|
template<enumeration T>
|
||||||
|
static void load(ArchiveBuffer& buffer, T& type)
|
||||||
|
{
|
||||||
|
buffer.readBytes(&type, sizeof(type));
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
static void save(ArchiveBuffer& buffer, const T& type) requires(serializable<ArchiveBuffer, T>)
|
||||||
|
{
|
||||||
|
type.save(buffer);
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
static void load(ArchiveBuffer& buffer, T& type) requires(serializable<ArchiveBuffer, T>)
|
||||||
|
{
|
||||||
|
type.load(buffer);
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
static void save(ArchiveBuffer& buffer, const RefPtr<T>& ptr);
|
||||||
|
template<typename T>
|
||||||
|
static void load(ArchiveBuffer& buffer, RefPtr<T>& ptr);
|
||||||
|
static void save(ArchiveBuffer& buffer, const std::string& type)
|
||||||
|
{
|
||||||
|
uint64 length = type.size();
|
||||||
|
buffer.writeBytes(&length, sizeof(uint64));
|
||||||
|
buffer.writeBytes(type.data(), type.size() * sizeof(char));
|
||||||
|
}
|
||||||
|
static void load(ArchiveBuffer& buffer, std::string& type)
|
||||||
|
{
|
||||||
|
uint64 length = 0;
|
||||||
|
buffer.readBytes(&length, sizeof(uint64));
|
||||||
|
type.resize(length);
|
||||||
|
buffer.readBytes(type.data(), length * sizeof(char));
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
static void save(ArchiveBuffer& buffer, const Array<T>& type) requires (std::is_integral_v<T> || std::is_floating_point_v<T>)
|
||||||
|
{
|
||||||
|
uint64 length = type.size();
|
||||||
|
buffer.writeBytes(&length, sizeof(uint64));
|
||||||
|
buffer.writeBytes(type.data(), sizeof(T) * type.size());
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
static void load(ArchiveBuffer& buffer, Array<T>& type) requires (std::is_integral_v<T> || std::is_floating_point_v<T>)
|
||||||
|
{
|
||||||
|
uint64 length = 0;
|
||||||
|
buffer.readBytes(&length, sizeof(uint64));
|
||||||
|
type.resize(length);
|
||||||
|
buffer.readBytes(type.data(), sizeof(T) * type.size());
|
||||||
|
}
|
||||||
|
template<typename T, size_t N>
|
||||||
|
static void save(ArchiveBuffer& buffer, const StaticArray<T, N>& type) requires (std::is_integral_v<T> || std::is_floating_point_v<T>)
|
||||||
|
{
|
||||||
|
buffer.writeBytes(type.data(), sizeof(T) * N);
|
||||||
|
}
|
||||||
|
template<typename T, size_t N>
|
||||||
|
static void load(ArchiveBuffer& buffer, StaticArray<T, N>& type) requires (std::is_integral_v<T> || std::is_floating_point_v<T>)
|
||||||
|
{
|
||||||
|
buffer.readBytes(type.data(), sizeof(T) * N);
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
static void save(ArchiveBuffer& buffer, const Array<T>& type)
|
||||||
|
{
|
||||||
|
uint64 length = type.size();
|
||||||
|
buffer.writeBytes(&length, sizeof(uint64));
|
||||||
|
for (const auto& x : type)
|
||||||
|
{
|
||||||
|
save(buffer, x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
static void load(ArchiveBuffer& buffer, Array<T>& type)
|
||||||
|
{
|
||||||
|
uint64 length = 0;
|
||||||
|
buffer.readBytes(&length, sizeof(uint64));
|
||||||
|
type.resize(length);
|
||||||
|
for (auto& x : type)
|
||||||
|
{
|
||||||
|
load(buffer, x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace Serialization
|
||||||
|
} // namespace Seele
|
||||||
Reference in New Issue
Block a user