Quadtree Spatial Indexing Demo

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
dreadkillz
Party member
Posts: 223
Joined: Sun Mar 04, 2012 2:04 pm
Location: USA

Quadtree Spatial Indexing Demo

Post by dreadkillz »

Hi everyone. I find love2d really cool! ^^ I got interested in spatial indexing and decided to try my hand on quadtrees. I tried to base it on this link: http://www.kyleschouviller.com/wsuxna/q ... -included/

I've attached a demo showing what it looks like. You can left mouse click on a circle to retrieve it's collidable objects. The collidables are in green and the circle you clicked is in blue. Circle's that collide with each other turn red. Nodes with objects are also drawn. I think it's pretty cool.
Attachments
quadtreeDemo.love
(2.93 KiB) Downloaded 482 times
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Quadtree Spatial Indexing Demo

Post by Inny »

Neat. Out of curiosity, have you checked how fast memory grows with this? print the output of collectgarbage("count") to check this, though, remember that lua's strings grow memory usage as well so only check it like once a second so it doesn't make your memory usage explode out of control.
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Re: Quadtree Spatial Indexing Demo

Post by Lap »

Clean and clear visualization. Well done. This would be a great addition to the wiki.
User avatar
kraftman
Party member
Posts: 277
Joined: Sat May 14, 2011 10:18 am

Re: Quadtree Spatial Indexing Demo

Post by kraftman »

nice, I did something similar recently with spatial hashing but not quadtree:
Balls and Walls.love
(1.6 KiB) Downloaded 415 times
Click to increase ball number, arrow keys up and down for grid density
User avatar
dreadkillz
Party member
Posts: 223
Joined: Sun Mar 04, 2012 2:04 pm
Location: USA

Re: Quadtree Spatial Indexing Demo

Post by dreadkillz »

kraftman wrote:nice, I did something similar recently with spatial hashing but not quadtree:

Click to increase ball number, arrow keys up and down for grid density
Very cool. ^^ My quadtree is not very optimized with large numbers of balls, but I just wanted to show it as a proof of concept in lua.
User avatar
Codex
Party member
Posts: 106
Joined: Tue Mar 06, 2012 6:49 am

Re: Quadtree Spatial Indexing Demo

Post by Codex »

Thanks for the resources guys! I'm definitely going to try and add this to the game I'm working on right now! :ultrahappy:
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Re: Quadtree Spatial Indexing Demo

Post by Lap »

I've always been interested in how well various quadtree methods and similar tricks would work within this engine. I've long dreamed of mkaing some sort of 2d space shooter with many ships flying around with shots and particles all over the place. I was never able to get framerates to acceptable levels during my stress tests.

This demo shows my FPS at 90ish
Attempting on LuaJIT build gives about 145.

I've worried about being able to keep 60fps with more drawings, particles effects, weapons, hitscans, etc.

Removed circle function, replaced with drawing an image instead:

Love 0.8: 6.7ish frame time = 150ish FPS
LuaJIT: 3.0ish frame time = 300ish FPS.

Sure shows LuaJit being quite a significant improvement. I can even do 1000 balls and get 40FPS with the JIT version. Still, I wonder how more "real world" tests would fare.
User avatar
dreadkillz
Party member
Posts: 223
Joined: Sun Mar 04, 2012 2:04 pm
Location: USA

Re: Quadtree Spatial Indexing Demo

Post by dreadkillz »

Lap wrote:I've always been interested in how well various quadtree methods and similar tricks would work within this engine. I've long dreamed of mkaing some sort of 2d space shooter with many ships flying around with shots and particles all over the place. I was never able to get framerates to acceptable levels during my stress tests.

This demo shows my FPS at 90ish
Attempting on LuaJIT build gives about 145.

I've worried about being able to keep 60fps with more drawings, particles effects, weapons, hitscans, etc.

Removed circle function, replaced with drawing an image instead:

Love 0.8: 6.7ish frame time = 150ish FPS
LuaJIT: 3.0ish frame time = 300ish FPS.

Sure shows LuaJit being quite a significant improvement. I can even do 1000 balls and get 40FPS with the JIT version. Still, I wonder how more "real world" tests would fare.
Well if its any consolation, the quadtree could be improved by a lot. The demo doesn't have the most efficient methods of moving objects in the tree or finding collidables. Basically, tree traversals optimization would help a lot. Compared to kraftman's grid, the quadtree is horribly slow at large numbers of balls.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Quadtree Spatial Indexing Demo

Post by bartbes »

I've seen luajit go 6x as fast as lua on particularly lua-heavy code (I think it was one of jasoco's 3d things) but also match the speed of lua on gpu-heavy code.
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Quadtree Spatial Indexing Demo

Post by Xgoff »

bartbes wrote:I've seen luajit go 6x as fast as lua on particularly lua-heavy code (I think it was one of jasoco's 3d things) but also match the speed of lua on gpu-heavy code.
any lua codepath that happens to call a love c api function will never get compiled, so it's not too surprising that gpu-heavy code doesn't benefit (either because the gpu is the bottleneck or you're hammering love.graphics functions)

technically a proper luajit version of love would use the ffi for everything (or implement as much in lua as possible)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests