refactoring

This commit is contained in:
Nomango 2018-10-03 18:04:04 +08:00
parent 9039dff8d3
commit ba99ca38c1
49 changed files with 619 additions and 1859 deletions

View File

@ -1,5 +1,4 @@
#include "..\e2daction.h" #include "..\e2daction.h"
#include "..\e2dmanager.h"
e2d::Action::Action() e2d::Action::Action()
: running_(false) : running_(false)

View File

@ -25,7 +25,7 @@ void e2d::JumpBy::Init()
if (target_) if (target_)
{ {
prev_pos_ = start_pos_ = target_->GetPos(); prev_pos_ = start_pos_ = target_->GetPosition();
} }
} }
@ -40,7 +40,7 @@ void e2d::JumpBy::Update()
float y = height_ * 4 * frac * (1 - frac); float y = height_ * 4 * frac * (1 - frac);
y += delta_pos_.y * delta_; y += delta_pos_.y * delta_;
Point currentPos = target_->GetPos(); Point currentPos = target_->GetPosition();
Point diff = currentPos - prev_pos_; Point diff = currentPos - prev_pos_;
start_pos_ = diff + start_pos_; start_pos_ = diff + start_pos_;

View File

@ -1,5 +1,4 @@
#include "..\e2daction.h" #include "..\e2daction.h"
#include "..\e2dmanager.h"
e2d::Loop::Loop(Action * action, int times /* = -1 */) e2d::Loop::Loop(Action * action, int times /* = -1 */)
: action_(action) : action_(action)

View File

