Standardize on a vector math library?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
clofresh
Citizen
Posts: 87
Joined: Sun Jul 26, 2009 4:21 pm
Contact:

Standardize on a vector math library?

Post by clofresh »

Hello,

Do you guys think we could incorporate a vector math library as part of LOVE? I know the LOVE community prides itself on a DIY, "don't force me into a particular way of doing things" kind of spirit, but everyone does the same things with vectors: add, subtract, dot product, normalize, etc. Even though it's the same functionality, everyone implements it with a slightly different interface, making it difficult to interop with different libraries. You end up writing a lot of code that translates between variations of vector interfaces.

Another future benefit could be that performance sensitive vector operations could potentially be implemented in C/C++ behind the scenes, without the end user devs having to worry about bundling native code.

Maybe initially we could bundle hump.vector_light as love.vector? Or if not bundle a particular implementation, create a type signature that anyone can implement so libraries can assume a standard interface, if not implementation.
----------------------------------------
Sluicer Games
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Standardize on a vector math library?

Post by Positive07 »

I wouldn't use it though, and I would recommend CPML more than hump.vector too. And I don't understand why you can't go and use hump in your code. I don't see any need on vector classes. Maybe we could add some vector math to [wiki]love.math[/wiki] but I would be more interested in transformation matrices and a way to used with [wiki]love.graphics[/wiki]
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Standardize on a vector math library?

Post by slime »

If LOVE included a vector library then people would probably assume its other APIs should accept vectors, but...

viewtopic.php?f=3&t=81457&start=50#p193807
slime wrote:
spill wrote:it would be really cool if LÖVE used 2d vectors instead of x/y coordinates everywhere.
The main problem with LÖVE's APIs using vector objects is that in Lua, vector objects tend to create a lot of garbage if used heavily. So having them required for using LÖVE functions prevents optimal performance. Some engines go to extreme lengths to try to work around that: https://www.youtube.com/watch?v=wTjyM7d7_YA#t=23m6s

I don't want to make vector-specific function variants either, as that would make the API a lot messier.
Having the vector code be in C++ would also (for the most part) either be as efficient or slower than having it in Lua, since love uses LuaJIT.

If good solutions are proposed for those problems though, then I'd be all ears. :)
Last edited by slime on Mon Aug 29, 2016 2:32 am, edited 1 time in total.
User avatar
clofresh
Citizen
Posts: 87
Joined: Sun Jul 26, 2009 4:21 pm
Contact:

Re: Standardize on a vector math library?

Post by clofresh »

Ah ok, looks like you guys have discussed this in depth. (Couldn't find it from searching, should I start a FAQ wiki page for questions like these?)

The garbage generation is a good point. I'll think about it for a bit.
----------------------------------------
Sluicer Games
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Standardize on a vector math library?

Post by raidho36 »

You could write vector library to use pools internally, you know. No garbage.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Standardize on a vector math library?

Post by zorg »

clofresh wrote:(Couldn't find it from searching, should I start a FAQ wiki page for questions like these?)
In actuality, that was also discussed a few times, at length, as well :3
I planned to do something like that, but alas, i hadn't had time for it yet, nor did i think out a neat format for it.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Standardize on a vector math library?

Post by slime »

raidho36 wrote:You could write vector library to use pools internally, you know. No garbage.
You pretty much have to choose between arithmetic operator overloads or no-garbage vectors (e.g. CPML has no-garbage APIs, and then the arithmetic operators which do generate garbage).

I did experiment with the gc metamethod and a pool of FFI vectors, but it ended up being slower than just plain FFI structs of doubles (which still generates garbage).
User avatar
clofresh
Citizen
Posts: 87
Joined: Sun Jul 26, 2009 4:21 pm
Contact:

Re: Standardize on a vector math library?

Post by clofresh »

zorg wrote:
clofresh wrote:(Couldn't find it from searching, should I start a FAQ wiki page for questions like these?)
In actuality, that was also discussed a few times, at length, as well :3
I planned to do something like that, but alas, i hadn't had time for it yet, nor did i think out a neat format for it.
Started it: https://love2d.org/wiki/FAQ

It's not linked from anywhere though.
----------------------------------------
Sluicer Games
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Standardize on a vector math library?

Post by zorg »

clofresh wrote:Started it: https://love2d.org/wiki/FAQ
It's not linked from anywhere though.
I started its discussion page, see there for what i had, and am still, planning on. As for linkage, it would be nice to have a link, but the version history page lacks one as well, so idk :o:
/OFF-TOPIC
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Standardize on a vector math library?

Post by raidho36 »

slime wrote: You pretty much have to choose between arithmetic operator overloads or no-garbage vectors (e.g. CPML has no-garbage APIs, and then the arithmetic operators which do generate garbage).

I did experiment with the gc metamethod and a pool of FFI vectors, but it ended up being slower than just plain FFI structs of doubles (which still generates garbage).
Just to be clear, this is about in-engine implementation, not a LUA library?
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests