Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (563)
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 1600 times)
0 Members and 1 Guest are viewing this topic.
Offline Alien94

Senior Newbie





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

Hi!

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?

Thanks!!!
Offline theagentd
« Reply #1 - Posted 2012-11-08 21:55:37 »

1  
Socket.setTCPNoDelay(true);

Myomyomyo.
Offline Alien94

Senior Newbie





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

1  
Socket.setTCPNoDelay(true);


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
« League of Dukes »

JGO Overlord


Medals: 799
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:
1  
2  
3  
4  
5  
6  
7  
8  
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.

 

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

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (19 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (31 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24: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!