Boids

Showcase your libraries, tools and other projects that help your fellow love users.
mikeisinlove
Prole
Posts: 44
Joined: Sun Mar 31, 2013 11:55 am

Re: Boids

Post by mikeisinlove »

without clearing the previous frames
https://www.youtube.com/watch?v=hohnjFj_zqI
User avatar
NobodysSon
Prole
Posts: 33
Joined: Tue Oct 30, 2012 10:37 pm

Re: Boids

Post by NobodysSon »

This was posted some time ago but I wanted to say how cool I thought your program was! It is very soothing to watch - reminds me of schools of fish.
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

Re: Boids

Post by Sir_Silver »

ivan wrote:Cool demo.
I have a couple of suggestions about the code:

Code: Select all

closest = {x=boid.x,y=boid.y}
The line above creates a lot of intermediate tables, you can just use 2 variables or do:

Code: Select all

closest.x, closest.y = boid.x, boid.y
I haven't taken the time to download the love file or check out the code, but what's so wrong with the first piece of code? Assuming that there isn't another handle to that table somewhere, it should just get garbage collected eventually, right? Are you just suggesting this for the sake of minimizing the work that has to be done come garbage day? :p
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Boids

Post by ivan »

I believe the code was creating intermediate tables in a loop.
Sir_Silver wrote:but what's so wrong with the first piece of code? Assuming that there isn't another handle to that table somewhere, it should just get garbage collected eventually, right? Are you just suggesting this for the sake of minimizing the work that has to be done come garbage day? :p
Yes, primarily because of the GC and it's just not a good use of intermediate tables
(I'm probably nitpicking, but then you have to access the table via "." which is slower than using locals)
In my experience, poor GC leads to occasional frame drops.
prixt
Prole
Posts: 26
Joined: Sat Sep 12, 2015 5:53 am

Re: Boids

Post by prixt »

Haven't been able to code properly for sometime, finally got access to my own laptop.
Here's a new one.
Attachments
boids.love
(4.41 KiB) Downloaded 151 times
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Re: Boids

Post by KayleMaster »

Can this be used as a pathfinding alternative for grid based games?
prixt
Prole
Posts: 26
Joined: Sat Sep 12, 2015 5:53 am

Re: Boids

Post by prixt »

KayleMaster wrote: Fri Dec 29, 2017 12:08 pm Can this be used as a pathfinding alternative for grid based games?
Well this technically isn't pathfinding: https://en.wikipedia.org/wiki/Boids
The grid here exists so only entities within a certain range will be iterated.
But you could get creative and use this combined with other algorithms.
Post Reply

Who is online

Users browsing this forum: No registered users and 59 guests