aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/main.cpp
diff options
context:
space:
mode:
authorjaroWMR <jarorutjes07@gmail.com>2024-10-07 18:07:17 +0200
committerjaroWMR <jarorutjes07@gmail.com>2024-10-07 18:07:17 +0200
commit5f84969c851530ebc430be2cf8e99c945ff7a4a7 (patch)
tree9fcd2755dbfd456f20f0ad37c18c7281b81382b1 /src/crepe/main.cpp
parent5cf5cf64d6f9597849ed5558da4f1bc201165fed (diff)
improved particle system from 90ms to ~ 0.7ms
Diffstat (limited to 'src/crepe/main.cpp')
-rw-r--r--src/crepe/main.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/crepe/main.cpp b/src/crepe/main.cpp
index 314dbed..58480a9 100644
--- a/src/crepe/main.cpp
+++ b/src/crepe/main.cpp
@@ -20,7 +20,7 @@ int main(int argc, char* argv[]) {
ParticleSystem particleSystem;
- unsigned int maxParticles = 10; // maximum number of particles
+ unsigned int maxParticles = 100; // maximum number of particles
unsigned int emissionRate = 1; // particles created per second
unsigned int speed = 50; // base speed of particles
unsigned int speedOffset = 10; // random offset for particle speed
@@ -33,7 +33,7 @@ int main(int argc, char* argv[]) {
std::vector<ParticleEmitter> emitters;
// Loop to create 1000 emitters
- for (unsigned int i = 0; i < 100; ++i) {
+ for (unsigned int i = 0; i < 1000; ++i) {
ParticleEmitter emitter(maxParticles, emissionRate, speed, speedOffset, angle, angleOffset, beginLifespan, endLifespan);
// Set a position for each emitter, modifying the position for demonstration
@@ -43,7 +43,7 @@ int main(int argc, char* argv[]) {
}
float deltaTime = 0.1f;
bool running = true;
-
+ std::cout << "start loop " << std::endl;
while (running) {
app.handleEvents(running);
@@ -59,15 +59,20 @@ int main(int argc, char* argv[]) {
std::cout << "Update took " << duration.count() << " ms" << std::endl;
app.clearScreen();
+ start = std::chrono::high_resolution_clock::now();
// render particles using the drawSquare method from SDLApp
for (const ParticleEmitter& emitter : emitters) {
for (const Particle& particle : emitter.particles) {
-
- app.drawSquare(particle.position.x, particle.position.y, 5); // draw each particle
+ if(particle.active)app.drawSquare(particle.position.x, particle.position.y, 5); // draw each particle
}
}
+
app.presentScreen();
+ end = std::chrono::high_resolution_clock::now();
+ duration = end - start; // get duration in milliseconds
+
+ std::cout << "screen took " << duration.count() << " ms" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(20)); // simulate ~50 FPS
}