• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
  • entries
    10
  • comments
    51
  • views
    41819

Abstraction in a Game Engine/Framework

Sign in to follow this  
Followers 0
ZachBethel

1976 views

If there's one thing that's dang hard, it's trying to find a decent balance between flexibility and simplicity when writing a good abstraction layer. I'm relatively new to DirectX 11, but so far it is a much nicer API to work with than previous versions of DirectX. It's so nice in fact, that I'm having a hard time finding ways to wrap things into nice little bundle classes without losing core functionality. While I don't particularly enjoy having to play around directly with a graphics API (I'd much rather hide it away behind some nice facade), I must say that the designers are making it hard on me.

I ended up creating an IDX11Graphics interface which encapsulate the device context, the device, and the factory object. I have a simple Init() function which enumerates all mode data from all of the adapters and files them away into a data structure that lets me filter modes by adapter, output, and format. Pretty simple stuff. The initialization stuff is the easiest to encapsulate, which is obvious when you look at the DXUT library that Microsoft provides.

I'm starting to realize that there is little you can do to improve the API without moving up a software abstraction layer. The farther up you go, however, the more flexibility you lose. For instance, I was trying to create a render target wrapper class, but I realized that the components of a render target really weren't meant to be coupled, which is undoubtedly why Microsoft did it in the first place. D'oh! There is a nice relationship between how DirectX handles resources and resource views; it seems clunky to just plop them both together into one helper class.

For instance, how do we handle render targets in a flexible way that actually simplifies the process? We could build a class that creates a texture, render target view, and shader resource view, But then how do we handle swap chains, which have a different creation process? The class could take a pointer to the texture as input to allow the user to create it however they want; or we could remove the shader resource view and put it in another supporting class. As another example, I considered writing one IDX11Texture class to encapsulate all types of textures, but one big immediate problem I ran into is high potential for bloat. In order to accommodate all different types of textures (1D, 2D, 3D, etc.), the class would have include ALL of the data. Ultimately, I think these options detract from the elegance of the SDK and make things more confusing and less flexible. This is one aspect of object oriented programming that drives me crazy. There just doesn't seem to be the Right Way to do it.

On the other hand, in order to simplify things, we have to sacrifice flexibility at some point. It's just going to happen. I guess where I struggle is finding the happy medium where an abstraction can make the programmer's life lots easier, but also allow retain the features that they need for their graphics algorithms. It's definitely hard to know what features are needed when you're just learning the SDK--a fact I know first hand.

I think this is the challenge that appeals to me the most about game engine development. There is so much software engineering involved. If you don't carefully plan out the intricate relationships between components and subsystems, the entire things quickly degrades into chaos. I have high respect for people who can grasp it all.

In any case, I have graphics interface in place that takes care of initialization and device enumeration. I am still deciding what other tasks I should give it--whether it should just be a glorified ID3D11Device, or more of an abstract renderer. Because I am still going to retain DirectX 11 access within my engine, I am hoping that it can become both. What really bugs me is when I create a helper interface that ends up just having 5 lines per function call that parrot things back to the Direct3D device. That doesn't seem constructive to me at all.

In any case, that's all I've got for now.

2
Sign in to follow this  
Followers 0


3 Comments


I would caution against lumping the device and device context together - sooner or later you will want to use deferred contexts, and they are inherently separated from the functionality of the device. In Hieroglyph 3 I have a RendererDX11 class that wraps the device, and a PipelineManagerDX11 class that wraps a device context.

The renderer provides the same types of services that the device does - it creates the other resources and objects to be used by D3D11. So to make life easier, I provide creation methods that automatically track the created objects and ultimately maintain a list of things that need to be released at shutdown.

The pipeline manager is what is used for rendering with the pipeline, and can be used with immediate or deferred contexts interchangeably. This makes it so that you can switch between single or multi-threaded rendering fairly easily. Since the device context is used to manipulate pipeline state, then I add methods to the pipeline manager that make that easier.

The abstractions that you choose should be intended to simplify a problem that you see - don't create abstractions simply to do it! Of course you will never plan everything right from the beginning, but nobody can - that is how you learn. That is also why refactoring is such a big part of software engineering too...

That was a great post - very interesting to read. I look forward to hearing what else you have to say :)
0

Share this comment


Link to comment
Ah, see, there's another example. My first instinct is try and encapsulate everything into one nice package class. But it's obvious that Microsoft didn't intend for that to be the case. Like I said, I'm relatively new to DirectX 11. I didn't realize that deferred contexts would need that functionality; but now that you mention it, I do see that. Thanks for the heads up!

I've been looking over your Hieroglyph 3 framework. Have you ever read Game Coding Complete? I can see architectural elements in your code that resemble those used by McShaffry in his book (like the render views). It's a lot of source files, but it looks like many of them are quite small (i.e. the classes are pretty thin abstractions). I particularly liked how your wrapped the shaders and effect framework. I may reference your code for my implementation. :)

Your comment about refactoring is very sound. I'm going to devote my next blog post to that, because I really struggle with it. Thanks for the feedback!
0

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now