Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@

### Changed

- Remove redundant runtime-table writes after mutating morph weights.

- Keep entity runtime tables private to their subsystems. Read individual UI,
visibility, audio, and character controller results instead of mutating their
stores. Use `set_scroll_position`, focus operations, and LDtk respawn operations
for writes. Scroll positions and contact arrays are snapshots; `AudioSink`
exposes playback methods without public fields. Hide the internal `Focused`
and `LdtkRespawn` marker types.

- Store engine runtime state, event buses, and event reader cursors in their
owning World resources instead of global World-ID maps.
- Index entity runtime data by reusable slots with full-handle validation,
insertion-ordered traversal, and explicit cleanup of orphan generations.
Read physics results with `resolved_velocity(entity)`.
- Use arrays for animation graph and glTF node indices, typed integer keys for
spatial/autotile grids and physics handles, and sets for membership tracking.
Remove unnecessary iteration snapshots and defer example entity deletions.
- Filter animation fades in place and snapshot observer subscriptions when
callbacks can modify them during dispatch.

- Destructure tuple elements directly in `for` patterns across the engine,
backend, examples, and tests, removing temporary tuple bindings and projections.

Expand Down
49 changes: 27 additions & 22 deletions examples/pixeladventure/systems.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,10 @@ fn player_controller_system(world : @ecs.World) -> Unit {
return
}

let resolved_velocity = @physics2d.resolved_velocities()
.get(session.player)
.map_or(@math.Vec2::zero(), fn(velocity) { velocity.0 })
let resolved_velocity = @physics2d.resolved_velocity(session.player).map_or(
@math.Vec2::zero(),
fn(velocity) { velocity.0 },
)
let grounded = @physics2d.is_grounded(session.player)
let velocity = player_motion_base_velocity(
resolved_velocity,
Expand Down Expand Up @@ -496,25 +497,26 @@ fn player_bird_contact_system(world : @ecs.World) -> Unit {
guard entity_rect(session.player) is Some(player_rect) else { return }

let fixed_delta = @time.fixed_delta()
let player_resolved_velocity = @physics2d.resolved_velocities()
.get(session.player)
.map_or(@math.Vec2::zero(), fn(v) { v.0 })
let player_resolved_velocity = @physics2d.resolved_velocity(session.player).map_or(
@math.Vec2::zero(),
fn(v) { v.0 },
)
let player_prev_rect = player_rect.shift(
player_resolved_velocity.scalar_mul(-fixed_delta),
)

for (bird_entity, _) in birds().to_array() {
for bird_entity, bird in birds() {
if !bird_entity.is_alive() {
continue
}
guard birds().get(bird_entity) is Some(bird) else { continue }
if bird.is_hurt {
continue
}
guard entity_rect(bird_entity) is Some(bird_rect) else { continue }
let bird_resolved_velocity = @physics2d.resolved_velocities()
.get(bird_entity)
.map_or(@math.Vec2::zero(), fn(v) { v.0 })
let bird_resolved_velocity = @physics2d.resolved_velocity(bird_entity).map_or(
@math.Vec2::zero(),
fn(v) { v.0 },
)
let bird_prev_rect = bird_rect.shift(
bird_resolved_velocity.scalar_mul(-fixed_delta),
)
Expand All @@ -539,27 +541,29 @@ fn player_bird_contact_system(world : @ecs.World) -> Unit {
}

///|
fn bird_patrol_system(_world : @ecs.World) -> Unit {
for (bird_entity, _) in birds().to_array() {
fn bird_patrol_system(world : @ecs.World) -> Unit {
let commands = @ecs.commands(world)
for bird_entity, bird in birds() {
if !bird_entity.is_alive() {
continue
}
guard birds().get(bird_entity) is Some(bird) else { continue }
if bird.is_hurt {
@physics2d.linear_velocities().set(bird_entity, @math.Vec2::zero())
if @physics2d.colliders().get(bird_entity) is Some(collider) {
collider.active = false
}
play_bird_animation(bird_entity, bird)
if sprite_animation_finished(bird_entity) {
ignore(bird_entity.delete())
commands.delete(bird_entity)
}
continue
}

let resolved_x = @physics2d.resolved_velocities()
.get(bird_entity)
.map_or(0.0, fn(v) { v.0.x })
let resolved_x = @physics2d.resolved_velocity(bird_entity).map_or(0.0, fn(
v,
) {
v.0.x
})
let blocked = match bird.direction {
Left => resolved_x > -BIRD_SPEED * 0.5
Right => resolved_x < BIRD_SPEED * 0.5
Expand All @@ -583,30 +587,31 @@ fn bird_patrol_system(_world : @ecs.World) -> Unit {

///|
fn trigger_system(world : @ecs.World) -> Unit {
let commands = @ecs.commands(world)
guard (world.get_resource() : GameSession?) is Some(session) else { return }
if player_is_frozen(session.result) {
return
}

for (flag_entity, _) in flags().to_array() {
for flag_entity in flags().keys() {
if !flag_entity.is_alive() {
continue
}
if @physics2d.get_contains(flag_entity).contains(session.player) {
session.score += 100
session.result = Some(Win)
ignore(flag_entity.delete())
commands.delete(flag_entity)
}
}

for (apple_entity, _) in apples().to_array() {
for apple_entity in apples().keys() {
if !apple_entity.is_alive() {
continue
}
if @physics2d.get_contains(apple_entity).contains(session.player) {
session.score += 10
play_sfx(coin_sound(), session.volume_on)
ignore(apple_entity.delete())
commands.delete(apple_entity)
}
}
}
Expand Down
128 changes: 69 additions & 59 deletions examples/survivors/enemy.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -183,58 +183,66 @@ fn reset_wave_state() -> Unit {
}

///|
let enemy_data : Map[EnemyType, EnemyData] = {
let data = Map([])
data.set(Creeper, {
health: 1.0,
speed: 60.0,
points: 10,
right_animation: creeper_right_animation,
left_animation: creeper_left_animation,
})
data.set(Icecream, {
health: 2.0,
speed: 90.0,
points: 20,
right_animation: icecream_right_animation,
left_animation: icecream_left_animation,
})
data.set(Orc, {
health: 3.0,
speed: 75,
points: 30,
right_animation: orc_right_animation,
left_animation: orc_left_animation,
})
data.set(Skull, {
health: 5.0,
speed: 60.0,
points: 40,
right_animation: skull_right_animation,
left_animation: skull_left_animation,
})
data.set(Teleman, {
health: 20.0,
speed: 60.0,
points: 80,
right_animation: teleman_right_animation,
left_animation: teleman_left_animation,
})
data.set(Devil, {
health: 8.0,
speed: 90.0,
points: 50,
right_animation: devil_right_animation,
left_animation: devil_left_animation,
})
data.set(Pirate, {
health: 500.0,
speed: 60.0,
points: 200,
right_animation: pirate_right_animation,
left_animation: pirate_left_animation,
})
data
let creeper_data : EnemyData = {
health: 1.0,
speed: 60.0,
points: 10,
right_animation: creeper_right_animation,
left_animation: creeper_left_animation,
}

///|
let icecream_data : EnemyData = {
health: 2.0,
speed: 90.0,
points: 20,
right_animation: icecream_right_animation,
left_animation: icecream_left_animation,
}

///|
let orc_data : EnemyData = {
health: 3.0,
speed: 75,
points: 30,
right_animation: orc_right_animation,
left_animation: orc_left_animation,
}

///|
let skull_data : EnemyData = {
health: 5.0,
speed: 60.0,
points: 40,
right_animation: skull_right_animation,
left_animation: skull_left_animation,
}

///|
let teleman_data : EnemyData = {
health: 20.0,
speed: 60.0,
points: 80,
right_animation: teleman_right_animation,
left_animation: teleman_left_animation,
}

///|
let devil_data : EnemyData = {
health: 8.0,
speed: 90.0,
points: 50,
right_animation: devil_right_animation,
left_animation: devil_left_animation,
}

///|
let pirate_data : EnemyData = {
health: 500.0,
speed: 60.0,
points: 200,
right_animation: pirate_right_animation,
left_animation: pirate_left_animation,
}

///|
Expand Down Expand Up @@ -339,7 +347,7 @@ priv struct Enemy {
}

///|
#derive(Eq, Hash)
#derive(Eq)
enum EnemyType {
Creeper
Icecream
Expand All @@ -353,9 +361,6 @@ enum EnemyType {
///|
pub extend EnemyType with Eq::{not_equal, equal}

///|
pub extend EnemyType with Hash::{hash, hash_combine}

///|
fn enemies() -> @ecs.ComponentStore[Enemy] {
@ecs.components()
Expand Down Expand Up @@ -395,9 +400,14 @@ fn play_enemy_animation_state(

///|
fn get_enemy_data(enemy_type : EnemyType) -> EnemyData {
match enemy_data.get(enemy_type) {
Some(data) => data
None => abort("Enemy data not found")
match enemy_type {
Creeper => creeper_data
Icecream => icecream_data
Orc => orc_data
Skull => skull_data
Teleman => teleman_data
Devil => devil_data
Pirate => pirate_data
}
}

Expand Down
4 changes: 1 addition & 3 deletions examples/survivors/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ pub fn run() -> Unit
// Errors

// Types and methods
#derive(Eq, Hash)
#derive(Eq)
type EnemyType
pub fn EnemyType::equal(Self, Self) -> Bool
pub fn EnemyType::hash(Self) -> Int32
pub fn EnemyType::hash_combine(Self, Hasher) -> Unit
pub fn EnemyType::not_equal(Self, Self) -> Bool

#derive(Eq)
Expand Down
3 changes: 2 additions & 1 deletion selene-core/src/a11y/actions.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ fn dispatch_action(
fn process_action_requests() -> Unit {
for request in pending_action_requests {
guard request.target_tree() == a11y_tree_id else { continue }
guard current_node_entities.get(request.target_node()) is Some(entity) else {
guard a11y_runtime().current_node_entities.get(request.target_node())
is Some(entity) else {
continue
}
dispatch_action(entity, request.action(), request.data())
Expand Down
1 change: 1 addition & 0 deletions selene-core/src/a11y/moon.pkg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
"moonbitlang/core/set",
"Milky2018/moon_accesskit",
"Milky2018/selene/ecs",
"Milky2018/selene/ui",
Expand Down
Loading
Loading