Skip to content

Port codebase to golang#100

Open
siredmar wants to merge 94 commits into
masterfrom
golang
Open

Port codebase to golang#100
siredmar wants to merge 94 commits into
masterfrom
golang

Conversation

@siredmar

@siredmar siredmar commented Jan 8, 2024

Copy link
Copy Markdown
Owner

This project won't be maintained using C++ anymore. Instead the project will be continued using golang.

siredmar and others added 30 commits January 8, 2024 08:11
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
- Arr: x, y+56
-  @foo = +112
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Signed-off-by: Armin Schlegel <a.schlegel@gridx.de>
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Signed-off-by: Armin Schlegel <a.schlegel@gridx.de>
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
siredmar and others added 30 commits January 29, 2026 16:32
Add detailed documentation for AI agents to understand the mdcii-engine:

Main files:
- .github/copilot-instructions.md: Primary reference with TL;DR, quick reference tables
- .github/agents.md: Lean quick-reference card (95 lines)

Detailed topic docs in .github/docs/ (~3000 lines total):
- bsh-format.md: BSH sprite archives, RLE decoding algorithm
- cod-format.md: COD file parsing, building definitions, Kind types
- chunk-format.md: GAM/SCP chunk format, INSEL5/INSELHAUS structures
- islands.md: Island layers, two-layer system, Finalize() merging
- rendering.md: Isometric projection, depth sorting, layer ordering
- texture-atlas.md: Atlas generation, pivot calculation, caching
- ecs-architecture.md: ECS components, systems, queries
- rotation.md: World/building rotation, coordinate transforms

Covers: file formats, ECS architecture, isometric math, rendering pipeline,
atlas system, rotation system, and common development tasks.
- Add SavegameMeta with camera position, zoom, rotation
- Auto-center camera on first island when uninitialized
- Add World ECS component to track all island entities
- Add --savegame/-s flag to specify savegame file
- Skip unknown building IDs with log message instead of error
- Print camera position when panning (debug)
- Fix deep sea tile gaps by properly tiling isometric diamonds
- Skip deep sea tiles (1201) from sorting - drawn as cached background
- Fix frustum culling to account for zoom centered on screen center
- Add zoom-aware margin to prevent pop-in when panning
- Use pre-computed sort key with slices.SortFunc for faster sorting
- Restore Surf/Estuary coast transitions in Sea layer
- Replace camera wrapping with clamping at world bounds
- Scale pan speed linearly with zoom (1x at 100%, 10x at 10%)
- Mark camera as initialized when user moves or zooms
- Start at zoom 1.0 instead of 0.1
- Center on world center on first load
- Add Initialized flag to track if user moved camera
- Store initialized state in savegame for camera restoration
Extend the ID remapping to handle terrain tile IDs 102-110:
- IDs 102-103 map with +67 offset (to 169-170)
- IDs 104-110 map with +60 offset (to 164-170)

This fixes missing buildings/terrain when loading savegames that
use these legacy terrain IDs not present in haeuser.cod.
Add YAML config file support at ~/.mdcii/config.yaml:
- Configurable via -c/--config command line argument
- Fallback chain: specified path → ~/.mdcii/config.yaml → ./config.yaml
- Creates default config if none exists
- Exits with error on parse failure

Currently supports mouse_pan_factor setting (default: 0.67).
- Implement zoom-to-cursor: zoom centers on mouse position
- Scale mouse pan speed linearly with zoom level (faster when zoomed out)
- Reduce WASD pan speed by half (0.5 → 0.25)
- Use configurable mouse_pan_factor from config file
- Add --config/-c flag for custom config file path
Implement offscreen selection buffer for accurate building detection:
- Add HoveredBuildingID field to Control component
- Create ID↔Color encoding (24-bit, supports 16M+ IDs)
- Render buildings to offscreen buffer with ID-encoded colors
- Sample buffer at mouse position to get hovered building ID
- Display building ID in HUD overlay

