aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/BehaviorScript.hpp8
-rw-r--r--src/crepe/api/Script.cpp4
-rw-r--r--src/crepe/api/Script.h11
-rw-r--r--src/crepe/api/Script.hpp8
4 files changed, 15 insertions, 16 deletions
diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp
index 5b5a418..bd59337 100644
--- a/src/crepe/api/BehaviorScript.hpp
+++ b/src/crepe/api/BehaviorScript.hpp
@@ -15,10 +15,10 @@ BehaviorScript & BehaviorScript::set_script(Args &&... args) {
static_assert(std::is_base_of<Script, T>::value);
Script * s = new T(std::forward<Args>(args)...);
- s->game_object_id_ref = &this->game_object_id;
- s->active_ref = &this->active;
- s->component_manager_ref = &this->component_manager;
- s->event_manager_ref = &EventManager::get_instance();
+ s->game_object_id = this->game_object_id;
+ s->active = this->active;
+ s->component_manager = this->component_manager;
+ s->event_manager = EventManager::get_instance();
this->script = std::unique_ptr<Script>(s);
return *this;
diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp
index 0e73848..8bb3ef6 100644
--- a/src/crepe/api/Script.cpp
+++ b/src/crepe/api/Script.cpp
@@ -3,7 +3,7 @@
using namespace crepe;
Script::~Script() {
- EventManager & evmgr = *this->event_manager_ref;
+ EventManager & evmgr = this->event_manager;
for (auto id : this->listeners) {
evmgr.unsubscribe(id);
}
@@ -11,6 +11,6 @@ Script::~Script() {
template <>
void Script::subscribe(const EventHandler<CollisionEvent> & callback) {
- const game_object_id_t & game_object_id = *this->game_object_id_ref;
+ const game_object_id_t & game_object_id = this->game_object_id;
this->subscribe_internal(callback, game_object_id);
}
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
index 43efd15..6418b04 100644
--- a/src/crepe/api/Script.h
+++ b/src/crepe/api/Script.h
@@ -2,6 +2,7 @@
#include <vector>
+#include "../util/OptionalRef.h"
#include "../types.h"
#include "EventManager.h"
@@ -150,18 +151,16 @@ private:
* implement a non-default constructor (e.g. for passing references to their own concrete
* Script classes).
*
- * \todo These should be converted to OptionalRef<> once `loek/util` is merged
- *
* \{
*/
//! Game object ID of game object parent BehaviorScript is attached to
- const game_object_id_t * game_object_id_ref = nullptr;
+ OptionalRef<const game_object_id_t> game_object_id;
//! Reference to parent component
- bool * active_ref = nullptr;
+ OptionalRef<bool> active;
//! Reference to component manager instance
- ComponentManager * component_manager_ref = nullptr;
+ OptionalRef<ComponentManager> component_manager;
//! Reference to event manager instance
- EventManager * event_manager_ref = nullptr;
+ OptionalRef<EventManager> event_manager;
//! \}
private:
diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp
index e94278d..a2463bf 100644
--- a/src/crepe/api/Script.hpp
+++ b/src/crepe/api/Script.hpp
@@ -20,9 +20,9 @@ T & Script::get_component() const {
template <typename T>
RefVector<T> Script::get_components() const {
- ComponentManager & mgr = *this->component_manager_ref;
+ ComponentManager & mgr = this->component_manager;
- return mgr.get_components_by_id<T>(*this->game_object_id_ref);
+ return mgr.get_components_by_id<T>(this->game_object_id);
}
template <typename... Args>
@@ -33,10 +33,10 @@ void Script::logf(Args &&... args) {
template <typename EventType>
void Script::subscribe_internal(const EventHandler<EventType> & callback,
event_channel_t channel) {
- EventManager & mgr = *this->event_manager_ref;
+ EventManager & mgr = this->event_manager;
subscription_t listener = mgr.subscribe<EventType>(
[this, callback](const EventType & data) -> bool {
- bool & active = *this->active_ref;
+ bool & active = this->active;
if (!active) return false;
return callback(data);
},