Fixed threading bug and rewrote syntax of addState

This commit is contained in:
Grayson Riffe (Laptop) 2021-08-19 11:25:03 -05:00
parent a21c24040d
commit 9bfbfb637b
3 changed files with 6 additions and 3 deletions

View File

@ -10,7 +10,7 @@ int main(int argc, char* argv[]) {
// app.setWindowCursor(...); // app.setWindowCursor(...);
MainState* test = new MainState; MainState* test = new MainState;
app.addState("Main State", test); app.addState(test, "Main State");
app.addDefaultState("Main State"); app.addDefaultState("Main State");
app.run(); app.run();

View File

@ -34,7 +34,7 @@ namespace nf {
SetClassLongPtr(m_window, GCLP_HCURSOR, (LONG_PTR)hCursor); SetClassLongPtr(m_window, GCLP_HCURSOR, (LONG_PTR)hCursor);
} }
void Application::addState(const char* stateName, IGamestate* state) { void Application::addState(IGamestate* state, const char* stateName) {
if (m_states.find(stateName) == m_states.end()) { if (m_states.find(stateName) == m_states.end()) {
m_states[stateName] = state; m_states[stateName] = state;
} }
@ -142,6 +142,9 @@ namespace nf {
m_frameClock = std::chrono::steady_clock::now(); m_frameClock = std::chrono::steady_clock::now();
} }
m_currentState->onExit(); m_currentState->onExit();
ReleaseDC(m_window, m_hdc);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_hglrc);
} }
void Application::registerWindowClass() { void Application::registerWindowClass() {

View File

@ -17,7 +17,7 @@ namespace nf {
void setWindowIcon(HANDLE hIcon); void setWindowIcon(HANDLE hIcon);
void setWindowCursor(HCURSOR hCursor); void setWindowCursor(HCURSOR hCursor);
void addState(const char* stateName, IGamestate* state); void addState(IGamestate* state, const char* stateName);
void addDefaultState(const char* stateName); void addDefaultState(const char* stateName);
void changeState(const char* stateName); void changeState(const char* stateName);
void run(); void run();