Commit b4578190 by Alexander Bazo

Refactoring

parent 9ab70573
/* eslint-env node */
const TASKS = [{
imageUrl: "images/Brueghel-The_Dutch_Proverbs.jpg",
taskDescription: "Suchen Sie nach bildlichen Darstellungen niederländischer Sprichwörter des 16. Jahrhunderts.",
taskSource: "Pieter Bruegel the Elder, Netherlandish Proverbs (Oil on oak wood, 1599), Gemäldegalerie, Berlin",
duration: 30000,
}],
MAX_GAZE_POINT_AGE = 2000,
const MAX_GAZE_POINT_AGE = 2000,
GAZE_POINT_UPDATE_DELAY = 250;
const colyseus = require("colyseus"),
......@@ -16,7 +10,8 @@ const colyseus = require("colyseus"),
Task = require("../logic/Task.js"),
ImageViewerState = require("../logic/ImageViewerState.js");
var availableTasks,
var tasks = Task.getTasks(),
availableTasks,
currentTask,
currentTaskIndex,
gazePoints,
......@@ -37,9 +32,9 @@ class ImageViewerRoom extends colyseus.Room {
createTasks() {
availableTasks = [];
for (let i = 0; i < TASKS.length; i++) {
availableTasks.push(new Task(TASKS[i].imageUrl, TASKS[i].taskDescription,
TASKS[i].taskSource, TASKS[i].duration));
for (let i = 0; i < tasks.length; i++) {
availableTasks.push(new Task(tasks[i].imageUrl, tasks[i].taskDescription,
tasks[i].taskSource, tasks[i].duration));
}
currentTaskIndex = 0;
}
......@@ -76,18 +71,24 @@ class ImageViewerRoom extends colyseus.Room {
this.setTask();
}
// Run on each tick (~30FPS)
update() {
let now = Date.now();
// Remove old gaze points
this.updateGazePoints(now);
// Sanity check to prevent empty updates to subscribers
if(gazePoints.length === 0) {
return;
}
// Sanity check to prevent high frequency gaze updates to subscribers
if(now - lastGazePointUpdate < GAZE_POINT_UPDATE_DELAY) {
return;
}
for (let i = 0; i < gazeSubscribers.length; i++) {
let client = gazeSubscribers[i];
Logger.log(`${gazePoints.length} gaze points available`);
if (client && gazePoints.length > 0) {
Logger.log(`Sending ${gazePoints.length} gaze points to subsriber`, "ImageViewer Room");
this.send(client,{
if (gazeSubscribers[i]) {
Logger.log(`Sending ${gazePoints.length} gaze points to subscriber`, "ImageViewer Room");
this.send(gazeSubscribers[i],{
type: "gazelist",
data: gazePoints,
});
......@@ -109,11 +110,14 @@ class ImageViewerRoom extends colyseus.Room {
setTask() {
Logger.log("Sending current task to state", "ImageViewrRoom");
// Cycle through available tasks
currentTaskIndex += 1;
if (currentTaskIndex >= availableTasks.length) {
currentTaskIndex = 0;
}
currentTask = availableTasks[currentTaskIndex];
// Send task to state to auto update clients
// Set listener for task change event (is based on task's duration property)
this.state.setTask(currentTask, this.onTaskFinished.bind(this));
}
}
......
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 sign in to comment