Add stage stack
This commit is contained in:
parent
f7fd54ef1f
commit
f038dff384
|
|
@ -36,19 +36,14 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
void Director::EnterStage(StagePtr stage)
|
||||
void Director::EnterStage(StagePtr stage, TransitionPtr transition)
|
||||
{
|
||||
KGE_ASSERT(stage && "Director::EnterStage failed, NULL pointer exception");
|
||||
|
||||
if (curr_stage_ == stage || next_stage_ == stage)
|
||||
if (current_stage_ == stage || next_stage_ == stage)
|
||||
return;
|
||||
|
||||
next_stage_ = stage;
|
||||
}
|
||||
|
||||
void Director::EnterStage(StagePtr stage, TransitionPtr transition)
|
||||
{
|
||||
EnterStage(stage);
|
||||
|
||||
if (transition && next_stage_)
|
||||
{
|
||||
|
|
@ -57,13 +52,44 @@ namespace kiwano
|
|||
transition_->Stop();
|
||||
}
|
||||
transition_ = transition;
|
||||
transition_->Init(curr_stage_, next_stage_);
|
||||
transition_->Init(current_stage_, next_stage_);
|
||||
}
|
||||
}
|
||||
|
||||
void Director::PushStage(StagePtr stage, TransitionPtr transition)
|
||||
{
|
||||
EnterStage(stage, transition);
|
||||
|
||||
if (current_stage_)
|
||||
{
|
||||
stages_.push(current_stage_);
|
||||
}
|
||||
}
|
||||
|
||||
void Director::PopStage(TransitionPtr transition)
|
||||
{
|
||||
KGE_ASSERT(!stages_.empty() && "Director::PopStage failed, calling pop() on empty stage stack");
|
||||
|
||||
if (!stages_.empty())
|
||||
{
|
||||
next_stage_ = stages_.top();
|
||||
stages_.pop();
|
||||
}
|
||||
|
||||
if (transition && next_stage_)
|
||||
{
|
||||
if (transition_)
|
||||
{
|
||||
transition_->Stop();
|
||||
}
|
||||
transition_ = transition;
|
||||
transition_->Init(current_stage_, next_stage_);
|
||||
}
|
||||
}
|
||||
|
||||
StagePtr Director::GetCurrentStage()
|
||||
{
|
||||
return curr_stage_;
|
||||
return current_stage_;
|
||||
}
|
||||
|
||||
void Director::SetRenderBorderEnabled(bool enabled)
|
||||
|
|
@ -86,7 +112,10 @@ namespace kiwano
|
|||
|
||||
void Director::ClearStages()
|
||||
{
|
||||
curr_stage_.reset();
|
||||
while (!stages_.empty())
|
||||
stages_.pop();
|
||||
|
||||
current_stage_.reset();
|
||||
next_stage_.reset();
|
||||
debug_actor_.reset();
|
||||
transition_.reset();
|
||||
|
|
@ -104,19 +133,19 @@ namespace kiwano
|
|||
|
||||
if (next_stage_ && !transition_)
|
||||
{
|
||||
if (curr_stage_)
|
||||
if (current_stage_)
|
||||
{
|
||||
curr_stage_->OnExit();
|
||||
current_stage_->OnExit();
|
||||
}
|
||||
|
||||
next_stage_->OnEnter();
|
||||
|
||||
curr_stage_ = next_stage_;
|
||||
current_stage_ = next_stage_;
|
||||
next_stage_ = nullptr;
|
||||
}
|
||||
|
||||
if (curr_stage_)
|
||||
curr_stage_->Update(dt);
|
||||
if (current_stage_)
|
||||
current_stage_->Update(dt);
|
||||
|
||||
if (next_stage_)
|
||||
next_stage_->Update(dt);
|
||||
|
|
@ -131,17 +160,17 @@ namespace kiwano
|
|||
{
|
||||
transition_->Render(rt);
|
||||
}
|
||||
else if (curr_stage_)
|
||||
else if (current_stage_)
|
||||
{
|
||||
curr_stage_->Render(rt);
|
||||
current_stage_->Render(rt);
|
||||
}
|
||||
|
||||
if (render_border_enabled_)
|
||||
{
|
||||
rt->SetOpacity(1.f);
|
||||
if (curr_stage_)
|
||||
if (current_stage_)
|
||||
{
|
||||
curr_stage_->RenderBorder(rt);
|
||||
current_stage_->RenderBorder(rt);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,8 +185,8 @@ namespace kiwano
|
|||
if (debug_actor_)
|
||||
debug_actor_->Dispatch(evt);
|
||||
|
||||
if (curr_stage_)
|
||||
curr_stage_->Dispatch(evt);
|
||||
if (current_stage_)
|
||||
current_stage_->Dispatch(evt);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/macros.h>
|
||||
#include <kiwano/2d/include-forwards.h>
|
||||
#include <kiwano/base/Component.h>
|
||||
|
||||
|
|
@ -37,13 +36,19 @@ namespace kiwano
|
|||
public:
|
||||
// Çл»Îę̀
|
||||
void EnterStage(
|
||||
StagePtr stage /* 舞台 */
|
||||
StagePtr stage, /* 舞台 */
|
||||
TransitionPtr transition = nullptr /* 过渡动画 */
|
||||
);
|
||||
|
||||
// 切换舞台
|
||||
void EnterStage(
|
||||
StagePtr stage, /* 舞台 */
|
||||
TransitionPtr transition /* 过渡动画 */
|
||||
// 舞台压栈
|
||||
void PushStage(
|
||||
StagePtr stage, /* 舞台 */
|
||||
TransitionPtr transition = nullptr /* 过渡动画 */
|
||||
);
|
||||
|
||||
// 舞台出栈
|
||||
void PopStage(
|
||||
TransitionPtr transition = nullptr /* 过渡动画 */
|
||||
);
|
||||
|
||||
// »ñÈ¡µ±Ç°Îę̀
|
||||
|
|
@ -76,7 +81,8 @@ namespace kiwano
|
|||
|
||||
protected:
|
||||
bool render_border_enabled_;
|
||||
StagePtr curr_stage_;
|
||||
Stack<StagePtr> stages_;
|
||||
StagePtr current_stage_;
|
||||
StagePtr next_stage_;
|
||||
ActorPtr debug_actor_;
|
||||
TransitionPtr transition_;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <map>
|
||||
#include <list>
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <sstream>
|
||||
|
|
@ -61,6 +62,9 @@ namespace kiwano
|
|||
template <typename _Ty, typename... _Args>
|
||||
using UnorderedSet = std::unordered_set<_Ty, _Args...>;
|
||||
|
||||
template <typename _Ty, typename... _Args>
|
||||
using Stack = std::stack<_Ty, _Args...>;
|
||||
|
||||
template <typename _Kty, typename _Ty, typename... _Args>
|
||||
using Map = std::map<_Kty, _Ty, _Args...>;
|
||||
|
||||
|
|
|
|||
|
|
@ -150,6 +150,8 @@ namespace kiwano
|
|||
geometry.GetGeometry().get(),
|
||||
current_brush_.get()
|
||||
);
|
||||
|
||||
IncreasePrimitivesCount();
|
||||
}
|
||||
|
||||
ThrowIfFailed(hr);
|
||||
|
|
@ -217,6 +219,8 @@ namespace kiwano
|
|||
DX::ConvertToRectF(rect),
|
||||
current_brush_.get()
|
||||
);
|
||||
|
||||
IncreasePrimitivesCount();
|
||||
}
|
||||
|
||||
ThrowIfFailed(hr);
|
||||
|
|
@ -267,6 +271,8 @@ namespace kiwano
|
|||
),
|
||||
current_brush_.get()
|
||||
);
|
||||
|
||||
IncreasePrimitivesCount();
|
||||
}
|
||||
|
||||
ThrowIfFailed(hr);
|
||||
|
|
@ -317,6 +323,8 @@ namespace kiwano
|
|||
),
|
||||
current_brush_.get()
|
||||
);
|
||||
|
||||
IncreasePrimitivesCount();
|
||||
}
|
||||
|
||||
ThrowIfFailed(hr);
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#include <kiwano/renderer/GifImage.h>
|
||||
|
||||
#if defined(KGE_USE_DIRECTX10)
|
||||
# include "D3D10DeviceResources.h"
|
||||
# include "win32/D3D10DeviceResources.h"
|
||||
#else
|
||||
# include "win32/D3D11DeviceResources.h"
|
||||
#endif
|
||||
|
|
@ -72,7 +72,6 @@ namespace kiwano
|
|||
bool enabled
|
||||
);
|
||||
|
||||
public:
|
||||
void CreateTexture(
|
||||
Texture& texture,
|
||||
String const& file_path
|
||||
|
|
|
|||
Loading…
Reference in New Issue