using System.Diagnostics;
using System.Text.Json;
using XFEEDToolBox.Controls;
using XFEEDToolBox.Core.Galaxy;
using XFEEDToolBox.Core.Models;
namespace XFEEDToolBox;
public partial class App
{
private static async Task<object> RunGalaxyStreamingProbeAsync(string directory)
{
static void Require(bool value,string message){if(!value)throw new InvalidOperationException(message);}
var args=Environment.GetCommandLineArgs();
async Task<GalacticSystem[]> Read(string option)
{
var path=GetArgument(args,option)??throw new ArgumentException(option+" is required.");
using var document=JsonDocument.Parse(await File.ReadAllTextAsync(path));var root=document.RootElement;
return JsonSerializer.Deserialize<GalacticSystem[]>(root.ValueKind==JsonValueKind.Array?root:root.GetProperty("systems"),ToolboxSettings.JsonOptions)??[];
}
var core=await Read("--core-fixture");var local=await Read("--galaxy-fixture");
Require(core.Length==24000&&local.Length>100,"Actual recorded catalogue inputs are missing.");
var recorded=core.Concat(local).DistinctBy(s=>s.Name,StringComparer.OrdinalIgnoreCase).ToArray();
var sourceNames=recorded.Select(s=>s.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
var coreFocus=new Coordinates(25.21875,-20.90625,25899.96875);
var requests=new List<object>();var frames=new List<object>();var pixelMetrics=new Dictionary<string,object>();var requestCount=0;var returnedRows=0;var cancelledRequests=0;
// Completeness below applies ONLY to this finite recorded input set.
// This exercises application integration; it does not certify the live
// Stellar Forge response or invent stars outside the captured samples.
async Task<GalaxyRegionResult> RecordedQuery(Coordinates centre,double radius,CancellationToken token)
{
requestCount++;requests.Add(new{centre,radius,at=Environment.TickCount64});
try{await Task.Delay(85,token);}catch(OperationCanceledException){cancelledRequests++;throw;}
var rows=recorded.Where(s=>s.Position.DistanceTo(centre)<=radius).ToArray();returnedRows+=rows.Length;
return GalaxyRegionResult.Covered(rows);
}
ViewModel.SetGalaxyRegionQueryForProbe(RecordedQuery);ViewModel.GalaxyFilter=GalaxyMapFilter.Default;
var host=new Grid();MainWindow.Content=host;
var map=new GalaxyMapView{Centre=coreFocus,Filter=GalaxyMapFilter.Default};
host.Children.Add(map);await Task.Delay(150);map.ResetCamera();map.Zoom(.125);map.AdvanceCameraMotionForProbe(256);
using var pageStop=new CancellationTokenSource();var tasks=new List<Task>();var errors=new List<string>();
void Changed(object? sender,System.ComponentModel.PropertyChangedEventArgs e)
{if(e.PropertyName==nameof(ViewModel.GalaxySystems))map.Systems=ViewModel.GalaxySystems;}
ViewModel.PropertyChanged+=Changed;
async Task Stream(GalaxyViewport viewport)
{try{await ViewModel.StreamGalaxyRegionAsync(viewport,pageStop.Token);}catch(OperationCanceledException){}catch(Exception e){errors.Add(e.ToString());}}
void Requested(GalaxyViewport viewport)=>tasks.Add(Stream(viewport));
map.ViewportSettled+=Requested;
async Task Save(string name)
{
for(var wait=0;map.OriginalMilkyWayLoadPendingForProbe&&wait<100;wait++)
{await Task.Delay(20);map.RenderNowForProbe();}
map.RenderNowForProbe();var frame=map.CapturePixelsForProbe();
var bright=0;var peak=0;
for(var i=0;i<frame.Pixels.Length;i+=4)
{var value=Math.Max(frame.Pixels[i],Math.Max(frame.Pixels[i+1],frame.Pixels[i+2]));peak=Math.Max(peak,value);if(value>64)bright++;}
pixelMetrics[name]=new {frame.Width,frame.Height,rgbMaximumAbove64Pixels=bright,peakRgb=peak,
originalMilkyWayReady=map.OriginalMilkyWayReadyForProbe,originalMilkyWayInstances=map.OriginalMilkyWayInstancesForProbe,
originalCoreReady=map.OriginalCoreReadyForProbe,
originalBackgroundHdrDrawn=map.OriginalBackgroundHdrDrawnForProbe,
originalSceneHdrDrawn=map.OriginalSceneHdrDrawnForProbe,
originalGridSubmitted=map.OriginalGridSubmittedForProbe,originalGridWorldWidthRestored=map.OriginalGridWorldWidthForProbe};
await SaveModelFrameAsync(new(frame.Width,frame.Height,frame.Pixels,0),Path.Combine(directory,name+".png"));
}
try
{
map.FlushViewportForProbe();var before=map.ViewportNotifications;
var clock=Stopwatch.StartNew();var maximumDuringMotion=0;
for(var i=0;i<45;i++)
{
map.ApplyDragDelta(.9,.14,false);map.AdvanceCameraMotionForProbe();map.RenderNowForProbe();await Task.Delay(45);
maximumDuringMotion=Math.Max(maximumDuringMotion,ViewModel.GalaxySystems.Count);
frames.Add(new{milliseconds=clock.ElapsedMilliseconds,requests=requestCount,stars=map.VisibleStars,notifications=map.ViewportNotifications});
}
map.AdvanceCameraMotionForProbe(256);map.FlushViewportForProbe();
var deadline=clock.ElapsedMilliseconds+10000;
while(ViewModel.GalaxySystems.Count<500&&clock.ElapsedMilliseconds<deadline){await Task.Delay(70);map.RenderNowForProbe();}
Require(errors.Count==0,string.Join("\n",errors));
var motionNotifications=map.ViewportNotifications-before;
Require(motionNotifications>=6,"Continuous camera movement did not publish repeated viewports.");
Require(requestCount>2&&maximumDuringMotion>0,"Continuous camera movement starved catalogue queries.");
Require(ViewModel.GalaxySystems.Count>=500,"Recorded core was not progressively populated.");
Require(ViewModel.GalaxySystems.All(s=>sourceNames.Contains(s.Name)),"Streaming introduced an unrecorded star.");
var loadedCore=ViewModel.GalaxySystems.Count;await Save("stream-core-realistic");
Require(map.OriginalBackgroundHdrDrawnForProbe,"Original Core/MilkyWay did not reach the shared HDR final composite.");
Require(map.OriginalSceneHdrDrawnForProbe,"Stellar/world layers did not reach the common HDR composite.");
pageStop.Cancel();await Task.WhenAll(tasks.ToArray());
map.ViewportSettled-=Requested;
map.Zoom(.25);map.AdvanceCameraMotionForProbe(256);await Save("stream-core-original-milky-way-overview");
map.Zoom(4);map.AdvanceCameraMotionForProbe(256);
map.Systems=core;map.CurrentSystem=core[0].Name;map.Selection=core[0];
var selectedClass=GalaxyMapFilter.StarKey(core[0].StarClass);
var wanted=core.Select(s=>GalaxyMapFilter.StarKey(s.StarClass)).First(k=>k is not null&&k!=selectedClass)!;
map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Map,Values=new HashSet<string>{wanted},IncludeUnknown=false};map.RenderNowForProbe();
Require(map.VisibleModelsMatchFilter&&map.FilteredModels>0&&map.FilteredModels<core.Length,"Current/selected stars bypassed strict filtering.");
Require(map.QueryBackgroundStarsSuppressed,"Unclassified background stars remained in query mode.");
var filtered=map.FilteredModels;var farQuerySizing=map.ClassifiedSizingForProbe();await Save("stream-core-query");
// The far-view fixture has no native physical size fields. Inspect
// the same original classified style at a near scale separately;
// do not add a minimum-pixel size to make the far export brighter.
map.Centre=core.First(s=>GalaxyMapFilter.StarKey(s.StarClass)==wanted).Position;
map.ResetCamera();map.Zoom(2);map.AdvanceCameraMotionForProbe(256);map.RenderNowForProbe();
Require(map.VisibleStars>0&&map.VisibleModelsMatchFilter,"Near classified view lost its actual recorded query target.");
var nearQuerySizing=map.ClassifiedSizingForProbe();await Save("stream-core-query-near");
map.Filter=map.Filter with{Values=new HashSet<string>()};map.RenderNowForProbe();
Require(map.VisibleStars==0&&map.FilteredModels==0&&map.VisibleModelsMatchFilter,"Empty query left stellar models.");
await Save("stream-core-query-empty");
map.Filter=GalaxyMapFilter.Default;map.Systems=ViewModel.GalaxySystems;map.CurrentSystem="";map.ClearSelection();
ViewModel.SetGalaxyRegionQueryForProbe(RecordedQuery);ViewModel.GalaxyFilter=GalaxyMapFilter.Default;
using var localStop=new CancellationTokenSource(TimeSpan.FromSeconds(12));
map.Centre=new(0,0,0);map.ResetCamera();
var localTask=ViewModel.StreamGalaxyRegionAsync(map.RequestedViewportForProbe,localStop.Token);
while(ViewModel.GalaxySystems.Count<100&&!localTask.IsCompleted){await Task.Delay(50);map.RenderNowForProbe();}
localStop.Cancel();try{await localTask;}catch(OperationCanceledException){}
Require(ViewModel.GalaxySystems.Count>=100&&ViewModel.GalaxySystems.All(s=>Math.Abs(s.Position.Z)<1000),"New disjoint view retained old core results or failed to query local records.");
var loadedLocal=ViewModel.GalaxySystems.Count;await Save("stream-local-after-core");
map.Systems=EngineerDirectory.All.Select(e=>new GalacticSystem(e.SystemName,e.Position,Source:"Verified engineer directory"){Data=new(){Markers=["engineer"]}}).ToArray();
map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Map,Category=GalaxyFilterCategory.Markers,Values=new HashSet<string>{"engineer"}};
map.Centre=new(0,0,0);map.ResetCamera();map.Zoom(.3);map.AdvanceCameraMotionForProbe(256);await Task.Delay(350);map.RenderNowForProbe();
Require(map.VisibleWorldMarkers>0,"Known engineer records did not display original game icons.");
var iconTarget=map.WorldMarkerBoundsForProbe[0];var iconAt=new Windows.Foundation.Point(iconTarget.Bounds.X+13,iconTarget.Bounds.Y+13);
map.BeginPointer(iconAt,false);map.EndPointer(iconAt);Require(map.Selection?.Name==iconTarget.System.Name,"Clicking a marker selected another star.");
map.CurrentSystem=iconTarget.System.Name;map.RenderNowForProbe();Require(map.VisibleCurrentLocationMarker,"Current system did not display the original location arrow.");
var originalIcons=map.VisibleWorldMarkers;await Save("actual-engineer-markers");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"actual-engineer-markers-composite.png"));
var starsWithIcons=map.VisibleStars;map.Filter=map.Filter with{VisibleMarkerCategories=new HashSet<string>()};map.RenderNowForProbe();
Require(map.VisibleWorldMarkers==0&&map.VisibleStars==starsWithIcons,"Individual marker display switches changed the stellar query.");
map.Filter=map.Filter with{VisibleMarkerCategories=new HashSet<string>{"engineer"}};map.RenderNowForProbe();
Require(map.VisibleWorldMarkers>0&&map.VisibleStars==starsWithIcons,"Restoring the engineer display flag changed its query targets.");
map.Filter=map.Filter with{ShowMarkers=false};map.RenderNowForProbe();Require(map.VisibleWorldMarkers==0&&!map.VisibleCurrentLocationMarker,"Marker switch left original icons visible.");
map.Filter=GalaxyMapFilter.Default;map.RenderNowForProbe();
var namedRegions=map.VisibleRegionNameLabels;var starsBeforeNames=map.VisibleStars;
Require(namedRegions>0,"Original authored region names did not project near their source coordinates.");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"original-region-names-composite.png"));
await File.WriteAllTextAsync(Path.Combine(directory,"annotation-metrics.json"),JsonSerializer.Serialize(map.AnnotationMetricsForProbe,new JsonSerializerOptions{WriteIndented=true}));
map.Filter=map.Filter with{ShowRegionNames=false,ShowNebulaNames=false};map.RenderNowForProbe();
Require(map.VisibleRegionNameLabels==0&&map.VisibleNebulaNameLabels==0&&map.VisibleStars==starsBeforeNames,"Name-layer switches changed stellar filtering.");
var flowFrom=local.First(s=>s.SystemAddress is >0);var flowTo=local.First(s=>s.SystemAddress is >0&&s.SystemAddress!=flowFrom.SystemAddress&&s.Position.DistanceTo(flowFrom.Position) is >5 and <80);
// Synthetic appearance tests alpha=0 across the entire visible
// object pipeline, using an actual recorded address/position.
var transparentTarget=flowFrom with{OriginalAppearance=new(0x00112233,0x00445566,null,0,0,1,1,false),Data=new()};
map.Systems=[transparentTarget];map.CurrentSystem=transparentTarget.Name;map.Selection=transparentTarget;
map.Centre=transparentTarget.Position;map.ResetCamera();map.Filter=GalaxyMapFilter.Default;map.RenderNowForProbe();
Require(map.VisibleStars==0&&map.FilteredModels==0&&map.VisibleNameLabels==0&&!map.VisibleCurrentLocationMarker,"An explicitly transparent original source retained a stellar object, label or current marker.");
map.SelectAt(map.ProjectForProbe(transparentTarget.Position));Require(map.Selection is null,"An invisible original source remained selectable.");
// Declared runtime-marker fixture; the sole stellar address and
// coordinates remain an actual recorded catalogue entry.
var missionTarget=flowFrom with{Data=new(){NativeAccountMarkers=new("renderer-fixture",1,["mission"]){MissionMarkerTypes=[4,45]}}};
map.Systems=[missionTarget];map.CurrentSystem="";map.ClearSelection();map.Centre=missionTarget.Position;map.ResetCamera();
map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Map,Category=GalaxyFilterCategory.Markers,Values=new HashSet<string>{"mission"}};
map.RenderNowForProbe();Require(map.VisibleWorldMarkers==2,"Two actual mission marker types at one recorded system lost a glyph.");
foreach(var marker in map.WorldMarkerBoundsForProbe.ToArray())
{var point=new Windows.Foundation.Point(marker.Bounds.X+13,marker.Bounds.Y+13);map.BeginPointer(point,false);map.EndPointer(point);Require(map.Selection?.SystemAddress==missionTarget.SystemAddress,"Mission glyph did not select its exact system.");}
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"synthetic-mission-marker-styles-probe.png"));
var missionStars=map.VisibleStars;map.Filter=map.Filter with{VisibleMarkerCategories=new HashSet<string>()};map.RenderNowForProbe();
Require(map.VisibleWorldMarkers==0&&map.VisibleStars==missionStars,"Mission visibility changed the stellar query.");
map.Filter=map.Filter with{VisibleMarkerCategories=null,Values=new HashSet<string>()};map.RenderNowForProbe();
Require(map.VisibleWorldMarkers==0&&map.VisibleStars==0,"Mission glyphs bypassed an empty stellar query.");
// Only the edge/amounts in this renderer test are synthetic. Both
// endpoint IDs and positions remain actual recorded catalogue rows.
var edge=new GalaxyHistoricalTradeEdge(flowFrom.SystemAddress!.Value,flowTo.SystemAddress!.Value,"Gold",25,75,DateTimeOffset.UtcNow,flowFrom.SystemAddress.Value);
map.Systems=new[]{flowFrom,flowTo};map.HistoricalTradeFlows=new[]{new GalaxyHistoricalTradeFlow(edge,flowFrom,flowTo)};
map.Centre=flowFrom.Position;map.ResetCamera();map.Filter=GalaxyMapFilter.Default with{ShowHistoricalTradeFlows=true};map.RenderNowForProbe();
Require(map.VisibleHistoricalTradeSegments==1,"Resolved trade renderer test did not draw its directed edge.");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"synthetic-trade-renderer-probe.png"));
map.Filter=map.Filter with{HistoricalTradeCommodities=new HashSet<string>()};map.RenderNowForProbe();Require(map.VisibleHistoricalTradeSegments==0,"Empty trade commodity selection retained an edge.");
map.Filter=map.Filter with{HistoricalTradeCommodities=null,ShowHistoricalTradeFlows=false};map.RenderNowForProbe();Require(map.VisibleHistoricalTradeSegments==0,"Disabled historical trade layer retained an edge.");
// The metadata/style below is a declared renderer fixture. Its
// sole position and address remain from an actual catalogue row.
var territoryRequest=new GalaxyNativePowerTerritoryRequest(false,false,0);
var territoryStyle=new GalaxyNativePowerTerritoryStyle(1,4,3,5.775f,new[]{1f,.2f,.1f},new[]{1f,.0331f,.0101f},.15f);
var territoryTarget=flowFrom with{Data=new(){Power="Renderer fixture power",NativeFilterFacts=new("renderer-fixture",1,flowFrom.SystemAddress!.Value)
{PowerTerritory=new(territoryRequest,null,territoryStyle),PowerTerritoryOwnerName="Renderer fixture power",PowerStatus=new(1,4,0,3,0,0,true)}}};
map.Systems=[territoryTarget];map.HistoricalTradeFlows=[];map.Centre=territoryTarget.Position;map.ResetCamera();
map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Powerplay,Category=GalaxyFilterCategory.Power,ShowGrid=false,ShowRegionNames=false,ShowNebulaNames=false,ShowGalacticZonesPlane=false,ShowGalacticZoneNames=false};
map.RenderNowForProbe();Require(map.VisiblePowerContoursForProbe==1,"Bound original-layout territory fixture did not reach the GPU presentation.");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"synthetic-power-style-renderer-probe.png"));
map.Filter=GalaxyMapFilter.Default;map.RenderNowForProbe();Require(map.VisiblePowerContoursForProbe==0,"Leaving Territory retained a stale contour.");
map.Systems=[];map.HistoricalTradeFlows=[];map.CurrentSystem="";map.Selection=null;
map.Centre=new(0,0,26000);map.ResetCamera();map.Zoom(.002);map.AdvanceCameraMotionForProbe(256);
map.Filter=GalaxyMapFilter.Default with{ShowBackground=false,ShowGrid=false,ShowRegionNames=false,ShowNebulaNames=false,ShowGalacticZonesPlane=true,ShowGalacticZoneNames=true};
var zoneDeadline=Stopwatch.StartNew();
while(!map.GalacticZonesPlaneReadyForProbe&&zoneDeadline.Elapsed<TimeSpan.FromSeconds(8)){map.RenderNowForProbe();await Task.Delay(40);}
map.RenderNowForProbe();var zoneLabels=map.VisibleGalacticZoneLabels;
Require(!map.OriginalBackgroundHdrDrawnForProbe,"Disabling the background retained its HDR composite.");
Require(map.GalacticZonesPlaneDrawnForProbe&&zoneLabels>0&&map.VisibleStars==0,"Original GZM layers were unavailable or introduced stellar records.");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"original-galactic-zones-composite.png"));
map.Filter=map.Filter with{ShowGalacticZonesPlane=false};map.RenderNowForProbe();
Require(!map.GalacticZonesPlaneDrawnForProbe&&map.VisibleGalacticZoneLabels==zoneLabels,"Zone plane switch changed independent zone names.");
map.Filter=map.Filter with{ShowGalacticZoneNames=false};map.RenderNowForProbe();
Require(map.VisibleGalacticZoneLabels==0&&map.VisibleStars==0,"Zone name switch retained labels or introduced stars.");
var authoredBackground=await RunGalaxyAuthoredBackgroundProbeAsync(map,directory);
var constellation=await RunGalaxyConstellationProbeAsync(directory);
var currentTrade=await RunGalaxyCurrentTradeProbeAsync(directory);
var projectionBoundary=await RunGalaxyProjectionBoundaryProbeAsync(directory);
var cellSelection=await RunGalaxyCellSelectionProbeAsync(directory,recorded);
var frameFade=await RunGalaxyFrameFadeProbeAsync(directory,recorded);
var blackHole=await RunGalaxyBlackHoleProbeAsync(directory,recorded);
var powerRing=await RunGalaxyPowerRingProbeAsync(directory,recorded);
var colonisationHighlight=await RunGalaxyColonisationHighlightProbeAsync(directory,recorded);
await File.WriteAllTextAsync(Path.Combine(directory,"stream-frames.json"),JsonSerializer.Serialize(new{requests,frames,errors},new JsonSerializerOptions{WriteIndented=true}));
await File.WriteAllTextAsync(Path.Combine(directory,"stellar-sizing.json"),JsonSerializer.Serialize(new{farQuerySizing,nearQuerySizing,pixelMetrics},new JsonSerializerOptions{WriteIndented=true}));
return new{source="finite actual recorded catalogue set, injected offline provider",liveNativeCoverageConfirmed=false,generatedCatalogueCoordinates=false,
recordedCore=core.Length,recordedLocal=local.Length,loadedCore,loadedLocal,requestCount,returnedRows,cancelledRequests,maximumDuringMotion,
notificationsDuringMotion=motionNotifications,strictFilteredModels=filtered,selectedCurrentDoNotBypassQuery=true,emptyQueryLeavesNoStars=true,
unresolvedBackgroundStarsSuppressed=true,originalEngineerIcons=originalIcons,originalCurrentLocationArrow=true,markerSelectionUsesExactSystem=true,independentMarkerVisibility=true,
originalNamedRegionLabels=namedRegions,independentNameLayers=true,originalGalacticZoneLabels=zoneLabels,originalGalacticZonePlane=true,independentZoneLayers=true,
transparentOriginalAppearanceSynthetic=true,transparentSourceHasNoModelLabelOrHit=true,
missionMarkerSyntheticTypes=true,missionMarkerPositionActualRecorded=true,independentMissionMarkerVisibility=true,
tradeRendererSyntheticEdge=true,tradeEndpointsActualRecorded=true,powerContourSyntheticStyle=true,powerContourPositionActualRecorded=true,originalTerritoryBillboardRestored=map.OriginalPowerBillboardForProbe,originalTerritoryFillRestored=false,
authoredBackground,constellation,currentTrade,projectionBoundary,cellSelection,frameFade,blackHole,powerRing,colonisationHighlight,gameFlightCommandsInvoked=false,gameRestartInvoked=false};
}
finally
{
pageStop.Cancel();map.ViewportSettled-=Requested;ViewModel.PropertyChanged-=Changed;
ViewModel.SetGalaxyRegionQueryForProbe(null);map.SuspendPage();
}
}
}
using System.Diagnostics;
using System.Text.Json;
using XFEEDToolBox.Controls;
using XFEEDToolBox.Core.Galaxy;
using XFEEDToolBox.Core.Models;
namespace XFEEDToolBox;
public partial class App
{
private static async Task<object> RunGalaxyStreamingProbeAsync(string directory)
{
static void Require(bool value,string message){if(!value)throw new InvalidOperationException(message);}
var args=Environment.GetCommandLineArgs();
async Task<GalacticSystem[]> Read(string option)
{
var path=GetArgument(args,option)??throw new ArgumentException(option+" is required.");
using var document=JsonDocument.Parse(await File.ReadAllTextAsync(path));var root=document.RootElement;
return JsonSerializer.Deserialize<GalacticSystem[]>(root.ValueKind==JsonValueKind.Array?root:root.GetProperty("systems"),ToolboxSettings.JsonOptions)??[];
}
var core=await Read("--core-fixture");var local=await Read("--galaxy-fixture");
Require(core.Length==24000&&local.Length>100,"Actual recorded catalogue inputs are missing.");
var recorded=core.Concat(local).DistinctBy(s=>s.Name,StringComparer.OrdinalIgnoreCase).ToArray();
var sourceNames=recorded.Select(s=>s.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
var coreFocus=new Coordinates(25.21875,-20.90625,25899.96875);
var requests=new List<object>();var frames=new List<object>();var pixelMetrics=new Dictionary<string,object>();var requestCount=0;var returnedRows=0;var cancelledRequests=0;
// Completeness below applies ONLY to this finite recorded input set.
// This exercises application integration; it does not certify the live
// Stellar Forge response or invent stars outside the captured samples.
async Task<GalaxyRegionResult> RecordedQuery(Coordinates centre,double radius,CancellationToken token)
{
requestCount++;requests.Add(new{centre,radius,at=Environment.TickCount64});
try{await Task.Delay(85,token);}catch(OperationCanceledException){cancelledRequests++;throw;}
var rows=recorded.Where(s=>s.Position.DistanceTo(centre)<=radius).ToArray();returnedRows+=rows.Length;
return GalaxyRegionResult.Covered(rows);
}
ViewModel.SetGalaxyRegionQueryForProbe(RecordedQuery);ViewModel.GalaxyFilter=GalaxyMapFilter.Default;
var host=new Grid();MainWindow.Content=host;
var map=new GalaxyMapView{Centre=coreFocus,Filter=GalaxyMapFilter.Default};
host.Children.Add(map);await Task.Delay(150);map.ResetCamera();map.Zoom(.125);map.AdvanceCameraMotionForProbe(256);
using var pageStop=new CancellationTokenSource();var tasks=new List<Task>();var errors=new List<string>();
void Changed(object? sender,System.ComponentModel.PropertyChangedEventArgs e)
{if(e.PropertyName==nameof(ViewModel.GalaxySystems))map.Systems=ViewModel.GalaxySystems;}
ViewModel.PropertyChanged+=Changed;
async Task Stream(GalaxyViewport viewport)
{try{await ViewModel.StreamGalaxyRegionAsync(viewport,pageStop.Token);}catch(OperationCanceledException){}catch(Exception e){errors.Add(e.ToString());}}
void Requested(GalaxyViewport viewport)=>tasks.Add(Stream(viewport));
map.ViewportSettled+=Requested;
async Task Save(string name)
{
for(var wait=0;map.OriginalMilkyWayLoadPendingForProbe&&wait<100;wait++)
{await Task.Delay(20);map.RenderNowForProbe();}
map.RenderNowForProbe();var frame=map.CapturePixelsForProbe();
var bright=0;var peak=0;
for(var i=0;i<frame.Pixels.Length;i+=4)
{var value=Math.Max(frame.Pixels[i],Math.Max(frame.Pixels[i+1],frame.Pixels[i+2]));peak=Math.Max(peak,value);if(value>64)bright++;}
pixelMetrics[name]=new {frame.Width,frame.Height,rgbMaximumAbove64Pixels=bright,peakRgb=peak,
originalMilkyWayReady=map.OriginalMilkyWayReadyForProbe,originalMilkyWayInstances=map.OriginalMilkyWayInstancesForProbe,
originalCoreReady=map.OriginalCoreReadyForProbe,
originalBackgroundHdrDrawn=map.OriginalBackgroundHdrDrawnForProbe,
originalSceneHdrDrawn=map.OriginalSceneHdrDrawnForProbe,
originalGridSubmitted=map.OriginalGridSubmittedForProbe,originalGridWorldWidthRestored=map.OriginalGridWorldWidthForProbe};
await SaveModelFrameAsync(new(frame.Width,frame.Height,frame.Pixels,0),Path.Combine(directory,name+".png"));
}
try
{
map.FlushViewportForProbe();var before=map.ViewportNotifications;
var clock=Stopwatch.StartNew();var maximumDuringMotion=0;
for(var i=0;i<45;i++)
{
map.ApplyDragDelta(.9,.14,false);map.AdvanceCameraMotionForProbe();map.RenderNowForProbe();await Task.Delay(45);
maximumDuringMotion=Math.Max(maximumDuringMotion,ViewModel.GalaxySystems.Count);
frames.Add(new{milliseconds=clock.ElapsedMilliseconds,requests=requestCount,stars=map.VisibleStars,notifications=map.ViewportNotifications});
}
map.AdvanceCameraMotionForProbe(256);map.FlushViewportForProbe();
var deadline=clock.ElapsedMilliseconds+10000;
while(ViewModel.GalaxySystems.Count<500&&clock.ElapsedMilliseconds<deadline){await Task.Delay(70);map.RenderNowForProbe();}
Require(errors.Count==0,string.Join("\n",errors));
var motionNotifications=map.ViewportNotifications-before;
Require(motionNotifications>=6,"Continuous camera movement did not publish repeated viewports.");
Require(requestCount>2&&maximumDuringMotion>0,"Continuous camera movement starved catalogue queries.");
Require(ViewModel.GalaxySystems.Count>=500,"Recorded core was not progressively populated.");
Require(ViewModel.GalaxySystems.All(s=>sourceNames.Contains(s.Name)),"Streaming introduced an unrecorded star.");
var loadedCore=ViewModel.GalaxySystems.Count;await Save("stream-core-realistic");
Require(map.OriginalBackgroundHdrDrawnForProbe,"Original Core/MilkyWay did not reach the shared HDR final composite.");
Require(map.OriginalSceneHdrDrawnForProbe,"Stellar/world layers did not reach the common HDR composite.");
pageStop.Cancel();await Task.WhenAll(tasks.ToArray());
map.ViewportSettled-=Requested;
map.Zoom(.25);map.AdvanceCameraMotionForProbe(256);await Save("stream-core-original-milky-way-overview");
map.Zoom(4);map.AdvanceCameraMotionForProbe(256);
map.Systems=core;map.CurrentSystem=core[0].Name;map.Selection=core[0];
var selectedClass=GalaxyMapFilter.StarKey(core[0].StarClass);
var wanted=core.Select(s=>GalaxyMapFilter.StarKey(s.StarClass)).First(k=>k is not null&&k!=selectedClass)!;
map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Map,Values=new HashSet<string>{wanted},IncludeUnknown=false};map.RenderNowForProbe();
Require(map.VisibleModelsMatchFilter&&map.FilteredModels>0&&map.FilteredModels<core.Length,"Current/selected stars bypassed strict filtering.");
Require(map.QueryBackgroundStarsSuppressed,"Unclassified background stars remained in query mode.");
var filtered=map.FilteredModels;var farQuerySizing=map.ClassifiedSizingForProbe();await Save("stream-core-query");
// The far-view fixture has no native physical size fields. Inspect
// the same original classified style at a near scale separately;
// do not add a minimum-pixel size to make the far export brighter.
map.Centre=core.First(s=>GalaxyMapFilter.StarKey(s.StarClass)==wanted).Position;
map.ResetCamera();map.Zoom(2);map.AdvanceCameraMotionForProbe(256);map.RenderNowForProbe();
Require(map.VisibleStars>0&&map.VisibleModelsMatchFilter,"Near classified view lost its actual recorded query target.");
var nearQuerySizing=map.ClassifiedSizingForProbe();await Save("stream-core-query-near");
map.Filter=map.Filter with{Values=new HashSet<string>()};map.RenderNowForProbe();
Require(map.VisibleStars==0&&map.FilteredModels==0&&map.VisibleModelsMatchFilter,"Empty query left stellar models.");
await Save("stream-core-query-empty");
map.Filter=GalaxyMapFilter.Default;map.Systems=ViewModel.GalaxySystems;map.CurrentSystem="";map.ClearSelection();
ViewModel.SetGalaxyRegionQueryForProbe(RecordedQuery);ViewModel.GalaxyFilter=GalaxyMapFilter.Default;
using var localStop=new CancellationTokenSource(TimeSpan.FromSeconds(12));
map.Centre=new(0,0,0);map.ResetCamera();
var localTask=ViewModel.StreamGalaxyRegionAsync(map.RequestedViewportForProbe,localStop.Token);
while(ViewModel.GalaxySystems.Count<100&&!localTask.IsCompleted){await Task.Delay(50);map.RenderNowForProbe();}
localStop.Cancel();try{await localTask;}catch(OperationCanceledException){}
Require(ViewModel.GalaxySystems.Count>=100&&ViewModel.GalaxySystems.All(s=>Math.Abs(s.Position.Z)<1000),"New disjoint view retained old core results or failed to query local records.");
var loadedLocal=ViewModel.GalaxySystems.Count;await Save("stream-local-after-core");
map.Systems=EngineerDirectory.All.Select(e=>new GalacticSystem(e.SystemName,e.Position,Source:"Verified engineer directory"){Data=new(){Markers=["engineer"]}}).ToArray();
map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Map,Category=GalaxyFilterCategory.Markers,Values=new HashSet<string>{"engineer"}};
map.Centre=new(0,0,0);map.ResetCamera();map.Zoom(.3);map.AdvanceCameraMotionForProbe(256);await Task.Delay(350);map.RenderNowForProbe();
Require(map.VisibleWorldMarkers>0,"Known engineer records did not display original game icons.");
var iconTarget=map.WorldMarkerBoundsForProbe[0];var iconAt=new Windows.Foundation.Point(iconTarget.Bounds.X+13,iconTarget.Bounds.Y+13);
map.BeginPointer(iconAt,false);map.EndPointer(iconAt);Require(map.Selection?.Name==iconTarget.System.Name,"Clicking a marker selected another star.");
map.CurrentSystem=iconTarget.System.Name;map.RenderNowForProbe();Require(map.VisibleCurrentLocationMarker,"Current system did not display the original location arrow.");
var originalIcons=map.VisibleWorldMarkers;await Save("actual-engineer-markers");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"actual-engineer-markers-composite.png"));
var starsWithIcons=map.VisibleStars;map.Filter=map.Filter with{VisibleMarkerCategories=new HashSet<string>()};map.RenderNowForProbe();
Require(map.VisibleWorldMarkers==0&&map.VisibleStars==starsWithIcons,"Individual marker display switches changed the stellar query.");
map.Filter=map.Filter with{VisibleMarkerCategories=new HashSet<string>{"engineer"}};map.RenderNowForProbe();
Require(map.VisibleWorldMarkers>0&&map.VisibleStars==starsWithIcons,"Restoring the engineer display flag changed its query targets.");
map.Filter=map.Filter with{ShowMarkers=false};map.RenderNowForProbe();Require(map.VisibleWorldMarkers==0&&!map.VisibleCurrentLocationMarker,"Marker switch left original icons visible.");
map.Filter=GalaxyMapFilter.Default;map.RenderNowForProbe();
var namedRegions=map.VisibleRegionNameLabels;var starsBeforeNames=map.VisibleStars;
Require(namedRegions>0,"Original authored region names did not project near their source coordinates.");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"original-region-names-composite.png"));
await File.WriteAllTextAsync(Path.Combine(directory,"annotation-metrics.json"),JsonSerializer.Serialize(map.AnnotationMetricsForProbe,new JsonSerializerOptions{WriteIndented=true}));
map.Filter=map.Filter with{ShowRegionNames=false,ShowNebulaNames=false};map.RenderNowForProbe();
Require(map.VisibleRegionNameLabels==0&&map.VisibleNebulaNameLabels==0&&map.VisibleStars==starsBeforeNames,"Name-layer switches changed stellar filtering.");
var flowFrom=local.First(s=>s.SystemAddress is >0);var flowTo=local.First(s=>s.SystemAddress is >0&&s.SystemAddress!=flowFrom.SystemAddress&&s.Position.DistanceTo(flowFrom.Position) is >5 and <80);
// Synthetic appearance tests alpha=0 across the entire visible
// object pipeline, using an actual recorded address/position.
var transparentTarget=flowFrom with{OriginalAppearance=new(0x00112233,0x00445566,null,0,0,1,1,false),Data=new()};
map.Systems=[transparentTarget];map.CurrentSystem=transparentTarget.Name;map.Selection=transparentTarget;
map.Centre=transparentTarget.Position;map.ResetCamera();map.Filter=GalaxyMapFilter.Default;map.RenderNowForProbe();
Require(map.VisibleStars==0&&map.FilteredModels==0&&map.VisibleNameLabels==0&&!map.VisibleCurrentLocationMarker,"An explicitly transparent original source retained a stellar object, label or current marker.");
map.SelectAt(map.ProjectForProbe(transparentTarget.Position));Require(map.Selection is null,"An invisible original source remained selectable.");
// Declared runtime-marker fixture; the sole stellar address and
// coordinates remain an actual recorded catalogue entry.
var missionTarget=flowFrom with{Data=new(){NativeAccountMarkers=new("renderer-fixture",1,["mission"]){MissionMarkerTypes=[4,45]}}};
map.Systems=[missionTarget];map.CurrentSystem="";map.ClearSelection();map.Centre=missionTarget.Position;map.ResetCamera();
map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Map,Category=GalaxyFilterCategory.Markers,Values=new HashSet<string>{"mission"}};
map.RenderNowForProbe();Require(map.VisibleWorldMarkers==2,"Two actual mission marker types at one recorded system lost a glyph.");
foreach(var marker in map.WorldMarkerBoundsForProbe.ToArray())
{var point=new Windows.Foundation.Point(marker.Bounds.X+13,marker.Bounds.Y+13);map.BeginPointer(point,false);map.EndPointer(point);Require(map.Selection?.SystemAddress==missionTarget.SystemAddress,"Mission glyph did not select its exact system.");}
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"synthetic-mission-marker-styles-probe.png"));
var missionStars=map.VisibleStars;map.Filter=map.Filter with{VisibleMarkerCategories=new HashSet<string>()};map.RenderNowForProbe();
Require(map.VisibleWorldMarkers==0&&map.VisibleStars==missionStars,"Mission visibility changed the stellar query.");
map.Filter=map.Filter with{VisibleMarkerCategories=null,Values=new HashSet<string>()};map.RenderNowForProbe();
Require(map.VisibleWorldMarkers==0&&map.VisibleStars==0,"Mission glyphs bypassed an empty stellar query.");
// Only the edge/amounts in this renderer test are synthetic. Both
// endpoint IDs and positions remain actual recorded catalogue rows.
var edge=new GalaxyHistoricalTradeEdge(flowFrom.SystemAddress!.Value,flowTo.SystemAddress!.Value,"Gold",25,75,DateTimeOffset.UtcNow,flowFrom.SystemAddress.Value);
map.Systems=new[]{flowFrom,flowTo};map.HistoricalTradeFlows=new[]{new GalaxyHistoricalTradeFlow(edge,flowFrom,flowTo)};
map.Centre=flowFrom.Position;map.ResetCamera();map.Filter=GalaxyMapFilter.Default with{ShowHistoricalTradeFlows=true};map.RenderNowForProbe();
Require(map.VisibleHistoricalTradeSegments==1,"Resolved trade renderer test did not draw its directed edge.");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"synthetic-trade-renderer-probe.png"));
map.Filter=map.Filter with{HistoricalTradeCommodities=new HashSet<string>()};map.RenderNowForProbe();Require(map.VisibleHistoricalTradeSegments==0,"Empty trade commodity selection retained an edge.");
map.Filter=map.Filter with{HistoricalTradeCommodities=null,ShowHistoricalTradeFlows=false};map.RenderNowForProbe();Require(map.VisibleHistoricalTradeSegments==0,"Disabled historical trade layer retained an edge.");
// The metadata/style below is a declared renderer fixture. Its
// sole position and address remain from an actual catalogue row.
var territoryRequest=new GalaxyNativePowerTerritoryRequest(false,false,0);
var territoryStyle=new GalaxyNativePowerTerritoryStyle(1,4,3,5.775f,new[]{1f,.2f,.1f},new[]{1f,.0331f,.0101f},.15f);
var territoryTarget=flowFrom with{Data=new(){Power="Renderer fixture power",NativeFilterFacts=new("renderer-fixture",1,flowFrom.SystemAddress!.Value)
{PowerTerritory=new(territoryRequest,null,territoryStyle),PowerTerritoryOwnerName="Renderer fixture power",PowerStatus=new(1,4,0,3,0,0,true)}}};
map.Systems=[territoryTarget];map.HistoricalTradeFlows=[];map.Centre=territoryTarget.Position;map.ResetCamera();
map.Filter=GalaxyMapFilter.Default with{Mode=GalaxyMapMode.Powerplay,Category=GalaxyFilterCategory.Power,ShowGrid=false,ShowRegionNames=false,ShowNebulaNames=false,ShowGalacticZonesPlane=false,ShowGalacticZoneNames=false};
map.RenderNowForProbe();Require(map.VisiblePowerContoursForProbe==1,"Bound original-layout territory fixture did not reach the GPU presentation.");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"synthetic-power-style-renderer-probe.png"));
map.Filter=GalaxyMapFilter.Default;map.RenderNowForProbe();Require(map.VisiblePowerContoursForProbe==0,"Leaving Territory retained a stale contour.");
map.Systems=[];map.HistoricalTradeFlows=[];map.CurrentSystem="";map.Selection=null;
map.Centre=new(0,0,26000);map.ResetCamera();map.Zoom(.002);map.AdvanceCameraMotionForProbe(256);
map.Filter=GalaxyMapFilter.Default with{ShowBackground=false,ShowGrid=false,ShowRegionNames=false,ShowNebulaNames=false,ShowGalacticZonesPlane=true,ShowGalacticZoneNames=true};
var zoneDeadline=Stopwatch.StartNew();
while(!map.GalacticZonesPlaneReadyForProbe&&zoneDeadline.Elapsed<TimeSpan.FromSeconds(8)){map.RenderNowForProbe();await Task.Delay(40);}
map.RenderNowForProbe();var zoneLabels=map.VisibleGalacticZoneLabels;
Require(!map.OriginalBackgroundHdrDrawnForProbe,"Disabling the background retained its HDR composite.");
Require(map.GalacticZonesPlaneDrawnForProbe&&zoneLabels>0&&map.VisibleStars==0,"Original GZM layers were unavailable or introduced stellar records.");
using(await map.FreezeForXamlProbeAsync())await CaptureRefinementElementAsync(host,Path.Combine(directory,"original-galactic-zones-composite.png"));
map.Filter=map.Filter with{ShowGalacticZonesPlane=false};map.RenderNowForProbe();
Require(!map.GalacticZonesPlaneDrawnForProbe&&map.VisibleGalacticZoneLabels==zoneLabels,"Zone plane switch changed independent zone names.");
map.Filter=map.Filter with{ShowGalacticZoneNames=false};map.RenderNowForProbe();
Require(map.VisibleGalacticZoneLabels==0&&map.VisibleStars==0,"Zone name switch retained labels or introduced stars.");
var authoredBackground=await RunGalaxyAuthoredBackgroundProbeAsync(map,directory);
var constellation=await RunGalaxyConstellationProbeAsync(directory);
var currentTrade=await RunGalaxyCurrentTradeProbeAsync(directory);
var projectionBoundary=await RunGalaxyProjectionBoundaryProbeAsync(directory);
var cellSelection=await RunGalaxyCellSelectionProbeAsync(directory,recorded);
var frameFade=await RunGalaxyFrameFadeProbeAsync(directory,recorded);
var blackHole=await RunGalaxyBlackHoleProbeAsync(directory,recorded);
var powerRing=await RunGalaxyPowerRingProbeAsync(directory,recorded);
var colonisationHighlight=await RunGalaxyColonisationHighlightProbeAsync(directory,recorded);
await File.WriteAllTextAsync(Path.Combine(directory,"stream-frames.json"),JsonSerializer.Serialize(new{requests,frames,errors},new JsonSerializerOptions{WriteIndented=true}));
await File.WriteAllTextAsync(Path.Combine(directory,"stellar-sizing.json"),JsonSerializer.Serialize(new{farQuerySizing,nearQuerySizing,pixelMetrics},new JsonSerializerOptions{WriteIndented=true}));
return new{source="finite actual recorded catalogue set, injected offline provider",liveNativeCoverageConfirmed=false,generatedCatalogueCoordinates=false,
recordedCore=core.Length,recordedLocal=local.Length,loadedCore,loadedLocal,requestCount,returnedRows,cancelledRequests,maximumDuringMotion,
notificationsDuringMotion=motionNotifications,strictFilteredModels=filtered,selectedCurrentDoNotBypassQuery=true,emptyQueryLeavesNoStars=true,
unresolvedBackgroundStarsSuppressed=true,originalEngineerIcons=originalIcons,originalCurrentLocationArrow=true,markerSelectionUsesExactSystem=true,independentMarkerVisibility=true,
originalNamedRegionLabels=namedRegions,independentNameLayers=true,originalGalacticZoneLabels=zoneLabels,originalGalacticZonePlane=true,independentZoneLayers=true,
transparentOriginalAppearanceSynthetic=true,transparentSourceHasNoModelLabelOrHit=true,
missionMarkerSyntheticTypes=true,missionMarkerPositionActualRecorded=true,independentMissionMarkerVisibility=true,
tradeRendererSyntheticEdge=true,tradeEndpointsActualRecorded=true,powerContourSyntheticStyle=true,powerContourPositionActualRecorded=true,originalTerritoryBillboardRestored=map.OriginalPowerBillboardForProbe,originalTerritoryFillRestored=false,
authoredBackground,constellation,currentTrade,projectionBoundary,cellSelection,frameFade,blackHole,powerRing,colonisationHighlight,gameFlightCommandsInvoked=false,gameRestartInvoked=false};
}
finally
{
pageStop.Cancel();map.ViewportSettled-=Requested;ViewModel.PropertyChanged-=Changed;
ViewModel.SetGalaxyRegionQueryForProbe(null);map.SuspendPage();
}
}
}