What is the Map Generator?
The Map Generator is a Go-based command-line tool that converts PNG image files into optimized binary terrain maps for OpenFront. It processes source images from theassets/maps/ directory and outputs game-ready map files to resources/maps/.
Key Features
Terrain Processing
- PNG to Terrain Conversion: Reads PNG files and converts pixels into terrain based on the Blue channel value
- Multi-format Support: Grayscale and other image formats are fully supported since only blue values are used
- Automatic Cleanup: Removes small islands (< 30 tiles) and lakes (< 200 tiles) to improve game performance
- Dimension Normalization: Automatically crops dimensions to multiples of 4 for minimap compatibility
Output Generation
For each map, the generator creates:Binary Map Files
map.bin- Full-scale terrain datamap4x.bin- 1/4 scale (half dimensions) for minimapsmap16x.bin- 1/16 scale (quarter dimensions) for minimaps
Terrain Type Mapping
The generator determines terrain type and magnitude based on pixel blue channel values:| Input Condition | Terrain Type | Magnitude | Notes |
|---|---|---|---|
| Alpha < 20 | Water | Distance to Land* | Transparent pixels become water |
| Blue = 106 | Water | Distance to Land* | Specific key color for water |
| Blue < 140 | Land (Plains) | 0 | Clamped to minimum magnitude |
| Blue 140-158 | Land (Plains) | 0-9 | Low elevation terrain |
| Blue 159-178 | Land (Highland) | 10-19 | Medium elevation terrain |
| Blue 179-200 | Land (Mountain) | 20-30 | High elevation terrain |
| Blue > 200 | Land (Mountain) | 30 | Clamped to maximum magnitude |
*For water tiles, magnitude is calculated during generation as the Manhattan distance to the nearest land tile.
Performance Recommendations
The map generator includes built-in performance recommendations:- Map Area: 2-3 million pixels (width × height)
- Land Tiles: Maximum 3 million land tiles recommended
- Average Land Count: 1-2 million tiles
--log-level=debug or --log-performance.
How It Works
Pack Binary Data
Serializes terrain into compact binary format:
- Bit 7: Land (1) / Water (0)
- Bit 6: Shoreline flag
- Bit 5: Ocean flag
- Bits 0-4: Magnitude (0-31)