My mapgen4 renderer is quite messy. It’s webgl instead of canvas, and it has a lot of optimizations to bring it from 30 sec/frame to 30 frame/sec. But those optimizations make it specialized to handle only what mapgen4 needed, and not any other features I want to experiment with. In contrast, my mapgen2 renderer was fairly clean and modular, easy to adapt to many different features. Since mapgen2 and mapgen4 both use the same dual-mesh structure underneath, I decided to try gluing the mapgen2 renderer onto the mapgen4 generator.
Go ahead, paint on this map:
For this project I looked through the code
- mapgen2 and mapgen4 both use dual-mesh v3
- mapgen4’s ingredients
- painting.ts: input is noise and user drawing; output is a 2d height map
- mesh.ts: dual-mesh library
- map.ts: the main algorithms (assignElevation, assignRainfall, assignRivers) → runs in the web worker
- geometry.ts: input is elevation_r, elevation_t, rainfall_r, flow_s; output is indexed triangle mesh (but not biome colors); also some river code is in here; Geometry.setMapGeometry() runs in the web worker
- render.ts: input is buffers (buffer_quad_em, buffer_quad_elements, buffer_river_xyuv); plan to not use this at all
- uses gl-matrix (which is being updated[1] to be easier to use)
- mapgen2’s ingredients
- stylized rendering
- I have lots of code lying around to draw edges, regions, triangles, points
- but this code needs access to the map data, which is only in the web worker
- so either I need to do OffscreenCanvas, or get rid of the web worker
- 2502-mapgen4-overlay used an OffscreenCanvas in the worker
- for now, I’ll use OffscreenCanvas, and later figure out if I want to get rid of the web worker
Eventual goal is to try out some alternative mapgen algorithms
- maybe west to east gradient for heat, and north to south gradient for wind
- later: wraparound voronoi map, by merging neighbors together, but still having a ghost point for the other axis; but this could be separate, since I like west to east gradient here for web page layout reasons
- use town placement from earlier mapgen2 project, but have them grow and shrink over time, since the map is paintable
- continual randomized update of all-pairs paths
- pick random point, calculate dijkstra, update all-pair weights
- decay all-pair weights over time
- build roads where weights are high → need multiple road levels (path, dirt road, stone road, major) (maybe color+thickness)
- decay roads where weights are low
- do this in a separate worker thread? maybe not worth it
- draw on a separate layer, since it doesn’t update at the same frequency as the base map
- continual randomized update of rainfall
- it’d be more visually interesting to have these update smoothly after you edit the map, like 2505-mapgen-cylinder
- biomes would update in small ways over time, so I need to use smooth colormap for them
- could oscillate wind direction to make it feel like seasons
- could vary heat gradient also, to feel like seasons
- layer of particles on top to show trade between towns
- use 2d canvas but direct pixel painting
- do this in a separate worker thread
- this represents not only trade but also culture / religion influence
- draw territory / culture / religion influence, like 1744-territory-outline project
- interaction: click on cities to give them a boost of influence, and see the influence spread and then fade over a minute