client update ranges

Posted By: SchokoKeks

client update ranges - 12/20/09 16:03

Whats the best concept to implement client update ranges?

The problem is: some values like the "health" or movement state need to be send as soon as an npc enters the players update range. After that, the values only need to be send if they have changed. I can only think of two ways, both have a large impact on memory usage for games with many players/npcs.

1. Every npc function stores an array that holds a boolean for every player which determains if this entity has been in his update range in the last frame (or last update).

Problem is: If the server could possibly support 500 players max at the same time, every npc (lets say there are 1000 of them) needs to have a really big array. Also, a lot of memory goes to waste because there will hardly always be 500 players online at the same time.

2. Every player function stores an array of all npcs that contains if they have been in the players range in the last frame.

Problem: You'd have to set a maximum of npcs per level, and you'd have some ugly code for setting and reading the array from the npcs functions.

Are there other ways which I haven't thought off? how is the anet template doing it?
Posted By: Sichlid

Re: client update ranges - 03/24/10 03:58

my suggestion would be to store the value of old health in a var like old_health
and check on the client machine every frame if health has changed. if yes then only send the new health value to all machines.
Posted By: darkinferno

Re: client update ranges - 03/24/10 04:17

agreeing with sichlid, you dont need to send health unless its changed, even if within 'range'
Posted By: Puppeteer

Re: client update ranges - 03/28/10 11:11

@ Sichlid: This doenst solve the problem at all ^^

@ Schokokeks: Why not using zones? That way you have something like a range system without a lot of huge arrays.
If a player enters a zone all the neccessary information will be sent and while he is in it he'll receive updates.
So all you gotta know is who is in which zone.
Posted By: SchokoKeks

Re: client update ranges - 03/28/10 13:27

thank you all for your answers.

@ Sichlid + darkinferno: that doesn't solve the problem. using "old"-variables is something thats needed independent of client update ranges.

@Puppeteer: Thats a good idea, and it keeps the code simple. However, you'd have to keep the zones quite small, and you'd have to take care of smooth transitions between the zones, or entities will just pop up in front of the player when he gets near the zone border.

I'll be using zones with "hard transitions", meaning that the player will see a loading screen when switching between those zones (through doors or small gateways). They are supposed to be quite big, so I still need an update ranges system.

I've solved the problem this way:
Every entity that wants to send updates has an array that has as many slots as there can be players (about 100).
Every frame, the entity checks whether it is within the range of the players.
When the array entry for the player x is 0 (means "not in range before") it sends all its information (health, position, level etc) to x. The entry is then set to 1 (means "has been in range last frame"). When the array entry is 1 in the first place, only changed values are send.

This code has to run on the server only. I've yet to see if I'll get performance problem.
Posted By: Dark_samurai

Re: client update ranges - 03/28/10 14:58

Ok this is a nice concept. But if you use seperate zones I would advice you to use a seperate server for each zone. (look at HowTo 2 in the ANet manual)

Why? Because if a lot of people are playing your game let's say about 200 at the same time, it will be impossible that one server handles all these players. So you split your whole game into 10 zones. Now you have 20 players on 10 servers and that should be possible.

Of course this is unimportant if you are creating a small game. But then I would advice you to create it with vec_dist():
Every client sends its position updates to the server. The server then forwards it to the clients depending on the distance of the clients to the entity that sends the new position. Entities that are out of range should turn their invisible flag on. The Dead Reckoning Template of ANet does it this way.
© 2024 lite-C Forums