Physics demo with GetRestitution typo fix

Showcase your libraries, tools and other projects that help your fellow love users.
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Physics demo with GetRestitution typo fix

Post by pekka »

I wrote a little physics demo that shows how to correct for the typo with Shape:getRestitution() method. Some versions of LÖVE have it as getRestituion instead, but you can just monkey with the metatables a bit and everything turns out right. If you don't fix this, you might get an error saying you attempted to call a nil value or something similar.

Now, it's late, I'm in Finland & EET time zone you see, and I'd like others to review the code before I suggest you mention this in the docs, or somewhere. I actually thought I'd edit the online docs to mention this little thing, but I didn't manage to figure the markup out in time. Maybe this should go in the Wiki instead. It's not like it's a key issue for a lot of folks.

But! It's not fun if you write code that then breaks with other versions of LÖVE where this typo either exists or is fixed. Just to make sure everyone can avoid this little bit of embarrassment, it's useful to have something like this around. This way you can call the properly spelled method anywhere with no worries.

But have a look at it first, please. I'm a bit tired now. Also, sorry for pegging the CPU with no framerate limit, unless you have vsync on. Then it might look a bit choppy because the physics step 1/60 secs which is also a typical vsync rate. To get smooth physics with low framerate you probably need to interpolate between frames and all that jazz. I'm not in the mood now.

The ideal solution would probably be to create one polygon shape and one circle shape once in love.load and then fix their metatables right there. There's no need to use those boolean vars as in my code, but I wanted to be explicit that you only need to mess with two types of metatables once and then the fix stays in place. I am not sure about every detail though! E.g. if you destroy the world, do the metatables get reset when you make another?

Anyway, too much ado about a little typo that is fixed in the SVN already. Pay no mind if you are not going to use getRestitution a lot! But you can play with the little shapes you can make by clicking the mouse buttons no matter what.

Code: Select all

Code removed. Please see the posting later in this thread for a later version.
(license statement removed from here, new one placed into source code)
Last edited by pekka on Sat Jan 16, 2010 7:25 pm, edited 2 times in total.
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: Physics demo with GetRestitution typo fix

Post by pekka »

Well, I'll just leave this message here. It'll come up in a search if someone happens to run across that misspelled method name for real (not exactly likely I think). I decided to add a fps cap to the program (so it doesn't immediately run the batteries out on your laptops) and switched the order of mouse press processing. (License statement removed, placed into source code.)

I refer you to this Gaffer on Games article on why you might want to be careful with your physics updates and framerates. Not all games need to be this exact with it, but you ought to know the proper ways anyway, don't you?

http://gafferongames.com/game-physics/f ... -timestep/

(My example code is actually not proper by this measure. And it draws the shapes slowly.)

Code: Select all

Code removed. Please see the posting later in this thread for a later version.
Last edited by pekka on Sat Jan 16, 2010 7:25 pm, edited 2 times in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Physics demo with GetRestitution typo fix

Post by bartbes »

pekka wrote:I hereby grant the rights to use this code under the terms of the LPC License.
pekka wrote:This code is under the LPC License too.
I have to ask: which community?

And to everyone who hasn't read the bug report, the typo has been fixed for the next version.
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: Physics demo with GetRestitution typo fix

Post by pekka »

bartbes wrote:
pekka wrote:I hereby grant the rights to use this code under the terms of the LPC License.
pekka wrote:This code is under the LPC License too.
I have to ask: which community?
Oh, right. Ahem.

Well, if being a member of the LÖVE CLUB forum enables me to place my code under the LPC License with the community being the LÖVE CLUB forum, I'll do that. Is that all right?

Wouldn't it be useful if we could just assume any code posted here by its author is licensed with the LPC for the LÖVE CLUB unless the poster states otherwise when posting it? That way we could leave the copyright rituals for when we post about more serious projects, or perhaps use some already copyrighted resources with the terms of their licenses.

Speaking of projects, I am planning to use Löve to prototype some game ideas this year. I hope to write more about my experiences later. (It will be helpful to first have the experiences.)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Physics demo with GetRestitution typo fix

Post by bartbes »

Well, ehm.. this is a gray area, since the LÖVE community is everyone who has at least 10 posts on the forums here (>= a week ago), which you obviously don't have, but well, you are kind of the copyright holder..
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: Physics demo with GetRestitution typo fix

Post by pekka »

I could spam the boards with nonsense to make that work out. Seems like a good idea!! And by good here I mean bad, so I won't do it.

Just to avoid any bad copyright mojo, I'll edit my postings above and put the code under the BSD License. In the future I'll be explicit about the copyrights whenever I post some non-trivial code. You can remind me if I forget.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Physics demo with GetRestitution typo fix

Post by Robin »

pekka wrote:You can remind me if I forget.
We can do that. We can even remind you if you remember! Isn't that nice? ;)

But seriously, BSD seems like a good choice here.
Help us help you: attach a .love.
osuf oboys
Party member
Posts: 215
Joined: Sun Jan 18, 2009 8:03 pm

Re: Physics demo with GetRestitution typo fix

Post by osuf oboys »

Hmm... how about instead overloading newShape and setting the metatable appropriately before returning the created object. Also, if getRestitution is defined, and therefore presumably fixed, it should not replace it with getRestituion.

Regarding the license discussion. The point of LPCL is that the software should belong to a community and open for them to edit and improve (under the same name/trademark), even if the original authors do not agree with the community or if said author runs away. To not be in the community (yet) does not matter that much. You can still edit as you please but the community, e.g. the LÖVE forums, got the final say if any objections arise. If you think you should be in the community, then you should identify the properties that makes you a good member (e.g. that you have contributed a lot) and define the community from that; using your qualities rather than your identity. For a small project, LPCL could be an overcomplication. Also, LPCL needs to be reformulated and made clearer. As it stands, people are uncertain of what it means and may avoid it for that reason. Note also that BSD is more restrictive than LPCL - the latter is equivalent to the WTFPL in terms of copyright.
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: Physics demo with GetRestitution typo fix

Post by pekka »

Oh the silliness (of me). I had a code where I tested for getRestitution being nil and only assigning to it if it is nil. Thanks for pointing out I didn't include that bit in the code I posted.

Code: Select all

-- off the top of my head
if mt.getRestitution == nil then mt.getRestitution = mt.getRestituion end
I removed that test without thinking about it before posting my code. Which kind of made it miss the whole point I had for posting it. Let the point now be this:

If you have two different versions of Löve where the same method is spelled differently, you can still write code that runs in both by checking for and changing the names of the relevant methods in the metatables. Lua is good at reflection. You can ask a Lua expert to show you what is a good way to access and modify the metatables. Don't ask Pekka, because Pekka will just post code that has nothing to do with the actual topic. Pekka is like that sometimes! :)

By now this thread has gone on for too long. I'll bow out. Can I do that? I will do that. You'll have to bring me back kicking and screaming.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Physics demo with GetRestitution typo fix

Post by bartbes »

A lot of people (including me) would write

Code: Select all

mt.getRestitution = mt.getRestitution or mt.getRestituion
Anyway, thats just coding style.
If you are really not using this anymore, would you like me to lock the topic?
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests