From 9c5b5c92c676a1a7e24080b106642195ce2fa765 Mon Sep 17 00:00:00 2001 From: Jeff Quast Date: Sat, 22 Aug 2026 14:06:28 +0000 Subject: [PATCH] Save .cty files in the classic size saveFile appended the mop layer after the map, producing 51120-byte files. SimCity and Micropolis tools expect 27120, the size of every .cty in the tree. mop is transient scratch state that the simulation ignores and that loadFileData zeroes when it is absent, so this writes the map alone. loadFileData accepts either size, so files already saved with a mop layer keep loading. Same seed and city: 51120 bytes before, 27120 after, and the first 27120 bytes are identical, so the map bytes are unchanged. --- .../micropolis/src/lib/citySaveFormat.test.ts | 19 +++++++++++++++++++ packages/micropolis-engine/src/fileio.cpp | 3 +-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 apps/micropolis/src/lib/citySaveFormat.test.ts diff --git a/apps/micropolis/src/lib/citySaveFormat.test.ts b/apps/micropolis/src/lib/citySaveFormat.test.ts new file mode 100644 index 00000000..4506a8e4 --- /dev/null +++ b/apps/micropolis/src/lib/citySaveFormat.test.ts @@ -0,0 +1,19 @@ +import { describe, it, expect } from 'vitest'; +import { loadMicropolisMainModule } from './wasm/node'; +import { createNoopJsCallback } from './wasm/callbacks'; + +describe('city save format', () => { + it('writes a city file the same size as the one it loaded', async () => { + const engine = await loadMicropolisMainModule(); + const micropolis = new engine.Micropolis(); + micropolis.setCallback(createNoopJsCallback(engine), {}); + micropolis.init(); + const city = '/cities/haight.cty'; + expect(micropolis.loadCity(city)).toBe(true); + + micropolis.saveCityAs('/saved.cty'); + expect(engine.FS_readFile('/saved.cty').length).toBe(engine.FS_readFile(city).length); + + micropolis.delete(); + }); +}); diff --git a/packages/micropolis-engine/src/fileio.cpp b/packages/micropolis-engine/src/fileio.cpp index 30e91a04..5b51dd64 100644 --- a/packages/micropolis-engine/src/fileio.cpp +++ b/packages/micropolis-engine/src/fileio.cpp @@ -455,8 +455,7 @@ bool Micropolis::saveFile(const std::string &filename) * linear index x * WORLD_H + y. This is column-major relative to city * coordinates, and is the same order exposed to JavaScript/WASM tools. */ - save_short(((short *)&map[0][0]), WORLD_W * WORLD_H, f) && - save_short(((short *)&mop[0][0]), WORLD_W * WORLD_H, f); + save_short(((short *)&map[0][0]), WORLD_W * WORLD_H, f); fclose(f);