⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inputlayer.cpp

📁 这是一个屠宰场游戏,此游戏很休闲的请大家下载来看看.
💻 CPP
字号:
/*******************************************************************
 *         Advanced 3D Game Programming using DirectX 7.0
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *   Title: InputLayer.cpp
 *    Desc: Manages DirectInput
 *          Currently only has support for keyboard/mouse
 * copyright (c) 1999 by Adrian Perez
 * See license.txt for modification and distribution information
 ******************************************************************/
#include <Windows.h>
#include "GameErrors.h"
#include "InputLayer.h"
#include "Keyboard.h"
#include "Mouse.h"
//#include "Application.h"


cInputLayer* cInputLayer::m_pGlobalILayer = NULL;

cInputLayer::cInputLayer( 
	HINSTANCE hInst, 
	HWND hWnd, 
	bool bExclusive, 
	bool bUseKeyboard, 
	bool bUseMouse )
{
	m_pKeyboard = NULL;
	m_pMouse = NULL;

	if( m_pGlobalILayer )
	{
		throw cGameError("cInputLayer already initialized!\n");
	}
	m_pGlobalILayer = this;

	HRESULT hr;

	/**
	 * Create the DI7 object
	 */
	hr = DirectInput8Create(           //创建DirectInput8,获取接口指针
		hInst, 
		DIRECTINPUT_VERSION, 
		IID_IDirectInput8, 
		(void**)&m_pDI, 
		NULL); 
    if( FAILED(hr) )
	{
		throw cGameError("DirectInput7 object could not be created\n"); 
	}

	try 
	{
		if( bUseKeyboard )
		{
			m_pKeyboard = new cKeyboard( hWnd );
		}
		if( bUseMouse )
		{
			m_pMouse = new cMouse( hWnd, bExclusive );
		}
	}
	catch( ... )
	{
		SafeRelease( m_pDI );
		throw;
	}

}


cInputLayer::~cInputLayer()
{
	if( m_pDI )
	{
		if( m_pKeyboard )
		{
			delete m_pKeyboard; // this does all the de-init.
		}

		if( m_pMouse )
		{
			delete m_pMouse; // this does all the de-init.
		}
		ExtraSafeRelease( m_pDI );
	}
	m_pGlobalILayer = NULL;
}

void cInputLayer::UpdateDevices()
{
	if( m_pKeyboard )
	{
		m_pKeyboard->Update();
	}
	if( m_pMouse )
	{
		m_pMouse->Update();
	}
}


void cInputLayer::SetFocus()
{
	if( m_pKeyboard )
	{
		m_pKeyboard->ClearTable();
	}
	if( m_pMouse )
	{
		m_pMouse->Acquire();
	}
}


void cInputLayer::KillFocus()
{
	if( m_pKeyboard )
	{
		m_pKeyboard->ClearTable();
	}
	if( m_pMouse )
	{
		m_pMouse->UnAcquire();
	}
}

void cInputLayer::Destroy()
{
	if (m_pGlobalILayer) 
		delete m_pGlobalILayer;
	m_pGlobalILayer = NULL;
}

⌨️ 快捷键说明

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