Object libraries like Vector2 optimizations.

This commit is contained in:
jussi
2024-04-17 00:35:58 +03:00
parent 41b6739824
commit 70b40f6782
31 changed files with 527 additions and 370 deletions

View File

@@ -7,6 +7,8 @@ KEY CHANGES:
- ADDED Automation events. - ADDED Automation events.
- CHANGE: Raygui lib callbacks to single table. - CHANGE: Raygui lib callbacks to single table.
- ADDED OpenGL Stencil management functions. - ADDED OpenGL Stencil management functions.
- CHANGE: Object libraries like Vector2 optimizations. Separated table argument style for new and set methods.
Option for pre generated temp objects. There was a lot of overhead on old new method.
DETAILED CHANGES: DETAILED CHANGES:
- ADDED: GetBufferElementSize and GetBufferLength. - ADDED: GetBufferElementSize and GetBufferLength.
@@ -40,6 +42,7 @@ DETAILED CHANGES:
- ADDED: Raygui lib examples file browser. - ADDED: Raygui lib examples file browser.
- CHANGE: Position argument added for GetCodepoint, GetCodepointNext and GetCodepointPrevious. - CHANGE: Position argument added for GetCodepoint, GetCodepointNext and GetCodepointPrevious.
- ADDED glEnable, glDisable, glGetString and glClear. - ADDED glEnable, glDisable, glGetString and glClear.
- ADDED Stencil reflection example.
------------------------------------------------------------------------ ------------------------------------------------------------------------
Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0 Release: ReiLua version 0.7.0 Using Raylib 5.0 and Forked Raygui 4.0

View File

@@ -15,8 +15,8 @@ local WALL_MESH_HEIGHT = math.tan( RL.DEG2RAD * ( 90 - SHADOW_FOV / 2 ) ) * LIGH
print( "WALL_MESH_HEIGHT", WALL_MESH_HEIGHT ) print( "WALL_MESH_HEIGHT", WALL_MESH_HEIGHT )
local monitor = 0 local monitor = 0
local monitorPos = Vector2:new( RL.GetMonitorPosition( monitor ) ) local monitorPos = Vector2:newT( RL.GetMonitorPosition( monitor ) )
local monitorSize = Vector2:new( RL.GetMonitorSize( monitor ) ) local monitorSize = Vector2:newT( RL.GetMonitorSize( monitor ) )
local winScale = 1 local winScale = 1
local winSize = Vector2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale ) local winSize = Vector2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale )
@@ -32,6 +32,10 @@ local shadowMesh = nil
local lights = {} local lights = {}
local camera = nil -- 3D camera for shadow rendering. local camera = nil -- 3D camera for shadow rendering.
local kissa = Color:new( 255, 255, 255 )
print( "Kissa", kissa )
-- Init. -- Init.
local function addLight( pos, color, radius ) local function addLight( pos, color, radius )
@@ -98,19 +102,19 @@ function RL.init()
lightRender = RL.LoadRenderTexture( { LIGHTRENDER_SIZE, LIGHTRENDER_SIZE } ) lightRender = RL.LoadRenderTexture( { LIGHTRENDER_SIZE, LIGHTRENDER_SIZE } )
tileTex = RL.LoadTexture( RL.GetBasePath().."../resources/images/tile.png" ) tileTex = RL.LoadTexture( RL.GetBasePath().."../resources/images/tile.png" )
lightTex = RL.LoadTexture( RL.GetBasePath().."../resources/images/light.png" ) lightTex = RL.LoadTexture( RL.GetBasePath().."../resources/images/light.png" )
lightTexSize = Vector2:new( RL.GetTextureSize( lightTex ) ) lightTexSize = Vector2:newT( RL.GetTextureSize( lightTex ) )
RL.SetTextureFilter( tileTex, RL.TEXTURE_FILTER_TRILINEAR ) RL.SetTextureFilter( tileTex, RL.TEXTURE_FILTER_TRILINEAR )
RL.SetTextureFilter( lightTex, RL.TEXTURE_FILTER_TRILINEAR ) RL.SetTextureFilter( lightTex, RL.TEXTURE_FILTER_TRILINEAR )
createShadowMesh() createShadowMesh()
addLight( Vector2:new( 230, 480 ), Color:new( RL.ORANGE ), 512 ) addLight( Vector2:new( 230, 480 ), Color:newT( RL.ORANGE ), 512 )
addLight( Vector2:new( 600, 200 ), Color:new( RL.RED ), 512 ) addLight( Vector2:new( 600, 200 ), Color:newT( RL.RED ), 512 )
addLight( Vector2:new( 384, 520 ), Color:new( RL.GREEN ), 400 ) addLight( Vector2:new( 384, 520 ), Color:newT( RL.GREEN ), 400 )
addLight( Vector2:new( 880, 750 ), Color:new( RL.BLUE ), 300 ) addLight( Vector2:new( 880, 750 ), Color:newT( RL.BLUE ), 300 )
addLight( Vector2:new( 800, 500 ), Color:new( RL.PURPLE ), 512 ) addLight( Vector2:new( 800, 500 ), Color:newT( RL.PURPLE ), 512 )
addLight( Vector2:new( 200, 760 ), Color:new( RL.WHITE ), 400 ) addLight( Vector2:new( 200, 760 ), Color:newT( RL.WHITE ), 400 )
-- Stress test -- Stress test
@@ -136,7 +140,7 @@ end
-- Update. -- Update.
function RL.update( delta ) function RL.update( delta )
lights[1].pos:set( RL.GetMousePosition() ) lights[1].pos:setT( RL.GetMousePosition() )
end end
-- Drawing. -- Drawing.

View File

