diff options
-rw-r--r-- | .clang-format | 1 | ||||
-rw-r--r-- | mwe/ecs-homemade/src/Components.cpp | 4 | ||||
-rw-r--r-- | mwe/ecs-homemade/src/GameObjectMax.cpp | 6 | ||||
-rw-r--r-- | mwe/ecs-memory-efficient/inc/ContiguousContainer.hpp | 3 | ||||
-rw-r--r-- | mwe/ecs-memory-efficient/src/Components.cpp | 4 | ||||
-rw-r--r-- | mwe/ecs-memory-efficient/src/GameObjectMax.cpp | 6 | ||||
-rw-r--r-- | mwe/events/include/customTypes.h | 4 | ||||
-rw-r--r-- | mwe/events/include/eventHandler.h | 3 | ||||
-rw-r--r-- | mwe/events/src/event.cpp | 31 | ||||
-rw-r--r-- | mwe/events/src/main.cpp | 4 | ||||
-rw-r--r-- | mwe/events/src/uiObject.cpp | 13 | ||||
-rw-r--r-- | mwe/gameloop/src/gameObject.cpp | 7 | ||||
-rw-r--r-- | src/crepe/Exception.cpp | 3 | ||||
-rw-r--r-- | src/crepe/Exception.h | 2 | ||||
-rw-r--r-- | src/crepe/api/AudioSource.cpp | 23 | ||||
-rw-r--r-- | src/crepe/api/AudioSource.h | 39 | ||||
-rw-r--r-- | src/crepe/api/CircleCollider.h | 3 | ||||
-rw-r--r-- | src/crepe/api/Metadata.cpp | 4 | ||||
-rw-r--r-- | src/crepe/api/ParticleEmitter.cpp | 11 | ||||
-rw-r--r-- | src/crepe/api/Rigidbody.cpp | 3 | ||||
-rw-r--r-- | src/crepe/api/Sprite.cpp | 5 | ||||
-rw-r--r-- | src/crepe/api/Transform.cpp | 5 | ||||
-rw-r--r-- | src/crepe/facade/DB.cpp | 12 | ||||
-rw-r--r-- | src/makefile | 50 |
24 files changed, 99 insertions, 147 deletions
diff --git a/.clang-format b/.clang-format index 3ae6c28..8ce4033 100644 --- a/.clang-format +++ b/.clang-format @@ -23,6 +23,7 @@ ReflowComments: false AlignEscapedNewlines: DontAlign BreakBeforeBinaryOperators: All AlwaysBreakTemplateDeclarations: Yes +PackConstructorInitializers: CurrentLine ... # vim: ft=yaml diff --git a/mwe/ecs-homemade/src/Components.cpp b/mwe/ecs-homemade/src/Components.cpp index de8753e..0d62bd5 100644 --- a/mwe/ecs-homemade/src/Components.cpp +++ b/mwe/ecs-homemade/src/Components.cpp @@ -6,7 +6,9 @@ Component::Component() : mActive(true) {} Sprite::Sprite(std::string path) : mPath(path) {} Rigidbody::Rigidbody(int mass, int gravityScale, int bodyType) - : mMass(mass), mGravityScale(gravityScale), mBodyType(bodyType) {} + : mMass(mass), + mGravityScale(gravityScale), + mBodyType(bodyType) {} Colider::Colider(int size) : mSize(size) {} diff --git a/mwe/ecs-homemade/src/GameObjectMax.cpp b/mwe/ecs-homemade/src/GameObjectMax.cpp index b0c5af7..753c8e2 100644 --- a/mwe/ecs-homemade/src/GameObjectMax.cpp +++ b/mwe/ecs-homemade/src/GameObjectMax.cpp @@ -4,4 +4,8 @@ GameObject::GameObject(std::uint32_t id, std::string name, std::string tag, int layer) - : mId(id), mName(name), mTag(tag), mActive(true), mLayer(layer) {} + : mId(id), + mName(name), + mTag(tag), + mActive(true), + mLayer(layer) {} diff --git a/mwe/ecs-memory-efficient/inc/ContiguousContainer.hpp b/mwe/ecs-memory-efficient/inc/ContiguousContainer.hpp index 408d5aa..ff8fde4 100644 --- a/mwe/ecs-memory-efficient/inc/ContiguousContainer.hpp +++ b/mwe/ecs-memory-efficient/inc/ContiguousContainer.hpp @@ -1,5 +1,6 @@ template <typename T> -ContiguousContainer<T>::ContiguousContainer() : mSize(0), mCapacity(10) { +ContiguousContainer<T>::ContiguousContainer() : mSize(0), + mCapacity(10) { // Allocate memory for 10 objects initially mData = static_cast<T *>(malloc(mCapacity * sizeof(T))); if (!mData) { diff --git a/mwe/ecs-memory-efficient/src/Components.cpp b/mwe/ecs-memory-efficient/src/Components.cpp index c8347b3..2ec8609 100644 --- a/mwe/ecs-memory-efficient/src/Components.cpp +++ b/mwe/ecs-memory-efficient/src/Components.cpp @@ -6,6 +6,8 @@ Component::Component() : mActive(true) {} Sprite::Sprite(std::string path) : mPath(path) {} Rigidbody::Rigidbody(int mass, int gravityScale, int bodyType) - : mMass(mass), mGravityScale(gravityScale), mBodyType(bodyType) {} + : mMass(mass), + mGravityScale(gravityScale), + mBodyType(bodyType) {} Colider::Colider(int size) : mSize(size) {} diff --git a/mwe/ecs-memory-efficient/src/GameObjectMax.cpp b/mwe/ecs-memory-efficient/src/GameObjectMax.cpp index b0c5af7..753c8e2 100644 --- a/mwe/ecs-memory-efficient/src/GameObjectMax.cpp +++ b/mwe/ecs-memory-efficient/src/GameObjectMax.cpp @@ -4,4 +4,8 @@ GameObject::GameObject(std::uint32_t id, std::string name, std::string tag, int layer) - : mId(id), mName(name), mTag(tag), mActive(true), mLayer(layer) {} + : mId(id), + mName(name), + mTag(tag), + mActive(true), + mLayer(layer) {} diff --git a/mwe/events/include/customTypes.h b/mwe/events/include/customTypes.h index a5d8dc9..415b989 100644 --- a/mwe/events/include/customTypes.h +++ b/mwe/events/include/customTypes.h @@ -33,6 +33,8 @@ struct Collision { // Constructor to initialize a Collision Collision(int idA, int idB, const Vector2 & point, const Vector2 & normal, float depth) - : objectIdA(idA), objectIdB(idB), contactPoint(point), + : objectIdA(idA), + objectIdB(idB), + contactPoint(point), contactNormal(normal) {} }; diff --git a/mwe/events/include/eventHandler.h b/mwe/events/include/eventHandler.h index aa8f63b..3a83b15 100644 --- a/mwe/events/include/eventHandler.h +++ b/mwe/events/include/eventHandler.h @@ -24,7 +24,8 @@ class EventHandlerWrapper : public IEventHandlerWrapper { public: explicit EventHandlerWrapper(const EventHandler<EventType> & handler, const bool destroyOnSuccess = false) - : m_handler(handler), m_handlerType(m_handler.target_type().name()), + : m_handler(handler), + m_handlerType(m_handler.target_type().name()), m_destroyOnSuccess(destroyOnSuccess) { // std::cout << m_handlerType << std::endl; } diff --git a/mwe/events/src/event.cpp b/mwe/events/src/event.cpp index 0c9f3ed..8ffa0b1 100644 --- a/mwe/events/src/event.cpp +++ b/mwe/events/src/event.cpp @@ -23,7 +23,9 @@ void Event::markHandled() { isHandled = true; } // KeyPressedEvent class methods KeyPressedEvent::KeyPressedEvent(int keycode) - : Event("KeyPressedEvent"), key(keycode), repeatCount(0) {} + : Event("KeyPressedEvent"), + key(keycode), + repeatCount(0) {} Keycode KeyPressedEvent::getKeyCode() const { return key; } @@ -31,13 +33,16 @@ int KeyPressedEvent::getRepeatCount() const { return repeatCount; } // KeyReleasedEvent class methods KeyReleasedEvent::KeyReleasedEvent(int keycode) - : Event("KeyReleasedEvent"), key(keycode) {} + : Event("KeyReleasedEvent"), + key(keycode) {} Keycode KeyReleasedEvent::getKeyCode() const { return key; } // MousePressedEvent class methods MousePressedEvent::MousePressedEvent(int mouseX, int mouseY) - : Event("MousePressedEvent"), mouseX(mouseX), mouseY(mouseY) {} + : Event("MousePressedEvent"), + mouseX(mouseX), + mouseY(mouseY) {} std::pair<int, int> MousePressedEvent::getMousePosition() const { return {mouseX, mouseY}; @@ -45,26 +50,36 @@ std::pair<int, int> MousePressedEvent::getMousePosition() const { //Collision event CollisionEvent::CollisionEvent(Collision collision) - : collisionData(collision), Event("CollisionEvent") {} + : collisionData(collision), + Event("CollisionEvent") {} Collision CollisionEvent::getCollisionData() const { return this->collisionData; } TextSubmitEvent::TextSubmitEvent(std::string text) - : text(text), Event("TextSubmitEvent") {} + : text(text), + Event("TextSubmitEvent") {} std::string TextSubmitEvent::getText() const { return this->text; } MouseReleasedEvent::MouseReleasedEvent(int x, int y, MouseButton button) - : mouseX(x), mouseY(y), button(button), Event("MouseReleased") {} + : mouseX(x), + mouseY(y), + button(button), + Event("MouseReleased") {} std::pair<int, int> MouseReleasedEvent::getMousePosition() const { return {mouseX, mouseY}; } MouseClickEvent::MouseClickEvent(int x, int y, MouseButton button) - : mouseX(x), mouseY(y), button(button), Event("MouseClickEvent") {} + : mouseX(x), + mouseY(y), + button(button), + Event("MouseClickEvent") {} MouseMovedEvent::MouseMovedEvent(int x, int y) - : mouseX(x), mouseY(y), Event("MouseMovedEvent") {} + : mouseX(x), + mouseY(y), + Event("MouseMovedEvent") {} std::pair<int, int> MouseClickEvent::getMousePosition() const { return {mouseX, mouseY}; } diff --git a/mwe/events/src/main.cpp b/mwe/events/src/main.cpp index d49cf74..f4e7390 100644 --- a/mwe/events/src/main.cpp +++ b/mwe/events/src/main.cpp @@ -11,7 +11,9 @@ class PlayerDamagedEvent : public Event { public: PlayerDamagedEvent(int damage, int playerID) - : Event("PlayerDamaged"), damage(damage), playerID(playerID) {} + : Event("PlayerDamaged"), + damage(damage), + playerID(playerID) {} REGISTER_EVENT_TYPE(PlayerDamagedEvent); diff --git a/mwe/events/src/uiObject.cpp b/mwe/events/src/uiObject.cpp index 8405469..947d1a2 100644 --- a/mwe/events/src/uiObject.cpp +++ b/mwe/events/src/uiObject.cpp @@ -7,7 +7,9 @@ UIObject::UIObject(int width, int height) : width(width), height(height) {} Button::Button(int width, int height) : UIObject(width, height) {} Text::Text(int width, int height) - : UIObject(width, height), size(12), font(nullptr), + : UIObject(width, height), + size(12), + font(nullptr), color{255, 255, 255} { // Default size and color alignment.horizontal = Alignment::Horizontal::CENTER; alignment.vertical = Alignment::Vertical::MIDDLE; @@ -15,8 +17,13 @@ Text::Text(int width, int height) } TextInput::TextInput(int width, int height) - : UIObject(width, height), textBuffer(""), placeholder(""), isActive(false), - textColor{255, 255, 255}, backgroundColor{0, 0, 0}, maxLength(100), + : UIObject(width, height), + textBuffer(""), + placeholder(""), + isActive(false), + textColor{255, 255, 255}, + backgroundColor{0, 0, 0}, + maxLength(100), font(nullptr) { alignment.horizontal = Alignment::Horizontal::LEFT; alignment.vertical = Alignment::Vertical::TOP; diff --git a/mwe/gameloop/src/gameObject.cpp b/mwe/gameloop/src/gameObject.cpp index 78217c4..b33dc78 100644 --- a/mwe/gameloop/src/gameObject.cpp +++ b/mwe/gameloop/src/gameObject.cpp @@ -26,5 +26,10 @@ void GameObject::setVelY(float value) { velY = value; } GameObject::GameObject(std::string name, float x, float y, float width, float height, float velX, float velY) - : name(name), x(x), y(y), width(width), height(height), velX(velX), + : name(name), + x(x), + y(y), + width(width), + height(height), + velX(velX), velY(velY) {} diff --git a/src/crepe/Exception.cpp b/src/crepe/Exception.cpp index dab8f2e..a1fa765 100644 --- a/src/crepe/Exception.cpp +++ b/src/crepe/Exception.cpp @@ -6,7 +6,7 @@ using namespace std; using namespace crepe; -const char * Exception::what() { return error.c_str(); } +const char * Exception::what() const noexcept { return error.c_str(); } Exception::Exception(const char * fmt, ...) { va_list args; @@ -14,3 +14,4 @@ Exception::Exception(const char * fmt, ...) { this->error = va_stringf(args, fmt); va_end(args); } + diff --git a/src/crepe/Exception.h b/src/crepe/Exception.h index 6473043..80af068 100644 --- a/src/crepe/Exception.h +++ b/src/crepe/Exception.h @@ -11,7 +11,7 @@ public: //! printf Exception(const char * fmt, ...); //! Get formatted error message - const char * what(); + const char * what() const noexcept; protected: Exception() = default; diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp deleted file mode 100644 index 63fd0d7..0000000 --- a/src/crepe/api/AudioSource.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include <memory> - -#include "../facade/Sound.h" - -#include "AudioSource.h" - -using namespace crepe; - -AudioSource::AudioSource(std::unique_ptr<Asset> audio_clip) { - this->sound = std::make_unique<crepe::Sound>(std::move(audio_clip)); -} - -void AudioSource::play() { return this->play(false); } - -void AudioSource::play(bool looping) { - this->sound->set_looping(looping); - this->sound->play(); -} - -void AudioSource::stop() { - this->sound->pause(); - this->sound->rewind(); -} diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h deleted file mode 100644 index 1e24ae8..0000000 --- a/src/crepe/api/AudioSource.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include <memory> - -#include "../Asset.h" -#include "../Component.h" - -namespace crepe { - -class Sound; - -//! Audio source component -class AudioSource : public Component { -public: - AudioSource(std::unique_ptr<Asset> audio_clip); - virtual ~AudioSource() = default; - -public: - //! Start or resume this audio source - void play(); - void play(bool looping); - //! Stop this audio source - void stop(); - -public: - //! Sample file location - std::unique_ptr<Asset> audio_clip; - //! TODO: ????? - bool play_on_awake; - //! Repeat the current audio clip during playback - bool loop; - //! Normalized volume (0.0 - 1.0) - float volume; - -private: - std::unique_ptr<Sound> sound; -}; - -} // namespace crepe diff --git a/src/crepe/api/CircleCollider.h b/src/crepe/api/CircleCollider.h index caa7e43..e77a592 100644 --- a/src/crepe/api/CircleCollider.h +++ b/src/crepe/api/CircleCollider.h @@ -6,7 +6,8 @@ namespace crepe { class CircleCollider : public Collider { public: CircleCollider(game_object_id_t game_object_id, int radius) - : Collider(game_object_id), radius(radius) {} + : Collider(game_object_id), + radius(radius) {} int radius; }; diff --git a/src/crepe/api/Metadata.cpp b/src/crepe/api/Metadata.cpp index 76f11d7..d421de5 100644 --- a/src/crepe/api/Metadata.cpp +++ b/src/crepe/api/Metadata.cpp @@ -4,4 +4,6 @@ using namespace crepe; using namespace std; Metadata::Metadata(game_object_id_t id, const string & name, const string & tag) - : Component(id), name(name), tag(tag) {} + : Component(id), + name(name), + tag(tag) {} diff --git a/src/crepe/api/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp index 3b2e2f2..0bc2197 100644 --- a/src/crepe/api/ParticleEmitter.cpp +++ b/src/crepe/api/ParticleEmitter.cpp @@ -11,9 +11,14 @@ ParticleEmitter::ParticleEmitter(game_object_id_t id, uint32_t max_particles, uint32_t speed_offset, uint32_t angle, uint32_t angleOffset, float begin_lifespan, float end_lifespan) - : Component(id), max_particles(max_particles), emission_rate(emission_rate), - speed(speed), speed_offset(speed_offset), position{0, 0}, - begin_lifespan(begin_lifespan), end_lifespan(end_lifespan) { + : Component(id), + max_particles(max_particles), + emission_rate(emission_rate), + speed(speed), + speed_offset(speed_offset), + position{0, 0}, + begin_lifespan(begin_lifespan), + end_lifespan(end_lifespan) { std::srand( static_cast<uint32_t>(std::time(nullptr))); // initialize random seed std::cout << "Create emitter" << std::endl; diff --git a/src/crepe/api/Rigidbody.cpp b/src/crepe/api/Rigidbody.cpp index cbf1325..3bf1c5b 100644 --- a/src/crepe/api/Rigidbody.cpp +++ b/src/crepe/api/Rigidbody.cpp @@ -3,7 +3,8 @@ using namespace crepe; crepe::Rigidbody::Rigidbody(uint32_t game_object_id, const Data & data) - : Component(game_object_id), data(data) {} + : Component(game_object_id), + data(data) {} void crepe::Rigidbody::add_force_linear(const Vector2 & force) { this->data.linear_velocity += force; diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index f9cd761..6f0433f 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -12,7 +12,10 @@ using namespace crepe; Sprite::Sprite(game_object_id_t id, const shared_ptr<Texture> image, const Color & color, const FlipSettings & flip) - : Component(id), color(color), flip(flip), sprite_image(image) { + : Component(id), + color(color), + flip(flip), + sprite_image(image) { dbg_trace(); this->sprite_rect.w = sprite_image->get_width(); diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index a244bc5..e401120 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -6,6 +6,9 @@ using namespace crepe; Transform::Transform(game_object_id_t id, const Vector2 & point, double rotation, double scale) - : Component(id), position(point), rotation(rotation), scale(scale) { + : Component(id), + position(point), + rotation(rotation), + scale(scale) { dbg_trace(); } diff --git a/src/crepe/facade/DB.cpp b/src/crepe/facade/DB.cpp index 0a2f455..0805a08 100644 --- a/src/crepe/facade/DB.cpp +++ b/src/crepe/facade/DB.cpp @@ -19,15 +19,14 @@ DB::DB(const string & path) { this->db = {db, [](libdb::DB * db) { db->close(db, 0); }}; // load or create database file - if ((ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL, - libdb::DB_BTREE, DB_CREATE, 0)) - != 0) - throw Exception("db->open: %s", libdb::db_strerror(ret)); + ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL, + libdb::DB_BTREE, DB_CREATE, 0); + if (ret != 0) throw Exception("db->open: %s", libdb::db_strerror(ret)); // create cursor libdb::DBC * cursor; - if ((ret = this->db->cursor(this->db.get(), NULL, &cursor, 0)) != 0) - throw Exception("db->cursor: %s", libdb::db_strerror(ret)); + ret = this->db->cursor(this->db.get(), NULL, &cursor, 0); + if (ret != 0) throw Exception("db->cursor: %s", libdb::db_strerror(ret)); this->cursor = {cursor, [](libdb::DBC * cursor) { cursor->close(cursor); }}; } @@ -64,3 +63,4 @@ bool DB::has(const std::string & key) noexcept { } return true; } + diff --git a/src/makefile b/src/makefile index b9c44c8..778e2c9 100644 --- a/src/makefile +++ b/src/makefile @@ -15,87 +15,39 @@ # pull request. Make sure to ask someone to review the code standards for # each ENTIRE FILE in this pull request. -LOEK += crepe/Asset.cpp -LOEK += crepe/Asset.h TODO += crepe/Collider.cpp TODO += crepe/Collider.h -MAX += crepe/Component.cpp -MAX += crepe/Component.h -MAX += crepe/ComponentManager.cpp -MAX += crepe/ComponentManager.h -MAX += crepe/ComponentManager.hpp -MAX += crepe/api/Metadata.cpp -MAX += crepe/api/Metadata.h TODO += crepe/Particle.cpp TODO += crepe/Particle.h TODO += crepe/Position.h TODO += crepe/api/AssetManager.cpp TODO += crepe/api/AssetManager.h TODO += crepe/api/AssetManager.hpp -LOEK += crepe/api/AudioSource.cpp -LOEK += crepe/api/AudioSource.h -LOEK += crepe/api/BehaviorScript.cpp -LOEK += crepe/api/BehaviorScript.h -LOEK += crepe/api/BehaviorScript.hpp TODO += crepe/api/CircleCollider.h TODO += crepe/api/Color.cpp TODO += crepe/api/Color.h -LOEK += crepe/api/Config.h -MAX += crepe/api/GameObject.cpp -MAX += crepe/api/GameObject.h -MAX += crepe/api/GameObject.hpp TODO += crepe/api/ParticleEmitter.cpp TODO += crepe/api/ParticleEmitter.h TODO += crepe/api/Vector2.h TODO += crepe/api/Vector2.cpp -JARO += crepe/api/Rigidbody.cpp -JARO += crepe/api/Rigidbody.h -LOEK += crepe/api/Script.cpp -LOEK += crepe/api/Script.h -LOEK += crepe/api/Script.hpp TODO += crepe/api/Sprite.cpp TODO += crepe/api/Sprite.h TODO += crepe/api/Texture.cpp TODO += crepe/api/Texture.h -MAX += crepe/api/Transform.cpp -MAX += crepe/api/Transform.h TODO += crepe/facade/SDLContext.cpp TODO += crepe/facade/SDLContext.h -LOEK += crepe/facade/Sound.cpp -LOEK += crepe/facade/Sound.h -LOEK += crepe/facade/SoundContext.cpp -LOEK += crepe/facade/SoundContext.h TODO += crepe/system/CollisionSystem.cpp TODO += crepe/system/CollisionSystem.h TODO += crepe/system/ParticleSystem.cpp TODO += crepe/system/ParticleSystem.h -JARO += crepe/system/PhysicsSystem.cpp -JARO += crepe/system/PhysicsSystem.h TODO += crepe/system/RenderSystem.cpp TODO += crepe/system/RenderSystem.h -LOEK += crepe/system/ScriptSystem.cpp -LOEK += crepe/system/ScriptSystem.h -LOEK += crepe/system/System.h -LOEK += crepe/util/LogColor.cpp -LOEK += crepe/util/LogColor.h -LOEK += crepe/util/fmt.cpp -LOEK += crepe/util/fmt.h -LOEK += crepe/util/log.cpp -LOEK += crepe/util/log.h TODO += example/asset_manager.cpp -LOEK += example/audio_internal.cpp TODO += example/components_internal.cpp -MAX += example/ecs.cpp -LOEK += example/log.cpp TODO += example/particle.cpp -JARO += example/physics.cpp TODO += example/rendering.cpp -LOEK += example/script.cpp -LOEK += test/audio.cpp -LOEK += test/dummy.cpp -JARO += test/PhysicsTest.cpp -FMT := $(JARO) #<<< CHANGE THIS TO YOUR NAME FOR STEP 2 +FMT := $(LOEK) #<<< CHANGE THIS TO YOUR NAME FOR STEP 2 format: FORCE clang-tidy -p build/compile_commands.json --fix-errors $(FMT) |