Refactoring : project files

This commit is contained in:
Nomango 2018-09-05 13:38:30 +08:00
parent 65ba8e96d2
commit 42ac308278
10 changed files with 1279 additions and 1275 deletions

View File

@ -5,135 +5,135 @@ namespace e2d
{
// 按键消息
class KeyEvent
{
public:
// 按键消息类型
enum class Type : int
// 按键消息
class KeyEvent
{
Down = 0x0100, // 按下
Up // 抬起
public:
// 按键消息类型
enum class Type : int
{
Down = 0x0100, // 按下
Up // 抬起
};
public:
explicit KeyEvent(
HWND hWnd,
UINT message,
WPARAM w_param,
LPARAM l_param
);
// 获取按键键值
KeyCode GetCode() const;
// 获取按键次数
int GetCount() const;
// 获取事件类型
KeyEvent::Type GetType() const;
// VK 键值转换
static KeyCode ToKeyCode(
WPARAM w_param
);
protected:
int count_;
KeyCode code_;
KeyEvent::Type type_;
};
public:
explicit KeyEvent(
HWND hWnd,
UINT message,
WPARAM w_param,
LPARAM l_param
);
// 获取按键键值
KeyCode GetCode() const;
// 获取按键次数
int GetCount() const;
// 获取事件类型
KeyEvent::Type GetType() const;
// VK 键值转换
static KeyCode ToKeyCode(
WPARAM w_param
);
protected:
int count_;
KeyCode code_;
KeyEvent::Type type_;
};
// 鼠标消息
class MouseEvent
{
public:
// 鼠标消息类型
enum class Type : int
// 鼠标消息
class MouseEvent
{
Move = 0x0200, // 鼠标移动
LeftDown, // 鼠标左键按下
LeftUp, // 鼠标左键抬起
LeftDoubleClick, // 鼠标左键双击
RightDown, // 鼠标右键按下
RightUp, // 鼠标右键抬起
RightDoubleClick, // 鼠标右键双击
MiddleDown, // 鼠标中键按下
MiddleUp, // 鼠标中键抬起
MiddleDoubleClick, // 鼠标中键双击
Wheel // 滑动滚轮
public:
// 鼠标消息类型
enum class Type : int
{
Move = 0x0200, // 鼠标移动
LeftDown, // 鼠标左键按下
LeftUp, // 鼠标左键抬起
LeftDoubleClick, // 鼠标左键双击
RightDown, // 鼠标右键按下
RightUp, // 鼠标右键抬起
RightDoubleClick, // 鼠标右键双击
MiddleDown, // 鼠标中键按下
MiddleUp, // 鼠标中键抬起
MiddleDoubleClick, // 鼠标中键双击
Wheel // 滑动滚轮
};
public:
explicit MouseEvent(
HWND hWnd,
UINT message,
WPARAM w_param,
LPARAM l_param,
float dpi
);
// 获取鼠标横坐标
float GetX() const;
// 获取鼠标纵坐标
float GetY() const;
// 获取鼠标坐标
Point GetPos() const;
// 获取事件类型
MouseEvent::Type GetType() const;
float GetWheelDelta() const;
// 鼠标左键是否按下
bool IsLButtonDown() const;
// 鼠标右键是否按下
bool IsRButtonDown() const;
// 鼠标中键是否按下
bool IsMButtonDown() const;
// Shift 键是否按下
bool IsShiftDown() const;
// Ctrl 键是否按下
bool IsCtrlDown() const;
protected:
UINT message_;
WPARAM w_param_;
LPARAM l_param_;
Point pos_;
MouseEvent::Type type_;
};
public:
explicit MouseEvent(
HWND hWnd,
UINT message,
WPARAM w_param,
LPARAM l_param,
float dpi
);
// 获取鼠标横坐标
float GetX() const;
// 碰撞事件
class Collision
{
public:
Collision();
// 获取鼠标纵坐标
float GetY() const;
explicit Collision(
Node* node,
Collider::Relation relation
);
// 获取鼠标坐标
Point GetPos() const;
~Collision();
// 获取事件类型
MouseEvent::Type GetType() const;
// 获取发生碰撞节点
Node* GetNode() const;
float GetWheelDelta() const;
// 获取交集关系
Collider::Relation GetRelation() const;
// 鼠标左键是否按下
bool IsLButtonDown() const;
// 鼠标右键是否按下
bool IsRButtonDown() const;
// 鼠标中键是否按下
bool IsMButtonDown() const;
// Shift 键是否按下
bool IsShiftDown() const;
// Ctrl 键是否按下
bool IsCtrlDown() const;
protected:
UINT message_;
WPARAM w_param_;
LPARAM l_param_;
Point pos_;
MouseEvent::Type type_;
};
// 碰撞事件
class Collision
{
public:
Collision();
explicit Collision(
Node* node,
Collider::Relation relation
);
~Collision();
// 获取发生碰撞节点
Node* GetNode() const;
// 获取交集关系
Collider::Relation GetRelation() const;
protected:
Node * node_;
Collider::Relation relation_;
};
protected:
Node * node_;
Collider::Relation relation_;
};
}

View File

