SHARE
TWEET

Untitled

a guest Mar 20th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct SK_API sdl_deleter {
  2.     void operator()(SDL_Window* p) const { SDL_DestroyWindow(p); }
  3.     void operator()(SDL_Renderer* p) const { SDL_DestroyRenderer(p); }
  4.     void operator()(SDL_Texture* p) const { SDL_DestroyTexture(p); }
  5.     void operator()(SDL_Surface* p) const { SDL_FreeSurface(p); }
  6. };
  7.  
  8.  int main(int argc, char** argv)
  9. {
  10.     sky::g_Engine.startup();
  11. std::shared_ptr<sky::Window> window;
  12.  
  13. window->createWindow("Hello World!", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 200, 200, SDL_WINDOW_ALLOW_HIGHDPI);
  14.  
  15. sky::g_Engine.engineLoop();
  16.  
  17. sky::g_Engine.shutdown();
  18.  
  19. return EXIT_SUCCESS;
  20. }
  21.  
  22.  
  23. namespace sky {
  24.     class Engine;
  25.  
  26.     class SK_API Window {
  27.         friend class Engine;
  28.     public:
  29.         void createWindow(const char* title, int x, int y, int width, int height, uint32_t flags);
  30.     protected:
  31.         std::unique_ptr<SDL_Window, sdl_deleter> m_window = nullptr;
  32.     };
  33. }
  34.  
  35. namespace sky {
  36.     void Window::createWindow(const char* title, int x, int y, int width, int height, uint32_t flags)
  37.     {
  38.         m_window = std::unique_ptr<SDL_Window, sdl_deleter>(SDL_CreateWindow(title, x, y, width, height, flags), sdl_deleter());
  39.         if (nullptr == m_window) {
  40.             std::cout << "window create error" << SDL_GetError() << std::endl;
  41.         }
  42.     }
  43. }
  44.  
  45. class SK_API Engine : public Singleton<Engine> {
  46.         friend class Singleton<Engine>;
  47.         friend class Window;
  48.     public:
  49.         void startup();
  50.         void shutdown();
  51.         void engineLoop();
  52.         void registerWindow(std::shared_ptr<Window> window);
  53.     private:
  54.         std::vector<std::shared_ptr<Window>> m_windows;
  55.         bool m_isRunning = false;
  56.     };
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top