| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file jj1scene.h |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created scene.c |
| 10 | * - 3rd February 2009: Created scene.h from parts of scene.c |
| 11 | * - 1st August 2012: Renamed scene.h to jj1scene.h |
| 12 | * |
| 13 | * @par Licence: |
| 14 | * Copyright (c) 2005-2017 AJ Thomson |
| 15 | * Copyright (c) 2015-2024 Carsten Teibes |
| 16 | * |
| 17 | * OpenJazz is distributed under the terms of |
| 18 | * the GNU General Public License, version 2.0 |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | #ifndef _SCENE_H |
| 24 | #define _SCENE_H |
| 25 | |
| 26 | #include "io/file.h" |
| 27 | #include "types.h" |
| 28 | #include <list> |
| 29 | #include <vector> |
| 30 | |
| 31 | // Enums |
| 32 | |
| 33 | #define MAKE_0SC_HEADER(BEG, END) (BEG | END << 8) |
| 34 | |
| 35 | /// Cutscene file animation headers |
| 36 | enum ANIHeaders { |
| 37 | EAniHeader = MAKE_0SC_HEADER('A', 'N'), |
| 38 | E11AniHeader = MAKE_0SC_HEADER('1', '1'), ///< Background/start image |
| 39 | E1LAniHeader = MAKE_0SC_HEADER('1', 'L'), |
| 40 | E00AniHeader = MAKE_0SC_HEADER(0, 0), |
| 41 | EPBAniHeader = MAKE_0SC_HEADER('P', 'B'), |
| 42 | EFullFrameAniHeader = MAKE_0SC_HEADER('F', 'F'), ///< Floodfill? |
| 43 | ERNAniHeader = MAKE_0SC_HEADER('R', 'N'), |
| 44 | ERBAniHeader = MAKE_0SC_HEADER('R', 'B'), |
| 45 | ERCAniHeader = MAKE_0SC_HEADER('R', 'C'), |
| 46 | ERLAniHeader = MAKE_0SC_HEADER('R', 'L'), |
| 47 | EReverseAniHeader = MAKE_0SC_HEADER('R', 'R'), ///< Reverse animation when end found |
| 48 | EEndAniHeader = MAKE_0SC_HEADER('_', 'E'), ///< End of animation |
| 49 | ECompactedAniHeader = MAKE_0SC_HEADER(']', '['), ///< Full screen animation frame, does not clear the screen first |
| 50 | EMXAniHeader = MAKE_0SC_HEADER('M', 'X'), |
| 51 | ESoundTagAniHeader = MAKE_0SC_HEADER('S', 'T'), ///< Sound tag |
| 52 | ESoundListAniHeader = MAKE_0SC_HEADER('S', 'L'), ///< Sound list |
| 53 | EPlayListAniHeader = MAKE_0SC_HEADER('P', 'L') ///< Playlist |
| 54 | }; |
| 55 | |
| 56 | /// Cutscene script types - these are the known types |
| 57 | enum { |
| 58 | ESceneYesNo = 0x23, // # |
| 59 | ESceneMusic = 0x2A, // * |
| 60 | ESceneStopMusic = 0x2D, // - |
| 61 | ESceneTransitionType = 0x3F, // ? |
| 62 | ESceneTextBlock = 0x40, // @ |
| 63 | ESceneTextColour = 0x41, // A |
| 64 | ESceneFontFun = 0x45, // E |
| 65 | ESceneFontIndex = 0x46, // F |
| 66 | ESceneTextPosition = 0x47, // G |
| 67 | ESceneTextAlign = 0x4A, // J |
| 68 | ESceneTextAlign2 = 0x4B, // K |
| 69 | ESceneBackground = 0x4C, // L |
| 70 | ESceneBreaker = 0x50, // P |
| 71 | ESceneMusicTransition = 0x51, // Q |
| 72 | ESceneTextRect = 0x57, // W |
| 73 | ESceneFontDefine = 0x58, // X |
| 74 | ESceneTime = 0x5D, // ] |
| 75 | ESceneTextLine = 0x5E, // ^ |
| 76 | ESceneTextVAdjust = 0x5F, // _ = move "line" |
| 77 | ESceneAnimation = 0xA6, |
| 78 | ESceneAnimationPlayAndContinue = 0xA7, |
| 79 | ESceneBackgroundFade = 0xB1, |
| 80 | ESceneTextSomething = 0xD9, |
| 81 | ESceneTextShadow = 0xDB |
| 82 | }; |
| 83 | |
| 84 | |
| 85 | // Classes |
| 86 | |
| 87 | class Font; |
| 88 | |
| 89 | /// Cutscene page text |
| 90 | class JJ1SceneText { |
| 91 | |
| 92 | public: |
| 93 | unsigned char* text; |
| 94 | int alignment; |
| 95 | int fontId; |
| 96 | int x; |
| 97 | int y; |
| 98 | SDL_Rect textRect; |
| 99 | int extraLineHeight; |
| 100 | int textColour; |
| 101 | int shadowColour; |
| 102 | |
| 103 | JJ1SceneText (); |
| 104 | ~JJ1SceneText (); |
| 105 | }; |
| 106 | |
| 107 | /// Cutscene page |
| 108 | class JJ1ScenePage { |
| 109 | |
| 110 | public: |
| 111 | int backgrounds; |
| 112 | int bgIndex[30]; |
| 113 | unsigned short int bgX[30]; |
| 114 | unsigned short int bgY[30]; |
| 115 | |
| 116 | int animLoops; |
| 117 | int animSpeed; |
| 118 | int animIndex; |
| 119 | int nextPageAfterAnim; |
| 120 | |
| 121 | /// Length of the scene in seconds, or if zero = anim complete, or 256 = user interaction |
| 122 | int pageTime; |
| 123 | std::list<JJ1SceneText> texts; |
| 124 | char* musicFile; |
| 125 | int paletteIndex; |
| 126 | bool askForYesNo; |
| 127 | bool stopMusic; |
| 128 | int backgroundFade; |
| 129 | int transitionType; |
| 130 | |
| 131 | JJ1ScenePage (); |
| 132 | ~JJ1ScenePage (); |
| 133 | }; |
| 134 | |
| 135 | /// Cutscene background image |
| 136 | class JJ1SceneImage { |
| 137 | |
| 138 | public: |
| 139 | SDL_Surface* image; |
| 140 | int id; |
| 141 | |
| 142 | explicit JJ1SceneImage (int id); |
| 143 | ~JJ1SceneImage (); |
| 144 | JJ1SceneImage (const JJ1SceneImage&) = delete; // non construction-copyable |
| 145 | JJ1SceneImage& operator=(const JJ1SceneImage&) = delete; // non copyable |
| 146 | }; |
| 147 | |
| 148 | /// Cutscene palette |
| 149 | class JJ1ScenePalette { |
| 150 | |
| 151 | public: |
| 152 | SDL_Color palette[MAX_PALETTE_COLORS]; |
| 153 | int id; |
| 154 | |
| 155 | explicit JJ1ScenePalette (int id); |
| 156 | JJ1ScenePalette (const JJ1ScenePalette&) = delete; // non construction-copyable |
| 157 | JJ1ScenePalette& operator=(const JJ1ScenePalette&) = delete; // non copyable |
| 158 | }; |
| 159 | |
| 160 | /// Cutscene font |
| 161 | class JJ1SceneFont { |
| 162 | |
| 163 | public: |
| 164 | Font *font; |
| 165 | int id; |
| 166 | |
| 167 | explicit JJ1SceneFont (int id); |
| 168 | JJ1SceneFont (const JJ1SceneFont&) = delete; // non construction-copyable |
| 169 | JJ1SceneFont& operator=(const JJ1SceneFont&) = delete; // non copyable |
| 170 | }; |
| 171 | |
| 172 | /// Cutscene animation frame |
| 173 | class JJ1SceneFrame { |
| 174 | |
| 175 | public: |
| 176 | JJ1SceneFrame* next; |
| 177 | JJ1SceneFrame* prev; |
| 178 | unsigned char* frameData; |
| 179 | int frameSize; |
| 180 | unsigned int frameType; |
| 181 | SE::Type soundId; |
| 182 | |
| 183 | JJ1SceneFrame (int frameType, unsigned char* frameData, int frameSize); |
| 184 | ~JJ1SceneFrame (); |
| 185 | JJ1SceneFrame (const JJ1SceneFrame&) = delete; // non construction-copyable |
| 186 | JJ1SceneFrame& operator=(const JJ1SceneFrame&) = delete; // non copyable |
| 187 | }; |
| 188 | |
| 189 | /// Cutscene animation |
| 190 | class JJ1SceneAnimation { |
| 191 | |
| 192 | public: |
| 193 | JJ1SceneFrame* sceneFrames; |
| 194 | JJ1SceneFrame* lastFrame; |
| 195 | |
| 196 | SDL_Surface* background; |
| 197 | SDL_Surface* scratch; |
| 198 | int id; |
| 199 | int frames; |
| 200 | int reverseAnimation; |
| 201 | |
| 202 | explicit JJ1SceneAnimation (int id); |
| 203 | ~JJ1SceneAnimation (); |
| 204 | JJ1SceneAnimation (const JJ1SceneAnimation&) = delete; // non construction-copyable |
| 205 | JJ1SceneAnimation& operator=(const JJ1SceneAnimation&) = delete; // non copyable |
| 206 | |
| 207 | void addFrame (int frameType, unsigned char* frameData, int frameSize); |
| 208 | }; |
| 209 | |
| 210 | /// Cutscene |
| 211 | class JJ1Scene { |
| 212 | |
| 213 | private: |
| 214 | std::list<JJ1SceneAnimation> animations; |
| 215 | std::list<JJ1SceneImage> images; |
| 216 | std::list<JJ1ScenePalette> palettes; |
| 217 | std::list<JJ1SceneFont> fonts; |
| 218 | |
| 219 | /// Scripts all information needed to render script pages, text etc |
| 220 | std::vector<JJ1ScenePage> pages; |
| 221 | |
| 222 | unsigned short int scriptItems, dataItems; |
| 223 | std::vector<signed long int> scriptStarts, dataOffsets; |
| 224 | |
| 225 | void loadScripts (File* f); |
| 226 | void loadData (File* f); |
| 227 | void loadAni (JJ1SceneAnimation &animation, File* f, int dataIndex); |
| 228 | void loadCompactedMem (int size, unsigned char* frameData, unsigned char* pixdata); |
| 229 | void loadFullFrameMem (int size, unsigned char* frameData, unsigned char* pixdata); |
| 230 | unsigned short int loadShortMem (unsigned char **data); |
| 231 | |
| 232 | public: |
| 233 | explicit JJ1Scene (const char* fileName); |
| 234 | JJ1Scene (const JJ1Scene&) = delete; // non construction-copyable |
| 235 | JJ1Scene& operator=(const JJ1Scene&) = delete; // non copyable |
| 236 | |
| 237 | int play (); |
| 238 | }; |
| 239 | |
| 240 | #endif |