Page 2 of 2
Re: Friction From Scratch
Posted: Wed Feb 01, 2012 8:53 am
by BmB
I'm not sure how these functions aren't reusable? You could use any length finding function to supply the length for this setlength function. Benefit being you still only need to compute the length once. I think this is very clear, functionally. Even if I don't use the absolute minimum amount of characters to write it.
An operation once every frame or twice every frame I'd have to say is a big difference, especially as it grows exponentially with the amount of frames you're doing.
I cleaned up the relevant table statements:
Code: Select all
xcontrol, ycontrol = controlvector()
xspeed = xspeed + (xcontrol*accel)
yspeed = yspeed + (ycontrol*accel)
loc[1] = loc[1] + xspeed
loc[2] = loc[2] + yspeed
Re: Friction From Scratch
Posted: Wed Feb 01, 2012 9:44 am
by Robin
BmB wrote:An operation once every frame or twice every frame I'd have to say is a big difference, especially as it grows exponentially with the amount of frames you're doing.
That would be linearly, not exponentially.
Re: Friction From Scratch
Posted: Wed Feb 01, 2012 9:52 am
by BmB
Frames are a measure of hertz yes, the smaller the linear timestep the more frames you need by x + x*2 and if you have 2 operations each frame that's then x + x*2*2. Yes?
Re: Friction From Scratch
Posted: Wed Feb 01, 2012 3:26 pm
by MarekkPie
x + x*2*2 = x + 4x, which is still linear.
If you had two objects that spawned two more objects that spawned two more objects...that all did the same thing, then it would be 2^x, which is exponentially.
Re: Friction From Scratch
Posted: Wed Feb 01, 2012 4:23 pm
by Xgoff
ivan wrote:Lastly, I would advise against using table to represent vectors.
In my experience, it's an unnecessary strain on the Lua garbage collector.
Hope this helps
haha yeah, this makes me really nervous about using vector-heavy lua libs
granted you need to be creating a "lot" of tables per frame for this to happen, although in my case this was something like 13-14k, which was enough to pull the framerate down to 30 (cloth sim, and a fairly bad one at that [euler integration and only one solve per iteration], a better one would likely tear through a good deal more than that)
it makes me wonder if it's better to implement vectors as userdata which can be pooled on the c side (assuming that's even a reasonable option without deterministic lifetimes)
EDIT: actually maybe it's possible to do the pooling through the vector functions... like
function add (a, b) pool2(a, b) return vector(a[1] + b[1], a[2] + b[2]) end.
haven't really thought about it though
Re: Friction From Scratch
Posted: Thu Feb 02, 2012 3:01 am
by BmB
MarekkPie wrote:x + x*2*2 = x + 4x, which is still linear.
If you had two objects that spawned two more objects that spawned two more objects...that all did the same thing, then it would be 2^x, which is exponentially.
Alright yeah as stated I suck at math. Still a lot tho.