diff --git a/Makefile b/Makefile index 552a058..bafb3e4 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ $(TARGET): $(OBJ_FILES) # Pattern rule to compile .cpp files to .o files # Note the mkdir on the $(dir $@) ensures subfolders under build/ exist. $(BUILD_DIR)/%.o: %.cpp - @mkdir "$(dir $@)" >nul 2>&1 + @mkdir "$(dir $@)" >nul 2>&1 | echo Folder exists @echo Compiling $<... $(CXX) $(CXXFLAGS) -c $< -o $@ diff --git a/examples/BounceingItem.lua b/examples/BounceingItem.lua deleted file mode 100644 index d25db2f..0000000 --- a/examples/BounceingItem.lua +++ /dev/null @@ -1,132 +0,0 @@ --- --- This lua makes a Game object bounce a nd spin like a minecraft item. -local GameObjectName = "Gun" -- This is the tag of the game object you want it to modify --- --- --- - - - - - - - - - - -local Math = require("math") -- Require the enhanced math module -local Engine = require("engine") - - --- Variables to track elapsed time and rotation -local elapsedTime = 0 -local rotationSpeed = 90 -- Degrees per second for spinning -local new_rotation = 0 - --- Variables for bobbing effect -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 bobFrequency = 0.5 -- Frequency of the bobbing (oscillations per second) - --- Reference to the Gun GameObject and its Transform component -local gun = nil -local transform = nil - -local TAU = Math.constants.TAU - - - - - - - - - - - - - - - - - - - - - --- Update function called every frame -function OnUpdate(deltaTime) - -- Ensure that the Gun and its Transform component are valid - -- this was made after OnInit was depricated - if not gun then - gun = Engine.GetGameObjectByTag(GameObjectName) - 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 - Engine.Log("Gun GameObject still not found.", {1, 1, 0, 1}) - 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 - Engine.Log("Transform component still not found on Gun.", {1, 1, 0, 1}) - return - end - end - - -- Increment elapsed time - elapsedTime = elapsedTime + deltaTime - - -- === Spinning the Gun === - -- Update the rotation angle based on rotationSpeed and deltaTime - new_rotation = new_rotation + (deltaTime * rotationSpeed) - - -- Keep the rotation angle within 0-360 degrees to prevent overflow - if new_rotation >= 360 then - new_rotation = new_rotation - 360 - end - - -- Define the new rotation (spinning around the Y-axis) - local rotation = { - x = -180, -- Preserving existing rotation on X-axis - y = new_rotation, -- Updated rotation on Y-axis for spinning - z = 0 -- Preserving existing rotation on Z-axis - } - - -- Apply the new rotation to the Transform component - transform:SetRotation(rotation) - - -- === Bobbing the Gun Up and Down === - -- Calculate the bobbing offset using a sine wave - local bobOffset = bobAmplitude * math.sin(TAU * bobFrequency * elapsedTime) - - -- Define the new position by adding the bobbing offset to the initial Y position - local new_position = { - x = initial_position.x, -- No change on X-axis - y = initial_position.y + bobOffset, -- Bouncing up and down on Y-axis - z = initial_position.z -- No change on Z-axis - } - - -- Apply the new position to the Transform component - transform:SetPosition(new_position) - - -- === Optional: Log Current Rotation and Position === - -- Uncomment the following lines if you wish to log the gun's current rotation and position - -- local current_rotation = transform:GetRotation() - -- Engine.Log(string.format("Gun Rotation: (X: %.2f, Y: %.2f, Z: %.2f)", current_rotation.x, current_rotation.y, current_rotation.z), {1, 1, 1, 1}) - - -- local current_position = transform:GetPosition() - -- Engine.Log(string.format("Gun Position: (X: %.2f, Y: %.2f, Z: %.2f)", current_position.x, current_position.y, current_position.z), {1, 1, 1, 1}) -end diff --git a/src/Engine.cpp b/src/Engine.cpp index 2d095cb..c64516c 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -56,6 +56,7 @@ std::vector> g_GameObjects; std::shared_ptr g_RuntimeCameraObject; int g_GPU_Triangles_drawn_to_screen = 0; +int g_GPU_Draw_Calls = 0; GameObject *g_SelectedObject; // Pointer to the currently selected object @@ -309,7 +310,7 @@ void MyEngine::Run() } // After rendering - m_PerformanceWindow->UpdatePerformanceStats(-1, g_GPU_Triangles_drawn_to_screen); + m_PerformanceWindow->UpdatePerformanceStats(g_GPU_Draw_Calls, g_GPU_Triangles_drawn_to_screen); // End frame EndFrame(); diff --git a/src/Windows/PerformanceWindow.cpp b/src/Windows/PerformanceWindow.cpp index 018e9e2..87e52e4 100644 --- a/src/Windows/PerformanceWindow.cpp +++ b/src/Windows/PerformanceWindow.cpp @@ -6,6 +6,8 @@ extern int LoadedAssets; extern int g_GPU_Triangles_drawn_to_screen; +extern int g_GPU_Draw_Calls; + const char *polygonModeOptions[] = {"Fill", "Wireframe", "Points"}; const int numPolygonModes = sizeof(polygonModeOptions) / sizeof(polygonModeOptions[0]); @@ -47,6 +49,7 @@ void PerformanceWindow::UpdatePerformanceStats(int newCallCount, int newTriangle m_TriangleCount = newTriangleCount; g_GPU_Triangles_drawn_to_screen = 0; + g_GPU_Draw_Calls = 0; } void PerformanceWindow::Show(float fps, float ms) diff --git a/src/Windows/RenderWindow.cpp b/src/Windows/RenderWindow.cpp index eb26ab6..1c30aee 100644 --- a/src/Windows/RenderWindow.cpp +++ b/src/Windows/RenderWindow.cpp @@ -32,6 +32,8 @@ extern AssetManager g_AssetManager; extern std::shared_ptr g_RuntimeCameraObject; extern int g_GPU_Triangles_drawn_to_screen; +extern int g_GPU_Draw_Calls; + bool PlayPauseButton(const char *label, bool *isPlaying, ImVec2 Size) { @@ -276,7 +278,7 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning) model = glm::scale(model, transform->scale); // Compute MVP matrix - glm::mat4 mvp = proj * view * model; + glm::mat4 mvp = proj * view * model; // why is this the wrong way? // Pass MVP and Model matrices to the shader m_ShaderPtr->SetMat4("uMVP", mvp); @@ -336,6 +338,7 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning) // Draw the submesh glBindVertexArray(submesh.vao); glDrawElements(GL_TRIANGLES, static_cast(submesh.indices.size()), GL_UNSIGNED_INT, nullptr); + g_GPU_Draw_Calls += 1; glBindVertexArray(0); // Reset active texture to default @@ -344,7 +347,6 @@ void RenderWindow::RenderSceneToFBO(bool *GameRunning) } } - // Cleanup: Unbind the shader program #if TRANSPERANCY glDisable(GL_BLEND);