aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/BehaviorScript.h1
-rw-r--r--src/crepe/api/Engine.cpp7
-rw-r--r--src/crepe/api/Engine.h14
-rw-r--r--src/crepe/api/GameObject.h3
-rw-r--r--src/crepe/api/ParticleEmitter.cpp15
-rw-r--r--src/crepe/api/ParticleEmitter.h6
-rw-r--r--src/crepe/api/Script.hpp11
-rw-r--r--src/crepe/api/Transform.h1
8 files changed, 45 insertions, 13 deletions
diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h
index 02d588a..3909b96 100644
--- a/src/crepe/api/BehaviorScript.h
+++ b/src/crepe/api/BehaviorScript.h
@@ -9,7 +9,6 @@
namespace crepe {
class ScriptSystem;
-class Mediator;
class ComponentManager;
class Script;
diff --git a/src/crepe/api/Engine.cpp b/src/crepe/api/Engine.cpp
index 7ae89b9..e8b7fd6 100644
--- a/src/crepe/api/Engine.cpp
+++ b/src/crepe/api/Engine.cpp
@@ -5,12 +5,12 @@
using namespace crepe;
using namespace std;
-void Engine::start() {
+int Engine::main() noexcept {
try {
this->setup();
} catch (const exception & e) {
Log::logf(Log::Level::ERROR, "Uncaught exception in setup: {}\n", e.what());
- return;
+ return EXIT_FAILURE;
}
try {
@@ -19,10 +19,11 @@ void Engine::start() {
Log::logf(Log::Level::ERROR, "Uncaught exception in main loop: {}\n", e.what());
this->event_manager.trigger_event<ShutDownEvent>();
}
+
+ return EXIT_SUCCESS;
}
void Engine::setup() {
- this->game_running = true;
this->loop_timer.start();
this->scene_manager.load_next_scene();
diff --git a/src/crepe/api/Engine.h b/src/crepe/api/Engine.h
index 5421d60..efe7853 100644
--- a/src/crepe/api/Engine.h
+++ b/src/crepe/api/Engine.h
@@ -20,13 +20,16 @@ namespace crepe {
*/
class Engine {
public:
- void start();
-
/**
- * \brief Add a new concrete scene to the scene manager
+ * \brief Engine entrypoint
+ *
+ * This function is called by the game programmer after registering all scenes
*
- * \tparam T Type of concrete scene
+ * \returns process exit code
*/
+ int main() noexcept;
+
+ //! \copydoc SceneManager::add_scene
template <typename T>
void add_scene();
@@ -44,7 +47,8 @@ private:
*/
void loop();
- bool game_running = false;
+ //! Game loop condition
+ bool game_running = true;
private:
//! Global context
diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h
index 6203f81..0dabed1 100644
--- a/src/crepe/api/GameObject.h
+++ b/src/crepe/api/GameObject.h
@@ -39,8 +39,9 @@ private:
public:
//! The id of the GameObject
const game_object_id_t id;
-
+ //! This entity's transform
Transform & transform;
+ //! This entity's metadata
Metadata & metadata;
public:
diff --git a/src/crepe/api/ParticleEmitter.cpp b/src/crepe/api/ParticleEmitter.cpp
index 90b77a0..fd69e26 100644
--- a/src/crepe/api/ParticleEmitter.cpp
+++ b/src/crepe/api/ParticleEmitter.cpp
@@ -1,6 +1,7 @@
#include "ParticleEmitter.h"
using namespace crepe;
+using namespace std;
ParticleEmitter::ParticleEmitter(game_object_id_t game_object_id, const Data & data)
: Component(game_object_id),
@@ -9,3 +10,17 @@ ParticleEmitter::ParticleEmitter(game_object_id_t game_object_id, const Data & d
this->data.particles.emplace_back();
}
}
+
+unique_ptr<Component> ParticleEmitter::save() const {
+ return unique_ptr<Component>{new ParticleEmitter(*this)};
+}
+
+void ParticleEmitter::restore(const Component & snapshot) {
+ *this = static_cast<const ParticleEmitter &>(snapshot);
+}
+
+ParticleEmitter & ParticleEmitter::operator=(const ParticleEmitter & other) {
+ data.particles = other.data.particles;
+ return *this;
+}
+
diff --git a/src/crepe/api/ParticleEmitter.h b/src/crepe/api/ParticleEmitter.h
index b83fd61..5f563de 100644
--- a/src/crepe/api/ParticleEmitter.h
+++ b/src/crepe/api/ParticleEmitter.h
@@ -80,6 +80,12 @@ public:
public:
//! Configuration data for particle emission settings.
Data data;
+
+protected:
+ virtual std::unique_ptr<Component> save() const;
+ ParticleEmitter(const ParticleEmitter &) = default;
+ virtual void restore(const Component & snapshot);
+ virtual ParticleEmitter & operator=(const ParticleEmitter &);
};
} // namespace crepe
diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp
index 2553fd1..b42a6df 100644
--- a/src/crepe/api/Script.hpp
+++ b/src/crepe/api/Script.hpp
@@ -40,10 +40,17 @@ void Script::subscribe_internal(const EventHandler<EventType> & callback,
EventManager & mgr = this->mediator->event_manager;
subscription_t listener = mgr.subscribe<EventType>(
[this, callback](const EventType & data) -> bool {
+ // check if (parent) BehaviorScript component is active
bool & active = this->active;
if (!active) return false;
- ReplayManager & replay = this->mediator->replay_manager;
- if (replay.get_state() == ReplayManager::PLAYING) return false;
+
+ // check if replay manager is playing (if initialized)
+ try {
+ ReplayManager & replay = this->mediator->replay_manager;
+ if (replay.get_state() == ReplayManager::PLAYING) return false;
+ } catch (const std::runtime_error &) {}
+
+ // call user-provided callback
return callback(data);
},
channel);
diff --git a/src/crepe/api/Transform.h b/src/crepe/api/Transform.h
index bbd23e0..a6f3486 100644
--- a/src/crepe/api/Transform.h
+++ b/src/crepe/api/Transform.h
@@ -41,7 +41,6 @@ protected:
Transform(const Transform &) = default;
virtual void restore(const Component & snapshot);
virtual Transform & operator=(const Transform &) = default;
-
};
} // namespace crepe