mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 08:45:36 +08:00
XPMPCreatePlaneWithModelName adds plane with a defined model name
It bypasses the internal model matching of libxplanemp and lets external applications do the model matching themselves.
This commit is contained in:
committed by
Mathew Sutcliffe
parent
6688a87ece
commit
b0530aa567
@@ -379,6 +379,14 @@ void XPMPGetModelInfo(int inIndex, const char **outModelName, const char **outIc
|
|||||||
XPMPPlaneData_f inDataFunc,
|
XPMPPlaneData_f inDataFunc,
|
||||||
void * inRefcon);
|
void * inRefcon);
|
||||||
|
|
||||||
|
XPMPPlaneID XPMPCreatePlaneWithModelName(
|
||||||
|
const char * inModelName,
|
||||||
|
const char * inICAOCode,
|
||||||
|
const char * inAirline,
|
||||||
|
const char * inLivery,
|
||||||
|
XPMPPlaneData_f inDataFunc,
|
||||||
|
void * inRefcon);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XPMPDestroyPlane
|
* XPMPDestroyPlane
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include "XPMPMultiplayerCSL.h"
|
#include "XPMPMultiplayerCSL.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -345,7 +346,50 @@ XPMPPlaneID XPMPCreatePlane(
|
|||||||
iter->first.first(plane, xpmp_PlaneNotification_Created, iter->first.second);
|
iter->first.first(plane, xpmp_PlaneNotification_Created, iter->first.second);
|
||||||
}
|
}
|
||||||
return plane;
|
return plane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CompareCaseInsensitive(string strFirst, string strSecond)
|
||||||
|
{
|
||||||
|
// Convert both strings to upper case by transfrom() before compare.
|
||||||
|
transform(strFirst.begin(), strFirst.end(), strFirst.begin(), static_cast<int (*)(int)>(std::toupper));
|
||||||
|
transform(strSecond.begin(), strSecond.end(), strSecond.begin(), static_cast<int (*)(int)>(std::toupper));
|
||||||
|
return strFirst == strSecond;
|
||||||
|
}
|
||||||
|
|
||||||
|
XPMPPlaneID XPMPCreatePlaneWithModelName(const char *inModelName, const char *inICAOCode, const char *inAirline, const char *inLivery, XPMPPlaneData_f inDataFunc, void *inRefcon)
|
||||||
|
{
|
||||||
|
XPMPPlanePtr plane = new XPMPPlane_t;
|
||||||
|
plane->icao = inICAOCode;
|
||||||
|
plane->livery = inLivery;
|
||||||
|
plane->airline = inAirline;
|
||||||
|
plane->dataFunc = inDataFunc;
|
||||||
|
plane->ref = inRefcon;
|
||||||
|
|
||||||
|
// Find the model
|
||||||
|
for (auto &package : gPackages)
|
||||||
|
{
|
||||||
|
auto cslPlane = std::find_if(package.planes.begin(), package.planes.end(), [inModelName](CSLPlane_t p) { return CompareCaseInsensitive(p.modelName, inModelName); });
|
||||||
|
if (cslPlane != package.planes.end())
|
||||||
|
{
|
||||||
|
plane->model = &(*cslPlane);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!plane->model) return nullptr;
|
||||||
|
|
||||||
|
plane->pos.size = sizeof(plane->pos);
|
||||||
|
plane->surface.size = sizeof(plane->surface);
|
||||||
|
plane->radar.size = sizeof(plane->radar);
|
||||||
|
plane->posAge = plane->radarAge = plane->surfaceAge = -1;
|
||||||
|
|
||||||
|
gPlanes.push_back(plane);
|
||||||
|
|
||||||
|
for (XPMPPlaneNotifierVector::iterator iter = gObservers.begin(); iter !=
|
||||||
|
gObservers.end(); ++iter)
|
||||||
|
{
|
||||||
|
iter->first.first(plane, xpmp_PlaneNotification_Created, iter->first.second);
|
||||||
|
}
|
||||||
|
return plane;
|
||||||
|
}
|
||||||
|
|
||||||
void XPMPDestroyPlane(XPMPPlaneID inID)
|
void XPMPDestroyPlane(XPMPPlaneID inID)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -154,12 +154,12 @@ struct XPMPPlane_t {
|
|||||||
string icao;
|
string icao;
|
||||||
string airline;
|
string airline;
|
||||||
string livery;
|
string livery;
|
||||||
CSLPlane_t * model; // May be null if no good match
|
CSLPlane_t * model = nullptr; // May be null if no good match
|
||||||
bool good_livery; // is our paint correctly matched?
|
bool good_livery; // is our paint correctly matched?
|
||||||
|
|
||||||
// This callback is used to pull data from the client for posiitons, etc.
|
// This callback is used to pull data from the client for posiitons, etc.
|
||||||
XPMPPlaneData_f dataFunc;
|
XPMPPlaneData_f dataFunc;
|
||||||
void * ref;
|
void * ref = nullptr;
|
||||||
|
|
||||||
// This is last known data we got for the plane, with timestamps.
|
// This is last known data we got for the plane, with timestamps.
|
||||||
int posAge;
|
int posAge;
|
||||||
|
|||||||
Reference in New Issue
Block a user