Jump to content

View more

Image of the Day

#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

OOP Help

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Normie   Members   


Posted 07 August 2001 - 04:26 PM

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?

#2 jaxson   Members   


Posted 07 August 2001 - 05:18 PM

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.

#3 Normie   Members   


Posted 07 August 2001 - 07:16 PM

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"™

-Normie, Lazy and Damned Proud

#4 jaxson   Members   


Posted 08 August 2001 - 06:20 PM

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.

#5 Shannon Barber   Moderators   


Posted 10 August 2001 - 05:22 PM

Your CDirect3D class could have a
CMyTextureClass* CreateTexture(...);
method that creates and initializes textures.

Magmai Kai Holmlor
- Not For Rent

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.