rename some protected functions
This commit is contained in:
parent
49783dbf8d
commit
627f04d7ce
|
|
@ -115,7 +115,7 @@ int e2d::Game::run()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ObjectManager::__flush(); // 刷新内存池
|
ObjectManager::__clearObjects(); // 刷新内存池
|
||||||
Time::__sleep(); // 挂起线程
|
Time::__sleep(); // 挂起线程
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -164,7 +164,7 @@ void e2d::Game::uninit()
|
||||||
// 清空图片缓存
|
// 清空图片缓存
|
||||||
Image::clearCache();
|
Image::clearCache();
|
||||||
// 刷新内存池
|
// 刷新内存池
|
||||||
ObjectManager::__flush();
|
ObjectManager::__clearObjects();
|
||||||
// 删除渲染相关资源
|
// 删除渲染相关资源
|
||||||
Renderer::__discardResources();
|
Renderer::__discardResources();
|
||||||
// 销毁窗口
|
// 销毁窗口
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,27 @@
|
||||||
#include "..\ebase.h"
|
#include "..\ebase.h"
|
||||||
#include "..\emanagers.h"
|
#include "..\emanagers.h"
|
||||||
|
|
||||||
e2d::Obj::Obj()
|
e2d::Object::Object()
|
||||||
: m_nRefCount(0)
|
: m_nRefCount(0)
|
||||||
, m_bManaged(false)
|
, m_bManaged(false)
|
||||||
{
|
{
|
||||||
ObjectManager::preload(this); // 将该对象放入释放池中
|
ObjectManager::add(this); // 将该对象放入释放池中
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::Obj::~Obj()
|
e2d::Object::~Object()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// 引用计数加一
|
// 引用计数加一
|
||||||
void e2d::Obj::retain()
|
void e2d::Object::retain()
|
||||||
{
|
{
|
||||||
m_nRefCount++;
|
m_nRefCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 引用计数减一
|
// 引用计数减一
|
||||||
void e2d::Obj::release()
|
void e2d::Object::release()
|
||||||
{
|
{
|
||||||
m_nRefCount--;
|
m_nRefCount--;
|
||||||
// 通知对象管理池刷新
|
// 通知对象管理池刷新
|
||||||
ObjectManager::notifyFlush();
|
ObjectManager::clear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ void e2d::Scene::setAutoUpdate(bool bAutoUpdate)
|
||||||
m_bAutoUpdate = bAutoUpdate;
|
m_bAutoUpdate = bAutoUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Scene::preload(Node * child, int order /* = 0 */)
|
void e2d::Scene::add(Node * child, int order /* = 0 */)
|
||||||
{
|
{
|
||||||
m_pRoot->addChild(child, order);
|
m_pRoot->addChild(child, order);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,17 @@
|
||||||
// 让其自动释放
|
// 让其自动释放
|
||||||
|
|
||||||
// 释放池容器
|
// 释放池容器
|
||||||
static std::vector<e2d::Obj*> s_vPool;
|
static std::vector<e2d::Object*> s_vPool;
|
||||||
// 标志释放池执行状态
|
// 标志释放池执行状态
|
||||||
static bool s_bNotifyed = false;
|
static bool s_bNotifyed = false;
|
||||||
|
|
||||||
void e2d::ObjectManager::__flush()
|
void e2d::ObjectManager::__clearObjects()
|
||||||
{
|
{
|
||||||
if (!s_bNotifyed) return;
|
if (!s_bNotifyed) return;
|
||||||
|
|
||||||
s_bNotifyed = false;
|
s_bNotifyed = false;
|
||||||
// 创建迭代器
|
// 创建迭代器
|
||||||
static std::vector<e2d::Obj*>::iterator iter;
|
static std::vector<e2d::Object*>::iterator iter;
|
||||||
// 循环遍历容器中的所有对象
|
// 循环遍历容器中的所有对象
|
||||||
for (iter = s_vPool.begin(); iter != s_vPool.end();)
|
for (iter = s_vPool.begin(); iter != s_vPool.end();)
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +37,7 @@ void e2d::ObjectManager::__flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::ObjectManager::preload(e2d::Obj * nptr)
|
void e2d::ObjectManager::add(e2d::Object * nptr)
|
||||||
{
|
{
|
||||||
if (!nptr->m_bManaged)
|
if (!nptr->m_bManaged)
|
||||||
{
|
{
|
||||||
|
|
@ -46,7 +46,7 @@ void e2d::ObjectManager::preload(e2d::Obj * nptr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::ObjectManager::notifyFlush()
|
void e2d::ObjectManager::clear()
|
||||||
{
|
{
|
||||||
s_bNotifyed = true;
|
s_bNotifyed = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ static e2d::Scene * s_pNextScene = nullptr;
|
||||||
static e2d::Transition * s_pTransition = nullptr;
|
static e2d::Transition * s_pTransition = nullptr;
|
||||||
static std::stack<e2d::Scene*> s_SceneStack;
|
static std::stack<e2d::Scene*> s_SceneStack;
|
||||||
|
|
||||||
void e2d::SceneManager::enterScene(Scene * scene, Transition * transition /* = nullptr */, bool saveCurrentScene /* = true */)
|
void e2d::SceneManager::enter(Scene * scene, Transition * transition /* = nullptr */, bool saveCurrentScene /* = true */)
|
||||||
{
|
{
|
||||||
ASSERT(scene != nullptr, "Next scene NULL pointer exception!");
|
ASSERT(scene != nullptr, "Next scene NULL pointer exception!");
|
||||||
scene->retain();
|
scene->retain();
|
||||||
|
|
@ -33,7 +33,7 @@ void e2d::SceneManager::enterScene(Scene * scene, Transition * transition /* = n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::SceneManager::backScene(Transition * transition /* = nullptr */)
|
void e2d::SceneManager::back(Transition * transition /* = nullptr */)
|
||||||
{
|
{
|
||||||
// 栈为空时,调用返回场景函数失败
|
// 栈为空时,调用返回场景函数失败
|
||||||
WARN_IF(s_SceneStack.size() == 0, "Scene stack now is empty!");
|
WARN_IF(s_SceneStack.size() == 0, "Scene stack now is empty!");
|
||||||
|
|
@ -61,7 +61,7 @@ void e2d::SceneManager::backScene(Transition * transition /* = nullptr */)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::SceneManager::clearScene()
|
void e2d::SceneManager::clear()
|
||||||
{
|
{
|
||||||
// 清空场景栈
|
// 清空场景栈
|
||||||
while (s_SceneStack.size())
|
while (s_SceneStack.size())
|
||||||
|
|
@ -168,5 +168,5 @@ void e2d::SceneManager::__uninit()
|
||||||
SafeRelease(&s_pCurrentScene);
|
SafeRelease(&s_pCurrentScene);
|
||||||
SafeRelease(&s_pNextScene);
|
SafeRelease(&s_pNextScene);
|
||||||
SafeRelease(&s_pTransition);
|
SafeRelease(&s_pTransition);
|
||||||
SceneManager::clearScene();
|
SceneManager::clear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,23 @@ void e2d::TimerManager::__update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::TimerManager::preload(Timer * pTimer, Scene * pParentScene)
|
void e2d::TimerManager::add(double timeOut, TimerCallback callback)
|
||||||
{
|
{
|
||||||
TimerManager::preload(pTimer, pParentScene->getRoot());
|
auto pTimer = new Timer(callback, timeOut, 0, false);
|
||||||
|
TimerManager::add(pTimer, SceneManager::getCurrentScene());
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::TimerManager::preload(Timer * pTimer, Node * pParentNode)
|
void e2d::TimerManager::add(Timer * pTimer, Scene * pParentScene)
|
||||||
|
{
|
||||||
|
WARN_IF(pParentScene == nullptr, "Bind Timer with a NULL Scene pointer!");
|
||||||
|
|
||||||
|
if (pParentScene)
|
||||||
|
{
|
||||||
|
TimerManager::add(pTimer, pParentScene->getRoot());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::TimerManager::add(Timer * pTimer, Node * pParentNode)
|
||||||
{
|
{
|
||||||
WARN_IF(pTimer == nullptr, "Timer NULL pointer exception!");
|
WARN_IF(pTimer == nullptr, "Timer NULL pointer exception!");
|
||||||
WARN_IF(pParentNode == nullptr, "Bind Timer with a NULL Node pointer!");
|
WARN_IF(pParentNode == nullptr, "Bind Timer with a NULL Node pointer!");
|
||||||
|
|
@ -32,7 +43,7 @@ void e2d::TimerManager::preload(Timer * pTimer, Node * pParentNode)
|
||||||
if (pTimer && pParentNode)
|
if (pTimer && pParentNode)
|
||||||
{
|
{
|
||||||
ASSERT(
|
ASSERT(
|
||||||
!pTimer->m_pParentNode,
|
pTimer->m_pParentNode != nullptr,
|
||||||
"The timer is already binded, cannot be binded again!"
|
"The timer is already binded, cannot be binded again!"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class EActionTwoAtSameTime;
|
||||||
class TransitionFade;
|
class TransitionFade;
|
||||||
|
|
||||||
class Action :
|
class Action :
|
||||||
public Obj
|
public Object
|
||||||
{
|
{
|
||||||
friend ActionManager;
|
friend ActionManager;
|
||||||
friend ActionTwo;
|
friend ActionTwo;
|
||||||
|
|
|
||||||
|
|
@ -388,14 +388,14 @@ public:
|
||||||
class ObjectManager;
|
class ObjectManager;
|
||||||
|
|
||||||
// 基础对象
|
// 基础对象
|
||||||
class Obj
|
class Object
|
||||||
{
|
{
|
||||||
friend ObjectManager;
|
friend ObjectManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Obj();
|
Object();
|
||||||
|
|
||||||
virtual ~Obj();
|
virtual ~Object();
|
||||||
|
|
||||||
// 引用计数加一
|
// 引用计数加一
|
||||||
void retain();
|
void retain();
|
||||||
|
|
@ -412,7 +412,7 @@ private:
|
||||||
class Text;
|
class Text;
|
||||||
|
|
||||||
class Font :
|
class Font :
|
||||||
public Obj
|
public Object
|
||||||
{
|
{
|
||||||
friend Text;
|
friend Text;
|
||||||
|
|
||||||
|
|
@ -486,7 +486,7 @@ protected:
|
||||||
|
|
||||||
// 图片
|
// 图片
|
||||||
class Image :
|
class Image :
|
||||||
public Obj
|
public Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// 创建一个空的图片
|
// 创建一个空的图片
|
||||||
|
|
@ -583,7 +583,7 @@ class Action;
|
||||||
|
|
||||||
// 场景
|
// 场景
|
||||||
class Scene :
|
class Scene :
|
||||||
public Obj
|
public Object
|
||||||
{
|
{
|
||||||
friend SceneManager;
|
friend SceneManager;
|
||||||
|
|
||||||
|
|
@ -619,7 +619,7 @@ public:
|
||||||
);
|
);
|
||||||
|
|
||||||
// 添加节点到场景
|
// 添加节点到场景
|
||||||
void preload(
|
void add(
|
||||||
Node * child,
|
Node * child,
|
||||||
int zOrder = 0
|
int zOrder = 0
|
||||||
);
|
);
|
||||||
|
|
@ -665,11 +665,16 @@ typedef VoidFunction TimerCallback;
|
||||||
// 按钮点击回调函数
|
// 按钮点击回调函数
|
||||||
typedef VoidFunction ButtonCallback;
|
typedef VoidFunction ButtonCallback;
|
||||||
|
|
||||||
|
#ifndef CreateCallback
|
||||||
|
#define CreateCallback(Func) std::bind(&Func, this)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void SafeDelete(T** p) { if (*p) { delete *p; *p = nullptr; } }
|
inline void SafeDelete(T** p) { if (*p) { delete *p; *p = nullptr; } }
|
||||||
|
|
||||||
template<typename Obj>
|
template<typename Object>
|
||||||
inline void SafeRelease(Obj** p) { if (*p) { (*p)->release(); *p = nullptr; } }
|
inline void SafeRelease(Object** p) { if (*p) { (*p)->release(); *p = nullptr; } }
|
||||||
|
|
||||||
template<class Interface>
|
template<class Interface>
|
||||||
inline void SafeReleaseInterface(Interface **pp) { if (*pp != nullptr) { (*pp)->Release(); (*pp) = nullptr; } }
|
inline void SafeReleaseInterface(Interface **pp) { if (*pp != nullptr) { (*pp)->Release(); (*pp) = nullptr; } }
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ namespace e2d
|
||||||
|
|
||||||
class Game;
|
class Game;
|
||||||
class Renderer;
|
class Renderer;
|
||||||
class Obj;
|
class Object;
|
||||||
class Scene;
|
class Scene;
|
||||||
class Node;
|
class Node;
|
||||||
class Timer;
|
class Timer;
|
||||||
|
|
@ -22,17 +22,17 @@ class ObjectManager
|
||||||
friend Game;
|
friend Game;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 将一个节点放入内存池
|
// 将一个对象放入内存池
|
||||||
static void preload(
|
static void add(
|
||||||
e2d::Obj * nptr
|
e2d::Object * nptr
|
||||||
);
|
);
|
||||||
|
|
||||||
// 通知内存池刷新
|
// 释放垃圾对象的内存空间
|
||||||
static void notifyFlush();
|
static void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 刷新内存池
|
// 释放引用计数为 0 的对象
|
||||||
static void __flush();
|
static void __clearObjects();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -44,19 +44,19 @@ class SceneManager
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 切换场景
|
// 切换场景
|
||||||
static void enterScene(
|
static void enter(
|
||||||
Scene * scene, /* 下一个场景的指针 */
|
Scene * scene, /* 下一个场景的指针 */
|
||||||
Transition * transition = nullptr, /* 场景切换动画 */
|
Transition * transition = nullptr, /* 场景切换动画 */
|
||||||
bool saveCurrentScene = true /* 是否保存当前场景 */
|
bool saveCurrentScene = true /* 是否保存当前场景 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 返回上一场景
|
// 返回上一场景
|
||||||
static void backScene(
|
static void back(
|
||||||
Transition * transition = nullptr /* 场景切换动画 */
|
Transition * transition = nullptr /* 场景切换动画 */
|
||||||
);
|
);
|
||||||
|
|
||||||
// 清空保存的所有场景
|
// 清空保存的所有场景
|
||||||
static void clearScene();
|
static void clear();
|
||||||
|
|
||||||
// 获取当前场景
|
// 获取当前场景
|
||||||
static Scene * getCurrentScene();
|
static Scene * getCurrentScene();
|
||||||
|
|
@ -86,18 +86,24 @@ class TimerManager
|
||||||
friend Node;
|
friend Node;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 绑定定时器到场景
|
// 添加一个定时器,并将它绑定到场景
|
||||||
static void preload(
|
static void add(
|
||||||
Timer * pTimer,
|
Timer * pTimer,
|
||||||
Scene * pParentScene
|
Scene * pParentScene
|
||||||
);
|
);
|
||||||
|
|
||||||
// 绑定定时器到节点
|
// 添加一个定时器,并将它绑定到节点
|
||||||
static void preload(
|
static void add(
|
||||||
Timer * pTimer,
|
Timer * pTimer,
|
||||||
Node * pParentNode
|
Node * pParentNode
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 等待一段时间后执行指定函数
|
||||||
|
static void add(
|
||||||
|
double timeOut, /* 等待的时长(秒) */
|
||||||
|
TimerCallback callback /* 执行的函数 */
|
||||||
|
);
|
||||||
|
|
||||||
// 启动具有相同名称的定时器
|
// 启动具有相同名称的定时器
|
||||||
static void startTimers(
|
static void startTimers(
|
||||||
const String &name
|
const String &name
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class Shape;
|
||||||
class Transition;
|
class Transition;
|
||||||
|
|
||||||
class Node :
|
class Node :
|
||||||
public Obj
|
public Object
|
||||||
{
|
{
|
||||||
friend Scene;
|
friend Scene;
|
||||||
friend Shape;
|
friend Shape;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class Node;
|
||||||
|
|
||||||
|
|
||||||
class Shape :
|
class Shape :
|
||||||
public Obj
|
public Object
|
||||||
{
|
{
|
||||||
friend ShapeManager;
|
friend ShapeManager;
|
||||||
friend Node;
|
friend Node;
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ public:
|
||||||
|
|
||||||
// 定时器
|
// 定时器
|
||||||
class Timer :
|
class Timer :
|
||||||
public Obj
|
public Object
|
||||||
{
|
{
|
||||||
friend TimerManager;
|
friend TimerManager;
|
||||||
|
|
||||||
|
|
@ -210,7 +210,7 @@ public:
|
||||||
|
|
||||||
// 音乐播放器
|
// 音乐播放器
|
||||||
class Music :
|
class Music :
|
||||||
public Obj
|
public Object
|
||||||
{
|
{
|
||||||
friend MusicManager;
|
friend MusicManager;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace e2d
|
||||||
class SceneManager;
|
class SceneManager;
|
||||||
|
|
||||||
class Transition :
|
class Transition :
|
||||||
public Obj
|
public Object
|
||||||
{
|
{
|
||||||
friend SceneManager;
|
friend SceneManager;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue