删除场景栈

This commit is contained in:
Nomango 2018-09-04 23:20:00 +08:00
parent 997aca7e6e
commit 8984817dd8
4 changed files with 12 additions and 104 deletions

View File

@ -38,7 +38,6 @@ e2d::GC::GC()
e2d::GC::~GC()
{
// 删除所有对象
Game::GetInstance()->ClearAllScenes();
Timer::GetInstance()->ClearAllTasks();
ActionManager::GetInstance()->ClearAll();

View File

@ -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::Scene*>& 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();

View File

@ -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()

View File

@ -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<Scene*>& GetSceneStack();
// 是否正在进行场景动画
bool IsTransitioning() const;
@ -395,7 +379,6 @@ private:
Scene* curr_scene_;
Scene* next_scene_;
Transition* transition_;
std::stack<Scene*> scenes_;
static Game * instance_;
};