general improvements

This commit is contained in:
Asuro
2025-02-14 02:44:40 +01:00
parent 6e82678ade
commit ab326d3624
16 changed files with 185 additions and 80 deletions

View File

@@ -1,8 +1,11 @@
#include "Global.h"
#include "Input.h"
#include "Instance.h"
#include "Level.h"
#include "Log.h"
#include "bgfx/bgfx.h"
#include <bx/math.h>
#include <cstdint>
namespace
{
@@ -10,10 +13,34 @@ namespace
namespace Game
{
void EntityRenderData::Render(const Model* models, const Material* materials)
{
if (ModelHandle == UINT16_MAX || MaterialHandle == UINT16_MAX) return;
Transform.UpdateMatrix();
bgfx::setTransform(Transform.M.M);
const Model& currentModel = models[ModelHandle];
const Material& currentMaterial = materials[MaterialHandle];
bgfx::setVertexBuffer(0, currentModel.VertexBuffer);
bgfx::setIndexBuffer(currentModel.IndexBuffer);
bgfx::setState(currentMaterial.State);
float TimeValues[4]{0.0f};
TimeValues[0] = GetInstance().Now;
bgfx::setUniform(currentMaterial.Uniforms[Material::UTime], TimeValues);
bgfx::setUniform(currentMaterial.Uniforms[Material::UDotColor], TestColor);
bgfx::submit(0, currentMaterial.Shader);
}
void Level::Setup(GameData& data)
{
Log("Level setup");
Cubes.Setup(data.EntityStorage);
void* storagePtr = data.EntityStorage;
bool needReset = false;
needReset |= Cubes.Setup(storagePtr, needReset);
needReset |= Tests.Setup(storagePtr, needReset);
if (Cubes.Count == 0)
{
for (uint32_t yy = 0; yy < 11; ++yy)
@@ -31,15 +58,29 @@ namespace Game
Cube* floor = Cubes.New();
}
if (Tests.Count == 0)
{
Tests.New();
}
}
void Level::Update()
{
if (GetKey(ScanCode::R))
{
Cubes.Count = 0;
Tests.Count = 0;
Setup(GetShared().Game);
}
Cubes.Update();
Tests.Update();
}
void Cube::Setup()
{
EData.MaterialHandle = 0;
EData.ModelHandle = 0;
}
void Cube::Update()
@@ -48,26 +89,32 @@ namespace Game
{
double globalTime = GetInstance().Now;
double time = TestY <= 5 ? globalTime * 1.0f : 0.0f;
if (TestX == 4 && TestY == 4)
{
// bx::mtxTranslate(Transform.M, 0, 0, bx::lerp(-20.0f, -32.0f, bx::sin(globalTime* 0.5f) * 0.5 + 0.5));
// bx::mtxTranslate(Transform.M, 0, 0, bx::lerp(0.0f, -32.0f, bx::sin(globalTime* 0.5f) * 0.5 + 0.5));
}
else
{
float scale = 1.0f + TestX * 0.4f;
Transform::CreateTransform(
Transform.M.M,
bx::Vec3{TestX * 10.0f - 40.0f, TestY * 10.0f - 40.0f, (float)TestX},
bx::fromEuler(
{static_cast<float>(time * 10.0f + TestX), static_cast<float>(time * 5.0f * TestY), 0.0f}),
{scale, scale, scale});
}
float scale = 1.0f + TestX * 0.4f;
EData.Transform.Position = bx::Vec3{TestX * 2.0f, TestY * 2.0f, 0.0f};
EData.Transform.Scale = {scale, scale, scale};
}
else
{
Transform::CreateTransform(
Transform.M.M, {0.0f, -30.0f, 100.0f}, bx::Quaternion(0.0f, 0.0f, 0.0f, 1.0f), {100.0f, 10.0f, 100.0f});
EData.Transform.Position = {0.0f, -1.0f, 0.0f};
EData.Transform.Scale = {100.0f, 1.0f, 100.0f};
EData.TestColor[0] = 0.3f;
EData.TestColor[1] = 0.4f;
EData.TestColor[2] = 0.8f;
}
}
void TestEntity::Setup()
{
EData.MaterialHandle = 0;
EData.ModelHandle = 1;
EData.Transform.Position = {0.0f, 0.0f, 10.0f};
}
void TestEntity::Update()
{
EData.TestColor[0] = 0.6f;
EData.TestColor[1] = 0.9f;
EData.TestColor[2] = 0.5f;
}
} // namespace Game