4

I'm trying to create a multiplayer game where,

  1. For every 2 players, the server will create 1 room (my game is PvP, one vs one)
  2. Each room handle the game logic
  3. I will use Java.Util.Timer as my game loop
  4. Server FPS = 5
  5. Each room will handle player movement and little physics

On to the actual question:

What kind of game loop should I use based on the points below? What are the pros or cons of each type of game loop below.

  1. Each room will have their own game loop ( timer )
  2. All rooms handled in a single game loop ( timer )
  3. All room handled in a single game loop, but when the total room count = 50, the server will create another new game loop.

EDIT

What I tried so far:

I used the game loop in point 1, But some rooms don't have a chance to update their game loop. I'm confused about whether I need to change my game loop or if I need to change my code in each loop or if the issues is because Java.Util.Timer.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
user3598272
  • 145
  • 10
  • Anything you tried so far?? – Anjula Ranasinghe Mar 28 '15 at 05:42
  • 1
    I think this questions is probably better suited for GameDev SE: http://gamedev.stackexchange.com/ – DonyorM Mar 28 '15 at 05:46
  • @Anjula_Ranasinghe i add what i tried so far in my question.. – user3598272 Mar 28 '15 at 05:59
  • @DonyorM i confuse because it have Java.Util.Timer that i think have relation with my problem – user3598272 Mar 28 '15 at 05:59
  • 1
    I'm pretty sure they can still handle programming. In fact the help article claims: `game-specific programming issues (engine architecture, game-related APIs, networking, tools, etc)` is allowed. Why don't you try putting it over there, I think you'll get a better answer. – DonyorM Mar 28 '15 at 06:02
  • 3
    All of the approaches you list are valid and the best answer depends on your requirements and netcode. This seems too broad to me. Getting bugs when implementing a particular approach is another question. – Vitruvie Mar 28 '15 at 06:09
  • Which rooms don't have a chance to update? Is it random? Is it the first room? the last room? Do some debugging with print statements or the debugger to figure out what's going on – satnam Mar 28 '15 at 06:12
  • @Saposhiente sir, can we know the pros and cons in my game loop list. yes it too broad, just make it short and simple for dummy, because its hard and took a long time to find the answer outside this site. – user3598272 Mar 28 '15 at 06:20
  • @satnam its random, all room have same code. sometimes it happen when server have many room, sometimes when server just have few room. let just focus on pros and cons of the game loop from my point list – user3598272 Mar 28 '15 at 06:23
  • 2
    @user3598272 The real answer is "If you don't know enough about your requirements to be able to figure out the answer on your own, pick whichever one seems easiest to implement because you have bigger problems to worry about. Then change it later if needed." – Vitruvie Mar 28 '15 at 07:27
  • It's silly to try to optimize the design when your code doesn't even work. Why don't you fix your stuff first. – satnam Mar 28 '15 at 17:14
  • You should definitely use libraries. Kryonet is pretty good for Java, and not too difficult. – bigcodeszzer Nov 20 '15 at 16:44
  • There are step by step youtube videos showing exactly how to implement kryonet from downloading to adding the jar files as well as implementation. – bigcodeszzer Nov 20 '15 at 16:45

2 Answers2

0

Ultimately, it depends, and you need to provide more information.

You are handling different games, or 'matches' in different rooms, I take it, because you said your game is 1v1.

If you do not need to transfer data between the various 'rooms' while they are running, than having separate loops makes no sense. If you are hosting the game on a server, than each 'room' should be handled as a different process in parallel.

Note also, that if no data needs to be transferred at all, than you should really be using direct TCP/UDP connections.

If you elaborate, I would be able to answer better, but I recommend taking a look at this. It is in C++ and not Java, but it still may help

Verifying sent packets on real time network using SFML

Community
  • 1
  • 1
dunworray
  • 49
  • 10
0

I was thinking of doing this myself. It will depend on how you code your network. I'm using kryonet library, so my solution may be different from yours.

Also, it's very difficult to answer this question without more information. What type of game are you making? Is it graphics heavy? Do you need UDP/TCP connection? Is latency an issue? Are you going to implement threading? Are the users interacting with a server or connecting directly to each other or both? (You mentioned rooms so I assume there is a server.

What I would recommend in general, based on limited information is something like this.

Server/host loop ---generates-----> Room1 loop
...............................................-----> Room2 loop
.............................................. -----> Room3 loop

I'm pretty sure each loop will need fps, and they will have to divide cleanly into the host loop, you'll need to play around with that. Also take a look through your network library for fps handling.

If you are not using a network library, I recommend you use one.

I had some various ideas about networking loops myself, the best was to have a server facilitate a TCP connection between the two users, then transfer the results back to the server when their match was complete.

I imagine there would be security concerns for the results being sent back and forth, but there are ways of dealing with this.

Good luck.

bigcodeszzer
  • 916
  • 1
  • 8
  • 27