{"TotalCount":41,"Files":[{"Ident":"chomnr.squishy_terry","Path":".obj/__compiler_extra.cs","FileName":"__compiler_extra.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"global using static Sandbox.Internal.GlobalGameNamespace;\r\nglobal using Microsoft.AspNetCore.Components;\r\nglobal using Microsoft.AspNetCore.Components.Rendering;\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022AddonTitle\u0022, \u0022Squishy Terry\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022AddonIdent\u0022, \u0022squishy_terry\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022OrgIdent\u0022, \u0022chomnr\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022Ident\u0022, \u0022chomnr.squishy_terry\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022EngineVersion\u0022, \u002229\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022EngineMinorVersion\u0022, \u00221\u0022 )]\r\n\r\n[assembly: System.Runtime.Versioning.TargetFramework( \u0022.NETCoreApp,Version=v9.0\u0022, FrameworkDisplayName = \u0022.NET 9.0\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyMetadata( \u0022CompileTime\u0022, \u00222026-09-27T23:41:50.3880674Z\u0022 )]\r\n[assembly: global::System.Reflection.AssemblyVersion(\u00220.0.264.0\u0022)]\r\n[assembly: global::System.Reflection.AssemblyFileVersion(\u00220.0.264.0\u0022)]"},{"Ident":"chomnr.squishy_terry","Path":"Audio/FaceAudio.cs","FileName":"FaceAudio.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\nusing Sandbox;\nusing SquishyTerry.Sim;\n\nnamespace SquishyTerry.Audio;\n\n/// \u003Csummary\u003E\n/// Plays the face\u0027s procedural voice: runs \u003Csee cref=\u0022FaceSynth\u0022/\u003E (the original game\u0027s audio patch) and streams it\n/// through a \u003Csee cref=\u0022SoundStream\u0022/\u003E. If a sibling \u003Csee cref=\u0022SquishyFace\u0022/\u003E exists, its state is sent to the synth\n/// every frame exactly like the original game did (volume, area, dragging, drag delta / distance, slap on snap-back).\n/// Without one, call \u003Csee cref=\u0022SetParameters\u0022/\u003E yourself each frame.\n/// \u003Cpara\u003E\n/// \u003Csee cref=\u0022Voice\u0022/\u003E picks the sound: \u003Csee cref=\u0022VoiceStyle.Original\u0022/\u003E is the recovered patch exactly as the\n/// original game played it; \u003Csee cref=\u0022VoiceStyle.Terry\u0022/\u003E adds Terry\u0027s vocal grunts (\u003Csee cref=\u0022GruntVoice\u0022/\u003E);\n/// \u003Csee cref=\u0022VoiceStyle.Variation\u0022/\u003E is a subtly varied original. The original patch code is shared and never modified.\n/// \u003C/para\u003E\n/// \u003C/summary\u003E\npublic sealed class FaceAudio : Component\n{\n\tpublic enum VoiceStyle\n\t{\n\t\t/// \u003Csummary\u003EThe original game\u0027s audio, unchanged.\u003C/summary\u003E\n\t\tOriginal,\n\t\t/// \u003Csummary\u003EThe original patch plus Terry\u0027s grunts: \u0022hmph\u0022 when stretched hard, \u0022oof\u0022 when squished.\u003C/summary\u003E\n\t\tTerry,\n\t\t/// \u003Csummary\u003E\n\t\t/// The original patch, subtly varied: pitched up a little, a slightly different mix, and a small random\n\t\t/// tone change on every grab so no two squishes sound quite the same.\n\t\t/// \u003C/summary\u003E\n\t\tVariation,\n\t}\n\n\t/// \u003Csummary\u003EWhich voice to play. Switch to Original for the untouched original audio.\u003C/summary\u003E\n\t[Property] public VoiceStyle Voice { get; set; } = VoiceStyle.Terry;\n\n\t/// \u003Csummary\u003EVariation voice: playback pitch (1 = original).\u003C/summary\u003E\n\t[Property, Range( 0.8f, 1.25f ), ShowIf( nameof( Voice ), VoiceStyle.Variation )] public float VariationPitch { get; set; } = 1.08f;\n\n\t/// \u003Csummary\u003EVariation voice: largest random tone change applied per grab (0 = none).\u003C/summary\u003E\n\t[Property, Range( 0f, 0.6f ), ShowIf( nameof( Voice ), VoiceStyle.Variation )] public float VariationSpread { get; set; } = 0.35f;\n\n\t/// \u003Csummary\u003ETerry voice: loudness of the grunts.\u003C/summary\u003E\n\t[Property, Range( 0f, 2f ), ShowIf( nameof( Voice ), VoiceStyle.Terry )] public float GruntLevel { get; set; } = 1f;\n\n\t/// \u003Csummary\u003ETerry voice: pitch of his voice in Hz (lower = deeper).\u003C/summary\u003E\n\t[Property, Range( 60f, 200f ), ShowIf( nameof( Voice ), VoiceStyle.Terry )] public float GruntPitch { get; set; } = 98f;\n\n\t/// \u003Csummary\u003EOutput volume of the stream (the patch\u0027s own master volume is applied on top).\u003C/summary\u003E\n\t[Property, Range( 0, 2 )] public float Volume { get; set; } = 1f;\n\n\t/// \u003Csummary\u003EHow far ahead of playback the synth renders, in seconds.\u003C/summary\u003E\n\t[Property, Range( 0.02f, 0.25f )] public float BufferAhead { get; set; } = 0.12f;\n\n\t/// \u003Csummary\u003ERead parameters from a sibling \u003Csee cref=\u0022SquishyFace\u0022/\u003E automatically.\u003C/summary\u003E\n\t[Property] public bool FollowFace { get; set; } = true;\n\n\t/// \u003Csummary\u003EThe synth instance (null until the component starts).\u003C/summary\u003E\n\tpublic FaceSynth Synth { get; private set; }\n\n\tconst int Channels = 2;\n\n\tSoundStream _stream;\n\tSoundHandle _handle;\n\tfloat[] _left = Array.Empty\u003Cfloat\u003E();\n\tfloat[] _right = Array.Empty\u003Cfloat\u003E();\n\tshort[] _pcm = Array.Empty\u003Cshort\u003E();\n\n\tSquishyFace _face;\n\tbool _slapPending;\n\treadonly GruntVoice _grunt = new();\n\tVoiceStyle? _mixFor;\n\tbool _wasDragging;\n\tfloat _grabTone;\n\treadonly Random _random = new();\n\n\tprotected override void OnEnabled()\n\t{\n\t\tSynth = new FaceSynth();\n\n\t\t// Same start-up messages as the original game (ie.prototype.start); ApplyMix sets the volumes.\n\t\tApplyMix();\n\t\tSynth.SetParameter( \u0022init\u0022, 500f );\n\n\t\t_stream = new SoundStream( FaceSynth.SampleRate, Channels );\n\t\t_handle = _stream.Play( Volume, 1f );\n\t\tif ( _handle is not null \u0026\u0026 _handle.IsValid )\n\t\t{\n\t\t\t_handle.SpacialBlend = 0f;\n\t\t\t_handle.ListenLocal = true;\n\t\t}\n\n\t\t// Prime the stream so playback starts with a full buffer.\n\t\tRender( (int)(BufferAhead * FaceSynth.SampleRate) );\n\t}\n\n\t/// \u003Csummary\u003ESends the voice\u0027s mix levels (the original game\u0027s values unless Variation is selected).\u003C/summary\u003E\n\tvoid ApplyMix()\n\t{\n\t\tbool variation = Voice == VoiceStyle.Variation;\n\t\tSynth.SetParameter( \u0022vol_gloop\u0022, variation ? 0.98f : 0.8f );\n\t\tSynth.SetParameter( \u0022vol_master\u0022, 0.6f );\n\t\tSynth.SetParameter( \u0022vol_slap\u0022, variation ? 0.52f : 0.4f );\n\t\tSynth.SetParameter( \u0022vol_slosh\u0022, variation ? 0.5f : 0.66f );\n\t\tSynth.SetParameter( \u0022vol_stretch\u0022, 0.7f );\n\t\t_mixFor = Voice;\n\t}\n\n\tprotected override void OnDisabled()\n\t{\n\t\tif ( _handle is not null \u0026\u0026 _handle.IsValid ) _handle.Stop( 0f );\n\t\t_handle = null;\n\t\t_stream?.Dispose();\n\t\t_stream = null;\n\t\tSynth = null;\n\t\tif ( _face is not null ) _face.Slapped -= OnSlapped;\n\t\t_face = null;\n\t}\n\n\tprotected override void OnUpdate()\n\t{\n\t\tif ( Synth is null || _stream is null ) return;\n\t\tif ( _mixFor != Voice ) ApplyMix();\n\t\tif ( _handle is not null \u0026\u0026 _handle.IsValid )\n\t\t{\n\t\t\t_handle.Volume = Volume;\n\t\t\t_handle.Pitch = Voice == VoiceStyle.Variation ? VariationPitch : 1f;\n\t\t}\n\n\t\tif ( FollowFace ) SendFaceParameters();\n\n\t\tint target = (int)(BufferAhead * FaceSynth.SampleRate);\n\t\tint queued = _stream.QueuedSampleCount / Channels;\n\t\tif ( queued \u003C target ) Render( target - queued );\n\t}\n\n\t/// \u003Csummary\u003E\n\t/// Sends one frame of parameters, the way the original game did: values with |x| \u0026lt; 1e-4 are sent as 0 and\n\t/// \u003Cparamref name=\u0022slap\u0022/\u003E sends a one-shot slap = 1.\n\t/// \u003C/summary\u003E\n\tpublic void SetParameters( float volume, float area, bool dragging, float dx, float dy, float dz, float dragDistance, bool slap )\n\t{\n\t\tif ( Synth is null ) return;\n\n\t\tif ( Voice == VoiceStyle.Terry )\n\t\t{\n\t\t\t_grunt.BasePitch = GruntPitch;\n\t\t\t_grunt.Update( dragging, dragDistance, volume, slap, Time.Delta );\n\t\t}\n\t\telse if ( Voice == VoiceStyle.Variation )\n\t\t{\n\t\t\t// A new small tone offset for every grab, held until the next one.\n\t\t\tif ( dragging \u0026\u0026 !_wasDragging ) _grabTone = ((float)_random.NextDouble() * 2f - 1f) * VariationSpread;\n\t\t\tarea \u002B= _grabTone;\n\t\t}\n\t\t_wasDragging = dragging;\n\n\n\t\tSend( \u0022volume\u0022, volume );\n\t\tSend( \u0022area\u0022, area );\n\t\tSend( \u0022dragging\u0022, dragging ? 1f : 0f );\n\t\tif ( slap ) Send( \u0022slap\u0022, 1f );\n\t\tSend( \u0022drag_delta_x\u0022, dx );\n\t\tSend( \u0022drag_delta_y\u0022, dy );\n\t\tSend( \u0022drag_delta_z\u0022, dz );\n\t\tSend( \u0022drag_distance\u0022, dragDistance );\n\t}\n\n\tvoid Send( string name, float value )\n\t{\n\t\tSynth.SetParameter( name, MathF.Abs( value ) \u003C 1e-4f ? 0f : value );\n\t}\n\n\tvoid OnSlapped() =\u003E _slapPending = true;\n\n\tvoid SendFaceParameters()\n\t{\n\t\tif ( _face is null )\n\t\t{\n\t\t\t_face = Components.Get\u003CSquishyFace\u003E();\n\t\t\tif ( _face is null ) return;\n\t\t\t_face.Slapped \u002B= OnSlapped;\n\t\t}\n\n\t\tvar sim = _face.Sim;\n\t\tif ( sim is null ) return;\n\n\t\t// Drag delta: the grabbed triangle\u0027s first vertex relative to its rest position.\n\t\tfloat dx = 0, dy = 0, dz = 0;\n\t\tint dragTri = _face.DraggingTriangle;\n\t\tif ( dragTri != -1 )\n\t\t{\n\t\t\tvar d = sim.Pos[sim.Indices[dragTri * 3]] - _face.RestPosition( dragTri );\n\t\t\tdx = d.X;\n\t\t\tdy = d.Y;\n\t\t\tdz = d.Z;\n\t\t}\n\n\t\tbool slap = _slapPending;\n\t\t_slapPending = false;\n\n\t\tSetParameters( _face.AudioVolume, _face.AudioArea, dragTri != -1, dx, dy, dz,\n\t\t\tMathF.Sqrt( dx * dx \u002B dy * dy \u002B dz * dz ), slap );\n\t}\n\n\tvoid Render( int frames )\n\t{\n\t\tif ( frames \u003C= 0 ) return;\n\t\tint max = _stream.MaxWriteSampleCount / Channels;\n\t\tif ( max \u003E 0 \u0026\u0026 frames \u003E max ) frames = max;\n\n\t\tif ( _left.Length \u003C frames )\n\t\t{\n\t\t\t_left = new float[frames];\n\t\t\t_right = new float[frames];\n\t\t\t_pcm = new short[frames * Channels];\n\t\t}\n\n\t\tSynth.Process( _left.AsSpan( 0, frames ), _right.AsSpan( 0, frames ) );\n\n\t\tif ( Voice == VoiceStyle.Terry )\n\t\t{\n\t\t\t_grunt.Level = GruntLevel;\n\t\t\t_grunt.MixInto( _left.AsSpan( 0, frames ), _right.AsSpan( 0, frames ) );\n\n\t\t\t// Gentle limiter so the extra layer can\u0027t clip (near-linear at normal levels).\n\t\t\tfor ( int i = 0; i \u003C frames; i\u002B\u002B )\n\t\t\t{\n\t\t\t\t_left[i] = MathF.Tanh( _left[i] );\n\t\t\t\t_right[i] = MathF.Tanh( _right[i] );\n\t\t\t}\n\t\t}\n\n\t\tfor ( int i = 0; i \u003C frames; i\u002B\u002B )\n\t\t{\n\t\t\t_pcm[i * 2] = ToPcm( _left[i] );\n\t\t\t_pcm[i * 2 \u002B 1] = ToPcm( _right[i] );\n\t\t}\n\t\t_stream.WriteData( _pcm.AsSpan( 0, frames * Channels ) );\n\t}\n\n\tstatic short ToPcm( float x )\n\t{\n\t\tfloat s = x * 32767f;\n\t\tif ( s \u003E 32767f ) s = 32767f;\n\t\telse if ( s \u003C -32768f ) s = -32768f;\n\t\treturn (short)s;\n\t}\n}\n"},{"Ident":"chomnr.squishy_terry","Path":"Audio/FaceSynth.cs","FileName":"FaceSynth.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\n\nnamespace SquishyTerry.Audio;\n\n/// \u003Csummary\u003E\n/// C# port of the original game\u0027s Heavy (hvcc / Pure Data) patch \u0022facesynth\u0022, the procedural voice of the face.\n/// \u003Cpara\u003E\n/// The patch has four voices, all mixed through an area dependent body resonator:\n/// \u003Cb\u003Eslap\u003C/b\u003E (release smack: filtered noise burst plus a ringing vcf~),\n/// \u003Cb\u003Eslosh\u003C/b\u003E (wet droplets whose density follows how fast the face volume changes),\n/// \u003Cb\u003Egloop\u003C/b\u003E (two bubble voices with rising pitch, triggered by fast drag changes) and\n/// \u003Cb\u003Estretch\u003C/b\u003E (two \u0022creak\u0022 voices built from a recorded click grain, driven by the rate of change of area).\n/// \u003C/para\u003E\n/// \u003Cpara\u003E\n/// The port is split in three files:\n/// this file holds the public API, the Heavy message runtime and the per sample signal graph (a line by line\n/// port of the patch\u0027s DSP loop, keeping the original operation order so the output matches the original to\n/// the last bit in most samples); \u003Cc\u003EFaceSynth.PowF.cs\u003C/c\u003E is musl\u0027s powf (so [pow] / mtof match the original);\n/// \u003Cc\u003EFaceSynthGraph.cs\u003C/c\u003E is the patch\u0027s control message graph, generated from\n/// the original binary (every Pd object keeps its original memory offset as its name suffix);\n/// \u003Cc\u003EFaceSynthTables.cs\u003C/c\u003E holds the table data.\n/// \u003C/para\u003E\n/// \u003Cpara\u003EThe synth always runs at 44100 Hz (the patch hard codes 44100 in the gloop timer and the creak grain rate).\u003C/para\u003E\n/// \u003C/summary\u003E\npublic sealed partial class FaceSynth\n{\n\t/// \u003Csummary\u003EInternal sample rate. The original patch hard codes this value in several places.\u003C/summary\u003E\n\tpublic const int SampleRate = 44100;\n\n\t/// \u003Csummary\u003EHash of the patch\u0027s internal loadbang receiver (\u003Cc\u003E__hv_init\u003C/c\u003E).\u003C/summary\u003E\n\tconst uint LoadbangHash = 0xCE5CC65B;\n\n\t/// \u003Csummary\u003ENumber of samples processed so far (the Heavy timestamp clock).\u003C/summary\u003E\n\tuint _now;\n\n\t/// \u003Csummary\u003EPending scheduled messages, sorted by timestamp (stable).\u003C/summary\u003E\n\tQEntry _queue;\n\n\t/// \u003Csummary\u003EThe queue entry currently being dispatched (used by delay objects to clear their slot).\u003C/summary\u003E\n\tQEntry _current;\n\n\tpublic FaceSynth()\n\t{\n\t\tInitTables();\n\t\tInitObjects();\n\t\tSchedule( 0, ReceiverFunction( LoadbangHash ), 0, Msg.Of( 0, Atom.Bang ) );\n\t}\n\n\t/// \u003Csummary\u003E\n\t/// Sends a float to one of the patch\u0027s receivers (same names as the original game: volume, area, dragging,\n\t/// drag_delta_x/y/z, drag_distance, slap, init, vol_master, vol_slap, vol_slosh, vol_gloop, vol_stretch ...).\n\t/// The message is applied at the first sample of the next \u003Csee cref=\u0022Process\u0022/\u003E call. Unknown names are ignored.\n\t/// \u003C/summary\u003E\n\tpublic void SetParameter( string name, float value )\n\t{\n\t\tint fn = ReceiverFunction( StringToHash( name ) );\n\t\tif ( fn == 0 ) return;\n\t\tSchedule( _now, fn, 0, Msg.Of( _now, Atom.Float( value ) ) );\n\t}\n\n\t/// \u003Csummary\u003ERenders \u003Cc\u003Eleft.Length\u003C/c\u003E stereo frames (both spans must have the same length).\u003C/summary\u003E\n\tpublic void Process( Span\u003Cfloat\u003E left, Span\u003Cfloat\u003E right )\n\t{\n\t\tint n = Math.Min( left.Length, right.Length );\n\t\tfor ( int i = 0; i \u003C n; i\u002B\u002B )\n\t\t{\n\t\t\tRunMessages();\n\t\t\tProcessSample( out left[i], out right[i] );\n\t\t\t_now\u002B\u002B;\n\t\t}\n\t}\n\n\t/// \u003Csummary\u003ERenders \u003Cc\u003Eframes\u003C/c\u003E interleaved stereo frames into \u003Cc\u003Einterleaved\u003C/c\u003E (L, R, L, R ...).\u003C/summary\u003E\n\tpublic void ProcessInterleaved( Span\u003Cfloat\u003E interleaved, int frames )\n\t{\n\t\tfor ( int i = 0; i \u003C frames; i\u002B\u002B )\n\t\t{\n\t\t\tRunMessages();\n\t\t\tProcessSample( out interleaved[i * 2], out interleaved[i * 2 \u002B 1] );\n\t\t\t_now\u002B\u002B;\n\t\t}\n\t}\n\n\t// ------------------------------------------------------------------------------------------------\n\t// Message runtime (Heavy semantics)\n\t// ------------------------------------------------------------------------------------------------\n\n\t/// \u003Csummary\u003EA message atom: bang (0), float (1), symbol (2, stored as its hash) or hash (3).\u003C/summary\u003E\n\tstruct Atom\n\t{\n\t\tpublic int Type;\n\t\tpublic float F;\n\t\tpublic uint H;\n\n\t\tpublic static Atom Bang =\u003E new Atom { Type = 0 };\n\t\tpublic static Atom Float( float f ) =\u003E new Atom { Type = 1, F = f };\n\t\tpublic static Atom Symbol( uint hash ) =\u003E new Atom { Type = 2, H = hash };\n\t\tpublic static Atom Hash( int hash ) =\u003E new Atom { Type = 3, H = (uint)hash };\n\n\t\t/// \u003Csummary\u003EHeavy\u0027s msg_getHash: bang -1, float its bit pattern, symbol / hash the hash.\u003C/summary\u003E\n\t\tpublic int GetHash()\n\t\t{\n\t\t\tswitch ( Type )\n\t\t\t{\n\t\t\t\tcase 0: return -1;\n\t\t\t\tcase 1: return BitConverter.SingleToInt32Bits( F );\n\t\t\t\tcase 2:\n\t\t\t\tcase 3: return (int)H;\n\t\t\t\tdefault: return 0;\n\t\t\t}\n\t\t}\n\t}\n\n\t/// \u003Csummary\u003EA Heavy message: a timestamp (in samples) and up to four atoms.\u003C/summary\u003E\n\tstruct Msg\n\t{\n\t\tpublic uint Ts;\n\t\tpublic int Count;\n\t\tpublic Atom A0, A1, A2, A3;\n\n\t\tpublic static Msg Of( uint ts, Atom a ) =\u003E new Msg { Ts = ts, Count = 1, A0 = a };\n\t\tpublic static Msg Of( uint ts, Atom a, Atom b ) =\u003E new Msg { Ts = ts, Count = 2, A0 = a, A1 = b };\n\t\tpublic static Msg Of( uint ts, Atom a, Atom b, Atom c ) =\u003E new Msg { Ts = ts, Count = 3, A0 = a, A1 = b, A2 = c };\n\n\t\tpublic readonly Atom At( int i )\n\t\t{\n\t\t\tswitch ( i )\n\t\t\t{\n\t\t\t\tcase 0: return A0;\n\t\t\t\tcase 1: return A1;\n\t\t\t\tcase 2: return A2;\n\t\t\t\tdefault: return A3;\n\t\t\t}\n\t\t}\n\n\t\tpublic void Set( int i, Atom a )\n\t\t{\n\t\t\tswitch ( i )\n\t\t\t{\n\t\t\t\tcase 0: A0 = a; break;\n\t\t\t\tcase 1: A1 = a; break;\n\t\t\t\tcase 2: A2 = a; break;\n\t\t\t\tdefault: A3 = a; break;\n\t\t\t}\n\t\t}\n\n\t\tpublic readonly int TypeAt( int i ) =\u003E i \u003C Count ? At( i ).Type : -1;\n\t\tpublic readonly float FloatAt( int i ) =\u003E At( i ).F;\n\t\tpublic readonly int HashAt( int i ) =\u003E At( i ).GetHash();\n\t\tpublic readonly bool IsFloat( int i ) =\u003E i \u003C Count \u0026\u0026 At( i ).Type == 1;\n\t\tpublic readonly bool IsSymbol( int i, uint hash ) =\u003E i \u003C Count \u0026\u0026 At( i ).Type == 2 \u0026\u0026 At( i ).H == hash;\n\t}\n\n\t/// \u003Csummary\u003EAn entry of the message queue.\u003C/summary\u003E\n\tsealed class QEntry\n\t{\n\t\tpublic uint Ts;\n\t\tpublic int Fn;\n\t\tpublic int LetIn;\n\t\tpublic Msg M;\n\t\tpublic QEntry Next;\n\t\tpublic bool Queued;\n\t}\n\n\t/// \u003Csummary\u003EA Heavy table (buffer plus the head used by tabwrite~ / delay lines).\u003C/summary\u003E\n\tsealed class HvTable\n\t{\n\t\tpublic float[] Buffer;\n\t\tpublic int Length;\n\t\tpublic int Size;\n\t\tpublic int Head;\n\t}\n\n\t/// \u003Csummary\u003EControl [delay]: delay in samples plus up to 8 pending messages.\u003C/summary\u003E\n\tsealed class DelayObj\n\t{\n\t\tpublic uint Delay;\n\t\tpublic readonly QEntry[] Slots = new QEntry[8];\n\t}\n\n\t/// \u003Csummary\u003EControl [list split] / [route] helper: start index and length.\u003C/summary\u003E\n\tsealed class SliceObj\n\t{\n\t\tpublic int I;\n\t\tpublic int N;\n\t}\n\n\t/// \u003Csummary\u003EControl [tabread].\u003C/summary\u003E\n\tsealed class TabreadObj\n\t{\n\t\tpublic HvTable Table;\n\t}\n\n\t/// \u003Csummary\u003EHeavy\u0027s [random] (Park-Miller style generator).\u003C/summary\u003E\n\tsealed class RandomObj\n\t{\n\t\tpublic uint State;\n\t}\n\n\t/// \u003Csummary\u003EControl [spigot].\u003C/summary\u003E\n\tsealed class SpigotObj\n\t{\n\t\tpublic bool Open;\n\t}\n\n\t/// \u003Csummary\u003EControl [pack].\u003C/summary\u003E\n\tsealed class PackObj\n\t{\n\t\tpublic Msg M;\n\t}\n\n\t/// \u003Csummary\u003EWrite head of a tabwrite~ (delay line writer).\u003C/summary\u003E\n\tsealed class TabheadObj\n\t{\n\t\tpublic HvTable Table;\n\t\tpublic int Head;\n\t}\n\n\t/// \u003Csummary\u003EHeavy signal line~ state (output is \u003Cc\u003EN \u0026lt; 0 ? T : X\u003C/c\u003E).\u003C/summary\u003E\n\tstruct SLine\n\t{\n\t\tpublic int N;\n\t\tpublic float X;\n\t\tpublic float M;\n\t\tpublic float T;\n\t}\n\n\t/// \u003Csummary\u003EBiquad state (x[n-1], x[n-2], y[n-1], y[n-2]).\u003C/summary\u003E\n\tstruct Biquad\n\t{\n\t\tpublic float X1, X2, Y1, Y2;\n\t}\n\n\tstatic readonly uint HashClear = StringToHash( \u0022clear\u0022 );\n\tstatic readonly uint HashFlush = StringToHash( \u0022flush\u0022 );\n\tstatic readonly uint HashStop = StringToHash( \u0022stop\u0022 );\n\tstatic readonly uint HashBang = StringToHash( \u0022bang\u0022 );\n\tstatic readonly uint HashFloat = StringToHash( \u0022float\u0022 );\n\tstatic readonly uint HashResize = StringToHash( \u0022resize\u0022 );\n\tstatic readonly uint HashMirror = StringToHash( \u0022mirror\u0022 );\n\tstatic readonly uint HashSamplerate = StringToHash( \u0022samplerate\u0022 );\n\tstatic readonly uint HashNumIn = StringToHash( \u0022numInputChannels\u0022 );\n\tstatic readonly uint HashNumOut = StringToHash( \u0022numOutputChannels\u0022 );\n\tstatic readonly uint HashCurrentTime = StringToHash( \u0022currentTime\u0022 );\n\tstatic readonly uint HashTable = StringToHash( \u0022table\u0022 );\n\tstatic readonly uint HashLength = StringToHash( \u0022length\u0022 );\n\tstatic readonly uint HashSize = StringToHash( \u0022size\u0022 );\n\tstatic readonly uint HashHead = StringToHash( \u0022head\u0022 );\n\n\t/// \u003Csummary\u003EHeavy\u0027s string hash (MurmurHash2 variant seeded with the length).\u003C/summary\u003E\n\tpublic static uint StringToHash( string s )\n\t{\n\t\tif ( s == null ) return 0;\n\t\tconst uint n = 0x5bd1e995;\n\t\tint len = s.Length;\n\t\tuint x = (uint)len;\n\t\tint i = 0;\n\t\twhile ( len \u003E= 4 )\n\t\t{\n\t\t\tuint k = (uint)(s[i] \u0026 0xff) | ((uint)(s[i \u002B 1] \u0026 0xff) \u003C\u003C 8) | ((uint)(s[i \u002B 2] \u0026 0xff) \u003C\u003C 16) | ((uint)(s[i \u002B 3] \u0026 0xff) \u003C\u003C 24);\n\t\t\tk *= n;\n\t\t\tk ^= k \u003E\u003E 24;\n\t\t\tk *= n;\n\t\t\tx *= n;\n\t\t\tx ^= k;\n\t\t\ti \u002B= 4;\n\t\t\tlen -= 4;\n\t\t}\n\t\tif ( len == 3 ) x ^= (uint)(s[i \u002B 2] \u0026 0xff) \u003C\u003C 16;\n\t\tif ( len \u003E= 2 ) x ^= (uint)(s[i \u002B 1] \u0026 0xff) \u003C\u003C 8;\n\t\tif ( len \u003E= 1 )\n\t\t{\n\t\t\tx ^= (uint)(s[i] \u0026 0xff);\n\t\t\tx *= n;\n\t\t}\n\t\tx ^= x \u003E\u003E 13;\n\t\tx *= n;\n\t\tx ^= x \u003E\u003E 15;\n\t\treturn x;\n\t}\n\n\t/// \u003Csummary\u003EHeavy\u0027s ms to samples conversion (truncating).\u003C/summary\u003E\n\tstatic uint MsToSamples( float ms )\n\t{\n\t\tfloat c = ms \u003E 0f ? ms : 0f;\n\t\tdouble d = c * 0.001 * SampleRate;\n\t\tif ( double.IsNaN( d ) || d \u003E= 4294967296.0 || d \u003C= -1.0 ) return 0;\n\t\treturn (uint)d;\n\t}\n\n\t/// \u003Csummary\u003Ewasm-style float to int truncation (NaN and out of range give int.MinValue).\u003C/summary\u003E\n\tstatic int Trunc( float x )\n\t{\n\t\tif ( float.IsNaN( x ) || x \u003E= 2147483648f || x \u003C= -2147483648f ) return int.MinValue;\n\t\treturn (int)x;\n\t}\n\n\t/// \u003Csummary\u003Ewasm-style float to uint truncation (NaN and out of range give 0).\u003C/summary\u003E\n\tstatic uint TruncU( float x )\n\t{\n\t\tif ( float.IsNaN( x ) || x \u003E= 4294967296f || x \u003C= -1f ) return 0;\n\t\treturn (uint)x;\n\t}\n\n\t/// \u003Csummary\u003Efminf semantics (a NaN operand yields the other one).\u003C/summary\u003E\n\tstatic float FMin( float x, float b )\n\t{\n\t\tif ( float.IsNaN( x ) ) return b;\n\t\tif ( float.IsNaN( b ) ) return x;\n\t\treturn x \u003C b ? x : b;\n\t}\n\n\t/// \u003Csummary\u003Efmaxf semantics (a NaN operand yields the other one).\u003C/summary\u003E\n\tstatic float FMax( float x, float b )\n\t{\n\t\tif ( float.IsNaN( x ) ) return b;\n\t\tif ( float.IsNaN( b ) ) return x;\n\t\treturn x \u003E b ? x : b;\n\t}\n\n\t/// \u003Csummary\u003EInserts a message into the queue after every entry with a timestamp \u0026lt;= \u003Cparamref name=\u0022ts\u0022/\u003E.\u003C/summary\u003E\n\tQEntry Schedule( uint ts, int fn, int letIn, Msg m )\n\t{\n\t\tm.Ts = ts;\n\t\tvar e = new QEntry { Ts = ts, Fn = fn, LetIn = letIn, M = m, Queued = true };\n\t\tif ( _queue == null || ts \u003C _queue.Ts )\n\t\t{\n\t\t\te.Next = _queue;\n\t\t\t_queue = e;\n\t\t\treturn e;\n\t\t}\n\t\tvar p = _queue;\n\t\twhile ( p.Next != null \u0026\u0026 p.Next.Ts \u003C= ts ) p = p.Next;\n\t\te.Next = p.Next;\n\t\tp.Next = e;\n\t\treturn e;\n\t}\n\n\tvoid Cancel( QEntry e )\n\t{\n\t\tif ( e == null || !e.Queued ) return;\n\t\te.Queued = false;\n\t\tif ( _queue == e )\n\t\t{\n\t\t\t_queue = e.Next;\n\t\t\treturn;\n\t\t}\n\t\tvar p = _queue;\n\t\twhile ( p != null \u0026\u0026 p.Next != e ) p = p.Next;\n\t\tif ( p != null ) p.Next = e.Next;\n\t}\n\n\t/// \u003Csummary\u003EDispatches every queued message due at (or before) the current sample.\u003C/summary\u003E\n\tvoid RunMessages()\n\t{\n\t\twhile ( _queue != null \u0026\u0026 _queue.Ts \u003C= _now )\n\t\t{\n\t\t\tvar e = _queue;\n\t\t\t_current = e;\n\t\t\tDispatch( e.Fn, e.LetIn, e.M );\n\t\t\t_current = null;\n\t\t\t// Heavy pops the queue head after the callback returns.\n\t\t\tvar h = _queue;\n\t\t\tif ( h != null )\n\t\t\t{\n\t\t\t\t_queue = h.Next;\n\t\t\t\th.Queued = false;\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid Send( int fn, int letIn, in Msg m )\n\t{\n\t\tif ( fn != 0 ) Dispatch( fn, letIn, m );\n\t}\n\n\tvoid SendFloat( int fn, uint ts, float f )\n\t{\n\t\tif ( fn == 0 ) return;\n\t\tvar m = Msg.Of( ts, Atom.Float( f ) );\n\t\tDispatch( fn, 0, m );\n\t}\n\n\t/// \u003Csummary\u003EHeavy binary operators (the op codes of the original ControlBinop).\u003C/summary\u003E\n\tstatic float BinopApply( int op, float a, float b )\n\t{\n\t\tswitch ( op )\n\t\t{\n\t\t\tcase 0: return b \u002B a;\n\t\t\tcase 1: return a - b;\n\t\t\tcase 2: return b * a;\n\t\t\tcase 3: return b == 0f ? 0f : a / b;\n\t\t\tcase 4:\n\t\t\t\t{\n\t\t\t\t\tint ib = Trunc( b );\n\t\t\t\t\tif ( ib == 0 ) return 0f;\n\t\t\t\t\tint ia = Trunc( a );\n\t\t\t\t\tif ( ia == int.MinValue \u0026\u0026 ib == -1 ) return 0f;\n\t\t\t\t\treturn ia / ib;\n\t\t\t\t}\n\t\t\tcase 5:\n\t\t\t\t{\n\t\t\t\t\tint ib = Trunc( b );\n\t\t\t\t\tif ( ib == 0 ) return 0f;\n\t\t\t\t\tint ia = Trunc( a );\n\t\t\t\t\tif ( ib == -1 ) return 0f;\n\t\t\t\t\treturn ia % ib;\n\t\t\t\t}\n\t\t\tcase 6:\n\t\t\t\t{\n\t\t\t\t\tfloat e;\n\t\t\t\t\tif ( b == 0f ) e = 0f;\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\tint ib = Trunc( b );\n\t\t\t\t\t\tint ia = Trunc( a );\n\t\t\t\t\t\te = ib == 0 || ib == -1 ? 0f : ia % ib;\n\t\t\t\t\t}\n\t\t\t\t\treturn e \u003C 0f ? e \u002B MathF.Abs( b ) : e;\n\t\t\t\t}\n\t\t\tcase 7: return Trunc( a ) \u003C\u003C Trunc( b );\n\t\t\tcase 8: return Trunc( a ) \u003E\u003E Trunc( b );\n\t\t\tcase 9: return Trunc( b ) \u0026 Trunc( a );\n\t\t\tcase 10: return Trunc( b ) ^ Trunc( a );\n\t\t\tcase 11: return Trunc( b ) | Trunc( a );\n\t\t\tcase 12: return a == b ? 1f : 0f;\n\t\t\tcase 13: return a != b ? 1f : 0f;\n\t\t\tcase 14: return a == 0f || b == 0f ? 0f : 1f;\n\t\t\tcase 15: return a == 0f \u0026\u0026 b == 0f ? 0f : 1f;\n\t\t\tcase 16: return a \u003C b ? 1f : 0f;\n\t\t\tcase 17: return a \u003C= b ? 1f : 0f;\n\t\t\tcase 18: return a \u003E b ? 1f : 0f;\n\t\t\tcase 19: return a \u003E= b ? 1f : 0f;\n\t\t\tcase 20: return FMax( a, b );\n\t\t\tcase 21: return FMin( a, b );\n\t\t\tcase 22: return a \u003E 0f ? PowF( a, b ) : 0f;\n\t\t\tcase 23: return a == 0f \u0026\u0026 b == 0f ? 0f : (float)Math.Atan2( a, b );\n\t\t\tdefault: return 0f;\n\t\t}\n\t}\n\n\t/// \u003Csummary\u003E[op ] with a right operand held in \u003Cparamref name=\u0022k\u0022/\u003E (inlet 1 sets it).\u003C/summary\u003E\n\tvoid Binop( ref float k, int op, int inlet, in Msg m, int cb )\n\t{\n\t\tif ( inlet == 0 )\n\t\t{\n\t\t\tif ( !m.IsFloat( 0 ) ) return;\n\t\t\tif ( m.Count \u003E 1 \u0026\u0026 m.A1.Type == 1 ) k = m.A1.F;\n\t\t\tSendFloat( cb, m.Ts, BinopApply( op, m.A0.F, k ) );\n\t\t}\n\t\telse if ( inlet == 1 )\n\t\t{\n\t\t\tif ( m.IsFloat( 0 ) ) k = m.A0.F;\n\t\t}\n\t}\n\n\t/// \u003Csummary\u003E[op k] with a constant right operand.\u003C/summary\u003E\n\tvoid BinopK( int op, float k, in Msg m, int cb )\n\t{\n\t\tif ( !m.IsFloat( 0 ) ) return;\n\t\tif ( m.Count \u003E 1 \u0026\u0026 m.A1.Type == 1 ) k = m.A1.F;\n\t\tSendFloat( cb, m.Ts, BinopApply( op, m.A0.F, k ) );\n\t}\n\n\t/// \u003Csummary\u003E[f ] / [symbol ] storage object.\u003C/summary\u003E\n\tvoid Var( ref Atom v, int inlet, in Msg m, int cb )\n\t{\n\t\tint t = m.TypeAt( 0 );\n\t\tif ( inlet == 0 )\n\t\t{\n\t\t\tswitch ( t )\n\t\t\t{\n\t\t\t\tcase 0:\n\t\t\t\t\tif ( v.Type == 1 ) SendFloat( cb, m.Ts, v.F );\n\t\t\t\t\telse if ( v.Type == 3 )\n\t\t\t\t\t{\n\t\t\t\t\t\tvar o = Msg.Of( m.Ts, Atom.Hash( (int)v.H ) );\n\t\t\t\t\t\tSend( cb, 0, o );\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\tcase 1:\n\t\t\t\t\tv = Atom.Float( m.A0.F );\n\t\t\t\t\tSend( cb, 0, m );\n\t\t\t\t\tbreak;\n\t\t\t\tcase 2:\n\t\t\t\tcase 3:\n\t\t\t\t\tv = Atom.Hash( m.HashAt( 0 ) );\n\t\t\t\t\tSend( cb, 0, m );\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\telse if ( inlet == 1 )\n\t\t{\n\t\t\tif ( t == 1 ) v = Atom.Float( m.A0.F );\n\t\t\telse if ( t == 2 || t == 3 ) v = Atom.Hash( m.HashAt( 0 ) );\n\t\t}\n\t}\n\n\t/// \u003Csummary\u003EType casts: 0 = bang, 1 = float, 2 = symbol.\u003C/summary\u003E\n\tvoid Cast( int type, in Msg m, int cb )\n\t{\n\t\tswitch ( type )\n\t\t{\n\t\t\tcase 0:\n\t\t\t\t{\n\t\t\t\t\tvar o = Msg.Of( m.Ts, Atom.Bang );\n\t\t\t\t\tSend( cb, 0, o );\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tcase 1:\n\t\t\t\tif ( m.IsFloat( 0 ) ) SendFloat( cb, m.Ts, m.A0.F );\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\t{\n\t\t\t\t\tint t = m.TypeAt( 0 );\n\t\t\t\t\tif ( t == 0 ) { var o = Msg.Of( m.Ts, Atom.Symbol( HashBang ) ); Send( cb, 0, o ); }\n\t\t\t\t\telse if ( t == 1 ) { var o = Msg.Of( m.Ts, Atom.Symbol( HashFloat ) ); Send( cb, 0, o ); }\n\t\t\t\t\telse if ( t == 2 ) Send( cb, 0, m );\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t}\n\n\t/// \u003Csummary\u003EUnary math operators.\u003C/summary\u003E\n\tvoid Unop( int op, in Msg m, int cb )\n\t{\n\t\tif ( !m.IsFloat( 0 ) ) return;\n\t\tfloat f = m.A0.F;\n\t\tfloat g;\n\t\tswitch ( op )\n\t\t{\n\t\t\tcase 0: g = (float)Math.Asin( f ); break;\n\t\t\tcase 1: g = (float)Math.Asinh( f ); break;\n\t\t\tcase 2: g = (float)Math.Acos( f ); break;\n\t\t\tcase 3: g = (float)Math.Acosh( f ); break;\n\t\t\tcase 4: g = (float)Math.Atan( f ); break;\n\t\t\tcase 5: g = (float)Math.Atanh( f ); break;\n\t\t\tcase 6: g = (float)Math.Sin( f ); break;\n\t\t\tcase 7: g = (float)Math.Sinh( f ); break;\n\t\t\tcase 8: g = (float)Math.Cos( f ); break;\n\t\t\tcase 9: g = (float)Math.Cosh( f ); break;\n\t\t\tcase 10: g = (float)Math.Tan( f ); break;\n\t\t\tcase 11: g = (float)Math.Tanh( f ); break;\n\t\t\tcase 12: g = (float)Math.Exp( f ); break;\n\t\t\tcase 13: g = MathF.Abs( f ); break;\n\t\t\tcase 14: g = f \u003E 0f ? MathF.Sqrt( f ) : 0f; break;\n\t\t\tcase 15: g = f \u003E 0f ? (float)Math.Log( f ) : 0f; break;\n\t\t\tcase 16: g = f \u003E 0f ? (float)Math.Log( f ) * 1.44269502f : 0f; break;\n\t\t\tcase 17: g = f \u003E 0f ? (float)Math.Log( f ) * 0.434294492f : 0f; break;\n\t\t\tcase 18: g = MathF.Ceiling( f ); break;\n\t\t\tcase 19: g = MathF.Floor( f ); break;\n\t\t\tcase 20:\n\t\t\t\t{\n\t\t\t\t\tdouble h = f;\n\t\t\t\t\tg = (float)(h \u003E= 0.0 ? Math.Floor( h \u002B 0.5 ) : Math.Ceiling( h - 0.5 ));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tdefault: return;\n\t\t}\n\t\tSendFloat( cb, m.Ts, g );\n\t}\n\n\t/// \u003Csummary\u003EMessages to a signal line~: \u0022target\u0022, \u0022target time\u0022 or \u0022stop\u0022.\u003C/summary\u003E\n\tstatic void LineMsg( ref SLine l, in Msg m )\n\t{\n\t\tif ( m.IsFloat( 0 ) )\n\t\t{\n\t\t\tif ( m.Count \u003E 1 \u0026\u0026 m.A1.Type == 1 )\n\t\t\t{\n\t\t\t\tint n = (int)MsToSamples( m.A1.F );\n\t\t\t\tfloat x = l.N \u003E 0 ? l.M \u002B l.X : l.T;\n\t\t\t\tl.X = x;\n\t\t\t\tl.N = n;\n\t\t\t\tl.M = (m.A0.F - x) / n;\n\t\t\t\tl.T = m.A0.F;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tl.N = 0;\n\t\t\tl.X = m.A0.F;\n\t\t\tl.M = 0f;\n\t\t\tl.T = m.A0.F;\n\t\t\treturn;\n\t\t}\n\t\tif ( m.IsSymbol( 0, HashStop ) )\n\t\t{\n\t\t\tl.N = 0;\n\t\t\tl.X = l.X \u002B l.M;\n\t\t\tl.M = 0f;\n\t\t\tl.T = l.X;\n\t\t}\n\t}\n\n\t/// \u003Csummary\u003EReads a line~ (one sample) and advances it.\u003C/summary\u003E\n\tstatic float Line( ref SLine l )\n\t{\n\t\tfloat v = l.N \u003C 0 ? l.T : l.X;\n\t\tl.N--;\n\t\tl.X \u002B= l.M;\n\t\treturn v;\n\t}\n\n\t/// \u003Csummary\u003EHeavy\u0027s biquad, with the original operation order.\u003C/summary\u003E\n\tstatic float Bq( ref Biquad s, float x, float b0, float b1, float b2, float a1, float a2 )\n\t{\n\t\tfloat y = ((s.X1 * b1) \u002B (b0 * x) \u002B (s.X2 * b2)) - ((s.Y2 * a2) \u002B (s.Y1 * a1));\n\t\ts.X2 = s.X1;\n\t\ts.X1 = x;\n\t\ts.Y2 = s.Y1;\n\t\ts.Y1 = y;\n\t\treturn y;\n\t}\n\n\t/// \u003Csummary\u003EList slice (outlet 0: the slice, outlet 1: bang when the list is too short).\u003C/summary\u003E\n\tvoid Slice( SliceObj o, int inlet, in Msg m, int cb )\n\t{\n\t\tswitch ( inlet )\n\t\t{\n\t\t\tcase 0:\n\t\t\t\tif ( o.I \u003C m.Count )\n\t\t\t\t{\n\t\t\t\t\tint g = m.Count - o.I;\n\t\t\t\t\tint c = o.N;\n\t\t\t\t\tif ( g \u003C c ) c = g;\n\t\t\t\t\tint len = o.N \u003E 0 ? c : g;\n\t\t\t\t\tvar r = new Msg { Ts = m.Ts, Count = len };\n\t\t\t\t\tfor ( int i = 0; i \u003C len; i\u002B\u002B ) r.Set( i, m.At( o.I \u002B i ) );\n\t\t\t\t\tSend( cb, 0, r );\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tvar b = Msg.Of( m.Ts, Atom.Bang );\n\t\t\t\t\tSend( cb, 1, b );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 1:\n\t\t\t\tif ( m.IsFloat( 0 ) )\n\t\t\t\t{\n\t\t\t\t\to.I = Trunc( m.A0.F );\n\t\t\t\t\tif ( m.Count \u003E 1 \u0026\u0026 m.A1.Type == 1 ) o.N = Trunc( m.A1.F );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tif ( m.IsFloat( 0 ) ) o.N = Trunc( m.A0.F );\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tvoid Tabread( TabreadObj o, int inlet, in Msg m, int cb )\n\t{\n\t\tif ( inlet == 0 )\n\t\t{\n\t\t\tif ( !m.IsFloat( 0 ) || !(m.A0.F \u003E= 0f) || o.Table == null ) return;\n\t\t\tuint idx = TruncU( m.A0.F );\n\t\t\tif ( (uint)o.Table.Size \u003E idx ) SendFloat( cb, m.Ts, o.Table.Buffer[idx] );\n\t\t}\n\t\telse if ( inlet == 1 )\n\t\t{\n\t\t\tint t = m.TypeAt( 0 );\n\t\t\tif ( t == 2 || t == 3 ) o.Table = TableForHash( m.HashAt( 0 ) );\n\t\t}\n\t}\n\n\tvoid Delay( DelayObj o, int inlet, in Msg m, int cb )\n\t{\n\t\tswitch ( inlet )\n\t\t{\n\t\t\tcase 0:\n\t\t\t\tif ( m.IsSymbol( 0, HashFlush ) )\n\t\t\t\t{\n\t\t\t\t\tfor ( int i = 0; i \u003C 8; i\u002B\u002B )\n\t\t\t\t\t{\n\t\t\t\t\t\tvar e = o.Slots[i];\n\t\t\t\t\t\tif ( e == null ) continue;\n\t\t\t\t\t\te.M.Ts = m.Ts;\n\t\t\t\t\t\tSend( cb, 0, e.M );\n\t\t\t\t\t\tCancel( e );\n\t\t\t\t\t}\n\t\t\t\t\tArray.Clear( o.Slots, 0, 8 );\n\t\t\t\t}\n\t\t\t\telse if ( !m.IsSymbol( 0, HashClear ) )\n\t\t\t\t{\n\t\t\t\t\tfor ( int i = 0; i \u003C 8; i\u002B\u002B )\n\t\t\t\t\t{\n\t\t\t\t\t\tif ( o.Slots[i] != null ) continue;\n\t\t\t\t\t\to.Slots[i] = Schedule( m.Ts \u002B o.Delay, cb, 0, m );\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tfor ( int i = 0; i \u003C 8; i\u002B\u002B ) Cancel( o.Slots[i] );\n\t\t\t\t\tArray.Clear( o.Slots, 0, 8 );\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 1:\n\t\t\t\tif ( m.IsFloat( 0 ) ) o.Delay = MsToSamples( m.A0.F );\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tif ( m.IsFloat( 0 ) ) o.Delay = TruncU( m.A0.F \u003E 0f ? m.A0.F : 0f );\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\t/// \u003Csummary\u003ECalled by a delay\u0027s output callback: forgets the message that is firing now.\u003C/summary\u003E\n\tvoid DelayClear( DelayObj o, in Msg m )\n\t{\n\t\tfor ( int i = 0; i \u003C 8; i\u002B\u002B )\n\t\t{\n\t\t\tif ( o.Slots[i] != null \u0026\u0026 o.Slots[i] == _current )\n\t\t\t{\n\t\t\t\to.Slots[i] = null;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\tvoid Random( RandomObj o, int inlet, in Msg m, int cb )\n\t{\n\t\tif ( inlet == 0 )\n\t\t{\n\t\t\to.State = (uint)((ulong)o.State * 279470273UL % 4294967291UL);\n\t\t\tSendFloat( cb, m.Ts, (o.State \u003E\u003E 9) * 1.1920929e-07f );\n\t\t}\n\t\telse if ( inlet == 1 )\n\t\t{\n\t\t\tif ( m.IsFloat( 0 ) ) o.State = TruncU( m.A0.F );\n\t\t}\n\t}\n\n\tvoid Spigot( SpigotObj o, int inlet, in Msg m, int cb )\n\t{\n\t\tif ( inlet == 0 ) Send( cb, o.Open ? 1 : 0, m );\n\t\telse if ( inlet == 1 \u0026\u0026 m.IsFloat( 0 ) ) o.Open = m.A0.F != 0f;\n\t}\n\n\tvoid Pack( PackObj o, int inlet, in Msg m, int cb )\n\t{\n\t\tif ( inlet \u003E 0 )\n\t\t{\n\t\t\tint t = m.TypeAt( 0 );\n\t\t\tif ( t == 1 ) o.M.Set( inlet, Atom.Float( m.A0.F ) );\n\t\t\telse if ( t == 2 || t == 3 ) o.M.Set( inlet, Atom.Hash( m.HashAt( 0 ) ) );\n\t\t\treturn;\n\t\t}\n\t\tint c = Math.Min( o.M.Count, m.Count );\n\t\tfor ( int i = c - 1; i \u003E= 0; i-- )\n\t\t{\n\t\t\tint t = m.TypeAt( i );\n\t\t\tif ( t == 1 ) o.M.Set( i, Atom.Float( m.At( i ).F ) );\n\t\t\telse if ( t == 2 || t == 3 ) o.M.Set( i, Atom.Hash( m.HashAt( i ) ) );\n\t\t}\n\t\to.M.Ts = m.Ts;\n\t\tvar copy = o.M;\n\t\tSend( cb, 0, copy );\n\t}\n\n\t/// \u003Csummary\u003EHeavy \u0022system\u0022 queries (samplerate, currentTime, table length ...).\u003C/summary\u003E\n\tvoid SystemQuery( in Msg m, int cb )\n\t{\n\t\tfloat f;\n\t\tif ( m.IsSymbol( 0, HashSamplerate ) ) f = SampleRate;\n\t\telse if ( m.IsSymbol( 0, HashNumIn ) ) f = 0f;\n\t\telse if ( m.IsSymbol( 0, HashNumOut ) ) f = 2f;\n\t\telse if ( m.IsSymbol( 0, HashCurrentTime ) ) f = m.Ts;\n\t\telse if ( m.IsSymbol( 0, HashTable ) )\n\t\t{\n\t\t\tvar t = TableForHash( m.HashAt( 1 ) );\n\t\t\tif ( t == null ) return;\n\t\t\tif ( m.IsSymbol( 2, HashLength ) ) f = t.Length;\n\t\t\telse if ( m.IsSymbol( 2, HashSize ) ) f = t.Size;\n\t\t\telse if ( m.IsSymbol( 2, HashHead ) ) f = t.Head;\n\t\t\telse return;\n\t\t}\n\t\telse return;\n\t\tSendFloat( cb, m.Ts, f );\n\t}\n\n\t/// \u003Csummary\u003ESets the phase of a signal phasor (inlet 1).\u003C/summary\u003E\n\tstatic void PhasorPhase( ref uint phase, int inlet, in Msg m )\n\t{\n\t\tif ( inlet != 1 || !m.IsFloat( 0 ) ) return;\n\t\tfloat e = m.A0.F;\n\t\twhile ( e \u003C 0f ) e \u002B= 1f;\n\t\twhile ( e \u003E 1f ) e -= 1f;\n\t\tdouble d = e * 4294967296.0;\n\t\tphase = double.IsNaN( d ) || d \u003E= 4294967296.0 || d \u003C= -1.0 ? 0 : (uint)d;\n\t}\n\n\t/// \u003Csummary\u003ESets an integer signal variable (noise seeds).\u003C/summary\u003E\n\tstatic void IntSet( ref int v, in Msg m )\n\t{\n\t\tif ( m.IsFloat( 0 ) ) v = Trunc( m.A0.F );\n\t}\n\n\t/// \u003Csummary\u003ETable messages (\u0022resize n\u0022, \u0022mirror\u0022).\u003C/summary\u003E\n\tvoid Tablemsg( HvTable t, int inlet, in Msg m, int cb )\n\t{\n\t\tif ( m.IsSymbol( 0, HashResize ) \u0026\u0026 m.Count \u003E 1 \u0026\u0026 m.A1.Type == 1 \u0026\u0026 m.A1.F \u003E= 0f )\n\t\t{\n\t\t\tint g = Trunc( MathF.Ceiling( m.A1.F ) );\n\t\t\tif ( t.Size != g )\n\t\t\t{\n\t\t\t\tvar nb = new float[g \u002B 1];\n\t\t\t\tArray.Copy( t.Buffer, nb, Math.Min( t.Buffer.Length, g \u002B 1 ) );\n\t\t\t\tt.Buffer = nb;\n\t\t\t\tt.Length = g;\n\t\t\t\tt.Size = g;\n\t\t\t}\n\t\t\tSendFloat( cb, m.Ts, (uint)g );\n\t\t\treturn;\n\t\t}\n\t\tif ( m.IsSymbol( 0, HashMirror ) ) t.Buffer[t.Size] = t.Buffer[0];\n\t}\n\n\t/// \u003Csummary\u003EMessages to a tabwrite~ head (inlet 1: restart / stop, inlet 2: set table).\u003C/summary\u003E\n\tvoid Tabhead( TabheadObj o, int inlet, in Msg m, int cb )\n\t{\n\t\tif ( inlet == 1 )\n\t\t{\n\t\t\tswitch ( m.TypeAt( 0 ) )\n\t\t\t{\n\t\t\t\tcase 0: o.Head = 0; break;\n\t\t\t\tcase 1: o.Head = m.A0.F \u003E= 0f ? (int)TruncU( m.A0.F ) : -1; break;\n\t\t\t\tcase 2: if ( m.IsSymbol( 0, HashStop ) ) o.Head = -1; break;\n\t\t\t}\n\t\t}\n\t\telse if ( inlet == 2 )\n\t\t{\n\t\t\tint t = m.TypeAt( 0 );\n\t\t\tif ( t == 2 || t == 3 ) o.Table = TableForHash( m.HashAt( 0 ) );\n\t\t}\n\t}\n\n\t// ------------------------------------------------------------------------------------------------\n\t// Signal graph (one sample). Field names end with the object\u0027s byte offset in the original patch.\n\t// ------------------------------------------------------------------------------------------------\n\n\tconst float NoiseScale = 4.6566101e-10f;\n\n\t/// \u003Csummary\u003E(float)(phase \u0026gt;\u0026gt; 9) / 2^23, i.e. the phasor\u0027s position in [0, 1).\u003C/summary\u003E\n\tstatic float Phase01( uint p ) =\u003E (p \u003E\u003E 9) * 1.1920929e-07f;\n\n\tstatic void TabWrite( TabheadObj w, float x )\n\t{\n\t\tvar t = w.Table;\n\t\tif ( w.Head \u003E= 0 \u0026\u0026 w.Head \u003C t.Buffer.Length ) t.Buffer[w.Head] = x;\n\t\tw.Head\u002B\u002B;\n\t\tt.Head = w.Head;\n\t}\n\n\t/// \u003Csummary\u003EReads a delay line: linear interpolation at \u003Cc\u003Ehead - 1 - delay\u003C/c\u003E, wrapping by \u003Cparamref name=\u0022wrap\u0022/\u003E.\u003C/summary\u003E\n\tstatic float DelayRead( HvTable t, float delay, float wrap )\n\t{\n\t\tfloat pos = ((uint)t.Head \u002B -1.0f) - delay;\n\t\tfloat fl = MathF.Floor( pos );\n\t\tfloat idx = (fl \u003C 0f ? wrap : 0f) \u002B fl;\n\t\tint i = Trunc( idx );\n\t\tfloat b = Tap( t.Buffer, i \u002B 1 );\n\t\tfloat a = Tap( t.Buffer, i );\n\t\treturn ((b - a) * (pos - fl)) \u002B a;\n\t}\n\n\tstatic float Tap( float[] b, int i ) =\u003E i \u003E= 0 \u0026\u0026 i \u003C b.Length ? b[i] : 0f;\n\n\t/// \u003Csummary\u003ESoftclip used by the output stage: x(27 \u002B x^2) / (27 \u002B 9x^2), with the original operation order.\u003C/summary\u003E\n\tstatic float SoftclipFactor( float x )\n\t{\n\t\tfloat x2 = x * x;\n\t\tfloat d = (x2 * 9.0f) \u002B 27.0f;\n\t\tfloat r = (x2 \u002B 27.0f) / d;\n\t\treturn d != 0f ? r : 0f;\n\t}\n\n\t/// \u003Csummary\u003EPolynomial sine used by the slosh and gloop oscillators (input is the phasor state).\u003C/summary\u003E\n\tstatic float OscAngle( uint phase ) =\u003E (MathF.Abs( Phase01( phase ) \u002B -0.5f ) \u002B -0.25f) * 6.28318548f;\n\n\tvoid ProcessSample( out float outL, out float outR )\n\t{\n\t\t// ============================== SLAP ==============================\n\t\tvari10868 = vari10868 * 16807;\n\t\tfloat noise = vari10868 * NoiseScale;\n\t\tsig11096 = noise;\n\n\t\tfloat b0 = Line( ref line136 );\n\t\tfloat b2 = Line( ref line152 );\n\t\tfloat a1 = Line( ref line168 );\n\t\tfloat a2 = Line( ref line184 );\n\t\tfloat bp1 = Bq( ref bq200, noise, b0, 0f, b2, a1, a2 );              // BP ~8 kHz (drag_delta_x)\n\t\tb0 = Line( ref line216 );\n\t\tb2 = Line( ref line232 );\n\t\ta1 = Line( ref line248 );\n\t\ta2 = Line( ref line264 );\n\t\tfloat bp2 = Bq( ref bq280, noise, b0, 0f, b2, a1, a2 );              // BP ~3.5 kHz (drag_delta_y)\n\t\tfloat mix = (0.4f * bp1) \u002B bp2;\n\t\tb0 = Line( ref line296 );\n\t\tb2 = Line( ref line312 );\n\t\ta1 = Line( ref line328 );\n\t\ta2 = Line( ref line344 );\n\t\tfloat bp3 = Bq( ref bq360, noise, b0, 0f, b2, a1, a2 );              // BP ~400 Hz\n\t\tfloat click = (mix - (bp3 * 0.3f)) * Line( ref line376 );\n\t\tfloat burst = Line( ref line392 );\n\t\tburst *= burst;\n\t\tb0 = Line( ref line408 );\n\t\tfloat b1 = Line( ref line424 );\n\t\tb2 = Line( ref line440 );\n\t\ta1 = Line( ref line456 );\n\t\ta2 = Line( ref line472 );\n\t\tfloat lowNoise = Bq( ref bq488, sig11096, b0, b1, b2, a1, a2 );      // LP ~800 Hz\n\n\t\t// vcf~ (Pd), Q = 3: coefficient maths with Heavy\u0027s polynomial sine / cosine\n\t\tfloat vin = sig11096;\n\t\tfloat cf = FMax( Line( ref line504 ), 0f ) * sig11248;\n\t\tfloat kr = (sig11268 * (cf * 6.28318024f)) \u002B -1.0f;\n\t\tif ( !(sig11236 != 0f) || kr == 0f ) kr = 0f;\n\t\tfloat negR = float.IsNaN( kr ) ? 0f : (kr \u003C 0f ? kr : 0f);\n\t\tfloat gain = ((negR \u002B 1.0f) * vin) * sig11240;\n\t\tfloat s = cf \u002B -0.25f;\n\t\ts = (MathF.Abs( (s - MathF.Floor( s )) \u002B -0.5f ) \u002B -0.25f) * 6.28318977f;\n\t\tfloat s2 = s * s;\n\t\tfloat s3 = s2 * s;\n\t\tfloat s5 = s3 * s2;\n\t\tfloat im = sig524;\n\t\tfloat sinR = negR * (((s3 * -0.166666999f) \u002B s) \u002B (s5 * 0.00784313958f));\n\t\tfloat re = sig520;\n\t\tfloat c = (MathF.Abs( (cf \u002B -0.5f) - MathF.Floor( cf ) ) \u002B -0.25f) * 6.28318977f;\n\t\tfloat c2 = c * c;\n\t\tfloat cosR = negR * ((((c2 * 0.00784313958f) \u002B -0.166666999f) * (c2 * c)) \u002B c);\n\t\tfloat vcf = ((im * sinR) - (re * cosR)) \u002B gain;\n\t\tsig520 = vcf;\n\t\tsig524 = -((re * sinR) \u002B (im * cosR));\n\t\tfloat ring = Line( ref line528 );\n\t\tfloat slap = (sig10848 * ((click * 0.4f) \u002B ((lowNoise * burst) \u002B ((ring * ring) * (vcf * 50.0f))))) * sig11280;\n\n\t\t// ============================== SLOSH ==============================\n\t\tvari8828 = vari8828 * 16807;\n\t\tfloat nraw = vari8828;\n\t\tfloat dens = (sig8872 * sig8936) - (sig544 * sig8952);\n\t\tsig544 = dens;\n\t\tfloat u = (nraw * 2.32830505e-10f) \u002B 0.5f;\n\t\tfloat trig = u \u003C= dens ? 1f : 0f;\n\t\tfloat env = (trig * sig8860) - (sig548 * sig8836);\n\t\tsig548 = env;\n\t\tfloat loud = sig8784;\n\t\tfloat prevTrig = sig552;\n\t\tsig552 = trig;\n\t\tif ( trig \u003C prevTrig ) sig556 = u;\n\t\telse u = sig556;\n\t\tuint ph = phasor560;\n\t\tphasor560 = ph \u002B (uint)Trunc( sig568 * ((u * sig8632) \u002B sig8756 ) );\n\t\tfloat ang = OscAngle( ph );\n\t\tfloat ang2 = ang * ang;\n\t\tfloat amp = ((loud * env) * sig8892) * sig8900;\n\t\tfloat ang3 = ang2 * ang;\n\t\tfloat slosh = amp * (((ang3 * -0.166666672f) \u002B ang) \u002B ((ang3 * ang2) * 0.00783333369f));\n\t\tsig8320 = slosh \u002B slap;\n\n\t\t// ============================== BODY RESONATOR ==============================\n\t\tfloat prevGR = sig8328;\n\t\tfloat fade = Line( ref line572 );\n\t\tfade *= fade;\n\t\tfloat resIn = (sig11544 \u002B sig8512) \u002B sig6344;\n\n\t\tb0 = Line( ref line588 );\n\t\tb2 = Line( ref line604 );\n\t\ta1 = Line( ref line620 );\n\t\ta2 = Line( ref line636 );\n\t\tTabWrite( tabhead668, Bq( ref bq652, resIn, b0, 0f, b2, a1, a2 ) );\n\t\tsig676 = (sig7536 * sig7820) - (sig676 * sig7548);\n\t\tfloat tap1 = DelayRead( table7800, FMax( FMin( sig7568 * sig676, sig7564 ), 0f ), sig7580 );\n\n\t\tb0 = Line( ref line708 );\n\t\tb2 = Line( ref line724 );\n\t\ta1 = Line( ref line740 );\n\t\ta2 = Line( ref line756 );\n\t\tTabWrite( tabhead788, Bq( ref bq772, resIn, b0, 0f, b2, a1, a2 ) );\n\t\tsig796 = (sig7496 * sig7444) - (sig796 * sig7500);\n\t\tfloat tap2 = DelayRead( table7368, FMax( FMin( sig796 * sig7464, sig7448 ), 0f ), sig7472 ) \u002B tap1;\n\n\t\tsig828 = (sig8036 * sig7848) - (sig828 * sig8016);\n\t\tfloat tap3 = DelayRead( table8116, FMax( FMin( sig7988 * sig828, sig7976 ), 0f ), sig7980 );\n\t\tb0 = Line( ref line860 );\n\t\tb2 = Line( ref line876 );\n\t\ta1 = Line( ref line892 );\n\t\ta2 = Line( ref line908 );\n\t\tTabWrite( tabhead940, Bq( ref bq924, resIn, b0, 0f, b2, a1, a2 ) );\n\n\t\tfloat res = (tap3 \u002B tap2) \u002B sig8320;\n\t\tfloat resFaded = res * fade;\n\t\tfloat right = FMax( FMin( ((prevGR \u002B res) * fade) * sig8508, 3f ), -3f );\n\n\t\t// ============================== GLOOP ==============================\n\t\tfloat voiceA = GloopVoice( ref line948, ref sig988, ref phasor992, sig1000, sig9812, sig10016,\n\t\t\tsig9648, sig9636, sig9576, sig9616, table10308, table8988 );\n\t\tvoiceA = GloopWindowA( Line( ref line1028 ), sig10032, sig10056, table10116 ) * voiceA;\n\t\tfloat voiceB = GloopVoice( ref line1068, ref sig1108, ref phasor1112, sig1120, sig9128, sig9132,\n\t\t\tsig9344, sig9380, sig9468, sig9496, table10308, table8988 );\n\t\tfloat gloop = (((GloopWindowB( Line( ref line1148 ), sig9212, sig9208, table10116 ) * voiceB) \u002B voiceA) * 1.5f) * sig10076;\n\t\tsig11544 = gloop;\n\n\t\t// ============================== STRETCH ==============================\n\t\tfloat creakIn = sig4024 \u002B sig5812;\n\t\tb0 = Line( ref line1188 );\n\t\tb1 = Line( ref line1204 );\n\t\tb2 = Line( ref line1220 );\n\t\ta1 = Line( ref line1236 );\n\t\ta2 = Line( ref line1252 );\n\t\tfloat stretch = ((Bq( ref bq1268, creakIn, b0, b1, b2, a1, a2 ) * sig6168) * sig2216) * sig1800;\n\t\tCreakVoice1();\n\t\tCreakVoice2();\n\n\t\t// ============================== OUTPUT / PAN ==============================\n\t\tfloat g = gloop \u002B stretch;\n\t\tsig1548 = (sig8484 * sig8348) - (sig1548 * sig8332);\n\t\tfloat pan256 = FMax( FMin( sig1548, 1f ), -1f ) * 256.0f;\n\t\tfloat iL = FMax( FMin( 256.0f - pan256, sig8424 ), 0f );\n\t\tfloat cL = table8368.Buffer[Trunc( iL )];\n\t\tfloat pL = 257.0f - pan256;\n\t\tfloat fracL = pL - MathF.Floor( pL );\n\t\tfloat wL = 1.0f - fracL;\n\t\tfloat jL = FMax( FMin( pL, sig8388 ), 0f );\n\t\tfloat xL = FMax( FMin( (((wL * cL) \u002B 1.0f) \u002B (fracL * table8368.Buffer[Trunc( jL )])) * 0.855000019f, 3f ), -3f );\n\t\tfloat kL = SoftclipFactor( xL );\n\n\t\tfloat iR = FMax( FMin( pan256 \u002B 256.0f, sig8444 ), 0f );\n\t\tfloat cR = table8368.Buffer[Trunc( iR )];\n\t\tfloat pR = pan256 \u002B 257.0f;\n\t\tfloat fracR = pR - MathF.Floor( pR );\n\t\tfloat jR = FMax( FMin( pR, sig8460 ), 0f );\n\t\tfloat xR = FMax( FMin( (((table8368.Buffer[Trunc( jR )] * fracR) \u002B 1.0f) \u002B ((1.0f - fracR) * cR)) * 0.855000019f, 3f ), -3f );\n\t\tsig8328 = (xR * g) * SoftclipFactor( xR );\n\t\tfloat gl = (xL * g) * kL;\n\t\tsig8324 = gl;\n\t\tsig6344 = stretch;\n\t\tsig8512 = slosh * 0.200000003f;\n\n\t\tfloat left = FMax( FMin( sig8516 * ((gl * fade) \u002B resFaded), 3f ), -3f );\n\t\toutL = SoftclipFactor( left ) * left;\n\t\toutR = SoftclipFactor( right ) * right;\n\t}\n\n\t/// \u003Csummary\u003E\n\t/// One gloop bubble: a timer counting seconds since the last trigger (reset through the 2-point \u00221986-imp\u0022 table),\n\t/// a sine whose pitch glides up with the timer, and the 512-point \u00221986-env\u0022 envelope read at timer / duration.\n\t/// \u003C/summary\u003E\n\tstatic float GloopVoice( ref SLine timerLine, ref float timer, ref uint phase, float step, float freq, float dur,\n\t\tfloat t1Hi, float t0Hi, float e0Hi, float e1Hi, HvTable imp, HvTable envTab )\n\t{\n\t\tfloat tl = Line( ref timerLine );\n\t\tfloat t1 = tl \u002B 1.0f;\n\t\tfloat imp1 = imp.Buffer[Trunc( FMax( FMin( t1, t1Hi ), 0f ) )];\n\t\tfloat fr = t1 - MathF.Floor( t1 );\n\t\tfloat imp0 = imp.Buffer[Trunc( FMax( FMin( tl, t0Hi ), 0f ) )];\n\t\tfloat t = ((((1.0f - fr) * imp0) \u002B (fr * imp1)) * timer) \u002B 2.26757365e-05f;\n\t\ttimer = t;\n\t\tuint ph = phase;\n\t\tphase = ph \u002B (uint)Trunc( step * ((t * freq) \u002B freq) );\n\t\tfloat ang = OscAngle( ph );\n\t\tfloat ang2 = ang * ang;\n\t\tfloat ang3 = ang2 * ang;\n\t\tfloat osc = ((ang3 * ang2) * 0.00783333369f) \u002B (ang - (ang3 * 0.166666672f));\n\t\tfloat q = t / dur;\n\t\tfloat e = FMax( FMin( dur != 0f ? q : 0f, 1f ), 0f ) * 512.0f;\n\t\tfloat env0 = envTab.Buffer[Trunc( FMax( FMin( e, e0Hi ), 0f ) )];\n\t\tfloat e1 = e \u002B 1.0f;\n\t\tfloat ef = e1 - MathF.Floor( e1 );\n\t\tfloat env1 = envTab.Buffer[Trunc( FMax( FMin( e1, e1Hi ), 0f ) )];\n\t\treturn (((1.0f - ef) * env0) \u002B (ef * env1)) * osc;\n\t}\n\n\t/// \u003Csummary\u003ERaised-cosine window of gloop voice A (1986-sin table read at the window line~ position).\u003C/summary\u003E\n\tstatic float GloopWindowA( float w, float w1Hi, float w0Hi, HvTable sin )\n\t{\n\t\tfloat w1 = w \u002B 1.0f;\n\t\tfloat s1 = sin.Buffer[Trunc( FMax( FMin( w1, w1Hi ), 0f ) )];\n\t\tfloat fr = w1 - MathF.Floor( w1 );\n\t\tfloat s0 = sin.Buffer[Trunc( FMax( FMin( w, w0Hi ), 0f ) )];\n\t\treturn (((fr * s1) \u002B ((1.0f - fr) * s0)) * 0.5f) \u002B 0.5f;\n\t}\n\n\t/// \u003Csummary\u003ERaised-cosine window of gloop voice B.\u003C/summary\u003E\n\tstatic float GloopWindowB( float w, float w0Hi, float w1Hi, HvTable sin )\n\t{\n\t\tfloat s0 = sin.Buffer[Trunc( FMax( FMin( w, w0Hi ), 0f ) )];\n\t\tfloat w1 = w \u002B 1.0f;\n\t\tfloat fr = w1 - MathF.Floor( w1 );\n\t\tfloat s1 = sin.Buffer[Trunc( FMax( FMin( w1, w1Hi ), 0f ) )];\n\t\treturn ((((1.0f - fr) * s0) \u002B (fr * s1)) * 0.5f) \u002B 0.5f;\n\t}\n\n\t/// \u003Csummary\u003EIndex into a creak grain: phase * 44100 / f, clamped to [0, 1024] and then to [0, hi].\u003C/summary\u003E\n\tstatic float GrainIndex( float phase, float f, float hi )\n\t{\n\t\tfloat rate = 44100.0f / f;\n\t\treturn FMax( FMin( FMax( FMin( phase * (f != 0f ? rate : 0f), 1024f ), 0f ), hi ), 0f );\n\t}\n\n\t/// \u003Csummary\u003ESquared polyBLEP style corrections used by the creak pulse and buzz oscillators.\u003C/summary\u003E\n\tstatic void Blep( float t, float dt, out float lead, out float trail )\n\t{\n\t\tfloat inv = 1.0f / dt;\n\t\tif ( !(dt != 0f) ) inv = 0f;\n\t\tfloat tt = inv * t;\n\t\tfloat a = tt \u002B -1.0f;\n\t\ta *= a;\n\t\tlead = t \u003C= dt ? a : 0f;\n\t\tfloat b = (1.0f - inv) \u002B tt;\n\t\tb *= b;\n\t\ttrail = t \u003E= 1.0f - dt ? b : 0f;\n\t}\n\n\t/// \u003Csummary\u003E\n\t/// Creak voice 1 (\u0022vocal fry\u0022): a pulse gate (grain \u002B saw at rate fA, compared to a width threshold) that\n\t/// chops a buzz (grain \u002B saw at pitch fB), followed by a one-pole low-pass, two one-pole high-passes and\n\t/// a smoothed amplitude. The output (@4024) feeds the stretch high-pass on the next sample.\n\t/// \u003C/summary\u003E\n\tvoid CreakVoice1()\n\t{\n\t\t// part A: pulse rate fA with noise jitter\n\t\tvari2616 = vari2616 * 16807;\n\t\tfloat fA = ((sig3676 * sig4008) * sig3848) - (sig1284 * sig3844);\n\t\tsig1284 = fA;\n\t\tfloat jitA = (sig4068 * (((vari2616 * NoiseScale) * fA) * sig3664)) - (sig1288 * sig4064);\n\t\tsig1288 = jitA;\n\t\tuint p1 = phasor1292;\n\t\tfloat t1 = Phase01( p1 );\n\t\tfloat f = jitA \u002B fA;\n\t\tphasor1292 = p1 \u002B (uint)Trunc( sig1300 * f );\n\t\tfloat idx = GrainIndex( t1, f, sig3952 );\n\t\tfloat fl = MathF.Floor( idx );\n\t\tint i = Trunc( fl );\n\t\tfloat g1 = Tap( table3912.Buffer, i \u002B 1 );\n\t\tfloat g0 = Tap( table3912.Buffer, i );\n\t\tuint p2 = phasor1328;\n\t\tfloat t2 = Phase01( p2 );\n\t\tphasor1328 = p2 \u002B (uint)Trunc( sig1336 * f );\n\t\tfloat saw = (t2 * 2.0f) \u002B -1.0f;\n\t\tBlep( t2, f * sig4016, out float lead, out float trail );\n\t\tfloat delta = (g1 - g0) * (idx - fl);\n\t\tfloat gate = (1.0f - ((((((g0 \u002B 1.0f) \u002B delta) \u002B saw) \u002B lead) - trail) * 0.5f)) \u003E= sig3876 ? 1f : 0f;\n\n\t\t// part B: buzz pitch fB with noise jitter\n\t\tvari3972 = vari3972 * 16807;\n\t\tfloat fB = ((sig3668 * sig4164) * sig2508) - (sig1340 * sig2532);\n\t\tsig1340 = fB;\n\t\tfloat jitB = (sig3680 * (((vari3972 * NoiseScale) * fB) * sig3888)) - (sig1344 * sig3700);\n\t\tsig1344 = jitB;\n\t\tuint p3 = phasor1348;\n\t\tfloat t3 = Phase01( p3 );\n\t\tfloat fb = jitB \u002B fB;\n\t\tphasor1348 = p3 \u002B (uint)Trunc( sig1356 * fb );\n\t\tidx = GrainIndex( t3, fb, sig3652 );\n\t\tfl = MathF.Floor( idx );\n\t\ti = Trunc( fl );\n\t\tfloat gb0 = Tap( table3612.Buffer, i );\n\t\tfloat grain = ((idx - fl) * (Tap( table3612.Buffer, i \u002B 1 ) - gb0)) \u002B gb0;\n\t\tuint p4 = phasor1384;\n\t\tfloat t4 = Phase01( p4 );\n\t\tphasor1384 = p4 \u002B (uint)Trunc( sig1392 * fb );\n\t\tBlep( t4, sig2600 * fb, out lead, out trail );\n\n\t\tsig1396 = ((((((grain \u002B -1.0f) \u002B (t4 * 2.0f)) \u002B lead) - trail) * sig2604) * gate) - (sig1396 * sig4096);\n\t\tfloat prev = sig1400;\n\t\tsig1400 = sig1396;\n\t\tsig1404 = ((sig1396 - prev) * sig4092) - (sig1404 * sig2564);\n\t\tprev = sig1408;\n\t\tsig1408 = sig1404;\n\t\tfloat hp = (sig1404 - prev) * sig2588;\n\t\tsig1412 = (sig4136 * sig2644) - (sig1412 * sig4148);\n\t\tsig4024 = sig1412 * hp;\n\t}\n\n\t/// \u003Csummary\u003ECreak voice 2: same structure as voice 1 with its own noise, tables and parameters (output @5812).\u003C/summary\u003E\n\tvoid CreakVoice2()\n\t{\n\t\tvari5832 = vari5832 * 16807;\n\t\tfloat fA = ((sig4428 * sig5808) * sig5564) - (sig1416 * sig5552);\n\t\tsig1416 = fA;\n\t\tfloat jitA = (sig4268 * (((vari5832 * NoiseScale) * fA) * sig5548)) - (sig1420 * sig4252);\n\t\tsig1420 = jitA;\n\t\tuint p5 = phasor1424;\n\t\tfloat t5 = Phase01( p5 );\n\t\tfloat f = jitA \u002B fA;\n\t\tphasor1424 = p5 \u002B (uint)Trunc( sig1432 * f );\n\t\tfloat idx = GrainIndex( t5, f, sig4304 );\n\t\tfloat fl = MathF.Floor( idx );\n\t\tint i = Trunc( fl );\n\t\tfloat g0 = Tap( table4280.Buffer, i );\n\t\tfloat grainA = ((idx - fl) * (Tap( table4280.Buffer, i \u002B 1 ) - g0)) \u002B g0;\n\t\tuint p6 = phasor1460;\n\t\tfloat t6 = Phase01( p6 );\n\t\tphasor1460 = p6 \u002B (uint)Trunc( sig1468 * f );\n\t\tBlep( t6, sig5836 * f, out float leadA, out float trailA );\n\t\tfloat width = sig4440;\n\n\t\tvari5792 = vari5792 * 16807;\n\t\tfloat fB = ((sig5740 * sig5796) * sig5600) - (sig1472 * sig5624);\n\t\tsig1472 = fB;\n\t\tfloat jitB = (((fB * (vari5792 * NoiseScale)) * sig4436) * sig5704) - (sig1476 * sig5708);\n\t\tsig1476 = jitB;\n\t\tuint p7 = phasor1480;\n\t\tfloat t7 = Phase01( p7 );\n\t\tfloat fb = jitB \u002B fB;\n\t\tphasor1480 = p7 \u002B (uint)Trunc( sig1488 * fb );\n\t\tidx = GrainIndex( t7, fb, sig5872 );\n\t\tfl = MathF.Floor( idx );\n\t\ti = Trunc( fl );\n\t\tfloat gb0 = Tap( table5876.Buffer, i );\n\t\tfloat grainB = ((Tap( table5876.Buffer, i \u002B 1 ) - gb0) * (idx - fl)) \u002B gb0;\n\t\tuint p8 = phasor1516;\n\t\tfloat t8 = Phase01( p8 );\n\t\tphasor1516 = p8 \u002B (uint)Trunc( sig1524 * fb );\n\t\tBlep( t8, sig4564 * fb, out float leadB, out float trailB );\n\n\t\tfloat gate = (1.0f - ((((grainA \u002B (t6 * 2.0f)) \u002B leadA) - trailA) * 0.5f)) \u003E= width ? 1f : 0f;\n\t\tsig1528 = ((gate * sig4572) * ((((grainB \u002B -1.0f) \u002B (t8 * 2.0f)) - trailB) \u002B leadB)) - (sig1528 * sig5680);\n\t\tfloat prev = sig1532;\n\t\tsig1532 = sig1528;\n\t\tsig1536 = (sig5652 * (sig1528 - prev)) - (sig1536 * sig4352);\n\t\tprev = sig1540;\n\t\tsig1540 = sig1536;\n\t\tfloat hp = (sig1536 - prev) * sig4348;\n\t\tsig1544 = (sig4232 * sig4432) - (sig1544 * sig4216);\n\t\tsig5812 = sig1544 * hp;\n\t}\n\n}\n"},{"Ident":"chomnr.squishy_terry","Path":"Scoring/ComboDrain.cs","FileName":"ComboDrain.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\n\nnamespace SquishyTerry.Scoring;\n\n/// \u003Csummary\u003E\n/// The timeline of a combo running out, shared by the \u003Csee cref=\u0022ScoreKeeper\u0022/\u003E (which lets a hit\n/// during it rescue the combo) and the combo HUD (which animates it), so the number you see counting\n/// down is exactly the number a rescue keeps.\n/// \u003Clist type=\u0022bullet\u0022\u003E\n/// \u003Citem\u003EFreeze: the count holds for a moment.\u003C/item\u003E\n/// \u003Citem\u003EPhase A (combos bigger than the bar): the count eases down to a full bar.\u003C/item\u003E\n/// \u003Citem\u003ESwap gap: a short hold at a full bar (the HUD swaps its title card back to the bar here).\u003C/item\u003E\n/// \u003Citem\u003EPhase B: the bar drains one segment per step, the count following it to zero.\u003C/item\u003E\n/// \u003C/list\u003E\n/// \u003C/summary\u003E\npublic static class ComboDrain\n{\n\t/// \u003Csummary\u003ESegments in the HUD\u0027s bar (a combo this big fills it).\u003C/summary\u003E\n\tpublic const int Segments = 20;\n\n\tpublic const float FreezeTime = 0.3f;\n\tpublic const float CountdownA = 0.7f;\n\tpublic const float SwapGap = 0.3f;\n\tpublic const float DropStep = 0.035f;\n\tpublic const float DropFade = 0.06f;\n\n\tpublic static bool HasPhaseA( int peak ) =\u003E peak \u003E Segments;\n\tpublic static int Lit( int peak ) =\u003E Math.Clamp( peak, 0, Segments );\n\tpublic static float PhaseBStart( int peak ) =\u003E FreezeTime \u002B (HasPhaseA( peak ) ? CountdownA \u002B SwapGap : 0f);\n\n\t/// \u003Csummary\u003ETotal length of the drain for a combo of this size.\u003C/summary\u003E\n\tpublic static float Duration( int peak ) =\u003E PhaseBStart( peak ) \u002B Lit( peak ) * DropStep \u002B DropFade;\n\n\t/// \u003Csummary\u003E0..1 how far bar segment k (0 = bottom) has dropped out at time t; the top lit one goes first.\u003C/summary\u003E\n\tpublic static float Dropped( int peak, int k, float t )\n\t{\n\t\tfloat at = PhaseBStart( peak ) \u002B (Lit( peak ) - 1 - k) * DropStep;\n\t\treturn Math.Clamp( (t - at) / DropFade, 0f, 1f );\n\t}\n\n\t/// \u003Csummary\u003EThe combo value shown (and kept by a rescue) at time t into the drain.\u003C/summary\u003E\n\tpublic static int ValueAt( int peak, float t )\n\t{\n\t\tif ( peak \u003C= 0 ) return 0;\n\n\t\t// Phase A: ease the count down from the combo to a full bar.\n\t\tif ( HasPhaseA( peak ) \u0026\u0026 t \u003C FreezeTime \u002B CountdownA )\n\t\t{\n\t\t\tfloat p = Math.Clamp( (t - FreezeTime) / CountdownA, 0f, 1f );\n\t\t\tfloat eased = 1f - (1f - p) * (1f - p);\n\t\t\treturn (int)MathF.Ceiling( peak \u002B (Segments - peak) * eased - 0.001f );\n\t\t}\n\n\t\t// Phase B: exactly the segments still standing.\n\t\tfloat remaining = 0f;\n\t\tfor ( int k = 0; k \u003C Lit( peak ); k\u002B\u002B ) remaining \u002B= 1f - Dropped( peak, k, t );\n\t\treturn (int)MathF.Ceiling( remaining - 0.001f );\n\t}\n}\n"},{"Ident":"chomnr.squishy_terry","Path":"Sim/Face.cs","FileName":"Face.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace SquishyTerry.Sim;\r\n\r\n/// \u003Csummary\u003E\r\n/// The squishy face soft body, reconstructed from the original C\u002B\u002B (wasm) build.\r\n///\r\n/// A unit icosphere (4 subdivisions) is carved into a face: a mouth dent, flattened eye/nose/ear\r\n/// patches and a hair shell. Each step runs position-based dynamics with a BDF2 predictor:\r\n/// pre-tensioned distance constraints, dihedral bending, shape matching on the feature patches\r\n/// and a weak pull back to the rest shape. One step = one 60 Hz frame; there is no dt.\r\n/// \u003C/summary\u003E\r\npublic sealed class Face\r\n{\r\n\t// Per-vertex state (original offsets in the 4496-byte Face object in comments).\r\n\tpublic Vec3[] Pos;          // \u002B0\r\n\tpublic Vec3[] PrevPos;      // \u002B12\r\n\tpublic Vec3[] Normals;      // \u002B24\r\n\tpublic int[] Indices;       // \u002B36\r\n\tpublic float[] InvMass;     // \u002B48\r\n\tpublic float[] Wrinkle;     // \u002B60\r\n\tpublic Vec3[] Vel;          // \u002B72\r\n\tpublic Vec3[] PrevVel;      // \u002B84\r\n\tpublic Vec3[] Pred;         // \u002B96\r\n\tpublic Vec3[] RestPos;      // \u002B108\r\n\tpublic int[] HiddenTriangles; // \u002B120\r\n\tpublic float[] Mouthiness;  // \u002B132\r\n\r\n\tpublic readonly FaceStyle Style;\r\n\r\n\t/// \u003Csummary\u003EHair shell, or null for a bald style.\u003C/summary\u003E\r\n\tpublic Shell Hair;\r\n\t/// \u003Csummary\u003EEyelid shells over each eyeball, or nulls.\u003C/summary\u003E\r\n\tpublic readonly Shell[] Lids = new Shell[2];\r\n\tpublic readonly Part[] Eyes = new Part[2];\r\n\tpublic Part Nose;\r\n\tpublic readonly Part[] Ears = new Part[2];\r\n\r\n\tpublic readonly int[] EyeVertex = new int[2];\r\n\tpublic int MouthVertex;\r\n\tpublic int NoseVertex;\r\n\tpublic readonly int[] EarVertex = new int[2];\r\n\t/// \u003Csummary\u003ERings of vertices around the mouth vertex that form the mouth (2 in the original).\u003C/summary\u003E\r\n\tpublic int MouthRings =\u003E Style.MouthRings;\r\n\r\n\tList\u003CEdge\u003E _edges;\r\n\tList\u003CBend\u003E _bends;\r\n\t// Flattened copies of _edges/_bends for the solver (rebuilt whenever the lists change).\r\n\tDistanceConstraints _distance;\r\n\tBendConstraints _bending;\r\n\r\n\t// Per-step scratch: restRotation applied to RestPos (cached while the rotation is unchanged)\r\n\t// and the per-vertex rest-pull weights k / (1 - k) while dragging.\r\n\tVec3[] _rotatedRest;\r\n\tQuat _rotatedRestFor;\r\n\tbool _rotatedRestValid;\r\n\tfloat[] _pullK;\r\n\tfloat[] _pullKeep;\r\n\r\n\treadonly ShapeRegion[] _eyeRegion = { new(), new() };\r\n\treadonly ShapeRegion _mouthRegion = new();\r\n\treadonly ShapeRegion _noseRegion = new();\r\n\treadonly ShapeRegion[] _earRegion = { new(), new() };\r\n\r\n\tpublic int VertexCount =\u003E Pos.Length;\r\n\tpublic int TriangleCount =\u003E Indices.Length / 3;\r\n\r\n\tpublic Face() : this( FaceStyle.Original ) { }\r\n\r\n\tpublic Face( FaceStyle style )\r\n\t{\r\n\t\tStyle = style;\r\n\t\tvar posList = new List\u003CVec3\u003E();\r\n\t\tvar idxList = new List\u003Cint\u003E();\r\n\t\tGeometry.Icosphere( 4, posList, idxList );\r\n\t\tPos = posList.ToArray();\r\n\t\tIndices = idxList.ToArray();\r\n\t\tint n = Pos.Length;\r\n\r\n\t\tEyeVertex[0] = Nearest( style.LeftEye );\r\n\t\tEyeVertex[1] = Nearest( style.RightEye );\r\n\t\tNoseVertex = Nearest( style.Nose );\r\n\t\tEarVertex[0] = Nearest( style.LeftEar );\r\n\t\tEarVertex[1] = Nearest( style.RightEar );\r\n\t\tMouthVertex = Nearest( style.Mouth );\r\n\r\n\t\tif ( style.HeadShape is not null )\r\n\t\t{\r\n\t\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\t\tPos[v] = style.HeadShape( Pos[v] );\r\n\t\t}\r\n\r\n\t\tWrinkle = new float[n];\r\n\t\tArray.Fill( Wrinkle, 1.0f );\r\n\r\n\t\tvar hidden = new List\u003Cint\u003E();\r\n\t\tif ( style.Hair )\r\n\t\t{\r\n\t\t\tHair = Shell.CreateHair( Pos, Indices );\r\n\t\t\tfor ( int t = 0; t \u003C TriangleCount; t\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tif ( Hair.Inside[Indices[t * 3]] \u0026\u0026 Hair.Inside[Indices[t * 3 \u002B 1]] \u0026\u0026 Hair.Inside[Indices[t * 3 \u002B 2]] )\r\n\t\t\t\t\thidden.Add( t );\r\n\t\t\t}\r\n\t\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\t\tif ( Hair.Touched[v] ) Wrinkle[v] = 0.0f;\r\n\t\t}\r\n\t\tHiddenTriangles = hidden.ToArray();\r\n\r\n\t\t// Carve the mouth: pull the two rings around the mouth vertex in towards it.\r\n\t\tvar mouthRing = Geometry.RingDistances( n, Indices, MouthVertex, MouthRings );\r\n\t\t{\r\n\t\t\tvar c = Pos[MouthVertex];\r\n\t\t\tvar ms = style.MouthScale;\r\n\t\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tint k = mouthRing[v];\r\n\t\t\t\tif ( k \u003C= 0 || k \u003E MouthRings ) continue;\r\n\t\t\t\tvar d = Pos[v] - c;\r\n\t\t\t\tfloat s = (k / (float)MouthRings) * (1.0f / d.Length);\r\n\t\t\t\tPos[v] = new Vec3( d.X * s * ms.X \u002B c.X, d.Y * s * ms.Y \u002B c.Y, d.Z * s * ms.Z \u002B c.Z );\r\n\t\t\t}\r\n\r\n\t\t\tif ( style.MouthCurve != 0 )\r\n\t\t\t{\r\n\t\t\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\t\t{\r\n\t\t\t\t\tif ( mouthRing[v] \u003C 0 || mouthRing[v] \u003E MouthRings ) continue;\r\n\t\t\t\t\tfloat dx = Pos[v].X - c.X;\r\n\t\t\t\t\tPos[v] = new Vec3( Pos[v].X, Pos[v].Y - style.MouthCurve * dx * dx, Pos[v].Z );\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tPrevPos = Geometry.Copy( Pos );\r\n\t\tRestPos = Geometry.Copy( Pos );\r\n\t\tNormals = Geometry.Copy( Pos );\r\n\t\tInvMass = new float[n];\r\n\t\tVel = new Vec3[n];\r\n\t\tPrevVel = new Vec3[n];\r\n\t\tPred = new Vec3[n];\r\n\r\n\t\t_edges = Geometry.BuildEdges( Pos, Indices, 0.75f );\r\n\t\t_bends = Geometry.BuildBends( Pos, Indices );\r\n\t\t_distance = new DistanceConstraints( _edges );\r\n\t\t_bending = new BendConstraints( _bends );\r\n\t\t_rotatedRest = new Vec3[n];\r\n\t\t_pullK = new float[n];\r\n\t\t_pullKeep = new float[n];\r\n\r\n\t\tfor ( int i = 0; i \u003C 30; i\u002B\u002B ) WarmupStep();\r\n\r\n\t\tCarvePatch( NoseVertex, style.NoseRings, style.NosePatch, _noseRegion );\r\n\t\tCarvePatch( EyeVertex[0], style.EyeRings, style.EyePatch, _eyeRegion[0] );\r\n\t\tCarvePatch( EyeVertex[1], style.EyeRings, style.EyePatch, _eyeRegion[1] );\r\n\t\tCarvePatch( EarVertex[0], style.EarRings, style.EarPatch, _earRegion[0] );\r\n\t\tCarvePatch( EarVertex[1], style.EarRings, style.EarPatch, _earRegion[1] );\r\n\t\tGeometry.ComputeNormals( Pos, Indices, Normals );\r\n\r\n\t\tNose = new Part( Pos[NoseVertex], Normals[NoseVertex], style.NoseSize, style.NoseCut, 0.0f, 0.0f, style.NoseShape, style.NoseDetail, style.NoseMask );\r\n\t\tEyes[0] = new Part( Pos[EyeVertex[0]], Normals[EyeVertex[0]], style.EyeSize, style.EyeCut, 0.0f, 0.0f );\r\n\t\tEyes[1] = new Part( Pos[EyeVertex[1]], Normals[EyeVertex[1]], style.EyeSize, style.EyeCut, 0.0f, 0.0f );\r\n\t\tvar earShape = style.EarShape;\r\n\t\tFunc\u003CVec3, Vec3\u003E leftEarShape = earShape is null ? null : p =\u003E { var q = earShape( new Vec3( -p.X, p.Y, p.Z ) ); return new Vec3( -q.X, q.Y, q.Z ); };\r\n\t\tEars[0] = new Part( Pos[EarVertex[0]], Normals[EarVertex[0]], style.EarSize, style.EarCut, -style.EarShear, -style.EarRotation, leftEarShape, style.EarDetail );\r\n\t\tEars[1] = new Part( Pos[EarVertex[1]], Normals[EarVertex[1]], style.EarSize, style.EarCut, style.EarShear, style.EarRotation, earShape, style.EarDetail );\r\n\r\n\t\tif ( style.Eyelids )\r\n\t\t{\r\n\t\t\tvar lidNormal = new Vec3( 0, 1, style.LidTilt ).Normalized;\r\n\t\t\tfloat thickness = style.LidThickness;\r\n\t\t\tfor ( int i = 0; i \u003C 2; i\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tLids[i] = new Shell( Eyes[i].RestUnaligned, Eyes[i].Indices, new Vec3( 0, style.LidHeight, 0 ), lidNormal, _ =\u003E thickness );\r\n\t\t\t\tLids[i].Update( Eyes[i].Pos, Eyes[i].Normals );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvar mouthIdx = new List\u003Cint\u003E();\r\n\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\tif ( mouthRing[v] != -1 ) mouthIdx.Add( v );\r\n\t\t_mouthRegion.Init( true, mouthIdx, Pos );\r\n\r\n\t\tMouthiness = new float[n];\r\n\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\tMouthiness[v] = mouthRing[v] == -1 ? 0.0f : 1.0f - mouthRing[v] / (float)MouthRings;\r\n\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\tif ( (uint)mouthRing[v] \u003C MouthRings \u002B 1 ) Wrinkle[v] = 0.0f;\r\n\r\n\t\t// The mouth centre and first ring lose their springs; no bending anywhere in the mouth.\r\n\t\tbool InInner( int v ) =\u003E mouthRing[v] \u003E -1 \u0026\u0026 mouthRing[v] \u003C MouthRings;\r\n\t\t_edges.RemoveAll( e =\u003E InInner( e.A ) || InInner( e.B ) );\r\n\t\t_bends.RemoveAll( b =\u003E mouthRing[b.P1] != -1 || mouthRing[b.P2] != -1 || mouthRing[b.P3] != -1 || mouthRing[b.P4] != -1 );\r\n\t\t_distance = new DistanceConstraints( _edges );\r\n\t\t_bending = new BendConstraints( _bends );\r\n\r\n\t\tfor ( int i = 0; i \u003C 15; i\u002B\u002B ) WarmupStep();\r\n\t}\r\n\r\n\tvoid WarmupStep() =\u003E\r\n\t\tStep( Quat.Identity, false, 0, Vec3.Zero, 0.8f );\r\n\r\n\tint Nearest( Vec3 target )\r\n\t{\r\n\t\tint best = 0;\r\n\t\tfloat bestDist = 100000000.0f;\r\n\t\tfor ( int i = 0; i \u003C Pos.Length; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tfloat d = (target - Pos[i]).Length;\r\n\t\t\tif ( d \u003C bestDist ) { bestDist = d; best = i; }\r\n\t\t}\r\n\t\treturn best;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EScale a feature patch towards its centre, flatten it and make it shape-matched (f_ic).\u003C/summary\u003E\r\n\tvoid CarvePatch( int center, int rings, Vec3 scale, ShapeRegion region )\r\n\t{\r\n\t\tint n = Pos.Length;\r\n\t\tvar ring = Geometry.RingDistances( n, Indices, center, rings );\r\n\t\tvar c = Pos[center];\r\n\t\tfloat invRings = 1.0f / rings;\r\n\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t{\r\n\t\t\tint k = ring[v];\r\n\t\t\tif ( k \u003C 1 || !(k \u003C= (float)rings) ) continue;\r\n\t\t\tvar d = Pos[v] - c;\r\n\t\t\tfloat x = invRings * k * (1.0f / d.Length);\r\n\t\t\tPos[v] = new Vec3( d.X * scale.X * x \u002B c.X, d.Y * scale.Y * x \u002B c.Y, d.Z * scale.Z * x \u002B c.Z );\r\n\t\t}\r\n\r\n\t\t// Outer boundary loop: edges of triangles with two verts on the last ring and one inside it.\r\n\t\tvar next = new Dictionary\u003Cint, int\u003E();\r\n\t\tint inner = rings - 1;\r\n\t\tfor ( int t = 0; t \u002B 2 \u003C Indices.Length; t \u002B= 3 )\r\n\t\t{\r\n\t\t\tint a = Indices[t], b = Indices[t \u002B 1], cc = Indices[t \u002B 2];\r\n\t\t\tif ( ring[a] == rings \u0026\u0026 ring[b] == rings \u0026\u0026 ring[cc] == inner ) next[a] = b;\r\n\t\t\tif ( ring[b] == rings \u0026\u0026 ring[cc] == rings \u0026\u0026 ring[a] == inner ) next[b] = cc;\r\n\t\t\tif ( ring[cc] == rings \u0026\u0026 ring[a] == rings \u0026\u0026 ring[b] == inner ) next[cc] = a;\r\n\t\t}\r\n\t\tint start = Array.IndexOf( ring, rings );\r\n\t\tvar loop = new List\u003Cint\u003E { start };\r\n\t\twhile ( true )\r\n\t\t{\r\n\t\t\tnext.TryGetValue( loop[^1], out int nx );\r\n\t\t\tif ( nx == loop[0] || loop.Count \u003E n ) break;\r\n\t\t\tloop.Add( nx );\r\n\t\t}\r\n\r\n\t\tvar p0 = Pos[loop[0]];\r\n\t\tvar normal = Vec3.Cross( Pos[loop[1]] - p0, Pos[loop[2]] - p0 ).Normalized;\r\n\t\tif ( Style.FitPatchPlanes )\r\n\t\t{\r\n\t\t\t// Newell\u0027s method: best-fit normal of the whole loop, through its centroid.\r\n\t\t\tvar sum = Vec3.Zero;\r\n\t\t\tvar centroid = Vec3.Zero;\r\n\t\t\tfor ( int i = 0; i \u003C loop.Count; i\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tvar a = Pos[loop[i]];\r\n\t\t\t\tvar b = Pos[loop[(i \u002B 1) % loop.Count]];\r\n\t\t\t\tsum \u002B= new Vec3( (a.Y - b.Y) * (a.Z \u002B b.Z), (a.Z - b.Z) * (a.X \u002B b.X), (a.X - b.X) * (a.Y \u002B b.Y) );\r\n\t\t\t\tcentroid \u002B= a;\r\n\t\t\t}\r\n\t\t\tnormal = sum.Normalized;\r\n\t\t\tp0 = centroid / loop.Count;\r\n\t\t}\r\n\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t{\r\n\t\t\tif ( ring[v] == -1 ) continue;\r\n\t\t\tfloat d = Vec3.Dot( Pos[v] - p0, normal );\r\n\t\t\tPos[v] -= Style.PatchFlatten == 1.0f ? normal * d : normal * (d * Style.PatchFlatten);\r\n\t\t}\r\n\r\n\t\tvar idx = new List\u003Cint\u003E();\r\n\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\tif ( ring[v] != -1 ) idx.Add( v );\r\n\t\tregion.Init( false, idx, Pos );\r\n\r\n\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\tif ( ring[v] \u003C= rings \u0026\u0026 ring[v] \u003E -1 ) Wrinkle[v] = 0.0f;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Advance one frame (f_zd). The JS always passed an identity \u003Cparamref name=\u0022restRotation\u0022/\u003E.\r\n\t/// \u003C/summary\u003E\r\n\t/// \u003Cparam name=\u0022dragging\u0022\u003EWhether a triangle is grabbed.\u003C/param\u003E\r\n\t/// \u003Cparam name=\u0022triangle\u0022\u003EGrabbed triangle index.\u003C/param\u003E\r\n\t/// \u003Cparam name=\u0022target\u0022\u003EWhere the grabbed triangle\u0027s first vertex should go (face-local).\u003C/param\u003E\r\n\t/// \u003Cparam name=\u0022damping\u0022\u003EVelocity damping: 0.8 while dragging, 0.97 otherwise.\u003C/param\u003E\r\n\tpublic void Step( Quat restRotation, bool dragging, int triangle, Vec3 target, float damping )\r\n\t{\r\n\t\t// The per-vertex loops below spell out the Vec3 math by hand: the s\u0026box editor compiles game\r\n\t\t// code unoptimized, where every operator/property is a real call. Each expression keeps the\r\n\t\t// original evaluation order, so the results are bit-identical to the operator version.\r\n\t\tVec3[] pos = Pos, prevPos = PrevPos, vel = Vel, prevVel = PrevVel, pred = Pred, rest = RestPos;\r\n\t\tfloat[] invMass = InvMass;\r\n\t\tint n = pos.Length;\r\n\t\tint t0 = Indices[triangle * 3], t1 = Indices[triangle * 3 \u002B 1], t2 = Indices[triangle * 3 \u002B 2];\r\n\r\n\t\tArray.Fill( invMass, 1.0f );\r\n\t\tif ( dragging )\r\n\t\t{\r\n\t\t\tinvMass[t0] = 0.0f;\r\n\t\t\tinvMass[t1] = 0.0f;\r\n\t\t\tinvMass[t2] = 0.0f;\r\n\t\t}\r\n\r\n\t\t// BDF2 predictor with h = 1 frame.\r\n\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t{\r\n\t\t\tref Vec3 vl = ref vel[v];\r\n\t\t\tfloat vx = vl.X * damping, vy = vl.Y * damping, vz = vl.Z * damping;\r\n\t\t\tvl.X = vx; vl.Y = vy; vl.Z = vz;\r\n\t\t\tref Vec3 p = ref pos[v];\r\n\t\t\tref Vec3 pp = ref prevPos[v];\r\n\t\t\tref Vec3 pv = ref prevVel[v];\r\n\t\t\tref Vec3 pr = ref pred[v];\r\n\t\t\tpr.X = p.X * 1.333333f \u002B vx * 0.888889f \u002B pp.X * -0.333333f \u002B pv.X * -0.222222f;\r\n\t\t\tpr.Y = p.Y * 1.333333f \u002B vy * 0.888889f \u002B pp.Y * -0.333333f \u002B pv.Y * -0.222222f;\r\n\t\t\tpr.Z = p.Z * 1.333333f \u002B vz * 0.888889f \u002B pp.Z * -0.333333f \u002B pv.Z * -0.222222f;\r\n\t\t}\r\n\r\n\t\tif ( dragging )\r\n\t\t{\r\n\t\t\t// Carry the grabbed triangle rigidly, rotated so it stays tangent to the surface.\r\n\t\t\tvar a = rest[t0].Normalized;\r\n\t\t\tvar b = target.Normalized;\r\n\t\t\tvar axis = Vec3.Cross( a, b );\r\n\t\t\tfloat s = axis.Length;\r\n\t\t\tvar r = Quat.Identity;\r\n\t\t\tif ( s \u003E 0 )\r\n\t\t\t\tr = Quat.FromAxisAngle( axis / s, MathF.Asin( MathF.Min( s, 1.0f ) ) );\r\n\t\t\tpred[t0] = target;\r\n\t\t\tpred[t1] = target \u002B r.Rotate( rest[t1] - rest[t0] );\r\n\t\t\tpred[t2] = target \u002B r.Rotate( rest[t2] - rest[t0] );\r\n\t\t}\r\n\r\n\t\t// Rest shape under restRotation; constant for the step (and across steps while it is unchanged).\r\n\t\tVec3[] rotRest = _rotatedRest;\r\n\t\tif ( !_rotatedRestValid || restRotation.X != _rotatedRestFor.X || restRotation.Y != _rotatedRestFor.Y\r\n\t\t\t|| restRotation.Z != _rotatedRestFor.Z || restRotation.W != _rotatedRestFor.W )\r\n\t\t{\r\n\t\t\tfloat qx = restRotation.X, qy = restRotation.Y, qz = restRotation.Z, qw = restRotation.W;\r\n\t\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tref Vec3 rp = ref rest[v];\r\n\t\t\t\t// Quat.Rotate\r\n\t\t\t\tfloat tx = 2f * (qy * rp.Z - qz * rp.Y);\r\n\t\t\t\tfloat ty = 2f * (qz * rp.X - qx * rp.Z);\r\n\t\t\t\tfloat tz = 2f * (qx * rp.Y - qy * rp.X);\r\n\t\t\t\tref Vec3 o = ref rotRest[v];\r\n\t\t\t\to.X = rp.X \u002B qw * tx \u002B (qy * tz - qz * ty);\r\n\t\t\t\to.Y = rp.Y \u002B qw * ty \u002B (qz * tx - qx * tz);\r\n\t\t\t\to.Z = rp.Z \u002B qw * tz \u002B (qx * ty - qy * tx);\r\n\t\t\t}\r\n\t\t\t_rotatedRestFor = restRotation;\r\n\t\t\t_rotatedRestValid = true;\r\n\t\t}\r\n\r\n\t\t// Rest-pull weight k, constant over the solver iterations.\r\n\t\tfloat[] pullK = _pullK, pullKeep = _pullKeep;\r\n\t\tif ( dragging )\r\n\t\t{\r\n\t\t\tvar grab = rest[t0];\r\n\t\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tref Vec3 rp = ref rest[v];\r\n\t\t\t\tfloat k = invMass[v] * 0.01f * (0.5f - (grab.X * rp.X \u002B grab.Y * rp.Y \u002B grab.Z * rp.Z) * 0.5f);\r\n\t\t\t\tpullK[v] = k;\r\n\t\t\t\tpullKeep[v] = 1.0f - k;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tfor ( int iter = 0; iter \u003C 3; iter\u002B\u002B )\r\n\t\t{\r\n\t\t\tGeometry.SolveDistance( _distance, pred, invMass );\r\n\t\t\tGeometry.SolveBending( _bending, pred, invMass, 0.25f );\r\n\t\t\tif ( _mouthRegion.Enabled ) _mouthRegion.Solve( pred );\r\n\r\n\t\t\tif ( dragging )\r\n\t\t\t{\r\n\t\t\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\t\t{\r\n\t\t\t\t\tfloat k = pullK[v], keep = pullKeep[v];\r\n\t\t\t\t\tref Vec3 rr = ref rotRest[v];\r\n\t\t\t\t\tref Vec3 pr = ref pred[v];\r\n\t\t\t\t\tpr.X = rr.X * k \u002B pr.X * keep;\r\n\t\t\t\t\tpr.Y = rr.Y * k \u002B pr.Y * keep;\r\n\t\t\t\t\tpr.Z = rr.Z * k \u002B pr.Z * keep;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t// InvMass is all 1 here, so k = InvMass * 0.001 is the same for every vertex.\r\n\t\t\t\tfloat k = 1.0f * 0.001f, keep = 1.0f - k;\r\n\t\t\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t\t\t{\r\n\t\t\t\t\tref Vec3 rr = ref rotRest[v];\r\n\t\t\t\t\tref Vec3 pr = ref pred[v];\r\n\t\t\t\t\tpr.X = rr.X * k \u002B pr.X * keep;\r\n\t\t\t\t\tpr.Y = rr.Y * k \u002B pr.Y * keep;\r\n\t\t\t\t\tpr.Z = rr.Z * k \u002B pr.Z * keep;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif ( _eyeRegion[0].Enabled ) _eyeRegion[0].Solve( pred );\r\n\t\t\tif ( _eyeRegion[1].Enabled ) _eyeRegion[1].Solve( pred );\r\n\t\t\tif ( _noseRegion.Enabled ) _noseRegion.Solve( pred );\r\n\t\t\tif ( _earRegion[0].Enabled ) _earRegion[0].Solve( pred );\r\n\t\t\tif ( _earRegion[1].Enabled ) _earRegion[1].Solve( pred );\r\n\t\t}\r\n\r\n\t\tfor ( int v = 0; v \u003C n; v\u002B\u002B )\r\n\t\t{\r\n\t\t\tref Vec3 p = ref pos[v];\r\n\t\t\tref Vec3 pr = ref pred[v];\r\n\t\t\tref Vec3 pp = ref prevPos[v];\r\n\t\t\tref Vec3 vl = ref vel[v];\r\n\t\t\tprevVel[v] = vl;\r\n\t\t\tvl.X = p.X * -2.0f \u002B pr.X * 1.5f \u002B pp.X * 0.5f;\r\n\t\t\tvl.Y = p.Y * -2.0f \u002B pr.Y * 1.5f \u002B pp.Y * 0.5f;\r\n\t\t\tvl.Z = p.Z * -2.0f \u002B pr.Z * 1.5f \u002B pp.Z * 0.5f;\r\n\t\t\tpp = p;\r\n\t\t\tp = pr;\r\n\t\t}\r\n\r\n\t\tGeometry.ComputeNormals( pos, Indices, Normals );\r\n\t\tHair?.Update( pos, Normals );\r\n\r\n\t\tEyes[0]?.Update( pos[EyeVertex[0]], Normals[EyeVertex[0]], _eyeRegion[0].Rotation, vel[EyeVertex[0]] );\r\n\t\tEyes[1]?.Update( pos[EyeVertex[1]], Normals[EyeVertex[1]], _eyeRegion[1].Rotation, vel[EyeVertex[1]] );\r\n\t\tNose?.Update( pos[NoseVertex], Normals[NoseVertex], _noseRegion.Rotation, vel[NoseVertex] );\r\n\t\tEars[0]?.Update( pos[EarVertex[0]], Normals[EarVertex[0]], _earRegion[0].Rotation, vel[EarVertex[0]] );\r\n\t\tEars[1]?.Update( pos[EarVertex[1]], Normals[EarVertex[1]], _earRegion[1].Rotation, vel[EarVertex[1]] );\r\n\t\tfor ( int i = 0; i \u003C 2; i\u002B\u002B )\r\n\t\t\tif ( Lids[i] is not null ) Lids[i].Update( Eyes[i].Pos, Eyes[i].Normals );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Triangle under a face-local ray, or -1 (f_oxa). Hair blocks grabbing, and a hit on the mouth\r\n\t/// is redirected to the nearest non-mouth triangle.\r\n\t/// \u003C/summary\u003E\r\n\tpublic int RayIntersect( Vec3 origin, Vec3 dir )\r\n\t{\r\n\t\tint faceTri = ClosestHit( origin, dir, Pos, Indices, out float faceT );\r\n\t\tif ( faceTri == -1 ) return -1;\r\n\t\tif ( Hair is not null )\r\n\t\t{\r\n\t\t\tint hairTri = ClosestHit( origin, dir, Hair.Pos, Hair.Indices, out float hairT );\r\n\t\t\tif ( hairTri != -1 \u0026\u0026 hairT \u003C faceT ) return -1;\r\n\t\t}\r\n\r\n\t\tint a = Indices[faceTri * 3], b = Indices[faceTri * 3 \u002B 1], c = Indices[faceTri * 3 \u002B 2];\r\n\t\tif ( !(Mouthiness[a] \u003E 0) \u0026\u0026 !(Mouthiness[b] \u003E 0) \u0026\u0026 !(Mouthiness[c] \u003E 0) )\r\n\t\t\treturn faceTri;\r\n\t\treturn NearestNonMouthTriangle( faceTri );\r\n\t}\r\n\r\n\tstatic int ClosestHit( Vec3 origin, Vec3 dir, Vec3[] pos, int[] idx, out float bestT )\r\n\t{\r\n\t\tbestT = float.MaxValue;\r\n\t\tint best = -1;\r\n\t\tfor ( int t = 0; t \u002B 2 \u003C idx.Length; t \u002B= 3 )\r\n\t\t{\r\n\t\t\tif ( !Geometry.RayTriangle( origin, dir, pos[idx[t]], pos[idx[t \u002B 1]], pos[idx[t \u002B 2]], out float d ) ) continue;\r\n\t\t\tif ( d \u003C bestT ) { bestT = d; best = t / 3; }\r\n\t\t}\r\n\t\tif ( best == -1 ) bestT = -1;\r\n\t\treturn best;\r\n\t}\r\n\r\n\tint NearestNonMouthTriangle( int tri )\r\n\t{\r\n\t\tvar r = RestPos;\r\n\t\tvar sum = r[Indices[tri * 3]] \u002B r[Indices[tri * 3 \u002B 1]] \u002B r[Indices[tri * 3 \u002B 2]];\r\n\t\tint best = -1;\r\n\t\tfloat bestD = float.MaxValue;\r\n\t\tfor ( int t = 0; t \u003C TriangleCount; t\u002B\u002B )\r\n\t\t{\r\n\t\t\tint a = Indices[t * 3], b = Indices[t * 3 \u002B 1], c = Indices[t * 3 \u002B 2];\r\n\t\t\tvar d = (sum - r[a] - r[b] - r[c]) * 0.333333f;\r\n\t\t\tfloat len = d.Length;\r\n\t\t\tif ( len \u003C bestD \u0026\u0026 !(Mouthiness[a] \u003E 0) \u0026\u0026 !(Mouthiness[b] \u003E 0) \u0026\u0026 !(Mouthiness[c] \u003E 0) )\r\n\t\t\t{\r\n\t\t\t\tbestD = len;\r\n\t\t\t\tbest = t;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn best;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003ECurrent rotation of an eye\u0027s shape-matched patch (what the eyeball rides on).\u003C/summary\u003E\r\n\tpublic Quat EyeRotation( int eye ) =\u003E _eyeRegion[eye].Rotation;\r\n\r\n\t/// \u003Csummary\u003ECentre of an eyeball\u0027s sphere, in face space.\u003C/summary\u003E\r\n\tpublic Vec3 EyeCentre( int eye )\r\n\t{\r\n\t\tvar e = Eyes[eye];\r\n\t\tvar local = new Vec3( 0, 0, -Style.EyeCut * Style.EyeSize.Z );\r\n\t\treturn Pos[EyeVertex[eye]] \u002B _eyeRegion[eye].Rotation.Rotate( e.Align.Rotate( local ) );\r\n\t}\r\n\r\n\tpublic float ComputeVolume() =\u003E Metrics.Volume( Pos, Indices );\r\n\tpublic float ComputeArea() =\u003E Metrics.Area( Pos, Indices );\r\n\tpublic float ComputeAverageSpeed() =\u003E Metrics.AverageSpeed( Vel );\r\n}\r\n"},{"Ident":"chomnr.squishy_terry","Path":"Sim/Geometry.cs","FileName":"Geometry.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\n\r\nnamespace SquishyTerry.Sim;\r\n\r\n/// \u003Csummary\u003EDistance constraint (original: 12-byte struct {u32 a, u32 b, float rest}).\u003C/summary\u003E\r\npublic struct Edge\r\n{\r\n\tpublic int A, B;\r\n\tpublic float Rest;\r\n}\r\n\r\n/// \u003Csummary\u003EDihedral bending constraint across edge P1-P2 (original: 20-byte struct).\u003C/summary\u003E\r\npublic struct Bend\r\n{\r\n\tpublic int P1, P2, P3, P4;\r\n\tpublic float RestAngle;\r\n}\r\n\r\n/// \u003Csummary\u003E\r\n/// Distance constraints flattened into arrays for the solver hot loop (List indexers and struct\r\n/// copies are expensive in the unoptimized editor build).\r\n/// \u003C/summary\u003E\r\npublic sealed class DistanceConstraints\r\n{\r\n\tpublic readonly int[] A, B;\r\n\tpublic readonly float[] Rest;\r\n\tpublic readonly int Count;\r\n\r\n\t/// \u003Cparam name=\u0022edges\u0022\u003EConstraints in solve order.\u003C/param\u003E\r\n\tpublic DistanceConstraints( List\u003CEdge\u003E edges )\r\n\t{\r\n\t\tCount = edges.Count;\r\n\t\tA = new int[Count];\r\n\t\tB = new int[Count];\r\n\t\tRest = new float[Count];\r\n\t\tfor ( int i = 0; i \u003C Count; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tvar e = edges[i];\r\n\t\t\tA[i] = e.A;\r\n\t\t\tB[i] = e.B;\r\n\t\t\tRest[i] = e.Rest;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/// \u003Csummary\u003EBending constraints flattened into arrays, see \u003Csee cref=\u0022DistanceConstraints\u0022/\u003E.\u003C/summary\u003E\r\npublic sealed class BendConstraints\r\n{\r\n\tpublic readonly int[] P1, P2, P3, P4;\r\n\tpublic readonly float[] RestAngle;\r\n\tpublic readonly int Count;\r\n\r\n\t/// \u003Cparam name=\u0022bends\u0022\u003EConstraints in solve order.\u003C/param\u003E\r\n\tpublic BendConstraints( List\u003CBend\u003E bends )\r\n\t{\r\n\t\tCount = bends.Count;\r\n\t\tP1 = new int[Count];\r\n\t\tP2 = new int[Count];\r\n\t\tP3 = new int[Count];\r\n\t\tP4 = new int[Count];\r\n\t\tRestAngle = new float[Count];\r\n\t\tfor ( int i = 0; i \u003C Count; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tvar b = bends[i];\r\n\t\t\tP1[i] = b.P1;\r\n\t\t\tP2[i] = b.P2;\r\n\t\t\tP3[i] = b.P3;\r\n\t\t\tP4[i] = b.P4;\r\n\t\t\tRestAngle[i] = b.RestAngle;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/// \u003Csummary\u003EMesh generation and PBD constraint helpers recovered from the wasm build.\u003C/summary\u003E\r\npublic static class Geometry\r\n{\r\n\t/// \u003Csummary\u003EArray copy (Array.Clone is not on the s\u0026amp;box whitelist).\u003C/summary\u003E\r\n\tpublic static T[] Copy\u003CT\u003E( T[] src )\r\n\t{\r\n\t\tvar dst = new T[src.Length];\r\n\t\tfor ( int i = 0; i \u003C src.Length; i\u002B\u002B ) dst[i] = src[i];\r\n\t\treturn dst;\r\n\t}\r\n\r\n\tstatic readonly int[] IcoTris =\r\n\t{\r\n\t\t0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,\r\n\t\t1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,\r\n\t\t3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,\r\n\t\t4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003EUnit icosphere (f_om / f_caa). Vertex order matches the original.\u003C/summary\u003E\r\n\tpublic static void Icosphere( int levels, List\u003CVec3\u003E pos, List\u003Cint\u003E idx )\r\n\t{\r\n\t\tconst float a = 0.525731f, b = 0.850651f;\r\n\t\tpos.Clear();\r\n\t\tpos.Add( new Vec3( -a, b, 0 ) ); pos.Add( new Vec3( a, b, 0 ) );\r\n\t\tpos.Add( new Vec3( -a, -b, 0 ) ); pos.Add( new Vec3( a, -b, 0 ) );\r\n\t\tpos.Add( new Vec3( 0, -a, b ) ); pos.Add( new Vec3( 0, a, b ) );\r\n\t\tpos.Add( new Vec3( 0, -a, -b ) ); pos.Add( new Vec3( 0, a, -b ) );\r\n\t\tpos.Add( new Vec3( b, 0, -a ) ); pos.Add( new Vec3( b, 0, a ) );\r\n\t\tpos.Add( new Vec3( -b, 0, -a ) ); pos.Add( new Vec3( -b, 0, a ) );\r\n\r\n\t\tidx.Clear();\r\n\t\tidx.AddRange( IcoTris );\r\n\r\n\t\t// The original dedupes midpoints with a linear search (tolerance 1e-4). On a sphere that is\r\n\t\t// equivalent to keying by edge, and the append order is identical.\r\n\t\tvar mids = new Dictionary\u003Clong, int\u003E();\r\n\t\tint Mid( int i, int j )\r\n\t\t{\r\n\t\t\tlong key = i \u003C j ? ((long)i \u003C\u003C 32) | (uint)j : ((long)j \u003C\u003C 32) | (uint)i;\r\n\t\t\tif ( mids.TryGetValue( key, out int m ) ) return m;\r\n\t\t\tvar p = ((pos[i] \u002B pos[j]) * 0.5f).Normalized;\r\n\t\t\tpos.Add( p );\r\n\t\t\tmids[key] = pos.Count - 1;\r\n\t\t\treturn pos.Count - 1;\r\n\t\t}\r\n\r\n\t\tfor ( int l = 0; l \u003C levels; l\u002B\u002B )\r\n\t\t{\r\n\t\t\tvar next = new List\u003Cint\u003E( idx.Count * 4 );\r\n\t\t\tfor ( int t = 0; t \u003C idx.Count; t \u002B= 3 )\r\n\t\t\t{\r\n\t\t\t\tint k = idx[t], m = idx[t \u002B 1], j = idx[t \u002B 2];\r\n\t\t\t\tint g = Mid( k, m ), h = Mid( m, j ), i = Mid( j, k );\r\n\t\t\t\tnext.Add( k ); next.Add( g ); next.Add( i );\r\n\t\t\t\tnext.Add( m ); next.Add( h ); next.Add( g );\r\n\t\t\t\tnext.Add( j ); next.Add( i ); next.Add( h );\r\n\t\t\t\tnext.Add( g ); next.Add( h ); next.Add( i );\r\n\t\t\t}\r\n\t\t\tidx.Clear();\r\n\t\t\tidx.AddRange( next );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Hop distance from \u003Cparamref name=\u0022center\u0022/\u003E through shared triangles, -1 beyond\r\n\t/// \u003Cparamref name=\u0022maxRing\u0022/\u003E (f_wl).\r\n\t/// \u003C/summary\u003E\r\n\tpublic static int[] RingDistances( int vertexCount, IReadOnlyList\u003Cint\u003E idx, int center, int maxRing )\r\n\t{\r\n\t\tvar ring = new int[vertexCount];\r\n\t\tArray.Fill( ring, -1 );\r\n\t\tring[center] = 0;\r\n\t\tfor ( int b = 0; b \u003C maxRing; b\u002B\u002B )\r\n\t\t{\r\n\t\t\tint a = b \u002B 1;\r\n\t\t\tfor ( int t = 0; t \u002B 2 \u003C idx.Count; t \u002B= 3 )\r\n\t\t\t{\r\n\t\t\t\tint i0 = idx[t], i1 = idx[t \u002B 1], i2 = idx[t \u002B 2];\r\n\t\t\t\tif ( ring[i0] == b ) { if ( ring[i1] == -1 ) ring[i1] = a; if ( ring[i2] == -1 ) ring[i2] = a; }\r\n\t\t\t\tif ( ring[i1] == b ) { if ( ring[i0] == -1 ) ring[i0] = a; if ( ring[i2] == -1 ) ring[i2] = a; }\r\n\t\t\t\tif ( ring[i2] == b ) { if ( ring[i0] == -1 ) ring[i0] = a; if ( ring[i1] == -1 ) ring[i1] = a; }\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn ring;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EArea-weighted vertex normals (f_zb).\u003C/summary\u003E\r\n\tpublic static void ComputeNormals( IReadOnlyList\u003CVec3\u003E pos, IReadOnlyList\u003Cint\u003E idx, Vec3[] normals )\r\n\t{\r\n\t\tArray.Clear( normals );\r\n\t\tfor ( int t = 0; t \u002B 2 \u003C idx.Count; t \u002B= 3 )\r\n\t\t{\r\n\t\t\tint a = idx[t], b = idx[t \u002B 1], c = idx[t \u002B 2];\r\n\t\t\tvar n = Vec3.Cross( pos[b] - pos[a], pos[c] - pos[a] );\r\n\t\t\tnormals[a] \u002B= n;\r\n\t\t\tnormals[b] \u002B= n;\r\n\t\t\tnormals[c] \u002B= n;\r\n\t\t}\r\n\t\tfor ( int i = 0; i \u003C normals.Length; i\u002B\u002B )\r\n\t\t\tnormals[i] = normals[i].Normalized;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Area-weighted vertex normals (f_zb), array fast path. The Vec3 math is inlined by hand\r\n\t/// because the editor build is unoptimized; the arithmetic order matches the overload above.\r\n\t/// \u003C/summary\u003E\r\n\tpublic static void ComputeNormals( Vec3[] pos, int[] idx, Vec3[] normals )\r\n\t{\r\n\t\tArray.Clear( normals );\r\n\t\tint count = idx.Length - 2;\r\n\t\tfor ( int t = 0; t \u003C count; t \u002B= 3 )\r\n\t\t{\r\n\t\t\tint a = idx[t], b = idx[t \u002B 1], c = idx[t \u002B 2];\r\n\t\t\tref Vec3 pa = ref pos[a];\r\n\t\t\tref Vec3 pb = ref pos[b];\r\n\t\t\tref Vec3 pc = ref pos[c];\r\n\t\t\tfloat ux = pb.X - pa.X, uy = pb.Y - pa.Y, uz = pb.Z - pa.Z;\r\n\t\t\tfloat vx = pc.X - pa.X, vy = pc.Y - pa.Y, vz = pc.Z - pa.Z;\r\n\t\t\tfloat nx = uy * vz - uz * vy, ny = uz * vx - ux * vz, nz = ux * vy - uy * vx;\r\n\t\t\tref Vec3 na = ref normals[a];\r\n\t\t\tna.X \u002B= nx; na.Y \u002B= ny; na.Z \u002B= nz;\r\n\t\t\tref Vec3 nb = ref normals[b];\r\n\t\t\tnb.X \u002B= nx; nb.Y \u002B= ny; nb.Z \u002B= nz;\r\n\t\t\tref Vec3 nc = ref normals[c];\r\n\t\t\tnc.X \u002B= nx; nc.Y \u002B= ny; nc.Z \u002B= nz;\r\n\t\t}\r\n\t\tfor ( int i = 0; i \u003C normals.Length; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tref Vec3 n = ref normals[i];\r\n\t\t\tfloat inv = 1.0f / MathF.Sqrt( n.X * n.X \u002B n.Y * n.Y \u002B n.Z * n.Z );\r\n\t\t\tn.X *= inv; n.Y *= inv; n.Z *= inv;\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EUnique edges in first-seen order, rest length scaled (f_il / f_ed).\u003C/summary\u003E\r\n\tpublic static List\u003CEdge\u003E BuildEdges( IReadOnlyList\u003CVec3\u003E pos, IReadOnlyList\u003Cint\u003E idx, float scale )\r\n\t{\r\n\t\tvar edges = new List\u003CEdge\u003E();\r\n\t\tvar seen = new HashSet\u003Clong\u003E();\r\n\t\tvoid Add( int a, int b )\r\n\t\t{\r\n\t\t\tlong key = a \u003C b ? ((long)a \u003C\u003C 32) | (uint)b : ((long)b \u003C\u003C 32) | (uint)a;\r\n\t\t\tif ( !seen.Add( key ) ) return;\r\n\t\t\tedges.Add( new Edge { A = a, B = b, Rest = (pos[a] - pos[b]).Length * scale } );\r\n\t\t}\r\n\t\tfor ( int t = 0; t \u002B 2 \u003C idx.Count; t \u002B= 3 )\r\n\t\t{\r\n\t\t\tint i = idx[t], a = idx[t \u002B 1], h = idx[t \u002B 2];\r\n\t\t\tAdd( i, a );\r\n\t\t\tAdd( a, h );\r\n\t\t\tAdd( h, i );\r\n\t\t}\r\n\t\treturn edges;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// One bending constraint per interior edge p1\u0026lt;=p2, found by searching for the triangle that\r\n\t/// contains the reversed edge (f_zk / f_dd).\r\n\t/// \u003C/summary\u003E\r\n\tpublic static List\u003CBend\u003E BuildBends( IReadOnlyList\u003CVec3\u003E pos, IReadOnlyList\u003Cint\u003E idx )\r\n\t{\r\n\t\tvar bends = new List\u003CBend\u003E();\r\n\r\n\t\t// Directed edge -\u003E opposite vertex, so the O(n^2) search in the original becomes a lookup.\r\n\t\t// Iteration order is unaffected because each directed edge occurs once in a manifold mesh.\r\n\t\tvar opposite = new Dictionary\u003Clong, int\u003E();\r\n\t\tstatic long Key( int from, int to ) =\u003E ((long)from \u003C\u003C 32) | (uint)to;\r\n\t\tfor ( int t = 0; t \u002B 2 \u003C idx.Count; t \u002B= 3 )\r\n\t\t{\r\n\t\t\tint a = idx[t], b = idx[t \u002B 1], c = idx[t \u002B 2];\r\n\t\t\topposite[Key( a, b )] = c;\r\n\t\t\topposite[Key( b, c )] = a;\r\n\t\t\topposite[Key( c, a )] = b;\r\n\t\t}\r\n\r\n\t\tvoid Try( int p1, int p2, int p3 )\r\n\t\t{\r\n\t\t\tif ( p2 \u003C p1 ) return;\r\n\t\t\tif ( !opposite.TryGetValue( Key( p2, p1 ), out int p4 ) ) return;\r\n\t\t\tvar e = pos[p2] - pos[p1];\r\n\t\t\tvar n1 = Vec3.Cross( e, pos[p3] - pos[p1] );\r\n\t\t\tvar n2 = Vec3.Cross( e, pos[p4] - pos[p1] );\r\n\t\t\tfloat d = Vec3.Dot( n1, n2 ) * (1.0f / n1.Length) * (1.0f / n2.Length);\r\n\t\t\t// Clamped: nearly coplanar triangles can round to |d| \u003E 1 (never happens on the original sphere).\r\n\t\t\tbends.Add( new Bend { P1 = p1, P2 = p2, P3 = p3, P4 = p4, RestAngle = MathF.Acos( Math.Clamp( d, -1.0f, 1.0f ) ) } );\r\n\t\t}\r\n\r\n\t\tfor ( int t = 0; t \u002B 2 \u003C idx.Count; t \u002B= 3 )\r\n\t\t{\r\n\t\t\tint e = idx[t], f = idx[t \u002B 1], a = idx[t \u002B 2];\r\n\t\t\tTry( e, f, a );\r\n\t\t\tTry( f, a, e );\r\n\t\t\tTry( a, e, f );\r\n\t\t}\r\n\t\treturn bends;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EGauss-Seidel PBD distance projection, stiffness 1 (f_vh).\u003C/summary\u003E\r\n\tpublic static void SolveDistance( DistanceConstraints edges, Vec3[] p, float[] w )\r\n\t{\r\n\t\t// Vec3 math inlined by hand (operators cost a call each in the unoptimized editor build).\r\n\t\t// Every expression keeps the original evaluation order so results stay bit-identical.\r\n\t\tint[] ea = edges.A, eb = edges.B;\r\n\t\tfloat[] rest = edges.Rest;\r\n\t\tint count = edges.Count;\r\n\t\tfor ( int i = 0; i \u003C count; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tint ia = ea[i], ib = eb[i];\r\n\t\t\tref Vec3 pa = ref p[ia];\r\n\t\t\tref Vec3 pb = ref p[ib];\r\n\t\t\tfloat dx = pb.X - pa.X, dy = pb.Y - pa.Y, dz = pb.Z - pa.Z;\r\n\t\t\tfloat len = MathF.Sqrt( dx * dx \u002B dy * dy \u002B dz * dz );\r\n\t\t\tif ( len \u003C 0.000001f ) continue;\r\n\t\t\tfloat wa = w[ia], wb = w[ib];\r\n\t\t\tif ( wa == 0.0f \u0026\u0026 wb == 0.0f ) continue;\r\n\t\t\tfloat q = len - rest[i];\r\n\t\t\tfloat cx = q * dx / len, cy = q * dy / len, cz = q * dz / len;\r\n\t\t\tfloat sum = wb \u002B wa;\r\n\t\t\tfloat sa = wa / sum, sb = wb / sum;\r\n\t\t\tpa.X \u002B= cx * sa; pa.Y \u002B= cy * sa; pa.Z \u002B= cz * sa;\r\n\t\t\tpb.X -= cx * sb; pb.Y -= cy * sb; pb.Z -= cz * sb;\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EM\u00FCller et al. 2007 PBD dihedral bending (f_hjb).\u003C/summary\u003E\r\n\tpublic static void SolveBending( BendConstraints bends, Vec3[] p, float[] w, float stiffness )\r\n\t{\r\n\t\t// Inlined like SolveDistance. n1 x p2 is exactly -(p2 x n1) in IEEE float (same products,\r\n\t\t// negated difference), so q3 and q4 share the two cross products A and B. The four points\r\n\t\t// are read by value and written back once (faster than ref access in the unoptimized build);\r\n\t\t// P1..P4 are always distinct vertices, so this equals updating them in place.\r\n\t\tint[] b1 = bends.P1, b2 = bends.P2, b3 = bends.P3, b4 = bends.P4;\r\n\t\tfloat[] restAngle = bends.RestAngle;\r\n\t\tint count = bends.Count;\r\n\t\tfor ( int i = 0; i \u003C count; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tint i1 = b1[i], i2 = b2[i], i3 = b3[i], i4 = b4[i];\r\n\t\t\tfloat w1 = w[i1], w2 = w[i2], w3 = w[i3], w4 = w[i4];\r\n\t\t\tif ( w1 == 0 || w2 == 0 || w3 == 0 || w4 == 0 ) continue;\r\n\r\n\t\t\tVec3 r1 = p[i1], r2 = p[i2], r3 = p[i3], r4 = p[i4];\r\n\t\t\tfloat ox = r1.X, oy = r1.Y, oz = r1.Z;\r\n\t\t\tfloat p2x = r2.X - ox, p2y = r2.Y - oy, p2z = r2.Z - oz;\r\n\t\t\tfloat p3x = r3.X - ox, p3y = r3.Y - oy, p3z = r3.Z - oz;\r\n\t\t\tfloat p4x = r4.X - ox, p4y = r4.Y - oy, p4z = r4.Z - oz;\r\n\r\n\t\t\tfloat c23x = p2y * p3z - p2z * p3y, c23y = p2z * p3x - p2x * p3z, c23z = p2x * p3y - p2y * p3x;\r\n\t\t\tfloat l23 = MathF.Sqrt( c23x * c23x \u002B c23y * c23y \u002B c23z * c23z );\r\n\t\t\tif ( l23 \u003C 0.00001f ) continue;\r\n\t\t\tfloat n1x = c23x / l23, n1y = c23y / l23, n1z = c23z / l23;\r\n\r\n\t\t\tfloat c24x = p2y * p4z - p2z * p4y, c24y = p2z * p4x - p2x * p4z, c24z = p2x * p4y - p2y * p4x;\r\n\t\t\tfloat l24 = MathF.Sqrt( c24x * c24x \u002B c24y * c24y \u002B c24z * c24z );\r\n\t\t\tif ( l24 \u003C 0.00001f ) continue;\r\n\t\t\tfloat n2x = c24x / l24, n2y = c24y / l24, n2z = c24z / l24;\r\n\r\n\t\t\tfloat d = n1x * n2x \u002B n1y * n2y \u002B n1z * n2z;\r\n\t\t\tif ( d \u003E= 1.0f || d \u003C= -1.0f ) continue;\r\n\r\n\t\t\t// A = p2 x n2, B = p2 x n1\r\n\t\t\tfloat ax = p2y * n2z - p2z * n2y, ay = p2z * n2x - p2x * n2z, az = p2x * n2y - p2y * n2x;\r\n\t\t\tfloat bx = p2y * n1z - p2z * n1y, by = p2z * n1x - p2x * n1z, bz = p2x * n1y - p2y * n1x;\r\n\t\t\t// q3 = (A \u002B (n1 x p2) d) / l23 ; q4 = (B \u002B (n2 x p2) d) / l24\r\n\t\t\tfloat q3x = (ax - bx * d) / l23, q3y = (ay - by * d) / l23, q3z = (az - bz * d) / l23;\r\n\t\t\tfloat q4x = (bx - ax * d) / l24, q4y = (by - ay * d) / l24, q4z = (bz - az * d) / l24;\r\n\r\n\t\t\t// q2 = -((p3 x n2 \u002B (n1 x p3) d) / l23) - (p4 x n1 \u002B (n2 x p4) d) / l24\r\n\t\t\tfloat ex = p3y * n2z - p3z * n2y, ey = p3z * n2x - p3x * n2z, ez = p3x * n2y - p3y * n2x;\r\n\t\t\tfloat fx = n1y * p3z - n1z * p3y, fy = n1z * p3x - n1x * p3z, fz = n1x * p3y - n1y * p3x;\r\n\t\t\tfloat gx = p4y * n1z - p4z * n1y, gy = p4z * n1x - p4x * n1z, gz = p4x * n1y - p4y * n1x;\r\n\t\t\tfloat hx = n2y * p4z - n2z * p4y, hy = n2z * p4x - n2x * p4z, hz = n2x * p4y - n2y * p4x;\r\n\t\t\tfloat q2x = -((ex \u002B fx * d) / l23) - (gx \u002B hx * d) / l24;\r\n\t\t\tfloat q2y = -((ey \u002B fy * d) / l23) - (gy \u002B hy * d) / l24;\r\n\t\t\tfloat q2z = -((ez \u002B fz * d) / l23) - (gz \u002B hz * d) / l24;\r\n\t\t\tfloat q1x = -q2x - q3x - q4x, q1y = -q2y - q3y - q4y, q1z = -q2z - q3z - q4z;\r\n\r\n\t\t\tfloat denom = w1 * (q1x * q1x \u002B q1y * q1y \u002B q1z * q1z) \u002B w2 * (q2x * q2x \u002B q2y * q2y \u002B q2z * q2z)\r\n\t\t\t\t\u002B w3 * (q3x * q3x \u002B q3y * q3y \u002B q3z * q3z) \u002B w4 * (q4x * q4x \u002B q4y * q4y \u002B q4z * q4z);\r\n\t\t\tif ( denom \u003C 0.00001f ) continue;\r\n\r\n\t\t\tfloat lambda = MathF.Sqrt( 1.0f - d * d ) * stiffness * (MathF.Acos( d ) - restAngle[i]) / denom;\r\n\t\t\tfloat s1 = lambda * w1, s2 = lambda * w2, s3 = lambda * w3, s4 = lambda * w4;\r\n\t\t\tp[i1] = new Vec3( r1.X - q1x * s1, r1.Y - q1y * s1, r1.Z - q1z * s1 );\r\n\t\t\tp[i2] = new Vec3( r2.X - q2x * s2, r2.Y - q2y * s2, r2.Z - q2z * s2 );\r\n\t\t\tp[i3] = new Vec3( r3.X - q3x * s3, r3.Y - q3y * s3, r3.Z - q3z * s3 );\r\n\t\t\tp[i4] = new Vec3( r4.X - q4x * s4, r4.Y - q4y * s4, r4.Z - q4z * s4 );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EM\u00F6ller\u2013Trumbore; like the original it does not reject hits behind the origin (f_kc).\u003C/summary\u003E\r\n\tpublic static bool RayTriangle( Vec3 origin, Vec3 dir, Vec3 a, Vec3 b, Vec3 c, out float t )\r\n\t{\r\n\t\tt = 0;\r\n\t\tvar e1 = b - a;\r\n\t\tvar e2 = c - a;\r\n\t\tvar pv = Vec3.Cross( dir, e2 );\r\n\t\tfloat det = Vec3.Dot( e1, pv );\r\n\t\tif ( det \u003E -1e-8f \u0026\u0026 det \u003C 1e-8f ) return false;\r\n\t\tfloat inv = 1.0f / det;\r\n\t\tvar tv = origin - a;\r\n\t\tfloat u = Vec3.Dot( tv, pv ) * inv;\r\n\t\tif ( u \u003C 0.0f || u \u003E 1.0f ) return false;\r\n\t\tvar qv = Vec3.Cross( tv, e1 );\r\n\t\tfloat v = Vec3.Dot( dir, qv ) * inv;\r\n\t\tif ( v \u003C 0.0f || u \u002B v \u003E 1.0f ) return false;\r\n\t\tt = Vec3.Dot( e2, qv ) * inv;\r\n\t\treturn true;\r\n\t}\r\n}\r\n"},{"Ident":"chomnr.squishy_terry","Path":"Sim/Metrics.cs","FileName":"Metrics.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\nusing System.Collections.Generic;\n\nnamespace SquishyTerry.Sim;\n\n/// \u003Csummary\u003EMesh measurements that drive the audio (computeVolume / computeArea / ...).\u003C/summary\u003E\npublic static class Metrics\n{\n\tpublic static float Volume( IReadOnlyList\u003CVec3\u003E p, IReadOnlyList\u003Cint\u003E idx )\n\t{\n\t\tfloat v = 0;\n\t\tfor ( int t = 0; t \u002B 2 \u003C idx.Count; t \u002B= 3 )\n\t\t\tv \u002B= Vec3.Dot( p[idx[t]], Vec3.Cross( p[idx[t \u002B 1]], p[idx[t \u002B 2]] ) ) / 6.0f;\n\t\treturn MathF.Abs( v );\n\t}\n\n\t/// \u003Csummary\u003EArray fast path of \u003Csee cref=\u0022Volume(IReadOnlyList{Vec3}, IReadOnlyList{int})\u0022/\u003E (same arithmetic order).\u003C/summary\u003E\n\tpublic static float Volume( Vec3[] p, int[] idx )\n\t{\n\t\tfloat v = 0;\n\t\tint count = idx.Length - 2;\n\t\tfor ( int t = 0; t \u003C count; t \u002B= 3 )\n\t\t{\n\t\t\tref Vec3 a = ref p[idx[t]];\n\t\t\tref Vec3 b = ref p[idx[t \u002B 1]];\n\t\t\tref Vec3 c = ref p[idx[t \u002B 2]];\n\t\t\tfloat cx = b.Y * c.Z - b.Z * c.Y, cy = b.Z * c.X - b.X * c.Z, cz = b.X * c.Y - b.Y * c.X;\n\t\t\tv \u002B= (a.X * cx \u002B a.Y * cy \u002B a.Z * cz) / 6.0f;\n\t\t}\n\t\treturn MathF.Abs( v );\n\t}\n\n\tpublic static float Area( IReadOnlyList\u003CVec3\u003E p, IReadOnlyList\u003Cint\u003E idx )\n\t{\n\t\tfloat a = 0;\n\t\tfor ( int t = 0; t \u002B 2 \u003C idx.Count; t \u002B= 3 )\n\t\t\ta \u002B= Vec3.Cross( p[idx[t \u002B 1]] - p[idx[t]], p[idx[t \u002B 2]] - p[idx[t]] ).Length * 0.5f;\n\t\treturn a;\n\t}\n\n\t/// \u003Csummary\u003EArray fast path of \u003Csee cref=\u0022Area(IReadOnlyList{Vec3}, IReadOnlyList{int})\u0022/\u003E (same arithmetic order).\u003C/summary\u003E\n\tpublic static float Area( Vec3[] p, int[] idx )\n\t{\n\t\tfloat a = 0;\n\t\tint count = idx.Length - 2;\n\t\tfor ( int t = 0; t \u003C count; t \u002B= 3 )\n\t\t{\n\t\t\tref Vec3 p0 = ref p[idx[t]];\n\t\t\tref Vec3 p1 = ref p[idx[t \u002B 1]];\n\t\t\tref Vec3 p2 = ref p[idx[t \u002B 2]];\n\t\t\tfloat ux = p1.X - p0.X, uy = p1.Y - p0.Y, uz = p1.Z - p0.Z;\n\t\t\tfloat vx = p2.X - p0.X, vy = p2.Y - p0.Y, vz = p2.Z - p0.Z;\n\t\t\tfloat nx = uy * vz - uz * vy, ny = uz * vx - ux * vz, nz = ux * vy - uy * vx;\n\t\t\ta \u002B= MathF.Sqrt( nx * nx \u002B ny * ny \u002B nz * nz ) * 0.5f;\n\t\t}\n\t\treturn a;\n\t}\n\n\tpublic static float AverageSpeed( IReadOnlyList\u003CVec3\u003E vel )\n\t{\n\t\tif ( vel.Count == 0 ) return 0;\n\t\tfloat s = 0;\n\t\tfor ( int i = 0; i \u003C vel.Count; i\u002B\u002B ) s \u002B= vel[i].Length;\n\t\treturn s / vel.Count;\n\t}\n\n\t/// \u003Csummary\u003EArray fast path of \u003Csee cref=\u0022AverageSpeed(IReadOnlyList{Vec3})\u0022/\u003E (same arithmetic order).\u003C/summary\u003E\n\tpublic static float AverageSpeed( Vec3[] vel )\n\t{\n\t\tif ( vel.Length == 0 ) return 0;\n\t\tfloat s = 0;\n\t\tfor ( int i = 0; i \u003C vel.Length; i\u002B\u002B )\n\t\t{\n\t\t\tref Vec3 v = ref vel[i];\n\t\t\ts \u002B= MathF.Sqrt( v.X * v.X \u002B v.Y * v.Y \u002B v.Z * v.Z );\n\t\t}\n\t\treturn s / vel.Length;\n\t}\n}\n"},{"Ident":"chomnr.squishy_terry","Path":"UI/Leaderboard.razor","FileName":"Leaderboard.razor","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"@using Sandbox;\r\n@using Sandbox.UI;\r\n@using SquishyTerry.Scoring;\r\n@namespace SquishyTerry\r\n@inherits PanelComponent\r\n\r\n@*\r\n\tTop 10 leaderboard card on the left of the screen, live from the s\u0026box stats service. The\r\n\tarrows (or the keyboard arrows) switch boards with the deck animation. Scores are recorded by\r\n\tthe ScoreKeeper; the footer shows the player\u0027s own best from their saved profile.\r\n*@\r\n\r\n\u003Croot\u003E\r\n\t@{ var rows = Rows( CurrentBoard ); }\r\n\t\u003Cdiv class=\u0022deck\u0022\u003E\r\n\t\u003Cdiv class=\u0022card\u0022 style=\u0022@CardStyle()\u0022\u003E\r\n\t\t@* Purple tab poking out above the top-left corner. *@\r\n\t\t\u003Cdiv class=\u0022tab\u0022\u003E\u003C/div\u003E\r\n\r\n\t\t\u003Cdiv class=\u0022header\u0022\u003E\r\n\t\t\t@* Terry peeking over the banner, with a little \u0022!\u0022 burst. *@\r\n\t\t\t\u003Cdiv class=\u0022peek\u0022\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022face\u0022\u003E\u003C/div\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022burst b1\u0022\u003E\u003C/div\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022burst b2\u0022\u003E\u003C/div\u003E\r\n\t\t\t\u003C/div\u003E\r\n\r\n\t\t\t\u003Cdiv class=\u0022title-banner\u0022\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022crown\u0022\u003E\u003C/div\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022title\u0022\u003ELeaderboard\u003C/div\u003E\r\n\t\t\t\u003C/div\u003E\r\n\r\n\t\t\t@* Terry\u0027s hands on the edge of the banner. *@\r\n\t\t\t\u003Cdiv class=\u0022hand left\u0022\u003E\u003C/div\u003E\r\n\t\t\t\u003Cdiv class=\u0022hand right\u0022\u003E\u003C/div\u003E\r\n\r\n\t\t\t\u003Cdiv class=\u0022switcher\u0022\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022arrow\u0022 onclick=\u0022@(() =\u003E Cycle( -1 ))\u0022\u003E\u25C0\u003C/div\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022subtitle\u0022\u003E@CurrentBoard.Title\u003C/div\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022arrow\u0022 onclick=\u0022@(() =\u003E Cycle( 1 ))\u0022\u003E\u25B6\u003C/div\u003E\r\n\t\t\t\u003C/div\u003E\r\n\t\t\u003C/div\u003E\r\n\r\n\t\t\u003Cdiv class=\u0022rows\u0022\u003E\r\n\t\t\t@if ( rows.Count == 0 )\r\n\t\t\t{\r\n\t\t\t\t\u003Cdiv class=\u0022empty\u0022\u003E@(_loading.Contains( CurrentBoard.Stat ) ? \u0022Loading...\u0022 : \u0022No scores yet. Be the first!\u0022)\u003C/div\u003E\r\n\t\t\t}\r\n\t\t\t@for ( int i = 0; i \u003C rows.Count; i\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tvar entry = rows[i];\r\n\t\t\t\t@if ( i == 0 )\r\n\t\t\t\t{\r\n\t\t\t\t\t@* First place: a rainbow border that cycles around the row. *@\r\n\t\t\t\t\t\u003Cdiv class=\u0022rainbow\u0022 style=\u0022background-image: @RainbowGradient()\u0022\u003E\r\n\t\t\t\t\t\t\u003Cdiv class=\u0022row first @(entry.IsMe ? \u0022me\u0022 : \u0022\u0022)\u0022\u003E\r\n\t\t\t\t\t\t\t\u003Cdiv class=\u0022dots\u0022\u003E\u003C/div\u003E\r\n\t\t\t\t\t\t\t\u003Cdiv class=\u0022rank\u0022\u003E\r\n\t\t\t\t\t\t\t\t\u003Clabel\u003E1\u003C/label\u003E\r\n\t\t\t\t\t\t\t\t\u003Cdiv class=\u0022crown small\u0022\u003E\u003C/div\u003E\r\n\t\t\t\t\t\t\t\u003C/div\u003E\r\n\t\t\t\t\t\t\t\u003Cdiv class=\u0022avatar-ring gold\u0022 style=\u0022background-image: @RainbowGradient()\u0022\u003E@Avatar( entry )\u003C/div\u003E\r\n\t\t\t\t\t\t\t\u003Cdiv class=\u0022name cycle\u0022\u003E\r\n\t\t\t\t\t\t\t\t@for ( int c = 0; c \u003C entry.Name.Length; c\u002B\u002B )\r\n\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\u003Clabel style=\u0022color: @CycleColor( c, entry.Name.Length )\u0022\u003E@entry.Name[c]\u003C/label\u003E\r\n\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\u003C/div\u003E\r\n\t\t\t\t\t\t\t\u003Cdiv class=\u0022score\u0022\u003E@entry.Score\u003C/div\u003E\r\n\t\t\t\t\t\t\u003C/div\u003E\r\n\t\t\t\t\t\u003C/div\u003E\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t\u003Cdiv class=\u0022row @(entry.IsMe ? \u0022me\u0022 : \u0022\u0022)\u0022\u003E\r\n\t\t\t\t\t\t\u003Cdiv class=\u0022rank box\u0022\u003E@(i \u002B 1)\u003C/div\u003E\r\n\t\t\t\t\t\t\u003Cdiv class=\u0022avatar-ring\u0022\u003E@Avatar( entry )\u003C/div\u003E\r\n\t\t\t\t\t\t\u003Cdiv class=\u0022name\u0022\u003E@entry.Name\u003C/div\u003E\r\n\t\t\t\t\t\t\u003Cdiv class=\u0022score\u0022\u003E@entry.Score\u003C/div\u003E\r\n\t\t\t\t\t\u003C/div\u003E\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\u003C/div\u003E\r\n\r\n\t\t@if ( MeRow( CurrentBoard, rows ) is { } me )\r\n\t\t{\r\n\t\t\t@* You, when you\u0027re not in the top 10: your account\u0027s rank, avatar, name and score. *@\r\n\t\t\t\u003Cdiv class=\u0022you-divider\u0022\u003E\u2022\u2022\u2022\u003C/div\u003E\r\n\t\t\t\u003Cdiv class=\u0022row you\u0022\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022rank box\u0022\u003E@me.Rank\u003C/div\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022avatar-ring\u0022\u003E@Avatar( me.Entry )\u003C/div\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022name\u0022\u003E@me.Entry.Name\u003C/div\u003E\r\n\t\t\t\t\u003Cdiv class=\u0022score\u0022\u003E@me.Entry.Score\u003C/div\u003E\r\n\t\t\t\u003C/div\u003E\r\n\t\t}\r\n\r\n\t\t\u003Cdiv class=\u0022footer\u0022\u003E\r\n\t\t\t\u003Cdiv class=\u0022tagline\u0022\u003E@Tagline( CurrentBoard )\u003C/div\u003E\r\n\t\t\u003C/div\u003E\r\n\r\n\t\t@* Corner detail: dot texture bottom left. *@\r\n\t\t\u003Cdiv class=\u0022corner-dots\u0022\u003E\u003C/div\u003E\r\n\t\u003C/div\u003E\r\n\t\u003C/div\u003E\r\n\u003C/root\u003E\r\n\r\n@code\r\n{\r\n\t/// \u003Cparam name=\u0022SteamId\u0022\u003ESteam id for the avatar; 0 shows the name\u0027s initial instead.\u003C/param\u003E\r\n\tpublic record Entry( string Name, string Score, bool IsMe = false, long SteamId = 0 );\r\n\r\n\t/// \u003Csummary\u003EWhere scores come from (the player\u0027s saved profile is read from it too).\u003C/summary\u003E\r\n\t[Property] public ScoreKeeper Keeper { get; set; }\r\n\r\n\tpublic enum Aggregation { Max, Sum, Avg }\r\n\r\n\t/// \u003Cparam name=\u0022Title\u0022\u003EWhat the board ranks, shown between the arrows.\u003C/param\u003E\r\n\t/// \u003Cparam name=\u0022Stat\u0022\u003EThe stats-service stat it ranks (recorded by the ScoreKeeper).\u003C/param\u003E\r\n\t/// \u003Cparam name=\u0022Personal\u0022\u003EThe player\u0027s own best on this board, from their saved profile.\u003C/param\u003E\r\n\t/// \u003Cparam name=\u0022Placeholder\u0022\u003ERows shown in the editor while there\u0027s no live data yet.\u003C/param\u003E\r\n\tpublic record Board( string Title, string Stat, Aggregation Aggregate, System.Func\u003Cdouble, string\u003E Format,\r\n\t\tSystem.Func\u003CPlayerProfile, string\u003E Personal, List\u003CEntry\u003E Placeholder );\r\n\r\n\t/// \u003Csummary\u003EThe boards the arrows cycle through (placeholders for now).\u003C/summary\u003E\r\n\tpublic List\u003CBoard\u003E Boards { get; set; } = new()\r\n\t{\r\n\t\tnew( \u0022Biggest stretch\u0022, ScoreKeeper.StretchStat, Aggregation.Max, v =\u003E $\u0022{v:0.00}\u0022, p =\u003E $\u0022{p.BestStretch:0.00}\u0022, new()\r\n\t\t{\r\n\t\t\tnew( \u0022Garry\u0022, \u00223.42\u0022, SteamId: 76561197960279927 ),\r\n\t\t\tnew( \u0022Terry\u0022, \u00223.10\u0022 ),\r\n\t\t\tnew( \u0022Layla\u0022, \u00222.87\u0022 ),\r\n\t\t\tnew( \u0022Kristen\u0022, \u00222.61\u0022 ),\r\n\t\t\tnew( \u0022Casey\u0022, \u00222.40\u0022 ),\r\n\t\t\tnew( \u0022Matt\u0022, \u00222.12\u0022 ),\r\n\t\t\tnew( \u0022Sam\u0022, \u00221.98\u0022 ),\r\n\t\t\tnew( \u0022Alex\u0022, \u00221.73\u0022 ),\r\n\t\t\tnew( \u0022Jordan\u0022, \u00221.51\u0022 ),\r\n\t\t\tnew( \u0022Robin\u0022, \u00221.20\u0022 ),\r\n\t\t} ),\r\n\t\tnew( \u0022Best combo\u0022, ScoreKeeper.ComboStat, Aggregation.Max, v =\u003E $\u0022{v:0}\u0022, p =\u003E $\u0022{p.BestCombo}\u0022, new()\r\n\t\t{\r\n\t\t\tnew( \u0022Layla\u0022, \u0022212\u0022 ),\r\n\t\t\tnew( \u0022Garry\u0022, \u0022180\u0022, SteamId: 76561197960279927 ),\r\n\t\t\tnew( \u0022Sam\u0022, \u0022154\u0022 ),\r\n\t\t\tnew( \u0022You\u0022, \u0022121\u0022, true, Sandbox.Utility.Steam.SteamId ),\r\n\t\t\tnew( \u0022Kristen\u0022, \u002298\u0022 ),\r\n\t\t\tnew( \u0022Terry\u0022, \u002277\u0022 ),\r\n\t\t\tnew( \u0022Robin\u0022, \u002264\u0022 ),\r\n\t\t\tnew( \u0022Matt\u0022, \u002251\u0022 ),\r\n\t\t\tnew( \u0022Jordan\u0022, \u002240\u0022 ),\r\n\t\t\tnew( \u0022Alex\u0022, \u002233\u0022 ),\r\n\t\t} ),\r\n\t\tnew( \u0022Total squishes\u0022, ScoreKeeper.SquishStat, Aggregation.Sum, v =\u003E $\u0022{v:N0}\u0022, p =\u003E $\u0022{p.TotalSquishes:N0}\u0022, new()\r\n\t\t{\r\n\t\t\tnew( \u0022Terry\u0022, \u002248,210\u0022 ),\r\n\t\t\tnew( \u0022You\u0022, \u002231,877\u0022, true, Sandbox.Utility.Steam.SteamId ),\r\n\t\t\tnew( \u0022Matt\u0022, \u002227,004\u0022 ),\r\n\t\t\tnew( \u0022Garry\u0022, \u002219,550\u0022, SteamId: 76561197960279927 ),\r\n\t\t\tnew( \u0022Alex\u0022, \u002215,121\u0022 ),\r\n\t\t\tnew( \u0022Jordan\u0022, \u002212,980\u0022 ),\r\n\t\t\tnew( \u0022Layla\u0022, \u00229,440\u0022 ),\r\n\t\t\tnew( \u0022Robin\u0022, \u00227,302\u0022 ),\r\n\t\t\tnew( \u0022Sam\u0022, \u00225,118\u0022 ),\r\n\t\t\tnew( \u0022Kristen\u0022, \u00222,760\u0022 ),\r\n\t\t} ),\r\n\t\tnew( \u0022Total stretches\u0022, ScoreKeeper.StretchCountStat, Aggregation.Sum, v =\u003E $\u0022{v:N0}\u0022, p =\u003E $\u0022{p.TotalStretches:N0}\u0022, new()\r\n\t\t{\r\n\t\t\tnew( \u0022Garry\u0022, \u002239,882\u0022, SteamId: 76561197960279927 ),\r\n\t\t\tnew( \u0022Matt\u0022, \u002230,415\u0022 ),\r\n\t\t\tnew( \u0022Terry\u0022, \u002226,003\u0022 ),\r\n\t\t\tnew( \u0022Layla\u0022, \u002218,774\u0022 ),\r\n\t\t\tnew( \u0022Jordan\u0022, \u002214,090\u0022 ),\r\n\t\t\tnew( \u0022Sam\u0022, \u002211,236\u0022 ),\r\n\t\t\tnew( \u0022Robin\u0022, \u00228,905\u0022 ),\r\n\t\t\tnew( \u0022Alex\u0022, \u00226,321\u0022 ),\r\n\t\t\tnew( \u0022Kristen\u0022, \u00224,450\u0022 ),\r\n\t\t\tnew( \u0022Casey\u0022, \u00221,982\u0022 ),\r\n\t\t} ),\r\n\t\tnew( \u0022Most wrinkles\u0022, ScoreKeeper.WrinkleStat, Aggregation.Max, v =\u003E $\u0022{v:N0}\u0022, p =\u003E $\u0022{p.MostWrinkles:N0}\u0022, new()\r\n\t\t{\r\n\t\t\tnew( \u0022Kristen\u0022, \u0022612\u0022 ),\r\n\t\t\tnew( \u0022Terry\u0022, \u0022575\u0022 ),\r\n\t\t\tnew( \u0022Garry\u0022, \u0022540\u0022, SteamId: 76561197960279927 ),\r\n\t\t\tnew( \u0022Alex\u0022, \u0022498\u0022 ),\r\n\t\t\tnew( \u0022Layla\u0022, \u0022466\u0022 ),\r\n\t\t\tnew( \u0022Matt\u0022, \u0022431\u0022 ),\r\n\t\t\tnew( \u0022Jordan\u0022, \u0022402\u0022 ),\r\n\t\t\tnew( \u0022Robin\u0022, \u0022377\u0022 ),\r\n\t\t\tnew( \u0022Sam\u0022, \u0022351\u0022 ),\r\n\t\t\tnew( \u0022Casey\u0022, \u0022329\u0022 ),\r\n\t\t} ),\r\n\t\tnew( \u0022Fatalities\u0022, ScoreKeeper.FatalityStat, Aggregation.Sum, v =\u003E $\u0022{v:N0}\u0022, p =\u003E $\u0022{p.TotalFatalities:N0}\u0022, new()\r\n\t\t{\r\n\t\t\tnew( \u0022Terry\u0022, \u002288\u0022 ),\r\n\t\t\tnew( \u0022Garry\u0022, \u002271\u0022, SteamId: 76561197960279927 ),\r\n\t\t\tnew( \u0022Matt\u0022, \u002264\u0022 ),\r\n\t\t\tnew( \u0022Layla\u0022, \u002252\u0022 ),\r\n\t\t\tnew( \u0022Jordan\u0022, \u002241\u0022 ),\r\n\t\t\tnew( \u0022Alex\u0022, \u002233\u0022 ),\r\n\t\t\tnew( \u0022Sam\u0022, \u002225\u0022 ),\r\n\t\t\tnew( \u0022Robin\u0022, \u002218\u0022 ),\r\n\t\t\tnew( \u0022Kristen\u0022, \u002211\u0022 ),\r\n\t\t\tnew( \u0022Casey\u0022, \u00224\u0022 ),\r\n\t\t} ),\r\n\t\tnew( \u0022Most blood\u0022, ScoreKeeper.BloodStat, Aggregation.Max, v =\u003E $\u0022{v:N0} ml\u0022, p =\u003E $\u0022{p.MostBlood:N0} ml\u0022, new()\r\n\t\t{\r\n\t\t\tnew( \u0022Terry\u0022, \u00229,840 ml\u0022 ),\r\n\t\t\tnew( \u0022Garry\u0022, \u00228,215 ml\u0022, SteamId: 76561197960279927 ),\r\n\t\t\tnew( \u0022Layla\u0022, \u00227,090 ml\u0022 ),\r\n\t\t\tnew( \u0022Matt\u0022, \u00226,402 ml\u0022 ),\r\n\t\t\tnew( \u0022Jordan\u0022, \u00225,377 ml\u0022 ),\r\n\t\t\tnew( \u0022Alex\u0022, \u00224,120 ml\u0022 ),\r\n\t\t\tnew( \u0022Sam\u0022, \u00223,561 ml\u0022 ),\r\n\t\t\tnew( \u0022Robin\u0022, \u00222,904 ml\u0022 ),\r\n\t\t\tnew( \u0022Kristen\u0022, \u00221,733 ml\u0022 ),\r\n\t\t\tnew( \u0022Casey\u0022, \u0022846 ml\u0022 ),\r\n\t\t} ),\r\n\t\tnew( \u0022Squish efficiency\u0022, ScoreKeeper.EfficiencyStat, Aggregation.Avg, v =\u003E $\u0022{v:0.0}%\u0022, p =\u003E $\u0022{p.AverageEfficiency():0.0}%\u0022, new()\r\n\t\t{\r\n\t\t\tnew( \u0022Sam\u0022, \u002298.7%\u0022 ),\r\n\t\t\tnew( \u0022Garry\u0022, \u002297.2%\u0022, SteamId: 76561197960279927 ),\r\n\t\t\tnew( \u0022Kristen\u0022, \u002295.9%\u0022 ),\r\n\t\t\tnew( \u0022Terry\u0022, \u002293.4%\u0022 ),\r\n\t\t\tnew( \u0022Robin\u0022, \u002291.0%\u0022 ),\r\n\t\t\tnew( \u0022Casey\u0022, \u002288.6%\u0022 ),\r\n\t\t\tnew( \u0022Jordan\u0022, \u002284.1%\u0022 ),\r\n\t\t\tnew( \u0022Layla\u0022, \u002280.3%\u0022 ),\r\n\t\t\tnew( \u0022Alex\u0022, \u002276.8%\u0022 ),\r\n\t\t\tnew( \u0022Matt\u0022, \u002271.5%\u0022 ),\r\n\t\t} ),\r\n\t};\r\n\r\n\t// --- Live data ---\r\n\treadonly Dictionary\u003Cstring, List\u003CEntry\u003E\u003E _live = new();\r\n\treadonly HashSet\u003Cstring\u003E _loading = new();\r\n\treadonly HashSet\u003Cstring\u003E _reportedUnavailable = new();\r\n\t// The player\u0027s own entry per board (rank \u002B value), for the YOU row.\r\n\treadonly Dictionary\u003Cstring, (long Rank, double Value)\u003E _mine = new();\r\n\tfloat _refreshTimer;\r\n\tconst float RefreshInterval = 30f;\r\n\tScoreKeeper _subscribed;\r\n\r\n\t/// \u003Csummary\u003EThe rows to draw: live scores, or the placeholders in the editor before any exist.\u003C/summary\u003E\r\n\tList\u003CEntry\u003E Rows( Board board )\r\n\t{\r\n\t\tif ( _live.TryGetValue( board.Stat, out var live ) \u0026\u0026 live.Count \u003E 0 ) return live;\r\n\t\treturn Game.IsEditor ? board.Placeholder : new List\u003CEntry\u003E();\r\n\t}\r\n\r\n\tasync System.Threading.Tasks.Task Refresh( Board board )\r\n\t{\r\n\t\tif ( !_loading.Add( board.Stat ) ) return;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tvar lb = Sandbox.Services.Leaderboards.GetFromStat( board.Stat );\r\n\t\t\tswitch ( board.Aggregate )\r\n\t\t\t{\r\n\t\t\t\tcase Aggregation.Sum: lb.SetAggregationSum(); break;\r\n\t\t\t\tcase Aggregation.Avg: lb.SetAggregationAvg(); break;\r\n\t\t\t\tdefault: lb.SetAggregationMax(); break;\r\n\t\t\t}\r\n\t\t\tlb.SetSortDescending();\r\n\t\t\tlb.MaxEntries = 10;\r\n\t\t\tawait lb.Refresh( default );\r\n\r\n\t\t\tlong me = Sandbox.Utility.Steam.SteamId;\r\n\t\t\tvar rows = new List\u003CEntry\u003E();\r\n\t\t\tforeach ( var e in lb.Entries ?? System.Array.Empty\u003CSandbox.Services.Leaderboards.Board2.Entry\u003E() )\r\n\t\t\t\trows.Add( new Entry( e.SteamId == me ? \u0022You\u0022 : e.DisplayName ?? \u0022?\u0022, board.Format( e.Value ), e.SteamId == me, e.SteamId ) );\r\n\t\t\t_live[board.Stat] = rows;\r\n\r\n\t\t\t// The player\u0027s own rank: the same board, centred on them, one entry.\r\n\t\t\tvar mine = Sandbox.Services.Leaderboards.GetFromStat( board.Stat );\r\n\t\t\tswitch ( board.Aggregate )\r\n\t\t\t{\r\n\t\t\t\tcase Aggregation.Sum: mine.SetAggregationSum(); break;\r\n\t\t\t\tcase Aggregation.Avg: mine.SetAggregationAvg(); break;\r\n\t\t\t\tdefault: mine.SetAggregationMax(); break;\r\n\t\t\t}\r\n\t\t\tmine.SetSortDescending();\r\n\t\t\tmine.CenterOnMe();\r\n\t\t\tmine.MaxEntries = 1;\r\n\t\t\tawait mine.Refresh( default );\r\n\t\t\tforeach ( var e in mine.Entries ?? System.Array.Empty\u003CSandbox.Services.Leaderboards.Board2.Entry\u003E() )\r\n\t\t\t\tif ( e.SteamId == me ) _mine[board.Stat] = (e.Rank, e.Value);\r\n\t\t}\r\n\t\tcatch ( System.Exception e )\r\n\t\t{\r\n\t\t\t// Offline, or the game isn\u0027t published yet. Say so once per board, not every refresh.\r\n\t\t\tif ( _reportedUnavailable.Add( board.Stat ) )\r\n\t\t\t\tLog.Info( $\u0022Leaderboard \u0027{board.Stat}\u0027 unavailable: {e.Message}\u0022 );\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\t_loading.Remove( board.Stat );\r\n\t\t}\r\n\t}\r\n\r\n\tpublic record MeEntry( string Rank, Entry Entry );\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The YOU row: shown when the player isn\u0027t in the rows above. Uses their live rank when the\r\n\t/// service has one, otherwise their saved personal best (rank unknown).\r\n\t/// \u003C/summary\u003E\r\n\tMeEntry MeRow( Board board, List\u003CEntry\u003E rows )\r\n\t{\r\n\t\tforeach ( var r in rows ) if ( r.IsMe ) return null;\r\n\r\n\t\tlong me = Sandbox.Utility.Steam.SteamId;\r\n\t\tconst string name = \u0022You\u0022;\r\n\t\tif ( _mine.TryGetValue( board.Stat, out var mine ) )\r\n\t\t\treturn new MeEntry( $\u0022{mine.Rank:N0}\u0022, new Entry( name, board.Format( mine.Value ), true, me ) );\r\n\r\n\t\tif ( Keeper?.Profile is { } profile )\r\n\t\t\treturn new MeEntry( \u0022\u2014\u0022, new Entry( name, board.Personal( profile ), true, me ) );\r\n\r\n\t\treturn null;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003ERefreshes the board on screen (the others refresh when you switch to them).\u003C/summary\u003E\r\n\tvoid RefreshCurrent()\r\n\t{\r\n\t\t_ = Refresh( CurrentBoard );\r\n\t\t_refreshTimer = 0f;\r\n\t}\r\n\r\n\tprotected override void OnStart() =\u003E RefreshCurrent();\r\n\r\n\tint _boardIndex;\r\n\tBoard CurrentBoard =\u003E Boards[System.Math.Clamp( _boardIndex, 0, Boards.Count - 1 )];\r\n\r\n\t// --- Switching boards: the card lifts off the deck, sinks back in, and the next board rises\r\n\t// out of the deck and settles with a small overshoot. The content swaps while it\u0027s tucked in. ---\r\n\tconst float LiftTime = 0.14f, SinkTime = 0.16f, RiseTime = 0.3f;\r\n\tconst float SwitchTime = LiftTime \u002B SinkTime \u002B RiseTime;\r\n\r\n\tfloat _switchT = -1f;\r\n\tint _switchDir;\r\n\tint _nextIndex;\r\n\r\n\t// Stats are batched by the service, so give a submission a few seconds before re-reading.\r\n\tvoid OnSubmitted() =\u003E _refreshTimer = System.MathF.Max( _refreshTimer, RefreshInterval - 5f );\r\n\r\n\tprotected override void OnDestroy()\r\n\t{\r\n\t\tif ( _subscribed is not null ) _subscribed.Submitted -= OnSubmitted;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003ESwitches to the next (1) or previous (-1) board with the deck animation.\u003C/summary\u003E\r\n\tpublic void Cycle( int dir )\r\n\t{\r\n\t\tif ( Boards.Count \u003C 2 ) return;\r\n\t\t// A new press mid-switch just retargets the board that comes up.\r\n\t\t_nextIndex = ((_switchT \u003E= 0 ? _nextIndex : _boardIndex) \u002B dir \u002B Boards.Count) % Boards.Count;\r\n\t\tif ( _switchT \u003C 0 || _switchT \u003E LiftTime \u002B SinkTime ) _switchT = 0f;\r\n\t\t_switchDir = dir;\r\n\t}\r\n\r\n\tstatic float EaseOut( float x ) =\u003E 1f - (1f - x) * (1f - x) * (1f - x);\r\n\tstatic float EaseIn( float x ) =\u003E x * x * x;\r\n\tstatic float EaseOutBack( float x )\r\n\t{\r\n\t\tconst float c1 = 1.70158f, c3 = c1 \u002B 1f;\r\n\t\tfloat y = x - 1f;\r\n\t\treturn 1f \u002B c3 * y * y * y \u002B c1 * y * y;\r\n\t}\r\n\r\n\tstring CardStyle()\r\n\t{\r\n\t\t// Resting pose: the slight tilt that matches the combo counter.\r\n\t\tfloat y = 0f, x = 0f, scale = 1f, rotate = 0f, opacity = 1f;\r\n\r\n\t\tif ( _switchT \u003E= 0f )\r\n\t\t{\r\n\t\t\tfloat t = _switchT;\r\n\t\t\tif ( t \u003C LiftTime )\r\n\t\t\t{\r\n\t\t\t\t// Lift: up off the deck, a touch bigger, tipping towards the arrow pressed.\r\n\t\t\t\tfloat p = EaseOut( t / LiftTime );\r\n\t\t\t\ty = -34f * p;\r\n\t\t\t\tx = 10f * _switchDir * p;\r\n\t\t\t\tscale = 1f \u002B 0.05f * p;\r\n\t\t\t\trotate = 5f * _switchDir * p;\r\n\t\t\t}\r\n\t\t\telse if ( t \u003C LiftTime \u002B SinkTime )\r\n\t\t\t{\r\n\t\t\t\t// Sink: back down into the deck, shrinking and fading as it tucks in.\r\n\t\t\t\tfloat p = EaseIn( (t - LiftTime) / SinkTime );\r\n\t\t\t\ty = -34f \u002B 60f * p;\r\n\t\t\t\tx = 10f * _switchDir * (1f - p);\r\n\t\t\t\tscale = 1.05f - 0.13f * p;\r\n\t\t\t\trotate = 5f * _switchDir * (1f - p);\r\n\t\t\t\topacity = 1f - p;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t// Rise: the next board comes up out of the deck and settles with an overshoot.\r\n\t\t\t\tfloat p = System.Math.Clamp( (t - LiftTime - SinkTime) / RiseTime, 0f, 1f );\r\n\t\t\t\tfloat e = EaseOutBack( p );\r\n\t\t\t\ty = 26f * (1f - e);\r\n\t\t\t\tscale = 0.92f \u002B 0.08f * e;\r\n\t\t\t\trotate = -3f * _switchDir * (1f - e);\r\n\t\t\t\topacity = System.Math.Clamp( p * 3f, 0f, 1f );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn $\u0022transform: translateX( {x:0.#}px ) translateY( {y:0.#}px ) scale( {scale:0.###} ) rotate( {rotate:0.##}deg ); opacity: {opacity:0.##};\u0022;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EThe little call to action under each board.\u003C/summary\u003E\r\n\tstatic string Tagline( Board board ) =\u003E board.Stat switch\r\n\t{\r\n\t\tScoreKeeper.StretchStat =\u003E \u0022Stretch further\u0022,\r\n\t\tScoreKeeper.ComboStat =\u003E \u0022Keep the chain alive\u0022,\r\n\t\tScoreKeeper.SquishStat =\u003E \u0022Squish more\u0022,\r\n\t\tScoreKeeper.StretchCountStat =\u003E \u0022Stretch more\u0022,\r\n\t\tScoreKeeper.WrinkleStat =\u003E \u0022Wrinkle harder\u0022,\r\n\t\tScoreKeeper.FatalityStat =\u003E \u0022Finish him\u0022,\r\n\t\tScoreKeeper.BloodStat =\u003E \u0022Make him bleed\u0022,\r\n\t\tScoreKeeper.EfficiencyStat =\u003E \u0022Squish smarter\u0022,\r\n\t\t_ =\u003E \u0022Squish on\u0022,\r\n\t};\r\n\r\n\tRenderFragment Avatar( Entry entry ) =\u003E entry.SteamId != 0\r\n\t\t? @\u003Cdiv class=\u0022avatar\u0022 style=\u0022background-image: url( avatar:@entry.SteamId )\u0022\u003E\u003C/div\u003E\r\n\t\t: @\u003Cdiv class=\u0022avatar placeholder\u0022\u003E@(string.IsNullOrEmpty( entry.Name ) ? \u0022?\u0022 : entry.Name[..1].ToUpperInvariant())\u003C/div\u003E;\r\n\r\n\t/// \u003Csummary\u003EA rainbow colour, the same one the border uses at this point of the spectrum (0..1).\u003C/summary\u003E\r\n\tstring RainbowColor( float t, float saturation = 0.75f, float value = 1f )\r\n\t{\r\n\t\tfloat hue = (t \u002B _rainbowTurn) % 1f * 360f;\r\n\t\tvar c = new ColorHsv( hue, saturation, value ).ToColor();\r\n\t\treturn $\u0022rgb( {(int)(c.r * 255)}, {(int)(c.g * 255)}, {(int)(c.b * 255)} )\u0022;\r\n\t}\r\n\r\n\t// First-place name: Quake-style sticky colour codes. Each new colour wipes across the name left\r\n\t// to right, one letter per step; letters past the wipe keep the previous colour. The palette is\r\n\t// the border\u0027s rainbow (same saturation and brightness), evenly spaced around the spectrum.\r\n\tconst int CycleColors = 6;\r\n\r\n\t/// \u003Csummary\u003EMilliseconds per letter of the first-place colour wipe.\u003C/summary\u003E\r\n\t[Property, Range( 20, 500 )] public float CycleStepMs { get; set; } = 100f;\r\n\r\n\tfloat _cycleTime;\r\n\tlong CycleStep =\u003E (long)(_cycleTime * 1000f / System.MathF.Max( CycleStepMs, 1f ));\r\n\r\n\tstatic string PaletteColor( int index )\r\n\t{\r\n\t\tvar c = new ColorHsv( index * 360f / CycleColors, 0.75f, 1f ).ToColor();\r\n\t\treturn $\u0022rgb( {(int)(c.r * 255)}, {(int)(c.g * 255)}, {(int)(c.b * 255)} )\u0022;\r\n\t}\r\n\r\n\tstring CycleColor( int letter, int length )\r\n\t{\r\n\t\tif ( length \u003C= 0 ) return PaletteColor( 0 );\r\n\t\tlong step = CycleStep;\r\n\t\tint incoming = (int)((step / length) % CycleColors);\r\n\t\tint boundary = (int)(step % length);\r\n\t\treturn PaletteColor( letter \u003C boundary ? incoming : (incoming \u002B CycleColors - 1) % CycleColors );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EHow fast the first-place rainbow goes around (turns per second).\u003C/summary\u003E\r\n\t[Property, Range( 0, 2 )] public float RainbowSpeed { get; set; } = 0.35f;\r\n\r\n\tfloat _rainbowTurn;\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\t_rainbowTurn = (_rainbowTurn \u002B RealTime.Delta * RainbowSpeed) % 1f;\r\n\t\t_cycleTime \u002B= RealTime.Delta;\r\n\r\n\t\t// Hook up to the score keeper; after it submits, refresh soon so new scores show up.\r\n\t\tKeeper ??= Scene.GetAllComponents\u003CScoreKeeper\u003E().FirstOrDefault();\r\n\t\tif ( Keeper != _subscribed )\r\n\t\t{\r\n\t\t\tif ( _subscribed is not null ) _subscribed.Submitted -= OnSubmitted;\r\n\t\t\tif ( Keeper is not null ) Keeper.Submitted \u002B= OnSubmitted;\r\n\t\t\t_subscribed = Keeper;\r\n\t\t}\r\n\t\tif ( (_refreshTimer \u002B= RealTime.Delta) \u003E= RefreshInterval ) RefreshCurrent();\r\n\r\n\t\t// Keyboard arrows switch boards too.\r\n\t\tif ( Input.Keyboard.Pressed( \u0022LEFTARROW\u0022 ) ) Cycle( -1 );\r\n\t\tif ( Input.Keyboard.Pressed( \u0022RIGHTARROW\u0022 ) ) Cycle( 1 );\r\n\r\n\t\tif ( _switchT \u003E= 0f )\r\n\t\t{\r\n\t\t\tfloat before = _switchT;\r\n\t\t\t_switchT \u002B= RealTime.Delta;\r\n\t\t\t// Swap the content while the card is tucked into the deck.\r\n\t\t\tif ( before \u003C LiftTime \u002B SinkTime \u0026\u0026 _switchT \u003E= LiftTime \u002B SinkTime )\r\n\t\t\t{\r\n\t\t\t\t_boardIndex = _nextIndex;\r\n\t\t\t\tRefreshCurrent();\r\n\t\t\t}\r\n\t\t\tif ( _switchT \u003E= SwitchTime ) { _boardIndex = _nextIndex; _switchT = -1f; }\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// A full-spectrum gradient whose direction and colours rotate over time. Lower saturation and\r\n\t/// value give the dark version behind the first-place row, so its bright text stays readable.\r\n\t/// \u003C/summary\u003E\r\n\tstring RainbowGradient( float saturation = 0.75f, float value = 1f )\r\n\t{\r\n\t\tconst int Stops = 7;\r\n\t\tvar stops = new string[Stops];\r\n\t\tfor ( int k = 0; k \u003C Stops; k\u002B\u002B )\r\n\t\t{\r\n\t\t\tstops[k] = RainbowColor( k / (float)(Stops - 1), saturation, value );\r\n\t\t}\r\n\t\treturn $\u0022linear-gradient( {(int)(_rainbowTurn * 360f)}deg, {string.Join( \u0022, \u0022, stops )} )\u0022;\r\n\t}\r\n\r\n\tprotected override int BuildHash() =\u003E System.HashCode.Combine(\r\n\t\tSystem.HashCode.Combine( _boardIndex, Boards.Count, (int)(_rainbowTurn * 360f), CycleStep, (int)(_switchT * 120f) ),\r\n\t\t_live.TryGetValue( CurrentBoard.Stat, out var live ) ? live.GetHashCode() : 0, _loading.Count,\r\n\t\tKeeper?.Profile is { } p ? CurrentBoard.Personal( p ) : \u0022\u0022 );\r\n}\r\n"},{"Ident":"chomnr.squishy_terry","Path":"UI/PullPrompt.razor","FileName":"PullPrompt.razor","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"@using Sandbox;\n@using Sandbox.UI;\n@namespace SquishyTerry\n@inherits PanelComponent\n\n@*\n\tThe original\u0027s in-canvas overlay: the scene fades in from black over 30 frames, and a \u0022pull\u0022\n\tprompt hangs under the chin until 60 frames after the first grab. The original prompt image\n\t(pull.png) was not recovered, so this is a text stand-in.\n*@\n\n\u003Croot\u003E\n\t\u003Cdiv class=\u0022fade\u0022 style=\u0022opacity: @(1f - _fade)\u0022\u003E\u003C/div\u003E\n\n\t@if ( _promptAlpha \u003E 0.001f )\n\t{\n\t\t\u003Cdiv class=\u0022prompt\u0022 style=\u0022opacity: @_promptAlpha; top: @(_top)%;\u0022\u003E\n\t\t\t\u003Cdiv class=\u0022arrow\u0022\u003E\u2194\u003C/div\u003E\n\t\t\t\u003Cdiv class=\u0022label\u0022\u003Epull\u003C/div\u003E\n\t\t\u003C/div\u003E\n\t}\n\u003C/root\u003E\n\n@code\n{\n\t/// \u003Csummary\u003EThe face to follow; found automatically when left empty.\u003C/summary\u003E\n\t[Property] public SquishyFace Face { get; set; }\n\n\tfloat _fade = 1f;\n\tfloat _promptAlpha;\n\tfloat _top = 80f;\n\n\tprotected override void OnUpdate()\n\t{\n\t\tFace ??= Scene.GetAllComponents\u003CSquishyFace\u003E().FirstOrDefault();\n\t\tif ( Face is null || Scene.Camera is null ) return;\n\n\t\t_fade = Face.FadeIn;\n\t\t_promptAlpha = Face.PromptAlpha;\n\t\t// The original put the image\u0027s top 6% of the screen above the anchor point.\n\t\t_top = Scene.Camera.PointToScreenNormal( Face.PromptAnchor ).y * 100f - 6f;\n\t}\n\n\tprotected override int BuildHash() =\u003E System.HashCode.Combine( (int)(_fade * 100), (int)(_promptAlpha * 100), (int)_top );\n}\n"},{"Ident":"chomnr.squishy_terry","Path":"ui/pullprompt.razor.scss","FileName":"pullprompt.razor.scss","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"PullPrompt\n{\n\tposition: absolute;\n\twidth: 100%;\n\theight: 100%;\n\tpointer-events: none;\n}\n\n.fade\n{\n\tposition: absolute;\n\twidth: 100%;\n\theight: 100%;\n\tbackground-color: black;\n}\n\n.prompt\n{\n\tposition: absolute;\n\twidth: 100%;\n\tflex-direction: column;\n\talign-items: center;\n\tcolor: rgba( 255, 255, 255, 0.92 );\n\ttext-shadow: 0 2px 8px rgba( 0, 0, 0, 0.45 );\n\tfont-family: Poppins;\n\n\t.arrow\n\t{\n\t\tfont-size: 34px;\n\t\tline-height: 34px;\n\t}\n\n\t.label\n\t{\n\t\tfont-size: 28px;\n\t\tfont-weight: 600;\n\t\tletter-spacing: 6px;\n\t\ttext-transform: uppercase;\n\t}\n}\n"},{"Ident":"chomnr.squishy_terry","Path":"Scoring/FatalityGate.cs","FileName":"FatalityGate.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\r\n\r\nnamespace SquishyTerry.Scoring;\r\n\r\n/// \u003Csummary\u003E\r\n/// Decides whether a fatality counts, with no engine dependencies (so the test harness can run it).\r\n/// \u003Clist type=\u0022bullet\u0022\u003E\r\n/// \u003Citem\u003EA fatality is \u003Cb\u003Earmed\u003C/b\u003E only by a validated squish that takes the combo to\r\n/// \u003Csee cref=\u0022Combo\u0022/\u003E, and only if the chain got there at a humanly possible pace.\u003C/item\u003E\r\n/// \u003Citem\u003EAn armed fatality must be \u003Cb\u003Espent\u003C/b\u003E within \u003Csee cref=\u0022ArmWindow\u0022/\u003E seconds, and no sooner\r\n/// than \u003Csee cref=\u0022MinKillTime\u0022/\u003E (the knife has to drop, be yanked off its string and driven in).\u003C/item\u003E\r\n/// \u003Citem\u003EEach one needs its own \u003Csee cref=\u0022Combo\u0022/\u003E squishes: a session can never have more\r\n/// fatalities than squishes / \u003Csee cref=\u0022Combo\u0022/\u003E.\u003C/item\u003E\r\n/// \u003Citem\u003EArming again while armed just restarts the window: arms never stack.\u003C/item\u003E\r\n/// \u003C/list\u003E\r\n/// All state lives in \u003Csee cref=\u0022Guarded\u0022/\u003E storage, so memory edits are detected.\r\n/// \u003C/summary\u003E\r\npublic sealed class FatalityGate\r\n{\r\n\t/// \u003Csummary\u003ECombo that earns a fatality.\u003C/summary\u003E\r\n\tpublic const int Combo = 25;\r\n\r\n\t/// \u003Csummary\u003EFastest chain a person can squish (squishes per second).\u003C/summary\u003E\r\n\tpublic const float MaxSquishesPerSecond = 8f;\r\n\r\n\t/// \u003Csummary\u003ESeconds after arming that the kill must happen within.\u003C/summary\u003E\r\n\tpublic const float ArmWindow = 600f; // long enough to let him bleed first (the blood score)\r\n\r\n\t/// \u003Csummary\u003ESeconds after arming before a kill is physically possible.\u003C/summary\u003E\r\n\tpublic const float MinKillTime = 0.75f;\r\n\r\n\treadonly Guarded _armed = new();\r\n\treadonly Guarded _armedAt = new();\r\n\treadonly Guarded _count = new();\r\n\r\n\tpublic bool Armed =\u003E _armed.Value \u003E 0.5f;\r\n\r\n\t/// \u003Csummary\u003EFatalities counted this session.\u003C/summary\u003E\r\n\tpublic int Count =\u003E (int)_count.Value;\r\n\r\n\tpublic bool Tampered =\u003E _armed.Tampered || _armedAt.Tampered || _count.Tampered;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// A validated squish just landed. Arms if it took the combo to \u003Csee cref=\u0022Combo\u0022/\u003E at a possible pace.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void OnSquish( int combo, float chainSeconds, float now )\r\n\t{\r\n\t\tif ( combo != Combo ) return;\r\n\t\tif ( (combo - 1) / MathF.Max( chainSeconds, 0.001f ) \u003E MaxSquishesPerSecond ) return;\r\n\t\t_armed.Value = 1f;\r\n\t\t_armedAt.Value = now;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The knife went all the way in. Spends the arm and returns true if this fatality counts.\r\n\t/// \u003Cparamref name=\u0022sessionSquishes\u0022/\u003E is the validated squishes this session; \u003Cparamref name=\u0022suspicious\u0022/\u003E\r\n\t/// is the anti-macro verdict on the input right now.\r\n\t/// \u003C/summary\u003E\r\n\tpublic bool TryRecord( float now, int sessionSquishes, bool suspicious )\r\n\t{\r\n\t\t// Read everything first: a Guarded value only notices an edit when it\u0027s read.\r\n\t\tbool armed = Armed;\r\n\t\tfloat since = now - _armedAt.Value;\r\n\t\tint count = Count;\r\n\t\tif ( !armed ) return false;\r\n\t\t_armed.Value = 0f; // spent (or thrown away) either way: one knife, one try\r\n\r\n\t\tif ( suspicious || Tampered ) return false;\r\n\t\tif ( since \u003C MinKillTime || since \u003E ArmWindow ) return false;\r\n\t\tif ( sessionSquishes \u003C Combo * (count \u002B 1) ) return false;\r\n\r\n\t\t_count.Value = count \u002B 1;\r\n\t\treturn true;\r\n\t}\r\n}\r\n"},{"Ident":"chomnr.squishy_terry","Path":"Sim/FaceStyle.cs","FileName":"FaceStyle.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\n\nnamespace SquishyTerry.Sim;\n\n/// \u003Csummary\u003E\n/// Everything that decides what the face looks like. \u003Csee cref=\u0022Original\u0022/\u003E reproduces the\n/// recovered game exactly (it is what the wasm comparison test runs); \u003Csee cref=\u0022Terry\u0022/\u003E reshapes\n/// it into the s\u0026amp;box citizen. All feature positions are directions on the unit sphere, picked\n/// before \u003Csee cref=\u0022HeadShape\u0022/\u003E is applied.\n/// \u003C/summary\u003E\npublic sealed class FaceStyle\n{\n\t/// \u003Csummary\u003EDeforms the initial unit sphere. Null keeps the sphere.\u003C/summary\u003E\n\tpublic Func\u003CVec3, Vec3\u003E HeadShape;\n\n\tpublic Vec3 LeftEye = new( -0.234667f, 0.159318f, 0.958931f );\n\tpublic Vec3 RightEye = new( 0.234666f, 0.159318f, 0.958931f );\n\tpublic Vec3 Nose = new( -0.0f, -0.099833f, 0.995004f );\n\tpublic Vec3 LeftEar = new( -0.867728f, -0.149438f, 0.474042f );\n\tpublic Vec3 RightEar = new( 0.867728f, -0.149438f, 0.474042f );\n\tpublic Vec3 Mouth = new( -0.0f, -0.342898f, 0.939373f );\n\n\tpublic bool Hair = true;\n\n\t/// \u003Csummary\u003E\n\t/// Flatten feature patches onto a plane fitted to their whole boundary loop. The original uses\n\t/// three neighbouring boundary points, which tilts mirrored features differently.\n\t/// \u003C/summary\u003E\n\tpublic bool FitPatchPlanes;\n\n\t/// \u003Csummary\u003EHow far feature patches are pushed onto their plane (1 = fully flat, as in the original).\u003C/summary\u003E\n\tpublic float PatchFlatten = 1.0f;\n\n\t/// \u003Csummary\u003EHow many vertex rings around the mouth vertex make up the mouth.\u003C/summary\u003E\n\tpublic int MouthRings = 2;\n\t/// \u003Csummary\u003EMouth rings are squashed onto an ellipse of this size.\u003C/summary\u003E\n\tpublic Vec3 MouthScale = new( 0.16f, 0.08f, 0.16f );\n\t/// \u003Csummary\u003ESkin shading: mouthiness above this is drawn as the inside of the mouth (0.15 in the original).\u003C/summary\u003E\n\tpublic float MouthShadeThreshold = 0.15f;\n\t/// \u003Csummary\u003EPulls the mouth corners down (y -= curve * dx^2).\u003C/summary\u003E\n\tpublic float MouthCurve;\n\n\tpublic int NoseRings = 1;\n\tpublic Vec3 NosePatch = new( 0.065f, 0.065f, 0.065f );\n\tpublic Vec3 NoseSize = new( 0.05f, 0.05f, 0.075f );\n\tpublic float NoseCut = 0.001f;\n\t/// \u003Csummary\u003EOptional sculpt of the nose\u0027s unit sphere (\u002BZ out of the face, \u002BY up) before it is clipped.\u003C/summary\u003E\n\tpublic Func\u003CVec3, Vec3\u003E NoseShape;\n\t/// \u003Csummary\u003ENose mesh subdivisions (3 in the original).\u003C/summary\u003E\n\tpublic int NoseDetail = 3;\n\t/// \u003Csummary\u003EOptional nose shading mask on the sculpted unit sphere: 1 draws in the mouth colour (nostrils).\u003C/summary\u003E\n\tpublic Func\u003CVec3, float\u003E NoseMask;\n\n\tpublic int EyeRings = 3;\n\tpublic Vec3 EyePatch = new( 0.17f, 0.17f, 0.17f );\n\tpublic Vec3 EyeSize = new( 0.17f, 0.17f, 0.17f );\n\tpublic float EyeCut = 0.2f;\n\n\tpublic int EarRings = 2;\n\tpublic Vec3 EarPatch = new( 0.12f, 0.12f, 0.07f );\n\tpublic Vec3 EarSize = new( 0.05f, 0.12f, 0.08f );\n\tpublic float EarCut = 0.001f;\n\tpublic float EarShear = 2.0f;\n\tpublic float EarRotation = 0.3f;\n\t/// \u003Csummary\u003EOptional sculpt of the right ear\u0027s unit sphere (x = back, y = up, z = out from the head); mirrored for the left.\u003C/summary\u003E\n\tpublic Func\u003CVec3, Vec3\u003E EarShape;\n\t/// \u003Csummary\u003EIcosphere subdivisions for the ears (3 in the original).\u003C/summary\u003E\n\tpublic int EarDetail = 3;\n\n\t/// \u003Csummary\u003ESkin shells over the top of each eyeball.\u003C/summary\u003E\n\tpublic bool Eyelids;\n\t/// \u003Csummary\u003ELid edge height in eye space (\u002BY up, \u002BZ out of the face).\u003C/summary\u003E\n\tpublic float LidHeight;\n\t/// \u003Csummary\u003ETilts the lid edge; positive droops it towards the front of the eye.\u003C/summary\u003E\n\tpublic float LidTilt;\n\tpublic float LidThickness = 0.02f;\n\n\tpublic static FaceStyle Original =\u003E new();\n\n\t/// \u003Csummary\u003E0..1 nostril depth on the nose\u0027s unit sphere: two soft holes on the lower front.\u003C/summary\u003E\n\tstatic float NostrilDepth( float x, float y, float z )\n\t{\n\t\tif ( z \u003C 0.1f ) return 0f;\n\t\tfloat depth = 0f;\n\t\tfor ( int side = -1; side \u003C= 1; side \u002B= 2 )\n\t\t{\n\t\t\t// Equal radii (x slightly less to cancel the bulb\u0027s flare) so the holes read as circles from the front.\n\t\t\tfloat dx = (x - side * 0.3f) / 0.19f, dy = (y \u002B 0.36f) / 0.205f;\n\t\t\tfloat d = MathF.Sqrt( dx * dx \u002B dy * dy );\n\t\t\tif ( d \u003C 1f ) depth = MathF.Max( depth, (1f - d) * (1f - d) * (3f - 2f * (1f - d)) );\n\t\t}\n\t\treturn depth;\n\t}\n\n\tpublic static FaceStyle Terry =\u003E new()\n\t{\n\t\tHeadShape = p =\u003E\n\t\t{\n\t\t\t// Bullet head: round dome on top, long jaw below, and a rounded-square cross-section so\n\t\t\t// the face is flat enough for the eyes to look forward.\n\t\t\tfloat y = p.Y \u003E= 0 ? p.Y * 0.95f : p.Y * 1.9f;\n\t\t\tfloat widen = p.Y \u003E= 0 ? 1.0f : 1.0f \u002B 0.35f * p.Y * p.Y;\n\t\t\tfloat r = MathF.Sqrt( p.X * p.X \u002B p.Z * p.Z );\n\t\t\tfloat square = 1.0f;\n\t\t\tif ( r \u003E 1e-6f )\n\t\t\t{\n\t\t\t\tfloat c = MathF.Abs( p.X / r ), s = MathF.Abs( p.Z / r );\n\t\t\t\tsquare = MathF.Pow( c * c * c \u002B s * s * s, -1.0f / 3.0f ) * 0.92f;\n\t\t\t}\n\t\t\tfloat k = widen * square;\n\t\t\treturn new Vec3( p.X * k, y \u002B 0.45f, p.Z * 0.95f * k );\n\t\t},\n\n\t\tLeftEye = new Vec3( -0.52f, -0.2f, 0.843f ).Normalized,\n\t\tRightEye = new Vec3( 0.52f, -0.2f, 0.843f ).Normalized,\n\t\tNose = new Vec3( 0.0f, -0.34f, 0.94f ).Normalized,\n\t\tMouth = new Vec3( 0.0f, -0.6f, 0.8f ).Normalized,\n\t\tLeftEar = new Vec3( -0.9f, -0.25f, 0.357f ).Normalized,\n\t\tRightEar = new Vec3( 0.9f, -0.25f, 0.357f ).Normalized,\n\n\t\tHair = false,\n\t\tFitPatchPlanes = true,\n\t\tPatchFlatten = 1.0f,\n\n\t\tMouthRings = 3,\n\t\tMouthScale = new Vec3( 0.25f, 0.03f, 0.1f ),\n\t\tMouthCurve = 0.6f,\n\t\tMouthShadeThreshold = 0.35f,\n\n\t\tNoseRings = 2,\n\t\tNosePatch = new Vec3( 0.11f, 0.11f, 0.11f ),\n\t\t// Citizen nose: a small, low, rounded bulb, slightly wider at the bottom, with a snub tip so the\n\t\t// two nostrils show from the front.\n\t\tNoseSize = new Vec3( 0.13f, 0.112f, 0.08f ),\n\t\tNoseCut = 0.0f,\n\t\tNoseDetail = 4,\n\t\tNoseShape = p =\u003E\n\t\t{\n\t\t\tfloat x = p.X, y = p.Y, z = p.Z;\n\n\t\t\t// Flatten the underside into a face pointing forward-down, where the nostrils sit; the upper\n\t\t\t// part stays a full rounded bulb.\n\t\t\tconst float ny = -0.857f, nz = 0.514f, plane = 0.35f;\n\t\t\tfloat along = y * ny \u002B z * nz;\n\t\t\tif ( along \u003E plane )\n\t\t\t{\n\t\t\t\tfloat pull = (along - plane) * 0.75f;\n\t\t\t\ty -= pull * ny;\n\t\t\t\tz -= pull * nz;\n\t\t\t}\n\n\t\t\t// Nostrils: push two holes into that flat underside.\n\t\t\tfloat hole = NostrilDepth( x, y, z );\n\t\t\tfloat inward = 1f - 0.45f * hole;\n\t\t\tx *= inward; y *= inward; z *= inward;\n\n\t\t\t// A rounded bulb, only slightly wider at the bottom than the top.\n\t\t\tfloat flare = y \u003C 0 ? 1f \u002B 0.15f * -y : 1f - 0.1f * y;\n\t\t\tx *= flare;\n\n\t\t\treturn new Vec3( x, y, z );\n\t\t},\n\t\tNoseMask = p =\u003E\n\t\t{\n\t\t\t// The sculpted holes are shallow at this size, so darken them like the original does the mouth.\n\t\t\tfloat x = p.X / (p.Y \u003C 0 ? 1f \u002B 0.15f * -p.Y : 1f - 0.1f * p.Y);\n\t\t\t// A smooth value (not 0/1) so the shader\u0027s threshold cuts a round contour across the triangles.\n\t\t\treturn Math.Clamp( (NostrilDepth( x, p.Y, p.Z ) - 0.05f) / 0.2f, 0f, 1f );\n\t\t},\n\n\t\tEyeRings = 3,\n\t\tEyePatch = new Vec3( 0.185f, 0.185f, 0.185f ),\n\t\tEyeSize = new Vec3( 0.185f, 0.185f, 0.185f ),\n\t\tEyeCut = 0.1f,\n\n\t\tEarSize = new Vec3( 0.075f, 0.19f, 0.12f ),\n\t\tEarPatch = new Vec3( 0.14f, 0.14f, 0.08f ),\n\t\tEarShear = 1.3f,\n\t\tEarDetail = 4,\n\t\tEarShape = p =\u003E\n\t\t{\n\t\t\t// Local frame: x = back, y = up, z = out from the head. The shear leans the ear back, so\n\t\t\t// its front (x \u003C 0) is the side you see.\n\t\t\tfloat x = p.X, y = p.Y, z = p.Z;\n\n\t\t\t// A \u0022C\u0022 outline: full at the top, narrowing down into the lobe.\n\t\t\tx *= 1f \u002B 0.2f * y;\n\n\t\t\t// Hollow bowl in the front face, leaving a rolled rim around the top, back and lobe.\n\t\t\tif ( x \u003C 0f )\n\t\t\t{\n\t\t\t\tfloat dy = y / 0.72f, dz = (z - 0.5f) / 0.42f;\n\t\t\t\tfloat r = MathF.Sqrt( dy * dy \u002B dz * dz );\n\t\t\t\tif ( r \u003C 1f )\n\t\t\t\t{\n\t\t\t\t\tfloat s = 1f - r;\n\t\t\t\t\tx *= 1f - 1.5f * s * s * (3f - 2f * s);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn new Vec3( x, y, z );\n\t\t},\n\n\t\tEyelids = true,\n\t\tLidHeight = 0.01f,\n\t\tLidTilt = 0.15f,\n\t\tLidThickness = 0.02f,\n\t};\n}\n"},{"Ident":"chomnr.squishy_terry","Path":"Audio/FaceSynthTables.cs","FileName":"FaceSynthTables.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"// \u003Cauto-generated\u003E\r\n// Table data of the Heavy patch \u0022facesynth\u0022, extracted from the original binary.\r\n// \u003C/auto-generated\u003E\r\n\r\nnamespace SquishyTerry.Audio;\r\n\r\n/// \u003Csummary\u003ETable data used by \u003Csee cref=\u0022FaceSynth\u0022/\u003E.\u003C/summary\u003E\r\nstatic class FaceSynthTables\r\n{\r\n\t/// \u003Csummary\u003ETable \u0022f2_l\u0022 (100 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] F2Low =\r\n\t{\r\n\t\t0.600000024f, 0.600000024f, 0.610000014f, 0.610000014f, 0.600000024f, 0.600000024f, 0.589999974f, 0.589999974f,\r\n\t\t0.579999983f, 0.579999983f, 0.579999983f, 0.579999983f, 0.569999993f, 0.569999993f, 0.560000002f, 0.560000002f,\r\n\t\t0.550000012f, 0.550000012f, 0.540000021f, 0.529999971f, 0.524999976f, 0.519999981f, 0.519999981f, 0.519999981f,\r\n\t\t0.50999999f, 0.5f, 0.5f, 0.49000001f, 0.49000001f, 0.479999989f, 0.479999989f, 0.479999989f,\r\n\t\t0.479999989f, 0.479999989f, 0.479999989f, 0.479999989f, 0.479999989f, 0.479999989f, 0.479999989f, 0.479999989f,\r\n\t\t0.479999989f, 0.479999989f, 0.479999989f, 0.479999989f, 0.479999989f, 0.479999989f, 0.479999989f, 0.49000001f,\r\n\t\t0.49000001f, 0.49000001f, 0.49000001f, 0.49000001f, 0.5f, 0.5f, 0.5f, 0.5f,\r\n\t\t0.50999999f, 0.50999999f, 0.50999999f, 0.50999999f, 0.50999999f, 0.50999999f, 0.50999999f, 0.50999999f,\r\n\t\t0.519999981f, 0.519999981f, 0.529999971f, 0.529999971f, 0.529999971f, 0.529999971f, 0.540000021f, 0.540000021f,\r\n\t\t0.540000021f, 0.540000021f, 0.550000012f, 0.560000002f, 0.560000002f, 0.560000002f, 0.569999993f, 0.579999983f,\r\n\t\t0.589999974f, 0.600000024f, 0.600000024f, 0.620000005f, 0.629999995f, 0.639999986f, 0.660000026f, 0.660000026f,\r\n\t\t0.680000007f, 0.680000007f, 0.699999988f, 0.699999988f, 0.709999979f, 0.720000029f, 0.730000019f, 0.75f,\r\n\t\t0.75999999f, 0.769999981f, 0.779999971f, 0.819999993f, 0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003ETable \u0022f1_l\u0022 (100 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] F1Low =\r\n\t{\r\n\t\t0.389999986f, 0.379999995f, 0.370000005f, 0.370000005f, 0.360000014f, 0.349999994f, 0.349999994f, 0.340000004f,\r\n\t\t0.340000004f, 0.319999993f, 0.319999993f, 0.319999993f, 0.310000002f, 0.310000002f, 0.300000012f, 0.300000012f,\r\n\t\t0.300000012f, 0.289999992f, 0.289999992f, 0.280000001f, 0.273333013f, 0.266665995f, 0.25999999f, 0.25999999f,\r\n\t\t0.25999999f, 0.25f, 0.239999995f, 0.239999995f, 0.219999999f, 0.209999993f, 0.200000003f, 0.189999998f,\r\n\t\t0.180000007f, 0.170000002f, 0.170000002f, 0.166666999f, 0.163332999f, 0.159999996f, 0.155000001f, 0.150000006f,\r\n\t\t0.140000001f, 0.140000001f, 0.140000001f, 0.129999995f, 0.126666993f, 0.123333f, 0.119999997f, 0.1175f,\r\n\t\t0.115000002f, 0.112499997f, 0.109999999f, 0.108000003f, 0.105999999f, 0.104000002f, 0.101999998f, 0.0999998972f,\r\n\t\t0.094999902f, 0.0899998993f, 0.0899998993f, 0.0899998993f, 0.0699999034f, 0.0674998984f, 0.0649999008f, 0.0624998994f,\r\n\t\t0.0599999018f, 0.0599999018f, 0.0599999018f, 0.0599999018f, 0.0599999018f, 0.0599999018f, 0.0566666014f, 0.0533333011f,\r\n\t\t0.0500000007f, 0.0466665998f, 0.0433332995f, 0.0399999991f, 0.0399999991f, 0.0399999991f, 0.0399999991f, 0.0399999991f,\r\n\t\t0.0383333005f, 0.0366665982f, 0.0350000001f, 0.0333333015f, 0.0316665992f, 0.0299999993f, 0.0285714008f, 0.0271428004f,\r\n\t\t0.0257143006f, 0.0242857002f, 0.0228570998f, 0.0214284994f, 0.0199999996f, 0.0183332991f, 0.0166666992f, 0.0149999997f,\r\n\t\t0.0133333001f, 0.0116667002f, 0.00999999046f, 0.00999999046f, 0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003ETable \u0022f1_h\u0022 (100 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] F1High =\r\n\t{\r\n\t\t-0.00999980979f, -0.00999980979f, 1.78814005E-07f, 1.78814005E-07f, 1.78814005E-07f, 0.0100002f, 0.0100002f, 0.0200002007f,\r\n\t\t0.0200002007f, 0.0200002007f, 0.0300002005f, 0.0300002005f, 0.0400000997f, 0.0400000997f, 0.0400000997f, 0.0600000992f,\r\n\t\t0.0600000992f, 0.109999999f, 0.119999997f, 0.129999995f, 0.140000001f, 0.140000001f, 0.140000001f, 0.150000006f,\r\n\t\t0.159999996f, 0.159999996f, 0.159999996f, 0.170000002f, 0.180000007f, 0.150000006f, 0.170000002f, 0.170000002f,\r\n\t\t0.150000006f, 0.150000006f, 0.140000001f, 0.140000001f, 0.140000001f, 0.140000001f, 0.140000001f, 0.129999995f,\r\n\t\t0.129999995f, 0.129999995f, 0.129999995f, 0.129999995f, 0.129999995f, 0.129999995f, 0.129999995f, 0.129999995f,\r\n\t\t0.129999995f, 0.119999997f, 0.119999997f, 0.119999997f, 0.119999997f, 0.119999997f, 0.119999997f, 0.109999999f,\r\n\t\t0.109999999f, 0.0999998972f, 0.0999998972f, 0.0899998993f, 0.0899998993f, 0.0799999014f, 0.0799999014f, 0.0699999034f,\r\n\t\t0.0699999034f, 0.0599999018f, 0.0599999018f, 0.0500000007f, 0.0500000007f, 0.0500000007f, 0.0599999987f, 0.0500000007f,\r\n\t\t0.0399999991f, 0.0399999991f, 0.0299999993f, 0.0299999993f, 0.0299999993f, 0.0199999996f, 0.0199999996f, 0.0199999996f,\r\n\t\t0.0199999996f, 0.0199999996f, 0.0199999996f, 0.0100001004f, 0.0100001004f, 0.0100001004f, 0.0100001004f, 0.0100001004f,\r\n\t\t0.0100001004f, 0.0100001004f, 0.0100001004f, 0.0100001004f, 0.00999999046f, 0.00999999046f, 0.00999999046f, 0.00999999046f,\r\n\t\t0.00999999046f, 0.00999999046f, 0.00999999046f, 0.00999999046f, 0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003ETable \u0022v_l\u0022 (100 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] VLow =\r\n\t{\r\n\t\t0.00999999046f, 0.00999975018f, 0.00999975018f, 0.00999975018f, 0.0500211008f, 0.0600208007f, 0.0700206012f, 0.080020301f,\r\n\t\t0.0900200978f, 0.110019997f, 0.130018994f, 0.140019f, 0.170018002f, 0.190017998f, 0.200017005f, 0.210016996f,\r\n\t\t0.220017001f, 0.230017006f, 0.280014992f, 0.290015012f, 0.290015012f, 0.310014993f, 0.320014f, 0.340014011f,\r\n\t\t0.340014011f, 0.350014001f, 0.370012999f, 0.370012999f, 0.380012989f, 0.390013009f, 0.400011986f, 0.410012007f,\r\n\t\t0.410012007f, 0.420011997f, 0.430011988f, 0.440010995f, 0.450010985f, 0.45501101f, 0.460011005f, 0.460011005f,\r\n\t\t0.470010996f, 0.470010996f, 0.480010003f, 0.490009993f, 0.500010014f, 0.510010004f, 0.520008981f, 0.520008981f,\r\n\t\t0.530008972f, 0.540009022f, 0.540009022f, 0.560007989f, 0.560007989f, 0.560007989f, 0.57000798f, 0.573341012f,\r\n\t\t0.576674998f, 0.58000797f, 0.59000802f, 0.595008016f, 0.600006998f, 0.610006988f, 0.610006988f, 0.620006979f,\r\n\t\t0.630007029f, 0.630007029f, 0.650005996f, 0.650005996f, 0.660005987f, 0.670005977f, 0.670005977f, 0.680005014f,\r\n\t\t0.690005004f, 0.690005004f, 0.700004995f, 0.700004995f, 0.710004985f, 0.710004985f, 0.720004022f, 0.720004022f,\r\n\t\t0.720004022f, 0.730004013f, 0.740004003f, 0.750003994f, 0.770003021f, 0.770003021f, 0.780003011f, 0.800001979f,\r\n\t\t0.800001979f, 0.820002019f, 0.820002019f, 0.83000201f, 0.840000987f, 0.840000987f, 0.850000978f, 0.860001028f,\r\n\t\t0.879999995f, 0.879999995f, 0.889999986f, 0.899999976f, 0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003ETable \u0022v_h\u0022 (100 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] VHigh =\r\n\t{\r\n\t\t0.620002985f, 0.665001988f, 0.670001984f, 0.675001025f, 0.68000102f, 0.685001016f, 0.690001011f, 0.690001011f,\r\n\t\t0.700001001f, 0.705000997f, 0.710000992f, 0.710000992f, 0.720000029f, 0.730000019f, 0.729996979f, 0.729996979f,\r\n\t\t0.729996979f, 0.739997983f, 0.739997983f, 0.749997973f, 0.749997973f, 0.749997973f, 0.749997973f, 0.749997973f,\r\n\t\t0.759998024f, 0.759998024f, 0.759998024f, 0.759998024f, 0.769998014f, 0.779998004f, 0.779998004f, 0.789999008f,\r\n\t\t0.789999008f, 0.799998999f, 0.809998989f, 0.81999898f, 0.829999983f, 0.829999983f, 0.839999974f, 0.850000024f,\r\n\t\t0.850000024f, 0.870012999f, 0.870012999f, 0.880014002f, 0.880014002f, 0.890013993f, 0.900013983f, 0.900013983f,\r\n\t\t0.900013983f, 0.900013983f, 0.900013983f, 0.903347015f, 0.906681001f, 0.910013974f, 0.910013974f, 0.920014024f,\r\n\t\t0.920014024f, 0.920014024f, 0.920014024f, 0.920014024f, 0.920014024f, 0.920014024f, 0.920014024f, 0.920014024f,\r\n\t\t0.920014024f, 0.920014024f, 0.920014024f, 0.920014024f, 0.920014024f, 0.920014024f, 0.920014024f, 0.920014024f,\r\n\t\t0.920014024f, 0.920014024f, 0.920014024f, 0.920014977f, 0.92334801f, 0.926680982f, 0.930015028f, 0.930015028f,\r\n\t\t0.930015028f, 0.930015028f, 0.940015018f, 0.940015018f, 0.940015018f, 0.940015018f, 0.940015018f, 0.940015018f,\r\n\t\t0.940015018f, 0.940015018f, 0.940015018f, 0.950015008f, 0.950015008f, 0.950015008f, 0.950015008f, 0.950015008f,\r\n\t\t0.950015008f, 0.950015008f, 0.950015008f, 0.950015008f, 0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003ETable \u0022hp_l\u0022 (100 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] HpLow =\r\n\t{\r\n\t\t0.569999993f, 0.560000002f, 0.550000012f, 0.540000021f, 0.540000021f, 0.529999971f, 0.529999971f, 0.529999971f,\r\n\t\t0.519999981f, 0.519999981f, 0.514999986f, 0.50999999f, 0.504999995f, 0.5f, 0.5f, 0.5f,\r\n\t\t0.49000001f, 0.479999989f, 0.479999989f, 0.479999989f, 0.476666003f, 0.473333001f, 0.469999999f, 0.469999999f,\r\n\t\t0.469999999f, 0.460000008f, 0.449999988f, 0.449999988f, 0.439999998f, 0.439999998f, 0.430000007f, 0.419999987f,\r\n\t\t0.409999996f, 0.409999996f, 0.405000001f, 0.400000006f, 0.395000011f, 0.389999986f, 0.389999986f, 0.379999995f,\r\n\t\t0.370000005f, 0.370000005f, 0.36500001f, 0.360000014f, 0.349999994f, 0.349999994f, 0.340000004f, 0.340000004f,\r\n\t\t0.330000013f, 0.319999993f, 0.314999998f, 0.310000002f, 0.310000002f, 0.300000012f, 0.289999992f, 0.289999992f,\r\n\t\t0.280000001f, 0.270000011f, 0.270000011f, 0.25999999f, 0.254999995f, 0.25f, 0.25f, 0.239999995f,\r\n\t\t0.239999995f, 0.239999995f, 0.230000004f, 0.230000004f, 0.219999999f, 0.209999993f, 0.209999993f, 0.200000003f,\r\n\t\t0.200000003f, 0.189999998f, 0.180000007f, 0.180000007f, 0.170000002f, 0.170000002f, 0.170000002f, 0.159999996f,\r\n\t\t0.159999996f, 0.159999996f, 0.159999996f, 0.155000001f, 0.150000006f, 0.144999996f, 0.140000001f, 0.140000001f,\r\n\t\t0.140000001f, 0.140000001f, 0.140000001f, 0.140000001f, 0.140000001f, 0.140000001f, 0.150001004f, 0.150001004f,\r\n\t\t0.150001004f, 0.150001004f, 0.160000995f, 0.119999997f, 0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003ETable \u0022f2_h\u0022 (100 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] F2High =\r\n\t{\r\n\t\t-0.209999993f, -0.189999998f, -0.180000007f, -0.170000002f, -0.159999996f, -0.150000006f, -0.140000001f, -0.129999995f,\r\n\t\t-0.119999997f, -0.119999997f, -0.109999999f, -0.0999998003f, -0.0999998003f, -0.0899998993f, -0.0799999014f, -0.0699999034f,\r\n\t\t-0.0699999034f, -0.0599999018f, -0.0499999002f, -0.0499999002f, -0.0399998985f, -0.0299999006f, -0.0299999006f, -0.0199999008f,\r\n\t\t-0.00999992993f, -0.00999992993f, 5.96045986E-08f, 0.0100001004f, 0.0199999996f, 0.0199999996f, 0.0299999993f, 0.0299999993f,\r\n\t\t0.0399999991f, 0.0399999991f, 0.0500000007f, 0.0500000007f, 0.0599999987f, 0.0599999987f, 0.0700000003f, 0.0799999982f,\r\n\t\t0.0799999982f, 0.0799999982f, 0.0900000036f, 0.100000001f, 0.100000001f, 0.109999999f, 0.109999999f, 0.119999997f,\r\n\t\t0.119999997f, 0.119999997f, 0.129999995f, 0.129999995f, 0.129999995f, 0.129999995f, 0.129999995f, 0.129999995f,\r\n\t\t0.140000001f, 0.140000001f, 0.140000001f, 0.140000001f, 0.140000001f, 0.140000001f, 0.150000006f, 0.150000006f,\r\n\t\t0.159999996f, 0.159999996f, 0.159999996f, 0.159999996f, 0.170000002f, 0.170000002f, 0.170000002f, 0.170000002f,\r\n\t\t0.180000007f, 0.180000007f, 0.180000007f, 0.189999998f, 0.189999998f, 0.189999998f, 0.189999998f, 0.200000003f,\r\n\t\t0.200000003f, 0.200000003f, 0.209999993f, 0.209999993f, 0.209999993f, 0.219999999f, 0.219999999f, 0.219999999f,\r\n\t\t0.230000004f, 0.230000004f, 0.230000004f, 0.230000004f, 0.239999995f, 0.239999995f, 0.239999995f, 0.239999995f,\r\n\t\t0.245000005f, 0.25f, 0.25f, 0.25f, 0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003ETable \u0022hp_h\u0022 (100 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] HpHigh =\r\n\t{\r\n\t\t0.0100001004f, 0.0199999996f, 0.0299999993f, 0.0299999993f, 0.0399999991f, 0.0399999991f, 0.0399999991f, 0.0500000007f,\r\n\t\t0.0500000007f, 0.0599999987f, 0.0800011009f, 0.0800011009f, 0.0900013f, 0.0950014964f, 0.100001998f, 0.110002004f,\r\n\t\t0.110002004f, 0.110002004f, 0.120002002f, 0.130002007f, 0.130002007f, 0.133335993f, 0.136668995f, 0.140002996f,\r\n\t\t0.143335998f, 0.146669f, 0.150003001f, 0.160003006f, 0.170002997f, 0.170002997f, 0.180003002f, 0.180003002f,\r\n\t\t0.185003996f, 0.190004006f, 0.195004001f, 0.200003996f, 0.205004007f, 0.210004002f, 0.213338003f, 0.216671005f,\r\n\t\t0.220004007f, 0.220004007f, 0.230004996f, 0.230004996f, 0.240005001f, 0.250005007f, 0.255005002f, 0.260004997f,\r\n\t\t0.265004992f, 0.270004988f, 0.280000001f, 0.280000001f, 0.289999992f, 0.289999992f, 0.289999992f, 0.289999992f,\r\n\t\t0.289999992f, 0.300000012f, 0.300000012f, 0.300000012f, 0.300000012f, 0.310000002f, 0.310000002f, 0.310000002f,\r\n\t\t0.310000002f, 0.319999993f, 0.319999993f, 0.330000013f, 0.330000013f, 0.340000004f, 0.340000004f, 0.340000004f,\r\n\t\t0.344999999f, 0.349999994f, 0.349999994f, 0.349999994f, 0.349999994f, 0.349999994f, 0.349999994f, 0.349999994f,\r\n\t\t0.349999994f, 0.349999994f, 0.349999994f, 0.349999994f, 0.349999994f, 0.340000004f, 0.330000013f, 0.330000013f,\r\n\t\t0.319999993f, 0.319999993f, 0.319999993f, 0.310000002f, 0.300000012f, 0.300000012f, 0.289999992f, 0.289999992f,\r\n\t\t0.280000001f, 0.270000011f, 0.270000011f, 0.239999995f, 0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003EThe recorded 1024-sample creak click (all five grain tables of the patch are identical).\u003C/summary\u003E\r\n\tpublic static readonly float[] Grain =\r\n\t{\r\n\t\t0f, -0.00213623f, -0.00152587995f, 0.0124816997f, 0.0734253004f, 0.174011007f, 0.141967997f, -0.179473996f,\r\n\t\t-0.433562994f, -0.315613002f, -0.256897002f, -0.152404994f, 0.505280018f, 0.966369987f, 0.592926025f, 0.115417004f,\r\n\t\t-0.0703125f, -0.173767f, -0.136107996f, -0.119354002f, -0.483336985f, -0.915161014f, -0.724457026f, -0.354705989f,\r\n\t\t-0.202483997f, 0.0869446024f, 0.572356999f, 0.67077601f, 0.329558998f, 0.247649997f, 0.287932992f, 0.110748f,\r\n\t\t-0.131683007f, -0.0308532994f, 0.0738219991f, -0.0438842997f, -0.256774992f, -0.354279011f, -0.360320985f, -0.322571009f,\r\n\t\t-0.196349993f, -0.203186005f, -0.241364002f, -0.129210994f, 0.0806884989f, 0.122437f, 0.159332007f, 0.255066007f,\r\n\t\t0.300568014f, 0.226256996f, 0.204315007f, 0.213776007f, 0.223327994f, 0.161193997f, 0.0856017992f, -0.0170593001f,\r\n\t\t-0.120086998f, -0.194549993f, -0.242156997f, -0.240326002f, -0.148528993f, -0.0234069992f, 0.0227355994f, 0.0167542007f,\r\n\t\t-0.0263672005f, -0.0680236965f, -0.0906371996f, -0.0590820014f, -0.0261841007f, 0.00262451009f, 0.00512694987f, 0.0264282003f,\r\n\t\t0.0711975023f, 0.128174007f, 0.108214997f, 0.0685425028f, 0.0241088998f, 0.00454712007f, -0.0155945001f, 0.00772095006f,\r\n\t\t0.0476073995f, 0.0802002028f, 0.0505980998f, 0.0243835002f, 0.0102233998f, 0.0102233998f, -0.000518799003f, 0.0570373982f,\r\n\t\t0.143889993f, 0.207275003f, 0.230498999f, 0.246490002f, 0.212769002f, 0.146759003f, 0.0713500977f, 0.0246581994f,\r\n\t\t-0.0297241006f, -0.0795288011f, -0.118408002f, -0.158020005f, -0.229156002f, -0.269439995f, -0.289245993f, -0.287079006f,\r\n\t\t-0.263884991f, -0.216187f, -0.189910993f, -0.169738993f, -0.140045002f, -0.0876464993f, -0.0385742001f, 0.00558472006f,\r\n\t\t0.0476685017f, 0.114532001f, 0.165282995f, 0.200683996f, 0.220612004f, 0.215545997f, 0.171021f, 0.113982998f,\r\n\t\t0.0441588983f, -0.0230407994f, -0.0734862983f, -0.109039001f, -0.140961006f, -0.158996999f, -0.146088004f, -0.0937805027f,\r\n\t\t-0.0425719991f, -0.00851439964f, 0.0139464997f, 0.0251464993f, 0.0334778018f, 0.0499267988f, 0.0550841987f, 0.0546264984f,\r\n\t\t0.0507812016f, 0.0479735993f, 0.0474854f, 0.0388488993f, 0.0115662003f, -0.0320740007f, -0.096771203f, -0.163422003f,\r\n\t\t-0.200531006f, -0.1875f, -0.157897994f, -0.143981993f, -0.124573f, -0.0901184008f, -0.0531310998f, -0.0145568997f,\r\n\t\t0.034454301f, 0.0863037035f, 0.124268003f, 0.152252004f, 0.160492003f, 0.147125006f, 0.124389999f, 0.106140003f,\r\n\t\t0.0750121996f, 0.0281067006f, 0.0060119601f, 0.00555420015f, -0.0154724f, -0.0498657003f, -0.0576171987f, -0.0505980998f,\r\n\t\t-0.0848082975f, -0.161559999f, -0.214995995f, -0.210480005f, -0.166840002f, -0.152678996f, -0.168823004f, -0.157471001f,\r\n\t\t-0.111786f, -0.088043198f, -0.0920410007f, -0.0945435017f, -0.0832519978f, -0.0662230998f, -0.0408019982f, -0.0246887002f,\r\n\t\t-0.0195617992f, -0.0223082993f, -0.0129089002f, 0.00439452985f, 0.0316466987f, 0.0690917969f, 0.0916137993f, 0.0981139988f,\r\n\t\t0.0989990011f, 0.0882567987f, 0.0658264011f, 0.0303649995f, 0.000244141003f, -0.0201415997f, -0.0387878008f, -0.0551147014f,\r\n\t\t-0.0646973029f, -0.0586548001f, -0.0467833988f, -0.0453185998f, -0.0660706013f, -0.100403003f, -0.123901002f, -0.132721007f,\r\n\t\t-0.134064004f, -0.132080004f, -0.121276997f, -0.099822998f, -0.0693970025f, -0.0488892011f, -0.0457458012f, -0.0529174991f,\r\n\t\t-0.0476073995f, -0.0324706994f, -0.0234069992f, -0.0222168006f, -0.0253906008f, -0.0312194992f, -0.0302124005f, -0.0266724005f,\r\n\t\t-0.0207519997f, -0.0123290997f, 0.00277710008f, 0.0194701999f, 0.032531701f, 0.0420836993f, 0.0505065992f, 0.0476378985f,\r\n\t\t0.0401306003f, 0.0314636007f, 0.0231934004f, 0.0137938997f, 0.00173949997f, -0.00982666016f, -0.0221862998f, -0.0449524f,\r\n\t\t-0.0693664998f, -0.0868529975f, -0.102477998f, -0.126282007f, -0.148560002f, -0.161530003f, -0.161896005f, -0.160126001f,\r\n\t\t-0.159637004f, -0.152435005f, -0.132172003f, -0.108306997f, -0.093566902f, -0.085113503f, -0.0754394978f, -0.0781859979f,\r\n\t\t-0.0840758979f, -0.0819701999f, -0.0680236965f, -0.0498046987f, -0.0283812992f, -0.00750732003f, -0.000915526995f, -0.00228881999f,\r\n\t\t0.0100098001f, 0.0271301009f, 0.0413512997f, 0.050079301f, 0.0560607985f, 0.0562743992f, 0.0493469015f, 0.0352783017f,\r\n\t\t0.0258483998f, 0.0262755994f, 0.0313721001f, 0.0341491997f, 0.0350036994f, 0.0298156999f, 0.0141602f, -0.00573730003f,\r\n\t\t-0.0218810998f, -0.0419921987f, -0.0663451999f, -0.0894469991f, -0.101623997f, -0.106628001f, -0.112182997f, -0.116791002f,\r\n\t\t-0.108795002f, -0.0940247029f, -0.0754394978f, -0.0567017011f, -0.0496825986f, -0.0493774004f, -0.0369567983f, -0.0241698995f,\r\n\t\t-0.033142101f, -0.044982899f, -0.0183410998f, 0.00469970983f, -0.00839233026f, -0.0188292991f, -0.0202025995f, -0.0332030989f,\r\n\t\t-0.0504150018f, -0.0688782036f, -0.0965270996f, -0.127868995f, -0.147400007f, -0.122741997f, -0.0722045973f, -0.0245971996f,\r\n\t\t0.0143432999f, 0.0420532003f, 0.0784607008f, 0.0870971978f, 0.0719909966f, 0.0537109002f, 0.0408935994f, 0.0313416012f,\r\n\t\t0.0188599005f, 0.0026855499f, -0.0148925995f, -0.0263672005f, -0.0223693997f, -0.0287475996f, -0.0618285984f, -0.0931395963f,\r\n\t\t-0.114165999f, -0.125854f, -0.118712999f, -0.106201001f, -0.103394002f, -0.105469003f, -0.0964661017f, -0.0717163011f,\r\n\t\t-0.0531615987f, -0.0451049991f, -0.0330200009f, -0.0139159998f, -0.00366211007f, 0.000732421991f, 0.0090026902f, 0.0167235993f,\r\n\t\t0.0226440001f, 0.0293883998f, 0.0332336016f, 0.0308228005f, 0.0231934004f, 0.0147705004f, 0.00891113002f, 0.000244141003f,\r\n\t\t-0.00878905971f, -0.0132446f, -0.013855f, -0.0165100005f, -0.0173339993f, -0.0146179004f, -0.00869750977f, -0.00567627f,\r\n\t\t-0.000518799003f, -0.00262451009f, -0.00488281017f, -0.0102843996f, -0.0215149f, -0.0378113016f, -0.0534972996f, -0.0589293987f,\r\n\t\t-0.0525512993f, -0.0466613993f, -0.0438232012f, -0.0450745001f, -0.0479126014f, -0.0488586016f, -0.0433043987f, -0.0336304009f,\r\n\t\t-0.0202636998f, -0.0114441002f, -0.00588988978f, -0.00363158993f, -0.00869750977f, -0.0183410998f, -0.0211791992f, -0.0179137997f,\r\n\t\t-0.0169983003f, -0.0147399995f, -0.00799561013f, -0.00527954008f, -0.0105285998f, -0.0182799995f, -0.0196838006f, -0.0198363997f,\r\n\t\t-0.0268249996f, -0.0337219015f, -0.0306396f, -0.0267944001f, -0.0268859994f, -0.0266417991f, -0.0220031999f, -0.0189513993f,\r\n\t\t-0.0149536002f, -0.00418091007f, 0.00555420015f, 0.00915526971f, 0.0141602f, 0.0154114002f, 0.0111694001f, 0.0074768099f,\r\n\t\t0.00643920992f, 0.00512694987f, 0.00451660017f, -0.000640869024f, -0.00173949997f, 0.00140380999f, -0.000518799003f, -0.00396728981f,\r\n\t\t-0.00198364002f, 0.00128174003f, 0.00256348005f, 0.00411986979f, 0.00634765998f, 0.00582886022f, 0.00503539992f, 0.00244140998f,\r\n\t\t-0.000793456973f, -0.000305176014f, -6.10351999E-05f, -0.00454712007f, -0.00640869001f, -0.00515746977f, 6.10351999E-05f, 0.0169373006f,\r\n\t\t0.0332642011f, 0.0408019982f, 0.0422362983f, 0.0360413007f, 0.0238646995f, 0.0093078604f, 0.00143433001f, -0.0042419401f,\r\n\t\t-0.0179443005f, -0.0343628004f, -0.0410461016f, -0.0378722996f, -0.0363770016f, -0.0413817987f, -0.046905499f, -0.0507812016f,\r\n\t\t-0.0537109002f, -0.0542908013f, -0.0496216007f, -0.0441895016f, -0.0389403999f, -0.0325927995f, -0.0283812992f, -0.0279846005f,\r\n\t\t-0.0273132008f, -0.0175476f, -0.0078125f, -0.00411986979f, 0.0042419401f, 0.0144042997f, 0.0217285007f, 0.0285339002f,\r\n\t\t0.0368041992f, 0.0450439006f, 0.0511168987f, 0.0547485016f, 0.0544434004f, 0.0463256985f, 0.0317687988f, 0.0245971996f,\r\n\t\t0.0216979999f, 0.0142821996f, 0.00872803014f, 0.00759888021f, 0.00564575009f, -0.00100707996f, -0.00933837984f, -0.0191955995f,\r\n\t\t-0.0313110016f, -0.0382996015f, -0.0382080004f, -0.0350036994f, -0.0277100001f, -0.0161742996f, -0.00973511022f, -0.00866699032f,\r\n\t\t-0.00741577009f, -0.00848389044f, -0.00717162993f, -9.1552698E-05f, 0.0105895996f, 0.0208129995f, 0.0289916992f, 0.0363770016f,\r\n\t\t0.0452881008f, 0.0499878004f, 0.052612301f, 0.0548706017f, 0.0552368015f, 0.0559998006f, 0.0548096001f, 0.0482482985f,\r\n\t\t0.0411682017f, 0.0314331017f, 0.0205077995f, 0.0139464997f, 0.0125427004f, 0.0096130399f, 0.00381470006f, -0.00543212984f,\r\n\t\t-0.0161742996f, -0.0281371996f, -0.0367432013f, -0.0413817987f, -0.0430298001f, -0.0426636003f, -0.0423889011f, -0.0411987007f,\r\n\t\t-0.0356750004f, -0.0285339002f, -0.0264586993f, -0.0301818997f, -0.0346985012f, -0.0366820991f, -0.0343017988f, -0.0286560003f,\r\n\t\t-0.0190734994f, -0.00372314011f, 0.0104980003f, 0.0212097f, 0.0317382999f, 0.0433043987f, 0.0475464016f, 0.0419616997f,\r\n\t\t0.0323485993f, 0.0231934004f, 0.0215149f, 0.0276184008f, 0.0402831994f, 0.0527038984f, 0.059295699f, 0.0621642992f,\r\n\t\t0.0545349009f, 0.0427551009f, 0.0289612003f, 0.0150451995f, 0.00613402994f, 0.00405884022f, 0.00653075986f, 0.0093078604f,\r\n\t\t0.0105285998f, 0.0066223098f, 0.00137328997f, -0.000183105003f, 0.00506591983f, 0.0111694001f, 0.0110168001f, 0.00723267021f,\r\n\t\t0.00491333008f, 0.00488281017f, -0.000305176014f, -0.0117493002f, -0.0174866002f, -0.0161132999f, -0.0155333998f, -0.0153502999f,\r\n\t\t-0.0122069996f, -0.00622559013f, -0.00161743001f, -0.00439452985f, -0.0108337002f, -0.0128479004f, -0.00692748977f, -0.00103759998f,\r\n\t\t-0.00286865002f, -0.00643920992f, -0.00387573009f, 0.00399779994f, 0.00732422015f, 0.00692748977f, 0.00933837984f, 0.0144042997f,\r\n\t\t0.0177002009f, 0.0222472996f, 0.0293579008f, 0.0357055999f, 0.0376586989f, 0.0346679986f, 0.0286864992f, 0.0254516993f,\r\n\t\t0.0260314997f, 0.0237732008f, 0.0145873995f, 0.00381470006f, -0.00173949997f, -0.000488280988f, -0.000152588007f, -0.00289916992f,\r\n\t\t-0.0042419401f, -0.00152587995f, 0.00225830008f, 0.0066223098f, 0.0119019002f, 0.0171814002f, 0.0206604004f, 0.0228271f,\r\n\t\t0.0236205999f, 0.0225524995f, 0.0177002009f, 0.0124511998f, 0.00744628999f, 0.00692748977f, 0.00952147972f, 0.00869750977f,\r\n\t\t0.00524902018f, 0.00393676991f, 0.00704956008f, 0.0127258003f, 0.0169066992f, 0.0212097f, 0.0318908989f, 0.0434264988f,\r\n\t\t0.045410201f, 0.0414123982f, 0.0382689983f, 0.0343932994f, 0.0294799991f, 0.0255127009f, 0.0233459007f, 0.0221862998f,\r\n\t\t0.0184937008f, 0.0100707998f, -0.00253295992f, -0.0119324001f, -0.0123290997f, -0.0132141002f, -0.0170898009f, -0.0198059008f,\r\n\t\t-0.0193176009f, -0.0184630994f, -0.0211791992f, -0.0256958008f, -0.0290833004f, -0.0288391002f, -0.0258483998f, -0.0235290993f,\r\n\t\t-0.0220337007f, -0.0158080999f, -0.00817871001f, -0.00262451009f, 0.00228881999f, 0.00674438011f, 0.00875854027f, 0.00476073986f,\r\n\t\t-0.00152587995f, -0.00155639998f, 0.00451660017f, 0.0101012997f, 0.0115662003f, 0.0134583004f, 0.0165404994f, 0.0183105003f,\r\n\t\t0.0202636998f, 0.0237732008f, 0.0275878999f, 0.0319823995f, 0.0334472992f, 0.0326538011f, 0.0330200009f, 0.0349730998f,\r\n\t\t0.0348206013f, 0.0323181003f, 0.0262755994f, 0.0202942006f, 0.0168456994f, 0.0129699996f, 0.00762938987f, 0.0023193399f,\r\n\t\t-0.00366211007f, -0.00915526971f, -0.0132141002f, -0.0134888003f, -0.0117798001f, -0.0102843996f, -0.00817871001f, -0.00119018997f,\r\n\t\t0.00698853005f, 0.00997924991f, 0.0108337002f, 0.0162963998f, 0.0187682994f, 0.0144042997f, 0.0110168001f, 0.0096130399f,\r\n\t\t0.00756835984f, 0.00399779994f, 0.00170897995f, 0.000518799003f, -0.000274657999f, -0.00183105003f, -0.00546265021f, -0.00888061989f,\r\n\t\t-0.0135802999f, -0.0190430004f, -0.0223082993f, -0.0206604004f, -0.0138854999f, -0.00537109002f, -9.1552698E-05f, 0.00390625f,\r\n\t\t0.0114136003f, 0.0168762002f, 0.0155945001f, 0.0110473996f, 0.0108032003f, 0.0161438007f, 0.0187378004f, 0.0178833008f,\r\n\t\t0.0162659008f, 0.0113220001f, 0.00643920992f, 0.00463867001f, 0.00277710008f, -6.10351999E-05f, -0.00427246001f, -0.00814818963f,\r\n\t\t-0.0063781701f, 0.00094604498f, 0.00860595983f, 0.0111694001f, 0.0120543996f, 0.0139159998f, 0.0142211998f, 0.0145568997f,\r\n\t\t0.0153502999f, 0.0167542007f, 0.0159302f, 0.0115355998f, 0.00799561013f, 0.00643920992f, 0.00488281017f, 0.00405884022f,\r\n\t\t0.00131226005f, -0.00234985002f, 0.000854492013f, 0.00888061989f, 0.00909424014f, 0.00155639998f, -0.00588988978f, -0.00732422015f,\r\n\t\t-0.00378417992f, 0.00167847006f, 0.00860595983f, 0.0137328999f, 0.0189819001f, 0.0226745997f, 0.0209350996f, 0.0162048005f,\r\n\t\t0.0114136003f, 0.00643920992f, -0.00238036993f, -0.0110168001f, -0.0167846996f, -0.0198059008f, -0.0187378004f, -0.0131225996f,\r\n\t\t-0.0066223098f, -0.00131226005f, 0.00323486002f, 0.00677490002f, 0.00796508975f, 0.00833129976f, 0.0101317996f, 0.0101317996f,\r\n\t\t0.00808716007f, 0.00759888021f, 0.00622559013f, 0.00500488002f, 0.00445557013f, -0.000610352028f, -0.00799561013f, -0.0111389002f,\r\n\t\t-0.0096130399f, -0.00866699032f, -0.0078125f, -0.0042419401f, 0.00198364002f, 0.00738525018f, 0.0119933998f, 0.0163269006f,\r\n\t\t0.0183410998f, 0.0155640002f, 0.0114441002f, 0.0090026902f, 0.0053405799f, 0.00222777994f, 0.00152587995f, -0.000152588007f,\r\n\t\t-0.00689696986f, -0.0117798001f, -0.0112305004f, -0.00955200009f, -0.00891113002f, -0.00616454985f, 0.00149536005f, 0.00909424014f,\r\n\t\t0.0129394997f, 0.0159911998f, 0.0204163007f, 0.0253601f, 0.0271911994f, 0.0234375f, 0.0184326004f, 0.0151062002f,\r\n\t\t0.0115662003f, 0.00494384998f, 0.000518799003f, 0.00146484002f, 0.00317382999f, 0.00296020997f, 0.00369262998f, 0.00488281017f,\r\n\t\t0.00506591983f, 0.00396728981f, 0.00201415992f, -0.00067138701f, -0.00192260998f, -0.00195311999f, -0.00341796991f, -0.00692748977f,\r\n\t\t-0.00820923038f, -0.00521851005f, -0.00234985002f, -0.00094604498f, 0.00207519997f, 0.00445557013f, 0.00631714007f, 0.00958252046f,\r\n\t\t0.0122680999f, 0.013855f, 0.0122069996f, 0.00704956008f, 0.00198364002f, 0.000610352028f, 0.000762938987f, -0.000793456973f,\r\n\t\t-0.00289916992f, -0.00640869001f, -0.00857544038f, -0.00692748977f, -0.00411986979f, -0.00134276995f, 0.00201415992f, 0.00714111002f,\r\n\t\t0.0135193001f, 0.0187682994f, 0.0198975001f, 0.0187988002f, 0.0165404994f, 0.0126342997f, 0.00875854027f, 0.00421142997f,\r\n\t\t-0.00167847006f, -0.00692748977f, -0.00894165039f, -0.00927734002f, -0.0107421996f, -0.0124206999f, -0.0122985998f, -0.0107116997f,\r\n\t\t-0.00680541992f, -0.00262451009f, -0.00100707996f, 0.00115966995f, 0.00515746977f, 0.00717162993f, 0.00531005999f, 0.00234985002f,\r\n\t\t0.00192260998f, 0.00100707996f, -0.000701904006f, -0.00228881999f, -0.00192260998f, 0.000457763992f, 0.00317382999f, 0.00469970983f,\r\n\t\t0.00549315987f, 0.00573730003f, 0.00448607979f, 0.00228881999f, 0.0026855499f, 0.00677490002f, 0.0109863002f, 0.0126037998f,\r\n\t\t0.0135498f, 0.0138245001f, 0.0118712997f, 0.0084228497f, 0.00708007999f, 0.0101012997f, 0.0145568997f, 0.0155640002f,\r\n\t\t0.0112305004f, 0.00524902018f, 0.00222777994f, 0.00112915004f, -0.00238036993f, -0.00796508975f, -0.0120238997f, -0.0114746001f,\r\n\t\t-0.00735474005f, -0.00277710008f, -0.000579833984f, -9.1552698E-05f, 0.000305176014f, -0.000152588007f, -0.00234985002f, -0.00384520995f,\r\n\t\t-0.00421142997f, -0.0035705599f, -0.00238036993f, -0.00195311999f, -0.00146484002f, -0.000579833984f, -3.05176E-05f, 0.000854492013f,\r\n\t\t0.00323486002f, 0.00567627f, 0.00848389044f, 0.0120238997f, 0.0127868997f, 0.0105590997f, 0.00878905971f, 0.00860595983f,\r\n\t\t0.00823974982f, 0.00711059989f, 0.00640869001f, 0.00579833984f, 0.00402831985f, 0.00259398995f, 0.00134276995f, -0.000640869024f,\r\n\t\t-0.00347899995f, -0.00668335008f, -0.00665283017f, -0.00283813011f, 0.00152587995f, 0.00491333008f, 0.00643920992f, 0.00552367978f,\r\n\t\t0.00323486002f, 0.00213623f, 0.00109863002f, -0.00201415992f, -0.00503539992f, -0.00491333008f, -0.00170897995f, 0.00094604498f,\r\n\t\t0.00186157005f, 0.00228881999f, 0.00457763998f, 0.00720214983f, 0.00720214983f, 0.00540160993f, 0.00418091007f, 0.00314331008f,\r\n\t\t0.00146484002f, -0.000915526995f, -0.00225830008f, -0.00161743001f, -0.000915526995f, -0.000152588007f, 0.00186157005f, 0.00350952009f,\r\n\t\t0.00396728981f, 0.00378417992f, 0.00350952009f, 0.0029907201f, 0.00167847006f, 0.000152588007f, -0.000823975017f, -0.000976561976f,\r\n\t\t0.000366210996f, 0.00186157005f, 0.00167847006f, 0.00115966995f, 0.00137328997f, 0.00100707996f, -0.000183105003f, -0.000915526995f,\r\n\t\t-0.00119018997f, -0.00180054002f, -0.0026855499f, -0.00317382999f, -0.0033569301f, -0.00347899995f, -0.00323486002f, -0.00280761998f,\r\n\t\t-0.00219727005f, -0.00143433001f, -0.000823975017f, 0f, 0.00109863002f, 0.00170897995f, 0.00183105003f, 0.00173949997f,\r\n\t\t0.00164795003f, 0.00186157005f, 0.00183105003f, 0.00155639998f, 0.00137328997f, 0.00152587995f, 0.00177002f, 0.00177002f,\r\n\t\t0.00137328997f, 0.000885009998f, 0.000457763992f, 0.000213623003f, 9.1552698E-05f, 0f, -3.05176E-05f, -3.05176E-05f,\r\n\t\t0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003ETable \u00221892-cos\u0022 (1024 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] PanCos =\r\n\t{\r\n\t\t-1.0f, -0.999980986f, -0.999925017f, -0.999831021f, -0.999698997f, -0.999529004f, -0.999321997f, -0.999077976f,\r\n\t\t-0.998794973f, -0.998475015f, -0.998117983f, -0.997722983f, -0.997290015f, -0.996819973f, -0.996312022f, -0.995766997f,\r\n\t\t-0.995185018f, -0.994563997f, -0.993906975f, -0.993211985f, -0.992479026f, -0.991710007f, -0.990902007f, -0.990058005f,\r\n\t\t-0.989175975f, -0.988256991f, -0.987300992f, -0.986307979f, -0.985276997f, -0.984210014f, -0.983105004f, -0.981963992f,\r\n\t\t-0.980785012f, -0.979569972f, -0.978317022f, -0.977028012f, -0.975701988f, -0.974339008f, -0.972940028f, -0.971503973f,\r\n\t\t-0.970031023f, -0.968522012f, -0.966975987f, -0.96539402f, -0.963775992f, -0.96212101f, -0.960430026f, -0.958702981f,\r\n\t\t-0.956939995f, -0.955141008f, -0.953306019f, -0.95143503f, -0.949527979f, -0.947584987f, -0.945607007f, -0.943593025f,\r\n\t\t-0.941543996f, -0.939459026f, -0.937339008f, -0.935182989f, -0.932991982f, -0.930767f, -0.928506017f, -0.926209986f,\r\n\t\t-0.923879027f, -0.921513975f, -0.91911298f, -0.916679025f, -0.914209008f, -0.911705971f, -0.909168005f, -0.906594992f,\r\n\t\t-0.903989017f, -0.901347995f, -0.898674011f, -0.895965993f, -0.893224001f, -0.890447974f, -0.887638986f, -0.884796977f,\r\n\t\t-0.881920993f, -0.879011989f, -0.876070023f, -0.873094976f, -0.870087028f, -0.867045999f, -0.863972008f, -0.86086601f,\r\n\t\t-0.857728004f, -0.854557991f, -0.851355016f, -0.848119974f, -0.844852984f, -0.841554999f, -0.838223994f, -0.834861994f,\r\n\t\t-0.831468999f, -0.828045011f, -0.824589014f, -0.821102023f, -0.817583978f, -0.814036012f, -0.810456991f, -0.806846976f,\r\n\t\t-0.80320698f, -0.799537003f, -0.795835972f, -0.792105973f, -0.788345993f, -0.784555972f, -0.780736983f, -0.776888013f,\r\n\t\t-0.773010015f, -0.769102991f, -0.765166998f, -0.761201978f, -0.75720799f, -0.753185987f, -0.749135971f, -0.745056987f,\r\n\t\t-0.740951002f, -0.736815989f, -0.732653975f, -0.728464007f, -0.724246979f, -0.720001996f, -0.715730011f, -0.71143198f,\r\n\t\t-0.707105994f, -0.702754021f, -0.698376f, -0.693970978f, -0.689540029f, -0.685082972f, -0.680601001f, -0.676092029f,\r\n\t\t-0.671558022f, -0.666998982f, -0.662415028f, -0.657805979f, -0.653172016f, -0.648513973f, -0.643831015f, -0.639123976f,\r\n\t\t-0.634392977f, -0.629638016f, -0.624858975f, -0.620056987f, -0.615230978f, -0.61038202f, -0.60551101f, -0.600615978f,\r\n\t\t-0.595699012f, -0.590758979f, -0.585797012f, -0.580814004f, -0.575807989f, -0.570779979f, -0.565730989f, -0.560661018f,\r\n\t\t-0.555570006f, -0.550458014f, -0.545324981f, -0.540171027f, -0.534996986f, -0.529802978f, -0.524589002f, -0.519356012f,\r\n\t\t-0.514101982f, -0.508830011f, -0.503538013f, -0.498227f, -0.492897987f, -0.48754999f, -0.482183009f, -0.476799011f,\r\n\t\t-0.471395999f, -0.465976f, -0.460538f, -0.455083013f, -0.449611008f, -0.444121987f, -0.438616008f, -0.433093011f,\r\n\t\t-0.427554995f, -0.421999991f, -0.416429013f, -0.410843015f, -0.405241013f, -0.39962399f, -0.393992007f, -0.388345003f,\r\n\t\t-0.382683009f, -0.377007008f, -0.371316999f, -0.365613014f, -0.359894991f, -0.354162991f, -0.348417997f, -0.34266001f,\r\n\t\t-0.336890012f, -0.331106007f, -0.325309992f, -0.319501996f, -0.313681006f, -0.30784899f, -0.302006006f, -0.296151012f,\r\n\t\t-0.290284008f, -0.28440699f, -0.278519005f, -0.272621006f, -0.266712993f, -0.260794014f, -0.254864991f, -0.248926997f,\r\n\t\t-0.242980003f, -0.237022996f, -0.231058002f, -0.225084007f, -0.219100997f, -0.21311f, -0.207111001f, -0.201104f,\r\n\t\t-0.195089996f, -0.189068004f, -0.183039993f, -0.177003995f, -0.170962006f, -0.164912999f, -0.158858001f, -0.152796999f,\r\n\t\t-0.146730006f, -0.140658006f, -0.134581f, -0.128498003f, -0.122410998f, -0.116318002f, -0.110221997f, -0.104121998f,\r\n\t\t-0.0980170965f, -0.0919089019f, -0.0857971981f, -0.0796824023f, -0.0735644996f, -0.0674438998f, -0.0613206998f, -0.0551952012f,\r\n\t\t-0.0490676016f, -0.0429382995f, -0.0368072018f, -0.0306748003f, -0.0245411992f, -0.0184067003f, -0.0122715998f, -0.00613590004f,\r\n\t\t0f, 0.00613590004f, 0.0122715998f, 0.0184067003f, 0.0245411992f, 0.0306748003f, 0.0368072018f, 0.0429382995f,\r\n\t\t0.0490676016f, 0.0551952012f, 0.0613206998f, 0.0674438998f, 0.0735644996f, 0.0796824023f, 0.0857971981f, 0.0919089019f,\r\n\t\t0.0980170965f, 0.104121998f, 0.110221997f, 0.116318002f, 0.122410998f, 0.128498003f, 0.134581f, 0.140658006f,\r\n\t\t0.146730006f, 0.152796999f, 0.158858001f, 0.164912999f, 0.170962006f, 0.177003995f, 0.183039993f, 0.189068004f,\r\n\t\t0.195089996f, 0.201104f, 0.207111001f, 0.21311f, 0.219100997f, 0.225084007f, 0.231058002f, 0.237022996f,\r\n\t\t0.242980003f, 0.248926997f, 0.254864991f, 0.260794014f, 0.266712993f, 0.272621006f, 0.278519005f, 0.28440699f,\r\n\t\t0.290284008f, 0.296151012f, 0.302006006f, 0.30784899f, 0.313681006f, 0.319501996f, 0.325309992f, 0.331106007f,\r\n\t\t0.336890012f, 0.34266001f, 0.348417997f, 0.354162991f, 0.359894991f, 0.365613014f, 0.371316999f, 0.377007008f,\r\n\t\t0.382683009f, 0.388345003f, 0.393992007f, 0.39962399f, 0.405241013f, 0.410843015f, 0.416429013f, 0.421999991f,\r\n\t\t0.427554995f, 0.433093011f, 0.438616008f, 0.444121987f, 0.449611008f, 0.455083013f, 0.460538f, 0.465976f,\r\n\t\t0.471395999f, 0.476799011f, 0.482183009f, 0.48754999f, 0.492897987f, 0.498227f, 0.503538013f, 0.508830011f,\r\n\t\t0.514101982f, 0.519356012f, 0.524589002f, 0.529802978f, 0.534996986f, 0.540171027f, 0.545324981f, 0.550458014f,\r\n\t\t0.555570006f, 0.560661018f, 0.565730989f, 0.570779979f, 0.575807989f, 0.580814004f, 0.585797012f, 0.590758979f,\r\n\t\t0.595699012f, 0.600615978f, 0.60551101f, 0.61038202f, 0.615230978f, 0.620056987f, 0.624858975f, 0.629638016f,\r\n\t\t0.634392977f, 0.639123976f, 0.643831015f, 0.648513973f, 0.653172016f, 0.657805979f, 0.662415028f, 0.666999996f,\r\n\t\t0.671558976f, 0.676092029f, 0.680601001f, 0.685082972f, 0.689540029f, 0.693970978f, 0.698376f, 0.702754021f,\r\n\t\t0.707105994f, 0.71143198f, 0.715730011f, 0.720001996f, 0.724246979f, 0.728464007f, 0.732653975f, 0.736815989f,\r\n\t\t0.740951002f, 0.745056987f, 0.749135971f, 0.753185987f, 0.75720799f, 0.761201978f, 0.765166998f, 0.769102991f,\r\n\t\t0.773010015f, 0.776888013f, 0.780736983f, 0.784555972f, 0.788345993f, 0.792105973f, 0.795835972f, 0.799537003f,\r\n\t\t0.80320698f, 0.806846976f, 0.810456991f, 0.814036012f, 0.817583978f, 0.821102023f, 0.824589014f, 0.828045011f,\r\n\t\t0.831468999f, 0.834861994f, 0.838223994f, 0.841554999f, 0.844852984f, 0.848119974f, 0.851355016f, 0.854557991f,\r\n\t\t0.857728004f, 0.86086601f, 0.863972008f, 0.867045999f, 0.870087028f, 0.873094976f, 0.876070023f, 0.879011989f,\r\n\t\t0.881920993f, 0.884796977f, 0.887638986f, 0.890447974f, 0.893224001f, 0.895965993f, 0.898674011f, 0.901347995f,\r\n\t\t0.903989017f, 0.906594992f, 0.909168005f, 0.911705971f, 0.914209008f, 0.916679025f, 0.91911298f, 0.921513975f,\r\n\t\t0.923879027f, 0.926209986f, 0.928506017f, 0.930767f, 0.932991982f, 0.935182989f, 0.937339008f, 0.939459026f,\r\n\t\t0.941543996f, 0.943593025f, 0.945607007f, 0.947584987f, 0.949527979f, 0.95143503f, 0.953306019f, 0.955141008f,\r\n\t\t0.956939995f, 0.958702981f, 0.960430026f, 0.96212101f, 0.963775992f, 0.96539402f, 0.966975987f, 0.968522012f,\r\n\t\t0.970031023f, 0.971503973f, 0.972940028f, 0.974339008f, 0.975701988f, 0.977028012f, 0.978317022f, 0.979569972f,\r\n\t\t0.980785012f, 0.981963992f, 0.983105004f, 0.984210014f, 0.985276997f, 0.986307979f, 0.987300992f, 0.988256991f,\r\n\t\t0.989175975f, 0.990058005f, 0.990902007f, 0.991710007f, 0.992479026f, 0.993211985f, 0.993906975f, 0.994563997f,\r\n\t\t0.995185018f, 0.995766997f, 0.996312022f, 0.996819973f, 0.997290015f, 0.997722983f, 0.998117983f, 0.998475015f,\r\n\t\t0.998794973f, 0.999077976f, 0.999321997f, 0.999529004f, 0.999698997f, 0.999831021f, 0.999925017f, 0.999980986f,\r\n\t\t1.0f, 0.999980986f, 0.999925017f, 0.999831021f, 0.999698997f, 0.999529004f, 0.999321997f, 0.999077976f,\r\n\t\t0.998795986f, 0.998476028f, 0.998117983f, 0.997722983f, 0.997291028f, 0.996819973f, 0.996312976f, 0.995768011f,\r\n\t\t0.995185018f, 0.99456501f, 0.993906975f, 0.993211985f, 0.99247998f, 0.991710007f, 0.99090302f, 0.990058005f,\r\n\t\t0.989176989f, 0.988258004f, 0.987302005f, 0.986307979f, 0.98527801f, 0.984210014f, 0.983106017f, 0.981963992f,\r\n\t\t0.980786026f, 0.979569972f, 0.978317976f, 0.977028012f, 0.975701988f, 0.974340022f, 0.972940028f, 0.971503973f,\r\n\t\t0.970031977f, 0.968522012f, 0.966977f, 0.965394974f, 0.963775992f, 0.962122023f, 0.96043098f, 0.958703995f,\r\n\t\t0.956941009f, 0.955142021f, 0.953306019f, 0.951435983f, 0.949528992f, 0.947586f, 0.94560802f, 0.943593979f,\r\n\t\t0.94154501f, 0.93945998f, 0.937340021f, 0.935184002f, 0.932992995f, 0.930768013f, 0.92850697f, 0.926210999f,\r\n\t\t0.923879981f, 0.921514988f, 0.919113994f, 0.916679978f, 0.914210021f, 0.911706984f, 0.909169018f, 0.906596005f,\r\n\t\t0.903989971f, 0.901350021f, 0.898675025f, 0.895967007f, 0.893225014f, 0.890448987f, 0.887639999f, 0.88479799f,\r\n\t\t0.881922007f, 0.879013002f, 0.876070976f, 0.873095989f, 0.870087981f, 0.867047012f, 0.863973975f, 0.860867977f,\r\n\t\t0.857729018f, 0.854559004f, 0.85135603f, 0.848120987f, 0.844855011f, 0.841556013f, 0.83822602f, 0.83486402f,\r\n\t\t0.831471026f, 0.828046024f, 0.824590027f, 0.821102977f, 0.817586005f, 0.814037025f, 0.810458004f, 0.806849003f,\r\n\t\t0.803209007f, 0.799538016f, 0.795837998f, 0.792107999f, 0.788348019f, 0.784557998f, 0.780737996f, 0.77688998f,\r\n\t\t0.773011982f, 0.769105017f, 0.765168011f, 0.761204004f, 0.757210016f, 0.753188014f, 0.749137998f, 0.745059013f,\r\n\t\t0.740952015f, 0.736818016f, 0.732654989f, 0.728465974f, 0.724247992f, 0.720004022f, 0.715731978f, 0.711434007f,\r\n\t\t0.707108021f, 0.702755988f, 0.698378026f, 0.693973005f, 0.689541996f, 0.685084999f, 0.680602014f, 0.676093996f,\r\n\t\t0.671559989f, 0.667001009f, 0.662416995f, 0.657808006f, 0.653173983f, 0.648515999f, 0.643832982f, 0.639126003f,\r\n\t\t0.634395003f, 0.629639983f, 0.624861002f, 0.620059013f, 0.615233004f, 0.610383987f, 0.605512977f, 0.600618005f,\r\n\t\t0.595700979f, 0.590761006f, 0.585798979f, 0.580815017f, 0.575810015f, 0.570782006f, 0.565733016f, 0.560662985f,\r\n\t\t0.555571973f, 0.550459981f, 0.545327008f, 0.540172994f, 0.534999013f, 0.529805005f, 0.524591982f, 0.519357979f,\r\n\t\t0.514105022f, 0.508831978f, 0.503539979f, 0.49823001f, 0.492900014f, 0.487551987f, 0.48218599f, 0.476801008f,\r\n\t\t0.471399009f, 0.465977997f, 0.460539997f, 0.455085009f, 0.449613005f, 0.444124013f, 0.438618004f, 0.433095992f,\r\n\t\t0.427556992f, 0.422001988f, 0.416431993f, 0.410845011f, 0.405243009f, 0.399625987f, 0.393994004f, 0.388347f,\r\n\t\t0.382685006f, 0.377009004f, 0.371318996f, 0.36561501f, 0.359896988f, 0.354166001f, 0.348421007f, 0.34266299f,\r\n\t\t0.336892009f, 0.331108004f, 0.325311989f, 0.319503993f, 0.313683987f, 0.307852f, 0.302008003f, 0.296153009f,\r\n\t\t0.290286988f, 0.28441f, 0.278522015f, 0.272623986f, 0.26671499f, 0.26079601f, 0.254868001f, 0.248930007f,\r\n\t\t0.242982f, 0.237026006f, 0.231059998f, 0.225086004f, 0.219102994f, 0.213111997f, 0.207113996f, 0.201106995f,\r\n\t\t0.195091993f, 0.189071f, 0.183042005f, 0.177007005f, 0.170964003f, 0.164915994f, 0.158860996f, 0.152799994f,\r\n\t\t0.146733001f, 0.140661001f, 0.134582996f, 0.128500998f, 0.122413002f, 0.116320997f, 0.110224999f, 0.104124002f,\r\n\t\t0.0980195031f, 0.091911301f, 0.0857995972f, 0.0796846971f, 0.0735668018f, 0.067446202f, 0.0613234006f, 0.0551978983f,\r\n\t\t0.0490702987f, 0.0429408997f, 0.0368098989f, 0.0306774005f, 0.0245437995f, 0.0184093006f, 0.0122741004f, 0.00613844022f,\r\n\t\t2.5351801E-06f, -0.0061333701f, -0.0122689996f, -0.0184042007f, -0.0245388001f, -0.0306723993f, -0.036804799f, -0.0429357998f,\r\n\t\t-0.0490652993f, -0.055192899f, -0.0613184012f, -0.0674410984f, -0.0735618025f, -0.0796796978f, -0.0857945979f, -0.0919061974f,\r\n\t\t-0.0980143994f, -0.104119003f, -0.11022f, -0.116315998f, -0.122408003f, -0.128494993f, -0.134578004f, -0.140655994f,\r\n\t\t-0.146727994f, -0.152795002f, -0.158856004f, -0.164911002f, -0.170958996f, -0.177001998f, -0.183036998f, -0.189065993f,\r\n\t\t-0.195087001f, -0.201102003f, -0.207109004f, -0.213108003f, -0.219098002f, -0.225080997f, -0.231055006f, -0.237020999f,\r\n\t\t-0.242976993f, -0.248925f, -0.254862994f, -0.260791004f, -0.266710013f, -0.272619009f, -0.278517008f, -0.284404993f,\r\n\t\t-0.290282011f, -0.296148002f, -0.302002996f, -0.307846993f, -0.31367901f, -0.319499999f, -0.325307012f, -0.331102997f,\r\n\t\t-0.336887002f, -0.342658013f, -0.348416001f, -0.354160994f, -0.359892011f, -0.365610003f, -0.371315002f, -0.377005011f,\r\n\t\t-0.382681012f, -0.388341993f, -0.393988997f, -0.399621993f, -0.405238986f, -0.410840988f, -0.416426986f, -0.421997994f,\r\n\t\t-0.427552998f, -0.433091015f, -0.438614011f, -0.444119006f, -0.449609011f, -0.455080986f, -0.460536003f, -0.465974003f,\r\n\t\t-0.471394002f, -0.476797014f, -0.482181013f, -0.487547994f, -0.492895991f, -0.498225003f, -0.503535986f, -0.508827984f,\r\n\t\t-0.514100015f, -0.519353986f, -0.524586976f, -0.529801011f, -0.534995019f, -0.540169001f, -0.545323014f, -0.550455987f,\r\n\t\t-0.55556798f, -0.560658991f, -0.565729022f, -0.570778012f, -0.575806022f, -0.580811024f, -0.585794985f, -0.590757012f,\r\n\t\t-0.595696986f, -0.600614011f, -0.605508983f, -0.610379994f, -0.615229011f, -0.62005502f, -0.624857008f, -0.62963599f,\r\n\t\t-0.63439101f, -0.639122009f, -0.643828988f, -0.648512006f, -0.653171003f, -0.657805026f, -0.662413001f, -0.666997015f,\r\n\t\t-0.671557009f, -0.676090002f, -0.680598974f, -0.685081005f, -0.689538002f, -0.693969011f, -0.698373973f, -0.702751994f,\r\n\t\t-0.707104981f, -0.711430013f, -0.715728998f, -0.720000029f, -0.724245012f, -0.728461981f, -0.732652009f, -0.736814022f,\r\n\t\t-0.740948975f, -0.745055974f, -0.749134004f, -0.753184021f, -0.757206976f, -0.761200011f, -0.765164971f, -0.769101024f,\r\n\t\t-0.773007989f, -0.776885986f, -0.780735016f, -0.784555018f, -0.788344026f, -0.792105019f, -0.795835018f, -0.799534976f,\r\n\t\t-0.803206027f, -0.806846023f, -0.810455024f, -0.814033985f, -0.817583025f, -0.82110101f, -0.824588001f, -0.828042984f,\r\n\t\t-0.831467986f, -0.834860981f, -0.83822298f, -0.841552973f, -0.844851971f, -0.848118007f, -0.85135299f, -0.854556024f,\r\n\t\t-0.857726991f, -0.860864997f, -0.863970995f, -0.867044985f, -0.870085001f, -0.873093009f, -0.876067996f, -0.879010975f,\r\n\t\t-0.88191998f, -0.884796023f, -0.887637973f, -0.890447021f, -0.893222988f, -0.89596498f, -0.898672998f, -0.901346982f,\r\n\t\t-0.903988004f, -0.906593978f, -0.909166992f, -0.911705017f, -0.914207995f, -0.916678011f, -0.919112027f, -0.921513021f,\r\n\t\t-0.923878014f, -0.926208973f, -0.928505003f, -0.930765986f, -0.932991982f, -0.935181975f, -0.937337995f, -0.939458013f,\r\n\t\t-0.941542983f, -0.943592012f, -0.945605993f, -0.947583973f, -0.949527025f, -0.951434016f, -0.953305006f, -0.955139995f,\r\n\t\t-0.956938982f, -0.958702028f, -0.960429013f, -0.962119997f, -0.963774979f, -0.965393007f, -0.966975987f, -0.968520999f,\r\n\t\t-0.97003001f, -0.971503019f, -0.972939014f, -0.974339008f, -0.975700974f, -0.977026999f, -0.978317022f, -0.979569018f,\r\n\t\t-0.980785012f, -0.981962979f, -0.983105004f, -0.984209001f, -0.985276997f, -0.986307025f, -0.987300992f, -0.988256991f,\r\n\t\t-0.989175975f, -0.990058005f, -0.990902007f, -0.991708994f, -0.992479026f, -0.993211985f, -0.993906975f, -0.994563997f,\r\n\t\t-0.995184004f, -0.995766997f, -0.996312022f, -0.996819973f, -0.997290015f, -0.997722983f, -0.998117983f, -0.998475015f,\r\n\t\t-0.998794973f, -0.999077976f, -0.999321997f, -0.999529004f, -0.999698997f, -0.999830008f, -0.999925017f, -0.999980986f,\r\n\t\t0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003ETable \u00221986-env\u0022 (512 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] GloopEnv =\r\n\t{\r\n\t\t0f, 0.125f, 0.176777005f, 0.216506004f, 0.25f, 0.279509008f, 0.306185991f, 0.330718994f,\r\n\t\t0.353552997f, 0.375f, 0.39528501f, 0.414577991f, 0.433012992f, 0.450693995f, 0.467707008f, 0.484122992f,\r\n\t\t0.5f, 0.515388012f, 0.530330002f, 0.544861972f, 0.559017003f, 0.572821975f, 0.586301982f, 0.59947902f,\r\n\t\t0.612371981f, 0.625f, 0.637377024f, 0.649519026f, 0.661437988f, 0.673146009f, 0.684652984f, 0.695971012f,\r\n\t\t0.707107008f, 0.718069971f, 0.728869021f, 0.73951f, 0.75f, 0.760344982f, 0.77055198f, 0.780624986f,\r\n\t\t0.790569007f, 0.800391018f, 0.810092986f, 0.819679976f, 0.829155982f, 0.838524997f, 0.847791016f, 0.856957018f,\r\n\t\t0.866024971f, 0.875f, 0.883882999f, 0.892678976f, 0.90138799f, 0.910013974f, 0.918559015f, 0.92702502f,\r\n\t\t0.935414016f, 0.943728983f, 0.951972008f, 0.96014303f, 0.968245983f, 0.976280987f, 0.984251022f, 0.992156982f,\r\n\t\t1.0f, 0.995531023f, 0.991070986f, 0.986621976f, 0.98218298f, 0.977753997f, 0.973334014f, 0.968924999f,\r\n\t\t0.964525998f, 0.96013701f, 0.955757976f, 0.951389015f, 0.947028995f, 0.942680001f, 0.938341022f, 0.934011996f,\r\n\t\t0.929692984f, 0.925383985f, 0.921085f, 0.916795015f, 0.912515998f, 0.908246994f, 0.903988004f, 0.899739027f,\r\n\t\t0.895500004f, 0.891270995f, 0.887052f, 0.882843018f, 0.87864399f, 0.874454975f, 0.870275974f, 0.866106987f,\r\n\t\t0.861948013f, 0.857798994f, 0.853659987f, 0.849530995f, 0.845412016f, 0.841302991f, 0.837204993f, 0.833115995f,\r\n\t\t0.829037011f, 0.82496798f, 0.820909023f, 0.81686002f, 0.812820971f, 0.808791995f, 0.804773986f, 0.800764978f,\r\n\t\t0.796765983f, 0.792777002f, 0.788797975f, 0.784829021f, 0.780870974f, 0.776921988f, 0.772983015f, 0.769053996f,\r\n\t\t0.765136003f, 0.761227012f, 0.757327974f, 0.753440022f, 0.749561012f, 0.745692015f, 0.741832972f, 0.737985015f,\r\n\t\t0.734145999f, 0.730316997f, 0.726499021f, 0.722689986f, 0.718891978f, 0.715102971f, 0.711323977f, 0.707556009f,\r\n\t\t0.703796983f, 0.700048983f, 0.696309984f, 0.692580998f, 0.688862979f, 0.685154021f, 0.681456029f, 0.677766979f,\r\n\t\t0.674089015f, 0.670419991f, 0.666761994f, 0.663112998f, 0.659475029f, 0.655846f, 0.652227998f, 0.648618996f,\r\n\t\t0.645021021f, 0.641433001f, 0.63785398f, 0.634285986f, 0.630726993f, 0.627179027f, 0.623641014f, 0.620112002f,\r\n\t\t0.616594017f, 0.613084972f, 0.609587014f, 0.60609901f, 0.602621019f, 0.599152029f, 0.595694005f, 0.592245996f,\r\n\t\t0.588806987f, 0.585379004f, 0.581960976f, 0.578553021f, 0.575154006f, 0.571766019f, 0.568387985f, 0.565020025f,\r\n\t\t0.561661005f, 0.558313012f, 0.554974973f, 0.551647007f, 0.548328996f, 0.545019984f, 0.541722f, 0.538434029f,\r\n\t\t0.535156012f, 0.531888008f, 0.528630018f, 0.525381982f, 0.52214402f, 0.518916011f, 0.515697002f, 0.512489021f,\r\n\t\t0.509290993f, 0.506102979f, 0.502924979f, 0.499756992f, 0.496598989f, 0.493450999f, 0.490312994f, 0.487185001f,\r\n\t\t0.484066993f, 0.480958998f, 0.477860987f, 0.47477299f, 0.471695006f, 0.468627989f, 0.465570003f, 0.462522f,\r\n\t\t0.459484011f, 0.456456006f, 0.453438014f, 0.450430006f, 0.447432011f, 0.444444001f, 0.441466987f, 0.438499004f,\r\n\t\t0.435541004f, 0.432592988f, 0.429654986f, 0.42672801f, 0.423810005f, 0.420902014f, 0.418004006f, 0.415116012f,\r\n\t\t0.412238985f, 0.409370989f, 0.406513005f, 0.40366599f, 0.400828004f, 0.398000002f, 0.395182014f, 0.392374992f,\r\n\t\t0.389577001f, 0.386788994f, 0.384012014f, 0.381244004f, 0.378486007f, 0.375739008f, 0.373001009f, 0.370274007f,\r\n\t\t0.367556006f, 0.364847988f, 0.362150997f, 0.359463006f, 0.356786013f, 0.35411799f, 0.351460993f, 0.348812997f,\r\n\t\t0.346175998f, 0.343548f, 0.340930998f, 0.338322997f, 0.335725993f, 0.333137989f, 0.330561012f, 0.327993006f,\r\n\t\t0.325435996f, 0.322887987f, 0.320351005f, 0.317822993f, 0.315306008f, 0.312799007f, 0.310301006f, 0.307814002f,\r\n\t\t0.305337012f, 0.302868992f, 0.300411999f, 0.29796499f, 0.295527011f, 0.293099999f, 0.290683001f, 0.288275003f,\r\n\t\t0.285878003f, 0.283490986f, 0.281112999f, 0.278746009f, 0.276389003f, 0.27404201f, 0.271703988f, 0.269376993f,\r\n\t\t0.267060012f, 0.264753014f, 0.262456f, 0.260167986f, 0.257890999f, 0.255623996f, 0.253367007f, 0.251120001f,\r\n\t\t0.248882994f, 0.246656001f, 0.244437993f, 0.242230996f, 0.240033999f, 0.237847f, 0.23567f, 0.233502999f,\r\n\t\t0.231345996f, 0.229199007f, 0.227062002f, 0.224934995f, 0.222818002f, 0.220710993f, 0.218613997f, 0.216527f,\r\n\t\t0.214450002f, 0.212383002f, 0.210326001f, 0.208278999f, 0.206241995f, 0.204215005f, 0.202197999f, 0.200191006f,\r\n\t\t0.198193997f, 0.196207002f, 0.194231004f, 0.192264006f, 0.190307006f, 0.188360006f, 0.186423004f, 0.184496f,\r\n\t\t0.182578996f, 0.180673003f, 0.178775996f, 0.176889002f, 0.175012007f, 0.173144996f, 0.171288997f, 0.169441998f,\r\n\t\t0.167604998f, 0.165777996f, 0.163962007f, 0.162155002f, 0.160357997f, 0.158571005f, 0.156794995f, 0.155028f,\r\n\t\t0.153271005f, 0.151525006f, 0.149788007f, 0.148061007f, 0.146345004f, 0.144638002f, 0.142941996f, 0.141255006f,\r\n\t\t0.139578f, 0.137912005f, 0.136254996f, 0.134608999f, 0.132972002f, 0.131345004f, 0.129729003f, 0.128122002f,\r\n\t\t0.126525998f, 0.124939002f, 0.123363003f, 0.121795997f, 0.120240003f, 0.118693002f, 0.117156997f, 0.115630001f,\r\n\t\t0.114114001f, 0.112608001f, 0.111111f, 0.109624997f, 0.108148001f, 0.106682003f, 0.105226003f, 0.103779003f,\r\n\t\t0.102343f, 0.100915998f, 0.0995000005f, 0.0980937034f, 0.0966973007f, 0.0953110009f, 0.0939346999f, 0.0925683975f,\r\n\t\t0.0912121013f, 0.0898658037f, 0.0885296017f, 0.0872033015f, 0.085887f, 0.0845808014f, 0.0832844973f, 0.0819983035f,\r\n\t\t0.080722101f, 0.0794558972f, 0.0781996995f, 0.0769535005f, 0.0757173002f, 0.0744910985f, 0.0732749999f, 0.072068803f,\r\n\t\t0.0708727017f, 0.0696865991f, 0.0685103983f, 0.0673443004f, 0.0661882013f, 0.0650421008f, 0.0639059991f, 0.0627799034f,\r\n\t\t0.0616638996f, 0.0605578013f, 0.0594617985f, 0.0583757982f, 0.0572996996f, 0.0562337004f, 0.0551776998f, 0.0541317016f,\r\n\t\t0.0530956984f, 0.0520697013f, 0.0510537997f, 0.0500477999f, 0.0490517989f, 0.0480659008f, 0.0470900014f, 0.0461240001f,\r\n\t\t0.0451681018f, 0.0442221984f, 0.0432863012f, 0.0423604995f, 0.0414445996f, 0.0405386984f, 0.0396429002f, 0.0387570001f,\r\n\t\t0.0378811993f, 0.0370153002f, 0.0361595005f, 0.0353136994f, 0.0344779007f, 0.0336521007f, 0.0328364f, 0.0320306011f,\r\n\t\t0.0312348008f, 0.0304490998f, 0.0296733007f, 0.0289076008f, 0.0281518996f, 0.0274062008f, 0.0266705006f, 0.0259447992f,\r\n\t\t0.0252291001f, 0.0245233998f, 0.0238278005f, 0.0231420994f, 0.0224664994f, 0.0218007993f, 0.0211452004f, 0.0204996001f,\r\n\t\t0.0198640004f, 0.0192383993f, 0.0186228007f, 0.0180172008f, 0.0174215995f, 0.0168360993f, 0.0162604991f, 0.0156950001f,\r\n\t\t0.0151394997f, 0.0145939002f, 0.0140583999f, 0.0135329003f, 0.0130174002f, 0.0125118997f, 0.0120165003f, 0.011531f,\r\n\t\t0.0110555999f, 0.0105900997f, 0.0101346998f, 0.00968926027f, 0.00925383996f, 0.00882843044f, 0.00841304008f, 0.00800765026f,\r\n\t\t0.00761226984f, 0.0072269002f, 0.00685153995f, 0.00648619002f, 0.00613084994f, 0.00578552019f, 0.00545019982f, 0.00512488978f,\r\n\t\t0.00480959984f, 0.00450430019f, 0.00420902018f, 0.00392375002f, 0.00364848995f, 0.00338322995f, 0.00312799006f, 0.00288275001f,\r\n\t\t0.00264753005f, 0.00242230995f, 0.00220710994f, 0.00200191f, 0.00180673006f, 0.00162154995f, 0.00144638005f, 0.00128122f,\r\n\t\t0.00112608005f, 0.000980937039f, 0.000845808012f, 0.000720688025f, 0.00060557801f, 0.000500476977f, 0.000405386003f, 0.000320305f,\r\n\t\t0.000245233008f, 0.000180172996f, 0.000125120001f, 8.0076803E-05f, 4.50432017E-05f, 2.00192007E-05f, 5.00480019E-06f, 0f,\r\n\t\t0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003ETable \u00221986-sin\u0022 (1024 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] GloopSin =\r\n\t{\r\n\t\t1.0f, 0.999980986f, 0.999925017f, 0.999831021f, 0.999698997f, 0.999529004f, 0.999321997f, 0.999077976f,\r\n\t\t0.998795986f, 0.998476028f, 0.998117983f, 0.997722983f, 0.997291028f, 0.996819973f, 0.996312976f, 0.995768011f,\r\n\t\t0.995185018f, 0.99456501f, 0.993906975f, 0.993211985f, 0.99247998f, 0.991710007f, 0.99090302f, 0.990058005f,\r\n\t\t0.989176989f, 0.988258004f, 0.987302005f, 0.986307979f, 0.98527801f, 0.984210014f, 0.983106017f, 0.981963992f,\r\n\t\t0.980786026f, 0.979569972f, 0.978317976f, 0.977028012f, 0.975701988f, 0.974340022f, 0.972940028f, 0.971503973f,\r\n\t\t0.970031977f, 0.968522012f, 0.966977f, 0.965394974f, 0.963775992f, 0.962122023f, 0.96043098f, 0.958703995f,\r\n\t\t0.956941009f, 0.955142021f, 0.953306019f, 0.951435983f, 0.949528992f, 0.947586f, 0.94560802f, 0.943593979f,\r\n\t\t0.94154501f, 0.93945998f, 0.937340021f, 0.935184002f, 0.932992995f, 0.930768013f, 0.92850697f, 0.926210999f,\r\n\t\t0.923879981f, 0.921514988f, 0.919113994f, 0.916679978f, 0.914210021f, 0.911706984f, 0.909169018f, 0.906596005f,\r\n\t\t0.903989971f, 0.901350021f, 0.898675025f, 0.895967007f, 0.893225014f, 0.890448987f, 0.887639999f, 0.88479799f,\r\n\t\t0.881922007f, 0.879013002f, 0.876070976f, 0.873095989f, 0.870087981f, 0.867047012f, 0.863973975f, 0.860867977f,\r\n\t\t0.857729018f, 0.854559004f, 0.85135603f, 0.848120987f, 0.844853997f, 0.841556013f, 0.83822602f, 0.83486402f,\r\n\t\t0.831471026f, 0.828046024f, 0.824590027f, 0.821102977f, 0.817586005f, 0.814037025f, 0.810458004f, 0.806849003f,\r\n\t\t0.803209007f, 0.799538016f, 0.795837998f, 0.792107999f, 0.788348019f, 0.784557998f, 0.780737996f, 0.77688998f,\r\n\t\t0.773011982f, 0.769104004f, 0.765168011f, 0.761204004f, 0.757210016f, 0.753188014f, 0.749137998f, 0.745059013f,\r\n\t\t0.740952015f, 0.736818016f, 0.732656002f, 0.728465974f, 0.724247992f, 0.720004022f, 0.715731978f, 0.711434007f,\r\n\t\t0.707108021f, 0.702755988f, 0.698378026f, 0.693973005f, 0.689541996f, 0.685084999f, 0.680602014f, 0.676093996f,\r\n\t\t0.671559989f, 0.667001009f, 0.662416995f, 0.657808006f, 0.653173983f, 0.648515999f, 0.643832982f, 0.639126003f,\r\n\t\t0.634395003f, 0.629639983f, 0.624861002f, 0.620059013f, 0.615233004f, 0.610383987f, 0.605512977f, 0.600618005f,\r\n\t\t0.595700979f, 0.590761006f, 0.585798979f, 0.580815017f, 0.575810015f, 0.570782006f, 0.565734029f, 0.560662985f,\r\n\t\t0.555571973f, 0.550459981f, 0.545327008f, 0.540172994f, 0.534999013f, 0.529805005f, 0.524591982f, 0.519357979f,\r\n\t\t0.514105022f, 0.508831978f, 0.503539979f, 0.49823001f, 0.492900014f, 0.487551987f, 0.48218599f, 0.476801008f,\r\n\t\t0.471399009f, 0.465977997f, 0.460539997f, 0.455085993f, 0.449613005f, 0.444124013f, 0.438618004f, 0.433095992f,\r\n\t\t0.427556992f, 0.422001988f, 0.416431993f, 0.410845011f, 0.405243009f, 0.399625987f, 0.393994004f, 0.388347f,\r\n\t\t0.382685006f, 0.377009004f, 0.371318996f, 0.36561501f, 0.359896988f, 0.354166001f, 0.348421007f, 0.34266299f,\r\n\t\t0.336892009f, 0.331108004f, 0.325311989f, 0.319503993f, 0.313683987f, 0.307852f, 0.302008003f, 0.296153009f,\r\n\t\t0.290286988f, 0.28441f, 0.278522015f, 0.272623986f, 0.26671499f, 0.26079601f, 0.254868001f, 0.248930007f,\r\n\t\t0.242982f, 0.237026006f, 0.231059998f, 0.225086004f, 0.219102994f, 0.213111997f, 0.207113996f, 0.201106995f,\r\n\t\t0.195093006f, 0.189071f, 0.183042005f, 0.177007005f, 0.170964003f, 0.164915994f, 0.158860996f, 0.152799994f,\r\n\t\t0.146733001f, 0.140661001f, 0.134582996f, 0.128500998f, 0.122413002f, 0.116320997f, 0.110224999f, 0.104124002f,\r\n\t\t0.0980195031f, 0.091911301f, 0.0857995972f, 0.0796850026f, 0.0735670999f, 0.0674464032f, 0.0613231994f, 0.0551977009f,\r\n\t\t0.0490701012f, 0.0429408997f, 0.0368098989f, 0.0306774005f, 0.0245437995f, 0.0184093006f, 0.0122741004f, 0.00613844022f,\r\n\t\t2.5351801E-06f, -0.0061333701f, -0.0122689996f, -0.0184042007f, -0.0245388001f, -0.0306723993f, -0.036804799f, -0.0429357998f,\r\n\t\t-0.0490650013f, -0.0551926009f, -0.0613180995f, -0.0674412996f, -0.0735620037f, -0.0796798989f, -0.0857945979f, -0.0919061974f,\r\n\t\t-0.0980143994f, -0.104119003f, -0.11022f, -0.116315998f, -0.122408003f, -0.128494993f, -0.134578004f, -0.140655994f,\r\n\t\t-0.146727994f, -0.152795002f, -0.158856004f, -0.164911002f, -0.170958996f, -0.177001998f, -0.183036998f, -0.189065993f,\r\n\t\t-0.195087999f, -0.201102003f, -0.207109004f, -0.213108003f, -0.219098002f, -0.225080997f, -0.231055006f, -0.237020999f,\r\n\t\t-0.242976993f, -0.248925f, -0.254862994f, -0.260791004f, -0.266710013f, -0.272619009f, -0.278517008f, -0.284404993f,\r\n\t\t-0.290282011f, -0.296148002f, -0.302002996f, -0.307846993f, -0.31367901f, -0.319498986f, -0.325307995f, -0.33110401f,\r\n\t\t-0.336887002f, -0.342658013f, -0.348416001f, -0.354160994f, -0.359892011f, -0.365610003f, -0.371315002f, -0.377005011f,\r\n\t\t-0.382681012f, -0.388341993f, -0.393988997f, -0.399621993f, -0.405238986f, -0.410840988f, -0.416426986f, -0.421997994f,\r\n\t\t-0.427552015f, -0.433091015f, -0.438614011f, -0.44411999f, -0.449609011f, -0.455080986f, -0.460536003f, -0.465974003f,\r\n\t\t-0.471394002f, -0.476797014f, -0.482181013f, -0.487547994f, -0.492895991f, -0.498225003f, -0.503535986f, -0.508827984f,\r\n\t\t-0.514100015f, -0.519353986f, -0.524586976f, -0.529801011f, -0.534995019f, -0.540169001f, -0.545322001f, -0.550454974f,\r\n\t\t-0.55556798f, -0.560658991f, -0.565729022f, -0.570778012f, -0.575806022f, -0.580811977f, -0.585794985f, -0.590757012f,\r\n\t\t-0.595696986f, -0.600614011f, -0.605508983f, -0.610379994f, -0.615229011f, -0.62005502f, -0.624857008f, -0.62963599f,\r\n\t\t-0.63439101f, -0.639122009f, -0.643828988f, -0.648512006f, -0.65316999f, -0.657804012f, -0.662413001f, -0.666998029f,\r\n\t\t-0.671557009f, -0.676090002f, -0.680598974f, -0.685081005f, -0.689538002f, -0.693969011f, -0.698373973f, -0.702751994f,\r\n\t\t-0.707104981f, -0.711430013f, -0.715728998f, -0.720000029f, -0.724245012f, -0.728461981f, -0.732652009f, -0.736814022f,\r\n\t\t-0.740948975f, -0.745055974f, -0.749134004f, -0.753184974f, -0.757206976f, -0.761200011f, -0.765164971f, -0.769101977f,\r\n\t\t-0.773007989f, -0.776885986f, -0.780735016f, -0.784555018f, -0.788344026f, -0.792105019f, -0.795835018f, -0.799534976f,\r\n\t\t-0.803206027f, -0.806846023f, -0.810455024f, -0.814033985f, -0.817583025f, -0.821099997f, -0.824586987f, -0.828042984f,\r\n\t\t-0.831467986f, -0.834860981f, -0.83822298f, -0.841552973f, -0.844851971f, -0.848118007f, -0.85135299f, -0.854556024f,\r\n\t\t-0.857726991f, -0.860864997f, -0.863970995f, -0.867044985f, -0.870085001f, -0.873093009f, -0.876067996f, -0.879010975f,\r\n\t\t-0.88191998f, -0.884796023f, -0.887637973f, -0.890447021f, -0.893222988f, -0.89596498f, -0.898672998f, -0.901346982f,\r\n\t\t-0.903988004f, -0.906593978f, -0.909166992f, -0.911705017f, -0.914207995f, -0.916678011f, -0.919112027f, -0.921513021f,\r\n\t\t-0.923878014f, -0.926208973f, -0.928505003f, -0.930765986f, -0.932991982f, -0.935181975f, -0.937337995f, -0.939458013f,\r\n\t\t-0.941542983f, -0.943592012f, -0.945605993f, -0.947583973f, -0.949527025f, -0.951434016f, -0.953305006f, -0.955139995f,\r\n\t\t-0.956938982f, -0.958702028f, -0.960429013f, -0.962119997f, -0.963774979f, -0.965393007f, -0.966975987f, -0.968520999f,\r\n\t\t-0.97003001f, -0.971503019f, -0.972939014f, -0.974339008f, -0.975700974f, -0.977026999f, -0.978317022f, -0.979569018f,\r\n\t\t-0.980785012f, -0.981962979f, -0.983105004f, -0.984209001f, -0.985276997f, -0.986307979f, -0.987300992f, -0.988256991f,\r\n\t\t-0.989175975f, -0.990058005f, -0.990902007f, -0.991708994f, -0.992479026f, -0.993211985f, -0.993906975f, -0.994563997f,\r\n\t\t-0.995184004f, -0.995766997f, -0.996312022f, -0.996819973f, -0.997290015f, -0.997722983f, -0.998117983f, -0.998475015f,\r\n\t\t-0.998794973f, -0.999077976f, -0.999321997f, -0.999529004f, -0.999698997f, -0.999830008f, -0.999925017f, -0.999980986f,\r\n\t\t-1.0f, -0.999980986f, -0.999925017f, -0.999831021f, -0.999698997f, -0.999530017f, -0.99932301f, -0.999077976f,\r\n\t\t-0.998795986f, -0.998476028f, -0.998117983f, -0.997722983f, -0.997291028f, -0.996820986f, -0.996312976f, -0.995768011f,\r\n\t\t-0.995185018f, -0.99456501f, -0.993906975f, -0.993211985f, -0.99247998f, -0.991710007f, -0.99090302f, -0.990059018f,\r\n\t\t-0.989176989f, -0.988258004f, -0.987302005f, -0.986308992f, -0.98527801f, -0.984211028f, -0.983106017f, -0.981965005f,\r\n\t\t-0.980786026f, -0.979570985f, -0.978317976f, -0.977029026f, -0.975703001f, -0.974340022f, -0.972940981f, -0.971504986f,\r\n\t\t-0.970031977f, -0.968523026f, -0.966977f, -0.965395987f, -0.963777006f, -0.962122023f, -0.960431993f, -0.958705008f,\r\n\t\t-0.956941009f, -0.955142021f, -0.953306973f, -0.951435983f, -0.949528992f, -0.947587013f, -0.945608974f, -0.943594992f,\r\n\t\t-0.94154501f, -0.939460993f, -0.937340021f, -0.935185015f, -0.932994008f, -0.930768013f, -0.928507984f, -0.926212013f,\r\n\t\t-0.923880994f, -0.921516001f, -0.919115007f, -0.916680992f, -0.914210975f, -0.911707997f, -0.909169972f, -0.906597972f,\r\n\t\t-0.903990984f, -0.901350975f, -0.898675978f, -0.89596802f, -0.893226027f, -0.890451014f, -0.887642026f, -0.884799004f,\r\n\t\t-0.88192302f, -0.879014015f, -0.87607199f, -0.873097003f, -0.870088995f, -0.867048025f, -0.863974988f, -0.86086899f,\r\n\t\t-0.857730985f, -0.854560018f, -0.851356983f, -0.848123014f, -0.844856024f, -0.841557026f, -0.838226974f, -0.834864974f,\r\n\t\t-0.83147198f, -0.828046978f, -0.824591994f, -0.821105003f, -0.817587018f, -0.814038992f, -0.810459971f, -0.806850016f,\r\n\t\t-0.80321002f, -0.799539983f, -0.795840025f, -0.792109013f, -0.788348973f, -0.784559011f, -0.780740023f, -0.776890993f,\r\n\t\t-0.773012996f, -0.769105971f, -0.765169978f, -0.761205018f, -0.757211983f, -0.753189981f, -0.749139011f, -0.74506098f,\r\n\t\t-0.740953982f, -0.736819983f, -0.732657015f, -0.728466988f, -0.724250019f, -0.720005989f, -0.715734005f, -0.71143502f,\r\n\t\t-0.707109988f, -0.702758014f, -0.69837898f, -0.693974972f, -0.689544022f, -0.685087025f, -0.680603981f, -0.676096022f,\r\n\t\t-0.671562016f, -0.667002976f, -0.662419021f, -0.657809973f, -0.65317601f, -0.648518026f, -0.643835008f, -0.639128029f,\r\n\t\t-0.63439697f, -0.62964201f, -0.624863029f, -0.62006098f, -0.615234971f, -0.610386014f, -0.605515003f, -0.600619972f,\r\n\t\t-0.595703006f, -0.590762973f, -0.585801005f, -0.580817997f, -0.575811982f, -0.570783973f, -0.565734982f, -0.560665011f,\r\n\t\t-0.555574f, -0.550462008f, -0.545328975f, -0.540175021f, -0.535001993f, -0.529807985f, -0.524594009f, -0.519360006f,\r\n\t\t-0.514106989f, -0.508834004f, -0.503542006f, -0.498232007f, -0.492902011f, -0.487554014f, -0.482187986f, -0.476803005f,\r\n\t\t-0.471401006f, -0.465979993f, -0.460543007f, -0.45508799f, -0.449615002f, -0.44412601f, -0.438621014f, -0.433097988f,\r\n\t\t-0.427560002f, -0.422004998f, -0.41643399f, -0.410847992f, -0.40524599f, -0.399628997f, -0.393996f, -0.388348997f,\r\n\t\t-0.382687986f, -0.377012014f, -0.371322006f, -0.365617007f, -0.359899014f, -0.354167998f, -0.348423004f, -0.342664987f,\r\n\t\t-0.336894006f, -0.331111014f, -0.325314999f, -0.319507003f, -0.313686997f, -0.307853997f, -0.302011013f, -0.296155989f,\r\n\t\t-0.290289015f, -0.284411997f, -0.278524011f, -0.272626013f, -0.266716987f, -0.260798991f, -0.254869998f, -0.248932004f,\r\n\t\t-0.242984995f, -0.237028003f, -0.231062993f, -0.225088999f, -0.219106004f, -0.213115007f, -0.207115993f, -0.201109007f,\r\n\t\t-0.195095003f, -0.189073995f, -0.183045f, -0.177009001f, -0.170966998f, -0.164918005f, -0.158862993f, -0.152802005f,\r\n\t\t-0.146734998f, -0.140662998f, -0.134586006f, -0.128502995f, -0.122415997f, -0.116324f, -0.110227004f, -0.104125999f,\r\n\t\t-0.098021999f, -0.091913797f, -0.0858021006f, -0.0796872005f, -0.0735692978f, -0.067448698f, -0.0613260008f, -0.0552004986f,\r\n\t\t-0.0490728989f, -0.0429433994f, -0.0368123986f, -0.0306800008f, -0.0245463997f, -0.0184119008f, -0.0122766001f, -0.00614097016f,\r\n\t\t-5.0703602E-06f, 0.00613082992f, 0.0122664999f, 0.0184016991f, 0.0245361999f, 0.0306697991f, 0.0368022993f, 0.0429333001f,\r\n\t\t0.0490626991f, 0.0551902987f, 0.061315801f, 0.0674386024f, 0.0735592023f, 0.0796770975f, 0.0857919976f, 0.0919037014f,\r\n\t\t0.0980119035f, 0.104116f, 0.110216998f, 0.116313003f, 0.122405998f, 0.128492996f, 0.134575993f, 0.140652999f,\r\n\t\t0.146724999f, 0.152792007f, 0.158852994f, 0.164908007f, 0.170956999f, 0.176999003f, 0.183035001f, 0.189063996f,\r\n\t\t0.195085004f, 0.201098993f, 0.207105994f, 0.213104993f, 0.219096005f, 0.225079f, 0.231052995f, 0.237018004f,\r\n\t\t0.242974997f, 0.248922005f, 0.254860997f, 0.260789007f, 0.266707987f, 0.272615999f, 0.278515011f, 0.284402996f,\r\n\t\t0.290280014f, 0.296146005f, 0.302000999f, 0.307844996f, 0.313677013f, 0.319496989f, 0.325305015f, 0.331101f,\r\n\t\t0.336885005f, 0.342655987f, 0.348414004f, 0.354158014f, 0.359890014f, 0.365608007f, 0.371311992f, 0.377002001f,\r\n\t\t0.382678002f, 0.388339996f, 0.393987f, 0.399619013f, 0.405236006f, 0.410838008f, 0.41642499f, 0.421995014f,\r\n\t\t0.427549988f, 0.433088988f, 0.438612014f, 0.44411701f, 0.449606001f, 0.455078989f, 0.460534006f, 0.465972006f,\r\n\t\t0.471392006f, 0.476794004f, 0.482178986f, 0.487545013f, 0.49289301f, 0.498223007f, 0.503534019f, 0.508825004f,\r\n\t\t0.514097989f, 0.519351006f, 0.524585009f, 0.529798985f, 0.534992993f, 0.540166974f, 0.545320988f, 0.550454021f,\r\n\t\t0.555566013f, 0.560657024f, 0.565726995f, 0.570775986f, 0.575803995f, 0.580808997f, 0.585793018f, 0.590754986f,\r\n\t\t0.595695019f, 0.600611985f, 0.605507016f, 0.610378027f, 0.615226984f, 0.620052993f, 0.624854982f, 0.629634023f,\r\n\t\t0.634388983f, 0.639119983f, 0.643827021f, 0.648509979f, 0.653168976f, 0.657802999f, 0.662410975f, 0.666996002f,\r\n\t\t0.671554983f, 0.676087976f, 0.680597007f, 0.685078979f, 0.689535975f, 0.693966985f, 0.698372006f, 0.702750981f,\r\n\t\t0.707103014f, 0.711427987f, 0.715726972f, 0.719999015f, 0.724242985f, 0.728461027f, 0.732649982f, 0.736813009f,\r\n\t\t0.740947008f, 0.745054007f, 0.749132991f, 0.753183007f, 0.757205009f, 0.761198997f, 0.765163004f, 0.76910001f,\r\n\t\t0.773006976f, 0.776884973f, 0.780734003f, 0.784552991f, 0.788343012f, 0.792102993f, 0.795832992f, 0.799534023f,\r\n\t\t0.803204f, 0.806843996f, 0.810454011f, 0.814032972f, 0.817582011f, 0.821098983f, 0.824585974f, 0.828041971f,\r\n\t\t0.831466019f, 0.834860027f, 0.838221014f, 0.841552019f, 0.844850004f, 0.848116994f, 0.851351976f, 0.854555011f,\r\n\t\t0.857725978f, 0.860863984f, 0.863969982f, 0.867043018f, 0.870083988f, 0.873091996f, 0.876066983f, 0.879009008f,\r\n\t\t0.881918013f, 0.884793997f, 0.887637019f, 0.890446007f, 0.893221974f, 0.895964026f, 0.898671985f, 0.901346028f,\r\n\t\t0.90398699f, 0.906593025f, 0.909165025f, 0.911704004f, 0.914206982f, 0.916676998f, 0.919111013f, 0.921512008f,\r\n\t\t0.923877001f, 0.926208019f, 0.92850399f, 0.930764973f, 0.932991028f, 0.935181022f, 0.937336981f, 0.939456999f,\r\n\t\t0.941542029f, 0.943592012f, 0.94560498f, 0.947583973f, 0.949526012f, 0.951433003f, 0.953303993f, 0.955138981f,\r\n\t\t0.956938982f, 0.958702028f, 0.960429013f, 0.962119997f, 0.963774025f, 0.965393007f, 0.966974974f, 0.968520999f,\r\n\t\t0.97003001f, 0.971502006f, 0.972939014f, 0.974337995f, 0.975700974f, 0.977026999f, 0.978316009f, 0.979569018f,\r\n\t\t0.980783999f, 0.981962979f, 0.983103991f, 0.984209001f, 0.985276997f, 0.986307025f, 0.987299979f, 0.988256991f,\r\n\t\t0.989175975f, 0.990056992f, 0.990902007f, 0.991708994f, 0.992479026f, 0.993210971f, 0.993906021f, 0.994563997f,\r\n\t\t0.995184004f, 0.995766997f, 0.996312022f, 0.996819973f, 0.997290015f, 0.997722983f, 0.998117983f, 0.998475015f,\r\n\t\t0.998794973f, 0.999077022f, 0.999321997f, 0.999529004f, 0.999698997f, 0.999830008f, 0.999925017f, 0.999980986f,\r\n\t\t0f,\r\n\t};\r\n\r\n\t/// \u003Csummary\u003ETable \u00221986-imp\u0022 (2 points \u002B guard point).\u003C/summary\u003E\r\n\tpublic static readonly float[] GloopImp =\r\n\t{\r\n\t\t1.0f, 0f, 0f,\r\n\t};\r\n}\r\n"},{"Ident":"chomnr.squishy_terry","Path":"Fatality/Blood.cs","FileName":"Blood.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing SquishyTerry.Sim;\r\n\r\nnamespace SquishyTerry;\r\n\r\n/// \u003Csummary\u003E\r\n/// Blood for the fatality: a small, cheap liquid simulation made for the squishy face.\r\n/// \u003Clist type=\u0022bullet\u0022\u003E\r\n/// \u003Citem\u003E\u003Cb\u003EDrips\u003C/b\u003E live on the skin: a position on a triangle (barycentric) that runs downhill\r\n/// along the surface under gravity, walking from triangle to triangle, slowing and thinning as it\r\n/// leaves a trail behind. Because every point is stored on the skin, drips and trails ride along\r\n/// as the face squishes and turns.\u003C/item\u003E\r\n/// \u003Citem\u003E\u003Cb\u003EDroplets\u003C/b\u003E are thrown from a wound: ballistic particles that splat into new little\r\n/// drips where they land back on the face, or fall away out of view.\u003C/item\u003E\r\n/// \u003Citem\u003E\u003Cb\u003EWounds\u003C/b\u003E bleed while open: a growing stain, drips every so often, and spurts when\r\n/// the knife moves.\u003C/item\u003E\r\n/// \u003C/list\u003E\r\n/// Everything is drawn from one preallocated mesh rewritten each frame (unused slots collapse to\r\n/// nothing), with a glossy material and rounded normals so the trails read as wet beads.\r\n/// \u003C/summary\u003E\r\npublic sealed class Blood : Component\r\n{\r\n\t[Property] public Material Material { get; set; }\r\n\t[Property] public Color Color { get; set; } = new( 0.22f, 0.005f, 0.012f );\r\n\r\n\t/// \u003Csummary\u003EWorld gravity for thrown droplets (units / s\u00B2).\u003C/summary\u003E\r\n\t[Property] public float DropletGravity { get; set; } = 60f;\r\n\r\n\t/// \u003Csummary\u003EHow fast a full drip runs down the skin (simulation units / s; the head is ~2 across).\u003C/summary\u003E\r\n\t[Property] public float DripSpeed { get; set; } = 0.3f;\r\n\r\n\t/// \u003Csummary\u003ESeconds blood stays after it stops moving (or a wound closes) before it fades; 0 = it stays.\u003C/summary\u003E\r\n\t[Property] public float StainLifetime { get; set; } = 0f;\r\n\r\n\t/// \u003Csummary\u003EEditor testing: tick to open a wound on Terry\u0027s cheek (untick to close it).\u003C/summary\u003E\r\n\t[Property] public bool TestWound { get; set; }\r\n\r\n\t// Capacity: past these the oldest blood is reused, so they\u0027re generous.\r\n\tconst int MaxDrips = 96;\r\n\tconst int MaxSpots = 192;\r\n\tconst int SpotSides = 8;\r\n\tconst int MaxTrail = 40;\r\n\tconst int MaxDroplets = 64;\r\n\tconst int MaxWounds = 16;\r\n\tconst int BlobSides = 10;\r\n\tconst int WoundSides = 14;\r\n\r\n\tconst float TrailSpacing = 0.018f;   // simulation units between trail points\r\n\tconst float DripWidth = 0.5f;        // world units, a full drip\r\n\tconst float SurfaceLift = 0.4f;      // world units above the skin\r\n\tconst float Consumption = 1.3f;      // volume used per simulation unit travelled\r\n\tconst float FadeTime = 2f;\r\n\tconst int TracesPerFrame = 6;        // droplet-vs-face ray tests allowed per frame\r\n\r\n\tsealed class Drip\r\n\t{\r\n\t\tpublic bool Alive;\r\n\t\tpublic int Tri;\r\n\t\tpublic Vector3 Bary;\r\n\t\tpublic float Volume, Speed, Phase, Still, Size;\r\n\t\tpublic Vec3 LastTrail;\r\n\t\tpublic readonly List\u003C(int Tri, Vector3 Bary, float Width)\u003E Trail = new();\r\n\t}\r\n\r\n\tstruct Droplet\r\n\t{\r\n\t\tpublic bool Alive;\r\n\t\tpublic Vector3 Pos, Vel;\r\n\t\tpublic float Size, Age;\r\n\t}\r\n\r\n\tsealed class Wound\r\n\t{\r\n\t\tpublic bool Alive, Open;\r\n\t\tpublic int Tri;\r\n\t\tpublic Vector3 Bary;\r\n\t\tpublic float Radius, MaxRadius, NextDrip, Closed, Ooze;\r\n\t\tpublic int Order;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EA splat where a thrown droplet landed: a small stain on the skin.\u003C/summary\u003E\r\n\tstruct Spot\r\n\t{\r\n\t\tpublic bool Alive;\r\n\t\tpublic int Tri;\r\n\t\tpublic Vector3 Bary;\r\n\t\tpublic float Radius;\r\n\t}\r\n\r\n\treadonly Drip[] _drips = new Drip[MaxDrips];\r\n\treadonly Droplet[] _droplets = new Droplet[MaxDroplets];\r\n\treadonly Wound[] _wounds = new Wound[MaxWounds];\r\n\treadonly Spot[] _spots = new Spot[MaxSpots];\r\n\tint _nextSpot, _woundOrder;\r\n\tint _nextDrip, _nextDroplet;\r\n\r\n\tSquishyFace _face;\r\n\tint[] _adjacent; // per triangle corner k: the triangle across the edge opposite corner k, or -1\r\n\r\n\tGameObject _object;\r\n\tMesh _mesh;\r\n\tVertex[] _verts;\r\n\tModelRenderer _renderer;\r\n\tint _dripVerts, _woundVerts;\r\n\treadonly Random _random = new();\r\n\r\n\t// --- Public API ---\r\n\r\n\t/// \u003Csummary\u003EOpens a wound at a point on the skin; returns its id.\u003C/summary\u003E\r\n\tpublic int OpenWound( int triangle, Vector3 bary )\r\n\t{\r\n\t\t// A free slot, else the oldest wound.\r\n\t\tint slot = 0;\r\n\t\tfor ( int i = 0; i \u003C MaxWounds; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tif ( !_wounds[i].Alive ) { slot = i; break; }\r\n\t\t\tif ( _wounds[i].Order \u003C _wounds[slot].Order ) slot = i;\r\n\t\t}\r\n\t\tvar w = _wounds[slot];\r\n\t\tw.Order = \u002B\u002B_woundOrder;\r\n\t\tw.Alive = true;\r\n\t\tw.Open = true;\r\n\t\tw.Tri = triangle;\r\n\t\tw.Bary = bary;\r\n\t\tw.Radius = 0.15f;\r\n\t\tw.MaxRadius = 0.9f \u002B Rand( 0f, 0.4f );\r\n\t\tw.NextDrip = 0.1f;\r\n\t\tw.Closed = 0f;\r\n\t\tw.Ooze = 0f;\r\n\t\treturn slot;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EThe knife was pulled out: a last gush, then the wound oozes for a few seconds and stops.\u003C/summary\u003E\r\n\tpublic void CloseWound( int id, Vector3 outward )\r\n\t{\r\n\t\tif ( id \u003C 0 || id \u003E= MaxWounds || !_wounds[id].Alive ) return;\r\n\t\tvar w = _wounds[id];\r\n\t\tw.Open = false;\r\n\t\tw.Ooze = 8f;\r\n\t\tSpurt( id, outward, 22, 1.2f );\r\n\t\tfor ( int i = 0; i \u003C 3; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tvar (t, b) = Around( w.Tri, w.Bary, w.Radius );\r\n\t\t\tAddDrip( t, b, Rand( 0.7f, 1f ) );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EThrows droplets out of a wound (along \u003Cparamref name=\u0022outward\u0022/\u003E, spread in a cone).\u003C/summary\u003E\r\n\tpublic void Spurt( int id, Vector3 outward, int count, float force = 1f )\r\n\t{\r\n\t\tif ( _face is null || id \u003C 0 || id \u003E= MaxWounds || !_wounds[id].Alive ) return;\r\n\t\tvar w = _wounds[id];\r\n\t\tvar origin = _face.SurfacePoint( w.Tri, w.Bary );\r\n\t\tvar normal = _face.SurfaceNormal( w.Tri, w.Bary );\r\n\t\tvar dir = (outward.Normal \u002B normal).Normal;\r\n\r\n\t\tfor ( int i = 0; i \u003C count; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tvar spread = new Vector3( Rand( -1f, 1f ), Rand( -1f, 1f ), Rand( -1f, 1f ) ) * 0.55f;\r\n\t\t\tvar velocity = (dir \u002B spread).Normal * Rand( 6f, 18f ) * force;\r\n\t\t\tref var d = ref _droplets[_nextDroplet];\r\n\t\t\t_nextDroplet = (_nextDroplet \u002B 1) % MaxDroplets;\r\n\t\t\td.Alive = true;\r\n\t\t\td.Pos = origin \u002B normal * 0.2f;\r\n\t\t\td.Vel = velocity;\r\n\t\t\td.Size = Rand( 0.07f, 0.2f );\r\n\t\t\td.Age = 0f;\r\n\t\t}\r\n\r\n\t\t// Pushing the wound also pumps a fresh drip down the skin.\r\n\t\tvar (st, sb) = Around( w.Tri, w.Bary, w.Radius );\r\n\t\tAddDrip( st, sb, Rand( 0.5f, 0.9f ) * MathF.Min( force, 1f ) );\r\n\t\tw.Radius = MathF.Min( w.Radius \u002B 0.1f * force, w.MaxRadius );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EHow hard he\u0027s being squished: wounds drip up to this many times faster (1 = at rest).\u003C/summary\u003E\r\n\tpublic float Pump { get; set; } = 1f;\r\n\r\n\t/// \u003Csummary\u003EWounds still bleeding (open, or oozing after the knife came out).\u003C/summary\u003E\r\n\tpublic int BleedingWounds\r\n\t{\r\n\t\tget\r\n\t\t{\r\n\t\t\tint n = 0;\r\n\t\t\tforeach ( var w in _wounds ) if ( w is not null \u0026\u0026 w.Alive \u0026\u0026 (w.Open || w.Ooze \u003E 0f) ) n\u002B\u002B;\r\n\t\t\treturn n;\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EA squish landed: every bleeding wound spurts.\u003C/summary\u003E\r\n\tpublic void PumpAll( int droplets )\r\n\t{\r\n\t\tfor ( int i = 0; i \u003C MaxWounds; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tvar w = _wounds[i];\r\n\t\t\tif ( w is null || !w.Alive || !(w.Open || w.Ooze \u003E 0f) ) continue;\r\n\t\t\tSpurt( i, _face?.SurfaceNormal( w.Tri, w.Bary ) ?? Vector3.Up, droplets, 0.7f );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003ERemoves all blood.\u003C/summary\u003E\r\n\tpublic void Clear()\r\n\t{\r\n\t\tforeach ( var d in _drips ) { d.Alive = false; d.Trail.Clear(); }\r\n\t\tfor ( int i = 0; i \u003C MaxDroplets; i\u002B\u002B ) _droplets[i].Alive = false;\r\n\t\tforeach ( var w in _wounds ) w.Alive = false;\r\n\t\tfor ( int i = 0; i \u003C MaxSpots; i\u002B\u002B ) _spots[i].Alive = false;\r\n\t}\r\n\r\n\t// --- Lifecycle ---\r\n\r\n\tprotected override void OnEnabled()\r\n\t{\r\n\t\tfor ( int i = 0; i \u003C MaxDrips; i\u002B\u002B ) _drips[i] = new Drip();\r\n\t\tfor ( int i = 0; i \u003C MaxWounds; i\u002B\u002B ) _wounds[i] = new Wound();\r\n\t\tBuildMesh();\r\n\t}\r\n\r\n\tprotected override void OnDisabled()\r\n\t{\r\n\t\t_object?.Destroy();\r\n\t\t_object = null;\r\n\t\t_mesh = null;\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\t_face ??= Components.Get\u003CSquishyFace\u003E();\r\n\t\tif ( _face?.Sim is null || _mesh is null ) return;\r\n\t\tif ( _adjacent is null ) BuildAdjacency( _face.Sim.Indices );\r\n\r\n\t\tUpdateTestWound();\r\n\r\n\t\tfloat dt = MathF.Min( RealTime.Delta, 0.05f ) * SlowMo.Scale;\r\n\t\tUpdateWounds( dt );\r\n\t\tUpdateDrips( dt );\r\n\t\tUpdateDroplets( dt );\r\n\t\tRender();\r\n\t}\r\n\r\n\tint _testWound = -1;\r\n\r\n\tvoid UpdateTestWound()\r\n\t{\r\n\t\tif ( TestWound \u0026\u0026 _testWound \u003C 0 \u0026\u0026 Scene.Camera is { } camera )\r\n\t\t{\r\n\t\t\t// Aim at the right cheek, a little below the eye.\r\n\t\t\tvar ray = camera.ScreenNormalToRay( new Vector3( 0.56f, 0.6f, 0f ) );\r\n\t\t\tif ( _face.TraceSurface( ray, out int tri, out var bary ) )\r\n\t\t\t{\r\n\t\t\t\t_testWound = OpenWound( tri, bary );\r\n\t\t\t\tSpurt( _testWound, -ray.Forward, 14 );\r\n\t\t\t}\r\n\t\t}\r\n\t\telse if ( !TestWound \u0026\u0026 _testWound \u003E= 0 )\r\n\t\t{\r\n\t\t\tCloseWound( _testWound, -(Scene.Camera?.WorldRotation.Forward ?? Vector3.Forward) );\r\n\t\t\t_testWound = -1;\r\n\t\t}\r\n\t}\r\n\r\n\t// --- Simulation ---\r\n\r\n\tvoid UpdateWounds( float dt )\r\n\t{\r\n\t\tforeach ( var w in _wounds )\r\n\t\t{\r\n\t\t\tif ( !w.Alive ) continue;\r\n\t\t\tbool bleeding = w.Open || w.Ooze \u003E 0f;\r\n\t\t\tif ( !w.Open ) { w.Ooze -= dt; w.Closed \u002B= dt; }\r\n\r\n\t\t\tif ( bleeding )\r\n\t\t\t{\r\n\t\t\t\tw.Radius = MathF.Min( w.Radius \u002B dt * 0.25f, w.MaxRadius );\r\n\t\t\t\tw.NextDrip -= dt * Pump;\r\n\t\t\t\tif ( w.NextDrip \u003C= 0f )\r\n\t\t\t\t{\r\n\t\t\t\t\tw.NextDrip = Rand( 0.35f, 0.9f );\r\n\t\t\t\t\tvar (t, b) = Around( w.Tri, w.Bary, w.Radius );\r\n\t\t\t\t\tAddDrip( t, b, Rand( 0.35f, 1f ) );\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tif ( StainLifetime \u003E 0f \u0026\u0026 w.Closed \u003E StainLifetime \u002B FadeTime ) w.Alive = false;\r\n\t\t}\r\n\t}\r\n\r\n\tvoid AddDrip( int tri, Vector3 bary, float volume )\r\n\t{\r\n\t\t// Reuse a free slot, else the oldest.\r\n\t\tDrip drip = null;\r\n\t\tfor ( int i = 0; i \u003C MaxDrips \u0026\u0026 drip is null; i\u002B\u002B )\r\n\t\t\tif ( !_drips[i].Alive ) drip = _drips[i];\r\n\t\tif ( drip is null )\r\n\t\t{\r\n\t\t\tdrip = _drips[_nextDrip];\r\n\t\t\t_nextDrip = (_nextDrip \u002B 1) % MaxDrips;\r\n\t\t}\r\n\r\n\t\tdrip.Alive = true;\r\n\t\tdrip.Tri = tri;\r\n\t\tdrip.Bary = bary;\r\n\t\tdrip.Volume = volume;\r\n\t\tdrip.Size = volume;\r\n\t\tdrip.Speed = 0f;\r\n\t\tdrip.Phase = Rand( 0f, 10f );\r\n\t\tdrip.Still = 0f;\r\n\t\tdrip.Trail.Clear();\r\n\t\tdrip.LastTrail = SimPoint( tri, bary );\r\n\t\tdrip.Trail.Add( (tri, bary, Width( volume )) );\r\n\t}\r\n\r\n\tvoid AddSpot( int tri, Vector3 bary, float radius )\r\n\t{\r\n\t\tref var spot = ref _spots[_nextSpot];\r\n\t\t_nextSpot = (_nextSpot \u002B 1) % MaxSpots;\r\n\t\tspot.Alive = true;\r\n\t\tspot.Tri = tri;\r\n\t\tspot.Bary = bary;\r\n\t\tspot.Radius = radius;\r\n\t}\r\n\r\n\tvoid UpdateDrips( float dt )\r\n\t{\r\n\t\tvar sim = _face.Sim;\r\n\t\tvar gravity = _face.WorldDirectionToSim( Vector3.Down ).Normalized;\r\n\r\n\t\tforeach ( var d in _drips )\r\n\t\t{\r\n\t\t\tif ( !d.Alive ) continue;\r\n\r\n\t\t\tbool moving = d.Volume \u003E 0.08f \u0026\u0026 d.Trail.Count \u003C MaxTrail;\r\n\t\t\tif ( !moving )\r\n\t\t\t{\r\n\t\t\t\td.Still \u002B= dt;\r\n\t\t\t\tif ( StainLifetime \u003E 0f \u0026\u0026 d.Still \u003E StainLifetime \u002B FadeTime ) { d.Alive = false; d.Trail.Clear(); }\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tCorners( sim, d.Tri, out var a, out var b, out var c );\r\n\t\t\tvar n = Vec3.Cross( b - a, c - a ).Normalized;\r\n\t\t\tvar downhill = gravity - n * Vec3.Dot( gravity, n );\r\n\t\t\tfloat slope = downhill.Length;\r\n\t\t\tif ( slope \u003C 0.05f ) { d.Volume -= dt * 0.5f; continue; } // on a flat top: it just soaks in\r\n\t\t\tdownhill /= slope;\r\n\r\n\t\t\t// Thick drips run faster; a slow wobble keeps the path from being a ruler-straight line.\r\n\t\t\td.Phase \u002B= dt * 1.5f;\r\n\t\t\tvar side = Vec3.Cross( n, downhill );\r\n\t\t\tvar dir = (downhill \u002B side * (MathF.Sin( d.Phase ) * 0.12f)).Normalized;\r\n\t\t\tfloat target = DripSpeed * slope * (0.3f \u002B 0.7f * d.Volume);\r\n\t\t\td.Speed \u002B= (target - d.Speed) * MathF.Min( dt * 4f, 1f );\r\n\r\n\t\t\tfloat step = d.Speed * dt;\r\n\t\t\tvar p = SimPoint( d.Tri, d.Bary ) \u002B dir * step;\r\n\t\t\tWalk( d, p );\r\n\t\t\td.Volume -= step * Consumption;\r\n\r\n\t\t\t// Reached an overhang (under the chin, the jaw): the drop lets go and falls.\r\n\t\t\tif ( d.Volume \u003E 0.15f \u0026\u0026 Vector3.Dot( _face.SurfaceNormal( d.Tri, d.Bary ), Vector3.Down ) \u003E 0.55f )\r\n\t\t\t{\r\n\t\t\t\tRelease( d );\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tvar here = SimPoint( d.Tri, d.Bary );\r\n\t\t\tif ( (here - d.LastTrail).Length \u003E= TrailSpacing )\r\n\t\t\t{\r\n\t\t\t\td.LastTrail = here;\r\n\t\t\t\td.Trail.Add( (d.Tri, d.Bary, Width( d.Volume )) );\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EMoves a drip to (near) point p on the skin, crossing into neighbouring triangles as needed.\u003C/summary\u003E\r\n\tvoid Walk( Drip d, Vec3 p ) =\u003E Walk( ref d.Tri, ref d.Bary, p, 4 );\r\n\r\n\tvoid Walk( ref int tri, ref Vector3 bary, Vec3 p, int maxHops )\r\n\t{\r\n\t\tvar sim = _face.Sim;\r\n\t\tfor ( int hop = 0; hop \u003C maxHops; hop\u002B\u002B )\r\n\t\t{\r\n\t\t\tCorners( sim, tri, out var a, out var b, out var c );\r\n\t\t\tvar here = Barycentric( p, a, b, c );\r\n\t\t\tint k = here.x \u003C here.y ? (here.x \u003C here.z ? 0 : 2) : (here.y \u003C here.z ? 1 : 2);\r\n\t\t\tfloat min = k == 0 ? here.x : k == 1 ? here.y : here.z;\r\n\t\t\tif ( min \u003E= 0f ) { bary = here; return; }\r\n\r\n\t\t\tint next = _adjacent[tri * 3 \u002B k];\r\n\t\t\tif ( next \u003C 0 ) break;\r\n\t\t\ttri = next;\r\n\t\t}\r\n\r\n\t\t// Couldn\u0027t settle cleanly: clamp into the current triangle.\r\n\t\tCorners( sim, tri, out var a2, out var b2, out var c2 );\r\n\t\tvar clamped = Barycentric( p, a2, b2, c2 );\r\n\t\tclamped = new Vector3( MathF.Max( clamped.x, 0f ), MathF.Max( clamped.y, 0f ), MathF.Max( clamped.z, 0f ) );\r\n\t\tfloat sum = clamped.x \u002B clamped.y \u002B clamped.z;\r\n\t\tbary = sum \u003E 1e-5f ? clamped / sum : new Vector3( 1f / 3f );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EA random spot on the skin within \u003Cparamref name=\u0022worldRadius\u0022/\u003E of a point on it.\u003C/summary\u003E\r\n\t(int Tri, Vector3 Bary) Around( int tri, Vector3 bary, float worldRadius )\r\n\t{\r\n\t\tCorners( _face.Sim, tri, out var a, out var b, out var c );\r\n\t\tvar n = Vec3.Cross( b - a, c - a ).Normalized;\r\n\t\tvar u = (b - a).Normalized;\r\n\t\tvar v = Vec3.Cross( n, u );\r\n\t\tfloat angle = Rand( 0f, MathF.Tau );\r\n\t\tfloat r = MathF.Sqrt( Rand( 0f, 1f ) ) * worldRadius / _face.WorldScale.x;\r\n\t\tvar p = SimPoint( tri, bary ) \u002B (u * MathF.Cos( angle ) \u002B v * MathF.Sin( angle )) * r;\r\n\t\tWalk( ref tri, ref bary, p, 12 );\r\n\t\treturn (tri, bary);\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EA drip hanging off an overhang drops: its bead becomes a falling droplet and the trail stays.\u003C/summary\u003E\r\n\tvoid Release( Drip d )\r\n\t{\r\n\t\tref var drop = ref _droplets[_nextDroplet];\r\n\t\t_nextDroplet = (_nextDroplet \u002B 1) % MaxDroplets;\r\n\t\tdrop.Alive = true;\r\n\t\tdrop.Pos = _face.SurfacePoint( d.Tri, d.Bary ) \u002B Vector3.Down * 0.3f;\r\n\t\tdrop.Vel = Vector3.Down * 2f;\r\n\t\tdrop.Size = 0.12f \u002B 0.12f * d.Volume;\r\n\t\tdrop.Age = 0.05f;\r\n\t\td.Volume = 0.1f; // what\u0027s left dries where it hung\r\n\t\td.Size = 0.5f;\r\n\t}\r\n\r\n\tvoid UpdateDroplets( float dt )\r\n\t{\r\n\t\tvar center = _face.WorldPosition;\r\n\t\tfloat radius = _face.WorldScale.x * 1.15f;\r\n\t\tint traces = 0;\r\n\r\n\t\tfor ( int i = 0; i \u003C MaxDroplets; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tref var d = ref _droplets[i];\r\n\t\t\tif ( !d.Alive ) continue;\r\n\r\n\t\t\tvar from = d.Pos;\r\n\t\t\td.Vel \u002B= Vector3.Down * DropletGravity * dt;\r\n\t\t\td.Vel *= 1f - 0.6f * dt; // air drag\r\n\t\t\td.Pos \u002B= d.Vel * dt;\r\n\t\t\td.Age \u002B= dt;\r\n\t\t\tif ( d.Age \u003E 3f ) { d.Alive = false; continue; }\r\n\r\n\t\t\t// Landing back on the face: only near it, heading inwards, and within this frame\u0027s ray budget.\r\n\t\t\tif ( d.Age \u003C 0.05f || (d.Pos - center).Length \u003E radius ) continue;\r\n\t\t\tif ( Vector3.Dot( d.Vel, center - d.Pos ) \u003C= 0f ) continue;\r\n\t\t\tif ( traces \u003E= TracesPerFrame ) continue;\r\n\t\t\ttraces\u002B\u002B;\r\n\r\n\t\t\tvar travel = d.Pos - from;\r\n\t\t\tfloat length = travel.Length;\r\n\t\t\tif ( length \u003C 1e-4f ) continue;\r\n\t\t\tif ( !_face.TraceSurface( new Ray( from, travel / length ), out int tri, out var bary ) ) continue;\r\n\t\t\tif ( (_face.SurfacePoint( tri, bary ) - from).Length \u003E length \u002B 0.3f ) continue;\r\n\r\n\t\t\t// Big drops run; small ones just splat.\r\n\t\t\tif ( d.Size \u003E 0.16f ) AddDrip( tri, bary, Math.Clamp( d.Size * 1.6f, 0.15f, 0.4f ) );\r\n\t\t\telse AddSpot( tri, bary, d.Size * 2.2f );\r\n\t\t\td.Alive = false;\r\n\t\t}\r\n\t}\r\n\r\n\t// --- Rendering ---\r\n\r\n\tvoid BuildMesh()\r\n\t{\r\n\t\t_object = new GameObject( true, \u0022Blood\u0022 );\r\n\t\t_object.Flags |= GameObjectFlags.NotSaved | GameObjectFlags.NotNetworked;\r\n\t\t_object.NetworkMode = NetworkMode.Never;\r\n\r\n\t\tint dripVerts = MaxTrail * 2 \u002B BlobSides \u002B 1;\r\n\t\tint woundVerts = WoundSides \u002B 1;\r\n\t\tconst int dropletVerts = 6;\r\n\t\t_dripVerts = dripVerts;\r\n\t\t_woundVerts = woundVerts;\r\n\r\n\t\tvar indices = new List\u003Cint\u003E();\r\n\t\tint v = 0;\r\n\t\tfor ( int i = 0; i \u003C MaxDrips; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tfor ( int t = 0; t \u002B 1 \u003C MaxTrail; t\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tint l0 = v \u002B t * 2, r0 = l0 \u002B 1, l1 = l0 \u002B 2, r1 = l0 \u002B 3;\r\n\t\t\t\tindices.AddRange( new[] { l0, l1, r0, r0, l1, r1 } );\r\n\t\t\t}\r\n\t\t\tFan( indices, v \u002B MaxTrail * 2, BlobSides );\r\n\t\t\tv \u002B= dripVerts;\r\n\t\t}\r\n\t\tfor ( int i = 0; i \u003C MaxWounds; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tFan( indices, v, WoundSides );\r\n\t\t\tv \u002B= woundVerts;\r\n\t\t}\r\n\t\tfor ( int i = 0; i \u003C MaxSpots; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tFan( indices, v, SpotSides );\r\n\t\t\tv \u002B= SpotSides \u002B 1;\r\n\t\t}\r\n\t\tfor ( int i = 0; i \u003C MaxDroplets; i\u002B\u002B )\r\n\t\t{\r\n\t\t\t// Octahedron: 0/1 = ends, 2..5 = ring.\r\n\t\t\tfor ( int s = 0; s \u003C 4; s\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tint r0 = v \u002B 2 \u002B s, r1 = v \u002B 2 \u002B (s \u002B 1) % 4;\r\n\t\t\t\tindices.AddRange( new[] { v, r0, r1, v \u002B 1, r1, r0 } );\r\n\t\t\t}\r\n\t\t\tv \u002B= dropletVerts;\r\n\t\t}\r\n\r\n\t\t_verts = new Vertex[v];\r\n\t\t_mesh = new Mesh( Material ?? Material.Load( \u0022materials/squishy_blood.vmat\u0022 ) );\r\n\t\t_mesh.CreateVertexBuffer( v, Vertex.Layout, new List\u003CVertex\u003E( _verts ) );\r\n\t\t_mesh.CreateIndexBuffer( indices.Count, indices );\r\n\t\t_mesh.Bounds = BBox.FromPositionAndSize( Vector3.Zero, 100000f );\r\n\r\n\t\t_renderer = _object.Components.Create\u003CModelRenderer\u003E();\r\n\t\t_renderer.Model = Model.Builder.AddMesh( _mesh ).Create();\r\n\t\t_renderer.Tint = Color;\r\n\t\t_renderer.RenderType = ModelRenderer.ShadowRenderType.Off;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003ETriangle fan: centre vertex first, then the rim.\u003C/summary\u003E\r\n\tstatic void Fan( List\u003Cint\u003E indices, int start, int sides )\r\n\t{\r\n\t\tfor ( int s = 0; s \u003C sides; s\u002B\u002B )\r\n\t\t\tindices.AddRange( new[] { start, start \u002B 1 \u002B (s \u002B 1) % sides, start \u002B 1 \u002B s } );\r\n\t}\r\n\r\n\tvoid Render()\r\n\t{\r\n\t\tArray.Clear( _verts );\r\n\t\tint v = 0;\r\n\r\n\t\tforeach ( var d in _drips )\r\n\t\t{\r\n\t\t\tif ( d.Alive \u0026\u0026 d.Trail.Count \u003E 0 ) WriteDrip( d, v );\r\n\t\t\tv \u002B= _dripVerts;\r\n\t\t}\r\n\t\tforeach ( var w in _wounds )\r\n\t\t{\r\n\t\t\tif ( w.Alive )\r\n\t\t\t{\r\n\t\t\t\tfloat fade = StainLifetime \u003E 0f ? 1f - Math.Clamp( (w.Closed - StainLifetime) / FadeTime, 0f, 1f ) : 1f;\r\n\t\t\t\tWriteBlob( v, w.Tri, w.Bary, w.Radius * fade, WoundSides, 0.08f );\r\n\t\t\t}\r\n\t\t\tv \u002B= _woundVerts;\r\n\t\t}\r\n\t\tfor ( int i = 0; i \u003C MaxSpots; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tif ( _spots[i].Alive ) WriteBlob( v, _spots[i].Tri, _spots[i].Bary, _spots[i].Radius, SpotSides, 0.04f );\r\n\t\t\tv \u002B= SpotSides \u002B 1;\r\n\t\t}\r\n\t\tfor ( int i = 0; i \u003C MaxDroplets; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tif ( _droplets[i].Alive ) WriteDroplet( v, _droplets[i] );\r\n\t\t\tv \u002B= 6;\r\n\t\t}\r\n\r\n\t\t_mesh.SetVertexBufferData( _verts.AsSpan(), 0 );\r\n\t\t_renderer.Tint = Color;\r\n\t\t_object.WorldPosition = Vector3.Zero;\r\n\t\t_object.WorldRotation = Rotation.Identity;\r\n\t}\r\n\r\n\tvoid WriteDrip( Drip d, int start )\r\n\t{\r\n\t\tfloat fade = StainLifetime \u003E 0f ? 1f - Math.Clamp( (d.Still - StainLifetime) / FadeTime, 0f, 1f ) : 1f;\r\n\t\tint count = d.Trail.Count;\r\n\r\n\t\tfor ( int t = 0; t \u003C count; t\u002B\u002B )\r\n\t\t{\r\n\t\t\tvar (tri, bary, width) = d.Trail[t];\r\n\t\t\tvar n = _face.SurfaceNormal( tri, bary );\r\n\t\t\tvar c = _face.SurfacePoint( tri, bary ) \u002B n * SurfaceLift;\r\n\r\n\t\t\t// Direction along the trail (towards the next point, or from the previous at the end).\r\n\t\t\tvar (ntri, nbary, _) = d.Trail[Math.Min( t \u002B 1, count - 1 )];\r\n\t\t\tvar (ptri, pbary, _) = d.Trail[Math.Max( t - 1, 0 )];\r\n\t\t\tvar along = _face.SurfacePoint( ntri, nbary ) - _face.SurfacePoint( ptri, pbary );\r\n\t\t\tif ( along.Length \u003C 1e-4f ) along = Vector3.Down;\r\n\t\t\tvar side = Vector3.Cross( n, along ).Normal;\r\n\r\n\t\t\t// The trail tapers to nothing at its start and fattens towards the drop.\r\n\t\t\tfloat taper = MathF.Min( t / 3f, 1f );\r\n\t\t\tfloat half = width * 0.5f * taper * fade;\r\n\t\t\t// Normals tilted outwards at the edges read as a rounded, wet bead under the light.\r\n\t\t\t_verts[start \u002B t * 2] = new Vertex( c - side * half, (n - side * 0.7f).Normal, along.Normal, Vector4.Zero );\r\n\t\t\t_verts[start \u002B t * 2 \u002B 1] = new Vertex( c \u002B side * half, (n \u002B side * 0.7f).Normal, along.Normal, Vector4.Zero );\r\n\t\t}\r\n\r\n\t\t// Collapse the unused trail slots onto the last point so they draw nothing.\r\n\t\tfor ( int t = count; t \u003C MaxTrail; t\u002B\u002B )\r\n\t\t{\r\n\t\t\t_verts[start \u002B t * 2] = _verts[start \u002B (count - 1) * 2];\r\n\t\t\t_verts[start \u002B t * 2 \u002B 1] = _verts[start \u002B (count - 1) * 2];\r\n\t\t}\r\n\r\n\t\t// The drop at the head: a little dome, bigger while it still has blood to give.\r\n\t\tfloat radius = (d.Volume \u003E 0.08f ? 0.22f \u002B 0.28f * d.Volume : 0.18f) * fade * MathF.Max( d.Size, 0.5f );\r\n\t\tWriteBlob( start \u002B MaxTrail * 2, d.Tri, d.Bary, radius, BlobSides, 0.12f );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EA domed disc on the skin (a drop, or a wound\u0027s stain).\u003C/summary\u003E\r\n\tvoid WriteBlob( int start, int tri, Vector3 bary, float radius, int sides, float dome )\r\n\t{\r\n\t\tif ( radius \u003C= 0.001f ) return;\r\n\t\tvar n = _face.SurfaceNormal( tri, bary );\r\n\t\tvar c = _face.SurfacePoint( tri, bary ) \u002B n * SurfaceLift;\r\n\t\tvar u = Vector3.Cross( n, MathF.Abs( n.z ) \u003C 0.9f ? Vector3.Up : Vector3.Forward ).Normal;\r\n\t\tvar w = Vector3.Cross( n, u );\r\n\r\n\t\t_verts[start] = new Vertex( c \u002B n * dome, n, u, Vector4.Zero );\r\n\t\tfor ( int s = 0; s \u003C sides; s\u002B\u002B )\r\n\t\t{\r\n\t\t\tfloat a = s * MathF.Tau / sides;\r\n\t\t\t// A slightly uneven rim, fixed per spot, so stains aren\u0027t perfect circles.\r\n\t\t\tfloat wobble = 1f \u002B 0.18f * MathF.Sin( a * 3f \u002B tri ) \u002B 0.1f * MathF.Sin( a * 5f \u002B tri * 0.7f );\r\n\t\t\tvar rim = (u * MathF.Cos( a ) \u002B w * MathF.Sin( a )) * radius * wobble;\r\n\t\t\t_verts[start \u002B 1 \u002B s] = new Vertex( c \u002B rim, (n \u002B rim.Normal * 0.6f).Normal, u, Vector4.Zero );\r\n\t\t}\r\n\t}\r\n\r\n\tvoid WriteDroplet( int start, in Droplet d )\r\n\t{\r\n\t\tfloat speed = d.Vel.Length;\r\n\t\tvar axis = speed \u003E 1e-3f ? d.Vel / speed : Vector3.Down;\r\n\t\tfloat half = d.Size \u002B speed * 0.008f; // stretched along its motion\r\n\t\tvar u = Vector3.Cross( axis, MathF.Abs( axis.z ) \u003C 0.9f ? Vector3.Up : Vector3.Forward ).Normal;\r\n\t\tvar w = Vector3.Cross( axis, u );\r\n\r\n\t\t_verts[start] = new Vertex( d.Pos \u002B axis * half, axis, u, Vector4.Zero );\r\n\t\t_verts[start \u002B 1] = new Vertex( d.Pos - axis * half, -axis, u, Vector4.Zero );\r\n\t\t_verts[start \u002B 2] = new Vertex( d.Pos \u002B u * d.Size, u, axis, Vector4.Zero );\r\n\t\t_verts[start \u002B 3] = new Vertex( d.Pos \u002B w * d.Size, w, axis, Vector4.Zero );\r\n\t\t_verts[start \u002B 4] = new Vertex( d.Pos - u * d.Size, -u, axis, Vector4.Zero );\r\n\t\t_verts[start \u002B 5] = new Vertex( d.Pos - w * d.Size, -w, axis, Vector4.Zero );\r\n\t}\r\n\r\n\t// --- Helpers ---\r\n\r\n\tvoid BuildAdjacency( int[] indices )\r\n\t{\r\n\t\tint tris = indices.Length / 3;\r\n\t\t_adjacent = new int[tris * 3];\r\n\t\tArray.Fill( _adjacent, -1 );\r\n\t\tvar edges = new Dictionary\u003Clong, int\u003E();\r\n\t\tfor ( int t = 0; t \u003C tris; t\u002B\u002B )\r\n\t\t{\r\n\t\t\tfor ( int k = 0; k \u003C 3; k\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tint a = indices[t * 3 \u002B (k \u002B 1) % 3], b = indices[t * 3 \u002B (k \u002B 2) % 3];\r\n\t\t\t\tlong key = (long)Math.Min( a, b ) \u003C\u003C 32 | (uint)Math.Max( a, b );\r\n\t\t\t\tif ( edges.TryGetValue( key, out int other ) )\r\n\t\t\t\t{\r\n\t\t\t\t\t_adjacent[t * 3 \u002B k] = other / 3;\r\n\t\t\t\t\t_adjacent[other] = t;\r\n\t\t\t\t}\r\n\t\t\t\telse edges[key] = t * 3 \u002B k;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstatic void Corners( Face sim, int tri, out Vec3 a, out Vec3 b, out Vec3 c )\r\n\t{\r\n\t\ta = sim.Pos[sim.Indices[tri * 3]];\r\n\t\tb = sim.Pos[sim.Indices[tri * 3 \u002B 1]];\r\n\t\tc = sim.Pos[sim.Indices[tri * 3 \u002B 2]];\r\n\t}\r\n\r\n\tVec3 SimPoint( int tri, Vector3 bary )\r\n\t{\r\n\t\tCorners( _face.Sim, tri, out var a, out var b, out var c );\r\n\t\treturn a * bary.x \u002B b * bary.y \u002B c * bary.z;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EBarycentric coordinates of p projected onto triangle abc.\u003C/summary\u003E\r\n\tstatic Vector3 Barycentric( Vec3 p, Vec3 a, Vec3 b, Vec3 c )\r\n\t{\r\n\t\tvar v0 = b - a;\r\n\t\tvar v1 = c - a;\r\n\t\tvar v2 = p - a;\r\n\t\tfloat d00 = Vec3.Dot( v0, v0 ), d01 = Vec3.Dot( v0, v1 ), d11 = Vec3.Dot( v1, v1 );\r\n\t\tfloat d20 = Vec3.Dot( v2, v0 ), d21 = Vec3.Dot( v2, v1 );\r\n\t\tfloat denom = d00 * d11 - d01 * d01;\r\n\t\tif ( MathF.Abs( denom ) \u003C 1e-12f ) return new Vector3( 1f / 3f );\r\n\t\tfloat y = (d11 * d20 - d01 * d21) / denom;\r\n\t\tfloat z = (d00 * d21 - d01 * d20) / denom;\r\n\t\treturn new Vector3( 1f - y - z, y, z );\r\n\t}\r\n\r\n\tfloat Width( float volume ) =\u003E DripWidth * (0.35f \u002B 0.65f * MathF.Sqrt( Math.Clamp( volume, 0f, 1f ) ));\r\n\r\n\tfloat Rand( float min, float max ) =\u003E min \u002B (float)_random.NextDouble() * (max - min);\r\n}\r\n"},{"Ident":"chomnr.squishy_terry","Path":"Scoring/WrinkleMeter.cs","FileName":"WrinkleMeter.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\nusing System.Collections.Generic;\nusing SquishyTerry.Sim;\n\nnamespace SquishyTerry.Scoring;\n\n/// \u003Csummary\u003E\n/// Measures how wrinkled the face is right now, on the CPU.\n/// \u003Cpara\u003E\n/// The visible wrinkles are the GPU skin cloth buckling where the surface underneath is squeezed.\n/// Reading that back from the GPU would stall the game, so this measures the cause instead: every\n/// mesh edge that is shorter than at rest (compressed) adds its compression, weighted by the face\u0027s\n/// wrinkle mask (no wrinkles on the eyes, nose, mouth and hair patches, same as the skin).\n/// \u003C/para\u003E\n/// Engine-agnostic, so the test harness can calibrate it.\n/// \u003C/summary\u003E\npublic sealed class WrinkleMeter\n{\n\t/// \u003Csummary\u003ECompression below this is ignored (resting noise, not a wrinkle).\u003C/summary\u003E\n\tpublic float Threshold = 0.03f;\n\n\t/// \u003Csummary\u003EScales the raw sum to a friendly \u0022wrinkle count\u0022.\u003C/summary\u003E\n\tpublic float Scale = 1f;\n\n\treadonly int[] _a, _b;\n\treadonly float[] _rest, _weight;\n\n\tpublic WrinkleMeter( int[] indices, Vec3[] restPositions, float[] wrinkleMask )\n\t{\n\t\tvar seen = new HashSet\u003Clong\u003E();\n\t\tvar a = new List\u003Cint\u003E();\n\t\tvar b = new List\u003Cint\u003E();\n\t\tfor ( int t = 0; t \u002B 2 \u003C indices.Length; t \u002B= 3 )\n\t\t{\n\t\t\tfor ( int e = 0; e \u003C 3; e\u002B\u002B )\n\t\t\t{\n\t\t\t\tint i = indices[t \u002B e], j = indices[t \u002B (e \u002B 1) % 3];\n\t\t\t\tint lo = Math.Min( i, j ), hi = Math.Max( i, j );\n\t\t\t\tif ( seen.Add( ((long)lo \u003C\u003C 32) | (uint)hi ) )\n\t\t\t\t{\n\t\t\t\t\ta.Add( lo );\n\t\t\t\t\tb.Add( hi );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t_a = a.ToArray();\n\t\t_b = b.ToArray();\n\t\t_rest = new float[_a.Length];\n\t\t_weight = new float[_a.Length];\n\t\tfor ( int k = 0; k \u003C _a.Length; k\u002B\u002B )\n\t\t{\n\t\t\t_rest[k] = (restPositions[_a[k]] - restPositions[_b[k]]).Length;\n\t\t\t_weight[k] = wrinkleMask is null ? 1f : MathF.Min( wrinkleMask[_a[k]], wrinkleMask[_b[k]] );\n\t\t}\n\t}\n\n\t/// \u003Csummary\u003ECurrent wrinkle amount for these positions.\u003C/summary\u003E\n\tpublic float Measure( Vec3[] positions )\n\t{\n\t\tfloat sum = 0f;\n\t\tfor ( int k = 0; k \u003C _a.Length; k\u002B\u002B )\n\t\t{\n\t\t\tfloat w = _weight[k];\n\t\t\tif ( w \u003C= 0f || _rest[k] \u003C= 0f ) continue;\n\t\t\tfloat compression = 1f - (positions[_a[k]] - positions[_b[k]]).Length / _rest[k];\n\t\t\tif ( compression \u003E Threshold ) sum \u002B= w * (compression - Threshold);\n\t\t}\n\t\treturn sum * Scale;\n\t}\n}\n"},{"Ident":"chomnr.squishy_terry","Path":"Assembly.cs","FileName":"Assembly.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"global using Sandbox;\r\nglobal using System.Collections.Generic;\r\nglobal using System.Linq;\r\n"},{"Ident":"chomnr.squishy_terry","Path":"Fatality/KnifeDrop.cs","FileName":"KnifeDrop.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing SquishyTerry.Scoring;\r\n\r\nnamespace SquishyTerry;\r\n\r\n/// \u003Csummary\u003E\r\n/// Fatality, part one: when the combo reaches \u003Csee cref=\u0022TriggerCombo\u0022/\u003E, a knife on a string drops in\r\n/// from the top of the screen and swings until it settles, dangling in front of Terry. When the combo\r\n/// ends it\u0027s hauled back up out of view.\r\n/// \u003Cpara\u003E\r\n/// The knife can be grabbed (left click) and dragged. Yank it hard enough away from where the string\r\n/// hangs from and the string snaps off at the top: the knife is yours, string still attached, and stays\r\n/// in your hand even after the combo ends. Let go of a snapped knife and it falls away and is removed\r\n/// \u003Csee cref=\u0022LooseLifetime\u0022/\u003E seconds later. If the combo ends before the string snaps, the knife is\r\n/// pulled out of your hand and hauled back up.\r\n/// \u003C/para\u003E\r\n/// \u003Cpara\u003E\r\n/// Once the string has snapped, drag the tip onto Terry and it sticks in. Keep pushing (in the direction the knife points) to drive\r\n/// it deeper, up to the guard; pull back to draw it out. Let go and it stays stuck, riding along with\r\n/// the skin as the face squishes, until you grab it and pull it out.\r\n/// \u003C/para\u003E\r\n/// \u003Cpara\u003E\r\n/// The string and knife are simulated the same way as the face: position-based dynamics. Each step\r\n/// predicts every point from its velocity and gravity, then repeatedly enforces distance constraints\r\n/// (rope links, and the knife as a rigid two-point bar hanging off the end), and derives the new\r\n/// velocities from how far the points moved. It runs in fixed sub-steps, and at slow-motion speed.\r\n/// \u003C/para\u003E\r\n/// Everything is placed relative to the camera, so the string always hangs from just above the top\r\n/// edge of the view.\r\n/// \u003C/summary\u003E\r\npublic sealed class KnifeDrop : Component\r\n{\r\n\t/// \u003Csummary\u003ECombo that drops the knife.\u003C/summary\u003E\r\n\t[Property] public int TriggerCombo { get; set; } = ScoreKeeper.FatalityCombo;\r\n\r\n\t/// \u003Csummary\u003EEditor testing: drop the knife now (untick to haul it back up).\u003C/summary\u003E\r\n\t[Property] public bool Preview { get; set; }\r\n\r\n\t/// \u003Csummary\u003EHow far in front of the camera the string hangs (world units; the face is ~11 away).\u003C/summary\u003E\r\n\t[Property] public float Depth { get; set; } = 9f;\r\n\r\n\t/// \u003Csummary\u003ESideways offset of the anchor from the centre of the view (world units, \u002B = right).\u003C/summary\u003E\r\n\t[Property] public float Sideways { get; set; } = 6f;\r\n\r\n\t/// \u003Csummary\u003ELength of the string (world units).\u003C/summary\u003E\r\n\t[Property] public float RopeLength { get; set; } = 9f;\r\n\r\n\t/// \u003Csummary\u003EGravity (world units / s\u00B2).\u003C/summary\u003E\r\n\t[Property] public float Gravity { get; set; } = 70f;\r\n\r\n\t/// \u003Csummary\u003EHow far past the string\u0027s reach the knife has to be pulled to snap it (world units).\u003C/summary\u003E\r\n\t[Property] public float BreakStretch { get; set; } = 2.5f;\r\n\r\n\t/// \u003Csummary\u003EHow fast that pull has to be going to count as a yank (world units / s).\u003C/summary\u003E\r\n\t[Property] public float BreakSpeed { get; set; } = 20f;\r\n\r\n\t/// \u003Csummary\u003EPulled this far past the reach, it snaps however slowly (world units).\u003C/summary\u003E\r\n\t[Property] public float BreakStretchAlways { get; set; } = 6f;\r\n\r\n\t/// \u003Csummary\u003ESeconds a snapped knife lingers after being let go before it\u0027s removed.\u003C/summary\u003E\r\n\t[Property] public float LooseLifetime { get; set; } = 5f;\r\n\r\n\t/// \u003Csummary\u003EThe player is holding the knife.\u003C/summary\u003E\r\n\tpublic bool Held =\u003E _held;\r\n\r\n\tconst int Links = 18;             // rope segments\r\n\tconst float KnifeLength = 5f;     // pommel to tip\r\n\tconst float StepTime = 1f / 120f; // fixed physics sub-step\r\n\tconst int Iterations = 12;        // constraint passes per step\r\n\tconst float Damping = 0.995f;\r\n\tconst float RetractSpeed = 40f;   // units / s the anchor is hauled up when the combo ends\r\n\tconst float RopeThickness = 0.14f;\r\n\tconst float BladeStart = 1.8f;    // guard end of the blade (from the pommel)\r\n\tconst float MaxDepth = KnifeLength - BladeStart; // all the way in, up to the guard\r\n\tconst float StabTilt = 0.6f;      // how steeply a stab turns into the skin (vs. the way it was held)\r\n\tconst float SpurtEvery = 0.6f;\r\n\tconst float MotionScale = 150f;   // face speed (simulation units / frame) that counts as squishing hard, inverted\r\n\tconst float FinishHold = 2.5f;    // seconds of the fatality (X eyes, slow motion) before everything resets    // pushing this much deeper throws a fresh spurt of blood\r\n\tconst float StabBlendTime = 0.08f;\r\n\tconst float GrabRadius = 0.8f;     // how close to the knife a click has to be\r\n\tconst float GrabStiffness = 0.35f; // per constraint pass: the hand wins, but the string still tugs back\r\n\r\n\t// Points 0..Links are the rope (0 = anchor); Links is also the knife\u0027s pommel; Links \u002B 1 is its tip.\r\n\tVector3[] _pos, _prev;\r\n\tfloat[] _invMass;\r\n\tfloat _linkLength;\r\n\tfloat _stepAcc;\r\n\r\n\tbool _active;      // simulating and visible\r\n\tbool _retracting;\r\n\tbool _loose;       // the string snapped off at the top\r\n\tfloat _looseTimer; // seconds since a snapped knife was let go\r\n\r\n\tbool _held;\r\n\tfloat _grabAlong;  // 0 = pommel, 1 = tip\r\n\tfloat _grabDepth;  // distance along the camera\u0027s forward of the grabbed point\r\n\tVector3 _grabTarget;\r\n\tfloat _prevExcess;\r\n\r\n\t// Stuck in the face.\r\n\tSquishyFace _face;\r\n\tbool _stuck;\r\n\tbool _mustLeave;        // pulled out: the tip has to leave the face before it can stick again\r\n\tint _stuckTri;\r\n\tVector3 _stuckBary;     // entry point on the skin\r\n\tVector3 _stuckDirHead;  // knife direction, in the head\u0027s frame (turns with the head)\r\n\tVector3 _pushAxis;      // on-screen direction that pushes it deeper\r\n\tfloat _stuckDepth;      // how far the tip is in\r\n\tfloat _pushBase;\r\n\tfloat _stuckBlend;\r\n\tVector3 _fromPommel, _fromTip, _stuckPommel, _stuckTip;\r\n\r\n\t// The skin is farther from the camera than the plane the knife hangs in, so a stuck knife is scaled\r\n\t// up by the depth ratio to keep the size it had on screen (instead of looking tiny).\r\n\tfloat _stuckScale = 1f;\r\n\tfloat _visualScale = 1f;\r\n\r\n\tBlood _blood;\r\n\tint _wound = -1;\r\n\tfloat _lastSpurtDepth;\r\n\tfloat _bloodied;   // 0..1 how much of the blade has been in\r\n\tModelRenderer _blade;\r\n\r\n\tStageHook _hook;\r\n\tbool _finishing;\r\n\tfloat _finishTimer;\r\n\tfloat _lift;       // how far the anchor has been hauled up\r\n\tint _prevCombo;\r\n\tScoreKeeper _keeper;\r\n\r\n\tGameObject _root, _knife;\r\n\treadonly List\u003CGameObject\u003E _ropeSegments = new();\r\n\r\n\t// --- Lifecycle ---\r\n\r\n\tprotected override void OnEnabled()\r\n\t{\r\n\t\tBuildVisuals();\r\n\t\t_root.Enabled = false;\r\n\t}\r\n\r\n\tprotected override void OnDisabled()\r\n\t{\r\n\t\tif ( _keeper is not null ) _keeper.SquishLanded -= OnSquishLanded;\r\n\t\t_keeper = null;\r\n\t\t_root?.Destroy();\r\n\t\t_root = null;\r\n\t\t_ropeSegments.Clear();\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tif ( _keeper is null )\r\n\t\t{\r\n\t\t\t_keeper = Scene.GetAllComponents\u003CScoreKeeper\u003E().FirstOrDefault();\r\n\t\t\tif ( _keeper is not null ) _keeper.SquishLanded \u002B= OnSquishLanded;\r\n\t\t}\r\n\t\t_face ??= Components.Get\u003CSquishyFace\u003E();\r\n\t\t_blood ??= Components.Get\u003CBlood\u003E();\r\n\t\t_hook ??= Components.Get\u003CStageHook\u003E();\r\n\t\tvar camera = Scene.Camera;\r\n\t\tif ( camera is null ) return;\r\n\r\n\t\t// Drop when the combo reaches the trigger (or the preview box is ticked).\r\n\t\tint combo = _keeper?.Combo ?? 0;\r\n\t\tbool trigger = combo \u003E= TriggerCombo \u0026\u0026 _prevCombo \u003C TriggerCombo;\r\n\t\tif ( trigger \u0026\u0026 (!_active || _loose \u0026\u0026 !_held) || Preview \u0026\u0026 !_active ) Drop( camera );\r\n\t\t_prevCombo = combo;\r\n\r\n\t\tUpdateBleeding();\r\n\t\tif ( !_active ) return;\r\n\r\n\t\t// The fatality plays out (the stage hook drags him off, if there is one), then everything resets.\r\n\t\tif ( _finishing \u0026\u0026 _hook is null \u0026\u0026 (_finishTimer \u002B= RealTime.Delta) \u003E= FinishHold )\r\n\t\t{\r\n\t\t\tEndFatality();\r\n\t\t\tif ( _face is not null ) _face.InputLocked = false;\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t// The combo ended with the string still attached: it\u0027s pulled out of your hand and hauled up.\r\n\t\tif ( !_loose \u0026\u0026 !_retracting \u0026\u0026 !Preview \u0026\u0026 combo == 0 )\r\n\t\t{\r\n\t\t\tif ( _stuck ) Unstick( camera );\r\n\t\t\t_retracting = true;\r\n\t\t\t_held = false;\r\n\t\t}\r\n\r\n\t\tif ( _held )\r\n\t\t{\r\n\t\t\tif ( Input.Down( \u0022Attack1\u0022 ) ) _grabTarget = MouseTarget( camera );\r\n\t\t\telse _held = false;\r\n\t\t}\r\n\r\n\t\tif ( _stuck ) UpdateStuck( camera );\r\n\t\telse if ( _held \u0026\u0026 _loose ) TryStick( camera ); // only once the string has snapped\r\n\r\n\t\tif ( _retracting )\r\n\t\t{\r\n\t\t\t_lift \u002B= RetractSpeed * RealTime.Delta;\r\n\t\t\t// Gone once the knife is well above the top of the view.\r\n\t\t\tif ( _lift \u003E RopeLength \u002B KnifeLength \u002B 12f ) { Hide(); return; }\r\n\t\t}\r\n\r\n\t\t// A snapped knife that\u0027s been let go falls away and is removed a few seconds later.\r\n\t\tif ( _loose \u0026\u0026 !_held \u0026\u0026 !_stuck )\r\n\t\t{\r\n\t\t\t_looseTimer \u002B= RealTime.Delta;\r\n\t\t\tif ( _looseTimer \u003E= LooseLifetime ) { Hide(); return; }\r\n\t\t}\r\n\t\telse _looseTimer = 0f;\r\n\r\n\t\t// Fixed sub-steps, at slow-motion speed.\r\n\t\t_stepAcc \u002B= Time.Delta * SlowMo.Scale;\r\n\t\tint steps = 0;\r\n\t\twhile ( _stepAcc \u003E= StepTime \u0026\u0026 steps \u003C 8 )\r\n\t\t{\r\n\t\t\tStep( camera );\r\n\t\t\t_stepAcc -= StepTime;\r\n\t\t\tsteps\u002B\u002B;\r\n\t\t}\r\n\t\tif ( steps == 8 ) _stepAcc = 0f;\r\n\r\n\t\tif ( _held \u0026\u0026 !_loose \u0026\u0026 !_stuck ) CheckSnap( camera );\r\n\r\n\t\tUpdateVisuals( camera );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003ESquishing him while he bleeds makes every wound spurt.\u003C/summary\u003E\r\n\tvoid OnSquishLanded()\r\n\t{\r\n\t\tif ( _blood is not null \u0026\u0026 _blood.BleedingWounds \u003E 0 ) _blood.PumpAll( 5 );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EHow hard the face is moving (0 still .. 1 being squished hard): bleeding is pumped by it.\u003C/summary\u003E\r\n\tfloat FaceMotion()\r\n\t{\r\n\t\tif ( _face?.Sim is null ) return 0f;\r\n\t\tfloat motion = Math.Clamp( _face.Sim.ComputeAverageSpeed() * MotionScale, 0f, 1f );\r\n\t\treturn _face.IsDragging ? MathF.Max( motion, 0.5f ) : motion;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EBleeding this frame: pumps the drips and feeds the blood score.\u003C/summary\u003E\r\n\tvoid UpdateBleeding()\r\n\t{\r\n\t\tif ( _blood is null ) return;\r\n\t\tfloat motion = FaceMotion();\r\n\t\t_blood.Pump = 1f \u002B BloodTally.MotionBoost * motion;\r\n\t\tif ( _keeper is not null \u0026\u0026 _keeper.Bleeding \u0026\u0026 !_finishing )\r\n\t\t\t_keeper.BloodTick( RealTime.Delta, _blood.BleedingWounds, _stuck ? _stuckDepth / MaxDepth : 0f, motion );\r\n\t}\r\n\r\n\tvoid Hide()\r\n\t{\r\n\t\t_keeper?.EndBloodRun(); // the knife went away without a fatality: the bleeding scores as it stands\r\n\t\t_active = false;\r\n\t\t_retracting = false;\r\n\t\t_loose = false;\r\n\t\t_held = false;\r\n\t\t_stuck = false;\r\n\t\t_finishing = false;\r\n\t\t_root.Enabled = false;\r\n\t}\r\n\r\n\t// --- Stabbing ---\r\n\r\n\t/// \u003Csummary\u003EWhile held: if the tip is over Terry, it sticks into the skin under it.\u003C/summary\u003E\r\n\tvoid TryStick( CameraComponent camera )\r\n\t{\r\n\t\tif ( _face is null ) return;\r\n\r\n\t\tvar pommel = _pos[Links];\r\n\t\tvar tip = _pos[Links \u002B 1];\r\n\t\tvar eye = camera.WorldPosition;\r\n\t\tif ( !_face.TraceSurface( new Ray( eye, (tip - eye).Normal ), out int tri, out var bary ) )\r\n\t\t{\r\n\t\t\t_mustLeave = false;\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tif ( _mustLeave ) return;\r\n\r\n\t\t// The way the knife points on screen, turned into the skin.\r\n\t\tvar forward = camera.WorldRotation.Forward;\r\n\t\tvar along = (tip - pommel).Normal;\r\n\t\tvar axis = along - forward * Vector3.Dot( along, forward );\r\n\t\taxis = axis.Length \u003E 0.1f ? axis.Normal : camera.WorldRotation.Down;\r\n\t\tvar dir = (axis - _face.SurfaceNormal( tri, bary ) * StabTilt).Normal;\r\n\r\n\t\tvar eyeForward = camera.WorldRotation.Forward;\r\n\t\tfloat heldDepth = MathF.Max( Vector3.Dot( tip - eye, eyeForward ), 0.1f );\r\n\t\tfloat skinDepth = Vector3.Dot( _face.SurfacePoint( tri, bary ) - eye, eyeForward );\r\n\t\t_stuckScale = Math.Clamp( skinDepth / heldDepth, 0.5f, 3f );\r\n\r\n\t\t_stuck = true;\r\n\t\t_stuckTri = tri;\r\n\t\t_stuckBary = bary;\r\n\t\t_stuckDirHead = _face.DirectionToHead( dir );\r\n\t\t_pushAxis = axis;\r\n\t\t_stuckDepth = 0.2f;\r\n\t\t_pushBase = _stuckDepth - Vector3.Dot( _grabTarget, _pushAxis );\r\n\t\t_stuckBlend = 0f;\r\n\t\t_fromPommel = pommel;\r\n\t\t_fromTip = tip;\r\n\t\t_invMass[Links] = 0f;\r\n\t\t_invMass[Links \u002B 1] = 0f;\r\n\r\n\t\t_lastSpurtDepth = _stuckDepth;\r\n\t\t_keeper?.BloodStab();\r\n\t\tif ( _blood is not null )\r\n\t\t{\r\n\t\t\t_wound = _blood.OpenWound( tri, bary );\r\n\t\t\t_blood.Spurt( _wound, -dir, 14 );\r\n\t\t}\r\n\t\tUpdateStuck( camera );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EPlaces a stuck knife on its entry point; pushing and pulling (while held) moves it in and out.\u003C/summary\u003E\r\n\tvoid UpdateStuck( CameraComponent camera )\r\n\t{\r\n\t\tvar dir = _face.DirectionFromHead( _stuckDirHead ).Normal;\r\n\t\tif ( _held )\r\n\t\t{\r\n\t\t\tfloat push = Vector3.Dot( _grabTarget, _pushAxis );\r\n\t\t\t_stuckDepth = MathF.Min( _pushBase \u002B push, MaxDepth );\r\n\t\t\tif ( _stuckDepth \u003C 0f ) { Unstick( camera ); return; }\r\n\t\t\t_pushBase = _stuckDepth - push; // pulling back responds at once, even after pushing past the guard\r\n\r\n\t\t\t// Driving it deeper makes it bleed harder.\r\n\t\t\tif ( _stuckDepth - _lastSpurtDepth \u003E SpurtEvery )\r\n\t\t\t{\r\n\t\t\t\t_lastSpurtDepth = _stuckDepth;\r\n\t\t\t\t_blood?.Spurt( _wound, -dir, 6, 0.8f );\r\n\t\t\t}\r\n\t\t\t_lastSpurtDepth = MathF.Min( _lastSpurtDepth, _stuckDepth );\r\n\t\t\t_bloodied = MathF.Max( _bloodied, _stuckDepth / MaxDepth );\r\n\r\n\t\t\t// All the way in, up to the guard: fatality.\r\n\t\t\tif ( _stuckDepth \u003E= MaxDepth - 0.05f \u0026\u0026 !_finishing ) Fatality( dir );\r\n\t\t}\r\n\r\n\t\tvar entry = _face.SurfacePoint( _stuckTri, _stuckBary );\r\n\t\t_stuckTip = entry \u002B dir * (_stuckDepth * _stuckScale);\r\n\t\t_stuckPommel = _stuckTip - dir * (KnifeLength * _stuckScale);\r\n\r\n\t\t// Ease in from where it was held, so it doesn\u0027t pop.\r\n\t\t_stuckBlend = MathF.Min( _stuckBlend \u002B RealTime.Delta / StabBlendTime, 1f );\r\n\t\tif ( _stuckBlend \u003C 1f )\r\n\t\t{\r\n\t\t\t_stuckTip = Vector3.Lerp( _fromTip, _stuckTip, _stuckBlend );\r\n\t\t\t_stuckPommel = Vector3.Lerp( _fromPommel, _stuckPommel, _stuckBlend );\r\n\t\t}\r\n\t\t_visualScale = 1f \u002B (_stuckScale - 1f) * _stuckBlend;\r\n\t\tPinKnife();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003ELights out: X eyes, a last gush, slow motion, and it counts on the leaderboard.\u003C/summary\u003E\r\n\tvoid Fatality( Vector3 dir )\r\n\t{\r\n\t\t_finishing = true;\r\n\t\t_finishTimer = 0f;\r\n\t\t_held = false;\r\n\t\tif ( _face is not null )\r\n\t\t{\r\n\t\t\t_face.XEyes = true;\r\n\t\t\t_face.InputLocked = true; // he\u0027s done: no more stretching or squishing\r\n\t\t}\r\n\t\t_blood?.Spurt( _wound, -dir, 24, 1.3f );\r\n\t\tSlowMo.Trigger();\r\n\t\t_keeper?.RecordFatality();\r\n\t\t_hook?.Begin();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EClears the fatality away: knife, blood and X eyes (a fresh Terry is coming).\u003C/summary\u003E\r\n\tpublic void EndFatality()\r\n\t{\r\n\t\tHide();\r\n\t\t_blood?.Clear();\r\n\t\tif ( _face is not null ) _face.XEyes = false;\r\n\t}\r\n\r\n\tvoid PinKnife()\r\n\t{\r\n\t\t_pos[Links] = _prev[Links] = _stuckPommel;\r\n\t\t_pos[Links \u002B 1] = _prev[Links \u002B 1] = _stuckTip;\r\n\t}\r\n\r\n\tvoid Unstick( CameraComponent camera )\r\n\t{\r\n\t\t// Back into the hand, in the plane the knife is held in, at its normal size, pointing the way it\r\n\t\t// was stuck, and at rest: jumping there in one step would read as a huge velocity and fling it.\r\n\t\tvar eye = camera.WorldPosition;\r\n\t\tvar forward = camera.WorldRotation.Forward;\r\n\t\tvar stuckDir = (_stuckTip - _stuckPommel).Normal;\r\n\t\tvar dir = stuckDir - forward * Vector3.Dot( stuckDir, forward );\r\n\t\tdir = dir.Length \u003E 0.1f ? dir.Normal : camera.WorldRotation.Down;\r\n\r\n\t\tvar hand = _grabTarget;\r\n\t\tif ( !_held )\r\n\t\t{\r\n\t\t\tvar grabbed = Vector3.Lerp( _stuckPommel, _stuckTip, _grabAlong );\r\n\t\t\thand = eye \u002B (grabbed - eye) * (Depth / MathF.Max( Vector3.Dot( grabbed - eye, forward ), 0.1f ));\r\n\t\t}\r\n\t\tvar pommel = hand - dir * (_grabAlong * KnifeLength);\r\n\t\tvar shift = pommel - _pos[Links];\r\n\t\tfor ( int i = 0; i \u003C Links; i\u002B\u002B )\r\n\t\t{\r\n\t\t\t_pos[i] \u002B= shift; // the string comes along rather than being yanked\r\n\t\t\t_prev[i] = _pos[i];\r\n\t\t}\r\n\t\t_pos[Links] = _prev[Links] = pommel;\r\n\t\t_pos[Links \u002B 1] = _prev[Links \u002B 1] = pommel \u002B dir * KnifeLength;\r\n\r\n\t\t_stuck = false;\r\n\t\t_mustLeave = true;\r\n\t\t_visualScale = 1f;\r\n\t\t_invMass[Links] = 0.25f;\r\n\t\t_invMass[Links \u002B 1] = 0.25f;\r\n\t\t_prevExcess = float.MaxValue; // no yank reading from the jump out\r\n\r\n\t\t_blood?.CloseWound( _wound, -stuckDir );\r\n\t\tif ( _face is not null ) _face.XEyes = false;\r\n\t\t_wound = -1;\r\n\t}\r\n\r\n\t// --- Grabbing ---\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Called on a click: grabs the knife if the ray passes close enough to it.\r\n\t/// Returns true when it did, so the click doesn\u0027t also grab the face.\r\n\t/// \u003C/summary\u003E\r\n\tpublic bool TryGrab( Ray ray )\r\n\t{\r\n\t\tif ( !_active || _retracting || _finishing || Scene.Camera is not { } camera ) return false;\r\n\r\n\t\tvar pommel = _pos[Links];\r\n\t\tvar along = _pos[Links \u002B 1] - pommel;\r\n\t\tfloat lengthSq = along.LengthSquared;\r\n\t\tif ( lengthSq \u003C 1e-6f ) return false;\r\n\r\n\t\t// Closest points between the click ray and the knife.\r\n\t\tvar w = ray.Position - pommel;\r\n\t\tfloat b = Vector3.Dot( ray.Forward, along );\r\n\t\tfloat d = Vector3.Dot( ray.Forward, w );\r\n\t\tfloat e = Vector3.Dot( along, w );\r\n\t\tfloat denom = lengthSq - b * b; // ray.Forward is unit length\r\n\t\tfloat visible = _stuck ? (KnifeLength - _stuckDepth) / KnifeLength : 1f; // a stuck blade is hidden in the face\r\n\t\tfloat s = denom \u003E 1e-6f ? Math.Clamp( (e - b * d) / denom, 0f, visible ) : 0f;\r\n\t\tvar onKnife = pommel \u002B along * s;\r\n\t\tfloat t = MathF.Max( Vector3.Dot( onKnife - ray.Position, ray.Forward ), 0f );\r\n\t\tif ( (ray.Position \u002B ray.Forward * t - onKnife).Length \u003E GrabRadius ) return false;\r\n\r\n\t\t_held = true;\r\n\t\t_grabAlong = s;\r\n\t\t_grabDepth = _stuck ? Depth : Vector3.Dot( onKnife - camera.WorldPosition, camera.WorldRotation.Forward );\r\n\t\t_grabTarget = _stuck ? MouseTarget( camera ) : onKnife;\r\n\t\t_prevExcess = Excess( camera );\r\n\t\tif ( _stuck ) _pushBase = _stuckDepth - Vector3.Dot( _grabTarget, _pushAxis );\r\n\t\treturn true;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EThe point under the mouse at the depth the knife was grabbed at.\u003C/summary\u003E\r\n\tVector3 MouseTarget( CameraComponent camera )\r\n\t{\r\n\t\tvar ray = camera.ScreenPixelToRay( Mouse.Position );\r\n\t\tfloat facing = MathF.Max( Vector3.Dot( ray.Forward, camera.WorldRotation.Forward ), 0.1f );\r\n\t\treturn ray.Position \u002B ray.Forward * (_grabDepth / facing);\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EHow far the hand is past what the string can reach (0 when within reach).\u003C/summary\u003E\r\n\tfloat Excess( CameraComponent camera )\r\n\t{\r\n\t\tfloat reach = RopeLength \u002B _grabAlong * KnifeLength;\r\n\t\treturn MathF.Max( (_grabTarget - Anchor( camera )).Length - reach, 0f );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EA hard yank (or a very long pull) snaps the string off at the top.\u003C/summary\u003E\r\n\tvoid CheckSnap( CameraComponent camera )\r\n\t{\r\n\t\tfloat excess = Excess( camera );\r\n\t\tfloat speed = (excess - _prevExcess) / MathF.Max( RealTime.Delta, 1e-4f );\r\n\t\t_prevExcess = excess;\r\n\t\tif ( excess \u003E BreakStretchAlways || excess \u003E BreakStretch \u0026\u0026 speed \u003E BreakSpeed ) Snap();\r\n\t}\r\n\r\n\tvoid Snap()\r\n\t{\r\n\t\t_loose = true;\r\n\t\t_invMass[0] = 1f; // the top end is free now, trailing behind the knife\r\n\t\t_prev[0] = _pos[0];\r\n\t}\r\n\r\n\t// --- Simulation ---\r\n\r\n\tVector3 Anchor( CameraComponent camera )\r\n\t{\r\n\t\tfloat halfHeight = Depth * MathF.Tan( camera.FieldOfView.DegreeToRadian() * 0.5f );\r\n\t\tvar rot = camera.WorldRotation;\r\n\t\treturn camera.WorldPosition \u002B rot.Forward * Depth \u002B rot.Up * (halfHeight \u002B 1.5f \u002B _lift) \u002B rot.Right * Sideways;\r\n\t}\r\n\r\n\tvoid Drop( CameraComponent camera )\r\n\t{\r\n\t\t_keeper?.EndBloodRun();\r\n\t\tint n = Links \u002B 2;\r\n\t\t_pos = new Vector3[n];\r\n\t\t_prev = new Vector3[n];\r\n\t\t_invMass = new float[n];\r\n\t\t_linkLength = RopeLength / Links;\r\n\t\t_lift = 0f;\r\n\t\t_retracting = false;\r\n\t\t_loose = false;\r\n\t\t_held = false;\r\n\t\t_looseTimer = 0f;\r\n\t\t_stuck = false;\r\n\t\t_mustLeave = false;\r\n\t\t_visualScale = 1f;\r\n\t\t_bloodied = 0f;\r\n\t\t_wound = -1;\r\n\t\tif ( _face is not null ) _face.XEyes = false;\r\n\t\t_stepAcc = 0f;\r\n\r\n\t\t// Everything starts bunched at the anchor (just above the view) and falls in; a small sideways\r\n\t\t// nudge on the knife gives it a natural swing as the string snaps taut.\r\n\t\tvar anchor = Anchor( camera );\r\n\t\tvar right = camera.WorldRotation.Right;\r\n\t\tfor ( int i = 0; i \u003C= Links; i\u002B\u002B )\r\n\t\t{\r\n\t\t\t_pos[i] = anchor \u002B right * (i * 0.02f);\r\n\t\t\t_prev[i] = _pos[i];\r\n\t\t\t_invMass[i] = 1f;\r\n\t\t}\r\n\t\t_invMass[0] = 0f; // pinned to the anchor\r\n\t\t_invMass[Links] = 0.25f; // pommel: the knife is heavy\r\n\t\t_pos[Links \u002B 1] = _pos[Links] \u002B Vector3.Down * KnifeLength;\r\n\t\t_prev[Links \u002B 1] = _pos[Links \u002B 1] - right * 0.15f;\r\n\t\t_invMass[Links \u002B 1] = 0.25f;\r\n\r\n\t\t_active = true;\r\n\t\t_root.Enabled = true;\r\n\t}\r\n\r\n\tvoid Step( CameraComponent camera )\r\n\t{\r\n\t\tint n = _pos.Length;\r\n\t\tif ( !_loose )\r\n\t\t{\r\n\t\t\t_pos[0] = Anchor( camera );\r\n\t\t\t_prev[0] = _pos[0];\r\n\t\t}\r\n\r\n\t\t// Predict: velocity (from the last move) \u002B gravity.\r\n\t\tvar gravity = Vector3.Down * Gravity * StepTime * StepTime;\r\n\t\tfor ( int i = _loose ? 0 : 1; i \u003C n; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tvar velocity = (_pos[i] - _prev[i]) * Damping;\r\n\t\t\t_prev[i] = _pos[i];\r\n\t\t\t_pos[i] \u002B= velocity \u002B gravity;\r\n\t\t}\r\n\r\n\t\tif ( _stuck ) PinKnife();\r\n\r\n\t\t// Enforce the constraints: rope links (they can stretch no further than their length, like a\r\n\t\t// string) and the knife as a rigid bar.\r\n\t\tfor ( int it = 0; it \u003C Iterations; it\u002B\u002B )\r\n\t\t{\r\n\t\t\tfor ( int i = 0; i \u003C Links; i\u002B\u002B ) SolveDistance( i, i \u002B 1, _linkLength, ropeOnly: true );\r\n\t\t\tSolveDistance( Links, Links \u002B 1, KnifeLength, ropeOnly: false );\r\n\t\t\tif ( _held ) SolveGrab();\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EPulls the grabbed point of the knife (between pommel and tip) towards the mouse.\u003C/summary\u003E\r\n\tvoid SolveGrab()\r\n\t{\r\n\t\tint a = Links, b = Links \u002B 1;\r\n\t\tfloat ca = 1f - _grabAlong, cb = _grabAlong;\r\n\t\tvar point = _pos[a] * ca \u002B _pos[b] * cb;\r\n\t\tfloat w = _invMass[a] * ca * ca \u002B _invMass[b] * cb * cb;\r\n\t\tif ( w \u003C= 1e-6f ) return;\r\n\t\tvar correction = (_grabTarget - point) * (GrabStiffness / w);\r\n\t\t_pos[a] \u002B= correction * (_invMass[a] * ca);\r\n\t\t_pos[b] \u002B= correction * (_invMass[b] * cb);\r\n\t}\r\n\r\n\tvoid SolveDistance( int a, int b, float rest, bool ropeOnly )\r\n\t{\r\n\t\tvar delta = _pos[b] - _pos[a];\r\n\t\tfloat length = delta.Length;\r\n\t\tif ( length \u003C 1e-6f ) return;\r\n\t\tif ( ropeOnly \u0026\u0026 length \u003C= rest ) return; // a string only pulls, it doesn\u0027t push\r\n\r\n\t\tfloat wa = _invMass[a], wb = _invMass[b];\r\n\t\tfloat w = wa \u002B wb;\r\n\t\tif ( w \u003C= 0f ) return;\r\n\t\tvar correction = delta * ((length - rest) / (length * w));\r\n\t\t_pos[a] \u002B= correction * wa;\r\n\t\t_pos[b] -= correction * wb;\r\n\t}\r\n\r\n\t// --- Visuals ---\r\n\r\n\tvoid BuildVisuals()\r\n\t{\r\n\t\t_root = new GameObject( GameObject, true, \u0022Fatality Knife\u0022 );\r\n\t\t_root.Flags |= GameObjectFlags.NotSaved | GameObjectFlags.NotNetworked;\r\n\t\t_root.NetworkMode = NetworkMode.Never;\r\n\r\n\t\tvar material = Material.Load( \u0022materials/default.vmat\u0022 );\r\n\t\tvar unitBox = Model.Builder.AddMesh( BoxMesh( material, Vector3.Zero, Vector3.One ) ).Create();\r\n\r\n\t\tfor ( int i = 0; i \u003C Links; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tvar seg = new GameObject( _root, true, $\u0022Rope {i}\u0022 );\r\n\t\t\tvar r = seg.Components.Create\u003CModelRenderer\u003E();\r\n\t\t\tr.Model = unitBox;\r\n\t\t\tr.Tint = new Color( 0.78f, 0.7f, 0.52f );\r\n\t\t\tr.RenderType = ModelRenderer.ShadowRenderType.Off;\r\n\t\t\t_ropeSegments.Add( seg );\r\n\t\t}\r\n\r\n\t\t// The knife, built along \u002BX from the pommel (0) to the tip (KnifeLength), blade facing \u002BZ.\r\n\t\t_knife = new GameObject( _root, true, \u0022Knife\u0022 );\r\n\t\tAddPart( _knife, \u0022Handle\u0022, Model.Builder.AddMesh( BoxMesh( material, new Vector3( 0.8f, 0f, 0f ), new Vector3( 1.6f, 0.42f, 0.34f ) ) ).Create(), new Color( 0.32f, 0.18f, 0.09f ) );\r\n\t\tAddPart( _knife, \u0022Guard\u0022, Model.Builder.AddMesh( BoxMesh( material, new Vector3( 1.7f, 0f, 0f ), new Vector3( 0.2f, 1.05f, 0.4f ) ) ).Create(), new Color( 0.18f, 0.18f, 0.2f ) );\r\n\t\t_blade = AddPart( _knife, \u0022Blade\u0022, Model.Builder.AddMesh( BladeMesh( material ) ).Create(), SteelColor );\r\n\t}\r\n\r\n\tstatic readonly Color SteelColor = new( 0.86f, 0.88f, 0.92f );\r\n\tstatic readonly Color BloodySteelColor = new( 0.45f, 0.06f, 0.07f );\r\n\r\n\tstatic ModelRenderer AddPart( GameObject parent, string name, Model model, Color tint )\r\n\t{\r\n\t\tvar go = new GameObject( parent, true, name );\r\n\t\tvar r = go.Components.Create\u003CModelRenderer\u003E();\r\n\t\tr.Model = model;\r\n\t\tr.Tint = tint;\r\n\t\treturn r;\r\n\t}\r\n\r\n\tvoid UpdateVisuals( CameraComponent camera )\r\n\t{\r\n\t\tvar toCamera = -camera.WorldRotation.Forward;\r\n\r\n\t\tfor ( int i = 0; i \u003C Links; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tvar a = _pos[i];\r\n\t\t\tvar b = _pos[i \u002B 1];\r\n\t\t\tvar dir = b - a;\r\n\t\t\tfloat len = dir.Length;\r\n\t\t\tvar seg = _ropeSegments[i];\r\n\t\t\tseg.WorldPosition = (a \u002B b) * 0.5f;\r\n\t\t\tseg.WorldRotation = len \u003E 1e-5f ? Rotation.LookAt( dir / len, toCamera ) : Rotation.Identity;\r\n\t\t\tseg.WorldScale = new Vector3( MathF.Max( len, 0.01f ), RopeThickness, RopeThickness );\r\n\t\t}\r\n\r\n\t\t// Knife: from the pommel towards the tip, flat side to the camera.\r\n\t\tvar pommel = _pos[Links];\r\n\t\tvar along = _pos[Links \u002B 1] - pommel;\r\n\t\t_knife.WorldPosition = pommel;\r\n\t\t_knife.WorldRotation = Rotation.LookAt( along.Normal, toCamera );\r\n\t\t_knife.WorldScale = _visualScale;\r\n\t\tif ( _blade is not null ) _blade.Tint = Color.Lerp( SteelColor, BloodySteelColor, _bloodied * 0.8f );\r\n\t}\r\n\r\n\t// --- Meshes ---\r\n\r\n\t/// \u003Csummary\u003EAn axis-aligned box of the given size centred on \u003Cparamref name=\u0022center\u0022/\u003E.\u003C/summary\u003E\r\n\tstatic Mesh BoxMesh( Material material, Vector3 center, Vector3 size )\r\n\t{\r\n\t\tvar verts = new List\u003CVertex\u003E();\r\n\t\tvar indices = new List\u003Cint\u003E();\r\n\t\tvar h = size * 0.5f;\r\n\t\tVector3[] normals = { Vector3.Forward, Vector3.Backward, Vector3.Left, Vector3.Right, Vector3.Up, Vector3.Down };\r\n\t\tforeach ( var nrm in normals )\r\n\t\t{\r\n\t\t\t// Two axes spanning the face.\r\n\t\t\tvar u = MathF.Abs( nrm.z ) \u003E 0.5f ? Vector3.Forward : Vector3.Up;\r\n\t\t\tvar v = Vector3.Cross( nrm, u );\r\n\t\t\tint start = verts.Count;\r\n\t\t\tforeach ( var (su, sv) in new[] { (-1f, -1f), (1f, -1f), (1f, 1f), (-1f, 1f) } )\r\n\t\t\t{\r\n\t\t\t\tvar p = nrm \u002B u * su \u002B v * sv;\r\n\t\t\t\tverts.Add( new Vertex( center \u002B p * h, nrm, u, Vector4.Zero ) );\r\n\t\t\t}\r\n\t\t\tindices.AddRange( new[] { start, start \u002B 1, start \u002B 2, start, start \u002B 2, start \u002B 3 } );\r\n\t\t}\r\n\t\treturn BuildMesh( material, verts, indices, center, size );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003EA flat blade from the guard to the tip: straight spine on top, curved edge below.\u003C/summary\u003E\r\n\tstatic Mesh BladeMesh( Material material )\r\n\t{\r\n\t\t(float x, float y)[] outline =\r\n\t\t{\r\n\t\t\t(1.8f, 0.42f), (4.4f, 0.42f), (5f, 0.3f), (4.6f, 0.02f), (3.8f, -0.3f), (2.8f, -0.44f), (1.8f, -0.46f),\r\n\t\t};\r\n\t\tconst float half = 0.045f;\r\n\t\tvar verts = new List\u003CVertex\u003E();\r\n\t\tvar indices = new List\u003Cint\u003E();\r\n\r\n\t\t// Front and back faces (the outline is convex, so a fan works).\r\n\t\tforeach ( float side in new[] { 1f, -1f } )\r\n\t\t{\r\n\t\t\tint start = verts.Count;\r\n\t\t\tvar nrm = new Vector3( 0, 0, side );\r\n\t\t\tforeach ( var (x, y) in outline ) verts.Add( new Vertex( new Vector3( x, y, half * side ), nrm, Vector3.Forward, Vector4.Zero ) );\r\n\t\t\tfor ( int i = 1; i \u002B 1 \u003C outline.Length; i\u002B\u002B )\r\n\t\t\t{\r\n\t\t\t\tif ( side \u003E 0 ) indices.AddRange( new[] { start, start \u002B i, start \u002B i \u002B 1 } );\r\n\t\t\t\telse indices.AddRange( new[] { start, start \u002B i \u002B 1, start \u002B i } );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Thin edges around the outline.\r\n\t\tfor ( int i = 0; i \u003C outline.Length; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tvar (x0, y0) = outline[i];\r\n\t\t\tvar (x1, y1) = outline[(i \u002B 1) % outline.Length];\r\n\t\t\tvar edge = new Vector3( x1 - x0, y1 - y0, 0 );\r\n\t\t\tvar nrm = new Vector3( edge.y, -edge.x, 0 ).Normal;\r\n\t\t\tint start = verts.Count;\r\n\t\t\tverts.Add( new Vertex( new Vector3( x0, y0, half ), nrm, Vector3.Forward, Vector4.Zero ) );\r\n\t\t\tverts.Add( new Vertex( new Vector3( x1, y1, half ), nrm, Vector3.Forward, Vector4.Zero ) );\r\n\t\t\tverts.Add( new Vertex( new Vector3( x1, y1, -half ), nrm, Vector3.Forward, Vector4.Zero ) );\r\n\t\t\tverts.Add( new Vertex( new Vector3( x0, y0, -half ), nrm, Vector3.Forward, Vector4.Zero ) );\r\n\t\t\tindices.AddRange( new[] { start, start \u002B 2, start \u002B 1, start, start \u002B 3, start \u002B 2 } );\r\n\t\t}\r\n\r\n\t\treturn BuildMesh( material, verts, indices, new Vector3( 3.4f, 0, 0 ), new Vector3( 3.4f, 1f, 0.2f ) );\r\n\t}\r\n\r\n\tstatic Mesh BuildMesh( Material material, List\u003CVertex\u003E verts, List\u003Cint\u003E indices, Vector3 center, Vector3 size )\r\n\t{\r\n\t\tvar mesh = new Mesh( material );\r\n\t\tmesh.CreateVertexBuffer( verts.Count, Vertex.Layout, verts );\r\n\t\tmesh.CreateIndexBuffer( indices.Count, indices );\r\n\t\tmesh.Bounds = BBox.FromPositionAndSize( center, size \u002B Vector3.One * 0.1f );\r\n\t\treturn mesh;\r\n\t}\r\n}\r\n"},{"Ident":"chomnr.squishy_terry","Path":"Scoring/Guarded.cs","FileName":"Guarded.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\n\nnamespace SquishyTerry.Scoring;\n\n/// \u003Csummary\u003E\n/// A number kept obfuscated in memory: stored XOR\u0027d with a fresh random key on every write, plus\n/// a checksum. Memory scanners (Cheat Engine and the like) can\u0027t find the value by searching for\n/// it, and editing the stored bits breaks the checksum, which flags \u003Csee cref=\u0022Tampered\u0022/\u003E.\n/// \u003C/summary\u003E\nsealed class Guarded\n{\n\tstatic readonly Random Rng = new();\n\n\tint _key, _masked, _check;\n\n\t/// \u003Csummary\u003ESet once the stored bits have been changed from outside; never clears.\u003C/summary\u003E\n\tpublic bool Tampered { get; private set; }\n\n\tpublic Guarded( float value = 0f ) =\u003E Value = value;\n\n\tpublic float Value\n\t{\n\t\tget\n\t\t{\n\t\t\tif ( Checksum( _masked, _key ) != _check )\n\t\t\t{\n\t\t\t\tTampered = true;\n\t\t\t\treturn 0f;\n\t\t\t}\n\t\t\treturn BitConverter.Int32BitsToSingle( _masked ^ _key );\n\t\t}\n\t\tset\n\t\t{\n\t\t\t_key = Rng.Next( int.MinValue, int.MaxValue );\n\t\t\t_masked = BitConverter.SingleToInt32Bits( value ) ^ _key;\n\t\t\t_check = Checksum( _masked, _key );\n\t\t}\n\t}\n\n\tstatic int Checksum( int masked, int key )\n\t{\n\t\tunchecked\n\t\t{\n\t\t\tuint h = (uint)masked * 2654435761u;\n\t\t\th ^= (uint)key \u003E\u003E 7;\n\t\t\th *= 2246822519u;\n\t\t\treturn (int)(h ^ 0x2F6B3A1Du);\n\t\t}\n\t}\n}\n"},{"Ident":"chomnr.squishy_terry","Path":"Scoring/HumanInput.cs","FileName":"HumanInput.cs","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"using System;\nusing System.Collections.Generic;\n\nnamespace SquishyTerry.Scoring;\n\n/// \u003Csummary\u003E\n/// Anti-macro / inhuman-click checks on the mouse presses that drive squishing.\n/// \u003Clist type=\u0022bullet\u0022\u003E\n/// \u003Citem\u003EInhuman speed: presses closer together than a person can click are ignored, and a burst\n/// of too many presses in one second is a strike.\u003C/item\u003E\n/// \u003Citem\u003ERobotic timing: a long run of press intervals that are nearly identical (auto-clickers\n/// fire on a fixed timer; people drift) is a strike.\u003C/item\u003E\n/// \u003Citem\u003ERobotic movement: a run of grab-and-release gestures that start and end on exactly the\n/// same pixels (scripted drags) is a strike.\u003C/item\u003E\n/// \u003C/list\u003E\n/// A strike makes the player \u003Csee cref=\u0022Suspicious\u0022/\u003E for a while (squishes don\u0027t count); enough\n/// strikes in a session mark it \u003Csee cref=\u0022Flagged\u0022/\u003E (nothing is submitted for the rest of it).\n/// The thresholds are deliberately loose so fast, skilled play never trips them.\n/// \u003C/summary\u003E\nsealed class HumanInput\n{\n\t// Fastest humans manage roughly 12-16 clicks per second in short bursts.\n\tconst float MinPressInterval = 0.055f;\n\tconst int MaxPressesPerSecond = 16;\n\n\t// Timing regularity: this many intervals, all under 0.4 s, with a spread below 4 ms.\n\tconst int TimingWindow = 16;\n\tconst float MaxRhythmicInterval = 0.4f;\n\tconst float MinHumanJitter = 0.004f;\n\n\t// Movement: this many gestures whose press and release points match the first to within a pixel.\n\tconst int GestureWindow = 10;\n\tconst float SamePixel = 1f;\n\n\tconst float SuspicionTime = 30f;\n\tconst int StrikesToFlag = 3;\n\n\treadonly List\u003Cfloat\u003E _presses = new();\n\treadonly List\u003C(float X, float Y, float UpX, float UpY)\u003E _gestures = new();\n\tfloat _pressX, _pressY;\n\tfloat _suspiciousUntil = -1f;\n\n\tpublic int Strikes { get; private set; }\n\tpublic bool Flagged =\u003E Strikes \u003E= StrikesToFlag;\n\n\tpublic bool Suspicious( float now ) =\u003E Flagged || now \u003C _suspiciousUntil;\n\n\t/// \u003Csummary\u003ERecords a press; returns false if this press itself was inhumanly fast.\u003C/summary\u003E\n\tpublic bool Press( float now, float x, float y )\n\t{\n\t\tbool human = _presses.Count == 0 || now - _presses[^1] \u003E= MinPressInterval;\n\n\t\t_presses.Add( now );\n\t\tif ( _presses.Count \u003E 64 ) _presses.RemoveAt( 0 );\n\t\t_pressX = x;\n\t\t_pressY = y;\n\n\t\tint lastSecond = 0;\n\t\tfor ( int i = _presses.Count - 1; i \u003E= 0 \u0026\u0026 now - _presses[i] \u003C= 1f; i-- ) lastSecond\u002B\u002B;\n\t\tif ( lastSecond \u003E MaxPressesPerSecond ) Strike( now, clearPresses: true );\n\t\telse if ( RoboticTiming() ) Strike( now, clearPresses: true );\n\n\t\treturn human;\n\t}\n\n\tpublic void Release( float now, float x, float y )\n\t{\n\t\t_gestures.Add( (_pressX, _pressY, x, y) );\n\t\tif ( _gestures.Count \u003E GestureWindow ) _gestures.RemoveAt( 0 );\n\n\t\tif ( _gestures.Count == GestureWindow \u0026\u0026 RoboticMovement() )\n\t\t{\n\t\t\tStrike( now, clearPresses: false );\n\t\t\t_gestures.Clear();\n\t\t}\n\t}\n\n\tbool RoboticTiming()\n\t{\n\t\tif ( _presses.Count \u003C TimingWindow \u002B 1 ) return false;\n\n\t\tint start = _presses.Count - TimingWindow;\n\t\tfloat sum = 0f, sumSq = 0f;\n\t\tfor ( int i = start; i \u003C _presses.Count; i\u002B\u002B )\n\t\t{\n\t\t\tfloat d = _presses[i] - _presses[i - 1];\n\t\t\tif ( d \u003E MaxRhythmicInterval ) return false;\n\t\t\tsum \u002B= d;\n\t\t\tsumSq \u002B= d * d;\n\t\t}\n\t\tfloat mean = sum / TimingWindow;\n\t\tfloat spread = MathF.Sqrt( MathF.Max( 0f, sumSq / TimingWindow - mean * mean ) );\n\t\treturn spread \u003C MinHumanJitter;\n\t}\n\n\tbool RoboticMovement()\n\t{\n\t\tvar first = _gestures[0];\n\t\tforeach ( var g in _gestures )\n\t\t{\n\t\t\tif ( MathF.Abs( g.X - first.X ) \u003E SamePixel || MathF.Abs( g.Y - first.Y ) \u003E SamePixel ) return false;\n\t\t\tif ( MathF.Abs( g.UpX - first.UpX ) \u003E SamePixel || MathF.Abs( g.UpY - first.UpY ) \u003E SamePixel ) return false;\n\t\t}\n\t\t// Pressing and releasing on the very same spot (a plain tap) is normal; only identical drags count.\n\t\treturn MathF.Abs( first.UpX - first.X ) \u003E SamePixel || MathF.Abs( first.UpY - first.Y ) \u003E SamePixel;\n\t}\n\n\tvoid Strike( float now, bool clearPresses )\n\t{\n\t\tStrikes\u002B\u002B;\n\t\t_suspiciousUntil = now \u002B SuspicionTime;\n\t\tif ( clearPresses ) _presses.Clear();\n\t}\n}\n"},{"Ident":"chomnr.squishy_terry","Path":"ui/leaderboard.razor.scss","FileName":"leaderboard.razor.scss","PackageType":"game","CodeKind":"Game","AssetVersionId":398013,"IsPrivate":false,"Code":"// Leaderboard card: deep purple-black panel with a violet frame, a yellow banner with Terry\r\n// peeking over it, and dark rows. Poppins bold italic throughout, like the combo counter.\r\n\r\n$ink: #140a14;\r\n$row: #211a28;\r\n$row-edge: #2e2537;\r\n$frame: #4a2a7a;\r\n$violet: #8f3dff;\r\n$magenta: #e73bd8;\r\n$yellow: #ffd93b;\r\n$text: #f4eef8;\r\n$muted: #8d8398;\r\n$skin: #e8a57e;\r\n\r\nLeaderboard\r\n{\r\n\tposition: absolute;\r\n\twidth: 100%;\r\n\theight: 100%;\r\n\tpointer-events: none;\r\n\tfont-family: Poppins;\r\n\tfont-weight: 700;\r\n\tfont-style: italic;\r\n\tcolor: $text;\r\n\talign-items: center;\r\n}\r\n\r\n.deck\r\n{\r\n\tmargin-left: 28px;\r\n\tmargin-top: 60px;\r\n\tposition: relative;\r\n}\r\n\r\n.card\r\n{\r\n\tposition: relative;\r\n\twidth: 364px;\r\n\tflex-direction: column;\r\n\tpadding: 14px 14px 12px;\r\n\tbackground-color: rgba( 23, 18, 29, 0.94 );\r\n\tborder: 3px solid $frame;\r\n\tborder-radius: 14px 10px 18px 10px;\r\n\tbox-shadow: 0px 10px 30px rgba( 0, 0, 0, 0.55 );\r\n}\r\n\r\n// Purple tab sticking up from the top-left corner.\r\n.tab\r\n{\r\n\tposition: absolute;\r\n\tleft: 18px;\r\n\ttop: -12px;\r\n\twidth: 120px;\r\n\theight: 12px;\r\n\tbackground-color: $frame;\r\n\tborder-radius: 6px 6px 0px 0px;\r\n\ttransform: skewX( -20deg );\r\n}\r\n\r\n// --- Header ---\r\n.header\r\n{\r\n\tposition: relative;\r\n\tflex-direction: column;\r\n\tmargin-bottom: 10px;\r\n}\r\n\r\n.peek\r\n{\r\n\tposition: absolute;\r\n\tright: 22px;\r\n\ttop: -58px;\r\n\twidth: 84px;\r\n\theight: 84px;\r\n\r\n\t.face\r\n\t{\r\n\t\tposition: absolute;\r\n\t\tleft: 0px;\r\n\t\ttop: 0px;\r\n\t\twidth: 84px;\r\n\t\theight: 84px;\r\n\t\tbackground-image: url( /ui/leaderboard_face.png );\r\n\t\tbackground-size: 100%;\r\n\t\tbackground-repeat: no-repeat;\r\n\t}\r\n\r\n\t// \u0022!\u0022 burst lines up and to the right of his head.\r\n\t.burst\r\n\t{\r\n\t\tposition: absolute;\r\n\t\twidth: 5px;\r\n\t\theight: 16px;\r\n\t\tbackground-color: $yellow;\r\n\t\tborder-radius: 3px;\r\n\t}\r\n\r\n\t.b1 { left: 86px; top: 4px; height: 12px; transform: rotate( 30deg ); }\r\n\t.b2 { left: 94px; top: 12px; height: 12px; transform: rotate( 65deg ); }\r\n}\r\n\r\n.title-banner\r\n{\r\n\tflex-direction: row;\r\n\talign-items: center;\r\n\tpadding: 6px 16px 6px 14px;\r\n\tbackground-color: $yellow;\r\n\t// Smooth gloss: pale at the top, blending evenly down to deep gold at the bottom.\r\n\tbackground-image: linear-gradient( to bottom, #fff29e 0%, #ffe66a 30%, #ffd83a 60%, #ffc21a 100% );\r\n\tborder: 3px solid $ink;\r\n\tborder-radius: 6px;\r\n\tbox-shadow: 0px 4px 0px $ink;\r\n\ttransform: skewX( -6deg );\r\n\r\n\t.title\r\n\t{\r\n\t\tfont-size: 33px;\r\n\t\tfont-weight: 800;\r\n\t\twhite-space: nowrap;\r\n\t\tletter-spacing: 0px;\r\n\t\ttext-transform: uppercase;\r\n\t\tcolor: $ink;\r\n\t}\r\n}\r\n\r\n.crown\r\n{\r\n\twidth: 40px;\r\n\theight: 30px;\r\n\tmargin-right: 10px;\r\n\tbackground-image: url( /ui/crown.png );\r\n\tbackground-size: 100%;\r\n\tbackground-repeat: no-repeat;\r\n\tbackground-tint: $ink;\r\n\r\n\t\u0026.small\r\n\t{\r\n\t\twidth: 18px;\r\n\t\theight: 14px;\r\n\t\tmargin-right: 0px;\r\n\t\tmargin-left: 4px;\r\n\t\tbackground-tint: $yellow;\r\n\t}\r\n}\r\n\r\n// Terry\u0027s hands gripping the banner edge.\r\n.hand\r\n{\r\n\tposition: absolute;\r\n\ttop: -8px;\r\n\twidth: 22px;\r\n\theight: 18px;\r\n\tbackground-color: $skin;\r\n\tborder: 2px solid $ink;\r\n\tborder-radius: 50%;\r\n\r\n\t\u0026.left { right: 82px; }\r\n\t\u0026.right { right: 22px; }\r\n}\r\n\r\n.switcher\r\n{\r\n\tflex-direction: row;\r\n\talign-items: center;\r\n\tmargin-top: 10px;\r\n\tpadding: 6px 10px;\r\n\tbackground-color: #1f1827;\r\n\tborder: 2px solid $row-edge;\r\n\tborder-radius: 6px;\r\n\ttransform: skewX( -6deg );\r\n\r\n\t.arrow\r\n\t{\r\n\t\twidth: 26px;\r\n\t\tjustify-content: center;\r\n\t\tfont-size: 16px;\r\n\t\tfont-style: normal;\r\n\t\tcolor: $violet;\r\n\t\tpointer-events: all;\r\n\t\tcursor: pointer;\r\n\r\n\t\t\u0026:hover { color: $magenta; }\r\n\t}\r\n\r\n\t.subtitle\r\n\t{\r\n\t\tflex-grow: 1;\r\n\t\tjustify-content: center;\r\n\t\tfont-size: 14px;\r\n\t\tfont-weight: 600;\r\n\t\tletter-spacing: 5px;\r\n\t\ttext-transform: uppercase;\r\n\t\tcolor: $text;\r\n\t}\r\n}\r\n\r\n// --- Rows ---\r\n.rows\r\n{\r\n\tflex-direction: column;\r\n}\r\n\r\n.row\r\n{\r\n\tposition: relative;\r\n\tflex-direction: row;\r\n\talign-items: center;\r\n\theight: 42px;\r\n\tpadding: 0px 12px 0px 6px;\r\n\tmargin-bottom: 6px;\r\n\tbackground-color: $row;\r\n\tborder: 1px solid $row-edge;\r\n\tborder-radius: 8px;\r\n\r\n\t.rank\r\n\t{\r\n\t\tflex-shrink: 0;\r\n\t\tjustify-content: center;\r\n\t\talign-items: center;\r\n\t\tfont-size: 20px;\r\n\t\tcolor: $text;\r\n\r\n\t\t\u0026.box\r\n\t\t{\r\n\t\t\twidth: 38px;\r\n\t\t\theight: 32px;\r\n\t\t\tbackground-color: #2a2233;\r\n\t\t\tborder-radius: 6px;\r\n\t\t}\r\n\t}\r\n\r\n\t.avatar-ring\r\n\t{\r\n\t\tflex-shrink: 0;\r\n\t\tmargin: 0px 10px 0px 10px;\r\n\t\tpadding: 2px;\r\n\t\tbackground-color: #3a2f45;\r\n\t\tborder-radius: 50%;\r\n\r\n\t\t\u0026.gold { background-color: $yellow; padding: 1px; }\r\n\t}\r\n\r\n\t.avatar\r\n\t{\r\n\t\twidth: 28px;\r\n\t\theight: 28px;\r\n\t\tborder-radius: 50%;\r\n\t\tbackground-size: cover;\r\n\t\tbackground-color: #2a2233;\r\n\r\n\t\t\u0026.placeholder\r\n\t\t{\r\n\t\t\tjustify-content: center;\r\n\t\t\talign-items: center;\r\n\t\t\tfont-size: 13px;\r\n\t\t\tfont-style: normal;\r\n\t\t\tcolor: $text;\r\n\t\t}\r\n\t}\r\n\r\n\t.name\r\n\t{\r\n\t\tflex-grow: 1;\r\n\t\tflex-shrink: 1;\r\n\t\tmin-width: 0;\r\n\t\tfont-size: 17px;\r\n\t\tletter-spacing: 0.5px;\r\n\t\ttext-transform: uppercase;\r\n\t\toverflow: hidden;\r\n\t\twhite-space: nowrap;\r\n\t\ttext-overflow: ellipsis;\r\n\t}\r\n\r\n\t// Per-letter colours: keep spaces and clip long names (no ellipsis across letters).\r\n\t.name.cycle\r\n\t{\r\n\t\tflex-direction: row;\r\n\r\n\t\tlabel\r\n\t\t{\r\n\t\t\twhite-space: pre;\r\n\t\t\tflex-shrink: 0;\r\n\t\t}\r\n\t}\r\n\r\n\t.score\r\n\t{\r\n\t\tflex-shrink: 0;\r\n\t\tmax-width: 100px;\r\n\t\tmargin-left: 8px;\r\n\t\toverflow: hidden;\r\n\t\twhite-space: nowrap;\r\n\t\ttext-overflow: ellipsis;\r\n\t\tfont-size: 19px;\r\n\t}\r\n\r\n\t// First place sits inside the rainbow border.\r\n\t\u0026.first\r\n\t{\r\n\t\theight: 44px;\r\n\t\tmargin-bottom: 0px;\r\n\t\tpadding-left: 12px;\r\n\t\tborder: 0px;\r\n\t\tbackground-color: #1b1522;\r\n\r\n\t\t.rank\r\n\t\t{\r\n\t\t\tflex-direction: row;\r\n\t\t\twidth: 44px;\r\n\t\t\tjustify-content: flex-start;\r\n\t\t\tcolor: $yellow;\r\n\t\t\tfont-size: 22px;\r\n\t\t}\r\n\r\n\t\t.avatar-ring { margin-left: 4px; }\r\n\r\n\t\t.score { font-size: 22px; }\r\n\t}\r\n\r\n\t// Faint dot texture behind first place\u0027s score.\r\n\t.dots\r\n\t{\r\n\t\tposition: absolute;\r\n\t\tright: 70px;\r\n\t\ttop: 0px;\r\n\t\twidth: 90px;\r\n\t\theight: 100%;\r\n\t\tbackground-image: url( /ui/dots.png );\r\n\t\tbackground-repeat: repeat;\r\n\t\tbackground-size: 12px 12px;\r\n\t\tbackground-tint: $violet;\r\n\t\topacity: 0.25;\r\n\t}\r\n}\r\n\r\n// First place: the padding shows the rotating gradient behind the row as a border.\r\n.rainbow\r\n{\r\n\tflex-direction: column;\r\n\tpadding: 3px;\r\n\tmargin-bottom: 8px;\r\n\tborder-radius: 10px;\r\n\tbox-shadow: 0px 0px 14px rgba( 255, 217, 59, 0.25 );\r\n}\r\n\r\n// No live scores yet.\r\n.empty\r\n{\r\n\theight: 44px;\r\n\tjustify-content: center;\r\n\talign-items: center;\r\n\tfont-size: 15px;\r\n\tletter-spacing: 1px;\r\n\ttext-transform: uppercase;\r\n\tcolor: $muted;\r\n}\r\n\r\n// YOU: the player\u0027s own row under the top 10 when they aren\u0027t in it.\r\n.you-divider\r\n{\r\n\tjustify-content: center;\r\n\theight: 14px;\r\n\tmargin-bottom: 4px;\r\n\tfont-size: 12px;\r\n\tletter-spacing: 4px;\r\n\tcolor: $muted;\r\n}\r\n\r\n.row.you\r\n{\r\n\tborder: 2px solid $magenta;\r\n\tbackground-color: #2a1830;\r\n\tmargin-bottom: 0px;\r\n\r\n\t.name { color: $magenta; }\r\n}\r\n\r\n// --- Footer ---\r\n.footer\r\n{\r\n\tflex-direction: row;\r\n\talign-items: center;\r\n\tjustify-content: center;\r\n\tmargin-top: 10px;\r\n\tmargin-bottom: 4px;\r\n\r\n\r\n\t.tagline\r\n\t{\r\n\t\tmargin: 0px 12px;\r\n\t\tfont-size: 12px;\r\n\t\tfont-weight: 600;\r\n\t\twhite-space: nowrap;\r\n\t\tletter-spacing: 4px;\r\n\t\ttext-transform: uppercase;\r\n\t\tcolor: $muted;\r\n\t}\r\n}\r\n\r\n.corner-dots\r\n{\r\n\tposition: absolute;\r\n\tleft: 8px;\r\n\tbottom: 8px;\r\n\twidth: 70px;\r\n\theight: 44px;\r\n\tbackground-image: url( /ui/dots.png );\r\n\tbackground-repeat: repeat;\r\n\tbackground-size: 10px 10px;\r\n\tbackground-tint: $violet;\r\n\topacity: 0.35;\r\n}\r\n"}]}