diff --git a/include/XPCAircraft.h b/include/XPCAircraft.h new file mode 100644 index 000000000..20ffb8543 --- /dev/null +++ b/include/XPCAircraft.h @@ -0,0 +1,35 @@ +#ifndef _XPCAircraft_h_ +#define _XPCAircraft_h_ + +#include + +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 diff --git a/src/PlatformUtils.h b/src/PlatformUtils.h index 4c032cfa2..e94219cef 100644 --- a/src/PlatformUtils.h +++ b/src/PlatformUtils.h @@ -23,6 +23,8 @@ #ifndef _PlatformUtils_h_ #define _PlatformUtils_h_ +#error who uses this? + /* * PlatformUtils * diff --git a/src/XOGLUtils.cpp b/src/XOGLUtils.cpp index 45c708820..99e6d0e43 100644 --- a/src/XOGLUtils.cpp +++ b/src/XOGLUtils.cpp @@ -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) diff --git a/src/XPCAircraft.cpp b/src/XPCAircraft.cpp new file mode 100644 index 000000000..ab8d97103 --- /dev/null +++ b/src/XPCAircraft.cpp @@ -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(this)); +} + +XPCAircraft::~XPCAircraft() +{ + XPMPDestroyPlane(mPlane); +} + +XPMPPlaneCallbackResult XPCAircraft::AircraftCB( + XPMPPlaneID inPlane, + XPMPPlaneDataType inDataType, + void * ioData, + void * inRefcon) +{ + XPCAircraft * me = reinterpret_cast(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; + } +} diff --git a/src/XPMPMultiplayer.cpp b/src/XPMPMultiplayer.cpp index 01ae700a3..e2185ff10 100644 --- a/src/XPMPMultiplayer.cpp +++ b/src/XPMPMultiplayer.cpp @@ -38,7 +38,7 @@ #include "XPLMUtilities.h" #include "XOGLUtils.h" -#include "PlatformUtils.h" +//#include "PlatformUtils.h" #include #include diff --git a/src/XPMPMultiplayerCSL.cpp b/src/XPMPMultiplayerCSL.cpp index 860e6b54a..11a6775eb 100644 --- a/src/XPMPMultiplayerCSL.cpp +++ b/src/XPMPMultiplayerCSL.cpp @@ -27,7 +27,7 @@ #include "XOGLUtils.h" #include #include -#include "PlatformUtils.h" +//#include "PlatformUtils.h" #include #include @@ -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 +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 inStr(CFStringCreateWithCString(kCFAllocatorDefault, path ,kCFStringEncodingMacRoman)); + if (inStr == NULL) return -1; + + CFSmartPtr url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, inStr, kCFURLPOSIXPathStyle,0)); + if (url == NULL) return -1; + + CFSmartPtr 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 inStr(CFStringCreateWithCString(kCFAllocatorDefault, path ,kCFStringEncodingMacRoman)); + if (inStr == NULL) return -1; + + CFSmartPtr url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, inStr, kCFURLHFSPathStyle,0)); + if (url == NULL) return -1; + + CFSmartPtr 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 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); } diff --git a/src/XPMPMultiplayerCSL.h b/src/XPMPMultiplayerCSL.h index e9400b336..b5c72bce4 100644 --- a/src/XPMPMultiplayerCSL.h +++ b/src/XPMPMultiplayerCSL.h @@ -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 */ diff --git a/src/XPMPMultiplayerObj.cpp b/src/XPMPMultiplayerObj.cpp index 036ce2016..ed0c1a6c0 100644 --- a/src/XPMPMultiplayerObj.cpp +++ b/src/XPMPMultiplayerObj.cpp @@ -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 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"; diff --git a/src/XUtils.cpp b/src/XUtils.cpp index 356c3fcec..28ecfe393 100644 --- a/src/XUtils.cpp +++ b/src/XUtils.cpp @@ -25,7 +25,7 @@ #include #include "XObjDefs.h" #include -#include "PlatformUtils.h" +//#include "PlatformUtils.h" //#include #include #include @@ -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) diff --git a/src/XUtils.h b/src/XUtils.h index 71ebc2655..843e98d02 100644 --- a/src/XUtils.h +++ b/src/XUtils.h @@ -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& chances); bool RollDice(double inProb);