fixing small issues to save some resources

This commit is contained in:
Erris 2025-04-20 21:31:53 +02:00
parent b714c6f82d
commit 5077c09d38
3 changed files with 5 additions and 6 deletions

View File

@ -7,7 +7,8 @@ template<typename StateOwnerType>
class StateMachinePool { class StateMachinePool {
public: public:
void RegisterEntity(const std::string &id, StateOwnerType &entity) { void RegisterEntity(const std::string &id, StateOwnerType &entity) {
machines[id] = std::make_unique<StateMachine<StateOwnerType>>(entity, factory); auto machine = std::make_unique<StateMachine<StateOwnerType>>(entity, factory);
machines[id] = std::move(machine);
} }
void UnregisterEntity(const std::string &id) { void UnregisterEntity(const std::string &id) {

View File

@ -13,8 +13,6 @@ using json = nlohmann::json;
template<typename T> template<typename T>
class StateMachine { class StateMachine {
using SharedState = std::shared_ptr<State<T>>;
public: public:
StateMachine(T &owner, const StateFactory<T> &factory) : owner(owner), factory(factory) {}; StateMachine(T &owner, const StateFactory<T> &factory) : owner(owner), factory(factory) {};

View File

@ -48,18 +48,18 @@ class StateSystem {
GetPool<T>().Deserialize(j, getEntity); GetPool<T>().Deserialize(j, getEntity);
} }
template<typename T> template <typename T>
void SetStrictTransitions(bool enabled) { void SetStrictTransitions(bool enabled) {
GetPool<T>().SetStrictTransitions(enabled); GetPool<T>().SetStrictTransitions(enabled);
} }
template<typename T> template <typename T>
void SetAutoTransitions(bool enabled) { void SetAutoTransitions(bool enabled) {
GetPool<T>().SetAutoTransitions(enabled); GetPool<T>().SetAutoTransitions(enabled);
} }
private: private:
template<typename T> template <typename T>
StateMachinePool<T> &GetPool() const { StateMachinePool<T> &GetPool() const {
static StateMachinePool<T> pool; static StateMachinePool<T> pool;
return pool; return pool;