17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 10:59:20 +02:00

Give the terrain its own archive, its normals, and a level per tile

The tiles moved out of the scenery's pak into an archive of their own: a
sorted index of fixed-size entries found by where a tile sits in the
quadtree rather than by a name, each entry compressed on its own so a
tile can be read without touching the rest. A name apiece would have been
seventy megabytes of index to read before the first tile could be drawn.

An entry carries what its tile's ground asks for - how far it departs
from the finest mesh, and how long its triangles are - because which
level to draw has to be settled for tiles that are not on the card yet,
and the index is the only thing about them that is read up front. Until
now the figure came from the tile's level, which is the worst tile in it,
so one steep corner spoke for every tile that shared its level.

The mesh carries a normal per vertex, octahedron-encoded into two bytes,
in place of the face normal the fragment stage worked out from how the
view position changed across a triangle. A face normal makes the ground
read as facets, and a coarser level's facets face differently from the
ones they stand for, so the light over a hillside changed as the level
did. A geometry stage hands the fragment stage the three materials of the
triangle it is in and the barycentric weights, so ground changes over a
triangle rather than along its edge; 3.3 has no gl_BaryCoordEXT.

And the level a tile is drawn at now counts the camera's height. The
distance was measured on the ground plane alone, which puts the tile
underfoot nought metres away from a camera a kilometre above it - and
nought metres asks for the finest level there is, so a view from the air
wanted the whole ground at full detail, more tiles than the buffers hold,
and what would not fit came out as holes.

Archives written under the old rules are refused at the door and baked
again.
This commit is contained in:
maj00r
2026-09-20 21:22:03 +02:00
parent b877bc0772
commit 9408216ae7
21 changed files with 1604 additions and 550 deletions

View File

@@ -21,7 +21,7 @@ module;
#include <unordered_map>
#include <vector>
#include "utilities/Globals_macros.h"
#include "scene/pakformat.h"
#include "scene/quantizedmesharchive.h"
#include "scene/quantizedmeshcooker.h"
#include "scene/quantizedmeshreader.h"
@@ -374,6 +374,14 @@ void
finish( std::string const &Sceneryfile, std::vector<std::string> const &Included ) {
if( true == planning() ) {
// let the note go: it is only wanted while the scenery is being read, and on a large map it is
// hundreds of megabytes - galicja's is two hundred and seventy
auto const letgo {
[]() {
decltype( state.note ) empty;
state.note.swap( empty );
std::vector<std::uint8_t> nomasks;
state.masks.swap( nomasks ); } };
WriteLog(
"Terrain cook: " + std::to_string( state.skipped ) + " triangle nodes left to the tiles, "
+ std::to_string( state.filtered ) + " drawn in part, " + std::to_string( state.drawn )
@@ -384,6 +392,7 @@ finish( std::string const &Sceneryfile, std::vector<std::string> const &Included
WriteLog( "Terrain cook: the scenery includes different files than when it was cooked; cooking again on the next start" );
discard( Sceneryfile );
}
letgo();
return;
}
if( false == state.collecting ) { return; }
@@ -401,8 +410,8 @@ finish( std::string const &Sceneryfile, std::vector<std::string> const &Included
// the cook itself, apart from the load that fed it: what a second start saves is the cook
auto const cookstarted { std::chrono::steady_clock::now() };
auto const archive { archive_path( Sceneryfile ) };
pak::writer writer;
if( false == writer.open( archive ) ) {
quantizedmesh::archive_writer writer;
if( false == writer.open( archive, quantizedmesh::cook_rules ) ) {
ErrorLog( "Terrain cook: cannot write \"" + archive + "\"" );
return;
}
@@ -410,8 +419,9 @@ finish( std::string const &Sceneryfile, std::vector<std::string> const &Included
auto written { true };
quantizedmesh::terrain_table table;
auto const sink {
[ &writer, &written ]( quantizedmesh::tile_address const &Tile, std::vector<std::uint8_t> const &Bytes ) {
written = writer.add( quantizedmesh::tile_name( Tile ), Bytes ) && written; } };
[ &writer, &written ]( quantizedmesh::tile_address const &Tile, std::vector<std::uint8_t> const &Bytes,
quantizedmesh::tile_measure const &Measure ) {
written = writer.add( Tile, Bytes, Measure ) && written; } };
if( ( false == state.cooker.finish( sink, table ) ) || ( false == written ) ) {
ErrorLog( "Terrain cook: cooking failed, no tiles written" );
@@ -419,7 +429,7 @@ finish( std::string const &Sceneryfile, std::vector<std::string> const &Included
discard( Sceneryfile );
return;
}
if( false == writer.add( quantizedmesh::tablename, quantizedmesh::write_table( table ) ) ) {
if( false == writer.table( quantizedmesh::write_table( table ) ) ) {
written = false;
}
if( ( false == writer.close() ) || ( false == written ) ) {