17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-30 12:00:30 +01:00

Stream the scenery: a baked terrain heightfield, a logic container, and prefabs

Today's work on the binary scene format plan (binary-scene-format-plan.md), from the
first measurement to a terrain that bakes itself on first run and streams from a
thread. The step-by-step history is kept on backup/scene-streaming-format-presquash-0916.

Measuring first. -loadprofile times a scenery load by stage and by node kind and reports
node counts and resident memory. On l204 terrain is 95% of the bytes and 99.8% of the
nodes; on quarkmce2007 vehicles, not models, dominate what is left. The terrain turned
out to be a heightfield in all but name, a ribbon covering 12% of its bounding box.

The heightfield. scene/heightfieldformat.h is the .ehf layout: Morton-ordered tiles
of 128 samples with one shared edge sample, a point-sampled mip chain, zstd per tile,
a nodata sentinel, a material palette with a measured tiling per material, and a stamp
of the rules that decided what counted as terrain. scene/heightfieldreader.h reads it
for the tool, the renderer and the loader alike, and scene/terraincooker.h writes it,
shared by the terraincook tool and the engine so a first-run bake is the file the tool
would have made. The cooker rasterises every triangle where it is drawn (through
scene::place_in_world, the placement the region applies too), keeps an upper surface
laid within half a metre over another and the lower of two further apart, and then
asks each triangle whether the heightfield shows it: laid, reaching a sample, keeping
nearly all it claimed, and with the ground around it drawn at every level out to 2 km.

Baking on first run. simulation/terrainbake bakes <scenario>.ehf the first time a
scenery is opened, choosing the grid step from the first 200,000 vertices, and on later
loads leaves out the triangles its node table says the heightfield shows. Everything
else - trees, grass tufts, gantries, bridge decks - is drawn as written, so a bad bake
can at worst draw something twice, and the heightfield sits 2 cm under the triangles so
the original wins there. Nodes are keyed by file, line, include parameters and
placement; an edited file changes its keys and those nodes are drawn again. A bake under
older rules, or without its table, is thrown away and redone. A launcher copy named
$scenario shares the scenario's files. -nobaketerrain shows the triangles as written.
A scenery can still name hand-cooked fields, several at different steps.

Drawing and streaming. rendering/terrainclipmap draws resident tiles at the mip level
their distance earns, deriving the grid from gl_VertexID and texturing in world space
with the scenery's own materials. rendering/terraintileloader reads and decodes tiles on
a thread of its own; the renderer rescans what is in range only after moving a quarter
of a tile, asks for what is missing nearest first, uploads at most 32 tiles a frame,
drops arrivals the camera has moved past, and keeps drawing a tile at the level it has
until the right one arrives. The terrain has its own range, terrainrange in the ini and
a slider in the debug panel, 20 km by default and independent of basedrawrange; the far
plane of an ordinary view is pushed out to it. The debug panel shows the range, tiles in
view, on the gpu, wanted and queued, and how many sit at each level.

Events. The event queue moved out of the events into a binary heap with a deterministic
tie-break, and an event is handed its activator instead of storing it, so basic_event
is a definition and nothing else.

The logic container. scene/logicformat.h and scene/logiccontainer write a scenery's
events, their targets and sibling chains as flat, deterministic arrays with a schema
hash that refuses a mismatched build. simulation/logiccook cooks it from the loaded
state whenever it is missing, stale or unreadable, reads it straight back to check it,
and resolves each target to a position in the registry its event kind searches.
-cooklogic forces a cook, -verifylogic only checks. Nothing reads it at load yet.

Prefabs. scene/prefab describes a signal by the aspects it can show - lights, speeds,
animation channels, a sound - instead of pasting an .inc per variant, and expands an
instance to ordinary scenery text. Tried on a light signal and a shape signal.

Screenshots without a person present: -shot x,y,z[,yaw[,pitch]], -shotsettle, -shotstay.
This commit is contained in:
maj00r
2026-09-16 23:18:09 +02:00
parent 366645ef59
commit 2660d14565
47 changed files with 7117 additions and 240 deletions

View File

