aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-22 16:12:31 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-22 16:12:31 +0100
commit7e12ebdf945d40d6f11872cf5852c9bb54d1864f (patch)
treed81f4661e2fd47f487cf0c9627baa1e21dc45b37 /src/crepe/api
parent61148c757a1f742ff09e40e5347e74e638c7371c (diff)
big WIP
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/BehaviorScript.cpp18
-rw-r--r--src/crepe/api/BehaviorScript.h6
-rw-r--r--src/crepe/api/BehaviorScript.hpp1
-rw-r--r--src/crepe/api/Components.h16
-rw-r--r--src/crepe/api/Config.h3
-rw-r--r--src/crepe/api/Engine.cpp27
-rw-r--r--src/crepe/api/Engine.h5
-rw-r--r--src/crepe/api/GameObject.h7
8 files changed, 75 insertions, 8 deletions
diff --git a/src/crepe/api/BehaviorScript.cpp b/src/crepe/api/BehaviorScript.cpp
index af7572c..e1c06b0 100644
--- a/src/crepe/api/BehaviorScript.cpp
+++ b/src/crepe/api/BehaviorScript.cpp
@@ -13,3 +13,21 @@ BehaviorScript & GameObject::add_component<BehaviorScript>() {
ComponentManager & mgr = this->mediator.component_manager;
return mgr.add_component<BehaviorScript>(this->id, this->mediator);
}
+
+BehaviorScript::BehaviorScript(const BehaviorScript & other) : mediator(other.mediator), Component(other.game_object_id) {
+ Log::logf("COPY CONSTRUCTOR!!!");
+}
+
+BehaviorScript::BehaviorScript(BehaviorScript && other) : mediator(other.mediator), Component(other.game_object_id) {
+ Log::logf("MOVE CONSTRUCTOR!!!");
+}
+
+BehaviorScript & BehaviorScript::operator = (const BehaviorScript & other) {
+ Log::logf("COPY OPERATOR!!!");
+ return *this;
+}
+
+BehaviorScript & BehaviorScript::operator = (BehaviorScript && other) {
+ Log::logf("MOVE OPERATOR!!!");
+ return *this;
+}
diff --git a/src/crepe/api/BehaviorScript.h b/src/crepe/api/BehaviorScript.h
index 3909b96..52a7cbf 100644
--- a/src/crepe/api/BehaviorScript.h
+++ b/src/crepe/api/BehaviorScript.h
@@ -33,6 +33,11 @@ protected:
//! Only ComponentManager is allowed to instantiate BehaviorScript
friend class ComponentManager;
+ BehaviorScript(const BehaviorScript &);
+ BehaviorScript(BehaviorScript &&);
+ BehaviorScript & operator = (const BehaviorScript &);
+ BehaviorScript & operator = (BehaviorScript &&);
+
public:
/**
* \brief Set the concrete script of this component
@@ -48,6 +53,7 @@ public:
BehaviorScript & set_script(Args &&... args);
protected:
+ 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 353d5e2..218f27c 100644
--- a/src/crepe/api/BehaviorScript.hpp
+++ b/src/crepe/api/BehaviorScript.hpp
@@ -11,6 +11,7 @@ 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/Components.h b/src/crepe/api/Components.h
new file mode 100644
index 0000000..fa0663d
--- /dev/null
+++ b/src/crepe/api/Components.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "AI.h"
+#include "Animator.h"
+#include "AudioSource.h"
+#include "BehaviorScript.h"
+#include "BoxCollider.h"
+#include "Button.h"
+#include "Camera.h"
+#include "CircleCollider.h"
+#include "Metadata.h"
+#include "ParticleEmitter.h"
+#include "Rigidbody.h"
+#include "Sprite.h"
+#include "Text.h"
+#include "Transform.h"
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h
index 6b9e3ca..32f1a2e 100644
--- a/src/crepe/api/Config.h
+++ b/src/crepe/api/Config.h
@@ -60,7 +60,8 @@ struct Config final {
struct {
//! default screen size in pixels
ivec2 default_size = {1280, 720};
- std::string window_title = "Jetpack joyride clone";
+ //! default window title
+ std::string window_title = "crepe window";
} window_settings;
//! Asset loading options
diff --git a/src/crepe/api/Engine.cpp b/src/crepe/api/Engine.cpp
index cd9786b..bf3f50c 100644
--- a/src/crepe/api/Engine.cpp
+++ b/src/crepe/api/Engine.cpp
@@ -1,4 +1,7 @@
+#include <segvcatch.h>
+
#include "../util/Log.h"
+#include "../facade/SignalCatch.h"
#include "Engine.h"
@@ -6,6 +9,8 @@ using namespace crepe;
using namespace std;
int Engine::main() noexcept {
+ SignalCatch signal_catch;
+
try {
this->setup();
} catch (const exception & e) {
@@ -37,31 +42,39 @@ void Engine::setup() {
void Engine::loop() {
LoopTimerManager & timer = this->loop_timer;
- SystemManager & systems = this->system_manager;
while (this->game_running) {
timer.update();
while (timer.get_lag() >= timer.get_fixed_delta_time()) {
try {
- systems.fixed_update();
+ this->fixed_update();
} catch (const exception & e) {
Log::logf(
- Log::Level::WARNING, "Uncaught exception in fixed update function: {}\n",
+ Log::Level::WARNING, "Uncaught exception in fixed update function: {}",
e.what()
);
}
- timer.advance_fixed_elapsed_time();
}
try {
- systems.frame_update();
+ this->frame_update();
} catch (const exception & e) {
Log::logf(
- Log::Level::WARNING, "Uncaught exception in frame update function: {}\n",
+ Log::Level::WARNING, "Uncaught exception in frame update function: {}",
e.what()
);
}
- timer.enforce_frame_rate();
}
}
+
+void Engine::fixed_update() {
+ this->system_manager.fixed_update();
+ this->loop_timer.advance_fixed_elapsed_time();
+}
+
+void Engine::frame_update() {
+ this->system_manager.frame_update();
+ this->loop_timer.enforce_frame_rate();
+}
+
diff --git a/src/crepe/api/Engine.h b/src/crepe/api/Engine.h
index 452a856..23acfb4 100644
--- a/src/crepe/api/Engine.h
+++ b/src/crepe/api/Engine.h
@@ -46,6 +46,11 @@ private:
*/
void loop();
+ //! Fixed update function
+ void fixed_update();
+ //! Frame update function
+ void frame_update();
+
//! Game loop condition
bool game_running = true;
diff --git a/src/crepe/api/GameObject.h b/src/crepe/api/GameObject.h
index 043913a..c66da3d 100644
--- a/src/crepe/api/GameObject.h
+++ b/src/crepe/api/GameObject.h
@@ -37,6 +37,13 @@ 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;