mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Minor bugfix
This commit is contained in:
@@ -34,6 +34,7 @@ public:
|
||||
void setROE(wstring newROE);
|
||||
void setReactionToThreat(wstring newReactionToThreat);
|
||||
void landAt(Coords loc);
|
||||
void setHasNewData(bool newHasNewData) { hasNewData = newHasNewData; }
|
||||
|
||||
int getID() { return ID; }
|
||||
wstring getName() { return name; }
|
||||
@@ -56,6 +57,7 @@ public:
|
||||
bool getIsLeader() { return isLeader; }
|
||||
bool getIsWingman() { return isWingman; }
|
||||
wstring getFormation() { return formation; }
|
||||
bool getHasNewData() { return hasNewData; }
|
||||
|
||||
virtual double getTargetSpeed() { return targetSpeed; };
|
||||
virtual double getTargetAltitude() { return targetAltitude; };
|
||||
@@ -68,6 +70,8 @@ public:
|
||||
|
||||
protected:
|
||||
int ID;
|
||||
bool hasNewData = false;
|
||||
int newDataCounter = 0;
|
||||
int state = State::IDLE;
|
||||
bool hasTask = false;
|
||||
bool AI = false;
|
||||
@@ -104,6 +108,8 @@ protected:
|
||||
Coords activeDestination = Coords(0);
|
||||
Coords oldPosition = Coords(0); // Used to approximate speed
|
||||
|
||||
list<pair<int, std::function<void(void)>>> schedule;
|
||||
|
||||
virtual void AIloop() = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ Unit::Unit(json::value json, int ID) :
|
||||
ID(ID)
|
||||
{
|
||||
log("Creating unit with ID: " + to_string(ID));
|
||||
newDataCounter = 1.0 / UPDATE_TIME_INTERVAL > 0? 1.0 / UPDATE_TIME_INTERVAL: 1; // Mark the unit has hasNewData for 1 second
|
||||
}
|
||||
|
||||
Unit::~Unit()
|
||||
@@ -25,6 +26,10 @@ Unit::~Unit()
|
||||
|
||||
void Unit::updateExportData(json::value json)
|
||||
{
|
||||
if (newDataCounter > 0)
|
||||
newDataCounter--;
|
||||
setHasNewData(newDataCounter);
|
||||
|
||||
/* Compute speed (loGetWorldObjects does not provide speed, we compute it for better performance instead of relying on many lua calls) */
|
||||
if (oldPosition != NULL)
|
||||
{
|
||||
@@ -69,6 +74,7 @@ void Unit::updateExportData(json::value json)
|
||||
|
||||
void Unit::updateMissionData(json::value json)
|
||||
{
|
||||
newDataCounter = 1.0 / UPDATE_TIME_INTERVAL > 0 ? 1.0 / UPDATE_TIME_INTERVAL : 1; // Mark the unit has hasNewData for 1 second
|
||||
if (json.has_number_field(L"fuel"))
|
||||
fuel = int(json[L"fuel"].as_number().to_double() * 100);
|
||||
if (json.has_object_field(L"ammo"))
|
||||
@@ -99,7 +105,7 @@ json::value Unit::json(bool fullRefresh)
|
||||
json[L"flightData"][L"speed"] = speed;
|
||||
json[L"flightData"][L"heading"] = heading;
|
||||
|
||||
if (fullRefresh)
|
||||
if (fullRefresh || getHasNewData())
|
||||
{
|
||||
/********** Mission data **********/
|
||||
json[L"missionData"] = json::value::object();
|
||||
|
||||
@@ -15,6 +15,7 @@ json::value airbasesData;
|
||||
json::value bullseyesData;
|
||||
mutex mutexLock;
|
||||
bool initialized = false;
|
||||
string sessionHash;
|
||||
|
||||
/* Called when DCS simulation stops. All singleton instances are deleted. */
|
||||
extern "C" DllExport int coreDeinit(lua_State* L)
|
||||
@@ -38,6 +39,7 @@ extern "C" DllExport int coreDeinit(lua_State* L)
|
||||
/* Called when DCS simulation starts. All singletons are instantiated, and the custom Lua functions are registered in the Lua state. */
|
||||
extern "C" DllExport int coreInit(lua_State* L)
|
||||
{
|
||||
sessionHash = random_string(16);
|
||||
unitsManager = new UnitsManager(L);
|
||||
server = new Server(L);
|
||||
scheduler = new Scheduler(L);
|
||||
|
||||
@@ -12,6 +12,7 @@ extern Scheduler* scheduler;
|
||||
extern json::value airbasesData;
|
||||
extern json::value bullseyesData;
|
||||
extern mutex mutexLock;
|
||||
extern string sessionHash;
|
||||
|
||||
void handle_eptr(std::exception_ptr eptr)
|
||||
{
|
||||
@@ -93,7 +94,10 @@ void Server::handle_get(http_request request)
|
||||
answer[L"airbases"] = airbasesData;
|
||||
else if (path[0] == BULLSEYE_URI)
|
||||
answer[L"bullseyes"] = bullseyesData;
|
||||
|
||||
answer[L"sessionHash"] = json::value::string(to_wstring(sessionHash));
|
||||
}
|
||||
|
||||
response.set_body(answer);
|
||||
}
|
||||
catch (...) {
|
||||
|
||||
@@ -17,6 +17,7 @@ struct Offset {
|
||||
const DllExport std::string CurrentDateTime();
|
||||
std::wstring DllExport to_wstring(const std::string& str);
|
||||
std::string DllExport to_string(const std::wstring& wstr);
|
||||
std::string DllExport random_string(size_t length);
|
||||
|
||||
bool DllExport operator== (const Coords& a, const Coords& b);
|
||||
bool DllExport operator!= (const Coords& a, const Coords& b);
|
||||
@@ -27,3 +28,4 @@ bool DllExport operator== (const Offset& a, const Offset& b);
|
||||
bool DllExport operator!= (const Offset& a, const Offset& b);
|
||||
bool DllExport operator== (const Offset& a, const int& b);
|
||||
bool DllExport operator!= (const Offset& a, const int& b);
|
||||
|
||||
|
||||
@@ -38,6 +38,22 @@ std::string to_string(const std::wstring& wstr)
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string random_string(size_t length)
|
||||
{
|
||||
auto randchar = []() -> char
|
||||
{
|
||||
const char charset[] =
|
||||
"0123456789"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
const size_t max_index = (sizeof(charset) - 1);
|
||||
return charset[rand() % max_index];
|
||||
};
|
||||
std::string str(length, 0);
|
||||
std::generate_n(str.begin(), length, randchar);
|
||||
return str;
|
||||
}
|
||||
|
||||
bool operator== (const Coords& a, const Coords& b) { return a.lat == b.lat && a.lng == b.lng && a.alt == b.alt; }
|
||||
bool operator!= (const Coords& a, const Coords& b) { return !(a == b); }
|
||||
bool operator== (const Coords& a, const int& b) { return a.lat == b && a.lng == b && a.alt == b; }
|
||||
|
||||
Reference in New Issue
Block a user