ludic.shop, ludic.net: nothing made per tick - the week's lists and dice reused, the net's facts from a ring, the room's watch address made once, pools and kept lists through kept_push; what runs once per host, join, room or guest says so in @alloc_ok

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 16:09:32 +03:00
parent f5834f8f63
commit 4b533b5ff6
18 changed files with 86 additions and 23 deletions

View file

@ -25,11 +25,12 @@ function shop_pick_one(shop_st: ShopState, v: int, taken: []int) -> int {
}
function shop_roll_vendor(shop_st: mut ShopState, v: int) -> void {
let taken = new []int
let taken = shop_st.shop_taken
List.clear(taken)
for k in 0 .. shop_st.shop_wants_n {
let it = shop_pick_one(shop_st, v, taken)
shop_st.shop_want_list[v * shop_st.shop_wants_n + k] = it
if it >= 0 { push(taken, it) }
if it >= 0 { kept_push(taken, it) }
}
shop_st.shop_full_list[v] = shop_pick_one(shop_st, v, taken)
}
@ -39,11 +40,8 @@ export function shop_roll(shop_st: mut ShopState) -> void {
let week = shop_week(shop_st)
if week == shop_st.shop_week_rolled and shop_st.shop_want_list != null { return }
shop_st.shop_week_rolled = week
shop_st.shop_dice = rng_new(shop_st.shop_seed + week * 37)
shop_st.shop_want_list = new []int
shop_st.shop_full_list = new []int
for i in 0 .. shop_vendors(shop_st) * shop_st.shop_wants_n { push(shop_st.shop_want_list, -1) }
for v in 0 .. shop_vendors(shop_st) { push(shop_st.shop_full_list, -1) }
rng_seed(shop_st.shop_dice, shop_st.shop_seed + week * 37)
shop_lists_empty(shop_st)
if shop_items(shop_st) == 0 { return }
for v in 0 .. shop_vendors(shop_st) { shop_roll_vendor(shop_st, v) }
}
@ -90,3 +88,4 @@ function shop_demand_reset(shop_st: mut ShopState) -> void {
shop_st.shop_want_list = null
shop_st.shop_full_list = null
}

View file

@ -5,6 +5,7 @@ numbers float
import "ludic.base"
import "state.ludic"
import "demand.ludic"
import "week_lists.ludic"
import "prices.ludic"
import "trade.ludic"
import "system.ludic"

View file

@ -40,7 +40,8 @@ export state ShopState {
shop_week_rolled: int = -1
shop_want_list: []int = null # shop_wants_n per vendor, -1 empty
shop_full_list: []int = null # one per vendor, -1 none
shop_dice: Rng = null
shop_dice: Rng = rng_new(0)
shop_taken: []int = new []int # a vendor's picks while its week is rolled, kept
shop_base: []int = null # an item's base price
shop_sell_frac: []float = null # what fraction of the curve a vendor pays for it
shop_vendor_list: []ShopVendor = null

View file

@ -0,0 +1,14 @@
# ludic.shop/week_lists.ludic - the lists a week is rolled into, made once and cleared after
# the week's lists, every entry -1: made the first week and cleared after, the vendors being fixed
function shop_lists_empty(shop_st: mut ShopState) -> void {
if shop_st.shop_want_list == null {
@alloc_ok("once: the lists are made the first week they are rolled")
shop_st.shop_want_list = new []int
@alloc_ok("once: as above")
shop_st.shop_full_list = new []int
}
List.clear(shop_st.shop_want_list)
List.clear(shop_st.shop_full_list)
for i in 0 .. shop_vendors(shop_st) * shop_st.shop_wants_n { kept_push(shop_st.shop_want_list, -1) }
for v in 0 .. shop_vendors(shop_st) { kept_push(shop_st.shop_full_list, -1) }
}