* Rewrite a bit of get_level_name() and a bunch of cleanup.
This commit is contained in:
Prince Frizzy 2022-03-27 01:13:57 -04:00 committed by GitHub
parent 3f3936e874
commit 0fdd721241
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 183 additions and 166 deletions

View file

@ -28,5 +28,7 @@ enum CourseNum
#undef DEFINE_BONUS_COURSE #undef DEFINE_BONUS_COURSE
#define COURSE_IS_MAIN_COURSE(cmd) (cmd >= COURSE_MIN && cmd <= COURSE_STAGES_MAX) #define COURSE_IS_MAIN_COURSE(cmd) (cmd >= COURSE_MIN && cmd <= COURSE_STAGES_MAX)
#define COURSE_IS_VALID_COURSE(cmd) (cmd >= COURSE_MIN && cmd <= COURSE_MAX)
#endif // COURSE_TABLE_H #endif // COURSE_TABLE_H

View file

@ -198,15 +198,13 @@ void clear_areas(void) {
np->currLevelSyncValid = false; np->currLevelSyncValid = false;
} }
s32 i;
gCurrentArea = NULL; gCurrentArea = NULL;
gWarpTransition.isActive = FALSE; gWarpTransition.isActive = FALSE;
gWarpTransition.pauseRendering = FALSE; gWarpTransition.pauseRendering = FALSE;
gPlayerSpawnInfos[0].areaIndex = -1; gPlayerSpawnInfos[0].areaIndex = -1;
gPlayerSpawnInfos[1].areaIndex = -1; gPlayerSpawnInfos[1].areaIndex = -1;
for (i = 0; i < 8; i++) { for (s32 i = 0; i < 8; i++) {
gAreaData[i].index = i; gAreaData[i].index = i;
gAreaData[i].flags = 0; gAreaData[i].flags = 0;
gAreaData[i].terrainType = 0; gAreaData[i].terrainType = 0;
@ -232,15 +230,13 @@ void clear_areas(void) {
} }
void clear_area_graph_nodes(void) { void clear_area_graph_nodes(void) {
s32 i;
if (gCurrentArea != NULL) { if (gCurrentArea != NULL) {
geo_call_global_function_nodes(&gCurrentArea->unk04->node, GEO_CONTEXT_AREA_UNLOAD); geo_call_global_function_nodes(&gCurrentArea->unk04->node, GEO_CONTEXT_AREA_UNLOAD);
gCurrentArea = NULL; gCurrentArea = NULL;
gWarpTransition.isActive = FALSE; gWarpTransition.isActive = FALSE;
} }
for (i = 0; i < 8; i++) { for (s32 i = 0; i < 8; i++) {
if (gAreaData[i].unk04 != NULL) { if (gAreaData[i].unk04 != NULL) {
geo_call_global_function_nodes(&gAreaData[i].unk04->node, GEO_CONTEXT_AREA_INIT); geo_call_global_function_nodes(&gAreaData[i].unk04->node, GEO_CONTEXT_AREA_INIT);
gAreaData[i].unk04 = NULL; gAreaData[i].unk04 = NULL;
@ -289,7 +285,7 @@ void load_mario_area(void) {
stop_sounds_in_continuous_banks(); stop_sounds_in_continuous_banks();
load_area(gMarioSpawnInfo->areaIndex); load_area(gMarioSpawnInfo->areaIndex);
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
gMarioStates[i].spawnInfo->areaIndex = gCurrentArea->index; gMarioStates[i].spawnInfo->areaIndex = gCurrentArea->index;
} }
@ -320,13 +316,13 @@ void change_area(s32 index) {
if (gCurrentArea != NULL) { if (gCurrentArea != NULL) {
gCurrentArea->flags = areaFlags; gCurrentArea->flags = areaFlags;
} }
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
gMarioStates[i].marioObj->oActiveParticleFlags = 0; gMarioStates[i].marioObj->oActiveParticleFlags = 0;
} }
} }
if (areaFlags & 0x01) { if (areaFlags & 0x01) {
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
gMarioStates[i].marioObj->header.gfx.areaIndex = index; gMarioStates[i].marioObj->header.gfx.areaIndex = index;
gMarioStates[i].spawnInfo->areaIndex = index; gMarioStates[i].spawnInfo->areaIndex = index;
} }

View file

@ -355,13 +355,11 @@ static void record_demo(void) {
// take the updated controller struct and calculate // take the updated controller struct and calculate
// the new x, y, and distance floats. // the new x, y, and distance floats.
void adjust_analog_stick(struct Controller *controller) { void adjust_analog_stick(struct Controller *controller) {
UNUSED u8 pad[8]; // Reset the controller's x and y floats.
// reset the controller's x and y floats.
controller->stickX = 0; controller->stickX = 0;
controller->stickY = 0; controller->stickY = 0;
// modulate the rawStickX and rawStickY to be the new f32 values by adding/subtracting 6. // Modulate the rawStickX and rawStickY to be the new f32 values by adding/subtracting 6.
if (controller->rawStickX <= -8) { if (controller->rawStickX <= -8) {
controller->stickX = controller->rawStickX + 6; controller->stickX = controller->rawStickX + 6;
} }
@ -378,11 +376,11 @@ void adjust_analog_stick(struct Controller *controller) {
controller->stickY = controller->rawStickY - 6; controller->stickY = controller->rawStickY - 6;
} }
// calculate f32 magnitude from the center by vector length. // Calculate f32 magnitude from the center by vector length.
controller->stickMag = controller->stickMag =
sqrtf(controller->stickX * controller->stickX + controller->stickY * controller->stickY); sqrtf(controller->stickX * controller->stickX + controller->stickY * controller->stickY);
// magnitude cannot exceed 64.0f: if it does, modify the values appropriately to // Magnitude cannot exceed 64.0f: if it does, modify the values appropriately to
// flatten the values down to the allowed maximum value. // flatten the values down to the allowed maximum value.
if (controller->stickMag > 64) { if (controller->stickMag > 64) {
controller->stickX *= 64 / controller->stickMag; controller->stickX *= 64 / controller->stickMag;
@ -455,9 +453,7 @@ void run_demo_inputs(void) {
// update the controller struct with available inputs if present. // update the controller struct with available inputs if present.
void read_controller_inputs(void) { void read_controller_inputs(void) {
s32 i; // If any controllers are plugged in, update the
// if any controllers are plugged in, update the
// controller information. // controller information.
if (gControllerBits) { if (gControllerBits) {
osRecvMesg(&gSIEventMesgQueue, &D_80339BEC, OS_MESG_BLOCK); osRecvMesg(&gSIEventMesgQueue, &D_80339BEC, OS_MESG_BLOCK);
@ -466,7 +462,7 @@ void read_controller_inputs(void) {
} }
run_demo_inputs(); run_demo_inputs();
for (i = 0; i < 1; i++) { for (s32 i = 0; i < 1; i++) {
struct Controller *controller = &gControllers[i]; struct Controller *controller = &gControllers[i];
// if we're receiving inputs, update the controller struct // if we're receiving inputs, update the controller struct
@ -555,7 +551,7 @@ void setup_game_memory(void) {
gPhysicalFrameBuffers[0] = VIRTUAL_TO_PHYSICAL(gFrameBuffer0); gPhysicalFrameBuffers[0] = VIRTUAL_TO_PHYSICAL(gFrameBuffer0);
gPhysicalFrameBuffers[1] = VIRTUAL_TO_PHYSICAL(gFrameBuffer1); gPhysicalFrameBuffers[1] = VIRTUAL_TO_PHYSICAL(gFrameBuffer1);
gPhysicalFrameBuffers[2] = VIRTUAL_TO_PHYSICAL(gFrameBuffer2); gPhysicalFrameBuffers[2] = VIRTUAL_TO_PHYSICAL(gFrameBuffer2);
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
D_80339CF0[i] = main_pool_alloc(0x4000, MEMORY_POOL_LEFT); D_80339CF0[i] = main_pool_alloc(0x4000, MEMORY_POOL_LEFT);
set_segment_base_addr(17, (void *)D_80339CF0[i]); set_segment_base_addr(17, (void *)D_80339CF0[i]);
func_80278A78(&D_80339D10[i], gMarioAnims, D_80339CF0[i]); func_80278A78(&D_80339D10[i], gMarioAnims, D_80339CF0[i]);

View file

@ -1,8 +1,11 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include "types.h" #include "course_table.h"
#include "level_info.h"
#include "game/memory.h" #include "game/memory.h"
#include "level_info.h"
#include "level_table.h"
#include "types.h"
extern u8 seg2_course_name_table[]; extern u8 seg2_course_name_table[];
@ -80,34 +83,52 @@ static void convert_string(const u8* str, char* output) {
} }
const char *get_level_name(s16 courseNum, s16 levelNum, s16 areaIndex) { const char *get_level_name(s16 courseNum, s16 levelNum, s16 areaIndex) {
static char stage[188]; static char stage[188] = { 0 };
// overrides for castle locations
if (courseNum == 0 && levelNum == 16) { //printf("get_level_name: %i %i %i, COURSE_MAX: %u COURSE_MIN: %u.\n", courseNum, levelNum, areaIndex, COURSE_MAX, COURSE_MIN);
// Overrides for non-course based locations.
if (courseNum == COURSE_NONE) {
// A switch case is much more effective here
// then a if statement, It allows for the
// same results for a different level much easier.
// It also auto-covers if none of the cases match
// with a default.
switch (levelNum) {
case LEVEL_CASTLE_GROUNDS:
strcpy(stage, "Castle Grounds"); strcpy(stage, "Castle Grounds");
return stage; break;
} case LEVEL_CASTLE:
if (courseNum == 0 && levelNum == 6) { // Switch case inside a switch case,
if (areaIndex == 1) { // I think it looks ugly but it works.
switch (areaIndex) {
case 1:
strcpy(stage, "Castle Main Floor"); strcpy(stage, "Castle Main Floor");
return stage; break;
} case 2:
else if (areaIndex == 2) {
strcpy(stage, "Castle Upper Floor"); strcpy(stage, "Castle Upper Floor");
return stage; break;
} case 3:
else if (areaIndex == 3) {
strcpy(stage, "Castle Basement"); strcpy(stage, "Castle Basement");
return stage; break;
default: // If we don't have a proper corresponding area, We return the default.
strcpy(stage, "Castle Purgatory");
break;
} }
} break;
if (courseNum == 0 && levelNum == 26) { case LEVEL_CASTLE_COURTYARD:
strcpy(stage, "Castle Courtyard"); strcpy(stage, "Castle Courtyard");
break;
default: // If we don't have a proper corresponding level, We return the default.
strcpy(stage, "Peach's Castle");
break;
}
return stage; return stage;
} }
// If we are in in Course 0 we are in the castle which doesn't have a string // If we are in in Course 0 we are in the castle which doesn't have a string.
if (courseNum > 0 && courseNum < 27) { if (COURSE_IS_VALID_COURSE(courseNum)) {
void** courseNameTbl; void **courseNameTbl = NULL;
#ifndef VERSION_EU #ifndef VERSION_EU
courseNameTbl = segmented_to_virtual(seg2_course_name_table); courseNameTbl = segmented_to_virtual(seg2_course_name_table);

View file

@ -2153,7 +2153,7 @@ static void init_single_mario(struct MarioState* m) {
// figure out if we should apply offset // figure out if we should apply offset
u8 nearbyPlayers = 1; u8 nearbyPlayers = 1;
for (int i = 1; i < MAX_PLAYERS; i++) { for (s32 i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i]; struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected) { continue; } if (!np->connected) { continue; }
if (np->currCourseNum == gCurrCourseNum && np->currLevelNum == gCurrLevelNum && np->currActNum == gCurrActStarNum && np->currAreaIndex == gCurrAreaIndex) { if (np->currCourseNum == gCurrCourseNum && np->currLevelNum == gCurrLevelNum && np->currActNum == gCurrActStarNum && np->currAreaIndex == gCurrAreaIndex) {
@ -2194,10 +2194,9 @@ static void init_single_mario(struct MarioState* m) {
vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0); vec3s_set(m->marioObj->header.gfx.angle, 0, m->faceAngle[1], 0);
// cap will never be lying on the ground in coop // cap will never be lying on the ground in coop
/* struct Object* capObject; /* Vec3s capPos;
Vec3s capPos;
if (save_file_get_cap_pos(capPos)) { if (save_file_get_cap_pos(capPos)) {
capObject = spawn_object(m->marioObj, MODEL_MARIOS_CAP, bhvNormalCap); struct Object *capObject = spawn_object(m->marioObj, MODEL_MARIOS_CAP, bhvNormalCap);
capObject->oPosX = capPos[0]; capObject->oPosX = capPos[0];
capObject->oPosY = capPos[1]; capObject->oPosY = capPos[1];
@ -2223,7 +2222,7 @@ static void init_single_mario(struct MarioState* m) {
} }
void init_mario(void) { void init_mario(void) {
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
gMarioStates[i].playerIndex = i; gMarioStates[i].playerIndex = i;
init_single_mario(&gMarioStates[i]); init_single_mario(&gMarioStates[i]);
} }
@ -2251,7 +2250,7 @@ static void init_mario_single_from_save_file(struct MarioState* m, u16 index) {
} }
void init_mario_from_save_file(void) { void init_mario_from_save_file(void) {
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
init_mario_single_from_save_file(&gMarioStates[i], i); init_mario_single_from_save_file(&gMarioStates[i], i);
} }
gHudDisplay.coins = 0; gHudDisplay.coins = 0;

View file

@ -39,8 +39,9 @@ static void playerlist_update_row(u8 i, struct NetworkPlayer* np) {
} }
void djui_panel_playerlist_on_render_pre(UNUSED struct DjuiBase* base, UNUSED bool* skipRender) { void djui_panel_playerlist_on_render_pre(UNUSED struct DjuiBase* base, UNUSED bool* skipRender) {
int j = 0; s32 j = 0;
for (int i = 0; i < MAX_PLAYERS; i++) {
for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i]; struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected) { continue; } if (!np->connected) { continue; }
playerlist_update_row(j++, np); playerlist_update_row(j++, np);
@ -65,7 +66,7 @@ void djui_panel_playerlist_create(UNUSED struct DjuiBase* caller) {
struct DjuiFlowLayout* body = (struct DjuiFlowLayout*)djui_three_panel_get_body(panel); struct DjuiFlowLayout* body = (struct DjuiFlowLayout*)djui_three_panel_get_body(panel);
djui_flow_layout_set_margin(body, 4); djui_flow_layout_set_margin(body, 4);
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct DjuiFlowLayout* row = djui_flow_layout_create(&body->base); struct DjuiFlowLayout* row = djui_flow_layout_create(&body->base);
djui_base_set_size_type(&row->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); djui_base_set_size_type(&row->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&row->base, 1.0f, 32.0f); djui_base_set_size(&row->base, 1.0f, 32.0f);

View file

@ -35,7 +35,7 @@ void network_player_update_model(u8 localIndex) {
} }
bool network_player_any_connected(void) { bool network_player_any_connected(void) {
for (int i = 1; i < MAX_PLAYERS; i++) { for (s32 i = 1; i < MAX_PLAYERS; i++) {
if (gNetworkPlayers[i].connected) { return true; } if (gNetworkPlayers[i].connected) { return true; }
} }
return false; return false;
@ -43,7 +43,7 @@ bool network_player_any_connected(void) {
u8 network_player_connected_count(void) { u8 network_player_connected_count(void) {
u8 count = 0; u8 count = 0;
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
if (gNetworkPlayers[i].connected) { count++; } if (gNetworkPlayers[i].connected) { count++; }
} }
return count; return count;
@ -65,7 +65,7 @@ void network_player_set_description(struct NetworkPlayer* np, const char* descri
} }
struct NetworkPlayer *network_player_from_global_index(u8 globalIndex) { struct NetworkPlayer *network_player_from_global_index(u8 globalIndex) {
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
if (!gNetworkPlayers[i].connected) { continue; } if (!gNetworkPlayers[i].connected) { continue; }
if (gNetworkPlayers[i].globalIndex == globalIndex) { if (gNetworkPlayers[i].globalIndex == globalIndex) {
return &gNetworkPlayers[i]; return &gNetworkPlayers[i];
@ -75,7 +75,7 @@ struct NetworkPlayer* network_player_from_global_index(u8 globalIndex) {
} }
struct NetworkPlayer *get_network_player_from_level(s16 courseNum, s16 actNum, s16 levelNum) { struct NetworkPlayer *get_network_player_from_level(s16 courseNum, s16 actNum, s16 levelNum) {
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i]; struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected) { continue; } if (!np->connected) { continue; }
if (!np->currLevelSyncValid) { continue; } if (!np->currLevelSyncValid) { continue; }
@ -88,7 +88,7 @@ struct NetworkPlayer* get_network_player_from_level(s16 courseNum, s16 actNum, s
} }
struct NetworkPlayer *get_network_player_from_area(s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) { struct NetworkPlayer *get_network_player_from_area(s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i]; struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected) { continue; } if (!np->connected) { continue; }
if (!np->currLevelSyncValid) { continue; } if (!np->currLevelSyncValid) { continue; }
@ -105,7 +105,7 @@ struct NetworkPlayer* get_network_player_from_area(s16 courseNum, s16 actNum, s1
struct NetworkPlayer *get_network_player_smallest_global(void) { struct NetworkPlayer *get_network_player_smallest_global(void) {
struct NetworkPlayer* lNp = gNetworkPlayerLocal; struct NetworkPlayer* lNp = gNetworkPlayerLocal;
struct NetworkPlayer* smallest = gNetworkPlayerLocal; struct NetworkPlayer* smallest = gNetworkPlayerLocal;
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i]; struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected) { continue; } if (!np->connected) { continue; }
if (!np->currLevelSyncValid) { continue; } if (!np->currLevelSyncValid) { continue; }
@ -120,7 +120,7 @@ struct NetworkPlayer* get_network_player_smallest_global(void) {
} }
void network_player_update(void) { void network_player_update(void) {
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i]; struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected && i > 0) { continue; } if (!np->connected && i > 0) { continue; }
@ -130,7 +130,7 @@ void network_player_update(void) {
if (!network_player_any_connected()) { return; } if (!network_player_any_connected()) { return; }
if (gNetworkType == NT_SERVER) { if (gNetworkType == NT_SERVER) {
for (int i = 1; i < MAX_PLAYERS; i++) { for (s32 i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i]; struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected && i > 0) { continue; } if (!np->connected && i > 0) { continue; }
@ -236,9 +236,9 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
np->onRxSeqId = 0; np->onRxSeqId = 0;
if (localIndex != 0) { if (localIndex != 0) {
for (int j = 0; j < MAX_SYNC_OBJECTS; j++) { gSyncObjects[j].rxEventId[localIndex] = 0; } for (s32 j = 0; j < MAX_SYNC_OBJECTS; j++) { gSyncObjects[j].rxEventId[localIndex] = 0; }
} }
for (int j = 0; j < MAX_RX_SEQ_IDS; j++) { np->rxSeqIds[j] = 0; np->rxPacketHash[j] = 0; } for (s32 j = 0; j < MAX_RX_SEQ_IDS; j++) { np->rxSeqIds[j] = 0; np->rxPacketHash[j] = 0; }
packet_ordered_clear(globalIndex); packet_ordered_clear(globalIndex);
// set up network player pointers // set up network player pointers
@ -280,7 +280,7 @@ u8 network_player_disconnected(u8 globalIndex) {
return UNKNOWN_GLOBAL_INDEX; return UNKNOWN_GLOBAL_INDEX;
} }
for (int i = 1; i < MAX_PLAYERS; i++) { for (s32 i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np = &gNetworkPlayers[i]; struct NetworkPlayer* np = &gNetworkPlayers[i];
if (!np->connected) { continue; } if (!np->connected) { continue; }
if (np->globalIndex != globalIndex) { continue; } if (np->globalIndex != globalIndex) { continue; }
@ -294,7 +294,7 @@ u8 network_player_disconnected(u8 globalIndex) {
np->currAreaSyncValid = false; np->currAreaSyncValid = false;
gNetworkSystem->clear_id(i); gNetworkSystem->clear_id(i);
network_forget_all_reliable_from(i); network_forget_all_reliable_from(i);
for (int j = 0; j < MAX_SYNC_OBJECTS; j++) { gSyncObjects[j].rxEventId[i] = 0; } for (s32 j = 0; j < MAX_SYNC_OBJECTS; j++) { gSyncObjects[j].rxEventId[i] = 0; }
LOG_INFO("player disconnected, local %d, global %d", i, globalIndex); LOG_INFO("player disconnected, local %d, global %d", i, globalIndex);
// display popup // display popup
@ -314,12 +314,13 @@ u8 network_player_disconnected(u8 globalIndex) {
} }
void network_player_update_course_level(struct NetworkPlayer *np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) { void network_player_update_course_level(struct NetworkPlayer *np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
// display popup
bool inCredits = (np->currActNum == 99); bool inCredits = (np->currActNum == 99);
if (np->currCourseNum != courseNum && np->localIndex != 0 && !inCredits) { if (np->currCourseNum != courseNum && np->localIndex != 0 && !inCredits) {
char *playerColorString = network_get_player_text_color_string(np->localIndex); char *playerColorString = network_get_player_text_color_string(np->localIndex);
char popupMsg[128] = { 0 }; char popupMsg[128] = { 0 };
bool matchingLocal = (np->currCourseNum == gNetworkPlayerLocal->currCourseNum) && (np->currActNum == gNetworkPlayerLocal->currActNum); bool matchingLocal = (np->currCourseNum == gNetworkPlayerLocal->currCourseNum) && (np->currActNum == gNetworkPlayerLocal->currActNum);
if (matchingLocal && gNetworkPlayerLocal->currCourseNum != 0) { if (matchingLocal && gNetworkPlayerLocal->currCourseNum != 0) {
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ left this level", playerColorString, np->name); snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ left this level", playerColorString, np->name);
} else if (matchingLocal && gNetworkPlayerLocal->currCourseNum != 0) { } else if (matchingLocal && gNetworkPlayerLocal->currCourseNum != 0) {
@ -327,6 +328,8 @@ void network_player_update_course_level(struct NetworkPlayer* np, s16 courseNum,
} else { } else {
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ entered\n%s", playerColorString, np->name, get_level_name(courseNum, levelNum, areaIndex)); snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ entered\n%s", playerColorString, np->name, get_level_name(courseNum, levelNum, areaIndex));
} }
// display popup
if (configDisablePopups == 0) { if (configDisablePopups == 0) {
djui_popup_create(popupMsg, 1); djui_popup_create(popupMsg, 1);
} }
@ -341,7 +344,7 @@ void network_player_update_course_level(struct NetworkPlayer* np, s16 courseNum,
void network_player_shutdown(void) { void network_player_shutdown(void) {
gNetworkPlayerLocal = NULL; gNetworkPlayerLocal = NULL;
gNetworkPlayerServer = NULL; gNetworkPlayerServer = NULL;
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *networkPlayer = &gNetworkPlayers[i]; struct NetworkPlayer *networkPlayer = &gNetworkPlayers[i];
networkPlayer->connected = false; networkPlayer->connected = false;
gNetworkSystem->clear_id(i); gNetworkSystem->clear_id(i);

View file

@ -13,7 +13,7 @@ static u16 sLevelAreaInformSeq[MAX_PLAYERS][MAX_PLAYERS] = { 0 };
void network_send_level_area_inform(struct NetworkPlayer *np) { void network_send_level_area_inform(struct NetworkPlayer *np) {
SOFT_ASSERT(gNetworkType == NT_SERVER); SOFT_ASSERT(gNetworkType == NT_SERVER);
for (int i = 1; i < MAX_PLAYERS; i++) { for (s32 i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np2 = &gNetworkPlayers[i]; struct NetworkPlayer *np2 = &gNetworkPlayers[i];
if (!np2->connected) { continue; } if (!np2->connected) { continue; }
if (np2->localIndex == np->localIndex) { continue; } if (np2->localIndex == np->localIndex) { continue; }
@ -37,7 +37,6 @@ void network_send_level_area_inform(struct NetworkPlayer* np) {
} }
void network_receive_level_area_inform(struct Packet *p) { void network_receive_level_area_inform(struct Packet *p) {
SOFT_ASSERT(gNetworkType != NT_SERVER); SOFT_ASSERT(gNetworkType != NT_SERVER);
u16 seq; u16 seq;

View file

@ -15,7 +15,7 @@ static void network_send_to_network_players(u8 sendToLocalIndex) {
struct Packet p = { 0 }; struct Packet p = { 0 };
packet_init(&p, PACKET_NETWORK_PLAYERS, true, PLMT_NONE); packet_init(&p, PACKET_NETWORK_PLAYERS, true, PLMT_NONE);
packet_write(&p, &connectedCount, sizeof(u8)); packet_write(&p, &connectedCount, sizeof(u8));
for (int i = 0; i < MAX_PLAYERS; i++) { for (s32 i = 0; i < MAX_PLAYERS; i++) {
if (!gNetworkPlayers[i].connected) { continue; } if (!gNetworkPlayers[i].connected) { continue; }
u8 npType = gNetworkPlayers[i].type; u8 npType = gNetworkPlayers[i].type;
if (npType == NPT_LOCAL) { npType = NPT_SERVER; } if (npType == NPT_LOCAL) { npType = NPT_SERVER; }
@ -62,7 +62,7 @@ void network_receive_network_players_request(struct Packet* p) {
void network_send_network_players(u8 exceptLocalIndex) { void network_send_network_players(u8 exceptLocalIndex) {
SOFT_ASSERT(gNetworkType == NT_SERVER); SOFT_ASSERT(gNetworkType == NT_SERVER);
LOG_INFO("sending list of network players to all"); LOG_INFO("sending list of network players to all");
for (int i = 1; i < MAX_PLAYERS; i++) { for (s32 i = 1; i < MAX_PLAYERS; i++) {
if (!gNetworkPlayers[i].connected) { continue; } if (!gNetworkPlayers[i].connected) { continue; }
if (i == exceptLocalIndex) { continue; } if (i == exceptLocalIndex) { continue; }
network_send_to_network_players(i); network_send_to_network_players(i);
@ -77,7 +77,7 @@ void network_receive_network_players(struct Packet* p) {
} }
u8 connectedCount = 0; u8 connectedCount = 0;
packet_read(p, &connectedCount, sizeof(u8)); packet_read(p, &connectedCount, sizeof(u8));
for (int i = 0; i < connectedCount; i++) { for (s16 i = 0; i < connectedCount; i++) {
u8 npType, globalIndex; u8 npType, globalIndex;
u16 levelAreaSeqId; u16 levelAreaSeqId;
s16 courseNum, actNum, levelNum, areaIndex; s16 courseNum, actNum, levelNum, areaIndex;

View file

@ -21,7 +21,7 @@ void network_send_reservation_list(struct NetworkPlayer* np, u8 syncIds[]) {
packet_write(&p, &np->currLevelNum, sizeof(u8)); packet_write(&p, &np->currLevelNum, sizeof(u8));
packet_write(&p, &np->currAreaIndex, sizeof(u8)); packet_write(&p, &np->currAreaIndex, sizeof(u8));
for (int i = 0; i < RESERVED_IDS_PER_PLAYER_COUNT; i++) { for (s32 i = 0; i < RESERVED_IDS_PER_PLAYER_COUNT; i++) {
packet_write(&p, &syncIds[i], sizeof(u8)); packet_write(&p, &syncIds[i], sizeof(u8));
} }
@ -46,7 +46,7 @@ void network_receive_reservation_list(struct Packet* p) {
} }
u8 syncIds[RESERVED_IDS_PER_PLAYER_COUNT]; u8 syncIds[RESERVED_IDS_PER_PLAYER_COUNT];
for (int i = 0; i < RESERVED_IDS_PER_PLAYER_COUNT; i++) { for (s32 i = 0; i < RESERVED_IDS_PER_PLAYER_COUNT; i++) {
packet_read(p, &syncIds[i], sizeof(u8)); packet_read(p, &syncIds[i], sizeof(u8));
} }