mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-07 08:15:59 -10:00
Fix the unique pointer and constructor
Unique pointers need to be constructed in very particular ways, but so did this NGON radar class, so we just had to put the constructor function inside unique pointer constructor.
And to keep that special pointer from going out of scope, we switched to the ternery operator.
Also made these changes:
Change to hypotf()
Fix Shadowing, Zero Vector macro not working at all.
Offset changed to offset_incoming
blip changed to blip_instance
Offset changed to = {} to initialize the struct without a problem.
clampBlip() required an override
Give offset a default initializer.
Switch to <cmath>
(Apparently <math.h> was deprecated and needs to be replaced with <cmath>.)
One last complaint from travis about a redundant default value.
Thank you Travis!
This commit is contained in:
1 parent
1fb194a729
commit
a17f5031bf
4 files changed
+23
-22
No files matched your search
+10
-9
@@ -2714,16 +2714,17 @@ void load_gauge_radar_std(gauge_settings* settings)
|
||||
}
|
||||
}
|
||||
|
||||
HudGaugeRadarStd* hud_gauge;
|
||||
if (num_sides == 0) {
|
||||
// Standard radar
|
||||
hud_gauge = gauge_load_common<HudGaugeRadarStd>(settings);
|
||||
} else {
|
||||
// Ngon radar
|
||||
hud_gauge = new HudGaugeRadarNgon(num_sides, offset);
|
||||
hud_gauge = gauge_load_common<HudGaugeRadarNgon>(settings, static_cast<HudGaugeRadarNgon*>(hud_gauge));
|
||||
}
|
||||
//=======================================================================================================
|
||||
// Cyborg17 - not using auto here is a huge pain to get exactly right and to read. If we put this in a
|
||||
// normal if block, either auto will break or hud_gauge will go out of scope before the last block below.
|
||||
// The ternery operator lets us circumvent this problem by allowing us to use auto, while also loading
|
||||
// the radar and creating the unique_ptr.
|
||||
|
||||
// did we have a normal radar? If so, load the regular radar.
|
||||
auto hud_gauge = (num_sides == 0) ? gauge_load_common<HudGaugeRadarStd>(settings)
|
||||
// if not *construct* and then load the ngon radar
|
||||
: gauge_load_common<HudGaugeRadarNgon>(settings, new HudGaugeRadarNgon(num_sides, offset));
|
||||
|
||||
// Only load this if the user hasn't specified a preference
|
||||
if (Cmdline_orb_radar == 0) {
|
||||
hud_gauge->initBitmaps(fname);
|
||||
|
||||
@@ -394,7 +394,7 @@ void HudGaugeRadarStd::plotBlip(blip *b, int *x, int *y)
|
||||
|
||||
zdist = hypotf(pos->xyz.x, pos->xyz.y);
|
||||
|
||||
vec3d new_pos = ZERO_VECTOR;
|
||||
vec3d new_pos = {};
|
||||
|
||||
if (zdist >= 0.01f)
|
||||
{
|
||||
|
||||
+10
-10
@@ -2,31 +2,31 @@
|
||||
|
||||
#include "math/vecmat.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <cmath>
|
||||
|
||||
void HudGaugeRadarNgon::clampBlip(vec3d* blip) {
|
||||
void HudGaugeRadarNgon::clampBlip(vec3d* blip_instance) {
|
||||
float hypotenuse;
|
||||
|
||||
hypotenuse = _hypotf(blip->xyz.x, blip->xyz.y);
|
||||
hypotenuse = hypotf(blip_instance->xyz.x, blip_instance->xyz.y);
|
||||
|
||||
// Only do this math if the blip hypotenuse is longer than or equal to the apothem
|
||||
if (hypotenuse >= r_min) {
|
||||
float angle = atan2(blip->xyz.y, blip->xyz.x);
|
||||
float angle = atan2(blip_instance->xyz.y, blip_instance->xyz.x);
|
||||
vec3d Line_p;
|
||||
vec3d Line_v;
|
||||
formLine(&Line_p, &Line_v, angle);
|
||||
|
||||
float s;
|
||||
int success = find_intersection(&s, &vmd_zero_vector, &Line_p, blip, &Line_v);
|
||||
int success = find_intersection(&s, &vmd_zero_vector, &Line_p, blip_instance, &Line_v);
|
||||
|
||||
if ((success == 0) && (s < 1.0f)) {
|
||||
// Clamp the blip to the edge
|
||||
vm_vec_scale(blip, s);
|
||||
vm_vec_scale(blip_instance, s);
|
||||
}
|
||||
}
|
||||
|
||||
// Use Std's method of clamping and scaling, we'll get some nice rounded corners in the process
|
||||
HudGaugeRadarStd::clampBlip(blip);
|
||||
HudGaugeRadarStd::clampBlip(blip_instance);
|
||||
}
|
||||
|
||||
void HudGaugeRadarNgon::formLine(vec3d* p, vec3d* v, float angle) {
|
||||
@@ -50,9 +50,9 @@ void HudGaugeRadarNgon::formLine(vec3d* p, vec3d* v, float angle) {
|
||||
|
||||
// Default to a hexagon
|
||||
HudGaugeRadarNgon::HudGaugeRadarNgon()
|
||||
: arclen(PI2 / i2fl(6)), offset(0.0f), r_min(cos(PI / i2fl(6))) {}
|
||||
: arclen(PI2 / i2fl(6)), r_min(cos(PI / i2fl(6))) {}
|
||||
|
||||
HudGaugeRadarNgon::HudGaugeRadarNgon(int num_sides, float offset)
|
||||
: arclen(PI2 / i2fl(num_sides)), offset(offset * (PI / 180.0f)), r_min(cos(PI / i2fl(num_sides)))
|
||||
HudGaugeRadarNgon::HudGaugeRadarNgon(int num_sides, float offset_incoming)
|
||||
: arclen(PI2 / i2fl(num_sides)), offset(offset_incoming * (PI / 180.0f)), r_min(cos(PI / i2fl(num_sides)))
|
||||
{
|
||||
}
|
||||
@@ -20,7 +20,7 @@ const int RADAR_NGON_MIN_SIDES = 3; //!< Required, things break if n < 3
|
||||
class HudGaugeRadarNgon : public HudGaugeRadarStd
|
||||
{
|
||||
float arclen; // The arc length of each n-gon sector (radians)
|
||||
float offset; // The angle offset of the plot area (+ is counter-clockwise) (radians)
|
||||
float offset {0.0f}; // The angle offset of the plot area (+ is counter-clockwise) (radians),
|
||||
float r_min; // The apothem of the ngon (0.0f < r_min <= 1.0f)
|
||||
|
||||
protected:
|
||||
@@ -36,7 +36,7 @@ protected:
|
||||
* @brief Clamps and scales the blip to be within the plot area
|
||||
* @param[in] vec The blip coordinates (only x and y are nonzero)
|
||||
*/
|
||||
void clampBlip(vec3d* blip);
|
||||
void clampBlip(vec3d* blip) override;
|
||||
|
||||
public:
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user