diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/color.h | 40 | ||||
| -rw-r--r-- | src/common/logging/backend.cpp | 50 | ||||
| -rw-r--r-- | src/common/logging/backend.h | 4 | ||||
| -rw-r--r-- | src/common/math_util.h | 4 | ||||
| -rw-r--r-- | src/common/quaternion.h | 10 | ||||
| -rw-r--r-- | src/common/vector_math.h | 4 | 
6 files changed, 54 insertions, 58 deletions
| diff --git a/src/common/color.h b/src/common/color.h index 0379040be..3a2222077 100644 --- a/src/common/color.h +++ b/src/common/color.h @@ -55,36 +55,36 @@ constexpr u8 Convert8To6(u8 value) {  /**   * Decode a color stored in RGBA8 format   * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4<u8> + * @return Result color decoded as Common::Vec4<u8>   */ -inline Math::Vec4<u8> DecodeRGBA8(const u8* bytes) { +inline Common::Vec4<u8> DecodeRGBA8(const u8* bytes) {      return {bytes[3], bytes[2], bytes[1], bytes[0]};  }  /**   * Decode a color stored in RGB8 format   * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4<u8> + * @return Result color decoded as Common::Vec4<u8>   */ -inline Math::Vec4<u8> DecodeRGB8(const u8* bytes) { +inline Common::Vec4<u8> DecodeRGB8(const u8* bytes) {      return {bytes[2], bytes[1], bytes[0], 255};  }  /**   * Decode a color stored in RG8 (aka HILO8) format   * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4<u8> + * @return Result color decoded as Common::Vec4<u8>   */ -inline Math::Vec4<u8> DecodeRG8(const u8* bytes) { +inline Common::Vec4<u8> DecodeRG8(const u8* bytes) {      return {bytes[1], bytes[0], 0, 255};  }  /**   * Decode a color stored in RGB565 format   * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4<u8> + * @return Result color decoded as Common::Vec4<u8>   */ -inline Math::Vec4<u8> DecodeRGB565(const u8* bytes) { +inline Common::Vec4<u8> DecodeRGB565(const u8* bytes) {      u16_le pixel;      std::memcpy(&pixel, bytes, sizeof(pixel));      return {Convert5To8((pixel >> 11) & 0x1F), Convert6To8((pixel >> 5) & 0x3F), @@ -94,9 +94,9 @@ inline Math::Vec4<u8> DecodeRGB565(const u8* bytes) {  /**   * Decode a color stored in RGB5A1 format   * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4<u8> + * @return Result color decoded as Common::Vec4<u8>   */ -inline Math::Vec4<u8> DecodeRGB5A1(const u8* bytes) { +inline Common::Vec4<u8> DecodeRGB5A1(const u8* bytes) {      u16_le pixel;      std::memcpy(&pixel, bytes, sizeof(pixel));      return {Convert5To8((pixel >> 11) & 0x1F), Convert5To8((pixel >> 6) & 0x1F), @@ -106,9 +106,9 @@ inline Math::Vec4<u8> DecodeRGB5A1(const u8* bytes) {  /**   * Decode a color stored in RGBA4 format   * @param bytes Pointer to encoded source color - * @return Result color decoded as Math::Vec4<u8> + * @return Result color decoded as Common::Vec4<u8>   */ -inline Math::Vec4<u8> DecodeRGBA4(const u8* bytes) { +inline Common::Vec4<u8> DecodeRGBA4(const u8* bytes) {      u16_le pixel;      std::memcpy(&pixel, bytes, sizeof(pixel));      return {Convert4To8((pixel >> 12) & 0xF), Convert4To8((pixel >> 8) & 0xF), @@ -138,9 +138,9 @@ inline u32 DecodeD24(const u8* bytes) {  /**   * Decode a depth value and a stencil value stored in D24S8 format   * @param bytes Pointer to encoded source values - * @return Resulting values stored as a Math::Vec2 + * @return Resulting values stored as a Common::Vec2   */ -inline Math::Vec2<u32> DecodeD24S8(const u8* bytes) { +inline Common::Vec2<u32> DecodeD24S8(const u8* bytes) {      return {static_cast<u32>((bytes[2] << 16) | (bytes[1] << 8) | bytes[0]), bytes[3]};  } @@ -149,7 +149,7 @@ inline Math::Vec2<u32> DecodeD24S8(const u8* bytes) {   * @param color Source color to encode   * @param bytes Destination pointer to store encoded color   */ -inline void EncodeRGBA8(const Math::Vec4<u8>& color, u8* bytes) { +inline void EncodeRGBA8(const Common::Vec4<u8>& color, u8* bytes) {      bytes[3] = color.r();      bytes[2] = color.g();      bytes[1] = color.b(); @@ -161,7 +161,7 @@ inline void EncodeRGBA8(const Math::Vec4<u8>& color, u8* bytes) {   * @param color Source color to encode   * @param bytes Destination pointer to store encoded color   */ -inline void EncodeRGB8(const Math::Vec4<u8>& color, u8* bytes) { +inline void EncodeRGB8(const Common::Vec4<u8>& color, u8* bytes) {      bytes[2] = color.r();      bytes[1] = color.g();      bytes[0] = color.b(); @@ -172,7 +172,7 @@ inline void EncodeRGB8(const Math::Vec4<u8>& color, u8* bytes) {   * @param color Source color to encode   * @param bytes Destination pointer to store encoded color   */ -inline void EncodeRG8(const Math::Vec4<u8>& color, u8* bytes) { +inline void EncodeRG8(const Common::Vec4<u8>& color, u8* bytes) {      bytes[1] = color.r();      bytes[0] = color.g();  } @@ -181,7 +181,7 @@ inline void EncodeRG8(const Math::Vec4<u8>& color, u8* bytes) {   * @param color Source color to encode   * @param bytes Destination pointer to store encoded color   */ -inline void EncodeRGB565(const Math::Vec4<u8>& color, u8* bytes) { +inline void EncodeRGB565(const Common::Vec4<u8>& color, u8* bytes) {      const u16_le data =          (Convert8To5(color.r()) << 11) | (Convert8To6(color.g()) << 5) | Convert8To5(color.b()); @@ -193,7 +193,7 @@ inline void EncodeRGB565(const Math::Vec4<u8>& color, u8* bytes) {   * @param color Source color to encode   * @param bytes Destination pointer to store encoded color   */ -inline void EncodeRGB5A1(const Math::Vec4<u8>& color, u8* bytes) { +inline void EncodeRGB5A1(const Common::Vec4<u8>& color, u8* bytes) {      const u16_le data = (Convert8To5(color.r()) << 11) | (Convert8To5(color.g()) << 6) |                          (Convert8To5(color.b()) << 1) | Convert8To1(color.a()); @@ -205,7 +205,7 @@ inline void EncodeRGB5A1(const Math::Vec4<u8>& color, u8* bytes) {   * @param color Source color to encode   * @param bytes Destination pointer to store encoded color   */ -inline void EncodeRGBA4(const Math::Vec4<u8>& color, u8* bytes) { +inline void EncodeRGBA4(const Common::Vec4<u8>& color, u8* bytes) {      const u16 data = (Convert8To4(color.r()) << 12) | (Convert8To4(color.g()) << 8) |                       (Convert8To4(color.b()) << 4) | Convert8To4(color.a()); diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index b369f199f..4462ff3fb 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -39,8 +39,10 @@ public:      Impl(Impl const&) = delete;      const Impl& operator=(Impl const&) = delete; -    void PushEntry(Entry e) { -        message_queue.Push(std::move(e)); +    void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num, +                   const char* function, std::string message) { +        message_queue.Push( +            CreateEntry(log_class, log_level, filename, line_num, function, std::move(message)));      }      void AddBackend(std::unique_ptr<Backend> backend) { @@ -108,11 +110,30 @@ private:          backend_thread.join();      } +    Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, +                      const char* function, std::string message) const { +        using std::chrono::duration_cast; +        using std::chrono::steady_clock; + +        Entry entry; +        entry.timestamp = +            duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin); +        entry.log_class = log_class; +        entry.log_level = log_level; +        entry.filename = Common::TrimSourcePath(filename); +        entry.line_num = line_nr; +        entry.function = function; +        entry.message = std::move(message); + +        return entry; +    } +      std::mutex writing_mutex;      std::thread backend_thread;      std::vector<std::unique_ptr<Backend>> backends;      Common::MPSCQueue<Log::Entry> message_queue;      Filter filter; +    std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()};  };  void ConsoleBackend::Write(const Entry& entry) { @@ -271,25 +292,6 @@ const char* GetLevelName(Level log_level) {  #undef LVL  } -Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, -                  const char* function, std::string message) { -    using std::chrono::duration_cast; -    using std::chrono::steady_clock; - -    static steady_clock::time_point time_origin = steady_clock::now(); - -    Entry entry; -    entry.timestamp = duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin); -    entry.log_class = log_class; -    entry.log_level = log_level; -    entry.filename = Common::TrimSourcePath(filename); -    entry.line_num = line_nr; -    entry.function = function; -    entry.message = std::move(message); - -    return entry; -} -  void SetGlobalFilter(const Filter& filter) {      Impl::Instance().SetGlobalFilter(filter);  } @@ -314,9 +316,7 @@ void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,      if (!filter.CheckMessage(log_class, log_level))          return; -    Entry entry = -        CreateEntry(log_class, log_level, filename, line_num, function, fmt::vformat(format, args)); - -    instance.PushEntry(std::move(entry)); +    instance.PushEntry(log_class, log_level, filename, line_num, function, +                       fmt::vformat(format, args));  }  } // namespace Log diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index a31ee6968..fca0267a1 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h @@ -135,10 +135,6 @@ const char* GetLogClassName(Class log_class);   */  const char* GetLevelName(Level log_level); -/// Creates a log entry by formatting the given source location, and message. -Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, -                  const char* function, std::string message); -  /**   * The global filter will prevent any messages from even being processed if they are filtered. Each   * backend can have a filter, but if the level is lower than the global filter, the backend will diff --git a/src/common/math_util.h b/src/common/math_util.h index 94b4394c5..cff3d48c5 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h @@ -7,7 +7,7 @@  #include <cstdlib>  #include <type_traits> -namespace MathUtil { +namespace Common {  constexpr float PI = 3.14159265f; @@ -41,4 +41,4 @@ struct Rectangle {      }  }; -} // namespace MathUtil +} // namespace Common diff --git a/src/common/quaternion.h b/src/common/quaternion.h index c528c0b68..370198ae0 100644 --- a/src/common/quaternion.h +++ b/src/common/quaternion.h @@ -6,12 +6,12 @@  #include "common/vector_math.h" -namespace Math { +namespace Common {  template <typename T>  class Quaternion {  public: -    Math::Vec3<T> xyz; +    Vec3<T> xyz;      T w{};      Quaternion<decltype(-T{})> Inverse() const { @@ -38,12 +38,12 @@ public:  };  template <typename T> -auto QuaternionRotate(const Quaternion<T>& q, const Math::Vec3<T>& v) { +auto QuaternionRotate(const Quaternion<T>& q, const Vec3<T>& v) {      return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w);  } -inline Quaternion<float> MakeQuaternion(const Math::Vec3<float>& axis, float angle) { +inline Quaternion<float> MakeQuaternion(const Vec3<float>& axis, float angle) {      return {axis * std::sin(angle / 2), std::cos(angle / 2)};  } -} // namespace Math +} // namespace Common diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 8feb49941..429485329 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -33,7 +33,7 @@  #include <cmath>  #include <type_traits> -namespace Math { +namespace Common {  template <typename T>  class Vec2; @@ -690,4 +690,4 @@ constexpr Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) {      return MakeVec(x, yzw[0], yzw[1], yzw[2]);  } -} // namespace Math +} // namespace Common | 
