OpenXcom  1.0
Open-source clone of the original X-Com
FlcPlayer.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #pragma once
22 /*
23  * Based on http://www.libsdl.org/projects/flxplay/
24  */
25 #include <SDL.h>
26 
27 namespace OpenXcom
28 {
29 
30 class Screen;
31 class Game;
32 
33 class FlcPlayer
34 {
35 private:
36 
37  Uint8 *_fileBuf;
38  Uint32 _fileSize;
39  Uint8 *_videoFrameData;
40  Uint8 *_chunkData;
41  Uint8 *_audioFrameData;
42  Uint16 _frameCount; /* Frame Counter */
43  Uint32 _headerSize; /* Fli file size */
44  Uint16 _headerType; /* Fli header check */
45  Uint16 _headerFrames; /* Number of frames in flic */
46  Uint16 _headerWidth; /* Fli width */
47  Uint16 _headerHeight; /* Fli heigth */
48  Uint16 _headerDepth; /* Color depth */
49  Uint16 _headerSpeed; /* Number of video ticks between frame */
50  Uint32 _videoFrameSize; /* Frame size in bytes */
51  Uint16 _videoFrameType;
52  Uint16 _frameChunks; /* Number of chunks in frame */
53  Uint32 _chunkSize; /* Size of chunk */
54  Uint16 _chunkType; /* Type of chunk */
55  Uint16 _delayOverride; /* FRAME_TYPE extension */
56  Uint32 _audioFrameSize;
57  Uint16 _audioFrameType;
58 
59  void (*_frameCallBack)();
60 
61  SDL_Surface *_mainScreen;
62  Screen *_realScreen;
63  SDL_Color _colors[256];
64  int _screenWidth;
65  int _screenHeight;
66  int _screenDepth;
67  int _dx, _dy;
68  int _offset;
69  int _playingState;
70  bool _hasAudio, _useInternalAudio;
71  int _videoDelay;
72  double _volume;
73 
74  typedef struct AudioBuffer
75  {
76  Sint16 *samples;
77  int sampleCount;
78  int sampleBufSize;
79  int currSamplePos;
80  }AudioBuffer;
81 
82 
83  typedef struct AudioData
84  {
85  int sampleRate;
86  AudioBuffer *loadingBuffer;
87  AudioBuffer *playingBuffer;
88  SDL_sem *sharedLock;
89 
90  }AudioData;
91 
92  AudioData _audioData;
93 
94  Game *_game;
95 
96  void readU16(Uint16 &dst, const Uint8 *const src);
97  void readU32(Uint32 &dst, const Uint8 *const src);
98  void readS16(Sint16 &dst, const Sint8 *const src);
99  void readS32(Sint32 &dst, const Sint8 *const src);
100  void readFileHeader();
101 
102  bool isValidFrame(Uint8 *frameHeader, Uint32 &frameSize, Uint16 &frameType);
103  void decodeVideo(bool skipLastFrame);
104  void decodeAudio(int frames);
105  void waitForNextFrame(Uint32 delay);
106  void SDLPolling();
107  bool shouldQuit();
108 
109  void playVideoFrame();
110  void color256();
111  void fliBRun();
112  void fliCopy();
113  void fliSS2();
114  void fliLC();
115  void color64();
116  void black();
117 
118  void playAudioFrame(Uint16 sampleRate);
119  void initAudio(Uint16 format, Uint8 channels);
120  void deInitAudio();
121 
122  bool isEndOfFile(Uint8 *pos);
123 
124  static void audioCallback(void *userData, Uint8 *stream, int len);
125 
126 public:
127 
128  FlcPlayer();
129  ~FlcPlayer();
130 
132  bool init(const char *filename, void(*frameCallBack)(), Game *game, bool useAudio, int dx, int dy);
134  void play(bool skipLastFrame);
136  void deInit();
137  // Stop FLC Player
138  void stop();
140  void delay(Uint32 milliseconds);
141  void setHeaderSpeed(int speed);
142  int getFrameCount();
143  bool wasSkipped();
144 };
145 
146 }
void deInit()
Free memory, free love, etc.
Definition: FlcPlayer.cpp:173
void play(bool skipLastFrame)
Play the loaded file; set flc.mainScreen first!
Definition: FlcPlayer.cpp:192
Definition: FlcPlayer.h:33
void delay(Uint32 milliseconds)
Delay player at the end.
Definition: FlcPlayer.cpp:221
bool init(const char *filename, void(*frameCallBack)(), Game *game, bool useAudio, int dx, int dy)
Open FLC or FLI file, read header, prepare to play it.
Definition: FlcPlayer.cpp:100
The core of the game engine, manages the game&#39;s entire contents and structure.
Definition: Game.h:41
A display screen, handles rendering onto the game window.
Definition: Screen.h:38
Definition: BaseInfoState.cpp:40