include cleanup

This commit is contained in:
Asuro
2025-03-30 20:17:32 +02:00
parent 052fc2cc07
commit 6d170be57a
28 changed files with 173 additions and 379 deletions

View File

@@ -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]);

View File

@@ -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

View File

@@ -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

View File

@@ -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)
{ {

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
namespace Generated namespace Gen
{ {
struct Serializer; struct Serializer;
struct Deserializer; struct Deserializer;

View File

@@ -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;
} }
} }

View File

@@ -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;
}; };

View File

@@ -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,4 @@ namespace Generated
res.Y += rhs.Y; res.Y += rhs.Y;
return res; return res;
} }
} // namespace Generated } // namespace Gen

View File

@@ -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,4 @@ 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 } // namespace Gen

View File

@@ -6,7 +6,7 @@
#include <cassert> #include <cassert>
#include <cstdint> #include <cstdint>
using namespace Generated; using namespace Gen;
namespace namespace
{ {

View File

@@ -1,215 +1,8 @@
#pragma once #pragma once
#include "Gen.h" #include "../gen/Generated.h"
#include "bx/math.h" #include "bx/math.h"
using namespace Generated;
// 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)
{ {
return in | flags; return in | flags;
@@ -231,97 +24,110 @@ inline bool GetFlag(int32_t in, int32_t flags)
return (in & flags) > 0; return (in & flags) > 0;
} }
namespace Gen
{
bool IsValid(const AssetHandle& h);
bool IsValid(const ModelHandle& h);
bool IsValid(const TextureHandle& h);
bool operator==(const AssetHandle& lhs, const AssetHandle& rhs);
bool operator==(const ModelHandle& lhs, const ModelHandle& rhs);
PuzPos operator+=(PuzPos lhs, const PuzPos& rhs);
PuzPos operator+(PuzPos lhs, const PuzPos& rhs);
} // namespace Gen
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();
}; };
Vec4& operator+=(Vec4& lhs, const Vec4& rhs); Gen::Vec4& operator+=(Gen::Vec4& lhs, const Gen::Vec4& rhs);
Vec4 operator+(const Vec4& lhs, const Vec4& rhs); Gen::Vec4 operator+(const Gen::Vec4& lhs, const Gen::Vec4& rhs);
Vec4& operator+=(Vec4& lhs, float rhs); Gen::Vec4& operator+=(Gen::Vec4& lhs, float rhs);
Vec4 operator+(Vec4& lhs, float rhs); Gen::Vec4 operator+(Gen::Vec4& lhs, float rhs);
Vec4& operator-=(Vec4& lhs, const Vec4& rhs); Gen::Vec4& operator-=(Gen::Vec4& lhs, const Gen::Vec4& rhs);
Vec4 operator-(const Vec4& lhs, const Vec4& rhs); Gen::Vec4 operator-(const Gen::Vec4& lhs, const Gen::Vec4& rhs);
Vec4& operator-=(Vec4& lhs, float rhs); Gen::Vec4& operator-=(Gen::Vec4& lhs, float rhs);
Vec4 operator-(const Vec4& lhs, float rhs); Gen::Vec4 operator-(const Gen::Vec4& lhs, float rhs);
Vec4& operator*=(Vec4& lhs, float rhs); Gen::Vec4& operator*=(Gen::Vec4& lhs, float rhs);
Vec4 operator*(const Vec4& lhs, float rhs); Gen::Vec4 operator*(const Gen::Vec4& lhs, float rhs);
Vec4& operator/=(Vec4& lhs, float rhs); Gen::Vec4& operator/=(Gen::Vec4& lhs, float rhs);
Vec4 operator/(const Vec4& lhs, float rhs); Gen::Vec4 operator/(const Gen::Vec4& lhs, float rhs);
Vec3& operator+=(Vec3& lhs, const Vec3& rhs); Gen::Vec3& operator+=(Gen::Vec3& lhs, const Gen::Vec3& rhs);
Vec3 operator+(const Vec3& lhs, const Vec3& rhs); Gen::Vec3 operator+(const Gen::Vec3& lhs, const Gen::Vec3& rhs);
Vec3& operator+=(Vec3& lhs, float rhs); Gen::Vec3& operator+=(Gen::Vec3& lhs, float rhs);
Vec3 operator+(Vec3& lhs, float rhs); Gen::Vec3 operator+(Gen::Vec3& lhs, float rhs);
Vec3& operator-=(Vec3& lhs, const Vec3& rhs); Gen::Vec3& operator-=(Gen::Vec3& lhs, const Gen::Vec3& rhs);
Vec3 operator-(const Vec3& lhs, const Vec3& rhs); Gen::Vec3 operator-(const Gen::Vec3& lhs, const Gen::Vec3& rhs);
Vec3& operator-=(Vec3& lhs, float rhs); Gen::Vec3& operator-=(Gen::Vec3& lhs, float rhs);
Vec3 operator-(const Vec3& lhs, float rhs); Gen::Vec3 operator-(const Gen::Vec3& lhs, float rhs);
Vec3& operator*=(Vec3& lhs, float rhs); Gen::Vec3& operator*=(Gen::Vec3& lhs, float rhs);
Vec3 operator*(const Vec3& lhs, float rhs); Gen::Vec3 operator*(const Gen::Vec3& lhs, float rhs);
Vec3& operator/=(Vec3& lhs, float rhs); Gen::Vec3& operator/=(Gen::Vec3& lhs, float rhs);
Vec3 operator/(const Vec3& lhs, float rhs); Gen::Vec3 operator/(const Gen::Vec3& lhs, float rhs);
Vec2& operator+=(Vec2& lhs, const Vec2& rhs); Gen::Vec2& operator+=(Gen::Vec2& lhs, const Gen::Vec2& rhs);
Vec2 operator+(const Vec2& lhs, const Vec2& rhs); Gen::Vec2 operator+(const Gen::Vec2& lhs, const Gen::Vec2& rhs);
Vec2& operator+=(Vec2& lhs, float rhs); Gen::Vec2& operator+=(Gen::Vec2& lhs, float rhs);
Vec2 operator+(Vec2& lhs, float rhs); Gen::Vec2 operator+(Gen::Vec2& lhs, float rhs);
Vec2& operator-=(Vec2& lhs, const Vec2& rhs); Gen::Vec2& operator-=(Gen::Vec2& lhs, const Gen::Vec2& rhs);
Vec2 operator-(const Vec2& lhs, const Vec2& rhs); Gen::Vec2 operator-(const Gen::Vec2& lhs, const Gen::Vec2& rhs);
Vec2& operator-=(Vec2& lhs, float rhs); Gen::Vec2& operator-=(Gen::Vec2& lhs, float rhs);
Vec2 operator-(const Vec2& lhs, float rhs); Gen::Vec2 operator-(const Gen::Vec2& lhs, float rhs);
Vec2& operator*=(Vec2& lhs, float rhs); Gen::Vec2& operator*=(Gen::Vec2& lhs, float rhs);
Vec2 operator*(const Vec2& lhs, float rhs); Gen::Vec2 operator*(const Gen::Vec2& lhs, float rhs);
Vec2& operator/=(Vec2& lhs, float rhs); Gen::Vec2& operator/=(Gen::Vec2& lhs, float rhs);
Vec2 operator/(const Vec2& lhs, float rhs); Gen::Vec2 operator/(const Gen::Vec2& lhs, float rhs);
float Magnitude(const Vec4& vec); float Magnitude(const Gen::Vec4& vec);
float Magnitude(const Vec3& vec); float Magnitude(const Gen::Vec3& vec);
float Magnitude(const Vec2& vec); float Magnitude(const Gen::Vec2& vec);
Vec4 Normalized(const Vec4& vec); Gen::Vec4 Normalized(const Gen::Vec4& vec);
Vec3 Normalized(const Vec3& vec); Gen::Vec3 Normalized(const Gen::Vec3& vec);
Vec2 Normalized(const Vec2& vec); Gen::Vec2 Normalized(const Gen::Vec2& vec);
Mat4 Inverse(const Mat4& mat); Gen::Mat4 Inverse(const Gen::Mat4& mat);
Mat4 Transpose(const Mat4& mat); Gen::Mat4 Transpose(const Gen::Mat4& mat);
Vec4 Mul(const Mat4& mat, const Vec4& vec); Gen::Vec4 Mul(const Gen::Mat4& mat, const Gen::Vec4& vec);
float DotProduct(Vec3 a, Vec3 b); float DotProduct(Gen::Vec3 a, Gen::Vec3 b);
Vec3 CrossProduct(Vec3 a, Vec3 b); Gen::Vec3 CrossProduct(Gen::Vec3 a, Gen::Vec3 b);
Vec3 CrossProductFromPlane(Vec3 a, Vec3 b, Vec3 c); Gen::Vec3 CrossProductFromPlane(Gen::Vec3 a, Gen::Vec3 b, Gen::Vec3 c);
bool RayPlaneIntersect(Vec3 l1, Vec3 l2, Vec3 p1, Vec3 p2, Vec3 p3, Vec3& out); bool RayPlaneIntersect(Gen::Vec3 l1, Gen::Vec3 l2, Gen::Vec3 p1, Gen::Vec3 p2, Gen::Vec3 p3, Gen::Vec3& out);
struct SharedData; struct SharedData;

