Files

52 lines
2.9 KiB
GDScript
Raw Permalink Normal View History

extends SceneTree
## Reproducible stress save; never writes to the player's user:// directory.
const E = preload("res://world/owniverse/math/exact.gd")
const State = preload("res://world/owniverse/civilization_state.gd")
func _initialize(): call_deferred("run")
func run():
var global: Node = root.get_node("Global")
var world = load("res://world/owniverse/owniverse.gd").new()
world.catalog.load_definitions(global.OwniverseEntities)
world.speed = 6
world.state.time = {"datetime": 1000000000000000, "year": 1000000000000000, "tick_remainder": 0}
world.state.energy = E.of("1e100")
for id in world.catalog.entities:
world.state.amount[id] = E.of("6e60")
world.state.stats.total_amount[id] = world.state.amount[id]
if global.CivilizationRules.has(id): world.state.amount[id] = E.of("6e20")
world.state.amount.S = E.of("1e90")
world.state.amount.H = E.of("1e90")
world.state.amount.He = E.of("1e80")
world.state.amount.Met = E.of("1e80")
world.ledger.refresh_groups(world.state)
State.enforce_capacity(world, world.state, global.CivilizationRules, world.state.time.year)
State.reconcile(world, world.state, global.CivilizationRules)
var cohorts: int = 0
for id in world.catalog.entities:
if world.catalog.is_group(id): continue
var lifespan: Variant = State.effective_span(world, world.state, id, global.CivilizationRules)
if E.le(lifespan, 0): continue
world.state.batches[id] = []
var width: Variant = E.divide(lifespan, 10)
for i in 10:
var start: Variant = E.add(world.state.time.year, E.multiply(width, i))
var end: Variant = E.add(start, width)
var birth: Variant = E.subtract(start, lifespan)
world.state.batches[id].append({"amount": E.divide(world.state.amount[id], 10), "created_from": birth, "created_to": E.add(birth, width), "start_year": start, "end_year": end})
cohorts += 1
world.state.batch_origins[id] = world.state.batches[id][0].created_from
world.state.stats.total_amount = world.state.amount.duplicate(true)
var manager: Node = root.get_node("SaveManager")
var folder: String = ProjectSettings.globalize_path("res://tests/artifacts")
DirAccess.make_dir_recursive_absolute(folder)
manager.save_directory = folder
global.save_plaintext_copy = true
var success: bool = manager.save_data("all_objects_speed6", "qwerty", {"state": world.state, "simulation": world.frame_checkpoint(), "ui": {"current_page": 4}})
var empty: Array = []
for id in world.catalog.entities:
if E.le(world.state.amount.get(id, 0), 0): empty.append(id)
print("Full save: objects=%d civilization stages=%d cohorts=%d empty=%s success=%s" % [world.catalog.entities.size(), global.CivilizationRules.size(), cohorts, empty, success])
for entity in world.catalog.entities.values(): entity.free()
world.free()
quit(0 if success and empty.is_empty() else 1)