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

Game engine architecture

15 posts in this topic

I want to start implementing a game engine, but I don't have a clear understanding of how it should be designed. I've read much on the topic and it would seem the best way should be creating standalone generic components that are then used to create various objects. Would it look something like this? 

class CMaterial
{
// texture, diffuse color...
};
class CMesh
{
CMaterial mMaterial;
vertex buffer
index buffer
// each mesh has exactly 1 material when using assimp (I think)
};
class CModel
{
constant buffer per model
std::vector<CMesh>mMeshes;
};

Then one would create a generic model for a humanoid:

class CHumanoid
{
CModel mModel;
CPhysics mPhysics;
CInputHandler mInputHandler;
};

Which would include draw,create and destroy functions.

 

You see, I'm not sure how I could implement the different components that I could use to make up some sort of a complete structure, such as a human (it needs to be rendered, physics needs to have effect on it, it need to be able to move, wield weapons ...).

 

Then it would need to have a rendering class that uses dx11 to draw it, would I make this a static/global class or what?

 

I'm very lost here as to how one should create a game engine from generic components that handle themselves and are as decoupled as possible.

0

Share this post


Link to post
Share on other sites

Thanks for the answers, I am quite patient and fine with taking it slow. I want to do things right from the start so when the project grows, adding new features would be as clean and simple as possible. Currently though, I dont even know how would I begin implementing a graphics engine, do I create a wrapper around dx11 to ensure I dont make any unnecessary calls (like setting a state that is already set)? Where would I begin? That is, I am not sure what are the bare minimum things Id need to implement for a graphics engine.

Edited by eee
0

Share this post


Link to post
Share on other sites

Since Im considering using assimp, if i understood it correctly then: a model is a car, the car is broken up into meshes (each bodypanel, if theyre different, windows of the glass) where each mesh has a different material (that includes a texture, diff color, blending states etc). Quote from the official page: "Each aiMesh refers to one material by its index in the array." and "A mesh represents a geometry or model with a single material." If there are better alternatives to assimp, please point me in the right direction. I have tried implementing an .obj loader but it was very slow :(.

 

I have never written a wrapper, so would this be the way:

pseudocode:

 

class CDirectX11States

{

void SetInputLayout(ID3D11InputLayout* inputLayout){
if (mCurrentInputLayout != inputLayout){
mCurrentInputLayout = inputLayout;
mDevCon->IASetInputLayout(inputLayout);
}
ID3D11InputLayout* mCurrentInputLayout;

};

class CDirectX11

{

 

device

devicecontext

swapchain

etc

};

 

Thanks for everyones patience!

0

Share this post


Link to post
Share on other sites
I like how unity handled mesh and material binding. Meshes don't carry material information. They just specify a slots for how many materials the mesh supports. There is a seperate class called a MeshRenderer that would take a mesh and an array of materials as input to render the geometry. This way, it is easy to specify an object with the same geometric shape, but with different materials.

EDIT: Thought of another piece of advice

do I create a wrapper around dx11 to ensure I dont make any unnecessary calls


Another reason to make a wrapper is to allow you to change graphics APIs. Your wrapper can supply a consistent interface to your graphics engine, but different sub classes of the wrapper can implement OpenGL, Mantle, DX12, Metal, or even game console graphics APIs. Edited by HappyCoder
0

Share this post


Link to post
Share on other sites

 

If Assimp says that the red, green, and blue are 3 different meshes, it’s wrong.
If it says there are 2 meshes but a mesh can have only 1 material, it’s wrong.

I have never used Assimp and don’t know its limitations, but if it says a mesh can have only 1 material then that sounds like a pretty bad limitation.
 

 

I have used assimp for my loader and I also have a similar approach to L.Spiro in the fact that I have Mesh and Submesh classes where only the Submesh part holds the rendering data. 

 

It is purely the naming differences that make things confusing. an assimp aiScene is analogous to a Mesh, and the aiMesh is essentially the Submesh. There are a few other things to work around but as a whole assimp is great for model loading and I wouldn't use anything else at the moment. 

0

Share this post


Link to post
Share on other sites

 

"A mesh represents a geometry or model with a single material."

While it is true that below the level of a “mesh” there are no common or official terms, a single mesh can definitely have more than 1 material and render call.
I outlined this on my site, where I referred to the sub-mesh level as “render part” for lack of a better term at the time (since then I have found “sub-mesh” to be better).
LSModelBreakdown1.png

In such a simple case as this you could possibly draw the red and green parts in one draw call (though it would be non-trivial in any generic sense), but the fact is that the red and green areas are 2 different materials on the same mesh and it is meant to illustrate that in a more advanced case you will have no choice but to draw the red, switch materials and shaders, and then draw the green.
 
If Assimp says that the red, green, and blue are 3 different meshes, it’s wrong.
If it says there are 2 meshes but a mesh can have only 1 material, it’s wrong.

I have never used Assimp and don’t know its limitations, but if it says a mesh can have only 1 material then that sounds like a pretty bad limitation.
 
 

would this be the way:

Yes, but that’s the active way.
A better way is the last-minute way.
Basic Graphics Implementation


L. Spiro

 

I read your site and liked it, however I couldn't fully understand how to implement what you call the last-minute way. For example, I don't understand what CStd::Min( LSG_MAX_TEXTURE_UNITS, CFndBase::m_mMetrics.ui32MaxTexSlot ); does. 

 

Am I right in understanding you have two arrays :  an array of last active states (for example m_psrvLastActiveTextures[i] ) and the ones that are active at the time of the render call (for example m_psrvActiveTextures[i])?

And then you set the last active to the current one if they are not already equal?

 

I am still fuzzy on the details, though, it seems similar to the active way because you are swapping a current sate and a last one? Whats the difference?

 

Thanks!

0

Share this post


Link to post
Share on other sites

In order to create a model system, I need to choose a file format I am going to primarily support. I couldn't find too much information on which ones are used in the game industry, but it would seem .fbx is a good choice? Would it be possible to export models as compiled vertex and index buffers and then load them into the engines buffers? That would be very fast and efficient and it would make loading quite simple on the engine side (albeit not the exporter side, fbx is quite undocumented and I don't know where to start). 

 

What should my hierarchy look like?

 

CModel

{

std::vector<CMesh*>mMeshes;

XMFLOAT3 mPos;

// what else?

};

CMesh

{

std::vector<CSubMesh*>mSubMeshes;

// what else?

};

CSubMesh

{

CMaterial* mMaterial;

vbuffer

ibuffer

pshader

vshader

// what else?

};

 

Thank you !

0

Share this post


Link to post
Share on other sites

I couldn't find too much information on which ones are used in the game industry, but it would seem .fbx is a good choice?

 

Most engines use custom formats to store and load meshes at runtime. FBX is an interchange file format not optimized for runtime loading. Try to create a (binary) format specific to the needs of your engine that makes loading ultra fast, something like: <N><array of N vertices><...>, so when you load the model you can simply read the number of vertices and memcpy N*sizeof(Vertex) directly to the correct place (eg: graphics API vertex buffer).

 

My engine uses an hierarchy like this:

Actor
{
    Model
    Position
    Actor specific constants
}

Model
{
    Mesh
    vector<Subset>
}

Mesh
{
    Vertex Buffer
    Index Buffer
}

Subset
{
    Start index
    Number of indices
    Material
}

Material
{
    Textures
    Shader
    Other data
}

This way you can have multiple Actors at different positions using the same model, and multiple models using the same mesh but with different materials, etc

Edited by TiagoCosta
0

Share this post


Link to post
Share on other sites

Assimp does not limit 1 material per mesh - very roughly speaking what Assimp calls a Scene is what LSpiro is referring to as a mesh, and what Assimp calls a Mesh is what LSpiro is calling a Subset

 

Assimp loads the "Scene" as an array of "Meshes" which each have an index in to the array of Materials for the scene

 

This translates, in my engine, as a Mesh which contains an array of Submeshes, each with integer handles to the material.. Each Submesh can refer to only 1 material.. Each Material then contains an integer handle to the Shader responsible for drawing the material

 

When using components, don't call your resources components - anything that you have to load could be considered a resource - textures, meshes, animations, audio clips, shaders, etc

You only want to load these things once - and either pass around handles or pointers to these within the engine

 

IE if you want to have a Render component, it should contain a pointer or handle to a mesh rather than the mesh itself

1

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