18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 06:14:58 +01:00
Files
maszyna/editor/editorTerrainStreamer.hpp
pol102 142a3bc287 feat(editor): Fields in the Terrain work mode, the ground under them made wavy, natural slopes (#315)
* feat(editor): Fields in the Terrain work mode, the ground under them made wavy, natural slopes

A Fields tool beside Fill: LMB outlines a field, which gets the material chosen in the palette
and is kept in a list (terrain/<name>/patches.txt, or in the manifest while there are few),
where its material, repeat, angle, transition and grass are changed later.

- painted into the terrain (the paint of the chunks, its edge blended over a transition and
  shifted by a noise, the 3D grass under it left, taken away or of another kind), or
- a surface of its own: the ground cut away within the outline and the field drawn over the
  hole as a mesh following the heights of the terrain, made around the camera as the water
  is. It doesn't take one of the 8 materials of a chunk; its edge is sharp.

The ground under a field can be made wavy before: rolling hills, furrows, bumps, long waves,
a hollow or a mound, hummocks in a grid, strips of fields; with a profile (rounded, sharp
ridges, sharp valleys, terraces, flat tops), roughness, variation and a fade from the edge.
The chunks under it are made finer where the waves need it.

The formation modifiers get an optional natural shape (natural: wander, scale, gentler,
soften, roughness in the manifest): the formation and the edges of the track bed stay, the
slopes and their foot wander, get gentler and meet the ground softly. Without it the
modifiers shape the ground as before.

Formats: new optional entries patches, patches_file and natural of the manifest, and the
patches file; a terrain without them reads and saves as before, and the release doesn't read
them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ

* Fields: one noise for the edges of the fields and the natural slopes, one filling of the geometry of the water

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ

* Fields: the vertices handed to the geometry of the water by value

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ

* fix(editor): whole-number loop counters instead of float ones (Sonar cpp:S2193)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ

* fix(editor): Fields: the edits of a field stick, the natural slopes stay when the formations are laid again, no holes far off or by a missing chunk

The copy of the field the widgets edit is kept while one of them is held, so a drag ends with what it was dragged to. Laying
the formations again keeps the natural shape of the slopes of each. The surfaces of the fields are made as far as the chunks
are drawn, so their holes never show without them; a field over ground with no chunk is made of what has ground, and waits
only for chunks which are in the files but not loaded yet. Outline it again puts the points on the ground and the cut changes
that field. The holes of the fields are marked (254) and giving one back closes only its own, the holes cut by hand stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ

* fix(editor): Fields: a separate field is built after loading with the camera still; a cleared outline or another field chosen forgets the one to outline again; giving back a field keeps the holes of the others over it

- waits_for_ground counts a chunk as still coming while its pack isn't read
  yet (right after opening the scenery none is), and as not coming only when
  the pack is missing or read without that chunk. Before, the first build
  after opening left a saved separate field a hole until the camera moved.
- Clear the outline (Fields and the area fill) and choosing another field in
  the list forget the field put back by Outline it again, so the next cut is
  a new field and not the old one moved.
- All holes of separate fields share one mark, so closing one closed it under
  an overlapping field too; the separate fields left over the closed outline
  are cut again after it (when a field is given back or outlined again).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ

* chore(editor): Fields: one identifier a statement, contains() for the sets (Sonar cpp:S1659, cpp:S6171)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ

* ci(windows): build lua51.dll for the unit tests

(cherry picked from commit b3e6e02779)

* fix(terrain): the fields made again only when one comes or goes; patches_file a plain name; the hand holes leave the fields'

After the review of jerrrrycho at edb5160a:
- update() no longer rebuilds all the water and the separate fields every 200 m the camera moves. Past
  patch_move it compares the separate (not painted) fields within the reach with the ones made, and rebuilds
  only when one came within the reach or left it; otherwise only the centre moves. A terrain with only
  painted fields never rebuilds for a move, also in driving mode. The fields waiting for their ground are
  made again as before.
- patches_file of a manifest is taken only as a plain file name in the folder of the terrain. A path with
  folders, "..", or a root is logged ("Bad terrain: ...") and patches.txt is used instead, so a downloaded
  manifest can't have the patches read from, or saved over, a file elsewhere.
- The holes cut or closed by hand (the Holes tool, "Close the hole" of the Fill section) leave the hole
  samples of the fields (kFieldHole) as they are, so a field's mesh no longer stands over closed ground and
  z-fights with it, and "Give back" still finds the field's hole. The unmarked fallback of cut_field (the
  fields cut before the mark) thereby closes only unmarked holes.
