Esempio n. 1
0
// Frees all the member vars and resets afterwards...
void CD3D_Device::FreeAll()
{
	// Destoy all the Render Objects in the list...
	while (m_pRenderObjectList_Head)
	{
		CRenderObject* pTmp = m_pRenderObjectList_Head->GetNext();
		DestroyRenderObject(m_pRenderObjectList_Head);
		m_pRenderObjectList_Head = pTmp;
	}

	// Destoy all the Render Styles in the list...
	while (m_pRenderStyleList_Head)
	{
		CD3DRenderStyle* pTmp = m_pRenderStyleList_Head->GetNext();
		DestroyRenderStyle(m_pRenderStyleList_Head);
		m_pRenderStyleList_Head = pTmp;
	}

	delete m_pRenderWorld;
	m_pRenderWorld = NULL;

	FreeFrameTextures();

	FreeDevice();

	Reset();
}
Esempio n. 2
0
	void CWindowsApp::Run(IGameState *gameState)
	{
		ShowWindow(m_windowHandle, SW_SHOWDEFAULT);
		UpdateWindow(m_windowHandle);

		CoreManager::GetInstance()->SetDevice(m_direct3DDevice, (float)m_width, (float)m_height);
		GameStateManager::GetInstance()->PushGameState(gameState);
		Input::GetInstance()->Init(m_windowHandle);

		{
			MSG msg;
			ZeroMemory(&msg, sizeof(msg));

			Time::GetInstance()->Init();
			while (msg.message != WM_QUIT)
			{
				while (PeekMessage(&msg, nullptr, 0U, 0U, PM_REMOVE))
				{
					TranslateMessage(&msg);
					DispatchMessage(&msg);
				}

				Time::GetInstance()->CalculateTime();
				Input::GetInstance()->Acquiring();
				CoreManager::GetInstance()->Loop();
			}

			//UnregisterClass(m_wndClassEx.lpszClassName, m_wndClassEx.hInstance);
			UnregisterClassW(m_wndClassEx.lpszClassName, m_wndClassEx.hInstance);
			FreeDevice();
		}

		GameStateManager::GetInstance()->ClearAllState();
		CoreManager::GetInstance()->RemoveDevice();
	}
Esempio n. 3
0
/* Function to cause any queued joystick insertions to be processed
 */
