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,10 +5,10 @@ namespace e2d
{
// 按键消息
class KeyEvent
{
public:
// 按键消息
class KeyEvent
{
public:
// 按键消息类型
enum class Type : int
{
@ -16,7 +16,7 @@ public:
Up // 抬起
};
public:
public:
explicit KeyEvent(
HWND hWnd,
UINT message,
@ -38,17 +38,17 @@ public:
WPARAM w_param
);
protected:
protected:
int count_;
KeyCode code_;
KeyEvent::Type type_;
};
};
// 鼠标消息
class MouseEvent
{
public:
// 鼠标消息
class MouseEvent
{
public:
// 鼠标消息类型
enum class Type : int
{
@ -65,7 +65,7 @@ public:
Wheel // 滑动滚轮
};
public:
public:
explicit MouseEvent(
HWND hWnd,
UINT message,
@ -103,19 +103,19 @@ public:
// Ctrl 键是否按下
bool IsCtrlDown() const;
protected:
protected:
UINT message_;
WPARAM w_param_;
LPARAM l_param_;
Point pos_;
MouseEvent::Type type_;
};
};
// 碰撞事件
class Collision
{
public:
// 碰撞事件
class Collision
{
public:
Collision();
explicit Collision(
@ -131,9 +131,9 @@ public:
// 获取交集关系
Collider::Relation GetRelation() const;
protected:
protected:
Node * node_;
Collider::Relation relation_;
};
};
}

View File

@ -5,13 +5,13 @@ namespace e2d
{
class Music;
class Music;
// 音源回调
class VoiceCallback
// 音源回调
class VoiceCallback
: public IXAudio2VoiceCallback
{
public:
{
public:
VoiceCallback();
~VoiceCallback();
@ -34,22 +34,22 @@ public:
STDMETHOD_(void, SetCallbackOnLoopEnd) (THIS_ const Function& func);
protected:
protected:
Function loop_end_callback_;
Function stream_end_callback_;
};
};
// 文字渲染器
class E2DTextRenderer
// 文字渲染器
class E2DTextRenderer
: public IDWriteTextRenderer
{
private:
{
private:
E2DTextRenderer();
~E2DTextRenderer();
public:
public:
static HRESULT Create(
E2DTextRenderer** ppTextRenderer,
ID2D1Factory* pD2DFactory,
@ -116,7 +116,7 @@ public:
__out FLOAT* pixelsPerDip
);
public:
public:
unsigned long STDMETHODCALLTYPE AddRef();
unsigned long STDMETHODCALLTYPE Release();
HRESULT STDMETHODCALLTYPE QueryInterface(
@ -124,7 +124,7 @@ public:
void** ppvObject
);
private:
private:
unsigned long cRefCount_;
D2D1_COLOR_F sFillColor_;
D2D1_COLOR_F sOutlineColor_;
@ -134,13 +134,13 @@ private:
ID2D1HwndRenderTarget* pRT_;
ID2D1SolidColorBrush* pBrush_;
ID2D1StrokeStyle * pCurrStrokeStyle_;
};
};
// 异常
class Exception
{
public:
// 异常
class Exception
{
public:
Exception() E2D_NOEXCEPT;
explicit Exception(const char * message) E2D_NOEXCEPT;
@ -154,35 +154,35 @@ public:
// 获取异常信息
virtual const char * GetMsg() const;
private:
private:
const char * message_;
};
};
// 系统异常
class SystemException
// 系统异常
class SystemException
: public Exception
{
public:
{
public:
SystemException() E2D_NOEXCEPT;
explicit SystemException(const char * message) E2D_NOEXCEPT;
};
};
template<class Interface>
inline void SafeRelease(Interface*& p)
{
template<class Interface>
inline void SafeRelease(Interface*& p)
{
if (p != nullptr)
{
p->Release();
p = nullptr;
}
}
}
inline void ThrowIfFailed(HRESULT hr)
{
inline void ThrowIfFailed(HRESULT hr)
{
if (FAILED(hr))
{
// 在此处设置断点以捕获 D2D API 异常.
@ -190,6 +190,6 @@ inline void ThrowIfFailed(HRESULT hr)
sprintf_s(s_str, "Failure with HRESULT of %08X", static_cast<unsigned int>(hr));
throw SystemException(s_str);
}
}
}
}

View File

@ -6,16 +6,16 @@ namespace e2d
{
class Node;
class Node;
// 碰撞体管理器
class CollisionManager
{
// 碰撞体管理器
class CollisionManager
{
friend class Node;
friend class Collider;
public:
public:
// 获取碰撞体管理器实例
static CollisionManager * GetInstance();
@ -48,7 +48,7 @@ public:
const String& name2
);
private:
private:
CollisionManager();
~CollisionManager();
@ -70,10 +70,10 @@ private:
Collider* collider
);
private:
private:
bool collision_enabled_;
std::vector<Collider*> colliders_;
std::set<std::pair<size_t, size_t>> collision_list_;
};
};
}

View File

@ -8,10 +8,10 @@ namespace e2d
{
// 窗体
class Window
{
public:
// 窗体
class Window
{
public:
// 鼠标指针样式
enum class Cursor : int
{
@ -30,7 +30,7 @@ public:
Error /* 错误 */
};
public:
public:
// 获取窗体实例
static Window * GetInstance();
@ -103,7 +103,7 @@ public:
// 处理窗体消息
void Poll();
private:
private:
Window();
~Window();
@ -124,7 +124,7 @@ private:
LPARAM l_param
);
private:
private:
HWND hWnd_;
MSG msg_;
int width_;
@ -134,13 +134,13 @@ private:
float dpi_;
static Window * instance_;
};
};
// 渲染器
class Renderer
{
public:
// 渲染器
class Renderer
{
public:
// 获取渲染器实例
static Renderer * GetInstance();
@ -194,14 +194,14 @@ public:
// 获取 Round 样式的 ID2D1StrokeStyle
static ID2D1StrokeStyle * GetRoundStrokeStyle();
protected:
protected:
Renderer();
~Renderer();
E2D_DISABLE_COPY(Renderer);
protected:
protected:
bool show_fps_;
int render_times_;
Time last_render_time_;
@ -219,13 +219,13 @@ protected:
static ID2D1StrokeStyle* bevel_stroke_style_;
static ID2D1StrokeStyle* round_stroke_style_;
static Renderer * instance_;
};
};
// 输入设备
class Input
{
public:
// 输入设备
class Input
{
public:
// 获取输入设备实例
static Input * GetInstance();
@ -263,14 +263,14 @@ public:
// 刷新输入设备状态
void Update();
protected:
protected:
Input();
~Input();
E2D_DISABLE_COPY(Input);
protected:
protected:
IDirectInput8W * direct_input_;
IDirectInputDevice8W* keyboard_device_;
IDirectInputDevice8W* mouse_device_;
@ -278,13 +278,13 @@ protected:
char key_buffer_[256];
static Input * instance_;
};
};
// 音频设备
class Audio
{
public:
// 音频设备
class Audio
{
public:
// 获取音频设备实例
static Audio * GetInstance();
@ -297,25 +297,25 @@ public:
// 获取 MasteringVoice 实例对象
IXAudio2MasteringVoice* GetMasteringVoice();
protected:
protected:
Audio();
virtual ~Audio();
E2D_DISABLE_COPY(Audio);
protected:
protected:
IXAudio2 * x_audio2_;
IXAudio2MasteringVoice* mastering_voice_;
static Audio * instance_;
};
};
// 游戏
class Game
{
public:
// 游戏
class Game
{
public:
// 获取 Game 实例
static Game * GetInstance();
@ -359,14 +359,14 @@ public:
// 渲染场景画面
void DrawScene();
protected:
protected:
Game();
~Game();
E2D_DISABLE_COPY(Game);
private:
private:
bool quit_;
bool paused_;
Scene* curr_scene_;
@ -374,13 +374,13 @@ private:
Transition* transition_;
static Game * instance_;
};
};
// 垃圾回收池
class GC
{
public:
// 垃圾回收池
class GC
{
public:
// 获取 GC 实例
static GC * GetInstance();
@ -397,17 +397,17 @@ public:
// 刷新内存池
void Flush();
private:
private:
GC();
~GC();
E2D_DISABLE_COPY(GC);
private:
private:
bool notifyed_;
bool cleanup_;
std::set<Ref*> pool_;
};
};
}

View File

