Magic_Game/src/kiwano/2d/action/ActionManager.cpp

105 lines
2.7 KiB
C++
Raw Normal View History

2019-04-11 14:40:54 +08:00
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "ActionManager.h"
#include "../Actor.h"
2019-08-14 21:52:49 +08:00
#include "../../base/Logger.h"
2019-04-11 14:40:54 +08:00
namespace kiwano
{
void ActionManager::UpdateActions(ActorPtr target, Duration dt)
{
2019-08-20 19:32:36 +08:00
if (actions_.empty() || !target)
return;
ActionPtr next;
2019-08-13 21:16:38 +08:00
for (auto action = actions_.first_item(); action; action = next)
{
2019-08-13 21:16:38 +08:00
next = action->next_item();
if (action->IsRunning())
action->UpdateStep(target, dt);
if (action->IsRemoveable())
2019-08-20 19:32:36 +08:00
actions_.remove(action);
}
}
2019-08-18 22:49:44 +08:00
Action* ActionManager::AddAction(ActionPtr action)
{
2019-04-11 14:40:54 +08:00
KGE_ASSERT(action && "AddAction failed, NULL pointer exception");
if (action)
{
2019-08-20 19:32:36 +08:00
actions_.push_back(action);
}
2019-08-18 22:49:44 +08:00
return action.get();
}
ActionPtr ActionManager::GetAction(String const & name)
{
2019-08-20 19:32:36 +08:00
if (actions_.empty())
return nullptr;
2019-08-13 21:16:38 +08:00
for (auto action = actions_.first_item().get(); action; action = action->next_item().get())
if (action->IsName(name))
return action;
return nullptr;
}
void ActionManager::ResumeAllActions()
{
2019-08-20 19:32:36 +08:00
if (actions_.empty())
return;
2019-08-13 21:16:38 +08:00
for (auto action = actions_.first_item().get(); action; action = action->next_item().get())
{
action->Resume();
}
}
void ActionManager::PauseAllActions()
{
2019-08-20 19:32:36 +08:00
if (actions_.empty())
return;
2019-08-13 21:16:38 +08:00
for (auto action = actions_.first_item().get(); action; action = action->next_item().get())
{
action->Pause();
}
}
void ActionManager::StopAllActions()
{
2019-08-20 19:32:36 +08:00
if (actions_.empty())
return;
2019-08-13 21:16:38 +08:00
for (auto action = actions_.first_item().get(); action; action = action->next_item().get())
{
action->Stop();
}
}
const ActionManager::Actions& ActionManager::GetAllActions() const
{
return actions_;
}
}