Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  KryoNet Player Locations  (Read 1191 times)
0 Members and 1 Guest are viewing this topic.
Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Posted 2013-11-15 15:49:13 »

When using KryoNet in a 3D multiplayer game with a big world, do I have to send every Players Location to every Client? even if they aren't in range for them to see? And how do i manage the connected clients? ArrayList doesn't work that well throwing ConcurrentModificationExceptions on Disconnect, so How to Store the data?
Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #1 - Posted 2013-11-15 15:57:42 »

You want to send to every client all relevant entities. This can be determined in the following ways:

* An entity is relevant if it's within X units (hearing distance)
* An entity is relevant if it's within the view frustum within a specified distance (or line-of-sight)
* An entity is relevant if it is flagged as always relevant
* An entity is relevant if it was relevant for another reason in the pass Y seconds.

When entities connect to my server, the server gives out an ID (as an int for example)... to store entities on the clients I keep it in a Map<ID, Entity>.

Basically the server knows what entities are relevant to each client. When the server receives an entity create/update/death message it makes sure to tell the client when a new entity is created, it's not relevant, it is relevant, an entity has updated, and an entity has been removed. The server only sends updates to relevant clients, but creates and deaths to all clients.

I hope this helps!


Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #2 - Posted 2013-11-15 16:05:29 »

Okay, when I Store Entities in a Map<ID, Entity> how can I add an Entity which is controled by the Server with some AI? If I just give it an ID the next Connection could have the same ID which would cause problems no?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #3 - Posted 2013-11-15 16:08:41 »

Here's my ID generation/sync process:

1. Client generates a LOCAL ID when an entity (like a bullet or grenade or something)  is created and sends to server.
2. Server generates a REMOTE ID which is unique to the server (the server can do nextId++ or something) and the server sends a message to the client "your LOCAL ID should be changed to REMOTE ID so we're in sync"
3. Client only sends information now with REMOTE ID given by server

Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #4 - Posted 2013-11-15 16:15:58 »

ah so for the IDs you don't use the ID KryoNet creates ("Connection.getID()")? You create your own IDs?
Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #5 - Posted 2013-11-15 16:18:24 »

I don't use Kryonet, but I wouldn't use their ID stuff if I did.

Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #6 - Posted 2013-11-15 16:24:58 »

Okay, i'm going to generate my own IDs now. Next Problem: Map<ID, Entity> can't use an integer as an ID an using an Object which just stores that ID doesn't support the Function to just call Map.get(new ID(5)); and get the Entity cause the ID object isn't the same
Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #7 - Posted 2013-11-15 16:27:08 »

1  
2  
3  
4  
5  
6  
7  
8  
public void remove(int ID) {
      for (ID id : entities.keySet()) {
         if (id.ID == ID) {
            entities.remove(id);
            break;
         }
      }
   }


trying out this now
Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #8 - Posted 2013-11-15 16:29:37 »

You can do Map<Integer, Entity> map = ... and map.get(5) will work. map.remove(4) will also work.

Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #9 - Posted 2013-11-15 16:32:45 »

Ah, tryed it with just "int" what did not work Cheesy what Kind of Map should i use best? HashMap?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #10 - Posted 2013-11-15 16:36:08 »

Are you using a game engine? Some come with IntMap which is far better than using Map<Integer, Entity>. I would use HashMap if you don't have access to something like an IntMap.

Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #11 - Posted 2013-11-15 16:37:50 »

No, I'm not using an Engine, i'm just using KryoNet for Network and LWJGL for Graphics. So I'll stay with HashMaps Cheesy
Offline Seiya02

JGO Coder


Medals: 4
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #12 - Posted 2013-11-15 16:58:37 »

So the next thing is the Interpolation on Client side, would it work if i send the coordinates (x,y,z) + Rotation and Movement directions (dx,dy,dz) for an ID and for Interpolation i send System.nanoTime(); in a long so the Client knows when the position was exact and can interpolate it with his System.nanoTime();?
Offline ClickerMonkey

JGO Coder


Medals: 20


Game Engineer


« Reply #13 - Posted 2013-11-15 18:36:53 »

I do this for interpolation:

A simple Entity structure: { ping, lastUpdateTime, time, lastPosition, nextPosition, position }

When I get an update for an entity
1  
2  
3  
4  
5  
long currentTime = System.nanoTime();
user.ping = (currentTime - user.lastUpdateTime) * 0.000000001f; // in seconds
user.lastUpdateTime = currentTime;
user.lastPosition.set( user.position );
user.nextPosition.set( UPDATE.newPosition );


Every update call (where dt is seconds since last update)
1  
2  
user.time += dt;
user.position = (user.nextPosition - user.lastPosition) * (user.time / user.ping) + user.lastPosition;


This handles interpolation from previous position to new, and even extrapolation if time passes expected ping (you don't receive an UPDATE in ping seconds).

You can apply this logic to other things like direction and velocity if necessary.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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 (13 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (31 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (19 views)
2014-08-16 06:20:21

Tekkerue (29 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (42 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
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!