Refactor production request handling: implement queuing mechanism and improve production application logic

This commit is contained in:
Kirill
2026-10-08 22:19:29 +03:00
parent 02c9843e1b
commit 00b6192d19
7 changed files with 107 additions and 39 deletions
+4
View File
@@ -38,6 +38,10 @@ func run() -> void:
actions.set_actions("step", 123, func ( request ) : return E.multiply(E.floor_value(E.divide(request, 5)), 5))
check(E.eq(actions.action_values.values(), [10, 100, 123, 0, 0]), "Unproducible small requests omitted")
check(E.eq(actions.action_labels[2].text, "120"), "Recipe preview displayed while original request retained")
actions.mark_pending(123)
check(actions.action_labels[2].text == "…" and actions.action_labels[2].get_parent().get_node("TextureButton").disabled, "Queued action is visibly pending and cannot be duplicated")
actions.set_actions("step", 123, func ( request ) : return E.multiply(E.floor_value(E.divide(request, 5)), 5))
check(actions.action_labels[2].text == "120" and not actions.action_labels[2].get_parent().get_node("TextureButton").disabled, "Action refresh clears pending state")
var emitted: Array = []
actions.action_pressed.connect(func ( _page , amount ) : emitted.append(amount))
actions._on_action_button_pressed(2)
+5 -4
View File
@@ -38,13 +38,14 @@ func run():
sliced.evolute_frame(0.2, self)
check(sliced.frame_busy, "Heavy transaction yields before publishing")
check(E.eq(sliced.state.time.year, 0), "Published clock stays at completed transaction")
sliced.request_production("H", 1, true)
check(sliced.request_production("H", 1, true), "Production requested during a frame is queued")
check(sliced.frame_checkpoint().productions.size() == 1, "Queued production remains part of the save checkpoint")
check(E.eq(sliced.state.amount.H, initial_h), "Player action waits for transaction commit")
sliced.evolute_frame(0.01, self)
var requested: Dictionary = sliced.frame_clock.duplicate()
sliced.speed = 3
check(sliced.speed == 3 and sliced.state.speed == 6, "Speed change is visible and cannot mutate an unfinished transaction")
while sliced.frame_busy: await process_frame
while sliced.frame_busy or sliced.production_queue_busy: await process_frame
direct.evolute(0.2)
direct.production.produce_hs("H", 1)
direct.speed = 3
@@ -54,7 +55,7 @@ func run():
sliced.evolute_frame(0.189, self)
var second_clock: Dictionary = Clock.advance(Clock.advance(requested, 0.001, 3), 0.189, 3)
var active: Dictionary = sliced.frame_active_clock.duplicate()
while sliced.frame_busy: await process_frame
while sliced.frame_busy or sliced.production_queue_busy: await process_frame
direct.evolution.evolute_to_datetime(active.datetime, active)
check(E.eq(direct.state, sliced.state), "Bounded frame transaction matches its exact target clock")
check(E.eq(sliced.frame_clock, second_clock), "All elapsed time during a busy frame remains in the requested clock")
@@ -77,7 +78,7 @@ func run():
expected.state = published.duplicate(true)
resumed.restore_frame_checkpoint(checkpoint)
resumed.evolute_frame(0.0, self)
while resumed.frame_busy: await process_frame
while resumed.frame_busy or resumed.production_queue_busy: await process_frame
expected.evolution.evolute_to_datetime(expected_clock.datetime, expected_clock)
expected.production.produce_hs("H", 123)
expected.speed = 3
+8
View File
@@ -72,6 +72,14 @@ func run() -> void:
check((E.eq(world.state.amount.H, 6) and E.eq(world.state.amount.S, 4)), "Exact cost and binding")
check(E.eq(world.state.auto_resources.H, 6), "Exact automatic budget")
check((E.eq(old_batches[0].amount, 10) and E.eq(world.state.batches.H[0].amount, 6)), "Consumed batches isolated")
for member in world.catalog.members("Star"): world.state.amount[member] = 0
var star_stocks: Array = ["1234567890123456789", "876543210987654321", "3141592653589793238", "2718281828459045235", "1414213562373095048", "1732050807568877293", "2236067977499789696", "2449489742783178098", "3162277660168379331"]
for i in star_stocks.size(): world.state.amount[world.catalog.members("Star")[i]] = E.of(star_stocks[i])
var scd_request: Variant = E.of("1e15")
var scd_created: Variant = world.production.produce("SCD", scd_request)
check(E.eq(scd_created, scd_request), "Large SCD production distributes a whole star quota exactly")
check(E.eq(world.state.amount.SCD, scd_request), "Large SCD creation is committed")
print(("Transaction: %d checks, %d failures" % [checks, failures]))
dispose(world)
quit((1 if failures else 0))