Compare commits

...

5 Commits

14 changed files with 85 additions and 70 deletions

View File

@ -143,13 +143,12 @@
<attstr name="font" val="medium"/>
</section>
<!--
<section name="MaxRefreshRateCombo">
<attstr name="type" val="combo box"/>
<attnum name="max len" val="4"/>
<attstr name="tip" val="Select your max. refresh rate"/>
<attnum name="x" val="320"/>
<attnum name="y" val="158"/>
<attnum name="x" val="270"/>
<attnum name="y" val="228"/>
<attnum name="width" val="220"/>
<attnum name="arrows width" val="24"/>
<attnum name="arrows height" val="24"/>
@ -157,7 +156,6 @@
<attstr name="focused color" val="0xFFFFFF"/>
<attstr name="font" val="medium"/>
</section>
-->
<section name="CancelButton">
<attstr name="type" val="text button"/>
@ -315,6 +313,17 @@
<attstr name="font" val="small_t"/>
</section>
<section name="12">
<attstr name="type" val="label"/>
<attnum name="x" val="20"/>
<attnum name="y" val="232"/>
<attstr name="text" val="Max FPS:"/>
<attstr name="tip" val="Sets maximum frames per second rate"/>
<attstr name="h align" val="right"/>
<attnum name="width" val="220"/>
<attstr name="font" val="small_t"/>
</section>
</section>
</params>

View File

@ -278,9 +278,4 @@ void GfEventLoop::recompute()
// Call the 'recompute' callback if any.
if (_pPrivate->cbRecompute)
_pPrivate->cbRecompute();
// ... otherwise let the CPU take breath (and fans stay at low and quiet speed,
// which would not be the case if really doing nothing).
else
SDL_Delay(1); // ms.
}

View File

@ -19,6 +19,7 @@
#include <SDL.h>
#include "tgfclient.h"
#include "tgf.h"
#ifdef WEBSERVER
#include "webserver.h"
@ -48,12 +49,14 @@ class GfuiEventLoop::Private
// Variables.
bool bRedisplay; // Flag to say if a redisplay is necessary.
double max_refresh; // Max refresh rate.
};
GfuiEventLoop::Private::Private()
: cbMouseButton(0), cbMouseMotion(0), cbMousePassiveMotion(0), cbMouseWheel(0),
cbJoystickAxis(0), cbJoystickButton(0),
cbDisplay(0), cbReshape(0), bRedisplay(false)
cbDisplay(0), cbReshape(0), bRedisplay(false),
max_refresh(50.0)
{
}
@ -238,11 +241,22 @@ void GfuiEventLoop::operator()()
if (!quitRequested())
{
double now = GfTimeClock();
// Recompute if anything to.
recompute();
// Redisplay if anything to.
redisplay();
double elapsed = GfTimeClock() - now;
if (_pPrivate->max_refresh)
{
double rate = 1.0 / _pPrivate->max_refresh;
if (elapsed < rate)
GfSleep(rate - elapsed);
}
}
}
@ -294,6 +308,11 @@ void GfuiEventLoop::postRedisplay(void)
_pPrivate->bRedisplay = true;
}
void GfuiEventLoop::setMaxRefreshRate(double rate)
{
_pPrivate->max_refresh = rate;
}
void GfuiEventLoop::forceRedisplay()
{
#ifdef WEBSERVER

View File

@ -207,6 +207,7 @@ ScreenSizeVector GfScrGetSupportedSizes(int nDisplayIndex)
tScreenSize last;
last.width = 0;
last.height = 0;
last.refresh_rate = 0;
bounds.w = 0;
bounds.h = 0;
@ -240,6 +241,7 @@ ScreenSizeVector GfScrGetSupportedSizes(int nDisplayIndex)
GfLogDebug(" %d x %d x %d @ %d hz\n",mode.w,mode.h,SDL_BITSPERPIXEL(mode.format),mode.refresh_rate);
last.width = mode.w;
last.height = mode.h;
last.refresh_rate = mode.refresh_rate;
vecSizes.push_back(last);
}
}
@ -259,6 +261,7 @@ ScreenSizeVector GfScrGetSupportedSizes(int nDisplayIndex)
// Desperation stick the Display Bounds into the vector
last.width = bounds.w;
last.height = bounds.h;
last.refresh_rate = mode.refresh_rate;
vecSizes.push_back(last);
}
@ -276,12 +279,14 @@ tScreenSize GfScrGetCurrentDisplaySize(int nDisplayIndex)
size.width = 0;
size.height = 0;
size.refresh_rate = 0;
SDL_DisplayMode mode;
if(SDL_GetCurrentDisplayMode(nDisplayIndex, &mode) == 0)
{
size.width = mode.w;
size.height = mode.h;
size.refresh_rate = mode.refresh_rate;
}
return size;
}
@ -490,6 +495,10 @@ bool GfScrInitSDL2(int nWinWidth, int nWinHeight, int nFullScreen)
GfScrStartDisplayId = 0;
}
double maxRefreshRate = GfParmGetNum(hparmScreen, pszScrPropSec, GFSCR_ATT_MAXREFRESH, NULL, 50);
GfuiApp().eventLoop().setMaxRefreshRate(maxRefreshRate);
bool bFullScreen;
if (nFullScreen < 0)
bFullScreen =
@ -723,6 +732,7 @@ bool GfScrInitSDL2(int nWinWidth, int nWinHeight, int nFullScreen)
GfLogInfo(" Full screen : %s\n", (bfVideoMode & SDL_WINDOW_FULLSCREEN) ? "Yes" : "No");
GfLogInfo(" Size : %dx%d\n", nWinWidth, nWinHeight);
GfLogInfo(" Color depth : %d bits\n", nTotalDepth);
GfLogInfo(" Max. refresh rate : %f\n", maxRefreshRate);
// Report about underlying hardware (needs a running frame buffer).
GfglFeatures::self().dumpHardwareInfo();
@ -804,6 +814,8 @@ void GfScrShutdown(void)
GfParmGetNum(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_STARTUPDISPLAY, 0, 0));
GfParmSetStr(hparmScreen, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_VDETECT,
GfParmGetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_VDETECT, GFSCR_VAL_VDETECT_AUTO));
GfParmSetNum(hparmScreen, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_MAXREFRESH, 0,
GfParmGetNum(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_MAXREFRESH, 0, 50));
const char* pszVInitMode =
GfParmGetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_VINIT,
GFSCR_VAL_VINIT_COMPATIBLE);
@ -1259,6 +1271,20 @@ bool GfScrInitSDL2()
// Setup the event loop about the new display.
GfuiApp().eventLoop().setReshapeCB(gfScrReshapeViewport);
GfuiApp().eventLoop().postRedisplay();
double maxRefreshRate = 50;
void* hparmScreen =
GfParmReadFileLocal(GFSCR_CONF_FILE, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
if (hparmScreen)
{
maxRefreshRate = GfParmGetNum(hparmScreen,
GFSCR_SECT_VALIDPROPS, GFSCR_ATT_MAXREFRESH, NULL, maxRefreshRate);
GfParmReleaseHandle(hparmScreen);
}
GfuiApp().eventLoop().setMaxRefreshRate(maxRefreshRate);
return true;
}
else