@ -5,191 +5,191 @@ namespace e2d
{
class Music;
class Music;
// 音源回调
class VoiceCallback
: public IXAudio2VoiceCallback
{
public:
VoiceCallback();
~VoiceCallback();
STDMETHOD_(void, OnVoiceProcessingPassStart) (THIS_ UINT32 BytesRequired) {}
STDMETHOD_(void, OnVoiceProcessingPassEnd) (THIS) {}
STDMETHOD_(void, OnStreamEnd) (THIS);
STDMETHOD_(void, OnBufferStart) (THIS_ void* pBufferContext) {}
STDMETHOD_(void, OnBufferEnd) (THIS_ void* pBufferContext);
STDMETHOD_(void, OnLoopEnd) (THIS_ void* pBufferContext);
STDMETHOD_(void, OnVoiceError) (THIS_ void* pBufferContext, HRESULT Error) {}
STDMETHOD_(void, SetCallbackOnStreamEnd) (THIS_ const Function& func);
STDMETHOD_(void, SetCallbackOnLoopEnd) (THIS_ const Function& func);
protected:
Function loop_end_callback_;
Function stream_end_callback_;
};
// 文字渲染器
class E2DTextRenderer
: public IDWriteTextRenderer
{
private:
E2DTextRenderer();
~E2DTextRenderer();
public:
static HRESULT Create(
E2DTextRenderer** ppTextRenderer,
ID2D1Factory* pD2DFactory,
ID2D1HwndRenderTarget* pRT,
ID2D1SolidColorBrush* pBrush
);
STDMETHOD_(void, SetTextStyle)(
CONST D2D1_COLOR_F &fillColor,
BOOL outline,
CONST D2D1_COLOR_F &outline_color,
FLOAT outline_width,
D2D1_LINE_JOIN outlineJoin
);
STDMETHOD(DrawGlyphRun)(
__maybenull void* clientDrawingContext,
FLOAT baselineOriginX,
FLOAT baselineOriginY,
DWRITE_MEASURING_MODE measuringMode,
__in DWRITE_GLYPH_RUN const* glyphRun,
__in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
IUnknown* clientDrawingEffect
);
STDMETHOD(DrawUnderline)(
__maybenull void* clientDrawingContext,
FLOAT baselineOriginX,
FLOAT baselineOriginY,
__in DWRITE_UNDERLINE const* underline,
IUnknown* clientDrawingEffect
);
STDMETHOD(DrawStrikethrough)(
__maybenull void* clientDrawingContext,
FLOAT baselineOriginX,
FLOAT baselineOriginY,
__in DWRITE_STRIKETHROUGH const* strikethrough,
IUnknown* clientDrawingEffect
);
STDMETHOD(DrawInlineObject)(
__maybenull void* clientDrawingContext,
FLOAT originX,
FLOAT originY,
IDWriteInlineObject* inlineObject,
BOOL IsSideways,
BOOL IsRightToLeft,
IUnknown* clientDrawingEffect
);
STDMETHOD(IsPixelSnappingDisabled)(
__maybenull void* clientDrawingContext,
__out BOOL* isDisabled
);
STDMETHOD(GetCurrentTransform)(
__maybenull void* clientDrawingContext,
__out DWRITE_MATRIX* transform
);
STDMETHOD(GetPixelsPerDip)(
__maybenull void* clientDrawingContext,
__out FLOAT* pixelsPerDip
);
public:
unsigned long STDMETHODCALLTYPE AddRef();
unsigned long STDMETHODCALLTYPE Release();
HRESULT STDMETHODCALLTYPE QueryInterface(
IID const& riid,
void** ppvObject
);
private:
unsigned long cRefCount_;
D2D1_COLOR_F sFillColor_;
D2D1_COLOR_F sOutlineColor_;
FLOAT fOutlineWidth;
BOOL bShowOutline_;
ID2D1Factory* pD2DFactory_;
ID2D1HwndRenderTarget* pRT_;
ID2D1SolidColorBrush* pBrush_;
ID2D1StrokeStyle * pCurrStrokeStyle_;
};
// 异常
class Exception
{
public:
Exception() E2D_NOEXCEPT;
explicit Exception(const char * message) E2D_NOEXCEPT;
Exception(Exception const& other) E2D_NOEXCEPT;
virtual ~Exception() E2D_NOEXCEPT;
Exception& operator=(Exception const& other) E2D_NOEXCEPT;
// 获取异常信息
virtual const char * GetMsg() const;
private:
const char * message_;
};
// 系统异常
class SystemException
: public Exception
{
public:
SystemException() E2D_NOEXCEPT;
explicit SystemException(const char * message) E2D_NOEXCEPT;
};
template<class Interface>
inline void SafeRelease(Interface*& p)
{
if (p != nullptr)
// 音源回调
class VoiceCallback
: public IXAudio2VoiceCallback
{
p->Release();
p = nullptr;
}
}
public:
VoiceCallback();
~VoiceCallback();
STDMETHOD_(void, OnVoiceProcessingPassStart) (THIS_ UINT32 BytesRequired) {}
STDMETHOD_(void, OnVoiceProcessingPassEnd) (THIS) {}
STDMETHOD_(void, OnStreamEnd) (THIS);
STDMETHOD_(void, OnBufferStart) (THIS_ void* pBufferContext) {}
STDMETHOD_(void, OnBufferEnd) (THIS_ void* pBufferContext);
STDMETHOD_(void, OnLoopEnd) (THIS_ void* pBufferContext);
STDMETHOD_(void, OnVoiceError) (THIS_ void* pBufferContext, HRESULT Error) {}
STDMETHOD_(void, SetCallbackOnStreamEnd) (THIS_ const Function& func);
STDMETHOD_(void, SetCallbackOnLoopEnd) (THIS_ const Function& func);
protected:
Function loop_end_callback_;
Function stream_end_callback_;
};
inline void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
// 文字渲染器
class E2DTextRenderer
: public IDWriteTextRenderer
{
// 在此处设置断点以捕获 D2D API 异常.
static char s_str[64] = {};
sprintf_s(s_str, "Failure with HRESULT of %08X", static_cast<unsigned int>(hr));
throw SystemException(s_str);
private:
E2DTextRenderer();
~E2DTextRenderer();
public:
static HRESULT Create(
E2DTextRenderer** ppTextRenderer,
ID2D1Factory* pD2DFactory,
ID2D1HwndRenderTarget* pRT,
ID2D1SolidColorBrush* pBrush
);
STDMETHOD_(void, SetTextStyle)(
CONST D2D1_COLOR_F &fillColor,
BOOL outline,
CONST D2D1_COLOR_F &outline_color,
FLOAT outline_width,
D2D1_LINE_JOIN outlineJoin
);
STDMETHOD(DrawGlyphRun)(
__maybenull void* clientDrawingContext,
FLOAT baselineOriginX,
FLOAT baselineOriginY,
DWRITE_MEASURING_MODE measuringMode,
__in DWRITE_GLYPH_RUN const* glyphRun,
__in DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
IUnknown* clientDrawingEffect
);
STDMETHOD(DrawUnderline)(
__maybenull void* clientDrawingContext,
FLOAT baselineOriginX,
FLOAT baselineOriginY,
__in DWRITE_UNDERLINE const* underline,
IUnknown* clientDrawingEffect
);
STDMETHOD(DrawStrikethrough)(
__maybenull void* clientDrawingContext,
FLOAT baselineOriginX,
FLOAT baselineOriginY,
__in DWRITE_STRIKETHROUGH const* strikethrough,
IUnknown* clientDrawingEffect
);
STDMETHOD(DrawInlineObject)(
__maybenull void* clientDrawingContext,
FLOAT originX,
FLOAT originY,
IDWriteInlineObject* inlineObject,
BOOL IsSideways,
BOOL IsRightToLeft,
IUnknown* clientDrawingEffect
);
STDMETHOD(IsPixelSnappingDisabled)(
__maybenull void* clientDrawingContext,
__out BOOL* isDisabled
);
STDMETHOD(GetCurrentTransform)(
__maybenull void* clientDrawingContext,
__out DWRITE_MATRIX* transform
);
STDMETHOD(GetPixelsPerDip)(
__maybenull void* clientDrawingContext,
__out FLOAT* pixelsPerDip
);
public:
unsigned long STDMETHODCALLTYPE AddRef();
unsigned long STDMETHODCALLTYPE Release();
HRESULT STDMETHODCALLTYPE QueryInterface(
IID const& riid,
void** ppvObject
);
private:
unsigned long cRefCount_;
D2D1_COLOR_F sFillColor_;
D2D1_COLOR_F sOutlineColor_;
FLOAT fOutlineWidth;
BOOL bShowOutline_;
ID2D1Factory* pD2DFactory_;
ID2D1HwndRenderTarget* pRT_;
ID2D1SolidColorBrush* pBrush_;
ID2D1StrokeStyle * pCurrStrokeStyle_;
};
// 异常
class Exception
{
public:
Exception() E2D_NOEXCEPT;
explicit Exception(const char * message) E2D_NOEXCEPT;
Exception(Exception const& other) E2D_NOEXCEPT;
virtual ~Exception() E2D_NOEXCEPT;
Exception& operator=(Exception const& other) E2D_NOEXCEPT;
// 获取异常信息
virtual const char * GetMsg() const;
private:
const char * message_;
};
// 系统异常
class SystemException
: public Exception
{
public:
SystemException() E2D_NOEXCEPT;
explicit SystemException(const char * message) E2D_NOEXCEPT;
};
template<class Interface>
inline void SafeRelease(Interface*& p)
{
if (p != nullptr)
{
p->Release();
p = nullptr;
}
}
inline void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
{
// 在此处设置断点以捕获 D2D API 异常.
static char s_str[64] = {};
sprintf_s(s_str, "Failure with HRESULT of %08X", static_cast<unsigned int>(hr));
throw SystemException(s_str);
}
}
}
}

View File

@ -6,74 +6,74 @@ namespace e2d
{
class Node;
class Node;
// 碰撞体管理器
class CollisionManager
{
friend class Node;
friend class Collider;
// 碰撞体管理器
class CollisionManager
{
friend class Node;
friend class Collider;
public:
// 获取碰撞体管理器实例
static CollisionManager * GetInstance();
public:
// 获取碰撞体管理器实例
static CollisionManager * GetInstance();
// 打开或关闭碰撞监听
// 默认:关闭
void SetCollisionEnabled(
bool enabled
);
// 打开或关闭碰撞监听
// 默认:关闭
void SetCollisionEnabled(
bool enabled
);
// 添加可互相碰撞物体的名称
void AddName(
const String& name1,
const String& name2
);
// 添加可互相碰撞物体的名称
void AddName(
const String& name1,
const String& name2
);
// 添加可互相碰撞物体的名称
void AddName(
const std::vector<std::pair<String, String>>& names
);
// 添加可互相碰撞物体的名称
void AddName(
const std::vector<std::pair<String, String>>& names
);
// 判断两个物体是否是可碰撞的
bool IsCollidable(
Node * node1,
Node * node2
);
// 判断两个物体是否是可碰撞的
bool IsCollidable(
Node * node1,
Node * node2
);
// 判断两个物体是否是可碰撞的
bool IsCollidable(
const String& name1,
const String& name2
);
// 判断两个物体是否是可碰撞的
bool IsCollidable(
const String& name1,
const String& name2
);
private:
CollisionManager();
private:
CollisionManager();
~CollisionManager();
~CollisionManager();
E2D_DISABLE_COPY(CollisionManager);
E2D_DISABLE_COPY(CollisionManager);
// 添加碰撞体
void AddCollider(
Collider* collider
);
// 添加碰撞体
void AddCollider(
Collider* collider
);
// 移除碰撞体
void RemoveCollider(
Collider* collider
);
// 移除碰撞体
void RemoveCollider(
Collider* collider
);
// 更新碰撞体
void UpdateCollider(
Collider* collider
);
// 更新碰撞体
void UpdateCollider(
Collider* collider
);
private:
bool collision_enabled_;
std::vector<Collider*> colliders_;
std::set<std::pair<size_t, size_t>> collision_list_;
};
private:
bool collision_enabled_;
std::vector<Collider*> colliders_;
std::set<std::pair<size_t, size_t>> collision_list_;
};
}

View File

