using System.Runtime.InteropServices; namespace XFEEDToolBox.Plugin; internal static unsafe partial class Navigation { static uint GalaxyAppearanceSelfTest() { var memory=Platform.Allocate(1024);if(memory==0)return 0; try { uint passed=0;var tree=memory;var root=memory+128;var lesser=memory+256;var greater=memory+384; Write(tree+8,3UL);Write(tree+0x10,root); Write(root,greater);Write(root+8,lesser);Write(root+0x1C,4);Write(root+0x20,(byte)5);Write(root+0x2C,0xFFAABBCCu); Write(lesser+0x1C,4);Write(lesser+0x20,(byte)2);Write(lesser+0x2C,0xFF112233u); Write(greater+0x1C,5);Write(greater+0x20,(byte)1);Write(greater+0x2C,0xFF445566u); if(GalaxyAppearanceLuminosityGroup(0)==1&&GalaxyAppearanceLuminosityGroup(2<<10)==1&& GalaxyAppearanceLuminosityGroup(6<<10)==7&&GalaxyAppearanceLuminosityGroup(14<<10)==5&& GalaxyAppearanceLuminosityGroup(23<<10)==6&&GalaxyAppearanceLuminosityGroup(24<<10)==-1)passed|=1; if(GalaxyAppearanceTree(tree,4,5,out var colour)&&colour==0xFFAABBCC&& GalaxyAppearanceTree(tree,4,2,out colour)&&colour==0xFF112233&& GalaxyAppearanceTree(tree,5,1,out colour)&&colour==0xFF445566)passed|=2; var before=Platform.ReadBytes(tree,1024); if(!GalaxyAppearanceTree(tree,4,3,out _)&&!GalaxyAppearanceTree(tree,6,0,out _)&& Platform.ReadBytes(tree,1024).AsSpan().SequenceEqual(before))passed|=4; Write(lesser+8,lesser); if(!GalaxyAppearanceTree(tree,3,0,out _))passed|=8; Write(lesser+8,(nuint)0); if(GalaxyAppearanceMix(0xFF000000,0xFFFFFFFF,0)==0xFF000000&& GalaxyAppearanceMix(0xFF000000,0xFFFFFFFF,1)==0xFFFFFFFF&& GalaxyAppearanceMix(0xFF000000,0xFFFFFFFF,.5f)==0xFF7F7F7F)passed|=16; var normal=GalaxyAppearanceSize(32768,4,false);var small=GalaxyAppearanceSize(32768,4,true); if(Math.Abs(normal-(.3f+3f/11f*.9f))<1e-6f&&Math.Abs(small-(.05f+3f/11f*1.45f))<1e-6f&& GalaxyAppearanceSize(0,4,false)==.3f&&GalaxyAppearanceSize(uint.MaxValue,4,false)==1.2f&& GalaxyAppearanceSize(32768,40,false)==.3f&&GalaxyAppearanceSize(32768,41,true)==.05f)passed|=32; var fakeImage=tree-0x5FDF2A0; if(GalaxyAppearancePhysicalColour(fakeImage,4|(5<<6),0,0xFF000000,out colour)&&colour==0xFFAABBCC&& GalaxyAppearancePhysicalColour(fakeImage,4|(24<<10),0,0xFF123456,out colour)&&colour==0xFF123456)passed|=64; // The original prototype-star temperature buckets have sparse // globals. Allocate only the exact bounded span used by the port. var temperature=Platform.Allocate(0xAA6300); if(temperature!=0) { try { var expectedImage=temperature-0x5539320; Write(temperature,10u);Write(temperature+4,100u); Write(expectedImage+0x5FDF490,1000u);Write(expectedImage+0x5FDF494,2000u); Write(expectedImage+0x5FDF498,0u);Write(expectedImage+0x5FDF4A0,temperature+128); Write(expectedImage+0x5FDF4B0,10u);Write(expectedImage+0x5FDF4B8,temperature+2048); Write(temperature+128+50*8,4UL|(2UL<<32));Write(temperature+2048+5*8,5UL|(3UL<<32)); Write(expectedImage+0x5FDF4C8,0UL|(1UL<<32)); var valid=GalaxyAppearanceTemperatureKey(expectedImage,500,out var type,out var minor)&&type==4&&minor==2&& GalaxyAppearanceTemperatureKey(expectedImage,1500,out type,out minor)&&type==5&&minor==3&& GalaxyAppearanceTemperatureKey(expectedImage,2500,out type,out minor)&&type==0&&minor==1; Write(expectedImage+0x5FDF494,1u); if(valid&&!GalaxyAppearanceTemperatureKey(expectedImage,500,out _,out _))passed|=128; } finally{Platform.Free(temperature);} } return passed; } finally{Platform.Free(memory);} } #if PLUGIN_NAVIGATION [UnmanagedCallersOnly(EntryPoint="XFENavigationGalaxyAppearanceSelfTest")] internal static uint ExportGalaxyAppearanceSelfTest()=>RunTest(GalaxyAppearanceSelfTest); #endif }