lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

local midentity = matrixh()
local valtitude = vector()
function model:update_fast()
   local global_matrix = self.global_matrix
   geometry.matrixh.copy(global_matrix, midentity)
   global_matrix:rotate(self.orbital_orientation)
   valtitude.y = self.altitude
   global_matrix:translate(valtitude)
   global_matrix:rotate(self.orientation)
   global_matrix:translate(self.position)
end

And even if that optimized form is acceptable for entity
update, for skeletal animation of a couple hundred of
entities with 64 bones each it just takes too much time to
run at interactive framerate, so instead I rewrite these
critical bottlenecks in C.

If you are willing to use this syntax, you could perhaps go
the next step and use light user data for matrices? You
could then completely avoid Lua's garbage collection (and
production).

    local midentity = matrixh()
        -- returns lightuserdata pointing to memory chunk
        -- outside of Lua's control
    local valtitude = vector()
        -- ditto
    function model:update_fast()
       local global_matrix = self.global_matrix
       copy(global_matrix, midentity)
       rotate(global_matrix, self.orbital_orientation)
       valtitude.y = self.altitude
       translate(global_matrix, valtitude)
       rotate(global_matrix, self.orientation)
       translate(global_matrix, self.position)
    end

Does not look bad at all. Your only overhead would be Lua
function calls.

Regards,
Diego