@@ -20,7 +20,7 @@ function Calculator:new( pos )
padding = 10, padding = 10,
onClicked = function() onClicked = function()
object:set2Top() object:set2Top()
object.dragPos = Vec2:new( RL.GetMousePosition() ) - Vec2:new( object.handle.bounds.x, object.handle.bounds.y ) object.dragPos = Vec2:newT( RL.GetMousePosition() ) - Vec2:new( object.handle.bounds.x, object.handle.bounds.y )
Gui.heldCallback = function() object:drag() end Gui.heldCallback = function() object:drag() end
end, end,
} ) } )
@@ -30,7 +30,7 @@ function Calculator:new( pos )
texture = BgrTexture, texture = BgrTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:newT( RL.LIGHTGRAY ),
} ) ) } ) )
object.handle:add( Gui.texture:new( { object.handle:add( Gui.texture:new( {
@@ -38,7 +38,7 @@ function Calculator:new( pos )
texture = BorderTexture, texture = BorderTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:newT( RL.LIGHTGRAY ),
nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH }, nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH },
} ) ) } ) )
@@ -51,8 +51,8 @@ function Calculator:new( pos )
onClicked = function() onClicked = function()
object:setVisible( false ) object:setVisible( false )
end, end,
onMouseOver = function( self ) self.items[1].color = Color:new( RL.WHITE ) end, onMouseOver = function( this ) this.items[1].color = Color:newT( RL.WHITE ) end,
notMouseOver = function( self ) self.items[1].color = Color:new( RL.BLACK ) end, notMouseOver = function( this ) this.items[1].color = Color:newT( RL.BLACK ) end,
} ) } )
object.closeButton:add( Gui.texture:new( { object.closeButton:add( Gui.texture:new( {
@@ -73,7 +73,7 @@ function Calculator:new( pos )
texture = BgrTexture, texture = BgrTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.GRAY ), color = Color:newT( RL.GRAY ),
} ) ) } ) )
object.panel:add( Gui.texture:new( { object.panel:add( Gui.texture:new( {
@@ -81,7 +81,7 @@ function Calculator:new( pos )
texture = BorderTexture, texture = BorderTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:newT( RL.LIGHTGRAY ),
nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH }, nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH },
} ) ) } ) )
@@ -91,7 +91,7 @@ function Calculator:new( pos )
bounds = Rect:new( 0, 0, object.windowRect.width - 16, object.DISPLAY_HIGHT ), bounds = Rect:new( 0, 0, object.windowRect.width - 16, object.DISPLAY_HIGHT ),
padding = 10, padding = 10,
drawBounds = true, drawBounds = true,
color = Color:new( RL.WHITE ) color = Color:newT( RL.WHITE )
} ) } )
object.display:add( Gui.text:new( { text = "", fontSize = 30, VAling = Gui.ALING.CENTER, maxTextLen = 8 } ) ) object.display:add( Gui.text:new( { text = "", fontSize = 30, VAling = Gui.ALING.CENTER, maxTextLen = 8 } ) )
@@ -108,8 +108,8 @@ function Calculator:new( pos )
table.insert( object.buttons, Gui.element:new( { table.insert( object.buttons, Gui.element:new( {
bounds = Rect:new( 0, 0, 40, 32 ), bounds = Rect:new( 0, 0, 40, 32 ),
drawBounds = true, drawBounds = true,
onMouseOver = function( self ) self.color = Color:new( RL.WHITE ) end, onMouseOver = function( self ) self.color = Color:newT( RL.WHITE ) end,
notMouseOver = function( self ) self.color = Color:new( RL.LIGHTGRAY ) end, notMouseOver = function( self ) self.color = Color:newT( RL.LIGHTGRAY ) end,
} ) ) } ) )
object.buttons[ #object.buttons ].pos = Vec2:new( 8 + x * 46, object.HANDLE_HIGHT + object.DISPLAY_HIGHT + 16 + y * 38 ) object.buttons[ #object.buttons ].pos = Vec2:new( 8 + x * 46, object.HANDLE_HIGHT + object.DISPLAY_HIGHT + 16 + y * 38 )
@@ -161,7 +161,7 @@ function Calculator:setPosition( pos )
end end
function Calculator:drag() function Calculator:drag()
local mousePos = Vec2:new( RL.GetMousePosition() ) local mousePos = Vec2:newT( RL.GetMousePosition() )
local winPos = Vec2:new( self.handle.bounds.x, self.handle.bounds.y ) local winPos = Vec2:new( self.handle.bounds.x, self.handle.bounds.y )
self:setPosition( mousePos - self.dragPos ) self:setPosition( mousePos - self.dragPos )

View File

@@ -20,7 +20,7 @@ function FileExplorer:new( pos )
padding = 10, padding = 10,
onClicked = function() onClicked = function()
object:set2Top() object:set2Top()
object.dragPos = Vec2:new( RL.GetMousePosition() ) - Vec2:new( object.handle.bounds.x, object.handle.bounds.y ) object.dragPos = Vec2:newT( RL.GetMousePosition() ) - Vec2:new( object.handle.bounds.x, object.handle.bounds.y )
Gui.heldCallback = function() object:drag() end Gui.heldCallback = function() object:drag() end
end, end,
} ) } )
@@ -30,7 +30,7 @@ function FileExplorer:new( pos )
texture = BgrTexture, texture = BgrTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:newT( RL.LIGHTGRAY ),
} ) ) } ) )
object.handle:add( Gui.texture:new( { object.handle:add( Gui.texture:new( {
@@ -38,7 +38,7 @@ function FileExplorer:new( pos )
texture = BorderTexture, texture = BorderTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:newT( RL.LIGHTGRAY ),
nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH }, nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH },
} ) ) } ) )
@@ -51,8 +51,8 @@ function FileExplorer:new( pos )
onClicked = function() onClicked = function()
object:setVisible( false ) object:setVisible( false )
end, end,
onMouseOver = function( self ) self.items[1].color = Color:new( RL.WHITE ) end, onMouseOver = function( self ) self.items[1].color = Color:newT( RL.WHITE ) end,
notMouseOver = function( self ) self.items[1].color = Color:new( RL.BLACK ) end, notMouseOver = function( self ) self.items[1].color = Color:newT( RL.BLACK ) end,
} ) } )
object.closeButton:add( Gui.texture:new( { object.closeButton:add( Gui.texture:new( {
@@ -73,7 +73,7 @@ function FileExplorer:new( pos )
texture = BgrTexture, texture = BgrTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.GRAY ), color = Color:newT( RL.GRAY ),
} ) ) } ) )
object.panel:add( Gui.texture:new( { object.panel:add( Gui.texture:new( {
@@ -81,7 +81,7 @@ function FileExplorer:new( pos )
texture = BorderTexture, texture = BorderTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( RL.LIGHTGRAY ), color = Color:newT( RL.LIGHTGRAY ),
nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH }, nPatchInfo = { source = { 0, 0, 24, 24 }, left = 8, top = 8, right = 8, bottom = 8, layout = RL.NPATCH_NINE_PATCH },
} ) ) } ) )
@@ -90,7 +90,7 @@ function FileExplorer:new( pos )
object.pathBox = Gui.element:new( { object.pathBox = Gui.element:new( {
bounds = Rect:new( 0, 0, object.windowRect.width - 16 - 64, object.HANDLE_HIGHT ), bounds = Rect:new( 0, 0, object.windowRect.width - 16 - 64, object.HANDLE_HIGHT ),
drawBounds = true, drawBounds = true,
color = Color:new( RL.WHITE ), color = Color:newT( RL.WHITE ),
-- onClicked = function() Gui.setInputFocus( object.pathBox ) end, -- onClicked = function() Gui.setInputFocus( object.pathBox ) end,
-- inputFocus = function() object.pathBox.color = Color:new( BLUE ) end, -- inputFocus = function() object.pathBox.color = Color:new( BLUE ) end,
-- inputUnfocus = function() object.pathBox.color = Color:new( WHITE ) end, -- inputUnfocus = function() object.pathBox.color = Color:new( WHITE ) end,
@@ -103,8 +103,8 @@ function FileExplorer:new( pos )
object.backButton = Gui.element:new( { object.backButton = Gui.element:new( {
bounds = Rect:new( 0, 0, 56, object.HANDLE_HIGHT ), bounds = Rect:new( 0, 0, 56, object.HANDLE_HIGHT ),
drawBounds = true, drawBounds = true,
onMouseOver = function( self ) self.color = Color:new( RL.WHITE ) end, onMouseOver = function( self ) self.color = Color:newT( RL.WHITE ) end,
notMouseOver = function( self ) self.color = Color:new( RL.LIGHTGRAY ) end, notMouseOver = function( self ) self.color = Color:newT( RL.LIGHTGRAY ) end,
onClicked = function() object:backDir() end, onClicked = function() object:backDir() end,
} ) } )
@@ -112,7 +112,7 @@ function FileExplorer:new( pos )
bounds = Rect:new( 0, 0, object.HANDLE_HIGHT, object.HANDLE_HIGHT ), bounds = Rect:new( 0, 0, object.HANDLE_HIGHT, object.HANDLE_HIGHT ),
texture = BackTexture, texture = BackTexture,
HAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER,
color = Color:new( RL.BLACK ) color = Color:newT( RL.BLACK )
} ) ) } ) )
-- Files. -- Files.
@@ -130,7 +130,7 @@ function FileExplorer:new( pos )
object.fileName = Gui.element:new( { object.fileName = Gui.element:new( {
bounds = Rect:new( 0, 0, object.windowRect.width - 16 - 70, object.HANDLE_HIGHT ), bounds = Rect:new( 0, 0, object.windowRect.width - 16 - 70, object.HANDLE_HIGHT ),
drawBounds = true, drawBounds = true,
color = Color:new( RL.WHITE ), color = Color:newT( RL.WHITE ),
} ) } )
object.fileName:add( Gui.text:new( { text = "", maxTextLen = 32, allowLineBreak = false, VAling = Gui.ALING.CENTER } ) ) object.fileName:add( Gui.text:new( { text = "", maxTextLen = 32, allowLineBreak = false, VAling = Gui.ALING.CENTER } ) )
@@ -140,10 +140,10 @@ function FileExplorer:new( pos )
object.openButton = Gui.element:new( { object.openButton = Gui.element:new( {
bounds = Rect:new( 0, 0, 64, object.HANDLE_HIGHT ), bounds = Rect:new( 0, 0, 64, object.HANDLE_HIGHT ),
drawBounds = true, drawBounds = true,
color = Color:new( RL.WHITE ), color = Color:newT( RL.WHITE ),
onClicked = function() object:openFile() end, onClicked = function() object:openFile() end,
onMouseOver = function( self ) self.color = Color:new( RL.WHITE ) end, onMouseOver = function( self ) self.color = Color:newT( RL.WHITE ) end,
notMouseOver = function( self ) self.color = Color:new( RL.LIGHTGRAY ) end, notMouseOver = function( self ) self.color = Color:newT( RL.LIGHTGRAY ) end,
} ) } )
object.openButton:add( Gui.text:new( { text = "Open", VAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER } ) ) object.openButton:add( Gui.text:new( { text = "Open", VAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER } ) )
@@ -257,14 +257,14 @@ function FileExplorer:addFileToList( file, texture, color, func )
bounds = Rect:new( 0, 0, 20, 20 ), bounds = Rect:new( 0, 0, 20, 20 ),
texture = texture, texture = texture,
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
color = Color:new( color ), color = Color:newT( color ),
} ) ) } ) )
element.bounds.width = element.items[1].bounds.width + element.padding + element.items[2].bounds.width element.bounds.width = element.items[1].bounds.width + element.padding + element.items[2].bounds.width
end end
function FileExplorer:drag() function FileExplorer:drag()
local mousePos = Vec2:new( RL.GetMousePosition() ) local mousePos = Vec2:newT( RL.GetMousePosition() )
local winPos = Vec2:new( self.handle.bounds.x, self.handle.bounds.y ) local winPos = Vec2:new( self.handle.bounds.x, self.handle.bounds.y )
self:setPosition( mousePos - self.dragPos ) self:setPosition( mousePos - self.dragPos )

View File

@@ -51,8 +51,8 @@ local function initGui()
calculator:setVisible( true ) calculator:setVisible( true )
fileExplorer:setVisible( true ) fileExplorer:setVisible( true )
end, end,
onMouseOver = function( self ) self.color = Color:new( RL.LIGHTGRAY ) end, onMouseOver = function( self ) self.color = Color:newT( RL.LIGHTGRAY ) end,
notMouseOver = function( self ) self.color = Color:new( RL.GRAY ) end, notMouseOver = function( self ) self.color = Color:newT( RL.GRAY ) end,
} ) } )
showButton:add( Gui.text:new( { text = "Show", VAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER } ) ) showButton:add( Gui.text:new( { text = "Show", VAling = Gui.ALING.CENTER, HAling = Gui.ALING.CENTER } ) )
@@ -77,7 +77,7 @@ function RL.init()
end end
function RL.update( delta ) function RL.update( delta )
Gui.update( Vec2:new( RL.GetMousePosition() ) ) Gui.update( Vec2:newT( RL.GetMousePosition() ) )
end end
function RL.draw() function RL.draw()

View File

@@ -23,7 +23,7 @@ function RL.init()
end end
function RL.update( delta ) function RL.update( delta )
local moveDir = Vec2:new() local moveDir = Vec2:new( 0, 0 )
if RL.IsKeyDown( RL.KEY_RIGHT ) then if RL.IsKeyDown( RL.KEY_RIGHT ) then
moveDir.x = 1 moveDir.x = 1

View File

@@ -18,8 +18,8 @@ local shader = -1
local lights = {} local lights = {}
function RL.init() function RL.init()
local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local mSize = Vec2:new( RL.GetMonitorSize( monitor ) ) local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
local winSize = Vec2:new( 1028, 720 ) local winSize = Vec2:new( 1028, 720 )
RL.SetWindowTitle( "Simple Lighting" ) RL.SetWindowTitle( "Simple Lighting" )

View File

