Log In  

Probably a silly question, but I can't seem to work it out.

I have a slow function - it takes more than 1/30 of second to execute but needs to be done in the _draw() function. This makes my code slow and unresponsive and it's clearly not the way to do it.

So what I want to do is the following:

  • run my slow function once in the _init() (drawing a bunch of stuff to the screen)
  • capture the screen to extended memory
  • in my _draw() function do repeated copies back to the screen

This works ... BUT ... when I run my slow function it shows on the screen (briefly, during _init() ). Probably because it overruns the 1/30 second _draw update time. I would rather suspend draw updates during _init().

So is there a way to suspend screen refreshing for a bit and then switch it back on?

P#106736 2022-02-11 22:39 ( Edited 2022-02-18 16:19)

2

You could try making a global flag and checking it. Something like this:

function _draw()
  if (draw_paused) then return end
  -- rest of the draw
end
P#106738 2022-02-11 23:38

@kimiyoribaka thanks! That is what I tried first, but it doesn't work (I think that whenever _init() runs longer than 1/30 second, PICO8 decides to do a screen update outside _draw ?)

But I'm looking into setting the sprite memeory as drawable, do my stuff there, store it in extended memory and do a reload to get my sprites back. Should work, right?

P#106781 2022-02-12 11:59

_init can run forever without calling draw.

function _init()
 while true do
 end
end

function _draw()
 -- never called
 assert(false)
end

Are you sure all the slow code is in init?

P#106783 2022-02-12 13:48

pico8 may skip calling _draw if _update takes too long to run.

P#106785 2022-02-12 14:02

@freds72 that's true - there's ways to circumvent calling _draw. But that doesn't stop PICO8 from doing a screen refresh I think. Any drawing to the screen in _init will still be shown. Even if _draw is doing nothing (or even missing from your code alltogether).
But I will investigate this a little further. Thanks for the comments so far!

P#106791 2022-02-12 19:11 ( Edited 2022-02-12 22:07)
1

yes, there are blits happening no matter what...
using the sprite sheet should work if you don't need pre-defined sprites.
you could also redefine the screen palette to blacks while you're initializing (pal(...,1)), just reset it at the end of _init()

(edit)
you can also use holdframe():

function _init()
 holdframe()
 print("wot")
 while not btnp(4) do end
end

function _draw()
?"done"
end
P#106805 2022-02-13 00:24 ( Edited 2022-02-13 01:33)
3

Actually I think @ultrabrite has it, @Miez. You just want the screen to stop appearing even though you are still drawing to it, even =IF= it's exceeded the 1/30th of a second timeout. That would make use of the seldom known function, holdframe()

:: Undocumented functions
-- From http://pico-8.wikia.com/wiki/Category:Undocumented_API
holdframe() forces display not to update until flip() is called
P#106815 2022-02-13 02:16 ( Edited 2022-02-13 02:33)

Absolutely brilliant suggestion @ultrabrite - that fixed it! This command needs some more attention :D

It would be nice if _init() had an optional parameter to switch updates on or off during its' execution. Ah well...

P#106830 2022-02-13 11:01

I don’t really understand that last line: there are no updates during init (_init runs once, then _update and _draw are called in the game loop). if you have long calculations to run before the game can start, then you could run them in a title screen or loading screen (with a function called from _update, or even using coroutines which are functions that can be paused and resumed with their local state intact), with _draw showing some simple loading bar and text!

P#106898 2022-02-14 14:38

@merwok - I think I didn't explain clearly. _init could perhaps do with a parameter to have SCREEN updates on or off during it's execution. It could be argued that screen updates should only be done in the _draw function, but that's clearly not the case.
It's no problem, only in very weird cases (such as mine, where I require an image to be made procedurally and stored without it showing on screen as it's being made).

P#106914 2022-02-14 18:41
1

@dw817 thx so much for holdframe()!!! I wasn't aware that page existed in the wiki and that function is exactly what I needed!

I'm making use of the new poke(0x5f55, 0) to do some work on the spritesheet during init, either at the root level before _init() is defined, or actually in _init(). The former will never flip to the screen, which makes sense; but the latter will, which also makes sense but might not be desired as in mine and OP's case. @zep, Sorry to tag/bother you with this, but since you're the only one who can answer, is holdframe() relatively safe from future deprecation? If not the function itself, will there always be some way or another to prevent a screen refresh, like setting a value in RAM?

P#107781 2022-02-27 22:21
1

@ridgekuhn you may be interested in this lovely article written by @replaycoding.

https://www.lexaloffle.com/bbs/?pid=58671

It is where I found the holdframe() command - and there are many other secrets revealed not yet listed in standard Pico-8 help files and documents.

Come one, learn all.

P#107783 2022-02-27 22:46

@dw817 thx! I've read it a couple times before but apparently need a refresher!

P#107789 2022-02-27 23:54

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 14:19:45 | 0.101s | Q:37