planetsim/src/render/Map2D.hpp
Jonas Reith f84e06507a Live World weather: dynamic clouds & rain cycle (save v10)
A per-cell humidity/cloud/rain cycle advanced on the live clock (PlanetWeather.cpp,
raylib-free): evaporate over warm sunlit seas -> advect humidity & cloud along the prevailing
wind (upwind differencing) -> condense into cloud (saturation vs temperature + windward
orographic lift) -> rain out thick cloud -> dissipate. Bounded exp-rate forms keep it stable at
any timestep, so it runs cleanly from hours/sec up to a month/sec. initWeather() spins the
fields up from the moisture climatology; fully deterministic (no RNG).

Render: a translucent cloud shell over the 3D globe (white -> dark slate where it rains,
alpha = cover) plus a matching drawWeather2D layer on the 2D map (shared drawMapTris
rasterizer), toggled with K (default on). stepSim runs stepWeather each live frame at the
sim-hours added to liveTime (held when paused). Cell-info shows cloud/humidity/raining.

Saved as v10 (humidity/cloud/rain, flag-gated; pre-v10 saves spin weather up live). New
weather* config knobs. Reseed/regen now also drops out of Live World. test_weather.cpp:
fields in range, clouds form + rain falls, oceans moister than land, determinism, v10
round-trip; the other four suites still pass; GUI build clean. Docs updated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 14:01:34 +02:00

29 lines
1.2 KiB
C++

#pragma once
#include "raylib.h"
#include "Planet.hpp"
#include <vector>
// Equal Earth 2D map: per-cell screen positions + the projection/draw helpers.
struct Map2D {
std::vector<Vector2> pos; // screen position per cell (fast path)
std::vector<double> lon; // longitude per cell (radians, for seam detection)
std::vector<double> lat; // latitude per cell (radians)
};
void buildMap2D(const Planet& p, Rectangle r, Map2D& m);
double wrapPi(double l);
// Project a (lon,lat) onto the map with the longitude pan applied.
Vector2 projLonLat(double lon, double lat, double lonOffset, Rectangle r);
Vector2 mapScreen(const Map2D& m, int idx, Rectangle r, double lonOffset);
// lonOffset pans the map east/west (radians); y is unchanged by the pan.
void drawMap2D(const Planet& p, const std::vector<Color>& vc,
const Map2D& m, Rectangle r, double lonOffset);
// Translucent Live World cloud/rain layer over the 2D map (white -> dark storm where it rains;
// alpha = cloud cover). Same triangle iteration as drawMap2D but blended on top.
void drawWeather2D(const Planet& p, const std::vector<double>& cloud, const std::vector<double>& rain,
const Map2D& m, Rectangle r, double lonOffset);