Win32 window creation
This commit is contained in:
parent
8e85720849
commit
d7eef04063
@ -37,6 +37,9 @@ option(LIBRARY_GLFW3_STATIC "Enable tweaks when using static GLFW3" OFF)
|
|||||||
|
|
||||||
if(BUILD_CLIENT)
|
if(BUILD_CLIENT)
|
||||||
file(GLOB_RECURSE CLIENT_SOURCES "src/game/**.cpp")
|
file(GLOB_RECURSE CLIENT_SOURCES "src/game/**.cpp")
|
||||||
|
if(NOT WIN32)
|
||||||
|
list(REMOVE_ITEM CLIENT_SOURCES "src/game/window/win32_window.cpp")
|
||||||
|
endif()
|
||||||
file(GLOB_RECURSE VENDOR_SOURCES "src/vendor/**.cpp")
|
file(GLOB_RECURSE VENDOR_SOURCES "src/vendor/**.cpp")
|
||||||
endif()
|
endif()
|
||||||
if(BUILD_SERVER)
|
if(BUILD_SERVER)
|
||||||
|
@ -25,6 +25,8 @@ SOFTWARE.
|
|||||||
#ifndef POLYGUN_WINDOW_EVENT_HPP
|
#ifndef POLYGUN_WINDOW_EVENT_HPP
|
||||||
#define POLYGUN_WINDOW_EVENT_HPP
|
#define POLYGUN_WINDOW_EVENT_HPP
|
||||||
|
|
||||||
|
#include "game/window/mouse.hpp"
|
||||||
|
|
||||||
namespace polygun::window {
|
namespace polygun::window {
|
||||||
enum EventType {
|
enum EventType {
|
||||||
EVENT_TYPE_NO_EVENT,
|
EVENT_TYPE_NO_EVENT,
|
||||||
|
83
src/game/window/win32_window.cpp
Normal file
83
src/game/window/win32_window.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
PolyGun
|
||||||
|
|
||||||
|
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "game/window/win32_window.hpp"
|
||||||
|
|
||||||
|
#include "common/logger.hpp"
|
||||||
|
|
||||||
|
using namespace polygun::window;
|
||||||
|
|
||||||
|
static HINSTANCE g_instance;
|
||||||
|
|
||||||
|
extern int main(int argc, char** args);
|
||||||
|
int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev_inst, PTSTR cmd_line, int show_cmd) {
|
||||||
|
g_instance = inst;
|
||||||
|
main(1, &cmd_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
Win32Window::Win32Window(const std::string& title, unsigned width, unsigned height) :
|
||||||
|
m_window_handle(),
|
||||||
|
m_message_thread(),
|
||||||
|
m_access_mutex()
|
||||||
|
{
|
||||||
|
WNDCLASSEX window_class;
|
||||||
|
window_class.cbSize = sizeof(window_class);
|
||||||
|
window_class.style = 0;
|
||||||
|
window_class.lpfnWndProc = DefWindowProc;
|
||||||
|
window_class.cbClsExtra = 0;
|
||||||
|
window_class.hInstance = g_instance;
|
||||||
|
const TCHAR* class_name = title.c_str();
|
||||||
|
window_class.lpszClassName = class_name;
|
||||||
|
if(!RegisterClassEx(&window_class))
|
||||||
|
LOG_FATAL("Failed to register window class");
|
||||||
|
|
||||||
|
m_window_handle = CreateWindowEx(WS_EX_LEFT, class_name, nullptr, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, g_instance, nullptr);
|
||||||
|
if(!m_window_handle)
|
||||||
|
LOG_FATAL("Failed to create window");
|
||||||
|
|
||||||
|
ShowWindow(m_window_handle, false);
|
||||||
|
UpdateWindow(m_window_handle);
|
||||||
|
m_message_thread.reset(new std::thread(&Win32Window::message_thread_func, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
Win32Window::~Win32Window() {
|
||||||
|
if(m_message_thread->joinable())
|
||||||
|
m_message_thread->join();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Win32Window::poll_events(Event& event) {
|
||||||
|
return Window::poll_events(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Win32Window::message_thread_func() {
|
||||||
|
MSG msg;
|
||||||
|
while(GetMessage(&msg, m_window_handle, 0, 0)) {
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessage(&msg);
|
||||||
|
}
|
||||||
|
m_access_mutex.lock();
|
||||||
|
Event close_event;
|
||||||
|
close_event.m_type = EventType::EVENT_TYPE_WINDOW_CLOSE;
|
||||||
|
m_event_queue.push_back(close_event);
|
||||||
|
}
|
50
src/game/window/win32_window.hpp
Normal file
50
src/game/window/win32_window.hpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
PolyGun
|
||||||
|
|
||||||
|
Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "game/window/window.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace polygun::window {
|
||||||
|
class Win32Window final : public Window {
|
||||||
|
public:
|
||||||
|
Win32Window(const std::string& title, unsigned width, unsigned height);
|
||||||
|
virtual ~Win32Window() override;
|
||||||
|
|
||||||
|
virtual size_t poll_events(Event& event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
HWND m_window_handle;
|
||||||
|
std::unique_ptr<std::thread> m_message_thread;
|
||||||
|
std::mutex m_access_mutex;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void message_thread_func();
|
||||||
|
};
|
||||||
|
}
|
@ -27,7 +27,10 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "game/window/event.hpp"
|
||||||
|
|
||||||
namespace polygun::window {
|
namespace polygun::window {
|
||||||
|
|
||||||
class Window {
|
class Window {
|
||||||
public:
|
public:
|
||||||
Window() = default;
|
Window() = default;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user