• 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.
Sign in to follow this  
Followers 0
Mellkor

DirectX Style Engine Design Questions: Object Drawing and Drawcalls..

4 posts in this topic

Hi, 
 
I used to spend a lot of time messing around with xna then i realized that i needed to get some some professional education in Software Development so i put xna on hold... Now, i want to start doing some more projects with my now improved knowledge.
 
The way i used to approach drawing objects on the screen was to have something like this (doing this off the top of my head)
 
Class Sprite : Game
{

bool drawable = false;

Public override Draw()

{

//Draw Something

}

}
 
Class Manager
{

List<Sprite> sprites = new list<Sprite>();

foreach s in sprites

{

if (s.drawable)

{

s.Draw();

}

}

}
 
So all the sprites would draw themselves if their flaged as drawable...
 
Now i'm looking at doing some Directx work using SharpDx purely as learning experience. But im wondering if this technique would work or even if its the "Way its done" when it comes to directx.
Im also under no illusion that there is much more involved with directx, But as a concept is this how its done?
 
I hope people can interpret what i'm asking...
 
Thanks in advance,
 
Mell.
 
 
 
 

0

Share this post


Link to post
Share on other sites

It totally depends on the scope/scale of things and your goals. DirectX, though I haven't used SharpDx is in essence not all that different than XNA from what I'm aware of, if you take all the high-level abstractions away. Yout create your resources, set a bunch of states, bind those resources and issue a draw call. Things get a bit more complicated when you start using shader instead of the fixed function pipeline (which I'd recommend), but practically, your approach would work. Is this what you want, then go with it, you can do all that in each class that describes a renderable object. I personally wouldn't consider it a good design though, since it isn't flexible at all. As an advanced system, you would e.g. build a low level rendering system with render commands and queues, as thoroughly described in this thread (pages 2+ specially), and probably apply an entity/component-like system on the very top of things. Its certainly a hell lot of work to get things running, but once you have it, its totally satisfactory to use (if integrated right).

 

Two more things though, I'm uncertain if this is just because its sample code, but:

 

- class Sprite : Game ... so Sprite derives from Game? So your sprite IS a game? Inheritance is normally an IS-A relationship, so eighter this is a slight naming issue (Drawable instead of Game), or there is some serious design flaw going on I'd encourage you to look at more closely.

 

- class Manager : there is some discussion about whether "manager" classes are too wide-ranged, unspecific and bloated, as IMHO, I'd agree that those classes often end up doing to much work, but this is up to you to decide. However, I assume too that this should really be DrawManager/RenderManager, since otherwise this would be one unspecific, possible monster class, and I'd suggest splitting that up a little bit too.

 

Hope that helps, and that those are thing you'd wanted to hear? (Your questions are a bit wague, so I'm not sure).

Edited by Juliean
0

Share this post


Link to post
Share on other sites

It totally depends on the scope/scale of things and your goals. DirectX, though I haven't used SharpDx is in essence not all that different than XNA from what I'm aware of, if you take all the high-level abstractions away. Yout create your resources, set a bunch of states, bind those resources and issue a draw call. Things get a bit more complicated when you start using shader instead of the fixed function pipeline (which I'd recommend), but practically, your approach would work. Is this what you want, then go with it, you can do all that in each class that describes a renderable object. I personally wouldn't consider it a good design though, since it isn't flexible at all. As an advanced system, you would e.g. build a low level rendering system with render commands and queues, as thoroughly described in this thread (pages 2+ specially), and probably apply an entity/component-like system on the very top of things. Its certainly a hell lot of work to get things running, but once you have it, its totally satisfactory to use (if integrated right).

 

 

Well, i eventfully want to have better, faster, more efficient algorithms and designs but if you recon this approach is plausible for the time being i can use it as a crutch..

At the moment i'm still only experimenting in 2D, but when i start with 3D experimentation i would very much like a thorough understand of the best practices.

 

 

Two more things though, I'm uncertain if this is just because its sample code, but:

 

- class Sprite : Game ... so Sprite derives from Game? So your sprite IS a game? Inheritance is normally an IS-A relationship, so eighter this is a slight naming issue (Drawable instead of Game), or there is some serious design flaw going on I'd encourage you to look at more closely.

 

 

Its more complicated than the code i written above, but eventually something will inherit from game. Game being the main component in xna that has: "initialize", "Update" And "Draw" methods.

 

If i passed game as a parameter in the constructor, or passed it by some other means i could not invoke and override game.Draw() and not take advantage of polymorphisim. Unless i'm missing something?

 

I know inheritance is usually an "Is-A" model, but the way XNA seems to be constructed they kinda bend this rule abit..

 

 

- class Manager : there is some discussion about whether "manager" classes are too wide-ranged, unspecific and bloated, as IMHO, I'd agree that those classes often end up doing to much work, but this is up to you to decide. However, I assume too that this should really be DrawManager/RenderManager, since otherwise this would be one unspecific, possible monster class, and I'd suggest splitting that up a little bit too.

 

Hope that helps, and that those are thing you'd wanted to hear? (Your questions are a bit wague, so I'm not sure).

 

 

Yeah that's kinda the bulk of my question, If i had something that iterates through all the drawable objects in a level, Then invokes a draw method in a super class accordingly, wouldn't that be completely inefficient?

Seems you have pointed me in the right direction of some healthy alternatives so ill give them a read, shortly.

 

Although i know my way around code better, Directx and game programming concepts i'm still not too sharp on. Most of the information on directx programming is pretty much "how to draw a triangle" ect, but i haven't found any real "meaty" discussions on actual engine design, i'e how to draw a scene of triangles with different states.

0

Share this post


Link to post
Share on other sites

When you leave the drawing to the individual object to handle, then you're limited to draw for only that object.  It does make thing easier to read, organize and understand.  But with the manager with more information on multiple objects, it can organize to draw many in one swoop.  Imagine if you have 1000 bullet sprites on screen, you could have individual bullet draw itself or have the some render manager issue a single draw call to draw 1000 quads with the same texture at 1000 locations.  I hope that I interpret what you're asking correctly.

0

Share this post


Link to post
Share on other sites

First of in XNA you will want to inherit from GameComponent or DrawableComponent in C#.

 

Generally it is not a good idea to have a game object draw itself, it doesn't need to know any of that information, it can have a model object and that can know how to draw itself or generate a list of render commands to be drawn. I generally prefer the second method as it allows you to do some sorting and other optimisations in the render passes, like sort on material, shader, texture or even transparency, but also batching of vertex buffers that have same render settings. But also visibility querries and the like, early culling.

 

If using scenegraphs use a visitor pattern to collect all of the draw commands you need to pass on to the renderer.

 

In rendering you want to minimize the amount of state changes you need to do to be able to draw a complete scene to the screen, state changes are things like: switching texture, constant buffers, shaders, ibs and vbs, renderstates and rendertargets.

Edited by NightCreature83
0

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0