From 22e576b5aa065f3cb2ca67a951af5e68063419a2 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 18 Oct 2021 02:12:30 +0800 Subject: *scripting --- Editor/EditorMain.cpp | 12 +-- Editor/GUI/EditorWindows.h | 2 +- Editor/GUI/GUIWindow.cpp | 2 +- .../Scripting/EditorGUI/ContainerWindow.bind.cpp | 8 ++ Editor/Scripting/EditorGUI/EditorGUI.bind.cpp | 11 +-- Editor/Scripting/EditorScripting.cpp | 20 +++-- Editor/Utils/Log.cpp | 94 ---------------------- Editor/Utils/Log.h | 22 ----- Projects/VisualStudio/Editor/Editor.vcxproj | 13 +-- .../VisualStudio/Editor/Editor.vcxproj.filters | 33 +++++--- Resources/Scripts/EditorApplication.lua | 18 +++-- Runtime/Graphics/OpenGL.cpp | 3 + Runtime/ImGUI/GUIButton.cpp | 0 Runtime/ImGUI/GUIButton.h | 6 -- Runtime/ImGUI/GUILabel.cpp | 0 Runtime/ImGUI/GUILabel.h | 0 Runtime/LuaBind/LuaBindCFunctions.h | 21 ++++- Runtime/LuaBind/LuaBindState.cpp | 33 +++++++- Runtime/Scripting/GL.bind.cpp | 9 --- Runtime/Scripting/GL/GL.bind.cpp | 9 +++ 20 files changed, 135 insertions(+), 181 deletions(-) delete mode 100644 Editor/Utils/Log.cpp delete mode 100644 Editor/Utils/Log.h delete mode 100644 Runtime/ImGUI/GUIButton.cpp delete mode 100644 Runtime/ImGUI/GUIButton.h delete mode 100644 Runtime/ImGUI/GUILabel.cpp delete mode 100644 Runtime/ImGUI/GUILabel.h delete mode 100644 Runtime/Scripting/GL.bind.cpp create mode 100644 Runtime/Scripting/GL/GL.bind.cpp diff --git a/Editor/EditorMain.cpp b/Editor/EditorMain.cpp index 9745598..1606e94 100644 --- a/Editor/EditorMain.cpp +++ b/Editor/EditorMain.cpp @@ -35,13 +35,6 @@ static int MainLoop() return (INT)msg.wParam; } -void OpenLogTags() -{ - //log_open_tag("WndProc"); - //log_open_tag("Menu"); - log_open_tag("Scripting"); -} - void InitLuaState() { LuaBind::VM vm; @@ -61,11 +54,10 @@ int main() int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) #endif { - OpenLogTags(); - WindowUtil::Init(); - InitLuaState(); + WindowUtil::Init(); + ContainnerWindow* wnd = new ContainnerWindow(); Vector2f min = Vector2f(100, 100); Vector2f max = Vector2f(700, 700); diff --git a/Editor/GUI/EditorWindows.h b/Editor/GUI/EditorWindows.h index 42d2623..307ab86 100644 --- a/Editor/GUI/EditorWindows.h +++ b/Editor/GUI/EditorWindows.h @@ -6,7 +6,7 @@ #include "Runtime/Math/Rect.h" #include "Runtime/LuaBind/LuaBind.h" #include "Runtime/Utilities/Singleton.h" -#include "Editor/Utils/Log.h" +#include "Runtime/Debug/Log.h" #include "Runtime/Graphics/OpenGL.h" #include "Runtime/Utilities/UtilMacros.h" #include "Editor/Utils/HelperFuncs.h" diff --git a/Editor/GUI/GUIWindow.cpp b/Editor/GUI/GUIWindow.cpp index e58b620..3df0370 100644 --- a/Editor/GUI/GUIWindow.cpp +++ b/Editor/GUI/GUIWindow.cpp @@ -56,7 +56,7 @@ LRESULT CALLBACK GUIWindow::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wPara case WM_MOUSEWHEEL: // 在这个子窗口滚动 { - log_info("WM_MOUSEWHEEL"); + log_info("WndProc","WM_MOUSEWHEEL"); // quick check if mouse is in our window RECT rc; diff --git a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp b/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp index f51b6b4..265ea2e 100644 --- a/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp +++ b/Editor/Scripting/EditorGUI/ContainerWindow.bind.cpp @@ -10,6 +10,14 @@ LUA_BIND_REGISTRY(ContainnerWindow) LUA_BIND_POSTPROCESS(ContainnerWindow) { + 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(ContainnerWindow, _SetTitle) diff --git a/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp b/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp index be97638..57c45ca 100644 --- a/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp +++ b/Editor/Scripting/EditorGUI/EditorGUI.bind.cpp @@ -1,21 +1,18 @@ #include "Editor/GUI/EditorWindows.h" // GameLab.Editor.GUI -void luaopen_GameLab_Editor_GUI(lua_State* L) +int luaopen_GameLab_Editor_GUI(lua_State* L) { + log_info("Scripting", "luaopen_GameLab_Editor_GUI()"); + LUA_BIND_STATE(L); state.PushGlobalNamespace(); - state.PushNamespace("GameLab"); state.PushNamespace("Editor"); state.PushNamespace("GUI"); state.RegisterFactory(); - state.PopNamespace();// EditorGUI - state.PopNamespace();// GameLab - state.PopNamespace();// Editor - state.PopNamespace();// Global - + return 1; } \ No newline at end of file diff --git a/Editor/Scripting/EditorScripting.cpp b/Editor/Scripting/EditorScripting.cpp index 235636a..65fa8c4 100644 --- a/Editor/Scripting/EditorScripting.cpp +++ b/Editor/Scripting/EditorScripting.cpp @@ -1,22 +1,28 @@ #include "EditorScripting.h" -#include "Editor/Utils/Log.h" +#include "Runtime/Debug/Log.h" // GameLab.Editor -extern void luaopen_GameLab_Editor_GUI(lua_State* L); // GameLab.Editor.GUI -extern void luaopen_GameLab_Editor_GUILayout(lua_State* L); // GameLab.Editor.GUILayout -extern void luaopen_GameLab_Editor_IMGUI(lua_State* L); // GameLab.Editor.IMGUI -extern void luaopen_GameLab_Editor_Resource(lua_State* L); // GameLab.Editor.Resource +extern int luaopen_GameLab_Editor_GUI(lua_State* L); // GameLab.Editor.GUI +extern int luaopen_GameLab_Editor_GUILayout(lua_State* L); // GameLab.Editor.GUILayout +extern int luaopen_GameLab_Editor_IMGUI(lua_State* L); // GameLab.Editor.IMGUI +extern int luaopen_GameLab_Editor_Resource(lua_State* L); // GameLab.Editor.Resource // GameLab.Engine +extern int luaopen_GameLab_Engine_Rendering(lua_State* L); // GameLab.Engine.Rendering // GameLab -extern void luaopen_GameLab_Debug(lua_State* L); +extern int luaopen_GameLab_Debug(lua_State* L); + +#define openlib(cfunc) \ + lua_pushcfunction(L, cfunc);\ + lua_call(L, 0, 0); bool SetupGameLabEditorScripting(lua_State* L) { log_info("Scripting", "SetupGameLabEditorScripting()"); - luaopen_GameLab_Editor_GUI(L); + openlib(luaopen_GameLab_Debug); + openlib(luaopen_GameLab_Editor_GUI); return true; } diff --git a/Editor/Utils/Log.cpp b/Editor/Utils/Log.cpp deleted file mode 100644 index 9ec7d42..0000000 --- a/Editor/Utils/Log.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "log.h" -#include -#include -#include -#include "HelperFuncs.h" - -using namespace std; - -//long g_LogTags = LogTag::All; -unordered_set s_OpenTags; - -#ifdef GAMELAB_DEBUG -// https://stackoverflow.com/questions/997946/how-to-get-current-time-and-date-in-c -// Get current date/time, format is YYYY-MM-DD.HH:mm:ss -const std::string currentDateTime() { - time_t now = time(0); - struct tm tstruct; - char buf[80]; - tstruct = *localtime(&now); - // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime - // for more information about date/time format - strftime(buf, sizeof(buf), "%Y-%m-%d %X", &tstruct); - - return buf; -} - -void log_open_tag(std::string tag) -{ - s_OpenTags.insert(tag); -} - -// https://stackoverflow.com/questions/4053837/colorizing-text-in-the-console-with-c - -void log_info(std::string log) -{ - cout << "\x1B[97m" << currentDateTime() << " [Info] " << log << "\033[0m" << endl; -} - -void log_warning(std::string log) -{ - cout << "\x1B[93m" << currentDateTime() << " [Wanning] " << log << "\033[0m" << endl; -} - -void log_error(std::string log) -{ - cout << "\x1B[91m" << currentDateTime() << " [Error] " << log << "\033[0m" << endl; -} - -void log_error_null_param(std::string funcName, std::string param) -{ - log_error("Null parameter in " + funcName + " called " + param); -} - -void log_info(string tag, std::string log) -{ - if (s_OpenTags.count(tag) <= 0) - return; - log_info("[" + tag + "] " + log); -} -void log_warning(string tag, std::string log) -{ - if (s_OpenTags.count(tag) <= 0) - return; - log_warning("[" + tag + "] " + log); -} -void log_error(string tag, std::string log) -{ - if (s_OpenTags.count(tag) <= 0) - return; - log_error("[" + tag + "] " + log); -} -#else -void log_open_tag(std::string tag) {} -void log_info(std::string log) -{ -} - -void log_warning(std::string log) -{ -} - -void log_error(std::string log) -{ -} - -void log_error_null_param(std::string funcName, std::string param) -{ -} - -void log_info(string tag, std::string log) {} -void log_warning(string tag, std::string log) {} -void log_error(string tag, std::string log) {} - -#endif \ No newline at end of file diff --git a/Editor/Utils/Log.h b/Editor/Utils/Log.h deleted file mode 100644 index d66f705..0000000 --- a/Editor/Utils/Log.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include - -//enum LogTag : unsigned long -//{ -// -// All = ~0 -//}; -// -//extern long g_LogTags; - -void log_open_tag(std::string tag); - -void log_info(std::string log); -void log_warning(std::string log); -void log_error(std::string log); - -void log_error_null_param(std::string funcName, std::string param); - -void log_info(std::string tag, std::string log); -void log_warning(std::string tag, std::string log); -void log_error(std::string tag, std::string log); diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj b/Projects/VisualStudio/Editor/Editor.vcxproj index 14bdfb3..972d606 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj +++ b/Projects/VisualStudio/Editor/Editor.vcxproj @@ -87,12 +87,12 @@ Disabled true true - _CRT_SECURE_NO_WARNINGS;GAMELAB_DEBUG;%(PreprocessorDefinitions) + _CRT_SECURE_NO_WARNINGS;GAMELAB_DEBUG;GAMELAB_EDITOR;%(PreprocessorDefinitions) $(SolutionDir)..\..\;$(SolutionDir)..\..\ThirdParty\;%(AdditionalIncludeDirectories) Console - opengl32.lib;%(AdditionalDependencies) + %(AdditionalDependencies) @@ -163,7 +163,8 @@ - + + @@ -175,7 +176,8 @@ - + + @@ -190,7 +192,8 @@ - + + diff --git a/Projects/VisualStudio/Editor/Editor.vcxproj.filters b/Projects/VisualStudio/Editor/Editor.vcxproj.filters index cf4698b..7aff217 100644 --- a/Projects/VisualStudio/Editor/Editor.vcxproj.filters +++ b/Projects/VisualStudio/Editor/Editor.vcxproj.filters @@ -55,6 +55,12 @@ {707a995f-6856-44c8-857c-14e7834e86e3} + + {df6cfcb1-ec0a-4b6d-b80d-8ee197425509} + + + {be13ccc9-0b31-4d22-b512-e2a05d7f3c5b} + @@ -84,9 +90,6 @@ Editor\GUI - - Editor\Utils - Editor\GUI @@ -159,12 +162,21 @@ Runtime\LuaBind - - Runtime\Scripting\GL - Editor\Shaders + + Runtime\Debug + + + Runtime\Scripting\GL + + + Runtime\Scripting\Debug + + + Runtime\Graphics + @@ -218,9 +230,6 @@ Editor\GUI - - Editor\Utils - Editor\GUI @@ -284,6 +293,12 @@ Editor\Shaders + + Runtime\Debug + + + Runtime\Graphics + diff --git a/Resources/Scripts/EditorApplication.lua b/Resources/Scripts/EditorApplication.lua index 79686ba..935547d 100644 --- a/Resources/Scripts/EditorApplication.lua +++ b/Resources/Scripts/EditorApplication.lua @@ -1,11 +1,19 @@ local Debug = GameLab.Debug +local GUI = GameLab.Editor.GUI +Debug.OpenTag("WndProc") -local i = 10 -while i > 0 do +Debug.Log("WndProc", "123") -i= i-1 -print(1) +local i = 0 +while i < 10 do + + i = i + 1 + Debug.Log(i) + +end + + +Debug.Log(GUI.EShowMode.NoShadow) -end diff --git a/Runtime/Graphics/OpenGL.cpp b/Runtime/Graphics/OpenGL.cpp index e69de29..e0dc8f1 100644 --- a/Runtime/Graphics/OpenGL.cpp +++ b/Runtime/Graphics/OpenGL.cpp @@ -0,0 +1,3 @@ +#include "OpenGL.h" + +#pragma comment(lib, "opengl32.lib") diff --git a/Runtime/ImGUI/GUIButton.cpp b/Runtime/ImGUI/GUIButton.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Runtime/ImGUI/GUIButton.h b/Runtime/ImGUI/GUIButton.h deleted file mode 100644 index fbcd0bb..0000000 --- a/Runtime/ImGUI/GUIButton.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef GUI_BUTTON_H -#define GUI_BUTTON_H - - - -#endif \ No newline at end of file diff --git a/Runtime/ImGUI/GUILabel.cpp b/Runtime/ImGUI/GUILabel.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/Runtime/ImGUI/GUILabel.h b/Runtime/ImGUI/GUILabel.h deleted file mode 100644 index e69de29..0000000 diff --git a/Runtime/LuaBind/LuaBindCFunctions.h b/Runtime/LuaBind/LuaBindCFunctions.h index 25ccbc2..f0f07dd 100644 --- a/Runtime/LuaBind/LuaBindCFunctions.h +++ b/Runtime/LuaBind/LuaBindCFunctions.h @@ -10,16 +10,29 @@ namespace { - // // 获得第一个upvalue - // extern int luax_c_getupvalue(lua_State* L); - // // 调用此函数时会报错,upvalue(1)是错误信息 - // extern int luax_c_errfunc(lua_State* L); +#define luax_is(T, L, i) (lua_is##T(L, i)) +#define luax_isnumber(L, i) luax_is(number, L, i) + + inline int luax_isinteger(lua_State* L, int i) + { + if (!luax_isnumber(L, i)) + return 0; + return lua_tonumber(L, i) == lua_tointeger(L, i); + } + + inline int luax_isfloat(lua_State* L, int i) + { + if (!luax_isnumber(L, i)) + return 0; + return lua_tonumber(L, i) != lua_tointeger(L, i); + } + } #endif \ No newline at end of file diff --git a/Runtime/LuaBind/LuaBindState.cpp b/Runtime/LuaBind/LuaBindState.cpp index a9520a8..4ee87f4 100644 --- a/Runtime/LuaBind/LuaBindState.cpp +++ b/Runtime/LuaBind/LuaBindState.cpp @@ -4,6 +4,8 @@ #include "LuaBindClass.hpp" #include "LuaBindInternal.h" +#include + namespace LuaBind { @@ -40,6 +42,7 @@ namespace LuaBind void State::PushGlobalNamespace() { +#if false int top = GetTop(); lua_newtable(mState); // pseudo namespace table @@ -59,6 +62,9 @@ namespace LuaBind // stack: // -1 pseudo global namespace +#else + lua_pushvalue(mState, LUA_GLOBALSINDEX); +#endif } void State::PushNamespace(cc8* name) @@ -533,13 +539,38 @@ namespace LuaBind return value; } - + static std::string s_str; template <> cc8* State::GetValue < cc8* >(int idx, const cc8* value) { if (this->IsType(idx, LUA_TSTRING)) { return lua_tostring(this->mState, idx); } + + if (this->IsType(idx, LUA_TNUMBER)) { + if (luax_isinteger(mState, -1)) { + int num = lua_tointeger(this->mState, idx); + s_str = std::to_string(num); + cc8* str = s_str.c_str(); + return str; + } + else { + float num = lua_tonumber(this->mState, idx); + s_str = std::to_string(num); + cc8* str = s_str.c_str(); + return str; + } + } + + if (this->IsType(idx, LUA_TBOOLEAN)) { + bool b = lua_toboolean(this->mState, idx); + return b ? "true" : "false"; + } + + if (this->IsType(idx, LUA_TNIL)) { + return "NIL"; + } + return value; } diff --git a/Runtime/Scripting/GL.bind.cpp b/Runtime/Scripting/GL.bind.cpp deleted file mode 100644 index 57dba09..0000000 --- a/Runtime/Scripting/GL.bind.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Runtime/Graphics/OpenGL.h" -#include "Runtime/LuaBind/LuaBind.h" - -// GameLab.Engine.GL -void luaopen_GameLab_Engine_GL(lua_State* L) -{ - LUA_BIND_STATE(L); - -} diff --git a/Runtime/Scripting/GL/GL.bind.cpp b/Runtime/Scripting/GL/GL.bind.cpp new file mode 100644 index 0000000..57dba09 --- /dev/null +++ b/Runtime/Scripting/GL/GL.bind.cpp @@ -0,0 +1,9 @@ +#include "Runtime/Graphics/OpenGL.h" +#include "Runtime/LuaBind/LuaBind.h" + +// GameLab.Engine.GL +void luaopen_GameLab_Engine_GL(lua_State* L) +{ + LUA_BIND_STATE(L); + +} -- cgit v1.1-26-g67d0