@@ -61,37 +61,34 @@ namespace enemy_animation {
6161// BugLarge walk(up)
6262
6363inline FlecsRegistry register_enemy_animation_system ([](flecs::world& world) {
64- world.system <const HitPoints, const Velocity2D, const MovementSpeed, const AnimationFrameOffset, const DeathTimer, const HitReactionTimer, HFlipTimer, VFlipTimer, RenderingCustomData >(" Enemy Animation" )
64+ world.system <HFlipTimer, VFlipTimer, RenderingCustomData, const EnemyAnimationSettings, const HitPoints, const Velocity2D, const MovementSpeed, const AnimationFrameOffset, const DeathTimer, const HitReactionTimer>(" Enemy Animation" )
6565 .with (flecs::IsA, world.lookup (" Enemy" ))
6666 .kind (flecs::PostUpdate)
6767 .run ([](flecs::iter& it) {
68- const EnemyAnimationSettings* animation_settings = it.world ().try_get <EnemyAnimationSettings>();
69- if (animation_settings == nullptr ) {
70- return ;
71- }
72-
73- const godot::real_t animation_interval = animation_settings->animation_interval ;
74- const godot::real_t animation_speed = animation_interval > 0.0 ? godot::real_t (1.0 ) / animation_interval : godot::real_t (0.0 );
75- const godot::real_t animation_range = animation_settings->walk_animation_range ;
76- const godot::real_t death_animation_frame_count = animation_settings->death_animation_frame_count ;
77- const godot::real_t death_animation_range = death_animation_frame_count - godot::real_t (1.0 );
78- const godot::real_t frame_interval = animation_interval > 0.0 ? animation_interval : godot::real_t (0.001 );
79- const godot::real_t up_direction_frame_offset = animation_settings->up_direction_frame_offset ;
80- const godot::real_t horizontal_flip_cooldown = godot::Math::max (animation_settings->horizontal_flip_cooldown , godot::real_t (0.0 ));
81- const godot::real_t vertical_flip_cooldown = godot::Math::max (animation_settings->vertical_flip_cooldown , godot::real_t (0.0 ));
82- const godot::real_t nominal_movement_speed = animation_settings->nominal_movement_speed ;
83- const godot::real_t animation_offset_fraction_range = godot::Math::max (animation_settings->animation_offset_fraction_range , godot::real_t (0.0 ));
84-
8568 while (it.next ()) {
86- flecs::field<const HitPoints> hit_points = it.field <const HitPoints>(0 );
87- flecs::field<const Velocity2D> velocities = it.field <const Velocity2D>(1 );
88- flecs::field<const MovementSpeed> movement_speeds = it.field <const MovementSpeed>(2 );
89- flecs::field<const AnimationFrameOffset> frame_offsets = it.field <const AnimationFrameOffset>(3 );
90- flecs::field<const DeathTimer> death_timer = it.field <const DeathTimer>(4 );
91- flecs::field<const HitReactionTimer> hit_reaction_timers = it.field <const HitReactionTimer>(5 );
92- flecs::field<HFlipTimer> horizontal_flip_timers = it.field <HFlipTimer>(6 );
93- flecs::field<VFlipTimer> vertical_flip_timers = it.field <VFlipTimer>(7 );
94- flecs::field<RenderingCustomData> custom_data_field = it.field <RenderingCustomData>(8 );
69+ flecs::field<HFlipTimer> horizontal_flip_timers = it.field <HFlipTimer>(0 );
70+ flecs::field<VFlipTimer> vertical_flip_timers = it.field <VFlipTimer>(1 );
71+ flecs::field<RenderingCustomData> custom_data_field = it.field <RenderingCustomData>(2 );
72+ flecs::field<const EnemyAnimationSettings> animation_settings_field = it.field <const EnemyAnimationSettings>(3 ); // singleton
73+ flecs::field<const HitPoints> hit_points = it.field <const HitPoints>(4 );
74+ flecs::field<const Velocity2D> velocities = it.field <const Velocity2D>(5 );
75+ flecs::field<const MovementSpeed> movement_speeds = it.field <const MovementSpeed>(6 );
76+ flecs::field<const AnimationFrameOffset> frame_offsets = it.field <const AnimationFrameOffset>(7 );
77+ flecs::field<const DeathTimer> death_timer = it.field <const DeathTimer>(8 );
78+ flecs::field<const HitReactionTimer> hit_reaction_timers = it.field <const HitReactionTimer>(9 );
79+
80+ const EnemyAnimationSettings* animation_settings = &animation_settings_field[0 ];
81+ const godot::real_t animation_interval = animation_settings->animation_interval ;
82+ const godot::real_t animation_speed = animation_interval > 0.0 ? godot::real_t (1.0 ) / animation_interval : godot::real_t (0.0 );
83+ const godot::real_t animation_range = animation_settings->walk_animation_range ;
84+ const godot::real_t death_animation_frame_count = animation_settings->death_animation_frame_count ;
85+ const godot::real_t death_animation_range = death_animation_frame_count - godot::real_t (1.0 );
86+ const godot::real_t frame_interval = animation_interval > 0.0 ? animation_interval : godot::real_t (0.001 );
87+ const godot::real_t up_direction_frame_offset = animation_settings->up_direction_frame_offset ;
88+ const godot::real_t horizontal_flip_cooldown = godot::Math::max (animation_settings->horizontal_flip_cooldown , godot::real_t (0.0 ));
89+ const godot::real_t vertical_flip_cooldown = godot::Math::max (animation_settings->vertical_flip_cooldown , godot::real_t (0.0 ));
90+ const godot::real_t nominal_movement_speed = animation_settings->nominal_movement_speed ;
91+ const godot::real_t animation_offset_fraction_range = godot::Math::max (animation_settings->animation_offset_fraction_range , godot::real_t (0.0 ));
9592
9693 const size_t count = it.count ();
9794 for (size_t i = 0 ; i < count; ++i) {
0 commit comments