idk anymore

This commit is contained in:
OusmBlueNinja 2024-12-30 00:28:15 -06:00
parent 17f847b561
commit af98c41a6f
13 changed files with 75312 additions and 180 deletions

Binary file not shown.

View File

@ -0,0 +1,368 @@
# Blender MTL File: 'InteriorTest.blend'
# Material Count: 34
newmtl Aluminium
Ns 728.999998
Ka 1.000000 1.000000 1.000000
Kd 0.233016 0.233016 0.233016
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 3
newmtl Book
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\5b106c26cc7e5c429ba4e5de573d0dce.jpg
newmtl Book2
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\finalimage.jpg
newmtl Carpet
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\drive-download-20210610T021657Z-001\\Fabric_Rug_006_COLOR.jpg
map_Ns Texture\\drive-download-20210610T021657Z-001\\Fabric_Rug_006_ROUGH.jpg
newmtl Cermin
Ns 900.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 3
newmtl Cusion
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Emmision
Ns 323.999994
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl Floor
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\ParquetFlooring05_MR_2K\\ParquetFlooring05_2K_BaseColor.png
newmtl Gelas
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\Marble09_MR_2K\\Marble09_2K_BaseColor.png
map_Ns Texture\\Marble09_MR_2K\\Marble09_2K_Roughness.png
newmtl InsideBook
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.295692 0.295692 0.295692
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Jam
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\png-clipart-black-analog-clock-at-11-55-clock-face-clocks-angle-text.png
newmtl Kaca
Ns 323.999994
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
newmtl KerangkaLemari
Ns 225.000000
Ka 0.800000 0.800000 0.800000
Kd 0.000000 0.000000 0.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 3
newmtl Lemari
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\Wood09_MR_2K\\Wood09_2K_BaseColor.png
map_Ns Texture\\Wood09_MR_2K\\Wood09_2K_Roughness.png
newmtl Meja
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\Wood09_MR_2K\\Wood09_2K_BaseColor.png
map_Ns Texture\\Wood09_MR_2K\\Wood09_2K_Roughness.png
newmtl Netflix
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\Netflix_TV_interface_test_wm_1594887506248.jpg
newmtl None
Ns 500
Ka 0.8 0.8 0.8
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2
newmtl Picture
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\Best-Abstract-Art-course-tutorial-class-certification-training-online-scaled.jpg
newmtl Picture2
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\639170_18090338_3255399_0cc8cc8e_image.jpg
newmtl Picture3
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\Ocean_Dreams_-_Contemporary_Abstract_Painting_7aa795bd-f372-40cf-b6c0-99a7b985aae4.jpg
newmtl Picture4
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\On-Impulse-36x36-1-1200x1200.jpeg
newmtl PictureBorder
Ns 225.000000
Ka 0.700000 0.700000 0.700000
Kd 0.015995 0.015995 0.015995
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 3
newmtl Roof
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl SideTegel
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.711822 0.736521 0.787399
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Side_Wall
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\Concrete_Wall\\Concrete_Wall_009_basecolor.jpg
map_Ns Texture\\Concrete_Wall\\Concrete_Wall_009_roughness.jpg
newmtl Sofa
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Sofa_Kecil
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.486897 0.486897 0.486897
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl TV
Ns 143.999983
Ka 0.900000 0.900000 0.900000
Kd 0.018849 0.018849 0.018849
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 3
newmtl TiangMeja
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
newmtl Tree
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Bump Texture\\Mapple\\Maple_Bark\\Maple_Bark_2_NRM.png
map_Ks Texture\\Mapple\\Maple_Bark\\Maple_Bark_2_SPEC.png
newmtl Tree07_4K
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\Tree07_4K.png
map_d Texture\\Tree07_4K.png
newmtl Tree_Branch
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\Mapple\\Tree Branch.png
map_d Texture\\Mapple\\Tree Branch.png
newmtl Wall
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Ns Texture\\WhiteStuccoWall01_MR_2K\\WhiteStuccoWall01_2K_Roughness.png
newmtl Wall_Down
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 1.000000 1.000000 1.000000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd Texture\\White Brick\\WhiteBrickWall01_2K_BaseColor.png
map_Ns Texture\\White Brick\\WhiteBrickWall01_2K_Roughness.png

74367
assets/models/InteriorTest.obj Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -5,13 +5,13 @@ local Engine = require("./assets/scripts/engine")
-- Variables to track elapsed time and rotation -- Variables to track elapsed time and rotation
local elapsedTime = 0 local elapsedTime = 0
local rotationSpeed = 90 -- Degrees per second for spinning local rotationSpeed = 45 -- Degrees per second for spinning
local new_rotation = 0 local new_rotation = 0
-- Variables for bobbing effect -- Variables for bobbing effect
local initial_position = {x = 0, y = 0, z = 0} -- To store the gun's initial position local initial_position = {x = 0, y = 0, z = 0} -- To store the gun's initial position
local bobAmplitude = 0.1 -- Amplitude of the bobbing (units) local bobAmplitude = 0.5 -- Amplitude of the bobbing (units)
local bobFrequency = 0.5 -- Frequency of the bobbing (oscillations per second) local bobFrequency = 0.1 -- Frequency of the bobbing (oscillations per second)
-- Reference to the Gun GameObject and its Transform component -- Reference to the Gun GameObject and its Transform component
local gun = nil local gun = nil
@ -19,11 +19,12 @@ local transform = nil
local TAU = Math.constants.TAU local TAU = Math.constants.TAU
function OnInit()
local startTime = os.clock()
Engine.Log("Init START", {1.0,1.0,1.0,1.0})
-- Update function called every frame
function OnUpdate(deltaTime)
-- Ensure that the Gun and its Transform component are valid
if not gun then if not gun then
gun = Engine.GetGameObjectByTag("Gun") gun = Engine.GetGameObjectByTag("Gun")
if gun then if gun then
@ -51,6 +52,46 @@ function OnUpdate(deltaTime)
return return
end end
end end
Engine.Log("Init OK", {0.0,1.0,0.0,1.0})
local endTime = os.clock()
Engine.Log(string.format("Time to load: %f", endTime-startTime))
end
-- Update function called every frame
function OnUpdate(deltaTime)
-- Ensure that the Gun and its Transform component are valid
if not gun then
gun = Engine.GetGameObjectByTag("Gun")
if gun then
transform = gun:GetComponent("Transform")
if transform then
local pos = transform:GetPosition()
initial_position = {x = pos.x, y = pos.y, z = pos.z}
Engine.Log("Gun found and initial position updated.", {1, 1, 1, 1})
else
Engine.Log("Transform component not found on Gun.", {1, 1, 0, 1})
return
end
else
return
end
elseif not transform then
transform = gun:GetComponent("Transform")
if transform then
local pos = transform:GetPosition()
initial_position = {x = pos.x, y = pos.y, z = pos.z}
Engine.Log("Transform component found and initial position updated.", {1, 1, 1, 1})
else
return
end
end
-- Increment elapsed time -- Increment elapsed time
elapsedTime = elapsedTime + deltaTime elapsedTime = elapsedTime + deltaTime

View File

@ -0,0 +1,240 @@
-- unitTests.lua
-- Unit Tests for C++ Lua API and Game Engine
local Math = require("./assets/scripts/math")
local Engine = require("./assets/scripts/engine")
local function OnInit()
-- Log a message with a custom red color
Engine.Log("This is a red message.", {1.0, 0.0, 0.0, 1.0})
-- Log a message with a custom green color
Engine.Log("This is a green message.", {0.0, 1.0, 0.0, 1.0})
-- Log a message with a custom blue color
Engine.Log("This is a blue message.", {0.0, 0.0, 1.0, 1.0})
end
-- Simple Test Framework
local Tests = {}
local passed = 0
local failed = 0
-- Assertion Functions
local function assertEquals(expected, actual, message)
if expected ~= actual then
error(message or string.format("Assertion Failed: expected '%s', got '%s'", tostring(expected), tostring(actual)))
end
end
local function assertTableEquals(expected, actual, message)
if type(expected) ~= "table" or type(actual) ~= "table" then
error(message or "Assertion Failed: One of the values is not a table.")
end
for k, v in pairs(expected) do
if actual[k] ~= v then
error(message or string.format("Assertion Failed: For key '%s', expected '%s', got '%s'", tostring(k), tostring(v), tostring(actual[k])))
end
end
end
local function assertNotNil(value, message)
if value == nil then
error(message or "Assertion Failed: value is nil.")
end
end
local function assertTrue(condition, message)
if not condition then
error(message or "Assertion Failed: condition is not true.")
end
end
-- Helper Function to Capture Logs
local capturedLogs = {}
local originalLog = Engine.Log
local function mockLog(message, color)
table.insert(capturedLogs, {message = message, color = color})
end
-- Register Test Cases
function Tests.testEngineLog()
-- Replace Engine.Log with mockLog
Engine.Log = mockLog
-- Call OnInit to generate logs
OnInit()
-- Restore original Engine.Log
Engine.Log = originalLog
-- Assertions
assertEquals(3, #capturedLogs, "OnInit should log exactly 3 messages.")
-- Check first log (Red Message)
assertEquals("This is a red message.", capturedLogs[1].message)
assertTableEquals({1.0, 0.0, 0.0, 1.0}, capturedLogs[1].color, "First log color mismatch.")
-- Check second log (Green Message)
assertEquals("This is a green message.", capturedLogs[2].message)
assertTableEquals({0.0, 1.0, 0.0, 1.0}, capturedLogs[2].color, "Second log color mismatch.")
-- Check third log (Blue Message)
assertEquals("This is a blue message.", capturedLogs[3].message)
assertTableEquals({0.0, 0.0, 1.0, 1.0}, capturedLogs[3].color, "Third log color mismatch.")
end
function Tests.testGetGameObjectByTag()
-- Assume "Player" and "Gun" GameObjects exist
local player = Engine.GetGameObjectByTag("Player")
assertNotNil(player, "Player GameObject should exist.")
local gun = Engine.GetGameObjectByTag("Gun")
assertNotNil(gun, "Gun GameObject should exist.")
-- Test for a non-existent tag
local nonExistent = Engine.GetGameObjectByTag("NonExistentTag")
assertEquals(nil, nonExistent, "Non-existent GameObject should return nil.")
end
function Tests.testGameObjectGetName()
local player = Engine.GetGameObjectByTag("Player")
assertNotNil(player, "Player GameObject should exist.")
local name = player:GetName()
assertEquals("Player", name, "Player GameObject name should be 'Player'.")
end
function Tests.testGameObjectGetComponent()
local player = Engine.GetGameObjectByTag("Player")
assertNotNil(player, "Player GameObject should exist.")
local transform = player:GetComponent("Transform")
assertNotNil(transform, "Player should have a Transform component.")
local nonExistentComponent = player:GetComponent("NonExistentComponent")
assertEquals(nil, nonExistentComponent, "Non-existent component should return nil.")
end
function Tests.testTransformComponentPosition()
local player = Engine.GetGameObjectByTag("Player")
assertNotNil(player, "Player GameObject should exist.")
local transform = player:GetComponent("Transform")
assertNotNil(transform, "Player should have a Transform component.")
-- Get initial position
local position = transform:GetPosition()
assertNotNil(position, "Transform:GetPosition should return a position table.")
assertEquals(0.0, position.x, "Initial X position should be 0.0.")
assertEquals(2.0, position.y, "Initial Y position should be 2.0.")
assertEquals(-12.0, position.z, "Initial Z position should be -12.0.")
-- Set new position
local newPosition = {x = 5.0, y = 10.0, z = -15.0}
transform:SetPosition(newPosition)
-- Get updated position
local updatedPosition = transform:GetPosition()
assertTableEquals(newPosition, updatedPosition, "Transform:SetPosition did not update position correctly.")
end
function Tests.testTransformComponentRotation()
local player = Engine.GetGameObjectByTag("Player")
assertNotNil(player, "Player GameObject should exist.")
local transform = player:GetComponent("Transform")
assertNotNil(transform, "Player should have a Transform component.")
-- Get initial rotation
local rotation = transform:GetRotation()
assertNotNil(rotation, "Transform:GetRotation should return a rotation table.")
-- Set new rotation
local newRotation = {x = 45.0, y = 90.0, z = 135.0}
transform:SetRotation(newRotation)
-- Get updated rotation
local updatedRotation = transform:GetRotation()
assertTableEquals(newRotation, updatedRotation, "Transform:SetRotation did not update rotation correctly.")
end
function Tests.testOnUpdateFunctionality()
-- Mock GameObject and Transform
local mockPlayer = {
GetName = function() return "Player" end,
GetComponent = function(componentName)
if componentName == "Transform" then
return {
GetRotation = function()
return {x = new_rotation, y = new_rotation, z = new_rotation}
end,
SetRotation = function(rotation)
new_rotation = rotation.x
end
}
end
return nil
end
}
-- Replace Engine.GetGameObjectByTag to return mockPlayer
local originalGetGameObjectByTag = Engine.GetGameObjectByTag
Engine.GetGameObjectByTag = function(tag)
if tag == "Player" then
return mockPlayer
end
return originalGetGameObjectByTag(tag)
end
-- Initialize rotation
new_rotation = 0
speed = 50
-- Call OnUpdate with deltaTime = 1
OnUpdate(1)
-- Check new_rotation
assertEquals(50, new_rotation, "After first OnUpdate, new_rotation should be 50.")
-- Call OnUpdate with deltaTime = 14 (to exceed 720)
OnUpdate(14)
-- new_rotation should reset to 0 after exceeding 720
assertEquals(720 + 50 - 720, new_rotation, "After exceeding 720, new_rotation should reset appropriately.")
-- Restore original Engine.GetGameObjectByTag
Engine.GetGameObjectByTag = originalGetGameObjectByTag
end
-- Add more test functions below as needed
-- Test Runner
local function runTests()
print("Starting Unit Tests...\n")
for testName, testFunc in pairs(Tests) do
io.write(string.format("Running %s... ", testName))
local status, err = pcall(testFunc)
if status then
print("PASSED")
passed = passed + 1
else
print("FAILED")
print(" Error:", err)
failed = failed + 1
end
end
print(string.format("\nUnit Tests Completed: %d Passed, %d Failed", passed, failed))
end
-- Execute Tests
runTests()

View File

@ -115,8 +115,8 @@ Collapsed=0
DockId=0x00000011,0 DockId=0x00000011,0
[Window][Profiler] [Window][Profiler]
Pos=889,689 Pos=888,780
Size=676,480 Size=646,389
Collapsed=0 Collapsed=0
DockId=0x0000001C,1 DockId=0x0000001C,1
@ -149,7 +149,7 @@ DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,27 Size=1904
DockNode ID=0x00000017 Parent=0x0000000D SizeRef=1303,751 CentralNode=1 HiddenTabBar=1 Selected=0xDFF75B3F DockNode ID=0x00000017 Parent=0x0000000D SizeRef=1303,751 CentralNode=1 HiddenTabBar=1 Selected=0xDFF75B3F
DockNode ID=0x00000018 Parent=0x0000000D SizeRef=1303,389 Split=X Selected=0x9B5D3198 DockNode ID=0x00000018 Parent=0x0000000D SizeRef=1303,389 Split=X Selected=0x9B5D3198
DockNode ID=0x0000001B Parent=0x00000018 SizeRef=612,680 HiddenTabBar=1 Selected=0x1C0788A1 DockNode ID=0x0000001B Parent=0x00000018 SizeRef=612,680 HiddenTabBar=1 Selected=0x1C0788A1
DockNode ID=0x0000001C Parent=0x00000018 SizeRef=645,680 Selected=0x7D9E6BA2 DockNode ID=0x0000001C Parent=0x00000018 SizeRef=645,680 Selected=0x9B5D3198
DockNode ID=0x0000000E Parent=0x00000003 SizeRef=1202,569 Selected=0xE98146C5 DockNode ID=0x0000000E Parent=0x00000003 SizeRef=1202,569 Selected=0xE98146C5
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1202,291 Selected=0x9DD4E196 DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1202,291 Selected=0x9DD4E196
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=334,1142 HiddenTabBar=1 Selected=0x36DC96AB DockNode ID=0x00000002 Parent=0x00000008 SizeRef=334,1142 HiddenTabBar=1 Selected=0x36DC96AB

View File

@ -1,147 +1,87 @@
Entities: Entities:
- ID: 0 - ID: 0
Name: Player
Components:
Transform:
Position: [0, 2.79999995, -12.6000004]
Rotation: [498.009338, 498.009338, 498.009338]
Scale: [1, 1, 1]
Mesh:
vao: 2
indexCount: 15810
textureID: 1
MeshPath: assets/models/LowPolyFiatUNO.obj
- ID: 2
Name: Gun Name: Gun
Components: Components:
Transform: Transform:
Position: [-2.5, 0.755197883, -0.300000012] Position: [-0.200000003, 14.618, 0.699999988]
Rotation: [-180, 105.403984, 0] Rotation: [0, -88, 0]
Scale: [0.00499999989, 0.00499999989, 0.00499999989] Scale: [0.0500000007, 0.0500000007, 0.0500000007]
Mesh: Mesh:
vao: 5 vao: 7
indexCount: 116445 indexCount: 786801
textureID: 5 textures:
MeshPath: assets/models/Ak-47.obj - id: 11
type: texture_diffuse
path: textures/lion.tga
- id: 12
type: texture_diffuse
path: textures/background.tga
- id: 13
type: texture_diffuse
path: textures/vase_plant.tga
- id: 14
type: texture_diffuse
path: textures/sponza_arch_diff.tga
- id: 15
type: texture_diffuse
path: textures/spnza_bricks_a_diff.tga
- id: 16
type: texture_diffuse
path: textures/sponza_ceiling_a_diff.tga
- id: 17
type: texture_diffuse
path: textures/chain_texture.tga
- id: 18
type: texture_diffuse
path: textures/sponza_column_a_diff.tga
- id: 19
type: texture_diffuse
path: textures/sponza_column_b_diff.tga
- id: 20
type: texture_diffuse
path: textures/sponza_column_c_diff.tga
- id: 21
type: texture_diffuse
path: textures/sponza_details_diff.tga
- id: 22
type: texture_diffuse
path: textures/sponza_fabric_diff.tga
- id: 23
type: texture_diffuse
path: textures/sponza_curtain_diff.tga
- id: 24
type: texture_diffuse
path: textures/sponza_fabric_blue_diff.tga
- id: 25
type: texture_diffuse
path: textures/sponza_fabric_green_diff.tga
- id: 26
type: texture_diffuse
path: textures/sponza_curtain_green_diff.tga
- id: 27
type: texture_diffuse
path: textures/sponza_curtain_blue_diff.tga
- id: 28
type: texture_diffuse
path: textures/sponza_flagpole_diff.tga
- id: 29
type: texture_diffuse
path: textures/sponza_floor_a_diff.tga
- id: 30
type: texture_diffuse
path: textures/sponza_thorn_diff.tga
- id: 31
type: texture_diffuse
path: textures/sponza_roof_diff.tga
- id: 32
type: texture_diffuse
path: textures/vase_dif.tga
- id: 33
type: texture_diffuse
path: textures/vase_hanging.tga
- id: 34
type: texture_diffuse
path: textures/vase_round.tga
MeshPath: assets/models/sponza.obj
ScriptComponent: ScriptComponent:
ScriptPath: assets/scripts/BouncingItem.lua ScriptPath: assets/scripts/BouncingItem.lua
- ID: 3
Name: Grass Box Top
Components:
Transform:
Position: [-1.20000005, -3.4000001, -17.7000008]
Rotation: [-23.5, 15.8999996, -59.9000015]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 4
MeshPath: assets/models/DefaultMesh.obj
- ID: 4
Name: Bark Box
Components:
Transform:
Position: [8.10000038, 0.800000012, -12]
Rotation: [-17.2999992, -16.1000004, -19.2999992]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 5
MeshPath: assets/models/DefaultMesh.obj
- ID: 5
Name: Skybox
Components:
Mesh:
vao: 1
indexCount: 36
textureID: 7
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [0, 0, 43.2000008]
Rotation: [0, 0, 0]
Scale: [100, 100, 100]
- ID: 6
Name: Null Texture Box
Components:
Transform:
Position: [-6.5, -6, -18]
Rotation: [15.8000002, -18.2000008, -11.1000004]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 3
MeshPath: assets/models/DefaultMesh.obj
- ID: 7
Name: Grass Box Bottom
Components:
Transform:
Position: [6.5999999, 1.79999995, -23.8999996]
Rotation: [-16.1000004, -15.8999996, -35]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 4
MeshPath: assets/models/DefaultMesh.obj
- ID: 8
Name: Wood Box
Components:
Transform:
Position: [-7.80000019, 0.200000003, -29.7999992]
Rotation: [22.2999992, -32.7999992, 0]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 1
MeshPath: assets/models/DefaultMesh.obj
- ID: 9
Name: Bricks
Components:
Transform:
Position: [5.5, -2.9000001, -19.5]
Rotation: [-41.4000015, -22.6000004, -52.2999992]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 2
MeshPath: assets/models/DefaultMesh.obj
- ID: 10
Name: Script
Components:
ScriptComponent:
ScriptPath: assets/scripts/script.lua
- ID: 10
Name: Gun Podium
Components:
Mesh:
vao: 1
indexCount: 36
textureID: 4
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [-2.5, 2, -0.300000012]
Rotation: [0, 0, 0]
Scale: [0.25, 1, 0.25]
- ID: 11
Name: Camera
Components:
CameraComponent:
IsPerspective: true
DefaultRuntimeCamera: true
FOV: 45
AspectRatio: 1.77777779
NearPlane: 0.100000001
FarPlane: 1000
Mesh:
vao: 0
indexCount: 36
textureID: 0
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [0, -0.100000001, 0.400000006]
Rotation: [15.3999996, -164.399994, 0]
Scale: [1, 1, 1]

147
scenes/Saved.scene Normal file
View File

@ -0,0 +1,147 @@
Entities:
- ID: 0
Name: Player
Components:
Transform:
Position: [0, 2.79999995, -12.6000004]
Rotation: [498.009338, 498.009338, 498.009338]
Scale: [1, 1, 1]
Mesh:
vao: 2
indexCount: 15810
textureID: 1
MeshPath: assets/models/LowPolyFiatUNO.obj
- ID: 2
Name: Gun
Components:
Transform:
Position: [-2.5, 0.755197883, -0.300000012]
Rotation: [-180, 105.403984, 0]
Scale: [0.00499999989, 0.00499999989, 0.00499999989]
Mesh:
vao: 5
indexCount: 116445
textureID: 5
MeshPath: assets/models/Ak-47.obj
ScriptComponent:
ScriptPath: assets/scripts/BouncingItem.lua
- ID: 3
Name: Grass Box Top
Components:
Transform:
Position: [-1.20000005, -3.4000001, -17.7000008]
Rotation: [-23.5, 15.8999996, -59.9000015]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 4
MeshPath: assets/models/DefaultMesh.obj
- ID: 4
Name: Bark Box
Components:
Transform:
Position: [8.10000038, 0.800000012, -12]
Rotation: [-17.2999992, -16.1000004, -19.2999992]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 5
MeshPath: assets/models/DefaultMesh.obj
- ID: 5
Name: Skybox
Components:
Mesh:
vao: 1
indexCount: 36
textureID: 7
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [0, 0, 43.2000008]
Rotation: [0, 0, 0]
Scale: [100, 100, 100]
- ID: 6
Name: Null Texture Box
Components:
Transform:
Position: [-6.5, -6, -18]
Rotation: [15.8000002, -18.2000008, -11.1000004]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 3
MeshPath: assets/models/DefaultMesh.obj
- ID: 7
Name: Grass Box Bottom
Components:
Transform:
Position: [6.5999999, 1.79999995, -23.8999996]
Rotation: [-16.1000004, -15.8999996, -35]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 4
MeshPath: assets/models/DefaultMesh.obj
- ID: 8
Name: Wood Box
Components:
Transform:
Position: [-7.80000019, 0.200000003, -29.7999992]
Rotation: [22.2999992, -32.7999992, 0]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 1
MeshPath: assets/models/DefaultMesh.obj
- ID: 9
Name: Bricks
Components:
Transform:
Position: [5.5, -2.9000001, -19.5]
Rotation: [-41.4000015, -22.6000004, -52.2999992]
Scale: [1, 1, 1]
Mesh:
vao: 1
indexCount: 36
textureID: 2
MeshPath: assets/models/DefaultMesh.obj
- ID: 10
Name: Script
Components:
ScriptComponent:
ScriptPath: assets/scripts/script.lua
- ID: 10
Name: Gun Podium
Components:
Mesh:
vao: 1
indexCount: 36
textureID: 4
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [-2.5, 2, -0.300000012]
Rotation: [0, 0, 0]
Scale: [0.25, 1, 0.25]
- ID: 11
Name: Camera
Components:
CameraComponent:
IsPerspective: true
DefaultRuntimeCamera: true
FOV: 45
AspectRatio: 1.77777779
NearPlane: 0.100000001
FarPlane: 1000
Mesh:
vao: 0
indexCount: 36
textureID: 0
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [0, -0.100000001, 0.400000006]
Rotation: [15.3999996, -164.399994, 0]
Scale: [1, 1, 1]

View File

@ -14,6 +14,9 @@
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <filesystem> // C++17 or later
// TODO: Add camera component Meta Table
// External LoggerWindow instance for logging // External LoggerWindow instance for logging
extern LoggerWindow *g_LoggerWindow; extern LoggerWindow *g_LoggerWindow;
@ -21,6 +24,8 @@ extern LoggerWindow *g_LoggerWindow;
// External GameObjects list // External GameObjects list
extern std::vector<std::unique_ptr<GameObject>> g_GameObjects; extern std::vector<std::unique_ptr<GameObject>> g_GameObjects;
std::string LuaManager::m_ScriptName = "LUA_UNDEFINED";
// Constructor // Constructor
LuaManager::LuaManager() LuaManager::LuaManager()
: ScriptPath(""), m_LuaState(nullptr), m_LastErrorMessage("") : ScriptPath(""), m_LuaState(nullptr), m_LastErrorMessage("")
@ -55,6 +60,8 @@ bool LuaManager::Initialize(const std::string &scriptPath)
ScriptPath = scriptPath; ScriptPath = scriptPath;
m_ScriptName = std::filesystem::path(scriptPath).filename().string();
// Create a new Lua state // Create a new Lua state
m_LuaState = luaL_newstate(); m_LuaState = luaL_newstate();
if (!m_LuaState) if (!m_LuaState)
@ -85,6 +92,10 @@ bool LuaManager::Initialize(const std::string &scriptPath)
lua_pushcfunction(m_LuaState, Lua_Engine_Log); lua_pushcfunction(m_LuaState, Lua_Engine_Log);
lua_setfield(m_LuaState, -2, "Log"); lua_setfield(m_LuaState, -2, "Log");
// Add the ScriptName binding
lua_pushcfunction(m_LuaState, Lua_Engine_ScriptName);
lua_setfield(m_LuaState, -2, "ScriptName");
// Bind the GetGameObjectByTag function to the Engine table // Bind the GetGameObjectByTag function to the Engine table
lua_pushcfunction(m_LuaState, Lua_Engine_GetGameObjectByTag); lua_pushcfunction(m_LuaState, Lua_Engine_GetGameObjectByTag);
lua_setfield(m_LuaState, -2, "GetGameObjectByTag"); lua_setfield(m_LuaState, -2, "GetGameObjectByTag");
@ -290,48 +301,70 @@ void LuaManager::CallLuaFunction(std::string functionName)
} }
} }
int LuaManager::Lua_Engine_ScriptName(lua_State *L)
{
// Push the script name onto the Lua stack
lua_pushstring(L, m_ScriptName.c_str());
// Return 1 value (the string)
return 1;
}
// Binding function to log messages from Lua // Binding function to log messages from Lua
int LuaManager::Lua_Engine_Log(lua_State *L) int LuaManager::Lua_Engine_Log(lua_State *L)
{ {
int argc = lua_gettop(L); int argc = lua_gettop(L);
if (argc < 1 || !lua_isstring(L, 1)) if (argc < 1 || !lua_isstring(L, 1))
{ {
lua_pushstring(L, "Engine.Log expects at least one string argument."); luaL_error(L, "Engine.Log expects at least one string argument.");
lua_error(L); return 0; // This line won't be reached due to lua_error
return 0;
} }
std::string message = lua_tostring(L, 1);
ImVec4 color = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // Default white
// Optional color table // Retrieve the log message
const char *message = lua_tostring(L, 1);
// Prepend the script name
std::string formattedMessage = "[" + m_ScriptName + "]: " + message;
// Default color: white
ImVec4 color(1.0f, 1.0f, 1.0f, 1.0f);
// Check if a color table is provided
if (argc >= 2 && lua_istable(L, 2)) if (argc >= 2 && lua_istable(L, 2))
{ {
lua_getfield(L, 2, "r"); // Efficiently retrieve color components using numeric indices
// Assumes color table is an array: {r, g, b, a}
// lua_geti is faster than lua_getfield for numeric indices
// r (index 1)
lua_geti(L, 2, 1);
if (lua_isnumber(L, -1)) if (lua_isnumber(L, -1))
color.x = lua_tonumber(L, -1); color.x = static_cast<float>(lua_tonumber(L, -1));
lua_pop(L, 1); // Remove the value from the stack
// g (index 2)
lua_geti(L, 2, 2);
if (lua_isnumber(L, -1))
color.y = static_cast<float>(lua_tonumber(L, -1));
lua_pop(L, 1); lua_pop(L, 1);
lua_getfield(L, 2, "g"); // b (index 3)
lua_geti(L, 2, 3);
if (lua_isnumber(L, -1)) if (lua_isnumber(L, -1))
color.y = lua_tonumber(L, -1); color.z = static_cast<float>(lua_tonumber(L, -1));
lua_pop(L, 1); lua_pop(L, 1);
lua_getfield(L, 2, "b"); // a (index 4)
lua_geti(L, 2, 4);
if (lua_isnumber(L, -1)) if (lua_isnumber(L, -1))
color.z = lua_tonumber(L, -1); color.w = static_cast<float>(lua_tonumber(L, -1));
lua_pop(L, 1);
lua_getfield(L, 2, "a");
if (lua_isnumber(L, -1))
color.w = lua_tonumber(L, -1);
lua_pop(L, 1); lua_pop(L, 1);
} }
// Log the message // Log the message with the specified color
if (g_LoggerWindow)
{ g_LoggerWindow->AddLog(formattedMessage.c_str(), std::optional<ImVec4>(color));
g_LoggerWindow->AddLog(message.c_str(), std::optional<ImVec4>(color));
}
return 0; // No return values return 0; // No return values
} }
@ -627,8 +660,6 @@ int LuaManager::Lua_TransformComponent_SetRotation(lua_State *L)
return 0; // No return values return 0; // No return values
} }
// Binding function to retrieve a ScriptComponent's script path // Binding function to retrieve a ScriptComponent's script path
int LuaManager::Lua_ScriptComponent_GetScriptPath(lua_State *L) int LuaManager::Lua_ScriptComponent_GetScriptPath(lua_State *L)
{ {

View File

@ -63,6 +63,8 @@ private:
// Lua state // Lua state
std::string ScriptPath; std::string ScriptPath;
static std::string m_ScriptName;
lua_State *m_LuaState; lua_State *m_LuaState;
// Last error message to prevent duplicate logging // Last error message to prevent duplicate logging
@ -98,5 +100,7 @@ private:
// Binding functions for Engine table // Binding functions for Engine table
static int Lua_Engine_Log(lua_State *L); static int Lua_Engine_Log(lua_State *L);
static int Lua_Engine_ScriptName(lua_State *L);
static int Lua_Engine_GetGameObjectByTag(lua_State *L); static int Lua_Engine_GetGameObjectByTag(lua_State *L);
}; };

View File

@ -391,14 +391,11 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning)
// Bind the FBO // Bind the FBO
m_FBO.Bind(); m_FBO.Bind();
glViewport(0, 0, m_LastWidth, m_LastHeight); glViewport(0, 0, m_LastWidth, m_LastHeight);
CheckOpenGLError("After glViewport");
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
CheckOpenGLError("After glEnable(GL_DEPTH_TEST)");
glClearColor(0.f, 0.f, 0.f, 1.f); glClearColor(0.f, 0.f, 0.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
CheckOpenGLError("After glClear");
// Use our loaded shader // Use our loaded shader
if (!m_ShaderPtr) if (!m_ShaderPtr)
@ -410,7 +407,6 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning)
m_ShaderPtr->Use(); m_ShaderPtr->Use();
GLuint programID = m_ShaderPtr->GetProgramID(); GLuint programID = m_ShaderPtr->GetProgramID();
CheckOpenGLError("After shader use");
// Define view and projection matrices once // Define view and projection matrices once
std::shared_ptr<CameraComponent> activeCamera = nullptr; std::shared_ptr<CameraComponent> activeCamera = nullptr;
@ -504,8 +500,7 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning)
{ {
if (textureUnit >= MAX_DIFFUSE) if (textureUnit >= MAX_DIFFUSE)
{ {
std::cerr << "[RenderWindow] Warning: Exceeded maximum number of diffuse textures (" DEBUG_PRINT("[RenderWindow] Warning: Exceeded maximum number of diffuse textures (%d) for shader.", MAX_DIFFUSE);
<< MAX_DIFFUSE << ") for shader." << std::endl;
break; // Prevent exceeding the array bounds in the shader break; // Prevent exceeding the array bounds in the shader
} }

View File

@ -30,7 +30,6 @@ std::shared_ptr<GameObject> CreateDefaultCube()
mesh->vao = CreateCubeVAO(); mesh->vao = CreateCubeVAO();
mesh->indexCount = 36; mesh->indexCount = 36;
mesh->textureID = g_AssetManager.loadAsset<GLuint>(AssetType::TEXTURE, "assets/textures/wood.png");
return newGameObject; return newGameObject;
} }