* 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,44 +1,47 @@
#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[];
static const char charset[0xFF + 1] = { static const char charset[0xFF + 1] = {
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 7 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 7
' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', // 15 ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', // 15
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 23 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 23
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 31 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 31
'w', 'x', 'y', 'z', ' ', ' ', ' ', ' ', // 39 'w', 'x', 'y', 'z', ' ', ' ', ' ', ' ', // 39
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 49 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 49
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 55 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 55
' ', ' ', ' ', ' ', ' ', ' ', '\'', ' ', // 63 ' ', ' ', ' ', ' ', ' ', ' ', '\'', ' ', // 63
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 71 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 71
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 79 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 79
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 87 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 87
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 95 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 95
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 103 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 103
' ', ' ', ' ', ' ', ' ', ' ', ' ', ',', // 111 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ',', // 111
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 119 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 119
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 127 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 127
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 135 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 135
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 143 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 143
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 151 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 151
' ', ' ', ' ', ' ', ' ', ' ', ' ', '-', // 159 ' ', ' ', ' ', ' ', ' ', ' ', ' ', '-', // 159
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 167 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 167
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 175 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 175
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 183 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 183
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 192 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 192
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 199 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 199
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 207 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 207
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 215 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 215
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 223 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 223
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 231 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 231
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 239 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 239
' ', ' ', '!', ' ', ' ', ' ', ' ', ' ', // 247 ' ', ' ', '!', ' ', ' ', ' ', ' ', ' ', // 247
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' // 255 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' // 255
}; };
static void convert_string(const u8* str, char* output) { static void convert_string(const u8* str, char* output) {
@ -79,52 +82,70 @@ static void convert_string(const u8* str, char* output) {
output[strPos] = '\0'; output[strPos] = '\0';
} }
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);
strcpy(stage, "Castle Grounds");
return stage; // Overrides for non-course based locations.
} if (courseNum == COURSE_NONE) {
if (courseNum == 0 && levelNum == 6) { // A switch case is much more effective here
if (areaIndex == 1) { // then a if statement, It allows for the
strcpy(stage, "Castle Main Floor"); // same results for a different level much easier.
return stage; // It also auto-covers if none of the cases match
// with a default.
switch (levelNum) {
case LEVEL_CASTLE_GROUNDS:
strcpy(stage, "Castle Grounds");
break;
case LEVEL_CASTLE:
// Switch case inside a switch case,
// I think it looks ugly but it works.
switch (areaIndex) {
case 1:
strcpy(stage, "Castle Main Floor");
break;
case 2:
strcpy(stage, "Castle Upper Floor");
break;
case 3:
strcpy(stage, "Castle Basement");
break;
default: // If we don't have a proper corresponding area, We return the default.
strcpy(stage, "Castle Purgatory");
break;
}
break;
case LEVEL_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;
} }
else if (areaIndex == 2) {
strcpy(stage, "Castle Upper Floor");
return stage;
}
else if (areaIndex == 3) {
strcpy(stage, "Castle Basement");
return stage;
}
}
if (courseNum == 0 && levelNum == 26) {
strcpy(stage, "Castle Courtyard");
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);
#else #else
switch (gInGameLanguage) { switch (gInGameLanguage) {
case LANGUAGE_ENGLISH: case LANGUAGE_ENGLISH:
courseNameTbl = segmented_to_virtual(course_name_table_eu_en); courseNameTbl = segmented_to_virtual(course_name_table_eu_en);
break; break;
case LANGUAGE_FRENCH: case LANGUAGE_FRENCH:
courseNameTbl = segmented_to_virtual(course_name_table_eu_fr); courseNameTbl = segmented_to_virtual(course_name_table_eu_fr);
break; break;
case LANGUAGE_GERMAN: case LANGUAGE_GERMAN:
courseNameTbl = segmented_to_virtual(course_name_table_eu_de); courseNameTbl = segmented_to_virtual(course_name_table_eu_de);
break; break;
} }
#endif #endif
u8* courseName = segmented_to_virtual(courseNameTbl[courseNum - 1]); u8 *courseName = segmented_to_virtual(courseNameTbl[courseNum - 1]);
convert_string(&courseName[3], stage); convert_string(&courseName[3], stage);
} else { } else {

View file

@ -3,6 +3,6 @@
#include <PR/ultratypes.h> #include <PR/ultratypes.h>
const char* get_level_name(s16 courseNum, s16 levelNum, s16 areaIndex); const char *get_level_name(s16 courseNum, s16 levelNum, s16 areaIndex);
#endif // LEVEL_INFO_H #endif // LEVEL_INFO_H

View file

@ -1894,7 +1894,7 @@ static u8 prevent_hang(u32 hangPreventionActions[], u8* hangPreventionIndex) {
s32 execute_mario_action(UNUSED struct Object *o) { s32 execute_mario_action(UNUSED struct Object *o) {
s32 inLoop = TRUE; s32 inLoop = TRUE;
// hide inactive players // hide inactive players
struct NetworkPlayer* np = &gNetworkPlayers[gMarioState->playerIndex]; struct NetworkPlayer *np = &gNetworkPlayers[gMarioState->playerIndex];
if (gMarioState->playerIndex != 0) { if (gMarioState->playerIndex != 0) {
bool levelAreaMismatch = ((gNetworkPlayerLocal == NULL) bool levelAreaMismatch = ((gNetworkPlayerLocal == NULL)
|| np->currCourseNum != gNetworkPlayerLocal->currCourseNum || np->currCourseNum != gNetworkPlayerLocal->currCourseNum
@ -2153,8 +2153,8 @@ 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) {
nearbyPlayers++; nearbyPlayers++;
@ -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

@ -16,7 +16,7 @@ static struct DjuiText* djuiTextNames[MAX_PLAYERS] = { 0 };
static struct DjuiText* djuiTextDescriptions[MAX_PLAYERS] = { 0 }; static struct DjuiText* djuiTextDescriptions[MAX_PLAYERS] = { 0 };
static struct DjuiText* djuiTextLocations[MAX_PLAYERS] = { 0 }; static struct DjuiText* djuiTextLocations[MAX_PLAYERS] = { 0 };
static void playerlist_update_row(u8 i, struct NetworkPlayer* np) { static void playerlist_update_row(u8 i, struct NetworkPlayer *np) {
u8 charIndex = np->overrideModelIndex; u8 charIndex = np->overrideModelIndex;
if (charIndex >= CT_MAX) { charIndex = 0; } if (charIndex >= CT_MAX) { charIndex = 0; }
djuiImages[i]->texture = gCharacters[charIndex].hudHeadTexture.texture; djuiImages[i]->texture = gCharacters[charIndex].hudHeadTexture.texture;
@ -39,9 +39,10 @@ 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++) {
struct NetworkPlayer* np = &gNetworkPlayers[i]; for (s32 i = 0; i < MAX_PLAYERS; 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

@ -10,8 +10,8 @@
#include "pc/lua/smlua_hooks.h" #include "pc/lua/smlua_hooks.h"
struct NetworkPlayer gNetworkPlayers[MAX_PLAYERS] = { 0 }; struct NetworkPlayer gNetworkPlayers[MAX_PLAYERS] = { 0 };
struct NetworkPlayer* gNetworkPlayerLocal = NULL; struct NetworkPlayer *gNetworkPlayerLocal = NULL;
struct NetworkPlayer* gNetworkPlayerServer = NULL; struct NetworkPlayer *gNetworkPlayerServer = NULL;
static char sDefaultPlayerName[] = "Player"; static char sDefaultPlayerName[] = "Player";
void network_player_init(void) { void network_player_init(void) {
@ -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,13 +43,13 @@ 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;
} }
void network_player_set_description(struct NetworkPlayer* np, const char* description, u8 r, u8 g, u8 b, u8 a) { void network_player_set_description(struct NetworkPlayer *np, const char *description, u8 r, u8 g, u8 b, u8 a) {
if (np == NULL) { return; } if (np == NULL) { return; }
if (description != NULL) { if (description != NULL) {
@ -64,8 +64,8 @@ void network_player_set_description(struct NetworkPlayer* np, const char* descri
np->descriptionA = a; np->descriptionA = a;
} }
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];
@ -74,9 +74,9 @@ struct NetworkPlayer* network_player_from_global_index(u8 globalIndex) {
return NULL; return NULL;
} }
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; }
if (np->currCourseNum != courseNum) { continue; } if (np->currCourseNum != courseNum) { continue; }
@ -87,9 +87,9 @@ struct NetworkPlayer* get_network_player_from_level(s16 courseNum, s16 actNum, s
return NULL; return NULL;
} }
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; }
if (!np->currAreaSyncValid) { continue; } if (!np->currAreaSyncValid) { continue; }
@ -102,11 +102,11 @@ struct NetworkPlayer* get_network_player_from_area(s16 courseNum, s16 actNum, s1
return NULL; return NULL;
} }
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; }
if (!np->currAreaSyncValid) { continue; } if (!np->currAreaSyncValid) { continue; }
@ -120,8 +120,8 @@ 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; }
network_player_update_model(i); network_player_update_model(i);
@ -130,8 +130,8 @@ 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; }
float elapsed = (clock_elapsed() - np->lastReceived); float elapsed = (clock_elapsed() - np->lastReceived);
@ -148,7 +148,7 @@ void network_player_update(void) {
} }
} }
} else if (gNetworkType == NT_CLIENT && gNetworkSentJoin) { } else if (gNetworkType == NT_CLIENT && gNetworkSentJoin) {
struct NetworkPlayer* np = gNetworkPlayerServer; struct NetworkPlayer *np = gNetworkPlayerServer;
if (!np->connected) { return; } if (!np->connected) { return; }
float elapsed = (clock_elapsed() - np->lastReceived); float elapsed = (clock_elapsed() - np->lastReceived);
@ -166,7 +166,7 @@ void network_player_update(void) {
} }
} }
u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, u8 paletteIndex, char* name) { u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 modelIndex, u8 paletteIndex, char *name) {
// translate globalIndex to localIndex // translate globalIndex to localIndex
u8 localIndex = globalIndex; u8 localIndex = globalIndex;
if (gNetworkType == NT_SERVER) { if (gNetworkType == NT_SERVER) {
@ -180,7 +180,7 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
} else { } else {
assert(false); assert(false);
} }
struct NetworkPlayer* np = &gNetworkPlayers[localIndex]; struct NetworkPlayer *np = &gNetworkPlayers[localIndex];
// ensure that a name is given // ensure that a name is given
if (name[0] == '\0') { if (name[0] == '\0') {
@ -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
@ -253,7 +253,7 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
// display connected popup // display connected popup
if (type != NPT_SERVER && (gNetworkType != NT_SERVER || type != NPT_LOCAL)) { if (type != NPT_SERVER && (gNetworkType != NT_SERVER || type != NPT_LOCAL)) {
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 };
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ connected", playerColorString, np->name); snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ connected", playerColorString, np->name);
djui_popup_create(popupMsg, 1); djui_popup_create(popupMsg, 1);
@ -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,11 +294,11 @@ 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
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 };
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ disconnected", playerColorString, np->name); snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ disconnected", playerColorString, np->name);
djui_popup_create(popupMsg, 1); djui_popup_create(popupMsg, 1);
@ -313,13 +313,14 @@ u8 network_player_disconnected(u8 globalIndex) {
return UNKNOWN_GLOBAL_INDEX; return UNKNOWN_GLOBAL_INDEX;
} }
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,8 +344,8 @@ 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

