Removed 'int' from most of networking code

moved -Werror over to 'STRICT'
This commit is contained in:
MysterD 2020-09-04 11:43:12 -07:00
parent 9512fde4a5
commit 1289f863ca
14 changed files with 45 additions and 38 deletions

View file

@ -3952,6 +3952,7 @@
<ClCompile Include="..\src\pc\network\packets\packet_collect_coin.c" />
<ClCompile Include="..\src\pc\network\packets\packet_collect_item.c" />
<ClCompile Include="..\src\pc\network\packets\packet_collect_star.c" />
<ClCompile Include="..\src\pc\network\packets\packet_custom.c" />
<ClCompile Include="..\src\pc\network\packets\packet_inside_painting.c" />
<ClCompile Include="..\src\pc\network\packets\packet_level_warp.c" />
<ClCompile Include="..\src\pc\network\packets\packet_object.c" />

View file

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

View file

@ -1 +1 @@
make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 && winpty cgdb ./build/us_pc/sm64.us.f3dex2e.exe -ex 'break debug_breakpoint_here' -ex 'run' -ex 'quit'
make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 STRICT=1 && winpty cgdb ./build/us_pc/sm64.us.f3dex2e.exe -ex 'break debug_breakpoint_here' -ex 'run' -ex 'quit'

View file

@ -1 +1 @@
make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 && winpty cgdb ./build/us_pc/sm64.us.f3dex2e.exe -ex 'break debug_breakpoint_here'
make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 STRICT=1 && winpty cgdb ./build/us_pc/sm64.us.f3dex2e.exe -ex 'break debug_breakpoint_here'

View file

@ -1,5 +1,9 @@
set -e
if [ $# -eq 0 ]; then
make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1
else
make BETTERCAMERA=1 NODRAWINGDISTANCE=1 DEBUG=1 IMMEDIATELOAD=1 STRICT=1
fi
# find file
FILE=./build/us_pc/sm64.us.f3dex2e.exe

View file

@ -1,6 +1,7 @@
#ifndef NETWORK_H
#define NETWORK_H
#include "PR/ultratypes.h"
#include <time.h>
#include <types.h>
#include <assert.h>
@ -32,13 +33,13 @@ enum PacketType {
};
struct Packet {
int dataLength;
int cursor;
u16 dataLength;
u16 cursor;
bool error;
bool reliable;
u16 seqId;
bool sent;
char buffer[PACKET_LENGTH];
u8 buffer[PACKET_LENGTH];
};
struct SyncObject {
@ -80,8 +81,8 @@ void network_shutdown(void);
// packet read / write
void packet_init(struct Packet* packet, enum PacketType packetType, bool reliable);
void packet_write(struct Packet* packet, void* data, int length);
void packet_read(struct Packet* packet, void* data, int length);
void packet_write(struct Packet* packet, void* data, u16 length);
void packet_read(struct Packet* packet, void* data, u16 length);
u32 packet_hash(struct Packet* packet);
bool packet_check_hash(struct Packet* packet);

View file

@ -82,7 +82,7 @@ void network_receive_collect_coin(struct Packet* p) {
const void* behavior = get_behavior_from_id(behaviorId);
// check if remote coin id has already been seen
for (int i = 0; i < MAX_REMOTE_COIN_IDS; i++) {
for (u16 i = 0; i < MAX_REMOTE_COIN_IDS; i++) {
if (remoteCoinIds[i] == remoteCoinId) {
// we already saw this coin!
goto SANITY_CHECK_COINS;

View file

@ -73,7 +73,7 @@ void network_receive_collect_item(struct Packet* p) {
const void* behavior = get_behavior_from_id(behaviorId);
// check if remote item id has already been seen
for (int i = 0; i < MAX_REMOTE_ITEM_IDS; i++) {
for (u16 i = 0; i < MAX_REMOTE_ITEM_IDS; i++) {
if (remoteItemIds[i] == remoteItemId) {
// we already saw this item!
return;

View file

@ -24,7 +24,7 @@ float player_distance(struct MarioState* marioState, struct Object* o) {
}
void network_clear_sync_objects(void) {
for (int i = 0; i < MAX_SYNC_OBJECTS; i++) {
for (u16 i = 0; i < MAX_SYNC_OBJECTS; i++) {
network_forget_sync_object(&syncObjects[i]);
}
nextSyncID = 1;
@ -36,7 +36,7 @@ void network_set_sync_id(struct Object* o) {
// two-player hack
u8 reserveId = (networkLevelLoaded && networkType == NT_CLIENT) ? 1 : 0;
for (int i = 0; i < MAX_SYNC_OBJECTS; i++) {
for (u16 i = 0; i < MAX_SYNC_OBJECTS; i++) {
if (syncObjects[nextSyncID].reserved == reserveId && syncObjects[nextSyncID].o == NULL) { break; }
nextSyncID = (nextSyncID + 1) % MAX_SYNC_OBJECTS;
}
@ -78,7 +78,7 @@ void network_init_object_field(struct Object *o, void* field) {
assert(o->oSyncID != 0);
// remember to synchronize this extra field
struct SyncObject* so = &syncObjects[o->oSyncID];
int index = so->extraFieldCount++;
u8 index = so->extraFieldCount++;
so->extraFields[index] = field;
}
@ -234,7 +234,7 @@ static void packet_write_object_extra_fields(struct Packet* p, struct Object* o)
packet_write(p, &so->extraFieldCount, sizeof(u8));
// write the extra field
for (int i = 0; i < so->extraFieldCount; i++) {
for (u8 i = 0; i < so->extraFieldCount; i++) {
assert(so->extraFields[i] != NULL);
packet_write(p, so->extraFields[i], sizeof(u32));
}
@ -252,7 +252,7 @@ static void packet_read_object_extra_fields(struct Packet* p, struct Object* o)
}
// read the extra fields
for (int i = 0; i < extraFieldsCount; i++) {
for (u8 i = 0; i < extraFieldsCount; i++) {
assert(so->extraFields[i] != NULL);
packet_read(p, so->extraFields[i], sizeof(u32));
}

View file

@ -17,24 +17,24 @@ void packet_init(struct Packet* packet, enum PacketType packetType, bool reliabl
packet->sent = false;
}
void packet_write(struct Packet* packet, void* data, int length) {
void packet_write(struct Packet* packet, void* data, u16 length) {
if (data == NULL) { packet->error = true; return; }
memcpy(&packet->buffer[packet->cursor], data, length);
packet->dataLength += length;
packet->cursor += length;
}
void packet_read(struct Packet* packet, void* data, int length) {
void packet_read(struct Packet* packet, void* data, u16 length) {
if (data == NULL) { packet->error = true; return; }
int cursor = packet->cursor;
u16 cursor = packet->cursor;
memcpy(data, &packet->buffer[cursor], length);
packet->cursor = cursor + length;
}
u32 packet_hash(struct Packet* packet) {
u32 hash = 0;
int byte = 0;
for (int i = 0; i < packet->dataLength; i++) {
u16 byte = 0;
for (u16 i = 0; i < packet->dataLength; i++) {
hash ^= ((u32)packet->buffer[i]) << (8 * byte);
byte = (byte + 1) % sizeof(u32);
}

View file

@ -24,12 +24,12 @@ void network_receive_reservation_request(UNUSED struct Packet* p) {
void network_send_reservation(void) {
assert(networkType == NT_SERVER);
int clientPlayerIndex = 1; // two-player hack
u8 clientPlayerIndex = 1; // two-player hack
// find all reserved objects
u8 reservedObjs[RESERVATION_COUNT] = { 0 };
int reservedIndex = 0;
for (int i = 1; i < MAX_SYNC_OBJECTS; i++) {
u16 reservedIndex = 0;
for (u16 i = 1; i < MAX_SYNC_OBJECTS; i++) {
if (syncObjects[i].reserved == clientPlayerIndex) {
reservedObjs[reservedIndex++] = i;
if (reservedIndex >= RESERVATION_COUNT) { break; }
@ -38,7 +38,7 @@ void network_send_reservation(void) {
if (reservedIndex < RESERVATION_COUNT) {
// reserve the rest
for (int i = MAX_SYNC_OBJECTS - 1; i > 0; i--) {
for (u16 i = MAX_SYNC_OBJECTS - 1; i > 0; i--) {
if (syncObjects[i].o != NULL) { continue; }
if (syncObjects[i].reserved != 0) { continue; }
syncObjects[i].reserved = clientPlayerIndex;
@ -55,18 +55,16 @@ void network_send_reservation(void) {
void network_receive_reservation(struct Packet* p) {
assert(networkType == NT_CLIENT);
int clientPlayerIndex = 1; // two-player hack
u8 clientPlayerIndex = 1; // two-player hack
// find all reserved objects
u8 reservedObjs[RESERVATION_COUNT] = { 0 };
packet_read(p, reservedObjs, sizeof(u8) * RESERVATION_COUNT);
for (int i = 0; i < RESERVATION_COUNT; i++) {
int index = reservedObjs[i];
printf(" %d", index);
for (u16 i = 0; i < RESERVATION_COUNT; i++) {
u16 index = reservedObjs[i];
if (index == 0) { continue; }
if (syncObjects[index].o != NULL) { continue; }
syncObjects[index].reserved = clientPlayerIndex;
}
printf("\n");
}

View file

@ -35,7 +35,7 @@ static u8 generate_parent_id(struct Object* objects[], u8 onIndex) {
return (u8)o->parentObj->oSyncID;
}
for (u8 i = onIndex; i < onIndex; i--) {
for (u8 i = onIndex; i != (u8)-1; i--) {
if (o->parentObj == objects[i]) { return i; }
}
@ -76,7 +76,7 @@ void network_receive_spawn_objects(struct Packet* p) {
packet_read(p, &objectCount, sizeof(u8));
// check if remote spawn id has already been seen
for (int i = 0; i < MAX_REMOTE_SPAWN_IDS; i++) {
for (u16 i = 0; i < MAX_REMOTE_SPAWN_IDS; i++) {
if (remoteSpawnIds[i] == remoteSpawnId) {
// we already saw this event!
return;

View file

@ -1,6 +1,6 @@
#include <stdio.h>
#include "socket.h"
#include "../network.h"
#include "socket.h"
int socket_bind(SOCKET sock, unsigned int port) {
struct sockaddr_in rxAddr;
@ -16,9 +16,9 @@ int socket_bind(SOCKET sock, unsigned int port) {
return rc;
}
int socket_send(SOCKET sock, struct sockaddr_in* txAddr, char* buffer, int bufferLength) {
int socket_send(SOCKET sock, struct sockaddr_in* txAddr, u8* buffer, u16 bufferLength) {
int txAddrSize = sizeof(struct sockaddr_in);
int rc = sendto(sock, buffer, bufferLength, 0, (struct sockaddr*)txAddr, txAddrSize);
int rc = sendto(sock, (char*)buffer, bufferLength, 0, (struct sockaddr*)txAddr, txAddrSize);
if (rc == SOCKET_ERROR) {
printf("%s sendto failed with error: %d\n", NETWORKTYPESTR, SOCKET_LAST_ERROR);
}
@ -26,11 +26,11 @@ int socket_send(SOCKET sock, struct sockaddr_in* txAddr, char* buffer, int buffe
return rc;
}
int socket_receive(SOCKET sock, struct sockaddr_in* rxAddr, char* buffer, int bufferLength, int* receiveLength) {
int socket_receive(SOCKET sock, struct sockaddr_in* rxAddr, u8* buffer, u16 bufferLength, u16* receiveLength) {
*receiveLength = 0;
int rxAddrSize = sizeof(struct sockaddr_in);
int rc = recvfrom(sock, buffer, bufferLength, 0, (struct sockaddr*)rxAddr, &rxAddrSize);
int rc = recvfrom(sock, (char*)buffer, bufferLength, 0, (struct sockaddr*)rxAddr, &rxAddrSize);
if (rc == SOCKET_ERROR) {
int error = SOCKET_LAST_ERROR;
if (error != SOCKET_EWOULDBLOCK && error != SOCKET_ECONNRESET) {

View file

@ -9,8 +9,8 @@
SOCKET socket_initialize(void);
int socket_bind(SOCKET sock, unsigned int port);
int socket_send(SOCKET sock, struct sockaddr_in* txAddr, char* buffer, int bufferLength);
int socket_receive(SOCKET sock, struct sockaddr_in* rxAddr, char* buffer, int bufferLength, int* receiveLength);
int socket_send(SOCKET sock, struct sockaddr_in* txAddr, u8* buffer, u16 bufferLength);
int socket_receive(SOCKET sock, struct sockaddr_in* rxAddr, u8* buffer, u16 bufferLength, u16* receiveLength);
void socket_close(SOCKET sock);
#endif