Implementation:4thfever Cultivation world simulator perform game initialization
| Knowledge Sources | |
|---|---|
| Domains | Game_Initialization, Server |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Concrete tool for bootstrapping a new game session from static data through staged initialization, provided by the Cultivation World Simulator server.
Description
The perform_game_initialization function is the top-level async orchestrator for game world creation. It accepts all dependencies as callable parameters (dependency injection), runs the entire initialization inside the runtime's mutation lock, and reports progress through an `update_init_progress` callback.
The function orchestrates seven stages: asset scanning, map loading, save slot creation, world instantiation, dynasty/emperor generation, world lore rewriting, avatar generation, character profiling, and the first simulation step. Each stage updates the initialization progress.
Usage
Import and call this function when starting a new game session:
- Normal game start: called by the game start lifecycle handler with the user's `RunConfig`
- Test mode: called with `test_mode=True` in the run config; LLM-dependent stages (lore rewriting, profiling, LLM connectivity check) are skipped or use rule-based fallbacks
- Re-initialization: called again when the user requests a reinit (resetting the world)
Code Reference
Source Location
- Repository: cultivation-world-simulator
- File: src/server/init_flow.py
Signature
async def perform_game_initialization(
*,
runtime,
avatar_assets: dict[str, list[int]],
assets_path: str,
config,
update_init_progress: Callable[[int, str], None],
reset_runtime_custom_content: Callable[[], None],
reload_all_static_data: Callable[[], None],
scan_avatar_assets: Callable[..., dict[str, list[int]]],
load_cultivation_world_map: Callable[[], Any],
get_events_db_path,
get_runtime_run_config: Callable[[Any], Any],
world_cls,
create_month_stamp,
year_cls,
month_enum,
generate_dynasty: Callable[[], Any],
generate_emperor: Callable[[Any, int], Any],
event_cls,
translate: Callable[..., str],
simulator_cls,
model_to_dict: Callable[[Any], dict[str, Any]],
world_lore_manager_cls,
build_world_lore_snapshot: Callable[[Any], Any],
sects_by_id,
make_random_avatars,
check_llm_connectivity: Callable[[], tuple[bool, str]],
) -> None:
Import
from src.server.init_flow import perform_game_initialization
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| runtime | GameSessionRuntime | Yes | Runtime with mutation lock, init state tracking, and world/sim slots |
| avatar_assets | dict[str, list[int]] | Yes | Avatar portrait asset mapping (race -> male/female ID lists) |
| assets_path | str | Yes | Path to avatar portrait assets directory |
| config | StaticConfig | Yes | Static game config with paths, world settings, start_year |
| update_init_progress | Callable[[int, str], None] | Yes | Progress callback (phase_number, phase_name) |
| reset_runtime_custom_content | Callable[[], None] | Yes | Clears runtime custom content |
| reload_all_static_data | Callable[[], None] | Yes | Reloads CSV/game_configs from disk |
| scan_avatar_assets | Callable | Yes | Scans avatar portrait directory for new assets |
| load_cultivation_world_map | Callable | Yes | Loads map from JSON (returns Map) |
| get_events_db_path | Callable | Yes | Derives SQLite events DB path from save path |
| sects_by_id | dict | Yes | All sect templates loaded from CSV |
| make_random_avatars | Callable | Yes | Generates N random avatars |
| check_llm_connectivity | Callable | Yes | Tests LLM provider connectivity |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effects) | None | World and simulator set on runtime; init progress set to 100%; roleplay session cleared; LLM check started as background task (skipped in test mode) |
Usage Examples
Basic Game Start
import asyncio
from src.server.init_flow import perform_game_initialization
# All dependencies are injected; in production these are assembled
# by src/server/main.py
await perform_game_initialization(
runtime=runtime,
avatar_assets=avatar_assets,
assets_path=assets_path,
config=config,
update_init_progress=lambda phase, name: print(f"Phase {phase}: {name}"),
reset_runtime_custom_content=reset_runtime_custom_content,
reload_all_static_data=reload_all_static_data,
scan_avatar_assets=scan_avatar_assets,
load_cultivation_world_map=load_cultivation_world_map,
get_events_db_path=get_events_db_path,
get_runtime_run_config=get_runtime_run_config,
world_cls=World,
create_month_stamp=MonthStamp,
year_cls=Year,
month_enum=Month,
generate_dynasty=generate_dynasty,
generate_emperor=generate_emperor,
event_cls=Event,
translate=translate,
simulator_cls=Simulator,
model_to_dict=model_to_dict,
world_lore_manager_cls=WorldLoreManager,
build_world_lore_snapshot=build_world_lore_snapshot,
sects_by_id=sects_by_id,
make_random_avatars=make_avatars,
check_llm_connectivity=check_llm_connectivity,
)
Related Pages
Implements Principle
Required Environments
- Environment:4thfever_Cultivation_world_simulator_Python_Runtime_Environment
- Environment:4thfever_Cultivation_world_simulator_LLM_Provider_Connectivity
- Environment:4thfever_Cultivation_world_simulator_Docker_Deployment_Environment