Commit fa3f86a7 authored by Roque's avatar Roque

erp5_drone_simulator: refactor drone_dict

parent f0d304c9
......@@ -11,17 +11,19 @@ var TAKEOFF_RADIUS = 60,
var DroneAaileFixeAPI = /** @class */ (function () {
"use strict";
//** CONSTRUCTOR
function DroneAaileFixeAPI(gameManager, drone_info, flight_parameters) {
function DroneAaileFixeAPI(gameManager, drone_info, flight_parameters, id) {
this._gameManager = gameManager;
this._mapManager = this._gameManager._mapManager;
this._map_dict = this._mapManager.getMapInfo();
this._flight_parameters = flight_parameters;
this._id = id;
this._drone_info = drone_info;
this._loiter_radius = 0;
this._last_loiter_point_reached = -1;
//this._start_altitude = 0;
//this._last_altitude_point_reached = -1;
this._loiter_mode = false;
//this._start_altitude = 0;
this._drone_dict_list = [];
}
/*
** Function called on start phase of the drone, just before onStart AI script
......@@ -38,6 +40,27 @@ var DroneAaileFixeAPI = /** @class */ (function () {
/*if (this._start_altitude > 0) { //TODO move start_altitude here
this.reachAltitude(drone);
}*/
var _this = this, drone_position = drone.getCurrentPosition(), drone_info;
if (drone_position) {
drone_info = {
'altitudeRel' : drone_position.z,
'altitudeAbs' : this._mapManager.getMapInfo().start_AMSL +
drone_position.z,
'latitude' : drone_position.x,
'longitude' : drone_position.y
};
this._drone_dict_list[this._id] = drone_info;
//broadcast drone info using internal msg
this._gameManager._droneList.forEach(function (drone) {
if (drone.id !== _this._id) {
drone.internal_getMsg(drone_info, _this._id);
}
});
}
};
DroneAaileFixeAPI.prototype.internal_getMsg = function (msg, id) {
this._drone_dict_list[id] = msg;
};
DroneAaileFixeAPI.prototype.set_loiter_mode = function (radius) {
......@@ -88,7 +111,7 @@ var DroneAaileFixeAPI = /** @class */ (function () {
return;
};
DroneAaileFixeAPI.prototype.internal_sendMsg = function (msg, to) {
DroneAaileFixeAPI.prototype.sendMsg = function (msg, to) {
var _this = this,
droneList = _this._gameManager._droneList;
_this._gameManager.delay(function () {
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1004.13828.40056.62976</string> </value>
<value> <string>1004.25224.30173.1314</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1668017844.98</float>
<float>1668701317.95</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -6,7 +6,7 @@
var DroneLogAPI = /** @class */ (function () {
"use strict";
//** CONSTRUCTOR
function DroneLogAPI(gameManager, drone_info, flight_parameters) {
function DroneLogAPI(gameManager, drone_info, flight_parameters, id) {
this._gameManager = gameManager;
this._mapManager = this._gameManager._mapManager;
this._drone_info = drone_info;
......@@ -85,7 +85,7 @@ var DroneLogAPI = /** @class */ (function () {
return;
};
DroneLogAPI.prototype.internal_sendMsg = function (msg, to) {
DroneLogAPI.prototype.sendMsg = function (msg, to) {
return;
};
DroneLogAPI.prototype.log = function (msg) {
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1004.13789.44664.33126</string> </value>
<value> <string>1004.25197.65379.45943</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1668015277.76</float>
<float>1668699757.5</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -24,7 +24,6 @@ var DroneManager = /** @class */ (function () {
this._canUpdate = true;
this._id = id;
this._leader_id = 0;
this._drone_dict = {};
this._API = API; // var API created on AI evel
// Create the control mesh
this._controlMesh = BABYLON.Mesh.CreateBox(
......@@ -56,8 +55,7 @@ var DroneManager = /** @class */ (function () {
configurable: true
});
Object.defineProperty(DroneManager.prototype, "drone_dict", {
get: function () { return this._drone_dict; },
set: function (value) { this._drone_dict = value; },
get: function () { return this._API._drone_dict_list; },
enumerable: true,
configurable: true
});
......@@ -217,7 +215,7 @@ var DroneManager = /** @class */ (function () {
this._direction = new BABYLON.Vector3(x, z, y).normalize();
};
/**
* Send a message to team drones
* Send a message to drones
* @param msg The message to send
* @param id The targeted drone. -1 or nothing to broadcast
*/
......@@ -231,9 +229,17 @@ var DroneManager = /** @class */ (function () {
id = -1;
}
if (_this.infosMesh) {
return _this._API.internal_sendMsg(JSON.parse(JSON.stringify(msg)), id);
return _this._API.sendMsg(JSON.parse(JSON.stringify(msg)), id);
}
};
/**
* Handle internal get msg
* @param msg The message to send
* @param id of the sender
*/
DroneManager.prototype.internal_getMsg = function (msg, id) {
return this._API.internal_getMsg(msg, id);
};
/** Perform a console.log with drone id + the message */
DroneManager.prototype.log = function (msg) { return msg; };
DroneManager.prototype.getMaxHeight = function () {
......@@ -578,7 +584,7 @@ var GameManager = /** @class */ (function () {
GameManager.prototype._update = function (delta_time) {
var _this = this,
queue = new RSVP.Queue(),
i, drone_dict = [], drone_position;
i, drone_position;
this._updateTimeAndLog(delta_time);
// trigger all deferred calls if it is time
......@@ -591,23 +597,9 @@ var GameManager = /** @class */ (function () {
}
}
this._droneList.forEach(function (drone) {
drone_position = drone.getCurrentPosition();
if (drone_position) {
drone_dict.push({
'altitudeRel' : drone_position.z,
'altitudeAbs' : _this._mapManager.getMapInfo().start_AMSL +
drone_position.z,
'latitude' : drone_position.x,
'longitude' : drone_position.y
});
}
});
this._droneList.forEach(function (drone) {
queue.push(function () {
drone._tick += 1;
drone.drone_dict = drone_dict;
return drone.internal_update(delta_time);
});
});
......@@ -939,7 +931,7 @@ var GameManager = /** @class */ (function () {
else {
position_list.push(position);
api = new this.APIs_dict[drone_list[i].type](
this, drone_list[i], GAMEPARAMETERS);
this, drone_list[i], GAMEPARAMETERS, i);
spawnDrone(position.x, position.y, position.z, i,
drone_list[i], api);
}
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1004.25069.55215.44288</string> </value>
<value> <string>1004.25222.46703.18858</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1668692274.42</float>
<float>1668701293.79</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment