iOS test port: phone build switches, PerfTest overlay, Codemagic workflow

A one-day port to measure a late night on an iPhone before committing to
touch controls (docs/ios-test-port.md).

- MobilePort: on phones (the "mobile" feature) no ToonLook (standard
  materials, Mobile renderer), 3D at 0.75 resolution scale, co-op hidden,
  microphone never opened, and leaving the app pauses. `-- --mobile` and
  `-- --perf-test` turn the same switches on for desktop.
- PerfTest (the iOS preset's "perf_test" feature): frame time, physics,
  render CPU and GPU readout, a per-night summary (avg, p99, worst), and
  tap buttons for night 20/30, unlock all, next phase, and a shield.
  CampaignDebug's jumps also work in that release build.
- iOS export preset (export project only; bundle
  com.oatmealgames.harvestseason, team 823T4Q2T3U), an opaque 1024 icon,
  filled privacy purpose strings, ETC2/ASTC import, landscape both ways.
- codemagic.yaml: Godot 4.7.2 export, signing, .ipa, TestFlight upload.

Graph update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-14 12:59:22 -04:00
parent f0059f2e80
commit 938a4124df
46 changed files with 65141 additions and 1881 deletions

View file

@ -88,6 +88,12 @@ func _unhandled_input(event: InputEvent) -> void:
s.strip()
## Whether the jumps (jump_morning, unlock_all) work: debug builds, and the iOS test build's
## release export (MobilePort.perf_test, PerfTest's buttons).
static func allowed() -> bool:
return OS.is_debug_build() or MobilePort.perf_test()
## Debug builds, in the morning review only: to the morning of the next (step 1) or previous
## (step -1) day, within the vacation. The farm stays as it is and nights_survived follows as
## night - 1. It's the campaign's own new-morning path (CampaignController.load_state with the
@ -98,7 +104,7 @@ func _unhandled_input(event: InputEvent) -> void:
## alone. Returns whether it moved.
func jump_morning(step: int) -> bool:
var s := campaign.state
if not OS.is_debug_build() or s.phase != CampaignController.Phase.MORNING or campaign.remote_request.is_valid():
if not allowed() or s.phase != CampaignController.Phase.MORNING or campaign.remote_request.is_valid():
return false
var night := clampi(s.night + step, 1, campaign.config.campaign_nights)
if night == s.night:
@ -122,7 +128,7 @@ func jump_morning(step: int) -> bool:
## it (the morning snapshot is retaken); later in the day a retry goes back to that morning
## without it. Nothing is saved until the next morning's autosave. Returns the levels it added.
func unlock_all() -> int:
if not OS.is_debug_build() or campaign.is_over() or campaign.remote_request.is_valid():
if not allowed() or campaign.is_over() or campaign.remote_request.is_valid():
return 0
var n := Upgrades.grant_all(campaign, sim.structures if sim != null else null)
if campaign.state.phase == CampaignController.Phase.MORNING:

View file

@ -26,8 +26,9 @@ var move_dead_zone := 0.2
var aim_dead_zone := 0.3
var fullscreen := false
var vsync := true
var pixel_size := 4
var resolution_scale := 1.0
## Phones (MobilePort) default to no pixel look, at three quarters of the screen's resolution.
var pixel_size := 1 if MobilePort.active() else 4
var resolution_scale := 0.75 if MobilePort.active() else 1.0
var show_tips := true
## Co-op: your name for the lobby and the name tag, and whether your microphone is sent.
var player_name := ""

View file

@ -19,6 +19,8 @@ extends Node
## over GD-Sync (GDSyncLink), with voice chat. In co-op the menus don't pause the farm; the
## host's leaving ends the partner's game (back to this menu, which says why), the partner's
## leaving leaves the host alone. [M] mutes the microphone.
## * On a phone (MobilePort): no ToonLook, no co-op, and leaving the app pauses. The iOS test
## build adds PerfTest (frame times and test buttons).
## Main processes while paused; the farm doesn't. Tests set save_path and settings_path
## before adding it to the tree.
@ -57,9 +59,15 @@ func _ready() -> void:
farm.process_mode = Node.PROCESS_MODE_PAUSABLE
settings = GameSettings.load_from(settings_path)
settings.apply(get_viewport(), sim.config)
var look := ToonLook.new() # toon shading and pixel outlines on the farm
look.name = "ToonLook"
add_child(look)
if not MobilePort.active(): # phones keep the standard materials (MobilePort)
var look := ToonLook.new() # toon shading and pixel outlines on the farm
look.name = "ToonLook"
add_child(look)
if MobilePort.perf_test():
var perf := PerfTest.new()
perf.name = "PerfTest"
perf.setup(sim, farm.get_node_or_null("CampaignDebug") as CampaignDebug)
add_child(perf)
sim.campaign.save_path = save_path
if sim.end_panel != null:
sim.end_panel.has_menu = true
@ -252,6 +260,8 @@ func quit_game() -> void:
func _notification(what: int) -> void:
if what == NOTIFICATION_WM_CLOSE_REQUEST:
quit_game()
elif what == NOTIFICATION_APPLICATION_PAUSED: # a phone app sent to the background
pause()
func _play() -> void:

View file

@ -2,7 +2,7 @@ class_name MainMenu
extends Control
## The title screen over the farm (Main slowly circles a camera around it): the title, then
## Continue (with which morning it resumes at, or why the save can't be continued), New
## vacation, Play with a friend (co-op, CoopMenu), Settings, and Quit, and a notice line (e.g.
## vacation, Play with a friend (co-op, CoopMenu; not on phones), Settings, and Quit, and a notice line (e.g.
## why a co-op game ended). Mouse, keyboard, and gamepad work through focus.
signal continue_requested
@ -57,6 +57,7 @@ func _ready() -> void:
new_button.pressed.connect(func() -> void: new_requested.emit())
coop_button = _button(box, "Play with a friend")
coop_button.pressed.connect(func() -> void: coop_requested.emit())
coop_button.visible = not MobilePort.active() # no co-op on phones
settings_button = _button(box, "Settings")
settings_button.pressed.connect(func() -> void: settings_requested.emit())
quit_button = _button(box, "Quit")

View file

@ -0,0 +1,20 @@
class_name MobilePort
extends RefCounted
## The phone build's switches (the iOS preset in export_presets.cfg; docs/ios-test-port.md):
## * active(): a phone (the "mobile" feature). The farm keeps its standard materials (Main
## doesn't add ToonLook: the outline needs Forward+, phones run the Mobile renderer), the 3D
## view renders at GameSettings.resolution_scale instead of pixelated, co-op is hidden (the
## main menu's button and the settings' Co-op section), and leaving the app pauses the game.
## The microphone is never opened (audio/driver/enable_input.mobile in project.godot).
## * perf_test(): the iOS preset's "perf_test" feature. Main adds PerfTest (the frame-time
## readout and test buttons), and CampaignDebug's jumps work in that release build.
## On desktop, `-- --mobile` and `-- --perf-test` after the usual arguments turn the same switches
## on, to see the phone build without a phone (add --rendering-method mobile for its renderer).
static func active() -> bool:
return OS.has_feature("mobile") or "--mobile" in OS.get_cmdline_user_args()
static func perf_test() -> bool:
return OS.has_feature("perf_test") or "--perf-test" in OS.get_cmdline_user_args()

View file

@ -0,0 +1 @@
uid://d3q4p7vbjii07

243
game/scripts/perf_test.gd Normal file
View file

@ -0,0 +1,243 @@
class_name PerfTest
extends CanvasLayer
## The iOS test port's readout and buttons (MobilePort.perf_test(); Main adds it), to measure a
## late night on a phone (docs/ios-test-port.md). Over everything, top centre:
## * Now, over the last second: FPS, the frame time (average and worst), the CPU time in
## physics (the farm's tick, FarmSim.step, runs there) and in rendering, the GPU time to draw
## the view, the enemies alive, the 3D view's render size, and the renderer and device.
## * This night, from its start to its end (then held until the next night): the frame time's
## average, 99th percentile, and worst, the share of frames slower than 30 FPS, the peak
## enemies alive, and how long it ran. Frames while paused aren't counted. Printed as one
## "PERF {json}" line at the night's end too.
## * Buttons (taps; they never take gamepad focus): Night 20 / Night 30 (in the morning review,
## CampaignDebug.jump_morning), Unlock all (CampaignDebug.unlock_all), Next phase
## (CampaignController.advance_phase), Shield (the scarecrow takes no hits, as the soak's
## --shield, without its hit flash), and Hide (folds it all into that one button).
## Frame times are measured with the wall clock between _process calls, not with delta, which
## Godot smooths.
const BUCKET_MS := 0.25
const BUCKETS := 400 # 0-100 ms; slower frames land in the last bucket
const SLOW_MS := 1000.0 / 30.0
## The nights the jump buttons go to: the ones docs/thirty-night-soak.md measured on desktop.
const TEST_NIGHTS: Array[int] = [20, 30]
var sim: FarmSim
var debug: CampaignDebug
## The scarecrow takes no hits while on.
var shield := false
var _panel: PanelContainer
var _now: Label
var _night: Label
var _buttons: HBoxContainer
var _jumps: Array[Button] = []
var _shield: Button
var _fold: Button
var _viewport_rid: RID
var _last_usec := 0
# The current second.
var _second_usec := 0
var _second_frames := 0
var _second_worst := 0.0
var _second_render_cpu := 0.0
var _second_physics := 0.0
var _second_physics_worst := 0.0
# The night being measured (or the last one).
var _in_night := false
var _night_number := 0
var _hist := PackedInt32Array()
var _frames := 0
var _sum_ms := 0.0
var _worst_ms := 0.0
var _slow := 0
var _peak_enemies := 0
var _night_usec := 0
func setup(p_sim: FarmSim, p_debug: CampaignDebug) -> void:
sim = p_sim
debug = p_debug
func _ready() -> void:
layer = 20 # over the HUD (1) and the menus (10)
process_mode = Node.PROCESS_MODE_ALWAYS
_viewport_rid = get_viewport().get_viewport_rid()
RenderingServer.viewport_set_measure_render_time(_viewport_rid, true)
_hist.resize(BUCKETS)
var box := VBoxContainer.new()
box.mouse_filter = Control.MOUSE_FILTER_IGNORE
box.add_theme_constant_override("separation", 8)
add_child(box)
box.set_anchors_and_offsets_preset(Control.PRESET_CENTER_TOP)
box.grow_horizontal = Control.GROW_DIRECTION_BOTH
box.offset_top = 12.0
_panel = PanelContainer.new()
_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
box.add_child(_panel)
var lines := VBoxContainer.new()
_panel.add_child(lines)
_now = _label(lines)
_night = _label(lines)
_night.text = "No night measured yet. In the morning: Night 20, Unlock all, Shield, then Next phase to the night."
_buttons = HBoxContainer.new()
_buttons.alignment = BoxContainer.ALIGNMENT_CENTER
_buttons.add_theme_constant_override("separation", 10)
box.add_child(_buttons)
for night in TEST_NIGHTS:
_jumps.append(_button("Night %d" % night, _on_jump.bind(night)))
_button("Unlock all", _on_unlock)
_button("Next phase", _on_next_phase)
_shield = _button("Shield: off", _on_shield)
_fold = _button("Hide", _on_fold)
if sim != null:
sim.campaign.phase_changed.connect(_on_phase_changed)
func _process(_delta: float) -> void:
var now := Time.get_ticks_usec()
if _last_usec == 0:
_last_usec = now
_second_usec = now
return
var ms := (now - _last_usec) / 1000.0
_last_usec = now
_second_frames += 1
_second_worst = maxf(_second_worst, ms)
_second_render_cpu += RenderingServer.viewport_get_measured_render_time_cpu(_viewport_rid) + RenderingServer.get_frame_setup_time_cpu()
var physics := Performance.get_monitor(Performance.TIME_PHYSICS_PROCESS) * 1000.0
_second_physics += physics
_second_physics_worst = maxf(_second_physics_worst, physics)
if _in_night and not get_tree().paused:
_count(ms)
if shield and sim != null and sim.scarecrow != null and sim.scarecrow.player != null:
sim.scarecrow.player.set_flash(0.0) # after Scarecrow's _process: the pinned shield would flash it all night
if now - _second_usec >= 1000000:
_refresh(now)
func _physics_process(_delta: float) -> void:
if shield and sim != null and sim.scarecrow != null:
sim.scarecrow.invulnerable_left = 1.0 # as soak_night.gd's --shield
func _count(ms: float) -> void:
_frames += 1
_sum_ms += ms
_night_usec += roundi(ms * 1000.0)
_worst_ms = maxf(_worst_ms, ms)
if ms > SLOW_MS:
_slow += 1
_hist[mini(int(ms / BUCKET_MS), BUCKETS - 1)] += 1
_peak_enemies = maxi(_peak_enemies, sim.enemies.alive_count())
## Writes the last second's line and the night's, then starts a new second.
func _refresh(now: int) -> void:
var span := (now - _second_usec) / 1000.0
var n := maxi(_second_frames, 1)
var gpu := RenderingServer.viewport_get_measured_render_time_gpu(_viewport_rid)
var win := get_window()
var size_3d := Vector2(win.size) * win.scaling_3d_scale # the window in real pixels, not the 1920-wide canvas
var enemies := sim.enemies.alive_count() if sim != null else 0
_now.text = "%d fps · frame %.1f ms (worst %.1f) · physics %.1f (worst %.1f) · render CPU %.1f · GPU %s\nEnemies %d · 3D %d×%d · %s/%s · %s" % [
roundi(_second_frames * 1000.0 / span), span / n, _second_worst, _second_physics / n, _second_physics_worst,
_second_render_cpu / n, "%.1f ms" % gpu if gpu > 0.0 else "n/a", enemies, roundi(size_3d.x), roundi(size_3d.y),
RenderingServer.get_current_rendering_method(), RenderingServer.get_current_rendering_driver_name(), OS.get_model_name()]
if _in_night:
_night.text = _describe_night("so far")
_second_usec = now
_second_frames = 0
_second_worst = 0.0
_second_render_cpu = 0.0
_second_physics = 0.0
_second_physics_worst = 0.0
var morning := debug != null and sim != null and sim.campaign.state.phase == CampaignController.Phase.MORNING
for b: Button in _jumps:
b.disabled = not morning
func _on_phase_changed(phase: CampaignController.Phase, previous: CampaignController.Phase) -> void:
if phase == CampaignController.Phase.NIGHT:
_in_night = true
_night_number = sim.campaign.state.night
_hist.fill(0)
_frames = 0
_sum_ms = 0.0
_worst_ms = 0.0
_slow = 0
_peak_enemies = 0
_night_usec = 0
elif previous == CampaignController.Phase.NIGHT and _in_night:
_in_night = false
_night.text = _describe_night("done")
print("PERF " + JSON.stringify({"night": _night_number, "seconds": snappedf(_night_usec / 1e6, 0.1), "frames": _frames,
"avg_ms": snappedf(_sum_ms / maxi(_frames, 1), 0.01), "p99_ms": _percentile(0.99), "worst_ms": snappedf(_worst_ms, 0.01),
"slow_share": snappedf(float(_slow) / maxi(_frames, 1), 0.0001), "peak_enemies": _peak_enemies,
"renderer": RenderingServer.get_current_rendering_method(), "model": OS.get_model_name()}))
func _describe_night(status: String) -> String:
var n := maxi(_frames, 1)
return "Night %d (%s, %d s): frame avg %.1f ms · p99 %.1f · worst %.1f · %.1f%% slower than 30 FPS · peak enemies %d" % [
_night_number, status, roundi(_night_usec / 1e6), _sum_ms / n, _percentile(0.99), _worst_ms, 100.0 * _slow / n, _peak_enemies]
## The frame time (ms) that the share p of this night's frames came in under (bucket's top edge).
func _percentile(p: float) -> float:
var target := ceili(_frames * p)
var seen := 0
for i in BUCKETS:
seen += _hist[i]
if seen >= target:
return (i + 1) * BUCKET_MS
return BUCKETS * BUCKET_MS
func _on_jump(night: int) -> void:
if debug != null and sim != null:
debug.jump_morning(night - sim.campaign.state.night)
func _on_unlock() -> void:
if debug != null:
debug.unlock_all()
func _on_next_phase() -> void:
if sim != null:
sim.campaign.advance_phase()
func _on_shield() -> void:
shield = not shield
_shield.text = "Shield: on" if shield else "Shield: off"
func _on_fold() -> void:
var fold := _panel.visible
_panel.visible = not fold
for b in _buttons.get_children():
if b != _fold:
b.visible = not fold
_fold.text = "Perf" if fold else "Hide"
func _label(parent: Control) -> Label:
var l := Label.new()
l.add_theme_font_size_override("font_size", 22)
l.add_theme_color_override("font_outline_color", Color.BLACK)
l.add_theme_constant_override("outline_size", 6)
parent.add_child(l)
return l
func _button(text: String, on_press: Callable) -> Button:
var b := Button.new()
b.text = text
b.focus_mode = Control.FOCUS_NONE # taps only: the gamepad keeps driving the game and menus
b.custom_minimum_size = Vector2(170.0, 60.0)
b.pressed.connect(on_press)
_buttons.add_child(b)
return b

View file

@ -0,0 +1 @@
uid://b8ju6rcgh216v

View file

@ -8,6 +8,7 @@ extends CenterContainer
## Display fullscreen, VSync, 3D resolution scale
## Gameplay tips on the first day and night
## Co-op your name (the lobby and your name tag), and your microphone for voice chat
## (not on phones: MobilePort)
## Every change is applied and saved at once (changed); Back or Escape / B closes it.
signal changed
@ -93,9 +94,10 @@ func _ready() -> void:
_note("Pixel size 1 turns the pixel look off; the resolution scale is used only then.")
_head("Gameplay")
_check("show_tips", "Tips on the first day and night")
_head("Co-op")
_text("player_name", "Your name")
_check("microphone", "Send my microphone in voice chat")
if not MobilePort.active(): # no co-op on phones
_head("Co-op")
_text("player_name", "Your name")
_check("microphone", "Send my microphone in voice chat")
var row := HBoxContainer.new()
row.add_theme_constant_override("separation", 20)
outer.add_child(row)