ticbuild 1.0.17 → 1.0.19
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 +115 -6
- package/dist/backend/ImportedResourceTypes.d.ts +2 -1
- package/dist/backend/ImportedResourceTypes.d.ts.map +1 -1
- package/dist/backend/ImportedResourceTypes.js.map +1 -1
- package/dist/backend/codeBanking.test.js +112 -0
- package/dist/backend/codeBanking.test.js.map +1 -1
- package/dist/backend/importers/LuaCodeImporter.d.ts +7 -8
- package/dist/backend/importers/LuaCodeImporter.d.ts.map +1 -1
- package/dist/backend/importers/LuaCodeImporter.js +54 -15
- package/dist/backend/importers/LuaCodeImporter.js.map +1 -1
- package/dist/backend/importers/LuaCodeImporter.test.js +109 -7
- package/dist/backend/importers/LuaCodeImporter.test.js.map +1 -1
- package/dist/backend/luaEncode.js +1 -1
- package/dist/backend/luaEncode.js.map +1 -1
- package/dist/backend/luaPreprocessor.d.ts +1 -0
- package/dist/backend/luaPreprocessor.d.ts.map +1 -1
- package/dist/backend/luaPreprocessor.js +46 -0
- package/dist/backend/luaPreprocessor.js.map +1 -1
- package/dist/backend/luaPreprocessor.test.js +69 -0
- package/dist/backend/luaPreprocessor.test.js.map +1 -1
- package/dist/backend/manifestTypes.d.ts +4 -0
- package/dist/backend/manifestTypes.d.ts.map +1 -1
- package/dist/backend/manifestTypes.js.map +1 -1
- package/dist/backend/project.d.ts.map +1 -1
- package/dist/backend/project.js +56 -3
- package/dist/backend/project.js.map +1 -1
- package/dist/backend/symbolIndex.js +1 -0
- package/dist/backend/symbolIndex.js.map +1 -1
- package/dist/buildInfo.d.ts +5 -5
- package/dist/buildInfo.js +5 -5
- package/dist/buildInfo.js.map +1 -1
- package/dist/frontend/core.d.ts.map +1 -1
- package/dist/frontend/core.js +136 -4
- package/dist/frontend/core.js.map +1 -1
- package/dist/frontend/luaCodeArtifacts.test.d.ts +2 -0
- package/dist/frontend/luaCodeArtifacts.test.d.ts.map +1 -0
- package/dist/frontend/luaCodeArtifacts.test.js +260 -0
- package/dist/frontend/luaCodeArtifacts.test.js.map +1 -0
- package/dist/utils/lua/lua_alias_expressions.js +1 -1
- package/dist/utils/lua/lua_alias_expressions.js.map +1 -1
- package/dist/utils/lua/lua_alias_literals.js +1 -1
- package/dist/utils/lua/lua_alias_literals.js.map +1 -1
- package/dist/utils/lua/lua_alias_shared.js +1 -1
- package/dist/utils/lua/lua_alias_shared.js.map +1 -1
- package/dist/utils/lua/lua_processor.d.ts +2 -0
- package/dist/utils/lua/lua_processor.d.ts.map +1 -1
- package/dist/utils/lua/lua_processor.js +9 -0
- package/dist/utils/lua/lua_processor.js.map +1 -1
- package/dist/utils/lua/lua_processor.test.js +242 -0
- package/dist/utils/lua/lua_processor.test.js.map +1 -1
- package/dist/utils/lua/lua_rename_allowed_globals.d.ts +8 -0
- package/dist/utils/lua/lua_rename_allowed_globals.d.ts.map +1 -0
- package/dist/utils/lua/lua_rename_allowed_globals.js +268 -0
- package/dist/utils/lua/lua_rename_allowed_globals.js.map +1 -0
- package/dist/utils/tic80/bankSupport.test.js +27 -1
- package/dist/utils/tic80/bankSupport.test.js.map +1 -1
- package/dist/utils/tic80/cartLoader.d.ts.map +1 -1
- package/dist/utils/tic80/cartLoader.js +4 -2
- package/dist/utils/tic80/cartLoader.js.map +1 -1
- package/dist/utils/tic80/cartWriter.d.ts +6 -1
- package/dist/utils/tic80/cartWriter.d.ts.map +1 -1
- package/dist/utils/tic80/cartWriter.js +24 -13
- package/dist/utils/tic80/cartWriter.js.map +1 -1
- package/dist/utils/tic80/tic80.d.ts +8 -5
- package/dist/utils/tic80/tic80.d.ts.map +1 -1
- package/dist/utils/tic80/tic80.js +2 -1
- package/dist/utils/tic80/tic80.js.map +1 -1
- package/package.json +2 -1
- package/templates/TIC-80-ticbuild/tic80.exe +0 -0
- package/ticbuild.schema.json +49 -23
- package/templates/TIC-80-ticbuild/remoting_README.md +0 -470
package/ticbuild.schema.json
CHANGED
|
@@ -253,13 +253,22 @@
|
|
|
253
253
|
"renameTableFields": {
|
|
254
254
|
"type": "boolean"
|
|
255
255
|
},
|
|
256
|
-
"tableEntryKeysToRename": {
|
|
257
|
-
"type": "array",
|
|
258
|
-
"items": {
|
|
259
|
-
"type": "string"
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
256
|
+
"tableEntryKeysToRename": {
|
|
257
|
+
"type": "array",
|
|
258
|
+
"items": {
|
|
259
|
+
"type": "string"
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
"globalSymbolsToRename": {
|
|
263
|
+
"type": "array",
|
|
264
|
+
"items": {
|
|
265
|
+
"type": "string"
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
"renameSpecifiedGlobalSymbols": {
|
|
269
|
+
"type": "boolean"
|
|
270
|
+
}
|
|
271
|
+
},
|
|
263
272
|
"description": "Minification options (OptimizationRuleOptions)"
|
|
264
273
|
},
|
|
265
274
|
"globals": {
|
|
@@ -311,12 +320,12 @@
|
|
|
311
320
|
]
|
|
312
321
|
}
|
|
313
322
|
},
|
|
314
|
-
"bank": {
|
|
315
|
-
"type": "integer",
|
|
316
|
-
"minimum": 0,
|
|
317
|
-
"maximum":
|
|
318
|
-
"description": "Bank index (defaults to 0)"
|
|
319
|
-
},
|
|
323
|
+
"bank": {
|
|
324
|
+
"type": "integer",
|
|
325
|
+
"minimum": 0,
|
|
326
|
+
"maximum": 15,
|
|
327
|
+
"description": "Bank index (defaults to 0). Standard TIC-80 chunks support banks 0..7; CODE banks 8..15 require code.extendedCodeBanks, and CODE_COMPRESSED banks 1..15 require code.multiBankCompressedCode and the private TIC-80 build"
|
|
328
|
+
},
|
|
320
329
|
"asset": {
|
|
321
330
|
"oneOf": [
|
|
322
331
|
{
|
|
@@ -341,15 +350,32 @@
|
|
|
341
350
|
}
|
|
342
351
|
]
|
|
343
352
|
},
|
|
344
|
-
"code": {
|
|
345
|
-
"type": "object",
|
|
346
|
-
"properties": {
|
|
347
|
-
"emitGlobals": {
|
|
348
|
-
"type": "boolean",
|
|
349
|
-
"description": "Whether to emit assembly.lua.globals for this code block"
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
+
"code": {
|
|
354
|
+
"type": "object",
|
|
355
|
+
"properties": {
|
|
356
|
+
"emitGlobals": {
|
|
357
|
+
"type": "boolean",
|
|
358
|
+
"description": "Whether to emit assembly.lua.globals for this code block"
|
|
359
|
+
},
|
|
360
|
+
"compressionMode": {
|
|
361
|
+
"type": "string",
|
|
362
|
+
"enum": [
|
|
363
|
+
"default",
|
|
364
|
+
"zlib-max",
|
|
365
|
+
"zopfli"
|
|
366
|
+
],
|
|
367
|
+
"description": "Compression mode for CODE_COMPRESSED chunks emitted by this code block"
|
|
368
|
+
},
|
|
369
|
+
"extendedCodeBanks": {
|
|
370
|
+
"type": "boolean",
|
|
371
|
+
"description": "Allow CODE chunks to use private TIC-80 extended banks 8..15. Carts built with this option are not compatible with stock TIC-80"
|
|
372
|
+
},
|
|
373
|
+
"multiBankCompressedCode": {
|
|
374
|
+
"type": "boolean",
|
|
375
|
+
"description": "Allow CODE_COMPRESSED output to split across private TIC-80 compressed code banks. Carts that need more than one compressed bank are not compatible with stock TIC-80"
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
353
379
|
}
|
|
354
380
|
}
|
|
355
381
|
}
|
|
@@ -399,4 +425,4 @@
|
|
|
399
425
|
"description": "Build configuration overrides"
|
|
400
426
|
}
|
|
401
427
|
}
|
|
402
|
-
}
|
|
428
|
+
}
|
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
# Features in this fork
|
|
2
|
-
|
|
3
|
-
- Remoting server
|
|
4
|
-
- Frame timing and remoting display in window title and HUD (access via <kbd>ALT+0</kbd>)
|
|
5
|
-
|
|
6
|
-
# Perf HUD color scheme and thresholds
|
|
7
|
-
|
|
8
|
-
HUD colors are configured with these optional command line args:
|
|
9
|
-
|
|
10
|
-
- `--hud-palette-outline`
|
|
11
|
-
- `--hud-palette-text`
|
|
12
|
-
- `--hud-palette-ok`
|
|
13
|
-
- `--hud-palette-warning`
|
|
14
|
-
- `--hud-palette-alert`
|
|
15
|
-
|
|
16
|
-
Each value can be:
|
|
17
|
-
|
|
18
|
-
- `auto` (use built-in target color matching against current frame palette)
|
|
19
|
-
- a palette index (`0` to `15`)
|
|
20
|
-
- a hex color token without `#`, in either `rgb` or `rrggbb` form (`f80`, `ff8800`)
|
|
21
|
-
|
|
22
|
-
`auto` default targets are:
|
|
23
|
-
|
|
24
|
-
- outline: black
|
|
25
|
-
- text: white
|
|
26
|
-
- ok: green
|
|
27
|
-
- warning: orange/yellow
|
|
28
|
-
- alert: red
|
|
29
|
-
|
|
30
|
-
Threshold command line args:
|
|
31
|
-
|
|
32
|
-
- `--thresh-fps-warn` (fps)
|
|
33
|
-
- `--thresh-fps-alert` (fps)
|
|
34
|
-
- `--thresh-mem-warn` (kb)
|
|
35
|
-
- `--thresh-mem-alert` (kb)
|
|
36
|
-
- `--thresh-cycles-warn` (kcycles)
|
|
37
|
-
- `--thresh-cycles-alert` (kcycles)
|
|
38
|
-
|
|
39
|
-
Default thresholds:
|
|
40
|
-
|
|
41
|
-
- FPS: warning `<57`, alert `<53`
|
|
42
|
-
- MEM: warning `>102400` kb, alert `>256000` kb
|
|
43
|
-
- cycles (TIC/SCN+BDR): warning `>1800` kcycles, alert `>2400` kcycles
|
|
44
|
-
|
|
45
|
-
Threshold state is checked as alert first, then warning, then OK. For FPS (lower is
|
|
46
|
-
worse), comparisons are inverted.
|
|
47
|
-
|
|
48
|
-
Graph coloring is evaluated per rendered x-column and value text is colored by the
|
|
49
|
-
same severity. Custom perf metrics always use OK color.
|
|
50
|
-
|
|
51
|
-
# remoting support for ticbuild
|
|
52
|
-
|
|
53
|
-
[ticbuild](https://github.com/thenfour/ticbuild) is a build system for TIC-80 which
|
|
54
|
-
supports watching cart dependencies for live updates.
|
|
55
|
-
|
|
56
|
-
In order to make that work, we need to add some functionality to TIC-80 for remote control.
|
|
57
|
-
|
|
58
|
-
We add a command line arg:
|
|
59
|
-
|
|
60
|
-
`tic80.exe --remoting-port=9977`
|
|
61
|
-
|
|
62
|
-
While TIC-80 is running, it will listen on this port for remote commands. Always
|
|
63
|
-
binds to `127.0.0.1`. Up to 10 clients supported.
|
|
64
|
-
|
|
65
|
-
# Protocol
|
|
66
|
-
|
|
67
|
-
- Line-based human readable (terminal-friendly)
|
|
68
|
-
- dead-simple, no optional args or multiple datatypes if possible.
|
|
69
|
-
- requests
|
|
70
|
-
- each line in the form `<id> <command> <args...>`
|
|
71
|
-
- `id` is an id used to pair responses with requests. `id` must be integral number, and non-negative (>=0).
|
|
72
|
-
Invalid/negative IDs won't echo back to clients; id will be `0` in that case. (`-1 hello` will give response `0 ERR "invalid id"`)
|
|
73
|
-
- example: `1 sync 24`
|
|
74
|
-
- example: `1 poke 0x8fff <24 ff c0>`
|
|
75
|
-
- this `<xx ...>` syntax allows representing binary data in hex byte form
|
|
76
|
-
- multiple args are separated by whitespace.
|
|
77
|
-
- example: `1 eval "trace(\"hello from remote\")"`
|
|
78
|
-
- quotes wrap an arg that contains whitespace. Escape char is `\`
|
|
79
|
-
- `\\` = `\`
|
|
80
|
-
- `\"` = `"`
|
|
81
|
-
- commands are not case-sensitive. `sync` and `SYNC` and `SyNc` are equivalent.
|
|
82
|
-
- whitespace is forgiving. `1 sync 24` (or tabs) is the same as `1 sync 24`.
|
|
83
|
-
- trailing whitespace is trimmed/ignored
|
|
84
|
-
- non-ASCII chars are considered an error.
|
|
85
|
-
- named args not supported (yet)
|
|
86
|
-
- commands supported:
|
|
87
|
-
- `hello` - returns a description of the system (TIC-80 remoting v1)
|
|
88
|
-
- `load <cart_path.tic> <run:1|0>`, e.g. `load "c:\\xyz.tic" 1`.
|
|
89
|
-
If the run flag is `0`, the cart is just loaded. If `1`, the cart is
|
|
90
|
-
launched after successful load.
|
|
91
|
-
- `ping` - returns data `PONG`
|
|
92
|
-
- `sync <flags>` - returns nothing (syncs cart & runtime memory; see tic80 docs)
|
|
93
|
-
- `poke <addr> <data>` - returns nothing
|
|
94
|
-
- `peek <addr> <size>`
|
|
95
|
-
- returns the binary result, e.g., `<c0 a7 ff 00>`.
|
|
96
|
-
- size is required even if it's only 1.
|
|
97
|
-
- `restart`
|
|
98
|
-
- `quit`
|
|
99
|
-
- `eval <code>` - no return possible (`tic_script.eval` has `void` return type).
|
|
100
|
-
you could just make the script do something visible, like `poke()`.
|
|
101
|
-
- TODO: enable trace output to remote? or support return data?
|
|
102
|
-
- `evalexpr <expression>` - returns the result of the given single expression.
|
|
103
|
-
It's effectively your expression with `return` prepended, allowing syntax like `1+3`
|
|
104
|
-
or `width * size`
|
|
105
|
-
without having to type `return width * size`. That can cause issues if you need
|
|
106
|
-
to execute a lot of code, but always workaroundable with something like,
|
|
107
|
-
`evelexpr "(function() ... end)()"`.
|
|
108
|
-
- `status` - return runtime & loaded cart status. see below.
|
|
109
|
-
- `listglobals` - returns a single-line, comma-separated list of eval-able
|
|
110
|
-
global symbols (identifier keys from the Lua global environment).
|
|
111
|
-
- `typeschema <symbol>` - returns a type schema of the specified global symbol. see below.
|
|
112
|
-
- `getfps` - gets current FPS
|
|
113
|
-
- `cartpath` - returns the full path to the currently open cartridge.
|
|
114
|
-
empty string if there's no open cart.
|
|
115
|
-
- `fs` - returns the current filesystem local path (the one you can control via command line `--fs=...`)
|
|
116
|
-
- `perf` - returns current live performance metrics. see below for response
|
|
117
|
-
- `metadata <key>` - returns the value for the metadata value in code.
|
|
118
|
-
See: https://github.com/nesbox/TIC-80/wiki/Cartridge-Metadata.
|
|
119
|
-
- `lua_profiler_start <mode> <instructionInterval> <wallClockPeriodMicros> <seconds?> <output_path?>` - Starts a
|
|
120
|
-
Lua performance profiling session. See below for performance profiler instructions.
|
|
121
|
-
- `lua_profiler_stop <output_path>`. Stops the profiler and writes the output to the optional
|
|
122
|
-
specified path (otherwise one is auto-generated)
|
|
123
|
-
See below for performance profiler instructions.
|
|
124
|
-
- `lua_profiler_status` - returns the status of the lua profiler
|
|
125
|
-
- `event_subscribe <event_type|event_type> <enabled:1|0>` - set client subscription status for event types.
|
|
126
|
-
Specify the event types to affect; they can be combined with pipe char `|`. Enable subscription to the
|
|
127
|
-
types with `1`; `0` will unsubscribe. Event types that aren't specified here are unaffected.
|
|
128
|
-
Example: `0 event_subscribe "trace|cart_run" 1` enables
|
|
129
|
-
receiving `trace()` and cart run events pushed from server to client (and other event types remain unaffected)
|
|
130
|
-
- datatypes
|
|
131
|
-
- numbers (integral, negative, decimal)
|
|
132
|
-
- No fancy `1e3` forms
|
|
133
|
-
- integral: `1` `0` `24` `-1000`
|
|
134
|
-
- decimal: `1.011` `.1` `-123.456` `.1`
|
|
135
|
-
- leading `0` not necessary (`.1` is valid; `0.1` is also valid)
|
|
136
|
-
- trailing decimal supported (`1.` is valid)
|
|
137
|
-
- decimal on its own (no leading 0 + trailing decimal) is an error (`.`)
|
|
138
|
-
- hex `0xff` `-0x1` (always integral, prefix with `0x`).
|
|
139
|
-
- strings
|
|
140
|
-
- always require double quotes, ASCII-only, escape char is `\`.
|
|
141
|
-
- binary, enclosed in `<` and `>`.
|
|
142
|
-
- example: `<ff 22 00>`
|
|
143
|
-
- string syntax: always hexadecimal.
|
|
144
|
-
- whitespace is ignored so `<ff2200>` or `<f f220 0>` are equivalent to `<ff 22 00>`
|
|
145
|
-
- response
|
|
146
|
-
- datatypes follow same convention as requests
|
|
147
|
-
- `<id> <status> <data...>`
|
|
148
|
-
- `id` is the same ID as the request. no checking is done on this, you can
|
|
149
|
-
send the same id always and the server doesn't care.
|
|
150
|
-
- `status` is either `OK` or `ERR`
|
|
151
|
-
- data is defined by the command, but is similar to the request args.
|
|
152
|
-
- `1 ping` => `1 OK PONG`
|
|
153
|
-
- `44 sync 24` => `44 OK`
|
|
154
|
-
- `xx` => `0 ERR "error description here"`
|
|
155
|
-
- events (pushed from server to client): `<-id> <eventtype> <data...>`
|
|
156
|
-
- server can send event messages to the client using similar message format. The
|
|
157
|
-
message id is a negative integer (e.g. `-243`). Datatype syntax remains.
|
|
158
|
-
Note that clients will only receive event types they subscribe to via `event_subscribe`
|
|
159
|
-
explicitly; by default clients do not receive any events. Event subscription is
|
|
160
|
-
per-client; if client A subscribes, then only it receives the event; it doesn't
|
|
161
|
-
affect other clients. No guarantees are made about ids being in a particular order,
|
|
162
|
-
having gaps, or duplicates (though reasonably speaking there won't be duplicates due to int64 numeric range).
|
|
163
|
-
Examples of received events:
|
|
164
|
-
- `-1 trace "hello from tic80"` sent for all `trace()` Lua calls.
|
|
165
|
-
- `-2 cart_run` sent when cart is launched / game is run (ctrl+R)
|
|
166
|
-
- `-3 lua_profiler_stopped` sent when the lua profiler finishes
|
|
167
|
-
- (this is the only one supported so far)
|
|
168
|
-
- Commands to be queued and executed at a deterministic safe point in the
|
|
169
|
-
TIC-80 system loop (e.g., between frames if the cart is running)
|
|
170
|
-
|
|
171
|
-
# `perf` command
|
|
172
|
-
|
|
173
|
-
returns a single-line, comma-separated, `key=value` pairs.
|
|
174
|
-
|
|
175
|
-
## keys
|
|
176
|
-
|
|
177
|
-
- `client_count` integer; number of clients connected to remoting
|
|
178
|
-
- `fps` current capped FPS from the rolling window tracker, floating-point (e.g. `59.95`, `60`)
|
|
179
|
-
- `fps_uncapped` estimated uncapped FPS derived from `total_ms`, integral.
|
|
180
|
-
- `tic_ms` time spent in TIC, in milliseconds quantized to `0.1ms`.
|
|
181
|
-
- `scn_ms`
|
|
182
|
-
- `bdr_ms`
|
|
183
|
-
- `total_ms` total time spent in TIC+SCN+BDR, in milliseconds quantized to `0.1ms`.
|
|
184
|
-
- `tic_cycles` number of Lua VM cycles spent in TIC. integral.
|
|
185
|
-
- `scn_cycles`
|
|
186
|
-
- `bdr_cycles`
|
|
187
|
-
- `total_cycles`
|
|
188
|
-
- `lua_gc_mem` - lua's gc memory usage, in bytes (integral)
|
|
189
|
-
|
|
190
|
-
Timing values are measured as fixed-point `ms10` internally, so all `*_ms` values
|
|
191
|
-
are rounded to the nearest `0.1ms` before being exposed. `fps_uncapped` is
|
|
192
|
-
derived from that quantized `total_ms` value, so it is approximate and becomes
|
|
193
|
-
coarser at very high frame rates.
|
|
194
|
-
|
|
195
|
-
# Discovery Protocol
|
|
196
|
-
|
|
197
|
-
When the remoting server is listening, we will make the server discoverable by
|
|
198
|
-
placing a json file on the filesystem.
|
|
199
|
-
|
|
200
|
-
If the file already exists, it shall be overwritten.
|
|
201
|
-
|
|
202
|
-
The file is to be deleted when the server stops listening.
|
|
203
|
-
|
|
204
|
-
The global file will be placed in `%LOCALAPPDATA%\TIC-80\remoting\sessions\` and
|
|
205
|
-
the file is to be named `tic80-remote.<pid>.json`. Its contents will look like,
|
|
206
|
-
|
|
207
|
-
```json
|
|
208
|
-
{
|
|
209
|
-
"pid": 1234,
|
|
210
|
-
"host": "127.0.0.1",
|
|
211
|
-
"port": 51000,
|
|
212
|
-
"startedAt": "2026-01-31T19:50:26.859Z",
|
|
213
|
-
"remotingVersion": "v1"
|
|
214
|
-
}
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
- `remotingVersion` is the same as in the `hello` command.
|
|
218
|
-
|
|
219
|
-
We also must support a new command line arg, for specifying where to output the
|
|
220
|
-
remote session file.
|
|
221
|
-
|
|
222
|
-
`tic80.exe --remote-session-location=c:\my\folder`
|
|
223
|
-
|
|
224
|
-
will write the discovery file as `c:\my\folder\tic80-remote.<pid>.json`
|
|
225
|
-
|
|
226
|
-
The global discovery location (under `%LOCALAPPDATA%`) is written unless disabled
|
|
227
|
-
with the `--global-disco=OFF|ON` command line arg. It is `ON` by default. The
|
|
228
|
-
user-specified `--remote-session-location` file is always written regardless of
|
|
229
|
-
the global flag.
|
|
230
|
-
|
|
231
|
-
example:
|
|
232
|
-
|
|
233
|
-
`tic80.exe --remote-session-location=c:\my\folder --global-disco=OFF`
|
|
234
|
-
|
|
235
|
-
writes the remote session file to `c:\my\folder`
|
|
236
|
-
|
|
237
|
-
# `typeschema <symbol>`
|
|
238
|
-
|
|
239
|
-
Returns the type schema of the specified global symbol. For simple values it's
|
|
240
|
-
the same as Lua's keyword `type(x)`. So it can return:
|
|
241
|
-
|
|
242
|
-
- `string`
|
|
243
|
-
- `number`
|
|
244
|
-
- `function`
|
|
245
|
-
- `boolean`
|
|
246
|
-
- `nil`
|
|
247
|
-
|
|
248
|
-
However for tables
|
|
249
|
-
|
|
250
|
-
- `table`
|
|
251
|
-
|
|
252
|
-
# code structure
|
|
253
|
-
|
|
254
|
-
changes to existing "official" TIC-80 code to be surgical and minimal. put our own
|
|
255
|
-
sources under `/src/ticbuild_remoting`.
|
|
256
|
-
|
|
257
|
-
# performance profiler
|
|
258
|
-
|
|
259
|
-
Want to see which Lua functions or lines are causing performance issues? The
|
|
260
|
-
following remoting commands can be used to record stack trace samples to eventually
|
|
261
|
-
view in as a flame graph.
|
|
262
|
-
|
|
263
|
-
`lua_profiler_start <mode> <instructionInterval> <wallClockPeriodMicros> <seconds?> <output_path?>`
|
|
264
|
-
|
|
265
|
-
Starts a Lua performance profiling session.
|
|
266
|
-
|
|
267
|
-
- `mode` can be:
|
|
268
|
-
- `instructions`: samples are collected every `<instructionInterval>` Lua instructions.
|
|
269
|
-
- `wallclock`: samples are collected every `<wallClockPeriodMicros>` microseconds
|
|
270
|
-
(1000 micros = 1 millisecond). Because of the way we sample the Lua runtime,
|
|
271
|
-
`<instructionInterval>` is still used here.
|
|
272
|
-
- `seconds` is optional and specifies the # of seconds to profile for. After this # of
|
|
273
|
-
seconds has elapsed, profiling stops automatically on the next regular update/frame poll.
|
|
274
|
-
- `output_path` has the same semantics as `lua_profiler_stop`. Optional; and only
|
|
275
|
-
used when `seconds` is specified. If not specified, auto-stop will choose an auto
|
|
276
|
-
temp file path.
|
|
277
|
-
|
|
278
|
-
When `seconds` is specified, the `lua_profiler_start` response includes the reserved
|
|
279
|
-
save path immediately, for example:
|
|
280
|
-
|
|
281
|
-
`auto_stop=1,duration=12,output_path="C:\\Users\\you\\AppData\\Local\\Temp\\tic80-lua-profiler-1234.txt"`
|
|
282
|
-
|
|
283
|
-
When `seconds` is omitted, the response is:
|
|
284
|
-
|
|
285
|
-
`auto_stop=0`
|
|
286
|
-
|
|
287
|
-
Notes:
|
|
288
|
-
|
|
289
|
-
- It is an error to start a session when one is already running
|
|
290
|
-
- It is an error to stop a session when one is not running.
|
|
291
|
-
- It is not defined how the profiler acts when reloading/stopping/pausing etc. Don't bother handling these scenarios explicitly; that's on the user.
|
|
292
|
-
|
|
293
|
-
Once profiling is started, the title bar will indicate that profiling is active.
|
|
294
|
-
|
|
295
|
-
`TIC-80 | 60/60 fps | 55 + 3 = 58 kcyc | 1.2 ms | 100 kb | listening on 127.0.0.1:55555 (1 client) | PROFILING... 12s`
|
|
296
|
-
|
|
297
|
-
To stop profiling and collect the data, call
|
|
298
|
-
|
|
299
|
-
`lua_profiler_stop <output_path>`.
|
|
300
|
-
|
|
301
|
-
Stops the profiler and writes the output to the specified path. If no path is specified,
|
|
302
|
-
a temp path is chosen. The response will indicate the saved file path.
|
|
303
|
-
|
|
304
|
-
`lua_profiler_status`
|
|
305
|
-
|
|
306
|
-
returns the status of the lua profiler. single-line, comma-separated, `key=value` pairs.
|
|
307
|
-
|
|
308
|
-
examples:
|
|
309
|
-
|
|
310
|
-
```
|
|
311
|
-
running=0,auto_stop=0
|
|
312
|
-
running=1,auto_stop=0,mode=instructions,instruction_interval=1000,elapsed_seconds=12
|
|
313
|
-
running=1,auto_stop=1,mode=wallclock,instruction_interval=1000,wall_clock_period_micros=10,elapsed_seconds=12,duration=30,remaining_seconds=18,output_path="C:\\Users\\you\\AppData\\Local\\Temp\\tic80-lua-profiler-1234.txt"
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
## `instructions` vs. `wallclock` mode
|
|
317
|
-
|
|
318
|
-
Lua instructions are a host-agnostic way to measure performance. If you're working on a team
|
|
319
|
-
of people with different computer specs, you cannot for example compare FPS values.
|
|
320
|
-
In this case Lua instructions (or kcycles as in the title bar) is an objective cross-host
|
|
321
|
-
metric.
|
|
322
|
-
|
|
323
|
-
Just be aware that not all instructions are made equal, so there are cases where
|
|
324
|
-
you optimize for kcycles but actual Windows host performance is worse.
|
|
325
|
-
|
|
326
|
-
For profiling on your own machine against your own metrics during development,
|
|
327
|
-
`wallclock` can be more useful. It measures the actual host time spent. So while
|
|
328
|
-
it is the actual metric that says "this is running faster", it's not consistent because
|
|
329
|
-
it depends on the environment: if another process is hogging CPU, or if you run
|
|
330
|
-
in a VM etc, you cannot compare the values anymore.
|
|
331
|
-
|
|
332
|
-
Further note about difficulties in measuring `wallclock`: we use `lua_getstack` and `lua_getinfo`,
|
|
333
|
-
which cannot be run at arbitrary times. We therefore use `lua_sethook`, but this
|
|
334
|
-
operates on a lua instruction count basis, not host clock. So in order to sample
|
|
335
|
-
at host clock intervals, we use `lua_sethook` but on a tight-ish interval,
|
|
336
|
-
and check if a sample is due. If not, return. If it's due, collect the sample.
|
|
337
|
-
|
|
338
|
-
This means some kind of jitter can cause slight noise, but that's not expected
|
|
339
|
-
to be an issue over thousands of collections.
|
|
340
|
-
|
|
341
|
-
Jitter can even be a good thing in profiling because some natural code loops/cadences
|
|
342
|
-
can accidentally line up with the sampling cadence. Apparently most profilers
|
|
343
|
-
introduce some strategic jitter to ensure this is accounted for. Not sure our kind
|
|
344
|
-
of jitter would be the good kind or not.
|
|
345
|
-
|
|
346
|
-
## Stats collection
|
|
347
|
-
|
|
348
|
-
We're going to collect stats in the least intrusive way possible. We are expecting
|
|
349
|
-
a lot of hits for certain paths, so a map-like structure is expected here. Better
|
|
350
|
-
to defer any processing (like mapping stack trace to symbols/source file:line etc)
|
|
351
|
-
until when the session is ended, to avoid affecting runtime.
|
|
352
|
-
|
|
353
|
-
As tempting as it is to introduce C++, let's stay in C for consistency.
|
|
354
|
-
|
|
355
|
-
## Output format
|
|
356
|
-
|
|
357
|
-
The output is a plain text file that can be imported to [speedscope](https://github.com/jlfwong/speedscope/).
|
|
358
|
-
|
|
359
|
-
In particular the "Brendan Gregg" format is fine for us. Just line-based plain text,
|
|
360
|
-
each line has a semi-colon delimited stack frames and integral sample count at the end.
|
|
361
|
-
|
|
362
|
-
```
|
|
363
|
-
main;a;b;c 1
|
|
364
|
-
main;a;b;c 1
|
|
365
|
-
main;a;b;d 4
|
|
366
|
-
main;a;b;c 3
|
|
367
|
-
main;a;b 5
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
## Integration with existing system
|
|
371
|
-
|
|
372
|
-
`lua_sethook` I believe just handles one hook at a time. It's not some kind of hook chain;
|
|
373
|
-
the interval needs to be chosen for the hook and the profiling hook will want
|
|
374
|
-
a different cadence than the default hook.
|
|
375
|
-
|
|
376
|
-
It means either we disable the exsiting perf hook during profiling, or we find a
|
|
377
|
-
way to synergize. Disabling existing hook is impossible because it's important information
|
|
378
|
-
even during profiling.
|
|
379
|
-
|
|
380
|
-
The existing hook interval is `TB_LUA_HOOK_STEP = 1000`.
|
|
381
|
-
|
|
382
|
-
## Example
|
|
383
|
-
|
|
384
|
-
**First, be running this fork of TIC-80 with a cart**
|
|
385
|
-
|
|
386
|
-
**Launch remote terminal**
|
|
387
|
-
|
|
388
|
-
easiest way is
|
|
389
|
-
|
|
390
|
-
```
|
|
391
|
-
> ticbuild terminal
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
which will automatically connect, via the discovery protocol
|
|
395
|
-
|
|
396
|
-
**Begin profiling**
|
|
397
|
-
|
|
398
|
-
Let's do a timed 10-second profile...
|
|
399
|
-
|
|
400
|
-
```
|
|
401
|
-
0 lua_profiler_start "wallclock" 1000 50 4
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
Which returns:
|
|
405
|
-
|
|
406
|
-
```
|
|
407
|
-
0 OK auto_stop=1,duration=4,output_path="C:\\Users\\carl\\AppData\\Local\\Temp\\tic80-lua-profiler-34672.txt"
|
|
408
|
-
```
|
|
409
|
-
|
|
410
|
-
This samples on a host time cadence, checking every 1000 lua instructions if the
|
|
411
|
-
50 microsecond sample is due.
|
|
412
|
-
|
|
413
|
-
Sample collection happens over 4 seconds, and then stops automatically, placing the
|
|
414
|
-
file. This is done silently; remoting clients don't get a notification that profiling has
|
|
415
|
-
stopped.
|
|
416
|
-
|
|
417
|
-
**Checking on status**
|
|
418
|
-
|
|
419
|
-
```
|
|
420
|
-
0 lua_profiler_status
|
|
421
|
-
```
|
|
422
|
-
|
|
423
|
-
While the auto-stopping profile session is capturing, the response can be like,
|
|
424
|
-
|
|
425
|
-
```
|
|
426
|
-
0 OK running=1,auto_stop=1,mode=wallclock,instruction_interval=1000,
|
|
427
|
-
wall_clock_period_micros=50,elapsed_seconds=1,duration=4,remaining_seconds=3,
|
|
428
|
-
output_path="C:\\Users\\carl\\AppData\\Local\\Temp\\tic80-lua-profiler-34672.txt"
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
Notably, `remaining_seconds` can be used by clients to know how much time
|
|
432
|
-
is left in the capture session.
|
|
433
|
-
|
|
434
|
-
Also note: output_path is not sticky; after the file is written, this status goes back
|
|
435
|
-
to:
|
|
436
|
-
|
|
437
|
-
```
|
|
438
|
-
> 0 lua_profiler_status
|
|
439
|
-
0 OK running=0,auto_stop=0
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
# `status` command
|
|
443
|
-
|
|
444
|
-
Similar to `perf`, returns a single-line, comma-separated, `key=value` pairs.
|
|
445
|
-
|
|
446
|
-
## keys
|
|
447
|
-
|
|
448
|
-
- `cart_loaded_at` timestamp when the current cartridge was loaded. `0` if there's no cart.
|
|
449
|
-
- `cart_last_launch_at` timestamp when the cart was last launched (ignores pausing/resuming).
|
|
450
|
-
if never launched, `0`. Also this resets when cart changes.
|
|
451
|
-
- `now` current wall clock timestamp; for reference / sanity check against the other fields
|
|
452
|
-
- `process_started_at` timestamp when this process was started.
|
|
453
|
-
- `pid` the pid of the this process
|
|
454
|
-
|
|
455
|
-
Timestamps are unix epoch.
|
|
456
|
-
|
|
457
|
-
Hosts can use `cart_loaded_at` and `cart_last_launch_at` to guarantee if the
|
|
458
|
-
cart has changed (note that changing Lua code requires a relaunch).
|
|
459
|
-
|
|
460
|
-
```
|
|
461
|
-
> 0 status
|
|
462
|
-
0 OK cart_loaded_at=1767225600123,cart_last_launch_at=1767225600456,now=1767225610000,process_started_at=1767225600123,pid=1773
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
While serial generation counters would be theoretically more precise, timestamps
|
|
466
|
-
are just simpler in code (`ts = time()` instead of `gen = existing_gen + 1`).
|
|
467
|
-
|
|
468
|
-
Generation is also problematic if you ever compare across sessions. We want that
|
|
469
|
-
`cart_loaded_at` is _always_ different on a different cart load, no matter which
|
|
470
|
-
tic-80 instance did it. Simplifies client logic.
|