World Stores
crowdypy.stores is the SDK-managed game state CrowdyJS calls the World
Stores, running on CrowdyCPP's native world session. session.tick() applies
every notification since the last tick to the stores natively. It then runs
your actor's send loop and reaping, and fires your callbacks. Nothing a tick
does waits on the network.
from crowdypy.codecs import f32, struct_codec, u16
from crowdypy.stores import create_world_session
pose = struct_codec({"x": f32(), "y": f32(), "z": f32(), "yaw": u16()})
session = create_world_session(game, app_id, actor_codec=pose, host=True, save=True)
session.self.join((0, 0, 0), {"x": 0.0, "y": 64.0, "z": 0.0, "yaw": 0})
session.actors.on_join(lambda actor: print("joined", actor.uuid, actor.value))
asyncio.create_task(session.run()) # tick 60 times a second
snapshot = session.actors.snapshot() # once a frame: every actor at once
states = pose.decode_many(snapshot.state_offsets, snapshot.state_data) # numpy, no loop
The stores
| Store | What it holds |
|---|---|
session.self | your actor: join, set or patch state, send-on-change with keyframes and heartbeats |
session.actors | everyone else, with staleness, sample history, join, leave and update callbacks, native lanes filtered by state[offset] & mask == value, and snapshot() columns |
session.chunks | voxels: real-time merge, optimistic set_voxel (optimistic=False applies an edit only when the server's echo arrives, 0.15.0), ensure_around and hydrate from the Application API, write-back of generated chunks with retries, and an on_missing world-generation hook. Since 0.30.0 ensure_around reads only the chunks it lacks, as boxes in pages; set_voxel returns an edit id and is paced (max_edits_in_flight 128, max_edits_per_second 250); an edit the server refuses or never echoes (edit_timeout_ms, 10 s) is undone and reaches on_edit_refused; a chunk a mod replaced is read again, and a reconnect catches up (catch_up(since)). Since 0.33.0 (Application API v2.70.0) a voxel with no entry in a copy is dated by the chunk's whole-chunk write (CachedChunk.stored_at, voxelsUpdatedAt), so a chunk-state or LOD write drops no newer change; row_at orders copies. A 16×16×16 helper: an edit its one-byte grid cannot hold (a type outside 0-255, a position outside 0-15) is kept in overlay(chunk) (0.8.0) |
session.errors, direct_inbox, channel_inbox, events | errors attributed to your sends, inboxes and the event router |
session.host, save, avatar | host election, save state and avatar state, run from the session's timers |
Session events (0.8.0): session.on("voxel_update", ...) for every inbound voxel edit after
session.chunks merged it, your own echo included (compare the uuid and sequence with your
send's); session.on("generic_spatial", ...) for message type 140; and
session.on("channel_audio", ...) for channel voice.
From 0.41.0, session.on("not_present", ...) and session.on("not_present_ended", ...) say
once that the session's heartbeat was refused where its actor stands, and when that ended.
session.not_present() returns the report that stands, or None. From replication server
v0.51.0 that is what having no access in a place looks like: the actor is not present
there. session.errors records one heartbeat error for a report. Through 0.40.0 it
recorded each refusal, as an error of an unknown or a stale kind. See
A refused heartbeat is reported once.
Codecs
json_codec, raw_codec and text_codec cover most states. struct_codec
declares a fixed binary layout and decodes a whole lane's states in one call,
into a numpy structured array.
The Game Kit
client.kit(app_id) is the Game Kit: typed clients for the
ck-exec starter hubs (kit.world, kit.matchmaking, kit.sessions, kit.npcs,
kit.topology), the client conventions (kit.spectate, kit.emotes,
kit.shards) and the social helpers (parties, guilds, chat). Beside the World
Stores, decode_kit_actor_state and kit_actor_lanes read the mobs, NPCs, pets
and balls hubs show; the engine pose format with engine_lanes(), the event
parsers and run_optimistic_action are there too (CrowdyPy 0.12.0).