Cool Code: Wrapping the API
2 posters
Page 1 of 1
Cool Code: Wrapping the API
Something I'm kicking myself for, especially since I'm reaching the limits of Allegro, is not wrapping the API into its own static class. Obviously, structures like sound clips, fonts and bitmap surfaces need to be in the scope of the API, but the game would be portable if all this would be externalized to the actual logic and class hierarchy.
A static class like "External" or "API" for instance would have functions like
And each of these structures (BitmapSurface, SoundClip and Font) will each have to be their own classes which wrap the API's structures, making access to the API inaccessible by the rest of the project.
This way, porting to another API or OS would simply be a matter of changing the names of the structures within BitmapSurface, SoundClip and Font.
A static class like "External" or "API" for instance would have functions like
- Code:
BitmapSurface* GetBitmapSurface();
SoundClip* GetSoundClip();
Font* GetFont();
And each of these structures (BitmapSurface, SoundClip and Font) will each have to be their own classes which wrap the API's structures, making access to the API inaccessible by the rest of the project.
This way, porting to another API or OS would simply be a matter of changing the names of the structures within BitmapSurface, SoundClip and Font.
Nate- Posts : 70
Join date : 2011-06-14
Re: Cool Code: Wrapping the API
I had this same thought the other day while I was mowing the yard (I think of the weirdest things when I'm doing something). I thought about making some smart class that would hold all the OS/API types and refer to them and all the user has to do is bind the proper functions.
It's a more complicated approach but still on the same concept. I definitely want to do that with my framework when I get to releasing version 2.0 just for the sake of having something I don't have to rely on one API for. (Haven't even gotten to 1.0 yet! )
It's a more complicated approach but still on the same concept. I definitely want to do that with my framework when I get to releasing version 2.0 just for the sake of having something I don't have to rely on one API for. (Haven't even gotten to 1.0 yet! )
MaverickProgrammer- Posts : 63
Join date : 2011-06-14
Re: Cool Code: Wrapping the API
I likely won't do it with Salem. It probably won't be worth the trouble at this point. Next time I start a project, it's gona get this treatment though.
Nate- Posts : 70
Join date : 2011-06-14
Re: Cool Code: Wrapping the API
Well I would hope you wouldn't jump at it with Salem. That'd definitely set us back.
MaverickProgrammer- Posts : 63
Join date : 2011-06-14
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|