mainfrm.cpp

来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 1,788 行 · 第 1/5 页

CPP
1,788 行
字号
            break;
          }
        }
      }
    }
  }
  delete []pBuff;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	return CFrameWnd::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::CreateQEChildren()
{
	// the project file can be specified on the command line,
	// or implicitly found in the scripts directory
  bool bProjectLoaded = false;
	if (AfxGetApp()->m_lpCmdLine && strlen(AfxGetApp()->m_lpCmdLine))
	{
		ParseCommandLine (AfxGetApp()->m_lpCmdLine);
		bProjectLoaded = QE_LoadProject(argv[1]);
	}
	else 
  {
    if (g_PrefsDlg.m_bLoadLast && g_PrefsDlg.m_strLastProject.GetLength() > 0)
    {
	    bProjectLoaded = QE_LoadProject(g_PrefsDlg.m_strLastProject.GetBuffer(0));
    }
    if (!bProjectLoaded)
    {
      CString str = g_strAppPath;
      AddSlash(str);
      str += "../baseq3/scripts/quake.qe4";
      char cWork[1024];
      char *pFile = NULL;
      GetFullPathName(str, 1024, cWork, &pFile);
      bProjectLoaded = QE_LoadProject(cWork);
    }
    if (!bProjectLoaded)
    {
      bProjectLoaded = QE_LoadProject("scripts/quake.qe4");
    }
  }

  if (!bProjectLoaded)
  {
#if 0
    // let's try the default project directory..
    char* pBuff = new char[1024];
    ::GetCurrentDirectory(1024, pBuff);
    CString strDefProj = g_strAppPath;
    AddSlash(strDefProj);
    strDefProj += "defproj";
    if (::SetCurrentDirectory(strDefProj))
    {
	    bProjectLoaded = QE_LoadProject("scripts/quake.qe4");
      if (bProjectLoaded)
      {
        // setup auto load stuff for the default map
        g_PrefsDlg.m_bLoadLast = TRUE;
        AddSlash(strDefProj);
        strDefProj += "maps\\defproj.map";
        g_PrefsDlg.m_strLastMap = strDefProj;
        g_PrefsDlg.SavePrefs();
      }
    }
    else
    {
      ::SetCurrentDirectory(pBuff);
    }
    delete []pBuff;
#endif

    if (!bProjectLoaded)
    {
      Sys_Printf ("Using default.qe4. You may experience problems. See the readme.txt\n");
      CString strProj = g_strAppPath;
      strProj += "\\default.qe4";
      bProjectLoaded = QE_LoadProject(strProj.GetBuffer(0));

      if (!bProjectLoaded)
      {
        CFileDialog dlgFile(true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Q3Radiant Project files (*.qe4, *.prj)|*.qe4|*.prj||", this);
        if (dlgFile.DoModal() == IDOK)
          bProjectLoaded = QE_LoadProject(dlgFile.GetPathName().GetBuffer(0));
      }
    }
  }

  if (!bProjectLoaded)
    Error("Unable to load project file. It was unavailable in the scripts path and the default could not be found");


  if (g_PrefsDlg.m_bPAK == TRUE)
  {
    // FIXME: pay attention to Q3 pref
    //InitPakFile(ValueForKey(g_qeglobals.d_project_entity, "basepath"), g_PrefsDlg.m_strPAKFile);
    InitPakFile(ValueForKey(g_qeglobals.d_project_entity, "basepath"), NULL);
  }

	QE_Init ();
  
	Sys_Printf ("Entering message loop\n");

  m_bDoLoop = true;
	SetTimer(QE_TIMER0, 1000, NULL);

}

BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	return CFrameWnd::OnCommand(wParam, lParam);
}

LRESULT CMainFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
  RoutineProcessing();
	return CFrameWnd::DefWindowProc(message, wParam, lParam);
}


