Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
34 changes: 34 additions & 0 deletions docs/local-independent-views.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.
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
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`.
16 changes: 15 additions & 1 deletion mods/preloaded/packages/megaman-x.coop/0.0.1/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
68 changes: 58 additions & 10 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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. */
Expand Down Expand Up @@ -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");
}
Expand All @@ -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<h;++y)
memcpy(output+y*pane+(pane-256)/2,field+y*256*4,256*4);
return SnesLocalViews_ComposeSideBySide(dst,pitch,pane,h,output,(size_t)pane*4,NULL,0);
}
bool ready=false;
#if MMX_NATIVE_RASTER
ready=s_composed_ready && s_composed_view.width==g_mmx_custom_view.width &&
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;
#endif
Expand All @@ -196,11 +236,19 @@ static int MmxDrawFrame(uint8_t *dst, size_t pitch, const uint8_t *field,
return 1;
}
static void MmxViewport(int w, int h, int dw, int dh, SnesDisplayViewport *view) {
if (g_mmx_custom_renderer) *view = MmxRendererDestination(g_mmx_custom_view, dw, dh);
if(MmxLocalSplit()) *view=SnesLocalViews_Viewport(g_mmx_custom_view.aspect,dw,dh);
else if (g_mmx_custom_renderer) *view = MmxRendererDestination(g_mmx_custom_view, dw, dh);
else MmxDisplay_ComputeViewport(w, h, dw, dh,
SnesDisplayAspect_Clamp(g_config.display_aspect), g_config.ignore_aspect_ratio, false, view);
}
static int MmxWindowWidth(int w) {
if(MmxLocalSplit()) {
double aspect=!g_config.widescreen ? 5.0/4 :
g_mmx_custom_aspect==MMX_ASPECT_21_9 ? 21.0/9 :
g_mmx_custom_aspect==MMX_ASPECT_32_9 ? 32.0/9 :
g_mmx_custom_aspect==MMX_ASPECT_16_9 ? 16.0/9 : g_mmx_custom_view.aspect;
return (int)(2*aspect*MmxDisplay_GetWindowBaseHeight()+.5);
}
return MmxDisplay_GetWindowBaseWidth(w, SnesDisplayAspect_Clamp(MmxNetplayActive() ? 0 : g_config.display_aspect));
}

Expand Down
20 changes: 10 additions & 10 deletions src/mmx_coop.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static bool scene_tick(uint8_t *r);
static unsigned word(const uint8_t *p) {return p[0]|p[1]<<8;}
static void putword(uint8_t *p,unsigned v) {p[0]=(uint8_t)v;p[1]=(uint8_t)(v>>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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<LEARNER_AWAY_FRAMES) return;
}
learner_scene(r,MMX_COOP_SCENE_LIVE);
Expand Down Expand Up @@ -1949,7 +1949,7 @@ static bool lift_elevator(unsigned d);
static bool capsule_slot(unsigned d);
static bool platform_item(unsigned d);
static bool object_ghost_wanted(unsigned d) {
if(MmxCoopViewsOnline() || state.menu_owner || state.scene_owner || state.contact_pass ||
if(MmxCoopViewsActive() || state.menu_owner || state.scene_owner || state.contact_pass ||
state.object_pass || g_ram[0xd3]!=4 || state.current!=state.anchor || !ghost_partner_ready()) return false;
bool enemy=d>=0xe68 && d<0x1228 && !((d-0xe68)%64);
bool projectile=d>=0x1428 && d<0x1628 && !((d-0x1428)%64);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)<bound) putword(g_ram,bound);
return;
}
/* Learner Mode: the camera follows P1 alone. */
if (!shared_screen() || MmxCoopViewsOnline() || learner_mode) return;
if (!shared_screen() || MmxCoopViewsActive() || learner_mode) return;
unsigned axis=((pc&65535)==0xdebf || (pc&65535)==0xdeca) ? 8 : 5;
/* Round the midpoint toward the world actor. Plain (a+b)/2 floors, so
* two bodies falling at the same speed one subpixel phase apart (1 px gap
Expand Down Expand Up @@ -2502,7 +2502,7 @@ void MmxCoopTraceFrame(const uint8_t *r) {
if (g_mmx_coop_trace && enabled && state.initialized) MmxCoopTraceFrameEnd(&state,r);
}
static void view_world_hook(CpuState *cpu,uint32_t pc) {
if(!MmxCoopViewsOnline() || !enabled || !state.initialized || state.stage_pending ||
if(!MmxCoopViewsActive() || !enabled || !state.initialized || state.stage_pending ||
state.menu_owner || state.scene_owner || g_ram[0xd3]!=4) {
MmxWsCullHook(cpu,pc);return;
}
Expand Down Expand Up @@ -2595,7 +2595,7 @@ static void view_actor_hook(CpuState *cpu,uint32_t pc) {
}
MmxCoopViewsActorReturn(state.current+1);MmxCoopSelect(g_ram,xs);return;
}
if(!MmxCoopViewsOnline() && !(returning ? world.actor_return :
if(!MmxCoopViewsActive() && !(returning ? world.actor_return :
(at==0xd4f6 || at==0xd515) && couch_nearest_target(cpu->D))) return;
if(returning) {
if(world.actor_return) {
Expand Down
Loading
Loading