add: use intrusive pointers to solve memory management problems

minor improves
This commit is contained in:
Haibo 2018-11-14 01:34:41 +08:00 committed by Nomango
parent b44f71e251
commit ccba1363a0
54 changed files with 856 additions and 920 deletions

View File

@ -1,106 +0,0 @@
// Copyright (c) 2016-2018 Easy2D - 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 "Action.h"
#include "base.h"
namespace easy2d
{
Action::Action()
: running_(false), done_(false), initialized_(false), target_(nullptr)
{
}
Action::~Action()
{
}
bool Action::IsRunning()
{
return running_;
}
void Action::Resume()
{
running_ = true;
}
void Action::Pause()
{
running_ = false;
}
void Action::Stop()
{
done_ = true;
}
const String& Action::GetName() const
{
return name_;
}
void Action::SetName(const String& name)
{
name_ = name;
}
Node * Action::GetTarget()
{
return target_;
}
void Action::Reset()
{
initialized_ = false;
done_ = false;
started_ = time::Now();
}
bool Action::IsDone() const
{
return done_;
}
void Action::StartWithTarget(Node* target)
{
target_ = target;
running_ = true;
this->Reset();
}
void Action::Initialize()
{
initialized_ = true;
started_ = time::Now();
}
void Action::Update()
{
if (!initialized_)
{
Initialize();
}
}
void Action::ResetTime()
{
}
}

View File

