Implemented VSync timer using SDL
This commit is contained in:
@@ -308,12 +308,22 @@ bool rc_windowOpenEx(std::string title, int x, int y, int w, int h, uint32_t win
|
||||
irr_creation_params.Bits = 16;
|
||||
irr_creation_params.Fullscreen = fullscreen;
|
||||
irr_creation_params.Stencilbuffer = stencil_buffer;
|
||||
irr_creation_params.Vsync = vsync;
|
||||
irr_creation_params.Vsync = false;
|
||||
irr_creation_params.EventReceiver = 0;
|
||||
irr_creation_params.WindowPosition = position2d<s32>(x, y);
|
||||
irr_creation_params.AntiAlias = AntiAlias;
|
||||
irr_creation_params.OGLES2ShaderPath = ".shaders/";
|
||||
|
||||
rc_window_vsync = vsync;
|
||||
|
||||
if(vsync)
|
||||
{
|
||||
SDL_DisplayMode dm;
|
||||
SDL_GetDesktopDisplayMode(0, &dm);
|
||||
rc_vsync_refresh_rate = dm.refresh_rate;
|
||||
rc_vsync_timer = SDL_GetTicks();
|
||||
}
|
||||
|
||||
device = createDeviceEx(irr_creation_params);
|
||||
|
||||
|
||||
|
||||
@@ -255,6 +255,9 @@ bool rc_mouse_zone_active = false;
|
||||
double rc_window_zone_scale_x = 1;
|
||||
double rc_window_zone_scale_y = 1;
|
||||
SDL_Rect rc_mouse_zone;
|
||||
bool rc_window_vsync = false;
|
||||
int rc_vsync_refresh_rate = 0;
|
||||
Uint32 rc_vsync_timer = 0;
|
||||
|
||||
struct rc_scene_properties_obj
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define RC_OS_DEFINES_H_INCLUDED
|
||||
|
||||
//USED FOR TESTING ONLY
|
||||
//#define RC_TESTING
|
||||
#define RC_TESTING
|
||||
|
||||
//I am checking Android first since I think it also defines __linux__
|
||||
|
||||
|
||||
@@ -79,6 +79,13 @@ void rc_preUpdate()
|
||||
|
||||
bool rc_update()
|
||||
{
|
||||
if(rc_window_vsync)
|
||||
{
|
||||
int frame_delay = 1000/rc_vsync_refresh_rate;
|
||||
while( (SDL_GetTicks()-rc_vsync_timer) < frame_delay ){}
|
||||
rc_vsync_timer = SDL_GetTicks();
|
||||
}
|
||||
|
||||
if(!device->run())
|
||||
return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user