Compare commits
3 Commits
b006d14197
...
c244b997c1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c244b997c1 | ||
|
|
6d170be57a | ||
|
|
052fc2cc07 |
@@ -9,7 +9,7 @@
|
|||||||
#include <winnt.h>
|
#include <winnt.h>
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include "Windows.h"
|
#include "Windows.h" // IWYU pragma: keep
|
||||||
|
|
||||||
namespace WriteTemplates
|
namespace WriteTemplates
|
||||||
{
|
{
|
||||||
@@ -17,7 +17,7 @@ namespace WriteTemplates
|
|||||||
R"END(#pragma once
|
R"END(#pragma once
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
struct Serializer;
|
struct Serializer;
|
||||||
struct Deserializer;
|
struct Deserializer;
|
||||||
@@ -25,7 +25,7 @@ namespace Generated
|
|||||||
constexpr char FileCppStart[] = R"END(#include "Def.h"
|
constexpr char FileCppStart[] = R"END(#include "Def.h"
|
||||||
#include "Generated.h"
|
#include "Generated.h"
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
)END";
|
)END";
|
||||||
|
|
||||||
@@ -171,9 +171,9 @@ void CppFileWriter::PrintTypeName(char* buf,
|
|||||||
{
|
{
|
||||||
if (type.FieldKind == Def::EFieldType::Native)
|
if (type.FieldKind == Def::EFieldType::Native)
|
||||||
{
|
{
|
||||||
if (int32_t(type.Native) < Generated::KnownType::EntryCount)
|
if (int32_t(type.Native) < Gen::KnownType::EntryCount)
|
||||||
{
|
{
|
||||||
bx::strCopy(buf, bufSize, Generated::KnownType::CName[size_t(type.Native)]);
|
bx::strCopy(buf, bufSize, Gen::KnownType::CName[size_t(type.Native)]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -201,7 +201,7 @@ void CppFileWriter::WriteEnums(const Def::DefinitionFile& definitions)
|
|||||||
e.Name,
|
e.Name,
|
||||||
e.EntryCount,
|
e.EntryCount,
|
||||||
e.Hash,
|
e.Hash,
|
||||||
Generated::KnownType::CName[(int32_t)e.EnumType.Native]);
|
Gen::KnownType::CName[(int32_t)e.EnumType.Native]);
|
||||||
for (int32_t entryIdx = 0; entryIdx < e.EntryCount; ++entryIdx)
|
for (int32_t entryIdx = 0; entryIdx < e.EntryCount; ++entryIdx)
|
||||||
{
|
{
|
||||||
Write(WriteTemplates::EnumField1, e.EntryNames[entryIdx]);
|
Write(WriteTemplates::EnumField1, e.EntryNames[entryIdx]);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
template bool Save<T>(const T* obj, uint32_t count, Serializer& serializer); \
|
template bool Save<T>(const T* obj, uint32_t count, Serializer& serializer); \
|
||||||
template bool Load<T>(T * obj, uint32_t count, Deserializer & serializer);
|
template bool Load<T>(T * obj, uint32_t count, Deserializer & serializer);
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
template <typename T> bool Save(const T* obj, uint32_t count, Serializer& serializer)
|
template <typename T> bool Save(const T* obj, uint32_t count, Serializer& serializer)
|
||||||
{
|
{
|
||||||
@@ -38,4 +38,4 @@ namespace Generated
|
|||||||
INST(double)
|
INST(double)
|
||||||
INST(bool)
|
INST(bool)
|
||||||
INST(char)
|
INST(char)
|
||||||
} // namespace Generated
|
} // namespace Gen
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#define LOG_ERROR(...)
|
#define LOG_ERROR(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
struct EmbeddedTypeDef
|
struct EmbeddedTypeDef
|
||||||
{
|
{
|
||||||
@@ -122,4 +122,4 @@ namespace Generated
|
|||||||
|
|
||||||
template <typename T> bool Save(const T* obj, uint32_t count, Serializer& serializer);
|
template <typename T> bool Save(const T* obj, uint32_t count, Serializer& serializer);
|
||||||
template <typename T> bool Load(T* obj, uint32_t count, Deserializer& serializer);
|
template <typename T> bool Load(T* obj, uint32_t count, Deserializer& serializer);
|
||||||
} // namespace Generated
|
} // namespace Gen
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "Def.h"
|
#include "Def.h"
|
||||||
#include "Generated.h"
|
#include "Generated.h"
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
bool Save(const KnownType::Enum* obj, uint32_t count, Serializer& serializer)
|
bool Save(const KnownType::Enum* obj, uint32_t count, Serializer& serializer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
struct Serializer;
|
struct Serializer;
|
||||||
struct Deserializer;
|
struct Deserializer;
|
||||||
|
|||||||
@@ -348,12 +348,12 @@ Parser::Result Parser::ReadTypeToken()
|
|||||||
Parser::Result Parser::ReadNativeFieldType(Def::FieldType& FieldT)
|
Parser::Result Parser::ReadNativeFieldType(Def::FieldType& FieldT)
|
||||||
{
|
{
|
||||||
Result Res = OK;
|
Result Res = OK;
|
||||||
for (int32_t i = 0; i < Generated::KnownType::EntryCount; ++i)
|
for (int32_t i = 0; i < Gen::KnownType::EntryCount; ++i)
|
||||||
{
|
{
|
||||||
if (CmpAdvance(Generated::KnownType::EntryNames[i], Res, true) && Res == OK)
|
if (CmpAdvance(Gen::KnownType::EntryNames[i], Res, true) && Res == OK)
|
||||||
{
|
{
|
||||||
FieldT.FieldKind = Def::EFieldType::Native;
|
FieldT.FieldKind = Def::EFieldType::Native;
|
||||||
FieldT.Native = Generated::KnownType::Enum(i);
|
FieldT.Native = Gen::KnownType::Enum(i);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Def
|
|||||||
struct FieldType
|
struct FieldType
|
||||||
{
|
{
|
||||||
EFieldType FieldKind = EFieldType::Native;
|
EFieldType FieldKind = EFieldType::Native;
|
||||||
Generated::KnownType::Enum Native = Generated::KnownType::Enum::i32;
|
Gen::KnownType::Enum Native = Gen::KnownType::Enum::i32;
|
||||||
uint16_t TypeIdx = UINT16_MAX;
|
uint16_t TypeIdx = UINT16_MAX;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
319
src/game/Gen.cpp
319
src/game/Gen.cpp
@@ -1,6 +1,6 @@
|
|||||||
#include "Gen.h"
|
#include "Gen.h"
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
bool IsValid(const ModelHandle& h)
|
bool IsValid(const ModelHandle& h)
|
||||||
{
|
{
|
||||||
@@ -49,4 +49,319 @@ namespace Generated
|
|||||||
res.Y += rhs.Y;
|
res.Y += rhs.Y;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} // namespace Generated
|
|
||||||
|
// Vec4
|
||||||
|
Vec4& operator+=(Vec4& lhs, const Vec4& rhs)
|
||||||
|
{
|
||||||
|
lhs.x += rhs.x;
|
||||||
|
lhs.y += rhs.y;
|
||||||
|
lhs.z += rhs.z;
|
||||||
|
lhs.w += rhs.w;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec4 operator+(const Vec4& lhs, const Vec4& rhs)
|
||||||
|
{
|
||||||
|
Vec4 out = lhs;
|
||||||
|
return out += rhs;
|
||||||
|
}
|
||||||
|
Vec4& operator+=(Vec4& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x += rhs;
|
||||||
|
lhs.y += rhs;
|
||||||
|
lhs.z += rhs;
|
||||||
|
lhs.w += rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec4 operator+(Vec4& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec4 out = lhs;
|
||||||
|
return out += rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec4& operator-=(Vec4& lhs, const Vec4& rhs)
|
||||||
|
{
|
||||||
|
lhs.x -= rhs.x;
|
||||||
|
lhs.y -= rhs.y;
|
||||||
|
lhs.z -= rhs.z;
|
||||||
|
lhs.w -= rhs.w;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec4 operator-(const Vec4& lhs, const Vec4& rhs)
|
||||||
|
{
|
||||||
|
Vec4 out = lhs;
|
||||||
|
return out -= rhs;
|
||||||
|
}
|
||||||
|
Vec4& operator-=(Vec4& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x -= rhs;
|
||||||
|
lhs.y -= rhs;
|
||||||
|
lhs.z -= rhs;
|
||||||
|
lhs.w -= rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec4 operator-(const Vec4& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec4 out = lhs;
|
||||||
|
return out -= rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec4& operator*=(Vec4& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x *= rhs;
|
||||||
|
lhs.y *= rhs;
|
||||||
|
lhs.z *= rhs;
|
||||||
|
lhs.w *= rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec4 operator*(const Vec4& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec4 out = lhs;
|
||||||
|
return out *= rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec4& operator/=(Vec4& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x /= rhs;
|
||||||
|
lhs.y /= rhs;
|
||||||
|
lhs.z /= rhs;
|
||||||
|
lhs.w /= rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec4 operator/(const Vec4& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec4 out = lhs;
|
||||||
|
return out /= rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vec3
|
||||||
|
Vec3& operator+=(Vec3& lhs, const Vec3& rhs)
|
||||||
|
{
|
||||||
|
lhs.x += rhs.x;
|
||||||
|
lhs.y += rhs.y;
|
||||||
|
lhs.z += rhs.z;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec3 operator+(const Vec3& lhs, const Vec3& rhs)
|
||||||
|
{
|
||||||
|
Vec3 out = lhs;
|
||||||
|
return out += rhs;
|
||||||
|
}
|
||||||
|
Vec3& operator+=(Vec3& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x += rhs;
|
||||||
|
lhs.y += rhs;
|
||||||
|
lhs.z += rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec3 operator+(Vec3& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec3 out = lhs;
|
||||||
|
return out += rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3& operator-=(Vec3& lhs, const Vec3& rhs)
|
||||||
|
{
|
||||||
|
lhs.x -= rhs.x;
|
||||||
|
lhs.y -= rhs.y;
|
||||||
|
lhs.z -= rhs.z;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec3 operator-(const Vec3& lhs, const Vec3& rhs)
|
||||||
|
{
|
||||||
|
Vec3 out = lhs;
|
||||||
|
return out -= rhs;
|
||||||
|
}
|
||||||
|
Vec3& operator-=(Vec3& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x -= rhs;
|
||||||
|
lhs.y -= rhs;
|
||||||
|
lhs.z -= rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec3 operator-(const Vec3& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec3 out = lhs;
|
||||||
|
return out -= rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3& operator*=(Vec3& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x *= rhs;
|
||||||
|
lhs.y *= rhs;
|
||||||
|
lhs.z *= rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec3 operator*(const Vec3& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec3 out = lhs;
|
||||||
|
return out *= rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3& operator/=(Vec3& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x /= rhs;
|
||||||
|
lhs.y /= rhs;
|
||||||
|
lhs.z /= rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec3 operator/(const Vec3& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec3 out = lhs;
|
||||||
|
return out /= rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vec2
|
||||||
|
Vec2& operator+=(Vec2& lhs, const Vec2& rhs)
|
||||||
|
{
|
||||||
|
lhs.x += rhs.x;
|
||||||
|
lhs.y += rhs.y;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec2 operator+(const Vec2& lhs, const Vec2& rhs)
|
||||||
|
{
|
||||||
|
Vec2 out = lhs;
|
||||||
|
return out += rhs;
|
||||||
|
}
|
||||||
|
Vec2& operator+=(Vec2& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x += rhs;
|
||||||
|
lhs.y += rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec2 operator+(Vec2& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec2 out = lhs;
|
||||||
|
return out += rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2& operator-=(Vec2& lhs, const Vec2& rhs)
|
||||||
|
{
|
||||||
|
lhs.x -= rhs.x;
|
||||||
|
lhs.y -= rhs.y;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec2 operator-(const Vec2& lhs, const Vec2& rhs)
|
||||||
|
{
|
||||||
|
Vec2 out = lhs;
|
||||||
|
return out -= rhs;
|
||||||
|
}
|
||||||
|
Vec2& operator-=(Vec2& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x -= rhs;
|
||||||
|
lhs.y -= rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec2 operator-(const Vec2& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec2 out = lhs;
|
||||||
|
return out -= rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2& operator*=(Vec2& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x *= rhs;
|
||||||
|
lhs.y *= rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec2 operator*(const Vec2& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec2 out = lhs;
|
||||||
|
return out *= rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2& operator/=(Vec2& lhs, float rhs)
|
||||||
|
{
|
||||||
|
lhs.x /= rhs;
|
||||||
|
lhs.y /= rhs;
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
Vec2 operator/(const Vec2& lhs, float rhs)
|
||||||
|
{
|
||||||
|
Vec2 out = lhs;
|
||||||
|
return out /= rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat4 Inverse(const Mat4& mat)
|
||||||
|
{
|
||||||
|
Mat4 result;
|
||||||
|
bx::mtxInverse(result.M, &mat.M[0]);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
Mat4 Transpose(const Mat4& mat)
|
||||||
|
{
|
||||||
|
Mat4 result;
|
||||||
|
bx::mtxTranspose(result.M, &mat.M[0]);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
Vec4 Mul(const Mat4& mat, const Vec4& vec)
|
||||||
|
{
|
||||||
|
Vec4 out;
|
||||||
|
bx::vec4MulMtx(&out.x, &vec.x, &mat.M[0]);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Magnitude(const Vec4& vec)
|
||||||
|
{
|
||||||
|
return bx::sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z + vec.w * vec.w);
|
||||||
|
}
|
||||||
|
float Magnitude(const Vec3& vec)
|
||||||
|
{
|
||||||
|
return bx::sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
|
||||||
|
}
|
||||||
|
float Magnitude(const Vec2& vec)
|
||||||
|
{
|
||||||
|
return bx::sqrt(vec.x * vec.x + vec.y * vec.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec4 Normalized(const Vec4& vec)
|
||||||
|
{
|
||||||
|
Vec4 res = vec;
|
||||||
|
return res /= Magnitude(vec);
|
||||||
|
}
|
||||||
|
Vec3 Normalized(const Vec3& vec)
|
||||||
|
{
|
||||||
|
Vec3 res = vec;
|
||||||
|
return res /= Magnitude(vec);
|
||||||
|
}
|
||||||
|
Vec2 Normalized(const Vec2& vec)
|
||||||
|
{
|
||||||
|
Vec2 res = vec;
|
||||||
|
return res /= Magnitude(vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
float DotProduct(Vec3 a, Vec3 b)
|
||||||
|
{
|
||||||
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||||
|
}
|
||||||
|
Vec3 CrossProduct(Vec3 a, Vec3 b)
|
||||||
|
{
|
||||||
|
float x = a.y * b.z - a.z * b.y;
|
||||||
|
float y = a.z * b.x - a.x * b.z;
|
||||||
|
float z = a.x * b.y - a.y * b.x;
|
||||||
|
return {x, y, z};
|
||||||
|
}
|
||||||
|
Vec3 CrossProductFromPlane(Vec3 a, Vec3 b, Vec3 c)
|
||||||
|
{
|
||||||
|
// TODO: normalize might not be necessary
|
||||||
|
Vec3 lineA = Normalized(b - a);
|
||||||
|
Vec3 lineB = Normalized(c - a);
|
||||||
|
return CrossProduct(lineA, lineB);
|
||||||
|
}
|
||||||
|
bool RayPlaneIntersect(Vec3 l1, Vec3 l2, Vec3 p1, Vec3 p2, Vec3 p3, Vec3& out)
|
||||||
|
{
|
||||||
|
// thanks to Paul Bourke and Bryan Hanson
|
||||||
|
// l1,l2 constitute the line. P1,P2,P3 constitute the plane
|
||||||
|
out = {};
|
||||||
|
Vec3 N = CrossProductFromPlane(p1, p2, p3); // N is the normal of the plane
|
||||||
|
float n = DotProduct(N, Vec3{p3.x - l1.x, p3.y - l1.y, p3.z - l1.z});
|
||||||
|
Vec3 LbMinusLa = Vec3{l2.x - l1.x, l2.y - l1.y, l2.z - l1.z};
|
||||||
|
float d = DotProduct(N, LbMinusLa);
|
||||||
|
if (d == 0) return false; // Line is parallel to or in the plane
|
||||||
|
float u = n / d;
|
||||||
|
if ((u >= 0.0) && (u <= 1.0))
|
||||||
|
{ // Plane is between the two points
|
||||||
|
} // can be used for checking but does not influence the outcome
|
||||||
|
out = Vec3{l1.x + u * LbMinusLa.x, l1.y + u * LbMinusLa.y, l1.z + u * LbMinusLa.z};
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} // namespace Gen
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../gen/Generated.h"
|
#include "../gen/Generated.h"
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
bool IsValid(const AssetHandle& h);
|
bool IsValid(const AssetHandle& h);
|
||||||
bool IsValid(const ModelHandle& h);
|
bool IsValid(const ModelHandle& h);
|
||||||
@@ -12,4 +12,69 @@ namespace Generated
|
|||||||
|
|
||||||
PuzPos operator+=(PuzPos lhs, const PuzPos& rhs);
|
PuzPos operator+=(PuzPos lhs, const PuzPos& rhs);
|
||||||
PuzPos operator+(PuzPos lhs, const PuzPos& rhs);
|
PuzPos operator+(PuzPos lhs, const PuzPos& rhs);
|
||||||
} // namespace Generated
|
|
||||||
|
Vec4& operator+=(Vec4& lhs, const Vec4& rhs);
|
||||||
|
Vec4 operator+(const Vec4& lhs, const Vec4& rhs);
|
||||||
|
Vec4& operator+=(Vec4& lhs, float rhs);
|
||||||
|
Vec4 operator+(Vec4& lhs, float rhs);
|
||||||
|
|
||||||
|
Vec4& operator-=(Vec4& lhs, const Vec4& rhs);
|
||||||
|
Vec4 operator-(const Vec4& lhs, const Vec4& rhs);
|
||||||
|
Vec4& operator-=(Vec4& lhs, float rhs);
|
||||||
|
Vec4 operator-(const Vec4& lhs, float rhs);
|
||||||
|
|
||||||
|
Vec4& operator*=(Vec4& lhs, float rhs);
|
||||||
|
Vec4 operator*(const Vec4& lhs, float rhs);
|
||||||
|
|
||||||
|
Vec4& operator/=(Vec4& lhs, float rhs);
|
||||||
|
Vec4 operator/(const Vec4& lhs, float rhs);
|
||||||
|
|
||||||
|
Vec3& operator+=(Vec3& lhs, const Vec3& rhs);
|
||||||
|
Vec3 operator+(const Vec3& lhs, const Vec3& rhs);
|
||||||
|
Vec3& operator+=(Vec3& lhs, float rhs);
|
||||||
|
Vec3 operator+(Vec3& lhs, float rhs);
|
||||||
|
|
||||||
|
Vec3& operator-=(Vec3& lhs, const Vec3& rhs);
|
||||||
|
Vec3 operator-(const Vec3& lhs, const Vec3& rhs);
|
||||||
|
Vec3& operator-=(Vec3& lhs, float rhs);
|
||||||
|
Vec3 operator-(const Vec3& lhs, float rhs);
|
||||||
|
|
||||||
|
Vec3& operator*=(Vec3& lhs, float rhs);
|
||||||
|
Vec3 operator*(const Vec3& lhs, float rhs);
|
||||||
|
|
||||||
|
Vec3& operator/=(Vec3& lhs, float rhs);
|
||||||
|
Vec3 operator/(const Vec3& lhs, float rhs);
|
||||||
|
|
||||||
|
Vec2& operator+=(Vec2& lhs, const Vec2& rhs);
|
||||||
|
Vec2 operator+(const Vec2& lhs, const Vec2& rhs);
|
||||||
|
Vec2& operator+=(Vec2& lhs, float rhs);
|
||||||
|
Vec2 operator+(Vec2& lhs, float rhs);
|
||||||
|
|
||||||
|
Vec2& operator-=(Vec2& lhs, const Vec2& rhs);
|
||||||
|
Vec2 operator-(const Vec2& lhs, const Vec2& rhs);
|
||||||
|
Vec2& operator-=(Vec2& lhs, float rhs);
|
||||||
|
Vec2 operator-(const Vec2& lhs, float rhs);
|
||||||
|
|
||||||
|
Vec2& operator*=(Vec2& lhs, float rhs);
|
||||||
|
Vec2 operator*(const Vec2& lhs, float rhs);
|
||||||
|
|
||||||
|
Vec2& operator/=(Vec2& lhs, float rhs);
|
||||||
|
Vec2 operator/(const Vec2& lhs, float rhs);
|
||||||
|
|
||||||
|
float Magnitude(const Vec4& vec);
|
||||||
|
float Magnitude(const Vec3& vec);
|
||||||
|
float Magnitude(const Vec2& vec);
|
||||||
|
|
||||||
|
Vec4 Normalized(const Vec4& vec);
|
||||||
|
Vec3 Normalized(const Vec3& vec);
|
||||||
|
Vec2 Normalized(const Vec2& vec);
|
||||||
|
|
||||||
|
Mat4 Inverse(const Mat4& mat);
|
||||||
|
Mat4 Transpose(const Mat4& mat);
|
||||||
|
Vec4 Mul(const Mat4& mat, const Vec4& vec);
|
||||||
|
|
||||||
|
float DotProduct(Vec3 a, Vec3 b);
|
||||||
|
Vec3 CrossProduct(Vec3 a, Vec3 b);
|
||||||
|
Vec3 CrossProductFromPlane(Vec3 a, Vec3 b, Vec3 c);
|
||||||
|
bool RayPlaneIntersect(Vec3 l1, Vec3 l2, Vec3 p1, Vec3 p2, Vec3 p3, Vec3& out);
|
||||||
|
} // namespace Gen
|
||||||
|
|||||||
@@ -1,17 +1,59 @@
|
|||||||
#include "../engine/Shared.h"
|
#include "../engine/Shared.h"
|
||||||
|
#include "Gen.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Instance.h"
|
#include "Instance.h"
|
||||||
|
|
||||||
#include "bx/bx.h"
|
#include "bx/bx.h"
|
||||||
#include "bx/math.h"
|
#include "bx/math.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
using namespace Gen;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
SharedData* SharedInstance = nullptr;
|
SharedData* SharedInstance = nullptr;
|
||||||
Game::GameInstance* GameInst = nullptr;
|
Game::GameInstance* GameInst = nullptr;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
namespace Game
|
||||||
|
{
|
||||||
|
SharedData& GetShared()
|
||||||
|
{
|
||||||
|
assert(SharedInstance != nullptr);
|
||||||
|
return *SharedInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetShared(SharedData& instance)
|
||||||
|
{
|
||||||
|
SharedInstance = &instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameInstance& GetInstance()
|
||||||
|
{
|
||||||
|
assert(GameInst != nullptr);
|
||||||
|
return *GameInst;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetInstance(Game::GameInstance& instance)
|
||||||
|
{
|
||||||
|
GameInst = &instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* AllocateScratch(size_t byteCount, size_t align)
|
||||||
|
{
|
||||||
|
size_t offset = GetInstance().UsedScratchAmount;
|
||||||
|
uint8_t* base = static_cast<uint8_t*>(GetShared().Game.TransientStorage);
|
||||||
|
uint8_t* current = base + offset;
|
||||||
|
size_t offsetAligned = ((offset + align - 1) / align) * align;
|
||||||
|
uint8_t* ptrAligned = base + offsetAligned;
|
||||||
|
size_t newOffset = offsetAligned + byteCount;
|
||||||
|
if (newOffset > GetShared().Game.TransientStorageSize) return nullptr;
|
||||||
|
GetInstance().UsedScratchAmount = newOffset;
|
||||||
|
return reinterpret_cast<void*>(ptrAligned);
|
||||||
|
}
|
||||||
|
} // namespace Game
|
||||||
|
|
||||||
void Transform::CreateTransform(float* out, bx::Vec3 pos, bx::Quaternion rot, bx::Vec3 scale)
|
void Transform::CreateTransform(float* out, bx::Vec3 pos, bx::Quaternion rot, bx::Vec3 scale)
|
||||||
{
|
{
|
||||||
if (out == nullptr) return;
|
if (out == nullptr) return;
|
||||||
@@ -82,49 +124,12 @@ void Transform::UpdateMatrix()
|
|||||||
bx::mtxInverse(MI.M, M.M);
|
bx::mtxInverse(MI.M, M.M);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Game
|
|
||||||
{
|
|
||||||
SharedData& GetShared()
|
|
||||||
{
|
|
||||||
assert(SharedInstance != nullptr);
|
|
||||||
return *SharedInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetShared(SharedData& instance)
|
|
||||||
{
|
|
||||||
SharedInstance = &instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameInstance& GetInstance()
|
|
||||||
{
|
|
||||||
assert(GameInst != nullptr);
|
|
||||||
return *GameInst;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetInstance(Game::GameInstance& instance)
|
|
||||||
{
|
|
||||||
GameInst = &instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* AllocateScratch(size_t byteCount, size_t align)
|
|
||||||
{
|
|
||||||
size_t offset = GetInstance().UsedScratchAmount;
|
|
||||||
uint8_t* base = static_cast<uint8_t*>(GetShared().Game.TransientStorage);
|
|
||||||
uint8_t* current = base + offset;
|
|
||||||
size_t offsetAligned = ((offset + align - 1) / align) * align;
|
|
||||||
uint8_t* ptrAligned = base + offsetAligned;
|
|
||||||
size_t newOffset = offsetAligned + byteCount;
|
|
||||||
if (newOffset > GetShared().Game.TransientStorageSize) return nullptr;
|
|
||||||
GetInstance().UsedScratchAmount = newOffset;
|
|
||||||
return reinterpret_cast<void*>(ptrAligned);
|
|
||||||
}
|
|
||||||
} // namespace Game
|
|
||||||
Vec3 Transform::GlobalToLocalDirection(Vec3 global)
|
Vec3 Transform::GlobalToLocalDirection(Vec3 global)
|
||||||
{
|
{
|
||||||
UpdateMatrix();
|
UpdateMatrix();
|
||||||
float in[4]{global.x, global.y, global.z, 0.0f};
|
float in[4]{global.x, global.y, global.z, 0.0f};
|
||||||
float out[4]{0.0f};
|
float out[4]{0.0f};
|
||||||
bx::vec4MulMtx(out, in, MI.Transpose().M);
|
bx::vec4MulMtx(out, in, Transpose(MI).M);
|
||||||
return {out[0], out[1], out[2]};
|
return {out[0], out[1], out[2]};
|
||||||
}
|
}
|
||||||
Vec3 Transform::GlobalToLocalPoint(Vec3 global)
|
Vec3 Transform::GlobalToLocalPoint(Vec3 global)
|
||||||
@@ -140,7 +145,7 @@ Vec3 Transform::LocalToGlobalDirection(Vec3 local)
|
|||||||
UpdateMatrix();
|
UpdateMatrix();
|
||||||
float in[4]{local.x, local.y, local.z, 0.0f};
|
float in[4]{local.x, local.y, local.z, 0.0f};
|
||||||
float out[4]{0.0f};
|
float out[4]{0.0f};
|
||||||
bx::vec4MulMtx(out, in, M.Transpose().M);
|
bx::vec4MulMtx(out, in, Transpose(M).M);
|
||||||
return {out[0], out[1], out[2]};
|
return {out[0], out[1], out[2]};
|
||||||
}
|
}
|
||||||
Vec3 Transform::LocalToGlobalPoint(Vec3 local)
|
Vec3 Transform::LocalToGlobalPoint(Vec3 local)
|
||||||
@@ -159,56 +164,3 @@ Vec3 Transform::GetPosition()
|
|||||||
{
|
{
|
||||||
return {Position.x, Position.y, Position.z};
|
return {Position.x, Position.y, Position.z};
|
||||||
}
|
}
|
||||||
Mat4 Mat4::Inverse()
|
|
||||||
{
|
|
||||||
Mat4 result;
|
|
||||||
bx::mtxInverse(result.M, M);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
Mat4 Mat4::Transpose()
|
|
||||||
{
|
|
||||||
Mat4 result;
|
|
||||||
bx::mtxTranspose(result.M, M);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
Vec4 Mat4::Mul(const Vec4& vec)
|
|
||||||
{
|
|
||||||
Vec4 out;
|
|
||||||
bx::vec4MulMtx(&out.x, &vec.x, &M[0]);
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
float DotProduct(Vec3 a, Vec3 b)
|
|
||||||
{
|
|
||||||
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
||||||
}
|
|
||||||
Vec3 CrossProduct(Vec3 a, Vec3 b)
|
|
||||||
{
|
|
||||||
float x = a.y * b.z - a.z * b.y;
|
|
||||||
float y = a.z * b.x - a.x * b.z;
|
|
||||||
float z = a.x * b.y - a.y * b.x;
|
|
||||||
return {x, y, z};
|
|
||||||
}
|
|
||||||
Vec3 CrossProductFromPlane(Vec3 a, Vec3 b, Vec3 c)
|
|
||||||
{
|
|
||||||
// TODO: normalize might not be necessary
|
|
||||||
Vec3 lineA = (b - a).Normalize();
|
|
||||||
Vec3 lineB = (c - a).Normalize();
|
|
||||||
return CrossProduct(lineA, lineB);
|
|
||||||
}
|
|
||||||
bool RayPlaneIntersect(Vec3 l1, Vec3 l2, Vec3 p1, Vec3 p2, Vec3 p3, Vec3& out)
|
|
||||||
{
|
|
||||||
// thanks to Paul Bourke and Bryan Hanson
|
|
||||||
// l1,l2 constitute the line. P1,P2,P3 constitute the plane
|
|
||||||
out = {};
|
|
||||||
Vec3 N = CrossProductFromPlane(p1, p2, p3); // N is the normal of the plane
|
|
||||||
float n = DotProduct(N, Vec3{p3.x - l1.x, p3.y - l1.y, p3.z - l1.z});
|
|
||||||
Vec3 LbMinusLa = Vec3{l2.x - l1.x, l2.y - l1.y, l2.z - l1.z};
|
|
||||||
float d = DotProduct(N, LbMinusLa);
|
|
||||||
if (d == 0) return false; // Line is parallel to or in the plane
|
|
||||||
float u = n / d;
|
|
||||||
if ((u >= 0.0) && (u <= 1.0))
|
|
||||||
{ // Plane is between the two points
|
|
||||||
} // can be used for checking but does not influence the outcome
|
|
||||||
out = Vec3{l1.x + u * LbMinusLa.x, l1.y + u * LbMinusLa.y, l1.z + u * LbMinusLa.z};
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,213 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../gen/Generated.h"
|
||||||
#include "bx/math.h"
|
#include "bx/math.h"
|
||||||
#include <cfloat>
|
|
||||||
|
|
||||||
struct Vec2
|
|
||||||
{
|
|
||||||
float x = 0.0f;
|
|
||||||
float y = 0.0f;
|
|
||||||
|
|
||||||
Vec2& operator+=(const Vec2& rhs)
|
|
||||||
{
|
|
||||||
x += rhs.x;
|
|
||||||
y += rhs.y;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend Vec2 operator+(Vec2 lhs, const Vec2& rhs)
|
|
||||||
{
|
|
||||||
lhs += rhs;
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2& operator+=(const float& rhs)
|
|
||||||
{
|
|
||||||
x += rhs;
|
|
||||||
y += rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend Vec2 operator+(Vec2 lhs, const float& rhs)
|
|
||||||
{
|
|
||||||
lhs += rhs;
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2& operator-=(const Vec2& rhs)
|
|
||||||
{
|
|
||||||
x -= rhs.x;
|
|
||||||
y -= rhs.y;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend Vec2 operator-(Vec2 lhs, const Vec2& rhs)
|
|
||||||
{
|
|
||||||
lhs -= rhs;
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2& operator-=(const float& rhs)
|
|
||||||
{
|
|
||||||
x -= rhs;
|
|
||||||
y -= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend Vec2 operator-(Vec2 lhs, const float& rhs)
|
|
||||||
{
|
|
||||||
lhs -= rhs;
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2& operator*=(const float rhs)
|
|
||||||
{
|
|
||||||
x *= rhs;
|
|
||||||
y *= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend Vec2 operator*(Vec2 lhs, const float rhs)
|
|
||||||
{
|
|
||||||
lhs *= rhs;
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2& operator/=(const float rhs)
|
|
||||||
{
|
|
||||||
x /= rhs;
|
|
||||||
y /= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend Vec2 operator/(Vec2 lhs, const float rhs)
|
|
||||||
{
|
|
||||||
lhs /= rhs;
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Magnitude()
|
|
||||||
{
|
|
||||||
return bx::sqrt(x * x + y * y);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2 Normalize()
|
|
||||||
{
|
|
||||||
float mag = Magnitude();
|
|
||||||
if (mag < FLT_EPSILON) return {};
|
|
||||||
return {x / mag, y / mag};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Vec3
|
|
||||||
{
|
|
||||||
float x = 0.0f;
|
|
||||||
float y = 0.0f;
|
|
||||||
float z = 0.0f;
|
|
||||||
|
|
||||||
Vec3& operator+=(const Vec3& rhs)
|
|
||||||
{
|
|
||||||
x += rhs.x;
|
|
||||||
y += rhs.y;
|
|
||||||
z += rhs.z;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend Vec3 operator+(Vec3 lhs, const Vec3& rhs)
|
|
||||||
{
|
|
||||||
lhs += rhs;
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3& operator-=(const Vec3& rhs)
|
|
||||||
{
|
|
||||||
x -= rhs.x;
|
|
||||||
y -= rhs.y;
|
|
||||||
z -= rhs.z;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend Vec3 operator-(Vec3 lhs, const Vec3& rhs)
|
|
||||||
{
|
|
||||||
lhs -= rhs;
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3& operator*=(const float rhs)
|
|
||||||
{
|
|
||||||
x *= rhs;
|
|
||||||
y *= rhs;
|
|
||||||
z *= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend Vec3 operator*(Vec3 lhs, const float rhs)
|
|
||||||
{
|
|
||||||
lhs *= rhs;
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3& operator/=(const float rhs)
|
|
||||||
{
|
|
||||||
x /= rhs;
|
|
||||||
y /= rhs;
|
|
||||||
z /= rhs;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend Vec3 operator/(Vec3 lhs, const float rhs)
|
|
||||||
{
|
|
||||||
lhs /= rhs;
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Magnitude()
|
|
||||||
{
|
|
||||||
return bx::sqrt(x * x + y * y + z * z);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3 Normalize()
|
|
||||||
{
|
|
||||||
float mag = Magnitude();
|
|
||||||
if (mag < FLT_EPSILON) return {};
|
|
||||||
return {x / mag, y / mag, z / mag};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Vec4
|
|
||||||
{
|
|
||||||
float x = 0.0f;
|
|
||||||
float y = 0.0f;
|
|
||||||
float z = 0.0f;
|
|
||||||
float w = 0.0f;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Mat3
|
|
||||||
{
|
|
||||||
// clang-format off
|
|
||||||
float M[9]{
|
|
||||||
1.0f, 0.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 0.0f, 1.0f,
|
|
||||||
};
|
|
||||||
// clang-format on
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Mat4
|
|
||||||
{
|
|
||||||
// clang-format off
|
|
||||||
float M[16]{
|
|
||||||
1.0, 0.0, 0.0, 0.0,
|
|
||||||
0.0, 1.0, 0.0, 0.0,
|
|
||||||
0.0, 0.0, 1.0, 0.0,
|
|
||||||
0.0, 0.0, 0.0, 1.0,
|
|
||||||
};
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
Mat4 Inverse();
|
|
||||||
Mat4 Transpose();
|
|
||||||
Vec4 Mul(const Vec4& vec);
|
|
||||||
};
|
|
||||||
|
|
||||||
inline int32_t SetFlags(int32_t in, int32_t flags)
|
inline int32_t SetFlags(int32_t in, int32_t flags)
|
||||||
{
|
{
|
||||||
@@ -232,35 +26,31 @@ inline bool GetFlag(int32_t in, int32_t flags)
|
|||||||
|
|
||||||
struct Transform
|
struct Transform
|
||||||
{
|
{
|
||||||
Mat4 M;
|
Gen::Mat4 M;
|
||||||
Mat4 MI;
|
Gen::Mat4 MI;
|
||||||
bx::Vec3 Position{0.0f, 0.0f, 0.0f};
|
bx::Vec3 Position{0.0f, 0.0f, 0.0f};
|
||||||
Mat4 Rotation;
|
Gen::Mat4 Rotation;
|
||||||
bx::Vec3 Scale{1.0f, 1.0f, 1.0f};
|
bx::Vec3 Scale{1.0f, 1.0f, 1.0f};
|
||||||
|
|
||||||
static void CreateTransform(float* out, bx::Vec3 pos, bx::Quaternion rot, bx::Vec3 scale);
|
static void CreateTransform(float* out, bx::Vec3 pos, bx::Quaternion rot, bx::Vec3 scale);
|
||||||
void Translate(Vec3 offset);
|
void Translate(Gen::Vec3 offset);
|
||||||
void TranslateLocal(Vec3 offset);
|
void TranslateLocal(Gen::Vec3 offset);
|
||||||
void Rotate(Vec3 rotation);
|
void Rotate(Gen::Vec3 rotation);
|
||||||
void RotateLocal(Vec3 rotation);
|
void RotateLocal(Gen::Vec3 rotation);
|
||||||
Vec3 LocalToGlobalPoint(Vec3 local);
|
Gen::Vec3 LocalToGlobalPoint(Gen::Vec3 local);
|
||||||
Vec3 LocalToGlobalDirection(Vec3 local);
|
Gen::Vec3 LocalToGlobalDirection(Gen::Vec3 local);
|
||||||
Vec3 GlobalToLocalPoint(Vec3 global);
|
Gen::Vec3 GlobalToLocalPoint(Gen::Vec3 global);
|
||||||
Vec3 GlobalToLocalDirection(Vec3 global);
|
Gen::Vec3 GlobalToLocalDirection(Gen::Vec3 global);
|
||||||
Vec3 Right() const;
|
Gen::Vec3 Right() const;
|
||||||
Vec3 Up() const;
|
Gen::Vec3 Up() const;
|
||||||
Vec3 Forward() const;
|
Gen::Vec3 Forward() const;
|
||||||
void SetPosition(Vec3 pos);
|
void SetPosition(Gen::Vec3 pos);
|
||||||
Vec3 GetPosition();
|
Gen::Vec3 GetPosition();
|
||||||
const float* GetPtr();
|
const float* GetPtr();
|
||||||
void UpdateMatrix();
|
void UpdateMatrix();
|
||||||
void UpdateMatrixForCam();
|
void UpdateMatrixForCam();
|
||||||
};
|
};
|
||||||
|
|
||||||
Vec3 CrossProduct(Vec3 a, Vec3 b);
|
|
||||||
Vec3 CrossProductFromPlane(Vec3 a, Vec3 b, Vec3 c);
|
|
||||||
bool RayPlaneIntersect(Vec3 l1, Vec3 l2, Vec3 p1, Vec3 p2, Vec3 p3, Vec3& out);
|
|
||||||
|
|
||||||
struct SharedData;
|
struct SharedData;
|
||||||
|
|
||||||
namespace Game
|
namespace Game
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
namespace Game
|
namespace Game
|
||||||
{
|
{
|
||||||
|
using namespace Gen;
|
||||||
|
|
||||||
bool IsKeyboardAllowed()
|
bool IsKeyboardAllowed()
|
||||||
{
|
{
|
||||||
auto& IO = ImGui::GetIO();
|
auto& IO = ImGui::GetIO();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Global.h"
|
#include "../gen/Generated.h"
|
||||||
|
|
||||||
enum class MouseButton
|
enum class MouseButton
|
||||||
{
|
{
|
||||||
@@ -393,6 +393,6 @@ namespace Game
|
|||||||
bool GetMouseButton(MouseButton button);
|
bool GetMouseButton(MouseButton button);
|
||||||
bool GetMouseButtonPressedNow(MouseButton button);
|
bool GetMouseButtonPressedNow(MouseButton button);
|
||||||
bool GetMouseButtonReleasedNow(MouseButton button);
|
bool GetMouseButtonReleasedNow(MouseButton button);
|
||||||
Vec2 GetMouseMovement();
|
Gen::Vec2 GetMouseMovement();
|
||||||
Vec2 GetMousePos();
|
Gen::Vec2 GetMousePos();
|
||||||
} // namespace Game
|
} // namespace Game
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ namespace Game
|
|||||||
{
|
{
|
||||||
Transform PlayerCamTransform;
|
Transform PlayerCamTransform;
|
||||||
Transform FreeflyCamTransform;
|
Transform FreeflyCamTransform;
|
||||||
Mat4 Projection;
|
Gen::Mat4 Projection;
|
||||||
Mat4 ProjectionInverse;
|
Gen::Mat4 ProjectionInverse;
|
||||||
float FreeflyXRot = 0.0f;
|
float FreeflyXRot = 0.0f;
|
||||||
float FreeflyYRot = 0.0f;
|
float FreeflyYRot = 0.0f;
|
||||||
float WalkXRot = 0.0f;
|
float WalkXRot = 0.0f;
|
||||||
@@ -49,7 +49,7 @@ namespace Game
|
|||||||
char ImguiIni[4096]{0};
|
char ImguiIni[4096]{0};
|
||||||
static constexpr uint32_t MaxAssets = 128;
|
static constexpr uint32_t MaxAssets = 128;
|
||||||
uint32_t AssetCount = 0;
|
uint32_t AssetCount = 0;
|
||||||
Generated::AssetHandle AssetHandles[MaxAssets]{0};
|
Gen::AssetHandle AssetHandles[MaxAssets]{0};
|
||||||
char AssetHandlePaths[MaxAssets][128];
|
char AssetHandlePaths[MaxAssets][128];
|
||||||
bool ShowImguiDemo = false;
|
bool ShowImguiDemo = false;
|
||||||
uint8_t DebugCardRotation = 0;
|
uint8_t DebugCardRotation = 0;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include "Level.h"
|
#include "Level.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "Puzzle.h"
|
#include "Puzzle.h"
|
||||||
#include "bx/constants.h"
|
|
||||||
#include "rendering/Rendering.h"
|
#include "rendering/Rendering.h"
|
||||||
|
|
||||||
#include "SDL3/SDL_mouse.h"
|
#include "SDL3/SDL_mouse.h"
|
||||||
@@ -21,12 +20,14 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <tracy/Tracy.hpp>
|
#include <tracy/Tracy.hpp>
|
||||||
|
|
||||||
|
using namespace Gen;
|
||||||
|
|
||||||
namespace Game
|
namespace Game
|
||||||
{
|
{
|
||||||
void EntityRenderData::Render(const Model* models, const Material* materials, const Texture* textures)
|
void EntityRenderData::Render(const Model* models, const Material* materials, const Texture* textures)
|
||||||
{
|
{
|
||||||
if (models == nullptr || materials == nullptr || textures == nullptr) return;
|
if (models == nullptr || materials == nullptr || textures == nullptr) return;
|
||||||
if (!Generated::IsValid(ModelH) || MaterialHandle == EMaterial::UNDEFINED) return;
|
if (!Gen::IsValid(ModelH) || MaterialHandle == EMaterial::UNDEFINED) return;
|
||||||
if (!Visible) return;
|
if (!Visible) return;
|
||||||
auto& rendering = GameRendering::Get();
|
auto& rendering = GameRendering::Get();
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@ namespace Game
|
|||||||
bgfx::setTexture(1, rendering.DitherTextures.DitherSampler, rendering.DitherTextures.FinalTex);
|
bgfx::setTexture(1, rendering.DitherTextures.DitherSampler, rendering.DitherTextures.FinalTex);
|
||||||
bgfx::setTexture(2, rendering.DitherTextures.RampSampler, rendering.DitherTextures.RampTex);
|
bgfx::setTexture(2, rendering.DitherTextures.RampSampler, rendering.DitherTextures.RampTex);
|
||||||
bgfx::setUniform(currentMaterial.Uniforms[Material::UTime], timeValues);
|
bgfx::setUniform(currentMaterial.Uniforms[Material::UTime], timeValues);
|
||||||
bgfx::setUniform(currentMaterial.Uniforms[Material::UDotColor], &TestColor.x);
|
bgfx::setUniform(currentMaterial.Uniforms[Material::UDotColor], &DotColor.x);
|
||||||
bgfx::setUniform(currentMaterial.Uniforms[Material::UTexInfo], texInfo);
|
bgfx::setUniform(currentMaterial.Uniforms[Material::UTexInfo], texInfo);
|
||||||
bgfx::setUniform(currentMaterial.Uniforms[Material::UBaseColor], &BaseColor.x);
|
bgfx::setUniform(currentMaterial.Uniforms[Material::UBaseColor], &BaseColor.x);
|
||||||
|
|
||||||
@@ -117,8 +118,8 @@ namespace Game
|
|||||||
fullPath.join(info.filePath);
|
fullPath.join(info.filePath);
|
||||||
LOG("Loading %s", fullPath.getCPtr());
|
LOG("Loading %s", fullPath.getCPtr());
|
||||||
|
|
||||||
Generated::Deserializer ser;
|
Gen::Deserializer ser;
|
||||||
Generated::PuzzleData dataBuf;
|
Gen::PuzzleData dataBuf;
|
||||||
if (ser.Init(fullPath, "PZZL") && ser.ReadT(dataBuf))
|
if (ser.Init(fullPath, "PZZL") && ser.ReadT(dataBuf))
|
||||||
{
|
{
|
||||||
if (dataBuf.ID >= BX_COUNTOF(Puzzles))
|
if (dataBuf.ID >= BX_COUNTOF(Puzzles))
|
||||||
@@ -154,10 +155,6 @@ namespace Game
|
|||||||
Cubes.Get(PlayerOutsideViewCube).Setup();
|
Cubes.Get(PlayerOutsideViewCube).Setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Tests.Count == 0)
|
|
||||||
{
|
|
||||||
Tests.Get(Tests.New()).Setup();
|
|
||||||
}
|
|
||||||
UIQuads.Count = 0;
|
UIQuads.Count = 0;
|
||||||
PuzzleTiles.Count = 0;
|
PuzzleTiles.Count = 0;
|
||||||
for (int32_t i = 0; i < BX_COUNTOF(Puzzles); ++i)
|
for (int32_t i = 0; i < BX_COUNTOF(Puzzles); ++i)
|
||||||
@@ -343,7 +340,7 @@ namespace Game
|
|||||||
mousePos *= 2.0f;
|
mousePos *= 2.0f;
|
||||||
mousePos -= 1.0f;
|
mousePos -= 1.0f;
|
||||||
Vec4 mousePosView = {mousePos.x, -mousePos.y, 0.0f, 1.0f};
|
Vec4 mousePosView = {mousePos.x, -mousePos.y, 0.0f, 1.0f};
|
||||||
Vec4 mousePosCam4 = GetInstance().Player.ProjectionInverse.Mul(mousePosView);
|
Vec4 mousePosCam4 = Mul(GetInstance().Player.ProjectionInverse, mousePosView);
|
||||||
Vec3 mousePosCam = Vec3{
|
Vec3 mousePosCam = Vec3{
|
||||||
mousePosCam4.x /= mousePosCam4.w,
|
mousePosCam4.x /= mousePosCam4.w,
|
||||||
mousePosCam4.y /= mousePosCam4.w,
|
mousePosCam4.y /= mousePosCam4.w,
|
||||||
@@ -357,7 +354,7 @@ namespace Game
|
|||||||
for (int8_t x = 0; x < Data.WidthTiles / Puzzle::Config::CardSize; ++x)
|
for (int8_t x = 0; x < Data.WidthTiles / Puzzle::Config::CardSize; ++x)
|
||||||
{
|
{
|
||||||
int32_t cardIdx = y * Puzzle::Config::MaxPuzzleSizeCards + x;
|
int32_t cardIdx = y * Puzzle::Config::MaxPuzzleSizeCards + x;
|
||||||
Generated::PlacedPuzzleCard& card = Data.PlacedCards[cardIdx];
|
Gen::PlacedPuzzleCard& card = Data.PlacedCards[cardIdx];
|
||||||
auto& tile = level.PuzzleTiles.Get(TileHandles[cardIdx]);
|
auto& tile = level.PuzzleTiles.Get(TileHandles[cardIdx]);
|
||||||
auto& quad = level.UIQuads.Get(UIPlacedCards[cardIdx]);
|
auto& quad = level.UIQuads.Get(UIPlacedCards[cardIdx]);
|
||||||
|
|
||||||
@@ -380,13 +377,14 @@ namespace Game
|
|||||||
|
|
||||||
quad.EData.Visible = isValid;
|
quad.EData.Visible = isValid;
|
||||||
quad.EData.TextureHandle =
|
quad.EData.TextureHandle =
|
||||||
isValid ? staticCards[card.RefCard.Idx].BoardTextureHandle : Generated::TextureHandle{};
|
isValid ? staticCards[card.RefCard.Idx].BoardTextureHandle : Gen::TextureHandle{};
|
||||||
|
quad.EData.DotColor = card.IsLocked ? Vec4{0.0f, 0.0f, 0.0f, 0.0f} : Vec4{1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
|
|
||||||
quad.EData.Transform = boardTransform;
|
quad.EData.Transform = boardTransform;
|
||||||
quad.EData.Transform.TranslateLocal(Vec3{(float)card.Position.X, (float)card.Position.Y, 0.0f} *
|
quad.EData.Transform.TranslateLocal(Vec3{(float)card.Position.X, (float)card.Position.Y, 0.0f} *
|
||||||
UICardOffset);
|
UICardOffset);
|
||||||
quad.EData.Transform.Scale = {0.1f, 0.1f, 0.1f};
|
quad.EData.Transform.Scale = {0.1f, 0.1f, 0.1f};
|
||||||
quad.EData.Transform.Rotate(Vec3{bx::kPi * 0.5f, 0.0f, (1.0f + card.Rotation * 0.5f) * bx::kPi});
|
quad.EData.Transform.Rotate(Vec3{bx::kPi * 0.5f, 0.0f, (1.0f - card.Rotation * 0.5f) * bx::kPi});
|
||||||
|
|
||||||
Vec3 quadPosWorld = quad.EData.Transform.GetPosition();
|
Vec3 quadPosWorld = quad.EData.Transform.GetPosition();
|
||||||
Vec3 quadXWorld = quad.EData.Transform.LocalToGlobalPoint({1, 0, 0});
|
Vec3 quadXWorld = quad.EData.Transform.LocalToGlobalPoint({1, 0, 0});
|
||||||
@@ -417,8 +415,8 @@ namespace Game
|
|||||||
Vec3 boardTilePos = boardPos / UICardOffset;
|
Vec3 boardTilePos = boardPos / UICardOffset;
|
||||||
int32_t xPos = (int32_t)bx::round(boardTilePos.x);
|
int32_t xPos = (int32_t)bx::round(boardTilePos.x);
|
||||||
int32_t yPos = (int32_t)bx::round(boardTilePos.y);
|
int32_t yPos = (int32_t)bx::round(boardTilePos.y);
|
||||||
Generated::PuzPos srcCardPos = {(int8_t)DraggedCard.X, (int8_t)DraggedCard.Y};
|
Gen::PuzPos srcCardPos = {(int8_t)DraggedCard.X, (int8_t)DraggedCard.Y};
|
||||||
Generated::PlacedPuzzleCard& srcCard =
|
Gen::PlacedPuzzleCard& srcCard =
|
||||||
Data.PlacedCards[srcCardPos.Y * Puzzle::Config::MaxPuzzleSizeCards + srcCardPos.X];
|
Data.PlacedCards[srcCardPos.Y * Puzzle::Config::MaxPuzzleSizeCards + srcCardPos.X];
|
||||||
|
|
||||||
if (GetMouseButtonPressedNow(MouseButton::Right))
|
if (GetMouseButtonPressedNow(MouseButton::Right))
|
||||||
@@ -429,11 +427,11 @@ namespace Game
|
|||||||
|
|
||||||
if (!GetMouseButton(MouseButton::Left))
|
if (!GetMouseButton(MouseButton::Left))
|
||||||
{
|
{
|
||||||
Generated::PuzPos targetCardPos = {(int8_t)xPos, (int8_t)yPos};
|
Gen::PuzPos targetCardPos = {(int8_t)xPos, (int8_t)yPos};
|
||||||
if (xPos >= 0 && xPos < Data.WidthTiles / Puzzle::Config::CardSize && yPos >= 0 &&
|
if (xPos >= 0 && xPos < Data.WidthTiles / Puzzle::Config::CardSize && yPos >= 0 &&
|
||||||
yPos < Data.HeightTiles / Puzzle::Config::CardSize)
|
yPos < Data.HeightTiles / Puzzle::Config::CardSize)
|
||||||
{
|
{
|
||||||
Generated::PlacedPuzzleCard& targetCard =
|
Gen::PlacedPuzzleCard& targetCard =
|
||||||
Data.PlacedCards[yPos * Puzzle::Config::MaxPuzzleSizeCards + xPos];
|
Data.PlacedCards[yPos * Puzzle::Config::MaxPuzzleSizeCards + xPos];
|
||||||
bool canBeReplaced = !Puzzle::IsValid(targetCard.RefCard) || targetCard.RefCard.Idx == 0;
|
bool canBeReplaced = !Puzzle::IsValid(targetCard.RefCard) || targetCard.RefCard.Idx == 0;
|
||||||
if (canBeReplaced && Puzzle::ReturnPlacedCard(Data, srcCardPos))
|
if (canBeReplaced && Puzzle::ReturnPlacedCard(Data, srcCardPos))
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ namespace Game
|
|||||||
{
|
{
|
||||||
struct EntityRenderData
|
struct EntityRenderData
|
||||||
{
|
{
|
||||||
Vec4 TestColor{1.0f, 1.0f, 1.0f, 1.0f};
|
Gen::Vec4 DotColor{1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
Vec4 BaseColor{0.0f, 0.0f, 0.0f, 1.0f};
|
Gen::Vec4 BaseColor{0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
Transform Transform;
|
Transform Transform;
|
||||||
EMaterial MaterialHandle = EMaterial::UNDEFINED;
|
EMaterial MaterialHandle = EMaterial::UNDEFINED;
|
||||||
Generated::TextureHandle TextureHandle;
|
Gen::TextureHandle TextureHandle;
|
||||||
Generated::ModelHandle ModelH;
|
Gen::ModelHandle ModelH;
|
||||||
bool Visible = true;
|
bool Visible = true;
|
||||||
|
|
||||||
void Render(const Model* models, const Material* materials, const Texture* textures);
|
void Render(const Model* models, const Material* materials, const Texture* textures);
|
||||||
@@ -135,13 +135,13 @@ namespace Game
|
|||||||
|
|
||||||
struct WorldPuzzle
|
struct WorldPuzzle
|
||||||
{
|
{
|
||||||
static constexpr Vec2 WorldCardSize{10.0f, 10.0f};
|
static constexpr Gen::Vec2 WorldCardSize{10.0f, 10.0f};
|
||||||
static constexpr float UICardOffset = 0.21f;
|
static constexpr float UICardOffset = 0.21f;
|
||||||
Generated::PuzzleData Data;
|
Gen::PuzzleData Data;
|
||||||
Vec3 WorldPosition;
|
Gen::Vec3 WorldPosition;
|
||||||
PuzzleTileEntityHandle TileHandles[Puzzle::Config::MaxCardsInPuzzle];
|
PuzzleTileEntityHandle TileHandles[Puzzle::Config::MaxCardsInPuzzle];
|
||||||
UIQuadEntityHandle UIPlacedCards[Puzzle::Config::MaxCardsInPuzzle];
|
UIQuadEntityHandle UIPlacedCards[Puzzle::Config::MaxCardsInPuzzle];
|
||||||
Generated::PuzPos DraggedCard{-1, -1};
|
Gen::PuzPos DraggedCard{-1, -1};
|
||||||
bool IsSetup = false;
|
bool IsSetup = false;
|
||||||
|
|
||||||
void Setup();
|
void Setup();
|
||||||
@@ -158,7 +158,7 @@ namespace Game
|
|||||||
CubeHandle PlayerOutsideViewCube;
|
CubeHandle PlayerOutsideViewCube;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Generated::StaticPuzzleData PuzzleData;
|
Gen::StaticPuzzleData PuzzleData;
|
||||||
WorldPuzzle Puzzles[1];
|
WorldPuzzle Puzzles[1];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "../gen/Def.h"
|
#include "Gen.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Instance.h"
|
#include "Instance.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
@@ -8,25 +8,25 @@
|
|||||||
#include "bx/string.h"
|
#include "bx/string.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
static constexpr Generated::PuzPos Dirs[4]{
|
using namespace Gen;
|
||||||
|
static constexpr PuzPos Dirs[4]{
|
||||||
{-1, 0},
|
{-1, 0},
|
||||||
{0, -1},
|
{0, -1},
|
||||||
{0, 1},
|
{0, 1},
|
||||||
{1, 0},
|
{1, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
Generated::StaticPuzzleData StaticData;
|
StaticPuzzleData StaticData;
|
||||||
Generated::StaticPuzzleCard InvalidCard;
|
StaticPuzzleCard InvalidCard;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace Puzzle
|
namespace Puzzle
|
||||||
{
|
{
|
||||||
constexpr float UIPuzBoxSize = 26;
|
constexpr float UIPuzBoxSize = 26;
|
||||||
using namespace Generated;
|
using namespace Gen;
|
||||||
|
|
||||||
void Setup()
|
void Setup()
|
||||||
{
|
{
|
||||||
@@ -339,7 +339,7 @@ namespace Puzzle
|
|||||||
{
|
{
|
||||||
char filepath[128]{0};
|
char filepath[128]{0};
|
||||||
WritePuzzleFilePath(filepath, sizeof(filepath), obj.ID);
|
WritePuzzleFilePath(filepath, sizeof(filepath), obj.ID);
|
||||||
remove(filepath);
|
bx::remove(filepath);
|
||||||
obj.ID = UINT16_MAX;
|
obj.ID = UINT16_MAX;
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
#include "Gen.h" // IWYU pragma: keep
|
#include "../gen/Generated.h"
|
||||||
|
|
||||||
namespace Puzzle
|
namespace Puzzle
|
||||||
{
|
{
|
||||||
using namespace Generated;
|
using namespace Gen;
|
||||||
|
|
||||||
constexpr const char* PuzzleFileDir = "game/data/puzzles/";
|
constexpr const char* PuzzleFileDir = "game/data/puzzles/";
|
||||||
|
|
||||||
@@ -43,11 +43,11 @@ namespace Puzzle
|
|||||||
|
|
||||||
struct PuzzleSolver
|
struct PuzzleSolver
|
||||||
{
|
{
|
||||||
bool IsPuzzleSolved(const Generated::PuzzleData& puzzle);
|
bool IsPuzzleSolved(const PuzzleData& puzzle);
|
||||||
bool IsExitSatisfied(const Generated::PuzzleData& puzzle, PuzPos pos);
|
bool IsExitSatisfied(const PuzzleData& puzzle, PuzPos pos);
|
||||||
|
|
||||||
// This assumes flowFrom is already verified to be connected.
|
// This assumes flowFrom is already verified to be connected.
|
||||||
bool IsValidGoalConnection(const Generated::PuzzleData& puzzle,
|
bool IsValidGoalConnection(const PuzzleData& puzzle,
|
||||||
PuzPos flowFrom,
|
PuzPos flowFrom,
|
||||||
PuzPos flowTo,
|
PuzPos flowTo,
|
||||||
PuzzleElementType::Enum goalType);
|
PuzzleElementType::Enum goalType);
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
|
#include "Gen.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Instance.h"
|
#include "Instance.h"
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
|
#include "Puzzle.h"
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
#include "bx/timer.h"
|
#include "bx/timer.h"
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <tracy/Tracy.hpp>
|
#include <tracy/Tracy.hpp>
|
||||||
|
|
||||||
|
using namespace Gen;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
constexpr int32_t FrameTimeBufSize = 512;
|
constexpr int32_t FrameTimeBufSize = 512;
|
||||||
@@ -16,7 +20,7 @@ namespace
|
|||||||
|
|
||||||
namespace Tools
|
namespace Tools
|
||||||
{
|
{
|
||||||
const char* GetAssetPath(Generated::AssetHandle assetHandle)
|
const char* GetAssetPath(Gen::AssetHandle assetHandle)
|
||||||
{
|
{
|
||||||
const auto& inst = Game::GetInstance();
|
const auto& inst = Game::GetInstance();
|
||||||
for (int32_t j = 0; j < inst.DebugData.AssetCount; ++j)
|
for (int32_t j = 0; j < inst.DebugData.AssetCount; ++j)
|
||||||
@@ -29,7 +33,7 @@ namespace Tools
|
|||||||
return "---";
|
return "---";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelDropdown(Generated::ModelHandle& modelHandle)
|
void ModelDropdown(Gen::ModelHandle& modelHandle)
|
||||||
{
|
{
|
||||||
auto& R = Game::GameRendering::Get();
|
auto& R = Game::GameRendering::Get();
|
||||||
const char* name = GetAssetPath(modelHandle.Asset);
|
const char* name = GetAssetPath(modelHandle.Asset);
|
||||||
@@ -46,7 +50,7 @@ namespace Tools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureDropdown(Generated::TextureHandle& texHandle)
|
void TextureDropdown(Gen::TextureHandle& texHandle)
|
||||||
{
|
{
|
||||||
auto& R = Game::GameRendering::Get();
|
auto& R = Game::GameRendering::Get();
|
||||||
const char* name = GetAssetPath(texHandle.Asset);
|
const char* name = GetAssetPath(texHandle.Asset);
|
||||||
@@ -193,20 +197,21 @@ namespace Tools
|
|||||||
Vec3 quadPos = level.UIQuads.Get({0}).EData.Transform.GetPosition();
|
Vec3 quadPos = level.UIQuads.Get({0}).EData.Transform.GetPosition();
|
||||||
ImGui::Text("%f %f %f", quadPos.x, quadPos.y, quadPos.z);
|
ImGui::Text("%f %f %f", quadPos.x, quadPos.y, quadPos.z);
|
||||||
|
|
||||||
if (ImGui::ColorEdit3("Base Color", &rendering.DefaultBaseColor.x))
|
auto& puzzleVisuals = Puzzle::GetStaticPuzzleData().Visuals;
|
||||||
|
if (ImGui::ColorEdit3("Tile Base Color", &puzzleVisuals.TileBaseColor.x))
|
||||||
{
|
{
|
||||||
auto& tiles = level.PuzzleTiles;
|
auto& tiles = level.PuzzleTiles;
|
||||||
for (int32_t i = 0; i < tiles.Count; ++i)
|
for (int32_t i = 0; i < tiles.Count; ++i)
|
||||||
{
|
{
|
||||||
tiles.Data[i].EData.BaseColor = rendering.DefaultBaseColor;
|
tiles.Data[i].EData.BaseColor = puzzleVisuals.TileBaseColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ImGui::ColorEdit3("Dot Color", &rendering.DefaultTileColor.x))
|
if (ImGui::ColorEdit3("Tile Dot Color", &puzzleVisuals.TileDotColor.x))
|
||||||
{
|
{
|
||||||
auto& tiles = level.PuzzleTiles;
|
auto& tiles = level.PuzzleTiles;
|
||||||
for (int32_t i = 0; i < tiles.Count; ++i)
|
for (int32_t i = 0; i < tiles.Count; ++i)
|
||||||
{
|
{
|
||||||
tiles.Data[i].EData.TestColor = rendering.DefaultTileColor;
|
tiles.Data[i].EData.DotColor = puzzleVisuals.TileDotColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,7 +281,7 @@ namespace Tools
|
|||||||
}
|
}
|
||||||
if (ImGui::Begin("Cards"))
|
if (ImGui::Begin("Cards"))
|
||||||
{
|
{
|
||||||
Generated::StaticPuzzleData& staticData = Puzzle::GetStaticPuzzleData();
|
Gen::StaticPuzzleData& staticData = Puzzle::GetStaticPuzzleData();
|
||||||
if (ImGui::Button("Save"))
|
if (ImGui::Button("Save"))
|
||||||
{
|
{
|
||||||
Puzzle::SaveStaticPuzzleData();
|
Puzzle::SaveStaticPuzzleData();
|
||||||
@@ -291,7 +296,7 @@ namespace Tools
|
|||||||
{
|
{
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
Generated::StaticPuzzleCard& card = staticData.Cards[i];
|
Gen::StaticPuzzleCard& card = staticData.Cards[i];
|
||||||
ImGui::PushID(i);
|
ImGui::PushID(i);
|
||||||
char cardName[64]{0};
|
char cardName[64]{0};
|
||||||
bx::snprintf(cardName, sizeof(cardName), "%i", i);
|
bx::snprintf(cardName, sizeof(cardName), "%i", i);
|
||||||
@@ -313,14 +318,14 @@ namespace Tools
|
|||||||
if (x > 0) ImGui::SameLine();
|
if (x > 0) ImGui::SameLine();
|
||||||
ImGui::PushID(x);
|
ImGui::PushID(x);
|
||||||
auto& node = Puzzle::EditCardNodeAt(card, 0, x, y);
|
auto& node = Puzzle::EditCardNodeAt(card, 0, x, y);
|
||||||
if (ImGui::Button(Generated::PuzzleElementType::ShortName[node], {26, 24}))
|
if (ImGui::Button(Gen::PuzzleElementType::ShortName[node], {26, 24}))
|
||||||
{
|
{
|
||||||
int32_t newVal = int32_t(node) + 1;
|
int32_t newVal = int32_t(node) + 1;
|
||||||
if (newVal >= Generated::PuzzleElementType::EntryCount)
|
if (newVal >= Gen::PuzzleElementType::EntryCount)
|
||||||
{
|
{
|
||||||
newVal = 0;
|
newVal = 0;
|
||||||
}
|
}
|
||||||
node = Generated::PuzzleElementType::Enum(newVal);
|
node = Gen::PuzzleElementType::Enum(newVal);
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Gen.h"
|
#include "../gen/Generated.h"
|
||||||
#include "rendering/Rendering.h"
|
#include "rendering/Rendering.h"
|
||||||
|
|
||||||
namespace Tools
|
namespace Tools
|
||||||
{
|
{
|
||||||
void ModelDropdown(Generated::ModelHandle& modelHandle);
|
void ModelDropdown(Gen::ModelHandle& modelHandle);
|
||||||
void TextureDropdown(Generated::TextureHandle& texHandle);
|
void TextureDropdown(Gen::TextureHandle& texHandle);
|
||||||
void RenderDebugUI(Game::GameRendering& rendering);
|
void RenderDebugUI(Game::GameRendering& rendering);
|
||||||
void MeasureFrameEnd();
|
void MeasureFrameEnd();
|
||||||
} // namespace Tools
|
} // namespace Tools
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,22 +1,22 @@
|
|||||||
type Vec2
|
type Vec2
|
||||||
{
|
{
|
||||||
f32 X
|
f32 x
|
||||||
f32 Y
|
f32 y
|
||||||
}
|
}
|
||||||
|
|
||||||
type Vec3
|
type Vec3
|
||||||
{
|
{
|
||||||
f32 X
|
f32 x
|
||||||
f32 Y
|
f32 y
|
||||||
f32 Z
|
f32 z
|
||||||
}
|
}
|
||||||
|
|
||||||
type Vec4
|
type Vec4
|
||||||
{
|
{
|
||||||
f32 X
|
f32 x
|
||||||
f32 Y
|
f32 y
|
||||||
f32 Z
|
f32 z
|
||||||
f32 W
|
f32 w
|
||||||
}
|
}
|
||||||
|
|
||||||
type Mat3
|
type Mat3
|
||||||
@@ -85,9 +85,17 @@ type StaticPuzzleCardHandle
|
|||||||
u16 Idx Default("UINT16_MAX")
|
u16 Idx Default("UINT16_MAX")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PuzzleVisualSettings
|
||||||
|
{
|
||||||
|
Vec4 TileBaseColor
|
||||||
|
Vec4 TileDotColor
|
||||||
|
Vec4 DisabledCardTint
|
||||||
|
}
|
||||||
|
|
||||||
type StaticPuzzleData
|
type StaticPuzzleData
|
||||||
{
|
{
|
||||||
StaticPuzzleCard Cards Arr(64)
|
StaticPuzzleCard Cards Arr(64)
|
||||||
|
PuzzleVisualSettings Visuals
|
||||||
}
|
}
|
||||||
|
|
||||||
type PuzzleCardStack
|
type PuzzleCardStack
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
#include "../Gen.h"
|
||||||
#include "../Log.h"
|
#include "../Log.h"
|
||||||
#include "Dither.h"
|
#include "Dither.h"
|
||||||
|
|
||||||
|
using namespace Gen;
|
||||||
|
|
||||||
void DitherGen(DitherData& data, int32_t recursion)
|
void DitherGen(DitherData& data, int32_t recursion)
|
||||||
{
|
{
|
||||||
data.Points[0] = {0.0f, 0.0f};
|
data.Points[0] = {0.0f, 0.0f};
|
||||||
@@ -55,7 +58,7 @@ void DitherGen(DitherData& data, int32_t recursion)
|
|||||||
{
|
{
|
||||||
Vec2 vec = point - data.Points[i];
|
Vec2 vec = point - data.Points[i];
|
||||||
Vec2 wrappedVec{bx::mod(vec.x + 0.5f, 1.0f) - 0.5f, bx::mod(vec.y + 0.5f, 1.0f) - 0.5f};
|
Vec2 wrappedVec{bx::mod(vec.x + 0.5f, 1.0f) - 0.5f, bx::mod(vec.y + 0.5f, 1.0f) - 0.5f};
|
||||||
float curDist = wrappedVec.Magnitude();
|
float curDist = Magnitude(wrappedVec);
|
||||||
dist = bx::min(dist, curDist);
|
dist = bx::min(dist, curDist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../Global.h"
|
#include "../../gen/Generated.h"
|
||||||
|
|
||||||
#include <bgfx/bgfx.h>
|
#include <bgfx/bgfx.h>
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
struct DitherData
|
struct DitherData
|
||||||
{
|
{
|
||||||
static constexpr uint32_t BrightnessBucketCount = 256;
|
static constexpr uint32_t BrightnessBucketCount = 256;
|
||||||
Vec2 Points[4096];
|
Gen::Vec2 Points[4096];
|
||||||
uint32_t PointCount = 0;
|
uint32_t PointCount = 0;
|
||||||
Vec4 DitherTex[256 * 256 * 64];
|
Gen::Vec4 DitherTex[256 * 256 * 64];
|
||||||
uint32_t DitherTexWH = 0;
|
uint32_t DitherTexWH = 0;
|
||||||
uint32_t DitherTexDepth = 0;
|
uint32_t DitherTexDepth = 0;
|
||||||
int32_t BrightnessBuckets[BrightnessBucketCount];
|
int32_t BrightnessBuckets[BrightnessBucketCount];
|
||||||
|
|||||||
@@ -463,14 +463,14 @@ namespace Game
|
|||||||
mat.State = 0 | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS |
|
mat.State = 0 | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS |
|
||||||
BGFX_STATE_CULL_CCW | BGFX_STATE_MSAA;
|
BGFX_STATE_CULL_CCW | BGFX_STATE_MSAA;
|
||||||
mat.Uniforms[Material::UTime] = bgfx::createUniform("u_time", bgfx::UniformType::Vec4);
|
mat.Uniforms[Material::UTime] = bgfx::createUniform("u_time", bgfx::UniformType::Vec4);
|
||||||
mat.Uniforms[Material::UDotColor] = bgfx::createUniform("u_testColor", bgfx::UniformType::Vec4);
|
mat.Uniforms[Material::UDotColor] = bgfx::createUniform("u_dotColor", bgfx::UniformType::Vec4);
|
||||||
mat.Uniforms[Material::UTexInfo] = bgfx::createUniform("u_texInfo", bgfx::UniformType::Vec4);
|
mat.Uniforms[Material::UTexInfo] = bgfx::createUniform("u_texInfo", bgfx::UniformType::Vec4);
|
||||||
mat.Uniforms[Material::UBaseColor] = bgfx::createUniform("u_baseColor", bgfx::UniformType::Vec4);
|
mat.Uniforms[Material::UBaseColor] = bgfx::createUniform("u_baseColor", bgfx::UniformType::Vec4);
|
||||||
mat.ViewID = view;
|
mat.ViewID = view;
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
Generated::ModelHandle GameRendering::GetModelHandleFromPath(const char* path)
|
Gen::ModelHandle GameRendering::GetModelHandleFromPath(const char* path)
|
||||||
{
|
{
|
||||||
uint32_t AssetHandle = CrcPath(path);
|
uint32_t AssetHandle = CrcPath(path);
|
||||||
for (int32_t i = 0; i < ModelCount; ++i)
|
for (int32_t i = 0; i < ModelCount; ++i)
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
#include <bx/string.h>
|
#include <bx/string.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include "../Gen.h" // IWYU pragma: keep
|
#include "../../gen/Generated.h"
|
||||||
#include "../Global.h"
|
|
||||||
#include "Dither.h"
|
#include "Dither.h"
|
||||||
|
|
||||||
union SDL_Event;
|
union SDL_Event;
|
||||||
@@ -30,7 +29,7 @@ namespace Game
|
|||||||
bgfx::UniformHandle SamplerHandle = {bgfx::kInvalidHandle};
|
bgfx::UniformHandle SamplerHandle = {bgfx::kInvalidHandle};
|
||||||
bgfx::TextureHandle RenderHandle = {bgfx::kInvalidHandle};
|
bgfx::TextureHandle RenderHandle = {bgfx::kInvalidHandle};
|
||||||
bgfx::TextureInfo Info;
|
bgfx::TextureInfo Info;
|
||||||
Generated::TextureHandle TexHandle;
|
Gen::TextureHandle TexHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Model
|
struct Model
|
||||||
@@ -38,7 +37,7 @@ namespace Game
|
|||||||
bgfx::VertexBufferHandle VertexBuffer = {bgfx::kInvalidHandle};
|
bgfx::VertexBufferHandle VertexBuffer = {bgfx::kInvalidHandle};
|
||||||
bgfx::IndexBufferHandle IndexBuffer = {bgfx::kInvalidHandle};
|
bgfx::IndexBufferHandle IndexBuffer = {bgfx::kInvalidHandle};
|
||||||
bgfx::VertexLayout VertLayout;
|
bgfx::VertexLayout VertLayout;
|
||||||
Generated::ModelHandle Handle;
|
Gen::ModelHandle Handle;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Material
|
struct Material
|
||||||
@@ -95,8 +94,6 @@ namespace Game
|
|||||||
uint16_t MainViewID = 10;
|
uint16_t MainViewID = 10;
|
||||||
float LastShaderLoadTime = 0.0f;
|
float LastShaderLoadTime = 0.0f;
|
||||||
int32_t DitherRecursion = 1;
|
int32_t DitherRecursion = 1;
|
||||||
Vec4 DefaultBaseColor;
|
|
||||||
Vec4 DefaultTileColor;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Setup();
|
void Setup();
|
||||||
@@ -105,6 +102,6 @@ namespace Game
|
|||||||
void LoadTextures();
|
void LoadTextures();
|
||||||
void ReloadShaders();
|
void ReloadShaders();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
Generated::ModelHandle GetModelHandleFromPath(const char* path);
|
Gen::ModelHandle GetModelHandleFromPath(const char* path);
|
||||||
};
|
};
|
||||||
} // namespace Game
|
} // namespace Game
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ SAMPLER2D(s_texColor, 0);
|
|||||||
SAMPLER3D(s_ditherSampler, 1);
|
SAMPLER3D(s_ditherSampler, 1);
|
||||||
SAMPLER2D(s_rampSampler, 2);
|
SAMPLER2D(s_rampSampler, 2);
|
||||||
uniform vec4 u_time;
|
uniform vec4 u_time;
|
||||||
uniform vec4 u_testColor;
|
uniform vec4 u_dotColor;
|
||||||
uniform vec4 u_texInfo;
|
uniform vec4 u_texInfo;
|
||||||
uniform vec4 u_baseColor;
|
uniform vec4 u_baseColor;
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ void main()
|
|||||||
float testSpeed = 1.0;
|
float testSpeed = 1.0;
|
||||||
vec3 testOffset = vec3(0.0, 0.0, 50.0);
|
vec3 testOffset = vec3(0.0, 0.0, 50.0);
|
||||||
float3 lightPos = vec3(sin(u_time.x * testSpeed) * testRadius, 5.0, cos(u_time.x * testSpeed) * testRadius);
|
float3 lightPos = vec3(sin(u_time.x * testSpeed) * testRadius, 5.0, cos(u_time.x * testSpeed) * testRadius);
|
||||||
vec3 texColor = u_testColor.x > 0.1 ? u_testColor.xyz : texture2D(s_texColor, v_uv0).xyz;
|
vec3 texColor = u_dotColor.x > 0.1 ? u_dotColor.xyz : texture2D(s_texColor, v_uv0).xyz;
|
||||||
|
|
||||||
// lighting
|
// lighting
|
||||||
// float brightness = calcBrightness(lightPos, v_wpos, v_normal);
|
// float brightness = calcBrightness(lightPos, v_wpos, v_normal);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ SAMPLER2D(s_texColor, 0);
|
|||||||
SAMPLER3D(s_ditherSampler, 1);
|
SAMPLER3D(s_ditherSampler, 1);
|
||||||
SAMPLER2D(s_rampSampler, 2);
|
SAMPLER2D(s_rampSampler, 2);
|
||||||
uniform vec4 u_time;
|
uniform vec4 u_time;
|
||||||
uniform vec4 u_testColor;
|
uniform vec4 u_dotColor;
|
||||||
uniform vec4 u_texInfo;
|
uniform vec4 u_texInfo;
|
||||||
uniform vec4 u_baseColor;
|
uniform vec4 u_baseColor;
|
||||||
|
|
||||||
@@ -89,6 +89,7 @@ void main()
|
|||||||
{
|
{
|
||||||
vec2 uv = vec2(1.0 - v_uv0.x, v_uv0.y);
|
vec2 uv = vec2(1.0 - v_uv0.x, v_uv0.y);
|
||||||
vec3 rawTex = texture2D(s_texColor, uv).xyz;
|
vec3 rawTex = texture2D(s_texColor, uv).xyz;
|
||||||
|
vec3 col = rawTex * u_dotColor.xyz;
|
||||||
float brightness = lerp(0.5, 0.9, calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal));
|
float brightness = lerp(0.5, 0.9, calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal));
|
||||||
gl_FragColor = vec4(rawTex, 1.0);
|
gl_FragColor = vec4(col * brightness, 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
template bool Save<T>(const T* obj, uint32_t count, Serializer& serializer); \
|
template bool Save<T>(const T* obj, uint32_t count, Serializer& serializer); \
|
||||||
template bool Load<T>(T * obj, uint32_t count, Deserializer & serializer);
|
template bool Load<T>(T * obj, uint32_t count, Deserializer & serializer);
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
template <typename T> bool Save(const T* obj, uint32_t count, Serializer& serializer)
|
template <typename T> bool Save(const T* obj, uint32_t count, Serializer& serializer)
|
||||||
{
|
{
|
||||||
@@ -38,4 +38,4 @@ namespace Generated
|
|||||||
INST(double)
|
INST(double)
|
||||||
INST(bool)
|
INST(bool)
|
||||||
INST(char)
|
INST(char)
|
||||||
} // namespace Generated
|
} // namespace Gen
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../dependency/minidef/src/TypeDef.h"
|
|
||||||
#include "../game/Log.h"
|
#include "../game/Log.h"
|
||||||
|
|
||||||
#include "bx/string.h"
|
#include "bx/string.h"
|
||||||
#include <bx/file.h>
|
#include <bx/file.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
struct Serializer
|
struct Serializer
|
||||||
{
|
{
|
||||||
@@ -170,4 +169,4 @@ namespace Generated
|
|||||||
|
|
||||||
template <typename T> bool Save(const T* obj, uint32_t count, Serializer& serializer);
|
template <typename T> bool Save(const T* obj, uint32_t count, Serializer& serializer);
|
||||||
template <typename T> bool Load(T* obj, uint32_t count, Deserializer& serializer);
|
template <typename T> bool Load(T* obj, uint32_t count, Deserializer& serializer);
|
||||||
} // namespace Generated
|
} // namespace Gen
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "Generated.h"
|
#include "Generated.h"
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
bool Save(const PuzzleElementType::Enum* obj, uint32_t count, Serializer& serializer)
|
bool Save(const PuzzleElementType::Enum* obj, uint32_t count, Serializer& serializer)
|
||||||
{
|
{
|
||||||
@@ -27,8 +27,8 @@ namespace Generated
|
|||||||
bool isOk = true;
|
bool isOk = true;
|
||||||
for (uint32_t i = 0; i < count; ++i)
|
for (uint32_t i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
isOk = Save(&obj[i].X, 1, serializer) && isOk;
|
isOk = Save(&obj[i].x, 1, serializer) && isOk;
|
||||||
isOk = Save(&obj[i].Y, 1, serializer) && isOk;
|
isOk = Save(&obj[i].y, 1, serializer) && isOk;
|
||||||
}
|
}
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
@@ -37,8 +37,8 @@ namespace Generated
|
|||||||
bool isOk = true;
|
bool isOk = true;
|
||||||
for (uint32_t i = 0; i < count; ++i)
|
for (uint32_t i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
isOk = Load(&obj[i].X, 1, serializer) && isOk;
|
isOk = Load(&obj[i].x, 1, serializer) && isOk;
|
||||||
isOk = Load(&obj[i].Y, 1, serializer) && isOk;
|
isOk = Load(&obj[i].y, 1, serializer) && isOk;
|
||||||
}
|
}
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
@@ -47,9 +47,9 @@ namespace Generated
|
|||||||
bool isOk = true;
|
bool isOk = true;
|
||||||
for (uint32_t i = 0; i < count; ++i)
|
for (uint32_t i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
isOk = Save(&obj[i].X, 1, serializer) && isOk;
|
isOk = Save(&obj[i].x, 1, serializer) && isOk;
|
||||||
isOk = Save(&obj[i].Y, 1, serializer) && isOk;
|
isOk = Save(&obj[i].y, 1, serializer) && isOk;
|
||||||
isOk = Save(&obj[i].Z, 1, serializer) && isOk;
|
isOk = Save(&obj[i].z, 1, serializer) && isOk;
|
||||||
}
|
}
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
@@ -58,9 +58,9 @@ namespace Generated
|
|||||||
bool isOk = true;
|
bool isOk = true;
|
||||||
for (uint32_t i = 0; i < count; ++i)
|
for (uint32_t i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
isOk = Load(&obj[i].X, 1, serializer) && isOk;
|
isOk = Load(&obj[i].x, 1, serializer) && isOk;
|
||||||
isOk = Load(&obj[i].Y, 1, serializer) && isOk;
|
isOk = Load(&obj[i].y, 1, serializer) && isOk;
|
||||||
isOk = Load(&obj[i].Z, 1, serializer) && isOk;
|
isOk = Load(&obj[i].z, 1, serializer) && isOk;
|
||||||
}
|
}
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
@@ -69,10 +69,10 @@ namespace Generated
|
|||||||
bool isOk = true;
|
bool isOk = true;
|
||||||
for (uint32_t i = 0; i < count; ++i)
|
for (uint32_t i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
isOk = Save(&obj[i].X, 1, serializer) && isOk;
|
isOk = Save(&obj[i].x, 1, serializer) && isOk;
|
||||||
isOk = Save(&obj[i].Y, 1, serializer) && isOk;
|
isOk = Save(&obj[i].y, 1, serializer) && isOk;
|
||||||
isOk = Save(&obj[i].Z, 1, serializer) && isOk;
|
isOk = Save(&obj[i].z, 1, serializer) && isOk;
|
||||||
isOk = Save(&obj[i].W, 1, serializer) && isOk;
|
isOk = Save(&obj[i].w, 1, serializer) && isOk;
|
||||||
}
|
}
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
@@ -81,10 +81,10 @@ namespace Generated
|
|||||||
bool isOk = true;
|
bool isOk = true;
|
||||||
for (uint32_t i = 0; i < count; ++i)
|
for (uint32_t i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
isOk = Load(&obj[i].X, 1, serializer) && isOk;
|
isOk = Load(&obj[i].x, 1, serializer) && isOk;
|
||||||
isOk = Load(&obj[i].Y, 1, serializer) && isOk;
|
isOk = Load(&obj[i].y, 1, serializer) && isOk;
|
||||||
isOk = Load(&obj[i].Z, 1, serializer) && isOk;
|
isOk = Load(&obj[i].z, 1, serializer) && isOk;
|
||||||
isOk = Load(&obj[i].W, 1, serializer) && isOk;
|
isOk = Load(&obj[i].w, 1, serializer) && isOk;
|
||||||
}
|
}
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
@@ -242,12 +242,35 @@ namespace Generated
|
|||||||
}
|
}
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
|
bool Save(const PuzzleVisualSettings* obj, uint32_t count, Serializer& serializer)
|
||||||
|
{
|
||||||
|
bool isOk = true;
|
||||||
|
for (uint32_t i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
isOk = Save(&obj[i].TileBaseColor, 1, serializer) && isOk;
|
||||||
|
isOk = Save(&obj[i].TileDotColor, 1, serializer) && isOk;
|
||||||
|
isOk = Save(&obj[i].DisabledCardTint, 1, serializer) && isOk;
|
||||||
|
}
|
||||||
|
return isOk;
|
||||||
|
}
|
||||||
|
bool Load(PuzzleVisualSettings* obj, uint32_t count, Deserializer& serializer)
|
||||||
|
{
|
||||||
|
bool isOk = true;
|
||||||
|
for (uint32_t i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
isOk = Load(&obj[i].TileBaseColor, 1, serializer) && isOk;
|
||||||
|
isOk = Load(&obj[i].TileDotColor, 1, serializer) && isOk;
|
||||||
|
isOk = Load(&obj[i].DisabledCardTint, 1, serializer) && isOk;
|
||||||
|
}
|
||||||
|
return isOk;
|
||||||
|
}
|
||||||
bool Save(const StaticPuzzleData* obj, uint32_t count, Serializer& serializer)
|
bool Save(const StaticPuzzleData* obj, uint32_t count, Serializer& serializer)
|
||||||
{
|
{
|
||||||
bool isOk = true;
|
bool isOk = true;
|
||||||
for (uint32_t i = 0; i < count; ++i)
|
for (uint32_t i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
isOk = Save(obj[i].Cards, 64, serializer) && isOk;
|
isOk = Save(obj[i].Cards, 64, serializer) && isOk;
|
||||||
|
isOk = Save(&obj[i].Visuals, 1, serializer) && isOk;
|
||||||
}
|
}
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
@@ -257,6 +280,7 @@ namespace Generated
|
|||||||
for (uint32_t i = 0; i < count; ++i)
|
for (uint32_t i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
isOk = Load(obj[i].Cards, 64, serializer) && isOk;
|
isOk = Load(obj[i].Cards, 64, serializer) && isOk;
|
||||||
|
isOk = Load(&obj[i].Visuals, 1, serializer) && isOk;
|
||||||
}
|
}
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
@@ -342,4 +366,4 @@ namespace Generated
|
|||||||
}
|
}
|
||||||
return isOk;
|
return isOk;
|
||||||
}
|
}
|
||||||
}
|
} // namespace Gen
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Def.h"
|
#include "Def.h"
|
||||||
|
|
||||||
namespace Generated
|
namespace Gen
|
||||||
{
|
{
|
||||||
struct PuzzleElementType
|
struct PuzzleElementType
|
||||||
{
|
{
|
||||||
@@ -18,8 +18,7 @@ namespace Generated
|
|||||||
Blocked,
|
Blocked,
|
||||||
Bridge,
|
Bridge,
|
||||||
};
|
};
|
||||||
static constexpr char EntryNames[EntryCount][64]
|
static constexpr char EntryNames[EntryCount][64]{
|
||||||
{
|
|
||||||
"None",
|
"None",
|
||||||
"WaterIn",
|
"WaterIn",
|
||||||
"WaterGoal",
|
"WaterGoal",
|
||||||
@@ -29,8 +28,7 @@ namespace Generated
|
|||||||
"Blocked",
|
"Blocked",
|
||||||
"Bridge",
|
"Bridge",
|
||||||
};
|
};
|
||||||
static constexpr char GameName[EntryCount][64]
|
static constexpr char GameName[EntryCount][64]{
|
||||||
{
|
|
||||||
"Empty",
|
"Empty",
|
||||||
"Water Source",
|
"Water Source",
|
||||||
"Water Goal",
|
"Water Goal",
|
||||||
@@ -40,8 +38,7 @@ namespace Generated
|
|||||||
"Blocked",
|
"Blocked",
|
||||||
"Bridge",
|
"Bridge",
|
||||||
};
|
};
|
||||||
static constexpr char ShortName[EntryCount][64]
|
static constexpr char ShortName[EntryCount][64]{
|
||||||
{
|
|
||||||
" ",
|
" ",
|
||||||
"~+",
|
"~+",
|
||||||
"~!",
|
"~!",
|
||||||
@@ -54,43 +51,34 @@ namespace Generated
|
|||||||
};
|
};
|
||||||
struct Vec2
|
struct Vec2
|
||||||
{
|
{
|
||||||
static constexpr uint32_t Hash = 4242122113;
|
static constexpr uint32_t Hash = 2667033957;
|
||||||
float X = {};
|
float x = {};
|
||||||
float Y = {};
|
float y = {};
|
||||||
};
|
};
|
||||||
struct Vec3
|
struct Vec3
|
||||||
{
|
{
|
||||||
static constexpr uint32_t Hash = 1694997017;
|
static constexpr uint32_t Hash = 473740858;
|
||||||
float X = {};
|
float x = {};
|
||||||
float Y = {};
|
float y = {};
|
||||||
float Z = {};
|
float z = {};
|
||||||
};
|
};
|
||||||
struct Vec4
|
struct Vec4
|
||||||
{
|
{
|
||||||
static constexpr uint32_t Hash = 447058821;
|
static constexpr uint32_t Hash = 2507696603;
|
||||||
float X = {};
|
float x = {};
|
||||||
float Y = {};
|
float y = {};
|
||||||
float Z = {};
|
float z = {};
|
||||||
float W = {};
|
float w = {};
|
||||||
};
|
};
|
||||||
struct Mat3
|
struct Mat3
|
||||||
{
|
{
|
||||||
static constexpr uint32_t Hash = 3364737048;
|
static constexpr uint32_t Hash = 3364737048;
|
||||||
float M[9] = {
|
float M[9] = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
1.0f, 0.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 0.0f, 1.0f
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
struct Mat4
|
struct Mat4
|
||||||
{
|
{
|
||||||
static constexpr uint32_t Hash = 1650094019;
|
static constexpr uint32_t Hash = 1650094019;
|
||||||
float M[16] = {
|
float M[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
1.0f, 0.0f, 0.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f, 0.0f,
|
|
||||||
0.0f, 0.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 0.0f, 0.0f, 1.0f
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
struct AssetHandle
|
struct AssetHandle
|
||||||
{
|
{
|
||||||
@@ -127,10 +115,18 @@ namespace Generated
|
|||||||
static constexpr uint32_t Hash = 1742502768;
|
static constexpr uint32_t Hash = 1742502768;
|
||||||
uint16_t Idx = UINT16_MAX;
|
uint16_t Idx = UINT16_MAX;
|
||||||
};
|
};
|
||||||
|
struct PuzzleVisualSettings
|
||||||
|
{
|
||||||
|
static constexpr uint32_t Hash = 4208425878;
|
||||||
|
Vec4 TileBaseColor = {};
|
||||||
|
Vec4 TileDotColor = {};
|
||||||
|
Vec4 DisabledCardTint = {};
|
||||||
|
};
|
||||||
struct StaticPuzzleData
|
struct StaticPuzzleData
|
||||||
{
|
{
|
||||||
static constexpr uint32_t Hash = 1497693577;
|
static constexpr uint32_t Hash = 1076634601;
|
||||||
StaticPuzzleCard Cards[64] = {};
|
StaticPuzzleCard Cards[64] = {};
|
||||||
|
PuzzleVisualSettings Visuals = {};
|
||||||
};
|
};
|
||||||
struct PuzzleCardStack
|
struct PuzzleCardStack
|
||||||
{
|
{
|
||||||
@@ -185,6 +181,8 @@ namespace Generated
|
|||||||
bool Load(StaticPuzzleCard* obj, uint32_t count, Deserializer& serializer);
|
bool Load(StaticPuzzleCard* obj, uint32_t count, Deserializer& serializer);
|
||||||
bool Save(const StaticPuzzleCardHandle* obj, uint32_t count, Serializer& serializer);
|
bool Save(const StaticPuzzleCardHandle* obj, uint32_t count, Serializer& serializer);
|
||||||
bool Load(StaticPuzzleCardHandle* obj, uint32_t count, Deserializer& serializer);
|
bool Load(StaticPuzzleCardHandle* obj, uint32_t count, Deserializer& serializer);
|
||||||
|
bool Save(const PuzzleVisualSettings* obj, uint32_t count, Serializer& serializer);
|
||||||
|
bool Load(PuzzleVisualSettings* obj, uint32_t count, Deserializer& serializer);
|
||||||
bool Save(const StaticPuzzleData* obj, uint32_t count, Serializer& serializer);
|
bool Save(const StaticPuzzleData* obj, uint32_t count, Serializer& serializer);
|
||||||
bool Load(StaticPuzzleData* obj, uint32_t count, Deserializer& serializer);
|
bool Load(StaticPuzzleData* obj, uint32_t count, Deserializer& serializer);
|
||||||
bool Save(const PuzzleCardStack* obj, uint32_t count, Serializer& serializer);
|
bool Save(const PuzzleCardStack* obj, uint32_t count, Serializer& serializer);
|
||||||
@@ -193,4 +191,4 @@ namespace Generated
|
|||||||
bool Load(PlacedPuzzleCard* obj, uint32_t count, Deserializer& serializer);
|
bool Load(PlacedPuzzleCard* obj, uint32_t count, Deserializer& serializer);
|
||||||
bool Save(const PuzzleData* obj, uint32_t count, Serializer& serializer);
|
bool Save(const PuzzleData* obj, uint32_t count, Serializer& serializer);
|
||||||
bool Load(PuzzleData* obj, uint32_t count, Deserializer& serializer);
|
bool Load(PuzzleData* obj, uint32_t count, Deserializer& serializer);
|
||||||
}
|
} // namespace Gen
|
||||||
|
|||||||
Reference in New Issue
Block a user