Synchronized held objects, made respawners keep their sync ID

This commit is contained in:
MysterD 2020-08-02 14:18:34 -07:00
parent 579415dca9
commit 716a924803
13 changed files with 71 additions and 35 deletions

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@ -22,7 +22,7 @@
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{8ADFCAB9-E7D6-4588-86B5-A128DA4F811D}</ProjectGuid>
<RootNamespace>sm64ex</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@ -41,7 +41,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
@ -74,7 +74,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\include;..\src;$(IncludePath)</IncludePath>
<IncludePath>..\include;..\src;.\;..\;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
@ -3944,6 +3944,9 @@
<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_object.c" />
<ClCompile Include="..\src\pc\network\packets\packet_player.c" />
<ClCompile Include="..\src\pc\network\packets\packet_read_write.c" />
<ClCompile Include="..\src\pc\pc_main.c" />
<ClCompile Include="..\src\pc\platform.c" />
<ClCompile Include="..\src\pc\ultra_reimplementation.c" />
@ -3979,7 +3982,6 @@
<ClCompile Include="..\tools\textconv.c" />
<ClCompile Include="..\tools\utf8.c" />
<ClCompile Include="..\tools\utils.c" />
<ClCompile Include="packet_player.c" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\actors\common0.h" />

View file

@ -14943,7 +14943,13 @@
<ClCompile Include="..\src\pc\network\network.c">
<Filter>Source Files\src\pc\network</Filter>
</ClCompile>
<ClCompile Include="packet_player.c">
<ClCompile Include="..\src\pc\network\packets\packet_object.c">
<Filter>Source Files\src\pc\network\packets</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\network\packets\packet_player.c">
<Filter>Source Files\src\pc\network\packets</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\network\packets\packet_read_write.c">
<Filter>Source Files\src\pc\network\packets</Filter>
</ClCompile>
</ItemGroup>

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 'b act_jump_kick' -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

@ -37,7 +37,7 @@ void bobomb_act_explode(void) {
explosion->oGraphYOffset += 100.0f;
bobomb_spawn_coin();
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000);
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000, o->oSyncID);
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
}
}
@ -128,12 +128,12 @@ void generic_bobomb_free_loop(void) {
case BOBOMB_ACT_LAVA_DEATH:
if (obj_lava_death() == 1)
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000);
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000, o->oSyncID);
break;
case BOBOMB_ACT_DEATH_PLANE_DEATH:
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000);
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000, o->oSyncID);
break;
}
@ -155,12 +155,12 @@ void stationary_bobomb_free_loop(void) {
case BOBOMB_ACT_LAVA_DEATH:
if (obj_lava_death() == 1)
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000);
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000, o->oSyncID);
break;
case BOBOMB_ACT_DEATH_PLANE_DEATH:
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000);
create_respawner(MODEL_BLACK_BOBOMB, bhvBobomb, 3000, o->oSyncID);
break;
}

View file

@ -65,7 +65,7 @@ void breakable_box_small_released_loop(void) {
// Despawn, and create a corkbox respawner
if (o->oBreakableBoxSmallFramesSinceReleased > 900) {
create_respawner(MODEL_BREAKABLE_BOX_SMALL, bhvBreakableBoxSmall, 3000);
create_respawner(MODEL_BREAKABLE_BOX_SMALL, bhvBreakableBoxSmall, 3000, o->oSyncID);
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
}
}
@ -82,7 +82,7 @@ void breakable_box_small_idle_loop(void) {
case 101:
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
create_respawner(MODEL_BREAKABLE_BOX_SMALL, bhvBreakableBoxSmall, 3000);
create_respawner(MODEL_BREAKABLE_BOX_SMALL, bhvBreakableBoxSmall, 3000, o->oSyncID);
break;
}

View file

@ -44,15 +44,17 @@ void bhv_respawner_loop(void) {
if (!is_point_within_radius_of_mario(o->oPosX, o->oPosY, o->oPosZ, o->oRespawnerMinSpawnDist)) {
spawnedObject = spawn_object(o, o->oRespawnerModelToRespawn, o->oRespawnerBehaviorToRespawn);
spawnedObject->oBehParams = o->oBehParams;
spawnedObject->oSyncID = o->oSyncID;
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
}
}
void create_respawner(s32 model, const BehaviorScript *behToSpawn, s32 minSpawnDist) {
void create_respawner(s32 model, const BehaviorScript *behToSpawn, s32 minSpawnDist, u32 syncID) {
struct Object *respawner = spawn_object_abs_with_rot(o, 0, MODEL_NONE, bhvRespawner, o->oHomeX,
o->oHomeY, o->oHomeZ, 0, 0, 0);
respawner->oBehParams = o->oBehParams;
respawner->oRespawnerModelToRespawn = model;
respawner->oRespawnerMinSpawnDist = minSpawnDist;
respawner->oRespawnerBehaviorToRespawn = behToSpawn;
respawner->oSyncID = syncID;
}

View file

@ -96,7 +96,7 @@ void snowmans_bottom_act_2(void) {
}
if (o->oTimer == 200) {
create_respawner(MODEL_CCM_SNOWMAN_BASE, bhvSnowmansBottom, 3000);
create_respawner(MODEL_CCM_SNOWMAN_BASE, bhvSnowmansBottom, 3000, o->oSyncID);
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
}
}

View file

@ -34,7 +34,7 @@ void yoshi_walk_loop(void) {
o->oAction = YOSHI_ACT_TALK;
if (o->oPosY < 2100.0f) {
create_respawner(MODEL_YOSHI, bhvYoshi, 3000);
create_respawner(MODEL_YOSHI, bhvYoshi, 3000, o->oSyncID);
o->activeFlags = ACTIVE_FLAG_DEACTIVATED;
}
}

