Fixed various type inconsistencies to remove warning when building on Windows

This commit is contained in:
Jason Watkins
2015-04-14 15:49:25 -07:00
parent 118af68620
commit 8591db96c0
9 changed files with 65 additions and 44 deletions

View File

@@ -176,7 +176,7 @@ namespace XPC
} }
} }
std::size_t DataManager::Get(std::string dref, float values[], std::size_t size) int DataManager::Get(std::string dref, float values[], int size)
{ {
XPLMDataRef& xdref = sdrefs[dref]; XPLMDataRef& xdref = sdrefs[dref];
if (xdref == nullptr) if (xdref == nullptr)
@@ -200,7 +200,7 @@ namespace XPC
{ {
case 1: // Integer case 1: // Integer
{ {
values[0] = XPLMGetDatai(xdref); values[0] = (float)XPLMGetDatai(xdref);
#if LOG_VERBOSITY > 4 #if LOG_VERBOSITY > 4
Log::FormatLine(" value was %i", (int)values[0]); Log::FormatLine(" value was %i", (int)values[0]);
#endif #endif
@@ -208,7 +208,7 @@ namespace XPC
} }
case 4: // Double case 4: // Double
{ {
values[0] = XPLMGetDatad(xdref); values[0] = (float)XPLMGetDatad(xdref);
#if LOG_VERBOSITY > 4 #if LOG_VERBOSITY > 4
Log::FormatLine(" value was %f", values[0]); Log::FormatLine(" value was %f", values[0]);
#endif #endif
@@ -233,7 +233,7 @@ namespace XPC
XPLMGetDatavi(xdref, iValues, 0, drefSize); XPLMGetDatavi(xdref, iValues, 0, drefSize);
for (int i = 0; i < drefSize; ++i) for (int i = 0; i < drefSize; ++i)
{ {
values[i] = iValues[i]; values[i] = (float)iValues[i];
} }
#if LOG_VERBOSITY > 4 #if LOG_VERBOSITY > 4
Log::FormatLine(" value count was %i", drefSize); Log::FormatLine(" value count was %i", drefSize);
@@ -281,7 +281,7 @@ namespace XPC
return value; return value;
} }
std::size_t DataManager::GetFloatArray(DREF dref, float values[], std::size_t size, std::uint8_t aircraft) int DataManager::GetFloatArray(DREF dref, float values[], int size, std::uint8_t aircraft)
{ {
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref]; const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
int resultSize = XPLMGetDatavf(xdref, values, 0, size); int resultSize = XPLMGetDatavf(xdref, values, 0, size);
@@ -291,7 +291,7 @@ namespace XPC
return resultSize; return resultSize;
} }
std::size_t DataManager::GetIntArray(DREF dref, int values[], std::size_t size, std::uint8_t aircraft) int DataManager::GetIntArray(DREF dref, int values[], int size, std::uint8_t aircraft)
{ {
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref]; const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
int resultSize = XPLMGetDatavi(xdref, values, 0, size); int resultSize = XPLMGetDatavi(xdref, values, 0, size);
@@ -328,29 +328,29 @@ namespace XPC
XPLMSetDatai(xdref, value); XPLMSetDatai(xdref, value);
} }
void DataManager::Set(DREF dref, float values[], std::size_t size, std::uint8_t aircraft) void DataManager::Set(DREF dref, float values[], int size, std::uint8_t aircraft)
{ {
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref]; const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
#if LOG_VERBOSITY > 4 #if LOG_VERBOSITY > 4
Log::FormatLine("[DMAN] Set DREF %i (x:%X) (%i values) for a/c %i", dref, xdref, size, aircraft); Log::FormatLine("[DMAN] Set DREF %i (x:%X) (%i values) for a/c %i", dref, xdref, size, aircraft);
#endif #endif
std::size_t drefSize = XPLMGetDatavf(xdref, NULL, 0, 0); int drefSize = XPLMGetDatavf(xdref, NULL, 0, 0);
drefSize = min(drefSize, size); drefSize = min(drefSize, size);
XPLMSetDatavf(xdref, values, 0, drefSize); XPLMSetDatavf(xdref, values, 0, drefSize);
} }
void DataManager::Set(DREF dref, int values[], std::size_t size, std::uint8_t aircraft) void DataManager::Set(DREF dref, int values[], int size, std::uint8_t aircraft)
{ {
const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref]; const XPLMDataRef& xdref = aircraft == 0 ? drefs[dref] : mdrefs[aircraft][dref];
#if LOG_VERBOSITY > 4 #if LOG_VERBOSITY > 4
Log::FormatLine("[DMAN] Setting DREF %i (x:%X) (%i values) for a/c %i", dref, xdref, size, aircraft); Log::FormatLine("[DMAN] Setting DREF %i (x:%X) (%i values) for a/c %i", dref, xdref, size, aircraft);
#endif #endif
std::size_t drefSize = XPLMGetDatavi(xdref, NULL, 0, 0); int drefSize = XPLMGetDatavi(xdref, NULL, 0, 0);
drefSize = min(drefSize, size); drefSize = min(drefSize, size);
XPLMSetDatavi(xdref, values, 0, drefSize); XPLMSetDatavi(xdref, values, 0, drefSize);
} }
void DataManager::Set(std::string dref, float values[], std::size_t size) void DataManager::Set(std::string dref, float values[], int size)
{ {
XPLMDataRef& xdref = sdrefs[dref]; XPLMDataRef& xdref = sdrefs[dref];
if (xdref == nullptr) if (xdref == nullptr)

View File

@@ -170,7 +170,7 @@ namespace XPC
/// doubles where high precision is required, using this method may result /// doubles where high precision is required, using this method may result
/// in a loss of precision. In that case, consider using one of the /// in a loss of precision. In that case, consider using one of the
/// strongly typed methods instead. /// strongly typed methods instead.
static std::size_t Get(std::string dref, float values[], std::size_t size); static int Get(std::string dref, float values[], int size);
/// Gets the value of a double dataref. /// Gets the value of a double dataref.
/// ///
@@ -248,7 +248,7 @@ namespace XPC
/// method, most drefs are not valid for multiplayer aircraft. All drefs /// method, most drefs are not valid for multiplayer aircraft. All drefs
/// that are not prefixed with 'MP' are valid for the player aircraft. /// that are not prefixed with 'MP' are valid for the player aircraft.
/// 'MP' drefs should be called with aircraft 0. /// 'MP' drefs should be called with aircraft 0.
static std::size_t GetFloatArray(DREF dref, float values[], std::size_t size, std::uint8_t aircraft = 0); static int GetFloatArray(DREF dref, float values[], int size, std::uint8_t aircraft = 0);
/// Gets the value of an int array dataref. /// Gets the value of an int array dataref.
@@ -270,7 +270,7 @@ namespace XPC
/// method, most drefs are not valid for multiplayer aircraft. All drefs /// method, most drefs are not valid for multiplayer aircraft. All drefs
/// that are not prefixed with 'MP' are valid for the player aircraft. /// that are not prefixed with 'MP' are valid for the player aircraft.
/// 'MP' drefs should be called with aircraft 0. /// 'MP' drefs should be called with aircraft 0.
static std::size_t GetIntArray(DREF dref, int values[], std::size_t size, std::uint8_t aircraft = 0); static int GetIntArray(DREF dref, int values[], int size, std::uint8_t aircraft = 0);
/// Sets the value of a dataref /// Sets the value of a dataref
/// ///
@@ -290,7 +290,7 @@ namespace XPC
/// doubles where high precision is required, using this method may result /// doubles where high precision is required, using this method may result
/// in a loss of precision. In that case, consider using one of the /// in a loss of precision. In that case, consider using one of the
/// strongly typed methods instead. /// strongly typed methods instead.
static void Set(std::string dref, float values[], std::size_t size); static void Set(std::string dref, float values[], int size);
/// Sets the value of a double dataref. /// Sets the value of a double dataref.
/// ///
@@ -359,7 +359,7 @@ namespace XPC
/// method, most drefs are not valid for multiplayer aircraft. All drefs /// method, most drefs are not valid for multiplayer aircraft. All drefs
/// that are not prefixed with 'MP' are valid for the player aircraft. /// that are not prefixed with 'MP' are valid for the player aircraft.
/// 'MP' drefs should be called with aircraft 0. /// 'MP' drefs should be called with aircraft 0.
static void Set(DREF dref, float values[], std::size_t size, std::uint8_t aircraft = 0); static void Set(DREF dref, float values[], int size, std::uint8_t aircraft = 0);
/// Sets the value of an integer array dataref. /// Sets the value of an integer array dataref.
/// ///
@@ -377,7 +377,7 @@ namespace XPC
/// method, most drefs are not valid for multiplayer aircraft. All drefs /// method, most drefs are not valid for multiplayer aircraft. All drefs
/// that are not prefixed with 'MP' are valid for the player aircraft. /// that are not prefixed with 'MP' are valid for the player aircraft.
/// 'MP' drefs should be called with aircraft 0. /// 'MP' drefs should be called with aircraft 0.
static void Set(DREF dref, int values[], std::size_t size, std::uint8_t aircraft = 0); static void Set(DREF dref, int values[], int size, std::uint8_t aircraft = 0);
/// Sets the landing gear for the specified airplane. /// Sets the landing gear for the specified airplane.
/// ///

View File

@@ -15,12 +15,13 @@
// without specific prior written permission from the authors or // without specific prior written permission from the authors or
// Laminar Research, respectively. // Laminar Research, respectively.
#include "Drawing.h" #include "Drawing.h"
#include "XPLMDisplay.h" #include "XPLMDisplay.h"
#include "XPLMGraphics.h" #include "XPLMGraphics.h"
#include "XPLMDataAccess.h" #include "XPLMDataAccess.h"
#include <math.h>
#include <string.h> #include <cmath>
#include <stdio.h> #include <string>
//OpenGL includes //OpenGL includes
#if IBM #if IBM
#include <windows.h> #include <windows.h>
@@ -65,13 +66,23 @@ namespace XPC
//Internal Functions //Internal Functions
static int cmp(const void * a, const void * b) static int cmp(const void * a, const void * b)
{ {
return (*(size_t*)a - *(size_t*)b); std::size_t sa = *(size_t*)a;
std::size_t sb = *(size_t*)b;
if (sa > sb)
{
return 1;
}
if (sb > sa)
{
return -1;
}
return 0;
} }
static void gl_drawCube(float x, float y, float z, float d) static void gl_drawCube(float x, float y, float z, float d)
{ {
//tan(0.25) degrees. Should scale all markers to appear about the same size //tan(0.25) degrees. Should scale all markers to appear about the same size
const float TAN = 0.00436335082070156648652885284203; const float TAN = 0.00436335F;
float h = d * TAN; float h = d * TAN;
glBegin(GL_QUAD_STRIP); glBegin(GL_QUAD_STRIP);

View File

@@ -3,9 +3,10 @@
#ifndef XPC_DRAWING_H #ifndef XPC_DRAWING_H
#define XPC_DRAWING_H #define XPC_DRAWING_H
#include <stdlib.h>
#include "xplaneConnect.h" #include "xplaneConnect.h"
#include <cstdlib>
namespace XPC namespace XPC
{ {
/// Handles tasks that involve drawing to the screen in X-Plane. /// Handles tasks that involve drawing to the screen in X-Plane.

View File

@@ -205,7 +205,7 @@ namespace XPC
float thr = *((float*)(buffer + 17)); float thr = *((float*)(buffer + 17));
std::int8_t gear = buffer[21]; std::int8_t gear = buffer[21];
float flaps = *((float*)(buffer + 22)); float flaps = *((float*)(buffer + 22));
float aircraft = 0; std::uint8_t aircraft = 0;
if (size == 27) if (size == 27)
{ {
aircraft = buffer[26]; aircraft = buffer[26];
@@ -241,7 +241,27 @@ namespace XPC
// Parse data // Parse data
const std::uint8_t* buffer = msg.GetBuffer(); const std::uint8_t* buffer = msg.GetBuffer();
std::size_t size = msg.GetSize(); std::size_t size = msg.GetSize();
std::uint8_t numCols = (size - 5) / 36; std::size_t numCols = (size - 5) / 36;
if (numCols > 0)
{
#if LOG_VERBOSITY > 3
Log::FormatLine("[DATA] Message Received (Conn %i)", connection.id);
#endif
}
if (numCols > 32) // Error. Will overflow values
{
#if LOG_VERBOSITY > 2
Log::FormatLine("[DATA] ERROR numCols to large.");
#endif
return;
}
else
{
#if LOG_VERBOSITY > 2
Log::FormatLine("[DATA] WARNING: Empty data packet received (Conn %i)", connection.id);
#endif
return;
}
float values[32][9]; float values[32][9];
for (int i = 0; i < numCols; ++i) for (int i = 0; i < numCols; ++i)
{ {
@@ -250,19 +270,6 @@ namespace XPC
} }
// Update log // Update log
#if LOG_VERBOSITY > 1
if (numCols > 0)
{
// UPDATE LOG
Log::FormatLine("[DATA] Message Received (Conn %i)", connection.id);
}
else
{
// UPDATE LOG
Log::FormatLine("[DATA] WARNING: Empty data packet received (Conn %i)", connection.id);
return;
}
#endif
float savedAlpha = -998; float savedAlpha = -998;
float savedHPath = -998; float savedHPath = -998;
@@ -449,7 +456,7 @@ namespace XPC
for (int i = 0; i < drefCount; ++i) for (int i = 0; i < drefCount; ++i)
{ {
float values[255]; float values[255];
std::size_t count = DataManager::Get(connection.getdRequest[i], values, 255); int count = DataManager::Get(connection.getdRequest[i], values, 255);
response[cur++] = count; response[cur++] = count;
memcpy(response + cur, values, count * sizeof(float)); memcpy(response + cur, values, count * sizeof(float));
cur += count * sizeof(float); cur += count * sizeof(float);

View File

@@ -141,7 +141,8 @@ namespace XPC
{ {
remoteHost = "127.0.0.1"; remoteHost = "127.0.0.1";
} }
std::uint32_t ip = inet_addr(remoteHost.c_str()); std::uint32_t ip;
inet_pton(AF_INET, remoteHost.c_str(), &ip);
SendTo(buffer, len, ip, remotePort); SendTo(buffer, len, ip, remotePort);
} }
@@ -160,7 +161,7 @@ namespace XPC
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)); setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));
buffer[4] = (std::uint8_t)len; buffer[4] = (std::uint8_t)len;
if (sendto(sock, (char*)buffer, len, 0, (const struct sockaddr *) &remoteAddr, sizeof(remoteAddr)) < 0) if (sendto(sock, (char*)buffer, (int)len, 0, (const struct sockaddr *) &remoteAddr, sizeof(remoteAddr)) < 0)
{ {
#if LOG_VERBOSITY > 0 #if LOG_VERBOSITY > 0
Log::FormatLine("[SOCK] Send failed. (remote: %s:%d)", remoteAddr, remotePort); Log::FormatLine("[SOCK] Send failed. (remote: %s:%d)", remoteAddr, remotePort);

Binary file not shown.

Binary file not shown.

View File

@@ -59,12 +59,13 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>IBM=1;XPLM200;_DEBUG;_WINDOWS;_USRDLL;XPCPLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>IBM=1;XPLM200;_DEBUG;_WINDOWS;_USRDLL;XPCPLUGIN_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>OldStyle</DebugInformationFormat> <DebugInformationFormat>OldStyle</DebugInformationFormat>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<OmitFramePointers /> <OmitFramePointers />
<FunctionLevelLinking>false</FunctionLevelLinking> <FunctionLevelLinking>false</FunctionLevelLinking>
<DisableSpecificWarnings>4996</DisableSpecificWarnings> <DisableSpecificWarnings>
</DisableSpecificWarnings>
<MinimalRebuild>false</MinimalRebuild> <MinimalRebuild>false</MinimalRebuild>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile> </ClCompile>
@@ -79,7 +80,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>IBM=1;XPLM200;_DEBUG;_WINDOWS;_USRDLL;XPCPLUGIN_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>IBM=1;XPLM200;_DEBUG;_WINDOWS;_USRDLL;XPCPLUGIN_EXPORTS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck> <SDLCheck>
</SDLCheck> </SDLCheck>
<DebugInformationFormat>OldStyle</DebugInformationFormat> <DebugInformationFormat>OldStyle</DebugInformationFormat>