feat: compressed world maps — 84-98% smaller, ~2.8x faster, zero code changes#21
Open
web3dev1337 wants to merge 35 commits intohytopiagg:mainfrom
Open
feat: compressed world maps — 84-98% smaller, ~2.8x faster, zero code changes#21web3dev1337 wants to merge 35 commits intohytopiagg:mainfrom
web3dev1337 wants to merge 35 commits intohytopiagg:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Expanded server shared/types/ from one-liner to all 8 individual type files. Expanded protocol/ from generic directory listings to every individual packet and schema file (~50 files). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
docs: add CLAUDE.md and CODEBASE_DOCUMENTATION.md
Adds a user-facing CLI command to compress WorldMap JSON files: hytopia map-compress # default: assets/map.json hytopia map-compress path/to/map.json # custom path hytopia map-compress --algorithm gzip --level 6 # options hytopia map-compress --no-chunk-cache # skip chunk cache Generates: - map.compressed.json (brotli-compressed, ~95% smaller) - map.chunks.bin (precomputed chunk cache, ~30% faster load) Also includes regenerated SDK build outputs (server.mjs, server.d.ts, docs) so the compression APIs are available at runtime. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When loadMap() receives a legacy WorldMap object, it now checks for
compressed artifacts (assets/map.chunks.bin, assets/map.compressed.json)
at the conventional location. If found, it loads the fastest format
via WorldMapFileLoader — zero code changes needed in existing games.
Also accepts a string file path for explicit control:
world.loadMap('assets/map.json')
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When compressed artifacts exist (map.compressed.json / map.chunks.bin), `hytopia start` checks if map.json is newer. If so, it automatically recompresses before building — keeping artifacts in sync with zero manual steps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…plicates Replaced ~250 lines of duplicated compression/chunk-cache code with lazy-loaded SDK imports (WorldMapCodec, WorldMapChunkCacheCodec, WorldMapArtifactsGenerator). Fixed TDZ bug with _sdk declaration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TL;DR: Drop-in map compression that makes large maps ~84-98% smaller on disk, loads up to ~2.8x faster -- zero code changes required in existing games.
map.jsonkeeps working with no changes.world.loadMap(worldMap)auto-detects compressed artifacts alongsideassets/map.jsonand loads the fastest available format.hytopia startdetects whenmap.jsonis newer than compressed artifacts and recompresses automatically.world.loadMap('assets/map.json')also works -- WorldMapFileLoader handles format detection.world.loadMap(map, { preferMapArtifacts: false })disables auto-detection.scripts.jslazy-loads SDK codecs instead of duplicating compression logic.Zero-Code Workflow
Your existing code stays exactly the same:
When
world.loadMap()receives a legacy WorldMap, it checks forassets/map.chunks.binandassets/map.compressed.json. If found, it transparently loads the fastest format instead. Pass{ preferMapArtifacts: false }to disable.When
hytopia startruns, it checks ifmap.jsonhas been modified since the last compression. If so, it automatically recompresses before building -- no manual step needed.CLI Command
Output files (generated alongside your map.json):
map.compressed.json-- 84-98% smaller, brotli-compressed varint streammap.chunks.bin-- precomputed 16x16x16 chunk cache for fastest loadingPerformance
API Additions
world.loadMap(path: string)-- load map from file path with auto-detectionworld.loadMap(map, { preferMapArtifacts })-- opt-in/out of auto-upgradeWorldMapFileLoader.load(path)-- explicit file loader (supports .json, .compressed.json, .chunks.bin)WorldMapCodec-- compress/decompress WorldMap objectsWorldMapChunkCacheCodec-- chunk cache encode/decodeWorldMapArtifactsGenerator-- generate all artifacts in one callhytopia map-compress-- CLI command for generating compressed artifactshytopia start-- auto-recompresses when map.json changesTest Plan
hytopia map-compressgenerates valid artifactshytopia startdetects stale artifacts and recompresseshytopia startskips when artifacts are fresh🤖 Generated with Claude Code