fix: MCP server starts after 3rd frame to avoid blocking Vulkan init
- MCP server (Kestrel) launched on background thread after 3 frames to avoid conflicting with Vulkan/SDL3 initialization - --mcp-port 0 (default) = disabled, scene works as before - --mcp-port 5000 = MCP starts after 3rd frame - Reduced extra balls from 30 to 10 for stability - Engine.AI/McpEngineServerHost reverted to original (no WebApplicationOptions)
This commit is contained in:
@@ -39,29 +39,8 @@ class Program
|
||||
|
||||
#if !RELEASE_AOT
|
||||
WebApplication? mcpApp = null;
|
||||
if (mcpPort > 0)
|
||||
{
|
||||
var mcpThread = new Thread(() =>
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
try
|
||||
{
|
||||
mcpApp = McpEngineServerHost.Create(Array.Empty<string>(), queue, port: mcpPort);
|
||||
mcpApp.Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[App] MCP server error: {ex.Message}");
|
||||
}
|
||||
})
|
||||
{ IsBackground = true };
|
||||
mcpThread.Start();
|
||||
Console.WriteLine($"[App] MCP HTTP server starting on http://localhost:{mcpPort}/ (SSE)");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("[App] MCP server disabled (--mcp-port 0).");
|
||||
}
|
||||
var mcpStarted = false;
|
||||
var frameCount = 0;
|
||||
#endif
|
||||
|
||||
var cameraEntity = world.Entity("Camera")
|
||||
@@ -98,6 +77,29 @@ class Program
|
||||
window.PumpEvents();
|
||||
input.BeginFrame();
|
||||
|
||||
#if !RELEASE_AOT
|
||||
frameCount++;
|
||||
if (mcpPort > 0 && !mcpStarted && frameCount > 3)
|
||||
{
|
||||
mcpStarted = true;
|
||||
var port = mcpPort;
|
||||
var q = queue;
|
||||
new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
mcpApp = McpEngineServerHost.Create(Array.Empty<string>(), q, port: port);
|
||||
Console.WriteLine($"[App] MCP HTTP server listening on http://localhost:{port}/ (SSE)");
|
||||
mcpApp.Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[App] MCP server error: {ex.Message}");
|
||||
}
|
||||
}) { IsBackground = true }.Start();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (window.Width != lastWidth || window.Height != lastHeight)
|
||||
{
|
||||
lastWidth = window.Width;
|
||||
@@ -235,6 +237,24 @@ class Program
|
||||
.Set(RigidBody.DynamicSphere(0.7f, mass: 1.5f));
|
||||
}
|
||||
|
||||
var rand = new Random(42);
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var x = (float)(rand.NextDouble() * 16 - 8);
|
||||
var y = (float)(rand.NextDouble() * 15 + 5);
|
||||
var z = (float)(rand.NextDouble() * 16 - 8);
|
||||
var r = 0.3f + (float)rand.NextDouble() * 0.5f;
|
||||
var color = new Vector3(
|
||||
0.3f + (float)rand.NextDouble() * 0.7f,
|
||||
0.3f + (float)rand.NextDouble() * 0.7f,
|
||||
0.3f + (float)rand.NextDouble() * 0.7f);
|
||||
var ballMesh = ProceduralMesh.CreateSphere(r, 16, 8, color);
|
||||
world.Entity($"Ball{i}")
|
||||
.Set(new Transform(new Vector3(x, y, z), Quaternion.Identity, Vector3.One))
|
||||
.Set(ballMesh)
|
||||
.Set(RigidBody.DynamicSphere(r, mass: r * 2f));
|
||||
}
|
||||
|
||||
world.Entity("Floor")
|
||||
.Set(new Transform(new Vector3(0, -0.5f, 0), Quaternion.Identity, new Vector3(20, 0.5f, 20)))
|
||||
.Set(LoadMesh("Content/cube.obj", new Vector3(0.3f, 0.3f, 0.35f)))
|
||||
|
||||
Reference in New Issue
Block a user