-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBlazorDoom.cs
61 lines (54 loc) · 1.8 KB
/
BlazorDoom.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Net.Http;
using System.Runtime.InteropServices.JavaScript;
using System.Runtime.Versioning;
using System.Threading.Tasks;
namespace BlazorDoom
{
// Must be named MainJS
public partial class MainJS
{
static ManagedDoom.DoomApplication? app = null;
[JSExport]
public static void GameLoop(int[] downKeys, int[] upKeys)
{
if (app == null)
{
return;
}
//var watch = System.Diagnostics.Stopwatch.StartNew();
app.Run(downKeys, upKeys);
//watch.Stop();
//Console.WriteLine($"fps {1000 / (float)(watch.ElapsedMilliseconds)}", );
}
[JSImport("getBaseUrl", "main.js")]
public static partial string getBaseUrl();
[JSExport]
public static async Task LoadWad(string wadName = "doom1")
{
Console.WriteLine("Loading assets");
string wadUrl = $"{getBaseUrl()}wad/{wadName}.wad";
string soundFontUrl = $"{getBaseUrl()}wad/TimGM6mb.sf2";
// string soundFontUrl = "http://localhost:5000/Roland_SC-55_v3.7.sf2";
string[] args = { };
string[] configLines = { };
var http = new HttpClient();
//jsProcessRuntime.InvokeVoid("gameLoop");
Console.WriteLine(wadUrl);
var stream = await http.GetStreamAsync(wadUrl);
var soundFontStream = await http.GetStreamAsync(soundFontUrl);
var commandLineArgs = new ManagedDoom.CommandLineArgs(args);
ManagedDoom.DoomApplication.SoundFontStream = soundFontStream;
app = new ManagedDoom.DoomApplication(commandLineArgs, configLines, http, stream, wadUrl);
Console.WriteLine("Ready!");
}
public static async Task Main()
{
if (!OperatingSystem.IsBrowser())
{
throw new PlatformNotSupportedException("This demo is expected to run on browser platform");
}
LoadWad();
}
}
}