Skip to content

Commit 78b09c3

Browse files
committed
Update flecs and modules
1 parent 96d1cc8 commit 78b09c3

File tree

10 files changed

+308
-81
lines changed

10 files changed

+308
-81
lines changed

deps/flecs.c

Lines changed: 248 additions & 66 deletions
Large diffs are not rendered by default.

deps/flecs.h

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4219,6 +4219,16 @@ void flecs_component_ids_set(
42194219
int32_t index,
42204220
ecs_entity_t id);
42214221

4222+
/** Query iterator function for trivially cached queries.
4223+
* This operation can be called if an iterator matches the conditions for
4224+
* trivial iteration:
4225+
*
4226+
* @param it The query iterator.
4227+
* @return Whether the query has more results.
4228+
*/
4229+
FLECS_API
4230+
bool flecs_query_trivial_cached_next(
4231+
ecs_iter_t *it);
42224232

42234233
#ifdef FLECS_DEBUG
42244234
/** Check if current thread has exclusive access to world.
@@ -12869,9 +12879,6 @@ typedef struct ecs_system_t {
1286912879
/** System query */
1287012880
ecs_query_t *query;
1287112881

12872-
/** Entity associated with query */
12873-
ecs_entity_t query_entity;
12874-
1287512882
/** Tick source associated with system */
1287612883
ecs_entity_t tick_source;
1287712884

@@ -12912,8 +12919,6 @@ typedef struct ecs_system_t {
1291212919
int64_t last_frame;
1291312920

1291412921
/* Mixins */
12915-
ecs_world_t *world;
12916-
ecs_entity_t entity;
1291712922
flecs_poly_dtor_t dtor;
1291812923
} ecs_system_t;
1291912924

@@ -27545,6 +27550,16 @@ struct each_delegate : public delegate {
2754527550
self->invoke(iter);
2754627551
}
2754727552

27553+
// Static function that can be used as callback for systems/triggers.
27554+
// Different from run() in that it loops the iterator.
27555+
static void run_each(ecs_iter_t *iter) {
27556+
auto self = static_cast<const each_delegate*>(iter->run_ctx);
27557+
ecs_assert(self != nullptr, ECS_INTERNAL_ERROR, NULL);
27558+
while (iter->next(iter)) {
27559+
self->invoke(iter);
27560+
}
27561+
}
27562+
2754827563
// Create instance of delegate
2754927564
static each_delegate* make(const Func& func) {
2755027565
return FLECS_NEW(each_delegate)(func);
@@ -31916,6 +31931,17 @@ struct node_builder : IBuilder<Base, Components ...>
3191631931
return T(world_, &desc_);
3191731932
}
3191831933

31934+
template <typename Func>
31935+
T run_each(Func&& func) {
31936+
using Delegate = typename _::each_delegate<
31937+
typename std::decay<Func>::type, Components...>;
31938+
auto ctx = FLECS_NEW(Delegate)(FLECS_FWD(func));
31939+
desc_.run = Delegate::run_each;
31940+
desc_.run_ctx = ctx;
31941+
desc_.run_ctx_free = _::free_obj<Delegate>;
31942+
return T(world_, &desc_);
31943+
}
31944+
3191931945
protected:
3192031946
flecs::world_t* world_v() override { return world_; }
3192131947
TDesc desc_;
@@ -32535,6 +32561,9 @@ struct system_builder final : _::system_builder_base<Components...> {
3253532561
ecs_add_id(world, this->desc_.entity, flecs::OnUpdate);
3253632562
#endif
3253732563
}
32564+
32565+
template <typename Func>
32566+
system each(Func&& func);
3253832567
};
3253932568

3254032569
}
@@ -32719,6 +32748,14 @@ inline void system_init(flecs::world& world) {
3271932748
}
3272032749

3272132750
} // namespace _
32751+
32752+
template <typename ... Components>
32753+
template <typename Func>
32754+
inline system system_builder<Components...>::each(Func&& func) {
32755+
// Faster version of each() that iterates the query on the C++ side.
32756+
return this->run_each(FLECS_FWD(func));
32757+
}
32758+
3272232759
} // namespace flecs
3272332760

3272432761
#endif

deps/flecs_components_graphics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ ECS_STRUCT(EcsAtmosphere, {
128128
float rayleigh_scale_height;
129129
float mie_scale_height;
130130
float mie_scatter_dir;
131+
EcsRgb night_color;
131132
});
132133

