minidef
This commit is contained in:
@@ -38,6 +38,13 @@ namespace Game
|
||||
InputMode InputM = InputMode::Game;
|
||||
};
|
||||
|
||||
struct InstanceDebugData
|
||||
{
|
||||
uint16_t SelectedDebugLevel = UINT16_MAX;
|
||||
uint64_t ImguiIniSize = 0;
|
||||
char ImguiIni[4096]{0};
|
||||
};
|
||||
|
||||
struct GameInstance
|
||||
{
|
||||
bool IsInitialized = false;
|
||||
@@ -46,7 +53,6 @@ namespace Game
|
||||
Time Time;
|
||||
PlayerData Player;
|
||||
Level GameLevel;
|
||||
uint64_t ImguiIniSize = 0;
|
||||
char ImguiIni[4096]{0};
|
||||
InstanceDebugData DebugData;
|
||||
};
|
||||
} // namespace Game
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace Game
|
||||
|
||||
// Cubes.Render(models, materials);
|
||||
Tests.Render(models, materials);
|
||||
// PuzzleTiles.Render(models, materials);
|
||||
PuzzleTiles.Render(models, materials);
|
||||
UIQuads.Render(models, materials);
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ namespace Game
|
||||
|
||||
UIQuadEntity& quad = level.UIQuads.Get(UIPlacedCards[cardI]);
|
||||
quad.EData.MaterialHandle = 0;
|
||||
quad.EData.ModelHandle = GameRendering::Get().GetModelHandleFromPath("models/cube.glb");
|
||||
quad.EData.ModelHandle = GameRendering::Get().GetModelHandleFromPath("models/plane.glb");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "Log.h"
|
||||
#include "Puzzle.h"
|
||||
#include "bx/string.h"
|
||||
#include "imgui.h"
|
||||
#include "rendering/Rendering.h"
|
||||
|
||||
#include "bx/bx.h"
|
||||
@@ -154,4 +156,47 @@ namespace Puzzle
|
||||
return (sourceType == PuzzleElementType::WaterIn && goalType == PuzzleElementType::WaterGoal) ||
|
||||
(sourceType == PuzzleElementType::ElectricIn && goalType == PuzzleElementType::ElectricGoal);
|
||||
}
|
||||
|
||||
bool PuzzleData::RenderDebugUI()
|
||||
{
|
||||
bool dataChanged = false;
|
||||
|
||||
bool isVisible = true;
|
||||
if (ImGui::Begin("Puzzle", &isVisible))
|
||||
{
|
||||
ImGui::Text("%s", PuzzleName);
|
||||
|
||||
int32_t W = S.WidthTiles;
|
||||
int32_t H = S.HeightTiles;
|
||||
ImGui::PushID("width");
|
||||
ImGui::SetNextItemWidth(40);
|
||||
if (ImGui::DragInt("", &W, 0.3f, 0, Config::MaxPuzzleSizeTiles))
|
||||
{
|
||||
S.WidthTiles = uint8_t(W);
|
||||
dataChanged = true;
|
||||
}
|
||||
ImGui::PopID();
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("x");
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(40);
|
||||
ImGui::PushID("height");
|
||||
if (ImGui::DragInt("", &H, 0.3f, 0, Config::MaxPuzzleSizeTiles))
|
||||
{
|
||||
S.HeightTiles = uint8_t(H);
|
||||
dataChanged = true;
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
if (dataChanged)
|
||||
{
|
||||
char path[128]{0};
|
||||
bx::snprintf(path, sizeof(path), "game/data/%s.pzl", PuzzleName);
|
||||
SerializeStruct(&S, sizeof(S), path);
|
||||
}
|
||||
|
||||
return isVisible;
|
||||
}
|
||||
} // namespace Puzzle
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
#include "Serial.h"
|
||||
#include <cstdint>
|
||||
|
||||
#include "../../gen/Generated.h"
|
||||
|
||||
namespace Puzzle
|
||||
{
|
||||
struct Config
|
||||
@@ -104,6 +107,9 @@ namespace Puzzle
|
||||
|
||||
struct PuzzleData
|
||||
{
|
||||
SER_HEADER(1, "PZZL");
|
||||
Generated::PuzzleData S;
|
||||
|
||||
uint32_t AvailableCardCount = 0;
|
||||
PuzzleCardStack AvailableCards[Config::MaxAvailableStacks];
|
||||
uint32_t PlacedCardCount = 0;
|
||||
@@ -117,6 +123,9 @@ namespace Puzzle
|
||||
|
||||
const PuzzleNode& GetNodeAt(PuzPos pos) const;
|
||||
PuzzleElementType GetElementAt(ElemPos pos) const;
|
||||
|
||||
char PuzzleName[32]{"Unnamed"};
|
||||
bool RenderDebugUI();
|
||||
};
|
||||
|
||||
struct PuzzleSolver
|
||||
|
||||
32
src/game/Serial.cpp
Normal file
32
src/game/Serial.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "Global.h"
|
||||
#include "Log.h"
|
||||
#include "Serial.h"
|
||||
#include "bx/bx.h"
|
||||
#include "bx/file.h"
|
||||
#include "bx/filepath.h"
|
||||
|
||||
void SerializeStruct(void* data, uint64_t size, const char* path)
|
||||
{
|
||||
bx::Error err;
|
||||
bx::FilePath filePath{path};
|
||||
bx::FileWriter writer;
|
||||
if (writer.open(filePath, false, &err))
|
||||
{
|
||||
if (!writer.write(data, size, &err))
|
||||
{
|
||||
LOG_ERROR("Failed to write to file %s: %s", path, err.getMessage().getCPtr());
|
||||
writer.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Failed to open file %s: %s", path, err.getMessage().getCPtr());
|
||||
return;
|
||||
}
|
||||
LOG("Successful serialization");
|
||||
}
|
||||
|
||||
void DeserializeStruct(void* data, SerializationHeader& expectedHeader, const char* path)
|
||||
{
|
||||
}
|
||||
32
src/game/Serial.h
Normal file
32
src/game/Serial.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <cstdint>
|
||||
|
||||
struct SerializationHeader
|
||||
{
|
||||
uint8_t _ID0 = 0;
|
||||
uint8_t _ID1 = 0;
|
||||
uint8_t _ID2 = 0;
|
||||
uint8_t _ID3 = 0;
|
||||
uint8_t HeaderVersion = 0;
|
||||
uint8_t VersionNum = 0;
|
||||
uint8_t Reserved0 = 0;
|
||||
uint8_t Reserved1 = 0;
|
||||
};
|
||||
|
||||
#define SER_HEADER(Version, FCC) \
|
||||
SerializationHeader __Header{ \
|
||||
FCC[0], \
|
||||
FCC[1], \
|
||||
FCC[2], \
|
||||
FCC[3], \
|
||||
1, \
|
||||
Version, \
|
||||
0, \
|
||||
0, \
|
||||
}; \
|
||||
bool VersionMatches(uint8_t headerVersion, uint8_t versionNum) \
|
||||
{ \
|
||||
return headerVersion == 1 && versionNum == Version; \
|
||||
}
|
||||
|
||||
void SerializeStruct(void* data, uint64_t size, const char* path);
|
||||
void DeserializeStruct(void* data, SerializationHeader& expectedHeader, const char* path);
|
||||
8
src/game/mini.def
Normal file
8
src/game/mini.def
Normal file
@@ -0,0 +1,8 @@
|
||||
type PuzzleData
|
||||
{
|
||||
u8 WidthTiles
|
||||
u8 HeightTiles
|
||||
u32 AvailableCardCount
|
||||
u32 PlacedCardCount
|
||||
u32 GoalPositionCount
|
||||
}
|
||||
@@ -390,9 +390,9 @@ namespace Game
|
||||
inst.Time.StartTime = bx::getHPCounter();
|
||||
}
|
||||
|
||||
if (inst.ImguiIniSize > 0)
|
||||
if (inst.DebugData.ImguiIniSize > 0)
|
||||
{
|
||||
ImGui::LoadIniSettingsFromMemory(inst.ImguiIni, inst.ImguiIniSize);
|
||||
ImGui::LoadIniSettingsFromMemory(inst.DebugData.ImguiIni, inst.DebugData.ImguiIniSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -453,6 +453,8 @@ namespace Game
|
||||
ImGui_ImplSDL3_NewFrame();
|
||||
ImGui::DockSpaceOverViewport(0, 0, ImGuiDockNodeFlags_PassthruCentralNode);
|
||||
|
||||
auto& level = GetInstance().GameLevel;
|
||||
auto& debug = GetInstance().DebugData;
|
||||
if (UIVisible == UIVisibilityState::Debug)
|
||||
{
|
||||
if (ImGui::Begin("Rendering"))
|
||||
@@ -500,12 +502,39 @@ namespace Game
|
||||
{
|
||||
ImGui::Image(DitherTextures.RampTex.idx, {BX_COUNTOF(DitherTextures.BrightnessRamp), 8});
|
||||
}
|
||||
Vec3 quadPos = GetInstance().GameLevel.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("Shader log:");
|
||||
ImGui::TextWrapped("%s", GetShared().Dev.ShaderLog);
|
||||
}
|
||||
ImGui::End();
|
||||
if (ImGui::Begin("Puzzles"))
|
||||
{
|
||||
ImGui::Text("List");
|
||||
for (int32_t i = 0; i < BX_COUNTOF(level.Puzzles); ++i)
|
||||
{
|
||||
auto& puzzleData = level.Puzzles[i].Data;
|
||||
bool isSelected = debug.SelectedDebugLevel == i;
|
||||
ImGui::PushID("selectable");
|
||||
if (ImGui::Selectable(puzzleData.PuzzleName, isSelected))
|
||||
{
|
||||
debug.SelectedDebugLevel = isSelected ? UINT16_MAX : i;
|
||||
}
|
||||
ImGui::PopID();
|
||||
if (isSelected)
|
||||
{
|
||||
ImGui::PushID("edit field");
|
||||
ImGui::InputText("", puzzleData.PuzzleName, sizeof(Puzzle::PuzzleData::PuzzleName));
|
||||
ImGui::PopID();
|
||||
|
||||
if (!puzzleData.RenderDebugUI())
|
||||
{
|
||||
debug.SelectedDebugLevel = UINT16_MAX;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
GetInstance().GameLevel.Update();
|
||||
@@ -536,10 +565,10 @@ namespace Game
|
||||
{
|
||||
LOG("--- RENDERING_SHUTDOWN ---");
|
||||
ImGui::SaveIniSettingsToDisk("imgui.ini");
|
||||
const char* iniData = ImGui::SaveIniSettingsToMemory(reinterpret_cast<uint64_t*>(&GetInstance().ImguiIniSize));
|
||||
assert(GetInstance().ImguiIniSize <= BX_COUNTOF(GameInstance::ImguiIni));
|
||||
bx::memCopy(
|
||||
GetInstance().ImguiIni, iniData, bx::min(GetInstance().ImguiIniSize, BX_COUNTOF(GameInstance::ImguiIni)));
|
||||
auto& debug = GetInstance().DebugData;
|
||||
const char* iniData = ImGui::SaveIniSettingsToMemory(reinterpret_cast<uint64_t*>(&debug.ImguiIniSize));
|
||||
assert(debug.ImguiIniSize <= BX_COUNTOF(InstanceDebugData::ImguiIni));
|
||||
bx::memCopy(debug.ImguiIni, iniData, bx::min(debug.ImguiIniSize, BX_COUNTOF(InstanceDebugData::ImguiIni)));
|
||||
ImGui_ImplSDL3_Shutdown();
|
||||
imguiDestroy();
|
||||
bgfx::shutdown();
|
||||
|
||||
Reference in New Issue
Block a user