View File

@ -75,6 +75,7 @@ typedef struct ScreenSize
{
int width; // Width in pixels.
int height; // Height in pixels.
double refresh_rate; // Refresh rate in Hz.
} tScreenSize;
typedef std::vector<tScreenSize> ScreenSizeVector;
@ -768,6 +769,9 @@ class TGFCLIENT_API GfuiEventLoop : public GfEventLoop
//! Force a call to the "redisplay/refresh" callback function.
void forceRedisplay();
//! Sets maximum refresh rate to the event loop.
void setMaxRefreshRate(double rate);
protected:
//! Process a keyboard event.

View File

@ -486,9 +486,6 @@ configure_for_joy_axis:
return;
}
}
/* Let CPU take breath (and fans stay at low and quiet speed) */
GfSleep(0.001);
}
/* Push button callback for each command button : activate input devices action collection loop */

View File

@ -33,10 +33,8 @@ static const char* ADisplayModes[DisplayMenu::nDisplayModes] = { "Full-screen",
static const char* MonitorTypes[DisplayMenu::nDisplayTypes] = { "none", "4:3", "16:9", "21:9" };
static const char* SpansplitValues[] = { GR_VAL_NO, GR_VAL_YES };
static const int NbSpansplitValues = sizeof(SpansplitValues) / sizeof(SpansplitValues[0]);
#ifndef NoMaxRefreshRate
static const int AMaxRefreshRates[] = { 0, 30, 40, 50, 60, 75, 85, 100, 120, 150, 200 };
static const int AMaxRefreshRates[] = {30, 40, 50, 60, 75, 85, 100, 120, 150, 200 };
static const int NMaxRefreshRates = sizeof(AMaxRefreshRates) / sizeof(AMaxRefreshRates[0]);
#endif
// The unique DisplayMenu instance.
static DisplayMenu* PDisplayMenu = 0;
@ -155,7 +153,6 @@ void DisplayMenu::onChangeMenuDisplay(tComboBoxInfo *pInfo)
pMenu->setMenuDisplay(pInfo->nPos);
}
#ifndef NoMaxRefreshRate
void DisplayMenu::onChangeMaxRefreshRate(tComboBoxInfo *pInfo)
{
// Get the DisplayMenu instance from call-back user data.
@ -163,7 +160,6 @@ void DisplayMenu::onChangeMaxRefreshRate(tComboBoxInfo *pInfo)
pMenu->setMaxRefreshRateIndex(pInfo->nPos);
}
#endif
// Re-init screen to take new graphical settings into account (implies process restart).
void DisplayMenu::onAccept(void *pDisplayMenu)
@ -202,7 +198,8 @@ bool DisplayMenu::restartNeeded()
bool needRestart = ((_eDisplayMode != _eOriginalDisplayMode)
|| (_nScreenWidth !=_nOriginalScreenWidth)
|| (_nScreenHeight != _nOriginalScreenHeight)
|| (_nOriginalMenuDisplay != _nMenuDisplay));
|| (_nOriginalMenuDisplay != _nMenuDisplay))
|| (_nOriginalMaxRefreshRate != _nMaxRefreshRate);
if(GfScrUsingResizableWindow() && (_eDisplayMode == eResizable))
needRestart = false;
@ -261,7 +258,6 @@ void DisplayMenu::updateControls()
sprintf(buf, "%g", PDisplayMenu->_fArcRatio);
GfuiEditboxSetString(getMenuHandle(), sArcRatioID, buf);
#ifndef NoMaxRefreshRate
nControlId = getDynamicControlId("MaxRefreshRateCombo");
int nMaxRefRateIndex = 0; // Defaults to None.
for (int nMaxRefRateInd = 0; nMaxRefRateInd < NMaxRefreshRates; nMaxRefRateInd++)
@ -271,7 +267,6 @@ void DisplayMenu::updateControls()
break;
}
GfuiComboboxSetSelectedIndex(getMenuHandle(), nControlId, nMaxRefRateIndex);
#endif
}
void DisplayMenu::loadSettings()
@ -303,11 +298,9 @@ void DisplayMenu::loadSettings()
}
#ifndef NoMaxRefreshRate
// Max. refresh rate (Hz).
_nMaxRefreshRate =
(int)GfParmGetNum(hScrConfParams, pszScrPropSec, GFSCR_ATT_MAXREFRESH, NULL, 0);
#endif
_nMaxRefreshRate = _nOriginalMaxRefreshRate =
(int)GfParmGetNum(hScrConfParams, pszScrPropSec, GFSCR_ATT_MAXREFRESH, NULL, 50);
// Release screen config params file.
GfParmReleaseHandle(hScrConfParams);
@ -328,9 +321,7 @@ void DisplayMenu::storeSettings() const
GfParmSetNum(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_X, (char*)NULL, _nScreenWidth);
GfParmSetNum(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_Y, (char*)NULL, _nScreenHeight);
GfParmSetNum(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_STARTUPDISPLAY, (char*)NULL, _nMenuDisplay);
#ifndef NoMaxRefreshRate
GfParmSetNum(hScrConfParams, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_MAXREFRESH, (char*)NULL, _nMaxRefreshRate);
#endif
const char* pszDisplMode =
(_eDisplayMode == eFullScreen) ? GFSCR_VAL_YES : GFSCR_VAL_NO;
@ -468,6 +459,7 @@ void DisplayMenu::resetScreenSizes()
tScreenSize _currSize = GfScrGetCurrentDisplaySize( _nMenuDisplay);
_nScreenWidth = _currSize.width;
_nScreenHeight = _currSize.height;
_nMaxRefreshRate = _currSize.refresh_rate;
}
else
{
@ -520,6 +512,20 @@ void DisplayMenu::resetScreenSizes()
// Select the found one in the combo-box.
GfuiComboboxSetSelectedIndex(getMenuHandle(), nComboId, nScreenSizeIndex);
{
const int nComboId = getDynamicControlId("MaxRefreshRateCombo");
if (nComboId != -1)
for (size_t i = 0; i < NMaxRefreshRates; i++)
{
if (AMaxRefreshRates[i] == _nMaxRefreshRate)
{
GfuiComboboxSetSelectedIndex(getMenuHandle(), nComboId, i);
break;
}
}
}
}
void DisplayMenu::setScreenSizeIndex(int nIndex)
@ -562,12 +568,10 @@ void DisplayMenu::setMenuDisplay(int nIndex)
}
}
#ifndef NoMaxRefreshRate
void DisplayMenu::setMaxRefreshRateIndex(int nIndex)
{
_nMaxRefreshRate = AMaxRefreshRates[nIndex];
}
#endif
DisplayMenu::DisplayMenu()
: GfuiMenuScreen("displayconfigmenu.xml")
@ -585,9 +589,7 @@ DisplayMenu::DisplayMenu()
_nOriginalScreenHeight = 600;
_nOriginalMenuDisplay = 0;
_eOriginalDisplayMode = eWindowed;
#ifndef NoMaxRefreshRate
_nMaxRefreshRate = 0;
#endif
_nMaxRefreshRate = 50;
}
bool DisplayMenu::initialize(void *pPreviousMenu)
@ -635,10 +637,8 @@ bool DisplayMenu::initialize(void *pPreviousMenu)
sArcRatioID = createEditControl("arcratioedit", this, NULL, onChangeArcRatio);
#ifndef NoMaxRefreshRate
const int nMaxRefRateComboId =
createComboboxControl("MaxRefreshRateCombo", this, onChangeMaxRefreshRate);
#endif
createButtonControl("ApplyButton", this, onAccept);
createButtonControl("CancelButton", this, onCancel);
@ -668,7 +668,6 @@ bool DisplayMenu::initialize(void *pPreviousMenu)
GfuiComboboxAddText(getMenuHandle(), nSpanSplitsComboId, SpansplitValues[index]);
#ifndef NoMaxRefreshRate
// 6) Max refresh rate combo.
std::ostringstream ossMaxRefRate;
for (int nRefRateInd = 0; nRefRateInd < NMaxRefreshRates; nRefRateInd++)
@ -680,7 +679,6 @@ bool DisplayMenu::initialize(void *pPreviousMenu)
ossMaxRefRate << "None";
GfuiComboboxAddText(getMenuHandle(), nMaxRefRateComboId, ossMaxRefRate.str().c_str());
}
#endif
return true;
}

