This commit is contained in:
Asuro
2025-02-21 22:44:57 +01:00
parent edde743542
commit 833d78c142
8 changed files with 118 additions and 44 deletions

View File

@@ -3,14 +3,13 @@
#include "Instance.h"
#include "Level.h"
#include "Log.h"
#include "SDL3/SDL_mouse.h"
#include "bgfx/bgfx.h"
#include "imgui.h"
#include <SDL3/SDL.h>
#include <bx/math.h>
#include <cstdint>
namespace
{
}
namespace Game
{
void EntityRenderData::Render(const Model* models, const Material* materials)
@@ -35,6 +34,17 @@ namespace Game
bgfx::submit(currentMaterial.ViewID, currentMaterial.Shader);
}
namespace
{
void UpdatePlayerInputMode()
{
bool IsGaming = GetInstance().Player.InputM == InputMode::Game;
SDL_SetWindowRelativeMouseMode(GetShared().Window.SDLWindow, IsGaming);
auto& IO = ImGui::GetIO();
IO.ConfigFlags = FlagBool(IO.ConfigFlags, ImGuiConfigFlags_NoMouse | ImGuiConfigFlags_NoKeyboard, IsGaming);
}
} // namespace
void Level::Setup(GameData& data)
{
Log("Level setup");
@@ -63,6 +73,8 @@ namespace Game
{
Tests.New();
}
UpdatePlayerInputMode();
}
void Level::Update()
@@ -85,10 +97,23 @@ namespace Game
if (GetKeyPressedNow(ScanCode::F1))
{
player.Mode = player.Mode == PlayerMode::Walk ? PlayerMode::Freefly : PlayerMode::Walk;
player.CameraM = player.CameraM == CameraMode::Walk ? CameraMode::Freefly : CameraMode::Walk;
}
if (player.Mode == PlayerMode::Freefly)
if (GetKeyPressedNow(ScanCode::F2))
{
if (player.InputM == InputMode::Game)
{
player.InputM = InputMode::UI;
}
else
{
player.InputM = InputMode::Game;
}
UpdatePlayerInputMode();
}
if (player.CameraM == CameraMode::Freefly)
{
if (GetMouseButton(MouseButton::Left))
{
@@ -101,7 +126,7 @@ namespace Game
player.FreeflyCamTransform.TranslateLocal({0.0f, 0.0f, -inputVec.z});
player.FreeflyCamTransform.TranslateLocal({-inputVec.x, 0.0f, 0.0f});
}
else if (player.Mode == PlayerMode::Walk)
else if (player.CameraM == CameraMode::Walk)
{
player.PlayerCamTransform.TranslateLocal({0.0f, 0.0f, -inputVec.z});
player.PlayerCamTransform.TranslateLocal({-inputVec.x, 0.0f, 0.0f});
@@ -118,6 +143,34 @@ namespace Game
END_PERF(GetShared().Window.PerfCounters, PerfCounterType::GameLevelUpdate, GetShared().Window.FrameCounter);
}
void Level::Render(uint16_t viewId, const Model* models, const Material* materials)
{
auto& shared = GetShared();
float proj[16];
bx::mtxProj(proj,
75.0f,
float(shared.Window.WindowWidth) / float(shared.Window.WindowHeight),
0.1f,
1000.0f,
bgfx::getCaps()->homogeneousDepth);
auto& player = GetInstance().Player;
if (player.CameraM == CameraMode::Freefly)
{
player.FreeflyCamTransform.UpdateMatrix();
bgfx::setViewTransform(viewId, player.FreeflyCamTransform.M.M, proj);
}
else
{
player.PlayerCamTransform.UpdateMatrix();
bgfx::setViewTransform(viewId, player.PlayerCamTransform.M.M, proj);
}
Cubes.Render(models, materials);
Tests.Render(models, materials);
}
void Cube::Setup()
{
EData.MaterialHandle = 0;
@@ -155,7 +208,5 @@ namespace Game
void TestEntity::Update()
{
EData.TestColor[0] = 0.0f;
// EData.TestColor[1] = 0.9f;
// EData.TestColor[2] = 0.5f;
}
} // namespace Game