diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-22 17:26:27 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-22 17:26:27 +0100 |
commit | 0dae96161a99158815a8075b5c405a35b0939936 (patch) | |
tree | 5b9b214c0397694b671e271f6b743c0fd845f51f | |
parent | 7e12ebdf945d40d6f11872cf5852c9bb54d1864f (diff) |
fix Player prefab
-rw-r--r-- | game/prefab/PlayerObject.cpp | 8 | ||||
-rw-r--r-- | game/prefab/PlayerScript.cpp | 15 | ||||
-rw-r--r-- | game/prefab/PlayerScript.h | 10 | ||||
-rw-r--r-- | src/crepe/api/GameObject.h | 7 | ||||
-rw-r--r-- | src/crepe/system/ScriptSystem.cpp | 8 |
5 files changed, 11 insertions, 37 deletions
diff --git a/game/prefab/PlayerObject.cpp b/game/prefab/PlayerObject.cpp index 736704a..ef7b6cc 100644 --- a/game/prefab/PlayerObject.cpp +++ b/game/prefab/PlayerObject.cpp @@ -1,5 +1,3 @@ -#include <crepe/util/Log.h> - #include "Config.h" #include "PlayerObject.h" #include "PlayerScript.h" @@ -67,10 +65,8 @@ PlayerObject::PlayerObject(crepe::GameObject && base) .collision_layer = COLL_LAY_PLAYER, })), collider(add_component<BoxCollider>(vec2(50, 50))), - controller(add_component<BehaviorScript>().set_script<PlayerScript>(this)) { + controller(add_component<BehaviorScript>().set_script<PlayerScript>(*this)) { sprite.jetpack.active = false; - // controller.active = false; - - Log::logf(Log::DEBUG, "PlayerObject: ref {}", (void*) &(this->body.game_object_id)); + controller.active = false; } diff --git a/game/prefab/PlayerScript.cpp b/game/prefab/PlayerScript.cpp index e4a4951..67aadb6 100644 --- a/game/prefab/PlayerScript.cpp +++ b/game/prefab/PlayerScript.cpp @@ -6,21 +6,10 @@ using namespace crepe; using namespace std; -PlayerScript::PlayerScript(PlayerObject * player) : player(player) { - logf(Log::DEBUG, "PlayerScript: [C] player {}", (void*) &(*player)); - logf(Log::DEBUG, "PlayerScript: [C] player.body {}", (void*) &(player->body)); - logf(Log::DEBUG, "PlayerScript: [C] player.body.id {}", (void*) &(player->body.game_object_id)); -} - -void PlayerScript::init() { - logf(Log::DEBUG, "PlayerScript: [C] player {}", (void*) &(*player)); - logf(Log::DEBUG, "PlayerScript: [C] player.body {}", (void*) &(player->body)); - logf(Log::DEBUG, "PlayerScript: [C] player.body.id {}", (void*) &(player->body.game_object_id)); - player->controller.active = false; -} +PlayerScript::PlayerScript(const PlayerObject & player) : player(player) { } void PlayerScript::fixed_update(crepe::duration_t dt) { if (this->get_key_state(Keycode::SPACE)) - player->body.add_force_linear({ 0, -10 }); + player.body.add_force_linear({ 0, -10 }); } diff --git a/game/prefab/PlayerScript.h b/game/prefab/PlayerScript.h index bd4a00a..131c73f 100644 --- a/game/prefab/PlayerScript.h +++ b/game/prefab/PlayerScript.h @@ -6,18 +6,12 @@ class PlayerScript : public crepe::Script { public: - PlayerScript(PlayerObject * player); - - PlayerScript(const PlayerScript &) = delete; - PlayerScript(PlayerScript &&) = delete; - PlayerScript & operator=(const PlayerScript &) = delete; - PlayerScript & operator=(PlayerScript &&) = delete; + PlayerScript(const PlayerObject & player); protected: void fixed_update(crepe::duration_t dt); - void init(); protected: - PlayerObject * player = nullptr; + PlayerObject player; }; diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h index c66da3d..043913a 100644 --- a/src/crepe/api/GameObject.h +++ b/src/crepe/api/GameObject.h @@ -37,13 +37,6 @@ private: //! ComponentManager instances GameObject friend class ComponentManager; -protected: - GameObject(GameObject &&) = default; - - GameObject(const GameObject &) = delete; - GameObject & operator=(const GameObject &) = delete; - GameObject & operator=(GameObject &&) = delete; - public: //! The id of the GameObject const game_object_id_t id; diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index 4cce42b..411a9a3 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -36,15 +36,17 @@ void ScriptSystem::update( script->init(); script->initialized = true; } catch (const exception & e) { - Log::logf(Log::Level::WARNING, "Uncaught exception in {} init: {}", behavior_script.name, e.what()); + Log::logf(Log::Level::WARNING, "Disabled script \"{}\" due to exception in init function: {}", behavior_script.name, e.what()); + behavior_script.active = false; } } try { (*script.*update_function)(delta_time); } catch (const exception & e) { - // TODO: print if it is fixed/frame update - Log::logf(Log::Level::WARNING, "Uncaught exception in {}: {}", behavior_script.name, e.what()); + // 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; } } } |