Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ modavd [--root <dir>] [--json] [--quiet] [--verbose] <command> [args]
| --- | --- |
| `list` | All instances and their status |
| `info <i>` / `status <i>` | Details of one instance / its status |
| `create [--index N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto\|N] [--fps 1-60] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--no-bridge] [--timeout 1200]`, `create --resume N` | Create an instance (automatic data disk by default, see below), then start it once in the background, headless, to finish initialization, and shut it down (see below). The arm64 execution bridge is included by default; `--no-bridge` records that this instance does not want the bridge, so it is not installed on later starts either. New instances never get the Google Play Store; add it afterwards with `playstore <i> install`. `--resume N` redoes the initialization of an instance whose creation failed |
| `set <i> [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--data-gb auto\|N] [--diagnostics on\|off] [--sound on\|off] [--app-keepalive on\|off] [--boss-key combination\|none]` | Change settings. Diagnostics and the boss key apply immediately; other settings take effect at the next start. `--data-gb auto` makes the data disk automatic, `--data-gb N` gives it a fixed size (see below); the size can only be increased, and game data is untouched: the emulator (from 0.36) grows the disk image at start and grows the file system online after boot. A disk created before 0.36 at 16 GB or smaller can only be grown to just below the next backup group (a 16 GB disk to about 30 GB). `--sound on` gives this instance sound from its next start (windowed and headless, at some extra CPU); the default `off` boots without a sound card; stored as `instances.<i>.sound` in `mas-avd.json`. `--boss-key` is this instance's boss key (see the ModAVD.exe manager section), for example `Ctrl+Alt+Shift+1`; `none` means no boss key; Windows only. |
| `create [--index N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto\|N] [--fps 15\|30\|60] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--no-bridge] [--timeout 1200]`, `create --resume N` | Create an instance (automatic data disk by default, see below), then start it once in the background, headless, to finish initialization, and shut it down (see below). The arm64 execution bridge is included by default; `--no-bridge` records that this instance does not want the bridge, so it is not installed on later starts either. New instances never get the Google Play Store; add it afterwards with `playstore <i> install`. `--resume N` redoes the initialization of an instance whose creation failed |
| `set <i> [--title T] [--memory M] [--cpu N] [--fps 15\|30\|60] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--data-gb auto\|N] [--diagnostics on\|off] [--sound on\|off] [--app-keepalive on\|off] [--boss-key combination\|none]` | Change settings. Diagnostics and the boss key apply immediately; other settings take effect at the next start. `--data-gb auto` makes the data disk automatic, `--data-gb N` gives it a fixed size (see below); the size can only be increased, and game data is untouched: the emulator (from 0.36) grows the disk image at start and grows the file system online after boot. A disk created before 0.36 at 16 GB or smaller can only be grown to just below the next backup group (a 16 GB disk to about 30 GB). `--sound on` gives this instance sound from its next start (windowed and headless, at some extra CPU); the default `off` boots without a sound card; stored as `instances.<i>.sound` in `mas-avd.json`. `--boss-key` is this instance's boss key (see the ModAVD.exe manager section), for example `Ctrl+Alt+Shift+1`; `none` means no boss key; Windows only. |
| `proxy <i> [on\|off\|test] [--server URL\|auto] [--add PKG] [--remove PKG] [--apps PKG]` | Per-app proxy: the listed apps go through a proxy, the others direct (see below) |
| `delete <i> --yes` | Delete a stopped instance, together with its game data |
| `clone <i> [--title T]` | Copy a stopped instance whole into a new one (games, logins and settings included): the new one takes the smallest free index and its ports, everything else follows the source. The data disk is copied whole, so the two do not affect each other; without enough free space the command fails (`precheck_failed`) and copies nothing, and a failed or canceled copy is deleted. Both have the same Android device IDs (Android ID, GSF ID) |
Expand All @@ -87,7 +87,7 @@ The instance setting **Keep background apps** takes effect at the next boot. Wit

Apple Silicon macOS supports `report-config` and `collect-info`, including hardware, macOS, HVF, Metal and component versions. Game lists are queried only through an existing private ADB server and running instances with verified ownership; no service is started. The package contains an allowlist of local instance settings and at most eight emulator logs, capped at 2 MiB each and 20 MiB of text in total. Common credential fields, paths and device identifiers are filtered. macOS does not collect screenshots, system dumps or other applications' logs. Review the package before sharing it. Clipboard copying and Finder reveal can be disabled with `--no-clipboard` and `--no-explorer`.

