mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 18:25:37 +08:00
Remove obsolete method LoadOnePackage
This commit is contained in:
committed by
Mathew Sutcliffe
parent
cf3d527457
commit
b661443053
@@ -276,8 +276,6 @@ void BreakStringPvt(const char * inString, std::vector<std::string>& outStrings,
|
||||
* CSL LOADING
|
||||
************************************************************************/
|
||||
|
||||
static bool LoadOnePackage(const string& inPath, int pass);
|
||||
|
||||
bool CSL_Init(
|
||||
const char* inTexturePath)
|
||||
{
|
||||
@@ -759,445 +757,6 @@ void ParseFullPackage(const std::string &content, CSLPackage_t &package)
|
||||
}
|
||||
}
|
||||
|
||||
// This routine loads one CSL package.
|
||||
bool LoadOnePackage(const string& inPath, int pass)
|
||||
{
|
||||
string group, icao, livery, airline;
|
||||
bool parse_err = false;
|
||||
char line[1024*4];
|
||||
int sim, xplm;
|
||||
XPLMHostApplicationID host;
|
||||
|
||||
#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 += "/"; //XPLMGetDirectorySeparator();
|
||||
path += "xsb_aircraft.txt";
|
||||
#if DEBUG_CSL_LOADING
|
||||
XPLMDump() << "LoadOnePackage attempting to open: " << path << ".\n";
|
||||
#endif
|
||||
|
||||
FILE * fi = fopen(path.c_str(), "r");
|
||||
|
||||
XPLMGetVersions(&sim, &xplm, &host);
|
||||
|
||||
if (fi != NULL)
|
||||
{
|
||||
if (pass == pass_Load)
|
||||
XPLMDump() << "xbus: Loading package: " << path << "\n";
|
||||
|
||||
if (pass == pass_Load)
|
||||
gPackages.push_back(CSLPackage_t());
|
||||
CSLPackage_t * pckg = (pass == pass_Load) ? &gPackages.back() : NULL;
|
||||
if (pass == pass_Load)
|
||||
pckg->name = path;
|
||||
|
||||
std::vector<std::string> tokens;
|
||||
|
||||
// BEN SEZ: we need to understand why thsi hack would be needed!
|
||||
// I dont know why - but this seems to fix a Linux STL issue, somehow -Martin
|
||||
// tokens.push_back("");
|
||||
// tokens.push_back("");
|
||||
// tokens.push_back("");
|
||||
// tokens.push_back("");
|
||||
// tokens.push_back("");
|
||||
|
||||
// Go through the file and handle each token.
|
||||
int lineNum = 0;
|
||||
while(!feof(fi))
|
||||
{
|
||||
if (!fgets_multiplatform(line, sizeof(line), fi))
|
||||
break;
|
||||
++lineNum;
|
||||
|
||||
if (line[0] == '#') continue;
|
||||
|
||||
char * p = line;
|
||||
while (*p)
|
||||
{
|
||||
if (*p == '\n' || *p == '\r') *p = 0;
|
||||
++p;
|
||||
}
|
||||
|
||||
BreakStringPvt(line, tokens, 4, " \t\r\n");
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// PACKAGE MANAGEMENT
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
// EXPORT_NAME <package name>
|
||||
if (!tokens.empty() && tokens[0] == "EXPORT_NAME" && pass == pass_Depend)
|
||||
{
|
||||
if (tokens.size() == 2)
|
||||
{
|
||||
if (gPackageNames.count(tokens[1]) == 0)
|
||||
{
|
||||
gPackageNames[tokens[1]] = inPath;
|
||||
} else {
|
||||
//parse_err = true; // warning, not error
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: Package name " << tokens[1].c_str() << " already in use by "<< gPackageNames[tokens[1]].c_str() << " reqested by use by " << inPath.c_str() << "'\n";
|
||||
}
|
||||
} else {
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: EXPORT_NAME command requires 1 argument.\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// DEPENDENCY <package name>
|
||||
if (!tokens.empty() && tokens[0] == "DEPENDENCY" && pass == pass_Load)
|
||||
{
|
||||
if (tokens.size() == 2)
|
||||
{
|
||||
if (gPackageNames.count(tokens[1]) == 0)
|
||||
{
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: required package " << tokens[1] << " not found. Aborting processing of this package.\n";
|
||||
fclose(fi);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: DEPENDENCY command needs 1 argument.\n";
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// AUSTIN OLD SCHOOL ACFS
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
// AIRCAFT <min> <max> <path>
|
||||
if (!tokens.empty() && tokens[0] == "AIRCRAFT" && pass == pass_Load)
|
||||
{
|
||||
if (tokens.size() == 4)
|
||||
{
|
||||
if (sim >= atoi(tokens[1].c_str()) &&
|
||||
sim <= atoi(tokens[2].c_str()))
|
||||
{
|
||||
std::string fullPath = tokens[3];
|
||||
MakePartialPathNativeObj(fullPath);
|
||||
if (!DoPackageSub(fullPath))
|
||||
{
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: package not found.\n";
|
||||
parse_err = true;
|
||||
}
|
||||
pckg->planes.push_back(CSLPlane_t());
|
||||
pckg->planes.back().plane_type = plane_Austin;
|
||||
pckg->planes.back().file_path = fullPath;
|
||||
pckg->planes.back().moving_gear = true;
|
||||
pckg->planes.back().austin_idx = -1;
|
||||
#if DEBUG_CSL_LOADING
|
||||
XPLMDebugString(" Got Airplane: ");
|
||||
XPLMDebugString(fullPath.c_str());
|
||||
XPLMDebugString("\n");
|
||||
#endif
|
||||
|
||||
}
|
||||
} else {
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: AIRCRAFT command takes 3 arguments.\n";
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// OBJ7 DRAWN WITH OUR CODE
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
// OBJECT <filename>
|
||||
if (!tokens.empty() && tokens[0] == "OBJECT" && pass == pass_Load)
|
||||
{
|
||||
BreakStringPvt(line, tokens, 2, " \t\r\n");
|
||||
if (tokens.size() == 2)
|
||||
{
|
||||
std::string fullPath = tokens[1];
|
||||
MakePartialPathNativeObj(fullPath);
|
||||
if (!DoPackageSub(fullPath))
|
||||
{
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: package not found.\n";
|
||||
parse_err = true;
|
||||
}
|
||||
pckg->planes.push_back(CSLPlane_t());
|
||||
pckg->planes.back().plane_type = plane_Obj;
|
||||
pckg->planes.back().file_path = fullPath;
|
||||
pckg->planes.back().moving_gear = true;
|
||||
pckg->planes.back().texID = 0;
|
||||
pckg->planes.back().texLitID = 0;
|
||||
pckg->planes.back().obj_idx = OBJ_LoadModel(fullPath.c_str());
|
||||
if (pckg->planes.back().obj_idx == -1)
|
||||
{
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: the model " << fullPath << " failed to load.\n";
|
||||
parse_err = true;
|
||||
}
|
||||
#if DEBUG_CSL_LOADING
|
||||
XPLMDebugString(" Got Object: ");
|
||||
XPLMDebugString(fullPath.c_str());
|
||||
XPLMDebugString("\n");
|
||||
#endif
|
||||
} else {
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: OBJECT command takes 1 argument.\n";
|
||||
}
|
||||
}
|
||||
|
||||
// TEXTURE
|
||||
if (!tokens.empty() && tokens[0] == "TEXTURE" && pass == pass_Load)
|
||||
{
|
||||
if(tokens.size() != 2)
|
||||
{
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: TEXTURE command takes 1 argument.\n";
|
||||
} else {
|
||||
// Load regular texture
|
||||
string texPath = tokens[1];
|
||||
MakePartialPathNativeObj(texPath);
|
||||
|
||||
if (!DoPackageSub(texPath))
|
||||
{
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: package not found.\n";
|
||||
}
|
||||
pckg->planes.back().texID = OBJ_LoadTexture(texPath.c_str(), false);
|
||||
if (pckg->planes.back().texID == -1)
|
||||
{
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "Texture " << texPath << " failed to load.\n";
|
||||
}
|
||||
// Load the lit texture
|
||||
string texLitPath = texPath;
|
||||
string::size_type pos2 = texLitPath.find_last_of(".");
|
||||
if(pos2 != string::npos)
|
||||
{
|
||||
texLitPath.insert(pos2, "LIT");
|
||||
pckg->planes.back().texLitID = OBJ_LoadTexture(texLitPath.c_str(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// OBJ8 MULTI-OBJ WITH SIM RENDERING
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
// OBJ8_AIRCRAFT
|
||||
if (!tokens.empty() && tokens[0] == "OBJ8_AIRCRAFT" && pass == pass_Load)
|
||||
{
|
||||
BreakStringPvt(line, tokens, 2, " \t\r\n");
|
||||
|
||||
if(tokens.size() == 2)
|
||||
{
|
||||
pckg->planes.push_back(CSLPlane_t());
|
||||
pckg->planes.back().plane_type = plane_Obj8;
|
||||
pckg->planes.back().file_path = tokens[1]; // debug str
|
||||
pckg->planes.back().moving_gear = true;
|
||||
pckg->planes.back().texID = 0;
|
||||
pckg->planes.back().texLitID = 0;
|
||||
pckg->planes.back().obj_idx = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: OBJ8_AIRCARFT command takes 1 argument.\n";
|
||||
}
|
||||
}
|
||||
|
||||
// OBJ8 <group> <animate YES|NO> <filename>
|
||||
if (!tokens.empty() && tokens[0] == "OBJ8" && pass == pass_Load)
|
||||
{
|
||||
BreakStringPvt(line, tokens, 4, " \t\r\n");
|
||||
|
||||
if(tokens.size() == 4)
|
||||
{
|
||||
if(pckg->planes.empty() || pckg->planes.back().plane_type != plane_Obj8)
|
||||
{
|
||||
// err - obj8 record at stupid place in file
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
obj_for_acf att;
|
||||
|
||||
if(tokens[1] == "GLASS")
|
||||
att.draw_type = draw_glass;
|
||||
else if(tokens[1] == "LIGHTS")
|
||||
att.draw_type = draw_lights;
|
||||
else if(tokens[1] == "LOW_LOD")
|
||||
att.draw_type = draw_low_lod;
|
||||
else if(tokens[1] == "SOLID")
|
||||
att.draw_type = draw_solid;
|
||||
else {
|
||||
// err crap enum
|
||||
}
|
||||
|
||||
if(tokens[2] == "YES")
|
||||
att.needs_animation = true;
|
||||
else if(tokens[2] == "NO")
|
||||
att.needs_animation = false;
|
||||
else
|
||||
{
|
||||
// crap flag
|
||||
}
|
||||
std::string fullPath = tokens[3];
|
||||
|
||||
MakePartialPathNativeObj(fullPath);
|
||||
if (!DoPackageSub(fullPath))
|
||||
{
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: package not found.\n";
|
||||
parse_err = true;
|
||||
}
|
||||
|
||||
char xsystem[1024];
|
||||
XPLMGetSystemPath(xsystem);
|
||||
|
||||
#if APL
|
||||
HFS2PosixPath(xsystem, xsystem, 1024);
|
||||
#endif
|
||||
|
||||
size_t sys_len = strlen(xsystem);
|
||||
if(fullPath.size() > sys_len)
|
||||
fullPath.erase(fullPath.begin(),fullPath.begin() + sys_len);
|
||||
else
|
||||
{
|
||||
// should probaby freak out here.
|
||||
}
|
||||
|
||||
att.handle = NULL;
|
||||
att.file = fullPath;
|
||||
|
||||
pckg->planes.back().attachments.push_back(att);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// err - f---ed line.
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// MATCHING CRAP AND OTHER COMMON META-DATA
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// HASGEAR YES|NO
|
||||
// This line specifies whether the previous plane has retractable gear.
|
||||
// Useful for preventing XSB from rolling up a C152's gear on takeoff!
|
||||
if (!tokens.empty() && tokens[0] == "HASGEAR" && pass == pass_Load)
|
||||
{
|
||||
if (tokens.size() != 2 || (tokens[1] != "YES" && tokens[1] != "NO"))
|
||||
{
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: HASGEAR takes one argument that must be YES or NO.\n";
|
||||
} else {
|
||||
if (tokens[1] == "YES")
|
||||
pckg->planes.back().moving_gear = true;
|
||||
else if (tokens[1] == "NO")
|
||||
pckg->planes.back().moving_gear = false;
|
||||
else {
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: HASGEAR must have a YES or NO argument, but we got " << tokens[1] << ".\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ICAO <code>
|
||||
// This line maps one ICAO code to the previous airline, without
|
||||
// specifying an airline or livery.
|
||||
if (!tokens.empty() && tokens[0] == "ICAO" && pass == pass_Load)
|
||||
{
|
||||
BreakStringPvt(line, tokens, 0, " \t");
|
||||
if (tokens.size() == 2)
|
||||
{
|
||||
icao = tokens[1];
|
||||
group = gGroupings[icao];
|
||||
if (pckg->matches[match_icao].count(icao) == 0)
|
||||
pckg->matches[match_icao] [icao] = static_cast<int>(pckg->planes.size()) - 1;
|
||||
if (!group.empty())
|
||||
if (pckg->matches[match_group].count(group) == 0)
|
||||
pckg->matches[match_group] [group] = static_cast<int>(pckg->planes.size()) - 1;
|
||||
} else {
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: ICAO command takes 1 argument.\n";
|
||||
}
|
||||
}
|
||||
|
||||
// AIRLINE <code> <airline>
|
||||
// This line maps one ICAO code to the previous airline, with
|
||||
// an airline but without a livery. This will also create
|
||||
// an ICAO-only association for non-airline-specific matching.
|
||||
if (!tokens.empty() && tokens[0] == "AIRLINE" && pass == pass_Load)
|
||||
{
|
||||
BreakStringPvt(line, tokens, 0, " \t");
|
||||
if (tokens.size() == 3)
|
||||
{
|
||||
icao = tokens[1];
|
||||
airline = tokens[2];
|
||||
group = gGroupings[icao];
|
||||
if (pckg->matches[match_icao_airline].count(icao + " " + airline) == 0)
|
||||
pckg->matches[match_icao_airline] [icao + " " + airline] = static_cast<int>(pckg->planes.size()) - 1;
|
||||
#if USE_DEFAULTING
|
||||
if (pckg->matches[match_icao ].count(icao ) == 0)
|
||||
pckg->matches[match_icao ] [icao ] = pckg->planes.size() - 1;
|
||||
#endif
|
||||
if (!group.empty())
|
||||
{
|
||||
#if USE_DEFAULTING
|
||||
if (pckg->matches[match_group ].count(group ) == 0)
|
||||
pckg->matches[match_group ] [group ] = pckg->planes.size() - 1;
|
||||
#endif
|
||||
if (pckg->matches[match_group_airline].count(group + " " + airline) == 0)
|
||||
pckg->matches[match_group_airline] [group + " " + airline] = static_cast<int>(pckg->planes.size()) - 1;
|
||||
}
|
||||
} else {
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: AIRLINE command takes two arguments.\n";
|
||||
}
|
||||
}
|
||||
|
||||
// LIVERY <code> <airline> <livery>
|
||||
// This line maps one ICAO code to the previous airline, with
|
||||
// an airline and livery. This will also create
|
||||
// an ICAO-only and ICAO/airline association for non-airline-specific
|
||||
// matching.
|
||||
if (!tokens.empty() && tokens[0] == "LIVERY" && pass == pass_Load)
|
||||
{
|
||||
BreakStringPvt(line, tokens, 0, " \t");
|
||||
if (tokens.size() == 4)
|
||||
{
|
||||
icao = tokens[1];
|
||||
airline = tokens[2];
|
||||
livery = tokens[3];
|
||||
group = gGroupings[icao];
|
||||
#if USE_DEFAULTING
|
||||
if (pckg->matches[match_icao ].count(icao ) == 0)
|
||||
pckg->matches[match_icao ] [icao ] = pckg->planes.size() - 1;
|
||||
if (pckg->matches[match_icao ].count(icao ) == 0)
|
||||
pckg->matches[match_icao_airline ] [icao + " " + airline ] = pckg->planes.size() - 1;
|
||||
#endif
|
||||
if (pckg->matches[match_icao_airline_livery ].count(icao + " " + airline + " " + livery) == 0)
|
||||
pckg->matches[match_icao_airline_livery ] [icao + " " + airline + " " + livery] = static_cast<int>(pckg->planes.size()) - 1;
|
||||
if (!group.empty())
|
||||
{
|
||||
#if USE_DEFAULTING
|
||||
if (pckg->matches[match_group ].count(group ) == 0)
|
||||
pckg->matches[match_group ] [group ] = pckg->planes.size() - 1;
|
||||
if (pckg->matches[match_group_airline ].count(group + " " + airline ) == 0)
|
||||
pckg->matches[match_group_airline ] [group + " " + airline ] = pckg->planes.size() - 1;
|
||||
#endif
|
||||
if (pckg->matches[match_group_airline_livery ].count(group + " " + airline + " " + livery) == 0)
|
||||
pckg->matches[match_group_airline_livery ] [group + " " + airline + " " + livery] = static_cast<int>(pckg->planes.size()) - 1;
|
||||
}
|
||||
} else {
|
||||
parse_err = true;
|
||||
XPLMDump(path, lineNum, line) << "xbus WARNING: LIVERY command takes two arguments.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fi);
|
||||
} else {
|
||||
XPLMDump() << "xbus WARNING: package '" << inPath << "' could not be opened. Error was: " << strerror(errno) << ".\n";
|
||||
}
|
||||
return parse_err;
|
||||
}
|
||||
|
||||
// This routine loads the related.txt file and also all packages.
|
||||
bool CSL_LoadCSL(const char * inFolderPath, const char * inRelatedFile, const char * inDoc8643)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user