View File

@ -25,8 +25,6 @@
#include "confscreens.h"
// Comment-out to activate max. refresh rate settings.
#define NoMaxRefreshRate 1
class DisplayMenu : public GfuiMenuScreen
@ -46,9 +44,7 @@ public:
void setMonitorType(EDisplayType eType);
void setArcRatio(float ratio);
void setMenuDisplay(int nIndex);
#ifndef NoMaxRefreshRate
void setMaxRefreshRateIndex(int nIndex);
#endif
void storeSettings() const;
void loadSettings();
@ -76,9 +72,7 @@ protected:
static void onChangeScreenDist(void *pDisplayMenu);
static void onChangeArcRatio(void *pDisplayMenu);
static void onChangeMenuDisplay(tComboBoxInfo *pInfo);
#ifndef NoMaxRefreshRate
static void onChangeMaxRefreshRate(tComboBoxInfo *pInfo);
#endif
static void onAccept(void *pDisplayMenu);
static void onCancel(void *pDisplayMenu);
@ -108,10 +102,9 @@ private:
float _fScreenDist;
#ifndef NoMaxRefreshRate
//! Currently selected max. refresh rate (Hz).
int _nMaxRefreshRate;
#endif
int _nOriginalMaxRefreshRate;
};
extern void* DisplayMenuInit(void* pPreviousMenu);

