From ee2c9f5da033356b6901ff442749c7253e5aff45 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 31 Mar 2025 14:59:33 +0300 Subject: [PATCH] Use a different way of determining the default transactor of a component Declaring the type alias in BufferedComponent results in a transactor for BufferedComponent, which does not match the actual type used in system dependencies. --- source/game/component.h | 2 -- source/game/system.h | 4 ++-- source/game/transactor.h | 12 ++++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/source/game/component.h b/source/game/component.h index 7250660..372e8d9 100644 --- a/source/game/component.h +++ b/source/game/component.h @@ -5,7 +5,6 @@ #include "accessguard.h" #include "handle.h" #include "mspgame_api.h" -#include "transactor.h" namespace Msp::Game { @@ -31,7 +30,6 @@ class BufferedComponent: public Component { public: using Data = T; - using Transactor = BasicTransactor>; private: T data[2]; diff --git a/source/game/system.h b/source/game/system.h index 51b032b..84671c2 100644 --- a/source/game/system.h +++ b/source/game/system.h @@ -105,9 +105,9 @@ inline void System::declare_dependency(DependencyFlags flags) dep.flags = flags; if constexpr(std::is_base_of_v) { - if constexpr(requires{ typename T::Transactor; }) + if constexpr(Transactable) { - dep.transactor = &stage.get_or_create_transactor(); + dep.transactor = &stage.get_or_create_transactor::Type>(); if((flags&UPDATE)==READ_OLD) dep.transact_mode = Transactor::READ; else if((flags&UPDATE)==WRITE) diff --git a/source/game/transactor.h b/source/game/transactor.h index d278a9a..93767f3 100644 --- a/source/game/transactor.h +++ b/source/game/transactor.h @@ -7,6 +7,10 @@ namespace Msp::Game { +template +concept Transactable = + requires(T &x) { typename T::Data; x.prepare_tick(); x.commit_tick(); }; + class MSPGAME_API Transactor { public: @@ -84,6 +88,14 @@ void BasicTransactor::commit(Mode mode) stage.iterate_objects([](T &c){ c.commit_tick(); }); } + +template +struct TransactorFor { using Type = BasicTransactor; }; + +template + requires requires { typename T::Transactor; } +struct TransactorFor { using Type = typename T::Transactor; }; + } // namespace Msp::Game #endif -- 2.45.2