Archived

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

Layers of abstraction - from scratch

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

What I''m pondering upon has been talked about a lot here on gamedev, but still, no matter how many threads I read about the design that goes into making a robust engine, it never gets tiresome. I''ve been a frequent reader for some time, but I''ve never really posted anything until now, because I''d like to get some good ideas on things regarding the layers of abstraction people put in to their engines. Ok, basically, this is the case: I''m thinking about writing a Life Force/Gradius-like shooter, using VC++ and Direct Draw. I''ve been messing with DX on and off for some months, but I''ve nailed down the most importants calls for getting the system up and running. Though, my attempts at a decent wrapper for Direct Draw have been pitiful. Don''t know what I should do really. I''ve tried just making a class for DD, which would take care of trivial stuff like creating the DD object; creating a primary surface, backbuffer, etc; a general interface, through which to receive a surface, attaching clippers, etc. It just gets to cluttered, not to mention when I''m trying to incorporate the wrapper into a simple game engine. I''m not sure if I should decouple the inner and lower parts of DirectX entirely from the game engine itself, which sounds like a good thingie, but then comes the problem how I should wrap around the surface neatly enough to not have a big mesh of objects wanting to dig into their parents, responsible for creating ''em, etc. Hope it makes sense... One important thing to nail down at first, it seems, is what belongs in the DD wrapper and game engine, respectively. Would Allegro, with its way of dealing with BMPs, be a good medium level wrapper; where bitmaps are a good abstraction of the lower level gfx calls, and then perhaps your own sprite system be an abstraction layer on top of the bitmaps and oter data. Say we chose the Allegro way of dealing with this mess, and we''d now like to create a BMP class. What should it contain? A statically defined DirectDraw object, from which to get the surface to place our graphics data on. Or should we set up DirectDraw singelton, so that the inner part of the BMP class could say something like: DD::get_instance()->CreateSurface... How would you guys approach this?

Share this post


Link to post
Share on other sites
Don''t wrap DirectDraw with your own class; instead, build classes where an abstraction seems appropriate from the POV of the client.

In the case of a 2D top-scrolling shooter, the high levels of the game code will address objects such as the background and individual ships/planes/tanks/whatever. Each ship will use a (shared) animated sprite internally. The background itself can be stored in whatever method seems appropriate for the game (is it built using tiles? is it a single large bitmap?).

Next, use a single abstraction to represent the "screen." High level code might look like "ship->Render()", which calls "animatedSprite->Render(frame,x,y)", which calls "sprite->Render(x,y)", which calls "bitmap->Render(x,y)", which then makes DD calls.

Your goal should be to work with contextually-relevant conceptual units. AI, for example, should never know about DirectX.

btw, I presume you are talking about C++ and OO methods, not just using MSVC. It will probably take you several iterations to find a set of abstractions that you are comfortable with. Don''t worry about getting that right the first time--just keep trying to clean the design each time.

-Anduril

Share this post


Link to post
Share on other sites
Is this the kind of abstraction you are looking for, as an example?

1. Set up graphics (how many back buffers, flip method, resolution)

2. Load bitmap animations

3. Render bitmap animation (location on screen, clipping rectangle)

4. Load level

5. Render level background

6. Swap buffers

7. Release level

8. Release bitmap animation

9. Release graphics

It takes a few tries to figure out what you really need. Your first attempt always suits the specific game you are working on. Then when you start to make more games, you realize you might need to split up the abtraction a little until you get a feel for what the pieces really need to be.


[edited by - Waverider on September 3, 2002 2:09:18 AM]

[edited by - Waverider on September 3, 2002 2:09:49 AM]

Share this post


Link to post
Share on other sites