VisualLogger.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * VisualLogger.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../int3.h"
  12. #include "../constants/EntityIdentifiers.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class ILogVisualizer
  15. {
  16. public:
  17. virtual void drawLine(int3 start, int3 end) = 0;
  18. };
  19. class IVisualLogBuilder
  20. {
  21. public:
  22. virtual void addLine(int3 start, int3 end) = 0;
  23. };
  24. /// The logger is used to show screen overlay
  25. class DLL_LINKAGE VisualLogger
  26. {
  27. private:
  28. struct MapLine
  29. {
  30. int3 start;
  31. int3 end;
  32. MapLine(int3 start, int3 end)
  33. :start(start), end(end)
  34. {
  35. }
  36. };
  37. class VisualLogBuilder : public IVisualLogBuilder
  38. {
  39. private:
  40. std::vector<MapLine> & mapLines;
  41. public:
  42. VisualLogBuilder(std::vector<MapLine> & mapLines)
  43. :mapLines(mapLines)
  44. {
  45. }
  46. virtual void addLine(int3 start, int3 end) override
  47. {
  48. mapLines.push_back(MapLine(start, end));
  49. }
  50. };
  51. private:
  52. std::map<std::string, std::vector<MapLine>> mapLines;
  53. std::mutex mutex;
  54. std::string keyToShow;
  55. public:
  56. void updateWithLock(std::string channel, std::function<void(IVisualLogBuilder & logBuilder)> func);
  57. void visualize(ILogVisualizer & visulizer);
  58. void setKey(std::string key);
  59. };
  60. extern DLL_LINKAGE VisualLogger * logVisual;
  61. VCMI_LIB_NAMESPACE_END