I'm just wondering what the best practice is with chunked terrains and component entity systems. Should each chunk be an entity in itself? Or should the whole terrain be an entity?

I'm trying to streamline and refactor my rendering process, and indeed, design parts of it that haven't been done yet. I have a sandbox project that doesn't use my new architecture and it has my terrain system in it, which is honed and extremely efficient. Porting it to my new game engine is throwing up lots of design decisions. My rendering engine essentially works sequentially through a vector of render 'tokens' which allow me to sort it on various criteria. My main question is "should" my terrain parts (i.e. chunks) be just another render token in the list or should I contain my specialised terrain rendering code in its own render method.

It feels wrong to keep it in its own method, but its quadtree and relational nature doesn't really lend itself to a linear list of completely unrelated render tokens. My set up is essentially like this at the moment:

Entity (contains standard orientation data)

---> RenderableComponent (there is a link to this object in each 'RenderToken' which just holds the sortable key, the material and link)

My entity system doesn't really have 'systems' that control the entities/components, rather the functionality exists within the components. This was an early design decision that I quite like but it's easily changable.

So how would you go about moving a quadtree-based terrain system into this architecture? Keep it a self-contained terrain system or integrate it into the pipeline properly?

My main question is "should" my terrain parts (i.e. chunks) be just another render token in the list or should I contain my specialised terrain rendering code in its own render method.

my chunks are basically memory images of my renderables list (my drawlist of Zdrawinfos) for a single chunk, ready to draw. but i use separate dedicated code to do it.

in your token system, the equivalent would be breaking a chunk into its tokens in a dedicated list, and strong the chunk that way. then having dedicated code just to draw that.

however it appears you want to treat a chunk as a single renderable. my chunks consist of 1 ground mesh per texture, plus all the plants, rocks, and water in the chunk. obviously more than one renderable. a complex chunk can have 4000+ renderables.

my layout happened by accident. the current drawlist data structure was originally invented for the chunk system. its worked so well, the drawlist was changed to use it. thus the two dedicated drawing routines. it could probably be done as one routine.

treating a chunk as just another token is the clean way to do it. everything is just a token, one token drawer. job done. gimme a beer! <g>.

My main question is "should" my terrain parts (i.e. chunks) be just another render token in the list or should I contain my specialised terrain rendering code in its own render method.

my chunks are basically memory images of my renderables list (my drawlist of Zdrawinfos) for a single chunk, ready to draw. but i use separate dedicated code to do it. in your token system, the equivalent would be breaking a chunk into its tokens in a dedicated list, and strong the chunk that way. then having dedicated code just to draw that. however it appears you want to treat a chunk as a single renderable. my chunks consist of 1 ground mesh per texture, plus all the plants, rocks, and water in the chunk. obviously more than one renderable. a complex chunk can have 4000+ renderables. my layout happened by accident. the current drawlist data structure was originally invented for the chunk system. its worked so well, the drawlist was changed to use it. thus the two dedicated drawing routines. it could probably be done as one routine. treating a chunk as just another token is the clean way to do it. everything is just a token, one token drawer. job done. gimme a beer! <g>.

Well after a whole day of refactoring yesterday, my terrain chunks are now just normal render tokens. My ground chunks don't have anything else associated with them (foliage, trees, etc), but that's not to say they won't at some point ( in some spatial form). There won't be any special links between eye candy and the terrain where the renderer is concerned though, it just takes a token and renders it, all the ordering is done before that. This feels like a nice system.

My terrain works in blended layers for texturing so if a chunk (32x32) has x number of textures on it, that's x draw calls - I didn't want to be restricted by passing all of my textures in one draw call especially as I have normal, specular, bump, etc too. So each terrain layer is also a token now and they are sorted to be drawn after the base terrain detail and blended on top. I blend out the detail texture layers at a very short distance (40m or so) so you only ever end up drawing layers on one or two chunks keeping the draw count down nicely - the overall surface texture (which covers 512x512 of the terrain) blends in beautifully - think Crysis,

It's really interesting to hear all your views. Norm, do you have any demos/screenshots of your engine in action?

OTOH, rendering a scene is usually easier accomplished in stages, rater than just stuffing everything in one big list and going for it.

even with my drawlist, i actually clear, populate, and draw it 3 or 4 time each frame. only then do i draw the ground - with a separate but almost identical routine.

so from that point of view, it would be nice to be able to draw the ground separately, before or after other things in the scene.

Even though everything is in one big list, the list is keyed on a sort code which can contain any criteria you like, so if I 'or' in a numerical hash of 'TerrainPatch' for instance, all terrain patches will be batched together, this makes perfect sense as they all use the same shader.

So it's both generic and flexible. I've even pushed my post processing filters onto the renderqueue. Their mesh being just a full screen quad and the RenderableComponent having some specialised shader setup code (for passing results of previous renders, etc). I know with this type of development (if not, all) if something doesn't feel right, it probably isn't and this does feel very right (for once!). I'm on my 4th engine now so hopefully I'm starting to get things right. Getting some game logic in there too now, so it's coming together nicely.

I'm on my 4th engine now so hopefully I'm starting to get things right. Getting some game logic in there too now, so it's coming together nicely.

sounds like we're working the same issues. but you're doing a full engine / game, while i'm playing with a testbed just to implement different architectures and code organization. the testbed program is yet another app of mine, and it's not yet up in my gallery. but already you can move around and shoot stuff, with about 200 lines of user code. implementing the user collision handler in the demo program is next. right now its just displays a message saying "target x collided with (whatever)" for testing purposes. the nice thing about the testbed is you can try things quickly. I've done 4 engine designs in the last 2 weeks with it.

now i need to figure out the best way to implement an optional ground drawing routine. i already have both chunk and dynamic mesh technology working. but i need to figure out what's best for all types of ground: shooters, flight sims, RTS, etc. one ground drawing routine to rule them all.

any suggestions?

i've got about 6 titles on my short todo list (beyond CAVEMAN, AIrships!, Armies of Steel II, and CIty States) , so i'm trying to get my library / boilerplate code / engine whipped into shape so i can use it for all of them. but the REAL problem is content. all those models required. as coders, we can use libraries, engines, and good old copy / paste / edit to get the coding done quickly. but i see no speedups for the typical week+ required for a fully rigged and animated character model with matching equipment.

other types of models also take time to create. until there's a good supply of ready to go content available free/cheap, it will be a barrier to those without artists on the team or deep pockets.