Start on SimConnect

This commit is contained in:
2022-10-03 02:05:06 +02:00
parent 997586b8aa
commit 23db85c2a5
22 changed files with 1209 additions and 116 deletions
+16 -1
View File
@@ -40,7 +40,7 @@ namespace file
double trueHeading;
public:
// From X-Plane or MakeRwys
// From X-Plane
inline Runway(std::string designator,
double latitudeStart,
double longitudeStart,
@@ -63,6 +63,21 @@ namespace file
this->trueHeading,
this->width);
};
// From MakeRwys
inline Runway(std::string designator,
struct geodata::point start,
double width,
double length,
double trueHeading)
: designator(designator), width(width), length(length),
trueHeading(trueHeading)
{
geodata::point end =
geodata::calculatePointDD(start, trueHeading, length);
this->bounds =
geodata::calculateBoxDD(start, end, trueHeading, width);
};
// From database
inline Runway(std::string designator,
struct geodata::box bounds,
+67 -15
View File
@@ -16,7 +16,12 @@
#include "constants.h"
#include "simdata/gate.hpp"
#include "simdata/runway.hpp"
#ifdef XP
#include "simdata/simdataXP.hpp"
#endif
#ifndef MSFS
#include "simdata/simdataESP.hpp"
#endif
/*
* Header
@@ -84,9 +89,11 @@ namespace file
in.close();
}
inline void fromFile()
inline void fromFile(const char *file)
{
std::ifstream in(BASE_DIRECTORY SIMDATABASE, std::ifstream::binary);
std::string path(BASE_DIRECTORY);
path.append(file);
std::ifstream in(path, std::ifstream::binary);
std::string ident = readString(in, 4);
if (ident.compare(SIMDATABASE_HEADER) != 0) {
@@ -100,37 +107,82 @@ namespace file
}
public:
inline SimDatabase(int xPlaneVersion,
inline SimDatabase(int simVersion,
const char *hash,
std::unique_ptr<config::Config> &configuration,
std::shared_ptr<config::Config> &configuration,
std::function<void(const std::string)> toLog)
{
if (strcmp(configuration->getScenery().c_str(), hash) != 0 ||
!util::fileExists(BASE_DIRECTORY SIMDATABASE)) {
#ifdef XP
scan(xPlaneVersion < 12000 ? XPLANE11_BASE_SCENERY
: XPLANE12_BASE_SCENERY,
scan(simVersion < 12000 ? XPLANE11_BASE_SCENERY
: XPLANE12_BASE_SCENERY,
XPLANE_CUSTOM_SCENERY,
BASE_DIRECTORY "log.txt",
airports);
#else
toLog("ESP SCAN WILL BE HERE");
#endif
#ifndef MSFS
scan(BASE_DIRECTORY MAKERWYS_R5,
BASE_DIRECTORY MAKERWYS_G5,
BASE_DIRECTORY "db_log.txt",
airports);
#endif
configuration->updateScenery(hash);
this->toFile();
#ifdef XP
this->toFile(SIMDATABASE);
#endif
#ifndef MSFS
switch (simVersion) {
case FSX_VERSION:
this->toFile(FSX_PREFIX SIMDATABASE);
break;
case FSXSE_VERSION:
this->toFile(FSXSE_PREFIX SIMDATABASE);
break;
case P3D3_VERSION:
this->toFile(P3D3_PREFIX SIMDATABASE);
break;
case P3D4_VERSION:
this->toFile(P3D4_PREFIX SIMDATABASE);
break;
case P3D5_VERSION:
this->toFile(P3D5_PREFIX SIMDATABASE);
break;
}
#endif
toLog("Sim Database updated");
} else {
this->fromFile();
#ifdef XP
this->fromFile(SIMDATABASE);
#endif
#ifndef MSFS
switch (simVersion) {
case FSX_VERSION:
this->fromFile(FSX_PREFIX SIMDATABASE);
break;
case FSXSE_VERSION:
this->fromFile(FSXSE_PREFIX SIMDATABASE);
break;
case P3D3_VERSION:
this->fromFile(P3D3_PREFIX SIMDATABASE);
break;
case P3D4_VERSION:
this->fromFile(P3D4_PREFIX SIMDATABASE);
break;
case P3D5_VERSION:
this->fromFile(P3D5_PREFIX SIMDATABASE);
break;
}
#endif
toLog("Sim Database loaded");
}
}
inline void toFile() const
inline void toFile(const char *file) const
{
std::ofstream out(BASE_DIRECTORY SIMDATABASE, std::fstream::binary);
std::string path(BASE_DIRECTORY);
path.append(file);
std::ofstream out(path, std::fstream::binary);
// File Header
out.write(SIMDATABASE_HEADER, 4);
+141
View File
@@ -0,0 +1,141 @@
#ifndef GERMANAIRLINESVA_FILE_SIMDATA_SIMDATAXP_H
#define GERMANAIRLINESVA_FILE_SIMDATA_SIMDATAXP_H
#include <cstdint>
#include <fstream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
#include "geodata.hpp"
#include "simdata/gate.hpp"
#include "simdata/runway.hpp"
#include "util.hpp"
namespace germanairlinesva
{
namespace file
{
namespace simdata
{
inline int scan(
const std::string runwaysFile,
const std::string gatesFile,
const std::string logFile,
std::map<std::string, std::pair<std::vector<Gate>, std::vector<Runway>>>
&airports)
{
std::ifstream runways(runwaysFile);
if (!runways.good()) {
return 1;
}
std::ifstream gates(gatesFile);
if (!gates.good()) {
runways.close();
return 2;
}
std::ofstream log(logFile, std::fstream::trunc);
if (!log.good()) {
runways.close();
gates.close();
return 3;
}
std::string line;
std::string *currentIcao = nullptr;
std::map<std::string, std::vector<Gate>> tmpAirportGates;
std::map<std::string, std::vector<Runway>> tmpAirportRunways;
std::vector<Gate> tmpGates;
std::vector<Runway> tmpRunways;
int apCount = 0;
int validCount = 0;
log << "<FILE> " << runwaysFile << std::endl;
while (std::getline(runways, line)) {
std::vector<std::string> fields = util::split(line, ',');
// New ICAO
if (currentIcao != nullptr && *currentIcao != fields[0]) {
tmpAirportRunways[*currentIcao] = tmpRunways;
tmpRunways = std::vector<Runway>();
apCount++;
}
currentIcao = new std::string(fields[0]);
int desig = std::stoi(fields[1]);
std::string designator;
switch (desig % 10) {
case 0:
designator = std::to_string(desig / 10);
break;
case 1:
designator = std::to_string(desig / 10) + " L";
break;
case 2:
designator = std::to_string(desig / 10) + " R";
break;
case 3:
designator = std::to_string(desig / 10) + " C";
break;
}
if (desig < 100) {
designator = "0" + designator;
}
struct geodata::point start = {std::stod(fields[2]),
std::stod(fields[3])};
tmpRunways.emplace_back(designator,
start,
geodata::toMetre(std::stod(fields[8])),
geodata::toMetre(std::stod(fields[6])),
std::stod(fields[5]) + std::stod(fields[9]));
log << "\t<RUNWAY> " << line << std::endl;
}
currentIcao = nullptr;
while (std::getline(gates, line)) {
std::vector<std::string> fields = util::split(line, ',');
// New ICAO
if (currentIcao != nullptr && *currentIcao != fields[0]) {
tmpAirportGates[*currentIcao] = tmpGates;
tmpGates = std::vector<Gate>();
}
currentIcao = new std::string(fields[0]);
double width = std::stod(fields[5]);
tmpGates.emplace_back(fields[1] + fields[2],
std::stod(fields[3]),
std::stod(fields[4]),
width > 0 ? width : 20);
log << "\t<GATE> " << line << std::endl;
}
for (const auto &pair : tmpAirportRunways) {
std::string icao = pair.first;
if (!tmpAirportGates[icao].empty() && !pair.second.empty()) {
airports[icao] = {tmpAirportGates[icao], pair.second};
log << "\t<STATUS> " << icao << " committed" << std::endl;
validCount++;
} else {
log << "\t<STATUS> " << icao << " had no gates or runways"
<< std::endl;
}
}
log << "<STATUS> " << apCount << " airports found, of which "
<< validCount << " are valid" << std::endl;
return 0;
}
} // namespace simdata
} // namespace file
} // namespace germanairlinesva
#endif
+1 -1
View File
@@ -60,7 +60,7 @@ namespace file
gates.emplace_back(gateName,
std::stod(fields[1]),
std::stod(fields[2]),
40);
20);
}
inline void makeAirport(