Link to home
Start Free TrialLog in
Avatar of davidastle
davidastle

asked on

Object Oriented Networked Game Design Question

I am making a game.
This will be a good game.
The game is being written in managed directx in C#.
I have a question about this game.
It is a multiplayer game in which people connect to a server.
Each person controls a person.
I have a moveable object class.
Every graphical object inherits that class directly or indirectly.
In my person class, should I have the moveable object as a member variable or make the person class inherit the moveable object?
SOLUTION
Avatar of str_ek
str_ek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of davidastle
davidastle

ASKER

I compared the efficiency and most of the examples run at very similar frame rates
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, first of all, I am using DirectPlay for the server. This decision is based on the face that DirectPlay has a LOT of built in functionality, and making a server to compete with the directx server is a difficult task.  Also, future changes that the managed directx team makes to directplay will only benefit me.

It seems that you want an example of how I handle movement.  I learned about this method from an article the Game Programming Gems 3 books.
Lets say that Person A wants to move forward.  His program does initial validation checks, and if it seems that it is alright for him to move forward, he will be rendered at his new position on the screen.  He then sends a packet out to the server that states his new position (don't criticize me if this is inefficient, but please provide an alternative; i'm doing optimizations later).  The server then performs validation checks, and if it finds an error, it will let the client know and deal with it.  The server then reveals the clients new position to everyone (if it changed).

The client uses an asynchronous connection that calls a function every time a packet is received.  That packet is parsed, and then the appropriate event is fired.  If that event is significant for the player class, he will be subscribed to it.  Else, the event will be handled elsewhere.  For example, if some parsed data reveals that player number 7 just shot your player, an event will be triggered that passes in the appropriate parameters, and the player class will be subscribed to this event and handle it.

When the player moves, he will fire an event that states his new position.  The ValidateAction class will be subscribed to this event, and it performs the initial validation checks and if the movement is valid, then this class will fire another event that the client (connection/socket class) is connected to.

Please give me constructive criticism.  Playing devils advocate won't help me.
Let me perhaps save some time by anticipating a criticism.  You may dislike my use of events, but I am only implementing this system after much, much thought.  My reasoning is that events allow for much more readable code, and much more changeable code.   For example, if i later want to make a MovementAnalyzer class that analyzes the movement habits of a group of players and I did not make an event that passes in the ID of who moved and his new location, I will have to changev the client's connection class code to call a function in the MovementAnalyzer class.  And if i later get rid of the movement analyzer class or adda  new one... again I have to change the client code.  I believe this is anti object oriented, as the client class is dependent on the external classes.  Making a PlayerMove event would solve this problem.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Bcladd,
U are awesome. Have you written any books?
Venkatesh.S
One in progress. Don't doubt that ad space will be purchased here.
-bcl
Looking at my argument against the Mover/ValidateAction publish subscribe connection: At the cost of additional event types you have the ability to publish a "proposed move" from the Mover and then have the ValidateAction object publish the "move" event after validating. Then those interested in moves (as opposed to simply proposed moves) can subscribe to the approved move event. Increases complexity of events but decouples ValidateAction from Mover (and all the other action starting objects).

-bcl
Yes, i have decided to use cancellable events (actually built into C#).  I'm working on getting the basic architecture for my game up where people can connect and walk around.  Right now I am trying to work out some thread sync issues.  Actually, let me start a new post on this topic.