diff --git a/packages/ludic.zones/README.md b/packages/ludic.zones/README.md index 979d7f82..e4ae25cd 100644 --- a/packages/ludic.zones/README.md +++ b/packages/ludic.zones/README.md @@ -1,7 +1,7 @@ # ludic.zones Where a world is simulated: a disc per player - `(x, z, r)`, `r = zones_radius(fog)`, that is the -fog distance plus 40 m and never under 150 m, 900 m with no fog - and the discs that overlap merged +fog distance plus 40 m, never under 150 m nor over 900 m, and 900 m with no fog - and the discs that overlap merged into clusters with a bounding circle. Uses `ludic.base` and nothing else. - `zones_set(pid, x, z, r)`, `zones_clear(pid)`, `zones_reset()`; `zones_merge()` once a frame diff --git a/packages/ludic.zones/state.ludic b/packages/ludic.zones/state.ludic index 48a76c6e..6ea8fba4 100644 --- a/packages/ludic.zones/state.ludic +++ b/packages/ludic.zones/state.ludic @@ -18,10 +18,11 @@ export state ZonesState { zn_cn: words = words(ZONES_MAX) # how many discs it holds } -# a player's radius from how far they see: fog_dist <= 0 is no fog +# a player's radius from how far they see: fog_dist <= 0 is no fog; never past no fog's, so a far fog +# never keeps more of the world than none does export function zones_radius(fog_dist: float) -> float { if fog_dist <= 0.0 { return ZONES_NO_FOG } - return Math.max(fog_dist + ZONES_PAST_FOG, ZONES_LEAST) + return Math.min(Math.max(fog_dist + ZONES_PAST_FOG, ZONES_LEAST), ZONES_NO_FOG) } export function zones_set(zones_st: mut ZonesState, pid: int, x: float, z: float, r: float) -> void { diff --git a/packages/ludic.zones/tests/zones_test.ludic b/packages/ludic.zones/tests/zones_test.ludic index 1206f13b..a8348ea3 100644 --- a/packages/ludic.zones/tests/zones_test.ludic +++ b/packages/ludic.zones/tests/zones_test.ludic @@ -44,9 +44,11 @@ program ZonesTest { expect(Math.abs(zones_nearest(zones_st, 350.0, 100.0) - 100.0) < 0.001) } - test "a player's radius: past the fog, never under the least, the horizon with none" (zones_st: mut ZonesState) { + test "a player's radius: past the fog, never under the least nor over no fog's" (zones_st: mut ZonesState) { expect(zones_radius(0.0) == ZONES_NO_FOG) expect(zones_radius(30.0) == ZONES_LEAST) expect(zones_radius(500.0) == 540.0) + expect(zones_radius(1000.0) == ZONES_NO_FOG) # a kilometre's fog keeps no more than none + expect(zones_radius(860.0) == ZONES_NO_FOG) } }