mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 08:39:19 +02:00
Track what cooked data was made from, and cook it as a step of its own
A baked heightfield was trusted for as long as its file was readable, and the logic container while the .scn was older than it: an edited include went unnoticed by both, and node keys leaned on file dates, so merely touching a file changed them. And cooking only ever happened as a side effect of starting a scenery. Every cooked artifact now has a manifest beside it - <scenario>.ehf.deps, <scenario>.logic.deps - listing each file it was made from with its size, modification time and a hash of its content (simulation/cookdeps). The parser records what it includes as it reads, so the list is exactly what the load read. An artifact is current when every listed file still has its content: size and time are the quick check, and when either differs the content is hashed, so a touched or copied file does not force a rebuild and an edited one always does. A file added to the scenery cannot be in a manifest; the files read are compared with it after the load, and a mismatch sends the terrain to be baked on the next start - the new file's nodes, whose keys are unknown, are drawn as geometry meanwhile - and the logic, cooked from the loaded state, is cooked at once. The terrain depends on what the scenario includes and not on the scenario file itself, which the launcher rewrites on every start; the logic depends on both, since events can be written in either, and costs milliseconds to cook again. With the manifest vouching for file content, a triangle node's key is its file, line, include parameters and placement, without the date. -cook loads a scenery, brings whatever is stale up to date, and quits: the step that prepares a scenery ahead of play. It closes the window directly, as there is no simulation to wind down; a quit command waited a minute in the queue for one. Baking on a first start stays as the fallback, and -nobaketerrain still turns it off. Tried on a copy of baltyk with a terrain include of its own: a fresh cook bakes and cooks everything, a second finds nothing to do, a touched file changes nothing, an edited include is caught by its hash and both artifacts are rebuilt, and a new include has the logic recooked at once and the terrain on the next run. A cooking run of baltyk takes 5.5 s with nothing stale and 10.7 s with everything to do.
This commit is contained in:
@@ -26,6 +26,7 @@ import eu07.simulation.simulationsounds;
|
||||
import eu07.utilities.logs;
|
||||
import eu07.utilities.globals;
|
||||
import eu07.utilities.utilities;
|
||||
import eu07.simulation.cookdeps;
|
||||
|
||||
namespace simulation {
|
||||
|
||||
@@ -130,7 +131,7 @@ targets_of( basic_event const &Event, scene::logic::event_kind const Kind, scene
|
||||
} // anonymous namespace
|
||||
|
||||
bool
|
||||
cook_logic( std::string const &Sceneryfile ) {
|
||||
cook_logic( std::string const &Sceneryfile, std::vector<std::string> const &Sources ) {
|
||||
|
||||
scene::logic::container_writer writer;
|
||||
auto const count { simulation::Events.event_count() };
|
||||
@@ -158,19 +159,22 @@ cook_logic( std::string const &Sceneryfile ) {
|
||||
ErrorLog( "Logic container: " + std::to_string( unknown ) + " events of a kind this build cannot cook" );
|
||||
}
|
||||
|
||||
return writer.write( scene::logic::container_path( Sceneryfile ) );
|
||||
auto const path { scene::logic::container_path( Sceneryfile ) };
|
||||
return ( true == writer.write( path ) )
|
||||
&& ( true == cookdeps::write( path + ".deps", Sources ) );
|
||||
}
|
||||
|
||||
bool
|
||||
logic_stale( std::string const &Sceneryfile ) {
|
||||
logic_stale( std::string const &Sceneryfile, std::vector<std::string> const &Sources ) {
|
||||
|
||||
auto const path { scene::logic::container_path( Sceneryfile ) };
|
||||
|
||||
if( false == FileExists( path ) ) {
|
||||
return true;
|
||||
}
|
||||
if( last_modified( scenery_file( Sceneryfile ) ) > last_modified( path ) ) {
|
||||
WriteLog( "Logic container: \"" + path + "\" is older than the scenery, recooking" );
|
||||
if( ( false == cookdeps::current( path + ".deps" ) )
|
||||
|| ( false == cookdeps::lists( path + ".deps", Sources ) ) ) {
|
||||
WriteLog( "Logic container: \"" + path + "\" was made from files that have changed since, recooking" );
|
||||
return true;
|
||||
}
|
||||
// the header says whether this build can read it at all, which covers a container
|
||||
|
||||
Reference in New Issue
Block a user