source: trunk/src/debugrecord.cpp @ 664

Last change on this file since 664 was 619, checked in by sam, 10 years ago

Add a recording mode to Ticker that ensures fixed deltatime even when
lagging behind.

  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
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
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdio>
16#include <cstring>
17
18#if defined USE_PIPI
19#   include <pipi.h>
20#endif
21
22#include "core.h"
23#include "debugrecord.h"
24
25/*
26 * DebugRecord implementation class
27 */
28
29class DebugRecordData
30{
31    friend class DebugRecord;
32
33private:
34    char const *path;
35    int width, height, fps;
36#if defined USE_PIPI
37    pipi_sequence_t *sequence;
38#endif
39};
40
41/*
42 * Public DebugRecord class
43 */
44
45DebugRecord::DebugRecord(char const *path, float fps)
46  : data(new DebugRecordData())
47{
48    Ticker::StartRecording();
49
50    data->path = strdup(path);
51    data->width = 0;
52    data->height = 0;
53    data->fps = (int)(fps + 0.5f);
54#if defined USE_PIPI
55    data->sequence = NULL;
56#endif
57
58    drawgroup = DRAWGROUP_CAPTURE;
59}
60
61void DebugRecord::TickGame(float deltams)
62{
63    Entity::TickGame(deltams);
64}
65
66void DebugRecord::TickDraw(float deltams)
67{
68    Entity::TickDraw(deltams);
69
70    int width = Video::GetWidth();
71    int height = Video::GetHeight();
72
73    if (data->width != width || data->height != height)
74    {
75        data->width = width;
76        data->height = height;
77
78#if defined USE_PIPI
79        if (data->sequence)
80            pipi_close_sequence(data->sequence);
81
82        data->sequence = pipi_open_sequence(data->path, width, height,
83                                            1 /* RGB */, data->fps,
84                                            1, 1, 60 * 1024 * 1024);
85#endif
86    }
87
88#if defined USE_PIPI
89    if (data->sequence)
90    {
91        uint32_t *buffer = new uint32_t[width * height];
92        Video::Capture(buffer);
93        pipi_feed_sequence(data->sequence, (uint8_t *)buffer, width, height);
94        delete[] buffer;
95    }
96#endif
97}
98
99DebugRecord::~DebugRecord()
100{
101    Ticker::StopRecording();
102
103    delete data;
104}
Note: See TracBrowser for help on using the repository browser.