more stuff

This commit is contained in:
Asuro
2025-02-24 05:29:24 +01:00
parent 369b994755
commit d3dcec1458
6 changed files with 156 additions and 6 deletions

View File

@@ -3,6 +3,7 @@
#include "Instance.h"
#include "Level.h"
#include "Log.h"
#include "Puzzle.h"
#include "SDL3/SDL_mouse.h"
#include "bgfx/bgfx.h"
#include "imgui.h"
@@ -15,6 +16,7 @@ namespace Game
void EntityRenderData::Render(const Model* models, const Material* materials)
{
if (ModelHandle == UINT16_MAX || MaterialHandle == UINT16_MAX) return;
if (!Visible) return;
Transform.UpdateMatrix();
bgfx::setTransform(Transform.M.M);
@@ -52,6 +54,10 @@ namespace Game
bool needReset = false;
needReset |= Cubes.Setup(storagePtr, needReset);
needReset |= Tests.Setup(storagePtr, needReset);
needReset |= PuzzleTiles.Setup(storagePtr, needReset);
PuzzleData.Setup();
if (Cubes.Count == 0)
{
for (uint32_t yy = 0; yy < 11; ++yy)
@@ -63,6 +69,7 @@ namespace Game
{
c->TestX = xx;
c->TestY = yy;
c->Setup();
}
}
}
@@ -70,7 +77,14 @@ namespace Game
}
if (Tests.Count == 0)
{
Tests.New();
Tests.Get(Tests.New())->Setup();
}
if (PuzzleTiles.Count == 0)
{
for (uint32_t puzI = 0; puzI < BX_COUNTOF(Puzzles); ++puzI)
{
Puzzles[puzI].Setup();
}
}
UpdatePlayerInputMode();
@@ -81,6 +95,7 @@ namespace Game
START_PERF();
PlayerData& player = GetInstance().Player;
// Input
float delta = GetInstance().Time.Delta;
delta = 1.0f / 144.0f;
constexpr float moveSpeed = 10.0f;
@@ -137,10 +152,18 @@ namespace Game
player.PlayerCamTransform.RotateLocal({player.WalkXRot, 0.0f, 0.0f});
}
// Cubes
for (uint16_t i = 0; i < Cubes.Count; ++i)
{
Cubes.Get({i})->Update();
}
// Puzzle tiles
for (int32_t i = 0; i < BX_COUNTOF(Puzzles); ++i)
{
Puzzles[i].Update();
}
END_PERF(GetShared().Window.PerfCounters, PerfCounterType::GameLevelUpdate, GetShared().Window.FrameCounter);
}
@@ -161,15 +184,18 @@ namespace Game
{
player.FreeflyCamTransform.UpdateMatrix();
bgfx::setViewTransform(viewId, player.FreeflyCamTransform.M.M, proj);
bgfx::dbgTextPrintf(1, 0, 0b1100, "NOCLIP");
}
else
{
player.PlayerCamTransform.UpdateMatrix();
bgfx::setViewTransform(viewId, player.PlayerCamTransform.M.M, proj);
bgfx::dbgTextPrintf(1, 0, 0b1100, " ");
}
Cubes.Render(models, materials);
// Cubes.Render(models, materials);
Tests.Render(models, materials);
PuzzleTiles.Render(models, materials);
}
void Cube::Setup()
@@ -206,4 +232,40 @@ namespace Game
EData.Transform.Position = {0.0f, 0.0f, 10.0f};
EData.TestColor[0] = 0.0f;
}
void WorldPuzzle::Setup()
{
Data.PlacedCardCount = 16;
for (int32_t i = 0; i < 16; ++i)
{
Data.PlacedCards[i].RefCard = {0};
Data.PlacedCards[i].Position = {int8_t(i % 4), int8_t(i / 4)};
}
for (uint32_t cardI = 0; cardI < Data.PlacedCardCount; ++cardI)
{
const Puzzle::PlacedPuzzleCard& card = Data.PlacedCards[cardI];
auto& tiles = GetInstance().GameLevel.PuzzleTiles;
TileHandles[cardI] = tiles.New();
bx::Vec3 Pos = {
WorldPosition.x + card.Position.X * WorldCardSize.x,
WorldPosition.y,
WorldPosition.z + card.Position.Y * WorldCardSize.y,
};
auto& tile = *tiles.Get(TileHandles[cardI]);
tile.EData.Transform.Position = Pos;
tile.EData.MaterialHandle = 0;
}
}
void WorldPuzzle::Update()
{
for (int32_t cardI = 0; cardI < Data.PlacedCardCount; ++cardI)
{
Puzzle::PlacedPuzzleCard& card = Data.PlacedCards[cardI];
if (!card.RefCard.IsValid()) continue;
const Puzzle::StaticPuzzleCard& cData = Puzzle::StaticPuzzleData::Get().GetCard(card.RefCard);
GetInstance().GameLevel.PuzzleTiles.Get(TileHandles[cardI])->EData.ModelHandle = cData.ModelHandle;
}
}
} // namespace Game