summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/3rd-party/Luax/luax_class.cpp24
-rw-r--r--source/3rd-party/Luax/luax_class.hpp168
-rw-r--r--source/3rd-party/Luax/luax_class.inl196
-rw-r--r--source/3rd-party/Luax/luax_config.h6
-rw-r--r--source/3rd-party/Luax/luax_dog.cpp0
-rw-r--r--source/3rd-party/Luax/luax_dog.h33
-rw-r--r--source/3rd-party/Luax/luax_enum.cpp6
-rw-r--r--source/3rd-party/Luax/luax_enum.h4
-rw-r--r--source/3rd-party/Luax/luax_state.cpp4
-rw-r--r--source/3rd-party/Luax/luax_state.h4
-rw-r--r--source/3rd-party/Luax/luax_state.inl71
-rw-r--r--source/Asura.Editor/controls/widget.h3
-rw-r--r--source/modules/asura-box2d/physics/binding/_body.cpp1
-rw-r--r--source/modules/asura-core/graphics/gl.cpp72
-rw-r--r--source/modules/asura-core/graphics/gl.h13
-rw-r--r--source/modules/asura-core/graphics/image.h5
-rw-r--r--source/modules/asura-core/graphics/shader.cpp37
-rw-r--r--source/modules/asura-core/graphics/shader.h5
-rw-r--r--source/modules/asura-core/graphics/texture.h2
-rw-r--r--source/modules/asura-utils/io/compressor.h2
-rw-r--r--source/modules/asura-utils/io/data_buffer.h16
-rw-r--r--source/modules/asura-utils/io/file_data.cpp9
-rw-r--r--source/modules/asura-utils/io/io_task.cpp6
-rw-r--r--source/modules/asura-utils/io/io_task.h7
-rw-r--r--source/modules/asura-utils/scripting/portable.hpp10
-rw-r--r--source/modules/asura-utils/threading/task.h3
-rw-r--r--source/modules/asura-utils/threading/thread.cpp4
-rw-r--r--source/modules/asura-utils/type.h2
-rw-r--r--source/modules/asura-utils/utils_module.cpp2
-rw-r--r--source/tests/05-physfs/main.cpp2
-rw-r--r--source/tests/win32/01-window/03_sub_menu.cpp3
31 files changed, 457 insertions, 263 deletions
diff --git a/source/3rd-party/Luax/luax_class.cpp b/source/3rd-party/Luax/luax_class.cpp
index bb1609d..762f0dc 100644
--- a/source/3rd-party/Luax/luax_class.cpp
+++ b/source/3rd-party/Luax/luax_class.cpp
@@ -1,6 +1,6 @@
#include "luax_class.hpp"
-#include "luax_vm.h"
#include "luax_cfunctions.h"
+#include "luax_vm.h"
namespace Luax
{
@@ -29,30 +29,30 @@ namespace Luax
lua_setfield(L, -2, "GetClass");
// TypeOf()
- lua_pushcfunction(L, l_TypeOf);
+ lua_pushcfunction(L, _TypeOf);
lua_setfield(L, -2, "TypeOf");
// New()
lua_pushvalue(L, -1); // class table
- lua_pushcclosure(L, l_New, 1);
+ lua_pushcclosure(L, _New, 1);
lua_setfield(L, -2, "New");
// Extend()
lua_pushvalue(L, -1); // class table
- lua_pushcclosure(L, l_Extend, 1);
+ lua_pushcclosure(L, _Extend, 1);
lua_setfield(L, -2, "Extend");
lua_pushvalue(L, -1); // class table
lua_setfield(L, -2, "__index");
lua_pushstring(L, type);
- lua_pushcclosure(L, _Tostring, 1);
+ lua_pushcclosure(L, __tostring, 1);
lua_setfield(L, -2, "__tostring");
return 1;
}
- int LuaxPlainClass::_Tostring(lua_State* L)
+ int LuaxPlainClass::__tostring(lua_State* L)
{
// upvalues:
// 1: class name
@@ -75,7 +75,7 @@ namespace Luax
///
/// NewnԻȡ__init__initʼʵ
///
- int LuaxPlainClass::l_New(lua_State* L)
+ int LuaxPlainClass::_New(lua_State* L)
{
LUAX_STATE(L);
@@ -140,7 +140,7 @@ namespace Luax
return 1;
}
- int LuaxPlainClass::l_Extend(lua_State* L)
+ int LuaxPlainClass::_Extend(lua_State* L)
{
LUAX_STATE(L);
@@ -168,12 +168,12 @@ namespace Luax
// New()
lua_pushvalue(L, -1); // class table
- lua_pushcclosure(L, l_New, 1);
+ lua_pushcclosure(L, _New, 1);
lua_setfield(L, -2, "New");
// Extend()
lua_pushvalue(L, -1); // class table
- lua_pushcclosure(L, l_Extend, 1);
+ lua_pushcclosure(L, _Extend, 1);
lua_setfield(L, -2, "Extend");
// .__base
@@ -184,7 +184,7 @@ namespace Luax
lua_setfield(L, -2, "__index");
lua_pushstring(L, type);
- lua_pushcclosure(L, _Tostring, 1);
+ lua_pushcclosure(L, __tostring, 1);
lua_setfield(L, -2, "__tostring");
// classmetatableΪbaseClass
@@ -194,7 +194,7 @@ namespace Luax
return 1;
}
- int LuaxPlainClass::l_TypeOf(lua_State* L)
+ int LuaxPlainClass::_TypeOf(lua_State* L)
{
// params:
// 1: lua instance
diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp
index ba8d16a..c41adbd 100644
--- a/source/3rd-party/Luax/luax_class.hpp
+++ b/source/3rd-party/Luax/luax_class.hpp
@@ -1,27 +1,36 @@
#ifndef __LUAX_CLASS_H__
#define __LUAX_CLASS_H__
+#include "luax_config.h"
+
+#if LUAX_PROFILER
+#include <unordered_set>
+#endif
+
#include <vector>
-#include "luax_config.h"
#include "luax_ref.h"
#include "luax_memberref.h"
#include "luax_cfunctions.h"
+#include "luax_dog.h"
namespace Luax
{
+ class LuaxVM;
+
///
/// RegisterLuaxClass עķͳԱö١ȵclass table
/// LuaxGetFactoryName ùͬʱעʱעΪsingletonͨ
/// ʱ
///
#define LUAX_DECL_FACTORY(type) \
- static void RegisterLuaxClass(Luax::LuaxState&);\
- static void RegisterLuaxPostprocess(Luax::LuaxState&); \
+ friend class Luax::LuaxState; \
+ static void RegisterLuaxClass(Luax::LuaxState&); \
+ static void RegisterLuaxPostprocess(Luax::LuaxState&); \
static const char* GetLuaxFactoryName() { return #type; };\
static const char* GetLuaxClassName() { return #type; };\
- static bool IsLuaxClassSingleton() { return false; }
+ static bool IsLuaxClassSingleton() { return false; }
///
/// Ϊij󹤳ʹô˺꣬עһڣעắеãעЩ
@@ -30,21 +39,22 @@ namespace Luax
#define LUAX_DECL_ABSTRACT_FACTORY() \
static void RegisterLuaxClass(Luax::LuaxState&);\
static void RegisterLuaxPostprocess(Luax::LuaxState&)
-
+
///
/// RegisterLuaxClass עķͳԱö١ȵclass table
/// LuaxGetSingletonName õ
///
#define LUAX_DECL_SINGLETON(type) \
- static void RegisterLuaxClass(Luax::LuaxState&); \
- static void RegisterLuaxPostprocess(Luax::LuaxState&); \
+ friend class Luax::LuaxState; \
+ static void RegisterLuaxClass(Luax::LuaxState&); \
+ static void RegisterLuaxPostprocess(Luax::LuaxState&); \
static const char* GetLuaxSingletonName() { return #type; }; \
static const char* GetLuaxClassName() { return #type; }; \
- static bool IsLuaxClassSingleton() { return true; }
-
+ static bool IsLuaxClassSingleton() { return true; }
+
#define LUAX_DECL_METHOD(mtd) static int mtd(lua_State* L)
-#define LUAX_DECL_ENUM(e, under_line_index) static void _luax_decl_enum_##e()
+#define LUAX_DECL_ENUM(e, under_line_index) static void _luax_dec_enum_##e()
///
/// ʵֵĺꡣһL
@@ -58,10 +68,10 @@ namespace Luax
#define LUAX_POSTPROCESS(type) void type::RegisterLuaxPostprocess(Luax::LuaxState& state)
///
- /// עĺꡣ
+ /// עĺꡣ֮ǰÿɱ꣬ûluaclastable refûעԡ
///
-#define LUAX_REGISTER_FACTORY(state, type) state.RegisterFactory<type>()
-#define LUAX_REGISTER_SINGLETON(state, type) state.RegisterSingleton<type>()
+#define LUAX_REGISTER_FACTORY(state, param) state.RegisterFactory<param>()
+#define LUAX_REGISTER_SINGLETON(state, param) state.RegisterSingleton<param>()
#define LUAX_REGISTER_ABSTRACT_FACTORY(state, type) type::RegisterLuaxPostprocess(state)
#define LUAX_REGISTER_METHODS(state, ...) \
do{ \
@@ -89,56 +99,82 @@ namespace Luax
/// ݳԱݳԱʼɵһЩ⡣һ㣬vpbӽӽC#Java
/// InterfaceԣIͷʶһӿڡ
///
- class ILuaxNativeAccessor
+ class LuaxObject
{
public:
+ LuaxObject() {};
+ virtual ~LuaxObject() {};
///
- /// Աùʵref tableáȡ
+ /// Աùʵref tableáȡ
///
- virtual bool PushLuaxMemberRef(LuaxState& state, int refID) { assert(false); return false; };
+ virtual bool PushLuaxMemberRef(LuaxState& state, int refID) = 0;
+ virtual bool PushLuaxUserdata(LuaxState& state) = 0;
+ virtual bool PushLuaxMemberTable(LuaxState& state) = 0;
+ virtual bool PushLuaxRefTable(LuaxState& state) = 0;
- virtual bool PushLuaxUserdata(LuaxState& state) { assert(false); return false; };
- virtual bool PushLuaxMemberTable(LuaxState& state) { assert(false); return false; };
- virtual bool PushLuaxRefTable(LuaxState& state) { assert(false); return false; };
+ ///
+ /// LuaxNativeClassʵ֡
+ ///
+ virtual void Retain() = 0;
+ virtual void Release() = 0;
};
+ //class LuaxNativeClassBase
+ //{
+ //}
+
///
/// Ҫ¶luanative classҪ̳дࡣͨluaʵҪȷüȷԣ
/// ߳Ҫȷͷš
///
- template<class T>
- class LuaxNativeClass : virtual public ILuaxNativeAccessor
+ template<class TYPE, class BASE = LuaxObject>
+ class LuaxNativeClass : public BASE
{
public:
- static bool IsTypeOf(ILuaxNativeAccessor);
-
///
/// userdataΪkeyref tableuserdataһãάuserdataڡ
/// Ƚmember refʵᱻαͬʵõƵЩʵ壬
- ///luaƵĵgc⡣
+ /// luaƵĵgc⡣
///
- template<class U> void LuaxRetain(LuaxState& state, U* userdata);
+ template<class USERDATA> void LuaxRetain(LuaxState& state, USERDATA* userdata);
///
/// userdataһref tableԳԻuserdata
///
- template<class U> void LuaxRelease(LuaxState& state, U* userdata);
-
- bool PushLuaxMemberRef(LuaxState& state, int refID) override;
+ template<class USERDATA> void LuaxRelease(LuaxState& state, USERDATA* userdata);
///
/// userdata pushջûгʼmUserdataʼúԪѳʼõ
/// userdataջһáһnativeȨƽluaƵķ
///
- bool PushLuaxUserdata(LuaxState& state);
- bool PushLuaxMemberTable(LuaxState& state);
- bool PushLuaxRefTable(LuaxState& state);
+ bool PushLuaxMemberRef(LuaxState& state, int refID) override;
+ bool PushLuaxUserdata(LuaxState& state) override;
+ bool PushLuaxMemberTable(LuaxState& state) override;
+ bool PushLuaxRefTable(LuaxState& state) override;
+
+ ///
+ /// Watch dog һnativeáluaVMòṩⲿӿڡ̳д಻ֱʹ
+ /// deleteӦʹReleaseͷšһ__gcУû
+ /// nativeиͷţҪʹRelease
+ ///
+ /// nativeӿڡ
+ ///
+ void Retain() override;
+ void Release() override;
+
+#if LUAX_PROFILER
+ // Զϴʵdeleteռ
+ static void operator delete(void* pdead, size_t size);
+#endif
protected:
+ LuaxNativeClass();
+ virtual ~LuaxNativeClass();
+
///
/// Աùʵref tableáȡ
///
@@ -146,36 +182,49 @@ namespace Luax
bool PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef);
void ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef);
- LuaxNativeClass();
- virtual ~LuaxNativeClass();
-
private:
friend class LuaxState;
- static void RegisterLuaxClass(LuaxState& state);
+ static void RegisterLuaxClassShared(LuaxState& state);
static void RegisterLuaxFactoryClass(LuaxState& state);
static void RegisterLuaxSingletonClass(LuaxState& state);
static void SetLuaxClassTableRef(LuaxState& state, int idx);
-
static void PushLuaxClassTable(LuaxState& state);
-
- ///
- /// ȡַҪַֻͨڶϴʵõջϺ;̬ı
- /// ȡַ֤ü׼ȷҪãʹôݶǴݵַ
- ///
- //void* operator &();
///
/// userdataʵstate
///
void BindToLua(LuaxState& state);
+ //------------------------------------------------------------------------------//
+
+ //
+ LUAX_DECL_METHOD(__tostring);
+ LUAX_DECL_METHOD(_GetClass);
+ LUAX_DECL_METHOD(_GetClassName);
+
+ //
+ LUAX_DECL_METHOD(__gc);
+#if LUAX_ENABLE_NATIVE_EXTEND
+ LUAX_DECL_METHOD(_ExtendFactory);
+#endif
+ LUAX_DECL_METHOD(_GetRefTable);
+ LUAX_DECL_METHOD(_New);
+
+ //
+#if LUAX_ENABLE_NATIVE_EXTEND
+ LUAX_DECL_METHOD(_ExtendSingleton);
+#endif
+
+ //--------------------------------------------------------------------------------//
+
///
/// class table͵С
///
static LuaxStrongRef mClassTable;
+
///
/// ǵsingletonùϵԱ֤ᱻͨref table
/// ijԱȫڵģֱ_LUAX_STRONGREF_TABLEuserdata
@@ -183,7 +232,7 @@ namespace Luax
/// ģtable_LUAX_STRONGREF_TABLE
///
static LuaxStrongRef mSingletonRefTable;
-
+
///
/// ͨuserdataõ:
/// 1: ref table
@@ -192,27 +241,20 @@ namespace Luax
///
LuaxWeakRef mUserdata;
- //
- LUAX_DECL_METHOD( _Tostring );
- LUAX_DECL_METHOD( l_GetClass );
- LUAX_DECL_METHOD( l_GetClassName );
+ ///
+ /// ͨɾ
+ ///
+ LuaxDog mWatchDog;
- //
- LUAX_DECL_METHOD( _GC );
-#if LUAX_ENABLE_NATIVE_EXTEND
- LUAX_DECL_METHOD( l_ExtendFactory );
+#if LUAX_PROFILER
+ // йܴ˶
+ std::unordered_set<LuaxVM*> mRefVMs;
+ // գ಻ⲿʹdeleteֱɾӦʹRelease
+ bool mSafer;
#endif
- LUAX_DECL_METHOD( l_GetRefTable );
- LUAX_DECL_METHOD( l_New );
- //
-#if LUAX_ENABLE_NATIVE_EXTEND
- LUAX_DECL_METHOD( l_ExtendSingleton );
-#endif
};
- //--------------------------------------------------------------------------------//
-
#if LUAX_ENABLE_PLAIN_CLASS
///
/// lua
@@ -226,10 +268,10 @@ namespace Luax
///
static int registry(lua_State* L);
- LUAX_DECL_METHOD( _Tostring );
- LUAX_DECL_METHOD( l_Extend );
- LUAX_DECL_METHOD( l_New );
- LUAX_DECL_METHOD( l_TypeOf );
+ LUAX_DECL_METHOD(__tostring);
+ LUAX_DECL_METHOD(_Extend);
+ LUAX_DECL_METHOD(_New);
+ LUAX_DECL_METHOD(_TypeOf);
};
#endif
diff --git a/source/3rd-party/Luax/luax_class.inl b/source/3rd-party/Luax/luax_class.inl
index 45e6552..95965ff 100644
--- a/source/3rd-party/Luax/luax_class.inl
+++ b/source/3rd-party/Luax/luax_class.inl
@@ -2,17 +2,16 @@ namespace Luax
{
//--------------------------------------------------------------------------------//
- // ӿ
///
/// ԲͬͣͨGetLuaClassName࣬GetClassNameᱻǣָluax_c_getupvalue
///
- template<typename T>
- int LuaxNativeClass<T>::l_GetClassName(lua_State* L)
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_GetClassName(lua_State* L)
{
LUAX_SETUP(L, "*");
- cc8* type = T::GetLuaxClassName();
+ cc8* type = TYPE::GetLuaxClassName();
state.Push(type);
return 1;
}
@@ -22,12 +21,12 @@ namespace Luax
///
/// עṤ͵еԱ
///
- template<typename T>
- void LuaxNativeClass<T>::RegisterLuaxClass(LuaxState& state)
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::RegisterLuaxClassShared(LuaxState& state)
{
luaL_Reg regTable[] = {
- { "GetClass", l_GetClass },
- { "GetClassName", l_GetClassName },
+ { "GetClass", _GetClass },
+ { "GetClassName", _GetClassName },
{ NULL, NULL }
};
@@ -37,11 +36,11 @@ namespace Luax
///
/// ijԱעclass table
///
- template<typename T>
- void LuaxNativeClass<T>::RegisterLuaxFactoryClass(LuaxState& state)
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::RegisterLuaxFactoryClass(LuaxState& state)
{
luaL_Reg regTable[] = {
- { "GetRefTable", l_GetRefTable },
+ { "GetRefTable", _GetRefTable },
{ NULL, NULL }
};
@@ -51,8 +50,8 @@ namespace Luax
///
/// ijԱעclass table
///
- template<typename T>
- void LuaxNativeClass<T>::RegisterLuaxSingletonClass(LuaxState& state)
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::RegisterLuaxSingletonClass(LuaxState& state)
{
luaL_Reg regTable[] = {
{ NULL, NULL }
@@ -61,33 +60,70 @@ namespace Luax
state.RegisterMethods(regTable);
}
- template<typename T>
- void LuaxNativeClass<T>::PushLuaxClassTable(LuaxState& state)
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::PushLuaxClassTable(LuaxState& state)
{
assert(mClassTable);
mClassTable.PushRef(state);
}
- template<typename T>
- void LuaxNativeClass<T>::SetLuaxClassTableRef(LuaxState& state, int idx)
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::SetLuaxClassTableRef(LuaxState& state, int idx)
{
mClassTable.SetRef(state, idx);
}
- template<typename T>
- LuaxNativeClass<T>::LuaxNativeClass()
+ template<class TYPE, class BASE>
+ LuaxNativeClass<TYPE, BASE>::LuaxNativeClass()
+ : mWatchDog()
+#if LUAX_PROFILER
+ , mSafer(false)
+#endif
+ {
+ }
+
+ template<class TYPE, class BASE>
+ LuaxNativeClass<TYPE, BASE>::~LuaxNativeClass()
+ {
+ }
+
+#if LUAX_PROFILER
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::operator delete(void* pdead, size_t size)
+ {
+ if (pdead == nullptr)
+ return;
+ // ϴʵʹReleaseͷš
+ LuaxNativeClass* p = static_cast<LuaxNativeClass*>(pdead);
+ assert(p->mSafer);
+ ::operator delete(pdead, size);
+ }
+#endif
+
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::Retain()
{
+ ++mWatchDog.mNativeRef;
}
- template<typename T>
- LuaxNativeClass<T>::~LuaxNativeClass()
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::Release()
{
+ if (mWatchDog.mNativeRef > 0)
+ --mWatchDog.mNativeRef;
+ if (mWatchDog)
+ {
+#if LUAX_PROFILER
+ mSafer = true;
+#endif
+ delete this;
+ }
}
- template<typename T>
+ template<class TYPE, class BASE>
template<typename U>
- void LuaxNativeClass<T>::LuaxRetain(LuaxState& state, U* userdata)
+ void LuaxNativeClass<TYPE, BASE>::LuaxRetain(LuaxState& state, U* userdata)
{
if (PushLuaxRefTable(state))
{
@@ -103,9 +139,9 @@ namespace Luax
}
}
- template<typename T>
+ template<class TYPE, class BASE>
template<typename U>
- void LuaxNativeClass<T>::LuaxRelease(LuaxState& state, U* userdata)
+ void LuaxNativeClass<TYPE, BASE>::LuaxRelease(LuaxState& state, U* userdata)
{
if (PushLuaxRefTable(state))
{
@@ -139,10 +175,10 @@ namespace Luax
}
}
- template<typename T>
- bool LuaxNativeClass<T>::PushLuaxUserdata(LuaxState& state)
+ template<class TYPE, class BASE>
+ bool LuaxNativeClass<TYPE, BASE>::PushLuaxUserdata(LuaxState& state)
{
- assert(!T::IsLuaxClassSingleton());
+ assert(!TYPE::IsLuaxClassSingleton());
if (!mUserdata)
{
BindToLua(state);
@@ -151,8 +187,8 @@ namespace Luax
return mUserdata.PushRef(state);
}
- template<typename T>
- bool LuaxNativeClass<T>::PushLuaxMemberTable(LuaxState& state)
+ template<class TYPE, class BASE>
+ bool LuaxNativeClass<TYPE, BASE>::PushLuaxMemberTable(LuaxState& state)
{
int top = state.GetTop();
if (this->PushLuaxUserdata(state))
@@ -172,11 +208,11 @@ namespace Luax
return false;
}
- template<typename T>
- bool LuaxNativeClass<T>::PushLuaxRefTable(LuaxState& state)
+ template<class TYPE, class BASE>
+ bool LuaxNativeClass<TYPE, BASE>::PushLuaxRefTable(LuaxState& state)
{
// Singleton
- if (T::IsLuaxClassSingleton())
+ if (TYPE::IsLuaxClassSingleton())
{
if (!this->mSingletonRefTable) {
lua_newtable(state);
@@ -209,19 +245,21 @@ namespace Luax
/// member table luaʵijԱ
/// class table б͵ʵеĺ
///
- template<typename T>
- void LuaxNativeClass<T>::BindToLua(LuaxState& state)
+ /// BindToLuaֻڵһעLuaʱá
+ ///
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::BindToLua(LuaxState& state)
{
// ܰuserdata
- assert(!T::IsLuaxClassSingleton());
+ assert(!TYPE::IsLuaxClassSingleton());
assert(!mUserdata);
///
- /// userdataջעַҪתΪT*ֱthisܻᵼ¶ؼ̳еɥʧ̬
+ /// userdataջעַҪתΪTYPE*ֱthisܻᵼ¶ؼ̳еɥʧ̬
/// ֱӴthisȥڶؼ̳£òһͷ麯ġҪthis
/// תΪĵ͵ַõһ麯ͨһʵֶ̬
///
- T* p = static_cast<T*>(this);
+ TYPE* p = static_cast<TYPE*>(this);
state.PushPtrUserdata(p);
lua_newtable(state); // ref table޷luaʣC
@@ -239,10 +277,10 @@ namespace Luax
int refTable = top - 2;
// ref table ע __tostring __gc
- lua_pushcfunction(state, _Tostring);
+ lua_pushcfunction(state, __tostring);
lua_setfield(state, refTable, "__tostring");
- lua_pushcfunction(state, _GC);
+ lua_pushcfunction(state, __gc);
lua_setfield(state, refTable, "__gc");
// ref table __index __newindex Ϊ member table
@@ -260,13 +298,19 @@ namespace Luax
// һuserdataãͨPushLuaUserdatalua
mUserdata.SetRef(state, -1);
assert(mUserdata);
+
+ // һãGCʱ-1
+ ++mWatchDog.mVMRef;
+#if LUAX_PROFILER
+ mRefVMs.insert(state.GetVM());
+#endif
}
///
/// Աù
///
- template<typename T>
- void LuaxNativeClass<T>::SetLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx)
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::SetLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx)
{
ClearLuaxMemberRef(state, memRef);
if (!lua_isnil(state, idx))
@@ -281,8 +325,8 @@ namespace Luax
}
}
- template<typename T>
- bool LuaxNativeClass<T>::PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef)
+ template<class TYPE, class BASE>
+ bool LuaxNativeClass<TYPE, BASE>::PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef)
{
if (memRef)
{
@@ -301,8 +345,8 @@ namespace Luax
return false;
}
- template<typename T>
- bool LuaxNativeClass<T>::PushLuaxMemberRef(LuaxState& state, int refID)
+ template<class TYPE, class BASE>
+ bool LuaxNativeClass<TYPE, BASE>::PushLuaxMemberRef(LuaxState& state, int refID)
{
if (PushLuaxRefTable(state))
{
@@ -317,8 +361,8 @@ namespace Luax
return false;
}
- template<typename T>
- void LuaxNativeClass<T>::ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef)
+ template<class TYPE, class BASE>
+ void LuaxNativeClass<TYPE, BASE>::ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef)
{
if (memRef)
{
@@ -336,16 +380,20 @@ namespace Luax
///
/// ͷŹʵ
///
- template<typename T>
- int LuaxNativeClass<T>::_GC(lua_State* L)
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::__gc(lua_State* L)
{
+ LUAX_STATE(L);
+ TYPE* self = state.GetUserdata<TYPE>(1);
+ assert(self);
+
#if LUAX_PROFILER
- std::cout << "Luax: GC<" << T::GetLuaxClassName() << ">\n";
+ std::cout << "Luax: GC<" << TYPE::GetLuaxClassName() << ">\n";
#endif
- LUAX_SETUP(L, "U");
- T* self = state.GetUserdata<T>(1);
- delete self;
+ --self->mWatchDog.mVMRef;
+ self->LuaxNativeClass<TYPE, BASE>::Release();
+
return 0;
}
@@ -353,14 +401,14 @@ namespace Luax
/// ʽ:
/// ַ
///
- template<typename T>
- int LuaxNativeClass<T>::_Tostring(lua_State* L)
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::__tostring(lua_State* L)
{
// params:
// 1: userdata
LUAX_STATE(L);
- T* self = state.GetUserdata<T>(1);
+ TYPE* self = state.GetUserdata<TYPE>(1);
if (self)
{
cc8* classname = "";
@@ -373,7 +421,7 @@ namespace Luax
}
else
{
- classname = T::GetLuaxClassName();
+ classname = TYPE::GetLuaxClassName();
}
lua_pushfstring(L, "%s: %p", classname, self);
return 1;
@@ -386,8 +434,8 @@ namespace Luax
/// ࣬luaijԱΪƣDZ֤userdataͳһNative classṩ__init֧֣
/// nativeʵ崴ʹ__initгʼӵкͻһNewбnativeһ͡
///
- template<typename T>
- int LuaxNativeClass<T>::l_ExtendFactory(lua_State* L)
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_ExtendFactory(lua_State* L)
{
// upvalues:
// 1: base class
@@ -414,13 +462,13 @@ namespace Luax
// .Extend()
lua_pushvalue(L, inheritClass);
- lua_pushcclosure(L, l_ExtendFactory, 1);
+ lua_pushcclosure(L, _ExtendFactory, 1);
lua_setfield(L, -2, "Extend");
// .New()
lua_pushvalue(L, inheritClass);
lua_getfield(L, baseClass, "New");
- lua_pushcclosure(L, l_New, 2);
+ lua_pushcclosure(L, _New, 2);
lua_setfield(L, -2, "New");
// __base = baseClass
@@ -438,8 +486,8 @@ namespace Luax
return 1;
}
- template<typename T>
- int LuaxNativeClass<T>::l_ExtendSingleton(lua_State* L)
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_ExtendSingleton(lua_State* L)
{
// upvalues:
// 1: base class
@@ -466,7 +514,7 @@ namespace Luax
// .Extend()
lua_pushvalue(L, inheritClass);
- lua_pushcclosure(L, l_ExtendFactory, 1);
+ lua_pushcclosure(L, _ExtendFactory, 1);
lua_setfield(L, -2, "Extend");
// __base = baseClass
@@ -485,8 +533,8 @@ namespace Luax
}
#endif /*LUAX_ENABLE_NATIVE_EXTEND*/
- template<typename T>
- int LuaxNativeClass<T>::l_GetClass(lua_State* L)
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_GetClass(lua_State* L)
{
LUAX_STATE(L);
if (!mClassTable)
@@ -496,19 +544,19 @@ namespace Luax
return 1;
}
- template<typename T>
- int LuaxNativeClass<T>::l_GetRefTable(lua_State* L)
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_GetRefTable(lua_State* L)
{
LUAX_STATE(L);
- T* self = state.GetUserdata<T>(1);
+ TYPE* self = state.GetUserdata<TYPE>(1);
bool success = self->PushLuaxRefTable(state);
if (!success)
lua_pushnil(L);
return 1;
}
- template<typename T>
- int LuaxNativeClass<T>::l_New(lua_State* L)
+ template<class TYPE, class BASE>
+ int LuaxNativeClass<TYPE, BASE>::_New(lua_State* L)
{
LUAX_STATE(L);
@@ -580,7 +628,7 @@ namespace Luax
return 0;
}
- template<typename T> LuaxStrongRef LuaxNativeClass<T>::mClassTable; // class table
- template<typename T> LuaxStrongRef LuaxNativeClass<T>::mSingletonRefTable; //
+ template<class TYPE, class BASE> LuaxStrongRef LuaxNativeClass<TYPE, BASE>::mClassTable; // class table
+ template<class TYPE, class BASE> LuaxStrongRef LuaxNativeClass<TYPE, BASE>::mSingletonRefTable; //
} \ No newline at end of file
diff --git a/source/3rd-party/Luax/luax_config.h b/source/3rd-party/Luax/luax_config.h
index 2a8ed3e..31ea7df 100644
--- a/source/3rd-party/Luax/luax_config.h
+++ b/source/3rd-party/Luax/luax_config.h
@@ -57,10 +57,10 @@ namespace Luax
#define LUAX_PROFILER 1
+}
+
#if LUAX_PROFILER
#include <iostream>
#endif
-}
-
-#endif \ No newline at end of file
+#endif // __LUAX_TYPE_H__ \ No newline at end of file
diff --git a/source/3rd-party/Luax/luax_dog.cpp b/source/3rd-party/Luax/luax_dog.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/source/3rd-party/Luax/luax_dog.cpp
diff --git a/source/3rd-party/Luax/luax_dog.h b/source/3rd-party/Luax/luax_dog.h
new file mode 100644
index 0000000..f6d95d5
--- /dev/null
+++ b/source/3rd-party/Luax/luax_dog.h
@@ -0,0 +1,33 @@
+#ifndef __LUAX_DOG_H__
+#define __LUAX_DOG_H__
+
+#include "luax_config.h"
+
+namespace Luax
+{
+
+ ///
+ /// LuaxNativeClassʵüwatch dogֻwatch dogͨʱſdelete
+ ///
+ class LuaxDog
+ {
+ public:
+ LuaxDog()
+ : mVMRef(0)
+ , mNativeRef(0)
+ {
+ }
+
+ inline operator bool()
+ {
+ return mVMRef == 0 && mNativeRef == 0;
+ }
+
+ uint mVMRef; // йܸ
+ uint mNativeRef; //
+
+ };
+
+}
+
+#endif \ No newline at end of file
diff --git a/source/3rd-party/Luax/luax_enum.cpp b/source/3rd-party/Luax/luax_enum.cpp
index 59d8161..ec73fce 100644
--- a/source/3rd-party/Luax/luax_enum.cpp
+++ b/source/3rd-party/Luax/luax_enum.cpp
@@ -8,7 +8,7 @@ namespace Luax
///
/// ֻmetatable__index
///
- int l_rmt__index(lua_State* L)
+ int _rmt__index(lua_State* L)
{
// params:
// 1: enum table
@@ -24,7 +24,7 @@ namespace Luax
return 1;
}
- int l_rmt__newindex(lua_State* L)
+ int _rmt__newindex(lua_State* L)
{
// upvalue:
// 1: enum table name
@@ -53,7 +53,7 @@ namespace Luax
lua_setfield(L, -2, "__index");
lua_pushstring(L, name);
- lua_pushcclosure(L, l_rmt__newindex, 1);
+ lua_pushcclosure(L, _rmt__newindex, 1);
lua_setfield(L, -2, "__newindex");
lua_newtable(L); // enum table
diff --git a/source/3rd-party/Luax/luax_enum.h b/source/3rd-party/Luax/luax_enum.h
index 395eaf0..9afece2 100644
--- a/source/3rd-party/Luax/luax_enum.h
+++ b/source/3rd-party/Luax/luax_enum.h
@@ -15,9 +15,9 @@ namespace Luax
int value;
};
- extern int l_rmt__index(lua_State* L);
+ extern int _rmt__index(lua_State* L);
- extern int l_rmt__newindex(lua_State* L);
+ extern int _rmt__newindex(lua_State* L);
//--------------------------------------------------------------------------------//
diff --git a/source/3rd-party/Luax/luax_state.cpp b/source/3rd-party/Luax/luax_state.cpp
index 612f26e..a2610b4 100644
--- a/source/3rd-party/Luax/luax_state.cpp
+++ b/source/3rd-party/Luax/luax_state.cpp
@@ -684,13 +684,13 @@ namespace Luax
// __index
//lua_pushvalue(L, -1); // metatable
- //lua_pushcclosure(L, l_rmt__index, 1);
+ //lua_pushcclosure(L, _rmt__index, 1);
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
// __newinedx
lua_pushstring(L, name); // enum name
- lua_pushcclosure(L, l_rmt__newindex, 1);
+ lua_pushcclosure(L, _rmt__newindex, 1);
lua_setfield(L, -2, "__newindex");
lua_setmetatable(L, et);
diff --git a/source/3rd-party/Luax/luax_state.h b/source/3rd-party/Luax/luax_state.h
index 7c7d813..e162965 100644
--- a/source/3rd-party/Luax/luax_state.h
+++ b/source/3rd-party/Luax/luax_state.h
@@ -153,12 +153,12 @@ namespace Luax
///
/// עṤͨ࣬New
///
- template<typename T> void RegisterFactory();
+ template<class TYPE> void RegisterFactory();
///
/// עᵥûNew
///
- template<typename T> void RegisterSingleton();
+ template<class TYPE> void RegisterSingleton();
///
/// עö
diff --git a/source/3rd-party/Luax/luax_state.inl b/source/3rd-party/Luax/luax_state.inl
index 20d132c..6671bb5 100644
--- a/source/3rd-party/Luax/luax_state.inl
+++ b/source/3rd-party/Luax/luax_state.inl
@@ -4,9 +4,11 @@ namespace Luax
///
/// עṤעclass tabletype nameΪƿռϡע׶βԪȵNewõʱŻᡣ
///
- template<typename T>
+ template<class TYPE>
void LuaxState::RegisterFactory()
{
+ cc8* type = TYPE::GetLuaxFactoryName();
+
lua_State* L = mState;
LuaxState& state = *this;
@@ -15,11 +17,11 @@ namespace Luax
// class table
lua_newtable(L);
- LuaxNativeClass<T>::RegisterLuaxClass(state);
- LuaxNativeClass<T>::RegisterLuaxFactoryClass(state);
- T::RegisterLuaxClass(state);
+ TYPE::RegisterLuaxClassShared(state);
+ TYPE::RegisterLuaxFactoryClass(state);
+ TYPE::RegisterLuaxClass(state);
- // TǷûעķ
+ // TYPEǷûעķ
#define _assertmethod(I, NAME) \
GetField(I, NAME); \
assert(IsType(-1, LUA_TFUNCTION)); \
@@ -32,7 +34,7 @@ namespace Luax
#if LUAX_ENABLE_NATIVE_EXTEND
// .Extend()
lua_pushvalue(state, -1); // class table
- lua_pushcclosure(state, LuaxNativeClass<T>::l_ExtendFactory, 1);
+ lua_pushcclosure(state, TYPE::_ExtendFactory, 1);
lua_setfield(state, -2, "Extend");
#endif
@@ -40,22 +42,21 @@ namespace Luax
lua_pushvalue(state, -1); // class table
lua_setfield(state, -2, "__index");
- LuaxNativeClass<T>::SetLuaxClassTableRef(state, -1);
+ TYPE::SetLuaxClassTableRef(state, -1);
- cc8* type = T::GetLuaxFactoryName();
SetField(top, type);
// reset top
lua_settop(L, top);
//
- T::RegisterLuaxPostprocess(state);
+ TYPE::RegisterLuaxPostprocess(state);
}
///
/// Singleton
///
- template<typename T>
+ template<typename TYPE>
void LuaxState::RegisterSingleton()
{
lua_State* L = mState;
@@ -66,11 +67,11 @@ namespace Luax
// class table.
lua_newtable(L);
- LuaxNativeClass<T>::RegisterLuaxClass(state);
- LuaxNativeClass<T>::RegisterLuaxSingletonClass(state);
- T::RegisterLuaxClass(state);
+ TYPE::RegisterLuaxClassShared(state);
+ TYPE::RegisterLuaxSingletonClass(state);
+ TYPE::RegisterLuaxClass(state);
- LuaxNativeClass<T>::SetLuaxClassTableRef(state, -1);
+ TYPE::SetLuaxClassTableRef(state, -1);
lua_pushvalue(state, -1);
lua_setfield(state, -2, "__index");
@@ -78,22 +79,22 @@ namespace Luax
#if LUAX_ENABLE_NATIVE_EXTEND
// .Extend()
lua_pushvalue(state, -1); // class table
- lua_pushcclosure(state, LuaxNativeClass<T>::l_ExtendSingleton, 1);
+ lua_pushcclosure(state, TYPE::_ExtendSingleton, 1);
lua_setfield(state, -2, "Extend");
#endif
- cc8* type = T::GetLuaxSingletonName();
+ cc8* type = TYPE::GetLuaxSingletonName();
SetField(top, type);
// reset top
lua_settop(L, top);
//
- T::RegisterLuaxPostprocess(state);
+ TYPE::RegisterLuaxPostprocess(state);
}
- template<typename T>
- void LuaxState::SetField(int idx, cc8* key, T value)
+ template<typename TYPE>
+ void LuaxState::SetField(int idx, cc8* key, TYPE value)
{
if (IsTableOrUserdata(idx))
{
@@ -103,8 +104,8 @@ namespace Luax
}
}
- template<typename T>
- void LuaxState::SetFieldByIndex(int idx, int key, T value)
+ template<typename TYPE>
+ void LuaxState::SetFieldByIndex(int idx, int key, TYPE value)
{
if (IsTableOrUserdata(idx))
{
@@ -114,28 +115,28 @@ namespace Luax
}
}
- template<typename T>
- T LuaxState::GetField(int idx, cc8* key, T value)
+ template<typename TYPE>
+ TYPE LuaxState::GetField(int idx, cc8* key, TYPE value)
{
GetField(idx, key);
- T result = GetValue < T >(-1, value);
+ TYPE result = GetValue < TYPE >(-1, value);
this->Pop();
return result;
}
- template<typename T>
- T LuaxState::GetField(int idx, int key, T value)
+ template<typename TYPE>
+ TYPE LuaxState::GetField(int idx, int key, TYPE value)
{
GetField(idx, key);
- T result = GetValue < T >(-1, value);
+ TYPE result = GetValue < TYPE >(-1, value);
Pop();
return result;
}
- template<typename T>
- T* LuaxState::GetUserdata(int idx)
+ template<typename TYPE>
+ TYPE* LuaxState::GetUserdata(int idx)
{
void* p = nullptr;
@@ -144,11 +145,11 @@ namespace Luax
p = *(void**)lua_touserdata(mState, idx);
}
- return static_cast<T*>(p);
+ return static_cast<TYPE*>(p);
}
- template<typename T>
- T* LuaxState::CheckUserdata(int idx)
+ template<typename TYPE>
+ TYPE* LuaxState::CheckUserdata(int idx)
{
if (IsType(idx, LUA_TUSERDATA))
{
@@ -158,11 +159,11 @@ namespace Luax
{
if (lua_getmetatable(mState, -1)) // class table
{
- T::PushLuaxClassTable(*this); // target class table
+ TYPE::PushLuaxClassTable(*this); // target class table
if (lua_rawequal(mState, -1, -2))
{
Pop(4); // ref\member\class\target class
- T* udata = GetUserdata<T>(idx);
+ TYPE* udata = GetUserdata<TYPE>(idx);
return udata; // userdata
}
Pop(2); // target class table\class table
@@ -172,7 +173,7 @@ namespace Luax
Pop(1); // ref table
}
}
- luaL_typerror(mState, idx, T::GetLuaxClassName());
+ luaL_typerror(mState, idx, TYPE::GetLuaxClassName());
return nullptr;
}
diff --git a/source/Asura.Editor/controls/widget.h b/source/Asura.Editor/controls/widget.h
index 0e881f6..df914bf 100644
--- a/source/Asura.Editor/controls/widget.h
+++ b/source/Asura.Editor/controls/widget.h
@@ -15,8 +15,7 @@ namespace AsuraEditor
///
/// Asura EditorĿؼ߼Ⱦں¼ѯֻ¼Ӧ߼ӿڡ
///
- ASURA_ABSTRACT class Widget
- : virtual public AEScripting::NativeAccessor
+ ASURA_ABSTRACT class Widget : public AEScripting::Object
{
public:
diff --git a/source/modules/asura-box2d/physics/binding/_body.cpp b/source/modules/asura-box2d/physics/binding/_body.cpp
index 68f3aaf..51cc0ab 100644
--- a/source/modules/asura-box2d/physics/binding/_body.cpp
+++ b/source/modules/asura-box2d/physics/binding/_body.cpp
@@ -45,7 +45,6 @@ namespace AsuraEngine
LUAX_IMPL_METHOD(Body, _GetType)
{
LUAX_PREPARE(L, Body);
-
return 0;
}
diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp
index e199a41..47476a7 100644
--- a/source/modules/asura-core/graphics/gl.cpp
+++ b/source/modules/asura-core/graphics/gl.cpp
@@ -12,24 +12,24 @@ namespace AsuraEngine
namespace Graphics
{
+#if ASURA_DEBUG
static bool _instantiated = false;
+#endif
- //
OpenGL gl;
OpenGL::OpenGL()
{
- // Ҫڶʵ
+#if ASURA_DEBUG
ASSERT(!_instantiated);
_instantiated = true;
+#endif
}
OpenGL::~OpenGL()
{
}
- //------------------------------------------------------------------------------//
-
void OpenGL::SetViewport(const Recti v)
{
glViewport(v.x, v.y, v.w, v.h);
@@ -52,5 +52,69 @@ namespace AsuraEngine
state.shader = nullptr;
}
+ //------------------------------------------------------------------------------//
+
+ void OpenGL::SetMatrixMode(MatrixMode mode)
+ {
+ state.matrixMode = mode;
+ }
+
+ MatrixMode OpenGL::GetMatrixMode()
+ {
+ return state.matrixMode;
+ }
+
+ void OpenGL::PushMatrix()
+ {
+ state.matrix[state.matrixMode].Push();
+ }
+
+ void OpenGL::PopMatrix()
+ {
+ state.matrix[state.matrixMode].Pop();
+ }
+
+ void OpenGL::LoadIdentity()
+ {
+ state.matrix[state.matrixMode].LoadIdentity();
+ }
+
+ void OpenGL::Rotate(float angle, float x, float y, float z)
+ {
+ state.matrix[state.matrixMode].Rotate(angle, x, y, z);
+ }
+
+ void OpenGL::Translate(float x, float y, float z)
+ {
+ state.matrix[state.matrixMode].Translate(x, y, z);
+ }
+
+ void OpenGL::Scale(float x, float y, float z)
+ {
+ state.matrix[state.matrixMode].Scale(x, y, z);
+ }
+
+ void OpenGL::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& OpenGL::GetMatrix(MatrixMode mode)
+ {
+ return state.matrix[state.matrixMode].GetTop();
+ }
+
+ uint OpenGL::GetMatrixDepth()
+ {
+ return state.matrix[state.matrixMode].GetCapacity();
+ }
+
+ uint OpenGL::GetMatrixIndex()
+ {
+ return state.matrix[state.matrixMode].GetTopIndex();
+ }
+
+ //------------------------------------------------------------------------------//
+
}
} \ No newline at end of file
diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h
index 3104288..6838bc9 100644
--- a/source/modules/asura-core/graphics/gl.h
+++ b/source/modules/asura-core/graphics/gl.h
@@ -22,15 +22,14 @@ namespace AsuraEngine
enum MatrixMode
{
MATRIX_PROJECTION = 0,
- MATRIX_MODELVIEW,
- _MATRIX_COUNT
+ MATRIX_MODELVIEW = 1,
};
///
/// OpenGLģһЩopengl״̬׷١ڱ༭രڻ£һڶӦһhwnd
/// һhdcԼopengl contextʹwglMakeCurrent(hdc, glc)ָǰ̶߳
/// Ⱦhdcopenglglcglм¼ľһ̵߳һڵһOpenGL
- /// ĵ״̬
+ /// ĵ״ֶ̬֧Ⱦ
///
class OpenGL : public AEScripting::Portable<OpenGL>
{
@@ -69,10 +68,10 @@ namespace AsuraEngine
///
struct
{
- Shader* shader; ///< ǰʹõshader
- AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
- MatrixStack matrix[_MATRIX_COUNT]; ///< ͶӰ
- MatrixMode matrixMode; ///< ǰľ
+ Shader* shader; ///< ǰʹõshader
+ AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯
+ MatrixStack matrix[2]; ///< 任
+ MatrixMode matrixMode; ///< ǰľ
} state;
private:
diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h
index 2e6ced2..e4aecd1 100644
--- a/source/modules/asura-core/graphics/image.h
+++ b/source/modules/asura-core/graphics/image.h
@@ -28,9 +28,8 @@ namespace AsuraEngine
/// һֻࡣҪǿǵeditorengineʹòͬķװ
///
class Image ASURA_FINAL
- : public Texture
- , public Scripting::Portable<Image>
- , public AEIO::Renewable
+ : public AEIO::Renewable
+ , public AEScripting::Portable<Image, Texture>
{
public:
diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp
index fdcdf1b..c26ddf1 100644
--- a/source/modules/asura-core/graphics/shader.cpp
+++ b/source/modules/asura-core/graphics/shader.cpp
@@ -12,24 +12,25 @@ namespace AsuraEngine
Shader::Shader()
{
- mProgram = glCreateProgram();
- if (mProgram == 0)
- throw Exception("Cannot create OpenGL shader program.");
-
- mVertShader = glCreateShader(GL_VERTEX_SHADER);
- if (mVertShader == 0)
- {
- glDeleteProgram(mProgram);
- throw Exception("Cannot create OpenGL vertex shader.");
- }
-
- mFragShader = glCreateShader(GL_FRAGMENT_SHADER);
- if (mFragShader == 0)
- {
- glDeleteProgram(mProgram);
- glDeleteShader(mVertShader);
- throw Exception("Cannot create OpenGL fragment shader.");
- }
+ //Fix: Ҫʱ
+ //mProgram = glCreateProgram();
+ //if (mProgram == 0)
+ // throw Exception("Cannot create OpenGL shader program.");
+
+ //mVertShader = glCreateShader(GL_VERTEX_SHADER);
+ //if (mVertShader == 0)
+ //{
+ // glDeleteProgram(mProgram);
+ // throw Exception("Cannot create OpenGL vertex shader.");
+ //}
+
+ //mFragShader = glCreateShader(GL_FRAGMENT_SHADER);
+ //if (mFragShader == 0)
+ //{
+ // glDeleteProgram(mProgram);
+ // glDeleteShader(mVertShader);
+ // throw Exception("Cannot create OpenGL fragment shader.");
+ //}
}
Shader::~Shader()
diff --git a/source/modules/asura-core/graphics/shader.h b/source/modules/asura-core/graphics/shader.h
index 6d51b8e..f4bce25 100644
--- a/source/modules/asura-core/graphics/shader.h
+++ b/source/modules/asura-core/graphics/shader.h
@@ -82,11 +82,6 @@ namespace AsuraEngine
private:
///
- /// ǰshader
- ///
- static Shader* mCurrentShader;
-
- ///
/// ñ
/// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ
/// vec2 Asura_RenderTargetSize RTĴСΪλ
diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h
index f19f3a7..571c617 100644
--- a/source/modules/asura-core/graphics/texture.h
+++ b/source/modules/asura-core/graphics/texture.h
@@ -57,7 +57,7 @@ namespace AsuraEngine
/// ϲԵѿϵΪ׼EditorҲϽΪԭ㣬Ϊ
/// 㡣
///
- ASURA_ABSTRACT class Texture : virtual public AEScripting::NativeAccessor
+ ASURA_ABSTRACT class Texture : public AEScripting::Object
{
public:
diff --git a/source/modules/asura-utils/io/compressor.h b/source/modules/asura-utils/io/compressor.h
index 30a074c..65fd88a 100644
--- a/source/modules/asura-utils/io/compressor.h
+++ b/source/modules/asura-utils/io/compressor.h
@@ -20,8 +20,6 @@ namespace AsuraEngine
LUAX_DECL_METHOD(_Compress);
LUAX_DECL_METHOD(_Decompress);
-
-
};
}
diff --git a/source/modules/asura-utils/io/data_buffer.h b/source/modules/asura-utils/io/data_buffer.h
index 61d158b..c60444e 100644
--- a/source/modules/asura-utils/io/data_buffer.h
+++ b/source/modules/asura-utils/io/data_buffer.h
@@ -56,6 +56,14 @@ namespace AsuraEngine
private:
+ LUAX_DECL_METHOD(_New);
+ LUAX_DECL_METHOD(_GetData);
+ LUAX_DECL_METHOD(_GetSize);
+ LUAX_DECL_METHOD(_GetCapacity);
+ LUAX_DECL_METHOD(_Refactor);
+ LUAX_DECL_METHOD(_Load);
+ LUAX_DECL_METHOD(_Clear);
+
///
/// Buffer׵ַݵij
///
@@ -69,14 +77,6 @@ namespace AsuraEngine
AEThreading::Mutex mMutex;
- LUAX_DECL_METHOD(_New);
- LUAX_DECL_METHOD(_GetData);
- LUAX_DECL_METHOD(_GetSize);
- LUAX_DECL_METHOD(_GetCapacity);
- LUAX_DECL_METHOD(_Refactor);
- LUAX_DECL_METHOD(_Load);
- LUAX_DECL_METHOD(_Clear);
-
};
}
diff --git a/source/modules/asura-utils/io/file_data.cpp b/source/modules/asura-utils/io/file_data.cpp
index 92333cf..ad58db9 100644
--- a/source/modules/asura-utils/io/file_data.cpp
+++ b/source/modules/asura-utils/io/file_data.cpp
@@ -21,6 +21,8 @@ namespace AsuraEngine
FileData::~FileData()
{
+ if (mData)
+ mData->Release();
}
const std::string& FileData::GetFileName()
@@ -40,7 +42,12 @@ namespace AsuraEngine
void FileData::BindData(ASURA_MOVE DataBuffer* buffer)
{
+ if (!buffer)
+ return;
+ if (mData)
+ mData->Release();
mData = buffer;
+ mData->Retain();
}
DataBuffer* FileData::GetDataBuffer()
@@ -49,4 +56,4 @@ namespace AsuraEngine
}
}
-}
+} \ No newline at end of file
diff --git a/source/modules/asura-utils/io/io_task.cpp b/source/modules/asura-utils/io/io_task.cpp
index 5f0e1c8..ca03b09 100644
--- a/source/modules/asura-utils/io/io_task.cpp
+++ b/source/modules/asura-utils/io/io_task.cpp
@@ -15,10 +15,14 @@ namespace AsuraEngine
: mPath(path)
, mBuffer(buffer)
{
+ if (buffer)
+ buffer->Retain();
}
IOTask::~IOTask()
{
+ if (mBuffer)
+ mBuffer->Release();
}
bool IOTask::Execute()
@@ -31,6 +35,8 @@ namespace AsuraEngine
// pathȡݱmBuffer
else if (mType == IOTASK_TYPE_READ)
{
+ if (!mBuffer)
+ return false;
file.Open(File::FILE_MODE_READ);
file.ReadAll(mBuffer);
file.Close();
diff --git a/source/modules/asura-utils/io/io_task.h b/source/modules/asura-utils/io/io_task.h
index 09c8798..0cf5023 100644
--- a/source/modules/asura-utils/io/io_task.h
+++ b/source/modules/asura-utils/io/io_task.h
@@ -24,8 +24,7 @@ namespace AsuraEngine
/// ȡļ
///
class IOTask ASURA_FINAL
- : public AEThreading::Task
- , public AEScripting::Portable<IOTask>
+ : public AEScripting::Portable<IOTask, AEThreading::Task>
{
public:
@@ -46,8 +45,8 @@ namespace AsuraEngine
std::string mPath;
IOTaskType mType;
- asura_ref DataBuffer* mBuffer;
- Luax::LuaxMemberRef mBufferRef;
+ DataBuffer* mBuffer;
+ Luax::LuaxMemberRef mBufferRef;
};
diff --git a/source/modules/asura-utils/scripting/portable.hpp b/source/modules/asura-utils/scripting/portable.hpp
index ffed49e..1c05163 100644
--- a/source/modules/asura-utils/scripting/portable.hpp
+++ b/source/modules/asura-utils/scripting/portable.hpp
@@ -15,15 +15,15 @@ namespace AsuraEngine
{
///
- /// ҪעluanativeҪ̳дģ塣
+ /// ҪΪ࣬userdatamember ref̳д࣬ע̳С
///
- template<typename T>
- using Portable = Luax::LuaxNativeClass<T>;
+ using Object = Luax::LuaxObject;
///
- /// ҪΪ࣬userdatamember ref̳д࣬ע̳С
+ /// ҪעluanativeҪ̳дģ塣
///
- using NativeAccessor = Luax::ILuaxNativeAccessor;
+ template<typename TYPE, typename BASE = Luax::LuaxObject>
+ using Portable = Luax::LuaxNativeClass<TYPE, BASE>;
}
}
diff --git a/source/modules/asura-utils/threading/task.h b/source/modules/asura-utils/threading/task.h
index 3b3a79c..9073045 100644
--- a/source/modules/asura-utils/threading/task.h
+++ b/source/modules/asura-utils/threading/task.h
@@ -12,8 +12,7 @@ namespace AsuraEngine
///
/// ϣһ̴߳񣬼̳TaskдExecute
///
- ASURA_ABSTRACT class Task
- : public virtual AEScripting::NativeAccessor
+ ASURA_ABSTRACT class Task : public AEScripting::Object
{
public:
diff --git a/source/modules/asura-utils/threading/thread.cpp b/source/modules/asura-utils/threading/thread.cpp
index fc397d2..0899485 100644
--- a/source/modules/asura-utils/threading/thread.cpp
+++ b/source/modules/asura-utils/threading/thread.cpp
@@ -43,6 +43,7 @@ namespace AsuraEngine
{
lock(mTaskQueueMutex)
{
+ task->Retain();
mTaskQueue.push(task);
}
return true;
@@ -207,6 +208,7 @@ namespace AsuraEngine
if (mType == THREAD_TYPE_DEFERRED)
{
mFinishedMutex.Lock();
+ task->Retain();
mFinishedTasks.push(task);
mFinishedMutex.Unlock();
}
@@ -218,6 +220,7 @@ namespace AsuraEngine
}
mTaskQueueMutex.Lock();
mTaskQueue.pop();
+ task->Release();
mTaskQueueMutex.Unlock();
}
}
@@ -262,6 +265,7 @@ namespace AsuraEngine
this->LuaxRelease<Task>(state, task);
mFinishedMutex.Lock();
mFinishedTasks.pop();
+ task->Release();
mFinishedMutex.Unlock();
}
}
diff --git a/source/modules/asura-utils/type.h b/source/modules/asura-utils/type.h
index 7f80bfa..738c4f1 100644
--- a/source/modules/asura-utils/type.h
+++ b/source/modules/asura-utils/type.h
@@ -70,6 +70,8 @@ namespace AsuraEngine
/// ƶָȨ
///
#define ASURA_MOVE
+
+#define ASURA_DEBUG 1
//--------------------------------------------------------------------------------//
diff --git a/source/modules/asura-utils/utils_module.cpp b/source/modules/asura-utils/utils_module.cpp
index 61780e6..5616be4 100644
--- a/source/modules/asura-utils/utils_module.cpp
+++ b/source/modules/asura-utils/utils_module.cpp
@@ -10,10 +10,10 @@ namespace AsuraEngine
{
// IO
LUAX_REGISTER_SINGLETON(state, Filesystem);
+ LUAX_REGISTER_FACTORY(state, IOTask);
LUAX_REGISTER_FACTORY(state, DataBuffer);
LUAX_REGISTER_FACTORY(state, FileData);
LUAX_REGISTER_FACTORY(state, File);
- LUAX_REGISTER_FACTORY(state, IOTask);
// Threading
LUAX_REGISTER_FACTORY(state, Thread);
}
diff --git a/source/tests/05-physfs/main.cpp b/source/tests/05-physfs/main.cpp
index f30a75b..4ae05b8 100644
--- a/source/tests/05-physfs/main.cpp
+++ b/source/tests/05-physfs/main.cpp
@@ -52,7 +52,7 @@ function main()
while true do
thread:Dispatch()
- Thread.Sleep(100)
+ Thread.Sleep(100)
end
end
diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp
index 793b0f6..24b9654 100644
--- a/source/tests/win32/01-window/03_sub_menu.cpp
+++ b/source/tests/win32/01-window/03_sub_menu.cpp
@@ -105,7 +105,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
imgdata->Decode(db);
img = new Image();
img->Update(imgdata);
-
wglMakeCurrent(hdc, glc);
file2 = new File("root/img.png");
@@ -113,7 +112,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
file2->ReadAll(&db);
imgdata->Decode(db);
img->Update(imgdata, {50, 100});
- delete imgdata;
+ imgdata->Release();
break;