Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jochen Bauer
spn-website
Commits
a8f87bd5
Commit
a8f87bd5
authored
May 05, 2018
by
Hubert Denkmair
Browse files
ensure that GameInfo message is processed first.
parent
4f677807
Changes
2
Hide whitespace changes
Inline
Side-by-side
visualization/static/visualization/Game.js
View file @
a8f87bd5
...
...
@@ -8,6 +8,8 @@ function Game(assets, snakeMoveStrategy, container)
this
.
viewer_key
=
0
;
this
.
vis
=
new
GameVisualization
(
assets
,
snakeMoveStrategy
,
container
);
this
.
logHandlers
=
[];
this
.
gameInfoReceived
=
false
;
this
.
preGameInfoMessages
=
[];
}
Game
.
prototype
.
AddLogHandler
=
function
(
callback
,
thisArg
)
...
...
@@ -57,6 +59,21 @@ Game.prototype.SetViewerKey = function(key)
Game
.
prototype
.
HandleMessage
=
function
(
event
)
{
let
data
=
JSON
.
parse
(
event
.
data
);
if
(
data
.
t
==
"
GameInfo
"
)
{
this
.
gameInfoReceived
=
true
;
this
.
vis
.
HandleGameInfoMessage
(
data
.
world_size_x
,
data
.
world_size_y
,
data
.
food_decay_per_frame
);
while
(
this
.
preGameInfoMessages
.
length
>
0
)
{
this
.
HandleMessage
(
this
.
preGameInfoMessages
.
pop
());
}
}
else
if
(
!
this
.
gameInfoReceived
)
{
this
.
preGameInfoMessages
.
push
(
event
);
return
;
}
switch
(
data
.
t
)
{
case
"
GameInfo
"
:
...
...
visualization/static/visualization/GameVisualization.js
View file @
a8f87bd5
...
...
@@ -33,7 +33,6 @@ function GameVisualization(assets, snakeMoveStrategy, container)
this
.
mainStage
=
new
PIXI
.
Container
();
this
.
app
.
stage
.
addChild
(
this
.
mainStage
);
this
.
segmentPool
=
new
ObjectPool
(
function
()
{
return
new
SnakeSegment
(
this
.
txBody
);
},
this
,
10000
);
...
...
@@ -91,6 +90,7 @@ GameVisualization.prototype.RemoveSnake = function(id)
GameVisualization
.
prototype
.
HandleGameInfoMessage
=
function
(
world_size_x
,
world_size_y
,
food_decay_rate
)
{
console
.
log
(
"
GameInfo received
"
);
this
.
world_size_x
=
world_size_x
;
this
.
world_size_y
=
world_size_y
;
this
.
food_decay_rate
=
food_decay_rate
;
...
...
@@ -134,6 +134,7 @@ GameVisualization.prototype.HandleTickMessage = function(frame_id)
GameVisualization
.
prototype
.
HandleWorldUpdateMessage
=
function
(
data
)
{
console
.
log
(
"
WorldUpdate received
"
);
for
(
let
id
in
data
.
bots
)
{
let
bot
=
data
.
bots
[
id
];
...
...
Write
Preview
Supports
Markdown
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