diff --git a/core/Action/Action.cpp b/core/Action/Action.cpp index 897a750f..a3a3d9a1 100644 --- a/core/Action/Action.cpp +++ b/core/Action/Action.cpp @@ -56,7 +56,7 @@ void e2d::EAction::setTarget(ENode * node) e2d::EAction * e2d::EAction::reverse() const { - assert(0); + ASSERT(false, "EAction cannot be reversed!"); return nullptr; } diff --git a/core/Action/ActionGradual.cpp b/core/Action/ActionGradual.cpp index c8c779b1..c1fbe469 100644 --- a/core/Action/ActionGradual.cpp +++ b/core/Action/ActionGradual.cpp @@ -13,6 +13,7 @@ void e2d::EActionGradual::_init() void e2d::EActionGradual::_update() { + EAction::_update(); // 判断时间间隔是否足够 if (m_fDuration == 0) { diff --git a/core/Action/ActionSequence.cpp b/core/Action/ActionSequence.cpp index 5cce2b07..015d1934 100644 --- a/core/Action/ActionSequence.cpp +++ b/core/Action/ActionSequence.cpp @@ -21,9 +21,9 @@ e2d::EActionSequence::EActionSequence(int number, EAction * action1, ...) : e2d::EActionSequence::~EActionSequence() { - for (auto action = m_vActions.begin(); action != m_vActions.end(); action++) + for (auto action : m_vActions) { - SafeRelease(&(*action)); + SafeRelease(&action); } } @@ -33,9 +33,9 @@ void e2d::EActionSequence::_init() // 将所有动作与目标绑定 if (m_pTarget) { - for (auto action = m_vActions.begin(); action != m_vActions.end(); action++) + for (auto action : m_vActions) { - (*action)->setTarget(m_pTarget); + action->setTarget(m_pTarget); } } // 初始化第一个动作 @@ -66,18 +66,18 @@ void e2d::EActionSequence::_update() void e2d::EActionSequence::_reset() { EAction::_reset(); - for (auto action = m_vActions.begin(); action != m_vActions.end(); action++) + for (auto action : m_vActions) { - (*action)->_reset(); + action->_reset(); } m_nActionIndex = 0; } void e2d::EActionSequence::_resetTime() { - for (auto action = m_vActions.begin(); action != m_vActions.end(); action++) + for (auto action : m_vActions) { - (*action)->_resetTime(); + action->_resetTime(); } } @@ -93,9 +93,9 @@ void e2d::EActionSequence::addAction(EAction * action) e2d::EActionSequence * e2d::EActionSequence::clone() const { auto a = new EActionSequence(); - for (auto action = m_vActions.begin(); action != m_vActions.end(); action++) + for (auto action : m_vActions) { - a->addAction((*action)->clone()); + a->addAction(action->clone()); } return a; } @@ -103,15 +103,15 @@ e2d::EActionSequence * e2d::EActionSequence::clone() const e2d::EActionSequence * e2d::EActionSequence::reverse(bool actionReverse) const { auto a = new EActionSequence(); - for (auto action = m_vActions.begin(); action != m_vActions.end(); action++) + for (auto action : m_vActions) { if (actionReverse) { - a->addAction((*action)->reverse()); + a->addAction(action->reverse()); } else { - a->addAction((*action)->clone()); + a->addAction(action->clone()); } } // 将动作顺序逆序排列 diff --git a/core/Action/Animation.cpp b/core/Action/Animation.cpp index 0f06cbb1..e62b3c3f 100644 --- a/core/Action/Animation.cpp +++ b/core/Action/Animation.cpp @@ -13,9 +13,9 @@ e2d::EAnimation::EAnimation(float invertal) e2d::EAnimation::~EAnimation() { - for (auto frame = m_vFrames.begin(); frame != m_vFrames.end(); frame++) + for (auto frame : m_vFrames) { - SafeRelease(&(*frame)); + SafeRelease(&frame); } } @@ -62,7 +62,7 @@ void e2d::EAnimation::_reset() m_nFrameIndex = 0; } -void e2d::EAnimation::addKeyframe(EKeyframe * frame) +void e2d::EAnimation::addKeyframe(EImage * frame) { if (frame) { @@ -74,9 +74,9 @@ void e2d::EAnimation::addKeyframe(EKeyframe * frame) e2d::EAnimation * e2d::EAnimation::clone() const { auto a = new EAnimation(m_fInterval); - for (auto frame = m_vFrames.begin(); frame != m_vFrames.end(); frame++) + for (auto frame : m_vFrames) { - a->addKeyframe((*frame)); + a->addKeyframe(frame); } return a; } diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index a78bf583..22787f46 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -167,6 +167,8 @@ void e2d::EGame::uninit() EMusicManager::__uninit(); // 恢复计时操作 ETime::__uninit(); + // 清空图片缓存 + EImage::clearCache(); // 删除渲染相关资源 ERenderer::__discardResources(); // 刷新内存池 diff --git a/core/Base/Renderer.cpp b/core/Base/Renderer.cpp index bd2e1823..f9db37d9 100644 --- a/core/Base/Renderer.cpp +++ b/core/Base/Renderer.cpp @@ -133,7 +133,7 @@ void e2d::ERenderer::__render() if (FAILED(hr)) { // 渲染时产生了未知的错误,退出游戏 - ASSERT(false, L"Renderer error!"); + ASSERT(false, L"Renderer error: %#X!", hr); EGame::quit(); } } diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index 51bb2d4d..1f9bee67 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -1,83 +1,82 @@ #include "..\enodes.h" #include - -struct ResKey -{ - ResKey() { resNameHash = 0; resTypeHash = 0; } - - bool operator < (ResKey const& key) const - { - if (resNameHash > key.resNameHash) - return true; - else if (resNameHash == key.resNameHash) - return resTypeHash > key.resTypeHash; - else - return false; - } - - size_t resNameHash; - size_t resTypeHash; -}; - static std::map s_mBitmapsFromFile; -static std::map s_mBitmapsFromResource; e2d::EImage::EImage() : m_pBitmap(nullptr) + , m_fSourceClipX(0) + , m_fSourceClipY(0) + , m_fSourceClipWidth(0) + , m_fSourceClipHeight(0) { } -e2d::EImage::EImage(LPCTSTR fileName) +e2d::EImage::EImage(LPCTSTR strFileName) { - this->loadFromFile(fileName); + this->loadFrom(strFileName); } -e2d::EImage::EImage(LPCTSTR resourceName, LPCTSTR resourceType) +e2d::EImage::EImage(LPCTSTR strFileName, float nClipX, float nClipY, float nClipWidth, float nClipHeight) { - this->loadFromResource(resourceName, resourceType); + this->loadFrom(strFileName); + this->clip(nClipX, nClipY, nClipWidth, nClipHeight); } e2d::EImage::~EImage() { } -void e2d::EImage::loadFromFile(const EString & fileName) +void e2d::EImage::loadFrom(const EString & strFilePath) { - WARN_IF(fileName.isEmpty(), "EImage cannot load bitmap from NULL file name."); + WARN_IF(strFilePath.isEmpty(), "EImage cannot load bitmap from NULL file name."); - if (fileName.isEmpty()) + if (strFilePath.isEmpty()) return; - if (!e2d::EImage::preload(fileName)) + if (!EImage::preload(strFilePath)) { WARN_IF(true, "Load EImage from file failed!"); return; } - m_pBitmap = s_mBitmapsFromFile.at(fileName.hash()); + m_pBitmap = s_mBitmapsFromFile.at(strFilePath.hash()); + m_fSourceClipX = m_fSourceClipY = 0; + m_fSourceClipWidth = m_pBitmap->GetSize().width; + m_fSourceClipHeight = m_pBitmap->GetSize().height; } -void e2d::EImage::loadFromResource(LPCTSTR resourceName, LPCTSTR resourceType) +void e2d::EImage::loadFrom(const EString & strFilePath, float x, float y, float width, float height) { - WARN_IF(!resourceName || !resourceType, "EImage cannot load bitmap from NULL resource."); + loadFrom(strFilePath); + clip(x, y, width, height); +} - if (!resourceName || !resourceType) - return; - - if (!e2d::EImage::preload(resourceName, resourceType)) +void e2d::EImage::clip(float x, float y, float width, float height) +{ + if (m_pBitmap) { - WARN_IF(true, "Load EImage from resource failed!"); - return; + m_fSourceClipX = min(max(x, 0), this->getSourceWidth()); + m_fSourceClipY = min(max(y, 0), this->getSourceHeight()); + m_fSourceClipWidth = min(max(width, 0), this->getSourceWidth() - m_fSourceClipX); + m_fSourceClipHeight = min(max(height, 0), this->getSourceHeight() - m_fSourceClipY); } +} - ResKey key; - std::hash h; - key.resNameHash = h(resourceName); - key.resTypeHash = h(resourceType); +float e2d::EImage::getWidth() const +{ + return m_fSourceClipWidth; +} - m_pBitmap = s_mBitmapsFromResource.at(key); +float e2d::EImage::getHeight() const +{ + return m_fSourceClipHeight; +} + +e2d::ESize e2d::EImage::getSize() const +{ + return ESize(m_fSourceClipWidth, m_fSourceClipHeight); } float e2d::EImage::getSourceWidth() const @@ -116,6 +115,21 @@ e2d::ESize e2d::EImage::getSourceSize() const } } +float e2d::EImage::getClipX() const +{ + return m_fSourceClipX; +} + +float e2d::EImage::getClipY() const +{ + return m_fSourceClipY; +} + +e2d::EPoint e2d::EImage::getClipPos() const +{ + return EPoint(m_fSourceClipX, m_fSourceClipY); +} + bool e2d::EImage::preload(const EString & fileName) { if (s_mBitmapsFromFile.find(fileName.hash()) != s_mBitmapsFromFile.end()) @@ -192,161 +206,16 @@ bool e2d::EImage::preload(const EString & fileName) return SUCCEEDED(hr); } -bool e2d::EImage::preload(LPCTSTR resourceName, LPCTSTR resourceType) -{ - std::hash h; - - ResKey key; - key.resNameHash = h(resourceName); - key.resTypeHash = h(resourceType); - - if (s_mBitmapsFromResource.find(key) != s_mBitmapsFromResource.end()) - { - return true; - } - - HRESULT hr = S_OK; - - IWICBitmapDecoder *pDecoder = nullptr; - IWICBitmapFrameDecode *pSource = nullptr; - IWICStream *pStream = nullptr; - IWICFormatConverter *pConverter = nullptr; - ID2D1Bitmap *pBitmap = nullptr; - - HRSRC imageResHandle = nullptr; - HGLOBAL imageResDataHandle = nullptr; - void *pImageFile = nullptr; - DWORD imageFileSize = 0; - - // 定位资源 - imageResHandle = ::FindResourceW(HINST_THISCOMPONENT, resourceName, resourceType); - - hr = imageResHandle ? S_OK : E_FAIL; - if (SUCCEEDED(hr)) - { - // 加载资源 - imageResDataHandle = ::LoadResource(HINST_THISCOMPONENT, imageResHandle); - - hr = imageResDataHandle ? S_OK : E_FAIL; - } - - if (SUCCEEDED(hr)) - { - // 获取文件指针,并锁定资源 - pImageFile = ::LockResource(imageResDataHandle); - - hr = pImageFile ? S_OK : E_FAIL; - } - - if (SUCCEEDED(hr)) - { - // 计算大小 - imageFileSize = SizeofResource(HINST_THISCOMPONENT, imageResHandle); - - hr = imageFileSize ? S_OK : E_FAIL; - } - - if (SUCCEEDED(hr)) - { - // 创建 WIC 流 - hr = ERenderer::getIWICImagingFactory()->CreateStream(&pStream); - } - - if (SUCCEEDED(hr)) - { - // 初始化流 - hr = pStream->InitializeFromMemory( - reinterpret_cast(pImageFile), - imageFileSize - ); - } - - if (SUCCEEDED(hr)) - { - // 创建流的解码器 - hr = ERenderer::getIWICImagingFactory()->CreateDecoderFromStream( - pStream, - NULL, - WICDecodeMetadataCacheOnLoad, - &pDecoder - ); - } - - if (SUCCEEDED(hr)) - { - // 创建初始化框架 - hr = pDecoder->GetFrame(0, &pSource); - } - - if (SUCCEEDED(hr)) - { - // 创建图片格式转换器 - // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED). - hr = ERenderer::getIWICImagingFactory()->CreateFormatConverter(&pConverter); - } - - if (SUCCEEDED(hr)) - { - // 图片格式转换成 32bppPBGRA - hr = pConverter->Initialize( - pSource, - GUID_WICPixelFormat32bppPBGRA, - WICBitmapDitherTypeNone, - NULL, - 0.f, - WICBitmapPaletteTypeMedianCut - ); - } - - if (SUCCEEDED(hr)) - { - // 从 WIC 位图创建一个 Direct2D 位图 - hr = ERenderer::getRenderTarget()->CreateBitmapFromWicBitmap( - pConverter, - NULL, - &pBitmap - ); - } - - if (SUCCEEDED(hr)) - { - std::hash h; - - ResKey key; - key.resNameHash = h(resourceName); - key.resTypeHash = h(resourceType); - - s_mBitmapsFromResource.insert( - std::map::value_type( - key, - pBitmap) - ); - } - - // 释放相关资源 - SafeReleaseInterface(&pDecoder); - SafeReleaseInterface(&pSource); - SafeReleaseInterface(&pStream); - SafeReleaseInterface(&pConverter); - - return SUCCEEDED(hr); -} - void e2d::EImage::clearCache() { - for (auto child = s_mBitmapsFromFile.begin(); child != s_mBitmapsFromFile.end(); child++) + for (auto child : s_mBitmapsFromFile) { - SafeReleaseInterface(&(*child).second); - } - for (auto child = s_mBitmapsFromFile.begin(); child != s_mBitmapsFromFile.end(); child++) - { - SafeReleaseInterface(&(*child).second); + SafeReleaseInterface(&child.second); } s_mBitmapsFromFile.clear(); - s_mBitmapsFromResource.clear(); } -ID2D1Bitmap * e2d::EImage::_getBitmap() +ID2D1Bitmap * e2d::EImage::getBitmap() { return m_pBitmap; } diff --git a/core/Common/Keyframe.cpp b/core/Common/Keyframe.cpp deleted file mode 100644 index 4f62950e..00000000 --- a/core/Common/Keyframe.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "..\ecommon.h" - -e2d::EKeyframe::EKeyframe() - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pImage(nullptr) -{ -} - -e2d::EKeyframe::EKeyframe(EImage * texture) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pImage(nullptr) -{ - _setImage(texture); -} - -e2d::EKeyframe::EKeyframe(const EString & imageFileName) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pImage(nullptr) -{ - _setImage(new EImage(imageFileName)); -} - -e2d::EKeyframe::EKeyframe(LPCTSTR resourceName, LPCTSTR resourceType) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pImage(nullptr) -{ - _setImage(new EImage(resourceName, resourceType)); -} - -e2d::EKeyframe::EKeyframe(EImage * texture, float x, float y, float width, float height) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pImage(nullptr) -{ - _setImage(texture); - _clipTexture(x, y, width, height); -} - -e2d::EKeyframe::EKeyframe(const EString & imageFileName, float x, float y, float width, float height) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pImage(nullptr) -{ - _setImage(new EImage(imageFileName)); - _clipTexture(x, y, width, height); -} - -e2d::EKeyframe::EKeyframe(LPCTSTR resourceName, LPCTSTR resourceType, float x, float y, float width, float height) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_fSourceClipWidth(0) - , m_fSourceClipHeight(0) - , m_pImage(nullptr) -{ - _setImage(new EImage(resourceName, resourceType)); - _clipTexture(x, y, width, height); -} - -e2d::EKeyframe::~EKeyframe() -{ - SafeRelease(&m_pImage); -} - -float e2d::EKeyframe::getWidth() const -{ - return m_fSourceClipWidth; -} - -float e2d::EKeyframe::getHeight() const -{ - return m_fSourceClipHeight; -} - -e2d::EImage * e2d::EKeyframe::getImage() const -{ - return m_pImage; -} - -void e2d::EKeyframe::_setImage(EImage * texture) -{ - if (texture) - { - SafeRelease(&m_pImage); - m_pImage = texture; - m_pImage->retain(); - m_fSourceClipX = 0; - m_fSourceClipY = 0; - m_fSourceClipWidth = texture->getSourceWidth(); - m_fSourceClipHeight = texture->getSourceHeight(); - } -} - -void e2d::EKeyframe::_clipTexture(float x, float y, float width, float height) -{ - if (m_pImage) - { - m_fSourceClipX = min(max(x, 0), m_pImage->getSourceWidth()); - m_fSourceClipY = min(max(y, 0), m_pImage->getSourceHeight()); - m_fSourceClipWidth = min(max(width, 0), m_pImage->getSourceWidth() - m_fSourceClipX); - m_fSourceClipHeight = min(max(height, 0), m_pImage->getSourceHeight() - m_fSourceClipY); - } -} diff --git a/core/Common/Scene.cpp b/core/Common/Scene.cpp index 737bc9a7..bcd7796d 100644 --- a/core/Common/Scene.cpp +++ b/core/Common/Scene.cpp @@ -7,8 +7,9 @@ e2d::EScene::EScene() : m_bWillSave(true) + , m_bAutoUpdate(true) , m_bSortNeeded(false) - , m_bGeometryVisiable(false) + , m_bShapeVisiable(false) , m_pRoot(new ENode()) { m_pRoot->retain(); @@ -27,23 +28,31 @@ void e2d::EScene::_render() { m_pRoot->_render(); - if (m_bGeometryVisiable) + if (m_bShapeVisiable) { // 恢复矩阵转换 ERenderer::getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); // 绘制所有几何图形 - m_pRoot->_drawGeometry(); + m_pRoot->_drawShape(); } } void e2d::EScene::_update() { // 执行 onUpdate 函数 - this->onUpdate(); + if (m_bAutoUpdate) + { + this->onUpdate(); + } // 更新根节点 m_pRoot->_update(); } +void e2d::EScene::setAutoUpdate(bool bAutoUpdate) +{ + m_bAutoUpdate = bAutoUpdate; +} + void e2d::EScene::add(ENode * child, int order /* = 0 */) { m_pRoot->addChild(child, order); @@ -54,42 +63,12 @@ bool e2d::EScene::remove(ENode * child) return m_pRoot->removeChild(child); } -void e2d::EScene::remove(const EString &childName) -{ - return m_pRoot->removeChild(childName); -} - -std::vector e2d::EScene::getChildren() -{ - return m_pRoot->m_vChildren; -} - -size_t e2d::EScene::getChildrenCount() const -{ - return m_pRoot->getChildrenCount(); -} - -e2d::ENode * e2d::EScene::getChild(const EString &childName) -{ - return m_pRoot->getChild(childName); -} - e2d::ENode * e2d::EScene::getRoot() const { return m_pRoot; } -void e2d::EScene::clearAllChildren() +void e2d::EScene::setShapeVisiable(bool visiable) { - m_pRoot->clearAllChildren(); -} - -void e2d::EScene::runAction(EAction * action) -{ - this->m_pRoot->runAction(action); -} - -void e2d::EScene::setGeometryVisiable(bool visiable) -{ - m_bGeometryVisiable = visiable; + m_bShapeVisiable = visiable; } diff --git a/core/Common/String.cpp b/core/Common/String.cpp index da8492ec..228fef2c 100644 --- a/core/Common/String.cpp +++ b/core/Common/String.cpp @@ -28,7 +28,9 @@ EString::EString(const wchar_t *str) } else { - this->EString::EString(); + _size = 0; + _string = new wchar_t[1]; + _string[0] = 0; } } @@ -49,7 +51,9 @@ EString::EString(const EString &str) } else { - this->EString::EString(); + _size = 0; + _string = new wchar_t[1]; + _string[0] = 0; } } @@ -63,7 +67,9 @@ e2d::EString::EString(const std::wstring &str) } else { - this->EString::EString(); + _size = 0; + _string = new wchar_t[1]; + _string[0] = 0; } } @@ -86,8 +92,9 @@ EString &EString::operator=(const wchar_t *str) } else { - _string = nullptr; _size = 0; + _string = new wchar_t[1]; + _string[0] = 0; } return *this; } @@ -106,8 +113,9 @@ EString &EString::operator=(const EString &str) } else { - _string = nullptr; _size = 0; + _string = new wchar_t[1]; + _string[0] = 0; } return *this; } @@ -123,15 +131,23 @@ EString & e2d::EString::operator=(const std::wstring &str) } else { - _string = nullptr; _size = 0; + _string = new wchar_t[1]; + _string[0] = 0; } return *this; } bool EString::operator==(const wchar_t *str) { - return (wcscmp(str, _string) == 0); + if (str) + { + return (wcscmp(str, _string) == 0); + } + else + { + return false; + } } bool EString::operator ==(const EString &str) diff --git a/core/Event/PhysicsEvent.cpp b/core/Event/PhysicsEvent.cpp deleted file mode 100644 index 49802df3..00000000 --- a/core/Event/PhysicsEvent.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "..\ecommon.h" - -e2d::EPhysicsEvent::INTERSECT_RELATION e2d::EPhysicsEvent::s_nRelation = e2d::EPhysicsEvent::UNKNOWN; -e2d::EGeometry * e2d::EPhysicsEvent::s_pActiveGeometry = nullptr; -e2d::EGeometry * e2d::EPhysicsEvent::s_pPassiveGeometry = nullptr; - -e2d::EPhysicsEvent::INTERSECT_RELATION e2d::EPhysicsEvent::getMsg() -{ - return EPhysicsEvent::s_nRelation; -} - -e2d::EGeometry * e2d::EPhysicsEvent::getActiveGeometry() -{ - return EPhysicsEvent::s_pActiveGeometry; -} - -e2d::EGeometry * e2d::EPhysicsEvent::getPassiveGeometry() -{ - return EPhysicsEvent::s_pPassiveGeometry; -} diff --git a/core/Geometry/Geometry.cpp b/core/Geometry/Geometry.cpp deleted file mode 100644 index 4ffb1c80..00000000 --- a/core/Geometry/Geometry.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "..\egeometry.h" -#include "..\emanagers.h" -#include "..\enodes.h" - -e2d::EGeometry::EGeometry() - : m_nCategoryBitmask(0) - , m_nCollisionBitmask(0) - , m_bIsVisiable(true) - , m_nColor(EColor::RED) - , m_fOpacity(1) - , m_pParentNode(nullptr) - , m_pTransformedGeometry(nullptr) -{ -} - -e2d::EGeometry::~EGeometry() -{ - SafeReleaseInterface(&m_pTransformedGeometry); -} - -e2d::ENode * e2d::EGeometry::getParentNode() const -{ - return m_pParentNode; -} - -UINT32 e2d::EGeometry::getCategoryBitmask() const -{ - return m_nCategoryBitmask; -} - -UINT32 e2d::EGeometry::getCollisionBitmask() const -{ - return m_nCollisionBitmask; -} - -void e2d::EGeometry::setCategoryBitmask(UINT32 mask) -{ - m_nCategoryBitmask = mask; -} - -void e2d::EGeometry::setCollisionBitmask(UINT32 mask) -{ - m_nCollisionBitmask = mask; -} - -void e2d::EGeometry::setVisiable(bool bVisiable) -{ - m_bIsVisiable = bVisiable; -} - -void e2d::EGeometry::setColor(UINT32 color) -{ - m_nColor = color; -} - -void e2d::EGeometry::setOpacity(float opacity) -{ - m_fOpacity = min(max(opacity, 0), 1); -} - -void e2d::EGeometry::_render() -{ - if (m_pTransformedGeometry) - { - ID2D1SolidColorBrush * pBrush = ERenderer::getSolidColorBrush(); - // 创建画刷 - ERenderer::getRenderTarget()->CreateSolidColorBrush( - D2D1::ColorF( - m_nColor, - m_fOpacity), - &pBrush - ); - // 绘制几何形状 - ERenderer::getRenderTarget()->DrawGeometry(m_pTransformedGeometry, pBrush); - } -} - -e2d::EPhysicsEvent::INTERSECT_RELATION e2d::EGeometry::_intersectWith(EGeometry * pGeometry) -{ - if (m_pTransformedGeometry && pGeometry->m_pTransformedGeometry) - { - D2D1_GEOMETRY_RELATION relation; - - m_pTransformedGeometry->CompareWithGeometry( - pGeometry->m_pTransformedGeometry, - D2D1::Matrix3x2F::Identity(), - &relation - ); - - return EPhysicsEvent::INTERSECT_RELATION(relation); - } - return EPhysicsEvent::UNKNOWN; -} - -void e2d::EGeometry::_transform() -{ - if (m_pParentNode) - { - // 释放原形状 - SafeReleaseInterface(&m_pTransformedGeometry); - - // 根据父节点转换几何图形 - ERenderer::getID2D1Factory()->CreateTransformedGeometry( - _getD2dGeometry(), - m_pParentNode->m_MatriFinal, - &m_pTransformedGeometry - ); - - // 判断形状变换后的情况 - EPhysicsManager::PhysicsGeometryProc(this); - } -} diff --git a/core/Listener/Listener.cpp b/core/Listener/Listener.cpp deleted file mode 100644 index 8fc9881c..00000000 --- a/core/Listener/Listener.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "..\elisteners.h" -#include "..\emanagers.h" -#include "..\enodes.h" - -e2d::EListener::EListener() - : m_bRunning(false) - , m_bAlways(false) - , m_pParentNode(nullptr) - , m_bSwallow(false) -{ -} - -e2d::EListener::EListener(const EString & name) - : m_bRunning(false) - , m_bAlways(false) - , m_pParentNode(nullptr) - , m_bSwallow(false) -{ - m_sName = name; -} - -bool e2d::EListener::isRunning() const -{ - return m_bRunning; -} - -void e2d::EListener::start() -{ - m_bRunning = true; -} - -void e2d::EListener::stop() -{ - m_bRunning = false; -} - -e2d::EString e2d::EListener::getName() const -{ - return m_sName; -} - -e2d::ENode * e2d::EListener::getParentNode() const -{ - return m_pParentNode; -} - -void e2d::EListener::setName(const EString & name) -{ - m_sName = name; -} - -void e2d::EListener::setSwallow(bool bSwallow) -{ - m_bSwallow = bSwallow; -} - -void e2d::EListener::setAlwaysWorking(bool bAlways) -{ - m_bAlways = bAlways; -} - -bool e2d::EListener::_isReady() const -{ - if (m_bRunning && m_pParentNode) - { - if (m_pParentNode->getParentScene() == ESceneManager::getCurrentScene()) - { - if (!EGame::isPaused() || m_bAlways) - return true; - } - } - return false; -} diff --git a/core/Listener/ListenerPhysics.cpp b/core/Listener/ListenerPhysics.cpp deleted file mode 100644 index 0617b72d..00000000 --- a/core/Listener/ListenerPhysics.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "..\elisteners.h" -#include "..\egeometry.h" -#include "..\emanagers.h" - -e2d::EListenerPhysics::EListenerPhysics() - : EListener() - , m_Callback(nullptr) -{ -} - -e2d::EListenerPhysics::EListenerPhysics(const EString & name) - : EListener(name) - , m_Callback(nullptr) -{ -} - -e2d::EListenerPhysics::EListenerPhysics(const PhysLsnrCallback & callback) - : EListener() - , m_Callback(callback) -{ -} - -e2d::EListenerPhysics::EListenerPhysics(const EString & name, const PhysLsnrCallback & callback) - : EListener(name) - , m_Callback(callback) -{ -} - -void e2d::EListenerPhysics::_callOn() -{ - if (m_Callback) - { - m_Callback(); - } -} - -void e2d::EListenerPhysics::setCallback(const PhysLsnrCallback & callback) -{ - m_Callback = callback; -} - -void e2d::EListenerPhysics::bindWith(EScene * pParentScene) -{ - WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); - - if (pParentScene) - { - EPhysicsManager::bindListener(this, pParentScene); - } -} - -void e2d::EListenerPhysics::bindWith(ENode * pParentNode) -{ - WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); - - if (pParentNode != nullptr) - { - EPhysicsManager::bindListener(this, pParentNode); - } -} diff --git a/core/Listener/ListenerPhysicsCollision.cpp b/core/Listener/ListenerPhysicsCollision.cpp deleted file mode 100644 index d98dfa51..00000000 --- a/core/Listener/ListenerPhysicsCollision.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "..\elisteners.h" -#include "..\egeometry.h" - -e2d::EListenerPhysicsCollision::EListenerPhysicsCollision() - : EListenerPhysics() - , m_Callback(nullptr) -{ -} - -e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const EString & name) - : EListenerPhysics(name) - , m_Callback(nullptr) -{ -} - -e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const ClsLsnrCallback & callback) - : EListenerPhysics() - , m_Callback(callback) -{ -} - -e2d::EListenerPhysicsCollision::EListenerPhysicsCollision(const EString & name, const ClsLsnrCallback & callback) - : EListenerPhysics(name) - , m_Callback(callback) -{ -} - -void e2d::EListenerPhysicsCollision::_callOn() -{ - if (EPhysicsEvent::getMsg() == EPhysicsEvent::OVERLAP || - EPhysicsEvent::getMsg() == EPhysicsEvent::CONTAINS || - EPhysicsEvent::getMsg() == EPhysicsEvent::IS_CONTAINED) - { - if (m_Callback) - { - m_Callback(); - } - } -} diff --git a/core/Manager/ActionManager.cpp b/core/Manager/ActionManager.cpp index b949824c..7e2cbbda 100644 --- a/core/Manager/ActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -20,16 +20,16 @@ void e2d::EActionManager::resumeAllActionsBindedWith(ENode * pTargetNode) { if (pTargetNode) { - for (auto action = s_vActions.begin(); action != s_vActions.end(); action++) + for (auto action : s_vActions) { - if ((*action)->getTarget() == pTargetNode) + if (action->getTarget() == pTargetNode) { - (*action)->start(); + action->start(); } } - for (auto child = pTargetNode->getChildren().begin(); child != pTargetNode->getChildren().end(); child++) + for (auto child : pTargetNode->getChildren()) { - EActionManager::resumeAllActionsBindedWith((*child)); + EActionManager::resumeAllActionsBindedWith(child); } } } @@ -38,16 +38,16 @@ void e2d::EActionManager::pauseAllActionsBindedWith(ENode * pTargetNode) { if (pTargetNode) { - for (auto action = s_vActions.begin(); action != s_vActions.end(); action++) + for (auto action : s_vActions) { - if ((*action)->getTarget() == pTargetNode) + if (action->getTarget() == pTargetNode) { - (*action)->pause(); + action->pause(); } } - for (auto child = pTargetNode->getChildren().begin(); child != pTargetNode->getChildren().end(); child++) + for (auto child : pTargetNode->getChildren()) { - EActionManager::pauseAllActionsBindedWith((*child)); + EActionManager::pauseAllActionsBindedWith(child); } } } @@ -56,16 +56,16 @@ void e2d::EActionManager::stopAllActionsBindedWith(ENode * pTargetNode) { if (pTargetNode) { - for (auto action = s_vActions.begin(); action != s_vActions.end(); action++) + for (auto action : s_vActions) { - if ((*action)->getTarget() == pTargetNode) + if (action->getTarget() == pTargetNode) { - (*action)->stop(); + action->stop(); } } - for (auto child = pTargetNode->getChildren().begin(); child != pTargetNode->getChildren().end(); child++) + for (auto child : pTargetNode->getChildren()) { - EActionManager::stopAllActionsBindedWith((*child)); + EActionManager::stopAllActionsBindedWith(child); } } } @@ -92,33 +92,33 @@ void e2d::EActionManager::__clearAllActionsBindedWith(ENode * pTargetNode) void e2d::EActionManager::resumeAllActions() { - for (auto child = ESceneManager::getCurrentScene()->getChildren().begin(); child != ESceneManager::getCurrentScene()->getChildren().end(); child++) + for (auto child : ESceneManager::getCurrentScene()->getRoot()->getChildren()) { - EActionManager::resumeAllActionsBindedWith((*child)); + EActionManager::resumeAllActionsBindedWith(child); } } void e2d::EActionManager::pauseAllActions() { - for (auto child = ESceneManager::getCurrentScene()->getChildren().begin(); child != ESceneManager::getCurrentScene()->getChildren().end(); child++) + for (auto child : ESceneManager::getCurrentScene()->getRoot()->getChildren()) { - EActionManager::pauseAllActionsBindedWith((*child)); + EActionManager::pauseAllActionsBindedWith(child); } } void e2d::EActionManager::stopAllActions() { - for (auto child = ESceneManager::getCurrentScene()->getChildren().begin(); child != ESceneManager::getCurrentScene()->getChildren().end(); child++) + for (auto child : ESceneManager::getCurrentScene()->getRoot()->getChildren()) { - EActionManager::stopAllActionsBindedWith((*child)); + EActionManager::stopAllActionsBindedWith(child); } } void e2d::EActionManager::__resetAllActions() { - for (auto action = s_vActions.begin(); action != s_vActions.end(); action++) + for (auto action : s_vActions) { - (*action)->_resetTime(); + action->_resetTime(); } } diff --git a/core/Manager/MusicManager.cpp b/core/Manager/MusicManager.cpp index c5251bf7..494f9f40 100644 --- a/core/Manager/MusicManager.cpp +++ b/core/Manager/MusicManager.cpp @@ -15,29 +15,27 @@ static MusicList& getMusicList() } -e2d::EMusic * e2d::EMusicManager::add(const EString & strFilePath) +bool e2d::EMusicManager::add(const EString & strFilePath) { EMusic * pPlayer = get(strFilePath); if (pPlayer) { - return pPlayer; + return true; } else { UINT nRet = strFilePath.hash(); - - getMusicList().insert(MusicPair(nRet, new EMusic())); - pPlayer = getMusicList()[nRet]; + pPlayer = new EMusic(); if (pPlayer->_open(strFilePath)) { - return pPlayer; + getMusicList().insert(MusicPair(nRet, pPlayer)); + return true; } else { delete pPlayer; - getMusicList().erase(nRet); - return nullptr; + return false; } } } @@ -57,25 +55,25 @@ e2d::EMusic * e2d::EMusicManager::get(const EString & strFilePath) void e2d::EMusicManager::pauseAllMusics() { - for (auto iter = getMusicList().begin(); iter != getMusicList().end(); iter++) + for (auto iter : getMusicList()) { - (*iter).second->pause(); + iter.second->pause(); } } void e2d::EMusicManager::resumeAllMusics() { - for (auto iter = getMusicList().begin(); iter != getMusicList().end(); iter++) + for (auto iter : getMusicList()) { - (*iter).second->resume(); + iter.second->resume(); } } void e2d::EMusicManager::stopAllMusics() { - for (auto iter = getMusicList().begin(); iter != getMusicList().end(); iter++) + for (auto iter : getMusicList()) { - (*iter).second->stop(); + iter.second->stop(); } } @@ -111,10 +109,10 @@ bool e2d::EMusicManager::__init() void e2d::EMusicManager::__uninit() { - for (auto iter = getMusicList().begin(); iter != getMusicList().end(); iter++) + for (auto iter : getMusicList()) { - (*iter).second->_close(); - (*iter).second->release(); + iter.second->_close(); + delete iter.second; } getMusicList().clear(); diff --git a/core/Manager/PhysicsManager.cpp b/core/Manager/PhysicsManager.cpp deleted file mode 100644 index dd8ce2ee..00000000 --- a/core/Manager/PhysicsManager.cpp +++ /dev/null @@ -1,225 +0,0 @@ -#include "..\emanagers.h" -#include "..\enodes.h" -#include "..\elisteners.h" -#include "..\egeometry.h" - -// 监听器集合 -std::vector s_vListeners; -// 形状集合 -std::vector s_vGeometries; - - -void e2d::EPhysicsManager::PhysicsGeometryProc(EGeometry * pActiveGeometry) -{ - if (s_vListeners.empty() || s_vGeometries.empty() || EGame::isPaused()) - return; - - // pActiveGeometry 为主动方 - EPhysicsEvent::s_pActiveGeometry = pActiveGeometry; - // 判断变化后的状态 - for (UINT i = 0; i < s_vGeometries.size(); i++) - { - auto pPassiveGeometry = s_vGeometries[i]; - // 不与其他场景的物体判断 - if (!pPassiveGeometry->getParentNode() || - (pPassiveGeometry->getParentNode()->getParentScene() != ESceneManager::getCurrentScene())) - continue; - - if (pActiveGeometry != pPassiveGeometry) - { - // 判断两物体是否是相互冲突的物体 - if (pActiveGeometry->m_nCollisionBitmask & pPassiveGeometry->m_nCategoryBitmask) - { - // pPassiveGeometry 为被动方 - EPhysicsEvent::s_pPassiveGeometry = pPassiveGeometry; - // 获取两方的关系 - EPhysicsEvent::s_nRelation = pActiveGeometry->_intersectWith(pPassiveGeometry); - // 如果关系不为未知或无交集,响应监听器 - if (EPhysicsEvent::s_nRelation != EPhysicsEvent::UNKNOWN && - EPhysicsEvent::s_nRelation != EPhysicsEvent::DISJOINT) - { - // 执行监听器 - PhysicsListenerProc(); - } - } - } - } -} - -void e2d::EPhysicsManager::PhysicsListenerProc() -{ - // 执行鼠标消息监听函数 - size_t i = s_vListeners.size(); - - do - { - auto listener = s_vListeners[--i]; - - if (listener->_isReady()) - { - listener->_callOn(); - if (listener->m_bSwallow) - break; - } - } while (i != 0); -} - -void e2d::EPhysicsManager::bindListener(EListenerPhysics * listener, EScene * pParentScene) -{ - EPhysicsManager::bindListener(listener, pParentScene->getRoot()); -} - -void e2d::EPhysicsManager::bindListener(EListenerPhysics * listener, ENode * pParentNode) -{ - WARN_IF(listener == nullptr, "EListenerPhysics NULL pointer exception!"); - WARN_IF(pParentNode == nullptr, "EListenerPhysics add to a NULL ENode pointer!"); - - if (listener && pParentNode) - { - ASSERT( - !listener->m_pParentNode, - "The listener is already binded, it cannot bind again!" - ); - - listener->retain(); - listener->start(); - listener->m_pParentNode = pParentNode; - s_vListeners.push_back(listener); - } -} - -void e2d::EPhysicsManager::_addGeometry(EGeometry * geometry) -{ - if (geometry) - { - geometry->retain(); - s_vGeometries.push_back(geometry); - } -} - -void e2d::EPhysicsManager::_delGeometry(EGeometry * geometry) -{ - if (geometry) - { - for (UINT i = 0; i < s_vGeometries.size(); i++) - { - if (s_vGeometries[i] == geometry) - { - SafeRelease(&geometry); - s_vGeometries.erase(s_vGeometries.begin() + i); - return; - } - } - } -} - -void e2d::EPhysicsManager::startListeners(const EString & name) -{ - for (auto listener = s_vListeners.begin(); listener != s_vListeners.end(); listener++) - { - if ((*listener)->getName() == name) - { - (*listener)->start(); - } - } -} - -void e2d::EPhysicsManager::stopListeners(const EString & name) -{ - for (auto listener = s_vListeners.begin(); listener != s_vListeners.end(); listener++) - { - if ((*listener)->getName() == name) - { - (*listener)->stop(); - } - } -} - -void e2d::EPhysicsManager::delListeners(const EString & name) -{ - std::vector::iterator iter; - for (iter = s_vListeners.begin(); iter != s_vListeners.end();) - { - if ((*iter)->getName() == name) - { - SafeRelease(&(*iter)); - iter = s_vListeners.erase(iter); - } - else - { - iter++; - } - } -} - -void e2d::EPhysicsManager::startAllListenersBindedWith(EScene * pParentScene) -{ - EPhysicsManager::startAllListenersBindedWith(pParentScene->getRoot()); -} - -void e2d::EPhysicsManager::stopAllListenersBindedWith(EScene * pParentScene) -{ - EPhysicsManager::stopAllListenersBindedWith(pParentScene->getRoot()); -} - -void e2d::EPhysicsManager::startAllListenersBindedWith(ENode * pParentNode) -{ - for (auto listener = s_vListeners.begin(); listener != s_vListeners.end(); listener++) - { - if ((*listener)->getParentNode() == pParentNode) - { - (*listener)->start(); - } - } - for (auto child = pParentNode->getChildren().begin(); child != pParentNode->getChildren().end(); child++) - { - EPhysicsManager::startAllListenersBindedWith((*child)); - } -} - -void e2d::EPhysicsManager::stopAllListenersBindedWith(ENode * pParentNode) -{ - for (auto listener = s_vListeners.begin(); listener != s_vListeners.end(); listener++) - { - if ((*listener)->getParentNode() == pParentNode) - { - (*listener)->stop(); - } - } - for (auto child = pParentNode->getChildren().begin(); child != pParentNode->getChildren().end(); child++) - { - EPhysicsManager::stopAllListenersBindedWith((*child)); - } -} - -void e2d::EPhysicsManager::startAllListeners() -{ - EPhysicsManager::startAllListenersBindedWith(ESceneManager::getCurrentScene()); -} - -void e2d::EPhysicsManager::stopAllListeners() -{ - EPhysicsManager::stopAllListenersBindedWith(ESceneManager::getCurrentScene()); -} - -void e2d::EPhysicsManager::_clearManager() -{ - s_vListeners.clear(); -} - -void e2d::EPhysicsManager::_clearAllListenersBindedWith(ENode * pParentNode) -{ - for (UINT i = 0; i < s_vListeners.size();) - { - auto listener = s_vListeners[i]; - if (listener->getParentNode() == pParentNode) - { - SafeRelease(&listener); - s_vListeners.erase(s_vListeners.begin() + i); - } - else - { - i++; - } - } -} diff --git a/core/Manager/SceneManager.cpp b/core/Manager/SceneManager.cpp index 2e1e2969..5dd2935b 100644 --- a/core/Manager/SceneManager.cpp +++ b/core/Manager/SceneManager.cpp @@ -79,21 +79,40 @@ e2d::EScene * e2d::ESceneManager::getCurrentScene() void e2d::ESceneManager::__update() { + // 更新场景内容 + if (s_pCurrentScene) + { + s_pCurrentScene->_update(); + } + // 正在切换场景时,执行场景切换动画 if (s_pTransition) { + // 更新场景内容 + if (s_pNextScene) + { + s_pNextScene->_update(); + } + // 更新场景动画 s_pTransition->_update(); + if (s_pTransition->isEnding()) { s_pTransition->release(); s_pTransition = nullptr; } - return; + else + { + return; + } } // 下一场景指针不为空时,切换场景 if (s_pNextScene) { + // 执行当前场景的 onExit 函数 + s_pCurrentScene->onExit(); + // 若要保存当前场景,把它放入栈中 if (s_pCurrentScene->m_bWillSave) { @@ -104,21 +123,12 @@ void e2d::ESceneManager::__update() SafeRelease(&s_pCurrentScene); } - // 执行当前场景的 onExit 函数 - s_pCurrentScene->onExit(); - // 执行下一场景的 onEnter 函数 s_pNextScene->onEnter(); s_pCurrentScene = s_pNextScene; // 切换场景 s_pNextScene = nullptr; // 下一场景置空 } - - // 断言当前场景非空 - ASSERT(s_pCurrentScene != nullptr, "Current scene NULL pointer exception."); - - // 更新场景内容 - s_pCurrentScene->_update(); } void e2d::ESceneManager::__render() diff --git a/core/Manager/ShapeManager.cpp b/core/Manager/ShapeManager.cpp new file mode 100644 index 00000000..26fd7630 --- /dev/null +++ b/core/Manager/ShapeManager.cpp @@ -0,0 +1,67 @@ +#include "..\emanagers.h" +#include "..\enodes.h" +#include "..\eshape.h" + +// 形状集合 +std::vector s_vShapes; + + +void e2d::EShapeManager::__updateShape(e2d::EShape * pActiveShape) +{ + ENode* pActiveNode = pActiveShape->m_pParentNode; + if (pActiveNode) + { + // 获取节点所在场景 + EScene* pCurrentScene = pActiveNode->getParentScene(); + // 判断与其他形状的交集情况 + for (auto pPassiveShape : s_vShapes) + { + // 判断两物体是否是相互冲突的物体 + if (pActiveShape->m_nCollisionBitmask & pPassiveShape->m_nCategoryBitmask) + { + // 获取被碰撞节点 + ENode* pPassiveNode = pPassiveShape->m_pParentNode; + // 判断两节点是否处于同一场景中 + if (pPassiveNode && + pPassiveNode != pActiveNode && + pPassiveNode->getParentScene() == pCurrentScene) + { + // 判断两形状交集情况 + int relation = pActiveShape->getRelationWith(pPassiveShape); + // 忽略 UNKNOWN 和 DISJOINT 情况 + if (relation != ERelation::UNKNOWN && relation != ERelation::DISJOINT) + { + pActiveNode->onCollide(pPassiveNode, relation); + pPassiveNode->onCollide(pActiveNode, pPassiveShape->getRelationWith(pActiveShape)); + pCurrentScene->onCollide(pActiveNode, pPassiveNode); + } + } + } + } + } +} + +void e2d::EShapeManager::__addShape(EShape * pShape) +{ + if (pShape) + { + pShape->retain(); + s_vShapes.push_back(pShape); + } +} + +void e2d::EShapeManager::__delShape(EShape * pShape) +{ + if (pShape) + { + for (size_t i = 0; i < s_vShapes.size(); i++) + { + if (s_vShapes[i] == pShape) + { + SafeRelease(&pShape); + s_vShapes.erase(s_vShapes.begin() + i); + return; + } + } + } +} diff --git a/core/Manager/TimerManager.cpp b/core/Manager/TimerManager.cpp index 2db90158..f99be925 100644 --- a/core/Manager/TimerManager.cpp +++ b/core/Manager/TimerManager.cpp @@ -46,22 +46,22 @@ void e2d::ETimerManager::bindTimer(ETimer * timer, ENode * pParentNode) void e2d::ETimerManager::startTimers(const EString & name) { - for (auto timer = s_vTimers.begin(); timer != s_vTimers.end(); timer++) + for (auto timer : s_vTimers) { - if ((*timer)->getName() == name) + if (timer->getName() == name) { - (*timer)->start(); + timer->start(); } } } void e2d::ETimerManager::stopTimers(const EString & name) { - for (auto timer = s_vTimers.begin(); timer != s_vTimers.end(); timer++) + for (auto timer : s_vTimers) { - if ((*timer)->getName() == name) + if (timer->getName() == name) { - (*timer)->stop(); + timer->stop(); } } } @@ -95,11 +95,11 @@ void e2d::ETimerManager::stopAllTimersBindedWith(EScene * pParentScene) void e2d::ETimerManager::startAllTimersBindedWith(ENode * pParentNode) { - for (auto timer = s_vTimers.begin(); timer != s_vTimers.end(); timer++) + for (auto timer : s_vTimers) { - if ((*timer)->getParentNode() == pParentNode) + if (timer->getParentNode() == pParentNode) { - (*timer)->start(); + timer->start(); } } for (auto child = pParentNode->getChildren().begin(); child != pParentNode->getChildren().end(); child++) @@ -110,16 +110,16 @@ void e2d::ETimerManager::startAllTimersBindedWith(ENode * pParentNode) void e2d::ETimerManager::stopAllTimersBindedWith(ENode * pParentNode) { - for (auto timer = s_vTimers.begin(); timer != s_vTimers.end(); timer++) + for (auto timer : s_vTimers) { - if ((*timer)->getParentNode() == pParentNode) + if (timer->getParentNode() == pParentNode) { - (*timer)->stop(); + timer->stop(); } } - for (auto child = pParentNode->getChildren().begin(); child != pParentNode->getChildren().end(); child++) + for (auto child : pParentNode->getChildren()) { - ETimerManager::stopAllTimersBindedWith((*child)); + ETimerManager::stopAllTimersBindedWith(child); } } @@ -142,9 +142,9 @@ void e2d::ETimerManager::__clearAllTimersBindedWith(ENode * pParentNode) void e2d::ETimerManager::__resetAllTimers() { - for (auto timer = s_vTimers.begin(); timer != s_vTimers.end(); timer++) + for (auto timer : s_vTimers) { - (*timer)->m_fLast = ETime::getTotalTime(); + timer->m_fLast = ETime::getTotalTime(); } } diff --git a/core/Node/Button.cpp b/core/Node/Button.cpp index 9807ca11..445f5223 100644 --- a/core/Node/Button.cpp +++ b/core/Node/Button.cpp @@ -1,6 +1,4 @@ #include "..\enodes.h" -#include "..\elisteners.h" -#include "..\emanagers.h" e2d::EButton::EButton() : m_Callback((const BtnClkCallback &)nullptr) diff --git a/core/Node/ButtonToggle.cpp b/core/Node/ButtonToggle.cpp index 50474df5..e2846d77 100644 --- a/core/Node/ButtonToggle.cpp +++ b/core/Node/ButtonToggle.cpp @@ -1,6 +1,4 @@ #include "..\enodes.h" -#include "..\elisteners.h" -#include "..\emanagers.h" e2d::EButtonToggle::EButtonToggle() : EButton() diff --git a/core/Node/Menu.cpp b/core/Node/Menu.cpp index b88fb004..b156782e 100644 --- a/core/Node/Menu.cpp +++ b/core/Node/Menu.cpp @@ -1,5 +1,4 @@ #include "..\enodes.h" -#include "..\elisteners.h" e2d::EMenu::EMenu() : m_bEnable(true) @@ -35,9 +34,9 @@ void e2d::EMenu::setEnable(bool enable) { m_bEnable = enable; - for (auto button = m_vButtons.begin(); button != m_vButtons.end(); button++) + for (auto button : m_vButtons) { - (*button)->setEnable(enable); + button->setEnable(enable); } } } diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index f816cf80..a7dc776e 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -2,7 +2,7 @@ #include "..\emanagers.h" #include "..\etools.h" #include "..\eactions.h" -#include "..\egeometry.h" +#include "..\eshape.h" #include // 默认中心点位置 @@ -24,59 +24,29 @@ e2d::ENode::ENode() , m_MatriFinal(D2D1::Matrix3x2F::Identity()) , m_bVisiable(true) , m_bDisplayedInScene(false) - , m_pGeometry(nullptr) + , m_pShape(nullptr) , m_pParent(nullptr) , m_pParentScene(nullptr) , m_nHashName(0) , m_bSortChildrenNeeded(false) , m_bTransformNeeded(false) + , m_bAutoUpdate(true) { } -e2d::ENode::ENode(const EString & name) - : m_nOrder(0) - , m_fScaleX(1.0f) - , m_fScaleY(1.0f) - , m_fRotation(0) - , m_fSkewAngleX(0) - , m_fSkewAngleY(0) - , m_fDisplayOpacity(1.0f) - , m_fRealOpacity(1.0f) - , m_fPivotX(s_fDefaultPiovtX) - , m_fPivotY(s_fDefaultPiovtY) - , m_MatriInitial(D2D1::Matrix3x2F::Identity()) - , m_MatriFinal(D2D1::Matrix3x2F::Identity()) - , m_bVisiable(true) - , m_bDisplayedInScene(false) - , m_pGeometry(nullptr) - , m_pParent(nullptr) - , m_pParentScene(nullptr) - , m_nHashName(0) - , m_bSortChildrenNeeded(false) - , m_bTransformNeeded(false) -{ - this->setName(name); -} - e2d::ENode::~ENode() { ETimerManager::__clearAllTimersBindedWith(this); EActionManager::__clearAllActionsBindedWith(this); - EPhysicsManager::_clearAllListenersBindedWith(this); - EPhysicsManager::_delGeometry(m_pGeometry); - for (auto child = m_vChildren.begin(); child != m_vChildren.end(); child++) + EShapeManager::__delShape(m_pShape); + for (auto child : m_vChildren) { - SafeRelease(&(*child)); + SafeRelease(&child); } } void e2d::ENode::_update() { - if (!m_bVisiable) - { - return; - } - if (m_bTransformNeeded) { _updateTransform(this); @@ -84,8 +54,21 @@ void e2d::ENode::_update() if (!m_vChildren.empty()) { - this->_sortChildren(); + // 子节点排序 + if (m_bSortChildrenNeeded) + { + std::sort( + std::begin(m_vChildren), + std::end(m_vChildren), + [](ENode * n1, ENode * n2) { + return n1->getOrder() < n2->getOrder(); + } + ); + m_bSortChildrenNeeded = false; + } + + // 遍历子节点 size_t size = m_vChildren.size(); size_t i; for (i = 0; i < size; i++) @@ -103,7 +86,10 @@ void e2d::ENode::_update() } // 执行 onUpdate 函数 - this->onUpdate(); + if (m_bAutoUpdate) + { + this->onUpdate(); + } // 访问剩余节点 for (; i < size; i++) @@ -159,31 +145,31 @@ void e2d::ENode::_render() } } -void e2d::ENode::_drawGeometry() +void e2d::ENode::_drawShape() { // 绘制自身的几何形状 - if (m_pGeometry && m_pGeometry->m_bIsVisiable) + if (m_pShape && m_pShape->m_bIsVisiable) { - m_pGeometry->_render(); + m_pShape->_render(); } // 绘制所有子节点的几何形状 - for (auto child = m_vChildren.begin(); child != m_vChildren.end(); child++) + for (auto child : m_vChildren) { - (*child)->_drawGeometry(); + child->_drawShape(); } } void e2d::ENode::_onEnter() { - if (!this->m_bDisplayedInScene && this->isVisiable()) + if (!this->m_bDisplayedInScene) { this->m_bDisplayedInScene = true; this->onEnter(); - for (auto child = m_vChildren.begin(); child != m_vChildren.end(); child++) + for (auto child : m_vChildren) { - (*child)->_onEnter(); + child->_onEnter(); } } } @@ -195,30 +181,13 @@ void e2d::ENode::_onExit() this->m_bDisplayedInScene = false; this->onExit(); - for (auto child = m_vChildren.begin(); child != m_vChildren.end(); child++) + for (auto child : m_vChildren) { - (*child)->_onExit(); + child->_onExit(); } } } -void e2d::ENode::_sortChildren() -{ - if (m_bSortChildrenNeeded) - { - // 子节点排序 - std::sort( - std::begin(m_vChildren), - std::end(m_vChildren), - [](ENode * n1, ENode * n2) { - return n1->getOrder() < n2->getOrder(); - } - ); - - m_bSortChildrenNeeded = false; - } -} - void e2d::ENode::_updateTransform() { // 计算中心点坐标 @@ -253,9 +222,9 @@ void e2d::ENode::_updateTransform() void e2d::ENode::_updateChildrenTransform() { - for (auto child = m_vChildren.begin(); child != m_vChildren.end(); child++) + for (auto child : m_vChildren) { - _updateTransform((*child)); + _updateTransform(child); } } @@ -264,9 +233,9 @@ void e2d::ENode::_updateTransform(ENode * node) // 计算自身的转换矩阵 node->_updateTransform(); // 绑定于自身的形状也进行相应转换 - if (node->m_pGeometry) + if (node->m_pShape) { - node->m_pGeometry->_transform(); + node->m_pShape->_transform(); } // 遍历子节点下的所有节点 node->_updateChildrenTransform(); @@ -276,9 +245,9 @@ void e2d::ENode::_updateTransform(ENode * node) void e2d::ENode::_updateChildrenOpacity() { - for (auto child = m_vChildren.begin(); child != m_vChildren.end(); child++) + for (auto child : m_vChildren) { - _updateOpacity((*child)); + _updateOpacity(child); } } @@ -386,6 +355,11 @@ float e2d::ENode::getOpacity() const return m_fRealOpacity; } +e2d::EShape * e2d::ENode::getShape() const +{ + return m_pShape; +} + int e2d::ENode::getOrder() const { return m_nOrder; @@ -441,21 +415,6 @@ void e2d::ENode::movePos(const EVector2 & v) this->movePos(v.x, v.y); } -void e2d::ENode::_setWidth(float width) -{ - this->_setSize(width, m_Size.height); -} - -void e2d::ENode::_setHeight(float height) -{ - this->_setSize(m_Size.width, height); -} - -void e2d::ENode::_setSize(const ESize & size) -{ - this->_setSize(size.width, size.height); -} - void e2d::ENode::_setSize(float width, float height) { if (m_Size.width == width && m_Size.height == height) @@ -550,32 +509,33 @@ void e2d::ENode::setPivot(float pivotX, float pivotY) m_bTransformNeeded = true; } -void e2d::ENode::setGeometry(EGeometry * geometry) +void e2d::ENode::setShape(EShape * pShape) { // 删除旧的形状 - EPhysicsManager::_delGeometry(m_pGeometry); + EShapeManager::__delShape(m_pShape); // 添加新的形状 - EPhysicsManager::_addGeometry(geometry); + EShapeManager::__addShape(pShape); - if (geometry) + if (pShape) { // 双向绑定 - this->m_pGeometry = geometry; - geometry->m_pParentNode = this; + this->m_pShape = pShape; + pShape->m_pParentNode = this; } else { - this->m_pGeometry = nullptr; + this->m_pShape = nullptr; } } void e2d::ENode::addChild(ENode * child, int order /* = 0 */) { WARN_IF(child == nullptr, "ENode::addChild NULL pointer exception."); - ASSERT(child->m_pParent == nullptr, "ENode already added. It can't be added again!"); if (child) { + ASSERT(child->m_pParent == nullptr, "ENode already added. It can't be added again!"); + for (ENode * parent = this; parent != nullptr; parent = parent->getParent()) { ASSERT(child != parent, "A ENode cannot be the child of his own children!"); @@ -623,9 +583,9 @@ std::vector& e2d::ENode::getChildren() return m_vChildren; } -size_t e2d::ENode::getChildrenCount() const +int e2d::ENode::getChildrenCount() const { - return m_vChildren.size(); + return static_cast(m_vChildren.size()); } e2d::ENode * e2d::ENode::getChild(const EString & name) @@ -634,15 +594,30 @@ e2d::ENode * e2d::ENode::getChild(const EString & name) unsigned int hash = name.hash(); - for (auto child = m_vChildren.begin(); child != m_vChildren.end(); child++) + for (auto child : m_vChildren) { // 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度 - if ((*child)->m_nHashName == hash && (*child)->m_sName == name) - return (*child); + if (child->m_nHashName == hash && child->m_sName == name) + return child; } return nullptr; } +std::vector e2d::ENode::getChildren(const EString & name) +{ + std::vector vChildren; + + WARN_IF(name.isEmpty(), "Invalid ENode name."); + + unsigned int hash = name.hash(); + + for (auto child : m_vChildren) + if (child->m_nHashName == hash && child->m_sName == name) + vChildren.push_back(child); + + return std::move(vChildren); +} + void e2d::ENode::removeFromParent() { if (m_pParent) @@ -653,7 +628,7 @@ void e2d::ENode::removeFromParent() bool e2d::ENode::removeChild(ENode * child) { - WARN_IF(child == nullptr, "ENode::removeChild NULL pointer exception."); + WARN_IF(child == nullptr, "ENode::removeChildren NULL pointer exception."); if (m_vChildren.empty()) { @@ -669,11 +644,16 @@ bool e2d::ENode::removeChild(ENode * child) { m_vChildren.erase(m_vChildren.begin() + i); child->m_pParent = nullptr; + if (child->m_pParentScene) { child->_setParentScene(nullptr); } - child->_onExit(); + if (child->m_bDisplayedInScene) + { + child->_onExit(); + } + child->release(); return true; } @@ -682,7 +662,7 @@ bool e2d::ENode::removeChild(ENode * child) return false; } -void e2d::ENode::removeChild(const EString & childName) +void e2d::ENode::removeChildren(const EString & childName) { WARN_IF(childName.isEmpty(), "Invalid ENode name."); @@ -706,9 +686,11 @@ void e2d::ENode::removeChild(const EString & childName) { child->_setParentScene(nullptr); } - child->_onExit(); + if (child->m_bDisplayedInScene) + { + child->_onExit(); + } child->release(); - return; } } } @@ -716,10 +698,13 @@ void e2d::ENode::removeChild(const EString & childName) void e2d::ENode::clearAllChildren() { // 所有节点的引用计数减一 - for (auto child = m_vChildren.begin(); child != m_vChildren.end(); child++) + for (auto child : m_vChildren) { - (*child)->_onExit(); - (*child)->release(); + if (child->m_bDisplayedInScene) + { + child->_onExit(); + } + child->release(); } // 清空储存节点的容器 m_vChildren.clear(); @@ -727,10 +712,14 @@ void e2d::ENode::clearAllChildren() void e2d::ENode::runAction(EAction * action) { - ASSERT( - (!action->getTarget()), - "The action is already running, it cannot run again!" + WARN_IF( + action->getTarget() != nullptr, + "The action is already running, The clone of the action will be created automatically!" ); + if (action->getTarget()) + { + action = action->clone(); + } action->setTarget(this); EActionManager::addAction(action); } @@ -778,13 +767,18 @@ bool e2d::ENode::isPointIn(EPoint point) } else { - for (auto child = m_vChildren.begin(); child != m_vChildren.end(); child++) - if ((*child)->isPointIn(point)) + for (auto child : m_vChildren) + if (child->isPointIn(point)) return true; } return false; } +void e2d::ENode::setAutoUpdate(bool bAutoUpdate) +{ + m_bAutoUpdate = bAutoUpdate; +} + void e2d::ENode::setDefaultPiovt(float defaultPiovtX, float defaultPiovtY) { s_fDefaultPiovtX = min(max(defaultPiovtX, 0), 1); @@ -817,17 +811,13 @@ void e2d::ENode::stopAllActions() void e2d::ENode::setVisiable(bool value) { m_bVisiable = value; - if (m_bDisplayedInScene == false) - { - this->_onEnter(); - } } void e2d::ENode::setName(const EString & name) { WARN_IF(name.isEmpty(), "Invalid ENode name."); - if (!name.isEmpty()) + if (!name.isEmpty() && m_sName != name) { // 保存节点名 m_sName = name; @@ -839,8 +829,8 @@ void e2d::ENode::setName(const EString & name) void e2d::ENode::_setParentScene(EScene * scene) { m_pParentScene = scene; - for (auto child = m_vChildren.begin(); child != m_vChildren.end(); child++) + for (auto child : m_vChildren) { - (*child)->_setParentScene(scene); + child->_setParentScene(scene); } } \ No newline at end of file diff --git a/core/Node/Sprite.cpp b/core/Node/Sprite.cpp index 07af97fa..c2fa61fd 100644 --- a/core/Node/Sprite.cpp +++ b/core/Node/Sprite.cpp @@ -2,62 +2,29 @@ e2d::ESprite::ESprite() - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pImage(nullptr) + : m_pImage(nullptr) { } e2d::ESprite::ESprite(EImage * image) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pImage(nullptr) + : m_pImage(nullptr) { loadFrom(image); } -e2d::ESprite::ESprite(EKeyframe * spriteFrame) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pImage(nullptr) -{ - loadFrom(spriteFrame); -} - e2d::ESprite::ESprite(LPCTSTR imageFileName) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pImage(nullptr) + : m_pImage(nullptr) { loadFrom(imageFileName); } e2d::ESprite::ESprite(LPCTSTR imageFileName, float x, float y, float width, float height) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pImage(nullptr) + : m_pImage(nullptr) { loadFrom(imageFileName); clip(x, y, width, height); } -e2d::ESprite::ESprite(LPCTSTR resourceName, LPCTSTR resourceType) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pImage(nullptr) -{ - loadFrom(resourceName, resourceType); -} - -e2d::ESprite::ESprite(LPCTSTR resourceName, LPCTSTR resourceType, float x, float y, float width, float height) - : m_fSourceClipX(0) - , m_fSourceClipY(0) - , m_pImage(nullptr) -{ - loadFrom(resourceName, resourceType); - clip(x, y, width, height); -} - e2d::ESprite::~ESprite() { SafeRelease(&m_pImage); @@ -71,9 +38,7 @@ void e2d::ESprite::loadFrom(EImage * image) m_pImage = image; m_pImage->retain(); - m_fSourceClipX = m_fSourceClipY = 0; - ENode::_setWidth(m_pImage->getSourceWidth()); - ENode::_setHeight(m_pImage->getSourceHeight()); + ENode::_setSize(m_pImage->getWidth(), m_pImage->getHeight()); } } @@ -82,49 +47,35 @@ void e2d::ESprite::loadFrom(LPCTSTR imageFileName) loadFrom(new EImage(imageFileName)); } -void e2d::ESprite::loadFrom(LPCTSTR resourceName, LPCTSTR resourceType) -{ - loadFrom(new EImage(resourceName, resourceType)); -} - -void e2d::ESprite::loadFrom(EImage * image, float x, float y, float width, float height) -{ - loadFrom(image); - clip(x, y, width, height); -} - -void e2d::ESprite::loadFrom(EKeyframe * frame) -{ - if (frame) - { - loadFrom(frame->m_pImage); - clip(frame->m_fSourceClipX, frame->m_fSourceClipY, frame->m_fSourceClipWidth, frame->m_fSourceClipHeight); - } -} - void e2d::ESprite::clip(float x, float y, float width, float height) { - m_fSourceClipX = min(max(x, 0), m_pImage->getSourceWidth()); - m_fSourceClipY = min(max(y, 0), m_pImage->getSourceHeight()); - ENode::_setWidth(min(max(width, 0), m_pImage->getSourceWidth() - m_fSourceClipX)); - ENode::_setHeight(min(max(height, 0), m_pImage->getSourceHeight() - m_fSourceClipY)); + m_pImage->clip(x, y, width, height); + ENode::_setSize( + min(max(width, 0), m_pImage->getSourceWidth() - m_pImage->getClipX()), + min(max(height, 0), m_pImage->getSourceHeight() - m_pImage->getClipY()) + ); +} + +e2d::EImage * e2d::ESprite::getImage() const +{ + return m_pImage; } void e2d::ESprite::onRender() { - if (m_pImage && m_pImage->_getBitmap()) + if (m_pImage && m_pImage->getBitmap()) { - // Draw bitmap + // 渲染图片 ERenderer::getRenderTarget()->DrawBitmap( - m_pImage->_getBitmap(), + m_pImage->getBitmap(), D2D1::RectF(0, 0, getRealWidth(), getRealHeight()), m_fDisplayOpacity, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1::RectF( - m_fSourceClipX, - m_fSourceClipY, - m_fSourceClipX + getRealWidth(), - m_fSourceClipY + getRealHeight() + m_pImage->getClipX(), + m_pImage->getClipY(), + m_pImage->getClipX() + getRealWidth(), + m_pImage->getClipY() + getRealHeight() ) ); } diff --git a/core/Node/Text.cpp b/core/Node/Text.cpp index 0be1f022..ac94ee63 100644 --- a/core/Node/Text.cpp +++ b/core/Node/Text.cpp @@ -120,7 +120,7 @@ void e2d::EText::_initTextLayout() // 未设置字体或空字符串时,文本宽高为 0 if (!m_pFont || m_sText.isEmpty()) { - this->_setHeight(0); + this->_setSize(0, 0); m_fWordWrappingWidth = 0; return; } diff --git a/core/Geometry/Circle.cpp b/core/Shape/Circle.cpp similarity index 97% rename from core/Geometry/Circle.cpp rename to core/Shape/Circle.cpp index ea014242..2dba943d 100644 --- a/core/Geometry/Circle.cpp +++ b/core/Shape/Circle.cpp @@ -1,4 +1,4 @@ -#include "..\egeometry.h" +#include "..\eshape.h" #include "..\enodes.h" e2d::ECircle::ECircle() diff --git a/core/Geometry/Ellipse.cpp b/core/Shape/Ellipse.cpp similarity index 97% rename from core/Geometry/Ellipse.cpp rename to core/Shape/Ellipse.cpp index 7e325ed1..2368a52d 100644 --- a/core/Geometry/Ellipse.cpp +++ b/core/Shape/Ellipse.cpp @@ -1,4 +1,4 @@ -#include "..\egeometry.h" +#include "..\eshape.h" #include "..\enodes.h" e2d::EEllipse::EEllipse() diff --git a/core/Geometry/Rectangle.cpp b/core/Shape/Rectangle.cpp similarity index 96% rename from core/Geometry/Rectangle.cpp rename to core/Shape/Rectangle.cpp index 01489e92..73485a0e 100644 --- a/core/Geometry/Rectangle.cpp +++ b/core/Shape/Rectangle.cpp @@ -1,4 +1,4 @@ -#include "..\egeometry.h" +#include "..\eshape.h" #include "..\enodes.h" e2d::ERectangle::ERectangle() diff --git a/core/Shape/Shape.cpp b/core/Shape/Shape.cpp new file mode 100644 index 00000000..3008c1aa --- /dev/null +++ b/core/Shape/Shape.cpp @@ -0,0 +1,120 @@ +#include "..\eshape.h" +#include "..\emanagers.h" +#include "..\enodes.h" + +e2d::EShape::EShape() + : m_nCategoryBitmask(0) + , m_nCollisionBitmask(0) + , m_bIsVisiable(true) + , m_nColor(EColor::RED) + , m_fOpacity(1) + , m_pParentNode(nullptr) + , m_pTransformedShape(nullptr) + , m_bEnable(true) +{ +} + +e2d::EShape::~EShape() +{ + SafeReleaseInterface(&m_pTransformedShape); +} + +e2d::ENode * e2d::EShape::getParentNode() const +{ + return m_pParentNode; +} + +UINT32 e2d::EShape::getCategoryBitmask() const +{ + return m_nCategoryBitmask; +} + +UINT32 e2d::EShape::getCollisionBitmask() const +{ + return m_nCollisionBitmask; +} + +void e2d::EShape::setCategoryBitmask(UINT32 mask) +{ + m_nCategoryBitmask = mask; +} + +void e2d::EShape::setCollisionBitmask(UINT32 mask) +{ + m_nCollisionBitmask = mask; +} + +void e2d::EShape::setEnable(bool bEnable) +{ + m_bEnable = bEnable; +} + +void e2d::EShape::setVisiable(bool bVisiable) +{ + m_bIsVisiable = bVisiable; +} + +void e2d::EShape::setColor(UINT32 color) +{ + m_nColor = color; +} + +void e2d::EShape::setOpacity(float opacity) +{ + m_fOpacity = min(max(opacity, 0), 1); +} + +void e2d::EShape::_render() +{ + if (m_pTransformedShape && m_bEnable) + { + ID2D1SolidColorBrush * pBrush = ERenderer::getSolidColorBrush(); + // 创建画刷 + ERenderer::getRenderTarget()->CreateSolidColorBrush( + D2D1::ColorF( + m_nColor, + m_fOpacity), + &pBrush + ); + // 绘制几何形状 + ERenderer::getRenderTarget()->DrawGeometry(m_pTransformedShape, pBrush); + } +} + +int e2d::EShape::getRelationWith(EShape * pShape) const +{ + if (m_pTransformedShape && pShape->m_pTransformedShape) + { + if (m_bEnable && pShape->m_bEnable) + { + D2D1_GEOMETRY_RELATION relation; + + m_pTransformedShape->CompareWithGeometry( + pShape->m_pTransformedShape, + D2D1::Matrix3x2F::Identity(), + &relation + ); + + return relation; + } + } + return 0; +} + +void e2d::EShape::_transform() +{ + if (m_pParentNode && m_bEnable) + { + // 释放原形状 + SafeReleaseInterface(&m_pTransformedShape); + + // 根据父节点转换几何图形 + ERenderer::getID2D1Factory()->CreateTransformedGeometry( + _getD2dGeometry(), + m_pParentNode->m_MatriFinal, + &m_pTransformedShape + ); + + EShapeManager::__updateShape(this); + } +} diff --git a/core/Tool/Music.cpp b/core/Tool/Music.cpp index 64e9a18a..947cbfa6 100644 --- a/core/Tool/Music.cpp +++ b/core/Tool/Music.cpp @@ -205,7 +205,7 @@ bool EMusic::isPlaying() } } -float e2d::EMusic::getVolume() const +float EMusic::getVolume() const { float fVolume = 0.0f; if (m_pSourceVoice) @@ -215,7 +215,7 @@ float e2d::EMusic::getVolume() const return fVolume; } -bool e2d::EMusic::setVolume(float fVolume) +bool EMusic::setVolume(float fVolume) { if (m_pSourceVoice) { @@ -224,7 +224,7 @@ bool e2d::EMusic::setVolume(float fVolume) return false; } -float e2d::EMusic::getFrequencyRatio() const +float EMusic::getFrequencyRatio() const { float fFrequencyRatio = 0.0f; if (m_pSourceVoice) @@ -234,7 +234,7 @@ float e2d::EMusic::getFrequencyRatio() const return fFrequencyRatio; } -bool e2d::EMusic::setFrequencyRatio(float fFrequencyRatio) +bool EMusic::setFrequencyRatio(float fFrequencyRatio) { if (m_pSourceVoice) { @@ -244,7 +244,7 @@ bool e2d::EMusic::setFrequencyRatio(float fFrequencyRatio) return false; } -IXAudio2SourceVoice * e2d::EMusic::getIXAudio2SourceVoice() const +IXAudio2SourceVoice * EMusic::getIXAudio2SourceVoice() const { return m_pSourceVoice; } diff --git a/core/eactions.h b/core/eactions.h index 82e98783..6d3e52ef 100644 --- a/core/eactions.h +++ b/core/eactions.h @@ -576,7 +576,7 @@ public: // 添加关键帧 void addKeyframe( - EKeyframe * frame /* 添加关键帧 */ + EImage * frame /* 添加关键帧 */ ); // 设置每一帧的时间间隔(秒) @@ -603,7 +603,7 @@ protected: protected: float m_fInterval; UINT m_nFrameIndex; - std::vector m_vFrames; + std::vector m_vFrames; }; diff --git a/core/easy2d.h b/core/easy2d.h index 94734ec8..22ed1ea5 100644 --- a/core/easy2d.h +++ b/core/easy2d.h @@ -1,5 +1,5 @@ /****************************************************** -* Easy2D Game Core +* Easy2D Game Framework * * Website: https://www.easy2d.cn * Source Code: https://github.com/Nomango/Easy2D @@ -12,8 +12,8 @@ #error 仅能在 C++ 环境下使用 Easy2D #endif -#if _MSC_VER < 1600 - #error Easy2D 不支持 Visual Studio 2010 以下版本 +#if _MSC_VER < 1700 + #error Easy2D 不支持 Visual Studio 2012 以下版本 #endif @@ -22,11 +22,10 @@ #include "ebase.h" #include "emanagers.h" #include "enodes.h" -#include "elisteners.h" #include "etools.h" #include "eactions.h" #include "etransitions.h" -#include "egeometry.h" +#include "eshape.h" #if defined(DEBUG) || defined(_DEBUG) diff --git a/core/ecommon.h b/core/ecommon.h index fa8666fe..f6f53bb1 100644 --- a/core/ecommon.h +++ b/core/ecommon.h @@ -86,6 +86,7 @@ struct ESize } }; + // 字符串 class EString { @@ -219,31 +220,6 @@ private: }; -// 二维向量 -typedef EPoint EVector2; - -// 定时器回调函数(参数为该定时器被调用的次数,从 0 开始) -typedef std::function TimerCallback; - -// 按钮点击回调函数 -typedef std::function BtnClkCallback; - -// 物理世界消息监听器回调函数 -typedef std::function PhysLsnrCallback; - -// 碰撞消息监听器回调函数 -typedef PhysLsnrCallback ClsLsnrCallback; - -template -inline void SafeDelete(T** p) { if (*p) { delete *p; *p = nullptr; } } - -template -inline void SafeRelease(Obj** p) { if (*p) { (*p)->release(); *p = nullptr; } } - -template -inline void SafeReleaseInterface(Interface **pp) { if (*pp != nullptr) { (*pp)->Release(); (*pp) = nullptr; } } - - // 颜色 class EColor { @@ -418,13 +394,11 @@ public: }; -class EGeometry; - -// 物理消息 -class EPhysicsEvent +// 形状交集关系 +class ERelation { public: - enum INTERSECT_RELATION + enum VALUE { UNKNOWN = 0, /* 关系不确定 */ DISJOINT = 1, /* 没有交集 */ @@ -432,25 +406,12 @@ public: CONTAINS = 3, /* 完全包含 */ OVERLAP = 4 /* 部分重叠 */ }; - - // 获取当前物理碰撞消息类型 - static INTERSECT_RELATION getMsg(); - - // 获取主动方 - static EGeometry * getActiveGeometry(); - - // 获取被动方 - static EGeometry * getPassiveGeometry(); - -public: - static INTERSECT_RELATION s_nRelation; - static EGeometry * s_pActiveGeometry; - static EGeometry * s_pPassiveGeometry; }; class EObjectManager; +// 基础对象 class EObject { friend EObjectManager; @@ -547,41 +508,61 @@ protected: }; -class ESprite; - +// 图片 class EImage : public EObject { - friend ESprite; - public: // 创建一个空的图片 EImage(); // 从本地文件中读取资源 EImage( - LPCTSTR fileName + LPCTSTR strFilePath /* 图片文件路径 */ ); - // 读取程序资源 + // 从本地文件中读取资源 EImage( - LPCTSTR resourceName, - LPCTSTR resourceType + LPCTSTR strFilePath,/* 图片文件路径 */ + float nClipX, /* 裁剪位置 X 坐标 */ + float nClipY, /* 裁剪位置 Y 坐标 */ + float nClipWidth, /* 裁剪宽度 */ + float nClipHeight /* 裁剪高度 */ ); virtual ~EImage(); - // 从本地文件中读取资源 - void loadFromFile( - const EString & fileName + // 裁剪图片 + void clip( + float nClipX, /* 裁剪位置 X 坐标 */ + float nClipY, /* 裁剪位置 Y 坐标 */ + float nClipWidth, /* 裁剪宽度 */ + float nClipHeight /* 裁剪高度 */ ); - // 读取程序资源 - void loadFromResource( - LPCTSTR resourceName, - LPCTSTR resourceType + // 从本地文件中读取图片 + void loadFrom( + const EString & strFilePath ); + // 从本地文件中读取图片并裁剪 + void loadFrom( + const EString & strFilePath,/* 图片文件路径 */ + float nClipX, /* 裁剪位置 X 坐标 */ + float nClipY, /* 裁剪位置 Y 坐标 */ + float nClipWidth, /* 裁剪宽度 */ + float nClipHeight /* 裁剪高度 */ + ); + + // 获取宽度 + virtual float getWidth() const; + + // 获取高度 + virtual float getHeight() const; + + // 获取大小 + virtual ESize getSize() const; + // 获取源图片宽度 virtual float getSourceWidth() const; @@ -590,113 +571,33 @@ public: // 获取源图片大小 virtual ESize getSourceSize() const; + + // 获取裁剪位置 X 坐标 + virtual float getClipX() const; + + // 获取裁剪位置 Y 坐标 + virtual float getClipY() const; + + // 获取裁剪位置 + virtual EPoint getClipPos() const; + + // 获取 ID2D1Bitmap 对象 + ID2D1Bitmap * getBitmap(); // 预加载资源 static bool preload( - const EString & fileName - ); - - // 预加载资源 - static bool preload( - LPCTSTR resourceName, - LPCTSTR resourceType + const EString & sFileName /* 图片文件路径 */ ); // 清空缓存 static void clearCache(); -protected: - ID2D1Bitmap * _getBitmap(); - -protected: - ID2D1Bitmap * m_pBitmap; -}; - - -class EKeyframe : - public EObject -{ - friend ESprite; - -public: - // 创建空的关键帧 - EKeyframe(); - - // 创建空的关键帧 - EKeyframe( - EImage * texture - ); - - // 创建空的关键帧 - EKeyframe( - const EString & imageFileName - ); - - // 创建空的关键帧 - EKeyframe( - LPCTSTR resourceName, - LPCTSTR resourceType - ); - - // 创建空的关键帧 - EKeyframe( - EImage * texture, - float x, - float y, - float width, - float height - ); - - // 创建空的关键帧 - EKeyframe( - const EString & imageFileName, - float x, - float y, - float width, - float height - ); - - // 创建空的关键帧 - EKeyframe( - LPCTSTR resourceName, - LPCTSTR resourceType, - float x, - float y, - float width, - float height - ); - - virtual ~EKeyframe(); - - // 获取宽度 - float getWidth() const; - - // 获取高度 - float getHeight() const; - - // 获取图片 - EImage * getImage() const; - -protected: - // 修改图片 - void _setImage( - EImage * texture - ); - - // 裁剪图片 - void _clipTexture( - float x, - float y, - float width, - float height - ); - protected: float m_fSourceClipX; float m_fSourceClipY; float m_fSourceClipWidth; float m_fSourceClipHeight; - EImage * m_pImage; + ID2D1Bitmap * m_pBitmap; }; @@ -721,11 +622,11 @@ public: // 重写这个函数,它将在离开这个场景时自动执行 virtual void onExit() {} - // 重写这个函数,它将在窗口激活时执行 - virtual bool onActivate() { return false; } - - // 重写这个函数,它将在窗口非激活时执行 - virtual bool onInactive() { return false; } + // 重写这个函数,它将在碰撞发生时自动执行 + virtual void onCollide( + ENode * pActiveNode, /* 主动发生碰撞的节点 */ + ENode * pPassiveNode /* 被动发生碰撞的节点 */ + ) {} // 重写这个函数,它将在关闭窗口时执行 virtual bool onCloseWindow() { return true; } @@ -733,7 +634,12 @@ public: // 重写这个函数,它将在每一帧画面刷新时执行 virtual void onUpdate() {} - // 添加子节点到场景 + // 开启或禁用 onUpdate 函数 + virtual void setAutoUpdate( + bool bAutoUpdate + ); + + // 添加节点到场景 void add( ENode * child, int zOrder = 0 @@ -744,35 +650,11 @@ public: ENode * child ); - // 删除相同名称的子节点 - void remove( - const EString &childName - ); - - // 获取所有子节点 - std::vector getChildren(); - - // 获取子节点数量 - size_t getChildrenCount() const; - - // 根据名称获取子节点 - ENode * getChild( - const EString &childName - ); - // 获取根节点 ENode * getRoot() const; - // 清空所有子成员 - void clearAllChildren(); - - // 执行动画 - void runAction( - EAction * action - ); - // 开启几何图形的渲染 - void setGeometryVisiable( + void setShapeVisiable( bool visiable ); @@ -784,10 +666,30 @@ protected: void _update(); protected: + bool m_bAutoUpdate; bool m_bSortNeeded; bool m_bWillSave; - bool m_bGeometryVisiable; + bool m_bShapeVisiable; ENode * m_pRoot; }; + +// 二维向量 +typedef EPoint EVector2; + +// 定时器回调函数(参数为该定时器被调用的次数,从 0 开始) +typedef std::function TimerCallback; + +// 按钮点击回调函数 +typedef std::function BtnClkCallback; + +template +inline void SafeDelete(T** p) { if (*p) { delete *p; *p = nullptr; } } + +template +inline void SafeRelease(Obj** p) { if (*p) { (*p)->release(); *p = nullptr; } } + +template +inline void SafeReleaseInterface(Interface **pp) { if (*pp != nullptr) { (*pp)->Release(); (*pp) = nullptr; } } + } \ No newline at end of file diff --git a/core/elisteners.h b/core/elisteners.h deleted file mode 100644 index 140d6425..00000000 --- a/core/elisteners.h +++ /dev/null @@ -1,152 +0,0 @@ -#pragma once -#include "ebase.h" -#include "egeometry.h" - -namespace e2d -{ - -class ENode; -class EPhysicsManager; - -// 监听器 -class EListener : - public EObject -{ -public: - EListener(); - - EListener( - const EString &name - ); - - // 获取监听器状态 - bool isRunning() const; - - // 启动监听 - void start(); - - // 停止监听 - void stop(); - - // 获取监听器名称 - EString getName() const; - - // 获取监听器所在节点 - ENode * getParentNode() const; - - // 设置监听器名称 - void setName( - const EString &name - ); - - // 设置监听器吞噬消息 - void setSwallow( - bool bSwallow - ); - - // 设置监听器在游戏暂停时继续工作 - void setAlwaysWorking( - bool bAlways - ); - - // 绑定监听器到场景 - virtual void bindWith( - EScene * pParentScene - ) = 0; - - // 绑定监听器到节点 - virtual void bindWith( - ENode * pParentNode - ) = 0; - -protected: - // 执行监听器回调函数 - virtual void _callOn() = 0; - - // 获取监听器状态是否就绪 - virtual bool _isReady() const; - -protected: - EString m_sName; - bool m_bRunning; - bool m_bAlways; - bool m_bSwallow; - ENode * m_pParentNode; -}; - - -// 物理世界消息监听器 -class EListenerPhysics : - public EListener -{ - friend EPhysicsManager; - -public: - EListenerPhysics(); - - EListenerPhysics( - const EString &name - ); - - EListenerPhysics( - const PhysLsnrCallback &callback - ); - - EListenerPhysics( - const EString &name, - const PhysLsnrCallback &callback - ); - - // 设置监听器回调函数 - void setCallback( - const PhysLsnrCallback &callback - ); - - // 将监听器与场景绑定 - virtual void bindWith( - EScene * pParentScene - ) override; - - // 将监听器与节点绑定 - virtual void bindWith( - ENode * pParentNode - ) override; - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - PhysLsnrCallback m_Callback; -}; - - -// 几何体冲突消息监听器 -class EListenerPhysicsCollision : - public EListenerPhysics -{ -public: - EListenerPhysicsCollision(); - - EListenerPhysicsCollision( - const EString &name - ); - - EListenerPhysicsCollision( - const ClsLsnrCallback &callback - ); - - EListenerPhysicsCollision( - const EString &name, - const ClsLsnrCallback &callback - ); - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - ClsLsnrCallback m_Callback; -}; - -} \ No newline at end of file diff --git a/core/emanagers.h b/core/emanagers.h index eb4416b3..14e193f5 100644 --- a/core/emanagers.h +++ b/core/emanagers.h @@ -13,7 +13,7 @@ class ENode; class ETimer; class EAction; class EMusic; -class EGeometry; +class EShape; class ETransition; class EListenerPhysics; @@ -81,7 +81,6 @@ private: class ETimerManager { friend EGame; - friend EScene; friend ENode; public: @@ -156,7 +155,6 @@ private: class EActionManager { friend EGame; - friend EScene; friend ENode; public: @@ -210,7 +208,7 @@ class EMusicManager public: // 添加音乐文件 - static EMusic * add( + static bool add( const EString & strFilePath /* 音乐文件路径 */ ); @@ -243,93 +241,27 @@ private: }; -class EPhysicsManager +class EShapeManager { friend EGame; - friend EScene; friend ENode; - friend EGeometry; - -public: - // 将监听器与场景绑定 - static void bindListener( - EListenerPhysics * listener, - EScene * pParentScene - ); - - // 将监听器与节点绑定 - static void bindListener( - EListenerPhysics * listener, - ENode * pParentNode - ); - - // 启动具有相同名称的监听器 - static void startListeners( - const EString &name - ); - - // 停止具有相同名称的监听器 - static void stopListeners( - const EString &name - ); - - // 删除具有相同名称的监听器 - static void delListeners( - const EString &name - ); - - // 启动绑定在场景及其子节点上的所有监听器 - static void startAllListenersBindedWith( - EScene * pParentScene - ); - - // 停止绑定在场景及其子节点上的所有监听器 - static void stopAllListenersBindedWith( - EScene * pParentScene - ); - - // 启动绑定在节点上的所有监听器 - static void startAllListenersBindedWith( - ENode * pParentNode - ); - - // 停止绑定在节点上的所有监听器 - static void stopAllListenersBindedWith( - ENode * pParentNode - ); - - // 启动所有监听器 - static void startAllListeners(); - - // 停止所有监听器 - static void stopAllListeners(); + friend EShape; private: - // 清空监听器管理器 - static void _clearManager(); + // 更新形状 + static void __updateShape( + EShape * pActiveShape + ); // 添加形状 - static void _addGeometry( - EGeometry * geometry + static void __addShape( + EShape * pShape ); // 删除已绑定的形状 - static void _delGeometry( - EGeometry * geometry + static void __delShape( + EShape * pShape ); - - // 清空绑定在节点上的所有监听器 - static void _clearAllListenersBindedWith( - ENode * pParentNode - ); - - // 几何图形判断程序 - static void PhysicsGeometryProc( - EGeometry * pActiveGeometry - ); - - // 物理碰撞监听器执行程序 - static void PhysicsListenerProc(); }; } \ No newline at end of file diff --git a/core/enodes.h b/core/enodes.h index 8df00389..f7d831a6 100644 --- a/core/enodes.h +++ b/core/enodes.h @@ -4,48 +4,49 @@ namespace e2d { -class EText; -class ESprite; + class EAction; -class EButton; -class EButtonToggle; -class EGeometry; -class EMenu; +class EShape; class ETransition; class ENode : public EObject { friend EScene; - friend EButton; - friend EButtonToggle; - friend EGeometry; + friend EShape; friend ETransition; public: ENode(); - ENode( - const EString & name - ); - virtual ~ENode(); - // 节点进入场景时,这个函数将自动运行 - virtual void onEnter() {} - - // 节点离开场景时,这个函数将自动运行 - virtual void onExit() {} - - // 每一帧画面刷新时,这个函数将自动运行 + // 更新节点 virtual void onUpdate() {} - // 渲染节点时,这个函数将自动运行 + // 渲染节点 virtual void onRender() {} + // 碰撞处理 + virtual void onCollide( + ENode* pCollisionNode, /* 发生碰撞的节点 */ + int nRelation /* 碰撞关系,取值为 ERelation::VALUE 中的一种 */ + ) {} + + // 进入场景时执行 + virtual void onEnter() {} + + // 离开场景时执行 + virtual void onExit() {} + // 获取节点显示状态 virtual bool isVisiable() const; + // 判断点是否在节点内 + virtual bool isPointIn( + EPoint point + ); + // 获取节点名称 virtual EString getName() const; @@ -103,28 +104,57 @@ public: // 获取节点透明度 virtual float getOpacity() const; + // 获取节点形状 + virtual EShape * getShape() const; + // 获取父节点 virtual ENode * getParent() const; // 获取节点所在场景 virtual EScene * getParentScene() const; - // 获取所有子节点 - virtual std::vector &getChildren(); - - // 获取子节点数量 - virtual size_t getChildrenCount() const; - - // 根据名字获取子节点 + // 获取名称相同的子节点 virtual ENode * getChild( const EString & name ); + // 获取所有名称相同的子节点 + virtual std::vector getChildren( + const EString & name + ); + + // 获取所有子节点 + virtual std::vector &getChildren(); + + // 获取子节点数量 + virtual int getChildrenCount() const; + + // 移除子节点 + virtual bool removeChild( + ENode * child + ); + + // 移除所有名称相同的子节点 + virtual void removeChildren( + const EString & childName + ); + + // 从父节点移除 + virtual void removeFromParent(); + + // 移除所有节点 + virtual void clearAllChildren(); + // 设置节点是否显示 virtual void setVisiable( bool value ); + // 开启或禁用 onUpdate 函数 + virtual void setAutoUpdate( + bool bAutoUpdate + ); + // 设置节点名称 virtual void setName( const EString & name @@ -254,8 +284,8 @@ public: ); // 设置节点形状 - virtual void setGeometry( - EGeometry * geometry + virtual void setShape( + EShape * pShape ); // 添加子节点 @@ -264,22 +294,6 @@ public: int order = 0 ); - // 从父节点移除 - virtual void removeFromParent(); - - // 移除子节点 - virtual bool removeChild( - ENode * child - ); - - // 移除子节点 - virtual void removeChild( - const EString & childName - ); - - // 移除所有节点 - virtual void clearAllChildren(); - // 执行动画 virtual void runAction( EAction * action @@ -309,11 +323,6 @@ public: // 停止所有动画 virtual void stopAllActions(); - // 判断点是否在节点内 - virtual bool isPointIn( - EPoint point - ); - // 修改节点的默认中心点位置 static void setDefaultPiovt( float defaultPiovtX, @@ -328,7 +337,7 @@ protected: virtual void _render(); // 渲染几何图形 - virtual void _drawGeometry(); + virtual void _drawShape(); // 节点被添加到场景时的执行程序 virtual void _onEnter(); @@ -336,9 +345,6 @@ protected: // 节点从场景中消失时的执行程序 virtual void _onExit(); - // 子节点排序 - void _sortChildren(); - // 设置节点所在场景 virtual void _setParentScene( EScene * scene @@ -359,22 +365,7 @@ protected: // 更新节点透明度 static void _updateOpacity(ENode * node); - // 设置节点宽度 - virtual void _setWidth( - float width - ); - - // 设置节点高度 - virtual void _setHeight( - float height - ); - - // 设置节点大小 - virtual void _setSize( - const ESize & size - ); - - // 设置节点大小 + // 修改节点大小 virtual void _setSize( float width, float height @@ -396,15 +387,16 @@ protected: float m_fPivotY; int m_nOrder; bool m_bVisiable; + bool m_bAutoUpdate; bool m_bDisplayedInScene; bool m_bSortChildrenNeeded; bool m_bTransformNeeded; - EGeometry * m_pGeometry; + EShape * m_pShape; EScene * m_pParentScene; ENode * m_pParent; D2D1::Matrix3x2F m_MatriInitial; D2D1::Matrix3x2F m_MatriFinal; - std::vector m_vChildren; + std::vector m_vChildren; }; @@ -415,16 +407,11 @@ public: // 创建一个空精灵 ESprite(); - // 从文理资源创建精灵 + // 从 EImage 对象创建精灵 ESprite( EImage * image ); - // 从关键帧创建精灵 - ESprite( - EKeyframe * spriteFrame - ); - // 从文件图片创建精灵 ESprite( LPCTSTR imageFileName @@ -439,68 +426,33 @@ public: float height ); - // 从资源图片创建精灵 - ESprite( - LPCTSTR resourceName, - LPCTSTR resourceType - ); - - // 从资源图片创建精灵并裁剪 - ESprite( - LPCTSTR resourceName, - LPCTSTR resourceType, - float x, - float y, - float width, - float height - ); - virtual ~ESprite(); // 加载精灵图片 - void loadFrom( + virtual void loadFrom( EImage * texture ); // 从本地文件加载图片 - void loadFrom( + virtual void loadFrom( LPCTSTR imageFileName ); - // 从资源加载图片 - void loadFrom( - LPCTSTR resourceName, - LPCTSTR resourceType - ); - - // 加载图片并裁剪 - void loadFrom( - EImage * image, - float x, - float y, - float width, - float height - ); - - // 从关键帧加载资源 - void loadFrom( - EKeyframe * frame - ); - // 裁剪图片 - void clip( + virtual void clip( float x, float y, float width, float height ); + // 获取 EImage 对象 + virtual EImage * getImage() const; + // 渲染精灵 virtual void onRender() override; protected: - float m_fSourceClipX; - float m_fSourceClipY; EImage * m_pImage; }; @@ -585,8 +537,6 @@ protected: class EButton : public ENode { - friend EMenu; - public: // 创建一个空按钮 EButton(); diff --git a/core/egeometry.h b/core/eshape.h similarity index 75% rename from core/egeometry.h rename to core/eshape.h index 6cbe436c..06f79850 100644 --- a/core/egeometry.h +++ b/core/eshape.h @@ -5,20 +5,25 @@ namespace e2d { -class EPhysicsManager; +class EShapeManager; class ENode; -class EGeometry : +class EShape : public EObject { - friend EPhysicsManager; + friend EShapeManager; friend ENode; public: - EGeometry(); + EShape(); - virtual ~EGeometry(); + virtual ~EShape(); + + // 判断两形状的交集关系 + virtual int getRelationWith( + EShape * pShape + ) const; // 获取父节点 ENode * getParentNode() const; @@ -39,7 +44,12 @@ public: UINT32 mask ); - // 设置几何形状的可见性 + // 启用或关闭该形状 + virtual void setEnable( + bool bEnable + ); + + // 设置形状的可见性 void setVisiable( bool bVisiable ); @@ -55,38 +65,35 @@ public: ); protected: - // 判断两形状的交集关系 - virtual EPhysicsEvent::INTERSECT_RELATION _intersectWith( - EGeometry * pGeometry - ); - // 转换形状 virtual void _transform(); - // 渲染几何图形 + // 渲染形状 virtual void _render(); + // 获取 ID2D1Geometry 对象 virtual ID2D1Geometry * _getD2dGeometry() const = 0; protected: + bool m_bEnable; bool m_bIsVisiable; UINT32 m_nCategoryBitmask; UINT32 m_nCollisionBitmask; UINT32 m_nColor; float m_fOpacity; ENode * m_pParentNode; - ID2D1TransformedGeometry * m_pTransformedGeometry; + ID2D1TransformedGeometry * m_pTransformedShape; }; class ERectangle : - public EGeometry + public EShape { public: - // 创建一个空几何矩形 + // 创建一个空矩形 ERectangle(); - // 根据左上角坐标和宽高创建几何矩形 + // 根据左上角坐标和宽高创建矩形 ERectangle( float x, float y, @@ -94,7 +101,7 @@ public: float height ); - // 创建一个和节点位置大小相同的几何矩形 + // 创建一个和节点位置大小相同的矩形 ERectangle( ENode * node ); @@ -117,19 +124,19 @@ protected: class ECircle : - public EGeometry + public EShape { public: - // 创建一个空的几何圆形 + // 创建一个空的圆形 ECircle(); - // 根据圆心和半径创建几何圆形 + // 根据圆心和半径创建圆形 ECircle( EPoint center, float radius ); - // 创建一个和节点位置大小相同的几何圆形 + // 创建一个和节点位置大小相同的圆形 ECircle( ENode * node ); @@ -150,20 +157,20 @@ protected: class EEllipse : - public EGeometry + public EShape { public: - // 创建一个空的几何椭圆 + // 创建一个空的椭圆 EEllipse(); - // 根据圆心和半径创建几何椭圆 + // 根据圆心和半径创建椭圆 EEllipse( EPoint center, float radiusX, float radiusY ); - // 创建一个和节点位置大小相同的几何椭圆 + // 创建一个和节点位置大小相同的椭圆 EEllipse( ENode * node ); diff --git a/core/etools.h b/core/etools.h index db3f7127..1e5cc61c 100644 --- a/core/etools.h +++ b/core/etools.h @@ -217,14 +217,13 @@ public: // 音乐播放器 class EMusic - : public EObject { friend EMusicManager; public: // 播放 bool play( - int nLoopCount = 0 /* 重复播放次数 */ + int nLoopCount = 0 /* 重复播放次数,设置为 255 时循环播放 */ ); // 暂停 diff --git a/project/vs2012/Easy2D.vcxproj b/project/vs2012/Easy2D.vcxproj index 324f8da0..86b65005 100644 --- a/project/vs2012/Easy2D.vcxproj +++ b/project/vs2012/Easy2D.vcxproj @@ -14,12 +14,10 @@ - - - + @@ -48,22 +46,14 @@ - - - - - - - - - + - + @@ -71,7 +61,12 @@ + + + + + diff --git a/project/vs2012/Easy2D.vcxproj.filters b/project/vs2012/Easy2D.vcxproj.filters index c11d1034..77b099cd 100644 --- a/project/vs2012/Easy2D.vcxproj.filters +++ b/project/vs2012/Easy2D.vcxproj.filters @@ -10,18 +10,9 @@ {08126b0c-d139-48f9-8559-3d9d9e3a5940} - - {a00a6f30-ec6b-42be-93a2-c540466670a8} - {a8185fe2-5477-4293-97d6-d84f27d354bb} - - {dfaa8954-50d7-49c5-8aa6-7232c6d5c557} - - - {9b2673ff-9077-4d74-b7ec-b435e5540b66} - {70412fec-4c60-425b-81c9-4547e5a1b78a} @@ -31,19 +22,20 @@ {337d5a0f-60fd-473a-83da-b2a3515affd9} + + {dfaa8954-50d7-49c5-8aa6-7232c6d5c557} + - - - + @@ -118,9 +110,6 @@ Common - - Common - Common @@ -130,45 +119,18 @@ Common - - Event - Manager Manager - - Manager - Manager Manager - - Geometry - - - Geometry - - - Geometry - - - Geometry - - - Listener - - - Listener - - - Listener - Tool @@ -211,5 +173,26 @@ Node + + Shape + + + Shape + + + Shape + + + Shape + + + Manager + + + Manager + + + Tool + \ No newline at end of file diff --git a/project/vs2013/Easy2D.vcxproj b/project/vs2013/Easy2D.vcxproj index abf975a4..700725b3 100644 --- a/project/vs2013/Easy2D.vcxproj +++ b/project/vs2013/Easy2D.vcxproj @@ -89,11 +89,10 @@ - - + @@ -122,22 +121,14 @@ - - - - - - - - - + - + @@ -145,7 +136,12 @@ + + + + + diff --git a/project/vs2013/Easy2D.vcxproj.filters b/project/vs2013/Easy2D.vcxproj.filters index c11d1034..a73afb1e 100644 --- a/project/vs2013/Easy2D.vcxproj.filters +++ b/project/vs2013/Easy2D.vcxproj.filters @@ -10,18 +10,9 @@ {08126b0c-d139-48f9-8559-3d9d9e3a5940} - - {a00a6f30-ec6b-42be-93a2-c540466670a8} - {a8185fe2-5477-4293-97d6-d84f27d354bb} - - {dfaa8954-50d7-49c5-8aa6-7232c6d5c557} - - - {9b2673ff-9077-4d74-b7ec-b435e5540b66} - {70412fec-4c60-425b-81c9-4547e5a1b78a} @@ -31,19 +22,21 @@ {337d5a0f-60fd-473a-83da-b2a3515affd9} + + {dfaa8954-50d7-49c5-8aa6-7232c6d5c557} + - - + @@ -118,9 +111,6 @@ Common - - Common - Common @@ -130,45 +120,18 @@ Common - - Event - Manager Manager - - Manager - Manager Manager - - Geometry - - - Geometry - - - Geometry - - - Geometry - - - Listener - - - Listener - - - Listener - Tool @@ -211,5 +174,26 @@ Node + + Shape + + + Shape + + + Shape + + + Shape + + + Manager + + + Tool + + + Manager + \ No newline at end of file diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index 28bb3273..50224617 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -214,22 +214,13 @@ - - - - - - - - - - + @@ -238,6 +229,10 @@ + + + + @@ -253,8 +248,7 @@ - - + diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters index 837392cc..131acbf8 100644 --- a/project/vs2017/Easy2D.vcxproj.filters +++ b/project/vs2017/Easy2D.vcxproj.filters @@ -19,17 +19,11 @@ {9031e36b-fa85-4b4e-8e80-657c7e68f283} - - {b9bb1728-5106-4574-998e-8564b49cb4a1} - - - {d5f86335-f3a0-450d-92a3-7edd9348d995} - {be5d9314-b00a-4f11-bd2a-1f720dc32407} - - {6d0b43af-2432-4221-b572-4bef331ae10e} + + {d5f86335-f3a0-450d-92a3-7edd9348d995} @@ -105,9 +99,6 @@ Common - - Common - Common @@ -117,39 +108,12 @@ Common - - Event - - - Geometry - - - Geometry - - - Geometry - - - Geometry - - - Listener - - - Listener - - - Listener - Manager Manager - - Manager - Manager @@ -204,6 +168,21 @@ Manager + + Manager + + + Shape + + + Shape + + + Shape + + + Shape + @@ -214,8 +193,7 @@ - - + \ No newline at end of file