using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text.Json; using System.Threading.Tasks; using Godot; using Age.Engine.Diagnostics; using Age.Engine.Hosting; using Age.Engine.Model; using Age.Engine.Persistence; using Age.Engine.Sys4; using Age.Engine.Text; #if AGE_WINDOWS_GDI using Age.Engine.Text.Windows; #endif using Age.Engine.Vm; using Script = Age.Engine.Model.Script; // disambiguate from Godot.Script public partial class Main : Godot.Control { // Provisional approximation only: AGE asks GDI to synthesize LOGFONT weight 700, grid-fit a // GGO_GRAY4 mask, and composites that mask itself. Godot instead applies FreeType embolden plus // spacing. Do not retune these values from screenshots; replace this approximation from the decoded // native glyph-mask contract. See docs/engine-re.md. private const float NativeBoldEmbolden = 0.53f; private const int NativeBoldGlyphSpacing = 1; private int _screenWidth = Sys4LogicalCanvas.DefaultWidth; private int _screenHeight = Sys4LogicalCanvas.DefaultHeight; private WindowLaunchOptions _windowOptions; private Sys4AssetCatalog _catalog = null!; private IAssetStore _assetStore = null!; private TextureRect _screenView = null!; // shows the composited screen backbuffer private Image _screen = null!; // SYS4INI-sized immediate-mode canvas private ImageTexture _screenTex = null!; private GpuRetainedRenderer _gpuRenderer = null!; private bool _useGpuBackend = true; private ImageTexture? _ageCursorTexture; private TextureRect _waitIndicator = null!; private ImageTexture? _waitIndicatorSheet; private AtlasTexture? _waitIndicatorAtlas; private int _waitIndicatorAssetId = -1; // One managed composition target for the entire frame. Layer helpers mutate it in place; only the // completed frame crosses the Godot Image boundary, avoiding a full GetData/SetData round-trip per layer. private byte[] _screenPixels = []; private Label _text = null!; private Label _speaker = null!; private readonly System.Collections.Generic.List