New creation methods for object libs.
This commit is contained in:
@@ -65,6 +65,17 @@ function Color:newT( t )
|
||||
return object
|
||||
end
|
||||
|
||||
function Color:newC( c )
|
||||
local object = setmetatable( {}, metatable )
|
||||
|
||||
object.r = c.r
|
||||
object.g = c.g
|
||||
object.b = c.b
|
||||
object.a = c.a
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Color:set( r, g, b, a )
|
||||
self.r = r or 255
|
||||
self.g = g or 255
|
||||
@@ -76,6 +87,13 @@ function Color:setT( t )
|
||||
self.r, self.g, self.b, self.a = table.unpack( t )
|
||||
end
|
||||
|
||||
function Color:setC( c )
|
||||
self.r = c.r
|
||||
self.g = c.g
|
||||
self.b = c.b
|
||||
self.a = c.a
|
||||
end
|
||||
|
||||
function Color:arr()
|
||||
return { self.r, self.g, self.b, self.a }
|
||||
end
|
||||
@@ -145,6 +163,8 @@ function Color:lerp( color, amount )
|
||||
)
|
||||
end
|
||||
|
||||
-- Temp pre generated objects to avoid "slow" table generation.
|
||||
|
||||
local TEMP_COUNT = 100
|
||||
local tempPool = {}
|
||||
local curTemp = 1
|
||||
@@ -153,7 +173,6 @@ for _ = 1, TEMP_COUNT do
|
||||
table.insert( tempPool, Color:new( 255, 255, 255, 255 ) )
|
||||
end
|
||||
|
||||
-- Uses pre generated objects to avoid "slow" table generation.
|
||||
function Color:temp( r, g, b, a )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
@@ -170,7 +189,6 @@ function Color:temp( r, g, b, a )
|
||||
return object
|
||||
end
|
||||
|
||||
-- Uses pre generated objects to avoid "slow" table generation.
|
||||
function Color:tempT( t )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
@@ -184,6 +202,22 @@ function Color:tempT( t )
|
||||
return object
|
||||
end
|
||||
|
||||
function Color:tempC( c )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
|
||||
object.r = c.r
|
||||
object.g = c.g
|
||||
object.b = c.b
|
||||
object.a = c.a
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Color:getTempId()
|
||||
return curTemp
|
||||
end
|
||||
|
||||
@@ -57,6 +57,17 @@ function Quaternion:newT( t )
|
||||
return object
|
||||
end
|
||||
|
||||
function Quaternion:newQ( q )
|
||||
local object = setmetatable( {}, metatable )
|
||||
|
||||
object.x = q.x
|
||||
object.y = q.y
|
||||
object.z = q.z
|
||||
object.w = q.w
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Quaternion:set( x, y, z, w )
|
||||
self.x = x or 0
|
||||
self.y = y or 0
|
||||
@@ -68,6 +79,13 @@ function Quaternion:setT( t )
|
||||
self.x, self.y, self.z, self.w = table.unpack( t )
|
||||
end
|
||||
|
||||
function Quaternion:setQ( q )
|
||||
self.x = q.x
|
||||
self.y = q.y
|
||||
self.z = q.z
|
||||
self.w = q.w
|
||||
end
|
||||
|
||||
function Quaternion:arr()
|
||||
return { self.x, self.y, self.z, self.w }
|
||||
end
|
||||
@@ -153,6 +171,8 @@ function Quaternion:transform( mat )
|
||||
return Quaternion:newT( RL.QuaternionTransform( self, mat ) )
|
||||
end
|
||||
|
||||
-- Temp pre generated objects to avoid "slow" table generation.
|
||||
|
||||
local TEMP_COUNT = 100
|
||||
local tempPool = {}
|
||||
local curTemp = 1
|
||||
@@ -161,7 +181,6 @@ for _ = 1, TEMP_COUNT do
|
||||
table.insert( tempPool, Quaternion:new( 0, 0, 0, 1 ) )
|
||||
end
|
||||
|
||||
-- Uses pre generated objects to avoid "slow" table generation.
|
||||
function Quaternion:temp( x, y, z, w )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
@@ -178,7 +197,6 @@ function Quaternion:temp( x, y, z, w )
|
||||
return object
|
||||
end
|
||||
|
||||
-- Uses pre generated objects to avoid "slow" table generation.
|
||||
function Quaternion:tempT( t )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
@@ -192,6 +210,22 @@ function Quaternion:tempT( t )
|
||||
return object
|
||||
end
|
||||
|
||||
function Quaternion:tempQ( q )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
|
||||
object.x = q.x
|
||||
object.y = q.y
|
||||
object.z = q.z
|
||||
object.w = q.w
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Quaternion:getTempId()
|
||||
return curTemp
|
||||
end
|
||||
|
||||
@@ -62,6 +62,17 @@ function Rectangle:newT( t )
|
||||
return object
|
||||
end
|
||||
|
||||
function Rectangle:newR( r )
|
||||
local object = setmetatable( {}, Rectangle.meta )
|
||||
|
||||
object.x = r.x
|
||||
object.y = r.y
|
||||
object.width = r.width
|
||||
object.height = r.height
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Rectangle:set( x, y, width, height )
|
||||
self.x = x or 0
|
||||
self.y = y or 0
|
||||
@@ -73,6 +84,13 @@ function Rectangle:setT( t )
|
||||
self.x, self.y, self.width, self.height = table.unpack( t )
|
||||
end
|
||||
|
||||
function Rectangle:setR( r )
|
||||
self.x = r.x
|
||||
self.y = r.y
|
||||
self.width = r.width
|
||||
self.height = r.height
|
||||
end
|
||||
|
||||
function Rectangle:arr()
|
||||
return { self.x, self.y, self.width, self.height }
|
||||
end
|
||||
@@ -153,6 +171,8 @@ function Rectangle:getCollisionRec( rec )
|
||||
return Rectangle:new( RL.GetCollisionRec( self, rec ) )
|
||||
end
|
||||
|
||||
-- Temp pre generated objects to avoid "slow" table generation.
|
||||
|
||||
local TEMP_COUNT = 100
|
||||
local tempPool = {}
|
||||
local curTemp = 1
|
||||
@@ -161,7 +181,6 @@ for _ = 1, TEMP_COUNT do
|
||||
table.insert( tempPool, Rectangle:new( 0, 0, 0, 0 ) )
|
||||
end
|
||||
|
||||
-- Uses pre generated objects to avoid "slow" table generation.
|
||||
function Rectangle:temp( x, y, width, height )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
@@ -178,7 +197,6 @@ function Rectangle:temp( x, y, width, height )
|
||||
return object
|
||||
end
|
||||
|
||||
-- Uses pre generated objects to avoid "slow" table generation.
|
||||
function Rectangle:tempT( t )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
@@ -192,6 +210,22 @@ function Rectangle:tempT( t )
|
||||
return object
|
||||
end
|
||||
|
||||
function Rectangle:tempR( r )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
|
||||
object.x = r.x
|
||||
object.y = r.y
|
||||
object.width = r.width
|
||||
object.height = r.height
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Rectangle:getTempId()
|
||||
return curTemp
|
||||
end
|
||||
|
||||
@@ -11,7 +11,6 @@ local metatable = {
|
||||
end,
|
||||
__add = function( v1, v2 )
|
||||
return Vector2:new( v1.x + v2.x, v1.y + v2.y )
|
||||
-- return Vector2:newOld( v1.x + v2.x, v1.y + v2.y )
|
||||
end,
|
||||
__sub = function( v1, v2 )
|
||||
return Vector2:new( v1.x - v2.x, v1.y - v2.y )
|
||||
@@ -59,6 +58,16 @@ function Vector2:newT( t )
|
||||
return object
|
||||
end
|
||||
|
||||
function Vector2:newV( v )
|
||||
local object = setmetatable( {}, metatable )
|
||||
|
||||
object.x = v.x
|
||||
object.y = v.y
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
|
||||
function Vector2:set( x, y )
|
||||
self.x = x or 0
|
||||
self.y = y or 0
|
||||
@@ -68,6 +77,11 @@ function Vector2:setT( t )
|
||||
self.x, self.y = table.unpack( t )
|
||||
end
|
||||
|
||||
function Vector2:setV( v )
|
||||
self.x = v.x
|
||||
self.y = v.y
|
||||
end
|
||||
|
||||
function Vector2:arr()
|
||||
return { self.x, self.y }
|
||||
end
|
||||
@@ -204,6 +218,8 @@ function Vector2:divEq( v2 )
|
||||
self.y = self.y / v2.y
|
||||
end
|
||||
|
||||
-- Temp pre generated objects to avoid "slow" table generation.
|
||||
|
||||
local TEMP_COUNT = 100
|
||||
local tempPool = {}
|
||||
local curTemp = 1
|
||||
@@ -212,7 +228,6 @@ for _ = 1, TEMP_COUNT do
|
||||
table.insert( tempPool, Vector2:new( 0, 0 ) )
|
||||
end
|
||||
|
||||
-- Uses pre generated objects to avoid "slow" table generation.
|
||||
function Vector2:temp( x, y )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
@@ -227,7 +242,6 @@ function Vector2:temp( x, y )
|
||||
return object
|
||||
end
|
||||
|
||||
-- Uses pre generated objects to avoid "slow" table generation.
|
||||
function Vector2:tempT( t )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
@@ -241,6 +255,20 @@ function Vector2:tempT( t )
|
||||
return object
|
||||
end
|
||||
|
||||
function Vector2:tempV( v )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
|
||||
object.x = v.x
|
||||
object.y = v.y
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Vector2:getTempId()
|
||||
return curTemp
|
||||
end
|
||||
|
||||
@@ -61,6 +61,16 @@ function Vector3:newT( t )
|
||||
return object
|
||||
end
|
||||
|
||||
function Vector3:newV( v )
|
||||
local object = setmetatable( {}, metatable )
|
||||
|
||||
object.x = v.x
|
||||
object.y = v.y
|
||||
object.z = v.z
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Vector3:set( x, y, z )
|
||||
self.x = x or 0
|
||||
self.y = y or 0
|
||||
@@ -71,6 +81,12 @@ function Vector3:setT( t )
|
||||
self.x, self.y, self.z = table.unpack( t )
|
||||
end
|
||||
|
||||
function Vector3:setV( v )
|
||||
self.x = v.x
|
||||
self.y = v.y
|
||||
self.z = v.z
|
||||
end
|
||||
|
||||
function Vector3:arr()
|
||||
return { self.x, self.y, self.z }
|
||||
end
|
||||
@@ -232,6 +248,8 @@ function Vector3:divEq( v2 )
|
||||
self.z = self.z / v2.z
|
||||
end
|
||||
|
||||
-- Temp pre generated objects to avoid "slow" table generation.
|
||||
|
||||
local TEMP_COUNT = 100
|
||||
local tempPool = {}
|
||||
local curTemp = 1
|
||||
@@ -240,7 +258,6 @@ for _ = 1, TEMP_COUNT do
|
||||
table.insert( tempPool, Vector3:new( 0, 0, 0 ) )
|
||||
end
|
||||
|
||||
-- Uses pre generated objects to avoid "slow" table generation.
|
||||
function Vector3:temp( x, y, z )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
@@ -256,7 +273,6 @@ function Vector3:temp( x, y, z )
|
||||
return object
|
||||
end
|
||||
|
||||
-- Uses pre generated objects to avoid "slow" table generation.
|
||||
function Vector3:tempT( t )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
@@ -270,6 +286,21 @@ function Vector3:tempT( t )
|
||||
return object
|
||||
end
|
||||
|
||||
function Vector3:tempV( v )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
|
||||
object.x = v.x
|
||||
object.y = v.y
|
||||
object.z = v.z
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Vector3:getTempId()
|
||||
return curTemp
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user