Skip to content

Keep Z as short in memory - #81

Merged
kaczy93 merged 10 commits into
kaczy93:masterfrom
DavideRei:z-as-short
Nov 19, 2026
Merged

kaczy93 merged 10 commits into
kaczy93:masterfrom
DavideRei:z-as-short

Conversation

@DavideRei

Copy link
Copy Markdown
Contributor

First step of the optional 16-bit Z plan: tile Z becomes short in memory, while map/statics files and network packets stay exactly as they are.

What changes

  • BaseTile.Z, LandTile, StaticTile, StaticInfo, landscape events, client/server packets, large scale operations, tools and UI use short instead of sbyte.
  • New ZRange helper in Shared/ZRange.cs:
    • Min/Max (currently -128/127) replace hard-coded limits in tools, filter window and LSO windows.
    • Clamp replaces (sbyte) casts that silently wrapped on overflow (e.g. scrolling Z from 125 by +10 used to give -121).
    • ReadZ/WriteZ read and write Z as a single signed byte, so disk and wire format are byte-identical to today.
  • ImportHeightmap: (sbyte)(value + 128) relied on wrap-around; rewritten as value - 128 (same result).

Not changed

  • File formats, packet layouts and sizes, protocol version.
  • Camera/rendering, heightmap export, random Z ranges.

Testing

  • Solution builds; all tests pass, including new ZRangeTest (map block and static tile round-trip byte-identical, WriteZ clamping).
  • Built and tested manually against a server.

🤖 Generated with Claude Code

DavideRei and others added 10 commits October 21, 2026 12:46
Tile Z, StaticInfo, landscape events, tools and UI now use short instead of
sbyte. Map/statics files and network packets are unchanged: Z is still read
and written as a single signed byte through the new ZRange helpers
(ReadZ/WriteZ), so the on-disk and on-wire format stays byte-identical.

ZRange.Min/Max replace the hard-coded -128/127 limits, and ZRange.Clamp
replaces sbyte casts that silently wrapped around on overflow.

This prepares optional 16-bit Z support without changing behavior.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaczy93
kaczy93 merged commit d2729d5 into kaczy93:master Nov 19, 2026
8 checks passed
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.

2 participants