From 1b6aa78e44cefdfae95494d8cdcd1a9e2a2ba572 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 22 Sep 2021 01:14:21 +0100 Subject: [PATCH] Levels tick --- Aeon/Aeon.cpp | 46 +++++++++++++++++++++++- Aeon/Aeon.hpp | 16 ++++----- Aeon/Core/Events.hpp | 2 +- Aeon/Core/GameLayer.hpp | 2 +- Game/ExampleGame.cpp | 78 ++++++++++++++++++++++++++++++++++++----- 5 files changed, 124 insertions(+), 20 deletions(-) diff --git a/Aeon/Aeon.cpp b/Aeon/Aeon.cpp index 792a21a..8e547c5 100644 --- a/Aeon/Aeon.cpp +++ b/Aeon/Aeon.cpp @@ -26,7 +26,35 @@ void App::Run() { mInput.PollInput(); - std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) ); + // std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) ); + + // tick through game layers + for ( const auto& layer : mGameLayers ) + { + layer->FrameTick(); + } + for ( const auto& layer : mTopLayers ) + { + layer->FrameTick(); + } + for ( const auto& layer : mDebugLayers ) + { + layer->FrameTick(); + } + + // tick through game layers *but timed* + for ( const auto& layer : mGameLayers ) + { + layer->TimeTick(); + } + for ( const auto& layer : mTopLayers ) + { + layer->TimeTick(); + } + for ( const auto& layer : mDebugLayers ) + { + layer->TimeTick(); + } mDisplay.EndFrame(); } @@ -37,6 +65,22 @@ const Display& App::GetDisplay() return mDisplay; } +void App::PushLayer( GameLayer* layer ) +{ + mGameLayers.push_back( layer ); +} + +void App::PushTopLayer( GameLayer* layer ) +{ + mTopLayers.push_back( layer ); +} + +void App::PushDebugLayer( GameLayer* layer ) +{ + mDebugLayers.push_back( layer ); +} + + bool App::EventRecieved( GenericEvent& e ) { if ( e.Type == "DISPLAY_CLOSED" ) diff --git a/Aeon/Aeon.hpp b/Aeon/Aeon.hpp index 0982df8..4f85044 100644 --- a/Aeon/Aeon.hpp +++ b/Aeon/Aeon.hpp @@ -23,15 +23,15 @@ public: const Display& GetDisplay(); - void PushLayer( GameLayer layer ); - void PushDebugLayer( GameLayer layer ); - void PopTopLayer( GameLayer layer ); + void PushLayer( GameLayer* layer ); + void PushTopLayer( GameLayer* layer ); + void PushDebugLayer( GameLayer* layer ); bool EventRecieved( GenericEvent& e ) override; public: void PopLayer(); - void PushTopLayer(); + void PopTopLayer(); void PopDebugLayer(); private: @@ -39,10 +39,10 @@ private: Aeon::Input::Input mInput; - // Game layers from z order - std::vector mGameLayers; - std::vector mTopLayers; - std::vector mDebugLayers; + // Game layers from z orderxko285132046 + std::vector mGameLayers; + std::vector mTopLayers; + std::vector mDebugLayers; private: bool mSIGTERM = false; diff --git a/Aeon/Core/Events.hpp b/Aeon/Core/Events.hpp index cfd22ce..d63ccd6 100644 --- a/Aeon/Core/Events.hpp +++ b/Aeon/Core/Events.hpp @@ -88,7 +88,7 @@ public: void UpdateLayer( int layer ); // return true = event handled - virtual bool EventRecieved(GenericEvent& e) = 0; + virtual bool EventRecieved( GenericEvent& e ) = 0; private: int mListenerID = -1; diff --git a/Aeon/Core/GameLayer.hpp b/Aeon/Core/GameLayer.hpp index 9c9eacf..db56666 100644 --- a/Aeon/Core/GameLayer.hpp +++ b/Aeon/Core/GameLayer.hpp @@ -12,7 +12,7 @@ public: virtual void Attach() = 0; virtual void FrameTick() = 0; virtual void TimeTick() = 0; - virtual void DetAttach() = 0; + virtual void Detach() = 0; protected: diff --git a/Game/ExampleGame.cpp b/Game/ExampleGame.cpp index b4a7579..5c7c40f 100644 --- a/Game/ExampleGame.cpp +++ b/Game/ExampleGame.cpp @@ -6,6 +6,70 @@ #include #include +class Level : public Aeon::Core::GameLayer +{ +public: + Level() { } + + void Attach() override + { + + } + + void FrameTick() override + { + + } + + void TimeTick() override + { + + } + + bool EventRecieved( Aeon::Core::GenericEvent& e ) override + { + + return false; + } + + void Detach() override + { + + } +}; + +class TopLevel : public Aeon::Core::GameLayer +{ +public: + TopLevel() { } + + void Attach() override + { + + } + + void FrameTick() override + { + + } + + void TimeTick() override + { + + } + + bool EventRecieved( Aeon::Core::GenericEvent& e ) override + { + + return false; + } + + void Detach() override + { + + } +}; + class ExampleGame : public Aeon::Core::App { public: @@ -14,9 +78,12 @@ public: ExampleGame() : App( { "Example" }, { "Game with AEON!" } ) { - GameLevel game; - PushLayer( game ); + Level* level = new Level; + TopLevel* topLevel = new TopLevel; + PushLayer( (Aeon::Core::GameLayer*)level ); + PushDebugLayer( (Aeon::Core::GameLayer*)topLevel ); Run(); + delete level; } ~ExampleGame() @@ -24,13 +91,6 @@ public: } -}; - -class GameLevel : public Aeon::Core::GameLayer -{ -public: - - }; int main( int argc, char** argv )