Welcome to the Browser-Base Game Zone forums!
$(document).ready(function(){ // Gogo recursive ajax (function(){ var updateWorld = function(){ $.getJSON('http://www.example.com/data.json', function(){ setTimeout(function(data){ console.log(data); updateWorld(); }, 1000); }) }; updateWorld(); })();});
SELECT *FROM world as wWHERE w.x > 50 AND w.x < 100 AND w.y > 50 AND w.y < 100// this can get a lot more sophisticated, by doing a subselect to find a specific user, then using that character's location as the base for the region-ing.
$(document).ready(function(){ // Gogo recursive ajax (function(){ var updateFrequency = 1000; var updateWorld = function(){ $.getJSON('http://www.example.com/data.json', function(){ setTimeout(function(data){ console.log(data); if (data.updateFrequency) { updateFrequency = data.updateFrequency; } updateWorld(); }, updateFrequency); }) }; updateWorld(); })();});
@Harkins: Thanks for pointing out that removing unnecessary headers will reduce overhead of AJAX calls. Do you know how I can achieve that in PHP?
header_remove('Name')
Header unset Name
INSERTing commands into the message queue... and every five seconds (or some other arbitrary number) messages will be plucked from the queue and executed.
WRT the recursive function call... I know there aren't any arguments being passed to the function (so that'll help to reduce the amount of stack space that's eaten up) but surely the continuous recursive calls will eventually reduce the amount of stack space available. Or, have I missed something here? Once my UI is displayed, the Web page never refreshes; AJAX is the only method used to update the UI. :-s
<?php$data = array( 'updateFrequency'=> 2000, 'gold'=> 123456, 'troops'=> array( array( array( 'name'=> 'lolninja', 'type'=> 'ninja', 'x'=> 50, 'y'=> 50 ), array( 'name'=> 'someone else', 'type'=> 'warrior', 'x'=> 60, 'y'=> 40 ) ) ));echo json_encode($data);
{"updateFrequency":2000,"gold":123456,"troops":[[{"name":"lolninja","type":"ninja","x":50,"y":50},{"name":"someone else","type":"warrior","x":60,"y":40}]]}
$(document).ready(function(){ // Gogo recursive ajax (function(){ var updateFrequency = 1000; var updateWorld = function(){ $.getJSON('http://www.example.com/data.json', function(){ setTimeout(function(data){ if (data.updateFrequency) { updateFrequency = data.updateFrequency; } if (data.gold) { $('#gold').text(data.gold); } if (data.troops) { $(data.troops).each(function(id, troop){ var dom = $('#troops').find('#' + troop.name); if (!dom.hasClass(troop.type)) { dom.addClass(troop.type); } dom.animate({ left: troop.x, top: troop.y }); }); } updateWorld(); }, updateFrequency); }) }; updateWorld(); })();});
If there is nothing happening in a specific region you can return the header code 204 or 'No Content'. Which limits the data you send down the line.
QuoteINSERTing commands into the message queue... and every five seconds (or some other arbitrary number) messages will be plucked from the queue and executed. I do not make online games with maps, so I could be wrong, but I'm almost sure a simple "go to the next spot on the tiled map" could be done much, much simplier...
Quote from: Chris on June 25, 2010, 04:49:58 AMQuoteINSERTing commands into the message queue... and every five seconds (or some other arbitrary number) messages will be plucked from the queue and executed. I do not make online games with maps, so I could be wrong, but I'm almost sure a simple "go to the next spot on the tiled map" could be done much, much simplier...Yes, it could... if you want people to move across the map as fast as they can click, but that doesn't appear to be what the OP wants. If you don't want events to complete immediately when the user clicks, then you pretty much have to use some variation on "put the events into a queue and process them when the appropriate time comes".Which then gets into the "(pseudo-)real-time vs. action points" design question...