Skip to content

Refactor WebSocket handling and improve simulation store structure#1

Merged
shima004 merged 3 commits into
mainfrom
refactor
May 26, 2026
Merged

Refactor WebSocket handling and improve simulation store structure#1
shima004 merged 3 commits into
mainfrom
refactor

Conversation

@shima004

Copy link
Copy Markdown
Owner

This pull request introduces a major refactor and modularization of the simulation state management system. The simulation store has been split into focused modules for data, file loading, frame handling, perception, and timeline management. The new structure separates non-reactive data from Svelte stores, adds robust file and URL loading with progress tracking, and introduces a clear API for interacting with simulation state. Additionally, the perception system has been improved for reconstructing agent-specific worldviews, and the sevenzip extraction logic has been moved and cleaned up for better maintainability.

Simulation state management and modularization:

  • Introduced src/lib/stores/simulation/data.ts to hold all non-reactive simulation data in a single mutable object, allowing safe resets and updates across modules.
  • Refactored the simulation store into modular files (file.ts, frame.ts, perception.ts, timeline.ts, reset.ts), each handling a distinct aspect of simulation state, and provided a unified public API via index.ts. [1] [2] [3] [4]

File and URL loading improvements:

  • Added robust file and URL loading logic in file.ts, including progress tracking for download, extraction, and parsing, as well as error handling and support for both direct and proxied fetches.
  • Implemented extraction of simulation log archives using the updated sevenzip interface, with support for progress reporting and efficient main-thread/UI updates. [1] [2] [3] [4] [5]

Perception and agent worldview reconstruction:

  • Added logic to reconstruct the "world as seen by an agent" from cumulative perception data, including handling of visible entities, communications, and proper filtering of agents/blockades based on actual perception.
  • Improved state updates and subscriptions for perception-related Svelte stores, ensuring UI stays in sync with the underlying simulation data.

Simulation log frame handling and timeline management:

  • Centralized handling of all log frame types (config, initialCondition, command, perception, update) in frame.ts, updating both non-reactive data and Svelte stores as appropriate.

Sevenzip extraction code reorganization:

  • Renamed and reorganized sevenzip worker code for clarity, moving worker logic to its own file and updating imports accordingly. [1] [2] [3] [4]

This refactor greatly improves code maintainability, scalability, and clarity, while providing a more robust and featureful simulation state management system.

@shima004 shima004 self-assigned this May 26, 2026
@shima004 shima004 merged commit c44a8ec into main May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant