Jump to content
  • Advertisement
Sign in to follow this  
PnP Bios

Library design question

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

Hello all, I am working on the next itteration of my 2d rendering library, hxRender, and this time, I am going to write it in C++, instead of C. The big thing about this version, more than just using classes, is that it is going to have the capability to use different libraries to create a context. So, I am wondering, how should I go about this. The most simple and straightforward way I can think of doing this would be using a virtual class, then creating a new object pointer to it from a derived class, like this, i guess... hxContext *screen = new hxWin32Context(); or hxContext *screen = new hxSDLContext(); Or, should I have initiator and destroyer functions like DirectX? hxContext *screen; screen = hxWin32CreateContext(); hxReleaseContext(screen); Perhaps there is yet another way I should do this?

Share this post


Link to post
Share on other sites
Advertisement
I like the first idea. Possibly then automatic 'garbage collection' of contexts could be implemented or something. I don't like DirectX's style because it forces you to learn an entire new API if you don't already know COM and stuff. If you go 'C++-style' anyone that knows C++ can allocate objects and stuff without needing to learn an entirely new API.

Cheers!

Share this post


Link to post
Share on other sites
Yes, go with the first approach, maybe later on you could add a function like:

// create a context based on the name, can be "gdi", "sdl", "ogl", etc.
hxContext* contextFactory(const std::string& type);

This way you can completely forget what type of context you are using, if you need some other object, say a sprite, you can ask the context object for a new sprite. The win32 implementation creates a new hxWin32Sprite, the sdl implementation returns a new hxSDLSprite. Look up the factory pattern for more information.

I would also recommend that you use some kind of smart pointer, boost::shared_pointer probably works here. This way you don't have to remember to delete/release your objects.

Share this post


Link to post
Share on other sites
I was leaning toward the second method, simply because that would make it easier to code. I haven't worked much with DLL's, and I hear they can be quite a pain to work with. I absoultly refuse to involve my self with COM.

I won't use BOOST, or any of those other libraries either, not everybody is going to have those installed, and I don't want this project to result in dependancy hell.

I'll play around with both methods for a while, basicaly, all the functions are going to do is wrap around the new and delete, so If I don't feel the need for them, they may not go in there.

Thanks for all the advice.

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!