BeanCheeseBurrito/Flecs.NET

Support for tick sources?

miguno opened this issue · 2 comments

miguno commented

Are tick sources supported yet?

Here is a C code example, which is useful to ensure that multiple systems are kept in-sync with regard to timing/ticks:

// Create a tick source to be shared across all systems
ecs_entity_t tick_source = ecs_set_interval(world, 0, tick_interval_secs);

// Set tick source for systems
ecs_set_tick_source(world, ecs_id(Move), tick_source);
ecs_set_tick_source(world, ecs_id(Transform), tick_source);

Yes, tick sources are supported. You can use the timer struct to set your tick source's properties and pass it into a RoutineBuilder using TickSource. In the next release, I'll add an overload to TickSource that takes a timer argument instead of an entity.

using System;
using Flecs.NET.Core;

using World world = World.Create();

// Run the system roughly every second.
Timer tickSource = world.Timer().Interval(1);

Routine routine = world.Routine(
    routine: world.RoutineBuilder().TickSource(tickSource.Entity),
    callback: (Iter it) => Console.WriteLine("1 second has passed")
);

world.App().Run();
miguno commented

Thank you!

This would be a welcome addition to the docs, too.