Expose provider cargo deltas in feedback

This commit is contained in:
Meta Vens 2026-07-15 11:45:50 +01:00
commit 817912a041
4 changed files with 108 additions and 4 deletions

View file

@ -205,6 +205,10 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests
float tractorBeamPower = 0f;
float tractorReleasedPower = 1f;
int tractorBeamParticleSystemCount = 0;
EveUnityFeedbackEvent pickupCollection = null;
int pickupCollectionEventCount = 0;
int initialPickupEntityCount = 0;
int finalPickupEntityCount = -1;
try
{
@ -267,6 +271,16 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests
}
Assert.That(host.PresentedEntities?.CurrentGeneration, Is.Not.Null);
Assert.That(host.PresentedEntities.CurrentGeneration.Entities.Count, Is.GreaterThan(0));
initialPickupEntityCount = host.PresentedEntities.CurrentGeneration.Entities.Count(entity =>
string.Equals(entity.EntityKind, "pickup", StringComparison.Ordinal));
Assert.That(initialPickupEntityCount, Is.GreaterThan(0),
"The daemon fixture did not publish its physical starter pickup through the entity SoA.");
runtime.FeedbackAvailable += feedback =>
{
if (!string.Equals(feedback.Kind, "pickup.collected", StringComparison.Ordinal)) return;
pickupCollectionEventCount++;
pickupCollection = feedback;
};
var playerId = runtime.ActiveWorld.PlayerEntityId;
var playerFact = host.PresentedEntities.CurrentGeneration.Entities
@ -418,6 +432,27 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests
tractorBeamParticleSystemCount = beamRenderer.ActiveParticleSystemCount;
Assert.That(tractorBeamParticleSystemCount, Is.GreaterThan(0),
"The generic beam lowerer did not instantiate the provider-owned effect prefab.");
var pickupDeadline = Time.realtimeSinceStartup + 12f;
while (Time.realtimeSinceStartup < pickupDeadline &&
(pickupCollection == null ||
host.PresentedEntities.CurrentGeneration.Entities.Any(entity =>
string.Equals(entity.EntityKind, "pickup", StringComparison.Ordinal))))
{
yield return new WaitForSecondsRealtime(0.1f);
runtime.Refresh();
}
finalPickupEntityCount = host.PresentedEntities.CurrentGeneration.Entities.Count(entity =>
string.Equals(entity.EntityKind, "pickup", StringComparison.Ordinal));
Assert.That(pickupCollection, Is.Not.Null,
"The released client did not observe provider-owned feedback for Ymir contact collection.");
Assert.That(pickupCollectionEventCount, Is.EqualTo(1),
"One Ymir contact transaction must emit one client-visible collection event.");
Assert.That(pickupCollection.ItemKey, Is.EqualTo("scrap-metal"));
Assert.That(pickupCollection.ScalarValue, Is.EqualTo(1));
Assert.That(pickupCollection.CargoQuantityBefore, Is.Zero);
Assert.That(pickupCollection.CargoQuantityAfter, Is.EqualTo(1));
Assert.That(finalPickupEntityCount, Is.EqualTo(initialPickupEntityCount - 1),
"Collected pickup remained in the provider-authored entity generation.");
var focusVersion = runtime.ActiveVersion;
var inputDriver = root.GetComponent<EveUnityPlayableWorldInputDriver>() ??
@ -659,6 +694,10 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests
tractorBeamPower,
tractorReleasedPower,
tractorBeamParticleSystemCount,
initialPickupEntityCount,
finalPickupEntityCount,
pickupCollectionEventCount,
pickupCollection,
playerRendererFacts);
}
finally
@ -711,6 +750,10 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests
float tractorBeamPower,
float tractorReleasedPower,
int tractorBeamParticleSystemCount,
int initialPickupEntityCount,
int finalPickupEntityCount,
int pickupCollectionEventCount,
EveUnityFeedbackEvent pickupCollection,
RendererFact[] playerRendererFacts)
{
var path = Environment.GetEnvironmentVariable("EVEUNITY_WITNESS_FACTS_PATH");
@ -753,6 +796,15 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests
tractorBeamPower = tractorBeamPower,
tractorReleasedPower = tractorReleasedPower,
tractorBeamParticleSystemCount = tractorBeamParticleSystemCount,
pickupCollection = pickupCollection != null && pickupCollectionEventCount == 1 &&
pickupCollection.CargoQuantityAfter - pickupCollection.CargoQuantityBefore == pickupCollection.ScalarValue,
initialPickupEntityCount = initialPickupEntityCount,
finalPickupEntityCount = finalPickupEntityCount,
pickupCollectionEventCount = pickupCollectionEventCount,
pickupItemKey = pickupCollection?.ItemKey ?? "",
pickupQuantity = (float)(pickupCollection?.ScalarValue ?? 0),
cargoQuantityBeforePickup = (float)(pickupCollection?.CargoQuantityBefore ?? 0),
cargoQuantityAfterPickup = (float)(pickupCollection?.CargoQuantityAfter ?? 0),
playerRenderers = playerRendererFacts,
mapChannelRendererCount = mapChannelRendererCount,
mapChangedPixels = mapChangedPixels,
@ -803,6 +855,14 @@ namespace GameCult.EveUnity.GenericClient.PlayModeTests
public float tractorBeamPower;
public float tractorReleasedPower;
public int tractorBeamParticleSystemCount;
public bool pickupCollection;
public int initialPickupEntityCount;
public int finalPickupEntityCount;
public int pickupCollectionEventCount;
public string pickupItemKey;
public float pickupQuantity;
public float cargoQuantityBeforePickup;
public float cargoQuantityAfterPickup;
public RendererFact[] playerRenderers;
public int mapChannelRendererCount;
public int mapChangedPixels;

View file

@ -11,10 +11,13 @@ namespace GameCult.Eve.UnityScene
public EveUnityFeedbackEvent(EveUnitySceneNode node)
{
EventId = Get(node, "eventId"); Kind = Get(node, "eventKind"); SubjectKey = Get(node, "subjectKey");
ItemKey = Get(node, "itemKey"); Position = Get(node, "position");
ItemKey = Get(node, "itemKey"); Position = Get(node, "position"); Reason = Get(node, "reason");
FrameId = Long(node, "frameId", -1); ZoneIndex = Int(node, "zoneIndex", -1);
SourceEntityIndex = Int(node, "sourceEntityIndex", -1); TargetEntityIndex = Int(node, "targetEntityIndex", -1);
PickupIndex = Int(node, "pickupIndex", -1); ScalarValue = Double(node, "scalarValue", 0);
AuxiliaryValue = Double(node, "auxiliaryValue", 0);
CargoQuantityBefore = Double(node, "cargoQuantityBefore", 0);
CargoQuantityAfter = Double(node, "cargoQuantityAfter", 0);
}
public string EventId { get; }
public string Kind { get; }
@ -26,7 +29,11 @@ namespace GameCult.Eve.UnityScene
public string SubjectKey { get; }
public string ItemKey { get; }
public string Position { get; }
public string Reason { get; }
public double ScalarValue { get; }
public double AuxiliaryValue { get; }
public double CargoQuantityBefore { get; }
public double CargoQuantityAfter { get; }
private static string Get(EveUnitySceneNode node, string key) => node.Props.TryGetValue(key, out var value) ? value ?? "" : "";
private static int Int(EveUnitySceneNode node, string key, int fallback) => int.TryParse(Get(node, key), NumberStyles.Integer, CultureInfo.InvariantCulture, out var value) ? value : fallback;
private static long Long(EveUnitySceneNode node, string key, long fallback) => long.TryParse(Get(node, key), NumberStyles.Integer, CultureInfo.InvariantCulture, out var value) ? value : fallback;

View file

@ -29,14 +29,51 @@ namespace GameCult.Eve.UnityScene.Tests
Assert.That(emitted.Count, Is.EqualTo(1));
}
[Test]
public void FeedbackEventPreservesProviderOwnedCargoDeltaAndReason()
{
var node = Event("pickup", "pickup.collected", 9, new Dictionary<string, string>
{
["itemKey"] = "scrap-metal",
["scalarValue"] = "1",
["auxiliaryValue"] = "0",
["cargoQuantityBefore"] = "0",
["cargoQuantityAfter"] = "1",
["reason"] = ""
});
var value = new EveUnityFeedbackEvent(node);
Assert.That(value.ItemKey, Is.EqualTo("scrap-metal"));
Assert.That(value.ScalarValue, Is.EqualTo(1));
Assert.That(value.AuxiliaryValue, Is.Zero);
Assert.That(value.CargoQuantityBefore, Is.Zero);
Assert.That(value.CargoQuantityAfter, Is.EqualTo(1));
Assert.That(value.Reason, Is.Empty);
}
private static EveUnitySceneProjection Projection(params EveUnitySceneNode[] events) =>
new EveUnitySceneProjection("provider", "surface", "world", "commands", "receipt", "provider", null,
Node("root", "surface", Node("feedback", "feedback.stream", events)));
private static EveUnitySceneNode Event(string id, string kind, long frame) =>
private static EveUnitySceneNode Event(
string id,
string kind,
long frame,
IReadOnlyDictionary<string, string>? extra = null)
{
var props = new Dictionary<string, string>(StringComparer.Ordinal)
{
["eventId"] = id,
["eventKind"] = kind,
["frameId"] = frame.ToString()
};
foreach (var pair in extra ?? Empty()) props[pair.Key] = pair.Value;
return
new EveUnitySceneNode(id, "feedback.event", "scene-node",
new Dictionary<string, string>(StringComparer.Ordinal) { ["eventId"] = id, ["eventKind"] = kind, ["frameId"] = frame.ToString() },
props,
Empty(), Empty(), 0, 0, Array.Empty<EveUnitySceneEmbeddedDocumentSlot>(), null, Array.Empty<EveUnitySceneNode>());
}
private static EveUnitySceneNode Node(string id, string kind, params EveUnitySceneNode[] children) =>
new EveUnitySceneNode(id, kind, "scene-node", Empty(), Empty(), Empty(), 0, 0,

View file

@ -1,7 +1,7 @@
{
"name": "org.gamecult.eve.unity-scene",
"displayName": "Eve Unity Scene Lowering",
"version": "0.3.31",
"version": "0.3.32",
"unity": "2021.3",
"description": "Provider-agnostic Unity scene shell for gamecult.eve.surface.v1 interactive world surfaces.",
"dependencies": {