Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Question about sync commands

Author
Message
Dragon slayer
19
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 15th Jun 2013 00:13
I will probably post something similar to this in DarkGdk forum as I am working with both C++ and DBP at the same time. So I do somewhat know what these commands are for but a little more explanation would be helpful.

I know you put it in the beginning of the program but when do you call it? I have seen sync at the end but then in GDK someone said turn it off before an input call then turn it on again after. Is there certain times in a DBP program when you have to do this?

Also do you have to use it if you are using 2D commands like line, box, ink, rgb?

I am going to check out the Advanced 2D plugin for DBP.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 15th Jun 2013 00:40
It updates graphics, and sound, and text. You can put them wherever you want to update something. It's usually best to update everything at the end but not always.

You can use sync whenever you want, but if you use it too often it will slow down your program, and it can cause some images to jerk behind other images.

The simple option in DB Pro is

1/ At the beginning of the program put SYNC ON

2/
Do
Code

SYNC
LOOP

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 15th Jun 2013 00:57
using sync commands is very important as your program gets bigger.

try always to begin your program with: sync on : sync rate value#.

this way you programs works in the back ground and you control when to display the contents on the screen when you use sync command.

you will notice a big shift in performance.

Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 15th Jun 2013 01:09 Edited at: 15th Jun 2013 01:11
Calling sync carries out most of the internal updates as stated above; it
♦ updates the built-in 3D animation system
♦ renders the 3D scene to the back buffer
♦ switches the back buffer with the front buffer
♦ updates whatever else (sound, music, etc. if that is really updated at all; maybe it carries out things as volume changes you've set earlier in the subsequent sync).

The reason you might want to turn it off when using the built-in input function is that this one blocks your program until the user presses the return key. It will thus print out the characters the user enters to the back buffer, but since your program never leaves the input command to issue a sync call, the buffers are never switched and you thus don't see these updates on the screen. If you turn the synchronisation "off" what you're really doing is telling DBP to sync at regular intervals by itself. This will thus happen even if you're in the middle of the input function. But it can also happen in the middle of repositioning objects in your scene and thus create incorrect renders, which is why you generally want to call it at times that you decide yourself (such as at the end of a loop cycle).

Edit: That was pretty poorly written... I blame all the "thus":es on the late hour


"Why do programmers get Halloween and Christmas mixed up?"
Dragon slayer
19
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 15th Jun 2013 01:46
I understand but am not sure if I use it only in the game loop/do loop or at the very beginning of the program and again at the end and once in a while throughout the program as necessary. Now I am working on a text program but am using 2D commands like line and box to make game screens. Do I need it for this or is it more for the 3D stuff?

I have not really used it in DBP but it is included in a DarkGDK default program and I had that problem with the input command in a c++ and DGDK program.
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 15th Jun 2013 12:05 Edited at: 15th Jun 2013 12:06
If you use Sync On at the beginning of DB Pro you have to use sync to see anything happen. If you don't put sync On at the beginning of the program DB Pro does the sync for you, but way too often. So now your game is slowed down.

So you put sync in the do loop after you put sync on at the beginning of the program.

Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 15th Jun 2013 23:53
Quote: "using sync commands is very important as your program gets bigger.

try always to begin your program with: sync on : sync rate value#.

this way you programs works in the back ground and you control when to display the contents on the screen when you use sync command."


Quote: "The reason you might want to turn it off when using the built-in input function is that this one blocks your program until the user presses the return key. It will thus print out the characters the user enters to the back buffer, but since your program never leaves the input command to issue a sync call, the buffers are never switched and you thus don't see these updates on the screen. If you turn the synchronisation "off" what you're really doing is telling DBP to sync at regular intervals by itself. This will thus happen even if you're in the middle of the input function. But it can also happen in the middle of repositioning objects in your scene and thus create incorrect renders, which is why you generally want to call it at times that you decide yourself (such as at the end of a loop cycle)."


I completely agree. Thanks for posting great advice.

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 16th Jun 2013 01:14
Whilst we're on the topic of Sync, recently I've started playing with Matrix1 Utilites "Get Presync Callback" & "Get Postsync Callback" commands. Check them out if you haven't as they're pretty cool!!!

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 18th Jun 2013 11:24
What do those commands do?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Jun 2013 12:42
Typo alert!!

Here's what Matrix1 Help file says about one of them:

Quote: "SET PRESYNC CALLBACK

Syntax

SET PRESYNC CALLBACK FunctionPointer
SET PRESYNC CALLBACK FunctionName

Description

These commands allow you to specify a function that will be called at the start of the sync process.

Your function should look like this:
FUNCTION YourFunctionName()
ENDFUNCTION

Any attempt to call the SYNC command within the callback will be ignored.

A FunctionPointer value of 0 or a FunctionName of "" will cause the callback to be disabled.
"


I've no idea what that command does or how it differs from simply calling the function just before the sync command.
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 18th Jun 2013 13:42 Edited at: 18th Jun 2013 13:42
I just use a wrapper function for all of my sync commands.
It's how I slip in some of the power efficiency techniques I posted previously about. Mainly a CPU friendly frame limiters, and in the case of several game editors a standby mode.
The wrapper also takes an input variable which controls whether HDR lighting will be applied to the screen whenever the function is called.

Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 18th Jun 2013 23:47
Nice Spot GG. Set, not get!

I use "Set PreSync Callback "DLL_Update"" call at the end of my subroutine "Sub_DLL_Load". By doing this, I only have to call the DLL_Update subroutine at the beginning of my program, and all my mouse & window array data fills up without any further function calls.

Mage, I've been practicing a method which keeps all those points in mind. One day I'll get there.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia

Login to post a reply

Server time is: 2026-07-06 18:37:09
Your offset time is: 2026-07-06 18:37:09