forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Flip and screen.waitVblankStart

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
JC



Joined: 02 Jun 2006
Posts: 16

PostPosted: Fri Jun 02, 2006 10:00 am    Post subject: Flip and screen.waitVblankStart Reply with quote

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:

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:

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
Back to top
View user's profile Send private message
Kameku



Joined: 23 Mar 2006
Posts: 32
Location: Oregon, USA

PostPosted: Fri Jun 02, 2006 3:07 pm    Post subject: Reply with quote

It's screen.flip()
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
JC



Joined: 02 Jun 2006
Posts: 16

PostPosted: Fri Jun 02, 2006 3:50 pm    Post subject: Reply with quote

Works the same with either screen.flip() or screen:flip()
Back to top
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Sat Jun 03, 2006 5:05 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sat Jun 03, 2006 8:05 am    Post subject: Re: Flip and screen.waitVblankStart Reply with quote

I've tested this code:

Code:

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).
Back to top
View user's profile Send private message
JC



Joined: 02 Jun 2006
Posts: 16

PostPosted: Sat Jun 03, 2006 9:14 am    Post subject: Reply with quote

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 ?
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Sat Jun 03, 2006 9:22 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
JC



Joined: 02 Jun 2006
Posts: 16

PostPosted: Sat Jun 03, 2006 10:23 am    Post subject: Reply with quote

Thanks,

I think I've got it now.

JC
Back to top
View user's profile Send private message
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Sat Jun 03, 2006 5:10 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
imhotep



Joined: 13 Dec 2005
Posts: 41

PostPosted: Sat Jun 10, 2006 11:23 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group