1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-22 08:50:18 +01:00

Compare commits

...

2 commits

Author SHA1 Message Date
Muzychenko Andrey
bbbdb2d9d4 Fixed off by one in frame time tool. 2021-11-13 15:48:16 +03:00
Gábor Dobra
585a2f7113
Minor performance optimizations (#89)
* Optimize performance by calling FreePlayedBlocks rarely

Don't call it at every main loop iteration, only after someTime.

* Optimize more aggressively in Release mode
2021-11-13 14:36:22 +03:00
6 changed files with 30 additions and 22 deletions

View file

@ -114,10 +114,10 @@ void Sound::Enable(int channelFrom, int channelTo, int enableFlag)
} }
} }
void Sound::Idle() void Sound::Idle(bool performCleanup)
{ {
if (pMem) if (pMem)
WaveMix::Pump(); WaveMix::Pump(performCleanup);
} }
void Sound::Activate() void Sound::Activate()

View file

@ -6,7 +6,7 @@ class Sound
public: public:
static int Init(HINSTANCE hInstance, int voices, void (* someFuncPtr)(int, MIXWAVE*, int)); static int Init(HINSTANCE hInstance, int voices, void (* someFuncPtr)(int, MIXWAVE*, int));
static void Enable(int channelFrom, int channelTo, int enableFlag); static void Enable(int channelFrom, int channelTo, int enableFlag);
static void Idle(); static void Idle(bool performCleanup = true);
static void Activate(); static void Activate();
static void Deactivate(); static void Deactivate();
static void Close(); static void Close();

View file

@ -308,6 +308,8 @@
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
@ -350,6 +352,8 @@
<ConformanceMode>false</ConformanceMode> <ConformanceMode>false</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
@ -392,6 +396,8 @@
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
@ -434,6 +440,8 @@
<ConformanceMode>false</ConformanceMode> <ConformanceMode>false</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>

View file

@ -550,7 +550,7 @@ int WaveMix::Activate(HANDLE hMixSession, bool fActivate)
return 0; return 0;
} }
void WaveMix::Pump() void WaveMix::Pump(bool performCleanup)
{ {
Globals = GlobalsActive; Globals = GlobalsActive;
if (GlobalsActive) if (GlobalsActive)
@ -567,6 +567,7 @@ void WaveMix::Pump()
else else
xHDR = xHDR->QNext; xHDR = xHDR->QNext;
} }
if (performCleanup)
FreePlayedBlocks(); FreePlayedBlocks();
while (MixerPlay(GetWaveBlock(), 1)); while (MixerPlay(GetWaveBlock(), 1));
} }
@ -1382,12 +1383,12 @@ int WaveMix::GetConfig(HANDLE hMixSession, MIXCONFIG* lpConfig)
unsigned WaveMix::MyWaveOutGetPosition(HWAVEOUT hWaveOut, int fGoodGetPos) unsigned WaveMix::MyWaveOutGetPosition(HWAVEOUT hWaveOut, int fGoodGetPos)
{ {
mmtime_tag pmmt{}; MMTIME pmmt{};
if (!fGoodGetPos) if (!fGoodGetPos)
return (timeGetTime() - Globals->dwBaseTime) * Globals->PCM.wf.nAvgBytesPerSec / 0x3E8 & 0xFFFFFFF8; return (timeGetTime() - Globals->dwBaseTime) * Globals->PCM.wf.nAvgBytesPerSec / 0x3E8 & 0xFFFFFFF8;
pmmt.wType = TIME_BYTES; pmmt.wType = TIME_BYTES;
waveOutGetPosition(hWaveOut, &pmmt, 0xCu); waveOutGetPosition(hWaveOut, &pmmt, sizeof(MMTIME));
return Globals->pfnSampleAdjust(pmmt.u.ms, Globals->dwWaveOutPos); return Globals->pfnSampleAdjust(pmmt.u.ms, Globals->dwWaveOutPos);
} }

View file

