home *** CD-ROM | disk | FTP | other *** search
- // QDTestDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "QDTest.h"
- #include "QDTestDlg.h"
- #include "QDServer_i.c"
-
- #include <math.h>
-
- #ifndef M_PI
- #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
- #endif
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define POSSTATE_IDLE 0x00000000
- #define POSSTATE_UP 0x00000001
- #define POSSTATE_DOWN 0x00000002
- #define POSSTATE_LEFT 0x00000004
- #define POSSTATE_RIGHT 0x00000008
- #define POSSTATE_WALK 0x00000010
-
- #define DELTA_STEP 5.0f
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
-
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
-
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
-
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
-
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
-
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CQDTestDlg dialog
-
- CQDTestDlg::CQDTestDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CQDTestDlg::IDD, pParent)
- ,m_pQDBspView(NULL)
- ,m_fStep(0)
- ,m_dwPosState(POSSTATE_IDLE)
- ,m_fFriction(1.0)
- ,m_nSliderPos(50)
- {
- //{{AFX_DATA_INIT(CQDTestDlg)
- m_strPakFile = _T("E:\\Quake2\\baseq2\\Pak0.pak");
- m_strMapName = _T("Base1");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
-
- memset(m_fViewAngles,0x00,sizeof(m_fViewAngles));
- memset(m_fViewPos,0x00,sizeof(m_fViewPos));
- }
-
-
- CQDTestDlg::~CQDTestDlg()
- {
- if(m_pQDBspView)
- {
- m_pQDBspView->Shutdown();
- m_pQDBspView->Release();
- }
- }
- void CQDTestDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CQDTestDlg)
- DDX_Control(pDX, IDC_SLIDER2, m_wndSlider);
- DDX_Control(pDX, IDC_FLYUP, m_wndFlyUp);
- DDX_Control(pDX, IDC_FLYDOWN, m_wndFlyDown);
- DDX_Control(pDX, IDC_WALK, m_wndWalk);
- DDX_Control(pDX, IDC_UP, m_wndUp);
- DDX_Control(pDX, IDC_RIGHT, m_wndRight);
- DDX_Control(pDX, IDC_LEFT, m_wndLeft);
- DDX_Control(pDX, IDC_DOWN, m_wndDown);
- DDX_Text(pDX, IDC_PAK, m_strPakFile);
- DDX_Text(pDX, IDC_MAP, m_strMapName);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CQDTestDlg, CDialog)
- //{{AFX_MSG_MAP(CQDTestDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
- ON_BN_CLICKED(IDC_VIEW, OnView)
- ON_WM_TIMER()
- ON_WM_MOUSEMOVE()
- ON_BN_CLICKED(IDC_DOWN, OnDown)
- ON_BN_CLICKED(IDC_LEFT, OnLeft)
- ON_BN_CLICKED(IDC_RIGHT, OnRight)
- ON_BN_CLICKED(IDC_UP, OnUp)
- ON_BN_CLICKED(IDC_WALK, OnWalk)
- ON_BN_CLICKED(IDC_FLYUP, OnFlyup)
- ON_BN_CLICKED(IDC_FLYDOWN, OnFlydown)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CQDTestDlg message handlers
-
- BOOL CQDTestDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // Add "About..." menu item to system menu.
-
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
-
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
-
- m_wndUp.LoadBitmaps(IDB_UP,IDB_UP,IDB_UP,IDB_UP);
- m_wndDown.LoadBitmaps(IDB_DOWN,IDB_DOWN,IDB_DOWN,IDB_DOWN);
- m_wndLeft.LoadBitmaps(IDB_LEFT,IDB_LEFT,IDB_LEFT,IDB_LEFT);
- m_wndRight.LoadBitmaps(IDB_RIGHT,IDB_RIGHT,IDB_RIGHT,IDB_RIGHT);
- m_wndWalk.LoadBitmaps(IDB_WALK,IDB_WALK,IDB_WALK,IDB_WALK);
-
- m_wndFlyUp.LoadBitmaps(IDB_FLYUP,IDB_FLYUP,IDB_FLYUP,IDB_FLYUP);
- m_wndFlyDown.LoadBitmaps(IDB_FLYDOWN,IDB_FLYDOWN,IDB_FLYDOWN,IDB_FLYDOWN);
-
- m_wndSlider.SetRange(0,100);
- m_wndSlider.SetPos(m_nSliderPos);
-
- CRect rcClient;
- GetClientRect(rcClient);
- CWnd* pWnd = GetDlgItem(IDC_SIZERLIMIT);
-
- SetTimer(1,100,NULL);
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- void CQDTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
-
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
-
- void CQDTestDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
-
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CQDTestDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- void CQDTestDlg::OnBrowse()
- {
- static char BASED_CODE szFilter[] = "Quake 2 Pak Files (*.pak)|*.pak||";
-
- CFileDialog dlg(TRUE,_T("*.pak"),
- m_strPakFile,
- OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- szFilter
- );
-
- if(dlg.DoModal() == IDOK)
- {
- CFile fileDemo;
- m_strPakFile = dlg.GetPathName();
- UpdateData(FALSE);
- }
- }
-
- void CQDTestDlg::OnView()
- {
- UpdateData(TRUE);
-
- // yeah yeah yeah I know there probably a
- // million other ways to have this done (import or tlb wrappers)
- // but well I'm a COM fan and I'm using the traditional way
-
- HRESULT hr = S_OK;
- if(!m_pQDBspView)
- {
- hr = ::CoCreateInstance(CLSID_QDBspView,NULL,CLSCTX_ALL,IID_IQDBspView,(LPVOID*)&m_pQDBspView);
- }
-
- if(SUCCEEDED(hr))
- {
- try
- {
-
-
- BSTR bstrCaption = ::SysAllocString(L"QDemServer Test Caption");
- BSTR bstrSky = ::SysAllocString(L"unit1_");
- BSTR bstrMap = m_strMapName.AllocSysString();
- BSTR bstrPak = m_strPakFile.AllocSysString();
-
- m_pQDBspView->Init(bstrPak,TRUE,320,240);
- // lets change the caption
- m_pQDBspView->SetCaption(bstrCaption);
- // and gamma
-
- m_nSliderPos = m_wndSlider.GetPos();
- m_pQDBspView->SetViewOptions(QDBSPVIEW_OPTION_GAMMA,100 - m_nSliderPos,0);
-
- m_pQDBspView->LoadMap(bstrMap,bstrSky,bstrPak,TRUE);
-
- ::SysFreeString(bstrCaption);
- ::SysFreeString(bstrSky);
- ::SysFreeString(bstrMap);
- ::SysFreeString(bstrPak);
- return;
- }
- catch(...)
- {
- // this might be dangerous since our server
- // might been crashed too but well ...
- m_pQDBspView->Release();
- m_pQDBspView = NULL;
- AfxMessageBox(_T("Helluva place to crash..."));
- return;
- }
-
- }
-
- if(m_pQDBspView)
- {
- m_pQDBspView->Release();
- m_pQDBspView = NULL;
- }
-
- CString strText;
- strText.Format(_T("Something went wrong here !!!. HRESULT %X"),hr);
- AfxMessageBox(strText);
- }
-
- void CQDTestDlg::UpdateFrame()
- {
- if(m_pQDBspView)
- {
- m_pQDBspView->SetCameraPos(m_fViewPos[0],
- m_fViewPos[1],
- m_fViewPos[2],
- m_fViewAngles[0],
- m_fViewAngles[1],
- m_fViewAngles[2]);
-
- }
- }
-
- void CQDTestDlg::OnTimer(UINT nIDEvent)
- {
- CDialog::OnTimer(nIDEvent);
-
- // yeah yeah dont tell me about it ...
- if(m_pQDBspView && nIDEvent == 1)
- {
-
- if(m_wndSlider.GetPos() != m_nSliderPos)
- {
- m_nSliderPos = m_wndSlider.GetPos();
- m_pQDBspView->SetViewOptions(QDBSPVIEW_OPTION_GAMMA,100 - m_nSliderPos,0);
- }
-
-
- switch(m_dwPosState)
- {
- case POSSTATE_UP:
- m_fViewAngles[0] -= DELTA_STEP * m_fFriction;
- if(m_fViewAngles[0] < 0) m_fViewAngles[0] = 360 - m_fViewAngles[0];
- break;
- case POSSTATE_DOWN:
- m_fViewAngles[0] += DELTA_STEP * m_fFriction;
- if(m_fViewAngles[0] >= 360) m_fViewAngles[0] = m_fViewAngles[0] - 360;
- break;
- case POSSTATE_LEFT:
- m_fViewAngles[1] += DELTA_STEP * m_fFriction;
- if(m_fViewAngles[1] >= 360) m_fViewAngles[1] = m_fViewAngles[1] - 360;
- break;
- case POSSTATE_RIGHT:
- m_fViewAngles[1] -= DELTA_STEP * m_fFriction;
- if(m_fViewAngles[1] >= 360) m_fViewAngles[1] = m_fViewAngles[1] - 360;
- break;
- case POSSTATE_WALK:
- m_fViewPos[0] += (float)(DELTA_STEP * m_fFriction * 2.0 * cos(m_fViewAngles[1] * (M_PI / 180.0)));
- m_fViewPos[1] += (float)(DELTA_STEP * m_fFriction * 2.0 * sin(m_fViewAngles[1] * (M_PI / 180.0)));
- break;
- default:
- m_fFriction = 1.0;
- return;
- break;
- }
- m_fFriction += 0.01f;
- if(m_fFriction >= 3.0f)
- m_fFriction == 3.0f;
- UpdateFrame();
- }
- }
-
- void CQDTestDlg::OnMouseMove(UINT nFlags, CPoint point)
- {
- CDialog::OnMouseMove(nFlags, point);
- }
-
- void CQDTestDlg::OnDown()
- {
- m_dwPosState = POSSTATE_DOWN;
- }
-
- void CQDTestDlg::OnLeft()
- {
- m_dwPosState = POSSTATE_LEFT;
- }
-
- void CQDTestDlg::OnRight()
- {
- m_dwPosState = POSSTATE_RIGHT;
- }
-
- void CQDTestDlg::OnUp()
- {
- m_dwPosState = POSSTATE_UP;
- }
-
- void CQDTestDlg::OnWalk()
- {
- if(m_dwPosState == POSSTATE_WALK)
- {
- m_dwPosState = POSSTATE_IDLE;
- return;
- }
-
- if(m_dwPosState != POSSTATE_IDLE)
- {
- m_dwPosState = POSSTATE_IDLE;
- return;
- }
-
- if(m_dwPosState == POSSTATE_IDLE)
- {
- m_dwPosState = POSSTATE_WALK;
- return;
- }
- }
-
- void CQDTestDlg::OnFlyup()
- {
- m_fViewPos[2] += 20.0f;
- UpdateFrame();
- }
-
- void CQDTestDlg::OnFlydown()
- {
- m_fViewPos[2] -= 20.0f;
- UpdateFrame();
- }
-