Page 1 of 2

Standardize on a vector math library?

Posted: Sun Aug 28, 2016 10:30 pm
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.

Re: Standardize on a vector math library?

Posted: Sun Aug 28, 2016 10:42 pm
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]

Re: Standardize on a vector math library?

Posted: Sun Aug 28, 2016 11:06 pm
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. :)

Re: Standardize on a vector math library?

Posted: Mon Aug 29, 2016 2:20 am
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.

Re: Standardize on a vector math library?

Posted: Mon Aug 29, 2016 2:23 am
by raidho36
You could write vector library to use pools internally, you know. No garbage.

Re: Standardize on a vector math library?

Posted: Mon Aug 29, 2016 2:23 am
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.

Re: Standardize on a vector math library?

Posted: Mon Aug 29, 2016 2:31 am
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).

Re: Standardize on a vector math library?

Posted: Mon Aug 29, 2016 2:35 am
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.

Re: Standardize on a vector math library?

Posted: Mon Aug 29, 2016 2:47 am
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

Re: Standardize on a vector math library?

Posted: Mon Aug 29, 2016 3:14 am
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?