Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ public static void Execute(ref CharacterPlatformComponent platformComponent, Vec

platformComponent.LastAvatarRelativePosition = platform.InverseTransformPoint(characterPosition);

// We only update the changed flag if a scene tick happened since last update
// We are assuming that to hit something, that game object must be part of the current scene
// if (currentScene != null && currentScene.SceneStateProvider.TickNumber > platformComponent.LastUpdateTick)
if (currentScene != null && currentScene.SceneStateProvider.State == SceneState.Running)
{
Vector3 updatedPosition = platform.position;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ protected override void Update(float t)
private void UpdateTick(ref CharacterPlatformComponent platformComponent)
{
ISceneFacade? currentScene = scenesCache.CurrentScene.Value;
platformComponent.LastUpdateTick = currentScene?.SceneStateProvider.TickNumber ?? 0;

if (currentScene != null)
{
if (currentScene.SceneStateProvider.State == SceneState.Running)
platformComponent.LastUpdateTick = currentScene.SceneStateProvider.TickNumber;
}
else
platformComponent.LastUpdateTick = 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ private void FilterHandlersIfInTeleport()
//We check if the player is teleporting, and if the scene we want to teleport to has started.
//If so, only scene metadata will be allowed to de downloaded
TeleportUtils.PlayerTeleportingState teleportParcel = TeleportUtils.GetTeleportParcel(World, playerEntity);
if (teleportParcel.IsTeleporting)
{
if (scenesCache.Contains(teleportParcel.Parcel))
downloadOnlySceneMetadata = true;
}

if (teleportParcel.IsTeleporting
&& scenesCache.TryGetByParcel(teleportParcel.Parcel, out ISceneFacade scene)
&& scene.SceneStateProvider.State == SceneState.Running)
downloadOnlySceneMetadata = true;

sameBoatQueries = downloadOnlySceneMetadata ? COMPONENT_HANDLERS_SCENES : COMPONENT_HANDLERS_SCENES_ASSETS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,26 @@ public override void Initialize()

public override void BeforeUpdate(in float t, bool throttle)
{
if (sceneStateProvider.State != SceneState.Running)
if (sceneStateProvider.State != SceneState.Running
&& sceneStateProvider.State != SceneState.Starting)
return;

BeforeUpdateInternal(in t, throttle);
}

public override void Update(in float t, bool throttle)
{
if (sceneStateProvider.State != SceneState.Running)
if (sceneStateProvider.State != SceneState.Running
&& sceneStateProvider.State != SceneState.Starting)
return;

UpdateInternal(in t, throttle);
}

public override void AfterUpdate(in float t, bool throttle)
{
if (sceneStateProvider.State != SceneState.Running)
if (sceneStateProvider.State != SceneState.Running
&& sceneStateProvider.State != SceneState.Starting)
return;

AfterUpdateInternal(in t, throttle);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using DCL.Optimization.Pools;
using DCL.Utilities;
using SceneRunner.Scene;
using System.Collections.Generic;
using UnityEngine;

Expand All @@ -21,11 +22,10 @@ public SceneReadinessReportQueue(IScenesCache scenesCache)
public void Enqueue(Vector2Int parcel, AsyncLoadProcessReport report)
{
// Shortcut
if (scenesCache.Contains(parcel))
{
if (scenesCache.TryGetByParcel(parcel, out ISceneFacade scene)
&& scene.SceneStateProvider.State == SceneState.Running)
// conclude immediately
report.SetProgress(1f);
}

if (!queue.TryGetValue(parcel, out PooledLoadReportList queuedReport))
queue[parcel] = queuedReport = new PooledLoadReportList(REPORT_POOL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

namespace ECS.SceneLifeCycle.Systems
{

/// <summary>
/// Starts the scene or changes fps of its execution
/// </summary>
Expand Down Expand Up @@ -68,7 +67,7 @@ private void HandleNotCreatedScenes(in Entity entity, ref ScenePromise promise,
if (!promise.TryConsume(World, out var result) || !result.Succeeded) return;

ISceneFacade scene = result.Asset!;
StartScene(definitionComponent, partition, scene);
StartAndUpdateSceneAsync(definitionComponent, partition, scene).Forget();

World.Add(entity, scene);
}
Expand All @@ -80,7 +79,7 @@ private void HandleSmartWearableScenes(Entity entity, in SceneDefinitionComponen
{
World.Add(entity, new SmartWearableSceneStarted());

StartScene(definitionComponent, partition, scene);
StartAndUpdateSceneAsync(definitionComponent, partition, scene).Forget();
}

[Query]
Expand All @@ -92,42 +91,33 @@ private void ChangeSceneFPS(ref ISceneFacade sceneFacade, in PartitionComponent
sceneFacade.SetTargetFPS(realmPartitionSettings.GetSceneUpdateFrequency(in partition));
}

private void StartScene(SceneDefinitionComponent definitionComponent, PartitionComponent partition, ISceneFacade scene)
private async UniTaskVoid StartAndUpdateSceneAsync(SceneDefinitionComponent definitionComponent, PartitionComponent partition, ISceneFacade scene)
{
int fps = realmPartitionSettings.GetSceneUpdateFrequency(partition);
RunOnThreadPoolAsync().Forget();

// So we know the scene has started
if (definitionComponent.IsPortableExperience)
scenesCache.AddPortableExperienceScene(scene, definitionComponent.IpfsPath.EntityId);
else
scenesCache.Add(scene, definitionComponent.Parcels);
try
{
if (definitionComponent.IsPortableExperience)
scenesCache.AddPortableExperienceScene(scene, definitionComponent.IpfsPath.EntityId);
else
scenesCache.Add(scene, definitionComponent.Parcels);
Comment thread
lorux0 marked this conversation as resolved.

ReportHub.LogProductionInfo($"Scene '{definitionComponent.Definition.GetLogSceneName()}' started");
ReportHub.LogProductionInfo($"Scene '{definitionComponent.Definition.GetLogSceneName()}' started");

return;
await DCLTask.SwitchToThreadPool();

async UniTaskVoid RunOnThreadPoolAsync()
{
try
{
await DCLTask.SwitchToThreadPool();

if (destroyCancellationToken.IsCancellationRequested) return;
if (destroyCancellationToken.IsCancellationRequested) return;

#if !UNITY_WEBGL
// Provide basic thread-pool synchronization context
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); // IGNORE_LINE_WEBGL_THREAD_SAFETY_FLAG

// Provide basic thread-pool synchronization context
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); // IGNORE_LINE_WEBGL_THREAD_SAFETY_FLAG
#endif

// FPS is set by another system
await scene.StartUpdateLoopAsync(fps, destroyCancellationToken);
}
catch (Exception e)
{
ReportHub.LogException(e, GetReportData());
}
await scene.StartUpdateLoopAsync(fps, destroyCancellationToken);
}
catch (OperationCanceledException) { }
catch (Exception e) { ReportHub.LogException(e, GetReportData()); }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ public interface ISceneFacade : IUniTaskAsyncDisposable, IDisposable

void Initialize();

/// <summary>
/// Start an update loop with a given FPS
/// </summary>
UniTask StartUpdateLoopAsync(int targetFPS, CancellationToken ct);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ISceneStateProvider

ref readonly SceneEngineStartInfo EngineStartInfo { get; }

void SetRunning(SceneEngineStartInfo startInfo);
void Start(SceneEngineStartInfo startInfo);
}

public static class SceneStateProviderExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public enum SceneState : byte
/// </summary>
Running,

Starting,

/// <summary>
/// Scene communication has broken
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class SceneStateProvider : ISceneStateProvider

public ref readonly SceneEngineStartInfo EngineStartInfo => ref engineStartInfo;

public void SetRunning(SceneEngineStartInfo startInfo)
public void Start(SceneEngineStartInfo startInfo)
{
State.Set(SceneState.Running);
State.Set(SceneState.Starting);
engineStartInfo = startInfo;
TickNumber = 0;
}
Expand Down
Loading
Loading