Commit b9ba1073 authored by Roque's avatar Roque

[WEB-WORKER] [WIP] Events handling (works!)

parent d6ce1354
...@@ -230,14 +230,17 @@ var GameManager = /** @class */ (function () { ...@@ -230,14 +230,17 @@ var GameManager = /** @class */ (function () {
var canvas = this._canvas; var canvas = this._canvas;
// Create the Babylon engine // Create the Babylon engine
this._engine = new BABYLON.Engine(canvas, true, { this._engine = new BABYLON.Engine(canvas, true, {
//options for event handling
stencil: true, stencil: true,
disableWebGL2Support: false, disableWebGL2Support: false,
audioEngine: false audioEngine: false
}); });
this._engine.enableOfflineSupport = false; //removed for event handling
//this._engine.enableOfflineSupport = false;
this._scene = new BABYLON.Scene(this._engine); this._scene = new BABYLON.Scene(this._engine);
this._scene.clearColor = new BABYLON.Color4(88/255,171/255,217/255,255/255); this._scene.clearColor = new BABYLON.Color4(88/255,171/255,217/255,255/255);
this._scene.collisionsEnabled = true; //removed for event handling
//this._scene.collisionsEnabled = true;
// Lights // Lights
var hemi_north = new BABYLON.HemisphericLight( var hemi_north = new BABYLON.HemisphericLight(
"hemiN", new BABYLON.Vector3(1, -1, 1), this._scene); "hemiN", new BABYLON.Vector3(1, -1, 1), this._scene);
...@@ -274,9 +277,12 @@ var GameManager = /** @class */ (function () { ...@@ -274,9 +277,12 @@ var GameManager = /** @class */ (function () {
camera = new BABYLON.ArcRotateCamera("camera", x_rotation, 1.25, radius, camera = new BABYLON.ArcRotateCamera("camera", x_rotation, 1.25, radius,
target, this._scene); target, this._scene);
camera.wheelPrecision = 10; camera.wheelPrecision = 10;
camera.attachControl(this._scene.getEngine().getRenderingCanvas()); //changed for event handling
//camera.attachControl(this._scene.getEngine().getRenderingCanvas()); //original
camera.attachControl(canvas, true);
camera.maxz = 40000; camera.maxz = 40000;
this._camera = camera; this._camera = camera;
// Render loop // Render loop
this._engine.runRenderLoop(function () { this._engine.runRenderLoop(function () {
_this._scene.render(); _this._scene.render();
......
...@@ -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.10032.46857.65518</string> </value> <value> <string>1003.14332.42567.56439</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>1663944101.22</float> <float>1664202073.56</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -4,6 +4,89 @@ ...@@ -4,6 +4,89 @@
DroneGameManager*/ DroneGameManager*/
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */ /*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*************************************************************************/
/**************************** ROQUE WW EVENTS ****************************/
/*************************************************************************/
console.log("WITH EVENTS");
self.window = {
addEventListener: function (event, fn, opt) {
bindHandler('window', event, fn, opt);
},
setTimeout: self.setTimeout.bind(self),
PointerEvent: true
};
self.document = {
addEventListener: function (event, fn, opt) {
bindHandler('document', event, fn, opt);
},
// Uses to detect wheel event like at src/Inputs/scene.inputManager.ts:797
createElement: function () {
return {onwheel: true};
},
defaultView: self.window,
};
importScripts('babylon.js', 'babylon.gui.js');
importScripts('rsvp.js',
'GameManager.js',
'DroneManager.js',
'MapManager.js',
'ObstacleManager.js',
'DroneAaileFixeAPI.js',
'DroneLogAPI.js',
'DroneAPI.js',
'gadget_erp5_page_game_logic.js');
function mainToWorker(evt) {
switch (evt.data.type) {
case 'start':
var offscreen_canvas = prepareCanvas(evt.data);
RSVP = window.RSVP;
return new RSVP.Queue()
.push(function () {
return runGame(offscreen_canvas, evt.data.script,
evt.data.game_parameters_json, evt.data.log);
})
.push(function () {
return postMessage({'type': 'started'});
});
break;
case 'update':
return new RSVP.Queue()
.push(function () {
return updateGame();
})
.push(function () {
return postMessage({'type': 'updated'});
});
break;
case 'event':
handleEvent(evt.data);
break;
default:
throw new Error('Unsupported message ' + JSON.stringify(evt.data));
}
};
/*****************************************************************************/
/************************************************************************/
/***************************** WORKING GAME *****************************/
/************************************************************************/
/*console.log("WORKING GAME WITH NO EVENTS");
var document = { var document = {
addEventListener: function () {}, addEventListener: function () {},
createElement: function () {} createElement: function () {}
...@@ -79,7 +162,11 @@ function mainToWorker(evt) { ...@@ -79,7 +162,11 @@ function mainToWorker(evt) {
default: default:
throw new Error('Unsupported message ' + JSON.stringify(evt.data)); throw new Error('Unsupported message ' + JSON.stringify(evt.data));
} }
}; };*/
/*****************************************************************************/
// Doesn't work without it // Doesn't work without it
class HTMLElement {} class HTMLElement {}
......
...@@ -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.10284.59408.13346</string> </value> <value> <string>1003.14300.40470.3601</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>1663959195.15</float> <float>1664202107.66</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