Debian Codegraph @

Descent3/cinematics.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "cinematics.h"
20 #include "d3movie.h"
21 #include "game.h"
22 #include "ddio.h"
23 #include "descent.h"
24 #include "gamefont.h"
25 #include "hlsoundlib.h"
26 #include "subtitles.h"
27 #include "dedicated_server.h"
28 #include "appdatabase.h"
29 #include "bitmap.h"
30
31 #include <cstring>
32
33 static bool Cinematic_lib_init = false;
34 static int Cinematic_x = 0, Cinematic_y = 0, Cinematic_w = 0, Cinematic_h = 0;
35
36 static void CinematicCallback(int mve_x, int mve_y, int frame_num);
37
38 ///////////////////////////////////////////////////////////////////////////////
39 // functions
40
41 bool InitCinematics() {
42 if (Dedicated_server) {
43 Cinematic_lib_init = false;
44 return true;
45 }
46
47 char path[_MAX_PATH];
48 ddio_MakePath(path, Base_directory, "movies", NULL);
49
50 if (mve_Init(path, Sound_card_name) != MVELIB_NOERROR)
51 return false;
52
53 mve_SetCallback(CinematicCallback);
54
55 Cinematic_lib_init = true;
56
57 return true;
58 }
59
60 void SetMovieProperties(int x, int y, int w, int h, renderer_type type) {
61 const bool kHiColorEnabled = true;
62 Cinematic_x = x;
63 Cinematic_y = y;
64 Cinematic_w = w;
65 Cinematic_h = h;
66 mve_SetRenderProperties(x, y, w, h, type, kHiColorEnabled);
67 }
68
69 bool PlayMovie(const std::filesystem::path &moviename) {
70 if (!Cinematic_lib_init)
71 return false;
72
73 // get in the right directory
74 std::filesystem::path filename = moviename;
75 // check extension
76 std::filesystem::path extension = moviename.extension();
77 if (stricmp(extension.u8string().c_str(), ".mve") != 0 && stricmp(extension.u8string().c_str(), ".mv8") != 0) {
78 // we need an extension
79 filename.replace_extension(extension.u8string() + ".mve");
80 }
81
82 // Initializes the subtitles for a given movie file
83 SubtInitSubtitles(moviename);
84
85 SetMovieProperties(0, 0, Max_window_w, Max_window_h, Renderer_type);
86
87 int mveerr = mve_PlayMovie(filename, Descent);
88
89 // Shutdown the subtitle system
90 SubtCloseSubtitles();
91
92 bool retval = true;
93 if (mveerr != MVELIB_NOERROR) {
94 mprintf(1, "Movie error %d.\n", mveerr);
95 retval = false;
96 }
97
98 return retval;
99 }
100
101 tCinematic *StartMovie(const char *moviename, bool looping) {
102 if (!Cinematic_lib_init)
103 return NULL;
104
105 // get in the right directory
106 char filename[_MAX_PATH];
107 strncpy(filename, moviename, sizeof(filename) - 1);
108 filename[sizeof(filename) - 1] = 0;
109
110 // check extension
111 const char *extension = strrchr(filename, '.');
112 if (extension == NULL || (stricmp(extension, ".mve") != 0 && stricmp(extension, ".mv8") != 0)) {
113 // we need an extension
114 strncat(filename, ".mve", sizeof(filename) - strlen(filename) - 1);
115 filename[sizeof(filename) - 1] = 0;
116 }
117
118 SetMovieProperties(0, 0, Max_window_w, Max_window_h, Renderer_type);
119
120 FILE *filehandle;
121 intptr_t hMovie = mve_SequenceStart(filename, &filehandle, Descent, looping);
122 if (hMovie == 0)
123 return NULL;
124
125 tCinematic *mve = new tCinematic;
126 mve->mvehandle = hMovie;
127 mve->filehandle = filehandle;
128 mve->frame_chunk.bm_array = NULL;
129 return mve;
130 }
131
132 bool FrameMovie(tCinematic *mve, int x, int y, bool sequence) {
133 if (!Cinematic_lib_init || mve == NULL)
134 return false;
135
136 int bm_handle;
137 intptr_t hNewMovie = mve_SequenceFrame(mve->mvehandle, mve->filehandle, sequence, &bm_handle);
138 if (hNewMovie != -1) {
139 // we must have looped, we have a new handle
140 mve->mvehandle = hNewMovie;
141 }
142
143 // do chunk conversion and blt if absolutely necessary.
144 if (bm_handle > -1) {
145 if (x == -1) {
146 x = (Cinematic_w - bm_w(bm_handle, 0)) / 2;
147 }
148
149 if (y == -1) {
150 y = (Cinematic_h - bm_h(bm_handle, 0)) / 2;
151 }
152
153 rend_SetAlphaType(AT_ALWAYS);
154 rend_CopyBitmapToFramebuffer(bm_handle, x, y);
155 }
156
157 return (hNewMovie != -1);
158 }
159
160 void EndMovie(tCinematic *mve) {
161 if (mve == NULL || !Cinematic_lib_init)
162 return;
163
164 mve_SequenceClose(mve->mvehandle, mve->filehandle);
165
166 if (mve->frame_chunk.bm_array) {
167 bm_DestroyChunkedBitmap(&mve->frame_chunk);
168 }
169
170 delete mve;
171 }
172
173 void CinematicCallback(int mveX, int mveY, int frameNum) { SubtDrawSubtitles(frameNum); }