From 92692378b4ca3a5c3daf116d46cfa97b825d5003 Mon Sep 17 00:00:00 2001 From: MysterD Date: Mon, 30 Aug 2021 18:22:36 -0700 Subject: [PATCH] Added adjustable draw distance for objects --- src/engine/behavior_script.c | 17 +- src/engine/behavior_script.h | 2 +- src/engine/surface_load.c | 12 +- src/game/behaviors/bub.inc.c | 19 +- src/game/behaviors/chain_chomp.inc.c | 230 ++++++++---------- src/game/behaviors/cloud.inc.c | 76 +++--- src/game/behaviors/coin.inc.c | 18 +- src/game/behaviors/enemy_lakitu.inc.c | 14 +- src/game/behaviors/fish.inc.c | 37 +-- src/game/behaviors/goomba.inc.c | 40 ++- src/game/behaviors/heave_ho.inc.c | 6 - src/game/behaviors/king_bobomb.inc.c | 9 +- .../behaviors/lll_floating_wood_piece.inc.c | 20 +- .../behaviors/lll_rotating_hex_flame.inc.c | 9 +- src/game/behaviors/piranha_plant.inc.c | 7 +- src/game/behaviors/pokey.inc.c | 38 ++- src/game/behaviors/sl_walking_penguin.inc.c | 4 +- src/game/behaviors/snufit.inc.c | 6 +- src/game/behaviors/triplet_butterfly.inc.c | 50 ++-- src/game/behaviors/water_bomb_cannon.inc.c | 24 +- src/game/behaviors/whirlpool.inc.c | 41 ++-- src/game/behaviors/whomp.inc.c | 2 - src/game/obj_behaviors.c | 13 +- src/game/object_helpers.c | 9 +- src/game/object_list_processor.h | 5 - src/pc/configfile.c | 2 + src/pc/configfile.h | 1 + src/pc/djui/djui_panel_display.c | 7 +- 28 files changed, 275 insertions(+), 443 deletions(-) diff --git a/src/engine/behavior_script.c b/src/engine/behavior_script.c index dd245d14a..155b0621b 100644 --- a/src/engine/behavior_script.c +++ b/src/engine/behavior_script.c @@ -1075,15 +1075,11 @@ cur_obj_update_begin:; } else if ((objFlags & OBJ_FLAG_COMPUTE_DIST_TO_MARIO) && gCurrentObject->collisionData == NULL) { if (!(objFlags & OBJ_FLAG_ACTIVE_FROM_AFAR)) { // If the object has a render distance, check if it should be shown. -#ifndef NODRAWINGDISTANCE - if (distanceFromMario > gCurrentObject->oDrawingDistance) { + if (distanceFromMario > gCurrentObject->oDrawingDistance * draw_distance_scalar()) { // Out of render distance, hide the object. gCurrentObject->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE; gCurrentObject->activeFlags |= ACTIVE_FLAG_FAR_AWAY; } else if (gCurrentObject->oHeldState == HELD_FREE) { -#else - if (distanceFromMario <= gCurrentObject->oDrawingDistance && gCurrentObject->oHeldState == HELD_FREE) { -#endif // In render distance (and not being held), show the object. gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE; gCurrentObject->activeFlags &= ~ACTIVE_FLAG_FAR_AWAY; @@ -1123,3 +1119,14 @@ f32 position_based_random_float_position(void) { u8 cur_obj_is_last_nat_update_per_frame(void) { return (gCurrentObject->areaTimer == (gNetworkAreaTimer - 1)); } + +f32 draw_distance_scalar(void) { + switch (configDrawDistance) { + case 0: return 0.5f; + case 1: return 1.0f; + case 2: return 1.5f; + case 3: return 3.0f; + case 4: return 10.0f; + default: return 999.0f; + } +} \ No newline at end of file diff --git a/src/engine/behavior_script.h b/src/engine/behavior_script.h index e7222aa20..6d2ff4912 100644 --- a/src/engine/behavior_script.h +++ b/src/engine/behavior_script.h @@ -26,10 +26,10 @@ s32 random_sign(void); void stub_behavior_script_2(void); void cur_obj_update(void); -void cur_obj_fake_update(void); u16 position_based_random_u16(void); f32 position_based_random_float_position(void); u8 cur_obj_is_last_nat_update_per_frame(void); +f32 draw_distance_scalar(void); #endif // BEHAVIOR_SCRIPT_H diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c index f7fc36432..d0f3254dc 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c @@ -795,18 +795,10 @@ void load_object_collision_model(void) { } } -#ifndef NODRAWINGDISTANCE - u8 anyPlayerInDrawRange = FALSE; - for (int i = 0; i < MAX_PLAYERS; i++) { - f32 dist = dist_between_objects(gCurrentObject, gMarioStates[i].marioObj); - if (dist < gCurrentObject->oDrawingDistance) { anyPlayerInDrawRange = TRUE; } - } - if (anyPlayerInDrawRange) { -#endif + f32 marioDist = dist_between_objects(gCurrentObject, gMarioStates[0].marioObj); + if (marioDist < gCurrentObject->oDrawingDistance * draw_distance_scalar()) { gCurrentObject->header.gfx.node.flags |= GRAPH_RENDER_ACTIVE; -#ifndef NODRAWINGDISTANCE } else { gCurrentObject->header.gfx.node.flags &= ~GRAPH_RENDER_ACTIVE; } -#endif } diff --git a/src/game/behaviors/bub.inc.c b/src/game/behaviors/bub.inc.c index 0e2c25164..aad0a34d4 100644 --- a/src/game/behaviors/bub.inc.c +++ b/src/game/behaviors/bub.inc.c @@ -8,25 +8,12 @@ void bub_spawner_act_0(void) { s32 i; s32 sp18 = o->oBirdChirpChirpUnkF4; -#ifndef NODRAWINGDISTANCE - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - if (distanceToPlayer < 1500.0f) { -#endif - for (i = 0; i < sp18; i++) - spawn_object(o, MODEL_BUB, bhvBub); - o->oAction = 1; -#ifndef NODRAWINGDISTANCE - } -#endif + for (i = 0; i < sp18; i++) + spawn_object(o, MODEL_BUB, bhvBub); + o->oAction = 1; } void bub_spawner_act_1(void) { -#ifndef NODRAWINGDISTANCE - struct Object* player = nearest_player_to_object(o); - if (player->oPosY - o->oPosY > 2000.0f) - o->oAction = 2; -#endif } void bub_spawner_act_2(void) { diff --git a/src/game/behaviors/chain_chomp.inc.c b/src/game/behaviors/chain_chomp.inc.c index 23b87641f..b6835f0da 100644 --- a/src/game/behaviors/chain_chomp.inc.c +++ b/src/game/behaviors/chain_chomp.inc.c @@ -53,41 +53,33 @@ static void chain_chomp_act_uninitialized(void) { struct ChainSegment *segments; s32 i; -#ifndef NODRAWINGDISTANCE - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - if (distanceToPlayer < 3000.0f) { -#endif - segments = mem_pool_alloc(gObjectMemoryPool, 5 * sizeof(struct ChainSegment)); - if (segments != NULL) { - // Each segment represents the offset of a chain part to the pivot. - // Segment 0 connects the pivot to the chain chomp itself. Segment - // 1 connects the pivot to the chain part next to the chain chomp - // (chain part 1), etc. - o->oChainChompSegments = segments; - for (i = 0; i <= 4; i++) { - chain_segment_init(&segments[i]); - } - - cur_obj_set_pos_to_home(); - - // Spawn the pivot and set to parent - if ((o->parentObj = - spawn_object(o, CHAIN_CHOMP_CHAIN_PART_BP_PIVOT, bhvChainChompChainPart)) - != NULL) { - // Spawn the non-pivot chain parts, starting from the chain - // chomp and moving toward the pivot - for (i = 1; i <= 4; i++) { - spawn_object_relative(i, 0, 0, 0, o, MODEL_METALLIC_BALL, bhvChainChompChainPart); - } - - o->oAction = CHAIN_CHOMP_ACT_MOVE; - cur_obj_unhide(); - } + segments = mem_pool_alloc(gObjectMemoryPool, 5 * sizeof(struct ChainSegment)); + if (segments != NULL) { + // Each segment represents the offset of a chain part to the pivot. + // Segment 0 connects the pivot to the chain chomp itself. Segment + // 1 connects the pivot to the chain part next to the chain chomp + // (chain part 1), etc. + o->oChainChompSegments = segments; + for (i = 0; i <= 4; i++) { + chain_segment_init(&segments[i]); + } + + cur_obj_set_pos_to_home(); + + // Spawn the pivot and set to parent + if ((o->parentObj = + spawn_object(o, CHAIN_CHOMP_CHAIN_PART_BP_PIVOT, bhvChainChompChainPart)) + != NULL) { + // Spawn the non-pivot chain parts, starting from the chain + // chomp and moving toward the pivot + for (i = 1; i <= 4; i++) { + spawn_object_relative(i, 0, 0, 0, o, MODEL_METALLIC_BALL, bhvChainChompChainPart); + } + + o->oAction = CHAIN_CHOMP_ACT_MOVE; + cur_obj_unhide(); } -#ifndef NODRAWINGDISTANCE } -#endif } /** @@ -358,100 +350,90 @@ static void chain_chomp_act_move(void) { f32 maxDistToPivot; // Unload chain if mario is far enough -#ifndef NODRAWINGDISTANCE - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - if (o->oChainChompReleaseStatus == CHAIN_CHOMP_NOT_RELEASED && distanceToPlayer > 4000.0f) { - o->oAction = CHAIN_CHOMP_ACT_UNLOAD_CHAIN; - o->oForwardVel = o->oVelY = 0.0f; - } else { -#endif - cur_obj_update_floor_and_walls(); + cur_obj_update_floor_and_walls(); - switch (o->oChainChompReleaseStatus) { - case CHAIN_CHOMP_NOT_RELEASED: - switch (o->oSubAction) { - case CHAIN_CHOMP_SUB_ACT_TURN: - chain_chomp_sub_act_turn(); - break; - case CHAIN_CHOMP_SUB_ACT_LUNGE: - chain_chomp_sub_act_lunge(); - break; - } - break; - case CHAIN_CHOMP_RELEASED_TRIGGER_CUTSCENE: - chain_chomp_released_trigger_cutscene(); - break; - case CHAIN_CHOMP_RELEASED_LUNGE_AROUND: - chain_chomp_released_lunge_around(); - break; - case CHAIN_CHOMP_RELEASED_BREAK_GATE: - chain_chomp_released_break_gate(); - break; - case CHAIN_CHOMP_RELEASED_JUMP_AWAY: - chain_chomp_released_jump_away(); - break; - case CHAIN_CHOMP_RELEASED_END_CUTSCENE: - chain_chomp_released_end_cutscene(); - break; - } - - cur_obj_move_standard(78); - - // Segment 0 connects the pivot to the chain chomp itself - o->oChainChompSegments[0].posX = o->oPosX - o->parentObj->oPosX; - o->oChainChompSegments[0].posY = o->oPosY - o->parentObj->oPosY; - o->oChainChompSegments[0].posZ = o->oPosZ - o->parentObj->oPosZ; - - o->oChainChompDistToPivot = - sqrtf(o->oChainChompSegments[0].posX * o->oChainChompSegments[0].posX - + o->oChainChompSegments[0].posY * o->oChainChompSegments[0].posY - + o->oChainChompSegments[0].posZ * o->oChainChompSegments[0].posZ); - - // If the chain is fully stretched - maxDistToPivot = o->oChainChompMaxDistFromPivotPerChainPart * 5; - if (o->oChainChompDistToPivot > maxDistToPivot) { - f32 ratio = maxDistToPivot / o->oChainChompDistToPivot; - o->oChainChompDistToPivot = maxDistToPivot; - - o->oChainChompSegments[0].posX *= ratio; - o->oChainChompSegments[0].posY *= ratio; - o->oChainChompSegments[0].posZ *= ratio; - - if (o->oChainChompReleaseStatus == CHAIN_CHOMP_NOT_RELEASED) { - // Restrict chain chomp position - o->oPosX = o->parentObj->oPosX + o->oChainChompSegments[0].posX; - o->oPosY = o->parentObj->oPosY + o->oChainChompSegments[0].posY; - o->oPosZ = o->parentObj->oPosZ + o->oChainChompSegments[0].posZ; - - o->oChainChompRestrictedByChain = TRUE; - } else { - // Move pivot like the chain chomp is pulling it along - f32 oldPivotY = o->parentObj->oPosY; - - o->parentObj->oPosX = o->oPosX - o->oChainChompSegments[0].posX; - o->parentObj->oPosY = o->oPosY - o->oChainChompSegments[0].posY; - o->parentObj->oVelY = o->parentObj->oPosY - oldPivotY; - o->parentObj->oPosZ = o->oPosZ - o->oChainChompSegments[0].posZ; + switch (o->oChainChompReleaseStatus) { + case CHAIN_CHOMP_NOT_RELEASED: + switch (o->oSubAction) { + case CHAIN_CHOMP_SUB_ACT_TURN: + chain_chomp_sub_act_turn(); + break; + case CHAIN_CHOMP_SUB_ACT_LUNGE: + chain_chomp_sub_act_lunge(); + break; } - } else { - o->oChainChompRestrictedByChain = FALSE; - } - - chain_chomp_update_chain_segments(); - - // Begin a lunge if mario tries to attack - if (obj_check_attacks(&sChainChompHitbox, o->oAction)) { - o->oSubAction = CHAIN_CHOMP_SUB_ACT_LUNGE; - o->oChainChompMaxDistFromPivotPerChainPart = 900.0f / 5; - o->oForwardVel = 0.0f; - o->oVelY = 300.0f; - o->oGravity = -4.0f; - o->oChainChompTargetPitch = -0x3000; - } -#ifndef NODRAWINGDISTANCE + break; + case CHAIN_CHOMP_RELEASED_TRIGGER_CUTSCENE: + chain_chomp_released_trigger_cutscene(); + break; + case CHAIN_CHOMP_RELEASED_LUNGE_AROUND: + chain_chomp_released_lunge_around(); + break; + case CHAIN_CHOMP_RELEASED_BREAK_GATE: + chain_chomp_released_break_gate(); + break; + case CHAIN_CHOMP_RELEASED_JUMP_AWAY: + chain_chomp_released_jump_away(); + break; + case CHAIN_CHOMP_RELEASED_END_CUTSCENE: + chain_chomp_released_end_cutscene(); + break; } -#endif + + cur_obj_move_standard(78); + + // Segment 0 connects the pivot to the chain chomp itself + o->oChainChompSegments[0].posX = o->oPosX - o->parentObj->oPosX; + o->oChainChompSegments[0].posY = o->oPosY - o->parentObj->oPosY; + o->oChainChompSegments[0].posZ = o->oPosZ - o->parentObj->oPosZ; + + o->oChainChompDistToPivot = + sqrtf(o->oChainChompSegments[0].posX * o->oChainChompSegments[0].posX + + o->oChainChompSegments[0].posY * o->oChainChompSegments[0].posY + + o->oChainChompSegments[0].posZ * o->oChainChompSegments[0].posZ); + + // If the chain is fully stretched + maxDistToPivot = o->oChainChompMaxDistFromPivotPerChainPart * 5; + if (o->oChainChompDistToPivot > maxDistToPivot) { + f32 ratio = maxDistToPivot / o->oChainChompDistToPivot; + o->oChainChompDistToPivot = maxDistToPivot; + + o->oChainChompSegments[0].posX *= ratio; + o->oChainChompSegments[0].posY *= ratio; + o->oChainChompSegments[0].posZ *= ratio; + + if (o->oChainChompReleaseStatus == CHAIN_CHOMP_NOT_RELEASED) { + // Restrict chain chomp position + o->oPosX = o->parentObj->oPosX + o->oChainChompSegments[0].posX; + o->oPosY = o->parentObj->oPosY + o->oChainChompSegments[0].posY; + o->oPosZ = o->parentObj->oPosZ + o->oChainChompSegments[0].posZ; + + o->oChainChompRestrictedByChain = TRUE; + } else { + // Move pivot like the chain chomp is pulling it along + f32 oldPivotY = o->parentObj->oPosY; + + o->parentObj->oPosX = o->oPosX - o->oChainChompSegments[0].posX; + o->parentObj->oPosY = o->oPosY - o->oChainChompSegments[0].posY; + o->parentObj->oVelY = o->parentObj->oPosY - oldPivotY; + o->parentObj->oPosZ = o->oPosZ - o->oChainChompSegments[0].posZ; + } + } else { + o->oChainChompRestrictedByChain = FALSE; + } + + chain_chomp_update_chain_segments(); + + // Begin a lunge if mario tries to attack + if (obj_check_attacks(&sChainChompHitbox, o->oAction)) { + o->oSubAction = CHAIN_CHOMP_SUB_ACT_LUNGE; + o->oChainChompMaxDistFromPivotPerChainPart = 900.0f / 5; + o->oForwardVel = 0.0f; + o->oVelY = 300.0f; + o->oGravity = -4.0f; + o->oChainChompTargetPitch = -0x3000; + } + if (o->oChainChompReleaseStatus != CHAIN_CHOMP_NOT_RELEASED) { cur_obj_become_intangible(); } diff --git a/src/game/behaviors/cloud.inc.c b/src/game/behaviors/cloud.inc.c index a019efe1b..4a5044bbf 100644 --- a/src/game/behaviors/cloud.inc.c +++ b/src/game/behaviors/cloud.inc.c @@ -47,16 +47,8 @@ static void cloud_act_spawn_parts(void) { * Wait for mario to approach, then unhide and enter the spawn parts action. */ static void cloud_act_fwoosh_hidden(void) { -#ifndef NODRAWINGDISTANCE - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - if (distanceToPlayer < 2000.0f) { -#endif - cur_obj_unhide(); - o->oAction = CLOUD_ACT_SPAWN_PARTS; -#ifndef NODRAWINGDISTANCE - } -#endif + cur_obj_unhide(); + o->oAction = CLOUD_ACT_SPAWN_PARTS; } /** @@ -77,48 +69,40 @@ static void cloud_fwoosh_update(void) { struct Object* player = nearest_player_to_object(o); int distanceToPlayer = dist_between_objects(o, player); -#ifndef NODRAWINGDISTANCE - if (distanceToPlayer > 2500.0f) { - o->oAction = CLOUD_ACT_UNLOAD; - } else { -#endif - if (o->oCloudBlowing) { - o->header.gfx.scale[0] += o->oCloudGrowSpeed; + if (o->oCloudBlowing) { + o->header.gfx.scale[0] += o->oCloudGrowSpeed; - if ((o->oCloudGrowSpeed -= 0.005f) < -0.16f) { - // Stop blowing once we are shrinking faster than -0.16 - o->oCloudBlowing = o->oTimer = 0; - } else if (o->oCloudGrowSpeed < -0.1f) { - // Start blowing once we start shrinking faster than -0.1 - cur_obj_play_sound_1(SOUND_AIR_BLOW_WIND); - cur_obj_spawn_strong_wind_particles(12, 3.0f, 0.0f, -50.0f, 120.0f); - } else { - cur_obj_play_sound_1(SOUND_ENV_WIND1); + if ((o->oCloudGrowSpeed -= 0.005f) < -0.16f) { + // Stop blowing once we are shrinking faster than -0.16 + o->oCloudBlowing = o->oTimer = 0; + } else if (o->oCloudGrowSpeed < -0.1f) { + // Start blowing once we start shrinking faster than -0.1 + cur_obj_play_sound_1(SOUND_AIR_BLOW_WIND); + cur_obj_spawn_strong_wind_particles(12, 3.0f, 0.0f, -50.0f, 120.0f); + } else { + cur_obj_play_sound_1(SOUND_ENV_WIND1); + } + } else { + // Return to normal size + approach_f32_ptr(&o->header.gfx.scale[0], 3.0f, 0.012f); + o->oCloudFwooshMovementRadius += 0xC8; + + // If mario stays nearby for 100 frames, begin blowing + if (distanceToPlayer < 1000.0f) { + if (o->oTimer > 100) { + o->oCloudBlowing = TRUE; + o->oCloudGrowSpeed = 0.14f; } } else { - // Return to normal size - approach_f32_ptr(&o->header.gfx.scale[0], 3.0f, 0.012f); - o->oCloudFwooshMovementRadius += 0xC8; - - // If mario stays nearby for 100 frames, begin blowing - if (distanceToPlayer < 1000.0f) { - if (o->oTimer > 100) { - o->oCloudBlowing = TRUE; - o->oCloudGrowSpeed = 0.14f; - } - } else { - o->oTimer = 0; - } - - o->oCloudCenterX = o->oHomeX + 100.0f * coss(o->oCloudFwooshMovementRadius); - o->oPosZ = o->oHomeZ + 100.0f * sins(o->oCloudFwooshMovementRadius); - o->oCloudCenterY = o->oHomeY; + o->oTimer = 0; } - cur_obj_scale(o->header.gfx.scale[0]); -#ifndef NODRAWINGDISTANCE + o->oCloudCenterX = o->oHomeX + 100.0f * coss(o->oCloudFwooshMovementRadius); + o->oPosZ = o->oHomeZ + 100.0f * sins(o->oCloudFwooshMovementRadius); + o->oCloudCenterY = o->oHomeY; } -#endif + + cur_obj_scale(o->header.gfx.scale[0]); } /** diff --git a/src/game/behaviors/coin.inc.c b/src/game/behaviors/coin.inc.c index 31081c38c..e5d4c3e45 100644 --- a/src/game/behaviors/coin.inc.c +++ b/src/game/behaviors/coin.inc.c @@ -186,23 +186,13 @@ void bhv_coin_formation_loop(void) { s32 bitIndex; switch (o->oAction) { case 0: -#ifndef NODRAWINGDISTANCE - if (o->oDistanceToMario < 2000.0f) { -#endif - for (bitIndex = 0; bitIndex < 8; bitIndex++) { - if (!(o->oCoinUnkF4 & (1 << bitIndex))) - spawn_coin_in_formation(bitIndex, o->oBehParams2ndByte); - } - o->oAction++; -#ifndef NODRAWINGDISTANCE + for (bitIndex = 0; bitIndex < 8; bitIndex++) { + if (!(o->oCoinUnkF4 & (1 << bitIndex))) + spawn_coin_in_formation(bitIndex, o->oBehParams2ndByte); } -#endif + o->oAction++; break; case 1: -#ifndef NODRAWINGDISTANCE - if (o->oDistanceToMario > 2100.0f) - o->oAction++; -#endif break; case 2: o->oAction = 0; diff --git a/src/game/behaviors/enemy_lakitu.inc.c b/src/game/behaviors/enemy_lakitu.inc.c index f9a5d2fe3..96525276e 100644 --- a/src/game/behaviors/enemy_lakitu.inc.c +++ b/src/game/behaviors/enemy_lakitu.inc.c @@ -24,18 +24,10 @@ static struct ObjectHitbox sEnemyLakituHitbox = { * Wait for mario to approach, then spawn the cloud and become visible. */ static void enemy_lakitu_act_uninitialized(void) { -#ifndef NODRAWINGDISTANCE - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - if (distanceToPlayer < 2000.0f) { -#endif - spawn_object_relative_with_scale(CLOUD_BP_LAKITU_CLOUD, 0, 0, 0, 2.0f, o, MODEL_MIST, bhvCloud); + spawn_object_relative_with_scale(CLOUD_BP_LAKITU_CLOUD, 0, 0, 0, 2.0f, o, MODEL_MIST, bhvCloud); - cur_obj_unhide(); - o->oAction = ENEMY_LAKITU_ACT_MAIN; -#ifndef NODRAWINGDISTANCE - } -#endif + cur_obj_unhide(); + o->oAction = ENEMY_LAKITU_ACT_MAIN; } /** diff --git a/src/game/behaviors/fish.inc.c b/src/game/behaviors/fish.inc.c index e69b14af2..7b0720243 100644 --- a/src/game/behaviors/fish.inc.c +++ b/src/game/behaviors/fish.inc.c @@ -12,29 +12,28 @@ void fish_act_spawn(void) { s32 i; s32 schoolQuantity; s16 model; - f32 minDistToMario; const struct Animation * const*fishAnimation; struct Object *fishObject; switch (o->oBehParams2ndByte) { // Blue fish with a quanitiy of twenty. case 0: - model = MODEL_FISH; schoolQuantity = 20; minDistToMario = 1500.0f; fishAnimation = blue_fish_seg3_anims_0301C2B0; + model = MODEL_FISH; schoolQuantity = 20; fishAnimation = blue_fish_seg3_anims_0301C2B0; break; // Blue fish with a quanitiy of five. case 1: - model = MODEL_FISH; schoolQuantity = 5; minDistToMario = 1500.0f; fishAnimation = blue_fish_seg3_anims_0301C2B0; + model = MODEL_FISH; schoolQuantity = 5; fishAnimation = blue_fish_seg3_anims_0301C2B0; break; // Cyan fish with a quanitiy of twenty. case 2: - model = MODEL_CYAN_FISH; schoolQuantity = 20; minDistToMario = 1500.0f; fishAnimation = cyan_fish_seg6_anims_0600E264; + model = MODEL_CYAN_FISH; schoolQuantity = 20; fishAnimation = cyan_fish_seg6_anims_0600E264; break; // Cyan fish with a quanitiy of five. case 3: - model = MODEL_CYAN_FISH; schoolQuantity = 5; minDistToMario = 1500.0f; fishAnimation = cyan_fish_seg6_anims_0600E264; + model = MODEL_CYAN_FISH; schoolQuantity = 5; fishAnimation = cyan_fish_seg6_anims_0600E264; break; } /** @@ -42,24 +41,13 @@ void fish_act_spawn(void) { * If the current level is Secret Aquarium, ignore this requirement. * Fish moves at random with a max-range of 700.0f. */ -#ifndef NODRAWINGDISTANCE - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - if (distanceToPlayer < minDistToMario || gCurrLevelNum == LEVEL_SA) { -#else - // get rid of warning - minDistToMario = minDistToMario; -#endif - for (i = 0; i < schoolQuantity; i++) { - fishObject = spawn_object(o, model, bhvFish); - fishObject->oBehParams2ndByte = o->oBehParams2ndByte; - obj_init_animation_with_sound(fishObject, fishAnimation, 0); - obj_translate_xyz_random(fishObject, 700.0f); - } - o->oAction = FISH_ACT_ACTIVE; -#ifndef NODRAWINGDISTANCE + for (i = 0; i < schoolQuantity; i++) { + fishObject = spawn_object(o, model, bhvFish); + fishObject->oBehParams2ndByte = o->oBehParams2ndByte; + obj_init_animation_with_sound(fishObject, fishAnimation, 0); + obj_translate_xyz_random(fishObject, 700.0f); } -#endif + o->oAction = FISH_ACT_ACTIVE; } /** @@ -67,14 +55,15 @@ void fish_act_spawn(void) { * Y coordinate is greater than 2000.0f then spawn another fish. */ void fish_act_respawn(void) { -#ifndef NODRAWINGDISTANCE + // TODO: should this be re-enabled? +/*#ifndef NODRAWINGDISTANCE if (gCurrLevelNum != LEVEL_SA) { struct Object* player = nearest_player_to_object(o); if (player->oPosY - o->oPosY > 2000.0f) { o->oAction = FISH_ACT_RESPAWN; } } -#endif +#endif*/ } /** diff --git a/src/game/behaviors/goomba.inc.c b/src/game/behaviors/goomba.inc.c index 09f285041..ae552ffa3 100644 --- a/src/game/behaviors/goomba.inc.c +++ b/src/game/behaviors/goomba.inc.c @@ -78,35 +78,25 @@ void bhv_goomba_triplet_spawner_update(void) { // If mario is close enough and the goombas aren't currently loaded, then // spawn them if (o->oAction == GOOMBA_TRIPLET_SPAWNER_ACT_UNLOADED) { -#ifndef NODRAWINGDISTANCE - if (dist_between_objects(o, player) < 3000.0f) { -#endif - // The spawner is capable of spawning more than 3 goombas, but this - // is not used in the game - dAngle = - 0x10000 - / (((o->oBehParams2ndByte & GOOMBA_TRIPLET_SPAWNER_BP_EXTRA_GOOMBAS_MASK) >> 2) + 3); + // The spawner is capable of spawning more than 3 goombas, but this + // is not used in the game + dAngle = + 0x10000 + / (((o->oBehParams2ndByte & GOOMBA_TRIPLET_SPAWNER_BP_EXTRA_GOOMBAS_MASK) >> 2) + 3); - for (angle = 0, goombaFlag = 1 << 8; angle < 0xFFFF; angle += dAngle, goombaFlag <<= 1) { - // Only spawn goombas which haven't been killed yet - if (!(o->oBehParams & goombaFlag)) { - dx = 500.0f * coss(angle); - dz = 500.0f * sins(angle); + for (angle = 0, goombaFlag = 1 << 8; angle < 0xFFFF; angle += dAngle, goombaFlag <<= 1) { + // Only spawn goombas which haven't been killed yet + if (!(o->oBehParams & goombaFlag)) { + dx = 500.0f * coss(angle); + dz = 500.0f * sins(angle); - spawn_object_relative((o->oBehParams2ndByte & GOOMBA_TRIPLET_SPAWNER_BP_SIZE_MASK) - | (goombaFlag >> 6), - dx, 0, dz, o, MODEL_GOOMBA, bhvGoomba); - } + spawn_object_relative((o->oBehParams2ndByte & GOOMBA_TRIPLET_SPAWNER_BP_SIZE_MASK) + | (goombaFlag >> 6), + dx, 0, dz, o, MODEL_GOOMBA, bhvGoomba); } - - o->oAction += 1; -#ifndef NODRAWINGDISTANCE } - } else if (dist_between_objects(o, player) > 4000.0f) { - // If mario is too far away, enter the unloaded action. The goombas - // will detect this and unload themselves - o->oAction = GOOMBA_TRIPLET_SPAWNER_ACT_UNLOADED; -#endif + + o->oAction += 1; } } diff --git a/src/game/behaviors/heave_ho.inc.c b/src/game/behaviors/heave_ho.inc.c index bb35cd67f..d1784f6f3 100644 --- a/src/game/behaviors/heave_ho.inc.c +++ b/src/game/behaviors/heave_ho.inc.c @@ -77,13 +77,7 @@ void heave_ho_act_3(void) { } void heave_ho_act_0(void) { -#ifndef NODRAWINGDISTANCE - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - if (find_water_level(o->oPosX, o->oPosZ) < o->oPosY && distanceToPlayer < 4000.0f) { -#else if (find_water_level(o->oPosX, o->oPosZ) < (o->oPosY - 50.0f)) { -#endif cur_obj_set_pos_to_home(); cur_obj_become_tangible(); cur_obj_unhide(); diff --git a/src/game/behaviors/king_bobomb.inc.c b/src/game/behaviors/king_bobomb.inc.c index dbaafbb3f..380016d15 100644 --- a/src/game/behaviors/king_bobomb.inc.c +++ b/src/game/behaviors/king_bobomb.inc.c @@ -350,16 +350,11 @@ void king_bobomb_move(void) { cur_obj_move_using_fvel_and_gravity(); cur_obj_call_action_function(sKingBobombActions); exec_anim_sound_state(sKingBobombSoundStates); -#ifndef NODRAWINGDISTANCE - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - if (distanceToPlayer < 5000.0f) -#endif + int distanceToPlayer = dist_between_objects(o, gMarioStates[0].marioObj); + if (distanceToPlayer < 5000.0f * draw_distance_scalar()) cur_obj_enable_rendering(); -#ifndef NODRAWINGDISTANCE else cur_obj_disable_rendering(); -#endif } u8 king_bobomb_ignore_if_true(void) { diff --git a/src/game/behaviors/lll_floating_wood_piece.inc.c b/src/game/behaviors/lll_floating_wood_piece.inc.c index 4be9fc0ee..a1534a2f7 100644 --- a/src/game/behaviors/lll_floating_wood_piece.inc.c +++ b/src/game/behaviors/lll_floating_wood_piece.inc.c @@ -19,24 +19,14 @@ void bhv_lll_floating_wood_bridge_loop(void) { s32 i; switch (o->oAction) { case 0: -#ifndef NODRAWINGDISTANCE - if (o->oDistanceToMario < 2500.0f) { -#endif - for (i = 1; i < 4; i++) { - sp3C = spawn_object_relative(0, (i - 2) * 300, 0, 0, o, MODEL_LLL_WOOD_BRIDGE, - bhvLllWoodPiece); - sp3C->oLllWoodPieceOscillationTimer = i * 4096; - } - o->oAction = 1; -#ifndef NODRAWINGDISTANCE + for (i = 1; i < 4; i++) { + sp3C = spawn_object_relative(0, (i - 2) * 300, 0, 0, o, MODEL_LLL_WOOD_BRIDGE, + bhvLllWoodPiece); + sp3C->oLllWoodPieceOscillationTimer = i * 4096; } -#endif + o->oAction = 1; break; case 1: -#ifndef NODRAWINGDISTANCE - if (o->oDistanceToMario > 2600.0f) - o->oAction = 2; -#endif break; case 2: o->oAction = 0; diff --git a/src/game/behaviors/lll_rotating_hex_flame.inc.c b/src/game/behaviors/lll_rotating_hex_flame.inc.c index 710794d6f..83308e37c 100644 --- a/src/game/behaviors/lll_rotating_hex_flame.inc.c +++ b/src/game/behaviors/lll_rotating_hex_flame.inc.c @@ -30,10 +30,7 @@ void fire_bar_spawn_flames(s16 a0) { } void fire_bar_act_0(void) { -#ifndef NODRAWINGDISTANCE - if (o->oDistanceToMario < 3000.0f) -#endif - o->oAction = 1; + o->oAction = 1; } void fire_bar_act_1(void) { @@ -47,10 +44,6 @@ void fire_bar_act_1(void) { void fire_bar_act_2(void) { o->oAngleVelYaw = -0x100; o->oMoveAngleYaw += o->oAngleVelYaw; -#ifndef NODRAWINGDISTANCE - if (o->oDistanceToMario > 3200.0f) - o->oAction = 3; -#endif } void fire_bar_act_3(void) { diff --git a/src/game/behaviors/piranha_plant.inc.c b/src/game/behaviors/piranha_plant.inc.c index 731d8d71d..4615a64c5 100644 --- a/src/game/behaviors/piranha_plant.inc.c +++ b/src/game/behaviors/piranha_plant.inc.c @@ -369,15 +369,14 @@ void bhv_piranha_plant_loop(void) { cur_obj_set_hurtbox_radius_and_height(150.0f, 100.0f); cur_obj_call_action_function(TablePiranhaPlantActions); - #ifndef NODRAWINGDISTANCE // In WF, hide all Piranha Plants once high enough up. if (gCurrLevelNum == LEVEL_WF) { - struct Object* player = nearest_player_to_object(o); - if (player->oPosY > 3400.0f) + struct Object* player = gMarioStates[0].marioObj; + f32 scalar = max(draw_distance_scalar(), 1.0f); + if (player->oPosY > 3400.0f * scalar) cur_obj_hide(); else cur_obj_unhide(); } - #endif o->oInteractStatus = 0; } diff --git a/src/game/behaviors/pokey.inc.c b/src/game/behaviors/pokey.inc.c index 68cb0e6cd..2952f47bb 100644 --- a/src/game/behaviors/pokey.inc.c +++ b/src/game/behaviors/pokey.inc.c @@ -171,30 +171,25 @@ static void pokey_act_uninitialized(void) { s32 i; s16 partModel; -#ifndef NODRAWINGDISTANCE - if (o->oDistanceToMario < 2000.0f) { -#endif - partModel = MODEL_POKEY_HEAD; + partModel = MODEL_POKEY_HEAD; - for (i = 0; i < 5; i++) { - // Spawn body parts at y offsets 480, 360, 240, 120, 0 - // behavior param 0 = head, 4 = lowest body part - bodyPart = spawn_object_relative(i, 0, -i * 120 + 480, 0, o, partModel, bhvPokeyBodyPart); + for (i = 0; i < 5; i++) { + // Spawn body parts at y offsets 480, 360, 240, 120, 0 + // behavior param 0 = head, 4 = lowest body part + bodyPart = spawn_object_relative(i, 0, -i * 120 + 480, 0, o, partModel, bhvPokeyBodyPart); - if (bodyPart != NULL) { - obj_scale(bodyPart, 3.0f); - } - - partModel = MODEL_POKEY_BODY_PART; + if (bodyPart != NULL) { + obj_scale(bodyPart, 3.0f); } - o->oPokeyAliveBodyPartFlags = 0x1F; - o->oPokeyNumAliveBodyParts = 5; - o->oPokeyBottomBodyPartSize = 1.0f; - o->oAction = POKEY_ACT_WANDER; -#ifndef NODRAWINGDISTANCE + partModel = MODEL_POKEY_BODY_PART; } -#endif + + o->oPokeyAliveBodyPartFlags = 0x1F; + o->oPokeyNumAliveBodyParts = 5; + o->oPokeyBottomBodyPartSize = 1.0f; + o->oAction = POKEY_ACT_WANDER; + if (!network_sync_object_initialized(o)) { struct SyncObject* so = network_init_object(o, 4000.0f); network_init_object_field(o, &o->oPokeyAliveBodyPartFlags); @@ -224,11 +219,6 @@ static void pokey_act_wander(void) { if (o->oPokeyNumAliveBodyParts == 0) { obj_mark_for_deletion(o); -#ifndef NODRAWINGDISTANCE - } else if (o->oDistanceToMario > 2500.0f) { - o->oAction = POKEY_ACT_UNLOAD_PARTS; - o->oForwardVel = 0.0f; -#endif } else { treat_far_home_as_mario(1000.0f); cur_obj_update_floor_and_walls(); diff --git a/src/game/behaviors/sl_walking_penguin.inc.c b/src/game/behaviors/sl_walking_penguin.inc.c index dad6cadda..c08bd6f59 100644 --- a/src/game/behaviors/sl_walking_penguin.inc.c +++ b/src/game/behaviors/sl_walking_penguin.inc.c @@ -108,9 +108,7 @@ void bhv_sl_walking_penguin_loop(void) { } cur_obj_move_standard(-78); -#ifndef NODRAWINGDISTANCE - if (!cur_obj_hide_if_mario_far_away_y(1000.0f)) -#endif + if (!cur_obj_hide_if_mario_far_away_y(1000.0f)) play_penguin_walking_sound(PENGUIN_WALK_BIG); // Adjust the position to get a point better lined up with the visual model, for stopping the wind. diff --git a/src/game/behaviors/snufit.inc.c b/src/game/behaviors/snufit.inc.c index 7ffec02b0..f4f3b592c 100644 --- a/src/game/behaviors/snufit.inc.c +++ b/src/game/behaviors/snufit.inc.c @@ -210,11 +210,7 @@ void bhv_snufit_loop(void) { */ void bhv_snufit_balls_loop(void) { // If far from Mario or in a different room, despawn. - if ((o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM) -#ifndef NODRAWINGDISTANCE - || (o->oTimer != 0 && o->oDistanceToMario > 1500.0f) -#endif - ){ + if (o->activeFlags & ACTIVE_FLAG_IN_DIFFERENT_ROOM) { obj_mark_for_deletion(o); } diff --git a/src/game/behaviors/triplet_butterfly.inc.c b/src/game/behaviors/triplet_butterfly.inc.c index 4a211ca2d..5007cc8bb 100644 --- a/src/game/behaviors/triplet_butterfly.inc.c +++ b/src/game/behaviors/triplet_butterfly.inc.c @@ -54,39 +54,31 @@ static void triplet_butterfly_act_init(void) { } static void triplet_butterfly_act_wander(void) { -#ifndef NODRAWINGDISTANCE - if (o->oDistanceToMario > 1500.0f) { - obj_mark_for_deletion(o); + approach_f32_ptr(&o->oTripletButterflySpeed, 8.0f, 0.5f); + if (o->oTimer < 60) { + o->oTripletButterflyTargetYaw = cur_obj_angle_to_home(); } else { -#endif - approach_f32_ptr(&o->oTripletButterflySpeed, 8.0f, 0.5f); - if (o->oTimer < 60) { - o->oTripletButterflyTargetYaw = cur_obj_angle_to_home(); - } else { - o->oTripletButterflyTargetYaw = (s32) o->oTripletButterflyBaseYaw; + o->oTripletButterflyTargetYaw = (s32) o->oTripletButterflyBaseYaw; - if (o->oTimer > 110 && o->oDistanceToMario < 200.0f - && o->oTripletButterflyType > TRIPLET_BUTTERFLY_TYPE_NORMAL) { - o->oAction = TRIPLET_BUTTERFLY_ACT_ACTIVATE; - o->oTripletButterflySpeed = 0.0f; - } + if (o->oTimer > 110 && o->oDistanceToMario < 200.0f + && o->oTripletButterflyType > TRIPLET_BUTTERFLY_TYPE_NORMAL) { + o->oAction = TRIPLET_BUTTERFLY_ACT_ACTIVATE; + o->oTripletButterflySpeed = 0.0f; } - - if (o->oHomeY < o->oFloorHeight) { - o->oHomeY = o->oFloorHeight; - } - - if (o->oPosY < o->oHomeY + random_linear_offset(50, 50)) { - o->oTripletButterflyTargetPitch = -0x2000; - } else { - o->oTripletButterflyTargetPitch = 0x2000; - } - - obj_move_pitch_approach(o->oTripletButterflyTargetPitch, 400); - cur_obj_rotate_yaw_toward(o->oTripletButterflyTargetYaw, random_linear_offset(400, 800)); -#ifndef NODRAWINGDISTANCE } -#endif + + if (o->oHomeY < o->oFloorHeight) { + o->oHomeY = o->oFloorHeight; + } + + if (o->oPosY < o->oHomeY + random_linear_offset(50, 50)) { + o->oTripletButterflyTargetPitch = -0x2000; + } else { + o->oTripletButterflyTargetPitch = 0x2000; + } + + obj_move_pitch_approach(o->oTripletButterflyTargetPitch, 400); + cur_obj_rotate_yaw_toward(o->oTripletButterflyTargetYaw, random_linear_offset(400, 800)); } static void triplet_butterfly_act_activate(void) { diff --git a/src/game/behaviors/water_bomb_cannon.inc.c b/src/game/behaviors/water_bomb_cannon.inc.c index 8cd3c9413..a53a9b9c0 100644 --- a/src/game/behaviors/water_bomb_cannon.inc.c +++ b/src/game/behaviors/water_bomb_cannon.inc.c @@ -38,31 +38,15 @@ void bhv_bubble_cannon_barrel_loop(void) { } void water_bomb_cannon_act_0(void) { -#ifndef NODRAWINGDISTANCE - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - if (distanceToPlayer < 2000.0f) { -#endif - spawn_object(o, MODEL_CANNON_BARREL, bhvCannonBarrelBubbles); - cur_obj_unhide(); + spawn_object(o, MODEL_CANNON_BARREL, bhvCannonBarrelBubbles); + cur_obj_unhide(); - o->oAction = 1; - o->oMoveAnglePitch = o->oWaterCannonUnkFC = 0x1C00; -#ifndef NODRAWINGDISTANCE - } -#endif + o->oAction = 1; + o->oMoveAnglePitch = o->oWaterCannonUnkFC = 0x1C00; } void water_bomb_cannon_act_1(void) { -#ifndef NODRAWINGDISTANCE - struct Object* player = nearest_player_to_object(o); - int distanceToPlayer = dist_between_objects(o, player); - if (distanceToPlayer > 2500.0f) { - o->oAction = 2; - } else if (o->oBehParams2ndByte == 0) { -#else if (o->oBehParams2ndByte == 0) { -#endif if (o->oWaterCannonUnkF4 != 0) { o->oWaterCannonUnkF4 -= 1; } else { diff --git a/src/game/behaviors/whirlpool.inc.c b/src/game/behaviors/whirlpool.inc.c index 64867e867..161918dfa 100644 --- a/src/game/behaviors/whirlpool.inc.c +++ b/src/game/behaviors/whirlpool.inc.c @@ -44,31 +44,27 @@ void bhv_whirlpool_loop(void) { o->oWhirlpoolTimeout = 30; } -#ifndef NODRAWINGDISTANCE - if (o->oDistanceToMario < 5000.0f) { -#endif + f32 marioDist = dist_between_objects(o, gMarioStates[0].marioObj); + if (marioDist < 5000.0f * draw_distance_scalar()) { o->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE; - - // not sure if actually an array - gEnvFxBubbleConfig[ENVFX_STATE_PARTICLECOUNT] = 60; - gEnvFxBubbleConfig[ENVFX_STATE_SRC_X] = o->oPosX; - gEnvFxBubbleConfig[ENVFX_STATE_SRC_Z] = o->oPosZ; - gEnvFxBubbleConfig[ENVFX_STATE_DEST_X] = o->oPosX; - gEnvFxBubbleConfig[ENVFX_STATE_DEST_Y] = o->oPosY; - gEnvFxBubbleConfig[ENVFX_STATE_DEST_Z] = o->oPosZ; - gEnvFxBubbleConfig[ENVFX_STATE_SRC_Y] = o->oPosY + 800.0f; - gEnvFxBubbleConfig[ENVFX_STATE_PITCH] = o->oWhirlpoolInitFacePitch; - gEnvFxBubbleConfig[ENVFX_STATE_YAW] = o->oWhirlpoolInitFaceRoll; - - whirpool_orient_graph(); - - o->oFaceAngleYaw += 0x1F40; -#ifndef NODRAWINGDISTANCE } else { o->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE; - gEnvFxBubbleConfig[ENVFX_STATE_PARTICLECOUNT] = 0; } -#endif + + // not sure if actually an array + gEnvFxBubbleConfig[ENVFX_STATE_PARTICLECOUNT] = 60; + gEnvFxBubbleConfig[ENVFX_STATE_SRC_X] = o->oPosX; + gEnvFxBubbleConfig[ENVFX_STATE_SRC_Z] = o->oPosZ; + gEnvFxBubbleConfig[ENVFX_STATE_DEST_X] = o->oPosX; + gEnvFxBubbleConfig[ENVFX_STATE_DEST_Y] = o->oPosY; + gEnvFxBubbleConfig[ENVFX_STATE_DEST_Z] = o->oPosZ; + gEnvFxBubbleConfig[ENVFX_STATE_SRC_Y] = o->oPosY + 800.0f; + gEnvFxBubbleConfig[ENVFX_STATE_PITCH] = o->oWhirlpoolInitFacePitch; + gEnvFxBubbleConfig[ENVFX_STATE_YAW] = o->oWhirlpoolInitFaceRoll; + + whirpool_orient_graph(); + + o->oFaceAngleYaw += 0x1F40; cur_obj_play_sound_1(SOUND_ENV_WATER); @@ -76,7 +72,8 @@ void bhv_whirlpool_loop(void) { } void bhv_jet_stream_loop(void) { - if (o->oDistanceToMario < 5000.0f) { + f32 marioDist = dist_between_objects(o, gMarioStates[0].marioObj); + if (marioDist < 5000.0f) { gEnvFxBubbleConfig[ENVFX_STATE_PARTICLECOUNT] = 60; gEnvFxBubbleConfig[ENVFX_STATE_SRC_X] = o->oPosX; gEnvFxBubbleConfig[ENVFX_STATE_SRC_Y] = o->oPosY; diff --git a/src/game/behaviors/whomp.inc.c b/src/game/behaviors/whomp.inc.c index 6ae731775..407924aee 100644 --- a/src/game/behaviors/whomp.inc.c +++ b/src/game/behaviors/whomp.inc.c @@ -280,14 +280,12 @@ void bhv_whomp_loop(void) { cur_obj_call_action_function(sWhompActions); cur_obj_move_standard(-20); if (o->oAction != 9) { -#ifndef NODRAWINGDISTANCE // o->oBehParams2ndByte here seems to be a flag // indicating whether this is a normal or king whomp if (o->oBehParams2ndByte != 0) cur_obj_hide_if_mario_far_away_y(2000.0f); else cur_obj_hide_if_mario_far_away_y(1000.0f); -#endif load_object_collision_model(); } } diff --git a/src/game/obj_behaviors.c b/src/game/obj_behaviors.c index 966c60a58..72562289f 100644 --- a/src/game/obj_behaviors.c +++ b/src/game/obj_behaviors.c @@ -585,20 +585,13 @@ s32 is_point_close_to_object(struct Object *obj, f32 x, f32 y, f32 z, s32 dist) /** * Sets an object as visible if within a certain distance of Mario's graphical position. */ -void set_object_visibility(struct Object *obj, UNUSED s32 dist) { -#ifndef NODRAWINGDISTANCE - f32 objX = obj->oPosX; - f32 objY = obj->oPosY; - f32 objZ = obj->oPosZ; - - if (is_point_within_radius_of_mario(objX, objY, objZ, dist) == TRUE) { -#endif +void set_object_visibility(struct Object *obj, s32 dist) { + int distanceToPlayer = dist_between_objects(obj, gMarioStates[0].marioObj); + if (distanceToPlayer < dist * draw_distance_scalar()) { obj->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE; -#ifndef NODRAWINGDISTANCE } else { obj->header.gfx.node.flags |= GRAPH_RENDER_INVISIBLE; } -#endif } /** diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index 73290b46c..b98708770 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -2638,12 +2638,9 @@ void cur_obj_if_hit_wall_bounce_away(void) { } s32 cur_obj_hide_if_mario_far_away_y(f32 distY) { - for (int i = 0; i < MAX_PLAYERS; i++) { - if (!is_player_active(&gMarioStates[i])) { continue; } - if (absf(o->oPosY - gMarioStates[i].marioObj->oPosY) < distY) { - cur_obj_unhide(); - return FALSE; - } + if (absf(o->oPosY - gMarioStates[0].marioObj->oPosY) < distY * draw_distance_scalar()) { + cur_obj_unhide(); + return FALSE; } cur_obj_hide(); return TRUE; diff --git a/src/game/object_list_processor.h b/src/game/object_list_processor.h index d222928e0..ba0339427 100644 --- a/src/game/object_list_processor.h +++ b/src/game/object_list_processor.h @@ -23,12 +23,7 @@ /** * The maximum number of objects that can be loaded at once. */ - -#ifdef NODRAWINGDISTANCE #define OBJECT_POOL_CAPACITY 960 -#else -#define OBJECT_POOL_CAPACITY 240 -#endif /** * Every object is categorized into an object list, which controls the order diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 729daf062..f274710d5 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -111,6 +111,7 @@ char configPlayerName[MAX_PLAYER_STRING] = ""; unsigned int configPlayerModel = 0; unsigned int configPlayerPalette = 0; unsigned int config60Fps = 1; +unsigned int configDrawDistance = 5; static const struct ConfigOption options[] = { {.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configWindow.fullscreen}, @@ -175,6 +176,7 @@ static const struct ConfigOption options[] = { {.name = "coop_player_model", .type = CONFIG_TYPE_UINT , .uintValue = &configPlayerModel}, {.name = "coop_player_palette", .type = CONFIG_TYPE_UINT , .uintValue = &configPlayerPalette}, {.name = "coop_60fps", .type = CONFIG_TYPE_UINT , .uintValue = &config60Fps}, + {.name = "coop_draw_distance", .type = CONFIG_TYPE_UINT , .uintValue = &configDrawDistance}, }; // Reads an entire line from a file (excluding the newline character) and returns an allocated string diff --git a/src/pc/configfile.h b/src/pc/configfile.h index fd8676bb4..30969de22 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -78,6 +78,7 @@ extern char configPlayerName[]; extern unsigned int configPlayerModel; extern unsigned int configPlayerPalette; extern unsigned int config60Fps; +extern unsigned int configDrawDistance; void configfile_load(const char *filename); void configfile_save(const char *filename); diff --git a/src/pc/djui/djui_panel_display.c b/src/pc/djui/djui_panel_display.c index 147b3ae07..6650f8e95 100644 --- a/src/pc/djui/djui_panel_display.c +++ b/src/pc/djui/djui_panel_display.c @@ -7,7 +7,7 @@ static void djui_panel_display_apply(UNUSED struct DjuiBase* caller) { } void djui_panel_display_create(struct DjuiBase* caller) { - f32 bodyHeight = 32 * 6 + 64 * 1 + 16 * 5; + f32 bodyHeight = 32 * 7 + 64 * 1 + 16 * 6; struct DjuiBase* defaultBase = NULL; struct DjuiThreePanel* panel = djui_panel_menu_create(bodyHeight, "\\#ff0800\\D\\#1be700\\I\\#00b3ff\\S\\#ffef00\\P\\#ff0800\\L\\#1be700\\A\\#00b3ff\\Y"); @@ -39,6 +39,11 @@ void djui_panel_display_create(struct DjuiBase* caller) { djui_base_set_size_type(&selectionbox2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); djui_base_set_size(&selectionbox2->base, 1.0f, 32); + char* drawDistanceChoices[6] = { "0.5x", "1x", "1.5x", "3x", "10x", "100x" }; + struct DjuiSelectionbox* selectionbox3 = djui_selectionbox_create(&body->base, "Draw Distance", drawDistanceChoices, 6, &configDrawDistance); + djui_base_set_size_type(&selectionbox3->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); + djui_base_set_size(&selectionbox3->base, 1.0f, 32); + struct DjuiButton* button6 = djui_button_create(&body->base, "Back"); djui_base_set_size_type(&button6->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE); djui_base_set_size(&button6->base, 1.0f, 64);