@ -6,10 +6,10 @@ namespace e2d
{
// 随机数产生器
class Random
{
public:
// 随机数产生器
class Random
{
public:
// 取得范围内的一个整型随机数
template<typename T>
static inline T Range(T min, T max)
@ -29,7 +29,7 @@ public:
return e2d::Random::RandomReal(min, max);
}
private:
private:
template<typename T>
static T RandomInt(T min, T max)
{
@ -46,16 +46,16 @@ private:
// 获取随机数产生器
static std::default_random_engine &GetEngine();
};
};
// 音乐
class Music :
// 音乐
class Music :
public Ref
{
{
friend class VoiceCallback;
public:
public:
Music();
explicit Music(
@ -116,7 +116,7 @@ public:
// 获取 IXAudio2SourceVoice 对象
IXAudio2SourceVoice * GetSourceVoice() const;
protected:
protected:
bool _readMMIO();
bool _resetFile();
@ -132,7 +132,7 @@ protected:
const wchar_t * file_name
);
protected:
protected:
bool opened_;
DWORD size_;
CHAR* buffer_;
@ -143,13 +143,13 @@ protected:
WAVEFORMATEX* wfx_;
VoiceCallback callback_;
IXAudio2SourceVoice* voice_;
};
};
// 音乐播放器
class Player
{
public:
// 音乐播放器
class Player
{
public:
// 获取播放器实例
static Player * GetInstance();
@ -238,30 +238,30 @@ public:
// 清空音乐缓存
void ClearCache();
protected:
protected:
Player();
~Player();
E2D_DISABLE_COPY(Player);
protected:
protected:
float volume_;
std::map<size_t, Music*> musics_;
static Player * instance_;
};
};
class Timer;
class Timer;
// 定时任务
class Task :
// 定时任务
class Task :
public Ref
{
{
friend class Timer;
public:
public:
explicit Task(
const Function& func, /* 执行函数 */
const String& name = L"" /* 任务名称 */
@ -286,14 +286,14 @@ public:
// 获取任务名称
const String& GetName() const;
protected:
protected:
// 执行任务
void Update();
// 任务是否就绪
bool IsReady() const;
protected:
protected:
bool running_;
bool stopped_;
int run_times_;
@ -302,13 +302,13 @@ protected:
Duration delay_;
Time last_time_;
Function callback_;
};
};
// 定时器
class Timer
{
public:
// 定时器
class Timer
{
public:
// 获取定时器实例
static Timer * GetInstance();
@ -347,22 +347,22 @@ public:
// 刷新所有任务计时
void UpdateTime();
private:
private:
Timer();
~Timer();
E2D_DISABLE_COPY(Timer);
private:
private:
std::vector<Task*> tasks_;
};
};
// 数据管理工具
class Data
{
public:
// 数据管理工具
class Data
{
public:
Data(
const String& key, /* 键值 */
const String& field = L"Defalut" /* 字段名称 */
@ -411,17 +411,17 @@ public:
// 获取 字符串 类型的值
String GetString();
protected:
protected:
String key_;
String field_;
const String& data_path_;
};
};
// 文件
class File
{
public:
// 文件
class File
{
public:
File();
File(
@ -480,20 +480,20 @@ public:
const String& def_ext = L"" /* 默认追加的扩展名,例如 "txt" */
);
protected:
protected:
DWORD attributes_;
String file_path_;
static std::list<String> search_paths_;
};
};
// 路径
class Path
{
// 路径
class Path
{
friend class Game;
public:
public:
// 获取数据的默认保存路径
static const String& GetDataPath();
@ -505,6 +505,6 @@ public:
// 获取当前程序的运行路径
static const String& GetExeFilePath();
};
};
}

View File

@ -5,16 +5,16 @@ namespace e2d
{
class Game;
class Scene;
class Game;
class Scene;
// 场景过渡
class Transition :
// 场景过渡
class Transition :
public Ref
{
{
friend class Game;
public:
public:
explicit Transition(
Scene* scene,
float duration
@ -25,7 +25,7 @@ public:
// 场景过渡动画是否结束
bool IsDone();
protected:
protected:
// 初始化场景过渡动画
virtual bool Init(
Game * game,
@ -44,7 +44,7 @@ protected:
// 重置场景过渡动画
virtual void Reset() { };
protected:
protected:
bool done_;
float duration_;
float delta_;
@ -55,20 +55,20 @@ protected:
ID2D1Layer * in_layer_;
D2D1_LAYER_PARAMETERS out_layer_param_;
D2D1_LAYER_PARAMETERS in_layer_param_;
};
};
// 淡入淡出过渡
class FadeTransition :
// 淡入淡出过渡
class FadeTransition :
public Transition
{
public:
{
public:
explicit FadeTransition(
Scene* scene, /* 切换的场景 */
float duration /* 动画持续时长 */
);
protected:
protected:
// 更新动画
virtual void Update() override;
@ -76,61 +76,61 @@ protected:
Game * game,
Scene * prev
) override;
};
};
// 渐变过渡
class EmergeTransition :
// 渐变过渡
class EmergeTransition :
public Transition
{
public:
{
public:
explicit EmergeTransition(
Scene* scene, /* 切换的场景 */
float duration /* 浮现动画持续时长 */
);
protected:
protected:
virtual void Update() override;
virtual bool Init(
Game * game,
Scene * prev
) override;
};
};
// 盒状过渡
class BoxTransition :
// 盒状过渡
class BoxTransition :
public Transition
{
public:
{
public:
explicit BoxTransition(
Scene* scene, /* 切换的场景 */
float duration /* 动画持续时长 */
);
protected:
protected:
virtual void Update() override;
virtual bool Init(
Game * game,
Scene * prev
) override;
};
};
// 移入过渡
class MoveTransition :
// 移入过渡
class MoveTransition :
public Transition
{
public:
{
public:
explicit MoveTransition(
Scene* scene, /* 切换的场景 */
float moveDuration, /* 场景移动动画持续时长 */
Direction direction = Direction::Left /* 场景移动方向 */
);
protected:
protected:
virtual void Update() override;
virtual bool Init(
@ -140,10 +140,10 @@ protected:
virtual void Reset() override;
protected:
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>