View file

@ -193,7 +193,7 @@ s32 act_picking_up(struct MarioState *m) {
}
}
if (m->actionState == 1) {
if (m->actionState == 1 && m->heldObj != NULL) {
if (m->heldObj->oInteractionSubtype & INT_SUBTYPE_GRABS_MARIO) {
m->marioBodyState->grabPos = GRAB_POS_HEAVY_OBJ;
set_mario_animation(m, MARIO_ANIM_GRAB_HEAVY_OBJECT);

View file

@ -87,7 +87,7 @@ void bhv_bobomb_bully_death_smoke_init(void);
void bhv_bobomb_explosion_bubble_init(void);
void bhv_bobomb_explosion_bubble_loop(void);
void bhv_respawner_loop(void);
void create_respawner(s32 arg0, const BehaviorScript *behToSpawn, s32 minSpawnDist);
void create_respawner(s32 arg0, const BehaviorScript *behToSpawn, s32 minSpawnDist, u32 syncID);
void bhv_small_bully_init(void);
void bhv_big_bully_init(void);
void bully_check_mario_collision(void);

View file

@ -2,13 +2,16 @@
#define NETWORK_H
#include <types.h>
#include <assert.h>
#include "../cliopts.h"
#define MAX_SYNC_OBJECTS 256
#define PACKET_LENGTH 1024
#define NETWORKTYPESTR (networkType == NT_CLIENT ? "Client" : "Server")
extern struct MarioState gMarioStates[];
extern enum NetworkType networkType;
extern struct Object* syncObjects[];
enum PacketType {
PACKET_PLAYER,

View file

@ -4,28 +4,33 @@
#include "object_constants.h"
u32 nextSyncID = 1;
struct Object* syncObject = NULL;
struct Object* syncObjects[MAX_SYNC_OBJECTS] = { 0 };
float player_distance(struct MarioState* marioState, struct Object* obj) {
float player_distance(struct MarioState* marioState, struct Object* o) {
if (marioState->marioObj == NULL) { return 0; }
f32 mx = marioState->marioObj->header.gfx.pos[0] - obj->oPosX;
f32 my = marioState->marioObj->header.gfx.pos[1] - obj->oPosY;
f32 mz = marioState->marioObj->header.gfx.pos[2] - obj->oPosZ;
f32 mx = marioState->marioObj->header.gfx.pos[0] - o->oPosX;
f32 my = marioState->marioObj->header.gfx.pos[1] - o->oPosY;
f32 mz = marioState->marioObj->header.gfx.pos[2] - o->oPosZ;
mx *= mx;
my *= my;
mz *= mz;
return sqrt(mx + my + mz);
}
void network_init_object(struct Object *object) {
object->oSyncID = nextSyncID++;
syncObject = object;
void network_init_object(struct Object *o) {
if (o->oSyncID == 0) {
o->oSyncID = nextSyncID++;
}
assert(o->oSyncID < MAX_SYNC_OBJECTS);
syncObjects[o->oSyncID] = o;
}
void network_send_object(struct Object* o) {
o = syncObject;
int expectedID = 1;
o = syncObjects[expectedID];
if (o == NULL) { return; }
if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) { return; }
//if (o->activeFlags == ACTIVE_FLAG_DEACTIVATED) { return; }
if (o->oSyncID != expectedID) { return; }
if (player_distance(&gMarioStates[0], o) > player_distance(&gMarioStates[1], o)) { return; }
struct Packet p;
@ -40,11 +45,14 @@ void network_send_object(struct Object* o) {
}
void network_receive_object(struct Packet* p) {
if (syncObject == NULL) { return; }
u32 syncId;
packet_read(p, &syncId, 4);
packet_read(p, &syncObject->oPosX, 28);
packet_read(p, &syncObject->oAction, 4);
packet_read(p, &syncObject->oHeldState, 4);
packet_read(p, &syncObject->oMoveAngleYaw, 4);
assert(syncId < MAX_SYNC_OBJECTS);
struct Object* o = syncObjects[syncId];
assert(o != NULL);
packet_read(p, &o->oPosX, 28);
packet_read(p, &o->oAction, 4);
packet_read(p, &o->oHeldState, 4);
packet_read(p, &o->oMoveAngleYaw, 4);
}

View file

@ -1,23 +1,38 @@
#include <stdio.h>
#include "../network.h"
#include "object_fields.h"
#include "object_constants.h"
void network_send_player(void) {
if (gMarioStates[0].marioObj == NULL) { return; }
u32 heldSyncID = (gMarioStates[0].heldObj != NULL)
? gMarioStates[0].heldObj->oSyncID
: NULL;
struct Packet p;
packet_init(&p, PACKET_PLAYER);
packet_write(&p, &gMarioStates[0], 96);
packet_write(&p, gMarioStates[0].controller, 20);
packet_write(&p, gMarioStates[0].marioObj->rawData.asU32, 320);
packet_write(&p, &heldSyncID, 4);
network_send(&p);
}
void network_receive_player(struct Packet* p) {
if (gMarioStates[1].marioObj == NULL) { return; }
int oldActionState = gMarioStates[1].actionState;
u32 heldSyncID = NULL;
packet_read(p, &gMarioStates[1], 96);
packet_read(p, gMarioStates[1].controller, 20);
packet_read(p, &gMarioStates[1].marioObj->rawData.asU32, 320);
packet_read(p, &heldSyncID, 4);
if (heldSyncID != NULL) {
assert(syncObjects[heldSyncID] != NULL);
gMarioStates[1].heldObj = syncObjects[heldSyncID];
gMarioStates[1].heldObj->heldByPlayerIndex = 1;
}
// restore action state, needed for jump kicking
gMarioStates[1].actionState = oldActionState;