Skip to content

Commit

Permalink
Properly limit the framerate to 60 + Upgrade to VS2022
Browse files Browse the repository at this point in the history
High refresh rate monitors were running too fast, sorry!
  • Loading branch information
refractionpcsx2 committed Jan 19, 2024
1 parent b7204e7 commit dd68638
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
25 changes: 25 additions & 0 deletions RefChip16/D3DApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions RefChip16/D3DApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#ifndef _D3DAPP_H
#define _D3DAPP_H

#include <d3d9.h>
#include <d3dx9.h>
#include <SDL.h>
#include <SDL_syswm.h>

Expand Down
11 changes: 5 additions & 6 deletions RefChip16/RefChip16.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,28 @@
<ProjectGuid>{F1F60059-1254-41A6-A847-6E7C959A5E3B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>RefChip16</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>NotSet</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>NotSet</CharacterSet>
<CLRSupport>false</CLRSupport>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Test|Win32'">
<UseOfMfc>Dynamic</UseOfMfc>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Test|Win32'">
<CLRSupport>false</CLRSupport>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -74,7 +73,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WINDOWS_IGNORE_PACKING_MISMATCH;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
<IntrinsicFunctions>false</IntrinsicFunctions>
Expand All @@ -96,7 +95,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WINDOWS_IGNORE_PACKING_MISMATCH;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>
</AdditionalIncludeDirectories>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
Expand Down
1 change: 1 addition & 0 deletions RefChip16/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <tchar.h>
#include <windows.h>
#include "resource.h"
#include <commdlg.h>
/*#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>*/
Expand Down
Binary file modified Release/RefChip16.exe
Binary file not shown.

0 comments on commit dd68638

Please sign in to comment.