Index: ddraw/timer.cpp |
— | — | @@ -1,74 +0,0 @@ |
2 | | -// DXGL
|
3 | | -// Copyright (C) 2013 William Feely
|
4 | | -
|
5 | | -// This library is free software; you can redistribute it and/or
|
6 | | -// modify it under the terms of the GNU Lesser General Public
|
7 | | -// License as published by the Free Software Foundation; either
|
8 | | -// version 2.1 of the License, or (at your option) any later version.
|
9 | | -
|
10 | | -// This library is distributed in the hope that it will be useful,
|
11 | | -// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | | -// Lesser General Public License for more details.
|
14 | | -
|
15 | | -// You should have received a copy of the GNU Lesser General Public
|
16 | | -// License along with this library; if not, write to the Free Software
|
17 | | -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | | -
|
19 | | -#include "common.h"
|
20 | | -#include "timer.h"
|
21 | | -
|
22 | | -DXGLTimer::DXGLTimer()
|
23 | | -{
|
24 | | - TIMECAPS mmcaps;
|
25 | | - LARGE_INTEGER freq;
|
26 | | - timertype = 0;
|
27 | | - freq.QuadPart = 0;
|
28 | | - QueryPerformanceFrequency(&freq);
|
29 | | - if (!freq.QuadPart)
|
30 | | - {
|
31 | | - timeGetDevCaps(&mmcaps, sizeof(TIMECAPS));
|
32 | | - timeBeginPeriod(mmcaps.wPeriodMin);
|
33 | | - timer_frequency = ((double) mmcaps.wPeriodMin / 1.0) * 1000.0;
|
34 | | - timertype = 2;
|
35 | | - }
|
36 | | - else
|
37 | | - {
|
38 | | - timer_frequency = (double)freq.QuadPart;
|
39 | | - timertype = 1;
|
40 | | - }
|
41 | | -}
|
42 | | -
|
43 | | -void DXGLTimer::Calibrate(unsigned int lines, unsigned int frequency)
|
44 | | -{
|
45 | | - monitor_period = (double) frequency / 1000.0;
|
46 | | - if (timertype == 1)
|
47 | | - {
|
48 | | - QueryPerformanceCounter(&timer_base);
|
49 | | - vsync_lines = 16;
|
50 | | - this->lines = lines + vsync_lines;
|
51 | | - }
|
52 | | - else
|
53 | | - {
|
54 | | - timer_base.QuadPart = timeGetTime();
|
55 | | - double linesperms = (double) lines / ((1.0 / (double) frequency) * 1000.0);
|
56 | | - vsync_lines = linesperms * (frequency / 1000.0);
|
57 | | - this->lines = lines + vsync_lines;
|
58 | | - }
|
59 | | -}
|
60 | | -
|
61 | | -unsigned int DXGLTimer::GetScanLine()
|
62 | | -{
|
63 | | - LARGE_INTEGER timerpos;
|
64 | | - double sync_pos;
|
65 | | - if (timertype == 1) QueryPerformanceCounter(&timerpos);
|
66 | | - else timerpos.QuadPart = timeGetTime();
|
67 | | - timerpos.QuadPart -= timer_base.QuadPart;
|
68 | | - double milliseconds;
|
69 | | - if (timertype == 1) milliseconds = ((double) timerpos.QuadPart / (double)timer_frequency) * 1000.0;
|
70 | | - else milliseconds = (double) timerpos.QuadPart;
|
71 | | - sync_pos = fmod(milliseconds, monitor_period);
|
72 | | - sync_pos /= monitor_period;
|
73 | | - sync_pos *= (double)lines;
|
74 | | - return sync_pos;
|
75 | | -} |
\ No newline at end of file |
Index: ddraw/common.h |
— | — | @@ -116,7 +116,5 @@ |
117 | 117 | extern CRITICAL_SECTION dll_cs;
|
118 | 118 |
|
119 | 119 | #include "trace.h"
|
120 | | -#ifdef __cplusplus
|
121 | 120 | #include "../cfgmgr/cfgmgr.h"
|
122 | | -#endif
|
123 | 121 | #endif //_COMMON_H
|
Index: ddraw/ddraw.vcxproj |
— | — | @@ -393,7 +393,14 @@ |
394 | 394 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
395 | 395 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">NotUsing</PrecompiledHeader>
|
396 | 396 | </ClCompile>
|
397 | | - <ClCompile Include="timer.cpp" />
|
| 397 | + <ClCompile Include="timer.c">
|
| 398 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
|
| 399 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
| 400 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
| 401 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
| 402 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
| 403 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">NotUsing</PrecompiledHeader>
|
| 404 | + </ClCompile>
|
398 | 405 | <ClCompile Include="trace.c">
|
399 | 406 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
|
400 | 407 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
Index: ddraw/ddraw.vcxproj.filters |
— | — | @@ -199,9 +199,6 @@ |
200 | 200 | <ClCompile Include="glDirect3DExecuteBuffer.cpp">
|
201 | 201 | <Filter>Source Files</Filter>
|
202 | 202 | </ClCompile>
|
203 | | - <ClCompile Include="timer.cpp">
|
204 | | - <Filter>Source Files</Filter>
|
205 | | - </ClCompile>
|
206 | 203 | <ClCompile Include="glUtil.cpp">
|
207 | 204 | <Filter>Source Files</Filter>
|
208 | 205 | </ClCompile>
|
— | — | @@ -235,6 +232,9 @@ |
236 | 233 | <ClCompile Include="ShaderGen2D.cpp">
|
237 | 234 | <Filter>Source Files</Filter>
|
238 | 235 | </ClCompile>
|
| 236 | + <ClCompile Include="timer.c">
|
| 237 | + <Filter>Source Files</Filter>
|
| 238 | + </ClCompile>
|
239 | 239 | </ItemGroup>
|
240 | 240 | <ItemGroup>
|
241 | 241 | <ResourceCompile Include="ddraw.rc">
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -683,7 +683,7 @@ |
684 | 684 | */
|
685 | 685 | unsigned int glRenderer_GetScanLine(glRenderer *This)
|
686 | 686 | {
|
687 | | - return This->timer.GetScanLine();
|
| 687 | + return DXGLTimer_GetScanLine(&This->timer);
|
688 | 688 | }
|
689 | 689 |
|
690 | 690 | /**
|
— | — | @@ -888,7 +888,8 @@ |
889 | 889 | glRenderer__SetSwap(This,1);
|
890 | 890 | SwapBuffers(This->hDC);
|
891 | 891 | glFinish();
|
892 | | - This->timer.Calibrate(height, frequency);
|
| 892 | + DXGLTimer_Init(&This->timer);
|
| 893 | + DXGLTimer_Calibrate(&This->timer, height, frequency);
|
893 | 894 | glRenderer__SetSwap(This,0);
|
894 | 895 | This->util->SetViewport(0,0,width,height);
|
895 | 896 | glViewport(0,0,width,height);
|
— | — | @@ -1698,7 +1699,8 @@ |
1699 | 1700 | LeaveCriticalSection(&dll_cs);
|
1700 | 1701 | glRenderer__SetSwap(This,1);
|
1701 | 1702 | SwapBuffers(This->hDC);
|
1702 | | - This->timer.Calibrate(height, frequency);
|
| 1703 | + DXGLTimer_Init(&This->timer);
|
| 1704 | + DXGLTimer_Calibrate(&This->timer, height, frequency);
|
1703 | 1705 | glRenderer__SetSwap(This,0);
|
1704 | 1706 | This->util->SetViewport(0,0,width,height);
|
1705 | 1707 | }
|
Index: ddraw/timer.c |
— | — | @@ -0,0 +1,76 @@ |
| 2 | +// DXGL
|
| 3 | +// Copyright (C) 2013 William Feely
|
| 4 | +
|
| 5 | +// This library is free software; you can redistribute it and/or
|
| 6 | +// modify it under the terms of the GNU Lesser General Public
|
| 7 | +// License as published by the Free Software Foundation; either
|
| 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| 9 | +
|
| 10 | +// This library is distributed in the hope that it will be useful,
|
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 | +// Lesser General Public License for more details.
|
| 14 | +
|
| 15 | +// You should have received a copy of the GNU Lesser General Public
|
| 16 | +// License along with this library; if not, write to the Free Software
|
| 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | +
|
| 19 | +#include "common.h"
|
| 20 | +#include <math.h>
|
| 21 | +#include "timer.h"
|
| 22 | +
|
| 23 | +void DXGLTimer_Init(DXGLTimer *timer)
|
| 24 | +{
|
| 25 | + TIMECAPS mmcaps;
|
| 26 | + LARGE_INTEGER freq;
|
| 27 | + timer->timertype = 0;
|
| 28 | + freq.QuadPart = 0;
|
| 29 | + QueryPerformanceFrequency(&freq);
|
| 30 | + if (!freq.QuadPart)
|
| 31 | + {
|
| 32 | + timeGetDevCaps(&mmcaps, sizeof(TIMECAPS));
|
| 33 | + timeBeginPeriod(mmcaps.wPeriodMin);
|
| 34 | + timer->timer_frequency = ((double) mmcaps.wPeriodMin / 1.0) * 1000.0;
|
| 35 | + timer->timertype = 2;
|
| 36 | + }
|
| 37 | + else
|
| 38 | + {
|
| 39 | + timer->timer_frequency = (double)freq.QuadPart;
|
| 40 | + timer->timertype = 1;
|
| 41 | + }
|
| 42 | +}
|
| 43 | +
|
| 44 | +void DXGLTimer_Calibrate(DXGLTimer *timer, unsigned int lines, unsigned int frequency)
|
| 45 | +{
|
| 46 | + double linesperms;
|
| 47 | + timer->monitor_period = (double) frequency / 1000.0;
|
| 48 | + if (timer->timertype == 1)
|
| 49 | + {
|
| 50 | + QueryPerformanceCounter(&timer->timer_base);
|
| 51 | + timer->vsync_lines = 16;
|
| 52 | + timer->lines = lines + timer->vsync_lines;
|
| 53 | + }
|
| 54 | + else
|
| 55 | + {
|
| 56 | + timer->timer_base.QuadPart = timeGetTime();
|
| 57 | + linesperms = (double) lines / ((1.0 / (double) frequency) * 1000.0);
|
| 58 | + timer->vsync_lines = (unsigned int)(linesperms * (frequency / 1000.0));
|
| 59 | + timer->lines = lines + timer->vsync_lines;
|
| 60 | + }
|
| 61 | +}
|
| 62 | +
|
| 63 | +unsigned int DXGLTimer_GetScanLine(DXGLTimer *timer)
|
| 64 | +{
|
| 65 | + LARGE_INTEGER timerpos;
|
| 66 | + double sync_pos;
|
| 67 | + double milliseconds;
|
| 68 | + if (timer->timertype == 1) QueryPerformanceCounter(&timerpos);
|
| 69 | + else timerpos.QuadPart = timeGetTime();
|
| 70 | + timerpos.QuadPart -= timer->timer_base.QuadPart;
|
| 71 | + if (timer->timertype == 1) milliseconds = ((double) timerpos.QuadPart / (double)timer->timer_frequency) * 1000.0;
|
| 72 | + else milliseconds = (double) timerpos.QuadPart;
|
| 73 | + sync_pos = fmod(milliseconds, timer->monitor_period);
|
| 74 | + sync_pos /= timer->monitor_period;
|
| 75 | + sync_pos *= (double)timer->lines;
|
| 76 | + return (unsigned int)sync_pos;
|
| 77 | +} |
\ No newline at end of file |
Index: ddraw/timer.h |
— | — | @@ -19,13 +19,12 @@ |
20 | 20 | #ifndef _TIMER_H
|
21 | 21 | #define _TIMER_H
|
22 | 22 |
|
23 | | -class DXGLTimer
|
| 23 | +#ifdef __cplusplus
|
| 24 | +extern "C" {
|
| 25 | +#endif
|
| 26 | +
|
| 27 | +typedef struct DXGLTimer
|
24 | 28 | {
|
25 | | -public:
|
26 | | - DXGLTimer();
|
27 | | - void Calibrate(unsigned int lines, unsigned int frequency);
|
28 | | - unsigned int GetScanLine();
|
29 | | -private:
|
30 | 29 | int timertype;
|
31 | 30 | unsigned int lines;
|
32 | 31 | unsigned int vsync_lines;
|
— | — | @@ -32,6 +31,15 @@ |
33 | 32 | double monitor_period;
|
34 | 33 | double timer_frequency;
|
35 | 34 | LARGE_INTEGER timer_base;
|
36 | | -};
|
| 35 | +} DXGLTimer;
|
37 | 36 |
|
| 37 | +void DXGLTimer_Init(DXGLTimer *timer);
|
| 38 | +void DXGLTimer_Calibrate(DXGLTimer *timer, unsigned int lines, unsigned int frequency);
|
| 39 | +unsigned int DXGLTimer_GetScanLine(DXGLTimer *timer);
|
| 40 | +
|
| 41 | +#ifdef __cplusplus
|
| 42 | +}
|
| 43 | +#endif
|
| 44 | +
|
| 45 | +
|
38 | 46 | #endif |
\ No newline at end of file |