mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-31 11:09:06 +01:00
perf(physics): road vehicles farther than 1 km from the camera go by one step of the physics in a frame (physics.roadlod); count what resets the switching time of the vehicles (compressor, mains, diesel, physics woken) in the debug panel
This commit is contained in:
@@ -485,6 +485,12 @@ bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string&
|
||||
return true;
|
||||
}
|
||||
|
||||
if (token == "physics.roadlod")
|
||||
{
|
||||
ParseOne(Parser, physics_roadlod);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (token == "enabletraction")
|
||||
{
|
||||
ParseOne(Parser, bEnableTraction);
|
||||
@@ -1894,6 +1900,7 @@ global_settings::export_as_text( std::ostream &Output ) const {
|
||||
export_as_text( Output, "physicslog", WriteLogFlag );
|
||||
export_as_text( Output, "fullphysics", FullPhysics );
|
||||
export_as_text( Output, "physics.sleepheld", physics_sleepheld );
|
||||
export_as_text( Output, "physics.roadlod", physics_roadlod );
|
||||
export_as_text( Output, "debuglog", iWriteLogEnabled );
|
||||
export_as_text( Output, "multiplelogs", MultipleLogs );
|
||||
export_as_text( Output, "showsystemconsole", ShowSystemConsole );
|
||||
|
||||
@@ -115,6 +115,7 @@ struct global_settings {
|
||||
std::string Period{}; // time of the day, based on sun position
|
||||
bool FullPhysics{ true }; // full calculations performed for each simulation step
|
||||
bool physics_sleepheld{ true }; // vehicles standing still and held by their brakes let their physics sleep, see TMoverParameters::accelerating()
|
||||
bool physics_roadlod{ true }; // road vehicles far from the camera go by one step of the physics in a frame, see vehicle_table::update()
|
||||
bool bnewAirCouplers{ true };
|
||||
float fMoveLight{ 0.f }; // numer dnia w roku albo -1
|
||||
bool FakeLight{ false }; // toggle between fixed and dynamic daylight
|
||||
|
||||
@@ -9,6 +9,11 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Timer {
|
||||
|
||||
double GetTime();
|
||||
@@ -79,6 +84,63 @@ private:
|
||||
float m_accumulator { 0.f };
|
||||
};
|
||||
|
||||
// what resets TMoverParameters::LastSwitchingTime, which keeps the physics of a vehicle on for 5 s: counted over a second,
|
||||
// with the vehicle which did it most often, for the debug panel
|
||||
class switching_counter {
|
||||
|
||||
public:
|
||||
enum source : std::size_t {
|
||||
compressor_on = 0,
|
||||
compressor_off,
|
||||
mains,
|
||||
diesel,
|
||||
wake, // switch_physics( true ) of a vehicle whose physics was off
|
||||
count
|
||||
};
|
||||
struct result {
|
||||
std::array<unsigned int, source::count> events {};
|
||||
std::string busiest; // type and name of the vehicle with the most events
|
||||
unsigned int busiestevents { 0 };
|
||||
};
|
||||
// Owner: the vehicle, Label: its type and name, read only when the second ends
|
||||
void
|
||||
note( source const Source, void const *Owner, std::string const *Type, std::string const *Name ) {
|
||||
++m_events[ Source ];
|
||||
auto &owner { m_owners[ Owner ] };
|
||||
++owner.events;
|
||||
owner.type = Type;
|
||||
owner.name = Name; }
|
||||
// ends the second when it's over. to be called once a frame, while the vehicles noted in it still exist
|
||||
void
|
||||
update() {
|
||||
auto const now { std::chrono::steady_clock::now() };
|
||||
if( now - m_start < std::chrono::seconds( 1 ) ) { return; }
|
||||
m_last = {};
|
||||
m_last.events = m_events;
|
||||
for( auto const &owner : m_owners ) {
|
||||
if( owner.second.events > m_last.busiestevents ) {
|
||||
m_last.busiestevents = owner.second.events;
|
||||
m_last.busiest = ( owner.second.type ? *owner.second.type : std::string{} ) + " " + ( owner.second.name ? *owner.second.name : std::string{} ); } }
|
||||
m_events = {};
|
||||
m_owners.clear();
|
||||
m_start = now; }
|
||||
// of the last whole second
|
||||
result const &
|
||||
last() const {
|
||||
return m_last; }
|
||||
|
||||
private:
|
||||
struct owner_data {
|
||||
unsigned int events { 0 };
|
||||
std::string const *type { nullptr };
|
||||
std::string const *name { nullptr };
|
||||
};
|
||||
std::chrono::time_point<std::chrono::steady_clock> m_start { std::chrono::steady_clock::now() };
|
||||
std::array<unsigned int, source::count> m_events {};
|
||||
std::unordered_map<void const *, owner_data> m_owners;
|
||||
result m_last;
|
||||
};
|
||||
|
||||
struct subsystem_stopwatches {
|
||||
stopwatch gfx_total;
|
||||
stopwatch gfx_color;
|
||||
@@ -139,6 +201,7 @@ struct subsystem_stopwatches {
|
||||
} awake;
|
||||
};
|
||||
vehicle_counts vehicles; // of the frame under way
|
||||
switching_counter switching;
|
||||
vehicle_counts vehicleslast; // of the last frame
|
||||
// ends the frame of the frame_stopwatches and of the counts
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user