Compare commits

...
10 Commits
Author SHA1 Message Date
cneicy 0d9e04c09d chore(release): publish supplemental packages and remove internal reports
Validate ShrinkSDK Workspace / catalog (push) Successful in 4s
Validate ShrinkSDK Workspace / unity (push) Successful in 3m20s
2026-09-29 10:42:21 +08:00
cneicy 08246ddb01 feat: integrate performance upgrade and agent inspection tooling
Validate ShrinkSDK Workspace / catalog (push) Successful in 5s
Validate ShrinkSDK Workspace / unity (push) Successful in 3m20s
2026-09-29 10:16:02 +08:00
cneicy f92105c97d fix: use self-contained catalog runner image
Validate ShrinkSDK Workspace / catalog (push) Successful in 37s
Validate ShrinkSDK Workspace / unity (push) Successful in 3m7s
2026-09-05 07:02:12 +08:00
cneicy ddd55c0c58 fix: install git for catalog workflow jobs
Validate ShrinkSDK Workspace / catalog (push) Successful in 16s
Validate ShrinkSDK Workspace / unity (push) Successful in 3m10s
2026-09-05 06:46:44 +08:00
cneicy 2760dee6a7 fix: run catalog checks outside Unity containers
Validate ShrinkSDK Workspace / catalog (push) Failing after 1s
Validate ShrinkSDK Workspace / unity (push) Skipped
2026-09-05 06:44:57 +08:00
cneicy bb12b8d02d fix: automate package versions and workspace validation
Validate ShrinkSDK Workspace / unity (push) Failing after 5s
2026-09-05 06:32:13 +08:00
cneicy 6c90f9dc08 docs: finalize Godot package installation
Validate ShrinkSDK Workspace / unity (push) Failing after 4s
2026-09-05 04:33:49 +08:00
cneicy 7debc0240c chore: publish Godot and NuGet module releases
Validate ShrinkSDK Workspace / unity (push) Failing after 5s
2026-09-05 04:28:36 +08:00
cneicy e9d8e93427 refactor: move Godot packages into module repositories
Validate ShrinkSDK Workspace / unity (push) Failing after 5s
2026-09-05 03:43:14 +08:00
cneicy 2695dcdbba docs: add Unity and Godot setup guide
Validate ShrinkSDK Workspace / unity (push) Failing after 3m9s
2026-09-05 02:46:19 +08:00
157 changed files with 8194 additions and 1918 deletions
+23 -2
View File
@@ -4,7 +4,29 @@ on:
workflow_dispatch:
jobs:
catalog:
runs-on: ubuntu-latest
container:
image: docker.m.daocloud.io/library/node:22-bookworm
permissions:
contents: read
steps:
- name: Validate submodules and version catalog
shell: bash
run: |
set -euo pipefail
ref="${{ gitea.sha }}"
git init .
git remote add origin "https://git.crash.work/ShrinkSDK/Workspace.git"
git fetch --depth=1 origin "$ref"
git checkout --detach FETCH_HEAD
git submodule sync --recursive
git submodule update --init --recursive
bash Tools/CI/Validate-Submodules.sh "$PWD"
node Tools/Release/update-shrinksdk-versions.mjs --check
editmode:
needs: catalog
runs-on: unity-2022.3.62f3
container:
image: docker.1panel.live/unityci/editor:ubuntu-2022.3.62f3-windows-mono-3
@@ -27,8 +49,7 @@ jobs:
git checkout --detach FETCH_HEAD
git submodule sync --recursive
git submodule update --init --recursive
test "$(git submodule status --recursive | wc -l | tr -d ' ')" = "21"
test -z "$(git submodule status --recursive | grep '^-')"
bash Tools/CI/Validate-Submodules.sh "$PWD"
- name: Run every standalone package EditMode host
shell: bash
+144
View File
@@ -0,0 +1,144 @@
name: Publish inspection and optional packages
on:
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
NUGET_AUTH_TOKEN: ${{ secrets.SHRINKSDK_PACKAGE_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.SHRINKSDK_PACKAGE_TOKEN }}
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: '1'
DOTNET_CLI_TELEMETRY_OPTOUT: '1'
LD_LIBRARY_PATH: /opt/dotnet-libs/usr/lib/x86_64-linux-gnu
SSL_CERT_FILE: /opt/ca-certificates.crt
steps:
- name: Fetch exact workspace and required submodules
env:
RELEASE_SHA: ${{ gitea.sha }}
shell: bash
run: |
set -euo pipefail
node --input-type=module <<'NODE'
import { mkdir, writeFile } from 'node:fs/promises';
import { execFileSync } from 'node:child_process';
const base = 'https://git.crash.work';
const sha = process.env.RELEASE_SHA;
if (!/^[a-f0-9]{40}$/.test(sha)) throw new Error('An exact commit is required');
async function fetchSource(repo, revision, destination) {
const response = await fetch(`${base}/ShrinkSDK/${repo}/archive/${revision}.tar.gz`);
if (!response.ok) throw new Error(`Cannot fetch ${repo}: ${response.status}`);
await writeFile('source.tar.gz', new Uint8Array(await response.arrayBuffer()));
await mkdir(destination, { recursive: true });
execFileSync('tar', ['-xzf', 'source.tar.gz', '--strip-components=1', '-C', destination]);
}
await fetchSource('Workspace', sha, 'release');
const response = await fetch(`${base}/api/v1/repos/ShrinkSDK/Workspace/git/trees/${sha}?recursive=true`);
if (!response.ok) throw new Error(`Cannot resolve submodules: ${response.status}`);
const tree = await response.json();
for (const repo of ['ShrinkShared.CodeGen', 'ShrinkNetwork']) {
const path = `Assets/Modules/${repo}`;
const entry = tree.tree.find(item => item.path === path && item.type === 'commit');
if (!entry) throw new Error(`Missing pinned submodule: ${path}`);
await fetchSource(repo, entry.sha, `release/${path}`);
}
NODE
- name: Install .NET 8 SDK
shell: bash
run: |
set -euo pipefail
node --input-type=module <<'NODE'
import { writeFile } from 'node:fs/promises';
import { rootCertificates } from 'node:tls';
await writeFile('/opt/ca-certificates.crt', rootCertificates.join('\n'));
const metadataResponse = await fetch('https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/8.0/releases.json');
if (!metadataResponse.ok) throw new Error(`Release metadata download failed: ${metadataResponse.status}`);
const metadata = await metadataResponse.json();
const sdkVersion = metadata['latest-sdk'];
const release = metadata.releases.find(item => item.sdk?.version === sdkVersion);
const file = release?.sdk?.files?.find(item => item.rid === 'linux-x64' && item.name.endsWith('.tar.gz'));
if (!file) throw new Error(`Linux x64 SDK archive not found for ${sdkVersion}`);
const archiveResponse = await fetch(file.url);
if (!archiveResponse.ok) throw new Error(`SDK download failed: ${archiveResponse.status}`);
await writeFile('/tmp/dotnet-sdk.tar.gz', new Uint8Array(await archiveResponse.arrayBuffer()));
const poolUrl = 'https://deb.debian.org/debian-security/pool/updates/main/o/openssl/';
const poolResponse = await fetch(poolUrl);
if (!poolResponse.ok) throw new Error(`OpenSSL package index download failed: ${poolResponse.status}`);
const poolIndex = await poolResponse.text();
const packages = [...poolIndex.matchAll(/href="(libssl3_[^"]+_amd64\.deb)"/g)].map(match => match[1]).sort();
const packageName = packages.at(-1);
if (!packageName) throw new Error('Debian libssl3 package was not found');
const packageResponse = await fetch(poolUrl + packageName);
if (!packageResponse.ok) throw new Error(`OpenSSL package download failed: ${packageResponse.status}`);
await writeFile('/tmp/libssl3.deb', new Uint8Array(await packageResponse.arrayBuffer()));
NODE
mkdir -p /opt/dotnet
tar -xzf /tmp/dotnet-sdk.tar.gz -C /opt/dotnet
mkdir -p /opt/dotnet-libs
dpkg-deb -x /tmp/libssl3.deb /opt/dotnet-libs
rm -f /tmp/dotnet-sdk.tar.gz
rm -f /tmp/libssl3.deb
/opt/dotnet/dotnet --info
- name: Build supplemental NuGet packages
shell: bash
run: |
set -euo pipefail
export PATH="/opt/dotnet:$PATH"
cd release
projects=(
Assets/ShrinkInspection/DotNet~/ShrinkSDK.Inspection.csproj
Assets/Modules/ShrinkNetwork/Adapters~/MessagePack/ShrinkSDK.Network.MessagePack.csproj
Tools/AgentSupport/Shrink.Inspect/Shrink.Inspect.csproj
)
for project in "${projects[@]}"; do
dotnet restore "$project" --configfile Assets/Modules/ShrinkNetwork/NuGet.Config
dotnet pack "$project" -c Release --no-restore -o "$PWD/packages"
done
- name: Publish NuGet and UPM packages
shell: bash
run: |
set -euo pipefail
: "${NUGET_AUTH_TOKEN:?SHRINKSDK_PACKAGE_TOKEN is required}"
export PATH="/opt/dotnet:$PATH"
cd release
dotnet nuget push 'packages/*.nupkg' --api-key "$NUGET_AUTH_TOKEN" --source https://git.crash.work/api/packages/ShrinkSDK/nuget/index.json --skip-duplicate
npmrc="$HOME/.npmrc"
trap 'rm -f "$npmrc"' EXIT
printf '%s\n' \
'registry=https://git.crash.work/api/packages/ShrinkSDK/npm/' \
'//git.crash.work/api/packages/ShrinkSDK/npm/:_authToken=${NODE_AUTH_TOKEN}' > "$npmrc"
for package in Assets/ShrinkInspection Assets/Modules/ShrinkNetwork/Adapters~/MessagePack; do
# Stage only Unity source and documentation; dotnet build output is not a UPM asset.
stage="$PWD/upm-$(basename "$package")"
mkdir "$stage"
cp "$package/package.json" "$package/README.md" "$stage/"
cp -r "$package/Runtime" "$stage/"
if [[ -d "$package/Editor" ]]; then cp -r "$package/Editor" "$stage/"; fi
find "$package" -maxdepth 1 -name '*.meta' -exec cp '{}' "$stage/" \;
name="$(node -p "require('./$package/package.json').name")"
version="$(node -p "require('./$package/package.json').version")"
export PACKAGE_NAME="$name" PACKAGE_VERSION="$version"
exists="$(node --input-type=module <<'NODE'
const url = `https://git.crash.work/api/packages/ShrinkSDK/npm/${encodeURIComponent(process.env.PACKAGE_NAME)}`;
const response = await fetch(url);
if (response.status === 404) console.log('no');
else {
if (!response.ok) throw new Error(`Registry lookup failed: ${response.status}`);
const metadata = await response.json();
console.log(metadata.versions?.[process.env.PACKAGE_VERSION] ? 'yes' : 'no');
}
NODE
)"
if [[ "$exists" = yes ]]; then echo "Already published: $name@$version"; continue; fi
(cd "$stage" && npm publish --registry=https://git.crash.work/api/packages/ShrinkSDK/npm/)
done
+23 -4
View File
@@ -7,7 +7,29 @@ on:
workflow_dispatch:
jobs:
catalog:
runs-on: ubuntu-latest
container:
image: docker.m.daocloud.io/library/node:22-bookworm
permissions:
contents: read
steps:
- name: Validate submodules and version catalog
shell: bash
run: |
set -euo pipefail
ref="${{ gitea.sha }}"
git init .
git remote add origin "https://git.crash.work/ShrinkSDK/Workspace.git"
git fetch --depth=1 origin "$ref"
git checkout --detach FETCH_HEAD
git submodule sync --recursive
git submodule update --init --recursive
bash Tools/CI/Validate-Submodules.sh "$PWD"
node Tools/Release/update-shrinksdk-versions.mjs --check
unity:
needs: catalog
runs-on: unity-2022.3.62f3
container:
image: docker.1panel.live/unityci/editor:ubuntu-2022.3.62f3-windows-mono-3
@@ -30,10 +52,7 @@ jobs:
git checkout --detach FETCH_HEAD
git submodule sync --recursive
git submodule update --init --recursive
module_count="$(git submodule status --recursive | wc -l | tr -d ' ')"
test "$module_count" = "21"
test -z "$(git submodule status --recursive | grep '^-')"
git submodule status --recursive
bash Tools/CI/Validate-Submodules.sh "$PWD"
- name: Compile Workspace and validate package graph
shell: bash
+10
View File
@@ -45,6 +45,9 @@ ExportedObj/
*.unityproj
*.sln
*.csproj
!Tools/**/*.csproj
Tools/**/bin/
Tools/**/obj/
*.suo
*.tmp
*.user
@@ -79,6 +82,8 @@ mono_crash.*
# namespace-suffixed Unity Integration.App packages in source control.
!Assets/Modules/*.Integration.App/
!Assets/Modules/*.Integration.App/**
!Godot/Packages/*.Integration.App/
!Godot/Packages/*.Integration.App/**
# Crashlytics generated file
crashlytics-build.properties
@@ -144,3 +149,8 @@ GeneratedServers/ExampleGreedMod.Rules/*
!GeneratedServers/ExampleGreedMod.Rules/pack-mod.ps1
GeneratedModSdk/
.mimosa/
!Assets/ShrinkInspection/DotNet~/*.csproj
Assets/ShrinkInspection/DotNet~/bin/
Assets/ShrinkInspection/DotNet~/obj/
+8
View File
@@ -82,3 +82,11 @@
path = Assets/Modules/ShrinkInstaller
url = https://git.crash.work/ShrinkSDK/Installer.git
branch = main
[submodule "Assets/Modules/ShrinkRuntime.Abstractions"]
path = Assets/Modules/ShrinkRuntime.Abstractions
url = https://git.crash.work/ShrinkSDK/ShrinkRuntime.Abstractions.git
branch = main
[submodule "Godot/Packages/ShrinkSDK.Godot"]
path = Godot/Packages/ShrinkSDK.Godot
url = https://git.crash.work/ShrinkSDK/ShrinkGodot.git
branch = main
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2319a25c4ac4b0941824ffb1fbfadcf4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 908affa5f1a95214fa21a165799e7e56
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,29 @@
using System.IO;
using UnityEditor;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;
[InitializeOnLoad]
public static class PlayerAcceptance
{
private static readonly TestRunnerApi Api;
static PlayerAcceptance() { Api = ScriptableObject.CreateInstance<TestRunnerApi>(); Api.RegisterCallbacks(new Results()); }
public static string Run()
{
SessionState.SetBool("Shrink.PlayerAcceptance.Active", true);
return Api.Execute(new ExecutionSettings(new Filter { testMode = TestMode.PlayMode, assemblyNames = new[] { "ShrinkSDK.AgentSupport.PlayerTests" }, targetPlatform = BuildTarget.StandaloneWindows64 }));
}
private sealed class Results : ICallbacks
{
public void RunStarted(ITestAdaptor tests) { }
public void TestStarted(ITestAdaptor test) { }
public void TestFinished(ITestResultAdaptor result) { }
public void RunFinished(ITestResultAdaptor result)
{
if (!SessionState.GetBool("Shrink.PlayerAcceptance.Active", false)) return;
SessionState.SetBool("Shrink.PlayerAcceptance.Active", false);
Directory.CreateDirectory("Artifacts/AgentSupport");
File.WriteAllText("Artifacts/AgentSupport/unity-player-results.xml", result.ToXml().OuterXml);
Debug.Log("Shrink Player acceptance: " + result.PassCount + " passed, " + result.FailCount + " failed.");
}
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 9f9b07df5ab1dc345be31f33e94077d2
guid: 84cf42c70f18cd84b9cdca62969b6af8
MonoImporter:
externalObjects: {}
serializedVersion: 2
@@ -0,0 +1,11 @@
{
"name": "ShrinkSDK.AgentSupport.EditorTests",
"references": [],
"includePlatforms": [
"Editor"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"autoReferenced": false
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 9285a23e48a9fd04ea5d3a7507010d2b
guid: c7d77cac6e21f93479774330dd7bda65
AssemblyDefinitionImporter:
externalObjects: {}
userData:
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: fdcff332146fc1d439fc0c82285637da
guid: 566d8dd60d1f29a42857bf011769527c
folderAsset: yes
DefaultImporter:
externalObjects: {}
@@ -0,0 +1,120 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Cysharp.Threading.Tasks;
using NUnit.Framework;
using ShrinkContext;
using ShrinkNetwork;
using ShrinkEventBus;
using UnityEngine.TestTools;
public sealed class PlayerContracts
{
[Test]
public void DotNetGoldenFrameIsIdenticalInPlayer()
{
var bytes = UnityEngine.Resources.Load<UnityEngine.TextAsset>("ShrinkV2Golden").bytes;
var packet = ShrinkPacketCodec.Decode(bytes);
var codec = new ShrinkJsonNetworkSerializer();
var message = (Message)codec.Deserialize(packet.Payload, typeof(Message));
Assert.That(message.Text, Is.EqualTo("跨宿主-v2"));
using var encoded = ShrinkPacketCodec.Encode(new ShrinkNetworkPacket { Opcode = 42, Route = "跨宿主" }, codec, message);
Assert.That(encoded.WrittenMemory.ToArray(), Is.EqualTo(bytes));
}
[Test]
public void BinaryEnvelopeAndLegacyRejection()
{
var codec = new ShrinkJsonNetworkSerializer();
foreach (var size in new[] { 64, 1024, 32768 })
{
var message = new Message { Text = new string('x', size) };
using var frame = ShrinkPacketCodec.Encode(new ShrinkNetworkPacket { Opcode = 42, Route = "跨宿主" }, codec, message);
var packet = ShrinkPacketCodec.Decode(frame.WrittenMemory);
Assert.That(((Message)codec.Deserialize(packet.Payload, typeof(Message))).Text, Is.EqualTo(message.Text));
var copy = frame.WrittenMemory.ToArray(); copy[4] = 1;
Assert.Throws<ShrinkProtocolException>(() => ShrinkPacketCodec.Decode(copy));
}
}
[UnityTest]
public IEnumerator ContextTenThousandRetirements() => UniTask.ToCoroutine(async () =>
{
var runtime = new ShrinkContextRuntime(16);
var watch = Stopwatch.StartNew();
for (var i = 0; i < 10000; i++) await runtime.RetireAsync(runtime.Use(new Provider()));
Assert.That(runtime.Fibers.Count, Is.Zero);
Assert.That(runtime.CaptureDiagnostic().Fibers.Count, Is.EqualTo(16));
UnityEngine.Debug.Log("PLAYER Context 10000 retirements ms=" + watch.Elapsed.TotalMilliseconds);
await runtime.ShutdownAsync();
});
[Test]
public void EventDispatchAllocations()
{
using var binding = ShrinkGeneratedBinding.Subscribe<Event>(ShrinkGeneratedBinding.RuntimeResolver, null, null, null, _ => { }, ShrinkEventPriority.Normal, 0, false);
for (var i = 0; i < 100; i++) EventBus.Post(new Event());
var watch = Stopwatch.StartNew();
for (var i = 0; i < 10000; i++) EventBus.Post(new Event());
watch.Stop();
var events=PlayerPerformance.AllocationEvents(() => EventBus.Post(new Event()),10000);
UnityEngine.Debug.Log("PLAYER EventBus 10000 posts allocationEvents="+events+" ms="+watch.Elapsed.TotalMilliseconds);
using var host=new ShrinkEventBusHost();
var local=host.CreateBus(ShrinkBusKey.Game,ShrinkBusOptions.Inline());
using var localBinding=ShrinkGeneratedBinding.Subscribe<Event>(host,null,null,null,_=>{},ShrinkEventPriority.Normal,0,false);
for(var i=0;i<100;i++) local.Post(new Event());
var isolatedEvents=PlayerPerformance.AllocationEvents(()=>local.Post(new Event()),10000);
UnityEngine.Debug.Log("PLAYER EventBus isolated 10000 posts allocationEvents="+isolatedEvents);
Assert.That(isolatedEvents,Is.Zero);
Assert.Throws<ArgumentNullException>(()=>local.Post<ReferenceEvent>(null));
}
[UnityTest]
public IEnumerator LoopbackRpc() => UniTask.ToCoroutine(async () =>
{
var a = new ShrinkLoopbackTransport(); var b = new ShrinkLoopbackTransport(); a.LinkPeer(b);
var client = new ShrinkNetworkService(); var server = new ShrinkNetworkService();
foreach (var service in new[] { client, server }) { service.RegisterMessage<Request>(1); service.RegisterMessage<Response>(2); }
server.RegisterRequestHandler<Request, Response>((_, r) => UniTask.FromResult(new Response { Text = r.Text }));
client.BindTransport(a); server.BindTransport(b); a.OpenSession(1);
try { Assert.That((await client.CallAsync<Request, Response>(client.Sessions[1], new Request { Text = "Unity Player" })).Text, Is.EqualTo("Unity Player")); }
finally { a.Stop(); b.Stop(); }
});
[UnityTest]
public IEnumerator SavePhaseMatrix() => UniTask.ToCoroutine(async () =>
{
var root = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "ShrinkPlayerSave-" + Guid.NewGuid().ToString("N"));
var storage = new ShrinkDataSaver.LocalStorageProvider(root);
var initialize = typeof(ShrinkDataSaver.ShrinkSave).GetMethod("Initialize", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
initialize.Invoke(null, new object[] { storage, System.IO.Path.Combine(root, "saves"), ".sav", 1 });
try
{
foreach (var size in new[] { 100 * 1024, 1024 * 1024, 10 * 1024 * 1024 })
foreach (var background in new[] { false, true })
{
var value = new string('s', size); var owner = System.Threading.Thread.CurrentThread.ManagedThreadId; var captureThread = -1;
ShrinkDataSaver.ShrinkSave.RegisterModule("player-benchmark", () => { captureThread = System.Threading.Thread.CurrentThread.ManagedThreadId; return value; }, _ => { });
var options = new ShrinkDataSaver.SaveOptions { EncodeInBackground = background, CollectTimings = true };
await ShrinkDataSaver.ShrinkSave.SaveSlotAsync(0, options);
Assert.That(captureThread, Is.EqualTo(owner));
Assert.That(options.LastTimings.EncodedBytes, Is.GreaterThan(size));
UnityEngine.Debug.Log("PLAYER Save " + size + " background=" + background + " " + "captureMs=" + options.LastTimings.CaptureMilliseconds + " encodeMs=" + options.LastTimings.EncodeMilliseconds + " encryptMs=" + options.LastTimings.EncryptMilliseconds + " writeMs=" + options.LastTimings.WriteMilliseconds + " bytes=" + options.LastTimings.EncodedBytes);
}
}
finally
{
ShrinkDataSaver.ShrinkSave.UnregisterModule("player-benchmark");
if (System.IO.Directory.Exists(root)) System.IO.Directory.Delete(root, true);
}
});
public sealed class Message : IShrinkNetworkMessage { public string Text { get; set; } }
public sealed class Request : IShrinkNetworkRequest { public string Text { get; set; } }
public sealed class Response : ShrinkRpcResponseBase { public string Text { get; set; } }
public readonly struct Event : IShrinkEvent { }
public sealed class ReferenceEvent : IShrinkEvent { }
private sealed class Provider : IShrinkComponent
{
public string Name => "test";
public IReadOnlyList<string> Inject => Array.Empty<string>();
public IReadOnlyList<string> Provide => new[] { "value" };
public UniTask ApplyAsync(ShrinkCtx ctx, object config) { ctx.Set("value", this); return UniTask.CompletedTask; }
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 531de603668484545b5993c8f4894027
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,139 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Cysharp.Threading.Tasks;
using NUnit.Framework;
using ShrinkContext;
using ShrinkEventBus;
using ShrinkNetwork;
using UnityEngine.TestTools;
using Unity.Profiling;
public sealed class PlayerPerformance
{
private static byte[] _allocationProbe;
public static long AllocationEvents(Action action, int count)
{
using var recorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, "GC.Alloc", 65536,
ProfilerRecorderOptions.StartImmediately | ProfilerRecorderOptions.CollectOnlyOnCurrentThread);
if (!recorder.Valid) throw new InvalidOperationException("GC.Alloc recorder unavailable.");
for (var i=0;i<count;i++) action();
recorder.Stop();
if (recorder.Count == recorder.Capacity) throw new InvalidOperationException("GC.Alloc recorder saturated.");
return recorder.Count;
}
[Test]
public void AllocationCounterDetectsKnownAllocation()
{
var before=GC.GetAllocatedBytesForCurrentThread();
_allocationProbe=new byte[1024];
var delta=GC.GetAllocatedBytesForCurrentThread()-before;
var events=AllocationEvents(() => _allocationProbe=new byte[1024],10);
GC.KeepAlive(_allocationProbe);
Assert.That(events,Is.GreaterThanOrEqualTo(10));
UnityEngine.Debug.Log("PLAYER allocation calibration managedCounterDelta="+delta+" profilerEvents="+events+"; use profiler events, not uncalibrated bytes.");
}
private static void Measure(string scenario, int count, Action action)
{
for (var i = 0; i < Math.Min(count, 20); i++) action();
var latency = new double[count];
var started = Stopwatch.GetTimestamp();
for (var i = 0; i < count; i++)
{
var tick = Stopwatch.GetTimestamp(); action();
latency[i] = (Stopwatch.GetTimestamp() - tick) * 1e6 / Stopwatch.Frequency;
}
var elapsed = (Stopwatch.GetTimestamp() - started) / (double)Stopwatch.Frequency;
Array.Sort(latency);
var allocationSamples=Math.Min(count,10);
var allocationEvents=AllocationEvents(action,allocationSamples);
UnityEngine.Debug.Log(FormattableString.Invariant($"PLAYER PERF {scenario} n={count} ops={count/elapsed:F2} allocBytes=unsupported allocationSamples={allocationSamples} allocEventsPerOp={allocationEvents/(double)allocationSamples:F2} p50us={latency[(int)(count*.5)]:F2} p95us={latency[(int)(count*.95)]:F2} p99us={latency[(int)(count*.99)]:F2}"));
}
[UnityTest]
public IEnumerator NetworkMatrix() => UniTask.ToCoroutine(async () =>
{
foreach (var bytes in new[] {64, 1024, 32768})
foreach (var sessions in new[] {1, 32, 256})
{
var client = new ShrinkNetworkService(); var server = new ShrinkNetworkService();
var a = new ShrinkLoopbackTransport(); var b = new ShrinkLoopbackTransport(); a.LinkPeer(b);
foreach (var service in new[] {client, server})
{
service.RegisterMessage<PlayerContracts.Request>(1); service.RegisterMessage<PlayerContracts.Response>(2);
service.RegisterMessage<PlayerContracts.Message>(3);
}
server.RegisterRequestHandler<PlayerContracts.Request, PlayerContracts.Response>((_, request) => UniTask.FromResult(new PlayerContracts.Response {Text=request.Text}));
var delivered=0;
server.RegisterHandler<PlayerContracts.Message>((_, message) => { delivered++; return UniTask.CompletedTask; });
client.BindTransport(a); server.BindTransport(b);
for (var i=0;i<sessions;i++) a.OpenSession(i);
try
{
var request = new PlayerContracts.Request {Text=new string('x',bytes)}; var cursor=0;
Measure($"loopback-rpc/bytes={bytes}/sessions={sessions}", 128, () => client.CallAsync<PlayerContracts.Request,PlayerContracts.Response>(client.Sessions[cursor++%sessions],request).GetAwaiter().GetResult());
var payload = new ShrinkJsonNetworkSerializer().Serialize(new PlayerContracts.Message {Text=request.Text});
Measure($"loopback-broadcast/bytes={bytes}/sessions={sessions}", 20, () => {
foreach(var peer in client.Sessions.Values) client.SendSerializedAsync(peer,typeof(PlayerContracts.Message),payload).GetAwaiter().GetResult();
});
Assert.That(delivered,Is.EqualTo(50*sessions));
}
finally {a.Stop();b.Stop();}
await UniTask.Yield();
}
});
[Test]
public void ContextAndEventMatrix()
{
foreach(var count in new[] {10,100,1000})
{
var runtime=new ShrinkContextRuntime();
try
{
for(var i=0;i<count;i++) runtime.Use(new Component("k"+i,i==0?null:"k"+(i-1)));
Measure("context-diagnostic/components="+count,100,()=>runtime.CaptureDiagnostic());
}
finally {runtime.ShutdownAsync().GetAwaiter().GetResult();}
}
using(var binding=ShrinkGeneratedBinding.SubscribeAsync<PlayerContracts.Event>(ShrinkGeneratedBinding.RuntimeResolver,null,null,null,(_,__)=>UniTask.CompletedTask,ShrinkEventPriority.Normal,0,false))
{
Measure("event-async-completed",10000,()=>EventBus.PostAsync(new PlayerContracts.Event()).GetAwaiter().GetResult());
Measure("event-bindings",1000,()=>EventBus.CaptureBindings(EventBus.Default));
}
Measure("event-register-withdraw",10000,()=>ShrinkGeneratedBinding.Subscribe<PlayerContracts.Event>(ShrinkGeneratedBinding.RuntimeResolver,null,null,null,_=>{},ShrinkEventPriority.Normal,0,false).Dispose());
}
[UnityTest]
public IEnumerator SlowConsumerAndBurst() => UniTask.ToCoroutine(async () =>
{
using var queue=new ShrinkNetworkWorkQueue(64,65536);
var gate=new UniTaskCompletionSource();
var slow=queue.EnqueueAsync(1,"reliable",1024,()=>gate.Task);
var pumping=queue.PumpAsync(64,65536,TimeSpan.FromMilliseconds(1));
var results=new List<UniTask<ShrinkNetworkQueueResult>>();
for(var i=0;i<128;i++) results.Add(queue.EnqueueAsync(i%32,"state",1024,()=>UniTask.CompletedTask,"position"));
var before=queue.CaptureDiagnostics();
Assert.That(before.Replaced,Is.EqualTo(96));
await UniTask.Delay(10);
Assert.That(pumping.Status,Is.EqualTo(UniTaskStatus.Pending));
gate.TrySetResult(); await pumping; await slow;
await queue.PumpAsync(64);
foreach(var result in results) await result;
Assert.That(queue.PendingCount,Is.Zero);
UnityEngine.Debug.Log("PLAYER Queue pending="+before.PendingCount+" bytes="+before.PendingBytes+" replaced="+before.Replaced+" rejected="+before.Rejected);
});
private sealed class Component : IShrinkComponent
{
private readonly string _key;
public Component(string key,string dependency) { _key=key; Inject=dependency==null?Array.Empty<string>():new[]{dependency}; Provide=new[]{key}; }
public string Name=>_key;
public IReadOnlyList<string> Inject {get;}
public IReadOnlyList<string> Provide {get;}
public UniTask ApplyAsync(ShrinkCtx ctx,object config) {ctx.Set(_key,this);return UniTask.CompletedTask;}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1a11773fcfc6a5547942e45a40ce1c30
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 04969664a502f284e94ccfd427fc052c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7f13c1997933654439e4d4ffa612ae4c
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,17 @@
{
"name": "ShrinkSDK.AgentSupport.PlayerTests",
"references": [
"ShrinkContext.Core.Runtime",
"ShrinkEventBus.Runtime",
"ShrinkNetwork.Runtime",
"UniTask",
"ShrinkDataSaver.Runtime"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"autoReferenced": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ec966393c67534f4d9331d20dae2a555
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+140 -51
View File
@@ -2,9 +2,12 @@
#nullable enable
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;
@@ -13,30 +16,11 @@ namespace ShrinkSDK.WorkspaceValidation
{
public static class ShrinkSdkWorkspaceValidation
{
private static readonly ExpectedPackage[] ExpectedPackages =
{
new ExpectedPackage("ShrinkApp.Core", "com.cneicy.shrink-app-core", "0.1.4"),
new ExpectedPackage("ShrinkApp.Starter.Basic", "com.cneicy.shrink-app-starter-basic", "0.2.2"),
new ExpectedPackage("ShrinkCommand", "com.cneicy.shrink-command", "0.2.0"),
new ExpectedPackage("ShrinkCommand.Integration.App", "com.cneicy.shrink-command-integration-app", "0.1.3"),
new ExpectedPackage("ShrinkCommand.Integration.EventBus", "com.cneicy.shrink-command-integration-eventbus", "0.1.2"),
new ExpectedPackage("ShrinkCommand.Integration.Network", "com.cneicy.shrink-command-integration-network", "0.1.1"),
new ExpectedPackage("ShrinkContext.AppAdapter", "com.cneicy.shrink-context-app-adapter", "0.1.5"),
new ExpectedPackage("ShrinkContext.Core", "com.cneicy.shrink-context-core", "0.1.0"),
new ExpectedPackage("ShrinkContext.EventBusAdapter", "com.cneicy.shrink-context-eventbus-adapter", "0.1.1"),
new ExpectedPackage("ShrinkDataSaver", "com.cneicy.shrink-datasaver", "2.2.2"),
new ExpectedPackage("ShrinkDataSaver.Integration.App", "com.cneicy.shrink-datasaver-integration-app", "0.1.3"),
new ExpectedPackage("ShrinkDataSaver.Integration.EventBus", "com.cneicy.shrink-datasaver-integration-eventbus", "2.1.3"),
new ExpectedPackage("ShrinkEventBus", "com.cneicy.shrink-eventbus", "2.0.1"),
new ExpectedPackage("ShrinkEventBus.Entities", "com.cneicy.shrink-eventbus-entities", "0.1.1"),
new ExpectedPackage("ShrinkInstaller", "com.cneicy.shrink-installer", "0.2.4"),
new ExpectedPackage("ShrinkModFramework", "com.cneicy.shrink-mod-framework", "0.2.4"),
new ExpectedPackage("ShrinkNetwork", "com.cneicy.shrink-network", "0.2.1"),
new ExpectedPackage("ShrinkNetwork.Integration.App", "com.cneicy.shrink-network-integration-app", "0.1.3"),
new ExpectedPackage("ShrinkNetwork.Integration.EventBus", "com.cneicy.shrink-network-integration-eventbus", "0.1.3"),
new ExpectedPackage("ShrinkShared.CodeGen", "com.cneicy.shrink-shared-codegen", "0.1.0"),
new ExpectedPackage("ShrinkTutorial", "com.cneicy.shrink-tutorial", "0.1.4")
};
private const string InstallerPackageName = "com.cneicy.shrink-installer";
private const string InstallerCatalogTypeName = "ShrinkSDK.Installer.ShrinkSdkPackageCatalog";
private static readonly Regex SemanticVersion = new Regex(
@"^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$",
RegexOptions.CultureInvariant);
public static void Run()
{
@@ -45,6 +29,7 @@ namespace ShrinkSDK.WorkspaceValidation
var workspaceRoot = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
var packages = ReadPackages(workspaceRoot);
ValidateGraph(packages);
ValidateInstallerCatalog(packages);
Debug.Log($"ShrinkSDK Workspace validation passed: packages={packages.Count}");
EditorApplication.Exit(0);
}
@@ -57,36 +42,97 @@ namespace ShrinkSDK.WorkspaceValidation
private static Dictionary<string, PackageDefinition> ReadPackages(string workspaceRoot)
{
var result = new Dictionary<string, PackageDefinition>(StringComparer.Ordinal);
foreach (var expected in ExpectedPackages)
var modulesRoot = Path.Combine(workspaceRoot, "Assets", "Modules");
if (!Directory.Exists(modulesRoot))
{
var manifestPath = Path.Combine(workspaceRoot, "Assets", "Modules", expected.Directory, "package.json");
throw new DirectoryNotFoundException($"Workspace package directory is missing: {modulesRoot}");
}
var declaredDirectories = ReadDeclaredPackageDirectories(workspaceRoot);
var manifestDirectories = Directory.EnumerateDirectories(modulesRoot)
.Where(directory => File.Exists(Path.Combine(directory, "package.json")))
.Select(Path.GetFullPath)
.ToHashSet(StringComparer.OrdinalIgnoreCase);
var undeclared = manifestDirectories
.Where(directory => !declaredDirectories.Contains(directory))
.OrderBy(directory => directory, StringComparer.OrdinalIgnoreCase)
.ToArray();
if (undeclared.Length > 0)
{
throw new InvalidOperationException(
"Package directories are not declared as submodules: " + string.Join(", ", undeclared));
}
var result = new Dictionary<string, PackageDefinition>(StringComparer.Ordinal);
foreach (var directory in declaredDirectories.OrderBy(value => value, StringComparer.OrdinalIgnoreCase))
{
var manifestPath = Path.Combine(directory, "package.json");
if (!File.Exists(manifestPath))
{
throw new FileNotFoundException($"Required package manifest is missing: {expected.Directory}", manifestPath);
throw new FileNotFoundException("Declared package submodule has no package.json.", manifestPath);
}
var manifest = JObject.Parse(File.ReadAllText(manifestPath));
var packageName = manifest.Value<string>("name");
var version = manifest.Value<string>("version");
if (packageName == null || version == null || packageName.Length == 0 || version.Length == 0)
if (string.IsNullOrWhiteSpace(packageName) || string.IsNullOrWhiteSpace(version))
{
throw new InvalidOperationException($"{expected.Directory} has no valid package name or version.");
throw new InvalidOperationException($"{directory} has no valid package name or version.");
}
if (!string.Equals(packageName, expected.Name, StringComparison.Ordinal) ||
!string.Equals(version, expected.Version, StringComparison.Ordinal))
var validPackageName = packageName!;
var validVersion = version!;
if (!SemanticVersion.IsMatch(validVersion))
{
throw new InvalidOperationException(
$"{expected.Directory} must be {expected.Name}@{expected.Version}, found {packageName}@{version}.");
throw new InvalidOperationException($"{validPackageName} has an invalid semantic version: {validVersion}");
}
if (result.ContainsKey(packageName))
if (result.ContainsKey(validPackageName))
{
throw new InvalidOperationException($"Duplicate package manifest name: {packageName}");
throw new InvalidOperationException($"Duplicate package manifest name: {validPackageName}");
}
result.Add(packageName, new PackageDefinition(packageName, version, manifest));
result.Add(validPackageName, new PackageDefinition(validPackageName, validVersion, manifest));
}
return result;
}
private static HashSet<string> ReadDeclaredPackageDirectories(string workspaceRoot)
{
var gitModulesPath = Path.Combine(workspaceRoot, ".gitmodules");
if (!File.Exists(gitModulesPath))
{
throw new FileNotFoundException("Workspace .gitmodules is missing.", gitModulesPath);
}
var result = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var line in File.ReadLines(gitModulesPath))
{
var match = Regex.Match(line, @"^\s*path\s*=\s*(?<path>.+?)\s*$", RegexOptions.CultureInvariant);
if (!match.Success)
{
continue;
}
var relativePath = match.Groups["path"].Value.Replace('\\', '/');
if (!relativePath.StartsWith("Assets/Modules/", StringComparison.Ordinal) ||
relativePath.Substring("Assets/Modules/".Length).Contains("/"))
{
continue;
}
var fullPath = Path.GetFullPath(Path.Combine(workspaceRoot, relativePath));
if (!result.Add(fullPath))
{
throw new InvalidOperationException($"Duplicate package submodule path: {relativePath}");
}
}
if (result.Count == 0)
{
throw new InvalidOperationException("No Assets/Modules package submodules are declared.");
}
return result;
@@ -158,6 +204,63 @@ namespace ShrinkSDK.WorkspaceValidation
}
}
private static void ValidateInstallerCatalog(IReadOnlyDictionary<string, PackageDefinition> packages)
{
var catalogType = AppDomain.CurrentDomain.GetAssemblies()
.Select(assembly => assembly.GetType(InstallerCatalogTypeName, false))
.FirstOrDefault(type => type != null)
?? throw new InvalidOperationException($"Installer catalog type was not loaded: {InstallerCatalogTypeName}");
var packagesField = catalogType.GetField("Packages", BindingFlags.Static | BindingFlags.NonPublic)
?? throw new InvalidOperationException("Installer catalog Packages field was not found.");
var catalogItems = packagesField.GetValue(null) as IEnumerable
?? throw new InvalidOperationException("Installer catalog Packages field is not enumerable.");
var catalog = new Dictionary<string, string>(StringComparer.Ordinal);
foreach (var item in catalogItems)
{
if (item == null)
{
throw new InvalidOperationException("Installer catalog contains a null package entry.");
}
var itemType = item.GetType();
var packageName = itemType.GetProperty("PackageName")?.GetValue(item) as string;
var version = itemType.GetProperty("Version")?.GetValue(item) as string;
if (string.IsNullOrWhiteSpace(packageName) || string.IsNullOrWhiteSpace(version))
{
throw new InvalidOperationException("Installer catalog contains an invalid package entry.");
}
var validPackageName = packageName!;
var validVersion = version!;
if (!catalog.TryAdd(validPackageName, validVersion))
{
throw new InvalidOperationException($"Installer catalog contains duplicate package: {validPackageName}");
}
}
var expectedNames = packages.Keys
.Where(name => !string.Equals(name, InstallerPackageName, StringComparison.Ordinal))
.ToHashSet(StringComparer.Ordinal);
var missing = expectedNames.Except(catalog.Keys).OrderBy(name => name, StringComparer.Ordinal).ToArray();
var unexpected = catalog.Keys.Except(expectedNames).OrderBy(name => name, StringComparer.Ordinal).ToArray();
if (missing.Length > 0 || unexpected.Length > 0)
{
throw new InvalidOperationException(
$"Installer catalog package set differs from Workspace. Missing=[{string.Join(", ", missing)}], " +
$"unexpected=[{string.Join(", ", unexpected)}]");
}
foreach (var packageName in expectedNames)
{
if (!string.Equals(catalog[packageName], packages[packageName].Version, StringComparison.Ordinal))
{
throw new InvalidOperationException(
$"Installer catalog requires {packageName} {catalog[packageName]}, but the Workspace provides {packages[packageName].Version}.");
}
}
}
private sealed class PackageDefinition
{
public PackageDefinition(string name, string version, JObject manifest)
@@ -171,20 +274,6 @@ namespace ShrinkSDK.WorkspaceValidation
public string Version { get; }
public JObject Manifest { get; }
}
private readonly struct ExpectedPackage
{
public ExpectedPackage(string directory, string name, string version)
{
Directory = directory;
Name = name;
Version = version;
}
public string Directory { get; }
public string Name { get; }
public string Version { get; }
}
}
}
#endif
@@ -1,5 +0,0 @@
{
"name": "ShrinkRuntime.Abstractions",
"rootNamespace": "ShrinkSDK.Runtime",
"autoReferenced": true
}
@@ -1,127 +0,0 @@
#nullable enable
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace ShrinkSDK.Runtime
{
public enum ShrinkLogLevel { Trace, Debug, Information, Warning, Error }
public interface IShrinkLogger
{
void Log(ShrinkLogLevel level, string message, Exception? exception = null);
}
public interface IShrinkMainThreadDispatcher
{
bool IsMainThread { get; }
bool TryPost(Action action);
}
public interface IShrinkClock
{
DateTimeOffset UtcNow { get; }
double UnscaledTimeSeconds { get; }
}
public interface IShrinkPathProvider
{
string PersistentDataPath { get; }
string TemporaryDataPath { get; }
}
public interface IShrinkScreenshotProvider
{
ValueTask<byte[]> CapturePngAsync(CancellationToken cancellationToken = default);
}
public interface IShrinkApplicationLifecycle
{
event Action? Paused;
event Action? Resumed;
event Action? Exiting;
}
public static class ShrinkLoggerExtensions
{
public static void Error(this IShrinkLogger logger, string message, Exception? exception = null) =>
logger.Log(ShrinkLogLevel.Error, message, exception);
}
public static class ShrinkRuntimeServices
{
private static IShrinkLogger _logger = new ConsoleLogger();
private static IShrinkMainThreadDispatcher _dispatcher = new InlineDispatcher();
private static IShrinkClock _clock = new SystemClock();
private static IShrinkPathProvider _paths = new SystemPaths();
public static IShrinkLogger Logger => _logger;
public static IShrinkMainThreadDispatcher Dispatcher => _dispatcher;
public static IShrinkClock Clock => _clock;
public static IShrinkPathProvider Paths => _paths;
public static IShrinkScreenshotProvider? Screenshots { get; private set; }
public static IShrinkApplicationLifecycle? Lifecycle { get; private set; }
public static void Configure(IShrinkLogger logger, IShrinkMainThreadDispatcher dispatcher,
IShrinkClock clock, IShrinkPathProvider paths,
IShrinkScreenshotProvider? screenshots = null, IShrinkApplicationLifecycle? lifecycle = null)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
_clock = clock ?? throw new ArgumentNullException(nameof(clock));
_paths = paths ?? throw new ArgumentNullException(nameof(paths));
Screenshots = screenshots;
Lifecycle = lifecycle;
}
private sealed class ConsoleLogger : IShrinkLogger
{
public void Log(ShrinkLogLevel level, string message, Exception? exception = null)
{
Console.WriteLine($"[{level}] {message}");
if (exception != null) Console.WriteLine(exception);
}
}
private sealed class InlineDispatcher : IShrinkMainThreadDispatcher
{
public bool IsMainThread => true;
public bool TryPost(Action action)
{
if (action == null) return false;
action();
return true;
}
}
private sealed class SystemClock : IShrinkClock
{
private readonly Stopwatch _stopwatch = Stopwatch.StartNew();
public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
public double UnscaledTimeSeconds => _stopwatch.Elapsed.TotalSeconds;
}
private sealed class SystemPaths : IShrinkPathProvider
{
public string PersistentDataPath => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ShrinkSDK");
public string TemporaryDataPath => Path.GetTempPath();
}
}
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public sealed class ShrinkCodeGenWovenAttribute : Attribute
{
public ShrinkCodeGenWovenAttribute(string weaverVersion, string inputMvid)
{
WeaverVersion = weaverVersion;
InputMvid = inputMvid;
}
public string WeaverVersion { get; }
public string InputMvid { get; }
}
}
@@ -1,7 +0,0 @@
{
"name": "com.cneicy.shrink-runtime-abstractions",
"version": "0.1.0",
"displayName": "ShrinkSDK Runtime Abstractions",
"description": "Engine-neutral runtime services and CodeGen marker contracts.",
"unity": "2022.3"
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 13ee6beaa5cda4a4da34954ba6f00e7a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup><TargetFramework>netstandard2.1</TargetFramework><LangVersion>latest</LangVersion><Nullable>enable</Nullable><EnableDefaultCompileItems>false</EnableDefaultCompileItems><PackageId>ShrinkSDK.Inspection</PackageId><Version>0.1.0</Version><AssemblyName>ShrinkInspection.Runtime</AssemblyName></PropertyGroup>
<ItemGroup>
<Compile Include="../Runtime/**/*.cs" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="ShrinkSDK.Context.Core" Version="0.3.0" />
<PackageReference Include="ShrinkSDK.EventBus" Version="2.2.2" />
<PackageReference Include="ShrinkSDK.Network" Version="0.4.2" />
<PackageReference Include="ShrinkSDK.Command" Version="0.4.2" />
</ItemGroup>
</Project>
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2274a33f3eae9774db82c4e478f2f90d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,6 @@
{
"name": "ShrinkInspection.Editor",
"references": ["ShrinkInspection.Runtime", "ShrinkContext.Core.Runtime", "ShrinkEventBus.Runtime", "Newtonsoft.Json"],
"includePlatforms": ["Editor"],
"autoReferenced": true
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8a20e065e3e35a94e9e3c1c29328219f
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,61 @@
#nullable enable
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEditor;
using UnityEditor.Compilation;
using UnityEngine;
using ShrinkContext;
using ShrinkEventBus;
namespace ShrinkSDK.Inspection.Editor
{
public static class ShrinkInspectionExport
{
private const string DirectoryName = "Artifacts/Inspection";
/// <summary>Host extensions add explicitly owned Network/Command/Context instances. Remove handlers when the host shuts down.</summary>
public static event Action<ShrinkInspectionSnapshot>? CaptureHostState;
[MenuItem("Tools/ShrinkSDK/Inspection/Export compilation inputs")]
public static void ExportCompilation()
{
RequireStableEditor();
var root = Path.GetFullPath(".");
var assemblies = CompilationPipeline.GetAssemblies(AssembliesType.Player);
var loaded = AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic).Select(a => a.GetName().Name).ToHashSet();
var identityNames = assemblies.Select(a => a.name).Where(loaded.Contains).OrderBy(n => n, StringComparer.Ordinal).ToArray();
var inputs = assemblies.Select(a => new { Name = a.name, Sources = a.sourceFiles.Select(Path.GetFullPath).ToArray(),
References = a.allReferences.Select(Path.GetFullPath).Where(File.Exists).ToArray(), Defines = a.defines, Output = Path.GetFullPath(a.outputPath) }).ToArray();
var ticks = inputs.SelectMany(a => a.Sources.Concat(a.References)).Distinct(StringComparer.OrdinalIgnoreCase)
.ToDictionary(path => path, path => File.GetLastWriteTimeUtc(path).Ticks);
Directory.CreateDirectory(DirectoryName);
File.WriteAllText(DirectoryName + "/compilation.json", JsonConvert.SerializeObject(new { Root = root,
BuildId = ShrinkInspectionSnapshot.BuildIdentity(identityNames), IdentityAssemblies = identityNames, Assemblies = inputs, SourceTicks = ticks }, Formatting.Indented));
Debug.Log("Shrink inspection compilation exported: " + Path.GetFullPath(DirectoryName + "/compilation.json"));
}
[MenuItem("Tools/ShrinkSDK/Inspection/Export runtime snapshot")]
public static void ExportRuntime()
{
RequireStableEditor();
var path = DirectoryName + "/compilation.json";
if (!File.Exists(path)) throw new InvalidOperationException("Export compilation inputs first.");
var manifest = JsonConvert.DeserializeObject<IdentityManifest>(File.ReadAllText(path))!;
var snapshot = new ShrinkInspectionSnapshot(ShrinkInspectionSnapshot.BuildIdentity(manifest.IdentityAssemblies));
snapshot.AddContext("default-context", ShrinkContextDefaults.Default);
var ordinal = 0;
foreach (var bus in EventBus.CaptureNamedBuses()) snapshot.AddEventBus("named-bus-" + ordinal++, bus);
snapshot.Coverage.Add("Default Context and named EventBus instances only; host-owned instances require CaptureHostState registration.");
CaptureHostState?.Invoke(snapshot);
File.WriteAllText(DirectoryName + "/runtime.json", snapshot.ToJson());
Debug.Log("Shrink inspection runtime exported: " + Path.GetFullPath(DirectoryName + "/runtime.json"));
}
private static void RequireStableEditor()
{
if (EditorApplication.isCompiling || EditorApplication.isUpdating) throw new InvalidOperationException("Wait for Editor compilation/import to finish.");
}
private sealed class IdentityManifest { public string[] IdentityAssemblies = Array.Empty<string>(); }
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 35c6f0febfce34543a9efb401ce8b3b6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+23
View File
@@ -0,0 +1,23 @@
# Shrink Inspection
可选诊断接入包,提供 Unity 编译输入导出和跨 Unity/Godot/.NET 的按需绑定快照。它依赖被观察模块,不进入它们的热路径。
Unity 安装本目录的 UPM 包后,使用 `Tools/ShrinkSDK/Inspection` 导出编译输入和运行快照。结果位于项目的 `Artifacts/Inspection`。在命令行使用:
```text
shrink inspect flow command:execute --compilation Artifacts/Inspection/compilation.json --snapshot Artifacts/Inspection/runtime.json
```
编辑器默认只捕获默认 Context 与命名 EventBus。宿主持有的独立实例通过 `ShrinkInspectionExport.CaptureHostState` 按需加入;宿主退出时取消该委托,避免诊断代码持有已退役对象。`AddContext` 可同时传入 Loader,记录最近事务的阶段和恢复结果。
Godot/.NET 使用 `ShrinkSDK.Inspection` 和相同的 `ShrinkInspectionSnapshot` API。宿主在所属线程创建快照,调用 `AddContext`、`AddNetwork`、`AddEventBus`、`AddCommands`,再写入 `ToJson()`。构建标识由明确的程序集名集合计算;必须与编译输入的程序集集合和 MVID 一致。未知构建不能通过手写相同字符串伪装为已验证关联。
捕获时暂停同一实例的注册、退役和组合修改。快照只含符号、状态和计数;不含消息正文、会话令牌、存档内容及异常文本。它记录快照时刻的绑定,不提供完整调用时序。不同 scope 的绑定不能拼成已经确认的端到端调用。
<!-- shrink:capabilities -->
Capability: 导出真实编译输入、Context/provider 状态、EventBus/Network/Command 当前绑定及队列指标
Aliases: 导航 调试 诊断 快照 inspect snapshot 调用链
Limits: 按需快照,不是调用时序追踪;只覆盖显式加入的实例;过期或不同构建不能合并
Extension: 宿主在所属线程调用 AddContext/AddNetwork/AddEventBus/AddCommands,Unity 使用 CaptureHostState
Evidence: [快照 API](Runtime/ShrinkInspectionSnapshot.cs); [Unity 导出](Editor/ShrinkInspectionExport.cs)
<!-- /shrink:capabilities -->
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f566b821eafe5fa498c7504ccf0d40aa
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 87749fd61a2f5e44aab3896a7a873b38
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,6 @@
{
"name": "ShrinkInspection.Runtime",
"references": ["ShrinkContext.Core.Runtime", "ShrinkEventBus.Runtime", "ShrinkNetwork.Runtime", "ShrinkCommand.Runtime", "Newtonsoft.Json"],
"autoReferenced": true,
"noEngineReferences": true
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4210356b49bcdf240ad3c08659b7f720
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,102 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
using ShrinkContext;
using ShrinkEventBus;
using ShrinkNetwork;
using ShrinkCommand;
namespace ShrinkSDK.Inspection
{
public sealed class ShrinkInspectionRelation
{
public string From = "";
public string To = "";
public string Kind = "";
public string Scope = "";
}
/// <summary>Explicit, on-demand snapshot. Call from the owning host thread while registration/composition is stable.</summary>
public sealed class ShrinkInspectionSnapshot
{
public int FormatVersion = 1;
public string BuildId = "";
public string CapturedAtUtc = DateTime.UtcNow.ToString("O");
public readonly List<string> Coverage = new();
public readonly List<ShrinkInspectionRelation> Relations = new();
public readonly Dictionary<string, object> State = new();
public static string BuildIdentity(IEnumerable<string> assemblyNames)
{
var loaded = AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic).ToArray();
var identity = string.Join(";", assemblyNames.Distinct().OrderBy(n => n, StringComparer.Ordinal).Select(name =>
{
var candidates = loaded.Where(a => a.GetName().Name == name).ToArray();
if (candidates.Length != 1) throw new InvalidOperationException("Cannot establish unique runtime assembly identity: " + name);
return name + ":" + candidates[0].ManifestModule.ModuleVersionId.ToString("N");
}));
using var sha = System.Security.Cryptography.SHA256.Create();
return BitConverter.ToString(sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(identity))).Replace("-", "").ToLowerInvariant();
}
public ShrinkInspectionSnapshot(string buildId) { BuildId = buildId; }
public string ToJson() => JsonConvert.SerializeObject(this, Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter());
public void AddContext(string scope, ShrinkContextRuntime runtime, ShrinkContextLoader? loader = null)
{
var snapshot = runtime.CaptureDiagnostic();
State.Add(scope, new { snapshot.BindingCount, snapshot.Notifications,
Fibers = snapshot.Fibers.Select(f => new { f.Uid, f.Name, f.Status, f.Retired, f.InTransition, f.Inject, f.Provide, f.Dependencies, f.ErrorType }).ToArray(),
Transaction = loader?.LastTransaction is { } t ? new { t.Generation, t.Phase, t.CurrentEntryId, t.ErrorType, t.RestoreAttempted, t.PreviousCompositionRestored, t.RestoreErrorType } : null });
foreach (var fiber in snapshot.Fibers.Where(f => !f.Retired))
foreach (var dependency in fiber.Dependencies)
{
Add("fiber:" + scope + ":" + fiber.Uid, "key:" + dependency.Key, "requires@" + dependency.Realm, scope);
if (dependency.CurrentProviderUid.HasValue)
Add("fiber:" + scope + ":" + dependency.CurrentProviderUid, "fiber:" + scope + ":" + fiber.Uid, "provider:" + dependency.Key + "@" + dependency.Realm, scope);
}
}
public void AddNetwork(string scope, ShrinkNetworkService service)
{
State.Add(scope, new { Metrics = service.GetDiagnosticsSnapshot(), Queue = service.DispatchScheduler is ShrinkNetworkDispatchQueue queued ? queued.CaptureDiagnostics() : (service.DispatchScheduler as ShrinkNetworkInlineDispatchScheduler)?.CaptureDiagnostics() });
foreach (var meta in service.MessageRegistry.Registrations)
{
Add("opcode:" + meta.Opcode, "type:" + TypeName(meta.MessageType), "message", scope);
if (!string.IsNullOrEmpty(meta.Route)) Add("route:" + meta.Route, "type:" + TypeName(meta.MessageType), "message", scope);
}
foreach (var pair in service.Router.CaptureBindings()) Add("type:" + TypeName(pair.Key), MethodId(pair.Value), "handler", scope);
}
public void AddEventBus(string scope, IShrinkEventBus bus)
{
try
{
var bindings = EventBus.CaptureBindings(bus);
State.Add(scope, new { Bus = bus.Key.ToString(), Subscribers = bindings.Count });
foreach (var binding in bindings) Add("type:" + TypeName(binding.EventType), MethodId(binding.Handler), "subscribes", scope);
}
catch (NotSupportedException) { Coverage.Add(scope + ": custom EventBus does not expose bindings."); }
}
public void AddCommands(string scope, ShrinkCommandService service)
{
State.Add(scope, new { Registrations = service.Commands.Select(c => new { c.Path, c.Aliases, c.Permission, c.SourceKind }).ToArray() });
foreach (var binding in service.CaptureBindings()) Add("command:" + binding.Path, MethodId(binding.Handler), "command", scope);
}
private void Add(string from, string to, string kind, string scope) => Relations.Add(new ShrinkInspectionRelation { From = from, To = to, Kind = kind, Scope = scope });
private static string TypeName(Type type) => (type.FullName ?? type.Name).Replace('+', '.');
public static string MethodId(MethodInfo method)
{
// Generated wrappers and generic signatures remain runtime-only endpoints rather than guessed source matches.
if (method.IsGenericMethod || method.DeclaringType?.IsGenericType == true || method.GetParameters().Any(p => p.ParameterType.IsGenericType || p.ParameterType.IsArray || p.ParameterType.IsByRef))
return "runtime-method:" + method.Module.ModuleVersionId.ToString("N") + ":" + method.MetadataToken;
var parameters = method.GetParameters();
return "M:" + TypeName(method.DeclaringType!) + "." + method.Name + (parameters.Length == 0 ? "" : "(" + string.Join(",", parameters.Select(p => TypeName(p.ParameterType))) + ")");
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a412b2f6a531a33419d270e47853ef05
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+13
View File
@@ -0,0 +1,13 @@
{
"name": "com.cneicy.shrink-inspection",
"version": "0.1.0",
"displayName": "Shrink Inspection",
"unity": "2022.3",
"description": "On-demand build inputs and bounded runtime binding snapshots for shrink inspect.",
"dependencies": {
"com.cneicy.shrink-context-core": "0.3.0",
"com.cneicy.shrink-eventbus": "2.2.2",
"com.cneicy.shrink-network": "0.4.2",
"com.cneicy.shrink-command": "0.4.2"
}
}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 2f07481a8e08f454fa1d85c5afe4c92d
guid: fdb80de9a8588bc4392a94dd7352be58
TextScriptImporter:
externalObjects: {}
userData:
+43 -24
View File
@@ -65,7 +65,7 @@ ShrinkSDK 是以 Unity Package Manager 包为发布边界的 SDK Workspace,不
```text
ShrinkSDK Workspace/
|-- Assets/Modules/ 21 个同路径 Git submodule UPM 包
|-- Assets/Modules/ .gitmodules 声明的同路径 Git submodule UPM 包
|-- Assets/Modules/*.meta 根仓库追踪的 Unity 目录 GUID
|-- Assets/Scenes/ 示例与验收场景
|-- Assets/Resources/ 当前应用配置与组合 Profile
@@ -73,6 +73,7 @@ ShrinkSDK Workspace/
|-- GeneratedModSdk/ Mod SDK 导出物
|-- Packages/ 根 Unity 工程依赖
|-- Tools/UpmConsumerValidation/ 干净 UPM 消费工程验证
|-- Tools/Release/ 包版本、依赖与目录同步工具
|-- Tools/RepositoryMigration/ 子模块、发布仓库与独立宿主初始化脚本
|-- Docs/Archive/ 已完成迁移与过期地图,仅供追溯
|-- DESIGN.md 唯一当前架构文档
@@ -84,27 +85,28 @@ ShrinkSDK Workspace/
| 包 | 版本 | 职责 |
|---|---:|---|
| `com.cneicy.shrink-eventbus` | 2.0.1 | 单一事件模型、多 Bus、生成特性订阅、可选 MonoBehaviour 生命周期织入、UniTask 调度与零 GC 热路径 |
| `com.cneicy.shrink-eventbus-entities` | 0.1.1 | ShrinkEventBus 的 ECS/Burst NativeQueue writer 与 playback 适配 |
| `com.cneicy.shrink-datasaver` | 2.2.2 | 多槽位存档、设置、迁移、加密、原子写入与备份 |
| `com.cneicy.shrink-command` | 0.2.0 | 路径式命令、权限与同步/异步执行 |
| `com.cneicy.shrink-network` | 0.2.1 | 消息、RPC、权限、诊断、TCP/KCP/Loopback 与服务器生成 |
| `com.cneicy.shrink-mod-framework` | 0.2.4 | 模组发现、依赖、可逆生命周期、命名空间内容覆盖、外部 DLL revision 与 Harmony lease |
| `com.cneicy.shrink-tutorial` | 0.1.3 | 数据驱动引导、遮罩、锚点、触发与持久化 |
| `com.cneicy.shrink-context-core` | 0.1.0 | 可逆效应、coeffect、fiber、声明式 loader 与诊断 |
| `com.cneicy.shrink-app-core` | 0.1.4 | App 设置、服务门面、ClassicHost 兼容面与宿主协议 |
| `com.cneicy.shrink-app-starter-basic` | 0.2.2 | 默认 Context 组合根、配置资产和示例入口 |
| `com.cneicy.shrink-context-app-adapter` | 0.1.5 | ContextLoader 宿主、Profile/JSON、诊断与基准 |
| `com.cneicy.shrink-context-eventbus-adapter` | 0.1.1 | EventBus 生成绑定的可逆 EffectAttach 包装 |
| `com.cneicy.shrink-datasaver-integration-eventbus` | 2.1.3 | DataSaver 事件桥 |
| `com.cneicy.shrink-datasaver-integration-app` | 0.1.3 | DataSaver App installer/原生 Context 组件 |
| `com.cneicy.shrink-command-integration-eventbus` | 0.1.2 | 命令请求与生命周期事件桥 |
| `com.cneicy.shrink-command-integration-network` | 0.1.1 | `command/execute` RPC 桥 |
| `com.cneicy.shrink-command-integration-app` | 0.1.3 | Command App installer/原生 Context 组件 |
| `com.cneicy.shrink-network-integration-eventbus` | 0.1.3 | 网络事件广播、裁决结果与 delta 去重 |
| `com.cneicy.shrink-network-integration-app` | 0.1.3 | Network App installer/原生 Context 组件 |
| `com.cneicy.shrink-shared-codegen` | 0.1.0 | App、Command、Network 共用的 Editor-only IL 后处理注册表生成器 |
| `com.cneicy.shrink-installer` | 0.2.4 | UI Toolkit 包管理器:显示真实安装状态,按 Context 分层提供固定版本单包与推荐组合 |
| `com.cneicy.shrink-eventbus` | 2.2.2 | 单一事件模型、多 Bus、生成特性订阅、可选 MonoBehaviour 生命周期织入、UniTask 调度与零 GC 热路径 |
| `com.cneicy.shrink-eventbus-entities` | 0.1.5 | ShrinkEventBus 的 ECS/Burst NativeQueue writer 与 playback 适配 |
| `com.cneicy.shrink-datasaver` | 2.4.0 | 多槽位存档、设置、迁移、加密、原子写入与备份 |
| `com.cneicy.shrink-command` | 0.4.2 | 路径式命令、权限与同步/异步执行 |
| `com.cneicy.shrink-network` | 0.4.2 | 消息、RPC、权限、诊断、TCP/KCP/Loopback 与服务器生成 |
| `com.cneicy.shrink-mod-framework` | 0.3.6 | 模组发现、依赖、可逆生命周期、命名空间内容覆盖、外部 DLL revision 与 Harmony lease |
| `com.cneicy.shrink-tutorial` | 0.2.0 | 数据驱动引导、遮罩、锚点、触发与持久化 |
| `com.cneicy.shrink-context-core` | 0.3.0 | 可逆效应、coeffect、fiber、声明式 loader 与诊断 |
| `com.cneicy.shrink-app-core` | 0.2.3 | App 设置、服务门面、ClassicHost 兼容面与宿主协议 |
| `com.cneicy.shrink-app-starter-basic` | 0.3.7 | 默认 Context 组合根、配置资产和示例入口 |
| `com.cneicy.shrink-context-app-adapter` | 0.2.4 | ContextLoader 宿主、Profile/JSON、诊断与基准 |
| `com.cneicy.shrink-context-eventbus-adapter` | 0.2.4 | EventBus 生成绑定的可逆 EffectAttach 包装 |
| `com.cneicy.shrink-datasaver-integration-eventbus` | 2.2.5 | DataSaver 事件桥 |
| `com.cneicy.shrink-datasaver-integration-app` | 0.2.5 | DataSaver App installer/原生 Context 组件 |
| `com.cneicy.shrink-command-integration-eventbus` | 0.2.5 | 命令请求与生命周期事件桥 |
| `com.cneicy.shrink-command-integration-network` | 0.2.5 | `command/execute` RPC 桥 |
| `com.cneicy.shrink-command-integration-app` | 0.2.5 | Command App installer/原生 Context 组件 |
| `com.cneicy.shrink-network-integration-eventbus` | 0.2.5 | 网络事件广播、裁决结果与 delta 去重 |
| `com.cneicy.shrink-network-integration-app` | 0.2.5 | Network App installer/原生 Context 组件 |
| `com.cneicy.shrink-shared-codegen` | 0.2.1 | App、Command、Network 共用的 Editor-only IL 后处理注册表生成器 |
| `com.cneicy.shrink-runtime-abstractions` | 0.1.0 | Unity 与其他 .NET 宿主共用的平台服务合同 |
| `com.cneicy.shrink-installer` | 0.2.13 | UI Toolkit 包管理器:显示真实安装状态,按 Context 分层提供固定版本单包与推荐组合 |
`ShrinkShared.CodeGen` 不反向引用业务 asmdef,只按程序集名与类型全名读取 Cecil 元数据,因此业务包可以依赖它而不形成包循环。
@@ -200,7 +202,9 @@ Mono 中已加载程序集不能真正卸载。系统只回滚组件实例与效
### 8.1 Unity 运行时注册
`ShrinkEventBus/CodeGen/Editor/EventBusILPostProcessor.cs` 为引用方程序集生成实例直接调用绑定和静态模块初始化注册,不运行时枚举方法。`ShrinkShared.CodeGen/Editor/ShrinkRegistryILPostProcessor.cs` 继续负责 Command、Network 和 App 注册表。外部 Mod DLL 必须携带 EventBus 生成合同;没有合同的生产 DLL 不自动反射注册。
Unity 由 ShrinkShared.CodeGen 的 ShrinkRegistryILPostProcessor 作为唯一 IL 后处理入口,统一编织 EventBus、Command、Network 与 App 生成合同;旧分散入口保留兼容类但不再重复处理。运行时仍是生成的强类型绑定,不枚举方法。外部 Mod DLL 必须携带生成合同。
Unity 加载兼容其 Roslyn 3.8 的预构建分析器 DLL;独立 CLI 使用自己的较新 Roslyn,不能把相同源代码直接编译为仅支持新 API 的 DLL 后交给旧 Unity。SHRINK001–004 检查订阅签名、协议 opcode/route、installer 和常量 Context key。编译器分析不代替异步生命周期行为验证。
### 8.2 独立服务器生成
@@ -225,7 +229,7 @@ Mono 中已加载程序集不能真正卸载。系统只回滚组件实例与效
1. 内部包图检查:全部 `com.cneicy.*` 依赖版本一致、无循环,普通主包不反向依赖 Integration 包。
2. Unity 编译:目标 asmdef 和根项目无编译错误。
3. EditMode 测试:功能测试、Context 生命周期、语义扫描和模板覆写保护。
4. 真实 UPM 消费:`Tools/UpmConsumerValidation/Validate-UpmConsumer.ps1` 在递归 submodule 初始化后的 Workspace 中创建仓库外形态的临时 Unity 工程,通过 `file:` 安装全部 21 个包,启用 testables,验证包注册、程序集加载并运行 EditMode 测试。发布后还必须分别验证 registry、精确 Git URL 和 Installer 三种空白消费者工程路径。
4. 真实 UPM 消费:`Tools/UpmConsumerValidation/Validate-UpmConsumer.ps1` 在递归 submodule 初始化后的 Workspace 中创建仓库外形态的临时 Unity 工程,通过 `file:` 安装全部包,启用 testables,验证包注册、程序集加载并运行 EditMode 测试。发布后还必须分别验证 registry、精确 Git URL 和 Installer 三种空白消费者工程路径。
5. 独立宿主:生成工程与 RuntimeSmoke 按变更范围构建或运行。
6. 涉及真实生命周期时,仍需在目标场景执行 Play Mode 验收;源码检查和 EditMode 不能替代该路径。
@@ -253,8 +257,23 @@ Mono 中已加载程序集不能真正卸载。系统只回滚组件实例与效
- 当前架构只更新本文。
- 包级使用方式和 API 示例放在各包 README。
- `Tools/Release/Update-ShrinkSdkVersions.ps1` 负责包版本递增,并同步受影响的精确依赖、对应 NuGet 项目、Installer 目录、本文版本表和 `Tools/Release/package-versions.json`;依赖清单变化会触发依赖方 patch 版本递增。
- `Tools/UpmConsumerValidation/published-upm-versions.json` 只记录已经发布且要接受真实消费验证的版本,不随未打标签的 Workspace 版本提前更新。
- 包源码、标签、独立开发宿主与包级 CI 位于 `https://git.crash.work/ShrinkSDK/<Package>`;发布版本只能由与 `package.json.version` 一致的 `vX.Y.Z` 标签产生。
- `NETWORK_PITFALLS.md` 记录实现经验,不描述当前模块清单。
- `Docs/Archive/CORDIS_MIGRATION.completed.md` 保存迁移论证、阶段记录和历史验收数据。
- `Docs/Archive/codebase-map-2026-05-23/` 保存迁移前代码地图,其中关于 Git 状态、模块规模和测试覆盖的描述均已过期。
- `.planning/threads/` 只用于恢复工作上下文;其中历史 Notes 不得覆盖本文和当前源码。
## 12. 本地导航与性能合同
- Tools/AgentSupport/Shrink.Inspect 是无模型 API 依赖的本地 Roslyn CLI;capabilities 用包级职责/入口/复用边界/不负责内容/验证点,symbol、flow、impact 使用语义边而不是把 grep 当调用图。
- Unity 输入由 ShrinkInspection 导出实际源、引用、宏与构建标识;Godot/.NET 通过 MSBuildWorkspace 加载目标工程。static、candidate、runtime-bound、unresolved 分开显示;结果有数量、深度与分页上限,第三方引用和生成成员的缺口显式声明。
- 运行快照只按需导出明确宿主的 Context、Network、EventBus 与 Command 绑定。fiber 标识带 scope;缺失 provider 是未满足依赖,不是假造绑定。快照不保存消息正文/令牌,不常驻连接生产环境。
- Context 仅保留受管理的活跃/过渡 fiber;完全退役后移除运行时与父 effect 的实例引用,有界纯数据历史默认 64。依赖索引用于缩小诊断候选;同步深链转换以队列展开。
- Network 使用 v2 SHK2 封装、消息体单次编码和明确池内存生命周期。自动派发为每服务有界串行队列;主线程手动泵送提供数量/字节/时间预算。可靠操作满队列明确失败,只有显式状态 key 可合并,RPC 响应独立完成以避免嵌套等待死锁。
- MessagePack 为可选生成 resolver 适配器,不由核心反射发现 formatter。TCP 优化单次组合写入;没有把实验性 Pipelines 或 .NET 10 后端带入共享默认依赖。
- DataSaver 主线程采集与后台快照编码分离;后台开关默认关闭,格式、原子替换与备份回退不变。阶段计时按需开启。
使用方式见 Tools/AgentSupport/README.md;新内容先执行 Docs/ReuseFirstDesign.md;跨组件可编译示例入口见 Docs/IntegrationExamples.md;性能结论与限制见 Docs/Performance/2026-09-28.md。本次本地交付未改变远程发布治理规则。
+13
View File
@@ -0,0 +1,13 @@
# 接入示例
这些示例直接引用仓库中参与编译和测试的实现,不另存代码副本。
| 目标 | 实现入口 | 可运行验证 |
|---|---|---|
| Context 组件,声明依赖并注册可逆状态 | [测试组件](../Assets/Modules/ShrinkContext.Core/Tests/TestComponents.cs) | [Fiber 生命周期](../Assets/Modules/ShrinkContext.Core/Tests/FiberLifecycleTests.cs)、[退役保留](../Assets/Modules/ShrinkContext.Core/Tests/RetirementRetentionTests.cs) |
| Context 持有事件订阅并在卸载时撤回 | [EffectAttach](../Assets/Modules/ShrinkContext.EventBusAdapter/Runtime/ShrinkEventBusEffects.cs) | [事件接收和自动退订](../Assets/Modules/ShrinkContext.EventBusAdapter/Tests/EventBusEffectTests.cs) |
| RPC 到 Command 桥接 | [桥注册和执行](../Assets/Modules/ShrinkCommand.Integration.Network/ShrinkNetworkCommandBridge.cs) | [双 provider 就绪/退役/替换](../Assets/Modules/ShrinkCommand.Integration.Network/Tests/IntegrationComponentsTests.cs) |
Unity Test Runner 的 EditMode 选择 `ShrinkContext.Core.Tests`、`ShrinkContext.EventBusAdapter.Tests`、`ShrinkCommand.Integration.Network.Tests`。Player 验证入口为 `Assets/AgentSupportTests/Editor/PlayerAcceptance.cs`,仅使用测试场景。独立共享运行时测试使用 `dotnet test Tools/AgentSupport/RuntimeTests`。
事件特性需要 CodeGen 完成实际绑定;静态索引里的订阅边只是候选。RPC 桥的权限由 `ShrinkNetworkCommandBridgeOptions` 和命令源共同决定,不能为了复用绕过原有权限。拥有者在组件退出时撤回它的 effect,不替他人释放借来的服务。
+60
View File
@@ -0,0 +1,60 @@
# Network v2 与诊断接入迁移
网络消息体的编码器与包封装现已分离。所有 `ShrinkNetworkService` 使用 SHK2 二进制封装;协议版本为 2,旧 JSON/MessagePack 外层包会被拒绝。客户端与服务端必须一起升级。直接使用 TCP/KCP transport 传递自定义字节的项目保留自己的上层协议,不能把其版本号与 ShrinkNetworkService 的协议号混同。
## 消息编码与所有权
- JSON 消息编码仍可显式选择 `ShrinkJsonNetworkSerializer`,不再将字节消息体嵌入 JSON 外层包而产生 Base64。
- 原反射式 `ShrinkMessagePackNetworkSerializer` 已移除。安装可选的 `ShrinkSDK.Network.MessagePack`/UPM 适配包,引用 `ShrinkNetwork.MessagePack`,传入生成的 resolver,并对每个消息类型调用 `Register<T>()`。适配器只补充基础类型 formatter,不使用动态泛型反射回退。
- `ShrinkNetworkPacket.Payload` 从 `byte[]` 改为 `ReadOnlyMemory<byte>`。只有需要独立所有权时调用 `ToArray()`;`ShrinkPacketCodec.Decode` 借用输入内存。
- 实现 `IShrinkNetworkBufferSerializer` 可直接写入 `IBufferWriter<byte>`。旧消息序列化接口保留兼容路径,但会产生中间数组。
- 实现 `IShrinkNetworkMemoryTransport` 时,发送任务完成、取消或失败之前必须保持输入有效;任务结束后不能继续访问。服务层负责在 await 结束后归还池内存。旧传输接口收到独立数组。
- 广播可先编码消息体并使用 `SendSerializedAsync`,外层会话信息仍按收件人生成。调用方在所有发送完成前不得修改共享消息体。
## 排队行为
默认自动派发按序执行处理器;Unity/Godot 的主线程接入可使用 `ShrinkNetworkDispatchQueue`,按帧调用带数量、字节、时间预算的 `PumpAsync`。预算不会抢占正在执行的 handler;为避免饥饿,每轮允许首个合法包超过本轮字节预算。
可靠接收队列只允许 Reject。原 DropNewest/DropOldest 配置会明确报错。拒绝通过 `OnDispatchRejected` 与指标反馈;支持会话控制的 transport 会断开连接,以免继续使用缺失可靠操作的状态。
显式状态合并使用 `ShrinkNetworkWorkQueue.EnqueueAsync` 的 `stateKey`,只在相同 session/channel/key 内替换未执行项,替换后的项移至该分区队尾。返回值区分 Completed、Rejected、Replaced、Canceled;异常继续向调用方传播。RPC、可靠业务操作、存档事务和快照分片不能使用普通状态替换。多个分区轮转,但处理器仍串行执行。
RPC 响应单独完成挂起请求,避免嵌套调用等待当前处理队列而死锁。处理器的 async continuation 线程仍取决于其等待对象;访问引擎对象前由宿主保证线程切换。
## Context 与存档
`ShrinkContextRuntime.Fibers` 只保留仍被运行时管理的 fiber。退役历史改为有界纯数据诊断,构造参数 `retiredHistoryCapacity` 默认 64;需要审计时由上层保存诊断数据,不能继续依赖运行时永久持有所有历史组件。
生命周期转换使用同步队列展开深依赖链,保留确定性协调和依赖排空后撤回自身效应的规则。不要从多个线程同时修改同一 Context runtime。
`SaveOptions.EncodeInBackground` 默认关闭。开启后,模块采集和 JSON 快照物化仍在调用线程执行,后台只编码独立快照与加密。`CollectTimings` 提供采集、编码、加密、落盘阶段数据;存档格式、原子替换和备份回退保持兼容。
## 从包源升级
Unity 在 `Packages/manifest.json` 配置 ShrinkSDK scoped registry,使用明确版本号安装:
```json
{
"scopedRegistries": [{
"name": "ShrinkSDK",
"url": "https://git.crash.work/api/packages/ShrinkSDK/npm/",
"scopes": ["com.cneicy"]
}]
}
```
保留工程已有的 registry 和第三方依赖。核心版本为 Context 0.3.0、EventBus 2.2.2、Network 0.4.2、DataSaver 2.4.0、UPM CodeGen 0.2.1;按需添加 `com.cneicy.shrink-inspection` 0.1.0 与 `com.cneicy.shrink-network-messagepack` 0.1.0。完整版本以仓库版本目录及 [Gitea 包列表](https://git.crash.work/ShrinkSDK/-/packages) 为准。
.NET 使用 `https://git.crash.work/api/packages/ShrinkSDK/nuget/index.json` 作为 NuGet 源。CLI 安装见 [工具说明](../Tools/AgentSupport/README.md)。
MessagePack 适配包要求消费项目提供 MessagePack-CSharp 与生成式 formatter,避免重复安装二进制。适配器使用 .NET 3.1.8,已验证 Unity 3.1.10 生成 formatter 的字节互通。
升级后由 Unity Package Manager 解析依赖,等待编译完成并确认包来源为 registry。导出 compilation inputs 后,再从实际宿主导出 runtime snapshot;未注册宿主的实例不在默认快照覆盖内。编译、消息互通和实际启动应分别验证。
修改 SDK 源码时,可使用 `Pack-Local.ps1` 和 `Install-Unity.py <工程路径>` 测试本地构建;这会把目标项目的 ShrinkSDK 依赖改为本地 tarball,正式消费项目应恢复 registry 版本。
### 回退
1. 停止 Play Mode,保存当前 manifest、lock 与相关接入代码。
2. 同步回退使用新版 API 的业务接入与依赖版本,由 Unity 重建 lock;不手工修改 Library。
3. 客户端和使用 ShrinkNetworkService 的服务端共同回退。v1/v2 不兼容,不可只回退单边;自定义 transport 协议按其独立策略处理。
+80
View File
@@ -0,0 +1,80 @@
# 性能测量 — 2026-09-28 UTC
测量环境为本地开发机;结果用于比较实现,不代表生产容量。原始测量时间保留在 JSON 中。
## 方法与证据边界
- Windows x64;Unity 2022.3.62f3 的实际 Standalone Player,而非用 EditMode 冒充 Player;另有 .NET 8.0.31、.NET 10 和 Godot 4.6.3 Mono 的实际运行。
- 网络矩阵:64 B/1 KB/32 KB 负载参数,1/32/256 会话;RPC、广播、慢消费者、突发队列。Loopback 会话不是 OS socket;TCP 文件是实际本机 socket,且 RPC 采用串行往返采样,不等于高并发容量压测。
- Context:10/100/1000 组件依赖链,10,000 次创建退役;旧实现来自 Context 子模块提交 b93f3e61223e7572588b67c0d3935073817f0da6,不是重新编写的假想基线。
- 存档:100 KB/1 MB/10 MB,前台/后台编码;.NET 每组合 10 次并覆盖加密,Player 记录真实阶段耗时与采集线程。输入主要为字符串快照,不能推断复杂游戏对象的采集成本。
- 单机开发环境、有限样本,非隔离实验机;p99 易受 JIT、GC、系统调度影响。没有可靠的多轮置信区间,不将小幅波动称为普遍提升。
- Unity 的 GC.GetAllocatedBytesForCurrentThread 对已知分配返回零,已弃用该结果。Player 改用经已知数组分配校准的 GC.Alloc 事件计数;事件次数不是 B/op。独立 .NET 的字节计数与 Player 分开报告。
原始数据位于 [Data/2026-09-28](Data/2026-09-28/);Player 测量输出保存在 player-output.txt。工具、测试源代码保留在 Tools/AgentSupport 与 Assets/AgentSupportTests。
## 已量化的核心变化
### Context(.NET 8)
| 组件数 | 旧诊断 p95 µs | 新诊断 p95 µs | 旧 B/op | 新 B/op |
|---:|---:|---:|---:|---:|
| 10 | 9.4 | 11.7 | 10,456 | 7,312 |
| 100 | 538.2 | 116.9 | 108,016 | 73,456 |
| 1000 | 7,426.4 | 548.3 | 1,083,616 | 735,328 |
大规模诊断通过按依赖键访问 provider 候选索引获益;10 个组件的 p95 本轮反而略高,不能宣称所有规模都更快。10,000 次退役后旧运行时持有 10,000 个 fiber,新运行时为 0,诊断历史有界 64。弱引用测试验证实例可回收;整进程 GC 差值可能为负,不将其解读为精确节省字节数。
深链生命周期改为迭代队列展开,避免 1000 层同步完成/撤回造成栈溢出;不改变依赖排空与效应撤回顺序。
### 网络封装(.NET 8)
| 负载参数 | 旧 JSON 外封装 B/op | 新 v2 外封装 B/op |
|---:|---:|---:|
| 64 B | 3,504 | 32 |
| 1 KB | 10,560 | 32 |
| 32 KB | 230,328 | 32 |
这里只比较已经编码的消息体如何封装,不是端到端零分配。新封装取消外层 JSON/Base64,消息直接写入池化 buffer;仍有 writer 对象、消息反序列化、排队和 transport 的独立成本。JSON 与生成式 MessagePack 的完整消息编码对照见原始 rows,不能套用此表的 32 B。
队列突发测试输入 10,000 个显式可替换状态,32 个 session 分区最终保留 32 项、32 KB,返回 9,968 次 Replaced;一次 4 KB budget 泵送完成 4 项。可靠操作不使用这种替换机制,满队列显式拒绝。
### 实际 TCP 与后端选择
256 个本机 TCP 连接、1 KB、256 次串行 RPC 往返:
| 运行时 | p50 µs | p95 µs | p99 µs | ops/s |
|---|---:|---:|---:|---:|
| .NET 8 | 99.3 | 258.9 | 355.1 | 6,911 |
| .NET 10 | 88.4 | 250.8 | 384.3 | 7,392 |
其他参数组合有升有降;本轮未证明目标场景稳定达到 15% 收益,因此不引入新的默认 .NET 10 专属服务端依赖。Pipelines 仅有内存 buffer roundtrip 微实验,未实现等价 socket 后端对照,不足以采纳。共享运行时继续 netstandard2.1。
TCP 慢消费者测试证明有界队列和拒绝反馈,不证明业务消费成功:该突发负载使用 RPC 消息的一次性发送路径,记录中存在 DispatchMissCount;不能将该行视为完整 handler 吞吐测试。可靠队列行为、会话隔离、取消和故障另由功能测试验证。KCP 未作独立吞吐结论。
### EventBus 与存档
.NET 8 同步 Post、同步完成的异步 Post 为 0 B/op;注册/撤回 224 B/op,按需绑定诊断 120 B/op。同步路径的捕获闭包已移出快路径;Unity 的结构体事件空值检查另外增加值类型短路,避免 Mono 装箱。
校准后的 Player 实测:独立 Bus 10,000 次同步发布为 0 次分配事件;当前默认 Bus 为 10,000 次分配事件。修复值类型空值检查前默认通道是 20,000 次,不能将早先字节 API 的零值作为基线。
默认全局 Bus 可能带网络桥或诊断观察器;接口观察器需要结构体装箱,不能把独立 Bus 的零分配结果扩大到所有配置。Player 同时测量默认与独立通道,并为引用类型空值保留异常检查。
存档采集仍在调用线程,后台开关仅移动脱离宿主对象的快照编码与加密。示例 .NET 8 的 10 MB 未加密平均编码为前台约 7.68 ms、后台约 8.21 ms;主要收益是主线程工作转移,而非宣称总保存时间必然缩短。Player 的冷启动与各阶段实测见 player-output.txt;未隐藏首轮高耗时。格式、原子落盘、取消时备份保留及损坏回退均有测试。
## 复现
在已还原依赖的仓库运行:
~~~powershell
pwsh Tools/AgentSupport/Benchmarks/Prepare-Baseline.ps1
dotnet run --project Tools/AgentSupport/Benchmarks -c Release -f net8.0 -- Artifacts/AgentSupport/benchmark-net8.json
dotnet run --project Tools/AgentSupport/Benchmarks -c Release -f net10.0 -- Artifacts/AgentSupport/benchmark-net10.json
dotnet run --project Tools/AgentSupport/Benchmarks -c Release -f net8.0 -- --tcp Artifacts/AgentSupport/tcp-net8.json
dotnet test Tools/AgentSupport/RuntimeTests
dotnet test Tools/AgentSupport/Shrink.Inspect.Tests
~~~
Unity 用 TestRunner 的 StandaloneWindows64 Player 运行 ShrinkSDK.AgentSupport.PlayerTests;Editor 辅助入口 PlayerAcceptance.Run() 将本次结果保存到 Artifacts/AgentSupport/unity-player-results.xml。基线脚本默认固定上述旧提交;使用 `-Revision` 可指定其他对照版本。
协议和回退见 [迁移说明](../NetworkV2Migration.md)。
@@ -0,0 +1,7 @@
# 性能测量原始数据
- `benchmark-net8.json`、`benchmark-net10.json`:网络编码、队列、Context、EventBus 和存档微基准。
- `tcp-net8.json`、`tcp-net10.json`:真实本机 TCP socket 测量。
- `player-output.txt`:Unity Standalone Player 的阶段计时与分配事件计数。
环境、采样限制、结果解释和复现命令见 [性能报告](../../2026-09-28.md)。
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,47 @@
PLAYER Context 10000 retirements ms=123.6386
PLAYER EventBus 10000 posts allocationEvents=10000 ms=0.8038
PLAYER EventBus isolated 10000 posts allocationEvents=0
[ShrinkDataSaver] 槽位 0 已保存。(2 个模块)
PLAYER Save 102400 background=False captureMs=11.8073 encodeMs=7.7169 encryptMs=0 writeMs=17.803 bytes=103171
[ShrinkDataSaver] 槽位 0 已保存。(2 个模块)
PLAYER Save 102400 background=True captureMs=0.1186 encodeMs=0.2584 encryptMs=0 writeMs=29.4953 bytes=103171
[ShrinkDataSaver] 槽位 0 已保存。(2 个模块)
PLAYER Save 1048576 background=False captureMs=1.3102 encodeMs=7.8701 encryptMs=0 writeMs=13.9663 bytes=1049347
[ShrinkDataSaver] 槽位 0 已保存。(2 个模块)
PLAYER Save 1048576 background=True captureMs=0.1341 encodeMs=7.7226 encryptMs=0 writeMs=23.1749 bytes=1049347
[ShrinkDataSaver] 槽位 0 已保存。(2 个模块)
PLAYER Save 10485760 background=False captureMs=0.1424 encodeMs=28.173 encryptMs=0 writeMs=32.9821 bytes=10486531
[ShrinkDataSaver] 槽位 0 已保存。(2 个模块)
PLAYER Save 10485760 background=True captureMs=0.162 encodeMs=25.6417 encryptMs=0 writeMs=24.231 bytes=10486531
PLAYER allocation calibration managedCounterDelta=0 profilerEvents=10; use profiler events, not uncalibrated bytes.
PLAYER PERF context-diagnostic/components=10 n=100 ops=71994.24 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=135.00 p50us=13.00 p95us=20.20 p99us=25.60
PLAYER PERF context-diagnostic/components=100 n=100 ops=6276.68 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=1224.00 p50us=118.80 p95us=190.80 p99us=1980.20
PLAYER PERF context-diagnostic/components=1000 n=100 ops=391.93 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=12033.00 p50us=1841.90 p95us=5669.60 p99us=7090.60
PLAYER PERF event-async-completed n=10000 ops=1531534.29 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=3.00 p50us=0.30 p95us=0.60 p99us=1.10
PLAYER PERF event-bindings n=1000 ops=3377237.42 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=2.00 p50us=0.20 p95us=0.60 p99us=1.00
PLAYER PERF event-register-withdraw n=10000 ops=725100.06 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=10.00 p50us=0.80 p95us=1.70 p99us=2.40
PLAYER PERF loopback-rpc/bytes=64/sessions=1 n=128 ops=42139.92 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=100.00 p50us=22.40 p95us=32.20 p99us=35.80
PLAYER PERF loopback-broadcast/bytes=64/sessions=1 n=20 ops=135777.33 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=37.00 p50us=7.20 p95us=9.20 p99us=9.20
PLAYER PERF loopback-rpc/bytes=64/sessions=32 n=128 ops=22296.16 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=100.00 p50us=24.60 p95us=46.10 p99us=96.20
PLAYER PERF loopback-broadcast/bytes=64/sessions=32 n=20 ops=3283.21 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=1060.00 p50us=215.80 p95us=1999.10 p99us=1999.10
PLAYER PERF loopback-rpc/bytes=64/sessions=256 n=128 ops=16764.02 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=100.00 p50us=33.90 p95us=42.50 p99us=115.00
PLAYER PERF loopback-broadcast/bytes=64/sessions=256 n=20 ops=331.02 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=8452.00 p50us=3052.70 p95us=5858.40 p99us=5858.40
PLAYER PERF loopback-rpc/bytes=1024/sessions=1 n=128 ops=13102.67 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=102.00 p50us=27.70 p95us=302.40 p99us=1201.80
PLAYER PERF loopback-broadcast/bytes=1024/sessions=1 n=20 ops=117164.62 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=38.00 p50us=8.40 p95us=10.40 p99us=10.40
PLAYER PERF loopback-rpc/bytes=1024/sessions=32 n=128 ops=15497.49 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=102.00 p50us=27.60 p95us=62.90 p99us=1200.70
PLAYER PERF loopback-broadcast/bytes=1024/sessions=32 n=20 ops=1648.17 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=1092.00 p50us=361.60 p95us=1577.50 p99us=1577.50
PLAYER PERF loopback-rpc/bytes=1024/sessions=256 n=128 ops=12226.92 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=102.00 p50us=29.00 p95us=305.10 p99us=1402.90
PLAYER PERF loopback-broadcast/bytes=1024/sessions=256 n=20 ops=194.15 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=8708.00 p50us=4612.30 p95us=10631.00 p99us=10631.00
PLAYER PERF loopback-rpc/bytes=32768/sessions=1 n=128 ops=828.26 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=112.60 p50us=1123.40 p95us=3500.10 p99us=3837.10
PLAYER PERF loopback-broadcast/bytes=32768/sessions=1 n=20 ops=1815.71 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=43.00 p50us=98.60 p95us=3193.40 p99us=3193.40
PLAYER PERF loopback-rpc/bytes=32768/sessions=32 n=128 ops=842.40 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=112.00 p50us=1163.90 p95us=3475.30 p99us=3500.30
PLAYER PERF loopback-broadcast/bytes=32768/sessions=32 n=20 ops=65.08 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=1252.90 p50us=15096.30 p95us=26400.40 p99us=26400.40
PLAYER PERF loopback-rpc/bytes=32768/sessions=256 n=128 ops=830.36 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=112.60 p50us=1230.40 p95us=3500.80 p99us=3549.90
PLAYER PERF loopback-broadcast/bytes=32768/sessions=256 n=20 ops=8.67 allocBytes=unsupported allocationSamples=10 allocEventsPerOp=9995.60 p50us=114364.50 p95us=124433.00 p99us=124433.00
PLAYER Queue pending=32 bytes=32768 replaced=96 rejected=0
@@ -0,0 +1,303 @@
{
"runtime": ".NET 10.0.8",
"host": "Windows loopback TCP; sequential round-trip samples, multiple real connections",
"rows": [
{
"scenario": "tcp/rpc",
"connections": 1,
"bytes": 64,
"operations": 256,
"throughputPerSecond": 2569.8786133898707,
"p50Microseconds": 59.1,
"p95Microseconds": 172,
"p99Microseconds": 302.8,
"processAllocatedBytes": 4181192
},
{
"scenario": "tcp/broadcast",
"connections": 1,
"bytes": 64,
"elapsedMilliseconds": 3.9542,
"delivered": 1
},
{
"scenario": "tcp/rpc",
"connections": 1,
"bytes": 1024,
"operations": 256,
"throughputPerSecond": 9339.622985687758,
"p50Microseconds": 76.8,
"p95Microseconds": 233.8,
"p99Microseconds": 413.7,
"processAllocatedBytes": 9931824
},
{
"scenario": "tcp/broadcast",
"connections": 1,
"bytes": 1024,
"elapsedMilliseconds": 4.1822,
"delivered": 1
},
{
"scenario": "tcp/rpc",
"connections": 1,
"bytes": 32768,
"operations": 256,
"throughputPerSecond": 2077.1380931710028,
"p50Microseconds": 403.3,
"p95Microseconds": 1068.7,
"p99Microseconds": 1287.4,
"processAllocatedBytes": 229642408
},
{
"scenario": "tcp/broadcast",
"connections": 1,
"bytes": 32768,
"elapsedMilliseconds": 0.8935,
"delivered": 1
},
{
"scenario": "tcp/slow-consumer-burst",
"connections": 1,
"attempts": 8,
"beforePump": {
"PendingCount": 2,
"PendingBytes": 2136,
"Rejected": 1,
"Replaced": 0,
"Completed": 0,
"OldestWaitMilliseconds": 108.5865,
"LastWaitMilliseconds": 0
},
"afterPump": {
"PendingCount": 0,
"PendingBytes": 0,
"Rejected": 1,
"Replaced": 0,
"Completed": 2,
"OldestWaitMilliseconds": 0,
"LastWaitMilliseconds": 108.3473
},
"metrics": {
"CurrentSessions": 1,
"SessionsConnected": 1,
"SessionsDisconnected": 0,
"PacketsSent": 771,
"PacketsReceived": 770,
"BytesSent": 8772548,
"BytesReceived": 8703064,
"RpcStarted": 0,
"RpcCompleted": 0,
"RpcTimedOut": 0,
"RpcCanceled": 0,
"RpcFailed": 0,
"ProtocolViolations": 0,
"AuthRejectedCount": 0,
"PermissionDeniedCount": 0,
"HandlerExceptionCount": 0,
"UnknownOpcodeCount": 0,
"DispatchMissCount": 2,
"SerializationErrorCount": 0,
"DispatchQueueRejectedCount": 1
}
},
{
"scenario": "tcp/rpc",
"connections": 32,
"bytes": 64,
"operations": 256,
"throughputPerSecond": 13928.182807399347,
"p50Microseconds": 58.6,
"p95Microseconds": 147.2,
"p99Microseconds": 235,
"processAllocatedBytes": 3788328
},
{
"scenario": "tcp/broadcast",
"connections": 32,
"bytes": 64,
"elapsedMilliseconds": 15.9674,
"delivered": 32
},
{
"scenario": "tcp/rpc",
"connections": 32,
"bytes": 1024,
"operations": 256,
"throughputPerSecond": 9348.968509314276,
"p50Microseconds": 79.3,
"p95Microseconds": 199.6,
"p99Microseconds": 551,
"processAllocatedBytes": 9913976
},
{
"scenario": "tcp/broadcast",
"connections": 32,
"bytes": 1024,
"elapsedMilliseconds": 3.5947,
"delivered": 32
},
{
"scenario": "tcp/rpc",
"connections": 32,
"bytes": 32768,
"operations": 256,
"throughputPerSecond": 1782.1179776023969,
"p50Microseconds": 446.9,
"p95Microseconds": 1466.1,
"p99Microseconds": 1839.8,
"processAllocatedBytes": 229509592
},
{
"scenario": "tcp/broadcast",
"connections": 32,
"bytes": 32768,
"elapsedMilliseconds": 13.9419,
"delivered": 32
},
{
"scenario": "tcp/slow-consumer-burst",
"connections": 32,
"attempts": 256,
"beforePump": {
"PendingCount": 30,
"PendingBytes": 32040,
"Rejected": 32,
"Replaced": 0,
"Completed": 0,
"OldestWaitMilliseconds": 109.5715,
"LastWaitMilliseconds": 0
},
"afterPump": {
"PendingCount": 23,
"PendingBytes": 24564,
"Rejected": 32,
"Replaced": 0,
"Completed": 7,
"OldestWaitMilliseconds": 109.1555,
"LastWaitMilliseconds": 109.1537
},
"metrics": {
"CurrentSessions": 32,
"SessionsConnected": 32,
"SessionsDisconnected": 0,
"PacketsSent": 864,
"PacketsReceived": 775,
"BytesSent": 9826176,
"BytesReceived": 8708404,
"RpcStarted": 0,
"RpcCompleted": 0,
"RpcTimedOut": 0,
"RpcCanceled": 0,
"RpcFailed": 0,
"ProtocolViolations": 0,
"AuthRejectedCount": 0,
"PermissionDeniedCount": 0,
"HandlerExceptionCount": 0,
"UnknownOpcodeCount": 0,
"DispatchMissCount": 7,
"SerializationErrorCount": 0,
"DispatchQueueRejectedCount": 32
}
},
{
"scenario": "tcp/rpc",
"connections": 256,
"bytes": 64,
"operations": 256,
"throughputPerSecond": 8559.783062997996,
"p50Microseconds": 74.8,
"p95Microseconds": 204,
"p99Microseconds": 313.2,
"processAllocatedBytes": 4045992
},
{
"scenario": "tcp/broadcast",
"connections": 256,
"bytes": 64,
"elapsedMilliseconds": 12.374,
"delivered": 256
},
{
"scenario": "tcp/rpc",
"connections": 256,
"bytes": 1024,
"operations": 256,
"throughputPerSecond": 7391.815297015266,
"p50Microseconds": 88.4,
"p95Microseconds": 250.8,
"p99Microseconds": 384.3,
"processAllocatedBytes": 9917520
},
{
"scenario": "tcp/broadcast",
"connections": 256,
"bytes": 1024,
"elapsedMilliseconds": 12.6405,
"delivered": 256
},
{
"scenario": "tcp/rpc",
"connections": 256,
"bytes": 32768,
"operations": 256,
"throughputPerSecond": 1195.502482302127,
"p50Microseconds": 418.6,
"p95Microseconds": 1033.3,
"p99Microseconds": 16401.9,
"processAllocatedBytes": 227807112
},
{
"scenario": "tcp/broadcast",
"connections": 256,
"bytes": 32768,
"elapsedMilliseconds": 47.4633,
"delivered": 256
},
{
"scenario": "tcp/slow-consumer-burst",
"connections": 256,
"attempts": 2048,
"beforePump": {
"PendingCount": 30,
"PendingBytes": 32040,
"Rejected": 256,
"Replaced": 0,
"Completed": 0,
"OldestWaitMilliseconds": 124.5254,
"LastWaitMilliseconds": 0
},
"afterPump": {
"PendingCount": 23,
"PendingBytes": 24564,
"Rejected": 256,
"Replaced": 0,
"Completed": 7,
"OldestWaitMilliseconds": 124.4757,
"LastWaitMilliseconds": 124.5044
},
"metrics": {
"CurrentSessions": 256,
"SessionsConnected": 256,
"SessionsDisconnected": 0,
"PacketsSent": 1536,
"PacketsReceived": 775,
"BytesSent": 17439488,
"BytesReceived": 8708404,
"RpcStarted": 0,
"RpcCompleted": 0,
"RpcTimedOut": 0,
"RpcCanceled": 0,
"RpcFailed": 0,
"ProtocolViolations": 0,
"AuthRejectedCount": 0,
"PermissionDeniedCount": 0,
"HandlerExceptionCount": 0,
"UnknownOpcodeCount": 0,
"DispatchMissCount": 7,
"SerializationErrorCount": 0,
"DispatchQueueRejectedCount": 256
}
}
]
}
@@ -0,0 +1,303 @@
{
"runtime": ".NET 8.0.31",
"host": "Windows loopback TCP; sequential round-trip samples, multiple real connections",
"rows": [
{
"scenario": "tcp/rpc",
"connections": 1,
"bytes": 64,
"operations": 256,
"throughputPerSecond": 2786.3308702603804,
"p50Microseconds": 61.2,
"p95Microseconds": 164.7,
"p99Microseconds": 395.7,
"processAllocatedBytes": 4198840
},
{
"scenario": "tcp/broadcast",
"connections": 1,
"bytes": 64,
"elapsedMilliseconds": 2.3583,
"delivered": 1
},
{
"scenario": "tcp/rpc",
"connections": 1,
"bytes": 1024,
"operations": 256,
"throughputPerSecond": 9602.940900650823,
"p50Microseconds": 75.7,
"p95Microseconds": 193.2,
"p99Microseconds": 496,
"processAllocatedBytes": 9938800
},
{
"scenario": "tcp/broadcast",
"connections": 1,
"bytes": 1024,
"elapsedMilliseconds": 4.7543,
"delivered": 1
},
{
"scenario": "tcp/rpc",
"connections": 1,
"bytes": 32768,
"operations": 256,
"throughputPerSecond": 2206.3658826885603,
"p50Microseconds": 384.2,
"p95Microseconds": 1002.5,
"p99Microseconds": 1126.9,
"processAllocatedBytes": 229867960
},
{
"scenario": "tcp/broadcast",
"connections": 1,
"bytes": 32768,
"elapsedMilliseconds": 10.4461,
"delivered": 1
},
{
"scenario": "tcp/slow-consumer-burst",
"connections": 1,
"attempts": 8,
"beforePump": {
"PendingCount": 2,
"PendingBytes": 2136,
"Rejected": 1,
"Replaced": 0,
"Completed": 0,
"OldestWaitMilliseconds": 109.4399,
"LastWaitMilliseconds": 0
},
"afterPump": {
"PendingCount": 0,
"PendingBytes": 0,
"Rejected": 1,
"Replaced": 0,
"Completed": 2,
"OldestWaitMilliseconds": 0,
"LastWaitMilliseconds": 109.0027
},
"metrics": {
"CurrentSessions": 1,
"SessionsConnected": 1,
"SessionsDisconnected": 0,
"PacketsSent": 771,
"PacketsReceived": 770,
"BytesSent": 8772548,
"BytesReceived": 8703064,
"RpcStarted": 0,
"RpcCompleted": 0,
"RpcTimedOut": 0,
"RpcCanceled": 0,
"RpcFailed": 0,
"ProtocolViolations": 0,
"AuthRejectedCount": 0,
"PermissionDeniedCount": 0,
"HandlerExceptionCount": 0,
"UnknownOpcodeCount": 0,
"DispatchMissCount": 2,
"SerializationErrorCount": 0,
"DispatchQueueRejectedCount": 1
}
},
{
"scenario": "tcp/rpc",
"connections": 32,
"bytes": 64,
"operations": 256,
"throughputPerSecond": 9747.14534288249,
"p50Microseconds": 78.5,
"p95Microseconds": 235.1,
"p99Microseconds": 304.2,
"processAllocatedBytes": 3791256
},
{
"scenario": "tcp/broadcast",
"connections": 32,
"bytes": 64,
"elapsedMilliseconds": 9.6954,
"delivered": 32
},
{
"scenario": "tcp/rpc",
"connections": 32,
"bytes": 1024,
"operations": 256,
"throughputPerSecond": 8234.052955253068,
"p50Microseconds": 86.6,
"p95Microseconds": 247.5,
"p99Microseconds": 494.8,
"processAllocatedBytes": 9908800
},
{
"scenario": "tcp/broadcast",
"connections": 32,
"bytes": 1024,
"elapsedMilliseconds": 15.3001,
"delivered": 32
},
{
"scenario": "tcp/rpc",
"connections": 32,
"bytes": 32768,
"operations": 256,
"throughputPerSecond": 1754.0157368099387,
"p50Microseconds": 419.6,
"p95Microseconds": 1319.5,
"p99Microseconds": 1647.1,
"processAllocatedBytes": 230263696
},
{
"scenario": "tcp/broadcast",
"connections": 32,
"bytes": 32768,
"elapsedMilliseconds": 11.5336,
"delivered": 32
},
{
"scenario": "tcp/slow-consumer-burst",
"connections": 32,
"attempts": 256,
"beforePump": {
"PendingCount": 30,
"PendingBytes": 32040,
"Rejected": 32,
"Replaced": 0,
"Completed": 0,
"OldestWaitMilliseconds": 126.3722,
"LastWaitMilliseconds": 0
},
"afterPump": {
"PendingCount": 23,
"PendingBytes": 24564,
"Rejected": 32,
"Replaced": 0,
"Completed": 7,
"OldestWaitMilliseconds": 126.2021,
"LastWaitMilliseconds": 126.1876
},
"metrics": {
"CurrentSessions": 32,
"SessionsConnected": 32,
"SessionsDisconnected": 0,
"PacketsSent": 864,
"PacketsReceived": 775,
"BytesSent": 9826176,
"BytesReceived": 8708404,
"RpcStarted": 0,
"RpcCompleted": 0,
"RpcTimedOut": 0,
"RpcCanceled": 0,
"RpcFailed": 0,
"ProtocolViolations": 0,
"AuthRejectedCount": 0,
"PermissionDeniedCount": 0,
"HandlerExceptionCount": 0,
"UnknownOpcodeCount": 0,
"DispatchMissCount": 7,
"SerializationErrorCount": 0,
"DispatchQueueRejectedCount": 32
}
},
{
"scenario": "tcp/rpc",
"connections": 256,
"bytes": 64,
"operations": 256,
"throughputPerSecond": 6808.96336192566,
"p50Microseconds": 104.3,
"p95Microseconds": 248.8,
"p99Microseconds": 376.4,
"processAllocatedBytes": 4047528
},
{
"scenario": "tcp/broadcast",
"connections": 256,
"bytes": 64,
"elapsedMilliseconds": 8.4403,
"delivered": 256
},
{
"scenario": "tcp/rpc",
"connections": 256,
"bytes": 1024,
"operations": 256,
"throughputPerSecond": 6911.465743698012,
"p50Microseconds": 99.3,
"p95Microseconds": 258.9,
"p99Microseconds": 355.1,
"processAllocatedBytes": 9916024
},
{
"scenario": "tcp/broadcast",
"connections": 256,
"bytes": 1024,
"elapsedMilliseconds": 9.0517,
"delivered": 256
},
{
"scenario": "tcp/rpc",
"connections": 256,
"bytes": 32768,
"operations": 256,
"throughputPerSecond": 1056.106917624073,
"p50Microseconds": 439.3,
"p95Microseconds": 1988.3,
"p99Microseconds": 14849.1,
"processAllocatedBytes": 228731112
},
{
"scenario": "tcp/broadcast",
"connections": 256,
"bytes": 32768,
"elapsedMilliseconds": 64.9767,
"delivered": 256
},
{
"scenario": "tcp/slow-consumer-burst",
"connections": 256,
"attempts": 2048,
"beforePump": {
"PendingCount": 30,
"PendingBytes": 32040,
"Rejected": 256,
"Replaced": 0,
"Completed": 0,
"OldestWaitMilliseconds": 123.9167,
"LastWaitMilliseconds": 0
},
"afterPump": {
"PendingCount": 23,
"PendingBytes": 24564,
"Rejected": 256,
"Replaced": 0,
"Completed": 7,
"OldestWaitMilliseconds": 123.3004,
"LastWaitMilliseconds": 123.418
},
"metrics": {
"CurrentSessions": 256,
"SessionsConnected": 256,
"SessionsDisconnected": 0,
"PacketsSent": 1536,
"PacketsReceived": 775,
"BytesSent": 17439488,
"BytesReceived": 8708404,
"RpcStarted": 0,
"RpcCompleted": 0,
"RpcTimedOut": 0,
"RpcCanceled": 0,
"RpcFailed": 0,
"ProtocolViolations": 0,
"AuthRejectedCount": 0,
"PermissionDeniedCount": 0,
"HandlerExceptionCount": 0,
"UnknownOpcodeCount": 0,
"DispatchMissCount": 7,
"SerializationErrorCount": 0,
"DispatchQueueRejectedCount": 256
}
}
]
}
+29
View File
@@ -0,0 +1,29 @@
# 新系统与玩法内容:先查可复用能力
仅在新增系统、玩法内容或扩展机制时使用本文。普通修复先定位受影响代码。
1. 用一句话明确目标行为和约束;不要增加未提出的玩法联动。
2. 执行 `shrink inspect capabilities "关键词" --root <项目>`。先读最多三个候选的用途、限制、扩展点和证据,再查选中模块的 `symbol` / `flow`。中文使用项目业务词,例如 `存档`、`状态`、`属性`;不同叫法可另查别名。
3. 按 **配置 → 组合 → 扩展已有机制 → 新模块** 判断。候选命中不是复用证明;对照真实接口、实例和行为测试。资料缺失不能解释成能力不存在。
4. 确认状态归属、操作入口、结构化结果和退出时的撤销。只展开实际相关的持久化、联机、UI 或生命周期约束。
5. 明确列出已存在、本次新增和待确认。不要为复用绕开权限、反向依赖模块、用无结果事件执行需要裁决的操作,或把大量胶水代码包装成零新增能力。
默认输出四项:复用方案及证据、必要改动、协作关系、影响与验证。只有会改变结果而无法从项目推导的选择才询问用户。
例如击杀怒气机制,需要分别核对击杀事实、计量、条件触发、属性修饰及效果撤回。存在 EventBus 不证明这些业务能力已经存在;存在存档功能也不意味着这次怒气必须持久化。
## 能力说明格式
在模块现有 README 中只保留一个区段。说明业务含义,不重复生成的 API 签名、依赖和版本。
```text
<!-- shrink:capabilities -->
Capability: 能实现的行为
Aliases: 常见中文叫法 English aliases
Limits: 明确不支持的行为或成立条件
Extension: 可配置或组合的位置;需要新增代码的边界
Evidence: 相对本 README 的源码、配置类型和可运行示例路径
<!-- /shrink:capabilities -->
```
框架维护 SDK 能力,消费项目维护自己的业务能力。业务目录即使共享 asmdef 也可以声明能力。不得假定所有项目都有背包、战斗、任务或属性系统。
@@ -1,9 +0,0 @@
## Release 0.1.0
### New Rules
Rule ID | Category | Severity | Notes
--------|----------|----------|-------
SHRINK001 | ShrinkSDK.CodeGen | Error | Invalid event subscriber signature
SHRINK002 | ShrinkSDK.CodeGen | Error | Duplicate network opcode and route
SHRINK003 | ShrinkSDK.CodeGen | Error | Invalid application installer
@@ -1,75 +0,0 @@
#nullable enable
using System;
using System.Collections.Concurrent;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace ShrinkSDK.CodeGen.Analyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class ShrinkCodeGenAnalyzer : DiagnosticAnalyzer
{
private static readonly DiagnosticDescriptor InvalidEventHandler = new(
"SHRINK001", "Invalid event subscriber signature",
"Method '{0}' must use void(TEvent), UniTask(TEvent), or UniTask(TEvent, CancellationToken)",
"ShrinkSDK.CodeGen", DiagnosticSeverity.Error, true);
private static readonly DiagnosticDescriptor DuplicateNetworkContract = new(
"SHRINK002", "Duplicate network opcode and route",
"Network opcode/route '{0}' is already declared by '{1}'",
"ShrinkSDK.CodeGen", DiagnosticSeverity.Error, true);
private static readonly DiagnosticDescriptor InvalidInstaller = new(
"SHRINK003", "Invalid application installer",
"Type '{0}' has ShrinkAppModuleInstaller but does not implement IShrinkAppModuleInstaller",
"ShrinkSDK.CodeGen", DiagnosticSeverity.Error, true);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
ImmutableArray.Create(InvalidEventHandler, DuplicateNetworkContract, InvalidInstaller);
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
context.RegisterCompilationStartAction(start =>
{
var networkContracts = new ConcurrentDictionary<string, INamedTypeSymbol>(StringComparer.Ordinal);
start.RegisterSymbolAction(symbolContext => AnalyzeMethod(symbolContext), SymbolKind.Method);
start.RegisterSymbolAction(symbolContext => AnalyzeType(symbolContext, networkContracts), SymbolKind.NamedType);
});
}
private static void AnalyzeMethod(SymbolAnalysisContext context)
{
var method = (IMethodSymbol)context.Symbol;
if (!HasAttribute(method, "ShrinkEventBus.ShrinkSubscribeAttribute")) return;
var parametersValid = method.Parameters.Length == 1 ||
method.Parameters.Length == 2 && method.Parameters[1].Type.ToDisplayString() == "System.Threading.CancellationToken";
var returnName = method.ReturnType.ToDisplayString();
var returnValid = method.Parameters.Length == 1 && (method.ReturnsVoid || returnName == "Cysharp.Threading.Tasks.UniTask") ||
method.Parameters.Length == 2 && returnName == "Cysharp.Threading.Tasks.UniTask";
if (!parametersValid || !returnValid)
context.ReportDiagnostic(Diagnostic.Create(InvalidEventHandler, method.Locations.FirstOrDefault(), method.Name));
}
private static void AnalyzeType(SymbolAnalysisContext context, ConcurrentDictionary<string, INamedTypeSymbol> networkContracts)
{
var type = (INamedTypeSymbol)context.Symbol;
if (HasAttribute(type, "ShrinkApp.ShrinkAppModuleInstallerAttribute") &&
!type.AllInterfaces.Any(item => item.ToDisplayString() == "ShrinkApp.IShrinkAppModuleInstaller"))
context.ReportDiagnostic(Diagnostic.Create(InvalidInstaller, type.Locations.FirstOrDefault(), type.Name));
var network = type.GetAttributes().FirstOrDefault(attribute =>
attribute.AttributeClass?.ToDisplayString() == "ShrinkNetwork.ShrinkNetworkMessageAttribute");
if (network == null || network.ConstructorArguments.Length == 0) return;
var opcode = network.ConstructorArguments[0].Value?.ToString() ?? string.Empty;
var route = network.ConstructorArguments.Length > 1 ? network.ConstructorArguments[1].Value as string ?? string.Empty : string.Empty;
var key = opcode + ":" + route;
if (!networkContracts.TryAdd(key, type) && networkContracts.TryGetValue(key, out var previous))
context.ReportDiagnostic(Diagnostic.Create(DuplicateNetworkContract, type.Locations.FirstOrDefault(), key, previous.Name));
}
private static bool HasAttribute(ISymbol symbol, string fullName) =>
symbol.GetAttributes().Any(attribute => attribute.AttributeClass?.ToDisplayString() == fullName);
}
@@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>ShrinkSDK.CodeGen.Analyzers</AssemblyName>
<RootNamespace>ShrinkSDK.CodeGen.Analyzers</RootNamespace>
<IsPackable>false</IsPackable>
<IncludeBuildOutput>false</IncludeBuildOutput>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" PrivateAssets="all" />
</ItemGroup>
</Project>
@@ -1,15 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>ShrinkSDK.CodeGen.Core</AssemblyName>
<RootNamespace>ShrinkSDK.CodeGen</RootNamespace>
<PackageId>ShrinkSDK.CodeGen.Core</PackageId>
<Version>0.1.0</Version>
<IsPackable>true</IsPackable>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\Assets\Modules\ShrinkShared.CodeGen\Editor\Core\*.cs" />
<PackageReference Include="Mono.Cecil" Version="0.11.6" />
</ItemGroup>
</Project>
@@ -1,34 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>ShrinkSDK.CodeGen.Task</AssemblyName>
<RootNamespace>ShrinkSDK.CodeGen</RootNamespace>
<PackageId>ShrinkSDK.CodeGen</PackageId>
<Version>0.1.0</Version>
<Description>MSBuild integration for ShrinkSDK Cecil weaving.</Description>
<IsPackable>true</IsPackable>
<BuildOutputTargetFolder>tools</BuildOutputTargetFolder>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeShrinkCodeGenDependencies</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ShrinkSDK.CodeGen.Core\ShrinkSDK.CodeGen.Core.csproj" />
<ProjectReference Include="..\ShrinkSDK.CodeGen.Analyzers\ShrinkSDK.CodeGen.Analyzers.csproj" ReferenceOutputAssembly="false" />
<PackageReference Include="Mono.Cecil" Version="0.11.6" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.14.28" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.14.28" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<None Include="buildTransitive\ShrinkSDK.CodeGen.props" Pack="true" PackagePath="buildTransitive\ShrinkSDK.CodeGen.props" />
<None Include="buildTransitive\ShrinkSDK.CodeGen.targets" Pack="true" PackagePath="buildTransitive\ShrinkSDK.CodeGen.targets" />
<None Include="..\ShrinkSDK.CodeGen.Analyzers\bin\$(Configuration)\netstandard2.0\ShrinkSDK.CodeGen.Analyzers.dll"
Pack="true" PackagePath="analyzers\dotnet\cs\ShrinkSDK.CodeGen.Analyzers.dll" />
</ItemGroup>
<Target Name="IncludeShrinkCodeGenDependencies" DependsOnTargets="Build">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)ShrinkSDK.CodeGen.Core.dll" />
<BuildOutputInPackage Include="$(OutputPath)Mono.Cecil.dll" />
</ItemGroup>
</Target>
</Project>
@@ -1,98 +0,0 @@
#nullable enable
using System;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace ShrinkSDK.CodeGen;
public sealed class ShrinkWeaveTask : Task
{
[Required]
public string AssemblyPath { get; set; } = string.Empty;
public string? PdbPath { get; set; }
public ITaskItem[] ReferencePaths { get; set; } = Array.Empty<ITaskItem>();
public string? StrongNameKeyFile { get; set; }
[Output] public bool Changed { get; private set; }
[Output] public int InstanceSubscriberCount { get; private set; }
[Output] public int StaticSubscriberCount { get; private set; }
[Output] public int RegistryEntryCount { get; private set; }
public override bool Execute()
{
if (!File.Exists(AssemblyPath))
{
Log.LogError($"[ShrinkSDK.CodeGen] Intermediate assembly does not exist: {AssemblyPath}");
return false;
}
var assemblyDirectory = Path.GetDirectoryName(Path.GetFullPath(AssemblyPath))!;
var temporaryAssembly = Path.Combine(assemblyDirectory, $".{Path.GetFileName(AssemblyPath)}.{Guid.NewGuid():N}.tmp");
var hasPdb = !string.IsNullOrWhiteSpace(PdbPath) && File.Exists(PdbPath);
var temporaryPdb = hasPdb
? Path.Combine(assemblyDirectory, $".{Path.GetFileName(PdbPath)}.{Guid.NewGuid():N}.tmp")
: null;
try
{
var result = ShrinkAssemblyWeaver.Weave(
AssemblyPath,
hasPdb ? PdbPath : null,
ReferencePaths.Select(item => item.ItemSpec),
temporaryAssembly,
temporaryPdb,
ShrinkCodeGenPlatform.EngineNeutral,
StrongNameKeyFile);
foreach (var diagnostic in result.Diagnostics)
{
switch (diagnostic.Severity)
{
case ShrinkCodeGenDiagnosticSeverity.Warning:
Log.LogWarning($"[ShrinkSDK.CodeGen] {diagnostic.Message}");
break;
case ShrinkCodeGenDiagnosticSeverity.Error:
Log.LogError($"[ShrinkSDK.CodeGen] {diagnostic.Message}");
break;
default:
Log.LogMessage(MessageImportance.Low, $"[ShrinkSDK.CodeGen] {diagnostic.Message}");
break;
}
}
if (!result.Succeeded)
return false;
Changed = result.Changed;
InstanceSubscriberCount = result.InstanceSubscribers;
StaticSubscriberCount = result.StaticSubscribers;
RegistryEntryCount = result.RegistryEntries;
if (Changed)
{
File.Move(temporaryAssembly, AssemblyPath, true);
if (hasPdb && temporaryPdb != null)
File.Move(temporaryPdb, PdbPath!, true);
}
Log.LogMessage(MessageImportance.High,
$"[ShrinkSDK.CodeGen] {Path.GetFileName(AssemblyPath)} woven: instance={InstanceSubscriberCount}, static={StaticSubscriberCount}, registry={RegistryEntryCount}.");
return true;
}
catch (Exception exception)
{
Log.LogErrorFromException(exception, true);
return false;
}
finally
{
TryDelete(temporaryAssembly);
if (temporaryPdb != null) TryDelete(temporaryPdb);
}
}
private static void TryDelete(string path)
{
try { if (File.Exists(path)) File.Delete(path); }
catch { }
}
}
@@ -1,5 +0,0 @@
<Project>
<PropertyGroup>
<ShrinkCodeGenEnabled Condition="'$(ShrinkCodeGenEnabled)' == ''">true</ShrinkCodeGenEnabled>
</PropertyGroup>
</Project>
@@ -1,18 +0,0 @@
<Project>
<PropertyGroup>
<_ShrinkCodeGenTaskAssembly Condition="'$(_ShrinkCodeGenTaskAssembly)' == ''">$(MSBuildThisFileDirectory)..\tools\net8.0\ShrinkSDK.CodeGen.Task.dll</_ShrinkCodeGenTaskAssembly>
</PropertyGroup>
<UsingTask TaskName="ShrinkSDK.CodeGen.ShrinkWeaveTask" AssemblyFile="$(_ShrinkCodeGenTaskAssembly)" />
<Target Name="ShrinkCodeGenWeave"
AfterTargets="CoreCompile"
BeforeTargets="CopyFilesToOutputDirectory"
Condition="'$(ShrinkCodeGenEnabled)' == 'true' and '$(DesignTimeBuild)' != 'true'">
<PropertyGroup>
<_ShrinkCodeGenIntermediateAssembly>$(IntermediateOutputPath)$(TargetName).dll</_ShrinkCodeGenIntermediateAssembly>
</PropertyGroup>
<ShrinkWeaveTask AssemblyPath="$(_ShrinkCodeGenIntermediateAssembly)"
PdbPath="$(IntermediateOutputPath)$(TargetName).pdb"
ReferencePaths="@(ReferencePath)"
StrongNameKeyFile="$(ShrinkCodeGenStrongNameKeyFile)" />
</Target>
</Project>
@@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>ShrinkSDK.Godot.Installer</AssemblyName>
<PackageId>ShrinkSDK.Godot.Installer</PackageId>
<Version>0.1.1</Version>
<Description>Godot Editor package manager and CodeGen diagnostics for ShrinkSDK.</Description>
</PropertyGroup>
<ItemGroup>
<Compile Include="addons\shrinksdk\*.cs" />
<Compile Include="..\..\Assets\Modules\ShrinkInstaller\Editor\ShrinkPackageVersion.cs" Link="addons\shrinksdk\ShrinkPackageVersion.cs" />
<PackageReference Include="GodotSharp" Version="4.6.3" />
<PackageReference Include="GodotSharpEditor" Version="4.6.3" />
<None Include="addons\shrinksdk\plugin.cfg" Pack="true" PackagePath="contentFiles\any\any\addons\shrinksdk\plugin.cfg" />
<None Include="addons\shrinksdk\*.cs" Pack="true" PackagePath="contentFiles\any\any\addons\shrinksdk\" />
<None Include="..\..\Assets\Modules\ShrinkInstaller\Editor\ShrinkPackageVersion.cs" Pack="true" PackagePath="contentFiles\any\any\addons\shrinksdk\ShrinkPackageVersion.cs" />
</ItemGroup>
</Project>
@@ -1,133 +0,0 @@
#nullable enable
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Godot;
using ShrinkSDK.Installer;
namespace ShrinkSDK.Godot.Editor;
[Tool]
public partial class ShrinkGodotInstallerPlugin : EditorPlugin
{
private EditorDock? _panel;
private Label? _status;
private RichTextLabel? _output;
private readonly System.Collections.Generic.Dictionary<string, Button> _installActions =
new(StringComparer.OrdinalIgnoreCase);
private readonly System.Collections.Generic.Dictionary<string, Button> _removeActions =
new(StringComparer.OrdinalIgnoreCase);
private string ProjectDirectory => ProjectSettings.GlobalizePath("res://");
private string ProjectPath => Directory.GetFiles(ProjectDirectory, "*.csproj", SearchOption.TopDirectoryOnly).Single();
public override void _EnterTree()
{
_panel = new EditorDock { Name = "ShrinkSDK", Title = "ShrinkSDK", DefaultSlot = EditorDock.DockSlot.LeftBr };
var content = new VBoxContainer();
_panel.AddChild(content);
content.AddChild(new Label { Text = "ShrinkSDK Packages" });
_installActions.Clear();
_removeActions.Clear();
foreach (var package in ShrinkProjectPackageEditor.RecommendedPackages)
{
var row = new HBoxContainer();
row.AddChild(new Label { Text = $"{package.Key} {package.Value}", SizeFlagsHorizontal = Control.SizeFlags.ExpandFill });
var install = new Button { Text = "Install / Update" };
install.Pressed += () => ChangePackage(package.Key, package.Value);
row.AddChild(install);
_installActions[package.Key] = install;
var remove = new Button { Text = "Remove" };
remove.Pressed += () => ChangePackage(package.Key, null);
row.AddChild(remove);
_removeActions[package.Key] = remove;
content.AddChild(row);
}
var restore = new Button { Text = "Restore and Build" };
restore.Pressed += BuildProject;
content.AddChild(restore);
_status = new Label { Text = "CodeGen: not built" };
content.AddChild(_status);
_output = new RichTextLabel { FitContent = true, CustomMinimumSize = new Vector2(360, 180) };
content.AddChild(_output);
AddDock(_panel);
RefreshInstalledState();
}
public override void _ExitTree()
{
if (_panel == null) return;
RemoveDock(_panel);
_panel.QueueFree();
_panel = null;
}
private async void ChangePackage(string packageId, string? version)
{
try
{
ShrinkProjectPackageEditor.EnsureShrinkFeed(Path.Combine(ProjectDirectory, "NuGet.Config"));
ShrinkProjectPackageEditor.SetPackageReference(ProjectPath, packageId, version);
await RunBuild("restore");
}
catch (Exception exception) { ShowFailure(exception); }
}
private async void BuildProject()
{
try { await RunBuild("build"); }
catch (Exception exception) { ShowFailure(exception); }
}
private async System.Threading.Tasks.Task RunBuild(string command)
{
_status!.Text = $"CodeGen: running dotnet {command}";
var result = await ShrinkProjectPackageEditor.RunDotnetAsync(ProjectDirectory, $"{command} \"{ProjectPath}\" /nr:false");
_output!.Text = result.Output;
var match = Regex.Matches(result.Output, @"\[ShrinkSDK\.CodeGen\].*woven: instance=(\d+), static=(\d+), registry=(\d+)").Cast<Match>().LastOrDefault();
_status.Text = result.ExitCode == 0
? match == null ? "CodeGen: build succeeded (no attributed registrations)" : $"CodeGen: woven; instance={match.Groups[1].Value}, static={match.Groups[2].Value}, registry={match.Groups[3].Value}"
: "CodeGen: build failed";
RefreshInstalledState();
}
private void RefreshInstalledState()
{
if (_output == null) return;
var installed = File.Exists(ProjectPath)
? ShrinkProjectPackageEditor.ReadPackageReferences(ProjectPath)
: new System.Collections.Generic.Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var package in ShrinkProjectPackageEditor.RecommendedPackages)
{
var hasInstalled = installed.TryGetValue(package.Key, out var installedVersion);
var relation = hasInstalled
? ShrinkPackageVersion.Classify(installedVersion, package.Value)
: ShrinkPackageVersionRelation.Unknown;
if (_installActions.TryGetValue(package.Key, out var install))
{
install.Text = !hasInstalled
? $"Install {package.Value}"
: relation switch
{
ShrinkPackageVersionRelation.Equal => $"Installed {installedVersion}",
ShrinkPackageVersionRelation.Newer => $"Newer {installedVersion}",
ShrinkPackageVersionRelation.Older => $"Upgrade {installedVersion} → {package.Value}",
_ => $"Update {installedVersion} → {package.Value}"
};
install.Disabled = hasInstalled && relation is
ShrinkPackageVersionRelation.Equal or ShrinkPackageVersionRelation.Newer;
}
if (_removeActions.TryGetValue(package.Key, out var remove))
remove.Disabled = !hasInstalled;
}
_output.Text = "Direct packages: " + string.Join(", ", installed.Select(item => $"{item.Key}@{item.Value}"));
}
private void ShowFailure(Exception exception)
{
_status!.Text = "CodeGen: operation failed";
_output!.Text = exception.ToString();
GD.PushError(exception.ToString());
}
}
@@ -1,148 +0,0 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace ShrinkSDK.Godot.Editor;
public static class ShrinkProjectPackageEditor
{
public static readonly IReadOnlyDictionary<string, string> RecommendedPackages =
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
["ShrinkSDK.Godot"] = "0.1.0",
["ShrinkSDK.EventBus"] = "2.1.0",
["ShrinkSDK.Context.Core"] = "0.2.0",
["ShrinkSDK.Command"] = "0.3.0",
["ShrinkSDK.Command.Integration.EventBus"] = "0.2.0",
["ShrinkSDK.Command.Integration.Network"] = "0.2.0",
["ShrinkSDK.Command.Integration.App"] = "0.2.0",
["ShrinkSDK.Network"] = "0.3.0",
["ShrinkSDK.Network.Integration.EventBus"] = "0.2.0",
["ShrinkSDK.Network.Integration.App"] = "0.2.0",
["ShrinkSDK.DataSaver"] = "2.3.0",
["ShrinkSDK.DataSaver.Integration.EventBus"] = "2.2.0",
["ShrinkSDK.DataSaver.Integration.App"] = "0.2.0",
["ShrinkSDK.App.Core"] = "0.2.0",
["ShrinkSDK.Context.AppAdapter"] = "0.2.0",
["ShrinkSDK.App.Starter.Basic"] = "0.3.0",
["ShrinkSDK.ModFramework"] = "0.3.0",
["ShrinkSDK.ModFramework.Godot"] = "0.1.0",
["ShrinkSDK.Tutorial"] = "0.2.0",
["ShrinkSDK.Tutorial.Godot"] = "0.1.0"
};
public static IReadOnlyDictionary<string, string> ReadPackageReferences(string projectPath)
{
var document = XDocument.Load(projectPath, LoadOptions.PreserveWhitespace);
return document.Descendants("PackageReference")
.Select(element => new
{
Id = ((string?)element.Attribute("Include") ?? (string?)element.Attribute("Update"))?.Trim(),
Version = ((string?)element.Attribute("Version") ??
(string?)element.Attribute("VersionOverride") ??
element.Element("Version")?.Value)?.Trim() ?? string.Empty
})
.Where(item => !string.IsNullOrWhiteSpace(item.Id))
.GroupBy(item => item.Id!, StringComparer.OrdinalIgnoreCase)
.ToDictionary(group => group.Key, group => group.First().Version, StringComparer.OrdinalIgnoreCase);
}
public static void SetPackageReference(string projectPath, string packageId, string? version)
{
var document = XDocument.Load(projectPath, LoadOptions.PreserveWhitespace);
var root = document.Root ?? throw new InvalidDataException("The C# project has no root element.");
var references = root.Descendants("PackageReference").Where(element =>
string.Equals((string?)element.Attribute("Include"), packageId, StringComparison.OrdinalIgnoreCase)).ToArray();
foreach (var duplicate in references.Skip(1)) duplicate.Remove();
if (string.IsNullOrWhiteSpace(version))
{
foreach (var reference in references) reference.Remove();
}
else if (references.Length > 0)
{
var reference = references[0];
if (reference.Attribute("VersionOverride") != null)
reference.SetAttributeValue("VersionOverride", version);
else if (reference.Attribute("Version") != null)
reference.SetAttributeValue("Version", version);
else if (reference.Element("Version") != null)
reference.Element("Version")!.Value = version;
else
reference.SetAttributeValue("Version", version);
}
else
{
var group = root.Elements("ItemGroup").FirstOrDefault(element => element.Elements("PackageReference").Any());
if (group == null)
{
group = new XElement("ItemGroup");
root.Add(group);
}
group.Add(new XElement("PackageReference", new XAttribute("Include", packageId), new XAttribute("Version", version)));
}
WriteAtomically(projectPath, document);
}
public static void EnsureShrinkFeed(string nugetConfigPath)
{
XDocument document;
if (File.Exists(nugetConfigPath)) document = XDocument.Load(nugetConfigPath, LoadOptions.PreserveWhitespace);
else document = new XDocument(new XDeclaration("1.0", "utf-8", null), new XElement("configuration"));
var root = document.Root ?? throw new InvalidDataException("NuGet.Config has no root element.");
var sources = root.Element("packageSources");
if (sources == null)
{
sources = new XElement("packageSources");
root.Add(sources);
}
var existing = sources.Elements("add").FirstOrDefault(element =>
string.Equals((string?)element.Attribute("key"), "ShrinkSDK", StringComparison.OrdinalIgnoreCase));
if (existing == null)
sources.Add(new XElement("add", new XAttribute("key", "ShrinkSDK"),
new XAttribute("value", "https://git.crash.work/api/packages/ShrinkSDK/nuget/index.json")));
else
existing.SetAttributeValue("value", "https://git.crash.work/api/packages/ShrinkSDK/nuget/index.json");
WriteAtomically(nugetConfigPath, document);
}
public static async Task<(int ExitCode, string Output)> RunDotnetAsync(string projectDirectory,
string arguments, CancellationToken cancellationToken = default)
{
var output = new StringBuilder();
using var process = new Process
{
StartInfo = new ProcessStartInfo("dotnet", arguments)
{
WorkingDirectory = projectDirectory,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};
process.OutputDataReceived += (_, args) => { if (args.Data != null) output.AppendLine(args.Data); };
process.ErrorDataReceived += (_, args) => { if (args.Data != null) output.AppendLine(args.Data); };
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
await process.WaitForExitAsync(cancellationToken);
return (process.ExitCode, output.ToString());
}
private static void WriteAtomically(string path, XDocument document)
{
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))!);
var temporaryPath = path + ".shrinksdk.tmp";
using (var writer = new StreamWriter(temporaryPath, false, new UTF8Encoding(false)))
document.Save(writer, SaveOptions.DisableFormatting);
File.Move(temporaryPath, path, true);
}
}
@@ -1,7 +0,0 @@
[plugin]
name="ShrinkSDK Installer"
description="Installs and diagnoses ShrinkSDK NuGet modules and CodeGen weaving."
author="ShrinkSDK"
version="0.1.1"
script="ShrinkGodotInstallerPlugin.cs"
@@ -1,137 +0,0 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Cysharp.Threading.Tasks;
namespace ShrinkApp;
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class ShrinkAppModuleInstallerAttribute : Attribute { }
public interface IShrinkAppModuleInstaller
{
string ModuleId { get; }
int Order { get; }
IReadOnlyList<string> DependsOn { get; }
void RegisterServices(ShrinkAppContext context);
UniTask InitializeAsync(ShrinkAppContext context);
}
public interface IShrinkAppModuleShutdown
{
UniTask ShutdownAsync(ShrinkAppContext context);
}
public sealed class ShrinkAppSettings
{
public bool VerboseLogging { get; set; }
public string[] DisabledModuleIds { get; set; } = Array.Empty<string>();
}
public sealed class ShrinkAppServices
{
private readonly Dictionary<Type, object> _services = new();
public void Register<T>(T service) where T : class => _services[typeof(T)] = service ?? throw new ArgumentNullException(nameof(service));
public bool TryGet<T>(out T? service) where T : class
{
service = _services.TryGetValue(typeof(T), out var value) ? value as T : null;
return service != null;
}
public T GetRequired<T>() where T : class => TryGet<T>(out var value) ? value! : throw new InvalidOperationException($"Required service is not registered: {typeof(T).FullName}");
public bool TryUnregister<T>(T service) where T : class => _services.TryGetValue(typeof(T), out var value) && ReferenceEquals(value, service) && _services.Remove(typeof(T));
}
public sealed class ShrinkAppContext
{
public ShrinkAppContext(object? host, ShrinkAppSettings settings, ShrinkAppServices services)
{
Host = host;
Settings = settings ?? throw new ArgumentNullException(nameof(settings));
Services = services ?? throw new ArgumentNullException(nameof(services));
}
public object? Host { get; }
public ShrinkAppSettings Settings { get; }
public ShrinkAppServices Services { get; }
public static ShrinkAppContext CreateStandalone(ShrinkAppServices services, ShrinkAppSettings? settings = null) => new(null, settings ?? new ShrinkAppSettings(), services);
}
public sealed class ShrinkAppRuntime
{
private readonly List<IShrinkAppModuleInstaller> _started = new();
public ShrinkAppRuntime(object? host = null, ShrinkAppSettings? settings = null, ShrinkAppServices? services = null)
{
Context = new ShrinkAppContext(host, settings ?? new ShrinkAppSettings(), services ?? new ShrinkAppServices());
}
public ShrinkAppContext Context { get; }
public bool IsRunning { get; private set; }
public IReadOnlyList<string> StartedModules => _started.Select(item => item.ModuleId).ToArray();
public async UniTask StartAsync()
{
if (IsRunning) return;
var installers = Sort(CreateInstallers(), Context.Settings.DisabledModuleIds);
try
{
foreach (var installer in installers) installer.RegisterServices(Context);
foreach (var installer in installers)
{
await installer.InitializeAsync(Context);
_started.Add(installer);
}
IsRunning = true;
}
catch
{
await ShutdownStartedAsync();
throw;
}
}
public async UniTask ShutdownAsync()
{
await ShutdownStartedAsync();
IsRunning = false;
}
private async UniTask ShutdownStartedAsync()
{
for (var index = _started.Count - 1; index >= 0; index--)
if (_started[index] is IShrinkAppModuleShutdown shutdown) await shutdown.ShutdownAsync(Context);
_started.Clear();
}
private static IReadOnlyList<IShrinkAppModuleInstaller> CreateInstallers() =>
ShrinkAppInstallers.GetDiscoveredInstallerTypes().Select(type =>
Activator.CreateInstance(type) as IShrinkAppModuleInstaller ?? throw new InvalidOperationException($"Failed to create installer: {type.FullName}"))
.ToArray();
private static IReadOnlyList<IShrinkAppModuleInstaller> Sort(IEnumerable<IShrinkAppModuleInstaller> source, IEnumerable<string> disabledIds)
{
var disabled = new HashSet<string>(disabledIds ?? Array.Empty<string>(), StringComparer.OrdinalIgnoreCase);
var byId = source.Where(item => !disabled.Contains(item.ModuleId)).ToDictionary(item => item.ModuleId, StringComparer.OrdinalIgnoreCase);
var states = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
var result = new List<IShrinkAppModuleInstaller>();
foreach (var installer in byId.Values.OrderBy(item => item.Order).ThenBy(item => item.ModuleId, StringComparer.OrdinalIgnoreCase))
Visit(installer, byId, states, result);
return result;
}
private static void Visit(IShrinkAppModuleInstaller installer, IReadOnlyDictionary<string, IShrinkAppModuleInstaller> byId,
IDictionary<string, int> states, ICollection<IShrinkAppModuleInstaller> result)
{
var state = states.TryGetValue(installer.ModuleId, out var value) ? value : 0;
if (state == 2) return;
if (state == 1) throw new InvalidOperationException($"Circular installer dependency: {installer.ModuleId}");
states[installer.ModuleId] = 1;
foreach (var dependencyId in installer.DependsOn ?? Array.Empty<string>())
{
if (!byId.TryGetValue(dependencyId, out var dependency))
throw new InvalidOperationException($"Installer dependency missing. Module={installer.ModuleId}, DependsOn={dependencyId}");
Visit(dependency, byId, states, result);
}
states[installer.ModuleId] = 2;
result.Add(installer);
}
}
@@ -1,20 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>ShrinkApp.Core.Runtime</AssemblyName>
<RootNamespace>ShrinkApp</RootNamespace>
<PackageId>ShrinkSDK.App.Core</PackageId>
<Version>0.2.0</Version>
<Description>ShrinkSDK engine-neutral application composition runtime.</Description>
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
</PropertyGroup>
<ItemGroup>
<Compile Include="Runtime\ShrinkAppCore.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkApp.Core\Runtime\ShrinkAppGeneratedRegistry.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkApp.Core\Runtime\ShrinkAppInstallers.cs" />
<PackageReference Include="UniTask" Version="2.5.10" />
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
</ItemGroup>
</Project>
@@ -1,34 +0,0 @@
#nullable enable
using System.Collections.Generic;
using ShrinkApp;
using ShrinkCommand.Integration.App;
using ShrinkContext;
using ShrinkContext.AppAdapter;
using ShrinkDataSaver.Integration.App;
using ShrinkNetwork.Integration.App;
namespace ShrinkApp.Starter.Basic;
public static class ShrinkBasicComposition
{
public static ShrinkContextAppHost CreateHost(ShrinkAppServices? services = null)
{
var host = new ShrinkContextAppHost(services);
host.Register<ShrinkCommandAppComponent>("shrink.command");
host.Register<ShrinkDataSaverAppComponent>("shrink.datasaver");
host.Register<ShrinkNetworkAppComponent>("shrink.network");
return host;
}
public static IReadOnlyList<ShrinkLoaderEntry> CreateEntries(ShrinkAppServices services,
ShrinkNetworkAppModuleConfig? network = null) => new[]
{
new ShrinkLoaderEntry("datasaver", "shrink.datasaver", services),
new ShrinkLoaderEntry("command", "shrink.command", services),
new ShrinkLoaderEntry("network", "shrink.network", network ?? new ShrinkNetworkAppModuleConfig
{
Services = services
})
};
}
@@ -1,21 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>ShrinkApp.Starter.Basic</AssemblyName>
<RootNamespace>ShrinkApp.Starter.Basic</RootNamespace>
<PackageId>ShrinkSDK.App.Starter.Basic</PackageId>
<Version>0.3.0</Version>
<Description>Engine-neutral basic ShrinkApp composition.</Description>
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
</PropertyGroup>
<ItemGroup>
<Compile Include="Runtime\*.cs" />
<ProjectReference Include="..\ShrinkSDK.App.Core\ShrinkSDK.App.Core.csproj" />
<ProjectReference Include="..\ShrinkSDK.Context.Core\ShrinkSDK.Context.Core.csproj" />
<ProjectReference Include="..\ShrinkSDK.Context.AppAdapter\ShrinkSDK.Context.AppAdapter.csproj" />
<ProjectReference Include="..\ShrinkSDK.Command.Integration.App\ShrinkSDK.Command.Integration.App.csproj" />
<ProjectReference Include="..\ShrinkSDK.DataSaver.Integration.App\ShrinkSDK.DataSaver.Integration.App.csproj" />
<ProjectReference Include="..\ShrinkSDK.Network.Integration.App\ShrinkSDK.Network.Integration.App.csproj" />
</ItemGroup>
</Project>
@@ -1,20 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>ShrinkCommand.Integration.EventBus</AssemblyName>
<RootNamespace>ShrinkCommand.Integration</RootNamespace>
<PackageId>ShrinkSDK.Command.Integration.EventBus</PackageId>
<Version>0.2.0</Version>
<Description>ShrinkCommand and EventBus integration.</Description>
<ShrinkCodeGenEnabled>true</ShrinkCodeGenEnabled>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\Assets\Modules\ShrinkCommand.Integration.EventBus\*.cs" />
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
<ProjectReference Include="..\ShrinkSDK.Context.Core\ShrinkSDK.Context.Core.csproj" />
<ProjectReference Include="..\ShrinkSDK.EventBus\ShrinkSDK.EventBus.csproj" />
<ProjectReference Include="..\ShrinkSDK.Command\ShrinkSDK.Command.csproj" />
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
</ItemGroup>
</Project>
@@ -1,20 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>ShrinkCommand.Integration.Network</AssemblyName>
<RootNamespace>ShrinkCommand.Integration</RootNamespace>
<PackageId>ShrinkSDK.Command.Integration.Network</PackageId>
<Version>0.2.0</Version>
<Description>ShrinkCommand and Network RPC integration.</Description>
<ShrinkCodeGenEnabled>true</ShrinkCodeGenEnabled>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\Assets\Modules\ShrinkCommand.Integration.Network\*.cs" />
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
<ProjectReference Include="..\ShrinkSDK.Context.Core\ShrinkSDK.Context.Core.csproj" />
<ProjectReference Include="..\ShrinkSDK.Command\ShrinkSDK.Command.csproj" />
<ProjectReference Include="..\ShrinkSDK.Network\ShrinkSDK.Network.csproj" />
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
</ItemGroup>
</Project>
@@ -1,18 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>ShrinkCommand.Runtime</AssemblyName>
<RootNamespace>ShrinkCommand</RootNamespace>
<PackageId>ShrinkSDK.Command</PackageId>
<Version>0.3.0</Version>
<Description>ShrinkSDK command parsing, permissions and execution runtime.</Description>
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\Assets\Modules\ShrinkCommand\Runtime\**\*.cs" />
<PackageReference Include="UniTask" Version="2.5.10" />
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
</ItemGroup>
</Project>
@@ -1,31 +0,0 @@
#nullable enable
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using ShrinkApp;
namespace ShrinkContext.AppAdapter;
public sealed class ShrinkContextAppHost
{
private readonly ShrinkContextRuntime _runtime = new();
private readonly ShrinkComponentCatalog _catalog = new();
private readonly ShrinkContextLoader _loader;
public ShrinkContextAppHost(ShrinkAppServices? services = null)
{
Services = services ?? new ShrinkAppServices();
_loader = new ShrinkContextLoader(_runtime, _catalog);
}
public ShrinkAppServices Services { get; }
public ShrinkContextRuntime Runtime => _runtime;
public ShrinkLoaderTransactionDiagnostic? LastTransaction => _loader.LastTransaction;
public void Register(string name, Func<IShrinkComponent> factory) => _catalog.Register(name, factory);
public void Register<TComponent>(string name) where TComponent : IShrinkComponent, new() =>
_catalog.Register<TComponent>(name);
public UniTask ApplyAsync(IReadOnlyList<ShrinkLoaderEntry> entries) => _loader.ApplyAsync(entries);
public UniTask ShutdownAsync() => _runtime.ShutdownAsync();
}
@@ -1,17 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>ShrinkContext.AppAdapter</AssemblyName>
<RootNamespace>ShrinkContext.AppAdapter</RootNamespace>
<PackageId>ShrinkSDK.Context.AppAdapter</PackageId>
<Version>0.2.0</Version>
<Description>Engine-neutral ShrinkContext composition host for ShrinkApp.</Description>
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
</PropertyGroup>
<ItemGroup>
<Compile Include="Runtime\*.cs" />
<ProjectReference Include="..\ShrinkSDK.Context.Core\ShrinkSDK.Context.Core.csproj" />
<ProjectReference Include="..\ShrinkSDK.App.Core\ShrinkSDK.App.Core.csproj" />
</ItemGroup>
</Project>
@@ -1,17 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>ShrinkContext.Core.Runtime</AssemblyName>
<RootNamespace>ShrinkContext</RootNamespace>
<PackageId>ShrinkSDK.Context.Core</PackageId>
<Version>0.2.0</Version>
<Description>ShrinkSDK reversible context and fiber runtime.</Description>
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\Assets\Modules\ShrinkContext.Core\Runtime\**\*.cs" />
<PackageReference Include="UniTask" Version="2.5.10" />
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
</ItemGroup>
</Project>
@@ -1,20 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>ShrinkDataSaver.Integration.EventBus</AssemblyName>
<RootNamespace>ShrinkDataSaver.Integration</RootNamespace>
<PackageId>ShrinkSDK.DataSaver.Integration.EventBus</PackageId>
<Version>2.2.0</Version>
<Description>ShrinkDataSaver and EventBus integration.</Description>
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver.Integration.EventBus\*.cs" />
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
<ProjectReference Include="..\ShrinkSDK.Context.Core\ShrinkSDK.Context.Core.csproj" />
<ProjectReference Include="..\ShrinkSDK.EventBus\ShrinkSDK.EventBus.csproj" />
<ProjectReference Include="..\ShrinkSDK.DataSaver\ShrinkSDK.DataSaver.csproj" />
</ItemGroup>
</Project>
@@ -1,43 +0,0 @@
#nullable enable
using System.IO;
using Cysharp.Threading.Tasks;
using ShrinkSDK.Runtime;
namespace ShrinkDataSaver;
public sealed class ShrinkDataSaverRuntimeConfig
{
public string? RootPath { get; set; }
public string SaveFileExtension { get; set; } = ".sav";
public string SettingsFileName { get; set; } = "settings.json";
public int CurrentSaveVersion { get; set; } = 1;
public int MaxSlots { get; set; } = 3;
public float SettingsWriteDebounceSeconds { get; set; } = 0.35f;
public bool DontDestroyOnLoadDriver { get; set; }
}
public static class ShrinkDataSaverRuntime
{
public static bool IsInitialized { get; private set; }
public static void Initialize(ShrinkDataSaverRuntimeConfig? config = null)
{
if (IsInitialized) return;
config ??= new ShrinkDataSaverRuntimeConfig();
var root = string.IsNullOrWhiteSpace(config.RootPath)
? ShrinkRuntimeServices.Paths.PersistentDataPath
: config.RootPath!;
Directory.CreateDirectory(root);
var storage = new LocalStorageProvider(root);
ShrinkDataSaverPlatform.SettingsWriteDebounceSeconds = config.SettingsWriteDebounceSeconds;
ShrinkDataSaverPlatform.MaxSlots = config.MaxSlots;
ShrinkSettings.Initialize(storage, Path.Combine(root, config.SettingsFileName));
ShrinkSave.Initialize(storage, Path.Combine(root, "saves"), config.SaveFileExtension,
config.CurrentSaveVersion);
ShrinkSettings.LoadAsync().Forget();
IsInitialized = true;
ShrinkRuntimeServices.Logger.Log(ShrinkLogLevel.Information,
$"[ShrinkDataSaver] Runtime initialized. Root: {root}");
}
}
@@ -1,29 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>ShrinkDataSaver.Runtime</AssemblyName>
<RootNamespace>ShrinkDataSaver</RootNamespace>
<PackageId>ShrinkSDK.DataSaver</PackageId>
<Version>2.3.0</Version>
<Description>ShrinkSDK engine-neutral versioned save and settings runtime.</Description>
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="Runtime\ShrinkDataSaverRuntime.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\AssemblyInfo.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\DataSerializer.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\IStorageProvider.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\LocalStorageProvider.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\MigrationChain.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\SaveEncryptor.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\SaveTypes.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\ShrinkDataSaverPlatform.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\ShrinkSave.cs" />
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\ShrinkSettings.cs" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="UniTask" Version="2.5.10" />
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
</ItemGroup>
</Project>
@@ -1,19 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<AssemblyName>ShrinkEventBus.Runtime</AssemblyName>
<RootNamespace>ShrinkEventBus</RootNamespace>
<PackageId>ShrinkSDK.EventBus</PackageId>
<Version>2.1.0</Version>
<Description>ShrinkSDK typed event bus runtime.</Description>
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\..\Assets\Modules\ShrinkEventBus\Runtime\**\*.cs"
Exclude="..\..\..\Assets\Modules\ShrinkEventBus\Runtime\ShrinkMonoEventScope.cs" />
<PackageReference Include="UniTask" Version="2.5.10" />
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
</ItemGroup>
</Project>

Some files were not shown because too many files have changed in this diff Show More