@@ -5,9 +5,9 @@ package.path = package.path..";"..RL.GetBasePath().."../resources/lib/?.lua"
Vec2 = require( "vector2" ) Vec2 = require( "vector2" )
local monitor = 0 local monitor = 0
local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local mSize = Vec2:new( RL.GetMonitorSize( monitor ) ) local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
local winSize = Vec2:new( RL.GetScreenSize() ) local winSize = Vec2:newT( RL.GetScreenSize() )
local polygon = { local polygon = {
texture = -1, texture = -1,
@@ -56,7 +56,7 @@ function RL.update( delta )
-- Update points rotation with an angle transform -- Update points rotation with an angle transform
-- NOTE: Base points position are not modified -- NOTE: Base points position are not modified
for i = 1, #polygon.points do for i = 1, #polygon.points do
polygon.positions[i] = Vec2:new( RL.Vector2Rotate( polygon.points[i], polygon.angle ) ) polygon.positions[i] = Vec2:newT( RL.Vector2Rotate( polygon.points[i], polygon.angle ) )
end end
end end

View File

@@ -10,8 +10,8 @@ local camera = {}
local targetVisible = false local targetVisible = false
function RL.init() function RL.init()
local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local mSize = Vec2:new( RL.GetMonitorSize( monitor ) ) local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
local winSize = Vec2:new( 1028, 720 ) local winSize = Vec2:new( 1028, 720 )
RL.SetWindowTitle( "Free Camera3D" ) RL.SetWindowTitle( "Free Camera3D" )

View File

@@ -21,7 +21,7 @@ function RL.init()
end end
function RL.update( delta ) function RL.update( delta )
local mousePosition = Vec2:new( RL.GetMousePosition() ) local mousePosition = Vec2:newT( RL.GetMousePosition() )
-- Resize the n-patch based on mouse position -- Resize the n-patch based on mouse position
dstRec.width = mousePosition.x - dstRec.x; dstRec.width = mousePosition.x - dstRec.x;

View File

@@ -81,8 +81,8 @@ local function createMap()
end end
function RL.init() function RL.init()
local monitorPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) local monitorPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local monitorSize = Vec2:new( RL.GetMonitorSize( monitor ) ) local monitorSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
RL.SetWindowTitle( "Platformer" ) RL.SetWindowTitle( "Platformer" )
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
@@ -223,7 +223,7 @@ end
function RL.update( delta ) function RL.update( delta )
if RL.IsWindowResized() then if RL.IsWindowResized() then
winSize:set( RL.GetScreenSize() ) winSize:setT( RL.GetScreenSize() )
end end
playerMovement( delta ) playerMovement( delta )

View File

@@ -54,8 +54,8 @@ end
function RL.init() function RL.init()
-- Set window to center of monitor. -- Set window to center of monitor.
local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local mSize = Vec2:new( RL.GetMonitorSize( monitor ) ) local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
RL.SetConfigFlags( RL.FLAG_VSYNC_HINT ) RL.SetConfigFlags( RL.FLAG_VSYNC_HINT )
RL.SetWindowSize( winSize ) RL.SetWindowSize( winSize )
@@ -125,6 +125,6 @@ function RL.draw()
-- Draw score. -- Draw score.
RL.DrawText( tostring( playerLeft.score ), { 50, 10 }, 40, RL.WHITE ) RL.DrawText( tostring( playerLeft.score ), { 50, 10 }, 40, RL.WHITE )
local rightTextSize = Vec2:new( RL.MeasureTextEx( RL.GetFontDefault(), tostring( playerRight.score ), 40, 2 ) ) local rightTextSize = Vec2:newT( RL.MeasureTextEx( RL.GetFontDefault(), tostring( playerRight.score ), 40, 2 ) )
RL.DrawText( tostring( playerRight.score ), { winSize.x - 50 - rightTextSize.x, 10 }, 40, RL.WHITE ) RL.DrawText( tostring( playerRight.score ), { winSize.x - 50 - rightTextSize.x, 10 }, 40, RL.WHITE )
end end

View File

@@ -26,8 +26,8 @@ end
function RL.init() function RL.init()
local monitor = 0 local monitor = 0
local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local mSize = Vec2:new( RL.GetMonitorSize( monitor ) ) local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
local winSize = Vec2:new( 1024, 800 ) local winSize = Vec2:new( 1024, 800 )
RL.SetWindowTitle( "Raygui examples" ) RL.SetWindowTitle( "Raygui examples" )

View File

@@ -19,11 +19,11 @@ local buttonTexture = nil
local winSize = Vec2:new( 1024, 720 ) local winSize = Vec2:new( 1024, 720 )
local cat = { local cat = {
texture = nil, texture = nil,
source = Rect:new(), source = Rect:new( 0, 0, 0, 0 ),
dest = Rect:new(), dest = Rect:new( 0, 0, 0, 0 ),
origin = Vec2:new(), origin = Vec2:new( 0, 0 ),
rotation = 0.0, rotation = 0.0,
tint = Color:new( RL.WHITE ), tint = Color:newT( RL.WHITE ),
visible = true, visible = true,
flipped = false flipped = false
} }
@@ -88,7 +88,7 @@ local function addPropertyList()
RL.GuiSetStyle( RL.SPINNER, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT ) RL.GuiSetStyle( RL.SPINNER, RL.TEXT_ALIGNMENT, RL.TEXT_ALIGN_LEFT )
PropertyList:addControl( PropertyList.gui:Line( PropertyList:addControl( PropertyList.gui:Line(
Rect:new(), Rect:new( 0, 0, 0, 0 ),
"Cat Texture" "Cat Texture"
) ) ) )
@@ -98,7 +98,7 @@ local function addPropertyList()
-- Position. -- Position.
PropertyList:addControl( PropertyList.gui:Label( PropertyList:addControl( PropertyList.gui:Label(
Rect:new(), Rect:new( 0, 0, 0, 0 ),
"Position:" "Position:"
), transformGroup ) ), transformGroup )
PropertyList:addControl( PropertyList.gui:TextBox( PropertyList:addControl( PropertyList.gui:TextBox(
@@ -133,7 +133,7 @@ local function addPropertyList()
), transformGroup ) ), transformGroup )
-- Origin. -- Origin.
PropertyList:addControl( PropertyList.gui:Label( PropertyList:addControl( PropertyList.gui:Label(
Rect:new(), Rect:new( 0, 0, 0, 0 ),
"Origin:" "Origin:"
), transformGroup ) ), transformGroup )
PropertyList:addControl( PropertyList.gui:TextBox( PropertyList:addControl( PropertyList.gui:TextBox(
@@ -219,19 +219,19 @@ local function addPropertyList()
PropertyList:addControl( PropertyList.gui:ColorPicker( PropertyList:addControl( PropertyList.gui:ColorPicker(
Rect:new( 0, 0, 128, 128 ), Rect:new( 0, 0, 128, 128 ),
"Color Picker", "Color Picker",
Color:new(), Color:new( 255, 255, 255, 255 ),
{ -- Callbacks. { -- Callbacks.
edit = function( self ) cat.tint = self.color end edit = function( self ) cat.tint = self.color end
} }
), tintGroup ) ), tintGroup )
PropertyList:addControl( PropertyList.gui:Line( PropertyList:addControl( PropertyList.gui:Line(
Rect:new(), Rect:new( 0, 0, 0, 0 ),
"Testing" "Testing"
) ) ) )
PropertyList:addControl( PropertyList.gui:DropdownBox( PropertyList:addControl( PropertyList.gui:DropdownBox(
Rect:new(), Rect:new( 0, 0, 0, 0 ),
"Dog\nGiraffe\nLion\nHorse", "Dog\nGiraffe\nLion\nHorse",
0, 0,
false, false,
@@ -298,8 +298,8 @@ end
function RL.init() function RL.init()
local monitor = 0 local monitor = 0
local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local mSize = Vec2:new( RL.GetMonitorSize( monitor ) ) local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowState( RL.FLAG_VSYNC_HINT )
@@ -312,7 +312,7 @@ function RL.init()
-- RL.GuiSetStyle( RL.SPINNER, RL.TEXT_PADDING, 2 ) -- RL.GuiSetStyle( RL.SPINNER, RL.TEXT_PADDING, 2 )
cat.texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/cat.png" ) cat.texture = RL.LoadTexture( RL.GetBasePath().."../resources/images/cat.png" )
local texSize = Vec2:new( RL.GetTextureSize( cat.texture ) ) local texSize = Vec2:newT( RL.GetTextureSize( cat.texture ) )
cat.source:set( 0, 0, texSize.x, texSize.y ) cat.source:set( 0, 0, texSize.x, texSize.y )
cat.dest = cat.source:clone() cat.dest = cat.source:clone()

View File

@@ -10,8 +10,8 @@ function PropertyList:new( bounds, text, callbacks, styles, tooltip )
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
object.scroll = Vec2:new() object.scroll = Vec2:new( 0, 0 )
object.view = Rect:new() object.view = Rect:new( 0, 0, 0, 0 )
object.callbacks = callbacks -- scroll, grab, drag. object.callbacks = callbacks -- scroll, grab, drag.
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -183,8 +183,8 @@ end
function PropertyList:draw() function PropertyList:draw()
local oldScroll = self.scroll:clone() local oldScroll = self.scroll:clone()
local _, scroll, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view ) local _, scroll, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
self.view:set( view ) self.view:setT( view )
self.scroll:set( scroll ) self.scroll:setT( scroll )
if self.scroll ~= oldScroll or self._forceCheckScroll then if self.scroll ~= oldScroll or self._forceCheckScroll then
if not self._forceCheckScroll then if not self._forceCheckScroll then
@@ -237,7 +237,7 @@ function PropertyList:setSize( size )
self.defaultControlSize = Vec2:new( self.content.width, self.defaultControlHeight ) self.defaultControlSize = Vec2:new( self.content.width, self.defaultControlHeight )
local _, _, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view ) local _, _, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
self.view = Rect:new( view ) self.view = Rect:newT( view )
self.gui.view = Rect:new( 0, 0, self.view.width, self.view.height ) self.gui.view = Rect:new( 0, 0, self.view.width, self.view.height )
self.framebufferSize = Vec2:new( self.bounds.width, self.bounds.height - self.gui.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT ) self.framebufferSize = Vec2:new( self.bounds.width, self.bounds.height - self.gui.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT )

View File

@@ -42,7 +42,7 @@ function TreeItem:setOpenIcon()
end end
function TreeItem:draw() function TreeItem:draw()
local buttonRect = Rect:new() local buttonRect = Rect:new( 0, 0, 0, 0 )
local hasContainer = 0 < #self.controls local hasContainer = 0 < #self.controls
local lineCol = RL.GetColor( RL.GuiGetStyle( RL.DEFAULT, RL.LINE_COLOR ) ) local lineCol = RL.GetColor( RL.GuiGetStyle( RL.DEFAULT, RL.LINE_COLOR ) )

View File

@@ -20,8 +20,8 @@ function TreeView:new( bounds, text, callbacks, styles, tooltip )
object.bounds = bounds:clone() object.bounds = bounds:clone()
object.text = text object.text = text
object.scroll = Vec2:new() object.scroll = Vec2:new( 0, 0 )
object.view = Rect:new() object.view = Rect:new( 0, 0, 0, 0 )
object.callbacks = callbacks -- select, grab, drag. object.callbacks = callbacks -- select, grab, drag.
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -269,7 +269,7 @@ function TreeView:itemSelect( item )
end end
function TreeView:update() function TreeView:update()
local mousePos = Vec2:new( RL.GetMousePosition() ) local mousePos = Vec2:newT( RL.GetMousePosition() )
local guiMousePos = mousePos + self.gui.mouseOffset local guiMousePos = mousePos + self.gui.mouseOffset
local mouseInView = self.view:checkCollisionPoint( mousePos ) local mouseInView = self.view:checkCollisionPoint( mousePos )
@@ -336,8 +336,8 @@ end
function TreeView:draw() function TreeView:draw()
local oldScroll = self.scroll:clone() local oldScroll = self.scroll:clone()
local _, scroll, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view ) local _, scroll, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
self.view:set( view ) self.view:setT( view )
self.scroll:set( scroll ) self.scroll:setT( scroll )
if self.scroll ~= oldScroll or self._forceCheckScroll then if self.scroll ~= oldScroll or self._forceCheckScroll then
if not self._forceCheckScroll then if not self._forceCheckScroll then
@@ -386,7 +386,7 @@ function TreeView:setSize( size )
self.defaultControlSize = Vec2:new( self.content.width, self.defaultControlHeight ) self.defaultControlSize = Vec2:new( self.content.width, self.defaultControlHeight )
local _, _, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view ) local _, _, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
self.view = Rect:new( view ) self.view = Rect:newT( view )
self.gui.view = Rect:new( 0, 0, self.view.width, self.view.height ) self.gui.view = Rect:new( 0, 0, self.view.width, self.view.height )
self.framebufferSize = Vec2:new( self.bounds.width, self.bounds.height - self.gui.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT ) self.framebufferSize = Vec2:new( self.bounds.width, self.bounds.height - self.gui.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT )

View File

@@ -323,13 +323,13 @@ function RL.init()
local colorpicker = Gui:ColorPicker( local colorpicker = Gui:ColorPicker(
Rect:new( 1500, 32, 128, 128 ), Rect:new( 1500, 32, 128, 128 ),
"Color Picker", "Color Picker",
Color:new(), Color:new( 255, 255, 255, 255 ),
{} -- Callbacks. {} -- Callbacks.
) )
local colorpanel = Gui:ColorPanel( local colorpanel = Gui:ColorPanel(
Rect:new( 1700, 32, 128, 128 ), Rect:new( 1700, 32, 128, 128 ),
"Color Panel", "Color Panel",
Color:new(), Color:new( 255, 255, 255, 255 ),
{} -- Callbacks. {} -- Callbacks.
) )
local colorbaralpha = Gui:ColorBarAlpha( local colorbaralpha = Gui:ColorBarAlpha(

View File

@@ -61,15 +61,15 @@ function Camera3D:setProjection( projection )
end end
function Camera3D:getPosition() function Camera3D:getPosition()
return Vec3:new( RL.GetCamera3DPosition( self.camera ) ) return Vec3:newT( RL.GetCamera3DPosition( self.camera ) )
end end
function Camera3D:getTarget() function Camera3D:getTarget()
return Vec3:new( RL.GetCamera3DTarget( self.camera ) ) return Vec3:newT( RL.GetCamera3DTarget( self.camera ) )
end end
function Camera3D:getUp() function Camera3D:getUp()
return Vec3:new( RL.GetCamera3DUp( self.camera ) ) return Vec3:newT( RL.GetCamera3DUp( self.camera ) )
end end
function Camera3D:getFoyv() function Camera3D:getFoyv()
@@ -82,18 +82,18 @@ end
--- Returns the cameras forward vector ( normalized ) --- Returns the cameras forward vector ( normalized )
function Camera3D:getForward() function Camera3D:getForward()
return Vec3:new( RL.GetCamera3DForward( self.camera ) ) return Vec3:newT( RL.GetCamera3DForward( self.camera ) )
end end
--- Returns the cameras up vector ( normalized ) Note: The up vector might not be perpendicular to the forward vector --- Returns the cameras up vector ( normalized ) Note: The up vector might not be perpendicular to the forward vector
function Camera3D:getUpward() function Camera3D:getUpward()
return Vec3:new( RL.GetCamera3DUpNormalized( self.camera ) ) return Vec3:newT( RL.GetCamera3DUpNormalized( self.camera ) )
end end
function Camera3D:update( delta ) function Camera3D:update( delta )
if self.mode == self.MODES.FREE then if self.mode == self.MODES.FREE then
if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_MIDDLE ) then if RL.IsMouseButtonDown( RL.MOUSE_BUTTON_MIDDLE ) then
local mouseDelta = Vec2:new( RL.GetMouseDelta() ) local mouseDelta = Vec2:newT( RL.GetMouseDelta() )
if RL.IsKeyDown( self.KEYS.PAN ) then if RL.IsKeyDown( self.KEYS.PAN ) then
mouseDelta = mouseDelta:scale( self.MOUSE_MOVE_SPEED * delta ) mouseDelta = mouseDelta:scale( self.MOUSE_MOVE_SPEED * delta )
@@ -116,13 +116,13 @@ function Camera3D:update( delta )
RL.Camera3DMoveToTarget( self.camera, self.ZOOM_AMOUNT * self:getTargetDistance() * -mouseScroll ) RL.Camera3DMoveToTarget( self.camera, self.ZOOM_AMOUNT * self:getTargetDistance() * -mouseScroll )
end end
elseif self.mode == self.MODES.FIRST_PERSON then elseif self.mode == self.MODES.FIRST_PERSON then
local mouseDelta = Vec2:new( RL.GetMouseDelta() ) local mouseDelta = Vec2:newT( RL.GetMouseDelta() )
mouseDelta = mouseDelta:scale( self.TURN_SPEED * delta ) mouseDelta = mouseDelta:scale( self.TURN_SPEED * delta )
RL.Camera3DYaw( self.camera, -mouseDelta.x, false ) RL.Camera3DYaw( self.camera, -mouseDelta.x, false )
RL.Camera3DPitch( self.camera, -mouseDelta.y, false, false, false ) RL.Camera3DPitch( self.camera, -mouseDelta.y, false, false, false )
RL.SetMousePosition( Vec2:new( RL.GetScreenSize() ):scale( 0.5 ) ) RL.SetMousePosition( Vec2:newT( RL.GetScreenSize() ):scale( 0.5 ) )
local distance = self.KEYBOARD_MOVE_SPEED * delta local distance = self.KEYBOARD_MOVE_SPEED * delta

View File

@@ -47,41 +47,33 @@ local metatable = {
} }
function Color:new( r, g, b, a ) function Color:new( r, g, b, a )
if type( r ) == "table" then
r, g, b, a = table.unpack( r )
elseif type( r ) == "nil" then
r, g, b, a = 0, 0, 0, 255
end
if a == nil then
a = 255
end
local object = setmetatable( {}, metatable ) local object = setmetatable( {}, metatable )
object.r = r object.r = r or 255
object.g = g object.g = g or 255
object.b = b object.b = b or 255
object.a = a object.a = a or 255
return object
end
function Color:newT( t )
local object = setmetatable( {}, metatable )
object.r, object.g, object.b, object.a = table.unpack( t )
return object return object
end end
function Color:set( r, g, b, a ) function Color:set( r, g, b, a )
if type( r ) == "table" then self.r = r or 255
r, g, b, a = table.unpack( r ) self.g = g or 255
elseif type( r ) == "nil" then self.b = b or 255
r, g, b, a = 0, 0, 0, 255 self.a = a or 255
end end
if a == nil then function Color:setT( t )
a = 255 self.r, self.g, self.b, self.a = table.unpack( t )
end
self.r = r
self.g = g
self.b = b
self.a = a
end end
function Color:arr() function Color:arr()
@@ -101,7 +93,7 @@ function Color:scale( scalar )
end end
function Color:fade( alpha ) function Color:fade( alpha )
return Color:new( RL.Fade( self, alpha ) ) return Color:newT( RL.Fade( self, alpha ) )
end end
function Color:toHex() function Color:toHex()
@@ -109,7 +101,7 @@ function Color:toHex()
end end
function Color:fromHex( hexValue ) function Color:fromHex( hexValue )
return Color:new( RL.GetColor( hexValue ) ) return Color:newT( RL.GetColor( hexValue ) )
end end
function Color:getNormalized() function Color:getNormalized()
@@ -117,31 +109,31 @@ function Color:getNormalized()
end end
function Color:fromNormalized( normalized ) function Color:fromNormalized( normalized )
return Color:new( RL.ColorFromNormalized( normalized ) ) return Color:newT( RL.ColorFromNormalized( normalized ) )
end end
function Color:toHSV() function Color:toHSV()
return Vector3:new( RL.ColorToHSV( self ) ) return Vector3:newT( RL.ColorToHSV( self ) )
end end
function Color:fromHSV( hue, saturation, value ) function Color:fromHSV( hue, saturation, value )
return Color:new( RL.ColorFromHSV( hue, saturation, value ) ) return Color:newT( RL.ColorFromHSV( hue, saturation, value ) )
end end
function Color:tint( tint ) function Color:tint( tint )
return Color:new( RL.ColorTint( self, tint ) ) return Color:newT( RL.ColorTint( self, tint ) )
end end
function Color:brightness( factor ) function Color:brightness( factor )
return Color:new( RL.ColorBrightness( self, factor ) ) return Color:newT( RL.ColorBrightness( self, factor ) )
end end
function Color:contrast( contrast ) function Color:contrast( contrast )
return Color:new( RL.ColorContrast( self, contrast ) ) return Color:newT( RL.ColorContrast( self, contrast ) )
end end
function Color:alphaBlend( dst, src, tint ) function Color:alphaBlend( dst, src, tint )
return Color:new( RL.ColorAlphaBlend( dst, src, tint ) ) return Color:newT( RL.ColorAlphaBlend( dst, src, tint ) )
end end
function Color:lerp( color, amount ) function Color:lerp( color, amount )
@@ -153,4 +145,47 @@ function Color:lerp( color, amount )
) )
end end
local TEMP_COUNT = 100
local tempPool = {}
local curTemp = 1
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
if TEMP_COUNT < curTemp then
curTemp = 1
end
object.r = r or 255
object.g = g or 255
object.b = b or 255
object.a = a or 255
return object
end
-- Uses pre generated objects to avoid "slow" table generation.
function Color:tempT( t )
local object = tempPool[ curTemp ]
curTemp = curTemp + 1
if TEMP_COUNT < curTemp then
curTemp = 1
end
object.r, object.g, object.b, object.a = table.unpack( t )
return object
end
function Color:getTempId()
return curTemp
end
return Color return Color

View File

@@ -224,7 +224,7 @@ function Text:new( set )
object.text = setProperty( set, "text", "" ) object.text = setProperty( set, "text", "" )
object.fontSize = setProperty( set, "fontSize", Gui.fontSize ) object.fontSize = setProperty( set, "fontSize", Gui.fontSize )
object.spacing = setProperty( set, "spacing", Gui.spacing ) object.spacing = setProperty( set, "spacing", Gui.spacing )
object.color = setProperty( set, "color", Color:new( RL.BLACK ) ) object.color = setProperty( set, "color", Color:newT( RL.BLACK ) )
object.maxTextLen = setProperty( set, "maxTextLen", nil ) object.maxTextLen = setProperty( set, "maxTextLen", nil )
object.allowLineBreak = setProperty( set, "allowLineBreak", false ) object.allowLineBreak = setProperty( set, "allowLineBreak", false )
@@ -243,7 +243,7 @@ function Text:set( text )
self.text = text self.text = text
end end
local textSize = Vec2:new( RL.MeasureTextEx( self.font, self.text, self.fontSize, self.spacing ) ) local textSize = Vec2:newT( RL.MeasureTextEx( self.font, self.text, self.fontSize, self.spacing ) )
self.bounds.width = textSize.x self.bounds.width = textSize.x
self.bounds.height = textSize.y self.bounds.height = textSize.y
@@ -273,7 +273,7 @@ function Texture:new( set )
object.source = setProperty( set, "source", Rect:new( 0, 0, 0, 0 ) ) object.source = setProperty( set, "source", Rect:new( 0, 0, 0, 0 ) )
object.origin = setProperty( set, "origin", Vec2:new( 0, 0 ) ) object.origin = setProperty( set, "origin", Vec2:new( 0, 0 ) )
object.rotation = setProperty( set, "rotation", 0 ) object.rotation = setProperty( set, "rotation", 0 )
object.color = setProperty( set, "color", Color:new( RL.WHITE ) ) object.color = setProperty( set, "color", Color:newT( RL.WHITE ) )
object.nPatchInfo = setProperty( set, "nPatchInfo", nil ) object.nPatchInfo = setProperty( set, "nPatchInfo", nil )
object.visible = setProperty( set, "visible", true ) object.visible = setProperty( set, "visible", true )
@@ -289,7 +289,7 @@ function Texture:set( texture )
return return
end end
local texSize = Vec2:new( RL.GetTextureSize( texture ) ) local texSize = Vec2:newT( RL.GetTextureSize( texture ) )
if self.bounds.width == 0 or self.bounds.height == 0 then if self.bounds.width == 0 or self.bounds.height == 0 then
self.bounds.width = texSize.x self.bounds.width = texSize.x
@@ -349,7 +349,7 @@ function Shape:new( set )
object.roundness = setProperty( set, "roundness", 1 ) object.roundness = setProperty( set, "roundness", 1 )
object.segments = setProperty( set, "segments", 4 ) object.segments = setProperty( set, "segments", 4 )
object.color = setProperty( set, "color", Color:new( RL.WHITE ) ) object.color = setProperty( set, "color", Color:newT( RL.WHITE ) )
object.visible = setProperty( set, "visible", true ) object.visible = setProperty( set, "visible", true )
object._parent = nil object._parent = nil
@@ -418,7 +418,7 @@ function Element:new( set )
object.visible = setProperty( set, "visible", true ) object.visible = setProperty( set, "visible", true )
object.disabled = setProperty( set, "disabled", false ) object.disabled = setProperty( set, "disabled", false )
object.drawBounds = setProperty( set, "drawBounds", false ) object.drawBounds = setProperty( set, "drawBounds", false )
object.color = setProperty( set, "color", Color:new( RL.GRAY ) ) object.color = setProperty( set, "color", Color:newT( RL.GRAY ) )
object.items = {} object.items = {}
@@ -488,7 +488,7 @@ function Element:draw()
local usedScissor = false local usedScissor = false
if self._visibilityBounds ~= nil then if self._visibilityBounds ~= nil then
local rect = Rect:new( RL.GetCollisionRec( self.bounds, self._visibilityBounds ) ) local rect = Rect:newT( RL.GetCollisionRec( self.bounds, self._visibilityBounds ) )
-- Use scissor mode only on partyally visible. -- Use scissor mode only on partyally visible.
if rect.width == 0 and rect.height == 0 then if rect.width == 0 and rect.height == 0 then
@@ -547,7 +547,7 @@ function Container:new( set )
object.showScrollbar = setProperty( set, "showScrollbar", false ) object.showScrollbar = setProperty( set, "showScrollbar", false )
object.scrollbarWidth = setProperty( set, "scrollbarWidth", Gui.scrollbarWidth ) object.scrollbarWidth = setProperty( set, "scrollbarWidth", Gui.scrollbarWidth )
object.scrollAmount = setProperty( set, "scrollAmount", Gui.scrollAmount ) -- When using mouse scroll. object.scrollAmount = setProperty( set, "scrollAmount", Gui.scrollAmount ) -- When using mouse scroll.
object.color = setProperty( set, "color", Color:new( RL.WHITE ) ) object.color = setProperty( set, "color", Color:newT( RL.WHITE ) )
object.drawBounds = setProperty( set, "drawBounds", false ) object.drawBounds = setProperty( set, "drawBounds", false )
object.drawScrollRect = setProperty( set, "drawScrollRect", false ) object.drawScrollRect = setProperty( set, "drawScrollRect", false )
-- For grid container. Do not set both. -- For grid container. Do not set both.
@@ -691,7 +691,7 @@ function Container:update()
self._VScrollbar = Element:new( { self._VScrollbar = Element:new( {
padding = 0, padding = 0,
drawBounds = true, drawBounds = true,
color = Color:new( RL.GRAY ), color = Color:newT( RL.GRAY ),
onClicked = function() Gui.heldCallback = function() self:mouseScroll( Vec2:new( 0, 1 ) ) end end, onClicked = function() Gui.heldCallback = function() self:mouseScroll( Vec2:new( 0, 1 ) ) end end,
} ) } )
@@ -700,7 +700,7 @@ function Container:update()
VAling = Gui.ALING.NONE, VAling = Gui.ALING.NONE,
bounds = Rect:new( 0, 0, 0, 0 ), bounds = Rect:new( 0, 0, 0, 0 ),
shape = Gui.SHAPE.RECTANGLE_ROUNDED, shape = Gui.SHAPE.RECTANGLE_ROUNDED,
color = Color:new( RL.LIGHTGRAY ), color = Color:newT( RL.LIGHTGRAY ),
} ) ) } ) )
end end
@@ -708,7 +708,7 @@ function Container:update()
self._HScrollbar = Element:new( { self._HScrollbar = Element:new( {
padding = 0, padding = 0,
drawBounds = true, drawBounds = true,
color = Color:new( RL.GRAY ), color = Color:newT( RL.GRAY ),
onClicked = function() Gui.heldCallback = function() self:mouseScroll( Vec2:new( 1, 0 ) ) end end, onClicked = function() Gui.heldCallback = function() self:mouseScroll( Vec2:new( 1, 0 ) ) end end,
} ) } )
@@ -717,7 +717,7 @@ function Container:update()
VAling = Gui.ALING.CENTER, VAling = Gui.ALING.CENTER,
bounds = Rect:new( 0, 0, 0, 0 ), bounds = Rect:new( 0, 0, 0, 0 ),
shape = Gui.SHAPE.RECTANGLE_ROUNDED, shape = Gui.SHAPE.RECTANGLE_ROUNDED,
color = Color:new( RL.LIGHTGRAY ), color = Color:newT( RL.LIGHTGRAY ),
} ) ) } ) )
end end
end end

