Adds feature for creating multiple physics scenes
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "Engine/Debug/Exceptions/JsonParseException.h"
|
||||
#include "Engine/Graphics/RenderTask.h"
|
||||
#include "Engine/Graphics/RenderView.h"
|
||||
#include "Engine/Physics/Physics.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Scripting/Scripting.h"
|
||||
#include "Engine/Serialization/ISerializeModifier.h"
|
||||
@@ -77,6 +78,7 @@ Actor::Actor(const SpawnParams& params)
|
||||
, _transform(Transform::Identity)
|
||||
, _sphere(BoundingSphere::Empty)
|
||||
, _box(BoundingBox::Zero)
|
||||
, _physicsScene(nullptr)
|
||||
, HideFlags(HideFlags::None)
|
||||
{
|
||||
}
|
||||
@@ -1809,3 +1811,26 @@ void Actor::FromJson(const StringAnsiView& json)
|
||||
Scripting::ObjectsLookupIdMapping.Set(nullptr);
|
||||
OnTransformChanged();
|
||||
}
|
||||
|
||||
void Actor::SetPhysicsScene(PhysicsScene* scene)
|
||||
{
|
||||
ASSERT(scene);
|
||||
|
||||
auto previous = GetPhysicsScene();
|
||||
_physicsScene = scene;
|
||||
|
||||
if (previous != _physicsScene)
|
||||
OnPhysicsSceneChanged(previous);
|
||||
|
||||
// cascade
|
||||
for (auto child : Children)
|
||||
child->SetPhysicsScene(scene);
|
||||
}
|
||||
|
||||
PhysicsScene* Actor::GetPhysicsScene()
|
||||
{
|
||||
if (_physicsScene == nullptr)
|
||||
_physicsScene = Physics::DefaultScene;
|
||||
|
||||
return _physicsScene;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ struct RenderView;
|
||||
struct RenderContext;
|
||||
class GPUContext;
|
||||
class MemoryWriteStream;
|
||||
class PhysicsScene;
|
||||
class SceneRendering;
|
||||
class SceneRenderTask;
|
||||
|
||||
@@ -47,6 +48,7 @@ protected:
|
||||
BoundingSphere _sphere;
|
||||
BoundingBox _box;
|
||||
String _name;
|
||||
PhysicsScene* _physicsScene;
|
||||
|
||||
private:
|
||||
|
||||
@@ -959,6 +961,20 @@ public:
|
||||
/// <returns>The scene rendering interface.</returns>
|
||||
SceneRendering* GetSceneRendering() const;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Set the physics world the controller is part of.
|
||||
/// </summary>
|
||||
API_PROPERTY(Attributes="HideInEditor") void SetPhysicsScene(PhysicsScene* scene);
|
||||
|
||||
/// <summary>
|
||||
/// Get the physics world the controller is part of.
|
||||
/// </summary>
|
||||
API_PROPERTY(Attributes="HideInEditor") PhysicsScene* GetPhysicsScene();
|
||||
|
||||
protected:
|
||||
virtual void OnPhysicsSceneChanged(PhysicsScene* previous) {};
|
||||
|
||||
private:
|
||||
|
||||
void SetSceneInHierarchy(Scene* scene);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Scripting/Script.h"
|
||||
#include "Engine/Engine/Time.h"
|
||||
#include "Engine/Physics/Physics.h"
|
||||
#include "Engine/Scripting/ManagedCLR/MAssembly.h"
|
||||
#include "Engine/Scripting/ManagedCLR/MClass.h"
|
||||
#include "Engine/Scripting/ManagedCLR/MDomain.h"
|
||||
@@ -164,6 +165,8 @@ bool LevelImpl::spawnActor(Actor* actor, Actor* parent)
|
||||
}
|
||||
if (parent == nullptr)
|
||||
parent = Level::Scenes[0];
|
||||
|
||||
actor->SetPhysicsScene(parent->GetPhysicsScene());
|
||||
actor->SetParent(parent, true, true);
|
||||
}
|
||||
|
||||
@@ -776,6 +779,8 @@ bool LevelImpl::unloadScene(Scene* scene)
|
||||
// Force flush deleted objects so we actually delete unloaded scene objects (prevent from reloading their managed objects, etc.)
|
||||
ObjectsRemovalService::Flush();
|
||||
|
||||
Physics::EndPlay();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1026,6 +1031,8 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
|
||||
{
|
||||
PROFILE_CPU_NAMED("BeginPlay");
|
||||
|
||||
Physics::BeginPlay();
|
||||
|
||||
ScopeLock lock(ScenesLock);
|
||||
Scenes.Add(scene);
|
||||
SceneBeginData beginData;
|
||||
|
||||
Reference in New Issue
Block a user