Skip to main content
GameDev.net gamedev.net
🔒 Locked

Managing Game Objects - OOP Mess

Started by Telamon Feb 17, 2005 at 7:18 PM 2 replies 900+ views
Original Post
Telamon
Telamon
I realize that this post may be hand wavy and vague, but I'd appreciate any input. I'm building a multiplayer realtime space trading/exploration game. The problem I'm running into is how to manage the game objects. Specifically, I'm having trouble keeping the object state data (like position, rotation, velocity, ect) separate from the object-drawing code. I'm using C# and DirectX. I have a Direct3D window drawing inside a picturebox. I'm trying to adhere to the model-view-controller model, but I'm also having trouble having a C# object for each object type that knows how to draw itself because the picture box actually owns the D3D device handle. Making the whole thing multiplayer is an even bigger mess since it really forces the distinction between the state data for each object and what it happens to look like. I'm running into an intermediate level question here. I've got code that draws a bunch of ships and asteroids and planets everywhere, but networking is hung up on completely abstracting out the critical networkable parts of the objects. I don't really have any idea how to structure a project like this (ok, I have lots of ideas, picking a promising one to explore is hard).
fproto
fproto
what i have is objects, textures, materials, geometry.
the object is responsible for doing the transformations, etc.
the reason to keep them separate, is so that you don't have to
keep a mesh of a tree for every tree you draw in a scene.
you load one tree, and create numerous objects. apply the texture,
apply the material, apply each of the object matrices, and draw
the same mesh for each of them. for times where you just have
one of each thing, you can create a "package" class that just has
one of each of those things for convenience.
function(prototype);
dmikesell
dmikesell
Sounds like you need a good scene graph reference/book...
dave
dave
Well as you may or may not be aware im writing a HUD API for DirectX. Now for this i had to come up with some efficient way of managing controls like buttons and stuff.

Now there are several ways you can do it, these are two:

a) The method i have used for my scenegraph and object management system is for the user to register objects like buttons quads and boxes etc with a 'page' object during app-setup, when ur loading the level. Then u register the page with the scenegraph and page management system. So basically at game-play-time when the menu needs to be displayed, you simply request that a certain page needs to be displayed by adding a request to a request-list, that lies within the scenegraph. Now with this method you compile the page of controls during app setup and this builds the vertex buffer.
b) Another method is to register components with a scenegraph and have each component have its own vertex buffer. Then at run time you can build up a request list and then have the scengraph render individual controls according to this list.

Now when u are mentioning that updating all the objects and keeping track of them is tricky, i would suggest looking into having a base class that is the foundation for every renderable object in ur scene. This way you can have something called a polymorphic collection. A polymorphic collection is in the loosest terms an array or vector or list or deque of pointers that point to objects on the heap of type base-class. No what this allows you to do is to also have these 'base-class-pointers' point to any object that is derived from the base-class. As you may now see you can have all the objects in the scene in one controlled container. This would then allow you to run through the whole collection and Refresh() them (only if ur base class has this function). You can overload the base class Refresh() in each of the derived classes and therefore Refresh() each object in the way that suits it, providing they all take the same parameters, or none.

Now i know i kinda went off on one here but i hope it helps. Ive described theses ideas in the loosest terms, but hopefully in can shove you in a better dirction.

ace

Topic Locked

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

Sign in to reply to this topic.