Fix some issues in examples and favor vsync instead of fps locking.
This commit is contained in:
parent
83e4094cf6
commit
ada4f23d2b
@ -1,17 +1,15 @@
|
||||
setmetatable(_G, { __index = rl })
|
||||
|
||||
SetConfigFlags(FLAG_VSYNC_HINT)
|
||||
SetTargetFPS(60)
|
||||
|
||||
InitWindow(800, 450, "raylib [lua] example - global api")
|
||||
|
||||
while not WindowShouldClose() do
|
||||
BeginDrawing()
|
||||
|
||||
ClearBackground(RAYWHITE)
|
||||
DrawText("Global API !", 350, 200, 20, LIGHTGRAY)
|
||||
|
||||
EndDrawing()
|
||||
end
|
||||
|
||||
CloseWindow()
|
||||
setmetatable(_G, { __index = rl })
|
||||
|
||||
SetConfigFlags(FLAG_VSYNC_HINT)
|
||||
InitWindow(800, 450, "raylib [lua] example - global api")
|
||||
|
||||
while not WindowShouldClose() do
|
||||
BeginDrawing()
|
||||
|
||||
ClearBackground(RAYWHITE)
|
||||
DrawText("Global API !", 350, 200, 20, LIGHTGRAY)
|
||||
|
||||
EndDrawing()
|
||||
end
|
||||
|
||||
CloseWindow()
|
||||
|
@ -5,7 +5,7 @@ local screenHeight = 450
|
||||
|
||||
rl.SetConfigFlags(rl.FLAG_MSAA_4X_HINT)
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "Physac [raylib-lua] - Physics demo")
|
||||
rl.InitWindow(screenWidth, screenHeight, "Physac [raylua] - Physics demo")
|
||||
local logoX = screenWidth - rl.MeasureText("Physac", 30) - 10
|
||||
local logoY = 15
|
||||
|
||||
|
@ -1,11 +1,9 @@
|
||||
local ffi = require "ffi"
|
||||
local lua_color = ffi.new("Color", 3, 3, 128, 255)
|
||||
|
||||
rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
local width, height = 800, 450
|
||||
|
||||
rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)
|
||||
rl.InitWindow(800, 450, "raylib [shapes] example - basic shapes drawing")
|
||||
|
||||
while not rl.WindowShouldClose() do
|
||||
|
@ -1,112 +1,114 @@
|
||||
--------------------------------------------------------------------------------------------
|
||||
--
|
||||
-- raylib [textures] example - Bunnymark
|
||||
--
|
||||
-- This example has been created using raylib 1.6 (www.raylib.com)
|
||||
-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
--
|
||||
-- Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
||||
--
|
||||
--------------------------------------------------------------------------------------------
|
||||
local ffi = require "ffi"
|
||||
|
||||
local MAX_BUNNIES = 100000 -- 100K bunnies limit
|
||||
|
||||
-- This is the maximum amount of elements (quads) per batch
|
||||
-- NOTE: This value is defined in [rlgl] module and can be changed there
|
||||
local MAX_BATCH_ELEMENTS = 8192
|
||||
|
||||
-- Create the Bunny class.
|
||||
Bunny = {}
|
||||
Bunny.__index = Bunny
|
||||
function Bunny:new(pos, spd, col)
|
||||
local bunny = {}
|
||||
setmetatable(bunny,Bunny)
|
||||
bunny.position = pos
|
||||
bunny.speed = spd
|
||||
bunny.color = col
|
||||
return bunny
|
||||
end
|
||||
function Bunny:update(texture)
|
||||
self.position.x = self.position.x + self.speed.x
|
||||
self.position.y = self.position.y + self.speed.y
|
||||
if ((self.position.x + texture.width/2) > rl.GetScreenWidth()) or ((self.position.x + texture.width/2) < 0) then
|
||||
self.speed.x = self.speed.x * -1
|
||||
end
|
||||
if ((self.position.y + texture.height/2) > rl.GetScreenHeight()) or ((self.position.y + texture.height/2 - 40) < 0) then
|
||||
self.speed.y = self.speed.y * -1
|
||||
end
|
||||
end
|
||||
|
||||
-- Initialization
|
||||
--------------------------------------------------------------------------------------------
|
||||
--
|
||||
-- raylib [textures] example - Bunnymark
|
||||
--
|
||||
-- This example has been created using raylib 1.6 (www.raylib.com)
|
||||
-- raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
--
|
||||
-- Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
||||
--
|
||||
--------------------------------------------------------------------------------------------
|
||||
local ffi = require "ffi"
|
||||
local bit = require "bit"
|
||||
|
||||
local MAX_BUNNIES = 100000 -- 100K bunnies limit
|
||||
|
||||
-- This is the maximum amount of elements (quads) per batch
|
||||
-- NOTE: This value is defined in [rlgl] module and can be changed there
|
||||
local MAX_BATCH_ELEMENTS = 8192
|
||||
|
||||
-- Create the Bunny class.
|
||||
local Bunny = {}
|
||||
Bunny.__index = Bunny
|
||||
|
||||
function Bunny:new(pos, spd, col)
|
||||
local bunny = {}
|
||||
setmetatable(bunny,Bunny)
|
||||
bunny.position = pos
|
||||
bunny.speed = spd
|
||||
bunny.color = col
|
||||
return bunny
|
||||
end
|
||||
|
||||
function Bunny:update(texture)
|
||||
self.position.x = self.position.x + self.speed.x
|
||||
self.position.y = self.position.y + self.speed.y
|
||||
if ((self.position.x + texture.width/2) > rl.GetScreenWidth())
|
||||
or ((self.position.x + texture.width/2) < 0) then
|
||||
self.speed.x = self.speed.x * -1
|
||||
end
|
||||
if ((self.position.y + texture.height/2) > rl.GetScreenHeight())
|
||||
or ((self.position.y + texture.height/2 - 40) < 0) then
|
||||
self.speed.y = self.speed.y * -1
|
||||
end
|
||||
end
|
||||
|
||||
-- Initialization
|
||||
----------------------------------------------------------------------------------------
|
||||
local screenWidth = 800
|
||||
local screenHeight = 450
|
||||
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark")
|
||||
|
||||
-- Load bunny texture
|
||||
local texBunny = rl.LoadTexture("resources/wabbit_alpha.png")
|
||||
|
||||
local bunnies = {}
|
||||
|
||||
rl.SetTargetFPS(60) -- Set our game to run at 60 frames-per-second
|
||||
----------------------------------------------------------------------------------------
|
||||
|
||||
-- Main game loop
|
||||
while not rl.WindowShouldClose() do -- Detect window close button or ESC key
|
||||
-- Update
|
||||
------------------------------------------------------------------------------------
|
||||
if rl.IsMouseButtonDown(rl.MOUSE_LEFT_BUTTON) then
|
||||
-- Create more bunnies
|
||||
for i = 1, 100 do
|
||||
if #bunnies < MAX_BUNNIES then
|
||||
local speed = ffi.new("Vector2", rl.GetRandomValue(-250, 250) / 60, rl.GetRandomValue(-250, 250) / 60)
|
||||
local color = ffi.new("Color", rl.GetRandomValue(50, 240), rl.GetRandomValue(80, 240), rl.GetRandomValue(100, 240), 255)
|
||||
--bunnies[#bunnies] = Bunny:new(nil, GetMousePosition(), speed, color)
|
||||
table.insert(bunnies, Bunny:new(rl.GetMousePosition(), speed, color))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Update bunnies
|
||||
for i = 1, #bunnies do
|
||||
bunnies[i]:update(texBunny)
|
||||
end
|
||||
------------------------------------------------------------------------------------
|
||||
|
||||
-- Draw
|
||||
------------------------------------------------------------------------------------
|
||||
rl.BeginDrawing();
|
||||
|
||||
rl.ClearBackground(rl.RAYWHITE);
|
||||
|
||||
for i = 1, #bunnies do
|
||||
-- NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS),
|
||||
-- a draw call is launched and buffer starts being filled again;
|
||||
-- before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU...
|
||||
-- Process of sending data is costly and it could happen that GPU data has not been completely
|
||||
-- processed for drawing while new data is tried to be sent (updating current in-use buffers)
|
||||
-- it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies
|
||||
rl.DrawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, bunnies[i].color);
|
||||
end
|
||||
|
||||
rl.DrawRectangle(0, 0, screenWidth, 40, rl.BLACK)
|
||||
rl.DrawText("bunnies: " .. #bunnies, 120, 10, 20, rl.GREEN)
|
||||
rl.DrawText("batched draw calls: " .. math.ceil(1 + #bunnies / MAX_BATCH_ELEMENTS), 320, 10, 20, rl.MAROON)
|
||||
-- DrawText(FormatText("bunnies: %i", #bunnies), 120, 10, 20, GREEN)
|
||||
-- DrawText(FormatText("batched draw calls: %i", 1 + #bunnies/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON)
|
||||
|
||||
rl.DrawFPS(10, 10)
|
||||
|
||||
rl.EndDrawing()
|
||||
------------------------------------------------------------------------------------
|
||||
end
|
||||
|
||||
-- De-Initialization
|
||||
----------------------------------------------------------------------------------------
|
||||
|
||||
rl.UnloadTexture(texBunny) -- Unload bunny texture
|
||||
|
||||
rl.CloseWindow() -- Close window and OpenGL context
|
||||
----------------------------------------------------------------------------------------
|
||||
rl.SetConfigFlags(rl.FLAG_VSYNC_HINT)
|
||||
rl.InitWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark")
|
||||
|
||||
-- Load bunny texture
|
||||
local texBunny = rl.LoadTexture("resources/wabbit_alpha.png")
|
||||
|
||||
local bunnies = {}
|
||||
----------------------------------------------------------------------------------------
|
||||
|
||||
-- Main game loop
|
||||
while not rl.WindowShouldClose() do -- Detect window close button or ESC key
|
||||
-- Update
|
||||
------------------------------------------------------------------------------------
|
||||
if rl.IsMouseButtonDown(rl.MOUSE_LEFT_BUTTON) then
|
||||
-- Create more bunnies
|
||||
for i = 1, 100 do
|
||||
if #bunnies < MAX_BUNNIES then
|
||||
local speed = ffi.new("Vector2", rl.GetRandomValue(-250, 250) / 60, rl.GetRandomValue(-250, 250) / 60)
|
||||
local color = ffi.new("Color", rl.GetRandomValue(50, 240), rl.GetRandomValue(80, 240), rl.GetRandomValue(100, 240), 255)
|
||||
--bunnies[#bunnies] = Bunny:new(nil, GetMousePosition(), speed, color)
|
||||
table.insert(bunnies, Bunny:new(rl.GetMousePosition(), speed, color))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Update bunnies
|
||||
for i = 1, #bunnies do
|
||||
bunnies[i]:update(texBunny)
|
||||
end
|
||||
------------------------------------------------------------------------------------
|
||||
|
||||
-- Draw
|
||||
------------------------------------------------------------------------------------
|
||||
rl.BeginDrawing()
|
||||
|
||||
rl.ClearBackground(rl.RAYWHITE)
|
||||
|
||||
for i=1,#bunnies do
|
||||
-- NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS),
|
||||
-- a draw call is launched and buffer starts being filled again;
|
||||
-- before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU...
|
||||
-- Process of sending data is costly and it could happen that GPU data has not been completely
|
||||
-- processed for drawing while new data is tried to be sent (updating current in-use buffers)
|
||||
-- it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies
|
||||
rl.DrawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, bunnies[i].color);
|
||||
end
|
||||
|
||||
rl.DrawRectangle(0, 0, screenWidth, 40, rl.BLACK)
|
||||
rl.DrawText("bunnies: " .. #bunnies, 120, 10, 20, rl.GREEN)
|
||||
rl.DrawText("batched draw calls: " .. math.ceil(1 + #bunnies / MAX_BATCH_ELEMENTS), 320, 10, 20, rl.MAROON)
|
||||
|
||||
rl.DrawFPS(10, 10)
|
||||
|
||||
rl.EndDrawing()
|
||||
------------------------------------------------------------------------------------
|
||||
end
|
||||
|
||||
-- De-Initialization
|
||||
----------------------------------------------------------------------------------------
|
||||
|
||||
rl.UnloadTexture(texBunny) -- Unload bunny texture
|
||||
|
||||
rl.CloseWindow() -- Close window and OpenGL context
|
||||
----------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user