diff --git a/core/Base/GC.cpp b/core/Base/GC.cpp index a4fc7284..d34fbfbc 100644 --- a/core/Base/GC.cpp +++ b/core/Base/GC.cpp @@ -38,7 +38,6 @@ e2d::GC::GC() e2d::GC::~GC() { // 删除所有对象 - Game::GetInstance()->ClearAllScenes(); Timer::GetInstance()->ClearAllTasks(); ActionManager::GetInstance()->ClearAll(); diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index 47ea94c9..d86e0178 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -30,7 +30,6 @@ e2d::Game::Game() , curr_scene_(nullptr) , next_scene_(nullptr) , transition_(nullptr) - , scenes_() { ::CoInitialize(nullptr); } @@ -119,7 +118,7 @@ void e2d::Game::Quit() quit_ = true; } -void e2d::Game::PushScene(Scene * scene, bool save_current_scene) +void e2d::Game::EnterScene(Scene * scene) { if (!scene) return; @@ -128,19 +127,14 @@ void e2d::Game::PushScene(Scene * scene, bool save_current_scene) if (next_scene_) next_scene_->Release(); next_scene_ = scene; next_scene_->Retain(); - - if (save_current_scene && curr_scene_) - { - scenes_.push(curr_scene_); - } } -void e2d::Game::PushScene(Transition * transition, bool save_current_scene) +void e2d::Game::EnterScene(Transition * transition) { if (!transition) return; - PushScene(transition->in_scene_, save_current_scene); + EnterScene(transition->in_scene_); if (transition_) { @@ -159,72 +153,11 @@ void e2d::Game::PushScene(Transition * transition, bool save_current_scene) } } -e2d::Scene* e2d::Game::PopScene() -{ - // 栈为空时,调用返回场景函数失败 - if (scenes_.size() == 0) - { - WARN("Scene stack Is empty!"); - return nullptr; - } - - next_scene_ = scenes_.top(); - next_scene_->Release(); - scenes_.pop(); - - return next_scene_; -} - -e2d::Scene * e2d::Game::PopScene(Transition * transition) -{ - if (!transition) - return nullptr; - - auto scene = PopScene(); - if (scene) - { - if (transition_) - { - transition_->Stop(); - transition_->Release(); - } - transition_ = transition; - transition_->Retain(); - - transition_->in_scene_ = scene; - transition_->in_scene_->Retain(); - - // 初始化场景切换动画 - if (!transition_->Init(this, curr_scene_)) - { - WARN("Transition initialize failed!"); - transition_->Release(); - transition_ = nullptr; - } - } - - return scene; -} - -void e2d::Game::ClearAllScenes() -{ - while (!scenes_.empty()) - { - scenes_.top()->Release(); - scenes_.pop(); - } -} - e2d::Scene * e2d::Game::GetCurrentScene() { return curr_scene_; } -const std::stack& e2d::Game::GetSceneStack() -{ - return scenes_; -} - bool e2d::Game::IsTransitioning() const { return transition_ != nullptr; @@ -252,10 +185,7 @@ void e2d::Game::UpdateScene() if (curr_scene_) { curr_scene_->OnExit(); - if (scenes_.empty() || scenes_.top() != curr_scene_) - { - curr_scene_->Release(); - } + curr_scene_->Release(); } next_scene_->OnEnter(); diff --git a/core/Base/Renderer.cpp b/core/Base/Renderer.cpp index eeaa2d56..b9435530 100644 --- a/core/Base/Renderer.cpp +++ b/core/Base/Renderer.cpp @@ -118,9 +118,9 @@ void e2d::Renderer::EndDraw() if (fps_text_layout_) { - render_target_->SetTransform(D2D1::Matrix3x2F::Identity()); - solid_brush_->SetOpacity(1.0f); - text_renderer_->SetTextStyle( + GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); + GetSolidBrush()->SetOpacity(1.0f); + GetTextRenderer()->SetTextStyle( D2D1::ColorF(D2D1::ColorF::White), TRUE, D2D1::ColorF(D2D1::ColorF::Black, 0.4f), @@ -134,7 +134,6 @@ void e2d::Renderer::EndDraw() } } - // 终止渲染 HRESULT hr = render_target_->EndDraw(); if (hr == D2DERR_RECREATE_TARGET) @@ -150,10 +149,7 @@ void e2d::Renderer::EndDraw() SafeRelease(render_target_); } - if (FAILED(hr)) - { - throw SystemException("Device loss recovery failed"); - } + ThrowIfFailed(hr); } e2d::E2DTextRenderer * e2d::Renderer::GetTextRenderer() diff --git a/core/e2dbase.h b/core/e2dbase.h index 00232b1e..7b045b8a 100644 --- a/core/e2dbase.h +++ b/core/e2dbase.h @@ -345,34 +345,18 @@ public: bool IsPaused(); // 场景入栈 - void PushScene( - Scene * scene, /* 下一个场景的指针 */ - bool save_current_scene = true /* 是否保存当前场景 */ + void EnterScene( + Scene * scene /* 下一个场景的指针 */ ); // 场景入栈 - void PushScene( - Transition * transition, /* 场景动画 */ - bool save_current_scene = true /* 是否保存当前场景 */ + void EnterScene( + Transition * transition /* 场景动画 */ ); - // 场景出栈 - Scene* PopScene(); - - // 场景出栈 - Scene* PopScene( - Transition * transition /* 场景动画 */ - ); - - // 清空保存的所有场景 - void ClearAllScenes(); - // 获取当前场景 Scene * GetCurrentScene(); - // 获取场景栈 - const std::stack& GetSceneStack(); - // 是否正在进行场景动画 bool IsTransitioning() const; @@ -395,7 +379,6 @@ private: Scene* curr_scene_; Scene* next_scene_; Transition* transition_; - std::stack scenes_; static Game * instance_; };