Exemplo n.º 1
0
BOOL CModelerApp::SubInitInstance()
{
  char strIni[ 128];
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

  // settings will be saved into registry instead of ini file
  SetRegistryKey( "LastChaos");

	LoadStdProfileSettings(8);  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CMultiDocTemplate* pDocTemplate;
	m_pdtModelDocTemplate = pDocTemplate = new CMultiDocTemplate(
		IDR_MDLDOCTYPE,
		RUNTIME_CLASS(CModelerDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CModelerView));
	AddDocTemplate(pDocTemplate);
  
  m_pdtScriptTemplate = pDocTemplate = new CMultiDocTemplate(
		IDR_SCRIPTDOCTYPE,
		RUNTIME_CLASS(CScriptDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CScriptView));
	AddDocTemplate(pDocTemplate);

  // initialize engine, without network
  SE_InitEngine("");  // DO NOT SPECIFY NAME HERE!
  SE_LoadDefaultFonts();

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if( !pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE;
  m_pMainWnd = pMainFrame;
  
  // set main window for engine
  SE_UpdateWindowHandle( m_pMainWnd->m_hWnd);

	// Enable drag/drop open
	m_pMainWnd->DragAcceptFiles();

	// Enable DDE Execute open
	EnableShellOpen();
	RegisterShellFileTypes(TRUE);

  // load startup script
  _pShell->Execute( "include \"Scripts\\Modeler_startup.ini\"");
  
//안태훈 수정 시작	//(Modify Default API to D3D)(0.1)
  m_iApi=GAT_D3D;
  m_iApi=GetProfileInt("Display modes", "SED Gfx API", GAT_D3D);
//안태훈 수정 끝	//(Modify Default API to D3D)(0.1)
  // (re)set default display mode
  _pGfx->ResetDisplayMode((enum GfxAPIType) m_iApi);

  m_Preferences.ReadFromIniFile();

  // load background textures
  INDEX iWorkingTexturesCt = theApp.GetProfileInt( "Modeler prefs", 
                                                   "Modeler working textures count", -1);
  if( iWorkingTexturesCt != -1) {
    char strWTName[ 128];
    for( INDEX i=0; i<iWorkingTexturesCt; i++) {
      sprintf( strWTName, "Working texture %02d", i);
      INI_READ( strWTName, "Error in INI .file!");
      AddModelerWorkingTexture( CTString(strIni));
    }
  }
  // load working patches
  INDEX iWorkingPatchesCt = theApp.GetProfileInt( "Modeler prefs", 
                                                 "Modeler working patches count", -1);
  char strWPName[ 128];
  for( INDEX i=0; i<iWorkingPatchesCt; i++) {
    sprintf( strWPName, "Working patch %02d", i);
    INI_READ( strWPName, "Error in INI .file!");
    AddModelerWorkingPatch( CTString(strIni));
  }
  pMainFrame->m_StainsComboBox.Refresh();

  // create temporary directory to contain copy/paste mapping all
  CreateDirectory( _fnmApplicationPath + "Temp\\", NULL);
  
  // try to
  try
  { // load lamp model
    DECLARE_CTFILENAME( fnLampName, "Data\\Models\\Editor\\Lamp.mdl");
    m_pLampModelData = _pModelStock->Obtain_t( fnLampName);
    m_LampModelObject = new CModelObject;
    m_LampModelObject->SetData(m_pLampModelData);
    m_LampModelObject->SetAnim( 0);
    // load lamp's texture
    DECLARE_CTFILENAME( fnLampTex, "Data\\Models\\Editor\\SpotLight.tex");
    m_ptdLamp = _pTextureStock->Obtain_t( fnLampTex);
    m_LampModelObject->mo_toTexture.SetData( m_ptdLamp); 

    // load collision box model
    DECLARE_CTFILENAME( fnCollisionBox, "Data\\Models\\Editor\\CollisionBox.mdl");
    m_pCollisionBoxModelData = _pModelStock->Obtain_t( fnCollisionBox);
    m_pCollisionBoxModelObject = new CModelObject;
    m_pCollisionBoxModelObject->SetData(m_pCollisionBoxModelData);
    m_pCollisionBoxModelObject->SetAnim( 0);
    // load collision box's texture
    DECLARE_CTFILENAME( fnCollisionBoxTex, "Data\\Models\\Editor\\CollisionBox.tex");
    m_ptdCollisionBoxTexture = _pTextureStock->Obtain_t( fnCollisionBoxTex);
    m_pCollisionBoxModelObject->mo_toTexture.SetData( m_ptdCollisionBoxTexture); 

    // load floor model
    DECLARE_CTFILENAME( fnFloor, "Data\\Models\\Editor\\Floor.mdl");
    m_pFloorModelData = _pModelStock->Obtain_t( fnFloor);
    m_pFloorModelObject = new CModelObject;
    m_pFloorModelObject->SetData(m_pFloorModelData);
    m_pFloorModelObject->SetAnim( 0);
    // load collision box's texture
    DECLARE_CTFILENAME( fnFloorTex, "Data\\Models\\Editor\\Floor.tex");
    m_ptdFloorTexture = _pTextureStock->Obtain_t( fnFloorTex);
    m_pFloorModelObject->mo_toTexture.SetData( m_ptdFloorTexture); 

    DECLARE_CTFILENAME( fnShadowTex, "Data\\Textures\\Effects\\Shadow\\SimpleModelShadow.tex");
    // setup simple model shadow texture
    _toSimpleModelShadow.SetData_t( fnShadowTex);
  }
  catch( char *err_str)
  { // report error and continue without models
    AfxMessageBox( err_str);

    // if we allocated model object for collision box
    if( m_pCollisionBoxModelObject != NULL) {
      // delete it
      delete m_pCollisionBoxModelObject;
      m_pCollisionBoxModelObject = NULL;
    }
    // if we loaded collision box's texture
    if( m_ptdCollisionBoxTexture != NULL) {
      // release it and
      _pTextureStock->Release( m_ptdCollisionBoxTexture);
      m_ptdCollisionBoxTexture = NULL;
    }

    // if we loaded lamp's texture
    if( m_ptdLamp != NULL) {
      // release it and
      _pTextureStock->Release( m_ptdLamp);
      m_ptdLamp = NULL;
    }

    // if we allocated model object for floor
    if( m_pFloorModelObject != NULL) {
      // delete it
      delete m_pFloorModelObject;
      m_pFloorModelObject = NULL;
    }
    // if we loaded floor's texture
    if( m_ptdFloorTexture != NULL) {
      // release it and
      _pTextureStock->Release( m_ptdFloorTexture);
      m_ptdFloorTexture = NULL;
    }
  }

  // assign system font
  m_pfntFont = _pfdDisplayFont;

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

  if(CTString("")==CTString(cmdInfo.m_strFileName))
  {
    cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
  }
  else
  {
    cmdInfo.m_nShellCommand = CCommandLineInfo::FileOpen;
  }
  // Dispatch commands specified on the command line
	if( !ProcessShellCommand(cmdInfo)) return FALSE;

	// The main window has been initialized, so show and update it.
  m_nCmdShow = SW_SHOWMAXIMIZED; // maximize main frame !!!
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

  // if stating modeler for the first time
  if( m_bFirstTimeStarted) {
    // call preferences
    OnFilePreferences();
  }
  
  return TRUE;
}
Exemplo n.º 2
0
void CChildFrame::TestGame( BOOL bFullScreen) 
{
  // turn off info window
  CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  pMainFrame->HideInfoWindow();

  CWorldEditorView *pPerspectiveView = GetPerspectiveView();
  ASSERT( pPerspectiveView != NULL);
  SetActiveView( pPerspectiveView, FALSE);
	CWorldEditorDoc* pDoc = pPerspectiveView->GetDocument();

  CTFileName fnmWorldToPlay;
  CTFileName fnmTempWorld = CTString("Temp\\TestGame.wld");

  // if the world was never saved or if it is modified
  if( (!pDoc->m_bWasEverSaved && wed_bSaveTestGameFirstTime) || pDoc->IsModified())
  { // save world under temporary name
    ASSERT_VALID(pDoc);
    try {  
      pDoc->m_woWorld.Save_t(fnmTempWorld);
      fnmWorldToPlay = fnmTempWorld;
    } catch( char *strError) {
      AfxMessageBox( CString(strError));
      pPerspectiveView->EnableToolTips(TRUE);
      return;
    }
  // if the world is not modified (it is saved on disk)
  } else
  { // use the saved world
    fnmWorldToPlay = CTString(CStringA(pDoc->GetPathName()));
    try {
      fnmWorldToPlay.RemoveApplicationPath_t();
    } catch( char *strError) {
      AfxMessageBox( CString(strError));
      pPerspectiveView->EnableToolTips(TRUE);
      return;
    }
  }

  // set rendering preferences
  _wrpWorldRenderPrefs = pPerspectiveView->m_vpViewPrefs.m_wrpWorldRenderPrefs;
  _mrpModelRenderPrefs = pPerspectiveView->m_vpViewPrefs.m_mrpModelRenderPrefs;
  _wrpWorldRenderPrefs.SetShadowsType( pPerspectiveView->GetChildFrame()->m_stShadowType);
  _wrpWorldRenderPrefs.SetSelectedEntityModel( theApp.m_pEntityMarkerModelObject);
  _wrpWorldRenderPrefs.SetSelectedPortalModel( theApp.m_pPortalMarkerModelObject);
  _wrpWorldRenderPrefs.SetEmptyBrushModel( theApp.m_pEmptyBrushModelObject);
  _wrpWorldRenderPrefs.SetTextureLayerOn( theApp.m_bTexture1, 0);
  _wrpWorldRenderPrefs.SetTextureLayerOn( theApp.m_bTexture2, 1);
  _wrpWorldRenderPrefs.SetTextureLayerOn( theApp.m_bTexture3, 2);
  _wrpWorldRenderPrefs.DisableVisTweaks(FALSE);

  _wrpWorldRenderPrefs.SetSelectedEntityModel( theApp.m_pEntityMarkerModelObject);
  _wrpWorldRenderPrefs.SetSelectedPortalModel( theApp.m_pPortalMarkerModelObject);
  _wrpWorldRenderPrefs.SetEmptyBrushModel( theApp.m_pEmptyBrushModelObject);

  // prepare test game view/draw ports
  CViewPort *pvp = pPerspectiveView->m_pvpViewPort;
  CDrawPort *pdp = pPerspectiveView->m_pdpDrawPort;
  pdp->SetOverlappedRendering(FALSE); // we are not rendering scene over already rendered scene (used for CSG layer)

  // if full screen mode is required
  HWND hWndFullScreen=NULL;
  HINSTANCE hInstanceFullScreen;
  WNDCLASSEX wcFullScreen;
  char achWindowTitle[256]; // current window title
  if( bFullScreen) 
  {
    // get full screen display mode info
    const PIX pixSizeI = theApp.m_dmFullScreen.dm_pixSizeI;
    const PIX pixSizeJ = theApp.m_dmFullScreen.dm_pixSizeJ;
    const DisplayDepth dd = theApp.m_dmFullScreen.dm_ddDepth;
    const GfxAPIType gat  = theApp.m_gatFullScreen;
    // set OpenGL fullscreen (before window)
    if( gat==GAT_OGL) {
      const BOOL bRes = _pGfx->SetDisplayMode( gat, 0, pixSizeI, pixSizeJ, dd);
      if( !bRes) {
        WarningMessage( "Unable to setup full screen display.");
        return;
      }
    } // register the window class
    hInstanceFullScreen = AfxGetInstanceHandle();
    ASSERT( hInstanceFullScreen!=NULL);
    wcFullScreen.cbSize = sizeof(wcFullScreen);
    wcFullScreen.style = CS_HREDRAW | CS_VREDRAW;
    wcFullScreen.lpfnWndProc = ::DefWindowProc;
    wcFullScreen.cbClsExtra = 0;
    wcFullScreen.cbWndExtra = 0;
    wcFullScreen.hInstance = hInstanceFullScreen;
    wcFullScreen.hIcon = LoadIcon( hInstanceFullScreen, (LPCTSTR)IDR_MAINFRAME );
    wcFullScreen.hCursor = NULL;
    wcFullScreen.hbrBackground = NULL;
    wcFullScreen.lpszMenuName  = CString(APPLICATION_NAME);
    wcFullScreen.lpszClassName = CString(APPLICATION_NAME);
    wcFullScreen.hIconSm = NULL;
    RegisterClassEx(&wcFullScreen);

    // create a window, invisible initially
    hWndFullScreen = CreateWindowExA(
      WS_EX_TOPMOST,
      APPLICATION_NAME,
      "Serious Editor - Full Screen Test Game",   // title
      WS_POPUP,
      0,0,
      pixSizeI, pixSizeJ,  // window size
      NULL,
      NULL,
      hInstanceFullScreen,
      NULL);
    // didn't make it?
    ASSERT( hWndFullScreen!=NULL);
    if( hWndFullScreen==NULL) {
      if( gat==GAT_OGL) _pGfx->ResetDisplayMode( (enum GfxAPIType)theApp.m_iApi);
      WarningMessage( "Unable to setup window for full screen display.");
      return;
    }
    // set windows for engine
    CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
    SE_UpdateWindowHandle( hWndFullScreen);

    // set window title and show it
    sprintf( achWindowTitle, "Serious Editor - Test Game (FullScreen %dx%d)", pixSizeI, pixSizeJ);
    ::SetWindowTextA( hWndFullScreen, achWindowTitle);
    ::ShowWindow(    hWndFullScreen, SW_SHOWNORMAL);

    // set Direct3D full screen (after window)
#ifdef SE1_D3D
    if( gat==GAT_D3D) {
      const BOOL bRes = _pGfx->SetDisplayMode( gat, 0, pixSizeI, pixSizeJ, dd);
      if( !bRes) {
        WarningMessage( "Unable to setup full screen display.");
        ::DestroyWindow( hWndFullScreen);
        SE_UpdateWindowHandle( pMainFrame->m_hWnd);
        return;
      }
    }
#endif // SE1_D3D
    // create canvas
    _pGfx->CreateWindowCanvas( hWndFullScreen, &pvp, &pdp);
    // initial screen fill and swap, just to get context running
    BOOL bSuccess = FALSE;
    if( pdp!=NULL && pdp->Lock()) {
      pdp->Fill(C_dGREEN|CT_OPAQUE);
      pdp->Unlock();
      pvp->SwapBuffers();
      bSuccess = TRUE;
    }
    // must succeed!
    ASSERT( bSuccess);
    if( !bSuccess) {
      _pGfx->ResetDisplayMode( (enum GfxAPIType)theApp.m_iApi);
      WarningMessage( "Unable to setup canvas for full screen display.");
      return;
    }
  }

  // enable sound
  snd_iFormat = Clamp( snd_iFormat, (INDEX)CSoundLibrary::SF_NONE, (INDEX)CSoundLibrary::SF_44100_16);
  _pSound->SetFormat( (enum CSoundLibrary::SoundFormat)snd_iFormat, TRUE);

  // run quick test game
  extern BOOL _bInOnDraw; 
  _bInOnDraw = TRUE;
  _pGameGUI->QuickTest( fnmWorldToPlay, pdp, pvp);
  _bInOnDraw = FALSE;

  // disable sound
  _pSound->SetFormat( CSoundLibrary::SF_NONE);

  // restore default display mode and close test full screen window
  if( hWndFullScreen!=NULL) {
    _pGfx->ResetDisplayMode( (enum GfxAPIType)theApp.m_iApi);
    ::DestroyWindow( hWndFullScreen);
    SE_UpdateWindowHandle( pMainFrame->m_hWnd);
  }
  // redraw all views
  pDoc->UpdateAllViews( NULL);
  pPerspectiveView->EnableToolTips( TRUE);
}