Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+150
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Some helper classes / functions for AES
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AreaEffectSimulation/aes_export.h>
|
||||
#include <math.h>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
#include <QPointF>
|
||||
#include <QString>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <LtsUtilsCore/dds_bitarray.h>
|
||||
#include <LtsUtilsCore/qpoint3d.h>
|
||||
#include "aes_db.h"
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
inline bool chargeTypeIdIsVulcano(int chargeTypeId) { return /*(chargeTypeId == 376) ||*/ (chargeTypeId == 393) ; } // 376=Artillery ; 393=Rocket
|
||||
inline Core::GeoPosition toCoreGeoPosition(const LtsUtils::QPoint3D &point)
|
||||
{
|
||||
return Core::GeoPosition(point.x(), point.y(), point.z());
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helper namespace TrajectoryRelative (ADLER / SAA_Trajectory)
|
||||
//------------------------------------------------------------------------------
|
||||
namespace TrajectoryRelative
|
||||
{
|
||||
|
||||
// keyword used for encoding/decoding, or in other words: for toString/fromString
|
||||
static const QString TRAJECTORY_RELATIVE_KEYWORD = QStringLiteral("trajectoryRelative");
|
||||
|
||||
inline std::string toString(const std::vector<Core::RelativePositionRelativeTime> &trajectoryRelative)
|
||||
{
|
||||
if (trajectoryRelative.empty())
|
||||
return {};
|
||||
|
||||
QJsonObject obj;
|
||||
QJsonArray arr;
|
||||
|
||||
for (const auto &coordinate : trajectoryRelative)
|
||||
{
|
||||
QJsonObject coordObj;
|
||||
coordObj[QStringLiteral("offsetX")] = coordinate.offsetX();
|
||||
coordObj[QStringLiteral("offsetY")] = coordinate.offsetY();
|
||||
coordObj[QStringLiteral("offsetZ")] = coordinate.offsetZ();
|
||||
coordObj[QStringLiteral("relativeTime")] = coordinate.relativeTime();
|
||||
arr.append(coordObj);
|
||||
}
|
||||
obj[TRAJECTORY_RELATIVE_KEYWORD] = arr;
|
||||
|
||||
return QJsonDocument(obj).toJson(QJsonDocument::JsonFormat::Compact).toStdString();
|
||||
}
|
||||
|
||||
inline std::vector<Core::RelativePositionRelativeTime> fromString(const QString &trajectoryRelativeJson)
|
||||
{
|
||||
if (trajectoryRelativeJson.isEmpty())
|
||||
return {};
|
||||
|
||||
QJsonObject obj = QJsonDocument::fromJson(trajectoryRelativeJson.toUtf8()).object();
|
||||
if (!obj.contains(TRAJECTORY_RELATIVE_KEYWORD) || !obj[TRAJECTORY_RELATIVE_KEYWORD].isArray() )
|
||||
return {};
|
||||
|
||||
std::vector<Core::RelativePositionRelativeTime> ret;
|
||||
|
||||
QJsonArray arr = obj[TRAJECTORY_RELATIVE_KEYWORD].toArray();
|
||||
for (const auto arrRef: arr)
|
||||
{
|
||||
QJsonObject coordinate = arrRef.toObject();
|
||||
|
||||
if (!coordinate.contains(QStringLiteral("offsetX")) ||
|
||||
!coordinate.contains(QStringLiteral("offsetY")) ||
|
||||
!coordinate.contains(QStringLiteral("offsetZ")) ||
|
||||
!coordinate.contains(QStringLiteral("relativeTime"))
|
||||
)
|
||||
return {};
|
||||
|
||||
Core::RelativePositionRelativeTime coord;
|
||||
coord.offsetX() = coordinate[QStringLiteral("offsetX")].toDouble();
|
||||
coord.offsetY() = coordinate[QStringLiteral("offsetY")].toDouble();
|
||||
coord.offsetZ() = coordinate[QStringLiteral("offsetZ")].toDouble();
|
||||
coord.relativeTime() = coordinate[QStringLiteral("relativeTime")].toInt();
|
||||
|
||||
ret.push_back(coord);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace TrajectoryRelative
|
||||
|
||||
|
||||
|
||||
inline double getAngleDegreeNorth(const QPointF &p1, const QPointF &p2)
|
||||
{
|
||||
double x = p2.x() - p1.x();
|
||||
double y = p2.y() - p1.y();
|
||||
|
||||
// Winkel der Geraden bestimmen
|
||||
double alphaRad = atan2(y, x);
|
||||
|
||||
// // Fuer Winkel > PI liefert atan2 math. rechts drehende (also negative) Werte.
|
||||
// // Um Werte von 0-2PI zu bekommen muss deshalb hier von 2Pi abgezogen werden.
|
||||
|
||||
alphaRad -= M_PI / 2.0;
|
||||
alphaRad *= -1.0;
|
||||
|
||||
if (alphaRad < 0.0)
|
||||
alphaRad = 2 * M_PI + alphaRad;
|
||||
|
||||
return (alphaRad * 180.0 / M_PI);
|
||||
}
|
||||
|
||||
inline bool isPointSimilar(AreaEffectSimulation::AesExplosionGeometry geometry)
|
||||
{
|
||||
return (geometry.underlying() == AreaEffectSimulation::AesExplosionGeometry_def::EgAimPoint) ||
|
||||
(geometry.underlying() == AreaEffectSimulation::AesExplosionGeometry_def::EgPoint);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// helper class HandledImpactsStorage
|
||||
//------------------------------------------------------------------------------
|
||||
class AES_COMMON_EXPORT HandledImpactsStorage final
|
||||
{
|
||||
public:
|
||||
Q_DISABLE_COPY(HandledImpactsStorage)
|
||||
|
||||
HandledImpactsStorage();
|
||||
~HandledImpactsStorage();
|
||||
|
||||
void setIndexProcessed(int aesItemId, int index);
|
||||
bool isIndexProcessed(int aesItemId, int index);
|
||||
void removeAesItem(int aesItemId);
|
||||
|
||||
private:
|
||||
class Private;
|
||||
/**
|
||||
* The private d->pointer to not break BC when changing internals of this class
|
||||
*/
|
||||
Private *d = nullptr;
|
||||
};
|
||||
|
||||
} // namespace AreaEffectSimulation
|
||||
Reference in new issue
Block a user