I realized quite quickly that dbSync() doesn't return until (1/syncRate) seconds has gone by. This means that your entire code will only be run(if at a sync rate of 60) 60 times a second. That is incredibly slow if you need to do CPU intensive things, other than rendering, like sending/receiving network packets, large calculations, etc. Doing those kinds of routines inside of a drawing routine where you only get 60 cycles a second is incredibly insufficient.
Look at this code:
#include "DarkGDK.h"
// Since dbPerformanceTimer has no Freq - I wouldnt know precision might as well use GPF/QPC
// Global High precision Timer variables
LARGE_INTEGER g_PFreq; // Performance Frequency
LARGE_INTEGER g_LCount; // Last Count
LARGE_INTEGER g_CCount; // Current Count
// Frames Per Second
int g_FPS; // Actual FPS
int g_FPScount; // Counter for FPS
// Cycles Per Second
int g_CPS; // Actual CPS
int g_CPScount; // Coutner for CPS
char strBuff[500]; // For our strings
void DarkGDK()
{
dbSyncOn();
dbSyncRate(60);
//Initialize the counter
QueryPerformanceFrequency(&g_PFreq);
QueryPerformanceCounter(&g_LCount);
while(LoopGDK())
{
QueryPerformanceCounter(&g_CCount);
// Has one second gone by?
if(g_CCount.QuadPart - g_LCount.QuadPart >= g_PFreq.QuadPart)
{
g_LCount = g_CCount;
g_FPS = g_FPScount; // Set actual fps to how many frames were rendered in one second
g_CPS = g_CPScount; // Set actual cps to how many cycles were completed in one second
g_FPScount = -1;
g_CPScount = -1;
}
//Draw some stuff
dbCLS();
sprintf(strBuff, "Custom FPS: %d", g_FPS); // The fps our counter got
dbText(0, 0, strBuff);
sprintf(strBuff, "Custom CPS: %d", g_CPS); // The cps our counter got
dbText(0, 10, strBuff);
sprintf(strBuff, "dbScreenFPS: %d", dbScreenFPS());
dbText(0, 20, strBuff);
dbSync();
g_FPScount++; // A frame has been rendered
g_CPScount++; // A cycle has been completed
}
}
The output should be:
Custom FPS: 61
Custom CPS: 61
dbScreenFPS: 60
So, I decided to check if a certain amount of time has passed before doing any drawing. Somthing like "If 1/60th of a second has passed, draw some stuff." That right there makes dbSyncRate() useless.
Now Check this code out:
#include "DarkGDK.h"
#define MAX_FPS 60
// Since dbPerformanceTimer has no Freq - I wouldnt know precision might as well use GPF/QPC
// Global High precision Timer variables
LARGE_INTEGER g_PFreq; // Performance Frequency
LARGE_INTEGER g_LRCount; // Last Count For rendering
LARGE_INTEGER g_CRCount; // Current Count For Rendering
LARGE_INTEGER g_LCCount; // Last Count for FPS/CPS count
LARGE_INTEGER g_CCCount; // Current Count for FPS/CPS count
// Frames Per Second
int g_FPS; // Actual FPS
int g_FPScount; // Counter for FPS
// Cycles Per Second
int g_CPS; // Actual CPS
int g_CPScount; // Coutner for CPS
char strBuff[500]; // For our strings
void DarkGDK()
{
dbSyncOn();
//dbSyncRate(60); - Dont Need you
//Initialize the counter
QueryPerformanceFrequency(&g_PFreq);
QueryPerformanceCounter(&g_LRCount);
QueryPerformanceCounter(&g_LCCount);
while(LoopGDK())
{
QueryPerformanceCounter(&g_CRCount);
QueryPerformanceCounter(&g_CCCount);
// Has one second gone by?
if(g_CCCount.QuadPart - g_LCCount.QuadPart >= g_PFreq.QuadPart)
{
g_LCCount = g_CCCount;
g_FPS = g_FPScount; // Set actual fps to how many frames were rendered in one second
g_CPS = g_CPScount; // Set actual cps to how many cycles were completed in one second
g_FPScount = -1;
g_CPScount = -1;
}
// Has 1/60th of a second gone by?
if(g_CRCount.QuadPart - g_LRCount.QuadPart >= g_PFreq.QuadPart / MAX_FPS)
{
g_LRCount = g_CRCount;
//Draw some stuff
dbCLS(0xFF000F7F);
sprintf(strBuff, "Custom FPS: %d", g_FPS); // The fps our counter got
dbText(0, 0, strBuff);
sprintf(strBuff, "Custom CPS: %d", g_CPS); // The cps our counter got
dbText(0, 10, strBuff);
sprintf(strBuff, "dbScreenFPS: %d", dbScreenFPS());
dbText(0, 20, strBuff);
dbSync();
g_FPScount++; // A frame has been rendered
}
g_CPScount++; // A cycle has been completed
}
}
with MAX_FPS at 60:
Custom FPS: 59
Custom CPS: 150000
dbScreenFPS: 60
with MAX_FPS at 30:
Custom FPS: 29
Custom CPS 300000
dbScreenFPS: 30
So, that proves that dbSyncRate is useless. And also shows some newbies that they should put their drawing routines inside a timer.