Skip to content

Commit

Permalink
Review main (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbatalov authored Feb 15, 2025
1 parent d631bfc commit 2de7472
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 39 deletions.
8 changes: 0 additions & 8 deletions src/audio_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ static void audioEngineMixin(void* userData, Uint8* stream, int length)

bool audioEngineInit()
{
if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) {
return false;
}

SDL_AudioSpec desiredSpec;
desiredSpec.freq = 22050;
desiredSpec.format = AUDIO_S16;
Expand All @@ -122,10 +118,6 @@ void audioEngineExit()
SDL_CloseAudioDevice(gAudioEngineDeviceId);
gAudioEngineDeviceId = -1;
}

if (SDL_WasInit(SDL_INIT_AUDIO)) {
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
}

void audioEnginePause()
Expand Down
5 changes: 0 additions & 5 deletions src/dinput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ static int gMouseWheelDeltaY = 0;
// 0x4E0400
bool directInputInit()
{
if (SDL_InitSubSystem(SDL_INIT_EVENTS) != 0) {
return false;
}

if (!mouseDeviceInit()) {
goto err;
}
Expand All @@ -32,7 +28,6 @@ bool directInputInit()
// 0x4E0478
void directInputFree()
{
SDL_QuitSubSystem(SDL_INIT_EVENTS);
}

// 0x4E04E8
Expand Down
4 changes: 0 additions & 4 deletions src/svga.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ int _GNW95_init_window(int width, int height, bool fullscreen, int scale)
if (gSdlWindow == nullptr) {
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");

if (SDL_Init(SDL_INIT_VIDEO) != 0) {
return -1;
}

Uint32 windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_ALLOW_HIGHDPI;

if (fullscreen) {
Expand Down
42 changes: 23 additions & 19 deletions src/win32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,24 @@

namespace fallout {

#ifdef _WIN32
// 0x51E444
bool gProgramIsActive = false;

// GNW95MUTEX
HANDLE _GNW95_mutex = nullptr;
#ifdef _WIN32
HANDLE GNW95_mutex = nullptr;
#endif

// 0x4DE700
int main(int argc, char* argv[])
{
_GNW95_mutex = CreateMutexA(0, TRUE, "GNW95MUTEX");
if (GetLastError() == ERROR_SUCCESS) {
SDL_ShowCursor(SDL_DISABLE);
int rc;

gProgramIsActive = true;
falloutMain(argc, argv);

CloseHandle(_GNW95_mutex);
#if _WIN32
GNW95_mutex = CreateMutexA(0, TRUE, "GNW95MUTEX");
if (GetLastError() != ERROR_SUCCESS) {
return 0;
}
return 0;
}
#else
bool gProgramIsActive = false;
#endif

int main(int argc, char* argv[])
{
#if __APPLE__ && TARGET_OS_IOS
SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0");
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
Expand All @@ -62,12 +54,24 @@ int main(int argc, char* argv[])
chdir(SDL_AndroidGetExternalStoragePath());
#endif

if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) {
return EXIT_FAILURE;
}

atexit(SDL_Quit);

SDL_ShowCursor(SDL_DISABLE);

gProgramIsActive = true;
return falloutMain(argc, argv);
}
rc = falloutMain(argc, argv);

#if _WIN32
CloseHandle(GNW95_mutex);
#endif

return rc;
}

} // namespace fallout

int main(int argc, char* argv[])
Expand Down
2 changes: 1 addition & 1 deletion src/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace fallout {

#ifdef _WIN32
extern bool gProgramIsActive;
extern HANDLE _GNW95_mutex;
extern HANDLE GNW95_mutex;
#else
extern bool gProgramIsActive;
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ static ButtonGroup gButtonGroups[BUTTON_GROUP_LIST_CAPACITY];
int windowManagerInit(VideoSystemInitProc* videoSystemInitProc, VideoSystemExitProc* videoSystemExitProc, int a3)
{
#ifdef _WIN32
CloseHandle(_GNW95_mutex);
_GNW95_mutex = INVALID_HANDLE_VALUE;
CloseHandle(GNW95_mutex);
GNW95_mutex = INVALID_HANDLE_VALUE;
#endif

if (_GNW95_already_running) {
Expand Down

0 comments on commit 2de7472

Please sign in to comment.