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];
if (xdref == nullptr)
@@ -200,7 +200,7 @@ namespace XPC
{
case 1: // Integer
{
values[0] = XPLMGetDatai(xdref);
values[0] = (float)XPLMGetDatai(xdref);
#if LOG_VERBOSITY > 4
Log::FormatLine(" value was %i", (int)values[0]);
#endif
@@ -208,7 +208,7 @@ namespace XPC
}
case 4: // Double
{
values[0] = XPLMGetDatad(xdref);
values[0] = (float)XPLMGetDatad(xdref);
#if LOG_VERBOSITY > 4
Log::FormatLine(" value was %f", values[0]);
#endif
@@ -233,7 +233,7 @@ namespace XPC
XPLMGetDatavi(xdref, iValues, 0, drefSize);
for (int i = 0; i < drefSize; ++i)
{
values[i] = iValues[i];
values[i] = (float)iValues[i];
}
#if LOG_VERBOSITY > 4
Log::FormatLine(" value count was %i", drefSize);
@@ -281,7 +281,7 @@ namespace XPC
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];
int resultSize = XPLMGetDatavf(xdref, values, 0, size);
@@ -291,7 +291,7 @@ namespace XPC
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];
int resultSize = XPLMGetDatavi(xdref, values, 0, size);
@@ -328,29 +328,29 @@ namespace XPC
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];
#if LOG_VERBOSITY > 4
Log::FormatLine("[DMAN] Set DREF %i (x:%X) (%i values) for a/c %i", dref, xdref, size, aircraft);
#endif
std::size_t drefSize = XPLMGetDatavf(xdref, NULL, 0, 0);
int drefSize = XPLMGetDatavf(xdref, NULL, 0, 0);
drefSize = min(drefSize, size);
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];
#if LOG_VERBOSITY > 4
Log::FormatLine("[DMAN] Setting DREF %i (x:%X) (%i values) for a/c %i", dref, xdref, size, aircraft);
#endif
std::size_t drefSize = XPLMGetDatavi(xdref, NULL, 0, 0);
int drefSize = XPLMGetDatavi(xdref, NULL, 0, 0);
drefSize = min(drefSize, size);
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];
if (xdref == nullptr)

View File

@@ -170,7 +170,7 @@ namespace XPC
/// doubles where high precision is required, using this method may result
/// in a loss of precision. In that case, consider using one of the
/// 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.
///
@@ -248,7 +248,7 @@ namespace XPC
/// method, most drefs are not valid for multiplayer aircraft. All drefs
/// that are not prefixed with 'MP' are valid for the player aircraft.
/// '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.
@@ -270,7 +270,7 @@ namespace XPC
/// method, most drefs are not valid for multiplayer aircraft. All drefs
/// that are not prefixed with 'MP' are valid for the player aircraft.
/// '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
///
@@ -290,7 +290,7 @@ namespace XPC
/// doubles where high precision is required, using this method may result
/// in a loss of precision. In that case, consider using one of the
/// 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.
///
@@ -359,7 +359,7 @@ namespace XPC
/// method, most drefs are not valid for multiplayer aircraft. All drefs
/// that are not prefixed with 'MP' are valid for the player aircraft.
/// '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.
///
@@ -377,7 +377,7 @@ namespace XPC
/// method, most drefs are not valid for multiplayer aircraft. All drefs
/// that are not prefixed with 'MP' are valid for the player aircraft.
/// '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.
///

View File

@@ -15,12 +15,13 @@
// without specific prior written permission from the authors or
// Laminar Research, respectively.
#include "Drawing.h"
#include "XPLMDisplay.h"
#include "XPLMGraphics.h"
#include "XPLMDataAccess.h"
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <string>
//OpenGL includes
#if IBM
#include <windows.h>
@@ -65,13 +66,23 @@ namespace XPC
//Internal Functions
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)
{
//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;
glBegin(GL_QUAD_STRIP);

View File

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

View File

@@ -205,7 +205,7 @@ namespace XPC
float thr = *((float*)(buffer + 17));
std::int8_t gear = buffer[21];
float flaps = *((float*)(buffer + 22));
float aircraft = 0;
std::uint8_t aircraft = 0;
if (size == 27)
{
aircraft = buffer[26];
@@ -241,7 +241,27 @@ namespace XPC
// Parse data
const std::uint8_t* buffer = msg.GetBuffer();
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];
for (int i = 0; i < numCols; ++i)
{
@@ -250,19 +270,6 @@ namespace XPC
}
// 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 savedHPath = -998;
@@ -449,7 +456,7 @@ namespace XPC
for (int i = 0; i < drefCount; ++i)
{
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;
memcpy(response + cur, values, count * sizeof(float));
cur += count * sizeof(float);

View File

@@ -141,7 +141,8 @@ namespace XPC
{
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);
}
@@ -160,7 +161,7 @@ namespace XPC
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));
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
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>
<WarningLevel>Level3</WarningLevel>
<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>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<OmitFramePointers />
<FunctionLevelLinking>false</FunctionLevelLinking>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
<DisableSpecificWarnings>
</DisableSpecificWarnings>
<MinimalRebuild>false</MinimalRebuild>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
@@ -79,7 +80,7 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<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>
<DebugInformationFormat>OldStyle</DebugInformationFormat>