108 lines
2.0 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2011 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://sam.zoy.org/projects/COPYING.WTFPL 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 "core.h"
  18. #include "debugrecord.h"
  19. namespace lol
  20. {
  21. /*
  22. * DebugRecord implementation class
  23. */
  24. class DebugRecordData
  25. {
  26. friend class DebugRecord;
  27. private:
  28. char const *path;
  29. vec2i size;
  30. int fps;
  31. #if defined USE_PIPI
  32. pipi_sequence_t *sequence;
  33. #endif
  34. };
  35. /*
  36. * Public DebugRecord class
  37. */
  38. DebugRecord::DebugRecord(char const *path, float fps)
  39. : data(new DebugRecordData())
  40. {
  41. Ticker::StartRecording();
  42. data->path = strdup(path);
  43. data->size = 0;
  44. data->fps = (int)(fps + 0.5f);
  45. #if defined USE_PIPI
  46. data->sequence = NULL;
  47. #endif
  48. drawgroup = DRAWGROUP_CAPTURE;
  49. }
  50. void DebugRecord::TickGame(float deltams)
  51. {
  52. Entity::TickGame(deltams);
  53. }
  54. void DebugRecord::TickDraw(float deltams)
  55. {
  56. Entity::TickDraw(deltams);
  57. vec2i size = Video::GetSize();
  58. if (data->size != size)
  59. {
  60. data->size = size;
  61. #if defined USE_PIPI
  62. if (data->sequence)
  63. pipi_close_sequence(data->sequence);
  64. data->sequence = pipi_open_sequence(data->path, size.x, size.y,
  65. 1 /* RGB */, data->fps,
  66. 1, 1, 60 * 1024 * 1024);
  67. #endif
  68. }
  69. #if defined USE_PIPI
  70. if (data->sequence)
  71. {
  72. uint32_t *buffer = new uint32_t[size.x * size.y];
  73. Video::Capture(buffer);
  74. pipi_feed_sequence(data->sequence, (uint8_t *)buffer, size.x, size.y);
  75. delete[] buffer;
  76. }
  77. #endif
  78. }
  79. DebugRecord::~DebugRecord()
  80. {
  81. Ticker::StopRecording();
  82. delete data;
  83. }
  84. } /* namespace lol */