Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (579)
games submitted by our members
Games in WIP (500)
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  
  LWJGL, KryoNet  (Read 3151 times)
0 Members and 1 Guest are viewing this topic.
Offline Seiya02

Senior Member


Medals: 1
Projects: 3



« Posted 2013-09-05 21:03:23 »

Hey, I'm working on a little Multiplayer game (up to 16 players) in Java using LWJGL for the Graphics and KryoNet for the Networking. A Chat and some easy things with KryoNet are no problem, I even can see the other players move arround. I'm working this way: The Client sends his position+current moving direction to the server which sends it to all Clients except the one that sent it to him. So the moving of each Client is controlled by the Client and can't be manipulated by the server. The problem is, that i want to add sth. like explosions which will force the players next to it to get thrown away, but how does this work?
Should I just send the input of the Client to the Server and let the Server handle the movement of every Client on his own and send it back to All Clients? Or is there another possibility to do this?  Huh

-Thanks for Answers  Smiley
Offline netikan

Junior Member


Medals: 1
Projects: 1


Zombies!


« Reply #1 - Posted 2013-09-05 21:08:03 »

Look in your server code for "sendToAllExcept". This sounds like the issue.

Explosions should be done using box2d. They the easiest thing though.

Check out my project Land of Zom - Multiplatform Zombie MMO/RPG!
Soon to be at Eurogamer 2013.
Offline Herjan

Senior Member


Medals: 6
Projects: 1



« Reply #2 - Posted 2013-09-05 21:23:24 »

Should I just send the input of the Client to the Server and let the Server handle the movement of every Client on his own and send it back to All Clients?

This is exact how you should do this, handle everything with your server, and send info playerpositions and stuff to client.

Tasks:
Client: Render, send input to server (there are a few exceptions like chat)
So don't handle the input in the client, like you are doing now:

I'm working this way: The Client sends his position+current moving direction to the server which sends it to all Clients except the one that sent it to him. So the moving of each Client is controlled by the Client and can't be manipulated by the server.

Server: Do the tick, and send (60 times per second?) stuff like playerpositions back. And never forget: DON'T TRUST THE USER! Tongue

Good luck with your game!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


« Reply #3 - Posted 2013-09-05 21:54:27 »

The server shouldn't be sending 60 packets a secod for every single entity Sad

Offline Seiya02

Senior Member


Medals: 1
Projects: 3



« Reply #4 - Posted 2013-09-05 21:56:04 »

Okay, I'll check Box2D (I forgot to mention i'm coding in 3D, Box2D is just for 2D no?)
So collisions and everything else just gets managed by the server? When i send the input to the Server, how would it like manage the rotation of the camera the client has atm? or should i just send that too?
Offline Seiya02

Senior Member


Medals: 1
Projects: 3



« Reply #5 - Posted 2013-09-05 21:58:20 »

yeh, 60 times a second for each entity seems a bit too much, could I just send an object which contains all Entities? like an ArrayList or something?
Offline netikan

Junior Member


Medals: 1
Projects: 1


Zombies!


« Reply #6 - Posted 2013-09-05 22:02:44 »

The server shouldn't be sending 60 packets a secod for every single entity Sad

I completely agree.

I personally use updates every 0.333 seconds with added interpolation for movement. I can hold several hundred player entities within a small space quite easily.

Check out my project Land of Zom - Multiplatform Zombie MMO/RPG!
Soon to be at Eurogamer 2013.
Offline matheus23

JGO Wizard


Medals: 97
Projects: 3


You think about my Avatar right now!


« Reply #7 - Posted 2013-09-05 22:07:49 »

Many games update their entities only 20 times per second and interpolate the results when rendering at 60 fps (e.g. minecraft).

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Seiya02

Senior Member


Medals: 1
Projects: 3



« Reply #8 - Posted 2013-09-06 07:08:59 »

So I send the position of the entity and the direction it's walking so that the client can calculate where it's going until he receives new positions for the entity?
Offline Seiya02

Senior Member


Medals: 1
Projects: 3



« Reply #9 - Posted 2013-09-06 07:13:12 »

So should I send the position of each entity seperately or just put them all into an arraylist and send that arraylist? would that even nake a difference?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online trollwarrior1
« Reply #10 - Posted 2013-09-06 07:30:57 »

I haven't done lots of networking (Made only a simple chat Cheesy).

I have no idea Cheesy
More I think about it, more things come to my head Cheesy If you sent lists, you might be sending individual entities + list. So it might be better to send individual. But then, when you send lists, you might be sending less bytes, because they might be somehow packed in that list. Unless someone tells you about their experience doing this, I think you should just try.
Offline netikan

Junior Member


Medals: 1
Projects: 1


Zombies!


« Reply #11 - Posted 2013-09-06 11:02:27 »

So should I send the position of each entity seperately or just put them all into an arraylist and send that arraylist? would that even nake a difference?


Send the position of each entity separately. And use the UDP functions built into Kryonet.

Check out my project Land of Zom - Multiplatform Zombie MMO/RPG!
Soon to be at Eurogamer 2013.
Offline Seiya02

Senior Member


Medals: 1
Projects: 3



« Reply #12 - Posted 2013-09-06 13:35:45 »

Okay, and I give each entity an ID to manage them on client side yes? So i send an object containing positions+movement (for interpolation) to each client using udp. I'll try this out with sending like 20 times per second. Or anyone knows how often minecraft is sending so i can take the same value?
Offline Seiya02

Senior Member


Medals: 1
Projects: 3



« Reply #13 - Posted 2013-09-08 19:05:39 »

works fine for now with 20 times per second but i think this might not be perfect for an Realtime Action RPG, any suggestions how to make it "faster" and "smoother"?
Offline cobolfoo

Junior Newbie





« Reply #14 - Posted 2013-10-30 17:50:04 »

Some suggestions:

- Separate your server simulation ticks into states. A state contains the position and velocity of all the entities in the simulator for a specific period of time. When you send the information to your clients specify the state too.

- On the client, do the same in reverse, create states based on packets you receive and store positions, velocity, etc. in them.

- Instead of extrapolating, interpolate between previous states. Add a 100ms lag to all your player. It might sound strange to add lag, but you will get stability in exchange (giving time to packets to get in). You could still extrapolate if you have missing states (intense lag).

- In my game I have 32 entities that I update 20 times per second. (640 small UDP packets).

- Since you are sending something every 50 ms, you could store all the packets to a specific player and send them in a batch (of 1400 bytes packets).

- To reduce bandwidth and packet count: add some line of sight detection, send only packets to players who can find the information useful.

- Use java.nio.ByteBuffers to pack your data. You can pre-allocate a big one and re-use it for all your packets (for both reading and writing packets).


 
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.

xsi3rr4x (37 views)
2014-04-15 18:08:23

BurntPizza (33 views)
2014-04-15 03:46:01

UprightPath (49 views)
2014-04-14 17:39:50

UprightPath (31 views)
2014-04-14 17:35:47

Porlus (48 views)
2014-04-14 15:48:38

tom_mai78101 (70 views)
2014-04-10 04:04:31

BurntPizza (129 views)
2014-04-08 23:06:04

tom_mai78101 (229 views)
2014-04-05 13:34:39

trollwarrior1 (193 views)
2014-04-04 12:06:45

CJLetsGame (200 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!