87 lines
1.5 KiB

  1. //
  2. // Deus Hax (working title)
  3. // Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
  4. //
  5. #if defined HAVE_CONFIG_H
  6. # include "config.h"
  7. #endif
  8. #include <cstdio>
  9. #include <cstring>
  10. #include <pipi.h>
  11. #include "debugrecord.h"
  12. #include "video.h"
  13. /*
  14. * DebugRecord implementation class
  15. */
  16. class DebugRecordData
  17. {
  18. friend class DebugRecord;
  19. private:
  20. char const *path;
  21. int width, height;
  22. pipi_sequence_t *sequence;
  23. };
  24. /*
  25. * Public DebugRecord class
  26. */
  27. DebugRecord::DebugRecord(char const *path)
  28. {
  29. data = new DebugRecordData();
  30. data->path = strdup(path);
  31. data->width = 0;
  32. data->height = 0;
  33. data->sequence = NULL;
  34. }
  35. Entity::Group DebugRecord::GetGroup()
  36. {
  37. return GROUP_RENDER_CAPTURE;
  38. }
  39. void DebugRecord::TickGame(float delta_time)
  40. {
  41. Entity::TickGame(delta_time);
  42. }
  43. void DebugRecord::TickRender(float delta_time)
  44. {
  45. Entity::TickRender(delta_time);
  46. int width = Video::GetWidth();
  47. int height = Video::GetHeight();
  48. if (data->width != width || data->height != height)
  49. {
  50. data->width = width;
  51. data->height = height;
  52. if (data->sequence)
  53. pipi_close_sequence(data->sequence);
  54. data->sequence = pipi_open_sequence(data->path, width, height, 30);
  55. }
  56. if (data->sequence)
  57. {
  58. uint32_t *buffer = new uint32_t[width * height];
  59. Video::Capture(buffer);
  60. pipi_feed_sequence(data->sequence, (uint8_t *)buffer, width, height);
  61. delete[] buffer;
  62. }
  63. }
  64. DebugRecord::~DebugRecord()
  65. {
  66. delete data;
  67. }