From d80074b9b6f09879ea8b05935084127b62bc2d15 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Sat, 9 Oct 2021 12:33:33 +0300 Subject: [PATCH] Added Windows subsystem entry point for release builds. --- CMakeSettings.json | 10 +++---- SpaceCadetPinball/SpaceCadetPinball.cpp | 40 ++++++++++++++++--------- SpaceCadetPinball/midi.h | 30 +++++++++---------- SpaceCadetPinball/pch.h | 1 - SpaceCadetPinball/winmain.cpp | 2 +- 5 files changed, 46 insertions(+), 37 deletions(-) diff --git a/CMakeSettings.json b/CMakeSettings.json index 463eeb0..2ae5905 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -28,11 +28,10 @@ "configurationType": "Release", "buildRoot": "${projectDir}\\out\\build\\${name}", "installRoot": "${projectDir}\\out\\install\\${name}", - "cmakeCommandArgs": "", + "cmakeCommandArgs": "-DCMAKE_WIN32_EXECUTABLE:BOOL=1", "buildCommandArgs": "", "ctestCommandArgs": "", - "inheritEnvironments": [ "msvc_x86" ], - "variables": [] + "inheritEnvironments": [ "msvc_x86" ] }, { "name": "x64-Release", @@ -40,11 +39,10 @@ "configurationType": "Release", "buildRoot": "${projectDir}\\out\\build\\${name}", "installRoot": "${projectDir}\\out\\install\\${name}", - "cmakeCommandArgs": "", + "cmakeCommandArgs": "-DCMAKE_WIN32_EXECUTABLE:BOOL=1", "buildCommandArgs": "", "ctestCommandArgs": "", - "inheritEnvironments": [ "msvc_x64_x64" ], - "variables": [] + "inheritEnvironments": [ "msvc_x64_x64" ] } ] } \ No newline at end of file diff --git a/SpaceCadetPinball/SpaceCadetPinball.cpp b/SpaceCadetPinball/SpaceCadetPinball.cpp index 565a93d..e639ce8 100644 --- a/SpaceCadetPinball/SpaceCadetPinball.cpp +++ b/SpaceCadetPinball/SpaceCadetPinball.cpp @@ -5,25 +5,37 @@ #include "winmain.h" +int MainActual(LPCSTR lpCmdLine) +{ + // Todo: get rid of restart to change resolution. + int returnCode; + do + { + returnCode = winmain::WinMain(lpCmdLine); + } + while (winmain::RestartRequested()); + return returnCode; +} + int main(int argc, char* argv[]) { - { - // Testing with UI - std::string cmdLine; - for (int i = 0; i < argc; i++) - cmdLine += argv[i]; + std::string cmdLine; + for (int i = 1; i < argc; i++) + cmdLine += argv[i]; - // Todo: get rid of restart to change resolution. - int returnCode; - do - { - returnCode = winmain::WinMain(cmdLine.c_str()); - } - while (winmain::RestartRequested()); - return returnCode; - } + return MainActual(cmdLine.c_str()); } +#if _WIN32 +#include + +// Windows subsystem main +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) +{ + return MainActual(lpCmdLine); +} +#endif + // Run program: Ctrl + F5 or Debug > Start Without Debugging menu // Debug program: F5 or Debug > Start Debugging menu diff --git a/SpaceCadetPinball/midi.h b/SpaceCadetPinball/midi.h index 15a4842..91441b8 100644 --- a/SpaceCadetPinball/midi.h +++ b/SpaceCadetPinball/midi.h @@ -17,36 +17,36 @@ constexpr uint16_t SwapByteOrderShort(uint16_t val) #pragma pack(1) struct riff_block { - DWORD TkStart; - DWORD CbBuffer; + uint32_t TkStart; + uint32_t CbBuffer; char AData[4]; }; struct riff_data { - DWORD Data; - DWORD DataSize; - DWORD BlocksPerChunk; + uint32_t Data; + uint32_t DataSize; + uint32_t BlocksPerChunk; riff_block Blocks[1]; }; struct riff_header { - DWORD Riff; - DWORD FileSize; - DWORD Mids; - DWORD Fmt; - DWORD FmtSize; - DWORD dwTimeFormat; - DWORD cbMaxBuffer; - DWORD dwFlags; + uint32_t Riff; + uint32_t FileSize; + uint32_t Mids; + uint32_t Fmt; + uint32_t FmtSize; + uint32_t dwTimeFormat; + uint32_t cbMaxBuffer; + uint32_t dwFlags; riff_data Data; }; struct midi_event { - DWORD iTicks; - DWORD iEvent; + uint32_t iTicks; + uint32_t iEvent; }; struct midi_header diff --git a/SpaceCadetPinball/pch.h b/SpaceCadetPinball/pch.h index 969ad8b..c1fa767 100644 --- a/SpaceCadetPinball/pch.h +++ b/SpaceCadetPinball/pch.h @@ -41,7 +41,6 @@ //https://github.com/Tyyppi77/imgui_sdl 01deb04b102b6a1c15c7fdec1977a2c96a885e6f #include "imgui_sdl.h" -typedef uint32_t DWORD; typedef char* LPSTR; typedef const char* LPCSTR; diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index 57114e5..2f88544 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -152,7 +152,7 @@ int winmain::WinMain(LPCSTR lpCmdLine) else pb::replay_level(0); - DWORD dtHistoryCounter = 300u, updateCounter = 0, frameCounter = 0; + unsigned dtHistoryCounter = 300u, updateCounter = 0, frameCounter = 0; auto frameStart = Clock::now(); double UpdateToFrameCounter = 0;