aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-16 17:54:06 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-16 17:54:06 +0100
commitf0cda55f4336672e655420a22aaab3ccb7331e36 (patch)
treed41b8d97d9eb89d1d13c05877b5ce002d28ce659 /src/crepe/api
parentccc7dd1f167daf869fb91118bd3fca8ea796fc8d (diff)
parent876896e50711509e80ef551b4e8ad440e8039b97 (diff)
Merge remote-tracking branch 'origin/master' into max/game
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/CMakeLists.txt2
-rw-r--r--src/crepe/api/Config.h2
-rw-r--r--src/crepe/api/Rigidbody.h4
-rw-r--r--src/crepe/api/Scene.cpp15
-rw-r--r--src/crepe/api/Scene.h38
-rw-r--r--src/crepe/api/Scene.hpp19
6 files changed, 76 insertions, 4 deletions
diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt
index fb11c8d..8f84f06 100644
--- a/src/crepe/api/CMakeLists.txt
+++ b/src/crepe/api/CMakeLists.txt
@@ -20,6 +20,7 @@ target_sources(crepe PUBLIC
Button.cpp
UIObject.cpp
AI.cpp
+ Scene.cpp
)
target_sources(crepe PUBLIC FILE_SET HEADERS FILES
@@ -36,6 +37,7 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES
Vector2.hpp
Color.h
Scene.h
+ Scene.hpp
Metadata.h
Camera.h
Animator.h
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h
index 6472270..ca2d3f1 100644
--- a/src/crepe/api/Config.h
+++ b/src/crepe/api/Config.h
@@ -53,7 +53,7 @@ struct Config final {
*
* Gravity value of game.
*/
- double gravity = 1;
+ float gravity = 10;
} physics;
//! default window settings
diff --git a/src/crepe/api/Rigidbody.h b/src/crepe/api/Rigidbody.h
index 40c6bf1..b08c8db 100644
--- a/src/crepe/api/Rigidbody.h
+++ b/src/crepe/api/Rigidbody.h
@@ -53,7 +53,7 @@ public:
*/
struct Data {
//! objects mass
- float mass = 0.0;
+ float mass = 1;
/**
* \brief Gravity scale factor.
*
@@ -79,7 +79,7 @@ public:
//! Linear velocity of the object (speed and direction).
vec2 linear_velocity;
//! Maximum linear velocity of the object. This limits the object's speed.
- vec2 max_linear_velocity = {INFINITY, INFINITY};
+ float max_linear_velocity = INFINITY;
//! Linear velocity coefficient. This scales the object's velocity for adjustment or damping.
vec2 linear_velocity_coefficient = {1, 1};
//! \}
diff --git a/src/crepe/api/Scene.cpp b/src/crepe/api/Scene.cpp
new file mode 100644
index 0000000..ad729d2
--- /dev/null
+++ b/src/crepe/api/Scene.cpp
@@ -0,0 +1,15 @@
+#include "Scene.h"
+
+using namespace crepe;
+
+SaveManager & Scene::get_save_manager() const { return mediator->save_manager; }
+
+GameObject Scene::new_object(const std::string & name, const std::string & tag,
+ const vec2 & position, double rotation, double scale) {
+ // Forward the call to ComponentManager's new_object method
+ return mediator->component_manager->new_object(name, tag, position, rotation, scale);
+}
+
+void Scene::set_persistent(const Asset & asset, bool persistent) {
+ mediator->resource_manager->set_persistent(asset, persistent);
+}
diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h
index ba9bb76..dcca9d4 100644
--- a/src/crepe/api/Scene.h
+++ b/src/crepe/api/Scene.h
@@ -2,13 +2,19 @@
#include <string>
+#include "../manager/ComponentManager.h"
#include "../manager/Mediator.h"
+#include "../manager/ResourceManager.h"
+#include "../util/Log.h"
#include "../util/OptionalRef.h"
+#include "GameObject.h"
+
namespace crepe {
class SceneManager;
class ComponentManager;
+class Asset;
/**
* \brief Represents a Scene
@@ -38,7 +44,7 @@ public:
// TODO: Late references should ALWAYS be private! This is currently kept as-is so unit tests
// keep passing, but this reference should not be directly accessible by the user!!!
-protected:
+private:
/**
* \name Late references
*
@@ -53,6 +59,36 @@ protected:
//! Mediator reference
OptionalRef<Mediator> mediator;
//! \}
+
+protected:
+ /**
+ * \brief Retrieve the reference to the SaveManager instance
+ *
+ * \returns A reference to the SaveManager instance held by the Mediator.
+ */
+ SaveManager & get_save_manager() const;
+
+ //! \copydoc ComponentManager::new_object
+ GameObject new_object(const std::string & name, const std::string & tag = "",
+ const vec2 & position = {0, 0}, double rotation = 0,
+ double scale = 1);
+
+ //! \copydoc ResourceManager::set_persistent
+ void set_persistent(const Asset & asset, bool persistent);
+ /**
+ * \name Logging functions
+ * \see Log
+ * \{
+ */
+ //! \copydoc Log::logf
+ template <class... Args>
+ void logf(const Log::Level & level, std::format_string<Args...> fmt, Args &&... args);
+ //! \copydoc Log::logf
+ template <class... Args>
+ void logf(std::format_string<Args...> fmt, Args &&... args);
+ //! \}
};
} // namespace crepe
+
+#include "Scene.hpp"
diff --git a/src/crepe/api/Scene.hpp b/src/crepe/api/Scene.hpp
new file mode 100644
index 0000000..14635df
--- /dev/null
+++ b/src/crepe/api/Scene.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "../util/Log.h"
+
+#include "Scene.h"
+
+namespace crepe {
+
+template <class... Args>
+void Scene::logf(const Log::Level & level, std::format_string<Args...> fmt, Args &&... args) {
+ Log::logf(level, fmt, std::forward<Args>(args)...);
+}
+
+template <class... Args>
+void Scene::logf(std::format_string<Args...> fmt, Args &&... args) {
+ Log::logf(fmt, std::forward<Args>(args)...);
+}
+
+} // namespace crepe