Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 946 times)
0 Members and 1 Guest are viewing this topic.
Offline Alien94

Senior Newbie





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

1  
Socket.setTCPNoDelay(true);

Myomyomyo.
Offline Alien94

Senior Newbie





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

1  
Socket.setTCPNoDelay(true);


Thank you but i already use that!!
Games published by our own members! Check 'em out!
Try the Free Demo of Titan Attacks
Online Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


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
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
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:
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
« 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
« 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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (67 views)
2013-05-17 21:29:12

alaslipknot (76 views)
2013-05-16 21:24:48

gouessej (109 views)
2013-05-16 00:53:38

gouessej (104 views)
2013-05-16 00:17:58

theagentd (115 views)
2013-05-15 15:01:13

theagentd (104 views)
2013-05-15 15:00:54

StreetDoggy (149 views)
2013-05-14 15:56:26

kutucuk (172 views)
2013-05-12 17:10:36

kutucuk (170 views)
2013-05-12 15:36:09

UnluckyDevil (179 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.115 seconds with 21 queries.