Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Networked Racing Game Andrew Williams. Purpose We have seen with the incrementer program the fundamentals of network programming We are going to apply.

Similar presentations


Presentation on theme: "A Networked Racing Game Andrew Williams. Purpose We have seen with the incrementer program the fundamentals of network programming We are going to apply."— Presentation transcript:

1 A Networked Racing Game Andrew Williams

2 Purpose We have seen with the incrementer program the fundamentals of network programming We are going to apply them to a racing game The intention is not to create a good game – We want to demonstrate the concepts – Specifically deciding what information to send between the participating machines

3 RaceTrack Originally written for a colleague who wanted a demonstration of maths in games It shows two “cars” (which are just circles) and a number of dots in the road. It shows how a smooth racing line can be created without producing a huge number of waypoints In later versions the dots and the green car are invisible…

4 Race Track Have a look at the demo…

5 Race Track There is nothing especially interesting about the program (as you will see if you take a quick look) – I have used it because it was already there Our question must be, how are we going to make this network-aware? We will start with a simple Master-Slave arrangement

6 Master - Slave Our first attempt will be to simply mirror the contents of the master’s screen on the slave’s screen

7 Master - Slave Master Does what the previous RaceTrack.exe does It puts the dots down It has the green car follow the dots – (the green car and dots are invisible) It has the yellow car follow the green car It sends to the slave the information about where the car is Slave It receives from the master the current location of the yellow car It simply puts the yellow circle on the track to reflect the information it has from the master That’s it

8 CarStatusInformation.h The master has to send to the slave the current location of the car We use CarStatusInformation.h for this: class CarStatusInformation { public: int worldX; int worldY; };

9 CarStatusInformation These excerpts are from master.cpp Declaration (obviously before the game loop): CarStatusInformation *cSI = new CarStatusInformation(); Usage: cSI->worldX = yellowCar->get_x(); cSI->worldY = yellowCar->get_y(); send.send(2*sizeof(int), cSI);

10 CarStatusInformation These excerpts are from slave.cpp Declaration (obviously before the game loop): CarStatusInformation *cSI = new CarStatusInformation(); Usage: if(receive.receive()) {// Listen for the master memcpy(cSI, receive.p->data, 2*sizeof(int)); yellowCar->set_world_position(cSI->worldX, cSI->worldY); }

11 First Networked Racing Task The master-slave version is NetRacing401 Your first task is to modify the master-slave version so that there can be many slaves, each of which is on a different machine I don’t care how you do this


Download ppt "A Networked Racing Game Andrew Williams. Purpose We have seen with the incrementer program the fundamentals of network programming We are going to apply."

Similar presentations


Ads by Google