diff options
64 files changed, 832 insertions, 1567 deletions
diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Matrix33.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Matrix33.lua index 8cb7e72..ec263d0 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Matrix33.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Matrix33.lua @@ -1,4 +1,4 @@ -local Matrix33 = GameLab.Class("GameLab.Engine.Math.Matrix33") +local Matrix33 = GameLab.GlobalClass("GameLab.Engine.Math.Matrix33") Matrix33.Ctor = function(self) diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Matrix44.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Matrix44.lua index 2347207..9386daf 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Matrix44.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Matrix44.lua @@ -1,4 +1,4 @@ -local Matrix44 = GameLab.Class("GameLab.Engine.Math.Matrix44") +local Matrix44 = GameLab.GlobalClass("GameLab.Engine.Math.Matrix44") Matrix44.Ctor = function(self) for r = 0, 3 do diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua index 2aeb0f7..f603ed5 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Rect.lua @@ -1,4 +1,4 @@ -local Rect = GameLab.Class("GameLab.Engine.Math.Rect")
+local Rect = GameLab.GlobalClass("GameLab.Engine.Math.Rect")
Rect.Ctor = function(self, x, y, width, height)
self.x = x or 0
@@ -7,4 +7,11 @@ Rect.Ctor = function(self, x, y, width, height) self.height = height or 0
end
+Rect.Set = function(self, rect)
+ self.x = rect.x or rect[1]
+ self.y = rect.y or rect[2]
+ self.z = rect.z or rect[3]
+ self.w = rect.w or rect[4]
+end
+
return Rect
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector2.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector2.lua index 822537f..9a0e0a3 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector2.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector2.lua @@ -1,4 +1,4 @@ -local Vector2 = GameLab.Class("GameLab.Engine.Math.Vector2")
+local Vector2 = GameLab.GlobalClass("GameLab.Engine.Math.Vector2")
Vector2.Ctor = function(self, x, y)
self.x = x or 0
diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector3.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector3.lua index e383bf0..8203b1f 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector3.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector3.lua @@ -1,4 +1,4 @@ -local Vector3 = GameLab.Class("GameLab.Engine.Math.Vector3")
+local Vector3 = GameLab.GlobalClass("GameLab.Engine.Math.Vector3")
Vector3.Ctor = function(self, x, y, z)
self.x = x or 0
diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector4.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector4.lua index e232c93..3655184 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector4.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Math/Vector4.lua @@ -1,4 +1,4 @@ -local Vector4 = GameLab.Class("GameLab.Engine.Math.Vector4")
+local Vector4 = GameLab.GlobalClass("GameLab.Engine.Math.Vector4")
Vector4.Ctor = function (self, x, y, z, w)
self.x = x or 0
diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Math/init.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Math/init.lua index eb75db7..5131b07 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Math/init.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Math/init.lua @@ -4,12 +4,13 @@ GameLab.Engine.Math = m local import = GameLab.import(...)
import("Math")
-m.Vector2 = import("Vector2")
-m.Vector3 = import("Vector3")
-m.Vector4 = import("Vector4")
-m.Matrix44 = import("Matrix44")
-m.Matrix33 = import("Matrix33")
-m.Quaternion = import("Quaternion")
+import("Vector2")
+import("Vector3")
+import("Vector4")
+import("Matrix44")
+import("Matrix33")
+import("Quaternion")
+import("Rect")
GameLab.Debug.Log("GameLab.Engine.Math loaded")
diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua index bf908a4..2785bdf 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua @@ -1,4 +1,4 @@ -local Color = GameLab.Class("GameLab.Engine.Rendering.Color") +local Color = GameLab.GlobalClass("GameLab.Engine.Rendering.Color") Color.Ctor = function(self, r, g, b, a) self.r = r diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua index d108dfb..48902b6 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua @@ -1,4 +1,4 @@ -local Color32 = GameLab.Class("GameLab.Engine.Rendering.Color32") +local Color32 = GameLab.GlobalClass("GameLab.Engine.Rendering.Color32") Color32.Ctor = function(self, r, g, b, a) self.r = r diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Image.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Image.lua index b209425..5ef75e5 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Image.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Image.lua @@ -1,5 +1,5 @@ -- Image在texture基础上增加了一些元数据
-local Image = GameLab.Class("GameLab.Engine.Rendering.Image")
+local Image = GameLab.GlobalClass("GameLab.Engine.Rendering.Image")
Image.Ctor = function(self, texture)
self.texture = texture -- "atlas"
diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Material.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Material.lua index 872d7e1..7993f33 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Material.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Rendering/Material.lua @@ -1,4 +1,4 @@ -local Material = GameLab.Class("GameLab.Engine.Rendering.Material") +local Material = GameLab.GlobalClass("GameLab.Engine.Rendering.Material") Material.Ctor = function(self) self.shader = nil -- 绑定的shader diff --git a/Data/DefaultContent/Libraries/GameLab/Engine/Resource/ImageDataRequest.lua b/Data/DefaultContent/Libraries/GameLab/Engine/Resource/ImageDataRequest.lua index f7d7bbe..c35d35a 100644 --- a/Data/DefaultContent/Libraries/GameLab/Engine/Resource/ImageDataRequest.lua +++ b/Data/DefaultContent/Libraries/GameLab/Engine/Resource/ImageDataRequest.lua @@ -1,4 +1,4 @@ -local ImageDataRequest = GameLab.Class("GameLab.Engine.Resource.ImageDataRequest") +local ImageDataRequest = GameLab.GlobalClass("GameLab.Engine.Resource.ImageDataRequest") ImageDataRequest.Ctor = function(self) self.isDone = false diff --git a/Data/DefaultContent/Libraries/GameLab/Entity.lua b/Data/DefaultContent/Libraries/GameLab/Entity.lua deleted file mode 100644 index 27769f3..0000000 --- a/Data/DefaultContent/Libraries/GameLab/Entity.lua +++ /dev/null @@ -1,6 +0,0 @@ --- 游戏中的实体
-local Entity = GameLab.Class("GameLab.Entity")
-
-
-
-return Entity
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Enum.lua b/Data/DefaultContent/Libraries/GameLab/Enum.lua index d1a1ae0..1db5e89 100644 --- a/Data/DefaultContent/Libraries/GameLab/Enum.lua +++ b/Data/DefaultContent/Libraries/GameLab/Enum.lua @@ -1,9 +1,25 @@ -- Declare enum +local Debug = GameLab.Debug -local Enum = function() +local unmodified = { + __newindex = function(t, k, val) + Debug.LogError("Enum is readonly. key=" .. k) + end, + __index = function(t, k, val) + Debug.LogError("Invalid key " .. k) + end +} -end +local Enum = function(tb) + local enum = {} + for i, v in ipairs(tb) do + enum[v] = i + end + setmetatable(enum, unmodified) + return enum +end +GameLab.Enum = Enum -GameLab.Enum = Enum
\ No newline at end of file +return Enum diff --git a/Data/DefaultContent/Libraries/GameLab/GlobalClass.lua b/Data/DefaultContent/Libraries/GameLab/GlobalClass.lua new file mode 100644 index 0000000..dcb5fba --- /dev/null +++ b/Data/DefaultContent/Libraries/GameLab/GlobalClass.lua @@ -0,0 +1,20 @@ +local Class = GameLab.Class or require("GameLab.Class") + +-- 声明类的同时添加到G表 +local GlobalClass = function(className) + local cls = Class(className) + + local shortName = string.match(className, "%.*(%w+)$") + local t = _G + for pkg in string.gmatch(className, "%.*(%w+)%.") do + t[pkg] = t[pkg] or {} + t = t[pkg] + end + t[shortName] = cls + + return cls +end + +GameLab.GlobalClass = GlobalClass + +return GlobalClass
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/GlobalEnum.lua b/Data/DefaultContent/Libraries/GameLab/GlobalEnum.lua new file mode 100644 index 0000000..4a160fa --- /dev/null +++ b/Data/DefaultContent/Libraries/GameLab/GlobalEnum.lua @@ -0,0 +1,20 @@ +local Enum = GameLab.Enum or require("GameLab.Enum") + +-- 声明类的同时添加到G表 +local GlobalEnum = function(enumName) + local enum = Enum(enumName) + + local shortName = string.match(enumName, "%.*(%w+)$") + local t = _G + for pkg in string.gmatch(enumName, "%.*(%w+)%.") do + t[pkg] = t[pkg] or {} + t = t[pkg] + end + t[shortName] = enum + + return enum +end + +GameLab.GlobalEnum = GlobalEnum + +return GlobalEnum
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/InternalClass.lua b/Data/DefaultContent/Libraries/GameLab/InternalClass.lua deleted file mode 100644 index 36ad568..0000000 --- a/Data/DefaultContent/Libraries/GameLab/InternalClass.lua +++ /dev/null @@ -1,12 +0,0 @@ -local Class = GameLab.Class or require("GameLab.Class") - --- 声明类的同时添加到G表 -local InternalClass = function(className) - local cls = Class(className) - _G[className] = className - return cls -end - -GameLab.InternalClass = InternalClass - -return InternalClass
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Node.lua b/Data/DefaultContent/Libraries/GameLab/Node.lua new file mode 100644 index 0000000..c5d43e9 --- /dev/null +++ b/Data/DefaultContent/Libraries/GameLab/Node.lua @@ -0,0 +1,7 @@ +--https://stackoverflow.com/questions/27897714/whats-the-distinction-between-an-entity-and-a-game-object +-- 游戏中的实体 +local Node = GameLab.GlobalClass("GameLab.Node") + + + +return Node
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/Object.lua b/Data/DefaultContent/Libraries/GameLab/Object.lua deleted file mode 100644 index 94d4154..0000000 --- a/Data/DefaultContent/Libraries/GameLab/Object.lua +++ /dev/null @@ -1,5 +0,0 @@ -local Object = GameLab.Class("GameLab.Object")
-
-
-
-return Object
\ No newline at end of file diff --git a/Data/DefaultContent/Libraries/GameLab/init.lua b/Data/DefaultContent/Libraries/GameLab/init.lua index c87ace3..8f61b05 100644 --- a/Data/DefaultContent/Libraries/GameLab/init.lua +++ b/Data/DefaultContent/Libraries/GameLab/init.lua @@ -12,17 +12,6 @@ GameLab.import = function(packageName) return _import
end
--- 用于相对路径包含
--- GameLab.require = function(className)
--- local packageName = (type(className) == "string") and string.match(className, "^(.+)%.%w+$") or ""
--- local _require = function(path)
--- local name = packageName .. "." .. path
--- local m = require(name)
--- return m
--- end
--- return _require
--- end
-
GameLab.find = function(fullName)
if _G[fullName] ~= nil then
return _G[fullName]
@@ -35,7 +24,9 @@ end -- classes
GameLab.Class = require("GameLab.Class")
+GameLab.GlobalClass = require("GameLab.GlobalClass")
-GameLab.InternalClass = require("GameLab.InternalClass")
+GameLab.Enum = require("GameLab.Enum")
+GameLab.GlobalEnum = require("GameLab.GlobalEnum")
return GameLab
\ No newline at end of file diff --git a/Data/Libraries/GameLab/Editor/EditorWindow.lua b/Data/Libraries/GameLab/Editor/EditorWindow.lua index d765031..6bb59d3 100644 --- a/Data/Libraries/GameLab/Editor/EditorWindow.lua +++ b/Data/Libraries/GameLab/Editor/EditorWindow.lua @@ -4,7 +4,7 @@ -- |- GUIWindow -- |- EditorWindow -local EditorWindow = GameLab.Class("GameLab.Editor.EditorWindow") +local EditorWindow = GameLab.GlobalClass("GameLab.Editor.EditorWindow") EditorWindow.Ctor = function(self, title) self.title = title -- 编辑器名称 diff --git a/Data/Libraries/GameLab/Editor/GUI/ContainerWindow.lua b/Data/Libraries/GameLab/Editor/GUI/ContainerWindow.lua new file mode 100644 index 0000000..af525f0 --- /dev/null +++ b/Data/Libraries/GameLab/Editor/GUI/ContainerWindow.lua @@ -0,0 +1,20 @@ +local InternalContainWidow = GameLab.Editor.GUI.Internal.ContainerWindow +local ContainerWindow = GameLab.GlobalClass("GameLab.Editor.GUI.ContainerWindow") + +ContainerWindow.Ctor = function(self, position, showMode, min, max) + self.m_Internal = InternalContainWidow.New(position, showMode, min, max) +end + +ContainerWindow.SetTitle = function(self) + self.m_Internal:SetTitle(self) +end + +ContainerWindow.SetIcon = function(self) + self.m_Internal:SetIcon(self) +end + +ContainerWindow.GetInternal = function(self) + return self.m_Internal +end + +return ContainerWindow
\ No newline at end of file diff --git a/Data/Libraries/GameLab/Editor/GUI/GUIWindow.lua b/Data/Libraries/GameLab/Editor/GUI/GUIWindow.lua index 275c2a7..e283c07 100644 --- a/Data/Libraries/GameLab/Editor/GUI/GUIWindow.lua +++ b/Data/Libraries/GameLab/Editor/GUI/GUIWindow.lua @@ -1,5 +1,52 @@ -local GUIWindowScript = {}
+local InternalGUIWindow = GameLab.Editor.GUI.Internal.GUIWindow
+local GUIWindow = GameLab.GlobalClass("GameLab.Editor.GUI.GUIWindow")
+local Debug = GameLab.Debug
+local GL = GameLab.Engine.GL
+local Math = GameLab.Engine.Math
+local Rendering = GameLab.Engine.Rendering
+local Rect = Math.Rect
-return GUIWindowScript
\ No newline at end of file +GUIWindow.Ctor = function(self)
+ self.m_Internal = InternalGUIWindow.New(self)
+ self.m_ContainerWindow = nil
+ self.m_SplitWindow = nil
+ self.m_Position = Rect.New(0,0,0,0) -- 在父窗口中的位置和大小
+ self.m_EditorWindows = {} -- 编辑器脚本
+end
+
+GUIWindow.SetContainerWindow = function(self, containerWindow)
+ self.m_ContainerWindow = containerWindow
+ self.m_Internal:SetContainerWindow(containerWindow:GetInternal())
+end
+
+GUIWindow.SetPosition = function(self, pos)
+ self.m_Position:Set(pos)
+ self.m_Internal:SetPosition(pos)
+end
+
+GUIWindow.GetInternal = function(self)
+ return self.m_Internal
+end
+
+GUIWindow.OnGUI = function(self)
+ self:ClearBackground()
+
+end
+
+GUIWindow.GetContainerWindow = function(self)
+ return self.m_ContainerWindow
+end
+
+GUIWindow.OnFocus = function(self)
+ Debug.Log("GUIWindow.OnFocus")
+end
+
+GUIWindow.ClearBackground = function(self)
+ GL.ClearColor({1,0,0,1})
+ GL.Clear(GL.EBufferType.ColorBuffer)
+
+end
+
+return GUIWindow
\ No newline at end of file diff --git a/Data/Libraries/GameLab/Editor/GUI/SplitWindow.lua b/Data/Libraries/GameLab/Editor/GUI/SplitWindow.lua new file mode 100644 index 0000000..0d6417e --- /dev/null +++ b/Data/Libraries/GameLab/Editor/GUI/SplitWindow.lua @@ -0,0 +1,14 @@ +local SplitWindow = GameLab.GlobalClass("GameLab.Editor.GUI.SplitWindow") + +local ESplitMode = GameLab.GlobalEnum("GameLab.Editor.GUI.ESplitMode", { + "Vertical", + "Horizontal" +}) + +SplitWindow.Ctor = function(self) + self.m_Splitter = {} + self.m_SplitMode = ESplitMode.Horizontal + self.m_GUIWindows = {} +end + +return SplitWindow
\ No newline at end of file diff --git a/Data/Libraries/GameLab/Editor/GUI/init.lua b/Data/Libraries/GameLab/Editor/GUI/init.lua index 8e9b899..5507a16 100644 --- a/Data/Libraries/GameLab/Editor/GUI/init.lua +++ b/Data/Libraries/GameLab/Editor/GUI/init.lua @@ -3,4 +3,7 @@ local m = GameLab.Editor.GUI local import = GameLab.import(...)
+import("ContainerWindow")
+import("GUIWindow")
+
return m
\ No newline at end of file diff --git a/Data/Resources/Metatable/Excel/Icons.xlsx b/Data/Resources/Metatable/Excel/Icons.xlsx Binary files differindex c4c454a..625b9f0 100644 --- a/Data/Resources/Metatable/Excel/Icons.xlsx +++ b/Data/Resources/Metatable/Excel/Icons.xlsx diff --git a/Data/Scripts/Editor/AssetBrowser.lua b/Data/Scripts/Editor/AssetBrowser.lua index 42f4d71..37e9358 100644 --- a/Data/Scripts/Editor/AssetBrowser.lua +++ b/Data/Scripts/Editor/AssetBrowser.lua @@ -39,7 +39,7 @@ AssetBrowser.OnGUI = function(self) Engine.Rendering.SetVector2("gamelab_ui_position", {0, 0})
--Engine.Rendering.SetTexture("gamelab_main_tex", tex)
--Engine.Rendering.DrawUIQuad({0, 0, 200, 200})
- Editor.GUI.Text(_G["default_font"], "你好世界!\nHello,World!\nProject Window Properties", 12)
+ Editor.GUI.Text(_G["default_font"], "你好世界!\nMaterials\nHello,World!\nProject Window Properties", 12)
-- Engine.Rendering.SetVector2("gamelab_ui_position", {0, 100})
-- Editor.GUI.Text(_G["default_font"], "你好世界!\nHello,World!\nProject Window Properties", 12)
diff --git a/Data/Scripts/EditorApplication.lua b/Data/Scripts/EditorApplication.lua index 0576994..4c91f72 100644 --- a/Data/Scripts/EditorApplication.lua +++ b/Data/Scripts/EditorApplication.lua @@ -21,16 +21,20 @@ local mainWindow = GUI.ContainerWindow.New({400, 400, 800, 500}, GUI.EShowMode.M mainWindow:SetTitle("GameLab") mainWindow:SetIcon("./Data/Icon/GameLab.ico") -app:SetMainWindow(mainWindow) +app:SetMainWindow(mainWindow:GetInternal()) local guiWindow = GUI.GUIWindow.New() guiWindow:SetContainerWindow(mainWindow) guiWindow:SetPosition({0,0, 400, 400}) + +local guiWindow2 = GUI.GUIWindow.New() +guiWindow2:SetContainerWindow(mainWindow) +guiWindow2:SetPosition({500,0, 400, 400}) + collectgarbage() local wnd = AssetBrowser.New() -guiWindow:SetInstance(wnd) local v = GameLab.Engine.Math.Vector4.New(1,2,3,4) @@ -57,45 +61,6 @@ local tex = Engine.Resource.LoadTexture("./Resources/Images/brickwall.jpg") local request = Engine.Resource.LoadImageDataAsync("./Resources/Images/brickwall.jpg") -local vsh = [[ - #version 330 core - layout (location = 0) in vec3 aPos; - layout (location = 1) in vec3 aColor; - layout (location = 2) in vec2 aTexCoord; - - out vec3 ourColor; - out vec2 TexCoord; - - void main() - { - gl_Position = vec4(aPos, 1.0); - ourColor = aColor; - TexCoord = vec2(aTexCoord.x, aTexCoord.y); - } -]] - -local fsh = [[ - #version 330 core - out vec4 FragColor; - - in vec3 ourColor; - in vec2 TexCoord; - - uniform float mixValue; - - // texture samplers - uniform sampler2D texture1; - uniform sampler2D texture2; - - void main() - { - // linearly interpolate between both textures - FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), mixValue); - } -]] - -BeforeMainLoop() - local font = Engine.GUI.Font.New("./Resources/Font/msyh.ttc", {512, 512}, 5, 5) _G["default_font"] = font diff --git a/Data/macro.lua b/Data/Scripts/macro.lua index c8a4895..c8a4895 100644 --- a/Data/macro.lua +++ b/Data/Scripts/macro.lua diff --git a/Data/Scripts/settings.lua b/Data/Scripts/settings.lua new file mode 100644 index 0000000..c837e5c --- /dev/null +++ b/Data/Scripts/settings.lua @@ -0,0 +1,9 @@ +local opentags = { + "WndProc", +} + +local Debug = GameLab.Debug + +for _, tag in ipairs(opentags) do + Debug.OpenTag(tag) +end diff --git a/Data/boot.lua b/Data/boot.lua index ad8f4da..7b9dda0 100644 --- a/Data/boot.lua +++ b/Data/boot.lua @@ -1,5 +1,3 @@ -require("macro")
-
-- 模块搜索目录
local engineLuaLibs = "./DefaultContent/Libraries/?.lua" .. ";./DefaultContent/Libraries/?/init.lua" .. ";./DefaultContent/Libraries/?/?.lua" .. ";./DefaultContent/Libraries/?/?" ..
";./DefaultContent/Plugins/?.lua" .. ";./DefaultContent/Plugins/?/init.lua" .. ";./DefaultContent/Plugins/?/?.lua" .. ";./DefaultContent/Plugins/?/?"
@@ -12,6 +10,9 @@ local engineCLibs = "./DefaultContent/Libraries/?.dll" .. ";./DefaultContent/Plu local editorCLibs = "./Libraries/?.dll" .. "./Plugins/?.dll"
package.cpath=package.cpath .. ";" .. engineCLibs .. ";" .. editorCLibs
+require("macro")
+require("settings")
+
-- debugging
-- 在这里会报一个异常, 不知道为什么
--require("LuaPanda").start("127.0.0.1",8818)
diff --git a/Documents/TODO.xlsx b/Documents/TODO.xlsx Binary files differnew file mode 100644 index 0000000..09d65e3 --- /dev/null +++ b/Documents/TODO.xlsx diff --git a/Documents/窗口.xlsx b/Documents/窗口.xlsx Binary files differindex e0757bb..e93e2c6 100644 --- a/Documents/窗口.xlsx +++ b/Documents/窗口.xlsx diff --git a/Editor/EditorApplication.cpp b/Editor/EditorApplication.cpp index 5089d0b..59af056 100644 --- a/Editor/EditorApplication.cpp +++ b/Editor/EditorApplication.cpp @@ -41,5 +41,5 @@ void EditorApplication::PullMessage() void EditorApplication::OnQuit()
{
-
+ ExitProcess(0);
}
\ No newline at end of file diff --git a/Editor/EditorMain.cpp b/Editor/EditorMain.cpp index 7d7f07c..2336646 100644 --- a/Editor/EditorMain.cpp +++ b/Editor/EditorMain.cpp @@ -18,11 +18,6 @@ void ErrorHandle(cc8* msg) log_error("[Lua] %s", msg);
}
-int BeforeMainLoop(lua_State* L)
-{
- return 0;
-}
-
void InitLuaState(LuaBind::VM& vm)
{
vm.Setup();
@@ -42,9 +37,6 @@ void InitLuaState(LuaBind::VM& vm) Win::SetDllSearchDirectory(workingDir);
LuaBind::State state = vm.GetMainState();
- state.PushGlobalNamespace();
- state.RegisterMethod("BeforeMainLoop", BeforeMainLoop);
-
state.DoFile("./boot.lua");
}
diff --git a/Editor/GUI/ContainerWindow.cpp b/Editor/GUI/ContainerWindow.cpp index 57b1b48..99fa6cb 100644 --- a/Editor/GUI/ContainerWindow.cpp +++ b/Editor/GUI/ContainerWindow.cpp @@ -9,6 +9,7 @@ #include "Runtime/Math/Math.h" using namespace std; +using namespace LuaBind; static bool s_IsMainWindowMaximized; @@ -16,10 +17,10 @@ extern bool ProcessMainWindowMessages(HWND hWnd, UINT message, WPARAM wParam, LP LRESULT CALLBACK ContainerWindow::ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { -#if GAMELAB_DEBUG - static int _event_count = 0; - log_info_tag("WndProc", "ContrainerWindow Event %d", ++_event_count); -#endif +//#if GAMELAB_DEBUG +// static int _event_count = 0; +// log_info_tag("WndProc", "ContrainerWindow Event %d", ++_event_count); +//#endif ContainerWindow *self = (ContainerWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA); if (!self) @@ -45,13 +46,14 @@ LRESULT CALLBACK ContainerWindow::ContainerWndProc(HWND hWnd, UINT message, WPAR case WM_PAINT: { static PAINTSTRUCT ps; - log_info("WM_PAINT"); self->SetAsRenderContext(); + glEnable(GL_BLEND); float c = 26 / 255.f; glClearColor(c, c, c, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glFlush(); + BeginPaint(self->m_Window, &ps); EndPaint(self->m_Window, &ps); UpdateWindow(self->m_Window); diff --git a/Editor/GUI/ContainerWindow.h b/Editor/GUI/ContainerWindow.h new file mode 100644 index 0000000..140748d --- /dev/null +++ b/Editor/GUI/ContainerWindow.h @@ -0,0 +1,82 @@ +#pragma once + +#include <windows.h> +#include <vector> + +#include "Runtime/Math/Rect.h" +#include "Runtime/Lua/LuaBind/LuaBind.h" +#include "Runtime/Lua/LuaHelper.h" +#include "Runtime/Utilities/Singleton.h" +#include "Runtime/Debug/Log.h" +#include "Runtime/Graphics/OpenGL.h" +#include "Runtime/Utilities/UtilMacros.h" +#include "Editor/Utils/HelperFuncs.h" +#include "Runtime/Math/Math.h" +#include "Runtime/Utilities/Exception.h" + +// һcontainner windowжviewport +class ContainerWindow + : public LuaBind::NativeClass<ContainerWindow> +{ +public: + static LRESULT CALLBACK ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + + enum ShowMode { + kShowNormalWindow = 0, // normal window with max/min/close buttons + kShowPopupMenu = 1, // popup menu - no title bar + kShowUtility = 2, // tool window - floats in the app, and hides when the app deactivates + kShowNoShadow = 3, // no shadow/decorations + kShowMainWindow = 4, // main Unity window. On Mac does not have close button; on Windows has menu bar etc. + kShowAuxWindow = 5, // Popup windows like the color picker, gradient editor, etc. Drawn with black background on Mac + }; + + ContainerWindow(LuaBind::VM* vm); + ~ContainerWindow(); + + void Init(Rect size, int showMode, const Vector2& minSize, const Vector2& maxSize, std::string name = ""); + void SetTitle(const char* title); + void SetIcon(LPCSTR iconName); + void SetAsRenderContext(); + void DoPaint(); + void Close(); + + GET_SET(std::string, Name, m_Name); + + GET(HWND, WindowHandle, m_Window); + GET(HDC, DC, m_DC); + + void OnRectChanged(); + void OnActivateApplication(bool active); + +private: + bool SetRenderContext(); + + //-------------------------------------------------------- + + std::string m_Name; + + POINT m_Size; + ShowMode m_ShowMode; // + bool m_IsClosing; + bool m_InMenuLoop; + bool m_CloseFromScriptDontShutdown; + Rect m_InternalRect; + POINT m_MinSize; + POINT m_MaxSize; + +#ifdef GAMELAB_WIN + HWND m_Window; + HDC m_DC; +#endif + + //-------------------------------------------------------- + + LUA_BIND_DECL_CLASS(ContainerWindow); + + LUA_BIND_DECL_METHOD(_New); + LUA_BIND_DECL_METHOD(_SetTitle); + LUA_BIND_DECL_METHOD(_SetIcon); + LUA_BIND_DECL_METHOD(_DoPaint); + +}; + diff --git a/Editor/GUI/EditorWindows.h b/Editor/GUI/EditorWindows.h index d8a3f66..d31627c 100644 --- a/Editor/GUI/EditorWindows.h +++ b/Editor/GUI/EditorWindows.h @@ -1,5 +1,4 @@ -#ifndef EDITOR_WINDOW_H -#define EDITOR_WINDOW_H +#pragma once #include <windows.h> #include <vector> @@ -12,184 +11,7 @@ #include "Runtime/Utilities/UtilMacros.h" #include "Editor/Utils/HelperFuncs.h" #include "Runtime/Math/Math.h" +#include "Runtime/Utilities/Exception.h" -using namespace LuaBind; - -class GUIWindow; - -class WindowUtil -{ -public : - static void RegisterClasses(); - - static const wchar_t* kContainerWindowClassName; - static const wchar_t* kPopupWindowClassName; - static const wchar_t* kGUIWindowClassName; -}; - -class WindowManager : Singleton<WindowManager> -{ -public: - static Vector2 GetMousePosition(); - static GUIWindow* GetMouseOverWindow(); - -private: - static std::vector<GUIWindow*> s_GUIWindows; - -}; - -// һcontainner windowжviewport -class ContainerWindow - : public LuaBind::NativeClass<ContainerWindow> -{ -public: - static LRESULT CALLBACK ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); - - enum ShowMode { - kShowNormalWindow = 0, // normal window with max/min/close buttons - kShowPopupMenu = 1, // popup menu - no title bar - kShowUtility = 2, // tool window - floats in the app, and hides when the app deactivates - kShowNoShadow = 3, // no shadow/decorations - kShowMainWindow = 4, // main Unity window. On Mac does not have close button; on Windows has menu bar etc. - kShowAuxWindow = 5, // Popup windows like the color picker, gradient editor, etc. Drawn with black background on Mac - }; - - ContainerWindow(LuaBind::VM* vm); - ~ContainerWindow(); - - void Init(Rect size, int showMode, const Vector2& minSize, const Vector2& maxSize, std::string name = ""); - void SetTitle(const char* title); - void SetIcon(LPCSTR iconName); - void SetAsRenderContext(); - void DoPaint(); - void Close(); - - GET_SET(std::string, Name, m_Name); - - GET(HWND, WindowHandle, m_Window); - GET(HDC, DC, m_DC); - - void OnRectChanged(); - void OnActivateApplication(bool active); - -private: - bool SetRenderContext(); - - //-------------------------------------------------------- - - std::string m_Name; - - POINT m_Size; - ShowMode m_ShowMode; // - bool m_IsClosing; - bool m_InMenuLoop; - bool m_CloseFromScriptDontShutdown; - Rect m_InternalRect; - POINT m_MinSize; - POINT m_MaxSize; - -#ifdef GAMELAB_WIN - HWND m_Window; - HDC m_DC; -#endif - - //-------------------------------------------------------- - - LUA_BIND_DECL_CLASS(ContainerWindow); - - LUA_BIND_DECL_METHOD(_New); - LUA_BIND_DECL_METHOD(_SetTitle); - LUA_BIND_DECL_METHOD(_SetIcon); - LUA_BIND_DECL_METHOD(_DoPaint); - -}; - -class WindowBase -{ -}; - -// ڣ֣SplitWindowǶ -class SplitWindow : public WindowBase -{ -public: - enum SplitMode - { - Horizontal, - Vertical, - }; - - SplitMode GetSplitMode() { return m_SplitMode; } - - GET(SplitMode, SplitMode, m_SplitMode); - -private: - SplitMode m_SplitMode; - - // Ƕsplit - std::vector< SplitWindow*> m_ChildSplitWindows; - - // split windowGUIWindows - std::vector<GUIWindow*>* m_GUIWindows; - -}; - -// GUIڣ¼ӦơֵĵԪ -class GUIWindow - : public WindowBase - , public LuaBind::NativeClass<GUIWindow> -{ -public: - static LRESULT CALLBACK GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); - static void RepaintAll(); - - GUIWindow(LuaBind::VM* vm); - - void Init(std::string name = ""); - void DoPaint(); - void SetContainerWindow(ContainerWindow* wnd); - void Focus(); - void SetPosition(Rect position); - void SetAsRenderContext(); - - void OnFocus(); - void OnLostFocus(); - void OnPaint(); - - GET_SET(std::string, Name, m_Name); - GET(HDC, DC, m_DC); - -private: - void ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam); - bool SetRenderContext(); - - //----------------------------------------------------------------- - - std::string m_Name; - - ContainerWindow* m_ContainerWindow; - - std::vector<LuaBind::MemberRef> m_EditorWindows; - LuaBind::MemberRef m_EditorWindow; // EditorWindowű - LuaBind::MemberRef m_ActiveEditorWindow; // ǰEditorWindow - - LuaBind::MemberRef m_Script; // EditorWindowű - -#if GAMELAB_WIN - HWND m_Handle; - HDC m_DC; -#endif - - //----------------------------------------------------------------- - - LUA_BIND_DECL_CLASS(GUIWindow); - - LUA_BIND_DECL_METHOD(_New); - LUA_BIND_DECL_METHOD(_DoPaint); - LUA_BIND_DECL_METHOD(_Focus); - LUA_BIND_DECL_METHOD(_SetContainerWindow); - LUA_BIND_DECL_METHOD(_SetPosition); - LUA_BIND_DECL_METHOD(_SetInstance); - -}; - -#endif
\ No newline at end of file +#include "ContainerWindow.h" +#include "GUIWindow.h" diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp index 6bf7fd8..16cf768 100644 --- a/Editor/GUI/GUIWindow.cpp +++ b/Editor/GUI/GUIWindow.cpp @@ -5,6 +5,8 @@ #include "Editor/Win/Win.h" #include "Runtime/Math/Math.h" +using namespace LuaBind; + static bool RedirectMouseWheel(HWND window, WPARAM wParam, LPARAM lParam) { /// prevent reentrancy @@ -27,10 +29,10 @@ static bool RedirectMouseWheel(HWND window, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { -#if GAMELAB_DEBUG - static int _event_count = 0; - log_info_tag("WndProc", "GUIWindow Event %d", ++_event_count); -#endif +//#if GAMELAB_DEBUG +// static int _event_count = 0; +// log_info_tag("WndProc", "GUIWindow Event %d", ++_event_count); +//#endif GUIWindow* self = (GUIWindow*)GetWindowLongPtr(hWnd, GWLP_USERDATA); if (!self) @@ -82,7 +84,6 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara } case WM_CAPTURECHANGED: - return 0; case WM_LBUTTONDOWN: @@ -103,8 +104,32 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara case WM_SYSKEYDOWN: case WM_CHAR: case WM_MOUSEMOVE: + { + log_info_tag("WndProc", "Mouse Or Key Events"); + switch (message) { + case WM_MOUSEMOVE: + case WM_MOUSEHOVER: + { + if (!self->m_MouseTracking) + { + // Start tracking mouse + TRACKMOUSEEVENT trackMouseEvent; + trackMouseEvent.cbSize = sizeof(TRACKMOUSEEVENT); + trackMouseEvent.dwFlags = TME_HOVER | TME_LEAVE; + trackMouseEvent.hwndTrack = self->m_Handle; + trackMouseEvent.dwHoverTime = self->m_MouseHoverTime; + self->m_MouseTracking = TrackMouseEvent(&trackMouseEvent); + } + } + break; + case WM_MOUSELEAVE: + { + // Cancel tracking + self->m_MouseTracking = FALSE; + } + break; case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: @@ -113,23 +138,13 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara SetFocus(hWnd); self->DoPaint(); - - if (/*processInput && !focused*/ true) - { - //focused = (GetFocus() == hWnd); - - //if (focused) - //{ - // BOOL handled = FALSE; - // ProcessInputMessage(hWnd, message, wParam, lParam, handled); - //} - } } break; } // 룬 self->ProcessEventMessages(message, wParam, lParam); + } case WM_SETCURSOR: // We're setting the cursor on every WM_MOUSEMOVE. @@ -138,6 +153,8 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara case WM_WINDOWPOSCHANGED: { + log_info_tag("WndProc", "WM_WINDOWPOSCHANGED"); + // лopenglȾĿ꣬ػû //if (self->m_GfxWindow) //{ @@ -160,19 +177,25 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara } case WM_SETFOCUS: //ý + log_info_tag("WndProc", "WM_SETFOCUS"); + self->OnFocus(); return 0; case WM_KILLFOCUS: //ʧȥ + log_info_tag("WndProc", "WM_KILLFOCUS"); + return 0; case WM_ACTIVATE: break; case WM_CLOSE: + log_info_tag("WndProc", "WM_CLOSE"); delete self; return 0; case WM_INITMENUPOPUP: //˵Ӳ˵Ҫʱ + log_info_tag("WndProc", "WM_INITMENUPOPUP"); return 0; } @@ -185,28 +208,20 @@ void GUIWindow::RepaintAll() //////////////////////////////////////////////////////////// -GUIWindow::GUIWindow(LuaBind::VM* vm) +GUIWindow::GUIWindow(LuaBind::VM* vm, std::string name) : LuaBind::NativeClass<GUIWindow>(vm) , m_Script() { -} - -void GUIWindow::ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam) -{ - -} - -void GUIWindow::Init(std::string name) -{ log_info("Init GUIWindow"); - + m_Name = name; + m_MouseHoverTime = 1; DWORD windowStyle = WS_CHILD; //DWORD windowStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; DWORD extendedStyle = WS_EX_TOOLWINDOW; - Rect pixelRect; + Rect pixelRect; pixelRect.x = 0; pixelRect.y = 0; pixelRect.width = 32; @@ -220,17 +235,17 @@ void GUIWindow::Init(std::string name) AdjustWindowRectEx(&rc, windowStyle, FALSE, extendedStyle); m_Handle = CreateWindowExW( - extendedStyle, - WindowUtil::kGUIWindowClassName, + extendedStyle, + WindowUtil::kGUIWindowClassName, L"", windowStyle, - rc.left, - rc.top, - rc.right - rc.left, + rc.left, + rc.top, + rc.right - rc.left, rc.bottom - rc.top, HWND_MESSAGE, // message only - NULL, - winutils::GetInstanceHandle(), + NULL, + winutils::GetInstanceHandle(), NULL ); @@ -238,13 +253,18 @@ void GUIWindow::Init(std::string name) ShowWindow(m_Handle, SW_SHOW); - bool bRC = SetRenderContext(); + bool bRC = SetRenderContext(); if (!bRC) log_error("Failed to setup rendering context"); log_info("Created GUIWindow "); } +void GUIWindow::ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam) +{ + +} + bool GUIWindow::SetRenderContext() { m_DC = ::GetDC(m_Handle); @@ -318,7 +338,11 @@ void GUIWindow::OnLostFocus() void GUIWindow::OnPaint() { - InvokeLuaCallback(m_Script, "OnGUI"); + LuaBind::MemberInvoker invoker = MemberInvoker(GetVM()->GetCurThread(), this); + invoker.member = m_Script; + invoker.method = "OnGUI"; + invoker.AddMember(m_Script); + invoker.Invoke(0); } void GUIWindow::SetPosition(Rect position) @@ -344,20 +368,18 @@ void GUIWindow::SetAsRenderContext() void GUIWindow::Focus() { log_info("Focus GUIWindow "); - if (m_Handle) - { - if (::GetForegroundWindow() != m_ContainerWindow->GetWindowHandle()) - ::SetForegroundWindow(m_ContainerWindow->GetWindowHandle()); - SetFocus(m_Handle); - } + //if (m_Handle) + //{ + // if (::GetForegroundWindow() != m_ContainerWindow->GetWindowHandle()) + // ::SetForegroundWindow(m_ContainerWindow->GetWindowHandle()); + // SetFocus(m_Handle); + //} } void GUIWindow::SetContainerWindow(ContainerWindow* wnd) { Assert(wnd != NULL); - m_ContainerWindow = wnd; - if (wnd->GetWindowHandle() != m_Handle) { HWND parentWindowHandle = wnd->GetWindowHandle(); diff --git a/Editor/GUI/GUIWindow.h b/Editor/GUI/GUIWindow.h new file mode 100644 index 0000000..aa81b38 --- /dev/null +++ b/Editor/GUI/GUIWindow.h @@ -0,0 +1,69 @@ +#pragma once + +#include <windows.h> +#include <vector> +#include "Runtime/Math/Rect.h" +#include "Runtime/Lua/LuaBind/LuaBind.h" +#include "Runtime/Lua/LuaHelper.h" +#include "Runtime/Utilities/Singleton.h" +#include "Runtime/Debug/Log.h" +#include "Runtime/Graphics/OpenGL.h" +#include "Runtime/Utilities/UtilMacros.h" +#include "Editor/Utils/HelperFuncs.h" +#include "Runtime/Math/Math.h" +#include "Runtime/Utilities/Exception.h" + +#include "WindowBase.h" + +// GUIڣ¼ӦơֵĵԪ +class GUIWindow + : public WindowBase + , public LuaBind::NativeClass<GUIWindow> +{ +public: + static LRESULT CALLBACK GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + static void RepaintAll(); + + GUIWindow(LuaBind::VM* vm, std::string name = ""); //throw WindowException + + void DoPaint(); + void SetContainerWindow(ContainerWindow* wnd); + void Focus(); + void SetPosition(Rect position); + void SetAsRenderContext(); + + void OnFocus(); + void OnLostFocus(); + void OnPaint(); + + GET_SET(std::string, Name, m_Name); + GET(HDC, DC, m_DC); + +private: + void ProcessEventMessages(UINT message, WPARAM wParam, LPARAM lParam); + bool SetRenderContext(); + + //----------------------------------------------------------------- + + std::string m_Name; + + LuaBind::MemberRef m_Script; + + BOOL m_MouseTracking; + DWORD m_MouseHoverTime; + + HWND m_Handle; + HDC m_DC; + + //----------------------------------------------------------------- + + LUA_BIND_DECL_CLASS(GUIWindow); + + LUA_BIND_DECL_METHOD(_New); + LUA_BIND_DECL_METHOD(_DoPaint); + LUA_BIND_DECL_METHOD(_Focus); + LUA_BIND_DECL_METHOD(_SetContainerWindow); + LUA_BIND_DECL_METHOD(_SetPosition); + +}; + diff --git a/Editor/GUI/WindowBase.h b/Editor/GUI/WindowBase.h new file mode 100644 index 0000000..cf3cae6 --- /dev/null +++ b/Editor/GUI/WindowBase.h @@ -0,0 +1,43 @@ +#pragma once + +#include <windows.h> +#include <vector> +#include "Runtime/Math/Rect.h" +#include "Runtime/Lua/LuaBind/LuaBind.h" +#include "Runtime/Lua/LuaHelper.h" +#include "Runtime/Utilities/Singleton.h" +#include "Runtime/Debug/Log.h" +#include "Runtime/Graphics/OpenGL.h" +#include "Runtime/Utilities/UtilMacros.h" +#include "Editor/Utils/HelperFuncs.h" +#include "Runtime/Math/Math.h" +#include "Runtime/Utilities/Exception.h" + +class WindowBase +{ +}; + +CustomException(WindowException); + +class GUIWindow; + +class WindowUtil +{ +public: + static void RegisterClasses(); + + static const wchar_t* kContainerWindowClassName; + static const wchar_t* kPopupWindowClassName; + static const wchar_t* kGUIWindowClassName; +}; + +class WindowManager : Singleton<WindowManager> +{ +public: + static Vector2 GetMousePosition(); + static GUIWindow* GetMouseOverWindow(); + +private: + static std::vector<GUIWindow*> s_GUIWindows; + +}; diff --git a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp b/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp index 0269b72..6c73116 100644 --- a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp +++ b/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp @@ -1,6 +1,8 @@ #include "Editor/GUI/EditorWindows.h" #include "Runtime/Math/Math.h" +using namespace LuaBind; + LUA_BIND_REGISTRY(ContainerWindow) { LUA_BIND_REGISTER_METHODS(state, @@ -13,14 +15,6 @@ LUA_BIND_REGISTRY(ContainerWindow) LUA_BIND_POSTPROCESS(ContainerWindow) { - LUA_BIND_REGISTER_ENUM(state, "EShowMode", - { "NormalWindow", ShowMode::kShowNormalWindow }, - { "ShowPopupMenu", ShowMode::kShowPopupMenu }, - { "Utility ", ShowMode::kShowUtility }, - { "NoShadow", ShowMode::kShowNoShadow }, - { "MainWindow", ShowMode::kShowMainWindow }, - { "AuxWindow", ShowMode::kShowAuxWindow } - ); } LUA_BIND_IMPL_METHOD(ContainerWindow, _SetTitle) diff --git a/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp b/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp index bd21f7d..ed26604 100644 --- a/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp +++ b/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp @@ -11,6 +11,8 @@ #include "Runtime/GUI/TextMeshGenerator.h" #include "Runtime/Utilities/AutoInvoke.h" +using namespace LuaBind;
+
static std::vector<character::Unicode>* s_Codepoints;
InitializeStaticVariables([]() {
@@ -96,8 +98,19 @@ int luaopen_GameLab_Editor_GUI(lua_State* L) state.PushNamespace("Editor"); state.PushNamespace("GUI"); + state.PushNamespace("Internal"); state.RegisterNativeClass<ContainerWindow>(); state.RegisterNativeClass<GUIWindow>(); + state.PopNamespace(); + + LUA_BIND_REGISTER_ENUM(state, "EShowMode",
+ { "NormalWindow", ContainerWindow::kShowNormalWindow },
+ { "ShowPopupMenu", ContainerWindow::kShowPopupMenu },
+ { "Utility ", ContainerWindow::kShowUtility },
+ { "NoShadow", ContainerWindow::kShowNoShadow },
+ { "MainWindow", ContainerWindow::kShowMainWindow },
+ { "AuxWindow", ContainerWindow::kShowAuxWindow }
+ ); state.RegisterMethods(guiFuncs); diff --git a/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp b/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp index dbb26f4..212cb50 100644 --- a/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp +++ b/Editor/Scripting/EditorGUI/GUIWindow.bind.cpp @@ -8,7 +8,6 @@ LUA_BIND_REGISTRY(GUIWindow) { "Focus", _Focus }, { "SetContainerWindow", _SetContainerWindow }, { "SetPosition", _SetPosition }, - { "SetInstance", _SetInstance}, { "New", _New } ); } @@ -17,11 +16,17 @@ LUA_BIND_POSTPROCESS(GUIWindow) { } +// GUIWindow.New([script]) LUA_BIND_IMPL_METHOD(GUIWindow, _New) { LUA_BIND_STATE(L, GUIWindow); + LUA_BIND_CHECK(L, "T"); + GUIWindow* wnd = new GUIWindow(state.GetVM()); - wnd->Init(); + + if (LuaHelper::IsType(state, "GameLab.Editor.GUI.GUIWindow", -1)) + wnd->SetMemberRef(state, wnd->m_Script, -1); + wnd->PushUserdata(state); return 1; } @@ -48,14 +53,6 @@ LUA_BIND_IMPL_METHOD(GUIWindow, _SetContainerWindow) return 0; } -// SetInstance(self, editorWindow) -LUA_BIND_IMPL_METHOD(GUIWindow, _SetInstance) -{ - LUA_BIND_PREPARE(L, GUIWindow); - self->SetMemberRef(state,self->m_Script, -1); - return 0; -} - // GUIWindow.SetPosition(self, {x, y, width, height}) LUA_BIND_IMPL_METHOD(GUIWindow, _SetPosition) { diff --git a/Other/README.txt b/Other/README.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Other/README.txt diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj index 7acc117..5231a28 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj +++ b/Projects/VisualStudio/Editor/Editor.vcxproj @@ -176,6 +176,7 @@ <ClCompile Include="..\..\..\Editor\Win\Win.cpp" />
<ClCompile Include="..\..\..\Runtime\Common\DataBuffer.cpp" />
<ClCompile Include="..\..\..\Runtime\Debug\Log.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Events\InputEvent.cpp" />
<ClCompile Include="..\..\..\Runtime\FileSystem\File.cpp" />
<ClCompile Include="..\..\..\Runtime\FileSystem\FileJobs.cpp" />
<ClCompile Include="..\..\..\Runtime\FileSystem\ImageJobs.cpp" />
@@ -211,6 +212,7 @@ <ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindEnum.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindHelper.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindInvoker.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindMemberRef.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindRef.cpp" />
<ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindRefTable.cpp" />
@@ -248,10 +250,13 @@ <ClInclude Include="..\..\..\Editor\EditorManager.h" />
<ClInclude Include="..\..\..\Editor\FileSystem\FileWatcher.h" />
<ClInclude Include="..\..\..\Editor\Graphics\Graphics.h" />
+ <ClInclude Include="..\..\..\Editor\GUI\ContainerWindow.h" />
<ClInclude Include="..\..\..\Editor\GUI\Dock.h" />
<ClInclude Include="..\..\..\Editor\GUI\EditorWindows.h" />
+ <ClInclude Include="..\..\..\Editor\GUI\GUIWindow.h" />
<ClInclude Include="..\..\..\Editor\GUI\MenuManager.h" />
<ClInclude Include="..\..\..\Editor\GUI\Rect.h" />
+ <ClInclude Include="..\..\..\Editor\GUI\WindowBase.h" />
<ClInclude Include="..\..\..\Editor\GUI\WinUtils.h" />
<ClInclude Include="..\..\..\Editor\Resource\ResourceManager.h" />
<ClInclude Include="..\..\..\Editor\Scripting\EditorScripting.h" />
@@ -261,6 +266,7 @@ <ClInclude Include="..\..\..\Editor\Win\Win.h" />
<ClInclude Include="..\..\..\Runtime\Common\DataBuffer.h" />
<ClInclude Include="..\..\..\Runtime\Debug\Log.h" />
+ <ClInclude Include="..\..\..\Runtime\Events\InputEvent.h" />
<ClInclude Include="..\..\..\Runtime\FileSystem\File.h" />
<ClInclude Include="..\..\..\Runtime\FileSystem\FileJobs.h" />
<ClInclude Include="..\..\..\Runtime\FileSystem\ImageJobs.h" />
@@ -303,10 +309,12 @@ <ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindGlobalState.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindHelper.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindInternal.h" />
+ <ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindInvoker.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindMemberRef.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindRef.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindRefTable.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindState.h" />
+ <ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindTable.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindUtility.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindVM.h" />
<ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindWatchDog.h" />
@@ -328,6 +336,7 @@ <ClInclude Include="..\..\..\Runtime\Profiling\Profiler.h" />
<ClInclude Include="..\..\..\Runtime\Rendering\DynamicMesh.h" />
<ClInclude Include="..\..\..\Runtime\Rendering\Quad.h" />
+ <ClInclude Include="..\..\..\Runtime\Scripting\ScriptingChecks.h" />
<ClInclude Include="..\..\..\Runtime\Threading\Job.h" />
<ClInclude Include="..\..\..\Runtime\Threading\JobSystem.h" />
<ClInclude Include="..\..\..\Runtime\Threading\Mutex.h" />
diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters index c7de4d1..d4fb6b7 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters +++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters @@ -28,6 +28,9 @@ <Filter Include="Editor\Resource">
<UniqueIdentifier>{5b8dba28-42d0-450a-98e1-ca4a65a4fc76}</UniqueIdentifier>
</Filter>
+ <Filter Include="Editor\Scripting\EditorGUI">
+ <UniqueIdentifier>{848489fc-f661-4b10-91f5-db1687293b95}</UniqueIdentifier>
+ </Filter>
<Filter Include="Editor\Scripting\EditorGUILayout">
<UniqueIdentifier>{87edd159-c171-4ccb-9094-9e5061c980d0}</UniqueIdentifier>
</Filter>
@@ -115,8 +118,8 @@ <Filter Include="Runtime\Scripting\GUI">
<UniqueIdentifier>{f209c361-c009-43ac-9e02-aa06804da376}</UniqueIdentifier>
</Filter>
- <Filter Include="Editor\Scripting\GUI">
- <UniqueIdentifier>{848489fc-f661-4b10-91f5-db1687293b95}</UniqueIdentifier>
+ <Filter Include="Runtime\Events">
+ <UniqueIdentifier>{ebaa23ba-fd66-4554-8a90-959097e25cf3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
@@ -160,19 +163,19 @@ <Filter>Editor\Resource</Filter>
</ClCompile>
<ClCompile Include="..\..\..\Editor\Scripting\EditorGUI\EditorGUI.bind.cpp">
- <Filter>Editor\Scripting\GUI</Filter>
+ <Filter>Editor\Scripting\EditorGUI</Filter>
</ClCompile>
<ClCompile Include="..\..\..\Editor\Scripting\EditorScripting.cpp">
<Filter>Editor\Scripting</Filter>
</ClCompile>
<ClCompile Include="..\..\..\Editor\Scripting\EditorGUI\ContainerWindow.bind.cpp">
- <Filter>Editor\Scripting\GUI</Filter>
+ <Filter>Editor\Scripting\EditorGUI</Filter>
</ClCompile>
<ClCompile Include="..\..\..\Editor\Scripting\EditorGUI\GUIWindow.bind.cpp">
- <Filter>Editor\Scripting\GUI</Filter>
+ <Filter>Editor\Scripting\EditorGUI</Filter>
</ClCompile>
<ClCompile Include="..\..\..\Editor\Scripting\EditorGUI\SplitWindow.bind.cpp">
- <Filter>Editor\Scripting\GUI</Filter>
+ <Filter>Editor\Scripting\EditorGUI</Filter>
</ClCompile>
<ClCompile Include="..\..\..\Editor\Scripting\IMGUI\GUIButton.bind.cpp">
<Filter>Editor\Scripting\IMGUI</Filter>
@@ -405,8 +408,12 @@ <ClCompile Include="..\..\..\Runtime\GUI\UIMesh.cpp">
<Filter>Runtime\GUI</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Runtime\Graphics\Color.cpp">
- <Filter>Runtime\Graphics</Filter>
+ <ClCompile Include="..\..\..\Runtime\Graphics\Color.cpp" />
+ <ClCompile Include="..\..\..\Runtime\Lua\LuaBind\LuaBindInvoker.cpp">
+ <Filter>Runtime\Lua\LuaBind</Filter>
+ </ClCompile>
+ <ClCompile Include="..\..\..\Runtime\Events\InputEvent.cpp">
+ <Filter>Runtime\Events</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
@@ -716,6 +723,27 @@ <ClInclude Include="..\..\..\Runtime\Utilities\AutoInvoke.h">
<Filter>Runtime\Utilities</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Scripting\ScriptingChecks.h">
+ <Filter>Runtime\Scripting</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindInvoker.h">
+ <Filter>Runtime\Lua\LuaBind</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Events\InputEvent.h">
+ <Filter>Runtime\Events</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Runtime\Lua\LuaBind\LuaBindTable.h">
+ <Filter>Runtime\Lua\LuaBind</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Editor\GUI\ContainerWindow.h">
+ <Filter>Editor\GUI</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Editor\GUI\GUIWindow.h">
+ <Filter>Editor\GUI</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\Editor\GUI\WindowBase.h">
+ <Filter>Editor\GUI</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\Runtime\Lua\LuaBind\LuaBindClass.inc">
diff --git a/Runtime/Debug/Log.cpp b/Runtime/Debug/Log.cpp index 301e15a..484e3c7 100644 --- a/Runtime/Debug/Log.cpp +++ b/Runtime/Debug/Log.cpp @@ -95,8 +95,14 @@ void log_error(const char* fmt, ...) }
} +#define CHECK_TAG(tag)\ +if (s_OpenTags.count(tag) == 0)\ + return; + void log_info_tag(const char* tag, const char* fmt, ...) { + CHECK_TAG(tag); + Lock(s_Mutex) { SetOutputColor(0); va_list pArgs = NULL;
@@ -110,6 +116,8 @@ void log_info_tag(const char* tag, const char* fmt, ...) void log_warning_tag(const char* tag, const char* fmt, ...) { + CHECK_TAG(tag); + Lock(s_Mutex) { SetOutputColor(1); va_list pArgs = NULL;
@@ -123,6 +131,8 @@ void log_warning_tag(const char* tag, const char* fmt, ...) void log_error_tag(const char* tag, const char* fmt, ...) { + CHECK_TAG(tag); + Lock(s_Mutex) { SetOutputColor(2); va_list pArgs = NULL;
diff --git a/Runtime/Events/InputEvent.cpp b/Runtime/Events/InputEvent.cpp new file mode 100644 index 0000000..ac41c94 --- /dev/null +++ b/Runtime/Events/InputEvent.cpp @@ -0,0 +1,12 @@ +#include "InputEvent.h" + +void InputEvent::CastToTable(LuaBind::State& state) +{ + lua_newtable(state); + int table = state.GetTop(); + + lua_pushnumber(state, type); + lua_setfield(state, table, "type"); + + +} diff --git a/Runtime/Events/InputEvent.h b/Runtime/Events/InputEvent.h new file mode 100644 index 0000000..5a5ed36 --- /dev/null +++ b/Runtime/Events/InputEvent.h @@ -0,0 +1,54 @@ +#pragma once + +#include "Runtime/Lua/LuaHelper.h" +#include "Runtime/Math/Math.h" + +enum EInputEventType +{ + InputEvent_MouseDown = 0, + InputEvent_MouseUp = 1, + InputEvent_MouseMove = 2, + InputEvent_MouseDrag = 3, + InputEvent_KeyDown = 4, + InputEvent_KeyUp = 5, + InputEvent_ScrollWheel = 6, + InputEvent_Repaint = 7, + InputEvent_Layout = 8, + InputEvent_DragUpdated = 9, + InputEvent_DragPerform = 10, + InputEvent_DragExited = 15, + InputEvent_Ignore = 11, + InputEvent_Used = 12, + InputEvent_ValidateCommand = 13, + InputEvent_ExecuteCommand = 14, + InputEvent_ContextClick = 16, + InputEvent_MouseEnterWindow = 20, + InputEvent_MouseLeaveWindow = 21, + InputEvent_MagnifyGesture = 1000, + InputEvent_SwipeGesture = 1001, + InputEvent_RotateGesture = 1002 +}; + +// ¼ +struct InputEvent : public LuaBind::INativeTable +{ + EInputEventType type; + + Vector2f mousePosition; + Vector2f mouseDelta; + + int button; ///< mouse button number. (bitfield of MouseButton enum) + int modifiers; ///< keyboard modifier flags. (bitfield of Modifiers enum) + float pressure; ///< Stylus pressure. + int clickCount; + uint16_t character; ///< unicode keyboard character (with modifiers). + uint16_t keycode; ///< The keyboard scancode of the event. + int displayIndex; ///< Display index to which this event belongs. + char* commandString; + bool keyRepeat; ///< Is the event the result of key repeat? + + bool use; + + void CastToTable(LuaBind::State& state) override; + +};
\ No newline at end of file diff --git a/Runtime/Lua/LuaBind/LuaBind.h b/Runtime/Lua/LuaBind/LuaBind.h index e12c4b9..b6c5870 100644 --- a/Runtime/Lua/LuaBind/LuaBind.h +++ b/Runtime/Lua/LuaBind/LuaBind.h @@ -10,5 +10,7 @@ #include "LuaBindMemberRef.h" #include "LuaBindClass.inc" #include "LuaBindState.inc" +#include "LuaBindInvoker.h" +#include "LuaBindTable.h" #endif
\ No newline at end of file diff --git a/Runtime/Lua/LuaBind/LuaBindClass.hpp b/Runtime/Lua/LuaBind/LuaBindClass.hpp index 3a407d2..a5ac978 100644 --- a/Runtime/Lua/LuaBind/LuaBindClass.hpp +++ b/Runtime/Lua/LuaBind/LuaBindClass.hpp @@ -87,7 +87,7 @@ namespace LuaBind NativeClass(LuaBind::VM* vm); virtual ~NativeClass(); - VM* GetVM() { return mOwner; } + LuaBind::VM* GetVM() { return mOwner; } // Աùʵref tableáȡ void SetMemberRef(State& state, MemberRef& memRef, int idx); diff --git a/Runtime/Lua/LuaBind/LuaBindInvoker.cpp b/Runtime/Lua/LuaBind/LuaBindInvoker.cpp new file mode 100644 index 0000000..debebf8 --- /dev/null +++ b/Runtime/Lua/LuaBind/LuaBindInvoker.cpp @@ -0,0 +1,105 @@ +#include "LuaBindInvoker.h" + +namespace LuaBind +{ + + void GlobalInvoker::AddInt(int n) + { + state.Push(n); + ++argc; + } + + void GlobalInvoker::AddFloat(float n) + { + state.Push(n); + ++argc; + } + + void GlobalInvoker::AddNil() + { + state.PushNil(); + ++argc; + } + + void GlobalInvoker::AddBool(bool b) + { + state.Push(b); + ++argc; + } + + void GlobalInvoker::AddString(const char* str) + { + state.Push(str); + ++argc; + } + + void GlobalInvoker::AddTable(INativeTable& tb) + { + tb.CastToTable(state); + ++argc; + } + + void GlobalInvoker::Invoke(int nReturns) + { + method.PushRef(state); + state.Call(argc, nReturns, onErrorOccured); + } + + + void MemberInvoker::AddInt(int n) + { + state.Push(n); + ++argc; + } + + void MemberInvoker::AddFloat(float n) + { + state.Push(n); + ++argc; + } + + void MemberInvoker::AddNil() + { + state.PushNil(); + ++argc; + } + + void MemberInvoker::AddBool(bool b) + { + state.Push(b); + ++argc; + } + + void MemberInvoker::AddString(const char* str) + { + state.Push(str); + ++argc; + } + + void MemberInvoker::AddTable(INativeTable& tb) + { + tb.CastToTable(state); + ++argc; + } + + void MemberInvoker::AddMember(MemberRef member) + { + owner->PushMemberRef(state, member); + ++argc; + } + + void MemberInvoker::Invoke(int nReturns) + { + owner->PushMemberRef(state, member); + state.GetField(-1, method); + if (!state.IsType(-1, LUA_TFUNCTION)) + { + state.Pop(2); + return; + } + lua_replace(state, -2); + lua_insert(state, -1 - argc); + state.Call(argc, nReturns, onErrorOccured); + } + +} diff --git a/Runtime/Lua/LuaBind/LuaBindInvoker.h b/Runtime/Lua/LuaBind/LuaBindInvoker.h new file mode 100644 index 0000000..8ea57a2 --- /dev/null +++ b/Runtime/Lua/LuaBind/LuaBindInvoker.h @@ -0,0 +1,77 @@ +#ifndef LUA_BIND_INVOKER_H +#define LUA_BIND_INVOKER_H + +#include "LuaBindRef.h" +#include "LuaBindTable.h" +#include "LuaBindClass.hpp" + +namespace LuaBind +{ + + // ȫlua + struct GlobalInvoker + { + GlobalInvoker(lua_State* st) + : state(st) + { + argc = 0; + } + UniversalRef method; + + void AddInt(int n); + void AddFloat(float n); + void AddNil(); + void AddBool(bool b); + void AddString(const char* str); + void AddTable(INativeTable& tb); + template<class T> + void AddUserdata(NativeClass<T>& udata) { + udata.PushUserdata(state); + ++argc; + } + + void Invoke(int nReturns); + + private: + State state; + int argc; + }; + + // óԱķ + struct MemberInvoker + { + MemberRef member; + const char* method; + + MemberInvoker(lua_State* st, LuaBind::Object* owner) + : state(st) + { + argc = 0; + this->owner = owner; + } + + void AddMember(MemberRef member); + void AddInt(int n); + void AddFloat(float n); + void AddNil(); + void AddBool(bool b); + void AddString(const char* str); + void AddTable(INativeTable& tb); + template<class T> + void AddUserdata(NativeClass<T>& udata) { + udata.PushUserdata(state); + ++argc; + } + + void Invoke(int nReturns); + + private: + LuaBind::Object* owner; + State state; + int argc; + + }; + +} + +#endif
\ No newline at end of file diff --git a/Runtime/Lua/LuaBind/LuaBindMemberRef.h b/Runtime/Lua/LuaBind/LuaBindMemberRef.h index ecc50f5..37fe413 100644 --- a/Runtime/Lua/LuaBind/LuaBindMemberRef.h +++ b/Runtime/Lua/LuaBind/LuaBindMemberRef.h @@ -8,6 +8,7 @@ namespace LuaBind // ʵref tablemember refluax classĹʵref tableǿãmemberڡ // luanative֮ݹͨ + // ѭöڴй¶ΪluaGCtracing GC class MemberRef { public: diff --git a/Runtime/Lua/LuaBind/LuaBindState.cpp b/Runtime/Lua/LuaBind/LuaBindState.cpp index 384cba2..676c19c 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.cpp +++ b/Runtime/Lua/LuaBind/LuaBindState.cpp @@ -196,6 +196,11 @@ namespace LuaBind } } + void State::PushTable(INativeTable& tb) + { + tb.CastToTable(*this); + } + void State::PushNil() { lua_pushnil(mState); diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h index e639d4d..24bd092 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.h +++ b/Runtime/Lua/LuaBind/LuaBindState.h @@ -6,6 +6,7 @@ #include "LuaBindConfig.h" #include "LuaBindRefTable.h" #include "LuaBindGlobalState.h" +#include "LuaBindTable.h" namespace LuaBind { @@ -100,6 +101,7 @@ namespace LuaBind bool HasField(int idx, int name, int type); bool HasKeys(int idx); + void PushTable(INativeTable& tb); void PushNil(); void Push(bool value); void Push(cc8* value); diff --git a/Runtime/Lua/LuaBind/LuaBindTable.h b/Runtime/Lua/LuaBind/LuaBindTable.h new file mode 100644 index 0000000..3a6ec6c --- /dev/null +++ b/Runtime/Lua/LuaBind/LuaBindTable.h @@ -0,0 +1,15 @@ +#pragma once + +namespace LuaBind +{ + + class State; + + // ҪΪtableluaĽṹʵӿ + struct INativeTable + { + // ṹתΪtableջ + virtual void CastToTable(State& state) = 0; + }; + +}
\ No newline at end of file diff --git a/Runtime/Lua/LuaBind/LuaBindUtility.h b/Runtime/Lua/LuaBind/LuaBindUtility.h index e88dd68..e47a326 100644 --- a/Runtime/Lua/LuaBind/LuaBindUtility.h +++ b/Runtime/Lua/LuaBind/LuaBindUtility.h @@ -34,7 +34,7 @@ }while(0) #define LUA_BIND_REGISTER_ENUM(state, name, ...) \ do{ \ - ::Enum __e[] = {__VA_ARGS__,{0, 0}}; \ + LuaBind::Enum __e[] = {__VA_ARGS__,{0, 0}}; \ state.RegisterEnum(name, __e); \ }while(0) diff --git a/Runtime/Lua/LuaBind/signal/bind.h b/Runtime/Lua/LuaBind/signal/bind.h deleted file mode 100644 index e29896b..0000000 --- a/Runtime/Lua/LuaBind/signal/bind.h +++ /dev/null @@ -1,510 +0,0 @@ -// Aseprite Base Library -// Copyright (c) 2001-2013 David Capello -// -// This file is released under the terms of the MIT license. -// Read LICENSE.txt for more information. - -#ifndef BASE_BIND_H_INCLUDED -#define BASE_BIND_H_INCLUDED -#pragma once - -// BindAdapter0_fun -template<typename R, typename F> -class BindAdapter0_fun -{ - F f; -public: - BindAdapter0_fun(const F& f) : f(f) { } - - R operator()() { return f(); } - - template<typename A1> - R operator()(const A1& a1) { return f(); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return f(); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(); } -}; - -template<typename F> -class BindAdapter0_fun<void, F> -{ - F f; -public: - BindAdapter0_fun(const F& f) : f(f) { } - - void operator()() { f(); } - - template<typename A1> - void operator()(const A1& a1) { f(); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { f(); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { f(); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(); } -}; - -template<typename R, typename F> -BindAdapter0_fun<R, F> -Bind(const F& f) -{ - return BindAdapter0_fun<R, F>(f); -} - -// BindAdapter0_mem -template<typename R, typename T> -class BindAdapter0_mem -{ - R (T::*m)(); - T* t; -public: - template<typename T2> - BindAdapter0_mem(R (T::*m)(), T2* t) : m(m), t(t) { } - - R operator()() { return (t->*m)(); } - - template <typename A1> - R operator()(const A1& a1) { return (t->*m)(); } - - template <typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return (t->*m)(); } - - template <typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(); } - - template <typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(); } -}; - -template<typename T> -class BindAdapter0_mem<void, T> -{ - void (T::*m)(); - T* t; -public: - template<typename T2> - BindAdapter0_mem(void (T::*m)(), T2* t) : m(m), t(t) { } - - void operator()() { (t->*m)(); } - - template <typename A1> - void operator()(const A1& a1) { (t->*m)(); } - - template <typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { (t->*m)(); } - - template <typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(); } - - template <typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(); } -}; - -template<typename R, typename T, typename T2> -BindAdapter0_mem<R, T> -Bind(R (T::*m)(), T2* t) -{ - return BindAdapter0_mem<R, T>(m, t); -} - -// BindAdapter1_fun -template<typename R, typename F, - typename X1> -class BindAdapter1_fun -{ - F f; - X1 x1; -public: - BindAdapter1_fun(const F& f, X1 x1) : f(f), x1(x1) { } - - R operator()() { return f(x1); } - - template<typename A1> - R operator()(const A1& a1) { return f(x1); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return f(x1); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1); } -}; - -template<typename F, - typename X1> -class BindAdapter1_fun<void, F, X1> -{ - F f; - X1 x1; -public: - BindAdapter1_fun(const F& f, X1 x1) : f(f), x1(x1) { } - - void operator()() { f(x1); } - - template<typename A1> - void operator()(const A1& a1) { f(x1); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { f(x1); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1); } -}; - -template<typename R, typename F, - typename X1> -BindAdapter1_fun<R, F, X1> -Bind(const F& f, X1 x1) -{ - return BindAdapter1_fun<R, F, X1>(f, x1); -} - -// BindAdapter1_mem -template<typename R, typename T, - typename B1, - typename X1> -class BindAdapter1_mem -{ - R (T::*m)(B1); - T* t; - X1 x1; -public: - template<typename T2> - BindAdapter1_mem(R (T::*m)(B1), T2* t, X1 x1) : m(m), t(t), x1(x1) { } - - R operator()() { return (t->*m)(x1); } - - template <typename A1> - R operator()(const A1& a1) { return (t->*m)(x1); } - - template <typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1); } - - template <typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1); } - - template <typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1); } -}; - -template<typename T, - typename B1, - typename X1> -class BindAdapter1_mem<void, T, B1, X1> -{ - void (T::*m)(B1); - T* t; - X1 x1; -public: - template<typename T2> - BindAdapter1_mem(void (T::*m)(B1), T2* t, X1 x1) : m(m), t(t), x1(x1) { } - - void operator()() { (t->*m)(x1); } - - template <typename A1> - void operator()(const A1& a1) { (t->*m)(x1); } - - template <typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { (t->*m)(x1); } - - template <typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1); } - - template <typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1); } -}; - -template<typename R, typename T, typename T2, - typename B1, typename X1> -BindAdapter1_mem<R, T, B1, X1> -Bind(R (T::*m)(B1), T2* t, X1 x1) -{ - return BindAdapter1_mem<R, T, B1, X1>(m, t, x1); -} - -// BindAdapter2_fun -template<typename R, typename F, - typename X1, typename X2> -class BindAdapter2_fun -{ - F f; - X1 x1; - X2 x2; -public: - BindAdapter2_fun(const F& f, X1 x1, X2 x2) : f(f), x1(x1), x2(x2) { } - - R operator()() { return f(x1, x2); } - - template<typename A1> - R operator()(const A1& a1) { return f(x1, x2); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return f(x1, x2); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1, x2); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1, x2); } -}; - -template<typename F, - typename X1, typename X2> -class BindAdapter2_fun<void, F, X1, X2> -{ - F f; - X1 x1; - X2 x2; -public: - BindAdapter2_fun(const F& f, X1 x1, X2 x2) : f(f), x1(x1), x2(x2) { } - - void operator()() { f(x1, x2); } - - template<typename A1> - void operator()(const A1& a1) { f(x1, x2); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { f(x1, x2); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1, x2); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1, x2); } -}; - -template<typename R, typename F, - typename X1, typename X2> -BindAdapter2_fun<R, F, X1, X2> -Bind(const F& f, X1 x1, X2 x2) -{ - return BindAdapter2_fun<R, F, X1, X2>(f, x1, x2); -} - -// BindAdapter2_mem -template<typename R, typename T, - typename B1, typename B2, - typename X1, typename X2> -class BindAdapter2_mem -{ - R (T::*m)(B1, B2); - T* t; - X1 x1; - X2 x2; -public: - template<typename T2> - BindAdapter2_mem(R (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { } - - R operator()() { return (t->*m)(x1, x2); } - - template<typename A1> - R operator()(const A1& a1) { return (t->*m)(x1, x2); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1, x2); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1, x2); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1, x2); } -}; - -template<typename T, - typename B1, typename B2, - typename X1, typename X2> -class BindAdapter2_mem<void, T, B1, B2, X1, X2> -{ - void (T::*m)(B1, B2); - T* t; - X1 x1; - X2 x2; -public: - template<typename T2> - BindAdapter2_mem(void (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { } - - void operator()() { (t->*m)(x1, x2); } - - template<typename A1> - void operator()(const A1& a1) { (t->*m)(x1, x2); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { (t->*m)(x1, x2); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1, x2); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1, x2); } -}; - -template<typename R, typename T, typename T2, typename B1, typename B2, typename X1, typename X2> -BindAdapter2_mem<R, T, B1, B2, X1, X2> -Bind(R (T::*m)(B1, B2), T2* t, X1 x1, X2 x2) -{ - return BindAdapter2_mem<R, T, B1, B2, X1, X2>(m, t, x1, x2); -} - -// BindAdapter3_fun -template<typename R, typename F, - typename X1, typename X2, typename X3> -class BindAdapter3_fun -{ - F f; - X1 x1; - X2 x2; - X3 x3; -public: - BindAdapter3_fun(const F& f, X1 x1, X2 x2, X3 x3) : f(f), x1(x1), x2(x2), x3(x3) { } - - R operator()() { return f(x1, x2, x3); } - - template<typename A1> - R operator()(const A1& a1) { return f(x1, x2, x3); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return f(x1, x2, x3); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return f(x1, x2, x3); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return f(x1, x2, x3); } -}; - -template<typename F, - typename X1, typename X2, typename X3> -class BindAdapter3_fun<void, F, X1, X2, X3> -{ - F f; - X1 x1; - X2 x2; - X3 x3; -public: - BindAdapter3_fun(const F& f, X1 x1, X2 x2, X3 x3) : f(f), x1(x1), x2(x2), x3(x3) { } - - void operator()() { f(x1, x2, x3); } - - template<typename A1> - void operator()(const A1& a1) { f(x1, x2, x3); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { f(x1, x2, x3); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { f(x1, x2, x3); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { f(x1, x2, x3); } -}; - -template<typename R, typename F, - typename X1, typename X2, typename X3> -BindAdapter3_fun<R, F, X1, X2, X3> -Bind(const F& f, X1 x1, X2 x2, X3 x3) -{ - return BindAdapter3_fun<R, F, X1, X2, X3>(f, x1, x2, x3); -} - -// BindAdapter3_mem -template<typename R, typename T, - typename B1, typename B2, typename B3, - typename X1, typename X2, typename X3> -class BindAdapter3_mem -{ - R (T::*m)(B1, B2, B3); - T* t; - X1 x1; - X2 x2; - X3 x3; -public: - template<typename T2> - BindAdapter3_mem(R (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2, X3 x3) : m(m), t(t), x1(x1), x2(x2), x3(x3) { } - - R operator()() { return (t->*m)(x1, x2, x3); } - - template<typename A1> - R operator()(const A1& a1) { return (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2> - R operator()(const A1& a1, const A2& a2) { return (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2, typename A3> - R operator()(const A1& a1, const A2& a2, const A3& a3) { return (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2, typename A3, typename A4> - R operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { return (t->*m)(x1, x2, x3); } -}; - -template<typename T, - typename B1, typename B2, typename B3, - typename X1, typename X2, typename X3> -class BindAdapter3_mem<void, T, B1, B2, B3, X1, X2, X3> -{ - void (T::*m)(B1, B2, B3); - T* t; - X1 x1; - X2 x2; - X3 x3; -public: - template<typename T2> - BindAdapter3_mem(void (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2) : m(m), t(t), x1(x1), x2(x2) { } - - void operator()() { (t->*m)(x1, x2, x3); } - - template<typename A1> - void operator()(const A1& a1) { (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2> - void operator()(const A1& a1, const A2& a2) { (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2, typename A3> - void operator()(const A1& a1, const A2& a2, const A3& a3) { (t->*m)(x1, x2, x3); } - - template<typename A1, typename A2, typename A3, typename A4> - void operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) { (t->*m)(x1, x2, x3); } -}; - -template<typename R, typename T, typename T2, - typename B1, typename B2, typename B3, - typename X1, typename X2, typename X3> -BindAdapter3_mem<R, T, B1, B2, B3, X1, X2, X3> -Bind(R (T::*m)(B1, B2, B3), T2* t, X1 x1, X2 x2) -{ - return BindAdapter3_mem<R, T, B1, B2, B3, X1, X2, X3>(m, t, x1, x2); -} - -// Helper class to holds references as pointers (to avoid copying the -// original object). -template<class T> -class RefWrapper -{ - T* ptr; -public: - RefWrapper(T& ref) : ptr(&ref) { } - operator T&() const { return *ptr; } -}; - -// Creates RefWrappers, useful to wrap arguments that have to be -// passed as a reference when you use Bind. -template<class T> -RefWrapper<T> Ref(T& ref) -{ - return RefWrapper<T>(ref); -} - -#endif diff --git a/Runtime/Lua/LuaBind/signal/remove_from_container.h b/Runtime/Lua/LuaBind/signal/remove_from_container.h deleted file mode 100644 index 9fdc442..0000000 --- a/Runtime/Lua/LuaBind/signal/remove_from_container.h +++ /dev/null @@ -1,32 +0,0 @@ -// Aseprite Base Library
-// Copyright (c) 2001-2013 David Capello
-//
-// This file is released under the terms of the MIT license.
-// Read LICENSE.txt for more information.
-
-#ifndef BASE_REMOVE_FROM_CONTAINER_H_INCLUDED
-#define BASE_REMOVE_FROM_CONTAINER_H_INCLUDED
-#pragma once
-
-namespace base {
-
-// Removes all ocurrences of the specified element from the STL container.
-template<typename ContainerType>
-void remove_from_container(ContainerType& container,
- typename ContainerType::const_reference element)
-{
- for (typename ContainerType::iterator
- it = container.begin(),
- end = container.end(); it != end; ) {
- if (*it == element) {
- it = container.erase(it);
- end = container.end();
- }
- else
- ++it;
- }
-}
-
-}
-
-#endif
diff --git a/Runtime/Lua/LuaBind/signal/signal.h b/Runtime/Lua/LuaBind/signal/signal.h deleted file mode 100644 index 97882c6..0000000 --- a/Runtime/Lua/LuaBind/signal/signal.h +++ /dev/null @@ -1,451 +0,0 @@ -// Aseprite Base Library
-// Copyright (c) 2001-2013 David Capello
-//
-// This file is released under the terms of the MIT license.
-// Read LICENSE.txt for more information.
-
-#ifndef BASE_SIGNAL_H_INCLUDED
-#define BASE_SIGNAL_H_INCLUDED
-#pragma once
-
-//#include "base/slot.h"
-//#include "base/remove_from_container.h"
-
-#include "./slot.h"
-#include "./remove_from_container.h"
-
-#include <vector>
-
-// Signal0_base<R> - Base class to delegate responsibility to
-// functions of zero arguments.
-template<typename R>
-class Signal0_base
-{
-public:
- typedef R ReturnType;
- typedef Slot0<R> SlotType;
- typedef std::vector<SlotType*> SlotList;
-
-protected:
- SlotList m_slots;
-
-public:
- Signal0_base() { }
- Signal0_base(const Signal0_base<R>& s)
- {
- copy(s);
- }
- ~Signal0_base()
- {
- disconnectAll();
- }
-
- SlotType* addSlot(SlotType* slot)
- {
- m_slots.push_back(slot);
- return slot;
- }
-
- template<typename F>
- SlotType* connect(const F& f)
- {
- return addSlot(new Slot0_fun<R, F>(f));
- }
-
- template<class T>
- SlotType* connect(R (T::*m)(), T* t)
- {
- return addSlot(new Slot0_mem<R, T>(m, t));
- }
-
- const SlotList& getSlots() const
- {
- return m_slots;
- }
-
- void disconnect(SlotType* slot)
- {
- base::remove_from_container(m_slots, slot);
- }
-
- void disconnectAll()
- {
- typename SlotList::iterator end = m_slots.end();
- for (typename SlotList::iterator
- it = m_slots.begin(); it != end; ++it)
- delete *it;
- m_slots.clear();
- }
-
- bool empty() const
- {
- return m_slots.empty();
- }
-
- Signal0_base& operator=(const Signal0_base<R>& s) {
- copy(s);
- return *this;
- }
-
-private:
-
- void copy(const Signal0_base<R>& s)
- {
- typename SlotList::const_iterator end = s.m_slots.end();
- for (typename SlotList::const_iterator
- it = s.m_slots.begin(); it != end; ++it) {
- m_slots.push_back((*it)->clone());
- }
- }
-
-};
-
-// Signal0<R>
-template<typename R>
-class Signal0 : public Signal0_base<R>
-{
-public:
- Signal0() { }
-
- Signal0(const Signal0<R>& s)
- : Signal0_base<R>(s) { }
-
- R operator()(R default_result = R())
- {
- R result(default_result);
- typename Signal0_base<R>::SlotList::iterator end = Signal0_base<R>::m_slots.end();
- for (typename Signal0_base<R>::SlotList::iterator
- it = Signal0_base<R>::m_slots.begin(); it != end; ++it) {
- typename Signal0_base<R>::SlotType* slot = *it;
- result = (*slot)();
- }
- return result;
- }
-
- template<typename Merger>
- R operator()(R default_result, const Merger& m)
- {
- R result(default_result);
- Merger merger(m);
- typename Signal0_base<R>::SlotList::iterator end = Signal0_base<R>::m_slots.end();
- for (typename Signal0_base<R>::SlotList::iterator
- it = Signal0_base<R>::m_slots.begin(); it != end; ++it) {
- typename Signal0_base<R>::SlotType* slot = *it;
- result = merger(result, (*slot)());
- }
- return result;
- }
-
-};
-
-// Signal0<void>
-template<>
-class Signal0<void> : public Signal0_base<void>
-{
-public:
- Signal0() { }
-
- Signal0(const Signal0<void>& s)
- : Signal0_base<void>(s) { }
-
- void operator()()
- {
- SlotList::iterator end = m_slots.end();
- for (SlotList::iterator
- it = m_slots.begin(); it != end; ++it) {
- SlotType* slot = *it;
- (*slot)();
- }
- }
-
-};
-
-// Signal1_base<R, A1> - Base class to delegate responsibility to
-// functions of one argument.
-template<typename R, typename A1>
-class Signal1_base
-{
-public:
- typedef R ReturnType;
- typedef Slot1<R, A1> SlotType;
- typedef std::vector<SlotType*> SlotList;
-
-protected:
- SlotList m_slots;
-
-public:
- Signal1_base() { }
- Signal1_base(const Signal1_base<R, A1>& s)
- {
- copy(s);
- }
- ~Signal1_base()
- {
- disconnectAll();
- }
-
- SlotType* addSlot(SlotType* slot)
- {
- m_slots.push_back(slot);
- return slot;
- }
-
- template<typename F>
- SlotType* connect(const F& f)
- {
- return addSlot(new Slot1_fun<R, F, A1>(f));
- }
-
- template<class T>
- SlotType* connect(R (T::*m)(A1), T* t)
- {
- return addSlot(new Slot1_mem<R, T, A1>(m, t));
- }
-
- const SlotList& getSlots() const
- {
- return m_slots;
- }
-
- void disconnect(SlotType* slot)
- {
- base::remove_from_container(m_slots, slot);
- }
-
- void disconnectAll()
- {
- typename SlotList::iterator end = m_slots.end();
- for (typename SlotList::iterator
- it = m_slots.begin(); it != end; ++it)
- delete *it;
- m_slots.clear();
- }
-
- bool empty() const
- {
- return m_slots.empty();
- }
-
- Signal1_base& operator=(const Signal1_base<R, A1>& s) {
- copy(s);
- return *this;
- }
-
-private:
-
- void copy(const Signal1_base<R, A1>& s)
- {
- typename SlotList::const_iterator end = s.m_slots.end();
- for (typename SlotList::const_iterator
- it = s.m_slots.begin(); it != end; ++it) {
- m_slots.push_back((*it)->clone());
- }
- }
-
-};
-
-// Signal1<R, A1>
-template<typename R, typename A1>
-class Signal1 : public Signal1_base<R, A1>
-{
-public:
- Signal1() { }
-
- Signal1(const Signal1<R, A1>& s)
- : Signal1_base<R, A1>(s) { }
-
- R operator()(A1 a1, R default_result = R())
- {
- R result(default_result);
- typename Signal1_base<R, A1>::SlotList::iterator end = Signal1_base<R, A1>::m_slots.end();
- for (typename Signal1_base<R, A1>::SlotList::iterator
- it = Signal1_base<R, A1>::m_slots.begin(); it != end; ++it) {
- typename Signal1_base<R, A1>::SlotType* slot = *it;
- result = (*slot)(a1);
- }
- return result;
- }
-
- template<typename Merger>
- R operator()(A1 a1, R default_result, const Merger& m)
- {
- R result(default_result);
- Merger merger(m);
- typename Signal1_base<R, A1>::SlotList::iterator end = Signal1_base<R, A1>::m_slots.end();
- for (typename Signal1_base<R, A1>::SlotList::iterator
- it = Signal1_base<R, A1>::m_slots.begin(); it != end; ++it) {
- typename Signal1_base<R, A1>::SlotType* slot = *it;
- result = merger(result, (*slot)(a1));
- }
- return result;
- }
-
-};
-
-// Signal1<void, A1>
-template<typename A1>
-class Signal1<void, A1> : public Signal1_base<void, A1>
-{
-public:
- Signal1() { }
-
- Signal1(const Signal1<void, A1>& s)
- : Signal1_base<void, A1>(s) { }
-
- void operator()(A1 a1)
- {
- typename Signal1_base<void, A1>::SlotList::iterator end = Signal1_base<void, A1>::m_slots.end();
- for (typename Signal1_base<void, A1>::SlotList::iterator
- it = Signal1_base<void, A1>::m_slots.begin(); it != end; ++it) {
- typename Signal1_base<void, A1>::SlotType* slot = *it;
- (*slot)(a1);
- }
- }
-
-};
-
-// Signal2_base<R, A1, A2> - Base class to delegate responsibility to
-// functions of two arguments.
-template<typename R, typename A1, typename A2>
-class Signal2_base
-{
-public:
- typedef R ReturnType;
- typedef Slot2<R, A1, A2> SlotType;
- typedef std::vector<SlotType*> SlotList;
-
-protected:
- SlotList m_slots;
-
-public:
- Signal2_base() { }
- Signal2_base(const Signal2_base<R, A1, A2>& s)
- {
- copy(s);
- }
- ~Signal2_base()
- {
- disconnectAll();
- }
-
- SlotType* addSlot(SlotType* slot)
- {
- m_slots.push_back(slot);
- return slot;
- }
-
- template<typename F>
- SlotType* connect(const F& f)
- {
- return addSlot(new Slot2_fun<R, F, A1, A2>(f));
- }
-
- template<class T>
- SlotType* connect(R (T::*m)(A1, A2), T* t)
- {
- return addSlot(new Slot2_mem<R, T, A1, A2>(m, t));
- }
-
- const SlotList& getSlots() const
- {
- return m_slots;
- }
-
- void disconnect(SlotType* slot)
- {
- base::remove_from_container(m_slots, slot);
- }
-
- void disconnectAll()
- {
- typename SlotList::iterator end = m_slots.end();
- for (typename SlotList::iterator
- it = m_slots.begin(); it != end; ++it)
- delete *it;
- m_slots.clear();
- }
-
- bool empty() const
- {
- return m_slots.empty();
- }
-
- Signal2_base& operator=(const Signal2_base<R, A1, A2>& s) {
- copy(s);
- return *this;
- }
-
-private:
-
- void copy(const Signal2_base<R, A1, A2>& s)
- {
- typename SlotList::const_iterator end = s.m_slots.end();
- for (typename SlotList::const_iterator
- it = s.m_slots.begin(); it != end; ++it) {
- m_slots.push_back((*it)->clone());
- }
- }
-
-};
-
-// Signal2<R, A1>
-template<typename R, typename A1, typename A2>
-class Signal2 : public Signal2_base<R, A1, A2>
-{
-public:
- Signal2() { }
-
- Signal2(const Signal2<R, A1, A2>& s)
- : Signal2_base<R, A1, A2>(s) { }
-
- R operator()(A1 a1, A2 a2, R default_result = R())
- {
- R result(default_result);
- typename Signal2_base<R, A1, A2>::SlotList::iterator end = Signal2_base<R, A1, A2>::m_slots.end();
- for (typename Signal2_base<R, A1, A2>::SlotList::iterator
- it = Signal2_base<R, A1, A2>::m_slots.begin(); it != end; ++it) {
- typename Signal2_base<R, A1, A2>::SlotType* slot = *it;
- result = (*slot)(a1, a2);
- }
- return result;
- }
-
- template<typename Merger>
- R operator()(A1 a1, A2 a2, R default_result, const Merger& m)
- {
- R result(default_result);
- Merger merger(m);
- typename Signal2_base<R, A1, A2>::SlotList::iterator end = Signal2_base<R, A1, A2>::m_slots.end();
- for (typename Signal2_base<R, A1, A2>::SlotList::iterator
- it = Signal2_base<R, A1, A2>::m_slots.begin(); it != end; ++it) {
- typename Signal2_base<R, A1, A2>::SlotType* slot = *it;
- result = merger(result, (*slot)(a1, a2));
- }
- return result;
- }
-
-};
-
-// Signal2<void, A1>
-template<typename A1, typename A2>
-class Signal2<void, A1, A2> : public Signal2_base<void, A1, A2>
-{
-public:
- Signal2() { }
-
- Signal2(const Signal2<void, A1, A2>& s)
- : Signal2_base<void, A1, A2>(s) { }
-
- void operator()(A1 a1, A2 a2)
- {
- typename Signal2_base<void, A1, A2>::SlotList::iterator end = Signal2_base<void, A1, A2>::m_slots.end();
- for (typename Signal2_base<void, A1, A2>::SlotList::iterator
- it = Signal2_base<void, A1, A2>::m_slots.begin(); it != end; ++it) {
- typename Signal2_base<void, A1, A2>::SlotType* slot = *it;
- (*slot)(a1, a2);
- }
- }
-
-};
-
-#endif
diff --git a/Runtime/Lua/LuaBind/signal/slot.h b/Runtime/Lua/LuaBind/signal/slot.h deleted file mode 100644 index 226d382..0000000 --- a/Runtime/Lua/LuaBind/signal/slot.h +++ /dev/null @@ -1,203 +0,0 @@ -// Aseprite Base Library
-// Copyright (c) 2001-2013 David Capello
-//
-// This file is released under the terms of the MIT license.
-// Read LICENSE.txt for more information.
-
-#ifndef BASE_SLOT_H_INCLUDED
-#define BASE_SLOT_H_INCLUDED
-#pragma once
-
-// Slot0 - Base class for delegates of zero arguments.
-template<typename R>
-class Slot0
-{
-public:
- Slot0() { }
- Slot0(const Slot0& s) { (void)s; }
- virtual ~Slot0() { }
- virtual R operator()() = 0;
- virtual Slot0* clone() const = 0;
-};
-
-// Slot0_fun - hold a F instance and use the function call operator
-template<typename R, typename F>
-class Slot0_fun : public Slot0<R>
-{
- F f;
-public:
- Slot0_fun(const F& f) : f(f) { }
- Slot0_fun(const Slot0_fun& s) : Slot0<R>(s), f(s.f) { }
- ~Slot0_fun() { }
- R operator()() { return f(); }
- Slot0_fun* clone() const { return new Slot0_fun(*this); }
-};
-
-template<typename F>
-class Slot0_fun<void, F> : public Slot0<void>
-{
- F f;
-public:
- Slot0_fun(const F& f) : f(f) { }
- Slot0_fun(const Slot0_fun& s) : Slot0<void>(s), f(s.f) { }
- ~Slot0_fun() { }
- void operator()() { f(); }
- Slot0_fun* clone() const { return new Slot0_fun(*this); }
-};
-
-// Slot0_mem - pointer to a member function of the T class
-template<typename R, class T>
-class Slot0_mem : public Slot0<R>
-{
- R (T::*m)();
- T* t;
-public:
- Slot0_mem(R (T::*m)(), T* t) : m(m), t(t) { }
- Slot0_mem(const Slot0_mem& s) : Slot0<R>(s), m(s.m), t(s.t) { }
- ~Slot0_mem() { }
- R operator()() { return (t->*m)(); }
- Slot0_mem* clone() const { return new Slot0_mem(*this); }
-};
-
-template<class T>
-class Slot0_mem<void, T> : public Slot0<void>
-{
- void (T::*m)();
- T* t;
-public:
- Slot0_mem(void (T::*m)(), T* t) : m(m), t(t) { }
- Slot0_mem(const Slot0_mem& s) : Slot0<void>(s), m(s.m), t(s.t) { }
- ~Slot0_mem() { }
- void operator()() { (t->*m)(); }
- Slot0_mem* clone() const { return new Slot0_mem(*this); }
-};
-
-// Slot1 - Base class for delegates of one argument.
-template<typename R, typename A1>
-class Slot1
-{
-public:
- Slot1() { }
- Slot1(const Slot1& s) { (void)s; }
- virtual ~Slot1() { }
- virtual R operator()(A1 a1) = 0;
- virtual Slot1* clone() const = 0;
-};
-
-// Slot1_fun - hold a F instance and use the function call operator
-template<typename R, typename F, typename A1>
-class Slot1_fun : public Slot1<R, A1>
-{
- F f;
-public:
- Slot1_fun(const F& f) : f(f) { }
- Slot1_fun(const Slot1_fun& s) : Slot1<R, A1>(s), f(s.f) { }
- ~Slot1_fun() { }
- R operator()(A1 a1) { return f(a1); }
- Slot1_fun* clone() const { return new Slot1_fun(*this); }
-};
-
-template<typename F, typename A1>
-class Slot1_fun<void, F, A1> : public Slot1<void, A1>
-{
- F f;
-public:
- Slot1_fun(const F& f) : f(f) { }
- Slot1_fun(const Slot1_fun& s) : Slot1<void, A1>(s), f(s.f) { }
- ~Slot1_fun() { }
- void operator()(A1 a1) { f(a1); }
- Slot1_fun* clone() const { return new Slot1_fun(*this); }
-};
-
-// Slot1_mem - pointer to a member function of the T class
-template<typename R, class T, typename A1>
-class Slot1_mem : public Slot1<R, A1>
-{
- R (T::*m)(A1);
- T* t;
-public:
- Slot1_mem(R (T::*m)(A1), T* t) : m(m), t(t) { }
- Slot1_mem(const Slot1_mem& s) : Slot1<R, A1>(s), m(s.m), t(s.t) { }
- ~Slot1_mem() { }
- R operator()(A1 a1) { return (t->*m)(a1); }
- Slot1_mem* clone() const { return new Slot1_mem(*this); }
-};
-
-template<class T, typename A1>
-class Slot1_mem<void, T, A1> : public Slot1<void, A1>
-{
- void (T::*m)(A1);
- T* t;
-public:
- Slot1_mem(void (T::*m)(A1), T* t) : m(m), t(t) { }
- Slot1_mem(const Slot1_mem& s) : Slot1<void, A1>(s), m(s.m), t(s.t) { }
- ~Slot1_mem() { }
- void operator()(A1 a1) { (t->*m)(a1); }
- Slot1_mem* clone() const { return new Slot1_mem(*this); }
-};
-
-// Slot2 - Base class for delegates of two arguments.
-template<typename R, typename A1, typename A2>
-class Slot2
-{
-public:
- Slot2() { }
- Slot2(const Slot2& s) { (void)s; }
- virtual ~Slot2() { }
- virtual R operator()(A1 a1, A2 a2) = 0;
- virtual Slot2* clone() const = 0;
-};
-
-// Slot2_fun - hold a F instance and use the function call operator
-template<typename R, typename F, typename A1, typename A2>
-class Slot2_fun : public Slot2<R, A1, A2>
-{
- F f;
-public:
- Slot2_fun(const F& f) : f(f) { }
- Slot2_fun(const Slot2_fun& s) : Slot2<R, A1, A2>(s), f(s.f) { }
- ~Slot2_fun() { }
- R operator()(A1 a1, A2 a2) { return f(a1, a2); }
- Slot2_fun* clone() const { return new Slot2_fun(*this); }
-};
-
-template<typename F, typename A1, typename A2>
-class Slot2_fun<void, F, A1, A2> : public Slot2<void, A1, A2>
-{
- F f;
-public:
- Slot2_fun(const F& f) : f(f) { }
- Slot2_fun(const Slot2_fun& s) : Slot2<void, A1, A2>(s), f(s.f) { }
- ~Slot2_fun() { }
- void operator()(A1 a1, A2 a2) { f(a1, a2); }
- Slot2_fun* clone() const { return new Slot2_fun(*this); }
-};
-
-// Slot2_mem - pointer to a member function of the T class
-template<typename R, class T, typename A1, typename A2>
-class Slot2_mem : public Slot2<R, A1, A2>
-{
- R (T::*m)(A1, A2);
- T* t;
-public:
- Slot2_mem(R (T::*m)(A1, A2), T* t) : m(m), t(t) { }
- Slot2_mem(const Slot2_mem& s) : Slot2<R, A1, A2>(s), m(s.m), t(s.t) { }
- ~Slot2_mem() { }
- R operator()(A1 a1, A2 a2) { return (t->*m)(a1, a2); }
- Slot2_mem* clone() const { return new Slot2_mem(*this); }
-};
-
-template<class T, typename A1, typename A2>
-class Slot2_mem<void, T, A1, A2> : public Slot2<void, A1, A2>
-{
- void (T::*m)(A1, A2);
- T* t;
-public:
- Slot2_mem(void (T::*m)(A1, A2), T* t) : m(m), t(t) { }
- Slot2_mem(const Slot2_mem& s) : Slot2<void, A1, A2>(s), m(s.m), t(s.t) { }
- ~Slot2_mem() { }
- void operator()(A1 a1, A2 a2) { return (t->*m)(a1, a2); }
- Slot2_mem* clone() const { return new Slot2_mem(*this); }
-};
-
-#endif
diff --git a/Runtime/Scripting/ScriptingChecks.h b/Runtime/Scripting/ScriptingChecks.h new file mode 100644 index 0000000..d8bb742 --- /dev/null +++ b/Runtime/Scripting/ScriptingChecks.h @@ -0,0 +1,7 @@ +#pragma once + +// ̵ֻ߳ +#define SCRIPTING_CHECK_THREAD(methodName) + +// ֻЭ̵ +#define SCRIPTING_CHECK_COROUTINE(methodName) |