void
SDL_SYS_JoystickDetect()
{
    while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
        /* no-op. Pending callbacks will fire in CFRunLoopRunInMode(). */
    }

    if (s_bDeviceAdded || s_bDeviceRemoved) {
        recDevice *device = gpDeviceList;
        s_bDeviceAdded = SDL_FALSE;
        s_bDeviceRemoved = SDL_FALSE;
        int device_index = 0;
        /* send notifications */
        while (device) {
            if (device->send_open_event) {
                device->send_open_event = 0;
/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceAdded()? */
#if !SDL_EVENTS_DISABLED
                SDL_Event event;
                event.type = SDL_JOYDEVICEADDED;

                if (SDL_GetEventState(event.type) == SDL_ENABLE) {
                    event.jdevice.which = device_index;
                    if ((SDL_EventOK == NULL)
                        || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
                        SDL_PushEvent(&event);
                    }
                }
#endif /* !SDL_EVENTS_DISABLED */

            }

            if (device->removed) {
                const int instance_id = device->instance_id;
                device = FreeDevice(device);

/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceRemoved()? */
#if !SDL_EVENTS_DISABLED
                SDL_Event event;
                event.type = SDL_JOYDEVICEREMOVED;

                if (SDL_GetEventState(event.type) == SDL_ENABLE) {
                    event.jdevice.which = instance_id;
                    if ((SDL_EventOK == NULL)
                        || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
                        SDL_PushEvent(&event);
                    }
                }
#endif /* !SDL_EVENTS_DISABLED */

            } else {
                device = device->pNext;
                device_index++;
            }
        }
    }
}
Esempio n. 4
0
USBDevice::~USBDevice()
{
	FreeDevice();
#ifdef _DEBUG
	debugPrintf("ASIOUAC: ~USBDevice()\n");
#endif
	if(m_deviceMutex)
		CloseHandle(m_deviceMutex);
}
Esempio n. 5
0
// Create the Sucka...
bool CD3D_Device::CreateDevice(D3DAdapterInfo* pAdapter,D3DDeviceInfo* pDevice,D3DModeInfo* pMode)
{
	if (!TdGuard::Aegis::GetSingleton().DoWork())
	{
		return false;
	}


	FreeDevice();								// Make sure it's all released and groovie...

	m_pAdapter	= pAdapter;						// Initialization...
	m_pDevice	= pDevice;
	m_pMode		= pMode;

	// Create the sucka...
	uint32 BehaviorFlags = D3DCREATE_MULTITHREADED;
	if (pDevice->d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) 
	{
		BehaviorFlags |= D3DCREATE_MIXED_VERTEXPROCESSING;
	}
	else 
	{
		BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
	}

	D3DPRESENT_PARAMETERS PresentationParam;
	SetPresentationParams(PresentationParam,pMode);
	HRESULT hResult = PDIRECT3D->CreateDevice(pAdapter->iAdapterNum,pDevice->DeviceType,g_hWnd_RenderWindow,BehaviorFlags,&PresentationParam,&m_pD3DDevice);
	if ((hResult != D3D_OK) || !m_pD3DDevice) 
	{	// Give it more more try - Presentation params might have been changed by D3D to something acceptable...
		OutputDebugString("Warning: Create failed. Attempting to fall back...\n");
		TryFallingBack_OnFailedDevCreate(&PresentationParam);

		hResult = PDIRECT3D->CreateDevice(pAdapter->iAdapterNum,pDevice->DeviceType,g_hWnd_RenderWindow,BehaviorFlags,&PresentationParam,&m_pD3DDevice);

		if ((hResult != D3D_OK) || !m_pD3DDevice) 
		{ 
			FreeAll(); 
			return false; 
		} 
	}

	if (FAILED(m_pD3DDevice->GetDeviceCaps(&m_DeviceCaps)))	
	{ 
		FreeAll(); 
		return false; 
	}

	SetDefaultRenderStates();					// Set the default render states...
	PreCalcSomeDeviceCaps();					// Do some precalcing of device caps (figure out if we can do some puff)...

	// Display a warning message
//	if (m_pDevice->DeviceType == D3DDEVTYPE_REF) AddDebugMessage(1,"Warning: Couldnt' find any HAL devices, Using reference rasterizer");

	return true;
}
Esempio n. 6
0
void KSGDeviceManager::Clear()
{
	DeviceList::iterator i;
	for (i = _devList.begin();i != _devList.end();++i)
	{
		KSGDeviceNode * node = *i;
		FreeDevice(node);
	}
	_devList.clear();
	_devices.clear();
}
Esempio n. 7
0
// Frees all the member vars and resets afterwards...
void CD3D_Device::FreeAll()
{
	// Destoy all the Render Objects in the list...
	while (m_pRenderObjectList_Head) {
		CRenderObject* pTmp = m_pRenderObjectList_Head->GetNext();
		DestroyRenderObject(m_pRenderObjectList_Head);
		m_pRenderObjectList_Head = pTmp; } 

	FreeDevice();

	Reset();
}
Esempio n. 8
0
/* Function to cause any queued joystick insertions to be processed
 */
