From 382802c62aba27bb1f58d04765c4b0b3879879f4 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Sat, 24 Sep 2022 20:14:51 -0400 Subject: [PATCH] Rework -Removed bullet -Removed Soloud Removed every instances of bullet usage. Edited some UI stuff --- Editor/src/ComponentsPanel/ScriptPanel.h | 26 +- Editor/src/Windows/EditorInterface.cpp | 32 +- Nuake/VisibilityComponent.h | 2 + Nuake/dependencies/bullet3 | 1 - Nuake/dependencies/bullet_p5.lua | 116 ---- Nuake/dependencies/soloud_p5.lua | 620 ------------------ Nuake/src/Core/Logger.cpp | 2 +- Nuake/src/Core/Physics/BulletDebugDrawer.cpp | 28 +- Nuake/src/Core/Physics/BulletDebugDrawer.h | 16 +- .../src/Core/Physics/CharacterController.cpp | 149 +---- Nuake/src/Core/Physics/CharacterController.h | 10 - Nuake/src/Core/Physics/DynamicWorld.cpp | 76 +-- Nuake/src/Core/Physics/DynamicWorld.h | 4 - Nuake/src/Core/Physics/GhostObject.cpp | 22 +- Nuake/src/Core/Physics/GhostObject.h | 4 - Nuake/src/Core/Physics/PhysicsManager.cpp | 6 +- Nuake/src/Core/Physics/PhysicsManager.h | 1 - Nuake/src/Core/Physics/PhysicsShapes.cpp | 12 - Nuake/src/Core/Physics/RaycastResult.h | 54 +- Nuake/src/Core/Physics/Rigibody.h | 8 +- Nuake/src/Core/Physics/Rigidbody.cpp | 64 +- Nuake/src/Rendering/SceneRenderer.cpp | 30 +- Nuake/src/Scene/Components/BaseComponent.h | 25 + .../Components/CharacterControllerComponent.h | 6 +- .../Scene/Components/RigidbodyComponent.cpp | 7 - Nuake/src/Scene/Entities/Entity.cpp | 6 + Nuake/src/Scene/Scene.cpp | 10 +- Nuake/src/Window.cpp | 1 - generate.bat | 2 +- premake5.lua | 13 +- 30 files changed, 139 insertions(+), 1214 deletions(-) create mode 100644 Nuake/VisibilityComponent.h delete mode 160000 Nuake/dependencies/bullet3 delete mode 100644 Nuake/dependencies/bullet_p5.lua delete mode 100644 Nuake/dependencies/soloud_p5.lua diff --git a/Editor/src/ComponentsPanel/ScriptPanel.h b/Editor/src/ComponentsPanel/ScriptPanel.h index 782028c3..a68f9324 100644 --- a/Editor/src/ComponentsPanel/ScriptPanel.h +++ b/Editor/src/ComponentsPanel/ScriptPanel.h @@ -33,6 +33,8 @@ public: Ref nuakeFile = Nuake::FileSystem::GetFile(path); component.mWrenScript = CreateRef(nuakeFile, true); auto modules = component.mWrenScript->GetModules(); + if (modules.size() > 0) + component.mModule = 0; } ImGui::EndDragDropTarget(); } @@ -50,12 +52,26 @@ public: ImGui::Text("Module"); ImGui::TableNextColumn(); - // Todo: Automatically parse available modules. and offer a dropdown - //ImGuiHelper::DrawVec3("Rotation", &component.Rotation); + // Here we create a dropdown for every modules + + auto wrenScript = component.mWrenScript; + + if (wrenScript) + { + auto modules = wrenScript->GetModules(); + + std::vector modulesC; + + for (auto& m : modules) + { + modulesC.push_back(m.c_str()); + } + static int currentModule = (int)component.mModule; + ImGui::Combo("##WrenModule", ¤tModule, &modulesC[0], modules.size()); + component.mModule = currentModule; + } + ImGui::TableNextColumn(); - - - //ComponentTableReset(component.Class, ""); } } diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 89121a60..0299de66 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -151,24 +151,44 @@ namespace Nuake { if (Selection.Type == EditorSelectionType::Entity && Selection.Entity == e) base_flags |= ImGuiTreeNodeFlags_Selected; + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{ 0.0f, 0.0f }); + { + ImGui::TableNextColumn(); + + bool& isVisible = e.GetComponent().Visible; + char* visibilityIcon = isVisible ? ICON_FA_EYE : ICON_FA_EYE_SLASH; + + + ImGui::PushStyleColor(ImGuiCol_Button, { 0, 0, 0, 0 }); + if (ImGui::Button(visibilityIcon, { 40, 40 })) + { + isVisible = !isVisible; + } + ImGui::PopStyleColor(); + } + + ImGui::PopStyleVar(); + ImGui::TableNextColumn(); - - ImGui::TableNextColumn(); - // Write in normal font. ImGui::PushFont(normalFont); + // If has no childrens draw tree node leaf if (parent.Children.size() <= 0) + { base_flags |= ImGuiTreeNodeFlags_Leaf; + } - if(nameComponent.IsPrefab && e.HasComponent()) - ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0,255,0,255)); + if (nameComponent.IsPrefab && e.HasComponent()) + { + ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 255, 0, 255)); + } ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8, 8)); - bool open = ImGui::TreeNodeEx(name.c_str(), base_flags); ImGui::PopStyleVar(); + if(nameComponent.IsPrefab && e.HasComponent()) ImGui::PopStyleColor(); else diff --git a/Nuake/VisibilityComponent.h b/Nuake/VisibilityComponent.h new file mode 100644 index 00000000..3f59c932 --- /dev/null +++ b/Nuake/VisibilityComponent.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/Nuake/dependencies/bullet3 b/Nuake/dependencies/bullet3 deleted file mode 160000 index 0e124cb2..00000000 --- a/Nuake/dependencies/bullet3 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0e124cb2f103c40de4afac6c100b7e8e1f5d9e15 diff --git a/Nuake/dependencies/bullet_p5.lua b/Nuake/dependencies/bullet_p5.lua deleted file mode 100644 index 23c1a52b..00000000 --- a/Nuake/dependencies/bullet_p5.lua +++ /dev/null @@ -1,116 +0,0 @@ -project "BulletCollision" - location "bullet3/src/BulletCollision" - kind "StaticLib" - staticruntime "on" - - targetdir ("bullet3/bin/" .. outputdir .. "/%{prj.name}") - objdir ("bullet3/bin-obj/" .. outputdir .. "/%{prj.name}") - includedirs { - "bullet3/src", - } - - defines - { - "BT_THREADSAFE=1", - "BT_USE_DOUBLE_PRECISION" - } - - filter "system:windows" - systemversion "latest" - files - { - "bullet3/src/*.cpp", - "bullet3/src/*.h", - "bullet3/src/BulletCollision/BroadphaseCollision/*.cpp", - "bullet3/src/BulletCollision/BroadphaseCollision/*.h", - "bullet3/src/BulletCollision/CollisionDispatch/*.cpp", - "bullet3/src/BulletCollision/CollisionDispatch/*.h", - "bullet3/src/BulletCollision/CollisionShapes/*.cpp", - "bullet3/src/BulletCollision/CollisionShapes/*.h", - "bullet3/src/BulletCollision/Gimpact/*.cpp", - "bullet3/src/BulletCollision/Gimpact/*.h", - "bullet3/src/BulletCollision/NarrowPhaseCollision/*.cpp", - "bullet3/src/BulletCollision/NarrowPhaseCollision/*.h", - } - - filter "configurations:Debug" - runtime "Debug" - symbols "on" - - filter "configurations:Release" - runtime "Release" - optimize "on" - -project "BulletDynamics" - location "bullet3/src/BulletDynamics" - kind "StaticLib" - staticruntime "on" - - targetdir ("bullet3/bin/" .. outputdir .. "/%{prj.name}") - objdir ("bullet3/bin-obj/" .. outputdir .. "/%{prj.name}") - - includedirs { - "bullet3/src", - } - - defines - { - "BT_THREADSAFE=1", - "BT_USE_DOUBLE_PRECISION" - } - - filter "system:windows" - systemversion "latest" - files - { - "bullet3/src/BulletDynamics/Dynamics/*.cpp", - "bullet3/src/BulletDynamics/Dynamics/*.h", - "bullet3/src/BulletDynamics/ConstraintSolver/*.cpp", - "bullet3/src/BulletDynamics/ConstraintSolver/*.h", - "bullet3/src/BulletDynamics/Featherstone/*.cpp", - "bullet3/src/BulletDynamics/Featherstone/*.h", - "bullet3/src/BulletDynamics/MLCPSolvers/*.cpp", - "bullet3/src/BulletDynamics/MLCPSolvers/*.h", - "bullet3/src/BulletDynamics/Vehicle/*.cpp", - "bullet3/src/BulletDynamics/Vehicle/*.h", - "bullet3/src/BulletDynamics/Character/*.cpp", - "bullet3/src/BulletDynamics/Character/*.h" - } - - filter "configurations:Debug" - runtime "Debug" - symbols "on" - - filter "configurations:Release" - runtime "Release" - optimize "on" - - -project "LinearMath" - location "bullet3/src/LinearMath" - kind "StaticLib" - staticruntime "on" - - targetdir ("bullet3/bin/" .. outputdir .. "/%{prj.name}") - objdir ("bullet3/bin-obj/" .. outputdir .. "/%{prj.name}") - - includedirs { - "bullet3/src" - } - - filter "system:windows" - systemversion "latest" - files { - "bullet3/src/LinearMath/*.cpp", - "bullet3/src/LinearMath/*.h", - "bullet3/src/LinearMath/TaskScheduler/*.cpp", - "bullet3/src/LinearMath/TaskScheduler/*.h" - } - - filter "configurations:Debug" - runtime "Debug" - symbols "on" - - filter "configurations:Release" - runtime "Release" - optimize "on" diff --git a/Nuake/dependencies/soloud_p5.lua b/Nuake/dependencies/soloud_p5.lua deleted file mode 100644 index d93be44a..00000000 --- a/Nuake/dependencies/soloud_p5.lua +++ /dev/null @@ -1,620 +0,0 @@ -local WITH_SDL = 0 -local WITH_SDL2 = 0 -local WITH_SDL_STATIC = 0 -local WITH_SDL2_STATIC = 0 -local WITH_PORTAUDIO = 0 -local WITH_OPENAL = 0 -local WITH_XAUDIO2 = 0 -local WITH_WINMM = 0 -local WITH_WASAPI = 0 -local WITH_ALSA = 0 -local WITH_JACK = 0 -local WITH_OSS = 0 -local WITH_COREAUDIO = 0 -local WITH_VITA_HOMEBREW = 0 -local WITH_NOSOUND = 0 -local WITH_MINIAUDIO = 0 -local WITH_NULL = 1 -local WITH_TOOLS = 0 - -if (os.is("Windows")) then - WITH_WINMM = 1 -elseif (os.is("macosx")) then - WITH_COREAUDIO = 1 -else - WITH_ALSA = 1 - WITH_OSS = 1 -end - --- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- - -local sdl_root = "/libraries/sdl" -local sdl2_root = "/libraries/sdl2" -local dxsdk_root = os.getenv("DXSDK_DIR") and os.getenv("DXSDK_DIR") or "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)" -local portaudio_root = "/libraries/portaudio" -local openal_root = "/libraries/openal" - --- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- - -local sdl_include = sdl_root .. "/include" -local sdl2_include = sdl2_root .. "/include" -local sdl2_lib_x86 = sdl2_root .. "/lib/x86" -local sdl2_lib_x64 = sdl2_root .. "/lib/x64" -local dxsdk_include = dxsdk_root .. "/include" -local portaudio_include = portaudio_root .. "/include" -local openal_include = openal_root .. "/include" - -local buildroot = "" -if _ACTION then buildroot = _ACTION end - --- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- - -newoption { - trigger = "with-common-backends", - description = "Includes common backends in build" -} - -newoption { - trigger = "with-openal", - description = "Include OpenAL backend in build" -} - -newoption { - trigger = "with-sdl", - description = "Include SDL backend in build" -} - -newoption { - trigger = "with-sdl2", - description = "Include SDL2 backend in build" -} - -newoption { - trigger = "with-portaudio", - description = "Include PortAudio backend in build" -} - -newoption { - trigger = "with-wasapi", - description = "Include WASAPI backend in build" -} - -newoption { - trigger = "with-xaudio2", - description = "Include XAudio2 backend in build" -} - -newoption { - trigger = "with-native-only", - description = "Only native backends (winmm/oss) in build (default)" -} - -newoption { - trigger = "with-sdl-only", - description = "Only include sdl in build" -} - -newoption { - trigger = "with-sdlstatic-only", - description = "Only include sdl that doesn't use dyndll in build" -} - -newoption { - trigger = "with-sdl2-only", - description = "Only include sdl2 in build" -} - -newoption { - trigger = "with-sdl2static-only", - description = "Only include sdl2 that doesn't use dyndll in build" -} - -newoption { - trigger = "with-coreaudio", - description = "Include OS X CoreAudio backend in build" -} - -newoption { - trigger = "with-vita-homebrew-only", - description = "Only include PS Vita homebrew backend in build" -} - -newoption { - trigger = "with-tools", - description = "Include (optional) tools in build" -} - -newoption { - trigger = "soloud-devel", - description = "Shorthand for options used while developing SoLoud" -} - -newoption { - trigger = "with-nosound", - description = "Include nosound backend in build" -} - -newoption { - trigger = "with-jack", - description = "Include JACK backend in build" -} - -newoption { - trigger = "with-jack-only", - description = "Only include JACK backend in build" -} - -newoption { - trigger = "with-miniaudio", - description = "Include MiniAudio in build" -} - -newoption { - trigger = "with-miniaudio-only", - description = "Only include MiniAudio in build" -} - -if _OPTIONS["soloud-devel"] then - WITH_SDL = 0 - WITH_SDL2 = 1 - WITH_SDL_STATIC = 0 - WITH_SDL2_STATIC = 0 - WITH_PORTAUDIO = 1 - WITH_OPENAL = 1 - WITH_XAUDIO2 = 0 - WITH_WINMM = 0 - WITH_WASAPI = 0 - WITH_MINIAUDIO = 1 - WITH_OSS = 1 - WITH_NOSOUND = 1 - if (os.is("Windows")) then - WITH_XAUDIO2 = 0 - WITH_WINMM = 1 - WITH_WASAPI = 1 - WITH_OSS = 0 - end - WITH_TOOLS = 1 -end - -if _OPTIONS["with-common-backends"] then - WITH_SDL = 1 - WITH_SDL_STATIC = 0 - WITH_SDL2_STATIC = 0 - WITH_PORTAUDIO = 1 - WITH_OPENAL = 1 - WITH_XAUDIO2 = 0 - WITH_WINMM = 0 - WITH_WASAPI = 0 - WITH_OSS = 1 - WITH_NOSOUND = 1 - WITH_MINIAUDIO = 0 - - if (os.is("Windows")) then - WITH_XAUDIO2 = 0 - WITH_WINMM = 1 - WITH_WASAPI = 1 - WITH_OSS = 0 - end -end - -if _OPTIONS["with-xaudio2"] then - WITH_XAUDIO2 = 1 -end - -if _OPTIONS["with-openal"] then - WITH_OPENAL = 1 -end - -if _OPTIONS["with-portaudio"] then - WITH_PORTAUDIO = 1 -end - -if _OPTIONS["with-coreaudio"] then - WITH_COREAUDIO = 1 -end - -if _OPTIONS["with-sdl"] then - WITH_SDL = 1 -end - -if _OPTIONS["with-sdl2"] then - WITH_SDL2 = 1 -end - -if _OPTIONS["with-wasapi"] then - WITH_WASAPI = 1 -end - -if _OPTIONS["with-nosound"] then - WITH_NOSOUND = 1 -end - -if _OPTIONS["with-sdl-only"] then - WITH_SDL = 1 - WITH_SDL2 = 0 - WITH_SDL_STATIC = 0 - WITH_SDL2_STATIC = 0 - WITH_PORTAUDIO = 0 - WITH_OPENAL = 0 - WITH_XAUDIO2 = 0 - WITH_WINMM = 0 - WITH_WASAPI = 0 - WITH_OSS = 0 - WITH_NOSOUND = 0 - WITH_MINIAUDIO = 0 -end - -if _OPTIONS["with-sdl2-only"] then - WITH_SDL = 0 - WITH_SDL2 = 1 - WITH_SDL_STATIC = 0 - WITH_SDL2_STATIC = 0 - WITH_PORTAUDIO = 0 - WITH_OPENAL = 0 - WITH_XAUDIO2 = 0 - WITH_WINMM = 0 - WITH_WASAPI = 0 - WITH_OSS = 0 - WITH_NOSOUND = 0 - WITH_MINIAUDIO = 0 -end - -if _OPTIONS["with-sdlstatic-only"] then - WITH_SDL = 0 - WITH_SDL2 = 0 - WITH_SDL_STATIC = 1 - WITH_PORTAUDIO = 0 - WITH_OPENAL = 0 - WITH_XAUDIO2 = 0 - WITH_WINMM = 0 - WITH_WASAPI = 0 - WITH_OSS = 0 - WITH_NOSOUND = 0 - WITH_MINIAUDIO = 0 -end - -if _OPTIONS["with-sdl2static-only"] then - WITH_SDL = 0 - WITH_SDL2 = 0 - WITH_SDL_STATIC = 0 - WITH_SDL2_STATIC = 1 - WITH_PORTAUDIO = 0 - WITH_OPENAL = 0 - WITH_XAUDIO2 = 0 - WITH_WINMM = 0 - WITH_WASAPI = 0 - WITH_OSS = 0 - WITH_NOSOUND = 0 - WITH_MINIAUDIO = 0 -end - -if _OPTIONS["with-sdl2static-only"] then - WITH_SDL = 0 - WITH_SDL2 = 0 - WITH_SDL_STATIC = 0 - WITH_SDL2_STATIC = 1 - WITH_PORTAUDIO = 0 - WITH_OPENAL = 0 - WITH_XAUDIO2 = 0 - WITH_WINMM = 0 - WITH_WASAPI = 0 - WITH_OSS = 0 - WITH_NOSOUND = 0 - WITH_MINIAUDIO = 0 -end - -if _OPTIONS["with-vita-homebrew-only"] then - WITH_SDL = 0 - WITH_SDL2 = 0 - WITH_SDL_STATIC = 0 - WITH_SDL2_STATIC = 0 - WITH_PORTAUDIO = 0 - WITH_OPENAL = 0 - WITH_XAUDIO2 = 0 - WITH_WINMM = 0 - WITH_WASAPI = 0 - WITH_OSS = 0 - WITH_ALSA = 0 - WITH_VITA_HOMEBREW = 1 - WITH_NOSOUND = 0 - WITH_MINIAUDIO = 0 - - premake.gcc.cc = "arm-vita-eabi-gcc" - premake.gcc.cxx = "arm-vita-eabi-g++" - premake.gcc.ar = "arm-vita-eabi-ar" -end - -if _OPTIONS["with-jack"] then - WITH_JACK = 1 -end - -if _OPTIONS["with-jack-only"] then - WITH_SDL = 0 - WITH_SDL2 = 0 - WITH_SDL_STATIC = 0 - WITH_SDL2_STATIC = 0 - WITH_PORTAUDIO = 0 - WITH_OPENAL = 0 - WITH_XAUDIO2 = 0 - WITH_WINMM = 0 - WITH_WASAPI = 0 - WITH_OSS = 0 - WITH_ALSA = 0 - WITH_VITA_HOMEBREW = 0 - WITH_COREAUDIO = 0 - WITH_JACK = 1 - WITH_NOSOUND = 0 - WITH_MINIAUDIO = 0 -end - -if _OPTIONS["with-miniaudio"] then - WITH_MINIAUDIO = 1 -end - -if _OPTIONS["with-miniaudio-only"] then - WITH_SDL = 0 - WITH_SDL2 = 0 - WITH_SDL_STATIC = 0 - WITH_SDL2_STATIC = 0 - WITH_PORTAUDIO = 0 - WITH_OPENAL = 0 - WITH_XAUDIO2 = 0 - WITH_WINMM = 0 - WITH_WASAPI = 0 - WITH_OSS = 0 - WITH_ALSA = 0 - WITH_VITA_HOMEBREW = 0 - WITH_COREAUDIO = 0 - WITH_JACK = 0 - WITH_NOSOUND = 0 - WITH_MINIAUDIO = 1 -end - -if _OPTIONS["with-native-only"] then - WITH_SDL = 0 - WITH_SDL2 = 0 - WITH_SDL_STATIC = 0 - WITH_SDL2_STATIC = 0 - WITH_PORTAUDIO = 0 - WITH_OPENAL = 0 - WITH_XAUDIO2 = 0 - WITH_WINMM = 0 - WITH_WASAPI = 0 - WITH_OSS = 0 - WITH_MINIAUDIO = 0 - WITH_NOSOUND = 0 - if (os.is("Windows")) then - WITH_WINMM = 1 - elseif (os.is("macosx")) then - WITH_COREAUDIO = 1 - else - WITH_OSS = 1 - end -end - -if _OPTIONS["with-tools"] then - WITH_TOOLS = 1 -end - -print ("") -print ("Active options:") -print ("WITH_SDL = ", WITH_SDL) -print ("WITH_SDL2 = ", WITH_SDL2) -print ("WITH_PORTAUDIO = ", WITH_PORTAUDIO) -print ("WITH_OPENAL = ", WITH_OPENAL) -print ("WITH_XAUDIO2 = ", WITH_XAUDIO2) -print ("WITH_WINMM = ", WITH_WINMM) -print ("WITH_WASAPI = ", WITH_WASAPI) -print ("WITH_ALSA = ", WITH_ALSA) -print ("WITH_JACK = ", WITH_JACK) -print ("WITH_OSS = ", WITH_OSS) -print ("WITH_MINIAUDIO = ", WITH_MINIAUDIO) -print ("WITH_NOSOUND = ", WITH_NOSOUND) -print ("WITH_COREAUDIO = ", WITH_COREAUDIO) -print ("WITH_VITA_HOMEBREW = ", WITH_VITA_HOMEBREW) -print ("WITH_TOOLS = ", WITH_TOOLS) -print ("") - - --- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- - - -project "SoloudStatic" -kind "StaticLib" -targetdir "soloud/lib" -language "C++" - -files -{ -"soloud/src/audiosource/**.c*", -"soloud/src/filter/**.c*", -"soloud/src/core/**.c*" -} - -includedirs -{ -"soloud/src/**", -"soloud/include" -} -if (WITH_OPENAL == 1) then -defines {"WITH_OPENAL"} -files { -"soloud/src/backend/openal/**.c*" -} -includedirs { -"soloud/include", -openal_include -} -end - -if (WITH_ALSA == 1) then -defines {"WITH_ALSA"} -files { -"soloud/src/backend/alsa/**.c*" -} -includedirs { -"soloud/include" -} -end - -if (WITH_OSS == 1) then -defines {"WITH_OSS"} -files { -"soloud/src/backend/oss/**.c*" -} -includedirs { -"soloud/include" -} -end - -if (WITH_MINIAUDIO == 1) then -defines {"WITH_MINIAUDIO"} -files { -"soloud/src/backend/miniaudio/**.c*" -} -includedirs { -"soloud/include" -} -end - -if (WITH_NOSOUND == 1) then -defines {"WITH_NOSOUND"} -files { -"soloud/src/backend/nosound/**.c*" -} -includedirs { -"soloud/include" -} -end - -if (WITH_COREAUDIO == 1) then -defines {"WITH_COREAUDIO"} -files { -"soloud/src/backend/coreaudio/**.c*" -} -includedirs { -"soloud/include" -} -end - -if (WITH_PORTAUDIO == 1) then -defines {"WITH_PORTAUDIO"} - -files { -"../src/backend/portaudio/**.c*" -} -includedirs { -"soloud/include", -portaudio_include -} -end - -if (WITH_SDL == 1) then -defines { "WITH_SDL" } -files { -"soloud/src/backend/sdl/**.c*" -} -includedirs { -"../include", -sdl2_include -} -end - -if (WITH_SDL2 == 1) then -defines { "WITH_SDL2" } -files { -"soloud/src/backend/sdl/**.c*" -} -includedirs { -"soloud/include", -sdl2_include -} -end - -if (WITH_SDL_STATIC == 1) then -defines { "WITH_SDL_STATIC" } -files { -"../src/backend/sdl_static/**.c*" -} -includedirs { -"../include", -sdl_include -} -end - -if (WITH_SDL2_STATIC == 1) then -defines { "WITH_SDL2_STATIC" } -files { -"../src/backend/sdl2_static/**.c*" -} -includedirs { -"../include", -sdl2_include -} -end - -if (WITH_WASAPI == 1) then -defines { "WITH_WASAPI" } -files { -"../src/backend/wasapi/**.c*" -} -includedirs { -"../include" -} -end - -if (WITH_XAUDIO2 == 1) then -defines {"WITH_XAUDIO2"} -files { -"../src/backend/xaudio2/**.c*" -} -includedirs { -"../include", -dxsdk_include -} -end - -if (WITH_WINMM == 1) then -defines { "WITH_WINMM" } -files { -"../src/backend/winmm/**.c*" -} -includedirs { -"../include" -} -end - -if (WITH_VITA_HOMEBREW == 1) then -defines { "WITH_VITA_HOMEBREW", "usleep=sceKernelDelayThread" } -files { -"../src/backend/vita_homebrew/**.c*" -} -includedirs { -"../include" -} -end - - -if (WITH_JACK == 1) then -defines { "WITH_JACK" } -links { "jack" } -files { -"../src/backend/jack/**.c*" -} -includedirs { -"../include" -} -end - -if (WITH_NULL == 1) then -defines { "WITH_NULL" } -files { -"../src/backend/null/**.c*" -} -includedirs { -"../include" -} -end - -targetname "soloud_static" - diff --git a/Nuake/src/Core/Logger.cpp b/Nuake/src/Core/Logger.cpp index bbb6870d..711591c5 100644 --- a/Nuake/src/Core/Logger.cpp +++ b/Nuake/src/Core/Logger.cpp @@ -21,7 +21,7 @@ namespace Nuake }; std::string msg = "[" + std::string(buff) + "]" + std::string(" - ") + log + "\n"; - printf((msg).c_str()); + std::cout << msg << std::endl; if (m_Logs.size() >= MAX_LOG) m_Logs.erase(m_Logs.begin()); diff --git a/Nuake/src/Core/Physics/BulletDebugDrawer.cpp b/Nuake/src/Core/Physics/BulletDebugDrawer.cpp index b59aef84..78b1876f 100644 --- a/Nuake/src/Core/Physics/BulletDebugDrawer.cpp +++ b/Nuake/src/Core/Physics/BulletDebugDrawer.cpp @@ -1,33 +1,7 @@ -#include "BulletDebugDrawer.h" #include "../../Rendering/Renderer.h" #include namespace Nuake { - void BulletDebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& color) - { - TransformComponent tc = TransformComponent(); - - //tc.Translation = glm::vec3(from.x(), from.y(), from.z()); - //tc.Scale = glm::vec3(1.0f); - //tc.Rotation = glm::vec3(0.0f); - - glBegin(GL_LINES); - glColor3f((float)(color.x()), (float)(color.y()), (float)(color.z())); - glVertex3f((float)(from.x()), (float)(from.y()), (float)(from.z())); - glVertex3f((float)(to.x()), (float)(to.y()), (float)(to.z())); - glEnd(); - - //Renderer::DrawCube(tc, glm::vec4(color.x(), color.y(), color.z(), 1.0f)); - } - - void BulletDebugDrawer::drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color) - { - if (lifeTime > 3.0f) - return; - glBegin(GL_POINTS); - glColor3f(color.x(), color.y(), color.z()); - glVertex3f(PointOnB.x(), PointOnB.y(), PointOnB.z()); - glEnd(); - } + } diff --git a/Nuake/src/Core/Physics/BulletDebugDrawer.h b/Nuake/src/Core/Physics/BulletDebugDrawer.h index 46218269..cb837afe 100644 --- a/Nuake/src/Core/Physics/BulletDebugDrawer.h +++ b/Nuake/src/Core/Physics/BulletDebugDrawer.h @@ -1,20 +1,6 @@ #pragma once -#include "btBulletCollisionCommon.h" namespace Nuake { - class BulletDebugDrawer : public btIDebugDraw - { - void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override; - - int getDebugMode() const override { return 1; } - - void draw3dText(const btVector3& location, const char* textString) override {} - - void reportErrorWarning(const char* warningString) override { }; - - void setDebugMode(int debugMode) {}; - - void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color) override; - }; + } diff --git a/Nuake/src/Core/Physics/CharacterController.cpp b/Nuake/src/Core/Physics/CharacterController.cpp index c003e334..f789a0eb 100644 --- a/Nuake/src/Core/Physics/CharacterController.cpp +++ b/Nuake/src/Core/Physics/CharacterController.cpp @@ -12,184 +12,51 @@ namespace Nuake m_bottomRoundedRegionYOffset = (height + radius) / 2.0f; m_bottomYOffset = height / 2.0f + radius; - m_CollisionShape = new btCapsuleShape(radius, height); - btQuaternion quat = btQuaternion(0, 0, 0); - m_Transform = new btTransform(); - m_Transform->setOrigin(btVector3(position.x, position.y, position.z)); - m_Transform->setRotation(quat); - m_MotionState = new btDefaultMotionState(*m_Transform); + - btVector3 inertia; //m_CollisionShape->calculateLocalInertia(mass, inertia); - btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, m_MotionState, m_CollisionShape, inertia); - - rigidBodyCI.m_friction = 0.0f; + //rigidBodyCI.m_additionalDamping = true; //rigidBodyCI.m_additionalLinearDampingThresholdSqr= 1.0f; //rigidBodyCI.m_additionalLinearDampingThresholdSqr = 0.5f; - rigidBodyCI.m_restitution = 0.0f; - - rigidBodyCI.m_linearDamping = 0.0f; - m_Rigidbody = new btRigidBody(rigidBodyCI); - m_Rigidbody->setGravity(btVector3(0, 0, 0)); - // Keep upright - m_Rigidbody->setAngularFactor(0.0f); - - // No sleeping (or else setLinearVelocity won't work) - m_Rigidbody->setActivationState(DISABLE_DEACTIVATION); - - //m_pPhysicsWorld->m_pDynamicsWorld->addRigidBody(m_pRigidBody); - - // Ghost object that is synchronized with rigid body - m_GhostObject = new btPairCachingGhostObject(); - m_GhostObject->setCollisionShape(m_CollisionShape); - + // Specify filters manually, otherwise ghost doesn't collide with statics for some reason //m_pPhysicsWorld->m_pDynamicsWorld->addCollisionObject(m_pGhostObject, btBroadphaseProxy::KinematicFilter, btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter); } void CharacterController::SetEntity(Entity& ent) { - m_Rigidbody->setUserIndex(ent.GetHandle()); - m_GhostObject->setUserIndex(ent.GetHandle()); + } void CharacterController::MoveAndSlide(glm::vec3 velocity) { - m_Rigidbody->setGravity(btVector3(0, 0, 0)); - m_manualVelocity = velocity; - // Sync ghost with actually object - m_GhostObject->setWorldTransform(m_Rigidbody->getWorldTransform()); + IsOnGround = false; ParseGhostContacts(); UpdatePosition(); UpdateVelocity(); - m_MotionState->getWorldTransform(m_motionTransform); } void CharacterController::ParseGhostContacts() { - btManifoldArray manifoldArray; - btBroadphasePairArray& pairArray = m_GhostObject->getOverlappingPairCache()->getOverlappingPairArray(); - int numPairs = pairArray.size(); - - m_hittingWall = false; - - for (int i = 0; i < numPairs; i++) - { - manifoldArray.clear(); - - const btBroadphasePair& pair = pairArray[i]; - - btDiscreteDynamicsWorld* world = PhysicsManager::Get()->GetWorld()->GetDynamicWorld(); - btBroadphasePair* collisionPair = world->getPairCache()->findPair(pair.m_pProxy0, pair.m_pProxy1); - - if (collisionPair == NULL) - continue; - - if (collisionPair->m_algorithm != NULL) - collisionPair->m_algorithm->getAllContactManifolds(manifoldArray); - - for (int j = 0; j < manifoldArray.size(); j++) - { - btPersistentManifold* pManifold = manifoldArray[j]; - - // Skip the rigid body the ghost monitors - if (pManifold->getBody0() == m_Rigidbody) - continue; - - for (int p = 0; p < pManifold->getNumContacts(); p++) - { - const btManifoldPoint& point = pManifold->getContactPoint(p); - - if (point.getDistance() < 0.0f) - { - //const btVector3 &ptA = point.getPositionWorldOnA(); - const btVector3& ptB = point.getPositionWorldOnB(); - - //const btVector3 &normalOnB = point.m_normalWorldOnB; - - // If point is in rounded bottom region of capsule shape, it is on the ground - if (ptB.getY() < m_motionTransform.getOrigin().getY() - m_bottomRoundedRegionYOffset) - IsOnGround = true; - else - { - m_hittingWall = true; - - m_surfaceHitNormals.push_back(glm::vec3(point.m_normalWorldOnB.x(), point.m_normalWorldOnB.y(), point.m_normalWorldOnB.z())); - } - } - } - } - } + } void CharacterController::UpdatePosition() { - // Ray cast, ignore rigid body - IgnoreBodyAndGhostCast rayCallBack_bottom(m_Rigidbody, m_GhostObject); + - btVector3 from = m_Rigidbody->getWorldTransform().getOrigin(); - btVector3 toBt = m_Rigidbody->getWorldTransform().getOrigin() - btVector3(0.0f, m_bottomYOffset + m_stepHeight, 0.0f); - PhysicsManager::Get()->GetWorld()->GetDynamicWorld()->rayTest(from, toBt, rayCallBack_bottom); - - // Bump up if hit - if (rayCallBack_bottom.hasHit()) - { - float previousY = m_Rigidbody->getWorldTransform().getOrigin().getY(); - - - float t = rayCallBack_bottom.m_closestHitFraction; - - float clamped = (1.0 - rayCallBack_bottom.m_closestHitFraction); - btVector3 vel(m_Rigidbody->getLinearVelocity()); - - if (vel.getY() < 0) // -magic number is to fix bouncing down a slope. - m_Rigidbody->getWorldTransform().getOrigin().setY(previousY - 0.14f + (m_bottomYOffset + m_stepHeight) * (clamped)); - - vel.setY(0.0f); - - m_Rigidbody->setLinearVelocity(vel); - - IsOnGround = true; - - } - - - - float testOffset = 0.07f; - - // Ray cast, ignore rigid body - IgnoreBodyAndGhostCast rayCallBack_top(m_Rigidbody, m_GhostObject); - - PhysicsManager::Get()->GetWorld()->GetDynamicWorld()->rayTest(m_Rigidbody->getWorldTransform().getOrigin(), m_Rigidbody->getWorldTransform().getOrigin() + btVector3(0.0f, m_bottomYOffset + testOffset, 0.0f), rayCallBack_top); - - // Bump up if hit - if (rayCallBack_top.hasHit()) - { - m_Rigidbody->getWorldTransform().setOrigin(m_previousPosition); - - btVector3 vel(m_Rigidbody->getLinearVelocity()); - - vel.setY(0.0f); - - m_Rigidbody->setLinearVelocity(vel); - } - - m_previousPosition = m_Rigidbody->getWorldTransform().getOrigin(); } void CharacterController::UpdateVelocity() { - //m_manualVelocity.y = m_Rigidbody->getLinearVelocity().getY(); - btVector3 grav = m_Rigidbody->getGravity(); - btVector3 finalVel = btVector3(m_manualVelocity.x, m_manualVelocity.y, m_manualVelocity.z); - m_Rigidbody->setLinearVelocity(finalVel); + // Decelerate //m_manualVelocity -= m_manualVelocity * m_deceleration * m_pPhysicsWorld->GetScene()->m_frameTimer.GetTimeMultiplier(); diff --git a/Nuake/src/Core/Physics/CharacterController.h b/Nuake/src/Core/Physics/CharacterController.h index 72785e17..45addd66 100644 --- a/Nuake/src/Core/Physics/CharacterController.h +++ b/Nuake/src/Core/Physics/CharacterController.h @@ -2,9 +2,6 @@ #include "src/Core/Core.h" #include "src/Core/Maths.h" -#include -#include - namespace Nuake { class Entity; @@ -19,23 +16,16 @@ namespace Nuake float m_stepHeight = 0.35f; float m_MaxSlopeAngle = 45.0f; - btTransform* m_Transform; - btCollisionShape* m_CollisionShape; - btRigidBody* m_Rigidbody; - btPairCachingGhostObject* m_GhostObject; - btMotionState* m_MotionState; //bool m_onJumpableGround; // A bit lower contact than just onGround float m_bottomYOffset; float m_bottomRoundedRegionYOffset; - btTransform m_motionTransform; glm::vec3 m_manualVelocity; std::vector m_surfaceHitNormals; - btVector3 m_previousPosition; float m_jumpRechargeTimer; CharacterController(float height, float radius, float mass, Vector3 position); diff --git a/Nuake/src/Core/Physics/DynamicWorld.cpp b/Nuake/src/Core/Physics/DynamicWorld.cpp index edf02a43..7f06b078 100644 --- a/Nuake/src/Core/Physics/DynamicWorld.cpp +++ b/Nuake/src/Core/Physics/DynamicWorld.cpp @@ -1,7 +1,6 @@ #include "DynamicWorld.h" #include "Rigibody.h" #include "../Core/Core.h" -#include "BulletDebugDrawer.h" #include #include @@ -11,82 +10,47 @@ namespace Nuake { DynamicWorld::DynamicWorld() { ///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration. - btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration(); - - ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) - btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration); - - ///btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep. - btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase(); - - ///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) - btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver; - - dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration); - dynamicsWorld->setDebugDrawer(new BulletDebugDrawer()); - - m_Bodies = std::map>(); - + SetGravity(Vector3(0, -10000, 0)); } void DynamicWorld::DrawDebug() { - dynamicsWorld->debugDrawWorld(); } void DynamicWorld::SetGravity(glm::vec3 g) { - dynamicsWorld->setGravity(btVector3(g.x, g.y, g.z)); } void DynamicWorld::AddRigidbody(Ref rb) { - btRigidBody* bt = rb->GetBulletRigidbody(); - m_Bodies.emplace(std::pair>(bt, rb)); - dynamicsWorld->addRigidBody(rb->GetBulletRigidbody()); + } void DynamicWorld::AddGhostbody(Ref gb) { - dynamicsWorld->addCollisionObject(gb->GetBulletObject(), btBroadphaseProxy::SensorTrigger, btBroadphaseProxy::KinematicFilter); } void DynamicWorld::AddCharacterController(Ref cc) { - dynamicsWorld->addRigidBody(cc->m_Rigidbody); // Specify filters manually, otherwise ghost doesn't collide with statics for some reason - dynamicsWorld->addCollisionObject(cc->m_GhostObject, btBroadphaseProxy::KinematicFilter, btBroadphaseProxy::SensorTrigger | btBroadphaseProxy::StaticFilter); } RaycastResult DynamicWorld::Raycast(glm::vec3 from, glm::vec3 to) { - btVector3 btFrom(from.x, from.y, from.z); - btVector3 btTo(to.x, to.y, to.z); - ClosestRayResultCallback res(btFrom, btTo); - - dynamicsWorld->rayTest(btFrom, btTo, res); - btVector3 localNormal; - if (res.m_collisionObject) - { - // TODO: Fix the godammn fucked up normal - localNormal = res.m_hitNormalWorld; - } - - - Vector3 localNorm = glm::vec3(localNormal.x(), localNormal.y(), localNormal.z()); + Vector3 localNorm = glm::vec3(0,0,0); //Logger::Log("normal: x:" + std::to_string(localNorm.x) + " y:" + std::to_string(localNorm.y )+ "z: " + std::to_string(localNorm.z)); - res.m_closestHitFraction; + // Map bullet result to dto. RaycastResult result{ - glm::vec3(res.m_hitPointWorld.x(), res.m_hitPointWorld.y(), res.m_hitPointWorld.z()), - glm::vec3(res.m_hitPointWorld.x(), res.m_hitPointWorld.y(), res.m_hitPointWorld.z()), + glm::vec3(0,0,0), + glm::vec3(0,0,0), localNorm }; @@ -96,39 +60,13 @@ namespace Nuake void DynamicWorld::StepSimulation(Timestep ts) { - dynamicsWorld->stepSimulation(ts, 0); - for (int j = dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--) - { - btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[j]; - btRigidBody* body = btRigidBody::upcast(obj); - btTransform trans; - if (body && body->getMotionState()) - { - body->getMotionState()->getWorldTransform(trans); - if (m_Bodies.find(body) != m_Bodies.end()) - m_Bodies[body]->UpdateTransform(trans); - } - else - { - trans = obj->getWorldTransform(); - if (m_Bodies.find(body) != m_Bodies.end()) - m_Bodies[body]->UpdateTransform(trans); - } - //printf("world pos object %d = %f,%f,%f\n", j, float(trans.getOrigin().getX()), float(trans.getOrigin().getY()), float(trans.getOrigin().getZ())); - } } void DynamicWorld::Clear() { - for (int j = dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; j--) - { - btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[j]; - dynamicsWorld->removeCollisionObject(obj); - } - - m_Bodies.clear(); + } } diff --git a/Nuake/src/Core/Physics/DynamicWorld.h b/Nuake/src/Core/Physics/DynamicWorld.h index b5985464..b4e9d4a1 100644 --- a/Nuake/src/Core/Physics/DynamicWorld.h +++ b/Nuake/src/Core/Physics/DynamicWorld.h @@ -1,5 +1,4 @@ #pragma once -#include #include #include "Rigibody.h" #include "src/Core/Timestep.h" @@ -15,8 +14,6 @@ namespace Nuake namespace Physics { class DynamicWorld { private: - btDiscreteDynamicsWorld* dynamicsWorld; - std::map> m_Bodies; public: DynamicWorld(); @@ -33,7 +30,6 @@ namespace Nuake void StepSimulation(Timestep ts); void Clear(); - btDiscreteDynamicsWorld* GetDynamicWorld() { return dynamicsWorld; } }; } } diff --git a/Nuake/src/Core/Physics/GhostObject.cpp b/Nuake/src/Core/Physics/GhostObject.cpp index 17a838e1..7a969226 100644 --- a/Nuake/src/Core/Physics/GhostObject.cpp +++ b/Nuake/src/Core/Physics/GhostObject.cpp @@ -1,7 +1,5 @@ #include "GhostObject.h" -#include -#include -#include + #include namespace Nuake @@ -9,19 +7,11 @@ namespace Nuake GhostObject::GhostObject(Vector3 position, Ref shape) { m_OverlappingEntities = std::vector(); - m_BulletObject = new btGhostObject(); - - btTransform transform = btTransform(); - transform.setIdentity(); - transform.setOrigin(btVector3(position.x, position.y, position.z)); - - m_BulletObject->setWorldTransform(transform); - m_BulletObject->setCollisionShape(shape->GetBulletShape()); } int GhostObject::OverlappingCount() { - return m_BulletObject->getNumOverlappingObjects(); + return 0; } void GhostObject::ClearOverlappingList() @@ -31,7 +21,6 @@ namespace Nuake void GhostObject::SetEntityID(Entity ent) { - m_BulletObject->setUserIndex(ent.GetHandle()); } void GhostObject::ScanOverlap() @@ -40,7 +29,7 @@ namespace Nuake for (int i = 0; i < OverlappingCount(); i++) { - int index = m_BulletObject->getOverlappingObject(i)->getUserIndex(); + int index =0; if (index == -1) continue; @@ -54,9 +43,4 @@ namespace Nuake return m_OverlappingEntities; } - // Internal use only. - btGhostObject* GhostObject::GetBulletObject() - { - return m_BulletObject; - } } diff --git a/Nuake/src/Core/Physics/GhostObject.h b/Nuake/src/Core/Physics/GhostObject.h index f1bf3d8a..fd01ffc8 100644 --- a/Nuake/src/Core/Physics/GhostObject.h +++ b/Nuake/src/Core/Physics/GhostObject.h @@ -7,13 +7,11 @@ #include -class btGhostObject; namespace Nuake { class GhostObject { private: - btGhostObject* m_BulletObject; std::vector m_OverlappingEntities; public: @@ -27,7 +25,5 @@ namespace Nuake std::vector GetOverlappingEntities(); - // Internal use only. - btGhostObject* GetBulletObject(); }; } diff --git a/Nuake/src/Core/Physics/PhysicsManager.cpp b/Nuake/src/Core/Physics/PhysicsManager.cpp index f51c49f1..9ab6bcb8 100644 --- a/Nuake/src/Core/Physics/PhysicsManager.cpp +++ b/Nuake/src/Core/Physics/PhysicsManager.cpp @@ -1,6 +1,5 @@ #include "PhysicsManager.h" #include "PhysicsShapes.h" -#include "btBulletDynamicsCommon.h" #include "../Core/Core.h" namespace Nuake @@ -33,9 +32,7 @@ namespace Nuake RaycastResult PhysicsManager::Raycast(glm::vec3 from, glm::vec3 to) { - btVector3 btFrom(from.x, from.y, from.z); - btVector3 btTo(to.x, to.y, to.z); - btCollisionWorld::ClosestRayResultCallback res(btFrom, btTo); + return m_World->Raycast(from, to); @@ -52,7 +49,6 @@ namespace Nuake m_World = new Physics::DynamicWorld(); m_World->SetGravity(glm::vec3(0, -3, 0)); - m_World->GetDynamicWorld()->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback()); m_IsRunning = false; } diff --git a/Nuake/src/Core/Physics/PhysicsManager.h b/Nuake/src/Core/Physics/PhysicsManager.h index 932c90a9..fa917139 100644 --- a/Nuake/src/Core/Physics/PhysicsManager.h +++ b/Nuake/src/Core/Physics/PhysicsManager.h @@ -13,7 +13,6 @@ namespace Nuake private: Physics::DynamicWorld* m_World; bool m_IsRunning = false; - btAlignedObjectArray collisionShapes; bool m_DrawDebug = false; static PhysicsManager* m_Instance; diff --git a/Nuake/src/Core/Physics/PhysicsShapes.cpp b/Nuake/src/Core/Physics/PhysicsShapes.cpp index b95e242d..ec773dd1 100644 --- a/Nuake/src/Core/Physics/PhysicsShapes.cpp +++ b/Nuake/src/Core/Physics/PhysicsShapes.cpp @@ -1,5 +1,4 @@ #include "PhysicsShapes.h" -#include "btBulletDynamicsCommon.h" #include "src/Rendering/Vertex.h" namespace Nuake @@ -9,19 +8,16 @@ namespace Nuake Box::Box() { Size = glm::vec3(1); - bShape = new btBoxShape(btVector3(Size.x, Size.y, Size.z)); m_Type = BOX; } // Sphere Box::Box(glm::vec3 size) { Size = size; - bShape = new btBoxShape(btVector3(size.x, size.y, size.z)); m_Type = BOX; } Box::Box(float x, float y, float z) { Size = glm::vec3(x, y, z); - bShape = new btBoxShape(btVector3(x, y, z)); m_Type = BOX; } @@ -33,13 +29,11 @@ namespace Nuake // Sphere Sphere::Sphere(float radius) { Radius = radius; - bShape = new btSphereShape(Radius); m_Type = SPHERE; } void Sphere::SetRadius(float radius) { - ((btSphereShape*)bShape)->setUnscaledRadius(radius); Radius = radius; } @@ -51,7 +45,6 @@ namespace Nuake MeshShape::MeshShape(Ref mesh) { m_Mesh = mesh; - btTriangleMesh* trimesh = new btTriangleMesh(); auto& indices = mesh->GetIndices(); auto& vertices = mesh->GetVertices(); @@ -61,14 +54,9 @@ namespace Nuake Vector3 tri2 = vertices[indices[i + 1]].position; Vector3 tri3 = vertices[indices[i + 2]].position; - btVector3 btri1 = btVector3(tri1.x, tri1.y, tri1.z); - btVector3 btri2 = btVector3(tri2.x, tri2.y, tri2.z); - btVector3 btri3 = btVector3(tri3.x, tri3.y, tri3.z); - trimesh->addTriangle(btri1, btri2, btri3, false); } - bShape = new btBvhTriangleMeshShape(trimesh, false, true);; } btCollisionShape* MeshShape::GetBulletShape() diff --git a/Nuake/src/Core/Physics/RaycastResult.h b/Nuake/src/Core/Physics/RaycastResult.h index aae05b18..2da51a59 100644 --- a/Nuake/src/Core/Physics/RaycastResult.h +++ b/Nuake/src/Core/Physics/RaycastResult.h @@ -2,64 +2,12 @@ #include #include "CharacterController.h" -#include namespace Nuake { namespace Physics { - struct ClosestRayResultCallback : public btCollisionWorld::RayResultCallback - { - ClosestRayResultCallback(const btVector3& rayFromWorld, const btVector3& rayToWorld) - : m_rayFromWorld(rayFromWorld), - m_rayToWorld(rayToWorld) - { - } - - btVector3 m_rayFromWorld; //used to calculate hitPointWorld from hitFraction - btVector3 m_rayToWorld; - - btVector3 m_hitNormalWorld; - btVector3 m_hitPointWorld; - - virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) - { - //caller already does the filter on the m_closestHitFraction - btAssert(rayResult.m_hitFraction <= m_closestHitFraction); - - m_closestHitFraction = rayResult.m_hitFraction; - m_collisionObject = rayResult.m_collisionObject; - - m_hitNormalWorld = rayResult.m_hitNormalLocal; - - - m_hitPointWorld.setInterpolate3(m_rayFromWorld, m_rayToWorld, rayResult.m_hitFraction); - return rayResult.m_hitFraction; - } - }; - - class IgnoreBodyAndGhostCast : - public Physics::ClosestRayResultCallback - { - private: - btRigidBody* m_pBody; - btPairCachingGhostObject* m_pGhostObject; - - public: - IgnoreBodyAndGhostCast(btRigidBody* pBody, btPairCachingGhostObject* pGhostObject) - : ClosestRayResultCallback(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 0.0, 0.0)), - m_pBody(pBody), m_pGhostObject(pGhostObject) - { - } - - btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) - { - if (rayResult.m_collisionObject == m_pBody || rayResult.m_collisionObject == m_pGhostObject) - return 1.0f; - - return ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace); - } - }; + } diff --git a/Nuake/src/Core/Physics/Rigibody.h b/Nuake/src/Core/Physics/Rigibody.h index f82fe66a..4a4694e0 100644 --- a/Nuake/src/Core/Physics/Rigibody.h +++ b/Nuake/src/Core/Physics/Rigibody.h @@ -2,9 +2,6 @@ #include "PhysicsShapes.h" #include "../Core/Core.h" #include -class btTransform; -class btRigidBody; -class btVector3; namespace Nuake { @@ -16,20 +13,17 @@ namespace Nuake bool m_IsKinematic = false; glm::vec3 m_InitialVel; - btRigidBody* m_Rigidbody; Ref m_CollisionShape; public: - btTransform* m_Transform; float m_Mass; RigidBody(); RigidBody(glm::vec3 position, Entity handle); RigidBody(float mass, glm::vec3 position, Ref shape, glm::vec3 initialVel = glm::vec3(0, 0, 0)); - btRigidBody* GetBulletRigidbody() const { return m_Rigidbody; } - void UpdateTransform(btTransform t); + void UpdateTransform(); glm::vec3 GetPosition() const; glm::vec3 GetRotation() const; diff --git a/Nuake/src/Core/Physics/Rigidbody.cpp b/Nuake/src/Core/Physics/Rigidbody.cpp index 8c7a8652..af49f466 100644 --- a/Nuake/src/Core/Physics/Rigidbody.cpp +++ b/Nuake/src/Core/Physics/Rigidbody.cpp @@ -1,6 +1,5 @@ #include "PhysicsShapes.h" #include "Rigibody.h" -#include #include "../Core.h" #include #include @@ -11,9 +10,7 @@ namespace Nuake { RigidBody::RigidBody() { - m_Transform = new btTransform(); - m_Transform->setIdentity(); - //m_Transform->setOrigin(btVector3(position.x, position.y, position.z)); + } RigidBody::RigidBody(glm::vec3 position, Entity handle) @@ -21,100 +18,59 @@ namespace Nuake Ref shape = CreateRef(); m_CollisionShape = shape; - m_Transform = new btTransform(); - m_Transform->setIdentity(); - m_Transform->setOrigin(btVector3(position.x, position.y, position.z)); + m_Mass = 0.0f; //rigidbody is dynamic if and only if mass is non zero, otherwise static m_IsDynamic = (m_Mass != 0.0f); - btVector3 localInertia(0, 0, 0); - if (m_IsDynamic) - m_CollisionShape->GetBulletShape()->calculateLocalInertia(m_Mass, localInertia); + m_InitialVel = glm::vec3(0, 0, 0); - //using motionstate is optional, it provides interpolation capabilities, and only synchronizes 'active' objects - btDefaultMotionState* myMotionState = new btDefaultMotionState(*m_Transform); - btRigidBody::btRigidBodyConstructionInfo rbInfo(m_Mass, myMotionState, m_CollisionShape->GetBulletShape(), localInertia); - - m_Rigidbody = new btRigidBody(rbInfo); - m_Rigidbody->setUserIndex(handle.GetHandle()); + } RigidBody::RigidBody(float mass, glm::vec3 position, Ref shape, glm::vec3 initialVel) { m_CollisionShape = shape; - m_Transform = new btTransform(); - m_Transform->setIdentity(); - m_Transform->setOrigin(btVector3(position.x, position.y, position.z)); - m_Mass = mass; //rigidbody is dynamic if and only if mass is non zero, otherwise static m_IsDynamic = (m_Mass != 0.0f); - btVector3 localInertia(initialVel.x, initialVel.y, initialVel.z); - m_InitialVel = initialVel; - if (m_IsDynamic) - m_CollisionShape->GetBulletShape()->calculateLocalInertia(m_Mass, localInertia); - - //using motionstate is optional, it provides interpolation capabilities, and only synchronizes 'active' objects - btDefaultMotionState* myMotionState = new btDefaultMotionState(*m_Transform); - btRigidBody::btRigidBodyConstructionInfo rbInfo(m_Mass, myMotionState, m_CollisionShape->GetBulletShape(), localInertia); - - m_Rigidbody = new btRigidBody(rbInfo); } void RigidBody::SetShape(Ref shape) { - m_Rigidbody->setCollisionShape(shape->GetBulletShape()); m_CollisionShape = shape; } - void RigidBody::UpdateTransform(btTransform t) + void RigidBody::UpdateTransform() { - m_Transform->setOrigin(t.getOrigin()); - m_Transform->setRotation(t.getRotation()); - m_Rigidbody->setWorldTransform(t); } glm::vec3 RigidBody::GetRotation() const { - auto q = m_Transform->getRotation(); - btScalar x = 0, y = 0, z = 0; - q.getEulerZYX(z, y, x); - return glm::vec3(glm::degrees(x), glm::degrees(y), glm::degrees(z)); + return { 0, 0, 0 }; } void RigidBody::SetEntityID(Entity ent) { - m_Rigidbody->setUserIndex(ent.GetHandle()); + } void RigidBody::SetKinematic(bool value) { - if (value) // Kinematic bodies dont deactivate. - { - m_Rigidbody->setCollisionFlags(m_Rigidbody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); - m_Rigidbody->setActivationState(DISABLE_DEACTIVATION); - } - else // Reenable deactivation. - { - m_Rigidbody->setCollisionFlags(m_Rigidbody->getCollisionFlags() ^ ~btCollisionObject::CF_KINEMATIC_OBJECT); - m_Rigidbody->setActivationState(WANTS_DEACTIVATION); - } + } glm::vec3 RigidBody::GetPosition() const { - btVector3 btPos = m_Transform->getOrigin(); - - return glm::vec3(btPos.x(), btPos.y(), btPos.z()); + return { 0, 0, 0 }; } - void RigidBody::SetMass(float m) { m_Rigidbody->setMassProps(m, btVector3(m_InitialVel.x, m_InitialVel.y, m_InitialVel.y)); m_Mass = m; } + void RigidBody::SetMass(float m) { } void RigidBody::MoveAndSlide(glm::vec3 velocity) { diff --git a/Nuake/src/Rendering/SceneRenderer.cpp b/Nuake/src/Rendering/SceneRenderer.cpp index 00b5fbcc..a08d79c9 100644 --- a/Nuake/src/Rendering/SceneRenderer.cpp +++ b/Nuake/src/Rendering/SceneRenderer.cpp @@ -123,13 +123,13 @@ namespace Nuake { RenderCommand::Disable(RendererEnum::FACE_CULL); glCullFace(GL_BACK); - auto meshView = scene.m_Registry.view(); - auto quakeView = scene.m_Registry.view(); - auto view = scene.m_Registry.view(); + auto meshView = scene.m_Registry.view(); + auto quakeView = scene.m_Registry.view(); + auto view = scene.m_Registry.view(); for (auto l : view) { - auto [lightTransform, light] = view.get(l); - if (light.Type != LightType::Directional || !light.CastShadows) + auto [lightTransform, light, visibility] = view.get(l); + if (light.Type != LightType::Directional || !light.CastShadows || !visibility.Visible) continue; light.CalculateViewProjection(mView, mProjection); @@ -142,8 +142,8 @@ namespace Nuake { shader->SetUniformMat4f("u_LightTransform", light.mViewProjections[i]); for (auto e : meshView) { - auto [transform, mesh] = meshView.get(e); - if (mesh.ModelResource != nullptr) + auto [transform, mesh, visibility] = meshView.get(e); + if (mesh.ModelResource != nullptr && visibility.Visible) { for (auto& m : mesh.ModelResource->GetMeshes()) Renderer::SubmitMesh(m, transform.GetGlobalTransform()); @@ -152,9 +152,9 @@ namespace Nuake { for (auto e : quakeView) { - auto [transform, model] = quakeView.get(e); + auto [transform, model, visibility] = quakeView.get(e); - if (model.IsTransparent) + if (model.IsTransparent || !visibility.Visible) continue; for (Ref& m : model.Meshes) @@ -181,12 +181,12 @@ namespace Nuake { gBufferShader->SetUniformMat4f("u_Projection", mProjection); gBufferShader->SetUniformMat4f("u_View", mView); - auto view = scene.m_Registry.view(); + auto view = scene.m_Registry.view(); for (auto e : view) { - auto [transform, mesh, parent] = view.get(e); + auto [transform, mesh, parent, visibility] = view.get(e); - if (mesh.ModelResource) + if (mesh.ModelResource && visibility.Visible) { for (auto& m : mesh.ModelResource->GetMeshes()) Renderer::SubmitMesh(m, transform.GetGlobalTransform()); @@ -197,12 +197,12 @@ namespace Nuake { RenderCommand::Disable(RendererEnum::FACE_CULL); Renderer::Flush(gBufferShader, false); - auto quakeView = scene.m_Registry.view(); + auto quakeView = scene.m_Registry.view(); for (auto e : quakeView) { - auto [transform, model, parent] = quakeView.get(e); + auto [transform, model, parent, visibility] = quakeView.get(e); - if (model.IsTransparent) + if (model.IsTransparent || !visibility.Visible) continue; for (auto& b : model.Meshes) diff --git a/Nuake/src/Scene/Components/BaseComponent.h b/Nuake/src/Scene/Components/BaseComponent.h index 6f70f09b..2e3681ad 100644 --- a/Nuake/src/Scene/Components/BaseComponent.h +++ b/Nuake/src/Scene/Components/BaseComponent.h @@ -1 +1,26 @@ #pragma once +#include "src/Resource/Serializable.h" + +struct VisibilityComponent +{ + bool Visible = true; + + json Serialize() + { + BEGIN_SERIALIZE(); + SERIALIZE_VAL(Visible); + END_SERIALIZE(); + } + + bool Deserialize(std::string str) + { + BEGIN_DESERIALIZE(); + + if (j.contains("Visible")) + { + Visible = j["Visible"]; + } + + return true; + } +}; \ No newline at end of file diff --git a/Nuake/src/Scene/Components/CharacterControllerComponent.h b/Nuake/src/Scene/Components/CharacterControllerComponent.h index ef3a55bb..b35df9b2 100644 --- a/Nuake/src/Scene/Components/CharacterControllerComponent.h +++ b/Nuake/src/Scene/Components/CharacterControllerComponent.h @@ -33,10 +33,8 @@ namespace Nuake { } void SyncWithTransform(TransformComponent& tc) { - btVector3 pos = CharacterController->m_motionTransform.getOrigin(); - glm::vec3 finalPos = glm::vec3(pos.x(), pos.y(), pos.z()); - - tc.SetLocalPosition(finalPos); + + } }; } diff --git a/Nuake/src/Scene/Components/RigidbodyComponent.cpp b/Nuake/src/Scene/Components/RigidbodyComponent.cpp index 61749eb6..96fa61fb 100644 --- a/Nuake/src/Scene/Components/RigidbodyComponent.cpp +++ b/Nuake/src/Scene/Components/RigidbodyComponent.cpp @@ -57,14 +57,7 @@ namespace Nuake { if (!m_Rigidbody) return; - btTransform newTransform; - newTransform.setIdentity(); - //newTransform.setOrigin(btVector3(tc->Translation.x, tc->Translation.t, tc->Translation.z)); - btQuaternion quat; - //quat.setEulerZYX(tc->Rotation.x, tc->Rotation.y, tc->Rotation.z); - newTransform.setRotation(quat); - m_Rigidbody->UpdateTransform(newTransform); } void RigidBodyComponent::DrawShape(TransformComponent* tc) diff --git a/Nuake/src/Scene/Entities/Entity.cpp b/Nuake/src/Scene/Entities/Entity.cpp index 07398336..c6eaf063 100644 --- a/Nuake/src/Scene/Entities/Entity.cpp +++ b/Nuake/src/Scene/Entities/Entity.cpp @@ -34,6 +34,7 @@ namespace Nuake SERIALIZE_OBJECT_REF_LBL("NameComponent", GetComponent()); SERIALIZE_OBJECT_REF_LBL("ParentComponent", GetComponent()); SERIALIZE_OBJECT_REF_LBL("TransformComponent", GetComponent()); + SERIALIZE_OBJECT_REF_LBL("VisibilityComponent", GetComponent()); if (HasComponent()) SERIALIZE_OBJECT_REF_LBL("CameraComponent", GetComponent()); if (HasComponent()) @@ -57,6 +58,11 @@ namespace Nuake { BEGIN_DESERIALIZE(); DESERIALIZE_COMPONENT(TransformComponent); + DESERIALIZE_COMPONENT(VisibilityComponent) + else + { + AddComponent(); + } DESERIALIZE_COMPONENT(NameComponent); DESERIALIZE_COMPONENT(ParentComponent); DESERIALIZE_COMPONENT(CameraComponent); diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index c1d1f885..3f2cee3a 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -191,14 +191,14 @@ namespace Nuake { { Entity entity = { m_Registry.create(), this }; entity.AddComponent(); + entity.AddComponent(); + entity.AddComponent(); NameComponent& nameComponent = entity.AddComponent(); nameComponent.Name = name; nameComponent.ID = id; - ParentComponent& parentComponent = entity.AddComponent(); - - Logger::Log("Created entity: " + nameComponent.Name + "\n"); + Logger::Log("Created entity: " + nameComponent.Name, LOG_TYPE::VERBOSE); return entity; } @@ -214,7 +214,7 @@ namespace Nuake { for (auto& c : copyChildrens) { - Logger::Log("Deleting... entity" + std::to_string(c.GetHandle())); + Logger::Log("Deleting entity " + std::to_string(c.GetHandle())); DestroyEntity(c); } @@ -318,10 +318,12 @@ namespace Nuake { } CopyComponent(sceneCopy->m_Registry, this->m_Registry); + CopyComponent(sceneCopy->m_Registry, this->m_Registry); CopyComponent(sceneCopy->m_Registry, this->m_Registry); CopyComponent(sceneCopy->m_Registry, this->m_Registry); CopyComponent(sceneCopy->m_Registry, this->m_Registry); CopyComponent(sceneCopy->m_Registry, this->m_Registry); + CopyComponent(sceneCopy->m_Registry, this->m_Registry); return sceneCopy; } diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index f1521002..2bbca37e 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -225,7 +225,6 @@ namespace Nuake { void Window::Update(Timestep ts) { - // TODO: have event here? m_Scene->Update(ts); } diff --git a/generate.bat b/generate.bat index fc462e1b..df0944fc 100644 --- a/generate.bat +++ b/generate.bat @@ -1,2 +1,2 @@ -premake5 vs2019 +premake5 vs2022 pause \ No newline at end of file diff --git a/premake5.lua b/premake5.lua index f0dada50..f4e7778b 100644 --- a/premake5.lua +++ b/premake5.lua @@ -11,9 +11,7 @@ outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}" include "Nuake/dependencies/glfw_p5.lua" include "Nuake/dependencies/assimp_p5.lua" -include "Nuake/dependencies/bullet_p5.lua" include "Nuake/dependencies/freetype_p5.lua" -include "Nuake/dependencies/soloud_p5.lua" project "Nuake" location "Nuake" @@ -55,21 +53,16 @@ project "Nuake" "%{prj.name}/../Nuake/src/Vendors", "%{prj.name}/../Nuake/Dependencies/GLEW/include", "%{prj.name}/../Nuake/Dependencies/GLFW/include", - "%{prj.name}/../Nuake/Dependencies/bullet3/src", "%{prj.name}/../Nuake/Dependencies/assimp/include", "%{prj.name}/../Nuake/Dependencies/build", "%{prj.name}/../Nuake/src/Vendors/msdfgen/include", "%{prj.name}/../Nuake/src/Vendors/msdfgen/freetype/include", "%{prj.name}/../Nuake/src/Vendors/msdfgen", "%{prj.name}/../Nuake/src/Vendors/wren/src/include", - "%(prj.name}/../Nuake/Dependencies/soloud/include" } links { - "BulletCollision", - "BulletDynamics", - "LinearMath", "Freetype" } @@ -106,7 +99,6 @@ project "Editor" "%{prj.name}/../Nuake/src/Vendors", "%{prj.name}/../Nuake/Dependencies/GLEW/include", "%{prj.name}/../Nuake/Dependencies/GLFW/include", - "%{prj.name}/../Nuake/Dependencies/bullet3/src", "%{prj.name}/../Nuake/Dependencies/assimp/include", "%{prj.name}/../Nuake/Dependencies/build", "%{prj.name}/../Nuake/src/Vendors/msdfgen" @@ -130,10 +122,7 @@ project "Editor" "GLFW", "assimp", "glew32s.lib", - "opengl32.lib", - "BulletCollision", - "BulletDynamics", - "LinearMath", + "opengl32.lib", "Freetype" }