Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [1.1.0-pre.3] - 2023-10-17

### Changed

* the DefaultTranslationSmoothingAction.DefaultStaticUserParams is now public and can be used by user code (to either change the defaults or use them in their own custom smoothing methods).

### Fixed

* issue when using prediction error smoothing, causing wrong component data retrieved from the backup buffer and consequently not making the smoothing function work as expected.
* an issue in the reported elapsed time when executing the PredictedFixedStepSystemGroup in presence of partial ticks and PredictedFixedStepSimulationTickRatio grater than 1, causing problem with physics and character controller interpolation.
* An issue with the change mask not read correctly when serializing/deserializing components with more than 32 fields.
* `InvalidOperationException: Comparison function is incorrect` inside `GhostComponentSerializerCollectionSystemGroup` due to `ComponentTypeSerializationStrategy.DefaultType` being a `byte` flag enum (so it erroneously matched `128 - 0` the same as `0 - 128` due to wrapping).
  • Loading branch information
Unity Technologies committed Oct 17, 2023
1 parent a2764a0 commit 403389c
Show file tree
Hide file tree
Showing 16 changed files with 420 additions and 51 deletions.
4 changes: 0 additions & 4 deletions .buginfo

This file was deleted.

18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
---
uid: changelog
---

# Changelog

## [1.1.0-pre.3] - 2023-10-17

### Changed

* the DefaultTranslationSmoothingAction.DefaultStaticUserParams is now public and can be used by user code (to either change the defaults or use them in their own custom smoothing methods).

### Fixed

* issue when using prediction error smoothing, causing wrong component data retrieved from the backup buffer and consequently not making the smoothing function work as expected.
* an issue in the reported elapsed time when executing the PredictedFixedStepSystemGroup in presence of partial ticks and PredictedFixedStepSimulationTickRatio grater than 1, causing problem with physics and character controller interpolation.
* An issue with the change mask not read correctly when serializing/deserializing components with more than 32 fields.
* `InvalidOperationException: Comparison function is incorrect` inside `GhostComponentSerializerCollectionSystemGroup` due to `ComponentTypeSerializationStrategy.DefaultType` being a `byte` flag enum (so it erroneously matched `128 - 0` the same as `0 - 128` due to wrapping).


## [1.1.0-exp.1] - 2023-09-18

### Added
Expand Down
5 changes: 2 additions & 3 deletions Editor/Templates/GhostComponentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,10 @@ private static void CalculateChangeMask(ref Snapshot snapshot, in Snapshot basel
#region __GHOST_CALCULATE_CHANGE_MASK__
#endregion
#region __GHOST_FLUSH_COMPONENT_CHANGE_MASK__
GhostComponentSerializer.CopyToChangeMask(bits, changeMask, startOffset, 32);
startOffset += 32;
GhostComponentSerializer.CopyToChangeMask(bits, changeMask, startOffset + __GHOST_CURRENT_MASK_BITS__, 32);
#endregion
#region __GHOST_FLUSH_FINAL_COMPONENT_CHANGE_MASK__
GhostComponentSerializer.CopyToChangeMask(bits, changeMask, startOffset, __GHOST_CHANGE_MASK_BITS__);
GhostComponentSerializer.CopyToChangeMask(bits, changeMask, startOffset + __GHOST_CHANGE_MASK_BITS__, __GHOST_CURRENT_MASK_BITS__);
#endregion
#endif
}
Expand Down
118 changes: 116 additions & 2 deletions Runtime/Command/IInputComponentData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode.LowLevel.Unsafe;

