Commit 567a03a5 authored by Roque's avatar Roque

[WEB-WORKER] [WIP] handle game finish

parent b5c1cde2
...@@ -61,7 +61,12 @@ var GameManager = /** @class */ (function () { ...@@ -61,7 +61,12 @@ var GameManager = /** @class */ (function () {
GameManager.prototype.run = function () { GameManager.prototype.run = function () {
var gadget = this; var gadget = this;
return gadget._init(); return gadget._init()
.push(function () {
//TODO return result
gadget._final_score = "fake-result 000";
return gadget._final_score;
});
}; };
/*GameManager.prototype.event = function (event) { /*GameManager.prototype.event = function (event) {
...@@ -97,7 +102,6 @@ var GameManager = /** @class */ (function () { ...@@ -97,7 +102,6 @@ var GameManager = /** @class */ (function () {
} }
} }
triggerUpdateIfPossible(); triggerUpdateIfPossible();
console.log("after triggerUpdateIfPossible call");
}; };
GameManager.prototype.delay = function (callback, millisecond) { GameManager.prototype.delay = function (callback, millisecond) {
...@@ -206,12 +210,23 @@ var GameManager = /** @class */ (function () { ...@@ -206,12 +210,23 @@ var GameManager = /** @class */ (function () {
}); });
return queue return queue
//TODO finish .push(function () {
/*.push(function () { if (_this._timeOut()) {
if (_this._allDroneAreOut()) { console.log("TIMEOUT!");
return _this._finish(); return _this._finish();
} }
})*/; });
};
GameManager.prototype._timeOut = function () {
var seconds = Math.floor(this._game_duration / 1000);
return this._totalTime - seconds <= 0;
};
GameManager.prototype._finish = function () {
console.log("Simulation finished");
this._canUpdate = false;
return this.finish_deferred.resolve();
}; };
GameManager.prototype._dispose = function () { GameManager.prototype._dispose = function () {
...@@ -396,7 +411,6 @@ var GameManager = /** @class */ (function () { ...@@ -396,7 +411,6 @@ var GameManager = /** @class */ (function () {
// Timing // Timing
this._game_duration = 0; this._game_duration = 0;
this._totalTime = GAMEPARAMETERS.gameTime; this._totalTime = GAMEPARAMETERS.gameTime;
this._canUpdate = true;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
...@@ -412,9 +426,7 @@ var GameManager = /** @class */ (function () { ...@@ -412,9 +426,7 @@ var GameManager = /** @class */ (function () {
return RSVP.all(promise_list); return RSVP.all(promise_list);
}) })
.push(function () { .push(function () {
//TODO refactor this as start promise _this._canUpdate = true;
//solving promise so game-start finishes and web worker can update
_this.finish_deferred.resolve();
return _this.finish_deferred.promise; return _this.finish_deferred.promise;
}); });
}; };
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1003.14634.55498.60808</string> </value> <value> <string>1003.14745.13798.24388</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1664220253.75</float> <float>1664226905.63</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -212,8 +212,6 @@ var runGame, updateGame, eventGame, game_manager_instance; ...@@ -212,8 +212,6 @@ var runGame, updateGame, eventGame, game_manager_instance;
game_parameters_json.randomSpawn.rightTeam.position.y = destination[1]; game_parameters_json.randomSpawn.rightTeam.position.y = destination[1];
return game_parameters_json; return game_parameters_json;
} }
console.log('runGame', canvas);
game_parameters_json = processLog(game_parameters_json, log); game_parameters_json = processLog(game_parameters_json, log);
if (!game_manager_instance) { if (!game_manager_instance) {
game_manager_instance = new GameManager(canvas, script, game_manager_instance = new GameManager(canvas, script,
...@@ -223,7 +221,9 @@ var runGame, updateGame, eventGame, game_manager_instance; ...@@ -223,7 +221,9 @@ var runGame, updateGame, eventGame, game_manager_instance;
}; };
updateGame = function () { updateGame = function () {
return game_manager_instance.update(); if (game_manager_instance) {
return game_manager_instance.update();
}
}; };
/*eventGame = function (event) { /*eventGame = function (event) {
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1003.14628.31171.12032</string> </value> <value> <string>1003.14747.15369.21845</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1664220293.27</float> <float>1664226919.33</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -136,7 +136,6 @@ ...@@ -136,7 +136,6 @@
worker.onmessage = workerToMain; worker.onmessage = workerToMain;
// Always quit the game when the worker callback usage is over // Always quit the game when the worker callback usage is over
// to prevent trying to call pause // to prevent trying to call pause
//context.quit();
return message_error_handler_defer.promise; return message_error_handler_defer.promise;
function workerToMain(evt) { function workerToMain(evt) {
...@@ -161,6 +160,10 @@ ...@@ -161,6 +160,10 @@
case 'updated': case 'updated':
return update_defer.resolve('updated'); return update_defer.resolve('updated');
break; break;
case 'finished':
console.log('GAME: finished');
return context.quit();
break;
case 'event': case 'event':
bindEvent(evt.data); bindEvent(evt.data);
break; break;
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1003.14385.9806.22681</string> </value> <value> <string>1003.14737.54205.32802</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1664205234.37</float> <float>1664226969.03</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
/**************************** ROQUE WW EVENTS ****************************/ /**************************** ROQUE WW EVENTS ****************************/
/*************************************************************************/ /*************************************************************************/
console.log("WITH EVENTS HANDLING");
self.window = { self.window = {
addEventListener: function (event, fn, opt) { addEventListener: function (event, fn, opt) {
bindHandler('window', event, fn, opt); bindHandler('window', event, fn, opt);
...@@ -52,11 +49,12 @@ function mainToWorker(evt) { ...@@ -52,11 +49,12 @@ function mainToWorker(evt) {
RSVP = window.RSVP; RSVP = window.RSVP;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
postMessage({'type': 'started'});
return runGame(offscreen_canvas, evt.data.script, return runGame(offscreen_canvas, evt.data.script,
evt.data.game_parameters_json, evt.data.log); evt.data.game_parameters_json, evt.data.log);
}) })
.push(function () { .push(function (result) {
return postMessage({'type': 'started'}); return postMessage({'type': 'finished', 'result': result});
}); });
break; break;
case 'update': case 'update':
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1003.14379.48012.26709</string> </value> <value> <string>1003.14747.40357.20480</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1664205261.72</float> <float>1664226941.47</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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