summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/common_funcs.h30
-rw-r--r--src/common/file_util.cpp48
-rw-r--r--src/common/file_util.h12
-rw-r--r--src/common/logging/backend.cpp1
-rw-r--r--src/common/logging/log.h3
-rw-r--r--src/common/swap.h68
6 files changed, 79 insertions, 83 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index ab3515683..4633897ce 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -72,18 +72,24 @@ inline u64 _rotr64(u64 x, unsigned int shift){
}
#else // _MSC_VER
- #if (_MSC_VER < 1900)
- // Function Cross-Compatibility
- #define snprintf _snprintf
- #endif
-
- // Locale Cross-Compatibility
- #define locale_t _locale_t
-
- extern "C" {
- __declspec(dllimport) void __stdcall DebugBreak(void);
- }
- #define Crash() {DebugBreak();}
+
+#if (_MSC_VER < 1900)
+ // Function Cross-Compatibility
+ #define snprintf _snprintf
+#endif
+
+// Locale Cross-Compatibility
+#define locale_t _locale_t
+
+extern "C" {
+ __declspec(dllimport) void __stdcall DebugBreak(void);
+}
+#define Crash() {DebugBreak();}
+
+// cstdlib provides these on MSVC
+#define rotr _rotr
+#define rotl _rotl
+
#endif // _MSC_VER ndef
// Generic function to get last error message.
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 6e2867658..17af7c385 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -434,7 +434,7 @@ bool CreateEmptyFile(const std::string &filename)
}
-bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback)
+bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback, unsigned int recursion)
{
LOG_TRACE(Common_Filesystem, "directory %s", directory.c_str());
@@ -472,7 +472,7 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo
continue;
unsigned ret_entries = 0;
- if (!callback(&ret_entries, directory, virtual_name)) {
+ if (!callback(&ret_entries, directory, virtual_name, recursion)) {
callback_error = true;
break;
}
@@ -486,30 +486,34 @@ bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directo
closedir(dirp);
#endif
- if (!callback_error) {
- // num_entries_out is allowed to be specified nullptr, in which case we shouldn't try to set it
- if (num_entries_out != nullptr)
- *num_entries_out = found_entries;
- return true;
- } else {
+ if (callback_error)
return false;
- }
+
+ // num_entries_out is allowed to be specified nullptr, in which case we shouldn't try to set it
+ if (num_entries_out != nullptr)
+ *num_entries_out = found_entries;
+ return true;
}
-unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry)
+unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry, unsigned int recursion)
{
const auto callback = [&parent_entry](unsigned* num_entries_out,
const std::string& directory,
- const std::string& virtual_name) -> bool {
+ const std::string& virtual_name,
+ unsigned int recursion) -> bool {
FSTEntry entry;
entry.virtualName = virtual_name;
entry.physicalName = directory + DIR_SEP + virtual_name;
if (IsDirectory(entry.physicalName)) {
entry.isDirectory = true;
- // is a directory, lets go inside
- entry.size = ScanDirectoryTree(entry.physicalName, entry);
- *num_entries_out += (int)entry.size;
+ // is a directory, lets go inside if we didn't recurse to often
+ if (recursion > 0) {
+ entry.size = ScanDirectoryTree(entry.physicalName, entry, recursion - 1);
+ *num_entries_out += (int)entry.size;
+ } else {
+ entry.size = 0;
+ }
} else { // is a file
entry.isDirectory = false;
entry.size = GetSize(entry.physicalName);
@@ -522,23 +526,27 @@ unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry)
};
unsigned num_entries;
- return ForeachDirectoryEntry(&num_entries, directory, callback) ? num_entries : 0;
+ return ForeachDirectoryEntry(&num_entries, directory, callback, recursion) ? num_entries : 0;
}
-bool DeleteDirRecursively(const std::string &directory)
+bool DeleteDirRecursively(const std::string &directory, unsigned int recursion)
{
const static auto callback = [](unsigned* num_entries_out,
const std::string& directory,
- const std::string& virtual_name) -> bool {
+ const std::string& virtual_name,
+ unsigned int recursion) -> bool {
std::string new_path = directory + DIR_SEP_CHR + virtual_name;
- if (IsDirectory(new_path))
- return DeleteDirRecursively(new_path);
+ if (IsDirectory(new_path)) {
+ if (recursion == 0)
+ return false;
+ return DeleteDirRecursively(new_path, recursion - 1);
+ }
return Delete(new_path);
};
- if (!ForeachDirectoryEntry(nullptr, directory, callback))
+ if (!ForeachDirectoryEntry(nullptr, directory, callback, recursion))
return false;
// Delete the outermost directory
diff --git a/src/common/file_util.h b/src/common/file_util.h
index c6a8694ce..32ae2dc57 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -105,11 +105,13 @@ bool CreateEmptyFile(const std::string &filename);
* @param num_entries_out to be assigned by the callable with the number of iterated directory entries, never null
* @param directory the path to the enclosing directory
* @param virtual_name the entry name, without any preceding directory info
+ * @param recursion Number of children directory to read before giving up
* @return whether handling the entry succeeded
*/
using DirectoryEntryCallable = std::function<bool(unsigned* num_entries_out,
const std::string& directory,
- const std::string& virtual_name)>;
+ const std::string& virtual_name,
+ unsigned int recursion)>;
/**
* Scans a directory, calling the callback for each file/directory contained within.
@@ -117,20 +119,22 @@ using DirectoryEntryCallable = std::function<bool(unsigned* num_entries_out,
* @param num_entries_out assigned by the function with the number of iterated directory entries, can be null
* @param directory the directory to scan
* @param callback The callback which will be called for each entry
+ * @param recursion Number of children directories to read before giving up
* @return whether scanning the directory succeeded
*/
-bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback);
+bool ForeachDirectoryEntry(unsigned* num_entries_out, const std::string &directory, DirectoryEntryCallable callback, unsigned int recursion = 0);
/**
* Scans the directory tree, storing the results.
* @param directory the parent directory to start scanning from
* @param parent_entry FSTEntry where the filesystem tree results will be stored.
+ * @param recursion Number of children directories to read before giving up.
* @return the total number of files/directories found
*/
-unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry);
+unsigned ScanDirectoryTree(const std::string &directory, FSTEntry& parent_entry, unsigned int recursion = 0);
// deletes the given directory and anything under it. Returns true on success.
-bool DeleteDirRecursively(const std::string &directory);
+bool DeleteDirRecursively(const std::string &directory, unsigned int recursion = 256);
// Returns the current directory
std::string GetCurrentDir();
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 3d39f94d5..d7008fc66 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -65,6 +65,7 @@ namespace Log {
SUB(Render, OpenGL) \
CLS(Audio) \
SUB(Audio, DSP) \
+ SUB(Audio, Sink) \
CLS(Loader)
// GetClassName is a macro defined by Windows.h, grrr...
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index 521362317..c6910b1c7 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -78,8 +78,9 @@ enum class Class : ClassType {
Render, ///< Emulator video output and hardware acceleration
Render_Software, ///< Software renderer backend
Render_OpenGL, ///< OpenGL backend
- Audio, ///< Emulator audio output
+ Audio, ///< Audio emulation
Audio_DSP, ///< The HLE implementation of the DSP
+ Audio_Sink, ///< Emulator audio output backend
Loader, ///< ROM loader
Count ///< Total number of logging classes
diff --git a/src/common/swap.h b/src/common/swap.h
index a7c37bc44..1749bd7a4 100644
--- a/src/common/swap.h
+++ b/src/common/swap.h
@@ -25,6 +25,8 @@
#include <sys/endian.h>
#endif
+#include <cstring>
+
#include "common/common_types.h"
// GCC 4.6+
@@ -58,9 +60,6 @@
namespace Common {
-inline u8 swap8(u8 _data) {return _data;}
-inline u32 swap24(const u8* _data) {return (_data[0] << 16) | (_data[1] << 8) | _data[2];}
-
#ifdef _MSC_VER
inline u16 swap16(u16 _data) {return _byteswap_ushort(_data);}
inline u32 swap32(u32 _data) {return _byteswap_ulong (_data);}
@@ -92,52 +91,29 @@ inline u64 swap64(u64 data) {return ((u64)swap32(data) << 32) | swap32(data >> 3
#endif
inline float swapf(float f) {
- union {
- float f;
- unsigned int u32;
- } dat1, dat2;
-
- dat1.f = f;
- dat2.u32 = swap32(dat1.u32);
+ static_assert(sizeof(u32) == sizeof(float),
+ "float must be the same size as uint32_t.");
- return dat2.f;
-}
-
-inline double swapd(double f) {
- union {
- double f;
- unsigned long long u64;
- } dat1, dat2;
+ u32 value;
+ std::memcpy(&value, &f, sizeof(u32));
- dat1.f = f;
- dat2.u64 = swap64(dat1.u64);
+ value = swap32(value);
+ std::memcpy(&f, &value, sizeof(u32));
- return dat2.f;
+ return f;
}
-inline u16 swap16(const u8* _pData) {return swap16(*(const u16*)_pData);}
-inline u32 swap32(const u8* _pData) {return swap32(*(const u32*)_pData);}
-inline u64 swap64(const u8* _pData) {return swap64(*(const u64*)_pData);}
-
-template <int count>
-void swap(u8*);
+inline double swapd(double f) {
+ static_assert(sizeof(u64) == sizeof(double),
+ "double must be the same size as uint64_t.");
-template <>
-inline void swap<1>(u8* data) { }
+ u64 value;
+ std::memcpy(&value, &f, sizeof(u64));
-template <>
-inline void swap<2>(u8* data) {
- *reinterpret_cast<u16*>(data) = swap16(data);
-}
-
-template <>
-inline void swap<4>(u8* data) {
- *reinterpret_cast<u32*>(data) = swap32(data);
-}
+ value = swap64(value);
+ std::memcpy(&f, &value, sizeof(u64));
-template <>
-inline void swap<8>(u8* data) {
- *reinterpret_cast<u64*>(data) = swap64(data);
+ return f;
}
} // Namespace Common
@@ -534,35 +510,35 @@ bool operator==(const S &p, const swap_struct_t<T, F> v) {
template <typename T>
struct swap_64_t {
static T swap(T x) {
- return (T)Common::swap64(*(u64 *)&x);
+ return static_cast<T>(Common::swap64(x));
}
};
template <typename T>
struct swap_32_t {
static T swap(T x) {
- return (T)Common::swap32(*(u32 *)&x);
+ return static_cast<T>(Common::swap32(x));
}
};
template <typename T>
struct swap_16_t {
static T swap(T x) {
- return (T)Common::swap16(*(u16 *)&x);
+ return static_cast<T>(Common::swap16(x));
}
};
template <typename T>
struct swap_float_t {
static T swap(T x) {
- return (T)Common::swapf(*(float *)&x);
+ return static_cast<T>(Common::swapf(x));
}
};
template <typename T>
struct swap_double_t {
static T swap(T x) {
- return (T)Common::swapd(*(double *)&x);
+ return static_cast<T>(Common::swapd(x));
}
};