diff --git a/NothinFancy/CMakeLists.txt b/NothinFancy/CMakeLists.txt index 2092595..30f4e03 100644 --- a/NothinFancy/CMakeLists.txt +++ b/NothinFancy/CMakeLists.txt @@ -1,5 +1,5 @@ # NF library CMakeLists.txt -add_library(NothinFancy STATIC "src/Engine.cpp" "src/include/nf.h" "src/pch.h" "src/util.h" "src/util/log.h" "src/util/log.cpp" "src/include/nf/EngineConfig.h" "src/util/util.cpp" "src/util/file.h" "src/util/file.cpp") +add_library(NothinFancy STATIC "src/Engine.cpp" "src/include/nf.h" "src/pch.h" "src/util.h" "src/util/log.h" "src/util/log.cpp" "src/include/nf/EngineConfig.h" "src/util/util.cpp" "src/util/file.h" "src/util/file.cpp" "src/client/Client.h" "src/client/Client.cpp" "src/client/Window.h" "src/client/Window.cpp") # Use C++20 set_property(TARGET NothinFancy PROPERTY CXX_STANDARD 20) diff --git a/NothinFancy/src/Engine.cpp b/NothinFancy/src/Engine.cpp index 9ddcb33..3f12430 100644 --- a/NothinFancy/src/Engine.cpp +++ b/NothinFancy/src/Engine.cpp @@ -4,6 +4,7 @@ #include "nf/EngineConfig.h" #include "version.h" #include "util.h" +#include "client/Client.h" namespace nf { void runEngine(EngineConfig config) { @@ -16,9 +17,16 @@ namespace nf { SetThreadDescription(GetCurrentThread(), L"NF Main Thread"); SetConsoleTitle(std::format("{} Debug Console - {}", engineStr, gameStr).c_str()); #endif - for (int i = 0; i < 10; i++) - NFLog(util::getRandRange(3, 5)); - std::cin.get(); + // Disable automatic DPI upscaling + SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); + + // Start client + { + cli::Client client(config); + client.run(); + } + + NFLog("Engine shutdown"); } } diff --git a/NothinFancy/src/client/Client.cpp b/NothinFancy/src/client/Client.cpp new file mode 100644 index 0000000..6458ce5 --- /dev/null +++ b/NothinFancy/src/client/Client.cpp @@ -0,0 +1,18 @@ +// NF Client class implementation +#include "pch.h" + +#include "Client.h" + +namespace nf::cli { + Client::Client(EngineConfig config) + : m_currentConfig(config) + , m_window() + { + // Setup window and renderer + } + + void Client::run() { + // Main game loop + m_window.runLoop(); + } +} diff --git a/NothinFancy/src/client/Client.h b/NothinFancy/src/client/Client.h new file mode 100644 index 0000000..2fd3dac --- /dev/null +++ b/NothinFancy/src/client/Client.h @@ -0,0 +1,17 @@ +// NF Client class header +#pragma once + +#include "nf/EngineConfig.h" +#include "Window.h" + +namespace nf::cli { + class Client { + public: + Client(EngineConfig config); + + void run(); + private: + EngineConfig m_currentConfig; + Window m_window; + }; +} diff --git a/NothinFancy/src/client/Window.cpp b/NothinFancy/src/client/Window.cpp new file mode 100644 index 0000000..9bb3633 --- /dev/null +++ b/NothinFancy/src/client/Window.cpp @@ -0,0 +1,75 @@ +// Window class implementation +#include "pch.h" + +#include "Window.h" +#include "util.h" + +namespace nf::cli { + Window::Window() + : m_handle(nullptr) + , m_wndClassName("NothinFancyWindow") + , m_windowedStyle(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX) + { + NFLog("Creating window"); + + // Register window class + WNDCLASS wc = {}; + wc.lpszClassName = m_wndClassName; + wc.hCursor = LoadCursor(nullptr, IDC_ARROW); + wc.lpfnWndProc = wndProc; + RegisterClass(&wc); + + m_handle = CreateWindow(m_wndClassName, "NF Window", m_windowedStyle, 0, 0, 0, 0, nullptr, nullptr, nullptr, this); + } + + void Window::runLoop() { + show(); + MSG msg = {}; + while (GetMessage(&msg, nullptr, NULL, NULL)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + void Window::show(bool show) { + ShowWindow(m_handle, show ? SW_SHOW : SW_HIDE); + } + + LRESULT CALLBACK Window::wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { + static Window* wnd = nullptr; + + switch (msg) { + case WM_CREATE: { + wnd = reinterpret_cast(reinterpret_cast(lParam)->lpCreateParams); + + // Temporary monitor choice + POINT cursor = {}; + GetCursorPos(&cursor); + MONITORINFO mi = {}; + mi.cbSize = sizeof(mi); + GetMonitorInfo(MonitorFromPoint(cursor, MONITOR_DEFAULTTONEAREST), &mi); + int x = mi.rcMonitor.left + 100, y = mi.rcMonitor.top + 100; + + RECT cli = {}; + cli.right = 1280; + cli.bottom = 720; + AdjustWindowRect(&cli, wnd->m_windowedStyle, FALSE); + unsigned int width = cli.right - cli.left, height = cli.bottom - cli.top; + + SetWindowPos(hWnd, nullptr, x, y, width, height, SWP_NOZORDER); + return 0; + } + + case WM_CLOSE: + DestroyWindow(hWnd); + return 0; + + case WM_DESTROY: + PostQuitMessage(0); + return 0; + } + + return DefWindowProc(hWnd, msg, wParam, lParam); + } + +} diff --git a/NothinFancy/src/client/Window.h b/NothinFancy/src/client/Window.h new file mode 100644 index 0000000..5d76516 --- /dev/null +++ b/NothinFancy/src/client/Window.h @@ -0,0 +1,21 @@ +// Window class header +#pragma once + +#include + +namespace nf::cli { + class Window { + public: + Window(); + + void runLoop(); + void show(bool show = true); + private: + static LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + + HWND m_handle; + + const char* m_wndClassName; + const DWORD m_windowedStyle; + }; +} diff --git a/TestGame/CMakeLists.txt b/TestGame/CMakeLists.txt index fe14112..852cbbd 100644 --- a/TestGame/CMakeLists.txt +++ b/TestGame/CMakeLists.txt @@ -1,9 +1,17 @@ # TestGame app CMakeLists.txt -add_executable(TestGame "src/TestGame.cpp") +add_executable(TestGame WIN32 "src/TestGame.cpp") # Use C++20 set_property(TARGET TestGame PROPERTY CXX_STANDARD 20) +# Use "main" function +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /entry:mainCRTStartup") + +# Keep the console in debug +if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + set_property(TARGET TestGame PROPERTY WIN32_EXECUTABLE FALSE) +endif() + # Link to NF library target_link_libraries(TestGame NothinFancy) target_include_directories(TestGame PUBLIC "${CMAKE_SOURCE_DIR}/NothinFancy/src/include")