Added stress test code for 20000 objects

This commit is contained in:
Kah Wei 2022-09-23 18:49:04 +08:00
parent f8391d6c9e
commit bb38246111
6 changed files with 57 additions and 31 deletions

View File

@ -38,26 +38,49 @@ namespace Sandbox
// Create Materials
auto matInst = graphicsSystem->AddMaterialInstance();
// Create entity and add mesh
testObj = SHADE::SHEntityManager::CreateEntity<SHADE::SHRenderable, SHADE::SHTransformComponent>();
auto& renderable = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHRenderable>(testObj);
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
// Create Stress Test Objects
static const SHVec3 TEST_OBJ_SCALE = { 0.2f, 0.2f, 0.2f };
constexpr int NUM_ROWS = 200;
constexpr int NUM_COLS = 100;
static const SHVec3 TEST_OBJ_SPACING = { 1.0f, 1.0f, 1.0f };
static const SHVec3 TEST_OBJ_START_POS = { - (NUM_COLS / 2 * TEST_OBJ_SPACING.x ), 0.0f, 0.0f };
for (int z = 0; z < NUM_ROWS; ++z)
for (int x = 0; x < NUM_COLS; ++x)
{
auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity);
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
renderable.Mesh = CUBE_MESH;
renderable.SetMaterial(matInst);
renderable.Mesh = CUBE_MESH;
renderable.SetMaterial(matInst);
// Set initial positions
transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{ x * TEST_OBJ_SPACING.x, 0.0f, z * TEST_OBJ_SPACING.z });
//transform.SetLocalScale(TEST_OBJ_SCALE);
stressTestObjects.emplace_back(entity);
}
// Create blank entity with a script
testObj = SHADE::SHEntityManager::CreateEntity();
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
scriptEngine->AddScript(testObj, "TestScript");
}
void SBTestScene::Update(float dt)
{
static float rotation = 0.0f;
/*static float rotation = 0.0f;
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
transform.SetLocalRotation(rotation, 0.0f, 0.0f);
rotation += dt * 10.0f;
transform.SetLocalRotation(rotation, 0.0f, 0.0f);
rotation += dt * 10.0f;*/
/*static float rotation = 0.0f;
auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(stressTestObjects[0]);
transform.SetWorldPosition({rotation, 0.0f, 0.0f});
rotation += dt * 10.0f;*/
// Destroy entity if space is pressed
if (GetKeyState(VK_SPACE) & 0x8000)

View File

@ -10,6 +10,7 @@ namespace Sandbox
private:
EntityID camera;
EntityID testObj;
std::vector<EntityID> stressTestObjects;
public:
virtual void Load();

View File

@ -117,7 +117,7 @@ namespace SHADE
for (const SHRenderable* renderable : subBatch.Renderables)
{
// Transform
auto transform = SHComponentManager::GetComponent_s<SHTransformComponent>(renderable->GetEID());
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(renderable->GetEID());
if (!transform)
{
SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!");
@ -211,6 +211,7 @@ namespace SHADE
{
transformData.emplace_back(transform->GetTRS());
}
// Material Properties
if (!EMPTY_MAT_PROPS)
{

View File

@ -79,7 +79,7 @@ namespace SHADE
}
void SHSuperBatch::UpdateTransformBuffer(uint32_t frameIndex)
{
{
for (auto& batch : batches)
{
batch.UpdateTransformBuffer(frameIndex);

View File

@ -22,24 +22,24 @@ namespace SHADE
void SHCamera::SetLookAt(const SHVec3& pos, const SHVec3& target, const SHVec3& up)
{
SHVec3 view = target - pos; view = SHVec3::Normalise(view);
SHVec3 right = SHVec3::Cross(view, up); right = SHVec3::Normalise(right);
const SHVec3 UP = SHVec3::Cross(right, view);
viewMatrix = SHMatrix::Identity;
viewMatrix(0, 0) = UP[0];
viewMatrix(1, 0) = UP[1];
viewMatrix(2, 0) = UP[2];
viewMatrix(0, 1) = right[0];
viewMatrix(1, 1) = right[1];
viewMatrix(2, 1) = right[2];
viewMatrix(0, 2) = view[0];
viewMatrix(1, 2) = view[1];
viewMatrix(2, 2) = view[2];
viewMatrix(3, 0) = -UP.Dot(pos);
viewMatrix(3, 1) = -right.Dot(pos);
viewMatrix(3, 2) = -view.Dot(pos);
isDirty = true;
SHVec3 right = SHVec3::Cross(view, up); right = SHVec3::Normalise(right);
const SHVec3 UP = SHVec3::Cross(right, view);
viewMatrix = SHMatrix::Identity;
viewMatrix(0, 0) = UP[0];
viewMatrix(1, 0) = UP[1];
viewMatrix(2, 0) = UP[2];
viewMatrix(0, 1) = right[0];
viewMatrix(1, 1) = right[1];
viewMatrix(2, 1) = right[2];
viewMatrix(0, 2) = view[0];
viewMatrix(1, 2) = view[1];
viewMatrix(2, 2) = view[2];
viewMatrix(3, 0) = -UP.Dot(pos);
viewMatrix(3, 1) = -right.Dot(pos);
viewMatrix(3, 2) = -view.Dot(pos);
isDirty = true;
}
/*---------------------------------------------------------------------------------*/

View File

@ -114,7 +114,8 @@ namespace SHADE
screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f));
screenCamera->SetOrthographic(static_cast<float>(windowDims.first), static_cast<float>(windowDims.second), 0.01f, 100.0f);
worldCamera = resourceManager.Create<SHCamera>();
worldCamera->SetLookAt(SHVec3(1.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 2.0f), SHVec3(0.0f, 1.0f, 0.0f));
//worldCamera->SetLookAt(SHVec3(1.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 2.0f), SHVec3(0.0f, 1.0f, 0.0f));
worldCamera->SetLookAt(SHVec3(0.0f, 5.0f, -1.0f), SHVec3(0.0f, 0.0f, 2.0f), SHVec3(0.0f, 1.0f, 0.0f));
worldCamera->SetPerspective(90.0f, static_cast<float>(windowDims.first), static_cast<float>(windowDims.second), 0.0f, 100.0f);
// Create Default Viewport