View File

@@ -50,31 +50,15 @@ Matrix.meta = {
function Matrix:new( m ) function Matrix:new( m )
local object = setmetatable( {}, Matrix.meta ) local object = setmetatable( {}, Matrix.meta )
if type( m ) == "table" then
object.m = deepCopy( m ) object.m = deepCopy( m )
else
object.m = RL.MatrixIdentity()
end
return object return object
end end
function Matrix:set( m ) function Matrix:set( m )
if type( m ) == "table" then
self.m = deepCopy( m ) self.m = deepCopy( m )
else
self.m = RL.MatrixIdentity()
end
end end
-- function Matrix:arr()
-- return self.m
-- end
-- function Matrix:unpack()
-- return self.m
-- end
function Matrix:clone() function Matrix:clone()
return Matrix:new( self ) return Matrix:new( self )
end end

View File

@@ -13,19 +13,19 @@ local metatable = {
return "{"..tostring( q.x )..", "..tostring( q.y )..", "..tostring( q.z )..", "..tostring( q.w ).."}" return "{"..tostring( q.x )..", "..tostring( q.y )..", "..tostring( q.z )..", "..tostring( q.w ).."}"
end, end,
__add = function( q1, q2 ) __add = function( q1, q2 )
return Quaternion:new( RL.QuaternionAdd( q1, q2 ) ) return Quaternion:newT( RL.QuaternionAdd( q1, q2 ) )
end, end,
__sub = function( q1, q2 ) __sub = function( q1, q2 )
return Quaternion:new( RL.QuaternionSubtract( q1, q2 ) ) return Quaternion:newT( RL.QuaternionSubtract( q1, q2 ) )
end, end,
__mul = function( q1, q2 ) __mul = function( q1, q2 )
return Quaternion:new( RL.QuaternionMultiply( q1, q2 ) ) return Quaternion:newT( RL.QuaternionMultiply( q1, q2 ) )
end, end,
__div = function( q1, q2 ) __div = function( q1, q2 )
return Quaternion:new( RL.QuaternionDivide( q1, q2 ) ) return Quaternion:newT( RL.QuaternionDivide( q1, q2 ) )
end, end,
__unm = function( q ) __unm = function( q )
return Quaternion:new( RL.QuaternionInvert( q ) ) return Quaternion:newT( RL.QuaternionInvert( q ) )
end, end,
__len = function() __len = function()
return 4 return 4
@@ -39,33 +39,33 @@ local metatable = {
} }
function Quaternion:new( x, y, z, w ) function Quaternion:new( x, y, z, w )
if type( x ) == "table" then
x, y, z, w = table.unpack( x )
elseif type( x ) == "nil" then
x, y, z, w = 0, 0, 0, 1 -- QuaternionIdentity.
end
local object = setmetatable( {}, metatable ) local object = setmetatable( {}, metatable )
object.x = x object.x = x or 0
object.y = y object.y = y or 0
object.z = z object.z = z or 0
object.w = w object.w = w or 1
return object
end
function Quaternion:newT( t )
local object = setmetatable( {}, metatable )
object.x, object.y, object.z, object.w = table.unpack( t )
return object return object
end end
function Quaternion:set( x, y, z, w ) function Quaternion:set( x, y, z, w )
if type( x ) == "table" then self.x = x or 0
x, y, z, w = table.unpack( x ) self.y = y or 0
elseif type( x ) == "nil" then self.z = z or 0
x, y, z, w = 0, 0, 0, 1 -- QuaternionIdentity. self.w = w or 1
end end
self.x = x function Quaternion:setT( t )
self.y = y self.x, self.y, self.z, self.w = table.unpack( t )
self.z = z
self.w = w
end end
function Quaternion:arr() function Quaternion:arr()
@@ -81,15 +81,15 @@ function Quaternion:clone()
end end
function Quaternion:addValue( value ) function Quaternion:addValue( value )
return Quaternion:new( RL.QuaternionAddValue( self, value ) ) return Quaternion:newT( RL.QuaternionAddValue( self, value ) )
end end
function Quaternion:subValue( value ) function Quaternion:subValue( value )
return Quaternion:new( RL.QuaternionSubtractValue( self, value ) ) return Quaternion:newT( RL.QuaternionSubtractValue( self, value ) )
end end
function Quaternion:identity() function Quaternion:identity()
return Quaternion:new( RL.QuaternionIdentity() ) return Quaternion:newT( RL.QuaternionIdentity() )
end end
function Quaternion:length() function Quaternion:length()
@@ -97,88 +97,103 @@ function Quaternion:length()
end end
function Quaternion:normalize() function Quaternion:normalize()
return Quaternion:new( RL.QuaternionNormalize( self ) ) return Quaternion:newT( RL.QuaternionNormalize( self ) )
end end
function Quaternion:invert() function Quaternion:invert()
return Quaternion:new( RL.QuaternionInvert( self ) ) return Quaternion:newT( RL.QuaternionInvert( self ) )
end end
function Quaternion:scale( scalar ) function Quaternion:scale( scalar )
return Quaternion:new( RL.QuaternionScale( self, scalar ) ) return Quaternion:newT( RL.QuaternionScale( self, scalar ) )
end end
function Quaternion:lerp( q2, value ) function Quaternion:lerp( q2, value )
return Quaternion:new( RL.QuaternionLerp( self, q2, value ) ) return Quaternion:newT( RL.QuaternionLerp( self, q2, value ) )
end end
function Quaternion:nLerp( q2, value ) function Quaternion:nLerp( q2, value )
return Quaternion:new( RL.QuaternionNLerp( self, q2, value ) ) return Quaternion:newT( RL.QuaternionNLerp( self, q2, value ) )
end end
function Quaternion:sLerp( q2, value ) function Quaternion:sLerp( q2, value )
return Quaternion:new( RL.QuaternionSLerp( self, q2, value ) ) return Quaternion:newT( RL.QuaternionSLerp( self, q2, value ) )
end end
function Quaternion:fromVector3ToVector3( from, to ) function Quaternion:fromVector3ToVector3( from, to )
return Vector3:new( RL.QuaternionFromVector3ToVector3( from, to ) ) return Vector3:newT( RL.QuaternionFromVector3ToVector3( from, to ) )
end end
function Quaternion:fromMatrix( mat ) function Quaternion:fromMatrix( mat )
return Quaternion:new( RL.QuaternionFromMatrix( mat ) ) return Quaternion:newT( RL.QuaternionFromMatrix( mat ) )
end end
function Quaternion:toMatrix() function Quaternion:toMatrix()
return Matrix:new( RL.QuaternionToMatrix( self ) ) return Matrix:newT( RL.QuaternionToMatrix( self ) )
end end
function Quaternion:fromAxisAngle( axis, angle ) function Quaternion:fromAxisAngle( axis, angle )
return Quaternion:new( RL.QuaternionFromAxisAngle( axis, angle ) ) return Quaternion:newT( RL.QuaternionFromAxisAngle( axis, angle ) )
end end
function Quaternion:toAxisAngle() function Quaternion:toAxisAngle()
local axis, angle = Quaternion:new( RL.QuaternionToAxisAngle( self ) ) local axis, angle = Quaternion:newT( RL.QuaternionToAxisAngle( self ) )
return Vector3:new( axis ), angle return Vector3:new( axis ), angle
end end
function Quaternion:fromEuler( pitch, yaw, roll ) function Quaternion:fromEuler( pitch, yaw, roll )
return Quaternion:new( RL.QuaternionFromEuler( pitch, yaw, roll ) ) return Quaternion:newT( RL.QuaternionFromEuler( pitch, yaw, roll ) )
end end
function Quaternion:toEuler() function Quaternion:toEuler()
return Vector3:new( RL.QuaternionToEuler( self ) ) return Vector3:newT( RL.QuaternionToEuler( self ) )
end end
function Quaternion:transform( mat ) function Quaternion:transform( mat )
return Quaternion:new( RL.QuaternionTransform( self, mat ) ) return Quaternion:newT( RL.QuaternionTransform( self, mat ) )
end end
function Quaternion:addEq( q2 ) local TEMP_COUNT = 100
self.x = self.x + q2.x local tempPool = {}
self.y = self.y + q2.y local curTemp = 1
self.z = self.z + q2.z
self.w = self.w + q2.w for _ = 1, TEMP_COUNT do
table.insert( tempPool, Quaternion:new( 0, 0, 0, 1 ) )
end end
function Quaternion:subEq( q2 ) -- Uses pre generated objects to avoid "slow" table generation.
self.x = self.x - q2.x function Quaternion:temp( x, y, z, w )
self.y = self.y - q2.y local object = tempPool[ curTemp ]
self.z = self.z - q2.z curTemp = curTemp + 1
self.w = self.w - q2.w
if TEMP_COUNT < curTemp then
curTemp = 1
end
object.x = x or 0
object.y = y or 0
object.z = z or 0
object.w = w or 1
return object
end end
function Quaternion:mulEq( q2 ) -- Uses pre generated objects to avoid "slow" table generation.
self.x = self.x * q2.x function Quaternion:tempT( t )
self.y = self.y * q2.y local object = tempPool[ curTemp ]
self.z = self.z * q2.z curTemp = curTemp + 1
self.w = self.w * q2.w
if TEMP_COUNT < curTemp then
curTemp = 1
end
object.x, object.y, object.z, object.w = table.unpack( t )
return object
end end
function Quaternion:divEq( q2 ) function Quaternion:getTempId()
self.x = self.x / q2.x return curTemp
self.y = self.y / q2.y
self.z = self.z / q2.z
self.w = self.w / q2.w
end end
return Quaternion return Quaternion

View File

@@ -259,7 +259,7 @@ function ScrollPanel:new( bounds, text, content, scroll, callbacks, styles, tool
object.text = text object.text = text
object.content = content:clone() object.content = content:clone()
object.scroll = scroll:clone() object.scroll = scroll:clone()
object.view = Rect:new() object.view = Rect:new( 0, 0, 0, 0 )
object.callbacks = callbacks -- scroll, grab, drag. object.callbacks = callbacks -- scroll, grab, drag.
object.visible = true object.visible = true
@@ -278,8 +278,8 @@ end
function ScrollPanel:draw() function ScrollPanel:draw()
local oldScroll = self.scroll:clone() local oldScroll = self.scroll:clone()
local _, scroll, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view ) local _, scroll, view = RL.GuiScrollPanel( self.bounds, self.text, self.content, self.scroll, self.view )
self.view:set( view ) self.view:setT( view )
self.scroll:set( scroll ) self.scroll:setT( scroll )
if self.scroll ~= oldScroll then if self.scroll ~= oldScroll then
self._gui:checkScrolling() self._gui:checkScrolling()
@@ -581,10 +581,10 @@ function CheckBox:new( bounds, text, checked, callbacks, styles, tooltip )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.textBounds = Rect:new() object.textBounds = Rect:new( 0, 0, 0, 0 )
object.focusBounds = bounds:clone() object.focusBounds = bounds:clone()
object._focusBoundsOffset = Vec2:new() -- Used in set position. object._focusBoundsOffset = Vec2:new( 0, 0 ) -- Used in set position.
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -600,7 +600,7 @@ function CheckBox:draw()
local textBounds = nil local textBounds = nil
_, self.checked, textBounds = RL.GuiCheckBox( self.bounds, self.text, self.checked ) _, self.checked, textBounds = RL.GuiCheckBox( self.bounds, self.text, self.checked )
self.textBounds:set( textBounds ) self.textBounds:setT( textBounds )
self.focusBounds = self.bounds:fit( self.textBounds ) self.focusBounds = self.bounds:fit( self.textBounds )
self._focusBoundsOffset:set( self.focusBounds.x - self.bounds.x, self.focusBounds.y - self.bounds.y ) self._focusBoundsOffset:set( self.focusBounds.x - self.bounds.x, self.focusBounds.y - self.bounds.y )
@@ -758,10 +758,10 @@ function Spinner:new( bounds, text, value, minValue, maxValue, editMode, callbac
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.textBounds = Rect:new() object.textBounds = Rect:new( 0, 0, 0, 0 )
object.viewBounds = bounds:clone() object.viewBounds = bounds:clone()
object._viewBoundsOffset = Vec2:new() object._viewBoundsOffset = Vec2:new( 0, 0 )
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -782,7 +782,7 @@ function Spinner:draw()
local textBounds local textBounds
result, self.value, textBounds = RL.GuiSpinner( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode ) result, self.value, textBounds = RL.GuiSpinner( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode )
self.textBounds:set( textBounds ) self.textBounds:setT( textBounds )
self.viewBounds = self.bounds:fit( self.textBounds ) self.viewBounds = self.bounds:fit( self.textBounds )
self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y ) self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y )
@@ -829,10 +829,10 @@ function ValueBox:new( bounds, text, value, minValue, maxValue, editMode, callba
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.textBounds = Rect:new() object.textBounds = Rect:new( 0, 0, 0, 0 )
object.viewBounds = bounds:clone() object.viewBounds = bounds:clone()
object._viewBoundsOffset = Vec2:new() object._viewBoundsOffset = Vec2:new( 0, 0 )
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -853,7 +853,7 @@ function ValueBox:draw()
local textBounds local textBounds
result, self.value, textBounds = RL.GuiValueBox( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode ) result, self.value, textBounds = RL.GuiValueBox( self.bounds, self.text, self.value, self.minValue, self.maxValue, self.editMode )
self.textBounds:set( textBounds ) self.textBounds:setT( textBounds )
self.viewBounds = self.bounds:fit( self.textBounds ) self.viewBounds = self.bounds:fit( self.textBounds )
self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y ) self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y )
@@ -949,11 +949,11 @@ function Slider:new( bounds, textLeft, textRight, value, minValue, maxValue, cal
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.textLeftBounds = Rect:new() object.textLeftBounds = Rect:new( 0, 0, 0, 0 )
object.textRightBounds = Rect:new() object.textRightBounds = Rect:new( 0, 0, 0, 0 )
object.viewBounds = bounds:clone() object.viewBounds = bounds:clone()
object._viewBoundsOffset = Vec2:new() object._viewBoundsOffset = Vec2:new( 0, 0 )
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -968,8 +968,8 @@ function Slider:draw()
local oldValue, textLeftBounds, textRightBounds = self.value, nil, nil local oldValue, textLeftBounds, textRightBounds = self.value, nil, nil
_, self.value, textLeftBounds, textRightBounds = RL.GuiSlider( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue ) _, self.value, textLeftBounds, textRightBounds = RL.GuiSlider( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
self.textLeftBounds:set( textLeftBounds ) self.textLeftBounds:setT( textLeftBounds )
self.textRightBounds:set( textRightBounds ) self.textRightBounds:setT( textRightBounds )
self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds ) self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds )
self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y ) self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y )
@@ -1013,11 +1013,11 @@ function SliderBar:new( bounds, textLeft, textRight, value, minValue, maxValue,
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.textLeftBounds = Rect:new() object.textLeftBounds = Rect:new( 0, 0, 0, 0 )
object.textRightBounds = Rect:new() object.textRightBounds = Rect:new( 0, 0, 0, 0 )
object.viewBounds = bounds:clone() object.viewBounds = bounds:clone()
object._viewBoundsOffset = Vec2:new() object._viewBoundsOffset = Vec2:new( 0, 0 )
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -1032,8 +1032,8 @@ function SliderBar:draw()
local oldValue, textLeftBounds, textRightBounds = self.value, nil, nil local oldValue, textLeftBounds, textRightBounds = self.value, nil, nil
_, self.value, textLeftBounds, textRightBounds = RL.GuiSliderBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue ) _, self.value, textLeftBounds, textRightBounds = RL.GuiSliderBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
self.textLeftBounds:set( textLeftBounds ) self.textLeftBounds:setT( textLeftBounds )
self.textRightBounds:set( textRightBounds ) self.textRightBounds:setT( textRightBounds )
self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds ) self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds )
self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y ) self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y )
@@ -1077,11 +1077,11 @@ function ProgressBar:new( bounds, textLeft, textRight, value, minValue, maxValue
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.textLeftBounds = Rect:new() object.textLeftBounds = Rect:new( 0, 0, 0, 0 )
object.textRightBounds = Rect:new() object.textRightBounds = Rect:new( 0, 0, 0, 0 )
object.viewBounds = bounds:clone() object.viewBounds = bounds:clone()
object._viewBoundsOffset = Vec2:new() object._viewBoundsOffset = Vec2:new( 0, 0 )
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -1096,8 +1096,8 @@ function ProgressBar:draw()
local oldValue, textLeftBounds, textRightBounds = self.value, nil, nil local oldValue, textLeftBounds, textRightBounds = self.value, nil, nil
_, self.value, textLeftBounds, textRightBounds = RL.GuiProgressBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue ) _, self.value, textLeftBounds, textRightBounds = RL.GuiProgressBar( self.bounds, self.textLeft, self.textRight, self.value, self.minValue, self.maxValue )
self.textLeftBounds:set( textLeftBounds ) self.textLeftBounds:setT( textLeftBounds )
self.textRightBounds:set( textRightBounds ) self.textRightBounds:setT( textRightBounds )
self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds ) self.viewBounds = self.bounds:fit( self.textLeftBounds ):fit( self.textRightBounds )
self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y ) self._viewBoundsOffset:set( self.viewBounds.x - self.bounds.x, self.viewBounds.y - self.bounds.y )
@@ -1204,7 +1204,7 @@ function Grid:new( bounds, text, spacing, subdivs, callbacks, styles, tooltip )
object.subdivs = subdivs object.subdivs = subdivs
object.callbacks = callbacks -- cellChange. object.callbacks = callbacks -- cellChange.
object.mouseCell = Vec2:new() object.mouseCell = Vec2:new( 0, 0 )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.styles = styles object.styles = styles
@@ -1222,7 +1222,7 @@ function Grid:draw()
local mouseCell = {} local mouseCell = {}
_, mouseCell = RL.GuiGrid( self.bounds, self.text, self.spacing, self.subdivs, self.mouseCell ) _, mouseCell = RL.GuiGrid( self.bounds, self.text, self.spacing, self.subdivs, self.mouseCell )
self.mouseCell:set( mouseCell ) self.mouseCell:setT( mouseCell )
if oldCell ~= self.mouseCell and self.callbacks.cellChange ~= nil then if oldCell ~= self.mouseCell and self.callbacks.cellChange ~= nil then
self.callbacks.cellChange( self ) self.callbacks.cellChange( self )
@@ -1455,7 +1455,7 @@ function ColorPicker:new( bounds, text, color, callbacks, styles, tooltip )
object.visible = true object.visible = true
object.disabled = false object.disabled = false
object.focusBounds = Rect:new() object.focusBounds = Rect:new( 0, 0, 0, 0 )
object.styles = styles object.styles = styles
object.tooltip = tooltip object.tooltip = tooltip
@@ -1483,7 +1483,7 @@ function ColorPicker:draw()
local oldColor = self.color:clone() local oldColor = self.color:clone()
local _, color = RL.GuiColorPicker( self.bounds, self.text, self.color ) local _, color = RL.GuiColorPicker( self.bounds, self.text, self.color )
self.color = Color:new( color ) self.color = Color:newT( color )
if self.color ~= oldColor then if self.color ~= oldColor then
if not self._gui:clickedInBounds( self.focusBounds ) then if not self._gui:clickedInBounds( self.focusBounds ) then
@@ -1535,7 +1535,7 @@ function ColorPanel:draw()
local oldColor = self.color:clone() local oldColor = self.color:clone()
local _, color = RL.GuiColorPanel( self.bounds, self.text, self.color ) local _, color = RL.GuiColorPanel( self.bounds, self.text, self.color )
self.color = Color:new( color ) self.color = Color:newT( color )
if oldColor ~= self.color then if oldColor ~= self.color then
if not self._gui:clickedInBounds( self.bounds ) then if not self._gui:clickedInBounds( self.bounds ) then
@@ -1718,15 +1718,15 @@ function Raygui:new()
object.controls = {} object.controls = {}
object.focused = 0 object.focused = 0
object.dragging = nil object.dragging = nil
object.grabPos = Vec2:new() object.grabPos = Vec2:new( 0, 0 )
object.scrolling = false object.scrolling = false
object.textEdit = false object.textEdit = false
object.textEditControl = nil object.textEditControl = nil
object.defaultTexture = RL.GetTextureDefault() object.defaultTexture = RL.GetTextureDefault()
object.defaultRect = Rect:new( 0, 0, 1, 1 ) -- For texture. object.defaultRect = Rect:new( 0, 0, 1, 1 ) -- For texture.
object.defaultFont = RL.GuiGetFont() object.defaultFont = RL.GuiGetFont()
object.mouseOffset = Vec2:new() object.mouseOffset = Vec2:new( 0, 0 )
object.view = Rect:new() -- Active if larger than 0. Then only controls in view will be updated and drawn. object.view = Rect:new( 0, 0, 0, 0 ) -- Active if larger than 0. Then only controls in view will be updated and drawn.
object.tooltip = { object.tooltip = {
text = nil, text = nil,
offset = Vec2:new( 12, 24 ), offset = Vec2:new( 12, 24 ),
@@ -1759,7 +1759,7 @@ function Raygui:update()
RL.SetMouseOffset( self.mouseOffset ) RL.SetMouseOffset( self.mouseOffset )
if RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) then if RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) then
self._mousePressPos:set( RL.GetMousePosition() ) self._mousePressPos:setT( RL.GetMousePosition() )
end end
-- Focused is 0 if not over any control. -- Focused is 0 if not over any control.
self.focused = 0 self.focused = 0
@@ -1784,7 +1784,7 @@ function Raygui:update()
self.tooltip.timer = self.tooltip.timer + RL.GetFrameTime() self.tooltip.timer = self.tooltip.timer + RL.GetFrameTime()
else else
self.tooltip.text = control.tooltip self.tooltip.text = control.tooltip
self.tooltip.position = Vec2:new( RL.GetMousePosition() ) + self.tooltip.offset self.tooltip.position = Vec2:newT( RL.GetMousePosition() ) + self.tooltip.offset
end end
end end
@@ -1802,12 +1802,12 @@ function Raygui:update()
end end
function Raygui:drag( control ) function Raygui:drag( control )
local mousePos = Vec2:new( RL.GetMousePosition() ) local mousePos = Vec2:tempT( RL.GetMousePosition() )
local mouseOver = RL.CheckCollisionPointRec( mousePos, control.bounds ) local mouseOver = RL.CheckCollisionPointRec( mousePos, control.bounds )
if not control.disabled and control.draggable and control ~= self.dragging and RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT ) if not control.disabled and control.draggable and control ~= self.dragging and RL.IsMouseButtonPressed( RL.MOUSE_BUTTON_LEFT )
and mouseOver and mousePos.y - control.bounds.y <= self.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT then and mouseOver and mousePos.y - control.bounds.y <= self.RAYGUI_WINDOWBOX_STATUSBAR_HEIGHT then
self.grabPos = mousePos - Vec2:new( control.bounds.x, control.bounds.y ) self.grabPos = mousePos - Vec2:temp( control.bounds.x, control.bounds.y )
if control.callbacks.grab ~= nil then if control.callbacks.grab ~= nil then
control.callbacks.grab( control ) control.callbacks.grab( control )
@@ -1843,7 +1843,7 @@ function Raygui:_addLastProperty( property )
end end
function Raygui:drawTooltip() function Raygui:drawTooltip()
local textSize = Vec2:new( RL.MeasureTextEx( local textSize = Vec2:tempT( RL.MeasureTextEx(
self.defaultFont, self.defaultFont,
self.tooltip.text, self.tooltip.text,
RL.GuiGetStyle( RL.DEFAULT, RL.TEXT_SIZE ), RL.GuiGetStyle( RL.DEFAULT, RL.TEXT_SIZE ),
@@ -1853,7 +1853,7 @@ function Raygui:drawTooltip()
local view = self.view:clone() local view = self.view:clone()
-- If no view size, clamp to window size. -- If no view size, clamp to window size.
if view.width == 0 or view.height == 0 then if view.width == 0 or view.height == 0 then
local screenSize = Vec2:new( RL.GetScreenSize() ) local screenSize = Vec2:tempT( RL.GetScreenSize() )
view.width = screenSize.x view.width = screenSize.x
view.height = screenSize.y view.height = screenSize.y
end end
@@ -1922,6 +1922,7 @@ function Raygui:checkScrolling()
end end
function Raygui:clickedInBounds( bounds ) function Raygui:clickedInBounds( bounds )
print( self._mousePressPos, bounds )
return RL.CheckCollisionPointRec( self._mousePressPos, bounds ) return RL.CheckCollisionPointRec( self._mousePressPos, bounds )
end end

View File

@@ -44,33 +44,33 @@ Rectangle.meta = {
} }
function Rectangle:new( x, y, width, height ) function Rectangle:new( x, y, width, height )
if type( x ) == "table" then
x, y, width, height = table.unpack( x )
elseif type( x ) == "nil" then
x, y, width, height = 0, 0, 0, 0
end
local object = setmetatable( {}, Rectangle.meta ) local object = setmetatable( {}, Rectangle.meta )
object.x = x object.x = x or 0
object.y = y object.y = y or 0
object.width = width object.width = width or 0
object.height = height object.height = height or 0
return object
end
function Rectangle:newT( t )
local object = setmetatable( {}, Rectangle.meta )
object.x, object.y, object.width, object.height = table.unpack( t )
return object return object
end end
function Rectangle:set( x, y, width, height ) function Rectangle:set( x, y, width, height )
if type( x ) == "table" then self.x = x or 0
x, y, width, height = table.unpack( x ) self.y = y or 0
elseif type( x ) == "nil" then self.width = width or 0
x, y, width, height = 0, 0, 0, 0 self.height = height or 0
end end
self.x = x function Rectangle:setT( t )
self.y = y self.x, self.y, self.width, self.height = table.unpack( t )
self.width = width
self.height = height
end end
function Rectangle:arr() function Rectangle:arr()
@@ -153,4 +153,47 @@ function Rectangle:getCollisionRec( rec )
return Rectangle:new( RL.GetCollisionRec( self, rec ) ) return Rectangle:new( RL.GetCollisionRec( self, rec ) )
end end
local TEMP_COUNT = 100
local tempPool = {}
local curTemp = 1
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
if TEMP_COUNT < curTemp then
curTemp = 1
end
object.x = x or 0
object.y = y or 0
object.width = width or 0
object.height = height or 0
return object
end
-- Uses pre generated objects to avoid "slow" table generation.
function Rectangle:tempT( t )
local object = tempPool[ curTemp ]
curTemp = curTemp + 1
if TEMP_COUNT < curTemp then
curTemp = 1
end
object.x, object.y, object.width, object.height = table.unpack( t )
return object
end
function Rectangle:getTempId()
return curTemp
end
return Rectangle return Rectangle

View File

@@ -21,27 +21,15 @@ local metatable = {
} }
function Rune:new( string ) function Rune:new( string )
if type( string ) == "table" then
string = RL.LoadUTF8( string )
elseif type( string ) == "nil" then
string = ""
end
local object = setmetatable( {}, metatable ) local object = setmetatable( {}, metatable )
object.string = string object.string = string or ""
return object return object
end end
function Rune:set( string ) function Rune:set( string )
if type( string ) == "table" then self.string = string or ""
string = RL.LoadUTF8( string )
elseif type( string ) == "nil" then
string = ""
end
self.string = string
end end
function Rune:clone() function Rune:clone()
@@ -57,12 +45,12 @@ function Rune:getCodepoints()
end end
function Rune:getCodepoint( index ) function Rune:getCodepoint( index )
local codepoint = RL.GetCodepoint( self:sub( index, index ) ) local codepoint = RL.GetCodepoint( self.string, index )
return codepoint return codepoint
end end
function Rune:getCodepointSize( index ) function Rune:getCodepointSize( index )
local _, codepointSize = RL.GetCodepoint( self:sub( index, index ) ) local _, codepointSize = RL.GetCodepoint( self.string, index )
return codepointSize return codepointSize
end end

View File

@@ -11,6 +11,7 @@ local metatable = {
end, end,
__add = function( v1, v2 ) __add = function( v1, v2 )
return Vector2:new( v1.x + v2.x, v1.y + v2.y ) return Vector2:new( v1.x + v2.x, v1.y + v2.y )
-- return Vector2:newOld( v1.x + v2.x, v1.y + v2.y )
end, end,
__sub = function( v1, v2 ) __sub = function( v1, v2 )
return Vector2:new( v1.x - v2.x, v1.y - v2.y ) return Vector2:new( v1.x - v2.x, v1.y - v2.y )
@@ -42,27 +43,29 @@ local metatable = {
} }
function Vector2:new( x, y ) function Vector2:new( x, y )
if type( x ) == "table" then
x, y = table.unpack( x )
elseif type( x ) == "nil" then
x, y = 0, 0
end
local object = setmetatable( {}, metatable ) local object = setmetatable( {}, metatable )
object.x = x object.x = x or 0
object.y = y object.y = y or 0
return object
end
function Vector2:newT( t )
local object = setmetatable( {}, metatable )
object.x, object.y = table.unpack( t )
return object return object
end end
function Vector2:set( x, y ) function Vector2:set( x, y )
if type( x ) == "table" then self.x = x or 0
x, y = table.unpack( x ) self.y = y or 0
end end
self.x = x function Vector2:setT( t )
self.y = y self.x, self.y = table.unpack( t )
end end
function Vector2:arr() function Vector2:arr()
@@ -98,11 +101,11 @@ function Vector2:ceil()
end end
function Vector2:addValue( value ) function Vector2:addValue( value )
return Vector2:new( RL.Vector2AddValue( self, value ) ) return Vector2:newT( RL.Vector2AddValue( self, value ) )
end end
function Vector2:subValue( value ) function Vector2:subValue( value )
return Vector2:new( RL.Vector2SubtractValue( self, value ) ) return Vector2:newT( RL.Vector2SubtractValue( self, value ) )
end end
function Vector2:length() function Vector2:length()
@@ -138,43 +141,43 @@ function Vector2:atan2()
end end
function Vector2:scale( scale ) function Vector2:scale( scale )
return Vector2:new( RL.Vector2Scale( self, scale ) ) return Vector2:newT( RL.Vector2Scale( self, scale ) )
end end
function Vector2:normalize() function Vector2:normalize()
return Vector2:new( RL.Vector2Normalize( self ) ) return Vector2:newT( RL.Vector2Normalize( self ) )
end end
function Vector2:transform( mat ) function Vector2:transform( mat )
return Vector2:new( RL.Vector2Transform( self, mat ) ) return Vector2:newT( RL.Vector2Transform( self, mat ) )
end end
function Vector2:lerp( v2, value ) function Vector2:lerp( v2, value )
return Vector2:new( RL.Vector2Lerp( self, v2, value ) ) return Vector2:newT( RL.Vector2Lerp( self, v2, value ) )
end end
function Vector2:reflect( normal ) function Vector2:reflect( normal )
return Vector2:new( RL.Vector2Reflect( self, normal ) ) return Vector2:newT( RL.Vector2Reflect( self, normal ) )
end end
function Vector2:rotate( angle ) function Vector2:rotate( angle )
return Vector2:new( RL.Vector2Rotate( self, angle ) ) return Vector2:newT( RL.Vector2Rotate( self, angle ) )
end end
function Vector2:moveTowards( target, maxDistance ) function Vector2:moveTowards( target, maxDistance )
return Vector2:new( RL.Vector2MoveTowards( self, target, maxDistance ) ) return Vector2:newT( RL.Vector2MoveTowards( self, target, maxDistance ) )
end end
function Vector2:invert() function Vector2:invert()
return Vector2:new( RL.Vector2Invert( self ) ) return Vector2:newT( RL.Vector2Invert( self ) )
end end
function Vector2:clamp( min, max ) function Vector2:clamp( min, max )
return Vector2:new( RL.Vector2Clamp( self, min, max ) ) return Vector2:newT( RL.Vector2Clamp( self, min, max ) )
end end
function Vector2:clampValue( min, max ) function Vector2:clampValue( min, max )
return Vector2:new( RL.Vector2ClampValue( self, min, max ) ) return Vector2:newT( RL.Vector2ClampValue( self, min, max ) )
end end
function Vector2:equals( v2 ) function Vector2:equals( v2 )
@@ -201,4 +204,45 @@ function Vector2:divEq( v2 )
self.y = self.y / v2.y self.y = self.y / v2.y
end end
local TEMP_COUNT = 100
local tempPool = {}
local curTemp = 1
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
if TEMP_COUNT < curTemp then
curTemp = 1
end
object.x = x or 0
object.y = y or 0
return object
end
-- Uses pre generated objects to avoid "slow" table generation.
function Vector2:tempT( t )
local object = tempPool[ curTemp ]
curTemp = curTemp + 1
if TEMP_COUNT < curTemp then
curTemp = 1
end
object.x, object.y = table.unpack( t )
return object
end
function Vector2:getTempId()
return curTemp
end
return Vector2 return Vector2

View File

@@ -44,31 +44,31 @@ local metatable = {
} }
function Vector3:new( x, y, z ) function Vector3:new( x, y, z )
if type( x ) == "table" then
x, y, z = table.unpack( x )
elseif type( x ) == "nil" then
x, y, z = 0, 0, 0
end
local object = setmetatable( {}, metatable ) local object = setmetatable( {}, metatable )
object.x = x object.x = x or 0
object.y = y object.y = y or 0
object.z = z object.z = z or 0
return object
end
function Vector3:newT( t )
local object = setmetatable( {}, metatable )
object.x, object.y, object.z = table.unpack( t )
return object return object
end end
function Vector3:set( x, y, z ) function Vector3:set( x, y, z )
if type( x ) == "table" then self.x = x or 0
x, y, z = table.unpack( x ) self.y = y or 0
elseif type( x ) == "nil" then self.z = z or 0
x, y, z = 0, 0, 0 end
end
self.x = x function Vector3:setT( t )
self.y = y self.x, self.y, self.z = table.unpack( t )
self.z = z
end end
function Vector3:arr() function Vector3:arr()
@@ -100,11 +100,11 @@ function Vector3:abs()
end end
function Vector3:min( v2 ) function Vector3:min( v2 )
return Vector3:new( RL.Vector3Min( self, v2 ) ) return Vector3:newT( RL.Vector3Min( self, v2 ) )
end end
function Vector3:max( v2 ) function Vector3:max( v2 )
return Vector3:new( RL.Vector3Max( self, v2 ) ) return Vector3:newT( RL.Vector3Max( self, v2 ) )
end end
function Vector3:floor() function Vector3:floor()
@@ -116,23 +116,23 @@ function Vector3:ceil()
end end
function Vector3:addValue( value ) function Vector3:addValue( value )
return Vector3:new( RL.Vector3AddValue( self, value ) ) return Vector3:newT( RL.Vector3AddValue( self, value ) )
end end
function Vector3:subValue( value ) function Vector3:subValue( value )
return Vector3:new( RL.Vector3SubtractValue( self, value ) ) return Vector3:newT( RL.Vector3SubtractValue( self, value ) )
end end
function Vector3:scale( scalar ) function Vector3:scale( scalar )
return Vector3:new( RL.Vector3Scale( self, scalar ) ) return Vector3:newT( RL.Vector3Scale( self, scalar ) )
end end
function Vector3:cross( v2 ) function Vector3:cross( v2 )
return Vector3:new( RL.Vector3CrossProduct( self, v2 ) ) return Vector3:newT( RL.Vector3CrossProduct( self, v2 ) )
end end
function Vector3:perpendicular() function Vector3:perpendicular()
return Vector3:new( RL.Vector3Perpendicular( self ) ) return Vector3:newT( RL.Vector3Perpendicular( self ) )
end end
function Vector3:length() function Vector3:length()
@@ -160,11 +160,11 @@ function Vector3:angle( v2 )
end end
function Vector3:negate() function Vector3:negate()
return Vector3:new( RL.Vector3Negate( self ) ) return Vector3:newT( RL.Vector3Negate( self ) )
end end
function Vector3:normalize() function Vector3:normalize()
return Vector3:new( RL.Vector3Normalize( self ) ) return Vector3:newT( RL.Vector3Normalize( self ) )
end end
function Vector3:orthoNormalize( v2 ) function Vector3:orthoNormalize( v2 )
@@ -173,35 +173,35 @@ function Vector3:orthoNormalize( v2 )
end end
function Vector3:transform( mat ) function Vector3:transform( mat )
return Vector3:new( RL.Vector3Transform( self, mat ) ) return Vector3:newT( RL.Vector3Transform( self, mat ) )
end end
function Vector3:rotateByQuaternion( q ) function Vector3:rotateByQuaternion( q )
return Vector3:new( RL.Vector3RotateByQuaternion( self, q ) ) return Vector3:newT( RL.Vector3RotateByQuaternion( self, q ) )
end end
function Vector3:rotateByAxisAngle( axis, angle ) function Vector3:rotateByAxisAngle( axis, angle )
return Vector3:new( RL.Vector3RotateByAxisAngle( self, axis, angle ) ) return Vector3:newT( RL.Vector3RotateByAxisAngle( self, axis, angle ) )
end end
function Vector3:lerp( v2, value ) function Vector3:lerp( v2, value )
return Vector3:new( RL.Vector3Lerp( self, v2, value ) ) return Vector3:newT( RL.Vector3Lerp( self, v2, value ) )
end end
function Vector3:reflect( normal ) function Vector3:reflect( normal )
return Vector3:new( RL.Vector3Reflect( self, normal ) ) return Vector3:newT( RL.Vector3Reflect( self, normal ) )
end end
function Vector3:invert() function Vector3:invert()
return Vector3:new( RL.Vector3Invert( self ) ) return Vector3:newT( RL.Vector3Invert( self ) )
end end
function Vector3:clamp( min, max ) function Vector3:clamp( min, max )
return Vector3:new( RL.Vector3Clamp( self, min, max ) ) return Vector3:newT( RL.Vector3Clamp( self, min, max ) )
end end
function Vector3:clampValue( min, max ) function Vector3:clampValue( min, max )
return Vector3:new( RL.Vector3ClampValue( self, min, max ) ) return Vector3:newT( RL.Vector3ClampValue( self, min, max ) )
end end
function Vector3:equals( v2 ) function Vector3:equals( v2 )
@@ -232,4 +232,46 @@ function Vector3:divEq( v2 )
self.z = self.z / v2.z self.z = self.z / v2.z
end end
local TEMP_COUNT = 100
local tempPool = {}
local curTemp = 1
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
if TEMP_COUNT < curTemp then
curTemp = 1
end
object.x = x or 0
object.y = y or 0
object.z = z or 0
return object
end
-- Uses pre generated objects to avoid "slow" table generation.
function Vector3:tempT( t )
local object = tempPool[ curTemp ]
curTemp = curTemp + 1
if TEMP_COUNT < curTemp then
curTemp = 1
end
object.x, object.y, object.z = table.unpack( t )
return object
end
function Vector3:getTempId()
return curTemp
end
return Vector3 return Vector3

View File

@@ -12,7 +12,7 @@ local triangle = {
texture = { texture = {
id = -1, id = -1,
data = nil, data = nil,
size = Vec2:new(), size = Vec2:new( 0, 0 ),
mipmaps = 0, mipmaps = 0,
format = 0, format = 0,
}, },
@@ -60,7 +60,7 @@ local function loadTexture( path )
local image = RL.LoadImage( path ) local image = RL.LoadImage( path )
triangle.texture.data = RL.GetImageData( image ) triangle.texture.data = RL.GetImageData( image )
triangle.texture.size = Vec2:new( RL.GetImageSize( image ) ) triangle.texture.size = Vec2:newT( RL.GetImageSize( image ) )
triangle.texture.format = RL.GetImageFormat( image ) triangle.texture.format = RL.GetImageFormat( image )
triangle.texture.mipmaps = RL.GetImageMipmaps( image ) triangle.texture.mipmaps = RL.GetImageMipmaps( image )
@@ -131,8 +131,8 @@ local function createTriangle()
end end
function RL.init() function RL.init()
local monitorPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) local monitorPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local monitorSize = Vec2:new( RL.GetMonitorSize( monitor ) ) local monitorSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
RL.SetWindowTitle( "RLGL Hello Triangle" ) RL.SetWindowTitle( "RLGL Hello Triangle" )
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )

