Declaring the type alias in BufferedComponent results in a transactor
for BufferedComponent<T>, which does not match the actual type used in
system dependencies.
#include "accessguard.h"
#include "handle.h"
#include "mspgame_api.h"
-#include "transactor.h"
namespace Msp::Game {
{
public:
using Data = T;
- using Transactor = BasicTransactor<BufferedComponent<T>>;
private:
T data[2];
dep.flags = flags;
if constexpr(std::is_base_of_v<Component, T>)
{
- if constexpr(requires{ typename T::Transactor; })
+ if constexpr(Transactable<T>)
{
- dep.transactor = &stage.get_or_create_transactor<typename T::Transactor>();
+ dep.transactor = &stage.get_or_create_transactor<typename TransactorFor<T>::Type>();
if((flags&UPDATE)==READ_OLD)
dep.transact_mode = Transactor::READ;
else if((flags&UPDATE)==WRITE)
namespace Msp::Game {
+template<typename T>
+concept Transactable =
+ requires(T &x) { typename T::Data; x.prepare_tick(); x.commit_tick(); };
+
class MSPGAME_API Transactor
{
public:
stage.iterate_objects<T>([](T &c){ c.commit_tick(); });
}
+
+template<typename T>
+struct TransactorFor { using Type = BasicTransactor<T>; };
+
+template<typename T>
+ requires requires { typename T::Transactor; }
+struct TransactorFor<T> { using Type = typename T::Transactor; };
+
} // namespace Msp::Game
#endif