diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj
index 22441d8..4f00eae 100644
--- a/Game/Game.vcxproj
+++ b/Game/Game.vcxproj
@@ -121,6 +121,7 @@
true
true
true
+ mainCRTStartup
@@ -154,6 +155,7 @@
true
true
true
+ mainCRTStartup
diff --git a/Game/src/Game.cpp b/Game/src/Game.cpp
index 9a2ebc6..7e40c2c 100644
--- a/Game/src/Game.cpp
+++ b/Game/src/Game.cpp
@@ -4,9 +4,11 @@ using namespace nf;
int main(int argc, char* argv[]) {
- Config conf = { 1280, 720, false };
+ Config conf = { 1280, 720, false, "Test"};
Application app(conf);
+ //Create game states, load some assets, launch loop that continually updates and renders the current state and switches states when appropriate.
+ //Show window
return 0;
}
\ No newline at end of file
diff --git a/NothinFancy/src/Application.cpp b/NothinFancy/src/Application.cpp
index 637876c..cc15b27 100644
--- a/NothinFancy/src/Application.cpp
+++ b/NothinFancy/src/Application.cpp
@@ -1,13 +1,84 @@
#include "Application.h"
#include "Utility.h"
#include
+//TODO: delete this
namespace nf {
DEBUGINIT;
Application::Application(Config& config) :
- m_currentConfig(config)
+ m_currentConfig(config),
+ m_wndPlacement{ sizeof(m_wndPlacement) }
{
- std::cin.get();
+ Log("Creating NF application");
+ Log("Width: " + std::to_string(m_currentConfig.width) + ", Height: " + std::to_string(m_currentConfig.height) + ", Fullscreen: " + std::to_string(m_currentConfig.fullscreen) + ", Title: " + m_currentConfig.title);
+
+ m_hInst = GetModuleHandle(NULL);
+ registerWindowClass();
+ RECT windowSize = getWindowRect();
+
+ m_window = CreateWindowEx(NULL, m_wclassName, toWide(m_currentConfig.title), WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 1280, windowSize.bottom, NULL, NULL, m_hInst, NULL);
+ if(m_currentConfig.fullscreen) toggleFullscreen();
+ showWindow(true);
}
-}
\ No newline at end of file
+
+ Config& Application::getConfig() {
+ return m_currentConfig;
+ }
+
+ void Application::showWindow(bool show) {
+ if (show)
+ ShowWindow(m_window, SW_SHOW);
+ else
+ ShowWindow(m_window, SW_HIDE);
+ }
+
+ void Application::registerWindowClass() {
+ m_wclassName = L"NFClass";
+ WNDCLASS wclass = { };
+ wclass.lpszClassName = m_wclassName;
+ //TODO: Add custom cursor and window icon at request of frontend using future resource format
+ wclass.hInstance = m_hInst;
+ wclass.lpfnWndProc = Application::WindowProc;
+ RegisterClass(&wclass);
+ }
+
+ void Application::toggleFullscreen() {
+ DWORD wndStyle = GetWindowLong(m_window, GWL_STYLE);
+ if (wndStyle & WS_OVERLAPPEDWINDOW) {
+ GetWindowPlacement(m_window, &m_wndPlacement);
+ MONITORINFO mi = { sizeof(mi) };
+ GetMonitorInfo(MonitorFromWindow(m_window, MONITOR_DEFAULTTOPRIMARY), &mi);
+ SetWindowLong(m_window, GWL_STYLE, wndStyle & ~WS_OVERLAPPEDWINDOW);
+ SetWindowPos(m_window, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
+ }
+ else {
+ SetWindowLong(m_window, GWL_STYLE, wndStyle | WS_OVERLAPPEDWINDOW);
+ SetWindowPlacement(m_window, &m_wndPlacement);
+ SetWindowPos(m_window, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
+ }
+ }
+
+ RECT Application::getWindowRect() {
+ int w = m_currentConfig.width;
+ int h = m_currentConfig.height;
+ RECT temp = { };
+ temp.right = w;
+ temp.bottom = h;
+ AdjustWindowRect(&temp, WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, false);
+ temp.right -= temp.left;
+ temp.bottom -= temp.top;
+ return temp;
+ }
+
+ LRESULT CALLBACK Application::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
+ switch (uMsg) {
+
+ }
+ return DefWindowProc(hWnd, uMsg, wParam, lParam);//TODO: Fill out events
+ }
+
+ Application::~Application() {
+
+ }
+}
diff --git a/NothinFancy/src/Utility.cpp b/NothinFancy/src/Utility.cpp
index a2826f8..a100c50 100644
--- a/NothinFancy/src/Utility.cpp
+++ b/NothinFancy/src/Utility.cpp
@@ -1,9 +1,40 @@
//TODO: Debug logger
-//TODO: Argument parser
-//TODO: Resource pack reader
+//TODO: File IO functions
#include "Utility.h"
#include "Config.h"
+#include
namespace nf {
+#ifdef _DEBUG
+ void Debug::LogImp(const char* in) {
+ std::chrono::duration time = getCurrentTime();
+ std::printf("[%.4f] Debug: %s\n", time.count(), in);
+ }
+ void Debug::LogImp(const std::string& in) {
+ std::chrono::duration time = getCurrentTime();
+ std::printf("[%.4f] Debug: %s\n", time.count(), in.c_str());
+ }
+
+ void Debug::ErrorImp(const char* in, const char* filename, int line) {
+ std::chrono::duration time = getCurrentTime();
+ HANDLE cmd = GetStdHandle(STD_OUTPUT_HANDLE);
+ SetConsoleTextAttribute(cmd, FOREGROUND_RED);
+ std::printf("[%.4f] Error (%s, %i): %s\n", time.count(), filename, line, in);
+ SetConsoleTextAttribute(cmd, 7);
+ CloseHandle(cmd);
+ }
+
+ std::chrono::duration Debug::getCurrentTime() {
+ std::chrono::steady_clock::time_point now = std::chrono::high_resolution_clock::now();
+ return now - m_initTime;
+ }
+#endif
+
+ const wchar_t* toWide(const char* in) {
+ int length = std::strlen(in) + 1;
+ wchar_t* out = new wchar_t[length];
+ MultiByteToWideChar(CP_ACP, NULL, in, -1, out, length);
+ return out;
+ }
}
\ No newline at end of file
diff --git a/NothinFancy/src/include/Application.h b/NothinFancy/src/include/Application.h
index 6e19619..9e08fe6 100644
--- a/NothinFancy/src/include/Application.h
+++ b/NothinFancy/src/include/Application.h
@@ -8,7 +8,22 @@ namespace nf {
Application(Config& conf);
Application() = delete;
Application(Application& other) = delete;
+
+ Config& getConfig();
+ void showWindow(bool show);
+
+ ~Application();
private:
+ void registerWindowClass();
+ void toggleFullscreen();
+ RECT getWindowRect();
+
+ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+
Config m_currentConfig;
+ HINSTANCE m_hInst;
+ LPCWSTR m_wclassName;
+ HWND m_window;
+ WINDOWPLACEMENT m_wndPlacement;
};
}
\ No newline at end of file
diff --git a/NothinFancy/src/include/Config.h b/NothinFancy/src/include/Config.h
index 7469562..444850b 100644
--- a/NothinFancy/src/include/Config.h
+++ b/NothinFancy/src/include/Config.h
@@ -3,8 +3,9 @@
namespace nf {
struct Config {
public:
- int m_width;
- int m_height;
- bool m_fullscreen;
+ int width;
+ int height;
+ bool fullscreen;
+ const char* title;
};
}
\ No newline at end of file
diff --git a/NothinFancy/src/include/Utility.h b/NothinFancy/src/include/Utility.h
index ab2068f..84b1213 100644
--- a/NothinFancy/src/include/Utility.h
+++ b/NothinFancy/src/include/Utility.h
@@ -1,28 +1,29 @@
#pragma once
#include
#include
-
+#include
namespace nf {
#ifdef _DEBUG
#define __FILENAME__ strrchr(__FILE__, '\\') + 1
#define DEBUGINIT std::chrono::steady_clock::time_point Debug::m_initTime = std::chrono::high_resolution_clock::now();
-#define Log(x) Debug::LogImp(x) s
+#define Log(x) Debug::LogImp(x)
#define Error(x) Debug::ErrorImp(x,__FILENAME__, __LINE__);\
DebugBreak();
-
class Debug {
private:
static std::chrono::steady_clock::time_point m_initTime;
+ static std::chrono::duration getCurrentTime();
public:
- static void LogImp(char* in);
- static void LogImp(std::string& in);
- static void ErrorImp(char* in, char* filename, int line);
+ static void LogImp(const char* in);
+ static void LogImp(const std::string& in);
+ static void ErrorImp(const char* in, const char* filename, int line);
};
-
#else
#define DEBUGINIT
#define Log(x)
#define Error(x)
#endif
+
+ const wchar_t* toWide(const char* in);
}
\ No newline at end of file
diff --git a/notes.txt b/notes.txt
index 2a04a7d..e00f47b 100644
--- a/notes.txt
+++ b/notes.txt
@@ -20,7 +20,8 @@ NatVis
Command line options
Video options
Alt-Enter
-Writing settings to file (Executable directory)
+File IO functions
+Options file (Executable directory)
Input
Audio
Game states