diff options
author | chai <chaifix@163.com> | 2019-07-31 21:35:12 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-07-31 21:35:12 +0800 |
commit | 084623519e95f0ab0cf4bc328b5fa736d679c5bd (patch) | |
tree | 9d409dceda50335e9fb881fc5107c9c1c561f988 | |
parent | 012a44bd13ab41d056e7d3884a39027b6cea62b5 (diff) |
*修改名称空间风格
97 files changed, 3547 insertions, 3637 deletions
diff --git a/bin/win64/01-window.exe b/bin/win64/01-window.exe Binary files differindex ce9e832..111ed2d 100644 --- a/bin/win64/01-window.exe +++ b/bin/win64/01-window.exe diff --git a/build/modules/asura-utils/asura-utils.vcxproj b/build/modules/asura-utils/asura-utils.vcxproj index 3517962..c84c5a5 100644 --- a/build/modules/asura-utils/asura-utils.vcxproj +++ b/build/modules/asura-utils/asura-utils.vcxproj @@ -158,6 +158,7 @@ <ClCompile Include="..\..\..\source\modules\asura-utils\utils_module.cpp" /> </ItemGroup> <ItemGroup> + <ClInclude Include="..\..\..\source\modules\asura-utils\classes.h" /> <ClInclude Include="..\..\..\source\modules\asura-utils\exceptions\exception.h" /> <ClInclude Include="..\..\..\source\modules\asura-utils\io\compressor.h" /> <ClInclude Include="..\..\..\source\modules\asura-utils\io\data_buffer.h" /> diff --git a/build/modules/asura-utils/asura-utils.vcxproj.filters b/build/modules/asura-utils/asura-utils.vcxproj.filters index 3c6d092..027855d 100644 --- a/build/modules/asura-utils/asura-utils.vcxproj.filters +++ b/build/modules/asura-utils/asura-utils.vcxproj.filters @@ -226,6 +226,7 @@ <Filter>threading</Filter> </ClInclude> <ClInclude Include="..\..\..\source\modules\asura-utils\io\renewable.h" /> + <ClInclude Include="..\..\..\source\modules\asura-utils\classes.h" /> </ItemGroup> <ItemGroup> <None Include="..\..\..\source\modules\asura-utils\math\rect.inl"> diff --git a/source/modules/asura-core/application.cpp b/source/modules/asura-core/application.cpp index a630d4c..2f20e45 100644 --- a/source/modules/asura-core/application.cpp +++ b/source/modules/asura-core/application.cpp @@ -5,19 +5,19 @@ using namespace Luax; namespace AsuraEngine { - Application::Application() - { +Application::Application() +{ - } +} - Application::~Application() - { +Application::~Application() +{ - } +} - bool Application::InitSubModules(uint flag) - { - return false; - } +bool Application::InitSubModules(uint flag) +{ + return false; +} }
\ No newline at end of file diff --git a/source/modules/asura-core/application.h b/source/modules/asura-core/application.h index 0cde32f..c25e2d7 100644 --- a/source/modules/asura-core/application.h +++ b/source/modules/asura-core/application.h @@ -10,73 +10,73 @@ namespace AsuraEngine { +/// +/// ģ +/// +enum SubModules +{ + ASURA_MODULE_NONE = 0X00000000U, + + ASURA_MODULE_GRAPHICS = 1 << 1, + ASURA_MODULE_AUDIO = 1 << 2, + ASURA_MODULE_FONT = 1 << 3, + ASURA_MODULE_INPUT = 1 << 4, + ASURA_MODULE_MATH = 1 << 5, + ASURA_MODULE_PHYSICS = 1 << 6, + ASURA_MODULE_TIME = 1 << 7, + ASURA_MODULE_WINDOW = 1 << 8, + + ASURA_MODULE_ALL = 0XFFFFFFFFU +}; + +/// +/// ѭ +/// +class Application +{ +public: + + Application(); + + virtual ~Application(); + + /// + /// ʼǰϵͳ + /// + bool InitSubModules(uint flag = ASURA_MODULE_ALL); + /// - /// ģ + /// /// - enum SubModules - { - ASURA_MODULE_NONE = 0X00000000U, - - ASURA_MODULE_GRAPHICS = 1 << 1, - ASURA_MODULE_AUDIO = 1 << 2, - ASURA_MODULE_FONT = 1 << 3, - ASURA_MODULE_INPUT = 1 << 4, - ASURA_MODULE_MATH = 1 << 5, - ASURA_MODULE_PHYSICS = 1 << 6, - ASURA_MODULE_TIME = 1 << 7, - ASURA_MODULE_WINDOW = 1 << 8, - - ASURA_MODULE_ALL = 0XFFFFFFFFU - }; + virtual void Run(int argc, char* args[]); /// - /// ѭ + /// ˳runʱĴ /// - class Application - { - public: - - Application(); + virtual void OnExit(); - virtual ~Application(); +protected: - /// - /// ʼǰϵͳ - /// - bool InitSubModules(uint flag = ASURA_MODULE_ALL); - - /// - /// - /// - virtual void Run(int argc, char* args[]); - - /// - /// ˳runʱĴ - /// - virtual void OnExit(); - - protected: - - /// - /// moduleapplicationӵmoduleȨ - /// - void EnqueueModule(Module* module); + /// + /// moduleapplicationӵmoduleȨ + /// + void EnqueueModule(Module* module); - private: +private: - /// - /// ̵߳lua state handleӦѭСһ˵ֻҪ߳һlua_State̲߳Ҫ̼߳ - /// lua̫ʹˡC++дȻעһصһ̴߳lua_Stateעắִк - /// ̵߳lua_Stateֻ֤һnativeʵ֮һlua_State - /// - Luax::LuaxVM* m_VM; + /// + /// ̵߳lua state handleӦѭСһ˵ֻҪ߳һlua_State̲߳Ҫ̼߳ + /// lua̫ʹˡC++дȻעһصһ̴߳lua_Stateעắִк + /// ̵߳lua_Stateֻ֤һnativeʵ֮һlua_State + /// + Luax::LuaxVM* m_VM; - /// - /// Asura libsᰴն˳ʼ˳ʱִ˳ - /// - std::queue<Module*> m_Modules; + /// + /// Asura libsᰴն˳ʼ˳ʱִ˳ + /// + std::queue<Module*> m_Modules; - }; +}; } diff --git a/source/modules/asura-core/graphics/binding/_canvas.cpp b/source/modules/asura-core/graphics/binding/_canvas.cpp index 6728ff3..6dda773 100644 --- a/source/modules/asura-core/graphics/binding/_canvas.cpp +++ b/source/modules/asura-core/graphics/binding/_canvas.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Canvas) { diff --git a/source/modules/asura-core/graphics/binding/_color.cpp b/source/modules/asura-core/graphics/binding/_color.cpp index f06622c..c990d8b 100644 --- a/source/modules/asura-core/graphics/binding/_color.cpp +++ b/source/modules/asura-core/graphics/binding/_color.cpp @@ -3,129 +3,128 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + - LUAX_REGISTRY(Color) - { - LUAX_REGISTER_METHODS(state, - { "ToColor32", _ToColor32 }, - { "SetColor", _SetColor }, - { "GetColor", _GetColor }, - { "GetR", _GetR }, - { "GetG", _GetG }, - { "GetB", _GetB }, - { "GetA", _GetA }, - { "__eq", ___eq }, - { "__add", ___add }, - { "__sub", ___sub }, - { "__mul", ___mul }, - { "__div", ___div } - ); - } - - LUAX_POSTPROCESS(Color) - { - - } - - // color:ToColor32() - LUAX_IMPL_METHOD(Color, _ToColor32) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:SetColor() - LUAX_IMPL_METHOD(Color, _SetColor) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:GetColor() - LUAX_IMPL_METHOD(Color, _GetColor) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:GetR() - LUAX_IMPL_METHOD(Color, _GetR) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:GetG() - LUAX_IMPL_METHOD(Color, _GetG) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:GetB() - LUAX_IMPL_METHOD(Color, _GetB) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:GetA() - LUAX_IMPL_METHOD(Color, _GetA) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:__eq() - LUAX_IMPL_METHOD(Color, ___eq) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:__add() - LUAX_IMPL_METHOD(Color, ___add) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:__sub() - LUAX_IMPL_METHOD(Color, ___sub) - { - LUAX_PREPARE(L, Color); - - return 0; - } - - // color:__mul() - LUAX_IMPL_METHOD(Color, ___mul) - { - LUAX_PREPARE(L, Color); - - return 0; - } +LUAX_REGISTRY(Color) +{ + LUAX_REGISTER_METHODS(state, + { "ToColor32", _ToColor32 }, + { "SetColor", _SetColor }, + { "GetColor", _GetColor }, + { "GetR", _GetR }, + { "GetG", _GetG }, + { "GetB", _GetB }, + { "GetA", _GetA }, + { "__eq", ___eq }, + { "__add", ___add }, + { "__sub", ___sub }, + { "__mul", ___mul }, + { "__div", ___div } + ); +} + +LUAX_POSTPROCESS(Color) +{ + +} + +// color:ToColor32() +LUAX_IMPL_METHOD(Color, _ToColor32) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:SetColor() +LUAX_IMPL_METHOD(Color, _SetColor) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetColor() +LUAX_IMPL_METHOD(Color, _GetColor) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetR() +LUAX_IMPL_METHOD(Color, _GetR) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetG() +LUAX_IMPL_METHOD(Color, _GetG) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetB() +LUAX_IMPL_METHOD(Color, _GetB) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetA() +LUAX_IMPL_METHOD(Color, _GetA) +{ + LUAX_PREPARE(L, Color); - // color:__div() - LUAX_IMPL_METHOD(Color, ___div) - { - LUAX_PREPARE(L, Color); + return 0; +} + +// color:__eq() +LUAX_IMPL_METHOD(Color, ___eq) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__add() +LUAX_IMPL_METHOD(Color, ___add) +{ + LUAX_PREPARE(L, Color); - return 0; - } + return 0; +} + +// color:__sub() +LUAX_IMPL_METHOD(Color, ___sub) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__mul() +LUAX_IMPL_METHOD(Color, ___mul) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__div() +LUAX_IMPL_METHOD(Color, ___div) +{ + LUAX_PREPARE(L, Color); + + return 0; +} - } } +}
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/binding/_color32.cpp b/source/modules/asura-core/graphics/binding/_color32.cpp index f2f716a..96c63af 100644 --- a/source/modules/asura-core/graphics/binding/_color32.cpp +++ b/source/modules/asura-core/graphics/binding/_color32.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Color32) { diff --git a/source/modules/asura-core/graphics/binding/_gfx_device.cpp b/source/modules/asura-core/graphics/binding/_gfx_device.cpp index 5ae475c..60a0b0b 100644 --- a/source/modules/asura-core/graphics/binding/_gfx_device.cpp +++ b/source/modules/asura-core/graphics/binding/_gfx_device.cpp @@ -3,10 +3,9 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(GfxDevice) { diff --git a/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp b/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp index 785496e..479901e 100644 --- a/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp +++ b/source/modules/asura-core/graphics/binding/_gpu_buffer.cpp @@ -6,10 +6,9 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(GPUBuffer) { diff --git a/source/modules/asura-core/graphics/binding/_image.cpp b/source/modules/asura-core/graphics/binding/_image.cpp index 99373e3..0e4cb16 100644 --- a/source/modules/asura-core/graphics/binding/_image.cpp +++ b/source/modules/asura-core/graphics/binding/_image.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Image) { diff --git a/source/modules/asura-core/graphics/binding/_index_buffer.cpp b/source/modules/asura-core/graphics/binding/_index_buffer.cpp index 56bffb7..eb81699 100644 --- a/source/modules/asura-core/graphics/binding/_index_buffer.cpp +++ b/source/modules/asura-core/graphics/binding/_index_buffer.cpp @@ -3,10 +3,9 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(IndexBuffer) { diff --git a/source/modules/asura-core/graphics/binding/_mesh2d.cpp b/source/modules/asura-core/graphics/binding/_mesh2d.cpp index 07e9f12..4e3f426 100644 --- a/source/modules/asura-core/graphics/binding/_mesh2d.cpp +++ b/source/modules/asura-core/graphics/binding/_mesh2d.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Mesh2D) { diff --git a/source/modules/asura-core/graphics/binding/_shader.cpp b/source/modules/asura-core/graphics/binding/_shader.cpp index 71f4e28..85fd388 100644 --- a/source/modules/asura-core/graphics/binding/_shader.cpp +++ b/source/modules/asura-core/graphics/binding/_shader.cpp @@ -3,10 +3,9 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Shader) { diff --git a/source/modules/asura-core/graphics/binding/_sprite_batch.cpp b/source/modules/asura-core/graphics/binding/_sprite_batch.cpp index 8556c02..7795d26 100644 --- a/source/modules/asura-core/graphics/binding/_sprite_batch.cpp +++ b/source/modules/asura-core/graphics/binding/_sprite_batch.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(SpriteBatch) { diff --git a/source/modules/asura-core/graphics/binding/_texture.cpp b/source/modules/asura-core/graphics/binding/_texture.cpp index 305ac22..f5e5f17 100644 --- a/source/modules/asura-core/graphics/binding/_texture.cpp +++ b/source/modules/asura-core/graphics/binding/_texture.cpp @@ -2,10 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(Texture) { diff --git a/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp b/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp index 666e529..b181df3 100644 --- a/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp +++ b/source/modules/asura-core/graphics/binding/_vertex_buffer.cpp @@ -3,10 +3,9 @@ using namespace std; using namespace Luax; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + LUAX_REGISTRY(VertexBuffer) { diff --git a/source/modules/asura-core/graphics/blend_mode.h b/source/modules/asura-core/graphics/blend_mode.h index 775cc45..73e1a41 100644 --- a/source/modules/asura-core/graphics/blend_mode.h +++ b/source/modules/asura-core/graphics/blend_mode.h @@ -1,17 +1,17 @@ #ifndef __ASURA_ENGINE_BLEND_MODE_H__ #define __ASURA_ENGINE_BLEND_MODE_H__ -namespace AsuraEngine -{ - namespace Graphics - { +#include <asura-utils/classes.h> + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - enum BlendMode - { +enum BlendMode +{ - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/canvas.cpp b/source/modules/asura-core/graphics/canvas.cpp index e922a51..60c8f87 100644 --- a/source/modules/asura-core/graphics/canvas.cpp +++ b/source/modules/asura-core/graphics/canvas.cpp @@ -1,50 +1,49 @@ #include "Canvas.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Canvas::Canvas() + : m_Width(0) + , m_Height(0) + , m_FBO(0) { - namespace Graphics - { + // Fix: ôСʼʱframebufferԴ + //glGenFramebuffers(1, &m_FBO); + //GLint current_fbo; + //glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + //glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); + //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); + //glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); +} - Canvas::Canvas() - : m_Width(0) - , m_Height(0) - , m_FBO(0) +void Canvas::SetSize(uint w, uint h) +{ + if (m_FBO == 0) + { + glGenFramebuffers(1, &m_FBO); + if (m_FBO == 0) + throw Exception("OpenGL glGenFramebuffers cannot generate frame buffer object."); + // + if (m_TexID == 0) { - // Fix: ôСʼʱframebufferԴ - //glGenFramebuffers(1, &m_FBO); - //GLint current_fbo; - //glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); - //glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); - //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); - //glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); + glGenTextures(1, &m_TexID); + if (m_TexID == 0) + throw Exception("OpenGL glGenTextures cannot generate texture."); } + GLint current_fbo; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); + glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); + } + GLint current_tex; + glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); + glBindTexture(GL_TEXTURE_2D, m_TexID); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, current_tex); +} - void Canvas::SetSize(uint w, uint h) - { - if (m_FBO == 0) - { - glGenFramebuffers(1, &m_FBO); - if (m_FBO == 0) - throw Exception("OpenGL glGenFramebuffers cannot generate frame buffer object."); - // - if (m_TexID == 0) - { - glGenTextures(1, &m_TexID); - if (m_TexID == 0) - throw Exception("OpenGL glGenTextures cannot generate texture."); - } - GLint current_fbo; - glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); - glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); - glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); - } - GLint current_tex; - glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); - glBindTexture(GL_TEXTURE_2D, m_TexID); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, current_tex); - } +namespace_end - } -}
\ No newline at end of file +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/canvas.h b/source/modules/asura-core/graphics/canvas.h index 332e973..bbd098a 100644 --- a/source/modules/asura-core/graphics/canvas.h +++ b/source/modules/asura-core/graphics/canvas.h @@ -11,64 +11,63 @@ #include "render_target.h" #include "render_state.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + - /// - /// CanvasҲԳΪrender textureҲΪtextureȾ - /// - class Canvas ASURA_FINAL - : public Scripting::Portable<Canvas, RenderTarget> - { - public: +/// +/// CanvasҲԳΪrender textureҲΪtextureȾ +/// +class Canvas ASURA_FINAL + : public Scripting::Portable<Canvas, RenderTarget> +{ +public: - Canvas(); + Canvas(); - ~Canvas(); + ~Canvas(); - /// - /// render textureĴС - /// - void SetSize(uint w, uint h) ASURA_THROW(Exception); + /// + /// render textureĴС + /// + void SetSize(uint w, uint h) ASURA_THROW(Exception); - void Clear(const Color& col = Color::Black) override; + void Clear(const Color& col = Color::Black) override; /* - void Clear(const Math::Recti& quad, const Color& col = Color::Black) override; + void Clear(const Math::Recti& quad, const Color& col = Color::Black) override; */ - void Render(const RenderTarget* rt, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + void Render(const RenderTarget* rt, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); - void Render(const RenderTarget* rt, const Math::Rectf& quad, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + void Render(const RenderTarget* rt, const Math::Rectf& quad, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); - void Draw(const Drawable* texture, const RenderState& state); + void Draw(const Drawable* texture, const RenderState& state); - void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state); + void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state); - private: +private: - GLuint m_FBO; + GLuint m_FBO; - GLuint m_TexID; + GLuint m_TexID; - uint m_Width, m_Height; + uint m_Width, m_Height; - luaxport: +luaxport: - LUAX_DECL_FACTORY(Canvas, RenderTarget); + LUAX_DECL_FACTORY(Canvas, RenderTarget); - LUAX_DECL_METHOD(_SetSize); - LUAX_DECL_METHOD(_Bind); - LUAX_DECL_METHOD(_Unbind); + LUAX_DECL_METHOD(_SetSize); + LUAX_DECL_METHOD(_Bind); + LUAX_DECL_METHOD(_Unbind); - }; +}; - /// - /// CanvasΪRenderTexture - /// - typedef Canvas RenderTexture; +/// +/// CanvasΪRenderTexture +/// +typedef Canvas RenderTexture; - } -} +} // Graphics +} // AsuraEngine #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/color.cpp b/source/modules/asura-core/graphics/color.cpp index 76e0942..47e039f 100644 --- a/source/modules/asura-core/graphics/color.cpp +++ b/source/modules/asura-core/graphics/color.cpp @@ -1,60 +1,58 @@ #include "color.h" #include "color32.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Color::Color() +{ + r = g = b = a = 0; +} + +Color::Color(const Color& c) +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; +} + +Color::Color(float r, float g, float b, float a) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +Color::Color(const Color32& c) +{ + r = c.r / 255.f; + g = c.g / 255.f; + b = c.b / 255.f; + a = c.a / 255.f; +} + +Color::~Color() +{ +} + +void Color::Set(float r, float g, float b, float a) { - namespace Graphics - { - - Color::Color() - { - r = g = b = a = 0; - } - - Color::Color(const Color& c) - { - r = c.r; - g = c.g; - b = c.b; - a = c.a; - } - - Color::Color(float r, float g, float b, float a) - { - this->r = r; - this->g = g; - this->b = b; - this->a = a; - } - - Color::Color(const Color32& c) - { - r = c.r / 255.f; - g = c.g / 255.f; - b = c.b / 255.f; - a = c.a / 255.f; - } - - Color::~Color() - { - } - - void Color::Set(float r, float g, float b, float a) - { - this->r = r; - this->g = g; - this->b = b; - this->a = a; - } - - //Color Color::operator *(const Color& c) - //{ - // r *= c.r; - // g *= c.g; - // b *= c.b; - // a *= c.a; - - //} - - } -}
\ No newline at end of file + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +//Color Color::operator *(const Color& c) +//{ +// r *= c.r; +// g *= c.g; +// b *= c.b; +// a *= c.a; + +//} + +namespace_end +namespace_end diff --git a/source/modules/asura-core/graphics/color.h b/source/modules/asura-core/graphics/color.h index b29c43f..99a9b00 100644 --- a/source/modules/asura-core/graphics/color.h +++ b/source/modules/asura-core/graphics/color.h @@ -2,69 +2,73 @@ #define __ASURA_ENGINE_COLOR_H__ #include <asura-utils/scripting/portable.hpp> +#include <asura-utils/classes.h> #include "../core_config.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - class Color32; +class Color32; - /// - /// 淶ɫColor32иIJԡ - /// - class Color ASURA_FINAL - : public Scripting::Portable<Color> - { - public: +/// +/// 淶ɫColor32иIJԡ +/// +class Color ASURA_FINAL + : public Scripting::Portable<Color> +{ +public: - static Color Black; - static Color White; - static Color Red; - static Color Green; - static Color Blue; + static Color Black; + static Color White; + static Color Red; + static Color Green; + static Color Blue; - Color(); + Color(); - Color(const Color& c); + Color(const Color& c); - Color(float r, float g, float b, float a); + Color(float r, float g, float b, float a); - Color(const Color32& c); + Color(const Color32& c); - ~Color(); + ~Color(); - Color operator *(const Color& c); + Color operator *(const Color& c); - void Set(float r, float g, float b, float a); + void Set(float r, float g, float b, float a); + + GET_SET(float, Red, r); + GET_SET(float, Green, g); + GET_SET(float, Blue, b); + GET_SET(float, Alpha, a); - float r, g, b, a; + float r, g, b, a; - luaxport: +luaxport: - LUAX_DECL_FACTORY(Color); + LUAX_DECL_FACTORY(Color); - LUAX_DECL_METHOD(_ToColor32); - LUAX_DECL_METHOD(_SetColor); - LUAX_DECL_METHOD(_GetColor); - LUAX_DECL_METHOD(_GetR); - LUAX_DECL_METHOD(_GetG); - LUAX_DECL_METHOD(_GetB); - LUAX_DECL_METHOD(_GetA); + LUAX_DECL_METHOD(_ToColor32); + LUAX_DECL_METHOD(_SetColor); + LUAX_DECL_METHOD(_GetColor); + LUAX_DECL_METHOD(_GetR); + LUAX_DECL_METHOD(_GetG); + LUAX_DECL_METHOD(_GetB); + LUAX_DECL_METHOD(_GetA); - // Ԫ - LUAX_DECL_METHOD(___eq); // __eq - LUAX_DECL_METHOD(___add); // __add - LUAX_DECL_METHOD(___sub); // __sub - LUAX_DECL_METHOD(___mul); // __mul - LUAX_DECL_METHOD(___div); // __div + // Ԫ + LUAX_DECL_METHOD(___eq); // __eq + LUAX_DECL_METHOD(___add); // __add + LUAX_DECL_METHOD(___sub); // __sub + LUAX_DECL_METHOD(___mul); // __mul + LUAX_DECL_METHOD(___div); // __div - }; +}; - } -} +namespace_end +namespace_end namespace AEGraphics = AsuraEngine::Graphics; diff --git a/source/modules/asura-core/graphics/color32.cpp b/source/modules/asura-core/graphics/color32.cpp index 28260d5..11239c8 100644 --- a/source/modules/asura-core/graphics/color32.cpp +++ b/source/modules/asura-core/graphics/color32.cpp @@ -1,55 +1,53 @@ #include "color.h" #include "color32.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) #if ASURA_LITTLE_ENDIAN - // СˣֽڵAlphaڸߵַ - const uint32 Color32::RMASK = 0x000000ff; - const uint32 Color32::GMASK = 0x0000ff00; - const uint32 Color32::BMASK = 0x00ff0000; - const uint32 Color32::AMASK = 0xff000000; +// СˣֽڵAlphaڸߵַ +const uint32 Color32::RMASK = 0x000000ff; +const uint32 Color32::GMASK = 0x0000ff00; +const uint32 Color32::BMASK = 0x00ff0000; +const uint32 Color32::AMASK = 0xff000000; #endif - Color32::Color32() - { - r = g = b = a = 0; - } - - Color32::Color32(const Color32& c) - { - r = c.r; - g = c.g; - b = c.b; - a = c.a; - } - - Color32::Color32(const Color& c) - { - r = 255.f * c.r; - g = 255.f * c.g; - b = 255.f * c.b; - a = 255.f * c.a; - } - - Color32::Color32(byte r, byte g, byte b, byte a) - { - this->r = r; - this->g = g; - this->b = b; - this->a = a; - } - - void Color32::Set(const Color32& c32) - { - r = c32.r; - g = c32.g; - b = c32.b; - a = c32.a; - } - - } -}
\ No newline at end of file +Color32::Color32() +{ + r = g = b = a = 0; +} + +Color32::Color32(const Color32& c) +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; +} + +Color32::Color32(const Color& c) +{ + r = 255.f * c.r; + g = 255.f * c.g; + b = 255.f * c.b; + a = 255.f * c.a; +} + +Color32::Color32(byte r, byte g, byte b, byte a) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +void Color32::Set(const Color32& c32) +{ + r = c32.r; + g = c32.g; + b = c32.b; + a = c32.a; +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/color32.h b/source/modules/asura-core/graphics/color32.h index 9f14155..52405e9 100644 --- a/source/modules/asura-core/graphics/color32.h +++ b/source/modules/asura-core/graphics/color32.h @@ -1,59 +1,58 @@ #ifndef __ASURA_ENGINE_COLOR32_H__ #define __ASURA_ENGINE_COLOR32_H__ +#include <asura-utils/classes.h> #include <asura-utils/scripting/portable.hpp> #include "../core_config.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - class Color; +class Color; - /// - /// 32bitsɫ - /// - class Color32 ASURA_FINAL - : public Scripting::Portable<Color32> - { - public: +/// +/// 32bitsɫ +/// +class Color32 ASURA_FINAL + : public Scripting::Portable<Color32> +{ +public: - static const uint32 RMASK; - static const uint32 GMASK; - static const uint32 BMASK; - static const uint32 AMASK; + static const uint32 RMASK; + static const uint32 GMASK; + static const uint32 BMASK; + static const uint32 AMASK; - Color32(); + Color32(); - ~Color32(); + ~Color32(); - Color32(const Color32& c); + Color32(const Color32& c); - Color32(const Color& c); + Color32(const Color& c); - Color32(byte r, byte g, byte b, byte a); + Color32(byte r, byte g, byte b, byte a); - void Set(const Color32& c32); + void Set(const Color32& c32); - byte r, g, b, a; + byte r, g, b, a; - luaxport: +luaxport: - LUAX_DECL_FACTORY(Color32); + LUAX_DECL_FACTORY(Color32); - LUAX_DECL_METHOD(_ToColor); - LUAX_DECL_METHOD(_SetColor); - LUAX_DECL_METHOD(_GetColor); - LUAX_DECL_METHOD(_GetRed); - LUAX_DECL_METHOD(_GetGreen); - LUAX_DECL_METHOD(_GetBlue); - LUAX_DECL_METHOD(_GetAlpha); + LUAX_DECL_METHOD(_ToColor); + LUAX_DECL_METHOD(_SetColor); + LUAX_DECL_METHOD(_GetColor); + LUAX_DECL_METHOD(_GetRed); + LUAX_DECL_METHOD(_GetGreen); + LUAX_DECL_METHOD(_GetBlue); + LUAX_DECL_METHOD(_GetAlpha); - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gfx_device.cpp b/source/modules/asura-core/graphics/gfx_device.cpp index 83ea7f4..234ab23 100644 --- a/source/modules/asura-core/graphics/gfx_device.cpp +++ b/source/modules/asura-core/graphics/gfx_device.cpp @@ -9,201 +9,200 @@ using namespace AEMath; -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) #if ASURA_DEBUG - static bool instantiated = false; +static bool instantiated = false; #endif - GfxDevice gfx; +GfxDevice gfx; - GfxDevice::GfxDevice() - { +GfxDevice::GfxDevice() +{ #if ASURA_DEBUG - ASSERT(!instantiated); - instantiated = true; + ASSERT(!instantiated); + instantiated = true; #endif - } +} - GfxDevice::~GfxDevice() - { - } +GfxDevice::~GfxDevice() +{ +} - GfxDevice& GfxDevice::Get() - { - return gfx; - } +GfxDevice& GfxDevice::Get() +{ + return gfx; +} - static bool inited = false; +static bool inited = false; - bool GfxDevice::Init(const AEMath::Recti& view) - { - bool loaded = false; +bool GfxDevice::Init(const AEMath::Recti& view) +{ + bool loaded = false; #if ASURA_OPENGL_LOADER & ASURA_OPENGL_GLAD - if (!loaded) - loaded = gladLoadGL(); + if (!loaded) + loaded = gladLoadGL(); #endif - if (!loaded) - return false; - SetViewport(view); - - inited = true; - return true; - } - - bool GfxDevice::Inited() - { - return inited; - } - - void GfxDevice::WipeError() - { - while (glGetError() != GL_NO_ERROR); - } - - bool GfxDevice::HasError() - { - return glGetError() != GL_NO_ERROR; - } - - GLenum GfxDevice::GetError() - { - return glGetError(); - } - - void GfxDevice::SetDrawColor(float r, float g, float b, float a) - { - state.drawColor.Set(r, g, b, a); - } - - Color& GfxDevice::GetDrawColor() - { - return state.drawColor; - } - - Canvas* GfxDevice::GetActiveCanvas() const - { - return state.canvas; - } - - void GfxDevice::SetActiveCanvas(Canvas* canvas) - { - state.canvas = canvas; - } - - void GfxDevice::SetViewport(const Recti v) - { - state.viewport = v; - glViewport(v.x, v.y, v.w, v.h); - } - - const Recti& GfxDevice::GetViewport() - { - return state.viewport; - } - - void GfxDevice::SetActiveShader(Shader* shader) - { - if (state.shader == shader) - return; - if (state.shader) - state.shader->OnDisable(); - state.shader = shader; - if (shader) - { - GLint program = shader->GetGLProgram(); - glUseProgram(program); + if (!loaded) + return false; + SetViewport(view); + + inited = true; + return true; +} + +bool GfxDevice::Inited() +{ + return inited; +} + +void GfxDevice::WipeError() +{ + while (glGetError() != GL_NO_ERROR); +} + +bool GfxDevice::HasError() +{ + return glGetError() != GL_NO_ERROR; +} + +GLenum GfxDevice::GetError() +{ + return glGetError(); +} + +void GfxDevice::SetDrawColor(float r, float g, float b, float a) +{ + state.drawColor.Set(r, g, b, a); +} + +Color& GfxDevice::GetDrawColor() +{ + return state.drawColor; +} + +Canvas* GfxDevice::GetActiveCanvas() const +{ + return state.canvas; +} + +void GfxDevice::SetActiveCanvas(Canvas* canvas) +{ + state.canvas = canvas; +} + +void GfxDevice::SetViewport(const Recti v) +{ + state.viewport = v; + glViewport(v.x, v.y, v.w, v.h); +} + +const Recti& GfxDevice::GetViewport() +{ + return state.viewport; +} + +void GfxDevice::SetActiveShader(Shader* shader) +{ + if (state.shader == shader) + return; + if (state.shader) + state.shader->OnDisable(); + state.shader = shader; + if (shader) + { + GLint program = shader->GetGLProgram(); + glUseProgram(program); #if ASURA_GL_PROFILE - ++stats.shaderSwitch; + ++stats.shaderSwitch; #endif - shader->OnEnable(); - } - } - - Shader* GfxDevice::GetActiveShader() const - { - return state.shader; - } - - void GfxDevice::DrawArrays(GLenum mode, GLint first, GLsizei count) - { - glDrawArrays(mode, first, count); + shader->OnEnable(); + } +} + +Shader* GfxDevice::GetActiveShader() const +{ + return state.shader; +} + +void GfxDevice::DrawArrays(GLenum mode, GLint first, GLsizei count) +{ + glDrawArrays(mode, first, count); #if ASURA_GL_PROFILE - ++stats.drawCall; + ++stats.drawCall; #endif - if (state.shader) - state.shader->OnUsed(); - } - - void GfxDevice::SetMatrixMode (MatrixMode mode) - { - state.matrixMode = mode; - } - - MatrixMode GfxDevice::GetMatrixMode () - { - return state.matrixMode; - } - - void GfxDevice::PushMatrix () - { - state.matrix[state.matrixMode].Push (); - } - - void GfxDevice::PopMatrix () - { - state.matrix[state.matrixMode].Pop(); - } - - void GfxDevice::LoadIdentity() - { - state.matrix[state.matrixMode].LoadIdentity(); - } - - void GfxDevice::Rotate (float angle) - { - state.matrix[state.matrixMode].Rotate(angle); - } - - void GfxDevice::Translate (float x, float y) - { - state.matrix[state.matrixMode].Translate(x, y); - } - - void GfxDevice::Scale (float x, float y) - { - state.matrix[state.matrixMode].Scale(x, y); - } - - void GfxDevice::Ortho(float l, float r, float b, float t, float n, float f) - { - state.matrix[state.matrixMode].Ortho(l, r, b, t, n, f); - } - - AEMath::Matrix44& GfxDevice::GetMatrix(MatrixMode mode) - { - return state.matrix[mode].GetTop(); - } - - AEMath::Matrix44 GfxDevice::GetMVPMatrix() - { - return state.matrix[MATRIX_MODE_PROJECTION].GetTop() - * state.matrix[MATRIX_MODE_VIEW].GetTop() - * state.matrix[MATRIX_MODE_MODEL].GetTop(); - } - - uint GfxDevice::GetMatrixDepth() - { - return state.matrix[state.matrixMode].GetCapacity(); - } - - uint GfxDevice::GetMatrixIndex() - { - return state.matrix[state.matrixMode].GetTopIndex(); - } - - } // Graphics -} // AsuraEngine
\ No newline at end of file + if (state.shader) + state.shader->OnUsed(); +} + +void GfxDevice::SetMatrixMode (MatrixMode mode) +{ + state.matrixMode = mode; +} + +MatrixMode GfxDevice::GetMatrixMode () +{ + return state.matrixMode; +} + +void GfxDevice::PushMatrix () +{ + state.matrix[state.matrixMode].Push (); +} + +void GfxDevice::PopMatrix () +{ + state.matrix[state.matrixMode].Pop(); +} + +void GfxDevice::LoadIdentity() +{ + state.matrix[state.matrixMode].LoadIdentity(); +} + +void GfxDevice::Rotate (float angle) +{ + state.matrix[state.matrixMode].Rotate(angle); +} + +void GfxDevice::Translate (float x, float y) +{ + state.matrix[state.matrixMode].Translate(x, y); +} + +void GfxDevice::Scale (float x, float y) +{ + state.matrix[state.matrixMode].Scale(x, y); +} + +void GfxDevice::Ortho(float l, float r, float b, float t, float n, float f) +{ + state.matrix[state.matrixMode].Ortho(l, r, b, t, n, f); +} + +AEMath::Matrix44& GfxDevice::GetMatrix(MatrixMode mode) +{ + return state.matrix[mode].GetTop(); +} + +AEMath::Matrix44 GfxDevice::GetMVPMatrix() +{ + return state.matrix[MATRIX_MODE_PROJECTION].GetTop() + * state.matrix[MATRIX_MODE_VIEW].GetTop() + * state.matrix[MATRIX_MODE_MODEL].GetTop(); +} + +uint GfxDevice::GetMatrixDepth() +{ + return state.matrix[state.matrixMode].GetCapacity(); +} + +uint GfxDevice::GetMatrixIndex() +{ + return state.matrix[state.matrixMode].GetTopIndex(); +} + + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gfx_device.h b/source/modules/asura-core/graphics/gfx_device.h index 385f703..8d401dc 100644 --- a/source/modules/asura-core/graphics/gfx_device.h +++ b/source/modules/asura-core/graphics/gfx_device.h @@ -13,129 +13,127 @@ #include "color.h" #include "matrix_stack.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - class Profiler; - class Shader; - class GPUBuffer; - class Canvas; +class Profiler; +class Shader; +class GPUBuffer; +class Canvas; - enum MatrixMode - { - MATRIX_MODE_PROJECTION = 0, - MATRIX_MODE_MODEL = 1, - MATRIX_MODE_VIEW = 2, - }; +enum MatrixMode +{ + MATRIX_MODE_PROJECTION = 0, + MATRIX_MODE_MODEL = 1, + MATRIX_MODE_VIEW = 2, +}; - enum GLParams - { - GL_PARAM_MAX_TEXTURE_UNIT = 1, - }; +enum GLParams +{ + GL_PARAM_MAX_TEXTURE_UNIT = 1, +}; - class GfxDevice : public AEScripting::Portable<GfxDevice> - { - public: +class GfxDevice : public AEScripting::Portable<GfxDevice> +{ +public: - GfxDevice(); - ~GfxDevice(); + GfxDevice(); + ~GfxDevice(); - static GfxDevice& Get(); + static GfxDevice& Get(); - int GetParam(GLParams param); + int GetParam(GLParams param); - bool Init(const AEMath::Recti& viewport); - bool Inited(); + bool Init(const AEMath::Recti& viewport); + bool Inited(); - void SetViewport(const AEMath::Recti viewport); + void SetViewport(const AEMath::Recti viewport); - const AEMath::Recti& GetViewport(); + const AEMath::Recti& GetViewport(); - void SetMatrixMode(MatrixMode mode); - MatrixMode GetMatrixMode(); + void SetMatrixMode(MatrixMode mode); + MatrixMode GetMatrixMode(); - void PushMatrix(); - void PopMatrix(); + void PushMatrix(); + void PopMatrix(); - void LoadIdentity(); - void Rotate(float angle); - void Translate(float x, float y); - void Scale(float x, float y); - void Ortho(float l, float r, float b, float t, float n, float f); + void LoadIdentity(); + void Rotate(float angle); + void Translate(float x, float y); + void Scale(float x, float y); + void Ortho(float l, float r, float b, float t, float n, float f); - uint GetMatrixDepth(); - uint GetMatrixIndex(); + uint GetMatrixDepth(); + uint GetMatrixIndex(); - AEMath::Matrix44& GetMatrix(MatrixMode mode); - AEMath::Matrix44 GetMVPMatrix(); + AEMath::Matrix44& GetMatrix(MatrixMode mode); + AEMath::Matrix44 GetMVPMatrix(); - void SetDrawColor(float r, float g, float b, float a); - Color& GetDrawColor(); + void SetDrawColor(float r, float g, float b, float a); + Color& GetDrawColor(); - void SetActiveCanvas(Canvas* = NULL); - Canvas* GetActiveCanvas() const; + void SetActiveCanvas(Canvas* = NULL); + Canvas* GetActiveCanvas() const; - void SetActiveShader(Shader* = NULL); - Shader* GetActiveShader() const; + void SetActiveShader(Shader* = NULL); + Shader* GetActiveShader() const; - void DrawArrays(GLenum mode, GLint first, GLsizei count); + void DrawArrays(GLenum mode, GLint first, GLsizei count); - void WipeError(); - bool HasError(); - GLenum GetError(); + void WipeError(); + bool HasError(); + GLenum GetError(); - private: +private: - friend class Profiler; + friend class Profiler; - struct - { - AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 - MatrixStack matrix[3]; ///< model, view, projection - MatrixMode matrixMode; ///< ǰľ - Color drawColor; ///< Ƶɫ - Canvas* canvas; ///< ǰcanvas - Shader* shader; ///< ǰʹõshader - } state; + struct + { + AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 + MatrixStack matrix[3]; ///< model, view, projection + MatrixMode matrixMode; ///< ǰľ + Color drawColor; ///< Ƶɫ + Canvas* canvas; ///< ǰcanvas + Shader* shader; ///< ǰʹõshader + } state; #if ASURA_GL_PROFILE - struct - { - uint drawCall; ///< ͳdrawcall - uint canvasSwitch; ///< лtextureĴ - uint shaderSwitch; ///< лshaderĴ - } stats; + struct + { + uint drawCall; ///< ͳdrawcall + uint canvasSwitch; ///< лtextureĴ + uint shaderSwitch; ///< лshaderĴ + } stats; #endif - luaxport: +luaxport: - LUAX_DECL_SINGLETON(GfxDevice); + LUAX_DECL_SINGLETON(GfxDevice); - LUAX_DECL_ENUM(MatrixMode, 1); - LUAX_DECL_ENUM(GLParams, 1); + LUAX_DECL_ENUM(MatrixMode, 1); + LUAX_DECL_ENUM(GLParams, 1); - LUAX_DECL_METHOD(_SetMatrixMode); - LUAX_DECL_METHOD(_GetMatrixMode); - LUAX_DECL_METHOD(_PushMatrix); - LUAX_DECL_METHOD(_PopMatrix); - LUAX_DECL_METHOD(_LoadIdentity); - LUAX_DECL_METHOD(_Rotate); - LUAX_DECL_METHOD(_Translate); - LUAX_DECL_METHOD(_Scale); - LUAX_DECL_METHOD(_Ortho); - LUAX_DECL_METHOD(_GetMatrixDepth); - LUAX_DECL_METHOD(_GetMatrixIndex); - LUAX_DECL_METHOD(_UseShader); - LUAX_DECL_METHOD(_UnuseShader); + LUAX_DECL_METHOD(_SetMatrixMode); + LUAX_DECL_METHOD(_GetMatrixMode); + LUAX_DECL_METHOD(_PushMatrix); + LUAX_DECL_METHOD(_PopMatrix); + LUAX_DECL_METHOD(_LoadIdentity); + LUAX_DECL_METHOD(_Rotate); + LUAX_DECL_METHOD(_Translate); + LUAX_DECL_METHOD(_Scale); + LUAX_DECL_METHOD(_Ortho); + LUAX_DECL_METHOD(_GetMatrixDepth); + LUAX_DECL_METHOD(_GetMatrixIndex); + LUAX_DECL_METHOD(_UseShader); + LUAX_DECL_METHOD(_UnuseShader); - }; +}; - // ȫ GfxDevice - extern GfxDevice gfx; +// ȫ GfxDevice +extern GfxDevice gfx; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gpu_buffer.cpp b/source/modules/asura-core/graphics/gpu_buffer.cpp index 4d59009..bf5ac6a 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.cpp +++ b/source/modules/asura-core/graphics/gpu_buffer.cpp @@ -1,153 +1,151 @@ #include "gpu_buffer.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - GPUBuffer::GPUBuffer(BufferType type, BufferUsage usage, BufferDataType dataType, size_t size) - : m_Target(GL_ZERO) - , m_Buffer(GL_ZERO) - , m_Size(0) +GPUBuffer::GPUBuffer(BufferType type, BufferUsage usage, BufferDataType dataType, size_t size) + : m_Target(GL_ZERO) + , m_Buffer(GL_ZERO) + , m_Size(0) #if ASURA_DEBUG - , m_Data(nullptr) + , m_Data(nullptr) #endif - { - m_Target = ConvertBufferType(type); - m_Usage = ConvertBufferUsage(usage); - m_DataType = ConvertBufferDataType(dataType); - m_Size = size; - } +{ + m_Target = ConvertBufferType(type); + m_Usage = ConvertBufferUsage(usage); + m_DataType = ConvertBufferDataType(dataType); + m_Size = size; +} - GPUBuffer::~GPUBuffer() - { +GPUBuffer::~GPUBuffer() +{ #if ASURA_DEBUG - if (m_Data) - free(m_Data); + if (m_Data) + free(m_Data); #endif - glDeleteBuffers(1, &m_Buffer); - } + glDeleteBuffers(1, &m_Buffer); +} - GLenum GPUBuffer::ConvertBufferType(BufferType type) - { - switch (type) - { - case BUFFER_TYPE_VERTEX: - return GL_ARRAY_BUFFER; - case BUFFER_TYPE_INDEX: - return GL_ELEMENT_ARRAY_BUFFER; - } - } +GLenum GPUBuffer::ConvertBufferType(BufferType type) +{ + switch (type) + { + case BUFFER_TYPE_VERTEX: + return GL_ARRAY_BUFFER; + case BUFFER_TYPE_INDEX: + return GL_ELEMENT_ARRAY_BUFFER; + } +} - GLenum GPUBuffer::ConvertBufferUsage(BufferUsage usage) - { - switch (usage) - { - case BUFFER_USAGE_STREAM: - return GL_STREAM_DRAW; - case BUFFER_USAGE_DYNAMIC: - return GL_DYNAMIC_DRAW; - case BUFFER_USAGE_STATIC: - return GL_STATIC_DRAW; - } - } +GLenum GPUBuffer::ConvertBufferUsage(BufferUsage usage) +{ + switch (usage) + { + case BUFFER_USAGE_STREAM: + return GL_STREAM_DRAW; + case BUFFER_USAGE_DYNAMIC: + return GL_DYNAMIC_DRAW; + case BUFFER_USAGE_STATIC: + return GL_STATIC_DRAW; + } +} - GLenum GPUBuffer::ConvertBufferDataType(BufferDataType type) - { - switch (type) - { - case BUFFER_DATA_TYPE_INT: - return GL_INT; - case BUFFER_DATA_TYPE_FLOAT: - return GL_FLOAT; - case BUFFER_DATA_TYPE_UNSIGNED_BYTE: - return GL_UNSIGNED_BYTE; - } - } +GLenum GPUBuffer::ConvertBufferDataType(BufferDataType type) +{ + switch (type) + { + case BUFFER_DATA_TYPE_INT: + return GL_INT; + case BUFFER_DATA_TYPE_FLOAT: + return GL_FLOAT; + case BUFFER_DATA_TYPE_UNSIGNED_BYTE: + return GL_UNSIGNED_BYTE; + } +} - bool GPUBuffer::Fill(const void * data, size_t size, uint offset) +bool GPUBuffer::Fill(const void * data, size_t size, uint offset) +{ + if (data == nullptr) + return false; + if (m_Buffer == 0) + { + gfx.WipeError(); + glGenBuffers(1, &m_Buffer); + if (m_Buffer == 0) + throw Exception("OpenGL glGenBuffers failed."); + glBindBuffer(m_Target, m_Buffer); + glBufferData(m_Target, m_Size, NULL, m_Usage); + if (gfx.HasError()) { - if (data == nullptr) - return false; - if (m_Buffer == 0) - { - gfx.WipeError(); - glGenBuffers(1, &m_Buffer); - if (m_Buffer == 0) - throw Exception("OpenGL glGenBuffers failed."); - glBindBuffer(m_Target, m_Buffer); - glBufferData(m_Target, m_Size, NULL, m_Usage); - if (gfx.HasError()) - { - glBindBuffer(m_Target, 0); - throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gfx.GetError()); - } + glBindBuffer(m_Target, 0); + throw Exception("OpenGL glBufferData failed. Errorcode=%d.", gfx.GetError()); + } #if ASURA_DEBUG - m_Data = (byte*)malloc(size); - memset(m_Data, 0, size); + m_Data = (byte*)malloc(size); + memset(m_Data, 0, size); #endif - } - else - glBindBuffer(m_Target, m_Buffer); - glBufferSubData(m_Target, offset, size, data); - if (gfx.HasError()) - { - glBindBuffer(m_Target, 0); - throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", gfx.GetError()); - } - glBindBuffer(m_Target, 0); + } + else + glBindBuffer(m_Target, m_Buffer); + glBufferSubData(m_Target, offset, size, data); + if (gfx.HasError()) + { + glBindBuffer(m_Target, 0); + throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", gfx.GetError()); + } + glBindBuffer(m_Target, 0); #if ASURA_DEBUG - memcpy(m_Data + offset, data, size); + memcpy(m_Data + offset, data, size); #endif - return true; - } + return true; +} - void GPUBuffer::Bind() - { - glBindBuffer(m_Target, m_Buffer); - } +void GPUBuffer::Bind() +{ + glBindBuffer(m_Target, m_Buffer); +} - void GPUBuffer::UnBind() - { - glBindBuffer(m_Target, 0); - } - - uint GPUBuffer::GetBufferSize() - { - return m_Size; - } +void GPUBuffer::UnBind() +{ + glBindBuffer(m_Target, 0); +} - GLenum GPUBuffer::GetDataType() - { - return m_DataType; - } +uint GPUBuffer::GetBufferSize() +{ + return m_Size; +} - size_t GPUBuffer::GetDataTypeSize() - { - //https://blog.csdn.net/nklinux/article/details/16919017 - switch (m_DataType) - { - case GL_UNSIGNED_BYTE: - return sizeof(GLbyte); - case GL_FLOAT : - return sizeof(GLfloat); - case GL_INT: - return sizeof(GLint); - } - } +GLenum GPUBuffer::GetDataType() +{ + return m_DataType; +} - size_t GPUBuffer::GetDataTypeSize(GLenum datatype) - { - switch (datatype) - { - case GL_UNSIGNED_BYTE: - return sizeof(GLbyte); - case GL_FLOAT: - return sizeof(GLfloat); - case GL_INT: - return sizeof(GLint); - } - } +size_t GPUBuffer::GetDataTypeSize() +{ + //https://blog.csdn.net/nklinux/article/details/16919017 + switch (m_DataType) + { + case GL_UNSIGNED_BYTE: + return sizeof(GLbyte); + case GL_FLOAT : + return sizeof(GLfloat); + case GL_INT: + return sizeof(GLint); + } +} +size_t GPUBuffer::GetDataTypeSize(GLenum datatype) +{ + switch (datatype) + { + case GL_UNSIGNED_BYTE: + return sizeof(GLbyte); + case GL_FLOAT: + return sizeof(GLfloat); + case GL_INT: + return sizeof(GLint); } -}
\ No newline at end of file +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gpu_buffer.h b/source/modules/asura-core/graphics/gpu_buffer.h index 09c5476..3153904 100644 --- a/source/modules/asura-core/graphics/gpu_buffer.h +++ b/source/modules/asura-core/graphics/gpu_buffer.h @@ -7,91 +7,89 @@ #include "gfx_device.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +enum BufferType +{ + BUFFER_TYPE_VERTEX, ///< 㻺壬position\tangent\normal\color\texcoord(n) + BUFFER_TYPE_INDEX, ///< +}; + +enum BufferUsage +{ + BUFFER_USAGE_STREAM, ///< һΣʹô + BUFFER_USAGE_DYNAMIC, ///< һΣʹ + BUFFER_USAGE_STATIC, ///< ĺʹ +}; + +enum BufferDataType +{ + BUFFER_DATA_TYPE_INT, + BUFFER_DATA_TYPE_FLOAT, + BUFFER_DATA_TYPE_UNSIGNED_BYTE, +}; + +/// +/// VRAM壬ֶ㻺vboebo֣ÿζڴԴϴݡframeworkrenderers +/// +/// +ASURA_ABSTRACT class GPUBuffer { - namespace Graphics - { - - enum BufferType - { - BUFFER_TYPE_VERTEX, ///< 㻺壬position\tangent\normal\color\texcoord(n) - BUFFER_TYPE_INDEX, ///< - }; - - enum BufferUsage - { - BUFFER_USAGE_STREAM, ///< һΣʹô - BUFFER_USAGE_DYNAMIC, ///< һΣʹ - BUFFER_USAGE_STATIC, ///< ĺʹ - }; - - enum BufferDataType - { - BUFFER_DATA_TYPE_INT, - BUFFER_DATA_TYPE_FLOAT, - BUFFER_DATA_TYPE_UNSIGNED_BYTE, - }; - - /// - /// VRAM壬ֶ㻺vboebo֣ÿζڴԴϴݡframeworkrenderers - /// - /// - ASURA_ABSTRACT class GPUBuffer - { - public: - - GPUBuffer(BufferType type, BufferUsage usage, BufferDataType datatype, size_t size); - virtual ~GPUBuffer(); - - static size_t GetDataTypeSize(GLenum datatype); - - bool Fill(const void* data, size_t size, uint offset = 0) ASURA_THROW(Exception); - - void Bind(); - void UnBind(); - - uint GetBufferSize(); - uint GetBufferCount(); - GLenum GetDataType(); - size_t GetDataTypeSize(); - - private: - - GLenum ConvertBufferType(BufferType type); - GLenum ConvertBufferUsage(BufferUsage type); - GLenum ConvertBufferDataType(BufferDataType type); - - GLenum m_Target; - GLuint m_Buffer; - /// - /// openglԴ滺岢ûж͵ҪֻglVertexAttribPointerʱָ - /// drawcall ʱݸʼַʹbufferȡඥݣԲͬ - /// ԱһbufferСΪ˱ֽӿڵļ࣬ڳʼbufferʱָ - /// ͣڱ͵һ£Բͬͷͬbuffer - /// - GLenum m_DataType; - GLuint m_Usage; - uint m_Size; +public: + + GPUBuffer(BufferType type, BufferUsage usage, BufferDataType datatype, size_t size); + virtual ~GPUBuffer(); + + static size_t GetDataTypeSize(GLenum datatype); + + bool Fill(const void* data, size_t size, uint offset = 0) ASURA_THROW(Exception); + + void Bind(); + void UnBind(); + + uint GetBufferSize(); + uint GetBufferCount(); + GLenum GetDataType(); + size_t GetDataTypeSize(); + +private: + + GLenum ConvertBufferType(BufferType type); + GLenum ConvertBufferUsage(BufferUsage type); + GLenum ConvertBufferDataType(BufferDataType type); + + GLenum m_Target; + GLuint m_Buffer; + + /// openglԴ滺岢ûж͵ҪֻglVertexAttribPointerʱָdrawcall ʱݸ + /// ʼַʹbufferȡඥݣԲͬͿԱһbufferСΪ˱ + /// ӿڵļ࣬ڳʼbufferʱָͣڱ͵һ£Բͬ + /// ͷͬbuffer + + GLenum m_DataType; + GLuint m_Usage; + uint m_Size; #if ASURA_DEBUG - byte* m_Data; + byte* m_Data; #endif - luaxport: +luaxport: - LUAX_DECL_ABSTRACT_FACTORY(GPUBuffer); + LUAX_DECL_ABSTRACT_FACTORY(GPUBuffer); - LUAX_DECL_ENUM(BufferType, 1); - LUAX_DECL_ENUM(BufferUsage, 1); - LUAX_DECL_ENUM(BufferDataType, 2); + LUAX_DECL_ENUM(BufferType, 1); + LUAX_DECL_ENUM(BufferUsage, 1); + LUAX_DECL_ENUM(BufferDataType, 2); - LUAX_DECL_METHOD(_Fill); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_GetCount); + LUAX_DECL_METHOD(_Fill); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetCount); - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index a0dff8d..32fa870 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -9,97 +9,95 @@ using namespace AEIO; using namespace AEImage; -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Image::Image() + : m_Width(0) + , m_Height(0) +{ +} + +Image::~Image() +{ +} + +bool Image::Load(ImageData* imgData) { - namespace Graphics + if (!imgData) return false; + + if (m_TexID == 0) { + glGenTextures(1, &m_TexID); + if (m_TexID == 0) + throw Exception("OpenGL glGenTextures failed."); + } + + glBindTexture(GL_TEXTURE_2D, m_TexID); + imgData->Lock(); + int width = imgData->width; + int height = imgData->height; + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexImage2D( + GL_TEXTURE_2D + , 0 + , tf.internalformat + , width, height + , 0 + , tf.externalformat + , tf.type + , imgData->pixels + ); + + m_Width = imgData->width; + m_Height = imgData->height; + imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexImage2D cause error, error code=%d", err); + glBindTexture(GL_TEXTURE_2D, 0); + + return true; +} + +bool Image::Load(ImageData* imgData, const AEMath::Vector2i& pos) +{ + if (!imgData) return false; + + glBindTexture(GL_TEXTURE_2D, m_TexID); + imgData->Lock(); + int width = imgData->width; + int height = imgData->height; + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexSubImage2D( + GL_TEXTURE_2D + , 0 + , pos.x + , pos.y + , imgData->width + , imgData->height + , tf.externalformat + , tf.type + , imgData->pixels + ); + imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexSubImage2D cause error, error code=%d", err); + glBindTexture(GL_TEXTURE_2D, 0); + + return true; +} + +uint32 Image::GetWidth() +{ + return m_Width; +} + +uint32 Image::GetHeight() +{ + return m_Height; +} - Image::Image() - : m_Width(0) - , m_Height(0) - { - } - - Image::~Image() - { - } - - bool Image::Load(ImageData* imgData) - { - if (!imgData) return false; - - if (m_TexID == 0) - { - glGenTextures(1, &m_TexID); - if (m_TexID == 0) - throw Exception("OpenGL glGenTextures failed."); - } - - glBindTexture(GL_TEXTURE_2D, m_TexID); - imgData->Lock(); - int width = imgData->width; - int height = imgData->height; - TextureFormat tf = ConvertColorFormat(imgData->format); - glTexImage2D( - GL_TEXTURE_2D - , 0 - , tf.internalformat - , width, height - , 0 - , tf.externalformat - , tf.type - , imgData->pixels - ); - - m_Width = imgData->width; - m_Height = imgData->height; - imgData->Unlock(); - GLenum err = glGetError(); - if (err != GL_NO_ERROR) - throw Exception("OpenGL glTexImage2D cause error, error code=%d", err); - glBindTexture(GL_TEXTURE_2D, 0); - - return true; - } - - bool Image::Load(ImageData* imgData, const AEMath::Vector2i& pos) - { - if (!imgData) return false; - - glBindTexture(GL_TEXTURE_2D, m_TexID); - imgData->Lock(); - int width = imgData->width; - int height = imgData->height; - TextureFormat tf = ConvertColorFormat(imgData->format); - glTexSubImage2D( - GL_TEXTURE_2D - , 0 - , pos.x - , pos.y - , imgData->width - , imgData->height - , tf.externalformat - , tf.type - , imgData->pixels - ); - imgData->Unlock(); - GLenum err = glGetError(); - if (err != GL_NO_ERROR) - throw Exception("OpenGL glTexSubImage2D cause error, error code=%d", err); - glBindTexture(GL_TEXTURE_2D, 0); - - return true; - } - - uint32 Image::GetWidth() - { - return m_Width; - } - - uint32 Image::GetHeight() - { - return m_Height; - } - - } // Graphics -} // AsuraEngine
\ No newline at end of file +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index 229a849..72f1281 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -19,46 +19,44 @@ #include "gpu_buffer.h" #include "texture.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - class Image ASURA_FINAL : public AEScripting::Portable<Image, Texture> - { - public: +class Image ASURA_FINAL : public AEScripting::Portable<Image, Texture> +{ +public: - Image(); - ~Image(); + Image(); + ~Image(); - bool Load(AEImage::ImageData* decodeData); - bool Load(AEImage::ImageData* decodeData, const AEMath::Vector2i& pos); + bool Load(AEImage::ImageData* decodeData); + bool Load(AEImage::ImageData* decodeData, const AEMath::Vector2i& pos); - uint GetWidth(); - uint GetHeight(); + uint GetWidth(); + uint GetHeight(); - GPUBuffer* GenGPUBuffer(); + GPUBuffer* GenGPUBuffer(); - private: +private: - uint32 m_Width, m_Height; + uint32 m_Width, m_Height; - luaxport: +luaxport: - LUAX_DECL_FACTORY(Image, Texture); + LUAX_DECL_FACTORY(Image, Texture); - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Load); - LUAX_DECL_METHOD(_GetWidth); - LUAX_DECL_METHOD(_GetHeight); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_GetPixel); - LUAX_DECL_METHOD(_Render); + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetPixel); + LUAX_DECL_METHOD(_Render); - }; +}; - } // Graphics -} // AsuraEngine +namespace_end +namespace_end namespace AEGraphics = AsuraEngine::Graphics; diff --git a/source/modules/asura-core/graphics/index_buffer.cpp b/source/modules/asura-core/graphics/index_buffer.cpp index fd0295d..9d7416f 100644 --- a/source/modules/asura-core/graphics/index_buffer.cpp +++ b/source/modules/asura-core/graphics/index_buffer.cpp @@ -1,18 +1,17 @@ #include "index_buffer.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - IndexBuffer::IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size) - : GPUBuffer(BUFFER_TYPE_INDEX, usage, datatype, size) - { - } - IndexBuffer::~IndexBuffer() - { - } +IndexBuffer::IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size) + : GPUBuffer(BUFFER_TYPE_INDEX, usage, datatype, size) +{ +} - } +IndexBuffer::~IndexBuffer() +{ } + +namespace_end +namespace_end diff --git a/source/modules/asura-core/graphics/index_buffer.h b/source/modules/asura-core/graphics/index_buffer.h index 98e901a..538b43b 100644 --- a/source/modules/asura-core/graphics/index_buffer.h +++ b/source/modules/asura-core/graphics/index_buffer.h @@ -5,32 +5,30 @@ #include "gpu_buffer.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// +/// +class IndexBuffer ASURA_FINAL + : public AEScripting::Portable<IndexBuffer> + , public GPUBuffer { - namespace Graphics - { +public: - /// - /// - /// - class IndexBuffer ASURA_FINAL - : public AEScripting::Portable<IndexBuffer> - , public GPUBuffer - { - public: + IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); + ~IndexBuffer(); - IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); - ~IndexBuffer(); +luaxport: - luaxport: + LUAX_DECL_FACTORY(IndexBuffer); - LUAX_DECL_FACTORY(IndexBuffer); + LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_New); +}; - }; - - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/matrix_stack.cpp b/source/modules/asura-core/graphics/matrix_stack.cpp index 2211158..eaa686f 100644 --- a/source/modules/asura-core/graphics/matrix_stack.cpp +++ b/source/modules/asura-core/graphics/matrix_stack.cpp @@ -1,77 +1,75 @@ #include "matrix_stack.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - MatrixStack::MatrixStack() - : top(0) - { - // ջʼջô˱֤ջԶǿգȡֵ - m_Stack[top].SetIdentity(); - } +MatrixStack::MatrixStack() + : top(0) +{ + // ջʼջô˱֤ջԶǿգȡֵ + m_Stack[top].SetIdentity(); +} - MatrixStack::~MatrixStack() - { - } +MatrixStack::~MatrixStack() +{ +} - void MatrixStack::LoadIdentity() - { - m_Stack[top].SetIdentity(); - } +void MatrixStack::LoadIdentity() +{ + m_Stack[top].SetIdentity(); +} - bool MatrixStack::Push() - { - if (top == ASURA_MAX_MATRIX_STACK_DEPTH - 1) - return false; - ++top; - m_Stack[top] = m_Stack[top - 1]; - return true; - } +bool MatrixStack::Push() +{ + if (top == ASURA_MAX_MATRIX_STACK_DEPTH - 1) + return false; + ++top; + m_Stack[top] = m_Stack[top - 1]; + return true; +} - bool MatrixStack::Pop() - { - if (top == 0) - return false; - --top; - return true; - } +bool MatrixStack::Pop() +{ + if (top == 0) + return false; + --top; + return true; +} - AEMath::Matrix44& MatrixStack::GetTop() - { - return m_Stack[top]; - } +AEMath::Matrix44& MatrixStack::GetTop() +{ + return m_Stack[top]; +} - uint MatrixStack::GetTopIndex() - { - return top; - } +uint MatrixStack::GetTopIndex() +{ + return top; +} - uint MatrixStack::GetCapacity() - { - return ASURA_MAX_MATRIX_STACK_DEPTH; - } +uint MatrixStack::GetCapacity() +{ + return ASURA_MAX_MATRIX_STACK_DEPTH; +} - void MatrixStack::Ortho(float left, float right, float bottom, float top, float near, float far) - { - m_Stack[this->top].Ortho(left, right, bottom, top, near, far); - } +void MatrixStack::Ortho(float left, float right, float bottom, float top, float near, float far) +{ + m_Stack[this->top].Ortho(left, right, bottom, top, near, far); +} - void MatrixStack::Rotate(float angle) - { - m_Stack[top].Rotate(angle); - } +void MatrixStack::Rotate(float angle) +{ + m_Stack[top].Rotate(angle); +} - void MatrixStack::Translate(float x, float y) - { - m_Stack[top].Translate(x, y); - } +void MatrixStack::Translate(float x, float y) +{ + m_Stack[top].Translate(x, y); +} - void MatrixStack::Scale(float x, float y) - { - m_Stack[top].Scale(x, y); - } +void MatrixStack::Scale(float x, float y) +{ + m_Stack[top].Scale(x, y); +} - } -}
\ No newline at end of file +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/matrix_stack.h b/source/modules/asura-core/graphics/matrix_stack.h index 67401d0..ad32bb4 100644 --- a/source/modules/asura-core/graphics/matrix_stack.h +++ b/source/modules/asura-core/graphics/matrix_stack.h @@ -3,57 +3,56 @@ #include <asura-utils/type.h> #include <asura-utils/math/matrix44.h> +#include <asura-utils/classes.h> -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - /// - /// ջľȡ - /// +/// +/// ջľȡ +/// #define ASURA_MAX_MATRIX_STACK_DEPTH 32 // 2KB - /// - /// ջ״ָ̬֮ǰ״̬ջеһstack[i]ֵstack[0]*..*stack[i-1] - /// ֵһϵtransform - /// - /// TODO: template<uint _capacity> MatrixStack - /// - class MatrixStack - { - public: +/// +/// ջ״ָ̬֮ǰ״̬ջеһstack[i]ֵstack[0]*..*stack[i-1] +/// ֵһϵtransform +/// +/// TODO: template<uint _capacity> MatrixStack +/// +class MatrixStack +{ +public: - MatrixStack(); - ~MatrixStack(); + MatrixStack(); + ~MatrixStack(); - void LoadIdentity(); - bool Push(); - bool Pop(); + void LoadIdentity(); + bool Push(); + bool Pop(); - AEMath::Matrix44& GetTop(); - void GetTop(ASURA_OUT AEMath::Matrix44& mat44); + AEMath::Matrix44& GetTop(); + void GetTop(ASURA_OUT AEMath::Matrix44& mat44); - void LoadMatrix(const AEMath::Matrix44& mat44); - void MultMatrix(const AEMath::Matrix44& mat44); + void LoadMatrix(const AEMath::Matrix44& mat44); + void MultMatrix(const AEMath::Matrix44& mat44); - void Rotate(float angle); - void Translate(float x, float y); - void Scale(float x, float y); + void Rotate(float angle); + void Translate(float x, float y); + void Scale(float x, float y); - void Ortho(float l, float r, float b, float t, float n, float f); + void Ortho(float l, float r, float b, float t, float n, float f); - uint GetTopIndex(); - uint GetCapacity(); + uint GetTopIndex(); + uint GetCapacity(); - private: +private: - AEMath::Matrix44 m_Stack[ASURA_MAX_MATRIX_STACK_DEPTH]; - uint8 top; + AEMath::Matrix44 m_Stack[ASURA_MAX_MATRIX_STACK_DEPTH]; + uint8 top; - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h index 8c26564..d2d7d3b 100644 --- a/source/modules/asura-core/graphics/mesh2d.h +++ b/source/modules/asura-core/graphics/mesh2d.h @@ -16,39 +16,37 @@ #include "vertex_buffer.h" #include "index_buffer.h" -namespace AsuraEngine -{ - namespace Graphics - { +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - /// - /// 2D meshһЩ㶯 - /// https://en.wikipedia.org/wiki/Polygon_mesh - /// - class Mesh2D ASURA_FINAL - : public Scripting::Portable<Mesh2D> - { - public: +/// +/// 2D meshһЩ㶯 +/// https://en.wikipedia.org/wiki/Polygon_mesh +/// +class Mesh2D ASURA_FINAL + : public Scripting::Portable<Mesh2D> +{ +public: - Mesh2D(); - ~Mesh2D(); + Mesh2D(); + ~Mesh2D(); - bool Load(AEMesh::Mesh2DData* data); + bool Load(AEMesh::Mesh2DData* data); - private: +private: - VertexBuffer* m_VBO; ///< vertex buffer - IndexBuffer* m_IBO; ///< index buffer + VertexBuffer* m_VBO; ///< vertex buffer + IndexBuffer* m_IBO; ///< index buffer - luaxport: +luaxport: - LUAX_DECL_FACTORY(Mesh2D); + LUAX_DECL_FACTORY(Mesh2D); - LUAX_DECL_METHOD(_SetVertex); + LUAX_DECL_METHOD(_SetVertex); - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/render_state.h b/source/modules/asura-core/graphics/render_state.h index b5814d3..9f138c0 100644 --- a/source/modules/asura-core/graphics/render_state.h +++ b/source/modules/asura-core/graphics/render_state.h @@ -6,44 +6,42 @@ #include "blend_mode.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class Shader; + +/// +/// Ⱦǰķʽ +/// +struct RenderState ASURA_FINAL { - namespace Graphics - { - - class Shader; - - /// - /// Ⱦǰķʽ - /// - struct RenderState ASURA_FINAL - { - /// - /// Ĭϵrender state - /// - static RenderState Default; - - RenderState(); - ~RenderState(); - - /// - /// λášλúת - /// - Math::Transform transform; - - /// - /// ɫ - /// - Shader* shader; - - /// - /// Ϸʽ - /// - BlendMode blendMode; - - }; - - } -} + /// + /// Ĭϵrender state + /// + static RenderState Default; + + RenderState(); + ~RenderState(); + + /// + /// λášλúת + /// + Math::Transform transform; + + /// + /// ɫ + /// + Shader* shader; + + /// + /// Ϸʽ + /// + BlendMode blendMode; + +}; + +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/render_target.h b/source/modules/asura-core/graphics/render_target.h index 1992f6c..a52e7b0 100644 --- a/source/modules/asura-core/graphics/render_target.h +++ b/source/modules/asura-core/graphics/render_target.h @@ -8,47 +8,45 @@ #include "texture.h" #include "color.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// ɱΪȾĿ࣬ +/// Canvas(RenderTexture) +/// Window(RenderWindow) +/// +class RenderTarget : public AEScripting::Object { - namespace Graphics - { - - /// - /// ɱΪȾĿ࣬ - /// Canvas(RenderTexture) - /// Window(RenderWindow) - /// - class RenderTarget : public AEScripting::Object - { - public: - - RenderTarget() {}; - - virtual ~RenderTarget() {}; - - /// - /// ɫcolRT - /// - virtual void Clear(const Color& col = Color::Black) = 0; - - /// - /// ɫcolղRT - /// - virtual void Clear(const Math::Recti& quad, const Color& col = Color::Black) = 0; - - /// - /// textureRT - /// - virtual void Draw(const Drawable* texture, const RenderState& state) = 0; - - /// - /// һtextureRT - /// - virtual void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state) = 0; - - }; - - } -} +public: + + RenderTarget() {}; + + virtual ~RenderTarget() {}; + + /// + /// ɫcolRT + /// + virtual void Clear(const Color& col = Color::Black) = 0; + + /// + /// ɫcolղRT + /// + virtual void Clear(const Math::Recti& quad, const Color& col = Color::Black) = 0; + + /// + /// textureRT + /// + virtual void Draw(const Drawable* texture, const RenderState& state) = 0; + + /// + /// һtextureRT + /// + virtual void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state) = 0; + +}; + +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index 8606e79..eff62f0 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -5,280 +5,278 @@ using namespace std; -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +// texture unit +static uint8 texUnit = 0; + +Shader::Shader() +{ +} + +Shader::~Shader() { - namespace Graphics + if(m_VertShader) glDeleteShader(m_VertShader); + if(m_FragShader) glDeleteShader(m_FragShader); + if(m_Program) glDeleteProgram(m_Program); +} + +void Shader::SetActive(Shader* shader) +{ + gfx.SetActiveShader(shader); +} + +Shader* Shader::GetActive() +{ + return gfx.GetActiveShader(); +} + +bool Shader::Load(const string& vert, const string& frag) +{ + string warnning = ""; + + if (!m_Program) { + m_Program = glCreateProgram(); + if (!m_Program) + throw Exception("Cannot create OpenGL shader program."); + } - // texture unit - static uint8 texUnit = 0; + if (!CompileVertexShader(vert, warnning)) + { + throw Exception("Compile vertex shader failed:%s", warnning); + } - Shader::Shader() - { - } + if (!CompileFragementShader(frag, warnning)) + { + throw Exception("Compile fragment shader failed:%s", warnning); + } - Shader::~Shader() - { - if(m_VertShader) glDeleteShader(m_VertShader); - if(m_FragShader) glDeleteShader(m_FragShader); - if(m_Program) glDeleteProgram(m_Program); - } + glAttachShader(m_Program, m_VertShader); + glAttachShader(m_Program, m_FragShader); - void Shader::SetActive(Shader* shader) - { - gfx.SetActiveShader(shader); - } + glLinkProgram(m_Program); + GLint success; + glGetProgramiv(m_Program, GL_LINK_STATUS, &success); + if (success == GL_FALSE) + { + warnning = GetProgramWarnings(); + throw Exception("Link shader program failed:\n%s", warnning.c_str()); + } - Shader* Shader::GetActive() - { - return gfx.GetActiveShader(); - } + return true; +} - bool Shader::Load(const string& vert, const string& frag) +bool Shader::CompileVertexShader(const string& vert, string& outError) +{ + if (!m_VertShader) + { + m_VertShader = glCreateShader(GL_VERTEX_SHADER); + if (!m_VertShader) { - string warnning = ""; - - if (!m_Program) - { - m_Program = glCreateProgram(); - if (!m_Program) - throw Exception("Cannot create OpenGL shader program."); - } - - if (!CompileVertexShader(vert, warnning)) - { - throw Exception("Compile vertex shader failed:%s", warnning); - } - - if (!CompileFragementShader(frag, warnning)) - { - throw Exception("Compile fragment shader failed:%s", warnning); - } - - glAttachShader(m_Program, m_VertShader); - glAttachShader(m_Program, m_FragShader); - - glLinkProgram(m_Program); - GLint success; - glGetProgramiv(m_Program, GL_LINK_STATUS, &success); - if (success == GL_FALSE) - { - warnning = GetProgramWarnings(); - throw Exception("Link shader program failed:\n%s", warnning.c_str()); - } - - return true; + outError = "Cannot create OpenGL Vertex shader."; + return false; } + } - bool Shader::CompileVertexShader(const string& vert, string& outError) - { - if (!m_VertShader) - { - m_VertShader = glCreateShader(GL_VERTEX_SHADER); - if (!m_VertShader) - { - outError = "Cannot create OpenGL Vertex shader."; - return false; - } - } - - const GLchar* source = vert.c_str(); - GLint success; - - glShaderSource(m_VertShader, 1, &source, NULL); - glCompileShader(m_VertShader); - glGetShaderiv(m_VertShader, GL_COMPILE_STATUS, &success); - if (success == GL_FALSE) - { - outError = GetShaderWarnings(m_VertShader); - return false; - } - - return true; - } + const GLchar* source = vert.c_str(); + GLint success; - bool Shader::CompileFragementShader(const string& frag, string& outError) - { - if (!m_FragShader) - { - m_FragShader = glCreateShader(GL_FRAGMENT_SHADER); - if (!m_FragShader) - { - outError = "Cannot create OpenGL fragment shader."; - return false; - } - } - - const GLchar* source = frag.c_str(); - GLint success; - - source = frag.c_str(); - glShaderSource(m_FragShader, 1, &source, NULL); - glCompileShader(m_FragShader); - glGetShaderiv(m_FragShader, GL_COMPILE_STATUS, &success); - if (success == GL_FALSE) - { - outError = GetShaderWarnings(m_FragShader); - return false; - } - - return true; - } + glShaderSource(m_VertShader, 1, &source, NULL); + glCompileShader(m_VertShader); + glGetShaderiv(m_VertShader, GL_COMPILE_STATUS, &success); + if (success == GL_FALSE) + { + outError = GetShaderWarnings(m_VertShader); + return false; + } - void Shader::OnEnable() - { - texUnit = 0; - } + return true; +} - void Shader::OnDisable() +bool Shader::CompileFragementShader(const string& frag, string& outError) +{ + if (!m_FragShader) + { + m_FragShader = glCreateShader(GL_FRAGMENT_SHADER); + if (!m_FragShader) { - texUnit = 0; + outError = "Cannot create OpenGL fragment shader."; + return false; } + } - void Shader::OnUsed() - { - texUnit = 0; - } + const GLchar* source = frag.c_str(); + GLint success; - uint Shader::GetUniformLocation(const std::string& uniform) - { - GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); - return loc; - } + source = frag.c_str(); + glShaderSource(m_FragShader, 1, &source, NULL); + glCompileShader(m_FragShader); + glGetShaderiv(m_FragShader, GL_COMPILE_STATUS, &success); + if (success == GL_FALSE) + { + outError = GetShaderWarnings(m_FragShader); + return false; + } - bool Shader::HasUniform(const std::string& uniform) - { - GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); - return loc != -1; - } + return true; +} - GLuint Shader::GetGLProgram() - { - return m_Program; - } +void Shader::OnEnable() +{ + texUnit = 0; +} - void Shader::SetUniformFloat(uint loc, float value) - { - if(gfx.GetActiveShader() == this) - glUniform1f(loc, value); - } +void Shader::OnDisable() +{ + texUnit = 0; +} - bool Shader::SetUniformTexture(uint loc, const Texture& texture) - { - if (gfx.GetActiveShader() != this) - return false; - - gfx.WipeError(); - glActiveTexture(GL_TEXTURE0 + texUnit); - if (gfx.HasError()) - return false; - GLint tex = texture.GetGLTexture(); - glBindTexture(GL_TEXTURE_2D, tex); - if (gfx.HasError()) - return false; - glUniform1i(loc, texUnit); - if (gfx.HasError()) - return false; - ++texUnit; - } +void Shader::OnUsed() +{ + texUnit = 0; +} - void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) - { - if (gfx.GetActiveShader() == this) - glUniform2f(loc, vec2.x, vec2.y); - } +uint Shader::GetUniformLocation(const std::string& uniform) +{ + GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); + return loc; +} - void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) - { - if (gfx.GetActiveShader() == this) - glUniform3f(loc, vec3.x, vec3.y, vec3.z); - } +bool Shader::HasUniform(const std::string& uniform) +{ + GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); + return loc != -1; +} - void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) - { - if (gfx.GetActiveShader() == this) - glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); - } +GLuint Shader::GetGLProgram() +{ + return m_Program; +} - void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) - { - if (gfx.GetActiveShader() == this) - glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); - } +void Shader::SetUniformFloat(uint loc, float value) +{ + if(gfx.GetActiveShader() == this) + glUniform1f(loc, value); +} - void Shader::SetUniformColor(uint loc, const Color& color) - { - if (gfx.GetActiveShader() == this) - glUniform4f(loc, color.r, color.g, color.b, color.a); - } +bool Shader::SetUniformTexture(uint loc, const Texture& texture) +{ + if (gfx.GetActiveShader() != this) + return false; + + gfx.WipeError(); + glActiveTexture(GL_TEXTURE0 + texUnit); + if (gfx.HasError()) + return false; + GLint tex = texture.GetGLTexture(); + glBindTexture(GL_TEXTURE_2D, tex); + if (gfx.HasError()) + return false; + glUniform1i(loc, texUnit); + if (gfx.HasError()) + return false; + ++texUnit; +} + +void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) +{ + if (gfx.GetActiveShader() == this) + glUniform2f(loc, vec2.x, vec2.y); +} - uint Shader::GetGLTextureUnitCount() - { - GLint maxTextureUnits; - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); - return (uint)maxTextureUnits; - } +void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) +{ + if (gfx.GetActiveShader() == this) + glUniform3f(loc, vec3.x, vec3.y, vec3.z); +} - std::string Shader::GetProgramWarnings() - { - GLint strsize, nullpos; - glGetProgramiv(m_Program, GL_INFO_LOG_LENGTH, &strsize); +void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) +{ + if (gfx.GetActiveShader() == this) + glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); +} - if (strsize == 0) - return ""; +void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) +{ + if (gfx.GetActiveShader() == this) + glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); +} - char *tempstr = new char[strsize]; +void Shader::SetUniformColor(uint loc, const Color& color) +{ + if (gfx.GetActiveShader() == this) + glUniform4f(loc, color.r, color.g, color.b, color.a); +} - memset(tempstr, '\0', strsize); - glGetProgramInfoLog(m_Program, strsize, &nullpos, tempstr); - tempstr[nullpos] = '\0'; +uint Shader::GetGLTextureUnitCount() +{ + GLint maxTextureUnits; + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); + return (uint)maxTextureUnits; +} - std::string warnings(tempstr); - delete[] tempstr; +std::string Shader::GetProgramWarnings() +{ + GLint strsize, nullpos; + glGetProgramiv(m_Program, GL_INFO_LOG_LENGTH, &strsize); - return warnings; - } + if (strsize == 0) + return ""; - std::string Shader::GetShaderWarnings(GLuint shader) - { - GLint strsize, nullpos; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &strsize); + char *tempstr = new char[strsize]; - if (strsize == 0) - return ""; + memset(tempstr, '\0', strsize); + glGetProgramInfoLog(m_Program, strsize, &nullpos, tempstr); + tempstr[nullpos] = '\0'; - char *tempstr = new char[strsize]; + std::string warnings(tempstr); + delete[] tempstr; - memset(tempstr, '\0', strsize); - glGetShaderInfoLog(shader, strsize, &nullpos, tempstr); - tempstr[nullpos] = '\0'; + return warnings; +} - std::string warnings(tempstr); - delete[] tempstr; +std::string Shader::GetShaderWarnings(GLuint shader) +{ + GLint strsize, nullpos; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &strsize); - return warnings; - } + if (strsize == 0) + return ""; - void Shader::SetAttribute(int loc, VertexBuffer* vbo, uint offseti, uint stridei, bool normalized) - { - GLsizei offset = offseti * vbo->GetDataTypeSize(); - GLsizei stride = stridei * vbo->GetDataTypeSize(); - glEnableVertexAttribArray(loc); - vbo->Bind(); - glVertexAttribPointer(loc, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); - vbo->UnBind(); - } + char *tempstr = new char[strsize]; - int Shader::GetAttributeLocation(const std::string& attribute) - { - int loc = glGetAttribLocation(m_Program, attribute.c_str()); - return loc; - } + memset(tempstr, '\0', strsize); + glGetShaderInfoLog(shader, strsize, &nullpos, tempstr); + tempstr[nullpos] = '\0'; - void Shader::DisableAttribute(int loc) - { - glDisableVertexAttribArray(loc); - } + std::string warnings(tempstr); + delete[] tempstr; - } -}
\ No newline at end of file + return warnings; +} + +void Shader::SetAttribute(int loc, VertexBuffer* vbo, uint offseti, uint stridei, bool normalized) +{ + GLsizei offset = offseti * vbo->GetDataTypeSize(); + GLsizei stride = stridei * vbo->GetDataTypeSize(); + glEnableVertexAttribArray(loc); + vbo->Bind(); + glVertexAttribPointer(loc, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); + vbo->UnBind(); +} + +int Shader::GetAttributeLocation(const std::string& attribute) +{ + int loc = glGetAttribLocation(m_Program, attribute.c_str()); + return loc; +} + +void Shader::DisableAttribute(int loc) +{ + glDisableVertexAttribArray(loc); +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index dc8dbe0..c535570 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -20,100 +20,98 @@ #include "vertex_buffer.h" #include "index_buffer.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ uniformsuseɫ +/// ķ༭ÿshaderͨshaderҵuniforms¶frameworkmaterial +/// á +/// +class Shader ASURA_FINAL + : public Scripting::Portable<Shader> + , public AEIO::Renewable { - namespace Graphics - { - - /// - /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ uniformsuseɫ - /// ķ༭ÿshaderͨshaderҵuniforms¶frameworkmaterial - /// á - /// - class Shader ASURA_FINAL - : public Scripting::Portable<Shader> - , public AEIO::Renewable - { - public: - - Shader(); - - ~Shader(); - - static void SetActive(Shader* shader); - static Shader* GetActive(); - - bool Load(const std::string& vert, const std::string& frag) ASURA_THROW(Exception); - - // ʹSetActiveлshaderʱ - void OnEnable(); - void OnDisable(); - // Draw call֮ - void OnUsed(); +public: + + Shader(); + + ~Shader(); + + static void SetActive(Shader* shader); + static Shader* GetActive(); + + bool Load(const std::string& vert, const std::string& frag) ASURA_THROW(Exception); + + // ʹSetActiveлshaderʱ + void OnEnable(); + void OnDisable(); + // Draw call֮ + void OnUsed(); - void SetAttribute(int loc, VertexBuffer* vbo, uint offseti = 0, uint stridei = 0, bool normalized = false); - int GetAttributeLocation(const std::string& attribute); - void DisableAttribute(int loc); + void SetAttribute(int loc, VertexBuffer* vbo, uint offseti = 0, uint stridei = 0, bool normalized = false); + int GetAttributeLocation(const std::string& attribute); + void DisableAttribute(int loc); - bool HasUniform(const std::string& uniform); - uint GetUniformLocation(const std::string& uniform); - void SetUniformFloat(uint loc, float value); - void SetUniformVector2(uint loc, const Math::Vector2f& vec2); - void SetUniformVector3(uint loc, const Math::Vector3f& vec3); - void SetUniformVector4(uint loc, const Math::Vector4f& vec4); - void SetUniformColor(uint loc, const Color& color); - void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); - bool SetUniformTexture(uint loc, const Texture& texture); + bool HasUniform(const std::string& uniform); + uint GetUniformLocation(const std::string& uniform); + void SetUniformFloat(uint loc, float value); + void SetUniformVector2(uint loc, const Math::Vector2f& vec2); + void SetUniformVector3(uint loc, const Math::Vector3f& vec3); + void SetUniformVector4(uint loc, const Math::Vector4f& vec4); + void SetUniformColor(uint loc, const Color& color); + void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); + bool SetUniformTexture(uint loc, const Texture& texture); - float GetUniformFloat(uint loc); - AEMath::Vector2f GetUniformVector2(uint loc); - AEMath::Vector3f GetUniformVector3(uint loc); - AEMath::Vector4f GetUniformVector4s(uint loc); - AEMath::Matrix44 GetUniformMatrix44(uint loc); + float GetUniformFloat(uint loc); + AEMath::Vector2f GetUniformVector2(uint loc); + AEMath::Vector3f GetUniformVector3(uint loc); + AEMath::Vector4f GetUniformVector4s(uint loc); + AEMath::Matrix44 GetUniformMatrix44(uint loc); - GLuint GetGLProgram(); + GLuint GetGLProgram(); - static uint GetGLTextureUnitCount(); + static uint GetGLTextureUnitCount(); - private: +private: - bool CompileVertexShader(const std::string& vert, std::string& outError); - bool CompileFragementShader(const std::string& frag, std::string& outError); + bool CompileVertexShader(const std::string& vert, std::string& outError); + bool CompileFragementShader(const std::string& frag, std::string& outError); - std::string GetProgramWarnings(); - std::string GetShaderWarnings(GLuint shader); + std::string GetProgramWarnings(); + std::string GetShaderWarnings(GLuint shader); - GLuint m_Program; - GLuint m_VertShader; - GLuint m_FragShader; + GLuint m_Program; + GLuint m_VertShader; + GLuint m_FragShader; - luaxport: +luaxport: - LUAX_DECL_FACTORY(Shader); + LUAX_DECL_FACTORY(Shader); - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Load); - LUAX_DECL_METHOD(_Update); - LUAX_DECL_METHOD(_HasUniform); - LUAX_DECL_METHOD(_GetUniformLocation); - LUAX_DECL_METHOD(_SetUniformFloat); - LUAX_DECL_METHOD(_SetUniformTexture); - LUAX_DECL_METHOD(_SetUniformVector2); - LUAX_DECL_METHOD(_SetUniformVector3); - LUAX_DECL_METHOD(_SetUniformVector4); - LUAX_DECL_METHOD(_SetUniformColor); + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_Update); + LUAX_DECL_METHOD(_HasUniform); + LUAX_DECL_METHOD(_GetUniformLocation); + LUAX_DECL_METHOD(_SetUniformFloat); + LUAX_DECL_METHOD(_SetUniformTexture); + LUAX_DECL_METHOD(_SetUniformVector2); + LUAX_DECL_METHOD(_SetUniformVector3); + LUAX_DECL_METHOD(_SetUniformVector4); + LUAX_DECL_METHOD(_SetUniformColor); - LUAX_DECL_METHOD(_GetAttributeLocation); - LUAX_DECL_METHOD(_SetAttribute); - LUAX_DECL_METHOD(_DisableAttribute); + LUAX_DECL_METHOD(_GetAttributeLocation); + LUAX_DECL_METHOD(_SetAttribute); + LUAX_DECL_METHOD(_DisableAttribute); - LUAX_DECL_METHOD(_SetBuiltInUniforms); + LUAX_DECL_METHOD(_SetBuiltInUniforms); - }; +}; - typedef Shader GpuProgram; +typedef Shader GpuProgram; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/sprite_batch.h b/source/modules/asura-core/graphics/sprite_batch.h index b517334..7f22da0 100644 --- a/source/modules/asura-core/graphics/sprite_batch.h +++ b/source/modules/asura-core/graphics/sprite_batch.h @@ -5,32 +5,30 @@ #include "gpu_buffer.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// Sprite batchȾͼƬĵطϵͳ +/// +class SpriteBatch ASURA_FINAL + : public Scripting::Portable<SpriteBatch> { - namespace Graphics - { +public: - /// - /// Sprite batchȾͼƬĵطϵͳ - /// - class SpriteBatch ASURA_FINAL - : public Scripting::Portable<SpriteBatch> - { - public: + SpriteBatch(); - SpriteBatch(); + ~SpriteBatch(); - ~SpriteBatch(); +private: - private: +luaxport: - luaxport: + LUAX_DECL_FACTORY(SpriteBatch); - LUAX_DECL_FACTORY(SpriteBatch); +}; - }; - - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp index ef85ceb..42e3851 100644 --- a/source/modules/asura-core/graphics/texture.cpp +++ b/source/modules/asura-core/graphics/texture.cpp @@ -2,48 +2,46 @@ #include "Texture.h" -namespace AsuraEngine -{ - namespace Graphics - { - - Texture::Texture() - : m_TexID(0) - { - } +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - Texture::~Texture() - { - // ͷԴ - if(m_TexID != 0) - glDeleteTextures(1, &m_TexID); - } +Texture::Texture() + : m_TexID(0) +{ +} - GLuint Texture::GetGLTexture() const - { - return m_TexID; - } +Texture::~Texture() +{ + // ͷԴ + if(m_TexID != 0) + glDeleteTextures(1, &m_TexID); +} - TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat) - { - TextureFormat t; - switch (colorformat) - { - case COLOR_FORMAT_RGBA8: - t.internalformat = GL_RGBA8; // 4*sizeof(byte) ~= 4 bytes - t.externalformat = GL_RGBA; - t.type = GL_UNSIGNED_BYTE; - break; - case COLOR_FORMAT_RGBA32F: - t.internalformat = GL_RGBA32F; // 4*sizeof(float) = 16 bytes - t.externalformat = GL_RGBA; - t.type = GL_FLOAT; - break; - default: - ASSERT(false); - } - return t; - } +GLuint Texture::GetGLTexture() const +{ + return m_TexID; +} +TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat) +{ + TextureFormat t; + switch (colorformat) + { + case COLOR_FORMAT_RGBA8: + t.internalformat = GL_RGBA8; // 4*sizeof(byte) ~= 4 bytes + t.externalformat = GL_RGBA; + t.type = GL_UNSIGNED_BYTE; + break; + case COLOR_FORMAT_RGBA32F: + t.internalformat = GL_RGBA32F; // 4*sizeof(float) = 16 bytes + t.externalformat = GL_RGBA; + t.type = GL_FLOAT; + break; + default: + ASSERT(false); } -}
\ No newline at end of file + return t; +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 5d754eb..458e35a 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -9,95 +9,93 @@ #include "render_state.h" #include "gfx_device.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class RenderTarget; + +/// UVʽ +enum WrapMode +{ + WRAP_MODE_REPEAT, + WRAP_MODE_MIRROR, + WRAP_MODE_CLAMPTOEDGE, + WRAP_MODE_CLAMPTOBORDER, +}; + +/// ˲ģʽ +enum FilterMode { - namespace Graphics - { - - class RenderTarget; - - /// UVʽ - enum WrapMode - { - WRAP_MODE_REPEAT, - WRAP_MODE_MIRROR, - WRAP_MODE_CLAMPTOEDGE, - WRAP_MODE_CLAMPTOBORDER, - }; - - /// ˲ģʽ - enum FilterMode - { - FILTER_MODE_NEAREST, - FILTER_MODE_LINEAR, - }; - - /// ͼݵɫʽ - enum ColorFormat - { - COLOR_FORMAT_UNKNOWN, - COLOR_FORMAT_RGBA8, ///< RGBA8bits int - COLOR_FORMAT_RGBA32F, ///< RGBA32bits float - }; - - /// ʽGPUڲCPUⲿʽ - struct TextureFormat - { - GLenum internalformat; ///< GPUڲʽ - GLenum externalformat; ///< CPUⲿʽ - GLenum type; ///< ⲿʽÿchannelֵ - }; - - /// - /// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷϲԵѿ - /// ϵΪEditorҲϽΪԭ㣬Ϊ˷㡣 - /// - ASURA_ABSTRACT class Texture : public AEScripting::Object - { - public: - - LUAX_DECL_ABSTRACT_FACTORY(Texture); - - Texture(); - virtual ~Texture(); - - GLuint GetGLTexture() const; - - void SetFilterMode(FilterMode min, FilterMode mag); - void SetWrapMode(WrapMode wrapMode); - - void GetFilterMode(); - void GetWrapMode(); - - /// UVfilterΪ - bool IsGenMipmap(); - - protected: - - /// תcolor formatΪtexture format - TextureFormat ConvertColorFormat(const ColorFormat& colorformat); - - GLuint m_TexID; - FilterMode m_MinFilter; - FilterMode m_MagFilter; - WrapMode m_WrapMode; - bool m_IsGenMipmap; - - LUAX_DECL_ENUM(ColorFormat, 1); - LUAX_DECL_ENUM(FilterMode, 1); - LUAX_DECL_ENUM(WrapMode, 1); - - LUAX_DECL_METHOD(_SetFilterMode); - LUAX_DECL_METHOD(_SetWrapMode); - LUAX_DECL_METHOD(_GetFilterMode); - LUAX_DECL_METHOD(_GetWrapMode); - LUAX_DECL_METHOD(_IsGenMipmap); - - }; - - typedef Texture Drawable; - - } -} + FILTER_MODE_NEAREST, + FILTER_MODE_LINEAR, +}; + +/// ͼݵɫʽ +enum ColorFormat +{ + COLOR_FORMAT_UNKNOWN, + COLOR_FORMAT_RGBA8, ///< RGBA8bits int + COLOR_FORMAT_RGBA32F, ///< RGBA32bits float +}; + +/// ʽGPUڲCPUⲿʽ +struct TextureFormat +{ + GLenum internalformat; ///< GPUڲʽ + GLenum externalformat; ///< CPUⲿʽ + GLenum type; ///< ⲿʽÿchannelֵ +}; + +/// +/// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷϲԵѿ +/// ϵΪEditorҲϽΪԭ㣬Ϊ˷㡣 +/// +ASURA_ABSTRACT class Texture : public AEScripting::Object +{ +public: + + LUAX_DECL_ABSTRACT_FACTORY(Texture); + + Texture(); + virtual ~Texture(); + + GLuint GetGLTexture() const; + + void SetFilterMode(FilterMode min, FilterMode mag); + void SetWrapMode(WrapMode wrapMode); + + void GetFilterMode(); + void GetWrapMode(); + + /// UVfilterΪ + bool IsGenMipmap(); + +protected: + + /// תcolor formatΪtexture format + TextureFormat ConvertColorFormat(const ColorFormat& colorformat); + + GLuint m_TexID; + FilterMode m_MinFilter; + FilterMode m_MagFilter; + WrapMode m_WrapMode; + bool m_IsGenMipmap; + + LUAX_DECL_ENUM(ColorFormat, 1); + LUAX_DECL_ENUM(FilterMode, 1); + LUAX_DECL_ENUM(WrapMode, 1); + + LUAX_DECL_METHOD(_SetFilterMode); + LUAX_DECL_METHOD(_SetWrapMode); + LUAX_DECL_METHOD(_GetFilterMode); + LUAX_DECL_METHOD(_GetWrapMode); + LUAX_DECL_METHOD(_IsGenMipmap); + +}; + +typedef Texture Drawable; + +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/vertex_buffer.cpp b/source/modules/asura-core/graphics/vertex_buffer.cpp index 437bd48..7fcd3d4 100644 --- a/source/modules/asura-core/graphics/vertex_buffer.cpp +++ b/source/modules/asura-core/graphics/vertex_buffer.cpp @@ -1,18 +1,16 @@ #include "vertex_buffer.h" -namespace AsuraEngine -{ - namespace Graphics - { - - VertexBuffer::VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size) - : GPUBuffer(BUFFER_TYPE_VERTEX, usage, datatype, size) - { - } +namespace_begin(AsuraEngine) +namespace_begin(Graphics) - VertexBuffer::~VertexBuffer() - { - } +VertexBuffer::VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size) + : GPUBuffer(BUFFER_TYPE_VERTEX, usage, datatype, size) +{ +} - } +VertexBuffer::~VertexBuffer() +{ } + +namespace_end +namespace_end diff --git a/source/modules/asura-core/graphics/vertex_buffer.h b/source/modules/asura-core/graphics/vertex_buffer.h index c16c6d2..f0bfb9e 100644 --- a/source/modules/asura-core/graphics/vertex_buffer.h +++ b/source/modules/asura-core/graphics/vertex_buffer.h @@ -5,32 +5,30 @@ #include "gpu_buffer.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// frameworkṩ˴Դ滺Ĺܣֱû壬ֱܶͨöݡ +/// +class VertexBuffer ASURA_FINAL + : public AEScripting::Portable<VertexBuffer> + , public GPUBuffer { - namespace Graphics - { +public: - /// - /// frameworkṩ˴Դ滺Ĺܣֱû壬ֱܶͨöݡ - /// - class VertexBuffer ASURA_FINAL - : public AEScripting::Portable<VertexBuffer> - , public GPUBuffer - { - public: + VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); + ~VertexBuffer(); - VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); - ~VertexBuffer(); +luaxport: - luaxport: + LUAX_DECL_FACTORY(VertexBuffer); - LUAX_DECL_FACTORY(VertexBuffer); + LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_New); +}; - }; - - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/image/binding/_image_data.cpp b/source/modules/asura-core/image/binding/_image_data.cpp index 1030e93..93e63ce 100644 --- a/source/modules/asura-core/image/binding/_image_data.cpp +++ b/source/modules/asura-core/image/binding/_image_data.cpp @@ -7,12 +7,9 @@ using namespace std; using namespace AEThreading; using namespace AEIO; -namespace AsuraEngine -{ - namespace Image - { - - LUAX_REGISTRY(ImageData) +namespace_begin(AsuraEngine) +namespace_begin(Image) +LUAX_REGISTRY(ImageData) { LUAX_REGISTER_METHODS(state, { "New", _New }, diff --git a/source/modules/asura-core/image/binding/_image_decode_task.cpp b/source/modules/asura-core/image/binding/_image_decode_task.cpp index a0caddf..0181628 100644 --- a/source/modules/asura-core/image/binding/_image_decode_task.cpp +++ b/source/modules/asura-core/image/binding/_image_decode_task.cpp @@ -2,12 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Image - { - - LUAX_REGISTRY(ImageDecodeTask) +namespace_begin(AsuraEngine) +namespace_begin(Image) +LUAX_REGISTRY(ImageDecodeTask) { } diff --git a/source/modules/asura-core/image/image_data.cpp b/source/modules/asura-core/image/image_data.cpp index 883343c..1de70cd 100644 --- a/source/modules/asura-core/image/image_data.cpp +++ b/source/modules/asura-core/image/image_data.cpp @@ -7,58 +7,56 @@ using namespace std; using namespace AEGraphics; -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Image) + +// imagedecoderΪԡ +list<ImageDecoder*> ImageData::ImageDecoders = { + new PNGDecoder(), // png + new STBDecoder() // jpeg, tga, bmp +}; + +ImageData::ImageData() + : pixels(nullptr) + , size(0) + , width(0) + , height(0) + , format(COLOR_FORMAT_UNKNOWN) { - namespace Image - { - - // imagedecoderΪԡ - list<ImageDecoder*> ImageData::ImageDecoders = { - new PNGDecoder(), // png - new STBDecoder() // jpeg, tga, bmp - }; - - ImageData::ImageData() - : pixels(nullptr) - , size(0) - , width(0) - , height(0) - , format(COLOR_FORMAT_UNKNOWN) - { - } +} - ImageData::~ImageData() - { - if (pixels) - delete[] pixels; - } +ImageData::~ImageData() +{ + if (pixels) + delete[] pixels; +} - void ImageData::Decode(IO::DataBuffer& buffer) +void ImageData::Decode(IO::DataBuffer& buffer) +{ + for (ImageDecoder* decoder : ImageDecoders) + { + if (decoder->CanDecode(buffer)) { - for (ImageDecoder* decoder : ImageDecoders) - { - if (decoder->CanDecode(buffer)) - { - decoder->Decode(buffer, *this); - return; - } - } + decoder->Decode(buffer, *this); + return; } + } +} - Color ImageData::GetPixel(uint x, uint y) - { - return Color(); - } +Color ImageData::GetPixel(uint x, uint y) +{ + return Color(); +} - void ImageData::Lock() - { - m_Mutex.Lock(); - } +void ImageData::Lock() +{ + m_Mutex.Lock(); +} - void ImageData::Unlock() - { - m_Mutex.Unlock(); - } +void ImageData::Unlock() +{ + m_Mutex.Unlock(); +} - } -}
\ No newline at end of file +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/image/image_data.h b/source/modules/asura-core/image/image_data.h index 8b4f04a..93e3448 100644 --- a/source/modules/asura-core/image/image_data.h +++ b/source/modules/asura-core/image/image_data.h @@ -12,71 +12,69 @@ #include "../graphics/texture.h" #include "../graphics/color.h" -namespace AsuraEngine -{ - namespace Image - { +namespace_begin(AsuraEngine) +namespace_begin(Image) - class ImageDecoder; +class ImageDecoder; - class ImageData ASURA_FINAL - : public Scripting::Portable<ImageData> - , public AEIO::DecodedData - { - public: +class ImageData ASURA_FINAL + : public Scripting::Portable<ImageData> + , public AEIO::DecodedData +{ +public: - /// - /// ͼƬļϢʧܣ׳쳣 - /// - ImageData(); - ~ImageData(); + /// + /// ͼƬļϢʧܣ׳쳣 + /// + ImageData(); + ~ImageData(); - void Decode(AEIO::DataBuffer& buffer) override; + void Decode(AEIO::DataBuffer& buffer) override; - void Lock(); - void Unlock(); + void Lock(); + void Unlock(); - AEGraphics::Color GetPixel(uint x, uint y); + AEGraphics::Color GetPixel(uint x, uint y); - //----------------------------------------------------------------------------// + //----------------------------------------------------------------------------// - uint width, height; // سߴ - AEGraphics::ColorFormat format; // ʽ - byte* pixels; // - std::size_t size; // ݳ + uint width, height; // سߴ + AEGraphics::ColorFormat format; // ʽ + byte* pixels; // + std::size_t size; // ݳ - //----------------------------------------------------------------------------// + //----------------------------------------------------------------------------// - private: +private: - /// - /// ڵһimage dataʱṩdecoderڼdecodersмѡԡ - /// - static std::list<ImageDecoder*> ImageDecoders; + /// + /// ڵһimage dataʱṩdecoderڼdecodersмѡԡ + /// + static std::list<ImageDecoder*> ImageDecoders; - /// - /// дݵ - /// - AEThreading::Mutex m_Mutex; + /// + /// дݵ + /// + AEThreading::Mutex m_Mutex; - luaxport: +luaxport: - LUAX_DECL_FACTORY(ImageData); + LUAX_DECL_FACTORY(ImageData); - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_GetPixel); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_GetWidth); - LUAX_DECL_METHOD(_GetHeight); - LUAX_DECL_METHOD(_GetPixelFormat); - LUAX_DECL_METHOD(_Decode); - LUAX_DECL_METHOD(_DecodeAsync); - LUAX_DECL_METHOD(_IsAvailable); + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_GetPixel); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetPixelFormat); + LUAX_DECL_METHOD(_Decode); + LUAX_DECL_METHOD(_DecodeAsync); + LUAX_DECL_METHOD(_IsAvailable); - }; +}; - } -} +namespace_end +namespace_end namespace AEImage = AsuraEngine::Image; diff --git a/source/modules/asura-core/image/image_decode_task.cpp b/source/modules/asura-core/image/image_decode_task.cpp index 954749a..3cadb43 100644 --- a/source/modules/asura-core/image/image_decode_task.cpp +++ b/source/modules/asura-core/image/image_decode_task.cpp @@ -1,19 +1,17 @@ #include "image_decode_task.h" -namespace AsuraEngine -{ - namespace Image - { +namespace_begin(AsuraEngine) +namespace_begin(Image) - bool ImageDecodeTask::Execute() - { - return false; - } +bool ImageDecodeTask::Execute() +{ + return false; +} - void ImageDecodeTask::Invoke(lua_State* invokeThreaad) - { +void ImageDecodeTask::Invoke(lua_State* invokeThreaad) +{ - } +} - } -}
\ No newline at end of file +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/image/image_decode_task.h b/source/modules/asura-core/image/image_decode_task.h index 5108c23..3726514 100644 --- a/source/modules/asura-core/image/image_decode_task.h +++ b/source/modules/asura-core/image/image_decode_task.h @@ -3,34 +3,33 @@ #include <asura-utils/threading/task.h> #include <asura-utils/scripting/portable.hpp> +#include <asura-utils/classes.h> -namespace AsuraEngine -{ - namespace Image - { +namespace_begin(AsuraEngine) +namespace_begin(Image) - class ImageDecodeTask - : public AEScripting::Portable<ImageDecodeTask, AEThreading::Task> - { - public: +class ImageDecodeTask + : public AEScripting::Portable<ImageDecodeTask, AEThreading::Task> +{ +public: - /// - /// ִɺtrueûص - /// - bool Execute() override; + /// + /// ִɺtrueûص + /// + bool Execute() override; - /// - /// ûصinvoke threadص - /// - void Invoke(lua_State* invokeThreaad) override; + /// + /// ûصinvoke threadص + /// + void Invoke(lua_State* invokeThreaad) override; - luaxport: +luaxport: - LUAX_DECL_FACTORY(ImageDecodeTask, AEThreading::Task); + LUAX_DECL_FACTORY(ImageDecodeTask, AEThreading::Task); - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/image/image_decoder.h b/source/modules/asura-core/image/image_decoder.h index 15efff7..30e65d3 100644 --- a/source/modules/asura-core/image/image_decoder.h +++ b/source/modules/asura-core/image/image_decoder.h @@ -5,31 +5,29 @@ #include "image_data.h" -namespace AsuraEngine -{ - namespace Image - { +namespace_begin(AsuraEngine) +namespace_begin(Image) - ASURA_ABSTRACT class ImageDecoder - { - public: +ASURA_ABSTRACT class ImageDecoder +{ +public: - ImageDecoder() {}; - virtual ~ImageDecoder() {}; + ImageDecoder() {}; + virtual ~ImageDecoder() {}; - /// - /// жڴǷñdecoderѹ - /// - virtual bool CanDecode(AEIO::DataBuffer& input) = 0; + /// + /// жڴǷñdecoderѹ + /// + virtual bool CanDecode(AEIO::DataBuffer& input) = 0; - /// - /// һڴ棬һѹImage dataѹʧܷnullptr - /// - virtual void Decode(AEIO::DataBuffer& input, ImageData& target) = 0; + /// + /// һڴ棬һѹImage dataѹʧܷnullptr + /// + virtual void Decode(AEIO::DataBuffer& input, ImageData& target) = 0; - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/image/png_decoder.cpp b/source/modules/asura-core/image/png_decoder.cpp index a76af80..bf33959 100644 --- a/source/modules/asura-core/image/png_decoder.cpp +++ b/source/modules/asura-core/image/png_decoder.cpp @@ -1,19 +1,17 @@ #include "png_decoder.h" -namespace AsuraEngine -{ - namespace Image - { - - bool PNGDecoder::CanDecode(AEIO::DataBuffer& buffer) - { - return false; - } +namespace_begin(AsuraEngine) +namespace_begin(Image) - void PNGDecoder::Decode(AEIO::DataBuffer& buffer, ImageData& data) - { +bool PNGDecoder::CanDecode(AEIO::DataBuffer& buffer) +{ + return false; +} - } +void PNGDecoder::Decode(AEIO::DataBuffer& buffer, ImageData& data) +{ - } } + +namespace_end +namespace_end diff --git a/source/modules/asura-core/image/png_decoder.h b/source/modules/asura-core/image/png_decoder.h index 24e40c5..af67186 100644 --- a/source/modules/asura-core/image/png_decoder.h +++ b/source/modules/asura-core/image/png_decoder.h @@ -3,25 +3,23 @@ #include "image_decoder.h" -namespace AsuraEngine -{ - namespace Image - { +namespace_begin(AsuraEngine) +namespace_begin(Image) - /// - /// ʹlodepngѹpngļ - /// - class PNGDecoder ASURA_FINAL: public ImageDecoder - { - public: +/// +/// ʹlodepngѹpngļ +/// +class PNGDecoder ASURA_FINAL: public ImageDecoder +{ +public: - bool CanDecode(AEIO::DataBuffer& buffer) override; + bool CanDecode(AEIO::DataBuffer& buffer) override; - void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; + void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/image/stb_decoder.cpp b/source/modules/asura-core/image/stb_decoder.cpp index add1c13..ed61aa4 100644 --- a/source/modules/asura-core/image/stb_decoder.cpp +++ b/source/modules/asura-core/image/stb_decoder.cpp @@ -7,69 +7,67 @@ using namespace AEGraphics; -namespace AsuraEngine -{ - namespace Image - { +namespace_begin(AsuraEngine) +namespace_begin(Image) - bool STBDecoder::CanDecode(IO::DataBuffer& buffer) - { - int w = 0; - int h = 0; - int comp = 0; - - int status = stbi_info_from_memory((const stbi_uc*)buffer.GetData(), buffer.GetSize(), &w, &h, &comp); +bool STBDecoder::CanDecode(IO::DataBuffer& buffer) +{ + int w = 0; + int h = 0; + int comp = 0; - return status == 1 && w > 0 && h > 0; - } + int status = stbi_info_from_memory((const stbi_uc*)buffer.GetData(), buffer.GetSize(), &w, &h, &comp); - void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData) - { - const stbi_uc *buffer = (const stbi_uc *)db.GetData(); - // databufferݳ - int bufferlen = db.GetSize(); + return status == 1 && w > 0 && h > 0; +} - int width, height; - int comp = 0; - byte* data = nullptr; - ColorFormat format = COLOR_FORMAT_UNKNOWN; - std::size_t size = 0; +void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData) +{ + const stbi_uc *buffer = (const stbi_uc *)db.GetData(); + // databufferݳ + int bufferlen = db.GetSize(); - if (stbi_is_hdr_from_memory(buffer, bufferlen)) - { - // 4channelfloat - data = (byte*)stbi_loadf_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); - format = COLOR_FORMAT_RGBA32F; - size = width * height * 4 * sizeof(float); - } - else - { - data = (byte*)stbi_load_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); - format = COLOR_FORMAT_RGBA8; - size = width * height * 4; - } - if (data) - { - imageData.Lock(); + int width, height; + int comp = 0; + byte* data = nullptr; + ColorFormat format = COLOR_FORMAT_UNKNOWN; + std::size_t size = 0; - if (imageData.pixels) - free(imageData.pixels); - imageData.pixels = (byte*)data; - imageData.format = format; - imageData.width = width; - imageData.height = height; - imageData.size = size; + if (stbi_is_hdr_from_memory(buffer, bufferlen)) + { + // 4channelfloat + data = (byte*)stbi_loadf_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); + format = COLOR_FORMAT_RGBA32F; + size = width * height * 4 * sizeof(float); + } + else + { + data = (byte*)stbi_load_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); + format = COLOR_FORMAT_RGBA8; + size = width * height * 4; + } + if (data) + { + imageData.Lock(); - imageData.Unlock(); - } - else - { - const char *err = stbi_failure_reason(); - if (err == nullptr) - err = "unknown error"; - throw Exception("Could not decode image with stb_image (%s).", err); - } - } + if (imageData.pixels) + free(imageData.pixels); + imageData.pixels = (byte*)data; + imageData.format = format; + imageData.width = width; + imageData.height = height; + imageData.size = size; + imageData.Unlock(); } -}
\ No newline at end of file + else + { + const char *err = stbi_failure_reason(); + if (err == nullptr) + err = "unknown error"; + throw Exception("Could not decode image with stb_image (%s).", err); + } +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/image/stb_decoder.h b/source/modules/asura-core/image/stb_decoder.h index ad89214..6158b21 100644 --- a/source/modules/asura-core/image/stb_decoder.h +++ b/source/modules/asura-core/image/stb_decoder.h @@ -3,26 +3,24 @@ #include "image_decoder.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Image) + +/// +/// ʹstb_imageѹJPEGTGABMPļ +/// +class STBDecoder ASURA_FINAL + : public ImageDecoder { - namespace Image - { +public: - /// - /// ʹstb_imageѹJPEGTGABMPļ - /// - class STBDecoder ASURA_FINAL - : public ImageDecoder - { - public: + bool CanDecode(AEIO::DataBuffer& buffer) override; - bool CanDecode(AEIO::DataBuffer& buffer) override; + void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; - void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; +}; - }; - - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/input/button.h b/source/modules/asura-core/input/button.h index 0df8ed2..78f9b6d 100644 --- a/source/modules/asura-core/input/button.h +++ b/source/modules/asura-core/input/button.h @@ -1,32 +1,31 @@ #ifndef __BUTTON_H__ #define __BUTTON_H__ -namespace AsuraEngine -{ - namespace Input - { +#include <asura-utils/classes.h> - /// keyboard button \ mouse button \ joystick button - class Button - { - public: - inline Button(int key, bool state) : - key(key), - state(state) - { - } +namespace_begin(AsuraEngine) +namespace_begin(Input) - inline int GetKey(void) const { return this->key; } - inline bool GetState(void) const { return this->state; } +/// keyboard button \ mouse button \ joystick button +class Button +{ +public: + inline Button(int key, bool state) : + key(key), + state(state) + { + } - private: - int key; - bool state; + inline int GetKey(void) const { return this->key; } + inline bool GetState(void) const { return this->state; } - }; +private: + int key; + bool state; - } -} +}; +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/input/input_device.h b/source/modules/asura-core/input/input_device.h index 7082ea3..1c116e6 100644 --- a/source/modules/asura-core/input/input_device.h +++ b/source/modules/asura-core/input/input_device.h @@ -9,32 +9,30 @@ #include "keyboard_state.h" -namespace AsuraEngine -{ - namespace Input - { +namespace_begin(AsuraEngine) +namespace_begin(Input) - /// ͬƽ̨̳ಢʵhandleӿ - ASURA_ABSTRACT class InputDevice : public Singleton<InputDevice> - { - protected: +/// ͬƽ̨̳ಢʵhandleӿ +ASURA_ABSTRACT class InputDevice : public Singleton<InputDevice> +{ +protected: - void OnKeyDown(int key); - void OnKeyUp(int key); + void OnKeyDown(int key); + void OnKeyUp(int key); - void OnMouseMove(const AEMath::Vector2f& position); + void OnMouseMove(const AEMath::Vector2f& position); - void OnMouseButtonDown(int key); - void OnMouseButtonUp(int key); + void OnMouseButtonDown(int key); + void OnMouseButtonUp(int key); - void OnMouseWheel(); + void OnMouseWheel(); - void OnInputChar(); + void OnInputChar(); - }; +}; - } -} +namespace_end +namespace_end namespace AEInput = AsuraEngine::Input; diff --git a/source/modules/asura-core/input/input_manager.h b/source/modules/asura-core/input/input_manager.h index 4597d39..7e24b4e 100644 --- a/source/modules/asura-core/input/input_manager.h +++ b/source/modules/asura-core/input/input_manager.h @@ -3,23 +3,22 @@ #include <asura-utils/scripting/portable.hpp> #include <asura-utils/singleton.hpp> +#include <asura-utils/classes.h> -namespace AsuraEngine -{ - namespace Input - { +namespace_begin(AsuraEngine) +namespace_begin(Input) - /// - class InputManager : public Singleton<InputManager> - { - public : +/// +class InputManager : public Singleton<InputManager> +{ +public : - private : +private : - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/input/keyboard_state.h b/source/modules/asura-core/input/keyboard_state.h index f6aa5ea..5c43dff 100644 --- a/source/modules/asura-core/input/keyboard_state.h +++ b/source/modules/asura-core/input/keyboard_state.h @@ -5,35 +5,33 @@ #include "button.h" -namespace AsuraEngine -{ - namespace Input - { +namespace_begin(AsuraEngine) +namespace_begin(Input) - typedef std::vector<Button> Buttons; +typedef std::vector<Button> Buttons; - class KeyboardState - { - private: - Buttons buttons; +class KeyboardState +{ +private: + Buttons buttons; - public: - inline KeyboardState(void) - { - this->buttons.reserve(256); - } +public: + inline KeyboardState(void) + { + this->buttons.reserve(256); + } - inline const Buttons &GetButtons(void) const { return this->buttons; } - inline void AddButton(int key, bool state) { this->buttons.push_back(Button(key, state)); } + inline const Buttons &GetButtons(void) const { return this->buttons; } + inline void AddButton(int key, bool state) { this->buttons.push_back(Button(key, state)); } - void Reset(bool full) - { - this->buttons.clear(); - } + void Reset(bool full) + { + this->buttons.clear(); + } - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/mesh/am2_handler.cpp b/source/modules/asura-core/mesh/am2_handler.cpp index 31bd51b..d0b9252 100644 --- a/source/modules/asura-core/mesh/am2_handler.cpp +++ b/source/modules/asura-core/mesh/am2_handler.cpp @@ -1,9 +1,7 @@ #include "am2_handler.h" -namespace AsuraEngine -{ - namespace Mesh - { +namespace_begin(AsuraEngine) +namespace_begin(Mesh) /* Asuramesh2DʽΪ.am2ʽ¡ ͷ11ֽڱһAsuraMesh2Dļ @@ -32,5 +30,5 @@ f 0, 1, 2 - } -} +namespace_end +namespace_end diff --git a/source/modules/asura-core/mesh/am2_handler.h b/source/modules/asura-core/mesh/am2_handler.h index de93be9..4fa8ba5 100644 --- a/source/modules/asura-core/mesh/am2_handler.h +++ b/source/modules/asura-core/mesh/am2_handler.h @@ -3,30 +3,28 @@ #include "mesh2d_handler.h" -namespace AsuraEngine -{ - namespace Mesh - { +namespace_begin(AsuraEngine) +namespace_begin(Mesh) - /// - /// Asura Mesh Format handlerAsura.am2ʽmeshļ - /// - class AM2Handler ASURA_FINAL : public Mesh2DHandler - { - public: +/// +/// Asura Mesh Format handlerAsura.am2ʽmeshļ +/// +class AM2Handler ASURA_FINAL : public Mesh2DHandler +{ +public: - AM2Handler(); - ~AM2Handler(); + AM2Handler(); + ~AM2Handler(); - bool CanDecode(AEIO::DataBuffer& input) override; + bool CanDecode(AEIO::DataBuffer& input) override; - void Decode(AEIO::DataBuffer& input, Mesh2DData& target) override; + void Decode(AEIO::DataBuffer& input, Mesh2DData& target) override; - void Encode(Mesh2DData& input, AEIO::DataBuffer& target) override; + void Encode(Mesh2DData& input, AEIO::DataBuffer& target) override; - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/mesh/mesh2d_data.h b/source/modules/asura-core/mesh/mesh2d_data.h index 2fea7ec..024ba02 100644 --- a/source/modules/asura-core/mesh/mesh2d_data.h +++ b/source/modules/asura-core/mesh/mesh2d_data.h @@ -13,67 +13,65 @@ #include "../graphics/color.h" #include "../graphics/gpu_buffer.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Mesh) + +/// +/// Mesh2DĶݣindexʹáAsura 2D mesh֧4UVһϡ +/// +struct Vertex +{ + AEMath::Vector2f position; ///< + AEGraphics::Color color; ///< ɫ + AEMath::Vector2f texCoord[4]; ///< UVs +}; + +/// +/// meshĶݺ +/// +class Mesh2DData + : AEIO::DecodedData + , AEScripting::Portable<Mesh2DData> { - namespace Mesh +public: + + enum Mesh2DComponent { + MESH2D_COMPONENT_POSITION, + MESH2D_COMPONENT_COLOR, + MESH2D_COMPONENT_TEXCOORD0, + MESH2D_COMPONENT_TEXCOORD1, + MESH2D_COMPONENT_TEXCOORD2, + MESH2D_COMPONENT_TEXCOORD3, + }; + + void Decode(AEIO::DataBuffer& buffer) override; + +private: - /// - /// Mesh2DĶݣindexʹáAsura 2D mesh֧4UVһϡ - /// - struct Vertex - { - AEMath::Vector2f position; ///< - AEGraphics::Color color; ///< ɫ - AEMath::Vector2f texCoord[4]; ///< UVs - }; - - /// - /// meshĶݺ - /// - class Mesh2DData - : AEIO::DecodedData - , AEScripting::Portable<Mesh2DData> - { - public: - - enum Mesh2DComponent - { - MESH2D_COMPONENT_POSITION, - MESH2D_COMPONENT_COLOR, - MESH2D_COMPONENT_TEXCOORD0, - MESH2D_COMPONENT_TEXCOORD1, - MESH2D_COMPONENT_TEXCOORD2, - MESH2D_COMPONENT_TEXCOORD3, - }; - - void Decode(AEIO::DataBuffer& buffer) override; - - private: - - LUAX_DECL_FACTORY(Mesh2DData); + LUAX_DECL_FACTORY(Mesh2DData); - LUAX_DECL_ENUM(Mesh2DComponent, 1); + LUAX_DECL_ENUM(Mesh2DComponent, 1); - LUAX_DECL_METHOD(_GetVertices); - LUAX_DECL_METHOD(_GetVertex); + LUAX_DECL_METHOD(_GetVertices); + LUAX_DECL_METHOD(_GetVertex); - /// - /// meshж㡣 - /// - std::vector<Vertex*> m_Vertices; + /// + /// meshж㡣 + /// + std::vector<Vertex*> m_Vertices; - /// - /// ebo - /// - std::vector<int> m_Indices; + /// + /// ebo + /// + std::vector<int> m_Indices; - int m_Components; + int m_Components; - }; +}; - } -} +namespace_end +namespace_end namespace AEMesh = AsuraEngine::Mesh; diff --git a/source/modules/asura-core/mesh/mesh2d_handler.h b/source/modules/asura-core/mesh/mesh2d_handler.h index 05e12f0..c8ae32e 100644 --- a/source/modules/asura-core/mesh/mesh2d_handler.h +++ b/source/modules/asura-core/mesh/mesh2d_handler.h @@ -6,29 +6,27 @@ #include "mesh2d_data.h" -namespace AsuraEngine -{ - namespace Mesh - { +namespace_begin(AsuraEngine) +namespace_begin(Mesh) - /// - /// ͱmesh - /// - ASURA_ABSTRACT class Mesh2DHandler - { - public: - Mesh2DHandler() {}; - virtual ~Mesh2DHandler() {}; +/// +/// ͱmesh +/// +ASURA_ABSTRACT class Mesh2DHandler +{ +public: + Mesh2DHandler() {}; + virtual ~Mesh2DHandler() {}; - virtual bool CanDecode(AEIO::DataBuffer& input) = 0; + virtual bool CanDecode(AEIO::DataBuffer& input) = 0; - virtual void Decode(AEIO::DataBuffer& input, Mesh2DData& target) = 0; + virtual void Decode(AEIO::DataBuffer& input, Mesh2DData& target) = 0; - virtual void Encode(Mesh2DData& input, AEIO::DataBuffer& target) = 0; + virtual void Encode(Mesh2DData& input, AEIO::DataBuffer& target) = 0; - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/threading/channel.h b/source/modules/asura-core/threading/channel.h index edcd8cb..ede43e4 100644 --- a/source/modules/asura-core/threading/channel.h +++ b/source/modules/asura-core/threading/channel.h @@ -2,18 +2,17 @@ #define __ASURA_THREAD_CHANNEL_H__ #include <asura-utils/scripting/portable.hpp> +#include <asura-utils/classes.h> -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - class Channel - { +class Channel +{ - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/threading/thread_ex.cpp b/source/modules/asura-core/threading/thread_ex.cpp index 4883f90..da806f4 100644 --- a/source/modules/asura-core/threading/thread_ex.cpp +++ b/source/modules/asura-core/threading/thread_ex.cpp @@ -1,20 +1,20 @@ +#include <asura-utils/classes.h> + #include "thread_ex.h" -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - int ThreadEx::Process() - { +int ThreadEx::Process() +{ - return 0; - } + return 0; +} - void ThreadEx::RegisterModules() - { +void ThreadEx::RegisterModules() +{ - } +} - } -}
\ No newline at end of file +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-core/threading/thread_ex.h b/source/modules/asura-core/threading/thread_ex.h index 9678647..0015f61 100644 --- a/source/modules/asura-core/threading/thread_ex.h +++ b/source/modules/asura-core/threading/thread_ex.h @@ -4,51 +4,42 @@ #include <asura-utils/scripting/portable.hpp> #include <asura-utils/threading/thread.h> -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Threading) + +/// +/// ThreadExеͬͨ˶ͨݡ +/// +class ThreadEx ASURA_FINAL + : public AEScripting::Portable<ThreadEx> + , public Threadable { - namespace Threading - { +public: - /// - /// ThreadExеͬͨ˶ͨݡ - /// - class ThreadEx ASURA_FINAL - : public AEScripting::Portable<ThreadEx> - , public Threadable - { - public: + LUAX_DECL_FACTORY(ThreadEx); - LUAX_DECL_FACTORY(ThreadEx); + ThreadEx(); + ~ThreadEx(); - ThreadEx(); - ~ThreadEx(); + int Process() override; - int Process() override; +private: + + // ̵߳עAsuraͽӿڣעֻһֶ֮䴫ݡЩ͵Ķ + void RegisterModules(); - private: + ThreadImpl* m_Impl; - //----------------------------------------------------------------------------// + // ̴߳ + Luax::LuaxVM* m_VM; - LUAX_DECL_METHOD(_New); +luaxport: - //----------------------------------------------------------------------------// + LUAX_DECL_METHOD(_New); - /// - /// ̵߳עAsuraͽӿڣעֻһֶ֮䴫ݡ - /// Щ͵Ķ - /// - void RegisterModules(); +}; - ThreadImpl* m_Impl; - - /// - /// ̴߳ - /// - Luax::LuaxVM* m_VM; - - }; - - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-core/window/binding/_window.cpp b/source/modules/asura-core/window/binding/_window.cpp index cff1dd3..7119cd2 100644 --- a/source/modules/asura-core/window/binding/_window.cpp +++ b/source/modules/asura-core/window/binding/_window.cpp @@ -6,10 +6,8 @@ using namespace std; using namespace AEGraphics; using namespace AEImage; -namespace AsuraEngine -{ - namespace Window - { +namespace_begin(AsuraEngine) +namespace_begin(Window) LUAX_REGISTRY(Window) { diff --git a/source/modules/asura-core/window/window.cpp b/source/modules/asura-core/window/window.cpp index 939e974..bbcb949 100644 --- a/source/modules/asura-core/window/window.cpp +++ b/source/modules/asura-core/window/window.cpp @@ -6,10 +6,8 @@ #include "window_impl_glew.h" #include "window_impl_glut.h" -namespace AsuraEngine -{ - namespace Window - { +namespace_begin(AsuraEngine) +namespace_begin(Window) Window::Window() : m_Impl(nullptr) diff --git a/source/modules/asura-core/window/window.h b/source/modules/asura-core/window/window.h index deffc10..872c40f 100644 --- a/source/modules/asura-core/window/window.h +++ b/source/modules/asura-core/window/window.h @@ -9,131 +9,129 @@ #include "../graphics/render_state.h" #include "../graphics/render_target.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Window) + +class WindowImpl; + +/// +/// SDLģһЩõġ +/// +enum WindowFlag +{ + WINDOW_FULLSCREEN = 1 << 1, ///< fullscreen window + WINDOW_OPENGL = 1 << 2, ///< window usable with OpenGL context + WINDOW_SHOWN = 1 << 3, ///< window is visible + WINDOW_HIDDEN = 1 << 4, ///< window is not visible + WINDOW_BORDERLESS = 1 << 5, ///< no window decoration + WINDOW_RESIZABLE = 1 << 6, ///< window can be resized + WINDOW_MINIMIZED = 1 << 7, ///< window is minimized + WINDOW_MAXIMIZED = 1 << 8, ///< window is maximized + WINDOW_INPUT_GRABBED = 1 << 9, ///< window has grabbed input focus + WINDOW_INPUT_FOCUS = 1 << 10, ///< window has input focus + WINDOW_MOUSE_FOCUS = 1 << 11, ///< window has mouse focus + WINDOW_ALLOW_HIGHDPI = 1 << 12, ///< window should be created in high-DPI mode if supported. + ///< On macOS NSHighResolutionCapable must be set true in the + ///< application's Info.plist for this to have any effect. + WINDOW_MOUSE_CAPTURE = 1 << 13, ///< window has mouse captured (unrelated to INPUT_GRABBED) + WINDOW_ALWAYS_ON_TOP = 1 << 14, ///< window should always be above others +}; + +/// Windowʼ +struct WindowConfig +{ + uint width, height; ///< ߴ + int x, y; ///< ڳʼ + std::string title; ///< + bool vsync; ///< ֱͬ + AEImage::ImageData* icon; ///< ͼ + bool show; ///< Ƿʾ + int flag; ///< ڱ +}; + +/// +/// ϷĵڣrunnerֻҪһڡͬĿͻʵִ˽ӿڲֶעᵽlua༭ +/// ᵼ࣬ӵ༭ⴰϡ +/// +class Window ASURA_FINAL + : public AEScripting::Portable<Window, AEGraphics::RenderTarget> + , public Singleton<Window> { - namespace Window - { - - class WindowImpl; - - /// - /// SDLģһЩõġ - /// - enum WindowFlag - { - WINDOW_FULLSCREEN = 1 << 1, ///< fullscreen window - WINDOW_OPENGL = 1 << 2, ///< window usable with OpenGL context - WINDOW_SHOWN = 1 << 3, ///< window is visible - WINDOW_HIDDEN = 1 << 4, ///< window is not visible - WINDOW_BORDERLESS = 1 << 5, ///< no window decoration - WINDOW_RESIZABLE = 1 << 6, ///< window can be resized - WINDOW_MINIMIZED = 1 << 7, ///< window is minimized - WINDOW_MAXIMIZED = 1 << 8, ///< window is maximized - WINDOW_INPUT_GRABBED = 1 << 9, ///< window has grabbed input focus - WINDOW_INPUT_FOCUS = 1 << 10, ///< window has input focus - WINDOW_MOUSE_FOCUS = 1 << 11, ///< window has mouse focus - WINDOW_ALLOW_HIGHDPI = 1 << 12, ///< window should be created in high-DPI mode if supported. - ///< On macOS NSHighResolutionCapable must be set true in the - ///< application's Info.plist for this to have any effect. - WINDOW_MOUSE_CAPTURE = 1 << 13, ///< window has mouse captured (unrelated to INPUT_GRABBED) - WINDOW_ALWAYS_ON_TOP = 1 << 14, ///< window should always be above others - }; - - /// Windowʼ - struct WindowConfig - { - uint width, height; ///< ߴ - int x, y; ///< ڳʼ - std::string title; ///< - bool vsync; ///< ֱͬ - AEImage::ImageData* icon; ///< ͼ - bool show; ///< Ƿʾ - int flag; ///< ڱ - }; - - /// - /// ϷĵڣrunnerֻҪһڡͬĿͻʵִ˽ӿڲֶעᵽlua༭ - /// ᵼ࣬ӵ༭ⴰϡ - /// - class Window ASURA_FINAL - : public AEScripting::Portable<Window, AEGraphics::RenderTarget> - , public Singleton<Window> - { - public: - - /// ϷʱĴΨһģ༭õࡣ - LUAX_DECL_SINGLETON(Window); - - Window(); - ~Window(); - - /// ڡ - bool Init(const WindowConfig& config); - void Exit(); - - void SetSize(uint width, uint height); - void SetPosition(int x, int y); - void SetTitle(const std::string& title); - void SetIcon(AEImage::ImageData* imgData); - - void Show(); - void Hide(); - - /// ǿ˫ĴڣҪչʾǰ̨ - void SwapRenderBuffer(); - - void Clear(const AEGraphics::Color& col = AEGraphics::Color::Black) override; - void Clear(const Math::Recti& quad, const AEGraphics::Color& col = AEGraphics::Color::Black) override; - - void Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) override; - void Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) override; - - private: - - WindowImpl* m_Impl; - - luaxport: - - LUAX_DECL_ENUM(WindowFlag, 0); - - LUAX_DECL_METHOD(_Init); - LUAX_DECL_METHOD(_Exit); - LUAX_DECL_METHOD(_Show); - LUAX_DECL_METHOD(_Hide); - LUAX_DECL_METHOD(_SetSize); - LUAX_DECL_METHOD(_SetPosition); - LUAX_DECL_METHOD(_SetTitle); - LUAX_DECL_METHOD(_SetIcon); - LUAX_DECL_METHOD(_SwapRenderBuffer); - LUAX_DECL_METHOD(_Clear); - LUAX_DECL_METHOD(_Draw); - - }; - - using RenderWindow = Window; - - ASURA_ABSTRACT class WindowImpl - { - public: - - WindowImpl() {}; - virtual ~WindowImpl() {}; - - virtual bool Init(const WindowConfig& config); - - virtual void SetSize(uint width, uint height) = 0; - virtual void SetPosition(int x, int y) = 0; - virtual void SetTitils(const std::string& title) = 0; - - virtual void Show() = 0; - virtual void Hide() = 0; - - virtual void SwapRenderBuffer() = 0; - - }; +public: + + /// ϷʱĴΨһģ༭õࡣ + LUAX_DECL_SINGLETON(Window); + + Window(); + ~Window(); + + /// ڡ + bool Init(const WindowConfig& config); + void Exit(); + + void SetSize(uint width, uint height); + void SetPosition(int x, int y); + void SetTitle(const std::string& title); + void SetIcon(AEImage::ImageData* imgData); + + void Show(); + void Hide(); + + /// ǿ˫ĴڣҪչʾǰ̨ + void SwapRenderBuffer(); + + void Clear(const AEGraphics::Color& col = AEGraphics::Color::Black) override; + void Clear(const Math::Recti& quad, const AEGraphics::Color& col = AEGraphics::Color::Black) override; + + void Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) override; + void Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) override; + +private: + + WindowImpl* m_Impl; + +luaxport: + + LUAX_DECL_ENUM(WindowFlag, 0); + + LUAX_DECL_METHOD(_Init); + LUAX_DECL_METHOD(_Exit); + LUAX_DECL_METHOD(_Show); + LUAX_DECL_METHOD(_Hide); + LUAX_DECL_METHOD(_SetSize); + LUAX_DECL_METHOD(_SetPosition); + LUAX_DECL_METHOD(_SetTitle); + LUAX_DECL_METHOD(_SetIcon); + LUAX_DECL_METHOD(_SwapRenderBuffer); + LUAX_DECL_METHOD(_Clear); + LUAX_DECL_METHOD(_Draw); + +}; + +using RenderWindow = Window; + +ASURA_ABSTRACT class WindowImpl +{ +public: + + WindowImpl() {}; + virtual ~WindowImpl() {}; + + virtual bool Init(const WindowConfig& config); + + virtual void SetSize(uint width, uint height) = 0; + virtual void SetPosition(int x, int y) = 0; + virtual void SetTitils(const std::string& title) = 0; + + virtual void Show() = 0; + virtual void Hide() = 0; + + virtual void SwapRenderBuffer() = 0; + +}; - } -} +namespace_end +namespace_end namespace AEWindow = AsuraEngine::Window; diff --git a/source/modules/asura-core/window/window_impl_sdl.cpp b/source/modules/asura-core/window/window_impl_sdl.cpp index 29a7540..59562a4 100644 --- a/source/modules/asura-core/window/window_impl_sdl.cpp +++ b/source/modules/asura-core/window/window_impl_sdl.cpp @@ -11,145 +11,143 @@ using namespace AEGraphics; using namespace AEImage; -namespace AsuraEngine -{ - namespace Window - { +namespace_begin(AsuraEngine) +namespace_begin(Window) #define asura_flag_to_sdl_flag(flag, _flag, _sdl_flag) \ - if ((flag & _flag) != 0) \ - flag |= _sdl_flag +if ((flag & _flag) != 0) \ + flag |= _sdl_flag - WindowImplSDL::WindowImplSDL() - : m_Wnd(nullptr) - , m_GLContext(0) - { - } +WindowImplSDL::WindowImplSDL() + : m_Wnd(nullptr) + , m_GLContext(0) +{ +} - WindowImplSDL::~WindowImplSDL() - { - SDL_GL_DeleteContext(m_GLContext); - SDL_DestroyWindow(m_Wnd); - SDL_FlushEvent(SDL_WINDOWEVENT); - } +WindowImplSDL::~WindowImplSDL() +{ + SDL_GL_DeleteContext(m_GLContext); + SDL_DestroyWindow(m_Wnd); + SDL_FlushEvent(SDL_WINDOWEVENT); +} - bool WindowImplSDL::Init(const WindowConfig& config) +bool WindowImplSDL::Init(const WindowConfig& config) +{ + if (SDL_Init(SDL_INIT_VIDEO) < 0) + return false; + + int flag = 0; + asura_flag_to_sdl_flag(flag, WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN); + asura_flag_to_sdl_flag(flag, WINDOW_OPENGL, SDL_WINDOW_OPENGL); + asura_flag_to_sdl_flag(flag, WINDOW_SHOWN, SDL_WINDOW_SHOWN); + asura_flag_to_sdl_flag(flag, WINDOW_HIDDEN, SDL_WINDOW_HIDDEN); + asura_flag_to_sdl_flag(flag, WINDOW_BORDERLESS, SDL_WINDOW_BORDERLESS); + asura_flag_to_sdl_flag(flag, WINDOW_RESIZABLE, SDL_WINDOW_RESIZABLE); + asura_flag_to_sdl_flag(flag, WINDOW_MINIMIZED, SDL_WINDOW_MINIMIZED); + asura_flag_to_sdl_flag(flag, WINDOW_MAXIMIZED, SDL_WINDOW_MAXIMIZED); + asura_flag_to_sdl_flag(flag, WINDOW_INPUT_GRABBED, SDL_WINDOW_INPUT_GRABBED); + asura_flag_to_sdl_flag(flag, WINDOW_INPUT_FOCUS, SDL_WINDOW_INPUT_FOCUS); + asura_flag_to_sdl_flag(flag, WINDOW_MOUSE_FOCUS, SDL_WINDOW_MOUSE_FOCUS); + asura_flag_to_sdl_flag(flag, WINDOW_ALLOW_HIGHDPI, SDL_WINDOW_ALLOW_HIGHDPI); + asura_flag_to_sdl_flag(flag, WINDOW_MOUSE_CAPTURE, SDL_WINDOW_MOUSE_CAPTURE); + asura_flag_to_sdl_flag(flag, WINDOW_ALWAYS_ON_TOP, SDL_WINDOW_ALWAYS_ON_TOP); + + // Set GL window / framebuffer attributes. + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0); + + m_Wnd = SDL_CreateWindow(config.title.c_str(), config.x, config.y, config.width, config.height, flag); + + if (!m_Wnd) + return false; + + // ͼ + try + { + if (config.icon) { - if (SDL_Init(SDL_INIT_VIDEO) < 0) - return false; - - int flag = 0; - asura_flag_to_sdl_flag(flag, WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN); - asura_flag_to_sdl_flag(flag, WINDOW_OPENGL, SDL_WINDOW_OPENGL); - asura_flag_to_sdl_flag(flag, WINDOW_SHOWN, SDL_WINDOW_SHOWN); - asura_flag_to_sdl_flag(flag, WINDOW_HIDDEN, SDL_WINDOW_HIDDEN); - asura_flag_to_sdl_flag(flag, WINDOW_BORDERLESS, SDL_WINDOW_BORDERLESS); - asura_flag_to_sdl_flag(flag, WINDOW_RESIZABLE, SDL_WINDOW_RESIZABLE); - asura_flag_to_sdl_flag(flag, WINDOW_MINIMIZED, SDL_WINDOW_MINIMIZED); - asura_flag_to_sdl_flag(flag, WINDOW_MAXIMIZED, SDL_WINDOW_MAXIMIZED); - asura_flag_to_sdl_flag(flag, WINDOW_INPUT_GRABBED, SDL_WINDOW_INPUT_GRABBED); - asura_flag_to_sdl_flag(flag, WINDOW_INPUT_FOCUS, SDL_WINDOW_INPUT_FOCUS); - asura_flag_to_sdl_flag(flag, WINDOW_MOUSE_FOCUS, SDL_WINDOW_MOUSE_FOCUS); - asura_flag_to_sdl_flag(flag, WINDOW_ALLOW_HIGHDPI, SDL_WINDOW_ALLOW_HIGHDPI); - asura_flag_to_sdl_flag(flag, WINDOW_MOUSE_CAPTURE, SDL_WINDOW_MOUSE_CAPTURE); - asura_flag_to_sdl_flag(flag, WINDOW_ALWAYS_ON_TOP, SDL_WINDOW_ALWAYS_ON_TOP); - - // Set GL window / framebuffer attributes. - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0); - - m_Wnd = SDL_CreateWindow(config.title.c_str(), config.x, config.y, config.width, config.height, flag); - - if (!m_Wnd) - return false; - - // ͼ - try + ImageData* img = config.icon; + if (img->format == COLOR_FORMAT_RGBA8) { - if (config.icon) - { - ImageData* img = config.icon; - if (img->format == COLOR_FORMAT_RGBA8) - { - SDL_Surface *surface; - - img->Lock(); - - int w = img->width, h = img->height; - surface = SDL_CreateRGBSurfaceFrom( - img->pixels, - w, h, - 32, - w * 4, - Color32::RMASK, - Color32::GMASK, - Color32::BMASK, - Color32::AMASK - ); - - img->Unlock(); - - SDL_SetWindowIcon(m_Wnd, surface); - SDL_FreeSurface(surface); - } - } + SDL_Surface *surface; + + img->Lock(); + + int w = img->width, h = img->height; + surface = SDL_CreateRGBSurfaceFrom( + img->pixels, + w, h, + 32, + w * 4, + Color32::RMASK, + Color32::GMASK, + Color32::BMASK, + Color32::AMASK + ); + + img->Unlock(); + + SDL_SetWindowIcon(m_Wnd, surface); + SDL_FreeSurface(surface); } - catch (...) - { - } - - m_GLContext = SDL_GL_CreateContext(m_Wnd); + } + } + catch (...) + { + } - if (!m_GLContext) - { - SDL_DestroyWindow(m_Wnd); - return false; - } + m_GLContext = SDL_GL_CreateContext(m_Wnd); - SDL_GL_MakeCurrent(m_Wnd, m_GLContext); - SDL_GL_SetSwapInterval(config.vsync ? 1 : 0); + if (!m_GLContext) + { + SDL_DestroyWindow(m_Wnd); + return false; + } - return true; - } + SDL_GL_MakeCurrent(m_Wnd, m_GLContext); + SDL_GL_SetSwapInterval(config.vsync ? 1 : 0); - void WindowImplSDL::SetSize(uint width, uint height) - { - SDL_SetWindowSize(m_Wnd, width, height); - } + return true; +} - void WindowImplSDL::SetPosition(int x, int y) - { - SDL_SetWindowPosition(m_Wnd, x, y); - } +void WindowImplSDL::SetSize(uint width, uint height) +{ + SDL_SetWindowSize(m_Wnd, width, height); +} - void WindowImplSDL::SetTitils(const std::string& title) - { - SDL_SetWindowTitle(m_Wnd, title.c_str()); - } +void WindowImplSDL::SetPosition(int x, int y) +{ + SDL_SetWindowPosition(m_Wnd, x, y); +} - void WindowImplSDL::Show() - { - SDL_ShowWindow(m_Wnd); - } +void WindowImplSDL::SetTitils(const std::string& title) +{ + SDL_SetWindowTitle(m_Wnd, title.c_str()); +} - void WindowImplSDL::Hide() - { - SDL_HideWindow(m_Wnd); - } +void WindowImplSDL::Show() +{ + SDL_ShowWindow(m_Wnd); +} - void WindowImplSDL::SwapRenderBuffer() - { - SDL_GL_SwapWindow(m_Wnd); - } +void WindowImplSDL::Hide() +{ + SDL_HideWindow(m_Wnd); +} - } +void WindowImplSDL::SwapRenderBuffer() +{ + SDL_GL_SwapWindow(m_Wnd); } +namespace_end +namespace_end + #endif // ASURA_WINDOW_SDL
\ No newline at end of file diff --git a/source/modules/asura-core/window/window_impl_sdl.h b/source/modules/asura-core/window/window_impl_sdl.h index 1f4ea0e..20f5c95 100644 --- a/source/modules/asura-core/window/window_impl_sdl.h +++ b/source/modules/asura-core/window/window_impl_sdl.h @@ -9,38 +9,36 @@ #include "window.h" -namespace AsuraEngine -{ - namespace Window - { +namespace_begin(AsuraEngine) +namespace_begin(Window) - class WindowImplSDL ASURA_FINAL : public WindowImpl - { - public: +class WindowImplSDL ASURA_FINAL : public WindowImpl +{ +public: - WindowImplSDL(); - ~WindowImplSDL(); + WindowImplSDL(); + ~WindowImplSDL(); - bool Init(const WindowConfig& config); + bool Init(const WindowConfig& config); - void SetSize(uint width, uint height) override; - void SetPosition(int x, int y) override; - void SetTitils(const std::string& title) override; + void SetSize(uint width, uint height) override; + void SetPosition(int x, int y) override; + void SetTitils(const std::string& title) override; - void Show() override; - void Hide() override; + void Show() override; + void Hide() override; - void SwapRenderBuffer() override; + void SwapRenderBuffer() override; - private: +private: - SDL_Window* m_Wnd; - SDL_GLContext m_GLContext; + SDL_Window* m_Wnd; + SDL_GLContext m_GLContext; - }; +}; - } -} +namespace_end +namespace_end #endif // ASURA_WINDOW_SDL diff --git a/source/modules/asura-utils/classes.h b/source/modules/asura-utils/classes.h new file mode 100644 index 0000000..8c89b6a --- /dev/null +++ b/source/modules/asura-utils/classes.h @@ -0,0 +1,9 @@ +#ifndef __ASURAENGINE_CLASSES_H__ +#define __ASURAENGINE_CLASSES_H__ + +#define GET_SET(TYPE,PROP_NAME,VAR_NAME) void Set##PROP_NAME (TYPE val) { VAR_NAME = val; } const TYPE Get##PROP_NAME () const {return (const TYPE)VAR_NAME; } + +#define namespace_begin(NAMESPACE) namespace NAMESPACE { +#define namespace_end } + +#endif diff --git a/source/modules/asura-utils/exceptions/exception.h b/source/modules/asura-utils/exceptions/exception.h index 9873a38..4acbc1e 100644 --- a/source/modules/asura-utils/exceptions/exception.h +++ b/source/modules/asura-utils/exceptions/exception.h @@ -7,23 +7,23 @@ namespace AsuraEngine { - class Exception : public std::exception - { - public: +class Exception : public std::exception +{ +public: - Exception(const char *fmt, ...); - virtual ~Exception() throw(); + Exception(const char *fmt, ...); + virtual ~Exception() throw(); - inline virtual const char *what() const throw() - { - return message.c_str(); - } + inline virtual const char *what() const throw() + { + return message.c_str(); + } - private: +private: - std::string message; + std::string message; - }; // Exception +}; // Exception } diff --git a/source/modules/asura-utils/io/file.cpp b/source/modules/asura-utils/io/file.cpp index 2061fb1..a2f7403 100644 --- a/source/modules/asura-utils/io/file.cpp +++ b/source/modules/asura-utils/io/file.cpp @@ -80,8 +80,8 @@ namespace AsuraEngine throw Exception("Could not open file %s (%s)", m_FileName.c_str(), err); } - m_FileHandle = handle; - m_Mode = mode; + m_FileHandle = handle; + m_Mode = mode; if (m_FileHandle && !SetBuffer(m_BufferMode,m_BufferSize)) { diff --git a/source/modules/asura-utils/scripting/portable.hpp b/source/modules/asura-utils/scripting/portable.hpp index 2716da4..d691455 100644 --- a/source/modules/asura-utils/scripting/portable.hpp +++ b/source/modules/asura-utils/scripting/portable.hpp @@ -12,22 +12,18 @@ extern "C" { namespace AsuraEngine { - namespace Scripting - { - - /// - /// ҪΪ࣬userdatamember ref̳д࣬ע̳С - /// - using Object = Luax::LuaxObject; - - /// - /// ҪעluanativeҪ̳дģ塣BASEָ࣬ĬLuaxObjectָ - /// LuaxObjectࡢ - /// - template<typename TYPE, typename BASE = Luax::LuaxObject> - using Portable = Luax::LuaxNativeClass<TYPE, BASE>; - - } +namespace Scripting +{ + + +/// ҪΪ࣬userdatamember ref̳д࣬ע̳С +using Object = Luax::LuaxObject; + +/// ҪעluanativeҪ̳дģ塣BASEָ࣬ĬLuaxObjectָLuaxObjectࡢ +template<typename TYPE, typename BASE = Luax::LuaxObject> +using Portable = Luax::LuaxNativeClass<TYPE, BASE>; + +} } namespace AEScripting = AsuraEngine::Scripting; diff --git a/source/modules/asura-utils/threading/binding/_coroutine.cpp b/source/modules/asura-utils/threading/binding/_coroutine.cpp index 7f74cca..a710623 100644 --- a/source/modules/asura-utils/threading/binding/_coroutine.cpp +++ b/source/modules/asura-utils/threading/binding/_coroutine.cpp @@ -2,10 +2,8 @@ using namespace std; -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) LUAX_REGISTRY(Coroutine) { diff --git a/source/modules/asura-utils/threading/binding/_thread.cpp b/source/modules/asura-utils/threading/binding/_thread.cpp index ae43242..b835453 100644 --- a/source/modules/asura-utils/threading/binding/_thread.cpp +++ b/source/modules/asura-utils/threading/binding/_thread.cpp @@ -2,10 +2,8 @@ using namespace std; -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) LUAX_REGISTRY(Thread) { diff --git a/source/modules/asura-utils/threading/conditional.cpp b/source/modules/asura-utils/threading/conditional.cpp index e49bfde..c4d32d9 100644 --- a/source/modules/asura-utils/threading/conditional.cpp +++ b/source/modules/asura-utils/threading/conditional.cpp @@ -1,86 +1,84 @@ #include "conditional.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Threading) + +Conditional::Conditional() + : m_Waiting(0) + , m_Signals(0) { - namespace Threading - { +} - Conditional::Conditional() - : m_Waiting(0) - , m_Signals(0) - { - } +Conditional::~Conditional() +{ +} - Conditional::~Conditional() - { - } +void Conditional::Signal() +{ + m_Mutex.Lock(); + if (m_Waiting > m_Signals) + { + ++m_Signals; + signal(m_WaitSem); + m_Mutex.Unlock(); + wait(m_DoneSem); + } + else + { + m_Mutex.Unlock(); + } +} - void Conditional::Signal() - { - m_Mutex.Lock(); - if (m_Waiting > m_Signals) - { - ++m_Signals; - signal(m_WaitSem); - m_Mutex.Unlock(); - wait(m_DoneSem); - } - else - { - m_Mutex.Unlock(); - } +void Conditional::Broadcast() +{ + m_Mutex.Lock(); + if (m_Waiting> m_Signals) { + int i, num_waiting; + + num_waiting = (m_Waiting - m_Signals); + m_Signals = m_Waiting; + for (i = 0; i < num_waiting; ++i) { + signal(m_WaitSem); } - - void Conditional::Broadcast() - { - m_Mutex.Lock(); - if (m_Waiting> m_Signals) { - int i, num_waiting; - - num_waiting = (m_Waiting - m_Signals); - m_Signals = m_Waiting; - for (i = 0; i < num_waiting; ++i) { - signal(m_WaitSem); - } - m_Mutex.Unlock(); - for (i = 0; i < num_waiting; ++i) { - wait(m_DoneSem); - } - } - else { - m_Mutex.Unlock(); - } - + m_Mutex.Unlock(); + for (i = 0; i < num_waiting; ++i) { + wait(m_DoneSem); } + } + else { + m_Mutex.Unlock(); + } - bool Conditional::Wait(Mutex* mutex, int timeout /*= ASURA_MUTEX_MAXWAIT*/) - { - bool retval; - - m_Mutex.Lock(); - ++m_Waiting; - m_Mutex.Unlock(); - - mutex->Unlock(); +} - retval = wait(m_WaitSem, timeout); +bool Conditional::Wait(Mutex* mutex, int timeout /*= ASURA_MUTEX_MAXWAIT*/) +{ + bool retval; - m_Mutex.Lock(); - if (m_Signals > 0) { - if (!retval) { - wait(m_WaitSem); - } - signal(m_DoneSem); + m_Mutex.Lock(); + ++m_Waiting; + m_Mutex.Unlock(); - --m_Signals; - } - --m_Waiting; - m_Mutex.Unlock(); + mutex->Unlock(); - m_Mutex.Lock(); + retval = wait(m_WaitSem, timeout); - return retval; + m_Mutex.Lock(); + if (m_Signals > 0) { + if (!retval) { + wait(m_WaitSem); } + signal(m_DoneSem); + --m_Signals; } -}
\ No newline at end of file + --m_Waiting; + m_Mutex.Unlock(); + + m_Mutex.Lock(); + + return retval; +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/conditional.h b/source/modules/asura-utils/threading/conditional.h index 3aee392..ff832ac 100644 --- a/source/modules/asura-utils/threading/conditional.h +++ b/source/modules/asura-utils/threading/conditional.h @@ -1,41 +1,41 @@ #ifndef __ASURA_CONDITIONAL_H__ #define __ASURA_CONDITIONAL_H__ +#include <asura-utils/classes.h> + #include "mutex.h" #include "semaphore.h" -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - /// - /// - /// - class Conditional - { - public: +/// +/// +/// +class Conditional +{ +public: - Conditional(); - ~Conditional(); + Conditional(); + ~Conditional(); - void Signal(); - void Broadcast(); - bool Wait(Mutex* mutex, int timeout = ASURA_MUTEX_MAXWAIT); + void Signal(); + void Broadcast(); + bool Wait(Mutex* mutex, int timeout = ASURA_MUTEX_MAXWAIT); - private: +private: - Mutex m_Mutex; + Mutex m_Mutex; - Semaphore m_WaitSem; - Semaphore m_DoneSem; + Semaphore m_WaitSem; + Semaphore m_DoneSem; - int m_Waiting; - int m_Signals; + int m_Waiting; + int m_Signals; - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/coroutine.cpp b/source/modules/asura-utils/threading/coroutine.cpp index 9f65c5f..552a415 100644 --- a/source/modules/asura-utils/threading/coroutine.cpp +++ b/source/modules/asura-utils/threading/coroutine.cpp @@ -1,16 +1,15 @@ #include "coroutine.h" -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) + /* - Coroutine::Coroutine() - { +Coroutine::Coroutine() +{ - } +} */ - } -} +namespace_end +namespace_end diff --git a/source/modules/asura-utils/threading/coroutine.h b/source/modules/asura-utils/threading/coroutine.h index bd0f922..830dcd2 100644 --- a/source/modules/asura-utils/threading/coroutine.h +++ b/source/modules/asura-utils/threading/coroutine.h @@ -1,39 +1,39 @@ #ifndef __ASURA_COROUTINE_H__ #define __ASURA_COROUTINE_H__ +#include <asura-utils/classes.h> + #include "../scripting/portable.hpp" -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - /// - /// luaЭ̣һЩ - /// - class Coroutine ASURA_FINAL - : public AEScripting::Portable<Coroutine> - { - public: +/// +/// luaЭ̣һЩ +/// +class Coroutine ASURA_FINAL + : public AEScripting::Portable<Coroutine> +{ +public: - LUAX_DECL_FACTORY(Coroutine); + LUAX_DECL_FACTORY(Coroutine); - private: +private: - /// - /// ǰЭ̵state - /// - lua_State* m_ThreadState; + /// + /// ǰЭ̵state + /// + lua_State* m_ThreadState; - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Run); + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Run); - }; +}; - } -} +namespace_end +namespace_end namespace AEThreading = AsuraEngine::Threading; diff --git a/source/modules/asura-utils/threading/mutex.cpp b/source/modules/asura-utils/threading/mutex.cpp index a36af1b..ff0b3fa 100644 --- a/source/modules/asura-utils/threading/mutex.cpp +++ b/source/modules/asura-utils/threading/mutex.cpp @@ -2,106 +2,104 @@ #include "mutex.h" -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) #define try_create_mutex(impl)\ - if (!m_Impl) \ - { \ - try \ - { \ - m_Impl = new impl(); \ - } \ - catch (Exception& e) \ - { \ - m_Impl = nullptr; \ - } \ - } - - Mutex::Mutex() - : m_Impl(nullptr) - { +if (!m_Impl) \ +{ \ +try \ +{ \ + m_Impl = new impl(); \ +} \ +catch (Exception& e) \ +{ \ + m_Impl = nullptr; \ +} \ +} + +Mutex::Mutex() + : m_Impl(nullptr) +{ #if ASURA_MUTEX_WIN32_CRITICLE_SECTION - try_create_mutex(MutexImplWin32_CS); + try_create_mutex(MutexImplWin32_CS); #endif #if ASURA_MUTEX_WIN32_KERNAL_MUTEX - try_create_mutex(MutexImplWin32_KM); + try_create_mutex(MutexImplWin32_KM); #endif - ASSERT(m_Impl); - } + ASSERT(m_Impl); +} - Mutex::~Mutex() - { - if(m_Impl) - delete m_Impl; - } +Mutex::~Mutex() +{ + if(m_Impl) + delete m_Impl; +} - void Mutex::Lock() - { - ASSERT(m_Impl); +void Mutex::Lock() +{ + ASSERT(m_Impl); - m_Impl->Lock(); - } + m_Impl->Lock(); +} - void Mutex::Unlock() - { - ASSERT(m_Impl); +void Mutex::Unlock() +{ + ASSERT(m_Impl); - m_Impl->Unlock(); - } + m_Impl->Unlock(); +} #if ASURA_MUTEX_WIN32_CRITICLE_SECTION - MutexImplWin32_CS::MutexImplWin32_CS() - { - ::InitializeCriticalSection(&m_Mutex); - } +MutexImplWin32_CS::MutexImplWin32_CS() +{ + ::InitializeCriticalSection(&m_Mutex); +} - MutexImplWin32_CS::~MutexImplWin32_CS() - { - ::DeleteCriticalSection(&m_Mutex); - } +MutexImplWin32_CS::~MutexImplWin32_CS() +{ + ::DeleteCriticalSection(&m_Mutex); +} - void MutexImplWin32_CS::Lock() - { - ::EnterCriticalSection(&m_Mutex); - } +void MutexImplWin32_CS::Lock() +{ + ::EnterCriticalSection(&m_Mutex); +} - void MutexImplWin32_CS::Unlock() - { - ::LeaveCriticalSection(&m_Mutex); - } +void MutexImplWin32_CS::Unlock() +{ + ::LeaveCriticalSection(&m_Mutex); +} #endif // ASURA_MUTEX_WIN32_CRITICLE_SECTION #if ASURA_MUTEX_WIN32_KERNAL_MUTEX - MutexImplWin32_KM::MutexImplWin32_KM() - { - m_Handle = ::CreateMutex(NULL, FALSE, NULL); - if (!m_Handle) - throw Exception("Cant use win32 mutex."); - } - - MutexImplWin32_KM::~MutexImplWin32_KM() - { - ::CloseHandle(m_Handle); - m_Handle = NULL; - } - - void MutexImplWin32_KM::Lock() - { - ::WaitForSingleObject(m_Handle, ASURA_MUTEX_MAXWAIT); - } - - void MutexImplWin32_KM::Unlock() - { - ::ReleaseMutex(m_Handle); - } +MutexImplWin32_KM::MutexImplWin32_KM() +{ + m_Handle = ::CreateMutex(NULL, FALSE, NULL); + if (!m_Handle) + throw Exception("Cant use win32 mutex."); +} + +MutexImplWin32_KM::~MutexImplWin32_KM() +{ + ::CloseHandle(m_Handle); + m_Handle = NULL; +} + +void MutexImplWin32_KM::Lock() +{ + ::WaitForSingleObject(m_Handle, ASURA_MUTEX_MAXWAIT); +} + +void MutexImplWin32_KM::Unlock() +{ + ::ReleaseMutex(m_Handle); +} #endif // ASURA_MUTEX_WIN32_KERNAL_MUTEX - } -}
\ No newline at end of file +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/mutex.h b/source/modules/asura-utils/threading/mutex.h index 9e9d2c2..623a3db 100644 --- a/source/modules/asura-utils/threading/mutex.h +++ b/source/modules/asura-utils/threading/mutex.h @@ -2,127 +2,126 @@ #define __ASURA_MUTEX_H__ #include <asura-utils/type.h> +#include <asura-utils/classes.h> #include "../utils_config.h" #if ASURA_THREAD_WIN32 - #include <windows.h> +#include <windows.h> #endif -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) #define ASURA_MUTEX_MAXWAIT (~(uint32)0) - class MutexImpl; +class MutexImpl; - class Mutex - { - public: +class Mutex +{ +public: - Mutex(); - ~Mutex(); + Mutex(); + ~Mutex(); - void Lock(); - void Unlock(); + void Lock(); + void Unlock(); - private: +private: - // ֹ - Mutex(const Mutex&); - Mutex& operator=(const Mutex&); + // ֹ + Mutex(const Mutex&); + Mutex& operator=(const Mutex&); - MutexImpl* m_Impl; + MutexImpl* m_Impl; - }; +}; - class _mutex_locker - { - public: - _mutex_locker(Mutex& mutex) - : m(mutex) - { - m.Lock(); - }; - ~_mutex_locker() - { - m.Unlock(); - } - operator bool() { return false; }; - private: - void* operator new(size_t); - Mutex& m; - }; +class _mutex_locker +{ +public: + _mutex_locker(Mutex& mutex) + : m(mutex) + { + m.Lock(); + }; + ~_mutex_locker() + { + m.Unlock(); + } + operator bool() { return false; }; +private: + void* operator new(size_t); + Mutex& m; +}; #define lock(m) \ - if(_mutex_locker _asura_mutex_locker = m){} else +if(_mutex_locker _asura_mutex_locker = m){} else - ASURA_ABSTRACT class MutexImpl - { - public: +ASURA_ABSTRACT class MutexImpl +{ +public: - MutexImpl() {}; - virtual ~MutexImpl() {}; + MutexImpl() {}; + virtual ~MutexImpl() {}; - virtual void Lock() = 0; - virtual void Unlock() = 0; + virtual void Lock() = 0; + virtual void Unlock() = 0; - }; +}; #if ASURA_MUTEX_WIN32_CRITICLE_SECTION - //https://blog.csdn.net/l799623787/article/details/18259949 - class MutexImplWin32_CS ASURA_FINAL : public MutexImpl - { - public: +//https://blog.csdn.net/l799623787/article/details/18259949 +class MutexImplWin32_CS ASURA_FINAL : public MutexImpl +{ +public: - MutexImplWin32_CS(); - ~MutexImplWin32_CS(); + MutexImplWin32_CS(); + ~MutexImplWin32_CS(); - void Lock() override; - void Unlock() override; + void Lock() override; + void Unlock() override; - private: +private: - //HANDLE m_Handle; - CRITICAL_SECTION m_Mutex; + //HANDLE m_Handle; + CRITICAL_SECTION m_Mutex; - }; +}; #endif // ASURA_MUTEX_WIN32_CRITICLE_SECTION #if ASURA_MUTEX_WIN32_KERNAL_MUTEX - class MutexImplWin32_KM ASURA_FINAL : public MutexImpl - { - public: +class MutexImplWin32_KM ASURA_FINAL : public MutexImpl +{ +public: - MutexImplWin32_KM(); - ~MutexImplWin32_KM(); + MutexImplWin32_KM(); + ~MutexImplWin32_KM(); - void Lock() override; - void Unlock() override; + void Lock() override; + void Unlock() override; - private: +private: - HANDLE m_Handle; + HANDLE m_Handle; - }; +}; #endif // ASURA_MUTEX_WIN32_KERNAL_MUTEX #if ASURA_THREAD_STD - class MutexImplSTD ASURA_FINAL : public MutexImpl - { - }; +class MutexImplSTD ASURA_FINAL : public MutexImpl +{ +}; #endif // ASURA_THREAD_STD - } -} +namespace_end +namespace_end namespace AEThreading = AsuraEngine::Threading; diff --git a/source/modules/asura-utils/threading/semaphore.cpp b/source/modules/asura-utils/threading/semaphore.cpp index 7e5ccf5..f9ffb35 100644 --- a/source/modules/asura-utils/threading/semaphore.cpp +++ b/source/modules/asura-utils/threading/semaphore.cpp @@ -4,98 +4,96 @@ #include "mutex.h" #include "semaphore.h" -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) #define try_create_semaphore(impl) \ - if (!m_Impl) \ - { \ - try \ - { \ - m_Impl = new impl(init_count); \ - } \ - catch (Exception& e) \ - { \ - m_Impl = nullptr; \ - } \ - } +if (!m_Impl) \ +{ \ + try \ + { \ + m_Impl = new impl(init_count); \ + } \ + catch (Exception& e) \ + { \ + m_Impl = nullptr; \ + } \ +} - Semaphore::Semaphore(unsigned int init_count) - : m_Impl(nullptr) - { +Semaphore::Semaphore(unsigned int init_count) + : m_Impl(nullptr) +{ #ifdef ASURA_THREAD_WIN32 - try_create_semaphore(SemaphoreWin32); + try_create_semaphore(SemaphoreWin32); #endif - //ASSERT(m_Impl); - } + //ASSERT(m_Impl); +} - Semaphore::~Semaphore() - { - if (m_Impl) delete m_Impl; - } +Semaphore::~Semaphore() +{ + if (m_Impl) delete m_Impl; +} - void Semaphore::Signal() - { - ASSERT(m_Impl); - m_Impl->Signal(); - } +void Semaphore::Signal() +{ + ASSERT(m_Impl); + m_Impl->Signal(); +} - bool Semaphore::Wait(int timeout /*= ASURA_MUTEX_MAXWAIT*/) - { - ASSERT(m_Impl); - return m_Impl->Wait(timeout); - } +bool Semaphore::Wait(int timeout /*= ASURA_MUTEX_MAXWAIT*/) +{ + ASSERT(m_Impl); + return m_Impl->Wait(timeout); +} #if ASURA_THREAD_WIN32 - SemaphoreWin32::SemaphoreWin32(unsigned int init_value) - : SemaphoreImpl(init_value) - { - // UINT_MAX get error. - m_Sem = CreateSemaphore(NULL, init_value, INT_MAX, NULL); - if (!m_Sem) - { - int errorCode = GetLastError(); - throw Exception("Cant use win32 semaphore. Error code: %d.", errorCode); - } - } +SemaphoreWin32::SemaphoreWin32(unsigned int init_value) + : SemaphoreImpl(init_value) +{ + // UINT_MAX get error. + m_Sem = CreateSemaphore(NULL, init_value, INT_MAX, NULL); + if (!m_Sem) + { + int errorCode = GetLastError(); + throw Exception("Cant use win32 semaphore. Error code: %d.", errorCode); + } +} - SemaphoreWin32::~SemaphoreWin32() - { - CloseHandle(m_Sem); - } +SemaphoreWin32::~SemaphoreWin32() +{ + CloseHandle(m_Sem); +} - void SemaphoreWin32::Signal() - { - InterlockedIncrement(&m_Count); - if (ReleaseSemaphore(m_Sem, 1, NULL) == FALSE) - InterlockedDecrement(&m_Count); - } +void SemaphoreWin32::Signal() +{ + InterlockedIncrement(&m_Count); + if (ReleaseSemaphore(m_Sem, 1, NULL) == FALSE) + InterlockedDecrement(&m_Count); +} - bool SemaphoreWin32::Wait(int timeout) - { - int result; - result = WaitForSingleObject(m_Sem, timeout); - if (result == WAIT_OBJECT_0) - { - InterlockedDecrement(&m_Count); - return true; - } - else if(result == WAIT_TIMEOUT) - { - // ʱ - return false; - } - else - { - // δ֪ - throw Exception("WaitForSingleObject() failed"); - } - } +bool SemaphoreWin32::Wait(int timeout) +{ + int result; + result = WaitForSingleObject(m_Sem, timeout); + if (result == WAIT_OBJECT_0) + { + InterlockedDecrement(&m_Count); + return true; + } + else if(result == WAIT_TIMEOUT) + { + // ʱ + return false; + } + else + { + // δ֪ + throw Exception("WaitForSingleObject() failed"); + } +} #endif // ASURA_THREAD_WIN32 - } -}
\ No newline at end of file +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/semaphore.h b/source/modules/asura-utils/threading/semaphore.h index c75ae8a..ae7b10b 100644 --- a/source/modules/asura-utils/threading/semaphore.h +++ b/source/modules/asura-utils/threading/semaphore.h @@ -7,64 +7,62 @@ #include <windows.h> #endif -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - class SemaphoreImpl; +class SemaphoreImpl; - /// - /// ź - /// - class Semaphore - { - public: +/// +/// ź +/// +class Semaphore +{ +public: - Semaphore(unsigned int init_count = 1); - ~Semaphore(); + Semaphore(unsigned int init_count = 1); + ~Semaphore(); - void Signal(); - bool Wait(int timeout = ASURA_MUTEX_MAXWAIT); + void Signal(); + bool Wait(int timeout = ASURA_MUTEX_MAXWAIT); - private: - SemaphoreImpl* m_Impl; - }; +private: + SemaphoreImpl* m_Impl; +}; - class SemaphoreImpl - { - public: - SemaphoreImpl(unsigned int init_value) - : m_Count(init_value) - { - }; - virtual ~SemaphoreImpl() {}; - virtual void Signal() = 0; - virtual bool Wait(int timeout) = 0; - inline int Current() { return m_Count; } - protected: - unsigned int m_Count; - }; +class SemaphoreImpl +{ +public: + SemaphoreImpl(unsigned int init_value) + : m_Count(init_value) + { + }; + virtual ~SemaphoreImpl() {}; + virtual void Signal() = 0; + virtual bool Wait(int timeout) = 0; + inline int Current() { return m_Count; } +protected: + unsigned int m_Count; +}; #define wait(sem, ...) sem.Wait(__VA_ARGS__) #define signal(sem) sem.Signal() #if ASURA_THREAD_WIN32 - class SemaphoreWin32 : public SemaphoreImpl - { - public: - SemaphoreWin32(unsigned int init_value); - ~SemaphoreWin32(); - void Signal() override; - bool Wait(int timeout) override; - private: - HANDLE m_Sem; - }; +class SemaphoreWin32 : public SemaphoreImpl +{ +public: + SemaphoreWin32(unsigned int init_value); + ~SemaphoreWin32(); + void Signal() override; + bool Wait(int timeout) override; +private: + HANDLE m_Sem; +}; #endif // ASURA_THREAD_WIN32 - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/task.cpp b/source/modules/asura-utils/threading/task.cpp index decb74c..ea3f68e 100644 --- a/source/modules/asura-utils/threading/task.cpp +++ b/source/modules/asura-utils/threading/task.cpp @@ -3,10 +3,8 @@ using namespace AEScripting; -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - } -} +namespace_end +namespace_end diff --git a/source/modules/asura-utils/threading/task.h b/source/modules/asura-utils/threading/task.h index 6461fff..b959012 100644 --- a/source/modules/asura-utils/threading/task.h +++ b/source/modules/asura-utils/threading/task.h @@ -3,41 +3,40 @@ #include <asura-utils/type.h> #include <asura-utils/scripting/portable.hpp> +#include <asura-utils/classes.h> -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - /// - /// ϣһ̴̳߳TaskдExecute - /// - ASURA_ABSTRACT class Task : public AEScripting::Object - { - public: +/// +/// ϣһ̴̳߳TaskдExecute +/// +ASURA_ABSTRACT class Task : public AEScripting::Object +{ +public: - Task() {}; - virtual ~Task() {}; + Task() {}; + virtual ~Task() {}; - /// - /// ִɺtrueûص - /// - virtual bool Execute() = 0; + /// + /// ִɺtrueûص + /// + virtual bool Execute() = 0; - /// - /// ûصinvoke threadص - /// - virtual void Invoke(lua_State* invokeThreaad) = 0; + /// + /// ûصinvoke threadص + /// + virtual void Invoke(lua_State* invokeThreaad) = 0; - protected: +protected: - // ȡص - Luax::LuaxMemberRef m_Callback; + // ȡص + Luax::LuaxMemberRef m_Callback; - }; +}; - } -} +namespace_end +namespace_end namespace AEThreading = AsuraEngine::Threading; diff --git a/source/modules/asura-utils/threading/thread.cpp b/source/modules/asura-utils/threading/thread.cpp index 48f287f..cb71d32 100644 --- a/source/modules/asura-utils/threading/thread.cpp +++ b/source/modules/asura-utils/threading/thread.cpp @@ -5,285 +5,283 @@ #include "thread_impl_sdl.h" #include "thread_impl_std.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Threading) + +Thread::Thread(lua_State* luaThread, ThreadType type /*= THREAD_TYPE_DEFERRED*/, uint sleepTime /*= 0*/, const std::string& name /*= ""*/) + : m_Name(name) + , m_State(THREAD_STATE_IDLE) + , m_Type(type) + , m_LuaThread(luaThread) + , m_CallbackThread(nullptr) + , m_SleepTime(sleepTime) { - namespace Threading + LUAX_STATE(luaThread); + if (type == THREAD_TYPE_IMMEDIATE) { + Luax::LuaxVM* vm = state.GetVM(); + ASSERT(vm); + m_CallbackThread = vm->CreateThread(); + ASSERT(m_CallbackThread); + SetLuaxMemberRef(state, m_CallbackThreadRef, -1); + state.Pop(); // callback thread + } +} - Thread::Thread(lua_State* luaThread, ThreadType type /*= THREAD_TYPE_DEFERRED*/, uint sleepTime /*= 0*/, const std::string& name /*= ""*/) - : m_Name(name) - , m_State(THREAD_STATE_IDLE) - , m_Type(type) - , m_LuaThread(luaThread) - , m_CallbackThread(nullptr) - , m_SleepTime(sleepTime) - { - LUAX_STATE(luaThread); - if (type == THREAD_TYPE_IMMEDIATE) - { - Luax::LuaxVM* vm = state.GetVM(); - ASSERT(vm); - m_CallbackThread = vm->CreateThread(); - ASSERT(m_CallbackThread); - SetLuaxMemberRef(state, m_CallbackThreadRef, -1); - state.Pop(); // callback thread - } - } - - Thread::~Thread() - { - if (m_Impl) - { - delete m_Impl; - m_Impl = nullptr; - } - } +Thread::~Thread() +{ + if (m_Impl) + { + delete m_Impl; + m_Impl = nullptr; + } +} - bool Thread::AddTask(Task* task) - { - lock(m_TaskQueueMutex) - { - task->Retain(); - m_TaskQueue.push(task); - } - return true; - } +bool Thread::AddTask(Task* task) +{ + lock(m_TaskQueueMutex) + { + task->Retain(); + m_TaskQueue.push(task); + } + return true; +} - uint Thread::GetTaskCount() - { - return m_TaskQueue.size(); - } +uint Thread::GetTaskCount() +{ + return m_TaskQueue.size(); +} - void Thread::Idle() - { - m_State = THREAD_STATE_IDLE; - } +void Thread::Idle() +{ + m_State = THREAD_STATE_IDLE; +} #define try_start_thread(impl)\ - if (!m_Impl) \ - { \ - m_Impl = new impl(); \ - if (!m_Impl->Start(this, stacksize)) \ - { \ - delete m_Impl; \ - m_Impl = nullptr; \ - } \ - } - - bool Thread::Start(bool isDaemon /*= true*/, uint32 stacksize /*= 0*/) - { - if (m_State != THREAD_STATE_IDLE) - return false; +if (!m_Impl) \ +{ \ +m_Impl = new impl(); \ +if (!m_Impl->Start(this, stacksize)) \ +{ \ + delete m_Impl; \ + m_Impl = nullptr; \ +} \ +} + +bool Thread::Start(bool isDaemon /*= true*/, uint32 stacksize /*= 0*/) +{ + if (m_State != THREAD_STATE_IDLE) + return false; - // Ѿһ֮ǰģر - if (m_Impl) - { - delete m_Impl; - m_Impl = nullptr; - } + // Ѿһ֮ǰģر + if (m_Impl) + { + delete m_Impl; + m_Impl = nullptr; + } #if ASURA_THREAD_WIN32 - try_start_thread(ThreadImplWin32); + try_start_thread(ThreadImplWin32); #endif - if (!m_Impl) - return false; + if (!m_Impl) + return false; - m_IsDaemon = isDaemon; - m_StateMutex.Lock(); - m_State = THREAD_STATE_RUNNING; - m_StateMutex.Unlock(); - } + m_IsDaemon = isDaemon; + m_StateMutex.Lock(); + m_State = THREAD_STATE_RUNNING; + m_StateMutex.Unlock(); +} - void Thread::Pause() - { - ASSERT(m_Impl); +void Thread::Pause() +{ + ASSERT(m_Impl); - lock(m_StateMutex) - { - m_State = THREAD_STATE_PAUSED; - } - } + lock(m_StateMutex) + { + m_State = THREAD_STATE_PAUSED; + } +} - void Thread::Resume() - { - ASSERT(m_Impl); +void Thread::Resume() +{ + ASSERT(m_Impl); - lock(m_StateMutex) - { - if (m_State == THREAD_STATE_PAUSED) - m_State = THREAD_STATE_RUNNING; - } - } + lock(m_StateMutex) + { + if (m_State == THREAD_STATE_PAUSED) + m_State = THREAD_STATE_RUNNING; + } +} - void Thread::Stop() - { - ASSERT(m_Impl); +void Thread::Stop() +{ + ASSERT(m_Impl); - lock(m_StateMutex) - { - m_State = THREAD_STATE_STOPPED; - } - } + lock(m_StateMutex) + { + m_State = THREAD_STATE_STOPPED; + } +} - void Thread::PauseSync() - { - Pause(); - wait(m_SemPause); - } +void Thread::PauseSync() +{ + Pause(); + wait(m_SemPause); +} - void Thread::ResumeSync() - { - Resume(); - wait(m_SemResume); - } +void Thread::ResumeSync() +{ + Resume(); + wait(m_SemResume); +} - void Thread::StopSync() - { - Stop(); - wait(m_SemStop); - } +void Thread::StopSync() +{ + Stop(); + wait(m_SemStop); +} - void Thread::Join() - { - ASSERT(m_Impl); - m_Impl->Join(); - } +void Thread::Join() +{ + ASSERT(m_Impl); + m_Impl->Join(); +} - ThreadState Thread::GetState() - { - ThreadState state; - lock(m_StateMutex) - { - state = m_State; - } - return state; - } +ThreadState Thread::GetState() +{ + ThreadState state; + lock(m_StateMutex) + { + state = m_State; + } + return state; +} - bool Thread::IsRunning() - { - ASSERT(m_Impl); +bool Thread::IsRunning() +{ + ASSERT(m_Impl); - return GetState() == THREAD_STATE_RUNNING; - } + return GetState() == THREAD_STATE_RUNNING; +} - bool Thread::IsPaused() - { - ASSERT(m_Impl); +bool Thread::IsPaused() +{ + ASSERT(m_Impl); - return GetState() == THREAD_STATE_PAUSED; - } + return GetState() == THREAD_STATE_PAUSED; +} - bool Thread::IsStopped() - { - ASSERT(m_Impl); +bool Thread::IsStopped() +{ + ASSERT(m_Impl); - return GetState() == THREAD_STATE_STOPPED; - } + return GetState() == THREAD_STATE_STOPPED; +} - bool Thread::IsCurrent() - { - ASSERT(m_Impl); +bool Thread::IsCurrent() +{ + ASSERT(m_Impl); - return m_Impl->IsCurrent(); - } + return m_Impl->IsCurrent(); +} - const std::string& Thread::GetName() - { - return m_Name; - } +const std::string& Thread::GetName() +{ + return m_Name; +} - int Thread::Process() - { - LUAX_STATE(m_LuaThread); +int Thread::Process() +{ + LUAX_STATE(m_LuaThread); - do{ - if (IsRunning()) + do{ + if (IsRunning()) + { + while (!m_TaskQueue.empty()) + { + Task* task = m_TaskQueue.front(); + if (task && task->Execute()) { - while (!m_TaskQueue.empty()) + if (m_Type == THREAD_TYPE_DEFERRED) + { + m_FinishedMutex.Lock(); + task->Retain(); + m_FinishedTasks.push(task); + m_FinishedMutex.Unlock(); + } + else if (m_Type == THREAD_TYPE_IMMEDIATE) { - Task* task = m_TaskQueue.front(); - if (task && task->Execute()) - { - if (m_Type == THREAD_TYPE_DEFERRED) - { - m_FinishedMutex.Lock(); - task->Retain(); - m_FinishedTasks.push(task); - m_FinishedMutex.Unlock(); - } - else if (m_Type == THREAD_TYPE_IMMEDIATE) - { - // unsafe - task->Invoke(m_CallbackThread); - this->LuaxRelease<Task>(state, task); - } - m_TaskQueueMutex.Lock(); - m_TaskQueue.pop(); - task->Release(); - m_TaskQueueMutex.Unlock(); - } + // unsafe + task->Invoke(m_CallbackThread); + this->LuaxRelease<Task>(state, task); } + m_TaskQueueMutex.Lock(); + m_TaskQueue.pop(); + task->Release(); + m_TaskQueueMutex.Unlock(); } + } + } - // ˳ѭ - if (IsStopped()) - break; - - // CPUʹ - Sleep(m_SleepTime); - - } while (m_IsDaemon); + // ˳ѭ + if (IsStopped()) + break; - // ػ̣߳еstop״̬ - if (!m_IsDaemon) - Stop(); + // CPUʹ + Sleep(m_SleepTime); - signal(m_SemStop); + } while (m_IsDaemon); - // ״̬ΪIdle - Idle(); + // ػ̣߳еstop״̬ + if (!m_IsDaemon) + Stop(); - return 0; - } + signal(m_SemStop); - /// - /// ӳģʽص - /// - void Thread::Dispatch() - { - if (m_Type != THREAD_TYPE_DEFERRED) - return; + // ״̬ΪIdle + Idle(); - LUAX_STATE(m_LuaThread); - while (!m_FinishedTasks.empty()) - { - Task* task = m_FinishedTasks.front(); - if (task) - { - task->Invoke(m_LuaThread); - this->LuaxRelease<Task>(state, task); - m_FinishedMutex.Lock(); - m_FinishedTasks.pop(); - task->Release(); - m_FinishedMutex.Unlock(); - } - } - } + return 0; +} - void Thread::Sleep(uint ms) - { - ASSERT(m_Impl); - if (m_Impl) - { - m_Impl->Sleep(ms); - } - } +/// +/// ӳģʽص +/// +void Thread::Dispatch() +{ + if (m_Type != THREAD_TYPE_DEFERRED) + return; - void Thread::SetSleepTime(uint ms) + LUAX_STATE(m_LuaThread); + while (!m_FinishedTasks.empty()) + { + Task* task = m_FinishedTasks.front(); + if (task) { - m_SleepTime = ms; + task->Invoke(m_LuaThread); + this->LuaxRelease<Task>(state, task); + m_FinishedMutex.Lock(); + m_FinishedTasks.pop(); + task->Release(); + m_FinishedMutex.Unlock(); } + } +} +void Thread::Sleep(uint ms) +{ + ASSERT(m_Impl); + if (m_Impl) + { + m_Impl->Sleep(ms); } -}
\ No newline at end of file +} + +void Thread::SetSleepTime(uint ms) +{ + m_SleepTime = ms; +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/thread.h b/source/modules/asura-utils/threading/thread.h index 1de4e33..0235b6a 100644 --- a/source/modules/asura-utils/threading/thread.h +++ b/source/modules/asura-utils/threading/thread.h @@ -11,214 +11,212 @@ #include "semaphore.h" #include "threadable.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Threading) + +class ThreadImpl; + +/// +/// ̵߳ļֲͬʵ֣ +/// 1: Deferredӳģʽ߳ϵɺҪ̵ֶ߳Dispatch +/// ̵߳ص첽Ϊͬlua_Stateͻ⡣ +/// 2: Immediateģʽÿһ߳άһlua_newthreadlua_State +/// صڲͬlua_Stateеãⲻ̷ͬ߳ͬһlua_State +/// +enum ThreadType { - namespace Threading - { - - class ThreadImpl; - - /// - /// ̵߳ļֲͬʵ֣ - /// 1: Deferredӳģʽ߳ϵɺҪ̵ֶ߳Dispatch - /// ̵߳ص첽Ϊͬlua_Stateͻ⡣ - /// 2: Immediateģʽÿһ߳άһlua_newthreadlua_State - /// صڲͬlua_Stateеãⲻ̷ͬ߳ͬһlua_State - /// - enum ThreadType - { - THREAD_TYPE_DEFERRED, - THREAD_TYPE_IMMEDIATE, // unsafe - }; - - enum ThreadState - { - THREAD_STATE_IDLE, ///< ãδں˶ - THREAD_STATE_RUNNING, ///< ѭ - THREAD_STATE_PAUSED, ///< ѭͣ - THREAD_STATE_STOPPED, ///< ˳ѭ - }; - - /// - /// ߳壬ÿ߳άһtask queue - /// - class Thread ASURA_FINAL - : public AEScripting::Portable<Thread> - , public Threadable - { - public: - - LUAX_DECL_FACTORY(Thread); - - Thread(lua_State* luaThread, ThreadType type = THREAD_TYPE_DEFERRED, uint sleepTime = 1, const std::string& name = ""); - ~Thread(); - - bool AddTask(Task* task); - /// - /// õȴ - /// - uint GetTaskCount(); - - void Idle(); - - /// - /// ں˶Сdaemonȴֶstopijʱ̶ɺԶstop - /// - bool Start(bool daemon = true, uint32 stacksize = 0); - - /// - /// ͬ߳̿ƣʵʱġҪ߳ʹIsȷϵָ״̬ - /// - void Pause(); - void Resume(); - void Stop(); - - /// - /// ͬ߳̿ƣȷźźִС̵߳ȴ - /// - void PauseSync(); - void ResumeSync(); - void StopSync(); - - /// - /// ̵߳ȴ߳̽żִС - /// - void Join(); - - ThreadState GetState(); - - /// - /// ߳״̬ - /// 1: IdleУ̴߳Ĭ״̬ʱStart - /// 2: RunningУں˶´Ѿں˵УTask - /// 3: PausedͣȻںУ˶Ĵͣ - /// 4: StoppedֹͣȻںУѾ - /// - bool IsIdle(); - bool IsRunning(); - bool IsPaused(); - bool IsStopped(); - - bool IsCurrent(); - - /// - /// ִС - /// - int Process() override; - - const std::string& GetName(); - - /// - /// ص - /// - void Dispatch(); - - /// - /// ߺ - /// - void Sleep(uint ms); - - /// - /// ʱ - /// - void SetSleepTime(uint ms); - - private: - - //----------------------------------------------------------------------------// - - LUAX_DECL_ENUM(ThreadType); - LUAX_DECL_ENUM(ThreadState); - - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_AddTask); - LUAX_DECL_METHOD(_Start); - LUAX_DECL_METHOD(_Idle); - LUAX_DECL_METHOD(_Pause); - LUAX_DECL_METHOD(_Resume); - LUAX_DECL_METHOD(_Stop); - LUAX_DECL_METHOD(_Join); - LUAX_DECL_METHOD(_IsRunning); - LUAX_DECL_METHOD(_IsPaused); - LUAX_DECL_METHOD(_IsStopped); - LUAX_DECL_METHOD(_IsCurrent); - LUAX_DECL_METHOD(_Sleep); - LUAX_DECL_METHOD(_Dispatch); - LUAX_DECL_METHOD(_GetName); - LUAX_DECL_METHOD(_GetType); - LUAX_DECL_METHOD(_GetState); - LUAX_DECL_METHOD(_SetSleepTime); - - //----------------------------------------------------------------------------// - - ThreadImpl* m_Impl; - - lua_State* m_LuaThread; - - /// - /// ˴Ƿػģʽ - /// - bool m_IsDaemon; - - std::string m_Name; - ThreadType m_Type; - uint m_SleepTime; - - ThreadState m_State; - Mutex m_StateMutex; - - /// - /// ͬصź - /// - Semaphore m_SemPause; - Semaphore m_SemResume; - Semaphore m_SemStop; - - /// - /// С - /// - std::queue<Task*> m_TaskQueue; - Mutex m_TaskQueueMutex; - - /// - /// ӳģʽʹ - /// - std::queue<Task*> m_FinishedTasks; - Mutex m_FinishedMutex; - - /// - /// ģʽʹãصʹõlua߳ - /// - lua_State* m_CallbackThread; - Luax::LuaxMemberRef m_CallbackThreadRef; - - }; - - /// - /// ̵߳ľʵ֣ûģһֲԣ - /// 1: win32 - /// 2: posix - /// 3: SDL - /// 4: std::thread - /// - ASURA_ABSTRACT class ThreadImpl - { - public: - ThreadImpl() {}; - virtual ~ThreadImpl() {}; - - virtual bool Start(Threadable* thread, uint32 stacksize = 0) = 0; - virtual void Join() = 0; - virtual void Kill() = 0; - - virtual void Sleep(uint ms) = 0; - - virtual bool IsRunning() = 0; - virtual bool IsCurrent() = 0; - - }; - - } -} + THREAD_TYPE_DEFERRED, + THREAD_TYPE_IMMEDIATE, // unsafe +}; + +enum ThreadState +{ + THREAD_STATE_IDLE, ///< ãδں˶ + THREAD_STATE_RUNNING, ///< ѭ + THREAD_STATE_PAUSED, ///< ѭͣ + THREAD_STATE_STOPPED, ///< ˳ѭ +}; + +/// +/// ߳壬ÿ߳άһtask queue +/// +class Thread ASURA_FINAL + : public AEScripting::Portable<Thread> + , public Threadable +{ +public: + + LUAX_DECL_FACTORY(Thread); + + Thread(lua_State* luaThread, ThreadType type = THREAD_TYPE_DEFERRED, uint sleepTime = 1, const std::string& name = ""); + ~Thread(); + + bool AddTask(Task* task); + /// + /// õȴ + /// + uint GetTaskCount(); + + void Idle(); + + /// + /// ں˶Сdaemonȴֶstopijʱ̶ɺԶstop + /// + bool Start(bool daemon = true, uint32 stacksize = 0); + + /// + /// ͬ߳̿ƣʵʱġҪ߳ʹIsȷϵָ״̬ + /// + void Pause(); + void Resume(); + void Stop(); + + /// + /// ͬ߳̿ƣȷźźִС̵߳ȴ + /// + void PauseSync(); + void ResumeSync(); + void StopSync(); + + /// + /// ̵߳ȴ߳̽żִС + /// + void Join(); + + ThreadState GetState(); + + /// + /// ߳״̬ + /// 1: IdleУ̴߳Ĭ״̬ʱStart + /// 2: RunningУں˶´Ѿں˵УTask + /// 3: PausedͣȻںУ˶Ĵͣ + /// 4: StoppedֹͣȻںУѾ + /// + bool IsIdle(); + bool IsRunning(); + bool IsPaused(); + bool IsStopped(); + + bool IsCurrent(); + + /// + /// ִС + /// + int Process() override; + + const std::string& GetName(); + + /// + /// ص + /// + void Dispatch(); + + /// + /// ߺ + /// + void Sleep(uint ms); + + /// + /// ʱ + /// + void SetSleepTime(uint ms); + +private: + + //----------------------------------------------------------------------------// + + LUAX_DECL_ENUM(ThreadType); + LUAX_DECL_ENUM(ThreadState); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_AddTask); + LUAX_DECL_METHOD(_Start); + LUAX_DECL_METHOD(_Idle); + LUAX_DECL_METHOD(_Pause); + LUAX_DECL_METHOD(_Resume); + LUAX_DECL_METHOD(_Stop); + LUAX_DECL_METHOD(_Join); + LUAX_DECL_METHOD(_IsRunning); + LUAX_DECL_METHOD(_IsPaused); + LUAX_DECL_METHOD(_IsStopped); + LUAX_DECL_METHOD(_IsCurrent); + LUAX_DECL_METHOD(_Sleep); + LUAX_DECL_METHOD(_Dispatch); + LUAX_DECL_METHOD(_GetName); + LUAX_DECL_METHOD(_GetType); + LUAX_DECL_METHOD(_GetState); + LUAX_DECL_METHOD(_SetSleepTime); + + //----------------------------------------------------------------------------// + + ThreadImpl* m_Impl; + + lua_State* m_LuaThread; + + /// + /// ˴Ƿػģʽ + /// + bool m_IsDaemon; + + std::string m_Name; + ThreadType m_Type; + uint m_SleepTime; + + ThreadState m_State; + Mutex m_StateMutex; + + /// + /// ͬصź + /// + Semaphore m_SemPause; + Semaphore m_SemResume; + Semaphore m_SemStop; + + /// + /// С + /// + std::queue<Task*> m_TaskQueue; + Mutex m_TaskQueueMutex; + + /// + /// ӳģʽʹ + /// + std::queue<Task*> m_FinishedTasks; + Mutex m_FinishedMutex; + + /// + /// ģʽʹãصʹõlua߳ + /// + lua_State* m_CallbackThread; + Luax::LuaxMemberRef m_CallbackThreadRef; + +}; + +/// +/// ̵߳ľʵ֣ûģһֲԣ +/// 1: win32 +/// 2: posix +/// 3: SDL +/// 4: std::thread +/// +ASURA_ABSTRACT class ThreadImpl +{ +public: + ThreadImpl() {}; + virtual ~ThreadImpl() {}; + + virtual bool Start(Threadable* thread, uint32 stacksize = 0) = 0; + virtual void Join() = 0; + virtual void Kill() = 0; + + virtual void Sleep(uint ms) = 0; + + virtual bool IsRunning() = 0; + virtual bool IsCurrent() = 0; + +}; + +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/thread_impl_posix.cpp b/source/modules/asura-utils/threading/thread_impl_posix.cpp index d689353..d59bd8f 100644 --- a/source/modules/asura-utils/threading/thread_impl_posix.cpp +++ b/source/modules/asura-utils/threading/thread_impl_posix.cpp @@ -1,11 +1,9 @@ #include "thread_impl_posix.h" -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - } -}
\ No newline at end of file +namespace_end +namespace_end
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/thread_impl_posix.h b/source/modules/asura-utils/threading/thread_impl_posix.h index e69de29..a65a2ca 100644 --- a/source/modules/asura-utils/threading/thread_impl_posix.h +++ b/source/modules/asura-utils/threading/thread_impl_posix.h @@ -0,0 +1,2 @@ +#include <asura-utils/classes.h> + diff --git a/source/modules/asura-utils/threading/thread_impl_std.h b/source/modules/asura-utils/threading/thread_impl_std.h index 4cc5dfe..a2623ee 100644 --- a/source/modules/asura-utils/threading/thread_impl_std.h +++ b/source/modules/asura-utils/threading/thread_impl_std.h @@ -9,34 +9,32 @@ #include "thread.h" -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - /// - /// Threadstd::threadʵ֡ - /// - class ThreadImplSTD : public ThreadImpl - { - public: +/// +/// Threadstd::threadʵ֡ +/// +class ThreadImplSTD : public ThreadImpl +{ +public: - ThreadImplSTD(); - ~ThreadImplSTD(); + ThreadImplSTD(); + ~ThreadImplSTD(); - bool Start(Threadable* thread, uint32 stacksize) override; - void Join() override; - void Kill() override; + bool Start(Threadable* thread, uint32 stacksize) override; + void Join() override; + void Kill() override; - bool IsRunning() override; - bool IsCurrent() override; + bool IsRunning() override; + bool IsCurrent() override; - private: +private: - }; +}; - } -} +namespace_end +namespace_end #endif // #if ASURA_THREAD_STD diff --git a/source/modules/asura-utils/threading/thread_impl_win32.cpp b/source/modules/asura-utils/threading/thread_impl_win32.cpp index 61b1c13..c876be9 100644 --- a/source/modules/asura-utils/threading/thread_impl_win32.cpp +++ b/source/modules/asura-utils/threading/thread_impl_win32.cpp @@ -5,75 +5,73 @@ #if ASURA_THREAD_WIN32 -namespace AsuraEngine -{ - namespace Threading - { - - static DWORD WINAPI _thread_win32_runner(LPVOID param) - { - Threadable* thread = (Threadable*)param; - return thread->Process(); // β - } - - ThreadImplWin32::ThreadImplWin32() - { - } +namespace_begin(AsuraEngine) +namespace_begin(Threading) - ThreadImplWin32::~ThreadImplWin32() - { - if (!m_Handle) return; - ::CloseHandle(m_Handle); - m_Handle = 0; - } +static DWORD WINAPI _thread_win32_runner(LPVOID param) +{ + Threadable* thread = (Threadable*)param; + return thread->Process(); // β +} - bool ThreadImplWin32::Start(Threadable* thread, uint32 stacksize/*=0*/) - { - assert(!IsRunning()); - m_Handle = ::CreateThread( - NULL - , stacksize - , _thread_win32_runner - , thread - , 0 /*е*/ - , NULL); +ThreadImplWin32::ThreadImplWin32() +{ +} - return m_Handle; - } +ThreadImplWin32::~ThreadImplWin32() +{ + if (!m_Handle) return; + ::CloseHandle(m_Handle); + m_Handle = 0; +} - void ThreadImplWin32::Join() - { - // ̵߳ȴ̷߳ - ::WaitForSingleObject(m_Handle, INFINITE); - } +bool ThreadImplWin32::Start(Threadable* thread, uint32 stacksize/*=0*/) +{ + assert(!IsRunning()); + m_Handle = ::CreateThread( + NULL + , stacksize + , _thread_win32_runner + , thread + , 0 /*е*/ + , NULL); - void ThreadImplWin32::Kill() - { - ::TerminateThread(m_Handle, FALSE); - } + return m_Handle; +} - void ThreadImplWin32::Sleep(uint ms) - { - ::Sleep(ms); - } +void ThreadImplWin32::Join() +{ + // ̵߳ȴ̷߳ + ::WaitForSingleObject(m_Handle, INFINITE); +} - bool ThreadImplWin32::IsRunning() - { - if (m_Handle) { - DWORD exitCode = 0; - // https://blog.csdn.net/yuanmeng567/article/details/19485719 - ::GetExitCodeThread(m_Handle, &exitCode); - return exitCode == STILL_ACTIVE; - } - return false; - } +void ThreadImplWin32::Kill() +{ + ::TerminateThread(m_Handle, FALSE); +} - bool ThreadImplWin32::IsCurrent() - { - return m_Handle == ::GetCurrentThread(); - } +void ThreadImplWin32::Sleep(uint ms) +{ + ::Sleep(ms); +} +bool ThreadImplWin32::IsRunning() +{ + if (m_Handle) { + DWORD exitCode = 0; + // https://blog.csdn.net/yuanmeng567/article/details/19485719 + ::GetExitCodeThread(m_Handle, &exitCode); + return exitCode == STILL_ACTIVE; } + return false; } +bool ThreadImplWin32::IsCurrent() +{ + return m_Handle == ::GetCurrentThread(); +} + +namespace_end +namespace_end + #endif // ASURA_THREAD_WIN32
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/thread_impl_win32.h b/source/modules/asura-utils/threading/thread_impl_win32.h index d1b7ae5..846670b 100644 --- a/source/modules/asura-utils/threading/thread_impl_win32.h +++ b/source/modules/asura-utils/threading/thread_impl_win32.h @@ -9,39 +9,36 @@ #include "thread.h" -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - /// - /// Threadwin32ʵ֡ - /// - class ThreadImplWin32 : public ThreadImpl - { - public: +/// +/// Threadwin32ʵ֡ +/// +class ThreadImplWin32 : public ThreadImpl +{ +public: - ThreadImplWin32(); - ~ThreadImplWin32(); + ThreadImplWin32(); + ~ThreadImplWin32(); - bool Start(Threadable* thread, uint32 stacksize) override; - void Join() override; - void Kill() override; + bool Start(Threadable* thread, uint32 stacksize) override; + void Join() override; + void Kill() override; - void Sleep(uint ms) override; + void Sleep(uint ms) override; - bool IsRunning() override; - bool IsCurrent() override; + bool IsRunning() override; + bool IsCurrent() override; - private: +private: - HANDLE m_Handle; + HANDLE m_Handle; - }; +}; - } -} +namespace_end +namespace_end #endif // #if ASURA_THREAD_WIN32 - #endif // __ASURA_THREAD_WIN32_H__
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/threadable.h b/source/modules/asura-utils/threading/threadable.h index 08f807d..66973c5 100644 --- a/source/modules/asura-utils/threading/threadable.h +++ b/source/modules/asura-utils/threading/threadable.h @@ -3,23 +3,21 @@ #include "../type.h" -namespace AsuraEngine -{ - namespace Threading - { +namespace_begin(AsuraEngine) +namespace_begin(Threading) - ASURA_ABSTRACT class Threadable - { - public: +ASURA_ABSTRACT class Threadable +{ +public: - Threadable() {}; - virtual ~Threadable() {}; + Threadable() {}; + virtual ~Threadable() {}; - virtual int Process() = 0; + virtual int Process() = 0; - }; +}; - } -} +namespace_end +namespace_end #endif
\ No newline at end of file diff --git a/source/modules/asura-utils/utils_module.h b/source/modules/asura-utils/utils_module.h index e802730..479b052 100644 --- a/source/modules/asura-utils/utils_module.h +++ b/source/modules/asura-utils/utils_module.h @@ -11,6 +11,8 @@ #include "module.h" +#include "classes.h" + namespace AsuraEngine { diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp index 9467334..d34f4ed 100644 --- a/source/tests/win32/01-window/03_sub_menu.cpp +++ b/source/tests/win32/01-window/03_sub_menu.cpp @@ -26,6 +26,7 @@ void AddMenus(HWND); #define IDM_ASSET 20 HWND wnd; +HWND wnd2; AEMath::Recti viewport; @@ -61,12 +62,12 @@ void main() Shader* shader; VertexBuffer* vb; -struct +struct { - int pos; - int tex; - int m; - int v; + int pos; + int tex; + int m; + int v; int p; int color; } locs; @@ -77,22 +78,61 @@ struct Vert float s, t; // uv }; -int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow) +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow) { AEIO::Filesystem::Get()->Init("D:\Asura\bin\win64"); MSG msg; - WNDCLASSW wc = { 0 }; - wc.lpszClassName = L"Submenu"; - wc.hInstance = hInstance; - wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); - wc.lpfnWndProc = WndProc; - wc.hCursor = LoadCursor(0, IDC_ARROW); - RegisterClassW(&wc); - - wnd = CreateWindowW(wc.lpszClassName, L"Asura", - WS_OVERLAPPEDWINDOW | WS_VISIBLE, - 200, 200, 550, 450, 0, 0, hInstance, 0); + + WNDCLASSEXW wcex; + memset(&wcex, 0, sizeof(wcex)); + wcex.cbSize = sizeof(wcex); + wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = NULL; + wcex.lpszMenuName = NULL; + wcex.lpszClassName = L"Submenu"; + + RegisterClassExW(&wcex); + + //WNDCLASSW wc = { 0 }; + //wc.lpszClassName = L"Submenu"; + //wc.hInstance = hInstance; + //wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); + //wc.lpfnWndProc = WndProc; + //wc.hCursor = LoadCursor(0, IDC_ARROW); + //RegisterClassW(&wc); + + DWORD windowStyle = 0; + DWORD extendedStyle = 0; + windowStyle = WS_POPUP | WS_CLIPCHILDREN | WS_THICKFRAME | WS_VISIBLE; + extendedStyle = WS_EX_TOOLWINDOW; + //windowStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE; + + RECT rect = { 100, 100, 500, 500 }; + AdjustWindowRectEx(&rect, windowStyle, true, extendedStyle); + + wnd = CreateWindowExW(extendedStyle, wcex.lpszClassName, L"", windowStyle, + rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, + NULL, NULL, hInstance, NULL); + + // child + windowStyle = WS_POPUP | WS_CLIPCHILDREN | WS_THICKFRAME | WS_VISIBLE; + extendedStyle = WS_EX_TOOLWINDOW; + rect = { 100, 100, 500, 500 }; + AdjustWindowRectEx(&rect, windowStyle, false, extendedStyle); +/* + wnd2 = CreateWindowExW(extendedStyle, wcex.lpszClassName, L"", windowStyle, + rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, + NULL, NULL, hInstance, NULL); +*/ + //wnd = CreateWindowW(wcex.lpszClassName, L"Asura", + // WS_OVERLAPPEDWINDOW | WS_VISIBLE, + // 200, 200, 550, 450, 0, 0, hInstance, 0); while (GetMessage(&msg, NULL, 0, 0)) { @@ -126,7 +166,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, switch (msg) { - case WM_SIZE: + case WM_SIZE: { if (gfx.Inited()) { @@ -152,13 +192,13 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, tex = img->GetGLTexture(); glBindTexture(GL_TEXTURE_2D, tex); // - + // Χ - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // ˲ - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); { int imgLoc = shader->GetUniformLocation("img"); @@ -213,7 +253,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, file = new File("root/img.jpg"); file->Open(File::FILE_MODE_READ); file->ReadAll(&db); - + wglMakeCurrent(hdc, glc); RECT rect; @@ -231,14 +271,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, file2->Open(File::FILE_MODE_READ); file2->ReadAll(&db); imgdata->Decode(db); - img->Load(imgdata, {50, 100}); + img->Load(imgdata, { 50, 100 }); imgdata->Release(); // shader shader = new Shader(); shader->Load(vert, frag); { - int w = img->GetWidth(); + int w = img->GetWidth(); int h = img->GetHeight(); //Vert v[] = { // { 0.5f, 0.5f, 0, 0 }, @@ -287,12 +327,12 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, break; } - + return DefWindowProcW(hwnd, msg, wParam, lParam); } void AddMenus(HWND hwnd) { - + return; HMENU hMenubar = CreateMenu(); HMENU hMenu = CreateMenu(); HMENU hSubMenu = CreatePopupMenu(); |