Skip to content

Commit

Permalink
Merge pull request #362 from TheMadDodger/physics-module-base
Browse files Browse the repository at this point in the history
Add physics module base and inherit it in Jolt module
  • Loading branch information
TheMadDodger committed Jun 24, 2024
2 parents 36c9b25 + d55d2db commit 630f20f
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "EntityComponentEditor.h"
#include <Gizmos.h>
#include <JoltComponents.h>
#include <PhysicsComponents.h>

namespace Glory::Editor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <JoltPhysicsModule.h>
#include <GLORY_YAML.h>
#include <CreateEntityObjectsCallbacks.h>
#include <JoltComponents.h>
#include <PhysicsComponents.h>

#include <PhysicsBodyEditor.h>
#include <CharacterControllerEditor.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <EntityComponentEditor.h>
#include <JoltComponents.h>
#include <PhysicsComponents.h>
#include <Gizmos.h>

namespace Glory::Editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ project "JoltEditorExtension"
includedirs
{
"%{DepsIncludeDir}",
"%{BaseIncludeDir.physics}",

"%{IncludeDir.glm}",

Expand Down
28 changes: 28 additions & 0 deletions GloryEngine/Modules/Base/GloryPhysicsModule/PhysicsModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "PhysicsModule.h"
#include "PhysicsComponents.h"

#include <GloryECS/EntityRegistry.h>
#include <GloryECS/EntityView.h>

#include <Engine.h>
#include <SceneManager.h>

namespace Glory
{
PhysicsModule::PhysicsModule() {}
PhysicsModule::~PhysicsModule() {}

const std::type_info& PhysicsModule::GetBaseModuleType()
{
return typeid(PhysicsModule);
}

void PhysicsModule::Initialize()
{
Reflect::SetReflectInstance(&m_pEngine->Reflection());
Reflect::RegisterEnum<BodyType>();

m_pEngine->GetSceneManager()->RegisterComponent<PhysicsBody>();
m_pEngine->GetSceneManager()->RegisterComponent<CharacterController>();
}
}
24 changes: 24 additions & 0 deletions GloryEngine/Modules/Base/GloryPhysicsModule/PhysicsModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include <Module.h>

#include <functional>

namespace Glory
{
/** @brief Base class for audio backend and mixing modules */
class PhysicsModule : public Module
{
public:
/** @brief Constructor */
PhysicsModule();
/** @brief Destructor */
virtual ~PhysicsModule();

/** @brief PhysicsModule type */
const std::type_info& GetBaseModuleType() override;

protected:
virtual void Initialize() override;
virtual void Cleanup() = 0;
};
}
67 changes: 67 additions & 0 deletions GloryEngine/Modules/Base/GloryPhysicsModule/premake5.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
project "GloryPhysicsModule"
kind "StaticLib"
language "C++"
cppdialect "C++17"
staticruntime "Off"

targetdir ("%{moduleBaseOutDir}")
objdir ("%{outputDir}")

files
{
"**.h",
"**.cpp",
"premake5.lua",
}

vpaths
{

}

includedirs
{
"%{DepsIncludeDir}",

"%{IncludeDir.glm}",
"%{GloryIncludeDir.core}",
"%{IncludeDir.Reflect}",
"%{IncludeDir.Version}",
"%{IncludeDir.Utils}",
"%{IncludeDir.ECS}",

"%{IncludeDir.yaml_cpp}",

"%{DepIncludesDir}",
}

defines
{
"GLORY_EXPORTS"
}

filter "system:windows"
systemversion "10.0.19041.0"
toolset "v143"

defines
{
"_LIB"
}

filter "platforms:Win32"
architecture "x86"
defines "WIN32"

filter "platforms:x64"
architecture "x64"

filter "configurations:Debug"
runtime "Debug"
defines "_DEBUG"
symbols "On"

filter "configurations:Release"
runtime "Release"
defines "NDEBUG"
optimize "On"
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "CharacterControllerSystem.h"
#include "JoltPhysicsModule.h"
#include "JoltComponents.h"
#include "JoltCharacterManager.h"
#include "JoltShapeManager.h"
#include "JoltPhysicsModule.h"
Expand All @@ -9,6 +8,7 @@
#include <Engine.h>
#include <GScene.h>
#include <SceneManager.h>
#include <PhysicsComponents.h>

#include <Components.h>
#include <Engine.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "Physics.h"
#include <Physics.h>

#include <map>
#include <cstdint>
Expand Down
8 changes: 3 additions & 5 deletions GloryEngine/Modules/GloryJoltPhysics/JoltPhysicsModule.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "JoltPhysicsModule.h"
#include "Helpers.h"

#include "JoltComponents.h"
#include "PhysicsSystem.h"
#include "CharacterControllerSystem.h"

Expand Down Expand Up @@ -37,6 +36,7 @@
#include <Engine.h>
#include <SceneManager.h>
#include <BinaryStream.h>
#include <PhysicsComponents.h>


using namespace JPH;
Expand Down Expand Up @@ -605,6 +605,8 @@ namespace Glory

void JoltPhysicsModule::Initialize()
{
PhysicsModule::Initialize();

m_ObjectVSBroadPhase.m_pLayers = &m_pEngine->GetLayerManager();

Reflect::SetReflectInstance(&m_pEngine->Reflection());
Expand Down Expand Up @@ -658,12 +660,8 @@ namespace Glory
// Instead insert all new objects in batches instead of 1 at a time to keep the broad phase efficient.
//m_pJPHPhysicsSystem->OptimizeBroadPhase();

Reflect::RegisterEnum<BodyType>();

SceneManager* pScenes = m_pEngine->GetSceneManager();
Glory::Utils::ECS::ComponentTypes* pComponentTypes = pScenes->ComponentTypesInstance();
pScenes->RegisterComponent<PhysicsBody>();
pScenes->RegisterComponent<CharacterController>();

/* Physics Bodies */
pComponentTypes->RegisterInvokaction<PhysicsBody>(Glory::Utils::ECS::InvocationType::Start, PhysicsSystem::OnStart);
Expand Down
6 changes: 3 additions & 3 deletions GloryEngine/Modules/GloryJoltPhysics/JoltPhysicsModule.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "Physics.h"
#include <Physics.h>

#include <Module.h>
#include <PhysicsModule.h>
#include <glm/fwd.hpp>

namespace JPH
Expand Down Expand Up @@ -39,7 +39,7 @@ namespace Glory
class JoltCharacterManager;
class JoltShapeManager;

class JoltPhysicsModule : public Module
class JoltPhysicsModule : public PhysicsModule
{
public:
GLORY_API JoltPhysicsModule();
Expand Down
2 changes: 1 addition & 1 deletion GloryEngine/Modules/GloryJoltPhysics/PhysicsSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "JoltPhysicsModule.h"
#include "JoltPhysicsModule.h"
#include "JoltComponents.h"

#include <PhysicsComponents.h>
#include <PhysicsSystem.h>
#include <Engine.h>
#include <GScene.h>
Expand Down
4 changes: 4 additions & 0 deletions GloryEngine/Modules/GloryJoltPhysics/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ project "GloryJoltPhysics"
{
"%{DepsIncludeDir}",
"%{IncludeDir.glm}",
"%{BaseIncludeDir.physics}",

"%{GloryIncludeDir.core}",

Expand All @@ -54,11 +55,14 @@ project "GloryJoltPhysics"
"%{LibDirs.glory}",

"%{LibDirs.yaml_cpp}",

"{moduleBaseOutDir}",
}

links
{
"GloryCore",
"GloryPhysicsModule",
"GloryReflect",
"GloryECS",

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "PhysicsComponentsCSAPI.h"
#include "JoltPhysicsModule.h"
#include "JoltComponents.h"
#include "JoltCharacterManager.h"
#include "JoltShapeManager.h"

#include <PhysicsComponents.h>
#include <EntityCSAPI.h>
#include <cstdint>
#include <UUID.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ project "GloryJoltMonoExtender"
includedirs
{
"%{DepsIncludeDir}",
"%{BaseIncludeDir.physics}",

"%{IncludeDir.glm}",
"%{IncludeDir.yaml_cpp}",
Expand Down
2 changes: 2 additions & 0 deletions GloryEngine/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ GloryIncludeDir["threads"] = "%{engineDir}/Threads"

BaseIncludeDir = {}
BaseIncludeDir["audio"] = "%{modulesDir}/Base/GloryAudioModule"
BaseIncludeDir["physics"] = "%{modulesDir}/Base/GloryPhysicsModule"

SubmodoleDirs = {}
SubmodoleDirs["ImGui"] = "%{rootDir}/submodules/ImGui"
Expand Down Expand Up @@ -138,6 +139,7 @@ group ""

group "Modules/Base"
include "Modules/Base/GloryAudioModule"
include "Modules/Base/GloryPhysicsModule"
group ""

group "Editor"
Expand Down

0 comments on commit 630f20f

Please sign in to comment.