Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Function to return stats used by Slab #91

Closed
flamendless opened this issue Aug 2, 2021 · 1 comment
Closed

[Request] Function to return stats used by Slab #91

flamendless opened this issue Aug 2, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@flamendless
Copy link
Owner

This is useful for debugging, when users want to see the result of love.graphics.getStats() of their game without Slab stats mixing in the result (this happens when you draw the stats inside of a Slab window.

Usage would be (i think):

local stats = love.graphics.getStats()
local slab_stats = Slab.GetStats()
print(stats.drawcalls - slab_stats.drawcalls) --get the drawcalls stats without Slab mixed in
@flamendless flamendless added the enhancement New feature or request label Aug 21, 2021
@flamendless
Copy link
Owner Author

Here is an example of how to use this new feature:

function love.load(args)
	Slab.Initialize(args)
	Slab.EnableStats(true) --important
end

function love.update(dt)
	Slab.Update(dt)

	show = Slab.BeginWindow("test", {Title = "Test"})
	Slab.Text("test")
	Slab.Text("test")
	Slab.Text("test")
	Slab.Text("test")
	Slab.Text("test")
	Slab.Button("test")
	Slab.EndWindow()
end

local t = {}
function love.draw()

	--this will be not included in the Slab stats
	--any drawing called before Slab.draw call will not be included in the Slab stats
	love.graphics.print("test0", 256, 120)


	Slab.Draw()

	--get the stats used by Slab if you want to do anything with it
	--this will not include the printed "test0" earlier since it's outside of Slab (before Slab.Draw call)
	local d = Slab.GetStats()

	--draw more stuff (these are batched by love)
	--drawings after Slab.Draw are also not included in Slab stats
	love.graphics.print("test1", 256, 128)
	love.graphics.print("test2", 256, 134)
	love.graphics.print("test3", 256, 140)
	love.graphics.print("test4", 256, 146)

	--get the stats (this includes the Slab stats)
	t = love.graphics.getStats(t)

	--this will calculate the love stats (exclude Slab stats)
	t = Slab.CalculateStats(t)

	--draw to the screen to see the result
	local i = 0
	for k, v in pairs(t) do
		love.graphics.print(k .. " = " .. v, 32, i * 32)
		i = i + 1
	end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant