Skip to content

Commit ed86f3c

Browse files
committed
[Engine] Rewrote system launcher application
1 parent dcf7786 commit ed86f3c

File tree

2 files changed

+53
-25
lines changed

2 files changed

+53
-25
lines changed

src/docs/Changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2025-03-31 Dusan Jocic <dusanjocic@msn>
2+
* [Engine] Rewrote system launcher application
3+
14
2025-03-27 Dusan Jocic <dusanjocic@msn>
25
* [Engine] Misc fixes
36

src/engine/platform/systemLauncher.cpp

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
////////////////////////////////////////////////////////////////////////////////////////
1+
////////////////////////////////////////////////////////////////////////////////////////
22
// Copyright(C) 2019 - 2025 Dusan Jocic <dusanjocic@msn.com>
33
//
44
// This file is part of OpenWolf.
@@ -19,7 +19,7 @@
1919
//
2020
// -------------------------------------------------------------------------------------
2121
// File name: systemLauncher.cpp
22-
// Version: v1.01
22+
// Version: v1.02
2323
// Created: 11/06/2019
2424
// Compilers: Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28806 for x64,
2525
// gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0,
@@ -38,40 +38,65 @@
3838

3939
#include <iostream>
4040
#include <string>
41-
#include <stdexcept>
41+
#include <memory>
4242

43-
int main(int argc, char **argv) {
44-
std::string dynName;
45-
#if defined (_WIN32)
46-
dynName = "engine.AMD64.dll";
47-
#elif defined (__LINUX__)
48-
dynName = "./engine.x86_64.so";
43+
#ifdef _WIN32
44+
constexpr const char* ENGINE_LIB = "engine.AMD64.dll";
45+
#elif defined(__LINUX__)
46+
constexpr const char* ENGINE_LIB = "./engine.x86_64.so";
4947
#else
50-
dynName = "./engine.x86_64.dylib";
48+
constexpr const char* ENGINE_LIB = "./engine.x86_64.dylib";
5149
#endif
52-
const std::string engineExportName = "engineMain";
5350

54-
SDL_Init(0);
55-
const auto libraryHandle = SDL_LoadObject(dynName.c_str());
51+
constexpr const char* ENGINE_EXPORT_FUNC = "engineMain";
52+
53+
typedef int (*EngineMainFunc)(int, char**);
54+
55+
/*
56+
=================
57+
LoadEngine
58+
=================
59+
*/
60+
bool LoadEngine(std::unique_ptr<void, decltype(&SDL_UnloadObject)>& libraryHandle, EngineMainFunc& engineMain) {
61+
libraryHandle.reset(SDL_LoadObject(ENGINE_LIB));
5662

57-
if(libraryHandle == nullptr) {
58-
throw std::runtime_error("Failed to load library: " + std::string(
59-
SDL_GetError()));
63+
if (!libraryHandle) {
64+
std::cerr << "[ERROR] Failed to load library: " << SDL_GetError() << std::endl;
65+
return false;
6066
}
6167

62-
const auto engineMain = reinterpret_cast<int(*)(int, char **)>
63-
(SDL_LoadFunction(libraryHandle, engineExportName.c_str()));
68+
engineMain = reinterpret_cast<EngineMainFunc>(SDL_LoadFunction(libraryHandle.get(), ENGINE_EXPORT_FUNC));
6469

65-
if(engineMain == nullptr) {
66-
throw std::runtime_error("Failed to find function: " + std::string(
67-
SDL_GetError()));
70+
if (!engineMain) {
71+
std::cerr << "[ERROR] Failed to find function: " << SDL_GetError() << std::endl;
72+
return false;
73+
}
74+
75+
return true;
76+
}
77+
78+
/*
79+
=================
80+
main
81+
=================
82+
*/
83+
int main(int argc, char** argv) {
84+
if (SDL_Init(0) != 0) {
85+
std::cerr << "[ERROR] SDL initialization failed: " << SDL_GetError() << std::endl;
86+
return EXIT_FAILURE;
87+
}
88+
89+
std::unique_ptr<void, decltype(&SDL_UnloadObject)> libraryHandle(nullptr, SDL_UnloadObject);
90+
EngineMainFunc engineMain = nullptr;
91+
92+
if (!LoadEngine(libraryHandle, engineMain)) {
93+
std::cerr << "[ERROR] Engine failed to load. Exiting..." << std::endl;
94+
SDL_Quit();
95+
return EXIT_FAILURE;
6896
}
6997

7098
engineMain(argc, argv);
7199

72-
SDL_UnloadObject(libraryHandle);
73100
SDL_Quit();
74-
75-
return 0;
101+
return EXIT_SUCCESS;
76102
}
77-

0 commit comments

Comments
 (0)