StringPrinter.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. #include <utility>
  2. #include "StringPrinter.h"
  3. #include "WallpaperEngine/Data/Model/Wallpaper.h"
  4. using namespace WallpaperEngine::Data::Dumpers;
  5. using namespace WallpaperEngine::Data::Model;
  6. StringPrinter::StringPrinter (std::string indentationCharacter) :
  7. m_out (&this->m_buffer), m_indentationCharacter (std::move (indentationCharacter)) { }
  8. void StringPrinter::printWallpaper (const Wallpaper& wallpaper) {
  9. const bool isScene = wallpaper.is<Scene> ();
  10. const bool isVideo = wallpaper.is<Video> ();
  11. const bool isWeb = wallpaper.is<Web> ();
  12. if (isVideo) {
  13. const auto video = wallpaper.as<Video> ();
  14. this->m_out << "Video wallpaper: " << video->filename;
  15. this->lineEnd ();
  16. } else if (isWeb) {
  17. const auto web = wallpaper.as<Web> ();
  18. this->m_out << "Web wallpaper: " << web->filename;
  19. this->lineEnd ();
  20. } else if (isScene) {
  21. const auto scene = wallpaper.as<Scene> ();
  22. this->m_out << "Scene wallpaper: ";
  23. this->increaseIndentation ();
  24. this->lineEnd ();
  25. // TODO: implement FBO printing, current output doesn't reflect how it actually works
  26. this->m_out << "Objects count: " << scene->objects.size ();
  27. this->increaseIndentation ();
  28. for (const auto& object : scene->objects) {
  29. this->lineEnd ();
  30. this->printObject (*object);
  31. this->lineEnd ();
  32. }
  33. this->decreaseIndentation ();
  34. }
  35. }
  36. void StringPrinter::printObject (const Object& object) {
  37. this->m_out << "Object " << object.id << " " << object.name << ":";
  38. this->increaseIndentation ();
  39. this->lineEnd ();
  40. this->m_out << "Dependencies (" << object.dependencies.size () << "): ";
  41. for (const auto& dependency : object.dependencies) {
  42. this->m_out << dependency << ", ";
  43. }
  44. if (object.is<Image> ()) {
  45. this->lineEnd ();
  46. this->printImage (*object.as<Image> ());
  47. } else if (object.is<Sound> ()) {
  48. this->lineEnd ();
  49. this->printSound (*object.as<Sound> ());
  50. }
  51. this->decreaseIndentation ();
  52. }
  53. void StringPrinter::printImage (const Image& image) {
  54. this->printModel (*image.model);
  55. this->lineEnd ();
  56. this->m_out << "Image effects count: " << image.effects.size ();
  57. this->increaseIndentation ();
  58. for (const auto& effect : image.effects) {
  59. this->lineEnd ();
  60. this->printImageEffect (*effect);
  61. }
  62. this->decreaseIndentation ();
  63. }
  64. void StringPrinter::printSound (const Sound& sound) {
  65. this->m_out << "Sounds: " << sound.sounds.size ();
  66. this->increaseIndentation ();
  67. for (const auto& filename : sound.sounds) {
  68. this->lineEnd ();
  69. this->m_out << "Filename " << filename;
  70. }
  71. this->decreaseIndentation ();
  72. }
  73. void StringPrinter::printModel (const ModelStruct& model) {
  74. this->m_out << "Model " << model.filename << ":";
  75. this->increaseIndentation ();
  76. this->lineEnd ();
  77. this->m_out << "Autosize: " << model.autosize;
  78. this->lineEnd ();
  79. this->m_out << "Passthrough: " << model.passthrough;
  80. this->lineEnd ();
  81. this->m_out << "Fullscreen: " << model.fullscreen;
  82. this->lineEnd ();
  83. this->m_out << "No padding: " << model.nopadding;
  84. this->lineEnd ();
  85. this->m_out << "Solid layer: " << model.solidlayer;
  86. this->lineEnd ();
  87. if (model.width.has_value ()) {
  88. this->m_out << "Width: " << model.width.value ();
  89. this->lineEnd ();
  90. }
  91. if (model.height.has_value ()) {
  92. this->m_out << "Height: " << model.height.value ();
  93. this->lineEnd ();
  94. }
  95. this->printMaterial (*model.material);
  96. this->decreaseIndentation ();
  97. }
  98. void StringPrinter::printImageEffect (const ImageEffect& imageEffect) {
  99. this->m_out << "Image effect " << imageEffect.id << ":";
  100. this->increaseIndentation ();
  101. this->lineEnd ();
  102. this->m_out << "Default visibility status: " << imageEffect.visible->value->getBool ();
  103. this->printEffect (*imageEffect.effect);
  104. this->lineEnd ();
  105. this->m_out << "Effect overrides count: " << imageEffect.passOverrides.size ();
  106. this->increaseIndentation ();
  107. for (const auto& override : imageEffect.passOverrides) {
  108. this->printImageEffectPassOverride (*override);
  109. }
  110. this->decreaseIndentation ();
  111. this->decreaseIndentation ();
  112. }
  113. void StringPrinter::printImageEffectPassOverride (const ImageEffectPassOverride& imageEffectPass) {
  114. this->lineEnd ();
  115. this->m_out << "Pass override " << imageEffectPass.id << ":";
  116. this->increaseIndentation ();
  117. this->lineEnd ();
  118. this->m_out << "Textures count: " << imageEffectPass.textures.size ();
  119. if (!imageEffectPass.textures.empty ()) {
  120. this->increaseIndentation ();
  121. for (const auto& [index, texture] : imageEffectPass.textures) {
  122. this->lineEnd ();
  123. this->m_out << "Texture " << index << ": " << texture;
  124. }
  125. this->decreaseIndentation ();
  126. }
  127. this->lineEnd ();
  128. this->m_out << "Combos count: " << imageEffectPass.combos.size ();
  129. if (!imageEffectPass.combos.empty ()) {
  130. this->increaseIndentation ();
  131. for (const auto& [name, value] : imageEffectPass.combos) {
  132. this->lineEnd ();
  133. this->m_out << "Combo " << name << "=" << value;
  134. }
  135. this->decreaseIndentation ();
  136. }
  137. this->lineEnd ();
  138. this->m_out << "Constants count: " << imageEffectPass.constants.size ();
  139. if (!imageEffectPass.constants.empty ()) {
  140. this->increaseIndentation ();
  141. for (const auto& [name, value] : imageEffectPass.constants) {
  142. this->lineEnd ();
  143. this->m_out << "Constant " << name << "=" << value->value->toString ();
  144. }
  145. this->decreaseIndentation ();
  146. }
  147. this->decreaseIndentation ();
  148. }
  149. void StringPrinter::printEffect (const Effect& effect) {
  150. this->lineEnd ();
  151. this->m_out << "Effect " << effect.name << ":";
  152. this->increaseIndentation ();
  153. if (!effect.description.empty ()) {
  154. this->lineEnd ();
  155. this->m_out << "Description: " << effect.description;
  156. }
  157. if (!effect.dependencies.empty ()) {
  158. this->lineEnd ();
  159. this->m_out << "Dependencies count: " << effect.dependencies.size ();
  160. this->increaseIndentation ();
  161. for (const auto& dependency : effect.dependencies) {
  162. this->lineEnd ();
  163. this->m_out << "Dependency: " << dependency;
  164. }
  165. this->decreaseIndentation ();
  166. }
  167. if (!effect.group.empty ()) {
  168. this->lineEnd ();
  169. this->m_out << "Group: " << effect.group;
  170. }
  171. if (!effect.preview.empty ()) {
  172. this->lineEnd ();
  173. this->m_out << "Preview: " << effect.preview;
  174. }
  175. this->lineEnd ();
  176. this->m_out << "Passes count: " << effect.passes.size ();
  177. this->increaseIndentation ();
  178. int passId = 0;
  179. for (const auto& pass : effect.passes) {
  180. this->lineEnd ();
  181. this->m_out << "Pass " << ++passId << ":";
  182. this->increaseIndentation ();
  183. this->lineEnd ();
  184. this->printEffectPass (*pass);
  185. this->decreaseIndentation ();
  186. }
  187. this->decreaseIndentation ();
  188. this->lineEnd ();
  189. this->m_out << "FBOs count: " << effect.fbos.size ();
  190. this->increaseIndentation ();
  191. for (const auto& fbo : effect.fbos) {
  192. this->lineEnd ();
  193. this->printFBO (*fbo);
  194. }
  195. this->decreaseIndentation ();
  196. this->decreaseIndentation ();
  197. }
  198. void StringPrinter::printEffectPass (const EffectPass& effectPass) {
  199. if (effectPass.command.has_value ()) {
  200. this->m_out << "Command: " << (*effectPass.command == Command_Copy ? "copy" : "swap");
  201. if (effectPass.target.has_value () || effectPass.source.has_value ()) {
  202. this->lineEnd ();
  203. }
  204. }
  205. if (effectPass.target.has_value ()) {
  206. this->m_out << "Target: " << effectPass.target.value ();
  207. if (effectPass.source.has_value ()) {
  208. this->lineEnd ();
  209. }
  210. }
  211. if (effectPass.source.has_value ()) {
  212. this->m_out << "Source: " << effectPass.source.value ();
  213. }
  214. if (!effectPass.binds.empty ()) {
  215. if (effectPass.target.has_value ()) {
  216. this->lineEnd ();
  217. }
  218. this->m_out << "Binds count: " << effectPass.binds.size ();
  219. this->increaseIndentation ();
  220. for (const auto& [index, target] : effectPass.binds) {
  221. this->lineEnd ();
  222. this->m_out << "Bind " << index << ": " << target;
  223. }
  224. this->decreaseIndentation ();
  225. }
  226. if (effectPass.target.has_value () || !effectPass.binds.empty ()) {
  227. this->lineEnd ();
  228. }
  229. if (effectPass.material.has_value ()) {
  230. this->printMaterial (**effectPass.material);
  231. }
  232. }
  233. void StringPrinter::printFBO (const FBO& fbo) {
  234. this->m_out << "FBO " << fbo.name << ":";
  235. this->increaseIndentation ();
  236. this->lineEnd ();
  237. this->m_out << "Format: " << fbo.format;
  238. this->lineEnd ();
  239. this->m_out << "Scale: " << fbo.scale;
  240. this->decreaseIndentation ();
  241. }
  242. void StringPrinter::printMaterial (const Material& material) {
  243. this->m_out << "Material " << material.filename << ":";
  244. this->increaseIndentation ();
  245. this->lineEnd ();
  246. this->m_out << "Passes count: " << material.passes.size ();
  247. this->increaseIndentation ();
  248. for (const auto& pass : material.passes) {
  249. this->lineEnd ();
  250. this->printMaterialPass (*pass);
  251. }
  252. this->decreaseIndentation ();
  253. this->decreaseIndentation ();
  254. }
  255. void StringPrinter::printMaterialPass (const MaterialPass& materialPass) {
  256. this->m_out << "Pass " << materialPass.shader << ":";
  257. this->increaseIndentation ();
  258. this->lineEnd ();
  259. this->m_out << "Depth test: " << materialPass.depthtest;
  260. this->lineEnd ();
  261. this->m_out << "Depth write: " << materialPass.depthwrite;
  262. this->lineEnd ();
  263. this->m_out << "Blend mode: " << materialPass.blending;
  264. this->lineEnd ();
  265. this->m_out << "Culling mode: " << materialPass.cullmode;
  266. if (!materialPass.textures.empty ()) {
  267. this->lineEnd ();
  268. this->m_out << "Textures count: " << materialPass.textures.size ();
  269. this->increaseIndentation ();
  270. for (const auto& [index, texture] : materialPass.textures) {
  271. this->lineEnd ();
  272. this->m_out << "Texture " << index << ": " << texture;
  273. }
  274. this->decreaseIndentation ();
  275. }
  276. if (!materialPass.combos.empty ()) {
  277. this->lineEnd ();
  278. this->m_out << "Combos count: " << materialPass.combos.size ();
  279. this->increaseIndentation ();
  280. for (const auto& [name, value] : materialPass.combos) {
  281. this->lineEnd ();
  282. this->m_out << "Combo " << name << ": " << value;
  283. }
  284. this->decreaseIndentation ();
  285. }
  286. this->decreaseIndentation ();
  287. }
  288. void StringPrinter::indentation () {
  289. for (int i = 0; i < this->m_level; i++) {
  290. this->m_out << this->m_indentationCharacter;
  291. }
  292. }
  293. void StringPrinter::lineEnd () {
  294. this->m_out << "\n";
  295. this->indentation ();
  296. }
  297. void StringPrinter::increaseIndentation () { this->m_level++; }
  298. void StringPrinter::decreaseIndentation () { this->m_level--; }
  299. std::string StringPrinter::str () const { return this->m_buffer.str (); }