Added Lua GLOBALS
This commit is contained in:
parent
90fb92c3ae
commit
7e2769ac9e
44
imgui.ini
44
imgui.ini
@ -10,24 +10,24 @@ Collapsed=1
|
|||||||
|
|
||||||
[Window][WindowOverViewport_11111111]
|
[Window][WindowOverViewport_11111111]
|
||||||
Pos=0,19
|
Pos=0,19
|
||||||
Size=1920,1158
|
Size=1280,701
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Inspector]
|
[Window][Inspector]
|
||||||
Pos=1553,19
|
Pos=913,19
|
||||||
Size=367,659
|
Size=367,202
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000018,0
|
DockId=0x00000018,0
|
||||||
|
|
||||||
[Window][Scene Tree]
|
[Window][Scene Tree]
|
||||||
Pos=0,19
|
Pos=0,19
|
||||||
Size=335,579
|
Size=335,350
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x0000000F,0
|
DockId=0x0000001B,0
|
||||||
|
|
||||||
[Window][Viewport]
|
[Window][Viewport]
|
||||||
Pos=337,19
|
Pos=337,19
|
||||||
Size=1214,659
|
Size=574,202
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000017,0
|
DockId=0x00000017,0
|
||||||
|
|
||||||
@ -36,14 +36,14 @@ Size=1280,19
|
|||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Performance Info]
|
[Window][Performance Info]
|
||||||
Pos=1628,680
|
Pos=1106,223
|
||||||
Size=292,268
|
Size=174,268
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000019,0
|
DockId=0x00000019,0
|
||||||
|
|
||||||
[Window][Console]
|
[Window][Console]
|
||||||
Pos=337,680
|
Pos=337,223
|
||||||
Size=1238,497
|
Size=736,497
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000013,0
|
DockId=0x00000013,0
|
||||||
|
|
||||||
@ -78,8 +78,8 @@ Collapsed=0
|
|||||||
DockId=0x00000015,1
|
DockId=0x00000015,1
|
||||||
|
|
||||||
[Window][Color Correction]
|
[Window][Color Correction]
|
||||||
Pos=1628,950
|
Pos=1106,493
|
||||||
Size=292,227
|
Size=174,227
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x0000001A,0
|
DockId=0x0000001A,0
|
||||||
|
|
||||||
@ -113,8 +113,8 @@ Collapsed=0
|
|||||||
DockId=0x0000000E,0
|
DockId=0x0000000E,0
|
||||||
|
|
||||||
[Window][Audio Output]
|
[Window][Audio Output]
|
||||||
Pos=1577,680
|
Pos=1075,223
|
||||||
Size=49,497
|
Size=29,497
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000012,0
|
DockId=0x00000012,0
|
||||||
|
|
||||||
@ -125,8 +125,8 @@ Collapsed=0
|
|||||||
DockId=0x0000000D,0
|
DockId=0x0000000D,0
|
||||||
|
|
||||||
[Window][Resources]
|
[Window][Resources]
|
||||||
Pos=0,600
|
Pos=0,371
|
||||||
Size=335,577
|
Size=335,349
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000010,0
|
DockId=0x00000010,0
|
||||||
|
|
||||||
@ -135,17 +135,25 @@ Pos=584,22
|
|||||||
Size=536,391
|
Size=536,391
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][Lua Globals]
|
||||||
|
Pos=0,482
|
||||||
|
Size=335,116
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x0000001C,0
|
||||||
|
|
||||||
[Table][0x96376740,2]
|
[Table][0x96376740,2]
|
||||||
RefScale=13
|
RefScale=13
|
||||||
Column 0 Weight=1.0000
|
Column 0 Weight=1.0000
|
||||||
Column 1 Width=120
|
Column 1 Width=120
|
||||||
|
|
||||||
[Docking][Data]
|
[Docking][Data]
|
||||||
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1920,1158 Split=X
|
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1280,701 Split=X
|
||||||
DockNode ID=0x00000005 Parent=0x11111111 SizeRef=989,1158 Split=X
|
DockNode ID=0x00000005 Parent=0x11111111 SizeRef=989,1158 Split=X
|
||||||
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=335,701 Split=Y Selected=0x12EF0F59
|
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=335,701 Split=Y Selected=0x12EF0F59
|
||||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=342,637 Split=Y Selected=0x12EF0F59
|
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=342,637 Split=Y Selected=0x12EF0F59
|
||||||
DockNode ID=0x0000000F Parent=0x00000003 SizeRef=342,579 HiddenTabBar=1 Selected=0x12EF0F59
|
DockNode ID=0x0000000F Parent=0x00000003 SizeRef=342,579 Split=Y Selected=0x12EF0F59
|
||||||
|
DockNode ID=0x0000001B Parent=0x0000000F SizeRef=335,461 HiddenTabBar=1 Selected=0x12EF0F59
|
||||||
|
DockNode ID=0x0000001C Parent=0x0000000F SizeRef=335,116 HiddenTabBar=1 Selected=0x8CFF897F
|
||||||
DockNode ID=0x00000010 Parent=0x00000003 SizeRef=342,577 HiddenTabBar=1 Selected=0x30401527
|
DockNode ID=0x00000010 Parent=0x00000003 SizeRef=342,577 HiddenTabBar=1 Selected=0x30401527
|
||||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=342,519 HiddenTabBar=1 Selected=0x36AF052B
|
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=342,519 HiddenTabBar=1 Selected=0x36AF052B
|
||||||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=943,701 Split=Y Selected=0xC450F867
|
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=943,701 Split=Y Selected=0xC450F867
|
||||||
|
@ -1,4 +1,2 @@
|
|||||||
[COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -Isrc/vendor/xxhash -Isrc/vendor/miniaudio -Isrc/vendor/imguizmo -IC:/msys64/mingw64/include -IC:\msys64\mingw64\lib\libyaml-cpp.a -Isrc\vendor\imgui -MMD -MP -c src\src\core\functions\ScenePacker.cpp -o src\build\core\functions\ScenePacker.o
|
[COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -Isrc/vendor/xxhash -Isrc/vendor/miniaudio -Isrc/vendor/imguizmo -IC:/msys64/mingw64/include -IC:\msys64\mingw64\lib\libyaml-cpp.a -Isrc\vendor\imgui -MMD -MP -c src\src\Engine.cpp -o src\build\Engine.o
|
||||||
[LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\AnimationComponent.o src\build\Components\AudioPlayerComponent.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.o src\build\Components\ParticleComponent.o src\build\Components\PhysicsComponent.o src\build\Components\ScriptComponent.o src\build\Components\SpriteComponent.o src\build\Components\TextComonent.o src\build\Components\TilemapComponent.o src\build\core\audio\AudioEngine.o src\build\core\functions\Prefab.o src\build\core\functions\ScenePacker.o src\build\core\utils\AssetManager.o src\build\core\utils\EngineConfig.o src\build\core\utils\ExceptionHandler.o src\build\core\utils\FileDialog.o src\build\core\utils\input.o src\build\core\utils\LoadingWindow.o src\build\core\utils\Logging.o src\build\core\utils\Popup.o src\build\core\utils\Profiler.o src\build\core\utils\Texture.o src\build\core\utils\utils.o src\build\editor\windows\AssetBrowser.o src\build\editor\windows\AudioInfo.o src\build\editor\windows\Inspector.o src\build\Entitys\Object.o src\build\utils\GameObjectsList.o src\build\utils\Shader.o src\build\utils\UID.o src\build\lapi.o src\build\lauxlib.o src\build\lbaselib.o src\build\lcode.o src\build\lcorolib.o src\build\lctype.o src\build\ldblib.o src\build\ldebug.o src\build\ldo.o src\build\ldump.o src\build\lfunc.o src\build\lgc.o src\build\linit.o src\build\liolib.o src\build\llex.o src\build\lmathlib.o src\build\lmem.o src\build\loadlib.o src\build\lobject.o src\build\lopcodes.o src\build\loslib.o src\build\lparser.o src\build\lstate.o src\build\lstring.o src\build\lstrlib.o src\build\ltable.o src\build\ltablib.o src\build\ltm.o src\build\lua.o src\build\luac.o src\build\lundump.o src\build\lutf8lib.o src\build\lvm.o src\build\lzio.o src\build\imgui.o src\build\imgui_demo.o src\build\imgui_draw.o src\build\imgui_impl_glfw.o src\build\imgui_impl_opengl3.o src\build\imgui_tables.o src\build\imgui_widgets.o src\build\aabb.o src\build\arena_allocator.o src\build\array.o src\build\bitset.o src\build\body.o src\build\broad_phase.o src\build\constraint_graph.o src\build\contact.o src\build\contact_solver.o src\build\core.o src\build\distance.o src\build\distance_joint.o src\build\dynamic_tree.o src\build\geometry.o src\build\hull.o src\build\id_pool.o src\build\island.o src\build\joint.o src\build\manifold.o src\build\math_functions.o src\build\motor_joint.o src\build\mouse_joint.o src\build\mover.o src\build\prismatic_joint.o src\build\revolute_joint.o src\build\sensor.o src\build\shape.o src\build\solver.o src\build\solver_set.o src\build\table.o src\build\timer.o src\build\types.o src\build\weld_joint.o src\build\wheel_joint.o src\build\world.o src\build\xxhash.o src\build\miniaudio.o src\build\ImGuizmo.o -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto -ldbghelp -lz
|
[LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\AnimationComponent.o src\build\Components\AudioPlayerComponent.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.o src\build\Components\ParticleComponent.o src\build\Components\PhysicsComponent.o src\build\Components\ScriptComponent.o src\build\Components\SpriteComponent.o src\build\Components\TextComonent.o src\build\Components\TilemapComponent.o src\build\core\audio\AudioEngine.o src\build\core\functions\Prefab.o src\build\core\functions\ScenePacker.o src\build\core\scripts\LuaGlobalBridge.o src\build\core\utils\AssetManager.o src\build\core\utils\EngineConfig.o src\build\core\utils\ExceptionHandler.o src\build\core\utils\FileDialog.o src\build\core\utils\input.o src\build\core\utils\LoadingWindow.o src\build\core\utils\Logging.o src\build\core\utils\Popup.o src\build\core\utils\Profiler.o src\build\core\utils\Texture.o src\build\core\utils\utils.o src\build\editor\windows\AssetBrowser.o src\build\editor\windows\AudioInfo.o src\build\editor\windows\Inspector.o src\build\editor\windows\LuaGlobals.o src\build\Entitys\Object.o src\build\utils\GameObjectsList.o src\build\utils\Shader.o src\build\utils\UID.o src\build\lapi.o src\build\lauxlib.o src\build\lbaselib.o src\build\lcode.o src\build\lcorolib.o src\build\lctype.o src\build\ldblib.o src\build\ldebug.o src\build\ldo.o src\build\ldump.o src\build\lfunc.o src\build\lgc.o src\build\linit.o src\build\liolib.o src\build\llex.o src\build\lmathlib.o src\build\lmem.o src\build\loadlib.o src\build\lobject.o src\build\lopcodes.o src\build\loslib.o src\build\lparser.o src\build\lstate.o src\build\lstring.o src\build\lstrlib.o src\build\ltable.o src\build\ltablib.o src\build\ltm.o src\build\lua.o src\build\luac.o src\build\lundump.o src\build\lutf8lib.o src\build\lvm.o src\build\lzio.o src\build\imgui.o src\build\imgui_demo.o src\build\imgui_draw.o src\build\imgui_impl_glfw.o src\build\imgui_impl_opengl3.o src\build\imgui_tables.o src\build\imgui_widgets.o src\build\aabb.o src\build\arena_allocator.o src\build\array.o src\build\bitset.o src\build\body.o src\build\broad_phase.o src\build\constraint_graph.o src\build\contact.o src\build\contact_solver.o src\build\core.o src\build\distance.o src\build\distance_joint.o src\build\dynamic_tree.o src\build\geometry.o src\build\hull.o src\build\id_pool.o src\build\island.o src\build\joint.o src\build\manifold.o src\build\math_functions.o src\build\motor_joint.o src\build\mouse_joint.o src\build\mover.o src\build\prismatic_joint.o src\build\revolute_joint.o src\build\sensor.o src\build\shape.o src\build\solver.o src\build\solver_set.o src\build\table.o src\build\timer.o src\build\types.o src\build\weld_joint.o src\build\wheel_joint.o src\build\world.o src\build\xxhash.o src\build\miniaudio.o src\build\ImGuizmo.o -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto -ldbghelp -lz
|
||||||
[ERROR] Runtime crash
|
|
||||||
Command 'src\build\app.exe' returned non-zero exit status 3221225477.
|
|
||||||
|
4
src/assets/lua/add_health.lua
Normal file
4
src/assets/lua/add_health.lua
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
function OnUpdate(dt)
|
||||||
|
local hp = Engine.GetGlobal("player_health") or 0
|
||||||
|
Engine.SetGlobal("player_health", hp + 1)
|
||||||
|
end
|
8
src/assets/lua/get_health.lua
Normal file
8
src/assets/lua/get_health.lua
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
function OnUpdate(dt)
|
||||||
|
local hp = Engine.GetGlobal("player_health")
|
||||||
|
if hp ~= nil then
|
||||||
|
print("Player Health:", hp)
|
||||||
|
else
|
||||||
|
print("player_health is nil")
|
||||||
|
end
|
||||||
|
end
|
23
src/assets/scenes/lua_stesting.cene
Normal file
23
src/assets/scenes/lua_stesting.cene
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
engine_version: 0.8.3
|
||||||
|
scene_name: lua_stesting
|
||||||
|
scene_hash: b1e82bcabfb7fb81c42d1bf6ad852ae165648f6134d1a64ae35bb761bd1b626b
|
||||||
|
format_version: 1
|
||||||
|
objects:
|
||||||
|
- name: Hello, Create
|
||||||
|
uid: b0a9e03bdb314b6eb50f3b3eaa6097bc
|
||||||
|
id: 0
|
||||||
|
position: [0, 0]
|
||||||
|
rotation: 0
|
||||||
|
layer: 0
|
||||||
|
visable: true
|
||||||
|
components: []
|
||||||
|
children: []
|
||||||
|
color_correction:
|
||||||
|
brightness: 1
|
||||||
|
saturation: 1
|
||||||
|
gamma: 1
|
||||||
|
bloom: false
|
||||||
|
intensity: 1.20000005
|
||||||
|
threshold: 1
|
||||||
|
Assets:
|
||||||
|
[]
|
@ -20,9 +20,53 @@
|
|||||||
#include "../core/types/vec2.h"
|
#include "../core/types/vec2.h"
|
||||||
#include "../core/types/vec3.h"
|
#include "../core/types/vec3.h"
|
||||||
|
|
||||||
#include <lua.hpp>
|
#include "../core/scripts/LuaGlobalBridge.h"
|
||||||
#include <memory>
|
|
||||||
#include <cstring>
|
static int Lua_SetGlobal(lua_State *L)
|
||||||
|
{
|
||||||
|
const char *key = luaL_checkstring(L, 1);
|
||||||
|
|
||||||
|
switch (lua_type(L, 2))
|
||||||
|
{
|
||||||
|
case LUA_TNUMBER:
|
||||||
|
LuaGlobalBridge::Set(key, lua_tonumber(L, 2));
|
||||||
|
break;
|
||||||
|
case LUA_TBOOLEAN:
|
||||||
|
LuaGlobalBridge::Set(key, (bool)lua_toboolean(L, 2));
|
||||||
|
break;
|
||||||
|
case LUA_TSTRING:
|
||||||
|
LuaGlobalBridge::Set(key, std::string(lua_tostring(L, 2)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
luaL_error(L, "[Engine.SetGlobal] Unsupported value type");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Lua_GetGlobal(lua_State *L)
|
||||||
|
{
|
||||||
|
const char *key = luaL_checkstring(L, 1);
|
||||||
|
auto value = LuaGlobalBridge::Get(key);
|
||||||
|
|
||||||
|
if (!value.has_value())
|
||||||
|
{
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::visit([L](auto &&val)
|
||||||
|
{
|
||||||
|
using T = std::decay_t<decltype(val)>;
|
||||||
|
if constexpr (std::is_same_v<T, double>)
|
||||||
|
lua_pushnumber(L, val);
|
||||||
|
else if constexpr (std::is_same_v<T, bool>)
|
||||||
|
lua_pushboolean(L, val);
|
||||||
|
else if constexpr (std::is_same_v<T, std::string>)
|
||||||
|
lua_pushstring(L, val.c_str()); }, *value);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static bool luaDebugEnabled = false;
|
static bool luaDebugEnabled = false;
|
||||||
static bool old_state = false;
|
static bool old_state = false;
|
||||||
@ -153,21 +197,28 @@ static int Lua_DebugLua(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Component *GetComponentByName(Object *obj, const std::string &type)
|
static Component *GetComponentByName(Object *obj, const std::string &type)
|
||||||
{
|
{
|
||||||
PROFILE_DEEP_SCOPE("GetComponentByName");
|
PROFILE_DEEP_SCOPE("GetComponentByName");
|
||||||
|
|
||||||
using GetterFn = std::function<Component *(Object *)>;
|
using GetterFn = std::function<Component *(Object *)>;
|
||||||
static const std::unordered_map<std::string, GetterFn> table = {
|
static const std::unordered_map<std::string, GetterFn> table = {
|
||||||
{"SpriteComponent", [](Object* o) { return o->GetComponent<SpriteComponent>().get(); }},
|
{"SpriteComponent", [](Object *o)
|
||||||
{"CameraComponent", [](Object* o) { return o->GetComponent<CameraComponent>().get(); }},
|
{ return o->GetComponent<SpriteComponent>().get(); }},
|
||||||
{"LightComponent", [](Object* o) { return o->GetComponent<LightComponent>().get(); }},
|
{"CameraComponent", [](Object *o)
|
||||||
{"TilemapComponent", [](Object* o) { return o->GetComponent<TilemapComponent>().get(); }},
|
{ return o->GetComponent<CameraComponent>().get(); }},
|
||||||
{"TextComponent", [](Object* o) { return o->GetComponent<TextComponent>().get(); }},
|
{"LightComponent", [](Object *o)
|
||||||
{"ScriptComponent", [](Object* o) { return o->GetComponent<ScriptComponent>().get(); }},
|
{ return o->GetComponent<LightComponent>().get(); }},
|
||||||
{"AnimationComponent", [](Object* o) { return o->GetComponent<AnimationComponent>().get(); }},
|
{"TilemapComponent", [](Object *o)
|
||||||
{"AudioPlayerComponent", [](Object* o) { return o->GetComponent<AudioPlayerComponent>().get(); }},
|
{ return o->GetComponent<TilemapComponent>().get(); }},
|
||||||
|
{"TextComponent", [](Object *o)
|
||||||
|
{ return o->GetComponent<TextComponent>().get(); }},
|
||||||
|
{"ScriptComponent", [](Object *o)
|
||||||
|
{ return o->GetComponent<ScriptComponent>().get(); }},
|
||||||
|
{"AnimationComponent", [](Object *o)
|
||||||
|
{ return o->GetComponent<AnimationComponent>().get(); }},
|
||||||
|
{"AudioPlayerComponent", [](Object *o)
|
||||||
|
{ return o->GetComponent<AudioPlayerComponent>().get(); }},
|
||||||
};
|
};
|
||||||
|
|
||||||
auto it = table.find(type);
|
auto it = table.find(type);
|
||||||
@ -177,8 +228,6 @@ static Component* GetComponentByName(Object* obj, const std::string& type)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int Lua_GetMousePos(lua_State *L)
|
static int Lua_GetMousePos(lua_State *L)
|
||||||
{
|
{
|
||||||
PROFILE_DEEP_SCOPE("Engine::GetMousePos");
|
PROFILE_DEEP_SCOPE("Engine::GetMousePos");
|
||||||
@ -248,7 +297,6 @@ static int Lua_Object_GetComponent(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static AudioPlayerComponent *CheckSound(lua_State *L)
|
static AudioPlayerComponent *CheckSound(lua_State *L)
|
||||||
{
|
{
|
||||||
return ((LuaSoundWrapper *)luaL_checkudata(L, 1, LUA_SOUND_MT))->comp;
|
return ((LuaSoundWrapper *)luaL_checkudata(L, 1, LUA_SOUND_MT))->comp;
|
||||||
@ -287,8 +335,6 @@ static int Lua_Sound_Index(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int Lua_Object_GetPosition(lua_State *L)
|
static int Lua_Object_GetPosition(lua_State *L)
|
||||||
{
|
{
|
||||||
PROFILE_DEEP_SCOPE("Object::GetPosition");
|
PROFILE_DEEP_SCOPE("Object::GetPosition");
|
||||||
@ -448,10 +494,14 @@ void RegisterSoundType(lua_State* L)
|
|||||||
{
|
{
|
||||||
luaL_newmetatable(L, LUA_SOUND_MT);
|
luaL_newmetatable(L, LUA_SOUND_MT);
|
||||||
|
|
||||||
lua_pushcfunction(L, Lua_Sound_Play); lua_setfield(L, -2, "Play");
|
lua_pushcfunction(L, Lua_Sound_Play);
|
||||||
lua_pushcfunction(L, Lua_Sound_Stop); lua_setfield(L, -2, "Stop");
|
lua_setfield(L, -2, "Play");
|
||||||
lua_pushcfunction(L, Lua_Sound_Pause); lua_setfield(L, -2, "Pause");
|
lua_pushcfunction(L, Lua_Sound_Stop);
|
||||||
lua_pushcfunction(L, Lua_Sound_SetVolume); lua_setfield(L, -2, "SetVolume");
|
lua_setfield(L, -2, "Stop");
|
||||||
|
lua_pushcfunction(L, Lua_Sound_Pause);
|
||||||
|
lua_setfield(L, -2, "Pause");
|
||||||
|
lua_pushcfunction(L, Lua_Sound_SetVolume);
|
||||||
|
lua_setfield(L, -2, "SetVolume");
|
||||||
|
|
||||||
lua_pushcfunction(L, Lua_Sound_Index);
|
lua_pushcfunction(L, Lua_Sound_Index);
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
@ -459,9 +509,6 @@ void RegisterSoundType(lua_State* L)
|
|||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void RegisterLightType(lua_State *L)
|
void RegisterLightType(lua_State *L)
|
||||||
{
|
{
|
||||||
luaL_newmetatable(L, LUA_LIGHT_MT);
|
luaL_newmetatable(L, LUA_LIGHT_MT);
|
||||||
@ -951,6 +998,11 @@ void ScriptComponent::RegisterEngineBindings()
|
|||||||
lua_pushcfunction(L, Lua_GetMousePos);
|
lua_pushcfunction(L, Lua_GetMousePos);
|
||||||
lua_setfield(L, -2, "GetMousePos");
|
lua_setfield(L, -2, "GetMousePos");
|
||||||
|
|
||||||
|
lua_pushcfunction(L, Lua_SetGlobal);
|
||||||
|
lua_setfield(L, -2, "SetGlobal");
|
||||||
|
lua_pushcfunction(L, Lua_GetGlobal);
|
||||||
|
lua_setfield(L, -2, "GetGlobal");
|
||||||
|
|
||||||
lua_setglobal(L, "Engine");
|
lua_setglobal(L, "Engine");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,10 +24,14 @@
|
|||||||
#include "core/utils/Profiler.h"
|
#include "core/utils/Profiler.h"
|
||||||
#include "core/utils/utils.h"
|
#include "core/utils/utils.h"
|
||||||
#include "core/utils/LoadingWindow.h"
|
#include "core/utils/LoadingWindow.h"
|
||||||
|
#include "core/scripts/LuaGlobalBridge.h"
|
||||||
|
|
||||||
|
|
||||||
#include "editor/windows/AssetBrowser.h"
|
#include "editor/windows/AssetBrowser.h"
|
||||||
#include "editor/windows/Inspector.h"
|
#include "editor/windows/Inspector.h"
|
||||||
#include "editor/windows/AudioInfo.h"
|
#include "editor/windows/AudioInfo.h"
|
||||||
|
#include "editor/windows/LuaGlobals.h"
|
||||||
|
|
||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
@ -431,46 +435,53 @@ void ShowColorCorrectionWindow()
|
|||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <ImGuizmo.h>
|
||||||
|
|
||||||
void DrawGizmoForObject(const std::shared_ptr<Object>& obj, const glm::mat4& view, const glm::mat4& projection)
|
void DrawGizmoForObject(const std::shared_ptr<Object>& obj, const glm::mat4& view, const glm::mat4& projection)
|
||||||
{
|
{
|
||||||
if (!obj)
|
if (!obj)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// 1. Build model matrix from position and rotation
|
||||||
glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(obj->GetLocalPosition(), 0.0f));
|
glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(obj->GetLocalPosition(), 0.0f));
|
||||||
|
|
||||||
model = glm::rotate(model, obj->GetLocalRotation(), glm::vec3(0.0f, 0.0f, 1.0f));
|
model = glm::rotate(model, obj->GetLocalRotation(), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||||
|
|
||||||
// Setup ImGuizmo
|
// 2. Ensure ImGuizmo is configured correctly
|
||||||
ImGuizmo::SetOrthographic(false);
|
ImGuizmo::SetOrthographic(false);
|
||||||
ImGuizmo::SetDrawlist();
|
ImGuizmo::SetDrawlist();
|
||||||
|
|
||||||
ImVec2 windowPos = ImGui::GetWindowPos();
|
// 3. Set ImGuizmo rect to match current window (e.g., your viewport)
|
||||||
ImVec2 windowSize = ImGui::GetWindowSize();
|
ImVec2 pos = ImGui::GetWindowPos();
|
||||||
ImGuizmo::SetRect(windowPos.x, windowPos.y, windowSize.x, windowSize.y);
|
ImVec2 size = ImGui::GetWindowSize();
|
||||||
|
ImGuizmo::SetRect(pos.x, pos.y, size.x, size.y);
|
||||||
|
|
||||||
|
// 4. Handle mode switching
|
||||||
static ImGuizmo::OPERATION operation = ImGuizmo::TRANSLATE;
|
static ImGuizmo::OPERATION operation = ImGuizmo::TRANSLATE;
|
||||||
if (ImGui::IsKeyPressed(ImGuiKey_T))
|
if (ImGui::IsKeyPressed(ImGuiKey_T))
|
||||||
operation = ImGuizmo::TRANSLATE;
|
operation = ImGuizmo::TRANSLATE;
|
||||||
if (ImGui::IsKeyPressed(ImGuiKey_R))
|
if (ImGui::IsKeyPressed(ImGuiKey_R))
|
||||||
operation = ImGuizmo::ROTATE;
|
operation = ImGuizmo::ROTATE;
|
||||||
|
|
||||||
|
// 5. Perform manipulation
|
||||||
glm::mat4 manipulated = model;
|
glm::mat4 manipulated = model;
|
||||||
ImGuizmo::Manipulate(glm::value_ptr(view), glm::value_ptr(projection),
|
ImGuizmo::Manipulate(glm::value_ptr(view), glm::value_ptr(projection),
|
||||||
operation, ImGuizmo::LOCAL, glm::value_ptr(manipulated));
|
operation, ImGuizmo::LOCAL, glm::value_ptr(manipulated));
|
||||||
|
|
||||||
|
// 6. Apply result to object if actively using gizmo
|
||||||
if (ImGuizmo::IsUsing())
|
if (ImGuizmo::IsUsing())
|
||||||
{
|
{
|
||||||
glm::vec3 translation, rotation, dummyScale;
|
glm::vec3 translation, rotation, scale;
|
||||||
ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(manipulated),
|
ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(manipulated),
|
||||||
glm::value_ptr(translation),
|
glm::value_ptr(translation),
|
||||||
glm::value_ptr(rotation),
|
glm::value_ptr(rotation),
|
||||||
glm::value_ptr(dummyScale));
|
glm::value_ptr(scale));
|
||||||
|
|
||||||
obj->SetLocalPosition(translation);
|
obj->SetLocalPosition({translation.x, translation.y});
|
||||||
obj->SetLocalRotation(rotation.z);
|
obj->SetLocalRotation(rotation.z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Engine::Init()
|
void Engine::Init()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -789,6 +800,8 @@ void Engine::Run()
|
|||||||
ImGui::Checkbox("Assets", &g_engineConfig.settings.show_asset_window);
|
ImGui::Checkbox("Assets", &g_engineConfig.settings.show_asset_window);
|
||||||
ImGui::Checkbox("Performance Info", &g_engineConfig.settings.show_performance_window);
|
ImGui::Checkbox("Performance Info", &g_engineConfig.settings.show_performance_window);
|
||||||
ImGui::Checkbox("Audio Viewer", &g_engineConfig.settings.show_audio_window);
|
ImGui::Checkbox("Audio Viewer", &g_engineConfig.settings.show_audio_window);
|
||||||
|
ImGui::Checkbox("Lua Globals Viewer", &g_engineConfig.settings.show_lua_globals_window);
|
||||||
|
|
||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
@ -816,6 +829,7 @@ void Engine::Run()
|
|||||||
|
|
||||||
ShowAssetBrowser();
|
ShowAssetBrowser();
|
||||||
DrawAudioPlayingList();
|
DrawAudioPlayingList();
|
||||||
|
DrawImGuiWindow();
|
||||||
|
|
||||||
{
|
{
|
||||||
PROFILE_ENGINE_SCOPE("Engine::DrawSceneTree");
|
PROFILE_ENGINE_SCOPE("Engine::DrawSceneTree");
|
||||||
@ -897,12 +911,17 @@ void Engine::Run()
|
|||||||
editorCameraSavedPos = cameraPos;
|
editorCameraSavedPos = cameraPos;
|
||||||
editorCameraSavedZoom = cameraZoom;
|
editorCameraSavedZoom = cameraZoom;
|
||||||
editorCameraWasSaved = true;
|
editorCameraWasSaved = true;
|
||||||
|
LuaGlobalBridge::Clear();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (!playing && lastPlaying && editorCameraWasSaved)
|
else if (!playing && lastPlaying && editorCameraWasSaved)
|
||||||
{
|
{
|
||||||
cameraPos = editorCameraSavedPos;
|
cameraPos = editorCameraSavedPos;
|
||||||
cameraZoom = editorCameraSavedZoom;
|
cameraZoom = editorCameraSavedZoom;
|
||||||
editorCameraWasSaved = false;
|
editorCameraWasSaved = false;
|
||||||
|
LuaGlobalBridge::Clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
lastPlaying = playing;
|
lastPlaying = playing;
|
||||||
|
|
||||||
|
31
src/src/core/scripts/LuaGlobalBridge.cpp
Normal file
31
src/src/core/scripts/LuaGlobalBridge.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "LuaGlobalBridge.h"
|
||||||
|
|
||||||
|
void LuaGlobalBridge::Set(const std::string& key, const Value& value)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
globals[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<LuaGlobalBridge::Value> LuaGlobalBridge::Get(const std::string& key)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
auto it = globals.find(key);
|
||||||
|
if (it != globals.end())
|
||||||
|
return it->second;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::unordered_map<std::string, LuaGlobalBridge::Value> LuaGlobalBridge::GetAll()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
return globals;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LuaGlobalBridge::Clear()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
|
globals.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
25
src/src/core/scripts/LuaGlobalBridge.h
Normal file
25
src/src/core/scripts/LuaGlobalBridge.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <variant>
|
||||||
|
#include <optional>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
class LuaGlobalBridge
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using Value = std::variant<double, bool, std::string>;
|
||||||
|
|
||||||
|
static void Set(const std::string& key, const Value& value);
|
||||||
|
static std::optional<Value> Get(const std::string& key);
|
||||||
|
|
||||||
|
static std::unordered_map<std::string, Value> GetAll();
|
||||||
|
|
||||||
|
static void Clear();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
static inline std::unordered_map<std::string, Value> globals;
|
||||||
|
static inline std::mutex mutex;
|
||||||
|
};
|
@ -13,7 +13,8 @@
|
|||||||
USER_SETTING(profile_gpu, bool, false) \
|
USER_SETTING(profile_gpu, bool, false) \
|
||||||
USER_SETTING(show_performance_window, bool, false) \
|
USER_SETTING(show_performance_window, bool, false) \
|
||||||
USER_SETTING(show_audio_window, bool, false) \
|
USER_SETTING(show_audio_window, bool, false) \
|
||||||
USER_SETTING(ignore_invalid_versions_popups, bool, false)
|
USER_SETTING(ignore_invalid_versions_popups, bool, false) \
|
||||||
|
USER_SETTING(show_lua_globals_window, bool, true)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
58
src/src/editor/windows/LuaGlobals.cpp
Normal file
58
src/src/editor/windows/LuaGlobals.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include "LuaGlobals.h"
|
||||||
|
#include "../../core/scripts/LuaGlobalBridge.h"
|
||||||
|
#include "../../core/utils/Logging.h"
|
||||||
|
#include "../../core/utils/EngineConfig.h"
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
|
void DrawImGuiWindow()
|
||||||
|
{
|
||||||
|
if (!g_engineConfig.settings.show_lua_globals_window)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto allGlobals = LuaGlobalBridge::GetAll();
|
||||||
|
|
||||||
|
ImGui::Begin("Lua Globals");
|
||||||
|
|
||||||
|
if (allGlobals.empty())
|
||||||
|
{
|
||||||
|
ImGui::TextDisabled("No global variables set.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImGui::Text("Active Globals:");
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
ImGui::Columns(2, nullptr, false);
|
||||||
|
ImGui::SetColumnWidth(0, 160);
|
||||||
|
|
||||||
|
ImGui::TextColored(ImVec4(1, 1, 0.4f, 1), "Key");
|
||||||
|
ImGui::NextColumn();
|
||||||
|
ImGui::TextColored(ImVec4(1, 1, 0.4f, 1), "Value");
|
||||||
|
ImGui::NextColumn();
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
for (const auto& [key, value] : allGlobals)
|
||||||
|
{
|
||||||
|
std::string valueStr;
|
||||||
|
|
||||||
|
std::visit([&](auto&& val) {
|
||||||
|
using T = std::decay_t<decltype(val)>;
|
||||||
|
if constexpr (std::is_same_v<T, double>)
|
||||||
|
valueStr = std::to_string(val);
|
||||||
|
else if constexpr (std::is_same_v<T, bool>)
|
||||||
|
valueStr = val ? "true" : "false";
|
||||||
|
else if constexpr (std::is_same_v<T, std::string>)
|
||||||
|
valueStr = val;
|
||||||
|
}, value);
|
||||||
|
|
||||||
|
ImGui::TextUnformatted(key.c_str());
|
||||||
|
ImGui::NextColumn();
|
||||||
|
ImGui::TextUnformatted(valueStr.c_str());
|
||||||
|
ImGui::NextColumn();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::Columns(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
}
|
4
src/src/editor/windows/LuaGlobals.h
Normal file
4
src/src/editor/windows/LuaGlobals.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
void DrawImGuiWindow();
|
Loading…
Reference in New Issue
Block a user