Use ad-hoc pimpl instead of util::pimpl for app
This commit is contained in:
parent
ebe8ecfe55
commit
3ab93d21a7
2 changed files with 32 additions and 32 deletions
|
|
@ -1,13 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL_keycode.h>
|
#include <SDL2/SDL_keycode.h>
|
||||||
#include <psemek/util/pimpl.hpp>
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace psemek::app
|
namespace psemek::app
|
||||||
{
|
{
|
||||||
|
|
||||||
struct app
|
struct app
|
||||||
: util::pimpl::dynamic<app>
|
|
||||||
{
|
{
|
||||||
app(std::string const & name);
|
app(std::string const & name);
|
||||||
virtual ~app();
|
virtual ~app();
|
||||||
|
|
@ -39,6 +39,12 @@ namespace psemek::app
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
void show_cursor(bool show);
|
void show_cursor(bool show);
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct impl;
|
||||||
|
std::unique_ptr<impl> pimpl_;
|
||||||
|
struct impl & impl() { return *pimpl_; }
|
||||||
|
struct impl const & impl() const { return *pimpl_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,35 +4,34 @@
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
namespace
|
namespace psemek::app
|
||||||
{
|
{
|
||||||
|
|
||||||
[[noreturn]] void sdl_fail(std::string const & message)
|
namespace
|
||||||
{
|
{
|
||||||
throw std::runtime_error(message + SDL_GetError());
|
|
||||||
|
[[noreturn]] void sdl_fail(std::string const & message)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(message + SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sdl_initializer
|
||||||
|
{
|
||||||
|
sdl_initializer()
|
||||||
|
{
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||||
|
sdl_fail("Failed to initialize SDL2: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
~sdl_initializer()
|
||||||
|
{
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sdl_initializer
|
struct app::impl
|
||||||
{
|
|
||||||
sdl_initializer()
|
|
||||||
{
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO) != 0)
|
|
||||||
sdl_fail("Failed to initialize SDL2: ");
|
|
||||||
}
|
|
||||||
|
|
||||||
~sdl_initializer()
|
|
||||||
{
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace psemek::util::pimpl
|
|
||||||
{
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct impl<app::app>
|
|
||||||
{
|
{
|
||||||
sdl_initializer init;
|
sdl_initializer init;
|
||||||
SDL_Window * window = nullptr;
|
SDL_Window * window = nullptr;
|
||||||
|
|
@ -47,13 +46,8 @@ namespace psemek::util::pimpl
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace psemek::app
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
app::app(std::string const & name)
|
app::app(std::string const & name)
|
||||||
|
: pimpl_{std::make_unique<struct impl>()}
|
||||||
{
|
{
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, gl::sys::GetLeastMajorVersion());
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, gl::sys::GetLeastMajorVersion());
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue