Best way to integrate networking(raknet) into game flow?

Started by
0 comments, last by hplus0603 12 years, 6 months ago
Hi guys, I'm working on using Raknet in conjunction with Ogre and I want some input as far as how networking(client/server) should be integrated into a main game loop.

Here's an incredibly basic overview of the program flow as I currently envision it

main game loop
{
Detect user input and do whatever needs to be done with it

Game logic such as calculating movements of npcs and other changes to the world

networking loop(grabs packets and sends out new ones indicating change to game state based on input and game logic)
{
}

draw the graphics according to current game state
}

I'm torn as far as whether the netcode should be in its own class. I know this is generally preferable, but I think that in the case of raknet, it may be unnecessary and complicate things. The way raknet grabs packets as they come in within a for loop and then executes actions based on the input makes it hard for me to see how to make it a class very easily.

I'll keep reading about it, I was just hoping someone on here could give me some input from a more experienced point of view. Thanks.
Advertisement

I'm torn as far as whether the netcode should be in its own class. I know this is generally preferable, but I think that in the case of raknet, it may be unnecessary and complicate things.



Generally, you want "simulation" to be a different class from "presentation." Additionally, you want "input" to be input data to the "simulation." From the "network" you may receive "input" for the "simulation" of various game objects. Those "inputs" may be full state dumps -- making "simulation" do simple dead reckoning, or more analogous to user inputs -- making "simulation" do the same thing given the same inputs on each machine.
You probably also need an "entity" class that contains references to the simulation (or perhaps "input consumer") component and the presentation (or perhaps "display tick reactor") component and any other components you may want.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement