Added FSX worker to marshal SimConnect data to Lua structures - untested
This commit is contained in:
parent
54e7e36ee9
commit
f92d3e612b
@ -208,6 +208,58 @@ type
|
||||
end;
|
||||
|
||||
|
||||
TCustomLuaParameters = class(TInterfacedObject, ILuaVariable, ILuaReadParameters)
|
||||
protected
|
||||
function GetDefaultVariable: ILuaVariable;
|
||||
public
|
||||
{ ILuaVariable }
|
||||
function GetVariableType: TLuaVariableType;
|
||||
function GetDataType: TLuaDataType;
|
||||
|
||||
function GetAsBoolean: Boolean;
|
||||
function GetAsInteger: Integer;
|
||||
function GetAsNumber: Double;
|
||||
function GetAsUserData: Pointer;
|
||||
function GetAsString: string;
|
||||
function GetAsTable: ILuaTable;
|
||||
function GetAsFunction: ILuaFunction;
|
||||
|
||||
procedure SetAsBoolean(ABoolean: Boolean);
|
||||
procedure SetAsInteger(AInteger: Integer);
|
||||
procedure SetAsNumber(ANumber: Double);
|
||||
procedure SetAsUserData(AUserData: Pointer);
|
||||
procedure SetAsString(AString: string);
|
||||
procedure SetAsTable(ATable: ILuaTable);
|
||||
|
||||
{ ILuaReadParameters }
|
||||
function GetCount: Integer; virtual; abstract;
|
||||
function GetItem(Index: Integer): ILuaVariable; virtual; abstract;
|
||||
|
||||
function GetEnumerator: ILuaParametersEnumerator;
|
||||
function ToString: string; override;
|
||||
end;
|
||||
|
||||
|
||||
TLuaParameters = class(TCustomLuaParameters, ILuaWriteParameters)
|
||||
private
|
||||
FParameters: TList<ILuaVariable>;
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
|
||||
function GetCount: Integer; override;
|
||||
function GetItem(Index: Integer): ILuaVariable; override;
|
||||
|
||||
{ ILuaWriteParameters }
|
||||
procedure Push(ABoolean: Boolean); overload;
|
||||
procedure Push(AInteger: Integer); overload;
|
||||
procedure Push(ANumber: Double); overload;
|
||||
procedure Push(AUserData: Pointer); overload;
|
||||
procedure Push(const AString: string); overload;
|
||||
procedure Push(ATable: ILuaTable); overload;
|
||||
end;
|
||||
|
||||
|
||||
ILuaFunction = interface
|
||||
['{1BE5E470-0318-410E-8D5B-94BFE04A3DBE}']
|
||||
function Call(): ILuaReadParameters; overload;
|
||||
@ -413,38 +465,6 @@ type
|
||||
end;
|
||||
|
||||
|
||||
TCustomLuaParameters = class(TInterfacedObject, ILuaVariable, ILuaReadParameters)
|
||||
protected
|
||||
function GetDefaultVariable: ILuaVariable;
|
||||
public
|
||||
{ ILuaVariable }
|
||||
function GetVariableType: TLuaVariableType;
|
||||
function GetDataType: TLuaDataType;
|
||||
|
||||
function GetAsBoolean: Boolean;
|
||||
function GetAsInteger: Integer;
|
||||
function GetAsNumber: Double;
|
||||
function GetAsUserData: Pointer;
|
||||
function GetAsString: string;
|
||||
function GetAsTable: ILuaTable;
|
||||
function GetAsFunction: ILuaFunction;
|
||||
|
||||
procedure SetAsBoolean(ABoolean: Boolean);
|
||||
procedure SetAsInteger(AInteger: Integer);
|
||||
procedure SetAsNumber(ANumber: Double);
|
||||
procedure SetAsUserData(AUserData: Pointer);
|
||||
procedure SetAsString(AString: string);
|
||||
procedure SetAsTable(ATable: ILuaTable);
|
||||
|
||||
{ ILuaReadParameters }
|
||||
function GetCount: Integer; virtual; abstract;
|
||||
function GetItem(Index: Integer): ILuaVariable; virtual; abstract;
|
||||
|
||||
function GetEnumerator: ILuaParametersEnumerator;
|
||||
function ToString: string; override;
|
||||
end;
|
||||
|
||||
|
||||
TLuaStackParameters = class(TCustomLuaParameters)
|
||||
private
|
||||
FState: lua_State;
|
||||
@ -568,26 +588,6 @@ type
|
||||
end;
|
||||
|
||||
|
||||
TLuaReadWriteParameters = class(TCustomLuaParameters, ILuaWriteParameters)
|
||||
private
|
||||
FParameters: TList<ILuaVariable>;
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
|
||||
function GetCount: Integer; override;
|
||||
function GetItem(Index: Integer): ILuaVariable; override;
|
||||
|
||||
{ ILuaWriteParameters }
|
||||
procedure Push(ABoolean: Boolean); overload;
|
||||
procedure Push(AInteger: Integer); overload;
|
||||
procedure Push(ANumber: Double); overload;
|
||||
procedure Push(AUserData: Pointer); overload;
|
||||
procedure Push(const AString: string); overload;
|
||||
procedure Push(ATable: ILuaTable); overload;
|
||||
end;
|
||||
|
||||
|
||||
TLuaStackWriteParameters = class(TInterfacedObject, ILuaWriteParameters)
|
||||
private
|
||||
FState: lua_State;
|
||||
@ -682,11 +682,11 @@ class function TLuaHelpers.CreateParameters(AParameters: array of const): ILuaRe
|
||||
var
|
||||
parameterIndex: Integer;
|
||||
parameter: TVarRec;
|
||||
resultParameters: TLuaReadWriteParameters;
|
||||
resultParameters: TLuaParameters;
|
||||
table: ILuaTable;
|
||||
|
||||
begin
|
||||
resultParameters := TLuaReadWriteParameters.Create;
|
||||
resultParameters := TLuaParameters.Create;
|
||||
|
||||
for parameterIndex := Low(AParameters) to High(AParameters) do
|
||||
begin
|
||||
@ -2263,8 +2263,8 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
{ TLuaReadWriteParameters }
|
||||
constructor TLuaReadWriteParameters.Create;
|
||||
{ TLuaParameters }
|
||||
constructor TLuaParameters.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
@ -2272,7 +2272,7 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
destructor TLuaReadWriteParameters.Destroy;
|
||||
destructor TLuaParameters.Destroy;
|
||||
begin
|
||||
FreeAndNil(FParameters);
|
||||
|
||||
@ -2280,49 +2280,49 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function TLuaReadWriteParameters.GetCount: Integer;
|
||||
function TLuaParameters.GetCount: Integer;
|
||||
begin
|
||||
Result := FParameters.Count;
|
||||
end;
|
||||
|
||||
|
||||
function TLuaReadWriteParameters.GetItem(Index: Integer): ILuaVariable;
|
||||
function TLuaParameters.GetItem(Index: Integer): ILuaVariable;
|
||||
begin
|
||||
Result := FParameters[Index];
|
||||
end;
|
||||
|
||||
|
||||
procedure TLuaReadWriteParameters.Push(ABoolean: Boolean);
|
||||
procedure TLuaParameters.Push(ABoolean: Boolean);
|
||||
begin
|
||||
FParameters.Add(TLuaVariable.Create(ABoolean));
|
||||
end;
|
||||
|
||||
|
||||
procedure TLuaReadWriteParameters.Push(AInteger: Integer);
|
||||
procedure TLuaParameters.Push(AInteger: Integer);
|
||||
begin
|
||||
FParameters.Add(TLuaVariable.Create(AInteger));
|
||||
end;
|
||||
|
||||
|
||||
procedure TLuaReadWriteParameters.Push(ANumber: Double);
|
||||
procedure TLuaParameters.Push(ANumber: Double);
|
||||
begin
|
||||
FParameters.Add(TLuaVariable.Create(ANumber));
|
||||
end;
|
||||
|
||||
|
||||
procedure TLuaReadWriteParameters.Push(AUserData: Pointer);
|
||||
procedure TLuaParameters.Push(AUserData: Pointer);
|
||||
begin
|
||||
FParameters.Add(TLuaVariable.Create(AUserData));
|
||||
end;
|
||||
|
||||
|
||||
procedure TLuaReadWriteParameters.Push(const AString: string);
|
||||
procedure TLuaParameters.Push(const AString: string);
|
||||
begin
|
||||
FParameters.Add(TLuaVariable.Create(AString));
|
||||
end;
|
||||
|
||||
|
||||
procedure TLuaReadWriteParameters.Push(ATable: ILuaTable);
|
||||
procedure TLuaParameters.Push(ATable: ILuaTable);
|
||||
begin
|
||||
FParameters.Add(TLuaVariable.Create(ATable));
|
||||
end;
|
||||
|
@ -61,16 +61,18 @@ type
|
||||
constructor Create(AProvider: TFSXLEDFunctionProvider; AInfo: ILuaTable; AOnSetup: ILuaFunction);
|
||||
end;
|
||||
|
||||
TFSXDefinition = record
|
||||
ID: Cardinal;
|
||||
DataHandler: IFSXSimConnectDataHandler;
|
||||
end;
|
||||
|
||||
TFSXLEDFunctionWorker = class(TCustomLuaLEDFunctionWorker)
|
||||
private
|
||||
FDataHandler: IFSXSimConnectDataHandler;
|
||||
FDefinitionID: TList<Cardinal>;
|
||||
FDefinitions: TList<TFSXDefinition>;
|
||||
protected
|
||||
property DataHandler: IFSXSimConnectDataHandler read FDataHandler;
|
||||
property DefinitionID: TList<Cardinal> read FDefinitionID;
|
||||
property Definitions: TList<TFSXDefinition> read FDefinitions;
|
||||
protected
|
||||
procedure AddDefinition(ADefinition: IFSXSimConnectDefinition);
|
||||
procedure AddDefinition(ADefinition: IFSXSimConnectDefinition; ADataHandler: IFSXSimConnectDataHandler);
|
||||
|
||||
procedure HandleData(AData: Pointer); virtual; abstract;
|
||||
public
|
||||
@ -94,16 +96,39 @@ uses
|
||||
|
||||
|
||||
type
|
||||
TCustomFSXFunctionWorkerDataHandler = class(TInterfacedObject, IFSXSimConnectDataHandler)
|
||||
TLuaSimConnectDataType = (
|
||||
// Native types
|
||||
Float64, Float32, Int64, Int32, StringValue,
|
||||
|
||||
// Preprocessed types (for scripting convenience)
|
||||
Bool,
|
||||
|
||||
// Structures
|
||||
XYZ, LatLonAlt, Waypoint
|
||||
);
|
||||
|
||||
|
||||
TLuaSimConnectVariable = record
|
||||
Name: string;
|
||||
DataType: TLuaSimConnectDataType;
|
||||
end;
|
||||
|
||||
|
||||
TFSXFunctionWorkerDataHandler = class(TInterfacedObject, IFSXSimConnectDataHandler)
|
||||
private
|
||||
FWorker: TFSXLEDFunctionWorker;
|
||||
FOnData: ILuaFunction;
|
||||
FWorkerID: string;
|
||||
FVariables: TList<TLuaSimConnectVariable>;
|
||||
protected
|
||||
{ IFSXSimConnectDataHandler }
|
||||
procedure HandleData(AData: Pointer);
|
||||
|
||||
property Worker: TFSXLEDFunctionWorker read FWorker;
|
||||
property OnData: ILuaFunction read FOnData;
|
||||
property Variables: TList<TLuaSimConnectVariable> read FVariables;
|
||||
property WorkerID: string read FWorkerID;
|
||||
public
|
||||
constructor Create(AWorker: TFSXLEDFunctionWorker);
|
||||
constructor Create(AVariables: TList<TLuaSimConnectVariable>; const AWorkerID: string; AOnData: ILuaFunction);
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
|
||||
@ -119,34 +144,24 @@ type
|
||||
end;
|
||||
|
||||
|
||||
type
|
||||
TLuaSimConnectType = record
|
||||
TypeName: string;
|
||||
Units: string;
|
||||
DataType: SIMCONNECT_DATAType;
|
||||
end;
|
||||
|
||||
const
|
||||
LuaSimConnectTypes: array[0..4] of TLuaSimConnectType =
|
||||
(
|
||||
( TypeName: 'Bool'; Units: FSX_UNIT_BOOL; DataType: SIMCONNECT_DATAType_INT32 ),
|
||||
( TypeName: 'Percent'; Units: FSX_UNIT_PERCENT; DataType: SIMCONNECT_DATAType_FLOAT64 ),
|
||||
( TypeName: 'Integer'; Units: FSX_UNIT_NUMBER; DataType: SIMCONNECT_DATAType_INT32 ),
|
||||
( TypeName: 'Float'; Units: FSX_UNIT_NUMBER; DataType: SIMCONNECT_DATAType_FLOAT64 ),
|
||||
( TypeName: 'Mask'; Units: FSX_UNIT_MASK; DataType: SIMCONNECT_DATATYPE_INT32 )
|
||||
);
|
||||
LuaSimConnectDataTypes: array[TLuaSimConnectDataType] of string =
|
||||
(
|
||||
'Float64', 'Float32', 'Int64', 'Int32', 'String',
|
||||
'Bool',
|
||||
'XYZ', 'LatLonAlt', 'Waypoint'
|
||||
);
|
||||
|
||||
|
||||
function GetUnits(const AType: string; out AUnits: string; out ADataType: SIMCONNECT_DATAType): Boolean;
|
||||
function GetDataType(const ATypeName: string; out ADataType: TLuaSimConnectDataType): Boolean;
|
||||
var
|
||||
typeIndex: Integer;
|
||||
dataType: TLuaSimConnectDataType;
|
||||
|
||||
begin
|
||||
for typeIndex := Low(LuaSimConnectTypes) to High(LuaSimConnectTypes) do
|
||||
if SameText(AType, LuaSimConnectTypes[typeIndex].TypeName) then
|
||||
for dataType := Low(TLuaSimConnectDataType) to High(TLuaSimConnectDataType) do
|
||||
if SameText(ATypeName, LuaSimConnectDataTypes[dataType]) then
|
||||
begin
|
||||
AUnits := LuaSimConnectTypes[typeIndex].Units;
|
||||
ADataType := LuaSimConnectTypes[typeIndex].DataType;
|
||||
ADataType := dataType;
|
||||
Exit(True);
|
||||
end;
|
||||
|
||||
@ -251,7 +266,7 @@ end;
|
||||
procedure TFSXLEDFunctionProvider.InitInterpreter;
|
||||
var
|
||||
simConnectType: ILuaTable;
|
||||
typeIndex: Integer;
|
||||
dataType: TLuaSimConnectDataType;
|
||||
|
||||
begin
|
||||
inherited InitInterpreter;
|
||||
@ -259,8 +274,8 @@ begin
|
||||
Interpreter.RegisterFunctions(FScriptSimConnect, 'SimConnect');
|
||||
|
||||
simConnectType := TLuaTable.Create;
|
||||
for typeIndex := Low(LuaSimConnectTypes) to High(LuaSimConnectTypes) do
|
||||
simConnectType.SetValue(LuaSimConnectTypes[typeIndex].TypeName, LuaSimConnectTypes[typeIndex].TypeName);
|
||||
for dataType := Low(TLuaSimConnectDataType) to High(TLuaSimConnectDataType) do
|
||||
simConnectType.SetValue(LuaSimConnectDataTypes[dataType], LuaSimConnectDataTypes[dataType]);
|
||||
|
||||
Interpreter.SetGlobalVariable('SimConnectType', simConnectType);
|
||||
end;
|
||||
@ -358,11 +373,7 @@ end;
|
||||
{ TFSXLEDFunctionWorker }
|
||||
constructor TFSXLEDFunctionWorker.Create(const AProviderUID, AFunctionUID: string; AStates: ILEDMultiStateFunction; ASettings: ILEDFunctionWorkerSettings; const APreviousState: string);
|
||||
begin
|
||||
{ We can't pass ourselves as the Data Handler, as it would keep a reference to
|
||||
this worker from the SimConnect interface. That'd mean the worker never
|
||||
gets destroyed, and SimConnect never shuts down. Hence this proxy class. }
|
||||
FDataHandler := TCustomFSXFunctionWorkerDataHandler.Create(Self);
|
||||
FDefinitionID := TList<Cardinal>.Create;
|
||||
FDefinitions := TList<TFSXDefinition>.Create;
|
||||
|
||||
inherited Create(AProviderUID, AFunctionUID, AStates, ASettings, APreviousState);
|
||||
end;
|
||||
@ -371,41 +382,174 @@ end;
|
||||
destructor TFSXLEDFunctionWorker.Destroy;
|
||||
var
|
||||
simConnect: IFSXSimConnect;
|
||||
id: Cardinal;
|
||||
definition: TFSXDefinition;
|
||||
|
||||
begin
|
||||
if Assigned(Provider) and (DefinitionID.Count > 0) then
|
||||
if Assigned(Provider) and (Definitions.Count > 0) then
|
||||
begin
|
||||
simConnect := (Provider as TFSXLEDFunctionProvider).GetSimConnect;
|
||||
|
||||
for id in DefinitionID do
|
||||
simConnect.RemoveDefinition(id, DataHandler);
|
||||
for definition in Definitions do
|
||||
simConnect.RemoveDefinition(definition.ID, definition.DataHandler);
|
||||
end;
|
||||
|
||||
FreeAndNil(FDefinitionID);
|
||||
FreeAndNil(FDefinitions);
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
|
||||
procedure TFSXLEDFunctionWorker.AddDefinition(ADefinition: IFSXSimConnectDefinition);
|
||||
procedure TFSXLEDFunctionWorker.AddDefinition(ADefinition: IFSXSimConnectDefinition; ADataHandler: IFSXSimConnectDataHandler);
|
||||
var
|
||||
definition: TFSXDefinition;
|
||||
|
||||
begin
|
||||
DefinitionID.Add((Provider as TFSXLEDFunctionProvider).GetSimConnect.AddDefinition(ADefinition, DataHandler));
|
||||
definition.DataHandler := ADataHandler;
|
||||
definition.ID := (Provider as TFSXLEDFunctionProvider).GetSimConnect.AddDefinition(ADefinition, ADataHandler);
|
||||
|
||||
Definitions.Add(definition);
|
||||
end;
|
||||
|
||||
|
||||
{ TCustomFSXFunctionWorkerDataHandler }
|
||||
constructor TCustomFSXFunctionWorkerDataHandler.Create(AWorker: TFSXLEDFunctionWorker);
|
||||
{ TFSXFunctionWorkerDataHandler }
|
||||
constructor TFSXFunctionWorkerDataHandler.Create(AVariables: TList<TLuaSimConnectVariable>; const AWorkerID: string; AOnData: ILuaFunction);
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
FWorker := AWorker;
|
||||
FWorkerID := AWorkerID;
|
||||
FOnData := AOnData;
|
||||
|
||||
FVariables := TList<TLuaSimConnectVariable>.Create;
|
||||
FVariables.AddRange(AVariables);
|
||||
end;
|
||||
|
||||
|
||||
procedure TCustomFSXFunctionWorkerDataHandler.HandleData(AData: Pointer);
|
||||
destructor TFSXFunctionWorkerDataHandler.Destroy;
|
||||
begin
|
||||
Worker.HandleData(AData);
|
||||
FreeAndNil(FVariables);
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
|
||||
procedure TFSXFunctionWorkerDataHandler.HandleData(AData: Pointer);
|
||||
var
|
||||
data: ILuaTable;
|
||||
dataPointer: PByte;
|
||||
variableIndex: Integer;
|
||||
variable: TLuaSimConnectVariable;
|
||||
value: string;
|
||||
structure: ILuaTable;
|
||||
flags: ILuaTable;
|
||||
xyzData: ^SIMCONNECT_DATA_XYZ;
|
||||
latLonAltData: ^SIMCONNECT_DATA_LATLONALT;
|
||||
waypointData: ^SIMCONNECT_DATA_WAYPOINT;
|
||||
|
||||
begin
|
||||
data := TLuaTable.Create;
|
||||
dataPointer := AData;
|
||||
|
||||
for variableIndex := 0 to Pred(Variables.Count) do
|
||||
begin
|
||||
variable := Variables[variableIndex];
|
||||
|
||||
case variable.DataType of
|
||||
Float64:
|
||||
begin
|
||||
data.SetValue(variable.Name, PDouble(dataPointer)^);
|
||||
Inc(dataPointer, SizeOf(Double));
|
||||
end;
|
||||
|
||||
Float32:
|
||||
begin
|
||||
data.SetValue(variable.Name, PSingle(dataPointer)^);
|
||||
Inc(dataPointer, SizeOf(Single));
|
||||
end;
|
||||
|
||||
Int64:
|
||||
begin
|
||||
data.SetValue(variable.Name, PInt64(dataPointer)^);
|
||||
Inc(dataPointer, SizeOf(Int64));
|
||||
end;
|
||||
|
||||
Int32:
|
||||
begin
|
||||
data.SetValue(variable.Name, PInteger(dataPointer)^);
|
||||
Inc(dataPointer, SizeOf(Integer));
|
||||
end;
|
||||
|
||||
StringValue:
|
||||
begin
|
||||
// TODO change to STRINGV
|
||||
//SimConnect_RetrieveString()
|
||||
|
||||
SetString(value, PChar(dataPointer), 256);
|
||||
data.SetValue(variable.Name, value);
|
||||
|
||||
Inc(dataPointer, 256);
|
||||
end;
|
||||
|
||||
Bool:
|
||||
begin
|
||||
data.SetValue(variable.Name, (PInteger(dataPointer)^ <> 0));
|
||||
Inc(dataPointer, SizeOf(Integer));
|
||||
end;
|
||||
|
||||
XYZ:
|
||||
begin
|
||||
xyzData := AData;
|
||||
|
||||
structure := TLuaTable.Create;
|
||||
structure.SetValue('X', xyzData^.x);
|
||||
structure.SetValue('Y', xyzData^.y);
|
||||
structure.SetValue('Z', xyzData^.z);
|
||||
|
||||
data.SetValue(variable.Name, structure);
|
||||
Inc(dataPointer, SizeOf(SIMCONNECT_DATA_XYZ));
|
||||
end;
|
||||
|
||||
LatLonAlt:
|
||||
begin
|
||||
latLonAltData := AData;
|
||||
|
||||
structure := TLuaTable.Create;
|
||||
structure.SetValue('Latitude', latLonAltData^.Latitude);
|
||||
structure.SetValue('Longitude', latLonAltData^.Longitude);
|
||||
structure.SetValue('Altitude', latLonAltData^.Altitude);
|
||||
|
||||
data.SetValue(variable.Name, structure);
|
||||
Inc(dataPointer, SizeOf(SIMCONNECT_DATA_LATLONALT));
|
||||
end;
|
||||
|
||||
Waypoint:
|
||||
begin
|
||||
waypointData := AData;
|
||||
|
||||
structure := TLuaTable.Create;
|
||||
structure.SetValue('Latitude', waypointData^.Latitude);
|
||||
structure.SetValue('Longitude', waypointData^.Longitude);
|
||||
structure.SetValue('Altitude', waypointData^.Altitude);
|
||||
structure.SetValue('KtsSpeed', waypointData^.ktsSpeed);
|
||||
structure.SetValue('PercentThrottle', waypointData^.percentThrottle);
|
||||
|
||||
flags := TLuaTable.Create;
|
||||
flags.SetValue('SpeedRequested', (waypointData^.Flags and SIMCONNECT_WAYPOINT_SPEED_REQUESTED) <> 0);
|
||||
flags.SetValue('ThrottleRequested', (waypointData^.Flags and SIMCONNECT_WAYPOINT_THROTTLE_REQUESTED) <> 0);
|
||||
flags.SetValue('ComputeVerticalSpeed', (waypointData^.Flags and SIMCONNECT_WAYPOINT_COMPUTE_VERTICAL_SPEED) <> 0);
|
||||
flags.SetValue('IsAGL', (waypointData^.Flags and SIMCONNECT_WAYPOINT_ALTITUDE_IS_AGL) <> 0);
|
||||
flags.SetValue('OnGround', (waypointData^.Flags and SIMCONNECT_WAYPOINT_ON_GROUND) <> 0);
|
||||
flags.SetValue('Reverse', (waypointData^.Flags and SIMCONNECT_WAYPOINT_REVERSE) <> 0);
|
||||
flags.SetValue('WrapToFirst', (waypointData^.Flags and SIMCONNECT_WAYPOINT_WRAP_TO_FIRST) <> 0);
|
||||
|
||||
structure.SetValue('Flags', flags);
|
||||
|
||||
data.SetValue(variable.Name, structure);
|
||||
Inc(dataPointer, SizeOf(SIMCONNECT_DATA_WAYPOINT));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
OnData.Call([WorkerID, data]);
|
||||
end;
|
||||
|
||||
|
||||
@ -427,8 +571,11 @@ var
|
||||
definition: IFSXSimConnectDefinition;
|
||||
variable: TLuaKeyValuePair;
|
||||
info: ILuaTable;
|
||||
dataType: TLuaSimConnectDataType;
|
||||
simConnectDataType: SIMCONNECT_DATAType;
|
||||
units: string;
|
||||
dataType: SIMCONNECT_DATAType;
|
||||
luaVariables: TList<TLuaSimConnectVariable>;
|
||||
luaVariable: TLuaSimConnectVariable;
|
||||
|
||||
begin
|
||||
if Context.Parameters.Count < 3 then
|
||||
@ -453,21 +600,62 @@ begin
|
||||
|
||||
definition := Provider.GetSimConnect.CreateDefinition;
|
||||
|
||||
for variable in variables do
|
||||
begin
|
||||
if variable.Value.VariableType = VariableTable then
|
||||
luaVariables := TList<TLuaSimConnectVariable>.Create;
|
||||
try
|
||||
for variable in variables do
|
||||
begin
|
||||
info := variable.Value.AsTable;
|
||||
if info.HasValue('variable') and
|
||||
info.HasValue('type') and
|
||||
GetUnits(info.GetValue('type').AsString, units, dataType) then
|
||||
if variable.Value.VariableType = VariableTable then
|
||||
begin
|
||||
definition.AddVariable(info.GetValue('variable').AsString, units, dataType);
|
||||
info := variable.Value.AsTable;
|
||||
if info.HasValue('variable') then
|
||||
begin
|
||||
luaVariable.Name := variable.Key.AsString;
|
||||
units := '';
|
||||
simConnectDataType := SIMCONNECT_DATAType_FLOAT64;
|
||||
|
||||
if info.HasValue('type') and GetDataType(info.GetValue('type').AsString, dataType) then
|
||||
begin
|
||||
luaVariable.DataType := dataType;
|
||||
|
||||
case dataType of
|
||||
Float32: simConnectDataType := SIMCONNECT_DATAType_FLOAT32;
|
||||
Int64: simConnectDataType := SIMCONNECT_DATAType_INT64;
|
||||
Int32,
|
||||
Bool:
|
||||
begin
|
||||
simConnectDataType := SIMCONNECT_DATAType_INT32;
|
||||
units := 'bool';
|
||||
end;
|
||||
|
||||
// TODO change to STRINGV
|
||||
StringValue: simConnectDataType := SIMCONNECT_DATAType_STRING256;
|
||||
XYZ: simConnectDataType := SIMCONNECT_DATAType_XYZ;
|
||||
LatLonAlt: simConnectDataType := SIMCONNECT_DATAType_LATLONALT;
|
||||
Waypoint: simConnectDataType := SIMCONNECT_DATAType_WAYPOINT;
|
||||
end;
|
||||
|
||||
if info.HasValue('units') then
|
||||
units := info.GetValue('units').AsString
|
||||
else if not (dataType in [Bool, StringValue, XYZ, LatLonAlt, Waypoint]) then
|
||||
raise ELuaScriptError.CreateFmt('Missing units for variable %s', [variable.Key.AsString]);
|
||||
end else
|
||||
begin
|
||||
if not info.HasValue('units') then
|
||||
raise ELuaScriptError.CreateFmt('Missing units or type for variable %s', [variable.Key.AsString]);
|
||||
|
||||
units := info.GetValue('units').AsString;
|
||||
end;
|
||||
|
||||
luaVariables.Add(luaVariable);
|
||||
definition.AddVariable(info.GetValue('variable').AsString, units, simConnectDataType);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
(worker as TFSXLEDFunctionWorker).AddDefinition(definition);
|
||||
(worker as TFSXLEDFunctionWorker).AddDefinition(definition, TFSXFunctionWorkerDataHandler.Create(luaVariables, worker.UID, onData));
|
||||
finally
|
||||
FreeAndNil(luaVariables);
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -88,12 +88,12 @@ const
|
||||
type
|
||||
TFSXSimConnectDefinitionRef = class(TObject)
|
||||
private
|
||||
FDefinition: IFSXSimConnectDefinitionAccess;
|
||||
FDefinition: IFSXSimConnectDefinition;
|
||||
FDataHandlers: TInterfaceList;
|
||||
protected
|
||||
property DataHandlers: TInterfaceList read FDataHandlers;
|
||||
public
|
||||
constructor Create(ADefinition: IFSXSimConnectDefinitionAccess);
|
||||
constructor Create(ADefinition: IFSXSimConnectDefinition);
|
||||
destructor Destroy; override;
|
||||
|
||||
function Attach(ADataHandler: IFSXSimConnectDataHandler): Integer;
|
||||
@ -101,7 +101,7 @@ type
|
||||
|
||||
procedure HandleData(AData: Pointer);
|
||||
|
||||
property Definition: IFSXSimConnectDefinitionAccess read FDefinition;
|
||||
property Definition: IFSXSimConnectDefinition read FDefinition;
|
||||
end;
|
||||
|
||||
|
||||
@ -145,11 +145,11 @@ type
|
||||
procedure TrySimConnect(const ALibraryName: string); overload;
|
||||
|
||||
procedure RegisterDefinitions;
|
||||
procedure RegisterDefinition(ADefinitionID: Cardinal; ADefinition: IFSXSimConnectDefinitionAccess);
|
||||
procedure RegisterDefinition(ADefinitionID: Cardinal; ADefinition: IFSXSimConnectDefinition);
|
||||
procedure UpdateDefinition(ADefinitionID: Cardinal);
|
||||
procedure UnregisterDefinition(ADefinitionID: Cardinal);
|
||||
|
||||
function SameDefinition(ADefinition1, ADefinition2: IFSXSimConnectDefinitionAccess): Boolean;
|
||||
function SameDefinition(ADefinition1, ADefinition2: IFSXSimConnectDefinition): Boolean;
|
||||
|
||||
procedure UpdateProfileMenu;
|
||||
|
||||
@ -187,7 +187,7 @@ type
|
||||
|
||||
TFSXSimConnectVariableList = TObjectList<TFSXSimConnectVariable>;
|
||||
|
||||
TFSXSimConnectDefinition = class(TInterfacedObject, IFSXSimConnectDefinition, IFSXSimConnectDefinitionAccess)
|
||||
TFSXSimConnectDefinition = class(TInterfacedObject, IFSXSimConnectDefinition)
|
||||
private
|
||||
FSimConnect: IFSXSimConnect;
|
||||
FVariables: TFSXSimConnectVariableList;
|
||||
@ -198,7 +198,6 @@ type
|
||||
{ IFSXSimConnectDefinition }
|
||||
procedure AddVariable(AVariableName, AUnitsName: string; ADataType: SIMCONNECT_DATAType; AEpsilon: Single = 0);
|
||||
|
||||
{ IFSXSimConnectDefinitionAccess }
|
||||
function GetVariableCount: Integer;
|
||||
function GetVariable(AIndex: Integer): IFSXSimConnectVariable;
|
||||
public
|
||||
@ -518,6 +517,7 @@ var
|
||||
simObjectData: PSimConnectRecvSimObjectData;
|
||||
eventData: PSimConnectRecvEvent;
|
||||
definitionRef: TFSXSimConnectDefinitionRef;
|
||||
simObjectDataByType: PSimConnectRecvSimObjectDataByType;
|
||||
|
||||
begin
|
||||
Log.Verbose('Handling messages');
|
||||
@ -538,6 +538,18 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE:
|
||||
begin
|
||||
simObjectDataByType := PSimConnectRecvSimObjectDataByType(data);
|
||||
Log.Verbose(Format('Received Sim Object Data By Type message (definition = %d)', [simObjectDataByType^.dwDefineID]));
|
||||
|
||||
if Definitions.ContainsKey(simObjectDataByType^.dwDefineID) then
|
||||
begin
|
||||
definitionRef := Definitions[simObjectDataByType^.dwDefineID];
|
||||
definitionRef.HandleData(@simObjectDataByType^.dwData);
|
||||
end;
|
||||
end;
|
||||
|
||||
SIMCONNECT_RECV_ID_EVENT:
|
||||
begin
|
||||
eventData := PSimConnectRecvEvent(data);
|
||||
@ -608,7 +620,7 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
procedure TFSXSimConnectClient.RegisterDefinition(ADefinitionID: Cardinal; ADefinition: IFSXSimConnectDefinitionAccess);
|
||||
procedure TFSXSimConnectClient.RegisterDefinition(ADefinitionID: Cardinal; ADefinition: IFSXSimConnectDefinition);
|
||||
var
|
||||
variableIndex: Integer;
|
||||
variable: IFSXSimConnectVariable;
|
||||
@ -658,7 +670,7 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
function TFSXSimConnectClient.SameDefinition(ADefinition1, ADefinition2: IFSXSimConnectDefinitionAccess): Boolean;
|
||||
function TFSXSimConnectClient.SameDefinition(ADefinition1, ADefinition2: IFSXSimConnectDefinition): Boolean;
|
||||
var
|
||||
variableIndex: Integer;
|
||||
variable1: IFSXSimConnectVariable;
|
||||
@ -765,13 +777,13 @@ var
|
||||
addDefinition: TAddDefinitionValue;
|
||||
definitionID: Cardinal;
|
||||
definitionRef: TFSXSimConnectDefinitionRef;
|
||||
definitionAccess: IFSXSimConnectDefinitionAccess;
|
||||
definitionAccess: IFSXSimConnectDefinition;
|
||||
hasDefinition: Boolean;
|
||||
refCount: Integer;
|
||||
|
||||
begin
|
||||
addDefinition := Msg.MsgData;
|
||||
definitionAccess := (addDefinition.Definition as IFSXSimConnectDefinitionAccess);
|
||||
definitionAccess := (addDefinition.Definition as IFSXSimConnectDefinition);
|
||||
hasDefinition := False;
|
||||
|
||||
Log.Verbose('Received request to add a definition');
|
||||
@ -887,7 +899,7 @@ end;
|
||||
|
||||
|
||||
{ TFSXSimConnectDefinitionRef }
|
||||
constructor TFSXSimConnectDefinitionRef.Create(ADefinition: IFSXSimConnectDefinitionAccess);
|
||||
constructor TFSXSimConnectDefinitionRef.Create(ADefinition: IFSXSimConnectDefinition);
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
|
@ -39,12 +39,6 @@ type
|
||||
end;
|
||||
|
||||
|
||||
IFSXSimConnectDefinition = interface
|
||||
['{F1EAB3B1-0A3D-4B06-A75F-823E15C313B8}']
|
||||
procedure AddVariable(AVariableName, AUnitsName: string; ADataType: SIMCONNECT_DATAType; AEpsilon: Single = 0);
|
||||
end;
|
||||
|
||||
|
||||
IFSXSimConnectVariable = interface
|
||||
['{A41AD003-77C0-4E34-91E3-B0BAADD08FCE}']
|
||||
function GetVariableName: string;
|
||||
@ -54,8 +48,10 @@ type
|
||||
end;
|
||||
|
||||
|
||||
IFSXSimConnectDefinitionAccess = interface
|
||||
['{2592534C-0344-4442-8A5F-1AB34B96E1B5}']
|
||||
IFSXSimConnectDefinition = interface
|
||||
['{F1EAB3B1-0A3D-4B06-A75F-823E15C313B8}']
|
||||
procedure AddVariable(AVariableName, AUnitsName: string; ADataType: SIMCONNECT_DATAType; AEpsilon: Single = 0);
|
||||
|
||||
function GetVariableCount: Integer;
|
||||
function GetVariable(AIndex: Integer): IFSXSimConnectVariable;
|
||||
end;
|
||||
|
@ -171,6 +171,7 @@ begin
|
||||
|
||||
Interpreter.SetGlobalVariable('LEDColor', table);
|
||||
|
||||
// #ToDo1 -oMvR: 29-5-2017: Logging methods
|
||||
// #ToDo1 -oMvR: 28-5-2017: SetState
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user