111 lines
2.1 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstring>
  14. #if defined USE_PIPI
  15. # include <pipi.h>
  16. #endif
  17. #include <lol/main.h>
  18. #include "loldebug.h"
  19. using namespace std;
  20. namespace lol
  21. {
  22. /*
  23. * DebugRecord implementation class
  24. */
  25. class DebugRecordData
  26. {
  27. friend class DebugRecord;
  28. private:
  29. String m_path;
  30. ivec2 m_size;
  31. int m_fps;
  32. #if defined USE_PIPI
  33. pipi_sequence_t *m_sequence;
  34. #endif
  35. };
  36. /*
  37. * Public DebugRecord class
  38. */
  39. DebugRecord::DebugRecord(String const &path, float fps)
  40. : m_data(new DebugRecordData())
  41. {
  42. Ticker::StartRecording();
  43. m_data->m_path = path;
  44. m_data->m_size = ivec2::zero;
  45. m_data->m_fps = (int)(fps + 0.5f);
  46. #if defined USE_PIPI
  47. m_data->m_sequence = nullptr;
  48. #endif
  49. m_drawgroup = DRAWGROUP_CAPTURE;
  50. }
  51. void DebugRecord::TickGame(float seconds)
  52. {
  53. Entity::TickGame(seconds);
  54. }
  55. void DebugRecord::TickDraw(float seconds, Scene &scene)
  56. {
  57. Entity::TickDraw(seconds, scene);
  58. ivec2 size = Video::GetSize();
  59. if (m_data->m_size != size)
  60. {
  61. m_data->m_size = size;
  62. #if defined USE_PIPI
  63. if (m_data->m_sequence)
  64. pipi_close_sequence(m_data->m_sequence);
  65. m_data->m_sequence = pipi_open_sequence(m_data->m_path, size.x, size.y,
  66. 1 /* RGB */, m_data->m_fps,
  67. 1, 1, 60 * 1024 * 1024);
  68. #endif
  69. }
  70. #if defined USE_PIPI
  71. if (m_data->m_sequence)
  72. {
  73. uint32_t *buffer = new uint32_t[size.x * size.y];
  74. Video::Capture(buffer);
  75. pipi_feed_sequence(m_data->m_sequence, (uint8_t *)buffer,
  76. size.x, size.y);
  77. delete[] buffer;
  78. }
  79. #endif
  80. }
  81. DebugRecord::~DebugRecord()
  82. {
  83. Ticker::StopRecording();
  84. delete m_data;
  85. }
  86. } /* namespace lol */