BsDebug.h 1.9 KB

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