BsDebug.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #pragma once
  2. #include "BsPrerequisitesUtil.h"
  3. #include "BsLog.h"
  4. namespace BansheeEngine
  5. {
  6. class Log;
  7. /** @addtogroup Debug
  8. * @{
  9. */
  10. /** Available types of channels that debug messages can be logged to. */
  11. enum class DebugChannel
  12. {
  13. Debug, Warning, Error, CompilerWarning, CompilerError
  14. };
  15. /**
  16. * @brief Utility class providing various debug functionality.
  17. *
  18. * @note Thread safe.
  19. */
  20. class BS_UTILITY_EXPORT Debug
  21. {
  22. public:
  23. /** Adds a log entry in the "Debug" channel. */
  24. void logDebug(const String& msg);
  25. /** Adds a log entry in the "Warning" channel. */
  26. void logWarning(const String& msg);
  27. /** Adds a log entry in the "Error" channel. */
  28. void logError(const String& msg);
  29. /** Adds a log entry in the specified channel. You may specify custom channels as needed. */
  30. void log(const String& msg, UINT32 channel);
  31. /** Retrieves the Log used by the Debug instance. */
  32. Log& getLog() { return mLog; }
  33. /** Converts raw pixels into a BMP image. See BitmapWriter for more information. */
  34. void writeAsBMP(UINT8* rawPixels, UINT32 bytesPerPixel, UINT32 width, UINT32 height, const Path& filePath, bool overwrite = true) const;
  35. /**
  36. * Saves a log about the current state of the application to the specified location.
  37. *
  38. * @param path Absolute path to the log filename.
  39. */
  40. void saveLog(const Path& path) const;
  41. /**
  42. * @brief Triggered when a new entry in the log is added.
  43. *
  44. * @note Sim thread only.
  45. */
  46. Event<void(const LogEntry&)> onLogEntryAdded;
  47. /**
  48. * @brief Triggered whenever one or multiple log entries were added or removed.
  49. * Triggers only once per frame.
  50. *
  51. * @note Sim thread only.
  52. */
  53. Event<void()> onLogModified;
  54. /** @cond INTERNAL */
  55. /**
  56. * Triggers callbacks that notify external code that a log entry was added.
  57. *
  58. * @note Internal method. Sim thread only.
  59. */
  60. void _triggerCallbacks();
  61. /** @endcond */
  62. private:
  63. UINT64 mLogHash = 0;
  64. Log mLog;
  65. };
  66. /** A simpler way of accessing the Debug module. */
  67. BS_UTILITY_EXPORT Debug& gDebug();
  68. /** Shortcut for logging a message in the debug channel. */
  69. #define LOGDBG(x) BansheeEngine::gDebug().logDebug((x));
  70. /** Shortcut for logging a message in the warning channel. */
  71. #define LOGWRN(x) BansheeEngine::gDebug().logWarning((x));
  72. /** Shortcut for logging a message in the error channel. */
  73. #define LOGERR(x) BansheeEngine::gDebug().logError((x));
  74. /** Shortcut for logging a verbose message in the debug channel. Verbose messages can be ignored unlike other log messages. */
  75. #define LOGDBG_VERBOSE(x)
  76. /** Shortcut for logging a verbose message in the warning channel. Verbose messages can be ignored unlike other log messages. */
  77. #define LOGWRN_VERBOSE(x)
  78. /** @} */
  79. }