@ -151,7 +151,7 @@ public:
static MIXWAVE* OpenWave(HANDLE hMixSession, LPCSTR szWaveFilename, HINSTANCE hInst, unsigned int dwFlags); static MIXWAVE* OpenWave(HANDLE hMixSession, LPCSTR szWaveFilename, HINSTANCE hInst, unsigned int dwFlags);
static int FreeWave(HANDLE hMixSession, MIXWAVE* lpMixWave); static int FreeWave(HANDLE hMixSession, MIXWAVE* lpMixWave);
static int Activate(HANDLE hMixSession, bool fActivate); static int Activate(HANDLE hMixSession, bool fActivate);
static void Pump(); static void Pump(bool performCleanup = true);
static int Play(MIXPLAYPARAMS* lpMixPlayParams); static int Play(MIXPLAYPARAMS* lpMixPlayParams);
private: private:

View file

@ -228,9 +228,10 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
float sleepRemainder = 0, frameDuration = TargetFrameTime; float sleepRemainder = 0, frameDuration = TargetFrameTime;
while (true) while (true)
{ {
if (!someTimeCounter) if (someTimeCounter == 0)
{ {
someTimeCounter = 300; someTimeCounter = 300;
if (DispFrameRate) if (DispFrameRate)
{ {
auto curTime = timeGetTime(); auto curTime = timeGetTime();
@ -257,7 +258,10 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
} }
} }
Sound::Idle(); // Don't look for and free already played blocks at every single frame,
// as it is quite costly to look up. Only do that "sometimes".
bool performSoundCleanup = someTimeCounter == 300;
Sound::Idle(performSoundCleanup);
if (!ProcessWindowMessages() || bQuit) if (!ProcessWindowMessages() || bQuit)
break; break;
@ -286,25 +290,20 @@ int winmain::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
if (DispGRhistory) if (DispGRhistory)
{ {
auto width = render::vscreen.Width / 2; auto width = render::vscreen.Width / 2;
auto height = 64; auto height = 64, halfHeight = height / 2;
if (!gfr_display.BmpBufPtr1) if (!gfr_display.BmpBufPtr1)
{ {
gdrv::create_bitmap(&gfr_display, width, height); gdrv::create_bitmap(&gfr_display, width, height);
} }
gdrv::ScrollBitmapHorizontal(&gfr_display, -1); gdrv::ScrollBitmapHorizontal(&gfr_display, -1);
gdrv::fill_bitmap(&gfr_display, 1, halfHeight, width - 1, 0, 0); // Background
gdrv::fill_bitmap(&gfr_display, 1, halfHeight, width - 1, halfHeight, -1); // Target
float target = TargetFrameTime; auto scale = halfHeight / TargetFrameTime;
auto scale = height / target / 2; auto diffHeight = min(static_cast<int>(std::round(std::abs(TargetFrameTime - dt) * scale)), halfHeight);
gdrv::fill_bitmap(&gfr_display, 1, height, width - 1, 0, 0); // Background auto yOffset = dt < TargetFrameTime ? halfHeight : halfHeight - diffHeight;
gdrv::fill_bitmap(&gfr_display, 1, diffHeight, width - 1, yOffset, 1); // Target diff
auto targetVal = dt < target ? dt : target;
auto targetHeight = min(static_cast<int>(std::floor(targetVal * scale)), height);
gdrv::fill_bitmap(&gfr_display, 1, targetHeight, width - 1, height - targetHeight, -1); // Target
auto diffVal = dt < target ? target - dt : dt - target;
auto diffHeight = min(static_cast<int>(std::floor(diffVal * scale)), height);
gdrv::fill_bitmap(&gfr_display, 1, diffHeight, width - 1, height - targetHeight - diffHeight, 1); // Target diff
gdrv::blit(&gfr_display, 0, 0, render::vscreen.Width - width, 0, width, height); gdrv::blit(&gfr_display, 0, 0, render::vscreen.Width - width, 0, width, height);
} }