Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


OOP Help

This topic is 6188 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

I''m making a game in 2D through Direct3D (I know which forum this is, keep reading). I have a class that looks something like this:
class CDirect3D  
	void Update();
	void Render();
	virtual ~CDirect3D();

	IDirect3DTexture8* m_pTextures[256]; //arbitrary limit
	IDirect3D8* m_pD3D;
	IDirect3DDevice8* m_pDevice;
	ID3DXSprite* m_pSprite;
I was thinking of creating a new class to encapsulate m_pTextures in, so I have more control over each sprite. However, I''d need the new class to access members from CDirect3D (namely, m_pDevice). Having the new class inherit from CDirect3D just for the data members, however, seems a bit extreme. Is there a way to make some of the data members of CDirect3D accessible to the new class without making them global (or public static, or anything like that)? Also, the work I''ve done so far made me realize that I don''t know squadoo about organization in OOP. I know most of the technical details by heart, but my inability to create really good classes is seriously putting my game engine in jeopardy. Can anyone point me to a tutorial or something like that for OOP organization, esp. in video game development? Thanx, Normie "But time flows like a river... and history repeats." ... So...what about beaver dams?

Share this post

Link to post
Share on other sites
There are a few ways that you can do this. Some ways are easier than others and some ways are more object oriented than others. Here are some ideas:

a) Use C++ ''friend'' declarations to make member functions or variables available to your texture class.

b) Have a static member of your texture class that you set at some point with a pointer to the D3DDevice. In this way, you have access to the Device from all textures without storing a hundred copies of it. (This only works if you only have one D3DDevice in your entire app)

c) Pass in the device pointer everytime you need it. This is a bit of a hassle, but not a completely unrealistic choice.

Hopefully, these will give you some ideas. I''m sure there are more alternatives.

Share this post

Link to post
Share on other sites
Wow, thanks for the advice! Completely forgot about using friends (back to my C++ books for me, I guess ), and that static variable idea... damn, never even occured to me. Just to make sure I''m clear on the static variable idea...I assume you mean a private IDirect3DDevice8* in the sprite class, with a static function in the sprite class to set it? (I think I got it right, just want to check)

Oh yeah, and thanks for the third idea there...would probably just use that and be done with it, but that would be a serious violation of my "Lazy Programmer''s Doctrine"(tm)

-Normie, Lazy and Damned Proud

Share this post

Link to post
Share on other sites
Yes, I follow that same doctrine as much as possible too. I think most programmers do. Why else would we have ''printf'' instead of ''print_formatted_string'' and ''int'' instead of ''integer''?

As for your question, yes you have the right idea. Just make sure that you set that pointer before trying to do any drawing and also make sure you don''t try to release the device more than once.

Share this post

Link to post
Share on other sites

  • 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!