diff --git a/Game/src/Game.cpp b/Game/src/Game.cpp index c8a9eed..255ec8f 100644 --- a/Game/src/Game.cpp +++ b/Game/src/Game.cpp @@ -9,7 +9,7 @@ int main(int argc, char* argv[]) { //app.setWindowIcon(...); // app.setWindowCursor(...); - MainState* test = new MainState; + MainState* test = new MainState(&app); app.addState(test, "Main State"); app.addDefaultState("Main State"); diff --git a/Game/src/MainState.cpp b/Game/src/MainState.cpp index 21b8950..4bb402d 100644 --- a/Game/src/MainState.cpp +++ b/Game/src/MainState.cpp @@ -1,18 +1,22 @@ #include "MainState.h" -void MainState::onEnter(Application* app) { +MainState::MainState(Application* app) : + Gamestate(app) +{ +} + +void MainState::onEnter() { Log("MainState onEnter!"); - m_app = app; +} + +void MainState::update(double deltaTime) { + +} + +void MainState::render() { + } void MainState::onExit() { Log("MainState onExit!"); -} - -void MainState::update() { - Log("MainState update!"); -} - -void MainState::render() { - Log("MainState render!"); } \ No newline at end of file diff --git a/Game/src/include/MainState.h b/Game/src/include/MainState.h index bc41824..83813c3 100644 --- a/Game/src/include/MainState.h +++ b/Game/src/include/MainState.h @@ -1,13 +1,16 @@ #pragma once #include "NothinFancy.h" -class MainState : public nf::IGamestate { +class MainState : public nf::Gamestate { public: - void onEnter(Application* app) override; - void onExit() override; + MainState(Application* app); - void update() override; + void onEnter() override; + + void update(double deltaTime) override; void render() override; + + void onExit() override; private: }; \ No newline at end of file diff --git a/NothinFancy/NothinFancy.vcxproj b/NothinFancy/NothinFancy.vcxproj index b77e288..bd31894 100644 --- a/NothinFancy/NothinFancy.vcxproj +++ b/NothinFancy/NothinFancy.vcxproj @@ -192,6 +192,7 @@ + @@ -205,7 +206,7 @@ - + diff --git a/NothinFancy/NothinFancy.vcxproj.filters b/NothinFancy/NothinFancy.vcxproj.filters index d9aa77b..34dc2e7 100644 --- a/NothinFancy/NothinFancy.vcxproj.filters +++ b/NothinFancy/NothinFancy.vcxproj.filters @@ -42,6 +42,9 @@ Source Files + + Source Files + @@ -56,7 +59,7 @@ Header Files - + Header Files diff --git a/NothinFancy/src/Application.cpp b/NothinFancy/src/Application.cpp index e0eca42..165d7b9 100644 --- a/NothinFancy/src/Application.cpp +++ b/NothinFancy/src/Application.cpp @@ -40,7 +40,11 @@ namespace nf { SetClassLongPtr(m_window, GCLP_HCURSOR, (LONG_PTR)hCursor); } - void Application::addState(IGamestate* state,const std::string& stateName) { + Renderer* Application::getRenderer() const { + return m_renderer; + } + + void Application::addState(Gamestate* state,const std::string& stateName) { if (m_states.find(stateName) == m_states.end()) { m_states[stateName] = state; } @@ -188,9 +192,10 @@ namespace nf { std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now(); const std::chrono::duration wait_time = std::chrono::nanoseconds(1000000000 / 60); auto next_time = start_time + wait_time; + m_deltaTime = 0.0167; while (m_running) { start_time = std::chrono::steady_clock::now(); - m_currentState->update(); + m_currentState->update(m_deltaTime); m_currentState->render(); m_renderer->doFrame(); m_frames++; @@ -214,8 +219,8 @@ namespace nf { } void Application::startIntroState() { - m_sIntro = new IntroGamestate; - m_sIntro->onEnter(this); + m_sIntro = new IntroGamestate(this); + m_sIntro->onEnter(); m_currentState = m_sIntro; } @@ -223,7 +228,7 @@ namespace nf { m_stateChange = false; m_currentState->onExit(); m_currentState = m_states[m_nextState]; - m_currentState->onEnter(this); + m_currentState->onEnter(); } LRESULT CALLBACK Application::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -297,8 +302,8 @@ namespace nf { Application::~Application() { Log("Exiting NF application"); - for (std::pair state : m_states) { - IGamestate* curr = state.second; + for (std::pair state : m_states) { + Gamestate* curr = state.second; delete curr; } } diff --git a/NothinFancy/src/Gamestate.cpp b/NothinFancy/src/Gamestate.cpp new file mode 100644 index 0000000..6a4e2ea --- /dev/null +++ b/NothinFancy/src/Gamestate.cpp @@ -0,0 +1,27 @@ +#include "Gamestate.h" + +#include "Application.h" +#include "Utility.h" + +namespace nf { + Gamestate::Gamestate(Application* app) { + m_app = app; + m_renderer = m_app->getRenderer(); + } + + void Gamestate::onEnter() { + + } + + void Gamestate::update(double deltaTime) { + + } + + void Gamestate::render() { + + } + + void Gamestate::onExit() { + + } +} \ No newline at end of file diff --git a/NothinFancy/src/IntroGamestate.cpp b/NothinFancy/src/IntroGamestate.cpp index fd30787..bfee4c4 100644 --- a/NothinFancy/src/IntroGamestate.cpp +++ b/NothinFancy/src/IntroGamestate.cpp @@ -4,25 +4,29 @@ #include "Utility.h" namespace nf { - void IntroGamestate::onEnter(Application* app) { + IntroGamestate::IntroGamestate(Application* app) : + Gamestate(app), + m_counter(0) + { + } + + void IntroGamestate::onEnter() { Log("Intro onEnter!"); - m_app = app; - counter = 0; + m_counter = 0; + } + + + void IntroGamestate::update(double deltaTime) { + if (m_counter >= 120) { + m_app->changeState("Main State"); + } + m_counter++; + } + + void IntroGamestate::render() { } void IntroGamestate::onExit() { Log("Intro onExit!"); } - - void IntroGamestate::update() { - Log("Intro update!"); - if (counter >= 120) { - m_app->changeState("Main State"); - } - counter++; - } - - void IntroGamestate::render() { - Log("Intro render!"); - } } \ No newline at end of file diff --git a/NothinFancy/src/Renderer/Renderer.cpp b/NothinFancy/src/Renderer/Renderer.cpp index c89c77d..5ea2988 100644 --- a/NothinFancy/src/Renderer/Renderer.cpp +++ b/NothinFancy/src/Renderer/Renderer.cpp @@ -46,13 +46,31 @@ namespace nf { wglMakeCurrent(m_hdc, m_hglrc); wglSwapIntervalEXT(0); Log("OpenGL version: " + std::string((char*)glGetString(GL_VERSION))); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); } + void Renderer::render(const Drawable& in) { + //TODO: Check identity + } + void Renderer::doFrame() { glViewport(0, 0, m_app->getConfig().width, m_app->getConfig().height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + for (Drawable* draw : m_lGame) { + Drawable& curr = *draw; + + } + + for (Drawable* draw : m_lUI) { + Drawable& curr = *draw; + + } + SwapBuffers(m_hdc); GLenum err = glGetError(); diff --git a/NothinFancy/src/include/Application.h b/NothinFancy/src/include/Application.h index 44bc629..43f5aa6 100644 --- a/NothinFancy/src/include/Application.h +++ b/NothinFancy/src/include/Application.h @@ -17,7 +17,8 @@ namespace nf { void setWindowIcon(HANDLE hIcon); void setWindowCursor(HCURSOR hCursor); - void addState(IGamestate* state, const std::string& stateName); + Renderer* getRenderer() const; + void addState(Gamestate* state, const std::string& stateName); void addDefaultState(const std::string& stateName); void run(); void changeState(const std::string& stateName); @@ -59,11 +60,11 @@ namespace nf { //Inactive states to potentially be active during the Application's lifetime //Mapped to const char* to be referenced later in the frontend - std::unordered_map m_states; - IntroGamestate* m_sIntro; - IGamestate* m_DefaultState; + std::unordered_map m_states; + Gamestate* m_sIntro; + Gamestate* m_DefaultState; bool m_defaultStateAdded; - IGamestate* m_currentState; + Gamestate* m_currentState; bool m_stateChange; std::string m_nextState; diff --git a/NothinFancy/src/include/Drawable.h b/NothinFancy/src/include/Drawable.h index 2470563..5385cb8 100644 --- a/NothinFancy/src/include/Drawable.h +++ b/NothinFancy/src/include/Drawable.h @@ -1,12 +1,20 @@ #pragma once +#include "VertexArray.h" +#include "Shader.h" +#include "IndexBuffer.h" namespace nf { class Drawable { + enum class DrawableType { + NF_GAME, NF_UI + }; public: Drawable(); - ~Drawable(); - private: + virtual DrawableType identity(); + ~Drawable(); + protected: + //TODO: Add VAO, Shader, index buffer, etc. }; } \ No newline at end of file diff --git a/NothinFancy/src/include/Gamestate.h b/NothinFancy/src/include/Gamestate.h new file mode 100644 index 0000000..8b52d82 --- /dev/null +++ b/NothinFancy/src/include/Gamestate.h @@ -0,0 +1,24 @@ +#pragma once + +namespace nf { + class Application; + class Renderer; + + class Gamestate { + public: + Gamestate(Application* app); + Gamestate() = delete; + Gamestate(const Gamestate& other) = delete; + + virtual void onEnter(); + + virtual void update(double deltaTime); + virtual void render(); + + virtual void onExit(); + protected: + Application* m_app; + Renderer* m_renderer; + //Resource identifier? + }; +} \ No newline at end of file diff --git a/NothinFancy/src/include/IGamestate.h b/NothinFancy/src/include/IGamestate.h deleted file mode 100644 index f4f5e8f..0000000 --- a/NothinFancy/src/include/IGamestate.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -namespace nf { - class Application; - - class IGamestate { - public: - virtual void onEnter(Application* app) = 0; - virtual void onExit() = 0; - - virtual void update() = 0; - virtual void render() = 0; - - Application* m_app; - private: - //Resource identifier? - }; -} \ No newline at end of file diff --git a/NothinFancy/src/include/IntroGamestate.h b/NothinFancy/src/include/IntroGamestate.h index 1367f9b..83171e4 100644 --- a/NothinFancy/src/include/IntroGamestate.h +++ b/NothinFancy/src/include/IntroGamestate.h @@ -1,16 +1,19 @@ #pragma once -#include "IGamestate.h" +#include "Gamestate.h" namespace nf { - class IntroGamestate : public IGamestate { + class IntroGamestate : public Gamestate { public: - void onEnter(Application* app) override; - void onExit() override; + IntroGamestate(Application* app); - void update() override; + void onEnter() override; + + void update(double deltaTime) override; void render() override; + + void onExit() override; private: - int counter; + int m_counter; //TODO: Flesh out intro gamestate }; } \ No newline at end of file diff --git a/NothinFancy/src/include/Renderer.h b/NothinFancy/src/include/Renderer.h index 6715cc0..5d96715 100644 --- a/NothinFancy/src/include/Renderer.h +++ b/NothinFancy/src/include/Renderer.h @@ -11,6 +11,8 @@ namespace nf { public: Renderer(Application* app); + void render(const Drawable& in); + void doFrame(); ~Renderer();