Jump to content

  • Log In with Google      Sign In   
  • Create Account


Drawable entities and fast isometric depth sorting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Neurodoxx   Members   -  Reputation: 100

Like
0Likes
Like

Posted 08 March 2012 - 07:16 AM

Hello everyone,

Being new here, I'd like to introduce myself. Neurodoxx, french student in robotics, currently developing a C++/OpenGL isometric game engine.

My request is two-fold.

The engine I'm programming relies on a component based entity system to make sure a given entity only contains what it needs to carry out its duty. For instance, trigger entities won't need to display any sprite so they don't include the render component. It follows that some entities are not renderable. My engine is currently running a back to front painter's algorithm to display tiles on a map (hastily implemented as a multi-dimensional array to run tests quickly) and is unable to integrate displayable entities in the world. I came up with the idea (and I don't doubt that's a common way to do it) that my engine should deal with tiles and renderable entities the same way, which in OOP is easily done by deriving tiles and entities from the same -let's call it Drawable- interface. However, with my component-oriented design for the entity system I'm basically hitting a snag.
It appears to me that tiles should be implemented as entities at the cost of a relatively small overhead, yet I can't find an elegant way to iterate only over drawable entities in my render function. Should I split drawable and non-drawable entities into two different lists ?
I've been travelling all over the web to find a smart solution to address this issue but came up with no clue which might indicate I'm not following a good path, I fear, and as a result I can't sleep.

This problem apart, I know that some day I will need to perform depth-sorting over my list of displayable objects so as to draw them in the right order. This, in theory, I can deal with as I've seen many tutorials on how to do it efficiently. But can I, and if yes, how should I sort it in order to render exclusively objects located under the viewport ?

Thanks in advance for your feedback, and if you need code to make this less abstract, I can provide !
Have a good day !

Attached Thumbnails

  • ErwinEngine.jpg


Sponsor:

#2 JTippetts   Moderators   -  Reputation: 8209

Like
1Likes
Like

Posted 08 March 2012 - 08:31 AM

In my game, any entity that is to be drawn is given a renderable component of some type, be it static or animated. Rendering is handled by a Scene structure that implements the map with the tiles and the animated objects. A renderable component will create an animated object or static tile and place it in the map, and will listen for movement commands from the parent object. Any object that is not to be rendered is not given a renderable component, and thus is simply never considered for rendering.

The map is implemented as an array of buckets, where each bucket holds a list of SceneEntity. SceneEntity is currently either a StaticSceneEntity (something that is only a static image or tile, such as a ground tile, a tree/bush/rock, etc...), an AnimatedEntity (contains an animation set, which includes all animations in all facing directions the entity needs) or a TextSceneEntity (for over-the-head floating text). The map is iterated based on the current view or camera, and a render list is constructed that is sorted from back to front based on the RenderLayer of the entity as well as the back-to-front sorting. This way, I can implement underlay/overlay effects, blob shadows, and so forth by using RenderLayer to control ordering. Once the master list is constructed, it is iterated to draw the objects.

Every frame, the Scene is rendered. Now, in order for a game object to be drawn it needs a renderable component. Objects are implemented as basically a bucket of components. (You can read a bit about how my system works here). So if I want to create a static object such as a rock, I would do:

obj=createObject()
obj:addComponent(StaticSceneEntityComponent("rock.tga"))
obj:handleMessage("SetObjectLogicalPosition", {x=20, y=0, z=35})


Simple as that. If I leave out the step of adding a StaticSceneEntityComponent, then no entry for the rock is made into the Scene structure, so nothing is drawn for it.

#3 jrdmellow   Members   -  Reputation: 118

Like
0Likes
Like

Posted 08 March 2012 - 12:05 PM

Following up on JTippetts' comment, the 'bucket' approach definitely sounds like what you want, implementation though is entirely up to you.

Personally, I have a 'bucket' for every type of Component in my engine. There's a static bucket for each Component type which objects with the appropriate ID get added to when loaded into a scene (and removed when unloaded).

A little management at load time greatly reduces the iteration time for draws, just keep the bucket sorted at all times (put the object at the appropriate position at insert instead of sorting later). Then all you have to do is iterate over the bucket when it comes time to render.
Jordan M. www.jordanmellow.com

#4 Wyrframe   Members   -  Reputation: 730

Like
0Likes
Like

Posted 08 March 2012 - 03:43 PM

I don't know how efficient it actually is, as of yet, but I use a bucketing system to sort my draw calls, based largely on this article.

http://realtimecollisiondetection.net/blog/?p=86

Opaque batches are sorted based on shader and texture parameters, and loosely sorted based on depth, from nearest to furthest to take advantage of depth-buffer early fragment exclusion. Translucent batches are after all opaque ones, and sorted from furthest to nearest on stricter and more accurate basis, since sorting imprecision here will be visible, instead of merely inefficient.

Mind you, using bucketing is entirely separate from using a component-based scene architecture.

(( This email has been quad-ROT13 encrypted. Reading it violates the DMCA. ))
(( 我说很少的汉语,还我的语法平庸, but at least I'm UNICODE-compliant. ))


#5 Neurodoxx   Members   -  Reputation: 100

Like
0Likes
Like

Posted 09 March 2012 - 01:51 PM

Thanks a lot all three of you, I think I have what I need ! I'll let you know when I get the job done.

By the way,

JTippetts, your system is impressive ! I get it now, but I came upon one of your articles several months ago (maybe some video on youtube too), I was just starting the architecture for my engine and this gave me some directions to follow. Good work !






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS