diff --git a/Game/src/Game.cpp b/Game/src/Game.cpp
index 4065de6..9c1e9a0 100644
--- a/Game/src/Game.cpp
+++ b/Game/src/Game.cpp
@@ -10,8 +10,9 @@ int main(int argc, char* argv[]) {
Application app(conf);
//app.setWindowIcon(...);
// app.setWindowCursor(...);
- //Create game states, load some assets, launch loop that continually updates and renders the current state and switches states when appropriate.
- app.startLoop();
+ //Configure states
+ // app.addDefaultState(...);
+ app.run();
return 0;
}
\ No newline at end of file
diff --git a/NothinFancy/NothinFancy.vcxproj b/NothinFancy/NothinFancy.vcxproj
index 4df5745..233742b 100644
--- a/NothinFancy/NothinFancy.vcxproj
+++ b/NothinFancy/NothinFancy.vcxproj
@@ -192,13 +192,14 @@
-
+
-
+
+
diff --git a/NothinFancy/NothinFancy.vcxproj.filters b/NothinFancy/NothinFancy.vcxproj.filters
index 310cf2d..52f2d62 100644
--- a/NothinFancy/NothinFancy.vcxproj.filters
+++ b/NothinFancy/NothinFancy.vcxproj.filters
@@ -21,7 +21,7 @@
Source Files
-
+
Source Files
@@ -38,7 +38,10 @@
Header Files
-
+
+ Header Files
+
+
Header Files
diff --git a/NothinFancy/src/Application.cpp b/NothinFancy/src/Application.cpp
index 65f19b4..d753e5d 100644
--- a/NothinFancy/src/Application.cpp
+++ b/NothinFancy/src/Application.cpp
@@ -21,30 +21,42 @@ namespace nf {
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);
+ m_defaultWindowStyle = GetWindowLong(m_window, GWL_STYLE);
SetProp(m_window, L"App", this);
if (m_currentConfig.fullscreen) toggleFullscreen();
createOpenGLContext();
+ m_states.reserve(100);
+ m_activeStates.reserve(100);
+ m_sIntro = new IntroGamestate;
+ addState(m_sIntro);
}
void Application::setWindowIcon(HANDLE hIcon) {
SendMessage(m_window, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
SendMessage(m_window, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
}
-
+ //TODO: Test these top-level features
void Application::setWindowCursor(HCURSOR hCursor) {
SetClassLongPtr(m_window, GCLP_HCURSOR, (LONG_PTR)hCursor);
}
- void Application::startLoop() {
+ void Application::addState(IGamestate* in) {
+ (*in).onEnter();
+ m_states.push_back(in);
+ }
+
+ void Application::addDefaultState(IGamestate* in) {
+ (*in).onEnter();
+ m_activeStates.push_back(in);
+ }
+
+ void Application::run() {
showWindow(true);
m_running = true;
MSG msg = { };
while (m_running) {
- //TODO: delta timing
-
m_fpsDuration = std::chrono::steady_clock::now() - m_frameClock;
-
if (m_fpsDuration.count() >= m_minFrametime) {
m_deltaTime = m_fpsDuration.count();
while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) {
@@ -53,7 +65,6 @@ namespace nf {
if (msg.message == WM_QUIT)
m_running = false;
}
- glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
SwapBuffers(m_hdc);
m_frames++;
@@ -77,11 +88,11 @@ namespace nf {
ShowWindow(m_window, SW_HIDE);
}
- Config& Application::getConfig() {
+ const Config& Application::getConfig() const {
return m_currentConfig;
- }
+ }//Test this
- int Application::getFPS() {
+ int Application::getFPS() const {
return m_FPS;
}
@@ -106,13 +117,13 @@ namespace nf {
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);
+ SetWindowLong(m_window, GWL_STYLE, m_defaultWindowStyle);
}
}
- RECT Application::getWindowRect() {
+ RECT Application::getWindowRect() const {
int w = m_currentConfig.width;
int h = m_currentConfig.height;
RECT temp = { };
@@ -196,9 +207,10 @@ namespace nf {
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
Application::~Application() {
-
+ //TODO: Iterate through m_activeStates and m_states and exit and unload them
}
}
diff --git a/NothinFancy/src/Gamestates/Gamestate.cpp b/NothinFancy/src/Gamestates/Gamestate.cpp
deleted file mode 100644
index bc3d378..0000000
--- a/NothinFancy/src/Gamestates/Gamestate.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "Gamestate.h"
-
-namespace nf {
- Gamestate::Gamestate() {
-
- }
-}
\ No newline at end of file
diff --git a/NothinFancy/src/IntroGamestate.cpp b/NothinFancy/src/IntroGamestate.cpp
new file mode 100644
index 0000000..12488c9
--- /dev/null
+++ b/NothinFancy/src/IntroGamestate.cpp
@@ -0,0 +1,19 @@
+#include "IntroGamestate.h"
+
+namespace nf {
+ void IntroGamestate::onEnter() {
+
+ }
+
+ void IntroGamestate::onExit() {
+
+ }
+
+ void IntroGamestate::update() {
+
+ }
+
+ void IntroGamestate::render() {
+
+ }
+}
\ No newline at end of file
diff --git a/NothinFancy/src/include/Application.h b/NothinFancy/src/include/Application.h
index f0554cf..de9092d 100644
--- a/NothinFancy/src/include/Application.h
+++ b/NothinFancy/src/include/Application.h
@@ -1,5 +1,6 @@
#pragma once
#include "Config.h"
+#include "IntroGamestate.h"
#include
#include
#include
@@ -13,16 +14,18 @@ namespace nf {
void setWindowIcon(HANDLE hIcon);
void setWindowCursor(HCURSOR hCursor);
- void startLoop();
+ void addState(IGamestate* in);
+ void addDefaultState(IGamestate* in);
+ void run();
void showWindow(bool show);
- Config& getConfig();
- int getFPS();
+ const Config& getConfig() const;
+ int getFPS() const;
~Application();
private:
void registerWindowClass();
void toggleFullscreen();
- RECT getWindowRect();
+ RECT getWindowRect() const;
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
@@ -33,6 +36,7 @@ namespace nf {
HINSTANCE m_hInst;
LPCWSTR m_wclassName;
HWND m_window;
+ LONG m_defaultWindowStyle;
WINDOWPLACEMENT m_wndPlacement;
HDC m_hdc;
HGLRC m_hglrc;
@@ -47,6 +51,10 @@ namespace nf {
const double m_minFrametime = 1.0 / m_targetFPS;
int m_FPS;
-
+ //Inactive states states to potentially be loaded during the Application's lifetime
+ std::vector m_states;
+ //The currently active and loaded states where the top-most is the current one
+ std::vector m_activeStates;
+ IntroGamestate* m_sIntro;
};
}
\ No newline at end of file
diff --git a/NothinFancy/src/include/Gamestate.h b/NothinFancy/src/include/Gamestate.h
deleted file mode 100644
index 1407b06..0000000
--- a/NothinFancy/src/include/Gamestate.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma once
-
-namespace nf {
- class Gamestate {
- public:
- Gamestate();
-
- virtual void onEnter();
- virtual void onExit();
- private:
- //Resource stuff
- };
-}
\ No newline at end of file
diff --git a/NothinFancy/src/include/IGamestate.h b/NothinFancy/src/include/IGamestate.h
new file mode 100644
index 0000000..4aa36d7
--- /dev/null
+++ b/NothinFancy/src/include/IGamestate.h
@@ -0,0 +1,14 @@
+#pragma once
+
+namespace nf {
+ class IGamestate {
+ public:
+ virtual void onEnter() = 0;
+ virtual void onExit() = 0;
+
+ virtual void update() = 0;
+ virtual void render() = 0;
+ private:
+ //Resource identifier?
+ };
+}
\ No newline at end of file
diff --git a/NothinFancy/src/include/IntroGamestate.h b/NothinFancy/src/include/IntroGamestate.h
new file mode 100644
index 0000000..bc7eef0
--- /dev/null
+++ b/NothinFancy/src/include/IntroGamestate.h
@@ -0,0 +1,14 @@
+#include "IGamestate.h"
+
+namespace nf {
+ class IntroGamestate : public IGamestate {
+ public:
+ void onEnter() override;
+ void onExit() override;
+
+ void update() override;
+ void render() override;
+ private:
+
+ };
+}
\ No newline at end of file
diff --git a/STEMSln.sln b/STEMSln.sln
index 6438936..bc4469b 100644
--- a/STEMSln.sln
+++ b/STEMSln.sln
@@ -16,19 +16,15 @@ Global
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1B9C5361-E301-41BF-97E7-56D65F11E2BB}.Debug|x64.ActiveCfg = Debug|x64
- {1B9C5361-E301-41BF-97E7-56D65F11E2BB}.Debug|x64.Build.0 = Debug|x64
{1B9C5361-E301-41BF-97E7-56D65F11E2BB}.Debug|x86.ActiveCfg = Debug|Win32
{1B9C5361-E301-41BF-97E7-56D65F11E2BB}.Debug|x86.Build.0 = Debug|Win32
{1B9C5361-E301-41BF-97E7-56D65F11E2BB}.Release|x64.ActiveCfg = Release|x64
- {1B9C5361-E301-41BF-97E7-56D65F11E2BB}.Release|x64.Build.0 = Release|x64
{1B9C5361-E301-41BF-97E7-56D65F11E2BB}.Release|x86.ActiveCfg = Release|Win32
{1B9C5361-E301-41BF-97E7-56D65F11E2BB}.Release|x86.Build.0 = Release|Win32
{B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Debug|x64.ActiveCfg = Debug|x64
- {B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Debug|x64.Build.0 = Debug|x64
{B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Debug|x86.ActiveCfg = Debug|Win32
{B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Debug|x86.Build.0 = Debug|Win32
{B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Release|x64.ActiveCfg = Release|x64
- {B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Release|x64.Build.0 = Release|x64
{B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Release|x86.ActiveCfg = Release|Win32
{B7FEC2D6-1D8F-487E-89CB-FD611FD1AEB6}.Release|x86.Build.0 = Release|Win32
EndGlobalSection