mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 08:04:57 +01:00
* fix(editor): the orthophoto shown one of three ways, chosen in one place, and laid on the terrain without flicker
The settings of the orthophoto had two checkboxes ("Fit to terrain", "Covered by
objects and terrain") and three heights greyed out by turns, and the user couldn't
tell what they did. They're one choice now, each way told under it:
- over the view: drawn over everything, see-through, to compare with the map
- on the terrain, in the scene: tracks and models cover it, lit, the mouse
places objects on it
- a flat sheet in the scene: for a scenery with no terrain yet
The lift is shown only where it matters (on the terrain, in the scene), the
height is named for what it is in each way ("where there's no ground"), and the
ways in the scene are greyed out with the Better Renderer, which doesn't show
them.
On the terrain in the scene the photos are a copy of the ground's triangles 5 cm
up, which the depth buffer lost further away: they flickered with the terrain
textures. Their shapes are decals now, drawn with a polygon offset towards the
camera (the depth is reversed, so a positive one) in every pass but the shadows.
The translations hold the strings of the terrain of the download area as well.
* fix(editor): the terrain made from the NMT under one rule, also around the camera within the download area
The download area didn't bring the terrain: the NMT squares in it were fetched
only once the model had been placed (its panel opened) and the scenery had
terrain open, and nothing told why. They're fetched from the area as it is now,
in PUWG 1992 already.
Where a chunk is made from the model where there's no terrain, the rule is one
for the track laid, the area and the buttons of the panel (nmt_chunk_offset):
beside terrain made from the model it goes on at its height over the model,
otherwise (terrain made by hand, or none) at the offset of the scenery; no chunk
is left out for what lies beside it. Before, the terrain under the track laid
needed terrain in the scenery and a chunk of it beside, gave up chunks for the
session otherwise, and the model was placed only by its panel.
The terrain of the area: "The terrain of the scenery around the camera" (on by
default, kept with the editor) makes the chunks missing in the area in a square
of 9 x 9 around the camera, the nearest first, as the camera goes. Light: a chunk
at most every 0.1 s and three times as long as it took left to the editor, after
the work with the model the user asked for; the step of the terrain history the
editor keeps open is closed around each chunk, as for the terrain grown while
laying. Not the whole area at once: the chunks made wait in memory to be saved.
The log tells what holds it.
The download of the area gives way to the squares asked for: a square of the
area being downloaded is broken off as one is asked for (the terrain under the
track laid) and taken up again later.
The map no longer covers the area with green over the tiles in the cache, only
the failed ones are red.
* fix(editor): the terrain under the tracks follows them again, a brush stroke keeps its undo, the area terrain timed
From the review of the terrain made from the NMT under one rule:
- The terrain drawn to the tracks place by place (under the tracks) took the
height of the chunk beside it, carrying one offset along a run of chunks,
metres off the tracks: nmt_chunk_offset gives the offsets of the tracks there
again. The height the track laid goes on at (state.ahead) comes from the
terrain grown under it only, not from the chunks of the buttons.
- A chunk of the area made during a stroke of the terrain brush closed the
stroke's step of the history, and its undo lost the part brushed before: the
area terrain waits for the stroke to end.
- In a scenery with no name yet the terrain under the track laid was asked for
and dropped every half a second, the log filled: nothing is asked for there.
The log tells how long the chunks of the square around the camera took, and the
self-test sets the area terrain on or off for its run (nmtsettings area 0|1).
Measured on lukow.scn: 1.3-1.5 ms a chunk, 2.2 ms the longest; the longest frame
17 ms against 10 ms without it, none over 33 ms.
* fix(editor): the selftest turns the area terrain on or off for its run only, the setting kept
---------
Co-authored-by: maj00r <maj00r@host>
122 lines
4.8 KiB
C++
122 lines
4.8 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 <cstdint>
|
|
#include <deque>
|
|
#include <filesystem>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <set>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include <glm/glm.hpp>
|
|
|
|
// heights of the ground from the digital terrain model of GUGiK (NMT, the WCS service of geoportal.gov.pl): squares of the
|
|
// EPSG:2180 grid fetched in the background at 1 m, kept on the disk and sampled in the coordinates of the scenery. the
|
|
// scenery is placed on the grid by the PUWG 1992 coordinates of its point (0,0,0), as the orthophoto is: easting = east - x,
|
|
// northing = north + z. the heights are those of the model, metres over the sea
|
|
class editor_nmt
|
|
{
|
|
public:
|
|
editor_nmt();
|
|
~editor_nmt();
|
|
editor_nmt(editor_nmt const &) = delete;
|
|
editor_nmt &operator=(editor_nmt const &) = delete;
|
|
|
|
// where the point (0,0,0) of the scenery lies in PUWG 1992; the squares fetched stay, only the mapping changes
|
|
void place(double const North, double const East);
|
|
// a scenery at (0,0) isn't placed anywhere
|
|
bool placed() const;
|
|
// the height of the model at the point of the scenery; false where its square isn't in yet or the model has no data
|
|
bool height(double const X, double const Z, double &Height) const;
|
|
// the squares under the rectangle of the scenery (x, z) asked for in the background, the ones nearest its middle first;
|
|
// true if all of them are in already, those the service couldn't give included
|
|
bool request(glm::dvec2 const &Min, glm::dvec2 const &Max);
|
|
// squares asked for and not in yet
|
|
std::size_t waiting() const;
|
|
// a square under the rectangle the service didn't give, which is asked for again after a while
|
|
bool retrying(glm::dvec2 const &Min, glm::dvec2 const &Max) const;
|
|
// the squares the service didn't give asked for again at once
|
|
void retry();
|
|
// the squares waiting aren't fetched; those in stay
|
|
void cancel();
|
|
// why squares in memory have no data, empty when all came; a place outside of the model is told first. Again: whether
|
|
// some of them are asked for again
|
|
std::string error(bool *Again = nullptr) const;
|
|
// the squares dropped from the memory, and those waiting; the files on the disk stay
|
|
void clear();
|
|
// whether this build can fetch from the service at all
|
|
static bool can_download();
|
|
// the squares touching the polygon of PUWG 1992 (easting, northing) put into the disk cache in the background, while no
|
|
// square is asked for; none of them kept in the memory. Empty: none
|
|
void prefetch(std::vector<glm::dvec2> const &Polygon);
|
|
void prefetch_paused(bool const Paused);
|
|
// of the squares of the polygon: in the disk cache, all of them, failed
|
|
struct prefetch_state
|
|
{
|
|
int cached{0};
|
|
int total{0};
|
|
int failed{0};
|
|
};
|
|
prefetch_state prefetched() const;
|
|
|
|
// side of a square of the grid, m
|
|
static double constexpr square_size{500.0};
|
|
|
|
private:
|
|
using key = std::pair<int, int>; // easting and northing index of the square on the grid
|
|
struct square
|
|
{
|
|
double east{0.0}; // of the outer edge of the first column
|
|
double north{0.0}; // of the outer edge of the first row, the northernmost
|
|
double pixel{1.0};
|
|
int width{0};
|
|
int height{0};
|
|
std::vector<float> heights; // rows from the north, columns from the west
|
|
bool failed{false}; // the service gave nothing usable: the square has no data
|
|
bool outside{false}; // failed for it lies outside of the model: asked again, it gives nothing either
|
|
double failed_at{0.0}; // s
|
|
std::string error;
|
|
};
|
|
|
|
key key_of(double const East, double const North) const;
|
|
void work();
|
|
// Yielded given: a square of the download area, its download broken off as soon as a square is asked for (the terrain under the
|
|
// track laid), and true then
|
|
std::shared_ptr<square const> fetch(key const &Key, std::string &Error, bool *Yielded = nullptr);
|
|
|
|
mutable std::mutex m_mutex;
|
|
std::condition_variable m_wake;
|
|
std::vector<std::thread> m_workers;
|
|
std::deque<key> m_queue;
|
|
std::set<key> m_queued;
|
|
std::map<key, std::shared_ptr<square const>> m_squares;
|
|
std::string m_coverage; // the name of the model in the service, read from its capabilities once
|
|
double m_north{0.0};
|
|
double m_east{0.0};
|
|
bool m_stop{false};
|
|
// the squares of the download area for the disk cache
|
|
std::vector<key> m_prefetch;
|
|
std::size_t m_prefetch_next{0};
|
|
std::deque<key> m_prefetch_again; // broken off for a square asked for, taken up before the next ones
|
|
std::set<key> m_prefetch_cached;
|
|
std::set<key> m_prefetch_failed;
|
|
std::uint32_t m_prefetch_generation{0};
|
|
bool m_prefetch_paused{false};
|
|
void start_workers(); // under the lock
|
|
std::filesystem::path file_of(key const &Key) const; // in the disk cache
|
|
};
|