Skip to content

Commit

Permalink
Merge pull request #365 from FlyAndNotDown/master
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyAndNotDown authored Sep 20, 2024
2 parents cc371ca + 3634ea8 commit a4d78d8
Show file tree
Hide file tree
Showing 22 changed files with 596 additions and 275 deletions.
15 changes: 11 additions & 4 deletions Engine/Source/Common/Include/Common/Math/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ namespace Common { // NOLINT
= HashUtils::StrCrc32("Common::Box")
+ Serializer<T>::typeId;

static size_t Serialize(SerializeStream& stream, const Box<T>& value)
static size_t Serialize(BinarySerializeStream& stream, const Box<T>& value)
{
return Serializer<Vec<T, 3>>::Serialize(stream, value.min)
+ Serializer<Vec<T, 3>>::Serialize(stream, value.max);
}

static size_t Deserialize(DeserializeStream& stream, Box<T>& value)
static size_t Deserialize(BinaryDeserializeStream& stream, Box<T>& value)
{
return Serializer<Vec<T, 3>>::Deserialize(stream, value.min)
+ Serializer<Vec<T, 3>>::Deserialize(stream, value.max);
Expand Down Expand Up @@ -100,8 +100,15 @@ namespace Common { // NOLINT

static void JsonDeserialize(const rapidjson::Value& inJsonValue, Box<T>& outValue)
{
JsonSerializer<Vec<T, 3>>::JsonDeserialize(inJsonValue["min"], outValue.min);
JsonSerializer<Vec<T, 3>>::JsonDeserialize(inJsonValue["max"], outValue.max);
if (!inJsonValue.IsObject()) {
return;
}
if (inJsonValue.HasMember("min")) {
JsonSerializer<Vec<T, 3>>::JsonDeserialize(inJsonValue["min"], outValue.min);
}
if (inJsonValue.HasMember("max")) {
JsonSerializer<Vec<T, 3>>::JsonDeserialize(inJsonValue["max"], outValue.max);
}
}
};
}
Expand Down
46 changes: 34 additions & 12 deletions Engine/Source/Common/Include/Common/Math/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ namespace Common {
struct Serializer<Color> {
static constexpr size_t typeId = HashUtils::StrCrc32("Common::Color");

static size_t Serialize(SerializeStream& stream, const Color& value)
static size_t Serialize(BinarySerializeStream& stream, const Color& value)
{
return Serializer<uint8_t>::Serialize(stream, value.r)
+ Serializer<uint8_t>::Serialize(stream, value.g)
+ Serializer<uint8_t>::Serialize(stream, value.b)
+ Serializer<uint8_t>::Serialize(stream, value.a);
}

static size_t Deserialize(DeserializeStream& stream, Color& value)
static size_t Deserialize(BinaryDeserializeStream& stream, Color& value)
{
return Serializer<uint8_t>::Deserialize(stream, value.r)
+ Serializer<uint8_t>::Deserialize(stream, value.g)
Expand All @@ -94,15 +94,15 @@ namespace Common {
struct Serializer<LinearColor> {
static constexpr size_t typeId = HashUtils::StrCrc32("Common::LinearColor");

static size_t Serialize(SerializeStream& stream, const LinearColor& value)
static size_t Serialize(BinarySerializeStream& stream, const LinearColor& value)
{
return Serializer<float>::Serialize(stream, value.r)
+ Serializer<float>::Serialize(stream, value.g)
+ Serializer<float>::Serialize(stream, value.b)
+ Serializer<float>::Serialize(stream, value.a);
}

static size_t Deserialize(DeserializeStream& stream, LinearColor& value)
static size_t Deserialize(BinaryDeserializeStream& stream, LinearColor& value)
{
return Serializer<float>::Deserialize(stream, value.r)
+ Serializer<float>::Deserialize(stream, value.g)
Expand Down Expand Up @@ -154,10 +154,21 @@ namespace Common {

static void JsonDeserialize(const rapidjson::Value& inJsonValue, Color& outValue)
{
outValue.r = static_cast<uint8_t>(inJsonValue["r"].GetUint());
outValue.g = static_cast<uint8_t>(inJsonValue["g"].GetUint());
outValue.b = static_cast<uint8_t>(inJsonValue["b"].GetUint());
outValue.a = static_cast<uint8_t>(inJsonValue["a"].GetUint());
if (!inJsonValue.IsObject()) {
return;
}
if (inJsonValue.HasMember("r") && inJsonValue["r"].IsUint()) {
outValue.r = static_cast<uint8_t>(inJsonValue["r"].GetUint());
}
if (inJsonValue.HasMember("g") && inJsonValue["g"].IsUint()) {
outValue.g = static_cast<uint8_t>(inJsonValue["g"].GetUint());
}
if (inJsonValue.HasMember("b") && inJsonValue["b"].IsUint()) {
outValue.b = static_cast<uint8_t>(inJsonValue["b"].GetUint());
}
if (inJsonValue.HasMember("a") && inJsonValue["a"].IsUint()) {
outValue.a = static_cast<uint8_t>(inJsonValue["a"].GetUint());
}
}
};

Expand All @@ -174,10 +185,21 @@ namespace Common {

static void JsonDeserialize(const rapidjson::Value& inJsonValue, LinearColor& outValue)
{
outValue.r = inJsonValue["r"].GetFloat();
outValue.g = inJsonValue["g"].GetFloat();
outValue.b = inJsonValue["b"].GetFloat();
outValue.a = inJsonValue["a"].GetFloat();
if (!inJsonValue.IsObject()) {
return;
}
if (inJsonValue.HasMember("r") && inJsonValue["r"].IsFloat()) {
outValue.r = inJsonValue["r"].GetFloat();
}
if (inJsonValue.HasMember("g") && inJsonValue["g"].IsFloat()) {
outValue.g = inJsonValue["g"].GetFloat();
}
if (inJsonValue.HasMember("b") && inJsonValue["b"].IsFloat()) {
outValue.b = inJsonValue["b"].GetFloat();
}
if (inJsonValue.HasMember("a") && inJsonValue["a"].IsFloat()) {
outValue.a = inJsonValue["a"].GetFloat();
}
}
};
}
8 changes: 4 additions & 4 deletions Engine/Source/Common/Include/Common/Math/Half.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ namespace Common {
struct Serializer<Internal::FullFloat<E>> {
static constexpr size_t typeId = HashUtils::StrCrc32("Common::Internal::FullFloat");

static size_t Serialize(SerializeStream& stream, const Internal::FullFloat<E>& value)
static size_t Serialize(BinarySerializeStream& stream, const Internal::FullFloat<E>& value)
{
return Serializer<float>::Serialize(stream, value.value);
}

static size_t Deserialize(DeserializeStream& stream, Internal::FullFloat<E>& value)
static size_t Deserialize(BinaryDeserializeStream& stream, Internal::FullFloat<E>& value)
{
return Serializer<float>::Deserialize(stream, value.value);
}
Expand All @@ -101,12 +101,12 @@ namespace Common {
struct Serializer<HalfFloat<E>> {
static constexpr size_t typeId = HashUtils::StrCrc32("Common::Internal::HalfFloat");

static size_t Serialize(SerializeStream& stream, const HalfFloat<E>& value)
static size_t Serialize(BinarySerializeStream& stream, const HalfFloat<E>& value)
{
return Serializer<uint16_t>::Serialize(stream, value.value);
}

static size_t Deserialize(DeserializeStream& stream, HalfFloat<E>& value)
static size_t Deserialize(BinaryDeserializeStream& stream, HalfFloat<E>& value)
{
return Serializer<uint16_t>::Deserialize(stream, value.value);
}
Expand Down
7 changes: 5 additions & 2 deletions Engine/Source/Common/Include/Common/Math/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ namespace Common { // NOLINT
= HashUtils::StrCrc32("Common::Matrix")
+ Serializer<T>::typeId + (R << 8) + C;

static size_t Serialize(SerializeStream& stream, const Mat<T, R, C>& value)
static size_t Serialize(BinarySerializeStream& stream, const Mat<T, R, C>& value)
{
auto serialized = 0;
for (auto i = 0; i < R * C; i++) {
Expand All @@ -317,7 +317,7 @@ namespace Common { // NOLINT
return serialized;
}

static size_t Deserialize(DeserializeStream& stream, Mat<T, R, C>& value)
static size_t Deserialize(BinaryDeserializeStream& stream, Mat<T, R, C>& value)
{
auto deserialized = 0;
for (auto i = 0; i < R * C; i++) {
Expand Down Expand Up @@ -356,6 +356,9 @@ namespace Common { // NOLINT

static void JsonDeserialize(const rapidjson::Value& inJsonValue, Mat<T, R, C>& outValue)
{
if (!inJsonValue.IsArray() || inJsonValue.Size() != R * C) {
return;
}
for (auto i = 0; i < inJsonValue.Size(); i++) {
auto row = i / C;
auto col = i % C;
Expand Down
27 changes: 19 additions & 8 deletions Engine/Source/Common/Include/Common/Math/Projection.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ namespace Common {
= HashUtils::StrCrc32("Common::ReversedZOrthogonalProjection")
+ Serializer<T>::typeId;

static size_t Serialize(SerializeStream& stream, const ReversedZOrthogonalProjection<T>& value)
static size_t Serialize(BinarySerializeStream& stream, const ReversedZOrthogonalProjection<T>& value)
{
return Serializer<T>::Serialize(stream, value.width)
+ Serializer<T>::Serialize(stream, value.height)
+ Serializer<T>::Serialize(stream, value.nearPlane)
+ Serializer<std::optional<T>>::Serialize(stream, value.farPlane);
}

static size_t Deserialize(DeserializeStream& stream, ReversedZOrthogonalProjection<T>& value)
static size_t Deserialize(BinaryDeserializeStream& stream, ReversedZOrthogonalProjection<T>& value)
{
return Serializer<T>::Deserialize(stream, value.width)
+ Serializer<T>::Deserialize(stream, value.height)
Expand All @@ -88,7 +88,7 @@ namespace Common {
= HashUtils::StrCrc32("Common::ReversedZPerspectiveProjection")
+ Serializer<T>::typeId;

static size_t Serialize(SerializeStream& stream, const ReversedZPerspectiveProjection<T>& value)
static size_t Serialize(BinarySerializeStream& stream, const ReversedZPerspectiveProjection<T>& value)
{
return Serializer<T>::Serialize(stream, value.fov)
+ Serializer<T>::Serialize(stream, value.width)
Expand All @@ -97,7 +97,7 @@ namespace Common {
+ Serializer<std::optional<T>>::Serialize(stream, value.farPlane);
}

static size_t Deserialize(DeserializeStream& stream, ReversedZPerspectiveProjection<T>& value)
static size_t Deserialize(BinaryDeserializeStream& stream, ReversedZPerspectiveProjection<T>& value)
{
return Serializer<T>::Deserialize(stream, value.fov)
+ Serializer<T>::Deserialize(stream, value.width)
Expand Down Expand Up @@ -159,10 +159,21 @@ namespace Common {

static void JsonDeserialize(const rapidjson::Value& inJsonValue, ReversedZOrthogonalProjection<T>& outValue)
{
JsonSerializer<T>::JsonDeserialize(inJsonValue["width"], outValue.width);
JsonSerializer<T>::JsonDeserialize(inJsonValue["height"], outValue.height);
JsonSerializer<T>::JsonDeserialize(inJsonValue["near"], outValue.nearPlane);
JsonSerializer<std::optional<T>>::JsonDeserialize(inJsonValue["far"], outValue.farPlane);
if (!inJsonValue.IsObject()) {
return;
}
if (inJsonValue.HasMember("width")) {
JsonSerializer<T>::JsonDeserialize(inJsonValue["width"], outValue.width);
}
if (inJsonValue.HasMember("height")) {
JsonSerializer<T>::JsonDeserialize(inJsonValue["height"], outValue.height);
}
if (inJsonValue.HasMember("near")) {
JsonSerializer<T>::JsonDeserialize(inJsonValue["near"], outValue.nearPlane);
}
if (inJsonValue.HasMember("far")) {
JsonSerializer<std::optional<T>>::JsonDeserialize(inJsonValue["far"], outValue.farPlane);
}
}
};
}
Expand Down
23 changes: 13 additions & 10 deletions Engine/Source/Common/Include/Common/Math/Quaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ namespace Common {
= HashUtils::StrCrc32("Common::Angle")
+ Serializer<T>::typeId;

static size_t Serialize(SerializeStream& stream, const Angle<T>& value)
static size_t Serialize(BinarySerializeStream& stream, const Angle<T>& value)
{
return Serializer<T>::Serialize(stream, value.value);
}

static size_t Deserialize(DeserializeStream& stream, Angle<T>& value)
static size_t Deserialize(BinaryDeserializeStream& stream, Angle<T>& value)
{
return Serializer<T>::Deserialize(stream, value.value);
}
Expand All @@ -144,12 +144,12 @@ namespace Common {
= HashUtils::StrCrc32("Common::Radian")
+ Serializer<T>::typeId;

static size_t Serialize(SerializeStream& stream, const Radian<T>& value)
static size_t Serialize(BinarySerializeStream& stream, const Radian<T>& value)
{
return Serializer<T>::Serialize(stream, value.value);
}

static size_t Deserialize(DeserializeStream& stream, Radian<T>& value)
static size_t Deserialize(BinaryDeserializeStream& stream, Radian<T>& value)
{
return Serializer<T>::Deserialize(stream, value.value);
}
Expand All @@ -161,15 +161,15 @@ namespace Common {
= HashUtils::StrCrc32("Common::Quaternion")
+ Serializer<T>::typeId;

static size_t Serialize(SerializeStream& stream, const Quaternion<T>& value)
static size_t Serialize(BinarySerializeStream& stream, const Quaternion<T>& value)
{
return Serializer<T>::Serialize(stream, value.x)
+ Serializer<T>::Serialize(stream, value.y)
+ Serializer<T>::Serialize(stream, value.z)
+ Serializer<T>::Serialize(stream, value.w);
}

static size_t Deserialize(DeserializeStream& stream, Quaternion<T>& value)
static size_t Deserialize(BinaryDeserializeStream& stream, Quaternion<T>& value)
{
return Serializer<T>::Deserialize(stream, value.x)
+ Serializer<T>::Deserialize(stream, value.y)
Expand Down Expand Up @@ -211,25 +211,25 @@ namespace Common {
struct JsonSerializer<Angle<T>> {
static void JsonSerialize(rapidjson::Value& outJsonValue, rapidjson::Document::AllocatorType& inAllocator, const Angle<T>& inValue)
{
outJsonValue.SetFloat(inValue.value);
JsonSerializer<T>::JsonSerialize(outJsonValue, inAllocator, inValue.value);
}

static void JsonDeserialize(const rapidjson::Value& inJsonValue, Angle<T>& outValue)
{
outValue.value = inJsonValue.GetFloat();
JsonSerializer<T>::JsonDeserialize(inJsonValue, outValue.value);
}
};

template <JsonSerializable T>
struct JsonSerializer<Radian<T>> {
static void JsonSerialize(rapidjson::Value& outJsonValue, rapidjson::Document::AllocatorType& inAllocator, const Radian<T>& inValue)
{
outJsonValue.SetFloat(inValue.value);
JsonSerializer<T>::JsonSerialize(outJsonValue, inAllocator, inValue.value);
}

static void JsonDeserialize(const rapidjson::Value& inJsonValue, Radian<T>& outValue)
{
outValue.value = inJsonValue.GetFloat();
JsonSerializer<T>::JsonDeserialize(inJsonValue, outValue.value);
}
};

Expand Down Expand Up @@ -258,6 +258,9 @@ namespace Common {

static void JsonDeserialize(const rapidjson::Value& inJsonValue, Quaternion<T>& outValue)
{
if (!inJsonValue.IsArray() || inJsonValue.Size() != 4) {
return;
}
JsonSerializer<T>::JsonDeserialize(inJsonValue[0], outValue.x);
JsonSerializer<T>::JsonDeserialize(inJsonValue[1], outValue.y);
JsonSerializer<T>::JsonDeserialize(inJsonValue[2], outValue.z);
Expand Down
15 changes: 11 additions & 4 deletions Engine/Source/Common/Include/Common/Math/Rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ namespace Common {
= HashUtils::StrCrc32("Common::Rect")
+ Serializer<T>::typeId;

static size_t Serialize(SerializeStream& stream, const Rect<T>& value)
static size_t Serialize(BinarySerializeStream& stream, const Rect<T>& value)
{
return Serializer<Vec<T, 2>>::Serialize(stream, value.min)
+ Serializer<Vec<T, 2>>::Serialize(stream, value.max);
}

static size_t Deserialize(DeserializeStream& stream, Rect<T>& value)
static size_t Deserialize(BinaryDeserializeStream& stream, Rect<T>& value)
{
return Serializer<Vec<T, 2>>::Deserialize(stream, value.min)
+ Serializer<Vec<T, 2>>::Deserialize(stream, value.max);
Expand Down Expand Up @@ -98,8 +98,15 @@ namespace Common {

static void JsonDeserialize(const rapidjson::Value& inJsonValue, Rect<T>& outValue)
{
JsonSerializer<Vec<T, 2>>::JsonDeserialize(inJsonValue["min"], outValue.min);
JsonSerializer<Vec<T, 2>>::JsonDeserialize(inJsonValue["max"], outValue.max);
if (!inJsonValue.IsObject()) {
return;
}
if (inJsonValue.HasMember("min")) {
JsonSerializer<Vec<T, 2>>::JsonDeserialize(inJsonValue["min"], outValue.min);
}
if (inJsonValue.HasMember("max")) {
JsonSerializer<Vec<T, 2>>::JsonDeserialize(inJsonValue["max"], outValue.max);
}
}
};
}
Expand Down
15 changes: 11 additions & 4 deletions Engine/Source/Common/Include/Common/Math/Sphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ namespace Common {
= HashUtils::StrCrc32("Common::Sphere")
+ Serializer<T>::typeId;

static size_t Serialize(SerializeStream& stream, const Sphere<T>& value)
static size_t Serialize(BinarySerializeStream& stream, const Sphere<T>& value)
{
return Serializer<Vec<T, 3>>::Serialize(stream, value.center)
+ Serializer<T>::Serialize(stream, value.radius);
}

static size_t Deserialize(DeserializeStream& stream, Sphere<T>& value)
static size_t Deserialize(BinaryDeserializeStream& stream, Sphere<T>& value)
{
return Serializer<Vec<T, 3>>::Deserialize(stream, value.center)
+ Serializer<T>::Deserialize(stream, value.radius);
Expand Down Expand Up @@ -86,8 +86,15 @@ namespace Common {

static void JsonDeserialize(const rapidjson::Value& inJsonValue, Sphere<T>& outValue)
{
JsonSerializer<Vec<T, 3>>::JsonDeserialize(inJsonValue["center"], outValue.center);
JsonSerializer<T>::JsonDeserialize(inJsonValue["radius", outValue.radius]);
if (!inJsonValue.IsObject()) {
return;
}
if (inJsonValue.HasMember("center")) {
JsonSerializer<Vec<T, 3>>::JsonDeserialize(inJsonValue["center"], outValue.center);
}
if (inJsonValue.HasMember("radius")) {
JsonSerializer<T>::JsonDeserialize(inJsonValue["radius", outValue.radius]);
}
}
};
}
Expand Down
Loading

0 comments on commit a4d78d8

Please sign in to comment.