M12.4: retain and settle owned population intervals
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m28s
Foundation / checks (tsan) (push) Failing after 18m22s
Foundation / checks (network) (push) Successful in 20m38s
Foundation / checks (client) (push) Failing after 21m6s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 46m54s
Foundation / checks (checks) (push) Canceled after 47m3s

This commit is contained in:
dingo
2026-10-17 17:31:05 -04:00
parent 627411983f
commit 0a8962b57e
34 changed files with 1032 additions and 75 deletions
+13 -29
View File
@@ -1067,19 +1067,19 @@ int serve_cellular(Options& o) {
held_births.push_back(birth);
}
const bool birth_waiting = !held_births.empty();
const bool want_population =
o.cellular_populations && state &&
state->rules_version() == server::cellular_lives_foraging_rules && !player_present &&
!birth_waiting && host.queued_mutations().empty() &&
std::ranges::any_of(state->lives(), [](const auto& life) {
return life.account == server::LifeAccount{};
});
const bool want_population = o.cellular_populations && state &&
server::population_interval_safe(*state) && !player_present &&
!birth_waiting && host.queued_mutations().empty() &&
std::ranges::any_of(state->lives(), [](const auto& life) {
return life.account == server::LifeAccount{};
});
if (status.ready && state && want_population != host.population_mode()) {
[[maybe_unused]] const auto changed = host.set_population_mode(want_population);
state = host.state();
}
const bool needed = state && (player_present || birth_waiting ||
server::cellular_unattended_tick_needed(*state));
server::cellular_unattended_tick_needed(*state) ||
status.ecological_pending_ticks != 0);
const auto monotonic_us = [] {
return static_cast<std::uint64_t>(
std::chrono::duration_cast<std::chrono::microseconds>(
@@ -1088,32 +1088,16 @@ int serve_cellular(Options& o) {
};
const auto paced = schedule.observe(monotonic_us(), status.epoch,
state ? state->tick() : status.committed_tick, needed,
status.ready && state);
status.ready && state, status.ecological_pending_ticks);
if (!paced) {
std::puts("error cellular-schedule");
return finish(4);
}
if (status.ready && state && needed) {
if (status.ready && state && (needed || host.population_mode())) {
if (host.population_mode()) {
// Collect one second of due time before an unattended publication.
// Overload services at most 64 fixed steps per bounded batch. Debt
// remains visible and is consumed only by a confirmed head.
if (paced->due && paced->debt >= 20) {
const auto& head = host.committed()->head;
const server::CellularBatchHeader header{
o.host.key.world,
o.host.key.region,
o.host.frame,
head.commit,
head.digest,
head.end_tick,
head.end_tick + std::min<std::uint64_t>(paced->debt, 64)};
const auto inputs = server::unattended_population_inputs(*state, header);
const auto end = header.end_tick;
if (inputs) {
[[maybe_unused]] const auto published = host.publish(*inputs);
}
if (!host.state() || host.state()->tick() < end)
if (paced->retry_ready && (paced->due || status.ecological_pending_ticks != 0)) {
const auto published = host.advance_unattended(paced->due ? paced->debt : 0);
if (!published)
schedule.defer(monotonic_us());
}
} else if (paced->due && state->tick() != UINT64_MAX) {