@pkmn/engine 0.1.0-dev.a0167a9d → 0.1.0-dev.a0447192
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/build/pkg/addon/browser.d.ts +3 -0
- package/build/pkg/addon/browser.js +43 -0
- package/build/pkg/addon/browser.js.map +1 -0
- package/build/pkg/addon/node.d.ts +3 -0
- package/build/pkg/addon/node.js +96 -0
- package/build/pkg/addon/node.js.map +1 -0
- package/build/pkg/addon.d.ts +2 -0
- package/build/pkg/addon.js +29 -51
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data.d.ts +23 -1
- package/build/pkg/data.js.map +1 -1
- package/build/pkg/gen1.js +1 -1
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +22 -9
- package/build/pkg/index.js +15 -10
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +20 -1
- package/build/pkg/protocol.js +105 -103
- package/build/pkg/protocol.js.map +1 -1
- package/build/tools/debug.js +35 -68
- package/build/tools/debug.js.map +1 -1
- package/build/tools/display/debug.jsx +141 -0
- package/build/tools/display/debug.jsx.map +1 -0
- package/build/tools/display/index.js +132 -0
- package/build/tools/display/index.js.map +1 -0
- package/build/tools/display/ui.jsx +349 -0
- package/build/tools/display/ui.jsx.map +1 -0
- package/build/tools/display/util.js +18 -0
- package/build/tools/display/util.js.map +1 -0
- package/build.zig +199 -66
- package/package.json +46 -29
- package/src/bin/install-pkmn-engine +7 -5
- package/src/bin/pkmn-debug +1 -1
- package/src/lib/common/array.zig +77 -0
- package/src/lib/common/data.zig +8 -8
- package/src/lib/common/debug.zig +39 -8
- package/src/lib/common/js.zig +4 -2
- package/src/lib/common/optional.zig +13 -9
- package/src/lib/common/options.zig +2 -0
- package/src/lib/common/protocol.zig +41 -36
- package/src/lib/common/rational.zig +53 -51
- package/src/lib/common/rng.zig +4 -4
- package/src/lib/common/util.zig +50 -1
- package/src/lib/gen1/calc.zig +508 -127
- package/src/lib/gen1/chance.zig +316 -173
- package/src/lib/gen1/data.zig +28 -27
- package/src/lib/gen1/helpers.zig +15 -450
- package/src/lib/gen1/mechanics.zig +216 -145
- package/src/lib/gen2/calc.zig +34 -16
- package/src/lib/gen2/chance.zig +90 -592
- package/src/lib/gen2/data.zig +15 -14
- package/src/lib/gen2/helpers.zig +4 -6
- package/src/lib/gen2/mechanics.zig +47 -77
- package/src/lib/pkmn.zig +7 -5
- package/src/tools/display/dom.ts +96 -0
- package/src/tools/display/ui.css +359 -0
- package/build/test/display.js +0 -400
- package/build/test/display.js.map +0 -1
- package/src/test/display/pkmn.html.tmpl +0 -368
package/build.zig
CHANGED
|
@@ -1,10 +1,45 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const builtin = @import("builtin");
|
|
3
3
|
|
|
4
|
+
pub const Options = struct {
|
|
5
|
+
showdown: ?bool = null,
|
|
6
|
+
log: ?bool = null,
|
|
7
|
+
chance: ?bool = null,
|
|
8
|
+
calc: ?bool = null,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const Step = if (@hasDecl(std.Build, "Step")) std.Build.Step else .{
|
|
12
|
+
.Compile = std.Build.CompileStep,
|
|
13
|
+
.Options = std.Build.OptionsStep,
|
|
14
|
+
.Run = std.Build.RunStep,
|
|
15
|
+
};
|
|
16
|
+
const has_path = @hasField(std.Build.LazyPath, "path");
|
|
17
|
+
const root_module = @hasField(Step.Compile, "root_module");
|
|
18
|
+
const force_pic = !@hasField(std.Build.SharedLibraryOptions, "pic");
|
|
19
|
+
const ResolvedTarget =
|
|
20
|
+
if (@hasDecl(std.Build, "ResolvedTarget")) std.Build.ResolvedTarget else std.zig.CrossTarget;
|
|
21
|
+
|
|
22
|
+
pub fn module(b: *std.Build, options: Options) *std.Build.Module {
|
|
23
|
+
const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
|
|
24
|
+
const build_options = b.addOptions();
|
|
25
|
+
build_options.addOption(?bool, "showdown", options.showdown);
|
|
26
|
+
build_options.addOption(?bool, "log", options.log);
|
|
27
|
+
build_options.addOption(?bool, "chance", options.chance);
|
|
28
|
+
build_options.addOption(?bool, "calc", options.calc);
|
|
29
|
+
|
|
30
|
+
const root_source_file = .{ .cwd_relative = dirname ++ "/src/lib/pkmn.zig" };
|
|
31
|
+
const imports = &.{.{ .name = "build_options", .module = build_options.createModule() }};
|
|
32
|
+
return b.createModule(if (@hasDecl(std.Build, "CreateModuleOptions"))
|
|
33
|
+
.{ .source_file = root_source_file, .dependencies = imports }
|
|
34
|
+
else
|
|
35
|
+
.{ .root_source_file = root_source_file, .imports = imports });
|
|
36
|
+
}
|
|
37
|
+
|
|
4
38
|
pub fn build(b: *std.Build) !void {
|
|
5
39
|
const target = b.standardTargetOptions(.{});
|
|
6
40
|
const optimize = b.standardOptimizeOption(.{});
|
|
7
41
|
|
|
42
|
+
const default: ?bool = if (force_pic) false else null;
|
|
8
43
|
const node_headers = b.option([]const u8, "node-headers", "Path to node-headers");
|
|
9
44
|
const node_import_lib =
|
|
10
45
|
b.option([]const u8, "node-import-library", "Path to node import library (Windows)");
|
|
@@ -12,8 +47,8 @@ pub fn build(b: *std.Build) !void {
|
|
|
12
47
|
const wasm_stack_size =
|
|
13
48
|
b.option(u64, "wasm-stack-size", "The size of WASM stack") orelse std.wasm.page_size;
|
|
14
49
|
const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
|
|
15
|
-
const strip = b.option(bool, "strip", "Strip debugging symbols from binary");
|
|
16
|
-
const pic = b.option(bool, "pic", "Force position independent code");
|
|
50
|
+
const strip = b.option(bool, "strip", "Strip debugging symbols from binary") orelse default;
|
|
51
|
+
const pic = b.option(bool, "pic", "Force position independent code") orelse default;
|
|
17
52
|
const emit_asm = b.option(bool, "emit-asm", "Output .s (assembly code)") orelse false;
|
|
18
53
|
const emit_ll = b.option(bool, "emit-ll", "Output .ll (LLVM IR)") orelse false;
|
|
19
54
|
|
|
@@ -27,6 +62,12 @@ pub fn build(b: *std.Build) !void {
|
|
|
27
62
|
var repository = std.mem.splitSequence(u8, parsed.value.object.get("repository").?.string, ":");
|
|
28
63
|
std.debug.assert(std.mem.eql(u8, repository.first(), "github"));
|
|
29
64
|
|
|
65
|
+
const fast = try std.SemanticVersion.parse("0.12.0-dev.866+3a47bc715");
|
|
66
|
+
if (optimize != .Debug and fast.order(builtin.zig_version) == .lt) {
|
|
67
|
+
std.log.warn("Release builds are ~10-20% slower than before Zig " ++
|
|
68
|
+
"v0.12.0-dev.866+3a47bc715 due to ziglang/zig#17768", .{});
|
|
69
|
+
}
|
|
70
|
+
|
|
30
71
|
const showdown =
|
|
31
72
|
b.option(bool, "showdown", "Enable Pokémon Showdown compatibility mode") orelse false;
|
|
32
73
|
const log = b.option(bool, "log", "Enable protocol message logging") orelse false;
|
|
@@ -41,8 +82,11 @@ pub fn build(b: *std.Build) !void {
|
|
|
41
82
|
|
|
42
83
|
const name = if (showdown) "pkmn-showdown" else "pkmn";
|
|
43
84
|
|
|
44
|
-
const
|
|
45
|
-
.root_source_file =
|
|
85
|
+
const pkmn = if (@hasDecl(std.Build, "CreateModuleOptions")) null else b.addModule("pkmn", .{
|
|
86
|
+
.root_source_file = if (has_path)
|
|
87
|
+
.{ .path = "src/lib/pkmn.zig" }
|
|
88
|
+
else
|
|
89
|
+
b.path("src/lib/pkmn.zig"),
|
|
46
90
|
.optimize = optimize,
|
|
47
91
|
.target = target,
|
|
48
92
|
.imports = &.{.{ .name = "build_options", .module = options.createModule() }},
|
|
@@ -51,25 +95,32 @@ pub fn build(b: *std.Build) !void {
|
|
|
51
95
|
var c = false;
|
|
52
96
|
if (node_headers) |headers| {
|
|
53
97
|
const addon = b.fmt("{s}.node", .{name});
|
|
54
|
-
const
|
|
98
|
+
const path = if (has_path) .{ .path = "src/lib/node.zig" } else b.path("src/lib/node.zig");
|
|
99
|
+
const lib = b.addSharedLibrary(if (force_pic) .{
|
|
100
|
+
.name = addon,
|
|
101
|
+
.root_source_file = path,
|
|
102
|
+
.optimize = optimize,
|
|
103
|
+
.target = target,
|
|
104
|
+
} else .{
|
|
55
105
|
.name = addon,
|
|
56
|
-
.root_source_file =
|
|
106
|
+
.root_source_file = path,
|
|
57
107
|
.optimize = optimize,
|
|
58
108
|
.target = target,
|
|
59
109
|
.strip = strip,
|
|
60
110
|
.pic = pic,
|
|
61
111
|
});
|
|
62
|
-
lib.root_module.addOptions("build_options", options);
|
|
63
|
-
lib.addSystemIncludePath(b.path(headers));
|
|
112
|
+
(if (root_module) lib.root_module else lib).addOptions("build_options", options);
|
|
113
|
+
lib.addSystemIncludePath(if (has_path) .{ .path = headers } else b.path(headers));
|
|
64
114
|
lib.linkLibC();
|
|
65
115
|
if (node_import_lib) |il| {
|
|
66
|
-
lib.addObjectFile(b.path(il));
|
|
67
|
-
} else if (target.
|
|
116
|
+
lib.addObjectFile(if (has_path) .{ .path = il } else b.path(il));
|
|
117
|
+
} else if (detect(target).os.tag == .windows) {
|
|
68
118
|
try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
|
|
69
119
|
std.process.exit(1);
|
|
70
120
|
}
|
|
71
121
|
lib.linker_allow_shlib_undefined = true;
|
|
72
122
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
123
|
+
if (force_pic and pic orelse false) lib.force_pic = pic;
|
|
73
124
|
// Always emit to build/lib because this is where the driver code expects to find it
|
|
74
125
|
// TODO: ziglang/zig#2231 - using the following used to work (though was hacky):
|
|
75
126
|
//
|
|
@@ -80,69 +131,116 @@ pub fn build(b: *std.Build) !void {
|
|
|
80
131
|
// rename the file ourself in install-pkmn-engine
|
|
81
132
|
b.installArtifact(lib);
|
|
82
133
|
} else if (wasm) {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
134
|
+
const entry = @hasDecl(Step.Compile, "Entry");
|
|
135
|
+
const mode = switch (optimize) {
|
|
136
|
+
.ReleaseFast, .ReleaseSafe => .ReleaseSmall,
|
|
137
|
+
else => optimize,
|
|
138
|
+
};
|
|
139
|
+
const freestanding = if (@hasDecl(std.Build, "resolveTargetQuery"))
|
|
140
|
+
b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding })
|
|
141
|
+
else
|
|
142
|
+
ResolvedTarget{ .cpu_arch = .wasm32, .os_tag = .freestanding };
|
|
143
|
+
const path = if (has_path) .{ .path = "src/lib/wasm.zig" } else b.path("src/lib/wasm.zig");
|
|
144
|
+
const bin = if (entry) bin: {
|
|
145
|
+
const exe = b.addExecutable(if (force_pic) .{
|
|
146
|
+
.name = name,
|
|
147
|
+
.root_source_file = path,
|
|
148
|
+
.optimize = mode,
|
|
149
|
+
.target = freestanding,
|
|
150
|
+
} else .{
|
|
151
|
+
.name = name,
|
|
152
|
+
.root_source_file = path,
|
|
153
|
+
.optimize = mode,
|
|
154
|
+
.target = freestanding,
|
|
155
|
+
.strip = strip,
|
|
156
|
+
.pic = pic,
|
|
157
|
+
});
|
|
158
|
+
(if (root_module) exe.root_module else exe).export_symbol_names = &[_][]const u8{
|
|
159
|
+
"SHOWDOWN",
|
|
160
|
+
"LOG",
|
|
161
|
+
"CHANCE",
|
|
162
|
+
"CALC",
|
|
163
|
+
"GEN1_CHOICES_SIZE",
|
|
164
|
+
"GEN1_LOGS_SIZE",
|
|
165
|
+
};
|
|
166
|
+
exe.entry = .disabled;
|
|
167
|
+
break :bin exe;
|
|
168
|
+
} else bin: {
|
|
169
|
+
const lib = b.addSharedLibrary(.{
|
|
170
|
+
.name = name,
|
|
171
|
+
.root_source_file = path,
|
|
172
|
+
.optimize = mode,
|
|
173
|
+
.target = freestanding,
|
|
174
|
+
});
|
|
175
|
+
lib.rdynamic = true;
|
|
176
|
+
break :bin lib;
|
|
102
177
|
};
|
|
103
|
-
|
|
104
|
-
|
|
178
|
+
bin.stack_size = wasm_stack_size;
|
|
179
|
+
if (@hasDecl(@TypeOf(bin.*), "strip")) bin.strip = strip orelse false;
|
|
180
|
+
if (force_pic and pic orelse false) bin.force_pic = pic;
|
|
181
|
+
(if (root_module) bin.root_module else bin).addOptions("build_options", options);
|
|
182
|
+
|
|
105
183
|
const opt = b.findProgram(&.{"wasm-opt"}, &.{"./node_modules/.bin"}) catch null;
|
|
106
184
|
if (optimize != .Debug and opt != null) {
|
|
107
185
|
const out = b.fmt("build/lib/{s}.wasm", .{name});
|
|
108
186
|
const sh = b.addSystemCommand(&.{ opt.?, "-O4" });
|
|
109
|
-
sh.addArtifactArg(
|
|
187
|
+
sh.addArtifactArg(bin);
|
|
110
188
|
sh.addArg("-o");
|
|
111
|
-
|
|
189
|
+
if (@hasDecl(@TypeOf(sh.*), "addFileSourceArg")) {
|
|
190
|
+
sh.addFileSourceArg(if (has_path) .{ .path = out } else b.path(out));
|
|
191
|
+
} else {
|
|
192
|
+
sh.addFileArg(if (has_path) .{ .path = out } else b.path(out));
|
|
193
|
+
}
|
|
112
194
|
b.getInstallStep().dependOn(&sh.step);
|
|
113
|
-
|
|
114
|
-
|
|
195
|
+
if (!entry) b.installArtifact(bin);
|
|
196
|
+
} else if (entry) {
|
|
197
|
+
b.getInstallStep().dependOn(&b.addInstallArtifact(bin, .{
|
|
115
198
|
.dest_dir = .{ .override = std.Build.InstallDir{ .lib = {} } },
|
|
116
199
|
}).step);
|
|
117
200
|
}
|
|
118
201
|
} else if (dynamic) {
|
|
119
|
-
const
|
|
202
|
+
const path = if (has_path) .{ .path = "src/lib/c.zig" } else b.path("src/lib/c.zig");
|
|
203
|
+
const lib = b.addSharedLibrary(if (force_pic) .{
|
|
204
|
+
.name = name,
|
|
205
|
+
.root_source_file = path,
|
|
206
|
+
.version = try std.SemanticVersion.parse(version),
|
|
207
|
+
.optimize = optimize,
|
|
208
|
+
.target = target,
|
|
209
|
+
} else .{
|
|
120
210
|
.name = name,
|
|
121
|
-
.root_source_file =
|
|
211
|
+
.root_source_file = path,
|
|
122
212
|
.version = try std.SemanticVersion.parse(version),
|
|
123
213
|
.optimize = optimize,
|
|
124
214
|
.target = target,
|
|
125
215
|
.strip = strip,
|
|
126
216
|
.pic = pic,
|
|
127
217
|
});
|
|
128
|
-
lib.root_module.addOptions("build_options", options);
|
|
129
|
-
lib.addIncludePath(b.path("src/include"));
|
|
218
|
+
(if (root_module) lib.root_module else lib).addOptions("build_options", options);
|
|
219
|
+
lib.addIncludePath(if (has_path) .{ .path = "src/include" } else b.path("src/include"));
|
|
130
220
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
221
|
+
if (force_pic and pic orelse false) lib.force_pic = pic;
|
|
131
222
|
b.installArtifact(lib);
|
|
132
223
|
c = true;
|
|
133
224
|
} else {
|
|
134
|
-
const
|
|
225
|
+
const path = if (has_path) .{ .path = "src/lib/c.zig" } else b.path("src/lib/c.zig");
|
|
226
|
+
const lib = b.addStaticLibrary(if (force_pic) .{
|
|
135
227
|
.name = name,
|
|
136
|
-
.root_source_file =
|
|
228
|
+
.root_source_file = path,
|
|
229
|
+
.optimize = optimize,
|
|
230
|
+
.target = target,
|
|
231
|
+
} else .{
|
|
232
|
+
.name = name,
|
|
233
|
+
.root_source_file = path,
|
|
137
234
|
.optimize = optimize,
|
|
138
235
|
.target = target,
|
|
139
236
|
.strip = strip,
|
|
140
237
|
.pic = pic,
|
|
141
238
|
});
|
|
142
|
-
lib.root_module.addOptions("build_options", options);
|
|
143
|
-
lib.addIncludePath(b.path("src/include"));
|
|
239
|
+
(if (root_module) lib.root_module else lib).addOptions("build_options", options);
|
|
240
|
+
lib.addIncludePath(if (has_path) .{ .path = "src/include" } else b.path("src/include"));
|
|
144
241
|
lib.bundle_compiler_rt = true;
|
|
145
242
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
243
|
+
if (force_pic and pic orelse false) lib.force_pic = pic;
|
|
146
244
|
if (emit_asm) {
|
|
147
245
|
b.getInstallStep().dependOn(&b.addInstallFileWithDir(
|
|
148
246
|
lib.getEmittedAsm(),
|
|
@@ -162,11 +260,9 @@ pub fn build(b: *std.Build) !void {
|
|
|
162
260
|
}
|
|
163
261
|
|
|
164
262
|
if (c) {
|
|
165
|
-
const
|
|
166
|
-
b.path("src/include/pkmn.h")
|
|
167
|
-
|
|
168
|
-
"pkmn.h",
|
|
169
|
-
);
|
|
263
|
+
const path =
|
|
264
|
+
if (has_path) .{ .path = "src/include/pkmn.h" } else b.path("src/include/pkmn.h");
|
|
265
|
+
const header = b.addInstallFileWithDir(path, .header, "pkmn.h");
|
|
170
266
|
b.getInstallStep().dependOn(&header.step);
|
|
171
267
|
|
|
172
268
|
const pc = b.fmt("lib{s}.pc", .{name});
|
|
@@ -207,10 +303,15 @@ pub fn build(b: *std.Build) !void {
|
|
|
207
303
|
// TODO: tests can be run multiple times due to @imports
|
|
208
304
|
const tests = TestStep.create(b, options, config);
|
|
209
305
|
|
|
210
|
-
var exes = std.ArrayList(*
|
|
306
|
+
var exes = std.ArrayList(*Step.Compile).init(b.allocator);
|
|
211
307
|
const tools: ToolConfig = .{
|
|
212
|
-
.
|
|
213
|
-
|
|
308
|
+
.options = .{
|
|
309
|
+
.showdown = showdown,
|
|
310
|
+
.log = log,
|
|
311
|
+
.chance = chance,
|
|
312
|
+
.calc = calc,
|
|
313
|
+
},
|
|
314
|
+
.module = pkmn,
|
|
214
315
|
.general = config,
|
|
215
316
|
.tool = .{
|
|
216
317
|
.tests = if (tests.build) tests else null,
|
|
@@ -251,11 +352,12 @@ pub fn build(b: *std.Build) !void {
|
|
|
251
352
|
|
|
252
353
|
fn maybeStrip(
|
|
253
354
|
b: *std.Build,
|
|
254
|
-
artifact: *
|
|
355
|
+
artifact: *Step.Compile,
|
|
255
356
|
step: *std.Build.Step,
|
|
256
357
|
strip: ?bool,
|
|
257
358
|
cmd: ?[]const u8,
|
|
258
359
|
) void {
|
|
360
|
+
if (@hasDecl(@TypeOf(artifact.*), "strip")) artifact.strip = strip orelse false;
|
|
259
361
|
if (!(strip orelse false) or cmd == null) return;
|
|
260
362
|
// Using `strip -r -u` for dynamic libraries is supposed to work on macOS but doesn't...
|
|
261
363
|
const mac = builtin.os.tag == .macos;
|
|
@@ -268,7 +370,7 @@ fn maybeStrip(
|
|
|
268
370
|
}
|
|
269
371
|
|
|
270
372
|
const Config = struct {
|
|
271
|
-
target:
|
|
373
|
+
target: ResolvedTarget,
|
|
272
374
|
optimize: std.builtin.OptimizeMode,
|
|
273
375
|
pic: ?bool,
|
|
274
376
|
strip: ?bool,
|
|
@@ -279,7 +381,7 @@ const TestStep = struct {
|
|
|
279
381
|
step: std.Build.Step,
|
|
280
382
|
build: bool,
|
|
281
383
|
|
|
282
|
-
pub fn create(b: *std.Build, options: *
|
|
384
|
+
pub fn create(b: *std.Build, options: *Step.Options, config: Config) *TestStep {
|
|
283
385
|
const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
|
|
284
386
|
const test_filter =
|
|
285
387
|
b.option([]const u8, "test-filter", "Skip tests that do not match filter");
|
|
@@ -288,8 +390,14 @@ const TestStep = struct {
|
|
|
288
390
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
|
|
289
391
|
self.* = .{ .step = step, .build = test_filter == null };
|
|
290
392
|
|
|
291
|
-
const
|
|
292
|
-
|
|
393
|
+
const path = if (has_path) .{ .path = "src/lib/test.zig" } else b.path("src/lib/test.zig");
|
|
394
|
+
const tests = b.addTest(if (force_pic) .{
|
|
395
|
+
.root_source_file = path,
|
|
396
|
+
.optimize = config.optimize,
|
|
397
|
+
.target = config.target,
|
|
398
|
+
.filter = test_filter,
|
|
399
|
+
} else .{
|
|
400
|
+
.root_source_file = path,
|
|
293
401
|
.optimize = config.optimize,
|
|
294
402
|
.target = config.target,
|
|
295
403
|
.filter = test_filter,
|
|
@@ -297,8 +405,13 @@ const TestStep = struct {
|
|
|
297
405
|
.strip = config.strip,
|
|
298
406
|
.pic = config.pic,
|
|
299
407
|
});
|
|
300
|
-
tests.root_module.addOptions("build_options", options);
|
|
408
|
+
(if (root_module) tests.root_module else tests).addOptions("build_options", options);
|
|
409
|
+
|
|
301
410
|
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
411
|
+
if (force_pic) {
|
|
412
|
+
tests.single_threaded = true;
|
|
413
|
+
if (config.pic orelse false) tests.force_pic = config.pic;
|
|
414
|
+
}
|
|
302
415
|
if (coverage) |c| {
|
|
303
416
|
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
304
417
|
}
|
|
@@ -309,17 +422,17 @@ const TestStep = struct {
|
|
|
309
422
|
};
|
|
310
423
|
|
|
311
424
|
const ToolConfig = struct {
|
|
312
|
-
|
|
313
|
-
module:
|
|
425
|
+
options: Options,
|
|
426
|
+
module: ?*std.Build.Module,
|
|
314
427
|
general: Config,
|
|
315
428
|
tool: struct {
|
|
316
429
|
tests: ?*TestStep,
|
|
317
430
|
name: ?[]const u8 = null,
|
|
318
|
-
exes: *std.ArrayList(*
|
|
431
|
+
exes: *std.ArrayList(*Step.Compile),
|
|
319
432
|
},
|
|
320
433
|
};
|
|
321
434
|
|
|
322
|
-
fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*
|
|
435
|
+
fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*Step.Run {
|
|
323
436
|
std.fs.cwd().access(path, .{}) catch |err| switch (err) {
|
|
324
437
|
error.FileNotFound => return null,
|
|
325
438
|
else => |e| return e,
|
|
@@ -327,19 +440,34 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.Step.R
|
|
|
327
440
|
var name = config.tool.name orelse std.fs.path.basename(path);
|
|
328
441
|
const index = std.mem.lastIndexOfScalar(u8, name, '.');
|
|
329
442
|
if (index) |i| name = name[0..i];
|
|
330
|
-
if (config.showdown orelse false) name = b.fmt("{s}-showdown", .{name});
|
|
443
|
+
if (config.options.showdown orelse false) name = b.fmt("{s}-showdown", .{name});
|
|
331
444
|
|
|
332
|
-
const exe = b.addExecutable(.{
|
|
445
|
+
const exe = b.addExecutable(if (force_pic) .{
|
|
333
446
|
.name = name,
|
|
334
|
-
.root_source_file = b.path(path),
|
|
447
|
+
.root_source_file = if (has_path) .{ .path = path } else b.path(path),
|
|
448
|
+
.target = config.general.target,
|
|
449
|
+
.optimize = config.general.optimize,
|
|
450
|
+
} else .{
|
|
451
|
+
.name = name,
|
|
452
|
+
.root_source_file = if (has_path) .{ .path = path } else b.path(path),
|
|
335
453
|
.target = config.general.target,
|
|
336
454
|
.optimize = config.general.optimize,
|
|
337
455
|
.single_threaded = true,
|
|
338
456
|
.strip = config.general.strip,
|
|
339
457
|
.pic = config.general.pic,
|
|
340
458
|
});
|
|
341
|
-
exe.root_module.addImport("pkmn", config.module);
|
|
342
459
|
|
|
460
|
+
if (root_module) {
|
|
461
|
+
const import = if (config.module) |m| m else module(b, config.options);
|
|
462
|
+
exe.root_module.addImport("pkmn", import);
|
|
463
|
+
} else {
|
|
464
|
+
exe.addModule("pkmn", module(b, config.options));
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (force_pic) {
|
|
468
|
+
exe.single_threaded = true;
|
|
469
|
+
if (config.general.pic orelse false) exe.force_pic = config.general.pic;
|
|
470
|
+
}
|
|
343
471
|
if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
|
|
344
472
|
config.tool.exes.append(exe) catch @panic("OOM");
|
|
345
473
|
|
|
@@ -353,7 +481,7 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.Step.R
|
|
|
353
481
|
const ToolsStep = struct {
|
|
354
482
|
step: std.Build.Step,
|
|
355
483
|
|
|
356
|
-
pub fn create(b: *std.Build, exes: *std.ArrayList(*
|
|
484
|
+
pub fn create(b: *std.Build, exes: *std.ArrayList(*Step.Compile)) *ToolsStep {
|
|
357
485
|
const self = b.allocator.create(ToolsStep) catch @panic("OOM");
|
|
358
486
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Install tools", .owner = b });
|
|
359
487
|
self.* = .{ .step = step };
|
|
@@ -361,3 +489,8 @@ const ToolsStep = struct {
|
|
|
361
489
|
return self;
|
|
362
490
|
}
|
|
363
491
|
};
|
|
492
|
+
|
|
493
|
+
fn detect(target: anytype) std.Target {
|
|
494
|
+
if (@hasField(@TypeOf(target), "result")) return target.result;
|
|
495
|
+
return (std.zig.system.NativeTargetInfo.detect(target) catch unreachable).target;
|
|
496
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pkmn/engine",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.a0447192",
|
|
4
4
|
"description": "A minimal, complete, Pokémon battle simulation engine optimized for performance",
|
|
5
5
|
"repository": "github:pkmn/engine",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"main": "build/pkg/index.js",
|
|
9
9
|
"types": "build/pkg/index.d.ts",
|
|
10
|
+
"browser": {
|
|
11
|
+
"./build/pkg/addon/node.js": "./build/pkg/addon/browser.js"
|
|
12
|
+
},
|
|
10
13
|
"files": [
|
|
11
14
|
"build.zig",
|
|
12
|
-
"build/pkg/data.d.ts",
|
|
13
|
-
"build/pkg/data.js.map",
|
|
14
15
|
"build/pkg/addon.d.ts",
|
|
15
16
|
"build/pkg/addon.js.map",
|
|
16
17
|
"build/pkg/addon.js",
|
|
18
|
+
"build/pkg/addon/browser.d.ts",
|
|
19
|
+
"build/pkg/addon/browser.js.map",
|
|
20
|
+
"build/pkg/addon/browser.js",
|
|
21
|
+
"build/pkg/addon/node.d.ts",
|
|
22
|
+
"build/pkg/addon/node.js.map",
|
|
23
|
+
"build/pkg/addon/node.js",
|
|
24
|
+
"build/pkg/data.d.ts",
|
|
25
|
+
"build/pkg/data.js.map",
|
|
17
26
|
"build/pkg/data.js",
|
|
18
27
|
"build/pkg/data/ids.json",
|
|
19
28
|
"build/pkg/data/layout.json",
|
|
@@ -27,10 +36,17 @@
|
|
|
27
36
|
"build/pkg/protocol.d.ts",
|
|
28
37
|
"build/pkg/protocol.js.map",
|
|
29
38
|
"build/pkg/protocol.js",
|
|
30
|
-
"build/test/display.js.map",
|
|
31
|
-
"build/test/display.js",
|
|
32
39
|
"build/tools/debug.js.map",
|
|
33
40
|
"build/tools/debug.js",
|
|
41
|
+
"build/tools/display/index.js.map",
|
|
42
|
+
"build/tools/display/index.js",
|
|
43
|
+
"build/tools/display/debug.jsx.map",
|
|
44
|
+
"build/tools/display/debug.jsx",
|
|
45
|
+
"build/tools/display/ui.jsx.map",
|
|
46
|
+
"build/tools/display/ui.jsx",
|
|
47
|
+
"build/tools/display/util.js.map",
|
|
48
|
+
"build/tools/display/util.js",
|
|
49
|
+
"src/lib/common/array.zig",
|
|
34
50
|
"src/lib/common/battle.zig",
|
|
35
51
|
"src/lib/common/data.zig",
|
|
36
52
|
"src/lib/common/debug.zig",
|
|
@@ -62,7 +78,8 @@
|
|
|
62
78
|
"src/lib/node.zig",
|
|
63
79
|
"src/lib/pkmn.zig",
|
|
64
80
|
"src/lib/wasm.zig",
|
|
65
|
-
"src/
|
|
81
|
+
"src/tools/display/dom.ts",
|
|
82
|
+
"src/tools/display/ui.css"
|
|
66
83
|
],
|
|
67
84
|
"engines": {
|
|
68
85
|
"node": ">=16.0.0"
|
|
@@ -75,31 +92,37 @@
|
|
|
75
92
|
"access": "public"
|
|
76
93
|
},
|
|
77
94
|
"dependencies": {
|
|
78
|
-
"@pkmn/data": "^0.9.
|
|
79
|
-
"@pkmn/protocol": "^0.6.
|
|
95
|
+
"@pkmn/data": "^0.9.17",
|
|
96
|
+
"@pkmn/protocol": "^0.6.26"
|
|
80
97
|
},
|
|
81
98
|
"devDependencies": {
|
|
82
|
-
"@pkmn/eslint-config": "^8.
|
|
83
|
-
"@pkmn/img": "^0.2.
|
|
99
|
+
"@pkmn/eslint-config": "^8.3.0",
|
|
100
|
+
"@pkmn/img": "^0.2.32",
|
|
84
101
|
"@pkmn/sets": "^5.1.2",
|
|
85
|
-
"@pkmn/sim": "0.9.
|
|
102
|
+
"@pkmn/sim": "0.9.17",
|
|
86
103
|
"@types/html-minifier": "^4.0.5",
|
|
87
|
-
"@types/jest": "^29.5.
|
|
104
|
+
"@types/jest": "^29.5.13",
|
|
88
105
|
"@types/minimist": "^1.2.5",
|
|
89
106
|
"@types/mustache": "^4.2.5",
|
|
90
|
-
"@types/node": "^22.
|
|
91
|
-
"@
|
|
92
|
-
"
|
|
107
|
+
"@types/node": "^22.5.5",
|
|
108
|
+
"@types/react": "^18.3.8",
|
|
109
|
+
"@types/semver": "^7.5.8",
|
|
110
|
+
"@types/vscode": "^1.93.0",
|
|
111
|
+
"@vitest/coverage-v8": "^2.1.1",
|
|
112
|
+
"@vscode/vsce": "^3.1.0",
|
|
113
|
+
"binaryen": "^119.0.0",
|
|
114
|
+
"esbuild": "^0.23.1",
|
|
93
115
|
"eslint": "<=8",
|
|
94
116
|
"html-minifier": "^4.0.0",
|
|
95
|
-
"json-stringify-pretty-compact": "
|
|
117
|
+
"json-stringify-pretty-compact": "3.0.0",
|
|
96
118
|
"minimist": "^1.2.8",
|
|
97
119
|
"mustache": "^4.2.0",
|
|
120
|
+
"semver": "^7.6.3",
|
|
98
121
|
"source-map-support": "^0.5.21",
|
|
99
122
|
"table": "^6.8.2",
|
|
100
123
|
"trakr": "^0.2.0",
|
|
101
|
-
"typescript": "^5.
|
|
102
|
-
"vitest": "^2.
|
|
124
|
+
"typescript": "^5.6.2",
|
|
125
|
+
"vitest": "^2.1.1"
|
|
103
126
|
},
|
|
104
127
|
"scripts": {
|
|
105
128
|
"lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
|
|
@@ -109,11 +132,13 @@
|
|
|
109
132
|
"test": "vitest src/pkg",
|
|
110
133
|
"test:integration": "vitest src/test",
|
|
111
134
|
"debug": "npm run compile && node build/tools/debug",
|
|
135
|
+
"demo": "npm run compile && node build/tools/demo",
|
|
112
136
|
"fuzz": "npm run compile && node build/test/fuzz",
|
|
113
137
|
"generate": "npm run compile && node build/tools/generate",
|
|
114
138
|
"release": "npm run compile && node build/tools/release",
|
|
115
139
|
"benchmark": "npm run compile && node build/test/benchmark",
|
|
116
140
|
"integration": "npm run compile && node build/test/integration",
|
|
141
|
+
"extension": "npm -C src/tools/vscode run build",
|
|
117
142
|
"postinstall": "node src/bin/install-pkmn-engine"
|
|
118
143
|
},
|
|
119
144
|
"eslintConfig": {
|
|
@@ -122,7 +147,8 @@
|
|
|
122
147
|
"dist/",
|
|
123
148
|
"node_modules/",
|
|
124
149
|
"examples/zig",
|
|
125
|
-
"build/"
|
|
150
|
+
"build/",
|
|
151
|
+
"extension.js"
|
|
126
152
|
],
|
|
127
153
|
"env": {
|
|
128
154
|
"es6": true,
|
|
@@ -141,18 +167,9 @@
|
|
|
141
167
|
]
|
|
142
168
|
}
|
|
143
169
|
},
|
|
144
|
-
{
|
|
145
|
-
"files": [
|
|
146
|
-
"src/test/display.ts"
|
|
147
|
-
],
|
|
148
|
-
"rules": {
|
|
149
|
-
"@typescript-eslint/no-unnecessary-type-assertion": "off"
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
170
|
{
|
|
153
171
|
"files": [
|
|
154
172
|
"src/pkg/index.ts",
|
|
155
|
-
"src/test/display.ts",
|
|
156
173
|
"src/test/integration.ts"
|
|
157
174
|
],
|
|
158
175
|
"rules": {
|
|
@@ -164,7 +181,7 @@
|
|
|
164
181
|
},
|
|
165
182
|
{
|
|
166
183
|
"files": [
|
|
167
|
-
"src/pkg/addon.ts"
|
|
184
|
+
"src/pkg/addon/node.ts"
|
|
168
185
|
],
|
|
169
186
|
"rules": {
|
|
170
187
|
"@typescript-eslint/no-var-requires": "off"
|
|
@@ -10,7 +10,7 @@ const path = require('path');
|
|
|
10
10
|
const {pipeline} = require('stream/promises');
|
|
11
11
|
const tty = require('tty');
|
|
12
12
|
|
|
13
|
-
const ZIG_VERSION = {major: 0, minor:
|
|
13
|
+
const ZIG_VERSION = {major: 0, minor: 11, patch: 0};
|
|
14
14
|
const DEV = ZIG_VERSION.dev ? `-dev.${ZIG_VERSION.dev}` : '';
|
|
15
15
|
const VERSION = `${ZIG_VERSION.major}.${ZIG_VERSION.minor}.${ZIG_VERSION.patch}${DEV}`;
|
|
16
16
|
const INDEX = 'https://ziglang.org/download/index.json';
|
|
@@ -163,8 +163,10 @@ const install = async () => {
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
const index = JSON.parse(await fetch(INDEX));
|
|
166
|
-
|
|
167
|
-
const
|
|
166
|
+
// TODO: ziglang/zig#17768
|
|
167
|
+
// const version = Object.keys(index)[+!ZIG_VERSION.dev];
|
|
168
|
+
const version = VERSION;
|
|
169
|
+
const release = index[VERSION][`${arch}-${platform}`];
|
|
168
170
|
const url = release.tarball;
|
|
169
171
|
|
|
170
172
|
let base = path.basename(url);
|
|
@@ -389,11 +391,11 @@ const downloadImportLib = async () => {
|
|
|
389
391
|
const ext = process.platform === 'darwin'
|
|
390
392
|
? 'dylib' : process.platform === 'win32' ? 'dll' : 'so';
|
|
391
393
|
try {
|
|
392
|
-
const actual = path.join('build', 'lib', `${prefix}pkmn${suffix}.node.${ext}`);
|
|
394
|
+
const actual = path.join(ROOT, 'build', 'lib', `${prefix}pkmn${suffix}.node.${ext}`);
|
|
393
395
|
fs.renameSync(actual, artifact);
|
|
394
396
|
} catch (err) {
|
|
395
397
|
// ziglang/zig#19743 changed this path
|
|
396
|
-
const actual = path.join('build', 'bin', `${prefix}pkmn${suffix}.node.${ext}`);
|
|
398
|
+
const actual = path.join(ROOT, 'build', 'bin', `${prefix}pkmn${suffix}.node.${ext}`);
|
|
397
399
|
fs.renameSync(actual, artifact);
|
|
398
400
|
}
|
|
399
401
|
}
|
package/src/bin/pkmn-debug
CHANGED
|
@@ -15,7 +15,7 @@ const ROOT = resolve(__dirname, '..', '..');
|
|
|
15
15
|
const packageJSON = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
|
16
16
|
|
|
17
17
|
const missing = [];
|
|
18
|
-
for (const dep of ['@pkmn/img', 'html-minifier', '
|
|
18
|
+
for (const dep of ['@pkmn/img', 'html-minifier', 'esbuild']) {
|
|
19
19
|
try {
|
|
20
20
|
require.resolve(dep);
|
|
21
21
|
} catch (e) {
|