Skip to content

refactor : Discard FastList Completely #2798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion sources/core/Stride.Core/Collections/IndexingDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Stride.Core.Collections;
[DataSerializer(typeof(IndexingDictionarySerializer<>), Mode = DataSerializerGenericMode.GenericArguments)]
public class IndexingDictionary<T> : IDictionary<int, T> where T : class
{
private readonly FastList<T?> items = [];
private readonly List<T?> items = [];
private List<int>? keys;
private List<T>? values;

Expand Down
5 changes: 0 additions & 5 deletions sources/core/Stride.Core/Threading/Dispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,6 @@ public static void Sort<T>(ConcurrentCollector<T> collection, IComparer<T> compa
Sort(collection.Items, 0, collection.Count, comparer);
}

public static void Sort<T>(FastList<T> collection, IComparer<T> comparer)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I delete this, because the method is 0 used , and if deleted , the scripts will easier to maintain , if not it will cause misunderstandings to others

{
Sort(collection.Items, 0, collection.Count, comparer);
}

public static void Sort<T>(T[] collection, int index, int length, IComparer<T> comparer)
{
using var _ = Profiler.Begin(DispatcherSortKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Task UpdateLightProbeCoefficients()
}

/// <inheritdoc/>
public Task<Dictionary<Guid, FastList<Color3>>> RequestLightProbesStep()
public Task<Dictionary<Guid, List<Color3>>> RequestLightProbesStep()
{
return editor.Controller.InvokeAsync(() =>
{
Expand All @@ -89,7 +89,7 @@ public Task<Dictionary<Guid, FastList<Color3>>> RequestLightProbesStep()
// Note: we only process first LightProbeProcessor
var runtimeData = game.SceneSystem.SceneInstance.GetProcessor<LightProbeProcessor>()?.VisibilityGroup.Tags.Get(LightProbeRenderer.CurrentLightProbes);
if (runtimeData == null)
return new Dictionary<Guid, FastList<Color3>>();
return new Dictionary<Guid, List<Color3>>();

var editorCompositor = game.EditorSceneSystem.GraphicsCompositor.Game;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface IEditorGameLightProbeService : IEditorGameViewModelService
/// </summary>
/// <remarks>This won't reset light probe coefficients.</remarks>
/// <returns></returns>
Task<Dictionary<Guid, FastList<Color3>>> RequestLightProbesStep();
Task<Dictionary<Guid, List<Color3>>> RequestLightProbesStep();

/// <summary>
/// Transfers light probes coefficients by calling <see cref="LightProbeProcessor.UpdateLightProbeCoefficients"/> (from <see cref="LightProbeComponent.Coefficients"/> to <see cref="LightProbeRuntimeData.Coefficients"/>).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Stride.Core.Assets.Editor.Services;
using System.Collections.Generic;
using Stride.Core.Annotations;
using Stride.Core.Collections;
using Stride.Core.Extensions;
using Stride.Core.Mathematics;
using Stride.Core.Presentation.Commands;
using Stride.Core.Presentation.Services;
using Stride.Core.Presentation.ViewModels;
using Stride.Assets.Presentation.AssetEditors.EntityHierarchyEditor.Services;
using Stride.Assets.Presentation.AssetEditors.GameEditor.Services;
using Stride.Engine;
using Stride.Graphics;
using Stride.Rendering.LightProbes;
using Stride.Core.Presentation.ViewModels;

namespace Stride.Assets.Presentation.AssetEditors.EntityHierarchyEditor.ViewModels
{
Expand Down Expand Up @@ -71,7 +70,7 @@ private async Task RebuildLightProbes(int bounces)
{
// Find this light probe in Quantum
var assetNode = editor.NodeContainer.GetOrCreateNode(lightProbe);
var zeroCoefficients = new FastList<Color3>();
var zeroCoefficients = new List<Color3>();
for (int i = 0; i < LightProbeGenerator.LambertHamonicOrder * LightProbeGenerator.LambertHamonicOrder; ++i)
zeroCoefficients.Add(default(Color3));
assetNode[nameof(LightProbeComponent.Coefficients)].Update(zeroCoefficients);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Runtime.InteropServices;
using Stride.Core.Mathematics;
using Stride.Assets.Presentation.AssetEditors.EntityHierarchyEditor.Game;
using Stride.Engine;
using Stride.Engine.Gizmos;
using Stride.Extensions;
using Stride.Graphics;
using Stride.Graphics.GeometricPrimitives;
using Stride.Rendering;
using Stride.Rendering.LightProbes;
Expand Down Expand Up @@ -77,7 +77,10 @@ public override void Update()
base.Update();

if (Component.Coefficients != null)
lightProbeMaterial.Passes[0].Parameters.Set(ComputeSphericalHarmonicsKeys.SphericalColors, Component.Coefficients.Count, ref Component.Coefficients.Items[0]);
{
var coefficientsSpan = CollectionsMarshal.AsSpan(Component.Coefficients);
lightProbeMaterial.Passes[0].Parameters.Set(ComputeSphericalHarmonicsKeys.SphericalColors, Component.Coefficients.Count, ref coefficientsSpan[0]);
}
}

class ComputeSphericalHarmonics : ComputeValueBase<Color4>, IComputeColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private AnimationClip SubtractAnimations(AnimationClip baseAnimation, AnimationC

var resultEvaluator = animationBlender.CreateEvaluator(resultAnimation);

var animationOperations = new FastList<AnimationOperation>();
var animationOperations = new List<AnimationOperation>();

// Perform animation blending for each frame and upload results in a new animation
// Note that it does a simple per-frame sampling, so animation discontinuities will be lost.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Stride.Core.BuildEngine;
using Stride.Core.Collections;
using Stride.Core.Extensions;
Expand Down Expand Up @@ -158,7 +159,7 @@ private unsafe object ExportAnimation(ICommandContext commandContext, ContentMan
var animationKeys = animationKeysSet.ToList();
animationKeys.Sort();

var animationOperations = new FastList<AnimationOperation>();
var animationOperations = new List<AnimationOperation>();

var combinedAnimationClip = new AnimationClip();

Expand Down Expand Up @@ -241,11 +242,12 @@ private unsafe object ExportAnimation(ICommandContext commandContext, ContentMan
{
// Translate node with parent 0 using PivotPosition
var keyFrames = ((AnimationCurve<Vector3>)curve).KeyFrames;
var keyFramesSpan = CollectionsMarshal.AsSpan(keyFrames);
for (int i = 0; i < keyFrames.Count; ++i)
{
if (parentNodeIndex == 0)
keyFrames.Items[i].Value -= PivotPosition;
keyFrames.Items[i].Value *= ScaleImport;
keyFramesSpan[i].Value -= PivotPosition;
keyFramesSpan[i].Value *= ScaleImport;
}
}
animationClip.AddCurve($"[ModelComponent.Key].Skeleton.NodeTransformations[{skeletonMapping.SourceToTarget[nodeIndex]}]." + channelName, curve);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TestBowyerWatsonTetrahedralization
public void TestCube()
{
// Build cube from (0,0,0) to (1,1,1)
var positions = new FastList<Vector3>();
var positions = new List<Vector3>();
for (int i = 0; i < 8; ++i)
{
positions.Add(new Vector3
Expand Down
6 changes: 3 additions & 3 deletions sources/engine/Stride.Engine/Animations/AnimationBlender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ public static unsafe void Blend(CoreAnimationOperation blendOperation, float ble
/// </summary>
/// <param name="animationOperations">The animation operations to perform.</param>
/// <param name="result">The optional result (if not null, it expects the final stack to end up with this element).</param>
public void Compute(FastList<AnimationOperation> animationOperations, ref AnimationClipResult result)
public void Compute(List<AnimationOperation> animationOperations, ref AnimationClipResult result)
{
// Clear animation stack
animationStack.Clear();

// Apply first operation (should be a push), directly into result (considered first item in the stack)
var animationOperation0 = animationOperations.Items[0];
var animationOperation0 = animationOperations[0];

if (animationOperation0.Type != AnimationOperationType.Push)
throw new InvalidOperationException("First operation should be a push");
Expand Down Expand Up @@ -335,7 +335,7 @@ public void Compute(FastList<AnimationOperation> animationOperations, ref Animat

for (int index = 1; index < animationOperations.Count; index++)
{
var animationOperation = animationOperations.Items[index];
var animationOperation = animationOperations[index];

ApplyAnimationOperation(ref animationOperation);
}
Expand Down
6 changes: 3 additions & 3 deletions sources/engine/Stride.Engine/Animations/AnimationCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class AnimationCurve<T> : AnimationCurve
/// <value>
/// The key frames.
/// </value>
public FastList<KeyFrameData<T>> KeyFrames { get; set; }
public List<KeyFrameData<T>> KeyFrames { get; set; }

/// <inheritdoc/>
[DataMemberIgnore]
Expand All @@ -107,7 +107,7 @@ public override IReadOnlyList<CompressedTimeSpan> Keys

public AnimationCurve()
{
KeyFrames = new FastList<KeyFrameData<T>>();
KeyFrames = [];
}

/// <summary>
Expand Down Expand Up @@ -157,7 +157,7 @@ internal override AnimationData CreateOptimizedData(IEnumerable<KeyValuePair<str
/// <inheritdoc/>
public override void ShiftKeys(CompressedTimeSpan shiftTimeSpan)
{
var shiftedKeyFrames = new FastList<KeyFrameData<T>>();
var shiftedKeyFrames = new List<KeyFrameData<T>>();

foreach (var keyFrameData in KeyFrames)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected override unsafe void ProcessChannel(ref Channel channel, CompressedTim
var keyFrames = channel.Curve.KeyFrames;
var currentIndex = channel.CurrentIndex;

Unsafe.AsRef<T>((void*)(location + channel.Offset)) = keyFrames.Items[currentIndex].Value;
Unsafe.AsRef<T>((void*)(location + channel.Offset)) = keyFrames[currentIndex].Value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@

using System;
using Stride.Core.Mathematics;
using System.Runtime.InteropServices;

namespace Stride.Animations
{
public class AnimationCurveEvaluatorDirectFloatGroup : AnimationCurveEvaluatorDirectBlittableGroupBase<float>
{
protected unsafe override void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I Adjusted the location with unsafe and unsafe

protected override unsafe void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)
{
SetTime(ref channel, newTime);

var currentTime = channel.CurrentTime;
var currentIndex = channel.CurrentIndex;

var keyFrames = channel.Curve.KeyFrames;
var keyFramesItems = keyFrames.Items;
var keyFramesItems = CollectionsMarshal.AsSpan(keyFrames);
var keyFramesCount = keyFrames.Count;

// Extract data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
#pragma warning disable SA1402 // File may only contain a single class
using System;
using System.Runtime.InteropServices;
using Stride.Core.Collections;
using Stride.Core.Mathematics;
using Stride.Updater;
Expand Down Expand Up @@ -66,24 +67,24 @@ protected static void SetTime(ref Channel channel, CompressedTimeSpan newTime)
var currentIndex = channel.CurrentIndex;
var keyFrames = channel.Curve.KeyFrames;

var keyFramesItems = keyFrames.Items;
var keyFramesSpan = CollectionsMarshal.AsSpan(keyFrames);
var keyFramesCount = keyFrames.Count;

if (newTime > currentTime)
{
while (currentIndex + 1 < keyFramesCount - 1 && newTime >= keyFramesItems[currentIndex + 1].Time)
while (currentIndex + 1 < keyFramesCount - 1 && newTime >= keyFramesSpan[currentIndex + 1].Time)
{
++currentIndex;
}
}
else if (newTime <= keyFramesItems[0].Time)
else if (newTime <= keyFramesSpan[0].Time)
{
// Special case: fast rewind to beginning of animation
currentIndex = 0;
}
else // newTime < currentTime
{
while (currentIndex - 1 >= 0 && newTime < keyFramesItems[currentIndex].Time)
while (currentIndex - 1 >= 0 && newTime < keyFramesSpan[currentIndex].Time)
{
--currentIndex;
}
Expand Down Expand Up @@ -139,7 +140,7 @@ private void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, Upd
var keyFrames = channel.Curve.KeyFrames;
var currentIndex = channel.CurrentIndex;

objects[channel.Offset].Value = keyFrames.Items[currentIndex].Value;
objects[channel.Offset].Value = keyFrames[currentIndex].Value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@

using System;
using Stride.Core.Mathematics;
using System.Runtime.InteropServices;

namespace Stride.Animations
{
public class AnimationCurveEvaluatorDirectQuaternionGroup : AnimationCurveEvaluatorDirectBlittableGroupBase<Quaternion>
{
protected unsafe override void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)
protected override unsafe void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)
{
SetTime(ref channel, newTime);

var currentTime = channel.CurrentTime;
var currentIndex = channel.CurrentIndex;

var keyFrames = channel.Curve.KeyFrames;
var keyFramesItems = keyFrames.Items;
var keyFramesItems = CollectionsMarshal.AsSpan(keyFrames);
var keyFramesCount = keyFrames.Count;

// Extract data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@

using System;
using Stride.Core.Mathematics;
using System.Runtime.InteropServices;

namespace Stride.Animations
{
public class AnimationCurveEvaluatorDirectVector3Group : AnimationCurveEvaluatorDirectBlittableGroupBase<Vector3>
{
protected unsafe override void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)
protected override unsafe void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)
{
SetTime(ref channel, newTime);

var currentTime = channel.CurrentTime;
var currentIndex = channel.CurrentIndex;

var keyFrames = channel.Curve.KeyFrames;
var keyFramesItems = keyFrames.Items;
var keyFramesItems = CollectionsMarshal.AsSpan(keyFrames);
var keyFramesCount = keyFrames.Count;

// Extract data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using Stride.Core.Mathematics;
using System.Runtime.InteropServices;

namespace Stride.Animations
{
public class AnimationCurveEvaluatorDirectVector4Group : AnimationCurveEvaluatorDirectBlittableGroupBase<Vector4>
{
protected unsafe override void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)
protected override unsafe void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)
{
SetTime(ref channel, newTime);

var currentTime = channel.CurrentTime;
var currentIndex = channel.CurrentIndex;

var keyFrames = channel.Curve.KeyFrames;
var keyFramesItems = keyFrames.Items;
var keyFramesItems = CollectionsMarshal.AsSpan(keyFrames);
var keyFramesCount = keyFrames.Count;

// Extract data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Stride.Animations
{
public class AnimationProcessor : EntityProcessor<AnimationComponent, AnimationProcessor.AssociatedData>
{
private readonly ConcurrentPool<FastList<AnimationOperation>> animationOperationPool = new ConcurrentPool<FastList<AnimationOperation>>(() => new FastList<AnimationOperation>());
private readonly ConcurrentPool<List<AnimationOperation>> animationOperationPool = new ConcurrentPool<List<AnimationOperation>>(() => []);

public AnimationProcessor()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class ComputeAnimationCurve<T> : Comparer<AnimationKeyFrame<T>>,
public TrackingCollection<AnimationKeyFrame<T>> KeyFrames { get; set; } = new TrackingCollection<AnimationKeyFrame<T>>();

// TODO This list will become AnimationCurve<T>
private FastList<AnimationKeyFrame<T>> sortedKeys = new FastList<AnimationKeyFrame<T>>();
private List<AnimationKeyFrame<T>> sortedKeys = [];

private int framesCount = 0;
private bool HasChanged()
Expand Down
2 changes: 1 addition & 1 deletion sources/engine/Stride.Engine/Engine/AnimationComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,6 @@ public Task Ended(PlayingAnimation animation)

public interface IBlendTreeBuilder
{
void BuildBlendTree(FastList<AnimationOperation> animationList);
void BuildBlendTree(List<AnimationOperation> animationList);
}
}
Loading