Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Eye-Tracking Classroom
/
StarGazer-Server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
084add1b
authored
Oct 10, 2019
by
Alexander Bazo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle gaze data from clients
parent
6e825baf
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
13 deletions
+32
-13
index.js
+5
-2
lib/game/GazePoint.js
+12
-4
lib/game/StarGazerState.js
+5
-1
lib/rooms/StarGazerRoom.js
+10
-6
No files found.
index.js
View file @
084add1b
...
@@ -14,7 +14,7 @@ var app = express(),
...
@@ -14,7 +14,7 @@ var app = express(),
server
=
http
.
createServer
(
app
),
server
=
http
.
createServer
(
app
),
gameServer
;
gameServer
;
Logger
.
enable
();
//
Logger.enable();
app
.
use
(
cors
());
app
.
use
(
cors
());
app
.
use
(
express
.
json
());
app
.
use
(
express
.
json
());
...
@@ -29,7 +29,9 @@ gameServer.define(Config.getGameRoomName(), StarGazerRoom);
...
@@ -29,7 +29,9 @@ gameServer.define(Config.getGameRoomName(), StarGazerRoom);
app
.
use
(
Config
.
getSocialRoute
(),
socialRoutes
);
app
.
use
(
Config
.
getSocialRoute
(),
socialRoutes
);
app
.
use
(
Config
.
getMonitorRoute
(),
monitor
(
gameServer
));
app
.
use
(
Config
.
getMonitorRoute
(),
monitor
(
gameServer
));
// Prrobably shoud be set after game server is created
// Prrobably shoud be set after game server is created
app
.
use
(
Config
.
getGameRoute
(),
express
.
static
(
Config
.
getGamePath
()));
app
.
use
(
Config
.
getGameRoute
(),
express
.
static
(
Config
.
getGamePath
(),
{
maxAge
:
100
}));
gameServer
.
listen
(
Config
.
getPort
());
gameServer
.
listen
(
Config
.
getPort
());
Logger
.
log
(
`Listening on ws://localhost:
${
Config
.
getPort
()
}
`
,
"Server"
);
Logger
.
log
(
`Listening on ws://localhost:
${
Config
.
getPort
()
}
`
,
"Server"
);
\ No newline at end of file
lib/game/GazePoint.js
View file @
084add1b
...
@@ -3,11 +3,18 @@ const Schema = schema.Schema;
...
@@ -3,11 +3,18 @@ const Schema = schema.Schema;
class
GazePoint
extends
Schema
{
class
GazePoint
extends
Schema
{
constructor
(
screenX
,
screenY
)
{
constructor
(
screenX
,
screenY
,
createdAt
,
player
,
id
)
{
super
();
this
.
screenX
=
screenX
;
this
.
screenX
=
screenX
;
this
.
screenY
=
screenY
;
this
.
screenY
=
screenY
;
this
.
createdAt
=
Date
.
now
();
this
.
createdAt
=
createdAt
;
this
.
id
=
this
.
createdAt
;
this
.
player
=
player
;
this
.
id
=
id
;
this
.
relativeAge
=
0
;
}
static
fromClientData
(
data
)
{
return
new
GazePoint
(
data
.
screenX
,
data
.
screenY
,
data
.
createdAt
,
data
.
player
,
data
.
id
);
}
}
}
}
...
@@ -16,7 +23,8 @@ schema.defineTypes(GazePoint, {
...
@@ -16,7 +23,8 @@ schema.defineTypes(GazePoint, {
screenX
:
"number"
,
screenX
:
"number"
,
screenY
:
"number"
,
screenY
:
"number"
,
createdAt
:
"number"
,
createdAt
:
"number"
,
player
:
"text"
,
relativeAge
:
"number"
,
player
:
"string"
,
id
:
"number"
,
id
:
"number"
,
});
});
...
...
lib/game/StarGazerState.js
View file @
084add1b
...
@@ -22,6 +22,10 @@ class StarGazerState extends Schema {
...
@@ -22,6 +22,10 @@ class StarGazerState extends Schema {
this
.
lastEnemySpawn
=
0
;
this
.
lastEnemySpawn
=
0
;
}
}
addGazePoint
(
gazePoint
)
{
this
.
gazePoints
.
push
(
gazePoint
);
}
update
(
deltaTime
)
{
update
(
deltaTime
)
{
let
now
=
Date
.
now
(),
let
now
=
Date
.
now
(),
delta
=
now
-
this
.
lastUpdate
;
delta
=
now
-
this
.
lastUpdate
;
...
@@ -32,7 +36,7 @@ class StarGazerState extends Schema {
...
@@ -32,7 +36,7 @@ class StarGazerState extends Schema {
updateGazePoints
(
now
)
{
updateGazePoints
(
now
)
{
for
(
let
i
=
this
.
gazePoints
.
length
-
1
;
i
>=
0
;
i
--
)
{
for
(
let
i
=
this
.
gazePoints
.
length
-
1
;
i
>=
0
;
i
--
)
{
let
age
=
now
-
gazePoints
[
i
].
createdAt
;
let
age
=
now
-
this
.
gazePoints
[
i
].
createdAt
;
if
(
age
>
GameConfig
.
getMaxGazePointAge
())
{
if
(
age
>
GameConfig
.
getMaxGazePointAge
())
{
this
.
gazePoints
.
splice
(
i
,
1
);
this
.
gazePoints
.
splice
(
i
,
1
);
}
else
{
}
else
{
...
...
lib/rooms/StarGazerRoom.js
View file @
084add1b
const
colyseus
=
require
(
"colyseus"
),
const
colyseus
=
require
(
"colyseus"
),
Logger
=
require
(
"../utils/Logger.js"
);
GazePoint
=
require
(
"../game/GazePoint.js"
);
StarGazerState
=
require
(
"../game/StarGazerState.js"
);
StarGazerState
=
require
(
"../game/StarGazerState.js"
);
var
deltaTime
;
var
deltaTime
;
...
@@ -6,26 +8,28 @@ var deltaTime;
...
@@ -6,26 +8,28 @@ var deltaTime;
class
StarGazerRoom
extends
colyseus
.
Room
{
class
StarGazerRoom
extends
colyseus
.
Room
{
onCreate
(
options
)
{
onCreate
(
options
)
{
console
.
log
(
"in: onCreate"
);
Logger
.
log
(
"Creating StarGazerRoom"
,
"Game Room"
);
console
.
log
(
this
);
this
.
setSimulationInterval
(
this
.
update
.
bind
(
this
));
this
.
setSimulationInterval
(
this
.
update
.
bind
(
this
));
this
.
setState
(
new
StarGazerState
());
this
.
setState
(
new
StarGazerState
());
}
}
onJoin
(
client
,
options
)
{
onJoin
(
client
,
options
)
{
console
.
log
(
"in: onJoin
"
);
Logger
.
log
(
`Player
${
client
.
sessionId
}
joined StarGazerRoom`
,
"Game Room
"
);
}
}
onMessage
(
client
,
message
)
{
onMessage
(
client
,
message
)
{
console
.
log
(
"in: onMessage"
);
if
(
message
.
type
===
"gaze"
)
{
message
.
data
.
player
=
client
.
id
;
this
.
state
.
addGazePoint
(
GazePoint
.
fromClientData
(
message
.
data
));
}
}
}
onLeave
(
client
,
consented
)
{
onLeave
(
client
,
consented
)
{
console
.
log
(
"in: onLeave
"
);
Logger
.
log
(
`Player
${
client
.
sessionId
}
left StarGazerRoom`
,
"Game Room
"
);
}
}
onDispose
()
{
onDispose
()
{
console
.
log
(
"in: onDispose
"
);
Logger
.
log
(
"Disposing StarGazerRoom"
,
"Game Room
"
);
}
}
startGame
()
{
startGame
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment