Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Jun 29, 2017 10:59 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Properly drawing to canvas with double buffering
PostPosted: Fri Aug 12, 2011 1:19 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Since you're using the same image for all the canvases, it's no surprise that they all eventually show the same image. You have NO control over when a canvas might refresh, although OS X may give you the illusion that you do. Use a separate picture object for each canvas.


Top
 Profile  
Reply with quote  
 Post subject: Re: Properly drawing to canvas with double buffering
PostPosted: Fri Aug 12, 2011 5:07 am 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
You can download the sample project here: http://dl.dropbox.com/u/3800071/RS%20Projects.zip

Pixe

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
 Post subject: Re: Properly drawing to canvas with double buffering
PostPosted: Fri Aug 12, 2011 12:13 pm 
Offline

Joined: Wed Nov 30, 2005 8:22 pm
Posts: 227
Location: L.I., New York
Thanks for the test project, however Windows is still screwing up with the canvases that are not being refreshed. I guess I'll have to store each image in a separate variable.

Now if I can just get Windows to stop turning the canvas background of the canvas with DoubleBuffer true to white.

Why is Windows not keeping the Time event consistent? I have a high end PC and the Timer is quite jerky.


Top
 Profile  
Reply with quote  
 Post subject: Re: Properly drawing to canvas with double buffering
PostPosted: Fri Aug 12, 2011 3:29 pm 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
ccfman2004 wrote:
however Windows is still screwing up with the canvases that are not being refreshed.

Do you see that screwy behavior also in the test project? What is it exactly that you are observing?

ccfman2004 wrote:
I guess I'll have to store each image in a separate variable.

Tim already told you that. If you don't, your code will be wrong. Your code can only work if after each refresh call the refreshed canvas is redrawn before the temporary picture is changed for the next canvas. As you have experienced, it is not working like that on Windows.

ccfman2004 wrote:
Now if I can just get Windows to stop turning the canvas background of the canvas with DoubleBuffer true to white.

As I said before, I can't help you with that. Have you tried to search the forum for an answer? I would think that this issue should be common. Or, have you tried to look for a related bug in the feedback system?

ccfman2004 wrote:
Why is Windows not keeping the Time event consistent? I have a high end PC and the Timer is quite jerky.

The timer fires when two things happen: First, the period set by you must have passed since the last time "it fired", and second, the system/process/thread looks into the timer to see if it requires any attention. So, even when the period time has passed, the timer waits for other events to finish before it can act. The latency should be short, anyway.

What is the period you are using? I am not very experienced with timers, but I would say it is not easy to notice the lack of regularity a timer will show. Maybe the timer is not to be blamed for the irregularities you are observing?

Pixe

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
 Post subject: Re: Properly drawing to canvas with double buffering
PostPosted: Fri Aug 12, 2011 4:56 pm 
Offline

Joined: Wed Nov 30, 2005 8:22 pm
Posts: 227
Location: L.I., New York
pixe656 wrote:
ccfman2004 wrote:
however Windows is still screwing up with the canvases that are not being refreshed.

Do you see that screwy behavior also in the test project? What is it exactly that you are observing?

ccfman2004 wrote:
I guess I'll have to store each image in a separate variable.

Tim already told you that. If you don't, your code will be wrong. Your code can only work if after each refresh call the refreshed canvas is redrawn before the temporary picture is changed for the next canvas. As you have experienced, it is not working like that on Windows.

ccfman2004 wrote:
Now if I can just get Windows to stop turning the canvas background of the canvas with DoubleBuffer true to white.

As I said before, I can't help you with that. Have you tried to search the forum for an answer? I would think that this issue should be common. Or, have you tried to look for a related bug in the feedback system?

ccfman2004 wrote:
Why is Windows not keeping the Time event consistent? I have a high end PC and the Timer is quite jerky.

The timer fires when two things happen: First, the period set by you must have passed since the last time "it fired", and second, the system/process/thread looks into the timer to see if it requires any attention. So, even when the period time has passed, the timer waits for other events to finish before it can act. The latency should be short, anyway.

What is the period you are using? I am not very experienced with timers, but I would say it is not easy to notice the lack of regularity a timer will show. Maybe the timer is not to be blamed for the irregularities you are observing?

Pixe


In your test project, sometimes the other canvases will display the minus sign instead of the original plus sign. (I guess that is related to using the same temp pic variable.)

With regard to the jerky timer, I was talking about the timer in your test project. It is not consistent at all. It works fine on my Mac but is quite random on Windows. It is not a steady plus/minus at all.

Wow this is weird. I tried the test project again and it is not displaying those issues again. The only difference between then and now was a system reboot when my Anti-Spyware updated itself. Windows is so unpredictable.

