Object culling curiosities. Opinions, guys?

BlitzMax Forums/BlitzMax Programming/Object culling curiosities. Opinions, guys?

Dubious Drewski(Posted 2006) [#1]
Say I have a bunch of objects scattered around a map. This is a tile-based, scrollable,
zoomable map. I want objects in the camera's view to be drawn and objects off the screen
to be ignored, naturally. (Objects are z-sorted, then drawn on top of the tiles in a seperate loop.)

How would you guys go about this?

I can think of 2 methods offhand.

1. Cycle through each object on the map and use an If-statement to check if it's
visible. (Very amature, and with thousands of objects, it's very slow)

2. Attach each object to a ground tile, so that the same code that draws the ground tiles
automatically knows when to draw in any visible objects. (Used with good results in the
past. It's limited though, you don't have the freedom to bunch too many objects together,
and the object cannot stray too far from its home tile, or else it disappears along with the
tile before it's off the edge of the map.)

What methods do you guys use?


GfK(Posted 2006) [#2]
Ignore me - thought I was in the BB3D forum :D


Dubious Drewski(Posted 2006) [#3]
I forgive you.


tonyg(Posted 2006) [#4]
Can't each tile have a list of objects currently associated to it rather than a single object?
Depending on how many objects are involved drawing 1-2 that are just off-screen shouldn't matter.


Dubious Drewski(Posted 2006) [#5]
Yeah, I can do that too. So are you saying you favour the "hometile" system, and that it's my best option?

I'm sure the pros have some crazy, high-level methods of object culling. I'd like to be blown
away trying to read one of those algorithms! That's kind of what I'm after in this thread.


tonyg(Posted 2006) [#6]
I think they go with what works rather than anything clever. Don't think of it as a hometile system but more a wau of abstracting x/y coordinates into something more vague just to find out if the object is on-screen. The 'tile' they belong to doesn't really have to be the same size as your graphical tile. e.g. Tilesize 32*32, object 'holder' 128*128. You only want to know if the object is in a tile that's on-screen then you can draw it with it's own x/y.


Dubious Drewski(Posted 2006) [#7]
But isn't a clever solution always best way to do it? To me, "clever" implies efficiency
and versatility. I could use some of that. The hometile system I've been working on
for forever now allows drag-n-drop placement and it runs very efficiently. But I'm not
dellusioned. I know there are games out there running systems that are 10x more
efficient and versatile! I have much to learn! .. right?

But anyway, what you said about abstracting it and making it independant of the visual
terrain tiles sounds like a good idea.


tonyg(Posted 2006) [#8]
The idea is get it working and check the results. If it does what you want, in the time that you want then it's a result and clever enough. If not, you can then optimise or have a rethink.