Skip to content
Flecs v4.1
systems/delta_time

  • C

    View on GitHub

    1#include <delta_time.h>
    2#include <stdio.h>
    3
    4void PrintDeltaTime(ecs_iter_t *it) {
    5 // Print delta_time. The same value is passed to all systems.
    6 printf("delta_time: %f\n", (double)it->delta_time);
    7}
    8
    9int main(int argc, char *argv[]) {
    10 ecs_world_t *ecs = ecs_init_w_args(argc, argv);
    11
    12 // Create system that prints delta_time. This system doesn't query for any
    13 // components which means it won't match any entities, but will still be ran
    14 // once for each call to ecs_progress.
    15 ECS_SYSTEM(ecs, PrintDeltaTime, EcsOnUpdate, 0);
    16
    17 // Call progress with 0.0f for the delta_time parameter. This will cause
    18 // ecs_progress to measure the time passed since the last frame. The
    19 // delta_time of the first frame is a best guess (16ms).
    20 ecs_progress(ecs, 0.0f);
    21
    22 // The following calls should print a delta_time of approximately 100ms
    23
    24 ecs_os_sleep(0, 100 * 1000 * 1000);
    25 ecs_progress(ecs, 0.0f);
    26
    27 ecs_os_sleep(0, 100 * 1000 * 1000);
    28 ecs_progress(ecs, 0.0f);
    29
    30 return ecs_fini(ecs);
    31}
    const ecs_entity_t EcsOnUpdate
    OnUpdate pipeline phase.
    FLECS_API bool ecs_progress(ecs_world_t *world, ecs_ftime_t delta_time)
    Progress a world.
    #define ECS_SYSTEM(world, id, phase,...)
    Declare and define a system.
    Definition system.h:263
    struct ecs_world_t ecs_world_t
    A world is the container for all ECS data and supporting features.
    Definition flecs.h:439
    int ecs_fini(ecs_world_t *world)
    Delete a world.
    ecs_world_t * ecs_init_w_args(int argc, char *argv[])
    Create a new world with arguments.
    Iterator.
    Definition flecs.h:1183
    float delta_time
    Time elapsed since last frame.
    Definition flecs.h:1228

  • C++

    View on GitHub

    1#include <delta_time.h>
    2#include <iostream>
    3
    4int main(int, char *[]) {
    5 flecs::world ecs;
    6
    7 // Create system that prints delta_time. This system doesn't query for any
    8 // components which means it won't match any entities, but will still be ran
    9 // once for each call to ecs_progress.
    10 ecs.system()
    11 .run([](flecs::iter& it) {
    12 std::cout << "delta_time: " << it.delta_time() << std::endl;
    13 });
    14
    15 // Call progress with 0.0f for the delta_time parameter. This will cause
    16 // ecs_progress to measure the time passed since the last frame. The
    17 // delta_time of the first frame is a best guess (16ms).
    18 ecs.progress();
    19
    20 // The following calls should print a delta_time of approximately 100ms
    21
    22 ecs_os_sleep(0, 100 * 1000 * 1000);
    23 ecs.progress();
    24
    25 ecs_os_sleep(0, 100 * 1000 * 1000);
    26 ecs.progress();
    27}
    flecs::system system(flecs::entity e) const
    Upcast an entity to a system.
    Definition impl.hpp:181
    bool progress(ecs_ftime_t delta_time=0.0) const
    Progress the world one tick.
    Definition impl.hpp:47
    Class for iterating over query results.
    Definition iter.hpp:68
    ecs_ftime_t delta_time() const
    Get the time elapsed since the last frame.
    Definition iter.hpp:132
    system & run(Func &&func)
    Replace the system's run callback.
    Definition impl.hpp:108
    The world.
    Definition world.hpp:129