namespace Unity.NetCode
{
Expand Down Expand Up @@ -50,12 +52,124 @@ public void Set()
/// Interface used to handle automatic input command data setup with the IInputComponentData
/// style inputs. This is used internally by code generation, don't use this directly.
/// </summary>
[Obsolete("The IInputBufferData interface has been deprecated. It was meant for internal use and any reference to it is considered an error. Please always use ICommandData instead", true)]
[Obsolete("The IInputBufferData interface has been deprecated. It was meant for internal use and any reference to it is considered an error. " +
"Please always use ICommandData instead.", false)]
public interface IInputBufferData : ICommandData
{
/// <summary>
/// Take the stored input data we have and copy to the given input data pointed to. Decrement
/// any event counters by the counter value in the previous command buffer data element.
/// </summary>
/// <param name="prevInputBufferDataPtr">Command data from the previous tick</param>
/// <param name="inputPtr">Our stored input data will be copied over to this location</param>
public void DecrementEventsAndAssignToInput(IntPtr prevInputBufferDataPtr, IntPtr inputPtr);
/// <summary>
/// Save the input data with any event counters incremented by the counter from the last stored
/// input in the command buffer for the current tick. See <see cref="InputEvent"/>.
/// </summary>
/// <param name="lastInputBufferDataPtr">Pointer to the last command data in the buffer</param>
/// <param name="inputPtr">Pointer to input data to be saved in this command data</param>
public void IncrementEventsAndSetCurrentInputData(IntPtr lastInputBufferDataPtr, IntPtr inputPtr);
}

/// <summary>
/// <summary>
/// For internal use only, helper struct that should be used to implement systems that copy the content of an
/// <see cref="IInputComponentData"/> into the code-generated <see cref="ICommandData"/> buffer.
/// </summary>
/// <typeparam name="TInputBufferData"></typeparam>
/// <typeparam name="TInputComponentData"></typeparam>
[Obsolete("CopyInputToCommandBuffer has been deprecated. There is no replacement, being the method meant to be used only by code-generated systems.", false)]
public partial struct CopyInputToCommandBuffer<TInputBufferData, TInputComponentData>
where TInputBufferData : unmanaged, IInputBufferData
where TInputComponentData : unmanaged, IInputComponentData
{
/// <summary>
/// For internal use only, simplify the creation of system jobs that copies <see cref="IInputComponentData"/> data to the underlying <see cref="ICommandData"/> buffer.
/// </summary>
[Obsolete("CopyInputToBufferJob has been deprecated.", false)]
public struct CopyInputToBufferJob
{
/// <summary>
/// Implements the component copy and input event management.
/// Should be called your job <see cref="Unity.Jobs.IJob.Execute"/> method.
/// </summary>
/// <param name="chunk"></param>
/// <param name="orderIndex"></param>
public void Execute(ArchetypeChunk chunk, int orderIndex)
{
}
}

/// <summary>
/// Initialize the CopyInputToCommandBuffer by updating all the component type handles and create a
/// a new <see cref="CopyInputToBufferJob"/> instance.
/// </summary>
/// <param name="state"></param>
/// <returns>a new <see cref="CopyInputToBufferJob"/> instance.</returns>
public CopyInputToBufferJob InitJobData(ref SystemState state)
{
return default;
}

/// <summary>
/// Creates the internal component type handles, register to system state the component queries.
/// Very important, add an implicity constraint for running the parent system only when the client
/// is connected to the server, by requiring at least one connection with a <see cref="NetworkId"/> components.
/// <remarks>
/// Should be called inside your the system OnCreate method.
/// </remarks>
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
public EntityQuery Create(ref SystemState state)
{
return default;
}
}

/// <summary>
/// For internal use only, helper struct that should be used to implements systems that copies
/// commands from the <see cref="ICommandData"/> buffer to the <see cref="IInputComponentData"/> component
/// present on the entity.
/// </summary>
/// <typeparam name="TInputBufferData"></typeparam>
/// <typeparam name="TInputComponentData"></typeparam>
[Obsolete("ApplyCurrentInputBufferElementToInputData has been deprecated. There is no replacement, being the method meant to be used only by code-generated systems.", false)]
public partial struct ApplyCurrentInputBufferElementToInputData<TInputBufferData, TInputComponentData>
where TInputBufferData : unmanaged, IInputBufferData
where TInputComponentData : unmanaged, IInputComponentData
{
/// <summary>
/// Helper struct that should be used to implement jobs that copies commands from an <see cref="ICommandData"/> buffer
/// to the respective <see cref="IInputComponentData"/>.
/// </summary>
[Obsolete("ApplyInputDataFromBufferJob has been deprecated.", false)]
public struct ApplyInputDataFromBufferJob
{
/// <summary>
/// Copy the command for current server tick to the input component.
/// Should be called your job <see cref="Unity.Jobs.IJob.Execute"/> method.
/// </summary>
/// <param name="chunk"></param>
/// <param name="orderIndex"></param>
public void Execute(ArchetypeChunk chunk, int orderIndex)
{
}
}

/// <summary>
/// Update the component type handles and create a new <see cref="ApplyInputDataFromBufferJob"/>
/// that can be passed to your job.
/// </summary>
/// <param name="state"></param>
/// <returns>a new <see cref="ApplyInputDataFromBufferJob"/> instance.</returns>
public ApplyInputDataFromBufferJob InitJobData(ref SystemState state)
{
return default;
}
}

/// <summary>
/// The underlying <see cref="ICommandData"/> buffer used to store the <see cref="IInputComponentData"/>.
/// </summary>
/// <remarks>
Expand Down
10 changes: 10 additions & 0 deletions Runtime/Debug/DebugGhostDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Unity.Entities;

namespace Unity.NetCode
{
Expand All @@ -15,6 +16,12 @@ public class DebugGhostDrawer
static DebugGhostDrawer s_Instance;

public static List<CustomDrawer> CustomDrawers = new List<CustomDrawer>(2);

[Obsolete("Use ClientServerBootstrap.ServerWorld instead. RemoveAfter Entities 1.x")]
public static World FirstServerWorld => ClientServerBootstrap.ServerWorld;

[Obsolete("Use ClientServerBootstrap.ClientWorld instead. RemoveAfter Entities 1.x")]
public static World FirstClientWorld => ClientServerBootstrap.ClientWorld;

static ulong s_LastNextSequenceNumber;

Expand All @@ -29,6 +36,9 @@ public static void RegisterDrawAction(CustomDrawer newDrawAction)
CustomDrawers.Add(newDrawAction);
CustomDrawers.Sort();
}

[Obsolete("This functionality is obsolete, worlds are no longer cached here. RemoveAfter Entities 1.x")]
public static void RefreshWorldCaches() {}

public static bool HasRequiredWorlds => ClientServerBootstrap.ServerWorld != default && ClientServerBootstrap.ClientWorld != default;

Expand Down
8 changes: 4 additions & 4 deletions Runtime/Simulator/MultiplayerPlayModePreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ public static void ApplySimulatorPresetToPrefs(SimulatorPreset preset)
/// <summary>For the PlayMode Tools Window.</summary>
public enum SimulatorView
{
[Obsolete("RemovedAfter Entities 1.0")]
Disabled = -1,
PingView = 0,
PerPacketView = 1,
[Obsolete("Disabled is no longer supported. Use MultiplayerPlayModePreferences.SimulatorEnabled instead. RemovedAfter Entities 1.x")]
Disabled = 0,
PingView = 1,
PerPacketView = 2,
}
}
#endif
16 changes: 11 additions & 5 deletions Runtime/Snapshot/DefaultTranslationSmoothingAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ public unsafe struct DefaultTranslationSmoothingAction
/// </summary>
public sealed class DefaultStaticUserParams
{
internal static readonly SharedStatic<float> maxDist = SharedStatic<float>.GetOrCreate<DefaultStaticUserParams, MaxDistKey>();
internal static readonly SharedStatic<float> delta = SharedStatic<float>.GetOrCreate<DefaultStaticUserParams, DeltaKey>();
/// <summary>
/// If the prediction error is larger than this value, the entity position is snapped to the new value.
/// The default threshold is 10 units.
/// </summary>
public static readonly SharedStatic<float> maxDist = SharedStatic<float>.GetOrCreate<DefaultStaticUserParams, MaxDistKey>();
/// <summary>
/// If the prediction error is smaller than this value, the entity position is snapped to the new value.
/// The default threshold is 1 units.
/// </summary>
public static readonly SharedStatic<float> delta = SharedStatic<float>.GetOrCreate<DefaultStaticUserParams, DeltaKey>();

static DefaultStaticUserParams()
{
Expand All @@ -66,9 +74,7 @@ class DeltaKey {}
/// Return a the burst compatible function pointer that can be used to register the smoothing action to the
/// <see cref="GhostPredictionSmoothing"/> singleton.
/// </summary>
public static readonly PortableFunctionPointer<GhostPredictionSmoothing.SmoothingActionDelegate>
Action =
new PortableFunctionPointer<GhostPredictionSmoothing.SmoothingActionDelegate>(SmoothingAction);
public static readonly PortableFunctionPointer<GhostPredictionSmoothing.SmoothingActionDelegate> Action = new PortableFunctionPointer<GhostPredictionSmoothing.SmoothingActionDelegate>(SmoothingAction);

[BurstCompile(DisableDirectCall = true)]
[AOT.MonoPInvokeCallback(typeof(GhostPredictionSmoothing.SmoothingActionDelegate))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public int CompareTo(ComponentTypeSerializationStrategy other)
if (IsSerialized != other.IsSerialized)
return IsSerialized - other.IsSerialized;
if (DefaultRule != other.DefaultRule)
return DefaultRule - other.DefaultRule;
return (int)DefaultRule - (int)other.DefaultRule;
if (Hash != other.Hash)
return Hash < other.Hash ? -1 : 1;
return 0;
Expand Down Expand Up @@ -356,6 +356,20 @@ public void ThrowIfCollectionNotFinalized(in FixedString512Bytes context)
#endif
}

/// <summary>
/// Lookup a component type to use as a buffer for a given IInputComponentData.
/// </summary>
/// <param name="inputType"></param>
/// <param name="bufferType"></param>
/// <returns>True if the component has an assosiated buffer to use, false if it does not.</returns>
[Obsolete("TryGetBufferForInputComponent has been deprecated. In order to find the buffer associated with an IInputComponentData please just use" +
"IInputBuffer<T> where T is the IInputComponentData type you are looking for.", false)]
public bool TryGetBufferForInputComponent(ComponentType inputType, out ComponentType bufferType)
{
bufferType = default;
return false;
}

/// <summary>
/// Used by code-generated systems and meant for internal use only.
/// Adds a mapping from an IInputComponentData to the buffer it should use.
Expand Down
Loading

0 comments on commit 403389c

Please sign in to comment.