diff options
52 files changed, 394 insertions, 194 deletions
diff --git a/src/crepe/Component.cpp b/src/crepe/Component.cpp index acfd35c..141e1a8 100644 --- a/src/crepe/Component.cpp +++ b/src/crepe/Component.cpp @@ -3,3 +3,8 @@ using namespace crepe; Component::Component(game_object_id_t id) : game_object_id(id) {} + +Component & Component::operator=(const Component &) { + return *this; +} + diff --git a/src/crepe/Component.h b/src/crepe/Component.h index eff5a58..47c5c34 100644 --- a/src/crepe/Component.h +++ b/src/crepe/Component.h @@ -32,9 +32,13 @@ protected: //! Only ComponentManager can create components friend class ComponentManager; - Component(const Component &) = delete; + // create snapshot + Component(const Component &) = default; + // restore snapshot + virtual Component & operator=(const Component &); + + // components are never moved Component(Component &&) = delete; - virtual Component & operator=(const Component &) = delete; virtual Component & operator=(Component &&) = delete; public: diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp index d22afdf..af7572c 100644 --- a/src/crepe/api/BehaviorScript.cpp +++ b/src/crepe/api/BehaviorScript.cpp @@ -10,6 +10,6 @@ BehaviorScript::BehaviorScript(game_object_id_t id, Mediator & mediator) template <> BehaviorScript & GameObject::add_component<BehaviorScript>() { - ComponentManager & mgr = this->component_manager; - return mgr.add_component<BehaviorScript>(this->id, mgr.mediator); + ComponentManager & mgr = this->mediator.component_manager; + return mgr.add_component<BehaviorScript>(this->id, this->mediator); } diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 3909b96..02d588a 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -9,6 +9,7 @@ namespace crepe { class ScriptSystem; +class Mediator; class ComponentManager; class Script; diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index 9ef4682..ea9c425 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -7,20 +7,20 @@ using namespace crepe; using namespace std; -GameObject::GameObject(ComponentManager & component_manager, game_object_id_t id, +GameObject::GameObject(Mediator & mediator, game_object_id_t id, const std::string & name, const std::string & tag, const vec2 & position, double rotation, double scale) : id(id), - component_manager(component_manager) { + mediator(mediator) { // Add Transform and Metadata components - ComponentManager & mgr = this->component_manager; + ComponentManager & mgr = this->mediator.component_manager; mgr.add_component<Transform>(this->id, position, rotation, scale); mgr.add_component<Metadata>(this->id, name, tag); } void GameObject::set_parent(const GameObject & parent) { - ComponentManager & mgr = this->component_manager; + ComponentManager & mgr = this->mediator.component_manager; // Set parent on own Metadata component RefVector<Metadata> this_metadata = mgr.get_components_by_id<Metadata>(this->id); @@ -32,7 +32,7 @@ void GameObject::set_parent(const GameObject & parent) { } void GameObject::set_persistent(bool persistent) { - ComponentManager & mgr = this->component_manager; + ComponentManager & mgr = this->mediator.component_manager; mgr.set_persistent(this->id, persistent); } diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index ff80f49..a311c21 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -6,7 +6,7 @@ namespace crepe { -class ComponentManager; +class Mediator; /** * \brief Represents a GameObject @@ -20,7 +20,7 @@ private: * This constructor creates a new GameObject. It creates a new Transform and Metadata * component and adds them to the ComponentManager. * - * \param component_manager Reference to component_manager + * \param mediator Reference to mediator * \param id The id of the GameObject * \param name The name of the GameObject * \param tag The tag of the GameObject @@ -28,7 +28,7 @@ private: * \param rotation The rotation of the GameObject * \param scale The scale of the GameObject */ - GameObject(ComponentManager & component_manager, game_object_id_t id, + GameObject(Mediator & mediator, game_object_id_t id, const std::string & name, const std::string & tag, const vec2 & position, double rotation, double scale); //! ComponentManager instances GameObject @@ -73,7 +73,7 @@ public: const game_object_id_t id; protected: - ComponentManager & component_manager; + Mediator & mediator; }; } // namespace crepe diff --git a/src/crepe/api/GameObject.hpp b/src/crepe/api/GameObject.hpp index a6b45b0..69f7d73 100644 --- a/src/crepe/api/GameObject.hpp +++ b/src/crepe/api/GameObject.hpp @@ -8,7 +8,7 @@ namespace crepe { template <typename T, typename... Args> T & GameObject::add_component(Args &&... args) { - ComponentManager & mgr = this->component_manager; + ComponentManager & mgr = this->mediator.component_manager; return mgr.add_component<T>(this->id, std::forward<Args>(args)...); } diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp index 1f0ba72..3511bca 100644 --- a/src/crepe/api/LoopManager.cpp +++ b/src/crepe/api/LoopManager.cpp @@ -7,7 +7,7 @@ #include "../system/PhysicsSystem.h" #include "../system/RenderSystem.h" #include "../system/ScriptSystem.h" -#include "manager/EventManager.h" +#include "../system/EventSystem.h" #include "LoopManager.h" @@ -15,34 +15,43 @@ using namespace crepe; using namespace std; LoopManager::LoopManager() { - this->load_system<AnimatorSystem>(); + this->load_system<ScriptSystem>(); + this->load_system<AISystem>(); + this->load_system<PhysicsSystem>(); this->load_system<CollisionSystem>(); + this->load_system<AnimatorSystem>(); this->load_system<ParticleSystem>(); - this->load_system<PhysicsSystem>(); this->load_system<RenderSystem>(); - this->load_system<ScriptSystem>(); this->load_system<InputSystem>(); + this->load_system<EventSystem>(); this->load_system<AudioSystem>(); - this->load_system<AISystem>(); } -void LoopManager::process_input() { this->get_system<InputSystem>().update(); } - void LoopManager::start() { this->setup(); this->loop(); } -void LoopManager::set_running(bool running) { this->game_running = running; } void LoopManager::fixed_update() { - // TODO: retrieve EventManager from direct member after singleton refactor - EventManager & ev = this->mediator.event_manager; - ev.dispatch_events(); - this->get_system<ScriptSystem>().update(); - this->get_system<AISystem>().update(); - this->get_system<PhysicsSystem>().update(); - this->get_system<CollisionSystem>().update(); - this->get_system<AudioSystem>().update(); + for (auto & [type, system] : this->systems) { + if (!system->active) continue; + system->fixed_update(); + } +} + +void LoopManager::frame_update() { + for (auto & [type, system] : this->systems) { + if (!system->active) continue; + system->frame_update(); + } +} + +void LoopManager::setup() { + LoopTimer & timer = this->loop_timer; + this->game_running = true; + this->scene_manager.load_next_scene(); + timer.start(); + timer.set_fps(200); } void LoopManager::loop() { @@ -53,31 +62,12 @@ void LoopManager::loop() { timer.update(); while (timer.get_lag() >= timer.get_fixed_delta_time()) { - this->process_input(); this->fixed_update(); timer.advance_fixed_update(); } - this->update(); - this->render(); - + this->frame_update(); timer.enforce_frame_rate(); } } -void LoopManager::setup() { - LoopTimer & timer = this->loop_timer; - this->game_running = true; - this->scene_manager.load_next_scene(); - timer.start(); - timer.set_fps(200); -} - -void LoopManager::render() { - if (!this->game_running) return; - - this->get_system<AnimatorSystem>().update(); - this->get_system<RenderSystem>().update(); -} - -void LoopManager::update() {} diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h index 1bafa56..28aa423 100644 --- a/src/crepe/api/LoopManager.h +++ b/src/crepe/api/LoopManager.h @@ -1,7 +1,5 @@ #pragma once -#include <memory> - #include "../facade/SDLContext.h" #include "../manager/ComponentManager.h" #include "../manager/ResourceManager.h" @@ -47,25 +45,11 @@ private: void loop(); /** - * \brief Function for handling input-related system calls. - * - * Processes user inputs from keyboard and mouse. - */ - void process_input(); - - /** * \brief Per-frame update. * * Updates the game state based on the elapsed time since the last frame. */ - void update(); - - /** - * \brief Late update which is called after update(). - * - * This function can be used for final adjustments before rendering. - */ - void late_update(); + void frame_update(); /** * \brief Fixed update executed at a fixed rate. @@ -74,20 +58,6 @@ private: */ void fixed_update(); - /** - * \brief Set game running variable - * - * \param running running (false = game shutdown, true = game running) - */ - void set_running(bool running); - - /** - * \brief Function for executing render-related systems. - * - * Renders the current state of the game to the screen. - */ - void render(); - bool game_running = false; private: diff --git a/src/crepe/api/LoopManager.hpp b/src/crepe/api/LoopManager.hpp index 266758a..627b281 100644 --- a/src/crepe/api/LoopManager.hpp +++ b/src/crepe/api/LoopManager.hpp @@ -1,11 +1,10 @@ #pragma once +#include <memory> #include <cassert> #include <format> -#include <memory> #include "../system/System.h" - #include "LoopManager.h" namespace crepe { @@ -18,8 +17,7 @@ void LoopManager::add_scene() { template <class T> T & LoopManager::get_system() { using namespace std; - static_assert(is_base_of<System, T>::value, - "get_system must recieve a derivative class of System"); + static_assert(is_base_of<System, T>::value, "get_system must recieve a derivative class of System"); const type_info & type = typeid(T); if (!this->systems.contains(type)) @@ -36,7 +34,7 @@ template <class T> void LoopManager::load_system() { using namespace std; static_assert(is_base_of<System, T>::value, - "load_system must recieve a derivative class of System"); + "load_system must recieve a derivative class of System"); const type_info & type = typeid(T); if (this->systems.contains(type)) diff --git a/src/crepe/manager/CMakeLists.txt b/src/crepe/manager/CMakeLists.txt index 480c8ee..459bbfa 100644 --- a/src/crepe/manager/CMakeLists.txt +++ b/src/crepe/manager/CMakeLists.txt @@ -5,6 +5,7 @@ target_sources(crepe PUBLIC SaveManager.cpp SceneManager.cpp ResourceManager.cpp + ReplayManager.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES @@ -19,5 +20,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES SceneManager.hpp ResourceManager.h ResourceManager.hpp + ReplayManager.h ) diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp index df30d27..24ba0d7 100644 --- a/src/crepe/manager/ComponentManager.cpp +++ b/src/crepe/manager/ComponentManager.cpp @@ -53,7 +53,7 @@ GameObject ComponentManager::new_object(const string & name, const string & tag, this->next_id++; } - GameObject object{*this, this->next_id, name, tag, position, rotation, scale}; + GameObject object{this->mediator, this->next_id, name, tag, position, rotation, scale}; this->next_id++; return object; diff --git a/src/crepe/manager/ComponentManager.h b/src/crepe/manager/ComponentManager.h index 19a8e81..dd7c154 100644 --- a/src/crepe/manager/ComponentManager.h +++ b/src/crepe/manager/ComponentManager.h @@ -21,13 +21,6 @@ class GameObject; * This class manages all components. It provides methods to add, delete and get components. */ class ComponentManager : public Manager { - // TODO: This relation should be removed! I (loek) believe that the scene manager should - // create/destroy components because the GameObject's are stored in concrete Scene classes, - // which will in turn call GameObject's destructor, which will in turn call - // ComponentManager::delete_components_by_id or something. This is a pretty major change, so - // here is a comment and temporary fix instead :tada: - friend class SceneManager; - public: ComponentManager(Mediator & mediator); ~ComponentManager(); // dbg_trace @@ -49,12 +42,7 @@ public: const vec2 & position = {0, 0}, double rotation = 0, double scale = 1); -protected: - /** - * GameObject is used as an interface to add/remove components, and the game programmer is - * supposed to use it instead of interfacing with the component manager directly. - */ - friend class GameObject; +public: /** * \brief Add a component to the ComponentManager * @@ -154,6 +142,15 @@ public: template <typename T> RefVector<T> get_components_by_tag(const std::string & tag) const; + struct SnapshotComponent { + Component component; + }; + struct Snapshot { + + }; + Snapshot save(); + void restore(const Snapshot &); + private: /** * \brief Get object IDs by predicate function diff --git a/src/crepe/manager/ReplayManager.cpp b/src/crepe/manager/ReplayManager.cpp new file mode 100644 index 0000000..3643a8e --- /dev/null +++ b/src/crepe/manager/ReplayManager.cpp @@ -0,0 +1,8 @@ +#include "ReplayManager.h" +#include "manager/Manager.h" + +using namespace crepe; + +ReplayManager::ReplayManager(Mediator & mediator) : Manager(mediator) { +} + diff --git a/src/crepe/manager/ReplayManager.h b/src/crepe/manager/ReplayManager.h new file mode 100644 index 0000000..c50196c --- /dev/null +++ b/src/crepe/manager/ReplayManager.h @@ -0,0 +1,37 @@ +#pragma once + +#include "Manager.h" +#include "ComponentManager.h" +#include <unordered_map> + +namespace crepe { + +class ReplaySystem; +class Memento; + +typedef size_t recording_t; + +class ReplayManager : public Manager { +public: + ReplayManager(Mediator & mediator); + friend class ReplaySystem; + +protected: + void record_frame(); + +private: + typedef std::vector<ComponentManager::Snapshot> Recording; + + bool recording = false; + recording_t current_recording = -1; + + + std::unordered_map<recording_t, std::unique_ptr<Recording>> memory; +public: + void record_start(); + recording_t record_end(); + void play(recording_t handle); + void release(recording_t handle); +}; + +} // namespace crepe diff --git a/src/crepe/system/AISystem.cpp b/src/crepe/system/AISystem.cpp index 7f04432..3c3fd93 100644 --- a/src/crepe/system/AISystem.cpp +++ b/src/crepe/system/AISystem.cpp @@ -9,7 +9,7 @@ using namespace crepe; -void AISystem::update() { +void AISystem::fixed_update() { const Mediator & mediator = this->mediator; ComponentManager & mgr = mediator.component_manager; LoopTimer & timer = mediator.timer; diff --git a/src/crepe/system/AISystem.h b/src/crepe/system/AISystem.h index d5f8a8e..04807cf 100644 --- a/src/crepe/system/AISystem.h +++ b/src/crepe/system/AISystem.h @@ -20,7 +20,7 @@ public: using System::System; //! Update the AI system - void update() override; + void fixed_update() override; private: /** diff --git a/src/crepe/system/AnimatorSystem.cpp b/src/crepe/system/AnimatorSystem.cpp index d61ba35..02647f1 100644 --- a/src/crepe/system/AnimatorSystem.cpp +++ b/src/crepe/system/AnimatorSystem.cpp @@ -1,5 +1,3 @@ - - #include "../api/Animator.h" #include "../manager/ComponentManager.h" #include "api/LoopTimer.h" @@ -8,7 +6,7 @@ using namespace crepe; -void AnimatorSystem::update() { +void AnimatorSystem::frame_update() { ComponentManager & mgr = this->mediator.component_manager; LoopTimer & timer = this->mediator.timer; RefVector<Animator> animations = mgr.get_components_by_type<Animator>(); diff --git a/src/crepe/system/AnimatorSystem.h b/src/crepe/system/AnimatorSystem.h index 7d3f565..092e131 100644 --- a/src/crepe/system/AnimatorSystem.h +++ b/src/crepe/system/AnimatorSystem.h @@ -22,7 +22,7 @@ public: * Animator components, moving the animations forward and managing their behavior (e.g., * looping). */ - void update() override; + void frame_update() override; }; } // namespace crepe diff --git a/src/crepe/system/AudioSystem.cpp b/src/crepe/system/AudioSystem.cpp index b1aa0f8..d4e8b9f 100644 --- a/src/crepe/system/AudioSystem.cpp +++ b/src/crepe/system/AudioSystem.cpp @@ -7,7 +7,7 @@ using namespace crepe; using namespace std; -void AudioSystem::update() { +void AudioSystem::fixed_update() { ComponentManager & component_manager = this->mediator.component_manager; ResourceManager & resource_manager = this->mediator.resource_manager; RefVector<AudioSource> components diff --git a/src/crepe/system/AudioSystem.h b/src/crepe/system/AudioSystem.h index 2ddc443..56fc98c 100644 --- a/src/crepe/system/AudioSystem.h +++ b/src/crepe/system/AudioSystem.h @@ -11,7 +11,7 @@ namespace crepe { class AudioSystem : public System { public: using System::System; - void update() override; + void fixed_update() override; private: /** diff --git a/src/crepe/system/CMakeLists.txt b/src/crepe/system/CMakeLists.txt index 0e2db76..3473876 100644 --- a/src/crepe/system/CMakeLists.txt +++ b/src/crepe/system/CMakeLists.txt @@ -8,6 +8,8 @@ target_sources(crepe PUBLIC AudioSystem.cpp AnimatorSystem.cpp InputSystem.cpp + EventSystem.cpp + ReplaySystem.cpp AISystem.cpp ) @@ -20,5 +22,6 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES AudioSystem.h AnimatorSystem.h InputSystem.h + EventSystem.h AISystem.h ) diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp index 44a0431..2db592f 100644 --- a/src/crepe/system/CollisionSystem.cpp +++ b/src/crepe/system/CollisionSystem.cpp @@ -23,7 +23,7 @@ using namespace crepe; -void CollisionSystem::update() { +void CollisionSystem::fixed_update() { std::vector<CollisionInternal> all_colliders; game_object_id_t id = 0; ComponentManager & mgr = this->mediator.component_manager; diff --git a/src/crepe/system/CollisionSystem.h b/src/crepe/system/CollisionSystem.h index 5b136c6..48a8f86 100644 --- a/src/crepe/system/CollisionSystem.h +++ b/src/crepe/system/CollisionSystem.h @@ -85,7 +85,7 @@ public: public: //! Updates the collision system by checking for collisions between colliders and handling them. - void update() override; + void fixed_update() override; private: /** diff --git a/src/crepe/system/EventSystem.cpp b/src/crepe/system/EventSystem.cpp new file mode 100644 index 0000000..bf2b6bc --- /dev/null +++ b/src/crepe/system/EventSystem.cpp @@ -0,0 +1,9 @@ +#include "EventSystem.h" + +using namespace crepe; + +void EventSystem::fixed_update() { + EventManager & ev = this->mediator.event_manager; + ev.dispatch_events(); +} + diff --git a/src/crepe/system/EventSystem.h b/src/crepe/system/EventSystem.h new file mode 100644 index 0000000..a179d00 --- /dev/null +++ b/src/crepe/system/EventSystem.h @@ -0,0 +1,15 @@ +#pragma once + +#include "System.h" + +namespace crepe { + +class EventSystem : public System { +public: + using System::System; + + void fixed_update() override; +}; + +} + diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index a710ae2..7796b47 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -8,7 +8,7 @@ using namespace crepe; -void InputSystem::update() { +void InputSystem::fixed_update() { ComponentManager & mgr = this->mediator.component_manager; EventManager & event_mgr = this->mediator.event_manager; SDLContext & context = this->mediator.sdl_context; diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h index 87e86f8..62b0fcd 100644 --- a/src/crepe/system/InputSystem.h +++ b/src/crepe/system/InputSystem.h @@ -27,7 +27,7 @@ public: * \brief Updates the system, processing all input events. * This method processes all events and triggers corresponding actions. */ - void update() override; + void fixed_update() override; private: //! Stores the last position of the mouse when the button was pressed. diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp index b14c52f..5ccd128 100644 --- a/src/crepe/system/ParticleSystem.cpp +++ b/src/crepe/system/ParticleSystem.cpp @@ -10,7 +10,7 @@ using namespace crepe; -void ParticleSystem::update() { +void ParticleSystem::frame_update() { // Get all emitters ComponentManager & mgr = this->mediator.component_manager; RefVector<ParticleEmitter> emitters = mgr.get_components_by_type<ParticleEmitter>(); diff --git a/src/crepe/system/ParticleSystem.h b/src/crepe/system/ParticleSystem.h index 068f01c..6c631ea 100644 --- a/src/crepe/system/ParticleSystem.h +++ b/src/crepe/system/ParticleSystem.h @@ -20,7 +20,7 @@ public: * \brief Updates all particle emitters by emitting particles, updating particle states, and * checking bounds. */ - void update() override; + void frame_update() override; private: /** diff --git a/src/crepe/system/PhysicsSystem.cpp b/src/crepe/system/PhysicsSystem.cpp index ebf4439..714e531 100644 --- a/src/crepe/system/PhysicsSystem.cpp +++ b/src/crepe/system/PhysicsSystem.cpp @@ -10,7 +10,7 @@ using namespace crepe; -void PhysicsSystem::update() { +void PhysicsSystem::fixed_update() { ComponentManager & mgr = this->mediator.component_manager; RefVector<Rigidbody> rigidbodies = mgr.get_components_by_type<Rigidbody>(); RefVector<Transform> transforms = mgr.get_components_by_type<Transform>(); diff --git a/src/crepe/system/PhysicsSystem.h b/src/crepe/system/PhysicsSystem.h index 26152a5..5ed624f 100644 --- a/src/crepe/system/PhysicsSystem.h +++ b/src/crepe/system/PhysicsSystem.h @@ -18,7 +18,7 @@ public: * * It calculates new velocties and changes the postion in the transform. */ - void update() override; + void fixed_update() override; }; } // namespace crepe diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 51340fb..7e9dfc6 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -63,7 +63,7 @@ RefVector<Sprite> RenderSystem::sort(RefVector<Sprite> & objs) const { return sorted_objs; } -void RenderSystem::update() { +void RenderSystem::frame_update() { this->clear_screen(); this->render(); this->present_screen(); diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index e270a6b..a01923d 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -27,7 +27,7 @@ public: * \brief Updates the RenderSystem for the current frame. * This method is called to perform all rendering operations for the current game frame. */ - void update() override; + void frame_update() override; private: //! Clears the screen in preparation for rendering. diff --git a/src/crepe/system/ReplaySystem.cpp b/src/crepe/system/ReplaySystem.cpp new file mode 100644 index 0000000..3aabb58 --- /dev/null +++ b/src/crepe/system/ReplaySystem.cpp @@ -0,0 +1,7 @@ +#include "ReplaySystem.h" + +using namespace crepe; + +void ReplaySystem::fixed_update() { +} + diff --git a/src/crepe/system/ReplaySystem.h b/src/crepe/system/ReplaySystem.h new file mode 100644 index 0000000..15ef3fc --- /dev/null +++ b/src/crepe/system/ReplaySystem.h @@ -0,0 +1,15 @@ +#pragma once + +#include "System.h" + +namespace crepe { + +class ReplaySystem : public System { +public: + using System::System; + + void fixed_update() override; +}; + +} + diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index d6b2ca1..ab79fc3 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -7,7 +7,7 @@ using namespace std; using namespace crepe; -void ScriptSystem::update() { +void ScriptSystem::fixed_update() { dbg_trace(); ComponentManager & mgr = this->mediator.component_manager; diff --git a/src/crepe/system/ScriptSystem.h b/src/crepe/system/ScriptSystem.h index 3db1b1e..612c2ae 100644 --- a/src/crepe/system/ScriptSystem.h +++ b/src/crepe/system/ScriptSystem.h @@ -22,7 +22,7 @@ public: * method. It also calls Script::init() if this has not been done before on * the \c BehaviorScript instance. */ - void update() override; + void fixed_update() override; }; } // namespace crepe diff --git a/src/crepe/system/System.h b/src/crepe/system/System.h index 063dfbf..e2ce7eb 100644 --- a/src/crepe/system/System.h +++ b/src/crepe/system/System.h @@ -14,10 +14,12 @@ class ComponentManager; */ class System { public: - /** - * \brief Process all components this system is responsible for. - */ - virtual void update() = 0; + //! Code that runs in the fixed loop + virtual void fixed_update() {}; + //! Code that runs in the frame loop + virtual void frame_update() {}; + //! Indicates that the update functions of this system should be run + bool active = true; public: System(const Mediator & m); diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index 187ed46..1bc31d8 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -19,4 +19,5 @@ endfunction() add_example(rendering_particle) add_example(game) add_example(button) +add_example(replay) add_example(AITest) diff --git a/src/example/replay.cpp b/src/example/replay.cpp new file mode 100644 index 0000000..0c4f9b3 --- /dev/null +++ b/src/example/replay.cpp @@ -0,0 +1,101 @@ +#include <crepe/util/OptionalRef.h> +#include <crepe/api/BoxCollider.h> +#include <crepe/api/Camera.h> +#include <crepe/api/Color.h> +#include <crepe/api/Event.h> +#include <crepe/api/GameObject.h> +#include <crepe/api/LoopManager.h> +#include <crepe/api/Rigidbody.h> +#include <crepe/api/Scene.h> +#include <crepe/api/Script.h> +#include <crepe/api/Sprite.h> +#include <crepe/api/Transform.h> +#include <crepe/manager/ComponentManager.h> +#include <crepe/manager/Mediator.h> +#include <crepe/manager/ReplayManager.h> + +using namespace crepe; +using namespace std; + +class AnimationScript : public Script { + Transform * transform; + float t = 0; + + void init() { + transform = &get_component<Transform>(); + } + + void update() { + t += 0.05; + transform->position = { sin(t), cos(t) }; + } +}; + +class Timeline : public Script { + unsigned i = 0; + OptionalRef<ReplayManager> mgr; + recording_t recording; + void update() { + ReplayManager & mgr = this->mgr; + switch (i++) { + default: break; + case 10: + // mgr.record_start(); + Log::logf("start"); + break; + case 60: + // this->recording = mgr.record_end(); + Log::logf("stop"); + break; + case 70: + // mgr.play(this->recording); + Log::logf("play"); + break; + case 71: + // mgr.release(this->recording); + Log::logf("end"); + break; + case 72: + Log::logf("exit"); + throw; + break; + }; + } +}; + +class TestScene : public Scene { +public: + using Scene::Scene; + + void load_scene() { + Mediator & m = this->mediator; + ComponentManager & mgr = m.component_manager; + + GameObject cam = mgr.new_object("cam"); + cam.add_component<Camera>(ivec2{640,480},vec2{3,3}, Camera::Data{ + .bg_color = Color::WHITE, + }); + + GameObject square = mgr.new_object("square"); + square.add_component<Sprite>( + Asset{"asset/texture/square.png"}, + Sprite::Data{ + .size = { 0.5, 0.5 }, + } + ); + square.add_component<BehaviorScript>().set_script<AnimationScript>(); + + GameObject scapegoat = mgr.new_object(""); + scapegoat.add_component<BehaviorScript>().set_script<Timeline>(); + } + + string get_name() const { return "scene1"; } +}; + +int main(int argc, char * argv[]) { + LoopManager gameloop; + + gameloop.add_scene<TestScene>(); + gameloop.start(); + return 0; +} diff --git a/src/test/AudioTest.cpp b/src/test/AudioTest.cpp index 48bba1b..415a12e 100644 --- a/src/test/AudioTest.cpp +++ b/src/test/AudioTest.cpp @@ -50,11 +50,11 @@ TEST_F(AudioTest, Default) { EXPECT_CALL(context, stop(_)).Times(0); EXPECT_CALL(context, set_volume(_, _)).Times(0); EXPECT_CALL(context, set_loop(_, _)).Times(0); - system.update(); + system.fixed_update(); } TEST_F(AudioTest, Play) { - system.update(); + system.fixed_update(); { InSequence seq; @@ -67,12 +67,12 @@ TEST_F(AudioTest, Play) { InSequence seq; EXPECT_CALL(context, play(_)).Times(1); - system.update(); + system.fixed_update(); } } TEST_F(AudioTest, Stop) { - system.update(); + system.fixed_update(); { InSequence seq; @@ -85,12 +85,12 @@ TEST_F(AudioTest, Stop) { InSequence seq; EXPECT_CALL(context, stop(_)).Times(1); - system.update(); + system.fixed_update(); } } TEST_F(AudioTest, Volume) { - system.update(); + system.fixed_update(); { InSequence seq; @@ -103,12 +103,12 @@ TEST_F(AudioTest, Volume) { InSequence seq; EXPECT_CALL(context, set_volume(_, component.volume)).Times(1); - system.update(); + system.fixed_update(); } } TEST_F(AudioTest, Looping) { - system.update(); + system.fixed_update(); { InSequence seq; @@ -121,33 +121,33 @@ TEST_F(AudioTest, Looping) { InSequence seq; EXPECT_CALL(context, set_loop(_, component.loop)).Times(1); - system.update(); + system.fixed_update(); } } TEST_F(AudioTest, StopOnDeactivate) { - system.update(); + system.fixed_update(); { InSequence seq; EXPECT_CALL(context, stop(_)).Times(1); component.active = false; - system.update(); + system.fixed_update(); } } TEST_F(AudioTest, PlayOnActive) { component.active = false; component.play_on_awake = true; - system.update(); + system.fixed_update(); { InSequence seq; EXPECT_CALL(context, play(_)).Times(1); component.active = true; - system.update(); + system.fixed_update(); } } @@ -157,5 +157,5 @@ TEST_F(AudioTest, PlayImmediately) { EXPECT_CALL(context, play(_)).Times(1); - system.update(); + system.fixed_update(); } diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 7196404..28a4f8b 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -22,4 +22,5 @@ target_sources(test_main PUBLIC SaveManagerTest.cpp ScriptSaveManagerTest.cpp ScriptECSTest.cpp + ReplayManagerTest.cpp ) diff --git a/src/test/CollisionTest.cpp b/src/test/CollisionTest.cpp index dd45eb6..0607128 100644 --- a/src/test/CollisionTest.cpp +++ b/src/test/CollisionTest.cpp @@ -106,7 +106,7 @@ public: ASSERT_NE(script_object2_ref, nullptr); // Ensure Script::init() is called on all BehaviorScript instances - script_sys.update(); + script_sys.fixed_update(); } }; @@ -121,7 +121,7 @@ TEST_F(CollisionTest, collision_example) { EXPECT_EQ(ev.info.this_collider.game_object_id, 2); }; EXPECT_FALSE(collision_happend); - collision_sys.update(); + collision_sys.fixed_update(); EXPECT_FALSE(collision_happend); } @@ -144,7 +144,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_both_no_velocity) { EXPECT_FALSE(collision_happend); Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); tf.position = {50, 30}; - collision_sys.update(); + collision_sys.fixed_update(); EXPECT_TRUE(collision_happend); } @@ -169,7 +169,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction_no_velocity) { EXPECT_FALSE(collision_happend); Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); tf.position = {45, 30}; - collision_sys.update(); + collision_sys.fixed_update(); EXPECT_TRUE(collision_happend); } @@ -194,7 +194,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction_no_velocity) { EXPECT_FALSE(collision_happend); Transform & tf = this->mgr.get_components_by_id<Transform>(1).front().get(); tf.position = {50, 25}; - collision_sys.update(); + collision_sys.fixed_update(); EXPECT_TRUE(collision_happend); } @@ -221,7 +221,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_both) { rg1.data.linear_velocity = {10, 10}; Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); rg2.data.linear_velocity = {10, 10}; - collision_sys.update(); + collision_sys.fixed_update(); EXPECT_TRUE(collision_happend); } @@ -250,7 +250,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_x_direction) { rg1.data.linear_velocity = {10, 10}; Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); rg2.data.linear_velocity = {10, 10}; - collision_sys.update(); + collision_sys.fixed_update(); EXPECT_TRUE(collision_happend); } @@ -279,7 +279,7 @@ TEST_F(CollisionTest, collision_box_box_dynamic_y_direction) { rg1.data.linear_velocity = {10, 10}; Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); rg2.data.linear_velocity = {10, 10}; - collision_sys.update(); + collision_sys.fixed_update(); EXPECT_TRUE(collision_happend); } @@ -301,7 +301,7 @@ TEST_F(CollisionTest, collision_box_box_static_both) { tf.position = {50, 30}; Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); rg2.data.body_type = crepe::Rigidbody::BodyType::STATIC; - collision_sys.update(); + collision_sys.fixed_update(); EXPECT_TRUE(collision_happend); } @@ -326,7 +326,7 @@ TEST_F(CollisionTest, collision_box_box_static_x_direction) { rg1.data.linear_velocity = {10, 10}; Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); rg2.data.body_type = crepe::Rigidbody::BodyType::STATIC; - collision_sys.update(); + collision_sys.fixed_update(); EXPECT_TRUE(collision_happend); } @@ -351,7 +351,7 @@ TEST_F(CollisionTest, collision_box_box_static_y_direction) { rg1.data.linear_velocity = {10, 10}; Rigidbody & rg2 = this->mgr.get_components_by_id<Rigidbody>(2).front().get(); rg2.data.body_type = crepe::Rigidbody::BodyType::STATIC; - collision_sys.update(); + collision_sys.fixed_update(); EXPECT_TRUE(collision_happend); } @@ -381,10 +381,10 @@ TEST_F(CollisionTest, collision_box_box_static_multiple) { //todo check visually this->game_object1.add_component<BoxCollider>(vec2{-5, 0}, vec2{10, 10}); offset_value = 5; resolution = 10; - collision_sys.update(); + collision_sys.fixed_update(); offset_value = -5; resolution = 10; tf.position = {55, 30}; - collision_sys.update(); + collision_sys.fixed_update(); EXPECT_TRUE(collision_happend); } diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp index 4c05e56..770d9b4 100644 --- a/src/test/InputTest.cpp +++ b/src/test/InputTest.cpp @@ -84,7 +84,7 @@ TEST_F(InputTest, MouseDown) { event.button.button = SDL_BUTTON_LEFT; SDL_PushEvent(&event); - input_system.update(); + input_system.fixed_update(); event_manager.dispatch_events(); EXPECT_TRUE(mouse_triggered); } @@ -112,7 +112,7 @@ TEST_F(InputTest, MouseUp) { event.button.button = SDL_BUTTON_LEFT; SDL_PushEvent(&event); - input_system.update(); + input_system.fixed_update(); event_manager.dispatch_events(); EXPECT_TRUE(function_triggered); } @@ -142,7 +142,7 @@ TEST_F(InputTest, MouseMove) { event.motion.yrel = 10; SDL_PushEvent(&event); - input_system.update(); + input_system.fixed_update(); event_manager.dispatch_events(); EXPECT_TRUE(function_triggered); } @@ -172,7 +172,7 @@ TEST_F(InputTest, KeyDown) { test_event.key.repeat = 1; // Set repeat flag SDL_PushEvent(&test_event); - input_system.update(); // Process the event + input_system.fixed_update(); // Process the event event_manager.dispatch_events(); // Dispatch events to handlers EXPECT_TRUE(function_triggered); // Check if the handler was triggered @@ -197,7 +197,7 @@ TEST_F(InputTest, KeyUp) { event.key.keysym.scancode = SDL_SCANCODE_B; SDL_PushEvent(&event); - input_system.update(); + input_system.fixed_update(); event_manager.dispatch_events(); EXPECT_TRUE(function_triggered); } @@ -218,7 +218,7 @@ TEST_F(InputTest, MouseClick) { event_manager.subscribe<MouseClickEvent>(on_mouse_click); this->simulate_mouse_click(250, 250, SDL_BUTTON_LEFT); - input_system.update(); + input_system.fixed_update(); event_manager.dispatch_events(); EXPECT_TRUE(on_click_triggered); } @@ -240,12 +240,12 @@ TEST_F(InputTest, testButtonClick) { button.is_pressed = false; button.is_toggle = false; this->simulate_mouse_click(999, 999, SDL_BUTTON_LEFT); - input_system.update(); + input_system.fixed_update(); event_manager.dispatch_events(); EXPECT_FALSE(button_clicked); this->simulate_mouse_click(250, 250, SDL_BUTTON_LEFT); - input_system.update(); + input_system.fixed_update(); event_manager.dispatch_events(); EXPECT_TRUE(button_clicked); } @@ -274,7 +274,7 @@ TEST_F(InputTest, testButtonHover) { event.motion.yrel = 10; SDL_PushEvent(&event); - input_system.update(); + input_system.fixed_update(); event_manager.dispatch_events(); EXPECT_FALSE(button.hover); @@ -288,7 +288,7 @@ TEST_F(InputTest, testButtonHover) { hover_event.motion.yrel = 10; SDL_PushEvent(&hover_event); - input_system.update(); + input_system.fixed_update(); event_manager.dispatch_events(); EXPECT_TRUE(button.hover); } diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp index 9112a3f..9ddb850 100644 --- a/src/test/ParticleTest.cpp +++ b/src/test/ParticleTest.cpp @@ -93,18 +93,18 @@ TEST_F(ParticlesTest, spawnParticle) { emitter.data.max_angle = 0.1; emitter.data.max_speed = 10; emitter.data.max_angle = 10; - particle_system.update(); + particle_system.frame_update(); //check if nothing happend EXPECT_EQ(emitter.data.particles[0].active, false); emitter.data.emission_rate = 1; //check particle spawnes - particle_system.update(); + particle_system.frame_update(); EXPECT_EQ(emitter.data.particles[0].active, true); - particle_system.update(); + particle_system.frame_update(); EXPECT_EQ(emitter.data.particles[1].active, true); - particle_system.update(); + particle_system.frame_update(); EXPECT_EQ(emitter.data.particles[2].active, true); - particle_system.update(); + particle_system.frame_update(); EXPECT_EQ(emitter.data.particles[3].active, true); for (auto & particle : emitter.data.particles) { @@ -138,7 +138,7 @@ TEST_F(ParticlesTest, moveParticleHorizontal) { emitter.data.max_angle = 0; emitter.data.emission_rate = 1; for (int a = 1; a < emitter.data.boundary.width / 2; a++) { - particle_system.update(); + particle_system.frame_update(); EXPECT_EQ(emitter.data.particles[0].position.x, a); } } @@ -156,7 +156,7 @@ TEST_F(ParticlesTest, moveParticleVertical) { emitter.data.max_angle = 90; emitter.data.emission_rate = 1; for (int a = 1; a < emitter.data.boundary.width / 2; a++) { - particle_system.update(); + particle_system.frame_update(); EXPECT_EQ(emitter.data.particles[0].position.y, a); } } @@ -175,7 +175,7 @@ TEST_F(ParticlesTest, boundaryParticleReset) { emitter.data.max_angle = 90; emitter.data.emission_rate = 1; for (int a = 0; a < emitter.data.boundary.width / 2 + 1; a++) { - particle_system.update(); + particle_system.frame_update(); } EXPECT_EQ(emitter.data.particles[0].active, false); } @@ -194,7 +194,7 @@ TEST_F(ParticlesTest, boundaryParticleStop) { emitter.data.max_angle = 90; emitter.data.emission_rate = 1; for (int a = 0; a < emitter.data.boundary.width / 2 + 1; a++) { - particle_system.update(); + particle_system.frame_update(); } const double TOLERANCE = 0.01; EXPECT_NEAR(emitter.data.particles[0].velocity.x, 0, TOLERANCE); diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp index 43d2931..7bd7626 100644 --- a/src/test/PhysicsTest.cpp +++ b/src/test/PhysicsTest.cpp @@ -54,10 +54,10 @@ TEST_F(PhysicsTest, gravity) { ASSERT_FALSE(transforms.empty()); EXPECT_EQ(transform.position.y, 0); - system.update(); + system.fixed_update(); EXPECT_EQ(transform.position.y, 1); - system.update(); + system.fixed_update(); EXPECT_EQ(transform.position.y, 3); } @@ -70,14 +70,14 @@ TEST_F(PhysicsTest, max_velocity) { rigidbody.add_force_linear({100, 100}); rigidbody.add_force_angular(100); - system.update(); + system.fixed_update(); EXPECT_EQ(rigidbody.data.linear_velocity.y, 10); EXPECT_EQ(rigidbody.data.linear_velocity.x, 10); EXPECT_EQ(rigidbody.data.angular_velocity, 10); rigidbody.add_force_linear({-100, -100}); rigidbody.add_force_angular(-100); - system.update(); + system.fixed_update(); EXPECT_EQ(rigidbody.data.linear_velocity.y, -10); EXPECT_EQ(rigidbody.data.linear_velocity.x, -10); EXPECT_EQ(rigidbody.data.angular_velocity, -10); @@ -95,7 +95,7 @@ TEST_F(PhysicsTest, movement) { rigidbody.add_force_linear({1, 1}); rigidbody.add_force_angular(1); - system.update(); + system.fixed_update(); EXPECT_EQ(transform.position.x, 1); EXPECT_EQ(transform.position.y, 1); EXPECT_EQ(transform.rotation, 1); @@ -108,7 +108,7 @@ TEST_F(PhysicsTest, movement) { rigidbody.data.linear_velocity_coefficient.x = 0.5; rigidbody.data.linear_velocity_coefficient.y = 0.5; rigidbody.data.angular_velocity_coefficient = 0.5; - system.update(); + system.fixed_update(); EXPECT_EQ(rigidbody.data.linear_velocity.x, 0.5); EXPECT_EQ(rigidbody.data.linear_velocity.y, 0.5); EXPECT_EQ(rigidbody.data.angular_velocity, 0.5); @@ -117,10 +117,10 @@ TEST_F(PhysicsTest, movement) { rigidbody.data.angular_velocity_coefficient = 0; rigidbody.data.max_angular_velocity = 1000; rigidbody.data.angular_velocity = 360; - system.update(); + system.fixed_update(); EXPECT_EQ(transform.rotation, 1); rigidbody.data.angular_velocity = -360; - system.update(); + system.fixed_update(); EXPECT_EQ(transform.rotation, 1); } diff --git a/src/test/Profiling.cpp b/src/test/Profiling.cpp index cc4c637..2c6deba 100644 --- a/src/test/Profiling.cpp +++ b/src/test/Profiling.cpp @@ -38,7 +38,7 @@ class TestScript : public Script { subscribe<CollisionEvent>( [this](const CollisionEvent & ev) -> bool { return this->oncollision(ev); }); } - void update() { + void fixed_update() { // Retrieve component from the same GameObject this script is on } }; @@ -81,9 +81,9 @@ public: }); // initialize systems here: //calls init - script_sys.update(); + script_sys.fixed_update(); //creates window - render_sys.update(); + render_sys.frame_update(); } // Helper function to time an update call and store its duration @@ -101,12 +101,12 @@ public: // Run and profile all systems, return the total time in milliseconds std::chrono::microseconds run_all_systems() { std::chrono::microseconds total_microseconds = 0us; - total_microseconds += time_function("PhysicsSystem", [&]() { physics_sys.update(); }); + total_microseconds += time_function("PhysicsSystem", [&]() { physics_sys.fixed_update(); }); total_microseconds - += time_function("CollisionSystem", [&]() { collision_sys.update(); }); + += time_function("CollisionSystem", [&]() { collision_sys.fixed_update(); }); total_microseconds - += time_function("ParticleSystem", [&]() { particle_sys.update(); }); - total_microseconds += time_function("RenderSystem", [&]() { render_sys.update(); }); + += time_function("ParticleSystem", [&]() { particle_sys.fixed_update(); }); + total_microseconds += time_function("RenderSystem", [&]() { render_sys.frame_update(); }); return total_microseconds; } @@ -231,7 +231,7 @@ TEST_F(DISABLED_ProfilingTest, Profiling_3) { .sprite = test_sprite, }); } - render_sys.update(); + render_sys.frame_update(); this->game_object_count++; this->total_time = 0us; diff --git a/src/test/RenderSystemTest.cpp b/src/test/RenderSystemTest.cpp index b4519cb..689a6d4 100644 --- a/src/test/RenderSystemTest.cpp +++ b/src/test/RenderSystemTest.cpp @@ -85,7 +85,7 @@ public: TEST_F(RenderSystemTest, NoCamera) { // No camera - EXPECT_ANY_THROW({ this->sys.update(); }); + EXPECT_ANY_THROW({ this->sys.frame_update(); }); } TEST_F(RenderSystemTest, make_sprites) {} @@ -139,7 +139,7 @@ TEST_F(RenderSystemTest, Update) { EXPECT_EQ(sprites[2].get().game_object_id, 2); EXPECT_EQ(sprites[3].get().game_object_id, 3); } - this->sys.update(); + this->sys.frame_update(); { vector<reference_wrapper<Sprite>> sprites = this->mgr.get_components_by_type<Sprite>(); ASSERT_EQ(sprites.size(), 4); @@ -178,7 +178,7 @@ TEST_F(RenderSystemTest, Color) { EXPECT_EQ(sprite.data.color.g, Color::GREEN.g); EXPECT_EQ(sprite.data.color.b, Color::GREEN.b); EXPECT_EQ(sprite.data.color.a, Color::GREEN.a); - this->sys.update(); + this->sys.frame_update(); EXPECT_EQ(sprite.data.color.r, Color::GREEN.r); EXPECT_EQ(sprite.data.color.g, Color::GREEN.g); EXPECT_EQ(sprite.data.color.b, Color::GREEN.b); diff --git a/src/test/ReplayManagerTest.cpp b/src/test/ReplayManagerTest.cpp new file mode 100644 index 0000000..aa5a766 --- /dev/null +++ b/src/test/ReplayManagerTest.cpp @@ -0,0 +1,36 @@ +#include <gtest/gtest.h> + +#include <crepe/manager/ReplayManager.h> +#include <crepe/system/ReplaySystem.h> +#include <crepe/api/Scene.h> +#include <crepe/api/Script.h> +#include <crepe/api/BehaviorScript.h> + +using namespace std; +using namespace crepe; +using namespace testing; + +class ReplayManagerTest : public Test { + Mediator mediator; +public: + ComponentManager component_manager{mediator}; + ReplayManager replay_manager{mediator}; + ReplaySystem replay_system{mediator}; + + GameObject entity = component_manager.new_object("foo"); + Transform & entity_transform = component_manager.get_components_by_id<Transform>(entity.id).back(); + Metadata & entity_metadata = component_manager.get_components_by_id<Metadata>(entity.id).back(); +}; + +TEST_F(ReplayManagerTest, Default) { + // replay_manager.record_start(); + + // replay_system.fixed_update(); + // entity_transform.position += {1, 1}; + // replay_system.fixed_update(); + // entity_transform.position += {1, 1}; + // replay_system.fixed_update(); + + // recording_t recording = replay_manager.record_end(); +} + diff --git a/src/test/ScriptEventTest.cpp b/src/test/ScriptEventTest.cpp index c1b4028..479e3f5 100644 --- a/src/test/ScriptEventTest.cpp +++ b/src/test/ScriptEventTest.cpp @@ -37,7 +37,7 @@ TEST_F(ScriptEventTest, Default) { return true; }); - system.update(); + system.fixed_update(); behaviorscript.active = false; EXPECT_EQ(0, event_count); diff --git a/src/test/ScriptTest.cpp b/src/test/ScriptTest.cpp index acdae70..ccf5060 100644 --- a/src/test/ScriptTest.cpp +++ b/src/test/ScriptTest.cpp @@ -39,7 +39,7 @@ TEST_F(ScriptTest, UpdateOnce) { EXPECT_CALL(script, init()).Times(1); EXPECT_CALL(script, update()).Times(1); - system.update(); + system.fixed_update(); } { @@ -47,7 +47,7 @@ TEST_F(ScriptTest, UpdateOnce) { EXPECT_CALL(script, init()).Times(0); EXPECT_CALL(script, update()).Times(1); - system.update(); + system.fixed_update(); } } @@ -61,7 +61,7 @@ TEST_F(ScriptTest, UpdateInactive) { EXPECT_CALL(script, init()).Times(0); EXPECT_CALL(script, update()).Times(0); behaviorscript.active = false; - system.update(); + system.fixed_update(); } { @@ -70,6 +70,6 @@ TEST_F(ScriptTest, UpdateInactive) { EXPECT_CALL(script, init()).Times(1); EXPECT_CALL(script, update()).Times(1); behaviorscript.active = true; - system.update(); + system.fixed_update(); } } |