spikes/KniWeb (outside LittleSim.sln): a kni-blazor-gl template project (KNI 4.2.9001, net8.0) referencing MrGameEng.Core directly. A mini-host in the GameHost mold drives EngineContext/GameClock/Scene phases over KNI's Game; the scene moves 300 Friflo entities in the update phase and draws them with SpriteBatch (WebGL). Verified in a real browser: sprites render and animate, browser console is clean. Decision (docs/web-client.md): path A — KNI — is the primary route for the web client; the core runs in Blazor WASM unchanged thanks to the Core/Host split. Known follow-ups: per-platform compilation of the graphics libraries against nkast.* packages, shader compatibility for Renderer2D, HTTP-served content instead of the filesystem. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using System;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Microsoft.Xna.Framework.Input;
|
|
using MrGameEng.Core;
|
|
|
|
namespace KniWebSpike
|
|
{
|
|
/// <summary>
|
|
/// Мини-хост в духе MrGameEng.Host.GameHost, но поверх KNI (BlazorGL/WebGL):
|
|
/// владеет EngineContext ядра, гонит GameClock и фазы сцены. Если этот класс
|
|
/// работает в браузере — будущий MrGameEng.Host.Web реализуем.
|
|
/// </summary>
|
|
public class KniWebSpikeGame : Game
|
|
{
|
|
public EngineContext Context { get; } = new EngineContext();
|
|
|
|
private GraphicsDeviceManager _graphics;
|
|
private SpriteBatch _spriteBatch;
|
|
private Texture2D _pixel;
|
|
|
|
public KniWebSpikeGame()
|
|
{
|
|
_graphics = new GraphicsDeviceManager(this);
|
|
Content.RootDirectory = "Content";
|
|
}
|
|
|
|
protected override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
var viewport = GraphicsDevice.Viewport;
|
|
Context.Scenes.Switch(
|
|
new SpikeScene(() => _spriteBatch, () => _pixel, viewport.Width, viewport.Height)
|
|
);
|
|
}
|
|
|
|
protected override void LoadContent()
|
|
{
|
|
_spriteBatch = new SpriteBatch(GraphicsDevice);
|
|
_pixel = new Texture2D(GraphicsDevice, 1, 1);
|
|
_pixel.SetData(new[] { Color.White });
|
|
}
|
|
|
|
protected override void Update(GameTime gameTime)
|
|
{
|
|
Context.Clock.Advance((float)gameTime.ElapsedGameTime.TotalSeconds);
|
|
Context.Scenes.Update(Context.Clock);
|
|
base.Update(gameTime);
|
|
}
|
|
|
|
protected override void Draw(GameTime gameTime)
|
|
{
|
|
GraphicsDevice.Clear(new Color(12, 16, 24));
|
|
Context.Scenes.Draw(Context.Clock);
|
|
base.Draw(gameTime);
|
|
}
|
|
}
|
|
}
|