From 72bad342ad75294ae85aac8b2e2e7bea54193c15 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 31 Mar 2019 19:59:58 +0800 Subject: *misc --- source/3rd-party/Luax/luax_class.hpp | 6 +++- source/modules/asura-core/application.cpp | 3 -- .../asura-core/graphics/binding/_color32.cpp | 27 ++------------- .../modules/asura-core/graphics/binding/_image.cpp | 2 +- source/modules/asura-core/graphics/image.h | 2 +- source/modules/asura-core/graphics/shader.h | 2 +- source/modules/asura-core/wnd/window.h | 4 +-- source/modules/asura-core/wnd/window_impl_sdl.cpp | 8 ++++- source/modules/asura-core/wnd/window_impl_sdl.h | 18 ++++++---- source/modules/asura-utils/io/reloadable.h | 33 ------------------- source/modules/asura-utils/io/renewable.h | 38 ++++++++++++++++++++++ source/modules/asura-utils/threading/mutex.h | 5 ++- 12 files changed, 73 insertions(+), 75 deletions(-) delete mode 100644 source/modules/asura-utils/io/reloadable.h create mode 100644 source/modules/asura-utils/io/renewable.h (limited to 'source') diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp index e056b75..dd9414a 100644 --- a/source/3rd-party/Luax/luax_class.hpp +++ b/source/3rd-party/Luax/luax_class.hpp @@ -84,6 +84,10 @@ namespace Luax /// 虚基类,为了实现多态。需要访问下面这些接口的外部基类需要虚继承此类,之后再派生链中就会 /// 调用对应实体的方法。注意继承此类时不能实现下面的方法,实现在LuaxNativeClass中,实现会 /// 导致二义性。 + /// + /// 依据Effective C++条款40,如果在必须使用virtual base基类情况下,应该尽可能避免向其中放 + /// 置数据成员,规避数据成员初始化造成的一些隐性问题。依据这一点,vpb基类更加接近C#和Java中 + /// 的Interface。所以,在这里把类用I开头标识这是一个接口。 /// class ILuaxNativeAccessor { @@ -105,7 +109,7 @@ namespace Luax /// 多个线程中需要确定不会误释放。 /// template - class LuaxNativeClass : public virtual ILuaxNativeAccessor + class LuaxNativeClass : virtual public ILuaxNativeAccessor { public: diff --git a/source/modules/asura-core/application.cpp b/source/modules/asura-core/application.cpp index 0a1c1ef..1ef9414 100644 --- a/source/modules/asura-core/application.cpp +++ b/source/modules/asura-core/application.cpp @@ -1,6 +1,3 @@ -#include "Sdl2/SDL.h" -#include "Exceptions/Exception.h" -#include "Scripting/Luax.hpp" #include "Application.h" using namespace Luax; diff --git a/source/modules/asura-core/graphics/binding/_color32.cpp b/source/modules/asura-core/graphics/binding/_color32.cpp index 7095866..ad7dad5 100644 --- a/source/modules/asura-core/graphics/binding/_color32.cpp +++ b/source/modules/asura-core/graphics/binding/_color32.cpp @@ -14,10 +14,7 @@ namespace AsuraEngine { "GetRed", _GetRed }, { "GetGreen", _GetGreen }, { "GetBlue", _GetBlue }, - { "GetAlpha", _GetAlpha }, - { "Multiply", _Multiply }, - { "Index", _Index }, - { "NewIndex", _NewIndex } + { "GetAlpha", _GetAlpha } ); } @@ -61,26 +58,6 @@ namespace AsuraEngine } - // color32:Multiply() - LUAX_IMPL_METHOD(Color32, _Multiply) - { - LUAX_PREPARE(L, Color32); - - } - - // color32:Index() - LUAX_IMPL_METHOD(Color32, _Index) - { - LUAX_PREPARE(L, Color32); - - } - - // color32:NewIndex() - LUAX_IMPL_METHOD(Color32, _NewIndex) - { - LUAX_PREPARE(L, Color32); - - } - } } + \ No newline at end of file diff --git a/source/modules/asura-core/graphics/binding/_image.cpp b/source/modules/asura-core/graphics/binding/_image.cpp index cc9a669..407ada7 100644 --- a/source/modules/asura-core/graphics/binding/_image.cpp +++ b/source/modules/asura-core/graphics/binding/_image.cpp @@ -54,7 +54,7 @@ namespace AsuraEngine state.Push(self->GetWidth()); return 1; } - + // height = image:GetHeight() LUAX_IMPL_METHOD(Image, _GetHeight) { diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index 06108ed..2424ebb 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h index df0fcca..ae24548 100644 --- a/source/modules/asura-core/graphics/shader.h +++ b/source/modules/asura-core/graphics/shader.h @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include diff --git a/source/modules/asura-core/wnd/window.h b/source/modules/asura-core/wnd/window.h index 1ecb934..eb8a574 100644 --- a/source/modules/asura-core/wnd/window.h +++ b/source/modules/asura-core/wnd/window.h @@ -134,8 +134,8 @@ namespace AsuraEngine virtual void SetPosition(int x, int y) = 0; virtual void SetTitils(const std::string& title) = 0; - virtual void Show(); - virtual void Hide(); + virtual void Show() = 0; + virtual void Hide() = 0; virtual void SwapRenderBuffer() = 0; diff --git a/source/modules/asura-core/wnd/window_impl_sdl.cpp b/source/modules/asura-core/wnd/window_impl_sdl.cpp index bbbef9a..e608b8b 100644 --- a/source/modules/asura-core/wnd/window_impl_sdl.cpp +++ b/source/modules/asura-core/wnd/window_impl_sdl.cpp @@ -1,3 +1,7 @@ +#include "../core_config.h" + +#if ASURA_WINDOW_SDL + #include #include @@ -138,4 +142,6 @@ namespace AsuraEngine } } -} \ No newline at end of file +} + +#endif // ASURA_WINDOW_SDL \ No newline at end of file diff --git a/source/modules/asura-core/wnd/window_impl_sdl.h b/source/modules/asura-core/wnd/window_impl_sdl.h index 03e6579..0e81c0a 100644 --- a/source/modules/asura-core/wnd/window_impl_sdl.h +++ b/source/modules/asura-core/wnd/window_impl_sdl.h @@ -1,6 +1,10 @@ #ifndef __ASURA_WINDOW_SDL_H_ #define __ASURA_WINDOW_SDL_H_ +#include "../core_config.h" + +#if ASURA_WINDOW_SDL + #include #include "window.h" @@ -17,14 +21,14 @@ namespace AsuraEngine WindowImplSDL(const WindowConfig& config); ~WindowImplSDL(); - void SetSize(uint width, uint height); - void SetPosition(int x, int y); - void SetTitils(const std::string& title); + void SetSize(uint width, uint height) override; + void SetPosition(int x, int y) override; + void SetTitils(const std::string& title) override; - void Show(); - void Hide(); + void Show() override; + void Hide() override; - void SwapRenderBuffer(); + void SwapRenderBuffer() override; private: @@ -36,4 +40,6 @@ namespace AsuraEngine } } +#endif // ASURA_WINDOW_SDL + #endif \ No newline at end of file diff --git a/source/modules/asura-utils/io/reloadable.h b/source/modules/asura-utils/io/reloadable.h deleted file mode 100644 index c3b89ac..0000000 --- a/source/modules/asura-utils/io/reloadable.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __ASURA_ENGINE_RENEWABLE_H__ -#define __ASURA_ENGINE_RENEWABLE_H__ - -#include "../scripting/portable.hpp" - -namespace AsuraEngine -{ - namespace IO - { - - /// - /// 可以重新构建的数据结构。比如图片、音频这种,从解析后数据可以直接构建,可以在编辑器内重 - /// 新构建,不会修改handle值,改变不具备破坏性,适用于不改变handle的资源。 - /// - ASURA_ABSTRACT class Renewable - { - public: - Renewable(); - virtual ~ Renewable(); - - /// - /// 继承Renewable的需要提供一个Refresh方法 - /// - virtual bool Refresh(AEIO::DecodedData* decode_data) = 0; - - }; - - } -} - -namespace AEIO = AsuraEngine::IO; - -#endif \ No newline at end of file diff --git a/source/modules/asura-utils/io/renewable.h b/source/modules/asura-utils/io/renewable.h new file mode 100644 index 0000000..769bdf6 --- /dev/null +++ b/source/modules/asura-utils/io/renewable.h @@ -0,0 +1,38 @@ +#ifndef __ASURA_ENGINE_RENEWABLE_H__ +#define __ASURA_ENGINE_RENEWABLE_H__ + +#include "../scripting/portable.hpp" + +#include "decoded_data.h" + +namespace AsuraEngine +{ + namespace IO + { + + /// + /// 可以重新构建的数据结构。比如图片、音频这种,从解析后数据可以直接构建,可以在编辑器内重 + /// 新构建,不会修改handle值,改变不具备破坏性,适用于不改变handle的资源。 + /// + ASURA_ABSTRACT class Renewable + { + public: + Renewable(); + virtual ~ Renewable(); + + /// + /// 继承Renewable的需要提供一个Refresh方法 + /// + /// 依据Effective C++条款09.应该禁止在构造函数中调用virtual方法,所以这里的Refresh + /// 被从构造函数中抽离,需要手动调用Refresh。 + /// + virtual bool Refresh(AEIO::DecodedData* decode_data) = 0; + + }; + + } +} + +namespace AEIO = AsuraEngine::IO; + +#endif \ 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 7afbe35..5d33be1 100644 --- a/source/modules/asura-utils/threading/mutex.h +++ b/source/modules/asura-utils/threading/mutex.h @@ -30,6 +30,10 @@ namespace AsuraEngine private: + // 禁止复制 + Mutex(const Mutex&); + Mutex& operator=(const Mutex&); + MutexImpl* mImpl; }; @@ -52,7 +56,6 @@ namespace AsuraEngine Mutex& m; }; -// 将所在的栈从此位置开始到退栈处作为临界区锁定。 #define lock(m) \ if(_mutex_locker _asura_mutex_locker = m){} else -- cgit v1.1-26-g67d0