View File

@@ -5,6 +5,8 @@
namespace Game namespace Game
{ {
using namespace Gen;
bool IsKeyboardAllowed() bool IsKeyboardAllowed()
{ {
auto& IO = ImGui::GetIO(); auto& IO = ImGui::GetIO();

View File

@@ -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

View File

@@ -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;

View File

@@ -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,14 +20,14 @@
#include <cstdint> #include <cstdint>
#include <tracy/Tracy.hpp> #include <tracy/Tracy.hpp>
using namespace Generated; 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();
@@ -119,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))
@@ -355,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]);
@@ -378,7 +377,7 @@ 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.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;
@@ -416,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))
@@ -428,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))

View File

@@ -21,12 +21,12 @@ namespace Game
{ {
struct EntityRenderData struct EntityRenderData
{ {
Vec4 DotColor{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:

View File

@@ -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;

View File

@@ -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);

View File

@@ -8,7 +8,7 @@
#include <imgui.h> #include <imgui.h>
#include <tracy/Tracy.hpp> #include <tracy/Tracy.hpp>
using namespace Generated; using namespace Gen;
namespace namespace
{ {
@@ -19,7 +19,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)
@@ -32,7 +32,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);
@@ -49,7 +49,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);
@@ -280,7 +280,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();
@@ -295,7 +295,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);
@@ -317,14 +317,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();
} }

View File

@@ -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

View File

@@ -1,7 +1,8 @@
#include "../Global.h"
#include "../Log.h" #include "../Log.h"
#include "Dither.h" #include "Dither.h"
using namespace Generated; using namespace Gen;
void DitherGen(DitherData& data, int32_t recursion) void DitherGen(DitherData& data, int32_t recursion)
{ {

View File

@@ -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];

View File

@@ -470,7 +470,7 @@ namespace Game
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)

View File

@@ -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
@@ -103,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

View File

@@ -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

View File

@@ -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

View File

@@ -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)
{ {
@@ -366,4 +366,4 @@ namespace Generated
} }
return isOk; return isOk;
} }
} } // namespace Gen

View File

@@ -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]{
{
" ", " ",
"~+", "~+",
"~!", "~!",
@@ -76,21 +73,12 @@ namespace Generated
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
{ {
@@ -203,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