mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
refs #891, moved common parts for FSX/P3D to fsxcommon
* driver / listener common parts * config common parts
This commit is contained in:
committed by
Mathew Sutcliffe
parent
347b54171b
commit
70045c046d
108
src/plugins/simulator/fsxcommon/simconnectobject.cpp
Normal file
108
src/plugins/simulator/fsxcommon/simconnectobject.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "simconnectobject.h"
|
||||
#include "blackmisc/simulation/interpolatorlinear.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackSimPlugin
|
||||
{
|
||||
namespace FsxCommon
|
||||
{
|
||||
CSimConnectObject::CSimConnectObject()
|
||||
{ }
|
||||
|
||||
CSimConnectObject::CSimConnectObject(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, DWORD requestId,
|
||||
BlackMisc::Simulation::CInterpolationLogger *logger) :
|
||||
m_aircraft(aircraft), m_requestId(requestId), m_validRequestId(true),
|
||||
m_interpolator(QSharedPointer<BlackMisc::Simulation::CInterpolatorLinear>::create(aircraft.getCallsign()))
|
||||
{
|
||||
m_interpolator->attachLogger(logger);
|
||||
}
|
||||
|
||||
bool CSimConnectObject::isPendingAdded() const
|
||||
{
|
||||
return !this->hasValidRequestAndObjectId() || !this->m_confirmedAdded;
|
||||
}
|
||||
|
||||
bool CSimConnectObject::isConfirmedAdded() const
|
||||
{
|
||||
Q_ASSERT_X(!m_confirmedAdded || this->hasValidRequestAndObjectId(), Q_FUNC_INFO, "confirmed but invalid ids");
|
||||
return m_confirmedAdded;
|
||||
}
|
||||
|
||||
void CSimConnectObject::setConfirmedAdded(bool confirm)
|
||||
{
|
||||
m_confirmedAdded = confirm;
|
||||
m_aircraft.setRendered(true);
|
||||
}
|
||||
|
||||
void CSimConnectObject::setPendingRemoved(bool pending)
|
||||
{
|
||||
m_pendingRemoved = pending;
|
||||
m_aircraft.setRendered(false);
|
||||
}
|
||||
|
||||
bool CSimConnectObject::hasValidRequestAndObjectId() const
|
||||
{
|
||||
return this->hasValidRequestId() && this->hasValidObjectId();
|
||||
}
|
||||
|
||||
bool CSimConnectObjects::setSimConnectObjectIdForRequestId(DWORD requestId, DWORD objectId)
|
||||
{
|
||||
// First check, if this request id belongs to us
|
||||
auto it = std::find_if(this->begin(), this->end(), [requestId](const CSimConnectObject & obj) { return obj.getRequestId() == requestId; });
|
||||
if (it == this->end()) { return false; }
|
||||
|
||||
// belongs to us
|
||||
it->setObjectId(objectId);
|
||||
return true;
|
||||
}
|
||||
|
||||
CCallsign CSimConnectObjects::getCallsignForObjectId(DWORD objectId) const
|
||||
{
|
||||
return getSimObjectForObjectId(objectId).getCallsign();
|
||||
}
|
||||
|
||||
CSimConnectObject CSimConnectObjects::getSimObjectForObjectId(DWORD objectId) const
|
||||
{
|
||||
for (const CSimConnectObject &simObject : this->values())
|
||||
{
|
||||
if (simObject.getObjectId() == objectId) { return simObject; }
|
||||
}
|
||||
return CSimConnectObject();
|
||||
}
|
||||
|
||||
CSimConnectObject CSimConnectObjects::getSimObjectForRequestId(DWORD requestId) const
|
||||
{
|
||||
for (const CSimConnectObject &simObject : this->values())
|
||||
{
|
||||
if (simObject.getRequestId() == requestId) { return simObject; }
|
||||
}
|
||||
return CSimConnectObject();
|
||||
}
|
||||
|
||||
bool CSimConnectObjects::isKnownSimObjectId(DWORD objectId) const
|
||||
{
|
||||
const CSimConnectObject simObject(getSimObjectForObjectId(objectId));
|
||||
return simObject.hasValidRequestAndObjectId() && objectId == simObject.getObjectId();
|
||||
}
|
||||
|
||||
bool CSimConnectObjects::containsPendingAdd() const
|
||||
{
|
||||
for (const CSimConnectObject &simObject : this->values())
|
||||
{
|
||||
if (simObject.isPendingAdded()) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user