Commit 567a03a5 authored by Roque's avatar Roque

[WEB-WORKER] [WIP] handle game finish

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