Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix datareftype query #88

Merged
merged 1 commit into from
Mar 16, 2024
Merged
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
10 changes: 5 additions & 5 deletions src/core/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,39 @@ Action::Action(XPLMDataRef dat, int d)
dataref = dat;
data = d;
index = -1; // dataref is not an array
dataref_type = XPLMGetDataRefTypes(dataref);
dataref_type = xplmType_Int;
}

Action::Action(XPLMDataRef dat, float d)
{
dataref = dat;
data_f = d;
index = -1; // dataref is not an array
dataref_type = XPLMGetDataRefTypes(dataref);
dataref_type = xplmType_Float;
}

Action::Action(XPLMDataRef dat, double d)
{
dataref = dat;
data_f = (float)d;
index = -1; // dataref is not an array
dataref_type = XPLMGetDataRefTypes(dataref);
dataref_type = xplmType_Double;
}

Action::Action(XPLMDataRef dat, int array_index, int d)
{
dataref = dat;
data = d;
index = array_index;
dataref_type = XPLMGetDataRefTypes(dataref);
dataref_type = xplmType_IntArray;
}

Action::Action(XPLMDataRef dat, int array_index, float d)
{
dataref = dat;
data_f = d;
index = array_index;
dataref_type = XPLMGetDataRefTypes(dataref);
dataref_type = xplmType_FloatArray;
}

Action::Action(XPLMDataRef dat, float _delta, float _max, float _min)
Expand Down
27 changes: 23 additions & 4 deletions src/core/ConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,25 @@ void Configparser::check_and_get_array_index(std::string& dataref, int& index)
}
}

XPLMDataTypeID Configparser::normalize_dataref_type(XPLMDataTypeID data_ref_type)
{
/* from xplane documenation:
Data types each take a bit field; it is legal to have a single dataref
be more than one type of data. When this happens, you can pick
any matching get/set API.
*/
if (data_ref_type & xplmType_Double)
return xplmType_Double;
else if (data_ref_type & xplmType_Float)
return xplmType_Float;
else if (data_ref_type & xplmType_FloatArray)
return xplmType_FloatArray;
else if (data_ref_type & xplmType_IntArray)
return xplmType_IntArray;
else
return data_ref_type;
}

int Configparser::handle_on_push_or_release(IniFileSectionHeader section_header, std::string key, std::string value, Configuration& config)
{
Action* action;
Expand Down Expand Up @@ -415,7 +434,7 @@ int Configparser::handle_on_push_or_release(IniFileSectionHeader section_header,
}
else
{
switch (XPLMGetDataRefTypes(dataRef)) {
switch (normalize_dataref_type(XPLMGetDataRefTypes(dataRef))) {
case xplmType_IntArray:
if (index < 0)
{
Expand Down Expand Up @@ -855,7 +874,7 @@ int Configparser::handle_on_fip_offset(IniFileSectionHeader section_header, std:
action->data_ref_index = index;

action->data_ref = dataRef;
action->data_ref_type = XPLMGetDataRefTypes(dataRef);
action->data_ref_type = normalize_dataref_type(XPLMGetDataRefTypes(dataRef));
}
else if (m[0] == TOKEN_LUA)
{
Expand Down Expand Up @@ -905,7 +924,7 @@ int Configparser::handle_on_fip_rotation(IniFileSectionHeader section_header, st
action->data_ref_index = index;

action->data_ref = dataRef;
action->data_ref_type = XPLMGetDataRefTypes(dataRef);
action->data_ref_type = normalize_dataref_type(XPLMGetDataRefTypes(dataRef));
}
else if (m[0] == TOKEN_LUA)
{
Expand Down Expand Up @@ -994,7 +1013,7 @@ int Configparser::handle_on_fip_text(IniFileSectionHeader section_header, std::s
return EXIT_FAILURE;
}
action->data_ref = dataRef;
action->data_ref_type = XPLMGetDataRefTypes(dataRef);
action->data_ref_type = normalize_dataref_type(XPLMGetDataRefTypes(dataRef));
action->type = SC_SET_TEXT;

Logger(logTRACE) << "config parser: add FIP text set dataref: " << action->data_ref << std::endl;
Expand Down
1 change: 1 addition & 0 deletions src/core/ConfigParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Configparser
int handle_on_fip_mask(IniFileSectionHeader section_header, std::string key, std::string value, Configuration& config);
int handle_on_fip_text(IniFileSectionHeader section_header, std::string key, std::string value, Configuration& config);

XPLMDataTypeID normalize_dataref_type(XPLMDataTypeID data_ref_type);

const std::string TOKEN_VID = "vid";
const std::string TOKEN_PID = "pid";
Expand Down
17 changes: 16 additions & 1 deletion src/core/LuaHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,22 @@ XPLMDataTypeID LuaHelper::get_dataref_type(XPLMDataRef dataref)
if (data_ref_types.count(dataref) == 0)
{
XPLMDataTypeID dataref_type = XPLMGetDataRefTypes(dataref);
data_ref_types[dataref] = dataref_type;

/* from xplane documenation:
Data types each take a bit field; it is legal to have a single dataref
be more than one type of data. When this happens, you can pick
any matching get/set API.
*/
if (dataref_type & xplmType_Double)
data_ref_types[dataref] = xplmType_Double;
else if (dataref_type & xplmType_Float)
data_ref_types[dataref] = xplmType_Float;
else if (dataref_type & xplmType_FloatArray)
data_ref_types[dataref] = xplmType_FloatArray;
else if (dataref_type & xplmType_IntArray)
data_ref_types[dataref] = xplmType_IntArray;
else
data_ref_types[dataref] = dataref_type;
}
return data_ref_types[dataref];
}
Expand Down
Loading