1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program 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 this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef MOHAWK_RIVEN_GRAPHICS_H 24 #define MOHAWK_RIVEN_GRAPHICS_H 25 26 #include "mohawk/graphics.h" 27 #include "mohawk/riven_graphics_detection_enums.h" 28 29 #include "common/ustr.h" 30 31 namespace Graphics { 32 class Font; 33 } 34 35 namespace Mohawk { 36 37 class MohawkEngine_Riven; 38 class FliesEffect; 39 class WaterEffect; 40 41 enum RivenTransition { 42 kRivenTransitionNone = -1, 43 kRivenTransitionWipeLeft = 0, 44 kRivenTransitionWipeRight = 1, 45 kRivenTransitionWipeUp = 2, 46 kRivenTransitionWipeDown = 3, 47 kRivenTransitionPanLeft = 12, 48 kRivenTransitionPanRight = 13, 49 kRivenTransitionPanUp = 14, 50 kRivenTransitionPanDown = 15, 51 kRivenTransitionBlend = 16, 52 kRivenTransitionBlend2 = 17 53 }; 54 55 enum RivenCreditsImageNumber { 56 kRivenCreditsZeroImage = 302, 57 kRivenCreditsFirstImage = 303, 58 kRivenCreditsSecondImage = 304, 59 kRivenCreditsLastImage = 320 60 }; 61 62 class RivenGraphics : public GraphicsManager { 63 public: 64 explicit RivenGraphics(MohawkEngine_Riven *vm); 65 ~RivenGraphics() override; 66 67 // Screen updates 68 void beginScreenUpdate(); 69 void applyScreenUpdate(bool force = false); 70 void enableCardUpdateScript(bool enable); 71 72 void copyImageToScreen(uint16 image, uint32 left, uint32 top, uint32 right, uint32 bottom); 73 void drawRect(const Common::Rect &rect, bool active); 74 void drawImageRect(uint16 id, const Common::Rect &srcRect, const Common::Rect &dstRect); 75 void drawExtrasImage(uint16 id, const Common::Rect &dstRect); 76 void drawExtrasImageToScreen(uint16 id, const Common::Rect &rect); 77 78 /** Copy a rect from the system screen to the game screen */ 79 void copySystemRectToScreen(const Common::Rect &rect); 80 81 Graphics::Surface *getEffectScreen(); 82 Graphics::Surface *getBackScreen(); 83 84 // Water Effect 85 void scheduleWaterEffect(uint16); 86 void clearWaterEffect(); 87 88 // Flies Effect 89 void setFliesEffect(uint16 count, bool fireflies); 90 void clearFliesEffect(); 91 92 /** Update the screen with the water and fly effects */ 93 void updateEffects(); 94 95 // Transitions 96 void scheduleTransition(RivenTransition id, const Common::Rect &rect = Common::Rect(0, 0, 608, 392)); 97 void runScheduledTransition(); 98 void fadeToBlack(); 99 void setTransitionMode(RivenTransitionMode mode); 100 static RivenTransitionMode sanitizeTransitionMode(int mode); 101 102 // Main menu 103 void loadMenuFont(); 104 void drawText(const Common::U32String &text, const Common::Rect &dest, uint8 greyLevel); 105 106 // Credits 107 void beginCredits(); 108 void updateCredits(); getCurCreditsImage()109 uint getCurCreditsImage() const { return _creditsImage; } 110 111 protected: 112 MohawkSurface *decodeImage(uint16 id) override; getVM()113 MohawkEngine *getVM() override { return (MohawkEngine *)_vm; } 114 115 private: 116 MohawkEngine_Riven *_vm; 117 MohawkBitmap *_bitmapDecoder; 118 int _screenUpdateNesting; 119 bool _screenUpdateRunning; 120 bool _enableCardUpdateScript; 121 122 // Effects 123 WaterEffect *_waterEffect; 124 FliesEffect *_fliesEffect; 125 126 // Transitions 127 RivenTransition _scheduledTransition; 128 Common::Rect _transitionRect; 129 RivenTransitionMode _transitionMode; 130 uint _transitionFrames; 131 uint _transitionDuration; 132 int16 _transitionOffset; 133 134 // Screen Related 135 Graphics::Surface *_mainScreen; 136 Graphics::Surface *_effectScreen; 137 bool _dirtyScreen; 138 139 Graphics::PixelFormat _pixelFormat; 140 void updateScreen(); 141 void clearMainScreen(); 142 143 // Main menu 144 Graphics::Font *_menuFont; 145 const Graphics::Font *getMenuFont() const; 146 147 // Credits 148 uint _creditsImage, _creditsPos; 149 }; 150 151 /** 152 * Move slightly the water portions of a view to simulate waves 153 */ 154 class WaterEffect { 155 public: 156 WaterEffect(MohawkEngine_Riven *vm, uint16 sfxeID); 157 ~WaterEffect(); 158 159 void update(); 160 161 private: 162 MohawkEngine_Riven *_vm; 163 164 // Record values 165 Common::Rect _rect; 166 uint16 _speed; 167 Common::Array<Common::SeekableReadStream *> _frameScripts; 168 169 // Cur frame 170 uint16 _curFrame; 171 uint32 _lastFrameTime; 172 }; 173 174 /** 175 * The flies effect draws flies in the scene 176 * 177 * It can draw either regular flies or fireflies. 178 * The flies' movement is simulated in 3 dimensions. 179 */ 180 class FliesEffect { 181 public: 182 FliesEffect(MohawkEngine_Riven *vm, uint16 count, bool fireflies); 183 ~FliesEffect(); 184 185 /** Simulate the flies' movement and draw them to the screen */ 186 void update(); 187 188 private: 189 struct FliesEffectEntry { 190 bool light; 191 int posX; 192 int posY; 193 int posZ; 194 const uint16 *alphaMap; 195 uint width; 196 uint height; 197 int framesTillLightSwitch; 198 bool hasBlur; 199 int blurPosX; 200 int blurPosY; 201 const uint16 *blurAlphaMap; 202 uint blurWidth; 203 uint blurHeight; 204 float posXFloat; 205 float posYFloat; 206 float posZFloat; 207 float directionAngleRad; 208 float directionAngleRadZ; 209 float speed; 210 }; 211 212 struct FliesEffectData { 213 bool lightable; 214 bool unlightIfTooBright; 215 bool isLarge; 216 bool canBlur; 217 float maxSpeed; 218 float minSpeed; 219 int maxAcceleration; 220 float blurSpeedTreshold; 221 float blurDistance; 222 uint32 color32; 223 int minFramesLit; 224 int maxLightDuration; 225 }; 226 227 MohawkEngine_Riven *_vm; 228 229 uint _nextUpdateTime; 230 int _updatePeriodMs; 231 232 Common::Rect _gameRect; 233 Graphics::Surface *_effectSurface; 234 Graphics::Surface *_backSurface; 235 Common::Array<Common::Rect> _screenSurfaceDirtyRects; 236 Common::Array<Common::Rect> _effectsSurfaceDirtyRects; 237 238 const FliesEffectData *_parameters; 239 static const FliesEffectData _firefliesParameters; 240 static const FliesEffectData _fliesParameters; 241 242 Common::Array<FliesEffectEntry> _fly; 243 244 void initFlies(uint16 count); 245 void initFlyRandomPosition(uint index); 246 void initFlyAtPosition(uint index, int posX, int posY, int posZ); 247 248 void updateFlies(); 249 void updateFlyPosition(uint index); 250 251 void draw(); 252 void updateScreen(); 253 254 void selectAlphaMap(bool horGridOffset, bool vertGridoffset, const uint16 **alphaMap, uint *width, uint *height); 255 void colorBlending(uint32 flyColor, byte &r, byte &g, byte &b, int alpha); 256 257 void addToScreenDirtyRects(const Common::Rect &rect); 258 void addToEffectsDirtyRects(const Common::Rect &rect); 259 void restoreEffectsSurface(); 260 261 int randomBetween(int min, int max); 262 }; 263 264 } // End of namespace Mohawk 265 266 #endif 267