aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-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
16 files changed, 114 insertions, 135 deletions
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