mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 06:45:37 +08:00
initial commit: 64-bit clean libxplanemp for mac. uses newer APIs to avoid deprecations.
This commit is contained in:
35
include/XPCAircraft.h
Normal file
35
include/XPCAircraft.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef _XPCAircraft_h_
|
||||
#define _XPCAircraft_h_
|
||||
|
||||
#include <XPMPMultiplayer.h>
|
||||
|
||||
class XPCAircraft {
|
||||
public:
|
||||
|
||||
XPCAircraft(
|
||||
const char * inICAOCode,
|
||||
const char * inAirline,
|
||||
const char * inLivery);
|
||||
virtual ~XPCAircraft();
|
||||
|
||||
virtual XPMPPlaneCallbackResult GetPlanePosition(
|
||||
XPMPPlanePosition_t * outPosition)=0;
|
||||
|
||||
virtual XPMPPlaneCallbackResult GetPlaneSurfaces(
|
||||
XPMPPlaneSurfaces_t * outSurfaces)=0;
|
||||
|
||||
virtual XPMPPlaneCallbackResult GetPlaneRadar(
|
||||
XPMPPlaneRadar_t * outRadar)=0;
|
||||
protected:
|
||||
|
||||
XPMPPlaneID mPlane;
|
||||
|
||||
static XPMPPlaneCallbackResult AircraftCB(
|
||||
XPMPPlaneID inPlane,
|
||||
XPMPPlaneDataType inDataType,
|
||||
void * ioData,
|
||||
void * inRefcon);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -23,6 +23,8 @@
|
||||
#ifndef _PlatformUtils_h_
|
||||
#define _PlatformUtils_h_
|
||||
|
||||
#error who uses this?
|
||||
|
||||
/*
|
||||
* PlatformUtils
|
||||
*
|
||||
|
||||
@@ -46,48 +46,62 @@ Nasty Mac Specific Stuff to Load OGL DLL Extensions
|
||||
|
||||
CFBundleRef gBundleRefOpenGL = NULL;
|
||||
|
||||
|
||||
// Utility routine to get a bundle from the system folder by file name....typically used to find OpenGL to get extension functions.
|
||||
int load_bundle_by_filename (const char * in_filename, CFBundleRef * io_bundle_ref)
|
||||
{
|
||||
OSStatus err = noErr;
|
||||
FSRef framework_fs;
|
||||
CFURLRef framework_url = NULL;
|
||||
CFURLRef bundle_url = NULL;
|
||||
CFStringRef bundle_name = NULL;
|
||||
CFBundleRef bundle_ref = NULL;
|
||||
|
||||
bundle_name = CFStringCreateWithCString(kCFAllocatorDefault, in_filename, kCFStringEncodingUTF8);
|
||||
if (bundle_name == NULL) {
|
||||
err = paramErr;
|
||||
goto bail; }
|
||||
|
||||
err = FSFindFolder(kSystemDomain, kFrameworksFolderType, false, &framework_fs);
|
||||
if (noErr != err) {
|
||||
err = dirNFErr;
|
||||
goto bail; }
|
||||
|
||||
// create URL to folder
|
||||
framework_url = CFURLCreateFromFSRef (kCFAllocatorDefault, &framework_fs);
|
||||
if(framework_url == NULL) {
|
||||
err = ioErr;
|
||||
goto bail; }
|
||||
|
||||
bundle_url = CFURLCreateWithFileSystemPathRelativeToBase(kCFAllocatorDefault, bundle_name, kCFURLPOSIXPathStyle, false, framework_url);
|
||||
if(bundle_url == NULL) {
|
||||
err = fnfErr;
|
||||
goto bail; }
|
||||
|
||||
bundle_ref = CFBundleCreate (kCFAllocatorDefault, bundle_url);
|
||||
if(bundle_ref == NULL) {
|
||||
err = permErr;
|
||||
goto bail; }
|
||||
|
||||
if (!CFBundleLoadExecutable (bundle_ref)) {
|
||||
err = bdNamErr;
|
||||
goto bail;
|
||||
}
|
||||
|
||||
if (io_bundle_ref) { *io_bundle_ref = bundle_ref; bundle_ref = NULL; }
|
||||
bail:
|
||||
if(bundle_ref) CFRelease(bundle_ref);
|
||||
if(bundle_name) CFRelease(bundle_name);
|
||||
if(bundle_url) CFRelease(bundle_url);
|
||||
if(framework_url) CFRelease(framework_url);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
OSStatus aglInitEntryPoints (void)
|
||||
{
|
||||
OSStatus err = noErr;
|
||||
const Str255 frameworkName = "\pOpenGL.framework";
|
||||
FSRefParam fileRefParam;
|
||||
FSRef fileRef;
|
||||
CFURLRef bundleURLOpenGL;
|
||||
|
||||
memset(&fileRefParam, 0, sizeof(fileRefParam));
|
||||
memset(&fileRef, 0, sizeof(fileRef));
|
||||
|
||||
fileRefParam.ioNamePtr = frameworkName;
|
||||
fileRefParam.newRef = &fileRef;
|
||||
|
||||
// Frameworks directory/folder
|
||||
err = FindFolder (kSystemDomain, kFrameworksFolderType, false,
|
||||
&fileRefParam.ioVRefNum, (SInt32 *) &fileRefParam.ioDirID);
|
||||
if (noErr != err) {
|
||||
return err;
|
||||
}
|
||||
err = PBMakeFSRefSync (&fileRefParam); // make FSRef for folder
|
||||
if (noErr != err) {
|
||||
return err;
|
||||
}
|
||||
// create URL to folder
|
||||
bundleURLOpenGL = CFURLCreateFromFSRef (kCFAllocatorDefault,
|
||||
&fileRef);
|
||||
if (!bundleURLOpenGL) {
|
||||
return paramErr;
|
||||
}
|
||||
// create ref to GL's bundle
|
||||
gBundleRefOpenGL = CFBundleCreate (kCFAllocatorDefault,
|
||||
bundleURLOpenGL);
|
||||
if (!gBundleRefOpenGL) {
|
||||
return paramErr;
|
||||
}
|
||||
CFRelease (bundleURLOpenGL); // release created bundle
|
||||
// if the code was successfully loaded, look for our function.
|
||||
if (!CFBundleLoadExecutable (gBundleRefOpenGL)) {
|
||||
return paramErr;
|
||||
}
|
||||
return err;
|
||||
return load_bundle_by_filename ("OpenGL.framework", &gBundleRefOpenGL);
|
||||
}
|
||||
|
||||
void * aglGetProcAddress (char * pszProc)
|
||||
|
||||
34
src/XPCAircraft.cpp
Normal file
34
src/XPCAircraft.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "XPCAircraft.h"
|
||||
|
||||
XPCAircraft::XPCAircraft(
|
||||
const char * inICAOCode,
|
||||
const char * inAirline,
|
||||
const char * inLivery)
|
||||
{
|
||||
mPlane = XPMPCreatePlane(inICAOCode, inAirline, inLivery, AircraftCB,
|
||||
reinterpret_cast<void *>(this));
|
||||
}
|
||||
|
||||
XPCAircraft::~XPCAircraft()
|
||||
{
|
||||
XPMPDestroyPlane(mPlane);
|
||||
}
|
||||
|
||||
XPMPPlaneCallbackResult XPCAircraft::AircraftCB(
|
||||
XPMPPlaneID inPlane,
|
||||
XPMPPlaneDataType inDataType,
|
||||
void * ioData,
|
||||
void * inRefcon)
|
||||
{
|
||||
XPCAircraft * me = reinterpret_cast<XPCAircraft *>(inRefcon);
|
||||
switch(inDataType) {
|
||||
case xpmpDataType_Position:
|
||||
return me->GetPlanePosition((XPMPPlanePosition_t *) ioData);
|
||||
case xpmpDataType_Surfaces:
|
||||
return me->GetPlaneSurfaces((XPMPPlaneSurfaces_t *) ioData);
|
||||
case xpmpDataType_Radar:
|
||||
return me->GetPlaneRadar((XPMPPlaneRadar_t *) ioData);
|
||||
default:
|
||||
return xpmpData_Unavailable;
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@
|
||||
#include "XPLMUtilities.h"
|
||||
|
||||
#include "XOGLUtils.h"
|
||||
#include "PlatformUtils.h"
|
||||
//#include "PlatformUtils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "XOGLUtils.h"
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include "PlatformUtils.h"
|
||||
//#include "PlatformUtils.h"
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -38,7 +38,7 @@ using std::max;
|
||||
#endif
|
||||
|
||||
// Set this to 1 to get TONS of diagnostics on what the lib is doing.
|
||||
#define DEBUG_CSL_LOADING 0
|
||||
#define DEBUG_CSL_LOADING 1
|
||||
|
||||
// Set this to 1 to cause AIRLINE and LIVERY to create ICAO codes automatically
|
||||
#define USE_DEFAULTING 0
|
||||
@@ -53,11 +53,62 @@ enum {
|
||||
* UTILITY ROUTINES
|
||||
************************************************************************/
|
||||
|
||||
#if APL
|
||||
|
||||
template <typename T>
|
||||
struct CFSmartPtr {
|
||||
CFSmartPtr(T p) : p_(p) { }
|
||||
~CFSmartPtr() { if (p_) CFRelease(p_); }
|
||||
operator T () { return p_; }
|
||||
T p_;
|
||||
};
|
||||
|
||||
int Posix2HFSPath(const char *path, char *result, int resultLen)
|
||||
{
|
||||
CFSmartPtr<CFStringRef> inStr(CFStringCreateWithCString(kCFAllocatorDefault, path ,kCFStringEncodingMacRoman));
|
||||
if (inStr == NULL) return -1;
|
||||
|
||||
CFSmartPtr<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, inStr, kCFURLPOSIXPathStyle,0));
|
||||
if (url == NULL) return -1;
|
||||
|
||||
CFSmartPtr<CFStringRef> outStr(CFURLCopyFileSystemPath(url, kCFURLHFSPathStyle));
|
||||
if (outStr == NULL) return -1;
|
||||
|
||||
if (!CFStringGetCString(outStr, result, resultLen, kCFStringEncodingMacRoman))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int HFS2PosixPath(const char *path, char *result, int resultLen)
|
||||
{
|
||||
bool is_dir = (path[strlen(path)-1] == ':');
|
||||
|
||||
CFSmartPtr<CFStringRef> inStr(CFStringCreateWithCString(kCFAllocatorDefault, path ,kCFStringEncodingMacRoman));
|
||||
if (inStr == NULL) return -1;
|
||||
|
||||
CFSmartPtr<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, inStr, kCFURLHFSPathStyle,0));
|
||||
if (url == NULL) return -1;
|
||||
|
||||
CFSmartPtr<CFStringRef> outStr(CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle));
|
||||
if (outStr == NULL) return -1;
|
||||
|
||||
if (!CFStringGetCString(outStr, result, resultLen, kCFStringEncodingMacRoman))
|
||||
return -1;
|
||||
|
||||
if(is_dir) strcat(result, "/");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void MakePartialPathNativeObj(string& io_str)
|
||||
{
|
||||
vector<char> chars(io_str.begin(),io_str.end());
|
||||
MakePartialPathNative(&*chars.begin(),&*chars.begin()+chars.size());
|
||||
io_str=string(chars.begin(),chars.end());
|
||||
// char sep = *XPLMGetDirectorySeparator();
|
||||
for(int i = 0; i < io_str.size(); ++i)
|
||||
if(io_str[i] == '/' || io_str[i] == ':' || io_str[i] == '\\')
|
||||
io_str[i] = '/';
|
||||
}
|
||||
|
||||
struct XPLMDump {
|
||||
@@ -220,13 +271,14 @@ bool LoadOnePackage(const string& inPath, int pass)
|
||||
int sim, xplm;
|
||||
XPLMHostApplicationID host;
|
||||
|
||||
#ifdef DEBUG_CSL_LOADING
|
||||
#if DEBUG_CSL_LOADING
|
||||
XPLMDump() << "LoadOnePackage was passed inPath of: " << inPath << ".\n";
|
||||
#endif
|
||||
// First locate and attempt to load the xsb_aircraft.txt file from th is package.
|
||||
string path(inPath);
|
||||
path += (DIR_STR "xsb_aircraft.txt");
|
||||
#ifdef DEBUG_CSL_LOADING
|
||||
path += "/"; //XPLMGetDirectorySeparator();
|
||||
path += "xsb_aircraft.txt";
|
||||
#if DEBUG_CSL_LOADING
|
||||
XPLMDump() << "LoadOnePackage attempting to open: " << path << ".\n";
|
||||
#endif
|
||||
|
||||
@@ -632,7 +684,7 @@ bool CSL_LoadCSL(const char * inFolderPath, const char * inRelatedFile, const ch
|
||||
|
||||
char * name_buf = (char *) malloc(16384);
|
||||
char ** index_buf = (char **) malloc(65536);
|
||||
long total, ret;
|
||||
int total, ret;
|
||||
|
||||
char folder[1024];
|
||||
|
||||
@@ -653,7 +705,7 @@ bool CSL_LoadCSL(const char * inFolderPath, const char * inRelatedFile, const ch
|
||||
#endif
|
||||
char * foo = index_buf[r];
|
||||
string path(inFolderPath);
|
||||
path += DIR_STR;
|
||||
path += "/";//XPLMGetDirectorySeparator();
|
||||
path += foo;
|
||||
pckgs.push_back(path);
|
||||
}
|
||||
|
||||
@@ -104,4 +104,9 @@ void CSL_DrawObject(
|
||||
XPLMPlaneDrawState_t * state);
|
||||
|
||||
|
||||
#if APL
|
||||
int Posix2HFSPath(const char *path, char *result, int resultLen);
|
||||
int HFS2PosixPath(const char *path, char *result, int resultLen);
|
||||
#endif
|
||||
|
||||
#endif /* XPLMMULTIPLAYERCSL_H */
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "XPMPMultiplayerObj.h"
|
||||
#include "XPMPMultiplayerVars.h"
|
||||
|
||||
#include "PlatformUtils.h"
|
||||
//#include "PlatformUtils.h"
|
||||
#include "XObjReadWrite.h"
|
||||
#include "TexUtils.h"
|
||||
#include "XOGLUtils.h"
|
||||
@@ -59,9 +59,10 @@ static int sLightTexture = -1;
|
||||
|
||||
static void MakePartialPathNativeObj(string& io_str)
|
||||
{
|
||||
vector<char> chars(io_str.begin(),io_str.end());
|
||||
MakePartialPathNative(&*chars.begin(),&*chars.begin()+chars.size());
|
||||
io_str=string(chars.begin(),chars.end());
|
||||
// char sep = *XPLMGetDirectorySeparator();
|
||||
for(int i = 0; i < io_str.size(); ++i)
|
||||
if(io_str[i] == '/' || io_str[i] == ':' || io_str[i] == '\\')
|
||||
io_str[i] = '/';
|
||||
}
|
||||
|
||||
static XPLMDataRef sFOVRef = XPLMFindDataRef("sim/graphics/view/field_of_view_deg");
|
||||
@@ -339,14 +340,14 @@ int OBJ_LoadModel(const char * inFilePath)
|
||||
|
||||
sObjects.back().path = path;
|
||||
string tex_path(path);
|
||||
string::size_type p = tex_path.find_last_of(DIR_STR);
|
||||
string::size_type p = tex_path.find_last_of("\\:/");//XPLMGetDirectorySeparator());
|
||||
tex_path.erase(p+1);
|
||||
tex_path += sObjects.back().obj.texture;
|
||||
tex_path += ".png";
|
||||
sObjects.back().texnum = OBJ_LoadTexture(tex_path.c_str(), false);
|
||||
|
||||
tex_path = path;
|
||||
p = tex_path.find_last_of(DIR_STR);
|
||||
p = tex_path.find_last_of("\\:/");//XPLMGetDirectorySeparator());
|
||||
tex_path.erase(p+1);
|
||||
tex_path += sObjects.back().obj.texture;
|
||||
tex_path += "_LIT.png";
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <ctype.h>
|
||||
#include "XObjDefs.h"
|
||||
#include <stdlib.h>
|
||||
#include "PlatformUtils.h"
|
||||
//#include "PlatformUtils.h"
|
||||
//#include <time.h>
|
||||
#include <map>
|
||||
#include <math.h>
|
||||
@@ -256,7 +256,7 @@ double RandRangeBias(double mmin, double mmax, double biasRatio, double randomAm
|
||||
return RandRange(mmin + span * lower_rat,mmin + span * upper_rat);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
void StripPath(string& ioPath)
|
||||
{
|
||||
string::size_type sep = ioPath.rfind(DIR_CHAR);
|
||||
@@ -281,7 +281,7 @@ void ExtractPath(string& ioPath)
|
||||
if (sep != ioPath.npos)
|
||||
ioPath = ioPath.substr(0, sep);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if APL
|
||||
|
||||
#if !defined(XUTILS_EXCLUDE_MAC_CRAP)
|
||||
|
||||
@@ -66,9 +66,9 @@ bool GetNextNoComments(StTextFileScanner& f, string& s);
|
||||
// unit is also rather questionable.
|
||||
double GetObjRadius(const XObj& inObj);
|
||||
|
||||
void StripPath(string& ioPath);
|
||||
void StripPathCP(string& ioPath);
|
||||
void ExtractPath(string& ioPath);
|
||||
//void StripPath(string& ioPath);
|
||||
//void StripPathCP(string& ioPath);
|
||||
//void ExtractPath(string& ioPath);
|
||||
|
||||
int PickRandom(vector<double>& chances);
|
||||
bool RollDice(double inProb);
|
||||
|
||||
Reference in New Issue
Block a user