@pkmn/engine 0.1.0-dev.44b2e6ec → 0.1.0-dev.46850a3d
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/LICENSE +1 -3
- package/README.md +5 -5
- package/build/pkg/addon.js +6 -7
- package/build/pkg/addon.js.map +1 -1
- package/build/pkg/data.d.ts +4 -5
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.js +4 -4
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +2 -2
- package/build/test/display.js.map +1 -1
- package/build/tools/debug.js +2 -3
- package/build/tools/debug.js.map +1 -1
- package/build.zig +57 -60
- package/package.json +29 -22
- package/src/bin/install-pkmn-engine +26 -18
- package/src/lib/common/data.zig +4 -4
- package/src/lib/common/optional.zig +1 -1
- package/src/lib/common/protocol.zig +15 -20
- package/src/lib/common/rng.zig +11 -11
- package/src/lib/gen1/chance.zig +27 -26
- package/src/lib/gen1/data/species.zig +1 -1
- package/src/lib/gen1/data.zig +18 -18
- package/src/lib/gen1/helpers.zig +7 -7
- package/src/lib/gen1/mechanics.zig +41 -5
- package/src/lib/gen2/chance.zig +38 -37
- package/src/lib/gen2/data.zig +8 -8
- package/src/lib/gen2/mechanics.zig +112 -27
- package/src/lib/{binding/node.zig → node.zig} +3 -2
- package/src/lib/pkmn.zig +26 -3
- package/src/lib/{binding/wasm.zig → wasm.zig} +2 -1
- package/src/lib/gen1/README.md +0 -894
- package/src/lib/gen2/README.md +0 -329
package/build/tools/debug.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/tools/debug.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/tools/debug.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,0BAuDC;AAED,kBAkBC;AA/GD,uCAAyB;AAE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CAAC;QACzB,CAAC;QACD,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,8DAA8D;IAC9D,GAAG,CAAC,IAAI,kBAAW,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACzD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/build.zig
CHANGED
|
@@ -16,8 +16,8 @@ pub fn module(b: *std.Build, options: Options) *std.Build.Module {
|
|
|
16
16
|
build_options.addOption(?bool, "chance", options.chance);
|
|
17
17
|
build_options.addOption(?bool, "calc", options.calc);
|
|
18
18
|
return b.createModule(.{
|
|
19
|
-
.
|
|
20
|
-
.
|
|
19
|
+
.root_source_file = .{ .cwd_relative = dirname ++ "/src/lib/pkmn.zig" },
|
|
20
|
+
.imports = &.{.{ .name = "build_options", .module = build_options.createModule() }},
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -32,8 +32,8 @@ pub fn build(b: *std.Build) !void {
|
|
|
32
32
|
const wasm_stack_size =
|
|
33
33
|
b.option(u64, "wasm-stack-size", "The size of WASM stack") orelse std.wasm.page_size;
|
|
34
34
|
const dynamic = b.option(bool, "dynamic", "Build a dynamic library") orelse false;
|
|
35
|
-
const strip = b.option(bool, "strip", "Strip debugging symbols from binary")
|
|
36
|
-
const pic = b.option(bool, "pic", "Force position independent code")
|
|
35
|
+
const strip = b.option(bool, "strip", "Strip debugging symbols from binary");
|
|
36
|
+
const pic = b.option(bool, "pic", "Force position independent code");
|
|
37
37
|
const emit_asm = b.option(bool, "emit-asm", "Output .s (assembly code)") orelse false;
|
|
38
38
|
const emit_ll = b.option(bool, "emit-ll", "Output .ll (LLVM IR)") orelse false;
|
|
39
39
|
|
|
@@ -44,7 +44,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
44
44
|
defer parsed.deinit();
|
|
45
45
|
const version = parsed.value.object.get("version").?.string;
|
|
46
46
|
const description = parsed.value.object.get("description").?.string;
|
|
47
|
-
var repository = std.mem.
|
|
47
|
+
var repository = std.mem.splitSequence(u8, parsed.value.object.get("repository").?.string, ":");
|
|
48
48
|
std.debug.assert(std.mem.eql(u8, repository.first(), "github"));
|
|
49
49
|
|
|
50
50
|
const showdown =
|
|
@@ -66,25 +66,25 @@ pub fn build(b: *std.Build) !void {
|
|
|
66
66
|
const addon = b.fmt("{s}.node", .{name});
|
|
67
67
|
const lib = b.addSharedLibrary(.{
|
|
68
68
|
.name = addon,
|
|
69
|
-
.
|
|
70
|
-
.root_source_file = .{ .path = "src/lib/binding/node.zig" },
|
|
69
|
+
.root_source_file = b.path("src/lib/node.zig"),
|
|
71
70
|
.optimize = optimize,
|
|
72
71
|
.target = target,
|
|
72
|
+
.strip = strip,
|
|
73
|
+
.pic = pic,
|
|
73
74
|
});
|
|
74
|
-
lib.addOptions("build_options", options);
|
|
75
|
-
lib.addSystemIncludePath(.
|
|
75
|
+
lib.root_module.addOptions("build_options", options);
|
|
76
|
+
lib.addSystemIncludePath(b.path(headers));
|
|
76
77
|
lib.linkLibC();
|
|
77
78
|
if (node_import_lib) |il| {
|
|
78
|
-
lib.addObjectFile(.
|
|
79
|
-
} else if (
|
|
79
|
+
lib.addObjectFile(b.path(il));
|
|
80
|
+
} else if (target.result.os.tag == .windows) {
|
|
80
81
|
try std.io.getStdErr().writeAll("Must provide --node-import-library path on Windows\n");
|
|
81
82
|
std.process.exit(1);
|
|
82
83
|
}
|
|
83
84
|
lib.linker_allow_shlib_undefined = true;
|
|
84
85
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
85
|
-
if (pic) lib.force_pic = pic;
|
|
86
86
|
// Always emit to build/lib because this is where the driver code expects to find it
|
|
87
|
-
// TODO
|
|
87
|
+
// TODO: ziglang/zig#2231 - using the following used to work (though was hacky):
|
|
88
88
|
//
|
|
89
89
|
// lib.emit_bin = .{ .emit_to = b.fmt("build/lib/{s}", .{addon}) };
|
|
90
90
|
// b.getInstallStep().dependOn(&lib.step);
|
|
@@ -95,16 +95,17 @@ pub fn build(b: *std.Build) !void {
|
|
|
95
95
|
} else if (wasm) {
|
|
96
96
|
const exe = b.addExecutable(.{
|
|
97
97
|
.name = name,
|
|
98
|
-
.
|
|
99
|
-
.root_source_file = .{ .path = "src/lib/binding/wasm.zig" },
|
|
98
|
+
.root_source_file = b.path("src/lib/wasm.zig"),
|
|
100
99
|
.optimize = switch (optimize) {
|
|
101
100
|
.ReleaseFast, .ReleaseSafe => .ReleaseSmall,
|
|
102
101
|
else => optimize,
|
|
103
102
|
},
|
|
104
|
-
.target = .{ .cpu_arch = .wasm32, .os_tag = .freestanding },
|
|
103
|
+
.target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
|
|
104
|
+
.strip = strip,
|
|
105
|
+
.pic = pic,
|
|
105
106
|
});
|
|
106
|
-
exe.addOptions("build_options", options);
|
|
107
|
-
exe.export_symbol_names = &[_][]const u8{
|
|
107
|
+
exe.root_module.addOptions("build_options", options);
|
|
108
|
+
exe.root_module.export_symbol_names = &[_][]const u8{
|
|
108
109
|
"SHOWDOWN",
|
|
109
110
|
"LOG",
|
|
110
111
|
"CHANCE",
|
|
@@ -114,15 +115,13 @@ pub fn build(b: *std.Build) !void {
|
|
|
114
115
|
};
|
|
115
116
|
exe.entry = .disabled;
|
|
116
117
|
exe.stack_size = wasm_stack_size;
|
|
117
|
-
exe.strip = strip;
|
|
118
|
-
if (pic) exe.force_pic = pic;
|
|
119
118
|
const opt = b.findProgram(&.{"wasm-opt"}, &.{"./node_modules/.bin"}) catch null;
|
|
120
119
|
if (optimize != .Debug and opt != null) {
|
|
121
120
|
const out = b.fmt("build/lib/{s}.wasm", .{name});
|
|
122
121
|
const sh = b.addSystemCommand(&.{ opt.?, "-O4" });
|
|
123
122
|
sh.addArtifactArg(exe);
|
|
124
123
|
sh.addArg("-o");
|
|
125
|
-
sh.
|
|
124
|
+
sh.addFileArg(b.path(out));
|
|
126
125
|
b.getInstallStep().dependOn(&sh.step);
|
|
127
126
|
} else {
|
|
128
127
|
b.getInstallStep().dependOn(&b.addInstallArtifact(exe, .{
|
|
@@ -132,31 +131,31 @@ pub fn build(b: *std.Build) !void {
|
|
|
132
131
|
} else if (dynamic) {
|
|
133
132
|
const lib = b.addSharedLibrary(.{
|
|
134
133
|
.name = name,
|
|
135
|
-
.
|
|
136
|
-
.root_source_file = .{ .path = "src/lib/binding/c.zig" },
|
|
134
|
+
.root_source_file = b.path("src/lib/c.zig"),
|
|
137
135
|
.version = try std.SemanticVersion.parse(version),
|
|
138
136
|
.optimize = optimize,
|
|
139
137
|
.target = target,
|
|
138
|
+
.strip = strip,
|
|
139
|
+
.pic = pic,
|
|
140
140
|
});
|
|
141
|
-
lib.addOptions("build_options", options);
|
|
142
|
-
lib.addIncludePath(.
|
|
141
|
+
lib.root_module.addOptions("build_options", options);
|
|
142
|
+
lib.addIncludePath(b.path("src/include"));
|
|
143
143
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
144
|
-
if (pic) lib.force_pic = pic;
|
|
145
144
|
b.installArtifact(lib);
|
|
146
145
|
c = true;
|
|
147
146
|
} else {
|
|
148
147
|
const lib = b.addStaticLibrary(.{
|
|
149
148
|
.name = name,
|
|
150
|
-
.
|
|
151
|
-
.root_source_file = .{ .path = "src/lib/binding/c.zig" },
|
|
149
|
+
.root_source_file = b.path("src/lib/c.zig"),
|
|
152
150
|
.optimize = optimize,
|
|
153
151
|
.target = target,
|
|
152
|
+
.strip = strip,
|
|
153
|
+
.pic = pic,
|
|
154
154
|
});
|
|
155
|
-
lib.addOptions("build_options", options);
|
|
156
|
-
lib.addIncludePath(.
|
|
155
|
+
lib.root_module.addOptions("build_options", options);
|
|
156
|
+
lib.addIncludePath(b.path("src/include"));
|
|
157
157
|
lib.bundle_compiler_rt = true;
|
|
158
158
|
maybeStrip(b, lib, b.getInstallStep(), strip, cmd);
|
|
159
|
-
if (pic) lib.force_pic = pic;
|
|
160
159
|
if (emit_asm) {
|
|
161
160
|
b.getInstallStep().dependOn(&b.addInstallFileWithDir(
|
|
162
161
|
lib.getEmittedAsm(),
|
|
@@ -177,14 +176,18 @@ pub fn build(b: *std.Build) !void {
|
|
|
177
176
|
|
|
178
177
|
if (c) {
|
|
179
178
|
const header = b.addInstallFileWithDir(
|
|
180
|
-
.
|
|
179
|
+
b.path("src/include/pkmn.h"),
|
|
181
180
|
.header,
|
|
182
181
|
"pkmn.h",
|
|
183
182
|
);
|
|
184
183
|
b.getInstallStep().dependOn(&header.step);
|
|
185
184
|
|
|
186
185
|
const pc = b.fmt("lib{s}.pc", .{name});
|
|
187
|
-
const file = try
|
|
186
|
+
const file = try std.fs.path.relative(
|
|
187
|
+
b.allocator,
|
|
188
|
+
try std.process.getCwdAlloc(b.allocator),
|
|
189
|
+
try b.cache_root.join(b.allocator, &.{pc}),
|
|
190
|
+
);
|
|
188
191
|
const pkgconfig_file = try std.fs.cwd().createFile(file, .{});
|
|
189
192
|
|
|
190
193
|
const dirname = comptime std.fs.path.dirname(@src().file) orelse ".";
|
|
@@ -217,7 +220,7 @@ pub fn build(b: *std.Build) !void {
|
|
|
217
220
|
// TODO: tests can be run multiple times due to @imports
|
|
218
221
|
const tests = TestStep.create(b, options, config);
|
|
219
222
|
|
|
220
|
-
var exes = std.ArrayList(*std.Build.
|
|
223
|
+
var exes = std.ArrayList(*std.Build.Step.Compile).init(b.allocator);
|
|
221
224
|
const tools: ToolConfig = .{
|
|
222
225
|
.options = .{
|
|
223
226
|
.showdown = showdown,
|
|
@@ -265,13 +268,12 @@ pub fn build(b: *std.Build) !void {
|
|
|
265
268
|
|
|
266
269
|
fn maybeStrip(
|
|
267
270
|
b: *std.Build,
|
|
268
|
-
artifact: *std.Build.
|
|
271
|
+
artifact: *std.Build.Step.Compile,
|
|
269
272
|
step: *std.Build.Step,
|
|
270
|
-
strip: bool,
|
|
273
|
+
strip: ?bool,
|
|
271
274
|
cmd: ?[]const u8,
|
|
272
275
|
) void {
|
|
273
|
-
|
|
274
|
-
if (!strip or cmd == null) return;
|
|
276
|
+
if (!(strip orelse false) or cmd == null) return;
|
|
275
277
|
// Using `strip -r -u` for dynamic libraries is supposed to work on macOS but doesn't...
|
|
276
278
|
const mac = builtin.os.tag == .macos;
|
|
277
279
|
if (mac and artifact.isDynamicLibrary()) return;
|
|
@@ -283,10 +285,10 @@ fn maybeStrip(
|
|
|
283
285
|
}
|
|
284
286
|
|
|
285
287
|
const Config = struct {
|
|
286
|
-
target: std.
|
|
288
|
+
target: std.Build.ResolvedTarget,
|
|
287
289
|
optimize: std.builtin.OptimizeMode,
|
|
288
|
-
pic: bool,
|
|
289
|
-
strip: bool,
|
|
290
|
+
pic: ?bool,
|
|
291
|
+
strip: ?bool,
|
|
290
292
|
cmd: ?[]const u8,
|
|
291
293
|
};
|
|
292
294
|
|
|
@@ -294,9 +296,8 @@ const TestStep = struct {
|
|
|
294
296
|
step: std.Build.Step,
|
|
295
297
|
build: bool,
|
|
296
298
|
|
|
297
|
-
pub fn create(b: *std.Build, options: *std.Build.
|
|
299
|
+
pub fn create(b: *std.Build, options: *std.Build.Step.Options, config: Config) *TestStep {
|
|
298
300
|
const coverage = b.option([]const u8, "test-coverage", "Generate test coverage");
|
|
299
|
-
const test_file = b.option([]const u8, "test-file", "Input file for test");
|
|
300
301
|
const test_filter =
|
|
301
302
|
b.option([]const u8, "test-filter", "Skip tests that do not match filter");
|
|
302
303
|
|
|
@@ -304,22 +305,17 @@ const TestStep = struct {
|
|
|
304
305
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Run all tests", .owner = b });
|
|
305
306
|
self.* = .{ .step = step, .build = test_filter == null };
|
|
306
307
|
|
|
307
|
-
const path = test_file orelse "src/lib/test.zig";
|
|
308
308
|
const tests = b.addTest(.{
|
|
309
|
-
.
|
|
310
|
-
std.fs.path.basename(std.fs.path.dirname(path).?),
|
|
311
|
-
std.fs.path.stem(std.fs.path.basename(path)),
|
|
312
|
-
}),
|
|
313
|
-
.main_pkg_path = .{ .path = "." },
|
|
314
|
-
.root_source_file = .{ .path = path },
|
|
309
|
+
.root_source_file = b.path("src/lib/test.zig"),
|
|
315
310
|
.optimize = config.optimize,
|
|
316
311
|
.target = config.target,
|
|
317
312
|
.filter = test_filter,
|
|
313
|
+
.single_threaded = true,
|
|
314
|
+
.strip = config.strip,
|
|
315
|
+
.pic = config.pic,
|
|
318
316
|
});
|
|
319
|
-
tests.addOptions("build_options", options);
|
|
320
|
-
tests.single_threaded = true;
|
|
317
|
+
tests.root_module.addOptions("build_options", options);
|
|
321
318
|
maybeStrip(b, tests, &tests.step, config.strip, config.cmd);
|
|
322
|
-
if (config.pic) tests.force_pic = config.pic;
|
|
323
319
|
if (coverage) |c| {
|
|
324
320
|
tests.setExecCmd(&.{ "kcov", "--include-pattern=src/lib", c, null });
|
|
325
321
|
}
|
|
@@ -335,11 +331,11 @@ const ToolConfig = struct {
|
|
|
335
331
|
tool: struct {
|
|
336
332
|
tests: ?*TestStep,
|
|
337
333
|
name: ?[]const u8 = null,
|
|
338
|
-
exes: *std.ArrayList(*std.Build.
|
|
334
|
+
exes: *std.ArrayList(*std.Build.Step.Compile),
|
|
339
335
|
},
|
|
340
336
|
};
|
|
341
337
|
|
|
342
|
-
fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.
|
|
338
|
+
fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.Step.Run {
|
|
343
339
|
std.fs.cwd().access(path, .{}) catch |err| switch (err) {
|
|
344
340
|
error.FileNotFound => return null,
|
|
345
341
|
else => |e| return e,
|
|
@@ -351,14 +347,15 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.RunSte
|
|
|
351
347
|
|
|
352
348
|
const exe = b.addExecutable(.{
|
|
353
349
|
.name = name,
|
|
354
|
-
.root_source_file = .
|
|
350
|
+
.root_source_file = b.path(path),
|
|
355
351
|
.target = config.general.target,
|
|
356
352
|
.optimize = config.general.optimize,
|
|
353
|
+
.single_threaded = true,
|
|
354
|
+
.strip = config.general.strip,
|
|
355
|
+
.pic = config.general.pic,
|
|
357
356
|
});
|
|
358
|
-
exe.
|
|
357
|
+
exe.root_module.addImport("pkmn", module(b, config.options));
|
|
359
358
|
|
|
360
|
-
exe.single_threaded = true;
|
|
361
|
-
if (config.general.pic) exe.force_pic = config.general.pic;
|
|
362
359
|
if (config.tool.tests) |ts| ts.step.dependOn(&exe.step);
|
|
363
360
|
config.tool.exes.append(exe) catch @panic("OOM");
|
|
364
361
|
|
|
@@ -372,7 +369,7 @@ fn tool(b: *std.Build, path: []const u8, config: ToolConfig) !?*std.Build.RunSte
|
|
|
372
369
|
const ToolsStep = struct {
|
|
373
370
|
step: std.Build.Step,
|
|
374
371
|
|
|
375
|
-
pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.
|
|
372
|
+
pub fn create(b: *std.Build, exes: *std.ArrayList(*std.Build.Step.Compile)) *ToolsStep {
|
|
376
373
|
const self = b.allocator.create(ToolsStep) catch @panic("OOM");
|
|
377
374
|
const step = std.Build.Step.init(.{ .id = .custom, .name = "Install tools", .owner = b });
|
|
378
375
|
self.* = .{ .step = step };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pkmn/engine",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.46850a3d",
|
|
4
4
|
"description": "A minimal, complete, Pokémon battle simulation engine optimized for performance",
|
|
5
5
|
"repository": "github:pkmn/engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,9 +31,6 @@
|
|
|
31
31
|
"build/test/display.js",
|
|
32
32
|
"build/tools/debug.js.map",
|
|
33
33
|
"build/tools/debug.js",
|
|
34
|
-
"src/bin/install-pkmn-engine",
|
|
35
|
-
"src/lib/binding/node.zig",
|
|
36
|
-
"src/lib/binding/wasm.zig",
|
|
37
34
|
"src/lib/common/battle.zig",
|
|
38
35
|
"src/lib/common/data.zig",
|
|
39
36
|
"src/lib/common/debug.zig",
|
|
@@ -62,7 +59,9 @@
|
|
|
62
59
|
"src/lib/gen2/generated.zig",
|
|
63
60
|
"src/lib/gen2/helpers.zig",
|
|
64
61
|
"src/lib/gen2/mechanics.zig",
|
|
62
|
+
"src/lib/node.zig",
|
|
65
63
|
"src/lib/pkmn.zig",
|
|
64
|
+
"src/lib/wasm.zig",
|
|
66
65
|
"src/test/display/pkmn.html.tmpl"
|
|
67
66
|
],
|
|
68
67
|
"engines": {
|
|
@@ -76,31 +75,31 @@
|
|
|
76
75
|
"access": "public"
|
|
77
76
|
},
|
|
78
77
|
"dependencies": {
|
|
79
|
-
"@pkmn/data": "^0.
|
|
80
|
-
"@pkmn/protocol": "^0.6.
|
|
78
|
+
"@pkmn/data": "^0.9.9",
|
|
79
|
+
"@pkmn/protocol": "^0.6.25"
|
|
81
80
|
},
|
|
82
81
|
"devDependencies": {
|
|
83
|
-
"@pkmn/eslint-config": "^5.
|
|
84
|
-
"@pkmn/img": "^0.2.
|
|
85
|
-
"@pkmn/sets": "^5.1.
|
|
86
|
-
"@pkmn/sim": "0.
|
|
87
|
-
"@types/html-minifier": "^4.0.
|
|
88
|
-
"@types/jest": "^29.5.
|
|
89
|
-
"@types/minimist": "^1.2.
|
|
90
|
-
"@types/mustache": "^4.2.
|
|
91
|
-
"@types/node": "^20.
|
|
92
|
-
"@vitest/coverage-
|
|
93
|
-
"binaryen": "^
|
|
94
|
-
"eslint": "
|
|
82
|
+
"@pkmn/eslint-config": "^7.5.0",
|
|
83
|
+
"@pkmn/img": "^0.2.30",
|
|
84
|
+
"@pkmn/sets": "^5.1.2",
|
|
85
|
+
"@pkmn/sim": "0.9.9",
|
|
86
|
+
"@types/html-minifier": "^4.0.5",
|
|
87
|
+
"@types/jest": "^29.5.12",
|
|
88
|
+
"@types/minimist": "^1.2.5",
|
|
89
|
+
"@types/mustache": "^4.2.5",
|
|
90
|
+
"@types/node": "^20.14.10",
|
|
91
|
+
"@vitest/coverage-v8": "^2.0.2",
|
|
92
|
+
"binaryen": "^118.0.0",
|
|
93
|
+
"eslint": "<=8",
|
|
95
94
|
"html-minifier": "^4.0.0",
|
|
96
|
-
"json-stringify-pretty-compact": "
|
|
95
|
+
"json-stringify-pretty-compact": "4.0.0",
|
|
97
96
|
"minimist": "^1.2.8",
|
|
98
97
|
"mustache": "^4.2.0",
|
|
99
98
|
"source-map-support": "^0.5.21",
|
|
100
|
-
"table": "^6.8.
|
|
99
|
+
"table": "^6.8.2",
|
|
101
100
|
"trakr": "^0.2.0",
|
|
102
|
-
"typescript": "^5.
|
|
103
|
-
"vitest": "^0.
|
|
101
|
+
"typescript": "^5.5.3",
|
|
102
|
+
"vitest": "^2.0.2"
|
|
104
103
|
},
|
|
105
104
|
"scripts": {
|
|
106
105
|
"lint": "eslint --cache src --ext ts,js && eslint src/bin/*",
|
|
@@ -142,6 +141,14 @@
|
|
|
142
141
|
]
|
|
143
142
|
}
|
|
144
143
|
},
|
|
144
|
+
{
|
|
145
|
+
"files": [
|
|
146
|
+
"src/test/display.ts"
|
|
147
|
+
],
|
|
148
|
+
"rules": {
|
|
149
|
+
"@typescript-eslint/no-unnecessary-type-assertion": "off"
|
|
150
|
+
}
|
|
151
|
+
},
|
|
145
152
|
{
|
|
146
153
|
"files": [
|
|
147
154
|
"src/pkg/index.ts",
|
|
@@ -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: 13, 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';
|
|
@@ -283,19 +283,19 @@ const downloadImportLib = async () => {
|
|
|
283
283
|
let error = false;
|
|
284
284
|
for (let i = 2; i < process.argv.length; i++) {
|
|
285
285
|
switch (process.argv[i]) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
286
|
+
case "--silent": {
|
|
287
|
+
SILENT = true;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case "--zig": {
|
|
291
|
+
if (options || only) error = true;
|
|
292
|
+
only = true;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
default: {
|
|
296
|
+
if (options || only || !process.argv[i].startsWith('--options=')) error = true;
|
|
297
|
+
options = process.argv[i].slice(10).split(' ');
|
|
298
|
+
}
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
if (error) {
|
|
@@ -370,8 +370,10 @@ const downloadImportLib = async () => {
|
|
|
370
370
|
const args = ['build', '-p', 'build', ...opts];
|
|
371
371
|
if (!process.env.DEBUG_PKMN_ENGINE) args.push('-Doptimize=ReleaseFast', '-Dstrip');
|
|
372
372
|
if (config.type === 'node') {
|
|
373
|
-
args.push(`-Dnode-headers=${headers}`);
|
|
374
|
-
if (process.platform === 'win32')
|
|
373
|
+
args.push(`-Dnode-headers=${path.relative(ROOT, headers)}`);
|
|
374
|
+
if (process.platform === 'win32') {
|
|
375
|
+
args.push(`-Dnode-import-library=${path.relative(ROOT, lib)}`);
|
|
376
|
+
}
|
|
375
377
|
} else {
|
|
376
378
|
args.push('-Dwasm');
|
|
377
379
|
}
|
|
@@ -386,8 +388,14 @@ const downloadImportLib = async () => {
|
|
|
386
388
|
const prefix = process.platform === 'win32' ? '' : 'lib';
|
|
387
389
|
const ext = process.platform === 'darwin'
|
|
388
390
|
? 'dylib' : process.platform === 'win32' ? 'dll' : 'so';
|
|
389
|
-
|
|
390
|
-
|
|
391
|
+
try {
|
|
392
|
+
const actual = path.join('build', 'lib', `${prefix}pkmn${suffix}.node.${ext}`);
|
|
393
|
+
fs.renameSync(actual, artifact);
|
|
394
|
+
} catch (err) {
|
|
395
|
+
// ziglang/zig#19743 changed this path
|
|
396
|
+
const actual = path.join('build', 'bin', `${prefix}pkmn${suffix}.node.${ext}`);
|
|
397
|
+
fs.renameSync(actual, artifact);
|
|
398
|
+
}
|
|
391
399
|
}
|
|
392
400
|
}
|
|
393
401
|
})().catch(e => {
|
package/src/lib/common/data.zig
CHANGED
|
@@ -22,8 +22,8 @@ pub const Player = enum(u1) {
|
|
|
22
22
|
|
|
23
23
|
test Player {
|
|
24
24
|
try expectEqual(Player.P2, Player.P1.foe());
|
|
25
|
-
try expectEqual(
|
|
26
|
-
try expectEqual(
|
|
25
|
+
try expectEqual(0b0001, @as(u8, @bitCast(Player.P1.ident(1))));
|
|
26
|
+
try expectEqual(0b1101, @as(u8, @bitCast(Player.P2.ident(5))));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/// An identifier for a specific Pokémon in battle.
|
|
@@ -46,8 +46,8 @@ pub const ID = packed struct(u8) {
|
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
test ID {
|
|
49
|
-
try expectEqual(
|
|
50
|
-
try expectEqual(
|
|
49
|
+
try expectEqual(0b0001, @as(u8, @bitCast(ID{ .player = .P1, .id = 1 })));
|
|
50
|
+
try expectEqual(0b1101, @as(u8, @bitCast(ID{ .player = .P2, .id = 5 })));
|
|
51
51
|
const id: ID = .{ .player = .P2, .id = 4 };
|
|
52
52
|
try expectEqual(id, ID.from(id.int()));
|
|
53
53
|
}
|
|
@@ -3,8 +3,8 @@ const builtin = @import("builtin");
|
|
|
3
3
|
|
|
4
4
|
const pkmn = @import("../pkmn.zig");
|
|
5
5
|
|
|
6
|
-
const data = @import("
|
|
7
|
-
const options = @import("
|
|
6
|
+
const data = @import("data.zig");
|
|
7
|
+
const options = @import("options.zig");
|
|
8
8
|
|
|
9
9
|
const assert = std.debug.assert;
|
|
10
10
|
const print = std.debug.print;
|
|
@@ -220,6 +220,7 @@ pub const Activate = enum(u8) {
|
|
|
220
220
|
BeatUp, // FIXME of
|
|
221
221
|
|
|
222
222
|
Magnitude,
|
|
223
|
+
Spite,
|
|
223
224
|
};
|
|
224
225
|
|
|
225
226
|
pub const Start = enum(u8) {
|
|
@@ -544,6 +545,7 @@ pub fn Log(comptime Writer: type) type {
|
|
|
544
545
|
// ident: ID, reason: Activate
|
|
545
546
|
// ident: ID, reason: .SubstituteBlock, m: <Move>
|
|
546
547
|
// ident: ID, reason: .Magnitude, num: u8
|
|
548
|
+
// ident: ID, reason: .Spite, m: <Move>, num: u8
|
|
547
549
|
pub fn activate(self: Self, args: anytype) Error!void {
|
|
548
550
|
if (!enabled) return;
|
|
549
551
|
|
|
@@ -561,6 +563,9 @@ pub fn Log(comptime Writer: type) type {
|
|
|
561
563
|
assert(reason == .Magnitude);
|
|
562
564
|
try self.writer.writeByte(args[2]);
|
|
563
565
|
}
|
|
566
|
+
} else if (args.len == 4) {
|
|
567
|
+
assert(reason == .Spite);
|
|
568
|
+
try self.writer.writeAll(&.{ @intFromEnum(args[2]), args[3] });
|
|
564
569
|
}
|
|
565
570
|
}
|
|
566
571
|
|
|
@@ -1202,14 +1207,11 @@ pub fn expectLog(
|
|
|
1202
1207
|
) !void {
|
|
1203
1208
|
if (!enabled) return;
|
|
1204
1209
|
|
|
1205
|
-
const color =
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
} else {
|
|
1211
|
-
break :color std.io.getStdErr().supportsAnsiEscapeCodes();
|
|
1212
|
-
}
|
|
1210
|
+
const color = if (std.process.hasEnvVarConstant("ZIG_DEBUG_COLOR"))
|
|
1211
|
+
true
|
|
1212
|
+
else switch (std.io.tty.detectConfig(std.io.getStdErr())) {
|
|
1213
|
+
.escape_codes => true,
|
|
1214
|
+
else => false,
|
|
1213
1215
|
};
|
|
1214
1216
|
|
|
1215
1217
|
expectEqualBytes(expected, actual, offset) catch |err| switch (err) {
|
|
@@ -1248,20 +1250,13 @@ fn N(e: anytype) u8 {
|
|
|
1248
1250
|
const p1 = Player.P1;
|
|
1249
1251
|
const p2 = Player.P2;
|
|
1250
1252
|
|
|
1251
|
-
const gen1 = struct {
|
|
1252
|
-
pub usingnamespace @import("../gen1/data.zig");
|
|
1253
|
-
pub const helpers = @import("../gen1/helpers.zig");
|
|
1254
|
-
};
|
|
1255
|
-
|
|
1256
|
-
const gen2 = struct {
|
|
1257
|
-
pub usingnamespace @import("../gen2/data.zig");
|
|
1258
|
-
pub const helpers = @import("../gen2/helpers.zig");
|
|
1259
|
-
};
|
|
1260
|
-
|
|
1261
1253
|
var buf: [pkmn.LOGS_SIZE]u8 = undefined;
|
|
1262
1254
|
var stream: ByteStream = .{ .buffer = &buf };
|
|
1263
1255
|
var log: FixedLog = .{ .writer = stream.writer() };
|
|
1264
1256
|
|
|
1257
|
+
const gen1 = pkmn.gen1;
|
|
1258
|
+
const gen2 = pkmn.gen2;
|
|
1259
|
+
|
|
1265
1260
|
const M1 = gen1.Move;
|
|
1266
1261
|
const S1 = gen1.Species;
|
|
1267
1262
|
|
package/src/lib/common/rng.zig
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
|
|
3
|
-
const options = @import("
|
|
3
|
+
const options = @import("options.zig");
|
|
4
4
|
|
|
5
5
|
const assert = std.debug.assert;
|
|
6
6
|
const expectEqual = std.testing.expectEqual;
|
|
@@ -66,11 +66,15 @@ pub const PSRNG = extern struct {
|
|
|
66
66
|
(@as(u64, self.range(u16, 0, 0x10000)) << 16) |
|
|
67
67
|
(@as(u64, self.range(u16, 0, 0x10000)));
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
pub fn Bound(comptime T: type) type {
|
|
71
|
+
return std.math.IntFittingRange(0, std.math.maxInt(T) + 1);
|
|
72
|
+
}
|
|
69
73
|
};
|
|
70
74
|
|
|
71
75
|
test PSRNG {
|
|
72
76
|
var psrng: PSRNG = .{ .src = .{ .seed = 0x0001000200030004 } };
|
|
73
|
-
try expectEqual(
|
|
77
|
+
try expectEqual(121, psrng.range(u8, 0, 256));
|
|
74
78
|
try expectEqual(false, psrng.chance(u8, 128, 256)); // 226 < 128
|
|
75
79
|
}
|
|
76
80
|
|
|
@@ -107,9 +111,9 @@ test Gen12 {
|
|
|
107
111
|
try expectEqual(e, rng.next());
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
try expectEqual(
|
|
111
|
-
try expectEqual(
|
|
112
|
-
try expectEqual(
|
|
114
|
+
try expectEqual(16, Gen12.percent(6) + 1);
|
|
115
|
+
try expectEqual(16, Gen12.percent(7) - 1);
|
|
116
|
+
try expectEqual(128, Gen12.percent(50) + 1);
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
// https://pkmn.cc/pokeemerald/src/random.c
|
|
@@ -197,7 +201,7 @@ pub fn FixedRNG(comptime gen: comptime_int, comptime len: usize) type {
|
|
|
197
201
|
for (0..n) |_| _ = self.next();
|
|
198
202
|
}
|
|
199
203
|
|
|
200
|
-
pub fn range(self: *Self, comptime T: type, from: T, to: Bound(T)) T {
|
|
204
|
+
pub fn range(self: *Self, comptime T: type, from: T, to: PSRNG.Bound(T)) T {
|
|
201
205
|
assert(showdown);
|
|
202
206
|
return @intCast(@as(u64, self.next()) * (to - from) / divisor + from);
|
|
203
207
|
}
|
|
@@ -206,7 +210,7 @@ pub fn FixedRNG(comptime gen: comptime_int, comptime len: usize) type {
|
|
|
206
210
|
self: *Self,
|
|
207
211
|
comptime T: type,
|
|
208
212
|
numerator: T,
|
|
209
|
-
denominator: Bound(T),
|
|
213
|
+
denominator: PSRNG.Bound(T),
|
|
210
214
|
) bool {
|
|
211
215
|
assert(showdown);
|
|
212
216
|
assert(denominator > 0);
|
|
@@ -237,7 +241,3 @@ fn Output(comptime gen: comptime_int) type {
|
|
|
237
241
|
else => unreachable,
|
|
238
242
|
};
|
|
239
243
|
}
|
|
240
|
-
|
|
241
|
-
fn Bound(comptime T: type) type {
|
|
242
|
-
return std.math.IntFittingRange(0, std.math.maxInt(T) + 1);
|
|
243
|
-
}
|