@ -5,14 +5,14 @@
//#define DISABLE_MODULE_LOG 1 //#define DISABLE_MODULE_LOG 1
#include "pc/debuglog.h" #include "pc/debuglog.h"
static void player_changed_area(struct NetworkPlayer* np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) { static void player_changed_area(struct NetworkPlayer *np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
// set NetworkPlayer variables // set NetworkPlayer variables
network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex); network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex);
np->currAreaSyncValid = false; np->currAreaSyncValid = false;
reservation_area_change(np); reservation_area_change(np);
// find a NetworkPlayer at that area // find a NetworkPlayer at that area
struct NetworkPlayer* npLevelAreaMatch = get_network_player_from_area(courseNum, actNum, levelNum, areaIndex); struct NetworkPlayer *npLevelAreaMatch = get_network_player_from_area(courseNum, actNum, levelNum, areaIndex);
bool inCredits = (np->currActNum == 99); bool inCredits = (np->currActNum == 99);
if (npLevelAreaMatch == NULL || inCredits) { if (npLevelAreaMatch == NULL || inCredits) {
@ -52,18 +52,18 @@ void network_send_change_area(void) {
packet_write(&p, &gCurrAreaIndex, sizeof(s16)); packet_write(&p, &gCurrAreaIndex, sizeof(s16));
network_send_to(gNetworkPlayerServer->localIndex, &p); network_send_to(gNetworkPlayerServer->localIndex, &p);
struct NetworkPlayer* np = gNetworkPlayerLocal; struct NetworkPlayer *np = gNetworkPlayerLocal;
network_player_update_course_level(np, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex); network_player_update_course_level(np, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex);
np->currAreaSyncValid = false; np->currAreaSyncValid = false;
LOG_INFO("tx change area"); LOG_INFO("tx change area");
} }
void network_receive_change_area(struct Packet* p) { void network_receive_change_area(struct Packet *p) {
LOG_INFO("rx change area"); LOG_INFO("rx change area");
SOFT_ASSERT(gNetworkType == NT_SERVER); SOFT_ASSERT(gNetworkType == NT_SERVER);
struct NetworkPlayer* np = &gNetworkPlayers[p->localIndex]; struct NetworkPlayer *np = &gNetworkPlayers[p->localIndex];
if (np == NULL || np->localIndex == UNKNOWN_LOCAL_INDEX || !np->connected) { if (np == NULL || np->localIndex == UNKNOWN_LOCAL_INDEX || !np->connected) {
LOG_ERROR("Receiving change area from inactive player!"); LOG_ERROR("Receiving change area from inactive player!");
return; return;

View file

@ -5,7 +5,7 @@
//#define DISABLE_MODULE_LOG 1 //#define DISABLE_MODULE_LOG 1
#include "pc/debuglog.h" #include "pc/debuglog.h"
static void player_changed_level(struct NetworkPlayer* np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) { static void player_changed_level(struct NetworkPlayer *np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
// set NetworkPlayer variables // set NetworkPlayer variables
network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex); network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex);
np->currLevelSyncValid = false; np->currLevelSyncValid = false;
@ -13,9 +13,9 @@ static void player_changed_level(struct NetworkPlayer* np, s16 courseNum, s16 ac
reservation_area_change(np); reservation_area_change(np);
// find a NetworkPlayer around that location // find a NetworkPlayer around that location
struct NetworkPlayer* npLevelAreaMatch = get_network_player_from_area(courseNum, actNum, levelNum, areaIndex); struct NetworkPlayer *npLevelAreaMatch = get_network_player_from_area(courseNum, actNum, levelNum, areaIndex);
struct NetworkPlayer* npLevelMatch = get_network_player_from_level(courseNum, actNum, levelNum); struct NetworkPlayer *npLevelMatch = get_network_player_from_level(courseNum, actNum, levelNum);
struct NetworkPlayer* npAny = (npLevelAreaMatch == NULL) ? npLevelMatch : npLevelAreaMatch; struct NetworkPlayer *npAny = (npLevelAreaMatch == NULL) ? npLevelMatch : npLevelAreaMatch;
bool inCredits = (np->currActNum == 99); bool inCredits = (np->currActNum == 99);
if (npAny == NULL || inCredits) { if (npAny == NULL || inCredits) {
@ -58,7 +58,7 @@ void network_send_change_level(void) {
packet_write(&p, &gCurrAreaIndex, sizeof(s16)); packet_write(&p, &gCurrAreaIndex, sizeof(s16));
network_send_to(gNetworkPlayerServer->localIndex, &p); network_send_to(gNetworkPlayerServer->localIndex, &p);
struct NetworkPlayer* np = gNetworkPlayerLocal; struct NetworkPlayer *np = gNetworkPlayerLocal;
network_player_update_course_level(np, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex); network_player_update_course_level(np, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex);
np->currAreaSyncValid = false; np->currAreaSyncValid = false;
np->currLevelSyncValid = false; np->currLevelSyncValid = false;
@ -66,11 +66,11 @@ void network_send_change_level(void) {
LOG_INFO("tx change level"); LOG_INFO("tx change level");
} }
void network_receive_change_level(struct Packet* p) { void network_receive_change_level(struct Packet *p) {
LOG_INFO("rx change level"); LOG_INFO("rx change level");
SOFT_ASSERT(gNetworkType == NT_SERVER); SOFT_ASSERT(gNetworkType == NT_SERVER);
struct NetworkPlayer* np = &gNetworkPlayers[p->localIndex]; struct NetworkPlayer *np = &gNetworkPlayers[p->localIndex];
if (np == NULL || np->localIndex == UNKNOWN_LOCAL_INDEX || !np->connected) { if (np == NULL || np->localIndex == UNKNOWN_LOCAL_INDEX || !np->connected) {
LOG_ERROR("Receiving change level from inactive player!"); LOG_ERROR("Receiving change level from inactive player!");
return; return;

View file

@ -10,11 +10,11 @@
static u16 sLevelAreaInformSeq[MAX_PLAYERS][MAX_PLAYERS] = { 0 }; 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; }
@ -36,8 +36,7 @@ void network_send_level_area_inform(struct NetworkPlayer* np) {
LOG_INFO("tx level area inform for global %d: (%d, %d, %d, %d)", np->globalIndex, np->currCourseNum, np->currActNum, np->currLevelNum, np->currAreaIndex); LOG_INFO("tx level area inform for global %d: (%d, %d, %d, %d)", np->globalIndex, np->currCourseNum, np->currActNum, np->currLevelNum, np->currAreaIndex);
} }
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;
@ -55,7 +54,7 @@ void network_receive_level_area_inform(struct Packet* p) {
LOG_INFO("rx level area inform for global %d: (%d, %d, %d, %d)", globalIndex, courseNum, actNum, levelNum, areaIndex); LOG_INFO("rx level area inform for global %d: (%d, %d, %d, %d)", globalIndex, courseNum, actNum, levelNum, areaIndex);
struct NetworkPlayer* np = network_player_from_global_index(globalIndex); struct NetworkPlayer *np = network_player_from_global_index(globalIndex);
if (np == NULL || np->localIndex == UNKNOWN_LOCAL_INDEX || !np->connected) { if (np == NULL || np->localIndex == UNKNOWN_LOCAL_INDEX || !np->connected) {
LOG_ERROR("Receiving level area inform from inactive player!"); LOG_ERROR("Receiving level area inform from inactive player!");
return; return;
@ -72,4 +71,4 @@ void network_receive_level_area_inform(struct Packet* p) {
network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex); network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex);
np->currLevelSyncValid = levelSyncValid; np->currLevelSyncValid = levelSyncValid;
np->currAreaSyncValid = areaSyncValid; np->currAreaSyncValid = areaSyncValid;
} }

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,14 +62,14 @@ 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);
} }
} }
void network_receive_network_players(struct Packet* p) { void network_receive_network_players(struct Packet *p) {
LOG_INFO("receiving list of network players"); LOG_INFO("receiving list of network players");
if (gNetworkType != NT_CLIENT) { if (gNetworkType != NT_CLIENT) {
LOG_ERROR("received list of clients as a non-client"); LOG_ERROR("received list of clients as a non-client");
@ -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;
@ -103,7 +103,7 @@ void network_receive_network_players(struct Packet* p) {
u8 localIndex = network_player_connected(npType, globalIndex, modelIndex, paletteIndex, playerName); u8 localIndex = network_player_connected(npType, globalIndex, modelIndex, paletteIndex, playerName);
LOG_INFO("received network player [%d == %d] (%d)", globalIndex, npType, localIndex); LOG_INFO("received network player [%d == %d] (%d)", globalIndex, npType, localIndex);
if (localIndex != UNKNOWN_GLOBAL_INDEX) { if (localIndex != UNKNOWN_GLOBAL_INDEX) {
struct NetworkPlayer* np = &gNetworkPlayers[localIndex]; struct NetworkPlayer *np = &gNetworkPlayers[localIndex];
if (localIndex != 0) { if (localIndex != 0) {
np->currLevelAreaSeqId = levelAreaSeqId; np->currLevelAreaSeqId = levelAreaSeqId;
network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex); network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex);

View file

@ -3,9 +3,9 @@
//#define DISABLE_MODULE_LOG 1 //#define DISABLE_MODULE_LOG 1
#include "pc/debuglog.h" #include "pc/debuglog.h"
void network_send_request_failed(struct NetworkPlayer* toNp, u8 requestType) { void network_send_request_failed(struct NetworkPlayer *toNp, u8 requestType) {
if (gNetworkType == NT_SERVER && toNp == gNetworkPlayerLocal) { if (gNetworkType == NT_SERVER && toNp == gNetworkPlayerLocal) {
struct NetworkPlayer* np = gNetworkPlayerLocal; struct NetworkPlayer *np = gNetworkPlayerLocal;
if (requestType == 0 && !np->currLevelSyncValid) { if (requestType == 0 && !np->currLevelSyncValid) {
LOG_INFO("re-requesting level"); LOG_INFO("re-requesting level");
network_send_change_level(); network_send_change_level();
@ -24,13 +24,13 @@ void network_send_request_failed(struct NetworkPlayer* toNp, u8 requestType) {
LOG_INFO("tx request failed"); LOG_INFO("tx request failed");
} }
void network_receive_request_failed(struct Packet* p) { void network_receive_request_failed(struct Packet *p) {
LOG_INFO("rx request failed"); LOG_INFO("rx request failed");
u8 requestType; u8 requestType;
packet_read(p, &requestType, sizeof(u8)); packet_read(p, &requestType, sizeof(u8));
struct NetworkPlayer* np = gNetworkPlayerLocal; struct NetworkPlayer *np = gNetworkPlayerLocal;
if (requestType == 0 && !np->currLevelSyncValid) { if (requestType == 0 && !np->currLevelSyncValid) {
LOG_INFO("re-requesting level"); LOG_INFO("re-requesting level");
network_send_change_level(); network_send_change_level();

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));
} }