Curiosity Labs
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Cool Code: Wrapping the API

2 posters

Go down

Cool Code: Wrapping the API Empty Cool Code: Wrapping the API

Post  Nate Thu Jun 30, 2011 3:09 pm

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

Back to top Go down

Cool Code: Wrapping the API Empty Re: Cool Code: Wrapping the API

Post  MaverickProgrammer Thu Jun 30, 2011 7:24 pm

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! Razz )

MaverickProgrammer

Posts : 63
Join date : 2011-06-14

Back to top Go down

Cool Code: Wrapping the API Empty Re: Cool Code: Wrapping the API

Post  Nate Thu Jun 30, 2011 7:45 pm

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

Back to top Go down

Cool Code: Wrapping the API Empty Re: Cool Code: Wrapping the API

Post  MaverickProgrammer Thu Jun 30, 2011 8:50 pm

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

Back to top Go down

Cool Code: Wrapping the API Empty Re: Cool Code: Wrapping the API

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum