? Flicker-less graphics without VSYNC/WAIT ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password
Another contest? You asked for it!

Flicker-less graphics without VSYNC/WAIT

Graphics drawing loops commonly look like this: WHILE 1 GCLS 'graphics stuff VSYNC WEND The VSYNC stops the image from flickering, but if the graphics code takes longer than 1 frame, the VSYNC will do nothing and it will flicker. Here is a solution: VAR PAGE% WHILE 1 GCLS 'graphics stuff GPAGE PAGE%,!PAGE% PAGE%=!PAGE% BSYNC WENDThis makes the program display one page, and edit another. After it finishes drawing the graphics for one loop, it switches the pages.
Author
12Me21
Updated
Rating
0 votes
Categories
Keywords
13 Comment(s) dfrost2 dfrost2 Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength you could just recreate the WAIT function by using the following: DEF WAITMILLISEC NUM M=MILLISEC WHILE MILLISEC-M<NUM WEND END IF THISWORKS==TRUE THEN PRINT "GOOD IDEA!" Lumage Lumage Head Admin Although the page is terrible and the intent not clear, the WAIT/VSYNC commands are not what is being discussed. The issue here is redrawing before previous drawing procedures finished, resulting in partially complete frames being shown, and, as a result, "flicker". The solution given is to use extra pages to implement a double-buffer and page swap when finished drawing. This approach has the trade-off of ALWAYS finishing drawing before the display is updated, and for long draw cycles can fail to keep a steady frame rate. 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself hmm this page sucks. I tried to remove most of the bad information... banana banana RNG Hidden Easter Eggs Disguised Hidden Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength This helped me to reduce flicker in LISA SquareFingers SquareFingers Removing VSYNC and WAIT, simply because one of their effects (helping reduce flicker) can be obtained in a different way, is not a good idea without also addressing their other effects (helping manage time). Imagine that you have written a game where sometimes, there is more processing to do than at other times (e.g. at the end of a level, you face a boss, who spawns more enemies than are usually on the screen). Compare VAR I ACLS WHILE TRUE GCLS GCIRCLE 200,120,50,0,I I=(I+1) MOD 360 DO_GAME VSYNC WEND DEF DO_GAME VAR DELAY IF (I>250) THEN ' boss time DELAY=3000+10000*HARDWARE FOR DELAY=DELAY TO 0 STEP -1 NEXT ENDIF END with: VAR I,PAGE ACLS WHILE TRUE GCLS GCIRCLE 200,120,50,0,I I=(I+1) MOD 360 DO_GAME GPAGE PAGE,!PAGE PAGE=!PAGE WEND DEF DO_GAME VAR DELAY IF (I>250) THEN ' boss time DELAY=3000+10000*HARDWARE FOR DELAY=DELAY TO 0 STEP -1 NEXT ENDIF END 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself For timed events you can use MAINCNT for an event to happen ever 700 frames, you could do IF !(MAINCNT MOD 700) THEN ... SquareFingers SquareFingers Removing VSYNC and WAIT is the LAST thing you want to do if you want "a very accurate timer". They help ensure accurate and consistent timing, certainly not reduce it (when used right). 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself FRAME=MAINCNT WHILE 1 GPUTCHR 100,100,(MAINCNT-FRAME)/60 GPAGE PAGE,!PAGE PAGE=!PAGE WEND Your timer should not be affected by how fast the loop runs. SquareFingers SquareFingers Yes :) you got me, I overstated the case. It's not the LAST thing. But taking them out and replacing them with something that doesn't use MAINCNT (as the original content of the page) is a step in the wrong direction. phil_ phil_ Scholar Received for knowing a great deal about programming topics Achievements osu! Is Awesome! I love osu! Express Yourself First Day Joined on the very first day of SmileBASIC Source Website Your method, 12Me, would be best for games. The technique you showed is what Calc84 used in his Raycaster engine for SBv2. Pretty much all modern games for some console use techniques like this. However, for making a timer, this method is bad, because the crazy speed at which it could will make it lose accuracy. 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself MAINCNT doesn't lose accuracy, as far as I know. And the new timer commands definitely won't.
But taking them out and replacing them with something that doesn't use MAINCNT (as the original content of the page) is a step in the wrong direction.
I'm not sure what you mean
SquareFingers SquareFingers I mean to say that changing from the type of code in the first block (with VSYNC) to the type of code in the second block (without VSYNC, and without MAINCNT) will make for a less accurate timer, not a more accurate one. 12Me21 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself The example code is for graphics display, not a timer.