@ -14,7 +14,7 @@ void e2d::MoveBy::Init()
if (target_) if (target_)
{ {
prev_pos_ = start_pos_ = target_->GetPos(); prev_pos_ = start_pos_ = target_->GetPosition();
} }
} }
@ -24,7 +24,7 @@ void e2d::MoveBy::Update()
if (target_) if (target_)
{ {
Point currentPos = target_->GetPos(); Point currentPos = target_->GetPosition();
Point diff = currentPos - prev_pos_; Point diff = currentPos - prev_pos_;
start_pos_ = start_pos_ + diff; start_pos_ = start_pos_ + diff;

View File

@ -1,5 +1,4 @@
#include "..\e2dcomponent.h" #include "..\e2dcomponent.h"
#include "..\e2dmanager.h"
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
#define SAFE_SET(pointer, func, ...) if (pointer) { pointer->##func(__VA_ARGS__); } #define SAFE_SET(pointer, func, ...) if (pointer) { pointer->##func(__VA_ARGS__); }
@ -148,7 +147,7 @@ bool e2d::Button::Dispatch(const MouseEvent & e, bool handled)
{ {
if (!handled && enabled_ && visible_ && normal_) if (!handled && enabled_ && visible_ && normal_)
{ {
bool contains = normal_->ContainsPoint(e.GetPos()); bool contains = normal_->ContainsPoint(e.GetPosition());
if (e.GetType() == MouseEvent::Type::LeftUp && is_selected_ && contains) if (e.GetType() == MouseEvent::Type::LeftUp && is_selected_ && contains)
{ {
if (callback_) if (callback_)
@ -200,13 +199,21 @@ void e2d::Button::Visit()
if (visible_ && if (visible_ &&
!enabled_ && !enabled_ &&
normal_ && normal_ &&
normal_->ContainsPoint(Input::GetInstance()->GetMousePos())) normal_->ContainsPoint(Device::GetInput()->GetMousePos()))
{ {
Window::GetInstance()->SetCursor(Window::Cursor::No); HCURSOR hcursor = ::LoadCursor(nullptr, IDC_NO);
if (hcursor)
{
::SetCursor(hcursor);
}
} }
else if (status_ == Status::Mouseover || status_ == Status::Selected) else if (status_ == Status::Mouseover || status_ == Status::Selected)
{ {
Window::GetInstance()->SetCursor(Window::Cursor::Hand); HCURSOR hcursor = ::LoadCursor(nullptr, IDC_HAND);
if (hcursor)
{
::SetCursor(hcursor);
}
} }
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "e2dutil.h" #include "e2dutil.h"
#include "e2dmodule.h" #include "e2dobject.h"
namespace e2d namespace e2d
{ {

View File

@ -73,7 +73,7 @@ namespace e2d
float GetY() const; float GetY() const;
// 获取鼠标坐标 // 获取鼠标坐标
Point GetPos() const; Point GetPosition() const;
// 获取事件类型 // 获取事件类型
MouseEvent::Type GetType() const; MouseEvent::Type GetType() const;

View File

@ -41,17 +41,17 @@ namespace e2d
// 文字渲染器 // 文字渲染器
class E2DTextRenderer class E2DTextRender
: public IDWriteTextRenderer : public IDWriteTextRenderer
{ {
private: private:
E2DTextRenderer(); E2DTextRender();
~E2DTextRenderer(); ~E2DTextRender();
public: public:
static HRESULT Create( static HRESULT Create(
E2DTextRenderer** ppTextRenderer, E2DTextRender** ppTextRenderer,
ID2D1Factory* pD2DFactory, ID2D1Factory* pD2DFactory,
ID2D1HwndRenderTarget* pRT, ID2D1HwndRenderTarget* pRT,
ID2D1SolidColorBrush* pBrush ID2D1SolidColorBrush* pBrush

View File

@ -57,6 +57,7 @@
#pragma comment(lib, "windowscodecs.lib") #pragma comment(lib, "windowscodecs.lib")
#pragma comment(lib, "winmm.lib") #pragma comment(lib, "winmm.lib")
#pragma comment(lib, "xaudio2.lib") #pragma comment(lib, "xaudio2.lib")
#pragma comment(lib, "dinput8.lib")
#ifndef HINST_THISCOMPONENT #ifndef HINST_THISCOMPONENT

View File

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

View File

@ -7,94 +7,16 @@
namespace e2d namespace e2d
{ {
// 图形设备
// 窗口
class Window
{
public:
// 鼠标指针样式
enum class Cursor : int
{
Normal, /* 默认指针样式 */
Hand, /* 手状指针 */
No, /* 禁止指针 */
Wait, /* 沙漏指针 */
ArrowWait /* 默认指针和小沙漏 */
};
// 弹窗样式
enum class PopupStyle : int
{
Info, /* 提示 */
Warning, /* 警告 */
Error /* 错误 */
};
public:
// 设置鼠标指针样式
static void SetCursor(
Cursor cursor
);
// 打开或隐藏控制台
static void ShowConsole(
bool enabled
);
// 弹出窗口
// 返回值:当窗口包含取消按钮时,返回值表示用户是否点击确认按钮
static bool Popup(
const String& text, /* 窗口内容 */
const String& title, /* 窗口标题 */
PopupStyle style = PopupStyle::Info,/* 弹窗样式 */
bool has_cancel = false /* 包含取消按钮 */
);
// 获取屏幕大小
static Size GetScreenSize();
};
// 渲染器
class Graphics class Graphics
{ {
public: public:
// 获取渲染器实例 Graphics(
static Graphics * Get(); HWND hwnd
// 获取 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();
// 获取文字渲染器
E2DTextRenderer * GetTextRenderer();
// 获取 ID2D1HwndRenderTarget 对象
ID2D1HwndRenderTarget * GetRenderTarget();
// 获取 ID2D1SolidColorBrush 对象
ID2D1SolidColorBrush * GetSolidBrush();
// 显示或隐藏 FPS
// 默认:隐藏
void ShowFps(
bool show
); );
~Graphics();
// 开始渲染 // 开始渲染
void BeginDraw(); void BeginDraw();
@ -104,31 +26,46 @@ namespace e2d
// 渲染调试信息 // 渲染调试信息
void DrawDebugInfo(); void DrawDebugInfo();
protected: // 获取 ID2D1Factory 对象
Graphics(); ID2D1Factory * GetFactory() const;
~Graphics(); // 获取 IWICImagingFactory 对象
IWICImagingFactory * GetImagingFactory() const;
E2D_DISABLE_COPY(Graphics); // 获取 IDWriteFactory 对象
IDWriteFactory * GetWriteFactory() const;
// 获取 ID2D1HwndRenderTarget 对象
ID2D1HwndRenderTarget * GetRenderTarget() const;
// 获取 ID2D1SolidColorBrush 对象
ID2D1SolidColorBrush * GetSolidBrush() const;
// 获取文字渲染工具
E2DTextRender * GetTextRender() const;
// 获取 Miter 样式的 ID2D1StrokeStyle
ID2D1StrokeStyle * GetMiterStrokeStyle();
// 获取 Bevel 样式的 ID2D1StrokeStyle
ID2D1StrokeStyle * GetBevelStrokeStyle();
// 获取 Round 样式的 ID2D1StrokeStyle
ID2D1StrokeStyle * GetRoundStrokeStyle();
protected: protected:
bool show_fps_;
int render_times_;
Time last_render_time_;
D2D1_COLOR_F clear_color_; D2D1_COLOR_F clear_color_;
E2DTextRenderer* text_renderer_; ID2D1Factory* factory_;
IWICImagingFactory* imaging_factory_;
IDWriteFactory* write_factory_;
ID2D1StrokeStyle* miter_stroke_style_;
ID2D1StrokeStyle* bevel_stroke_style_;
ID2D1StrokeStyle* round_stroke_style_;
E2DTextRender* text_renderer_;
IDWriteTextFormat* fps_text_format_; IDWriteTextFormat* fps_text_format_;
IDWriteTextLayout* fps_text_layout_; IDWriteTextLayout* fps_text_layout_;
ID2D1SolidColorBrush* solid_brush_; ID2D1SolidColorBrush* solid_brush_;
ID2D1HwndRenderTarget* render_target_; 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 Graphics * instance_;
}; };
@ -136,11 +73,11 @@ namespace e2d
class Input class Input
{ {
public: public:
// 获取输入设备实例 Input(
static Input * GetInstance(); HWND hwnd
);
// 销毁输入设备实例 ~Input();
static void DestroyInstance();
// 检测键盘某按键是否正被按下 // 检测键盘某按键是否正被按下
bool IsDown( bool IsDown(
@ -170,15 +107,8 @@ namespace e2d
// 获得鼠标Z轴鼠标滚轮坐标增量 // 获得鼠标Z轴鼠标滚轮坐标增量
float GetMouseDeltaZ(); float GetMouseDeltaZ();
// 刷新输入设备状态 // 刷新设备状态
void Update(); void Flush();
protected:
Input();
~Input();
E2D_DISABLE_COPY(Input);
protected: protected:
IDirectInput8W * direct_input_; IDirectInput8W * direct_input_;
@ -186,30 +116,28 @@ namespace e2d
IDirectInputDevice8W* mouse_device_; IDirectInputDevice8W* mouse_device_;
DIMOUSESTATE mouse_state_; DIMOUSESTATE mouse_state_;
char key_buffer_[256]; char key_buffer_[256];
static Input * instance_;
}; };
// 音频设备 // 音频设备
class Audio class Audio
{ {
public: public:
// 获取音频设备实例
static Audio * Get();
// 获取 XAudio2 实例对象
IXAudio2 * GetXAudio2() const;
// 获取 MasteringVoice 实例对象
IXAudio2MasteringVoice* GetMasteringVoice() const;
protected:
Audio(); Audio();
virtual ~Audio(); ~Audio();
E2D_DISABLE_COPY(Audio); // 开启设备
void Open();
// 关闭设备
void Close();
// 创建音源
HRESULT CreateVoice(
IXAudio2SourceVoice ** voice,
WAVEFORMATEX * wfx,
VoiceCallback * callback
);
protected: protected:
IXAudio2 * x_audio2_; IXAudio2 * x_audio2_;
@ -217,22 +145,43 @@ namespace e2d
}; };
// 选项 // 设备
struct Option class Device
{ {
String title; // 窗口标题 public:
int width; // 窗口宽度 // 获取图形设备
int height; // 窗口高度 static Graphics * GetGraphics();
int icon; // 窗口图标
Color background_color; // 背景色
bool debug_mode; // Debug 模式
Option() // 获取输入设备
static Input * GetInput();
// 获取音频设备
static Audio * GetAudio();
// 初始化
static void Init(
HWND hwnd
);
// 销毁资源
static void Destroy();
};
// 启动选项
struct Options
{
String title; // 标题
int width; // 宽度
int height; // 高度
int icon; // 图标资源 ID
bool debug_mode; // 调试模式
Options()
: title(L"Easy2D Game") : title(L"Easy2D Game")
, width(640) , width(640)
, height(480) , height(480)
, icon(0) , icon(0)
, background_color(Color::Black)
, debug_mode(false) , debug_mode(false)
{ {
} }
@ -243,34 +192,17 @@ namespace e2d
class Game class Game
{ {
public: public:
static Game * New( // 开始
const Option& option virtual void Start() = 0;
// 运行
void Run(
const Options& options = Options()
); );
// 获取控制器 // 结束
static Game * Get();
// 启动游戏
void Run();
// 结束游戏
void Quit(); void Quit();
// 获取窗体标题
const String& GetTitle() const;
// 获取窗体宽度
int GetWidth() const;
// 获取窗体高度
int GetHeight() const;
// 获取窗体大小
Size GetSize() const;
// 获取窗口句柄
HWND GetHWnd() const;
// 修改窗体大小 // 修改窗体大小
void SetSize( void SetSize(
int width, /* 窗体宽度 */ int width, /* 窗体宽度 */
@ -287,6 +219,21 @@ namespace e2d
int resource_id /* 图标资源 ID */ int resource_id /* 图标资源 ID */
); );
// 获取窗体标题
const String& GetTitle() const;
// 获取窗体宽度
int GetWidth() const;
// 获取窗体高度
int GetHeight() const;
// 获取窗体大小
Size GetSize() const;
// 获取窗口句柄
HWND GetHWnd() const;
// 切换场景 // 切换场景
void EnterScene( void EnterScene(
Scene * scene, /* 场景 */ Scene * scene, /* 场景 */
@ -296,7 +243,7 @@ namespace e2d
// 获取当前场景 // 获取当前场景
Scene * GetCurrentScene(); Scene * GetCurrentScene();
// 是否正在进行场景动画 // 是否正在进行场景过渡
bool IsTransitioning() const; bool IsTransitioning() const;
// 更新场景内容 // 更新场景内容
@ -305,13 +252,14 @@ namespace e2d
// 渲染场景画面 // 渲染场景画面
void DrawScene(); void DrawScene();
// 获取实例
static Game * GetInstance();
protected: protected:
Game(); Game();
~Game(); ~Game();
E2D_DISABLE_COPY(Game);
// 初始化 // 初始化
void Init(); void Init();
@ -329,7 +277,7 @@ namespace e2d
LPARAM l_param LPARAM l_param
); );
private: protected:
HWND hwnd_; HWND hwnd_;
String title_; String title_;
int width_; int width_;
@ -340,22 +288,6 @@ namespace e2d
Scene* curr_scene_; Scene* curr_scene_;
Scene* next_scene_; Scene* next_scene_;
Transition* transition_; Transition* transition_;
static Game * instance_;
};
// 垃圾回收
class GC
{
private:
GC();
~GC();
E2D_DISABLE_COPY(GC);
static GC instance_;
}; };
} }

View File

@ -80,22 +80,7 @@ namespace e2d
const Rect& GetCropRect() const; const Rect& GetCropRect() const;
// 获取 ID2D1Bitmap 对象 // 获取 ID2D1Bitmap 对象
ID2D1Bitmap * GetBitmap(); ID2D1Bitmap * GetBitmap() const;
// 设置 Bitmap
void SetBitmap(
ID2D1Bitmap * bitmap
);
// 预加载图片资源
static bool Preload(
const String& file_name
);
// 预加载图片资源
static bool Preload(
const Resource& res
);
// 清空缓存 // 清空缓存
static void ClearCache(); static void ClearCache();
@ -103,6 +88,21 @@ namespace e2d
protected: protected:
E2D_DISABLE_COPY(Image); E2D_DISABLE_COPY(Image);
// 加载图片资源
bool Load(
const String& file_name
);
// 加载图片资源
bool Load(
const Resource& res
);
// 设置 Bitmap
void SetBitmap(
ID2D1Bitmap * bitmap
);
protected: protected:
Rect crop_rect_; Rect crop_rect_;
ID2D1Bitmap * bitmap_; ID2D1Bitmap * bitmap_;
@ -174,132 +174,6 @@ namespace e2d
}; };
// 碰撞体
class Collider
{
public:
// 碰撞体形状
enum class Shape
{
None, /* 无 */
Rect, /* 矩形 */
Circle, /* 圆形 */
Ellipse /* 椭圆形 */
};
// 碰撞体交集关系
enum class Relation : int
{
Unknown = 0, /* 关系不确定 */
Disjoin = 1, /* 没有交集 */
IsContained = 2, /* 完全被包含 */
Contains = 3, /* 完全包含 */
Overlap = 4 /* 部分重叠 */
};
public:
explicit Collider(
Node * parent
);
virtual ~Collider();
// 设置碰撞体形状
void SetShape(
Shape shape
);
// 是否触发碰撞事件
void SetCollisionNotify(
bool notify
);
// 启用或关闭该碰撞体
void SetEnabled(
bool enabled
);
// 设置碰撞体的可见性
void SetVisible(
bool visible
);
// 设置绘制颜色
void SetBorderColor(
const Color& color
);
// 判断两碰撞体的交集关系
Relation GetRelationWith(
Collider * collider
) const;
// 是否启用碰撞体
bool IsEnabled() const;
// 是否可见
bool IsVisible() const;
// 是否触发碰撞事件
bool IsCollisionNotify() const;
// 获取绘制颜色
const Color& GetBorderColor() const;
// 获取形状
Shape GetShape() const;
// 获取绑定节点
Node* GetNode() const;
// 获取 ID2D1Geometry* 对象
ID2D1Geometry* GetGeometry() const;
// 重新生成
void Recreate();
// 渲染碰撞体
void Draw();
protected:
E2D_DISABLE_COPY(Collider);
protected:
bool enabled_;
bool visible_;
bool notify_;
Color border_color_;
Node * parent_node_;
Shape shape_;
ID2D1Geometry* geometry_;
};
// 碰撞事件
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_;
};
// 定时任务 // 定时任务
class Task class Task
: public Ref : public Ref
@ -353,24 +227,6 @@ namespace e2d
}; };
// 绘图接口
class Drawable
{
public:
// 渲染图形
virtual void Draw() const = 0;
};
// 更新接口
class Updatable
{
public:
// 渲染图形
virtual void Update() = 0;
};
// 按键消息处理接口 // 按键消息处理接口
class KeyEventHandler class KeyEventHandler
{ {
@ -389,15 +245,6 @@ namespace e2d
}; };
// 碰撞消息处理接口
class CollisionHandler
{
public:
// 处理碰撞消息
virtual void Handle(Collision collision) = 0;
};
class Action; class Action;
// 节点 // 节点
@ -406,7 +253,6 @@ namespace e2d
{ {
friend class Game; friend class Game;
friend class Scene; friend class Scene;
friend class Collider;
public: public:
typedef std::vector<Node*> Nodes; typedef std::vector<Node*> Nodes;
@ -429,14 +275,8 @@ namespace e2d
// 获取节点绘图顺序 // 获取节点绘图顺序
int GetOrder() const; int GetOrder() const;
// 获取节点横坐标
float GetPosX() const;
// 获取节点纵坐标
float GetPosY() const;
// 获取节点坐标 // 获取节点坐标
const Point& GetPos() const; const Point& GetPosition() const;
// 获取节点宽度 // 获取节点宽度
float GetWidth() const; float GetWidth() const;
@ -483,9 +323,6 @@ namespace e2d
// 获取节点透明度 // 获取节点透明度
float GetOpacity() const; float GetOpacity() const;
// 获取节点碰撞体
Collider * GetCollider();
// 获取父节点 // 获取父节点
Node * GetParent() const; Node * GetParent() const;
@ -769,6 +606,15 @@ namespace e2d
// 获取所有任务 // 获取所有任务
const Tasks& GetAllTasks() const; const Tasks& GetAllTasks() const;
// 渲染节点
virtual void Draw() const {}
// 更新节点
virtual void Update() {}
// 渲染节点边缘
void DrawBorder();
// 分发鼠标消息 // 分发鼠标消息
virtual bool Dispatch( virtual bool Dispatch(
const MouseEvent& e, const MouseEvent& e,
@ -787,12 +633,6 @@ namespace e2d
// 遍历节点 // 遍历节点
virtual void Visit(); virtual void Visit();
// 渲染节点边缘
void DrawBorder();
// 渲染碰撞体轮廓
void DrawCollider();
// 设置节点所在场景 // 设置节点所在场景
void SetParentScene( void SetParentScene(
Scene * scene Scene * scene
@ -824,7 +664,6 @@ namespace e2d
bool clip_enabled_; bool clip_enabled_;
bool dirty_sort_; bool dirty_sort_;
bool dirty_transform_; bool dirty_transform_;
Collider collider_;
Scene * parent_scene_; Scene * parent_scene_;
Node * parent_; Node * parent_;
Color border_color_; Color border_color_;
@ -840,7 +679,6 @@ namespace e2d
// 精灵 // 精灵
class Sprite class Sprite
: public Node : public Node
, public Drawable
{ {
public: public:
Sprite(); Sprite();
@ -906,7 +744,6 @@ namespace e2d
// 文本 // 文本
class Text class Text
: public Node : public Node
, public Drawable
{ {
public: public:
// 文本对齐方式 // 文本对齐方式
@ -1124,7 +961,6 @@ namespace e2d
// 画布 // 画布
class Canvas class Canvas
: public Node : public Node
, public Drawable
{ {
public: public:
Canvas( Canvas(

View File

@ -144,113 +144,6 @@ namespace e2d
}; };
// 音乐播放器
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 Data class Data
{ {

View File

@ -28,7 +28,8 @@ namespace e2d
// 初始化场景过渡动画 // 初始化场景过渡动画
virtual void Init( virtual void Init(
Scene * prev, Scene * prev,
Scene * next Scene * next,
Game * game
); );
// 更新场景过渡动画 // 更新场景过渡动画
@ -73,7 +74,8 @@ namespace e2d
virtual void Init( virtual void Init(
Scene * prev, Scene * prev,
Scene * next Scene * next,
Game * game
) override; ) override;
}; };
@ -92,7 +94,8 @@ namespace e2d
virtual void Init( virtual void Init(
Scene * prev, Scene * prev,
Scene * next Scene * next,
Game * game
) override; ) override;
}; };
@ -111,7 +114,8 @@ namespace e2d
virtual void Init( virtual void Init(
Scene * prev, Scene * prev,
Scene * next Scene * next,
Game * game
) override; ) override;
}; };
@ -131,7 +135,8 @@ namespace e2d
virtual void Init( virtual void Init(
Scene * prev, Scene * prev,
Scene * next Scene * next,
Game * game
) override; ) override;
virtual void Reset() override; virtual void Reset() override;
@ -158,7 +163,8 @@ namespace e2d
virtual void Init( virtual void Init(
Scene * prev, Scene * prev,
Scene * next Scene * next,
Game * game
) override; ) override;
virtual void Reset() override; virtual void Reset() override;

View File

@ -604,13 +604,6 @@ namespace e2d
// 二维转换 // 二维转换
class Transform class Transform
{ {
public:
Transform();
E2D_OP_EXPLICIT operator D2D1::Matrix3x2F() const;
bool operator== (const Transform& other) const;
public: public:
Point position; // 坐标 Point position; // 坐标
Size size; // 大小 Size size; // 大小
@ -621,6 +614,13 @@ namespace e2d
float skew_y; // 纵向倾斜角度 float skew_y; // 纵向倾斜角度
float pivot_x; // 支点横坐标 float pivot_x; // 支点横坐标
float pivot_y; // 支点纵坐标 float pivot_y; // 支点纵坐标
public:
Transform();
E2D_OP_EXPLICIT operator D2D1::Matrix3x2F() const;
bool operator== (const Transform& other) const;
}; };
@ -641,9 +641,6 @@ namespace e2d
// 获取引用计数 // 获取引用计数
LONG GetRefCount() const; LONG GetRefCount() const;
protected:
E2D_DISABLE_COPY(Ref);
protected: protected:
LONG ref_count_; LONG ref_count_;
}; };

View File

@ -19,7 +19,6 @@
#include "e2dmacros.h" #include "e2dmacros.h"
#include "e2dutil.h" #include "e2dutil.h"
#include "e2dmanager.h"
#include "e2dobject.h" #include "e2dobject.h"
#include "e2dcomponent.h" #include "e2dcomponent.h"
#include "e2dtool.h" #include "e2dtool.h"

View File

@ -1,27 +0,0 @@
#include "..\e2dobject.h"
e2d::Collision::Collision()
: node_(nullptr)
, relation_(Collider::Relation::Unknown)
{
}
e2d::Collision::Collision(Node* node, Collider::Relation relation)
: node_(node)
, relation_(relation)
{
}
e2d::Collision::~Collision()
{
}
e2d::Node * e2d::Collision::GetNode() const
{
return node_;
}
e2d::Collider::Relation e2d::Collision::GetRelation() const
{
return relation_;
}

View File

@ -10,22 +10,26 @@ e2d::MouseEvent::MouseEvent(UINT message, WPARAM w_param, LPARAM l_param)
float e2d::MouseEvent::GetX() const float e2d::MouseEvent::GetX() const
{ {
const float dpi = Window::GetInstance()->GetDpi(); HDC hdc = ::GetDC(0);
return ((float)(short)LOWORD(l_param_)) * 96.f / dpi; int dpi_x = ::GetDeviceCaps(hdc, LOGPIXELSX);
return ((float)(short)LOWORD(l_param_)) * 96.f / dpi_x;
} }
float e2d::MouseEvent::GetY() const float e2d::MouseEvent::GetY() const
{ {
const float dpi = Window::GetInstance()->GetDpi(); HDC hdc = ::GetDC(0);
return ((float)(short)HIWORD(l_param_)) * 96.f / dpi; int dpi_y = ::GetDeviceCaps(hdc, LOGPIXELSY);
return ((float)(short)HIWORD(l_param_)) * 96.f / dpi_y;
} }
e2d::Point e2d::MouseEvent::GetPos() const e2d::Point e2d::MouseEvent::GetPosition() const
{ {
const float dpi = Window::GetInstance()->GetDpi(); HDC hdc = ::GetDC(0);
int dpi_x = ::GetDeviceCaps(hdc, LOGPIXELSX);
int dpi_y = ::GetDeviceCaps(hdc, LOGPIXELSY);
return Point( return Point(
((float)(short)LOWORD(l_param_)) * 96.f / dpi, ((float)(short)LOWORD(l_param_)) * 96.f / dpi_x,
((float)(short)HIWORD(l_param_)) * 96.f / dpi ((float)(short)HIWORD(l_param_)) * 96.f / dpi_y
); );
} }

View File

@ -3,7 +3,7 @@
using namespace e2d; using namespace e2d;
E2DTextRenderer::E2DTextRenderer() E2DTextRender::E2DTextRender()
: cRefCount_(0) : cRefCount_(0)
, pD2DFactory_(nullptr) , pD2DFactory_(nullptr)
, pRT_(nullptr) , pRT_(nullptr)
@ -16,21 +16,21 @@ E2DTextRenderer::E2DTextRenderer()
{ {
} }
E2DTextRenderer::~E2DTextRenderer() E2DTextRender::~E2DTextRender()
{ {
SafeRelease(pD2DFactory_); SafeRelease(pD2DFactory_);
SafeRelease(pRT_); SafeRelease(pRT_);
SafeRelease(pBrush_); SafeRelease(pBrush_);
} }
HRESULT E2DTextRenderer::Create( HRESULT E2DTextRender::Create(
E2DTextRenderer** ppTextRenderer, E2DTextRender** ppTextRenderer,
ID2D1Factory* pD2DFactory, ID2D1Factory* pD2DFactory,
ID2D1HwndRenderTarget* pRT, ID2D1HwndRenderTarget* pRT,
ID2D1SolidColorBrush* pBrush ID2D1SolidColorBrush* pBrush
) )
{ {
*ppTextRenderer = new (std::nothrow) E2DTextRenderer(); *ppTextRenderer = new (std::nothrow) E2DTextRender();
if (*ppTextRenderer) if (*ppTextRenderer)
{ {
pD2DFactory->AddRef(); pD2DFactory->AddRef();
@ -46,7 +46,7 @@ HRESULT E2DTextRenderer::Create(
return E_FAIL; return E_FAIL;
} }
STDMETHODIMP_(void) E2DTextRenderer::SetTextStyle( STDMETHODIMP_(void) E2DTextRender::SetTextStyle(
CONST D2D1_COLOR_F &fillColor, CONST D2D1_COLOR_F &fillColor,
BOOL outline, BOOL outline,
CONST D2D1_COLOR_F &outline_color, CONST D2D1_COLOR_F &outline_color,
@ -62,13 +62,13 @@ STDMETHODIMP_(void) E2DTextRenderer::SetTextStyle(
switch (outlineJoin) switch (outlineJoin)
{ {
case D2D1_LINE_JOIN_MITER: case D2D1_LINE_JOIN_MITER:
pCurrStrokeStyle_ = Graphics::GetMiterStrokeStyle(); pCurrStrokeStyle_ = Device::GetGraphics()->GetMiterStrokeStyle();
break; break;
case D2D1_LINE_JOIN_BEVEL: case D2D1_LINE_JOIN_BEVEL:
pCurrStrokeStyle_ = Graphics::GetBevelStrokeStyle(); pCurrStrokeStyle_ = Device::GetGraphics()->GetBevelStrokeStyle();
break; break;
case D2D1_LINE_JOIN_ROUND: case D2D1_LINE_JOIN_ROUND:
pCurrStrokeStyle_ = Graphics::GetRoundStrokeStyle(); pCurrStrokeStyle_ = Device::GetGraphics()->GetRoundStrokeStyle();
break; break;
default: default:
pCurrStrokeStyle_ = nullptr; pCurrStrokeStyle_ = nullptr;
@ -76,7 +76,7 @@ STDMETHODIMP_(void) E2DTextRenderer::SetTextStyle(
} }
} }
STDMETHODIMP E2DTextRenderer::DrawGlyphRun( STDMETHODIMP E2DTextRender::DrawGlyphRun(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
FLOAT baselineOriginX, FLOAT baselineOriginX,
FLOAT baselineOriginY, FLOAT baselineOriginY,
@ -165,7 +165,7 @@ STDMETHODIMP E2DTextRenderer::DrawGlyphRun(
return hr; return hr;
} }
STDMETHODIMP E2DTextRenderer::DrawUnderline( STDMETHODIMP E2DTextRender::DrawUnderline(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
FLOAT baselineOriginX, FLOAT baselineOriginX,
FLOAT baselineOriginY, FLOAT baselineOriginY,
@ -232,7 +232,7 @@ STDMETHODIMP E2DTextRenderer::DrawUnderline(
return S_OK; return S_OK;
} }
STDMETHODIMP E2DTextRenderer::DrawStrikethrough( STDMETHODIMP E2DTextRender::DrawStrikethrough(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
FLOAT baselineOriginX, FLOAT baselineOriginX,
FLOAT baselineOriginY, FLOAT baselineOriginY,
@ -299,7 +299,7 @@ STDMETHODIMP E2DTextRenderer::DrawStrikethrough(
return S_OK; return S_OK;
} }
STDMETHODIMP E2DTextRenderer::DrawInlineObject( STDMETHODIMP E2DTextRender::DrawInlineObject(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
FLOAT originX, FLOAT originX,
FLOAT originY, FLOAT originY,
@ -312,12 +312,12 @@ STDMETHODIMP E2DTextRenderer::DrawInlineObject(
return E_NOTIMPL; return E_NOTIMPL;
} }
STDMETHODIMP_(unsigned long) E2DTextRenderer::AddRef() STDMETHODIMP_(unsigned long) E2DTextRender::AddRef()
{ {
return InterlockedIncrement(&cRefCount_); return InterlockedIncrement(&cRefCount_);
} }
STDMETHODIMP_(unsigned long) E2DTextRenderer::Release() STDMETHODIMP_(unsigned long) E2DTextRender::Release()
{ {
unsigned long newCount = InterlockedDecrement(&cRefCount_); unsigned long newCount = InterlockedDecrement(&cRefCount_);
@ -330,7 +330,7 @@ STDMETHODIMP_(unsigned long) E2DTextRenderer::Release()
return newCount; return newCount;
} }
STDMETHODIMP E2DTextRenderer::IsPixelSnappingDisabled( STDMETHODIMP E2DTextRender::IsPixelSnappingDisabled(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
__out BOOL* isDisabled __out BOOL* isDisabled
) )
@ -339,7 +339,7 @@ STDMETHODIMP E2DTextRenderer::IsPixelSnappingDisabled(
return S_OK; return S_OK;
} }
STDMETHODIMP E2DTextRenderer::GetCurrentTransform( STDMETHODIMP E2DTextRender::GetCurrentTransform(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
__out DWRITE_MATRIX* transform __out DWRITE_MATRIX* transform
) )
@ -348,7 +348,7 @@ STDMETHODIMP E2DTextRenderer::GetCurrentTransform(
return S_OK; return S_OK;
} }
STDMETHODIMP E2DTextRenderer::GetPixelsPerDip( STDMETHODIMP E2DTextRender::GetPixelsPerDip(
__maybenull void* clientDrawingContext, __maybenull void* clientDrawingContext,
__out FLOAT* pixelsPerDip __out FLOAT* pixelsPerDip
) )
@ -361,7 +361,7 @@ STDMETHODIMP E2DTextRenderer::GetPixelsPerDip(
return S_OK; return S_OK;
} }
STDMETHODIMP E2DTextRenderer::QueryInterface( STDMETHODIMP E2DTextRender::QueryInterface(
IID const& riid, IID const& riid,
void** ppvObject void** ppvObject
) )

View File

@ -1,126 +0,0 @@
#include "..\e2dmanager.h"
#include "..\e2dobject.h"
#include "..\e2dtool.h"
#include "..\e2dmodule.h"
e2d::CollisionManager * e2d::CollisionManager::GetInstance()
{
static CollisionManager instance;
return &instance;
}
e2d::CollisionManager::CollisionManager()
: collision_enabled_(false)
{
}
e2d::CollisionManager::~CollisionManager()
{
}
void e2d::CollisionManager::AddCollider(Collider * collider)
{
colliders_.push_back(collider);
}
void e2d::CollisionManager::RemoveCollider(Collider * collider)
{
auto iter = std::find(colliders_.begin(), colliders_.end(), collider);
if (iter != colliders_.end())
{
colliders_.erase(iter);
}
}
void e2d::CollisionManager::UpdateCollider(Collider* active)
{
if (!collision_enabled_ ||
Game::Get()->IsTransitioning())
return;
auto currScene = Game::Get()->GetCurrentScene();
if (active->GetNode()->GetParentScene() != currScene)
return;
std::vector<Collider*> currColliders;
currColliders.reserve(colliders_.size());
std::copy_if(
colliders_.begin(),
colliders_.end(),
std::back_inserter(currColliders),
[this, active, currScene](Collider* passive) -> bool
{
return active != passive &&
passive->GetNode()->IsVisible() &&
passive->GetNode()->GetParentScene() == currScene &&
this->IsCollidable(active->GetNode(), passive->GetNode());
}
);
for (const auto& passive : currColliders)
{
// 判断两碰撞体交集情况
Collider::Relation relation = active->GetRelationWith(passive);
// 忽略 UNKNOWN 和 DISJOIN 情况
if (relation != Collider::Relation::Unknown &&
relation != Collider::Relation::Disjoin)
{
auto activeNode = active->GetNode();
auto passiveNode = passive->GetNode();
// 触发两次碰撞事件
Collision activeCollision(passiveNode, relation);
if (dynamic_cast<CollisionHandler*>(activeNode))
dynamic_cast<CollisionHandler*>(activeNode)->Handle(activeCollision);
Collision passiveCollision(activeNode, passive->GetRelationWith(active));
if (dynamic_cast<CollisionHandler*>(passiveNode))
dynamic_cast<CollisionHandler*>(passiveNode)->Handle(passiveCollision);
}
}
}
void e2d::CollisionManager::SetCollisionEnabled(bool enabled)
{
collision_enabled_ = enabled;
}
void e2d::CollisionManager::AddName(const String & name1, const String & name2)
{
if (!name1.IsEmpty() && !name2.IsEmpty())
{
collision_list_.insert(std::make_pair(name1.GetHash(), name2.GetHash()));
}
}
void e2d::CollisionManager::AddName(const std::vector<std::pair<String, String> >& names)
{
for (const auto& name : names)
{
if (!name.first.IsEmpty() && !name.second.IsEmpty())
{
collision_list_.insert(std::make_pair(name.first.GetHash(), name.second.GetHash()));
}
}
}
bool e2d::CollisionManager::IsCollidable(Node * node1, Node * node2)
{
return CollisionManager::IsCollidable(node1->GetName(), node2->GetName());
}
bool e2d::CollisionManager::IsCollidable(const String & name1, const String & name2)
{
size_t hashName1 = name1.GetHash(),
hashName2 = name2.GetHash();
auto pair1 = std::make_pair(hashName1, hashName2),
pair2 = std::make_pair(hashName2, hashName1);
for (const auto& pair : collision_list_)
{
if (pair == pair1 || pair == pair2)
{
return true;
}
}
return false;
}

View File

@ -1,12 +1,6 @@
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
e2d::Audio * e2d::Audio::Get()
{
static Audio audio;
return &audio;
}
e2d::Audio::Audio() e2d::Audio::Audio()
: x_audio2_(nullptr) : x_audio2_(nullptr)
, mastering_voice_(nullptr) , mastering_voice_(nullptr)
@ -35,12 +29,17 @@ e2d::Audio::~Audio()
::CoUninitialize(); ::CoUninitialize();
} }
IXAudio2 * e2d::Audio::GetXAudio2() const HRESULT e2d::Audio::CreateVoice(IXAudio2SourceVoice ** voice, WAVEFORMATEX * wfx, VoiceCallback * callback)
{ {
return x_audio2_; return x_audio2_->CreateSourceVoice(voice, wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, callback);;
} }
IXAudio2MasteringVoice * e2d::Audio::GetMasteringVoice() const void e2d::Audio::Open()
{ {
return mastering_voice_; x_audio2_->StartEngine();
}
void e2d::Audio::Close()
{
x_audio2_->StopEngine();
} }

48
core/modules/Device.cpp Normal file
View File

@ -0,0 +1,48 @@
#include "..\e2dmodule.h"
static e2d::Graphics * graphics_device = nullptr;
static e2d::Input * input_device = nullptr;
static e2d::Audio * audio_device = nullptr;
e2d::Graphics * e2d::Device::GetGraphics()
{
return graphics_device;
}
e2d::Input * e2d::Device::GetInput()
{
return input_device;
}
e2d::Audio * e2d::Device::GetAudio()
{
return audio_device;
}
void e2d::Device::Init(HWND hwnd)
{
graphics_device = new (std::nothrow) Graphics(hwnd);
input_device = new (std::nothrow) Input(hwnd);
audio_device = new (std::nothrow) Audio();
}
void e2d::Device::Destroy()
{
if (audio_device)
{
delete audio_device;
audio_device = nullptr;
}
if (input_device)
{
delete input_device;
input_device = nullptr;
}
if (graphics_device)
{
delete graphics_device;
graphics_device = nullptr;
}
}

View File

@ -1,21 +0,0 @@
#include "..\e2dmodule.h"
#include "..\e2dtool.h"
e2d::GC e2d::GC::instance_;
e2d::GC::GC()
{
}
e2d::GC::~GC()
{
Image::ClearCache();
Player::DestroyInstance();
Audio::DestroyInstance();
Graphics::DestroyInstance();
Input::DestroyInstance();
Window::DestroyInstance();
Game::DestroyInstance();
}

View File

@ -1,7 +1,7 @@
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
#include "..\e2dtool.h"
#include "..\e2dtransition.h" #include "..\e2dtransition.h"
#include "..\e2dmanager.h"
#include <thread> #include <thread>
#include <imm.h> #include <imm.h>
#pragma comment (lib ,"imm32.lib") #pragma comment (lib ,"imm32.lib")
@ -10,7 +10,7 @@
#define REGISTER_CLASS L"Easy2DApp" #define REGISTER_CLASS L"Easy2DApp"
e2d::Game * e2d::Game::instance_ = nullptr; static e2d::Game * instance = nullptr;
e2d::Game::Game() e2d::Game::Game()
: hwnd_(nullptr) : hwnd_(nullptr)
@ -18,7 +18,18 @@ e2d::Game::Game()
, curr_scene_(nullptr) , curr_scene_(nullptr)
, next_scene_(nullptr) , next_scene_(nullptr)
, transition_(nullptr) , transition_(nullptr)
, title_(L"Easy2D Game")
, width_(640)
, height_(480)
, icon_(0)
, debug_mode_(false)
{ {
if (instance)
{
throw RuntimeException("同时只能存在一个游戏实例");
}
instance = this;
::CoInitialize(nullptr); ::CoInitialize(nullptr);
} }
@ -28,49 +39,43 @@ e2d::Game::~Game()
SafeRelease(curr_scene_); SafeRelease(curr_scene_);
SafeRelease(next_scene_); SafeRelease(next_scene_);
Image::ClearCache();
Device::Destroy();
if (hwnd_) if (hwnd_)
{ {
::DestroyWindow(hwnd_); ::DestroyWindow(hwnd_);
} }
instance = nullptr;
::CoUninitialize(); ::CoUninitialize();
} }
e2d::Game * e2d::Game::New(const Option & option) void e2d::Game::Run(const Options& options)
{ {
static Game game; title_ = options.title;
game.title_ = option.title; width_ = options.width;
game.width_ = option.width; height_ = options.height;
game.height_ = option.height; icon_ = options.icon;
game.icon_ = option.icon; debug_mode_ = options.debug_mode;
game.debug_mode_ = option.debug_mode;
game.Init(); // 初始化
Init();
instance_ = &game; // 开始
return instance_; Start();
}
e2d::Game * e2d::Game::Get()
{
return instance_;
}
void e2d::Game::Run()
{
quit_ = false;
auto input = Input::GetInstance();
auto graphics = Graphics::Get();
const int min_interval = 5;
Time last = Time::Now();
MSG msg = { 0 };
// 刷新场景
::ShowWindow(hwnd_, SW_SHOWNORMAL); ::ShowWindow(hwnd_, SW_SHOWNORMAL);
::UpdateWindow(hwnd_); ::UpdateWindow(hwnd_);
UpdateScene(); UpdateScene();
// 运行
const int min_interval = 5;
Time last = Time::Now();
MSG msg = { 0 };
while (!quit_) while (!quit_)
{ {
auto now = Time::Now(); auto now = Time::Now();
@ -79,7 +84,7 @@ void e2d::Game::Run()
if (dur.Milliseconds() > min_interval) if (dur.Milliseconds() > min_interval)
{ {
last = now; last = now;
input->Update(); Device::GetInput()->Flush();
UpdateScene(); UpdateScene();
DrawScene(); DrawScene();
@ -140,7 +145,7 @@ void e2d::Game::EnterScene(Scene * scene, Transition * transition)
transition_ = transition; transition_ = transition;
transition_->Retain(); transition_->Retain();
transition_->Init(curr_scene_, next_scene_); transition_->Init(curr_scene_, next_scene_, this);
} }
} }
@ -188,7 +193,7 @@ void e2d::Game::UpdateScene()
void e2d::Game::DrawScene() void e2d::Game::DrawScene()
{ {
auto graphics = Graphics::Get(); auto graphics = Device::GetGraphics();
graphics->BeginDraw(); graphics->BeginDraw();
if (transition_) if (transition_)
@ -200,27 +205,31 @@ void e2d::Game::DrawScene()
curr_scene_->Draw(); curr_scene_->Draw();
} }
// TODO @Nomango if debug_mode_ if (debug_mode_)
/* {
if (curr_scene_ && curr_scene_->GetRoot())
{ {
graphics->GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); graphics->GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
graphics->GetSolidBrush()->SetOpacity(1.f); graphics->GetSolidBrush()->SetOpacity(1.f);
root_->DrawBorder(); curr_scene_->GetRoot()->DrawBorder();
} }
if (next_scene_ && next_scene_->GetRoot())
{ {
graphics->GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); graphics->GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
root_->DrawCollider(); graphics->GetSolidBrush()->SetOpacity(1.f);
next_scene_->GetRoot()->DrawBorder();
} }
*/
if (debug_mode_)
{
graphics->DrawDebugInfo(); graphics->DrawDebugInfo();
} }
graphics->EndDraw(); graphics->EndDraw();
} }
e2d::Game * e2d::Game::GetInstance()
{
return instance;
}
void e2d::Game::Init() void e2d::Game::Init()
{ {
WNDCLASSEX wcex = { 0 }; WNDCLASSEX wcex = { 0 };
@ -270,32 +279,64 @@ void e2d::Game::Init()
this this
); );
if (hwnd_) if (hwnd_ == nullptr)
{ {
::UnregisterClass(REGISTER_CLASS, HINST_THISCOMPONENT);
throw RuntimeException("Create window failed");
return;
}
// 初始化设备
Device::Init(hwnd_);
// 禁用输入法 // 禁用输入法
::ImmAssociateContext(hwnd_, nullptr); ::ImmAssociateContext(hwnd_, nullptr);
// ½ûÓÿØÖÆÌ¨¹Ø±Õ°´Å¥
HWND console_hwnd = ::GetConsoleWindow(); // 若开启了调试模式,打开控制台
if (console_hwnd) HWND console = ::GetConsoleWindow();
// 关闭控制台
if (debug_mode_)
{ {
HMENU hmenu = ::GetSystemMenu(console_hwnd, FALSE); if (console)
{
::ShowWindow(console, SW_SHOWNORMAL);
}
else
{
// 显示一个新控制台
if (::AllocConsole())
{
console = ::GetConsoleWindow();
// 重定向输入输出
FILE * stdoutStream, *stdinStream, *stderrStream;
freopen_s(&stdoutStream, "conout$", "w+t", stdout);
freopen_s(&stdinStream, "conin$", "r+t", stdin);
freopen_s(&stderrStream, "conout$", "w+t", stderr);
// 禁用控制台关闭按钮
HMENU hmenu = ::GetSystemMenu(console, FALSE);
::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); ::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
} }
} }
}
else else
{ {
::UnregisterClass(REGISTER_CLASS, HINST_THISCOMPONENT); if (console)
throw RuntimeException("Create window failed"); {
::ShowWindow(console, SW_HIDE);
} }
} }
quit_ = false;
}
e2d::Rect e2d::Game::Locate(int width, int height) e2d::Rect e2d::Game::Locate(int width, int height)
{ {
int max_width = ::GetSystemMetrics(SM_CXSCREEN); int max_width = ::GetSystemMetrics(SM_CXSCREEN);
int max_height = ::GetSystemMetrics(SM_CYSCREEN); int max_height = ::GetSystemMetrics(SM_CYSCREEN);
float dpi_x, dpi_y; HDC hdc = ::GetDC(0);
Graphics::GetFactory()->GetDesktopDpi(&dpi_x, &dpi_y); int dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
int dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
RECT rect = { 0, 0, LONG(ceil(width * dpi_x / 96.f)), LONG(ceil(height * dpi_y / 96.f)) }; RECT rect = { 0, 0, LONG(ceil(width * dpi_x / 96.f)), LONG(ceil(height * dpi_y / 96.f)) };
// 计算合适的窗口大小 // 计算合适的窗口大小
@ -354,6 +395,8 @@ void e2d::Game::SetSize(int width, int height)
width_ = width; width_ = width;
height_ = height; height_ = height;
if (hwnd_)
{
Rect rect = Locate(width, height); Rect rect = Locate(width, height);
::MoveWindow( ::MoveWindow(
hwnd_, hwnd_,
@ -364,18 +407,24 @@ void e2d::Game::SetSize(int width, int height)
TRUE TRUE
); );
} }
}
void e2d::Game::SetTitle(const String& title) void e2d::Game::SetTitle(const String& title)
{ {
title_ = title; title_ = title;
if (hwnd_)
{
::SetWindowText(hwnd_, (LPCWSTR)title); ::SetWindowText(hwnd_, (LPCWSTR)title);
} }
}
void e2d::Game::SetIcon(int resource_id) void e2d::Game::SetIcon(int resource_id)
{ {
icon_ = resource_id; icon_ = resource_id;
if (hwnd_)
{
HICON icon = (HICON)::LoadImage( HICON icon = (HICON)::LoadImage(
HINST_THISCOMPONENT, HINST_THISCOMPONENT,
MAKEINTRESOURCE(resource_id), MAKEINTRESOURCE(resource_id),
@ -388,6 +437,7 @@ void e2d::Game::SetIcon(int resource_id)
::SendMessage(hwnd_, WM_SETICON, ICON_BIG, (LPARAM)icon); ::SendMessage(hwnd_, WM_SETICON, ICON_BIG, (LPARAM)icon);
::SendMessage(hwnd_, WM_SETICON, ICON_SMALL, (LPARAM)icon); ::SendMessage(hwnd_, WM_SETICON, ICON_SMALL, (LPARAM)icon);
} }
}
LRESULT e2d::Game::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param) LRESULT e2d::Game::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param)
@ -470,8 +520,9 @@ LRESULT e2d::Game::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param)
if (w_param == SIZE_RESTORED) if (w_param == SIZE_RESTORED)
{ {
float dpi_x, dpi_y; HDC hdc = ::GetDC(0);
Graphics::GetFactory()->GetDesktopDpi(&dpi_x, &dpi_y); int dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
int dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
game->width_ = static_cast<int>(width * 96.f / dpi_x); game->width_ = static_cast<int>(width * 96.f / dpi_x);
game->height_ = static_cast<int>(height * 96.f / dpi_y); game->height_ = static_cast<int>(height * 96.f / dpi_y);
} }
@ -479,10 +530,10 @@ LRESULT e2d::Game::WndProc(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param)
// 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染 // 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染
// 目标的大小。它可能会调用失败,但是这里可以忽略有可能的 // 目标的大小。它可能会调用失败,但是这里可以忽略有可能的
// 错误,因为这个错误将在下一次调用 EndDraw 时产生 // 错误,因为这个错误将在下一次调用 EndDraw 时产生
auto render_target = Graphics::Get()->GetRenderTarget(); auto render_target = Device::GetGraphics()->GetRenderTarget();
if (render_target) if (render_target)
{ {
render_target->Resize(D2D1::SizeU(width, height)); render_target->Resize(D2D1::SizeU(game->width_, game->height_));
} }
} }
break; break;

View File

@ -1,45 +1,14 @@
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
#include "..\e2dmanager.h"
#include "..\e2dobject.h" #include "..\e2dobject.h"
e2d::Graphics* e2d::Graphics::instance_ = nullptr; e2d::Graphics::Graphics(HWND hwnd)
ID2D1Factory* e2d::Graphics::factory_ = nullptr; : factory_(nullptr)
IWICImagingFactory* e2d::Graphics::imaging_factory_ = nullptr; , imaging_factory_(nullptr)
IDWriteFactory* e2d::Graphics::write_factory_ = nullptr; , write_factory_(nullptr)
ID2D1StrokeStyle* e2d::Graphics::miter_stroke_style_ = nullptr; , miter_stroke_style_(nullptr)
ID2D1StrokeStyle* e2d::Graphics::bevel_stroke_style_ = nullptr; , bevel_stroke_style_(nullptr)
ID2D1StrokeStyle* e2d::Graphics::round_stroke_style_ = nullptr; , round_stroke_style_(nullptr)
e2d::Graphics * e2d::Graphics::GetInstance()
{
if (!instance_)
{
instance_ = new (std::nothrow) Graphics;
}
return instance_;
}
void e2d::Graphics::DestroyInstance()
{
if (instance_)
{
delete instance_;
instance_ = nullptr;
SafeRelease(miter_stroke_style_);
SafeRelease(bevel_stroke_style_);
SafeRelease(round_stroke_style_);
SafeRelease(factory_);
SafeRelease(imaging_factory_);
SafeRelease(write_factory_);
}
}
e2d::Graphics::Graphics()
: show_fps_(false)
, last_render_time_(Time::Now())
, render_times_(0)
, fps_text_format_(nullptr) , fps_text_format_(nullptr)
, fps_text_layout_(nullptr) , fps_text_layout_(nullptr)
, render_target_(nullptr) , render_target_(nullptr)
@ -47,7 +16,69 @@ e2d::Graphics::Graphics()
, text_renderer_(nullptr) , text_renderer_(nullptr)
, clear_color_(D2D1::ColorF(D2D1::ColorF::Black)) , clear_color_(D2D1::ColorF(D2D1::ColorF::Black))
{ {
::CoInitialize(nullptr); ThrowIfFailed(
D2D1CreateFactory(
D2D1_FACTORY_TYPE_SINGLE_THREADED,
&factory_
)
);
ThrowIfFailed(
CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
reinterpret_cast<void**>(&imaging_factory_)
)
);
ThrowIfFailed(
DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&write_factory_)
)
);
RECT rc;
::GetClientRect(hwnd, &rc);
D2D1_SIZE_U size = D2D1::SizeU(
rc.right - rc.left,
rc.bottom - rc.top
);
// 创建设备相关资源。这些资源应在 Direct2D 设备消失时重建
// 创建一个 Direct2D 渲染目标
ThrowIfFailed(
factory_->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(
hwnd,
size,
D2D1_PRESENT_OPTIONS_NONE),
&render_target_
)
);
// 创建画刷
ThrowIfFailed(
render_target_->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::White),
&solid_brush_
)
);
// 创建自定义的文字渲染器
ThrowIfFailed(
E2DTextRender::Create(
&text_renderer_,
factory_,
render_target_,
solid_brush_
)
);
} }
e2d::Graphics::~Graphics() e2d::Graphics::~Graphics()
@ -58,15 +89,18 @@ e2d::Graphics::~Graphics()
SafeRelease(solid_brush_); SafeRelease(solid_brush_);
SafeRelease(render_target_); SafeRelease(render_target_);
::CoUninitialize(); SafeRelease(miter_stroke_style_);
SafeRelease(bevel_stroke_style_);
SafeRelease(round_stroke_style_);
SafeRelease(factory_);
SafeRelease(imaging_factory_);
SafeRelease(write_factory_);
} }
void e2d::Graphics::BeginDraw() void e2d::Graphics::BeginDraw()
{ {
auto render_target = GetRenderTarget(); render_target_->BeginDraw();
render_target->BeginDraw(); render_target_->Clear(clear_color_);
// 使用背景色清空屏幕
render_target->Clear(clear_color_);
} }
void e2d::Graphics::EndDraw() void e2d::Graphics::EndDraw()
@ -91,19 +125,14 @@ void e2d::Graphics::EndDraw()
void e2d::Graphics::DrawDebugInfo() void e2d::Graphics::DrawDebugInfo()
{ {
static int render_times_ = 0;
static Time last_render_time_ = Time::Now();
int duration = (Time::Now() - last_render_time_).Milliseconds(); int duration = (Time::Now() - last_render_time_).Milliseconds();
++render_times_;
if (duration >= 100)
{
String fpsText = String::Format(L"FPS: %.1f", (1000.f / duration * render_times_));
last_render_time_ = Time::Now();
render_times_ = 0;
if (!fps_text_format_) if (!fps_text_format_)
{ {
ThrowIfFailed( ThrowIfFailed(
GetWriteFactory()->CreateTextFormat( write_factory_->CreateTextFormat(
L"", L"",
nullptr, nullptr,
DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_WEIGHT_NORMAL,
@ -116,16 +145,25 @@ void e2d::Graphics::DrawDebugInfo()
); );
ThrowIfFailed( ThrowIfFailed(
fps_text_format_->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP) fps_text_format_->SetWordWrapping(
DWRITE_WORD_WRAPPING_NO_WRAP
)
); );
} }
++render_times_;
if (duration >= 100)
{
String fps_text = String::Format(L"FPS: %.1f", (1000.f / duration * render_times_));
last_render_time_ = Time::Now();
render_times_ = 0;
SafeRelease(fps_text_layout_); SafeRelease(fps_text_layout_);
ThrowIfFailed( ThrowIfFailed(
GetWriteFactory()->CreateTextLayout( write_factory_->CreateTextLayout(
(const wchar_t *)fpsText, (const wchar_t *)fps_text,
(UINT32)fpsText.GetLength(), (UINT32)fps_text.GetLength(),
fps_text_format_, fps_text_format_,
0, 0,
0, 0,
@ -136,9 +174,9 @@ void e2d::Graphics::DrawDebugInfo()
if (fps_text_layout_) if (fps_text_layout_)
{ {
GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); render_target_->SetTransform(D2D1::Matrix3x2F::Identity());
GetSolidBrush()->SetOpacity(1.0f); solid_brush_->SetOpacity(1.0f);
GetTextRenderer()->SetTextStyle( text_renderer_->SetTextStyle(
D2D1::ColorF(D2D1::ColorF::White), D2D1::ColorF(D2D1::ColorF::White),
TRUE, TRUE,
D2D1::ColorF(D2D1::ColorF::Black, 0.4f), D2D1::ColorF(D2D1::ColorF::Black, 0.4f),
@ -146,133 +184,42 @@ void e2d::Graphics::DrawDebugInfo()
D2D1_LINE_JOIN_ROUND D2D1_LINE_JOIN_ROUND
); );
ThrowIfFailed( fps_text_layout_->Draw(
fps_text_layout_->Draw(nullptr, text_renderer_, 10, 0) nullptr,
text_renderer_,
10,
0
); );
} }
} }
e2d::E2DTextRenderer * e2d::Graphics::GetTextRenderer() ID2D1HwndRenderTarget * e2d::Graphics::GetRenderTarget() const
{ {
if (!text_renderer_)
{
// 创建自定义的文字渲染器
ThrowIfFailed(
E2DTextRenderer::Create(
&text_renderer_,
GetFactory(),
GetRenderTarget(),
GetSolidBrush()
)
);
}
return text_renderer_;
}
ID2D1HwndRenderTarget * e2d::Graphics::GetRenderTarget()
{
if (!render_target_)
{
HWND hwnd = Game::Get()->GetHWnd();
RECT rc;
GetClientRect(hwnd, &rc);
D2D1_SIZE_U size = D2D1::SizeU(
rc.right - rc.left,
rc.bottom - rc.top
);
// 创建设备相关资源。这些资源应在 Direct2D 设备消失时重建
// 创建一个 Direct2D 渲染目标
ThrowIfFailed(
GetFactory()->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(
hwnd,
size,
D2D1_PRESENT_OPTIONS_NONE),
&render_target_
)
);
}
return render_target_; return render_target_;
} }
ID2D1SolidColorBrush * e2d::Graphics::GetSolidBrush() ID2D1SolidColorBrush * e2d::Graphics::GetSolidBrush() const
{ {
if (!solid_brush_)
{
ThrowIfFailed(
GetRenderTarget()->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::White),
&solid_brush_
)
);
}
return solid_brush_; return solid_brush_;
} }
void e2d::Graphics::ShowFps(bool show) e2d::E2DTextRender * e2d::Graphics::GetTextRender() const
{ {
show_fps_ = show; return text_renderer_;
} }
ID2D1Factory * e2d::Graphics::GetFactory() ID2D1Factory * e2d::Graphics::GetFactory() const
{ {
if (!factory_)
{
::CoInitialize(nullptr);
ThrowIfFailed(
D2D1CreateFactory(
D2D1_FACTORY_TYPE_SINGLE_THREADED,
&factory_
)
);
::CoUninitialize();
}
return factory_; return factory_;
} }
IWICImagingFactory * e2d::Graphics::GetImagingFactory() IWICImagingFactory * e2d::Graphics::GetImagingFactory() const
{ {
if (!imaging_factory_)
{
::CoInitialize(nullptr);
ThrowIfFailed(
CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_IWICImagingFactory,
reinterpret_cast<void**>(&imaging_factory_)
)
);
::CoUninitialize();
}
return imaging_factory_; return imaging_factory_;
} }
IDWriteFactory * e2d::Graphics::GetWriteFactory() IDWriteFactory * e2d::Graphics::GetWriteFactory() const
{ {
if (!write_factory_)
{
::CoInitialize(nullptr);
ThrowIfFailed(
DWriteCreateFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&write_factory_)
)
);
::CoUninitialize();
}
return write_factory_; return write_factory_;
} }
@ -281,7 +228,7 @@ ID2D1StrokeStyle * e2d::Graphics::GetMiterStrokeStyle()
if (!miter_stroke_style_) if (!miter_stroke_style_)
{ {
ThrowIfFailed( ThrowIfFailed(
GetFactory()->CreateStrokeStyle( factory_->CreateStrokeStyle(
D2D1::StrokeStyleProperties( D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
@ -304,7 +251,7 @@ ID2D1StrokeStyle * e2d::Graphics::GetBevelStrokeStyle()
if (!bevel_stroke_style_) if (!bevel_stroke_style_)
{ {
ThrowIfFailed( ThrowIfFailed(
GetFactory()->CreateStrokeStyle( factory_->CreateStrokeStyle(
D2D1::StrokeStyleProperties( D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
@ -327,7 +274,7 @@ ID2D1StrokeStyle * e2d::Graphics::GetRoundStrokeStyle()
if (!round_stroke_style_) if (!round_stroke_style_)
{ {
ThrowIfFailed( ThrowIfFailed(
GetFactory()->CreateStrokeStyle( factory_->CreateStrokeStyle(
D2D1::StrokeStyleProperties( D2D1::StrokeStyleProperties(
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_FLAT, D2D1_CAP_STYLE_FLAT,

View File

@ -1,34 +1,12 @@
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
#include "..\e2dtool.h" #include "..\e2dtool.h"
#include "..\e2dmanager.h"
#pragma comment(lib, "dinput8.lib")
e2d::Input * e2d::Input::instance_ = nullptr; e2d::Input::Input(HWND hwnd)
: direct_input_(nullptr)
e2d::Input * e2d::Input::GetInstance() , keyboard_device_(nullptr)
, mouse_device_(nullptr)
{ {
if (!instance_)
instance_ = new (std::nothrow) Input;
return instance_;
}
void e2d::Input::DestroyInstance()
{
if (instance_)
{
delete instance_;
instance_ = nullptr;
}
}
e2d::Input::Input()
: direct_input_(false)
, keyboard_device_(false)
, mouse_device_(false)
{
::CoInitialize(nullptr);
ZeroMemory(key_buffer_, sizeof(key_buffer_)); ZeroMemory(key_buffer_, sizeof(key_buffer_));
ZeroMemory(&mouse_state_, sizeof(mouse_state_)); ZeroMemory(&mouse_state_, sizeof(mouse_state_));
@ -43,8 +21,6 @@ e2d::Input::Input()
) )
); );
HWND hwnd = Window::GetInstance()->GetHWnd();
// ³õʼ»¯¼üÅÌÉ豸 // ³õʼ»¯¼üÅÌÉ豸
ThrowIfFailed( ThrowIfFailed(
direct_input_->CreateDevice( direct_input_->CreateDevice(
@ -84,11 +60,9 @@ e2d::Input::~Input()
SafeRelease(mouse_device_); SafeRelease(mouse_device_);
SafeRelease(keyboard_device_); SafeRelease(keyboard_device_);
SafeRelease(direct_input_); SafeRelease(direct_input_);
::CoUninitialize();
} }
void e2d::Input::Update() void e2d::Input::Flush()
{ {
if (keyboard_device_) if (keyboard_device_)
{ {
@ -101,7 +75,10 @@ void e2d::Input::Update()
} }
else else
{ {
keyboard_device_->GetDeviceState(sizeof(key_buffer_), (void**)&key_buffer_); keyboard_device_->GetDeviceState(
sizeof(key_buffer_),
(void**)&key_buffer_
);
} }
} }
@ -116,7 +93,10 @@ void e2d::Input::Update()
} }
else else
{ {
mouse_device_->GetDeviceState(sizeof(mouse_state_), (void**)&mouse_state_); mouse_device_->GetDeviceState(
sizeof(mouse_state_),
(void**)&mouse_state_
);
} }
} }
} }
@ -147,13 +127,14 @@ float e2d::Input::GetMouseY()
e2d::Point e2d::Input::GetMousePos() e2d::Point e2d::Input::GetMousePos()
{ {
auto window = Window::GetInstance(); HDC hdc = ::GetDC(0);
float dpi = window->GetDpi(); int dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
int dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
POINT mousePos; POINT mousePos;
::GetCursorPos(&mousePos); ::GetCursorPos(&mousePos);
::ScreenToClient(window->GetHWnd(), &mousePos); ::ScreenToClient(Game::GetInstance()->GetHWnd(), &mousePos);
return Point(mousePos.x * 96.f / dpi, mousePos.y * 96.f / dpi); return Point(mousePos.x * 96.f / dpi_x, mousePos.y * 96.f / dpi_y);
} }
float e2d::Input::GetMouseDeltaX() float e2d::Input::GetMouseDeltaX()

View File

@ -1,113 +0,0 @@
#include "..\e2dmodule.h"
e2d::Size e2d::Window::GetScreenSize()
{
int screen_width = ::GetSystemMetrics(SM_CXSCREEN);
int screen_height = ::GetSystemMetrics(SM_CYSCREEN);
Size screen_size(
static_cast<float>(screen_width),
static_cast<float>(screen_height)
);
return std::move(screen_size);
}
void e2d::Window::SetCursor(Cursor cursor)
{
LPCWSTR cursor_name = nullptr;
switch (cursor)
{
case Cursor::Normal:
cursor_name = IDC_ARROW;
break;
case Cursor::Hand:
cursor_name = IDC_HAND;
break;
case Cursor::No:
cursor_name = IDC_NO;
break;
case Cursor::Wait:
cursor_name = IDC_WAIT;
break;
case Cursor::ArrowWait:
cursor_name = IDC_APPSTARTING;
break;
default:
break;
}
HCURSOR hcursor = ::LoadCursor(nullptr, cursor_name);
if (hcursor)
{
::SetCursor(hcursor);
}
}
void e2d::Window::ShowConsole(bool enabled)
{
// 查找已存在的控制台句柄
HWND hwnd = ::GetConsoleWindow();
// 关闭控制台
if (enabled)
{
if (hwnd)
{
::ShowWindow(hwnd, SW_SHOWNORMAL);
}
else
{
// 显示一个新控制台
if (::AllocConsole())
{
hwnd = ::GetConsoleWindow();
// 重定向输入输出
FILE * stdoutStream, * stdinStream, * stderrStream;
freopen_s(&stdoutStream, "conout$", "w+t", stdout);
freopen_s(&stdinStream, "conin$", "r+t", stdin);
freopen_s(&stderrStream, "conout$", "w+t", stderr);
// 禁用控制台关闭按钮
HMENU hmenu = ::GetSystemMenu(hwnd, FALSE);
::RemoveMenu(hmenu, SC_CLOSE, MF_BYCOMMAND);
}
}
}
else
{
if (hwnd)
{
::ShowWindow(hwnd, SW_HIDE);
}
}
}
bool e2d::Window::Popup(const String & text, const String & title, PopupStyle style, bool has_cancel)
{
UINT type = 0;
switch (style)
{
case PopupStyle::Info:
type = MB_ICONINFORMATION;
break;
case PopupStyle::Warning:
type = MB_ICONWARNING;
break;
case PopupStyle::Error:
type = MB_ICONERROR;
break;
default:
break;
}
if (has_cancel)
{
type |= MB_OKCANCEL;
}
int ret = ::MessageBoxW(nullptr, (LPCWSTR)text, (LPCWSTR)title, type);
return ret == IDOK;
}

View File

@ -9,7 +9,7 @@ e2d::Canvas::Canvas(float width, float height)
, stroke_width_(1.0f) , stroke_width_(1.0f)
, stroke_(Stroke::Miter) , stroke_(Stroke::Miter)
{ {
render_target_ = Graphics::Get()->GetRenderTarget(); render_target_ = Device::GetGraphics()->GetRenderTarget();
render_target_->AddRef(); render_target_->AddRef();
ThrowIfFailed( ThrowIfFailed(
@ -59,13 +59,13 @@ void e2d::Canvas::SetStrokeStyle(Stroke strokeStyle)
switch (strokeStyle) switch (strokeStyle)
{ {
case e2d::Stroke::Miter: case e2d::Stroke::Miter:
stroke_style_ = Graphics::GetMiterStrokeStyle(); stroke_style_ = Device::GetGraphics()->GetMiterStrokeStyle();
break; break;
case e2d::Stroke::Bevel: case e2d::Stroke::Bevel:
stroke_style_ = Graphics::GetBevelStrokeStyle(); stroke_style_ = Device::GetGraphics()->GetBevelStrokeStyle();
break; break;
case e2d::Stroke::Round: case e2d::Stroke::Round:
stroke_style_ = Graphics::GetRoundStrokeStyle(); stroke_style_ = Device::GetGraphics()->GetRoundStrokeStyle();
break; break;
} }
} }

View File

@ -1,201 +0,0 @@
#include "..\e2dutil.h"
#include "..\e2dimpl.h"
#include "..\e2dmodule.h"
#include "..\e2dmanager.h"
#include "..\e2dobject.h"
e2d::Collider::Collider(Node * parent)
: visible_(true)
, border_color_(Color::Blue, 0.6f)
, parent_node_(parent)
, geometry_(nullptr)
, enabled_(true)
, shape_(Collider::Shape::None)
, notify_(true)
{
}
e2d::Collider::~Collider()
{
SafeRelease(geometry_);
CollisionManager::GetInstance()->RemoveCollider(this);
}
const e2d::Color& e2d::Collider::GetBorderColor() const
{
return border_color_;
}
e2d::Collider::Shape e2d::Collider::GetShape() const
{
return shape_;
}
e2d::Node * e2d::Collider::GetNode() const
{
return parent_node_;
}
ID2D1Geometry * e2d::Collider::GetGeometry() const
{
return geometry_;
}
void e2d::Collider::SetShape(Shape shape)
{
if (shape_ == shape)
return;
shape_ = shape;
if (shape == Shape::None)
{
SafeRelease(geometry_);
CollisionManager::GetInstance()->RemoveCollider(this);
}
else
{
this->Recreate();
CollisionManager::GetInstance()->AddCollider(this);
}
}
void e2d::Collider::SetCollisionNotify(bool notify)
{
notify_ = notify;
}
void e2d::Collider::SetEnabled(bool enabled)
{
enabled_ = enabled;
}
void e2d::Collider::SetVisible(bool visible)
{
visible_ = visible;
}
void e2d::Collider::SetBorderColor(const Color& color)
{
border_color_ = color;
}
void e2d::Collider::Draw()
{
if (geometry_ && enabled_ && visible_)
{
auto graphics = Graphics::GetInstance();
// 获取纯色画刷
ID2D1SolidColorBrush * brush = graphics->GetSolidBrush();
// 设置画刷颜色和透明度
brush->SetColor((D2D1_COLOR_F)border_color_);
brush->SetOpacity(1.f);
// 绘制几何碰撞体
graphics->GetRenderTarget()->DrawGeometry(geometry_, brush, 1.5f);
}
}
e2d::Collider::Relation e2d::Collider::GetRelationWith(Collider * collider) const
{
if (geometry_ && collider->geometry_)
{
if (enabled_ && collider->enabled_)
{
D2D1_GEOMETRY_RELATION relation;
geometry_->CompareWithGeometry(
collider->geometry_,
D2D1::Matrix3x2F::Identity(),
&relation
);
return Relation(relation);
}
}
return Relation::Unknown;
}
bool e2d::Collider::IsEnabled() const
{
return enabled_;
}
bool e2d::Collider::IsVisible() const
{
return visible_;
}
bool e2d::Collider::IsCollisionNotify() const
{
return notify_;
}
void e2d::Collider::Recreate()
{
if (!enabled_ || shape_ == Shape::None)
return;
SafeRelease(geometry_);
auto factory = Graphics::GetFactory();
switch (shape_)
{
case Shape::Rect:
{
ID2D1RectangleGeometry* rectangle = nullptr;
factory->CreateRectangleGeometry(
D2D1::RectF(0, 0, parent_node_->GetRealWidth(), parent_node_->GetRealHeight()),
&rectangle
);
geometry_ = rectangle;
}
break;
case Shape::Circle:
{
float minSide = std::min(parent_node_->GetRealWidth(), parent_node_->GetRealHeight());
ID2D1EllipseGeometry* circle = nullptr;
factory->CreateEllipseGeometry(
D2D1::Ellipse(
D2D1::Point2F(
parent_node_->GetRealWidth() / 2,
parent_node_->GetRealHeight() / 2
),
minSide / 2,
minSide / 2
),
&circle
);
geometry_ = circle;
}
break;
case Shape::Ellipse:
{
float halfWidth = parent_node_->GetWidth() / 2,
halfHeight = parent_node_->GetHeight() / 2;
ID2D1EllipseGeometry* ellipse = nullptr;
factory->CreateEllipseGeometry(
D2D1::Ellipse(
D2D1::Point2F(
halfWidth,
halfHeight),
halfWidth,
halfHeight),
&ellipse
);
geometry_ = ellipse;
}
break;
}
ID2D1TransformedGeometry * transformed;
factory->CreateTransformedGeometry(
geometry_,
parent_node_->final_matrix_,
&transformed
);
SafeRelease(geometry_);
geometry_ = transformed;
}

View File

@ -47,7 +47,7 @@ e2d::Image::~Image()
bool e2d::Image::Open(const Resource& res) bool e2d::Image::Open(const Resource& res)
{ {
if (!Image::Preload(res)) if (!Image::Load(res))
{ {
WARN("Load Image from file failed!"); WARN("Load Image from file failed!");
return false; return false;
@ -64,7 +64,7 @@ bool e2d::Image::Open(const String & file_name)
if (file_name.IsEmpty()) if (file_name.IsEmpty())
return false; return false;
if (!Image::Preload(file_name)) if (!Image::Load(file_name))
{ {
WARN("Load Image from file failed!"); WARN("Load Image from file failed!");
return false; return false;
@ -157,15 +157,20 @@ const e2d::Rect & e2d::Image::GetCropRect() const
return crop_rect_; return crop_rect_;
} }
bool e2d::Image::Preload(const Resource& res) ID2D1Bitmap * e2d::Image::GetBitmap() const
{
return bitmap_;
}
bool e2d::Image::Load(const Resource& res)
{ {
if (bitmap_cache_.find(res.id) != bitmap_cache_.end()) if (bitmap_cache_.find(res.id) != bitmap_cache_.end())
{ {
return true; return true;
} }
IWICImagingFactory *imaging_factory = Graphics::GetImagingFactory(); IWICImagingFactory *imaging_factory = Device::GetGraphics()->GetImagingFactory();
ID2D1HwndRenderTarget* render_target = Graphics::GetInstance()->GetRenderTarget(); ID2D1HwndRenderTarget* render_target = Device::GetGraphics()->GetRenderTarget();
IWICBitmapDecoder *decoder = nullptr; IWICBitmapDecoder *decoder = nullptr;
IWICBitmapFrameDecode *source = nullptr; IWICBitmapFrameDecode *source = nullptr;
IWICStream *stream = nullptr; IWICStream *stream = nullptr;
@ -283,7 +288,7 @@ bool e2d::Image::Preload(const Resource& res)
return SUCCEEDED(hr); return SUCCEEDED(hr);
} }
bool e2d::Image::Preload(const String & file_name) bool e2d::Image::Load(const String & file_name)
{ {
size_t hash = file_name.GetHash(); size_t hash = file_name.GetHash();
if (bitmap_cache_.find(hash) != bitmap_cache_.end()) if (bitmap_cache_.find(hash) != bitmap_cache_.end())
@ -297,8 +302,8 @@ bool e2d::Image::Preload(const String & file_name)
// 默认搜索路径,所以需要通过 File::GetPath 获取完整路径 // 默认搜索路径,所以需要通过 File::GetPath 获取完整路径
String image_file_path = image_file.GetPath(); String image_file_path = image_file.GetPath();
IWICImagingFactory *imaging_factory = Graphics::GetImagingFactory(); IWICImagingFactory *imaging_factory = Device::GetGraphics()->GetImagingFactory();
ID2D1HwndRenderTarget* render_target = Graphics::GetInstance()->GetRenderTarget(); ID2D1HwndRenderTarget* render_target = Device::GetGraphics()->GetRenderTarget();
IWICBitmapDecoder *decoder = nullptr; IWICBitmapDecoder *decoder = nullptr;
IWICBitmapFrameDecode *source = nullptr; IWICBitmapFrameDecode *source = nullptr;
IWICStream *stream = nullptr; IWICStream *stream = nullptr;
@ -395,8 +400,3 @@ void e2d::Image::SetBitmap(ID2D1Bitmap * bitmap)
crop_rect_.size.height = bitmap_->GetSize().height; crop_rect_.size.height = bitmap_->GetSize().height;
} }
} }
ID2D1Bitmap * e2d::Image::GetBitmap()
{
return bitmap_;
}

View File

@ -1,7 +1,7 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
#include "..\e2devent.h" #include "..\e2devent.h"
#include "..\e2dmanager.h"
#include "..\e2daction.h" #include "..\e2daction.h"
#include "..\e2dmodule.h"
e2d::Node::Node() e2d::Node::Node()
@ -12,7 +12,6 @@ e2d::Node::Node()
, clip_enabled_(false) , clip_enabled_(false)
, dirty_sort_(false) , dirty_sort_(false)
, dirty_transform_(false) , dirty_transform_(false)
, collider_(this)
, border_(nullptr) , border_(nullptr)
, order_(0) , order_(0)
, transform_() , transform_()
@ -52,18 +51,12 @@ void e2d::Node::Visit()
if (!visible_) if (!visible_)
return; return;
Update();
UpdateActions(); UpdateActions();
UpdateTasks(); UpdateTasks();
auto updatable_node = dynamic_cast<Updatable*>(this);
if (updatable_node)
{
updatable_node->Update();
}
UpdateTransform(); UpdateTransform();
auto render_target = Graphics::Get()->GetRenderTarget(); auto render_target = Device::GetGraphics()->GetRenderTarget();
if (clip_enabled_) if (clip_enabled_)
{ {
render_target->SetTransform(final_matrix_); render_target->SetTransform(final_matrix_);
@ -74,13 +67,9 @@ void e2d::Node::Visit()
} }
if (children_.empty()) if (children_.empty())
{
auto drawable_node = dynamic_cast<Drawable*>(this);
if (drawable_node)
{ {
render_target->SetTransform(final_matrix_); render_target->SetTransform(final_matrix_);
drawable_node->Draw(); Draw();
}
} }
else else
{ {
@ -111,12 +100,8 @@ void e2d::Node::Visit()
} }
} }
auto drawable_node = dynamic_cast<Drawable*>(this);
if (drawable_node)
{
render_target->SetTransform(final_matrix_); render_target->SetTransform(final_matrix_);
drawable_node->Draw(); Draw();
}
// 访问剩余节点 // 访问剩余节点
for (; i < children_.size(); ++i) for (; i < children_.size(); ++i)
@ -135,7 +120,7 @@ void e2d::Node::DrawBorder()
{ {
if (border_) if (border_)
{ {
auto graphics = Graphics::Get(); auto graphics = Device::GetGraphics();
auto brush = graphics->GetSolidBrush(); auto brush = graphics->GetSolidBrush();
brush->SetColor(D2D1_COLOR_F(border_color_)); brush->SetColor(D2D1_COLOR_F(border_color_));
graphics->GetRenderTarget()->DrawGeometry( graphics->GetRenderTarget()->DrawGeometry(
@ -152,19 +137,6 @@ void e2d::Node::DrawBorder()
} }
} }
void e2d::Node::DrawCollider()
{
if (visible_)
{
collider_.Draw();
for (const auto& child : children_)
{
child->DrawCollider();
}
}
}
void e2d::Node::UpdateTransform() void e2d::Node::UpdateTransform()
{ {
if (!dirty_transform_) if (!dirty_transform_)
@ -195,7 +167,7 @@ void e2d::Node::UpdateTransform()
// 重新构造轮廓 // 重新构造轮廓
SafeRelease(border_); SafeRelease(border_);
ID2D1Factory * factory = Graphics::GetFactory(); ID2D1Factory * factory = Device::GetGraphics()->GetFactory();
ID2D1RectangleGeometry * rectangle = nullptr; ID2D1RectangleGeometry * rectangle = nullptr;
ID2D1TransformedGeometry * transformed = nullptr; ID2D1TransformedGeometry * transformed = nullptr;
ThrowIfFailed( ThrowIfFailed(
@ -220,16 +192,6 @@ void e2d::Node::UpdateTransform()
{ {
child->dirty_transform_ = true; child->dirty_transform_ = true;
} }
// ¸üÐÂÅöײÌå
collider_.Recreate();
if (collider_.IsEnabled() &&
collider_.IsCollisionNotify() &&
collider_.GetShape() != Collider::Shape::None)
{
CollisionManager::GetInstance()->UpdateCollider(&collider_);
}
} }
bool e2d::Node::Dispatch(const MouseEvent & e, bool handled) bool e2d::Node::Dispatch(const MouseEvent & e, bool handled)
@ -322,17 +284,7 @@ size_t e2d::Node::GetHashName() const
return hash_name_; return hash_name_;
} }
float e2d::Node::GetPosX() const const e2d::Point& e2d::Node::GetPosition() const
{
return transform_.position.x;
}
float e2d::Node::GetPosY() const
{
return transform_.position.y;
}
const e2d::Point& e2d::Node::GetPos() const
{ {
return transform_.position; return transform_.position;
} }
@ -412,11 +364,6 @@ float e2d::Node::GetOpacity() const
return real_opacity_; return real_opacity_;
} }
e2d::Collider* e2d::Node::GetCollider()
{
return &collider_;
}
int e2d::Node::GetOrder() const int e2d::Node::GetOrder() const
{ {
return order_; return order_;

View File

@ -111,10 +111,8 @@ void e2d::Sprite::Draw() const
{ {
if (image_ && image_->GetBitmap()) if (image_ && image_->GetBitmap())
{ {
// »ñȡͼƬ²Ã¼ôλÖÃ
auto crop_pos = image_->GetCropPos(); auto crop_pos = image_->GetCropPos();
// äÖȾͼƬ Device::GetGraphics()->GetRenderTarget()->DrawBitmap(
Graphics::Get()->GetRenderTarget()->DrawBitmap(
image_->GetBitmap(), image_->GetBitmap(),
D2D1::RectF(0, 0, transform_.size.width, transform_.size.height), D2D1::RectF(0, 0, transform_.size.width, transform_.size.height),
display_opacity_, display_opacity_,

View File

@ -292,13 +292,13 @@ void e2d::Text::Draw() const
{ {
if (text_layout_) if (text_layout_)
{ {
auto graphics = Graphics::GetInstance(); auto graphics = Device::GetGraphics();
// 创建文本区域 // 创建文本区域
D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, transform_.size.width, transform_.size.height); D2D1_RECT_F textLayoutRect = D2D1::RectF(0, 0, transform_.size.width, transform_.size.height);
// 设置画刷颜色和透明度 // 设置画刷颜色和透明度
graphics->GetSolidBrush()->SetOpacity(display_opacity_); graphics->GetSolidBrush()->SetOpacity(display_opacity_);
// 获取文本渲染器 // 获取文本渲染器
auto textRenderer = graphics->GetTextRenderer(); auto textRenderer = graphics->GetTextRender();
textRenderer->SetTextStyle( textRenderer->SetTextStyle(
(D2D1_COLOR_F)style_.color, (D2D1_COLOR_F)style_.color,
style_.outline, style_.outline,
@ -323,7 +323,7 @@ void e2d::Text::CreateFormat()
SafeRelease(text_format_); SafeRelease(text_format_);
ThrowIfFailed( ThrowIfFailed(
Graphics::GetWriteFactory()->CreateTextFormat( Device::GetGraphics()->GetWriteFactory()->CreateTextFormat(
(const wchar_t *)font_.family, (const wchar_t *)font_.family,
nullptr, nullptr,
DWRITE_FONT_WEIGHT(font_.weight), DWRITE_FONT_WEIGHT(font_.weight),
@ -381,7 +381,7 @@ void e2d::Text::CreateLayout()
} }
UINT32 length = (UINT32)text_.GetLength(); UINT32 length = (UINT32)text_.GetLength();
auto writeFactory = Graphics::GetWriteFactory(); auto writeFactory = Device::GetGraphics()->GetWriteFactory();
// 对文本自动换行情况下进行处理 // 对文本自动换行情况下进行处理
if (style_.wrap) if (style_.wrap)

View File

@ -206,12 +206,7 @@ e2d::File e2d::File::ShowOpenDialog(const String & title, const String & filter)
file_open->SetFileTypes(1, spec); file_open->SetFileTypes(1, spec);
} }
Game::GetInstance()->Pause(); hr = file_open->Show(nullptr);
{
HWND hwnd = Window::GetInstance()->GetHWnd();
hr = file_open->Show(hwnd);
}
Game::GetInstance()->Resume();
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
@ -281,12 +276,7 @@ e2d::File e2d::File::ShowSaveDialog(const String & title, const String& def_file
file_save->SetFileTypes(1, spec); file_save->SetFileTypes(1, spec);
} }
Game::GetInstance()->Pause(); hr = file_save->Show(nullptr);
{
HWND hwnd = Window::GetInstance()->GetHWnd();
hr = file_save->Show(hwnd);
}
Game::GetInstance()->Resume();
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {

View File

@ -128,10 +128,7 @@ bool e2d::Music::Open(const e2d::String & file_path)
return false; return false;
} }
// ´´½¨ÒôÔ´ HRESULT hr = Device::GetAudio()->CreateVoice(&voice_, wfx_, &callback_);
auto xAudio2 = Audio::GetInstance()->GetXAudio2();
HRESULT hr = xAudio2->CreateSourceVoice(&voice_, wfx_, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &callback_);
if (FAILED(hr)) if (FAILED(hr))
{ {
TraceError(L"Create source voice error", hr); TraceError(L"Create source voice error", hr);
@ -206,10 +203,7 @@ bool e2d::Music::Open(const Resource& res)
return false; return false;
} }
// ´´½¨ÒôÔ´ HRESULT hr = Device::GetAudio()->CreateVoice(&voice_, wfx_, &callback_);
auto xAudio2 = Audio::GetInstance()->GetXAudio2();
HRESULT hr = xAudio2->CreateSourceVoice(&voice_, wfx_, 0, XAUDIO2_DEFAULT_FREQ_RATIO, &callback_);
if (FAILED(hr)) if (FAILED(hr))
{ {
TraceError(L"Create source voice error", hr); TraceError(L"Create source voice error", hr);

View File

@ -9,7 +9,7 @@ const e2d::String& e2d::Path::GetDataPath()
{ {
// 设置数据的保存路径 // 设置数据的保存路径
String local_app_data_path = Path::GetLocalAppDataPath(); String local_app_data_path = Path::GetLocalAppDataPath();
String title = Window::GetInstance()->GetTitle(); String title = Game::GetInstance()->GetTitle();
String folder_name = String::Parse(title.GetHash()); String folder_name = String::Parse(title.GetHash());
if (!local_app_data_path.IsEmpty()) if (!local_app_data_path.IsEmpty())
@ -34,7 +34,7 @@ const e2d::String& e2d::Path::GetTemporaryPath()
{ {
// 设置临时文件保存路径 // 设置临时文件保存路径
wchar_t path[_MAX_PATH]; wchar_t path[_MAX_PATH];
String title = Window::GetInstance()->GetTitle(); String title = Game::GetInstance()->GetTitle();
String folder_name = String::Parse(title.GetHash()); String folder_name = String::Parse(title.GetHash());
if (0 != ::GetTempPath(_MAX_PATH, path)) if (0 != ::GetTempPath(_MAX_PATH, path))

View File

@ -1,230 +0,0 @@
#include "..\e2dtool.h"
e2d::Player * e2d::Player::instance_ = nullptr;
e2d::Player * e2d::Player::GetInstance()
{
if (!instance_)
{
instance_ = new (std::nothrow) Player;
}
return instance_;
}
void e2d::Player::DestroyInstance()
{
if (instance_)
{
delete instance_;
instance_ = nullptr;
}
}
e2d::Player::Player()
: volume_(1.f)
{
}
e2d::Player::~Player()
{
if (!musics_.empty())
{
for (const auto& pair : musics_)
{
pair.second->Release();
}
}
}
bool e2d::Player::Preload(const String & file_path)
{
if (file_path.IsEmpty())
return false;
Music * music = new (std::nothrow) Music();
if (music)
{
music->Retain();
if (music->Open(file_path))
{
music->SetVolume(volume_);
musics_.insert(std::make_pair(file_path.GetHash(), music));
return true;
}
else
{
music->Release();
}
}
return false;
}
bool e2d::Player::Play(const String & file_path, int loop_count)
{
if (file_path.IsEmpty())
return false;
if (Player::Preload(file_path))
{
auto music = musics_[file_path.GetHash()];
if (music->Play(loop_count))
{
return true;
}
}
return false;
}
void e2d::Player::Pause(const String & file_path)
{
if (file_path.IsEmpty())
return;
size_t hash = file_path.GetHash();
if (musics_.end() != musics_.find(hash))
musics_[hash]->Pause();
}
void e2d::Player::Resume(const String & file_path)
{
if (file_path.IsEmpty())
return;
size_t hash = file_path.GetHash();
if (musics_.end() != musics_.find(hash))
musics_[hash]->Resume();
}
void e2d::Player::Stop(const String & file_path)
{
if (file_path.IsEmpty())
return;
size_t hash = file_path.GetHash();
if (musics_.end() != musics_.find(hash))
musics_[hash]->Stop();
}
bool e2d::Player::IsPlaying(const String & file_path)
{
if (file_path.IsEmpty())
return false;
size_t hash = file_path.GetHash();
if (musics_.end() != musics_.find(hash))
return musics_[hash]->IsPlaying();
return false;
}
bool e2d::Player::Preload(const Resource& res)
{
if (musics_.end() != musics_.find(res.id))
return true;
Music * music = new (std::nothrow) Music();
if (music)
{
music->Retain();
if (music->Open(res))
{
music->SetVolume(volume_);
musics_.insert(std::make_pair(res.id, music));
return true;
}
else
{
music->Release();
}
}
return false;
}
bool e2d::Player::Play(const Resource& res, int loop_count)
{
if (Player::Preload(res))
{
auto music = musics_[res.id];
if (music->Play(loop_count))
{
return true;
}
}
return false;
}
void e2d::Player::Pause(const Resource& res)
{
if (musics_.end() != musics_.find(res.id))
musics_[res.id]->Pause();
}
void e2d::Player::Resume(const Resource& res)
{
if (musics_.end() != musics_.find(res.id))
musics_[res.id]->Resume();
}
void e2d::Player::Stop(const Resource& res)
{
if (musics_.end() != musics_.find(res.id))
musics_[res.id]->Stop();
}
bool e2d::Player::IsPlaying(const Resource& res)
{
if (musics_.end() != musics_.find(res.id))
return musics_[res.id]->IsPlaying();
return false;
}
float e2d::Player::GetVolume()
{
return volume_;
}
void e2d::Player::SetVolume(float volume)
{
volume_ = std::min(std::max(volume, -224.f), 224.f);
for (const auto& pair : musics_)
{
pair.second->SetVolume(volume_);
}
}
void e2d::Player::PauseAll()
{
for (const auto& pair : musics_)
{
pair.second->Pause();
}
}
void e2d::Player::ResumeAll()
{
for (const auto& pair : musics_)
{
pair.second->Resume();
}
}
void e2d::Player::StopAll()
{
for (const auto& pair : musics_)
{
pair.second->Stop();
}
}
void e2d::Player::ClearCache()
{
for (const auto& pair : musics_)
{
delete pair.second;
}
musics_.clear();
}

View File

@ -6,9 +6,9 @@ e2d::BoxTransition::BoxTransition(float duration)
{ {
} }
void e2d::BoxTransition::Init(Scene * prev, Scene * next) void e2d::BoxTransition::Init(Scene * prev, Scene * next, Game * game)
{ {
Transition::Init(prev, next); Transition::Init(prev, next, game);
in_layer_param_.opacity = 0; in_layer_param_.opacity = 0;
} }

View File

@ -6,9 +6,9 @@ e2d::EmergeTransition::EmergeTransition(float duration)
{ {
} }
void e2d::EmergeTransition::Init(Scene * prev, Scene * next) void e2d::EmergeTransition::Init(Scene * prev, Scene * next, Game * game)
{ {
Transition::Init(prev, next); Transition::Init(prev, next, game);
out_layer_param_.opacity = 1; out_layer_param_.opacity = 1;
in_layer_param_.opacity = 0; in_layer_param_.opacity = 0;

View File

@ -6,9 +6,9 @@ e2d::FadeTransition::FadeTransition(float duration)
{ {
} }
void e2d::FadeTransition::Init(Scene * prev, Scene * next) void e2d::FadeTransition::Init(Scene * prev, Scene * next, Game * game)
{ {
Transition::Init(prev, next); Transition::Init(prev, next, game);
out_layer_param_.opacity = 1; out_layer_param_.opacity = 1;
in_layer_param_.opacity = 0; in_layer_param_.opacity = 0;

View File

@ -7,9 +7,9 @@ e2d::MoveTransition::MoveTransition(float duration, Direction direction)
{ {
} }
void e2d::MoveTransition::Init(Scene * prev, Scene * next) void e2d::MoveTransition::Init(Scene * prev, Scene * next, Game * game)
{ {
Transition::Init(prev, next); Transition::Init(prev, next, game);
switch (direction_) switch (direction_)
{ {

View File

@ -7,9 +7,9 @@ e2d::RotationTransition::RotationTransition(float duration, float rotation)
{ {
} }
void e2d::RotationTransition::Init(Scene * prev, Scene * next) void e2d::RotationTransition::Init(Scene * prev, Scene * next, Game * game)
{ {
Transition::Init(prev, next); Transition::Init(prev, next, game);
if (out_scene_) if (out_scene_)
{ {

View File

@ -30,7 +30,7 @@ bool e2d::Transition::IsDone()
return done_; return done_;
} }
void e2d::Transition::Init(Scene * prev, Scene * next) void e2d::Transition::Init(Scene * prev, Scene * next, Game * game)
{ {
started_ = Time::Now(); started_ = Time::Now();
out_scene_ = prev; out_scene_ = prev;
@ -42,7 +42,7 @@ void e2d::Transition::Init(Scene * prev, Scene * next)
if (in_scene_) if (in_scene_)
in_scene_->Retain(); in_scene_->Retain();
auto graphics = Graphics::GetInstance(); auto graphics = Device::GetGraphics();
if (in_scene_) if (in_scene_)
{ {
ThrowIfFailed( ThrowIfFailed(
@ -57,7 +57,7 @@ void e2d::Transition::Init(Scene * prev, Scene * next)
); );
} }
window_size_ = Window::GetInstance()->GetSize(); window_size_ = game->GetSize();
out_layer_param_ = in_layer_param_ = D2D1::LayerParameters( out_layer_param_ = in_layer_param_ = D2D1::LayerParameters(
D2D1::RectF( D2D1::RectF(
0.f, 0.f,
@ -94,7 +94,7 @@ void e2d::Transition::Update()
void e2d::Transition::Draw() void e2d::Transition::Draw()
{ {
auto render_target = Graphics::GetInstance()->GetRenderTarget(); auto render_target = Device::GetGraphics()->GetRenderTarget();
if (out_scene_) if (out_scene_)
{ {

View File

@ -42,20 +42,16 @@
<ClCompile Include="..\..\core\actions\Spawn.cpp" /> <ClCompile Include="..\..\core\actions\Spawn.cpp" />
<ClCompile Include="..\..\core\components\Button.cpp" /> <ClCompile Include="..\..\core\components\Button.cpp" />
<ClCompile Include="..\..\core\components\Menu.cpp" /> <ClCompile Include="..\..\core\components\Menu.cpp" />
<ClCompile Include="..\..\core\events\Collision.cpp" />
<ClCompile Include="..\..\core\events\KeyEvent.cpp" /> <ClCompile Include="..\..\core\events\KeyEvent.cpp" />
<ClCompile Include="..\..\core\events\MouseEvent.cpp" /> <ClCompile Include="..\..\core\events\MouseEvent.cpp" />
<ClCompile Include="..\..\core\impl\TextRenderer.cpp" /> <ClCompile Include="..\..\core\impl\TextRenderer.cpp" />
<ClCompile Include="..\..\core\impl\VoiceCallback.cpp" /> <ClCompile Include="..\..\core\impl\VoiceCallback.cpp" />
<ClCompile Include="..\..\core\managers\CollisionManager.cpp" />
<ClCompile Include="..\..\core\modules\Audio.cpp" /> <ClCompile Include="..\..\core\modules\Audio.cpp" />
<ClCompile Include="..\..\core\modules\Device.cpp" />
<ClCompile Include="..\..\core\modules\Game.cpp" /> <ClCompile Include="..\..\core\modules\Game.cpp" />
<ClCompile Include="..\..\core\modules\GC.cpp" />
<ClCompile Include="..\..\core\modules\Input.cpp" /> <ClCompile Include="..\..\core\modules\Input.cpp" />
<ClCompile Include="..\..\core\modules\Renderer.cpp" /> <ClCompile Include="..\..\core\modules\Graphics.cpp" />
<ClCompile Include="..\..\core\modules\Window.cpp" />
<ClCompile Include="..\..\core\objects\Canvas.cpp" /> <ClCompile Include="..\..\core\objects\Canvas.cpp" />
<ClCompile Include="..\..\core\objects\Collider.cpp" />
<ClCompile Include="..\..\core\objects\Image.cpp" /> <ClCompile Include="..\..\core\objects\Image.cpp" />
<ClCompile Include="..\..\core\objects\Node.cpp" /> <ClCompile Include="..\..\core\objects\Node.cpp" />
<ClCompile Include="..\..\core\objects\Scene.cpp" /> <ClCompile Include="..\..\core\objects\Scene.cpp" />
@ -66,7 +62,6 @@
<ClCompile Include="..\..\core\tools\File.cpp" /> <ClCompile Include="..\..\core\tools\File.cpp" />
<ClCompile Include="..\..\core\tools\Music.cpp" /> <ClCompile Include="..\..\core\tools\Music.cpp" />
<ClCompile Include="..\..\core\tools\Path.cpp" /> <ClCompile Include="..\..\core\tools\Path.cpp" />
<ClCompile Include="..\..\core\tools\Player.cpp" />
<ClCompile Include="..\..\core\tools\Random.cpp" /> <ClCompile Include="..\..\core\tools\Random.cpp" />
<ClCompile Include="..\..\core\transitions\BoxTransition.cpp" /> <ClCompile Include="..\..\core\transitions\BoxTransition.cpp" />
<ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" /> <ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" />
@ -97,7 +92,6 @@
<ClInclude Include="..\..\core\e2dimpl.h" /> <ClInclude Include="..\..\core\e2dimpl.h" />
<ClInclude Include="..\..\core\e2dmodule.h" /> <ClInclude Include="..\..\core\e2dmodule.h" />
<ClInclude Include="..\..\core\e2dmacros.h" /> <ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dtool.h" /> <ClInclude Include="..\..\core\e2dtool.h" />
<ClInclude Include="..\..\core\e2dtransition.h" /> <ClInclude Include="..\..\core\e2dtransition.h" />
</ItemGroup> </ItemGroup>

View File

@ -19,9 +19,6 @@
<Filter Include="events"> <Filter Include="events">
<UniqueIdentifier>{6c9657de-02d5-4d3b-9e1d-bc921eb5aea3}</UniqueIdentifier> <UniqueIdentifier>{6c9657de-02d5-4d3b-9e1d-bc921eb5aea3}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="managers">
<UniqueIdentifier>{9031e36b-fa85-4b4e-8e80-657c7e68f283}</UniqueIdentifier>
</Filter>
<Filter Include="transitions"> <Filter Include="transitions">
<UniqueIdentifier>{563b19f2-4c5e-4362-983a-94d2ae724550}</UniqueIdentifier> <UniqueIdentifier>{563b19f2-4c5e-4362-983a-94d2ae724550}</UniqueIdentifier>
</Filter> </Filter>
@ -102,18 +99,9 @@
<ClCompile Include="..\..\core\modules\Game.cpp"> <ClCompile Include="..\..\core\modules\Game.cpp">
<Filter>modules</Filter> <Filter>modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\modules\GC.cpp">
<Filter>modules</Filter>
</ClCompile>
<ClCompile Include="..\..\core\modules\Input.cpp"> <ClCompile Include="..\..\core\modules\Input.cpp">
<Filter>modules</Filter> <Filter>modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\modules\Renderer.cpp">
<Filter>modules</Filter>
</ClCompile>
<ClCompile Include="..\..\core\modules\Window.cpp">
<Filter>modules</Filter>
</ClCompile>
<ClCompile Include="..\..\core\utils\Color.cpp"> <ClCompile Include="..\..\core\utils\Color.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
@ -156,18 +144,12 @@
<ClCompile Include="..\..\core\impl\VoiceCallback.cpp"> <ClCompile Include="..\..\core\impl\VoiceCallback.cpp">
<Filter>impl</Filter> <Filter>impl</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\events\Collision.cpp">
<Filter>events</Filter>
</ClCompile>
<ClCompile Include="..\..\core\events\KeyEvent.cpp"> <ClCompile Include="..\..\core\events\KeyEvent.cpp">
<Filter>events</Filter> <Filter>events</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\events\MouseEvent.cpp"> <ClCompile Include="..\..\core\events\MouseEvent.cpp">
<Filter>events</Filter> <Filter>events</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\managers\CollisionManager.cpp">
<Filter>managers</Filter>
</ClCompile>
<ClCompile Include="..\..\core\tools\Data.cpp"> <ClCompile Include="..\..\core\tools\Data.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
@ -180,9 +162,6 @@
<ClCompile Include="..\..\core\tools\Path.cpp"> <ClCompile Include="..\..\core\tools\Path.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\tools\Player.cpp">
<Filter>tools</Filter>
</ClCompile>
<ClCompile Include="..\..\core\tools\Random.cpp"> <ClCompile Include="..\..\core\tools\Random.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
@ -207,9 +186,6 @@
<ClCompile Include="..\..\core\objects\Canvas.cpp"> <ClCompile Include="..\..\core\objects\Canvas.cpp">
<Filter>objects</Filter> <Filter>objects</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\objects\Collider.cpp">
<Filter>objects</Filter>
</ClCompile>
<ClCompile Include="..\..\core\objects\Image.cpp"> <ClCompile Include="..\..\core\objects\Image.cpp">
<Filter>objects</Filter> <Filter>objects</Filter>
</ClCompile> </ClCompile>
@ -234,12 +210,17 @@
<ClCompile Include="..\..\core\utils\Transform.cpp"> <ClCompile Include="..\..\core\utils\Transform.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\modules\Graphics.cpp">
<Filter>modules</Filter>
</ClCompile>
<ClCompile Include="..\..\core\modules\Device.cpp">
<Filter>modules</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\e2daction.h" /> <ClInclude Include="..\..\core\e2daction.h" />
<ClInclude Include="..\..\core\e2dmacros.h" /> <ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dtransition.h" /> <ClInclude Include="..\..\core\e2dtransition.h" />
<ClInclude Include="..\..\core\e2devent.h" /> <ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\e2dmodule.h" /> <ClInclude Include="..\..\core\e2dmodule.h" />

View File

@ -186,20 +186,16 @@
<ClCompile Include="..\..\core\actions\Spawn.cpp" /> <ClCompile Include="..\..\core\actions\Spawn.cpp" />
<ClCompile Include="..\..\core\components\Button.cpp" /> <ClCompile Include="..\..\core\components\Button.cpp" />
<ClCompile Include="..\..\core\components\Menu.cpp" /> <ClCompile Include="..\..\core\components\Menu.cpp" />
<ClCompile Include="..\..\core\events\Collision.cpp" />
<ClCompile Include="..\..\core\events\KeyEvent.cpp" /> <ClCompile Include="..\..\core\events\KeyEvent.cpp" />
<ClCompile Include="..\..\core\events\MouseEvent.cpp" /> <ClCompile Include="..\..\core\events\MouseEvent.cpp" />
<ClCompile Include="..\..\core\impl\TextRenderer.cpp" /> <ClCompile Include="..\..\core\impl\TextRenderer.cpp" />
<ClCompile Include="..\..\core\impl\VoiceCallback.cpp" /> <ClCompile Include="..\..\core\impl\VoiceCallback.cpp" />
<ClCompile Include="..\..\core\managers\CollisionManager.cpp" />
<ClCompile Include="..\..\core\modules\Audio.cpp" /> <ClCompile Include="..\..\core\modules\Audio.cpp" />
<ClCompile Include="..\..\core\modules\Device.cpp" />
<ClCompile Include="..\..\core\modules\Game.cpp" /> <ClCompile Include="..\..\core\modules\Game.cpp" />
<ClCompile Include="..\..\core\modules\GC.cpp" />
<ClCompile Include="..\..\core\modules\Input.cpp" /> <ClCompile Include="..\..\core\modules\Input.cpp" />
<ClCompile Include="..\..\core\modules\Renderer.cpp" /> <ClCompile Include="..\..\core\modules\Graphics.cpp" />
<ClCompile Include="..\..\core\modules\Window.cpp" />
<ClCompile Include="..\..\core\objects\Canvas.cpp" /> <ClCompile Include="..\..\core\objects\Canvas.cpp" />
<ClCompile Include="..\..\core\objects\Collider.cpp" />
<ClCompile Include="..\..\core\objects\Image.cpp" /> <ClCompile Include="..\..\core\objects\Image.cpp" />
<ClCompile Include="..\..\core\objects\Node.cpp" /> <ClCompile Include="..\..\core\objects\Node.cpp" />
<ClCompile Include="..\..\core\objects\Scene.cpp" /> <ClCompile Include="..\..\core\objects\Scene.cpp" />
@ -210,7 +206,6 @@
<ClCompile Include="..\..\core\tools\File.cpp" /> <ClCompile Include="..\..\core\tools\File.cpp" />
<ClCompile Include="..\..\core\tools\Music.cpp" /> <ClCompile Include="..\..\core\tools\Music.cpp" />
<ClCompile Include="..\..\core\tools\Path.cpp" /> <ClCompile Include="..\..\core\tools\Path.cpp" />
<ClCompile Include="..\..\core\tools\Player.cpp" />
<ClCompile Include="..\..\core\tools\Random.cpp" /> <ClCompile Include="..\..\core\tools\Random.cpp" />
<ClCompile Include="..\..\core\transitions\BoxTransition.cpp" /> <ClCompile Include="..\..\core\transitions\BoxTransition.cpp" />
<ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" /> <ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" />
@ -241,7 +236,6 @@
<ClInclude Include="..\..\core\e2dimpl.h" /> <ClInclude Include="..\..\core\e2dimpl.h" />
<ClInclude Include="..\..\core\e2dmodule.h" /> <ClInclude Include="..\..\core\e2dmodule.h" />
<ClInclude Include="..\..\core\e2dmacros.h" /> <ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dtool.h" /> <ClInclude Include="..\..\core\e2dtool.h" />
<ClInclude Include="..\..\core\e2dtransition.h" /> <ClInclude Include="..\..\core\e2dtransition.h" />
</ItemGroup> </ItemGroup>

View File

@ -19,9 +19,6 @@
<Filter Include="events"> <Filter Include="events">
<UniqueIdentifier>{6c9657de-02d5-4d3b-9e1d-bc921eb5aea3}</UniqueIdentifier> <UniqueIdentifier>{6c9657de-02d5-4d3b-9e1d-bc921eb5aea3}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="managers">
<UniqueIdentifier>{9031e36b-fa85-4b4e-8e80-657c7e68f283}</UniqueIdentifier>
</Filter>
<Filter Include="transitions"> <Filter Include="transitions">
<UniqueIdentifier>{563b19f2-4c5e-4362-983a-94d2ae724550}</UniqueIdentifier> <UniqueIdentifier>{563b19f2-4c5e-4362-983a-94d2ae724550}</UniqueIdentifier>
</Filter> </Filter>
@ -102,18 +99,9 @@
<ClCompile Include="..\..\core\modules\Game.cpp"> <ClCompile Include="..\..\core\modules\Game.cpp">
<Filter>modules</Filter> <Filter>modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\modules\GC.cpp">
<Filter>modules</Filter>
</ClCompile>
<ClCompile Include="..\..\core\modules\Input.cpp"> <ClCompile Include="..\..\core\modules\Input.cpp">
<Filter>modules</Filter> <Filter>modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\modules\Renderer.cpp">
<Filter>modules</Filter>
</ClCompile>
<ClCompile Include="..\..\core\modules\Window.cpp">
<Filter>modules</Filter>
</ClCompile>
<ClCompile Include="..\..\core\utils\Color.cpp"> <ClCompile Include="..\..\core\utils\Color.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
@ -156,18 +144,12 @@
<ClCompile Include="..\..\core\impl\VoiceCallback.cpp"> <ClCompile Include="..\..\core\impl\VoiceCallback.cpp">
<Filter>impl</Filter> <Filter>impl</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\events\Collision.cpp">
<Filter>events</Filter>
</ClCompile>
<ClCompile Include="..\..\core\events\KeyEvent.cpp"> <ClCompile Include="..\..\core\events\KeyEvent.cpp">
<Filter>events</Filter> <Filter>events</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\events\MouseEvent.cpp"> <ClCompile Include="..\..\core\events\MouseEvent.cpp">
<Filter>events</Filter> <Filter>events</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\managers\CollisionManager.cpp">
<Filter>managers</Filter>
</ClCompile>
<ClCompile Include="..\..\core\tools\Data.cpp"> <ClCompile Include="..\..\core\tools\Data.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
@ -180,9 +162,6 @@
<ClCompile Include="..\..\core\tools\Path.cpp"> <ClCompile Include="..\..\core\tools\Path.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\tools\Player.cpp">
<Filter>tools</Filter>
</ClCompile>
<ClCompile Include="..\..\core\tools\Random.cpp"> <ClCompile Include="..\..\core\tools\Random.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
@ -207,9 +186,6 @@
<ClCompile Include="..\..\core\objects\Canvas.cpp"> <ClCompile Include="..\..\core\objects\Canvas.cpp">
<Filter>objects</Filter> <Filter>objects</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\objects\Collider.cpp">
<Filter>objects</Filter>
</ClCompile>
<ClCompile Include="..\..\core\objects\Image.cpp"> <ClCompile Include="..\..\core\objects\Image.cpp">
<Filter>objects</Filter> <Filter>objects</Filter>
</ClCompile> </ClCompile>
@ -234,12 +210,17 @@
<ClCompile Include="..\..\core\utils\Transform.cpp"> <ClCompile Include="..\..\core\utils\Transform.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\modules\Graphics.cpp">
<Filter>modules</Filter>
</ClCompile>
<ClCompile Include="..\..\core\modules\Device.cpp">
<Filter>modules</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\e2daction.h" /> <ClInclude Include="..\..\core\e2daction.h" />
<ClInclude Include="..\..\core\e2dmacros.h" /> <ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dtransition.h" /> <ClInclude Include="..\..\core\e2dtransition.h" />
<ClInclude Include="..\..\core\e2devent.h" /> <ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\e2dmodule.h" /> <ClInclude Include="..\..\core\e2dmodule.h" />

View File

@ -219,20 +219,16 @@
<ClCompile Include="..\..\core\actions\Spawn.cpp" /> <ClCompile Include="..\..\core\actions\Spawn.cpp" />
<ClCompile Include="..\..\core\components\Button.cpp" /> <ClCompile Include="..\..\core\components\Button.cpp" />
<ClCompile Include="..\..\core\components\Menu.cpp" /> <ClCompile Include="..\..\core\components\Menu.cpp" />
<ClCompile Include="..\..\core\events\Collision.cpp" />
<ClCompile Include="..\..\core\events\KeyEvent.cpp" /> <ClCompile Include="..\..\core\events\KeyEvent.cpp" />
<ClCompile Include="..\..\core\events\MouseEvent.cpp" /> <ClCompile Include="..\..\core\events\MouseEvent.cpp" />
<ClCompile Include="..\..\core\impl\TextRenderer.cpp" /> <ClCompile Include="..\..\core\impl\TextRenderer.cpp" />
<ClCompile Include="..\..\core\impl\VoiceCallback.cpp" /> <ClCompile Include="..\..\core\impl\VoiceCallback.cpp" />
<ClCompile Include="..\..\core\managers\CollisionManager.cpp" />
<ClCompile Include="..\..\core\modules\Audio.cpp" /> <ClCompile Include="..\..\core\modules\Audio.cpp" />
<ClCompile Include="..\..\core\modules\Device.cpp" />
<ClCompile Include="..\..\core\modules\Game.cpp" /> <ClCompile Include="..\..\core\modules\Game.cpp" />
<ClCompile Include="..\..\core\modules\GC.cpp" />
<ClCompile Include="..\..\core\modules\Input.cpp" /> <ClCompile Include="..\..\core\modules\Input.cpp" />
<ClCompile Include="..\..\core\modules\Graphics.cpp" /> <ClCompile Include="..\..\core\modules\Graphics.cpp" />
<ClCompile Include="..\..\core\modules\Window.cpp" />
<ClCompile Include="..\..\core\objects\Canvas.cpp" /> <ClCompile Include="..\..\core\objects\Canvas.cpp" />
<ClCompile Include="..\..\core\objects\Collider.cpp" />
<ClCompile Include="..\..\core\objects\Image.cpp" /> <ClCompile Include="..\..\core\objects\Image.cpp" />
<ClCompile Include="..\..\core\objects\Node.cpp" /> <ClCompile Include="..\..\core\objects\Node.cpp" />
<ClCompile Include="..\..\core\objects\Scene.cpp" /> <ClCompile Include="..\..\core\objects\Scene.cpp" />
@ -243,7 +239,6 @@
<ClCompile Include="..\..\core\tools\File.cpp" /> <ClCompile Include="..\..\core\tools\File.cpp" />
<ClCompile Include="..\..\core\tools\Music.cpp" /> <ClCompile Include="..\..\core\tools\Music.cpp" />
<ClCompile Include="..\..\core\tools\Path.cpp" /> <ClCompile Include="..\..\core\tools\Path.cpp" />
<ClCompile Include="..\..\core\tools\Player.cpp" />
<ClCompile Include="..\..\core\tools\Random.cpp" /> <ClCompile Include="..\..\core\tools\Random.cpp" />
<ClCompile Include="..\..\core\transitions\BoxTransition.cpp" /> <ClCompile Include="..\..\core\transitions\BoxTransition.cpp" />
<ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" /> <ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" />
@ -274,7 +269,6 @@
<ClInclude Include="..\..\core\e2dimpl.h" /> <ClInclude Include="..\..\core\e2dimpl.h" />
<ClInclude Include="..\..\core\e2dmodule.h" /> <ClInclude Include="..\..\core\e2dmodule.h" />
<ClInclude Include="..\..\core\e2dmacros.h" /> <ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dtool.h" /> <ClInclude Include="..\..\core\e2dtool.h" />
<ClInclude Include="..\..\core\e2dtransition.h" /> <ClInclude Include="..\..\core\e2dtransition.h" />
</ItemGroup> </ItemGroup>

View File

@ -19,9 +19,6 @@
<Filter Include="events"> <Filter Include="events">
<UniqueIdentifier>{6c9657de-02d5-4d3b-9e1d-bc921eb5aea3}</UniqueIdentifier> <UniqueIdentifier>{6c9657de-02d5-4d3b-9e1d-bc921eb5aea3}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="managers">
<UniqueIdentifier>{9031e36b-fa85-4b4e-8e80-657c7e68f283}</UniqueIdentifier>
</Filter>
<Filter Include="transitions"> <Filter Include="transitions">
<UniqueIdentifier>{563b19f2-4c5e-4362-983a-94d2ae724550}</UniqueIdentifier> <UniqueIdentifier>{563b19f2-4c5e-4362-983a-94d2ae724550}</UniqueIdentifier>
</Filter> </Filter>
@ -102,15 +99,9 @@
<ClCompile Include="..\..\core\modules\Game.cpp"> <ClCompile Include="..\..\core\modules\Game.cpp">
<Filter>modules</Filter> <Filter>modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\modules\GC.cpp">
<Filter>modules</Filter>
</ClCompile>
<ClCompile Include="..\..\core\modules\Input.cpp"> <ClCompile Include="..\..\core\modules\Input.cpp">
<Filter>modules</Filter> <Filter>modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\modules\Window.cpp">
<Filter>modules</Filter>
</ClCompile>
<ClCompile Include="..\..\core\utils\Color.cpp"> <ClCompile Include="..\..\core\utils\Color.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
@ -153,18 +144,12 @@
<ClCompile Include="..\..\core\impl\VoiceCallback.cpp"> <ClCompile Include="..\..\core\impl\VoiceCallback.cpp">
<Filter>impl</Filter> <Filter>impl</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\events\Collision.cpp">
<Filter>events</Filter>
</ClCompile>
<ClCompile Include="..\..\core\events\KeyEvent.cpp"> <ClCompile Include="..\..\core\events\KeyEvent.cpp">
<Filter>events</Filter> <Filter>events</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\events\MouseEvent.cpp"> <ClCompile Include="..\..\core\events\MouseEvent.cpp">
<Filter>events</Filter> <Filter>events</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\managers\CollisionManager.cpp">
<Filter>managers</Filter>
</ClCompile>
<ClCompile Include="..\..\core\tools\Data.cpp"> <ClCompile Include="..\..\core\tools\Data.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
@ -177,9 +162,6 @@
<ClCompile Include="..\..\core\tools\Path.cpp"> <ClCompile Include="..\..\core\tools\Path.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\tools\Player.cpp">
<Filter>tools</Filter>
</ClCompile>
<ClCompile Include="..\..\core\tools\Random.cpp"> <ClCompile Include="..\..\core\tools\Random.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
@ -204,9 +186,6 @@
<ClCompile Include="..\..\core\objects\Canvas.cpp"> <ClCompile Include="..\..\core\objects\Canvas.cpp">
<Filter>objects</Filter> <Filter>objects</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\objects\Collider.cpp">
<Filter>objects</Filter>
</ClCompile>
<ClCompile Include="..\..\core\objects\Image.cpp"> <ClCompile Include="..\..\core\objects\Image.cpp">
<Filter>objects</Filter> <Filter>objects</Filter>
</ClCompile> </ClCompile>
@ -234,12 +213,14 @@
<ClCompile Include="..\..\core\modules\Graphics.cpp"> <ClCompile Include="..\..\core\modules\Graphics.cpp">
<Filter>modules</Filter> <Filter>modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\modules\Device.cpp">
<Filter>modules</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\e2daction.h" /> <ClInclude Include="..\..\core\e2daction.h" />
<ClInclude Include="..\..\core\e2dmacros.h" /> <ClInclude Include="..\..\core\e2dmacros.h" />
<ClInclude Include="..\..\core\e2dmanager.h" />
<ClInclude Include="..\..\core\e2dtransition.h" /> <ClInclude Include="..\..\core\e2dtransition.h" />
<ClInclude Include="..\..\core\e2devent.h" /> <ClInclude Include="..\..\core\e2devent.h" />
<ClInclude Include="..\..\core\e2dmodule.h" /> <ClInclude Include="..\..\core\e2dmodule.h" />