aboutsummaryrefslogtreecommitdiff
path: root/src/test/Profiling.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/Profiling.cpp')
-rw-r--r--src/test/Profiling.cpp111
1 files changed, 62 insertions, 49 deletions
diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp
index 16736b8..d8bd09d 100644
--- a/src/test/Profiling.cpp
+++ b/src/test/Profiling.cpp
@@ -32,14 +32,15 @@ using namespace testing;
class TestScript : public Script {
bool oncollision(const CollisionEvent & test) {
- Log::logf("Box {} script on_collision()", test.info.this_collider.game_object_id);
+ Log::logf("Box {} script on_collision()", test.info.self.transform.game_object_id);
return true;
}
void init() {
- subscribe<CollisionEvent>(
- [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); });
+ subscribe<CollisionEvent>([this](const CollisionEvent & ev) -> bool {
+ return this->oncollision(ev);
+ });
}
- void update() {
+ void fixed_update() {
// Retrieve component from the same GameObject this script is on
}
};
@@ -50,22 +51,24 @@ public:
// Minimum amount to let test pass
const int min_gameobject_count = 100;
// Maximum amount to stop test
- const int max_gameobject_count = 150;
+ const int max_gameobject_count = 3000;
// Amount of times a test runs to calculate average
const int average = 5;
// Maximum duration to stop test
const std::chrono::microseconds duration = 16000us;
Mediator m;
- SDLContext sdl_context{m};
- ResourceManager resman{m};
- ComponentManager mgr{m};
+ SDLContext sdl_context {m};
+ ResourceManager resman {m};
+ ComponentManager mgr {m};
// Add system used for profling tests
- CollisionSystem collision_sys{m};
- PhysicsSystem physics_sys{m};
- ParticleSystem particle_sys{m};
- RenderSystem render_sys{m};
- ScriptSystem script_sys{m};
+ EventManager evmgr {m};
+ LoopTimerManager loopmgr {m};
+ CollisionSystem collision_sys {m};
+ PhysicsSystem physics_sys {m};
+ ParticleSystem particle_sys {m};
+ RenderSystem render_sys {m};
+ ScriptSystem script_sys {m};
// Test data
std::map<std::string, std::chrono::microseconds> timings;
@@ -75,16 +78,18 @@ public:
void SetUp() override {
GameObject do_not_use = mgr.new_object("DO_NOT_USE", "", {0, 0});
- do_not_use.add_component<Camera>(ivec2{1080, 720}, vec2{2000, 2000},
- Camera::Data{
- .bg_color = Color::WHITE,
- .zoom = 1.0f,
- });
+ do_not_use.add_component<Camera>(
+ ivec2 {1080, 720}, vec2 {2000, 2000},
+ Camera::Data {
+ .bg_color = Color::WHITE,
+ .zoom = 1.0f,
+ }
+ );
// initialize systems here:
//calls init
- script_sys.update();
+ script_sys.fixed_update();
//creates window
- render_sys.update();
+ render_sys.frame_update();
}
// Helper function to time an update call and store its duration
@@ -102,12 +107,14 @@ public:
// Run and profile all systems, return the total time in milliseconds
std::chrono::microseconds run_all_systems() {
std::chrono::microseconds total_microseconds = 0us;
- total_microseconds += time_function("PhysicsSystem", [&]() { physics_sys.update(); });
total_microseconds
- += time_function("CollisionSystem", [&]() { collision_sys.update(); });
+ += time_function("PhysicsSystem", [&]() { physics_sys.fixed_update(); });
total_microseconds
- += time_function("ParticleSystem", [&]() { particle_sys.update(); });
- total_microseconds += time_function("RenderSystem", [&]() { render_sys.update(); });
+ += time_function("CollisionSystem", [&]() { collision_sys.fixed_update(); });
+ total_microseconds
+ += time_function("ParticleSystem", [&]() { particle_sys.fixed_update(); });
+ total_microseconds
+ += time_function("RenderSystem", [&]() { render_sys.frame_update(); });
return total_microseconds;
}
@@ -164,23 +171,25 @@ TEST_F(DISABLED_ProfilingTest, Profiling_2) {
{
//define gameobject used for testing
GameObject gameobject = mgr.new_object(
- "gameobject", "", {static_cast<float>(game_object_count * 2), 0});
- gameobject.add_component<Rigidbody>(Rigidbody::Data{
+ "gameobject", "", {static_cast<float>(game_object_count * 2), 0}
+ );
+ gameobject.add_component<Rigidbody>(Rigidbody::Data {
.gravity_scale = 0.0,
.body_type = Rigidbody::BodyType::STATIC,
});
- gameobject.add_component<BoxCollider>(vec2{0, 0}, vec2{1, 1});
+ gameobject.add_component<BoxCollider>(vec2 {0, 0}, vec2 {1, 1});
gameobject.add_component<BehaviorScript>().set_script<TestScript>();
Sprite & test_sprite = gameobject.add_component<Sprite>(
- Asset{"asset/texture/square.png"},
- Sprite::Data{
+ Asset {"asset/texture/square.png"},
+ Sprite::Data {
.color = {0, 0, 0, 0},
.flip = {.flip_x = false, .flip_y = false},
.sorting_in_layer = 1,
.order_in_layer = 1,
.size = {.y = 500},
- });
+ }
+ );
}
this->game_object_count++;
@@ -203,37 +212,41 @@ TEST_F(DISABLED_ProfilingTest, Profiling_3) {
{
//define gameobject used for testing
GameObject gameobject = mgr.new_object(
- "gameobject", "", {static_cast<float>(game_object_count * 2), 0});
- gameobject.add_component<Rigidbody>(Rigidbody::Data{
+ "gameobject", "", {static_cast<float>(game_object_count * 2), 0}
+ );
+ gameobject.add_component<Rigidbody>(Rigidbody::Data {
.gravity_scale = 0,
.body_type = Rigidbody::BodyType::STATIC,
});
- gameobject.add_component<BoxCollider>(vec2{0, 0}, vec2{1, 1});
+ gameobject.add_component<BoxCollider>(vec2 {0, 0}, vec2 {1, 1});
gameobject.add_component<BehaviorScript>().set_script<TestScript>();
Sprite & test_sprite = gameobject.add_component<Sprite>(
- Asset{"asset/texture/square.png"},
- Sprite::Data{
+ Asset {"asset/texture/square.png"},
+ Sprite::Data {
.color = {0, 0, 0, 0},
.flip = {.flip_x = false, .flip_y = false},
.sorting_in_layer = 1,
.order_in_layer = 1,
.size = {.y = 500},
- });
+ }
+ );
auto & test = gameobject.add_component<ParticleEmitter>(
- test_sprite, ParticleEmitter::Data{
- .max_particles = 10,
- .emission_rate = 100,
- .end_lifespan = 100000,
- .boundary{
- .width = 1000,
- .height = 1000,
- .offset = vec2{0, 0},
- .reset_on_exit = false,
- },
-
- });
+ test_sprite,
+ ParticleEmitter::Data {
+ .max_particles = 10,
+ .emission_rate = 100,
+ .end_lifespan = 100000,
+ .boundary {
+ .width = 1000,
+ .height = 1000,
+ .offset = vec2 {0, 0},
+ .reset_on_exit = false,
+ },
+
+ }
+ );
}
- render_sys.update();
+ render_sys.frame_update();
this->game_object_count++;
this->total_time = 0us;