@ -21,85 +21,86 @@
#pragma once #pragma once
#include "base.h" #include "base.h"
#include "time.h" #include "time.h"
#include "RefCounter.h"
namespace easy2d namespace easy2d
{ {
class Node;
class Loop;
class Sequence;
class Spawn;
// 基础动作
class Action class Action
: public RefCounter : public RefCounter
{ {
E2D_DISABLE_COPY(Action);
friend class Node;
friend class Loop; friend class Loop;
friend class Sequence; friend class Sequence;
friend class Spawn; friend class Spawn;
E2D_DISABLE_COPY(Action);
public: public:
Action(); Action() : running_(false), done_(false), initialized_(false) {}
virtual ~Action(); virtual ~Action() {}
// 获取动作运行状态 // 获取动作运行状态
virtual bool IsRunning(); inline bool IsRunning() { return running_; }
// 继续动作 // 继续动作
virtual void Resume(); inline void Resume() { running_ = true; }
// 暂停动作 // 暂停动作
virtual void Pause(); inline void Pause() { running_ = false; }
// 停止动作 // 停止动作
virtual void Stop(); inline void Stop() { done_ = true; }
// 获取动作名称 // 获取动作名称
virtual const String& GetName() const; inline const String& GetName() const { return name_; }
// 设置动作名称 // 设置动作名称
virtual void SetName( inline void SetName(const String& name) { name_ = name; }
const String& name
); inline bool IsDone() const { return done_; }
// 获取动作的拷贝 // 获取动作的拷贝
virtual Action * Clone() const = 0; virtual spAction Clone() const = 0;
// 获取动作的倒转 // 获取动作的倒转
virtual Action * Reverse() const = 0; virtual spAction Reverse() const = 0;
// 重置动作 // 重置动作
virtual void Reset(); virtual void Reset()
{
// 获取该动作的执行目标 initialized_ = false;
virtual Node * GetTarget(); done_ = false;
started_ = time::Now();
// 开始动作 }
virtual void StartWithTarget(
Node* target
);
// 初始化动作
virtual void Initialize();
// 更新动作
virtual void Update();
// 重置动作时间
virtual void ResetTime();
// 获取动作结束状态
virtual bool IsDone() const;
protected: protected:
String name_; virtual void Start()
bool running_; {
bool done_; running_ = true;
bool initialized_; this->Reset();
Node* target_; }
time::TimePoint started_;
virtual void Init(Node* target)
{
initialized_ = true;
started_ = time::Now();
}
virtual void Update(Node* target)
{
if (!initialized_)
{
Init(target);
}
}
virtual void ResetTime() {}
protected:
String name_;
bool running_;
bool done_;
bool initialized_;
TimePoint started_;
}; };
} }

View File

@ -27,30 +27,25 @@ namespace easy2d
// Loop // Loop
//------------------------------------------------------- //-------------------------------------------------------
Loop::Loop(Action * action, int times) Loop::Loop(spAction const& action, int times)
: action_(action) : action_(action)
, times_(0) , times_(0)
, total_times_(times) , total_times_(times)
{ {
E2D_WARNING_IF(action == nullptr, "Loop NULL pointer exception!"); E2D_WARNING_IF(!action, "Loop NULL pointer exception!");
if (action) action_ = action;
{
action_ = action;
action_->Retain();
}
} }
Loop::~Loop() Loop::~Loop()
{ {
SafeRelease(action_);
} }
Loop * Loop::Clone() const spAction Loop::Clone() const
{ {
if (action_) if (action_)
{ {
return new Loop(action_->Clone()); return new (std::nothrow) Loop(action_->Clone());
} }
else else
{ {
@ -58,11 +53,11 @@ namespace easy2d
} }
} }
Loop * Loop::Reverse() const spAction Loop::Reverse() const
{ {
if (action_) if (action_)
{ {
return new Loop(action_->Clone()); return new (std::nothrow) Loop(action_->Clone());
} }
else else
{ {
@ -70,20 +65,19 @@ namespace easy2d
} }
} }
void Loop::Initialize() void Loop::Init(Node* target)
{ {
Action::Initialize(); Action::Init(target);
if (action_) if (action_)
{ {
action_->target_ = target_; action_->Init(target);
action_->Initialize();
} }
} }
void Loop::Update() void Loop::Update(Node* target)
{ {
Action::Update(); Action::Update(target);
if (times_ == total_times_) if (times_ == total_times_)
{ {
@ -93,7 +87,7 @@ namespace easy2d
if (action_) if (action_)
{ {
action_->Update(); action_->Update(target);
if (action_->IsDone()) if (action_->IsDone())
{ {
@ -140,33 +134,20 @@ namespace easy2d
Sequence::~Sequence() Sequence::~Sequence()
{ {
for (auto action : actions_)
{
SafeRelease(action);
}
} }
void Sequence::Initialize() void Sequence::Init(Node* target)
{ {
Action::Initialize(); Action::Init(target);
// 将所有动作与目标绑定 actions_[0]->Init(target);
if (target_)
{
for (const auto& action : actions_)
{
action->target_ = target_;
}
}
// 初始化第一个动作
actions_[0]->Initialize();
} }
void Sequence::Update() void Sequence::Update(Node* target)
{ {
Action::Update(); Action::Update(target);
auto &action = actions_[action_index_]; auto &action = actions_[action_index_];
action->Update(); action->Update(target);
if (action->IsDone()) if (action->IsDone())
{ {
@ -177,7 +158,7 @@ namespace easy2d
} }
else else
{ {
actions_[action_index_]->Initialize(); actions_[action_index_]->Init(target);
} }
} }
} }
@ -200,12 +181,11 @@ namespace easy2d
} }
} }
void Sequence::Add(Action * action) void Sequence::Add(spAction const& action)
{ {
if (action) if (action)
{ {
actions_.push_back(action); actions_.push_back(action);
action->Retain();
} }
} }
@ -217,30 +197,32 @@ namespace easy2d
} }
} }
Sequence * Sequence::Clone() const spAction Sequence::Clone() const
{ {
auto sequence = new Sequence(); auto sequence = new (std::nothrow) Sequence();
for (const auto& action : actions_) if (sequence)
{ {
if (action) for (const auto& action : actions_)
{ {
sequence->Add(action->Clone()); if (action)
{
sequence->Add(action->Clone());
}
} }
} }
return sequence; return sequence;
} }
Sequence * Sequence::Reverse() const spAction Sequence::Reverse() const
{ {
auto sequence = new Sequence(); auto sequence = new (std::nothrow) Sequence();
if (sequence && !actions_.empty()) if (sequence && !actions_.empty())
{ {
std::vector<Action*> newActions(actions_.size()); for (auto iter = actions_.crbegin(), crend = actions_.crend(); iter != crend; ++iter)
for (auto iter = actions_.crbegin(), iterCrend = actions_.crend(); iter != iterCrend; ++iter)
{ {
newActions.push_back((*iter)->Reverse()); if (*iter)
sequence->Add((*iter)->Reverse());
} }
sequence->Add(newActions);
} }
return sequence; return sequence;
} }
@ -261,29 +243,24 @@ namespace easy2d
Spawn::~Spawn() Spawn::~Spawn()
{ {
for (auto action : actions_)
{
SafeRelease(action);
}
} }
void Spawn::Initialize() void Spawn::Init(Node* target)
{ {
Action::Initialize(); Action::Init(target);
if (target_) if (target)
{ {
for (const auto& action : actions_) for (const auto& action : actions_)
{ {
action->target_ = target_; action->Init(target);
action->Initialize();
} }
} }
} }
void Spawn::Update() void Spawn::Update(Node* target)
{ {
Action::Update(); Action::Update(target);
size_t done_num = 0; size_t done_num = 0;
for (const auto& action : actions_) for (const auto& action : actions_)
@ -294,7 +271,7 @@ namespace easy2d
} }
else else
{ {
action->Update(); action->Update(target);
} }
} }
@ -321,12 +298,11 @@ namespace easy2d
} }
} }
void Spawn::Add(Action * action) void Spawn::Add(spAction const& action)
{ {
if (action) if (action)
{ {
actions_.push_back(action); actions_.push_back(action);
action->Retain();
} }
} }
@ -338,30 +314,32 @@ namespace easy2d
} }
} }
Spawn * Spawn::Clone() const spAction Spawn::Clone() const
{ {
auto spawn = new Spawn(); auto spawn = new (std::nothrow) Spawn();
for (const auto& action : actions_) if (spawn)
{ {
if (action) for (const auto& action : actions_)
{ {
spawn->Add(action->Clone()); if (action)
{
spawn->Add(action->Clone());
}
} }
} }
return spawn; return spawn;
} }
Spawn * Spawn::Reverse() const spAction Spawn::Reverse() const
{ {
auto spawn = new Spawn(); auto spawn = new (std::nothrow) Spawn();
if (spawn && !actions_.empty()) if (spawn && !actions_.empty())
{ {
std::vector<Action*> newActions(actions_.size()); for (auto iter = actions_.crbegin(), crend = actions_.crend(); iter != crend; ++iter)
for (auto iter = actions_.crbegin(), iterCrend = actions_.crend(); iter != iterCrend; ++iter)
{ {
newActions.push_back((*iter)->Reverse()); if (*iter)
spawn->Add((*iter)->Reverse());
} }
spawn->Add(newActions);
} }
return spawn; return spawn;
} }

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "Action.h" #include "Action.hpp"
namespace easy2d namespace easy2d
{ {
@ -31,35 +31,35 @@ namespace easy2d
public: public:
explicit Loop( explicit Loop(
Action * action, /* 执行循环的动作 */ spAction const& action, /* 执行循环的动作 */
int times = -1 /* 循环次数 */ int times = -1 /* 循环次数 */
); );
virtual ~Loop(); virtual ~Loop();
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual Loop * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual Loop * Reverse() const override; virtual spAction Reverse() const override;
// 重置动作 // 重置动作
virtual void Reset() override; virtual void Reset() override;
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node* target) override;
// 重置动作时间 // 重置动作时间
virtual void ResetTime() override; virtual void ResetTime() override;
protected: protected:
Action * action_; spAction action_;
int times_; int times_;
int total_times_; int total_times_;
}; };
@ -70,8 +70,6 @@ namespace easy2d
E2D_DISABLE_COPY(Sequence); E2D_DISABLE_COPY(Sequence);
public: public:
typedef std::vector<Action*> Actions;
Sequence(); Sequence();
explicit Sequence( explicit Sequence(
@ -82,7 +80,7 @@ namespace easy2d
// 在结尾添加动作 // 在结尾添加动作
void Add( void Add(
Action * action spAction const& action
); );
// 在结尾添加多个动作 // 在结尾添加多个动作
@ -91,20 +89,20 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual Sequence * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual Sequence * Reverse() const; virtual spAction Reverse() const override;
// 重置动作 // 重置动作
virtual void Reset() override; virtual void Reset() override;
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node* target) override;
// 重置动作时间 // 重置动作时间
virtual void ResetTime() override; virtual void ResetTime() override;
@ -122,8 +120,6 @@ namespace easy2d
E2D_DISABLE_COPY(Spawn); E2D_DISABLE_COPY(Spawn);
public: public:
typedef std::vector<Action*> Actions;
Spawn(); Spawn();
explicit Spawn( explicit Spawn(
@ -134,7 +130,7 @@ namespace easy2d
// 在结尾添加动作 // 在结尾添加动作
void Add( void Add(
Action * action spAction const& action
); );
// 在结尾添加多个动作 // 在结尾添加多个动作
@ -143,20 +139,20 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual Spawn * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual Spawn * Reverse() const; virtual spAction Reverse() const;
// 重置动作 // 重置动作
virtual void Reset() override; virtual void Reset() override;
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node* target) override;
// 重置动作时间 // 重置动作时间
virtual void ResetTime() override; virtual void ResetTime() override;

View File

@ -41,14 +41,14 @@ namespace easy2d
delta_ = 0; delta_ = 0;
} }
void FiniteTimeAction::Initialize() void FiniteTimeAction::Init(Node* target)
{ {
Action::Initialize(); Action::Init(target);
} }
void FiniteTimeAction::Update() void FiniteTimeAction::Update(Node* target)
{ {
Action::Update(); Action::Update(target);
if (duration_ == 0) if (duration_ == 0)
{ {
@ -83,41 +83,41 @@ namespace easy2d
delta_pos_ = vector; delta_pos_ = vector;
} }
void MoveBy::Initialize() void MoveBy::Init(Node* target)
{ {
FiniteTimeAction::Initialize(); FiniteTimeAction::Init(target);
if (target_) if (target)
{ {
prev_pos_ = start_pos_ = target_->GetPosition(); prev_pos_ = start_pos_ = target->GetPosition();
} }
} }
void MoveBy::Update() void MoveBy::Update(Node* target)
{ {
FiniteTimeAction::Update(); FiniteTimeAction::Update(target);
if (target_) if (target)
{ {
Point currentPos = target_->GetPosition(); Point currentPos = target->GetPosition();
Point diff = currentPos - prev_pos_; Point diff = currentPos - prev_pos_;
start_pos_ = start_pos_ + diff; start_pos_ = start_pos_ + diff;
Point newPos = start_pos_ + (delta_pos_ * delta_); Point newPos = start_pos_ + (delta_pos_ * delta_);
target_->SetPosition(newPos); target->SetPosition(newPos);
prev_pos_ = newPos; prev_pos_ = newPos;
} }
} }
MoveBy * MoveBy::Clone() const spAction MoveBy::Clone() const
{ {
return new MoveBy(duration_, delta_pos_); return new (std::nothrow) MoveBy(duration_, delta_pos_);
} }
MoveBy * MoveBy::Reverse() const spAction MoveBy::Reverse() const
{ {
return new MoveBy(duration_, -delta_pos_); return new (std::nothrow) MoveBy(duration_, -delta_pos_);
} }
MoveTo::MoveTo(float duration, Point pos) MoveTo::MoveTo(float duration, Point pos)
@ -126,14 +126,14 @@ namespace easy2d
end_pos_ = pos; end_pos_ = pos;
} }
MoveTo * MoveTo::Clone() const spAction MoveTo::Clone() const
{ {
return new MoveTo(duration_, end_pos_); return new (std::nothrow) MoveTo(duration_, end_pos_);
} }
void MoveTo::Initialize() void MoveTo::Init(Node* target)
{ {
MoveBy::Initialize(); MoveBy::Init(target);
delta_pos_ = end_pos_ - start_pos_; delta_pos_ = end_pos_ - start_pos_;
} }
@ -150,44 +150,44 @@ namespace easy2d
{ {
} }
JumpBy * JumpBy::Clone() const spAction JumpBy::Clone() const
{ {
return new JumpBy(duration_, delta_pos_, height_, jumps_); return new (std::nothrow) JumpBy(duration_, delta_pos_, height_, jumps_);
} }
JumpBy * JumpBy::Reverse() const spAction JumpBy::Reverse() const
{ {
return new JumpBy(duration_, -delta_pos_, height_, jumps_); return new (std::nothrow) JumpBy(duration_, -delta_pos_, height_, jumps_);
} }
void JumpBy::Initialize() void JumpBy::Init(Node* target)
{ {
FiniteTimeAction::Initialize(); FiniteTimeAction::Init(target);
if (target_) if (target)
{ {
prev_pos_ = start_pos_ = target_->GetPosition(); prev_pos_ = start_pos_ = target->GetPosition();
} }
} }
void JumpBy::Update() void JumpBy::Update(Node* target)
{ {
FiniteTimeAction::Update(); FiniteTimeAction::Update(target);
if (target_) if (target)
{ {
float frac = fmod(delta_ * jumps_, 1.f); float frac = fmod(delta_ * jumps_, 1.f);
float x = delta_pos_.x * delta_; float x = delta_pos_.x * delta_;
float y = height_ * 4 * frac * (1 - frac); float y = height_ * 4 * frac * (1 - frac);
y += delta_pos_.y * delta_; y += delta_pos_.y * delta_;
Point currentPos = target_->GetPosition(); Point currentPos = target->GetPosition();
Point diff = currentPos - prev_pos_; Point diff = currentPos - prev_pos_;
start_pos_ = diff + start_pos_; start_pos_ = diff + start_pos_;
Point newPos = start_pos_ + Point(x, y); Point newPos = start_pos_ + Point(x, y);
target_->SetPosition(newPos); target->SetPosition(newPos);
prev_pos_ = newPos; prev_pos_ = newPos;
} }
@ -199,14 +199,14 @@ namespace easy2d
{ {
} }
JumpTo * JumpTo::Clone() const spAction JumpTo::Clone() const
{ {
return new JumpTo(duration_, end_pos_, height_, jumps_); return new (std::nothrow) JumpTo(duration_, end_pos_, height_, jumps_);
} }
void JumpTo::Initialize() void JumpTo::Init(Node* target)
{ {
JumpBy::Initialize(); JumpBy::Init(target);
delta_pos_ = end_pos_ - start_pos_; delta_pos_ = end_pos_ - start_pos_;
} }
@ -229,35 +229,35 @@ namespace easy2d
delta_y_ = scale_y; delta_y_ = scale_y;
} }
void ScaleBy::Initialize() void ScaleBy::Init(Node* target)
{ {
FiniteTimeAction::Initialize(); FiniteTimeAction::Init(target);
if (target_) if (target)
{ {
start_scale_x_ = target_->GetScaleX(); start_scale_x_ = target->GetScaleX();
start_scale_y_ = target_->GetScaleY(); start_scale_y_ = target->GetScaleY();
} }
} }
void ScaleBy::Update() void ScaleBy::Update(Node* target)
{ {
FiniteTimeAction::Update(); FiniteTimeAction::Update(target);
if (target_) if (target)
{ {
target_->SetScale(start_scale_x_ + delta_x_ * delta_, start_scale_y_ + delta_y_ * delta_); target->SetScale(start_scale_x_ + delta_x_ * delta_, start_scale_y_ + delta_y_ * delta_);
} }
} }
ScaleBy * ScaleBy::Clone() const spAction ScaleBy::Clone() const
{ {
return new ScaleBy(duration_, delta_x_, delta_y_); return new (std::nothrow) ScaleBy(duration_, delta_x_, delta_y_);
} }
ScaleBy * ScaleBy::Reverse() const spAction ScaleBy::Reverse() const
{ {
return new ScaleBy(duration_, -delta_x_, -delta_y_); return new (std::nothrow) ScaleBy(duration_, -delta_x_, -delta_y_);
} }
ScaleTo::ScaleTo(float duration, float scale) ScaleTo::ScaleTo(float duration, float scale)
@ -274,14 +274,14 @@ namespace easy2d
end_scale_y_ = scale_y; end_scale_y_ = scale_y;
} }
ScaleTo * ScaleTo::Clone() const spAction ScaleTo::Clone() const
{ {
return new ScaleTo(duration_, end_scale_x_, end_scale_y_); return new (std::nothrow) ScaleTo(duration_, end_scale_x_, end_scale_y_);
} }
void ScaleTo::Initialize() void ScaleTo::Init(Node* target)
{ {
ScaleBy::Initialize(); ScaleBy::Init(target);
delta_x_ = end_scale_x_ - start_scale_x_; delta_x_ = end_scale_x_ - start_scale_x_;
delta_y_ = end_scale_y_ - start_scale_y_; delta_y_ = end_scale_y_ - start_scale_y_;
} }
@ -297,34 +297,34 @@ namespace easy2d
delta_val_ = opacity; delta_val_ = opacity;
} }
void OpacityBy::Initialize() void OpacityBy::Init(Node* target)
{ {
FiniteTimeAction::Initialize(); FiniteTimeAction::Init(target);
if (target_) if (target)
{ {
start_val_ = target_->GetOpacity(); start_val_ = target->GetOpacity();
} }
} }
void OpacityBy::Update() void OpacityBy::Update(Node* target)
{ {
FiniteTimeAction::Update(); FiniteTimeAction::Update(target);
if (target_) if (target)
{ {
target_->SetOpacity(start_val_ + delta_val_ * delta_); target->SetOpacity(start_val_ + delta_val_ * delta_);
} }
} }
OpacityBy * OpacityBy::Clone() const spAction OpacityBy::Clone() const
{ {
return new OpacityBy(duration_, delta_val_); return new (std::nothrow) OpacityBy(duration_, delta_val_);
} }
OpacityBy * OpacityBy::Reverse() const spAction OpacityBy::Reverse() const
{ {
return new OpacityBy(duration_, -delta_val_); return new (std::nothrow) OpacityBy(duration_, -delta_val_);
} }
OpacityTo::OpacityTo(float duration, float opacity) OpacityTo::OpacityTo(float duration, float opacity)
@ -333,14 +333,14 @@ namespace easy2d
end_val_ = opacity; end_val_ = opacity;
} }
OpacityTo * OpacityTo::Clone() const spAction OpacityTo::Clone() const
{ {
return new OpacityTo(duration_, end_val_); return new (std::nothrow) OpacityTo(duration_, end_val_);
} }
void OpacityTo::Initialize() void OpacityTo::Init(Node* target)
{ {
OpacityBy::Initialize(); OpacityBy::Init(target);
delta_val_ = end_val_ - start_val_; delta_val_ = end_val_ - start_val_;
} }
@ -365,34 +365,34 @@ namespace easy2d
delta_val_ = rotation; delta_val_ = rotation;
} }
void RotateBy::Initialize() void RotateBy::Init(Node* target)
{ {
FiniteTimeAction::Initialize(); FiniteTimeAction::Init(target);
if (target_) if (target)
{ {
start_val_ = target_->GetRotation(); start_val_ = target->GetRotation();
} }
} }
void RotateBy::Update() void RotateBy::Update(Node* target)
{ {
FiniteTimeAction::Update(); FiniteTimeAction::Update(target);
if (target_) if (target)
{ {
target_->SetRotation(start_val_ + delta_val_ * delta_); target->SetRotation(start_val_ + delta_val_ * delta_);
} }
} }
RotateBy * RotateBy::Clone() const spAction RotateBy::Clone() const
{ {
return new RotateBy(duration_, delta_val_); return new (std::nothrow) RotateBy(duration_, delta_val_);
} }
RotateBy * RotateBy::Reverse() const spAction RotateBy::Reverse() const
{ {
return new RotateBy(duration_, -delta_val_); return new (std::nothrow) RotateBy(duration_, -delta_val_);
} }
RotateTo::RotateTo(float duration, float rotation) RotateTo::RotateTo(float duration, float rotation)
@ -401,14 +401,14 @@ namespace easy2d
end_val_ = rotation; end_val_ = rotation;
} }
RotateTo * RotateTo::Clone() const spAction RotateTo::Clone() const
{ {
return new RotateTo(duration_, end_val_); return new (std::nothrow) RotateTo(duration_, end_val_);
} }
void RotateTo::Initialize() void RotateTo::Init(Node* target)
{ {
RotateBy::Initialize(); RotateBy::Init(target);
delta_val_ = end_val_ - start_val_; delta_val_ = end_val_ - start_val_;
} }
@ -429,14 +429,14 @@ namespace easy2d
delta_ = 0; delta_ = 0;
} }
void Delay::Initialize() void Delay::Init(Node* target)
{ {
Action::Initialize(); Action::Init(target);
} }
void Delay::Update() void Delay::Update(Node* target)
{ {
Action::Update(); Action::Update(target);
delta_ = (time::Now() - started_).Seconds(); delta_ = (time::Now() - started_).Seconds();
@ -452,13 +452,13 @@ namespace easy2d
started_ = time::Now() - time::Second * delta_; started_ = time::Now() - time::Second * delta_;
} }
Delay * Delay::Clone() const spAction Delay::Clone() const
{ {
return new Delay(delay_); return new (std::nothrow) Delay(delay_);
} }
Delay * Delay::Reverse() const spAction Delay::Reverse() const
{ {
return new Delay(delay_); return new (std::nothrow) Delay(delay_);
} }
} }

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "Action.h" #include "Action.hpp"
namespace easy2d namespace easy2d
{ {
@ -40,10 +40,10 @@ namespace easy2d
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node* target) override;
// 重置动作时间 // 重置动作时间
virtual void ResetTime() override; virtual void ResetTime() override;
@ -67,17 +67,17 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual MoveBy * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual MoveBy * Reverse() const override; virtual spAction Reverse() const override;
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node* target) override;
protected: protected:
Point start_pos_; Point start_pos_;
@ -99,10 +99,10 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual MoveTo * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual MoveTo * Reverse() const override virtual spAction Reverse() const override
{ {
E2D_WARNING("Reverse() not supported in MoveTo"); E2D_WARNING("Reverse() not supported in MoveTo");
return nullptr; return nullptr;
@ -110,7 +110,7 @@ namespace easy2d
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
protected: protected:
Point end_pos_; Point end_pos_;
@ -132,17 +132,17 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual JumpBy * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual JumpBy * Reverse() const override; virtual spAction Reverse() const override;
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node* target) override;
protected: protected:
Point start_pos_; Point start_pos_;
@ -168,10 +168,10 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual JumpTo * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual JumpTo * Reverse() const override virtual spAction Reverse() const override
{ {
E2D_WARNING("Reverse() not supported in JumpTo"); E2D_WARNING("Reverse() not supported in JumpTo");
return nullptr; return nullptr;
@ -179,7 +179,7 @@ namespace easy2d
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
protected: protected:
Point end_pos_; Point end_pos_;
@ -205,17 +205,17 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual ScaleBy * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual ScaleBy * Reverse() const override; virtual spAction Reverse() const override;
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node* target) override;
protected: protected:
float start_scale_x_; float start_scale_x_;
@ -244,10 +244,10 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual ScaleTo * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual ScaleTo * Reverse() const override virtual spAction Reverse() const override
{ {
E2D_WARNING("Reverse() not supported in ScaleTo"); E2D_WARNING("Reverse() not supported in ScaleTo");
return nullptr; return nullptr;
@ -255,7 +255,7 @@ namespace easy2d
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
protected: protected:
float end_scale_x_; float end_scale_x_;
@ -276,17 +276,17 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual OpacityBy * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual OpacityBy * Reverse() const override; virtual spAction Reverse() const override;
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node* target) override;
protected: protected:
float start_val_; float start_val_;
@ -307,10 +307,10 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual OpacityTo * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual OpacityTo * Reverse() const override virtual spAction Reverse() const override
{ {
E2D_WARNING("Reverse() not supported in OpacityTo"); E2D_WARNING("Reverse() not supported in OpacityTo");
return nullptr; return nullptr;
@ -318,7 +318,7 @@ namespace easy2d
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
protected: protected:
float end_val_; float end_val_;
@ -366,17 +366,17 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual RotateBy * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual RotateBy * Reverse() const override; virtual spAction Reverse() const override;
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node* target) override;
protected: protected:
float start_val_; float start_val_;
@ -397,10 +397,10 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual RotateTo * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual RotateTo * Reverse() const override virtual spAction Reverse() const override
{ {
E2D_WARNING("Reverse() not supported in RotateTo"); E2D_WARNING("Reverse() not supported in RotateTo");
return nullptr; return nullptr;
@ -408,7 +408,7 @@ namespace easy2d
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
protected: protected:
float end_val_; float end_val_;
@ -427,20 +427,20 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual Delay * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual Delay * Reverse() const override; virtual spAction Reverse() const override;
// 重置动作 // 重置动作
virtual void Reset() override; virtual void Reset() override;
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node* target) override;
// 重置动作时间 // 重置动作时间
virtual void ResetTime() override; virtual void ResetTime() override;

View File

@ -33,7 +33,7 @@ namespace easy2d
{ {
} }
Animate::Animate(Animation * animation) Animate::Animate(spAnimation const& animation)
: frame_index_(0) : frame_index_(0)
, animation_(nullptr) , animation_(nullptr)
{ {
@ -42,43 +42,37 @@ namespace easy2d
Animate::~Animate() Animate::~Animate()
{ {
SafeRelease(animation_);
} }
Animation * Animate::GetAnimation() const spAnimation Animate::GetAnimation() const
{ {
return animation_; return animation_;
} }
void Animate::SetAnimation(Animation * animation) void Animate::SetAnimation(spAnimation const& animation)
{ {
if (animation && animation != animation_) if (animation && animation != animation_)
{ {
if (animation_)
{
animation_->Release();
}
animation_ = animation; animation_ = animation;
animation_->Retain();
frame_index_ = 0; frame_index_ = 0;
} }
} }
void Animate::Initialize() void Animate::Init(Node* target)
{ {
Action::Initialize(); Action::Init(target);
auto target = dynamic_cast<Sprite*>(target_); auto sprite_target = dynamic_cast<Sprite*>(target);
if (target && animation_) if (sprite_target && animation_)
{ {
target->Load(animation_->GetFrames()[frame_index_]); sprite_target->Load(animation_->GetFrames()[frame_index_]);
++frame_index_; ++frame_index_;
} }
} }
void Animate::Update() void Animate::Update(Node* target)
{ {
Action::Update(); Action::Update(target);
if (!animation_) if (!animation_)
{ {
@ -89,11 +83,11 @@ namespace easy2d
while ((time::Now() - started_).Seconds() >= animation_->GetInterval()) while ((time::Now() - started_).Seconds() >= animation_->GetInterval())
{ {
auto& frames = animation_->GetFrames(); auto& frames = animation_->GetFrames();
auto target = dynamic_cast<Sprite*>(target_); auto sprite_target = dynamic_cast<Sprite*>(target);
if (target) if (sprite_target)
{ {
target->Load(frames[frame_index_]); sprite_target->Load(frames[frame_index_]);
} }
started_ += time::Second * animation_->GetInterval(); started_ += time::Second * animation_->GetInterval();
@ -118,23 +112,23 @@ namespace easy2d
frame_index_ = 0; frame_index_ = 0;
} }
Animate * Animate::Clone() const spAction Animate::Clone() const
{ {
if (animation_) if (animation_)
{ {
return new Animate(animation_); return new (std::nothrow) Animate(animation_);
} }
return nullptr; return nullptr;
} }
Animate * Animate::Reverse() const spAction Animate::Reverse() const
{ {
if (animation_) if (animation_)
{ {
auto animation = animation_->Reverse(); auto animation = animation_->Reverse();
if (animation) if (animation)
{ {
return new Animate(animation); return new (std::nothrow) Animate(animation);
} }
} }
return nullptr; return nullptr;
@ -169,10 +163,6 @@ namespace easy2d
Animation::~Animation() Animation::~Animation()
{ {
for (auto frame : frames_)
{
SafeRelease(frame);
}
} }
void Animation::SetInterval(float interval) void Animation::SetInterval(float interval)
@ -180,13 +170,12 @@ namespace easy2d
interval_ = std::max(interval, 0.f); interval_ = std::max(interval, 0.f);
} }
void Animation::Add(Image * frame) void Animation::Add(spImage const& frame)
{ {
E2D_WARNING_IF(frame == nullptr, "Animation::Add failed, frame Is nullptr."); E2D_WARNING_IF(!frame, "Animation::Add failed, frame Is nullptr.");
if (frame) if (frame)
{ {
frames_.push_back(frame); frames_.push_back(frame);
frame->Retain();
} }
} }
@ -203,14 +192,14 @@ namespace easy2d
return interval_; return interval_;
} }
const Animation::Images& Animation::GetFrames() const const Images& Animation::GetFrames() const
{ {
return frames_; return frames_;
} }
Animation * Animation::Clone() const spAnimation Animation::Clone() const
{ {
auto animation = new Animation(interval_); auto animation = new (std::nothrow) Animation(interval_);
if (animation) if (animation)
{ {
for (const auto& frame : frames_) for (const auto& frame : frames_)
@ -221,26 +210,17 @@ namespace easy2d
return animation; return animation;
} }
Animation * Animation::Reverse() const spAnimation Animation::Reverse() const
{ {
auto& oldFrames = this->GetFrames(); auto animation = new (std::nothrow) Animation(interval_);
Images frames(oldFrames.size()); if (!frames_.empty())
if (!oldFrames.empty())
{ {
for (auto iter = oldFrames.crbegin(), for (auto iter = frames_.crbegin(), crend = frames_.crend(); iter != crend; ++iter)
iterCrend = oldFrames.crend();
iter != iterCrend;
++iter)
{ {
Image* frame = *iter; if (*iter)
if (frame) animation->Add(*iter);
{
frames.push_back(frame);
}
} }
} }
return animation;
return new Animation(this->GetInterval(), frames);
} }
} }

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "Action.h" #include "Action.hpp"
#include "Image.h" #include "Image.h"
namespace easy2d namespace easy2d
@ -31,8 +31,6 @@ namespace easy2d
E2D_DISABLE_COPY(Animation); E2D_DISABLE_COPY(Animation);
public: public:
typedef std::vector<Image*> Images;
Animation(); Animation();
explicit Animation( explicit Animation(
@ -52,7 +50,7 @@ namespace easy2d
// 添加关键帧 // 添加关键帧
void Add( void Add(
Image * frame /* ¹Ø¼üÖ¡ */ spImage const& frame /* ¹Ø¼üÖ¡ */
); );
// 添加多个关键帧 // 添加多个关键帧
@ -72,10 +70,10 @@ namespace easy2d
); );
// 获取帧动画的拷贝对象 // 获取帧动画的拷贝对象
Animation * Clone() const; spAnimation Clone() const;
// 获取帧动画的倒转 // 获取帧动画的倒转
Animation * Reverse() const; spAnimation Reverse() const;
protected: protected:
float interval_; float interval_;
@ -93,40 +91,40 @@ namespace easy2d
Animate(); Animate();
explicit Animate( explicit Animate(
Animation * animation spAnimation const& animation
); );
virtual ~Animate(); virtual ~Animate();
// 获取动画 // 获取动画
virtual Animation * GetAnimation() const; spAnimation GetAnimation() const;
// 设置动画 // 设置动画
virtual void SetAnimation( void SetAnimation(
Animation * animation spAnimation const& animation
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual Animate * Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual Animate * Reverse() const override; virtual spAction Reverse() const override;
// 重置动作 // 重置动作
virtual void Reset() override; virtual void Reset() override;
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node* target) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node* target) override;
// 重置动作时间 // 重置动作时间
virtual void ResetTime() override; virtual void ResetTime() override;
protected: protected:
UINT frame_index_; UINT frame_index_;
Animation * animation_; spAnimation animation_;
}; };
} }

View File

@ -20,10 +20,10 @@
#pragma once #pragma once
#include "macros.h" #include "macros.h"
#include "../math/vector.hpp"
#include "Color.h" #include "Color.h"
#include "Size.h" #include "Size.h"
#include "Rect.hpp" #include "Rect.hpp"
#include "../math/vector.hpp"
namespace easy2d namespace easy2d
{ {

View File

@ -27,21 +27,21 @@ namespace easy2d
{ {
} }
CallFunc * CallFunc::Clone() const spAction CallFunc::Clone() const
{ {
return new CallFunc(callback_); return new CallFunc(callback_);
} }
CallFunc * CallFunc::Reverse() const spAction CallFunc::Reverse() const
{ {
return new CallFunc(callback_); return new CallFunc(callback_);
} }
void CallFunc::Initialize() void CallFunc::Init(Node*)
{ {
} }
void CallFunc::Update() void CallFunc::Update(Node*)
{ {
callback_(); callback_();
this->Stop(); this->Stop();

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "Action.h" #include "Action.hpp"
#include <functional> #include <functional>
namespace easy2d namespace easy2d
@ -38,17 +38,17 @@ namespace easy2d
); );
// 获取该动作的拷贝对象 // 获取该动作的拷贝对象
virtual CallFunc *Clone() const override; virtual spAction Clone() const override;
// 获取该动作的倒转 // 获取该动作的倒转
virtual CallFunc *Reverse() const override; virtual spAction Reverse() const override;
protected: protected:
// 初始化动作 // 初始化动作
virtual void Initialize() override; virtual void Init(Node*) override;
// 更新动作 // 更新动作
virtual void Update() override; virtual void Update(Node*) override;
protected: protected:
Callback callback_; Callback callback_;

View File

@ -39,33 +39,37 @@ namespace easy2d
, curr_scene_(nullptr) , curr_scene_(nullptr)
, next_scene_(nullptr) , next_scene_(nullptr)
, transition_(nullptr) , transition_(nullptr)
, debug_mode_(false) , debug_enabled_(false)
, initialized_(false)
{ {
::CoInitialize(nullptr); ::CoInitialize(nullptr);
} }
Game::Game(Options const & options)
: Game()
{
Init(options);
}
Game::~Game() Game::~Game()
{ {
SafeRelease(transition_);
SafeRelease(curr_scene_);
SafeRelease(next_scene_);
::CoUninitialize(); ::CoUninitialize();
} }
void Game::Initialize(const Options& options) void Game::Init(const Options& options)
{ {
debug_mode_ = options.debug; if (initialized_)
return;
Window::Instance().Initialize(options.title, options.width, options.height, options.icon, debug_mode_); debug_enabled_ = options.debug;
devices::Graphics::Instance().Initialize(Window::Instance().GetHandle(), debug_mode_);
devices::Input::Instance().Initialize(debug_mode_); Window::Instance().Init(options.title, options.width, options.height, options.icon, debug_enabled_);
devices::Audio::Instance().Initialize(debug_mode_); devices::Graphics::Instance().Init(Window::Instance().GetHandle(), debug_enabled_);
devices::Input::Instance().Init(debug_enabled_);
devices::Audio::Instance().Init(debug_enabled_);
// 若开启了调试模式,打开控制台
HWND console = ::GetConsoleWindow(); HWND console = ::GetConsoleWindow();
// 关闭控制台 if (debug_enabled_)
if (debug_mode_)
{ {
if (console == nullptr) if (console == nullptr)
{ {
@ -97,6 +101,8 @@ namespace easy2d
GWLP_USERDATA, GWLP_USERDATA,
PtrToUlong(this) PtrToUlong(this)
); );
initialized_ = true;
} }
void Game::Run() void Game::Run()
@ -110,12 +116,13 @@ namespace easy2d
next_scene_ = nullptr; next_scene_ = nullptr;
} }
::ShowWindow(Window::Instance().GetHandle(), SW_SHOWNORMAL); const auto& window = Window::Instance();
::UpdateWindow(Window::Instance().GetHandle()); ::ShowWindow(window.GetHandle(), SW_SHOWNORMAL);
::UpdateWindow(window.GetHandle());
const int64_t min_interval = 5; const int64_t min_interval = 5;
auto last = time::Now(); auto last = time::Now();
MSG msg = { 0 }; MSG msg = {};
while (!quit_) while (!quit_)
{ {
@ -128,12 +135,11 @@ namespace easy2d
last = now; last = now;
devices::Input::Instance().Update( devices::Input::Instance().Update(
Window::Instance().GetHandle(), window.GetHandle(),
Window::Instance().GetContentScaleX(), window.GetContentScaleX(),
Window::Instance().GetContentScaleY() window.GetContentScaleY()
); );
OnUpdate(dt);
UpdateScene(dt); UpdateScene(dt);
DrawScene(); DrawScene();
@ -162,9 +168,9 @@ namespace easy2d
quit_ = true; quit_ = true;
} }
void Game::EnterScene(Scene * scene, Transition * transition) void Game::EnterScene(spScene const& scene, spTransition const& transition)
{ {
if (scene == nullptr) if (!scene)
{ {
E2D_WARNING("Next scene is null pointer!"); E2D_WARNING("Next scene is null pointer!");
return; return;
@ -172,45 +178,37 @@ namespace easy2d
if (curr_scene_ == scene) { return; } if (curr_scene_ == scene) { return; }
if (next_scene_)
{
next_scene_->Release();
}
next_scene_ = scene; next_scene_ = scene;
next_scene_->Retain();
if (transition) if (transition)
{ {
if (transition_) if (transition_)
{ {
transition_->Stop(); transition_->Stop();
transition_->Release();
} }
transition_ = transition; transition_ = transition;
transition_->Retain(); transition_->Init(curr_scene_, next_scene_);
transition_->Initialize(curr_scene_, next_scene_, this);
} }
} }
Scene * Game::GetCurrentScene() spScene const& Game::GetCurrentScene()
{ {
return curr_scene_; return curr_scene_;
} }
bool Game::IsTransitioning() const bool Game::IsTransitioning() const
{ {
return transition_ != nullptr; return transition_;
} }
void Game::UpdateScene(float dt) void Game::UpdateScene(float dt)
{ {
auto update = [&](Scene * scene) -> void auto update = [&](spScene const& scene) -> void
{ {
if (scene) if (scene)
{ {
scene->OnUpdate(dt); scene->OnUpdate(dt);
Node * root = scene->GetRoot(); spNode const& root = scene->GetRoot();
if (root) if (root)
{ {
root->UpdateChildren(dt); root->UpdateChildren(dt);
@ -227,7 +225,6 @@ namespace easy2d
if (transition_->IsDone()) if (transition_->IsDone())
{ {
transition_->Release();
transition_ = nullptr; transition_ = nullptr;
} }
else else
@ -241,7 +238,6 @@ namespace easy2d
if (curr_scene_) if (curr_scene_)
{ {
curr_scene_->OnExit(); curr_scene_->OnExit();
curr_scene_->Release();
} }
next_scene_->OnEnter(); next_scene_->OnEnter();
@ -265,7 +261,7 @@ namespace easy2d
curr_scene_->Draw(); curr_scene_->Draw();
} }
if (debug_mode_) if (debug_enabled_)
{ {
if (curr_scene_ && curr_scene_->GetRoot()) if (curr_scene_ && curr_scene_->GetRoot())
{ {

View File

@ -21,12 +21,11 @@
#pragma once #pragma once
#include "base.h" #include "base.h"
#include "window.h" #include "window.h"
#include "Scene.h"
#include "Transition.h"
namespace easy2d namespace easy2d
{ {
class Scene;
class Transition;
struct Options struct Options
{ {
String title; /* 标题 */ String title; /* 标题 */
@ -52,10 +51,11 @@ namespace easy2d
public: public:
Game(); Game();
virtual ~Game(); Game(
Options const& options
);
// 更新时 virtual ~Game();
virtual void OnUpdate(float dt) {}
// 退出时 // 退出时
virtual void OnExit() {} virtual void OnExit() {}
@ -65,8 +65,8 @@ namespace easy2d
virtual bool OnClose() { return true; } virtual bool OnClose() { return true; }
// 初始化 // 初始化
void Initialize( void Init(
const Options& options /* 属性 */ Options const& options
); );
// 运行 // 运行
@ -77,29 +77,27 @@ namespace easy2d
// 切换场景 // 切换场景
void EnterScene( void EnterScene(
Scene * scene, /* 场景 */ spScene const& scene, /* 场景 */
Transition * transition = nullptr /* 场景动画 */ spTransition const& transition = nullptr /* 场景动画 */
); );
// 获取当前场景 // 获取当前场景
Scene * GetCurrentScene(); spScene const& GetCurrentScene();
// 是否正在进行场景过渡
bool IsTransitioning() const; bool IsTransitioning() const;
// 渲染场景画面
void DrawScene(); void DrawScene();
// 更新场景
void UpdateScene( void UpdateScene(
float dt float dt
); );
private: private:
bool debug_mode_; bool initialized_;
bool quit_; bool debug_enabled_;
Scene* curr_scene_; bool quit_;
Scene* next_scene_; spScene curr_scene_;
Transition* transition_; spScene next_scene_;
spTransition transition_;
}; };
} }

View File

@ -192,10 +192,7 @@ namespace easy2d
if (bitmap_ == bitmap) if (bitmap_ == bitmap)
return; return;
if (bitmap_) SafeRelease(bitmap_);
{
bitmap_->Release();
}
if (bitmap) if (bitmap)
{ {

View File

@ -21,7 +21,6 @@
#pragma once #pragma once
#include "base.h" #include "base.h"
#include "Resource.h" #include "Resource.h"
#include "RefCounter.h"
namespace easy2d namespace easy2d
{ {

View File

@ -34,7 +34,7 @@ namespace easy2d
{ {
} }
void InputDevice::Initialize(bool debug) void InputDevice::Init(bool debug)
{ {
if (initialized) if (initialized)
return; return;

View File

@ -33,7 +33,7 @@ namespace easy2d
E2D_DISABLE_COPY(InputDevice); E2D_DISABLE_COPY(InputDevice);
public: public:
void Initialize(bool debug); void Init(bool debug);
// 检测键盘某按键是否正被按下 // 检测键盘某按键是否正被按下
bool IsDown( bool IsDown(

176
core/base/IntrusivePtr.hpp Normal file
View File

@ -0,0 +1,176 @@
// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining lhs 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.
#pragma once
#include <cassert>
namespace easy2d
{
template <typename T>
class IntrusivePtr
{
using ElemType = T;
ElemType* ptr_{ nullptr };
public:
IntrusivePtr() {}
IntrusivePtr(nullptr_t) {}
IntrusivePtr(ElemType* p) : ptr_(p)
{
IntrusivePtrAddRef(ptr_);
}
IntrusivePtr(const IntrusivePtr& other) : ptr_(other.ptr_)
{
IntrusivePtrAddRef(ptr_);
}
template <typename U>
IntrusivePtr(const IntrusivePtr<U>& other) : ptr_(other.Get())
{
IntrusivePtrAddRef(ptr_);
}
IntrusivePtr(IntrusivePtr&& other) : ptr_(::std::move(other.ptr_)) {}
~IntrusivePtr()
{
IntrusivePtrRelease(ptr_);
}
inline ElemType* Get() const { return ptr_; }
inline void Swap(IntrusivePtr& other)
{
::std::swap(ptr_, other.ptr_);
}
inline ElemType* operator ->() const
{
assert(ptr_ && ptr_->GetRefCount() > 0 &&
"Invalid pointer!");
return ptr_;
}
inline ElemType& operator *() const
{
assert(ptr_ && ptr_->GetRefCount() > 0 &&
"Invalid pointer!");
return *ptr_;
}
inline operator bool() const { return ptr_ != nullptr; }
inline bool operator !() const { return ptr_ == 0; }
inline IntrusivePtr& operator =(const IntrusivePtr& other)
{
IntrusivePtr(other).Swap(*this);
return *this;
}
inline IntrusivePtr& operator =(ElemType* p)
{
IntrusivePtr(p).Swap(*this);
return *this;
}
inline IntrusivePtr& operator =(nullptr_t)
{
IntrusivePtr{}.Swap(*this);
return *this;
}
};
template<class T, class U>
inline bool operator==(IntrusivePtr<T> const& lhs, IntrusivePtr<U> const& rhs)
{
return lhs.Get() == rhs.Get();
}
template<class T, class U>
inline bool operator!=(IntrusivePtr<T> const& lhs, IntrusivePtr<U> const& rhs)
{
return lhs.Get() != rhs.Get();
}
template<class T, class U>
inline bool operator<(IntrusivePtr<T> const& lhs, IntrusivePtr<U> const& rhs)
{
return lhs.Get() < rhs.Get();
}
template<class T>
inline bool operator==(IntrusivePtr<T> const& lhs, T* rhs)
{
return lhs.Get() == rhs;
}
template<class T>
inline bool operator!=(IntrusivePtr<T> const& lhs, T* rhs)
{
return lhs.Get() != rhs;
}
template<class T>
inline bool operator==(T* lhs, IntrusivePtr<T> const& rhs)
{
return lhs == rhs.Get();
}
template<class T>
inline bool operator!=(T* lhs, IntrusivePtr<T> const& rhs)
{
return lhs != rhs.Get();
}
template<class T>
inline bool operator==(IntrusivePtr<T> const& lhs, nullptr_t)
{
return !static_cast<bool>(lhs);
}
template<class T>
inline bool operator!=(IntrusivePtr<T> const& lhs, nullptr_t)
{
return static_cast<bool>(lhs);
}
template<class T>
inline bool operator==(nullptr_t, IntrusivePtr<T> const& rhs)
{
return !static_cast<bool>(rhs);
}
template<class T>
inline bool operator!=(nullptr_t, IntrusivePtr<T> const& rhs)
{
return static_cast<bool>(rhs);
}
template<class T>
inline IntrusivePtr<T> make_intrusive(T* ptr)
{
return IntrusivePtr<T>(ptr);
}
}

View File

@ -21,7 +21,6 @@
#pragma once #pragma once
#include "base.h" #include "base.h"
#include "audio.h" #include "audio.h"
#include "RefCounter.h"
#include "Resource.h" #include "Resource.h"
#include <xaudio2.h> #include <xaudio2.h>

View File

@ -21,7 +21,7 @@
#include "Node.h" #include "Node.h"
#include "Scene.h" #include "Scene.h"
#include "Task.h" #include "Task.h"
#include "Action.h" #include "Action.hpp"
#include "time.h" #include "time.h"
#include "render.h" #include "render.h"
#include <iterator> #include <iterator>
@ -31,7 +31,6 @@ namespace easy2d
Node::Node() Node::Node()
: visible_(true) : visible_(true)
, parent_(nullptr) , parent_(nullptr)
, parent_scene_(nullptr)
, hash_name_(0) , hash_name_(0)
, clip_enabled_(false) , clip_enabled_(false)
, dirty_sort_(false) , dirty_sort_(false)
@ -53,21 +52,6 @@ namespace easy2d
Node::~Node() Node::~Node()
{ {
SafeRelease(border_); SafeRelease(border_);
for (auto action : actions_)
{
SafeRelease(action);
}
for (auto task : tasks_)
{
SafeRelease(task);
}
for (auto child : children_)
{
SafeRelease(child);
}
} }
void Node::Visit() void Node::Visit()
@ -93,7 +77,7 @@ namespace easy2d
std::sort( std::sort(
std::begin(children_), std::begin(children_),
std::end(children_), std::end(children_),
[](Node * n1, Node * n2) { return n1->GetOrder() < n2->GetOrder(); } [](spNode const& n1, spNode const& n2) { return n1->GetOrder() < n2->GetOrder(); }
); );
dirty_sort_ = false; dirty_sort_ = false;
@ -202,11 +186,6 @@ namespace easy2d
initial_matrix_ = initial_matrix_ * parent_->initial_matrix_; initial_matrix_ = initial_matrix_ * parent_->initial_matrix_;
final_matrix_ = final_matrix_ * parent_->initial_matrix_; final_matrix_ = final_matrix_ * parent_->initial_matrix_;
} }
else if (parent_scene_)
{
initial_matrix_ = initial_matrix_ * parent_scene_->GetTransform();
final_matrix_ = final_matrix_ * parent_scene_->GetTransform();
}
// 重新构造轮廓 // 重新构造轮廓
SafeRelease(border_); SafeRelease(border_);
@ -269,25 +248,24 @@ namespace easy2d
if (actions_.empty()) if (actions_.empty())
return; return;
std::vector<Action*> currActions; std::vector<spAction> currActions;
currActions.reserve(actions_.size()); currActions.reserve(actions_.size());
std::copy_if( std::copy_if(
actions_.begin(), actions_.begin(),
actions_.end(), actions_.end(),
std::back_inserter(currActions), std::back_inserter(currActions),
[](Action* action) { return action->IsRunning() && !action->IsDone(); } [](spAction action) { return action->IsRunning() && !action->IsDone(); }
); );
// 遍历所有正在运行的动作 // 遍历所有正在运行的动作
for (const auto& action : currActions) for (const auto& action : currActions)
action->Update(); action->Update(this);
// 清除完成的动作 // 清除完成的动作
for (auto iter = actions_.begin(); iter != actions_.end();) for (auto iter = actions_.begin(); iter != actions_.end();)
{ {
if ((*iter)->IsDone()) if ((*iter)->IsDone())
{ {
(*iter)->Release();
iter = actions_.erase(iter); iter = actions_.erase(iter);
} }
else else
@ -574,18 +552,18 @@ namespace easy2d
border_color_ = color; border_color_ = color;
} }
void Node::AddChild(Node * child, int order) void Node::AddChild(spNode const& child, int order)
{ {
E2D_WARNING_IF(child == nullptr, "Node::AddChild NULL pointer exception."); E2D_WARNING_IF(!child, "Node::AddChild NULL pointer exception.");
if (child) if (child)
{ {
if (child->parent_ != nullptr) if (child->parent_)
{ {
throw std::runtime_error("节点已有父节点, 不能再添加到其他节点"); throw std::runtime_error("节点已有父节点, 不能再添加到其他节点");
} }
for (Node * parent = this; parent != nullptr; parent = parent->GetParent()) for (Node * parent = this; parent; parent = parent->GetParent().Get())
{ {
if (child == parent) if (child == parent)
{ {
@ -593,14 +571,9 @@ namespace easy2d
} }
} }
child->Retain();
children_.push_back(child); children_.push_back(child);
child->SetOrder(order); child->SetOrder(order);
child->parent_ = this; child->parent_ = this;
if (this->parent_scene_)
{
child->SetParentScene(this->parent_scene_);
}
// 更新子节点透明度 // 更新子节点透明度
child->UpdateOpacity(); child->UpdateOpacity();
@ -619,17 +592,12 @@ namespace easy2d
} }
} }
Node * Node::GetParent() const spNode Node::GetParent() const
{ {
return parent_; return parent_;
} }
Scene * Node::GetParentScene() const Nodes Node::GetChildren(const String& name) const
{
return parent_scene_;
}
Node::Nodes Node::GetChildren(const String& name) const
{ {
Nodes children; Nodes children;
size_t hash_code = std::hash<String>{}(name); size_t hash_code = std::hash<String>{}(name);
@ -645,7 +613,7 @@ namespace easy2d
return children; return children;
} }
Node * Node::GetChild(const String& name) const spNode Node::GetChild(const String& name) const
{ {
size_t hash_code = std::hash<String>{}(name); size_t hash_code = std::hash<String>{}(name);
@ -660,7 +628,7 @@ namespace easy2d
return nullptr; return nullptr;
} }
const std::vector<Node*>& Node::GetAllChildren() const const std::vector<spNode>& Node::GetAllChildren() const
{ {
return children_; return children_;
} }
@ -678,9 +646,9 @@ namespace easy2d
} }
} }
bool Node::RemoveChild(Node * child) bool Node::RemoveChild(spNode const& child)
{ {
E2D_WARNING_IF(child == nullptr, "Node::RemoveChildren NULL pointer exception."); E2D_WARNING_IF(!child, "Node::RemoveChildren NULL pointer exception.");
if (children_.empty()) if (children_.empty())
{ {
@ -694,13 +662,6 @@ namespace easy2d
{ {
children_.erase(iter); children_.erase(iter);
child->parent_ = nullptr; child->parent_ = nullptr;
if (child->parent_scene_)
{
child->SetParentScene(nullptr);
}
child->Release();
return true; return true;
} }
} }
@ -720,11 +681,6 @@ namespace easy2d
if ((*iter)->hash_name_ == hash_code && (*iter)->name_ == child_name) if ((*iter)->hash_name_ == hash_code && (*iter)->name_ == child_name)
{ {
(*iter)->parent_ = nullptr; (*iter)->parent_ = nullptr;
if ((*iter)->parent_scene_)
{
(*iter)->SetParentScene(nullptr);
}
(*iter)->Release();
iter = children_.erase(iter); iter = children_.erase(iter);
} }
else else
@ -736,34 +692,20 @@ namespace easy2d
void Node::RemoveAllChildren() void Node::RemoveAllChildren()
{ {
// 所有节点的引用计数减一
for (const auto& child : children_)
{
child->Release();
}
// 清空储存节点的容器
children_.clear(); children_.clear();
} }
void Node::RunAction(Action * action) void Node::RunAction(spAction const& action)
{ {
E2D_WARNING_IF(action == nullptr, "Action NULL pointer exception!"); E2D_WARNING_IF(!action, "Action NULL pointer exception!");
if (action) if (action)
{ {
if (action->GetTarget() == nullptr) auto iter = std::find(actions_.begin(), actions_.end(), action);
if (iter == actions_.end())
{ {
auto iter = std::find(actions_.begin(), actions_.end(), action); action->Start();
if (iter == actions_.end()) actions_.push_back(action);
{
action->Retain();
action->StartWithTarget(this);
actions_.push_back(action);
}
}
else
{
throw std::runtime_error("该 Action 已有执行目标");
} }
} }
} }
@ -828,7 +770,7 @@ namespace easy2d
return ret != 0; return ret != 0;
} }
bool Node::Intersects(Node * node) bool Node::Intersects(spNode const& node)
{ {
if (transform_.size.width == 0.f || transform_.size.height == 0.f || node->transform_.size.width == 0.f || node->transform_.size.height == 0.f) if (transform_.size.width == 0.f || transform_.size.height == 0.f || node->transform_.size.width == 0.f || node->transform_.size.height == 0.f)
return false; return false;
@ -883,19 +825,18 @@ namespace easy2d
} }
} }
const Node::Actions & Node::GetAllActions() const const Actions& Node::GetAllActions() const
{ {
return actions_; return actions_;
} }
void Node::AddTask(Task * task) void Node::AddTask(spTask const& task)
{ {
if (task) if (task)
{ {
auto iter = std::find(tasks_.begin(), tasks_.end(), task); auto iter = std::find(tasks_.begin(), tasks_.end(), task);
if (iter == tasks_.end()) if (iter == tasks_.end())
{ {
task->Retain();
task->last_time_ = time::Now(); task->last_time_ = time::Now();
tasks_.push_back(task); tasks_.push_back(task);
} }
@ -959,7 +900,7 @@ namespace easy2d
} }
} }
const Node::Tasks & Node::GetAllTasks() const const Tasks & Node::GetAllTasks() const
{ {
return tasks_; return tasks_;
} }
@ -969,13 +910,13 @@ namespace easy2d
if (tasks_.empty()) if (tasks_.empty())
return; return;
std::vector<Task*> currTasks; std::vector<spTask> currTasks;
currTasks.reserve(tasks_.size()); currTasks.reserve(tasks_.size());
std::copy_if( std::copy_if(
tasks_.begin(), tasks_.begin(),
tasks_.end(), tasks_.end(),
std::back_inserter(currTasks), std::back_inserter(currTasks),
[](Task* task) { return task->IsReady() && !task->stopped_; } [](spTask const& task) { return task->IsReady() && !task->stopped_; }
); );
// 遍历就绪的任务 // 遍历就绪的任务
@ -987,7 +928,6 @@ namespace easy2d
{ {
if ((*iter)->stopped_) if ((*iter)->stopped_)
{ {
(*iter)->Release();
iter = tasks_.erase(iter); iter = tasks_.erase(iter);
} }
else else
@ -1030,13 +970,4 @@ namespace easy2d
hash_name_ = std::hash<String>{}(name); hash_name_ = std::hash<String>{}(name);
} }
} }
void Node::SetParentScene(Scene * scene)
{
parent_scene_ = scene;
for (const auto& child : children_)
{
child->SetParentScene(scene);
}
}
} }

View File

@ -20,7 +20,6 @@
#pragma once #pragma once
#include "base.h" #include "base.h"
#include "RefCounter.h"
#include "KeyEvent.h" #include "KeyEvent.h"
#include "MouseEvent.h" #include "MouseEvent.h"
#include "../math/Transform.h" #include "../math/Transform.h"
@ -43,10 +42,6 @@ namespace easy2d
E2D_DISABLE_COPY(Node); E2D_DISABLE_COPY(Node);
public: public:
typedef std::vector<Node*> Nodes;
typedef std::vector<Action*> Actions;
typedef std::vector<Task*> Tasks;
Node(); Node();
virtual ~Node(); virtual ~Node();
@ -121,10 +116,7 @@ namespace easy2d
float GetDisplayOpacity() const; float GetDisplayOpacity() const;
// 获取父节点 // 获取父节点
Node * GetParent() const; spNode GetParent() const;
// 获取节点所在场景
Scene * GetParentScene() const;
// 设置节点是否显示 // 设置节点是否显示
void SetVisible( void SetVisible(
@ -292,12 +284,12 @@ namespace easy2d
// 判断两物体是否相交 // 判断两物体是否相交
bool Intersects( bool Intersects(
Node * node spNode const& node
); );
// 添加子节点 // 添加子节点
void AddChild( void AddChild(
Node * child, spNode const& child,
int order = 0 /* 渲染顺序 */ int order = 0 /* 渲染顺序 */
); );
@ -313,7 +305,7 @@ namespace easy2d
) const; ) const;
// 获取名称相同的子节点 // 获取名称相同的子节点
Node* GetChild( spNode GetChild(
const String& name const String& name
) const; ) const;
@ -325,7 +317,7 @@ namespace easy2d
// 移除子节点 // 移除子节点
bool RemoveChild( bool RemoveChild(
Node * child spNode const& child
); );
// 移除所有名称相同的子节点 // 移除所有名称相同的子节点
@ -341,7 +333,7 @@ namespace easy2d
// 执行动作 // 执行动作
void RunAction( void RunAction(
Action * action spAction const& action
); );
// 继续动作 // 继续动作
@ -373,7 +365,7 @@ namespace easy2d
// 添加任务 // 添加任务
void AddTask( void AddTask(
Task * task spTask const& task
); );
// 启动任务 // 启动任务
@ -423,11 +415,6 @@ namespace easy2d
// 渲染节点边缘 // 渲染节点边缘
void DrawBorder(); void DrawBorder();
// 设置节点所在场景
void SetParentScene(
Scene * scene
);
// 更新子节点 // 更新子节点
void UpdateChildren(float dt); void UpdateChildren(float dt);
@ -456,7 +443,6 @@ namespace easy2d
bool clip_enabled_; bool clip_enabled_;
bool dirty_sort_; bool dirty_sort_;
bool dirty_transform_; bool dirty_transform_;
Scene* parent_scene_;
Node* parent_; Node* parent_;
Color border_color_; Color border_color_;
Actions actions_; Actions actions_;

View File

@ -23,8 +23,8 @@
namespace easy2d namespace easy2d
{ {
RefCounter::RefCounter() RefCounter::RefCounter()
: ref_count_(0)
{ {
ref_count_ = 0;
} }
RefCounter::~RefCounter() RefCounter::~RefCounter()
@ -33,20 +33,12 @@ namespace easy2d
long RefCounter::Retain() long RefCounter::Retain()
{ {
return ::InterlockedIncrement(&ref_count_);
} }
long RefCounter::Release() long RefCounter::Release()
{ {
long new_count = ::InterlockedDecrement(&ref_count_);
if (new_count <= 0)
{
delete this;
return 0;
}
return new_count;
} }
long RefCounter::GetRefCount() const long RefCounter::GetRefCount() const

View File

@ -23,24 +23,39 @@
namespace easy2d namespace easy2d
{ {
// 引用计数
class RefCounter class RefCounter
{ {
public: E2D_DISABLE_COPY(RefCounter);
RefCounter();
virtual ~RefCounter(); public:
RefCounter() : ref_count_(0) {}
virtual ~RefCounter() {}
// 增加引用计数 // 增加引用计数
long Retain(); inline void Retain() { ::InterlockedIncrement(&ref_count_); }
// 减少引用计数 // 减少引用计数
long Release(); inline void Release()
{
if (::InterlockedDecrement(&ref_count_) <= 0)
delete this;
}
// 获取引用计数 // 获取引用计数
long GetRefCount() const; inline long GetRefCount() const { return ref_count_; }
private: private:
long ref_count_; long ref_count_;
}; };
inline void IntrusivePtrAddRef(RefCounter* ptr)
{
if (ptr) ptr->Retain();
}
inline void IntrusivePtrRelease(RefCounter* ptr)
{
if (ptr) ptr->Release();
}
} }

View File

@ -29,7 +29,7 @@ namespace easy2d
{ {
} }
Scene::Scene(Node * root) Scene::Scene(spNode const& root)
: root_(nullptr) : root_(nullptr)
, transform_() , transform_()
{ {
@ -38,34 +38,17 @@ namespace easy2d
Scene::~Scene() Scene::~Scene()
{ {
if (root_)
{
root_->SetParentScene(nullptr);
root_->Release();
}
} }
void Scene::SetRoot(Node * root) void Scene::SetRoot(spNode const& root)
{ {
if (root_ == root) if (root_ == root)
return; return;
if (root_)
{
root_->SetParentScene(nullptr);
root_->Release();
}
if (root)
{
root->Retain();
root->SetParentScene(this);
}
root_ = root; root_ = root;
} }
Node * Scene::GetRoot() const spNode const& Scene::GetRoot() const
{ {
return root_; return root_;
} }

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "RefCounter.h" #include "base.h"
#include "KeyEvent.h" #include "KeyEvent.h"
#include "MouseEvent.h" #include "MouseEvent.h"
#include "../math/Matrix.hpp" #include "../math/Matrix.hpp"
@ -38,7 +38,7 @@ namespace easy2d
Scene(); Scene();
explicit Scene( explicit Scene(
Node * root spNode const& root
); );
virtual ~Scene(); virtual ~Scene();
@ -54,11 +54,11 @@ namespace easy2d
// 设置根节点 // 设置根节点
void SetRoot( void SetRoot(
Node * root spNode const& root
); );
// 获取根节点 // 获取根节点
Node* GetRoot() const; spNode const& GetRoot() const;
// 渲染场景 // 渲染场景
void Draw(); void Draw();
@ -82,7 +82,7 @@ namespace easy2d
const math::Matrix& GetTransform() const; const math::Matrix& GetTransform() const;
private: private:
Node* root_; spNode root_;
math::Matrix transform_; math::Matrix transform_;
}; };
} }

View File

@ -29,7 +29,7 @@ namespace easy2d
{ {
} }
Sprite::Sprite(Image * image) Sprite::Sprite(spImage const& image)
: image_(nullptr) : image_(nullptr)
{ {
Load(image); Load(image);
@ -63,20 +63,13 @@ namespace easy2d
Sprite::~Sprite() Sprite::~Sprite()
{ {
SafeRelease(image_);
} }
bool Sprite::Load(Image * image) bool Sprite::Load(spImage const& image)
{ {
if (image) if (image)
{ {
if (image_)
{
image_->Release();
}
image_ = image; image_ = image;
image_->Retain();
Node::SetSize(image_->GetWidth(), image_->GetHeight()); Node::SetSize(image_->GetWidth(), image_->GetHeight());
return true; return true;
@ -88,14 +81,16 @@ namespace easy2d
{ {
if (!image_) if (!image_)
{ {
image_ = new Image(); image_ = new (std::nothrow) Image();
image_->Retain();
} }
if (image_->Load(res)) if (image_)
{ {
Node::SetSize(image_->GetWidth(), image_->GetHeight()); if (image_->Load(res))
return true; {
Node::SetSize(image_->GetWidth(), image_->GetHeight());
return true;
}
} }
return false; return false;
} }
@ -104,14 +99,16 @@ namespace easy2d
{ {
if (!image_) if (!image_)
{ {
image_ = new Image(); image_ = new (std::nothrow) Image();
image_->Retain();
} }
if (image_->Load(file_name)) if (image_)
{ {
Node::SetSize(image_->GetWidth(), image_->GetHeight()); if (image_->Load(file_name))
return true; {
Node::SetSize(image_->GetWidth(), image_->GetHeight());
return true;
}
} }
return false; return false;
} }
@ -125,7 +122,7 @@ namespace easy2d
); );
} }
Image * Sprite::GetImage() const spImage const& Sprite::GetImage() const
{ {
return image_; return image_;
} }

View File

@ -34,7 +34,7 @@ namespace easy2d
Sprite(); Sprite();
explicit Sprite( explicit Sprite(
Image * image spImage const& image
); );
explicit Sprite( explicit Sprite(
@ -69,7 +69,7 @@ namespace easy2d
// 加载图片 // 加载图片
bool Load( bool Load(
Image * image spImage const& image
); );
// 将图片裁剪为矩形 // 将图片裁剪为矩形
@ -78,12 +78,12 @@ namespace easy2d
); );
// 获取 Image 对象 // 获取 Image 对象
Image * GetImage() const; spImage const& GetImage() const;
// 渲染精灵 // 渲染精灵
virtual void OnDraw() const override; virtual void OnDraw() const override;
private: private:
Image* image_; spImage image_;
}; };
} }

View File

@ -23,22 +23,16 @@
namespace easy2d namespace easy2d
{ {
Task::Task(const Callback & func, const String & name) Task::Task(const Callback & func, const String & name)
: running_(true) : Task(func, Duration{}, -1, name)
, stopped_(false)
, run_times_(0)
, total_times_(-1)
, delay_()
, callback_(func)
, name_(name)
{ {
} }
Task::Task(const Callback & func, float delay, int times, const String & name) Task::Task(Callback const& func, Duration const& delay, int times, const String & name)
: running_(true) : running_(true)
, stopped_(false) , stopped_(false)
, run_times_(0) , run_times_(0)
, delay_(time::Second * std::max(delay, 0.f))
, total_times_(times) , total_times_(times)
, delay_(delay)
, callback_(func) , callback_(func)
, name_(name) , name_(name)
{ {

View File

@ -21,13 +21,10 @@
#pragma once #pragma once
#include "base.h" #include "base.h"
#include "time.h" #include "time.h"
#include "RefCounter.h"
#include <functional> #include <functional>
namespace easy2d namespace easy2d
{ {
class Node;
// 定时任务 // 定时任务
class Task class Task
: public RefCounter : public RefCounter
@ -38,14 +35,14 @@ namespace easy2d
public: public:
explicit Task( explicit Task(
const Callback& func, /* 执行函数 */ const Callback& func, /* 执行函数 */
const String& name = L"" /* 任务名称 */ const String& name = L"" /* 任务名称 */
); );
explicit Task( explicit Task(
const Callback& func, /* 执行函数 */ Callback const& func, /* 执行函数 */
float delay, /* 时间间隔(秒) */ Duration const& delay, /* 时间间隔(秒) */
int times = -1, /* 执行次数(设 -1 为永久执行) */ int times = -1, /* 执行次数(设 -1 为永久执行) */
const String& name = L"" /* 任务名称 */ const String& name = L"" /* 任务名称 */
); );
@ -61,24 +58,21 @@ namespace easy2d
// 获取任务名称 // 获取任务名称
const String& GetName() const; const String& GetName() const;
// 任务是否就绪 protected:
bool IsReady() const; bool IsReady() const;
// 执行任务
void Update(); void Update();
// 重置计时
void ResetTime(); void ResetTime();
private: private:
bool running_; bool running_;
bool stopped_; bool stopped_;
int run_times_; int run_times_;
int total_times_; int total_times_;
String name_; String name_;
time::Duration delay_; Duration delay_;
time::TimePoint last_time_; TimePoint last_time_;
Callback callback_; Callback callback_;
Node * target_;
}; };
} }

View File

@ -50,8 +50,6 @@ namespace easy2d
{ {
SafeRelease(out_layer_); SafeRelease(out_layer_);
SafeRelease(in_layer_); SafeRelease(in_layer_);
SafeRelease(out_scene_);
SafeRelease(in_scene_);
} }
bool Transition::IsDone() bool Transition::IsDone()
@ -59,18 +57,12 @@ namespace easy2d
return done_; return done_;
} }
void Transition::Initialize(Scene * prev, Scene * next, Game * game) void Transition::Init(spScene const& prev, spScene const& next)
{ {
started_ = time::Now(); started_ = time::Now();
out_scene_ = prev; out_scene_ = prev;
in_scene_ = next; in_scene_ = next;
if (out_scene_)
out_scene_->Retain();
if (in_scene_)
in_scene_->Retain();
if (in_scene_) if (in_scene_)
{ {
ThrowIfFailed( ThrowIfFailed(
@ -153,9 +145,9 @@ namespace easy2d
{ {
} }
void BoxTransition::Initialize(Scene * prev, Scene * next, Game * game) void BoxTransition::Init(spScene const& prev, spScene const& next)
{ {
Transition::Initialize(prev, next, game); Transition::Init(prev, next);
in_layer_prop_.opacity = 0; in_layer_prop_.opacity = 0;
} }
@ -195,9 +187,9 @@ namespace easy2d
{ {
} }
void EmergeTransition::Initialize(Scene * prev, Scene * next, Game * game) void EmergeTransition::Init(spScene const& prev, spScene const& next)
{ {
Transition::Initialize(prev, next, game); Transition::Init(prev, next);
out_layer_prop_.opacity = 1; out_layer_prop_.opacity = 1;
in_layer_prop_.opacity = 0; in_layer_prop_.opacity = 0;
@ -220,9 +212,9 @@ namespace easy2d
{ {
} }
void FadeTransition::Initialize(Scene * prev, Scene * next, Game * game) void FadeTransition::Init(spScene const& prev, spScene const& next)
{ {
Transition::Initialize(prev, next, game); Transition::Init(prev, next);
out_layer_prop_.opacity = 1; out_layer_prop_.opacity = 1;
in_layer_prop_.opacity = 0; in_layer_prop_.opacity = 0;
@ -254,9 +246,9 @@ namespace easy2d
{ {
} }
void MoveTransition::Initialize(Scene * prev, Scene * next, Game * game) void MoveTransition::Init(spScene const& prev, spScene const& next)
{ {
Transition::Initialize(prev, next, game); Transition::Init(prev, next);
switch (direction_) switch (direction_)
{ {
@ -344,9 +336,9 @@ namespace easy2d
{ {
} }
void RotationTransition::Initialize(Scene * prev, Scene * next, Game * game) void RotationTransition::Init(spScene const& prev, spScene const& next)
{ {
Transition::Initialize(prev, next, game); Transition::Init(prev, next);
if (out_scene_) if (out_scene_)
{ {

View File

@ -21,11 +21,9 @@
#pragma once #pragma once
#include "base.h" #include "base.h"
#include "time.h" #include "time.h"
#include "RefCounter.h"
namespace easy2d namespace easy2d
{ {
class Game;
class Scene; class Scene;
// 场景过渡 // 场景过渡
@ -46,10 +44,9 @@ namespace easy2d
protected: protected:
// 初始化场景过渡动画 // 初始化场景过渡动画
virtual void Initialize( virtual void Init(
Scene * prev, spScene const& prev,
Scene * next, spScene const& next
Game * game
); );
// 更新场景过渡动画 // 更新场景过渡动画
@ -68,10 +65,10 @@ namespace easy2d
bool done_; bool done_;
float duration_; float duration_;
float process_; float process_;
time::TimePoint started_; TimePoint started_;
Size window_size_; Size window_size_;
Scene* out_scene_; spScene out_scene_;
Scene* in_scene_; spScene in_scene_;
ID2D1Layer* out_layer_; ID2D1Layer* out_layer_;
ID2D1Layer* in_layer_; ID2D1Layer* in_layer_;
LayerProperties out_layer_prop_; LayerProperties out_layer_prop_;
@ -92,10 +89,9 @@ namespace easy2d
// 更新动画 // 更新动画
virtual void Update() override; virtual void Update() override;
virtual void Initialize( virtual void Init(
Scene * prev, spScene const& prev,
Scene * next, spScene const& next
Game * game
) override; ) override;
}; };
@ -112,10 +108,9 @@ namespace easy2d
protected: protected:
virtual void Update() override; virtual void Update() override;
virtual void Initialize( virtual void Init(
Scene * prev, spScene const& prev,
Scene * next, spScene const& next
Game * game
) override; ) override;
}; };
@ -132,10 +127,9 @@ namespace easy2d
protected: protected:
virtual void Update() override; virtual void Update() override;
virtual void Initialize( virtual void Init(
Scene * prev, spScene const& prev,
Scene * next, spScene const& next
Game * game
) override; ) override;
}; };
@ -153,10 +147,9 @@ namespace easy2d
protected: protected:
virtual void Update() override; virtual void Update() override;
virtual void Initialize( virtual void Init(
Scene * prev, spScene const& prev,
Scene * next, spScene const& next
Game * game
) override; ) override;
virtual void Reset() override; virtual void Reset() override;
@ -181,10 +174,9 @@ namespace easy2d
protected: protected:
virtual void Update() override; virtual void Update() override;
virtual void Initialize( virtual void Init(
Scene * prev, spScene const& prev,
Scene * next, spScene const& next
Game * game
) override; ) override;
virtual void Reset() override; virtual void Reset() override;

View File

@ -165,7 +165,7 @@ namespace easy2d
, mastering_voice_(nullptr) , mastering_voice_(nullptr)
, initialized(false) , initialized(false)
{ {
modules::Initialize(); modules::Init();
} }
AudioDevice::~AudioDevice() AudioDevice::~AudioDevice()
@ -185,7 +185,7 @@ namespace easy2d
modules::Destroy(); modules::Destroy();
} }
void AudioDevice::Initialize(bool debug) void AudioDevice::Init(bool debug)
{ {
if (initialized) if (initialized)
return; return;

View File

@ -81,7 +81,7 @@ namespace easy2d
E2D_DISABLE_COPY(AudioDevice); E2D_DISABLE_COPY(AudioDevice);
public: public:
void Initialize(bool debug); void Init(bool debug);
// 开启设备 // 开启设备
void Open(); void Open();
@ -106,10 +106,10 @@ namespace easy2d
~AudioDevice(); ~AudioDevice();
protected: protected:
bool initialized; bool initialized;
IXAudio2 * x_audio2_; IXAudio2* x_audio2_;
IXAudio2MasteringVoice* mastering_voice_; IXAudio2MasteringVoice* mastering_voice_;
std::list<Voice*> voice_cache_; std::list<Voice*> voice_cache_;
}; };
E2D_DECLARE_SINGLETON_TYPE(AudioDevice, Audio); E2D_DECLARE_SINGLETON_TYPE(AudioDevice, Audio);

View File

@ -20,10 +20,74 @@
#pragma once #pragma once
#include "BaseTypes.h" #include "BaseTypes.h"
#include "IntrusivePtr.hpp"
#include "RefCounter.hpp"
#include <stdexcept> #include <stdexcept>
#ifndef E2D_DECLARE_SMART_PTR
#define E2D_DECLARE_SMART_PTR(class_name)\
class class_name;\
using sp##class_name = ::easy2d::IntrusivePtr< class_name >
#define E2D_DECLARE_NS_SMART_PTR(ns_name, class_name)\
namespace ns_name\
{\
class class_name; \
using sp##class_name = ::easy2d::IntrusivePtr< class_name >;\
}
#endif
namespace easy2d namespace easy2d
{ {
E2D_DECLARE_SMART_PTR(Image);
E2D_DECLARE_SMART_PTR(Music);
E2D_DECLARE_SMART_PTR(Task);
E2D_DECLARE_SMART_PTR(Node);
E2D_DECLARE_SMART_PTR(Scene);
E2D_DECLARE_SMART_PTR(Sprite);
E2D_DECLARE_SMART_PTR(Text);
E2D_DECLARE_SMART_PTR(Canvas);
E2D_DECLARE_SMART_PTR(Action);
E2D_DECLARE_SMART_PTR(MoveBy);
E2D_DECLARE_SMART_PTR(MoveTo);
E2D_DECLARE_SMART_PTR(JumpBy);
E2D_DECLARE_SMART_PTR(JumpTo);
E2D_DECLARE_SMART_PTR(ScaleBy);
E2D_DECLARE_SMART_PTR(ScaleTo);
E2D_DECLARE_SMART_PTR(OpacityBy);
E2D_DECLARE_SMART_PTR(OpacityTo);
E2D_DECLARE_SMART_PTR(FadeIn);
E2D_DECLARE_SMART_PTR(FadeOut);
E2D_DECLARE_SMART_PTR(RotateBy);
E2D_DECLARE_SMART_PTR(RotateTo);
E2D_DECLARE_SMART_PTR(Delay);
E2D_DECLARE_SMART_PTR(Animation);
E2D_DECLARE_SMART_PTR(Animate);
E2D_DECLARE_SMART_PTR(CallFunc);
E2D_DECLARE_SMART_PTR(Loop);
E2D_DECLARE_SMART_PTR(Sequence);
E2D_DECLARE_SMART_PTR(Spawn);
E2D_DECLARE_SMART_PTR(Transition);
E2D_DECLARE_SMART_PTR(FadeTransition);
E2D_DECLARE_SMART_PTR(EmergeTransition);
E2D_DECLARE_SMART_PTR(BoxTransition);
E2D_DECLARE_SMART_PTR(MoveTransition);
E2D_DECLARE_SMART_PTR(RotationTransition);
E2D_DECLARE_NS_SMART_PTR(ui, Button);
E2D_DECLARE_NS_SMART_PTR(ui, Menu);
using Images = ::std::vector< spImage >;
using Nodes = ::std::vector< spNode >;
using Actions = ::std::vector< spAction >;
using Tasks = ::std::vector< spTask >;
template<class Interface> template<class Interface>
inline void SafeRelease(Interface*& p) inline void SafeRelease(Interface*& p)
{ {

View File

@ -38,7 +38,7 @@ namespace easy2d
Module_XAudio2 XAudio2; Module_XAudio2 XAudio2;
Module_MediaFoundation MediaFoundation; Module_MediaFoundation MediaFoundation;
void Initialize() void Init()
{ {
initialize_count++; initialize_count++;
if (initialize_count > 1) if (initialize_count > 1)

View File

@ -31,7 +31,7 @@ namespace easy2d
{ {
// modules can be initialized multiple times, // modules can be initialized multiple times,
// but it needs to be destroyed every time // but it needs to be destroyed every time
void Initialize(); void Init();
void Destroy(); void Destroy();

View File

@ -22,6 +22,7 @@
#include "time.h" #include "time.h"
#include "base.h" #include "base.h"
#include "modules.h" #include "modules.h"
#include "Image.h"
#pragma comment(lib, "d2d1.lib") #pragma comment(lib, "d2d1.lib")
#pragma comment(lib, "dwrite.lib") #pragma comment(lib, "dwrite.lib")
@ -38,7 +39,7 @@ namespace easy2d
{ {
ZeroMemory(&d2d, sizeof(D2DResources)); ZeroMemory(&d2d, sizeof(D2DResources));
modules::Initialize(); modules::Init();
} }
GraphicsDevice::~GraphicsDevice() GraphicsDevice::~GraphicsDevice()
@ -63,7 +64,7 @@ namespace easy2d
modules::Destroy(); modules::Destroy();
} }
void GraphicsDevice::Initialize(HWND hwnd, bool debug) void GraphicsDevice::Init(HWND hwnd, bool debug)
{ {
if (initialized) if (initialized)
return; return;
@ -302,7 +303,7 @@ namespace easy2d
} }
HRESULT GraphicsDevice::DrawImage( HRESULT GraphicsDevice::DrawImage(
Image * image, spImage const& image,
float opacity, float opacity,
const Rect & dest_rect, const Rect & dest_rect,
const Rect & source_rect const Rect & source_rect

View File

@ -23,12 +23,13 @@
#include "Singleton.hpp" #include "Singleton.hpp"
#include "Font.h" #include "Font.h"
#include "Resource.h" #include "Resource.h"
#include "Image.h"
#include "TextRenderer.h" #include "TextRenderer.h"
#include "../math/Matrix.hpp" #include "../math/Matrix.hpp"
namespace easy2d namespace easy2d
{ {
class Image;
namespace devices namespace devices
{ {
struct D2DResources struct D2DResources
@ -52,7 +53,7 @@ namespace easy2d
E2D_DISABLE_COPY(GraphicsDevice); E2D_DISABLE_COPY(GraphicsDevice);
public: public:
void Initialize(HWND hwnd, bool debug); void Init(HWND hwnd, bool debug);
// ¿ªÊ¼äÖȾ // ¿ªÊ¼äÖȾ
void BeginDraw(HWND hwnd); void BeginDraw(HWND hwnd);
@ -121,7 +122,7 @@ namespace easy2d
); );
HRESULT DrawImage( HRESULT DrawImage(
Image* image, spImage const& image,
float opacity, float opacity,
const Rect& dest_rect, const Rect& dest_rect,
const Rect& source_rect const Rect& source_rect

View File

@ -187,6 +187,11 @@ namespace easy2d
} }
} }
namespace easy2d
{
using namespace time;
}
#if VS_VER >= VS_2015 #if VS_VER >= VS_2015
namespace easy2d namespace easy2d

View File

@ -56,7 +56,7 @@ namespace easy2d
::DestroyWindow(handle); ::DestroyWindow(handle);
} }
void WindowImpl::Initialize(String title, int width, int height, LPCWSTR icon, bool debug) void WindowImpl::Init(String title, int width, int height, LPCWSTR icon, bool debug)
{ {
if (initialized) if (initialized)
return; return;

View File

@ -33,7 +33,7 @@ namespace easy2d
E2D_DISABLE_COPY(WindowImpl); E2D_DISABLE_COPY(WindowImpl);
public: public:
void Initialize( void Init(
String title, String title,
int width, int width,
int height, int height,

View File

@ -46,21 +46,22 @@
#include "base/Color.h" #include "base/Color.h"
#include "base/Resource.h" #include "base/Resource.h"
#include "base/RefCounter.h" #include "base/RefCounter.hpp"
#include "base/IntrusivePtr.hpp"
#include "base/Image.h" #include "base/Image.h"
#include "base/Scene.h"
#include "base/Node.h" #include "base/Node.h"
#include "base/Scene.h"
#include "base/Sprite.h" #include "base/Sprite.h"
#include "base/Task.h"
#include "base/Text.h" #include "base/Text.h"
#include "base/Action.h" #include "base/Canvas.h"
#include "base/Music.h"
#include "base/Task.h"
#include "base/Action.hpp"
#include "base/ActionCombined.h" #include "base/ActionCombined.h"
#include "base/ActionFiniteTime.h" #include "base/ActionFiniteTime.h"
#include "base/Animation.h" #include "base/Animation.h"
#include "base/CallFunc.h" #include "base/CallFunc.h"
#include "base/Canvas.h"
#include "base/Transition.h" #include "base/Transition.h"
#include "base/Music.h"
#include "base/KeyEvent.h" #include "base/KeyEvent.h"
#include "base/MouseEvent.h" #include "base/MouseEvent.h"

View File

@ -53,7 +53,7 @@ namespace easy2d
{ {
} }
Button::Button(Node * normal, const Callback& func) Button::Button(spNode const& normal, const Callback& func)
: callback_(nullptr) : callback_(nullptr)
, status_(Status::Normal) , status_(Status::Normal)
, enabled_(true) , enabled_(true)
@ -67,7 +67,7 @@ namespace easy2d
this->SetCallbackOnClick(func); this->SetCallbackOnClick(func);
} }
Button::Button(Node * normal, Node * selected, const Callback& func) Button::Button(spNode const& normal, spNode const& selected, const Callback& func)
: callback_(nullptr) : callback_(nullptr)
, status_(Status::Normal) , status_(Status::Normal)
, enabled_(true) , enabled_(true)
@ -82,7 +82,7 @@ namespace easy2d
this->SetCallbackOnClick(func); this->SetCallbackOnClick(func);
} }
Button::Button(Node * normal, Node * mouseover, Node * selected, const Callback& func) Button::Button(spNode const& normal, spNode const& mouseover, spNode const& selected, const Callback& func)
: callback_(nullptr) : callback_(nullptr)
, status_(Status::Normal) , status_(Status::Normal)
, enabled_(true) , enabled_(true)
@ -98,7 +98,7 @@ namespace easy2d
this->SetCallbackOnClick(func); this->SetCallbackOnClick(func);
} }
Button::Button(Node * normal, Node * mouseover, Node * selected, Node * disabled, const Callback& func) Button::Button(spNode const& normal, spNode const& mouseover, spNode const& selected, spNode const& disabled, const Callback& func)
: callback_(nullptr) : callback_(nullptr)
, status_(Status::Normal) , status_(Status::Normal)
, enabled_(true) , enabled_(true)
@ -115,12 +115,16 @@ namespace easy2d
this->SetCallbackOnClick(func); this->SetCallbackOnClick(func);
} }
Button::~Button()
{
}
bool Button::IsEnable() const bool Button::IsEnable() const
{ {
return enabled_; return enabled_;
} }
void Button::SetNormal(Node * normal) void Button::SetNormal(spNode const& normal)
{ {
SET_BUTTON_NODE(normal_, normal); SET_BUTTON_NODE(normal_, normal);
if (normal) if (normal)
@ -129,17 +133,17 @@ namespace easy2d
} }
} }
void Button::SetMouseOver(Node * mouseover) void Button::SetMouseOver(spNode const& mouseover)
{ {
SET_BUTTON_NODE(mouseover_, mouseover); SET_BUTTON_NODE(mouseover_, mouseover);
} }
void Button::SetSelected(Node * selected) void Button::SetSelected(spNode const& selected)
{ {
SET_BUTTON_NODE(selected_, selected); SET_BUTTON_NODE(selected_, selected);
} }
void Button::SetDisabled(Node * disabled) void Button::SetDisabled(spNode const& disabled)
{ {
SET_BUTTON_NODE(disabled_, disabled); SET_BUTTON_NODE(disabled_, disabled);
} }

View File

@ -31,37 +31,39 @@ namespace easy2d
{ {
E2D_DISABLE_COPY(Button); E2D_DISABLE_COPY(Button);
typedef std::function<void()> Callback; using Callback = std::function<void()>;
public: public:
Button(); Button();
explicit Button( explicit Button(
Node * normal, /* 噸宥彜蓑 */ spNode const& normal, /* 噸宥彜蓑 */
const Callback& func = nullptr /* 按钮点击后的回调函数 */ const Callback& func = nullptr /* 按钮点击后的回调函数 */
); );
explicit Button( explicit Button(
Node * normal, /* 噸宥彜蓑 */ spNode const& normal, /* 噸宥彜蓑 */
Node * selected, /* 報炎梓和彜蓑 */ spNode const& selected, /* 報炎梓和彜蓑 */
const Callback& func = nullptr /* 按钮点击后的回调函数 */ const Callback& func = nullptr /* 按钮点击后的回调函数 */
); );
explicit Button( explicit Button(
Node * normal, /* 噸宥彜蓑 */ spNode const& normal, /* 噸宥彜蓑 */
Node * mouseover, /* 報炎卞秘彜蓑 */ spNode const& mouseover, /* 報炎卞秘彜蓑 */
Node * selected, /* 報炎梓和彜蓑 */ spNode const& selected, /* 報炎梓和彜蓑 */
const Callback& func = nullptr /* 按钮点击后的回调函数 */ const Callback& func = nullptr /* 按钮点击后的回调函数 */
); );
explicit Button( explicit Button(
Node * normal, /* 噸宥彜蓑 */ spNode const& normal, /* 噸宥彜蓑 */
Node * mouseover, /* 報炎卞秘彜蓑 */ spNode const& mouseover, /* 報炎卞秘彜蓑 */
Node * selected, /* 報炎卞秘彜蓑 */ spNode const& selected, /* 報炎卞秘彜蓑 */
Node * disabled, /* 梓泥鋤喘彜蓑 */ spNode const& disabled, /* 梓泥鋤喘彜蓑 */
const Callback& func = nullptr /* 按钮点击后的回调函数 */ const Callback& func = nullptr /* 按钮点击后的回调函数 */
); );
virtual ~Button();
// 获取按钮状态是启用还是禁用 // 获取按钮状态是启用还是禁用
bool IsEnable() const; bool IsEnable() const;
@ -72,22 +74,22 @@ namespace easy2d
// 设置一般情况下显示的按钮 // 设置一般情况下显示的按钮
virtual void SetNormal( virtual void SetNormal(
Node * normal spNode const& normal
); );
// 设置鼠标移入按钮时显示的按钮 // 设置鼠标移入按钮时显示的按钮
virtual void SetMouseOver( virtual void SetMouseOver(
Node * mouseover spNode const& mouseover
); );
// 设置鼠标按下按钮时显示的按钮 // 设置鼠标按下按钮时显示的按钮
virtual void SetSelected( virtual void SetSelected(
Node * selected spNode const& selected
); );
// 设置按钮被禁用时显示的按钮 // 设置按钮被禁用时显示的按钮
virtual void SetDisabled( virtual void SetDisabled(
Node * disabled spNode const& disabled
); );
// 设置按钮点击后的回调函数 // 设置按钮点击后的回调函数
@ -124,10 +126,10 @@ namespace easy2d
virtual void Visit() override; virtual void Visit() override;
private: private:
Node * normal_; spNode normal_;
Node * mouseover_; spNode mouseover_;
Node * selected_; spNode selected_;
Node * disabled_; spNode disabled_;
bool enabled_; bool enabled_;
bool is_selected_; bool is_selected_;
Status status_; Status status_;

View File

@ -29,7 +29,7 @@ namespace easy2d
{ {
} }
Menu::Menu(const std::vector<Button*>& buttons) Menu::Menu(const std::vector<spButton>& buttons)
: enabled_(true) : enabled_(true)
{ {
for (const auto& button : buttons) for (const auto& button : buttons)
@ -61,7 +61,7 @@ namespace easy2d
} }
} }
void Menu::AddButton(Button * button) void Menu::AddButton(spButton const& button)
{ {
if (button) if (button)
{ {
@ -71,7 +71,7 @@ namespace easy2d
} }
} }
bool Menu::RemoveButton(Button * button) bool Menu::RemoveButton(spButton const& button)
{ {
if (buttons_.empty()) if (buttons_.empty())
{ {
@ -94,7 +94,7 @@ namespace easy2d
return false; return false;
} }
const std::vector<Button*>& Menu::GetAllButtons() const const std::vector<spButton>& Menu::GetAllButtons() const
{ {
return buttons_; return buttons_;
} }

View File

@ -19,7 +19,6 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "../base/Node.h"
#include "Button.h" #include "Button.h"
namespace easy2d namespace easy2d
@ -36,7 +35,7 @@ namespace easy2d
Menu(); Menu();
explicit Menu( explicit Menu(
const std::vector<Button*>& buttons /* 按钮数组 */ const std::vector<spButton>& buttons /* 按钮数组 */
); );
// 获取菜单是否禁用 // 获取菜单是否禁用
@ -52,20 +51,20 @@ namespace easy2d
// 添加按钮 // 添加按钮
void AddButton( void AddButton(
Button * button spButton const& button
); );
// 移除按钮 // 移除按钮
bool RemoveButton( bool RemoveButton(
Button * button spButton const& button
); );
// 获取所有按钮 // 获取所有按钮
const std::vector<Button*>& GetAllButtons() const; const std::vector<spButton>& GetAllButtons() const;
private: private:
bool enabled_; bool enabled_;
std::vector<Button*> buttons_; std::vector<spButton> buttons_;
}; };
} }
} }

View File

@ -38,7 +38,7 @@ namespace easy2d
if (file_path.empty()) if (file_path.empty())
return false; return false;
Music * music = new (std::nothrow) Music(); spMusic music = new (std::nothrow) Music();
if (music) if (music)
{ {
@ -50,10 +50,6 @@ namespace easy2d
musics_cache_.insert(std::make_pair(hash_code, music)); musics_cache_.insert(std::make_pair(hash_code, music));
return true; return true;
} }
else
{
music->Release();
}
} }
return false; return false;
} }
@ -121,7 +117,7 @@ namespace easy2d
if (musics_cache_.end() != musics_cache_.find(hash_code)) if (musics_cache_.end() != musics_cache_.find(hash_code))
return true; return true;
Music * music = new (std::nothrow) Music(); spMusic music = new (std::nothrow) Music();
if (music) if (music)
{ {
@ -131,10 +127,6 @@ namespace easy2d
musics_cache_.insert(std::make_pair(hash_code, music)); musics_cache_.insert(std::make_pair(hash_code, music));
return true; return true;
} }
else
{
music->Release();
}
} }
return false; return false;
} }
@ -222,13 +214,6 @@ namespace easy2d
void Player::ClearCache() void Player::ClearCache()
{ {
if (musics_cache_.empty())
return;
for (const auto& pair : musics_cache_)
{
pair.second->Release();
}
musics_cache_.clear(); musics_cache_.clear();
} }
} }

View File

@ -24,8 +24,6 @@
namespace easy2d namespace easy2d
{ {
class Music;
// 音乐播放器 // 音乐播放器
class Player class Player
{ {
@ -120,6 +118,6 @@ namespace easy2d
protected: protected:
float volume_; float volume_;
std::map<size_t, Music*> musics_cache_; std::map<size_t, spMusic> musics_cache_;
}; };
} }

View File

@ -19,7 +19,7 @@
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\base\Action.h" /> <ClInclude Include="..\..\core\base\Action.hpp" />
<ClInclude Include="..\..\core\base\ActionCombined.h" /> <ClInclude Include="..\..\core\base\ActionCombined.h" />
<ClInclude Include="..\..\core\base\ActionFiniteTime.h" /> <ClInclude Include="..\..\core\base\ActionFiniteTime.h" />
<ClInclude Include="..\..\core\base\Animation.h" /> <ClInclude Include="..\..\core\base\Animation.h" />
@ -33,6 +33,7 @@
<ClInclude Include="..\..\core\base\Game.h" /> <ClInclude Include="..\..\core\base\Game.h" />
<ClInclude Include="..\..\core\base\Image.h" /> <ClInclude Include="..\..\core\base\Image.h" />
<ClInclude Include="..\..\core\base\Input.h" /> <ClInclude Include="..\..\core\base\Input.h" />
<ClInclude Include="..\..\core\base\IntrusivePtr.hpp" />
<ClInclude Include="..\..\core\base\KeyEvent.h" /> <ClInclude Include="..\..\core\base\KeyEvent.h" />
<ClInclude Include="..\..\core\base\logs.h" /> <ClInclude Include="..\..\core\base\logs.h" />
<ClInclude Include="..\..\core\base\macros.h" /> <ClInclude Include="..\..\core\base\macros.h" />
@ -41,7 +42,7 @@
<ClInclude Include="..\..\core\base\Music.h" /> <ClInclude Include="..\..\core\base\Music.h" />
<ClInclude Include="..\..\core\base\Node.h" /> <ClInclude Include="..\..\core\base\Node.h" />
<ClInclude Include="..\..\core\base\Rect.hpp" /> <ClInclude Include="..\..\core\base\Rect.hpp" />
<ClInclude Include="..\..\core\base\RefCounter.h" /> <ClInclude Include="..\..\core\base\RefCounter.hpp" />
<ClInclude Include="..\..\core\base\render.h" /> <ClInclude Include="..\..\core\base\render.h" />
<ClInclude Include="..\..\core\base\Resource.h" /> <ClInclude Include="..\..\core\base\Resource.h" />
<ClInclude Include="..\..\core\base\Scene.h" /> <ClInclude Include="..\..\core\base\Scene.h" />
@ -69,7 +70,6 @@
<ClInclude Include="..\..\core\utils\Transcoder.h" /> <ClInclude Include="..\..\core\utils\Transcoder.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\core\base\Action.cpp" />
<ClCompile Include="..\..\core\base\ActionCombined.cpp" /> <ClCompile Include="..\..\core\base\ActionCombined.cpp" />
<ClCompile Include="..\..\core\base\ActionFiniteTime.cpp" /> <ClCompile Include="..\..\core\base\ActionFiniteTime.cpp" />
<ClCompile Include="..\..\core\base\Animation.cpp" /> <ClCompile Include="..\..\core\base\Animation.cpp" />
@ -86,7 +86,6 @@
<ClCompile Include="..\..\core\base\MouseEvent.cpp" /> <ClCompile Include="..\..\core\base\MouseEvent.cpp" />
<ClCompile Include="..\..\core\base\Music.cpp" /> <ClCompile Include="..\..\core\base\Music.cpp" />
<ClCompile Include="..\..\core\base\Node.cpp" /> <ClCompile Include="..\..\core\base\Node.cpp" />
<ClCompile Include="..\..\core\base\RefCounter.cpp" />
<ClCompile Include="..\..\core\base\render.cpp" /> <ClCompile Include="..\..\core\base\render.cpp" />
<ClCompile Include="..\..\core\base\Resource.cpp" /> <ClCompile Include="..\..\core\base\Resource.cpp" />
<ClCompile Include="..\..\core\base\Scene.cpp" /> <ClCompile Include="..\..\core\base\Scene.cpp" />

View File

@ -2,9 +2,6 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\base\Action.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\ActionCombined.h"> <ClInclude Include="..\..\core\base\ActionCombined.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
@ -59,9 +56,6 @@
<ClInclude Include="..\..\core\base\Rect.hpp"> <ClInclude Include="..\..\core\base\Rect.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\RefCounter.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\render.h"> <ClInclude Include="..\..\core\base\render.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
@ -143,6 +137,15 @@
<ClInclude Include="..\..\core\base\Singleton.hpp"> <ClInclude Include="..\..\core\base\Singleton.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\RefCounter.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\IntrusivePtr.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\Action.hpp">
<Filter>base</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="base"> <Filter Include="base">
@ -159,9 +162,6 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\core\base\Action.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\ActionCombined.cpp"> <ClCompile Include="..\..\core\base\ActionCombined.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
@ -201,9 +201,6 @@
<ClCompile Include="..\..\core\base\Node.cpp"> <ClCompile Include="..\..\core\base\Node.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\RefCounter.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\render.cpp"> <ClCompile Include="..\..\core\base\render.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>

View File

@ -19,7 +19,7 @@
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\base\Action.h" /> <ClInclude Include="..\..\core\base\Action.hpp" />
<ClInclude Include="..\..\core\base\ActionCombined.h" /> <ClInclude Include="..\..\core\base\ActionCombined.h" />
<ClInclude Include="..\..\core\base\ActionFiniteTime.h" /> <ClInclude Include="..\..\core\base\ActionFiniteTime.h" />
<ClInclude Include="..\..\core\base\Animation.h" /> <ClInclude Include="..\..\core\base\Animation.h" />
@ -33,6 +33,7 @@
<ClInclude Include="..\..\core\base\Game.h" /> <ClInclude Include="..\..\core\base\Game.h" />
<ClInclude Include="..\..\core\base\Image.h" /> <ClInclude Include="..\..\core\base\Image.h" />
<ClInclude Include="..\..\core\base\Input.h" /> <ClInclude Include="..\..\core\base\Input.h" />
<ClInclude Include="..\..\core\base\IntrusivePtr.hpp" />
<ClInclude Include="..\..\core\base\KeyEvent.h" /> <ClInclude Include="..\..\core\base\KeyEvent.h" />
<ClInclude Include="..\..\core\base\logs.h" /> <ClInclude Include="..\..\core\base\logs.h" />
<ClInclude Include="..\..\core\base\macros.h" /> <ClInclude Include="..\..\core\base\macros.h" />
@ -41,7 +42,7 @@
<ClInclude Include="..\..\core\base\Music.h" /> <ClInclude Include="..\..\core\base\Music.h" />
<ClInclude Include="..\..\core\base\Node.h" /> <ClInclude Include="..\..\core\base\Node.h" />
<ClInclude Include="..\..\core\base\Rect.hpp" /> <ClInclude Include="..\..\core\base\Rect.hpp" />
<ClInclude Include="..\..\core\base\RefCounter.h" /> <ClInclude Include="..\..\core\base\RefCounter.hpp" />
<ClInclude Include="..\..\core\base\render.h" /> <ClInclude Include="..\..\core\base\render.h" />
<ClInclude Include="..\..\core\base\Resource.h" /> <ClInclude Include="..\..\core\base\Resource.h" />
<ClInclude Include="..\..\core\base\Scene.h" /> <ClInclude Include="..\..\core\base\Scene.h" />
@ -69,7 +70,6 @@
<ClInclude Include="..\..\core\utils\Transcoder.h" /> <ClInclude Include="..\..\core\utils\Transcoder.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\core\base\Action.cpp" />
<ClCompile Include="..\..\core\base\ActionCombined.cpp" /> <ClCompile Include="..\..\core\base\ActionCombined.cpp" />
<ClCompile Include="..\..\core\base\ActionFiniteTime.cpp" /> <ClCompile Include="..\..\core\base\ActionFiniteTime.cpp" />
<ClCompile Include="..\..\core\base\Animation.cpp" /> <ClCompile Include="..\..\core\base\Animation.cpp" />
@ -86,7 +86,6 @@
<ClCompile Include="..\..\core\base\MouseEvent.cpp" /> <ClCompile Include="..\..\core\base\MouseEvent.cpp" />
<ClCompile Include="..\..\core\base\Music.cpp" /> <ClCompile Include="..\..\core\base\Music.cpp" />
<ClCompile Include="..\..\core\base\Node.cpp" /> <ClCompile Include="..\..\core\base\Node.cpp" />
<ClCompile Include="..\..\core\base\RefCounter.cpp" />
<ClCompile Include="..\..\core\base\render.cpp" /> <ClCompile Include="..\..\core\base\render.cpp" />
<ClCompile Include="..\..\core\base\Resource.cpp" /> <ClCompile Include="..\..\core\base\Resource.cpp" />
<ClCompile Include="..\..\core\base\Scene.cpp" /> <ClCompile Include="..\..\core\base\Scene.cpp" />

View File

@ -2,9 +2,6 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\base\Action.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\ActionCombined.h"> <ClInclude Include="..\..\core\base\ActionCombined.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
@ -59,9 +56,6 @@
<ClInclude Include="..\..\core\base\Rect.hpp"> <ClInclude Include="..\..\core\base\Rect.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\RefCounter.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\render.h"> <ClInclude Include="..\..\core\base\render.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
@ -143,6 +137,15 @@
<ClInclude Include="..\..\core\base\Singleton.hpp"> <ClInclude Include="..\..\core\base\Singleton.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\RefCounter.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\IntrusivePtr.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\Action.hpp">
<Filter>base</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="base"> <Filter Include="base">
@ -159,9 +162,6 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\core\base\Action.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\ActionCombined.cpp"> <ClCompile Include="..\..\core\base\ActionCombined.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
@ -201,9 +201,6 @@
<ClCompile Include="..\..\core\base\Node.cpp"> <ClCompile Include="..\..\core\base\Node.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\RefCounter.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\render.cpp"> <ClCompile Include="..\..\core\base\render.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>

View File

@ -19,7 +19,7 @@
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\base\Action.h" /> <ClInclude Include="..\..\core\base\Action.hpp" />
<ClInclude Include="..\..\core\base\ActionCombined.h" /> <ClInclude Include="..\..\core\base\ActionCombined.h" />
<ClInclude Include="..\..\core\base\ActionFiniteTime.h" /> <ClInclude Include="..\..\core\base\ActionFiniteTime.h" />
<ClInclude Include="..\..\core\base\Animation.h" /> <ClInclude Include="..\..\core\base\Animation.h" />
@ -33,6 +33,7 @@
<ClInclude Include="..\..\core\base\Game.h" /> <ClInclude Include="..\..\core\base\Game.h" />
<ClInclude Include="..\..\core\base\Image.h" /> <ClInclude Include="..\..\core\base\Image.h" />
<ClInclude Include="..\..\core\base\Input.h" /> <ClInclude Include="..\..\core\base\Input.h" />
<ClInclude Include="..\..\core\base\IntrusivePtr.hpp" />
<ClInclude Include="..\..\core\base\KeyEvent.h" /> <ClInclude Include="..\..\core\base\KeyEvent.h" />
<ClInclude Include="..\..\core\base\logs.h" /> <ClInclude Include="..\..\core\base\logs.h" />
<ClInclude Include="..\..\core\base\macros.h" /> <ClInclude Include="..\..\core\base\macros.h" />
@ -41,7 +42,7 @@
<ClInclude Include="..\..\core\base\Music.h" /> <ClInclude Include="..\..\core\base\Music.h" />
<ClInclude Include="..\..\core\base\Node.h" /> <ClInclude Include="..\..\core\base\Node.h" />
<ClInclude Include="..\..\core\base\Rect.hpp" /> <ClInclude Include="..\..\core\base\Rect.hpp" />
<ClInclude Include="..\..\core\base\RefCounter.h" /> <ClInclude Include="..\..\core\base\RefCounter.hpp" />
<ClInclude Include="..\..\core\base\render.h" /> <ClInclude Include="..\..\core\base\render.h" />
<ClInclude Include="..\..\core\base\Resource.h" /> <ClInclude Include="..\..\core\base\Resource.h" />
<ClInclude Include="..\..\core\base\Scene.h" /> <ClInclude Include="..\..\core\base\Scene.h" />
@ -69,7 +70,6 @@
<ClInclude Include="..\..\core\utils\Transcoder.h" /> <ClInclude Include="..\..\core\utils\Transcoder.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\core\base\Action.cpp" />
<ClCompile Include="..\..\core\base\ActionCombined.cpp" /> <ClCompile Include="..\..\core\base\ActionCombined.cpp" />
<ClCompile Include="..\..\core\base\ActionFiniteTime.cpp" /> <ClCompile Include="..\..\core\base\ActionFiniteTime.cpp" />
<ClCompile Include="..\..\core\base\Animation.cpp" /> <ClCompile Include="..\..\core\base\Animation.cpp" />
@ -86,7 +86,6 @@
<ClCompile Include="..\..\core\base\MouseEvent.cpp" /> <ClCompile Include="..\..\core\base\MouseEvent.cpp" />
<ClCompile Include="..\..\core\base\Music.cpp" /> <ClCompile Include="..\..\core\base\Music.cpp" />
<ClCompile Include="..\..\core\base\Node.cpp" /> <ClCompile Include="..\..\core\base\Node.cpp" />
<ClCompile Include="..\..\core\base\RefCounter.cpp" />
<ClCompile Include="..\..\core\base\render.cpp" /> <ClCompile Include="..\..\core\base\render.cpp" />
<ClCompile Include="..\..\core\base\Resource.cpp" /> <ClCompile Include="..\..\core\base\Resource.cpp" />
<ClCompile Include="..\..\core\base\Scene.cpp" /> <ClCompile Include="..\..\core\base\Scene.cpp" />
@ -198,7 +197,7 @@
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck> <SDLCheck>false</SDLCheck>
<DebugInformationFormat>None</DebugInformationFormat> <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<MinimalRebuild>false</MinimalRebuild> <MinimalRebuild>false</MinimalRebuild>
<TreatWarningAsError>true</TreatWarningAsError> <TreatWarningAsError>true</TreatWarningAsError>
</ClCompile> </ClCompile>

View File

@ -2,9 +2,6 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\base\Action.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\ActionCombined.h"> <ClInclude Include="..\..\core\base\ActionCombined.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
@ -59,9 +56,6 @@
<ClInclude Include="..\..\core\base\Rect.hpp"> <ClInclude Include="..\..\core\base\Rect.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\RefCounter.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\render.h"> <ClInclude Include="..\..\core\base\render.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
@ -143,6 +137,15 @@
<ClInclude Include="..\..\core\base\Singleton.hpp"> <ClInclude Include="..\..\core\base\Singleton.hpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\core\base\RefCounter.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\IntrusivePtr.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\..\core\base\Action.hpp">
<Filter>base</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="base"> <Filter Include="base">
@ -159,9 +162,6 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\core\base\Action.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\ActionCombined.cpp"> <ClCompile Include="..\..\core\base\ActionCombined.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
@ -201,9 +201,6 @@
<ClCompile Include="..\..\core\base\Node.cpp"> <ClCompile Include="..\..\core\base\Node.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\base\RefCounter.cpp">
<Filter>base</Filter>
</ClCompile>
<ClCompile Include="..\..\core\base\render.cpp"> <ClCompile Include="..\..\core\base\render.cpp">
<Filter>base</Filter> <Filter>base</Filter>
</ClCompile> </ClCompile>