diff --git a/common/include/maths.h b/common/include/maths.h index e56ef3c85..0bd27149e 100644 --- a/common/include/maths.h +++ b/common/include/maths.h @@ -16,6 +16,7 @@ #define D_RAND_MAX 32767 #ifdef __cplusplus +#include #include "dxxsconf.h" void d_srand (unsigned int seed); @@ -126,6 +127,21 @@ fix fix_sqrt (fix a); //compute sine and cosine of an angle, filling in the variables //either of the pointers can be NULL void fix_sincos (fix a, fix * s, fix * c); //with interpolation +void fix_sincos(fix, std::nullptr_t, std::nullptr_t) = delete; + +__attribute_warn_unused_result +static inline fix fix_sin(fix a) +{ + fix s; + return fix_sincos(a, &s, nullptr), s; +} + +__attribute_warn_unused_result +static inline fix fix_cos(fix a) +{ + fix c; + return fix_sincos(a, nullptr, &c), c; +} void fix_fastsincos (fix a, fix * s, fix * c); //no interpolation diff --git a/similar/main/ai.cpp b/similar/main/ai.cpp index 41e40dd10..c8e621b99 100644 --- a/similar/main/ai.cpp +++ b/similar/main/ai.cpp @@ -2229,13 +2229,13 @@ void start_boss_death_sequence(const vobjptr_t objp) #if defined(DXX_BUILD_DESCENT_I) static void do_boss_dying_frame(const vobjptridx_t objp) { - fix boss_roll_val, temp; + fix boss_roll_val; boss_roll_val = fixdiv(GameTime64 - Boss_dying_start_time, BOSS_DEATH_DURATION); - fix_sincos(fixmul(boss_roll_val, boss_roll_val), &temp, &objp->mtype.phys_info.rotvel.x); - fix_sincos(boss_roll_val, &temp, &objp->mtype.phys_info.rotvel.y); - fix_sincos(boss_roll_val-F1_0/8, &temp, &objp->mtype.phys_info.rotvel.z); + fix_sincos(fixmul(boss_roll_val, boss_roll_val), nullptr, &objp->mtype.phys_info.rotvel.x); + fix_sincos(boss_roll_val, nullptr, &objp->mtype.phys_info.rotvel.y); + fix_sincos(boss_roll_val-F1_0/8, nullptr, &objp->mtype.phys_info.rotvel.z); objp->mtype.phys_info.rotvel.x = (GameTime64 - Boss_dying_start_time)/9; objp->mtype.phys_info.rotvel.y = (GameTime64 - Boss_dying_start_time)/5; @@ -2329,7 +2329,7 @@ void start_robot_death_sequence(const vobjptr_t objp) // scale: F1_0*4 for boss, much smaller for much smaller guys static int do_robot_dying_frame(const vobjptridx_t objp, fix64 start_time, fix roll_duration, sbyte *dying_sound_playing, int death_sound, fix expl_scale, fix sound_scale) { - fix roll_val, temp; + fix roll_val; fix sound_duration; if (!roll_duration) @@ -2337,9 +2337,9 @@ static int do_robot_dying_frame(const vobjptridx_t objp, fix64 start_time, fix r roll_val = fixdiv(GameTime64 - start_time, roll_duration); - fix_sincos(fixmul(roll_val, roll_val), &temp, &objp->mtype.phys_info.rotvel.x); - fix_sincos(roll_val, &temp, &objp->mtype.phys_info.rotvel.y); - fix_sincos(roll_val-F1_0/8, &temp, &objp->mtype.phys_info.rotvel.z); + fix_sincos(fixmul(roll_val, roll_val), nullptr, &objp->mtype.phys_info.rotvel.x); + fix_sincos(roll_val, nullptr, &objp->mtype.phys_info.rotvel.y); + fix_sincos(roll_val-F1_0/8, nullptr, &objp->mtype.phys_info.rotvel.z); objp->mtype.phys_info.rotvel.x = (GameTime64 - start_time)/9; objp->mtype.phys_info.rotvel.y = (GameTime64 - start_time)/5; diff --git a/similar/main/digiobj.cpp b/similar/main/digiobj.cpp index d282eb452..c43bd7e79 100644 --- a/similar/main/digiobj.cpp +++ b/similar/main/digiobj.cpp @@ -133,7 +133,7 @@ static void digi_get_sound_loc(const vms_matrix &listener, const vms_vector &lis { vms_vector vector_to_sound; - fix angle_from_ear, cosang,sinang; + fix angle_from_ear; fix distance; fix path_distance; @@ -154,7 +154,7 @@ static void digi_get_sound_loc(const vms_matrix &listener, const vms_vector &lis *volume = max_volume - fixdiv(path_distance,max_distance); if (*volume > 0 ) { angle_from_ear = vm_vec_delta_ang_norm(listener.rvec,vector_to_sound,listener.uvec); - fix_sincos(angle_from_ear,&sinang,&cosang); + auto cosang = fix_cos(angle_from_ear); if (GameCfg.ReverseStereo) cosang *= -1; *pan = (cosang + F1_0)/2; } else { diff --git a/similar/main/lighting.cpp b/similar/main/lighting.cpp index 833081a92..213cee5f0 100644 --- a/similar/main/lighting.cpp +++ b/similar/main/lighting.cpp @@ -269,10 +269,10 @@ static g3s_lrgb compute_light_emission(int objnum) } else if (game_mode_hoard() && Players[obj->id].secondary_ammo[PROXIMITY_INDEX]) // If hoard game and player, add extra light based on how many orbs you have Pulse as well. { - fix s,hoardlight; + fix hoardlight; hoardlight=i2f(Players[obj->id].secondary_ammo[PROXIMITY_INDEX])/2; //i2f(12)); hoardlight++; - fix_sincos (((fix)(GameTime64/2)) & 0xFFFF,&s,NULL); // probably a bad way to do it + auto s = fix_sin(static_cast(GameTime64/2) & 0xFFFF); // probably a bad way to do it s+=F1_0; s>>=1; hoardlight=fixmul (s,hoardlight);