Commit a6c32ef0 authored by Roque's avatar Roque

[WEB-WORKER] [WIP] move all game logic into one file (WIP)

parent 95103c60
......@@ -10,11 +10,8 @@
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
......@@ -52,11 +49,8 @@
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
......@@ -169,7 +163,7 @@
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish_alive</string> </value>
<value> <string>hide</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
......@@ -195,7 +189,7 @@
</tuple>
<state>
<tuple>
<float>1662556207.86</float>
<float>1664301067.15</float>
<string>UTC</string>
</tuple>
</state>
......@@ -204,7 +198,7 @@
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published_alive</string> </value>
<value> <string>hidden</string> </value>
</item>
</dictionary>
</list>
......
......@@ -201,9 +201,12 @@ var runGame, updateGame, eventGame, game_manager_instance;
};
game_parameters_json.drone.maxSpeed = (flight_dist / flight_time) * SPEED_FACTOR;
game_parameters_json.obstacles = path_point_list;
game_parameters_json.randomSpawn.leftTeam.position.x = start_position[0];
/*game_parameters_json.randomSpawn.leftTeam.position.x = start_position[0];
game_parameters_json.randomSpawn.leftTeam.position.y = start_position[1];
game_parameters_json.randomSpawn.leftTeam.position.z = start_position[2];
game_parameters_json.randomSpawn.leftTeam.position.z = start_position[2];*/
game_parameters_json.dronesPosition.x = start_position[0];
game_parameters_json.dronesPosition.y = start_position[1];
game_parameters_json.dronesPosition.z = start_position[2];
game_parameters_json.gameTime = flight_time;
//give map some margin from the flight
game_parameters_json.mapSize.width = MAP_SIZE * 1.10;
......@@ -274,8 +277,11 @@ var GameManager = /** @class */ (function () {
this._last_position_drawn = [];
this._log_count = [];
this._flight_log = [];
//TODO drop the use of RS map and use a JSON instead. drop randomspawn and similar names //rename all
//TODO do this in above, in game logic game_parameters_json
//move this to JSON dict
if (GAMEPARAMETERS.compareFlights) {
for (var count = 0; count < GAMEPARAMETERS.teamSize; count++) {
for (var count = 0; count < GAMEPARAMETERS.droneList.length; count++) {
this._flight_log[count] = [];
this._log_count[count] = 0;
this._last_position_drawn[count] = null;
......@@ -289,8 +295,7 @@ var GameManager = /** @class */ (function () {
}
this.APIs_dict = {
DroneAaileFixeAPI: DroneAaileFixeAPI,
DroneLogAPI: DroneLogAPI,
DroneAPI: DroneAPI
DroneLogAPI: DroneLogAPI
};
}
......@@ -349,7 +354,7 @@ var GameManager = /** @class */ (function () {
this._game_duration += delta_time;
var seconds = Math.floor(this._game_duration / 1000);
if (GAMEPARAMETERS.compareFlights) {
for (var count = 0; count < GAMEPARAMETERS.teamSize; count++) {
for (var count = 0; count < GAMEPARAMETERS.droneList.length; count++) {
if (this._teamLeft[count]._controlMesh) {
var drone_position_x = this._teamLeft[count]._controlMesh.position.x,
drone_position_z = this._teamLeft[count]._controlMesh.position.y,
......@@ -369,7 +374,7 @@ var GameManager = /** @class */ (function () {
this._flight_log[count].push([lat, lon, drone_position_z]);
}
}
if (GAMEPARAMETERS.compareFlights.draw) {
if (GAMEPARAMETERS.compareFlights.draw) { //TODO review this in JSON dict
//draw drone position every second
if (this._last_position_drawn[count] !== seconds) {
this._last_position_drawn[count] = seconds;
......@@ -492,18 +497,14 @@ var GameManager = /** @class */ (function () {
GAMEPARAMETERS = ctx._getGameParameter();
ctx._map_swapped = true;
}
// Create the API
var lAPI = new DroneAPI(ctx, "L"); //TODO rename all left/team
console.log("APIs created");
// Set the AI code into drones
var AIcodeEval, AIcodeLeft;
var AIcodeEval, AIcodeLeft; //TODO rename all left/team/'L'
AIcodeLeft = ctx._script;
// Init the map
_this._mapManager = new MapManager(ctx._scene);
console.log("Map manager instantiated");
if (GAMEPARAMETERS.randomSpawn) { //TODO drop the use of RS map and use JSON instead. drop randomspawn and similar names //rename all
ctx._setRandomSpawnPosition(GAMEPARAMETERS.randomSpawn.leftTeam, GAMEPARAMETERS.teamSize, lAPI, AIcodeLeft, "L");
}
ctx._spawnDrones(GAMEPARAMETERS.dronesPosition, GAMEPARAMETERS.droneList, AIcodeLeft);
// Hide the drone prefab
DroneManager.Prefab.isVisible = false;
//Hack to make advanced texture work
......@@ -654,48 +655,43 @@ var GameManager = /** @class */ (function () {
return parameter;
};
GameManager.prototype._setRandomSpawnPosition = function (randomSpawn, team_size, api, code, team) {
var position, i, position_list = [], center = randomSpawn.position, max_collision = randomSpawn.maxCollision || 10 * team_size, collision_nb = 0;
function checkCollision(position, list) {
var i;
for (i = 0; i < list.length; i += 1) {
if (position.equalsWithEpsilon(list[i], 0.5)) {
return true;
}
GameManager.prototype._spawnDrones = function (center, drone_list, code) {
var position, i, position_list = [], max_collision = 10 * drone_list.length,
collision_nb = 0;
function checkCollision(position, list) {
var i;
for (i = 0; i < list.length; i += 1) {
if (position.equalsWithEpsilon(list[i], 0.5)) {
return true;
}
return false;
}
for (i = 0; i < team_size; i += 1) {
if (team === "L" || i === 0) { //TODO refactor as 'R' is dropped
position = randomSpherePoint(center.x + i, center.y + i, center.z + i, 0, 0, 0);
if (checkCollision(position, position_list) || position.z < 0.05) {
collision_nb += 1;
if (collision_nb < max_collision) {
i -= 1;
}
}
else {
position_list.push(position);
var lAPI = api;
if (randomSpawn.types) {
if (randomSpawn.types[i] in this.APIs_dict) {
lAPI = new this.APIs_dict[randomSpawn.types[i]](this, "L", GAMEPARAMETERS.compareFlights);
}
}
this._setSpawnDrone(position.x, position.y, position.z, i, lAPI, code, team);
}
return false;
}
for (i = 0; i < drone_list.length; i += 1) {
position = randomSpherePoint(center.x + i, center.y + i, center.z + i, 0, 0, 0);
if (checkCollision(position, position_list) || position.z < 0.05) {
collision_nb += 1;
if (collision_nb < max_collision) {
i -= 1;
}
}
else {
position_list.push(position);
var api = new this.APIs_dict[drone_list[i]](this, "L", GAMEPARAMETERS.compareFlights); //TODO drip L team in DroneAPI
this._setSpawnDrone(position.x, position.y, position.z, i, api, code);
}
}
};
GameManager.prototype._setSpawnDrone = function (x, y, z, index, api, code, team) {
GameManager.prototype._setSpawnDrone = function (x, y, z, index, api, code) {
var default_drone_AI = api.getDroneAI();
if (default_drone_AI) {
code = default_drone_AI;
}
var team = "L"; //TODO DROP TEAM
var ctx = this, base, code_eval = "let drone = new DroneManager(ctx._scene, " +
index + ', "' + team + '", api);' +
"let droneMe = function(NativeDate, me, Math, window, DroneManager, GameManager, DroneAPI, DroneLogAPI, DroneAaileFixeAPI, BABYLON, GAMEPARAMETERS) {" +
"let droneMe = function(NativeDate, me, Math, window, DroneManager, GameManager, DroneLogAPI, DroneAaileFixeAPI, BABYLON, GAMEPARAMETERS) {" +
"var start_time = (new Date(2070, 0, 0, 0, 0, 0, 0)).getTime();" +
"Date.now = function () {return start_time + drone._tick * 1000/60;}; " +
"function Date() {if (!(this instanceof Date)) {throw new Error('Missing new operator');} " +
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1003.15933.21857.42444</string> </value>
<value> <string>1003.16008.33206.11520</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1664298143.44</float>
<float>1664302663.7</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -30,7 +30,6 @@ importScripts('rsvp.js',
'ObstacleManager.js',
'DroneAaileFixeAPI.js',
'DroneLogAPI.js',
'DroneAPI.js',
'gadget_erp5_page_game_logic.js');
function mainToWorker(evt) {
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1003.15920.8115.24524</string> </value>
<value> <string>1003.15921.17646.56234</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1664297356.11</float>
<float>1664301536.13</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