Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (515)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
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  
  Storing all players  (Read 643 times)
0 Members and 1 Guest are viewing this topic.
Offline temu

Senior Newbie


Medals: 1
Exp: 2 years



« Posted 2014-07-10 15:53:11 »

Hi guys, I'm developing an mmorpg and my question is: what is the better way to store all the connected players in the server and how can I rapidly find them? I'm using kryonet so I have and ID and I'm storing them in a LinkedList at the moment. So any time I receive something like a movement update I have to use a
1  
for (Player p : connectedPlayers)
but I guess this is not the better solution.

And I have one more question, when I receive a packet, like a movement update, I'm looping between players in the same thread, this probably makes my server slower, is it a good idea to make a little thread that expires each time his little task has been handled? Or is it better to have something like a thread specialized on movement handling and each time a player moves it handles the data?
Let me know if you have any better approach, thanks.
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2014-07-10 16:22:11 »

First off, stop using that linked list. There is absolutely no point in using one. The only advantage linked lists have over array lists is the complexity of its remove operation. What you should do in the packet is store an id that corresponds to a player. When the packet is received, look up the id and call upon the correct player. Then perform whatever action you need to do.

Looping through your player list is not a complex operation at all, modern day computers have no issue looping through anything. Don't worry about that.

Offline temu

Senior Newbie


Medals: 1
Exp: 2 years



« Reply #2 - Posted 2014-07-10 16:33:44 »

First off, stop using that linked list..

So you suggest me to use arrays, ok I'll probably do that.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #3 - Posted 2014-07-10 16:34:41 »

I would suggest you use an array list.

Offline Gjallar

JGO Coder


Medals: 13
Projects: 1


Follower of Nurgle


« Reply #4 - Posted 2014-07-10 16:36:52 »

Why not use a map and use the player's id as the key?
Offline CopyableCougar4
« Reply #5 - Posted 2014-07-10 16:39:11 »

Hi

Depending on the key, you could keep arraylists and just file the arraylist by index. Otherwise a HashMap would work.
Filing arraylist by index:
put(int index, Object o)
get(int index)
remove(int index)


CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline temu

Senior Newbie


Medals: 1
Exp: 2 years



« Reply #6 - Posted 2014-07-10 16:39:31 »

That's what I was thinking about right now Cool

Anyone who say something about threads for various tasks? In other words, shall I put the login in different thread instead of kryonet's one, right?
Offline CopyableCougar4
« Reply #7 - Posted 2014-07-10 16:41:17 »

Hi

For me personally, it would depend how taxing/long it takes to complete a login. If it takes 1ms it's fine in that thread, but if it takes like half a second than use a different thread. (Just my opinion)

CopyableCougar4

Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline temu

Senior Newbie


Medals: 1
Exp: 2 years



« Reply #8 - Posted 2014-07-10 16:42:42 »

For me personally, it would depend how taxing/long it takes to complete a login.

For login and logout I've already set up a specific thread because I need to read and modify the database Wink
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #9 - Posted 2014-07-10 16:58:15 »

Don't use an arraylist actually. If you are storing by ID then there is no reason to reason to use a list of that type. A hashmap would be your best solution. Don't spawn a new thread every time you receive a packet, you receive thousands of packets every second. Think about all those threads, and you would eventually (or very soon) run into multithreading issues. Honestly, I think you need to do some research on how computers work first. It seems you think that small tasks will slow down computation, its not true at all. Receiving a packet and processing it shouldn't be a complex task.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline richierich
« Reply #10 - Posted 2014-07-10 18:26:09 »

Why not use a map and use the player's id as the key?

Surely the idea is to take player movements and notify all *other* players so they can update their local world state? In which case a loop is the only thing to do and the exact kind of list probably doesn't make too much difference.

To temu, how big is the world, and how many players are you hoping to connect? To start with I'd just do what you posted originally, and if you start getting hundreds of users then that's a nice problem to have Smiley

At that point one way it might be adapted to improve performance is divide the world into sub-areas and when player movements come in, only notify other players in their sub-area, and also probably adjacent sub-areas. When a player moves between areas, shift their "Player" record to the list for the new subarea. In that kind of scheme it could make sense to have movements in each area monitored by a separate thread, effectively treating each area as a separate small world. Potentially more scalable that way too as you might eventually run each area on a different machine entirely.

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.

TehJavaDev (31 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (40 views)
2014-10-26 19:37:11

Luminem (21 views)
2014-10-26 10:17:50

Luminem (25 views)
2014-10-26 10:14:04

theagentd (31 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (57 views)
2014-10-16 15:22:06

Norakomi (46 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!