mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 06:05:38 +00:00
Some cosmetic code cleanup.
This commit is contained in:
parent
370914791e
commit
2eb5125d0e
|
@ -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
|
||||||
|
|
|
@ -66,10 +66,10 @@ const std::vector<MetaDataDecl> folderMDD(folderDecls, folderDecls +
|
||||||
const std::vector<MetaDataDecl>& getMDDByType(MetaDataListType type)
|
const std::vector<MetaDataDecl>& getMDDByType(MetaDataListType type)
|
||||||
{
|
{
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case GAME_METADATA:
|
case GAME_METADATA:
|
||||||
return gameMDD;
|
return gameMDD;
|
||||||
case FOLDER_METADATA:
|
case FOLDER_METADATA:
|
||||||
return folderMDD;
|
return folderMDD;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(LogError) << "Invalid MDD type";
|
LOG(LogError) << "Invalid MDD type";
|
||||||
|
|
|
@ -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++) {
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -229,14 +229,14 @@ std::string resolvePlaceholders(const char* in)
|
||||||
return inStr;
|
return inStr;
|
||||||
|
|
||||||
const size_t variableBegin = inStr.find("${");
|
const size_t variableBegin = inStr.find("${");
|
||||||
const size_t variableEnd = inStr.find("}", variableBegin);
|
const size_t variableEnd = inStr.find("}", variableBegin);
|
||||||
|
|
||||||
if ((variableBegin == std::string::npos) || (variableEnd == std::string::npos))
|
if ((variableBegin == std::string::npos) || (variableEnd == std::string::npos))
|
||||||
return inStr;
|
return inStr;
|
||||||
|
|
||||||
std::string prefix = inStr.substr(0, variableBegin);
|
std::string prefix = inStr.substr(0, variableBegin);
|
||||||
std::string replace = inStr.substr(variableBegin + 2, variableEnd - (variableBegin + 2));
|
std::string replace = inStr.substr(variableBegin + 2, variableEnd - (variableBegin + 2));
|
||||||
std::string suffix = resolvePlaceholders(inStr.substr(variableEnd + 1).c_str());
|
std::string suffix = resolvePlaceholders(inStr.substr(variableEnd + 1).c_str());
|
||||||
|
|
||||||
return prefix + mVariables[replace] + suffix;
|
return prefix + mVariables[replace] + suffix;
|
||||||
}
|
}
|
||||||
|
@ -413,7 +413,7 @@ void ThemeData::parseView(const pugi::xml_node& root, ThemeView& view)
|
||||||
const char* delim = " \t\r\n,";
|
const char* delim = " \t\r\n,";
|
||||||
const std::string nameAttr = node.attribute("name").as_string();
|
const std::string nameAttr = node.attribute("name").as_string();
|
||||||
size_t prevOff = nameAttr.find_first_not_of(delim, 0);
|
size_t prevOff = nameAttr.find_first_not_of(delim, 0);
|
||||||
size_t off = nameAttr.find_first_of(delim, prevOff);
|
size_t off = nameAttr.find_first_of(delim, prevOff);
|
||||||
while (off != std::string::npos || prevOff != std::string::npos) {
|
while (off != std::string::npos || prevOff != std::string::npos) {
|
||||||
std::string elemKey = nameAttr.substr(prevOff, off - prevOff);
|
std::string elemKey = nameAttr.substr(prevOff, off - prevOff);
|
||||||
prevOff = nameAttr.find_first_not_of(delim, off);
|
prevOff = nameAttr.find_first_not_of(delim, off);
|
||||||
|
@ -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 [" <<
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue