Skip to content

Commit

Permalink
Some minor cleanups on situation support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ville Ranki committed Apr 4, 2018
1 parent 223c3cc commit 4938d85
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 52 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ Command identifiers are strings that look like datarefs.


### Situations ###
* ** sit {situationFileLocation} ** situation file location relative to XPlane root folder <br />
(e.g., sit Output/situations/SampleSit.sit )
* ** sit "{situationFileLocation}" ** situation file location relative to XPlane root folder <br />
(e.g., sit "Output/situations/SampleSit.sit" )

### Other ###

Expand Down
93 changes: 45 additions & 48 deletions extplane-plugin/xplaneplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,45 +55,45 @@ int XPlanePlugin::pluginStart(char * outName, char * outSig, char *outDesc) {

// Register the nav custom data accessors
XPLMRegisterDataAccessor("extplane/navdata/5km",
xplmType_Data, // The types we support
0, // Writable
NULL, NULL, // Integer accessors
NULL, NULL, // Float accessors
NULL, NULL, // Doubles accessors
NULL, NULL, // Int array accessors
NULL, NULL, // Float array accessors
NavCustomData::DataCallback_5km, NULL, // Raw data accessors
NULL, NULL); // Refcons not used
xplmType_Data, // The types we support
0, // Writable
NULL, NULL, // Integer accessors
NULL, NULL, // Float accessors
NULL, NULL, // Doubles accessors
NULL, NULL, // Int array accessors
NULL, NULL, // Float array accessors
NavCustomData::DataCallback_5km, NULL, // Raw data accessors
NULL, NULL); // Refcons not used
XPLMRegisterDataAccessor("extplane/navdata/20km",
xplmType_Data, // The types we support
0, // Writable
NULL, NULL, // Integer accessors
NULL, NULL, // Float accessors
NULL, NULL, // Doubles accessors
NULL, NULL, // Int array accessors
NULL, NULL, // Float array accessors
NavCustomData::DataCallback_20km, NULL, // Raw data accessors
NULL, NULL); // Refcons not used
xplmType_Data, // The types we support
0, // Writable
NULL, NULL, // Integer accessors
NULL, NULL, // Float accessors
NULL, NULL, // Doubles accessors
NULL, NULL, // Int array accessors
NULL, NULL, // Float array accessors
NavCustomData::DataCallback_20km, NULL, // Raw data accessors
NULL, NULL); // Refcons not used
XPLMRegisterDataAccessor("extplane/navdata/100km",
xplmType_Data, // The types we support
0, // Writable
NULL, NULL, // Integer accessors
NULL, NULL, // Float accessors
NULL, NULL, // Doubles accessors
NULL, NULL, // Int array accessors
NULL, NULL, // Float array accessors
NavCustomData::DataCallback_100km, NULL, // Raw data accessors
NULL, NULL); // Refcons not used
xplmType_Data, // The types we support
0, // Writable
NULL, NULL, // Integer accessors
NULL, NULL, // Float accessors
NULL, NULL, // Doubles accessors
NULL, NULL, // Int array accessors
NULL, NULL, // Float array accessors
NavCustomData::DataCallback_100km, NULL, // Raw data accessors
NULL, NULL); // Refcons not used
XPLMRegisterDataAccessor("extplane/atc/124thatc/latest",
xplmType_Data, // The types we support
0, // Writable
NULL, NULL, // Integer accessors
NULL, NULL, // Float accessors
NULL, NULL, // Doubles accessors
NULL, NULL, // Int array accessors
NULL, NULL, // Float array accessors
ATCCustomData::DataCallback, NULL, // Raw data accessors
NULL, NULL);
xplmType_Data, // The types we support
0, // Writable
NULL, NULL, // Integer accessors
NULL, NULL, // Float accessors
NULL, NULL, // Doubles accessors
NULL, NULL, // Int array accessors
NULL, NULL, // Float array accessors
ATCCustomData::DataCallback, NULL, // Raw data accessors
NULL, NULL);

app->processEvents();
return 1;
Expand Down Expand Up @@ -314,26 +314,23 @@ void XPlanePlugin::setFlightLoopInterval(float newInterval) {

QString XPlanePlugin::refNameWithoutModifiers(QString &original)
{
if(original.contains(":")) {
return original.left(original.indexOf(":"));
}
return original;
return original.contains(":") ? original.left(original.indexOf(":")) : original;
}

/**
* @brief XPlanePlugin::loadSituation
* @param name : situation file location -
* relative to XPlane root folder, e.g. Output/situations/XXX.sit
*/
bool XPlanePlugin::loadSituation(QString sitFileLocation){
int ret = XPLMLoadDataFile(xplm_DataFile_Situation, sitFileLocation.toLatin1().data());
if(ret == 1){
return true;
}else {
return false;
}
}
bool XPlanePlugin::loadSituation(QString sitFileLocation) {

// Remove quotes from filename
sitFileLocation = sitFileLocation.replace("\"", "");

// XPLMLoadDataFile's return value is not documented, assuming it returns
// 1 on success and 0 on fail. TODO: Check this.
return XPLMLoadDataFile(xplm_DataFile_Situation, sitFileLocation.toUtf8().data());
}

void XPlanePlugin::pluginStop() {
DEBUG;
Expand Down
1 change: 1 addition & 0 deletions extplane-plugin/xplaneplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DataRef;
*/
class XPlanePlugin : public QObject, public DataRefProvider {
Q_OBJECT

public:
explicit XPlanePlugin(QObject *parent = nullptr);

Expand Down
3 changes: 2 additions & 1 deletion extplane-server/datarefprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class DataRefProvider {
virtual void buttonRelease(int buttonid)=0;
// Run a named command
virtual void command(QString &name, extplaneCommandType type)=0;
//Load situation file from disk, relatively to XPlane root folder
//Load situation file from disk, relatively to simulator root folder
//Returns true on success
virtual bool loadSituation(QString sitFileLocation)=0;
};

Expand Down
2 changes: 1 addition & 1 deletion extplane-server/tcpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ TcpServer::TcpServer(QObject *parent, DataRefProvider *refProvider) : QObject(pa
, server(this)
, _refProvider(nullptr)
, _clientCount(0) {
connect(&server, SIGNAL(newConnection()), this, SLOT(clientConnected()));
connect(&server, &QTcpServer::newConnection, this, &TcpServer::clientConnected);
setDataRefProvider(refProvider);
}

Expand Down

0 comments on commit 4938d85

Please sign in to comment.