void
SDL_SYS_JoystickDetect()
{
    if (s_bDeviceAdded || s_bDeviceRemoved) {
        recDevice *device = gpDeviceList;
        s_bDeviceAdded = SDL_FALSE;
        s_bDeviceRemoved = SDL_FALSE;
        int device_index = 0;
        /* send notifications */
        while (device) {
            if (device->send_open_event) {
                device->send_open_event = 0;
/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceAdded()? */
#if !SDL_EVENTS_DISABLED
                SDL_Event event;
                event.type = SDL_JOYDEVICEADDED;

                if (SDL_GetEventState(event.type) == SDL_ENABLE) {
                    event.jdevice.which = device_index;
                    if ((SDL_EventOK == NULL)
                        || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
                        SDL_PushEvent(&event);
                    }
                }
#endif /* !SDL_EVENTS_DISABLED */

            }

            if (device->removed) {
                const int instance_id = device->instance_id;
                device = FreeDevice(device);

/* !!! FIXME: why isn't there an SDL_PrivateJoyDeviceRemoved()? */
#if !SDL_EVENTS_DISABLED
                SDL_Event event;
                event.type = SDL_JOYDEVICEREMOVED;

                if (SDL_GetEventState(event.type) == SDL_ENABLE) {
                    event.jdevice.which = instance_id;
                    if ((SDL_EventOK == NULL)
                        || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
                        SDL_PushEvent(&event);
                    }
                }
#endif /* !SDL_EVENTS_DISABLED */

            } else {
                device = device->pNext;
                device_index++;
            }
        }
    }
}
Esempio n. 9
0
/* Function to perform any system-specific joystick related cleanup */
void
SDL_SYS_JoystickQuit(void)
{
    while (FreeDevice(gpDeviceList)) {
        /* spin */
    }

    if (hidman) {
        IOHIDManagerUnscheduleFromRunLoop(hidman, CFRunLoopGetCurrent(), SDL_JOYSTICK_RUNLOOP_MODE);
        IOHIDManagerClose(hidman, kIOHIDOptionsTypeNone);
        CFRelease(hidman);
        hidman = NULL;
    }
}
Esempio n. 10
0
/* Function to perform any system-specific joystick related cleanup */
void
SDL_SYS_JoystickQuit(void)
{
    while (FreeDevice(gpDeviceList)) {
        /* spin */
    }

    if (hidman) {
        IOHIDManagerClose(hidman, kIOHIDOptionsTypeNone);
        CFRelease(hidman);
        hidman = NULL;
    }

    s_bDeviceAdded = s_bDeviceRemoved = SDL_FALSE;
}
Esempio n. 11
0
/* Function to cause any queued joystick insertions to be processed
 */
void
SDL_SYS_JoystickDetect()
{
    recDevice *device = gpDeviceList;
    while (device) {
        if (device->removed) {
            device = FreeDevice(device);
        } else {
            device = device->pNext;
        }
    }

	// run this after the checks above so we don't set device->removed and delete the device before
	// SDL_SYS_JoystickUpdate can run to clean up the SDL_Joystick object that owns this device
	while (CFRunLoopRunInMode(SDL_JOYSTICK_RUNLOOP_MODE,0,TRUE) == kCFRunLoopRunHandledSource) {
		/* no-op. Pending callbacks will fire in CFRunLoopRunInMode(). */
	}
}
Esempio n. 12
0
/*
 *************************************************************************
 *  MiniportHalt
 *************************************************************************
 *
 *  Halts the network interface card.
 *
 */
VOID MiniportHalt(IN NDIS_HANDLE MiniportAdapterContext)
{
	IrDevice *thisDev = CONTEXT_TO_DEV(MiniportAdapterContext);

	DBGOUT(("MiniportHalt(0x%x)", (UINT)MiniportAdapterContext));

	/*
	 *  Remove this device from our global list
	 */

	if (thisDev == firstIrDevice){
		firstIrDevice = firstIrDevice->next;
	}
	else {
		IrDevice *dev;
		for (dev = firstIrDevice; dev && (dev->next != thisDev); dev = dev->next){ }
		if (dev){
			dev->next = dev->next->next;
		}
		else {
			/*
			 *  Don't omit this error check.  I've seen NDIS call MiniportHalt with
			 *  a bogus context when the system gets corrupted.
			 */
			DBGERR(("Bad context in MiniportHalt"));
			return;
		}
	}


	/*
	 *  Now destroy the device object.
	 */
	DoClose(thisDev);

	NdisMDeregisterIoPortRange(	thisDev->ndisAdapterHandle,
								thisDev->portInfo.ioBase,
								8,
								(PVOID)thisDev->mappedPortRange);
	FreeDevice(thisDev);


}
Esempio n. 13
0
/*
 *************************************************************************
 *  MiniportInitialize
 *************************************************************************
 *
 *
 *  Initializes the network interface card.
 *
 *
 *
 */
