12.07.2015 Views

Implementation of a Peer-to-Peer Multiplayer Game with ... - DVS

Implementation of a Peer-to-Peer Multiplayer Game with ... - DVS

Implementation of a Peer-to-Peer Multiplayer Game with ... - DVS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}// init gamegame ->init(device , timer , eventMgr);// set up AI (optional)<strong>Game</strong>AI* = new SimpleAI();ai->init(game , timer , eventMgr);Finally, the main event processing loop provided by the timer component is started:timer ->run();The run() method blocks until the game is aborted. When it returns, all game objects are cleaned upand the program exits.An alternate network engine can be used simply by instantiating another implementation. For instance,the client-server network for the group network engine is set up using the following two lines:GroupNetwork* network = new CUSPClientServerNet(localPort , serverAddr);NetworkEngine* networkEngine = new GroupNetworkEngine(network);4.3.2 GUI-less SetupIf the game is <strong>to</strong> be run <strong>with</strong>out a 3D rendered GUI, two minor changes are necessary. Most importantly,IrrlichtDev has <strong>to</strong> be instructed <strong>to</strong> omit the setup <strong>of</strong> 3D rendering by setting the second parameter <strong>of</strong>its construc<strong>to</strong>r <strong>to</strong> false:IrrlichtDev* device = new IrrlichtDev(eventMgr , false);Second, it is advisable <strong>to</strong> use the <strong>Game</strong>Timer implementation for the BubbleS<strong>to</strong>rm/CUSP library <strong>to</strong> getrid <strong>of</strong> the busy-wait main loop. Of course, this only works if CUSP is used as the transport pro<strong>to</strong>col.<strong>Game</strong>Timer* timer = new BSTimer();4.3.3 Further ConfigurationSome further configuration settings for various components are s<strong>to</strong>red in config.h. Currently these areprimarily the locations <strong>of</strong> media files (3D models and textures) for the rendering engine.4.4 SimulationTo run the game in the BubbleS<strong>to</strong>rm/CUSP simula<strong>to</strong>r, it is not built as an executable but as a staticlibrary <strong>to</strong> be linked <strong>to</strong> the simula<strong>to</strong>r. The library is built <strong>with</strong>out main.cpp but instead <strong>with</strong> simnode.cppcontaining the entry point for the game. Instead <strong>of</strong> a main() function, there is void startNode(constchar* peerAddr, const char* gatewayAddr).The startNode() function initializes a single node game instance in a way very similar <strong>to</strong> the mainfunction <strong>of</strong> the standalone game version. The two function parameters specify the peer addresses for connecting<strong>to</strong> the virtual peer-<strong>to</strong>-peer network. peerAddr specifies the peer <strong>to</strong> connect <strong>to</strong>, and gatewayAddroptionally specifies a gateway node that helps <strong>with</strong> the connection <strong>to</strong> the peer if that peer is behind aNAT in the simulated network. In the simula<strong>to</strong>r, addresses are not IP addresses but just node IDs. Butas long as the application does not expect a particular addres format, the CUSP simula<strong>to</strong>r keeps thedifferences <strong>to</strong> real networking completely transparent <strong>to</strong> the application.62 4.4 Simulation

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!