Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct SK_API sdl_deleter {
- void operator()(SDL_Window* p) const { SDL_DestroyWindow(p); }
- void operator()(SDL_Renderer* p) const { SDL_DestroyRenderer(p); }
- void operator()(SDL_Texture* p) const { SDL_DestroyTexture(p); }
- void operator()(SDL_Surface* p) const { SDL_FreeSurface(p); }
- };
- int main(int argc, char** argv)
- {
- sky::g_Engine.startup();
- std::shared_ptr<sky::Window> window;
- window->createWindow("Hello World!", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 200, 200, SDL_WINDOW_ALLOW_HIGHDPI);
- sky::g_Engine.engineLoop();
- sky::g_Engine.shutdown();
- return EXIT_SUCCESS;
- }
- namespace sky {
- class Engine;
- class SK_API Window {
- friend class Engine;
- public:
- void createWindow(const char* title, int x, int y, int width, int height, uint32_t flags);
- protected:
- std::unique_ptr<SDL_Window, sdl_deleter> m_window = nullptr;
- };
- }
- namespace sky {
- void Window::createWindow(const char* title, int x, int y, int width, int height, uint32_t flags)
- {
- m_window = std::unique_ptr<SDL_Window, sdl_deleter>(SDL_CreateWindow(title, x, y, width, height, flags), sdl_deleter());
- if (nullptr == m_window) {
- std::cout << "window create error" << SDL_GetError() << std::endl;
- }
- }
- }
- class SK_API Engine : public Singleton<Engine> {
- friend class Singleton<Engine>;
- friend class Window;
- public:
- void startup();
- void shutdown();
- void engineLoop();
- void registerWindow(std::shared_ptr<Window> window);
- private:
- std::vector<std::shared_ptr<Window>> m_windows;
- bool m_isRunning = false;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement