From cd10d76d899b8ae1fa4f6c856f40220463190921 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Thu, 9 Jul 2015 15:38:56 +0200 Subject: [PATCH] More log --- js/l3d/apps/prototype/ButtonManager.js | 5 ++++ js/l3d/src/cameras/PointerCamera.js | 16 +++++++++++ js/l3d/src/utils/Logger.js | 21 +++++++++++++++ posts/fps/index.js | 4 +-- posts/pointer-locked/index.js | 21 +++++++++++++++ posts/pointer-locked/urls.js | 3 +++ posts/switched-lock-option/index.js | 21 +++++++++++++++ posts/switched-lock-option/urls.js | 3 +++ sql/backup.pgsql | 37 +++++++++++++++++++------- 9 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 posts/pointer-locked/index.js create mode 100644 posts/pointer-locked/urls.js create mode 100644 posts/switched-lock-option/index.js create mode 100644 posts/switched-lock-option/urls.js diff --git a/js/l3d/apps/prototype/ButtonManager.js b/js/l3d/apps/prototype/ButtonManager.js index bfaeef1..4210702 100644 --- a/js/l3d/apps/prototype/ButtonManager.js +++ b/js/l3d/apps/prototype/ButtonManager.js @@ -32,6 +32,11 @@ var ButtonManager = function(camera, cameras, previewer) { self.pointerLockElement.onchange = function() { self.camera.shouldLock = self.pointerLockElement.checked; self.camera.onPointerLockChange(); + + // Log + var event = new L3D.BD.Event.SwitchedLockOption(); + event.locked = self.pointerLockElement.checked; + event.send(); }; self.showarrowsElement.onchange = function() {self.showArrows = self.showarrowsElement.checked;}; diff --git a/js/l3d/src/cameras/PointerCamera.js b/js/l3d/src/cameras/PointerCamera.js index 7c51d06..47130a5 100644 --- a/js/l3d/src/cameras/PointerCamera.js +++ b/js/l3d/src/cameras/PointerCamera.js @@ -223,6 +223,7 @@ L3D.PointerCamera.prototype.isLocked = function() { * Update the camera when the pointer lock changes state */ L3D.PointerCamera.prototype.onPointerLockChange = function() { + var event = new L3D.BD.Event.PointerLocked(); if (this.isLocked()) { @@ -236,6 +237,14 @@ L3D.PointerCamera.prototype.onPointerLockChange = function() { // Remove start canvas this.startCanvas.clear(); + // Send event + event.locked = true; + + if (this.wasLocked !== event.locked) + event.send(); + + this.wasLocked = true; + } else { this.pointerLocked = false; @@ -250,8 +259,15 @@ L3D.PointerCamera.prototype.onPointerLockChange = function() { else this.startCanvas.clear(); + event.locked = false; + + if (this.wasLocked !== event.locked) + event.send(); + + this.wasLocked = false; } + }; /** diff --git a/js/l3d/src/utils/Logger.js b/js/l3d/src/utils/Logger.js index 9d7b55c..41cdcf3 100644 --- a/js/l3d/src/utils/Logger.js +++ b/js/l3d/src/utils/Logger.js @@ -114,3 +114,24 @@ L3D.BD.Event.Fps.prototype.send = function() { L3D.BD.Private.sendData(url, data); }; + +L3D.BD.Event.PointerLocked = function() {}; +L3D.BD.Event.PointerLocked.prototype.send = function() { + var url = "/pointer-locked"; + var data = { + locked: this.locked + }; + + L3D.BD.Private.sendData(url, data); +}; + +L3D.BD.Event.SwitchedLockOption = function() {}; +L3D.BD.Event.SwitchedLockOption.prototype.send = function() { + var url = "/switched-lock-option"; + + var data = { + locked: this.locked + }; + + L3D.BD.Private.sendData(url, data); +} diff --git a/posts/fps/index.js b/posts/fps/index.js index d94d85c..654be78 100644 --- a/posts/fps/index.js +++ b/posts/fps/index.js @@ -6,8 +6,8 @@ module.exports.index = function(req, res) { pg.connect(secret.url, function(err, client, release) { client.query( - "INSERT INTO fpscounter(exp_id, fps) VALUES($1,$2);", - [req.session.exp_id, req.body.fps], + "INSERT INTO fpscounter(exp_id, fps, time) VALUES($1,$2,to_timestamp($3));", + [req.session.exp_id, req.body.fps, req.body.time], function(err, result) { if (err !== null) Log.dberror(err + ' in fps'); diff --git a/posts/pointer-locked/index.js b/posts/pointer-locked/index.js new file mode 100644 index 0000000..1008d37 --- /dev/null +++ b/posts/pointer-locked/index.js @@ -0,0 +1,21 @@ +var pg = require('pg'); +var secret = require('../../private'); +var Log = require('../../lib/NodeLog.js'); + +module.exports.index = function(req, res) { + + pg.connect(secret.url, function(err, client, release) { + client.query( + "INSERT INTO pointerlocked(exp_id, locked, time) VALUES($1,$2,to_timestamp($3));", + [req.session.exp_id, req.body.locked, req.body.time], + function(err, result) { + if (err !== null) + Log.dberror(err + ' in fps'); + release(); + } + ); + }); + + res.setHeader('Content-Type', 'text/html'); + res.send(""); +}; diff --git a/posts/pointer-locked/urls.js b/posts/pointer-locked/urls.js new file mode 100644 index 0000000..8aaecbd --- /dev/null +++ b/posts/pointer-locked/urls.js @@ -0,0 +1,3 @@ +module.exports = { + '/pointer-locked': 'index' +}; diff --git a/posts/switched-lock-option/index.js b/posts/switched-lock-option/index.js new file mode 100644 index 0000000..4b993f2 --- /dev/null +++ b/posts/switched-lock-option/index.js @@ -0,0 +1,21 @@ +var pg = require('pg'); +var secret = require('../../private'); +var Log = require('../../lib/NodeLog.js'); + +module.exports.index = function(req, res) { + + pg.connect(secret.url, function(err, client, release) { + client.query( + "INSERT INTO switchedlockoption(exp_id, locked, time) VALUES($1,$2,to_timestamp($3));", + [req.session.exp_id, req.body.locked, req.body.time], + function(err, result) { + if (err !== null) + Log.dberror(err + ' in fps'); + release(); + } + ); + }); + + res.setHeader('Content-Type', 'text/html'); + res.send(""); +}; diff --git a/posts/switched-lock-option/urls.js b/posts/switched-lock-option/urls.js new file mode 100644 index 0000000..55e590a --- /dev/null +++ b/posts/switched-lock-option/urls.js @@ -0,0 +1,3 @@ +module.exports = { + '/switched-lock-option': 'index' +}; diff --git a/sql/backup.pgsql b/sql/backup.pgsql index 11ac907..7349b2f 100644 --- a/sql/backup.pgsql +++ b/sql/backup.pgsql @@ -1,14 +1,16 @@ -- Clear database from previous tables (just in case...) -DROP TABLE IF EXISTS users CASCADE; -DROP TABLE IF EXISTS arrowclicked CASCADE; -DROP TABLE IF EXISTS coinclicked CASCADE; -DROP TABLE IF EXISTS keyboardevent CASCADE; -DROP TABLE IF EXISTS resetclicked CASCADE; -DROP TABLE IF EXISTS previousnextclicked CASCADE; -DROP TABLE IF EXISTS hovered CASCADE; -DROP TABLE IF EXISTS scene CASCADE; -DROP TABLE IF EXISTS experiment CASCADE; -DROP TABLE IF EXISTS fpscounter CASCADE; +DROP TABLE IF EXISTS Users CASCADE; +DROP TABLE IF EXISTS Arrowclicked CASCADE; +DROP TABLE IF EXISTS CoinClicked CASCADE; +DROP TABLE IF EXISTS KeyboardEvent CASCADE; +DROP TABLE IF EXISTS ResetClicked CASCADE; +DROP TABLE IF EXISTS PreviousNextClicked CASCADE; +DROP TABLE IF EXISTS Hovered CASCADE; +DROP TABLE IF EXISTS Scene CASCADE; +DROP TABLE IF EXISTS Experiment CASCADE; +DROP TABLE IF EXISTS FpsCounter CASCADE; +DROP TABLE IF EXISTS PointerLocked CASCADE; +DROP TABLE IF EXISTS SwitchedLockOption CASCADE; DROP TYPE IF EXISTS VECTOR3 CASCADE; DROP TYPE IF EXISTS CAMERA CASCADE; @@ -100,5 +102,20 @@ CREATE TABLE hovered( CREATE TABLE fpscounter( id SERIAL PRIMARY KEY, exp_id SERIAL REFERENCES experiment (id), + time TIMESTAMP DEFAULT NOW(), fps REAL ); + +CREATE TABLE pointerlocked( + id SERIAL PRIMARY KEY, + exp_id SERIAL REFERENCES experiment (id), + time TIMESTAMP DEFAULT NOW(), + locked BOOLEAN +); + +CREATE TABLE switchedlockoption( + id SERIAL PRIMARY KEY, + exp_id SERIAL REFERENCES experiment (id), + time TIMESTAMP DEFAULT NOW(), + locked BOOLEAN +);