NDIS_STATUS MiniportInitialize	(	PNDIS_STATUS OpenErrorStatus,
									PUINT SelectedMediumIndex,
									PNDIS_MEDIUM MediumArray,
									UINT MediumArraySize,
									NDIS_HANDLE NdisAdapterHandle,
									NDIS_HANDLE WrapperConfigurationContext
								)
{
	UINT mediumIndex;
	IrDevice *thisDev = NULL;	
	NDIS_STATUS retStat, result = NDIS_STATUS_SUCCESS;

	DBGOUT(("MiniportInitialize()"));

	/*
	 *  Search the passed-in array of supported media for the IrDA medium.
	 */
	for (mediumIndex = 0; mediumIndex < MediumArraySize; mediumIndex++){
		if (MediumArray[mediumIndex] == NdisMediumIrda){
			break;
		}
	}
	if (mediumIndex < MediumArraySize){
		*SelectedMediumIndex = mediumIndex;
	}
	else {
		/*
		 *  Didn't see the IrDA medium
		 */
		DBGERR(("Didn't see the IRDA medium in MiniportInitialize"));
		result = NDIS_STATUS_UNSUPPORTED_MEDIA;
		goto _initDone;
	}

	/*
	 *  Allocate a new device object to represent this connection.
	 */
	thisDev = NewDevice();
	if (!thisDev){
		return NDIS_STATUS_NOT_ACCEPTED;
	}

	/*
	 *  Allocate resources for this connection.
	 */
	if (!OpenDevice(thisDev)){
		DBGERR(("OpenDevice failed"));
		result = NDIS_STATUS_FAILURE;
		goto _initDone;
	}


	/*
	 *  Read the system registry to get parameters like COM port number, etc.
	 */
	if (!Configure(thisDev, WrapperConfigurationContext)){
		result = NDIS_STATUS_FAILURE;
		goto _initDone;
	}


	/*
	 *  This call will associate our adapter handle with the wrapper's
	 *  adapter handle.  The wrapper will then always use our handle
	 *  when calling us.  We use a pointer to the device object as the context.
	 */
   	NdisMSetAttributes	(	NdisAdapterHandle,
							(NDIS_HANDLE)thisDev,
							FALSE,
							NdisInterfaceInternal  
						);

							
	/*
	 *  Tell NDIS about the range of IO space that we'll be using.
	 */
	retStat = NdisMRegisterIoPortRange(	(PVOID)thisDev->mappedPortRange,
										NdisAdapterHandle,
										thisDev->portInfo.ioBase,
										8);
	if (retStat != NDIS_STATUS_SUCCESS){
		DBGERR(("NdisMRegisterIoPortRange failed"));
		result = NDIS_STATUS_FAILURE;
		goto _initDone;
	}


	/*
	 *  Record the NDIS wrapper's handle for this adapter, which we use
	 *  when we call up to the wrapper.
	 *  (This miniport's adapter handle is just thisDev, the pointer to the device object.).
	 */
	DBGOUT(("NDIS handle: %xh <-> IRMINI handle: %xh", (UINT)NdisAdapterHandle, (UINT)thisDev));
	thisDev->ndisAdapterHandle = NdisAdapterHandle;


	/*
	 *  Open COMM communication channel.
	 *  This will let the dongle driver update its capabilities from their default values.
	 */
	if (!DoOpen(thisDev)){
		DBGERR(("DoOpen failed"));
		result = NDIS_STATUS_FAILURE;
		goto _initDone;
	}


	/*
	 *  Register an interrupt with NDIS.
	 */
	retStat = NdisMRegisterInterrupt(	(PNDIS_MINIPORT_INTERRUPT)&thisDev->interruptObj,
										NdisAdapterHandle,
										thisDev->portInfo.irq,
										thisDev->portInfo.irq,
										TRUE,	// want ISR
										TRUE,	// MUST share interrupts
										NdisInterruptLevelSensitive
									);
	if (retStat != NDIS_STATUS_SUCCESS){
		DBGERR(("NdisMRegisterInterrupt failed"));
		result = NDIS_STATUS_FAILURE;
		goto _initDone;
	}


 _initDone:
	if (result == NDIS_STATUS_SUCCESS){

		/*
		 *  Add this device object to the beginning of our global list.
		 */
		thisDev->next = firstIrDevice;
		firstIrDevice = thisDev;

		DBGOUT(("MiniportInitialize succeeded"));
	}
	else {
		if (thisDev){
			FreeDevice(thisDev);
		}
		DBGOUT(("MiniportInitialize failed"));
	}
	return result;

}
Esempio n. 14
0
	CWindowsApp::~CWindowsApp()
	{
		FreeDevice();
	}
