Commit 49bb8651 authored by Thomas Marrinan's avatar Thomas Marrinan

Merge branch 'master' of https://bitbucket.org/sage2/sage2


Former-commit-id: 9e3a36d3f307dd198e22b2532271dc7724ac9bb2
parents 7833cb6f 1b997e68
......@@ -116,10 +116,13 @@
});
wsio.on('initialize', function(data) {
var startTime = new Date(data.start);
var serverTime = new Date(data.time);
var clientTime = new Date();
dt = clientTime - serverTime;
Math.seed(startTime.getTime());
});
wsio.on('setupDisplayConfiguration', function(json_cfg) {
......@@ -686,6 +689,20 @@
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
Math.seed = function(s) {
Math.random = function() {
// POSIX drand48 ==> Xn+1 = (a*Xn+c) % m
var a = 25214903917;
var c = 11;
var m = 281474976710656;
s = (a*s+c) % m;
return s / m;
//s = Math.sin(s) * 10000; return s - Math.floor(s);
}
};
</script>
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
......
......@@ -8,14 +8,6 @@
// http://opensource.org/licenses/BSD-3-Clause
// See included LICENSE.txt file
// New seeded Math.random function
Math.seed = function(s) {
Math.random = function() {
s = Math.sin(s) * 10000; return s - Math.floor(s);
}
};
var SAGE2_App = Class.extend( {
construct: function() {
this.div = null;
......@@ -50,8 +42,6 @@ var SAGE2_App = Class.extend( {
this.startDate = date;
this.prevDate = date;
this.frame = 0;
// Seed the number generator based on current time
Math.seed(date.getTime());
},
preDraw: function(date) {
......
......@@ -68,6 +68,9 @@ var texture_cube = SAGE2_App.extend( {
this.roty = null;
this.resizeEvents = "continuous";
this.webglContextLost = this.webglContextLostMethod.bind(this);
this.webglContextRestored = this.webglContextRestoredMethod.bind(this);
},
init: function(id, width, height, resrc, date) {
......@@ -77,6 +80,9 @@ var texture_cube = SAGE2_App.extend( {
// application specific 'init'
this.initGL();
if(this.gl){
this.element.addEventListener("webglcontextlost", this.webglContextLost, false);
this.element.addEventListener("webglcontextrestored", this.webglContextRestored, false);
this.initShaders();
this.initLighting();
this.initBuffers();
......@@ -117,6 +123,16 @@ var texture_cube = SAGE2_App.extend( {
}
},
webglContextLostMethod: function(event) {
console.log("WebGL Context Lost");
console.log(event);
},
webglContextRestoredMethod: function(event) {
console.log("WebGL Context Restored");
console.log(event);
},
initShaders: function() {
var fragmentShader = this.getShader(shader_fs, "x-shader/x-fragment");
var vertexShader = this.getShader(shader_vs, "x-shader/x-vertex");
......
......@@ -95,6 +95,8 @@ var options = setupHttpsOptions();
var index = http.createServer(httpServerIndex.onrequest);
var server = https.createServer(options, httpsServerApp.onrequest);
var startTime = new Date();
// creates a WebSocket server - 2 way communication between server and all browser clients
var wsioServer = new websocketIO.Server({server: server});
......@@ -177,7 +179,7 @@ function wsAddClient(wsio, data) {
function initializeWSClient(wsio) {
var uniqueID = wsio.remoteAddress.address + ":" + wsio.remoteAddress.port;
wsio.emit('initialize', {UID: uniqueID, time: new Date()});
wsio.emit('initialize', {UID: uniqueID, time: new Date(), start: startTime});
// set up listeners based on what the client sends
if(wsio.messages.sendsPointerData){
......
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