Problem with high load

My Breakout clone is once again puzzling me.

This is my main loop:

My problem is, that "wait until running" does not seem to work. When the program enters it first, everything is fine. But when the program leaves the "repeat until not running" loop and again comes to "wait until running" the browser (Firefox) produces a high load. When I open the URL "about:processes" I can see that the Snap tab eats 50% CPU. My expectation was that it should do nothing, because it should wait for a keyboard input.

What is wrong here?

Why not take everything out of the forever and put it under the when key pressed, and then deleting the running variable?

This would make it possible to start the game while it is running.

not necessarily. There should be an option in the settings labeled "thread-safe scripts".

Why do you expect that? It doesn't say
untitled script pic (2)
Instead it's checking the value of a variable. It has to keep checking, in case (as you in fact expect) some other script changes the variable's value.

Imho the surprising thing is that it works better the first time!

"wait" has usually blocking semantics. If waiting for a variable does not block, what else does block the execution. Is keyboard input the only way?

I changed it this way but it has no effect.


Although there is nothing running after the "say Oh NO!", the tab generates a high load.

The results of 10s of profiling are
profile

Silver brick has a "generic when", for every clone, 60 times a second.
Pixel perfect collision detection is quite resource intensive. For the Ball you use a much more effective strategy - first check the bounding box and/or the pixel perfect.
Breakout script pic

Well, actually, the FOR is still running. I don't know how big SPEED is, so I don't know how important that it. But maybe you want a CATCH/THROW to short-circuit that case.

And then, the REPEAT UNTIL is still running, although only the test part, not the WARP. It shouldn't use up the entire CPU, though; it should test once per clock tick, when it's that script's turn to run. I think.

Yes I am missing some kind of early exit feature. I have not found it. Does it exist?

?????
Breakout script pic (1)


Performance profile (Chrome@Win10) without Breakout script pic (2)

profile

:page_facing_up: > Libraries > Iteration, Composition
You drag the "tag" variable from the CATCH block into the THROW block.

This has been an interesting journey in what seemed at first to be a simple program :slight_smile:

i feel like the 50% cpu thing kinda got glossed over. the wait block only checks a variable once per frame. it really shouldn't be eating cpu like that? there's clearly still some kind of snap bug here.

Didn't I say that?

But am I not remembering that it doesn't happen for everyone?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.