BsDebug.h 3.2 KB

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