mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-02 08:09:14 +01:00
fix(editor): the track shown while it's laid over the ground no longer holds up the frames: its grade line is fitted on a thread of its own, the line fitted a moment ago stretched over the track meanwhile, and the click takes the line fitted for the same ground instead of fitting it again; the terrain follows the tracks once the laying ends, not after each click of a chain
Fitting the grade line took 3 ms for 250 m of track, 30 ms for 1 km, 65 ms for 2 km and 200 ms for 4 km, and the preview of the lay tool and of the drag from a free end fitted it every frame, twice for the drag; on the terrain model the preview of some 800 m took 10 to 17 ms a frame, the cursor standing or not. Now the frame waits under 1.5 ms for 4 km. The formations of the tracks led into the terrain went through every chunk under them 0.3 s after each click, some 50 ms, while the cursor went on to the next point; they wait for the laying to end. The tracks laid and the terrain are the same as before. Selftests: perf logs the longest frame and those over 33 ms, fittime the time of the fit by length, terrainhash a hash of the chunks in memory.
This commit is contained in:
@@ -9,7 +9,11 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
@@ -49,7 +53,54 @@ struct grading
|
||||
double reach{100.0}; // m, how far the ground may part from the line and still be followed
|
||||
};
|
||||
|
||||
// where Bed finds no ground, the heights lead from one end to the other
|
||||
void follow(std::vector<segment_data> &Pieces, ends const &Ends, bed_query const &Bed, grading const &Grading = {});
|
||||
// the ground under a track, sampled along it, and what the grade line is fitted to
|
||||
struct request
|
||||
{
|
||||
std::vector<double> chainages;
|
||||
std::vector<double> targets; // the height of the bed at each chainage, NaN where there's no ground
|
||||
double total{0.0}; // m, the length in plan
|
||||
ends heights;
|
||||
grading grades;
|
||||
|
||||
bool operator==(request const &Other) const;
|
||||
};
|
||||
|
||||
// the grade lines of the track shown while it's laid, fitted on a thread of their own: fitting one takes some milliseconds,
|
||||
// tens of them on a long track over the terrain model, and the track follows the cursor frame after frame. The latest one
|
||||
// asked for is fitted, the ones asked for meanwhile are left out
|
||||
class fitter
|
||||
{
|
||||
public:
|
||||
~fitter();
|
||||
// the line of exactly this request, once fitted; graded false: none was found, the heights lead from end to end
|
||||
bool done(request const &Request, profile::line &Line, bool &Graded) const;
|
||||
// the line fitted last, of whatever request
|
||||
bool latest(request &Request, profile::line &Line, bool &Graded) const;
|
||||
void ask(request Request);
|
||||
|
||||
private:
|
||||
struct result
|
||||
{
|
||||
request asked;
|
||||
profile::line line;
|
||||
bool graded{false};
|
||||
};
|
||||
void work();
|
||||
|
||||
mutable std::mutex m_mutex;
|
||||
std::condition_variable m_wake;
|
||||
std::optional<request> m_asked;
|
||||
std::optional<request> m_fitting;
|
||||
std::optional<result> m_result;
|
||||
bool m_stop{false};
|
||||
std::thread m_thread;
|
||||
};
|
||||
|
||||
// where Bed finds no ground, the heights lead from one end to the other. With a fitter the line it fitted for the same ground
|
||||
// is taken instead of fitting it again
|
||||
void follow(std::vector<segment_data> &Pieces, ends const &Ends, bed_query const &Bed, grading const &Grading = {}, fitter const *Fitted = nullptr);
|
||||
// the same, though the line is fitted by the fitter: until it has it, the track gets the line it fitted last stretched over its
|
||||
// length, if it went on from the same end, or the heights from end to end
|
||||
void follow_meanwhile(std::vector<segment_data> &Pieces, ends const &Ends, bed_query const &Bed, grading const &Grading, fitter &Fitter);
|
||||
|
||||
} // namespace ground_follow
|
||||
|
||||
Reference in New Issue
Block a user