Jump to content
  • Advertisement
Sign in to follow this  
EvilNando

Classes - Lend me a hand please

This topic is 4817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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. :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!