From 11dcce7c2bbaf1566a65d08f47f2b1507d6af99b Mon Sep 17 00:00:00 2001 From: Matt Stanley <5354790+mstan@users.noreply.github.com> Date: Sun, 1 Nov 2026 11:33:31 -0800 Subject: [PATCH 1/4] Add local independent co-op view mode --- README.md | 2 +- docs/local-independent-views.md | 32 +++++++ .../megaman-x.coop/0.0.1/manifest.toml | 16 +++- .../1.0.0/manifest.toml | 2 +- src/main.c | 68 ++++++++++++-- src/mmx_coop.c | 20 ++-- src/mmx_coop_view.c | 19 ++-- src/mmx_coop_view.h | 10 +- src/mmx_netplay.c | 18 +++- src/mmx_renderer.c | 29 +++++- src/mmx_renderer.h | 3 + src/mmx_replay.c | 9 +- src/mmx_rtl.c | 2 +- src/mods/mmx_zero_plugin.c | 4 + tests/mmx_adaptive_state_test.c | 7 +- tests/mmx_coop_test.inc | 2 +- tests/mmx_coop_views_test.inc | 94 ++++++++++++++++++- tests/mmx_coop_weapon_graphics_test.inc | 2 +- tests/mmx_diagnostic_replay_test.inc | 3 + tests/mmx_netplay_test.inc | 16 +++- tests/mmx_player_presentation_test.inc | 4 +- tests/mmx_renderer_test.c | 29 +++++- tests/test_diagnostic_replay.py | 5 +- tools/apply_coop_hooks.py | 2 +- 24 files changed, 331 insertions(+), 67 deletions(-) create mode 100644 docs/local-independent-views.md diff --git a/README.md b/README.md index 2278bb340..cac5a19b4 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ Rev 1 build. | ☑ | **Adaptive widescreen** | Expanded gameplay with adaptive, 16:9, 21:9, and 32:9 views. | | ☑ | **Playable Zero** | X3 Zero with his buster/saber combo and grounded character switching. Separate health for X and Zero. | | ☑ | **Modern Zero** | Direct saber attacks, double jump, air dash, and movement during airborne swings. | -| ☑ | **Co-op mode** | X and Zero on screen together, with independent health, weapons, and weapon energy. | +| ☑ | **Co-op mode** | X and Zero with independent health, weapons, and weapon energy. Optional [local side-by-side screens](docs/local-independent-views.md), at 5:4 per player or widescreen per pane. | | ☑ | **[Boss Rush](docs/boss-rush.md)** | Endless fights against two different Mavericks, solo or co-op, from the game's title menu. | | ☑ | **X2 weapons** | All eight boss weapons and their charged attacks, adapted for X and Zero. | | ☑ | **X3 weapons** | All eight boss weapons and their charged attacks, adapted for X and Zero. | diff --git a/docs/local-independent-views.md b/docs/local-independent-views.md new file mode 100644 index 000000000..ae83ab67d --- /dev/null +++ b/docs/local-independent-views.md @@ -0,0 +1,32 @@ +# Local independent screens + +In **Mods → Characters → Co-op**, set **Local co-op display** to +**Side by side (Experimental)**, then start or restart the game. Assign the +two players' controls as usual. Co-op still uses your original X3 USA ROM for +Zero. **Unified** remains the default local layout. + +Each player gets their own camera and health/weapon HUD in the same window. +Without widescreen, each pane is **5:4**, making a **5:2** combined canvas. +With widescreen enabled, its ratio applies to each pane: 16:9 produces +16:9 + 16:9, for example. Adaptive uses each half of the drawable window and +letterboxes when the window is too narrow or exceeds the renderer's limits. +Each pane supports up to 1024 source pixels, for a 2048-pixel combined frame. +Local panes retain 5:4 base pixel proportions; Settings → Display Aspect +continues to control Unified views. + +Players can separate using the existing independent-camera simulation rules. +The world, enemies, audio, pickups and stage progression still update once. +Story events and doors retain the existing co-op ownership and reunion rules; +fallen or withdrawn players follow the surviving player's camera. + +Native pause menus keep their existing ownership: either player opens their +own inventory, which appears in both panes while the world pauses. Shared +menus and scripted transitions also appear in both panes. When a private +frame is unavailable, both panes display the current shared frame. + +**Netplay cameras** remains a separate online setting. Selecting a local +layout does not create a network session or change online camera behavior. +The local mode reuses the experimental independent-camera path, so its +existing stage-specific camera/art limitations also apply here. + +Tracking: `beads-8wg.1.155`; shared presentation support: `beads-8wg.2.191`. diff --git a/mods/preloaded/packages/megaman-x.coop/0.0.1/manifest.toml b/mods/preloaded/packages/megaman-x.coop/0.0.1/manifest.toml index 59d44aeb0..e24977d4b 100644 --- a/mods/preloaded/packages/megaman-x.coop/0.0.1/manifest.toml +++ b/mods/preloaded/packages/megaman-x.coop/0.0.1/manifest.toml @@ -54,7 +54,7 @@ label = "Saber Zero" feature = "coop" id = "cameras" label = "Netplay cameras" -description = "Unified keeps both players on one shared screen. Independent is experimental and may show graphics glitches or camera shaking. The host chooses for both peers; offline play always uses Unified." +description = "Unified keeps both players on one shared screen. Independent is experimental and may show graphics glitches or camera shaking. The host chooses for both peers. Local co-op display is a separate setting." type = "choice" default = "unified" [[option.choice]] @@ -64,6 +64,20 @@ label = "Unified" value = "independent" label = "Independent (Experimental)" +[[option]] +feature = "coop" +id = "local_cameras" +label = "Local co-op display" +description = "Unified shares one screen. Side by side gives each local player an independent camera and HUD, at 5:4 per screen by default. Widescreen applies to each screen; Adaptive fits each half of the window. Shared menus and story scenes appear in both screens. Requires a restart; online cameras are unchanged." +type = "choice" +default = "unified" +[[option.choice]] +value = "unified" +label = "Unified" +[[option.choice]] +value = "split" +label = "Side by side (Experimental)" + [[option]] feature = "coop" id = "hud" diff --git a/mods/preloaded/packages/megaman-x.enhancement.widescreen/1.0.0/manifest.toml b/mods/preloaded/packages/megaman-x.enhancement.widescreen/1.0.0/manifest.toml index 018dc61c2..e75d9b078 100644 --- a/mods/preloaded/packages/megaman-x.enhancement.widescreen/1.0.0/manifest.toml +++ b/mods/preloaded/packages/megaman-x.enhancement.widescreen/1.0.0/manifest.toml @@ -23,7 +23,7 @@ default_enabled = false feature = "widescreen" id = "aspect" label = "View aspect ratio" -description = "Fit the view to the window, or select a fixed ratio. Settings > Display Aspect controls pixel and sprite proportions in every mode." +description = "Fit the view to the window, or select a fixed ratio. Local Side by side applies this ratio to each screen, with 5:4 base pixel proportions. Unified follows Settings > Display Aspect." type = "choice" default = "adaptive" [[option.choice]] diff --git a/src/main.c b/src/main.c index 8f386d26d..97b87a718 100644 --- a/src/main.c +++ b/src/main.c @@ -54,22 +54,28 @@ extern int mmx_tier2_diagnostics_enabled(void); static bool s_render_valid; static uint64_t s_benchmark_native_lines; -static uint32_t s_composed_pixels[MMX_RENDER_MAX_WIDTH * 224]; +static uint32_t s_composed_pixels[kSnesDesktopMaxFrameWidth * 224]; #if MMX_NATIVE_RASTER static bool s_composed_ready; static MmxRenderView s_composed_view; static bool s_composed_hud; +static bool s_composed_split; #endif +static bool MmxLocalSplit(void) { + return !MMX_VARIANT_JP && !MmxNetplayActive() && + MmxCoopEnabled() && MmxCoopViewsLocalSplit(); +} static void MmxRomLoaded(const uint8_t *rom, size_t size) { if ((size & 0x7fff) == 512) { rom += 512; size -= 512; } MmxRendererSetRom(rom, size); } static void MmxPrepareFrame(int dw, int dh, int *w, int *h) { + bool split=MmxLocalSplit(); /* A room has one logical field. Window size and each peer's offline pixel * preference cannot widen it. The offline setting is never overwritten. */ SnesDisplayAspect aspect = SnesDisplayAspect_Clamp(MmxNetplayActive() ? 0 : g_config.display_aspect); - g_mmx_custom_renderer = !MMX_VARIANT_JP && (g_config.widescreen || MmxZeroEnabled() || MmxWeaponsEnabled() || MmxArmorEnabled() || MmxKncBugfixActive(0) || MmxKncBugfixActive(1) || MmxBossRushActive() || MmxBossRushGetState().menu || MmxRendererNeedsStormSkyRepair(g_ram)); + g_mmx_custom_renderer = !MMX_VARIANT_JP && (split || g_config.widescreen || MmxZeroEnabled() || MmxWeaponsEnabled() || MmxArmorEnabled() || MmxKncBugfixActive(0) || MmxKncBugfixActive(1) || MmxBossRushActive() || MmxBossRushGetState().menu || MmxRendererNeedsStormSkyRepair(g_ram)); g_mmx_custom_view = MmxRendererViewport(g_mmx_custom_aspect, dw, dh, aspect); if (!g_config.widescreen) { @@ -78,8 +84,17 @@ static void MmxPrepareFrame(int dw, int dh, int *w, int *h) { aspect, &pw, &ph); g_mmx_custom_view = (MmxRenderView){256, 0, (double)pw / ph}; } + if(split) { + double aspect = !g_config.widescreen ? 5.0/4 : + g_mmx_custom_aspect==MMX_ASPECT_16_9 ? 16.0/9 : + g_mmx_custom_aspect==MMX_ASPECT_21_9 ? 21.0/9 : + g_mmx_custom_aspect==MMX_ASPECT_32_9 ? 32.0/9 : + dw>0 && dh>0 ? (double)dw/(2*dh) : 5.0/4; + SnesDisplayFrame pane=SnesLocalViews_ComputePane(256,224,5.0/4,aspect); + g_mmx_custom_view=(MmxRenderView){pane.width,pane.extra,pane.aspect}; + } MmxReplayViewport(&g_mmx_custom_view.width,&g_mmx_custom_view.extra); - *w = g_mmx_custom_renderer ? g_mmx_custom_view.width : 256; + *w = g_mmx_custom_renderer ? g_mmx_custom_view.width*(split?2:1) : 256; *h = 224; } void MmxDisplay_SetWidescreenEnabled(bool enabled) { @@ -97,10 +112,11 @@ static void MmxBeforeFrame(void) { #endif if(!MmxReplayPlaying()) { #if SNESRECOMP_NET - MmxCoopViewsSetOnline(snes_netplay_active() && MmxCoopEnabled() && MmxCoopViewsIndependent()); - MmxRendererSetPeerView(MmxCoopViewsOnline()?snes_netplay_local_slot():-1); + bool online=snes_netplay_active() && MmxCoopEnabled() && MmxCoopViewsIndependent(); + MmxCoopViewsSetActive(online || MmxLocalSplit()); + MmxRendererSetPeerView(online?snes_netplay_local_slot():-1); #else - MmxCoopViewsSetOnline(false);MmxRendererSetPeerView(-1); + MmxCoopViewsSetActive(MmxLocalSplit());MmxRendererSetPeerView(-1); #endif } /* MMX's draw hook runs the original per-line HDMA sequence itself. */ @@ -155,16 +171,22 @@ static void MmxPublishNativeField(uint8_t *field, unsigned number) { if (!g_mmx_custom_renderer) { s_composed_ready=false; return; } s_composed_ready=false; if (s_render_valid) { - if (!MmxRendererDraw(s_composed_pixels,g_mmx_custom_view,g_mmx_custom_hud)) + bool split=MmxLocalSplit(); + int width=g_mmx_custom_view.width*(split?2:1); + bool ok=split ? MmxRendererDrawLocalPair((uint8_t *)s_composed_pixels,(size_t)width*4, + g_mmx_custom_view,g_mmx_custom_hud) : + MmxRendererDraw(s_composed_pixels,g_mmx_custom_view,g_mmx_custom_hud); + if (!ok) Die("Native frame composition failed"); s_composed_view=g_mmx_custom_view; s_composed_hud=g_mmx_custom_hud; + s_composed_split=split; s_composed_ready=true; /* This is the primary native-width field consumed by screenshots, * snapshots and overlays. The independent original field remains * available through MmxRendererStockFrame's explicit readback. */ for (unsigned y=0;y<224;++y) memcpy((uint32_t *)field+y*256, - s_composed_pixels+y*g_mmx_custom_view.width+g_mmx_custom_view.extra,256*4); + s_composed_pixels+y*width+g_mmx_custom_view.extra,256*4); } else if (MmxRendererNativeLines()) { Die("Native raster capture did not complete"); } @@ -181,9 +203,27 @@ static int MmxDrawFrame(uint8_t *dst, size_t pitch, const uint8_t *field, RtlWidescreenPresent(dst, pitch, (const uint8_t *)output, w, h); return 1; } + if(MmxLocalSplit()) { + if(h!=224 || w!=2*g_mmx_custom_view.width) return 0; +#if MMX_NATIVE_RASTER + bool ready=s_composed_ready && s_composed_split && + s_composed_view.width==g_mmx_custom_view.width && + s_composed_view.extra==g_mmx_custom_view.extra && s_composed_hud==g_mmx_custom_hud; + s_composed_ready=false; + if(s_render_valid && ready) {RtlWidescreenPresent(dst,pitch,(const uint8_t *)output,w,h);return 1;} +#endif + if(s_render_valid && MmxRendererDrawLocalPair(dst,pitch,g_mmx_custom_view,g_mmx_custom_hud)) return 1; + /* No private raster yet (boot, shared frontend, reset/load): publish the + * same current canonical frame in both panes, never one stale camera. */ + int pane=w/2; + memset(output,0,(size_t)pane*h*sizeof(*output)); + for(int y=0;y>8);} static unsigned weapon_view(const uint8_t *r,bool vertical) { - if(!MmxCoopViewsOnline() || !state.initialized || state.menu_owner || state.scene_owner) + if(!MmxCoopViewsActive() || !state.initialized || state.menu_owner || state.scene_owner) return word(r+(vertical?0x1e50:0x1e4d)); MmxCoopView v=MmxCoopViewForPlayer(r,&state,state.current); return (unsigned)(vertical?v.y:v.x); @@ -980,10 +980,10 @@ static bool scene_tick(uint8_t *r) { * he keeps falling into the native death zone. The partner is also * beamed as soon as an unentered Dr. Light capsule ($4D) exists while he * is away: its camera lock is about to leave him behind. */ - if(!state.scene_owner && MmxCoopViewsOnline() && state.players[0].status==MMX_COOP_ALIVE && + if(!state.scene_owner && MmxCoopViewsActive() && state.players[0].status==MMX_COOP_ALIVE && state.players[1].status==MMX_COOP_ALIVE && (state.players[0].body[0x27]&127) && (state.players[1].body[0x27]&127)) capsule_takes_world(r); - if(!state.scene_owner && !MmxCoopViewsOnline() && state.players[0].status==MMX_COOP_ALIVE && + if(!state.scene_owner && !MmxCoopViewsActive() && state.players[0].status==MMX_COOP_ALIVE && state.players[1].status==MMX_COOP_ALIVE && (state.players[0].body[0x27]&127) && (state.players[1].body[0x27]&127)) { /* MmxCoopFrameTick has just captured the current body: both stored @@ -1105,7 +1105,7 @@ static void learner_tick(uint8_t *r) { if(!gameplay || !(r[0xbcf]&127) || r[0xbaa]==12) return; if(state.learner_away!=LEARNER_RESCUE) { /* Online views give P2 his own camera; only hazards rescue him there. */ - if(MmxCoopViewsOnline() || learner_on_screen(r,p->body)) {state.learner_away=0;return;} + if(MmxCoopViewsActive() || learner_on_screen(r,p->body)) {state.learner_away=0;return;} if(++state.learner_away=0xe68 && d<0x1228 && !((d-0xe68)%64); bool projectile=d>=0x1428 && d<0x1628 && !((d-0x1428)%64); @@ -2216,7 +2216,7 @@ static bool shared_screen(void) { !g_ram[0x1f0c] && !g_ram[0x1f23] && !g_ram[0x1f48]; } static void constrain_player(uint8_t *r) { - bool independent=MmxCoopViewsOnline(); + bool independent=MmxCoopViewsActive(); if(independent || shared_screen()) { if(state.scene_owner || state.menu_owner || r[0xd3]!=4) return; /* Native camera clamping only sees the world actor. Clamp each @@ -2270,12 +2270,12 @@ static void camera_hook(CpuState *cpu,uint32_t pc) { * screen too. Its native check then uses the same level bound, so only * a real pit kills him; scene_tick beams him out otherwise. */ unsigned bound=word(g_ram+0x1e5c)+224; - if (!learner_mode && !MmxCoopViewsOnline() && state.current==state.anchor && p->status==MMX_COOP_ALIVE && + if (!learner_mode && !MmxCoopViewsActive() && state.current==state.anchor && p->status==MMX_COOP_ALIVE && (p->body[0x27]&127) && word(g_ram)D))) return; if(returning) { if(world.actor_return) { diff --git a/src/mmx_coop_view.c b/src/mmx_coop_view.c index 93496563c..f7ff7fdf8 100644 --- a/src/mmx_coop_view.c +++ b/src/mmx_coop_view.c @@ -1,8 +1,11 @@ #include "mmx_coop_view.h" #include "mmx_wide_policy.h" -static bool online; -/* Agreed mod option; actual session gating forces shared views offline. */ +static bool active; +static bool local_split; +void MmxCoopViewsSetLocalSplit(bool enabled) { local_split=enabled; } +bool MmxCoopViewsLocalSplit(void) { return local_split; } +/* Agreed online camera option; local layout is a separate preference. */ static bool independent=false; void MmxCoopViewsSetIndependent(bool enabled) { independent=enabled; } bool MmxCoopViewsIndependent(void) { return independent; } @@ -37,8 +40,8 @@ void MmxCoopViewsMark(unsigned flag,bool seen) { unsigned n=(flag-0xf800)>>3,bit=1u<<(flag&7); if(seen) world.seen[n]|=bit;else world.seen[n]&=~bit; } -void MmxCoopViewsSetOnline(bool active) { online=active; } -bool MmxCoopViewsOnline(void) { return online; } +void MmxCoopViewsSetActive(bool enabled) { active=enabled; } +bool MmxCoopViewsActive(void) { return active; } static int word(const uint8_t *r) { return r[0]|r[1]<<8; } static void putword(uint8_t *r,unsigned value) {r[0]=(uint8_t)value;r[1]=(uint8_t)(value>>8);} static int clamp(int v,int lo,int hi) { if(hihi?hi:v; } @@ -56,7 +59,7 @@ static unsigned rom_byte(unsigned address) { static void player_limits(const uint8_t *r,const MmxCoopState *s,unsigned seat, const MmxCoopViewBoundsState *b,int out[4]) { for(unsigned i=0;i<4;++i) out[i]=word(r+0x1e56+i*2); - if(online && s->initialized && !s->scene_owner && !s->stage_pending && + if(active && s->initialized && !s->scene_owner && !s->stage_pending && seat<2 && b->stage==r[0x1f7a] && (b->valid&(1u<limits[seat][i]; } @@ -64,7 +67,7 @@ void MmxCoopViewsPlayerLimits(const uint8_t *r,const MmxCoopState *s,unsigned se player_limits(r,s,seat,&bounds,out); } void MmxCoopViewsUpdateBounds(const uint8_t *r,const MmxCoopState *s) { - if(!online || !s->initialized || r[0x1f7a]>12) return; + if(!active || !s->initialized || r[0x1f7a]>12) return; unsigned stage=r[0x1f7a]; if(bounds.stage!=stage) {memset(&bounds,0,sizeof(bounds));bounds.stage=(uint8_t)stage;} /* Native scripted rooms and transport still own both cameras. Re-seed @@ -113,7 +116,7 @@ void MmxCoopViewsUpdateBounds(const uint8_t *r,const MmxCoopState *s) { MmxCoopView MmxCoopViewWithBounds(const uint8_t *r,const MmxCoopState *s,unsigned seat, const MmxCoopViewBoundsState *b) { MmxCoopView v={word(r+0x1e4d),word(r+0x1e50),s->anchor}; - if(!online || !s->initialized || seat>1) return v; + if(!active || !s->initialized || seat>1) return v; /* A transported partner watches the native script from its first frame, * including the teleport beams. Fallen/withdrawn seats watch the survivor. */ if(s->scene_owner || s->stage_pending || r[0xd3]!=4) return v; @@ -133,7 +136,7 @@ MmxCoopView MmxCoopViewForPlayer(const uint8_t *r,const MmxCoopState *s,unsigned return MmxCoopViewWithBounds(r,s,seat,&bounds); } void MmxCoopViewsAdoptPlayer(uint8_t *r,const MmxCoopState *s,unsigned seat) { - if(!online || !s->initialized || seat>1 || seat==s->anchor || s->scene_owner || + if(!active || !s->initialized || seat>1 || seat==s->anchor || s->scene_owner || s->stage_pending || r[0xd3]!=4 || bounds.stage!=r[0x1f7a] || !(bounds.valid&(1u<players[seat]) || s->players[seat].zero.swap_phase) return; diff --git a/src/mmx_coop_view.h b/src/mmx_coop_view.h index ec73e7875..cb02936b0 100644 --- a/src/mmx_coop_view.h +++ b/src/mmx_coop_view.h @@ -1,11 +1,13 @@ #pragma once #include "mmx_coop.h" -/* Session policy is identical on both peers. The local seat affects only - * presentation; it must never select a simulation camera or active region. */ +/* The active independent-world policy is shared by local split and online + * independent cameras. Selecting a presentation seat never changes it. */ typedef struct MmxCoopView { int x, y; unsigned player; } MmxCoopView; -void MmxCoopViewsSetOnline(bool online); -bool MmxCoopViewsOnline(void); +void MmxCoopViewsSetActive(bool active); +bool MmxCoopViewsActive(void); +void MmxCoopViewsSetLocalSplit(bool enabled); +bool MmxCoopViewsLocalSplit(void); void MmxCoopViewsSetIndependent(bool independent); bool MmxCoopViewsIndependent(void); diff --git a/src/mmx_netplay.c b/src/mmx_netplay.c index a0f622dfe..fce9bd05a 100644 --- a/src/mmx_netplay.c +++ b/src/mmx_netplay.c @@ -73,6 +73,9 @@ static void mode_changed(int enabled) { s_mods->feature_enable(s_mods->ctx, kZero, "zero", 0); if (!s_mods->feature_enable(s_mods->ctx, kCoop, "coop", 1)) fail("The X + Zero co-op mod is missing. Restore the bundled mods."); + /* The offline layout is not part of an online room. This temporary plan + * restores the player's saved local preference when they leave Netplay. */ + s_mods->feature_set_option(s_mods->ctx, kCoop, "coop", "local_cameras", "unified"); /* Preserve an existing fixed choice; Adaptive becomes 16:9 in this * temporary plan only. Disabled widescreen remains the native view. */ char aspect[32] = {0}; @@ -112,12 +115,15 @@ static int set_enabled(void *ctx, const char *pkg, int enabled) { s_error[0] = 0; return s_mods->set_enabled(ctx, pkg, enabled); } +static int hidden_camera_option(const char *id) { + return !strcmp(id, s_active ? "local_cameras" : "cameras"); +} static int feature_get(void *ctx, int index, RecompLauncherCModFeature *out) { if (!s_mods->feature_get(ctx, index, out)) return 0; - if (!s_active && !strcmp(out->package_id, kCoop)) { + if (!strcmp(out->package_id, kCoop)) { RecompLauncherCModOption option; for (int i=0; s_mods->feature_option_get(ctx, kCoop, out->id, i, &option); ++i) - if (!strcmp(option.id, "cameras")) --out->option_count; + if (hidden_camera_option(option.id)) --out->option_count; } if (s_active && !strcmp(out->package_id, kZero)) out->hidden = 1; if (s_active && !strcmp(out->package_id, kCoop) && !out->has_error) @@ -126,10 +132,10 @@ static int feature_get(void *ctx, int index, RecompLauncherCModFeature *out) { } static int option_get(void *ctx, const char *pkg, const char *fid, int index, RecompLauncherCModOption *out) { - if (!s_active && !strcmp(pkg, kCoop)) { + if (!strcmp(pkg, kCoop)) { int visible=0, found=0; for (int i=0; s_mods->feature_option_get(ctx, pkg, fid, i, out); ++i) { - if (!strcmp(out->id, "cameras")) continue; + if (hidden_camera_option(out->id)) continue; if (visible++==index) { found=1; break; } } if (!found) return 0; @@ -156,7 +162,9 @@ static int choice_get(void *ctx, const char *pkg, const char *fid, const char *o static int set_option(void *ctx, const char *pkg, const char *fid, const char *option, const char *value) { s_error[0] = 0; if (!s_active && !strcmp(pkg, kCoop) && !strcmp(option, "cameras")) - return fail("Offline play always uses Unified cameras. Open Netplay to choose the room's cameras."); + return fail("Choose Local co-op display for offline play. Open Netplay to choose the room's cameras."); + if (s_active && !strcmp(pkg, kCoop) && !strcmp(option, "local_cameras")) + return fail("Local co-op display is available offline. Choose Netplay cameras for the room."); if (!strcmp(option, "behavior") && ((!strcmp(pkg, kZero) && !strcmp(fid, "zero")) || (!strcmp(pkg, kCoop) && !strcmp(fid, "coop")))) { diff --git a/src/mmx_renderer.c b/src/mmx_renderer.c index 831146945..bef3da3e0 100644 --- a/src/mmx_renderer.c +++ b/src/mmx_renderer.c @@ -13,6 +13,7 @@ #include "mmx_coop_view.h" #include "mmx_boss_rush.h" #include "mmx_boss_rush_score.h" +#include "desktop/local_views.h" #include /* Mode-1 decode/composition follows SuperMetroidRecomp's sm_renderer.c. @@ -134,6 +135,7 @@ static MmxCoopState frame_coop; static MmxCoopViewBoundsState frame_bounds; static bool frame_held; static int peer_seat=-1,view_dx,view_dy; +static bool local_pane; void MmxRendererSetPeerView(int seat) { peer_seat=seat>=0 && seat<2?seat:-1; } int MmxRendererGetPeerView(void) { return peer_seat; } static int view_camera(const uint8_t *r,unsigned address) { @@ -504,7 +506,7 @@ void MmxRendererObserveObject(const uint8_t ram[0x20000], uint16_t object) { current_object = object; /* Two bosses and their attacks exceed the retail OAM submission budget. * Preserve the native queue and full arrangements in Rush too. */ - if (observed_lists || (!g_mmx_expanded_sprites && !MmxCoopViewsOnline() && + if (observed_lists || (!g_mmx_expanded_sprites && !MmxCoopViewsActive() && MmxBossRushGetState().mode!=MMX_RUSH_PLAYING)) return; observed_lists = true; expand_queues(ram); @@ -670,7 +672,7 @@ void MmxRendererBeginFrame(const uint8_t ram[0x20000]) { } frame.expanded_count = latched_stage == ram[0x1f7a] ? expanded_latched_count : 0; memcpy(frame.expanded, expanded_latched, frame.expanded_count * sizeof(Piece)); - frame.expand = g_mmx_expanded_sprites || MmxCoopViewsOnline() || + frame.expand = g_mmx_expanded_sprites || MmxCoopViewsActive() || (frame_rush.mode==MMX_RUSH_PLAYING && MmxWidePolicy_IsStageScene(frame.ram) && !zero_weapons_menu() && !MmxWeaponsMenuVisible(frame.ram)); @@ -2162,9 +2164,10 @@ static void coop_hud_row(const SnesRenderRegisters *ppu,const Raster *r,int y,Mm uint16_t *objects,int *colors) { for(unsigned seat=0;seat<2;++seat) { const MmxCoopPlayer *player=&frame_coop.players[seat]; + if(local_pane && peer_seat>=0 && seat!=(unsigned)peer_seat) continue; if(seat && player->status==MMX_COOP_ABSENT) continue; - bool inverted=coop_hud_compact && player->character==MMX_COOP_ZERO; - int x=8+(coop_hud_compact?0:(int)seat*32)-(anchored?view.extra:0),icon_y=inverted?100:80; + bool inverted=!local_pane && coop_hud_compact && player->character==MMX_COOP_ZERO; + int x=8+(coop_hud_compact || local_pane?0:(int)seat*32)-(anchored?view.extra:0),icon_y=inverted?100:80; unsigned hp=player->status==MMX_COOP_FALLEN?0:player->body[0x27]&127; /* A hidden learner meter leaves the weapon column in its place. */ if(!seat || !coop_hide_learner_health) { @@ -2358,7 +2361,7 @@ bool MmxRendererDraw(uint32_t *out, MmxRenderView view, bool hud) { bool own_scene = raster_scene_owned(); bool rush_hud = stage && frame_rush.loaded; view_dx=view_dy=0; - if(stage && peer_seat>=0 && frame_coop.initialized && MmxCoopViewsOnline()) { + if(stage && peer_seat>=0 && frame_coop.initialized && MmxCoopViewsActive()) { MmxCoopView camera=MmxCoopViewWithBounds(frame.ram,&frame_coop,(unsigned)peer_seat,&frame_bounds); view_dx=camera.x-(int)word(frame.ram,0x1e4d); view_dy=camera.y-(int)word(frame.ram,0x1e50); @@ -2992,3 +2995,19 @@ bool MmxRendererDraw(uint32_t *out, MmxRenderView view, bool hud) { } return true; } + +bool MmxRendererDrawLocalPair(uint8_t *output,size_t pitch,MmxRenderView view,bool hud) { + static uint32_t panes[2][MMX_RENDER_MAX_WIDTH * MMX_RENDER_HEIGHT]; + if(!output || view.width<256 || view.width>MMX_RENDER_MAX_WIDTH || + pitch<(size_t)view.width*8) return false; + int saved_seat=peer_seat,saved_dx=view_dx,saved_dy=view_dy; + bool saved_local=local_pane; + bool independent=frame_coop.initialized && !frame_coop.menu_owner && + !frame_coop.scene_owner && !frame_coop.stage_pending && MmxWidePolicy_IsStageScene(frame.ram); + local_pane=independent; + peer_seat=independent?0:-1;bool ok=MmxRendererDraw(panes[0],view,hud); + if(ok && independent) {peer_seat=1;ok=MmxRendererDraw(panes[1],view,hud);} + peer_seat=saved_seat;view_dx=saved_dx;view_dy=saved_dy;local_pane=saved_local; + return ok && SnesLocalViews_ComposeSideBySide(output,pitch,view.width,MMX_RENDER_HEIGHT, + panes[0],(size_t)view.width*4,independent?panes[1]:NULL,(size_t)view.width*4); +} diff --git a/src/mmx_renderer.h b/src/mmx_renderer.h index 4b55dd0a7..d11e68700 100644 --- a/src/mmx_renderer.h +++ b/src/mmx_renderer.h @@ -152,6 +152,9 @@ void MmxRendererHardwareVramChanged(void); void MmxRendererEndHardwareRaster(void); bool MmxRendererEndFrame(const uint32_t stock[256 * 224]); bool MmxRendererDraw(uint32_t *output, MmxRenderView view, bool anchor_hud); +/* Render both seats from the same immutable frame and publish the pair only + * after both succeed. The caller duplicates its canonical fallback on failure. */ +bool MmxRendererDrawLocalPair(uint8_t *output, size_t pitch, MmxRenderView view, bool anchor_hud); MmxRenderStats MmxRendererGetStats(void); MmxRasterStats MmxRendererGetRasterStats(void); bool MmxRendererStageTile(const uint8_t ram[0x20000], unsigned layer, diff --git a/src/mmx_replay.c b/src/mmx_replay.c index 7c47e1ef8..df1d53d0b 100644 --- a/src/mmx_replay.c +++ b/src/mmx_replay.c @@ -2,6 +2,7 @@ #include "diagnostics/replay_writer.h" #include "mmx_coop.h" #include "mmx_coop_view.h" +#include "mmx_netplay.h" #include "mmx_coop_trace.h" #include "mmx_renderer.h" #include "mmx_zero.h" @@ -91,7 +92,8 @@ static unsigned mods(void) { static unsigned policy(void) { return g_config.widescreen | g_mmx_custom_renderer<<1 | g_config.new_renderer<<2 | g_config.no_sprite_limits<<3 | MmxCoopViewsIndependent()<<4 | - rtl_apu_extended_frame_timing()<<5 | MmxCoopViewsOnline()<<6; + rtl_apu_extended_frame_timing()<<5 | MmxCoopViewsActive()<<6 | + (!MmxNetplayActive() && MmxCoopEnabled() && MmxCoopViewsLocalSplit())<<7; } void MmxReplayViewport(int *width,int *extra) { if(playing && playback_loaded) { *width=playback_width; *extra=(playback_width-256)/2; } @@ -351,7 +353,7 @@ static uint32_t playback_begin(uint32_t inputs) { playback_rom_verified=true; } } - if(!playback_checkpointed || sscanf(line,"I %u %x %x %d %d",&frame,&word,&flags,&width,&peer)!=5 || flags>127 || + if(!playback_checkpointed || sscanf(line,"I %u %x %x %d %d",&frame,&word,&flags,&width,&peer)!=5 || flags>255 || width<256 || width>MMX_RENDER_MAX_WIDTH || (width&1) || peer < -1 || peer>1) { error("invalid input record"); return inputs; } @@ -360,7 +362,8 @@ static uint32_t playback_begin(uint32_t inputs) { } g_config.widescreen=(flags&1)!=0; g_mmx_custom_renderer=(flags&2)!=0; g_config.new_renderer=(flags&4)!=0; g_config.no_sprite_limits=(flags&8)!=0; - MmxCoopViewsSetIndependent((flags&16)!=0); MmxCoopViewsSetOnline((flags&64)!=0); + MmxCoopViewsSetIndependent((flags&16)!=0); MmxCoopViewsSetActive((flags&64)!=0); + MmxCoopViewsSetLocalSplit((flags&128)!=0); if(flags&32) RtlEnableExtendedFrameTiming(); if(!!(flags&32)!=rtl_apu_extended_frame_timing()) { error("frame timing mode differs"); return inputs; } MmxRendererSetPeerView(peer); playback_width=width; diff --git a/src/mmx_rtl.c b/src/mmx_rtl.c index d4180e21c..664a332df 100644 --- a/src/mmx_rtl.c +++ b/src/mmx_rtl.c @@ -1448,7 +1448,7 @@ void MmxWsSpawnRunNativePass(CpuState *cpu) { * and collected flags; an owned upgrade's capsule still removes itself. */ static void MmxCoopCapsulePass(CpuState *cpu) { extern uint8_t g_ram[0x20000]; - if (!MmxCoopEnabled() || MmxCoopViewsOnline() || !MmxWidePolicy_IsStageScene(g_ram)) return; + if (!MmxCoopEnabled() || MmxCoopViewsActive() || !MmxWidePolicy_IsStageScene(g_ram)) return; MmxCoopState coop = MmxCoopGetState(); if (!coop.initialized || coop.menu_owner || coop.scene_owner) return; int seat = -1; diff --git a/src/mods/mmx_zero_plugin.c b/src/mods/mmx_zero_plugin.c index ab0a7029a..0cdbb552c 100644 --- a/src/mods/mmx_zero_plugin.c +++ b/src/mods/mmx_zero_plugin.c @@ -276,6 +276,8 @@ static void activate_coop(void) { MmxZeroSetModern(!strcmp(behavior,"modern")); snes_mod_runtime_feature_option_value_c("megaman-x.coop","coop","cameras",cameras,sizeof(cameras)); MmxCoopViewsSetIndependent(!strcmp(cameras,"independent")); + snes_mod_runtime_feature_option_value_c("megaman-x.coop","coop","local_cameras",cameras,sizeof(cameras)); + MmxCoopViewsSetLocalSplit(!strcmp(cameras,"split")); snes_mod_runtime_feature_option_value_c("megaman-x.coop","coop","hud",hud,sizeof(hud)); MmxRendererSetCompactCoopHud(strcmp(hud,"horizontal")!=0); unsigned p1=!strcmp(character,"zero") ? MMX_COOP_ZERO : MMX_COOP_X; @@ -316,6 +318,8 @@ static void reset(void) { MmxRendererSetCompactCoopHud(true); MmxRendererSetHideLearnerHealth(false); MmxCoopViewsSetIndependent(false); + MmxCoopViewsSetLocalSplit(false); + MmxCoopViewsSetActive(false); MmxCoopDisable(); if (MmxWeaponsEnabled()) g_ram[0x1f12] = 0; MmxZeroSetStartCharacter(false); diff --git a/tests/mmx_adaptive_state_test.c b/tests/mmx_adaptive_state_test.c index d98b0dbf6..9a723a4ff 100644 --- a/tests/mmx_adaptive_state_test.c +++ b/tests/mmx_adaptive_state_test.c @@ -17,9 +17,9 @@ static void frame(unsigned input) { getenv("MMX_COOP_ONLINE_FIXTURE") || getenv("MMX_COOP_LIFT_REPLAY_FIXTURE") || getenv("MMX_COOP_REGION_REPLAY_FIXTURE") || getenv("MMX_COOP_WRAP_REPLAY_FIXTURE") || getenv("MMX_COOP_SIGMA1_INTRO_FIXTURE") || getenv("MMX_COOP_SIGMA1_LOCKED_FIXTURE") || - getenv("MMX_COOP_SIGMA1_VILE_FIXTURE") || getenv("MMX_COOP_SIGMA1_LADDER_FIXTURE")) MmxCoopViewsSetOnline(!getenv("MMX_COOP_SIGMA1_UNIFIED")); + getenv("MMX_COOP_SIGMA1_VILE_FIXTURE") || getenv("MMX_COOP_SIGMA1_LADDER_FIXTURE")) MmxCoopViewsSetActive(!getenv("MMX_COOP_SIGMA1_UNIFIED")); if(!MmxReplayPlaying() && getenv("MMX_REPLAY_TEST") && !strcmp(getenv("MMX_REPLAY_TEST"),"online")) { - MmxCoopViewsSetIndependent(true);MmxCoopViewsSetOnline(true);MmxRendererSetPeerView(1); + MmxCoopViewsSetIndependent(true);MmxCoopViewsSetActive(true);MmxRendererSetPeerView(1); } RtlRunFrame(input | (1u << 30)); MmxBossRushAudioPresent(); @@ -1901,6 +1901,7 @@ static void render_rollback_checks(uint8 *start, uint8 *expected, uint8 *actual, } int main(int argc, char **argv) { + setvbuf(stdout,NULL,_IONBF,0); check(argc == 2 || argc == 3, "ROM supplied"); SDL_SetMainReady(); check(snesrecomp_sdl_init(SDL_INIT_EVENTS), "SDL initializes"); @@ -2053,7 +2054,7 @@ int main(int argc, char **argv) { coop_region_replay_checks(zero_assets,getenv("MMX_COOP_WRAP_REPLAY_FIXTURE"),start,expected,actual,cap);return 0; } if(getenv("MMX_REPLAY_TEST")) { diagnostic_replay_checks(zero_assets,getenv("MMX_REPLAY_TEST")); return 0; } - if(getenv("MMX_COOP_VIEWS_BOOT_TEST")) { + if(getenv("MMX_COOP_VIEWS_BOOT_TEST") || getenv("MMX_LOCAL_VIEWS_TEST")) { coop_view_boot_checks(zero_assets,start,expected,actual,cap);return 0; } if(getenv("MMX_COOP_REPLAY")) { coop_replay_probe(zero_assets,getenv("MMX_COOP_REPLAY")); return 0; } diff --git a/tests/mmx_coop_test.inc b/tests/mmx_coop_test.inc index 92e469604..e4d736cb4 100644 --- a/tests/mmx_coop_test.inc +++ b/tests/mmx_coop_test.inc @@ -603,7 +603,7 @@ static void coop_scene_checks(const char *fixture,uint8_t *start,uint8_t *expect ++departures; check(s.scene_owner==driver+1 && s.anchor==driver,"touching player owns native door walk"); } - if(s.scene_phase && MmxCoopViewsOnline()) { + if(s.scene_phase && MmxCoopViewsActive()) { MmxCoopView owner=MmxCoopViewForPlayer(g_ram,&s,driver),partner=MmxCoopViewForPlayer(g_ram,&s,driver^1); check(owner.x==partner.x && owner.y==partner.y && partner.player==driver, "scripted transport immediately gives both seats the owner's camera"); diff --git a/tests/mmx_coop_views_test.inc b/tests/mmx_coop_views_test.inc index a95c1b854..2f6d865e3 100644 --- a/tests/mmx_coop_views_test.inc +++ b/tests/mmx_coop_views_test.inc @@ -55,9 +55,72 @@ static void coop_region_replay_checks(const char *assets,const char *fixture, } puts(wrap?"MMX ISSUE110 WRAP REPLAY CHECKS PASSED":"MMX ISSUE110 REGION REPLAY CHECKS PASSED"); } +static void local_view_presentation_checks(uint8_t *start,uint8_t *actual,size_t cap) { + static uint32_t pixels[kSnesDesktopMaxFrameWidth*224]; + int w,h;SnesDisplayViewport viewport; + check(MmxLocalSplit() && MmxCoopViewsActive() && !MmxNetplayActive(), + "local split activates independent world without a network session"); + g_config.widescreen=false; + for(unsigned aspect=0;aspect<3;++aspect) { + g_config.display_aspect=aspect;MmxPrepareFrame(1600,900,&w,&h); + check(w==512 && h==224 && g_mmx_custom_view.aspect==5.0/4, + "default local panes are 5:4 across display preferences"); + } + MmxViewport(w,h,1600,900,&viewport); + check(viewport.width==1600 && viewport.height==640 && viewport.y==130 && MmxWindowWidth(w)==600, + "native pair has a 5:2 canvas and a 600x240 base window"); + size_t n=RtlSaveSnapshotToMemory(start,cap); + MmxRendererSetPeerView(1); + check(MmxDrawFrame((uint8_t *)pixels,(size_t)w*4,g_my_pixels,w,h,1), + "real desktop adapter composes the separated local pair"); + check(MmxRendererGetPeerView()==1,"pair rendering restores the caller's presentation seat"); + bool different=false; + for(int y=0;yfeature_set_option(linked->ctx,coop,"coop","cameras","independent"), - "camera selection is unavailable offline"); + "online camera selection is unavailable offline"); + int local_camera=0; + for(int i=0;linked->feature_option_get(linked->ctx,coop,"coop",i,&camera_option);++i) + local_camera|=!strcmp(camera_option.id,"local_cameras"); + check(local_camera && linked->feature_set_option(linked->ctx,coop,"coop","local_cameras","split"), + "offline launcher exposes independent side-by-side display"); MmxCoopViewsSetIndependent(true); MmxBeforeFrame(); - check(!MmxCoopViewsOnline(),"offline frames force Unified despite the catalog default"); + check(!MmxCoopViewsActive(),"offline frames force Unified despite the catalog default"); char behavior[32] = {0}; snes_mod_runtime_feature_option_value_c(zero,"zero","behavior",behavior,sizeof(behavior)); check(!strcmp(behavior,"x3"),"X3 Behavior is the default"); @@ -106,6 +111,10 @@ static void netplay_policy_checks(const char *root, const char *rom, const char check(p->feature_option_get(p->ctx,coop,"coop",2,&camera_option) && !strcmp(camera_option.id,"cameras") && !strcmp(camera_option.value,"unified") && camera_option.choice_count==2,"netplay exposes Unified by default and Independent opt-in"); + for(int i=0;p->feature_option_get(p->ctx,coop,"coop",i,&camera_option);++i) + check(strcmp(camera_option.id,"local_cameras")!=0,"online launcher hides local display preference"); + check(!p->feature_set_option(p->ctx,coop,"coop","local_cameras","split"), + "local layout cannot replace a room's camera agreement"); check(MmxNetplayActive() && snes_mod_runtime_feature_enabled_c(coop, "coop") && !snes_mod_runtime_feature_enabled_c(zero, "zero"), "entering Netplay replaces exchange with co-op"); check(!p->feature_enable(p->ctx, coop, "coop", 0) && @@ -128,6 +137,7 @@ static void netplay_policy_checks(const char *root, const char *rom, const char check(p->feature_set_option(p->ctx, wide, "widescreen", "aspect", ratios[ratio]) && p->commit_netplay(p->ctx, rom), "fixed view commits with local ROM validation"); snes_mod_runtime_activate_plugins_c(); + check(!MmxCoopViewsLocalSplit(),"temporary online plan suppresses the saved local split layout"); memset(g_ram + 0x1e60, 0, 12); MmxPasswordPrefill(g_ram); check(!g_ram[0x1e60], "online password screen keeps synchronized defaults"); @@ -303,7 +313,7 @@ static void netplay_pair_checks(const char *root, const char *rom, const char *x if (snes_netplay_rb_desync_count()) break; } check(frames==480 && !snes_netplay_rb_desync_count(), "two peers advance 480 frames without a digest fork"); - check(MmxCoopViewsOnline()==!getenv("MMX_NETPLAY_UNIFIED_TEST"),"runtime session applies agreed camera mode"); + check(MmxCoopViewsActive()==!getenv("MMX_NETPLAY_UNIFIED_TEST"),"runtime session applies agreed camera mode"); s=MmxCoopGetState(); check(MmxCoopValidState(&s) && s.players[0].status==MMX_COOP_ALIVE && s.players[1].status==MMX_COOP_ALIVE, "both players remain alive with independent contexts"); diff --git a/tests/mmx_player_presentation_test.inc b/tests/mmx_player_presentation_test.inc index 4e60b27c0..a96df8a29 100644 --- a/tests/mmx_player_presentation_test.inc +++ b/tests/mmx_player_presentation_test.inc @@ -44,7 +44,7 @@ static void coop_player_overlap(void) { rom_long(0x68000,0x8d9000);rom_long(0x69000,0x8d9100); rom_bytes[0x69100]=1; MmxRendererSetRom(NULL,0);MmxRendererSetRom(rom_bytes,sizeof(rom_bytes)); - MmxCoopViewsSetOnline(false);g_mmx_custom_renderer=true;g_mmx_expanded_sprites=false; + MmxCoopViewsSetActive(false);g_mmx_custom_renderer=true;g_mmx_expanded_sprites=false; for(unsigned current=0;current<2;++current)for(unsigned repairs=0;repairs<2;++repairs) for(unsigned overlay=0;overlay<2;++overlay)for(unsigned wide=0;wide<2;++wide) { memset(&ppu,0,sizeof(ppu));memset(ram,0,sizeof(ram));memset(stock,0,sizeof(stock)); @@ -92,6 +92,6 @@ static void coop_player_overlap(void) { assert(output[48*v.width+v.extra+44]==0xff0000); } } - MmxRendererSetPlayerOverlayProvider(NULL);MmxCoopViewsSetOnline(false); + MmxRendererSetPlayerOverlayProvider(NULL);MmxCoopViewsSetActive(false); g_mmx_custom_renderer=false;g_mmx_render_asset_repairs=true;MmxRendererReset(); } diff --git a/tests/mmx_renderer_test.c b/tests/mmx_renderer_test.c index 427b9c5dd..a3dd0dabd 100644 --- a/tests/mmx_renderer_test.c +++ b/tests/mmx_renderer_test.c @@ -246,7 +246,7 @@ static void independent_oam_visibility(void) { /* Native OAM contains hidden slots and wraps sprites across y=255. * Neither is a full world coordinate after selecting a distant peer view. */ MmxRendererSetRom(NULL,0);MmxZeroDisable();MmxRendererSetCompactCoopHud(false); - MmxCoopViewsSetOnline(true);g_mmx_custom_renderer=true; + MmxCoopViewsSetActive(true);g_mmx_custom_renderer=true; const int separation[]={0,208,256,-256,512,-512}; for(unsigned anchor=0;anchor<2;++anchor) for(unsigned n=0;n<6;++n) for(unsigned kind=0;kind<3;++kind) { @@ -288,7 +288,28 @@ static void independent_oam_visibility(void) { } } } - MmxRendererSetPeerView(-1);MmxCoopViewsSetOnline(false); + /* Publish both distant cameras from the same capture, at native, wide and + * maximum pane width. Caller padding and the selected peer must survive. */ + static uint32_t expected[2][MMX_RENDER_MAX_WIDTH*224]; + static uint32_t pair[(2*MMX_RENDER_MAX_WIDTH+4)*224]; + const int widths[]={256,364,MMX_RENDER_MAX_WIDTH}; + for(unsigned mode=0;mode<3;++mode) { + int width=widths[mode],stride=2*width+4; + MmxRenderView view={width,(width-256)/2,mode?16.0/9:5.0/4}; + for(unsigned seat=0;seat<2;++seat) { + MmxRendererSetPeerView((int)seat); + assert(MmxRendererDraw(expected[seat],view,true)); + } + memset(pair,0xcd,sizeof(pair)); + assert(MmxRendererDrawLocalPair((uint8_t *)pair,(size_t)stride*4,view,true)); + assert(MmxRendererGetPeerView()==1); + for(int y=0;y<224;++y) { + assert(!memcmp(pair+y*stride,expected[0]+y*width,(size_t)width*4)); + assert(!memcmp(pair+y*stride+width,expected[1]+y*width,(size_t)width*4)); + assert(pair[y*stride+2*width]==0xcdcdcdcd); + } + } + MmxRendererSetPeerView(-1);MmxCoopViewsSetActive(false); MmxRendererSetCompactCoopHud(true);g_mmx_custom_renderer=false;MmxRendererReset(); } static void expanded_capacity(void) { @@ -807,7 +828,7 @@ static void spark_effects(void) { * ($87:A6ED/A7AE). It must follow the same world position in either view. */ put_word(0x1e50,256);ppu.vScroll[0]=256; put_word(0x1e58,2048);put_word(0x1e5c,2048); - MmxCoopViewsSetOnline(true); + MmxCoopViewsSetActive(true); for(unsigned anchor=0;anchor<2;++anchor) for(int dy=-64;dy<=64;dy+=64) { MmxCoopState s={0};s.initialized=1;s.current=s.anchor=(uint8_t)anchor; for(unsigned seat=0;seat<2;++seat) { @@ -825,7 +846,7 @@ static void spark_effects(void) { (y>=top && y Date: Sun, 1 Nov 2026 13:43:08 -0800 Subject: [PATCH 2/4] Preserve native room pans for independent co-op cameras and prepare 2.3.12 --- CMakeLists.txt | 2 +- docs/local-independent-views.md | 2 + snesrecomp | 2 +- src/mmx_coop_view.c | 70 ++++++++++++++++++++++++++++++++- src/mmx_coop_view.h | 5 +++ src/mmx_cpu_infra.c | 9 ++++- src/mmx_renderer.c | 4 +- src/mmx_replay.c | 4 +- src/mmx_rtl.c | 5 ++- tests/mmx_adaptive_state_test.c | 1 + tests/mmx_coop_camera_test.inc | 48 ++++++++++++++++++++++ tests/mmx_coop_views_test.inc | 46 ++++++++++++++++++++++ tests/mmx_renderer_test.c | 3 +- tools/make_release.ps1 | 1 + 14 files changed, 190 insertions(+), 12 deletions(-) create mode 100644 tests/mmx_coop_camera_test.inc diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cc4d09e1..63a1bf0a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -project(MegaManXSNESRecomp VERSION 2.3.11 LANGUAGES C CXX) +project(MegaManXSNESRecomp VERSION 2.3.12 LANGUAGES C CXX) # Qualified Windows x64 default; retain explicit selections and other-target floors. set(_MMX_RASTER_IMPL_DEFAULT "LLE") string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _MMX_RASTER_IMPL_PROCESSOR) diff --git a/docs/local-independent-views.md b/docs/local-independent-views.md index ae83ab67d..e5c456c6f 100644 --- a/docs/local-independent-views.md +++ b/docs/local-independent-views.md @@ -18,6 +18,8 @@ Players can separate using the existing independent-camera simulation rules. The world, enemies, audio, pickups and stage progression still update once. Story events and doors retain the existing co-op ownership and reunion rules; fallen or withdrawn players follow the surviving player's camera. +Both cameras retain the native tracking dead zones and gradual room pans, +including the Highway camera transition after Bee Blader is defeated. Native pause menus keep their existing ownership: either player opens their own inventory, which appears in both panes while the world pauses. Shared diff --git a/snesrecomp b/snesrecomp index 901965395..009963061 160000 --- a/snesrecomp +++ b/snesrecomp @@ -1 +1 @@ -Subproject commit 90196539541b220de5cfe7182504ddac7e823ee3 +Subproject commit 009963061227fb32fb199f97d729932ac3a85a12 diff --git a/src/mmx_coop_view.c b/src/mmx_coop_view.c index f7ff7fdf8..038d0f7dc 100644 --- a/src/mmx_coop_view.c +++ b/src/mmx_coop_view.c @@ -16,9 +16,13 @@ static size_t rom_size; void MmxCoopViewsSetRom(const uint8_t *bytes,size_t size) {rom=bytes;rom_size=size;} MmxCoopViewBoundsState MmxCoopViewsGetBoundsState(void) {return bounds;} bool MmxCoopViewsValidBoundsState(const MmxCoopViewBoundsState *b) { - if(!b || b->valid>3 || b->stage>12) return false; + if(!b || b->valid>3 || b->camera_valid>3 || b->stage>12) return false; for(unsigned seat=0;seat<2;++seat) for(unsigned i=0;i<4;++i) if((b->valid&(1u<limits[seat][i]>8192) return false; + for(unsigned seat=0;seat<2;++seat) if(b->camera_valid&(1u<current[seat][i]>8192) return false; + for(unsigned i=0;i<2;++i) if(b->camera[seat][i]>8192) return false; + } return true; } void MmxCoopViewsSetBoundsState(const MmxCoopViewBoundsState *b) {bounds=*b;} @@ -40,7 +44,10 @@ void MmxCoopViewsMark(unsigned flag,bool seen) { unsigned n=(flag-0xf800)>>3,bit=1u<<(flag&7); if(seen) world.seen[n]|=bit;else world.seen[n]&=~bit; } -void MmxCoopViewsSetActive(bool enabled) { active=enabled; } +void MmxCoopViewsSetActive(bool enabled) { + if(active!=enabled) bounds.camera_valid=0; + active=enabled; +} bool MmxCoopViewsActive(void) { return active; } static int word(const uint8_t *r) { return r[0]|r[1]<<8; } static void putword(uint8_t *r,unsigned value) {r[0]=(uint8_t)value;r[1]=(uint8_t)(value>>8);} @@ -113,6 +120,62 @@ void MmxCoopViewsUpdateBounds(const uint8_t *r,const MmxCoopState *s) { } } } +/* $00:DE9D/DEBC keep the player inside a native dead zone; DE7E/DE5F + * limit tracking speed. E1B5..E2BA ease each room bound at $1E52 pixels per + * frame. Preserve those two phases instead of clamping to the final bound. */ +static int follow(int body,int camera,int low,int high,int speed) { + int delta=body-camera; + int desired=deltahigh?body-high:camera; + return clamp(desired,camera-speed,camera+speed); +} +static int limit_step(int target,int current,int camera,int body,int previous, + int zone,int speed,bool minimum) { + if(target==current) return current; + if(minimum ? target>=camera : target=target?camera-speed:target); + if((uint16_t)(body-camera-zone+2)<4) return target; + int movement=(int16_t)(body-previous); + if(minimum) {if(movement>0) movement=0;} + else if(movement<0) movement=0; + int next=camera+movement+(minimum?-speed:speed); + return minimum?(next>=target?next:target):(nextinitialized || s->scene_owner || s->stage_pending || r[0xd3]!=4) { + bounds.camera_valid=0;return; + } + if(s->menu_owner || r[0x1f10]>=6) return; + for(unsigned seat=0;seat<2;++seat) { + unsigned bit=1u<players[seat]; + if(!living(p) || p->zero.swap_phase) {bounds.camera_valid&=(uint8_t)~bit;continue;} + const uint8_t *body=seat==s->current?r+0xba8:p->body; + /* Shared encounters own the native camera. Retain their actual final + * position/current bounds so release starts the same pan on both seats. */ + if(seat==s->anchor || !(bounds.valid&bit)) { + bounds.camera[seat][0]=(uint16_t)word(r+0x1e4d); + bounds.camera[seat][1]=(uint16_t)word(r+0x1e50); + for(unsigned i=0;i<4;++i) bounds.current[seat][i]=(uint16_t)word(r+0x1e56+i*2); + bounds.camera_valid|=(uint8_t)bit;continue; + } + int x=word(body+5),y=word(body+8); + int zones[4]={word(r+0x1e74),word(r+0x1e76),word(r+0x1e70),word(r+0x1e72)}; + if(!(bounds.camera_valid&bit)) { + for(unsigned i=0;i<4;++i) bounds.current[seat][i]=bounds.limits[seat][i]; + bounds.camera[seat][0]=(uint16_t)clamp(x-zones[0],bounds.current[seat][0],bounds.current[seat][1]); + bounds.camera[seat][1]=(uint16_t)clamp(y-zones[2],bounds.current[seat][2],bounds.current[seat][3]); + bounds.camera_valid|=(uint8_t)bit; + } + int tracking=word(r+0x1e54),pan=word(r+0x1e52); + int cx=clamp(follow(x,bounds.camera[seat][0],zones[0],zones[1],tracking),bounds.current[seat][0],bounds.current[seat][1]); + int cy=clamp(follow(y,bounds.camera[seat][1],zones[2],zones[3],tracking),bounds.current[seat][2],bounds.current[seat][3]); + bounds.camera[seat][0]=(uint16_t)cx;bounds.camera[seat][1]=(uint16_t)cy; + for(unsigned i=0;i<4;++i) bounds.current[seat][i]=(uint16_t)limit_step( + bounds.limits[seat][i],bounds.current[seat][i],i<2?cx:cy,i<2?x:y, + word(body+(i<2?0x22:0x24)),zones[i],pan,!(i&1)); + } +} MmxCoopView MmxCoopViewWithBounds(const uint8_t *r,const MmxCoopState *s,unsigned seat, const MmxCoopViewBoundsState *b) { MmxCoopView v={word(r+0x1e4d),word(r+0x1e50),s->anchor}; @@ -124,6 +187,9 @@ MmxCoopView MmxCoopViewWithBounds(const uint8_t *r,const MmxCoopState *s,unsigne if(!living(p) || p->zero.swap_phase) seat=s->anchor; v.player=seat; if(seat==s->anchor) return v; + if(b->stage==r[0x1f7a] && (b->camera_valid&(1u<camera[seat][0];v.y=b->camera[seat][1];return v; + } const uint8_t *body=seat==s->current?r+0xba8:s->players[seat].body; /* Use the authored stage/room camera limits, not the other player's view. * X1's feet lie in the lower dead zone of the 224px native viewport. */ diff --git a/src/mmx_coop_view.h b/src/mmx_coop_view.h index cb02936b0..f34cbe86f 100644 --- a/src/mmx_coop_view.h +++ b/src/mmx_coop_view.h @@ -16,12 +16,17 @@ bool MmxCoopViewsIndependent(void); typedef struct MmxCoopViewBoundsState { uint16_t limits[2][4]; /* left, right, top, bottom */ uint8_t valid, stage; + /* Native current limits ease toward the authored targets above. Camera + * history advances once per simulation frame, never during presentation. */ + uint16_t current[2][4], camera[2][2]; + uint8_t camera_valid; } MmxCoopViewBoundsState; void MmxCoopViewsSetRom(const uint8_t *rom, size_t size); MmxCoopViewBoundsState MmxCoopViewsGetBoundsState(void); bool MmxCoopViewsValidBoundsState(const MmxCoopViewBoundsState *bounds); void MmxCoopViewsSetBoundsState(const MmxCoopViewBoundsState *bounds); void MmxCoopViewsUpdateBounds(const uint8_t *ram, const MmxCoopState *state); +void MmxCoopViewsEndFrame(const uint8_t *ram, const MmxCoopState *state); /* Before a remote player takes a native door, transfer its authored view to * the shared script camera while both independent views still exist. */ void MmxCoopViewsAdoptPlayer(uint8_t *ram, const MmxCoopState *state, unsigned seat); diff --git a/src/mmx_cpu_infra.c b/src/mmx_cpu_infra.c index c0a15f2b0..9b0d9697e 100644 --- a/src/mmx_cpu_infra.c +++ b/src/mmx_cpu_infra.c @@ -1,6 +1,13 @@ #include "common_cpu_infra.h" #include "mmx_rtl.h" #include "mmx_replay.h" +#include "mmx_coop_view.h" + +static void MmxFrameEnd(void) { + MmxCoopState coop=MmxCoopGetState(); + MmxCoopViewsEndFrame(g_ram,&coop); + MmxReplayEnd(); +} /* MMX_VARIANT_JP is a per-target compile-def (RockmanXSNESRecomp sets =1; * the USA MegaManX target leaves it undefined). Guard so this file compiles @@ -29,5 +36,5 @@ const RtlGameInfo kMmxGameInfo = { .on_state_loaded = &MmxOnStateLoaded, .hardware_reset = &MmxOnHardwareReset, .frame_begin = &MmxReplayBegin, - .frame_end = &MmxReplayEnd, + .frame_end = &MmxFrameEnd, }; diff --git a/src/mmx_renderer.c b/src/mmx_renderer.c index bef3da3e0..d33250ed4 100644 --- a/src/mmx_renderer.c +++ b/src/mmx_renderer.c @@ -1020,7 +1020,7 @@ bool MmxRendererSaveCapture(const char *path) { FILE *f = fopen(path, "wb"); if (!f) { free(saved); return false; } uint32_t count = vram_snapshots.count; - uint32_t header[] = {0x4d4d5843, frame_coop.initialized ? 31 : 30, + uint32_t header[] = {0x4d4d5843, frame_coop.initialized ? 33 : 32, (uint32_t)(sizeof(frame) + sizeof(count) + sizeof(indices) + count * 0x10000u + sizeof(frame_zero) + sizeof(frame_weapons) + sizeof(frame_weapon_combat) + (frame_coop.initialized ? sizeof(frame_coop) : 0) + sizeof(frame_rush) + @@ -1063,7 +1063,7 @@ bool MmxRendererLoadCapture(const char *path) { memset(&frame_rush, 0, sizeof(frame_rush)); memset(&frame_rush_visual, 0, sizeof(frame_rush_visual)); bool ok = fread(h, sizeof(h), 1, f) == 1 && h[0] == 0x4d4d5843 && - (h[1]==26 || h[1]==27 || h[1]==30 || h[1]==31) && fread(&frame, sizeof(frame), 1, f) == 1; + (h[1]==32 || h[1]==33) && fread(&frame, sizeof(frame), 1, f) == 1; const bool valid = true; ok = ok && !memcmp(&frame.valid, &valid, sizeof(valid)) && frame.captured == 224 && frame.piece_count <= MAX_PIECES && frame.expanded_count <= MAX_PIECES; diff --git a/src/mmx_replay.c b/src/mmx_replay.c index df1d53d0b..96b158089 100644 --- a/src/mmx_replay.c +++ b/src/mmx_replay.c @@ -145,7 +145,7 @@ static void hashes(uint32_t *w, uint32_t *c, uint32_t *v, uint32_t *p) { MmxCoopViewWorldState views=MmxCoopViewsGetWorldState(); *w=hash(g_ram,0x20000); *c=hash(&coop,sizeof(coop)); *v=hash(&views,sizeof(views)); MmxCoopViewBoundsState bounds=MmxCoopViewsGetBoundsState(); - if(playback_format>=3 && bounds.valid) *v=hash_continue(*v,&bounds,sizeof(bounds)); + if(playback_format>=3 && (bounds.valid || bounds.camera_valid)) *v=hash_continue(*v,&bounds,sizeof(bounds)); *p=hash(g_ppu->vram,sizeof(g_ppu->vram)); } static void error(const char *why) { @@ -451,7 +451,7 @@ void MmxReplayEnd(void) { MmxCoopViewBoundsState bounds=MmxCoopViewsGetBoundsState(); uint8_t views[sizeof(world)+sizeof(bounds)]; memcpy(views,&world,sizeof(world));memcpy(views+sizeof(world),&bounds,sizeof(bounds)); - size_t view_size=bounds.valid?sizeof(views):sizeof(world); + size_t view_size=(bounds.valid || bounds.camera_valid)?sizeof(views):sizeof(world); if(!SnesReplayWriterFrame(writer,(unsigned)snes_frame_counter,g_ram,0x20000, &coop,sizeof(coop),&views,view_size,g_ppu->vram,sizeof(g_ppu->vram))) error(SnesReplayWriterError(writer)); diff --git a/src/mmx_rtl.c b/src/mmx_rtl.c index 664a332df..50fe3372f 100644 --- a/src/mmx_rtl.c +++ b/src/mmx_rtl.c @@ -368,7 +368,7 @@ void mmx_host_yield(uint8_t countdown) { #include "snes/saveload.h" #define MMX_SAV_CHUNK_MAGIC 0x4D4D5854u /* "MMXT" */ -#define MMX_SAV_CHUNK_VERSION 24u /* donor X armor and charged projectiles */ +#define MMX_SAV_CHUNK_VERSION 25u /* independent native camera pan history */ typedef struct MmxSavChunk { uint32_t magic, version; @@ -491,7 +491,8 @@ void MmxStateLoadExtra(struct SaveLoadInfo *sli, uint32_t version) { memset(&g_load_chunk, 0, sizeof(g_load_chunk)); sli->func(sli, &g_load_chunk, sizeof(g_load_chunk)); if (g_load_chunk.magic == MMX_SAV_CHUNK_MAGIC && - g_load_chunk.version >= 1 && g_load_chunk.version != 23 && g_load_chunk.version <= MMX_SAV_CHUNK_VERSION) + g_load_chunk.version >= 1 && (g_load_chunk.version<22 || g_load_chunk.version>=25) && + g_load_chunk.version <= MMX_SAV_CHUNK_VERSION) g_load_chunk_ok = 1; /* The adaptive playtest wrote a 464-byte v2 chunk, while the shared-host * branch used v2 with appended execution/CHR data. Only the latter has a diff --git a/tests/mmx_adaptive_state_test.c b/tests/mmx_adaptive_state_test.c index 9a723a4ff..4bc41fbc0 100644 --- a/tests/mmx_adaptive_state_test.c +++ b/tests/mmx_adaptive_state_test.c @@ -2057,6 +2057,7 @@ int main(int argc, char **argv) { if(getenv("MMX_COOP_VIEWS_BOOT_TEST") || getenv("MMX_LOCAL_VIEWS_TEST")) { coop_view_boot_checks(zero_assets,start,expected,actual,cap);return 0; } + if(getenv("MMX_COOP_PAN_TEST")) { coop_camera_pan_checks(zero_assets,getenv("MMX_COOP_PAN_TEST"),start,expected,actual,cap);return 0; } if(getenv("MMX_COOP_REPLAY")) { coop_replay_probe(zero_assets,getenv("MMX_COOP_REPLAY")); return 0; } if(getenv("MMX_COOP_ZERO_SLOPE_FIXTURE")) { coop_zero_slope_burst_checks(zero_assets,getenv("MMX_COOP_ZERO_SLOPE_FIXTURE")); return 0; } if(getenv("MMX_COOP_ARMOR_PILOT_FIXTURE")) { coop_armor_pilot_checks(zero_assets,getenv("MMX_COOP_ARMOR_PILOT_FIXTURE")); return 0; } diff --git a/tests/mmx_coop_camera_test.inc b/tests/mmx_coop_camera_test.inc new file mode 100644 index 000000000..5c9686564 --- /dev/null +++ b/tests/mmx_coop_camera_test.inc @@ -0,0 +1,48 @@ +/* Room transitions must move through the native two-pixel pan, rather than + * jump to the target bounds. Run on both raster implementations/seats. */ +static void independent_camera_pan(void) { + memset(ram,0,sizeof(ram));ram[0xd3]=4; + put_word(0x1e52,2);put_word(0x1e54,8); + put_word(0x1e74,128);put_word(0x1e76,128); + put_word(0x1e70,160);put_word(0x1e72,160); + MmxCoopViewsSetActive(true); + for(unsigned anchor=0;anchor<2;++anchor) for(unsigned reverse=0;reverse<2;++reverse) { + MmxCoopState s={0};s.initialized=1;s.current=s.anchor=(uint8_t)anchor; + for(unsigned seat=0;seat<2;++seat) { + s.players[seat].status=MMX_COOP_ALIVE;s.players[seat].body[0x27]=16; + unsigned position=reverse?32:800; + for(unsigned off=5;off<=8;off+=3) { + s.players[seat].body[off]=(uint8_t)position; + s.players[seat].body[off+1]=(uint8_t)(position>>8); + unsigned previous=off==5?0x22:0x24; + s.players[seat].body[previous]=(uint8_t)position; + s.players[seat].body[previous+1]=(uint8_t)(position>>8); + } + } + MmxCoopViewBoundsState b={0};b.valid=b.camera_valid=3; + unsigned initial=reverse?400:100,target=reverse?100:400; + for(unsigned seat=0;seat<2;++seat) { + b.camera[seat][0]=b.camera[seat][1]=(uint16_t)initial; + for(unsigned i=0;i<4;++i) {b.current[seat][i]=(uint16_t)initial;b.limits[seat][i]=(uint16_t)target;} + } + MmxCoopViewsSetBoundsState(&b); + for(unsigned tick=0;tick<180;++tick) { + MmxCoopViewsEndFrame(ram,&s); + MmxCoopView v=MmxCoopViewForPlayer(ram,&s,anchor^1); + int expected=reverse?(int)initial-(int)(tick*2):(int)initial+(int)(tick*2); + if(reverse && expected<(int)target) expected=(int)target; + if(!reverse && expected>(int)target) expected=(int)target; + if(v.x!=expected || v.y!=expected) fprintf(stderr,"camera pan anchor=%u reverse=%u tick=%u xy=%d,%d expected=%d\n",anchor,reverse,tick,v.x,v.y,expected); + assert(v.x==expected && v.y==expected); + } + b=MmxCoopViewsGetBoundsState();assert(MmxCoopViewsValidBoundsState(&b)); + s.menu_owner=1;MmxCoopViewsEndFrame(ram,&s); + MmxCoopViewBoundsState paused=MmxCoopViewsGetBoundsState(); + assert(!memcmp(&b,&paused,sizeof(b))); + s.menu_owner=0;s.scene_owner=1;MmxCoopViewsEndFrame(ram,&s); + assert(!MmxCoopViewsGetBoundsState().camera_valid); + MmxCoopViewsSetBoundsState(&b); + assert(MmxCoopViewForPlayer(ram,&s,anchor^1).x==0); /* shared script */ + } + MmxCoopViewsResetWorld();MmxCoopViewsSetActive(false); +} diff --git a/tests/mmx_coop_views_test.inc b/tests/mmx_coop_views_test.inc index 2f6d865e3..b0deae4f2 100644 --- a/tests/mmx_coop_views_test.inc +++ b/tests/mmx_coop_views_test.inc @@ -301,3 +301,49 @@ static void coop_view_checks(const char *fixture,uint8_t *start,uint8_t *expecte MmxRendererSetPeerView(-1); puts("MMX CO-OP INDEPENDENT VIEW CHECKS PASSED"); } + +/* Retail inputs defeat Bee Blader normally; observe the native room pan and + * the partner's continuous camera, then restore in the middle of that pan. */ +static void coop_camera_pan_checks(const char *assets,const char *path, + uint8_t *start,uint8_t *expected,uint8_t *actual,size_t cap) { + static CoopReplay r;coop_replay_load(path,&r);coop_replay_start(assets); + MmxCoopViewsSetLocalSplit(true); + unsigned bee=0,pans=0,shared=0;bool seen=false,defeated=false; + size_t snapshot=0;unsigned restore_tick=0;bool restored=false; + MmxCoopView previous={0}; + for(unsigned tick=0;tick1 && b.camera_valid==3) + check(abs(v.y-previous.y)<=8,"released partner camera stays within native tracking speed"); + previous=v; + if(snapshot && tick==restore_tick+90) { + size_t en=RtlSaveSnapshotToMemory(expected,cap); + check(RtlLoadSnapshotFromMemory(start,snapshot),"mid-pan checkpoint loads"); + for(unsigned t=restore_tick;t<=tick;++t) coop_frames(1,r.p1[t],r.p2[t]); + same(expected,en,actual,RtlSaveSnapshotToMemory(actual,cap),"camera pan history replays byte-exactly"); + snapshot=0;restored=true; + } + } + fprintf(stderr,"Bee Blader pan frames: encounter=%u pans=%u shared=%u defeated=%u\n",bee,pans,shared,defeated); + check(seen && defeated && pans && shared,"retail route defeats Bee Blader and exercises its room pan"); + puts("MMX CO-OP CAMERA PAN CHECKS PASSED"); +} diff --git a/tests/mmx_renderer_test.c b/tests/mmx_renderer_test.c index a3dd0dabd..6903bf456 100644 --- a/tests/mmx_renderer_test.c +++ b/tests/mmx_renderer_test.c @@ -1804,4 +1804,5 @@ static void rush_results_page(void) { assert((output[48*256+92]&0xffffff)==0x00ffff); MmxBossRushReset(); } -int main(void) { geometry(); raster_and_hud(); immutable_vram_raster(); stage_map_draw_lifetime(); sprite_coordinates(); independent_oam_visibility(); expanded_capacity(); background_resources(); dialogue_and_password(); highway_arena_sky(); highway_airship_binding(); distant_doors(); storm_background_prefill(); resource_decode(); spark_effects(); airport_panorama_edge(); airport_upper_sky_repair(); wide_water_plane(); buried_submarine(); background_continuations(); launch_background_palettes(); sting_background_palettes(); mammoth_background_palettes(); dialogue_backdrop(); fortress_actor_presentation(); storm_dormant_presentation(); sprite_priority_and_cutscene_binding(); weapons_menu_margins(); zero_blink_submission(); rush_private_pose_graphics(); rush_static_and_streamed_graphics(); rush_results_page(); coop_special_graphics(); armor_menu_and_hud(); return 0; } +#include "mmx_coop_camera_test.inc" +int main(void) { independent_camera_pan(); geometry(); raster_and_hud(); immutable_vram_raster(); stage_map_draw_lifetime(); sprite_coordinates(); independent_oam_visibility(); expanded_capacity(); background_resources(); dialogue_and_password(); highway_arena_sky(); highway_airship_binding(); distant_doors(); storm_background_prefill(); resource_decode(); spark_effects(); airport_panorama_edge(); airport_upper_sky_repair(); wide_water_plane(); buried_submarine(); background_continuations(); launch_background_palettes(); sting_background_palettes(); mammoth_background_palettes(); dialogue_backdrop(); fortress_actor_presentation(); storm_dormant_presentation(); sprite_priority_and_cutscene_binding(); weapons_menu_margins(); zero_blink_submission(); rush_private_pose_graphics(); rush_static_and_streamed_graphics(); rush_results_page(); coop_special_graphics(); armor_menu_and_hud(); return 0; } diff --git a/tools/make_release.ps1 b/tools/make_release.ps1 index 10ae5ca51..d75a35765 100644 --- a/tools/make_release.ps1 +++ b/tools/make_release.ps1 @@ -78,6 +78,7 @@ $stageDocs = Join-Path $stage 'docs' New-Item -ItemType Directory -Path $stageDocs -Force | Out-Null Copy-Item -LiteralPath (Join-Path $root 'docs/screenshots') -Destination $stageDocs -Recurse Copy-Item -LiteralPath (Join-Path $root 'docs/boss-rush.md') -Destination $stageDocs +Copy-Item -LiteralPath (Join-Path $root 'docs/local-independent-views.md') -Destination $stageDocs Copy-Item -LiteralPath $assets -Destination $stage -Recurse if (Test-Path -LiteralPath $mods) { Copy-Item -LiteralPath $mods -Destination $stage -Recurse From 5cf5a11d6160d93ff295b9093583d17c56f7e758 Mon Sep 17 00:00:00 2001 From: Matt Stanley <5354790+mstan@users.noreply.github.com> Date: Sun, 1 Nov 2026 13:58:12 -0800 Subject: [PATCH 3/4] Qualify camera pans through the retail Bee Blader transition --- tests/mmx_coop_replay_test.inc | 46 ++++++++++++++++++++++++++++++++++ tests/mmx_coop_views_test.inc | 46 ---------------------------------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/tests/mmx_coop_replay_test.inc b/tests/mmx_coop_replay_test.inc index 43e4e9e66..d04f42951 100644 --- a/tests/mmx_coop_replay_test.inc +++ b/tests/mmx_coop_replay_test.inc @@ -253,3 +253,49 @@ static void coop_zero_slope_burst_checks(const char *assets, const char *fixture } puts("MMX CO-OP ZERO SLOPE BURST CHECKS PASSED"); } + +/* Prepare the encounter with the existing unified input route, then switch + * to local views before the fight ends. No boss/progression flags are set. */ +static void coop_camera_pan_checks(const char *assets,const char *path, + uint8_t *start,uint8_t *expected,uint8_t *actual,size_t cap) { + static CoopReplay r;coop_replay_load(path,&r);coop_replay_start(assets); + MmxCoopViewsSetLocalSplit(false); + unsigned bee=0,pans=0,shared=0;bool seen=false,defeated=false; + size_t snapshot=0;unsigned restore_tick=0;bool restored=false; + MmxCoopView previous={0}; + for(unsigned tick=0;tick1 && b.camera_valid==3) + check(abs(v.y-previous.y)<=8,"released partner camera stays within native tracking speed"); + previous=v; + if(snapshot && tick==restore_tick+90) { + size_t en=RtlSaveSnapshotToMemory(expected,cap); + check(RtlLoadSnapshotFromMemory(start,snapshot),"mid-pan checkpoint loads"); + for(unsigned t=restore_tick;t<=tick;++t) coop_frames(1,r.p1[t],r.p2[t]); + same(expected,en,actual,RtlSaveSnapshotToMemory(actual,cap),"camera pan history replays byte-exactly"); + snapshot=0;restored=true; + } + } + fprintf(stderr,"Bee Blader pan frames: encounter=%u pans=%u shared=%u defeated=%u\n",bee,pans,shared,defeated); + check(seen && defeated && pans && shared,"retail route defeats Bee Blader and exercises its room pan"); + puts("MMX CO-OP CAMERA PAN CHECKS PASSED"); +} diff --git a/tests/mmx_coop_views_test.inc b/tests/mmx_coop_views_test.inc index b0deae4f2..2f6d865e3 100644 --- a/tests/mmx_coop_views_test.inc +++ b/tests/mmx_coop_views_test.inc @@ -301,49 +301,3 @@ static void coop_view_checks(const char *fixture,uint8_t *start,uint8_t *expecte MmxRendererSetPeerView(-1); puts("MMX CO-OP INDEPENDENT VIEW CHECKS PASSED"); } - -/* Retail inputs defeat Bee Blader normally; observe the native room pan and - * the partner's continuous camera, then restore in the middle of that pan. */ -static void coop_camera_pan_checks(const char *assets,const char *path, - uint8_t *start,uint8_t *expected,uint8_t *actual,size_t cap) { - static CoopReplay r;coop_replay_load(path,&r);coop_replay_start(assets); - MmxCoopViewsSetLocalSplit(true); - unsigned bee=0,pans=0,shared=0;bool seen=false,defeated=false; - size_t snapshot=0;unsigned restore_tick=0;bool restored=false; - MmxCoopView previous={0}; - for(unsigned tick=0;tick1 && b.camera_valid==3) - check(abs(v.y-previous.y)<=8,"released partner camera stays within native tracking speed"); - previous=v; - if(snapshot && tick==restore_tick+90) { - size_t en=RtlSaveSnapshotToMemory(expected,cap); - check(RtlLoadSnapshotFromMemory(start,snapshot),"mid-pan checkpoint loads"); - for(unsigned t=restore_tick;t<=tick;++t) coop_frames(1,r.p1[t],r.p2[t]); - same(expected,en,actual,RtlSaveSnapshotToMemory(actual,cap),"camera pan history replays byte-exactly"); - snapshot=0;restored=true; - } - } - fprintf(stderr,"Bee Blader pan frames: encounter=%u pans=%u shared=%u defeated=%u\n",bee,pans,shared,defeated); - check(seen && defeated && pans && shared,"retail route defeats Bee Blader and exercises its room pan"); - puts("MMX CO-OP CAMERA PAN CHECKS PASSED"); -} From 7592a2005ff833b196807c3f7671e2467cabf5bd Mon Sep 17 00:00:00 2001 From: Matt Stanley <5354790+mstan@users.noreply.github.com> Date: Sun, 1 Nov 2026 13:59:27 -0800 Subject: [PATCH 4/4] Keep restored camera history when replay enables local views --- src/mmx_coop_view.c | 4 +++- tests/mmx_coop_camera_test.inc | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mmx_coop_view.c b/src/mmx_coop_view.c index 038d0f7dc..920d4a4e1 100644 --- a/src/mmx_coop_view.c +++ b/src/mmx_coop_view.c @@ -45,7 +45,9 @@ void MmxCoopViewsMark(unsigned flag,bool seen) { if(seen) world.seen[n]|=bit;else world.seen[n]&=~bit; } void MmxCoopViewsSetActive(bool enabled) { - if(active!=enabled) bounds.camera_valid=0; + /* Enabling after a checkpoint load must retain its restored pan history. + * An inactive simulation discards history before it can become stale. */ + if(!enabled) bounds.camera_valid=0; active=enabled; } bool MmxCoopViewsActive(void) { return active; } diff --git a/tests/mmx_coop_camera_test.inc b/tests/mmx_coop_camera_test.inc index 5c9686564..c61d6e04b 100644 --- a/tests/mmx_coop_camera_test.inc +++ b/tests/mmx_coop_camera_test.inc @@ -43,6 +43,9 @@ static void independent_camera_pan(void) { assert(!MmxCoopViewsGetBoundsState().camera_valid); MmxCoopViewsSetBoundsState(&b); assert(MmxCoopViewForPlayer(ram,&s,anchor^1).x==0); /* shared script */ + MmxCoopViewsSetActive(false);MmxCoopViewsSetBoundsState(&b); + MmxCoopViewsSetActive(true);s.scene_owner=0; + assert(MmxCoopViewForPlayer(ram,&s,anchor^1).x==(int)target); } MmxCoopViewsResetWorld();MmxCoopViewsSetActive(false); }