Merge branch 'lang/foundations' into lang/uifree

This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 00:20:51 +03:00
commit c2a5df4be8
2 changed files with 82 additions and 1 deletions

View file

@ -20,6 +20,16 @@ export function wildlife_turned(wildlife_st: WildlifeState) -> int { return wild
export function wildlife_turned_wet(wildlife_st: WildlifeState) -> int { return wildlife_st.wl_turned_wet } export function wildlife_turned_wet(wildlife_st: WildlifeState) -> int { return wildlife_st.wl_turned_wet }
export function wildlife_turned_steep(wildlife_st: WildlifeState) -> int { return wildlife_st.wl_turned_steep } export function wildlife_turned_steep(wildlife_st: WildlifeState) -> int { return wildlife_st.wl_turned_steep }
# a climb is judged over half a metre ahead, not one frame's step: a few centimetres of the drawn
# ground rise steeply over a pebble a walker steps across, and a frame's step shrinks with the rate
const WL_LOOK: float = 0.5
function wl_climb(a: WildAnimal, nx: float, nz: float) -> float {
let dx = nx - a.x
let dz = nz - a.z
let l = Math.sqrt(dx * dx + dz * dz)
return WildlifeWorld.ground(a.x + dx / l * WL_LOOK, a.z + dz / l * WL_LOOK) - a.y
}
function wl_step(wildlife_st: mut WildlifeState, a: WildAnimal, dt: float) -> bool { function wl_step(wildlife_st: mut WildlifeState, a: WildAnimal, dt: float) -> bool {
let d = a.speed * dt let d = a.speed * dt
if d < 0.0001 { return false } if d < 0.0001 { return false }
@ -33,7 +43,7 @@ function wl_step(wildlife_st: mut WildlifeState, a: WildAnimal, dt: float) -> bo
let nh = WildlifeWorld.ground(nx, nz) let nh = WildlifeWorld.ground(nx, nz)
let moved = Math.abs(nx - a.x) + Math.abs(nz - a.z) let moved = Math.abs(nx - a.x) + Math.abs(nz - a.z)
let wet = nh < WildlifeWorld.water(nx, nz) + 0.6 let wet = nh < WildlifeWorld.water(nx, nz) + 0.6
let steep = nh - a.y > d * 1.2 let steep = moved > 0.0001 and wl_climb(a, nx, nz) > WL_LOOK * 1.2
if wet or steep or moved < d * 0.2 { if wet or steep or moved < d * 0.2 {
if wet { wildlife_st.wl_turned_wet += 1 } else if steep { wildlife_st.wl_turned_steep += 1 } if wet { wildlife_st.wl_turned_wet += 1 } else if steep { wildlife_st.wl_turned_steep += 1 }
a.yaw = a.yaw + Math.deg_to_rad(75.0) a.yaw = a.yaw + Math.deg_to_rad(75.0)

View file

@ -0,0 +1,71 @@
# climb_test.ludic - a climb is judged over half a metre ahead: a pebble's few centimetres of steep
# ground are walked over, at any frame rate, and a wall is still turned from
import "ludic.wildlife"
import "ludic.base"
import "fake"
program ClimbTest {
numbers float
bind WildlifeWorld {
ground: fn ct_ground
water: fn fk_water
forest: fn fk_forest
sight: fn fk_sight
push: fn fk_push
pushed_x: fn fk_pushed_x
pushed_z: fn fk_pushed_z
players: fn fk_players
player_on: fn fk_player_on
player_x: fn fk_x
player_y: fn fk_y
player_z: fn fk_z
hidden: fn fk_is_hidden
noise: fn fk_noise_of
scent: fn fk_scent_of
stillness: fn fk_still_of
wind: fn fk_wind_of
wind_dir: fn fk_wind_to
winterness: fn fk_winter_of
about: fn fk_about_of
per_range: fn fk_one
lures: fn fk_count
lure: fn fk_lure
present: fn fk_present
born: fn fk_on_born
spot: fn fk_spot
}
# flat at 10 m, a pebble 4 cm high and 2 cm across at z = -10, a 3 m wall at z = -30
function ct_ground(x: float, z: float) -> float {
if z < -30.0 { return 13.0 }
if z < -9.99 and z > -10.01 { return 10.04 }
return 10.0
}
function walk(wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState, dt: float) -> float {
fk_setup(wildlife_st, wildlife_tests_fake_st)
let a = wildlife_make(wildlife_st, 0, 0.0, 0.0, false, 0.0, 0, 1.0, 1)
wildlife_tests_fake_st.fk_px[0] = 400.0
wildlife_tests_fake_st.fk_pz[0] = 0.0
wildlife_tests_fake_st.fk_hidden = true
a.state = WILD_WANDER
a.tx = 0.0
a.tz = -100.0
a.timer = 300.0
var south = 0.0
for k in 0 .. int(40.0 / dt) {
wildlife_tick(wildlife_st, dt, 0.0)
south = Math.min(south, a.z)
}
return south
}
test "a pebble is walked over and a wall is not, at 60 Hz" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) {
let s = walk(wildlife_st, wildlife_tests_fake_st, 1.0 / 60.0)
expect(s < -12.0)
expect(s > -30.5)
}
test "and the same at 240 Hz" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) {
let s = walk(wildlife_st, wildlife_tests_fake_st, 1.0 / 240.0)
expect(s < -12.0)
expect(s > -30.5)
}
}