int CCustomPlayer::InitEngine(HWND iMainWindow) { m_MainWindow = iMainWindow; // start the Virtools Engine CKStartUp(); // retrieve the plugin manager ... CKPluginManager* pluginManager = CKGetPluginManager(); // ... to intialize plugins ... if (!_InitPlugins(*pluginManager)) { MessageBox(NULL,UNABLE_TO_INIT_PLUGINS,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } // ... and the render engine. int renderEngine = _InitRenderEngines(*pluginManager); if (renderEngine==-1) { MessageBox(NULL,UNABLE_TO_LOAD_RENDERENGINE,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } XString inifile = CKGetStartPath(); inifile << "CompositionPrefs_R_Hi.ini"; CKERROR res = CKCreateContext(&m_CKContext,m_MainWindow,inifile.Str()); if (res!=CK_OK) { MessageBox(NULL,UNABLE_TO_INIT_CK,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } // retrieve the main managers which will be used by the player m_MessageManager = m_CKContext->GetMessageManager(); m_RenderManager = m_CKContext->GetRenderManager(); m_TimeManager = m_CKContext->GetTimeManager(); m_AttributeManager = m_CKContext->GetAttributeManager(); m_InputManager = (CKInputManager*)m_CKContext->GetManagerByGuid(INPUT_MANAGER_GUID); if (!m_MessageManager || !m_RenderManager || !m_TimeManager || !m_AttributeManager || !m_InputManager) { MessageBox(NULL,UNABLE_TO_INIT_MANAGERS,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } // initialize the display driver using the player configuration (resolution, rasterizer, ...) if (!_InitDriver()) { MessageBox(NULL,UNABLE_TO_INIT_DRIVER,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } return TRUE; }
HMODULE GBLCommon::ResourceTools:: GetParentModule(CK_PLUGIN_TYPE type,CKGUID guid) { CKPluginManager* ThePluginManager=CKGetPluginManager(); for (int i=0;i<ThePluginManager->GetPluginDllCount();i++) { CKPluginEntry* desc=ThePluginManager->GetPluginInfo(type,i); CKPluginDll* dll =ThePluginManager->GetPluginDllInfo(desc->m_PluginDllIndex); if (desc->m_PluginInfo.m_GUID == guid) return ((HMODULE)dll->m_DllInstance); } return NULL; }
BOOL CCustomPlayer::InitPlayer(HWND iMainWindow, HWND iRenderWindow, int iConfig, const void* iData,int iDataSize) { // keep a reference on the main/render window m_MainWindow = iMainWindow; m_RenderWindow = iRenderWindow; // start the Virtools Engine //CKInitCustomPlayer(false); CKStartUp(); ////////////////////////////////////////////////////////////////////////// // we have unmet requirements ? XString errorText; int hasError = DoSystemCheck(errorText); ////////////////////////////////////////////////////////////////////////// // show splash when we have no error and we are not in the explicit configuration mode ( invoked by : "CustomPlayer.exe -c ") : if( GetPAppStyle()->UseSplash() && !hasError && PGetApplicationMode() != config ) { ShowSplash(); } // retrieve the plugin manager ... CKPluginManager* pluginManager = CKGetPluginManager(); ////////////////////////////////////////////////////////////////////////// // ... to intialize plugins ... if (!_InitPlugins(*pluginManager)) { MessageBox(NULL,UNABLE_TO_INIT_PLUGINS,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } ////////////////////////////////////////////////////////////////////////// // ... and the render engine. int renderEngine = _InitRenderEngines(*pluginManager); if (renderEngine==-1) { MessageBox(NULL,UNABLE_TO_LOAD_RENDERENGINE,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } ////////////////////////////////////////////////////////////////////////// // now create the CK context XString inifile = CKGetStartPath(); inifile << "CompositionPrefs_R_Hi.ini"; CKERROR res = CKCreateContext(&m_CKContext,m_MainWindow,inifile.Str()); if (res!=CK_OK) { MessageBox(NULL,UNABLE_TO_INIT_CK,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } #if defined(CUSTOM_PLAYER_STATIC) // if the player is not static char BehaviorPath[_MAX_PATH]; char szPath[_MAX_PATH]; VxGetModuleFileName(NULL,szPath,_MAX_PATH); CKPathSplitter ps(szPath); sprintf(BehaviorPath,"%s%s%s",ps.GetDrive(),ps.GetDir(),GetEPathProfile()->BehaviorPath.Str()); pluginManager->ParsePlugins(BehaviorPath); #endif ////////////////////////////////////////////////////////////////////////// // adding load callback if(GetPAppStyle()->UseSplash() && !m_LastError && PGetApplicationMode() != config ) { if (GetPAppStyle()->ShowLoadingProcess()) { m_CKContext->SetInterfaceMode(FALSE,LoadCallBack,NULL); } } // retrieve the main managers which will be used by the player m_MessageManager = m_CKContext->GetMessageManager(); m_RenderManager = m_CKContext->GetRenderManager(); m_TimeManager = m_CKContext->GetTimeManager(); m_AttributeManager = m_CKContext->GetAttributeManager(); m_EnginePointers.TheMessageManager = m_MessageManager; m_EnginePointers.TheRenderManager = m_RenderManager; m_EnginePointers.TheTimeManager = m_TimeManager; m_EnginePointers.TheCKContext = m_CKContext; //We have an error, show our dialog : if (hasError) { AfxInitRichEdit2(); CustomPlayerDialog k(NULL,CString(errorText.Str())); k.DoModal(); if (CPA_ABORT_ON_ERROR) { return FALSE; } } m_InputManager = (CKInputManager*)m_CKContext->GetManagerByGuid(INPUT_MANAGER_GUID); if (!m_MessageManager || !m_RenderManager || !m_TimeManager || !m_AttributeManager || !m_InputManager) { MessageBox(NULL,UNABLE_TO_INIT_MANAGERS,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } // initialize the display driver using the player configuration (resolution, rasterizer, ...) if (!_InitDriver()) { MessageBox(NULL,UNABLE_TO_INIT_DRIVER,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } PLoadResourcePaths(CUSTOM_PLAYER_CONFIG_FILE,"Textures",0); PLoadResourcePaths(CUSTOM_PLAYER_CONFIG_FILE,"Data",1); PLoadResourcePaths(CUSTOM_PLAYER_CONFIG_FILE,"Music",2); // now load the composition if (iDataSize) { // if iDataSize is not null it means the composition is already in memory if (_Load(iData,iDataSize)!=CK_OK) { MessageBox(NULL,"Unable to load composition from memory.","Initialization Error",MB_OK|MB_ICONERROR); return FALSE; } } else if (_Load((const char*)iData)!=CK_OK) { // else we load it from a file (iData contains the filename) MessageBox(NULL,"Unable to load composition from file.","Initialization Error",MB_OK|MB_ICONERROR); return FALSE; } //GetPlayer().HideSplash(); //show our dialog ? if (GetPAppStyle()->g_ShowDialog) { AfxInitRichEdit2(); CustomPlayerDialog k(NULL,CString(errorText.Str())); k.DoModal(); } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // update of our member variables vtPlayer::Structs::xSEnginePointers* ep = GetPlayer().GetEnginePointers(); vtPlayer::Structs::xSEngineWindowInfo* ewinfo = GetPlayer().GetEngineWindowInfo(); m_WindowedHeight = ewinfo->g_HeightW; m_WindowedWidth = ewinfo->g_WidthW; m_FullscreenWidth = ewinfo->g_Width; m_FullscreenHeight = ewinfo->g_Height; if(ewinfo->g_GoFullScreen) m_Driver = ewinfo->g_FullScreenDriver; else m_Driver = ewinfo->g_WindowedDriver; m_FullscreenBpp = ewinfo->g_Bpp; ////////////////////////////////////////////////////////////////////////// CKVariableManager *vm = (CKVariableManager *)m_EnginePointers.TheCKContext->GetVariableManager(); vm->SetValue("CK2_3D/Antialias", GetEWindowInfo()->FSSA * 2 ); if(PGetApplicationMode() != config) { if (GetPlayer().GetPAppStyle()->IsRenderering()) { ////////////////////////////////////////////////////////////////////////// // create the render context if (GetEWindowInfo()->g_GoFullScreen) { // in fullscreen we specify the rendering size using a rectangle (CKRECT) CKRECT rect; rect.left = 0; rect.top = 0; rect.right = m_FullscreenWidth; rect.bottom = m_FullscreenHeight; // create the render context m_RenderContext = m_RenderManager->CreateRenderContext(m_RenderWindow,GetEWindowInfo()->g_FullScreenDriver,&rect,TRUE,m_FullscreenBpp); // set the position of the render window ::SetWindowPos(m_RenderWindow,NULL,0,0,m_FullscreenWidth,m_FullscreenHeight,SWP_NOMOVE|SWP_NOZORDER); // resize the render context if (m_RenderContext) { m_RenderContext->Resize(0,0,m_FullscreenWidth,m_FullscreenHeight); } } else { ////////////////////////////////////////////////////////////////////////// // [2/18/2008 mc007] // we only repositioning the window when we are not displayed by a hosting application like // a charp panel ! if (!GetPAppStyle()->g_OwnerDrawed) { LONG st = GetWindowLong(m_MainWindow,GWL_STYLE); st|=WS_THICKFRAME; st&=~WS_SIZEBOX; SetWindowLong(m_MainWindow,GWL_STYLE,st); //reposition the window m_MainWindowRect.left = (GetSystemMetrics(SM_CXSCREEN)-m_WindowedWidth)/2; m_MainWindowRect.right = m_WindowedWidth+m_MainWindowRect.left; m_MainWindowRect.top = (GetSystemMetrics(SM_CYSCREEN)-m_WindowedHeight)/2; m_MainWindowRect.bottom = m_WindowedHeight+m_MainWindowRect.top; BOOL ret = AdjustWindowRect(&m_MainWindowRect,WS_OVERLAPPEDWINDOW & ~(WS_SYSMENU|WS_SIZEBOX|WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_SIZEBOX),FALSE); ::SetWindowPos(m_MainWindow,0,m_MainWindowRect.left,m_MainWindowRect.top,m_MainWindowRect.right - m_MainWindowRect.left,m_MainWindowRect.bottom - m_MainWindowRect.top,NULL); // set the position of the render window ::SetWindowPos(m_RenderWindow,NULL,0,0,m_WindowedWidth,m_WindowedHeight,SWP_NOMOVE|SWP_NOZORDER); } // create the render context m_RenderContext = m_RenderManager->CreateRenderContext(m_RenderWindow,m_Driver,0,FALSE); // resize the render context if (m_RenderContext) { m_RenderContext->Resize(0,0,m_WindowedWidth,m_WindowedHeight); } } ////////////////////////////////////////////////////////////////////////// // when somebody changed any resolution in the configuration tab , we should update our windows : //store current size /* GetWindowRect(m_MainWindow,&m_MainWindowRect); LONG st = GetWindowLong(m_MainWindow,GWL_STYLE); st|=WS_THICKFRAME; st&=~WS_SIZEBOX; SetWindowLong(m_MainWindow,GWL_STYLE,st); //reposition the window m_MainWindowRect.left = (GetSystemMetrics(SM_CXSCREEN)-m_WindowedWidth)/2; m_MainWindowRect.right = m_WindowedWidth+m_MainWindowRect.left; m_MainWindowRect.top = (GetSystemMetrics(SM_CYSCREEN)-m_WindowedHeight)/2; m_MainWindowRect.bottom = m_WindowedHeight+m_MainWindowRect.top; BOOL ret = AdjustWindowRect(&m_MainWindowRect,WS_OVERLAPPEDWINDOW & ~(WS_SYSMENU|WS_SIZEBOX|WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_SIZEBOX),FALSE); ::SetWindowPos(m_MainWindow,0,m_MainWindowRect.left,m_MainWindowRect.top,m_MainWindowRect.right - m_MainWindowRect.left,m_MainWindowRect.bottom - m_MainWindowRect.top,NULL); // and set the position of the render window in the main window ::SetWindowPos(m_RenderWindow,NULL,0,0,m_WindowedWidth,m_WindowedHeight,SWP_NOMOVE|SWP_NOZORDER); m_RenderContext->Resize(0,0,GetEWindowInfo()->g_GoFullScreen ? m_FullscreenWidth : m_WindowedWidth, GetEWindowInfo()->g_GoFullScreen ? m_FullscreenHeight : m_WindowedHeight);*/ if (!m_RenderContext) { MessageBox(NULL,UNABLE_TO_CREATE_RENDERCONTEXT,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } ////////////////////////////////////////////////////////////////////////// // clear the render view m_RenderContext->Clear(); m_RenderContext->BackToFront(); m_RenderContext->Clear(); } // finalize the loading if (!_FinishLoad()) { return FALSE; } } return TRUE; }