mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-10-19 03:32:41 +00:00
Smooth over transition from sending raw enums
This commit is contained in:
parent
55bbe8d4d9
commit
28ad7f91ed
7 changed files with 30 additions and 22 deletions
|
@ -44,7 +44,7 @@ static struct Object* find_nearest_coin(const BehaviorScript *behavior, f32* pos
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_send_collect_coin(struct Object* o) {
|
void network_send_collect_coin(struct Object* o) {
|
||||||
enum BehaviorId behaviorId = get_id_from_behavior(o->behavior);
|
u16 behaviorId = get_id_from_behavior(o->behavior);
|
||||||
|
|
||||||
struct Packet p;
|
struct Packet p;
|
||||||
packet_init(&p, PACKET_COLLECT_COIN, true, true);
|
packet_init(&p, PACKET_COLLECT_COIN, true, true);
|
||||||
|
@ -57,7 +57,7 @@ void network_send_collect_coin(struct Object* o) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_receive_collect_coin(struct Packet* p) {
|
void network_receive_collect_coin(struct Packet* p) {
|
||||||
enum BehaviorId behaviorId;
|
u16 behaviorId;
|
||||||
f32 pos[3] = { 0 };
|
f32 pos[3] = { 0 };
|
||||||
s16 numCoins = 0;
|
s16 numCoins = 0;
|
||||||
s32 coinValue = 0;
|
s32 coinValue = 0;
|
||||||
|
|
|
@ -41,7 +41,7 @@ static struct Object* find_nearest_item(const BehaviorScript *behavior, f32* pos
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_send_collect_item(struct Object* o) {
|
void network_send_collect_item(struct Object* o) {
|
||||||
enum BehaviorId behaviorId = get_id_from_behavior(o->behavior);
|
u16 behaviorId = get_id_from_behavior(o->behavior);
|
||||||
|
|
||||||
struct Packet p;
|
struct Packet p;
|
||||||
packet_init(&p, PACKET_COLLECT_ITEM, true, true);
|
packet_init(&p, PACKET_COLLECT_ITEM, true, true);
|
||||||
|
@ -52,7 +52,7 @@ void network_send_collect_item(struct Object* o) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_receive_collect_item(struct Packet* p) {
|
void network_receive_collect_item(struct Packet* p) {
|
||||||
enum BehaviorId behaviorId;
|
u16 behaviorId;
|
||||||
f32 pos[3] = { 0 };
|
f32 pos[3] = { 0 };
|
||||||
|
|
||||||
packet_read(p, &behaviorId, sizeof(u16));
|
packet_read(p, &behaviorId, sizeof(u16));
|
||||||
|
|
|
@ -44,7 +44,7 @@ static struct Object* find_nearest_star(const BehaviorScript* behavior, f32* pos
|
||||||
}
|
}
|
||||||
|
|
||||||
void network_send_collect_star(struct Object* o, s16 coinScore, s16 starIndex) {
|
void network_send_collect_star(struct Object* o, s16 coinScore, s16 starIndex) {
|
||||||
enum BehaviorId behaviorId = get_id_from_behavior(o->behavior);
|
u16 behaviorId = get_id_from_behavior(o->behavior);
|
||||||
|
|
||||||
struct Packet p;
|
struct Packet p;
|
||||||
packet_init(&p, PACKET_COLLECT_STAR, true, false);
|
packet_init(&p, PACKET_COLLECT_STAR, true, false);
|
||||||
|
@ -61,7 +61,7 @@ void network_send_collect_star(struct Object* o, s16 coinScore, s16 starIndex) {
|
||||||
|
|
||||||
void network_receive_collect_star(struct Packet* p) {
|
void network_receive_collect_star(struct Packet* p) {
|
||||||
f32 pos[3] = { 0 };
|
f32 pos[3] = { 0 };
|
||||||
enum BehaviorId behaviorId;
|
u16 behaviorId;
|
||||||
s16 coinScore, starIndex;
|
s16 coinScore, starIndex;
|
||||||
s16 lastSaveFileNum = gCurrSaveFileNum;
|
s16 lastSaveFileNum = gCurrSaveFileNum;
|
||||||
s16 lastCourseNum = gCurrCourseNum;
|
s16 lastCourseNum = gCurrCourseNum;
|
||||||
|
|
|
@ -4,9 +4,10 @@
|
||||||
#include "pc/debuglog.h"
|
#include "pc/debuglog.h"
|
||||||
|
|
||||||
void network_send_kick(enum KickReasonType kickReason) {
|
void network_send_kick(enum KickReasonType kickReason) {
|
||||||
|
u8 kickReasonType = kickReason;
|
||||||
struct Packet p;
|
struct Packet p;
|
||||||
packet_init(&p, PACKET_KICK, false, false);
|
packet_init(&p, PACKET_KICK, false, false);
|
||||||
packet_write(&p, &kickReason, sizeof(u8));
|
packet_write(&p, &kickReasonType, sizeof(u8));
|
||||||
network_send_to(0, &p);
|
network_send_to(0, &p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,8 +22,10 @@ void network_receive_kick(struct Packet* p) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum KickReasonType kickReason;
|
u8 kickReasonType;
|
||||||
packet_read(p, &kickReason, sizeof(u8));
|
packet_read(p, &kickReasonType, sizeof(u8));
|
||||||
|
enum KickReasonType kickReason = kickReasonType;
|
||||||
|
|
||||||
switch (kickReason) {
|
switch (kickReason) {
|
||||||
case EKT_FULL_PARTY: custom_menu_error("The party is full."); break;
|
case EKT_FULL_PARTY: custom_menu_error("The party is full."); break;
|
||||||
default: custom_menu_error("Host has closed the connection."); break;
|
default: custom_menu_error("Host has closed the connection."); break;
|
||||||
|
|
|
@ -145,7 +145,7 @@ void network_set_sync_id(struct Object* o) {
|
||||||
|
|
||||||
static void packet_write_object_header(struct Packet* p, struct Object* o) {
|
static void packet_write_object_header(struct Packet* p, struct Object* o) {
|
||||||
struct SyncObject* so = &gSyncObjects[o->oSyncID];
|
struct SyncObject* so = &gSyncObjects[o->oSyncID];
|
||||||
enum BehaviorId behaviorId = get_id_from_behavior(o->behavior);
|
u16 behaviorId = get_id_from_behavior(o->behavior);
|
||||||
|
|
||||||
packet_write(p, &gNetworkPlayerLocal->globalIndex, sizeof(u8));
|
packet_write(p, &gNetworkPlayerLocal->globalIndex, sizeof(u8));
|
||||||
packet_write(p, &o->oSyncID, sizeof(u32));
|
packet_write(p, &o->oSyncID, sizeof(u32));
|
||||||
|
@ -215,8 +215,9 @@ static struct SyncObject* packet_read_object_header(struct Packet* p, u8* fromLo
|
||||||
packet_read(p, &so->randomSeed, sizeof(u16));
|
packet_read(p, &so->randomSeed, sizeof(u16));
|
||||||
|
|
||||||
// make sure the behaviors match
|
// make sure the behaviors match
|
||||||
enum BehaviorId behaviorId;
|
u16 behaviorId;
|
||||||
packet_read(p, &behaviorId, sizeof(u16));
|
packet_read(p, &behaviorId, sizeof(u16));
|
||||||
|
|
||||||
BehaviorScript* behavior = (BehaviorScript*)get_behavior_from_id(behaviorId);
|
BehaviorScript* behavior = (BehaviorScript*)get_behavior_from_id(behaviorId);
|
||||||
if (behavior == NULL) {
|
if (behavior == NULL) {
|
||||||
LOG_ERROR("unable to find behavior %04X for id %d", behaviorId, syncId);
|
LOG_ERROR("unable to find behavior %04X for id %d", behaviorId, syncId);
|
||||||
|
|
|
@ -6,21 +6,25 @@
|
||||||
static u16 nextSeqNum = 1;
|
static u16 nextSeqNum = 1;
|
||||||
void packet_init(struct Packet* packet, enum PacketType packetType, bool reliable, bool levelAreaMustMatch) {
|
void packet_init(struct Packet* packet, enum PacketType packetType, bool reliable, bool levelAreaMustMatch) {
|
||||||
memset(packet->buffer, 0, PACKET_LENGTH);
|
memset(packet->buffer, 0, PACKET_LENGTH);
|
||||||
packet->buffer[0] = (char)packetType;
|
packet->cursor = 0;
|
||||||
if (reliable) {
|
packet->dataLength = 0;
|
||||||
memcpy(&packet->buffer[1], &nextSeqNum, 2);
|
|
||||||
packet->seqId = nextSeqNum;
|
|
||||||
nextSeqNum++;
|
|
||||||
if (nextSeqNum == 0) { nextSeqNum++; }
|
|
||||||
}
|
|
||||||
packet->dataLength = 3;
|
|
||||||
packet->cursor = 3;
|
|
||||||
packet->error = false;
|
packet->error = false;
|
||||||
packet->reliable = reliable;
|
packet->reliable = reliable;
|
||||||
packet->levelAreaMustMatch = levelAreaMustMatch;
|
packet->levelAreaMustMatch = levelAreaMustMatch;
|
||||||
packet->requestBroadcast = false;
|
packet->requestBroadcast = false;
|
||||||
packet->sent = false;
|
packet->sent = false;
|
||||||
|
|
||||||
|
packet_write(packet, &packetType, sizeof(u8));
|
||||||
|
if (reliable) {
|
||||||
|
packet_write(packet, &nextSeqNum, sizeof(u16));
|
||||||
|
packet->seqId = nextSeqNum;
|
||||||
|
nextSeqNum++;
|
||||||
|
if (nextSeqNum == 0) { nextSeqNum++; }
|
||||||
|
} else {
|
||||||
|
u16 nullSeqNum = 0;
|
||||||
|
packet_write(packet, &nullSeqNum, sizeof(u16));
|
||||||
|
}
|
||||||
|
|
||||||
// write packet flags
|
// write packet flags
|
||||||
u8 flags = 0;
|
u8 flags = 0;
|
||||||
packet_write(packet, &flags, sizeof(u8)); // fill in the byte
|
packet_write(packet, &flags, sizeof(u8)); // fill in the byte
|
||||||
|
|
|
@ -19,7 +19,7 @@ static u8 onRemoteSpawnId = 0;
|
||||||
struct SpawnObjectData {
|
struct SpawnObjectData {
|
||||||
u8 parentId;
|
u8 parentId;
|
||||||
u32 model;
|
u32 model;
|
||||||
enum BehaviorId behaviorId;
|
u16 behaviorId;
|
||||||
s16 activeFlags;
|
s16 activeFlags;
|
||||||
s32 rawData[80];
|
s32 rawData[80];
|
||||||
};
|
};
|
||||||
|
@ -54,7 +54,7 @@ void network_send_spawn_objects(struct Object* objects[], u32 models[], u8 objec
|
||||||
struct Object* o = objects[i];
|
struct Object* o = objects[i];
|
||||||
u32 model = models[i];
|
u32 model = models[i];
|
||||||
u8 parentId = generate_parent_id(objects, i);
|
u8 parentId = generate_parent_id(objects, i);
|
||||||
enum BehaviorId behaviorId = get_id_from_behavior(o->behavior);
|
u16 behaviorId = get_id_from_behavior(o->behavior);
|
||||||
packet_write(&p, &parentId, sizeof(u8));
|
packet_write(&p, &parentId, sizeof(u8));
|
||||||
packet_write(&p, &model, sizeof(u32));
|
packet_write(&p, &model, sizeof(u32));
|
||||||
packet_write(&p, &behaviorId, sizeof(u16));
|
packet_write(&p, &behaviorId, sizeof(u16));
|
||||||
|
|
Loading…
Reference in a new issue