fixing stuff
This commit is contained in:
48
src/game/Gen.cpp
Normal file
48
src/game/Gen.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "Gen.h"
|
||||
|
||||
namespace Generated
|
||||
{
|
||||
bool IsValid(const ModelHandle& h)
|
||||
{
|
||||
return h.ModelIdx != UINT16_MAX && IsValid(h.Asset);
|
||||
}
|
||||
bool IsValid(const AssetHandle& h)
|
||||
{
|
||||
return h.Idx != UINT32_MAX;
|
||||
}
|
||||
bool operator==(const AssetHandle& lhs, const AssetHandle& rhs)
|
||||
{
|
||||
return lhs.Idx == rhs.Idx;
|
||||
}
|
||||
bool operator==(const ModelHandle& lhs, const ModelHandle& rhs)
|
||||
{
|
||||
if (!IsValid(lhs) || !IsValid(rhs)) return IsValid(lhs) == IsValid(rhs);
|
||||
return lhs.ModelIdx == rhs.ModelIdx && lhs.Asset == rhs.Asset;
|
||||
}
|
||||
PuzPos operator+=(PuzPos lhs, const PuzPos& rhs)
|
||||
{
|
||||
lhs.X += rhs.X;
|
||||
lhs.Y += rhs.Y;
|
||||
return lhs;
|
||||
}
|
||||
PuzPos operator+(PuzPos lhs, const PuzPos& rhs)
|
||||
{
|
||||
PuzPos res = lhs;
|
||||
res.X += rhs.X;
|
||||
res.Y += rhs.Y;
|
||||
return res;
|
||||
}
|
||||
PuzPos operator-=(PuzPos lhs, const PuzPos& rhs)
|
||||
{
|
||||
lhs.X -= rhs.X;
|
||||
lhs.Y -= rhs.Y;
|
||||
return lhs;
|
||||
}
|
||||
PuzPos operator-(PuzPos lhs, const PuzPos& rhs)
|
||||
{
|
||||
PuzPos res = lhs;
|
||||
res.X += rhs.X;
|
||||
res.Y += rhs.Y;
|
||||
return res;
|
||||
}
|
||||
} // namespace Generated
|
||||
14
src/game/Gen.h
Normal file
14
src/game/Gen.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "../gen/Generated.h"
|
||||
|
||||
namespace Generated
|
||||
{
|
||||
bool IsValid(const AssetHandle& h);
|
||||
bool IsValid(const ModelHandle& 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 Generated
|
||||
@@ -45,7 +45,7 @@ namespace Game
|
||||
char ImguiIni[4096]{0};
|
||||
static constexpr uint32_t MaxAssets = 128;
|
||||
uint32_t AssetCount = 0;
|
||||
uint32_t AssetHandles[MaxAssets]{0};
|
||||
Generated::AssetHandle AssetHandles[MaxAssets]{0};
|
||||
char AssetHandlePaths[MaxAssets][128];
|
||||
bool ShowImguiDemo = false;
|
||||
uint8_t DebugCardRotation = 0;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "../gen/Def.h"
|
||||
#include "Gen.h"
|
||||
#include "Global.h"
|
||||
#include "Input.h"
|
||||
#include "Instance.h"
|
||||
@@ -23,14 +24,14 @@ namespace Game
|
||||
{
|
||||
void EntityRenderData::Render(const Model* models, const Material* materials)
|
||||
{
|
||||
if (ModelHandle == UINT16_MAX || MaterialHandle == UINT16_MAX) return;
|
||||
if (!Generated::IsValid(ModelH) || MaterialHandle == UINT16_MAX) return;
|
||||
if (!Visible) return;
|
||||
auto& rendering = GameRendering::Get();
|
||||
|
||||
Transform.UpdateMatrix();
|
||||
bgfx::setTransform(Transform.M.M);
|
||||
|
||||
const Model& currentModel = models[ModelHandle];
|
||||
const Model& currentModel = models[ModelH.ModelIdx];
|
||||
const Material& currentMaterial = materials[MaterialHandle];
|
||||
bgfx::setVertexBuffer(0, currentModel.VertexBuffer);
|
||||
bgfx::setIndexBuffer(currentModel.IndexBuffer);
|
||||
@@ -277,7 +278,7 @@ namespace Game
|
||||
void Cube::Setup()
|
||||
{
|
||||
EData.MaterialHandle = 0;
|
||||
EData.ModelHandle = GameRendering::Get().GetModelHandleFromPath("models/cube.gltf");
|
||||
EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/cube.gltf");
|
||||
}
|
||||
|
||||
void Cube::Update()
|
||||
@@ -300,7 +301,7 @@ namespace Game
|
||||
void TestEntity::Setup()
|
||||
{
|
||||
EData.MaterialHandle = 0;
|
||||
EData.ModelHandle = GameRendering::Get().GetModelHandleFromPath("models/zurg.gltf");
|
||||
EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/zurg.gltf");
|
||||
|
||||
EData.Transform.Position = {0.0f, 0.0f, 0.0f};
|
||||
}
|
||||
@@ -326,7 +327,7 @@ namespace Game
|
||||
Level& level = GetInstance().GameLevel;
|
||||
auto& staticCards = Puzzle::GetStaticPuzzleData().Cards;
|
||||
|
||||
for (int8_t y = 0; y < Data.WidthTiles / Puzzle::Config::CardSize; ++y)
|
||||
for (int8_t y = 0; y < Data.HeightTiles / Puzzle::Config::CardSize; ++y)
|
||||
{
|
||||
for (int8_t x = 0; x < Data.WidthTiles / Puzzle::Config::CardSize; ++x)
|
||||
{
|
||||
@@ -336,21 +337,24 @@ namespace Game
|
||||
|
||||
bool IsValid = Puzzle::IsValid(card.RefCard);
|
||||
tile.EData.Visible = true;
|
||||
quad.EData.Visible = IsValid;
|
||||
quad.EData.Visible = true;
|
||||
|
||||
// const Generated::StaticPuzzleCard& cData = Puzzle::GetCard(card.RefCard);
|
||||
tile.EData.ModelHandle =
|
||||
IsValid ? staticCards[card.RefCard.Idx].ModelHandle : staticCards[0].ModelHandle;
|
||||
tile.EData.Transform.SetPosition({
|
||||
tile.EData.ModelH = IsValid ? staticCards[card.RefCard.Idx].ModelHandle : staticCards[0].ModelHandle;
|
||||
Vec3 cardPos = {
|
||||
(float)card.Position.X * Puzzle::Config::CardScaleWorld,
|
||||
-5.0f,
|
||||
(float)card.Position.Y * Puzzle::Config::CardScaleWorld,
|
||||
});
|
||||
};
|
||||
if (!IsValid)
|
||||
{
|
||||
cardPos = {x * Puzzle::Config::CardScaleWorld, -5.0f, y * Puzzle::Config::CardScaleWorld};
|
||||
}
|
||||
tile.EData.Transform.SetPosition(cardPos);
|
||||
bx::mtxRotateY(tile.EData.Transform.Rotation.M, card.Rotation * bx::kPi * 0.5f);
|
||||
|
||||
Vec3 fw = {0, -1, 0};
|
||||
quad.EData.Transform.SetPosition({});
|
||||
quad.EData.Transform.Rotation = camTransform.Rotation;
|
||||
quad.EData.Transform.SetPosition(fw);
|
||||
quad.EData.Transform.Rotation = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Game
|
||||
Vec4 BaseColor{0.0f, 0.0f, 0.0f, 1.0f};
|
||||
Transform Transform;
|
||||
uint16_t MaterialHandle = UINT16_MAX;
|
||||
uint16_t ModelHandle = UINT16_MAX;
|
||||
Generated::ModelHandle ModelH;
|
||||
bool Visible = true;
|
||||
|
||||
void Render(const Model* models, const Material* materials);
|
||||
|
||||
@@ -133,6 +133,7 @@ namespace Game
|
||||
}
|
||||
LOG("Found %u models!", modelFilePathCount);
|
||||
|
||||
auto& inst = GetInstance();
|
||||
int32_t writeI = 0;
|
||||
for (int32_t i = 0; i < modelFilePathCount; ++i)
|
||||
{
|
||||
@@ -141,11 +142,11 @@ namespace Game
|
||||
Model& mod = models[writeI];
|
||||
if (LoadMesh(mod, fullPath.getCPtr(), modelFileIsBinary[i]))
|
||||
{
|
||||
mod.AssetHandle = CrcPath(fullPath.getCPtr());
|
||||
auto& inst = GetInstance();
|
||||
mod.Handle.Asset.Idx = CrcPath(fullPath.getCPtr());
|
||||
mod.Handle.ModelIdx = inst.DebugData.AssetCount;
|
||||
if (inst.DebugData.AssetCount < inst.DebugData.MaxAssets)
|
||||
{
|
||||
inst.DebugData.AssetHandles[inst.DebugData.AssetCount] = mod.AssetHandle;
|
||||
inst.DebugData.AssetHandles[inst.DebugData.AssetCount] = mod.Handle.Asset;
|
||||
bx::strCopy(inst.DebugData.AssetHandlePaths[inst.DebugData.AssetCount],
|
||||
sizeof(inst.DebugData.AssetHandlePaths[inst.DebugData.AssetCount]),
|
||||
fullPath.getCPtr());
|
||||
|
||||
@@ -588,33 +588,3 @@ namespace Puzzle
|
||||
return isVisible;
|
||||
}
|
||||
} // namespace Puzzle
|
||||
|
||||
namespace Generated
|
||||
{
|
||||
PuzPos operator+=(PuzPos lhs, const PuzPos& rhs)
|
||||
{
|
||||
lhs.X += rhs.X;
|
||||
lhs.Y += rhs.Y;
|
||||
return lhs;
|
||||
}
|
||||
PuzPos operator+(PuzPos lhs, const PuzPos& rhs)
|
||||
{
|
||||
PuzPos res = lhs;
|
||||
res.X += rhs.X;
|
||||
res.Y += rhs.Y;
|
||||
return res;
|
||||
}
|
||||
PuzPos operator-=(PuzPos lhs, const PuzPos& rhs)
|
||||
{
|
||||
lhs.X -= rhs.X;
|
||||
lhs.Y -= rhs.Y;
|
||||
return lhs;
|
||||
}
|
||||
PuzPos operator-(PuzPos lhs, const PuzPos& rhs)
|
||||
{
|
||||
PuzPos res = lhs;
|
||||
res.X += rhs.X;
|
||||
res.Y += rhs.Y;
|
||||
return res;
|
||||
}
|
||||
} // namespace Generated
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <cstdint>
|
||||
#include <imgui.h>
|
||||
|
||||
#include "../../gen/Generated.h"
|
||||
#include "Gen.h"
|
||||
|
||||
namespace Puzzle
|
||||
{
|
||||
@@ -50,9 +50,3 @@ namespace Puzzle
|
||||
};
|
||||
bool RenderDebugUI(PuzzleData& obj);
|
||||
} // namespace Puzzle
|
||||
|
||||
namespace Generated
|
||||
{
|
||||
PuzPos operator+=(PuzPos lhs, const PuzPos& rhs);
|
||||
PuzPos operator+(PuzPos lhs, const PuzPos& rhs);
|
||||
} // namespace Generated
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#include "Global.h"
|
||||
#include "Instance.h"
|
||||
#include "Tools.h"
|
||||
#include "bx/string.h"
|
||||
#include "rendering/Rendering.h"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace Tools
|
||||
{
|
||||
const char* GetAssetPath(uint32_t assetHandle)
|
||||
const char* GetAssetPath(Generated::AssetHandle assetHandle)
|
||||
{
|
||||
const auto& inst = Game::GetInstance();
|
||||
for (int32_t j = 0; j < inst.DebugData.AssetCount; ++j)
|
||||
@@ -21,26 +20,17 @@ namespace Tools
|
||||
return "---";
|
||||
}
|
||||
|
||||
void ModelDropdown(uint32_t& modelHandle)
|
||||
void ModelDropdown(Generated::ModelHandle& modelHandle)
|
||||
{
|
||||
auto& R = Game::GameRendering::Get();
|
||||
const char* name = GetAssetPath(modelHandle);
|
||||
int32_t idx = -1;
|
||||
for (int32_t i = 0; i < R.ModelCount; ++i)
|
||||
{
|
||||
if (R.Models[i].AssetHandle == modelHandle)
|
||||
{
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const char* name = GetAssetPath(modelHandle.Asset);
|
||||
if (ImGui::BeginCombo("Models", name))
|
||||
{
|
||||
for (int32_t i = 0; i < R.ModelCount; ++i)
|
||||
{
|
||||
if (ImGui::Selectable(GetAssetPath(R.Models[i].AssetHandle), i == idx))
|
||||
if (ImGui::Selectable(GetAssetPath(R.Models[i].Handle.Asset), i == modelHandle.ModelIdx))
|
||||
{
|
||||
modelHandle = i;
|
||||
modelHandle = R.Models[i].Handle;
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include "Gen.h"
|
||||
|
||||
namespace Tools
|
||||
{
|
||||
void ModelDropdown(uint32_t& modelHandle);
|
||||
void ModelDropdown(Generated::ModelHandle& modelHandle);
|
||||
} // namespace Tools
|
||||
|
||||
BIN
src/game/data/puzzles/0.pzl
LFS
BIN
src/game/data/puzzles/0.pzl
LFS
Binary file not shown.
Binary file not shown.
@@ -38,6 +38,17 @@ type Mat4
|
||||
}")
|
||||
}
|
||||
|
||||
type AssetHandle
|
||||
{
|
||||
u32 Idx Default("UINT32_MAX")
|
||||
}
|
||||
|
||||
type ModelHandle
|
||||
{
|
||||
u16 ModelIdx Default("UINT16_MAX")
|
||||
AssetHandle Asset
|
||||
}
|
||||
|
||||
type PuzPos
|
||||
{
|
||||
i8 X
|
||||
@@ -59,7 +70,8 @@ enum PuzzleElementType(u8)
|
||||
type StaticPuzzleCard
|
||||
{
|
||||
PuzzleElementType Elements Arr(4)
|
||||
u32 ModelHandle
|
||||
ModelHandle ModelHandle
|
||||
|
||||
}
|
||||
|
||||
type StaticPuzzleCardHandle
|
||||
|
||||
@@ -731,17 +731,17 @@ namespace Game
|
||||
return mat;
|
||||
}
|
||||
|
||||
uint16_t GameRendering::GetModelHandleFromPath(const char* path)
|
||||
Generated::ModelHandle GameRendering::GetModelHandleFromPath(const char* path)
|
||||
{
|
||||
uint32_t AssetHandle = CrcPath(path);
|
||||
for (int32_t i = 0; i < ModelCount; ++i)
|
||||
{
|
||||
if (Models[i].AssetHandle == AssetHandle)
|
||||
if (Models[i].Handle.Asset.Idx == AssetHandle)
|
||||
{
|
||||
return i;
|
||||
return Models[i].Handle;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace Game
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
#include "bgfx/defines.h"
|
||||
#include "imgui.h"
|
||||
#include <bgfx/bgfx.h>
|
||||
#include <bx/string.h>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../Gen.h"
|
||||
#include "../Global.h"
|
||||
#include "imgui.h"
|
||||
|
||||
union SDL_Event;
|
||||
|
||||
@@ -36,7 +37,7 @@ namespace Game
|
||||
bgfx::VertexBufferHandle VertexBuffer;
|
||||
bgfx::IndexBufferHandle IndexBuffer;
|
||||
bgfx::VertexLayout VertLayout;
|
||||
uint32_t AssetHandle = UINT16_MAX;
|
||||
Generated::ModelHandle Handle;
|
||||
};
|
||||
|
||||
struct Material
|
||||
@@ -118,6 +119,6 @@ namespace Game
|
||||
void HandleEvents();
|
||||
void RenderDebugUI();
|
||||
void Shutdown();
|
||||
uint16_t GetModelHandleFromPath(const char* path);
|
||||
Generated::ModelHandle GetModelHandleFromPath(const char* path);
|
||||
};
|
||||
} // namespace Game
|
||||
|
||||
Reference in New Issue
Block a user