lundi 28 novembre 2016

Game engine structure OOP

I am currently working on a small engine in C++. I reached a stalemate in the OOP structure of my project and I am not sure if this schema I would like to use is right or not. I would like to know if this approach is good in terms of a clean OOP design or what is a mistake in my case. The reason I am asking is that I found some sources of potential include conflicts and circular dependencies.

This is how it looks like:

Scene - Finds out what objects to load, stores them, on update calls physics etc to update the object positions

AssetManager - Does the loading of textures, models,...

Renderer - Displays the data, OpenGL in this case but I want to keep it alone like this since I would love to make for example a Vulkan version later

Object - stores basic data about objects

Schema (assume that the arrows are dependencies):

Scene ---creates the objects and stores them---> Object
Scene ---tells what to load---> AssetManager 
Object ---keeps what assets are assigned to it---> AssetManager
Scene ---tells which assets to prepare to render---> Renderer
Renderer ---needs to ask for the asset data---> AssetManager

What bothers me is the need of communication like: AssetManager<-Scene->Renderer->AssetManager<-Renderer

Simplified code:

class Scene
{
  objects
  loadScene(assetManagerPointer, rendererPointer)
}
class Object
{
  someInfo
  assetPointer
  drawObject //needs the call from renderer
}
class Renderer
{
  preparedModels //needs the asset to know which data to use 
}

Thanks.

Aucun commentaire:

Enregistrer un commentaire