Skip to content

Commit

Permalink
Предварительно: поправлен рассинхрон по реалтайму
Browse files Browse the repository at this point in the history
  • Loading branch information
maisvendoo committed Oct 2, 2019
1 parent fcf0711 commit a2838e0
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cfg/init-data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<ProfileStep>100</ProfileStep>
<Direction>1</Direction>
<TrainConfig>default</TrainConfig>
<IntegrationTimeInterval>10</IntegrationTimeInterval>
<IntegrationTimeInterval>20</IntegrationTimeInterval>
<DebugPrint>true</DebugPrint>

<!-- Интервал опроса кнопок, мс -->
<ControlTimeInterval>10</ControlTimeInterval>
<ControlTimeInterval>20</ControlTimeInterval>

<!-- Объем буфера клавиатуры, байт -->
<KeysBufferSize>10240</KeysBufferSize>
Expand Down
51 changes: 51 additions & 0 deletions scripts/patch-deploy.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
rem Создаем структуру каталогов игры

mkdir %RRS_DEV_ROOT%
mkdir %RRS_DEV_ROOT%\bin
mkdir %RRS_DEV_ROOT%\lib
mkdir %RRS_DEV_ROOT%\modules
mkdir %RRS_DEV_ROOT%\plugins

mkdir %RRS_DEV_ROOT%\cfg
mkdir %RRS_DEV_ROOT%\data
mkdir %RRS_DEV_ROOT%\routes
mkdir %RRS_DEV_ROOT%\fonts
mkdir %RRS_DEV_ROOT%\themes

mkdir %RRS_DEV_ROOT%\sdk
mkdir %RRS_DEV_ROOT%\sdk\include

rem Копируем бинарные файлы

xcopy ..\..\bin\*.exe %RRS_DEV_ROOT%\bin\
xcopy ..\..\lib\*.dll %RRS_DEV_ROOT%\bin\
move %RRS_DEV_ROOT%\bin\rkf5.dll %RRS_DEV_ROOT%\lib\rkf5.dll
move %RRS_DEV_ROOT%\bin\rk4.dll %RRS_DEV_ROOT%\lib\rk4.dll

xcopy ..\..\modules\*.dll %RRS_DEV_ROOT%\modules
xcopy ..\..\modules\vl60\*.dll %RRS_DEV_ROOT%\modules\vl60\
xcopy ..\..\modules\passcar\*.dll %RRS_DEV_ROOT%\modules\passcar\

xcopy ..\..\plugins\*.dll %RRS_DEV_ROOT%\plugins

rem Копируем конфиги

xcopy ..\cfg\*.xml %RRS_DEV_ROOT%\cfg\
del %RRS_DEV_ROOT%\cfg\control-panel.xml
xcopy ..\cfg\couplings\*.xml %RRS_DEV_ROOT%\cfg\couplings\
xcopy ..\cfg\devices\*.xml %RRS_DEV_ROOT%\cfg\devices\

xcopy ..\cfg\main-resist\default.xml %RRS_DEV_ROOT%\cfg\main-resist\
xcopy ..\cfg\main-resist\passcar.xml %RRS_DEV_ROOT%\cfg\main-resist\
xcopy ..\cfg\main-resist\loco-resist.xml %RRS_DEV_ROOT%\cfg\main-resist\

xcopy ..\cfg\vehicles\vl60pk-1543\*.* %RRS_DEV_ROOT%\cfg\vehicles\vl60pk-1543\
xcopy ..\cfg\vehicles\IMR_pass_rzd-11100\*.* %RRS_DEV_ROOT%\cfg\vehicles\IMR_pass_rzd-11100\
xcopy ..\cfg\vehicles\IMR_pass_rzd-13819\*.* %RRS_DEV_ROOT%\cfg\vehicles\IMR_pass_rzd-13819\
xcopy ..\cfg\vehicles\IMR_pass_rzd-16733\*.* %RRS_DEV_ROOT%\cfg\vehicles\IMR_pass_rzd-16733\
xcopy ..\cfg\vehicles\IMR_pass_rzd-17669\*.* %RRS_DEV_ROOT%\cfg\vehicles\IMR_pass_rzd-17669\
xcopy ..\cfg\vehicles\IMR_pass_rzd-25924\*.* %RRS_DEV_ROOT%\cfg\vehicles\IMR_pass_rzd-25924\

