Quote:Original post by Kylotan
Quote:Original post by JasonBlochowiak
Erm, I'd say that's exactly backwards. You want to push responsibility out of main classes/functions and closer to the leaf classes. That's pretty much the point of encapsulation - everything knows how to do its own thing, rather than requiring central classes to know how to do everything.
I don't agree. I don't think rendering code should be scattered across all your objects. Instead I think it should be centralised in one class. It's a matter of personal preference though.
Hmm, in re-reading what I posted, I don't think it quite reads like I meant it to, and there's probably more agreement here than we initially thought.
What I meant to get across is:
1) Central game management classes shouldn't have knowledge about the specifics of individual game components.
2) Responsibility should be pushed as far away from central classes as makes sense. So, my game class shouldn't know the details of how to draw any of the game elements. The game elements shouldn't know the details of how they get rendered, but they should know how to specify (at a fairly abstract level) how they want to appear. Game specific render components know how to translate the game objects' appearance requests into a combination of requests to base render objects. The base render objects know the specifics of the rendering API they're using, such as DirectX or OpenGL.
Heh, I wrote this before reading superpig's post. Although his and my terminology differ some, we're pretty much saying the same thing. I completely agree that game objects shouldn't contain the details of their subcomponents - they should aggregate the subcomponents as self-contained units, and make requests of those subcomponents.
For what it's worth (and especially for anyone wondering if this is viable In The Real World), this approach has shipped SKUs on a high-performance, cross-platform engine, including targeting systems with weak CPU performance, and multiple core rendering APIs (custom PS2 API, DX on XBox, and the GL-ish API on GameCube).