A Lot of re organisation

This commit is contained in:
OusmBlueNinja 2025-04-19 22:27:49 -05:00
parent 06f4bd23d1
commit 96811c6e5a
43 changed files with 20922 additions and 13341 deletions

View File

@ -10,24 +10,24 @@ Collapsed=1
[Window][WindowOverViewport_11111111]
Pos=0,19
Size=32,32
Size=1280,701
Collapsed=0
[Window][Inspector]
Pos=0,42
Size=15,9
Pos=0,421
Size=342,299
Collapsed=0
DockId=0x0000000A,0
[Window][Scene Tree]
Pos=0,19
Size=15,21
Size=342,400
Collapsed=0
DockId=0x00000009,0
[Window][Viewport]
Pos=17,19
Size=15,15
Pos=344,19
Size=936,207
Collapsed=0
DockId=0x00000007,0
@ -36,16 +36,16 @@ Size=1280,19
Collapsed=0
[Window][Performance Info]
Pos=30,36
Size=4,7
Pos=1083,228
Size=197,273
Collapsed=0
DockId=0x00000003,0
[Window][Console]
Pos=17,44
Size=11,7
Pos=344,228
Size=363,492
Collapsed=0
DockId=0x0000000C,0
DockId=0x0000000D,0
[Window][Tilemap Editor]
Pos=265,19
@ -54,47 +54,53 @@ Collapsed=0
DockId=0x00000007,1
[Window][Profiler]
Pos=17,36
Size=11,6
Pos=344,19
Size=936,207
Collapsed=0
DockId=0x0000000B,0
DockId=0x00000007,1
[Window][Profiler Timeline]
Pos=265,69
Size=623,651
Collapsed=0
DockId=0x0000000B,1
DockId=0x00000005,1
[Window][Profiler (Unity Style)]
Pos=265,430
Size=623,290
Collapsed=0
DockId=0x0000000B,1
DockId=0x00000005,1
[Window][Profiler Timeline View]
Pos=265,526
Size=1263,651
Collapsed=0
DockId=0x0000000B,1
DockId=0x00000005,1
[Window][Color Correction]
Pos=30,45
Size=4,6
Pos=1083,503
Size=197,217
Collapsed=0
DockId=0x00000004,0
[Window][Asset Browser]
Pos=709,228
Size=372,492
Collapsed=0
DockId=0x0000000E,0
[Docking][Data]
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=32,32 Split=X
DockNode ID=0x00000001 Parent=0x11111111 SizeRef=333,701 Split=Y Selected=0x12EF0F59
DockNode ID=0x00000009 Parent=0x00000001 SizeRef=385,797 HiddenTabBar=1 Selected=0x12EF0F59
DockNode ID=0x0000000A Parent=0x00000001 SizeRef=385,359 HiddenTabBar=1 Selected=0x36DC96AB
DockNode ID=0x00000002 Parent=0x11111111 SizeRef=1249,701 Split=Y Selected=0xC450F867
DockNode ID=0x00000007 Parent=0x00000002 SizeRef=606,664 CentralNode=1 HiddenTabBar=1 Selected=0xC450F867
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1280,701 Split=X
DockNode ID=0x00000001 Parent=0x11111111 SizeRef=342,701 Split=Y Selected=0x12EF0F59
DockNode ID=0x00000009 Parent=0x00000001 SizeRef=385,662 HiddenTabBar=1 Selected=0x12EF0F59
DockNode ID=0x0000000A Parent=0x00000001 SizeRef=385,494 HiddenTabBar=1 Selected=0x36DC96AB
DockNode ID=0x00000002 Parent=0x11111111 SizeRef=1576,701 Split=Y Selected=0xC450F867
DockNode ID=0x00000007 Parent=0x00000002 SizeRef=606,664 CentralNode=1 Selected=0x9B5D3198
DockNode ID=0x00000008 Parent=0x00000002 SizeRef=606,492 Split=X Selected=0x9B5D3198
DockNode ID=0x00000005 Parent=0x00000008 SizeRef=1053,481 Split=Y Selected=0x9B5D3198
DockNode ID=0x0000000B Parent=0x00000005 SizeRef=1283,242 HiddenTabBar=1 Selected=0x9B5D3198
DockNode ID=0x0000000C Parent=0x00000005 SizeRef=1283,248 HiddenTabBar=1 Selected=0xEA83D666
DockNode ID=0x00000006 Parent=0x00000008 SizeRef=194,481 Split=Y Selected=0x3FC1A724
DockNode ID=0x00000005 Parent=0x00000008 SizeRef=737,481 Split=X Selected=0x9B5D3198
DockNode ID=0x0000000D Parent=0x00000005 SizeRef=363,248 HiddenTabBar=1 Selected=0xEA83D666
DockNode ID=0x0000000E Parent=0x00000005 SizeRef=372,248 HiddenTabBar=1 Selected=0x36AF052B
DockNode ID=0x00000006 Parent=0x00000008 SizeRef=197,481 Split=Y Selected=0x3FC1A724
DockNode ID=0x00000003 Parent=0x00000006 SizeRef=226,273 HiddenTabBar=1 Selected=0x3FC1A724
DockNode ID=0x00000004 Parent=0x00000006 SizeRef=226,217 HiddenTabBar=1 Selected=0xA873C17F

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,3 @@
[COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -IC:/msys64/mingw64/include -Isrc\vendor\imgui -IC:\msys64\mingw64\lib\libyaml-cpp.a -MMD -MP -c src\src\Renderer.cpp -o src\build\Renderer.o
[LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.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\Entitys\Object.o src\build\utils\EngineConfig.o src\build\utils\ExceptionHandler.o src\build\utils\FileDialog.o src\build\utils\GameObjectsList.o src\build\utils\Logging.o src\build\utils\Profiler.o src\build\utils\Shader.o src\build\utils\UID.o src\build\utils\utils.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 -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto
[COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -IC:/msys64/mingw64/include -IC:\msys64\mingw64\lib\libyaml-cpp.a -Isrc\vendor\imgui -MMD -MP -c src\src\editor\windows\AssetBrowser.cpp -o src\build\editor\windows\AssetBrowser.o
[LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.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\utils\AssetLoader.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\Logging.o src\build\core\utils\Profiler.o src\build\core\utils\utils.o src\build\editor\windows\AssetBrowser.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 -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto
[RUN] Executed app.exe successfully.

View File

@ -2,11 +2,13 @@ Engine.DebugLua(true)
local Objects = {}
local Velocities = {}
local CameraObj -- will hold our camera
local CamSpeed = 800 -- camera speed in world units/sec
-- new border extents
local MinX, MinY = 0, 0
local MaxX, MaxY = 5096, 5096
local Speed = 1000 -- units per second
local Speed = 1000 -- light speed in units per second
-- simple clamp
local function clamp(v, lo, hi)
@ -17,46 +19,84 @@ end
function OnInit()
math.randomseed(os.time())
Engine.LogInfo("Initial Speed: " .. Speed)
-- cache lights
for i = 0, 99 do
local tag = "Light_" .. i
local obj = Engine.GetObjectByTag(tag)
if obj then
table.insert(Objects, obj)
-- random direction
local ang = math.random() * 2 * math.pi
local vx = math.cos(ang) * Speed
local vy = math.sin(ang) * Speed
-- store velocity in plain table
Velocities[obj] = { x = vx, y = vy }
else
Engine.LogError("Object '" .. tag .. "' not found!")
end
end
-- grab the camera
CameraObj = Engine.GetObjectByTag("Camera")
if not CameraObj then
Engine.LogError("Camera object not found!")
end
end
function OnUpdate(dt)
-- light speed tweaks (same as before)
if Engine.KeyDown(Keycode.Equal) or Engine.KeyDown(Keycode.KPAdd) then
Speed = Speed + 100 * dt
Engine.LogInfo(string.format("Speed increased to %.1f", Speed))
elseif Engine.KeyDown(Keycode.Minus) or Engine.KeyDown(Keycode.KPSubtract) then
Speed = Speed - 100 * dt
if Speed < 0 then Speed = 0 end
Engine.LogInfo(string.format("Speed decreased to %.1f", Speed))
end
if not CameraObj then
Engine.LogError("Camera object not found!")
CameraObj = Engine.GetObjectByTag("Camera")
end
-- move lights
for _, obj in ipairs(Objects) do
local vel = Velocities[obj]
local pos = obj:GetPosition()
-- integrate
local ang = math.atan(vel.y, vel.x)
vel.x = math.cos(ang) * Speed
vel.y = math.sin(ang) * Speed
local nx = pos.x + vel.x * dt
local ny = pos.y + vel.y * dt
-- bounce X against [MinX,MaxX]
if nx < MinX or nx > MaxX then
vel.x = -vel.x
nx = clamp(nx, MinX, MaxX)
end
-- bounce Y against [MinY,MaxY]
if ny < MinY or ny > MaxY then
vel.y = -vel.y
ny = clamp(ny, MinY, MaxY)
end
-- store back and apply
Velocities[obj] = vel
obj:SetPosition(Vector2(nx, ny))
end
if CameraObj then
local camPos = CameraObj:GetPosition()
if Engine.KeyDown(Keycode.W) then
camPos.y = camPos.y - CamSpeed * dt
elseif Engine.KeyDown(Keycode.S) then
camPos.y = camPos.y + CamSpeed * dt
end
if Engine.KeyDown(Keycode.A) then
camPos.x = camPos.x - CamSpeed * dt
elseif Engine.KeyDown(Keycode.D) then
camPos.x = camPos.x + CamSpeed * dt
end
CameraObj:SetPosition(Vector2(camPos.x, camPos.y))
end
end

View File

@ -1,6 +1,6 @@
engine_version: 0.1.0
scene_name: Colors
scene_hash: e789c03c011f309c2816c72f16d409ee6db1eafc6c27dc6087522c3b459220f7
scene_hash: 45f41906b825a0458fca86b63f14e3fb7880343086b79c4f545b3f40e744b258
format_version: 1
objects:
- name: Pebble_0
@ -1306,7 +1306,7 @@ objects:
- name: Light_0
uid: b708398999fb49a6b0e0d2674dcc77fc
id: 100
position: [552.986267, 4973.9165]
position: [4187.08643, 3774.68164]
rotation: 0
layer: 0
visable: true
@ -1324,7 +1324,7 @@ objects:
- name: Light_1
uid: 88859ec57be44844aa534dfb4fa89d00
id: 101
position: [469.018555, 2798.83203]
position: [52.8271675, 989.955505]
rotation: 0
layer: 0
visable: true
@ -1342,7 +1342,7 @@ objects:
- name: Light_2
uid: dd1b22b81a0b463bb2d359fa542684ad
id: 102
position: [648.73468, 613.932739]
position: [534.239929, 3388.91357]
rotation: 0
layer: 0
visable: true
@ -1360,7 +1360,7 @@ objects:
- name: Light_3
uid: 28a5238ade60497195e8dcd6d5d1262e
id: 103
position: [3191.38916, 2295.30762]
position: [2980.92578, 4600.52734]
rotation: 0
layer: 0
visable: true
@ -1378,7 +1378,7 @@ objects:
- name: Light_4
uid: fde91d7f91b54cfdaef7dc83dee4035d
id: 104
position: [2643.11401, 872.14856]
position: [4393.89404, 1520.40479]
rotation: 0
layer: 0
visable: true
@ -1396,7 +1396,7 @@ objects:
- name: Light_5
uid: 6d2906de1c96412890734c5149c10bdb
id: 105
position: [1020.43378, 1298.57312]
position: [51.832901, 0]
rotation: 0
layer: 0
visable: true
@ -1414,7 +1414,7 @@ objects:
- name: Light_6
uid: dbb9fa1744d24f4f93c5b25cd59f67cb
id: 106
position: [412.781036, 1125.05017]
position: [5054.26465, 3245.80908]
rotation: 0
layer: 0
visable: true
@ -1432,7 +1432,7 @@ objects:
- name: Light_7
uid: 1a911f67759848e4b6188be945b19444
id: 107
position: [2872.0542, 633.325684]
position: [1805.81726, 25.7523537]
rotation: 0
layer: 0
visable: true
@ -1450,7 +1450,7 @@ objects:
- name: Light_8
uid: a84c1459a6384a00ae7a55bef90b0376
id: 108
position: [2503.82446, 3236.18823]
position: [2307.27466, 1380.87524]
rotation: 0
layer: 0
visable: true
@ -1468,7 +1468,7 @@ objects:
- name: Light_9
uid: 13f4ea1305b84b44b55d565980da72b5
id: 109
position: [1322.27625, 4635.42725]
position: [706.5354, 3042.4873]
rotation: 0
layer: 0
visable: true
@ -1486,7 +1486,7 @@ objects:
- name: Light_10
uid: 58de20d086c449c8ae39cbdc1476f721
id: 110
position: [3729.3186, 5032.26025]
position: [1194.97339, 60.1199951]
rotation: 0
layer: 0
visable: true
@ -1504,7 +1504,7 @@ objects:
- name: Light_11
uid: 892f36823c294545a1253646ddc32889
id: 111
position: [4670.3667, 257.51828]
position: [1985.00598, 4527.54102]
rotation: 0
layer: 0
visable: true
@ -1522,7 +1522,7 @@ objects:
- name: Light_12
uid: 376810f267da463eb60f58e7395b37bc
id: 112
position: [568.911926, 3778.14453]
position: [2098.36133, 154.310883]
rotation: 0
layer: 0
visable: true
@ -1540,7 +1540,7 @@ objects:
- name: Light_13
uid: fa0b9447c41d445b868a93d11c6be6e8
id: 113
position: [4208.92822, 1434.02722]
position: [2912.57227, 4802.9668]
rotation: 0
layer: 0
visable: true
@ -1558,7 +1558,7 @@ objects:
- name: Light_14
uid: 59a36f90f13043b5813127bcf8ddbaef
id: 114
position: [1301.81958, 1540.60632]
position: [2865.40186, 313.351135]
rotation: 0
layer: 0
visable: true
@ -1576,7 +1576,7 @@ objects:
- name: Light_15
uid: bbca9aa986024463ad35f1212cfed885
id: 115
position: [4709.48682, 3153.38623]
position: [2630.40894, 4811.3999]
rotation: 0
layer: 0
visable: true
@ -1594,7 +1594,7 @@ objects:
- name: Light_16
uid: c7a3c183ddd249089ab0ff36e9b8a928
id: 116
position: [3138.12744, 4681.85254]
position: [4983.39111, 1026.44556]
rotation: 0
layer: 0
visable: true
@ -1612,7 +1612,7 @@ objects:
- name: Light_17
uid: 3b040f3ae25345aaa78143475568d6e0
id: 117
position: [1982.30249, 501.78775]
position: [2405.61938, 1199.3772]
rotation: 0
layer: 0
visable: true
@ -1630,7 +1630,7 @@ objects:
- name: Light_18
uid: 238f6fc227804809ba6ba5b9046613d9
id: 118
position: [962.893433, 5032.26221]
position: [4711.94678, 761.653687]
rotation: 0
layer: 0
visable: true
@ -1648,7 +1648,7 @@ objects:
- name: Light_19
uid: f71f3ab20bbb4c5587120de7d971f6f1
id: 119
position: [4759.85303, 1812.43127]
position: [4600.64258, 3857.41064]
rotation: 0
layer: 0
visable: true
@ -1666,7 +1666,7 @@ objects:
- name: Light_20
uid: d596365c30eb40839fffefd9bf25f499
id: 120
position: [1149.14929, 4163.51465]
position: [2976.98193, 1488.39087]
rotation: 0
layer: 0
visable: true
@ -1684,7 +1684,7 @@ objects:
- name: Light_21
uid: c0e03e668552433491bde2e436ede76c
id: 121
position: [4311.44727, 2689.05298]
position: [80.3030701, 3008.24463]
rotation: 0
layer: 0
visable: true
@ -1702,7 +1702,7 @@ objects:
- name: Light_22
uid: 3a7304efd7fd401caded2ac773d4b212
id: 122
position: [3724.40454, 4067.07153]
position: [339.902527, 4018.41309]
rotation: 0
layer: 0
visable: true
@ -1720,7 +1720,7 @@ objects:
- name: Light_23
uid: 9ad7d7f453c543eda95a311139c57c4e
id: 123
position: [537.28479, 3353.68213]
position: [3854.66821, 1078.23987]
rotation: 0
layer: 0
visable: true
@ -1738,7 +1738,7 @@ objects:
- name: Light_24
uid: 1641cad349b845368368c25488d74446
id: 124
position: [2090.09229, 3877.80322]
position: [4338.96191, 2904.04907]
rotation: 0
layer: 0
visable: true
@ -1756,7 +1756,7 @@ objects:
- name: Light_25
uid: f68c769d122f4290971e31dec67b00c8
id: 125
position: [3825.71362, 1444.71204]
position: [3099.30396, 2659.16528]
rotation: 0
layer: 0
visable: true
@ -1774,7 +1774,7 @@ objects:
- name: Light_26
uid: 6605db58dbc54fd796bbef3400b2c85e
id: 126
position: [3666.12109, 4410.19922]
position: [4758.61475, 2485.95093]
rotation: 0
layer: 0
visable: true
@ -1792,7 +1792,7 @@ objects:
- name: Light_27
uid: a599210d949745ffb6fb3cef297fca07
id: 127
position: [1364.0531, 4571.73926]
position: [4883.23389, 4630.14697]
rotation: 0
layer: 0
visable: true
@ -1810,7 +1810,7 @@ objects:
- name: Light_28
uid: c57df595448e4a928311d531e2578c68
id: 128
position: [5058.71924, 1267.05029]
position: [1943.50928, 3350.98877]
rotation: 0
layer: 0
visable: true
@ -1828,7 +1828,7 @@ objects:
- name: Light_29
uid: ea2af648d427448a927e9b82f7b02820
id: 129
position: [3711.36475, 2556.93335]
position: [5028.66797, 0]
rotation: 0
layer: 0
visable: true
@ -1846,7 +1846,7 @@ objects:
- name: Light_30
uid: 3e8b23e48118446f9f0d364863b5292a
id: 130
position: [686.600647, 959.133789]
position: [4036.69531, 4414.5542]
rotation: 0
layer: 0
visable: true
@ -1864,7 +1864,7 @@ objects:
- name: Light_31
uid: 6c124ba50051492fbb49582659391846
id: 131
position: [2075.22119, 4413.44385]
position: [2401.58643, 4554.89697]
rotation: 0
layer: 0
visable: true
@ -1882,7 +1882,7 @@ objects:
- name: Light_32
uid: a23f6a9110a74a5393744d2cfdf7a8f4
id: 132
position: [4256.64893, 2567.84399]
position: [3404.9895, 4196.84766]
rotation: 0
layer: 0
visable: true
@ -1900,7 +1900,7 @@ objects:
- name: Light_33
uid: e3157da98bed4609ad1b4b64996691e7
id: 133
position: [4128.33643, 4990.91309]
position: [3283.08716, 1406.07812]
rotation: 0
layer: 0
visable: true
@ -1918,7 +1918,7 @@ objects:
- name: Light_34
uid: 96c44b3065f5489e938865e3290d2209
id: 134
position: [3288.70142, 2469.16479]
position: [3743.37231, 3001.93018]
rotation: 0
layer: 0
visable: true
@ -1936,7 +1936,7 @@ objects:
- name: Light_35
uid: 7ca3e25c700f468ab2b249ad38341623
id: 135
position: [4930.76758, 2255.27637]
position: [4346.39648, 1020.47382]
rotation: 0
layer: 0
visable: true
@ -1954,7 +1954,7 @@ objects:
- name: Light_36
uid: a775fbadbad041cbafb39ee84b4fb5d4
id: 136
position: [3662.49316, 4413.16064]
position: [445.669037, 3881.3418]
rotation: 0
layer: 0
visable: true
@ -1972,7 +1972,7 @@ objects:
- name: Light_37
uid: f72ad33906454ad186edd3da4b1e31ec
id: 137
position: [3799.03735, 3479.5144]
position: [2865.26685, 4078.13989]
rotation: 0
layer: 0
visable: true
@ -1990,7 +1990,7 @@ objects:
- name: Light_38
uid: c40cddd55628401a84ae80addf2bc06b
id: 138
position: [1891.36023, 648.988342]
position: [3803.01392, 1113.97632]
rotation: 0
layer: 0
visable: true
@ -2008,7 +2008,7 @@ objects:
- name: Light_39
uid: b6da3d4026c9495294c6e725e937f184
id: 139
position: [2023.21216, 4035.46313]
position: [5096, 2380.93481]
rotation: 0
layer: 0
visable: true
@ -2026,7 +2026,7 @@ objects:
- name: Light_40
uid: 6307adbd4fc1420a9378db38c2eadbc6
id: 140
position: [609.298767, 1009.36517]
position: [4417.41455, 1023.18579]
rotation: 0
layer: 0
visable: true
@ -2044,7 +2044,7 @@ objects:
- name: Light_41
uid: c052c4ee748e42708400651a8f512adb
id: 141
position: [4887.79736, 1406.77625]
position: [1158.61914, 779.855774]
rotation: 0
layer: 0
visable: true
@ -2062,7 +2062,7 @@ objects:
- name: Light_42
uid: 958cf05e78d44aeca0c703e9f9c74852
id: 142
position: [3022.3562, 4930.74707]
position: [2036.37244, 143.385773]
rotation: 0
layer: 0
visable: true
@ -2080,7 +2080,7 @@ objects:
- name: Light_43
uid: c0ad38bd78d24087ae4dd7b042d8473b
id: 143
position: [2996.58374, 480.619415]
position: [4587.33203, 3901.14355]
rotation: 0
layer: 0
visable: true
@ -2098,7 +2098,7 @@ objects:
- name: Light_44
uid: 1ec4247039b540e8af574ccbdf80c066
id: 144
position: [1297.97729, 2211.45825]
position: [3973.19653, 3044.97095]
rotation: 0
layer: 0
visable: true
@ -2116,7 +2116,7 @@ objects:
- name: Light_45
uid: a02060f16b3747e1ae31c1794d028268
id: 145
position: [3966.94116, 2247.6333]
position: [2288.56177, 225.631149]
rotation: 0
layer: 0
visable: true
@ -2134,7 +2134,7 @@ objects:
- name: Light_46
uid: b721dfd27a5d4781a0760403b3ebc023
id: 146
position: [2092.72095, 5008.44092]
position: [2909.60986, 2430.09351]
rotation: 0
layer: 0
visable: true
@ -2152,7 +2152,7 @@ objects:
- name: Light_47
uid: e609d76364e5492a9c5888d61e030bda
id: 147
position: [558.217957, 4483.80078]
position: [2281.6936, 2951.89136]
rotation: 0
layer: 0
visable: true
@ -2170,7 +2170,7 @@ objects:
- name: Light_48
uid: 7d4f01ca134c4191a26c0f30cc03e88a
id: 148
position: [806.885803, 539.971558]
position: [2208.12109, 3919.05713]
rotation: 0
layer: 0
visable: true
@ -2188,7 +2188,7 @@ objects:
- name: Light_49
uid: 69e350c393b444bc9d1a74a923e242e9
id: 149
position: [2760.37915, 4065.02954]
position: [3608.68701, 347.960052]
rotation: 0
layer: 0
visable: true
@ -2206,7 +2206,7 @@ objects:
- name: Light_50
uid: d417996bbffd47dea777de4484595516
id: 150
position: [1513.70703, 1235.87317]
position: [696.521301, 3787.09521]
rotation: 0
layer: 0
visable: true
@ -2224,7 +2224,7 @@ objects:
- name: Light_51
uid: 3d83053cf3de4003a8c815f67a348465
id: 151
position: [1566.86584, 516.980591]
position: [1598.47729, 1571.87427]
rotation: 0
layer: 0
visable: true
@ -2242,7 +2242,7 @@ objects:
- name: Light_52
uid: 69973003ce5942f5a09fd66d6d3a4c73
id: 152
position: [3090.41724, 2987.81494]
position: [1246.31213, 3496.25073]
rotation: 0
layer: 0
visable: true
@ -2260,7 +2260,7 @@ objects:
- name: Light_53
uid: 7b2177fd0e0c4198947db624191eff8a
id: 153
position: [1087.58447, 1511.36047]
position: [4744.07471, 3958.46729]
rotation: 0
layer: 0
visable: true
@ -2278,7 +2278,7 @@ objects:
- name: Light_54
uid: 1a4ffcd5a957483cbe3e6f433158199a
id: 154
position: [728.856079, 3729.56274]
position: [2207.73926, 1710.1228]
rotation: 0
layer: 0
visable: true
@ -2296,7 +2296,7 @@ objects:
- name: Light_55
uid: ab4c9b16e70d427b81f434b2d10e34ef
id: 155
position: [822.27478, 311.969421]
position: [2579.64697, 2758.85571]
rotation: 0
layer: 0
visable: true
@ -2314,7 +2314,7 @@ objects:
- name: Light_56
uid: 7d9ca9901da64465a2e1eeb789ee707a
id: 156
position: [3375.52539, 2227.19849]
position: [849.67334, 2529.47095]
rotation: 0
layer: 0
visable: true
@ -2332,7 +2332,7 @@ objects:
- name: Light_57
uid: e5129a0ea1c84804b695c1d390d30920
id: 157
position: [4841.91602, 1841.10339]
position: [4958.10303, 227.151245]
rotation: 0
layer: 0
visable: true
@ -2350,7 +2350,7 @@ objects:
- name: Light_58
uid: 830a109141c44f7d91b240e53e8179a8
id: 158
position: [4615.45947, 3993.15503]
position: [3918.61841, 4944.95752]
rotation: 0
layer: 0
visable: true
@ -2368,7 +2368,7 @@ objects:
- name: Light_59
uid: f4c8d2bc54cc4902b7d73a7902a4e774
id: 159
position: [2588.02734, 4683.25684]
position: [4067.41528, 649.093262]
rotation: 0
layer: 0
visable: true
@ -2386,7 +2386,7 @@ objects:
- name: Light_60
uid: 6d28ae530f9c4a88ac9c1b5a0afe9860
id: 160
position: [1200.20605, 2710.03076]
position: [2074.77417, 4964.62012]
rotation: 0
layer: 0
visable: true
@ -2404,7 +2404,7 @@ objects:
- name: Light_61
uid: 31bea3685354491e897239142164eb1f
id: 161
position: [4940.59912, 1868.11243]
position: [2615.75659, 4999.31299]
rotation: 0
layer: 0
visable: true
@ -2422,7 +2422,7 @@ objects:
- name: Light_62
uid: 560119d71b04477e95f87765504d4f95
id: 162
position: [1626.84863, 3259.09766]
position: [3437.99634, 1567.09668]
rotation: 0
layer: 0
visable: true
@ -2440,7 +2440,7 @@ objects:
- name: Light_63
uid: 26227232c9e2400484930a7857719984
id: 163
position: [3332.15723, 2394.61719]
position: [4474.40967, 427.699585]
rotation: 0
layer: 0
visable: true
@ -2458,7 +2458,7 @@ objects:
- name: Light_64
uid: f0dbddefc9fb48c68ee71ac142e91db6
id: 164
position: [575.838501, 4669.77881]
position: [453.406372, 4925.03564]
rotation: 0
layer: 0
visable: true
@ -2476,7 +2476,7 @@ objects:
- name: Light_65
uid: f07dee5c68af42b8a6b1d99433ab9048
id: 165
position: [226.745529, 4626.10547]
position: [2901.16382, 154.372513]
rotation: 0
layer: 0
visable: true
@ -2494,7 +2494,7 @@ objects:
- name: Light_66
uid: 3d2cf243ab9740ce9b1520d3119785f7
id: 166
position: [3949.24097, 2166.99292]
position: [3767.65771, 5062.71582]
rotation: 0
layer: 0
visable: true
@ -2512,7 +2512,7 @@ objects:
- name: Light_67
uid: 5c35ffbefdaf409fa061f27eb48d04a2
id: 167
position: [621.402893, 2872.22266]
position: [373.202576, 87.2368011]
rotation: 0
layer: 0
visable: true
@ -2530,7 +2530,7 @@ objects:
- name: Light_68
uid: e7246fad41044e3e977734ea9dc3ed00
id: 168
position: [1221.67871, 2990.59814]
position: [3901.17798, 1322.69617]
rotation: 0
layer: 0
visable: true
@ -2548,7 +2548,7 @@ objects:
- name: Light_69
uid: 3918f9fcbbdf4fb5a7178a954de1bcf5
id: 169
position: [3763.07007, 2913.14771]
position: [4506.62061, 4603.42236]
rotation: 0
layer: 0
visable: true
@ -2566,7 +2566,7 @@ objects:
- name: Light_70
uid: 4828ad494f334b57bf3f7162fd256d22
id: 170
position: [3896.14624, 2476.90137]
position: [4050.91968, 1187.70251]
rotation: 0
layer: 0
visable: true
@ -2584,7 +2584,7 @@ objects:
- name: Light_71
uid: aad69721bda746b08ea86c5b3ecb6e25
id: 171
position: [930.429016, 2030.17957]
position: [4516.12646, 4017.49976]
rotation: 0
layer: 0
visable: true
@ -2602,7 +2602,7 @@ objects:
- name: Light_72
uid: 0128ca95fe0a4856a12b5a7e5fc0fa74
id: 172
position: [2726.13672, 1720.68079]
position: [3596.82544, 2544.91602]
rotation: 0
layer: 0
visable: true
@ -2620,7 +2620,7 @@ objects:
- name: Light_73
uid: eaa1ca26f2cb4494bcb2470c68d0d702
id: 173
position: [2747.15527, 3278.37109]
position: [2745.54028, 1232.59973]
rotation: 0
layer: 0
visable: true
@ -2638,7 +2638,7 @@ objects:
- name: Light_74
uid: bbaf03ee37364e9ea78809477fdc270d
id: 174
position: [2830.42041, 2668.56812]
position: [3948.51294, 2241.76025]
rotation: 0
layer: 0
visable: true
@ -2656,7 +2656,7 @@ objects:
- name: Light_75
uid: 66ef231f3a39423797c7b2e344815bd0
id: 175
position: [2634.01587, 4088.47021]
position: [3632.33545, 360.615814]
rotation: 0
layer: 0
visable: true
@ -2674,7 +2674,7 @@ objects:
- name: Light_76
uid: 0e07ce4185664bf1a01534deba067a3a
id: 176
position: [876.178284, 1549.57214]
position: [1094.91443, 3316.23975]
rotation: 0
layer: 0
visable: true
@ -2692,7 +2692,7 @@ objects:
- name: Light_77
uid: a6ed346c2f0348708884a8044747f9ff
id: 177
position: [844.709595, 2922.30566]
position: [1990.19531, 3345.62817]
rotation: 0
layer: 0
visable: true
@ -2710,7 +2710,7 @@ objects:
- name: Light_78
uid: 2ceec34a5eb5463d8f5074ae75789b45
id: 178
position: [4198.05225, 4469.90039]
position: [2327.73999, 4822.90088]
rotation: 0
layer: 0
visable: true
@ -2728,7 +2728,7 @@ objects:
- name: Light_79
uid: 71e4ffdda5614a909b726ea16a05a3f8
id: 179
position: [740.727173, 1215.74011]
position: [4699.37891, 332.524231]
rotation: 0
layer: 0
visable: true
@ -2746,7 +2746,7 @@ objects:
- name: Light_80
uid: a13e28ac5ae84bcfb458a25fe56e8649
id: 180
position: [1924.19104, 2871.44873]
position: [1133.39392, 1468.32422]
rotation: 0
layer: 0
visable: true
@ -2764,7 +2764,7 @@ objects:
- name: Light_81
uid: 8bd1ee77e43a49eba376afd8c020a8e4
id: 181
position: [4318.4585, 1559.41956]
position: [3815.35303, 4806.5918]
rotation: 0
layer: 0
visable: true
@ -2782,7 +2782,7 @@ objects:
- name: Light_82
uid: 0960a71bf015404e8f8dcf9e7fd2159b
id: 182
position: [4279.44434, 4451.40234]
position: [989.270142, 1411.65234]
rotation: 0
layer: 0
visable: true
@ -2800,7 +2800,7 @@ objects:
- name: Light_83
uid: 03ec27ea3be14934bff6fd06360f348b
id: 183
position: [3179.14136, 2424.55151]
position: [3259.61084, 694.141235]
rotation: 0
layer: 0
visable: true
@ -2818,7 +2818,7 @@ objects:
- name: Light_84
uid: 616b83e25ebf4d989c2c4d74f739b2d3
id: 184
position: [1207.99011, 953.506714]
position: [4671.66846, 3051.76489]
rotation: 0
layer: 0
visable: true
@ -2836,7 +2836,7 @@ objects:
- name: Light_85
uid: 8258c4b6f0b849208d2c54e3a7c6ffe8
id: 185
position: [933.797668, 1605.1842]
position: [4686.10693, 3098.97998]
rotation: 0
layer: 0
visable: true
@ -2854,7 +2854,7 @@ objects:
- name: Light_86
uid: 3938fc039c1a4e3297ca409e5f1ddf5f
id: 186
position: [1482.51123, 727.935181]
position: [166.316528, 4440.89648]
rotation: 0
layer: 0
visable: true
@ -2872,7 +2872,7 @@ objects:
- name: Light_87
uid: f8c2ef0a562f4db58af0d54d6f3d3e8a
id: 187
position: [1779.20667, 4504.34912]
position: [1905.32642, 4068.01587]
rotation: 0
layer: 0
visable: true
@ -2890,7 +2890,7 @@ objects:
- name: Light_88
uid: 533ec1f709fd43cbaec1c2453ca7e70e
id: 188
position: [4517.98145, 4173.80615]
position: [4916.03418, 4333.51172]
rotation: 0
layer: 0
visable: true
@ -2908,7 +2908,7 @@ objects:
- name: Light_89
uid: 242adaefa00d4357a816985fbc82b3f2
id: 189
position: [2634.06885, 2514.98999]
position: [2418.58984, 2958.60254]
rotation: 0
layer: 0
visable: true
@ -2926,7 +2926,7 @@ objects:
- name: Light_90
uid: 5970facbd10c4f33a1790d876ad8ea10
id: 190
position: [1734.50366, 4693.05811]
position: [3718.23486, 3504.11084]
rotation: 0
layer: 0
visable: true
@ -2944,7 +2944,7 @@ objects:
- name: Light_91
uid: 58c17315a868491bbd72cab3e70a5675
id: 191
position: [4790.64209, 3143.86304]
position: [81.3819733, 2558.93872]
rotation: 0
layer: 0
visable: true
@ -2962,7 +2962,7 @@ objects:
- name: Light_92
uid: e46abe3268d54de68550608552d1bfad
id: 192
position: [2418.3501, 2260.04639]
position: [1681.95557, 1455.64124]
rotation: 0
layer: 0
visable: true
@ -2980,7 +2980,7 @@ objects:
- name: Light_93
uid: ec2a2b651ed44303bb69828d031a2825
id: 193
position: [3732.02612, 4125.68506]
position: [3952.50317, 4466.03955]
rotation: 0
layer: 0
visable: true
@ -2998,7 +2998,7 @@ objects:
- name: Light_94
uid: 1c563abac63641f2a030a6cf02b33f2b
id: 194
position: [935.298584, 1049.38342]
position: [2331.48657, 3875.41235]
rotation: 0
layer: 0
visable: true
@ -3016,7 +3016,7 @@ objects:
- name: Light_95
uid: 541482725fd04661a7d727cee6b81aa6
id: 195
position: [1390.31799, 870.444336]
position: [3384.19409, 613.124817]
rotation: 0
layer: 0
visable: true
@ -3034,7 +3034,7 @@ objects:
- name: Light_96
uid: 764a073f62af482e894a74030c221cd9
id: 196
position: [1331.90967, 2584.1228]
position: [512.433899, 3713.12573]
rotation: 0
layer: 0
visable: true
@ -3052,7 +3052,7 @@ objects:
- name: Light_97
uid: 23e06c36cf974dfa99de9188dc92e253
id: 197
position: [4574.4585, 3002.22974]
position: [1077.45642, 2779.45776]
rotation: 0
layer: 0
visable: true
@ -3070,7 +3070,7 @@ objects:
- name: Light_98
uid: c4dc907adfb84cbf895fe9e4ebd845a2
id: 198
position: [1527.01941, 711.761902]
position: [4174.22314, 1244.88806]
rotation: 0
layer: 0
visable: true
@ -3088,7 +3088,7 @@ objects:
- name: Light_99
uid: 1aaa8f48df1f41e8b0511eb5f0e16817
id: 199
position: [302.452332, 1254.70752]
position: [1829.97058, 2884.68726]
rotation: 0
layer: 0
visable: true
@ -3114,10 +3114,24 @@ objects:
- type: ScriptComponent
scriptPath: C:\Users\spenc\OneDrive\Documents\GitHub\Create-Engine\src\assets\lua\fireflyes.lua
children: []
- name: Camera
uid: 759b414de4944cbfa8561eb1ab6dbe83
id: 202
position: [0, 0]
rotation: 0
layer: 0
visable: true
components:
- type: CameraComponent
fov: 45
aspect: 1.76999998
zoom: 0.5
primary: true
children: []
color_correction:
brightness: 2
saturation: 1.5
gamma: 1.83000004
bloom: true
intensity: 0.219999999
threshold: 0
threshold: 0.449999988

View File

@ -4,7 +4,7 @@
#include <memory>
#include <vector>
#include <yaml-cpp/yaml.h>
#include "../utils/ExceptionHandler.h"
#include "../core/utils/ExceptionHandler.h"
class Object;

View File

@ -1,6 +1,6 @@
#include "ScriptComponent.h"
#include "../utils/Logging.h"
#include "../utils/ExceptionHandler.h"
#include "../core/utils/Logging.h"
#include "../core/utils/ExceptionHandler.h"
#include "../utils/GameObjectsList.h"
#include "../Entitys/Object.h"
@ -10,8 +10,14 @@
#include "../Components/TextComponent.h"
#include "../Components/TilemapComponent.h"
#include "../utils/Profiler.h"
#include "../utils/utils.h"
#include "../core/utils/Profiler.h"
#include "../core/utils/utils.h"
#include "../core/utils/keycode.h"
#include "../core/utils/input.h"
#include "../core/types/vec2.h"
#include <lua.hpp>
#include <memory>
@ -20,6 +26,13 @@
static bool luaDebugEnabled = false;
static bool old_state = false;
#define SET_KC(name) \
lua_pushinteger(L, static_cast<int>(Keycode::name)); \
lua_setfield(L, -2, #name);
struct LuaObjectWrapper
{
Object *obj;
@ -135,6 +148,22 @@ static Component *GetComponentByName(Object *obj, const std::string &type)
return nullptr;
}
static int Lua_GetMousePos(lua_State *L)
{
PROFILE_DEEP_SCOPE("Engine::GetMousePos");
core::types::Vec2 m = Input::GetMousePosition();
LuaVector2* vec = (LuaVector2*)lua_newuserdata(L, sizeof(LuaVector2));
vec->x = m.x;
vec->y = m.y;
luaL_getmetatable(L, LUA_VECTOR2_MT);
lua_setmetatable(L, -2);
return 1;
}
static int Lua_Object_GetComponent(lua_State *L)
{
PROFILE_DEEP_SCOPE("Object::GetComponent");
@ -217,6 +246,174 @@ static int Lua_GetObjectByTag(lua_State *L)
lua_pushnil(L);
return 1;
}
static int keycode_loader(lua_State *L)
{
lua_newtable(L);
// Printable
SET_KC(Space)
SET_KC(Apostrophe)
SET_KC(Comma)
SET_KC(Minus)
SET_KC(Period)
SET_KC(Slash)
SET_KC(Key0)
SET_KC(Key1)
SET_KC(Key2)
SET_KC(Key3)
SET_KC(Key4)
SET_KC(Key5)
SET_KC(Key6)
SET_KC(Key7)
SET_KC(Key8)
SET_KC(Key9)
SET_KC(Semicolon)
SET_KC(Equal)
SET_KC(A)
SET_KC(B)
SET_KC(C)
SET_KC(D)
SET_KC(E)
SET_KC(F)
SET_KC(G)
SET_KC(H)
SET_KC(I)
SET_KC(J)
SET_KC(K)
SET_KC(L)
SET_KC(M)
SET_KC(N)
SET_KC(O)
SET_KC(P)
SET_KC(Q)
SET_KC(R)
SET_KC(S)
SET_KC(T)
SET_KC(U)
SET_KC(V)
SET_KC(W)
SET_KC(X)
SET_KC(Y)
SET_KC(Z)
SET_KC(LeftBracket)
SET_KC(Backslash)
SET_KC(RightBracket)
SET_KC(GraveAccent)
SET_KC(World1)
SET_KC(World2)
// Function & Navigation
SET_KC(Escape)
SET_KC(Enter)
SET_KC(Tab)
SET_KC(Backspace)
SET_KC(Insert)
SET_KC(Delete)
SET_KC(Right)
SET_KC(Left)
SET_KC(Down)
SET_KC(Up)
SET_KC(PageUp)
SET_KC(PageDown)
SET_KC(Home)
SET_KC(End)
SET_KC(CapsLock)
SET_KC(ScrollLock)
SET_KC(NumLock)
SET_KC(PrintScreen)
SET_KC(Pause)
SET_KC(F1)
SET_KC(F2)
SET_KC(F3)
SET_KC(F4)
SET_KC(F5)
SET_KC(F6)
SET_KC(F7)
SET_KC(F8)
SET_KC(F9)
SET_KC(F10)
SET_KC(F11)
SET_KC(F12)
SET_KC(F13)
SET_KC(F14)
SET_KC(F15)
SET_KC(F16)
SET_KC(F17)
SET_KC(F18)
SET_KC(F19)
SET_KC(F20)
SET_KC(F21)
SET_KC(F22)
SET_KC(F23)
SET_KC(F24)
SET_KC(F25)
// Keypad
SET_KC(KP0)
SET_KC(KP1)
SET_KC(KP2)
SET_KC(KP3)
SET_KC(KP4)
SET_KC(KP5)
SET_KC(KP6)
SET_KC(KP7)
SET_KC(KP8)
SET_KC(KP9)
SET_KC(KPDecimal)
SET_KC(KPDivide)
SET_KC(KPMultiply)
SET_KC(KPSubtract)
SET_KC(KPAdd)
SET_KC(KPEnter)
SET_KC(KPEqual)
// Modifiers
SET_KC(LeftShift)
SET_KC(LeftControl)
SET_KC(LeftAlt)
SET_KC(LeftSuper)
SET_KC(RightShift)
SET_KC(RightControl)
SET_KC(RightAlt)
SET_KC(RightSuper)
SET_KC(Menu)
#undef SET_KC
lua_setglobal(L, "Keycode");
return 1;
}
static int Lua_KeyDown(lua_State *L)
{
// match your other deepprofile scopes
PROFILE_DEEP_SCOPE("Engine::KeyDown");
// grab the integer keycode from Lua
lua_Integer code = luaL_checkinteger(L, 1);
// cast into your stronglytyped enum and query
bool down = Input::IsKeyDown(static_cast<Keycode>(code));
// return a Lua boolean
lua_pushboolean(L, down);
return 1;
}
static int Lua_Vector2_New(lua_State *L)
{
PROFILE_DEEP_SCOPE("Vector2()");
@ -279,7 +476,7 @@ void RegisterVector2Type(lua_State *L)
lua_pushcfunction(L, Lua_Vector2_NewIndex);
lua_setfield(L, -2, "__newindex");
lua_pop(L, 1); // Pop metatable
lua_pop(L, 1);
lua_pushcfunction(L, Lua_Vector2_New);
lua_setglobal(L, "Vector2");
@ -300,7 +497,15 @@ void ScriptComponent::RegisterEngineBindings()
lua_setfield(L, -2, "GetObjectByTag");
lua_pushcfunction(L, Lua_DebugLua);
lua_setfield(L, -2, "DebugLua");
lua_pushcfunction(L, Lua_KeyDown);
lua_setfield(L, -2, "KeyDown");
lua_pushcfunction(L, Lua_GetMousePos);
lua_setfield(L, -2, "GetMousePos");
lua_setglobal(L, "Engine");
}
void ScriptComponent::ReloadScript()
@ -319,6 +524,8 @@ void ScriptComponent::ReloadScript()
RegisterObjectType(L);
RegisterVector2Type(L);
RegisterEngineBindings();
keycode_loader(L);
Logger::LogVerbose("[Lua] Loading Script from file.");
if (luaL_dofile(L, scriptPath.c_str()))

View File

@ -4,18 +4,13 @@
#include <unordered_map>
#include <GL/glew.h>
#include <iostream>
#include "../utils/Logging.h"
#include "../utils/utils.h"
#include "../core/utils/Logging.h"
#include "../core/utils/utils.h"
struct ImageCacheEntry {
unsigned int textureID;
glm::vec2 size;
};
static std::unordered_map<std::string, ImageCacheEntry> textureCache;

View File

@ -6,6 +6,9 @@
class SpriteComponent : public Component {
public:
SpriteComponent(Object* owner);

View File

@ -1,7 +1,7 @@
#include "TilemapComponent.h"
#include "../utils/Logging.h"
#include "../utils/FileDialog.h"
#include "../utils/utils.h"
#include "../core/utils/Logging.h"
#include "../core/utils/FileDialog.h"
#include "../core/utils/utils.h"
#include <stb_image.h>
#include <cstdio>
#include <cstring>

View File

@ -8,13 +8,17 @@
#include "components/ScriptComponent.h"
#include "components/PhysicsComponent.h"
#include "utils/FileDialog.h"
#include "utils/Logging.h"
#include "core/utils/FileDialog.h"
#include "core/utils/Logging.h"
#include "utils/EngineConfig.h"
#include "core/utils/EngineConfig.h"
#include "utils/GameObjectsList.h"
#include "utils/Profiler.h"
#include "utils/utils.h"
#include "core/utils/Profiler.h"
#include "core/utils/utils.h"
#include "editor/windows/AssetBrowser.h"
#include "editor/windows/Inspector.h"
#include <GL/glew.h>
#include <GLFW/glfw3.h>
@ -437,250 +441,7 @@ void Engine::Init()
Logger::LogInfo("Initialized Engine");
}
void DrawInspectorUI(std::shared_ptr<Object> selected)
{
PROFILE_ENGINE_SCOPE("Engine::DrawInspectorUI");
ImGui::Begin("Inspector");
if (!selected)
{
ImGui::TextDisabled("No object selected.");
ImGui::End();
return;
}
// --- keep track of the name buffer ---
static char nameBuffer[128] = "";
static std::shared_ptr<Object> lastSelected = nullptr;
if (selected != lastSelected)
{
strncpy(nameBuffer, selected->GetName().c_str(), sizeof(nameBuffer));
nameBuffer[sizeof(nameBuffer) - 1] = '\0';
lastSelected = selected;
}
// --- General ---
ImGui::TextUnformatted("General");
ImGui::Separator();
// Name edit
if (ImGui::InputText("Name", nameBuffer, sizeof(nameBuffer)))
selected->SetName(nameBuffer);
// Visibility toggle
bool visible = selected->GetVisable();
if (ImGui::Checkbox("Visible", &visible))
selected->SetVisable(visible);
// --- Transform ---
ImGui::TextUnformatted("Transform");
ImGui::Separator();
glm::vec2 pos = selected->GetLocalPosition();
if (ImGui::DragFloat2("Position", &pos.x, 0.1f))
selected->SetLocalPosition(pos);
float rotation = selected->GetLocalRotation();
if (ImGui::DragFloat("Rotation", &rotation, 1.0f))
selected->SetLocalRotation(rotation);
int layer = selected->layer;
if (ImGui::InputInt("Layer", &layer))
selected->layer = layer;
ImGui::Text("ID: %d", selected->uid.id);
ImGui::Text("UID: %s", selected->uid.uuid.c_str());
ImGui::Spacing();
ImGui::SeparatorText("Add Component");
static const char *componentTypes[] = {
"SpriteComponent",
"CameraComponent",
"LightComponent",
"ScriptComponent",
"TilemapComponent"};
static int selectedIndex = -1;
if (ImGui::BeginCombo("##ComponentCombo", selectedIndex >= 0 ? componentTypes[selectedIndex] : "Select Component"))
{
for (int i = 0; i < IM_ARRAYSIZE(componentTypes); ++i)
{
bool isSelected = (selectedIndex == i);
if (ImGui::Selectable(componentTypes[i], isSelected))
selectedIndex = i;
if (isSelected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
ImGui::SameLine();
if (ImGui::Button("Add") && selectedIndex != -1 && selected)
{
const std::string type = componentTypes[selectedIndex];
if (type == "SpriteComponent" && !selected->GetComponent<SpriteComponent>())
selected->AddComponent<SpriteComponent>();
else if (type == "CameraComponent" && !selected->GetComponent<CameraComponent>())
selected->AddComponent<CameraComponent>();
else if (type == "LightComponent" && !selected->GetComponent<LightComponent>())
selected->AddComponent<LightComponent>();
else if (type == "ScriptComponent" && !selected->GetComponent<ScriptComponent>())
selected->AddComponent<ScriptComponent>();
else if (type == "TilemapComponent" && !selected->GetComponent<TilemapComponent>())
selected->AddComponent<TilemapComponent>();
}
if (auto sprite = selected->GetComponent<SpriteComponent>())
{
ImGui::SeparatorText("Sprite Component");
const char *renderTypes[] = {"Unlit", "Lit"};
SpriteComponent::RenderType currentType = sprite->GetRenderType();
int currentTypeIndex = static_cast<int>(currentType);
if (ImGui::Combo("Render Type", &currentTypeIndex, renderTypes, IM_ARRAYSIZE(renderTypes)))
{
sprite->SetRenderType(static_cast<SpriteComponent::RenderType>(currentTypeIndex));
}
std::string tex = sprite->GetTexturePath();
ImGui::Text("Texture: %s", tex.c_str());
if (ImGui::Button("Load Texture"))
{
auto path = OpenFileDialog(FileDialogType::Images);
if (!path.empty())
sprite->SetTexture(path);
}
std::string norm = sprite->GetNormalMapPath();
ImGui::Text("Normal Map: %s", norm.c_str());
if (ImGui::Button("Load Normal Map"))
{
auto path = OpenFileDialog(FileDialogType::Images);
if (!path.empty())
sprite->SetNormalMap(path);
}
glm::vec2 size = sprite->GetSize();
ImGui::Text("Size: %.0f x %.0f", size.x, size.y);
if (ImGui::Button("Remove SpriteComponent"))
selected->RemoveComponent<SpriteComponent>();
}
if (auto cam = selected->GetComponent<CameraComponent>())
{
ImGui::SeparatorText("Camera Component");
float fov = cam->GetFOV();
float aspect = cam->GetAspect();
float zoom = cam->GetZoom();
if (ImGui::DragFloat("FOV", &fov, 0.1f, 1.0f, 179.0f))
cam->SetFOV(fov);
if (ImGui::DragFloat("Aspect", &aspect, 0.01f, 0.1f, 5.0f))
cam->SetAspect(aspect);
if (ImGui::DragFloat("Zoom", &zoom, 0.1f, 0.1f, 10.0f))
cam->SetZoom(zoom);
bool isPrimary = cam->IsPrimary();
if (ImGui::Checkbox("Primary", &isPrimary))
cam->SetPrimary(isPrimary);
if (ImGui::Button("Remove CameraComponent"))
selected->RemoveComponent<CameraComponent>();
}
if (auto light = selected->GetComponent<LightComponent>())
{
ImGui::SeparatorText("Light Component");
glm::vec3 color = light->GetColor();
float intensity = light->GetIntensity();
float radius = light->GetRadius();
float falloff = light->GetFalloff();
int type = light->GetType();
if (ImGui::ColorEdit3("Color", &color.x))
light->SetColor(color);
if (ImGui::DragFloat("Intensity", &intensity, 0.05f, 0.0f, 10.0f))
light->SetIntensity(intensity);
if (ImGui::DragFloat("Radius", &radius, 1.0f, 10.0f, 1000.0f))
light->SetRadius(radius);
if (ImGui::DragFloat("Falloff", &falloff, 0.05f, 0.1f, 5.0f))
light->SetFalloff(falloff);
// const char* types[] = { "Point", "Directional" };
// if (ImGui::Combo("Type", &type, types, IM_ARRAYSIZE(types)))
// light->SetType(type);
if (ImGui::Button("Remove LightComponent"))
selected->RemoveComponent<LightComponent>();
}
if (auto script = selected->GetComponent<ScriptComponent>())
{
ImGui::SeparatorText("Script Component");
std::string path = script->GetScriptPath();
ImGui::Text("Script Path:");
ImGui::TextWrapped("%s", path.c_str());
if (ImGui::Button("Load Script"))
{
std::string chosen = OpenFileDialog(FileDialogType::Scripts); // Add 'Scripts' filter if needed
if (!chosen.empty())
script->SetScriptPath(chosen);
}
ImGui::SameLine();
if (ImGui::Button("Reload"))
{
script->ReloadScript();
}
if (ImGui::Button("Remove ScriptComponent"))
selected->RemoveComponent<ScriptComponent>();
}
if (auto phys = selected->GetComponent<PhysicsComponent>())
{
ImGui::SeparatorText("Physics Component");
glm::vec2 vel = phys->GetVelocity();
if (ImGui::DragFloat2("Velocity", &vel.x))
phys->SetVelocity(vel);
float friction = phys->GetFriction();
if (ImGui::DragFloat("Friction", &friction, 0.01f, 0.0f, 1.0f))
phys->SetFriction(friction);
bool fixed = phys->IsFixedRotation();
if (ImGui::Checkbox("Fixed Rotation", &fixed))
phys->SetFixedRotation(fixed);
if (ImGui::Button("Remove PhysicsComponent"))
selected->RemoveComponent<PhysicsComponent>();
}
if (auto tilemap = selected->GetComponent<TilemapComponent>())
{
ImGui::SeparatorText("Tilemap Component");
ImGui::Text("Refer to Tilemap Editor Window");
if (ImGui::Button("Remove TilemapComponent"))
selected->RemoveComponent<TilemapComponent>();
}
ImGui::End();
if (auto tilemap = selected->GetComponent<TilemapComponent>())
{
tilemap->DrawEditorUI();
}
}
void Engine::collectObjects(bool playing, const glm::vec2 &camPos, float camZoom)
{
@ -883,6 +644,8 @@ void Engine::Run()
if (g_engineConfig.settings.show_color_correction_window)
ShowColorCorrectionWindow();
ShowAssetBrowser();
{
PROFILE_ENGINE_SCOPE("Engine::DrawSceneTree");
@ -1013,9 +776,9 @@ void Engine::Run()
m_scriptUpdates.clear();
profiler.EndEngineSection();
//profiler.BeginEngineSection("Draw Editor Grid");
//Renderer::DrawEditorGrid(cameraPos, cameraZoom);
//profiler.EndEngineSection();
// profiler.BeginEngineSection("Draw Editor Grid");
// Renderer::DrawEditorGrid(cameraPos, cameraZoom);
// profiler.EndEngineSection();
// Collect Objects
profiler.BeginEngineSection("Collect Objects");

View File

@ -7,7 +7,7 @@
#include "../Components/TextComponent.h"
#include "../Components/ScriptComponent.h"
#include "../utils/Logging.h"
#include "../core/utils/Logging.h"
#include "../utils/UID.h"
#include <algorithm>

View File

@ -1,10 +1,10 @@
#include "Renderer.h"
#include "Components/SpriteComponent.h"
#include "utils/Shader.h"
#include "utils/Logging.h"
#include "utils/EngineConfig.h"
#include "utils/utils.h"
#include "utils/Profiler.h"
#include "core/utils/Logging.h"
#include "core/utils/EngineConfig.h"
#include "core/utils/utils.h"
#include "core/utils/Profiler.h"
#include "Entitys/Object.h"
#include "stb_image.h"
@ -214,28 +214,6 @@ void Renderer::Init()
s_DrawCalls = 0;
}
void Renderer::UpdateClusterLights()
{
PROFILE_ENGINE_SCOPE("Renderer::UpdateClusterLights");
@ -245,7 +223,8 @@ void Renderer::UpdateClusterLights()
const int totalClusters = s_ClusterCols * s_ClusterRows;
static int lastCols = 0, lastRows = 0;
if (lastCols != s_ClusterCols || lastRows != s_ClusterRows) {
if (lastCols != s_ClusterCols || lastRows != s_ClusterRows)
{
lastCols = s_ClusterCols;
lastRows = s_ClusterRows;
s_Clusters.clear();
@ -254,18 +233,26 @@ void Renderer::UpdateClusterLights()
c.lightIndices.reserve(MAX_LIGHTS_PER_CLUSTER);
}
{
PROFILE_ENGINE_SCOPE("Clear");
for (auto &c : s_Clusters)
{
c.lightIndices.clear();
}
}
const float invCluster = 1.0f / float(CLUSTER_SIZE);
const int maxCol = s_ClusterCols - 1;
const int maxRow = s_ClusterRows - 1;
{
PROFILE_ENGINE_SCOPE("Assign");
for (int i = 0, n = int(s_Lights.size()); i < n; ++i)
{
PROFILE_ENGINE_SCOPE("L" + std::to_string(i));
const Light& light = s_Lights[i];
const Light &light = s_Lights[i];
glm::vec2 lo = light.screenPos - glm::vec2(light.radius);
glm::vec2 hi = light.screenPos + glm::vec2(light.radius);
@ -274,48 +261,61 @@ void Renderer::UpdateClusterLights()
int minY = std::max(int(lo.y * invCluster), 0);
int maxY = std::min(int(hi.y * invCluster), maxRow);
for (int y = minY; y <= maxY; ++y) {
for (int x = minX; x <= maxX; ++x) {
for (int y = minY; y <= maxY; ++y)
{
for (int x = minX; x <= maxX; ++x)
{
auto &cell = s_Clusters[y * s_ClusterCols + x].lightIndices;
if (int(cell.size()) < MAX_LIGHTS_PER_CLUSTER)
cell.emplace_back(i);
}
}
}
}
static std::vector<int> packed;
static size_t gpuBufferBytes = 0;
const size_t packCount = size_t(totalClusters) * MAX_LIGHTS_PER_CLUSTER;
const size_t byteSize = packCount * sizeof(int);
packed.assign(packCount, -1);
for (int c = 0; c < totalClusters; ++c) {
{
PROFILE_ENGINE_SCOPE("Pack");
packed.resize(packCount);
int *dst = packed.data();
std::memset(dst, 0xFF, packCount * sizeof(int));
for (int c = 0; c < totalClusters; ++c)
{
auto &src = s_Clusters[c].lightIndices;
std::copy(src.begin(), src.end(), packed.begin() + c * MAX_LIGHTS_PER_CLUSTER);
int n = int(src.size());
if (n > MAX_LIGHTS_PER_CLUSTER)
n = MAX_LIGHTS_PER_CLUSTER;
std::memcpy(
dst + c * MAX_LIGHTS_PER_CLUSTER,
src.data(),
n * sizeof(int));
}
}
{
PROFILE_ENGINE_SCOPE("Bind");
glBindBuffer(GL_SHADER_STORAGE_BUFFER, s_ClusterSSBO);
if (byteSize != gpuBufferBytes) {
if (byteSize != gpuBufferBytes)
{
glBufferData(GL_SHADER_STORAGE_BUFFER, byteSize, packed.data(), GL_DYNAMIC_DRAW);
gpuBufferBytes = byteSize;
} else {
}
else
{
glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, byteSize, packed.data());
}
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, s_ClusterSSBO);
}
}
void Renderer::Resize(int w, int h)
{
if (w == width && h == height)

View File

@ -6,9 +6,9 @@
#include "Components/TilemapComponent.h"
#include "Components/SpriteComponent.h"
#include "utils/EngineConfig.h"
#include "core/utils/EngineConfig.h"
#include "utils/Shader.h"
#include "utils/Profiler.h"
#include "core/utils/Profiler.h"
struct ColorCorrection
{

View File

@ -0,0 +1,17 @@
#pragma once
namespace core {
namespace types {
struct Color
{
float r{1}, g{1}, b{1}, a{1};
Color() = default;
Color(float _r, float _g, float _b, float _a = 1.0f)
: r(_r), g(_g), b(_b), a(_a)
{}
};
}
}

29
src/src/core/types/rect.h Normal file
View File

@ -0,0 +1,29 @@
// core/types/rect.h
#pragma once
#include "vec2.h"
namespace core
{
namespace types
{
struct Rect
{
Vec2 pos{0, 0};
Vec2 size{0, 0};
Rect() = default;
Rect(const Vec2 &_pos, const Vec2 &_size)
: pos(_pos), size(_size)
{
}
bool contains(const Vec2 &p) const
{
return p.x >= pos.x && p.y >= pos.y && p.x < pos.x + size.x && p.y < pos.y + size.y;
}
};
}
}

34
src/src/core/types/vec2.h Normal file
View File

@ -0,0 +1,34 @@
// core/types/vec2.h
#pragma once
namespace core
{
namespace types
{
struct Vec2
{
float x{0}, y{0};
Vec2() = default;
Vec2(float _x, float _y) : x(_x), y(_y) {}
Vec2 &operator+=(const Vec2 &o)
{
x += o.x;
y += o.y;
return *this;
}
Vec2 &operator-=(const Vec2 &o)
{
x -= o.x;
y -= o.y;
return *this;
}
friend Vec2 operator+(Vec2 a, const Vec2 &b) { return a += b; }
friend Vec2 operator-(Vec2 a, const Vec2 &b) { return a -= b; }
};
}
}

51
src/src/core/types/vec3.h Normal file
View File

@ -0,0 +1,51 @@
#pragma once
namespace core
{
namespace types
{
struct Vec3
{
float x{0}, y{0}, z{0};
Vec3() = default;
Vec3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
Vec3 &operator+=(const Vec3 &o)
{
x += o.x;
y += o.y;
z += o.z;
return *this;
}
Vec3 &operator-=(const Vec3 &o)
{
x -= o.x;
y -= o.y;
z -= o.z;
return *this;
}
Vec3 &operator*=(float s)
{
x *= s;
y *= s;
z *= s;
return *this;
}
Vec3 &operator/=(float s)
{
x /= s;
y /= s;
z /= s;
return *this;
}
friend Vec3 operator+(Vec3 a, const Vec3 &b) { return a += b; }
friend Vec3 operator-(Vec3 a, const Vec3 &b) { return a -= b; }
friend Vec3 operator*(Vec3 v, float s) { return v *= s; }
friend Vec3 operator/(Vec3 v, float s) { return v /= s; }
};
}
}

58
src/src/core/types/vec4.h Normal file
View File

@ -0,0 +1,58 @@
#pragma once
namespace core
{
namespace types
{
struct Vec4
{
float x{0}, y{0}, z{0}, w{0};
Vec4() = default;
Vec4(float _x, float _y, float _z, float _w)
: x(_x), y(_y), z(_z), w(_w)
{
}
Vec4 &operator+=(const Vec4 &o)
{
x += o.x;
y += o.y;
z += o.z;
w += o.w;
return *this;
}
Vec4 &operator-=(const Vec4 &o)
{
x -= o.x;
y -= o.y;
z -= o.z;
w -= o.w;
return *this;
}
Vec4 &operator*=(float s)
{
x *= s;
y *= s;
z *= s;
w *= s;
return *this;
}
Vec4 &operator/=(float s)
{
x /= s;
y /= s;
z /= s;
w /= s;
return *this;
}
friend Vec4 operator+(Vec4 a, const Vec4 &b) { return a += b; }
friend Vec4 operator-(Vec4 a, const Vec4 &b) { return a -= b; }
friend Vec4 operator*(Vec4 v, float s) { return v *= s; }
friend Vec4 operator/(Vec4 v, float s) { return v /= s; }
};
}
}

View File

View File

View File

@ -4,15 +4,16 @@
#include <cstdio>
#include <iostream>
// Logger.cpp or a logger helper header
#include <fstream>
#include <filesystem>
#include <windows.h>
class ScopedLogFileWriter {
class ScopedLogFileWriter
{
public:
ScopedLogFileWriter() {
ScopedLogFileWriter()
{
// Resolve user folder
char userPath[MAX_PATH];
DWORD len = GetEnvironmentVariableA("USERPROFILE", userPath, MAX_PATH);
@ -26,20 +27,18 @@ public:
stream.open(logPath, std::ios::out | std::ios::app); // append mode
}
~ScopedLogFileWriter() {
~ScopedLogFileWriter()
{
if (stream.is_open())
stream.close();
}
std::ofstream& Get() { return stream; }
std::ofstream &Get() { return stream; }
private:
std::ofstream stream;
};
std::vector<Logger::LogMessage> Logger::s_Messages;
bool Logger::s_AutoScroll = true;
bool Logger::s_ShowInfo = true;
@ -95,30 +94,25 @@ void Logger::Log(Level level, const char *fmt, ...)
va_end(args);
}
void Logger::LogVA(Level level, const char* fmt, va_list args)
void Logger::LogVA(Level level, const char *fmt, va_list args)
{
char buffer[1024];
vsnprintf(buffer, sizeof(buffer), fmt, args);
s_Messages.push_back({ buffer, level });
s_Messages.push_back({buffer, level});
const char* levelStr = ToString(level);
const char* ansiColor = GetAnsiColor(level);
const char *levelStr = ToString(level);
const char *ansiColor = GetAnsiColor(level);
std::string formatted = std::string("[Logger][") + levelStr + "] " + buffer;
std::cout << ansiColor << formatted << "\033[0m\n";
ScopedLogFileWriter logFile;
auto& out = logFile.Get();
auto &out = logFile.Get();
if (out.is_open())
out << formatted << "\n";
}
void Logger::LogInfo(const char *fmt, ...)
{
va_list args;
@ -164,6 +158,7 @@ void Logger::Clear()
s_Messages.clear();
}
void Logger::Draw(const char *title)
{
ImGui::Begin(title);
@ -183,11 +178,12 @@ void Logger::Draw(const char *title)
ImGui::Checkbox("Debug", &s_ShowDebug);
ImGui::SameLine();
ImGui::Checkbox("Verbose", &s_ShowVerbose);
ImGui::Separator();
ImGui::BeginChild("LogMessages");
std::vector<const LogMessage *> filtered;
filtered.reserve(s_Messages.size());
for (const auto &msg : s_Messages)
{
if ((msg.level == Info && !s_ShowInfo) ||
@ -195,37 +191,47 @@ void Logger::Draw(const char *title)
(msg.level == Error && !s_ShowError) ||
(msg.level == Debug && !s_ShowDebug) ||
(msg.level == Verbose && !s_ShowVerbose))
{
continue;
filtered.push_back(&msg);
}
ImGuiListClipper clipper;
clipper.Begin((int)filtered.size());
while (clipper.Step())
{
for (int idx = clipper.DisplayStart; idx < clipper.DisplayEnd; idx++)
{
const LogMessage *msg = filtered[idx];
ImVec4 color;
switch (msg.level)
switch (msg->level)
{
case Info:
color = ImVec4(0.8f, 0.8f, 0.8f, 1.0f);
break; // Light gray
break;
case Warning:
color = ImVec4(1.0f, 0.85f, 0.3f, 1.0f);
break; // Yellow
break;
case Error:
color = ImVec4(1.0f, 0.3f, 0.3f, 1.0f);
break; // Red
break;
case Debug:
color = ImVec4(0.3f, 0.9f, 1.0f, 1.0f);
break; // Cyan
break;
case Verbose:
color = ImVec4(0.5f, 0.5f, 0.5f, 1.0f);
break; // Dim gray
break;
default:
color = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
break; // Fallback white
color = ImVec4(1, 1, 1, 1);
break;
}
ImGui::PushStyleColor(ImGuiCol_Text, color);
ImGui::Text("[%s] %s", ToString(msg.level), msg.text.c_str());
ImGui::Text("[%s] %s", ToString(msg->level), msg->text.c_str());
ImGui::PopStyleColor();
}
}
clipper.End();
if (s_AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
ImGui::SetScrollHereY(1.0f);

View File

@ -0,0 +1,20 @@
#include "input.h"
#include <GLFW/glfw3.h>
#include <imgui.h>
extern GLFWwindow* window;
namespace Input
{
bool IsKeyDown(Keycode key)
{
return glfwGetKey(window, static_cast<int>(key)) == GLFW_PRESS;
}
core::types::Vec2 GetMousePosition()
{
ImVec2 p = ImGui::GetMousePos();
return core::types::Vec2 { p.x, p.y };
}
}

View File

@ -0,0 +1,10 @@
#pragma once
#include "keycode.h"
#include "../types/vec2.h"
namespace Input
{
bool IsKeyDown(Keycode key);
core::types::Vec2 GetMousePosition();
}

View File

@ -0,0 +1,134 @@
#pragma once
#include <GLFW/glfw3.h>
enum class Keycode : int
{
// Printable keys
Space = GLFW_KEY_SPACE,
Apostrophe = GLFW_KEY_APOSTROPHE, ///< '
Comma = GLFW_KEY_COMMA, ///< ,
Minus = GLFW_KEY_MINUS, ///< -
Period = GLFW_KEY_PERIOD, ///< .
Slash = GLFW_KEY_SLASH, ///< /
Key0 = GLFW_KEY_0,
Key1 = GLFW_KEY_1,
Key2 = GLFW_KEY_2,
Key3 = GLFW_KEY_3,
Key4 = GLFW_KEY_4,
Key5 = GLFW_KEY_5,
Key6 = GLFW_KEY_6,
Key7 = GLFW_KEY_7,
Key8 = GLFW_KEY_8,
Key9 = GLFW_KEY_9,
Semicolon = GLFW_KEY_SEMICOLON, ///< ;
Equal = GLFW_KEY_EQUAL, ///< =
A = GLFW_KEY_A,
B = GLFW_KEY_B,
C = GLFW_KEY_C,
D = GLFW_KEY_D,
E = GLFW_KEY_E,
F = GLFW_KEY_F,
G = GLFW_KEY_G,
H = GLFW_KEY_H,
I = GLFW_KEY_I,
J = GLFW_KEY_J,
K = GLFW_KEY_K,
L = GLFW_KEY_L,
M = GLFW_KEY_M,
N = GLFW_KEY_N,
O = GLFW_KEY_O,
P = GLFW_KEY_P,
Q = GLFW_KEY_Q,
R = GLFW_KEY_R,
S = GLFW_KEY_S,
T = GLFW_KEY_T,
U = GLFW_KEY_U,
V = GLFW_KEY_V,
W = GLFW_KEY_W,
X = GLFW_KEY_X,
Y = GLFW_KEY_Y,
Z = GLFW_KEY_Z,
LeftBracket = GLFW_KEY_LEFT_BRACKET, ///< [
Backslash = GLFW_KEY_BACKSLASH, ///<
RightBracket = GLFW_KEY_RIGHT_BRACKET, ///< ]
GraveAccent = GLFW_KEY_GRAVE_ACCENT, ///< `
World1 = GLFW_KEY_WORLD_1, ///< non-US #1
World2 = GLFW_KEY_WORLD_2, ///< non-US #2
// Function keys & navigation
Escape = GLFW_KEY_ESCAPE,
Enter = GLFW_KEY_ENTER,
Tab = GLFW_KEY_TAB,
Backspace = GLFW_KEY_BACKSPACE,
Insert = GLFW_KEY_INSERT,
Delete = GLFW_KEY_DELETE,
Right = GLFW_KEY_RIGHT,
Left = GLFW_KEY_LEFT,
Down = GLFW_KEY_DOWN,
Up = GLFW_KEY_UP,
PageUp = GLFW_KEY_PAGE_UP,
PageDown = GLFW_KEY_PAGE_DOWN,
Home = GLFW_KEY_HOME,
End = GLFW_KEY_END,
CapsLock = GLFW_KEY_CAPS_LOCK,
ScrollLock = GLFW_KEY_SCROLL_LOCK,
NumLock = GLFW_KEY_NUM_LOCK,
PrintScreen = GLFW_KEY_PRINT_SCREEN,
Pause = GLFW_KEY_PAUSE,
F1 = GLFW_KEY_F1,
F2 = GLFW_KEY_F2,
F3 = GLFW_KEY_F3,
F4 = GLFW_KEY_F4,
F5 = GLFW_KEY_F5,
F6 = GLFW_KEY_F6,
F7 = GLFW_KEY_F7,
F8 = GLFW_KEY_F8,
F9 = GLFW_KEY_F9,
F10 = GLFW_KEY_F10,
F11 = GLFW_KEY_F11,
F12 = GLFW_KEY_F12,
F13 = GLFW_KEY_F13,
F14 = GLFW_KEY_F14,
F15 = GLFW_KEY_F15,
F16 = GLFW_KEY_F16,
F17 = GLFW_KEY_F17,
F18 = GLFW_KEY_F18,
F19 = GLFW_KEY_F19,
F20 = GLFW_KEY_F20,
F21 = GLFW_KEY_F21,
F22 = GLFW_KEY_F22,
F23 = GLFW_KEY_F23,
F24 = GLFW_KEY_F24,
F25 = GLFW_KEY_F25,
// Keypad
KP0 = GLFW_KEY_KP_0,
KP1 = GLFW_KEY_KP_1,
KP2 = GLFW_KEY_KP_2,
KP3 = GLFW_KEY_KP_3,
KP4 = GLFW_KEY_KP_4,
KP5 = GLFW_KEY_KP_5,
KP6 = GLFW_KEY_KP_6,
KP7 = GLFW_KEY_KP_7,
KP8 = GLFW_KEY_KP_8,
KP9 = GLFW_KEY_KP_9,
KPDecimal = GLFW_KEY_KP_DECIMAL,
KPDivide = GLFW_KEY_KP_DIVIDE,
KPMultiply = GLFW_KEY_KP_MULTIPLY,
KPSubtract = GLFW_KEY_KP_SUBTRACT,
KPAdd = GLFW_KEY_KP_ADD,
KPEnter = GLFW_KEY_KP_ENTER,
KPEqual = GLFW_KEY_KP_EQUAL,
// Modifiers
LeftShift = GLFW_KEY_LEFT_SHIFT,
LeftControl = GLFW_KEY_LEFT_CONTROL,
LeftAlt = GLFW_KEY_LEFT_ALT,
LeftSuper = GLFW_KEY_LEFT_SUPER,
RightShift = GLFW_KEY_RIGHT_SHIFT,
RightControl = GLFW_KEY_RIGHT_CONTROL,
RightAlt = GLFW_KEY_RIGHT_ALT,
RightSuper = GLFW_KEY_RIGHT_SUPER,
Menu = GLFW_KEY_MENU
};

View File

@ -4,13 +4,22 @@
#include <windows.h>
#include <filesystem>
#include <string>
#include <unordered_map>
#include <mutex>
std::unordered_map<std::string, ImageCacheEntry> textureCache;
std::unordered_map<std::string, ImageCacheEntry> engineTextureCache;
static std::map<std::string, GLuint> textureCache;
GLuint LoadTextureIfNeeded(const std::string &path)
{
if (textureCache.count(path))
return textureCache[path];
auto [it, inserted] = textureCache.try_emplace(path, ImageCacheEntry{});
if (!inserted)
{
return it->second.textureID;
}
int w, h, channels;
stbi_set_flip_vertically_on_load(false);
@ -26,12 +35,45 @@ GLuint LoadTextureIfNeeded(const std::string &path)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
stbi_image_free(data);
textureCache[path] = id;
glm::vec2 imageSize(w, h);
it->second = { id, imageSize };
Logger::LogVerbose("Loaded Image: '%s'", path.c_str());
return id;
}
GLuint EngineLoadTextureIfNeeded(const std::string &path)
{
auto [it, inserted] = engineTextureCache.try_emplace(path, ImageCacheEntry{});
if (!inserted)
{
return it->second.textureID;
}
int w, h, channels;
stbi_set_flip_vertically_on_load(false);
unsigned char *data = stbi_load(path.c_str(), &w, &h, &channels, 4);
if (!data)
return 0;
GLuint id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
stbi_image_free(data);
glm::vec2 imageSize(w, h);
it->second = { id, imageSize };
Logger::LogVerbose("Loaded Image: '%s'", path.c_str());
return id;
}
#include <unordered_map>
#include <mutex>
std::string GetFilenameFromPath(const std::string &path)
{

View File

@ -4,11 +4,29 @@
#include <GL/glew.h>
#include <glm/glm.hpp>
// here so i only need to include once.
#include "Profiler.h"
#include "Logging.h"
#include "FileDialog.h"
struct ImageCacheEntry {
unsigned int textureID;
glm::vec2 size;
};
extern std::unordered_map<std::string, ImageCacheEntry> textureCache;
// Returns filename from a full path (e.g., "C:/foo/bar.png" → "bar.png")
std::string GetFilenameFromPath(const std::string& path);
// Loads a texture (with caching). Returns OpenGL texture ID
GLuint LoadTextureIfNeeded(const std::string& path);
GLuint EngineLoadTextureIfNeeded(const std::string &path);
bool DeleteLatestLogFile();

View File

@ -0,0 +1,70 @@
// core/render/AssetBrowser.cpp
#include "AssetBrowser.h"
#include <imgui.h>
extern std::unordered_map<std::string, ImageCacheEntry> textureCache;
void ShowAssetBrowser()
{
PROFILE_ENGINE_SCOPE("Editor::AssetBrowser");
ImGui::Begin("Asset Browser");
if (ImGui::Button("Load Asset"))
{
std::string path = OpenFileDialog(FileDialogType::Images);
if (!path.empty())
{
LoadTextureIfNeeded(path);
}
}
ImGui::Separator();
ImGui::BeginChild("##AssetScroll", ImVec2(0, 0), true);
const float padding = 8.0f;
const float thumbnailSize = 64.0f;
const float cellSize = thumbnailSize + padding;
float availWidth = ImGui::GetContentRegionAvail().x;
int columns = static_cast<int>(availWidth / cellSize);
if (columns < 1) columns = 1;
ImGui::Columns(columns, nullptr, false);
int idx = 0;
for (auto& kv : textureCache)
{
ImGui::PushID(idx++);
const std::string& path = kv.first;
const auto& entry = kv.second;
std::string displayName = GetFilenameFromPath(path);
ImGui::ImageButton("##Image",
(ImTextureID)(intptr_t)entry.textureID,
ImVec2(thumbnailSize, thumbnailSize),
ImVec2(0,0), ImVec2(1,1)
);
if (ImGui::BeginDragDropSource())
{
ImGui::SetDragDropPayload("ASSET_TEXTURE",
path.c_str(),
path.size()+1);
ImGui::Image((ImTextureID)(intptr_t)entry.textureID,
ImVec2(thumbnailSize*2, thumbnailSize*2));
ImGui::Text("%s", displayName.c_str());
ImGui::EndDragDropSource();
}
ImGui::TextWrapped("%s", displayName.c_str());
ImGui::NextColumn();
ImGui::PopID();
}
ImGui::Columns(1);
ImGui::EndChild();
ImGui::End();
}

View File

@ -0,0 +1,16 @@
// core/render/AssetBrowser.h
#pragma once
#include <unordered_map>
#include <string>
#include <glm/vec2.hpp>
#include "../../core/utils/Profiler.h"
#include "../../core/utils/utils.h"
#include "../../Components/SpriteComponent.h"
void ShowAssetBrowser();

View File

@ -0,0 +1,289 @@
#include "Inspector.h"
#include "../../Entitys/Object.h"
#include "../../components/SpriteComponent.h"
#include "../../components/CameraComponent.h"
#include "../../components/LightComponent.h"
#include "../../components/TilemapComponent.h"
#include "../../components/ScriptComponent.h"
#include "../../components/PhysicsComponent.h"
void DrawInspectorUI(std::shared_ptr<Object> selected)
{
PROFILE_ENGINE_SCOPE("Engine::DrawInspectorUI");
ImGui::Begin("Inspector");
if (!selected)
{
ImGui::TextDisabled("No object selected.");
ImGui::End();
return;
}
// --- keep track of the name buffer ---
static char nameBuffer[128] = "";
static std::shared_ptr<Object> lastSelected = nullptr;
if (selected != lastSelected)
{
strncpy(nameBuffer, selected->GetName().c_str(), sizeof(nameBuffer));
nameBuffer[sizeof(nameBuffer) - 1] = '\0';
lastSelected = selected;
}
// --- General ---
ImGui::TextUnformatted("General");
ImGui::Separator();
// Name edit
if (ImGui::InputText("Name", nameBuffer, sizeof(nameBuffer)))
selected->SetName(nameBuffer);
// Visibility toggle
bool visible = selected->GetVisable();
if (ImGui::Checkbox("Visible", &visible))
selected->SetVisable(visible);
// --- Transform ---
ImGui::TextUnformatted("Transform");
ImGui::Separator();
glm::vec2 pos = selected->GetLocalPosition();
if (ImGui::DragFloat2("Position", &pos.x, 0.1f))
selected->SetLocalPosition(pos);
float rotation = selected->GetLocalRotation();
if (ImGui::DragFloat("Rotation", &rotation, 1.0f))
selected->SetLocalRotation(rotation);
int layer = selected->layer;
if (ImGui::InputInt("Layer", &layer))
selected->layer = layer;
ImGui::Text("ID: %d", selected->uid.id);
ImGui::Text("UID: %s", selected->uid.uuid.c_str());
ImGui::Spacing();
ImGui::SeparatorText("Add Component");
static const char *componentTypes[] = {
"SpriteComponent",
"CameraComponent",
"LightComponent",
"ScriptComponent",
"TilemapComponent"};
static int selectedIndex = -1;
if (ImGui::BeginCombo("##ComponentCombo", selectedIndex >= 0 ? componentTypes[selectedIndex] : "Select Component"))
{
for (int i = 0; i < IM_ARRAYSIZE(componentTypes); ++i)
{
bool isSelected = (selectedIndex == i);
if (ImGui::Selectable(componentTypes[i], isSelected))
selectedIndex = i;
if (isSelected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
ImGui::SameLine();
if (ImGui::Button("Add") && selectedIndex != -1 && selected)
{
const std::string type = componentTypes[selectedIndex];
if (type == "SpriteComponent" && !selected->GetComponent<SpriteComponent>())
selected->AddComponent<SpriteComponent>();
else if (type == "CameraComponent" && !selected->GetComponent<CameraComponent>())
selected->AddComponent<CameraComponent>();
else if (type == "LightComponent" && !selected->GetComponent<LightComponent>())
selected->AddComponent<LightComponent>();
else if (type == "ScriptComponent" && !selected->GetComponent<ScriptComponent>())
selected->AddComponent<ScriptComponent>();
else if (type == "TilemapComponent" && !selected->GetComponent<TilemapComponent>())
selected->AddComponent<TilemapComponent>();
}
if (auto sprite = selected->GetComponent<SpriteComponent>())
{
ImGui::SeparatorText("Sprite Component");
// — Render Type (unchanged) —
const char *renderTypes[] = {"Unlit", "Lit"};
int currentTypeIndex = static_cast<int>(sprite->GetRenderType());
if (ImGui::Combo("Render Type", &currentTypeIndex, renderTypes, IM_ARRAYSIZE(renderTypes)))
sprite->SetRenderType(static_cast<SpriteComponent::RenderType>(currentTypeIndex));
ImGui::SeparatorText("Texture");
// — Texture File with Drag & Drop + Load Button —
{
std::string texFile = GetFilenameFromPath(sprite->GetTexturePath());
// filename text
ImGui::Text(texFile.c_str());
// accept draganddrop here
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("ASSET_TEXTURE"))
{
const char *dropped = (const char *)payload->Data;
sprite->SetTexture(dropped);
}
ImGui::EndDragDropTarget();
}
if (ImGui::SmallButton("Load##SpriteTex"))
{
auto path = OpenFileDialog(FileDialogType::Images);
if (!path.empty())
sprite->SetTexture(path);
}
}
ImGui::SeparatorText("Normal Map");
{
std::string normFile = GetFilenameFromPath(sprite->GetNormalMapPath());
ImGui::Text(normFile.c_str());
if (ImGui::BeginDragDropTarget())
{
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("ASSET_TEXTURE"))
{
const char *dropped = (const char *)payload->Data;
sprite->SetNormalMap(dropped);
}
ImGui::EndDragDropTarget();
}
if (ImGui::SmallButton("Load##SpriteNorm"))
{
auto path = OpenFileDialog(FileDialogType::Images);
if (!path.empty())
sprite->SetNormalMap(path);
}
}
ImGui::SeparatorText("Info");
// — Size Display & Remove —
glm::vec2 size = sprite->GetSize();
ImGui::Text("Size: %.0f × %.0f", size.x, size.y);
ImGui::Separator();
if (ImGui::Button("Remove SpriteComponent"))
selected->RemoveComponent<SpriteComponent>();
}
if (auto cam = selected->GetComponent<CameraComponent>())
{
ImGui::SeparatorText("Camera Component");
float fov = cam->GetFOV();
float aspect = cam->GetAspect();
float zoom = cam->GetZoom();
if (ImGui::DragFloat("FOV", &fov, 0.1f, 1.0f, 179.0f))
cam->SetFOV(fov);
if (ImGui::DragFloat("Aspect", &aspect, 0.01f, 0.1f, 5.0f))
cam->SetAspect(aspect);
if (ImGui::DragFloat("Zoom", &zoom, 0.1f, 0.1f, 10.0f))
cam->SetZoom(zoom);
bool isPrimary = cam->IsPrimary();
if (ImGui::Checkbox("Primary", &isPrimary))
cam->SetPrimary(isPrimary);
if (ImGui::Button("Remove CameraComponent"))
selected->RemoveComponent<CameraComponent>();
}
if (auto light = selected->GetComponent<LightComponent>())
{
ImGui::SeparatorText("Light Component");
glm::vec3 color = light->GetColor();
float intensity = light->GetIntensity();
float radius = light->GetRadius();
float falloff = light->GetFalloff();
int type = light->GetType();
if (ImGui::ColorEdit3("Color", &color.x))
light->SetColor(color);
if (ImGui::DragFloat("Intensity", &intensity, 0.05f, 0.0f, 10.0f))
light->SetIntensity(intensity);
if (ImGui::DragFloat("Radius", &radius, 1.0f, 10.0f, 1000.0f))
light->SetRadius(radius);
if (ImGui::DragFloat("Falloff", &falloff, 0.05f, 0.1f, 5.0f))
light->SetFalloff(falloff);
// const char* types[] = { "Point", "Directional" };
// if (ImGui::Combo("Type", &type, types, IM_ARRAYSIZE(types)))
// light->SetType(type);
if (ImGui::Button("Remove LightComponent"))
selected->RemoveComponent<LightComponent>();
}
if (auto script = selected->GetComponent<ScriptComponent>())
{
ImGui::SeparatorText("Script Component");
std::string path = script->GetScriptPath();
ImGui::Text("Script Path:");
ImGui::TextWrapped("%s", path.c_str());
if (ImGui::Button("Load Script"))
{
std::string chosen = OpenFileDialog(FileDialogType::Scripts); // Add 'Scripts' filter if needed
if (!chosen.empty())
script->SetScriptPath(chosen);
}
ImGui::SameLine();
if (ImGui::Button("Reload"))
{
script->ReloadScript();
}
if (ImGui::Button("Remove ScriptComponent"))
selected->RemoveComponent<ScriptComponent>();
}
if (auto phys = selected->GetComponent<PhysicsComponent>())
{
ImGui::SeparatorText("Physics Component");
glm::vec2 vel = phys->GetVelocity();
if (ImGui::DragFloat2("Velocity", &vel.x))
phys->SetVelocity(vel);
float friction = phys->GetFriction();
if (ImGui::DragFloat("Friction", &friction, 0.01f, 0.0f, 1.0f))
phys->SetFriction(friction);
bool fixed = phys->IsFixedRotation();
if (ImGui::Checkbox("Fixed Rotation", &fixed))
phys->SetFixedRotation(fixed);
if (ImGui::Button("Remove PhysicsComponent"))
selected->RemoveComponent<PhysicsComponent>();
}
if (auto tilemap = selected->GetComponent<TilemapComponent>())
{
ImGui::SeparatorText("Tilemap Component");
ImGui::Text("Refer to Tilemap Editor Window");
if (ImGui::Button("Remove TilemapComponent"))
selected->RemoveComponent<TilemapComponent>();
}
ImGui::End();
if (auto tilemap = selected->GetComponent<TilemapComponent>())
{
tilemap->DrawEditorUI();
}
}

View File

@ -0,0 +1,8 @@
#pragma once
#include "../../core/utils/utils.h"
class Object;
void DrawInspectorUI(std::shared_ptr<Object> selected);

View File

@ -1,5 +1,5 @@
#include "GameObjectsList.h"
#include "../utils/Logging.h"
#include "../core/utils/Logging.h"
std::vector<std::shared_ptr<Object>> objects;
std::string savedStateYAML;

View File

@ -1,6 +1,6 @@
#include "Shader.h"
#include "Logging.h"
#include "utils.h"
#include "../core/utils/Logging.h"
#include "../core/utils/utils.h"
#include <fstream>
#include <sstream>