Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 1514 times)
0 Members and 1 Guest are viewing this topic.
Offline Alien94

Senior Newbie

« Posted 2012-11-08 22: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
« Reply #1 - Posted 2012-11-08 22:55:37 »


Offline Alien94

Senior Newbie

« Reply #2 - Posted 2012-11-08 23: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
Online Riven
« League of Dukes »

JGO Overlord

Medals: 742
Projects: 4
Exp: 16 years

Hand over your head.

« Reply #3 - Posted 2012-11-08 23: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 23: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: 201

« Reply #5 - Posted 2012-11-09 08: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 08: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: 201

« Reply #7 - Posted 2012-11-09 20: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.


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

The first screenshot will be displayed as a thumbnail.

Riven (2 views)
2014-07-23 21:16:32

Riven (3 views)
2014-07-23 21:07:15

Riven (5 views)
2014-07-23 20:56:16

ctomni231 (39 views)
2014-07-18 06:55:21

Zero Volt (36 views)
2014-07-17 23:47:54

danieldean (29 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22 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!