@ -8,406 +8,406 @@ namespace e2d
{
// 窗体
class Window
{
public:
// 鼠标指针样式
enum class Cursor : int
// 窗体
class Window
{
Normal, /* 默认指针样式 */
Hand, /* 手状指针 */
No, /* 禁止指针 */
Wait, /* 沙漏指针 */
ArrowWait /* 默认指针和小沙漏 */
public:
// 鼠标指针样式
enum class Cursor : int
{
Normal, /* 默认指针样式 */
Hand, /* 手状指针 */
No, /* 禁止指针 */
Wait, /* 沙漏指针 */
ArrowWait /* 默认指针和小沙漏 */
};
// 弹窗样式
enum class PopupStyle : int
{
Info, /* 提示 */
Warning, /* 警告 */
Error /* 错误 */
};
public:
// 获取窗体实例
static Window * GetInstance();
// 销毁窗体实例
static void DestroyInstance();
// 创建窗体互斥体
bool CheckMutex(
const String& mutex = L"" /* 进程互斥体名称 */
);
// 获取窗体标题
const String& GetTitle() const;
// 获取窗体宽度
int GetWidth() const;
// 获取窗体高度
int GetHeight() const;
// 获取窗体大小
Size GetSize() const;
// 获取窗口 DPI
float GetDpi() const;
// 获取窗口句柄
HWND GetHWnd();
// 修改窗体大小
void SetSize(
int width, /* 窗体宽度 */
int height /* 窗体高度 */
);
// 设置窗体标题
void SetTitle(
const String& title /* 窗体标题 */
);
// 设置窗体图标
void SetIcon(
int icon_id
);
// 设置鼠标指针样式
void SetCursor(
Cursor cursor
);
// 打开或隐藏控制台
void SetConsoleEnabled(
bool enabled
);
// 是否允许响应输入法
void SetTypewritingEnabled(
bool enabled
);
// 弹出窗口
// 返回值:当窗口包含取消按钮时,返回值表示用户是否点击确认按钮
bool Popup(
const String& text, /* 窗口内容 */
const String& title, /* 窗口标题 */
PopupStyle style = PopupStyle::Info,/* 弹窗样式 */
bool has_cancel = false /* 包含取消按钮 */
);
// 处理窗体消息
void Poll();
private:
Window();
~Window();
E2D_DISABLE_COPY(Window);
// 根据客户区大小定位窗口
Rect Locate(
int width,
int height
);
// Win32 窗口消息回调程序
static LRESULT CALLBACK WndProc(
HWND hWnd,
UINT msg,
WPARAM w_param,
LPARAM l_param
);
private:
HWND hWnd_;
MSG msg_;
int width_;
int height_;
String title_;
int icon_id_;
float dpi_;
static Window * instance_;
};
// 弹窗样式
enum class PopupStyle : int
// 渲染器
class Renderer
{
Info, /* 提示 */
Warning, /* 警告 */
Error /* 错误 */
public:
// 获取渲染器实例
static Renderer * GetInstance();
// 销毁实例
static void DestroyInstance();
// 获取背景色
Color GetBackgroundColor();
// 修改背景色
void SetBackgroundColor(
const Color& color
);
// 显示或隐藏 FPS
// 默认:隐藏
void ShowFps(
bool show
);
// 开始渲染
void BeginDraw();
// 结束渲染
void EndDraw();
// 获取文字渲染器
E2DTextRenderer * GetTextRenderer();
// 获取 ID2D1HwndRenderTarget 对象
ID2D1HwndRenderTarget * GetRenderTarget();
// 获取 ID2D1SolidColorBrush 对象
ID2D1SolidColorBrush * GetSolidBrush();
// 获取 ID2D1Factory 对象
static ID2D1Factory * GetFactory();
// 获取 IWICImagingFactory 对象
static IWICImagingFactory * GetImagingFactory();
// 获取 IDWriteFactory 对象
static IDWriteFactory * GetWriteFactory();
// 获取 Miter 样式的 ID2D1StrokeStyle
static ID2D1StrokeStyle * GetMiterStrokeStyle();
// 获取 Bevel 样式的 ID2D1StrokeStyle
static ID2D1StrokeStyle * GetBevelStrokeStyle();
// 获取 Round 样式的 ID2D1StrokeStyle
static ID2D1StrokeStyle * GetRoundStrokeStyle();
protected:
Renderer();
~Renderer();
E2D_DISABLE_COPY(Renderer);
protected:
bool show_fps_;
int render_times_;
Time last_render_time_;
D2D1_COLOR_F clear_color_;
E2DTextRenderer* text_renderer_;
IDWriteTextFormat* fps_text_format_;
IDWriteTextLayout* fps_text_layout_;
ID2D1SolidColorBrush* solid_brush_;
ID2D1HwndRenderTarget* render_target_;
static ID2D1Factory* factory_;
static IWICImagingFactory* imaging_factory_;
static IDWriteFactory* write_factory_;
static ID2D1StrokeStyle* miter_stroke_style_;
static ID2D1StrokeStyle* bevel_stroke_style_;
static ID2D1StrokeStyle* round_stroke_style_;
static Renderer * instance_;
};
public:
// 获取窗体实例
static Window * GetInstance();
// 销毁窗体实例
static void DestroyInstance();
// 创建窗体互斥体
bool CheckMutex(
const String& mutex = L"" /* 进程互斥体名称 */
);
// 获取窗体标题
const String& GetTitle() const;
// 获取窗体宽度
int GetWidth() const;
// 获取窗体高度
int GetHeight() const;
// 获取窗体大小
Size GetSize() const;
// 获取窗口 DPI
float GetDpi() const;
// 获取窗口句柄
HWND GetHWnd();
// 修改窗体大小
void SetSize(
int width, /* 窗体宽度 */
int height /* 窗体高度 */
);
// 设置窗体标题
void SetTitle(
const String& title /* 窗体标题 */
);
// 设置窗体图标
void SetIcon(
int icon_id
);
// 设置鼠标指针样式
void SetCursor(
Cursor cursor
);
// 打开或隐藏控制台
void SetConsoleEnabled(
bool enabled
);
// 是否允许响应输入法
void SetTypewritingEnabled(
bool enabled
);
// 弹出窗口
// 返回值:当窗口包含取消按钮时,返回值表示用户是否点击确认按钮
bool Popup(
const String& text, /* 窗口内容 */
const String& title, /* 窗口标题 */
PopupStyle style = PopupStyle::Info,/* 弹窗样式 */
bool has_cancel = false /* 包含取消按钮 */
);
// 输入设备
class Input
{
public:
// 获取输入设备实例
static Input * GetInstance();
// 处理窗体消息
void Poll();
// 销毁输入设备实例
static void DestroyInstance();
private:
Window();
// 检测键盘某按键是否正被按下
bool IsDown(
KeyCode key
);
~Window();
// 检测鼠标按键是否正被按下
bool IsDown(
MouseCode code
);
E2D_DISABLE_COPY(Window);
// 根据客户区大小定位窗口
Rect Locate(
int width,
int height
);
// Win32 窗口消息回调程序
static LRESULT CALLBACK WndProc(
HWND hWnd,
UINT msg,
WPARAM w_param,
LPARAM l_param
);
private:
HWND hWnd_;
MSG msg_;
int width_;
int height_;
String title_;
int icon_id_;
float dpi_;
static Window * instance_;
};
// 渲染器
class Renderer
{
public:
// 获取渲染器实例
static Renderer * GetInstance();
// 销毁实例
static void DestroyInstance();
// 获取背景色
Color GetBackgroundColor();
// 修改背景色
void SetBackgroundColor(
const Color& color
);
// 显示或隐藏 FPS
// 默认:隐藏
void ShowFps(
bool show
);
// 开始渲染
void BeginDraw();
// 结束渲染
void EndDraw();
// 获取文字渲染器
E2DTextRenderer * GetTextRenderer();
// 获得鼠标X轴坐标值
float GetMouseX();
// 获取 ID2D1HwndRenderTarget 对象
ID2D1HwndRenderTarget * GetRenderTarget();
// 获得鼠标Y轴坐标值
float GetMouseY();
// 获取 ID2D1SolidColorBrush 对象
ID2D1SolidColorBrush * GetSolidBrush();
// 获得鼠标坐标值
Point GetMousePos();
// 获取 ID2D1Factory 对象
static ID2D1Factory * GetFactory();
// 获得鼠标X轴坐标增量
float GetMouseDeltaX();
// 获取 IWICImagingFactory 对象
static IWICImagingFactory * GetImagingFactory();
// 获得鼠标Y轴坐标增量
float GetMouseDeltaY();
// 获取 IDWriteFactory 对象
static IDWriteFactory * GetWriteFactory();
// 获得鼠标Z轴鼠标滚轮坐标增量
float GetMouseDeltaZ();
// 获取 Miter 样式的 ID2D1StrokeStyle
static ID2D1StrokeStyle * GetMiterStrokeStyle();
// 刷新输入设备状态
void Update();
// 获取 Bevel 样式的 ID2D1StrokeStyle
static ID2D1StrokeStyle * GetBevelStrokeStyle();
protected:
Input();
// 获取 Round 样式的 ID2D1StrokeStyle
static ID2D1StrokeStyle * GetRoundStrokeStyle();
~Input();
protected:
Renderer();
E2D_DISABLE_COPY(Input);
~Renderer();
protected:
IDirectInput8W * direct_input_;
IDirectInputDevice8W* keyboard_device_;
IDirectInputDevice8W* mouse_device_;
DIMOUSESTATE mouse_state_;
char key_buffer_[256];
E2D_DISABLE_COPY(Renderer);
static Input * instance_;
};
protected:
bool show_fps_;
int render_times_;
Time last_render_time_;
D2D1_COLOR_F clear_color_;
E2DTextRenderer* text_renderer_;
IDWriteTextFormat* fps_text_format_;
IDWriteTextLayout* fps_text_layout_;
ID2D1SolidColorBrush* solid_brush_;
ID2D1HwndRenderTarget* render_target_;
static ID2D1Factory* factory_;
static IWICImagingFactory* imaging_factory_;
static IDWriteFactory* write_factory_;
static ID2D1StrokeStyle* miter_stroke_style_;
static ID2D1StrokeStyle* bevel_stroke_style_;
static ID2D1StrokeStyle* round_stroke_style_;
static Renderer * instance_;
};
// 音频设备
class Audio
{
public:
// 获取音频设备实例
static Audio * GetInstance();
// 销毁实例
static void DestroyInstance();
// 输入设备
class Input
{
public:
// 获取输入设备实例
static Input * GetInstance();
// 获取 XAudio2 实例对象
IXAudio2 * GetXAudio2();
// 销毁输入设备实例
static void DestroyInstance();
// 获取 MasteringVoice 实例对象
IXAudio2MasteringVoice* GetMasteringVoice();
// 检测键盘某按键是否正被按下
bool IsDown(
KeyCode key
);
protected:
Audio();
// 检测鼠标按键是否正被按下
bool IsDown(
MouseCode code
);
virtual ~Audio();
// 获得鼠标X轴坐标值
float GetMouseX();
E2D_DISABLE_COPY(Audio);
// 获得鼠标Y轴坐标值
float GetMouseY();
protected:
IXAudio2 * x_audio2_;
IXAudio2MasteringVoice* mastering_voice_;
// 获得鼠标坐标值
Point GetMousePos();
static Audio * instance_;
};
// 获得鼠标X轴坐标增量
float GetMouseDeltaX();
// 获得鼠标Y轴坐标增量
float GetMouseDeltaY();
// 游戏
class Game
{
public:
// 获取 Game 实例
static Game * GetInstance();
// 获得鼠标Z轴鼠标滚轮坐标增量
float GetMouseDeltaZ();
// 销毁实例
static void DestroyInstance();
// 刷新输入设备状态
void Update();
// 启动游戏
void Start();
protected:
Input();
// 暂停游戏
void Pause();
~Input();
// 继续游戏
void Resume();
E2D_DISABLE_COPY(Input);
// 结束游戏
void Quit();
protected:
IDirectInput8W * direct_input_;
IDirectInputDevice8W* keyboard_device_;
IDirectInputDevice8W* mouse_device_;
DIMOUSESTATE mouse_state_;
char key_buffer_[256];
// 游戏是否暂停
bool IsPaused();
static Input * instance_;
};
// 场景入栈
void EnterScene(
Scene * scene /* 下一个场景的指针 */
);
// 场景入栈
void EnterScene(
Transition * transition /* 场景动画 */
);
// 音频设备
class Audio
{
public:
// 获取音频设备实例
static Audio * GetInstance();
// 获取当前场景
Scene * GetCurrentScene();
// 销毁实例
static void DestroyInstance();
// 是否正在进行场景动画
bool IsTransitioning() const;
// 获取 XAudio2 实例对象
IXAudio2 * GetXAudio2();
// 更新场景内容
void UpdateScene();
// 获取 MasteringVoice 实例对象
IXAudio2MasteringVoice* GetMasteringVoice();
// 渲染场景画面
void DrawScene();
protected:
Audio();
protected:
Game();
virtual ~Audio();
~Game();
E2D_DISABLE_COPY(Audio);
E2D_DISABLE_COPY(Game);
protected:
IXAudio2 * x_audio2_;
IXAudio2MasteringVoice* mastering_voice_;
private:
bool quit_;
bool paused_;
Scene* curr_scene_;
Scene* next_scene_;
Transition* transition_;
static Audio * instance_;
};
static Game * instance_;
};
// 游戏
class Game
{
public:
// 获取 Game 实例
static Game * GetInstance();
// 垃圾回收池
class GC
{
public:
// 获取 GC 实例
static GC * GetInstance();
// 销毁实例
static void DestroyInstance();
// 自动释放
void AutoRelease(
Ref* ref
);
// 启动游戏
void Start();
// 安全地释放对象
void SafeRelease(
Ref* ref
);
// 暂停游戏
void Pause();
// 刷新内存池
void Flush();
// 继续游戏
void Resume();
private:
GC();
// 结束游戏
void Quit();
~GC();
// 游戏是否暂停
bool IsPaused();
E2D_DISABLE_COPY(GC);
// 场景入栈
void EnterScene(
Scene * scene /* 下一个场景的指针 */
);
private:
bool notifyed_;
bool cleanup_;
std::set<Ref*> pool_;
};
// 场景入栈
void EnterScene(
Transition * transition /* 场景动画 */
);
// 获取当前场景
Scene * GetCurrentScene();
// 是否正在进行场景动画
bool IsTransitioning() const;
// 更新场景内容
void UpdateScene();
// 渲染场景画面
void DrawScene();
protected:
Game();
~Game();
E2D_DISABLE_COPY(Game);
private:
bool quit_;
bool paused_;
Scene* curr_scene_;
Scene* next_scene_;
Transition* transition_;
static Game * instance_;
};
// 垃圾回收池
class GC
{
public:
// 获取 GC 实例
static GC * GetInstance();
// 自动释放
void AutoRelease(
Ref* ref
);
// 安全地释放对象
void SafeRelease(
Ref* ref
);
// 刷新内存池
void Flush();
private:
GC();
~GC();
E2D_DISABLE_COPY(GC);
private:
bool notifyed_;
bool cleanup_;
std::set<Ref*> pool_;
};
}
}

View File

@ -6,505 +6,505 @@ namespace e2d
{
// 随机数产生器
class Random
{
public:
// 取得范围内的一个整型随机数
template<typename T>
static inline T Range(T min, T max)
{
return e2d::Random::RandomInt(min, max);
}
// 取得范围内的一个浮点数随机数
static inline float Range(float min, float max)
{
return e2d::Random::RandomReal(min, max);
}
// 取得范围内的一个浮点数随机数
static inline double Range(double min, double max)
{
return e2d::Random::RandomReal(min, max);
}
private:
template<typename T>
static T RandomInt(T min, T max)
// 随机数产生器
class Random
{
std::uniform_int_distribution<T> dist(min, max);
return dist(Random::GetEngine());
}
public:
// 取得范围内的一个整型随机数
template<typename T>
static inline T Range(T min, T max)
{
return e2d::Random::RandomInt(min, max);
}
template<typename T>
static T RandomReal(T min, T max)
// 取得范围内的一个浮点数随机数
static inline float Range(float min, float max)
{
return e2d::Random::RandomReal(min, max);
}
// 取得范围内的一个浮点数随机数
static inline double Range(double min, double max)
{
return e2d::Random::RandomReal(min, max);
}
private:
template<typename T>
static T RandomInt(T min, T max)
{
std::uniform_int_distribution<T> dist(min, max);
return dist(Random::GetEngine());
}
template<typename T>
static T RandomReal(T min, T max)
{
std::uniform_real_distribution<T> dist(min, max);
return dist(Random::GetEngine());
}
// 获取随机数产生器
static std::default_random_engine &GetEngine();
};
// 音乐
class Music :
public Ref
{
std::uniform_real_distribution<T> dist(min, max);
return dist(Random::GetEngine());
}
// 获取随机数产生器
static std::default_random_engine &GetEngine();
};
// 音乐
class Music :
public Ref
{
friend class VoiceCallback;
public:
Music();
explicit Music(
const e2d::String& file_path /* 音乐文件路径 */
);
explicit Music(
const Resource& res /* 音乐资源 */
);
virtual ~Music();
// 打开音乐文件
bool Open(
const e2d::String& file_path /* 音乐文件路径 */
);
// 打开音乐资源
bool Open(
const Resource& res
);
// 播放
bool Play(
int loopCount = 0
);
// 暂停
void Pause();
// 继续
void Resume();
// 停止
void Stop();
// 关闭并回收资源
void Close();
// 是否正在播放
bool IsPlaying() const;
// 设置音量
bool SetVolume(
float volume
);
// 设置播放结束时的执行函数
void SetCallbackOnEnd(
const Function& func
);
// 设置循环播放中每一次播放结束时的执行函数
void SetCallbackOnLoopEnd(
const Function& func
);
// 获取 IXAudio2SourceVoice 对象
IXAudio2SourceVoice * GetSourceVoice() const;
protected:
bool _readMMIO();
bool _resetFile();
bool _read(
BYTE* buffer,
DWORD size_to_read
);
bool _findMediaFileCch(
wchar_t* dest_path,
int cch_dest,
const wchar_t * file_name
);
protected:
bool opened_;
DWORD size_;
CHAR* buffer_;
BYTE* wave_data_;
HMMIO hmmio_;
MMCKINFO ck_;
MMCKINFO ck_riff_;
WAVEFORMATEX* wfx_;
VoiceCallback callback_;
IXAudio2SourceVoice* voice_;
};
// 音乐播放器
class Player
{
public:
// 获取播放器实例
static Player * GetInstance();
// 销毁实例
static void DestroyInstance();
// 预加载音乐资源
bool Preload(
const String& file_path /* 音乐文件路径 */
);
// 播放音乐
bool Play(
const String& file_path, /* 音乐文件路径 */
int loop_count = 0 /* 重复播放次数,设置 -1 为循环播放 */
);
// 暂停音乐
void Pause(
const String& file_path /* 音乐文件路径 */
);
// 继续播放音乐
void Resume(
const String& file_path /* 音乐文件路径 */
);
// 停止音乐
void Stop(
const String& file_path /* 音乐文件路径 */
);
// 获取音乐播放状态
bool IsPlaying(
const String& file_path /* 音乐文件路径 */
);
// 预加载音乐资源
bool Preload(
const Resource& res /* 音乐资源 */
);
// 播放音乐
bool Play(
const Resource& res, /* 音乐资源 */
int loop_count = 0 /* 重复播放次数,设置 -1 为循环播放 */
);
// 暂停音乐
void Pause(
const Resource& res /* 音乐资源 */
);
// 继续播放音乐
void Resume(
const Resource& res /* 音乐资源 */
);
// 停止音乐
void Stop(
const Resource& res /* 音乐资源 */
);
// 获取音乐播放状态
bool IsPlaying(
const Resource& res /* 音乐资源 */
);
// 获取音量
float GetVolume();
// 设置音量
void SetVolume(
float volume /* 音量范围为 -224 ~ 2240 是静音1 是正常音量 */
);
// 暂停所有音乐
void PauseAll();
// 继续播放所有音乐
void ResumeAll();
// 停止所有音乐
void StopAll();
// 清空音乐缓存
void ClearCache();
protected:
Player();
~Player();
E2D_DISABLE_COPY(Player);
protected:
float volume_;
std::map<size_t, Music*> musics_;
static Player * instance_;
};
friend class VoiceCallback;
public:
Music();
explicit Music(
const e2d::String& file_path /* 音乐文件路径 */
);
explicit Music(
const Resource& res /* 音乐资源 */
);
virtual ~Music();
// 打开音乐文件
bool Open(
const e2d::String& file_path /* 音乐文件路径 */
);
// 打开音乐资源
bool Open(
const Resource& res
);
// 播放
bool Play(
int loopCount = 0
);
// 暂停
void Pause();
// 继续
void Resume();
// 停止
void Stop();
// 关闭并回收资源
void Close();
// 是否正在播放
bool IsPlaying() const;
// 设置音量
bool SetVolume(
float volume
);
// 设置播放结束时的执行函数
void SetCallbackOnEnd(
const Function& func
);
// 设置循环播放中每一次播放结束时的执行函数
void SetCallbackOnLoopEnd(
const Function& func
);
// 获取 IXAudio2SourceVoice 对象
IXAudio2SourceVoice * GetSourceVoice() const;
protected:
bool _readMMIO();
bool _resetFile();
bool _read(
BYTE* buffer,
DWORD size_to_read
);
bool _findMediaFileCch(
wchar_t* dest_path,
int cch_dest,
const wchar_t * file_name
);
protected:
bool opened_;
DWORD size_;
CHAR* buffer_;
BYTE* wave_data_;
HMMIO hmmio_;
MMCKINFO ck_;
MMCKINFO ck_riff_;
WAVEFORMATEX* wfx_;
VoiceCallback callback_;
IXAudio2SourceVoice* voice_;
};
// 音乐播放器
class Player
{
public:
// 获取播放器实例
static Player * GetInstance();
// 销毁实例
static void DestroyInstance();
// 预加载音乐资源
bool Preload(
const String& file_path /* 音乐文件路径 */
);
// 播放音乐
bool Play(
const String& file_path, /* 音乐文件路径 */
int loop_count = 0 /* 重复播放次数,设置 -1 为循环播放 */
);
// 暂停音乐
void Pause(
const String& file_path /* 音乐文件路径 */
);
// 继续播放音乐
void Resume(
const String& file_path /* 音乐文件路径 */
);
// 停止音乐
void Stop(
const String& file_path /* 音乐文件路径 */
);
// 获取音乐播放状态
bool IsPlaying(
const String& file_path /* 音乐文件路径 */
);
// 预加载音乐资源
bool Preload(
const Resource& res /* 音乐资源 */
);
// 播放音乐
bool Play(
const Resource& res, /* 音乐资源 */
int loop_count = 0 /* 重复播放次数,设置 -1 为循环播放 */
);
// 暂停音乐
void Pause(
const Resource& res /* 音乐资源 */
);
// 继续播放音乐
void Resume(
const Resource& res /* 音乐资源 */
);
// 停止音乐
void Stop(
const Resource& res /* 音乐资源 */
);
// 获取音乐播放状态
bool IsPlaying(
const Resource& res /* 音乐资源 */
);
// 获取音量
float GetVolume();
// 设置音量
void SetVolume(
float volume /* 音量范围为 -224 ~ 2240 是静音1 是正常音量 */
);
// 暂停所有音乐
void PauseAll();
// 继续播放所有音乐
void ResumeAll();
// 停止所有音乐
void StopAll();
// 清空音乐缓存
void ClearCache();
protected:
Player();
~Player();
E2D_DISABLE_COPY(Player);
protected:
float volume_;
std::map<size_t, Music*> musics_;
static Player * instance_;
};
class Timer;
class Timer;
// 定时任务
class Task :
public Ref
{
friend class Timer;
// 定时任务
class Task :
public Ref
{
friend class Timer;
public:
explicit Task(
const Function& func, /* 执行函数 */
const String& name = L"" /* 任务名称 */
);
public:
explicit Task(
const Function& func, /* 执行函数 */
const String& name = L"" /* 任务名称 */
);
explicit Task(
const Function& func, /* 执行函数 */
float delay, /* 时间间隔(秒) */
int times = -1, /* 执行次数(设 -1 为永久执行) */
const String& name = L"" /* 任务名称 */
);
explicit Task(
const Function& func, /* 执行函数 */
float delay, /* 时间间隔(秒) */
int times = -1, /* 执行次数(设 -1 为永久执行) */
const String& name = L"" /* 任务名称 */
);
// 启动任务
void Start();
// 启动任务
void Start();
// 停止任务
void Stop();
// 停止任务
void Stop();
// 任务是否正在执行
bool IsRunning() const;
// 任务是否正在执行
bool IsRunning() const;
// 获取任务名称
const String& GetName() const;
// 获取任务名称
const String& GetName() const;
protected:
// 执行任务
void Update();
protected:
// 执行任务
void Update();
// 任务是否就绪
bool IsReady() const;
// 任务是否就绪
bool IsReady() const;
protected:
bool running_;
bool stopped_;
int run_times_;
int total_times_;
String name_;
Duration delay_;
Time last_time_;
Function callback_;
};
protected:
bool running_;
bool stopped_;
int run_times_;
int total_times_;
String name_;
Duration delay_;
Time last_time_;
Function callback_;
};
// 定时器
class Timer
{
public:
// 获取定时器实例
static Timer * GetInstance();
// 定时器
class Timer
{
public:
// 获取定时器实例
static Timer * GetInstance();
// 添加任务
void AddTask(
Task * task
);
// 添加任务
void AddTask(
Task * task
);
// 启动任务
void StartTasks(
const String& task_name
);
// 启动任务
void StartTasks(
const String& task_name
);
// 停止任务
void StopTasks(
const String& task_name
);
// 停止任务
void StopTasks(
const String& task_name
);
// 移除任务
void RemoveTasks(
const String& task_name
);
// 移除任务
void RemoveTasks(
const String& task_name
);
// 启动所有任务
void StartAllTasks();
// 启动所有任务
void StartAllTasks();
// 停止所有任务
void StopAllTasks();
// 停止所有任务
void StopAllTasks();
// 移除所有任务
void RemoveAllTasks();
// 移除所有任务
void RemoveAllTasks();
// 更新定时器
void Update();
// 更新定时器
void Update();
// 刷新所有任务计时
void UpdateTime();
// 刷新所有任务计时
void UpdateTime();
private:
Timer();
private:
Timer();
~Timer();
~Timer();
E2D_DISABLE_COPY(Timer);
E2D_DISABLE_COPY(Timer);
private:
std::vector<Task*> tasks_;
};
private:
std::vector<Task*> tasks_;
};
// 数据管理工具
class Data
{
public:
Data(
const String& key, /* 键值 */
const String& field = L"Defalut" /* 字段名称 */
);
// 数据管理工具
class Data
{
public:
Data(
const String& key, /* 键值 */
const String& field = L"Defalut" /* 字段名称 */
);
// 该数据是否存在
bool Exists() const;
// 该数据是否存在
bool Exists() const;
// 保存 int 类型的值
bool SaveInt(
int value
);
// 保存 int 类型的值
bool SaveInt(
int value
);
// 保存 float 类型的值
bool SaveFloat(
float value
);
// 保存 double 类型的值
bool SaveDouble(
double value
);
// 保存 bool 类型的值
bool SaveBool(
bool value
);
// 保存 String 类型的值
bool SaveString(
const String& value
);
// 获取 int 类型的值
int GetInt() const;
// 保存 float 类型的值
bool SaveFloat(
float value
);
// 保存 double 类型的值
bool SaveDouble(
double value
);
// 保存 bool 类型的值
bool SaveBool(
bool value
);
// 保存 String 类型的值
bool SaveString(
const String& value
);
// 获取 int 类型的值
int GetInt() const;
// 获取 float 类型的值
float GetFloat() const;
// 获取 float 类型的值
float GetFloat() const;
// 获取 double 类型的值
double GetDouble() const;
// 获取 double 类型的值
double GetDouble() const;
// 获取 bool 类型的值
bool GetBool() const;
// 获取 bool 类型的值
bool GetBool() const;
// 获取 字符串 类型的值
String GetString();
// 获取 字符串 类型的值
String GetString();
protected:
String key_;
String field_;
const String& data_path_;
};
protected:
String key_;
String field_;
const String& data_path_;
};
// 文件
class File
{
public:
File();
// 文件
class File
{
public:
File();
File(
const String& file_name
);
File(
const String& file_name
);
virtual ~File();
virtual ~File();
// 打开文件
bool Open(
const String& file_name
);
// 打开文件
bool Open(
const String& file_name
);
// 文件或文件夹是否存在
bool Exists() const;
// 文件或文件夹是否存在
bool Exists() const;
// 是否是文件夹
bool IsFolder() const;
// 是否是文件夹
bool IsFolder() const;
// 删除文件
bool Delete();
// 删除文件
bool Delete();
// 获取文件路径
const String& GetPath() const;
// 获取文件路径
const String& GetPath() const;
// 获取文件扩展名
String GetExtension() const;
// 获取文件扩展名
String GetExtension() const;
// 释放资源到临时文件目录
static File Extract(
int resource_name, /* 资源名称 */
const String& resource_type, /* 资源类型 */
const String& dest_file_name /* 目标文件名 */
);
// 释放资源到临时文件目录
static File Extract(
int resource_name, /* 资源名称 */
const String& resource_type, /* 资源类型 */
const String& dest_file_name /* 目标文件名 */
);
// 添加文件搜索路径
static void AddSearchPath(
const String& path
);
// 创建文件夹
static bool CreateFolder(
const String& dir_path /* 文件夹路径 */
);
// 添加文件搜索路径
static void AddSearchPath(
const String& path
);
// 创建文件夹
static bool CreateFolder(
const String& dir_path /* 文件夹路径 */
);
// 弹出打开文件对话框
static File ShowOpenDialog(
const String& title = L"打开", /* 对话框标题 */
const String& filter = L"" /* 筛选扩展名,例如 "*.jpg;*.jpeg" */
);
// 弹出打开文件对话框
static File ShowOpenDialog(
const String& title = L"打开", /* 对话框标题 */
const String& filter = L"" /* 筛选扩展名,例如 "*.jpg;*.jpeg" */
);
// 弹出保存文件对话框
static File ShowSaveDialog(
const String& title = L"保存", /* 对话框标题 */
const String& def_file = L"", /* 默认保存的文件名 */
const String& def_ext = L"" /* 默认追加的扩展名,例如 "txt" */
);
// 弹出保存文件对话框
static File ShowSaveDialog(
const String& title = L"保存", /* 对话框标题 */
const String& def_file = L"", /* 默认保存的文件名 */
const String& def_ext = L"" /* 默认追加的扩展名,例如 "txt" */
);
protected:
DWORD attributes_;
String file_path_;
protected:
DWORD attributes_;
String file_path_;
static std::list<String> search_paths_;
};
static std::list<String> search_paths_;
};
// 路径
class Path
{
friend class Game;
// 路径
class Path
{
friend class Game;
public:
// 获取数据的默认保存路径
static const String& GetDataPath();
public:
// 获取数据的默认保存路径
static const String& GetDataPath();
// 获取临时文件目录
static const String& GetTemporaryPath();
// 获取临时文件目录
static const String& GetTemporaryPath();
// 获取 LocalAppData 目录
static const String& GetLocalAppDataPath();
// 获取 LocalAppData 目录
static const String& GetLocalAppDataPath();
// 获取当前程序的运行路径
static const String& GetExeFilePath();
};
// 获取当前程序的运行路径
static const String& GetExeFilePath();
};
}

