From 99d4c55e88712a0b0dc0d97e4c9c52946a5f48f2 Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Fri, 27 Jul 2012 19:07:00 +0200 Subject: WINTERMUTE: Remove all unneccessary #if 0 blocks --- .../wintermute/base/font/base_font_truetype.cpp | 164 +------- engines/wintermute/base/gfx/base_image.cpp | 25 +- engines/wintermute/base/gfx/base_renderer.h | 1 + .../base/gfx/osystem/base_render_osystem.cpp | 114 +----- .../base/gfx/osystem/base_render_osystem.h | 2 +- .../base/scriptables/script_ext_date.cpp | 4 +- .../wintermute/base/scriptables/script_value.cpp | 4 - engines/wintermute/platform_osystem.cpp | 4 +- engines/wintermute/utils/path_util.cpp | 33 +- engines/wintermute/video/video_player.cpp | 431 +-------------------- engines/wintermute/video/video_player.h | 1 + engines/wintermute/video/video_theora_player.cpp | 153 +------- 12 files changed, 51 insertions(+), 885 deletions(-) diff --git a/engines/wintermute/base/font/base_font_truetype.cpp b/engines/wintermute/base/font/base_font_truetype.cpp index c643a5e1b1..638b939ec1 100644 --- a/engines/wintermute/base/font/base_font_truetype.cpp +++ b/engines/wintermute/base/font/base_font_truetype.cpp @@ -256,12 +256,6 @@ BaseSurface *BaseFontTT::renderTextToTexture(const WideString &text, int width, } else if (align == TAL_RIGHT) { alignment = Graphics::kTextAlignRight; } - // TODO: This function gets called a lot, so warnings like these drown out the usefull information - static bool hasWarned = false; - if (!hasWarned) { - hasWarned = true; - warning("BaseFontTT::RenderTextToTexture - Not fully ported yet"); - } debugC(kWinterMuteDebugFont, "%s %d %d %d %d", text.c_str(), RGBCOLGetR(_layers[0]->_color), RGBCOLGetG(_layers[0]->_color), RGBCOLGetB(_layers[0]->_color), RGBCOLGetA(_layers[0]->_color)); // void drawString(Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const; @@ -287,104 +281,7 @@ BaseSurface *BaseFontTT::renderTextToTexture(const WideString &text, int width, delete surface; delete convertedSurface; return retSurface; -#if 0 //TODO - int textHeight = lines.size() * (_maxCharHeight + _ascender); - SDL_Surface *surface = SDL_CreateRGBSurface(0, width, textHeight, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); - - SDL_LockSurface(surface); - - int posY = (int)GetLineHeight() - (int)_descender; - - for (it = lines.begin(); it != lines.end(); ++it) { - TextLine *line = (*it); - int posX = 0; - - switch (align) { - case TAL_CENTER: - posX += (width - line->GetWidth()) / 2; - break; - - case TAL_RIGHT: - posX += width - line->GetWidth(); - break; - } - - - textOffset = 0; - for (size_t i = 0; i < line->GetText().size(); i++) { - wchar_t ch = line->GetText()[i]; - - GlyphInfo *glyph = _glyphCache->GetGlyph(ch); - if (!glyph) { - continue; - } - - textOffset = MAX(textOffset, glyph->GetBearingY()); - } - - - int origPosX = posX; - - wchar_t prevChar = L'\0'; - for (size_t i = 0; i < line->GetText().size(); i++) { - wchar_t ch = line->GetText()[i]; - - GlyphInfo *glyph = _glyphCache->GetGlyph(ch); - if (!glyph) { - continue; - } - - float kerning = 0; - if (prevChar != L'\0') { - kerning = GetKerning(prevChar, ch); - } - posX += (int)kerning; - - - if (glyph->GetBearingY() > 0) { - int i = 10; - } - - SDL_Rect rect; - rect.x = posX + glyph->GetBearingX(); - rect.y = posY - glyph->GetBearingY() + textOffset; - rect.w = glyph->GetImage()->w; - rect.h = glyph->GetImage()->h; - - BlitSurface(glyph->GetImage(), surface, &rect); - - prevChar = ch; - posX += (int)(glyph->GetAdvanceX()); - posY += (int)(glyph->GetAdvanceY()); - } - - if (_isUnderline) { - for (int i = origPosX; i < origPosX + line->GetWidth(); i++) { - Uint8 *buf = (Uint8 *)surface->pixels + (int)(_underlinePos + _ascender) * surface->pitch; - Uint32 *buf32 = (Uint32 *)buf; - - buf32[i] = SDL_MapRGBA(surface->format, 255, 255, 255, 255); - } - } - - SDL_UnlockSurface(surface); - - delete line; - line = NULL; - posY += GetLineHeight(); - } - - BaseSurfaceOSystem *wmeSurface = new BaseSurfaceOSystem(_gameRef); - if (DID_SUCCEED(wmeSurface->CreateFromSDLSurface(surface))) { - SDL_FreeSurface(surface); - return wmeSurface; - } else { - SDL_FreeSurface(surface); - delete wmeSurface; - return NULL; - } -#endif - return NULL; + // TODO: _isUnderline, _isBold, _isItalic, _isStriked } @@ -666,65 +563,6 @@ bool BaseFontTT::initFont() { } _lineHeight = _font->getFontHeight(); return STATUS_OK; -#if 0 - FT_Error error; - - float vertDpi = 96.0; - float horDpi = 96.0; - - - _fTStream = (FT_Stream)new byte[sizeof(*_fTStream)]; - memset(_fTStream, 0, sizeof(*_fTStream)); - - _fTStream->read = BaseFontTT::FTReadSeekProc; - _fTStream->close = BaseFontTT::FTCloseProc; - _fTStream->descriptor.pointer = file; - _fTStream->size = file->GetSize(); - - FT_Open_Args args; - args.flags = FT_OPEN_STREAM; - args.stream = _fTStream; - - error = FT_Open_Face(_gameRef->_fontStorage->GetFTLibrary(), &args, 0, &_fTFace); - if (error) { - SAFE_DELETE_ARRAY(_fTStream); - _gameRef->_fileManager->closeFile(file); - return STATUS_FAILED; - } - - error = FT_Set_Char_Size(_fTFace, 0, (FT_F26Dot6)(_fontHeight * 64), (FT_UInt)horDpi, (FT_UInt)vertDpi); - if (error) { - FT_Done_Face(_fTFace); - _fTFace = NULL; - return STATUS_FAILED; - } - - // http://en.wikipedia.org/wiki/E_(typography) - float pixelsPerEm = (_fontHeight / 72.f) * vertDpi; // Size in inches * dpi - float emsPerUnit = 1.0f / _fTFace->units_per_EM; - float pixelsPerUnit = pixelsPerEm * EmsPerUnit; - - // bounding box in pixels - float xMin = _fTFace->bbox.xMin * pixelsPerUnit; - float xMax = _fTFace->bbox.xMax * pixelsPerUnit; - float yMin = _fTFace->bbox.yMin * pixelsPerUnit; - float yMax = _fTFace->bbox.yMax * pixelsPerUnit; - - // metrics in pixels - _ascender = _fTFace->ascender * pixelsPerUnit; - _descender = - _fTFace->descender * pixelsPerUnit; - _lineHeight = MathUtil::RoundUp(_fTFace->height * pixelsPerUnit) + 2; - _underlinePos = - _fTFace->underline_position * pixelsPerUnit; - - // max character size (used for texture grid) - _maxCharWidth = (size_t)MathUtil::RoundUp(xMax - xMin); - _maxCharHeight = (size_t)MathUtil::RoundUp(yMax - yMin); - - _glyphCache = new FontGlyphCache(); - _glyphCache->Initialize(); - -#endif - return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// diff --git a/engines/wintermute/base/gfx/base_image.cpp b/engines/wintermute/base/gfx/base_image.cpp index 3aa21d0f7f..1fff59d85b 100644 --- a/engines/wintermute/base/gfx/base_image.cpp +++ b/engines/wintermute/base/gfx/base_image.cpp @@ -114,23 +114,16 @@ bool BaseImage::saveBMPFile(const char *filename) const { ////////////////////////////////////////////////////////////////////////// bool BaseImage::resize(int newWidth, int newHeight) { - warning("BaseImage::resize(%d, %d), stubbed", newWidth, newHeight); -#if 0 - if (!_bitmap) { - return STATUS_FAILED; - } - - if (newWidth == 0) { - NewWidth = FreeImage_GetWidth(_bitmap); - } - if (newHeight == 0) { - NewHeight = FreeImage_GetHeight(_bitmap); + // WME Lite used FILTER_BILINEAR with FreeImage_Rescale here. + TransparentSurface temp(*_surface, true); + if (_deletableSurface) { + _deletableSurface->free(); + delete _deletableSurface; + _deletableSurface = NULL; } - - - FIBITMAP *newImg = FreeImage_Rescale(_bitmap, NewWidth, NewHeight, FILTER_BILINEAR); -#endif - return false; + _surface = _deletableSurface = temp.scaleSafe((uint16)newWidth, (uint16)newHeight); + temp.free(); + return true; } diff --git a/engines/wintermute/base/gfx/base_renderer.h b/engines/wintermute/base/gfx/base_renderer.h index 83b5ad0e16..008db69713 100644 --- a/engines/wintermute/base/gfx/base_renderer.h +++ b/engines/wintermute/base/gfx/base_renderer.h @@ -62,6 +62,7 @@ public: virtual BaseImage *takeScreenshot() = 0; virtual bool setViewport(int left, int top, int right, int bottom); virtual bool setViewport(Rect32 *rect); + virtual Rect32 getViewPort() = 0; virtual bool setScreenViewport(); virtual Graphics::PixelFormat getPixelFormat() const = 0; diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp index 00ef2ec95c..90dda1af72 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp @@ -231,8 +231,6 @@ bool BaseRenderOSystem::flip() { ////////////////////////////////////////////////////////////////////////// bool BaseRenderOSystem::fill(byte r, byte g, byte b, Common::Rect *rect) { - //SDL_SetRenderDrawColor(_renderer, r, g, b, 0xFF); - //SDL_RenderClear(_renderer); _clearColor = _renderSurface->format.ARGBToColor(0xFF, r, g, b); if (!_disableDirtyRects) { return STATUS_OK; @@ -240,6 +238,7 @@ bool BaseRenderOSystem::fill(byte r, byte g, byte b, Common::Rect *rect) { if (!rect) { rect = &_renderRect; } + // TODO: This doesn't work with dirty rects _renderSurface->fillRect(*rect, _clearColor); return STATUS_OK; @@ -410,7 +409,6 @@ void BaseRenderOSystem::addDirtyRect(const Common::Rect &rect) { _dirtyRect->extend(rect); } _dirtyRect->clip(_renderRect); -// warning("AddDirtyRect: %d %d %d %d", rect.left, rect.top, rect.right, rect.bottom); } void BaseRenderOSystem::drawTickets() { @@ -421,7 +419,6 @@ void BaseRenderOSystem::drawTickets() { if ((*it)->_wantsDraw == false || (*it)->_isValid == false) { RenderTicket *ticket = *it; addDirtyRect((*it)->_dstRect); - //warning("Discarding Rect: %d %d %d %d Width: %d Height: %d", (*it)->_dstRect.left, (*it)->_dstRect.top, (*it)->_dstRect.right, (*it)->_dstRect.bottom, (*it)->_dstRect.width() , (*it)->_dstRect.height()); it = _renderQueue.erase(it); delete ticket; decrement++; @@ -436,7 +433,6 @@ void BaseRenderOSystem::drawTickets() { // The color-mods are stored in the RenderTickets on add, since we set that state again during // draw, we need to keep track of what it was prior to draw. uint32 oldColorMod = _colorMod; -// warning("DirtyRect: %d %d %d %d Width: %d Height: %d", _dirtyRect->left, _dirtyRect->top, _dirtyRect->right, _dirtyRect->bottom, _dirtyRect->width(), _dirtyRect->height()); // Apply the clear-color to the dirty rect. _renderSurface->fillRect(*_dirtyRect, _clearColor); @@ -521,38 +517,11 @@ bool BaseRenderOSystem::drawLine(int x1, int y1, int x2, int y2, uint32 color) { ////////////////////////////////////////////////////////////////////////// BaseImage *BaseRenderOSystem::takeScreenshot() { -// TODO: Fix this +// TODO: Clip by viewport. warning("BaseRenderOSystem::TakeScreenshot() - not ported yet"); BaseImage *screenshot = new BaseImage(_gameRef->_fileManager); screenshot->copyFrom(_renderSurface); return screenshot; -#if 0 - SDL_Rect viewport; - - SDL_RenderGetViewport(_renderer, &viewport); - - SDL_Surface *surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, 0x00000000); - if (!surface) { - return NULL; - } - - if (SDL_RenderReadPixels(_renderer, NULL, surface->format->format, surface->pixels, surface->pitch) < 0) { - return NULL; - } - - FIBITMAP *dib = FreeImage_Allocate(viewport.w, viewport.h, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); - - int bytespp = FreeImage_GetLine(dib) / FreeImage_GetWidth(dib); - - for (unsigned y = 0; y < FreeImage_GetHeight(dib); y++) { - byte *bits = FreeImage_GetScanLine(dib, y); - byte *src = (byte *)surface->pixels + (viewport.h - y - 1) * surface->pitch; - memcpy(bits, src, bytespp * viewport.w); - } - - return new BaseImage(_gameRef, dib); -#endif - return NULL; } ////////////////////////////////////////////////////////////////////////// @@ -569,84 +538,43 @@ bool BaseRenderOSystem::setViewport(int left, int top, int right, int bottom) { rect.right = (int16)((right - left) * _ratioX); rect.bottom = (int16)((bottom - top) * _ratioY); + _renderRect = rect; return STATUS_OK; } +Rect32 BaseRenderOSystem::getViewPort() { + Rect32 ret; + ret.top = _renderRect.top; + ret.bottom = _renderRect.bottom; + ret.left = _renderRect.left; + ret.right = _renderRect.right; + return ret; +} + ////////////////////////////////////////////////////////////////////////// void BaseRenderOSystem::modTargetRect(Common::Rect *rect) { -#if 0 - SDL_Rect viewportRect; - SDL_RenderGetViewport(GetSdlRenderer(), &viewportRect); - - rect->x = MathUtil::Round(rect->x * _ratioX + _borderLeft - viewportRect.x); - rect->y = MathUtil::Round(rect->y * _ratioY + _borderTop - viewportRect.y); - rect->w = MathUtil::RoundUp(rect->w * _ratioX); - rect->h = MathUtil::RoundUp(rect->h * _ratioY); -#endif + rect->left = MathUtil::round(rect->left * _ratioX + _borderLeft - _renderRect.left); + rect->top = MathUtil::round(rect->top * _ratioY + _borderTop - _renderRect.top); + rect->setWidth(MathUtil::roundUp(rect->width() * _ratioX)); + rect->setHeight(MathUtil::roundUp(rect->height() * _ratioY)); } ////////////////////////////////////////////////////////////////////////// void BaseRenderOSystem::pointFromScreen(Point32 *point) { -#if 0 - SDL_Rect viewportRect; - SDL_RenderGetViewport(GetSdlRenderer(), &viewportRect); - - point->x = point->x / _ratioX - _borderLeft / _ratioX + viewportRect.x; - point->y = point->y / _ratioY - _borderTop / _ratioY + viewportRect.y; -#endif + point->x = point->x / _ratioX - _borderLeft / _ratioX + _renderRect.left; + point->y = point->y / _ratioY - _borderTop / _ratioY + _renderRect.top; } ////////////////////////////////////////////////////////////////////////// void BaseRenderOSystem::pointToScreen(Point32 *point) { -#if 0 - SDL_Rect viewportRect; - SDL_RenderGetViewport(GetSdlRenderer(), &viewportRect); - - point->x = MathUtil::RoundUp(point->x * _ratioX) + _borderLeft - viewportRect.x; - point->y = MathUtil::RoundUp(point->y * _ratioY) + _borderTop - viewportRect.y; -#endif + point->x = MathUtil::roundUp(point->x * _ratioX) + _borderLeft - _renderRect.left; + point->y = MathUtil::roundUp(point->y * _ratioY) + _borderTop - _renderRect.top; } ////////////////////////////////////////////////////////////////////////// void BaseRenderOSystem::dumpData(const char *filename) { - warning("BaseRenderOSystem::DumpData(%s) - not reimplemented yet", filename); // TODO -#if 0 - FILE *f = fopen(filename, "wt"); - if (!f) { - return; - } - - BaseSurfaceStorage *Mgr = _gameRef->_surfaceStorage; - - int totalKB = 0; - int totalLoss = 0; - fprintf(f, "Filename;Usage;Size;KBytes\n"); - for (int i = 0; i < Mgr->_surfaces.getSize(); i++) { - BaseSurfaceOSystem *Surf = (BaseSurfaceOSystem *)Mgr->_surfaces[i]; - if (!Surf->_filename) { - continue; - } - if (!Surf->_valid) { - continue; - } - - fprintf(f, "%s;%d;", Surf->_filename, Surf->_referenceCount); - fprintf(f, "%dx%d;", Surf->getWidth(), Surf->getHeight()); - - int kb = Surf->getWidth() * Surf->getHeight() * 4 / 1024; - - TotalKB += kb; - fprintf(f, "%d;", kb); - fprintf(f, "\n"); - } - fprintf(f, "Total %d;;;%d\n", Mgr->_surfaces.getSize(), TotalKB); - - - fclose(f); - _gameRef->LOG(0, "Texture Stats Dump completed."); - _gameRef->QuickMessage("Texture Stats Dump completed."); -#endif + warning("BaseRenderOSystem::DumpData(%s) - stubbed", filename); // TODO } BaseSurface *BaseRenderOSystem::createSurface() { diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.h b/engines/wintermute/base/gfx/osystem/base_render_osystem.h index 0d00b1b427..dfffc68c17 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.h +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.h @@ -82,7 +82,7 @@ public: void drawFromTicket(RenderTicket *renderTicket); bool setViewport(int left, int top, int right, int bottom); - + Rect32 getViewPort(); void modTargetRect(Common::Rect *rect); void pointFromScreen(Point32 *point); void pointToScreen(Point32 *point); diff --git a/engines/wintermute/base/scriptables/script_ext_date.cpp b/engines/wintermute/base/scriptables/script_ext_date.cpp index a3bb7e2183..181be8ddd0 100644 --- a/engines/wintermute/base/scriptables/script_ext_date.cpp +++ b/engines/wintermute/base/scriptables/script_ext_date.cpp @@ -68,9 +68,7 @@ const char *SXDate::scToString() { // TODO: Make this more stringy, and less ISO 8601-like _strRep.format("%04d-%02d-%02d - %02d:%02d:%02d", _tm.tm_year, _tm.tm_mon, _tm.tm_mday, _tm.tm_hour, _tm.tm_min, _tm.tm_sec); return _strRep.c_str(); -#if 0 - return asctime(&_tm); -#endif + //return asctime(&_tm); } diff --git a/engines/wintermute/base/scriptables/script_value.cpp b/engines/wintermute/base/scriptables/script_value.cpp index 01cb4044ff..9b83daf42f 100644 --- a/engines/wintermute/base/scriptables/script_value.cpp +++ b/engines/wintermute/base/scriptables/script_value.cpp @@ -166,11 +166,7 @@ ScValue *ScValue::getProp(const char *name) { if (_type == VAL_STRING && strcmp(name, "Length") == 0) { _gameRef->_scValue->_type = VAL_INT; -#if 0 // TODO: Remove FreeType-dependency if (_gameRef->_textEncoding == TEXT_ANSI) { -#else - if (true) { -#endif _gameRef->_scValue->setInt(strlen(_valString)); } else { WideString wstr = StringUtil::utf8ToWide(_valString); diff --git a/engines/wintermute/platform_osystem.cpp b/engines/wintermute/platform_osystem.cpp index c7d0c6cfed..32d53e3a50 100644 --- a/engines/wintermute/platform_osystem.cpp +++ b/engines/wintermute/platform_osystem.cpp @@ -179,8 +179,8 @@ bool BasePlatform::setCursorPos(int x, int y) { p.x = x; p.y = y; renderer->pointToScreen(&p); -// TODO - //SDL_WarpMouseInWindow(renderer->GetSdlWindow(), p.x, p.y); + + g_system->warpMouse(x, y); return true; } diff --git a/engines/wintermute/utils/path_util.cpp b/engines/wintermute/utils/path_util.cpp index 2fbe785a38..4e36c3e316 100644 --- a/engines/wintermute/utils/path_util.cpp +++ b/engines/wintermute/utils/path_util.cpp @@ -163,40 +163,9 @@ bool PathUtil::fileExists(const AnsiString &fileName) { ////////////////////////////////////////////////////////////////////////// -AnsiString PathUtil::getUserDirectory() { +AnsiString PathUtil::getUserDirectory() { // TODO: Get rid of warning("PathUtil::GetUserDirectory - stubbed"); AnsiString userDir = "./"; -#if 0 -#ifdef __WIN32__ - char buffer[MAX_PATH_LENGTH]; - buffer[0] = '\0'; - LPITEMIDLIST pidl = NULL; - LPMALLOC pMalloc; - if (DID_SUCCEED(SHGetMalloc(&pMalloc))) { - SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl); - if (pidl) { - SHGetPathFromIDList(pidl, buffer); - } - pMalloc->Free(pidl); - userDir = AnsiString(buffer); - } -#elif __MACOSX__ - FSRef fileRef; - OSStatus error = FSFindFolder(kUserDomain, kApplicationSupportFolderType, true, &fileRef); - if (error == noErr) { - char buffer[MAX_PATH_LENGTH]; - error = FSRefMakePath(&fileRef, (UInt8 *)buffer, sizeof(buffer)); - if (error == noErr) { - userDir = buffer; - } - - } -#elif __IPHONEOS__ - char path[MAX_PATH_LENGTH]; - IOS_GetDataDir(path); - userDir = AnsiString(path); -#endif -#endif // 0 return userDir; } diff --git a/engines/wintermute/video/video_player.cpp b/engines/wintermute/video/video_player.cpp index a4c81d12b5..d0b4019621 100644 --- a/engines/wintermute/video/video_player.cpp +++ b/engines/wintermute/video/video_player.cpp @@ -29,8 +29,6 @@ #include "engines/wintermute/video/video_player.h" -//#pragma comment(lib, "vfw32.lib") - namespace WinterMute { ////////////////////////////////////////////////////////////////////// @@ -42,33 +40,13 @@ VideoPlayer::VideoPlayer(BaseGame *inGame): BaseClass(inGame) { setDefaults(); } - ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::setDefaults() { _playing = false; - - /* _aviFile = NULL; - - _audioStream = NULL; - _audioFormat = NULL; - - _videoStream = NULL; - _videoFormat = NULL; - _videoPGF = NULL;*/ _videoEndTime = 0; - - //_sound = NULL; _soundAvailable = false; - - //_vidRenderer = NULL; - _startTime = 0; _totalVideoTime = 0; - - //_lastSample = -1; - - //_targetFormat = NULL; - _playPosX = _playPosY = 0; _playZoom = 0.0f; @@ -82,450 +60,49 @@ bool VideoPlayer::setDefaults() { return STATUS_OK; } - ////////////////////////////////////////////////////////////////////////// VideoPlayer::~VideoPlayer() { cleanup(); } - ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::cleanup() { -#if 0 - if (_sound) { - _sound->Stop(); - } - if (_videoPGF) { - AVIStreamGetFrameClose(_videoPGF); - } - _videoPGF = NULL; - - _playing = false; - - - if (_aviFile) { - AVIFileRelease(m_AviFile); - } - - if (_audioStream) { - AVIStreamRelease(m_AudioStream); - } - if (_videoStream) { - AVIStreamRelease(m_VideoStream); - } - - if (_audioFormat) { - delete[](byte *)m_AudioFormat; - } - if (_videoFormat) { - delete[](byte *)m_VideoFormat; - } - if (_targetFormat) { - delete[](byte *)m_TargetFormat; - } - - SAFE_DELETE(_sound); - SAFE_DELETE(_vidRenderer); - - SAFE_DELETE_ARRAY(_filename); - - for (int i = 0; i < _subtitles.getSize(); i++) { - delete _subtitles[i]; - } - _subtitles.clear(); - - return SetDefaults(); -#endif return 0; } - ////////////////////////////////////////////////////////////////////////// -bool VideoPlayer::initialize(const char *inFilename, const char *SubtitleFile) { -#if 0 - cleanup(); - - char filename[MAX_PATH_LENGTH]; - _gameRef->_fileManager->GetFullPath(inFilename, filename); - - // open file - if (AVIFileOpen(&_aviFile, Filename, OF_READ, NULL) != 0) { - _gameRef->LOG(0, "Error opening AVI file '%s'", filename); - return STATUS_FAILED; - } - - // get video stream - if (AVIFileGetStream(_aviFile, &_videoStream, streamtypeVIDEO, 0) != 0) { - _gameRef->LOG(0, "Error finding video stream in AVI file '%s'", filename); - return STATUS_FAILED; - } - _totalVideoTime = AVIStreamEndTime(_videoStream); - - // get audio stream - if (_gameRef->m_SoundMgr->_soundAvailable && AVIFileGetStream(_aviFile, &_audioStream, streamtypeAUDIO, 0) == 0) { - _soundAvailable = true; - } else { - _soundAvailable = false; - } - - - LONG Size; - - // get video format - if (AVIStreamReadFormat(m_VideoStream, 0, NULL, &Size)) { - _gameRef->LOG(0, "Error obtaining video stream format in AVI file '%s'", filename); - return STATUS_FAILED; - } - _videoFormat = (LPBITMAPINFO)new BYTE[Size]; - AVIStreamReadFormat(m_VideoStream, 0, m_VideoFormat, &Size); - - // initialize optimal target format - m_TargetFormat = (LPBITMAPV4HEADER)new BYTE[max(Size, sizeof(BITMAPV4HEADER))]; - memset(m_TargetFormat, 0, sizeof(BITMAPV4HEADER)); - memcpy(m_TargetFormat, m_VideoFormat, Size); - m_TargetFormat->bV4Size = max(Size, sizeof(BITMAPV4HEADER)); - - m_TargetFormat->bV4BitCount = 24; - m_TargetFormat->bV4V4Compression = BI_RGB; - - if (_gameRef->m_UseD3D) { - m_VidRenderer = new CVidRendererD3D(_gameRef); - } else { - m_VidRenderer = new CVidRendererDD(_gameRef); - } - - if (!m_VidRenderer || DID_FAIL(m_VidRenderer->Initialize(m_VideoFormat, m_TargetFormat))) { - _gameRef->LOG(0, "Error initializing video renderer for AVI file '%s'", filename); - SAFE_DELETE(m_VidRenderer); - return STATUS_FAILED; - } - - - // create sound buffer - bool res; - - if (_soundAvailable) { - _sound = new BaseSoundAVI(_gameRef); - if (DID_FAIL(res = _sound->InitializeBuffer(_audioStream))) { - SAFE_DELETE(_sound); - _soundAvailable = false; - _gameRef->LOG(res, "Error initializing sound buffer for AVI file '%s'", filename); - } - } - - if (_gameRef->_videoSubtitles) { - LoadSubtitles(inFilename, SubtitleFile); - } - - _filename = new char[strlen(filename) + 1]; - if (_filename) { - strcpy(_filename, filename); - } -#endif +bool VideoPlayer::initialize(const char *inFilename, const char *subtitleFile) { + warning("VideoPlayer: %s %s - Not implemented yet", inFilename, subtitleFile); return STATUS_OK; } - ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::update() { -#if 0 - if (!m_Playing) { - return STATUS_OK; - } - - bool res; - - if (_soundAvailable && m_Sound) { - res = _sound->update(); - if (DID_FAIL(res)) { - return res; - } - } - - - DWORD CurrentTime; // current playing time (in ms) - /* - if (m_SoundAvailable && m_Sound){ - CurrentTime = m_Sound->GetPosition(); // in samples - CurrentTime /= (m_Sound->m_Format.wf.nSamplesPerSec / 1000); - - if (!m_Sound->IsPlaying()) CurrentTime = m_TotalVideoTime; - } - else - CurrentTime = timeGetTime() - m_StartTime; - */ - CurrentTime = timeGetTime() - _startTime; - - if (CurrentTime >= _totalVideoTime) { - Stop(); - return STATUS_OK; - } - - - // get and render frame - DWORD sample = AVIStreamTimeToSample(_videoStream, CurrentTime); - if (sample != _lastSample) { - _lastSample = sample; - - // process subtitles - _showSubtitle = false; - while (_currentSubtitle < _subtitles.getSize()) { - int end = _subtitles[_currentSubtitle]->m_EndFrame; - - bool nextFrameOK = (_currentSubtitle < _subtitles.getSize() - 1 && _subtitles[_currentSubtitle + 1]->_startFrame <= sample); - - if (sample > End) { - if (NextFrameOK) { - _currentSubtitle++; - } else { - _showSubtitle = (End == 0); - break; - } - } else { - _showSubtitle = true; - break; - } - } - - - // render frame - LPBITMAPINFOHEADER FrameData = (LPBITMAPINFOHEADER)AVIStreamGetFrame(m_VideoPGF, sample); - if (FrameData) { - if (_slowRendering) { - return _vidRenderer->ProcessFrameSlow(FrameData); - } else { - return _vidRenderer->ProcessFrame(FrameData); - } - } else { - return STATUS_FAILED; - } - } else { - return STATUS_OK; - } -#endif return 0; } - ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::display() { -#if 0 - if (!m_Playing) { - return STATUS_OK; - } - - bool res; - if (_vidRenderer) { - res = _vidRenderer->display(m_PlayPosX, m_PlayPosY, m_PlayZoom); - } else { - res = STATUS_FAILED; - } - - // display subtitle - if (m_ShowSubtitle) { - BaseFont *font = _gameRef->_videoFont ? _gameRef->_videoFont : _gameRef->_systemFont; - int height = font->GetTextHeight((BYTE *)m_Subtitles[_currentSubtitle]->_text, _gameRef->_renderer->_width); - font->drawText((byte *)_subtitles[m_CurrentSubtitle]->_text, 0, _gameRef->_renderer->_height - Height - 5, _gameRef->_renderer->_width, TAL_CENTER); - } - - return res; -#endif return 0; } - - - ////////////////////////////////////////////////////////////////////////// -bool VideoPlayer::play(TVideoPlayback type, int x, int y, bool FreezeMusic) { -#if 0 - if (!_videoStream || !_vidRenderer) { - return STATUS_FAILED; - } - - switch (Type) { - case VID_PLAY_POS: - _playZoom = 100.0f; - _playPosX = X; - _playPosY = Y; - break; - - case VID_PLAY_STRETCH: { - float zoomX = (float)((float)_gameRef->_renderer->m_Width / (float)_videoFormat->bmiHeader.biWidth * 100); - float zoomY = (float)((float)_gameRef->_renderer->m_Height / (float)_videoFormat->bmiHeader.biHeight * 100); - _playZoom = min(ZoomX, ZoomY); - _playPosX = (_gameRef->_renderer->_width - _videoFormat->bmiHeader.biWidth * (_playZoom / 100)) / 2; - _playPosY = (_gameRef->_renderer->_height - _videoFormat->bmiHeader.biHeight * (_playZoom / 100)) / 2; - } - break; - - case VID_PLAY_CENTER: - _playZoom = 100.0f; - _playPosX = (_gameRef->_renderer->_width - _videoFormat->bmiHeader.biWidth) / 2; - _playPosY = (_gameRef->_renderer->_height - _videoFormat->bmiHeader.biHeight) / 2; - break; - } - - _targetFormat->bV4BitCount = 24; - _targetFormat->bV4V4Compression = BI_RGB; - - - _videoPGF = AVIStreamGetFrameOpen(_videoStream, (LPBITMAPINFOHEADER)m_TargetFormat); - if (!_videoPGF) { - _videoPGF = AVIStreamGetFrameOpen(_videoStream, NULL); - if (!_videoPGF) { - _gameRef->LOG(0, "Error: Unsupported AVI format (file '%s')", m_Filename); - cleanup(); - return STATUS_FAILED; - } else { - _gameRef->LOG(0, "Performance warning: non-optimal AVI format, using generic (i.e. slow) rendering routines (file '%s')", m_Filename); - _slowRendering = true; - } - } else { - _slowRendering = false; - } - - // HACK!!! - _slowRendering = true; - - - _currentSubtitle = 0; - - _gameRef->Freeze(FreezeMusic); - - _playing = true; - if (_sound) { - _sound->Play(); - } - _startTime = timeGetTime(); -#endif +bool VideoPlayer::play(TVideoPlayback type, int x, int y, bool freezeMusic) { return STATUS_OK; } - ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::stop() { -#if 0 - if (!_playing) { - return STATUS_OK; - } - - cleanup(); - - _gameRef->Unfreeze(); -#endif return STATUS_OK; } - ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::isPlaying() { return _playing; } - ////////////////////////////////////////////////////////////////////////// -bool VideoPlayer::loadSubtitles(const char *filename, const char *SubtitleFile) { -#if 0 - if (!Filename) { - return STATUS_OK; - } - - char newFile[MAX_PATH_LENGTH]; - char drive[_MAX_DRIVE]; - char dir[_MAX_DIR]; - char fname[_MAX_FNAME]; - - if (SubtitleFile) { - strcpy(NewFile, SubtitleFile); - } else { - _splitpath(filename, drive, dir, fname, NULL); - _makepath(NewFile, drive, dir, fname, ".SUB"); - } - - DWORD size; - BYTE *buffer = _gameRef->m_FileManager->readWholeFile(NewFile, &Size, false); - if (Buffer == NULL) { - return STATUS_OK; // no subtitles - } - - - LONG Start, End; - bool inToken; - char *tokenStart; - int tokenLength; - int tokenPos; - int textLength; - - int pos = 0; - int lineLength = 0; - while (Pos < Size) { - start = End = -1; - inToken = false; - tokenPos = -1; - textLength = 0; - - lineLength = 0; - while (Pos + LineLength < Size && Buffer[Pos + LineLength] != '\n' && Buffer[Pos + LineLength] != '\0') { - lineLength++; - } - - int realLength = LineLength - (Pos + LineLength >= Size ? 0 : 1); - char *text = new char[RealLength + 1]; - char *line = (char *)&Buffer[Pos]; - - for (int i = 0; i < RealLength; i++) { - if (line[i] == '{') { - if (!InToken) { - InToken = true; - TokenStart = line + i + 1; - TokenLength = 0; - TokenPos++; - } else { - TokenLength++; - } - } else if (line[i] == '}') { - if (InToken) { - InToken = false; - char *token = new char[TokenLength + 1]; - strncpy(Token, TokenStart, TokenLength); - Token[TokenLength] = '\0'; - if (TokenPos == 0) { - Start = atoi(Token); - } else if (TokenPos == 1) { - End = atoi(Token); - } - - delete[] Token; - } else { - Text[TextLength] = line[i]; - TextLength++; - } - } else { - if (InToken) { - TokenLength++; - } else { - Text[TextLength] = line[i]; - if (Text[TextLength] == '|') { - Text[TextLength] = '\n'; - } - TextLength++; - } - } - } - Text[TextLength] = '\0'; - - if (Start != -1 && TextLength > 0) { - _subtitles.add(new CVidSubtitle(_gameRef, Text, Start, End)); - } - - delete[] Text; - - Pos += LineLength + 1; - } - - delete[] Buffer; -#endif +bool VideoPlayer::loadSubtitles(const char *filename, const char *subtitleFile) { return STATUS_OK; } diff --git a/engines/wintermute/video/video_player.h b/engines/wintermute/video/video_player.h index 4c02506094..190223c6d1 100644 --- a/engines/wintermute/video/video_player.h +++ b/engines/wintermute/video/video_player.h @@ -38,6 +38,7 @@ namespace WinterMute { +// AVI-Video-player, currently fully stubbed class VideoPlayer : public BaseClass { public: bool _showSubtitle; diff --git a/engines/wintermute/video/video_theora_player.cpp b/engines/wintermute/video/video_theora_player.cpp index ada645c972..c0a86ecd7e 100644 --- a/engines/wintermute/video/video_theora_player.cpp +++ b/engines/wintermute/video/video_theora_player.cpp @@ -84,9 +84,9 @@ void VideoTheoraPlayer::SetDefaults() { _savedPos = 0; _volume = 100; _theoraDecoder = NULL; -#if 0 - _subtitler = NULL; -#endif + + // TODO: Add subtitles-support + //_subtitler = NULL; } ////////////////////////////////////////////////////////////////////////// @@ -154,7 +154,7 @@ bool VideoTheoraPlayer::initialize(const Common::String &filename, const Common: ////////////////////////////////////////////////////////////////////////// bool VideoTheoraPlayer::resetStream() { warning("VidTheoraPlayer::resetStream - stubbed"); -#if 0 +#if 0 // Stubbed for now, as theora isn't seekable if (_sound) { _sound->Stop(); } @@ -227,7 +227,7 @@ bool VideoTheoraPlayer::play(TVideoPlayback type, int x, int y, bool freezeGame, break; } return STATUS_OK; -#if 0 +#if 0 // Stubbed for now as theora isn't seekable if (StartTime) SeekToTime(StartTime); Update(); @@ -299,83 +299,6 @@ bool VideoTheoraPlayer::update() { } } -#if 0 - m_CurrentTime = m_FreezeGame ? _gameRef->m_LiveTimer : _gameRef->m_Timer; - - if (!IsPlaying()) return STATUS_OK; - - if (m_PlaybackStarted && m_Sound && !m_Sound->IsPlaying()) return STATUS_OK; - - if (m_PlaybackStarted && !m_FreezeGame && _gameRef->m_State == GAME_FROZEN) return STATUS_OK; - - int counter = 0; - while (true) { - if (m_Sound) DecodeVorbis(); - else m_AudioFrameReady = true; - - if (m_Texture) DecodeTheora(); - else m_VideoFrameReady = true; - - if ((!m_Sound || !m_AudioFrameReady) && (!m_Texture || !m_VideoFrameReady) && m_File->IsEOF()) { - // end playback - if (!m_Looping) { - m_State = THEORA_STATE_FINISHED; - if (m_Sound) m_Sound->Stop(); - if (m_FreezeGame) _gameRef->Unfreeze(); - break; - } else { - ResetStream(); - return STATUS_OK; - } - } - - - if (!m_VideoFrameReady || !m_AudioFrameReady) { - Counter++; - if (StreamInData() == 0) break; - } else break; - } - - - // If playback has begun, top audio buffer off immediately. - //if (m_Sound) WriteAudio(); - - // are we at or past time for this video frame? - if (m_PlaybackStarted && m_VideoFrameReady && (!m_FrameRendered || m_VideobufTime <= GetMovieTime())) { - //_gameRef->LOG(0, "%f %f", m_VideobufTime, GetMovieTime()); - if (m_Texture) WriteVideo(); - m_VideoFrameReady = false; - - if (m_SavedState == THEORA_STATE_PAUSED) { - Pause(); - m_SavedState = THEORA_STATE_NONE; - } - } - - // if our buffers either don't exist or are ready to go, - // we can begin playback - bool startNow = false; - if ((!m_TheoraStreams || m_VideoFrameReady) && - (!m_VorbisStreams || m_AudioFrameReady)) StartNow = true; - // same if we've run out of input - if (m_File->IsEOF()) StartNow = true; - - - if (m_Sound) WriteAudio(); - - - if (!m_PlaybackStarted && StartNow && !m_SeekingKeyframe) { - //m_StartTime = timeGetTime(); - m_StartTime = m_CurrentTime; - if (m_Sound) { - m_Sound->SetPrivateVolume(m_Volume); - m_Sound->Play(); - } - m_PlaybackStarted = true; - } - - if (m_Subtitler && _gameRef->m_VideoSubtitles) m_Subtitler->update(GetMovieFrame()); -#endif return STATUS_OK; } @@ -442,11 +365,11 @@ bool VideoTheoraPlayer::display(uint32 alpha) { } else { res = STATUS_FAILED; } -#if 0 - if (m_Subtitler && _gameRef->m_VideoSubtitles) { + // TODO: Add subtitles-support +/* if (m_Subtitler && _gameRef->m_VideoSubtitles) { m_Subtitler->display(); - } -#endif + }*/ + return res; } @@ -494,64 +417,6 @@ inline int intlog(int num) { ////////////////////////////////////////////////////////////////////////// bool VideoTheoraPlayer::seekToTime(uint32 time) { warning("VideoTheoraPlayer::SeekToTime(%d) - not supported", time); -#if 0 - if (!m_TheoraStreams) return STATUS_FAILED; - - - float targetTime = Time / 1000.0f; - - - ogg_page page; - int read = 1; - ogg_int64_t gran; - float movieLength = 0; - DWORD LastPos = 0; - - int keyframe_granule_shift = intlog(m_TheoraInfo.keyframe_frequency_force - 1); - - while (!m_File->IsEOF() && read != 0) { - read = BufferData(&m_OggSyncState); - - while (ogg_sync_pageout(&m_OggSyncState, &page) > 0) { - int serno = ogg_page_serialno(&page); - //This is theora stream we were searching for - if (m_TheoraStreamState.serialno == serno) { - //Calculate a rough time estimate - gran = ogg_page_granulepos(&page); - if (gran >= 0) { - ogg_int64_t iframe = gran >> keyframe_granule_shift; - ogg_int64_t pframe = gran - (iframe << keyframe_granule_shift); - movieLength = (iframe + pframe) * - ((double)m_TheoraInfo.fps_denominator / m_TheoraInfo.fps_numerator); - - if (movieLength >= TargetTime) { - m_TimeOffset = movieLength; - //m_TimeOffset = TargetTime; - //m_File->Seek(LastPos); - - goto finish; - } - LastPos = m_File->GetPos(); - } - } - } - } - -finish: - ogg_sync_reset(&m_OggSyncState); - - ogg_stream_reset(&m_TheoraStreamState); - ogg_stream_reset(&m_VorbisStreamState); - - theora_clear(&m_TheoraState); - theora_decode_init(&m_TheoraState, &m_TheoraInfo); - vorbis_synthesis_restart(&m_VorbisDSPState); - - m_SeekingKeyframe = true; - - //theora_packet_iskeyframe - -#endif return STATUS_OK; } -- cgit v1.2.3