solar2d cpu/ram/resource monitoring/api tools?

I’m used to game engines having some kind of built-in cpu/ram/resource monitors. This is my list so far from scrounging across the docs:

–solar2D API

display.fps --won’t game just slowdown w/o changing this number if default locked 60fps? how to quantify slowdown?
display.currentStage.numChildren --ttl objects ingame
for k,v in pairs(_G) do prints(“key”,k,“value”,v) end --check what globals exist
display.setDrawMode() --toggle wireframe on/off for collision/etc tests

What else am I missing or supposed to be using? My understanding of the livebuilds feature is it’s for polishing across mobile platform differences (I’m on windows and just interested in web/desktop). The only thing I can think of is just the cpu/ram of the simulator listed under task manager…is that an effective metric to test the efficacy of 1 version of code/game vs another? And can I do it with the simulator instead of building? In pico8 I could easily test the performance differences between singular things like ‘which loop type runs faster’ or ‘what type of layering algorithm won’t useup half the cpu limits’. Lua optimization guides are always useful (I read the ones on the site, try ) but not enough. A lot of algorithms have very small margins as to when one is better than the other, requiring ram/cpu/resource stats to figureout.

The most pressing thing I want to test is the efficacy of a game outline using eventListeners vs Gameloop vs Gameloop+clearscreen. Any unmentioned ideas how to do that would be great.

For ease of use, you can take a look at the Spyric Performance library.

About testing in simulator vs device, many will advise to try your builds on device and not the simulator alone. There may be nuances that you can miss on the simulator vs on-device.

I didn’t understand what you are asking with the last paragraph. Can you elaborate?

The profiler plugin might be what you’re looking for

1 Like

In lua engines like love2d and pico8 you run a game via the gameloop madeup of reserved functions draw() and update(). Most games in those engines are made with function draw()cls()…end where all the objects drawn onscreen are in this function and clearscreen removes all drawn objects every frame. Update() optionally contains all the game logic aka stuff that has to run on-time. The engine can then drop frames from draw to optimize performance instead of slowing down the entire game.
Solar2d doesn’t have those presets but lets u build a clearsceen function and build as many gameloops as u want. It also has just event listeners u can call to handle things in a more node based way I guess. Given I can use either of those 3 methods in solar2d, I don’t know what one to use to build a game with. You can partially mix them, but the core of the game needs to be built via one. So I thought to choose based on what runs best and what is easier to work in. So I need a way to gauge how an example of 1 runs vs the other two.

I also don’t really get if there is way to directly recreate the update/draw gameloop relationship of pico8 and love2d in solar2d. If there was some kind of value I could take…like cpu…then I could setup a block like:
function drawUpdateLoop()
–…update logic here runs every frame…
if cpu>0.5 and timer%30==0 then
… --run draw logic twice a second assuming 60fps
else
…–run draw logic 60 times a second
end

Or divide it into two loops or whatever. Just the key is having that cpu value.

I’m not really sure if I understand it correctly but delta time might help with what you’re trying to achieve in the second part. If so, Scrappy Time or Delta Time.

How to structure your game logic really depends on you. I can only suggest looking at some of the open sourced projects in awesome-solar2d list. For example, I chose to stay away from the game loop in my trivia game OpenBilgi since there was no need to constantly check some value or anything. Solar2D was drawing the screen 30-60 times a second and I was only triggering events as player interacts.

For my shooter game, which is not open source yet, I stick strictly to the game loop + events(for firing bullets) since I need to move the enemies, check collisions etc. in every/most frame.

Since you seem worried about the performance, I assume you’re trying to build an action-heavy game in which you need to check states and positions of your game elements. If that’s the case, I’d suggest using the second approach where you mix the game loop with events.

Please do take a look at the list I posted above. There are games from different genres. I believe those can give you a better idea before you choose how to structure your game logic.

How exactly are you intended to use the profiler.lua file? I followed the instructions on the page but it’s not recognizing the function call. I don’t get what that function call is supposed to produce or where its supposed to be put (call it a million times…call it once…what?) Does the entire zip have to go into the game folder or just the profiler.lua file?I tried both, neither doing it.

"Add the following to your build.settings"
I added this and it did a weird load bar I didn’t understand for a second then it was gone. What does this do?

{
    plugins = {
        ["plugin.profiler"] = {
            publisherId = "com.solar2d",
        },
    },
}

Where does the profile.lua file go? I tried both locations. I tried requring"profile.lua" i tried it without that as well and just the require “plugin.profiler” after putting the cmd in build settings. In my scene I call the following (I tried commenting them out and pairing them in every way but no luck) but profiler always returns a nil runtime error.


require"profiler"
local myPlugin = require( "plugin.profiler" )
myPlugin.myProfiler = profiler.new({frames = display.fps, colour1 = {1,0,0}, colour2 = {0,1,0}, colour3 = {0,0,1}, alpha = 0.6})
myProfiler = profiler.new({frames = display.fps, colour1 = {1,0,0}, colour2 = {0,1,0}, colour3 = {0,0,1}, alpha = 0.6})

attempt to index global ‘profiler’ (a nil value)…it doesn’t read its existance