garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/adr/017-prim-authoring-and-editing.md

raw

ADR-017: Prim Authoring and Editing (v0)


Metadata:


Context

Problem: The prim pipeline was read-only — prims loaded from SQLite at startup, broadcast inside WorldSnapshot, rendered on clients, with no mutation path at any layer. That blocks G-01 (authoring): without placing and editing objects the world is static.

Requirements:

Decision

Add client→server prim CRUD to the protocol, apply it server-side with immediate DB persistence and delta broadcast, and drive it from an in-house egui UI (context menu, edit dialog, transform gizmo) with hand-rolled raycast selection.

Protocol (cartopolis_core/src/protocol.rs) — variants and wire kinds:

VariantDirKindPurpose
CreatePrimC→S8New prim with full initial state (pos/rot/scale/color/shape/texture/surface/geometry)
UpdatePrimC→S9Updated fields (transform, color, texture, name, surface, geometry)
DeletePrimC→S10Delete by server-assigned id
PrimUpsertS→C11Authoritative full prim state after a create/update
PrimRemovedS→C7Emitted on delete
TextureCatalog* / TextureRequest / TextureDataC↔S12–16Standard texture library, streamed from the sim

PrimDto gained texture_id: Option<String> and (later, ADR-018) the PrimSurface + PrimGeometry fields, all #[serde(default)] for rollout. This ADR introduced the CRUD kinds; ADR-018 (v8) added surface + geometry. The current wire version and the full revision log live in PROTOCOL_HISTORY (crates/cartopolis_core/src/protocol.rs).

Server (cartopolis_simulator): SimWorld holds an Arc<Mutex<Connection>> (connection kept alive past load_world) and gains add_prim/update_prim/remove_prim, each persisting via db.rs and returning the authoritative PrimDto. net.rs handles the CRUD messages and broadcasts PrimUpsert/PrimRemoved immediately on mutation (not at the next tick); the full WorldSnapshot remains the consistency fallback. Migration V2 added the texture_id column.

Client (cartopolis):

Implemented across cartopolis_core/src/protocol.rs, cartopolis_simulator/src/{state,net,db}.rs, and cartopolis/src/systems/{picking,ui,gizmo,prim_ops,rendering,egui_manager}.rs.

Rationale

  1. Server-authoritative (P-01): all changes flow client→server→broadcast; the client never optimistically mutates shared state, avoiding desync (ADR-010/011).
  2. Immediate delta broadcast: PrimUpsert/PrimRemoved on mutation give sub-tick edit latency; the full snapshot stays as the fallback.
  3. In-house egui plugin: an off-the-shelf integration was avoided so the UI tracks our own Bevy version and render-graph wiring (the egui pass lives in Core3d); Bevy's native bevy_ui lacks editor widgets (text/dropdown/colour).
  4. String-keyed textures: human-readable ids that survive serialization and DB storage; no UUIDs for a bundled/served library.

Alternatives Considered:

AlternativeProsConsRejected Because
Client-authoritative primsLower edit latencyBreaks P-01; multi-editor desyncViolates the authority model
Full snapshot per change (no deltas)No new messages50 ms floor; re-sends unchanged primsPrimRemoved already set the delta precedent
Off-the-shelf UI/gizmo crates (bevy_egui, bevy_transform_gizmo, bevy_mod_raycast)Less code upfrontVersion lag against our Bevy bumps; thinner control of render wiringBuilt in-house for control; each was replaced by a local module
User-uploaded custom texturesMore powerfulNeeds asset pipeline, storage, abuse moderation (P-04)Deferred to a future Asset Pipeline ADR
Collaborative per-prim lockingPrevents conflictsUX friction; lock/crash recoveryOverkill for v0; last-write-wins is acceptable at low user counts

Consequences

Positive:

Negative:

Related