- The field picked with "Outline it again" is forgotten when the Fill tool uses the outline up, and when
  another terrain tool than the fields is chosen, so the next field drawn is a new one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QRgQ1K1Qu7TCsa74zsNURd

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Hirek193 <polomarket73@gmail.com>
2026-11-20 03:56:43 +01:00

397 lines
21 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <condition_variable>
#include <deque>
#include <map>
#include <memory>
#include <mutex>
#include <set>
#include <string>
#include <thread>
#include <vector>
#include <glm/glm.hpp>
#include "editor/editorTerrain.hpp"
struct world_vertex;
namespace scene { class basic_section; class basic_cell; }
// the heightmap terrain of the scenery (scene/heightmapterrain.h), loaded around the camera.
//
// the pack files are read and the meshes made by worker threads; the main thread only puts finished meshes on the gpu,
// within a few milliseconds of each frame. chunks are loaded around the camera and around the place the camera is heading
// to, so a moving train finds its terrain loaded. each chunk is drawn with a grid as coarse as its distance allows.
//
// the editor changes the chunks in memory; they're written to the pack files when the scenery is saved, until then the
// edited chunks stay in memory, also when they're far from the camera
class terrain_streamer
{
public:
using chunk_key = heightmap::chunk_key;
terrain_streamer() = default;
~terrain_streamer();
// opens the terrain kept in terrain/<Name>/ (the folder may not exist yet). returns: true if there's terrain to show
bool open(std::string const &Name);
// stops showing the terrain
void close();
bool active() const { return m_active; }
std::string const &name() const { return m_name; }
// the folder of the terrain, with a trailing slash
std::string const &directory() const { return m_directory; }
// loads and unloads the chunks around the camera, and puts finished meshes on the gpu
void update(glm::dvec3 const &Camera);
// hard reset used when a new scenery loads: drops everything WITHOUT touching scene sections
// (the old region is being torn down, so its section pointers are already dangling)
void reset();
// drawn detail: metres of distance per metre of grid spacing (larger: finer grid further away)
void detail(float const Detail) { m_detail = std::max(10.f, Detail); }
float detail() const { return m_detail; }
// smallest distance (chunks) the terrain is loaded to, whatever the draw range
void radius(int const Radius) { m_radius = std::max(0, Radius); }
int radius() const { return m_radius; }
// chunks held in memory
void collect(std::vector<editor_terrain *> &Out) const;
// chunk covering (X,Z), or nullptr
editor_terrain *terrain_at(double X, double Z) const;
// height of the terrain at (X,Z); false where there's no chunk in memory
bool height_at(double X, double Z, double &Height) const;
// the first point of the ground along the ray from the origin, within the reach; false if it meets none
bool raycast(glm::dvec3 const &Origin, glm::dvec3 const &Direction, double Reach, glm::dvec3 &Hit) const;
// triangles of the full grid of the chunks in memory overlapping the rectangle (x, z)
void gather_triangles(glm::dvec2 const &Min, glm::dvec2 const &Max, std::vector<std::array<glm::dvec3, 3>> &Out) const;
// true if the geometry belongs to the terrain (or its water)
bool owns(gfx::geometry_handle const &Geometry) const;
std::size_t resident() const { return m_chunks.size(); }
// the chunks in memory, those in the scene, their triangles and how many of them have each step of the grid, for the
// measurements of the editor
std::string stats() const;
// chunks in the pack files and in memory, less the removed ones; the files known so far
bool exists(chunk_key const &Key) const;
// the chunks of all the pack files in the folder of the terrain, each with the cells along its side (0: unknown), ordered
// by key, as the files are on the disk: the chunks added or removed since the last save are as they were. reads the
// headers of the files, so it's for a list made now and then, not for every frame
std::vector<std::pair<chunk_key, int>> stored_chunks();
// removed in the editor, still in the files until saved
bool removed(chunk_key const &Key) const { return m_removed.count(Key) > 0; }
// the chunk in memory, or nullptr; Load: read from its pack file if it isn't in memory yet
editor_terrain *chunk(chunk_key const &Key, bool const Load = false);
// editing; the chunks changed are written to the files by save()
heightmap::manifest const &manifest() const { return m_manifest; }
// a flat chunk at (Cx, Cz) of specified spacing and height, covered with the material of palette entry Layer;
// returns false if there's a chunk already
bool add_chunk(int Cx, int Cz, float Spacing, float Height, std::uint16_t Layer = 0);
// a chunk at (Cx, Cz), heights given for each grid point by Height (from its world position)
bool add_chunk(int Cx, int Cz, float Spacing, std::function<float(double X, double Z)> const &Height, std::uint16_t Layer = 0);
// a chunk made elsewhere, at the place its key says; its layers are indices of the palette
bool add_chunk(std::shared_ptr<heightmap::chunk_data> Data);
void remove_chunk(int Cx, int Cz);
// changes the point spacing of the chunk at (Cx, Cz), heights resampled; Paint: paint samples along a side less one
// the chunk gets, 0 keeps the ones it has. returns: true if the chunk changed
bool spacing(int Cx, int Cz, float Spacing, int Paint = 0);
// raises (Strength > 0) or lowers the ground within Radius of (X,Z), with a smooth falloff
bool sculpt(double X, double Z, double Radius, double Strength);
// evens out the ground within Radius of (X,Z), Amount (0..1) of the way at the centre
bool smooth(double X, double Z, double Radius, double Amount);
// leads the ground within Radius of (X,Z) towards the height Target, Amount (0..1) of the way at the centre;
// Mode: 0 up and down, 1 only raises it, 2 only lowers it
bool level(double X, double Z, double Radius, double Target, double Amount, int Mode = 0);
// gives every grid point within the rectangle to Shaper, with its world position and height; Shaper returns true if it
// changed the height. where the modifiers shape the ground the change is a touch-up kept over them (see touch_up()),
// elsewhere it changes the ground under them
bool reshape(glm::dvec2 const &Min, glm::dvec2 const &Max, std::function<bool(double X, double Z, float &Height)> const &Shaper);
// true: the brushes shape the terrain as it's seen, also where the modifiers (tracks) shape it, the changes kept there
// as touch-ups over the modifiers; false: the brushes shape only the ground under the modifiers, which keep their shape
void touch_up(bool const State) { m_touchup = State; }
bool touch_up() const { return m_touchup; }
// takes the touch-ups within Radius of (X,Z) back, Amount (0..1) of the way at the centre: the terrain goes back to the
// shape the modifiers give it
bool restore_stitching(double X, double Z, double Radius, double Amount);
// grid points with touch-ups over the modifiers, in the chunks in memory
std::size_t touched_up() const;
// paints the material of the palette entry Layer within Radius of (X,Z), Strength (0..1) of the way at the centre
bool paint(double X, double Z, double Radius, double Strength, std::uint16_t Layer);
// fills the area within Outline (x, z) with the material of the palette entry Layer, Strength (0..1) of the way.
// Feather: metres across the outline the material blends in over, half of them inside; 0: a sharp edge, as sharp as
// the paint samples of the chunks go. the chunks are loaded where needed
bool fill(std::vector<glm::dvec2> const &Outline, double Feather, std::uint16_t Layer, double Strength = 1.0);
// the same with the edge shifted by up to Noise metres, in waves of about NoiseScale metres, so it isn't drawn with a ruler
bool fill(std::vector<glm::dvec2> const &Outline, double Feather, std::uint16_t Layer, double Strength, double Noise, double NoiseScale);
// holes, for the portals of tunnels and the like: cut in the ground (Cut true) within Radius of (X,Z), or closed again
bool cut(double X, double Z, double Radius, bool Cut);
// the same within Outline (x, z); the chunks are loaded where needed
bool cut(std::vector<glm::dvec2> const &Outline, bool Cut);
// the hole of a field of its own surface cut (Cut true) or closed: marked as the field's, so closing it leaves the holes
// cut otherwise (the Holes tool) there as they are; a hole of a field cut before the mark is closed whole
bool cut_field(std::vector<glm::dvec2> const &Outline, bool Cut);
// grass: grows the kind of the grass palette Kind within Radius of (X,Z), Strength (0..1) of the way at the centre;
// Erase: takes every kind of grass away there instead
bool grass(double X, double Z, double Radius, double Strength, std::uint16_t Kind, bool Erase);
// the same within Outline (x, z), fully; the chunks are loaded where needed
bool grass(std::vector<glm::dvec2> const &Outline, std::uint16_t Kind, bool Erase);
// the grass palette
std::vector<heightmap::grass_def> const &grass_kinds() const { return m_manifest.grass; }
// adds a kind to the grass palette; returns: its index
std::uint16_t add_grass_kind(heightmap::grass_def Kind);
// changes a kind of the grass palette; the grass of that kind changes with it
void grass_kind(std::uint16_t Index, heightmap::grass_def Kind);
// palette entry of the material (repeated at Size, 0: any, turned by Rotation degrees), added to the palette if needed
std::uint16_t layer(std::string const &Material, float Size = 0.f, float Rotation = 0.f);
void layer_size(std::uint16_t Layer, float Size);
// turns the textures of the palette entry Layer by Rotation degrees, on every chunk painted with it
void layer_rotation(std::uint16_t Layer, float Rotation);
// gives the palette entry Layer another material; the chunks painted with it change with it
void layer_material(std::uint16_t Layer, std::string const &Material);
void compress(bool State);
void default_spacing(float Spacing);
// bodies of water
std::vector<heightmap::water_body> const &water() const { return m_manifest.water; }
void water(std::vector<heightmap::water_body> Water);
// material of the bodies of water which don't name their own
void water_material(std::string const &Material);
// pieces of the ground cut out of the terrain with a material of their own (the fields), drawn with the water
std::vector<heightmap::surface_patch> const &patches() const { return m_manifest.patches; }
void patches(std::vector<heightmap::surface_patch> Patches);
// modifiers: added or replaced by name
void modifier(heightmap::modifier Modifier);
// many at once, as the formation of all the tracks: each chunk they reach is led anew once
void modifiers(std::vector<heightmap::modifier> Modifiers);
// the modifiers whose names start so are forgotten, the chunks keep their heights till they're made anew; returns how many
std::size_t drop_modifiers(std::string const &Prefix);
bool remove_modifier(std::string const &Name);
// many at once, as the formations of tracks gone: each chunk they reach is led anew once; returns how many
std::size_t remove_modifiers(std::vector<std::string> const &Names);
// the ground takes the shape the modifier gives it for good, and the modifier is removed: from then on the
// terrain there is shaped by hand like anywhere else
bool bake_modifier(std::string const &Name);
std::vector<heightmap::modifier> const &modifiers() const { return m_manifest.modifiers; }
// changed since the last save
bool modified() const;
// undo: the state of what a change touched, from before it
struct change
{
std::map<chunk_key, heightmap::chunk_ptr> chunks; // the data the chunks had; null: there was no chunk
bool manifest{false}; // the palette, the water (and its material) and the modifiers below were changed
std::vector<heightmap::layer_def> layers;
std::vector<heightmap::water_body> water;
std::vector<heightmap::surface_patch> patches;
std::string water_material;
std::vector<heightmap::modifier> modifiers;
std::vector<heightmap::grass_def> grass;
bool empty() const { return chunks.empty() && false == manifest; }
};
// from now on the state of what's changed is kept, until end_change(); nested calls join the change in progress
void begin_change();
// returns: the state from before the changes made since begin_change() (empty if nothing changed)
change end_change();
bool recording() const { return m_recording > 0; }
// puts the terrain back in the state recorded. returns: the state it replaced, to go forward again
change restore(change const &Change);
// writes the description and the changed pack files. returns: true on success, Error describing the failure
bool save(std::string *Error = nullptr);
private:
struct pack_state
{
enum class state
{
unknown,
loading,
ready,
missing
} status{state::unknown};
std::shared_ptr<heightmap::pack_file const> file;
std::uint32_t generation{0};
};
struct job
{
enum class kind
{
pack,
chunk,
mesh
} type{kind::pack};
heightmap::pack_key pack{0, 0};
chunk_key chunk{0, 0};
std::shared_ptr<heightmap::pack_file const> file;
std::uint32_t generation{0};
heightmap::chunk_ptr data;
std::array<heightmap::chunk_ptr, 4> neighbours; // -x, +x, -z, +z
int stride{1};
glm::dvec3 origin{0.0};
std::uint64_t version{0};
double priority{0.0};
};
struct result
{
job::kind type{job::kind::pack};
heightmap::pack_key pack{0, 0};
chunk_key chunk{0, 0};
std::uint32_t generation{0};
std::shared_ptr<heightmap::pack_file const> file;
std::shared_ptr<heightmap::chunk_data> data;
heightmap::mesh mesh;
int stride{1};
int cells{0};
std::uint64_t version{0};
std::string error;
};
struct geometry_slot
{
gfx::geometrybank_handle bank{0, 0};
gfx::geometry_handle geometry{0, 0};
int cells{0};
int stride{0};
bool cut{false}; // the indices are of a chunk with holes, filled anew with every mesh
bool used{false};
};
struct water_shape
{
gfx::geometry_handle geometry{0, 0};
scene::basic_section *section{nullptr};
scene::basic_cell *cell{nullptr};
};
void start_workers();
void stop_workers();
void worker();
void submit(job Job);
void process(result &Result);
// the chunk is drawn: its shape put in the scene, or put back with a new mesh
void upload(editor_terrain &Chunk, heightmap::mesh &Mesh, int const Stride);
void update_material(editor_terrain &Chunk);
// puts the current material of the chunk in its shape
void upload_shape_material(editor_terrain &Chunk);
// takes the chunk out of the scene, its geometry slot and material given back
void undraw(editor_terrain &Chunk);
void request_mesh(editor_terrain &Chunk, int const Stride, double const Priority);
int wanted_stride(editor_terrain const &Chunk, glm::dvec3 const &Camera) const;
heightmap::chunk_ptr neighbour(chunk_key const &Key) const;
void touch_neighbours(chunk_key const &Key);
material_handle palette_material(std::uint16_t const Layer);
// paints the material of the palette entry Layer over the paint samples within the rectangle, Amount (0..1) of the way
// at each, as Amount gives it for the place of the sample. Load: chunks not in memory are loaded
bool paint_area(glm::dvec2 const &Min, glm::dvec2 const &Max, std::uint16_t Layer, bool Load, std::function<double(double X, double Z)> const &Amount);
// cuts (Cut true) or closes the holes at the hole samples within the rectangle where Inside says so. Load: chunks not in
// memory are loaded
// Mark: the value of a hole sample, 255 of the holes cut by hand, kFieldHole of the fields; with Mark other than 255 only
// the samples of that mark are closed, and a hole already there isn't marked over; with 255 the holes of the fields are left
// as they are
bool cut_area(glm::dvec2 const &Min, glm::dvec2 const &Max, bool Cut, bool Load, std::function<bool(double X, double Z)> const &Inside,
std::uint8_t Mark = 255);
static std::uint8_t constexpr kFieldHole{254};
// grows the kind Kind of the grass palette (or takes all grass away, Erase) over the grass samples within the rectangle,
// Amount (0..1) of the way at each
bool grass_area(glm::dvec2 const &Min, glm::dvec2 const &Max, std::uint16_t Kind, bool Erase, bool Load, std::function<double(double X, double Z)> const &Amount);
// hands the renderer the grass of the chunks near the camera
void publish_grass(glm::dvec3 const &Camera);
// chunk loaded right away from its pack file, for editing far from the camera
editor_terrain *load_now(chunk_key const &Key);
// chunks in memory or in the files overlapping the rectangle, loaded if needed
std::vector<editor_terrain *> chunks_in(glm::dvec2 const &Min, glm::dvec2 const &Max, bool const Load);
// leads the heights of the chunk from its base heights through the modifiers, within the rectangle
void apply_modifiers(editor_terrain &Chunk, glm::dvec2 const &Min, glm::dvec2 const &Max);
// the same with the rectangles the modifiers reach, as modifier_bounds() gives them, worked out once for many chunks
void apply_modifiers(editor_terrain &Chunk, glm::dvec2 const &Min, glm::dvec2 const &Max, std::vector<std::pair<glm::dvec2, glm::dvec2>> const &Bounds);
void apply_modifiers(glm::dvec2 const &Min, glm::dvec2 const &Max);
std::vector<std::pair<glm::dvec2, glm::dvec2>> modifier_bounds() const;
void build_water();
// the vertices of a shape of the water or of a field in the geometry of the water: one made before filled anew, or a new one;
// a handle of chunk 0 if it failed
gfx::geometry_handle water_geometry(gfx::vertex_array Vertices);
void clear_water(bool const Touch);
std::string pack_path(heightmap::pack_key const &Key) const;
// the state of a chunk (null: no chunk) or of the description is kept for the change in progress, if it's the first time
void remember(chunk_key const &Key, heightmap::chunk_ptr const &Data);
void remember(editor_terrain const &Chunk) { remember(Chunk.key(), Chunk.shared()); }
void remember_manifest();
bool m_active{false};
std::string m_name;
std::string m_directory;
heightmap::manifest m_manifest;
bool m_manifestchanged{false};
float m_detail{120.f};
bool m_touchup{true};
int m_radius{2};
std::map<heightmap::pack_key, pack_state> m_packs;
std::map<chunk_key, std::unique_ptr<editor_terrain>> m_chunks;
std::set<chunk_key> m_loading; // asked from a worker
std::set<chunk_key> m_removed; // removed in the editor, still in the files until saved
std::vector<geometry_slot> m_slots;
bool m_nocut{false}; // the renderer can't change the indices of the chunks: the holes are cut by the materials alone
std::map<std::uint64_t, int> m_slotofgeometry; // geometry key -> slot
std::map<std::uint16_t, material_handle> m_palette;
std::vector<water_shape> m_watershapes;
std::vector<gfx::geometry_handle> m_waterfree; // geometry of the water shown before, to be filled anew
gfx::geometrybank_handle m_waterbank{0, 0};
bool m_waterchanged{false};
int m_recording{0};
change m_change;
glm::dvec3 m_camera{0.0};
glm::dvec3 m_velocity{0.0};
double m_cameratime{0.0};
bool m_hascamera{false};
// the pieces cut out of the terrain are made around where the camera was, within patch_reach, again when it moves patch_move away
static constexpr double patch_reach{1500.0}; // at least; as far as the chunks are drawn
// a chunk under the piece is in the files but not loaded yet
bool waits_for_ground(heightmap::surface_patch const &Patch) const;
static constexpr double patch_move{200.0};
glm::dvec2 m_patchcentre{1e12};
bool m_patchpending{false}; // some waited for chunks not loaded
bool m_patchloaded{false}; // a chunk came since they were made
double m_patchtried{0.0};
std::vector<std::size_t> m_patchesbuilt; // the separate pieces (not laid into the paint) within the reach of m_patchcentre, made
// how far around the camera the pieces are made: as far as the chunks are drawn, patch_reach at least
static double reach_of_patches();
// the separate pieces within the reach of Centre, in the order of the manifest
std::vector<std::size_t> patches_in_reach(glm::dvec2 const &Centre) const;
// the pieces to be made anew: some wait for their ground and a chunk came, or the camera moved on so far that a separate piece
// came within the reach or left it. A move that changes nothing only moves the centre the next move is measured from
bool patches_due(glm::dvec3 const &Camera, double Now);
std::vector<chunk_key> m_ring; // offsets of the chunks around a point, the nearest first
int m_ringradius{-1};
double m_pixel{0.0}; // metres a pixel of the top view spans; none in the 3D view
// the last walk over the chunks around the camera, and whether it found nothing more to ask for
bool m_settled{false};
chunk_key m_walkhere{0, 0};
chunk_key m_walkthere{0, 0};
int m_walkradius{0};
double m_walktime{0.0};
// shared with the workers, guarded by m_mutex
std::mutex m_mutex;
std::condition_variable m_wakeup;
std::vector<job> m_jobs;
std::deque<result> m_results;
std::size_t m_busy{0}; // jobs taken by the workers and not finished yet
bool m_stop{false};
std::vector<std::thread> m_workers;
// the pack files are read by the workers and written by save()
std::mutex m_filemutex;
};
// single, simulation-level instance shared by the editor (authoring) and the scenery loader, so the terrain
// renders in every mode. opened by the `heightmap_terrain` scenery directive and updated each frame with the active camera.
extern terrain_streamer EditorTerrain;