// Setup Application Window and initialize Direct3D. bool FxPlayerTiny::SetupWindow(const GString& name) { hInstance = GetModuleHandle(NULL); // Register the window class WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, StaticWindowProc, 0L, sizeof(FxPlayerTiny*), hInstance, NULL, NULL, NULL, NULL, pWndClassName, NULL }; RegisterClassEx(&wc); // Create the application's window. RECT r = { 100, 100, 100 + Width, 100 + Height }; ::AdjustWindowRect(&r, WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU, 0); HWND hWnd = CreateWindow(pWndClassName, name.ToCStr(), WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU, r.left, r.top, r.right-r.left, r.bottom - r.top, GetDesktopWindow(), NULL, wc.hInstance, (LPVOID) this ); if (!pD3D)return 0; // Set up the structure used to create the D3DDevice ZeroMemory(&PresentParams, sizeof(PresentParams)); PresentParams.Windowed = TRUE; PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD; PresentParams.BackBufferFormat = D3DFMT_UNKNOWN; PresentParams.BackBufferWidth = Width; PresentParams.BackBufferHeight = Height; PresentParams.EnableAutoDepthStencil = 1; PresentParams.AutoDepthStencilFormat = D3DFMT_D24S8; //PresentParams.MultiSampleQuality = D3DMULTISAMPLE_4_SAMPLES; // Create the D3DDevice if (FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &PresentParams, &pDevice ) )) { return 0; } return 1; }
// Called from main()/WindMain() after settings are initialized to execute // most of the program logic. Responsible for setting up the window, // loading movies and containing the playback/message loop. int FxPlayerTiny::Run() { if (!SetupWindow(GString(FXPLAYER_APP_TITLE " ") + FileName)) return 1; // Show the window. ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); // Create and Configure GFxLoader. GFxLoader loader; // Developers set states on the loader to modify loading and playback behavior. // If you need to load files from a custom package, for example, you can // create a GFxFileOpener derived class that loads files in a custom way. // Here GFxFileOpener and GFxFSCommandHandler are set for sample purposes. GPtr<GFxFileOpener> pfileOpener = *new GFxFileOpener; loader.SetFileOpener(pfileOpener); GPtr<GFxFSCommandHandler> pcommandHandler = *new FxPlayerFSCommandHandler; loader.SetFSCommandHandler(pcommandHandler); // For D3D, it is good to override image creator to keep image data, // so that it can be restored in case of a lost device. GPtr<GFxImageCreator> pimageCreator = *new GFxImageCreator(1); loader.SetImageCreator(pimageCreator); // Load the movie file and create its instance. if (!(pMovieDef = *loader.CreateMovie(FileName))) { GString errorString = "Unable to load file: "; errorString += FileName; MessageBox(NULL, errorString.ToCStr(), "Error", MB_OK | MB_ICONEXCLAMATION); return 1; } if (!(pMovie = *pMovieDef->CreateInstance())) return 1; // Create renderer. if (!(pRenderer = *GRendererD3D9::CreateRenderer())) return 1; // Configure renderer in "Dependent mode", honoring externally // configured device settings. if (!pRenderer->SetDependentVideoMode(pDevice, &PresentParams, 0, hWnd)) return 1; // Set renderer on loader so that it is also applied to all children. pRenderConfig = *new GFxRenderConfig(pRenderer, GFxRenderConfig::RF_EdgeAA | GFxRenderConfig::RF_StrokeNormal); loader.SetRenderConfig(pRenderConfig); // Set playback view to span the entire window. pMovie->SetViewport(Width, Height, 0,0, Width, Height); // If you wanted to use the movie as a transparent HUD overlay, you would // set Background Alpha to 0. We don't need to do this for player sample. // pMovie->SetBackgroundAlpha(0.0f); // Store initial timing, so that we can determine // how much to advance Flash playback. MovieLastTime = timeGetTime(); // Application / Player message loop. MSG msg; ZeroMemory(&msg, sizeof(msg)); // KevinJ: 1/3 functions, Init() // Path to current exe is used to the patcher can restart itself if needed RakNet::Lobby2ClientGFx3Impl sampleImpl; GPtr<FxDelegate> pDelegate = *new FxDelegate; pMovie->SetExternalInterface(pDelegate); RakNet::Lobby2Client lobby2Client; RakNet::Lobby2MessageFactory messageFactory; RakNet::RakPeerInterface *rakPeer = RakNet::RakPeerInterface::GetInstance(); RakNet::SocketDescriptor sd; rakPeer->Startup(1,&sd, 1); rakPeer->AttachPlugin(&lobby2Client); rakPeer->AttachPlugin(&sampleImpl); lobby2Client.SetMessageFactory(&messageFactory); lobby2Client.SetCallbackInterface(&sampleImpl); sampleImpl.Init(&lobby2Client, &messageFactory, rakPeer, pDelegate, pMovie); while(msg.message != WM_QUIT) { if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { // Check for lost D3D Devices. if (pRenderer) { GRendererD3D9::DisplayStatus status = pRenderer->CheckDisplayStatus(); if (status == GRendererD3D9::DisplayStatus_Unavailable) { ::Sleep(10); continue; } if (status == GRendererD3D9::DisplayStatus_NeedsReset) { if (!SUCCEEDED(ResetD3D())) continue; } } // Advance movie animation and render it to screen. AdvanceAndDisplay(); } // KevinJ: 2/3 functions, periodic update RakNet::Packet *p; for (p=rakPeer->Receive(); p; rakPeer->DeallocatePacket(p), p=rakPeer->Receive()) { } } // KevinJ: 3/3 functions, Shutdown() sampleImpl.Shutdown(); RakNet::RakPeerInterface::DestroyInstance(rakPeer); return 0; }
int FxPlayerTiny::Run() { // Windows conf if (!SetupWindow(GString(FXPLAYER_APP_TITLE " "))) return 1; ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); // Gfx conf GFxLoader loader; GPtr<GFxFileOpener> pfileOpener = *new GFxFileOpener; loader.SetFileOpener(pfileOpener); // Register FsCommandHander GPtr<GFxFSCommandHandler> pcommandHandler = *new FxPlayerFSCommandHandler; loader.SetFSCommandHandler(pcommandHandler); // Register FsDelegate pGameDelegate = *new FxDelegate(); loader.SetExternalInterface(pGameDelegate); pGameDelegate->RegisterHandler(this); GPtr<GFxImageCreator> pimageCreator = *new GFxImageCreator(1); loader.SetImageCreator(pimageCreator); // Login flash if (!(pMovieDef = *loader.CreateMovie(FXPLAYER_FILENAME))) { GString errorString = "Unable to load file: "; MessageBox(NULL, errorString.ToCStr(), "Error", MB_OK | MB_ICONEXCLAMATION); return 1; } if (!(pMovie = *pMovieDef->CreateInstance())) return 1; pMovie->SetViewport(Width, Height, 0,0, Width, Height); // HUD flash if (!(pHUDDef = *loader.CreateMovie(CONFIG_FILENAME))) { GString errorString = "Unable to load file: "; MessageBox(NULL, errorString.ToCStr(), "Error", MB_OK | MB_ICONEXCLAMATION); return 1; } if (!(pHUD = *pHUDDef->CreateInstance())) return 1; pHUD->SetBackgroundAlpha(0.0f); pHUD->SetViewport(Width, Height, 0,0, Width, Height); // render config if (!(pRenderer = *GRendererD3D9::CreateRenderer())) return 1; if (!pRenderer->SetDependentVideoMode(pDevice, &PresentParams, 0, hWnd)) return 1; pRenderConfig = *new GFxRenderConfig(pRenderer, GFxRenderConfig::RF_EdgeAA | GFxRenderConfig::RF_StrokeNormal); loader.SetRenderConfig(pRenderConfig); // how much to advance Flash playback. MovieLastTime = timeGetTime(); // Application / Player message loop. MSG msg; ZeroMemory(&msg, sizeof(msg)); while(msg.message != WM_QUIT && g_gamestate != GAME_STATE::QUIT) { if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { // Check for lost D3D Devices. if (pRenderer) { GRendererD3D9::DisplayStatus status = pRenderer->CheckDisplayStatus(); if (status == GRendererD3D9::DisplayStatus_Unavailable) { ::Sleep(10); continue; } if (status == GRendererD3D9::DisplayStatus_NeedsReset) { if (!SUCCEEDED(ResetD3D())) continue; } } switch (g_gamestate) { case GAME_STATE::LOGIN_SCREEN: DisplayLoginScreen(); break; case GAME_STATE::LOGINED: DisplayGameScreen(); break; default: break; } } } return 0; }