summaryrefslogtreecommitdiff
path: root/examples/resources/lib
diff options
context:
space:
mode:
authorjussi2024-05-01 15:21:28 +0300
committerjussi2024-05-01 15:21:28 +0300
commit4452bccfa63cf86c134aa616ee0bebcc66beca03 (patch)
treea40befeb0393fd5599240ccb85a4500781d78c17 /examples/resources/lib
parentbdd660be01f3742befe15dff26929a77eeefe61d (diff)
downloadreilua-enhanced-4452bccfa63cf86c134aa616ee0bebcc66beca03.tar.gz
reilua-enhanced-4452bccfa63cf86c134aa616ee0bebcc66beca03.tar.bz2
reilua-enhanced-4452bccfa63cf86c134aa616ee0bebcc66beca03.zip
Bitwise operations for cross Lua compatibility.
Diffstat (limited to 'examples/resources/lib')
-rw-r--r--examples/resources/lib/bitlib.lua23
-rw-r--r--examples/resources/lib/camera3d.lua24
-rw-r--r--examples/resources/lib/color.lua15
-rw-r--r--examples/resources/lib/quaternion.lua15
-rw-r--r--examples/resources/lib/rectangle.lua27
-rw-r--r--examples/resources/lib/utillib.lua19
-rw-r--r--examples/resources/lib/vector2.lua21
-rw-r--r--examples/resources/lib/vector3.lua27
8 files changed, 61 insertions, 110 deletions
diff --git a/examples/resources/lib/bitlib.lua b/examples/resources/lib/bitlib.lua
deleted file mode 100644
index 246ac29..0000000
--- a/examples/resources/lib/bitlib.lua
+++ /dev/null
@@ -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
diff --git a/examples/resources/lib/camera3d.lua b/examples/resources/lib/camera3d.lua
index 2c84b31..8c15fa7 100644
--- a/examples/resources/lib/camera3d.lua
+++ b/examples/resources/lib/camera3d.lua
@@ -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
diff --git a/examples/resources/lib/color.lua b/examples/resources/lib/color.lua
index 1a222e8..7c98e92 100644
--- a/examples/resources/lib/color.lua
+++ b/examples/resources/lib/color.lua
@@ -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
diff --git a/examples/resources/lib/quaternion.lua b/examples/resources/lib/quaternion.lua
index 47d6ee1..db700d8 100644
--- a/examples/resources/lib/quaternion.lua
+++ b/examples/resources/lib/quaternion.lua
@@ -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
diff --git a/examples/resources/lib/rectangle.lua b/examples/resources/lib/rectangle.lua
index a167939..7413f53 100644
--- a/examples/resources/lib/rectangle.lua
+++ b/examples/resources/lib/rectangle.lua
@@ -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
diff --git a/examples/resources/lib/utillib.lua b/examples/resources/lib/utillib.lua
index a661f60..4054006 100644
--- a/examples/resources/lib/utillib.lua
+++ b/examples/resources/lib/utillib.lua
@@ -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
diff --git a/examples/resources/lib/vector2.lua b/examples/resources/lib/vector2.lua
index c9c8433..68adc2b 100644
--- a/examples/resources/lib/vector2.lua
+++ b/examples/resources/lib/vector2.lua
@@ -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
diff --git a/examples/resources/lib/vector3.lua b/examples/resources/lib/vector3.lua
index 13f621c..86f5270 100644
--- a/examples/resources/lib/vector3.lua
+++ b/examples/resources/lib/vector3.lua
@@ -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