-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Table Vectors #789
Open
bjornbytes
wants to merge
28
commits into
dev
Choose a base branch
from
table-vectors
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Table Vectors #789
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prevents "expected number, got number" type error messages for vectors. Had to add an unfortunate flag for whether checkbufferdata accepts numbers or not...
That way all the math stuff consumes the same number of arguments when nil.
No need for a matrix multiplication here.
They are in math.lua now.
This is a lot faster, since it doesn't have to do all the registry bookkeeping that the other objects do.
For backwards compatibility.
For compatibility.
Performance test on IK benchmark:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a branch that makes vectors use tables instead of userdata. It is an evolution of what was proposed in #737. For now, the Lua API tries to match the existing one as closely as possible. Methods that take vector objects like vec3 can instead take any table, e.g.
pass:sphere({ x, y, z }, radius)
.Also, there are only permanent vectors now, temporary vectors are removed. LuaJIT's garbage collector seems to be able to handle the increased GC load for most workloads, and it's possible to pool table vectors to avoid garbage explosion in tight loops.
Why do this?
It has the following known incompatibilities:
__len
is not supported on tables in Lua 5.1 and LuaJIT (without 5.2 compat), so you can't do#v
and need to dov:length()
now instead.rgba
andstpq
swizzles were dropped.lovr.math.drain
was removed, because there aren't temporary vectors anymore (TODO it could be added back as a deprecated function that does nothing, to avoid breakage).One thing that's a little bit annoying is that, for quaternions, you can't do
{ angle, ax, ay, az }
like you can for vec3 and instead need to doquat(angle, ax, ay, az)
to convert it to quaternion components. This is a small gotcha but I think it's ok.