mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 00:09:18 +02:00
Experimental async train processing option
This commit is contained in:
@@ -59,6 +59,11 @@ global_settings::ConfigParse(cParser &Parser) {
|
|||||||
Parser.getTokens();
|
Parser.getTokens();
|
||||||
Parser >> local_start_vehicle;
|
Parser >> local_start_vehicle;
|
||||||
}
|
}
|
||||||
|
else if (token == "async.trains")
|
||||||
|
{
|
||||||
|
Parser.getTokens();
|
||||||
|
Parser >> trainAsyncProcessing;
|
||||||
|
}
|
||||||
else if (token == "fieldofview")
|
else if (token == "fieldofview")
|
||||||
{
|
{
|
||||||
Parser.getTokens(1, false);
|
Parser.getTokens(1, false);
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ struct global_settings {
|
|||||||
int iSlowMotion{ 0 }; // info o malym FPS: 0-OK, 1-wyłączyć multisampling, 3-promień 1.5km, 7-1km
|
int iSlowMotion{ 0 }; // info o malym FPS: 0-OK, 1-wyłączyć multisampling, 3-promień 1.5km, 7-1km
|
||||||
basic_light DayLight;
|
basic_light DayLight;
|
||||||
float SunAngle{ 0.f }; // angle of the sun relative to horizon
|
float SunAngle{ 0.f }; // angle of the sun relative to horizon
|
||||||
|
bool trainAsyncProcessing{false};
|
||||||
double fLuminance{ 1.0 }; // jasność światła do automatycznego zapalania
|
double fLuminance{ 1.0 }; // jasność światła do automatycznego zapalania
|
||||||
double fTimeAngleDeg{ 0.0 }; // godzina w postaci kąta
|
double fTimeAngleDeg{ 0.0 }; // godzina w postaci kąta
|
||||||
float fClockAngleDeg[ 6 ]; // kąty obrotu cylindrów dla zegara cyfrowego
|
float fClockAngleDeg[ 6 ]; // kąty obrotu cylindrów dla zegara cyfrowego
|
||||||
|
|||||||
41
Train.cpp
41
Train.cpp
@@ -31,6 +31,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Console.h"
|
#include "Console.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
#include <future>
|
||||||
/*
|
/*
|
||||||
namespace input {
|
namespace input {
|
||||||
|
|
||||||
@@ -11100,6 +11101,46 @@ uint16_t TTrain::id() {
|
|||||||
return vid;
|
return vid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void train_table::updateAsync(double dt)
|
||||||
|
{
|
||||||
|
// init random engine
|
||||||
|
std::vector<std::pair<TTrain *, std::future<void>>> futures;
|
||||||
|
futures.reserve(m_items.size());
|
||||||
|
|
||||||
|
// update all trains in paallel
|
||||||
|
for (TTrain *train : m_items)
|
||||||
|
{
|
||||||
|
if (!train)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
futures.emplace_back(train, std::async(std::launch::async, [train, dt]() { train->Update(dt); }));
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait for every train to finish processing
|
||||||
|
for (auto &pair : futures)
|
||||||
|
{
|
||||||
|
pair.second.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// perform deletions
|
||||||
|
for (TTrain *train : m_items)
|
||||||
|
{
|
||||||
|
if (!train)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (train->pending_delete)
|
||||||
|
{
|
||||||
|
purge(train->Dynamic()->name());
|
||||||
|
if (simulation::Train == train)
|
||||||
|
simulation::Train = nullptr;
|
||||||
|
}
|
||||||
|
else if (simulation::Train != train && Global.network_servers.empty() && !Global.network_client)
|
||||||
|
{
|
||||||
|
purge(train->Dynamic()->name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void train_table::update(double dt)
|
void train_table::update(double dt)
|
||||||
{
|
{
|
||||||
for (TTrain *train : m_items) {
|
for (TTrain *train : m_items) {
|
||||||
|
|||||||
1
Train.h
1
Train.h
@@ -929,6 +929,7 @@ private:
|
|||||||
class train_table : public basic_table<TTrain> {
|
class train_table : public basic_table<TTrain> {
|
||||||
public:
|
public:
|
||||||
void update( double dt );
|
void update( double dt );
|
||||||
|
void updateAsync( double dt );
|
||||||
TTrain *find_id( std::uint16_t const Id ) const;
|
TTrain *find_id( std::uint16_t const Id ) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -497,7 +497,7 @@ eu07_application::run() {
|
|||||||
// send commands to command queue
|
// send commands to command queue
|
||||||
simulation::Commands.push_commands(commands_to_exec);
|
simulation::Commands.push_commands(commands_to_exec);
|
||||||
|
|
||||||
// do actual frame processing
|
// do actual frame processing (depending on mode)
|
||||||
if (!m_modes[ m_modestack.top() ]->update())
|
if (!m_modes[ m_modestack.top() ]->update())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|||||||
@@ -274,7 +274,16 @@ driver_mode::update() {
|
|||||||
else
|
else
|
||||||
TSubModel::iInstance = 0;
|
TSubModel::iInstance = 0;
|
||||||
|
|
||||||
simulation::Trains.update(deltatime);
|
|
||||||
|
if (Global.trainAsyncProcessing)
|
||||||
|
{
|
||||||
|
simulation::Trains.updateAsync(deltatime);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
simulation::Trains.update(deltatime);
|
||||||
|
}
|
||||||
|
|
||||||
simulation::Events.update();
|
simulation::Events.update();
|
||||||
simulation::Region->update_events();
|
simulation::Region->update_events();
|
||||||
simulation::Lights.update();
|
simulation::Lights.update();
|
||||||
|
|||||||
Reference in New Issue
Block a user