@pkmn/engine 0.1.0-dev.96b6c8fa → 0.1.0-dev.979a393a
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 +22 -22
- package/build/pkg/data/layout.json +1 -1
- package/build/pkg/gen1.d.ts +4 -5
- package/build/pkg/gen1.js +24 -43
- package/build/pkg/gen1.js.map +1 -1
- package/build/pkg/index.d.ts +12 -15
- package/build/pkg/index.js.map +1 -1
- package/build/pkg/protocol.d.ts +2 -4
- package/build/pkg/protocol.js +2 -4
- package/build/pkg/protocol.js.map +1 -1
- package/build/test/display.js +13 -31
- package/build/test/display.js.map +1 -1
- package/build.zig +26 -21
- package/package.json +9 -13
- package/src/bin/install-pkmn-engine +3 -3
- package/src/bin/pkmn-debug +6 -29
- package/src/lib/binding/node.zig +5 -5
- package/src/lib/binding/wasm.zig +3 -3
- package/src/lib/common/debug.zig +0 -1
- package/src/lib/common/options.zig +3 -3
- package/src/lib/common/protocol.zig +38 -38
- package/src/lib/gen1/README.md +71 -99
- package/src/lib/gen1/data.zig +17 -19
- package/src/lib/gen1/helpers.zig +15 -4
- package/src/lib/gen1/mechanics.zig +304 -378
- package/src/lib/gen2/data.zig +4 -4
- package/src/lib/pkmn.zig +7 -7
- package/build/pkg/addon.d.ts +0 -7
- package/build/pkg/addon.js +0 -111
- package/build/pkg/addon.js.map +0 -1
package/src/lib/gen2/data.zig
CHANGED
|
@@ -19,13 +19,13 @@ const assert = std.debug.assert;
|
|
|
19
19
|
const expectEqual = std.testing.expectEqual;
|
|
20
20
|
const expect = std.testing.expect;
|
|
21
21
|
|
|
22
|
-
pub const
|
|
22
|
+
pub const MAX_OPTIONS: usize = 9; // move 1..4, switch 2..6
|
|
23
23
|
pub const MAX_LOGS: usize = 180; // TODO
|
|
24
24
|
|
|
25
|
-
pub const
|
|
26
|
-
|
|
25
|
+
pub const OPTIONS_SIZE = if (builtin.mode == .ReleaseSmall)
|
|
26
|
+
MAX_OPTIONS
|
|
27
27
|
else
|
|
28
|
-
std.math.ceilPowerOfTwo(usize,
|
|
28
|
+
std.math.ceilPowerOfTwo(usize, MAX_OPTIONS) catch unreachable;
|
|
29
29
|
pub const LOGS_SIZE = if (builtin.mode == .ReleaseSmall)
|
|
30
30
|
MAX_LOGS
|
|
31
31
|
else
|
package/src/lib/pkmn.zig
CHANGED
|
@@ -4,10 +4,10 @@ pub const options = @import("common/options.zig");
|
|
|
4
4
|
pub const Options = options.Options;
|
|
5
5
|
|
|
6
6
|
/// The minimum size in bytes required to hold all choice options.
|
|
7
|
-
pub const
|
|
7
|
+
pub const MAX_OPTIONS = gen1.MAX_OPTIONS;
|
|
8
8
|
/// The optimal size in bytes required to hold all choice options.
|
|
9
|
-
/// At least as large as `
|
|
10
|
-
pub const
|
|
9
|
+
/// At least as large as `MAX_OPTIONS`.
|
|
10
|
+
pub const OPTIONS_SIZE = gen1.OPTIONS_SIZE;
|
|
11
11
|
/// The maximum number of bytes possibly logged by a single update.
|
|
12
12
|
pub const MAX_LOGS = gen1.MAX_LOGS;
|
|
13
13
|
/// The optimal size in bytes required to hold the largest amount of log data
|
|
@@ -25,12 +25,12 @@ pub const Result = @import("common/data.zig").Result;
|
|
|
25
25
|
/// Pokémon Showdown's RNG (backed by a Generation V & VI RNG).
|
|
26
26
|
pub const PSRNG = @import("common/rng.zig").PSRNG;
|
|
27
27
|
|
|
28
|
-
/// Namespace for helpers related to protocol
|
|
28
|
+
/// Namespace for helpers related to protocol trace logging.
|
|
29
29
|
pub const protocol = if (options.internal) struct {
|
|
30
30
|
pub usingnamespace @import("common/protocol.zig");
|
|
31
31
|
} else struct {
|
|
32
32
|
/// Logs protocol information to its `Writer` during a battle update when
|
|
33
|
-
/// `options.
|
|
33
|
+
/// `options.trace` is enabled.
|
|
34
34
|
pub const Log = @import("common/protocol.zig").Log;
|
|
35
35
|
/// Stripped down version of `std.io.FixedBufferStream` optimized for
|
|
36
36
|
/// efficiently writing the individual protocol bytes. Note that the
|
|
@@ -41,8 +41,8 @@ pub const protocol = if (options.internal) struct {
|
|
|
41
41
|
/// intialized with a `LOGS_SIZE`-sized buffer.
|
|
42
42
|
pub const FixedLog = @import("common/protocol.zig").FixedLog;
|
|
43
43
|
/// Null object pattern implementation of `Log` backed by a
|
|
44
|
-
/// `std.io.null_writer`. Ignores anything sent to it, though
|
|
45
|
-
///
|
|
44
|
+
/// `std.io.null_writer`. Ignores anything sent to it, though trace logging
|
|
45
|
+
/// should addtionally be turned off entirely by using `options.trace`.
|
|
46
46
|
pub const NULL = @import("common/protocol.zig").NULL;
|
|
47
47
|
};
|
|
48
48
|
|
package/build/pkg/addon.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Choice, Player, Result } from '.';
|
|
2
|
-
export declare function check(showdown: boolean): void;
|
|
3
|
-
export declare function supports(showdown: boolean, log?: boolean): boolean;
|
|
4
|
-
export declare function update(index: number, showdown: boolean, battle: ArrayBuffer, c1?: Choice, c2?: Choice, log?: ArrayBuffer): Result;
|
|
5
|
-
export declare function choices(index: number, showdown: boolean, battle: ArrayBuffer, player: Player, choice: Choice['type'], buf: ArrayBuffer): Choice[];
|
|
6
|
-
export declare function choose(index: number, showdown: boolean, battle: ArrayBuffer, player: Player, choice: Choice['type'], buf: ArrayBuffer, fn: (n: number) => number): Choice;
|
|
7
|
-
export declare function size(index: number, type: 'choices' | 'log'): number;
|
package/build/pkg/addon.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.size = exports.choose = exports.choices = exports.update = exports.supports = exports.check = void 0;
|
|
27
|
-
const path = __importStar(require("path"));
|
|
28
|
-
const _1 = require(".");
|
|
29
|
-
const ROOT = path.join(__dirname, '..', '..');
|
|
30
|
-
let ADDON = undefined;
|
|
31
|
-
function load() {
|
|
32
|
-
if (ADDON)
|
|
33
|
-
return ADDON;
|
|
34
|
-
let pkmn = undefined;
|
|
35
|
-
let showdown = undefined;
|
|
36
|
-
try {
|
|
37
|
-
pkmn = require(path.join(ROOT, 'build', 'lib', 'pkmn.node'));
|
|
38
|
-
}
|
|
39
|
-
catch { }
|
|
40
|
-
try {
|
|
41
|
-
showdown = require(path.join(ROOT, 'build', 'lib', 'pkmn-showdown.node'));
|
|
42
|
-
}
|
|
43
|
-
catch { }
|
|
44
|
-
if (!pkmn && !showdown) {
|
|
45
|
-
throw new Error('Could not find native addons - did you run `npx install-pkmn-engine`?');
|
|
46
|
-
}
|
|
47
|
-
return (ADDON = [pkmn, showdown]);
|
|
48
|
-
}
|
|
49
|
-
function check(showdown) {
|
|
50
|
-
if (!load()[+showdown]) {
|
|
51
|
-
const opts = ADDON[+!showdown].options.log ? ['-log'] : [];
|
|
52
|
-
if (showdown)
|
|
53
|
-
opts.push('-Dshowdown');
|
|
54
|
-
throw new Error(`@pkmn/engine has ${showdown ? 'not' : 'only'} been configured to support Pokémon Showdown.` +
|
|
55
|
-
`\n(running \`npx install-pkmn-engine --options='${opts.join(' ')}'\` can fix this issue).`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.check = check;
|
|
59
|
-
function supports(showdown, log) {
|
|
60
|
-
if (!load()[+showdown])
|
|
61
|
-
return false;
|
|
62
|
-
if (log === undefined)
|
|
63
|
-
return true;
|
|
64
|
-
return ADDON[+showdown].options.log === log;
|
|
65
|
-
}
|
|
66
|
-
exports.supports = supports;
|
|
67
|
-
function update(index, showdown, battle, c1, c2, log) {
|
|
68
|
-
return _1.Result.decode(ADDON[+showdown].bindings[index]
|
|
69
|
-
.update(battle, _1.Choice.encode(c1), _1.Choice.encode(c2), log));
|
|
70
|
-
}
|
|
71
|
-
exports.update = update;
|
|
72
|
-
function choices(index, showdown, battle, player, choice, buf) {
|
|
73
|
-
const request = choice[0] === 'p' ? 0 : choice[0] === 'm' ? 1 : 2;
|
|
74
|
-
const n = ADDON[+showdown].bindings[index].choices(battle, +(player !== 'p1'), request, buf);
|
|
75
|
-
// The top-level API signature means our hands our tied with respect to
|
|
76
|
-
// writing really fast bindings here. The simplest approach would be to return
|
|
77
|
-
// the ArrayBuffer the bindings populate as well as its size and only decode a
|
|
78
|
-
// Choice after the selection. However, given that we need to return
|
|
79
|
-
// `Choices[]` we need to decode all of them even if they're not all being
|
|
80
|
-
// used which is wasteful. This shouldn't be *that* bad as its a very small
|
|
81
|
-
// list, but its still wasted work. Switching the top-level API to return an
|
|
82
|
-
// Iterable<Choice> doesn't help as we need both the length and the ability to
|
|
83
|
-
// randomly access it, so the best way to make the current API fast would be
|
|
84
|
-
// to have the Zig bindings create Choice objects directly, only that won't
|
|
85
|
-
// scale well as it would require us to basically rewrite the low-level
|
|
86
|
-
// choices function for each generation within node.zig. We could do something
|
|
87
|
-
// really galaxy-brained and return some sort of frankenstein subclass of
|
|
88
|
-
// Array backed by ArrayBuffer which would lazily decode the Choice on access,
|
|
89
|
-
// but thats ultimately not worth the effort. You can't have both a high-level
|
|
90
|
-
// idiomatic API and performance here, hence why the choose function below
|
|
91
|
-
// exists.
|
|
92
|
-
const options = new Array(n);
|
|
93
|
-
const data = new Uint8Array(buf);
|
|
94
|
-
for (let i = 0; i < n; i++)
|
|
95
|
-
options[i] = _1.Choice.decode(data[i]);
|
|
96
|
-
return options;
|
|
97
|
-
}
|
|
98
|
-
exports.choices = choices;
|
|
99
|
-
function choose(index, showdown, battle, player, choice, buf, fn) {
|
|
100
|
-
const request = choice[0] === 'p' ? 0 : choice[0] === 'm' ? 1 : 2;
|
|
101
|
-
const n = ADDON[+showdown].bindings[index].choices(battle, +(player !== 'p1'), request, buf);
|
|
102
|
-
const data = new Uint8Array(buf);
|
|
103
|
-
return _1.Choice.decode(data[fn(n)]);
|
|
104
|
-
}
|
|
105
|
-
exports.choose = choose;
|
|
106
|
-
function size(index, type) {
|
|
107
|
-
const bindings = (ADDON[1] ?? ADDON[0]).bindings[index];
|
|
108
|
-
return type[0] === 'c' ? bindings.CHOICES_SIZE : bindings.LOGS_SIZE;
|
|
109
|
-
}
|
|
110
|
-
exports.size = size;
|
|
111
|
-
//# sourceMappingURL=addon.js.map
|
package/build/pkg/addon.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addon.js","sourceRoot":"","sources":["../../src/pkg/addon.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAE7B,wBAAyC;AAEzC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAE9C,IAAI,KAAK,GAAoD,SAAS,CAAC;AAcvE,SAAS,IAAI;IACX,IAA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