Esempio n. 15
0
bool USBDevice::InitDevice()
{
	BYTE configDescriptorBuffer[4096];
	ULONG lengthTransferred;

	m_deviceMutex = CreateMutex(NULL, FALSE, "Global\\ASIOUAC2");
	if(GetLastError() == ERROR_ALREADY_EXISTS)
	{
#ifdef _DEBUG
		debugPrintf("ASIOUAC: Can't start device! Device already used!\n");
#endif
		if(m_deviceMutex)
		{
			CloseHandle(m_deviceMutex);
			m_deviceMutex = NULL;
			m_errorCode = ERROR_BUSY;
		}
		return FALSE;
	}

	FreeDevice();
	InitDescriptors();

	m_usbDeviceHandle = FindDevice();
	if(m_usbDeviceHandle == NULL)
		return FALSE;

	lengthTransferred = sizeof(configDescriptorBuffer);
	if(!UsbK_QueryDeviceInformation( m_usbDeviceHandle, DEVICE_SPEED, &lengthTransferred, configDescriptorBuffer))
	{
		m_errorCode = GetLastError();
#ifdef _DEBUG
        debugPrintf("ASIOUAC: UsbK_QueryDeviceInformation failed. ErrorCode: %08Xh\n",  m_errorCode);
#endif
	    UsbK_Free(m_usbDeviceHandle);
		m_usbDeviceHandle = NULL;
		return FALSE;
	}
	m_deviceSpeed = (int)configDescriptorBuffer[0];
#ifdef _DEBUG
	if(m_deviceSpeed == HighSpeed)
        debugPrintf("ASIOUAC: Device speed: high\n");
	else
        debugPrintf("ASIOUAC: Device speed: low/full\n");
#endif
	if(!UsbK_GetDescriptor(m_usbDeviceHandle, USB_DESCRIPTOR_TYPE_DEVICE, 0, 0, configDescriptorBuffer, sizeof(configDescriptorBuffer), &lengthTransferred))
	{
        m_errorCode = GetLastError();
#ifdef _DEBUG
        debugPrintf("ASIOUAC: Get device descriptor failed. ErrorCode: %08Xh\n",  m_errorCode);
#endif
	    UsbK_Free(m_usbDeviceHandle);
		m_usbDeviceHandle = NULL;
		return FALSE;
	}
	memcpy(&m_deviceDescriptor, configDescriptorBuffer, sizeof(USB_DEVICE_DESCRIPTOR));

	if(SendUsbControl(BMREQUEST_DIR_DEVICE_TO_HOST, BMREQUEST_TYPE_STANDARD, BMREQUEST_RECIPIENT_DEVICE, 
					USB_REQUEST_GET_DESCRIPTOR, (USB_DESCRIPTOR_TYPE_CONFIGURATION << 8), 0,
					configDescriptorBuffer, sizeof(configDescriptorBuffer), &lengthTransferred))
	{
		ParseDescriptors(configDescriptorBuffer, lengthTransferred);
		return m_usbDeviceHandle != NULL;
	}
	else
	{
        m_errorCode = GetLastError();
#ifdef _DEBUG
        debugPrintf("ASIOUAC: Get config descriptor failed. ErrorCode: %08Xh\n",  m_errorCode);
#endif
	    UsbK_Free(m_usbDeviceHandle);
		m_usbDeviceHandle = NULL;
		return FALSE;
	}
}
Esempio n. 16
0
// Create the Sucka...
bool CD3D_Device::CreateDevice(D3DAdapterInfo* pAdapter,D3DDeviceInfo* pDevice,D3DModeInfo* pMode)
{
	FreeDevice();								// Make sure it's all released and groovie...

	m_pAdapter	= pAdapter;						// Initialization...
	m_pDevice	= pDevice;
	m_pMode		= pMode;

	// Create the sucka...
 	uint32 BehaviorFlags = D3DCREATE_MULTITHREADED;

	if (pDevice->d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
		BehaviorFlags |= D3DCREATE_MIXED_VERTEXPROCESSING;
	else
		BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;

	D3DPRESENT_PARAMETERS PresentationParam;
	SetPresentationParams(PresentationParam,pMode);
	IDirect3DDevice9 *pD3DDevice;
	HRESULT hResult = PDIRECT3D->CreateDevice(pAdapter->iAdapterNum,pDevice->DeviceType,g_hWnd,BehaviorFlags,&PresentationParam,&pD3DDevice);
	if ((hResult != D3D_OK) || !pD3DDevice)
	{
		// Give it more more try - Presentation params might have been changed by D3D to something acceptable...
		OUTPUT_D3D_ERROR(1,hResult);			// Report the error...
		OutputDebugString("Warning: Create failed. Attempting to fall back...\n");
		TryFallingBack_OnFailedDevCreate(&PresentationParam);
		hResult = PDIRECT3D->CreateDevice(pAdapter->iAdapterNum,pDevice->DeviceType,g_hWnd,BehaviorFlags,&PresentationParam,&pD3DDevice);
		if ((hResult != D3D_OK) || !pD3DDevice)
		{
			OUTPUT_D3D_ERROR(0,hResult); FreeDevice(); return false;
		}
	}

	// Create our wrapper, which we're going to present to the world as an actual D3D device
	LT_MEM_TRACK_ALLOC(m_pD3DDevice = new CDirect3DDevice9Wrapper,LT_MEM_TYPE_RENDERER);
	m_pD3DDevice->SetDevice(pD3DDevice);

	if (FAILED(m_pD3DDevice->GetDeviceCaps(&m_DeviceCaps)))
	{
		FreeDevice();
		return false;
	}

	SetDefaultRenderStates();					// Set the default render states...
	PreCalcSomeDeviceCaps();					// Do some precalcing of device caps (figure out if we can do some puff)...

	m_pD3DDevice->SetStates();

	// Display a warning message
	if (m_pDevice->DeviceType == D3DDEVTYPE_REF)
		AddDebugMessage(1,"Warning: Couldn\'t find any HAL devices, Using reference rasterizer");

	//make sure to clear out the back buffer so it isn't filled with left over garbage
	LTRGBColor ClearColor;
	ClearColor.dwordVal = 0;

	d3d_Clear(NULL, CLEARSCREEN_SCREEN | CLEARSCREEN_RENDER, ClearColor);

	//create the end of frame query events
	PD3DDEVICE->CreateQuery(D3DQUERYTYPE_EVENT, &m_pEndOfFrameQuery);

	// Initialize the render target manager.
	CRenderTargetMgr::GetSingleton().Init();

	return true;
}