Material loading works now
This commit is contained in:
+2
-2
@@ -114,8 +114,8 @@ target_precompile_headers(Engine
|
||||
|
||||
if(MSVC)
|
||||
set(_CRT_SECURE_NO_WARNINGS)
|
||||
target_compile_options(Engine PUBLIC /Zi /MP14 /W4 /DEBUG "/WX-")
|
||||
target_compile_options(Editor PUBLIC /Zi /MP14 /W4 /DEBUG "/WX-")
|
||||
target_compile_options(Engine PUBLIC /std:c++20 /Zi /MP14 /W4 /DEBUG "/WX-")
|
||||
target_compile_options(Editor PUBLIC /std:c++20 /Zi /MP14 /W4 /DEBUG "/WX-")
|
||||
target_sources(Engine INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Seele.natvis>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/Seele.natvis>
|
||||
|
||||
@@ -63,6 +63,6 @@ float4 fragmentMain(
|
||||
PointLight pointLight = pointLights[j];
|
||||
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
|
||||
{
|
||||
float3 baseColor;
|
||||
float metallic = 0;
|
||||
float3 normal = float3(0, 0, 1);
|
||||
float specular = 0.5;
|
||||
float roughness = 0.5;
|
||||
float sheen = 1.f;
|
||||
float metallic;
|
||||
float3 normal;
|
||||
float specular;
|
||||
float roughness;
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,6 @@ extern AssetRegistry* instance;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
std::string outputPath = "C:/Users/Dynamitos/TrackClearGame";
|
||||
std::string cmakePath = "C:/Users/Dynamitos/TrackClearGame/cmake";
|
||||
std::string gameName = "TrackClear";
|
||||
|
||||
@@ -6,11 +6,11 @@ namespace Seele
|
||||
template<class F, class... Args>
|
||||
concept invocable = std::invocable<F, Args...>;
|
||||
|
||||
template<class T, class Archive>
|
||||
concept serializable = requires(const T t, Archive& a)
|
||||
template<class Archive, class T>
|
||||
concept serializable = requires(const T& t, Archive& a)
|
||||
{
|
||||
t.save(a);
|
||||
} && requires(T t, Archive& a)
|
||||
} && requires(T& t, Archive& a)
|
||||
{
|
||||
t.load(a);
|
||||
};
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include <utility>
|
||||
#include "Array.h"
|
||||
#include "Pair.h"
|
||||
#include "Serialization/Serialization.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
template <typename K,
|
||||
@@ -397,6 +399,28 @@ public:
|
||||
{
|
||||
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:
|
||||
void verifyTree()
|
||||
{
|
||||
|
||||
@@ -54,7 +54,8 @@ void Material::save(ArchiveBuffer& buffer) const
|
||||
MaterialInterface::save(buffer);
|
||||
Serialization::save(buffer, materialName);
|
||||
Serialization::save(buffer, layout->getSetIndex());
|
||||
Serialization::save2(buffer, brdf);
|
||||
Serialization::save(buffer, codeExpressions);
|
||||
Serialization::save(buffer, brdf);
|
||||
const auto& bindings = layout->getBindings();
|
||||
Serialization::save(buffer, bindings.size());
|
||||
for (const auto& binding : bindings)
|
||||
@@ -74,7 +75,8 @@ void Material::load(ArchiveBuffer& buffer)
|
||||
Serialization::load(buffer, materialName);
|
||||
uint32 setIndex;
|
||||
Serialization::load(buffer, setIndex);
|
||||
Serialization::load2(buffer, brdf);
|
||||
Serialization::load(buffer, codeExpressions);
|
||||
Serialization::load(buffer, brdf);
|
||||
uint64 numBindings;
|
||||
Serialization::load(buffer, numBindings);
|
||||
layout = graphics->createDescriptorLayout();
|
||||
|
||||
@@ -6,13 +6,41 @@
|
||||
|
||||
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
|
||||
{
|
||||
Serialization::save(buffer, inputs);
|
||||
Serialization::save(buffer, output);
|
||||
Serialization::save(buffer, key);
|
||||
}
|
||||
|
||||
void ShaderExpression::load(ArchiveBuffer& buffer)
|
||||
{
|
||||
Serialization::load(buffer, inputs);
|
||||
Serialization::load(buffer, output);
|
||||
Serialization::load(buffer, key);
|
||||
}
|
||||
|
||||
@@ -378,86 +406,13 @@ void SampleExpression::load(ArchiveBuffer& buffer)
|
||||
ShaderExpression::load(buffer);
|
||||
}
|
||||
|
||||
void Serialization::save(ArchiveBuffer& buffer, const PShaderExpression& parameter)
|
||||
void MaterialNode::save(ArchiveBuffer& buffer) const
|
||||
{
|
||||
Serialization::save(buffer, parameter->getIdentifier());
|
||||
parameter->save(buffer);
|
||||
Serialization::save(buffer, profile);
|
||||
Serialization::save(buffer, variables);
|
||||
}
|
||||
|
||||
void Serialization::load(ArchiveBuffer& buffer, PShaderExpression& parameter)
|
||||
void MaterialNode::load(ArchiveBuffer& buffer)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
Serialization::load(buffer, profile);
|
||||
Serialization::load(buffer, variables);
|
||||
}
|
||||
@@ -20,11 +20,15 @@ struct ExpressionInput
|
||||
{
|
||||
int source;
|
||||
ExpressionType type = ExpressionType::UNKNOWN;
|
||||
void save(ArchiveBuffer& buffer) const;
|
||||
void load(ArchiveBuffer& buffer);
|
||||
};
|
||||
struct ExpressionOutput
|
||||
{
|
||||
std::string name;
|
||||
ExpressionType type = ExpressionType::UNKNOWN;
|
||||
void save(ArchiveBuffer& buffer) const;
|
||||
void load(ArchiveBuffer& buffer);
|
||||
};
|
||||
DECLARE_REF(ShaderExpression);
|
||||
struct ShaderExpression
|
||||
@@ -206,17 +210,97 @@ struct MaterialNode
|
||||
std::string profile;
|
||||
Map<std::string, PShaderExpression> variables;
|
||||
MaterialNode() {}
|
||||
virtual ~MaterialNode() {}
|
||||
virtual std::string evaluate() const { return ""; }
|
||||
~MaterialNode() {}
|
||||
void save(ArchiveBuffer& buffer) const;
|
||||
void load(ArchiveBuffer& buffer);
|
||||
};
|
||||
DEFINE_REF(MaterialNode)
|
||||
namespace Serialization
|
||||
template<>
|
||||
static void Serialization::save(ArchiveBuffer& buffer, const PShaderExpression& parameter)
|
||||
{
|
||||
void save(ArchiveBuffer& buffer, const PShaderExpression& parameter);
|
||||
void load(ArchiveBuffer& buffer, PShaderExpression& parameter);
|
||||
void save(ArchiveBuffer& buffer, const PShaderParameter& parameter);
|
||||
void load(ArchiveBuffer& buffer, PShaderParameter& parameter);
|
||||
} // namespace Serialization
|
||||
Serialization::save(buffer, parameter->getIdentifier());
|
||||
parameter->save(buffer);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#pragma warning(pop)
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include "Serialization/ArchiveBuffer.h"
|
||||
#include "Serialization/Serialization.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
|
||||
@@ -33,151 +33,4 @@ private:
|
||||
uint64 position = 0;
|
||||
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
|
||||
@@ -1,9 +1,11 @@
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
ArchiveBuffer.h
|
||||
ArchiveBuffer.cpp)
|
||||
ArchiveBuffer.cpp
|
||||
Serialization.h)
|
||||
|
||||
target_sources(Engine
|
||||
PUBLIC FILE_SET HEADERS
|
||||
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