Classes - Lend me a hand please

Started by
7 comments, last by S0n0 18 years, 7 months ago
Im making a new game and im trying to figure out how to separate the windows creation and the d3d initialization in different classes.. and im getting some troubles because both classes have data they both need.. any tips for pulling this one off thanks a lot guys!
Advertisement
the data that both classes need should be put in a class or a struct then passed to the other two classes.

Beginner in Game Development?  Read here. And read here.

 

hey thanks for the reply

can u give me a small ex. of what ure saying here
thanks a lot friend
u'll have to post your code first.

Beginner in Game Development?  Read here. And read here.

 

HWND initWindows(HINSTANCE hinstance);
void initD3D(HINSTANCE hinstance, HWND hwnd);

And voila, you have two separate functions, initializing the two subsystems, and both receive a copy of the data they need. (Assuming they both need the HINSTANCE. I can't actually remember if D3D needs it, but let's assume for the sake of argument that it does)

First you call initWindows, it returns the HWND, which is then passed to the D3D initialization through the second function. Not exactly rocket science. :)
oh.
he made it sound much more complicated than that...

Beginner in Game Development?  Read here. And read here.

 

What he meant was:
Make another struct or class that contains all data that both subsystems need. There will be more than just HINSTANCE and HWND. Like width and height.
Then pass an instance of that to your subsystems.
Thanks a lot ill try this approach
if i've understood your question correctly, this would also work ;)

// VideoBase.hpp -----------------------------

class IVideoBase {

protected:

// This will be global and private for any class derived
// from this one
static AnySharedDataStructT AnySharedDataStruct;

public:

static void StaticInitVideoBase( )
{
// Define values here for <AnySharedDataStructT>
}
};


// VideoBase.cpp -----------------------------

AnySharedDataStructT IVideoBase::AnySharedDataStruct;

// VideoClass.hpp ----------------------------

class IVideo : public IVideoBase {

public:

void AbuseMyGlobals( void )
{
// Access global data private to this class
IVideoBase::AnySharedDataStruct.Member = AnyData;
}
};

// D3DRenderer.hpp ---------------------------------

class ID3DRenderer : public IVideoBase {

public:

// Do the same as in <IVideo>-class
};

This should be an easy way, and if you implement a class in future which
will access the same data, just inherit it from IVideoBase. There's no need
for a <initXXX>-function...

This topic is closed to new replies.

Advertisement