Debian Codegraph @

d2x-rebirth/libmve/mvelib.h

raw
1 /*
2 * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3 * It is copyright by its individual contributors, as recorded in the
4 * project's Git history. See COPYING.txt at the top level for license
5 * terms and a link to the Git history.
6 */
7
8 #pragma once
9
10 #include <stdio.h>
11 #include <stdlib.h>
12
13 #include "libmve.h"
14
15 #include <array>
16 #include <cstdint>
17 #include <span>
18 #include <vector>
19 #include "dxxsconf.h"
20 #include <SDL.h>
21 #include "d_uspan.h"
22 #include "physfsrwops.h"
23
24 namespace d2x {
25
26 enum class mve_opcode : uint8_t
27 {
28 endofstream = 0x00,
29 endofchunk = 0x01,
30 createtimer = 0x02,
31 initaudiobuffers = 0x03,
32 startstopaudio = 0x04,
33 initvideobuffers = 0x05,
34
35 displayvideo = 0x07,
36 audioframedata = 0x08,
37 audioframesilence = 0x09,
38 initvideomode = 0x0A,
39
40 setpalette = 0x0C,
41 /* setpalettecompressed = 0x0D, // unused */
42
43 setdecodingmap = 0x0F,
44
45 videodata = 0x11,
46 None = 0xff,
47 };
48
49 /*
50 * structure for maintaining info on a MVEFILE stream
51 */
52 struct MVEFILE
53 {
54 MVEFILE() = default;
55 MVEFILE(RWops_ptr);
56 MVEFILE(MVEFILE &&) = default;
57 MVEFILE &operator=(MVEFILE &&) = default;
58 ~MVEFILE();
59 RWops_ptr stream{};
60 std::vector<uint8_t> cur_chunk;
61 std::size_t next_segment = 0;
62 };
63
64 /*
65 * get size of next segment in chunk (-1 if no more segments in chunk)
66 */
67 int_fast32_t mvefile_get_next_segment_size(const MVEFILE *movie);
68
69 /*
70 * get type of next segment in chunk (0xff if no more segments in chunk)
71 */
72 mve_opcode mvefile_get_next_segment_major(const MVEFILE *movie);
73
74 /*
75 * get subtype (version) of next segment in chunk (0xff if no more segments in
76 * chunk)
77 */
78 unsigned char mvefile_get_next_segment_minor(const MVEFILE *movie);
79
80 /*
81 * see next segment (return NULL if no next segment)
82 */
83 const unsigned char *mvefile_get_next_segment(const MVEFILE *movie);
84
85 /*
86 * advance to next segment
87 */
88 void mvefile_advance_segment(MVEFILE *movie);
89
90 /*
91 * fetch the next chunk (return 0 if at end of stream)
92 */
93 int mvefile_fetch_next_chunk(MVEFILE *movie);
94
95 /*
96 * callback for segment type
97 */
98 typedef int (*MVESEGMENTHANDLER)(mve_opcode major, unsigned char minor, const unsigned char *data, int len, void *context);
99
100 /*
101 * structure for maintaining an MVE stream
102 */
103 struct MVESTREAM
104 {
105 enum class handle_result : bool
106 {
107 step_finished,
108 step_again,
109 };
110 MVESTREAM(MVE_play_sounds, int x, int y);
111 ~MVESTREAM();
112 std::unique_ptr<MVEFILE> movie;
113 std::span<const uint8_t> pCurMap{};
114 std::vector<unsigned char> vBuffers{};
115 std::unique_ptr<SDL_AudioSpec> mve_audio_spec;
116 const MVE_play_sounds mve_audio_enabled;
117 bool mve_audio_playing{};
118 uint8_t timer_created{};
119 uint8_t truecolor{};
120 uint8_t videobuf_created{};
121 uint8_t video_initialized{};
122 uint8_t frameUpdated{};
123 uint8_t mve_audio_flags{};
124 uint16_t screenWidth{};
125 uint16_t screenHeight{};
126 const int destX;
127 const int destY;
128 int width{};
129 int height{};
130 int mve_audio_bufhead{};
131 int mve_audio_buftail{};
132 int mve_audio_curbuf_curpos{};
133 unsigned char *vBackBuf1{};
134 unsigned char *vBackBuf2{};
135 std::array<::dcx::unique_span<int16_t>, 64> mve_audio_buffers;
136
137 handle_result handle_mve_segment_endofstream();
138 handle_result handle_mve_segment_endofchunk();
139 handle_result handle_mve_segment_createtimer(const unsigned char *data);
140 handle_result handle_mve_segment_initaudiobuffers(unsigned char minor, const unsigned char *data);
141 handle_result handle_mve_segment_startstopaudio();
142 handle_result handle_mve_segment_initvideobuffers(unsigned char minor, const unsigned char *data);
143 handle_result handle_mve_segment_displayvideo();
144 handle_result handle_mve_segment_audioframedata(mve_opcode major, const unsigned char *data);
145 handle_result handle_mve_segment_initvideomode(const unsigned char *data);
146 handle_result handle_mve_segment_setpalette(const unsigned char *data);
147 handle_result handle_mve_segment_setdecodingmap(const unsigned char *data, int len);
148 handle_result handle_mve_segment_videodata(const unsigned char *data, int len);
149 };
150
151 struct MVESTREAM_deleter_t
152 {
153 void operator()(MVESTREAM *p) const
154 {
155 MVE_rmEndMovie(std::unique_ptr<MVESTREAM>(p));
156 }
157 };
158
159 typedef std::unique_ptr<MVESTREAM, MVESTREAM_deleter_t> MVESTREAM_ptr_t;
160 MVESTREAM_ptr_t MVE_rmPrepMovie(MVE_play_sounds, int x, int y, RWops_ptr stream);
161
162 /*
163 * open an MVE stream
164 */
165 MVESTREAM_ptr_t mve_open(MVE_play_sounds audio_enabled, int x, int y, RWops_ptr stream);
166
167 /*
168 * reset an MVE stream
169 */
170 void mve_reset(MVESTREAM *movie);
171
172 /*
173 * play next chunk
174 */
175 MVESTREAM::handle_result mve_play_next_chunk(MVESTREAM &movie);
176
177 unsigned MovieFileRead(SDL_RWops *handle, std::span<uint8_t> buf);
178
179 }