Friction From Scratch

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
BmB
Prole
Posts: 8
Joined: Mon Jan 30, 2012 8:33 am

Re: Friction From Scratch

Post 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
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Friction From Scratch

Post 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.
Help us help you: attach a .love.
User avatar
BmB
Prole
Posts: 8
Joined: Mon Jan 30, 2012 8:33 am

Re: Friction From Scratch

Post 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?
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Friction From Scratch

Post 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.
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Friction From Scratch

Post 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
User avatar
BmB
Prole
Posts: 8
Joined: Mon Jan 30, 2012 8:33 am

Re: Friction From Scratch

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 8 guests