Synchronize area changes

This commit is contained in:
MysterD 2020-08-10 12:08:40 -07:00
parent 6701b6096d
commit 1bef126df8
8 changed files with 99 additions and 35 deletions

View file

@ -87,7 +87,7 @@
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;WINSOCK;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
</ClCompile> </ClCompile>
<Link> <Link>
@ -2231,6 +2231,7 @@
<ClCompile Include="..\build\us_pc\textures\water\jrb_textures.0A800.rgba16.inc.c" /> <ClCompile Include="..\build\us_pc\textures\water\jrb_textures.0A800.rgba16.inc.c" />
<ClCompile Include="..\build\us_pc\textures\water\jrb_textures.0B800.rgba16.inc.c" /> <ClCompile Include="..\build\us_pc\textures\water\jrb_textures.0B800.rgba16.inc.c" />
<ClCompile Include="..\data\behavior_data.c" /> <ClCompile Include="..\data\behavior_data.c" />
<ClCompile Include="..\data\behavior_table.c" />
<ClCompile Include="..\include\trig_tables.inc.c" /> <ClCompile Include="..\include\trig_tables.inc.c" />
<ClCompile Include="..\levels\bbh\areas\1\1\model.inc.c" /> <ClCompile Include="..\levels\bbh\areas\1\1\model.inc.c" />
<ClCompile Include="..\levels\bbh\areas\1\10\model.inc.c" /> <ClCompile Include="..\levels\bbh\areas\1\10\model.inc.c" />
@ -3955,6 +3956,9 @@
<ClCompile Include="..\src\pc\network\packets\packet_reliable.c" /> <ClCompile Include="..\src\pc\network\packets\packet_reliable.c" />
<ClCompile Include="..\src\pc\network\packets\packet_spawn_objects.c" /> <ClCompile Include="..\src\pc\network\packets\packet_spawn_objects.c" />
<ClCompile Include="..\src\pc\network\packets\packet_spawn_star.c" /> <ClCompile Include="..\src\pc\network\packets\packet_spawn_star.c" />
<ClCompile Include="..\src\pc\network\socket\socket.c" />
<ClCompile Include="..\src\pc\network\socket\socket_linux.c" />
<ClCompile Include="..\src\pc\network\socket\socket_windows.c" />
<ClCompile Include="..\src\pc\pc_main.c" /> <ClCompile Include="..\src\pc\pc_main.c" />
<ClCompile Include="..\src\pc\platform.c" /> <ClCompile Include="..\src\pc\platform.c" />
<ClCompile Include="..\src\pc\ultra_reimplementation.c" /> <ClCompile Include="..\src\pc\ultra_reimplementation.c" />
@ -4293,7 +4297,11 @@
<ClCompile Include="..\tools\utils.h" /> <ClCompile Include="..\tools\utils.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\include\behavior_table.h" />
<ClInclude Include="..\src\pc\network\network.h" /> <ClInclude Include="..\src\pc\network\network.h" />
<ClInclude Include="..\src\pc\network\socket\socket.h" />
<ClInclude Include="..\src\pc\network\socket\socket_linux.h" />
<ClInclude Include="..\src\pc\network\socket\socket_windows.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View file

