BsDebug.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. * 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. See BitmapWriter for more information. */
  37. void writeAsBMP(UINT8* rawPixels, UINT32 bytesPerPixel, UINT32 width, UINT32 height, const Path& filePath, bool overwrite = true) const;
  38. /**
  39. * Saves a log about the current state of the application to the specified location.
  40. *
  41. * @param path Absolute path to the log filename.
  42. */
  43. void saveLog(const Path& path) const;
  44. /**
  45. * Triggered when a new entry in the log is added.
  46. *
  47. * @note Sim thread only.
  48. */
  49. Event<void(const LogEntry&)> onLogEntryAdded;
  50. /**
  51. * Triggered whenever one or multiple log entries were added or removed. Triggers only once per frame.
  52. *
  53. * @note Sim thread only.
  54. */
  55. Event<void()> onLogModified;
  56. public: // ***** INTERNAL ******
  57. /** @name Internal
  58. * @{
  59. */
  60. /**
  61. * Triggers callbacks that notify external code that a log entry was added.
  62. *
  63. * @note Internal method. Sim thread only.
  64. */
  65. void _triggerCallbacks();
  66. /** @} */
  67. private:
  68. UINT64 mLogHash = 0;
  69. Log mLog;
  70. };
  71. /** A simpler way of accessing the Debug module. */
  72. BS_UTILITY_EXPORT Debug& gDebug();
  73. /** Shortcut for logging a message in the debug channel. */
  74. #define LOGDBG(x) BansheeEngine::gDebug().logDebug((x));
  75. /** Shortcut for logging a message in the warning channel. */
  76. #define LOGWRN(x) BansheeEngine::gDebug().logWarning((x));
  77. /** Shortcut for logging a message in the error channel. */
  78. #define LOGERR(x) BansheeEngine::gDebug().logError((x));
  79. /** Shortcut for logging a verbose message in the debug channel. Verbose messages can be ignored unlike other log messages. */
  80. #define LOGDBG_VERBOSE(x)
  81. /** Shortcut for logging a verbose message in the warning channel. Verbose messages can be ignored unlike other log messages. */
  82. #define LOGWRN_VERBOSE(x)
  83. /** @} */
  84. }