Add Client and Window
This commit is contained in:
parent
1f1e62abdc
commit
91afd4ad1b
@ -1,5 +1,5 @@
|
|||||||
# NF library CMakeLists.txt
|
# 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
|
# Use C++20
|
||||||
set_property(TARGET NothinFancy PROPERTY CXX_STANDARD 20)
|
set_property(TARGET NothinFancy PROPERTY CXX_STANDARD 20)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "nf/EngineConfig.h"
|
#include "nf/EngineConfig.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "client/Client.h"
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
void runEngine(EngineConfig config) {
|
void runEngine(EngineConfig config) {
|
||||||
@ -16,9 +17,16 @@ namespace nf {
|
|||||||
SetThreadDescription(GetCurrentThread(), L"NF Main Thread");
|
SetThreadDescription(GetCurrentThread(), L"NF Main Thread");
|
||||||
SetConsoleTitle(std::format("{} Debug Console - {}", engineStr, gameStr).c_str());
|
SetConsoleTitle(std::format("{} Debug Console - {}", engineStr, gameStr).c_str());
|
||||||
#endif
|
#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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
18
NothinFancy/src/client/Client.cpp
Normal file
18
NothinFancy/src/client/Client.cpp
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
17
NothinFancy/src/client/Client.h
Normal file
17
NothinFancy/src/client/Client.h
Normal file
@ -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;
|
||||||
|
};
|
||||||
|
}
|
75
NothinFancy/src/client/Window.cpp
Normal file
75
NothinFancy/src/client/Window.cpp
Normal file
@ -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<Window*>(reinterpret_cast<CREATESTRUCT*>(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
21
NothinFancy/src/client/Window.h
Normal file
21
NothinFancy/src/client/Window.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Window class header
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
}
|
@ -1,9 +1,17 @@
|
|||||||
# TestGame app CMakeLists.txt
|
# TestGame app CMakeLists.txt
|
||||||
add_executable(TestGame "src/TestGame.cpp")
|
add_executable(TestGame WIN32 "src/TestGame.cpp")
|
||||||
|
|
||||||
# Use C++20
|
# Use C++20
|
||||||
set_property(TARGET TestGame PROPERTY CXX_STANDARD 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
|
# Link to NF library
|
||||||
target_link_libraries(TestGame NothinFancy)
|
target_link_libraries(TestGame NothinFancy)
|
||||||
target_include_directories(TestGame PUBLIC "${CMAKE_SOURCE_DIR}/NothinFancy/src/include")
|
target_include_directories(TestGame PUBLIC "${CMAKE_SOURCE_DIR}/NothinFancy/src/include")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user