Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  MMORPG - Handling Multiple Areas  (Read 2475 times)
0 Members and 1 Guest are viewing this topic.
Offline PocketCrafter7
« Posted 2014-06-20 17:47:30 »

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 ?

Nothing is difficult in this world. It is just how you look at it.
Offline ipe369

Junior Member


Medals: 3
Exp: 3 years



« Reply #1 - Posted 2014-06-20 17:58:10 »

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
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #2 - Posted 2014-06-21 02:11:31 »

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 ?

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.

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 ?

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.  Pointing

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline orange451

Senior Member


Medals: 7
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #3 - Posted 2014-06-23 18:43:30 »

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.

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline BurntPizza
« Reply #4 - Posted 2014-06-23 18:46:07 »

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.
Offline orange451

Senior Member


Medals: 7
Projects: 1
Exp: 4 years


Your face. Your ass. What's the difference?


« Reply #5 - Posted 2014-06-24 04:06:15 »

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

Working on a nice FPS in lwjgl Smiley http://i.imgur.com/q4uFqBS.png
Feel free to message me if you're interested!
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 793
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2014-06-24 11:13:10 »

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?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online Roquen
« Reply #7 - Posted 2014-06-24 12:06:23 »

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.
Offline sonnyg007
« Reply #8 - Posted 2014-07-03 17:37:31 »

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 ?

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.

Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (19 views)
2014-09-12 09:08:26

Norakomi (54 views)
2014-09-10 13:57:51

TehJavaDev (63 views)
2014-09-10 06:39:09

Tekkerue (31 views)
2014-09-09 02:24:56

mitcheeb (53 views)
2014-09-08 06:06:29

BurntPizza (37 views)
2014-09-07 01:13:42

Longarmx (23 views)
2014-09-07 01:12:14

Longarmx (27 views)
2014-09-07 01:11:22

Longarmx (27 views)
2014-09-07 01:10:19

mitcheeb (35 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!