xcopy ..\cfg\trains\vl60pk-1543.xml %RRS_DEV_ROOT%\cfg\trains\
xcopy ..\cfg\trains\vl60pk-1543-pass-train.xml %RRS_DEV_ROOT%\cfg\trains\

37 changes: 37 additions & 0 deletions simulator/model/include/elapsed-timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef ELAPSED_TIMER_H
#define ELAPSED_TIMER_H

#include <QThread>

class ElapsedTimer : public QObject
{
Q_OBJECT

public:

ElapsedTimer(QObject *parent = Q_NULLPTR);

~ElapsedTimer();

void setInterval(quint64 interval);

void start();

signals:

void process();

private:

bool is_started;

quint64 interval;

QThread thread;

private slots:

void loop();
};

#endif // ELAPSED_TIMER_H
9 changes: 8 additions & 1 deletion simulator/model/include/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "filesystem.h"
#include "log.h"
#include "train.h"
#include "elapsed-timer.h"

#include "server.h"

Expand Down Expand Up @@ -132,6 +133,8 @@ public slots:

QTimer controlTimer;

ElapsedTimer simTimer;

/// Log initialization
void logInit(bool clear_log = false);

Expand Down Expand Up @@ -164,7 +167,11 @@ public slots:

void controlStep(double &control_time, const double control_delay);

void timerEvent(QTimerEvent *event);
//void timerEvent(QTimerEvent *event);

private slots:

void process();
};

#endif // MODEL_H
44 changes: 44 additions & 0 deletions simulator/model/src/elapsed-timer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "elapsed-timer.h"

#include <QElapsedTimer>
#include <QTimer>
#include <QEventLoop>

ElapsedTimer::ElapsedTimer(QObject *parent) : QObject(parent)
, is_started(false)
, interval(0)
{

}

ElapsedTimer::~ElapsedTimer()
{

}

void ElapsedTimer::setInterval(quint64 interval)
{
this->interval = interval;
}

void ElapsedTimer::start()
{
is_started = true;
connect(&thread, &QThread::started, this, &ElapsedTimer::loop);
thread.start();
}

void ElapsedTimer::loop()
{
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &ElapsedTimer::process, Qt::DirectConnection);
timer->setTimerType(Qt::PreciseTimer);
timer->start(static_cast<int>(interval));

QEventLoop eventLoop;

while (is_started)
{
eventLoop.processEvents();
}
}
17 changes: 9 additions & 8 deletions simulator/model/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ void Model::start()
{
is_simulation_started = true;
t = start_time;
this->startTimer(integration_time_interval, Qt::TimerType::PreciseTimer);

connect(&simTimer, &ElapsedTimer::process, this, &Model::process, Qt::DirectConnection);
simTimer.setInterval(static_cast<quint64>(integration_time_interval));
simTimer.start();
}
}

Expand Down Expand Up @@ -500,15 +503,13 @@ void Model::controlStep(double &control_time, const double control_delay)
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void Model::timerEvent(QTimerEvent *event)
void Model::process()
{
Q_UNUSED(event)

// Feedback to viewer
sharedMemoryFeedback();
//sharedMemoryFeedback();

double tau = 0;
double integration_time = static_cast<double>(integration_time_interval) / 1000.0;
double integration_time = static_cast<double>(integration_time_interval) / 1000.0;

// Integrate all ODE in train motion model
while ( (tau <= integration_time) &&
Expand All @@ -517,7 +518,7 @@ void Model::timerEvent(QTimerEvent *event)
preStep(t);

// Feedback to viewer
//sharedMemoryFeedback();
sharedMemoryFeedback();

controlStep(control_time, control_delay);

Expand All @@ -534,6 +535,6 @@ void Model::timerEvent(QTimerEvent *event)

// Debug print, is allowed
if (is_debug_print)
debugPrint();
debugPrint();
}

0 comments on commit a2838e0

Please sign in to comment.