From f51ddfac7b8948a43a40894185238c8a1ceeb5c4 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 15 Nov 2024 17:25:12 +0100 Subject: wrap lines at column 95 instead of 80 --- src/crepe/api/LoopTimer.h | 144 +++++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 73 deletions(-) (limited to 'src/crepe/api/LoopTimer.h') diff --git a/src/crepe/api/LoopTimer.h b/src/crepe/api/LoopTimer.h index 85687be..c3c5631 100644 --- a/src/crepe/api/LoopTimer.h +++ b/src/crepe/api/LoopTimer.h @@ -8,117 +8,117 @@ namespace crepe { class LoopTimer { public: /** - * \brief Get the singleton instance of LoopTimer. - * - * \return A reference to the LoopTimer instance. - */ + * \brief Get the singleton instance of LoopTimer. + * + * \return A reference to the LoopTimer instance. + */ static LoopTimer & get_instance(); /** - * \brief Get the current delta time for the current frame. - * - * \return Delta time in seconds since the last frame. - */ + * \brief Get the current delta time for the current frame. + * + * \return Delta time in seconds since the last frame. + */ double get_delta_time() const; /** - * \brief Get the current game time. - * - * \note The current game time may vary from real-world elapsed time. - * It is the cumulative sum of each frame's delta time. - * - * \return Elapsed game time in seconds. - */ + * \brief Get the current game time. + * + * \note The current game time may vary from real-world elapsed time. It is the cumulative + * sum of each frame's delta time. + * + * \return Elapsed game time in seconds. + */ double get_current_time() const; /** - * \brief Set the target frames per second (FPS). - * - * \param fps The desired frames rendered per second. - */ + * \brief Set the target frames per second (FPS). + * + * \param fps The desired frames rendered per second. + */ void set_fps(int fps); /** - * \brief Get the current frames per second (FPS). - * - * \return Current FPS. - */ + * \brief Get the current frames per second (FPS). + * + * \return Current FPS. + */ int get_fps() const; /** - * \brief Get the current game scale. - * - * \return The current game scale, where 0 = paused, 1 = normal speed, and values > 1 speed up the game. - */ + * \brief Get the current game scale. + * + * \return The current game scale, where 0 = paused, 1 = normal speed, and values > 1 speed + * up the game. + */ double get_game_scale() const; /** - * \brief Set the game scale. - * - * \param game_scale The desired game scale (0 = pause, 1 = normal speed, > 1 = speed up). - */ + * \brief Set the game scale. + * + * \param game_scale The desired game scale (0 = pause, 1 = normal speed, > 1 = speed up). + */ void set_game_scale(double game_scale); private: friend class LoopManager; /** - * \brief Start the loop timer. - * - * Initializes the timer to begin tracking frame times. - */ + * \brief Start the loop timer. + * + * Initializes the timer to begin tracking frame times. + */ void start(); /** - * \brief Enforce the frame rate limit. - * - * Ensures that the game loop does not exceed the target FPS by delaying - * frame updates as necessary. - */ + * \brief Enforce the frame rate limit. + * + * Ensures that the game loop does not exceed the target FPS by delaying frame updates as + * necessary. + */ void enforce_frame_rate(); /** - * \brief Get the fixed delta time for consistent updates. - * - * Fixed delta time is used for operations that require uniform time steps, - * such as physics calculations. - * - * \return Fixed delta time in seconds. - */ + * \brief Get the fixed delta time for consistent updates. + * + * Fixed delta time is used for operations that require uniform time steps, such as physics + * calculations. + * + * \return Fixed delta time in seconds. + */ double get_fixed_delta_time() const; /** - * \brief Get the accumulated lag in the game loop. - * - * Lag represents the difference between the target frame time and the - * actual frame time, useful for managing fixed update intervals. - * - * \return Accumulated lag in seconds. - */ + * \brief Get the accumulated lag in the game loop. + * + * Lag represents the difference between the target frame time and the actual frame time, + * useful for managing fixed update intervals. + * + * \return Accumulated lag in seconds. + */ double get_lag() const; /** - * \brief Construct a new LoopTimer object. - * - * Private constructor for singleton pattern to restrict instantiation - * outside the class. - */ + * \brief Construct a new LoopTimer object. + * + * Private constructor for singleton pattern to restrict instantiation outside the class. + */ LoopTimer(); /** - * \brief Update the timer to the current frame. - * - * Calculates and updates the delta time for the current frame and adds it to - * the cumulative game time. - */ + * \brief Update the timer to the current frame. + * + * Calculates and updates the delta time for the current frame and adds it to the cumulative + * game time. + */ void update(); /** - * \brief Advance the game loop by a fixed update interval. - * - * This method progresses the game state by a consistent, fixed time step, - * allowing for stable updates independent of frame rate fluctuations. - */ + * \brief Advance the game loop by a fixed update interval. + * + * This method progresses the game state by a consistent, fixed time step, allowing for + * stable updates independent of frame rate fluctuations. + */ void advance_fixed_update(); private: @@ -131,11 +131,9 @@ private: //! Delta time for the current frame in seconds std::chrono::duration delta_time{0.0}; //! Target time per frame in seconds - std::chrono::duration frame_target_time - = std::chrono::seconds(1) / fps; + std::chrono::duration frame_target_time = std::chrono::seconds(1) / fps; //! Fixed delta time for fixed updates in seconds - std::chrono::duration fixed_delta_time - = std::chrono::seconds(1) / 50; + std::chrono::duration fixed_delta_time = std::chrono::seconds(1) / 50; //! Total elapsed game time in seconds std::chrono::duration elapsed_time{0.0}; //! Total elapsed time for fixed updates in seconds -- cgit v1.2.3 From 5bee4515c1089ce3499bc3b74780db94f0c02306 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 15 Nov 2024 20:26:26 +0100 Subject: process feedback on #26 --- src/crepe/CMakeLists.txt | 3 --- src/crepe/Component.h | 2 ++ src/crepe/ComponentManager.cpp | 11 +++++------ src/crepe/ComponentManager.h | 3 ++- src/crepe/ComponentManager.hpp | 1 - src/crepe/Exception.cpp | 8 -------- src/crepe/Exception.h | 31 ------------------------------- src/crepe/Exception.hpp | 12 ------------ src/crepe/api/Animator.cpp | 2 -- src/crepe/api/Animator.h | 2 -- src/crepe/api/BehaviorScript.h | 3 +-- src/crepe/api/CMakeLists.txt | 1 - src/crepe/api/Camera.h | 2 -- src/crepe/api/Config.h | 17 +++++++++++------ src/crepe/api/LoopManager.hpp | 4 ++-- src/crepe/api/LoopTimer.h | 1 - src/crepe/api/Rigidbody.h | 2 -- src/crepe/api/SceneManager.h | 3 --- src/crepe/api/Script.cpp | 3 --- src/crepe/api/Script.hpp | 8 +++----- src/crepe/api/Sprite.h | 1 - src/crepe/api/Transform.h | 8 +++++--- src/crepe/facade/DB.cpp | 24 +++++++++++++++--------- src/crepe/facade/DB.h | 7 ++++--- src/crepe/facade/SDLContext.cpp | 5 ++--- src/crepe/util/Log.cpp | 9 ++++----- src/crepe/util/Log.h | 2 ++ src/crepe/util/LogColor.cpp | 1 + src/crepe/util/LogColor.h | 24 +++++++++++++++++++++++- src/example/particles.cpp | 3 ++- 30 files changed, 84 insertions(+), 119 deletions(-) delete mode 100644 src/crepe/Exception.cpp delete mode 100644 src/crepe/Exception.h delete mode 100644 src/crepe/Exception.hpp delete mode 100644 src/crepe/api/Script.cpp (limited to 'src/crepe/api/LoopTimer.h') diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index 52a781e..3b05742 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -4,7 +4,6 @@ target_sources(crepe PUBLIC ComponentManager.cpp Component.cpp Collider.cpp - Exception.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES @@ -15,8 +14,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES Collider.h ValueBroker.h ValueBroker.hpp - Exception.h - Exception.hpp ) add_subdirectory(api) diff --git a/src/crepe/Component.h b/src/crepe/Component.h index 12c10cb..670446f 100644 --- a/src/crepe/Component.h +++ b/src/crepe/Component.h @@ -26,6 +26,8 @@ protected: Component(game_object_id_t id); //! Only the ComponentManager can create components friend class ComponentManager; +public: + virtual ~Component() = default; public: /** diff --git a/src/crepe/ComponentManager.cpp b/src/crepe/ComponentManager.cpp index 7af0380..67c6fc7 100644 --- a/src/crepe/ComponentManager.cpp +++ b/src/crepe/ComponentManager.cpp @@ -6,6 +6,9 @@ using namespace crepe; using namespace std; +ComponentManager::ComponentManager() { dbg_trace(); } +ComponentManager::~ComponentManager() { dbg_trace(); } + void ComponentManager::delete_all_components_of_id(game_object_id_t id) { // Loop through all the types (in the unordered_map<>) for (auto & [type, componentArray] : this->components) { @@ -18,18 +21,14 @@ void ComponentManager::delete_all_components_of_id(game_object_id_t id) { } void ComponentManager::delete_all_components() { - // Clear the whole unordered_map<> this->components.clear(); + this->next_id = 0; } -ComponentManager::ComponentManager() { dbg_trace(); } -ComponentManager::~ComponentManager() { dbg_trace(); } - GameObject ComponentManager::new_object(const string & name, const string & tag, const Vector2 & position, double rotation, double scale) { - GameObject object{*this, this->next_id, name, tag, - position, rotation, scale}; + GameObject object{*this, this->next_id, name, tag, position, rotation, scale}; this->next_id++; return object; } diff --git a/src/crepe/ComponentManager.h b/src/crepe/ComponentManager.h index 51c84a4..ca2e7c6 100644 --- a/src/crepe/ComponentManager.h +++ b/src/crepe/ComponentManager.h @@ -6,9 +6,10 @@ #include #include -#include "Component.h" #include "api/Vector2.h" +#include "Component.h" + namespace crepe { class GameObject; diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp index 98efb49..0a84468 100644 --- a/src/crepe/ComponentManager.hpp +++ b/src/crepe/ComponentManager.hpp @@ -40,7 +40,6 @@ T & ComponentManager::add_component(game_object_id_t id, Args &&... args) { // Check if the vector size is not greater than get_instances_max int max_instances = instance->get_instances_max(); if (max_instances != -1 && components[type][id].size() >= max_instances) { - // TODO: Exception throw std::runtime_error( "Exceeded maximum number of instances for this component type"); } diff --git a/src/crepe/Exception.cpp b/src/crepe/Exception.cpp deleted file mode 100644 index 5a24e7e..0000000 --- a/src/crepe/Exception.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "Exception.h" - -using namespace crepe; -using namespace std; - -const char * Exception::what() const noexcept { return error.c_str(); } - -Exception::Exception(const string & msg) { this->error = msg; } diff --git a/src/crepe/Exception.h b/src/crepe/Exception.h deleted file mode 100644 index 580fc16..0000000 --- a/src/crepe/Exception.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace crepe { - -//! Exception class -class Exception : public std::exception { -public: - //! Exception with plain message - Exception(const std::string & msg); - - //! Exception with \c std::format message - template - Exception(std::format_string fmt, Args &&... args); - - //! Get formatted error message - const char * what() const noexcept; - -protected: - Exception() = default; - - //! Formatted error message - std::string error; -}; - -} // namespace crepe - -#include "Exception.hpp" diff --git a/src/crepe/Exception.hpp b/src/crepe/Exception.hpp deleted file mode 100644 index 7c462a3..0000000 --- a/src/crepe/Exception.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "Exception.h" - -namespace crepe { - -template -Exception::Exception(std::format_string fmt, Args &&... args) { - this->error = std::format(fmt, std::forward(args)...); -} - -} // namespace crepe diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index 54b2ec3..cccbc67 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -1,6 +1,4 @@ -#include - #include "util/Log.h" #include "Animator.h" diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index 75b8139..3573403 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -1,7 +1,5 @@ #pragma once -#include - #include "Component.h" #include "Sprite.h" diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 2982358..1a8910d 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -3,6 +3,7 @@ #include #include "../Component.h" + #include "GameObject.h" namespace crepe { @@ -47,8 +48,6 @@ protected: std::unique_ptr