aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-20 14:24:08 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-20 14:24:08 +0100
commit22a7e9f3c40b4b6eb68a5343e4870e76c4bfcf63 (patch)
treeb927a520d1d25951a7b22ade23b470168db67a72
parent02845c3d25130e9473604cb2eeee42a7a7a8eadf (diff)
process feedback on #39
-rw-r--r--readme.md7
-rw-r--r--src/crepe/ComponentManager.h5
-rw-r--r--src/crepe/ComponentManager.hpp9
-rw-r--r--src/crepe/api/Asset.cpp5
-rw-r--r--src/crepe/api/Asset.h16
-rw-r--r--src/crepe/system/System.h2
-rw-r--r--src/crepe/util/OptionalRef.h11
-rw-r--r--src/crepe/util/OptionalRef.hpp24
8 files changed, 34 insertions, 45 deletions
diff --git a/readme.md b/readme.md
index c83853d..d309b30 100644
--- a/readme.md
+++ b/readme.md
@@ -32,6 +32,7 @@ This project uses the following libraries
|`SoLoud`|(latest git `master` version)|
|Google Test (`GTest`)|1.15.2|
|Berkeley DB (`libdb`)|5.3.21|
+|Where Am I?|(latest git `master` version)
> [!NOTE]
> Most of these libraries are likely available from your package manager if you
@@ -49,6 +50,11 @@ $ git submodule update --init --recursive --depth 1
Then, follow these steps for each library you want to install:
+> [!IMPORTANT]
+> A dollar sign prompt (`$`) indicates commands to be run as a regular user,
+> while a hashtag (`#`) is used to denote commands that must be run with
+> privileges (e.g. as root or using `sudo`).
+
1. Change into the library folder (run **one** of these):
```
$ cd lib/googletest
@@ -56,6 +62,7 @@ Then, follow these steps for each library you want to install:
$ cd lib/soloud/contrib
$ cd lib/sdl_image
$ cd lib/sdl_ttf
+ $ cd lib/whereami
```
2. Use CMake to configure the build, run the build and install (run **all** of
these):
diff --git a/src/crepe/ComponentManager.h b/src/crepe/ComponentManager.h
index 2107453..0956d1e 100644
--- a/src/crepe/ComponentManager.h
+++ b/src/crepe/ComponentManager.h
@@ -8,6 +8,7 @@
#include "api/Vector2.h"
#include "Component.h"
+#include "types.h"
namespace crepe {
@@ -112,7 +113,7 @@ public:
* \return A vector of all components of the specific type and id
*/
template <typename T>
- std::vector<std::reference_wrapper<T>> get_components_by_id(game_object_id_t id) const;
+ RefVector<T> get_components_by_id(game_object_id_t id) const;
/**
* \brief Get all components of a specific type
*
@@ -122,7 +123,7 @@ public:
* \return A vector of all components of the specific type
*/
template <typename T>
- std::vector<std::reference_wrapper<T>> get_components_by_type() const;
+ RefVector<T> get_components_by_type() const;
private:
/**
diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp
index be99cac..4d5eaf4 100644
--- a/src/crepe/ComponentManager.hpp
+++ b/src/crepe/ComponentManager.hpp
@@ -81,15 +81,14 @@ void ComponentManager::delete_components() {
}
template <typename T>
-std::vector<std::reference_wrapper<T>>
-ComponentManager::get_components_by_id(game_object_id_t id) const {
+RefVector<T> ComponentManager::get_components_by_id(game_object_id_t id) const {
using namespace std;
// Determine the type of T (this is used as the key of the unordered_map<>)
type_index type = typeid(T);
// Create an empty vector<>
- vector<reference_wrapper<T>> component_vector;
+ RefVector<T> component_vector;
if (this->components.find(type) == this->components.end()) return component_vector;
@@ -114,14 +113,14 @@ ComponentManager::get_components_by_id(game_object_id_t id) const {
}
template <typename T>
-std::vector<std::reference_wrapper<T>> ComponentManager::get_components_by_type() const {
+RefVector<T> ComponentManager::get_components_by_type() const {
using namespace std;
// Determine the type of T (this is used as the key of the unordered_map<>)
type_index type = typeid(T);
// Create an empty vector<>
- vector<reference_wrapper<T>> component_vector;
+ RefVector<T> component_vector;
// Find the type (in the unordered_map<>)
if (this->components.find(type) == this->components.end()) return component_vector;
diff --git a/src/crepe/api/Asset.cpp b/src/crepe/api/Asset.cpp
index 3fe3ceb..e148367 100644
--- a/src/crepe/api/Asset.cpp
+++ b/src/crepe/api/Asset.cpp
@@ -2,9 +2,10 @@
#include <stdexcept>
#include <whereami.h>
-#include "Asset.h"
#include "api/Config.h"
+#include "Asset.h"
+
using namespace crepe;
using namespace std;
@@ -15,7 +16,7 @@ const string & Asset::get_path() const noexcept { return this->src; }
string Asset::find_asset(const string & src) const {
auto & cfg = Config::get_instance();
- auto & root_pattern = cfg.asset.root_pattern;
+ string & root_pattern = cfg.asset.root_pattern;
// if root_pattern is empty, find_asset must return all paths as-is
if (root_pattern.empty()) return src;
diff --git a/src/crepe/api/Asset.h b/src/crepe/api/Asset.h
index 77596ac..bfd0ac7 100644
--- a/src/crepe/api/Asset.h
+++ b/src/crepe/api/Asset.h
@@ -40,6 +40,22 @@ private:
const std::string src;
private:
+ /**
+ * \brief Locate asset path, or throw exception if it cannot be found
+ *
+ * This function resolves asset locations relative to crepe::Config::root_pattern if it is
+ * set and \p src is a relative path. If \p src is an absolute path, it is canonicalized.
+ * This function only returns if the file can be found.
+ *
+ * \param src Arbitrary path to resource file
+ *
+ * \returns \p src if crepe::Config::root_pattern is empty
+ * \returns Canonical path to \p src
+ *
+ * \throws std::runtime_error if root_pattern cannot be found
+ * \throws std::filesystem::filesystem_error if the resolved path does not exist
+ * \throws std::filesystem::filesystem_error if the path cannot be canonicalized
+ */
std::string find_asset(const std::string & src) const;
/**
* \returns The path to the current executable
diff --git a/src/crepe/system/System.h b/src/crepe/system/System.h
index 36f7edc..28ea20e 100644
--- a/src/crepe/system/System.h
+++ b/src/crepe/system/System.h
@@ -1,7 +1,5 @@
#pragma once
-#include "../ComponentManager.h"
-
namespace crepe {
class ComponentManager;
diff --git a/src/crepe/util/OptionalRef.h b/src/crepe/util/OptionalRef.h
index 0a94ae5..57f9635 100644
--- a/src/crepe/util/OptionalRef.h
+++ b/src/crepe/util/OptionalRef.h
@@ -36,7 +36,7 @@ public:
*
* \param ref Reference to assign
*/
- void set(T &) noexcept;
+ void set(T & ref) noexcept;
/**
* \brief Retrieve this reference
*
@@ -50,15 +50,6 @@ public:
*/
void clear() noexcept;
- //! Copy constructor
- OptionalRef(const OptionalRef<T> &);
- //! Move constructor
- OptionalRef(OptionalRef<T> &&);
- //! Copy assignment
- OptionalRef<T> & operator=(const OptionalRef<T> &);
- //! Move assignment
- OptionalRef<T> & operator=(OptionalRef<T> &&);
-
private:
/**
* \brief Reference to the value of type \c T
diff --git a/src/crepe/util/OptionalRef.hpp b/src/crepe/util/OptionalRef.hpp
index ee41f61..71e2a39 100644
--- a/src/crepe/util/OptionalRef.hpp
+++ b/src/crepe/util/OptionalRef.hpp
@@ -12,30 +12,6 @@ OptionalRef<T>::OptionalRef(T & ref) {
}
template <typename T>
-OptionalRef<T>::OptionalRef(const OptionalRef<T> & other) {
- this->ref = other.ref;
-}
-
-template <typename T>
-OptionalRef<T>::OptionalRef(OptionalRef<T> && other) {
- this->ref = other.ref;
- other.clear();
-}
-
-template <typename T>
-OptionalRef<T> & OptionalRef<T>::operator=(const OptionalRef<T> & other) {
- this->ref = other.ref;
- return *this;
-}
-
-template <typename T>
-OptionalRef<T> & OptionalRef<T>::operator=(OptionalRef<T> && other) {
- this->ref = other.ref;
- other.clear();
- return *this;
-}
-
-template <typename T>
T & OptionalRef<T>::get() const {
if (this->ref == nullptr)
throw std::runtime_error("OptionalRef: attempt to dereference nullptr");