BsDebug.h 3.0 KB

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