@ -3421,6 +3421,12 @@
<Filter Include="Source Files\src\pc\network\packets"> <Filter Include="Source Files\src\pc\network\packets">
<UniqueIdentifier>{f7dcd9e2-f84f-4c82-96c5-0dc32d408693}</UniqueIdentifier> <UniqueIdentifier>{f7dcd9e2-f84f-4c82-96c5-0dc32d408693}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Source Files\src\pc\network\socket">
<UniqueIdentifier>{d884729b-710d-45b4-8757-287303e2d8e2}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\src\pc\network\socket">
<UniqueIdentifier>{b1b4937e-775c-4a0c-92f5-48b010783e4d}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\actors\amp\anims\anim_0800401C.inc.c"> <ClCompile Include="..\actors\amp\anims\anim_0800401C.inc.c">
@ -14973,6 +14979,18 @@
<ClCompile Include="..\src\pc\network\packets\packet_spawn_star.c"> <ClCompile Include="..\src\pc\network\packets\packet_spawn_star.c">
<Filter>Source Files\src\pc\network\packets</Filter> <Filter>Source Files\src\pc\network\packets</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\pc\network\socket\socket_linux.c">
<Filter>Source Files\src\pc\network\socket</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\network\socket\socket_windows.c">
<Filter>Source Files\src\pc\network\socket</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\network\socket\socket.c">
<Filter>Source Files\src\pc\network\socket</Filter>
</ClCompile>
<ClCompile Include="..\data\behavior_table.c">
<Filter>Source Files\data</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\actors\common0.h"> <ClCompile Include="..\actors\common0.h">
@ -15877,5 +15895,17 @@
<ClInclude Include="..\src\pc\network\network.h"> <ClInclude Include="..\src\pc\network\network.h">
<Filter>Header Files\src\pc\network</Filter> <Filter>Header Files\src\pc\network</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\src\pc\network\socket\socket_linux.h">
<Filter>Header Files\src\pc\network\socket</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\network\socket\socket_windows.h">
<Filter>Header Files\src\pc\network\socket</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\network\socket\socket.h">
<Filter>Header Files\src\pc\network\socket</Filter>
</ClInclude>
<ClInclude Include="..\include\behavior_table.h">
<Filter>Header Files\include</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -268,6 +268,10 @@ void load_mario_area(void) {
func_80320890(); func_80320890();
load_area(gMarioSpawnInfo->areaIndex); load_area(gMarioSpawnInfo->areaIndex);
for (int i = 0; i < MAX_PLAYERS; i++) {
gMarioStates[i].spawnInfo->areaIndex = gCurrentArea->index;
}
if (gCurrentArea->index == gMarioSpawnInfo->areaIndex) { if (gCurrentArea->index == gMarioSpawnInfo->areaIndex) {
gCurrentArea->flags |= 0x01; gCurrentArea->flags |= 0x01;
spawn_objects_from_info(0, gMarioSpawnInfo); spawn_objects_from_info(0, gMarioSpawnInfo);
@ -293,11 +297,16 @@ void change_area(s32 index) {
load_area(index); load_area(index);
gCurrentArea->flags = areaFlags; gCurrentArea->flags = areaFlags;
gMarioObject->oActiveParticleFlags = 0; for (int i = 0; i < MAX_PLAYERS; i++) {
gMarioStates[i].marioObj->oActiveParticleFlags = 0;
}
} }
if (areaFlags & 0x01) { if (areaFlags & 0x01) {
gMarioObject->header.gfx.unk18 = index, gMarioSpawnInfo->areaIndex = index; for (int i = 0; i < MAX_PLAYERS; i++) {
gMarioStates[i].marioObj->header.gfx.unk18 = index;
gMarioStates[i].spawnInfo->areaIndex = index;
}
} }
} }

View file

