Looking for a pattern, objects registering to a manager
#1 Members - Reputation: 120
Posted 15 June 2012 - 05:18 PM
It started with my rendering system. I'm using a component based architecture, and naturally my GameObjects would possess renderable components, such as a sprite. In order to render these components in an appropriate order, I had made a renderer object which would sort the renderable components and call render() on them in order. So when I construct a given GameObject, and it will have a renderable component, I pass a renderer to the constructor which the renderable is then added to.
The rub is that I'd like to be able to clone my GameObject, so all my components have to be cloneable. I'd like any renderables that I clone to end up registered to the same renderer as the renderable they were cloned from. To do this, my renderables keep track of which renderers they've been added to, and when they clone themselves, they can add the cloned renderable to the appropriate renderers.
It seemed like a good way of doing it at first, but now I'm beginning to wonder. I've now got an Actor component that needs to be registered to a Time object that manages which Actor takes their turn next (it's a turn based game). By the same reasoning as used for the renderable, the Actor will have to keep track of which Time object it's been added to. But now I'm adding more code to the actor, just to allow it to keep track of which Time object it was added to, than I've got describing the functionality of the Actor.
I'm being tempted by singletons for these object managers, but they make me feel dirty. Has anyone encountered similar issues?
#2 Moderators - Reputation: 7525
Posted 15 June 2012 - 06:12 PM
[Work - ArenaNet] [Epoch Language] [Scribblings] [Journal - peek into my shattered mind]
#3 Members - Reputation: 878
Posted 17 June 2012 - 03:25 AM
Small and simple Python 3.x media library: pslab
#4 Moderators - Reputation: 7525
Posted 18 June 2012 - 08:11 AM
There's more than one renderer? That seems like a fundamental flaw in basic design.
Says who?
I've worked with systems with several renderers even within the framework of a single graphics API. Different things like UI, debug information, particle effects, and so on might all benefit from slightly different rendering paths.
[Work - ArenaNet] [Epoch Language] [Scribblings] [Journal - peek into my shattered mind]
#5 Members - Reputation: 121
Posted 18 June 2012 - 09:47 AM
I use something like that with Renderers. All my renderer objects inherit from a RendererBase and each rendereable class has a pointer to a RendererBase object. Take a look at dependency injection.
Edited by Juliano Schroeder, 18 June 2012 - 09:48 AM.
drawing, programming and game design.
#6 Members - Reputation: 568
Posted 18 June 2012 - 12:28 PM
#7 Members - Reputation: 169
Posted 18 June 2012 - 04:36 PM
also registering each item that need to be rendered into a list each frame shouldn't be a big performance hit (just profiling it now with my engine, registering to a list compared to time for a draw call is nothing, interesting is the tradeoff with mesh batchin in my case).
Renderer1->register(this); Renderer2->register(this); etc.
Edited by DemonRad, 18 June 2012 - 04:38 PM.
#8 Members - Reputation: 878
Posted 18 June 2012 - 05:04 PM
Says who?
Just me - I used the word "seems" because I'm not sure, and I wanted the OP to provide good reasons for using multiple renderers to draw game objects, because if there were no good reasons, the problem could be solved in a very elegant manner.
I've worked with systems with several renderers even within the framework of a single graphics API. Different things like UI, debug information, particle effects, and so on might all benefit from slightly different rendering paths.
But when we talk about "different things", isn't the fact that they're different reflected in the data that describes their visual appearance?
When I made my original statement, it was in the context of this particular case, and in that context, I think that a well designed material system would be considerably better than yet another renderer. For one, the OP wouldn't have to think about which game objects belong to which renderer, because there's only one (fairly elegant way to solve that particular problem, wouldn't you say?
I realize that things like UI or Particle systems are less general, and probably warrant a whole new path (in certain cases), but for game objects ... I just don't see the benefits.
Small and simple Python 3.x media library: pslab
#9 Moderators - Reputation: 7525
Posted 18 June 2012 - 06:31 PM
[Work - ArenaNet] [Epoch Language] [Scribblings] [Journal - peek into my shattered mind]






