Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (498)
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  
  Writing a tetris game -- How to implement the network?  (Read 2073 times)
0 Members and 1 Guest are viewing this topic.
Offline JoshuaD

Senior Newbie




Java games rock!


« Posted 2006-03-08 00:32:29 »

Hey,

This is a really general question, because I don't know enough to ask a pointed one.

I'm working on writing a tetris that's playable over a network.  I've written up a really nice single player program, but I'm having trouble coming up with a design scheme for network play.

I really just don't know what tools to use.  I've got O'Rielly's "Learning Java", and I'm playing with RMI, but I really don't know where to start.

Depending on what the user is doing, I'm rendering the screen every 12-26ms. 

How would I go about getting two game running together over the network?



My goal is to have it so the local-player controls the game on the left side in that image while the remote-player controls the right side of that screen.   Idealy there would be no difference in gameplay if the two players are playing from the same computer (controlling it from the same keyboard) or over the network.  I would like to render the block falling just as I would if it was all local.

I'm sorry if this is really vague, but I just don't know much about network programming.

Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2006-03-08 01:08:58 »

Is this a LAN game or an Internet game?  The techniques will vary substantially dependign on which it is.

If it is a LAN game then you have effectively 0 net latency and you cna do it lock-step.  This means that both computers run both right and left games and you just send the controls across to the other player.

This will never work for an internet game howevre, the latency will cause the foreign keystrokles to arrive much too late.

Instead, in thsi case, you want the "foreign" game to really be a s.lightly time-delayed view.  You show the results of the foreign game player's actions rather then actually trying to run the remote game locally.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Kova

Senior Member





« Reply #2 - Posted 2006-03-08 01:43:11 »

first of all, what is gameplay interaction between two boards? or it's just than one player can see the progress of second one?
In O'Reilly's Java NIO the author is converting multiplayer tetris from regular IO stryle to NIO Smiley There when you complete a row(s) opponent gets row(s) of random garbage.

Anyway don't know much about networking, just started, my initial idea, p2p or client-server:
You connect 2 pcs, server sends start msg and his inital falling objects (first two, first one to start falling and second one that is next to fall) and client responds with what will his first two falling objects be.
Game engine starts to process these, each in own seperate board, on both sides, but localy for opponents board dosen't calculate any points or whatever, just the visual process of falling and so on.
When local player changes rotation of falling object or speeds it down you send a message what happened to other player. Other player receives it and his game engine process it.
When falling object falls localy you send a message of status of your board (what squares are filled). Other player receives it, his game engine process it. Now your opponent board and his local board should be the same. If object made filled a row game engine should process it exactly on your and opponents board, since you have info how the objects fell exactly.
You create new random falling object and send message to other player what it is, and other player renders it... and process starts again.

Note this is just my opinion, I neved created a single network game but I'm working on one right now Wink
Also in this case it's very important that message that signals status of board gets received... if you lose a message about rotation, no biggie, you'll just won't see how opponent rotated object when falling, but if you lose status message, boards won't be syncronized until next status message comes (when opponent places next falling object).

I hope it's sounds clear what I said.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline JoshuaD

Senior Newbie




Java games rock!


« Reply #3 - Posted 2006-03-08 04:48:39 »

Is this a LAN game or an Internet game?  The techniques will vary substantially dependign on which it is.

If it is a LAN game then you have effectively 0 net latency and you cna do it lock-step.  This means that both computers run both right and left games and you just send the controls across to the other player.

This will never work for an internet game howevre, the latency will cause the foreign keystrokles to arrive much too late.

Instead, in thsi case, you want the "foreign" game to really be a s.lightly time-delayed view.  You show the results of the foreign game player's actions rather then actually trying to run the remote game locally.




Internet.

Should I be using RMI or just some protocol I made up over sockets? 
Offline CommanderKeith
« Reply #4 - Posted 2006-03-08 05:26:35 »

Quote
Should I be using RMI or just some protocol I made up over sockets? 

I've been told RMI can do the job and has high performance and I tried looking into it myself but I found it too hard too get a grip of... stubs, remote objects.....

As far as I understand RMI is limited to TCP (rather than UDP or a combo of both) and it may be a bit too high-level, not giving you the fine-grained control that you'd want to have in a game.  The danger of coding it in RMI would be that its stuck in RMI.  I'd recommend sending your own byte packets using your own sockets so you can change between UDP and TCP as you see fit. 

