Quellcode durchsuchen

Changed over to use std smart pointers

Sean Taylor vor 5 Jahren
Ursprung
Commit
15b0cdec34

+ 9 - 9
include/gameplay/App.h

@@ -70,49 +70,49 @@ public:
      *
      * @return The application file system.
      */
-    FileSystem* get_file_system() const;
+    std::shared_ptr<FileSystem> get_file_system() const;
 
     /**
      * Gets the application config system.
      *
      * @return The application config system.
      */
-    Config* get_config() const;
+    std::shared_ptr<Config> get_config() const;
 
     /**
      * Gets the application logging system.
      *
      * @return The application logging system.
      */
-    Logging* get_logging() const;
+    std::shared_ptr<Logging> get_logging() const;
 
     /**
      * Gets the application windowing system.
      *
      * @return The application windowing system.
      */
-    Windowing* get_windowing() const;
+    std::shared_ptr<Windowing> get_windowing() const;
 
     /**
-     * Gets the application main window.
+     * Gets the main applicaton window.
      *
      * @return The application main window.
      */
-    Window* get_main_window() const;
+    std::shared_ptr<Window> get_window() const;
 
     /**
      * Gets the application renderer.
      *
      * @return The applications renderer.
      */
-    Renderer* get_renderer() const;
+    std::shared_ptr<Renderer> get_renderer() const;
 
     /**
      * Gets the application user interface (UI) system.
      *
      * @return The applications user interface (UI) system.
      */
-    UI* get_ui() const;
+    std::shared_ptr<UI> get_ui() const;
 
     /**
      * sets a resource path for the specified alias.
@@ -169,6 +169,6 @@ public:
 private:
 	App();
 	struct Impl;
-    Impl* _impl = nullptr;
+    std::unique_ptr<Impl> _impl;
 };
 }

+ 13 - 2
include/gameplay/Config.h

@@ -28,6 +28,19 @@ class GP_API Config
     friend class App;
 
 public:
+
+    /**
+     * Constructor.
+     *
+     * @see App::get_config() instead.
+     */
+    Config();
+
+    /**
+     * Destuctor.
+     */
+	~Config();
+
     /**
      * Gets a string value from config using the lookup key.
      *
@@ -206,8 +219,6 @@ public:
     void for_each_table(const char* key, OnVisitTableFn fn, void* userPtr);
 
  private:
-    Config();
-	~Config();
     void load(int argc, char** argv);
     struct Impl;
     Impl* _impl = nullptr;

+ 1 - 0
include/gameplay/Defines.h

@@ -330,3 +330,4 @@ constexpr uint64_t hash_scalar(const T& type, uint64_t hash = GP_FNV_BASIS)
 
 template <class... Args>
 void GP_UNUSED(Args&&...) {}
+

+ 13 - 3
include/gameplay/FileSystem.h

@@ -81,6 +81,18 @@ public:
         RENAMED
     };
 
+    /**
+     * Constructor.
+     *
+     * @see App::get_file_system() instead.
+     */
+    FileSystem();
+
+    /**
+     * Destructor.
+     */
+    ~FileSystem();
+
     /**
      * Gets the application executable file path.
      *
@@ -494,10 +506,8 @@ public:
     void unsubscribe_to_change_events(uint32_t id);
 
 private:
-    FileSystem();
-    ~FileSystem();
     void set_app_executable_path(const char* path);
     struct Impl;
-    Impl* _impl;
+    std::unique_ptr<Impl> _impl;
 };
 }

+ 12 - 2
include/gameplay/Logging.h

@@ -47,6 +47,18 @@ public:
         LEVEL_OFF
     };
 
+    /**
+     * Constructor.
+     *
+     * @see App::get_logging() instead.
+     */
+    Logging();
+
+    /**
+     * Destructor.
+     */
+    ~Logging();
+
     /**
      * Parses the logging level from a string.
      */
@@ -67,8 +79,6 @@ public:
     Level get_level() const;
 
 private:
-    Logging();
-    ~Logging();
     void startup();
     void shutdown();
 };

+ 1 - 1
include/gameplay/Monitor.h

@@ -118,6 +118,6 @@ public:
      */
     void* get_user_ptr() const;
 
-    MonitorHandle* handle = nullptr;
+    std::unique_ptr<MonitorHandle> handle;
 };
 }

+ 12 - 3
include/gameplay/Renderer.h

@@ -8,10 +8,19 @@ class GP_API Renderer
 {
     friend class App;
 public:
+    /**
+     * Constructor.
+     * 
+     * @see App::get_renderer() instead.
+     */
+    Renderer();
 
-private:
-	Renderer();
+    /**
+     * Destructor.
+     */
 	~Renderer();
+
+private:
 	void startup();
 	void shutdown();
     void update();
@@ -19,6 +28,6 @@ private:
     void render_frame();
     void present_frame();
     struct Impl;
-    Impl* _impl = nullptr;
+    std::unique_ptr<Impl> _impl;
 };
 }

+ 2 - 2
include/gameplay/Timer.h

@@ -60,13 +60,13 @@ public:
     inline T get_elapsed_time(Resolution resolution = Resolution::MILLISECONDS);
 
 private:
-    bool _running = false;
+    bool _running{false};
     std::chrono::high_resolution_clock::time_point _start;
     std::chrono::high_resolution_clock::time_point _stop;
 };
 
 
-///////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // impl
 
 double Timer::get_precision()

+ 12 - 4
include/gameplay/UI.h

@@ -8,15 +8,23 @@ class GP_API UI
 {
     friend class App;
 public:
-    // todo: manage styles, fonts, etc.
+    /**
+     * Constructor.
+     *
+     * @see Windowing::create_ui() instead.
+     */
+    UI();
 
-private:
-	UI();
+    /**
+     * Destructor.
+     */
 	~UI();
+
+private:
 	void startup();
 	void shutdown();
     void update();
     struct Impl;
-    Impl* _impl = nullptr;
+    std::unique_ptr<Impl> _impl;
 };
 }

+ 6 - 2
include/gameplay/Window.h

@@ -13,7 +13,7 @@ struct Cursor;
 /**
  * Defines a platform window.
  *
- * @see App::get_main_window() to access main window.
+ * @see App::get_window() to access main application window.
  * @see App::create_window() to create additional windows.
  */
 class GP_API Window
@@ -21,11 +21,15 @@ class GP_API Window
 public:
     /**
      * Constructor.
+     *
+     * @see Windowing::create_window() instead.
      */
     Window();
 
     /**
      * Destructor.
+     *
+     * @see Windowing::destroy_window() instead.
      */
     ~Window();
 
@@ -482,6 +486,6 @@ public:
      */
     void* get_user_ptr() const;
 
-    WindowHandle* handle = nullptr;
+    std::unique_ptr<WindowHandle> handle;
 };
 }

+ 17 - 6
include/gameplay/Windowing.h

@@ -25,7 +25,7 @@ constexpr WindowHints WINDOW_HINT_MAXIMIZED = 1 << 6;
 
 struct WindowDesc
 {
-    const char* title;
+    std::string title;
     int width;
     int height;
     bool fullscreen;
@@ -50,20 +50,33 @@ class GP_API Windowing
 {
     friend class App;
 public:
+
+    /**
+     * Constructor.
+     *
+     * Dont use. Instead use @see App::get_windowing().
+     */
+    Windowing();
+
+    /**
+     * Destructor.
+     */
+    ~Windowing();
+
     /**
      * Create a new platform window.
      *
      * @param desc The window descriptor.
      * @return The window created.
      */
-    Window* create_window(const WindowDesc& desc);
+    std::shared_ptr<Window> create_window(const WindowDesc& desc);
 
     /**
      * Destroy a platform window.
      *
      * @param window The window to be destroyed.
      */
-    void destroy_window(Window* window);
+    void destroy_window(std::shared_ptr<Window> window);
 
     /**
      * Parses a string containing window hints as string separated by "|"
@@ -176,12 +189,10 @@ public:
     const char* get_clipboard_string() const;
 
 private:
-    Windowing();
-    ~Windowing();
     void startup();
     void shutdown();
     struct Impl;
-    Impl* _impl = nullptr;
+    std::unique_ptr<Impl> _impl;
 };
 }
 

+ 22 - 23
source/gameplay/App.cpp

@@ -18,25 +18,24 @@ namespace gameplay
 struct App::Impl
 {
     bool running = false;
-    FileSystem* fs = nullptr;
-    Config* config = nullptr;
-    Logging* logging = nullptr;
-    Windowing* windowing = nullptr;
-    Window* window = nullptr;
-    Renderer* renderer = nullptr;
-    UI* ui = nullptr;
+    std::shared_ptr<FileSystem> fs{nullptr};
+    std::shared_ptr<Config> config{nullptr};
+    std::shared_ptr<Logging> logging{nullptr};
+    std::shared_ptr<Windowing> windowing{nullptr};
+    std::shared_ptr<Window> window{nullptr};
+    std::shared_ptr<Renderer> renderer{nullptr};
+    std::shared_ptr<UI> ui{nullptr};
     std::unordered_map<std::string, std::string> resourceAliases;
 };
 
 
 App::App()
 {
-    _impl = new App::Impl();
+    _impl = std::make_unique<App::Impl>();
 }
 
 App::~App()
 {
-    GP_SAFE_DELETE(_impl);
 }
 
 App* App::get_app()
@@ -52,10 +51,10 @@ int App::exec(int argc, char** argv)
 	_impl->running = true;
 
     // create the file system
-    _impl->fs = new FileSystem();
+    _impl->fs = std::make_shared<FileSystem>();
 
     // create and load settings
-    _impl->config = new Config();
+    _impl->config = std::make_shared<Config>();
     _impl->config->load(argc, argv);
 
     // register application executable directory as a file system alias
@@ -73,15 +72,15 @@ int App::exec(int argc, char** argv)
                 impl->resourceAliases[name] = pathStr;
             }
             return true;
-        }, (void*)_impl);
+        }, (void*)_impl.get());
 
 
     // startup the logging system
-    _impl->logging = new Logging();
+    _impl->logging = std::make_shared<Logging>();
     _impl->logging->startup();
     
     // startup the windowing system
-    _impl->windowing = new Windowing();
+    _impl->windowing = std::make_shared<Windowing>();
     _impl->windowing->startup();
 
     // load the main window from config
@@ -101,11 +100,11 @@ int App::exec(int argc, char** argv)
     _impl->window->set_pos({0, top});
 
     // startup the ui system
-    _impl->ui = new UI();
+    _impl->ui = std::make_shared<UI>();
     _impl->ui->startup();
 
     // startup the renderer
-    _impl->renderer = new Renderer();
+    _impl->renderer = std::make_shared<Renderer>();
     _impl->renderer->startup();
    
     // run the main window event loop until we should close
@@ -144,37 +143,37 @@ double App::get_time() const
     return _impl->windowing->get_time();
 }
 
-FileSystem* App::get_file_system() const
+std::shared_ptr<FileSystem> App::get_file_system() const
 {
 	return _impl->fs;
 }
 
-Config* App::get_config() const
+std::shared_ptr<Config> App::get_config() const
 {
 	return _impl->config;
 }
 
-Logging* App::get_logging() const
+std::shared_ptr<Logging> App::get_logging() const
 {
 	return _impl->logging;
 }
 
-Windowing* App::get_windowing() const
+std::shared_ptr<Windowing> App::get_windowing() const
 {
 	return _impl->windowing;
 }
 
-Window* App::get_main_window() const
+std::shared_ptr<Window> App::get_window() const
 {
 	return _impl->window;
 }
 
-Renderer* App::get_renderer() const
+std::shared_ptr<Renderer> App::get_renderer() const
 {
 	return _impl->renderer;
 }
 
-UI* App::get_ui() const
+std::shared_ptr<UI> App::get_ui() const
 {
 	return _impl->ui;
 }

+ 6 - 7
source/gameplay/FileSystem.cpp

@@ -62,10 +62,10 @@ struct File
 
 struct FileSystem::Impl
 {
-    std::string appExecutablePath = "";
-    std::string appDirectoryPath = "";
+    std::string appExecutablePath{""};
+    std::string appDirectoryPath{""};
+    char* cwd{nullptr};
     void update_cwd(const char* cwd);
-    char* cwd = nullptr;
 };
 
 typedef uint32_t WalkFlags;
@@ -80,7 +80,7 @@ static std::string __winapi_errorcode_to_string(DWORD errorCode);
 static time_t __filetime_to_timet(FILETIME const& ft);
 typedef VisitAction (*OnVisitDirectoryItemFnWindows)(const std::wstring& path, DirectoryInfo* info, void* userPtr);
 static VisitAction __walk_directory_windows(const std::wstring& pathAbsW, const std::wstring& parentW, OnVisitDirectoryItemFnWindows fn, void* userPtr,
-                                           WalkFlags flags, std::list<std::wstring>* files, std::list<std::wstring>* directories);
+                                            WalkFlags flags, std::list<std::wstring>* files, std::list<std::wstring>* directories);
 #elif GP_PLATFORM_LINUX
 static const size_t PATH_BUFFER_LEN = PATH_MAX + 1;;
 std::vector<std::string> __split_and_fix_linux_path(const std::string& path);
@@ -90,17 +90,16 @@ static VisitAction __walk_directory_linux(const std::string& pathAbs, const std:
 static std::string __resolve_path(FileSystem* fileSystem, const char* relativeOrAbsolutePath, const char* base);
 static void __remove_duplicated_slashes(std::string& path);
 
-//////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // impl.
 
 FileSystem::FileSystem()
 {
-    _impl = new FileSystem::Impl();
+    _impl = std::make_unique<FileSystem::Impl>();
 }
 
 FileSystem::~FileSystem()
 {
-    GP_SAFE_DELETE(_impl);
 }
 
 void FileSystem::set_app_executable_path(const char* path)

+ 8 - 8
source/gameplay/Input.cpp

@@ -18,49 +18,49 @@ Input::~Input()
 
 void Input::set_cursor_pos(const Double2& pos)
 {
-    static Window* window = App::get_app()->get_main_window();
+    static auto window = App::get_app()->get_window();
     window->set_cursor_pos(pos);
 }
 
 Double2 Input::get_cursor_pos()
 {
-    static Window* window = App::get_app()->get_main_window();
+    static auto window = App::get_app()->get_window();
     return window->get_cursor_pos();
 }
 
 void Input::set_cursor_mode(CursorMode mode)
 {
-    static Window* window = App::get_app()->get_main_window();
+    static auto window = App::get_app()->get_window();
     window->set_cursor_mode(mode);
 }
 
 CursorMode Input::get_cursor_mode()
 {
-    static Window* window = App::get_app()->get_main_window();
+    static auto window = App::get_app()->get_window();
     return window->get_cursor_mode();
 }
 
 void Input::set_input_mode_enabled(InputMode mode, bool enabled)
 {
-    static Window* window = App::get_app()->get_main_window();
+    static auto window = App::get_app()->get_window();
     window->set_input_mode_enabled(mode, enabled);
 }
 
 bool Input::is_input_mode_enabled(InputMode mode)
 {
-    static Window* window = App::get_app()->get_main_window();
+    static auto window = App::get_app()->get_window();
     return window->is_input_mode_enabled(mode);
 }
 
 ButtonAction Input::get_mouse_button_action(MouseButton button)
 {
-    static Window* window = App::get_app()->get_main_window();
+    static auto window = App::get_app()->get_window();
     return window->get_mouse_button_action(button);
 }
 
 KeyAction Input::get_key_action(Key key)
 {
-    static Window* window = App::get_app()->get_main_window();
+    static auto window = App::get_app()->get_window();
     return window->get_key_action(key);
 }
 

+ 0 - 1
source/gameplay/Monitor.cpp

@@ -11,7 +11,6 @@ Monitor::Monitor()
 
 Monitor::~Monitor()
 {
-    GP_SAFE_DELETE(handle);
 }
 
 const char* Monitor::get_name() const

+ 39 - 37
source/gameplay/Renderer.cpp

@@ -9,61 +9,64 @@
 #include "imgui_impl_vulkan.h"
 #include <vector>
 
+#define GP_RENDERER_VALIDATION false
+#define GP_RENDERER_MIN_IMAGE_COUNT 2
+
 namespace gameplay
 {
 
 struct RenderFrame
 {
-    VkCommandPool commandPool = VK_NULL_HANDLE;
-    VkCommandBuffer commandBuffer = VK_NULL_HANDLE;
-    VkFence fence = VK_NULL_HANDLE;
-    VkImage backbuffer = VK_NULL_HANDLE;
-    VkImageView backbufferView = VK_NULL_HANDLE;
-    VkFramebuffer framebuffer = VK_NULL_HANDLE;
-    VkSemaphore imageAcquiredSemaphore = VK_NULL_HANDLE;
-    VkSemaphore renderCompleteSemaphore = VK_NULL_HANDLE;
+    VkCommandPool commandPool{VK_NULL_HANDLE};
+    VkCommandBuffer commandBuffer{VK_NULL_HANDLE};
+    VkFence fence{VK_NULL_HANDLE};
+    VkImage backbuffer{VK_NULL_HANDLE};
+    VkImageView backbufferView{VK_NULL_HANDLE};
+    VkFramebuffer framebuffer{VK_NULL_HANDLE};
+    VkSemaphore imageAcquiredSemaphore{VK_NULL_HANDLE};
+    VkSemaphore renderCompleteSemaphore{VK_NULL_HANDLE};
 };
 
 struct Renderer::Impl
 {   
-    bool validation = false;
-    uint32_t minImageCount = 2;
-    GLFWwindow* glfwWindow = nullptr;
-    VkAllocationCallbacks* allocator = nullptr;
-    VkDebugReportCallbackEXT debugReport = nullptr; 
-    VkInstance instance = VK_NULL_HANDLE;
-    VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
+    bool validation{GP_RENDERER_VALIDATION};
+    uint32_t minImageCount{GP_RENDERER_MIN_IMAGE_COUNT};
+    GLFWwindow* glfwWindow{nullptr};
+    VkAllocationCallbacks* allocator{nullptr};
+    VkDebugReportCallbackEXT debugReport{nullptr}; 
+    VkInstance instance{VK_NULL_HANDLE};
+    VkPhysicalDevice physicalDevice{VK_NULL_HANDLE};
     VkPhysicalDeviceProperties physicalDeviceProperties = {};
     VkPhysicalDeviceMemoryProperties physicalDeviceMemoryProperties = {};
-    VkDevice device = VK_NULL_HANDLE;
+    VkDevice device{VK_NULL_HANDLE};
     std::vector<VkQueueFamilyProperties> queueFamilyProperties;
     struct
     {
-        uint32_t present = 0;
-        uint32_t graphics = 0;
-        uint32_t compute = 0;
-        uint32_t transfer = 0;
+        uint32_t present{0};
+        uint32_t graphics{0};
+        uint32_t compute{0};
+        uint32_t transfer{0};
     } queueFamilyIndices;
-    VkQueue queue = VK_NULL_HANDLE;
-    int surfaceWidth = 0;
-    int surfaceHeight = 0;
-    VkSurfaceKHR surface = VK_NULL_HANDLE;
+    VkQueue queue{VK_NULL_HANDLE};
+    int surfaceWidth{0};
+    int surfaceHeight{0};
+    VkSurfaceKHR surface{VK_NULL_HANDLE};
     VkSurfaceFormatKHR surfaceFormat;
     VkColorSpaceKHR colorSpace;
-    VkSwapchainKHR swapchain = VK_NULL_HANDLE;
+    VkSwapchainKHR swapchain{VK_NULL_HANDLE};
     VkPresentModeKHR presentMode;
-    VkRenderPass renderPass = VK_NULL_HANDLE;
-    VkPipeline pipeline = VK_NULL_HANDLE;
-    bool clearEnable = true;
+    VkRenderPass renderPass{VK_NULL_HANDLE};
+    VkPipeline pipeline{VK_NULL_HANDLE};
+    bool clearEnable{true};
     VkClearValue clearValue = {};
-    uint32_t frameIndex = 0;
-    uint32_t semaphoreIndex = 0;
+    uint32_t frameIndex{0};
+    uint32_t semaphoreIndex{0};
     VkFormat imageFormat;
-    uint32_t imageCount = 0;
+    uint32_t imageCount{0};
     std::vector<RenderFrame> frames;
-    VkPipelineCache pipelineCache = VK_NULL_HANDLE;
-    VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
-    bool rebuildSwapchain = false;
+    VkPipelineCache pipelineCache{VK_NULL_HANDLE};
+    VkDescriptorPool descriptorPool{VK_NULL_HANDLE};
+    bool rebuildSwapchain{false};
 
     void startup_vulkan();
     void shutdown_vulkan();
@@ -85,7 +88,7 @@ struct Renderer::Impl
 
 Renderer::Renderer()
 {
-    _impl = new Renderer::Impl();
+    _impl = std::make_unique<Renderer::Impl>();
     auto config = App::get_app()->get_config();
     _impl->validation = config->set_bool("graphics.validation", false);
     _impl->minImageCount = (uint32_t)config->set_int("graphics.minImageCount", 2);
@@ -93,7 +96,6 @@ Renderer::Renderer()
 
 Renderer::~Renderer()
 {
-    GP_SAFE_DELETE(_impl);
 }
 
 void Renderer::startup()
@@ -325,7 +327,7 @@ void Renderer::Impl::shutdown_vulkan()
 
 void Renderer::Impl::startup_window_surface()
 {
-    glfwWindow = App::get_app()->get_main_window()->handle->glfwWindow;
+    glfwWindow = App::get_app()->get_window()->handle->glfwWindow;
 
     // create the window surface
     VK_CHECK_RESULT(glfwCreateWindowSurface(instance, glfwWindow, allocator, &surface));

+ 3 - 4
source/gameplay/UI.cpp

@@ -16,12 +16,11 @@ struct UI::Impl
 
 UI::UI()
 {
-    _impl = new UI::Impl();
+    _impl = std::make_unique<UI::Impl>();
 }
 
 UI::~UI()
 {
-    GP_SAFE_DELETE(_impl);
 }
 
 
@@ -46,8 +45,8 @@ void UI::startup()
         style.Colors[ImGuiCol_WindowBg].w = 1.0f;
     }
 
-    auto window = App::get_app()->get_main_window()->handle->glfwWindow;
-    ImGui_ImplGlfw_InitForVulkan(window, true);
+    auto window = App::get_app()->get_window();
+    ImGui_ImplGlfw_InitForVulkan(window->handle->glfwWindow, true);
 
     // load the system fonts
     auto config = App::get_app()->get_config();

+ 2 - 2
source/gameplay/Window.cpp

@@ -18,7 +18,6 @@ Window::~Window()
     {
         glfwDestroyWindow(handle->glfwWindow);
     }
-    GP_SAFE_DELETE(handle);
 }
 
 void Window::set_title(const char* title)
@@ -53,8 +52,9 @@ Int2 Window::get_pos() const
 void Window::set_fullscreen(bool fullscreen)
 {
     if (handle->fullscreen == fullscreen)
+    {
         return;
-
+    }
     if (fullscreen)
     {
         glfwGetWindowPos(handle->glfwWindow, &handle->pos.x, &handle->pos.y);

+ 11 - 14
source/gameplay/Windowing.cpp

@@ -42,7 +42,7 @@ static void __on_monitor_callback(GLFWmonitor* mon, int evt)
     case GLFW_CONNECTED:
         changeEvent = MonitorChangeEvent::CONNECTED;
         monitor = new Monitor();
-        monitor->handle = new MonitorHandle();
+        monitor->handle = std::make_unique<MonitorHandle>();
         monitor->handle->glfwMonitor = mon;
         break;
     case GLFW_DISCONNECTED:
@@ -182,18 +182,17 @@ struct Windowing::Impl
 {
     bool initialized = false;
     std::vector<Monitor*> monitors;
-    std::unordered_set<Window*> windows;
+    std::unordered_set<std::shared_ptr<Window>> windows;
     std::unordered_set<Cursor*> cursors;
 };
 
 Windowing::Windowing()
 {
-    _impl = new Windowing::Impl();
+    _impl = std::make_unique<Windowing::Impl>();
 }
 
 Windowing::~Windowing()
 {
-    GP_SAFE_DELETE(_impl);
 }
 
 void Windowing::startup()
@@ -214,7 +213,7 @@ void Windowing::startup()
     for (int i = 0; i < monitorCount; i++)
     {
         Monitor* monitor = new Monitor();
-        monitor->handle = new MonitorHandle();
+        monitor->handle = std::make_unique<MonitorHandle>();
         monitor->handle->glfwMonitor = glfwMonitors[i];
         glfwSetMonitorUserPointer(monitor->handle->glfwMonitor, monitor);
     }
@@ -257,15 +256,14 @@ void Windowing::shutdown()
     // Cleanup the cursors and windows managed objects
     std::for_each(_impl->cursors.begin(), _impl->cursors.end(), [](auto& cursor){delete cursor;});
     _impl->cursors.clear();
-    std::for_each(_impl->windows.begin(), _impl->windows.end(), [](auto& window){delete window;});
     _impl->windows.clear();
 
     glfwTerminate();
 }
 
-Window* Windowing::create_window(const WindowDesc& desc)
+std::shared_ptr<Window> Windowing::create_window(const WindowDesc& desc)
 {
-    Window* window = nullptr;
+    std::shared_ptr<Window> window = nullptr;
 
     // default window hints
     glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
@@ -292,16 +290,16 @@ Window* Windowing::create_window(const WindowDesc& desc)
         glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
     }
     // create the window
-    window = new Window();
-    window->handle = new WindowHandle();
-    window->handle->glfwWindow = glfwCreateWindow(desc.width, desc.height, desc.title, nullptr, nullptr);
+    window = std::make_shared<Window>();
+    window->handle = std::make_unique<WindowHandle>();
+    window->handle->glfwWindow = glfwCreateWindow(desc.width, desc.height, desc.title.c_str(), nullptr, nullptr);
     if (!window->handle->glfwWindow)
     {
         return nullptr;
     }
 
     // store this window in the glfw user pointer
-    glfwSetWindowUserPointer(window->handle->glfwWindow, window);
+    glfwSetWindowUserPointer(window->handle->glfwWindow, window.get());
 
     // setup glfw window callbacks
     glfwSetWindowPosCallback(window->handle->glfwWindow, __on_window_pos_callback);
@@ -343,10 +341,9 @@ Window* Windowing::create_window(const WindowDesc& desc)
     return window;
 }
 
-void Windowing::destroy_window(Window* window)
+void Windowing::destroy_window(std::shared_ptr<Window> window)
 {
     _impl->windows.erase(window);
-    GP_SAFE_DELETE(window);
 }
 
 WindowHints Windowing::parse_window_hints(const char* str)

+ 11 - 11
source/gameplay/WindowingGLFW.h

@@ -22,26 +22,26 @@ class Windowing;
 
 struct WindowHandle
 {
-    GLFWwindow* glfwWindow = nullptr;
-    void* platformWindow = nullptr;
-    void* platformDisplay = nullptr;
-    bool fullscreen = false;
-    void* userPtr = nullptr;
-    Int2 pos = { 0, 0 };
-    Int2 size = { 0, 0 };
-    Float2 mouseScale = { 0.0f, 0.0f };
+    GLFWwindow* glfwWindow{nullptr};
+    void* platformWindow{nullptr};
+    void* platformDisplay{nullptr};
+    bool fullscreen{false};
+    void* userPtr{nullptr};
+    Int2 pos{0, 0};
+    Int2 size{0, 0};
+    Float2 mouseScale{0.0f, 0.0f};
 };
 
 struct MonitorHandle
 {
 public:
-    GLFWmonitor* glfwMonitor = nullptr;
-    void* userPtr = nullptr;
+    GLFWmonitor* glfwMonitor{nullptr};
+    void* userPtr{nullptr};
 };
 
 struct Cursor
 {
-    GLFWcursor* glfwCursor = nullptr;
+    GLFWcursor* glfwCursor{nullptr};
 };
 
 class GLFWUtils