Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emulate here #127

Open
github-actions bot opened this issue Jul 26, 2020 · 0 comments
Open

Emulate here #127

github-actions bot opened this issue Jul 26, 2020 · 0 comments
Labels

Comments

@github-actions
Copy link

Emulate here

// TODO: Emulate here

            }
        }
        // start emulation
        this.emulationCancel = new CancellationTokenSource();
        await OnEmulate(this.emulationCancel.Token);

        await base.OnAfterRenderAsync(firstRender);
    }

    private async Task OnEmulate(CancellationToken cancelToken) {
        for(this.counter = 0; !cancelToken.IsCancellationRequested; this.counter++) {
            var sw = Stopwatch.StartNew();
            // TODO: Emulate here
            // TODO: sound update

            // GCに移動されないよう固定してJSに渡す。終わったら捨てる
            var gch = System.Runtime.InteropServices.GCHandle.Alloc(frameBuffer, System.Runtime.InteropServices.GCHandleType.Pinned);
            var pinnedAddr = gch.AddrOfPinnedObject();
            var jsRuntime = JSRuntime as Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime;
            jsRuntime.InvokeUnmarshalled<IntPtr,string>("drawEmulatorCanvas", pinnedAddr);
            gch.Free();

            // Emulation info
            sw.Stop();
            var elapsedMs = sw.ElapsedMilliseconds > 0 ? sw.ElapsedMilliseconds : 1;
            this.actualFps = 1000.0f / (float)elapsedMs;
            @* Console.WriteLine($"counter:{counter} elapsed:{elapsedMs} actualFps:{actualFps}"); *@

            // FPS Control
            var idealMs = 1000.0f / this.FPS;
            if (idealMs > elapsedMs) {
                var diffMs = idealMs - elapsedMs;
                await Task.Delay((int)diffMs);
            }
        }
    }

    private void OnCanvasMouseMove(MouseEventArgs e) {
    }

ndex f6f6906..6413d56 100644
++ b/BlazeSnes/_Imports.razor

b64b396ec85fdafa65783301d3bc9543fb212c30

@github-actions github-actions bot added the todo label Jul 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants