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

Scene Graph Root Node

9 posts in this topic

Hi,
When a scene graph is implemented, the most of time there is a root node.
Is the root node really needed ?
Is it bad to have an array of node with parent to NULL who store children array pointer ?

Thanks Edited by Alundra
0

Share this post


Link to post
Share on other sites
The good of a root node is you can apply any algorithm on a node to the root, you can not do it for an array.
For example, assume you have a function to find a special child node, you can call it on the root.
0

Share this post


Link to post
Share on other sites
[quote name='Alundra' timestamp='1354982128' post='5008510']

Is it bad to have an array of node with parent to NULL who store children array pointer ?

[/quote]

how is this different from having a root node that, incidentally, already has an array to children nodes?

anyway.. ya,it can be done if you really like duplicating code and functionality around for no good reason whatsoever.
Edited by kunos
2

Share this post


Link to post
Share on other sites
The difference is merely a conceptual issue... the only difference is that your application would be the "root", instead of having a well defined struct/class..

programatically there would be no difference, but it's cleaner and more intuitive for other programmers to have a root node from which everything "spawns"...

most of the time you will have to take desisions between two options which both work ok (and there's no performance gain/loss between them), but with the question of which way would you leave a be better experience to the people who might be using your code.. ;)
0

Share this post


Link to post
Share on other sites
This depends on what kind of behaviour you want to get out of your scene graph.
In a lot of cases where a hierarchical scene system is implemented the word 'graph' is actually a misnomer, as most of those implementations are tree structures (since it doesn't really make sense in most cases to have cycles in a scene graph unless you're doing some really funky stuff), and to build a tree structure you need a root node.

Of course you could store multiple trees, which is basically what you're presenting. If you store parentless nodes with children in an array you're basically building a forest, and each of these nodes will become roots for their own trees in that forest.
So if you want your scene to be divided into different independent trees, then it isn't necessarily 'bad' to store your different tree roots in an array like you said.

However, the fact that you're trying to do something like this should trigger an alarm-bell. You're trying to 'break the rules' of your chosen data structure to get some kind of different behaviour, which basically tells me that the data structure you've initially chosen (being a scene tree) isn't a good choice for the problem you're trying to solve.

Is there any reason why you need hierarchy within your scene as a default rule, rather than as an exceptional case?
I think a lot of people on these forums will agree with me that the concept of using just a scene tree/graph is starting to get outdated, as the concept of having a hierarchy between objects just plain doesn't make sense in a lot of cases.

Different systems will need different representations of your scene, a physics engine might need to have some sort of partitioned scene structure containing shape and transformation data so it can optimize its collision detection algorithms, while a rendering engine just needs a list of visual data and transformations to crunch. Culling algorithms might need another partitioned structure containing bounding volumes, which again is completely different from what the rendering and physics engine need.
I could go on like this for a while, but I think my point should be somewhat clear by now.

Basically what I'm trying to say is that it doesn't take all too long for the "stick it all in a tree" approach to start breaking down, so if you're at the point where you're trying to somewhat break free from this approach you should maybe try to rethink how you want to handle your scene entirely instead of trying to bend and twist your current approach in ways it wasn't designed for.
0

Share this post


Link to post
Share on other sites
It's a conceptual difference, but there's also subtle but important details:

1. A node that is not part of the root node (an orphan node) is not in the scene and hence should not be rendered (this is important when Parent nodes don't own the memory of their children, but rather just have a pointer to it).


2. [b]Consistency[/b]. If you create a new node you should call sceneGraph->createNode( pos, rot )->attachObject( myObj );
But if you're creating a child, you should call parent->createChildNode()->attachObject( myObj );
or call parent->addChild( myChild ); after creating it with sceneGraph::createNode (two ways of doing the same, and in both ways the code for creating a child is different from creating a parent-less node)

However, if there is a root node, [b]your code is always the same[/b]:
parent->createChildNode()->attachObject( myObj );

Just feed the proper parent (which could be the root node) and you get a consistent behavior.


3. Many implementations are tree-based, like Radikalizm said. And trees start with a root node.

Having this said, you're not forced to have one root node. But I'm just answering your question (why so many implementations start from a root node). It's not bad to have an array of objects like you said. Particularly, I think reason #2 is a very good reason to use a root node for writing clean code. Reason #1 is just a convention & conceptual. Reason #3 depends on the implementation, it also depends on the literature being consulted (Which is often about having a root node, because the problem to solve is abstract, not specific towards graphics & scene management).

Cheers
Dark Sylinc
1

Share this post


Link to post
Share on other sites
Using a tree, recursive function is used to render the scene and find an object by name.
Is it bad to use recursive function for these operations ?

Thanks
0

Share this post


Link to post
Share on other sites
[quote name='Alundra' timestamp='1355010873' post='5008637']
Using a tree, recursive function is used to render the scene and find an object by name.
Is it bad to use recursive function for these operations ?

Thanks
[/quote]
Trees lend themselves well to recursive algorithms, which makes implementation easier, however going recursive has a few disadvantages:
- it is often a bit slower than an iterative algorithm where you maintain your own stack
- because it is stack-based, it may not be easily implemented on platforms where a stack isn't readily available (e.g. GPU's)

On the other hand, non-recursive approaches can be a real pain to get right.
2

Share this post


Link to post
Share on other sites
in my case, I have implemented dynamic scene with world register, a tree. If you have all root node, you can implement special exeptional logic to it, for example, if you scan register as what nodes to remove from game scene based on distance, you will not examine the root, for if player get distant from root too much, it would have to disappear and remove whole subtree (everything). You should take care as what you implement , but I would advice you to use unique root, for you can get catching your hair if you implement multiple nodes, as you develop aplication further, but I cannot think of how you could get screwed if you implement an all root.
0

Share this post


Link to post
Share on other sites
That's the start of a "b-tree". You still have a root-node, it's just an array instead of one node.
If you make all your nodes arrays then it's a b-tree.
For many applications b-trees are a superior design. They offer the recursive power of trees and the cache-coherency of arrays. Edited by Shannon Barber
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