View File

@@ -13,8 +13,8 @@ local STATE = { TITLE = 0, GAME = 1, OVER = 2 } -- Enum.
-- Resources -- Resources
local framebuffer = nil local framebuffer = nil
local monitor = 0 local monitor = 0
local monitorPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) local monitorPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local monitorSize = Vec2:new( RL.GetMonitorSize( monitor ) ) local monitorSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
local winScale = 6 local winScale = 6
local winSize = Vec2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale ) local winSize = Vec2:new( RESOLUTION.x * winScale, RESOLUTION.y * winScale )
local gameState = STATE.GAME local gameState = STATE.GAME
@@ -248,6 +248,4 @@ function RL.draw()
0.0, 0.0,
RL.WHITE RL.WHITE
) )
RL.DrawFPS( { 20, 20 } )
end end

View File

@@ -13,9 +13,9 @@ function RL.init()
RL.SetWindowState( RL.FLAG_VSYNC_HINT ) RL.SetWindowState( RL.FLAG_VSYNC_HINT )
RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE ) RL.SetWindowState( RL.FLAG_WINDOW_RESIZABLE )
local mPos = Vec2:new( RL.GetMonitorPosition( monitor ) ) local mPos = Vec2:newT( RL.GetMonitorPosition( monitor ) )
local mSize = Vec2:new( RL.GetMonitorSize( monitor ) ) local mSize = Vec2:newT( RL.GetMonitorSize( monitor ) )
local winSize = Vec2:new( RL.GetScreenSize() ) local winSize = Vec2:newT( RL.GetScreenSize() )
RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } ) RL.SetWindowPosition( { mPos.x + mSize.x / 2 - winSize.x / 2, mPos.y + mSize.y / 2 - winSize.y / 2 } )