There's a good, active project called JGN (http://www.java-gaming.org/forums/index.php?topic=12384.0) that has that network communication ready-made, among other libraries. 

I've also developed a Serialization-like way of doing a network game (http://www.java-gaming.org/forums/index.php?topic=11531.0) but there's no tutorial yet and my website's down so you won't be able to get the code (but I'm working on it)... 

Keith

Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2006-03-08 11:18:11 »

Is this a LAN game or an Internet game?  The techniques will vary substantially dependign on which it is.

If it is a LAN game then you have effectively 0 net latency and you cna do it lock-step.  This means that both computers run both right and left games and you just send the controls across to the other player.

This will never work for an internet game howevre, the latency will cause the foreign keystrokles to arrive much too late.

Instead, in thsi case, you want the "foreign" game to really be a s.lightly time-delayed view.  You show the results of the foreign game player's actions rather then actually trying to run the remote game locally.




Internet.

Should I be using RMI or just some protocol I made up over sockets? 

I would not use RMI.  Lots of over-head and very little gain for this sort of thing.

Id just use ByteBuffers and build your own packets.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline JoshuaD

Senior Newbie




Java games rock!


« Reply #6 - Posted 2006-03-08 23:09:51 »

first of all, what is gameplay interaction between two boards? or it's just than one player can see the progress of second one?
In O'Reilly's Java NIO the author is converting multiplayer tetris from regular IO stryle to NIO Smiley There when you complete a row(s) opponent gets row(s) of random garbage.

Anyway don't know much about networking, just started, my initial idea, p2p or client-server:
You connect 2 pcs, server sends start msg and his inital falling objects (first two, first one to start falling and second one that is next to fall) and client responds with what will his first two falling objects be.
Game engine starts to process these, each in own seperate board, on both sides, but localy for opponents board dosen't calculate any points or whatever, just the visual process of falling and so on.
When local player changes rotation of falling object or speeds it down you send a message what happened to other player. Other player receives it and his game engine process it.
When falling object falls localy you send a message of status of your board (what squares are filled). Other player receives it, his game engine process it. Now your opponent board and his local board should be the same. If object made filled a row game engine should process it exactly on your and opponents board, since you have info how the objects fell exactly.
You create new random falling object and send message to other player what it is, and other player renders it... and process starts again.

Note this is just my opinion, I neved created a single network game but I'm working on one right now Wink
Also in this case it's very important that message that signals status of board gets received... if you lose a message about rotation, no biggie, you'll just won't see how opponent rotated object when falling, but if you lose status message, boards won't be syncronized until next status message comes (when opponent places next falling object).

I hope it's sounds clear what I said.

It does sound clear, thanks.  This was the general scheme I had in mind.  I'm happy that it's something that O'Rielly thinks would work. 
Offline Kova

Senior Member





« Reply #7 - Posted 2006-03-08 23:18:16 »

on second thought... maybe it's not from O'Reilly... I read many tutorials lately so got things messed up. If you're interested exactly about it message me and I'll look it up.
And you got it wrong, the networking plan is all from me (so it's filled with holes probably Smiley ), what I picked up from that tutorial is just that when you complete a row you put row of random garbage to your opponent.
Offline JoshuaD

Senior Newbie




Java games rock!


« Reply #8 - Posted 2006-03-08 23:24:54 »

on second thought... maybe it's not from O'Reilly... I read many tutorials lately so got things messed up. If you're interested exactly about it message me and I'll look it up.
And you got it wrong, the networking plan is all from me (so it's filled with holes probably Smiley ), what I picked up from that tutorial is just that when you complete a row you put row of random garbage to your opponent.

Awesome.  Either way, knowing someone else came up w/ the same general idea I did gives me alot more confidence that it's a good idea. Smiley

I would like the name of that book/tutorial too, if you can find it.

Thanks!
Offline Kova

Senior Member





« Reply #9 - Posted 2006-03-08 23:47:37 »

click here, then go to part 3
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.

xsi3rr4x (16 views)
2014-04-15 18:08:23

BurntPizza (14 views)
2014-04-15 03:46:01

UprightPath (27 views)
2014-04-14 17:39:50

UprightPath (12 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (51 views)
2014-04-10 04:04:31

BurntPizza (110 views)
2014-04-08 23:06:04

tom_mai78101 (211 views)
2014-04-05 13:34:39

trollwarrior1 (179 views)
2014-04-04 12:06:45

CJLetsGame (185 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!