Jump to content
  • Advertisement
Sign in to follow this  
CoyCash

game object structure

This topic is 4434 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my game engine I have a GameObj class, a Render class and a Draw class. There are 2 approaches I have been contemplating: 1. The Render class has a render() which loops through every GameObj, each calling their own draw() function which in turn checks its flags to call the appropriate draw() from class Draw. OR 2. The Render class has a render() which loops through every GameObj, looks at its flags, then selects and calls the proper draw() from class Draw. Basically the first one has a more vertical structure while the 2nd is more horizontal. Which one is more flexible (ie easier to maintain/change) or better in the long run?

Share this post


Link to post
Share on other sites
Advertisement
do number #2 because #1 will take more maintenance. #1 uses more abstraction and might be more robust when finished, but will be harder to test/debug/code.

Share this post


Link to post
Share on other sites
Use neither, and ignore neverever, at least on this subject.

Instead of either of those approaches, a GameObject (not a GameObj - avoid abbreviation) should HaveA Rendereable (or multiple Renderables). That Renderable should be put on a (possibly ordered) RenderableList. Any state changes that affect the GameObject's visible representation should then be communicated to the Renderable, so the only thing that's necessary to render the scene is to walk the RenderableList, asking each Renderable to Render() itself. The rendering side of things should not have any awareness whatsoever of GameObjects.

Tightly coupling your GameObject's logic and drawing sub-responsibilities together is bad design - separating things that don't need to be coupled makes for far better code. If you're writing Pong, that doesn't matter. If you're planning on writing something bigger, then the improved clarity of code you get from proper design ends up creating less debugging headaches, because you're less likely to get different parts of the code stepping on data that other parts of the code think is its responsibility.

Share this post


Link to post
Share on other sites
Quote:
Original post by JasonBlochowiak
Instead of either of those approaches, a GameObject (not a GameObj - avoid abbreviation) should HaveA Rendereable (or multiple Renderables). That Renderable should be put on a (possibly ordered) RenderableList. Any state changes that affect the GameObject's visible representation should then be communicated to the Renderable, so the only thing that's necessary to render the scene is to walk the RenderableList, asking each Renderable to Render() itself. The rendering side of things should not have any awareness whatsoever of GameObjects.


Interesting approach, but how do you manage things like occlusion? Is that done on the renderList?

Doesn't you have to have multiple copies of the position and rotation? If so, doesn't that slowdown?

Share this post


Link to post
Share on other sites
Quote:
Original post by eXt_
Interesting approach, but how do you manage things like occlusion? Is that done on the renderList?

Doesn't you have to have multiple copies of the position and rotation? If so, doesn't that slowdown?


You can keep the transformations in a repository and use references to them in multiple locations of the engine if needed.

Share this post


Link to post
Share on other sites
Quote:
Original post by eXt_
Quote:
Original post by JasonBlochowiak
Instead of either of those approaches, a GameObject (not a GameObj - avoid abbreviation) should HaveA Rendereable (or multiple Renderables). That Renderable should be put on a (possibly ordered) RenderableList. Any state changes that affect the GameObject's visible representation should then be communicated to the Renderable, so the only thing that's necessary to render the scene is to walk the RenderableList, asking each Renderable to Render() itself. The rendering side of things should not have any awareness whatsoever of GameObjects.


Interesting approach, but how do you manage things like occlusion? Is that done on the renderList?

Doesn't you have to have multiple copies of the position and rotation? If so, doesn't that slowdown?


Yes, any occlusion handling would be done by whatever is doing the renderlist traversal, or the renderables themselves (or, more likely, some collaboration). The major point is that issues related to rendering are in code that's specialized for rendering, and the game code is in, well, game related code.

You can have a scene graph that contains positional information that the game code can manipulate, and that the renderer can read from, without any duplication. I must say, though, that if copying something like a vector and a quaternion around is a major slowdown in your code, something has gone heinously wrong.

Share this post


Link to post
Share on other sites
Quote:
Original post by JasonBlochowiak
I must say, though, that if copying something like a vector and a quaternion around is a major slowdown in your code, something has gone heinously wrong.


Nah, not really, but if I handle 2000 objects/second thats 4000 copies/second so some time *would* be lost there. But I rather see it like this, if copying vectors is the slowdown the engine is fast =)

I'm definitely going to try this approach out, it might solve some other problems I have with game object inheritance.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!