📄 geneditpreviewdlg.cpp
字号:
/****************************************************************************************/
/* GenEditPreviewDlg.cpp */
/* */
/* Author: Tom Morris */
/* Description: QuickViewer for viewing *.bsp files with the engine */
/* */
/* The contents of this file are subject to the Genesis3D Public License */
/* Version 1.01 (the "License"); you may not use this file except in */
/* compliance with the License. You may obtain a copy of the License at */
/* http://www.genesis3d.com */
/* */
/* Software distributed under the License is distributed on an "AS IS" */
/* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */
/* the License for the specific language governing rights and limitations */
/* under the License. */
/* */
/* The Original Code is Genesis3D, released March 25, 1999. */
/* Genesis3D Version 1.1 released November 15, 1999 */
/* Copyright (C) 1999 WildTangent, Inc. All Rights Reserved */
/* */
/* Modified by Tom Morris for GenEdit-Classic ver. 0.57, Feb. 3, 2001 */
/****************************************************************************************/
#include "stdafx.h"
#include "genedit.h"
#include "GenEditPreviewDlg.h"
#include "DirectInput\DirectInputMgr.h"
extern LPDIRECTINPUTDEVICE g_pdevJoystick;
extern LPDIRECTINPUTDEVICE g_pdevKeyboard;
extern LPDIRECTINPUTDEVICE g_pdevMouse;
extern DIDEVCAPS g_diDevCaps;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGenEditPreviewDlg dialog
CGenEditPreviewDlg::CGenEditPreviewDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGenEditPreviewDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGenEditPreviewDlg)
m_cameraXPos = 0;
m_cameraYPos = 0;
m_cameraZPos = 0;
m_DriverName = _T("");
m_bDrawGripper = FALSE;
Width = 640;
Height = 480;
m_collisionDetection = false; // no collision detection
m_previewLevelPath = _T("");
//}}AFX_DATA_INIT
}
void CGenEditPreviewDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGenEditPreviewDlg)
DDX_Control(pDX, IDC_ZERO_CAMERA_BTN, m_zeroCameraBtn);
DDX_Control(pDX, IDC_CAMERA_SLIDERZ, m_cameraSliderZ);
DDX_Control(pDX, IDC_CAMERA_SLIDERY, m_cameraSliderY);
DDX_Control(pDX, IDC_CAMERA_SLIDERX, m_cameraSliderX);
DDX_Control(pDX, IDC_SOFTWARE_TEXT, m_softwareText);
DDX_Control(pDX, IDC_SHOW_PREVIEW_BTN, m_previewWithEngineBtn);
DDX_Control(pDX, IDC_PREVIEW_LIST, m_previewLevelList);
DDX_Text(pDX, IDC_CAMERA_X, m_cameraXPos);
DDX_Text(pDX, IDC_CAMERA_Y, m_cameraYPos);
DDX_Text(pDX, IDC_CAMERA_Z, m_cameraZPos);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGenEditPreviewDlg, CDialog)
//{{AFX_MSG_MAP(CGenEditPreviewDlg)
ON_BN_CLICKED(IDC_SHOW_PREVIEW_BTN, OnShowPreviewBtn)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_PREVIEW_BROWSE_BTN, OnPreviewBrowseBtn)
ON_BN_CLICKED(IDC_RADIO_640, OnRadio640)
ON_BN_CLICKED(IDC_RADIO_1024, OnRadio1024)
ON_BN_CLICKED(IDC_RADIO_800, OnRadio800)
ON_BN_CLICKED(IDC_RADIO_COLLIDE, OnRadioCollide)
ON_BN_CLICKED(IDC_RADIO_NOCOLLIDE, OnRadioNocollide)
ON_BN_CLICKED(IDC_SOFTWARE_RADIO, OnSoftwareRadio)
ON_BN_CLICKED(IDC_DIRECT3D_RADIO, OnDirect3dRadio)
ON_BN_CLICKED(IDC_GLIDE_RADIO, OnGlideRadio)
ON_EN_KILLFOCUS(IDC_CAMERA_X, OnKillfocusCameraX)
ON_EN_KILLFOCUS(IDC_CAMERA_Y, OnKillfocusCameraY)
ON_EN_KILLFOCUS(IDC_CAMERA_Z, OnKillfocusCameraZ)
ON_WM_HSCROLL()
ON_WM_GETMINMAXINFO()
ON_WM_PAINT()
ON_WM_NCHITTEST()
ON_WM_SIZE()
ON_BN_CLICKED(IDC_ZERO_CAMERA_BTN, OnZeroCameraBtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGenEditPreviewDlg message handlers
BOOL CGenEditPreviewDlg::OnInitDialog() // post 0.55 // this whole func
{
// MSG msg;
CDialog::OnInitDialog();
if (m_DriverName == "")
{
m_DriverName = "D3D";
}
// driverString = "(";
// Width = -1; // for windowed mode
// Height = -1; // for windowed mode
Engine = NULL;
World = NULL; // post 0.55
SoundSys = NULL;
DrvSys = NULL;
Camera = NULL;
Driver = NULL;
Mode = NULL;
CameraExtBox.Min.X = -20.0f;
CameraExtBox.Min.Y = -20.0f;
CameraExtBox.Min.Z = -20.0f;
CameraExtBox.Max.X = 20.0f;
CameraExtBox.Max.Y = 20.0f;
CameraExtBox.Max.Z = 20.0f;
if (CGlobals::m_recentCompiledLevel != "")
{
m_previewLevelPath = CGlobals::m_recentCompiledLevel;
m_previewLevelList.DeleteAllItems();
m_previewLevelList.InsertItem(0, m_previewLevelPath);
m_previewWithEngineBtn.EnableWindow(TRUE);
}
m_softwareRadioBtn = (CButton*)this->GetDlgItem(IDC_SOFTWARE_RADIO);
m_direct3dRadioBtn = (CButton*)this->GetDlgItem(IDC_DIRECT3D_RADIO);
m_glideRadioBtn = (CButton*)this->GetDlgItem(IDC_GLIDE_RADIO);
m_640RadioBtn = (CButton*)this->GetDlgItem(IDC_RADIO_640);
m_800RadioBtn = (CButton*)this->GetDlgItem(IDC_RADIO_800);
m_1024RadioBtn = (CButton*)this->GetDlgItem(IDC_RADIO_1024);
m_collideRadioBtn = (CButton*)this->GetDlgItem(IDC_RADIO_COLLIDE);
m_noCollideRadioBtn = (CButton*)this->GetDlgItem(IDC_RADIO_NOCOLLIDE);
if (m_DriverName == "" || m_DriverName == "D3D")
{
OnDirect3dRadio();
m_direct3dRadioBtn->SetCheck(1);
}
if (m_DriverName == "Software")
{
OnSoftwareRadio();
m_softwareRadioBtn->SetCheck(1);
m_bDrawGripper = TRUE;
}
if (m_DriverName == "Glide")
{
OnGlideRadio();
m_glideRadioBtn->SetCheck(1);
}
switch (Width)
{
case 640:
m_640RadioBtn->SetCheck(1);
break;
case 800:
m_800RadioBtn->SetCheck(1);
break;
case 1024:
m_1024RadioBtn->SetCheck(1);
}
if (m_collisionDetection)
m_collideRadioBtn->SetCheck(1);
if (!m_collisionDetection)
m_noCollideRadioBtn->SetCheck(1);
m_cameraSliderX.SetRange(-4000, 4000);
m_cameraSliderY.SetRange(-4000, 4000);
m_cameraSliderZ.SetRange(-4000, 4000);
m_cameraSliderX.SetTicFreq(200);
m_cameraSliderY.SetTicFreq(200);
m_cameraSliderZ.SetTicFreq(200);
m_cameraSliderX.SetPos(m_cameraXPos);
m_cameraSliderY.SetPos(m_cameraYPos);
m_cameraSliderZ.SetPos(m_cameraZPos);
if (m_previewLevelPath != "")
{
m_previewLevelList.InsertItem(0, m_previewLevelPath);
m_previewWithEngineBtn.EnableWindow(TRUE);
}
GetWindowRect(m_restoreRect);
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CGenEditPreviewDlg::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
{
CRect previewRect;
Width = previewRect.Width();
Height = previewRect.Height();
CDialog::CalcWindowRect(lpClientRect, nAdjustType);
}
// since this is a resizeable dialog box, we need to set
// its MINIMUM size
void CGenEditPreviewDlg::OnGetMinMaxInfo(MINMAXINFO *lpMMI)
{
CDialog::OnGetMinMaxInfo(lpMMI);
lpMMI->ptMinTrackSize.x = m_restoreRect.right - m_restoreRect.left;
lpMMI->ptMinTrackSize.y = m_restoreRect.bottom - m_restoreRect.top;
}
///////////////////////////////////////////////////////////////////////////////
// SetDriverChoice
//
// Based on the user's driver choice
// we will copy either the Glide or D3D driver into the app's
// root directory. We do this because of driver enum problems on systems that
// have both Glide and D3D drivers installed (on the system level)
///////////////////////////////////////////////////////////////////////////////
void CGenEditPreviewDlg::SetDriverChoice()
{
auto char szBuf[MAX_PATH];
LPTSTR lpFile;
if (DeleteFile("GlideDrv.dll"))
{
// AfxMessageBox("Successfully Deleted Glide Driver");
}
if (DeleteFile("D3DDrv.dll"))
{
// AfxMessageBox("Successfully Deleted D3D Driver");
}
if (!strcmp(m_DriverName, "D3D"))
{
if (CopyFile("Drivers//D3DDrv.dll", "D3DDrv.dll", TRUE))
{
// AfxMessageBox("D3D Driver Successfully Copied");
SetCurrentDirectory(CGlobals::m_GlobalAppPath);
}
if (SearchPath(NULL, "D3DDrv.dll", NULL, MAX_PATH, szBuf, &lpFile))
{
// AfxMessageBox("D3D Driver Successfully Found");
}
else
AfxMessageBox("D3D Driver Not Found");
}
if (!strcmp(m_DriverName, "Glide"))
{
if (CopyFile("Drivers//GlideDrv.dll", "GlideDrv.dll", TRUE))
{
// AfxMessageBox("Glide Driver Successfully Copied");
SetCurrentDirectory(CGlobals::m_GlobalAppPath);
}
if (SearchPath(NULL, "GlideDrv.dll", NULL, MAX_PATH, szBuf, &lpFile))
{
// AfxMessageBox("Glide Driver Successfully Found");
}
else
AfxMessageBox("Glide Driver Not Found");
}
}
geBoolean CGenEditPreviewDlg::InitEngine(HWND hWnd)
{
SetCurrentDirectory(CGlobals::m_GlobalAppPath);
SetDriverChoice();
if (Engine == NULL)
{
Engine = geEngine_Create(hWnd, "GenEdit QuckViewer", ".");
if (!Engine)
{
AfxMessageBox( "Could not create engine object!");
return GE_FALSE;
}
}
if (!LoadDriver())
return GE_FALSE; //post 0.5
//Create the camera object.
if (Camera == NULL)
{
Camera = geCamera_Create(2.0f, &Rect);
}
if (!Camera)
{
AfxMessageBox( "Could not create camera object!");
return GE_FALSE; //post 0.5
}
// commented out post 0.55
/* if (SoundSys == NULL)
{
SoundSys = geSound_CreateSoundSystem(hWnd);
if (!SoundSys)
{
AfxMessageBox( "Could not create Sound System! There will be no sound!");
return GE_FALSE; //post 0.5
}
}
*/
//Load the level
char* levelpath = m_previewLevelPath.GetBuffer(m_previewLevelPath.GetLength());
if (!LoadLevel(levelpath))
{
return GE_FALSE;
}
//Set up the XForm for the camera. XForms determine our place in the world.
//Clear the transform
geXForm3d_SetIdentity(&XForm);
#pragma warning (disable:4244)
XForm.Translation.X = m_cameraXPos;
XForm.Translation.Y = m_cameraYPos;
XForm.Translation.Z = m_cameraZPos;
#pragma warning (default:4244)
//Setup the initial rotation
geXForm3d_RotateX(&XForm, 0.0f);
geXForm3d_RotateY(&XForm, 0.0f);
geXForm3d_RotateZ(&XForm, 0.0f);
//Set the XForm to the camera
geCamera_SetWorldSpaceXForm(Camera, &XForm);
return GE_TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// LoadDriver
///////////////////////////////////////////////////////////////////////////////
geBoolean CGenEditPreviewDlg::LoadDriver()
{
CString sDriverFindError = _T("Could not find a valid driver!\n");
sDriverFindError += _T("Make sure the following Genesis3D video drivers\n");
sDriverFindError += _T("reside in the same directory as GenEdit.exe\n");
sDriverFindError += _T("o SoftDrv.dll and softdrv2.dll - for software rendering\n\n");
sDriverFindError += _T("Make sure the following Genesis3D video drivers\n");
sDriverFindError += _T("reside in GenEdit.exe's 'Drivers' subdirectory\n");
sDriverFindError += _T("o D3DDrv.dll - for Direct3D video cards\n");
sDriverFindError += _T("o GlideDrv.dll - for VooDoo video cards\n");
long tempwidth;
long tempheight;
const char *drvname = NULL;
bool weScrewedUp = false;
if (DrvSys == NULL)
{
SetCurrentDirectory(CGlobals::m_GlobalAppPath);
DrvSys = geEngine_GetDriverSystem(Engine);
if (DrvSys == NULL)
{
AfxMessageBox( "Could not get the Genesis Driver System!");
return GE_FALSE;
}
}
if (Driver == NULL)
{
Driver = geDriver_SystemGetNextDriver(DrvSys, NULL);
if (Driver == NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -