From 0f606a3d7627274c53cf8af8f51f58cc84ad4e2f Mon Sep 17 00:00:00 2001 From: Leonardo Pedrozo Amaral Date: Sat, 18 Mar 2023 23:40:52 -0300 Subject: [PATCH 1/2] Several code style and language features usage changes: * global consts replaced from #define to constexpr * corrected namespace scope in source files * namespace naming to lower case --- include/xlite/oal/Buffer.hpp | 54 +++++++++++++++++----------------- include/xlite/oal/Device.hpp | 30 +++++++++---------- include/xlite/oal/Source.hpp | 42 +++++++++++++------------- include/xlite/sound/Audio.hpp | 24 +++++++-------- include/xlite/sound/Engine.hpp | 26 ++++++++-------- include/xlite/sound/Pool.hpp | 36 +++++++++++------------ src/oal/Buffer.cpp | 10 +++++-- src/oal/Device.cpp | 8 ++++- src/oal/Source.cpp | 8 ++++- src/sound/Audio.cpp | 10 +++++-- src/sound/Engine.cpp | 8 ++++- src/sound/Pool.cpp | 10 +++++-- 12 files changed, 151 insertions(+), 115 deletions(-) diff --git a/include/xlite/oal/Buffer.hpp b/include/xlite/oal/Buffer.hpp index 0c1b34f..d6b3888 100644 --- a/include/xlite/oal/Buffer.hpp +++ b/include/xlite/oal/Buffer.hpp @@ -5,39 +5,39 @@ #include #include -namespace Lite { +namespace lite { - namespace Sound { +namespace sound { - enum BufferFormat : int { - /** Signed 16-bit mono buffer format. */ - MONO_SIGNED_16_BIT = 0x1101, - /** Unsigned 8-bit mono buffer format. */ - MONO_UNSIGNED_8_BIT = 0x1100, - /** Signed 16-bit stereo buffer format. */ - STEREO_SIGNED_16_BIT = 0x1103, - /** Unsigned 8-bit stereo buffer format. */ - STEREO_UNSIGNED_8_BIT = 0x1102, - }; +enum BufferFormat : int { + /** Signed 16-bit mono buffer format. */ + MONO_SIGNED_16_BIT = 0x1101, + /** Unsigned 8-bit mono buffer format. */ + MONO_UNSIGNED_8_BIT = 0x1100, + /** Signed 16-bit stereo buffer format. */ + STEREO_SIGNED_16_BIT = 0x1103, + /** Unsigned 8-bit stereo buffer format. */ + STEREO_UNSIGNED_8_BIT = 0x1102, +}; - class LITE_API Buffer { - public: - Buffer(BufferFormat format, int sampleRate); - ~Buffer(); +class LITE_API Buffer { +public: + Buffer(BufferFormat format, int sampleRate); + ~Buffer(); - void Data(const void *data, size_t size) const; + void Data(const void *data, std::size_t size) const; - inline uint32_t GetBuffer() const { - return buffer; - } + inline uint32_t GetBuffer() const { + return buffer; + } - private: - uint32_t buffer = 0; +private: + uint32_t buffer = 0; - BufferFormat format; - int sampleRate; - }; + BufferFormat format; + int sampleRate; +}; - }// namespace Sound +} // namespace sound -}// namespace Lite +} // namespace lite diff --git a/include/xlite/oal/Device.hpp b/include/xlite/oal/Device.hpp index 00b332a..ddf018e 100644 --- a/include/xlite/oal/Device.hpp +++ b/include/xlite/oal/Device.hpp @@ -2,26 +2,26 @@ #include -#define LITE_MAX_MONO_SOURCES 64 -#define LITE_MAX_STEREO_SOURCES 64 +constexpr std::size_t LITE_MAX_MONO_SOURCES = 64; +constexpr std::size_t LITE_MAX_STEREO_SOURCES = 64; -namespace Lite { +namespace lite { - namespace Sound { +namespace sound { - class LITE_API Device { - public: - explicit Device(const char *deviceName); +class LITE_API Device { +public: + explicit Device(const char *deviceName); - Device() : Device("OpenAL Soft") {} + Device() : Device("OpenAL Soft") {} - ~Device(); + ~Device(); - private: - void *device; - void *context; - }; +private: + void *device; + void *context; +}; - }// namespace Sound +} // namespace sound -}// namespace Lite +} // namespace lite diff --git a/include/xlite/oal/Source.hpp b/include/xlite/oal/Source.hpp index 129c2c3..8950839 100644 --- a/include/xlite/oal/Source.hpp +++ b/include/xlite/oal/Source.hpp @@ -5,31 +5,31 @@ #include -namespace Lite { +namespace lite { - namespace Sound { +namespace sound { - class LITE_API Source { - public: - Source(); - ~Source(); +class LITE_API Source { +public: + Source(); + ~Source(); - void Play() const; - void Stop() const; - void Loop(bool loop) const; - void Gain(float gain) const; - bool IsPlaying() const; - void Attach(const Buffer &buffer) const; - void Detach() const; - bool Available() const; + void Play() const; + void Stop() const; + void Loop(bool loop) const; + void Gain(float gain) const; + bool IsPlaying() const; + void Attach(const Buffer &buffer) const; + void Detach() const; + bool Available() const; - private: - uint32_t source = 0; +private: + uint32_t source = 0; - Source(Source &) = delete; - Source(Source const &) = delete; - }; + Source(Source &) = delete; + Source(Source const &) = delete; +}; - }// namespace Sound +} // namespace sound -}// namespace Lite +} // namespace lite diff --git a/include/xlite/sound/Audio.hpp b/include/xlite/sound/Audio.hpp index ae98e2d..9d7ac92 100644 --- a/include/xlite/sound/Audio.hpp +++ b/include/xlite/sound/Audio.hpp @@ -3,21 +3,21 @@ #include #include -namespace Lite { +namespace lite { - namespace Sound { +namespace sound { - class LITE_API Audio { - public: - Audio(BufferFormat channelFormat, int sampleRate, const void *data, size_t size); - ~Audio() = default; +class LITE_API Audio { +public: + Audio(BufferFormat channelFormat, int sampleRate, const void *data, std::size_t size); + ~Audio() = default; - void Play(const Source &source) const; + void Play(const Source &source) const; - private: - Buffer buffer; - }; +private: + Buffer buffer; +}; - }// namespace Sound +} // namespace sound -}// namespace Lite +} // namespace lite diff --git a/include/xlite/sound/Engine.hpp b/include/xlite/sound/Engine.hpp index f043979..2fbea02 100644 --- a/include/xlite/sound/Engine.hpp +++ b/include/xlite/sound/Engine.hpp @@ -8,22 +8,22 @@ #include #include -namespace Lite { +namespace lite { - namespace Sound { +namespace sound { - class LITE_API Engine { - public: - Engine() = default; - ~Engine() = default; +class LITE_API Engine { +public: + Engine() = default; + ~Engine() = default; - bool Play(const Audio &audio); + bool Play(const Audio &audio); - private: - Device device; - Pool pool; - }; +private: + Device device; + Pool pool; +}; - }// namespace Sound +} // namespace sound -}// namespace Lite +} // namespace lite diff --git a/include/xlite/sound/Pool.hpp b/include/xlite/sound/Pool.hpp index 4b76c78..520e82e 100644 --- a/include/xlite/sound/Pool.hpp +++ b/include/xlite/sound/Pool.hpp @@ -10,30 +10,30 @@ #pragma warning(push) #pragma warning(disable : 4251)// Template warnings on vector/queue private members -namespace Lite { +namespace lite { - namespace Sound { +namespace sound { - class LITE_API Pool { - public: - Pool(); - ~Pool() = default; +class LITE_API Pool { +public: + Pool(); + ~Pool() = default; - std::shared_ptr Fetch(); + std::shared_ptr Fetch(); - inline size_t Size() const { - return sources.size(); - } + std::size_t Size() const { + return sources.size(); + } - private: - std::vector> sources; - std::vector> acquired; - std::queue> available; +private: + std::vector> sources; + std::vector> acquired; + std::queue> available; - void Update(); - }; + void Update(); +}; - }// namespace Sound +} // namespace sound -}// namespace Lite +} // namespace lite #pragma warning(pop) diff --git a/src/oal/Buffer.cpp b/src/oal/Buffer.cpp index 3fdd0e8..ee37804 100644 --- a/src/oal/Buffer.cpp +++ b/src/oal/Buffer.cpp @@ -2,7 +2,9 @@ #include -using namespace Lite::Sound; +namespace lite { + +namespace sound { Buffer::Buffer(BufferFormat format, int sampleRate) : format(format), sampleRate(sampleRate) { @@ -13,6 +15,10 @@ Buffer::~Buffer() { alDeleteBuffers(1, &buffer); } -void Buffer::Data(const void *data, size_t size) const { +void Buffer::Data(const void *data, std::size_t size) const { alBufferData(buffer, format, data, static_cast(size), sampleRate); } + +} // namespace sound + +} // namespace lite diff --git a/src/oal/Device.cpp b/src/oal/Device.cpp index d535bf6..41d94d6 100644 --- a/src/oal/Device.cpp +++ b/src/oal/Device.cpp @@ -2,7 +2,9 @@ #include -using namespace Lite::Sound; +namespace lite { + +namespace sound { Device::Device(const char *deviceName) { device = alcOpenDevice(deviceName); @@ -20,3 +22,7 @@ Device::~Device() { alcDestroyContext(static_cast(context)); alcCloseDevice(static_cast(device)); } + +} // namespace sound + +} // namespace lite diff --git a/src/oal/Source.cpp b/src/oal/Source.cpp index a446d35..db08958 100644 --- a/src/oal/Source.cpp +++ b/src/oal/Source.cpp @@ -2,7 +2,9 @@ #include -using namespace Lite::Sound; +namespace lite { + +namespace sound { Source::Source() { alGenSources(1, &source); @@ -56,3 +58,7 @@ bool Source::Available() const { return AL_STOPPED == state; } + +} // namespace sound + +} // namespace lite diff --git a/src/sound/Audio.cpp b/src/sound/Audio.cpp index 352da9b..379c3e1 100644 --- a/src/sound/Audio.cpp +++ b/src/sound/Audio.cpp @@ -1,8 +1,10 @@ #include -using namespace Lite::Sound; +namespace lite { -Audio::Audio(BufferFormat channelFormat, int sampleRate, const void *data, size_t size) +namespace sound { + +Audio::Audio(BufferFormat channelFormat, int sampleRate, const void *data, std::size_t size) : buffer(channelFormat, sampleRate) { buffer.Data(data, size); } @@ -11,3 +13,7 @@ void Audio::Play(const Source &source) const { source.Attach(buffer); source.Play(); } + +} // namespace sound + +} // namespace lite diff --git a/src/sound/Engine.cpp b/src/sound/Engine.cpp index e72d176..11f42db 100644 --- a/src/sound/Engine.cpp +++ b/src/sound/Engine.cpp @@ -1,6 +1,8 @@ #include -using namespace Lite::Sound; +namespace lite { + +namespace sound { bool Engine::Play(const Audio &audio) { auto source = pool.Fetch(); @@ -8,3 +10,7 @@ bool Engine::Play(const Audio &audio) { return true; } + +} // namespace sound + +} // namespace lite diff --git a/src/sound/Pool.cpp b/src/sound/Pool.cpp index b87863e..5cc587c 100644 --- a/src/sound/Pool.cpp +++ b/src/sound/Pool.cpp @@ -3,9 +3,11 @@ #include #include -#define POOL_PREFERRED_SIZE LITE_MAX_MONO_SOURCES + LITE_MAX_STEREO_SOURCES +constexpr std::size_t POOL_PREFERRED_SIZE = LITE_MAX_MONO_SOURCES + LITE_MAX_STEREO_SOURCES; -using namespace Lite::Sound; +namespace lite { + +namespace sound { Pool::Pool() { for (int i = 0; i < POOL_PREFERRED_SIZE; i++) { @@ -47,3 +49,7 @@ void Pool::Update() { ++it; } } + +} // namespace sound + +} // namespace lite From 189fdfd443010ed290e0fbe6674b1bdba8ec21f9 Mon Sep 17 00:00:00 2001 From: Leonardo Pedrozo Amaral Date: Sun, 19 Mar 2023 17:42:12 -0300 Subject: [PATCH 2/2] namespace identation removed and comment trailing add to 1 --- .clang-format | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.clang-format b/.clang-format index ad7f20b..bd10e00 100644 --- a/.clang-format +++ b/.clang-format @@ -27,7 +27,7 @@ IndentPPDirectives: None IndentWidth: 4 KeepEmptyLinesAtTheStartOfBlocks: true MaxEmptyLinesToKeep: 2 -NamespaceIndentation: All +NamespaceIndentation: None ObjCSpaceAfterProperty: false ObjCSpaceBeforeProtocolList: true PointerAlignment: Right @@ -43,7 +43,7 @@ SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements SpaceBeforeRangeBasedForLoopColon: true SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 0 +SpacesBeforeTrailingComments: 1 SpacesInAngles: false SpacesInCStyleCastParentheses: false SpacesInContainerLiterals: false