Collider作为Node的成员对象;禁止Ref子类的拷贝
This commit is contained in:
parent
2ee6ec29fe
commit
de951eaa40
|
|
@ -45,6 +45,7 @@ void e2d::Game::start(bool cleanup)
|
|||
auto timer = Timer::getInstance();
|
||||
auto sceneManager = SceneManager::getInstance();
|
||||
auto actionManager = ActionManager::getInstance();
|
||||
auto colliderManager = ColliderManager::getInstance();
|
||||
|
||||
// 显示窗口
|
||||
::ShowWindow(window->getHWnd(), SW_SHOWNORMAL);
|
||||
|
|
@ -76,6 +77,7 @@ void e2d::Game::start(bool cleanup)
|
|||
timer->update(); // 更新定时器
|
||||
actionManager->update(); // 更新动作管理器
|
||||
sceneManager->update(); // 更新场景内容
|
||||
colliderManager->update(); // 更新碰撞体
|
||||
renderer->render(); // 渲染游戏画面
|
||||
GC::flush(); // 刷新内存池
|
||||
|
||||
|
|
@ -145,8 +147,6 @@ void e2d::Game::cleanup()
|
|||
Timer::getInstance()->clearAllTasks();
|
||||
// 清除所有动作
|
||||
ActionManager::getInstance()->clearAll();
|
||||
// 清除所有碰撞体
|
||||
ColliderManager::getInstance()->clearAll();
|
||||
// 删除碰撞监听器
|
||||
Collision::clearAllListeners();
|
||||
// 删除输入监听器
|
||||
|
|
|
|||
|
|
@ -2,15 +2,16 @@
|
|||
#include "..\e2dmanager.h"
|
||||
#include "..\e2dnode.h"
|
||||
|
||||
e2d::Collider::Collider()
|
||||
e2d::Collider::Collider(Node * parent)
|
||||
: _visible(true)
|
||||
, _color(Color::Red, 0.7)
|
||||
, _parentNode(nullptr)
|
||||
, _parentNode(parent)
|
||||
, _transformed(nullptr)
|
||||
, _geometry(nullptr)
|
||||
, _enabled(true)
|
||||
, _type(Collider::Type::None)
|
||||
{
|
||||
_type = Game::getInstance()->getConfig()->getDefaultColliderType();
|
||||
}
|
||||
|
||||
e2d::Collider::~Collider()
|
||||
|
|
@ -19,11 +20,6 @@ e2d::Collider::~Collider()
|
|||
SafeRelease(_geometry);
|
||||
}
|
||||
|
||||
e2d::Node * e2d::Collider::getParentNode() const
|
||||
{
|
||||
return _parentNode;
|
||||
}
|
||||
|
||||
e2d::Color e2d::Collider::getColor() const
|
||||
{
|
||||
return _color;
|
||||
|
|
@ -93,76 +89,73 @@ void e2d::Collider::_recreate(Collider::Type type)
|
|||
{
|
||||
_type = type;
|
||||
|
||||
if (_parentNode)
|
||||
SafeRelease(_geometry);
|
||||
SafeRelease(_transformed);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
SafeRelease(_geometry);
|
||||
SafeRelease(_transformed);
|
||||
case Type::Rect:
|
||||
{
|
||||
ID2D1RectangleGeometry* rectangle = nullptr;
|
||||
Renderer::getFactory()->CreateRectangleGeometry(
|
||||
D2D1::RectF(
|
||||
0,
|
||||
0,
|
||||
float(_parentNode->getRealWidth()),
|
||||
float(_parentNode->getRealHeight())),
|
||||
&rectangle
|
||||
);
|
||||
_geometry = rectangle;
|
||||
}
|
||||
break;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case Type::Rect:
|
||||
{
|
||||
ID2D1RectangleGeometry* rectangle = nullptr;
|
||||
Renderer::getFactory()->CreateRectangleGeometry(
|
||||
D2D1::RectF(
|
||||
0,
|
||||
0,
|
||||
float(_parentNode->getRealWidth()),
|
||||
float(_parentNode->getRealHeight())),
|
||||
&rectangle
|
||||
);
|
||||
_geometry = rectangle;
|
||||
}
|
||||
break;
|
||||
case Type::Circle:
|
||||
{
|
||||
double minSide = std::min(_parentNode->getRealWidth(), _parentNode->getRealHeight());
|
||||
|
||||
case Type::Circle:
|
||||
{
|
||||
double minSide = std::min(_parentNode->getRealWidth(), _parentNode->getRealHeight());
|
||||
|
||||
ID2D1EllipseGeometry* circle = nullptr;
|
||||
Renderer::getFactory()->CreateEllipseGeometry(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(
|
||||
float(_parentNode->getRealWidth() / 2),
|
||||
float(_parentNode->getRealHeight() / 2)
|
||||
),
|
||||
float(minSide / 2),
|
||||
float(minSide / 2)
|
||||
ID2D1EllipseGeometry* circle = nullptr;
|
||||
Renderer::getFactory()->CreateEllipseGeometry(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(
|
||||
float(_parentNode->getRealWidth() / 2),
|
||||
float(_parentNode->getRealHeight() / 2)
|
||||
),
|
||||
&circle
|
||||
);
|
||||
_geometry = circle;
|
||||
}
|
||||
float(minSide / 2),
|
||||
float(minSide / 2)
|
||||
),
|
||||
&circle
|
||||
);
|
||||
_geometry = circle;
|
||||
}
|
||||
break;
|
||||
|
||||
case Type::Ellipse:
|
||||
{
|
||||
float halfWidth = float(_parentNode->getWidth() / 2),
|
||||
halfHeight = float(_parentNode->getHeight() / 2);
|
||||
|
||||
ID2D1EllipseGeometry* ellipse = nullptr;
|
||||
Renderer::getFactory()->CreateEllipseGeometry(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(
|
||||
halfWidth,
|
||||
halfHeight),
|
||||
halfWidth,
|
||||
halfHeight),
|
||||
&ellipse
|
||||
);
|
||||
_geometry = ellipse;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
case Type::Ellipse:
|
||||
{
|
||||
float halfWidth = float(_parentNode->getWidth() / 2),
|
||||
halfHeight = float(_parentNode->getHeight() / 2);
|
||||
|
||||
ID2D1EllipseGeometry* ellipse = nullptr;
|
||||
Renderer::getFactory()->CreateEllipseGeometry(
|
||||
D2D1::Ellipse(
|
||||
D2D1::Point2F(
|
||||
halfWidth,
|
||||
halfHeight),
|
||||
halfWidth,
|
||||
halfHeight),
|
||||
&ellipse
|
||||
);
|
||||
_geometry = ellipse;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::Collider::_transform()
|
||||
{
|
||||
if (_parentNode && _enabled)
|
||||
if (_enabled && _type != Type::None)
|
||||
{
|
||||
// 重新生成碰撞体
|
||||
_recreate(_type);
|
||||
|
|
@ -172,7 +165,5 @@ void e2d::Collider::_transform()
|
|||
_parentNode->_finalMatri,
|
||||
&_transformed
|
||||
);
|
||||
// ֪ͨÅöײÌå¹ÜÀíÆ÷
|
||||
ColliderManager::getInstance()->__updateCollider(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ void e2d::Scene::_render()
|
|||
// 恢复矩阵转换
|
||||
Renderer::getInstance()->getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||
// 绘制所有几何图形
|
||||
_root->_drawCollider();
|
||||
_root->_renderCollider();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "..\e2dmanager.h"
|
||||
#include "..\e2dnode.h"
|
||||
#include "..\e2dcollider.h"
|
||||
#include "..\e2dtool.h"
|
||||
|
||||
|
||||
e2d::ColliderManager * e2d::ColliderManager::_instance = nullptr;
|
||||
|
|
@ -23,7 +22,6 @@ void e2d::ColliderManager::destroyInstance()
|
|||
}
|
||||
|
||||
e2d::ColliderManager::ColliderManager()
|
||||
: _colliders()
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -31,79 +29,63 @@ e2d::ColliderManager::~ColliderManager()
|
|||
{
|
||||
}
|
||||
|
||||
void e2d::ColliderManager::clearAll()
|
||||
void e2d::ColliderManager::__remove(Node * node)
|
||||
{
|
||||
for (auto collder : _colliders)
|
||||
if (node)
|
||||
{
|
||||
GC::release(collder);
|
||||
auto iter = std::find(_nodes.begin(), _nodes.end(), node);
|
||||
if (iter != _nodes.end())
|
||||
{
|
||||
_nodes.erase(iter);
|
||||
}
|
||||
}
|
||||
_colliders.clear();
|
||||
}
|
||||
|
||||
void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
|
||||
void e2d::ColliderManager::updateCollider(Node * node)
|
||||
{
|
||||
if (node)
|
||||
{
|
||||
if (node->getCollider()->_type != Collider::Type::None)
|
||||
{
|
||||
node->getCollider()->_transform();
|
||||
_nodes.insert(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ColliderManager::update()
|
||||
{
|
||||
// 判断碰撞监听是否打开
|
||||
if (!Game::getInstance()->getConfig()->isCollisionEnabled())
|
||||
return;
|
||||
|
||||
Node* pActiveNode = pActiveCollider->_parentNode;
|
||||
if (pActiveNode)
|
||||
if (Game::getInstance()->isPaused() ||
|
||||
!Game::getInstance()->getConfig()->isCollisionEnabled() ||
|
||||
SceneManager::getInstance()->isTransitioning())
|
||||
{
|
||||
// 获取节点所在场景
|
||||
Scene* pCurrentScene = pActiveNode->getParentScene();
|
||||
_nodes.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto iter1 = _nodes.begin(); iter1 != _nodes.end(); iter1++)
|
||||
{
|
||||
auto node1 = (*iter1);
|
||||
// 判断与其他碰撞体的交集情况
|
||||
for (size_t i = 0; i < _colliders.size(); ++i)
|
||||
auto iter2 = iter1;
|
||||
iter2++;
|
||||
for (; iter2 != _nodes.end(); iter2++)
|
||||
{
|
||||
auto pPassiveCollider = _colliders[i];
|
||||
// 判断两个碰撞体是否是同一个对象
|
||||
if (pActiveCollider == pPassiveCollider)
|
||||
continue;
|
||||
|
||||
// 获取被碰撞节点
|
||||
Node* pPassiveNode = pPassiveCollider->_parentNode;
|
||||
// 判断两节点是否处于同一场景中
|
||||
if (pPassiveNode &&
|
||||
pPassiveNode->getParentScene() == pCurrentScene)
|
||||
auto node2 = (*iter2);
|
||||
// 判断两物体是否是相互冲突的物体
|
||||
if (Collision::isCollidable(node1, node2))
|
||||
{
|
||||
// 判断两物体是否是相互冲突的物体
|
||||
if (Collision::isCollidable(pActiveNode, pPassiveNode))
|
||||
// 判断两碰撞体交集情况
|
||||
Collider::Relation relation = node1->getCollider()->getRelationWith(node2->getCollider());
|
||||
// 忽略 UNKNOWN 和 DISJOIN 情况
|
||||
if (relation != Collider::Relation::Unknown && relation != Collider::Relation::Disjoin)
|
||||
{
|
||||
// 判断两碰撞体交集情况
|
||||
Collider::Relation relation = pActiveCollider->getRelationWith(pPassiveCollider);
|
||||
// 忽略 UNKNOWN 和 DISJOIN 情况
|
||||
if (relation != Collider::Relation::Unknown && relation != Collider::Relation::Disjoin)
|
||||
{
|
||||
// 更新碰撞监听器
|
||||
Collision::__update(pActiveNode, pPassiveNode);
|
||||
}
|
||||
// 更新碰撞监听器
|
||||
Collision::__update(node1, node2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ColliderManager::__add(Collider * collider)
|
||||
{
|
||||
if (collider)
|
||||
{
|
||||
GC::retain(collider);
|
||||
_colliders.push_back(collider);
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ColliderManager::__remove(Collider * collider)
|
||||
{
|
||||
if (collider)
|
||||
{
|
||||
for (size_t i = 0; i < _colliders.size(); ++i)
|
||||
{
|
||||
if (_colliders[i] == collider)
|
||||
{
|
||||
GC::release(collider);
|
||||
_colliders.erase(_colliders.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
_nodes.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ e2d::Node::Node()
|
|||
, _initialMatri(D2D1::Matrix3x2F::Identity())
|
||||
, _finalMatri(D2D1::Matrix3x2F::Identity())
|
||||
, _visible(true)
|
||||
, _collider(nullptr)
|
||||
, _collider(this)
|
||||
, _parent(nullptr)
|
||||
, _parentScene(nullptr)
|
||||
, _hashName(0)
|
||||
|
|
@ -30,21 +30,17 @@ e2d::Node::Node()
|
|||
, _needTransform(false)
|
||||
, _autoUpdate(true)
|
||||
, _positionFixed(false)
|
||||
, _colliderType(Collider::Type::None)
|
||||
{
|
||||
auto& config = Game::getInstance()->getConfig();
|
||||
// 设置默认中心点位置
|
||||
Point defPivot = config.getNodeDefaultPivot();
|
||||
Point defPivot = Game::getInstance()->getConfig()->getNodeDefaultPivot();
|
||||
this->_pivotX = float(defPivot.x);
|
||||
this->_pivotY = float(defPivot.y);
|
||||
// 设置默认碰撞体类型
|
||||
this->setColliderType(config.getDefaultColliderType());
|
||||
}
|
||||
|
||||
e2d::Node::~Node()
|
||||
{
|
||||
ActionManager::getInstance()->clearAllBindedWith(this);
|
||||
ColliderManager::getInstance()->__remove(_collider);
|
||||
ColliderManager::getInstance()->__remove(this);
|
||||
for (auto child : _children)
|
||||
{
|
||||
GC::release(child);
|
||||
|
|
@ -147,18 +143,18 @@ void e2d::Node::_render()
|
|||
}
|
||||
}
|
||||
|
||||
void e2d::Node::_drawCollider()
|
||||
void e2d::Node::_renderCollider()
|
||||
{
|
||||
// 绘制自身的几何碰撞体
|
||||
if (_collider && _collider->_visible)
|
||||
if (_collider._visible)
|
||||
{
|
||||
_collider->_render();
|
||||
_collider._render();
|
||||
}
|
||||
|
||||
// 绘制所有子节点的几何碰撞体
|
||||
for (auto child : _children)
|
||||
{
|
||||
child->_drawCollider();
|
||||
child->_renderCollider();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -194,11 +190,8 @@ void e2d::Node::_updateTransform()
|
|||
_finalMatri = _finalMatri * _parent->_initialMatri;
|
||||
}
|
||||
|
||||
// 重新生成碰撞体
|
||||
if (_collider)
|
||||
{
|
||||
_collider->_transform();
|
||||
}
|
||||
// ¸üÐÂÅöײÌå
|
||||
ColliderManager::getInstance()->updateCollider(this);
|
||||
// 标志已执行过变换
|
||||
_needTransform = false;
|
||||
|
||||
|
|
@ -354,9 +347,9 @@ e2d::Node::Property e2d::Node::getProperty() const
|
|||
return prop;
|
||||
}
|
||||
|
||||
e2d::Collider * e2d::Node::getCollider() const
|
||||
e2d::Collider* e2d::Node::getCollider()
|
||||
{
|
||||
return _collider;
|
||||
return &_collider;
|
||||
}
|
||||
|
||||
int e2d::Node::getOrder() const
|
||||
|
|
@ -546,50 +539,10 @@ void e2d::Node::setProperty(Property prop)
|
|||
|
||||
void e2d::Node::setColliderType(Collider::Type type)
|
||||
{
|
||||
if (_colliderType == type)
|
||||
return;
|
||||
|
||||
_colliderType = type;
|
||||
if (_collider)
|
||||
if (_collider._type != type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Collider::Type::Rect:
|
||||
case Collider::Type::Circle:
|
||||
case Collider::Type::Ellipse:
|
||||
{
|
||||
this->_collider->_recreate(type);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
// 删除碰撞体
|
||||
ColliderManager::getInstance()->__remove(_collider);
|
||||
_collider = nullptr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case Collider::Type::Rect:
|
||||
case Collider::Type::Circle:
|
||||
case Collider::Type::Ellipse:
|
||||
{
|
||||
_collider = new (e2d::autorelease) Collider();
|
||||
_collider->_parentNode = this;
|
||||
_collider->_recreate(type);
|
||||
// 添加新的碰撞体
|
||||
ColliderManager::getInstance()->__add(_collider);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
_collider._recreate(type);
|
||||
_needTransform = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -811,9 +764,9 @@ bool e2d::Node::containsPoint(const Point& point) const
|
|||
{
|
||||
BOOL ret = 0;
|
||||
// 如果存在碰撞体,用碰撞体判断
|
||||
if (_collider && _collider->getGeometry())
|
||||
if (_collider.getGeometry())
|
||||
{
|
||||
_collider->getGeometry()->FillContainsPoint(
|
||||
_collider.getGeometry()->FillContainsPoint(
|
||||
D2D1::Point2F(
|
||||
float(point.x),
|
||||
float(point.y)),
|
||||
|
|
@ -852,9 +805,9 @@ bool e2d::Node::containsPoint(const Point& point) const
|
|||
bool e2d::Node::intersects(Node * node) const
|
||||
{
|
||||
// 如果存在碰撞体,用碰撞体判断
|
||||
if (this->_collider && node->_collider)
|
||||
if (this->_collider.getGeometry() && node->_collider.getGeometry())
|
||||
{
|
||||
Collider::Relation relation = this->_collider->getRelationWith(node->_collider);
|
||||
Collider::Relation relation = this->_collider.getRelationWith(&node->_collider);
|
||||
if ((relation != Collider::Relation::Unknown) &&
|
||||
(relation != Collider::Relation::Disjoin))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -60,6 +60,8 @@ public:
|
|||
virtual Node * getTarget();
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Action);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init();
|
||||
|
||||
|
|
@ -101,6 +103,8 @@ public:
|
|||
virtual void reset() override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(FiniteTimeAction);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -133,6 +137,8 @@ public:
|
|||
virtual MoveBy * reverse() const override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(MoveBy);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -167,6 +173,8 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(MoveTo);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -194,6 +202,8 @@ public:
|
|||
virtual JumpBy * reverse() const override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(JumpBy);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -232,6 +242,8 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(JumpTo);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -263,6 +275,8 @@ public:
|
|||
virtual ScaleBy * reverse() const override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(ScaleBy);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -304,6 +318,8 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(ScaleTo);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -330,6 +346,8 @@ public:
|
|||
virtual OpacityBy * reverse() const override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(OpacityBy);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -363,6 +381,8 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(OpacityTo);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -383,6 +403,9 @@ public:
|
|||
: OpacityTo(duration, 1)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(FadeIn);
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -398,6 +421,9 @@ public:
|
|||
: OpacityTo(duration, 0)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(FadeOut);
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -418,6 +444,8 @@ public:
|
|||
virtual RotateBy * reverse() const override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(RotateBy);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -451,6 +479,8 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(RotateTo);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -478,6 +508,8 @@ public:
|
|||
virtual void reset() override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Delay);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -515,6 +547,8 @@ public:
|
|||
virtual void reset() override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Loop);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -547,6 +581,8 @@ public:
|
|||
virtual CallFunc * reverse() const override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(CallFunc);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -591,6 +627,8 @@ public:
|
|||
virtual void reset() override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Sequence);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -639,6 +677,8 @@ public:
|
|||
virtual void reset() override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Spawn);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
@ -702,6 +742,9 @@ public:
|
|||
// 获取帧动画的倒转
|
||||
Animation * reverse() const;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Animation);
|
||||
|
||||
protected:
|
||||
double _interval;
|
||||
std::vector<Image*> _frames;
|
||||
|
|
@ -739,6 +782,8 @@ public:
|
|||
virtual void reset() override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Animate);
|
||||
|
||||
// 初始化动作
|
||||
virtual void _init() override;
|
||||
|
||||
|
|
|
|||
190
core/e2dcommon.h
190
core/e2dcommon.h
|
|
@ -440,6 +440,96 @@ public:
|
|||
};
|
||||
|
||||
|
||||
class Node;
|
||||
class ColliderManager;
|
||||
|
||||
// 碰撞体
|
||||
class Collider
|
||||
{
|
||||
friend class Node;
|
||||
friend class ColliderManager;
|
||||
|
||||
public:
|
||||
// 碰撞体类别
|
||||
enum class Type
|
||||
{
|
||||
None, /* 无 */
|
||||
Rect, /* 矩形 */
|
||||
Circle, /* 圆形 */
|
||||
Ellipse /* 椭圆形 */
|
||||
};
|
||||
|
||||
// 碰撞体交集关系
|
||||
enum class Relation : int
|
||||
{
|
||||
Unknown = 0, /* 关系不确定 */
|
||||
Disjoin = 1, /* 没有交集 */
|
||||
IsContained = 2, /* 完全被包含 */
|
||||
Contains = 3, /* 完全包含 */
|
||||
Overlap = 4 /* 部分重叠 */
|
||||
};
|
||||
|
||||
public:
|
||||
// 启用或关闭该碰撞体
|
||||
virtual void setEnabled(
|
||||
bool enabled
|
||||
);
|
||||
|
||||
// 设置碰撞体的可见性
|
||||
void setVisible(
|
||||
bool visible
|
||||
);
|
||||
|
||||
// 设置绘制颜色
|
||||
void setColor(
|
||||
Color color
|
||||
);
|
||||
|
||||
// 判断两碰撞体的交集关系
|
||||
virtual Relation getRelationWith(
|
||||
Collider * pCollider
|
||||
) const;
|
||||
|
||||
// 获取绘制颜色
|
||||
Color getColor() const;
|
||||
|
||||
// 获取 ID2D1Geometry* 对象
|
||||
ID2D1Geometry* getGeometry() const;
|
||||
|
||||
// 获取 ID2D1TransformedGeometry* 对象
|
||||
ID2D1TransformedGeometry* getTransformedGeometry() const;
|
||||
|
||||
protected:
|
||||
Collider(
|
||||
Node * parent
|
||||
);
|
||||
|
||||
virtual ~Collider();
|
||||
|
||||
E2D_DISABLE_COPY(Collider);
|
||||
|
||||
// 重新生成
|
||||
void _recreate(
|
||||
Collider::Type type
|
||||
);
|
||||
|
||||
// 二维变换
|
||||
void _transform();
|
||||
|
||||
// 渲染碰撞体
|
||||
void _render();
|
||||
|
||||
protected:
|
||||
bool _enabled;
|
||||
bool _visible;
|
||||
Color _color;
|
||||
Node * _parentNode;
|
||||
Type _type;
|
||||
ID2D1Geometry* _geometry;
|
||||
ID2D1TransformedGeometry* _transformed;
|
||||
};
|
||||
|
||||
|
||||
// 引用计数对象
|
||||
class Ref
|
||||
{
|
||||
|
|
@ -457,6 +547,9 @@ public:
|
|||
// 获取引用计数
|
||||
int getRefCount() const;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Ref);
|
||||
|
||||
private:
|
||||
int _refCount;
|
||||
};
|
||||
|
|
@ -552,6 +645,8 @@ public:
|
|||
static void clearCache();
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Image);
|
||||
|
||||
// 设置 Bitmap
|
||||
void _setBitmap(
|
||||
ID2D1Bitmap * bitmap
|
||||
|
|
@ -563,7 +658,6 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
class Node;
|
||||
class SceneManager;
|
||||
class Transition;
|
||||
|
||||
|
|
@ -630,6 +724,8 @@ public:
|
|||
Node * getRoot() const;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Scene);
|
||||
|
||||
// 渲染场景画面
|
||||
void _render();
|
||||
|
||||
|
|
@ -642,95 +738,6 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
class ColliderManager;
|
||||
|
||||
// 碰撞体
|
||||
class Collider :
|
||||
public Ref
|
||||
{
|
||||
friend class Node;
|
||||
friend class ColliderManager;
|
||||
|
||||
public:
|
||||
// 碰撞体类别
|
||||
enum class Type
|
||||
{
|
||||
None, /* 无 */
|
||||
Rect, /* 矩形 */
|
||||
Circle, /* 圆形 */
|
||||
Ellipse /* 椭圆形 */
|
||||
};
|
||||
|
||||
// 碰撞体交集关系
|
||||
enum class Relation : int
|
||||
{
|
||||
Unknown = 0, /* 关系不确定 */
|
||||
Disjoin = 1, /* 没有交集 */
|
||||
IsContained = 2, /* 完全被包含 */
|
||||
Contains = 3, /* 完全包含 */
|
||||
Overlap = 4 /* 部分重叠 */
|
||||
};
|
||||
|
||||
public:
|
||||
Collider();
|
||||
|
||||
virtual ~Collider();
|
||||
|
||||
// 启用或关闭该碰撞体
|
||||
virtual void setEnabled(
|
||||
bool enabled
|
||||
);
|
||||
|
||||
// 设置碰撞体的可见性
|
||||
void setVisible(
|
||||
bool visible
|
||||
);
|
||||
|
||||
// 设置绘制颜色
|
||||
void setColor(
|
||||
Color color
|
||||
);
|
||||
|
||||
// 判断两碰撞体的交集关系
|
||||
virtual Relation getRelationWith(
|
||||
Collider * pCollider
|
||||
) const;
|
||||
|
||||
// 获取父节点
|
||||
Node * getParentNode() const;
|
||||
|
||||
// 获取绘制颜色
|
||||
Color getColor() const;
|
||||
|
||||
// 获取 ID2D1Geometry* 对象
|
||||
ID2D1Geometry* getGeometry() const;
|
||||
|
||||
// 获取 ID2D1TransformedGeometry* 对象
|
||||
ID2D1TransformedGeometry* getTransformedGeometry() const;
|
||||
|
||||
protected:
|
||||
// 重新生成
|
||||
void _recreate(
|
||||
Collider::Type type
|
||||
);
|
||||
|
||||
// 二维变换
|
||||
void _transform();
|
||||
|
||||
// 渲染碰撞体
|
||||
void _render();
|
||||
|
||||
protected:
|
||||
bool _enabled;
|
||||
bool _visible;
|
||||
Color _color;
|
||||
Node * _parentNode;
|
||||
Type _type;
|
||||
ID2D1Geometry* _geometry;
|
||||
ID2D1TransformedGeometry* _transformed;
|
||||
};
|
||||
|
||||
|
||||
class Game;
|
||||
|
||||
// 游戏配置
|
||||
|
|
@ -815,8 +822,6 @@ protected:
|
|||
}
|
||||
|
||||
|
||||
#ifndef __AUTORELEASE_T_DEFINED
|
||||
#define __AUTORELEASE_T_DEFINED
|
||||
namespace e2d
|
||||
{
|
||||
struct autorelease_t { };
|
||||
|
|
@ -843,4 +848,3 @@ void operator delete[](
|
|||
void* block,
|
||||
e2d::autorelease_t const&
|
||||
) E2D_NOEXCEPT;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -174,7 +174,6 @@ private:
|
|||
class ColliderManager
|
||||
{
|
||||
friend class Node;
|
||||
friend class Collider;
|
||||
|
||||
public:
|
||||
// 获取碰撞体管理器实例
|
||||
|
|
@ -183,8 +182,13 @@ public:
|
|||
// 销毁实例
|
||||
static void destroyInstance();
|
||||
|
||||
// 强制清除所有碰撞体
|
||||
void clearAll();
|
||||
// 更新碰撞体
|
||||
void updateCollider(
|
||||
Node * node
|
||||
);
|
||||
|
||||
// 更新碰撞体管理器
|
||||
void update();
|
||||
|
||||
private:
|
||||
ColliderManager();
|
||||
|
|
@ -193,23 +197,12 @@ private:
|
|||
|
||||
E2D_DISABLE_COPY(ColliderManager);
|
||||
|
||||
// 更新碰撞体
|
||||
void __updateCollider(
|
||||
Collider * pActiveCollider
|
||||
);
|
||||
|
||||
// 添加碰撞体
|
||||
void __add(
|
||||
Collider * pCollider
|
||||
);
|
||||
|
||||
// 删除已绑定的碰撞体
|
||||
void __remove(
|
||||
Collider * pCollider
|
||||
Node* node
|
||||
);
|
||||
|
||||
private:
|
||||
std::vector<Collider*> _colliders;
|
||||
std::set<Node*> _nodes;
|
||||
|
||||
static ColliderManager * _instance;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ public:
|
|||
virtual Property getProperty() const;
|
||||
|
||||
// 获取节点碰撞体
|
||||
virtual Collider * getCollider() const;
|
||||
virtual Collider * getCollider();
|
||||
|
||||
// 获取父节点
|
||||
virtual Node * getParent() const;
|
||||
|
|
@ -378,14 +378,16 @@ public:
|
|||
virtual void stopAllActions();
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Node);
|
||||
|
||||
// 更新节点
|
||||
void _update();
|
||||
|
||||
// 渲染节点
|
||||
void _render();
|
||||
|
||||
// äÖȾͼÐÎ
|
||||
void _drawCollider();
|
||||
// äÖȾÅöײÌåÂÖÀª
|
||||
void _renderCollider();
|
||||
|
||||
// 设置节点所在场景
|
||||
void _setParentScene(
|
||||
|
|
@ -426,10 +428,9 @@ protected:
|
|||
bool _needSort;
|
||||
bool _needTransform;
|
||||
bool _positionFixed;
|
||||
Collider * _collider;
|
||||
Collider _collider;
|
||||
Scene * _parentScene;
|
||||
Node * _parent;
|
||||
Collider::Type _colliderType;
|
||||
D2D1::Matrix3x2F _initialMatri;
|
||||
D2D1::Matrix3x2F _finalMatri;
|
||||
std::vector<Node*> _children;
|
||||
|
|
@ -495,6 +496,9 @@ public:
|
|||
// 渲染精灵
|
||||
virtual void onRender() override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Sprite);
|
||||
|
||||
protected:
|
||||
Image * _image;
|
||||
};
|
||||
|
|
@ -697,6 +701,8 @@ public:
|
|||
virtual void onRender() override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Text);
|
||||
|
||||
// 重新排版文字
|
||||
void _reset();
|
||||
|
||||
|
|
@ -781,6 +787,8 @@ public:
|
|||
);
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Button);
|
||||
|
||||
// 按钮状态枚举
|
||||
enum class ButtonState { Normal, Mouseover, Selected };
|
||||
|
||||
|
|
@ -899,6 +907,8 @@ public:
|
|||
);
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(ToggleButton);
|
||||
|
||||
// 刷新按钮开关
|
||||
virtual void _updateState();
|
||||
|
||||
|
|
@ -948,6 +958,9 @@ public:
|
|||
// 获取所有按钮
|
||||
const std::vector<Button*>& getAllButtons() const;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Menu);
|
||||
|
||||
protected:
|
||||
bool _enabled;
|
||||
std::vector<Button*> _buttons;
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ public:
|
|||
virtual void onRender() override;
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(Shape);
|
||||
|
||||
// äÖȾÂÖÀª
|
||||
virtual void _renderLine() = 0;
|
||||
|
||||
|
|
@ -96,6 +98,8 @@ public:
|
|||
virtual ~RectShape();
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(RectShape);
|
||||
|
||||
// äÖȾÂÖÀª
|
||||
virtual void _renderLine() override;
|
||||
|
||||
|
|
@ -143,6 +147,8 @@ public:
|
|||
);
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(RoundRectShape);
|
||||
|
||||
// äÖȾÂÖÀª
|
||||
virtual void _renderLine() override;
|
||||
|
||||
|
|
@ -182,6 +188,8 @@ public:
|
|||
);
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(CircleShape);
|
||||
|
||||
// äÖȾÂÖÀª
|
||||
virtual void _renderLine() override;
|
||||
|
||||
|
|
@ -230,6 +238,8 @@ public:
|
|||
);
|
||||
|
||||
protected:
|
||||
E2D_DISABLE_COPY(EllipseShape);
|
||||
|
||||
// äÖȾÂÖÀª
|
||||
virtual void _renderLine() override;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue