- fullscreen toggle and some cleanup. Not fully working yet.
This commit is contained in:
parent
89ce74443b
commit
babe55819e
15 changed files with 826 additions and 727 deletions
|
|
@ -42,108 +42,3 @@
|
|||
#include "c_cvars.h"
|
||||
#include "i_system.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
// TYPES -------------------------------------------------------------------
|
||||
|
||||
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
||||
|
||||
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
||||
|
||||
static void StopFPSLimit();
|
||||
|
||||
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
||||
|
||||
EXTERN_CVAR(Int, vid_maxfps)
|
||||
|
||||
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
||||
|
||||
static UINT FPSLimitTimer;
|
||||
|
||||
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
||||
|
||||
HANDLE FPSLimitEvent;
|
||||
|
||||
CVAR (Int, vid_adapter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// SetFPSLimit
|
||||
//
|
||||
// Initializes an event timer to fire at a rate of <limit>/sec. The video
|
||||
// update will wait for this timer to trigger before updating.
|
||||
//
|
||||
// Pass 0 as the limit for unlimited.
|
||||
// Pass a negative value for the limit to use the value of vid_maxfps.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void I_SetFPSLimit(int limit)
|
||||
{
|
||||
if (limit < 0)
|
||||
{
|
||||
limit = vid_maxfps;
|
||||
}
|
||||
// Kill any leftover timer.
|
||||
if (FPSLimitTimer != 0)
|
||||
{
|
||||
timeKillEvent(FPSLimitTimer);
|
||||
FPSLimitTimer = 0;
|
||||
}
|
||||
if (limit == 0)
|
||||
{ // no limit
|
||||
if (FPSLimitEvent != NULL)
|
||||
{
|
||||
CloseHandle(FPSLimitEvent);
|
||||
FPSLimitEvent = NULL;
|
||||
}
|
||||
DPrintf(DMSG_NOTIFY, "FPS timer disabled\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FPSLimitEvent == NULL)
|
||||
{
|
||||
FPSLimitEvent = CreateEvent(NULL, FALSE, TRUE, NULL);
|
||||
if (FPSLimitEvent == NULL)
|
||||
{ // Could not create event, so cannot use timer.
|
||||
Printf(DMSG_WARNING, "Failed to create FPS limitter event\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
atterm(StopFPSLimit);
|
||||
// Set timer event as close as we can to limit/sec, in milliseconds.
|
||||
UINT period = 1000 / limit;
|
||||
FPSLimitTimer = timeSetEvent(period, 0, (LPTIMECALLBACK)FPSLimitEvent, 0, TIME_PERIODIC | TIME_CALLBACK_EVENT_SET);
|
||||
if (FPSLimitTimer == 0)
|
||||
{
|
||||
CloseHandle(FPSLimitEvent);
|
||||
FPSLimitEvent = NULL;
|
||||
Printf("Failed to create FPS limiter timer\n");
|
||||
return;
|
||||
}
|
||||
DPrintf(DMSG_NOTIFY, "FPS timer set to %u ms\n", period);
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// StopFPSLimit
|
||||
//
|
||||
// Used for cleanup during application shutdown.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void StopFPSLimit()
|
||||
{
|
||||
I_SetFPSLimit(0);
|
||||
}
|
||||
|
||||
void I_FPSLimit()
|
||||
{
|
||||
if (FPSLimitEvent != NULL)
|
||||
{
|
||||
WaitForSingleObject(FPSLimitEvent, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue