From 02319832d47f3165dc1d3784ec67f5c1f1dbaa10 Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Tue, 25 Jan 2022 22:05:17 +0200 Subject: [PATCH] [sdl] small cleanup --- src/celestia/sdl/sdlmain.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/celestia/sdl/sdlmain.cpp b/src/celestia/sdl/sdlmain.cpp index 48685a2b7..cc3a83bc9 100644 --- a/src/celestia/sdl/sdlmain.cpp +++ b/src/celestia/sdl/sdlmain.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,7 @@ class SDL_Application { public: SDL_Application() = delete; - SDL_Application(const std::string name, int w, int h) : + SDL_Application(std::string_view name, int w, int h) : m_appName { name }, m_windowWidth { w }, m_windowHeight { h } @@ -54,13 +55,13 @@ class SDL_Application } ~SDL_Application(); - static std::shared_ptr init(const std::string, int, int); + static std::shared_ptr init(std::string_view, int, int); bool createOpenGLWindow(); bool initCelestiaCore(); void run(); - const char* getError() const; + std::string_view getError() const; private: void display(); @@ -97,7 +98,7 @@ class SDL_Application }; std::shared_ptr -SDL_Application::init(const std::string name, int w, int h) +SDL_Application::init(std::string_view name, int w, int h) { if (SDL_Init(SDL_INIT_VIDEO) < 0) return nullptr; @@ -109,7 +110,7 @@ SDL_Application::init(const std::string name, int w, int h) SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); #endif - return std::shared_ptr(new SDL_Application(std::move(name), w, h)); + return std::make_shared(name, w, h); } SDL_Application::~SDL_Application() @@ -145,7 +146,7 @@ SDL_Application::createOpenGLWindow() return true; } -const char* +std::string_view SDL_Application::getError() const { return SDL_GetError(); @@ -541,7 +542,8 @@ FatalError(const std::string &message) std::cerr << message << std::endl; } -void DumpGLInfo() +void +DumpGLInfo() { const char* s; s = reinterpret_cast(glGetString(GL_VERSION)); @@ -560,11 +562,9 @@ void DumpGLInfo() if (s != nullptr) std::cout << s << '\n'; } -} // namespace -using namespace celestia; - -int main(int argc, char **argv) +int +sdlmain(int /* argc */, char ** /* argv */) { setlocale(LC_ALL, ""); setlocale(LC_NUMERIC, "C"); @@ -620,3 +620,10 @@ int main(int argc, char **argv) return 0; } +} // namespace + +int +main(int argc, char **argv) +{ + return celestia::sdlmain(argc, argv); +}