Skip to content

Commit

Permalink
Allow world::entity and world::component to be used to retrieve modul…
Browse files Browse the repository at this point in the history
…e ids
  • Loading branch information
SanderMertens committed Oct 10, 2022
1 parent 7837410 commit 435827a
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 14 deletions.
4 changes: 2 additions & 2 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -29485,8 +29485,8 @@ ecs_float_t flecs_counter_record(
if (gauge_value < 0) {
gauge_value = 0; /* Counters are monotonically increasing */
}
flecs_gauge_record(m, t, value - prev);
return value - prev;
flecs_gauge_record(m, t, gauge_value);
return gauge_value;
}

static
Expand Down
7 changes: 3 additions & 4 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16289,7 +16289,7 @@ struct world {

/** Get current tick.
*/
int32_t tick() const {
int64_t tick() const {
const ecs_world_info_t *stats = ecs_get_world_info(m_world);
return stats->frame_count_total;
}
Expand Down Expand Up @@ -17205,7 +17205,7 @@ ecs_ftime_t get_time_scale() const;
/** Get tick
* @return Monotonically increasing frame count.
*/
int32_t get_tick() const;
int64_t get_tick() const;

/** Set target FPS
* @see ecs_set_target_fps
Expand Down Expand Up @@ -20941,7 +20941,6 @@ struct cpp_type_impl {
ecs_assert(world != nullptr, ECS_COMPONENT_NOT_REGISTERED, name);
} else {
ecs_assert(!id || s_id == id, ECS_INCONSISTENT_COMPONENT_ID, NULL);
ecs_assert(s_allow_tag == allow_tag, ECS_INVALID_PARAMETER, NULL);
}

// If no id has been registered yet for the component (indicating the
Expand Down Expand Up @@ -24069,7 +24068,7 @@ inline ecs_ftime_t world::get_time_scale() const {
return stats->time_scale;
}

inline int32_t world::get_tick() const {
inline int64_t world::get_tick() const {
const ecs_world_info_t *stats = ecs_get_world_info(m_world);
return stats->frame_count_total;
}
Expand Down
1 change: 0 additions & 1 deletion include/flecs/addons/cpp/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ struct cpp_type_impl {
ecs_assert(world != nullptr, ECS_COMPONENT_NOT_REGISTERED, name);
} else {
ecs_assert(!id || s_id == id, ECS_INCONSISTENT_COMPONENT_ID, NULL);
ecs_assert(s_allow_tag == allow_tag, ECS_INVALID_PARAMETER, NULL);
}

// If no id has been registered yet for the component (indicating the
Expand Down
2 changes: 1 addition & 1 deletion include/flecs/addons/cpp/mixins/pipeline/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ inline ecs_ftime_t world::get_time_scale() const {
return stats->time_scale;
}

inline int32_t world::get_tick() const {
inline int64_t world::get_tick() const {
const ecs_world_info_t *stats = ecs_get_world_info(m_world);
return stats->frame_count_total;
}
Expand Down
2 changes: 1 addition & 1 deletion include/flecs/addons/cpp/mixins/pipeline/mixin.inl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ecs_ftime_t get_time_scale() const;
/** Get tick
* @return Monotonically increasing frame count.
*/
int32_t get_tick() const;
int64_t get_tick() const;

/** Set target FPS
* @see ecs_set_target_fps
Expand Down
2 changes: 1 addition & 1 deletion include/flecs/addons/cpp/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct world {

/** Get current tick.
*/
int32_t tick() const {
int64_t tick() const {
const ecs_world_info_t *stats = ecs_get_world_info(m_world);
return stats->frame_count_total;
}
Expand Down
4 changes: 2 additions & 2 deletions src/addons/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ ecs_float_t flecs_counter_record(
if (gauge_value < 0) {
gauge_value = 0; /* Counters are monotonically increasing */
}
flecs_gauge_record(m, t, value - prev);
return value - prev;
flecs_gauge_record(m, t, gauge_value);
return gauge_value;
}

static
Expand Down
4 changes: 3 additions & 1 deletion test/cpp_api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,9 @@
"module_tag_on_namespace",
"dtor_on_fini",
"implicit_module",
"module_in_namespace_w_root_name"
"module_in_namespace_w_root_name",
"module_as_entity",
"module_as_component"
]
}, {
"id": "ImplicitComponents",
Expand Down
20 changes: 20 additions & 0 deletions test/cpp_api/src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,23 @@ void Module_module_in_namespace_w_root_name() {
test_assert(p != 0);
test_assert(p == p_lookup);
}

void Module_module_as_entity() {
flecs::world world;

auto m = world.import<ns::SimpleModule>();
test_assert(m != 0);

auto e = world.entity<ns::SimpleModule>();
test_assert(m == e);
}

void Module_module_as_component() {
flecs::world world;

auto m = world.import<ns::SimpleModule>();
test_assert(m != 0);

auto e = world.component<ns::SimpleModule>();
test_assert(m == e);
}
12 changes: 11 additions & 1 deletion test/cpp_api/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,8 @@ void Module_module_tag_on_namespace(void);
void Module_dtor_on_fini(void);
void Module_implicit_module(void);
void Module_module_in_namespace_w_root_name(void);
void Module_module_as_entity(void);
void Module_module_as_component(void);

// Testsuite 'ImplicitComponents'
void ImplicitComponents_add(void);
Expand Down Expand Up @@ -4265,6 +4267,14 @@ bake_test_case Module_testcases[] = {
{
"module_in_namespace_w_root_name",
Module_module_in_namespace_w_root_name
},
{
"module_as_entity",
Module_module_as_entity
},
{
"module_as_component",
Module_module_as_component
}
};

Expand Down Expand Up @@ -5143,7 +5153,7 @@ static bake_test_suite suites[] = {
"Module",
NULL,
NULL,
9,
11,
Module_testcases
},
{
Expand Down

0 comments on commit 435827a

Please sign in to comment.