View File

@ -5,145 +5,145 @@ namespace e2d
{
class Game;
class Scene;
class Game;
class Scene;
// 场景过渡
class Transition :
public Ref
{
friend class Game;
// 场景过渡
class Transition :
public Ref
{
friend class Game;
public:
explicit Transition(
Scene* scene,
float duration
);
public:
explicit Transition(
Scene* scene,
float duration
);
virtual ~Transition();
virtual ~Transition();
// 场景过渡动画是否结束
bool IsDone();
// 场景过渡动画是否结束
bool IsDone();
protected:
// 初始化场景过渡动画
virtual bool Init(
Game * game,
Scene * prev
);
protected:
// 初始化场景过渡动画
virtual bool Init(
Game * game,
Scene * prev
);
// 更新场景过渡动画
virtual void Update();
// 更新场景过渡动画
virtual void Update();
// 渲染场景过渡动画
virtual void Draw();
// 渲染场景过渡动画
virtual void Draw();
// 停止场景过渡动画
virtual void Stop();
// 停止场景过渡动画
virtual void Stop();
// 重置场景过渡动画
virtual void Reset() { };
// 重置场景过渡动画
virtual void Reset() { };
protected:
bool done_;
float duration_;
float delta_;
Time started_;
Scene* out_scene_;
Scene* in_scene_;
ID2D1Layer * out_layer_;
ID2D1Layer * in_layer_;
D2D1_LAYER_PARAMETERS out_layer_param_;
D2D1_LAYER_PARAMETERS in_layer_param_;
};
protected:
bool done_;
float duration_;
float delta_;
Time started_;
Scene* out_scene_;
Scene* in_scene_;
ID2D1Layer * out_layer_;
ID2D1Layer * in_layer_;
D2D1_LAYER_PARAMETERS out_layer_param_;
D2D1_LAYER_PARAMETERS in_layer_param_;
};
// 淡入淡出过渡
class FadeTransition :
public Transition
{
public:
explicit FadeTransition(
Scene* scene, /* 切换的场景 */
float duration /* 动画持续时长 */
);
// 淡入淡出过渡
class FadeTransition :
public Transition
{
public:
explicit FadeTransition(
Scene* scene, /* 切换的场景 */
float duration /* 动画持续时长 */
);
protected:
// 更新动画
virtual void Update() override;
protected:
// 更新动画
virtual void Update() override;
virtual bool Init(
Game * game,
Scene * prev
) override;
};
virtual bool Init(
Game * game,
Scene * prev
) override;
};
// 渐变过渡
class EmergeTransition :
public Transition
{
public:
explicit EmergeTransition(
Scene* scene, /* 切换的场景 */
float duration /* 浮现动画持续时长 */
);
// 渐变过渡
class EmergeTransition :
public Transition
{
public:
explicit EmergeTransition(
Scene* scene, /* 切换的场景 */
float duration /* 浮现动画持续时长 */
);
protected:
virtual void Update() override;
protected:
virtual void Update() override;
virtual bool Init(
Game * game,
Scene * prev
) override;
};
virtual bool Init(
Game * game,
Scene * prev
) override;
};
// 盒状过渡
class BoxTransition :
public Transition
{
public:
explicit BoxTransition(
Scene* scene, /* 切换的场景 */
float duration /* 动画持续时长 */
);
// 盒状过渡
class BoxTransition :
public Transition
{
public:
explicit BoxTransition(
Scene* scene, /* 切换的场景 */
float duration /* 动画持续时长 */
);
protected:
virtual void Update() override;
protected:
virtual void Update() override;
virtual bool Init(
Game * game,
Scene * prev
) override;
};
virtual bool Init(
Game * game,
Scene * prev
) override;
};
// 移入过渡
class MoveTransition :
public Transition
{
public:
explicit MoveTransition(
Scene* scene, /* 切换的场景 */
float moveDuration, /* 场景移动动画持续时长 */
Direction direction = Direction::Left /* 场景移动方向 */
);
// 移入过渡
class MoveTransition :
public Transition
{
public:
explicit MoveTransition(
Scene* scene, /* 切换的场景 */
float moveDuration, /* 场景移动动画持续时长 */
Direction direction = Direction::Left /* 场景移动方向 */
);
protected:
virtual void Update() override;
protected:
virtual void Update() override;
virtual bool Init(
Game * game,
Scene * prev
) override;
virtual bool Init(
Game * game,
Scene * prev
) override;
virtual void Reset() override;
virtual void Reset() override;
protected:
Direction direction_;
Point pos_delta_;
Point start_pos_;
};
protected:
Direction direction_;
Point pos_delta_;
Point start_pos_;
};
}

