Commit 97e719e7 by Alexander Bazo

Fix task duration bug

parent 1c8175b3
...@@ -14,14 +14,8 @@ class ImageViewerState extends Schema { ...@@ -14,14 +14,8 @@ class ImageViewerState extends Schema {
this.task = null; this.task = null;
} }
setTask(task, onFinish) { setTask(task) {
this.task = task; this.task = task;
currentCallback = onFinish;
setTimeout(this.onTaskFinished, task.duration);
}
onTaskFinished() {
currentCallback();
} }
} }
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
const MAX_GAZE_POINT_AGE = 4000, const MAX_GAZE_POINT_AGE = 4000,
// Set max update intervall to ~ 30FPS // Set max update intervall to ~ 30FPS
GAZE_POINT_UPDATE_DELAY = 1000 / 32; GAZE_POINT_UPDATE_DELAY = 1000 / 32,
DEFAULT_TASK_DURATION = 30000;
const colyseus = require("colyseus"), const colyseus = require("colyseus"),
Logger = require("../utils/Logger.js"), Logger = require("../utils/Logger.js"),
...@@ -16,9 +17,11 @@ var tasks = Task.getTasks(), ...@@ -16,9 +17,11 @@ var tasks = Task.getTasks(),
availableTasks, availableTasks,
currentTask, currentTask,
currentTaskIndex, currentTaskIndex,
currentTaskStartTime,
gazePoints, gazePoints,
gazeSubscribers, gazeSubscribers,
lastGazePointUpdate = 0; lastGazePointUpdate = 0,
context;
class ImageViewerRoom extends colyseus.Room { class ImageViewerRoom extends colyseus.Room {
...@@ -30,6 +33,7 @@ class ImageViewerRoom extends colyseus.Room { ...@@ -30,6 +33,7 @@ class ImageViewerRoom extends colyseus.Room {
this.setState(new ImageViewerState()); this.setState(new ImageViewerState());
this.setSimulationInterval(this.update.bind(this), ServerConfiguration.getUpdateInterval()); this.setSimulationInterval(this.update.bind(this), ServerConfiguration.getUpdateInterval());
this.setTask(); this.setTask();
context = this;
} }
createTasks() { createTasks() {
...@@ -50,7 +54,8 @@ class ImageViewerRoom extends colyseus.Room { ...@@ -50,7 +54,8 @@ class ImageViewerRoom extends colyseus.Room {
if (message.type === "gaze") { if (message.type === "gaze") {
if (client.color === undefined) { if (client.color === undefined) {
client.color = Colors.getNextColor(); client.color = Colors.getNextColor();
Logger.log(`Assign client color: ${client.color}`, "ImageViewer Room"); Logger.log(`Assign client color: ${client.color}`,
"ImageViewer Room");
} }
message.data.color = client.color; message.data.color = client.color;
let point = GazePoint.fromClientData(message.data); let point = GazePoint.fromClientData(message.data);
...@@ -104,6 +109,7 @@ class ImageViewerRoom extends colyseus.Room { ...@@ -104,6 +109,7 @@ class ImageViewerRoom extends colyseus.Room {
} }
} }
lastGazePointUpdate = now; lastGazePointUpdate = now;
this.setTask();
} }
updateGazePoints(now) { updateGazePoints(now) {
...@@ -118,16 +124,24 @@ class ImageViewerRoom extends colyseus.Room { ...@@ -118,16 +124,24 @@ class ImageViewerRoom extends colyseus.Room {
} }
setTask() { setTask() {
if (currentTask === undefined) {
currentTask = availableTasks[currentTaskIndex];
Logger.log("Sending current task to state", "ImageViewrRoom"); Logger.log("Sending current task to state", "ImageViewrRoom");
// Cycle through available tasks this.state.setTask(currentTask, this.onTaskFinished.bind(this));
currentTaskStartTime = Date.now();
return;
}
if ((Date.now() - currentTaskStartTime) >= DEFAULT_TASK_DURATION) {
Logger.log("Switching task", "ImageViewrRoom");
currentTaskIndex += 1; currentTaskIndex += 1;
if (currentTaskIndex >= availableTasks.length) { if (currentTaskIndex >= availableTasks.length) {
currentTaskIndex = 0; currentTaskIndex = 0;
} }
currentTask = availableTasks[currentTaskIndex]; currentTask = availableTasks[currentTaskIndex];
// Send task to state to auto update clients Logger.log("Sending current task to state", "ImageViewrRoom");
// Set listener for task change event (is based on task's duration property)
this.state.setTask(currentTask, this.onTaskFinished.bind(this)); this.state.setTask(currentTask, this.onTaskFinished.bind(this));
currentTaskStartTime = Date.now();
}
} }
} }
......
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