mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 16:19:19 +02:00
network improvements
This commit is contained in:
@@ -2838,7 +2838,7 @@ histerezę czasową, aby te tryby pracy nie przełączały się zbyt szybko.
|
|||||||
|
|
||||||
bool TDynamicObject::Update(double dt, double dt1)
|
bool TDynamicObject::Update(double dt, double dt1)
|
||||||
{
|
{
|
||||||
if (dt1 == 0)
|
if (dt1 == 0.0)
|
||||||
return true; // Ra: pauza
|
return true; // Ra: pauza
|
||||||
if (!MoverParameters->PhysicActivation &&
|
if (!MoverParameters->PhysicActivation &&
|
||||||
!MechInside) // to drugie, bo będąc w maszynowym blokuje się fizyka
|
!MechInside) // to drugie, bo będąc w maszynowym blokuje się fizyka
|
||||||
@@ -3302,7 +3302,7 @@ bool TDynamicObject::Update(double dt, double dt1)
|
|||||||
glm::dvec3 old_pos = vPosition;
|
glm::dvec3 old_pos = vPosition;
|
||||||
Move(dDOMoveLen);
|
Move(dDOMoveLen);
|
||||||
|
|
||||||
m_future_movement = (glm::dvec3(vPosition) - old_pos) / dt1 * Timer::GetDeltaTime();
|
m_future_movement = (glm::dvec3(vPosition) - old_pos) / dt1 * Timer::GetDeltaRenderTime();
|
||||||
|
|
||||||
if (!bEnabled) // usuwane pojazdy nie mają toru
|
if (!bEnabled) // usuwane pojazdy nie mają toru
|
||||||
{ // pojazd do usunięcia
|
{ // pojazd do usunięcia
|
||||||
@@ -3407,7 +3407,7 @@ bool TDynamicObject::Update(double dt, double dt1)
|
|||||||
dWheelAngle[2] += 114.59155902616464175359630962821 * MoverParameters->V * dt1 /
|
dWheelAngle[2] += 114.59155902616464175359630962821 * MoverParameters->V * dt1 /
|
||||||
MoverParameters->WheelDiameterT; // tylne toczne
|
MoverParameters->WheelDiameterT; // tylne toczne
|
||||||
|
|
||||||
m_future_wheels_angle = (glm::dvec3(dWheelAngle[0], dWheelAngle[1], dWheelAngle[2]) - old_wheels) / dt1 * Timer::GetDeltaTime();
|
m_future_wheels_angle = (glm::dvec3(dWheelAngle[0], dWheelAngle[1], dWheelAngle[2]) - old_wheels) / dt1 * Timer::GetDeltaRenderTime();
|
||||||
|
|
||||||
if (dWheelAngle[0] > 360.0)
|
if (dWheelAngle[0] > 360.0)
|
||||||
dWheelAngle[0] -= 360.0; // a w drugą stronę jak się kręcą?
|
dWheelAngle[0] -= 360.0; // a w drugą stronę jak się kręcą?
|
||||||
@@ -3898,7 +3898,7 @@ bool TDynamicObject::Update(double dt, double dt1)
|
|||||||
|
|
||||||
glm::dvec3 TDynamicObject::get_future_movement() const
|
glm::dvec3 TDynamicObject::get_future_movement() const
|
||||||
{
|
{
|
||||||
return m_future_movement;
|
return m_future_movement;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TDynamicObject::FastUpdate(double dt)
|
bool TDynamicObject::FastUpdate(double dt)
|
||||||
|
|||||||
6
DynObj.h
6
DynObj.h
@@ -178,7 +178,7 @@ private: // położenie pojazdu w świecie oraz parametry ruchu
|
|||||||
Math3D::vector3 modelRot; // obrot pudła względem świata - do przeanalizowania, czy potrzebne!!!
|
Math3D::vector3 modelRot; // obrot pudła względem świata - do przeanalizowania, czy potrzebne!!!
|
||||||
TDynamicObject * ABuFindNearestObject(glm::vec3 pos, TTrack *Track, TDynamicObject *MyPointer, int &CouplNr );
|
TDynamicObject * ABuFindNearestObject(glm::vec3 pos, TTrack *Track, TDynamicObject *MyPointer, int &CouplNr );
|
||||||
|
|
||||||
glm::dvec3 m_future_movement;
|
glm::dvec3 m_future_movement;
|
||||||
glm::dvec3 m_future_wheels_angle;
|
glm::dvec3 m_future_wheels_angle;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -640,7 +640,7 @@ private:
|
|||||||
int RouteWish(TTrack *tr);
|
int RouteWish(TTrack *tr);
|
||||||
void DestinationSet(std::string to, std::string numer);
|
void DestinationSet(std::string to, std::string numer);
|
||||||
void OverheadTrack(float o);
|
void OverheadTrack(float o);
|
||||||
glm::dvec3 get_future_movement() const;
|
glm::dvec3 get_future_movement() const;
|
||||||
|
|
||||||
double MED[9][8]; // lista zmiennych do debugowania hamulca ED
|
double MED[9][8]; // lista zmiennych do debugowania hamulca ED
|
||||||
static std::string const MED_labels[ 8 ];
|
static std::string const MED_labels[ 8 ];
|
||||||
@@ -682,7 +682,7 @@ public:
|
|||||||
Math3D::vector3 offset {}; // overall shake-driven offset from base position
|
Math3D::vector3 offset {}; // overall shake-driven offset from base position
|
||||||
} ShakeState;
|
} ShakeState;
|
||||||
|
|
||||||
Math3D::vector3 modelShake;
|
Math3D::vector3 modelShake;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ eu07_application::run() {
|
|||||||
if (m_network && m_network->client)
|
if (m_network && m_network->client)
|
||||||
{
|
{
|
||||||
// fetch frame info from network layer,
|
// fetch frame info from network layer,
|
||||||
auto frame_info = m_network->client->get_next_delta();
|
auto frame_info = m_network->client->get_next_delta(MAX_NETWORK_PER_FRAME - loop_remaining);
|
||||||
|
|
||||||
// use delta and commands received from master
|
// use delta and commands received from master
|
||||||
double delta = std::get<0>(frame_info);
|
double delta = std::get<0>(frame_info);
|
||||||
@@ -234,7 +234,8 @@ eu07_application::run() {
|
|||||||
{
|
{
|
||||||
// send delta, sync, and commands we just executed to clients
|
// send delta, sync, and commands we just executed to clients
|
||||||
double delta = Timer::GetDeltaTime();
|
double delta = Timer::GetDeltaTime();
|
||||||
m_network->servers->push_delta(delta, sync, commands_to_exec);
|
double render = Timer::GetDeltaRenderTime();
|
||||||
|
m_network->servers->push_delta(render, delta, sync, commands_to_exec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we're slave
|
// if we're slave
|
||||||
|
|||||||
@@ -16,12 +16,13 @@ command_queue::commands_map network::server_manager::pop_commands()
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
void network::server_manager::push_delta(double dt, double sync, const command_queue::commands_map &commands)
|
void network::server_manager::push_delta(double render_dt, double dt, double sync, const command_queue::commands_map &commands)
|
||||||
{
|
{
|
||||||
if (dt == 0.0 && commands.empty())
|
if (dt == 0.0 && commands.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
frame_info msg;
|
frame_info msg;
|
||||||
|
msg.render_dt = render_dt;
|
||||||
msg.dt = dt;
|
msg.dt = dt;
|
||||||
msg.sync = sync;
|
msg.sync = sync;
|
||||||
msg.commands = commands;
|
msg.commands = commands;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace network
|
|||||||
public:
|
public:
|
||||||
server_manager();
|
server_manager();
|
||||||
|
|
||||||
void push_delta(double dt, double sync, const command_queue::commands_map &commands);
|
void push_delta(double render_dt, double dt, double sync, const command_queue::commands_map &commands);
|
||||||
command_queue::commands_map pop_commands();
|
command_queue::commands_map pop_commands();
|
||||||
void create_server(const std::string &backend, const std::string &conf);
|
void create_server(const std::string &backend, const std::string &conf);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ void network::request_command::deserialize(std::istream &stream)
|
|||||||
|
|
||||||
void network::frame_info::serialize(std::ostream &stream) const
|
void network::frame_info::serialize(std::ostream &stream) const
|
||||||
{
|
{
|
||||||
|
sn_utils::ls_float64(stream, render_dt);
|
||||||
sn_utils::ls_float64(stream, dt);
|
sn_utils::ls_float64(stream, dt);
|
||||||
sn_utils::ls_float64(stream, sync);
|
sn_utils::ls_float64(stream, sync);
|
||||||
|
|
||||||
@@ -82,6 +83,7 @@ void network::frame_info::serialize(std::ostream &stream) const
|
|||||||
|
|
||||||
void network::frame_info::deserialize(std::istream &stream)
|
void network::frame_info::deserialize(std::istream &stream)
|
||||||
{
|
{
|
||||||
|
render_dt = sn_utils::ld_float64(stream);
|
||||||
dt = sn_utils::ld_float64(stream);
|
dt = sn_utils::ld_float64(stream);
|
||||||
sync = sn_utils::ld_float64(stream);
|
sync = sn_utils::ld_float64(stream);
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ struct frame_info : public request_command
|
|||||||
{
|
{
|
||||||
frame_info() : request_command(FRAME_INFO) {}
|
frame_info() : request_command(FRAME_INFO) {}
|
||||||
|
|
||||||
|
double render_dt;
|
||||||
double dt;
|
double dt;
|
||||||
double sync;
|
double sync;
|
||||||
|
|
||||||
|
|||||||
@@ -74,37 +74,7 @@ void network::connection::send_complete(std::shared_ptr<std::string> buf)
|
|||||||
|
|
||||||
// --------------
|
// --------------
|
||||||
|
|
||||||
/*
|
|
||||||
std::tuple<double, double, command_queue::commands_map> network::connection::get_next_delta()
|
|
||||||
{
|
|
||||||
if (delta_queue.empty()) {
|
|
||||||
return std::tuple<double, double,
|
|
||||||
command_queue::commands_map>(0.0, 0.0, command_queue::commands_map());
|
|
||||||
}
|
|
||||||
|
|
||||||
///auto now = std::chrono::high_resolution_clock::now();
|
|
||||||
|
|
||||||
//double last_frame = std::chrono::duration_cast<std::chrono::seconds>(now - last_time).count();
|
|
||||||
//last_time = now;
|
|
||||||
//accum += last_frame;
|
|
||||||
|
|
||||||
auto entry = delta_queue.front();
|
|
||||||
|
|
||||||
//if (accum > remote_dt) {
|
|
||||||
//accum -= remote_dt;
|
|
||||||
|
|
||||||
delta_queue.pop();
|
|
||||||
return std::make_tuple(entry.second->dt, entry.second->sync, entry.second->commands);
|
|
||||||
//}
|
|
||||||
//else {
|
|
||||||
//return 0.0;
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// server
|
// server
|
||||||
|
|
||||||
network::server::server(std::shared_ptr<std::istream> buf) : backbuffer(buf)
|
network::server::server(std::shared_ptr<std::istream> buf) : backbuffer(buf)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -186,18 +156,49 @@ void network::client::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// client
|
// client
|
||||||
std::tuple<double, double, command_queue::commands_map> network::client::get_next_delta()
|
std::tuple<double, double, command_queue::commands_map> network::client::get_next_delta(int counter)
|
||||||
{
|
{
|
||||||
|
if (counter == 1) {
|
||||||
|
auto now = std::chrono::high_resolution_clock::now();
|
||||||
|
frame_time = now - last_frame;
|
||||||
|
last_frame = now;
|
||||||
|
}
|
||||||
|
|
||||||
if (delta_queue.empty()) {
|
if (delta_queue.empty()) {
|
||||||
|
// buffer underflow
|
||||||
return std::tuple<double, double,
|
return std::tuple<double, double,
|
||||||
command_queue::commands_map>(0.0, 0.0, command_queue::commands_map());
|
command_queue::commands_map>(0.0, 0.0, command_queue::commands_map());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto entry = delta_queue.front();
|
|
||||||
delta_queue.pop();
|
|
||||||
|
|
||||||
auto &delta = entry.second;
|
float size = delta_queue.size() - consume_counter;
|
||||||
return std::make_tuple(entry.second.dt, entry.second.sync, entry.second.commands);
|
auto entry = delta_queue.front();
|
||||||
|
float mult = entry.render_dt / std::chrono::duration_cast<std::chrono::duration<float>>(frame_time).count();
|
||||||
|
|
||||||
|
if (counter == 1 && size < MAX_BUFFER_SIZE * 2.0f) {
|
||||||
|
last_target = last_target * TARGET_MIX +
|
||||||
|
(std::min(TARGET_MIN + jitteriness * JITTERINESS_MULTIPIER, MAX_BUFFER_SIZE)) * (1.0f - TARGET_MIX);
|
||||||
|
float diff = size - last_target;
|
||||||
|
jitteriness = std::max(jitteriness * JITTERINESS_MIX, std::abs(diff));
|
||||||
|
|
||||||
|
float speed = 1.0f + diff * CONSUME_MULTIPIER;
|
||||||
|
|
||||||
|
consume_counter += speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size > MAX_BUFFER_SIZE || consume_counter > mult) {
|
||||||
|
if (consume_counter > mult) {
|
||||||
|
consume_counter = std::clamp(consume_counter - mult, -MAX_BUFFER_SIZE, MAX_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
delta_queue.pop();
|
||||||
|
|
||||||
|
return std::make_tuple(entry.dt, entry.sync, entry.commands);
|
||||||
|
} else {
|
||||||
|
// nothing to push
|
||||||
|
return std::tuple<double, double,
|
||||||
|
command_queue::commands_map>(0.0, 0.0, command_queue::commands_map());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void network::client::send_commands(command_queue::commands_map commands)
|
void network::client::send_commands(command_queue::commands_map commands)
|
||||||
@@ -240,8 +241,7 @@ void network::client::handle_message(std::shared_ptr<connection> conn, const mes
|
|||||||
resume_frame_counter++;
|
resume_frame_counter++;
|
||||||
|
|
||||||
auto delta = dynamic_cast<const frame_info&>(msg);
|
auto delta = dynamic_cast<const frame_info&>(msg);
|
||||||
auto now = std::chrono::high_resolution_clock::now();
|
delta_queue.push(delta);
|
||||||
delta_queue.push(std::make_pair(now, delta));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,17 +18,6 @@ namespace network
|
|||||||
private:
|
private:
|
||||||
const int CATCHUP_PACKETS = 300;
|
const int CATCHUP_PACKETS = 300;
|
||||||
|
|
||||||
/*
|
|
||||||
std::queue<
|
|
||||||
std::pair<std::chrono::high_resolution_clock::time_point,
|
|
||||||
std::shared_ptr<frame_info>>> delta_queue;
|
|
||||||
|
|
||||||
command_queue::commands_map client_commands_queue;
|
|
||||||
bool is_client;
|
|
||||||
|
|
||||||
//std::chrono::high_resolution_clock::time_point last_time;
|
|
||||||
//double accum = -1.0;
|
|
||||||
*/
|
|
||||||
bool is_client;
|
bool is_client;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -88,14 +77,25 @@ namespace network
|
|||||||
size_t reconnect_delay = 0;
|
size_t reconnect_delay = 0;
|
||||||
|
|
||||||
const size_t RECONNECT_DELAY_FRAMES = 60;
|
const size_t RECONNECT_DELAY_FRAMES = 60;
|
||||||
|
const float MAX_BUFFER_SIZE = 60.0f;
|
||||||
|
const float JITTERINESS_MIX = 0.998f;
|
||||||
|
const float TARGET_MIN = 2.0f;
|
||||||
|
const float TARGET_MIX = 0.98f;
|
||||||
|
const float JITTERINESS_MULTIPIER = 2.0f;
|
||||||
|
const float CONSUME_MULTIPIER = 0.05f;
|
||||||
|
|
||||||
std::queue<
|
std::queue<frame_info> delta_queue;
|
||||||
std::pair<std::chrono::high_resolution_clock::time_point,
|
|
||||||
frame_info>> delta_queue;
|
float last_target = 20.0f;
|
||||||
|
float jitteriness = 1.0f;
|
||||||
|
float consume_counter = 0.0f;
|
||||||
|
|
||||||
|
std::chrono::high_resolution_clock::time_point last_frame;
|
||||||
|
std::chrono::high_resolution_clock::duration frame_time;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void update();
|
void update();
|
||||||
std::tuple<double, double, command_queue::commands_map> get_next_delta();
|
std::tuple<double, double, command_queue::commands_map> get_next_delta(int counter);
|
||||||
void send_commands(command_queue::commands_map commands);
|
void send_commands(command_queue::commands_map commands);
|
||||||
int get_frame_counter() {
|
int get_frame_counter() {
|
||||||
return resume_frame_counter;
|
return resume_frame_counter;
|
||||||
|
|||||||
@@ -117,17 +117,15 @@ void state_manager::process_commands() {
|
|||||||
if (train)
|
if (train)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( ( true == DebugModeFlag )
|
train = new TTrain();
|
||||||
|| ( dynamic->MoverParameters->Vel <= 5.0 ) ) {
|
if (train->Init(dynamic)) {
|
||||||
train = new TTrain();
|
simulation::Trains.insert(train, dynamic->name());
|
||||||
if (train->Init(dynamic)) {
|
|
||||||
simulation::Trains.insert(train, dynamic->name());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
delete train;
|
|
||||||
train = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
delete train;
|
||||||
|
train = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commanddata.command == user_command::queueevent) {
|
if (commanddata.command == user_command::queueevent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user