Force synchronizing of level changes

This commit is contained in:
MysterD 2020-08-02 23:02:29 -07:00
parent 9b5b5acf19
commit ec2199892f
18 changed files with 21427 additions and 20 deletions

View file

@ -3944,6 +3944,7 @@
<ClCompile Include="..\src\pc\ini.c" />
<ClCompile Include="..\src\pc\mixer.c" />
<ClCompile Include="..\src\pc\network\network.c" />
<ClCompile Include="..\src\pc\network\packets\packet_level_warp.c" />
<ClCompile Include="..\src\pc\network\packets\packet_object.c" />
<ClCompile Include="..\src\pc\network\packets\packet_player.c" />
<ClCompile Include="..\src\pc\network\packets\packet_read_write.c" />

View file

@ -14952,6 +14952,9 @@
<ClCompile Include="..\src\pc\network\packets\packet_read_write.c">
<Filter>Source Files\src\pc\network\packets</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\network\packets\packet_level_warp.c">
<Filter>Source Files\src\pc\network\packets</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\actors\common0.h">

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.18362.0
Debug|x64|X:\Projects\sm64ex\build-windows-visual-studio\|

View file

@ -365,4 +365,11 @@ struct MarioState
/*0xC4*/ f32 unkC4;
};
#define PLAY_MODE_NORMAL 0
#define PLAY_MODE_PAUSED 2
#define PLAY_MODE_CHANGE_AREA 3
#define PLAY_MODE_CHANGE_LEVEL 4
#define PLAY_MODE_FRAME_ADVANCE 5
#define PLAY_MODE_SYNC_LEVEL 6
#endif // _SM64_TYPES_H_

View file

@ -1,5 +1,5 @@
set -e
make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1
./build/us_pc/sm64.us.f3dex2e.exe --server --configfile sm64config_server.txt &
./build/us_pc/sm64.us.f3dex2e.exe --client --configfile sm64config_client.txt &
#winpty cgdb ./build/us_pc/sm64.us.f3dex2e.exe -ex 'run --client --configfile sm64config_client.txt' -ex 'quit'
#./build/us_pc/sm64.us.f3dex2e.exe --client --configfile sm64config_client.txt &
winpty cgdb ./build/us_pc/sm64.us.f3dex2e.exe -ex 'run --client --configfile sm64config_client.txt' -ex 'quit'

View file