- Write `<i>` as `3` or `mas_3` (0-9, except 5). Memory is written as `6144`, `6144M` or `6G`, with only five tiers: 3 / 4 / 5 / 6 / 8 GB. Cores are 2 / 4 / 6, and the frame rate is any whole number from 1 to 60 (default 60).
- Write `<i>` as `3` or `mas_3` (0-9, except 5). Memory is written as `6144`, `6144M` or `6G`, with only five tiers: 3 / 4 / 5 / 6 / 8 GB. Cores are 2 / 4 / 6, and the frame rate has three steps, 15 / 30 / 60 (default 60; 30 for games locked at 30 fps, the most even frame times; 15 only for idling, the whole system runs at 15 fps). Another frame rate given on the command line, over MCP or the HTTP API is not refused: it goes to the nearest step below (31-59 becomes 30, 16-29 becomes 15, 1-14 becomes 15, above 60 becomes 60) and the output says so. An instance set to another value earlier is changed the same way at its next start, with a line in the log.
- Root folder: `--root`; if not given, the environment variable `MODAVD_ROOT`; otherwise the folder containing `modavd.exe`, or its parent.
- From 0.3.0 there is no `restart`: `stop`, then `start`. An old call gets a usage error (exit code 2) that says so.

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ modavd [--root <目录>] [--json] [--quiet] [--verbose] <命令> [参数]
| --- | --- |
| `list` | 全部实例和状态 |
| `info <i>` / `status <i>` | 一台实例的详细信息 / 状态 |
| `create [--index N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto\|N] [--fps 1-60] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--no-bridge] [--timeout 1200]`、`create --resume N` | 新建(数据盘默认自动扩盘,见下),并在后台无头开机一次把初始化做完再关机(见下)。默认带 arm64 执行桥;`--no-bridge` 记下这台不要桥,以后开机也不装。新建的实例不带 Google Play 商店,要的话建好后用 `playstore <i> install`。`--resume N` 重做新建失败的那台的初始化 |
| `set <i> [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--data-gb auto\|N] [--diagnostics on\|off] [--sound on\|off] [--app-keepalive on\|off] [--boss-key 组合\|none]` | 修改;诊断模式和老板键立即生效,其余设置下次开机生效。`--data-gb auto` 改成自动扩盘,`--data-gb N` 改成指定大小(见下);大小只能改大,游戏数据不动:模拟器(0.36 起)开机时扩磁盘镜像,开机后在线扩文件系统。0.36 之前按 16 GB 及以下建的盘只能扩到下一个备份组之前(16 GB 约到 30 GB)。`--sound on` 让这台下次开机起有声音(带窗口和无头都是,会多占一些 CPU),默认 `off` 不带声卡;记在 `mas-avd.json` 的 `instances.<i>.sound`。`--boss-key` 是这台的老板键(见「管理器 ModAVD.exe」一节),比如 `Ctrl+Alt+Shift+1`,`none` 是不要,只有 Windows。 |
| `create [--index N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto\|N] [--fps 15\|30\|60] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--no-bridge] [--timeout 1200]`、`create --resume N` | 新建(数据盘默认自动扩盘,见下),并在后台无头开机一次把初始化做完再关机(见下)。默认带 arm64 执行桥;`--no-bridge` 记下这台不要桥,以后开机也不装。新建的实例不带 Google Play 商店,要的话建好后用 `playstore <i> install`。`--resume N` 重做新建失败的那台的初始化 |
| `set <i> [--title T] [--memory M] [--cpu N] [--fps 15\|30\|60] [--resolution 1080\|720] [--dpi auto\|N] [--orientation landscape\|portrait] [--data-gb auto\|N] [--diagnostics on\|off] [--sound on\|off] [--app-keepalive on\|off] [--boss-key 组合\|none]` | 修改;诊断模式和老板键立即生效,其余设置下次开机生效。`--data-gb auto` 改成自动扩盘,`--data-gb N` 改成指定大小(见下);大小只能改大,游戏数据不动:模拟器(0.36 起)开机时扩磁盘镜像,开机后在线扩文件系统。0.36 之前按 16 GB 及以下建的盘只能扩到下一个备份组之前(16 GB 约到 30 GB)。`--sound on` 让这台下次开机起有声音(带窗口和无头都是,会多占一些 CPU),默认 `off` 不带声卡;记在 `mas-avd.json` 的 `instances.<i>.sound`。`--boss-key` 是这台的老板键(见「管理器 ModAVD.exe」一节),比如 `Ctrl+Alt+Shift+1`,`none` 是不要,只有 Windows。 |
| `proxy <i> [on\|off\|test] [--server URL\|auto] [--add 包名] [--remove 包名] [--apps 包名]` | 按应用走代理:名单里的应用走代理,其余直连(见下) |
| `delete <i> --yes` | 删除已关机的实例,连同游戏数据 |
| `clone <i> [--title T]` | 把已关机的实例整份复制成一台新实例(游戏、登录状态、设置都带上):新实例用最小的空闲编号和它的端口,其余设置照源实例;数据盘整份复制,两台互不影响,可用空间不够时报错(`precheck_failed`)、什么都不复制;失败或取消时复制到一半的会删掉。两台的安卓设备标识(Android ID、GSF ID)相同 |
Expand All @@ -89,7 +89,7 @@ modavd [--root <目录>] [--json] [--quiet] [--verbose] <命令> [参数]

Apple Silicon macOS 支持 `report-config` 和 `collect-info`:读取硬件、macOS、HVF、Metal 和组件版本;游戏列表只向归属已确认的运行实例与现有私有 ADB 查询,不启动服务。问题包只收本目录的实例配置白名单和最多 8 份模拟器日志,每份最多 2 MiB、总文本最多 20 MiB,过滤常见凭据字段、路径和设备标识。macOS 不收截图、系统转储或其他应用日志;分享前请检查问题包。默认复制配置到剪贴板、用 Finder 显示问题包,自动化可用 `--no-clipboard` / `--no-explorer`。

- `<i>` 写成 `3` 或 `mas_3`(0–9,5 除外);内存写成 `6144`、`6144M` 或 `6G`,只有 3 / 4 / 5 / 6 / 8 GB 五档,核数 2 / 4 / 6,帧率 1–60 的整数(默认 60)。
- `<i>` 写成 `3` 或 `mas_3`(0–9,5 除外);内存写成 `6144`、`6144M` 或 `6G`,只有 3 / 4 / 5 / 6 / 8 GB 五档,核数 2 / 4 / 6,帧率 15 / 30 / 60 三档(默认 60;30 给锁 30 帧的游戏,帧间隔最匀;15 只适合纯挂机,整个系统都是 15 帧)。命令行、MCP、HTTP 接口给了别的帧率不报错,落到往下最近的一档(31–59 取 30,16–29 取 15,1–14 取 15,高于 60 取 60),并在输出里说明;以前设成别的值的实例,下次开机时自动改成这样取到的一档并记一行日志。
- 根目录:`--root`,没给就用环境变量 `MODAVD_ROOT`,再没有就用 `modavd.exe` 所在目录或它的上一级。
- 0.3.0 起没有 `restart`:先 `stop` 再 `start`。旧的调用报用法错误(退出码 2),提示改用这两步。

Expand Down
2 changes: 2 additions & 0 deletions changelog.d/286-fps-steps.change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
帧率只有 15 / 30 / 60 三档,原来设的其他值开机时自动调整(比如 36 调成 30) (ModAVD/ModAVD#286)
Frame rate has three steps, 15 / 30 / 60; another value set earlier is changed at the next start (36 becomes 30)
87 changes: 73 additions & 14 deletions internal/avd/avd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ var (
DPIChoices = []int{160, 240, 280, 320, 400, 480}
// OrientationChoices: landscape (the default; what AUTO-MAS and MAA expect) or portrait (the same wide canvas, turned).
OrientationChoices = []string{OrientationLandscape, OrientationPortrait}
// FPSChoices are the frame rates an instance can have (ModAVD/ModAVD#286): 60 (the default), 30 for games locked
// at 30 (every frame shown for the same time; at 36 or 45 they alternate one and two refreshes), 15 for idling.
FPSChoices = []int{60, 30, 15}
)

const (
Expand All @@ -46,7 +49,8 @@ const (
DefaultMemoryMB = 6144
DefaultCPU = 6
DefaultFPS = 60
// Any whole frame rate in MinFPS..MaxFPS (ModAVD#180); written as hw.lcd.vsync.
// The frame rate (hw.lcd.vsync, the display's refresh rate) is one of FPSChoices (ModAVD/ModAVD#286; 1–60 since
// ModAVD#180 before that). Any other value from MinFPS up is taken to a step (SnapFPS), above MaxFPS to MaxFPS.
MinFPS = 1
MaxFPS = 60
// AutoDataPartitionGB is the data partition of an instance whose data disk grows by itself (自动扩盘, the default,
Expand Down Expand Up @@ -316,11 +320,13 @@ func parseRAMSize(raw string) (int, bool) {
func (in *Instance) MemoryMB() (int, bool) { return parseRAMSize(in.Config.Value("hw.ramSize")) } // 4096 / 4096M / 4096MB / 4G
func (in *Instance) CPU() (int, bool) { return intOrNone(in.Config.Value("hw.cpu.ncore")) } // hw.cpu.ncore

// FPS is hw.lcd.vsync, DefaultFPS when absent / bad (and when 0: AUTO-MAS writes `or DEFAULT_FPS`); the emulator
// boots at 60 Hz without the key.
func (in *Instance) FPS() int {
if v, ok := intOrNone(in.Config.Value("hw.lcd.vsync")); ok && v != 0 {
return v
// FPS is hw.lcd.vsync taken to its step (SnapFPS; the next boot writes that, ApplyFPS), DefaultFPS when absent / bad /
// below 1 (and when 0: AUTO-MAS writes `or DEFAULT_FPS`); the emulator boots at 60 Hz without the key.
func (in *Instance) FPS() int { return fpsFor(in.Config) }

func fpsFor(cfg *Ini) int {
if v, ok := intOrNone(cfg.Value("hw.lcd.vsync")); ok && v >= MinFPS {
return SnapFPS(v)
}
return DefaultFPS
}
Expand Down Expand Up @@ -605,16 +611,36 @@ func ValidateOptions(memoryMB, cpu, dataGB *int) (int, int, int, error) {
return memory, cores, data, nil
}

// ValidateFPS: nil means DefaultFPS; anything outside MinFPS..MaxFPS is errs.InvalidArgument.
func ValidateFPS(fps *int) (int, error) {
value := DefaultFPS
// SnapFPS is the step of FPSChoices a frame rate of at least MinFPS falls to (ModAVD/ModAVD#286): down to the nearest
// step (31–59 -> 30, 16–29 -> 15), 1–14 up to 15, above MaxFPS MaxFPS.
func SnapFPS(v int) int {
switch {
case v >= 60:
return 60
case v >= 30:
return 30
}
return 15
}

// FPSAdjusted is the note said when a frame rate was moved to a step: "帧率 36 已调整为 30(只有 15 / 30 / 60 三档)".
func FPSAdjusted(from, to int) string {
return fmt.Sprintf("帧率 %d 已调整为 %d(只有 15 / 30 / 60 三档)", from, to)
}

// ValidateFPS: nil means DefaultFPS; below MinFPS is errs.InvalidArgument; any other value is taken to its step
// (SnapFPS) without an error, so a tool that still writes another frame rate keeps working. adjusted: the value given
// was not one of FPSChoices.
func ValidateFPS(fps *int) (value int, adjusted bool, err error) {
value = DefaultFPS
if fps != nil {
value = *fps
}
if value < MinFPS || value > MaxFPS {
return 0, errs.Newf(errs.InvalidArgument, "帧率只能在 %d–%d 之间", MinFPS, MaxFPS)
if value < MinFPS {
return 0, false, errs.Newf(errs.InvalidArgument, "帧率只能是 15、30 或 60")
}
return value, nil
snapped := SnapFPS(value)
return snapped, snapped != value, nil
}

// ValidateResolution defaults new instances to 1080p; DPI is part of the preset.
Expand Down Expand Up @@ -705,7 +731,7 @@ func Create(r *root.Root, i int, opt CreateOptions) (*Instance, error) {
if err != nil {
return nil, err
}
fps, err := ValidateFPS(&opt.FPS)
fps, _, err := ValidateFPS(&opt.FPS)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1009,7 +1035,7 @@ func Update(r *root.Root, i int, opt UpdateOptions) (map[string]any, error) {
}
var fps int
if opt.FPS != nil {
if fps, err = ValidateFPS(opt.FPS); err != nil {
if fps, _, err = ValidateFPS(opt.FPS); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -1323,3 +1349,36 @@ func ApplyDisplay(r *root.Root, i int) (bool, error) {
}
return true, nil
}

// ApplyFPS takes a frame rate that is not one of FPSChoices (an instance from before ModAVD/ModAVD#286 set to 36, or
// a tool that wrote config.ini itself) to its step (SnapFPS) in config.ini: from is the value found, to the one
// written, wrote whether it wrote. An absent, 0 or unreadable hw.lcd.vsync is left alone (the emulator boots at 60
// Hz, FPS says DefaultFPS). Only while stopped. Under the instance's root.LockInstanceConfig, like Update.
func ApplyFPS(r *root.Root, i int) (from, to int, wrote bool, err error) {
l, noDir, err := lockInstance(r, i)
if err != nil {
return 0, 0, false, err
}
if noDir {
return 0, 0, false, configUnreadable(i, notFound(i))
}
defer l.Unlock()
path := ConfigPath(r, i)
cfg, err := ReadIni(path)
if err != nil || cfg.Len() == 0 {
return 0, 0, false, configUnreadable(i, err)
}
v, ok := intOrNone(cfg.Value("hw.lcd.vsync"))
if !ok || v < MinFPS {
return v, DefaultFPS, false, nil
}
to = SnapFPS(v)
if to == v {
return v, v, false, nil
}
cfg.Set("hw.lcd.vsync", strconv.Itoa(to))
if err := WriteIni(path, cfg); err != nil {
return v, to, false, err
}
return v, to, true, nil
}
Loading
Loading