@ -36,11 +36,6 @@
#include "pc/configfile.h" #include "pc/configfile.h"
#include "pc/network/network.h" #include "pc/network/network.h"
#define WARP_TYPE_NOT_WARPING 0
#define WARP_TYPE_CHANGE_LEVEL 1
#define WARP_TYPE_CHANGE_AREA 2
#define WARP_TYPE_SAME_AREA 3
#define WARP_NODE_F0 0xF0 #define WARP_NODE_F0 0xF0
#define WARP_NODE_DEATH 0xF1 #define WARP_NODE_DEATH 0xF1
#define WARP_NODE_F2 0xF2 #define WARP_NODE_F2 0xF2
@ -548,21 +543,24 @@ void check_instant_warp(void) {
struct InstantWarp *warp = &gCurrentArea->instantWarps[index]; struct InstantWarp *warp = &gCurrentArea->instantWarps[index];
if (warp->id != 0) { if (warp->id != 0) {
gMarioState->pos[0] += warp->displacement[0]; for (int i = 0; i < MAX_PLAYERS; i++) {
gMarioState->pos[1] += warp->displacement[1]; gMarioStates[i].pos[0] += warp->displacement[0];
gMarioState->pos[2] += warp->displacement[2]; gMarioStates[i].pos[1] += warp->displacement[1];
gMarioStates[i].pos[2] += warp->displacement[2];
gMarioState->marioObj->oPosX = gMarioState->pos[0]; gMarioStates[i].marioObj->oPosX = gMarioStates[i].pos[0];
gMarioState->marioObj->oPosY = gMarioState->pos[1]; gMarioStates[i].marioObj->oPosY = gMarioStates[i].pos[1];
gMarioState->marioObj->oPosZ = gMarioState->pos[2]; gMarioStates[i].marioObj->oPosZ = gMarioStates[i].pos[2];
}
cameraAngle = gMarioState->area->camera->yaw; cameraAngle = gMarioState->area->camera->yaw;
change_area(warp->area); change_area(warp->area);
gMarioState->area = gCurrentArea;
for (int i = 0; i < MAX_PLAYERS; i++) {
gMarioStates[i].area = gCurrentArea;
}
warp_camera(warp->displacement[0], warp->displacement[1], warp->displacement[2]); warp_camera(warp->displacement[0], warp->displacement[1], warp->displacement[2]);
gMarioState->area->camera->yaw = cameraAngle; gMarioState->area->camera->yaw = cameraAngle;
} }
} }
@ -1011,13 +1009,19 @@ s32 play_mode_normal(void) {
// warp, change play mode accordingly. // warp, change play mode accordingly.
if (sCurrPlayMode == PLAY_MODE_NORMAL) { if (sCurrPlayMode == PLAY_MODE_NORMAL) {
if (sWarpDest.type == WARP_TYPE_CHANGE_LEVEL) { if (sWarpDest.type == WARP_TYPE_CHANGE_LEVEL) {
set_play_mode((networkType != NT_NONE) ? PLAY_MODE_SYNC_LEVEL : PLAY_MODE_CHANGE_LEVEL); if (sWarpDest.type == WARP_TYPE_NOT_WARPING) {
network_send_level_warp(); set_play_mode(PLAY_MODE_CHANGE_LEVEL);
} else {
set_play_mode((networkType != NT_NONE) ? PLAY_MODE_SYNC_LEVEL : PLAY_MODE_CHANGE_LEVEL);
network_send_level_warp();
}
} else if (sTransitionTimer != 0) { } else if (sTransitionTimer != 0) {
//////////////////////////////////// if (sWarpDest.type == WARP_TYPE_NOT_WARPING || gCurrentArea->index == sWarpDest.areaIdx) {
// todo: synchronize change_area. // set_play_mode(PLAY_MODE_CHANGE_AREA);
//////////////////////////////////// } else {
set_play_mode(PLAY_MODE_CHANGE_AREA); set_play_mode((networkType != NT_NONE) ? PLAY_MODE_SYNC_LEVEL : PLAY_MODE_CHANGE_AREA);
network_send_level_warp();
}
} else if (pressed_pause()) { } else if (pressed_pause()) {
lower_background_noise(1); lower_background_noise(1);
cancel_rumble(); cancel_rumble();
@ -1259,15 +1263,6 @@ s32 init_level(void) {
sound_banks_disable(2, 0x0330); sound_banks_disable(2, 0x0330);
} }
// set mario/luigi model
for (int i = 0; i < MAX_PLAYERS; i++) {
if (i == 0) {
gMarioState[i].marioObj->header.gfx.sharedChild = gLoadedGraphNodes[(networkType == NT_SERVER) ? MODEL_MARIO : MODEL_LUIGI];
} else {
gMarioState[i].marioObj->header.gfx.sharedChild = gLoadedGraphNodes[(networkType == NT_SERVER) ? MODEL_LUIGI2 : MODEL_MARIO2];
}
}
return 1; return 1;
} }

View file

@ -50,6 +50,10 @@
#define MARIO_SPAWN_LAUNCH_DEATH 0x25 #define MARIO_SPAWN_LAUNCH_DEATH 0x25
#define MARIO_SPAWN_UNKNOWN_27 0x27 #define MARIO_SPAWN_UNKNOWN_27 0x27
#define WARP_TYPE_NOT_WARPING 0
#define WARP_TYPE_CHANGE_LEVEL 1
#define WARP_TYPE_CHANGE_AREA 2
#define WARP_TYPE_SAME_AREA 3
struct CreditsEntry struct CreditsEntry
{ {

View file

@ -35,6 +35,7 @@
#include "thread6.h" #include "thread6.h"
#include "pc/configfile.h" #include "pc/configfile.h"
#include "pc/cheats.h" #include "pc/cheats.h"
#include "pc/network/network.h"
#ifdef BETTERCAMERA #ifdef BETTERCAMERA
#include "bettercamera.h" #include "bettercamera.h"
#endif #endif
@ -1943,6 +1944,13 @@ void init_mario(void) {
capObject->oMoveAngleYaw = 0; capObject->oMoveAngleYaw = 0;
} }
// set mario/luigi model
if (isLocal) {
gMarioState->marioObj->header.gfx.sharedChild = gLoadedGraphNodes[(networkType == NT_SERVER) ? MODEL_MARIO : MODEL_LUIGI];
} else {
gMarioState->marioObj->header.gfx.sharedChild = gLoadedGraphNodes[(networkType == NT_SERVER) ? MODEL_LUIGI2 : MODEL_MARIO2];
}
skippy: skippy:
if (isLocal) { if (isLocal) {
gMarioState = &gMarioStates[1]; gMarioState = &gMarioStates[1];

View file

@ -224,6 +224,7 @@ struct ParticleProperties sParticleTypes[] = {
void copy_mario_state_to_object(void) { void copy_mario_state_to_object(void) {
s32 i = 0; s32 i = 0;
// L is real // L is real
// two-player hack
if (gCurrentObject != gMarioObject) { if (gCurrentObject != gMarioObject) {
i += 1; i += 1;
} }

View file

@ -26,6 +26,7 @@ void network_receive_level_warp(struct Packet* p) {
bool matchingDest = memcmp(&remoteWarpDest, &sWarpDest, sizeof(struct WarpDest)) == 0; bool matchingDest = memcmp(&remoteWarpDest, &sWarpDest, sizeof(struct WarpDest)) == 0;
if (remotePlayMode == PLAY_MODE_SYNC_LEVEL && (sCurrPlayMode == PLAY_MODE_NORMAL || sCurrPlayMode == PLAY_MODE_PAUSED)) { if (remotePlayMode == PLAY_MODE_SYNC_LEVEL && (sCurrPlayMode == PLAY_MODE_NORMAL || sCurrPlayMode == PLAY_MODE_PAUSED)) {
if (remoteWarpDest.type == WARP_TYPE_NOT_WARPING) { return; }
sCurrPlayMode = PLAY_MODE_SYNC_LEVEL; sCurrPlayMode = PLAY_MODE_SYNC_LEVEL;
sWarpDest = remoteWarpDest; sWarpDest = remoteWarpDest;
gMenuMode = -1; gMenuMode = -1;
@ -38,9 +39,13 @@ void network_receive_level_warp(struct Packet* p) {
if (remotePlayMode == PLAY_MODE_SYNC_LEVEL && sCurrPlayMode == PLAY_MODE_SYNC_LEVEL) { if (remotePlayMode == PLAY_MODE_SYNC_LEVEL && sCurrPlayMode == PLAY_MODE_SYNC_LEVEL) {
if (matchingDest) { if (matchingDest) {
sCurrPlayMode = PLAY_MODE_CHANGE_LEVEL; switch (sWarpDest.type) {
case WARP_TYPE_CHANGE_AREA: sCurrPlayMode = PLAY_MODE_CHANGE_AREA; break;
case WARP_TYPE_CHANGE_LEVEL: sCurrPlayMode = PLAY_MODE_CHANGE_LEVEL; break;
}
} else { } else {
if (networkType == NT_CLIENT) { if (networkType == NT_CLIENT) {
if (remoteWarpDest.type == WARP_TYPE_NOT_WARPING) { return; }
// two-player hack: would need to use player index as priority // two-player hack: would need to use player index as priority
sWarpDest = remoteWarpDest; sWarpDest = remoteWarpDest;
} }
@ -49,7 +54,11 @@ void network_receive_level_warp(struct Packet* p) {
return; return;
} }
if (remotePlayMode == PLAY_MODE_CHANGE_LEVEL && sCurrPlayMode == PLAY_MODE_SYNC_LEVEL) { if ((remotePlayMode == PLAY_MODE_CHANGE_LEVEL || remotePlayMode == PLAY_MODE_CHANGE_AREA) && sCurrPlayMode == PLAY_MODE_SYNC_LEVEL) {
sCurrPlayMode = PLAY_MODE_CHANGE_LEVEL; if (remoteWarpDest.type == WARP_TYPE_NOT_WARPING) { return; }
switch (sWarpDest.type) {
case WARP_TYPE_CHANGE_AREA: sCurrPlayMode = PLAY_MODE_CHANGE_AREA; break;
case WARP_TYPE_CHANGE_LEVEL: sCurrPlayMode = PLAY_MODE_CHANGE_LEVEL; break;
}
} }
} }