@@ -79,10 +79,10 @@ public:
virtual
void
init() = 0;
// executes event
// executes the event on behalf of the vehicle that triggered it, if any
virtual
void
run();
run( TDynamicObject const *Activator );
// sends basic content of the class in legacy (text) format to provided stream
virtual
void
@@ -110,15 +110,20 @@ public:
void group( scene::group_handle Group );
scene::group_handle group() const;
std::string const &name() const { return m_name; }
// what this event calls itself in a scenery, for anything that has to write it back out
std::string type_name() const { return type(); }
// the names this event was written to act on, in the order it was written with them
std::vector<std::string> target_names() const;
// members
basic_event *m_next { nullptr }; // następny w kolejce // TODO: replace with event list in the manager
basic_event *m_sibling { nullptr }; // kolejny event z tą samą nazwą - od wersji 378
std::string m_name;
bool m_ignored { false }; // replacement for tp_ignored
bool m_passive { false }; // false gdy ma nie być dodawany do kolejki (skanowanie sygnałów)
int m_inqueue { 0 }; // ile razy dodany do kolejki
TDynamicObject const *m_activator { nullptr };
double m_launchtime { 0.0 };
// position in the manager's collection, assigned once when the event is inserted.
// it is the event's identity, not its state: the queue keys on it, so that two
// events due at the same instant run in an order that does not depend on the order
// they happened to be queued in
std::uint32_t m_index { 0 };
double m_delay { 0.0 };
double m_delayrandom { 0.0 }; // zakres dodatkowego opóźnienia // standardowo nie będzie dodatkowego losowego opóźnienia
double m_delaydeparture { std::numeric_limits<double>::quiet_NaN() }; // departure-based event delay
@@ -168,7 +173,7 @@ private:
// deserialize() subclass details
virtual void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) = 0;
// run() subclass details
virtual void run_() = 0;
virtual void run_( TDynamicObject const *Activator ) = 0;
// export_as_text() subclass details
virtual void export_as_text_( std::ostream &Output ) const = 0;
// members
@@ -220,7 +225,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -243,7 +248,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
};
@@ -273,7 +278,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
};
@@ -299,7 +304,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
//determines whether provided input should be passed to consist owner
@@ -322,7 +327,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
};
@@ -343,7 +348,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
};
@@ -369,7 +374,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -398,7 +403,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -432,7 +437,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -459,7 +464,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -488,7 +493,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -511,7 +516,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -536,7 +541,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -559,7 +564,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -582,7 +587,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -605,7 +610,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -622,7 +627,7 @@ public:
private:
std::string type() const override;
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
void run_() override;
void run_( TDynamicObject const *Activator ) override;
void export_as_text_( std::ostream &Output ) const override;
bool is_instant() const override;
@@ -645,7 +650,7 @@ private:
// deserialize() subclass details
void deserialize_( cParser &Input, scene::scratch_data &Scratchpad ) override;
// run() subclass details
void run_() override;
void run_( TDynamicObject const *Activator ) override;
// export_as_text() subclass details
void export_as_text_( std::ostream &Output ) const override;
// members
@@ -687,11 +692,39 @@ public:
inline void purge (TEventLauncher *Launcher) {
m_radiodrivenlaunchers.purge(Launcher);
m_inputdrivenlaunchers.purge(Launcher); }
// returns first event in the queue
inline
// one entry of the pending queue. the event itself holds none of this: when it runs
// and what asked for it are properties of this request, not of the event
struct queued_event {
double launchtime { 0.0 };
std::uint32_t index { 0 };
TDynamicObject const *activator { nullptr };
};
// the queue in the order it will run, for anything that wants to look at it.
// returned by value: this is for display and debugging, not for the hot path
std::vector<queued_event>
queue_snapshot() const;
// the event an entry refers to, or null if the index is stale
basic_event *
begin() {
return QueryRootEvent; }
event_at( std::uint32_t const Index ) const {
return Index < m_events.size() ? m_events[ Index ] : nullptr; }
bool
queue_empty() const { return m_queue.empty(); }
// how many events the manager holds. with event_at() this is the whole read-only view
// of the collection, which is all a cooker needs
std::uint32_t
event_count() const { return static_cast<std::uint32_t>( m_events.size() ); }
// the index of an event's next sibling - the next event registered under the same name
// - or an out of range value when it has none
std::uint32_t
sibling_of( std::uint32_t const Index ) const;
private:
static bool later( queued_event const &Left, queued_event const &Right );
bool pending( basic_event const *Event ) const;
void push( queued_event const &Entry );
public:
basic_event*
FindEventById(uint32_t id);
@@ -735,8 +768,14 @@ private:
// NOTE: disabled until event class refactoring
event_sequence m_eventqueue;
*/
// legacy version of the above
basic_event *QueryRootEvent { nullptr };
// pending events, kept as a binary heap ordered by launch time and then by event
// index. a sorted linked list threaded through the events themselves cost a linear
// walk on every insertion, put queue state inside the event definition, and left the
// order of events due at the same instant depending on insertion history
std::vector<queued_event> m_queue;
// whether an event is already pending, indexed by event index. guards against an
// event being queued twice over
std::vector<std::uint8_t> m_queued;
basic_event *m_workevent { nullptr };
event_map m_eventmap;
basic_table<TEventLauncher> m_inputdrivenlaunchers;