Added default gamestate and gamestate vectors; Minor fixes and refacorings
This commit is contained in:
parent
b1f6a2b317
commit
e540c19860
@ -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;
|
||||
}
|
@ -192,13 +192,14 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\Application.cpp" />
|
||||
<ClCompile Include="src\Gamestates\Gamestate.cpp" />
|
||||
<ClCompile Include="src\IntroGamestate.cpp" />
|
||||
<ClCompile Include="src\Utility.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\include\Application.h" />
|
||||
<ClInclude Include="src\include\Config.h" />
|
||||
<ClInclude Include="src\include\Gamestate.h" />
|
||||
<ClInclude Include="src\include\IGamestate.h" />
|
||||
<ClInclude Include="src\include\IntroGamestate.h" />
|
||||
<ClInclude Include="src\include\NothinFancy.h" />
|
||||
<ClInclude Include="src\include\Utility.h" />
|
||||
</ItemGroup>
|
||||
|
@ -21,7 +21,7 @@
|
||||
<ClCompile Include="src\Utility.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Gamestates\Gamestate.cpp">
|
||||
<ClCompile Include="src\IntroGamestate.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
@ -38,7 +38,10 @@
|
||||
<ClInclude Include="src\include\Application.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\Gamestate.h">
|
||||
<ClInclude Include="src\include\IGamestate.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\IntroGamestate.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
#include "Gamestate.h"
|
||||
|
||||
namespace nf {
|
||||
Gamestate::Gamestate() {
|
||||
|
||||
}
|
||||
}
|
19
NothinFancy/src/IntroGamestate.cpp
Normal file
19
NothinFancy/src/IntroGamestate.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "IntroGamestate.h"
|
||||
|
||||
namespace nf {
|
||||
void IntroGamestate::onEnter() {
|
||||
|
||||
}
|
||||
|
||||
void IntroGamestate::onExit() {
|
||||
|
||||
}
|
||||
|
||||
void IntroGamestate::update() {
|
||||
|
||||
}
|
||||
|
||||
void IntroGamestate::render() {
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "Config.h"
|
||||
#include "IntroGamestate.h"
|
||||
#include <Windows.h>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
@ -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<IGamestate*> m_states;
|
||||
//The currently active and loaded states where the top-most is the current one
|
||||
std::vector<IGamestate*> m_activeStates;
|
||||
IntroGamestate* m_sIntro;
|
||||
};
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace nf {
|
||||
class Gamestate {
|
||||
public:
|
||||
Gamestate();
|
||||
|
||||
virtual void onEnter();
|
||||
virtual void onExit();
|
||||
private:
|
||||
//Resource stuff
|
||||
};
|
||||
}
|
14
NothinFancy/src/include/IGamestate.h
Normal file
14
NothinFancy/src/include/IGamestate.h
Normal file
@ -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?
|
||||
};
|
||||
}
|
14
NothinFancy/src/include/IntroGamestate.h
Normal file
14
NothinFancy/src/include/IntroGamestate.h
Normal file
@ -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:
|
||||
|
||||
};
|
||||
}
|
@ -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
|
||||
|
Reference in New Issue
Block a user