From b8a8a61ff8883d0af26eca5f856d7bb92c758617 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 9 Jan 2022 15:25:42 +0000 Subject: [PATCH] Simplify multiplayer powerup creation Instead of creating the powerup from a player, then overwriting the location and velocity of the powerup, and fixing up its segment, create the powerup directly where it should be, with the intended velocity. --- common/include/vecmat.h | 2 ++ common/main/fireball.h | 2 +- common/maths/vecmat.cpp | 1 + similar/main/endlevel.cpp | 2 -- similar/main/fireball.cpp | 3 --- similar/main/multi.cpp | 12 +++--------- 6 files changed, 7 insertions(+), 15 deletions(-) diff --git a/common/include/vecmat.h b/common/include/vecmat.h index 621378a06..35d077678 100644 --- a/common/include/vecmat.h +++ b/common/include/vecmat.h @@ -410,6 +410,8 @@ static inline void vm_angvec_make(vms_angvec *v, fixang p, fixang b, fixang h) v->h = h; } +extern const vms_vector vmd_zero_vector; + } #endif diff --git a/common/main/fireball.h b/common/main/fireball.h index 1b2edbd92..26946581e 100644 --- a/common/main/fireball.h +++ b/common/main/fireball.h @@ -90,9 +90,9 @@ enum class explosion_vclip_stage : int namespace dsx { int get_explosion_vclip(const object_base &obj, explosion_vclip_stage stage); -#if defined(DXX_BUILD_DESCENT_II) imobjptridx_t drop_powerup(const d_vclip_array &Vclip, int id, unsigned num, const vms_vector &init_vel, const vms_vector &pos, vmsegptridx_t segnum, bool player); +#if defined(DXX_BUILD_DESCENT_II) // creates afterburner blobs behind the specified object void drop_afterburner_blobs(object &obj, int count, fix size_scale, fix lifetime); diff --git a/common/maths/vecmat.cpp b/common/maths/vecmat.cpp index 3c76d3c91..dffa34144 100644 --- a/common/maths/vecmat.cpp +++ b/common/maths/vecmat.cpp @@ -24,6 +24,7 @@ namespace dcx { //#define USE_ISQRT 1 constexpr vms_matrix vmd_identity_matrix = IDENTITY_MATRIX; +constexpr vms_vector vmd_zero_vector{}; //adds two vectors, fills in dest, returns ptr to dest //ok for dest to equal either source, but should use vm_vec_add2() if so diff --git a/similar/main/endlevel.cpp b/similar/main/endlevel.cpp index 47f51ce78..efa055616 100644 --- a/similar/main/endlevel.cpp +++ b/similar/main/endlevel.cpp @@ -105,8 +105,6 @@ namespace { #define FLY_ACCEL i2f(5) #define MAX_FLY_OBJECTS 2 -constexpr vms_vector vmd_zero_vector{}; - d_unique_endlevel_state UniqueEndlevelState; static void generate_starfield(d_unique_endlevel_state::starfield_type &stars); static void draw_stars(grs_canvas &, const d_unique_endlevel_state::starfield_type &stars); diff --git a/similar/main/fireball.cpp b/similar/main/fireball.cpp index 47062c4a5..3fe70dc07 100644 --- a/similar/main/fireball.cpp +++ b/similar/main/fireball.cpp @@ -1040,9 +1040,6 @@ void maybe_replace_powerup_with_energy(object_base &del_obj) } } -#if defined(DXX_BUILD_DESCENT_I) -static -#endif imobjptridx_t drop_powerup(const d_vclip_array &Vclip, int id, const unsigned num, const vms_vector &init_vel, const vms_vector &pos, const vmsegptridx_t segnum, const bool player) { imobjptridx_t objnum = object_none; diff --git a/similar/main/multi.cpp b/similar/main/multi.cpp index a6091ca11..09f8b2964 100644 --- a/similar/main/multi.cpp +++ b/similar/main/multi.cpp @@ -2167,7 +2167,7 @@ static void multi_do_controlcen_fire(const ubyte *buf) Laser_create_new_easy(to_target, objp->ctype.reactor_info.gun_pos[gun_num], objp, weapon_id_type::CONTROLCEN_WEAPON_NUM, 1); } -static void multi_do_create_powerup(fvmobjptr &vmobjptr, fvmsegptridx &vmsegptridx, const playernum_t pnum, const uint8_t *const buf) +static void multi_do_create_powerup(fvmsegptridx &vmsegptridx, const playernum_t pnum, const uint8_t *const buf) { auto &LevelUniqueControlCenterState = LevelUniqueObjectState.ControlCenterState; int count = 1; @@ -2194,7 +2194,7 @@ static void multi_do_create_powerup(fvmobjptr &vmobjptr, fvmsegptridx &vmsegptri } Net_create_loc = 0; - const auto &&my_objnum = call_object_create_egg(vmobjptr(vcplayerptr(pnum)->objnum), 1, powerup_type); + const auto &&my_objnum = drop_powerup(Vclip, powerup_type, 1, vmd_zero_vector, new_pos, segnum, true); if (my_objnum == object_none) { return; @@ -2205,12 +2205,6 @@ static void multi_do_create_powerup(fvmobjptr &vmobjptr, fvmsegptridx &vmsegptri Network_send_objnum = -1; } - my_objnum->pos = new_pos; - - vm_vec_zero(my_objnum->mtype.phys_info.velocity); - - obj_relink(vmobjptr, vmsegptr, my_objnum, segnum); - map_objnum_local_to_remote(my_objnum, objnum, pnum); object_create_explosion(segnum, new_pos, i2f(5), VCLIP_POWERUP_DISAPPEARANCE); @@ -5809,7 +5803,7 @@ static void multi_process_data(const playernum_t pnum, const ubyte *buf, const u case MULTI_CONTROLCEN_FIRE: multi_do_controlcen_fire(buf); break; case MULTI_CREATE_POWERUP: - multi_do_create_powerup(vmobjptr, vmsegptridx, pnum, buf); + multi_do_create_powerup(vmsegptridx, pnum, buf); break; case MULTI_PLAY_SOUND: multi_do_play_sound(Objects, pnum, buf);