aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent080ad535e6fc6666b919b1a21b6986aaf9b678eb (diff)
`clang-format`
Diffstat (limited to 'src')
-rw-r--r--src/crepe/Collider.cpp2
-rw-r--r--src/crepe/CollisionSystem.cpp8
-rw-r--r--src/crepe/CollisionSystem.h17
-rw-r--r--src/crepe/Component.cpp2
-rw-r--r--src/crepe/Component.h3
-rw-r--r--src/crepe/ComponentManager.hpp2
-rw-r--r--src/crepe/Particle.cpp25
-rw-r--r--src/crepe/Particle.h19
-rw-r--r--src/crepe/ParticleSystem.cpp99
-rw-r--r--src/crepe/ParticleSystem.h14
-rw-r--r--src/crepe/PhysicsSystem.cpp80
-rw-r--r--src/crepe/PhysicsSystem.h19
-rw-r--r--src/crepe/Position.h9
-rw-r--r--src/crepe/RenderSystem.cpp6
-rw-r--r--src/crepe/SDLApp.cpp111
-rw-r--r--src/crepe/SDLApp.h31
-rw-r--r--src/crepe/SdlContext.cpp4
-rw-r--r--src/crepe/api/AssetManager.cpp11
-rw-r--r--src/crepe/api/AssetManager.h30
-rw-r--r--src/crepe/api/CircleCollider.h5
-rw-r--r--src/crepe/api/Color.cpp52
-rw-r--r--src/crepe/api/Force.cpp12
-rw-r--r--src/crepe/api/Force.h8
-rw-r--r--src/crepe/api/ParticleEmitter.cpp40
-rw-r--r--src/crepe/api/ParticleEmitter.h36
-rw-r--r--src/crepe/api/Point.h5
-rw-r--r--src/crepe/api/Rigidbody.cpp7
-rw-r--r--src/crepe/api/Rigidbody.h13
-rw-r--r--src/crepe/api/Sprite.cpp3
-rw-r--r--src/crepe/api/Sprite.h17
-rw-r--r--src/crepe/api/Texture.cpp1
-rw-r--r--src/crepe/api/Texture.h7
-rw-r--r--src/crepe/api/Transform.h2
-rw-r--r--src/crepe/util/log.cpp14
-rw-r--r--src/crepe/util/log.h6
-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
39 files changed, 446 insertions, 491 deletions
diff --git a/src/crepe/Collider.cpp b/src/crepe/Collider.cpp
index 311ffb3..13a3f33 100644
--- a/src/crepe/Collider.cpp
+++ b/src/crepe/Collider.cpp
@@ -2,4 +2,4 @@
using namespace crepe;
-Collider::Collider(uint32_t gameObjectId) : Component(gameObjectId){}
+Collider::Collider(uint32_t gameObjectId) : Component(gameObjectId) {}
diff --git a/src/crepe/CollisionSystem.cpp b/src/crepe/CollisionSystem.cpp
index a0c6dca..77110a2 100644
--- a/src/crepe/CollisionSystem.cpp
+++ b/src/crepe/CollisionSystem.cpp
@@ -4,10 +4,6 @@
using namespace crepe;
-CollisionSystem::CollisionSystem() {
+CollisionSystem::CollisionSystem() {}
-}
-
-void CollisionSystem::update() {
-
-}
+void CollisionSystem::update() {}
diff --git a/src/crepe/CollisionSystem.h b/src/crepe/CollisionSystem.h
index 70d7237..4a222eb 100644
--- a/src/crepe/CollisionSystem.h
+++ b/src/crepe/CollisionSystem.h
@@ -2,14 +2,13 @@
namespace crepe {
-class CollisionSystem
-{
- private:
- /* data */
- public:
- CollisionSystem(/* args */);
- void update();
-};
+class CollisionSystem {
+private:
+ /* data */
-}
+public:
+ CollisionSystem(/* args */);
+ void update();
+};
+} // namespace crepe
diff --git a/src/crepe/Component.cpp b/src/crepe/Component.cpp
index e2cd7e0..358ce31 100644
--- a/src/crepe/Component.cpp
+++ b/src/crepe/Component.cpp
@@ -2,4 +2,4 @@
using namespace crepe;
-Component::Component(uint32_t id) : gameObjectId(id), active(true) {}
+Component::Component(uint32_t id) : game_object_id(id), active(true) {}
diff --git a/src/crepe/Component.h b/src/crepe/Component.h
index ccf95cb..9e10c42 100644
--- a/src/crepe/Component.h
+++ b/src/crepe/Component.h
@@ -9,11 +9,12 @@ class Component {
protected:
friend class crepe::ComponentManager;
Component(uint32_t id);
+
public:
virtual ~Component() = default;
public:
- uint32_t gameObjectId;
+ uint32_t game_object_id;
bool active;
};
diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp
index 22dbc66..9b07f13 100644
--- a/src/crepe/ComponentManager.hpp
+++ b/src/crepe/ComponentManager.hpp
@@ -30,7 +30,7 @@ T & ComponentManager::add_component(uint32_t id, Args &&... args) {
// Create a new component of type T (arguments directly forwarded). The
// constructor must be called by ComponentManager.
- T * instance = new T(id,forward<Args>(args)...);
+ T * instance = new T(id, forward<Args>(args)...);
// store its unique_ptr in the vector<>
components[type][id].push_back(unique_ptr<T>(instance));
diff --git a/src/crepe/Particle.cpp b/src/crepe/Particle.cpp
index aa33606..4810e80 100644
--- a/src/crepe/Particle.cpp
+++ b/src/crepe/Particle.cpp
@@ -1,25 +1,20 @@
#include "Particle.h"
-#include <iostream>
using namespace crepe;
-Particle::Particle()
-{
- this->active = false;
-}
+Particle::Particle() { this->active = false; }
void Particle::reset(float lifespan, Position position, Position velocity) {
- this->timeInLife = 0;
- this->lifespan = lifespan;
- this->position = position;
- this->velocity = velocity;
- this->active = true;
+ this->time_in_life = 0;
+ this->lifespan = lifespan;
+ this->position = position;
+ this->velocity = velocity;
+ this->active = true;
}
void Particle::update(float deltaTime) {
- timeInLife += deltaTime;
- position.x += velocity.x * deltaTime;
- position.y += velocity.y * deltaTime;
- if(timeInLife >= lifespan)this->active = false;
+ time_in_life += deltaTime;
+ position.x += velocity.x * deltaTime;
+ position.y += velocity.y * deltaTime;
+ if (time_in_life >= lifespan) this->active = false;
}
-
diff --git a/src/crepe/Particle.h b/src/crepe/Particle.h
index 006986a..6f689bd 100644
--- a/src/crepe/Particle.h
+++ b/src/crepe/Particle.h
@@ -6,16 +6,15 @@ namespace crepe {
class Particle {
public:
+ Position position;
+ Position velocity;
+ float lifespan;
+ bool active;
- Position position;
- Position velocity;
- float lifespan;
- bool active;
-
- Particle();
- void reset(float lifespan, Position position, Position velocity);
- void update(float deltaTime);
- float timeInLife;
+ Particle();
+ void reset(float lifespan, Position position, Position velocity);
+ void update(float deltaTime);
+ float time_in_life;
};
-}
+} // namespace crepe
diff --git a/src/crepe/ParticleSystem.cpp b/src/crepe/ParticleSystem.cpp
index bf7f8fc..f0220a1 100644
--- a/src/crepe/ParticleSystem.cpp
+++ b/src/crepe/ParticleSystem.cpp
@@ -1,59 +1,62 @@
#include "ParticleSystem.h"
+#include "ComponentManager.h"
+#include "Particle.h"
+#include "api/ParticleEmitter.h"
#include <cmath>
#include <ctime>
-#include "api/ParticleEmitter.h"
-#include "Particle.h"
-#include "ComponentManager.h"
using namespace crepe;
-ParticleSystem::ParticleSystem() : m_elapsedTime(0.0f) {} // Initialize m_elapsedTime to 0
+ParticleSystem::ParticleSystem()
+ : m_elapsed_time(0.0f) {} // Initialize m_elapsedTime to 0
void ParticleSystem::update() {
- ComponentManager& mgr = ComponentManager::get_instance();
- std::vector<std::reference_wrapper<ParticleEmitter>> emitters = mgr.get_components_by_type<ParticleEmitter>();
- float deltaTime = 0.10;
- for (ParticleEmitter& emitter : emitters) {
- float updateAmount = 1/static_cast<float>(emitter.m_emissionRate);
- for (float i = 0; i < deltaTime; i += updateAmount)
- {
- emitParticle(emitter);
- }
- for (size_t j = 0; j < emitter.particles.size(); j++)
- {
- if(emitter.particles[j].active)
- {
- emitter.particles[j].update(deltaTime);
- }
- }
- }
+ ComponentManager & mgr = ComponentManager::get_instance();
+ std::vector<std::reference_wrapper<ParticleEmitter>> emitters
+ = mgr.get_components_by_type<ParticleEmitter>();
+ float delta_time = 0.10;
+ for (ParticleEmitter & emitter : emitters) {
+ float update_amount = 1 / static_cast<float>(emitter.m_emission_rate);
+ for (float i = 0; i < delta_time; i += update_amount) {
+ emit_particle(emitter);
+ }
+ for (size_t j = 0; j < emitter.particles.size(); j++) {
+ if (emitter.particles[j].active) {
+ emitter.particles[j].update(delta_time);
+ }
+ }
+ }
}
-void ParticleSystem::emitParticle(ParticleEmitter& emitter) {
- Position initialPosition = { emitter.m_position.x, emitter.m_position.y};
- float randomAngle = 0.0f;
- if(emitter.m_maxAngle < emitter.m_minAngle)
- {
- randomAngle = ((emitter.m_minAngle + (std::rand() % (static_cast<uint32_t>(emitter.m_maxAngle + 360 - emitter.m_minAngle + 1))))%360);
- }
- else
- {
- randomAngle = emitter.m_minAngle + (std::rand() % (static_cast<uint32_t>(emitter.m_maxAngle - emitter.m_minAngle + 1)));
- }
- float angleInRadians = randomAngle * (M_PI / 180.0f);
- float randomSpeedOffset = (static_cast<float>(std::rand()) / RAND_MAX) * (2 * emitter.m_speedOffset) - emitter.m_speedOffset;
- float velocityX = (emitter.m_speed + randomSpeedOffset) * std::cos(angleInRadians);
- float velocityY = (emitter.m_speed + randomSpeedOffset) * std::sin(angleInRadians);
- Position initialVelocity = {
- velocityX,
- velocityY
- };
- for (size_t i = 0; i < emitter.particles.size(); i++)
- {
- if(!emitter.particles[i].active)
- {
- emitter.particles[i].reset(emitter.m_endLifespan, initialPosition, initialVelocity);
- break;
- }
- }
+void ParticleSystem::emit_particle(ParticleEmitter & emitter) {
+ Position initial_position = {emitter.m_position.x, emitter.m_position.y};
+ float random_angle = 0.0f;
+ if (emitter.m_max_angle < emitter.m_min_angle) {
+ random_angle = ((emitter.m_min_angle
+ + (std::rand()
+ % (static_cast<uint32_t>(emitter.m_max_angle + 360
+ - emitter.m_min_angle + 1))))
+ % 360);
+ } else {
+ random_angle = emitter.m_min_angle
+ + (std::rand()
+ % (static_cast<uint32_t>(emitter.m_max_angle
+ - emitter.m_min_angle + 1)));
+ }
+ float angle_in_radians = random_angle * (M_PI / 180.0f);
+ float random_speed_offset = (static_cast<float>(std::rand()) / RAND_MAX)
+ * (2 * emitter.m_speed_offset)
+ - emitter.m_speed_offset;
+ float velocity_x
+ = (emitter.m_speed + random_speed_offset) * std::cos(angle_in_radians);
+ float velocity_y
+ = (emitter.m_speed + random_speed_offset) * std::sin(angle_in_radians);
+ Position initial_velocity = {velocity_x, velocity_y};
+ for (size_t i = 0; i < emitter.particles.size(); i++) {
+ if (!emitter.particles[i].active) {
+ emitter.particles[i].reset(emitter.m_end_lifespan, initial_position,
+ initial_velocity);
+ break;
+ }
+ }
}
diff --git a/src/crepe/ParticleSystem.h b/src/crepe/ParticleSystem.h
index 313e1dd..071eec4 100644
--- a/src/crepe/ParticleSystem.h
+++ b/src/crepe/ParticleSystem.h
@@ -1,19 +1,19 @@
#pragma once
-#include <vector>
#include "api/ParticleEmitter.h"
-
+#include <vector>
namespace crepe {
class ParticleSystem {
public:
- ParticleSystem();
- void update();
+ ParticleSystem();
+ void update();
+
private:
- void emitParticle(ParticleEmitter &emitter); //emits a new particle
+ void emit_particle(ParticleEmitter & emitter); //emits a new particle
- float m_elapsedTime; //elapsed time since the last emission
+ float m_elapsed_time; //elapsed time since the last emission
};
-}
+} // namespace crepe
diff --git a/src/crepe/PhysicsSystem.cpp b/src/crepe/PhysicsSystem.cpp
index 93b20f1..4bb931d 100644
--- a/src/crepe/PhysicsSystem.cpp
+++ b/src/crepe/PhysicsSystem.cpp
@@ -1,56 +1,60 @@
#include "PhysicsSystem.h"
#include "ComponentManager.h"
+#include "api/Force.h"
#include "api/Rigidbody.h"
#include "api/Transform.h"
-#include "api/Force.h"
#include <iostream>
using namespace crepe;
using namespace crepe::api;
-PhysicsSystem::PhysicsSystem() {
-
-}
+PhysicsSystem::PhysicsSystem() {}
void PhysicsSystem::update() {
- ComponentManager& mgr = ComponentManager::get_instance();
- std::vector<std::reference_wrapper<Rigidbody>> rigidbodies = mgr.get_components_by_type<Rigidbody>();
- std::vector<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_type<Transform>();
-
- for (Rigidbody& rigidbody : rigidbodies) {
+ ComponentManager & mgr = ComponentManager::get_instance();
+ std::vector<std::reference_wrapper<Rigidbody>> rigidbodies
+ = mgr.get_components_by_type<Rigidbody>();
+ std::vector<std::reference_wrapper<Transform>> transforms
+ = mgr.get_components_by_type<Transform>();
+
+ for (Rigidbody & rigidbody : rigidbodies) {
+
+ switch (rigidbody.body_type) {
+ case BodyType::DYNAMIC:
+ for (Transform & transform : transforms) {
+ if (transform.game_object_id == rigidbody.game_object_id) {
+ rigidbody.velocity_x = 0;
+ rigidbody.velocity_y = 0;
+ std::vector<std::reference_wrapper<Force>> forces
+ = mgr.get_components_by_id<Force>(
+ rigidbody.game_object_id);
+ rigidbody.velocity_y
+ += rigidbody.gravity_scale * 1 * rigidbody.mass;
- switch (rigidbody.body_type)
- {
- case BodyType::Dynamic :
- for (Transform& transform : transforms) {
- if(transform.gameObjectId == rigidbody.gameObjectId)
- {
- rigidbody.velocity_x = 0;
- rigidbody.velocity_y = 0;
- std::vector<std::reference_wrapper<Force>> Forces = mgr.get_components_by_id<Force>(rigidbody.gameObjectId);
- rigidbody.velocity_y += rigidbody.gravity_scale * 1 * rigidbody.mass;
+ for (Force & force : forces) {
+ rigidbody.velocity_x += force.force_x;
+ rigidbody.velocity_y += force.force_y;
+ }
- for (Force& force : Forces)
- {
- rigidbody.velocity_x += force.force_x;
- rigidbody.velocity_y += force.force_y;
+ std::cout << "before transform.postion.x "
+ << transform.position.x << std::endl;
+ std::cout << "before transform.postion.y "
+ << transform.position.y << std::endl;
+ transform.position.x += rigidbody.velocity_x;
+ transform.position.y += rigidbody.velocity_y;
+ std::cout << "after transform.postion.x "
+ << transform.position.x << std::endl;
+ std::cout << "after transform.postion.y "
+ << transform.position.y << std::endl;
}
-
- std::cout << "before transform.postion.x " << transform.position.x << std::endl;
- std::cout << "before transform.postion.y " << transform.position.y << std::endl;
- transform.position.x += rigidbody.velocity_x;
- transform.position.y += rigidbody.velocity_y;
- std::cout << "after transform.postion.x " << transform.position.x << std::endl;
- std::cout << "after transform.postion.y " << transform.position.y << std::endl;
}
- }
- break;
- case BodyType::Kinematic :
- break; //(scripts)
- case BodyType::Static :
- break; //(unmoveable objects)
- default:
- break;
+ break;
+ case BodyType::KINEMATIC:
+ break; //(scripts)
+ case BodyType::STATIC:
+ break; //(unmoveable objects)
+ default:
+ break;
}
}
}
diff --git a/src/crepe/PhysicsSystem.h b/src/crepe/PhysicsSystem.h
index 1899089..dd242c7 100644
--- a/src/crepe/PhysicsSystem.h
+++ b/src/crepe/PhysicsSystem.h
@@ -2,16 +2,13 @@
namespace crepe {
-class PhysicsSystem
-{
- private:
- /* data */
- public:
- PhysicsSystem(/* args */);
- void update();
-};
-
-}
-
+class PhysicsSystem {
+private:
+ /* data */
+public:
+ PhysicsSystem(/* args */);
+ void update();
+};
+} // namespace crepe
diff --git a/src/crepe/Position.h b/src/crepe/Position.h
index 5eb985e..f84b63d 100644
--- a/src/crepe/Position.h
+++ b/src/crepe/Position.h
@@ -3,9 +3,8 @@
namespace crepe {
struct Position {
- float x = 0.0;
- float y = 0.0;
- };
-
-}
+ float x = 0.0;
+ float y = 0.0;
+};
+} // namespace crepe
diff --git a/src/crepe/RenderSystem.cpp b/src/crepe/RenderSystem.cpp
index b5503d3..b8789fc 100644
--- a/src/crepe/RenderSystem.cpp
+++ b/src/crepe/RenderSystem.cpp
@@ -32,11 +32,11 @@ void RenderSystem::update() {
render.clear_screen();
for (const Sprite & sprite : sprites) {
- std::vector<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_id<Transform>(sprite.gameObjectId);
- for (const Transform& transform : transforms) {
+ std::vector<std::reference_wrapper<Transform>> transforms
+ = mgr.get_components_by_id<Transform>(sprite.game_object_id);
+ for (const Transform & transform : transforms) {
render.draw(sprite, transform);
}
-
}
render.present_screen();
}
diff --git a/src/crepe/SDLApp.cpp b/src/crepe/SDLApp.cpp
index ca7e819..198c0d0 100644
--- a/src/crepe/SDLApp.cpp
+++ b/src/crepe/SDLApp.cpp
@@ -1,78 +1,69 @@
#include "SDLApp.h"
-#include <iostream>
-#include <vector>
#include "Particle.h"
#include "api/ParticleEmitter.h"
+#include <iostream>
+#include <vector>
-SDLApp::SDLApp(int windowWidth, int windowHeight)
- : windowWidth(windowWidth), windowHeight(windowHeight), window(nullptr), renderer(nullptr) {}
+SDLApp::SDLApp(int window_width, int window_height)
+ : window_width(window_width), window_height(window_height), window(nullptr),
+ renderer(nullptr) {}
-SDLApp::~SDLApp() {
- cleanUp();
-}
+SDLApp::~SDLApp() { clean_up(); }
bool SDLApp::initialize() {
- if (SDL_Init(SDL_INIT_VIDEO) != 0) {
- std::cerr << "SDL Initialization Error: " << SDL_GetError() << std::endl;
- return false;
- }
-
- window = SDL_CreateWindow("Particle System",
- SDL_WINDOWPOS_CENTERED,
- SDL_WINDOWPOS_CENTERED,
- windowWidth,
- windowHeight,
- SDL_WINDOW_SHOWN);
- if (!window) {
- std::cerr << "Window Creation Error: " << SDL_GetError() << std::endl;
- return false;
- }
-
- renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
- if (!renderer) {
- std::cerr << "Renderer Creation Error: " << SDL_GetError() << std::endl;
- return false;
- }
-
- return true;
+ if (SDL_Init(SDL_INIT_VIDEO) != 0) {
+ std::cerr << "SDL Initialization Error: " << SDL_GetError()
+ << std::endl;
+ return false;
+ }
+
+ window = SDL_CreateWindow("Particle System", SDL_WINDOWPOS_CENTERED,
+ SDL_WINDOWPOS_CENTERED, window_width, window_height,
+ SDL_WINDOW_SHOWN);
+ if (!window) {
+ std::cerr << "Window Creation Error: " << SDL_GetError() << std::endl;
+ return false;
+ }
+
+ renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
+ if (!renderer) {
+ std::cerr << "Renderer Creation Error: " << SDL_GetError() << std::endl;
+ return false;
+ }
+
+ return true;
}
-void SDLApp::handleEvents(bool& running) {
- SDL_Event event;
- while (SDL_PollEvent(&event)) {
- if (event.type == SDL_QUIT) {
- running = false;
- }
- }
+void SDLApp::handle_events(bool & running) {
+ SDL_Event event;
+ while (SDL_PollEvent(&event)) {
+ if (event.type == SDL_QUIT) {
+ running = false;
+ }
+ }
}
-void SDLApp::clearScreen() {
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_RenderClear(renderer);
+void SDLApp::clear_screen() {
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
+ SDL_RenderClear(renderer);
}
-void SDLApp::presentScreen() {
- SDL_RenderPresent(renderer);
-}
+void SDLApp::present_screen() { SDL_RenderPresent(renderer); }
-void SDLApp::drawSquare(int x, int y, int size) {
- SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
- SDL_Rect rect = { x, y, size, size };
- SDL_RenderFillRect(renderer, &rect);
+void SDLApp::draw_square(int x, int y, int size) {
+ SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
+ SDL_Rect rect = {x, y, size, size};
+ SDL_RenderFillRect(renderer, &rect);
}
-SDL_Texture* squareTexture = nullptr; // Load this with an image or create it
-
-
-
-
+SDL_Texture * square_texture = nullptr; // Load this with an image or create it
-void SDLApp::cleanUp() {
- if (renderer) {
- SDL_DestroyRenderer(renderer);
- }
- if (window) {
- SDL_DestroyWindow(window);
- }
- SDL_Quit();
+void SDLApp::clean_up() {
+ if (renderer) {
+ SDL_DestroyRenderer(renderer);
+ }
+ if (window) {
+ SDL_DestroyWindow(window);
+ }
+ SDL_Quit();
}
diff --git a/src/crepe/SDLApp.h b/src/crepe/SDLApp.h
index b536ac8..cdba4c3 100644
--- a/src/crepe/SDLApp.h
+++ b/src/crepe/SDLApp.h
@@ -1,28 +1,29 @@
#ifndef SDLAPP_HPP
#define SDLAPP_HPP
-#include <SDL2/SDL.h>
#include "Particle.h"
#include "api/ParticleEmitter.h"
+#include <SDL2/SDL.h>
class SDLApp {
public:
- SDLApp(int windowWidth, int windowHeight);
- ~SDLApp();
+ SDLApp(int windowWidth, int windowHeight);
+ ~SDLApp();
+
+ bool initialize();
+ void handle_events(bool & running);
+ void clear_screen();
+ void present_screen();
+ void draw_square(int x, int y, int size);
+ void clean_up();
+ void draw_particles(const std::vector<crepe::ParticleEmitter> & emitters);
+ void draw_multiple_squares(const std::vector<SDL_Rect> & squares);
- bool initialize();
- void handleEvents(bool& running);
- void clearScreen();
- void presentScreen();
- void drawSquare(int x, int y, int size);
- void cleanUp();
- void drawParticles(const std::vector<crepe::ParticleEmitter>& emitters);
- void drawMultipleSquares(const std::vector<SDL_Rect>& squares);
private:
- int windowWidth;
- int windowHeight;
- SDL_Window* window;
- SDL_Renderer* renderer;
+ int window_width;
+ int window_height;
+ SDL_Window * window;
+ SDL_Renderer * renderer;
};
#endif
diff --git a/src/crepe/SdlContext.cpp b/src/crepe/SdlContext.cpp
index 09d9c9b..f00dade 100644
--- a/src/crepe/SdlContext.cpp
+++ b/src/crepe/SdlContext.cpp
@@ -96,7 +96,7 @@ void SdlContext::draw(const api::Sprite & sprite,
.w = static_cast<int>(w * transform.scale),
.h = static_cast<int>(h * transform.scale),
};
-
+
double degrees = transform.rotation * 180 / M_PI;
SDL_RenderCopyEx(this->m_game_renderer, sprite.sprite_image->m_texture,
NULL, &dstrect, degrees, NULL, render_flip);
@@ -131,7 +131,7 @@ SDL_Texture * SdlContext::setTextureFromPath(const char * path, SDL_Rect & clip,
SDL_Texture * SdlContext::texture_from_path(const char * path) {
dbg_trace();
-
+
SDL_Surface * tmp = IMG_Load(path);
if (!tmp) {
std::cerr << "Error surface " << IMG_GetError << std::endl;
diff --git a/src/crepe/api/AssetManager.cpp b/src/crepe/api/AssetManager.cpp
index f6cc369..bf4217f 100644
--- a/src/crepe/api/AssetManager.cpp
+++ b/src/crepe/api/AssetManager.cpp
@@ -3,21 +3,16 @@
#include "AssetManager.h"
#include "util/log.h"
-
using namespace crepe::api;
-AssetManager& AssetManager::get_instance(){
+AssetManager & AssetManager::get_instance() {
static AssetManager instance;
return instance;
}
-
-AssetManager::~AssetManager(){
+AssetManager::~AssetManager() {
dbg_trace();
this->asset_cache.clear();
}
-AssetManager::AssetManager(){
- dbg_trace();
-}
-
+AssetManager::AssetManager() { dbg_trace(); }
diff --git a/src/crepe/api/AssetManager.h b/src/crepe/api/AssetManager.h
index 1b8b86f..f3f1307 100644
--- a/src/crepe/api/AssetManager.h
+++ b/src/crepe/api/AssetManager.h
@@ -1,22 +1,18 @@
#pragma once
-
-
#include <any>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
+namespace crepe::api {
-namespace crepe::api{
-
-class AssetManager{
-
+class AssetManager {
private:
- std::unordered_map< std::string, std::any> asset_cache;
-
+ std::unordered_map<std::string, std::any> asset_cache;
+
private:
AssetManager();
virtual ~AssetManager();
@@ -24,27 +20,27 @@ private:
public:
AssetManager(const AssetManager &) = delete;
AssetManager(AssetManager &&) = delete;
- AssetManager &operator=(const AssetManager &) = delete;
- AssetManager &operator=(AssetManager &&) = delete;
-
-
- static AssetManager& get_instance();
+ AssetManager & operator=(const AssetManager &) = delete;
+ AssetManager & operator=(AssetManager &&) = delete;
+ static AssetManager & get_instance();
public:
- template<typename asset>
- std::shared_ptr<asset> cache(const std::string& file_path, bool reload = false){
+ template <typename asset>
+ std::shared_ptr<asset> cache(const std::string & file_path,
+ bool reload = false) {
auto it = asset_cache.find(file_path);
if (!reload && it != asset_cache.end()) {
return std::any_cast<std::shared_ptr<asset>>(it->second);
}
- std::shared_ptr<asset> new_asset = std::make_shared<asset>(file_path.c_str());
+ std::shared_ptr<asset> new_asset
+ = std::make_shared<asset>(file_path.c_str());
asset_cache[file_path] = new_asset;
return new_asset;
}
};
-}
+} // namespace crepe::api
diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h
index 4a4883c..96d98ed 100644
--- a/src/crepe/api/CircleCollider.h
+++ b/src/crepe/api/CircleCollider.h
@@ -5,8 +5,9 @@ namespace crepe::api {
class CircleCollider : public Collider {
public:
- CircleCollider(uint32_t gameObjectId,int radius) : Collider(gameObjectId), radius(radius) {}
+ CircleCollider(uint32_t gameObjectId, int radius)
+ : Collider(gameObjectId), radius(radius) {}
int radius;
};
-} // namespace crepe
+} // namespace crepe::api
diff --git a/src/crepe/api/Color.cpp b/src/crepe/api/Color.cpp
index c73ce6c..5c7d8cc 100644
--- a/src/crepe/api/Color.cpp
+++ b/src/crepe/api/Color.cpp
@@ -2,52 +2,34 @@
#include "Color.h"
-
using namespace crepe::api;
-Color Color::white = Color(255,255,255,0);
-Color Color::red = Color(255,0,0,0);
-Color Color::green = Color(0,255,0,0);
-Color Color::blue = Color(0,0,255,0);
-Color Color::black = Color(0,0,0,0);
-Color Color::cyan = Color(0,255,255,0);
-Color Color::yellow = Color(255,255,0,0);
-Color Color::magenta= Color(255,0,255,0);
+Color Color::white = Color(255, 255, 255, 0);
+Color Color::red = Color(255, 0, 0, 0);
+Color Color::green = Color(0, 255, 0, 0);
+Color Color::blue = Color(0, 0, 255, 0);
+Color Color::black = Color(0, 0, 0, 0);
+Color Color::cyan = Color(0, 255, 255, 0);
+Color Color::yellow = Color(255, 255, 0, 0);
+Color Color::magenta = Color(255, 0, 255, 0);
-Color::Color(double red, double green, double blue, double alpha){
+Color::Color(double red, double green, double blue, double alpha) {
this->a = alpha;
this->r = red;
this->g = green;
this->b = blue;
};
-const Color& Color::get_white(){
- return Color::white;
-};
-
-const Color& Color::get_red(){
- return Color::red;
-};
-const Color& Color::get_green(){
- return Color::green;
-};
-const Color& Color::get_blue(){
- return Color::blue;
-};
+const Color & Color::get_white() { return Color::white; };
-const Color& Color::get_black(){
- return Color::black;
-};
+const Color & Color::get_red() { return Color::red; };
+const Color & Color::get_green() { return Color::green; };
+const Color & Color::get_blue() { return Color::blue; };
-const Color& Color::get_cyan(){
- return Color::cyan;
-};
+const Color & Color::get_black() { return Color::black; };
-const Color& Color::get_yellow(){
- return Color::yellow;
-};
+const Color & Color::get_cyan() { return Color::cyan; };
-const Color& Color::get_magenta(){
- return Color::magenta;
-};
+const Color & Color::get_yellow() { return Color::yellow; };
+const Color & Color::get_magenta() { return Color::magenta; };
diff --git a/src/crepe/api/Force.cpp b/src/crepe/api/Force.cpp
index 1b4c81a..ff82afa 100644
--- a/src/crepe/api/Force.cpp
+++ b/src/crepe/api/Force.cpp
@@ -3,12 +3,14 @@
namespace crepe::api {
-Force::Force(uint32_t gameObjectId, uint32_t forceMagnitude, uint32_t direction): Component(gameObjectId)
-{
+Force::Force(uint32_t gameObjectId, uint32_t forceMagnitude, uint32_t direction)
+ : Component(gameObjectId) {
// Convert direction from degrees to radians
- float radian_direction = static_cast<float>(direction) * (M_PI / 180.0f);
- force_x = static_cast<int32_t>(std::round(forceMagnitude * std::cos(radian_direction)));
- force_y = static_cast<int32_t>(std::round(forceMagnitude * std::sin(radian_direction)));
+ float radian_direction = static_cast<float>(direction) * (M_PI / 180.0f);
+ force_x = static_cast<int32_t>(
+ std::round(forceMagnitude * std::cos(radian_direction)));
+ force_y = static_cast<int32_t>(
+ std::round(forceMagnitude * std::sin(radian_direction)));
}
} // namespace crepe::api
diff --git a/src/crepe/api/Force.h b/src/crepe/api/Force.h
index 0b06da1..1d30af4 100644
--- a/src/crepe/api/Force.h
+++ b/src/crepe/api/Force.h
@@ -8,10 +8,10 @@ namespace crepe::api {
class Force : public Component {
public:
- Force(uint32_t gameObjectId, uint32_t forceMagnitude, uint32_t direction);
+ Force(uint32_t gameObjectId, uint32_t forceMagnitude, uint32_t direction);
- int32_t force_x;
- int32_t force_y;
+ int32_t force_x;
+ int32_t force_y;
};
-} // namespace crepe
+} // namespace crepe::api
diff --git a/src/crepe/api/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp
index 318c6db..298a5ec 100644
--- a/src/crepe/api/ParticleEmitter.cpp
+++ b/src/crepe/api/ParticleEmitter.cpp
@@ -1,28 +1,36 @@
#include "ParticleEmitter.h"
-#include <ctime>
#include "Particle.h"
+#include <ctime>
#include <iostream>
using namespace crepe;
-ParticleEmitter::ParticleEmitter(uint32_t gameObjectId ,uint32_t maxParticles, uint32_t emissionRate, uint32_t speed, uint32_t speedOffset, uint32_t angle, uint32_t angleOffset, float m_beginLifespan, float m_endLifespan)
- : Component(gameObjectId), m_maxParticles(maxParticles), m_emissionRate(emissionRate), m_speed(speed), m_speedOffset(speedOffset), m_position{0, 0}, m_beginLifespan(m_beginLifespan),m_endLifespan(m_endLifespan) {
- std::srand(static_cast<uint32_t>(std::time(nullptr))); // initialize random seed
- std::cout << "Create emitter" << std::endl;
- m_minAngle = (360 + angle - (angleOffset % 360)) % 360; // calculate minAngle
- m_maxAngle = (360 + angle + (angleOffset % 360)) % 360; // calculate maxAngle
+ParticleEmitter::ParticleEmitter(uint32_t gameObjectId, uint32_t max_particles,
+ uint32_t emission_rate, uint32_t speed,
+ uint32_t speed_offset, uint32_t angle,
+ uint32_t angleOffset, float m_begin_lifespan,
+ float m_end_lifespan)
+ : Component(gameObjectId), m_max_particles(max_particles),
+ m_emission_rate(emission_rate), m_speed(speed), m_speed_offset(speed_offset),
+ m_position{0, 0}, m_begin_lifespan(m_begin_lifespan),
+ m_end_lifespan(m_end_lifespan) {
+ std::srand(
+ static_cast<uint32_t>(std::time(nullptr))); // initialize random seed
+ std::cout << "Create emitter" << std::endl;
+ m_min_angle
+ = (360 + angle - (angleOffset % 360)) % 360; // calculate minAngle
+ m_max_angle
+ = (360 + angle + (angleOffset % 360)) % 360; // calculate maxAngle
m_position.x = 400;
m_position.y = 400;
- for (size_t i = 0; i < m_maxParticles; i++)
- {
- this->particles.emplace_back();
- }
-
+ for (size_t i = 0; i < m_max_particles; i++) {
+ this->particles.emplace_back();
+ }
}
ParticleEmitter::~ParticleEmitter() {
- std::vector<Particle>::iterator it = this->particles.begin();
- while (it != this->particles.end()) {
- it = this->particles.erase(it);
- }
+ std::vector<Particle>::iterator it = this->particles.begin();
+ while (it != this->particles.end()) {
+ it = this->particles.erase(it);
+ }
}
diff --git a/src/crepe/api/ParticleEmitter.h b/src/crepe/api/ParticleEmitter.h
index 8cd78a9..23f02f6 100644
--- a/src/crepe/api/ParticleEmitter.h
+++ b/src/crepe/api/ParticleEmitter.h
@@ -1,32 +1,32 @@
#pragma once
-#include <vector>
+#include "Component.h"
#include "Particle.h"
#include <cstdint>
-#include "Component.h"
+#include <vector>
#
namespace crepe {
class ParticleEmitter : public Component {
public:
- ParticleEmitter(uint32_t gameObjectId, uint32_t maxParticles, uint32_t emissionRate, uint32_t speed, uint32_t speedOffset, uint32_t angle, uint32_t angleOffset,float m_beginLifespan,float m_endLifespan);
- ~ParticleEmitter();
-
- Position m_position; //position of the emitter
- uint32_t m_maxParticles; //maximum number of particles
- uint32_t m_emissionRate; //rate of particle emission
+ ParticleEmitter(uint32_t gameObjectId, uint32_t maxParticles,
+ uint32_t emissionRate, uint32_t speed, uint32_t speedOffset,
+ uint32_t angle, uint32_t angleOffset, float m_beginLifespan,
+ float m_endLifespan);
+ ~ParticleEmitter();
+
+ Position m_position; //position of the emitter
+ uint32_t m_max_particles; //maximum number of particles
+ uint32_t m_emission_rate; //rate of particle emission
uint32_t m_speed; //base speed of the particles
- uint32_t m_speedOffset; //offset for random speed variation
- uint32_t m_minAngle; //min angle of particle emission
- uint32_t m_maxAngle; //max angle of particle emission
- float m_beginLifespan; //begin Lifespan of particle (only visual)
- float m_endLifespan; //begin Lifespan of particle
-
- std::vector<Particle> particles; //collection of particles
+ uint32_t m_speed_offset; //offset for random speed variation
+ uint32_t m_min_angle; //min angle of particle emission
+ uint32_t m_max_angle; //max angle of particle emission
+ float m_begin_lifespan; //begin Lifespan of particle (only visual)
+ float m_end_lifespan; //begin Lifespan of particle
+ std::vector<Particle> particles; //collection of particles
};
-}
-
-
+} // namespace crepe
diff --git a/src/crepe/api/Point.h b/src/crepe/api/Point.h
index 463aa7c..b47b7e6 100644
--- a/src/crepe/api/Point.h
+++ b/src/crepe/api/Point.h
@@ -1,7 +1,5 @@
#pragma once
-
-
namespace crepe::api {
class Point {
@@ -10,5 +8,4 @@ public:
double y;
};
-
-}
+} // namespace crepe::api
diff --git a/src/crepe/api/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp
index 30a2cff..b35d5b8 100644
--- a/src/crepe/api/Rigidbody.cpp
+++ b/src/crepe/api/Rigidbody.cpp
@@ -2,6 +2,7 @@
using namespace crepe::api;
-Rigidbody::Rigidbody(uint32_t gameObjectId,int mass, int gravityScale, BodyType bodyType)
- : Component(gameObjectId), mass(mass), gravity_scale(gravityScale), body_type(bodyType) {}
-
+Rigidbody::Rigidbody(uint32_t gameObjectId, int mass, int gravityScale,
+ BodyType bodyType)
+ : Component(gameObjectId), mass(mass), gravity_scale(gravityScale),
+ body_type(bodyType) {}
diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h
index e59e217..dc242c1 100644
--- a/src/crepe/api/Rigidbody.h
+++ b/src/crepe/api/Rigidbody.h
@@ -3,19 +3,20 @@
#include "../Component.h"
#include <cstdint>
-namespace crepe::api{
+namespace crepe::api {
enum class BodyType {
- Static, // Does not move (e.g. walls, ground ...)
- Dynamic, // Moves and responds to forces (e.g. player, physics objects ...)
- Kinematic // Moves but does not respond to forces (e.g. moving platforms ...)
+ STATIC, // Does not move (e.g. walls, ground ...)
+ DYNAMIC, // Moves and responds to forces (e.g. player, physics objects ...)
+ KINEMATIC // Moves but does not respond to forces (e.g. moving platforms ...)
};
class Rigidbody : public Component {
public:
- Rigidbody(uint32_t gameObjectId,int mass, int gravityScale, BodyType bodyType);
+ Rigidbody(uint32_t gameObjectId, int mass, int gravityScale,
+ BodyType bodyType);
int32_t velocity_x;
- int32_t velocity_y;
+ int32_t velocity_y;
int mass;
int gravity_scale;
BodyType body_type;
diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp
index 3cc263e..cdece28 100644
--- a/src/crepe/api/Sprite.cpp
+++ b/src/crepe/api/Sprite.cpp
@@ -13,7 +13,8 @@ using namespace crepe;
using namespace crepe::api;
Sprite::Sprite(uint32_t id, shared_ptr<Texture> image, const Color & color,
- const flip_settings & flip) : Component(id), color(color), flip(flip), sprite_image(image) {
+ const FlipSettings & flip)
+ : Component(id), color(color), flip(flip), sprite_image(image) {
dbg_trace();
}
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h
index 3d9e911..7a701e3 100644
--- a/src/crepe/api/Sprite.h
+++ b/src/crepe/api/Sprite.h
@@ -7,24 +7,23 @@
#include <cstdint>
#include <memory>
-
namespace crepe::api {
-struct flip_settings{
- bool flip_x: 1;
- bool flip_y : 1;
+struct FlipSettings {
+ bool flip_x = 1;
+ bool flip_y = 1;
};
class Sprite : public Component {
-
+
public:
- Sprite(uint32_t game_id, std::shared_ptr<Texture> image, const Color& color, const flip_settings& flip );
+ Sprite(uint32_t game_id, std::shared_ptr<Texture> image,
+ const Color & color, const FlipSettings & flip);
~Sprite();
std::shared_ptr<Texture> sprite_image;
Color color;
- flip_settings flip;
+ FlipSettings flip;
uint8_t sorting_in_layer;
uint8_t order_in_layer;
-
};
-}
+} // namespace crepe::api
diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp
index ba06c6d..c755fa9 100644
--- a/src/crepe/api/Texture.cpp
+++ b/src/crepe/api/Texture.cpp
@@ -28,5 +28,4 @@ Texture::~Texture() {
void Texture::load(std::unique_ptr<Asset> res) {
SdlContext & ctx = SdlContext::get_instance();
m_texture = ctx.texture_from_path(res->canonical());
-
}
diff --git a/src/crepe/api/Texture.h b/src/crepe/api/Texture.h
index b376b44..6d3fb40 100644
--- a/src/crepe/api/Texture.h
+++ b/src/crepe/api/Texture.h
@@ -4,9 +4,8 @@
#include <SDL2/SDL_render.h>
#include <memory>
-
namespace crepe {
- class SdlContext;
+class SdlContext;
}
namespace crepe::api {
@@ -18,15 +17,13 @@ public:
Texture(std::unique_ptr<Asset> res);
~Texture();
-
private:
void load(std::unique_ptr<Asset> res);
-
private:
SDL_Texture * m_texture = nullptr;
friend class crepe::SdlContext;
};
-} // namespace crepe
+} // namespace crepe::api
diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h
index 29e2a3d..c9d46c5 100644
--- a/src/crepe/api/Transform.h
+++ b/src/crepe/api/Transform.h
@@ -7,7 +7,7 @@ namespace crepe::api {
class Transform : public Component {
public:
- Transform(uint32_t id, Point&, double, double);
+ Transform(uint32_t id, Point &, double, double);
~Transform();
Point position; // Translation (shift)
double rotation; // Rotation, in radians
diff --git a/src/crepe/util/log.cpp b/src/crepe/util/log.cpp
index 0c2ce1e..b869aad 100644
--- a/src/crepe/util/log.cpp
+++ b/src/crepe/util/log.cpp
@@ -9,13 +9,13 @@
using namespace crepe::util;
static const char * const LOG_PREFIX[] = {
- [log_level::DEBUG] = "[DBG] ",
- [log_level::INFO] = "[INFO] ",
- [log_level::WARNING] = "[WARN] ",
- [log_level::ERROR] = "[ERR] ",
+ [LogLevel::DEBUG] = "[DBG] ",
+ [LogLevel::INFO] = "[INFO] ",
+ [LogLevel::WARNING] = "[WARN] ",
+ [LogLevel::ERROR] = "[ERR] ",
};
-static void log(enum log_level level, const std::string & msg) {
+static void log(LogLevel level, const std::string & msg) {
using namespace std;
string out = string(LOG_PREFIX[level]) + msg;
if (!out.ends_with("\n")) out += "\n";
@@ -28,11 +28,11 @@ static void log(enum log_level level, const std::string & msg) {
void crepe::util::logf(const char * fmt, ...) {
va_list args;
va_start(args, fmt);
- log(log_level::DEBUG, va_stringf(args, fmt));
+ log(LogLevel::DEBUG, va_stringf(args, fmt));
va_end(args);
}
-void crepe::util::logf(log_level level, const char * fmt, ...) {
+void crepe::util::logf(LogLevel level, const char * fmt, ...) {
va_list args;
va_start(args, fmt);
log(level, va_stringf(args, fmt));
diff --git a/src/crepe/util/log.h b/src/crepe/util/log.h
index 3e36f0a..f8e4f00 100644
--- a/src/crepe/util/log.h
+++ b/src/crepe/util/log.h
@@ -7,7 +7,7 @@
// utility macros
#define _crepe_logf_here(fmt, ...) \
- crepe::util::logf(util::log_level::DEBUG, "%s%s (%s:%d)%s" fmt "\n", \
+ crepe::util::logf(util::LogLevel::DEBUG, "%s%s (%s:%d)%s" fmt "\n", \
crepe::util::color::FG_WHITE, __PRETTY_FUNCTION__, \
__FILE_NAME__, __LINE__, crepe::util::color::RESET, \
__VA_ARGS__)
@@ -23,7 +23,7 @@
namespace crepe::util {
-enum log_level {
+enum LogLevel {
DEBUG,
INFO,
WARNING,
@@ -31,6 +31,6 @@ enum log_level {
};
void logf(const char * fmt, ...);
-void logf(enum log_level level, const char * fmt, ...);
+void logf(enum LogLevel level, const char * fmt, ...);
} // namespace crepe::util
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)) {