Skip to content
Browse files

Bug 736137: Fix player population counter issues

  • Loading branch information...
1 parent 2ce4c4d commit aa21e3c42b025b2e5154eccd9435718ad403a160 @sork sork committed Mar 15, 2012
Showing with 54 additions and 16 deletions.
  1. +1 −1 client/css/main.css
  2. +3 −3 client/index.html
  3. +0 −3 client/js/character.js
  4. +19 −0 client/js/main.js
  5. +19 −5 server/js/main.js
  6. +12 −4 server/js/metrics.js
View
2 client/css/main.css
@@ -161,7 +161,7 @@ footer, header, hgroup, menu, nav, section {
#playercount {font-family:'GraphicPixel';color:#e3e3e3;position:absolute;}
#playercount:hover {cursor:pointer;color:#FCE045;}
#population {background:url('../img/1/barsheet.png');image-rendering:-moz-crisp-edges;position:absolute;font-family:'GraphicPixel';color:#fff;text-align:center;opacity:0;pointer-events:none;-moz-transition:0.2s opacity linear, 0.2s height ease;-webkit-transition:0.2s opacity linear, 0.2s height ease;-o-transition:0.2s opacity linear, 0.2s height ease;-ms-transition:0.2s opacity linear, 0.2s height ease;transition:0.2s opacity linear, 0.2s height ease;height:0;overflow:hidden;}
- #population span {color:#FCE045;}
+ #population span:nth-child(1) {color:#FCE045;}
#population.visible {opacity:1;pointer-events:auto;}
.barbutton {background:url('../img/1/barsheet.png');image-rendering:-moz-crispt-edges;position:absolute;}
View
6 client/index.html
@@ -273,7 +273,7 @@ <h1 id="logo">
</div>
</div>
<div id="playercount" class="clickable">
- <span class="count">0</span> <span>online</span>
+ <span class="count">0</span> <span>players</span>
</div>
<div id="barbuttons">
<div id="chatbutton" class="barbutton clickable"></div>
@@ -289,10 +289,10 @@ <h1 id="logo">
</div>
<div id="population">
<div id="instance-population" class="">
- <span>75</span> players in your instance
+ <span>0</span> <span>players</span> in your instance
</div>
<div id="world-population" class="">
- <span>2,456</span> players worldwide
+ <span>0</span> <span>players</span> total
</div>
</div>
</div>
View
3 client/js/character.js
@@ -355,7 +355,6 @@ define(['entity', 'transition', 'timer'], function(Entity, Transition, Timer) {
},
disengage: function() {
- log.debug(this.id + " has disengaged from the fight.");
this.attackingMode = false;
this.followingMode = false;
this.removeTarget();
@@ -463,8 +462,6 @@ define(['entity', 'transition', 'timer'], function(Entity, Transition, Timer) {
this.target.removeAttacker(this);
}
this.target = null;
- } else {
- log.debug(this.id + " has no target");
}
},
View
19 client/js/main.js
@@ -197,10 +197,29 @@ define(['jquery', 'app'], function($, App) {
});
game.onNbPlayersChange(function(worldPlayers, totalPlayers) {
+ var setWorldPlayersString = function(string) {
+ $("#instance-population").find("span:nth-child(2)").text(string);
+ $("#playercount").find("span:nth-child(2)").text(string);
+ },
+ setTotalPlayersString = function(string) {
+ $("#world-population").find("span:nth-child(2)").text(string);
+ };
+
$("#playercount").find("span.count").text(worldPlayers);
$("#instance-population").find("span").text(worldPlayers);
+ if(worldPlayers == 1) {
+ setWorldPlayersString("player");
+ } else {
+ setWorldPlayersString("players");
+ }
+
$("#world-population").find("span").text(totalPlayers);
+ if(totalPlayers == 1) {
+ setTotalPlayersString("player");
+ } else {
+ setTotalPlayersString("players");
+ }
});
game.onAchievementUnlock(function(id, name, description) {
View
24 server/js/main.js
@@ -10,7 +10,20 @@ function main(config) {
_ = require('underscore'),
server = new ws.MultiVersionWebsocketServer(config.port),
metrics = config.metrics_enabled ? new Metrics(config) : null;
- worlds = [];
+ worlds = [],
+ lastTotalPlayers = 0,
+ checkPopulationInterval = setInterval(function() {
+ if(metrics.isReady) {
+ metrics.getTotalPlayers(function(totalPlayers) {
+ if(totalPlayers !== lastTotalPlayers) {
+ lastTotalPlayers = totalPlayers;
+ _.each(worlds, function(world) {
+ world.updatePopulation(totalPlayers);
+ });
+ }
+ });
+ }
+ }, 1000);
switch(config.debug_level) {
case "error":
@@ -53,11 +66,12 @@ function main(config) {
});
var onPopulationChange = function() {
- metrics.updatePlayerCounters(worlds);
- metrics.updateWorldDistribution(getWorldDistribution(worlds));
- _.each(worlds, function(world) {
- world.updatePopulation(metrics.totalPopulation);
+ metrics.updatePlayerCounters(worlds, function(totalPlayers) {
+ _.each(worlds, function(world) {
+ world.updatePopulation(totalPlayers);
+ });
});
+ metrics.updateWorldDistribution(getWorldDistribution(worlds));
};
_.each(_.range(config.nb_worlds), function(i) {
View
16 server/js/metrics.js
@@ -11,7 +11,6 @@ module.exports = Metrics = Class.extend({
this.client = new memcache.Client(config.memcached_port, config.memcached_host),
this.client.connect();
this.isReady = false;
- this.totalPopulation = 0;
this.client.on('connect', function() {
log.info("Metrics enabled: memcached client connected to "+config.memcached_host+":"+config.memcached_port);
@@ -26,7 +25,7 @@ module.exports = Metrics = Class.extend({
this.ready_callback = callback;
},
- updatePlayerCounters: function(worlds) {
+ updatePlayerCounters: function(worlds, updatedCallback) {
var self = this,
config = this.config,
numServers = _.size(config.game_servers),
@@ -45,8 +44,11 @@ module.exports = Metrics = Class.extend({
total_players += count;
numServers -= 1;
if(numServers === 0) {
- self.client.set('total_players', total_players);
- self.totalPopulation = total_players;
+ self.client.set('total_players', total_players, function() {
+ if(updatedCallback) {
+ updatedCallback(total_players);
+ }
+ });
}
});
});
@@ -64,5 +66,11 @@ module.exports = Metrics = Class.extend({
this.client.get('world_count_'+this.config.server_name, function(error, result) {
callback(result);
});
+ },
+
+ getTotalPlayers: function(callback) {
+ this.client.get('total_players', function(error, result) {
+ callback(result);
+ });
}
});

0 comments on commit aa21e3c

Please sign in to comment.
Something went wrong with that request. Please try again.