diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.h | 2 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.hpp | 1 | ||||
-rw-r--r-- | src/crepe/api/Engine.cpp | 13 | ||||
-rw-r--r-- | src/crepe/facade/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/crepe/facade/SignalCatch.cpp | 20 | ||||
-rw-r--r-- | src/crepe/facade/SignalCatch.h | 23 | ||||
-rw-r--r-- | src/crepe/manager/SystemManager.cpp | 30 | ||||
-rw-r--r-- | src/crepe/manager/SystemManager.h | 13 | ||||
-rw-r--r-- | src/crepe/manager/SystemManager.hpp | 5 | ||||
-rw-r--r-- | src/crepe/system/ScriptSystem.cpp | 25 |
11 files changed, 19 insertions, 117 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 90312b3..696856c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,7 +15,6 @@ find_package(GTest REQUIRED) find_package(whereami REQUIRED) find_library(BERKELEY_DB db) find_library(FONTCONFIG_LIB fontconfig) -find_package(segvcatch REQUIRED) add_library(crepe SHARED) add_executable(test_main EXCLUDE_FROM_ALL) @@ -32,7 +31,6 @@ target_link_libraries(crepe PUBLIC ${BERKELEY_DB} PUBLIC whereami PUBLIC ${FONTCONFIG_LIB} - PUBLIC segvcatch ) add_subdirectory(crepe) diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h index 52cf259..3909b96 100644 --- a/src/crepe/api/BehaviorScript.h +++ b/src/crepe/api/BehaviorScript.h @@ -48,8 +48,6 @@ public: BehaviorScript & set_script(Args &&... args); protected: - //! Script type name - std::string name = "unknown script"; //! Script instance std::unique_ptr<Script> script = nullptr; //! ScriptSystem needs direct access to the script instance diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp index 218f27c..353d5e2 100644 --- a/src/crepe/api/BehaviorScript.hpp +++ b/src/crepe/api/BehaviorScript.hpp @@ -11,7 +11,6 @@ template <class T, typename... Args> BehaviorScript & BehaviorScript::set_script(Args &&... args) { static_assert(std::is_base_of<Script, T>::value); this->script = std::unique_ptr<Script>(new T(std::forward<Args>(args)...)); - this->name = typeid(T).name(); this->script->game_object_id = this->game_object_id; this->script->active = this->active; diff --git a/src/crepe/api/Engine.cpp b/src/crepe/api/Engine.cpp index 35743e3..cd9786b 100644 --- a/src/crepe/api/Engine.cpp +++ b/src/crepe/api/Engine.cpp @@ -1,6 +1,3 @@ -#include <segvcatch.h> - -#include "../facade/SignalCatch.h" #include "../util/Log.h" #include "Engine.h" @@ -9,8 +6,6 @@ using namespace crepe; using namespace std; int Engine::main() noexcept { - SignalCatch signal_catch; - try { this->setup(); } catch (const exception & e) { @@ -50,23 +45,23 @@ void Engine::loop() { while (timer.get_lag() >= timer.get_fixed_delta_time()) { try { systems.fixed_update(); - timer.advance_fixed_elapsed_time(); } catch (const exception & e) { Log::logf( - Log::Level::WARNING, "Uncaught exception in fixed update function: {}", + Log::Level::WARNING, "Uncaught exception in fixed update function: {}\n", e.what() ); } + timer.advance_fixed_elapsed_time(); } try { systems.frame_update(); - timer.enforce_frame_rate(); } catch (const exception & e) { Log::logf( - Log::Level::WARNING, "Uncaught exception in frame update function: {}", + Log::Level::WARNING, "Uncaught exception in frame update function: {}\n", e.what() ); } + timer.enforce_frame_rate(); } } diff --git a/src/crepe/facade/CMakeLists.txt b/src/crepe/facade/CMakeLists.txt index 4873e8d..243ae46 100644 --- a/src/crepe/facade/CMakeLists.txt +++ b/src/crepe/facade/CMakeLists.txt @@ -6,7 +6,6 @@ target_sources(crepe PUBLIC DB.cpp FontFacade.cpp Font.cpp - SignalCatch.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES @@ -17,6 +16,5 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES DB.h FontFacade.h Font.h - SignalCatch.h ) diff --git a/src/crepe/facade/SignalCatch.cpp b/src/crepe/facade/SignalCatch.cpp deleted file mode 100644 index 4988047..0000000 --- a/src/crepe/facade/SignalCatch.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include <stdexcept> - -#include "SignalCatch.h" - -using namespace crepe; -using namespace std; - -SignalCatch::SignalCatch() { - segvcatch::init_segv(&SignalCatch::segv); - segvcatch::init_fpe(&SignalCatch::fpe); -} - -SignalCatch::~SignalCatch() { - segvcatch::init_segv(); - segvcatch::init_fpe(); -} - -void SignalCatch::segv() { throw runtime_error("segmentation fault"); } - -void SignalCatch::fpe() { throw domain_error("floating point exception"); } diff --git a/src/crepe/facade/SignalCatch.h b/src/crepe/facade/SignalCatch.h deleted file mode 100644 index cf86b56..0000000 --- a/src/crepe/facade/SignalCatch.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include <segvcatch.h> - -namespace crepe { - -class SignalCatch { -public: - SignalCatch(); - ~SignalCatch(); - -private: - static void segv(); - static void fpe(); - -public: - SignalCatch(const SignalCatch &) = delete; - SignalCatch(SignalCatch &&) = delete; - SignalCatch & operator=(const SignalCatch &) = delete; - SignalCatch & operator=(SignalCatch &&) = delete; -}; - -} // namespace crepe diff --git a/src/crepe/manager/SystemManager.cpp b/src/crepe/manager/SystemManager.cpp index fea59aa..eabc022 100644 --- a/src/crepe/manager/SystemManager.cpp +++ b/src/crepe/manager/SystemManager.cpp @@ -31,31 +31,17 @@ SystemManager::SystemManager(Mediator & mediator) : Manager(mediator) { this->mediator.system_manager = *this; } -void SystemManager::fixed_update() noexcept { - for (SystemEntry & entry : this->system_order) { - if (!entry.system.active) continue; - try { - entry.system.fixed_update(); - } catch (const exception & e) { - Log::logf( - Log::Level::WARNING, "Uncaught exception in {} fixed update: {}", entry.name, - e.what() - ); - } +void SystemManager::fixed_update() { + for (System & system : this->system_order) { + if (!system.active) continue; + system.fixed_update(); } } -void SystemManager::frame_update() noexcept { - for (SystemEntry & entry : this->system_order) { - if (!entry.system.active) continue; - try { - entry.system.frame_update(); - } catch (const exception & e) { - Log::logf( - Log::Level::WARNING, "Uncaught exception in {} frame update: {}", entry.name, - e.what() - ); - } +void SystemManager::frame_update() { + for (System & system : this->system_order) { + if (!system.active) continue; + system.frame_update(); } } diff --git a/src/crepe/manager/SystemManager.h b/src/crepe/manager/SystemManager.h index 7b862a3..614d90c 100644 --- a/src/crepe/manager/SystemManager.h +++ b/src/crepe/manager/SystemManager.h @@ -26,14 +26,14 @@ public: * * Updates the game state based on the elapsed time since the last frame. */ - void frame_update() noexcept; + void frame_update(); /** * \brief Fixed update executed at a fixed rate. * * This function updates physics and game logic based on LoopTimer's fixed_delta_time. */ - void fixed_update() noexcept; + void fixed_update(); private: /** @@ -43,20 +43,13 @@ private: * constructor of \c SystemManager using SystemManager::load_system. */ std::unordered_map<std::type_index, std::unique_ptr<System>> systems; - //! Internal ordered system list entry - struct SystemEntry { - //! System instance reference - System & system; - //! System name - std::string name; - }; /** * \brief Collection of System instances * * This map holds System instances indexed by the system's class typeid. It is filled in the * constructor of \c SystemManager using SystemManager::load_system. */ - std::vector<SystemEntry> system_order; + std::vector<std::reference_wrapper<System>> system_order; /** * \brief Initialize a system * \tparam T System type (must be derivative of \c System) diff --git a/src/crepe/manager/SystemManager.hpp b/src/crepe/manager/SystemManager.hpp index a19a253..addd274 100644 --- a/src/crepe/manager/SystemManager.hpp +++ b/src/crepe/manager/SystemManager.hpp @@ -38,10 +38,7 @@ void SystemManager::load_system() { throw runtime_error(format("SystemManager: {} is already initialized", type.name())); System * system = new T(this->mediator); this->systems[type] = unique_ptr<System>(system); - this->system_order.push_back(SystemEntry { - .system = *this->systems[type], - .name = type.name(), - }); + this->system_order.push_back(*this->systems[type]); } } // namespace crepe diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index f1e31f9..ed0c7cc 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -32,29 +32,10 @@ void ScriptSystem::update( if (script == nullptr) continue; if (!script->initialized) { - try { - script->init(); - script->initialized = true; - } catch (const exception & e) { - Log::logf( - Log::Level::WARNING, - "Disabled script \"{}\" due to exception in init function: {}", - behavior_script.name, e.what() - ); - behavior_script.active = false; - } + script->init(); + script->initialized = true; } - try { - (*script.*update_function)(delta_time); - } catch (const exception & e) { - // TODO: discern between fixed/frame update - Log::logf( - Log::Level::WARNING, - "Disabled script \"{}\" due to exception in update function: {}", - behavior_script.name, e.what() - ); - behavior_script.active = false; - } + (*script.*update_function)(delta_time); } } |