mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
@@ -37,56 +37,36 @@ namespace BlackSimTest
|
||||
return 0;
|
||||
}
|
||||
|
||||
streamOut << "d .. direct, b .. background" << endl;
|
||||
streamOut << "start reading" << endl;
|
||||
QString input = streamIn.readLine();
|
||||
Q_UNUSED(input);
|
||||
|
||||
if (!input.startsWith("b"))
|
||||
{
|
||||
streamOut << "reading directly" << endl;
|
||||
QTime time;
|
||||
time.start();
|
||||
streamOut << "reading " << mapper.getAircraftCfgEntriesList().getRootDirectory() << endl;
|
||||
mapper.readSimObjects();
|
||||
streamOut << "read entries: " << mapper.getAircraftCfgEntriesList().size() << " in " << time.restart() << "ms" << endl;
|
||||
streamOut << "reading directly" << endl;
|
||||
QTime time;
|
||||
time.start();
|
||||
streamOut << "reading " << mapper.getAircraftCfgEntriesList().getRootDirectory() << endl;
|
||||
mapper.readSimObjects();
|
||||
streamOut << "read entries: " << mapper.getAircraftCfgEntriesList().size() << " in " << time.restart() << "ms" << endl;
|
||||
|
||||
CAircraftCfgEntriesList entriesList = mapper.getAircraftCfgEntriesList();
|
||||
QJsonDocument doc(entriesList.toJson());
|
||||
QByteArray jsonArray(doc.toJson());
|
||||
streamOut << "write JSON array with size " << jsonArray.size() << endl;
|
||||
QTemporaryFile tempFile;
|
||||
tempFile.open();
|
||||
tempFile.write(jsonArray);
|
||||
tempFile.close();
|
||||
streamOut << "written to " << tempFile.fileName() << " in " << time.restart() << "ms" << endl;
|
||||
CAircraftCfgEntriesList entriesList = mapper.getAircraftCfgEntriesList();
|
||||
QJsonDocument doc(entriesList.toJson());
|
||||
QByteArray jsonArray(doc.toJson());
|
||||
streamOut << "write JSON array with size " << jsonArray.size() << endl;
|
||||
QTemporaryFile tempFile;
|
||||
tempFile.open();
|
||||
tempFile.write(jsonArray);
|
||||
tempFile.close();
|
||||
streamOut << "written to " << tempFile.fileName() << " in " << time.restart() << "ms" << endl;
|
||||
|
||||
// re-read
|
||||
tempFile.open();
|
||||
jsonArray = tempFile.readAll();
|
||||
doc = QJsonDocument::fromJson(jsonArray);
|
||||
entriesList.clear();
|
||||
entriesList.convertFromJson(doc.object());
|
||||
streamOut << "read JSON array with size " << jsonArray.size() << endl;
|
||||
streamOut << "read entries from disk: " << entriesList.size() << " in " << time.restart() << "ms" << endl;
|
||||
tempFile.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
streamOut << "reading in background" << endl;
|
||||
QFuture<int> f = mapper.readInBackground();
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
if (i % 20 == 0)
|
||||
{
|
||||
streamOut << ".";
|
||||
streamOut.flush();
|
||||
}
|
||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000 * 5);
|
||||
}
|
||||
while (!f.isFinished());
|
||||
streamOut << endl << f.result() << " entries" << endl;
|
||||
}
|
||||
streamOut << "-----------------------------------------------" << endl;
|
||||
// re-read
|
||||
tempFile.open();
|
||||
jsonArray = tempFile.readAll();
|
||||
doc = QJsonDocument::fromJson(jsonArray);
|
||||
entriesList.clear();
|
||||
entriesList.convertFromJson(doc.object());
|
||||
streamOut << "read JSON array with size " << jsonArray.size() << endl;
|
||||
streamOut << "read entries from disk: " << entriesList.size() << " in " << time.restart() << "ms" << endl;
|
||||
tempFile.close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -224,11 +224,11 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
template <typename ObjectType, typename ContainerType>
|
||||
BlackMisc::CWorker *CListModelBase<ObjectType, ContainerType>::updateAsync(const ContainerType &container, bool sort)
|
||||
CWorker *CListModelBase<ObjectType, ContainerType>::updateAsync(const ContainerType &container, bool sort)
|
||||
{
|
||||
auto sortColumn = this->getSortColumn();
|
||||
auto sortOrder = this->getSortOrder();
|
||||
BlackMisc::CWorker *worker = BlackMisc::CWorker::fromTask(this, "ModelSort", [this, container, sort, sortColumn, sortOrder]()
|
||||
CWorker *worker = BlackMisc::CWorker::fromTask(this, "ModelSort", [this, container, sort, sortColumn, sortOrder]()
|
||||
{
|
||||
ContainerType sortedContainer = this->sortContainerByColumn(container, sortColumn, sortOrder);
|
||||
QMetaObject::invokeMethod(this, "ps_updateContainer",
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "aircraftmapper.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/worker.h"
|
||||
#include <utility>
|
||||
|
||||
using namespace BlackMisc;
|
||||
@@ -45,27 +46,13 @@ namespace BlackSim
|
||||
return n;
|
||||
}
|
||||
|
||||
QFuture<int> &CAircraftMapper::readInBackground(const QString &simObjectDir)
|
||||
void CAircraftMapper::initCompletelyInBackground(const QString &simObjectDir)
|
||||
{
|
||||
if (!isRunningInBackground())
|
||||
if (this->m_initWorker) { return; }
|
||||
this->m_initWorker = BlackMisc::CWorker::fromTask(this, "CAircraftMapper::initCompletely", [this, simObjectDir]()
|
||||
{
|
||||
this->m_backgroundRead = QtConcurrent::run(this, &CAircraftMapper::readSimObjects, simObjectDir);
|
||||
}
|
||||
return this->m_backgroundRead;
|
||||
}
|
||||
|
||||
QFuture<bool> &CAircraftMapper::initCompletelyInBackground(const QString &simObjectDir)
|
||||
{
|
||||
if (!isRunningInBackground())
|
||||
{
|
||||
this->m_backgroundInit = QtConcurrent::run(this, &CAircraftMapper::initCompletely, simObjectDir);
|
||||
}
|
||||
return this->m_backgroundInit;
|
||||
}
|
||||
|
||||
bool CAircraftMapper::isRunningInBackground() const
|
||||
{
|
||||
return this->m_backgroundInit.isRunning() || this->m_backgroundRead.isRunning();
|
||||
this->initCompletely(simObjectDir);
|
||||
});
|
||||
}
|
||||
|
||||
bool CAircraftMapper::isInitialized() const
|
||||
@@ -106,13 +93,9 @@ namespace BlackSim
|
||||
void CAircraftMapper::gracefulShutdown()
|
||||
{
|
||||
// when running, force re-init
|
||||
if (isRunningInBackground())
|
||||
{
|
||||
m_init = false;
|
||||
this->m_entries.cancelRead();
|
||||
this->m_backgroundInit.cancel();
|
||||
this->m_backgroundRead.cancel();
|
||||
}
|
||||
this->m_entries.cancelRead();
|
||||
this->m_initInProgress = false;
|
||||
this->m_init = false;
|
||||
}
|
||||
|
||||
const CAircraftModel &CAircraftMapper::getDefaultModel()
|
||||
@@ -129,10 +112,13 @@ namespace BlackSim
|
||||
bool CAircraftMapper::initCompletely(QString simObjectDir)
|
||||
{
|
||||
if (this->m_init) { return true; }
|
||||
if (this->m_initInProgress) { return false; }
|
||||
this->m_initInProgress = true;
|
||||
if (!this->m_mappings)
|
||||
{
|
||||
CLogMessage(this).error("Missing mapping defintions");
|
||||
emit initCompleted(false);
|
||||
this->m_initInProgress = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -140,6 +126,7 @@ namespace BlackSim
|
||||
{
|
||||
CLogMessage(this).error("Mapping engine, cannot read Flight Simulator directory: %1") << simObjectDir;
|
||||
emit initCompleted(false);
|
||||
this->m_initInProgress = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -153,6 +140,7 @@ namespace BlackSim
|
||||
{
|
||||
CLogMessage(this).error("Reading mapping rules failed or empty");
|
||||
emit initCompleted(false);
|
||||
this->m_initInProgress = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -167,6 +155,7 @@ namespace BlackSim
|
||||
{
|
||||
CLogMessage(this).error("No SimObjects found in %1") << simObjectDir;
|
||||
emit initCompleted(false);
|
||||
this->m_initInProgress = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -180,6 +169,7 @@ namespace BlackSim
|
||||
// finish
|
||||
CLogMessage(this).info("Mapping system: %1 definitions for %2 entries") << this->m_mappings->size() << this->m_entries.size();
|
||||
emit initCompleted(true);
|
||||
this->m_initInProgress = false;
|
||||
this->m_init = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "aircraftcfgentrieslist.h"
|
||||
#include "../simulatormodelmappings.h"
|
||||
#include "blackmisc/worker.h"
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
#include <QFuture>
|
||||
@@ -61,14 +62,8 @@ namespace BlackSim
|
||||
//! Read for directory or re-read
|
||||
int readSimObjects(const QString &simObjectDir = "");
|
||||
|
||||
//! Read in background
|
||||
QFuture<int> &readInBackground(const QString &simObjectDir = "");
|
||||
|
||||
//! Init in background
|
||||
QFuture<bool> &initCompletelyInBackground(const QString &simObjectDir = "");
|
||||
|
||||
//! Running in background
|
||||
bool isRunningInBackground() const;
|
||||
void initCompletelyInBackground(const QString &simObjectDir = "");
|
||||
|
||||
//! Init completed?
|
||||
bool isInitialized() const;
|
||||
@@ -110,10 +105,9 @@ namespace BlackSim
|
||||
private:
|
||||
QScopedPointer<BlackSim::ISimulatorModelMappings> m_mappings; //!< all mapping definitions
|
||||
CAircraftCfgEntriesList m_entries; //!< all entries
|
||||
QFuture<bool> m_backgroundInit;
|
||||
QFuture<int> m_backgroundRead;
|
||||
bool m_init = false;
|
||||
|
||||
bool m_init = false;
|
||||
bool m_initInProgress = false;
|
||||
BlackMisc::CWorker *m_initWorker = nullptr;
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user