Skip to main content
gamedev.net
🔒 Locked

Code Design Problem...

Started by riyunoa Jan 24, 2007 at 11:48 AM 3 replies 800+ views
Original Post
riyunoa
riyunoa
I've been coding a multiplayer game, and I've run into this problem - I have a network class (holds all player/position data), and a World class (holds all object data). If the World class needs to access the Network class, how do I go about doing that? Do I: -Put a Network pointer in the World class -Put a World pointer in the Network class? I'm wondering the same thing about my input class... Thanks in advance. :)
templewulf
templewulf
Generally, the answer is "neither". You should prefer function parameters when you can have them.

Having said that, I often use a "game" or "application" object, which contains all the other manager-type objects. A pointer to "game" is a pointer to everything. The downside is that the class is far more mutable (read: unstable). The upside is that it's a very convenient hack.
XBox 360 gamertag: templewulf feel free to add me!
JohnBolton
JohnBolton
Since the World needs to access the Network, it needs some way of referencing it, and since the Network does not access the World, it does not.

Some higher level questions to consider: Why is the class that contains the players' positions called "Network"? Also, shouldn't the World contain the players, too? If not, then why does it need to access the player's positions?
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
umbrae
umbrae
I would probably have another class that performs actions on the world and network classes. That way the world doesn't need to know about networking.

When programming a game engine at the end of last year (for Uni no less) we had the following objects:

Single Player, No Networking

view
|
client - model
|
server
|
model


Server and Client:

view
|
client - model
|
proxy server
|
/
|
proxy client
|
server
|
model


Two Player:

view
|
client - model
|
| client - model
| |
server
|
model


It was quite cool because the server doesn't need to know what type of clients are connected. It was also cool because we could reconfigure the objects in various ways to have different game configurations. This would all be done dynamically of course, but the project was about components and we needed to use design time editing in Visual Studio.

We also had input classes, but they were very similar to the view and would complicate the ascii diagrams.

The client always has an additional copy of the model because it needs to know where things are itself. The upside is that it could run partial simulations when networked to predict what is going to happen in the world before the next update.

Anyway I'm not sure if this helps, I hope you find a good solution.
riyunoa
riyunoa
Thanks very much for your responses. :) Umbrae, I'm trying to acheive that, to make the network aspect seperate from the rest of the game, yet allowing the game to access positions and everything sent over the network. So you mean like, the Network returns some values to the main class, and the main class processes it and tosses it to the World?

Meep, I should have elaborated on my current code structure...
-World contains the player objects themselves, plus all the items and stuff.
-Network contains a list of all the playerIDs and respective positions.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.