@ -1898,7 +1898,7 @@ void render_dialog_entries(void) {
// Calls a gMenuMode value defined by render_menus_and_dialogs cases
void set_menu_mode(s16 mode) {
if (gMenuMode == -1) {
if (gMenuMode == -1 || mode == -1) {
gMenuMode = mode;
}
}
@ -2751,6 +2751,28 @@ s16 render_pause_courses_and_castle(void) {
return 0;
}
s16 render_sync_level_screen(void) {
// black screen
create_dl_translation_matrix(MENU_MTX_PUSH, GFX_DIMENSIONS_FROM_LEFT_EDGE(0), 240.0f, 0);
create_dl_scale_matrix(MENU_MTX_NOPUSH,
GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_HEIGHT / 130.0f, 3.0f, 1.0f);
gDPSetEnvColor(gDisplayListHead++, 0, 0, 0, 255);
gSPDisplayList(gDisplayListHead++, dl_draw_text_bg_box);
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
// text
u8 colorFade = sins(gDialogColorFadeTimer) * 50.0f + 200.0f;
gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin);
gDPSetEnvColor(gDisplayListHead++, colorFade, colorFade, colorFade, 255);
u8 synchronizing[] = { 0x1C,0x22,0x17,0x0C,0x11,0x1B,0x18,0x17,0x12,0x02,0x12,0x17,0x10,0xFF };
// s y n c h r o n i z i n g \0
print_hud_lut_string(HUD_LUT_GLOBAL, 70, 200, synchronizing);
gSPDisplayList(gDisplayListHead++, dl_rgba16_text_end);
return 0;
}
#if defined(VERSION_JP) || defined(VERSION_SH)
#define TXT_HISCORE_X 112
#define TXT_HISCORE_Y 48
@ -3138,6 +3160,9 @@ s16 render_menus_and_dialogs() {
case 3:
mode = render_course_complete_screen();
break;
case 4:
mode = render_sync_level_screen();
break;
}
gDialogColorFadeTimer = (s16) gDialogColorFadeTimer + 0x1000;

View file

@ -29,6 +29,7 @@
#define RENDER_PAUSE_SCREEN 1
#define RENDER_COURSE_DONE_SCREEN 2
#define RENDER_SYNC_LEVEL_SCREEN 4
extern s8 gDialogCourseActNum;

View file

@ -34,12 +34,7 @@
#include "pc/pc_main.h"
#include "pc/cliopts.h"
#include "pc/configfile.h"
#define PLAY_MODE_NORMAL 0
#define PLAY_MODE_PAUSED 2
#define PLAY_MODE_CHANGE_AREA 3
#define PLAY_MODE_CHANGE_LEVEL 4
#define PLAY_MODE_FRAME_ADVANCE 5
#include "pc/network/network.h"
#define WARP_TYPE_NOT_WARPING 0
#define WARP_TYPE_CHANGE_LEVEL 1
@ -1040,6 +1035,11 @@ s32 play_mode_paused(void) {
return 0;
}
s32 play_mode_sync_level(void) {
set_menu_mode(RENDER_SYNC_LEVEL_SCREEN);
return 0;
}
/**
* Debug mode that lets you frame advance by pressing D-pad down. Unfortunately
* it uses the pause camera, making it basically unusable in most levels.
@ -1154,6 +1154,9 @@ s32 update_level(void) {
case PLAY_MODE_FRAME_ADVANCE:
changeLevel = play_mode_frame_advance();
break;
case PLAY_MODE_SYNC_LEVEL:
changeLevel = play_mode_sync_level();
break;
}
if (changeLevel) {
@ -1229,6 +1232,9 @@ s32 init_level(void) {
sound_banks_disable(2, 0x0330);
}
if (networkType != NT_NONE) {
set_play_mode(PLAY_MODE_SYNC_LEVEL);
}
return 1;
}

View file

@ -26,6 +26,7 @@
#define WARP_OP_CREDITS_START 0x17
#define WARP_OP_CREDITS_NEXT 0x18
#define WARP_OP_DEMO_END 0x19
#define WARP_OP_FORCE_SYNC 0x20
#define WARP_OP_TRIGGERS_LEVEL_SELECT 0x10
@ -129,4 +130,6 @@ s32 lvl_set_current_level(UNUSED s16 arg0, s32 levelNum);
s32 lvl_play_the_end_screen_sound(UNUSED s16 arg0, UNUSED s32 arg1);
void basic_update(UNUSED s16 *arg);
s32 init_level(void);
#endif // LEVEL_UPDATE_H

View file

@ -939,9 +939,11 @@ s32 act_going_through_door(struct MarioState *m) {
set_mario_animation(m, MARIO_ANIM_PUSH_DOOR_WALK_IN);
}
}
m->faceAngle[1] = m->usedObj->oMoveAngleYaw;
m->pos[0] = m->usedObj->oPosX;
m->pos[2] = m->usedObj->oPosZ;
if (m->usedObj != NULL) {
m->faceAngle[1] = m->usedObj->oMoveAngleYaw;
m->pos[0] = m->usedObj->oPosX;
m->pos[2] = m->usedObj->oPosZ;
}
update_mario_pos_for_anim(m);
stop_and_set_height_to_floor(m);
@ -966,12 +968,15 @@ s32 act_going_through_door(struct MarioState *m) {
s32 act_warp_door_spawn(struct MarioState *m) {
if (m->actionState == 0) {
m->actionState = 1;
if (m->actionArg & 1) {
m->usedObj->oInteractStatus = 0x00040000;
} else {
m->usedObj->oInteractStatus = 0x00080000;
if (m->usedObj != NULL) {
if (m->actionArg & 1) {
m->usedObj->oInteractStatus = 0x00040000;
}
else {
m->usedObj->oInteractStatus = 0x00080000;
}
}
} else if (m->usedObj->oAction == 0) {
} else if (m->usedObj == NULL || m->usedObj->oAction == 0) {
if (gShouldNotPlayCastleMusic == TRUE && gCurrLevelNum == LEVEL_CASTLE) {
set_mario_action(m, ACT_READING_AUTOMATIC_DIALOG, DIALOG_021);
} else {

View file

@ -76,8 +76,12 @@ void network_send(struct Packet* p) {
void network_update(void) {
if (networkType == NT_NONE) { return; }
network_update_player();
network_update_objects();
if (sCurrPlayMode == PLAY_MODE_SYNC_LEVEL) {
network_update_level_warp();
} else {
network_update_player();
network_update_objects();
}
do {
struct sockaddr_in rxAddr;
@ -96,6 +100,7 @@ void network_update(void) {
switch (p.buffer[0]) {
case PACKET_PLAYER: network_receive_player(&p); break;
case PACKET_OBJECT: network_receive_object(&p); break;
case PACKET_LEVEL_WARP: network_receive_level_warp(&p); break;
default: printf("%s received unknown packet: %d\n", NETWORKTYPESTR, p.buffer[0]);
}

View file

@ -12,7 +12,8 @@
enum PacketType {
PACKET_PLAYER,
PACKET_OBJECT
PACKET_OBJECT,
PACKET_LEVEL_WARP,
};
struct Packet {
@ -31,6 +32,7 @@ struct SyncObject {
};
extern struct MarioState gMarioStates[];
extern s16 sCurrPlayMode;
extern enum NetworkType networkType;
extern struct SyncObject syncObjects[];
@ -52,4 +54,7 @@ void network_receive_player(struct Packet* p);
void network_update_objects(void);
void network_receive_object(struct Packet* p);
void network_update_level_warp(void);
void network_receive_level_warp(struct Packet* p);
#endif

View file

@ -0,0 +1,62 @@
#include <stdio.h>
#include "../network.h"
#include "src/game/level_update.h"
#include "src/game/area.h"
int warpTimeout = 0;
void network_send_level_warp(void) {
struct Packet p;
packet_init(&p, PACKET_LEVEL_WARP);
packet_write(&p, &sCurrPlayMode, 2);
packet_write(&p, &gCurrLevelNum, 2);
packet_write(&p, &sDelayedWarpArg, 4);
packet_write(&p, &sSourceWarpNodeId, 2);
network_send(&p);
}
void network_receive_level_warp(struct Packet* p) {
if (warpTimeout != 0) { return; }
s16 remotePlayMode;
s16 remoteLevelNum;
s32 remoteWarpArg;
s16 remoteWarpNodeId;
struct WarpDest remoteWarpDest;
packet_read(p, &remotePlayMode, 2);
packet_read(p, &remoteLevelNum, 2);
packet_read(p, &remoteWarpArg, 4);
packet_read(p, &remoteWarpNodeId, 2);
if (gCurrLevelNum == remoteLevelNum) {
if (sCurrPlayMode == PLAY_MODE_SYNC_LEVEL) {
// our levels match now, lets play!
set_play_mode(PLAY_MODE_NORMAL);
set_menu_mode((s16)-1);
}
// our levels match, make sure the other player knows that
network_send_level_warp();
return;
}
// remote isn't trying to sync, don't warp
if (remotePlayMode != PLAY_MODE_SYNC_LEVEL) { return; }
// we're trying to sync, don't warp
if (sCurrPlayMode == PLAY_MODE_SYNC_LEVEL) { return; }
// warp to the level
sDelayedWarpTimer = 1;
sDelayedWarpArg = remoteWarpArg;
sSourceWarpNodeId = remoteWarpNodeId;
sDelayedWarpOp = WARP_OP_FORCE_SYNC;
// don't repeat the warp too quickly
warpTimeout = 2;
}
void network_update_level_warp(void) {
network_send_level_warp();
if (warpTimeout > 0) { warpTimeout--; }
}