Bitwise operations for cross Lua compatibility.
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
local bitlib = {}
|
||||
|
||||
function bitlib.setBit( v, i, b )
|
||||
if b then
|
||||
return v | 1 << i
|
||||
else
|
||||
return v & ~( 1 << i )
|
||||
end
|
||||
end
|
||||
|
||||
function bitlib.toggleBit( v, i )
|
||||
return v ~ ( 1 << i )
|
||||
end
|
||||
|
||||
function bitlib.getBit( v, i )
|
||||
if v == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
return 0 < v & ( 1 << i )
|
||||
end
|
||||
|
||||
return bitlib
|
||||
@@ -1,6 +1,5 @@
|
||||
Util = require( "utillib" )
|
||||
Vec2 = require( "vector2" )
|
||||
Vec3 = require( "vector3" )
|
||||
local Vec2 = require( "vector2" )
|
||||
local Vec3 = require( "vector3" )
|
||||
|
||||
Camera3D = {}
|
||||
Camera3D.meta = {
|
||||
@@ -17,6 +16,8 @@ Camera3D.KEYS = {
|
||||
BACKWARD = RL.KEY_S,
|
||||
RIGHT = RL.KEY_D,
|
||||
LEFT = RL.KEY_A,
|
||||
UP = RL.KEY_R,
|
||||
DOWN = RL.KEY_F,
|
||||
PAN = RL.KEY_LEFT_SHIFT,
|
||||
FAST = RL.KEY_LEFT_SHIFT,
|
||||
}
|
||||
@@ -91,17 +92,19 @@ function Camera3D:getUpward()
|
||||
end
|
||||
|
||||
function Camera3D:update( delta )
|
||||
delta = 1 / 60 -- Hack for framerate independance.
|
||||
|
||||
if self.mode == self.MODES.FREE then
|
||||
if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_MIDDLE ) then
|
||||
local mouseDelta = Vec2:newT( RL.GetMouseDelta() )
|
||||
|
||||
|
||||
if RL.IsKeyDown( self.KEYS.PAN ) then
|
||||
mouseDelta = mouseDelta:scale( self.MOUSE_MOVE_SPEED * delta )
|
||||
local forward = RL.GetCamera3DForward( self.camera )[2]
|
||||
|
||||
RL.Camera3DMoveRight( self.camera, -mouseDelta.x, true )
|
||||
RL.Camera3DMoveUp( self.camera, mouseDelta.y * -( ( 1 - math.abs( forward ) ) * Util.sign( forward ) ) )
|
||||
RL.Camera3DMoveForward( self.camera, mouseDelta.y * math.abs( forward ), true )
|
||||
RL.Camera3DMoveUp( self.camera, mouseDelta.y * ( 1 - math.abs( forward ) ) )
|
||||
RL.Camera3DMoveForward( self.camera, mouseDelta.y * -forward, true )
|
||||
else
|
||||
mouseDelta = mouseDelta:scale( self.TURN_SPEED * delta )
|
||||
|
||||
@@ -125,6 +128,7 @@ function Camera3D:update( delta )
|
||||
RL.SetMousePosition( Vec2:newT( RL.GetScreenSize() ):scale( 0.5 ) )
|
||||
|
||||
local distance = self.KEYBOARD_MOVE_SPEED * delta
|
||||
local forward = RL.GetCamera3DForward( self.camera )[2]
|
||||
|
||||
if RL.IsKeyDown( self.KEYS.FAST ) then
|
||||
distance = distance * self.KEYBOARD_MOVE_SPEED_MULTI
|
||||
@@ -141,6 +145,14 @@ function Camera3D:update( delta )
|
||||
elseif RL.IsKeyDown( self.KEYS.LEFT ) then
|
||||
RL.Camera3DMoveRight( self.camera, -distance, true )
|
||||
end
|
||||
|
||||
if RL.IsKeyDown( self.KEYS.UP ) then
|
||||
RL.Camera3DMoveUp( self.camera, distance * ( 1 - math.abs( forward ) ) )
|
||||
RL.Camera3DMoveForward( self.camera, distance * -forward, true )
|
||||
elseif RL.IsKeyDown( self.KEYS.DOWN ) then
|
||||
RL.Camera3DMoveUp( self.camera, -distance * ( 1 - math.abs( forward ) ) )
|
||||
RL.Camera3DMoveForward( self.camera, -distance * -forward, true )
|
||||
end
|
||||
elseif self.mode == self.MODES.ORBITAL then
|
||||
RL.Camera3DYaw( self.camera, self.ORBITAL_SPEED * delta, true )
|
||||
end
|
||||
|
||||
@@ -175,11 +175,8 @@ end
|
||||
|
||||
function Color:temp( r, g, b, a )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.r = r or 255
|
||||
object.g = g or 255
|
||||
@@ -191,11 +188,8 @@ end
|
||||
|
||||
function Color:tempT( t )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.r, object.g, object.b, object.a = table.unpack( t )
|
||||
|
||||
@@ -204,11 +198,8 @@ end
|
||||
|
||||
function Color:tempC( c )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.r = c.r
|
||||
object.g = c.g
|
||||
|
||||
@@ -183,11 +183,8 @@ end
|
||||
|
||||
function Quaternion:temp( x, y, z, w )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x = x or 0
|
||||
object.y = y or 0
|
||||
@@ -199,11 +196,8 @@ end
|
||||
|
||||
function Quaternion:tempT( t )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x, object.y, object.z, object.w = table.unpack( t )
|
||||
|
||||
@@ -212,11 +206,8 @@ end
|
||||
|
||||
function Quaternion:tempQ( q )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x = q.x
|
||||
object.y = q.y
|
||||
|
||||
@@ -47,9 +47,9 @@ function Rectangle:new( x, y, width, height )
|
||||
local object = setmetatable( {}, Rectangle.meta )
|
||||
|
||||
object.x = x or 0
|
||||
object.y = y or 0
|
||||
object.y = y or object.x
|
||||
object.width = width or 0
|
||||
object.height = height or 0
|
||||
object.height = height or object.width
|
||||
|
||||
return object
|
||||
end
|
||||
@@ -75,9 +75,9 @@ end
|
||||
|
||||
function Rectangle:set( x, y, width, height )
|
||||
self.x = x or 0
|
||||
self.y = y or 0
|
||||
self.y = y or self.x
|
||||
self.width = width or 0
|
||||
self.height = height or 0
|
||||
self.height = height or self.width
|
||||
end
|
||||
|
||||
function Rectangle:setT( t )
|
||||
@@ -183,27 +183,21 @@ end
|
||||
|
||||
function Rectangle:temp( x, y, width, height )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x = x or 0
|
||||
object.y = y or 0
|
||||
object.y = y or object.x
|
||||
object.width = width or 0
|
||||
object.height = height or 0
|
||||
object.height = height or object.width
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Rectangle:tempT( t )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x, object.y, object.width, object.height = table.unpack( t )
|
||||
|
||||
@@ -212,11 +206,8 @@ end
|
||||
|
||||
function Rectangle:tempR( r )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x = r.x
|
||||
object.y = r.y
|
||||
|
||||
@@ -7,11 +7,6 @@ end
|
||||
|
||||
local utillib = {}
|
||||
|
||||
-- Does not work with dictionaries.
|
||||
function utillib.arrayClone( org )
|
||||
return { table.unpack( org ) }
|
||||
end
|
||||
|
||||
function utillib.deepCopy( orig )
|
||||
local copy
|
||||
|
||||
@@ -156,7 +151,8 @@ function utillib.colorLerp( a, b, f )
|
||||
return {
|
||||
utillib.round( utillib.lerp( a[1], b[1], f ) ),
|
||||
utillib.round( utillib.lerp( a[2], b[2], f ) ),
|
||||
utillib.round( utillib.lerp( a[3], b[3], f ) ) }
|
||||
utillib.round( utillib.lerp( a[3], b[3], f ) )
|
||||
}
|
||||
end
|
||||
|
||||
-- Move secuence of elements inside table.
|
||||
@@ -176,4 +172,15 @@ function utillib.randomFloat( min, max )
|
||||
return min + math.random() * ( max - min );
|
||||
end
|
||||
|
||||
function utillib.printBin( v )
|
||||
for i = 31, 0, -1 do
|
||||
if RL.BitGet( v, i ) then
|
||||
io.write( "1" )
|
||||
else
|
||||
io.write( "0" )
|
||||
end
|
||||
end
|
||||
print()
|
||||
end
|
||||
|
||||
return utillib
|
||||
|
||||
@@ -45,7 +45,7 @@ function Vector2:new( x, y )
|
||||
local object = setmetatable( {}, metatable )
|
||||
|
||||
object.x = x or 0
|
||||
object.y = y or 0
|
||||
object.y = y or object.x
|
||||
|
||||
return object
|
||||
end
|
||||
@@ -70,7 +70,7 @@ end
|
||||
|
||||
function Vector2:set( x, y )
|
||||
self.x = x or 0
|
||||
self.y = y or 0
|
||||
self.y = y or self.x
|
||||
end
|
||||
|
||||
function Vector2:setT( t )
|
||||
@@ -230,25 +230,19 @@ end
|
||||
|
||||
function Vector2:temp( x, y )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x = x or 0
|
||||
object.y = y or 0
|
||||
object.y = y or object.x
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Vector2:tempT( t )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x, object.y = table.unpack( t )
|
||||
|
||||
@@ -257,11 +251,8 @@ end
|
||||
|
||||
function Vector2:tempV( v )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x = v.x
|
||||
object.y = v.y
|
||||
|
||||
@@ -47,8 +47,8 @@ function Vector3:new( x, y, z )
|
||||
local object = setmetatable( {}, metatable )
|
||||
|
||||
object.x = x or 0
|
||||
object.y = y or 0
|
||||
object.z = z or 0
|
||||
object.y = y or object.x
|
||||
object.z = z or object.y
|
||||
|
||||
return object
|
||||
end
|
||||
@@ -73,8 +73,8 @@ end
|
||||
|
||||
function Vector3:set( x, y, z )
|
||||
self.x = x or 0
|
||||
self.y = y or 0
|
||||
self.z = z or 0
|
||||
self.y = y or self.x
|
||||
self.z = z or self.y
|
||||
end
|
||||
|
||||
function Vector3:setT( t )
|
||||
@@ -260,26 +260,20 @@ end
|
||||
|
||||
function Vector3:temp( x, y, z )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x = x or 0
|
||||
object.y = y or 0
|
||||
object.z = z or 0
|
||||
object.y = y or object.x
|
||||
object.z = z or object.y
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
function Vector3:tempT( t )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x, object.y, object.z = table.unpack( t )
|
||||
|
||||
@@ -288,11 +282,8 @@ end
|
||||
|
||||
function Vector3:tempV( v )
|
||||
local object = tempPool[ curTemp ]
|
||||
curTemp = curTemp + 1
|
||||
|
||||
if TEMP_COUNT < curTemp then
|
||||
curTemp = 1
|
||||
end
|
||||
curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
|
||||
|
||||
object.x = v.x
|
||||
object.y = v.y
|
||||
|
||||
Reference in New Issue
Block a user