I let the Mac version of the code (without the array changes) run for several hours and it still displays the canvases properly. I guess it's all part of the process of working on a cross-platform game.

Thanks, for all of your help.

Now to tackle that DoubleBuffer issue in Windows.


Top
 Profile  
Reply with quote  
 Post subject: Re: Properly drawing to canvas with double buffering
PostPosted: Sat Aug 13, 2011 1:35 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Im late to this party, but here is some advice

Add a property to the window, called

bBlink as boolean

This is to hold a flag saying whether the eyes should look left or right

In the timer code:

bBlink = not blink
imgCanvas(2).invalidate(false) //suggest a refresh occurs


In the ImgCanvas Paint event, change the code to say this:
(I do not know why you mirror every picture: if you need them the other way around, store them that way??


dim p as picture
select case index
case 0
p = PNGStringToPictureMBS(DecodeBase64(rs.Field("Pic0")),0)
g.drawpicture p,0,0
case 1
p = PNGStringToPictureMBS(DecodeBase64(rs.Field("Pic1")),0)
g.drawpicture p,0,0
case 2

//check blink and show different pictures according to its state
p = PNGStringToPictureMBS(DecodeBase64(rs.Field("Pic2")),0)
if bblink then
p = p.HMirrorMBS
else
p = PNGStringToPictureMBS(DecodeBase64(rs.Field("Blinked")),0)
end if
g.drawpicture p,0,0

case 3
p = PNGStringToPictureMBS(DecodeBase64(rs.Field("Pic3")),0)
g.drawpicture p,0,0
case 4
p = PNGStringToPictureMBS(DecodeBase64(rs.Field("Pic4")),0)
g.drawpicture p,0,0
case 5
p = PNGStringToPictureMBS(DecodeBase64(rs.Field("Pic5")),0)
g.drawpicture p,0,0
end select


Top
 Profile  
Reply with quote  
 Post subject: Re: Properly drawing to canvas with double buffering
PostPosted: Sat Aug 13, 2011 4:54 pm 
Offline

Joined: Wed Nov 30, 2005 8:22 pm
Posts: 227
Location: L.I., New York
I have many images that may be facing either left or right so I just store them one way and flip them on demand when needed. In this particular case, the images need to be flipped. These images are the avatar images for the game and depending on whether they are on the left or right of the game window, I can flip them on demand. I do this to cut down on the amount of images that I am using and to save disk space.

As for the blinking eyes, there are 3 images that are used to give the illusion of blinking eyes (fully open, halfway closed, fully closed).

EDIT: I have pretty much got everything working the way I want it to. I figured out how to fix the white background issue in Windows.

The Timer in Windows is still a bit inconsistent. It sometimes skips a blinking stage and I'm not sure why. I used SELECT CASE since I have 4 possible instances for eye blinking (fully open, halfway closed, fully closed, and halfway open) and this simply repeats. I do change the Timer period between fully open and halfway open to give the illusion of the eyes being open longer before blinking again. Otherwise you'd get a headache from the constant blinking with no rest.

Anyway, here is the Timer code:
Select Case intYugiBlinkState
Case 0
imgTmp(2) = MirrorPNG(GetPNG("CharPics", "Pic2", 1))
intYugiBlinkState = 1
tmrYugiBlink.Period = 7000

Case 1
imgTmp(2) = MirrorPNG(GetPNG("CharPics", "Pic6", 1))
intYugiBlinkState = 2
tmrYugiBlink.Period = 50

Case 2
imgTmp(2) = MirrorPNG(GetPNG("CharPics", "Pic7", 1))
intYugiBlinkState = 3

Case 3
imgTmp(2) = MirrorPNG(GetPNG("CharPics", "Pic6", 1))
intYugiBlinkState = 0

End Select

imgYugi(2).Refresh(False)

If something seems out of whack, let me know.

MirrorPNG is the Function that horizontally flips the image and mask when I need it to.
GetPNG is the Function that grabs the specified PNG image from the database.

While writing this I realized a better way to go. I should simply store the fully open, halfway closed and fully closed images in 3 variables this way I am not bogging down resources by continually grabbing the same images.

EDIT2: I have changed the Timer code to the following and it seems a bit faster now:
Select Case intYugiBlinkState
Case 0
imgTmp(2) = imgTmp(8)
intYugiBlinkState = 1
tmrYugiBlink.Period = 7000

Case 1
imgTmp(2) = imgTmp(6)
intYugiBlinkState = 2
tmrYugiBlink.Period = 50

Case 2
imgTmp(2) = imgTmp(7)
intYugiBlinkState = 3

Case 3
imgTmp(2) = imgTmp(6)
intYugiBlinkState = 0

End Select

imgYugi(2).Refresh(False)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group