return active;
}
-void System::begin_tick()
-{
- System *&active = get_active_ptr();
- if(active)
- throw logic_error("System::active != nullptr");
- active = this;
-
- for(const Dependency &d: dependencies)
- if(d.transactor)
- d.transactor->prepare(d.transact_mode);
-}
-
-void System::end_tick()
-{
- for(const Dependency &d: dependencies)
- if(d.transactor)
- d.transactor->commit(d.transact_mode);
-
- System *&active = get_active_ptr();
- if(active==this)
- active = nullptr;
-}
-
void System::deferred_tick()
{
for(const auto &f: deferred_queue)
DependencyFlags get_flags() const { return flags; }
const Reflection::ClassBase &get_type() const { return type; }
- };
-
- class Activator: public NonCopyable
- {
- private:
- System &system;
-
- public:
- Activator(System &s): system(s) { system.begin_tick(); }
- ~Activator() { system.end_tick(); }
+ Transactor *get_transactor() const { return transactor; }
+ Transactor::Mode get_transact_mode() const { return transact_mode; }
};
protected:
public:
virtual void early_tick() { }
- void begin_tick();
virtual void tick(Time::TimeDelta) = 0;
- void end_tick();
virtual void deferred_tick();
protected:
for(size_t i=0; i<nodes.size(); ++i)
if(!(pending&nodes[i].prerequisites))
{
- System::Activator act(*nodes[i].system);
- try
- {
- nodes[i].system->tick(dt);
- }
- catch(const invalid_access &exc)
- {
- throw invalid_access(format("%s by %s", exc.what(), nodes[i].type->get_name()));
- }
+ run_system(i, dt);
pending &= ~(1ULL<<i);
}
}
}
+void SystemScheduler::run_system(size_t index, Time::TimeDelta dt)
+{
+ System &sys = *nodes[index].system;
+ for(const System::Dependency &d: sys.get_dependencies())
+ if(Transactor *tract = d.get_transactor())
+ tract->prepare(d.get_transact_mode());
+
+ try
+ {
+ sys.tick(dt);
+ }
+ catch(const invalid_access &exc)
+ {
+ throw invalid_access(format("%s by %s", exc.what(), nodes[index].type->get_name()));
+ }
+
+ for(const System::Dependency &d: sys.get_dependencies())
+ if(Transactor *tract = d.get_transactor())
+ tract->commit(d.get_transact_mode());
+}
+
} // namespace Msp::Game
const std::vector<GraphNode> &get_graph() const { return nodes; }
void run(Time::TimeDelta);
+private:
+ void run_system(std::size_t, Time::TimeDelta);
};
} // namespace Msp::Game