Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions extplane-plugin/xplaneplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void XPlanePlugin::updateDataRef(DataRef *ref) {
{
IntArrayDataRef *iaRef = qobject_cast<IntArrayDataRef*>(ref);
int arrayLength = iaRef->value().size();
if(arrayLength <= 0) {
if(arrayLength == 0) {
arrayLength = XPLMGetDatavi(iaRef->ref(), nullptr, 0, 0);
iaRef->setLength(arrayLength);
}
Expand Down Expand Up @@ -210,13 +210,25 @@ void XPlanePlugin::changeDataRef(DataRef *ref)
case extplaneRefTypeFloatArray:
{
FloatArrayDataRef *faRef = qobject_cast<FloatArrayDataRef*>(ref);
XPLMSetDatavf(ref->ref(), faRef->valueArray(), 0, faRef->value().size());
while(!faRef->changedIndices.empty()) {
XPLMSetDatavf(ref->ref(), faRef->valueArray() + faRef->changedIndices.front().first,
faRef->changedIndices.front().first,
faRef->changedIndices.front().second - faRef->changedIndices.front().first + 1
);
faRef->changedIndices.pop_front();
}
break;
}
case extplaneRefTypeIntArray:
{
IntArrayDataRef *iaRef = qobject_cast<IntArrayDataRef*>(ref);
XPLMSetDatavi(ref->ref(), iaRef->valueArray(), 0, iaRef->value().size());
while(!iaRef->changedIndices.empty()) {
XPLMSetDatavi(ref->ref(), iaRef->valueArray() + iaRef->changedIndices.front().first,
iaRef->changedIndices.front().first,
iaRef->changedIndices.front().second - iaRef->changedIndices.front().first + 1
);
iaRef->changedIndices.pop_front();
}
break;
}
case extplaneRefTypeInt:
Expand Down
1 change: 0 additions & 1 deletion extplane-server/datarefs/dataref.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ enum {
extplaneRefTypeData = 32
};


/**
* Base class for DataRefs.
*/
Expand Down
6 changes: 6 additions & 0 deletions extplane-server/datarefs/floatarraydataref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ void FloatArrayDataRef::setValue(QString &newValue) {
float value = values[i].toFloat(&ok);
if(ok) {
_valueArray[i] = value;
if(changedIndices.empty() || changedIndices.back().second != (i-1))
{
changedIndices.push_back(std::pair<int, int>(i, i));
} else {
changedIndices.back().second = i;
}
} else if(!values.at(i).isEmpty()) {
INFO << "Invalid value " << values.at(i) << "in array";
}
Expand Down
2 changes: 2 additions & 0 deletions extplane-server/datarefs/floatarraydataref.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "dataref.h"
#include <vector>
#include <list>

class FloatArrayDataRef : public DataRef {
Q_OBJECT
Expand All @@ -19,6 +20,7 @@ class FloatArrayDataRef : public DataRef {
FloatArrayDataRef(QObject *parent, QString name, void* ref);
~FloatArrayDataRef();
std::vector<float> &value();
std::list<std::pair<int, int>> changedIndices;
virtual void updateValue();
virtual QString valueString();
virtual void setValue(QString &newValue);
Expand Down
17 changes: 13 additions & 4 deletions extplane-server/datarefs/intarraydataref.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "intarraydataref.h"
#include "../../util/console.h"
#include <QStringList>
#include <algorithm>
#include <QStringList>

IntArrayDataRef::IntArrayDataRef(QObject *parent, QString name, void *ref) : DataRef(parent, name, ref) {
_typeString = "ia";
Expand All @@ -18,7 +18,9 @@ std::vector<int> & IntArrayDataRef::value() {
return _values;
}

// Copies values from valuearray to value list and emits changed as needed
void IntArrayDataRef::updateValue() {
Q_ASSERT(_length > 0);
bool valuesChanged = false;
for(int i=0;i<_length;i++){
if(_values.at(i) != _valueArray[i]) {
Expand Down Expand Up @@ -62,23 +64,30 @@ void IntArrayDataRef::setValue(QString &newValue) {
int value = values[i].toInt(&ok);
if(ok) {
_valueArray[i] = value;
if(changedIndices.empty() || changedIndices.back().second != (i-1))
{
changedIndices.push_back(std::pair<int, int>(i, i));
} else {
changedIndices.back().second = i;
}
} else if(!values.at(i).isEmpty()) {
INFO << "Invalid value " << values.at(i) << "in array";
}
}
emit changed(this);
updateValue();
}

void IntArrayDataRef::setLength(int newLength)
{
Q_ASSERT(newLength > 0);
Q_ASSERT(newLength >= 0);
_values.resize(newLength);
std::fill(_values.begin(), _values.end(), -9999);
if(_valueArray) delete[] _valueArray;
_valueArray = new int[newLength];
_length = newLength;
}

int* IntArrayDataRef::valueArray()
int *IntArrayDataRef::valueArray()
{
Q_ASSERT(_valueArray);
return _valueArray;
Expand Down
3 changes: 2 additions & 1 deletion extplane-server/datarefs/intarraydataref.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define IntArrayDataRef_H

#include "dataref.h"
#include <QObject>
#include <vector>
#include <list>

class IntArrayDataRef : public DataRef {
Q_OBJECT
Expand All @@ -12,6 +12,7 @@ class IntArrayDataRef : public DataRef {
IntArrayDataRef(QObject *parent, QString name, void* ref);
~IntArrayDataRef();
std::vector<int> &value();
std::list<std::pair<int, int>> changedIndices;
virtual void updateValue();
virtual QString valueString();
virtual void setValue(QString &newValue);
Expand Down
2 changes: 1 addition & 1 deletion protocoldefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Network protocol, currently always 1
#define EXTPLANE_PROTOCOL 1
// Feature revision, every time we add a new feature or bug fix, this should be incremented so that clients can know how old the plugin is
#define EXTPLANE_VERSION 1010
#define EXTPLANE_VERSION 1011

// Base of udp ports. Bind to this + client_id
#define UDP_OUT_PORT_BASE 52000