The selection buffer uses the same transforms and depth sorting
as the main render, ensuring accurate detection even with
overlapping buildings and complex sprite shapes.
Press 'B' to toggle between normal rendering and the selection
buffer view, which shows buildings colored by their encoded IDs.
Useful for debugging pixel-perfect hover detection.
- Use rainbow colors (HSV-based) instead of dark blue ID encoding for debug view
- Create solid silhouette images (no sprite details) for cleaner display
- Separate ID-encoded buffer (for sampling) from rainbow display buffer
- Golden ratio distribution ensures adjacent buildings have distinct colors
Read pixels from source image and create solid white version
by replacing all non-transparent pixels with white while
preserving alpha channel. This removes all sprite details.
Roads (KindRoadsID) are now selectable in addition to buildings.
Renamed IsBuilding to IsSelectable to reflect the broader scope.
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
Add pixel-perfect building selection buffer to the raylib renderer,
matching the existing ebiten implementation. Toggle debug rainbow
overlay with B key; building ID under the mouse cursor is shown in
the HUD overlay.

- Render selectable tiles (buildings, roads) to an offscreen
  RenderTexture2D using ID-encoded solid-color silhouettes
- Sample the pixel at mouse position to decode the hovered building ID
- Rainbow-colored display buffer drawn on screen when toggled
- Silhouette textures cached per atlas page for performance
- Cleanup of render textures and silhouette cache on Close()

Amp-Thread-ID: https://ampcode.com/threads/T-019c31ba-7afb-73ad-8350-572738706305
Co-authored-by: Amp <amp@ampcode.com>
Compute tile range from actual screen corner coordinates instead of
using a fixed offset. The isometric projection maps screen corners
to tiles much further than a simple width/height estimate, causing
black gaps at the edges.

Amp-Thread-ID: https://ampcode.com/threads/T-019c31ba-7afb-73ad-8350-572738706305
Co-authored-by: Amp <amp@ampcode.com>
…aw sprite directly

RenderSystem only iterates IslandType entities, so the standalone
animation viewer got nothing rendered. Replace RenderSystem call with
direct sprite drawing centered on screen, plus a HUD showing building
info. Also add atlas caching and required Camera/Control ECS entities.

Amp-Thread-ID: https://ampcode.com/threads/T-019c778b-e470-70fe-9b5e-ca34f852e04d
Co-authored-by: Amp <amp@ampcode.com>
- AnimationSystem now syncs Count/Duration from animation definition
  each frame, so building ID or rotation changes are picked up
- Add Up/Down keys to step frames manually (pauses auto-play)
- Add Space to toggle play/pause
- Show frame counter and play state in HUD
- Update usage text with all controls

Amp-Thread-ID: https://ampcode.com/threads/T-019c778b-e470-70fe-9b5e-ca34f852e04d
Co-authored-by: Amp <amp@ampcode.com>
- Fix grid-to-sprite alignment by offsetting grid origin by tileW/2
  (BSH draw position is bounding box corner, diamond top vertex is
  at +tileW/2 from that)
- animations_ecs: add G key toggle, grid extends 2 tiles beyond
  building footprint in each direction
- Apply same tileW/2 fix to island_ecs Ebiten and Raylib grid overlays

Amp-Thread-ID: https://ampcode.com/threads/T-019c778b-e470-70fe-9b5e-ca34f852e04d
Co-authored-by: Amp <amp@ampcode.com>
- Sort tiles by isometric depth (x+y) instead of y-only for correct
  back-to-front rendering across all camera rotations
- Add depth-sorted rendering to Raylib renderer (was unsorted)
- Align debug grid to island ground level using PositionOffset
- Fix atlas rotation anchor using RotationOffsets origin tile
- Bump atlas version to 4 and add atlas caching to animations cmd

Amp-Thread-ID: https://ampcode.com/threads/T-019c7ae2-a69c-7741-b62c-0e47f7cadb43
Co-authored-by: Amp <amp@ampcode.com>
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