mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 10:15:38 +08:00
Add local implementation for IContextSimulator
This class implements the local BlackCore object for the simulator context. It initializes its member variables with default values. refs #135
This commit is contained in:
67
src/blackcore/context_simulator_impl.cpp
Normal file
67
src/blackcore/context_simulator_impl.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "context_simulator_impl.h"
|
||||
#include "coreruntime.h"
|
||||
#include "fsx/simulator_fsx.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Geo;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
// Init this context
|
||||
CContextSimulator::CContextSimulator(QObject *parent) :
|
||||
IContextSimulator(parent),
|
||||
m_simulator(new BlackCore::FSX::CSimulatorFSX(this)),
|
||||
m_updateTimer(nullptr),
|
||||
m_contextNetwork(nullptr)
|
||||
|
||||
{
|
||||
m_updateTimer = new QTimer(this);
|
||||
connect(m_simulator, &ISimulator::connectionChanged, this, &CContextSimulator::setConnectionStatus);
|
||||
connect(m_updateTimer, &QTimer::timeout, this, &CContextSimulator::updateOwnAircraft);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
CContextSimulator::~CContextSimulator()
|
||||
{
|
||||
}
|
||||
|
||||
bool CContextSimulator::isConnected() const
|
||||
{
|
||||
return m_simulator->isConnected();
|
||||
}
|
||||
|
||||
BlackMisc::Aviation::CAircraft CContextSimulator::ownAircraft() const
|
||||
{
|
||||
return m_ownAircraft;
|
||||
}
|
||||
|
||||
void CContextSimulator::updateOwnAircraft()
|
||||
{
|
||||
m_ownAircraft = m_simulator->getOwnAircraft();
|
||||
|
||||
if (!m_contextNetwork)
|
||||
{
|
||||
m_contextNetwork = getRuntime()->getIContextNetwork();
|
||||
}
|
||||
|
||||
m_contextNetwork->updateOwnSituation(m_ownAircraft.getSituation());
|
||||
m_contextNetwork->updateOwnCockpit(m_ownAircraft.getCom1System(), m_ownAircraft.getCom2System(), m_ownAircraft.getTransponder());
|
||||
}
|
||||
|
||||
void CContextSimulator::setConnectionStatus(bool value)
|
||||
{
|
||||
if (value)
|
||||
m_updateTimer->start(100);
|
||||
else
|
||||
m_updateTimer->stop();
|
||||
emit connectionChanged(value);
|
||||
}
|
||||
|
||||
} // namespace BlackCore
|
||||
91
src/blackcore/context_simulator_impl.h
Normal file
91
src/blackcore/context_simulator_impl.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef BLACKCORE_CONTEXTSIMULATOR_IMPL_H
|
||||
#define BLACKCORE_CONTEXTSIMULATOR_IMPL_H
|
||||
|
||||
#include "blackcore/context_simulator.h"
|
||||
#include "blackcore/context_network_interface.h"
|
||||
#include "blackcore/simulator.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
/*!
|
||||
* \brief Network simulator concrete implementation
|
||||
*/
|
||||
class CContextSimulator : public IContextSimulator
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTSIMULATOR_INTERFACENAME)
|
||||
|
||||
public:
|
||||
//! \brief Constructor
|
||||
CContextSimulator(QObject *parent = nullptr);
|
||||
|
||||
//! \brief Destructor
|
||||
virtual ~CContextSimulator();
|
||||
|
||||
/*!
|
||||
* \brief Register myself in DBus
|
||||
* \param server
|
||||
*/
|
||||
void registerWithDBus(CDBusServer *server)
|
||||
{
|
||||
Q_ASSERT(server);
|
||||
server->addObject(CContextSimulator::ObjectPath(), this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Runtime
|
||||
* \return
|
||||
*/
|
||||
const CCoreRuntime *getRuntime() const
|
||||
{
|
||||
return static_cast<CCoreRuntime *>(this->parent());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Runtime
|
||||
* \return
|
||||
*/
|
||||
CCoreRuntime *getRuntime()
|
||||
{
|
||||
return static_cast<CCoreRuntime *>(this->parent());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Using local objects?
|
||||
* \return
|
||||
*/
|
||||
virtual bool usingLocalObjects() const override { return true; }
|
||||
|
||||
virtual BlackMisc::Aviation::CAircraft ownAircraft() const override;
|
||||
|
||||
public slots:
|
||||
|
||||
virtual bool isConnected() const override;
|
||||
|
||||
private slots:
|
||||
virtual void updateOwnAircraft();
|
||||
|
||||
/*!
|
||||
* \brief Set new connection status
|
||||
* \param value
|
||||
*/
|
||||
void setConnectionStatus(bool value);
|
||||
|
||||
private:
|
||||
BlackMisc::Aviation::CAircraft m_ownAircraft;
|
||||
BlackCore::ISimulator *m_simulator;
|
||||
|
||||
QTimer *m_updateTimer;
|
||||
BlackCore::IContextNetwork *m_contextNetwork;
|
||||
};
|
||||
|
||||
} // namespace BlackCore
|
||||
|
||||
#endif // BLACKCORE_CONTEXTSIMULATOR_IMPL_H
|
||||
Reference in New Issue
Block a user