133134
FLECS_COMPONENTS_GRAPHICS_API

deps/flecs_components_transform.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,9 @@ void FlecsComponentsTransformImport(
3535
ecs_set_hooks(world, EcsTransform3, {
3636
.ctor = flecs_default_ctor
3737
});
38+
39+
ecs_add_pair(world, ecs_id(EcsPosition3), EcsWith, ecs_id(EcsTransform3));
40+
ecs_add_pair(world, ecs_id(EcsRotation3), EcsWith, ecs_id(EcsTransform3));
41+
ecs_add_pair(world, ecs_id(EcsScale3), EcsWith, ecs_id(EcsTransform3));
3842
}
3943

deps/flecs_game.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ void LightControllerSyncIntensity(ecs_iter_t *it) {
631631
static
632632
void TimeOfDayUpdate(ecs_iter_t *it) {
633633
EcsTimeOfDay *tod = ecs_field(it, EcsTimeOfDay, 0);
634-
tod->t += it->delta_time * tod->speed;
634+
tod->t += it->delta_system_time * tod->speed;
635635
}
636636

637637
static
@@ -742,5 +742,10 @@ void FlecsGameLightControllerImport(ecs_world_t *world) {
742742
ecs_add_pair(world, EcsSun, EcsWith, ecs_id(EcsDirectionalLight));
743743
ecs_add_pair(world, EcsSun, EcsWith, ecs_id(EcsRgb));
744744
ecs_add_pair(world, EcsSun, EcsWith, ecs_id(EcsLightIntensity));
745+
746+
ecs_system(world, {
747+
.entity = ecs_id(TimeOfDayUpdate),
748+
.interval = 1.0
749+
});
745750
}
746751

deps/flecs_systems_sokol.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29171,6 +29171,7 @@ typedef struct sokol_global_uniforms_t {
2917129171

2917229172
vec3 sun_direction;
2917329173
vec3 sun_color;
29174+
vec3 night_color;
2917429175
vec3 sun_screen_pos;
2917529176
float sun_intensity;
2917629177

@@ -30128,9 +30129,10 @@ void sokol_run_atmos_pass(
3012830129
glm_mat4_copy(state->uniforms.inv_mat_v, fs_u.inv_mat_vp);
3012930130
glm_vec3_copy(state->uniforms.eye_pos, fs_u.eye_pos);
3013030131
glm_vec3_copy(state->uniforms.sun_direction, fs_u.light_pos);
30131-
fs_u.night_color[0] = 0.001 / 8.0;
30132-
fs_u.night_color[1] = 0.008 / 8.0;
30133-
fs_u.night_color[2] = 0.016 / 8.0;
30132+
glm_vec3_copy((float*)&state->atmosphere->night_color, fs_u.night_color);
30133+
// fs_u.night_color[0] = 0.001 / 8.0;
30134+
// fs_u.night_color[1] = 0.008 / 8.0;
30135+
// fs_u.night_color[2] = 0.016 / 8.0;
3013430136
fs_u.aspect = state->uniforms.aspect;
3013530137
fs_u.offset = 0.05;
3013630138

deps/flecs_systems_transform.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "flecs_systems_transform.h"
22

33
void EcsApplyTransform3(ecs_iter_t *it) {
4-
// printf("---\n");
54
while (ecs_query_next(it)) {
65
EcsTransform3 *m = ecs_field(it, EcsTransform3, 0);
76
EcsTransform3 *m_parent = ecs_field(it, EcsTransform3, 1);
@@ -10,9 +9,6 @@ void EcsApplyTransform3(ecs_iter_t *it) {
109
EcsScale3 *s = ecs_field(it, EcsScale3, 4);
1110
int i;
1211

13-
14-
// printf("%llu\n", it->priv_.iter.query.node);
15-
1612
if (!m_parent) {
1713
if (ecs_field_is_self(it, 3)) {
1814
for (i = 0; i < it->count; i ++) {

etc/flecs_explorer.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

etc/flecs_explorer.wasm

89 Bytes
Binary file not shown.

etc/sokol/shaders/atmosphere_frag.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ void main() {
4141
mie_scatter_dir // Mie preferred scattering direction
4242
);
4343

44-
frag_color = max(vec4(atmos, 1.0), vec4(u_night_color, 1.0));
44+
frag_color = vec4(atmos, 1.0) + vec4(u_night_color, 1.0);
4545
}

0 commit comments

Comments
 (0)