Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (688)
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  
  2D Game commands delay  (Read 2077 times)
0 Members and 1 Guest are viewing this topic.
Offline Alien94

Senior Newbie

« Posted 2012-11-08 21:52:16 »


I'm working on a 2D game.
There are two players (in multiplayer) and about 350 entities (mobs and other).
To synchronize mobs i used a random with the same seed on both devices.
But to move the player and to fire, i send the commands to the other player through TCP.
It works fine but sometimes there are delays.

Is there a better way to manage players movement?

Offline theagentd

« JGO Bitwise Duke »

Medals: 597
Projects: 4
Exp: 8 years

« Reply #1 - Posted 2012-11-08 21:55:37 »


Offline Alien94

Senior Newbie

« Reply #2 - Posted 2012-11-08 22:06:19 »


Thank you but i already use that!!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven

« JGO Overlord »

Medals: 1068
Projects: 4
Exp: 16 years

Hand over your head.

« Reply #3 - Posted 2012-11-08 22:31:09 »

Then we need to see code.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline Alien94

Senior Newbie

« Reply #4 - Posted 2012-11-08 22:37:16 »

I have a class "Networking" with two threads:
- the first one sends packets in outgoing list;
- the second receive packets and i have a "handle" method to manage each package.

Handle method:
if(packet instanceof PlayerMovePacket) {
   if(isServer) players[1].incomingCommands.add(new PlayerMoveCommand(((PlayerMovePacket) packet).getDir()));
   else players[0].incomingCommands.add(new PlayerMoveCommand(((PlayerMovePacket) packet).getDir()));
else if(packet instanceof PlayerFirePacket) {
   if(isServer) players[1].incomingCommands.add(new PlayerFireCommand(((PlayerFirePacket) packet).getFire()));
   else players[0].incomingCommands.add(new PlayerFireCommand(((PlayerFirePacket) packet).getFire()));

Then, in the Player class i process all commands in "incomingCommands" list and for each command i move the player in that direction.
Do you need anything else?

Thank you!
Offline sproingie

JGO Kernel

Medals: 202

« Reply #5 - Posted 2012-11-09 07:17:14 »

Hard to tell from just that.  Try enabling -verbose:gc and seeing if the pauses coincide with a gc cycle.
Offline Alien94

Senior Newbie

« Reply #6 - Posted 2012-11-09 07:32:25 »

Hard to tell from just that.  Try enabling -verbose:gc and seeing if the pauses coincide with a gc cycle.

But is the reasoning right?
Offline sproingie

JGO Kernel

Medals: 202

« Reply #7 - Posted 2012-11-09 19:41:23 »

Is it the way I would organize things?  Not really.  But it does work I suppose.  There's all kinds of reasons things could hitch up, from gc thrashing to oversynchronization to network lag, but a half dozen LOC doesn't really say much.  I can't tell how expensive your command constructors are, or what collection implementation you're using, and so on. 

Performance troubleshooting is tricky enough, intermittent performance problems are maddening.  If you can find out what changes in the program or the environment cause the intermittent problem to get worse or more frequent, you're more than halfway to figuring out the cause.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (74 views)
2015-11-07 13:29:08

Rems19 (81 views)
2015-10-31 01:36:56

Rems19 (79 views)
2015-10-31 01:32:37

williamwoles (107 views)
2015-10-23 10:42:59

williamwoles (93 views)
2015-10-23 10:42:45

Jervac_ (111 views)
2015-10-18 23:29:12

DarkCart (137 views)
2015-10-16 00:58:11

KaiHH (118 views)
2015-10-11 14:10:14

KaiHH (158 views)
2015-10-11 13:26:18

BurntPizza (173 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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‑
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!