View File

@ -19,16 +19,17 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\core\e2dnode.h" />
<ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\e2daction.h" />
<ClInclude Include="..\..\core\e2dcommon.h" />
<ClInclude Include="..\..\core\e2dutil.h" />
<ClInclude Include="..\..\core\e2dcomponent.h" />
<ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\e2dimpl.h" />
<ClInclude Include="..\..\core\e2dmodule.h" />
<ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dutil.h" />
<ClInclude Include="..\..\core\e2dtool.h" />
<ClInclude Include="..\..\core\e2dtransition.h" />
</ItemGroup>
<ItemGroup>
@ -80,14 +81,14 @@
<ClCompile Include="..\..\core\Event\KeyEvent.cpp" />
<ClCompile Include="..\..\core\Event\MouseEvent.cpp" />
<ClCompile Include="..\..\core\Manager\CollisionManager.cpp" />
<ClCompile Include="..\..\core\Node\Button.cpp" />
<ClCompile Include="..\..\core\Node\Canvas.cpp" />
<ClCompile Include="..\..\core\Node\Scene.cpp" />
<ClCompile Include="..\..\core\Node\Menu.cpp" />
<ClCompile Include="..\..\core\Node\Node.cpp" />
<ClCompile Include="..\..\core\Node\Sprite.cpp" />
<ClCompile Include="..\..\core\Node\Text.cpp" />
<ClCompile Include="..\..\core\Node\ToggleButton.cpp" />
<ClCompile Include="..\..\core\Component\Button.cpp" />
<ClCompile Include="..\..\core\Component\ToggleButton.cpp" />
<ClCompile Include="..\..\core\Component\Menu.cpp" />
<ClCompile Include="..\..\core\Tool\Data.cpp" />
<ClCompile Include="..\..\core\Tool\File.cpp" />
<ClCompile Include="..\..\core\Tool\Music.cpp" />

