WAReborn / WorldsAdriftReborn

63 stars 15 forks source link

WeatherCellCoordsC error spam #34

Open sp00ktober opened 1 year ago

sp00ktober commented 1 year ago
[Error  : Unity Log] [2022-12-21T17:48:55]..[ERROR] [DEFAULT] [AddToIdComponentToEntityMapS`2] Attempting to add existing id that points to another entity: 0. Existing entity index: 0, entityIndex: 1.
   at BossaECS.Framework.Systems.AddToIdComponentToEntityMapS`2[[WASystems.Components.Weather.WeatherCellCoordsC, WASystems, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Execute()
   at BossaECS.Core.System.SystemBase.TryExecute()
   at BossaECS.Framework.Systems.IdComponentToEntityMapWrapperSystem`2[[WASystems.Components.Weather.WeatherCellCoordsC, WASystems, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Execute()
   at BossaECS.Core.System.SystemBase.TryExecute()
   at WASystems.Systems.Weather.UpdateWeatherCellCoordsMapS.Execute()
   at BossaECS.Core.System.SystemBase.TryExecute()
   at BossaECS.Core.System.CompositeSystem.Execute()
   at BossaECS.Core.System.SystemBase.TryExecute()
   at BossaECS.Core.System.CompositeSystem.Execute()
   at BossaECS.Core.System.EcsLifecycleWrapperSystem.Execute()
   at BossaECS.Core.System.SystemBase.TryExecute()
   at SpatialTranslator.Systems.SpatialRuntimeWrapperS.Execute()
   at BossaECS.Core.System.SystemBase.TryExecute()
   at EcsBootstrap.FixedUpdate()

We currently get spammed with this error just after instructing the game to spawn the player. The error gets triggered because both the island (which we spawn first) and the player request partially the same components.

grafik

Component 1139 is the WeatherCellState which triggers this error, if we only respond to onw of the two requests the error is gone. The question now is, should this component only be created once? Or are we missing something else?

To get a better understanding of this we need to look into where the error comes from BossaECS.Framework.Systems.AddToIdComponentToEntityMapS<WASystems.Components.Weather.WeatherCellCoordsC, uint>.Execute() which is part of a system of classes all having BossaECS.Core.System.SystemBase as their parent. This seems to form the ECS of the game which we need to understand properly to handle this error.

Bossa.Travellers.Weather.WriteToSnapshotEntities_WeatherCellStateS also seems to be an interesting class. WASystems.Installer also seems to add Bindings for WeatherCellCoordsC

This stack trace could also help, its printed by the game once we spawn the first entity.

[2022-12-30T21:51:01]..[INFO] [DEFAULT] [EntityComponentSystem] Resizing ECS from 0 to 640 took 15.603ms
   at BossaECS.Core.EntityComponentSystem.Resize(UInt32 newCapacity)
   at BossaECS.Core.EntityComponentSystem.CreateEntity()
   at SpatialTranslator.Systems.SpatialEntityLifecycleS.Execute()
   at BossaECS.Core.System.SystemBase.TryExecute()
   at BossaECS.Core.System.CompositeSystem.Execute()
   at BossaECS.Core.System.EcsLifecycleWrapperSystem.Execute()
   at BossaECS.Core.System.SystemBase.TryExecute()
   at SpatialTranslator.Systems.SpatialRuntimeWrapperS.Execute()
   at BossaECS.Core.System.SystemBase.TryExecute()
   at EcsBootstrap.FixedUpdate()

Here is another stack trace which might lead to a connection between adding components to entities and the ECS of Bossa

   UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
Improbable.Unity.Internal.SDKLogging:ExceptionCallback(Exception)
Improbable.Worker.ClientError:LogClientException(Exception)
Bossa.Travellers.Ecs.<RegisterWithConnection>c__AnonStorey2BD:<>m__685(AddComponentOp`1)
Improbable.Worker.<>c__DisplayClass15_0`1:<OnAddComponent>b__0(ComponentWrapperOp)
Improbable.Worker.Internal.Callbacks`1:InvokeAll(ComponentWrapperOp)
Improbable.Worker.Internal.ComponentCallbacks`1:InvokeAll(UInt32, ComponentWrapperOp)
Improbable.Worker.Dispatcher:AddComponentThunk(Void*, AddComponentOp*)
Improbable.Worker.Internal.WorkerProtocol:Dispatcher_Process(DispatcherHandle, OpListHandle)
Improbable.Worker.Dispatcher:Process(OpList)
Improbable.Unity.Core.ConnectionLifecycle:ProcessEvents()
Improbable.Unity.Core.SpatialOS:ProcessEvents()
Improbable.Unity.Core.EntityEventHandler:ProcessDeferred()
Improbable.Unity.Core.DispatchEventHandler:Update()
Improbable.Unity.Core.ConnectionLifecycle:Update()
Taraky commented 6 months ago

`// Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null // Assets.Visualizers.Weather.GlobalWeather using System; using System.Collections.Generic; using Assets.Scripts.Utils; using Assets.Visualizers.Weather; using Bossa.Travellers.Weather; using BossaECS.Core; using BossaECS.Framework.System; using Improbable.CoreLibrary.CoordinateRemapping; using Improbable.Math; using Improbable.Unity.Common.Core.Math; using JetBrains.Annotations; using UnityEngine; using WASystems.Components.Weather; using WASystems.Systems.Weather; using WASystems.Util; using Zenject;

public class GlobalWeather : Singleton { public struct WeatherSample { public Vector3 Wind;

    public float Pressure;
}

public interface WindModifier
{
    float GetWindDampeningAt(Coordinates pos);
}

private readonly HashSet<WindModifier> _modifiers = new HashSet<WindModifier>();

[Inject]
[UsedImplicitly]
private IdComponentToEntityMap<WeatherCellCoordsC, uint> _weatherCellCoordMap;

[ComponentStore]
[UsedImplicitly]
private WeatherCellStateC.Store _interpolatedWeatherCells;

public override void Init()
{
}

private Vector2i GetCellCoords(Vector3d pos)
{
    float weatherCellSpacing = WeatherCellGenesisS.WeatherCellSpacing;
    int x = Mathf.FloorToInt((float)(pos.X / (double)weatherCellSpacing));
    int y = Mathf.FloorToInt((float)(pos.Z / (double)weatherCellSpacing));
    return new Vector2i(x, y);
}

private WeatherSample GetCellSampleAt(int x, int z)
{
    if (_weatherCellCoordMap != null && _weatherCellCoordMap.TryGetValue(CantorPairUtils.GetCantorPairId(x, z), out var value))
    {
        WeatherCellStateC component = _interpolatedWeatherCells.GetComponent(value);
        WeatherSample result = default(WeatherSample);
        result.Wind = component.Wind.ToUnityVector3();
        result.Pressure = component.Pressure;
        return result;
    }
    WeatherSample result2 = default(WeatherSample);
    result2.Wind = new Vector3(1f, 0f, -2f);
    result2.Pressure = 0.5f;
    return result2;
}

public WeatherSample GetWeatherAt(Vector3d pos)
{
    float weatherCellSpacing = WeatherCellGenesisS.WeatherCellSpacing;
    WallData.WallQuery wallWindAt = WeatherWalls.GetWallWindAt(pos);
    Vector2i cellCoords = GetCellCoords(pos);
    Vector2 vector = cellCoords * weatherCellSpacing;
    WeatherSample cellSampleAt = GetCellSampleAt(cellCoords.x, cellCoords.y);
    WeatherSample cellSampleAt2 = GetCellSampleAt(cellCoords.x + 1, cellCoords.y);
    WeatherSample cellSampleAt3 = GetCellSampleAt(cellCoords.x, cellCoords.y + 1);
    WeatherSample cellSampleAt4 = GetCellSampleAt(cellCoords.x + 1, cellCoords.y + 1);
    float tx = (float)((pos.X - (double)vector.x) / (double)weatherCellSpacing);
    float ty = (float)((pos.Z - (double)vector.y) / (double)weatherCellSpacing);
    Vector3 wind = Vector3.Lerp(GetWindAt(cellSampleAt, cellSampleAt2, cellSampleAt3, cellSampleAt4, tx, ty), wallWindAt.Wind, wallWindAt.Intensity);
    if (WorldBoundsDataVisualizer.CheckedOut)
    {
        float halfEdge = (float)WorldBoundsDataVisualizer.EdgeLength * 0.5f;
        ApplyEdgeWindIfNeeded(ref wind.x, pos.X, halfEdge);
        ApplyTopWindIfNeeded(ref wind.y, pos.Y);
        ApplyEdgeWindIfNeeded(ref wind.z, pos.Z, halfEdge);
    }
    WeatherSample result = default(WeatherSample);
    result.Wind = wind;
    result.Pressure = Mathf.Lerp(0.25f, 0.75f, MathUtils.Lerp2D(cellSampleAt.Pressure, cellSampleAt2.Pressure, cellSampleAt3.Pressure, cellSampleAt4.Pressure, tx, ty));
    return result;
}

public static void ApplyEdgeWindIfNeeded(ref float wind, double pos, float halfEdge)
{
    if (CalculateHowFarIntoEdge(pos, halfEdge, out var normalizedDistance))
    {
        float num = normalizedDistance * normalizedDistance;
        wind = Mathf.LerpUnclamped(1f + wind, 400f, (!(normalizedDistance > 0f)) ? num : (0f - num));
    }
}

public static void ApplyTopWindIfNeeded(ref float wind, double pos)
{
    if (pos > 800.0)
    {
        float num = (float)((pos - 800.0) / 400.0);
        wind = Mathf.LerpUnclamped(1f + wind, 400f, num * num);
    }
}

public static float CalculateDistanceToEdge(Vector3d coords)
{
    if (WorldBoundsDataVisualizer.CheckedOut)
    {
        float num = (float)WorldBoundsDataVisualizer.EdgeLength * 0.5f;
        float b = (float)((double)num - Math.Abs(coords.X));
        float a = (float)((double)num - Math.Abs(coords.Z));
        return Mathf.Min(a, b);
    }
    return float.MaxValue;
}

private static bool CalculateHowFarIntoEdge(double pos, double halfEdge, out float normalizedDistance)
{
    double num = halfEdge - 400.0;
    if (pos > num)
    {
        normalizedDistance = (float)(pos - num) / 400f;
        return true;
    }
    if (pos < 0.0 - num)
    {
        normalizedDistance = (float)(pos + num) / 400f;
        return true;
    }
    normalizedDistance = 0f;
    return false;
}

public float GetWindModifierAt(Coordinates pos)
{
    return 0f;
}

private static Vector3 GetWindAt(WeatherSample c0, WeatherSample c1, WeatherSample c2, WeatherSample c3, float tx, float ty)
{
    Vector3 vector = MathUtils.Slerp2D(c0.Wind, c1.Wind, c2.Wind, c3.Wind, tx, ty);
    if (false)
    {
        float num = (c0.Wind.magnitude + c1.Wind.magnitude + c2.Wind.magnitude + c3.Wind.magnitude) * 0.25f;
        float magnitude = vector.magnitude;
        if (magnitude < num)
        {
            float num2 = Vector3.Dot(c0.Wind, new Vector3(1f, 0f, 1f)) + Vector3.Dot(c1.Wind, new Vector3(-1f, 0f, 1f)) + Vector3.Dot(c2.Wind, new Vector3(1f, 0f, -1f)) + Vector3.Dot(c3.Wind, new Vector3(-1f, 0f, -1f));
            num2 = Mathf.Clamp(num2 * 5f, -1f, 1f);
            vector.y += Mathf.Sqrt(num * num - magnitude * magnitude) * num2;
        }
    }
    if (vector.magnitude > 100f)
    {
        vector = vector.normalized * 100f;
    }
    if (vector.magnitude > 100f || !vector.IsFinite() || float.IsNaN(vector.x) || float.IsNaN(vector.y) || float.IsNaN(vector.z))
    {
        return Vector3.zero;
    }
    return vector;
}

public float GetTurbulenceAt(Vector3 position)
{
    return GetTurbulenceAt(position.RemapUnityVectorToGlobalVector());
}

public float GetTurbulenceAt(Vector3d position)
{
    float magnitude = GetWeatherAt(position).Wind.magnitude;
    return Mathf.Clamp01(magnitude / 100f);
}

public void RegisterWeatherModifier(WindModifier modifier)
{
    _modifiers.Add(modifier);
}

public void UnregisterWeatherModifier(WindModifier modifier)
{
    _modifiers.Remove(modifier);
}

}` and

`// WASystems, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null // WASystems.Components.Weather.WeatherCellCoordsC public struct WeatherCellCoordsC { public int X;

public int Z;

}`