Flip and screen.waitVblankStart

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
JC
Posts: 16
Joined: Fri Jun 02, 2006 9:30 am

Flip and screen.waitVblankStart

Post by JC »

Hi Folks,

I have a question regarding how to use screen:flip() and screen.waitVblankStart(). From what I have read you should issue the screen.waitVblankStart() before you do a screen:flip() , to wait for the start of the vblank etc. So based on that the following should work:

Code: Select all

screen:print(10,10,"test",Color.new(255,255,255))

screen.waitVblankStart()
screen:flip()


pad = Controls.read()
while not pad:start() do
  pad = Controls.read()
end
but it doesn't display anything. However if I do the following it does work:

Code: Select all

screen:print(10,10,"test",Color.new(255,255,255))

screen:flip()
screen.waitVblankStart()

pad = Controls.read()
while not pad:start() do
  pad = Controls.read()
end
Why ? This behaviour does not seem to backup the definition of waitVblankStart. The only thing I can think is that if the text is not drawn by the time the code hits the do loop then the screen is effectively frozen while the do loop is executing. Can somebody shed some light on this for me ?

TIA,
JC
Kameku
Posts: 32
Joined: Thu Mar 23, 2006 12:17 pm
Location: Oregon, USA

Post by Kameku »

It's screen.flip()
JC
Posts: 16
Joined: Fri Jun 02, 2006 9:30 am

Post by JC »

Works the same with either screen.flip() or screen:flip()
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

The screen.waitVblankStart() waits until the screen refreshes so, when you call the function it waits until the screen refreshes before doing anything. You also dont need to use that function if you arent going to be refreshing the screen, example reactive scripts, do not require this since screen.waitVblankStart() slows it down, however

creating animations and things like that need to have screen.waitVblankStart() . If that makes sense
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: Flip and screen.waitVblankStart

Post by Shine »

I've tested this code:

Code: Select all

screen:print(10,10,"test",Color.new(255,255,255)) 

screen.flip() 
screen.waitVblankStart() 

pad = Controls.read() 
while not pad:start() do 
  pad = Controls.read() 
end
And it works, with Lua Player Windows, Lua Player 0.19 and even with the new Lua Player 0.20 with Lua 5.1 support (not yet released).
JC
Posts: 16
Joined: Fri Jun 02, 2006 9:30 am

Post by JC »

Thanks for the replies,

I am still cutting my first teeth with Lua and from reading some of the documentation it suggested that the waitVblankStart() should come before the flip (I see a lot of programs that use it this way). But from what you guys are saying it should always come after the flip, it that correct ?
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

JC wrote:from reading some of the documentation it suggested that the waitVblankStart() should come before the flip (I see a lot of programs that use it this way). But from what you guys are saying it should always come after the flip, it that correct ?
As romero126 said: You don't need it for your example.

But you should first wait for the vblank, then switch the buffers to avoid flickering and other effects. As I explained: You are drawing to the offscreen buffer (an image with the size of your PSP screen, but invisible) and with "flip" the offscreen buffer will be displayed. But the PSP re-displays the current buffer 60 times per second, line-by-line, so you have to wait for the vblank (this is the time when after the last line is displayed and before the displaying the first again) to avoid switching in the middle of the process. This is important for animations: Imagine you move something on the offscreen, but on the onscreen buffer it is in the old position. If you switch the buffer when the PSP has displayed the first half of the onscreen, then for the second half the offscreen is displayed and the upper half of your moving object may be some pixels behind the lower half.
JC
Posts: 16
Joined: Fri Jun 02, 2006 9:30 am

Post by JC »

Thanks,

I think I've got it now.

JC
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

lol shine i love your explinations their great. any idea when you could allow loading images and sounds from variables without saving them to a file?
imhotep
Posts: 41
Joined: Tue Dec 13, 2005 9:15 pm

Post by imhotep »

romero126 wrote:lol shine i love your explinations their great. any idea when you could allow loading images and sounds from variables without saving them to a file?
why would you want that? in most cases you need the images again.
and if you don't need them anymore, give all those images/sounds the name dummy_image(_sound) and so they're overwritten the next time
Post Reply