From 75f40fad952b953e095902eafe72848bf714f254 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Fri, 20 Mar 2020 10:40:09 +0100 Subject: [PATCH] Use more modern C++ --- simgear/sound/xmlsound.cxx | 20 ++++++++++---------- simgear/sound/xmlsound.hxx | 9 ++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/simgear/sound/xmlsound.cxx b/simgear/sound/xmlsound.cxx index a419bffa..ccb52a66 100644 --- a/simgear/sound/xmlsound.cxx +++ b/simgear/sound/xmlsound.cxx @@ -55,7 +55,7 @@ static double _snd_log(double v) { return log(fabs(v)+1e-9); } // static double _snd_pow3(double v) { return v*v*v; } SGXmlSound::SGXmlSound() - : _sample(NULL), + : _sample(nullptr), _active(false), _name(""), _mode(SGXmlSound::ONCE), @@ -120,7 +120,7 @@ SGXmlSound::init( SGPropertyNode *root, _property = root->getNode(propval, true); SGPropertyNode *condition = node->getChild("condition"); - if (condition != NULL) + if (condition != nullptr) _condition = sgReadCondition(root, condition); if (!_property && !_condition) @@ -137,10 +137,10 @@ SGXmlSound::init( SGPropertyNode *root, float v = 0.0; std::vector kids = node->getChildren("volume"); for (i = 0; (i < kids.size()) && (i < SGXmlSound::MAXPROP); i++) { - _snd_prop volume = {NULL, NULL, NULL, NULL, 1.0, 0.0, 0.0, 0.0, false}; + _snd_prop volume = {nullptr, nullptr, nullptr, nullptr, 1.0, 0.0, 0.0, 0.0, false}; SGPropertyNode *n = kids[i]->getChild("expression"); - if (n != NULL) { + if (n != nullptr) { volume.expr = SGReadDoubleExpression(root, n->getChild(0)); } @@ -201,13 +201,13 @@ SGXmlSound::init( SGPropertyNode *root, float p = 0.0; kids = node->getChildren("pitch"); for (i = 0; (i < kids.size()) && (i < SGXmlSound::MAXPROP); i++) { - _snd_prop pitch = {NULL, NULL, NULL, NULL, 1.0, 1.0, 0.0, 0.0, false}; + _snd_prop pitch = {nullptr, nullptr, nullptr, nullptr, 1.0, 1.0, 0.0, 0.0, false}; double randomness = kids[i]->getDoubleValue("random", 0.0); randomness *= sg_random(); SGPropertyNode *n = kids[i]->getChild("expression"); - if (n != NULL) { + if (n != nullptr) { pitch.expr = SGReadDoubleExpression(root, n->getChild(0)); } @@ -265,7 +265,7 @@ SGXmlSound::init( SGPropertyNode *root, SGVec3f offset_pos = SGVec3f::zeros(); SGPropertyNode_ptr prop = node->getChild("position"); SGPropertyNode_ptr pos_prop[3]; - if ( prop != NULL ) { + if ( prop != nullptr ) { offset_pos[0] = -prop->getDoubleValue("x", 0.0); offset_pos[1] = -prop->getDoubleValue("y", 0.0); offset_pos[2] = -prop->getDoubleValue("z", 0.0); @@ -295,7 +295,7 @@ SGXmlSound::init( SGPropertyNode *root, float outer = 360.0; float outer_gain = 0.0; prop = node->getChild("orientation"); - if ( prop != NULL ) { + if ( prop != nullptr ) { dir = SGVec3f(-prop->getFloatValue("x", 0.0), -prop->getFloatValue("y", 0.0), -prop->getFloatValue("z", 0.0)); @@ -414,7 +414,7 @@ SGXmlSound::update (double dt) double v = 1.0; if (_volume[i].expr) { - v = _volume[i].expr->getValue(NULL); + v = _volume[i].expr->getValue(nullptr); expr = true; continue; } @@ -462,7 +462,7 @@ SGXmlSound::update (double dt) double p = 1.0; if (_pitch[i].expr) { - p = _pitch[i].expr->getValue(NULL); + p = _pitch[i].expr->getValue(nullptr); expr = true; continue; } diff --git a/simgear/sound/xmlsound.hxx b/simgear/sound/xmlsound.hxx index c19dac0b..647d83f7 100644 --- a/simgear/sound/xmlsound.hxx +++ b/simgear/sound/xmlsound.hxx @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -136,11 +137,11 @@ protected: enum { ONCE=0, LOOPED, IN_TRANSIT }; enum { LEVEL=0, INVERTED, FLIPFLOP }; - // SGXmlSound properties for + using _fn_t = std::function; typedef struct { SGSharedPtr expr; // sound system version 2.0 SGPropertyNode_ptr prop; - double (*fn)(double); + _fn_t fn; double *intern; double factor; double offset; @@ -149,9 +150,7 @@ protected: bool subtract; } _snd_prop; -protected: - typedef double (*_fn_t)(double); - typedef std::map _sound_fn_t; + using _sound_fn_t = std::map ; _sound_fn_t _sound_fn; private: