Advertisement

2 players on 2 PCs

Started by July 05, 2006 06:01 AM
1 comment, last by hplus0603 18 years, 7 months ago
Hi, I am totally new to this... Currently, I have a program written in C++ and OpenGL on Linux which can run a real-time driving simulator or real-time pedestrian simulator one at a time but not concurrently. Both simulators are controlled by users with keyboard. I'd like to set up a system with 2 PCs (thus 2 displays: 1 with driver's view and the other with pedestrian's view) interacting with each other. i.e On 1 Pc, A plays the driver and on the other Pc, B plays the pedestrian, and they share the same environment, meaning the 2 PCs must communicate real-time info. My questions: 1) How do I physically set up the 2 pcs to communicate with each other? With a crossover cable and what other settings do I have to do? 2) How do I make the 2 PCs communicate real time info? Thanks in advance, Yen
I'm not understanding your game concept quite well: Here's what am I understanding. Please tell me if I'm wrong.

PC A: Player (A) - The "Driver" on his screen (A) <- only one display on PC A right?

PC B: Player (B) - The "Pedestrian" on his screen (B) <- only one display on PC B right?

If this is how it is - basically you have game that needs networking. This game can be played over a LAN (ethernet cable connecting both the computers) or if developed, over the internet.

Look around for a C++ networking tutorial. You might find this site interesting:
http://www.tutorialized.com/tutorials/C-and-Cpp/Networking/1

Good luck
D. "Nex" ShankarRed Winter Studios
Advertisement
First, you have to make sure that regular networking works for these machines. If you can "ping" one machine from the other, then you're good to go. Typically, this requires two network cables, a hub, and some way of getting IP addresses to the PCs (if they're on the internet already, you're likely already fine).

Second, you need to add the concept of a pedestrian to your car simulation, and the concept of a car to your pedestrian simulation. That is so that the car can see the pedestrian on his screen, and vice versa.

Third, you need to register the terrains between the two simulations. This means that they use the same "game level" so that they agree on where the boundaries are, where the collisions are, etc.

Fourth, you need for each object to send its state to the other in some fashion. The easiest way to do it is to broadcast on a specific UDP port (assuming both machines are on the same subnet; typically sharing the same networking hub). Thus, you can define that a pedestrian will broadcast a packet X times a second, on port 50371, with the first four bytes being the value "1" and the next 12 bytes being the X, Y and Z of the pedestrian as floats. The car does the same thing, except it broadcasts the value "2" as the first 4 bytes.

Fifth, you then need to make each simulation receive the updates from the other simulation, and update the appropriate entity. Typically, you'll have position and velocity in each packet, and use dead reckoning to drive the remote entity on the local display.

Now, instead of using the ad-hoc solution for state updates in step four, you probably want to use a pre-made software package. For the kind of simulation you seem to be doing, the Distributed Interactive Simulation standard (DIS) seems to be about right. Look it up on google.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement