<commit_before>#include "core/window.hpp"
#include "gl/impl/backend/ogl2/tz_opengl.hpp"
#include <utility>

namespace tz
{
	Window::Window(WindowInitArgs args, WindowHintList hints):
	WindowFunctionality(nullptr)
	{
		if(!args.flags.resizeable)
		{
			// GLFW assumes window is resizable. If not we will need to add an extra hint.
			hints.add(WindowHint{.hint = GLFW_RESIZABLE, .value = GLFW_FALSE});
		}
		for(const WindowHint& hint : hints)
		{
			glfwWindowHint(hint.hint, hint.value);
		}

		#if TZ_VULKAN
			glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
		#elif TZ_OGL
			glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
			glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, tz::gl::ogl2::ogl_version.major);
			glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, tz::gl::ogl2::ogl_version.minor);
			glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
			#if TZ_DEBUG
				glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
			#else
				glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_FALSE);
			#endif
		#endif

		this->wnd = glfwCreateWindow(args.width, args.height, args.title, nullptr, nullptr);
		glfwMakeContextCurrent(this->wnd);
		#if TZ_OGL
			// Vulkan isn't fps-capped -- neither should opengl be.
			glfwSwapInterval(0);
		#endif
		glfwSetWindowUserPointer(this->wnd, this);
		glfwSetFramebufferSizeCallback(this->wnd, Window::window_resize_callback);
		glfwSetKeyCallback(this->wnd, Window::key_callback);
		glfwSetMouseButtonCallback(this->wnd, Window::mouse_button_callback);
	}

	Window::Window(Window&& move):
	WindowFunctionality(nullptr)
	{
		std::swap(this->wnd, move.wnd);
	}

	Window::~Window()
	{
		if(this->wnd != nullptr)
		{
			glfwDestroyWindow(this->wnd);
			this->wnd = nullptr;
		}
	}

	Window& Window::operator=(Window&& rhs)<commit_msg>+ Added extra error reporting incase a glfw window fails to create but initialises without issues<commit_after>#include "core/window.hpp"
#include "gl/impl/backend/ogl2/tz_opengl.hpp"
#include <utility>

namespace tz
{
	Window::Window(WindowInitArgs args, WindowHintList hints):
	WindowFunctionality(nullptr)
	{
		if(!args.flags.resizeable)
		{
			// GLFW assumes window is resizable. If not we will need to add an extra hint.
			hints.add(WindowHint{.hint = GLFW_RESIZABLE, .value = GLFW_FALSE});
		}
		for(const WindowHint& hint : hints)
		{
			glfwWindowHint(hint.hint, hint.value);
		}

		#if TZ_VULKAN
			glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
		#elif TZ_OGL
			glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
			glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, tz::gl::ogl2::ogl_version.major);
			glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, tz::gl::ogl2::ogl_version.minor);
			glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
			#if TZ_DEBUG
				glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
			#else
				glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_FALSE);
			#endif
		#endif

		this->wnd = glfwCreateWindow(args.width, args.height, args.title, nullptr, nullptr);
		if(TZ_DEBUG && this->wnd == nullptr)
		{
			// We failed somehow.	
			switch(glfwGetError(nullptr))
			{
				case GLFW_NOT_INITIALIZED:
					tz_error("Failed to create window because glfw was not initialised correctly.");
				break;
				case GLFW_INVALID_ENUM:
					tz_error("Failed to create window due to invalid glfw enum.");
				break;
				case GLFW_INVALID_VALUE:
					tz_error("Failed to create window due to invalid glfw value.");
				break;
				case GLFW_API_UNAVAILABLE:
					tz_error("Failed to create window because GLFW could not find support for the requested API on the system.");
				break;
				case GLFW_VERSION_UNAVAILABLE:
					tz_error("Failed to create window because the requested OpenGL version (4.6) is not available on this machine. If this is a vulkan build, please submit a bug report.");
				break;
				case GLFW_FORMAT_UNAVAILABLE:
					tz_error("Failed to create window because the requested pixel format is not supported.");
				break;
				case GLFW_PLATFORM_ERROR:
					tz_error("Failed to create window because a miscellaneous platform-specific error occurred. Either a bug/error in the config of GLFW has taken place, or the machine's OS/drivers are misconfigured, or there was a lack of required resources. Please submit a bug report.");
				break;
				default:
					tz_error("Failed to create window, but for unknown reason. GLFW has returned an undocumented error code for glfwCreateWindow, so something is very wrong. Please submit a bug report. Error code %d", glfwGetError(nullptr));
				break;
			}
		}
		glfwMakeContextCurrent(this->wnd);
		#if TZ_OGL
			// Vulkan isn't fps-capped -- neither should opengl be.
			glfwSwapInterval(0);
		#endif
		glfwSetWindowUserPointer(this->wnd, this);
		glfwSetFramebufferSizeCallback(this->wnd, Window::window_resize_callback);
		glfwSetKeyCallback(this->wnd, Window::key_callback);
		glfwSetMouseButtonCallback(this->wnd, Window::mouse_button_callback);
	}

	Window::Window(Window&& move):
	WindowFunctionality(nullptr)
	{
		std::swap(this->wnd, move.wnd);
	}

	Window::~Window()
	{
		if(this->wnd != nullptr)
		{
			glfwDestroyWindow(this->wnd);
			this->wnd = nullptr;
		}
	}

	Window& Window::operator=(Window&& rhs)
{'fraction_non_alphanumeric': 0.10694256430090891, 'fraction_numerical': 0.0019338619222587507, 'mean_word_length': 4.721238938053097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5481926', 'n_tokens_mistral': 2015, 'n_tokens_neox': 1785, 'n_words': 403}