diff --git a/RefChip16/D3DApp.cpp b/RefChip16/D3DApp.cpp index b4d256a..9bbb4dc 100644 --- a/RefChip16/D3DApp.cpp +++ b/RefChip16/D3DApp.cpp @@ -33,6 +33,10 @@ Sprite SpriteSet; struct CHIP16VERTEX {FLOAT X, Y, Z; DWORD COLOR;}; #define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE) CHIP16VERTEX pixel[4*16]; //Buffer to store all the pixel verticles +LARGE_INTEGER nStartTime; +LARGE_INTEGER nStopTime; +LARGE_INTEGER nElapsed; +LARGE_INTEGER nFrequency; #define CPU_LOG __Log #define FPS_LOG __Log2 @@ -372,6 +376,27 @@ void EndDrawing() SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); + if (MenuVSync) + { + float elapsedMicroseconds = 0; + QueryPerformanceCounter(&nStopTime); + nElapsed.QuadPart = (nStopTime.QuadPart - nStartTime.QuadPart) * 1000000; + + elapsedMicroseconds = (float)((float)nElapsed.QuadPart / (float)nFrequency.QuadPart); + //CPU_LOG("Frame took %f microseconds\n", elapsedMicroseconds); + while (elapsedMicroseconds < 16666.66667f) + { + Sleep((long)(16666 - elapsedMicroseconds) >> 10); //Divide by 1024, we want to be under the miliseconds if we can + QueryPerformanceCounter(&nStopTime); + nElapsed.QuadPart = (nStopTime.QuadPart - nStartTime.QuadPart) * 1000000; + elapsedMicroseconds = (float)((float)nElapsed.QuadPart / (float)nFrequency.QuadPart); + //CPU_LOG("%f microseconds now\n", elapsedMicroseconds); + } + + QueryPerformanceFrequency(&nFrequency); + QueryPerformanceCounter(&nStartTime); + } + SDL_RenderPresent(renderer); SDL_DestroyTexture(texture); } diff --git a/RefChip16/D3DApp.h b/RefChip16/D3DApp.h index ef92b78..77afb9b 100644 --- a/RefChip16/D3DApp.h +++ b/RefChip16/D3DApp.h @@ -20,8 +20,6 @@ #ifndef _D3DAPP_H #define _D3DAPP_H -#include -#include #include #include diff --git a/RefChip16/RefChip16.vcxproj b/RefChip16/RefChip16.vcxproj index ff9f128..aa46244 100644 --- a/RefChip16/RefChip16.vcxproj +++ b/RefChip16/RefChip16.vcxproj @@ -18,14 +18,13 @@ {F1F60059-1254-41A6-A847-6E7C959A5E3B} Win32Proj RefChip16 - 10.0.16299.0 Application true NotSet - v141 + v143 Application @@ -33,14 +32,14 @@ true NotSet false - v141 + v143 Dynamic false - v141 + v143 @@ -74,7 +73,7 @@ Level3 Disabled - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + WINDOWS_IGNORE_PACKING_MISMATCH;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) false @@ -96,7 +95,7 @@ MaxSpeed true true - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + WINDOWS_IGNORE_PACKING_MISMATCH;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) Speed diff --git a/RefChip16/main.cpp b/RefChip16/main.cpp index 1b27b33..b6b130b 100644 --- a/RefChip16/main.cpp +++ b/RefChip16/main.cpp @@ -27,6 +27,7 @@ #include #include #include "resource.h" +#include /*#define _CRTDBG_MAP_ALLOC #include #include */ diff --git a/Release/RefChip16.exe b/Release/RefChip16.exe index b2f9331..27156eb 100644 Binary files a/Release/RefChip16.exe and b/Release/RefChip16.exe differ