View File

@ -32,15 +32,16 @@
<ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\e2daction.h" />
<ClInclude Include="..\..\core\e2dcommon.h" />
<ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dtransition.h" />
<ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\e2dutil.h" />
<ClInclude Include="..\..\core\e2dmodule.h" />
<ClInclude Include="..\..\core\e2dcomponent.h" />
<ClInclude Include="..\..\core\e2dimpl.h" />
<ClInclude Include="..\..\core\e2dnode.h" />
<ClInclude Include="..\..\core\e2dtool.h" />
<ClInclude Include="..\..\core\e2dutil.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\core\Action\Action.cpp">
@ -154,12 +155,6 @@
<ClCompile Include="..\..\core\Custom\VoiceCallback.cpp">
<Filter>Custom</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\Button.cpp">
<Filter>Node</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\Menu.cpp">
<Filter>Node</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\Node.cpp">
<Filter>Node</Filter>
</ClCompile>
@ -169,9 +164,6 @@
<ClCompile Include="..\..\core\Node\Text.cpp">
<Filter>Node</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\ToggleButton.cpp">
<Filter>Node</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Tool\Data.cpp">
<Filter>Tool</Filter>
</ClCompile>
@ -244,5 +236,14 @@
<ClCompile Include="..\..\core\Action\Callback.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Component\Button.cpp">
<Filter>Component</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Component\Menu.cpp">
<Filter>Component</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Component\ToggleButton.cpp">
<Filter>Component</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -163,16 +163,17 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\core\e2dnode.h" />
<ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\e2daction.h" />
<ClInclude Include="..\..\core\e2dcommon.h" />
<ClInclude Include="..\..\core\e2dutil.h" />
<ClInclude Include="..\..\core\e2dcomponent.h" />
<ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\e2dimpl.h" />
<ClInclude Include="..\..\core\e2dmodule.h" />
<ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dutil.h" />
<ClInclude Include="..\..\core\e2dtool.h" />
<ClInclude Include="..\..\core\e2dtransition.h" />
</ItemGroup>
<ItemGroup>
@ -224,14 +225,14 @@
<ClCompile Include="..\..\core\Event\KeyEvent.cpp" />
<ClCompile Include="..\..\core\Event\MouseEvent.cpp" />
<ClCompile Include="..\..\core\Manager\CollisionManager.cpp" />
<ClCompile Include="..\..\core\Node\Button.cpp" />
<ClCompile Include="..\..\core\Node\Canvas.cpp" />
<ClCompile Include="..\..\core\Node\Scene.cpp" />
<ClCompile Include="..\..\core\Node\Menu.cpp" />
<ClCompile Include="..\..\core\Node\Node.cpp" />
<ClCompile Include="..\..\core\Node\Sprite.cpp" />
<ClCompile Include="..\..\core\Node\Text.cpp" />
<ClCompile Include="..\..\core\Node\ToggleButton.cpp" />
<ClCompile Include="..\..\core\Component\Button.cpp" />
<ClCompile Include="..\..\core\Component\ToggleButton.cpp" />
<ClCompile Include="..\..\core\Component\Menu.cpp" />
<ClCompile Include="..\..\core\Tool\Data.cpp" />
<ClCompile Include="..\..\core\Tool\File.cpp" />
<ClCompile Include="..\..\core\Tool\Music.cpp" />

View File

@ -32,15 +32,16 @@
<ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\e2daction.h" />
<ClInclude Include="..\..\core\e2dcommon.h" />
<ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dtransition.h" />
<ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\e2dutil.h" />
<ClInclude Include="..\..\core\e2dmodule.h" />
<ClInclude Include="..\..\core\e2dcomponent.h" />
<ClInclude Include="..\..\core\e2dimpl.h" />
<ClInclude Include="..\..\core\e2dnode.h" />
<ClInclude Include="..\..\core\e2dtool.h" />
<ClInclude Include="..\..\core\e2dutil.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\core\Action\Action.cpp">
@ -154,12 +155,6 @@
<ClCompile Include="..\..\core\Custom\VoiceCallback.cpp">
<Filter>Custom</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\Button.cpp">
<Filter>Node</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\Menu.cpp">
<Filter>Node</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\Node.cpp">
<Filter>Node</Filter>
</ClCompile>
@ -169,9 +164,6 @@
<ClCompile Include="..\..\core\Node\Text.cpp">
<Filter>Node</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\ToggleButton.cpp">
<Filter>Node</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Tool\Data.cpp">
<Filter>Tool</Filter>
</ClCompile>
@ -244,5 +236,14 @@
<ClCompile Include="..\..\core\Action\Callback.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Component\Button.cpp">
<Filter>Component</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Component\Menu.cpp">
<Filter>Component</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Component\ToggleButton.cpp">
<Filter>Component</Filter>
</ClCompile>
</ItemGroup>
</Project>