5
\$\begingroup\$

I viewed sources of rendering engines (ogre, irrlicht, openscenegraph) but I can't really grasp the main ideas of their scene management systems.

I also read many articles (including Game Engine Architecture's "The Rendering Engine" part) but they all talk in abstract manners and never explain which classes are responsible to what etc. What should the SceneManager class do? SceneGraph too. Where do I store the caches (of Meshes, Textures etc) and what classes should "see" them?

How exactly should I manage the scene? I want to know everything starting from a simple Node design to the render_frame() function. If you have a good article on the subject that would be great.

I know I'm asking broad questions, but this is my last resort. I haven't found any good source for these.

Edit: here are some specific questions:

  1. What is the task of the scene manager?
  2. What is the task of the scene graph?
  3. Where do I store all the caches, so that the user will be able to insert and query resources?
\$\endgroup\$
  • 4
    \$\begingroup\$ You've got many questions here. It's going to get put on hold for being too broad. Try breaking it into multiple, more specific questions and link them together. I'm sure folks will be able to help you but one answer will be much too long to answer all your inquiries. I'll say this: at it's basic a scene graph is just a tree structure where all objects are parented to some node in the tree, usually such that the entire graph has a single parent object. Don't get hung up on all the implementation details because there is no specific recipe. It's a concept. \$\endgroup\$ – Fuzzy Logic Aug 25 '15 at 15:33
  • \$\begingroup\$ I edited my post. Can you answer the questions? \$\endgroup\$ – Pilpel Aug 29 '15 at 13:20
9
\$\begingroup\$

It is difficult to answer these questions with much clarity because they are conceptual and the concept applied to each of these could be widely different depending on the engine and needs of any particular game. So I'm going to try to be fairly general.


1. Scene Manager

The scene manager keeps track of the scenes in a game, allowing to switch between them. At it's basic, it provides a centralized place to load and unload the scenes, keeping track of which one is loaded and handle unloading that scene when a new one is loaded.

See here for a basic example of a SceneManager.

It can get quite a bit more complicated, depending on the engine/game but primarily, its job is to provide a place to manage all the scenes so that each scene doesn't need to be uniquely referenced in the game code. Instead of the game having to deal with 10 or 20 (or 100) different scenes all over the code for example, by using a SceneManager and assigning all the scenes to it the game code can refer to the SceneManager and never need to know about any particular scene, how many scenes there are or if one is added/removed. In this way, to the rest of the code the number of scenes and specific names of the scenes does not need to matter.

This is a rather generic description. Some games or engines may use the scene manager a bit differently but the general concept will still apply. Usually the difference will come down to how a scene is defined. In most engines a scene is an entire level. In others a scene might be a subset of a level. In yet others, there may be no concept of a scene and instead they use screens but the same idea would still apply.

Really, this is just a software design pattern. In other areas of software development, we might call this a Facade or Mediator design pattern.



2. Scene Graph

I'm not going to get into explaining all the details of what a scene graph is since I think that this article does a better job of explaining it than I could and this answer would be too long otherwise. I will summarize though.

A scene graph is essentially a hierarchy of all the objects in a scene with parent-child relationships, such that manipulating one parent will implicitly affect the children. This is useful so that if you have a large number of objects, you can make one change to a node in a scene graph and that change will implicitly affect all the children of that node.

There are two key things that the scene graph helps with:

  • spatial relationships
  • behaviour relationships

The gamedev article I linked above uses a good example of a solar system to demonstrate how a scene graph is beneficial. Another example might be a squadron of ships, where they all act independently but also behave as a group, like a flock of birds.



3. Where to Store Caches

This is very subjective. You might have a ResourceManager to handle these things for your engine. You might have a manager for each type of resource or you might have both, where the ResourceManager coordinates all of the specific managers for each resource type. How much you need to break it down depends on the complexity of your game engine. Stick to the KISS principle and modify your design as you find that things are getting too messy and unmanageable.



Note: I'm no expert on these engine specifics. I'd rather leave these types of details to someone else to provide for me so I can focus on building games instead of implementing an engine that is likely going to be inferior to one that others have already spent a lot of time and effort to get right. I've learned enough to know why and how but explaining it is a little beyond my experience. Hopefully I'm not sharing incorrect information or missing any important details.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the answer. So basically, my "engine" can have its own abstract Scene class (consisting of generic functions like load(), draw() etc.), and then it lets the user create classes that inherit from that class (e.g MainScene, MenuScene etc) and then insert them to the SceneManager. Is that a legit approach? \$\endgroup\$ – Pilpel Aug 30 '15 at 16:29
  • 1
    \$\begingroup\$ Right. Then the SceneManager can call on the methods like Load()/Unload(), GetName(), etc to be able to do its management. \$\endgroup\$ – Fuzzy Logic Aug 30 '15 at 16:36
  • \$\begingroup\$ Okay thanks man. marked as answer. Do you have more references to articles on these subjects? \$\endgroup\$ – Pilpel Aug 30 '15 at 16:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.