Skip to main content
gamedev.net
🔒 Locked

Class layout

Started by s3202 May 28, 2002 at 1:51 PM 1 replies 350+ views
Original Post
s3202
s3202
I''m curious, how do many of you layout your code? I''ve tried many methods and haven''t been satisfied with one of them. Let me give you some examples of what I mean: I''ve tried making a series of objects that represent each "scene" in the game. The problem: What if I want to display two or more scenes at once? I''ve tried making a class for each item in a scene. A player class, background class, etc. The problem here is, each class still has its own D3D code. What if two objects use the same texture? Now I''m wasting memory. I''ve tried keep the D3D code out of the classes, but that seems to be defeating the purpose of the classes. They''re becomming not much more than data containers with no functionality in them. Does anybody have more efficient methods they might want to share? ---- "Caw, caw, BANG f**k I''m dead!" --The Crow
----Herb M. (s3202)
sphinx23
sphinx23
Maybe this helps:

Try to write a separate renderer class. this class should
be the only class with D3D code in it. then write a World
class, in which the separate scenes are stored.

-----------------------------------------------------------------

class Scene
{
// the objects or vertices are stored here
};

class World
{
Scene *pScenes; // pointer to the memory where
// the scenes are stored
int nScenes; // the scene count

// other stuff...
public:
Scene *GetScene (int nScene); // returns a pointer to
// a scene
int GetSceneCount (void)
{ return nScenes; }

// other stuff...
};

class Renderer
{
public:
void RenderScene (World *pWorld)
{
for (int i=0;iGetSceneCount ();i++)
{
// Get the current Scene like this:
Scene * pScene = pWorld->GetScene (j);

// here you can access the scene
// and render it
}
}
};

-----------------------------------------------------------------

Kylotan
Kylotan
quote:
Original post by s3202
I''ve tried making a series of objects that represent each "scene" in the game. The problem: What if I want to display two or more scenes at once?

I''ve tried making a class for each item in a scene. A player class, background class, etc. The problem here is, each class still has its own D3D code. What if two objects use the same texture? Now I''m wasting memory.

If you want more than one scene, have more than one Scene object. Each scene object contains its own objects.

If you want to share a texture, then share it. Don''t have objects owning textures, just have them store a value that states which texture they need from the central texture repository.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]

Topic Locked

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

Sign in to reply to this topic.