View File

@ -279,9 +279,6 @@ Idle2(void)
return;
}
}
/* Let CPU take breath (and fans stay at low and quite speed) */
GfSleep(0.001);
}

View File

@ -195,9 +195,6 @@ Idle2(void)
return;
}
}
/* Let CPU take breath (and fans stay at low and quite speed) */
GfSleep(0.001);
}

View File

@ -163,9 +163,6 @@ Idle2(void)
return;
}
}
/* Let CPU take breath (and fans stay at low and quiet speed) */
GfSleep(0.001);
}
static void

View File

@ -95,11 +95,6 @@ static void splashIdle()
// And now it's done, remember it.
splBackgroundWorkDone = true;
}
else
{
// Wait a little, to let the CPU take breath.
GfSleep(0.001);
}
// Close if the splash screen delay is over.
if (splTimedOut)

View File

@ -543,9 +543,6 @@ HostServerIdle(void)
GfuiApp().eventLoop().postRedisplay();
}
/* Let CPU take breath (and fans stay at low and quiet speed) */
GfSleep(0.001);
}
@ -580,9 +577,6 @@ ClientIdle(void)
GfuiApp().eventLoop().postRedisplay();
}
/* Let CPU take breath (and fans stay at low and quiet speed) */
GfSleep(0.001);
}
static void

View File

@ -541,9 +541,6 @@ HostServerIdle(void)
GfuiApp().eventLoop().postRedisplay();
}
/* Let CPU take breath (and fans stay at low and quiet speed) */
GfSleep(0.001);
}
@ -578,9 +575,6 @@ ClientIdle(void)
GfuiApp().eventLoop().postRedisplay();
}
/* Let CPU take breath (and fans stay at low and quiet speed) */
GfSleep(0.001);
}
static void