Some cosmetic code cleanup.

This commit is contained in:
Leon Styhre 2020-10-18 19:45:26 +02:00
parent 370914791e
commit 2eb5125d0e
8 changed files with 41 additions and 34 deletions

View file

@ -984,7 +984,7 @@ This will remove any media files for the game file or folder and also remove its
**Delete** _(Files only)_ **Delete** _(Files only)_
This will remove the actual game file and its gamelist.xml entry, as well as any media files. A prompt will be shown asking for confirmation. The deletion of folders is not supported as that would potentially be a bit dangerous, instead use the valid operating system tools to handle deletion of folders. This will remove the actual game file and its gamelist.xml entry, as well as any media files. A prompt will be shown asking for confirmation. The deletion of folders is not supported as that would potentially be a bit dangerous, instead use the appropriate operating system tools to handle deletion of folders.
## Screensaver ## Screensaver

View file

@ -18,7 +18,7 @@ std::vector<std::shared_ptr<Sound>> AudioManager::sSoundVector;
SDL_AudioSpec AudioManager::sAudioFormat; SDL_AudioSpec AudioManager::sAudioFormat;
std::shared_ptr<AudioManager> AudioManager::sInstance; std::shared_ptr<AudioManager> AudioManager::sInstance;
void AudioManager::mixAudio(void* /*unused*/, Uint8 *stream, int len) void AudioManager::mixAudio(void* /*unused*/, Uint8* stream, int len)
{ {
bool stillPlaying = false; bool stillPlaying = false;
@ -32,7 +32,7 @@ void AudioManager::mixAudio(void* /*unused*/, Uint8 *stream, int len)
if (sound->isPlaying()) { if (sound->isPlaying()) {
// Calculate rest length of current sample. // Calculate rest length of current sample.
Uint32 restLength = (sound->getLength() - sound->getPosition()); Uint32 restLength = (sound->getLength() - sound->getPosition());
if (restLength > (Uint32)len) { if (restLength > static_cast<Uint32>(len)) {
// If stream length is smaller than sample length, clip it. // If stream length is smaller than sample length, clip it.
restLength = len; restLength = len;
} }
@ -68,7 +68,7 @@ AudioManager::~AudioManager()
deinit(); deinit();
} }
std::shared_ptr<AudioManager> & AudioManager::getInstance() std::shared_ptr<AudioManager>& AudioManager::getInstance()
{ {
// Check if an AudioManager instance is already created, if not create one. // Check if an AudioManager instance is already created, if not create one.
if (sInstance == nullptr && Settings::getInstance()->getBool("NavigationSounds")) { if (sInstance == nullptr && Settings::getInstance()->getBool("NavigationSounds")) {
@ -116,13 +116,13 @@ void AudioManager::deinit()
sInstance = nullptr; sInstance = nullptr;
} }
void AudioManager::registerSound(std::shared_ptr<Sound> & sound) void AudioManager::registerSound(std::shared_ptr<Sound>& sound)
{ {
getInstance(); getInstance();
sSoundVector.push_back(sound); sSoundVector.push_back(sound);
} }
void AudioManager::unregisterSound(std::shared_ptr<Sound> & sound) void AudioManager::unregisterSound(std::shared_ptr<Sound>& sound)
{ {
getInstance(); getInstance();
for (unsigned int i = 0; i < sSoundVector.size(); i++) { for (unsigned int i = 0; i < sSoundVector.size(); i++) {

View file

@ -21,18 +21,18 @@ class AudioManager
static std::vector<std::shared_ptr<Sound>> sSoundVector; static std::vector<std::shared_ptr<Sound>> sSoundVector;
static std::shared_ptr<AudioManager> sInstance; static std::shared_ptr<AudioManager> sInstance;
static void mixAudio(void *unused, Uint8 *stream, int len); static void mixAudio(void* unused, Uint8* stream, int len);
AudioManager(); AudioManager();
public: public:
static std::shared_ptr<AudioManager> & getInstance(); static std::shared_ptr<AudioManager>& getInstance();
void init(); void init();
void deinit(); void deinit();
void registerSound(std::shared_ptr<Sound> & sound); void registerSound(std::shared_ptr<Sound>& sound);
void unregisterSound(std::shared_ptr<Sound> & sound); void unregisterSound(std::shared_ptr<Sound>& sound);
void play(); void play();
void stop(); void stop();

View file

@ -86,7 +86,7 @@ bool NavigationSounds::isPlayingThemeNavigationSound(NavigationSoundsID soundID)
} }
Sound::Sound( Sound::Sound(
const std::string & path) const std::string& path)
: mSampleData(nullptr), : mSampleData(nullptr),
mSamplePos(0), mSamplePos(0),
mSampleLength(0), mSampleLength(0),
@ -100,7 +100,7 @@ Sound::~Sound()
deinit(); deinit();
} }
void Sound::loadFile(const std::string & path) void Sound::loadFile(const std::string& path)
{ {
mPath = path; mPath = path;
init(); init();
@ -116,7 +116,7 @@ void Sound::init()
// Load WAV file via SDL. // Load WAV file via SDL.
SDL_AudioSpec wave; SDL_AudioSpec wave;
Uint8 * data = nullptr; Uint8* data = nullptr;
Uint32 dlen = 0; Uint32 dlen = 0;
if (SDL_LoadWAV(mPath.c_str(), &wave, &data, &dlen) == nullptr) { if (SDL_LoadWAV(mPath.c_str(), &wave, &data, &dlen) == nullptr) {
LOG(LogError) << "Failed to load theme navigation sound file:"; LOG(LogError) << "Failed to load theme navigation sound file:";
@ -203,7 +203,7 @@ void Sound::stop()
SDL_UnlockAudio(); SDL_UnlockAudio();
} }
const Uint8 * Sound::getData() const const Uint8* Sound::getData() const
{ {
return mSampleData; return mSampleData;
} }
@ -232,5 +232,5 @@ Uint32 Sound::getLengthMS() const
{ {
// 44100 samples per second, 2 channels (stereo). // 44100 samples per second, 2 channels (stereo).
// I have no idea why the *0.75 is necessary, but otherwise it's inaccurate. // I have no idea why the *0.75 is necessary, but otherwise it's inaccurate.
return (Uint32)((mSampleLength / 44100.0f / 2.0f * 0.75f) * 1000); return static_cast<Uint32>((mSampleLength / 44100.0f / 2.0f * 0.75f) * 1000);
} }

View file

@ -25,7 +25,7 @@ class Sound
{ {
std::string mPath; std::string mPath;
SDL_AudioSpec mSampleFormat; SDL_AudioSpec mSampleFormat;
Uint8 * mSampleData; Uint8* mSampleData;
Uint32 mSamplePos; Uint32 mSamplePos;
Uint32 mSampleLength; Uint32 mSampleLength;
bool playing; bool playing;
@ -40,21 +40,21 @@ public:
void init(); void init();
void deinit(); void deinit();
void loadFile(const std::string & path); void loadFile(const std::string& path);
void play(); void play();
bool isPlaying() const; bool isPlaying() const;
void stop(); void stop();
const Uint8 * getData() const; const Uint8* getData() const;
Uint32 getPosition() const; Uint32 getPosition() const;
void setPosition(Uint32 newPosition); void setPosition(Uint32 newPosition);
Uint32 getLength() const; Uint32 getLength() const;
Uint32 getLengthMS() const; Uint32 getLengthMS() const;
private: private:
Sound(const std::string & path = ""); Sound(const std::string& path = "");
static std::map< std::string, std::shared_ptr<Sound> > sMap; static std::map<std::string, std::shared_ptr<Sound>> sMap;
}; };
enum NavigationSoundsID { enum NavigationSoundsID {

View file

@ -453,12 +453,16 @@ void ThemeData::parseElement(const pugi::xml_node& root,
auto splits = Utils::String::delimitedStringToVector(str, " "); auto splits = Utils::String::delimitedStringToVector(str, " ");
if (splits.size() == 2) { if (splits.size() == 2) {
val = Vector4f((float)atof(splits.at(0).c_str()), (float)atof(splits.at(1).c_str()), val = Vector4f(static_cast<float>(atof(splits.at(0).c_str())),
(float)atof(splits.at(0).c_str()), (float)atof(splits.at(1).c_str())); static_cast<float>(atof(splits.at(1).c_str())),
static_cast<float>(atof(splits.at(0).c_str())),
static_cast<float>(atof(splits.at(1).c_str())));
} }
else if (splits.size() == 4) { else if (splits.size() == 4) {
val = Vector4f((float)atof(splits.at(0).c_str()), (float)atof(splits.at(1).c_str()), val = Vector4f(static_cast<float>(atof(splits.at(0).c_str())),
(float)atof(splits.at(2).c_str()), (float)atof(splits.at(3).c_str())); static_cast<float>(atof(splits.at(1).c_str())),
static_cast<float>(atof(splits.at(2).c_str())),
static_cast<float>(atof(splits.at(3).c_str())));
} }
element.properties[node.name()] = val; element.properties[node.name()] = val;
@ -473,7 +477,8 @@ void ThemeData::parseElement(const pugi::xml_node& root,
std::string first = str.substr(0, divider); std::string first = str.substr(0, divider);
std::string second = str.substr(divider, std::string::npos); std::string second = str.substr(divider, std::string::npos);
Vector2f val((float)atof(first.c_str()), (float)atof(second.c_str())); Vector2f val(static_cast<float>(atof(first.c_str())),
static_cast<float>(atof(second.c_str())));
element.properties[node.name()] = val; element.properties[node.name()] = val;
break; break;
@ -536,7 +541,8 @@ const ThemeData::ThemeElement* ThemeData::getElement(const std::string& view,
return nullptr; // Not found. return nullptr; // Not found.
auto elemIt = viewIt->second.elements.find(element); auto elemIt = viewIt->second.elements.find(element);
if (elemIt == viewIt->second.elements.cend()) return nullptr; if (elemIt == viewIt->second.elements.cend())
return nullptr;
if (elemIt->second.type != expectedType && !expectedType.empty()) { if (elemIt->second.type != expectedType && !expectedType.empty()) {
LOG(LogWarning) << " requested mismatched theme type for [" << LOG(LogWarning) << " requested mismatched theme type for [" <<

View file

@ -14,6 +14,7 @@
#include "math/Vector2f.h" #include "math/Vector2f.h"
#include "math/Vector4f.h" #include "math/Vector4f.h"
#include "utils/FileSystemUtil.h" #include "utils/FileSystemUtil.h"
#include <deque> #include <deque>
#include <map> #include <map>
#include <memory> #include <memory>