void CMainFrame::RoutineProcessing()
{
  if (m_bDoLoop)
  {
	  double time = 0.0;
    double oldtime = 0.0;
    double delta= 0.0;

    CheckBspProcess ();
	  time = Sys_DoubleTime ();
	  delta = time - oldtime;
	  oldtime = time;
	  if (delta > 0.2)
		  delta = 0.2;
	  
    // run time dependant behavior
    if (m_pCamWnd)
	    m_pCamWnd->Cam_MouseControl(delta);

    if (g_PrefsDlg.m_bQE4Painting && g_nUpdateBits)
    {
      int nBits = g_nUpdateBits;      // this is done to keep this routine from being
      g_nUpdateBits = 0;              // re-entered due to the paint process.. only
      UpdateWindows(nBits);           // happens in rare cases but causes a stack overflow
    }

  }
}

LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	return CFrameWnd::WindowProc(message, wParam, lParam);
}

bool MouseDown()
{
  if (::GetAsyncKeyState(VK_LBUTTON))
    return true;
  if (::GetAsyncKeyState(VK_RBUTTON))
    return true;
  if (::GetAsyncKeyState(VK_MBUTTON))
    return true;
  return false;
}


void CMainFrame::OnTimer(UINT nIDEvent) 
{
  if (!MouseDown())
  {
    QE_CountBrushesAndUpdateStatusBar();
    QE_CheckAutoSave();
  }
}
struct SplitInfo
{
  int m_nMin;
  int m_nCur;
};

bool LoadWindowPlacement(HWND hwnd, const char* pName)
{
  WINDOWPLACEMENT wp;
  wp.length = sizeof(WINDOWPLACEMENT);
	LONG lSize = sizeof(wp);
	if (LoadRegistryInfo(pName, &wp, &lSize))
  {
    ::SetWindowPlacement(hwnd, &wp);
    return true;
  }
  return false;
}

void SaveWindowPlacement(HWND hwnd, const char* pName)
{
  WINDOWPLACEMENT wp;
  wp.length = sizeof(WINDOWPLACEMENT);
  if (::GetWindowPlacement(hwnd, &wp))
  {
	  SaveRegistryInfo(pName, &wp, sizeof(wp));
  }
}


void CMainFrame::OnDestroy() 
{
  KillTimer(QE_TIMER0);

  SaveBarState("RadiantToolBars2");

  // FIXME
  // original mru stuff needs replaced with mfc stuff
	SaveMruInReg(g_qeglobals.d_lpMruMenu,"Software\\id\\QuakeEd4\\MRU");

	DeleteMruMenu(g_qeglobals.d_lpMruMenu);

  SaveWindowPlacement(GetSafeHwnd(), "Radiant::MainWindowPlace");
  //SaveWindowState(GetSafeHwnd(), "Radiant::MainWindow");
  //if (m_nCurrentStyle == QR_QE4)
    //SaveWindowPlacement(g_qeglobals.d_hwndEntity, "EntityWindowPlace");

  if (m_nCurrentStyle == 0 || m_nCurrentStyle == 3)
  {
    SaveWindowState(m_wndSplit.GetSafeHwnd(), "Radiant::Split");
    SaveWindowState(m_wndSplit2.GetSafeHwnd(), "Radiant::Split2");
    SaveWindowState(m_wndSplit3.GetSafeHwnd(), "Radiant::Split3");

    SplitInfo spinfo;
    m_wndSplit.GetRowInfo(0, spinfo.m_nCur, spinfo.m_nMin);
	  SaveRegistryInfo("Radiant::Split::Row_0", &spinfo, sizeof(spinfo));
    m_wndSplit.GetRowInfo(1, spinfo.m_nCur, spinfo.m_nMin);
	  SaveRegistryInfo("Radiant::Split::Row_1", &spinfo, sizeof(spinfo));

    m_wndSplit2.GetColumnInfo(0, spinfo.m_nCur, spinfo.m_nMin);
	  SaveRegistryInfo("Radiant::Split2::Col_0", &spinfo, sizeof(spinfo));
    m_wndSplit2.GetColumnInfo(1, spinfo.m_nCur, spinfo.m_nMin);
	  SaveRegistryInfo("Radiant::Split2::Col_1", &spinfo, sizeof(spinfo));
    m_wndSplit2.GetColumnInfo(2, spinfo.m_nCur, spinfo.m_nMin);
	  SaveRegistryInfo("Radiant::Split2::Col_2", &spinfo, sizeof(spinfo));

    m_wndSplit3.GetRowInfo(0, spinfo.m_nCur, spinfo.m_nMin);
	  SaveRegistryInfo("Radiant::Split3::Row_0", &spinfo, sizeof(spinfo));
    m_wndSplit3.GetRowInfo(1, spinfo.m_nCur, spinfo.m_nMin);
	  SaveRegistryInfo("Radiant::Split3::Row_1", &spinfo, sizeof(spinfo));
  }
  else 
  {
    SaveWindowPlacement(m_pXYWnd->GetSafeHwnd(), "xywindow");
    SaveWindowPlacement(m_pXZWnd->GetSafeHwnd(), "xzwindow");
    SaveWindowPlacement(m_pYZWnd->GetSafeHwnd(), "yzwindow");
	  SaveWindowPlacement(m_pCamWnd->GetSafeHwnd(), "camerawindow");
	  SaveWindowPlacement(m_pZWnd->GetSafeHwnd(), "zwindow");
	  SaveWindowState(m_pTexWnd->GetSafeHwnd(), "texwindow");
	  SaveWindowState(m_pEditWnd->GetSafeHwnd(), "editwindow");
  }

  if (m_pXYWnd->GetSafeHwnd())
    m_pXYWnd->SendMessage(WM_DESTROY, 0, 0);
  delete m_pXYWnd; m_pXYWnd = NULL;
  
  if (m_pYZWnd->GetSafeHwnd())
    m_pYZWnd->SendMessage(WM_DESTROY, 0, 0);
  delete m_pYZWnd; m_pYZWnd = NULL;
  
  if (m_pXZWnd->GetSafeHwnd())
    m_pXZWnd->SendMessage(WM_DESTROY, 0, 0);
  delete m_pXZWnd; m_pXZWnd = NULL;
  
  if (m_pZWnd->GetSafeHwnd())
    m_pZWnd->SendMessage(WM_DESTROY, 0, 0);
  delete m_pZWnd; m_pZWnd = NULL;
  
  if (m_pTexWnd->GetSafeHwnd())
    m_pTexWnd->SendMessage(WM_DESTROY, 0, 0);
  delete m_pTexWnd; m_pTexWnd = NULL;
  
  if (m_pEditWnd->GetSafeHwnd())
    m_pEditWnd->SendMessage(WM_DESTROY, 0, 0);
  delete m_pEditWnd; m_pEditWnd = NULL;

  if (m_pCamWnd->GetSafeHwnd())
    m_pCamWnd->SendMessage(WM_DESTROY, 0, 0);
  delete m_pCamWnd;m_pCamWnd = NULL;

	SaveRegistryInfo("SavedInfo", &g_qeglobals.d_savedinfo, sizeof(g_qeglobals.d_savedinfo));

  if (strcmpi(currentmap, "unnamed.map") != 0)
  {
    g_PrefsDlg.m_strLastMap = currentmap;
    g_PrefsDlg.SavePrefs();
  }
  CleanUpEntities();

  while (active_brushes.next != &active_brushes)
	  Brush_Free (active_brushes.next, false);
	while (selected_brushes.next != &selected_brushes)
		Brush_Free (selected_brushes.next, false);
	while (filtered_brushes.next != &filtered_brushes)
		Brush_Free (filtered_brushes.next, false);

	while (entities.next != &entities)
		Entity_Free (entities.next);

	epair_t* pEPair = g_qeglobals.d_project_entity->epairs;
  while (pEPair)
  {
    epair_t* pNextEPair = pEPair->next;
    free (pEPair->key);
    free (pEPair->value);
    free (pEPair);
    pEPair = pNextEPair;
  }

	entity_t* pEntity = g_qeglobals.d_project_entity->next;
  while (pEntity != NULL && pEntity != g_qeglobals.d_project_entity)
  {
    entity_t* pNextEntity = pEntity->next;
    Entity_Free(pEntity);
    pEntity = pNextEntity;
  }

  Texture_Cleanup();

  if (world_entity)
    Entity_Free(world_entity);

  if (notexture)
  {
  // Timo
  // Surface properties plugin
#ifdef _DEBUG
  if ( !notexture->pData )
	  Sys_Printf("WARNING: found a qtexture_t* with no IPluginQTexture\n");
#endif
  if ( notexture->pData )

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?