Commit a8f87bd5 authored by Hubert Denkmair's avatar Hubert Denkmair
Browse files

ensure that GameInfo message is processed first.

parent 4f677807
......@@ -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":
......
......@@ -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];
......
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 to comment