Cleanup code in #1367 and fix api compatibility, revert joint changes
This commit is contained in:
@@ -66,7 +66,7 @@ void AudioListener::OnTransformChanged()
|
|||||||
_box = BoundingBox(_transform.Translation);
|
_box = BoundingBox(_transform.Translation);
|
||||||
_sphere = BoundingSphere(_transform.Translation, 0.0f);
|
_sphere = BoundingSphere(_transform.Translation, 0.0f);
|
||||||
|
|
||||||
if (IsActiveInHierarchy())
|
if (IsActiveInHierarchy() && IsDuringPlay())
|
||||||
{
|
{
|
||||||
AudioBackend::Listener::TransformChanged(this);
|
AudioBackend::Listener::TransformChanged(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ void EnvironmentProbe::OnTransformChanged()
|
|||||||
|
|
||||||
UpdateBounds();
|
UpdateBounds();
|
||||||
|
|
||||||
if (IsDuringPlay() && UpdateMode == ProbeUpdateMode::WhenMoved)
|
if (IsActiveInHierarchy() && IsDuringPlay() && UpdateMode == ProbeUpdateMode::WhenMoved)
|
||||||
{
|
{
|
||||||
Bake(1.0f);
|
Bake(1.0f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -993,7 +993,7 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
|
|||||||
|
|
||||||
// /\ all above this has to be done on an any thread
|
// /\ all above this has to be done on an any thread
|
||||||
// \/ all below this has to be done on multiple threads at once
|
// \/ all below this has to be done on multiple threads at once
|
||||||
|
|
||||||
{
|
{
|
||||||
PROFILE_CPU_NAMED("Deserialize");
|
PROFILE_CPU_NAMED("Deserialize");
|
||||||
|
|
||||||
@@ -1001,10 +1001,11 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
|
|||||||
|
|
||||||
// Load all scene objects
|
// Load all scene objects
|
||||||
Scripting::ObjectsLookupIdMapping.Set(&modifier.Value->IdsMapping);
|
Scripting::ObjectsLookupIdMapping.Set(&modifier.Value->IdsMapping);
|
||||||
|
SceneObject** objects = sceneObjects->Get();
|
||||||
for (int32 i = 1; i < objectsCount; i++) // start from 1. at index [0] was scene
|
for (int32 i = 1; i < objectsCount; i++) // start from 1. at index [0] was scene
|
||||||
{
|
{
|
||||||
auto& objData = data[i];
|
auto& objData = data[i];
|
||||||
auto obj = sceneObjects->At(i);
|
auto obj = objects[i];
|
||||||
if (obj)
|
if (obj)
|
||||||
SceneObjectsFactory::Deserialize(context, obj, objData);
|
SceneObjectsFactory::Deserialize(context, obj, objData);
|
||||||
}
|
}
|
||||||
@@ -1016,7 +1017,6 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
|
|||||||
|
|
||||||
// Synchronize prefab instances (prefab may have objects removed or reordered so deserialized instances need to synchronize with it)
|
// Synchronize prefab instances (prefab may have objects removed or reordered so deserialized instances need to synchronize with it)
|
||||||
// TODO: resave and force sync scenes during game cooking so this step could be skipped in game
|
// TODO: resave and force sync scenes during game cooking so this step could be skipped in game
|
||||||
|
|
||||||
SceneObjectsFactory::SynchronizePrefabInstances(context, prefabSyncData);
|
SceneObjectsFactory::SynchronizePrefabInstances(context, prefabSyncData);
|
||||||
|
|
||||||
// Cache transformations
|
// Cache transformations
|
||||||
@@ -1030,9 +1030,10 @@ bool Level::loadScene(rapidjson_flax::Value& data, int32 engineBuild, Scene** ou
|
|||||||
{
|
{
|
||||||
PROFILE_CPU_NAMED("Initialize");
|
PROFILE_CPU_NAMED("Initialize");
|
||||||
|
|
||||||
|
SceneObject** objects = sceneObjects->Get();
|
||||||
for (int32 i = 0; i < sceneObjects->Count(); i++)
|
for (int32 i = 0; i < sceneObjects->Count(); i++)
|
||||||
{
|
{
|
||||||
SceneObject* obj = sceneObjects->At(i);
|
SceneObject* obj = objects[i];
|
||||||
if (obj)
|
if (obj)
|
||||||
{
|
{
|
||||||
obj->Initialize();
|
obj->Initialize();
|
||||||
@@ -1498,7 +1499,7 @@ Array<Actor*> Level::FindActors(const Tag& tag, const bool activeOnly, Actor* ro
|
|||||||
{
|
{
|
||||||
ScopeLock lock(ScenesLock);
|
ScopeLock lock(ScenesLock);
|
||||||
for (Scene* scene : Scenes)
|
for (Scene* scene : Scenes)
|
||||||
FindActorsRecursive(scene, tag, activeOnly, result);
|
FindActorsRecursive(scene, tag, activeOnly, result);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1221,7 +1221,7 @@ bool Prefab::SyncChangesInternal(PrefabInstancesData& prefabInstancesData)
|
|||||||
{
|
{
|
||||||
ScopeLock lock(Locker);
|
ScopeLock lock(Locker);
|
||||||
_isCreatingDefaultInstance = true;
|
_isCreatingDefaultInstance = true;
|
||||||
_defaultInstance = PrefabManager::SpawnPrefab(this,Transform::Identity, nullptr, &ObjectsCache, true);
|
_defaultInstance = PrefabManager::SpawnPrefab(this, Transform::Identity, nullptr, &ObjectsCache, true);
|
||||||
_isCreatingDefaultInstance = false;
|
_isCreatingDefaultInstance = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ Guid Prefab::GetRootObjectId() const
|
|||||||
if (prefabObjectId == basePrefabRootId)
|
if (prefabObjectId == basePrefabRootId)
|
||||||
{
|
{
|
||||||
objectIndex = i;
|
objectIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ PrefabManagerService PrefabManagerServiceInstance;
|
|||||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab)
|
Actor* PrefabManager::SpawnPrefab(Prefab* prefab)
|
||||||
{
|
{
|
||||||
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
|
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
|
||||||
return SpawnPrefab(prefab,Transform::Identity, parent, nullptr);
|
return SpawnPrefab(prefab, Transform::Identity, parent, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Vector3& position)
|
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Vector3& position)
|
||||||
@@ -65,11 +65,23 @@ Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Transform& transform)
|
|||||||
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
|
Actor* parent = Level::Scenes.Count() != 0 ? Level::Scenes.Get()[0] : nullptr;
|
||||||
return SpawnPrefab(prefab, transform, parent, nullptr);
|
return SpawnPrefab(prefab, transform, parent, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent, const Transform& transform)
|
||||||
|
{
|
||||||
|
return SpawnPrefab(prefab, transform, parent, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent)
|
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent)
|
||||||
{
|
{
|
||||||
return SpawnPrefab(prefab, Transform::Identity, parent, nullptr);
|
return SpawnPrefab(prefab, Transform::Identity, parent, nullptr);
|
||||||
}
|
}
|
||||||
Actor* PrefabManager::SpawnPrefab(Prefab* prefab,const Transform& transform, Actor* parent, Dictionary<Guid, const void*>* objectsCache, bool withSynchronization)
|
|
||||||
|
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid, const void*>* objectsCache, bool withSynchronization)
|
||||||
|
{
|
||||||
|
return SpawnPrefab(prefab, Transform::Identity, parent, objectsCache, withSynchronization);
|
||||||
|
}
|
||||||
|
|
||||||
|
Actor* PrefabManager::SpawnPrefab(Prefab* prefab, const Transform& transform, Actor* parent, Dictionary<Guid, const void*>* objectsCache, bool withSynchronization)
|
||||||
{
|
{
|
||||||
PROFILE_CPU_NAMED("Prefab.Spawn");
|
PROFILE_CPU_NAMED("Prefab.Spawn");
|
||||||
if (prefab == nullptr)
|
if (prefab == nullptr)
|
||||||
@@ -178,7 +190,7 @@ Actor* PrefabManager::SpawnPrefab(Prefab* prefab,const Transform& transform, Act
|
|||||||
if (parent)
|
if (parent)
|
||||||
parent->Children.Add(root);
|
parent->Children.Add(root);
|
||||||
|
|
||||||
//move root to right location
|
// Move root to the right location
|
||||||
if (transform != Transform::Identity)
|
if (transform != Transform::Identity)
|
||||||
root->SetTransform(transform);
|
root->SetTransform(transform);
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,15 @@ API_CLASS(Static) class FLAXENGINE_API PrefabManager
|
|||||||
/// <returns>The created actor (root) or null if failed.</returns>
|
/// <returns>The created actor (root) or null if failed.</returns>
|
||||||
API_FUNCTION() static Actor* SpawnPrefab(Prefab* prefab, const Transform& transform);
|
API_FUNCTION() static Actor* SpawnPrefab(Prefab* prefab, const Transform& transform);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Spawns the instance of the prefab objects. Prefab will be spawned to the first loaded scene.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prefab">The prefab asset.</param>
|
||||||
|
/// <param name="parent">The parent actor to add spawned object instance. Can be null to just deserialize contents of the prefab.</param>
|
||||||
|
/// <param name="transform">The spawn transformation in the world space.</param>
|
||||||
|
/// <returns>The created actor (root) or null if failed.</returns>
|
||||||
|
API_FUNCTION() static Actor* SpawnPrefab(Prefab* prefab, Actor* parent, const Transform& transform);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Spawns the instance of the prefab objects. If parent actor is specified then created actors are fully initialized (OnLoad event and BeginPlay is called if parent actor is already during gameplay).
|
/// Spawns the instance of the prefab objects. If parent actor is specified then created actors are fully initialized (OnLoad event and BeginPlay is called if parent actor is already during gameplay).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -72,6 +81,16 @@ API_CLASS(Static) class FLAXENGINE_API PrefabManager
|
|||||||
/// <returns>The created actor (root) or null if failed.</returns>
|
/// <returns>The created actor (root) or null if failed.</returns>
|
||||||
API_FUNCTION() static Actor* SpawnPrefab(Prefab* prefab, Actor* parent);
|
API_FUNCTION() static Actor* SpawnPrefab(Prefab* prefab, Actor* parent);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Spawns the instance of the prefab objects. If parent actor is specified then created actors are fully initialized (OnLoad event and BeginPlay is called if parent actor is already during gameplay).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prefab">The prefab asset.</param>
|
||||||
|
/// <param name="parent">The parent actor to add spawned object instance. Can be null to just deserialize contents of the prefab.</param>
|
||||||
|
/// <param name="objectsCache">The options output objects cache that can be filled with prefab object id mapping to deserialized object (actor or script).</param>
|
||||||
|
/// <param name="withSynchronization">True if perform prefab changes synchronization for the spawned objects. It will check if need to add new objects due to nested prefab modifications.</param>
|
||||||
|
/// <returns>The created actor (root) or null if failed.</returns>
|
||||||
|
static Actor* SpawnPrefab(Prefab* prefab, Actor* parent, Dictionary<Guid, const void*, HeapAllocation>* objectsCache, bool withSynchronization = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Spawns the instance of the prefab objects. If parent actor is specified then created actors are fully initialized (OnLoad event and BeginPlay is called if parent actor is already during gameplay).
|
/// Spawns the instance of the prefab objects. If parent actor is specified then created actors are fully initialized (OnLoad event and BeginPlay is called if parent actor is already during gameplay).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -803,7 +803,7 @@ void InvokeObjectSpawn(const NetworkMessageObjectSpawn& msgData, const NetworkMe
|
|||||||
NETWORK_REPLICATOR_LOG(Error, "[NetworkReplicator] Failed to find prefab {}", msgData.PrefabId.ToString());
|
NETWORK_REPLICATOR_LOG(Error, "[NetworkReplicator] Failed to find prefab {}", msgData.PrefabId.ToString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prefabInstance = PrefabManager::SpawnPrefab(prefab, nullptr, nullptr);
|
prefabInstance = PrefabManager::SpawnPrefab(prefab, Transform::Identity, nullptr, nullptr);
|
||||||
if (!prefabInstance)
|
if (!prefabInstance)
|
||||||
{
|
{
|
||||||
NETWORK_REPLICATOR_LOG(Error, "[NetworkReplicator] Failed to spawn object type {}", msgData.PrefabId.ToString());
|
NETWORK_REPLICATOR_LOG(Error, "[NetworkReplicator] Failed to spawn object type {}", msgData.PrefabId.ToString());
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ void Joint::Create()
|
|||||||
if (_enableAutoAnchor && target)
|
if (_enableAutoAnchor && target)
|
||||||
{
|
{
|
||||||
// Place target anchor at the joint location
|
// Place target anchor at the joint location
|
||||||
desc.Pos1 = (Target->GetOrientation() * (GetPosition() - Target->GetPosition())) + Target->GetPosition();
|
desc.Pos1 = Target->GetTransform().WorldToLocal(GetPosition());
|
||||||
desc.Rot1 = WorldToLocal(Target->GetOrientation(), GetOrientation());
|
desc.Rot1 = WorldToLocal(Target->GetOrientation(), GetOrientation());
|
||||||
}
|
}
|
||||||
_joint = CreateJoint(desc);
|
_joint = CreateJoint(desc);
|
||||||
@@ -197,9 +197,8 @@ Vector3 Joint::GetTargetPosition() const
|
|||||||
if (Target)
|
if (Target)
|
||||||
{
|
{
|
||||||
if (_enableAutoAnchor)
|
if (_enableAutoAnchor)
|
||||||
position = (Target->GetOrientation() * (GetPosition() - Target->GetPosition())) + Target->GetPosition();
|
position = Target->GetTransform().WorldToLocal(GetPosition());
|
||||||
else
|
position = Target->GetOrientation() * position + Target->GetPosition();
|
||||||
position = Target->GetOrientation() * position + Target->GetPosition();
|
|
||||||
}
|
}
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user