-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnowStuff.js
121 lines (96 loc) · 3.11 KB
/
nowStuff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function joinRoom(roomName) {
//join the room via node
now.changeRoom(roomName);
}
function getMyEquationInfo() {
var equationString = solver.problem.equationString;
var fixedVars = solver.baseSearchWindow.fixedVars;
var equationInfo = {
'equationString': equationString,
'fixedVars': fixedVars,
'fixAllBut2': false
};
return equationInfo;
}
function makeAndJoinRoom(roomName) {
//make the room, using our current variables
var equationInfo = getMyEquationInfo();
now.makeRoom(roomName, equationInfo);
//will join automatically once its made
}
function changeRoomEquation(equationInfo) {
if(window.now && now.receiveMessage)
{
now.receiveMessage("Changing room equation from your change");
}
//always divide up search space
if (window.now && window.now.position && window.now.total) {
solver.baseSearchWindow.divideUpSearchSpace(now.position, now.total);
}
if (!window.now || !window.now.changeEquation) {
console.log("returning");
return;
}
//update it, we will receive the equation as well but whatever
now.changeEquation(now.room, equationInfo);
}
function doNodeStuff() {
if (!window.now) {
console.log("no now.js detected, entering no-network mode");
}
now.ready(function () {
defineNowFunctions();
roomUpdate();
});
}
function defineNowFunctions() {
now.receiveNetworkMinimum = function (minPos) {
//go to the current solver's saver
if (!window.solver) {
return;
}
solver.minSaver.receiveNetworkMin(minPos);
};
now.receiveTotal = function (total) {
now.total = total;
//our position should be set
if (!now.position) {
alert("no position set! error");
return;
}
//now update the bounds on the main search window
solver.baseSearchWindow.divideUpSearchSpace(now.position, total);
now.receiveMessage("Dividing up search space with new total of " + String(total));
};
now.receiveRoom = function (room) {
//for some reason this isnt setting the room correctly...
now.room = room;
now.receiveMessage("Set room to " + room);
};
now.receiveEquation = function (equationInfo) {
console.log("equation info is", equationInfo);
now.receiveMessage("Changing equation to " + equationInfo.equationString);
changeOurEquation(equationInfo);
};
now.receiveMessage = function (message) {
//append to the message dom
$j('#networkMessages').prepend('<p>' + message + '</p>');
};
}
function roomUpdate() {
//first check if we are being linked to a room....
var href = window.location.href;
results = /room=(\w+)/.exec(href);
var room = null;
if (results) {
//we got linked to a room, go join it
room = results[1];
joinRoom(room);
} else {
//make room
room = randomString(5);
makeAndJoinRoom(room);
//link room
history.pushState(null, 'Genetic GPU!', "?room=" + room);
}
}