-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use C++20
concepts
to constrain component-specific functions
- Loading branch information
1 parent
700e96a
commit 08ef7cb
Showing
10 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "BehaviourComponent.hh" | ||
|
||
namespace volt::runtime { | ||
BehaviourComponent::BehaviourComponent(std::unique_ptr<IBehaviour> &&b) | ||
: behaviour{std::move(b)} | ||
{} | ||
|
||
void BehaviourComponent::Serialize(YAML::Emitter &) {} | ||
|
||
bool BehaviourComponent::Deserialize(YAML::Node &) { | ||
return false; | ||
} | ||
|
||
void BehaviourComponent::Draw(void) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include "IComponent.hh" | ||
#include "IBehaviour.hh" | ||
#include "../Core/LogSystem.hh" | ||
|
||
namespace volt::runtime { | ||
template <typename T> | ||
template <IBehaviour_t T> | ||
inline constexpr std::unique_ptr<T> Instantiate(void) { | ||
auto ptr { std::make_unique<T>() }; | ||
// NOTE: `typeid(T).name()` is mangled | ||
VOLT_LOG_INFO("Behaviour instantiated [{}|{}]", fmt::ptr(ptr.get()), typeid(T).name()); | ||
return ptr; | ||
} | ||
|
||
struct BehaviourComponent { | ||
struct BehaviourComponent : public IComponent { | ||
std::unique_ptr<IBehaviour> behaviour { nullptr }; | ||
BehaviourComponent(std::unique_ptr<IBehaviour> &&b); | ||
void Serialize(YAML::Emitter &) final; | ||
bool Deserialize(YAML::Node &) final; | ||
void Draw(void) final; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
#pragma once | ||
|
||
#include <type_traits> | ||
|
||
namespace volt::runtime { | ||
class Entity; | ||
|
||
struct IBehaviour { | ||
virtual ~IBehaviour(void) = default; | ||
virtual void Update(Entity &e) = 0; | ||
}; | ||
|
||
template <typename T> | ||
concept IBehaviour_t = std::is_base_of<IBehaviour, T>::value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "IDComponent.hh" | ||
|
||
namespace volt::runtime { | ||
IDComponent::IDComponent(core::SnowflakeID i) | ||
: id{i} | ||
{} | ||
|
||
void IDComponent::Serialize(YAML::Emitter &) {} | ||
|
||
bool IDComponent::Deserialize(YAML::Node &) { | ||
return false; | ||
} | ||
|
||
void IDComponent::Draw(void) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
#pragma once | ||
|
||
#include "IComponent.hh" | ||
#include "../Core/SnowflakeID.hh" | ||
|
||
namespace volt::runtime { | ||
struct IDComponent { | ||
struct IDComponent : public IComponent { | ||
core::SnowflakeID id; | ||
IDComponent(core::SnowflakeID i); | ||
void Serialize(YAML::Emitter &) final; | ||
bool Deserialize(YAML::Node &) final; | ||
void Draw(void) final; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "TagComponent.hh" | ||
|
||
namespace volt::runtime { | ||
TagComponent::TagComponent(const std::string &t) | ||
: tag{t} | ||
{} | ||
|
||
void TagComponent::Serialize(YAML::Emitter &) {} | ||
|
||
bool TagComponent::Deserialize(YAML::Node &) { | ||
return false; | ||
} | ||
|
||
void TagComponent::Draw(void) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include "IComponent.hh" | ||
|
||
namespace volt::runtime { | ||
struct TagComponent { | ||
struct TagComponent : public IComponent { | ||
std::string tag; | ||
TagComponent(const std::string &t); | ||
void Serialize(YAML::Emitter &) final; | ||
bool Deserialize(YAML::Node &) final; | ||
void Draw(void) final; | ||
}; | ||
} |