aboutsummaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-23 21:54:28 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-23 21:54:28 +0200
commit9b7be419c9dcc6ebd1e504713c7b2676ca3d2fdf (patch)
tree97a2fc5ce1ec1345bd6f44889682ea9a2ffafd76 /src/example
parent080ad535e6fc6666b919b1a21b6986aaf9b678eb (diff)
`clang-format`
Diffstat (limited to 'src/example')
-rw-r--r--src/example/asset_manager.cpp4
-rw-r--r--src/example/particle.cpp158
-rw-r--r--src/example/physics.cpp33
-rw-r--r--src/example/rendering.cpp22
4 files changed, 104 insertions, 113 deletions
diff --git a/src/example/asset_manager.cpp b/src/example/asset_manager.cpp
index 9b41c2f..7aa4ffe 100644
--- a/src/example/asset_manager.cpp
+++ b/src/example/asset_manager.cpp
@@ -9,9 +9,7 @@ using namespace crepe::api;
int main() {
// this needs to be called before the asset manager otherwise the destructor of sdl is not in the right order
- {
- Texture test("../asset/texture/img.png");
- }
+ { Texture test("../asset/texture/img.png"); }
auto & mgr = AssetManager::get_instance();
diff --git a/src/example/particle.cpp b/src/example/particle.cpp
index fb89a3d..66b1441 100644
--- a/src/example/particle.cpp
+++ b/src/example/particle.cpp
@@ -1,14 +1,13 @@
-#include <iostream>
-#include <thread>
-#include <chrono>
+#include "Particle.h"
+#include "ParticleSystem.h"
#include "SDLApp.h"
#include "api/ParticleEmitter.h"
-#include "ParticleSystem.h"
-#include "Particle.h"
+#include <chrono>
#include <crepe/Component.h>
#include <crepe/ComponentManager.h>
#include <crepe/api/GameObject.h>
-#include <chrono>
+#include <iostream>
+#include <thread>
using namespace crepe::api;
using namespace crepe;
@@ -17,87 +16,86 @@ using namespace std;
const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600;
-int main(int argc, char* argv[]) {
- SDLApp app(WINDOW_WIDTH, WINDOW_HEIGHT);
+int main(int argc, char * argv[]) {
+ SDLApp app(WINDOW_WIDTH, WINDOW_HEIGHT);
- if (!app.initialize()) {
- cerr << "Failed to initialize SDLApp." << endl;
- return 1;
- }
+ if (!app.initialize()) {
+ cerr << "Failed to initialize SDLApp." << endl;
+ return 1;
+ }
-
GameObject * game_object[1];
game_object[0] = new GameObject(0, "Name", "Tag", 0);
-
-
- ParticleSystem particleSystem;
-
- unsigned int maxParticles = 100; // maximum number of particles
- unsigned int emissionRate = 10; // particles created per second
- unsigned int speed = 50; // base speed of particles
- unsigned int speedOffset = 10; // random offset for particle speed
- unsigned int angle = 270; // base angle of particle emission
- unsigned int angleOffset = 30; // random offset for particle angle
- float beginLifespan = 0.0f; // beginning lifespan of particles
- float endLifespan = 6.0f; // ending lifespan of particles
-
- // Vector to hold all the emitters
- // vector<ParticleEmitter> emitters;
- game_object[0]->add_component<ParticleEmitter>(maxParticles, emissionRate, speed, speedOffset, angle, angleOffset, beginLifespan, endLifespan);
-
-
-
-
- // Loop to create 1000 emitters
- // 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
- // emitter.m_position = {static_cast<float>(200 + (i % 100)), static_cast<float>(200 + (i / 100) * 10)}; // Adjust position for each emitter
-
- // emitters.push_back(emitter); // Add the emitter to the vector
- // }
- float deltaTime = 0.1f;
- bool running = true;
- cout << "start loop " << endl;
- while (running) {
- app.handleEvents(running);
-
- // Start timing
- auto start = chrono::high_resolution_clock::now();
+ ParticleSystem particle_system;
+
+ unsigned int max_particles = 100; // maximum number of particles
+ unsigned int emission_rate = 10; // particles created per second
+ unsigned int speed = 50; // base speed of particles
+ unsigned int speed_offset = 10; // random offset for particle speed
+ unsigned int angle = 270; // base angle of particle emission
+ unsigned int angle_offset = 30; // random offset for particle angle
+ float begin_lifespan = 0.0f; // beginning lifespan of particles
+ float end_lifespan = 6.0f; // ending lifespan of particles
+
+ // Vector to hold all the emitters
+ // vector<ParticleEmitter> emitters;
+ game_object[0]->add_component<ParticleEmitter>(
+ max_particles, emission_rate, speed, speed_offset, angle, angle_offset,
+ begin_lifespan, end_lifespan);
+
+ // Loop to create 1000 emitters
+ // 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
+ // emitter.m_position = {static_cast<float>(200 + (i % 100)), static_cast<float>(200 + (i / 100) * 10)}; // Adjust position for each emitter
+
+ // emitters.push_back(emitter); // Add the emitter to the vector
+ // }
+ float delta_time = 0.1f;
+ bool running = true;
+ cout << "start loop " << endl;
+ while (running) {
+ app.handle_events(running);
+
+ // Start timing
+ auto start = chrono::high_resolution_clock::now();
// POC CODE
- particleSystem.update();
+ particle_system.update();
// POC CODE
- // End timing
- auto end = chrono::high_resolution_clock::now();
- chrono::duration<float, milli> duration = end - start; // get duration in milliseconds
-
- cout << "Update took " << duration.count() << " ms" << endl;
- app.clearScreen();
-
- start = chrono::high_resolution_clock::now();
- // render particles using the drawSquare method from SDLApp
- ComponentManager& mgr = ComponentManager::get_instance();
- std::vector<std::reference_wrapper<ParticleEmitter>> emitters = mgr.get_components_by_type<ParticleEmitter>();
- for (const ParticleEmitter& emitter : emitters) {
- for (const Particle& particle : emitter.particles) {
- if(particle.active)app.drawSquare(particle.position.x, particle.position.y, 5); // draw each particle
- }
- }
-
-
- app.presentScreen();
- end = chrono::high_resolution_clock::now();
- duration = end - start; // get duration in milliseconds
-
- cout << "screen took " << duration.count() << " ms" << endl;
-
- this_thread::sleep_for(chrono::milliseconds(20)); // simulate ~50 FPS
- }
-
- app.cleanUp();
- return 0;
+ // End timing
+ auto end = chrono::high_resolution_clock::now();
+ chrono::duration<float, milli> duration
+ = end - start; // get duration in milliseconds
+
+ cout << "Update took " << duration.count() << " ms" << endl;
+ app.clear_screen();
+
+ start = chrono::high_resolution_clock::now();
+ // render particles using the draw_square method from SDLApp
+ ComponentManager & mgr = ComponentManager::get_instance();
+ std::vector<std::reference_wrapper<ParticleEmitter>> emitters
+ = mgr.get_components_by_type<ParticleEmitter>();
+ for (const ParticleEmitter & emitter : emitters) {
+ for (const Particle & particle : emitter.particles) {
+ if (particle.active)
+ app.draw_square(particle.position.x, particle.position.y,
+ 5); // draw each particle
+ }
+ }
+
+ app.present_screen();
+ end = chrono::high_resolution_clock::now();
+ duration = end - start; // get duration in milliseconds
+
+ cout << "screen took " << duration.count() << " ms" << endl;
+
+ this_thread::sleep_for(chrono::milliseconds(20)); // simulate ~50 FPS
+ }
+
+ app.clean_up();
+ return 0;
}
diff --git a/src/example/physics.cpp b/src/example/physics.cpp
index ee75c5c..db69b9b 100644
--- a/src/example/physics.cpp
+++ b/src/example/physics.cpp
@@ -1,31 +1,30 @@
-#include <iostream>
-#include <thread>
-#include <chrono>
-#include <crepe/api/Transform.h>
-#include <crepe/api/Rigidbody.h>
-#include <crepe/api/Force.h>
#include "PhysicsSystem.h"
+#include <chrono>
#include <crepe/Component.h>
#include <crepe/ComponentManager.h>
+#include <crepe/api/Force.h>
#include <crepe/api/GameObject.h>
+#include <crepe/api/Rigidbody.h>
+#include <crepe/api/Transform.h>
+#include <iostream>
+#include <thread>
using namespace crepe::api;
using namespace crepe;
using namespace std;
-
-int main(int argc, char* argv[]) {
- PhysicsSystem physicsSystem;
+int main(int argc, char * argv[]) {
+ PhysicsSystem physics_system;
GameObject * game_object[2];
game_object[1] = new GameObject(2, "Name", "Tag", 0); // not found not used
game_object[0] = new GameObject(5, "Name", "Tag", 0);
Point point = {
- .x = 0,
- .y = 0,
- };
- game_object[0]->add_component<Transform>(point,0,0);
- game_object[0]->add_component<Rigidbody>(1, 1 , BodyType::Dynamic);
- game_object[0]->add_component<Force>(1 , 0);
- physicsSystem.update();
- return 0;
+ .x = 0,
+ .y = 0,
+ };
+ game_object[0]->add_component<Transform>(point, 0, 0);
+ game_object[0]->add_component<Rigidbody>(1, 1, BodyType::DYNAMIC);
+ game_object[0]->add_component<Force>(1, 0);
+ physics_system.update();
+ return 0;
}
diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp
index 1d83004..1bf448c 100644
--- a/src/example/rendering.cpp
+++ b/src/example/rendering.cpp
@@ -1,16 +1,16 @@
#include <crepe/ComponentManager.h>
-#include <crepe/api/GameObject.h>
#include <crepe/RenderSystem.h>
+#include <crepe/api/GameObject.h>
#include <crepe/util/log.h>
+#include <crepe/api/AssetManager.h>
#include <crepe/api/Color.h>
#include <crepe/api/Point.h>
#include <crepe/api/Sprite.h>
#include <crepe/api/Texture.h>
#include <crepe/api/Transform.h>
-#include <crepe/api/AssetManager.h>
#include <chrono>
#include <memory>
@@ -24,10 +24,10 @@ int main() {
dbg_trace();
auto obj = GameObject(0, "name", "tag", 0);
- auto obj1= GameObject(1, "name", "tag", 0);
+ auto obj1 = GameObject(1, "name", "tag", 0);
auto obj2 = GameObject(2, "name", "tag", 0);
- auto& mgr = AssetManager::get_instance();
+ auto & mgr = AssetManager::get_instance();
// Normal adding components
{
Color color(0, 0, 0, 0);
@@ -38,10 +38,9 @@ int main() {
obj.add_component<Transform>(point, 1, 1);
obj.add_component<Sprite>(
make_shared<Texture>("../asset/texture/img.png"), color,
- flip_settings{true, true});
+ FlipSettings{true, true});
}
-
{
Color color(0, 0, 0, 0);
Point point = {
@@ -49,9 +48,8 @@ int main() {
.y = 0,
};
obj1.add_component<Transform>(point, 0, 0.1);
- auto img = mgr.cache<Texture>("../asset/texture/second.png");
- obj1.add_component<Sprite>(img, color,
- flip_settings{true, true});
+ auto img = mgr.cache<Texture>("../asset/texture/second.png");
+ obj1.add_component<Sprite>(img, color, FlipSettings{true, true});
}
{
@@ -61,12 +59,10 @@ int main() {
.y = 0,
};
//obj.add_component<Transform>(point, 0, 0.1);
- auto img = mgr.cache<Texture>("../asset/texture/second.png");
- obj2.add_component<Sprite>(img, color,
- flip_settings{true, true});
+ auto img = mgr.cache<Texture>("../asset/texture/second.png");
+ obj2.add_component<Sprite>(img, color, FlipSettings{true, true});
}
-
auto & sys = crepe::RenderSystem::get_instance();
auto start = std::chrono::steady_clock::now();
while (std::chrono::steady_clock::now() - start < std::chrono::seconds(5)) {