From d29f5f4aebd90b1e256967801b28a5990249b2e7 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 16 Mar 2019 19:29:23 +0800 Subject: *luax --- Source/Asura.Engine/Graphics/Image.h | 3 +- Source/Asura.Engine/Scripting/Portable.cpp | 9 ------ Source/Asura.Engine/Scripting/Portable.h | 19 ------------- Source/Asura.Engine/graphics/image.h | 3 +- Source/Asura.Engine/graphics/render_state.h | 2 +- Source/Asura.Engine/scripting/portable.cpp | 9 ------ Source/Asura.Engine/scripting/portable.h | 19 ------------- Source/Asura.Engine/scripting/portable.hpp | 43 +++++++++++++++++++++++++++++ Source/Asura.Engine/scripting/portable.inl | 30 ++++++++++++++++++++ 9 files changed, 78 insertions(+), 59 deletions(-) delete mode 100644 Source/Asura.Engine/Scripting/Portable.cpp delete mode 100644 Source/Asura.Engine/Scripting/Portable.h delete mode 100644 Source/Asura.Engine/scripting/portable.cpp delete mode 100644 Source/Asura.Engine/scripting/portable.h create mode 100644 Source/Asura.Engine/scripting/portable.hpp create mode 100644 Source/Asura.Engine/scripting/portable.inl (limited to 'Source/Asura.Engine') diff --git a/Source/Asura.Engine/Graphics/Image.h b/Source/Asura.Engine/Graphics/Image.h index 2607969..916c365 100644 --- a/Source/Asura.Engine/Graphics/Image.h +++ b/Source/Asura.Engine/Graphics/Image.h @@ -2,13 +2,14 @@ #define __ASURA_ENGINE_IMAGE_H__ #include "math/vector2.hpp" -#include "scripting/portable.h" +#include "scripting/portable.hpp" #include "fileSystem/reloadable.h" #include "stringmap.hpp" #include "manager.hpp" #include "texture.h" #include "color.h" #include "image_data.h" +#include "render_state.h" namespace AsuraEngine { diff --git a/Source/Asura.Engine/Scripting/Portable.cpp b/Source/Asura.Engine/Scripting/Portable.cpp deleted file mode 100644 index 0aa5f08..0000000 --- a/Source/Asura.Engine/Scripting/Portable.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Portable.h" - -namespace AsuraEngine -{ - namespace Scripting - { - - } -} diff --git a/Source/Asura.Engine/Scripting/Portable.h b/Source/Asura.Engine/Scripting/Portable.h deleted file mode 100644 index 0527308..0000000 --- a/Source/Asura.Engine/Scripting/Portable.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __ASURA_ENGINE_PORTABLE_H__ -#define __ASURA_ENGINE_PORTABLE_H__ - -#include "Luax.hpp" -#include "Config.h" -#include "Type.h" - -namespace AsuraEngine -{ - namespace Scripting - { - - template - using Portable = Luax::LuaxClass; - - } -} - -#endif \ No newline at end of file diff --git a/Source/Asura.Engine/graphics/image.h b/Source/Asura.Engine/graphics/image.h index 2607969..916c365 100644 --- a/Source/Asura.Engine/graphics/image.h +++ b/Source/Asura.Engine/graphics/image.h @@ -2,13 +2,14 @@ #define __ASURA_ENGINE_IMAGE_H__ #include "math/vector2.hpp" -#include "scripting/portable.h" +#include "scripting/portable.hpp" #include "fileSystem/reloadable.h" #include "stringmap.hpp" #include "manager.hpp" #include "texture.h" #include "color.h" #include "image_data.h" +#include "render_state.h" namespace AsuraEngine { diff --git a/Source/Asura.Engine/graphics/render_state.h b/Source/Asura.Engine/graphics/render_state.h index f313296..a80efd3 100644 --- a/Source/Asura.Engine/graphics/render_state.h +++ b/Source/Asura.Engine/graphics/render_state.h @@ -6,7 +6,7 @@ #include "Math/Transform.h" #include "Shader.h" -#include "BlendMode.h" +#include "blend_mode.h" namespace AsuraEngine { diff --git a/Source/Asura.Engine/scripting/portable.cpp b/Source/Asura.Engine/scripting/portable.cpp deleted file mode 100644 index 0aa5f08..0000000 --- a/Source/Asura.Engine/scripting/portable.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Portable.h" - -namespace AsuraEngine -{ - namespace Scripting - { - - } -} diff --git a/Source/Asura.Engine/scripting/portable.h b/Source/Asura.Engine/scripting/portable.h deleted file mode 100644 index 0527308..0000000 --- a/Source/Asura.Engine/scripting/portable.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __ASURA_ENGINE_PORTABLE_H__ -#define __ASURA_ENGINE_PORTABLE_H__ - -#include "Luax.hpp" -#include "Config.h" -#include "Type.h" - -namespace AsuraEngine -{ - namespace Scripting - { - - template - using Portable = Luax::LuaxClass; - - } -} - -#endif \ No newline at end of file diff --git a/Source/Asura.Engine/scripting/portable.hpp b/Source/Asura.Engine/scripting/portable.hpp new file mode 100644 index 0000000..773e7ad --- /dev/null +++ b/Source/Asura.Engine/scripting/portable.hpp @@ -0,0 +1,43 @@ +#ifndef __ASURA_ENGINE_PORTABLE_H__ +#define __ASURA_ENGINE_PORTABLE_H__ + +#include "Config.h" +#include "Luax.hpp" +#include "Type.h" + +namespace AsuraEngine +{ + namespace Scripting + { + + template + class Portable : public Luax::LuaxClass + { + public: + + Portable(); + virtual ~Portable(); + + void Retain(); + void Release(); + + private: + + /// + /// 多线程保护,lua调用gc后,如果在其他线程用了此native object,不会调用delete。 + /// + int mRefCount; + + /// + /// delete保险,继承portable的类,无法使用delete,只能使用Release。 + /// + bool mSafer; + + }; + +#include "portable.inl" + + } +} + +#endif \ No newline at end of file diff --git a/Source/Asura.Engine/scripting/portable.inl b/Source/Asura.Engine/scripting/portable.inl new file mode 100644 index 0000000..a27b2e8 --- /dev/null +++ b/Source/Asura.Engine/scripting/portable.inl @@ -0,0 +1,30 @@ + +template +Portable::Portable() + : mRefCount(1) + , mSafer(false) +{ +} + +template +Portable::~Portable() +{ + ASSERT(mSafer); +} + +template +void Portable::Retain() +{ + ++mRefCount; +} + +template +void Portable::Release() +{ + if (--mRefCount <= 0) + { + mSafer = true; + delete this; + } +} + -- cgit v1.1-26-g67d0