18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 08:35:01 +01:00

feat(editor): ~ shows or hides the orthophoto, Ctrl+~ downloads what the camera sees first; the speed of the camera in the View menu (#312)

* feat(editor): ~ shows or hides the orthophoto, Ctrl+~ downloads what the camera sees first; the speed of the camera in the View menu

~ (the key left of 1) turns the orthophoto on and off. Ctrl+~ finds what of the ground the camera sees (rays through a grid
over the screen down to the level of the ground under the camera, or as far as 2.5 km where they don't come down to it) and
puts those tiles at the front of the queue of the downloads, the ones which failed tried again at once; the status line
tells how many. Tab is not used, the laying and the switches have it.

View > Camera speed: the speed of the free camera of the editor (x0.05 to x10, 1 as it was), how many times faster Ctrl makes
it (1 to 30, 30 as it was), and in the top view as fast as the view is zoomed, so the map crosses the screen at the same pace
zoomed in or out. Kept in the settings of the editor; the camera of the cab and of the free fly outside the editor unchanged.

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

* fix(editor): Ctrl+~ in the top view, over a scenery with no terrain under the camera and with the orthophoto off; "As it was" without the speed going with the zoom

In the top view the box is the view itself, its corners on the ground. The ground under the camera is the terrain, else the
scenery, else the rays go as far as the reach. The tile of the camera is taken anew by hurry(), it isn't followed while the
layer is off. The top view is as fast zoomed in as out by default, as before.

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

* fix(editor): the corners of the top view on the ground put where the camera is (the view matrix is camera-relative)

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

* i18n(editor): Polish for the orthophoto keys and the camera speed, on top of the master's own translations

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

* fix(editor): Ctrl+~ asks only for the tiles update() would ask for; the tooltip of "Track colours" back in its place

After the reviews of #312:
- hurry() skips the tiles outside the download area set and marks the ones outside the area the service covers
  as empty, as update() does, so Ctrl+~ no longer queues downloads update() drops at once (and the workers took
  anyway, into the disk cache, against the area set), nor requests the service can't answer.
- A blank tile hurried takes the standard image first, as in update(); first_level() and outside_area() are
  shared by both loops, and the body of the loop of hurry() is hurry_tile().
- orthophoto_hurry() takes the level of the terrain only when it's below the camera, as the branch of the
  scenery already did: a camera under the terrain (a tunnel, under the heightmap) no longer flips the box of
  the view behind it.
- The "Camera speed" menu goes after the tooltip of "Track colours", which it had taken.
- #include <set> once in editorOrthophoto.hpp.

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>
This commit is contained in:
pol102
2026-11-20 03:55:34 +01:00
committed by GitHub
parent 7524cfbcc2
commit 6c94f9743b
9 changed files with 317 additions and 9 deletions

View File

@@ -1032,6 +1032,20 @@ editor_orthophoto::statistics editor_orthophoto::stats() const
return out;
}
int editor_orthophoto::first_level(tile const &Tile, int const Level)
{
// a tile showing nothing yet takes the standard image first, from the disk cache at once mostly: the 4K one comes from a slow
// service a few at a time, the tiles around the camera stayed blank meanwhile though their standard images lay on the disk
if (Level > standard_pixels && Tile.level < standard_pixels)
return standard_pixels;
return Level;
}
bool editor_orthophoto::outside_area(tile_key const &Key) const
{
return false == m_area.empty() && 0 == m_area_tiles.count(Key);
}
int editor_orthophoto::level_for(int Distance, bool Hires)
{
// coarser imagery further away keeps the memory use of large radii in check
@@ -1630,7 +1644,7 @@ void editor_orthophoto::update(glm::dvec3 const &Camera)
{
tile_key const key{centre.first + dx, centre.second + dy};
// outside the download area: nothing asked for, nothing shown
if (false == m_area.empty() && 0 == m_area_tiles.count(key))
if (outside_area(key))
{
if (auto const found{m_tiles.find(key)}; found != m_tiles.end())
{
@@ -1642,11 +1656,7 @@ void editor_orthophoto::update(glm::dvec3 const &Camera)
tile &t = m_tiles[key];
if (!in_service_area(key.first, key.second))
t.empty = true;
int level = level_for(std::max(std::abs(dx), std::abs(dy)), m_config.hires);
// a tile showing nothing yet takes the standard image first, from the disk cache at once mostly: the 4K one comes from a slow
// service a few at a time, the tiles around the camera stayed blank meanwhile though their standard images lay on the disk
if (level > standard_pixels && t.level < standard_pixels)
level = standard_pixels;
int const level = first_level(t, level_for(std::max(std::abs(dx), std::abs(dy)), m_config.hires));
if (t.empty || (t.level == level && t.alpha == m_alpha) || (t.requested == level && t.requested_alpha == m_alpha) || now < t.retry_at)
continue;
schedule(key, t, level, m_alpha);
@@ -1713,7 +1723,8 @@ void editor_orthophoto::worker()
continue;
long long const dx = it->key.first - m_focus.first;
long long const dy = it->key.second - m_focus.second;
long long const d = dx * dx + dy * dy;
// the tiles hurried (Ctrl+~) before all the others, the nearest of them first
long long const d = dx * dx + dy * dy - (m_urgent.count(it->key) > 0 ? (1LL << 40) : 0LL);
if (d < bestdistance)
{
bestdistance = d;
@@ -1730,6 +1741,7 @@ void editor_orthophoto::worker()
{
current = *best;
m_queue.erase(best);
m_urgent.erase(current.key);
m_running.insert(current.key);
if (current.level >= hires_pixels)
++m_running_hires;
@@ -1957,3 +1969,58 @@ void editor_orthophoto::draw(glm::mat4 const &ViewProjection, glm::dvec3 const &
drawlist->PopTextureID();
}
}
bool editor_orthophoto::hurry_tile(tile_key const &Key, int const Distance)
{
// as update() does: nothing asked for outside the download area, nor outside the area the service covers, where the requests
// can't be answered
if (outside_area(Key))
return false;
auto &t{m_tiles[Key]};
if (false == in_service_area(Key.first, Key.second))
t.empty = true;
if (t.empty)
return false;
auto const level{first_level(t, level_for(Distance, m_config.hires))};
t.retry_at = 0.0;
if (t.level == level && t.alpha == m_alpha)
return false; // already shown as it should be
if (false == (t.requested == level && t.requested_alpha == m_alpha))
schedule(Key, t, level, m_alpha);
return true;
}
std::size_t editor_orthophoto::hurry(glm::dvec2 const &Min, glm::dvec2 const &Max, glm::dvec3 const &Camera)
{
if (false == m_enabled)
return 0;
// the tile of the camera as it is now: it isn't followed while the layer is off
m_camera_tile = camera_tile(Camera);
{
std::lock_guard<std::mutex> lock(m_mutex);
m_focus = m_camera_tile;
}
auto const a{camera_tile(glm::dvec3{Min.x, 0.0, Min.y})};
auto const b{camera_tile(glm::dvec3{Max.x, 0.0, Max.y})};
tile_key const first{std::min(a.first, b.first), std::min(a.second, b.second)};
tile_key const last{std::max(a.first, b.first), std::max(a.second, b.second)};
auto const centre{m_camera_tile};
int const radius = m_config.radius;
std::vector<tile_key> keys;
for (int y = first.second; y <= last.second; ++y)
for (int x = first.first; x <= last.first; ++x)
{
tile_key const key{x, y};
auto const distance{std::max(std::abs(x - centre.first), std::abs(y - centre.second))};
if (distance <= radius && hurry_tile(key, distance))
keys.push_back(key);
}
auto const count{keys.size()};
{
std::lock_guard<std::mutex> lock(m_mutex);
m_urgent.clear();
m_urgent.insert(keys.begin(), keys.end());
}
m_wakeup.notify_all();
return count;
}

View File

@@ -102,6 +102,9 @@ class editor_orthophoto
editor_orthophoto(editor_orthophoto const &) = delete;
editor_orthophoto &operator=(editor_orthophoto const &) = delete;
// the tiles over a rectangle of the world (x, z; what the camera sees), within the reach around the camera, asked for before anything
// else, the ones which failed tried again at once. returns: how many were put at the front of the queue
std::size_t hurry(glm::dvec2 const &Min, glm::dvec2 const &Max, glm::dvec3 const &Camera);
bool enabled() const { return m_enabled; }
// disabling drops the queue and returns the gpu memory of the resident tiles
void enabled(bool State);
@@ -245,6 +248,12 @@ class editor_orthophoto
};
static int level_for(int Distance, bool Hires);
// the level a tile is asked for at first: a tile showing nothing yet takes the standard image before the 4K one
static int first_level(tile const &Tile, int Level);
// the tile is outside the download area set, which then has no imagery asked for it
bool outside_area(tile_key const &Key) const;
// a tile of the view hurried: put at the front of the queue unless it's shown as it should be. true: counted among the hurried
bool hurry_tile(tile_key const &Key, int Distance);
tile_key camera_tile(glm::dvec3 const &Camera) const;
glm::dvec2 tile_corner(tile_key const &Key) const; // world (x,z) of the north-west corner
void schedule(tile_key const &Key, tile &Tile, int Level, std::uint8_t Alpha);
@@ -300,6 +309,7 @@ class editor_orthophoto
bool m_prefetch_paused{false};
source m_prefetch_source;
std::uint32_t m_prefetch_generation{0};
std::set<tile_key> m_urgent; // asked for by hurry(): workers take these first; guarded by m_mutex
std::atomic<bool> m_stop{false};
std::atomic<std::uint32_t> m_generation{1};

View File

@@ -198,6 +198,18 @@ bool editorSettings::load()
layer.terms = fields[5];
m_wms_layers.push_back(layer);
}
else if (key == "camera_speed")
{
parse(value, m_camera.speed);
m_camera.speed = std::clamp(m_camera.speed, 0.05, 10.0);
}
else if (key == "camera_fast")
{
parse(value, m_camera.fast);
m_camera.fast = std::clamp(m_camera.fast, 1.0, 30.0);
}
else if (key == "camera_zoomed")
m_camera.zoomed = (value == "1");
else if (key.rfind(origin_prefix, 0) == 0)
{
// northing;easting
@@ -269,6 +281,9 @@ bool editorSettings::save()
stream << "laying_heights " << (m_heights == lay_heights::points ? "points" : m_heights == lay_heights::level ? "level" : "fitted") << "\n";
for (auto const &layer : m_wms_layers)
stream << "wms_layer " << (layer.visible ? 1 : 0) << ";" << layer.opacity << ";" << encoded(layer.url) << ";" << encoded(layer.layers) << ";" << encoded(layer.title) << ";" << encoded(layer.terms) << "\n";
stream << "camera_speed " << m_camera.speed << "\n";
stream << "camera_fast " << m_camera.fast << "\n";
stream << "camera_zoomed " << (m_camera.zoomed ? 1 : 0) << "\n";
stream << std::fixed << std::setprecision(3);
for (auto const &origin : m_orthophoto_origins)
stream << origin.first << " " << origin.second.first << ";" << origin.second.second << "\n";

View File

@@ -119,10 +119,19 @@ public:
};
lay_heights heights() const { return m_heights; }
void heights(lay_heights Heights) { m_heights = Heights; }
// the free camera: its speed, how many times faster Ctrl makes it, and in the top view as fast as the view is zoomed
struct camera_settings
{
double speed{1.0};
double fast{30.0};
bool zoomed{false}; // off as the editor was before: "As it was" means it
};
camera_settings &camera() { return m_camera; }
private:
movement_scheme m_movement{movement_scheme::wsad};
orthophoto_settings m_orthophoto;
camera_settings m_camera;
std::map<std::string, std::pair<double, double>> m_orthophoto_origins;
std::vector<wms_layer> m_wms_layers;
double m_platform_edge{1.725};