Changeset 871 – HoverRace

Changeset 871

Show
Ignore:
Timestamp:
02/21/10 19:38:06 (5 months ago)
Author:
zoogie
Message:

#84: DirectShow support for intro movie.

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/client/Game2/GameApp.cpp

    r870 r871  
    24062406 
    24072407        case WM_PAINT: 
    2408             // Nothing to paint (all done by video or DirectX) 
    2409             PAINTSTRUCT lPs; 
    2410             BeginPaint(pWindow, &lPs); 
    2411             EndPaint(pWindow, &lPs); 
     2408            { 
     2409                // Nothing to paint (all done by video or DirectX) 
     2410                PAINTSTRUCT lPs; 
     2411                HDC hdc = BeginPaint(pWindow, &lPs); 
     2412                if (This->introMovie != NULL) 
     2413                    This->introMovie->Repaint(hdc); 
     2414                EndPaint(pWindow, &lPs); 
     2415            } 
    24122416            return 0; 
    24132417 
  • trunk/client/Game2/IntroMovie.cpp

    r868 r871  
    3232 
    3333#include "../../engine/Util/Config.h" 
     34#include "../../engine/Util/Str.h" 
    3435 
    3536#include "IntroMovie.h" 
     
    3738using namespace HoverRace; 
    3839using namespace HoverRace::Client; 
    39 using HoverRace::Util::Config; 
     40using namespace HoverRace::Util; 
    4041 
    4142IntroMovie::IntroMovie(HWND hwnd, HINSTANCE hinst) : 
    42     hwnd(hwnd) 
     43    hwnd(hwnd), 
     44#ifdef WITH_DIRECTSHOW 
     45    graph(NULL), winCtl(NULL), mediaCtl(NULL) 
     46#else 
     47    movieWnd(NULL) 
     48#endif 
    4349{ 
    4450    Config *cfg = Config::GetInstance(); 
     
    4652 
    4753#ifdef WITH_DIRECTSHOW 
    48     //TODO 
     54    HRESULT hr; 
     55    if (FAILED(hr = InitDirectShow(movieFilename))) { 
     56        Clean(); 
     57    } 
     58 
    4959#else 
     60 
    5061    movieWnd = MCIWndCreate( 
    5162        hwnd, hinst,  
     
    6576IntroMovie::~IntroMovie() 
    6677{ 
     78    Clean(); 
     79} 
     80 
     81void IntroMovie::Clean() 
     82{ 
    6783#ifdef WITH_DIRECTSHOW 
    68     //TODO 
     84    if (mediaCtl != NULL) 
     85        mediaCtl->Release(); 
     86    if (winCtl != NULL) 
     87        winCtl->Release(); 
     88    if (graph != NULL) 
     89        graph->Release(); 
    6990#else 
    7091    if (movieWnd != NULL) { 
     
    7697} 
    7798 
     99#ifdef WITH_DIRECTSHOW 
     100HRESULT IntroMovie::InitDirectShow(const std::string &movieFilename) 
     101{ 
     102    HRESULT hr; 
     103 
     104    if (FAILED(hr = CoCreateInstance(CLSID_FilterGraph, NULL, 
     105        CLSCTX_INPROC_SERVER, IID_IGraphBuilder, 
     106        (void**)&graph))) return hr; 
     107 
     108    CComPtr<IBaseFilter> vmr; 
     109    if (FAILED(hr = CoCreateInstance(CLSID_VideoMixingRenderer, NULL,  
     110        CLSCTX_INPROC_SERVER, IID_IBaseFilter, (void**)&vmr))) return hr; 
     111    if (FAILED(hr = graph->AddFilter(vmr, L"Video Mixing Renderer"))) return hr; 
     112 
     113    CComPtr<IVMRFilterConfig> filterCfg; 
     114    if (FAILED(hr = vmr->QueryInterface(IID_IVMRFilterConfig, (void**)&filterCfg))) return hr; 
     115    if (FAILED(hr = filterCfg->SetRenderingMode(VMRMode_Windowless))) return hr; 
     116 
     117    if (FAILED(hr = vmr->QueryInterface(IID_IVMRWindowlessControl, (void**)&winCtl))) return hr; 
     118 
     119    if (FAILED(hr = winCtl->SetVideoClippingWindow(hwnd))) return hr; 
     120 
     121    if (FAILED(hr = graph->RenderFile(Str::UW(movieFilename.c_str()), NULL))) return hr; 
     122 
     123    if (FAILED(hr = graph->QueryInterface(IID_IMediaControl, (void**)&mediaCtl))) return hr; 
     124 
     125    return ERROR_SUCCESS; 
     126} 
     127#endif 
     128 
    78129void IntroMovie::Play() 
    79130{ 
    80131#ifdef WITH_DIRECTSHOW 
    81     //TODO 
     132    if (mediaCtl != NULL) 
     133        mediaCtl->Run(); 
    82134#else 
    83135    if (movieWnd != NULL) 
     
    88140void IntroMovie::ResetSize() 
    89141{ 
    90 #ifndef WITH_DIRECTSHOW 
    91142    RECT clientRect, movieRect; 
    92143 
    93144    if (GetClientRect(hwnd, &clientRect)) { 
    94         if (GetWindowRect(movieWnd, &movieRect)) { 
    95             SetWindowPos(movieWnd, HWND_TOP, 
    96                 0, 0, 
    97                 clientRect.right - clientRect.left, 
    98                 clientRect.bottom - clientRect.top, 
    99                 SWP_SHOWWINDOW); 
    100         } 
     145#       ifdef WITH_DIRECTSHOW 
     146            HRESULT hr; 
     147            long w, h; 
     148 
     149            if (mediaCtl != NULL) { 
     150                if (FAILED(hr = winCtl->GetNativeVideoSize(&w, &h, NULL, NULL))) { 
     151                    return; 
     152                } 
     153                SetRect(&movieRect, 0, 0, w, h); 
     154                winCtl->SetVideoPosition(&movieRect, &clientRect); 
     155            } 
     156#       else 
     157            if (GetWindowRect(movieWnd, &movieRect)) { 
     158                SetWindowPos(movieWnd, HWND_TOP, 
     159                    0, 0, 
     160                    clientRect.right - clientRect.left, 
     161                    clientRect.bottom - clientRect.top, 
     162                    SWP_SHOWWINDOW); 
     163            } 
     164#       endif 
    101165    } 
     166} 
     167 
     168void IntroMovie::Repaint(HDC hdc) 
     169{ 
     170#ifdef WITH_DIRECTSHOW 
     171    if (winCtl != NULL) 
     172        winCtl->RepaintVideo(hwnd, hdc); 
    102173#endif 
    103174} 
     
    105176void IntroMovie::ResetPalette(bool background) 
    106177{ 
    107 #ifndef WITH_DIRECTSHOW 
     178#ifdef WITH_DIRECTSHOW 
     179    if (winCtl != NULL) 
     180        winCtl->DisplayModeChanged(); 
     181#else 
    108182    MCIWndRealize(movieWnd, background); 
    109183#endif 
  • trunk/client/Game2/IntroMovie.h

    r868 r871  
    2323#pragma once 
    2424 
     25#ifdef WITH_DIRECTSHOW 
     26#   include <dshow.h> 
     27#endif 
     28 
    2529namespace HoverRace { 
    2630namespace Client { 
     
    3640        ~IntroMovie(); 
    3741 
     42    private: 
     43        void Clean(); 
     44#       ifdef WITH_DIRECTSHOW 
     45            HRESULT InitDirectShow(const std::string &movieFilename); 
     46#       endif 
     47 
    3848    public: 
    3949        void Play(); 
    4050 
    4151        void ResetSize(); 
     52        void Repaint(HDC hdc); 
    4253        void ResetPalette(bool background=false); 
    4354 
     
    4556        HWND hwnd; 
    4657#       ifdef WITH_DIRECTSHOW 
    47             //TODO 
     58            IGraphBuilder *graph; 
     59            IVMRWindowlessControl *winCtl; 
     60            IMediaControl *mediaCtl; 
    4861#       else 
    4962            HWND movieWnd; 
  • trunk/client/Game2/main.cpp

    r861 r871  
    184184    _chdir(appPath); 
    185185    free(appPath); 
     186 
     187    CoInitialize(NULL); 
    186188#endif 
    187189 
     
    258260    Config::Shutdown(); 
    259261 
     262#ifdef _WIN32 
     263    CoUninitialize(); 
     264#endif 
     265 
    260266    return lErrorCode; 
    261267} 
  • trunk/include/config-win32.h

    r577 r871  
    22/* config-win32.h 
    33    Win32 counterpart to the config.h generated from Linux build. */ 
     4 
     5#include "ntverp.h" 
    46 
    57#define PACKAGE "hoverrace" 
     
    1315 
    1416#define HAVE_LUA 1 
     17 
     18// Only enable DirectShow support if a recent Windows SDK is installed. 
     19#if defined(VER_PRODUCTBUILD) && VER_PRODUCTBUILD >= 6001 
     20#   define WITH_DIRECTSHOW 1 
     21#endif