From 28e2b16607e3e81e94bf18ff90ddf41314f92555 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 24 Jun 2014 18:45:15 +0100 Subject: [PATCH] [swift] refactored initialization into legacy and nextgen parts --- include/XPMPMultiplayer.h | 55 ++++++++++++++++++++++++++++++++++++--- src/XPMPMultiplayer.cpp | 39 ++++++++++++++++++++++----- 2 files changed, 84 insertions(+), 10 deletions(-) diff --git a/include/XPMPMultiplayer.h b/include/XPMPMultiplayer.h index 53e530ac8..6916f8636 100644 --- a/include/XPMPMultiplayer.h +++ b/include/XPMPMultiplayer.h @@ -227,9 +227,9 @@ typedef XPMPPlaneCallbackResult (* XPMPPlaneData_f)( void * inRefcon); /* - * XPMPMultiplayerInit + * XPMPMultiplayerInitLegacyData * - * This routine initializes the multiplayer library. + * This routine initializes legacy portions of the multiplayer library. * * inPlaneList is a ptr to a fully qualified file name that is a text file of ICAO -> model * mappings. The xsb_aircraft.txt file can be used as a template. (Please note: other @@ -252,8 +252,13 @@ typedef XPMPPlaneCallbackResult (* XPMPPlaneData_f)( * * Call this once from your XPluginStart routine. * + * Depending on which plane packages are installed this can take between 30 seconds and 15 minutes. + * + * After transitioning to exclusively OBJ8-based packages, this function should no longer be required. + * Instead, make separate calls to XPMPLoadCSLPackages and XPMPSetDefaultPlaneICAO. + * */ -const char * XPMPMultiplayerInit( +const char * XPMPMultiplayerInitLegacyData( const char * inCSLFolder, const char * inRelatedPath, const char * inTexturePath, @@ -262,6 +267,27 @@ const char * XPMPMultiplayerInit( int (* inIntPrefsFunc)(const char *, const char *, int), float (* inFloatPrefsFunc)(const char *, const char *, float)); +/* + * XPMPMultiplayerInit + * + * The two prefs funcs each take an ini section and key and return a value and also take + * a default. The renderer uses them for configuration. Currently the following keys are + * needed: + * + * section key type default description + * planes full_distance float 3.0 + * planes max_full_count int 50 + * + * The return value is a string indicating any problem that may have gone wrong in a human-readable + * form, or an empty string if initalizatoin was okay. + * + * Call this once, typically from your XPluginStart routine. + * + */ +const char * XPMPMultiplayerInit( + int (* inIntPrefsFunc)(const char *, const char *, int), + float (* inFloatPrefsFunc)(const char *, const char *, float)); + /* * XPMPMultiplayerEnable * @@ -288,6 +314,29 @@ void XPMPMultiplayerDisable(void); */ void XPMPMultiplayerCleanup(void); +/* + * XPMPLoadCSLPackage + * + * Loads a collection of planes + * + * inPlaneList is a ptr to a fully qualified file name that is a text file of ICAO -> model + * mappings. The xsb_aircraft.txt file can be used as a template. (Please note: other + * XSB files are NOT necessary and are not necessarily available under open source license.) + * + * inDoc8643 is the path to the ICAO document 8643, available at + * http://www.icao.int/anb/ais/TxtFiles/Doc8643.txt. This file lists all aircraft types + * with their manufacturer, ICAO equipment code and aircraft category. + * + * This is fast if the planes are all OBJ8 (because the objects are loaded asynchronously, + * on demand), otherwise it could take several seconds or minutes depending on the quantity + * and fidelity of the planes. + * + */ +const char * XPMPLoadCSLPackage( + const char * inCSLFolder, + const char * inRelatedPath, + const char * inDoc8643); + /* * XPMPLoadPlanesIfNecessary * diff --git a/src/XPMPMultiplayer.cpp b/src/XPMPMultiplayer.cpp index d39bb4c0d..6601e915e 100644 --- a/src/XPMPMultiplayer.cpp +++ b/src/XPMPMultiplayer.cpp @@ -104,7 +104,7 @@ static int XPMPControlPlaneCount( ********************************************************************************/ -const char * XPMPMultiplayerInit( +const char * XPMPMultiplayerInitLegacyData( const char * inCSLFolder, const char * inRelatedPath, const char * inTexturePath, const char * inDoc8643, const char * inDefaultPlane, @@ -114,6 +114,25 @@ const char * XPMPMultiplayerInit( gDefaultPlane = inDefaultPlane; gIntPrefsFunc = inIntPrefsFunc; gFloatPrefsFunc = inFloatPrefsFunc; + + bool problem = false; + + if (!CSL_LoadCSL(inCSLFolder, inRelatedPath, inDoc8643)) + problem = true; + + if (!CSL_Init(inTexturePath)) + problem = true; + + if (problem) return "There were problems initializing XSquawkBox. Please examine X-Plane's error.out file for detailed information."; + else return ""; +} + +const char * XPMPMultiplayerInit( + int (* inIntPrefsFunc)(const char *, const char *, int), + float (* inFloatPrefsFunc)(const char *, const char *, float)) +{ + gIntPrefsFunc = inIntPrefsFunc; + gFloatPrefsFunc = inFloatPrefsFunc; //char myPath[1024]; //char airPath[1024]; //char line[256]; @@ -127,14 +146,8 @@ const char * XPMPMultiplayerInit( // Initialize our OpenGL Utilities OGL_UtilsInit(); - if (!CSL_LoadCSL(inCSLFolder, inRelatedPath, inDoc8643)) - problem = true; - XPMPInitDefaultPlaneRenderer(); - if (!CSL_Init(inTexturePath)) - problem = true; - // Register the plane control calls. XPLMRegisterDrawCallback(XPMPControlPlaneCount, xplm_Phase_Gauges, 0, /* after*/ 0 /* hide planes*/); @@ -223,6 +236,18 @@ void XPMPMultiplayerDisable(void) } +const char * XPMPLoadCSLPackage( + const char * inCSLFolder, const char * inRelatedPath, const char * inDoc8643) +{ + bool problem = false; + + if (!CSL_LoadCSL(inCSLFolder, inRelatedPath, inDoc8643)) + problem = true; + + if (problem) return "There were problems initializing XSquawkBox. Please examine X-Plane's error.out file for detailed information."; + else return ""; +} + // This routine checks plane loading and grabs anyone we're missing. void XPMPLoadPlanesIfNecessary(void) {