MMORPG - Handling Multiple Areas

This is kinda tough to explain. So, I will try my best.

Suppose the world has 5 islands. There are players on all the island. So, I don’t want to send the data of players, items, enemies and other entities that are on Island 1 to the players of other islands. I mean there is no point in doing that. So, is this the right approach ? I mean is this how people usually go about doing this ?

This is something I thought:
I store the player’s data in an ArrayList. So, I was thinking of making an ArrayList for all the islands and then players of the same island will share their data. But, I figured as the no. of islands will increase, things will get unorganized and complex.

So can you guys help me on how to handle this ?

What I would personally do, is store a list of all the players currently online, as Player objects.

Each player object would store a location.

Every time a player moves, the server would use pythagoras’ theorem to detect which players were near by - then store the pointers to THOSE players in another list INSIDE THE PLAYER OBJECT.

When it came to updating the player’s position, you’d loop through that list and send the data to each ‘nearby’ player.

Forgive me in this next section if I get the maths wrong:P

Categorising it by islands might be too large for any server you could afford to handle (Not being rude or anything). If each island had 200 players on it, then for each player you’d have to send them the data of the other 199 players. If the size of each data packet was 128 bytes, plus like 40 for TCP overhead (or 20 for UDP) you’d end up with

(128 + 40)*(n - 1)*n
Where n is the number of players on the island.

Going back to the assumption that you have 200 players on an island, then you have to send 6686400 bytes of data per update.

If you’re updating this 20 times a second or something, that becomes 133728000 per second!! or 133MB/s ish, which is pretty huge. Not only that but the server must maintain this for multiple islands.

If these players were spread out though, my above method would sacrifice a small amount of CPU power to reduce that by quite a bit.

Though I might have these numbers wrong:)

EDIT:
Thinking of it 128 bytes might be quite a large size for a packet. regardless, you still have the 40 byte overhead, so you’ll end up with at least 64 bytes or something

[quote=“PocketCrafter7,post:1,topic:49628”]
Uhhh… I suspect you mean “player lobbies” in where each island represents one lobby?

I mean, one good way of doing this is just to keep all the player data, and the location of that player on the server back end. Then, just share the data with players that are within that location. Let your server handle how to organize the players, and also handle the information you send back to players.

Well, unless you have 1 million islands, I don’t see it as the case. However, to relieve confusion, I would literally track it by player and give each player a “location ID”. Then, if multiple players have matching “location ID”'s, I’d send all the data necessary in a group to only those players. There is literally no reason to track the islands as a player literally can’t be in two places at once. :persecutioncomplex:

Hopefully that clears up a little, and my way is only one idea. There are other ways to do it, so feel free to experiment if this way doesn’t work for you. :point:

If you’re going to use the pythagorean theorem for distance checks, try doing it without the squareroot. Then if you’re checking say 64 distance, check 64^2 as your distance. It’s probably easier on the CPU when you have hundreds of players.

Maybe so if you have 100’s of thousands +, otherwise it’s negligible. Not worth potential confusion.

I disagree. Even with 64 players online, constant squareroot checks would be a cpu waste.

Calling Math.sqrt once, where you can work around it, is a CPU-cycle waste.

Working around calling Math.sqrt a few thousand times per second is a dev-time waste.

Don’t optimize until there is a need. Premature evil is the square root of optimization, aight?

Working around XXX isn’t if you know it and just do it. Be that as it may. I’m pretty sure HotSpot issues sqrtss which is about 17 cycles.

[quote]So, I don’t want to send the data of players, items, enemies and other entities that are on Island 1 to the players of other islands. I mean there is no point in doing that. So, is this the right approach ? I mean is this how people usually go about doing this ?
[/quote]
Yep, exactly right. If they’re not interacting with each other there’s really no need to send that data. In the multiplayer game I’m working on I do something similar but instead of islands I have “zones”. On a server instance all the players are in one big arraylist and each player has a field called “zoneID”. When it comes time to send packets to each player if the zoneID’s don’t match, don’t bother sending any updates for that player. Also don’t bother trying any collision detection, bullet hits, or any other update. On the serverside each player could be flying right next to each other but if the zoneIDs don’t match then they might as well be in different universes.

I did hit one snag doing this. What happens when player2 warps to a different zone while standing next to player1? Technically at that moment they are both are in different zones so they’re not going to get updates from each other but you still need to send that one last update that tells each player to remove the other one(ohh and also in a correct graphical way. the player warping out and the player staying behind has different effects.). Ohh and that last update needs to be guaranteed to eventually reach the user no matter what. (or else one or both players gets a random ship just sitting there doing nothing) Fun times.