Merge branch 'unstable' of github.com:sm64ex-coop-dev/sm64ex-coop into unstable

This commit is contained in:
MysterD 2022-03-26 23:58:24 -07:00
commit e346e8a275
16 changed files with 208 additions and 166 deletions

View File

@ -28,5 +28,7 @@ enum CourseNum
#undef DEFINE_BONUS_COURSE
#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

View File

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

View File

@ -355,13 +355,11 @@ static void record_demo(void) {
// take the updated controller struct and calculate
// the new x, y, and distance floats.
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->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) {
controller->stickX = controller->rawStickX + 6;
}
@ -378,11 +376,11 @@ void adjust_analog_stick(struct Controller *controller) {
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 =
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.
if (controller->stickMag > 64) {
controller->stickX *= 64 / controller->stickMag;
@ -455,9 +453,7 @@ void run_demo_inputs(void) {
// update the controller struct with available inputs if present.
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.
if (gControllerBits) {
osRecvMesg(&gSIEventMesgQueue, &D_80339BEC, OS_MESG_BLOCK);
@ -466,7 +462,7 @@ void read_controller_inputs(void) {
}
run_demo_inputs();
for (i = 0; i < 1; i++) {
for (s32 i = 0; i < 1; i++) {
struct Controller *controller = &gControllers[i];
// 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[1] = VIRTUAL_TO_PHYSICAL(gFrameBuffer1);
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);
set_segment_base_addr(17, (void *)D_80339CF0[i]);
func_80278A78(&D_80339D10[i], gMarioAnims, D_80339CF0[i]);

View File

@ -1,44 +1,47 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "types.h"
#include "level_info.h"
#include "course_table.h"
#include "game/memory.h"
#include "level_info.h"
#include "level_table.h"
#include "types.h"
extern u8 seg2_course_name_table[];
static const char charset[0xFF + 1] = {
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 7
' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', // 15
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 23
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 31
'w', 'x', 'y', 'z', ' ', ' ', ' ', ' ', // 39
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 49
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 55
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 7
' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', // 15
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 23
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 31
'w', 'x', 'y', 'z', ' ', ' ', ' ', ' ', // 39
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 49
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 55
' ', ' ', ' ', ' ', ' ', ' ', '\'', ' ', // 63
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 71
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 79
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 87
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 95
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 103
' ', ' ', ' ', ' ', ' ', ' ', ' ', ',', // 111
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 119
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 127
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 135
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 143
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 151
' ', ' ', ' ', ' ', ' ', ' ', ' ', '-', // 159
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 167
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 175
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 183
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 192
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 199
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 207
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 215
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 223
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 231
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 239
' ', ' ', '!', ' ', ' ', ' ', ' ', ' ', // 247
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' // 255
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 71
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 79
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 87
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 95
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 103
' ', ' ', ' ', ' ', ' ', ' ', ' ', ',', // 111
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 119
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 127
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 135
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 143
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 151
' ', ' ', ' ', ' ', ' ', ' ', ' ', '-', // 159
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 167
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 175
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 183
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 192
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 199
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 207
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 215
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 223
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 231
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 239
' ', ' ', '!', ' ', ' ', ' ', ' ', ' ', // 247
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' // 255
};
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';
}
const char* get_level_name(s16 courseNum, s16 levelNum, s16 areaIndex) {
static char stage[188];
// overrides for castle locations
if (courseNum == 0 && levelNum == 16) {
strcpy(stage, "Castle Grounds");
return stage;
}
if (courseNum == 0 && levelNum == 6) {
if (areaIndex == 1) {
strcpy(stage, "Castle Main Floor");
return stage;
const char *get_level_name(s16 courseNum, s16 levelNum, s16 areaIndex) {
static char stage[188] = { 0 };
//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");
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;
}
// If we are in in Course 0 we are in the castle which doesn't have a string
if (courseNum > 0 && courseNum < 27) {
void** courseNameTbl;
// If we are in in Course 0 we are in the castle which doesn't have a string.
if (COURSE_IS_VALID_COURSE(courseNum)) {
void **courseNameTbl = NULL;
#ifndef VERSION_EU
courseNameTbl = segmented_to_virtual(seg2_course_name_table);
#else
switch (gInGameLanguage) {
case LANGUAGE_ENGLISH:
courseNameTbl = segmented_to_virtual(course_name_table_eu_en);
break;
case LANGUAGE_FRENCH:
courseNameTbl = segmented_to_virtual(course_name_table_eu_fr);
break;
case LANGUAGE_GERMAN:
courseNameTbl = segmented_to_virtual(course_name_table_eu_de);
break;
case LANGUAGE_ENGLISH:
courseNameTbl = segmented_to_virtual(course_name_table_eu_en);
break;
case LANGUAGE_FRENCH:
courseNameTbl = segmented_to_virtual(course_name_table_eu_fr);
break;
case LANGUAGE_GERMAN:
courseNameTbl = segmented_to_virtual(course_name_table_eu_de);
break;
}
#endif
u8* courseName = segmented_to_virtual(courseNameTbl[courseNum - 1]);
u8 *courseName = segmented_to_virtual(courseNameTbl[courseNum - 1]);
convert_string(&courseName[3], stage);
} else {

View File

@ -3,6 +3,6 @@
#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

View File

@ -1894,7 +1894,7 @@ static u8 prevent_hang(u32 hangPreventionActions[], u8* hangPreventionIndex) {
s32 execute_mario_action(UNUSED struct Object *o) {
s32 inLoop = TRUE;
// hide inactive players
struct NetworkPlayer* np = &gNetworkPlayers[gMarioState->playerIndex];
struct NetworkPlayer *np = &gNetworkPlayers[gMarioState->playerIndex];
if (gMarioState->playerIndex != 0) {
bool levelAreaMismatch = ((gNetworkPlayerLocal == NULL)
|| np->currCourseNum != gNetworkPlayerLocal->currCourseNum
@ -2153,8 +2153,8 @@ static void init_single_mario(struct MarioState* m) {
// figure out if we should apply offset
u8 nearbyPlayers = 1;
for (int i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np = &gNetworkPlayers[i];
for (s32 i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected) { continue; }
if (np->currCourseNum == gCurrCourseNum && np->currLevelNum == gCurrLevelNum && np->currActNum == gCurrActStarNum && np->currAreaIndex == gCurrAreaIndex) {
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);
// cap will never be lying on the ground in coop
/* struct Object* capObject;
Vec3s capPos;
/* Vec3s 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->oPosY = capPos[1];
@ -2223,7 +2222,7 @@ static void init_single_mario(struct MarioState* m) {
}
void init_mario(void) {
for (int i = 0; i < MAX_PLAYERS; i++) {
for (s32 i = 0; i < MAX_PLAYERS; i++) {
gMarioStates[i].playerIndex = 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) {
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);
}
gHudDisplay.coins = 0;

View File

@ -608,6 +608,18 @@ s32 act_debug_free_move(struct MarioState *m) {
f32 speed;
u32 action;
#ifndef DEVELOPMENT
if (gNetworkType == NT_SERVER && configEnableCheats == 0 && m->action == ACT_DEBUG_FREE_MOVE) {
if (m->pos[1] <= m->waterLevel - 100) {
action = ACT_WATER_IDLE;
} else {
action = ACT_FREEFALL;
}
set_mario_action(m, action, 0);
return FALSE;
}
#endif
// integer immediates, generates convert instructions for some reason
speed = gPlayer1Controller->buttonDown & B_BUTTON ? 1 : 4;

View File

@ -16,7 +16,7 @@ static struct DjuiText* djuiTextNames[MAX_PLAYERS] = { 0 };
static struct DjuiText* djuiTextDescriptions[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;
if (charIndex >= CT_MAX) { charIndex = 0; }
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) {
int j = 0;
for (int i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np = &gNetworkPlayers[i];
s32 j = 0;
for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected) { continue; }
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);
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);
djui_base_set_size_type(&row->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&row->base, 1.0f, 32.0f);

View File

@ -10,8 +10,8 @@
#include "pc/lua/smlua_hooks.h"
struct NetworkPlayer gNetworkPlayers[MAX_PLAYERS] = { 0 };
struct NetworkPlayer* gNetworkPlayerLocal = NULL;
struct NetworkPlayer* gNetworkPlayerServer = NULL;
struct NetworkPlayer *gNetworkPlayerLocal = NULL;
struct NetworkPlayer *gNetworkPlayerServer = NULL;
static char sDefaultPlayerName[] = "Player";
void network_player_init(void) {
@ -35,7 +35,7 @@ void network_player_update_model(u8 localIndex) {
}
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; }
}
return false;
@ -43,13 +43,13 @@ bool network_player_any_connected(void) {
u8 network_player_connected_count(void) {
u8 count = 0;
for (int i = 0; i < MAX_PLAYERS; i++) {
for (s32 i = 0; i < MAX_PLAYERS; i++) {
if (gNetworkPlayers[i].connected) { 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 (description != NULL) {
@ -64,8 +64,8 @@ void network_player_set_description(struct NetworkPlayer* np, const char* descri
np->descriptionA = a;
}
struct NetworkPlayer* network_player_from_global_index(u8 globalIndex) {
for (int i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *network_player_from_global_index(u8 globalIndex) {
for (s32 i = 0; i < MAX_PLAYERS; i++) {
if (!gNetworkPlayers[i].connected) { continue; }
if (gNetworkPlayers[i].globalIndex == globalIndex) {
return &gNetworkPlayers[i];
@ -74,9 +74,9 @@ struct NetworkPlayer* network_player_from_global_index(u8 globalIndex) {
return NULL;
}
struct NetworkPlayer* get_network_player_from_level(s16 courseNum, s16 actNum, s16 levelNum) {
for (int i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np = &gNetworkPlayers[i];
struct NetworkPlayer *get_network_player_from_level(s16 courseNum, s16 actNum, s16 levelNum) {
for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected) { continue; }
if (!np->currLevelSyncValid) { continue; }
if (np->currCourseNum != courseNum) { continue; }
@ -87,9 +87,9 @@ struct NetworkPlayer* get_network_player_from_level(s16 courseNum, s16 actNum, s
return NULL;
}
struct NetworkPlayer* get_network_player_from_area(s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
for (int i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np = &gNetworkPlayers[i];
struct NetworkPlayer *get_network_player_from_area(s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected) { continue; }
if (!np->currLevelSyncValid) { continue; }
if (!np->currAreaSyncValid) { continue; }
@ -102,11 +102,11 @@ struct NetworkPlayer* get_network_player_from_area(s16 courseNum, s16 actNum, s1
return NULL;
}
struct NetworkPlayer* get_network_player_smallest_global(void) {
struct NetworkPlayer *get_network_player_smallest_global(void) {
struct NetworkPlayer* lNp = gNetworkPlayerLocal;
struct NetworkPlayer* smallest = gNetworkPlayerLocal;
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->currLevelSyncValid) { continue; }
if (!np->currAreaSyncValid) { continue; }
@ -120,8 +120,8 @@ struct NetworkPlayer* get_network_player_smallest_global(void) {
}
void network_player_update(void) {
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 && i > 0) { continue; }
network_player_update_model(i);
@ -130,8 +130,8 @@ void network_player_update(void) {
if (!network_player_any_connected()) { return; }
if (gNetworkType == NT_SERVER) {
for (int i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np = &gNetworkPlayers[i];
for (s32 i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np = &gNetworkPlayers[i];
if (!np->connected && i > 0) { continue; }
float elapsed = (clock_elapsed() - np->lastReceived);
@ -148,7 +148,7 @@ void network_player_update(void) {
}
}
} else if (gNetworkType == NT_CLIENT && gNetworkSentJoin) {
struct NetworkPlayer* np = gNetworkPlayerServer;
struct NetworkPlayer *np = gNetworkPlayerServer;
if (!np->connected) { return; }
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
u8 localIndex = globalIndex;
if (gNetworkType == NT_SERVER) {
@ -180,7 +180,7 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
} else {
assert(false);
}
struct NetworkPlayer* np = &gNetworkPlayers[localIndex];
struct NetworkPlayer *np = &gNetworkPlayers[localIndex];
// ensure that a name is given
if (name[0] == '\0') {
@ -236,9 +236,9 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
np->onRxSeqId = 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);
// set up network player pointers
@ -253,7 +253,7 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
// display connected popup
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 };
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ connected", playerColorString, np->name);
djui_popup_create(popupMsg, 1);
@ -280,7 +280,7 @@ u8 network_player_disconnected(u8 globalIndex) {
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];
if (!np->connected) { continue; }
if (np->globalIndex != globalIndex) { continue; }
@ -294,11 +294,11 @@ u8 network_player_disconnected(u8 globalIndex) {
np->currAreaSyncValid = false;
gNetworkSystem->clear_id(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);
// 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 };
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ disconnected", playerColorString, np->name);
djui_popup_create(popupMsg, 1);
@ -313,13 +313,14 @@ u8 network_player_disconnected(u8 globalIndex) {
return UNKNOWN_GLOBAL_INDEX;
}
void network_player_update_course_level(struct NetworkPlayer* np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
// display popup
void network_player_update_course_level(struct NetworkPlayer *np, s16 courseNum, s16 actNum, s16 levelNum, s16 areaIndex) {
bool inCredits = (np->currActNum == 99);
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 };
bool matchingLocal = (np->currCourseNum == gNetworkPlayerLocal->currCourseNum) && (np->currActNum == gNetworkPlayerLocal->currActNum);
if (matchingLocal && gNetworkPlayerLocal->currCourseNum != 0) {
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ left this level", playerColorString, np->name);
} else if (matchingLocal && gNetworkPlayerLocal->currCourseNum != 0) {
@ -327,6 +328,8 @@ void network_player_update_course_level(struct NetworkPlayer* np, s16 courseNum,
} else {
snprintf(popupMsg, 128, "%s%s\\#dcdcdc\\ entered\n%s", playerColorString, np->name, get_level_name(courseNum, levelNum, areaIndex));
}
// display popup
if (configDisablePopups == 0) {
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) {
gNetworkPlayerLocal = NULL;
gNetworkPlayerServer = NULL;
for (int i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* networkPlayer = &gNetworkPlayers[i];
for (s32 i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *networkPlayer = &gNetworkPlayers[i];
networkPlayer->connected = false;
gNetworkSystem->clear_id(i);
}

View File

@ -5,14 +5,14 @@
//#define DISABLE_MODULE_LOG 1
#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
network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex);
np->currAreaSyncValid = false;
reservation_area_change(np);
// 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);
if (npLevelAreaMatch == NULL || inCredits) {
@ -52,18 +52,18 @@ void network_send_change_area(void) {
packet_write(&p, &gCurrAreaIndex, sizeof(s16));
network_send_to(gNetworkPlayerServer->localIndex, &p);
struct NetworkPlayer* np = gNetworkPlayerLocal;
struct NetworkPlayer *np = gNetworkPlayerLocal;
network_player_update_course_level(np, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex);
np->currAreaSyncValid = false;
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");
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) {
LOG_ERROR("Receiving change area from inactive player!");
return;

View File

@ -5,7 +5,7 @@
//#define DISABLE_MODULE_LOG 1
#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
network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex);
np->currLevelSyncValid = false;
@ -13,9 +13,9 @@ static void player_changed_level(struct NetworkPlayer* np, s16 courseNum, s16 ac
reservation_area_change(np);
// find a NetworkPlayer around that location
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* npAny = (npLevelAreaMatch == NULL) ? npLevelMatch : npLevelAreaMatch;
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 *npAny = (npLevelAreaMatch == NULL) ? npLevelMatch : npLevelAreaMatch;
bool inCredits = (np->currActNum == 99);
if (npAny == NULL || inCredits) {
@ -58,7 +58,7 @@ void network_send_change_level(void) {
packet_write(&p, &gCurrAreaIndex, sizeof(s16));
network_send_to(gNetworkPlayerServer->localIndex, &p);
struct NetworkPlayer* np = gNetworkPlayerLocal;
struct NetworkPlayer *np = gNetworkPlayerLocal;
network_player_update_course_level(np, gCurrCourseNum, gCurrActStarNum, gCurrLevelNum, gCurrAreaIndex);
np->currAreaSyncValid = false;
np->currLevelSyncValid = false;
@ -66,11 +66,11 @@ void network_send_change_level(void) {
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");
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) {
LOG_ERROR("Receiving change level from inactive player!");
return;

View File

@ -10,11 +10,11 @@
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);
for (int i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np2 = &gNetworkPlayers[i];
for (s32 i = 1; i < MAX_PLAYERS; i++) {
struct NetworkPlayer *np2 = &gNetworkPlayers[i];
if (!np2->connected) { 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);
}
void network_receive_level_area_inform(struct Packet* p) {
void network_receive_level_area_inform(struct Packet *p) {
SOFT_ASSERT(gNetworkType != NT_SERVER);
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);
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) {
LOG_ERROR("Receiving level area inform from inactive player!");
return;
@ -72,4 +71,4 @@ void network_receive_level_area_inform(struct Packet* p) {
network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex);
np->currLevelSyncValid = levelSyncValid;
np->currAreaSyncValid = areaSyncValid;
}
}

View File

@ -15,7 +15,7 @@ static void network_send_to_network_players(u8 sendToLocalIndex) {
struct Packet p = { 0 };
packet_init(&p, PACKET_NETWORK_PLAYERS, true, PLMT_NONE);
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; }
u8 npType = gNetworkPlayers[i].type;
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) {
SOFT_ASSERT(gNetworkType == NT_SERVER);
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 (i == exceptLocalIndex) { continue; }
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");
if (gNetworkType != NT_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;
packet_read(p, &connectedCount, sizeof(u8));
for (int i = 0; i < connectedCount; i++) {
for (s16 i = 0; i < connectedCount; i++) {
u8 npType, globalIndex;
u16 levelAreaSeqId;
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);
LOG_INFO("received network player [%d == %d] (%d)", globalIndex, npType, localIndex);
if (localIndex != UNKNOWN_GLOBAL_INDEX) {
struct NetworkPlayer* np = &gNetworkPlayers[localIndex];
struct NetworkPlayer *np = &gNetworkPlayers[localIndex];
if (localIndex != 0) {
np->currLevelAreaSeqId = levelAreaSeqId;
network_player_update_course_level(np, courseNum, actNum, levelNum, areaIndex);

View File

@ -360,7 +360,20 @@ void network_receive_player(struct Packet* p) {
vec3f_copy(m->marioObj->header.gfx.pos, m->pos);
vec3s_copy(m->marioObj->header.gfx.angle, m->faceAngle);
}
#ifndef DEVELOPMENT
if (gNetworkType == NT_SERVER && configEnableCheats == 0) {
for (int i = 0; i < MAX_PLAYERS; i++) {
struct NetworkPlayer* np = &gNetworkPlayers[i];
struct MarioState* m = &gMarioStates[np->localIndex];
if (m->action == ACT_DEBUG_FREE_MOVE) {
network_send_kick(np->localIndex, EKT_CLOSE_CONNECTION);
network_player_disconnected(np->localIndex);
}
}
}
}
#endif
void network_update_player(void) {
if (!network_player_any_connected()) { return; }

View File

@ -3,9 +3,9 @@
//#define DISABLE_MODULE_LOG 1
#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) {
struct NetworkPlayer* np = gNetworkPlayerLocal;
struct NetworkPlayer *np = gNetworkPlayerLocal;
if (requestType == 0 && !np->currLevelSyncValid) {
LOG_INFO("re-requesting level");
network_send_change_level();
@ -24,13 +24,13 @@ void network_send_request_failed(struct NetworkPlayer* toNp, u8 requestType) {
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");
u8 requestType;
packet_read(p, &requestType, sizeof(u8));
struct NetworkPlayer* np = gNetworkPlayerLocal;
struct NetworkPlayer *np = gNetworkPlayerLocal;
if (requestType == 0 && !np->currLevelSyncValid) {
LOG_INFO("re-requesting 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->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));
}
@ -46,7 +46,7 @@ void network_receive_reservation_list(struct Packet* p) {
}
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));
}