Remove two-player hack for controlled warp

This commit is contained in:
MysterD 2020-10-15 18:04:53 -07:00
parent 48aee0c7be
commit 9f158de95d
6 changed files with 24 additions and 20 deletions

View File

@ -49,7 +49,7 @@
#define WARP_NODE_CREDITS_MIN 0xF8
struct SavedWarpValues gReceiveWarp = { 0 };
u8 gControlledWarp = 0;
u8 gControlledWarpGlobalIndex = 0;
extern s8 sReceivedLoadedActNum;
u8 gRejectInstantWarp = 0;
@ -1028,7 +1028,7 @@ static void check_received_warp(void) {
D_80339EE0 = gReceiveWarp.D_80339EE0;
gPaintingMarioYEntry = gReceiveWarp.paintingMarioYEntry;
if (!gControlledWarp) {
if (gControlledWarpGlobalIndex != gNetworkPlayerLocal->globalIndex) {
// force well behaved state
extern s16 gMenuMode;
gMenuMode = -1;

View File

@ -55,7 +55,7 @@ s8 sSelectableStarIndex = 0;
// Act Selector menu timer that keeps counting until you choose an act.
static s32 sActSelectorMenuTimer = 0;
extern u8 gControlledWarp;
extern u8 gControlledWarpGlobalIndex;
/**
* Act Selector Star Type Loop Action
@ -177,7 +177,7 @@ void bhv_act_selector_loop(void) {
// Sometimes, stars are not selectable even if they appear on the screen.
// This code filters selectable and non-selectable stars.
sSelectedActIndex = 0;
if (gControlledWarp) {
if (gControlledWarpGlobalIndex == gNetworkPlayerLocal->globalIndex) {
s8 oldIndex = sSelectableStarIndex;
handle_menu_scrolling(MENU_SCROLL_HORIZONTAL, &sSelectableStarIndex, 0, sObtainedStars);
if (oldIndex != sSelectableStarIndex) { network_send_inside_painting(); }
@ -195,7 +195,7 @@ void bhv_act_selector_loop(void) {
}
} else {
// If all stars are collected then they are all selectable.
if (gControlledWarp) {
if (gControlledWarpGlobalIndex == gNetworkPlayerLocal->globalIndex) {
s8 oldIndex = sSelectableStarIndex;
handle_menu_scrolling(MENU_SCROLL_HORIZONTAL, &sSelectableStarIndex, 0, sVisibleStars - 1);
if (oldIndex != sSelectableStarIndex) { network_send_inside_painting(); }
@ -299,7 +299,7 @@ void print_act_selector_strings(void) {
create_dl_ortho_matrix();
// display disclaimer that the other player has to select
if (!gControlledWarp) {
if (gControlledWarpGlobalIndex != gNetworkPlayerLocal->globalIndex) {
gSPDisplayList(gDisplayListHead++, dl_ia_text_begin);
u8 a = ((gGlobalTimer % 24) >= 12) ? 160 : 130;
gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, a);
@ -436,7 +436,7 @@ s32 lvl_init_act_selector_values_and_stars(UNUSED s32 arg, UNUSED s32 unused) {
* Also updates objects and returns act number selected after is chosen.
*/
s32 lvl_update_obj_and_load_act_button_actions(UNUSED s32 arg, UNUSED s32 unused) {
if (gControlledWarp && sActSelectorMenuTimer >= 11) {
if ((gControlledWarpGlobalIndex == gNetworkPlayerLocal->globalIndex) && sActSelectorMenuTimer >= 11) {
// If any of these buttons are pressed, play sound and go to course act
#ifndef VERSION_EU
if ((gPlayer3Controller->buttonPressed & A_BUTTON)
@ -473,5 +473,5 @@ void star_select_finish_selection(void) {
}
gDialogCourseActNum = sSelectedActIndex + 1;
if (gControlledWarp) { network_send_inside_painting(); }
if (gControlledWarpGlobalIndex == gNetworkPlayerLocal->globalIndex) { network_send_inside_painting(); }
}

View File

@ -5,7 +5,7 @@
#define DISABLE_MODULE_LOG
#include "pc/debuglog.h"
extern u8 gControlledWarp;
extern u8 gControlledWarpGlobalIndex;
extern u8 sSelectableStarIndex;
extern u8 sSelectedActIndex;
@ -42,8 +42,7 @@ void network_receive_inside_painting(struct Packet* p) {
struct PacketInsidePaintingData remote = { 0 };
packet_read(p, &remote, sizeof(struct PacketInsidePaintingData));
// two-player hack: gControlledWarp is a bool instead of an index
if (gControlledWarp) {
if (gControlledWarpGlobalIndex == gNetworkPlayerLocal->globalIndex) {
LOG_ERROR("this should never happen, received inside_painting when gControlledWarp");
return;
}

View File

@ -7,13 +7,16 @@
#define DISABLE_MODULE_LOG
#include "pc/debuglog.h"
// two-player hack
// this entire system needs to be ripped out and replaced
static u8 eventId = 0;
static u8 remoteFinishedEventId[2] = { (u8)-1, (u8)-1 };
extern s16 gTTCSpeedSetting;
extern s16 D_80339EE0;
extern float gPaintingMarioYEntry;
extern u8 gControlledWarp; // two-player hack
extern u8 gControlledWarpGlobalIndex;
extern struct SavedWarpValues gReceiveWarp;
struct SavedWarpValues saved = { 0 };
@ -36,7 +39,7 @@ struct PacketLevelWarpData {
static void populate_packet_data(struct PacketLevelWarpData* data, bool done, u8 packetEventId) {
data->eventId = packetEventId;
data->done = done;
data->controlledWarp = gControlledWarp;
data->controlledWarp = gControlledWarpGlobalIndex;
data->warpDest = saved.warpDest;
data->inWarpCheckpoint = saved.inWarpCheckpoint;
data->ttcSpeedSetting = saved.ttcSpeedSetting;
@ -53,9 +56,9 @@ void network_send_level_warp_begin(void) {
saved.paintingMarioYEntry = gPaintingMarioYEntry;
float elapsedSinceDone = (clock() - lastDoneEvent) / CLOCKS_PER_SEC;
gControlledWarp = (elapsedSinceDone < 1.0f)
? (gNetworkType == NT_SERVER) // two-player hack
: true;
gControlledWarpGlobalIndex = (elapsedSinceDone < 1.0f)
? 0
: gNetworkPlayerLocal->globalIndex;
eventId++;
if (eventId == (u8)-1) { eventId++; }
@ -136,7 +139,7 @@ void network_receive_level_warp(struct Packet* p) {
} else if (!isInWarp) {
// client initiated warp
LOG_INFO("client initiated warp!");
gControlledWarp = !remote.controlledWarp; // two-player hack
gControlledWarpGlobalIndex = remote.controlledWarp;
saved.warpDest = remote.warpDest;
saved.inWarpCheckpoint = remote.inWarpCheckpoint;
@ -165,7 +168,7 @@ void network_receive_level_warp(struct Packet* p) {
// server initiated warp
LOG_INFO("server initiated warp!");
gControlledWarp = !remote.controlledWarp; // two-player hack
gControlledWarpGlobalIndex = remote.controlledWarp;
saved.warpDest = remote.warpDest;
saved.inWarpCheckpoint = remote.inWarpCheckpoint;

View File

@ -6,6 +6,7 @@
#include "course_table.h"
#include "src/game/interaction.h"
#include "src/engine/math_util.h"
#include "pc/debuglog.h"
#define RESERVATION_COUNT 10
@ -51,6 +52,7 @@ void network_send_reservation(u8 toLocalIndex) {
packet_init(&p, PACKET_RESERVATION, true, false);
packet_write(&p, reservedObjs, sizeof(u8) * RESERVATION_COUNT);
network_send_to(toLocalIndex, &p);
LOG_INFO("sent reservation list to %d", toLocalIndex);
}
void network_receive_reservation(struct Packet* p) {
@ -66,4 +68,5 @@ void network_receive_reservation(struct Packet* p) {
if (gSyncObjects[index].o != NULL) { continue; }
gSyncObjects[index].reserved = gNetworkPlayerLocal->globalIndex;
}
LOG_INFO("received reservation list");
}

View File

@ -64,8 +64,7 @@ void network_receive_spawn_objects(struct Packet* p) {
packet_read(p, &objectCount, sizeof(u8));
// two-player hack
u8 reserveId = (gNetworkLevelLoaded && gNetworkType == NT_SERVER) ? 1 : 0;
u8 reserveId = gNetworkLevelLoaded ? gNetworkPlayers[p->localIndex].globalIndex : 0;
bool receivedReservedSyncObject = false;
struct Object* spawned[MAX_SPAWN_OBJECTS_PER_PACKET] = { 0 };