Saturday, June 26, 2010

Refreshing Comet Sessions in Fab.js

‹prev | My Chain | next›

Today is minor bug day in my (fab) game. First up, my player seem to be hitting a wall well before the bottom of the room. That turns out to be a simple matter of adding the scroll amount to the screen coordinates where I ought to be subtracting:
    var c_x = avatar.attr("cx") +
$(self.avatar.paper.canvas).parent().offset().left +
$(document).scrollLeft()
;

var c_y = avatar.attr("cy") +
$(self.avatar.paper.canvas).parent().offset().top +
$(document).scrollTop()
;
Sigh. I do not believe that I will ever be able to know when to add or subtract browser coordinates. I may forever be doomed to try one, fail, then go with the right way:
    var c_x = avatar.attr("cx") +
$(self.avatar.paper.canvas).parent().offset().left -
$(document).scrollLeft()
;

var c_y = avatar.attr("cy") +
$(self.avatar.paper.canvas).parent().offset().top -
$(document).scrollTop()
;
Next up, I am having trouble reloading the game.

For each player in my (fab) game, the backend keeps track of the comet <iframe> so that it can broadcast changes. We have noticed of late that reloading the game does not reload the comet <iframe>.

Hrm.. I eventually track this down to the code that adds players:
function broadcast_new (app) {
return function () {
var out = this;

return app.call( function listener(obj) {
if (obj && obj.body && obj.body.id) {
var new_id = obj.body.id;

if (!players[new_id]) {
puts("[broadcast_new] adding: " + new_id);

// Add player to local store
}

}
else {
out(obj);
}
return listener;
});
};
}
The problem, of course, is that the player is already in the local store so it will not re-added when the page is reloaded.

For now, I will remove the conditional. That will make it easy for others to impersonate players, so I will have to come up with another strategy, but I will leave that for another day.


Day #146

No comments:

Post a Comment