Problems with Direct Input

Started by
6 comments, last by LagunaCloud 18 years, 4 months ago
Hey I'm having a problem in my game where if I resize my window and reset everything, I lose my Joysticks. When I debug it, it goes through the re-initialization process, but when it gets to the Poll() and Aquire(), it fails every time. I have no idea what the problem is, when I reset, my keyboard control resets right?
Laguna!!!
Advertisement
Okay now it's even weirder...
It did reset everything and such, but it doesn't reinitialize the Joystick when I switch to a new windowed mode, but when I switch to a fullscreen mode, It works.
Laguna!!!
Lets see the code snippets then we may beable to help!
Goodluck
This is my initialize function;
BOOL cls_JOYSTICK::InitJoystick(HWND* hWnd){		BOOL Success;  HRESULT hr;  DIPROPRANGE diprg;   DIDEVCAPS g_diDevCaps;	init = true;	hwnd = hWnd;	int NumOfTries = 0;	if(FAILED(idi8->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticks, this, DIEDFL_ATTACHEDONLY)))	{		return FALSE;	}	ii = 0; //Static member to access my EnumJoysticks Function;	for(int i = 0; i < Joystick[0].NumOfJoysticks; i++)	{		  	if(FAILED(Joystick.Data->SetDataFormat(&c_dfDIJoystick2)))		{			Joystick.Data->Release();			Joystick.Data = NULL;			return FALSE;		}		if(FAILED(Joystick.Data->SetCooperativeLevel(*hwnd,DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))			{			Joystick.Data->Release();			Joystick.Data = NULL;			return FALSE;		}  		g_diDevCaps.dwSize = sizeof(DIDEVCAPS);		if (FAILED(hr = Joystick.Data->GetCapabilities(&g_diDevCaps)))	    return hr;	    diprg.diph.dwSize       = sizeof( diprg );		    diprg.diph.dwHeaderSize = sizeof( diprg.diph ); 	    diprg.diph.dwObj        = 0; 	    diprg.diph.dwHow        = DIPH_DEVICE; 	    diprg.lMin              = JOYMIN; 	    diprg.lMax              = JOYMAX;  	    if ( FAILED( Joystick.Data->SetProperty( DIPROP_RANGE, &diprg.diph ) ) )	        return FALSE;     // Set deadzone.	    DIPROPDWORD dipdw;		    dipdw.diph.dwSize       = sizeof( dipdw ); 	    dipdw.diph.dwHeaderSize = sizeof( dipdw.diph ); 	    dipdw.diph.dwObj        = 0;	    dipdw.diph.dwHow        = DIPH_DEVICE;	    dipdw.dwData            = JOYDEAD;	    if ( FAILED( Joystick.Data->SetProperty( DIPROP_DEADZONE, &dipdw.diph ) ) )	        return FALSE;    // Set saturation.	    dipdw.dwData            = JOYSAT;	    if ( FAILED( Joystick.Data->SetProperty( DIPROP_SATURATION, &dipdw.diph ) ) )	        return FALSE;    // Find out if force feedback available.	    DIDEVCAPS didc;	    didc.dwSize = sizeof( DIDEVCAPS );	    if ( FAILED(Joystick.Data->GetCapabilities( &didc ) ) ) 	        return FALSE;	   // m_FFAvailable = ( didc.dwFlags & DIDC_FORCEFEEDBACK );	    // If it's a force feedback stick, turn off autocenter so it doesn't	    // get in the way of our effects.	    if ( didc.dwFlags & DIDC_FORCEFEEDBACK )	    {	        DIPROPDWORD DIPropAutoCenter;	        DIPropAutoCenter.diph.dwSize = sizeof( DIPropAutoCenter );	        DIPropAutoCenter.diph.dwHeaderSize = sizeof( DIPROPHEADER );	        DIPropAutoCenter.diph.dwObj = 0;	        DIPropAutoCenter.diph.dwHow = DIPH_DEVICE;	        DIPropAutoCenter.dwData = 0;		        Joystick.Data->SetProperty( DIPROP_AUTOCENTER, 	                               &DIPropAutoCenter.diph );	    } 		else		{}		do{			Joystick.Data->Poll();			Success = SUCCEEDED(Joystick.Data->Acquire());			NumOfTries++;				}while(!Success && NumOfTries < 10);		if(!Success)break;	}	NumOfJoysticks = unsigned char(i);	if(i != 0 && Success)	{		Joy = Joystick[0].Data;		return TRUE;	}		return FALSE;}

This code is my initialize fullscreen

BOOL cls_GFX::InitDispModeFull(int SizeX,int SizeY,int Bits){//	char Bytes;	D3DFORMAT Fmt,AltFmt;	Hal = TRUE;	ZBuffer = TRUE;	if(FAILED(id3d8->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm)))	{//if not able to get current display mode		return FALSE;			//return false	}	ZeroMemory(&d3dpp,sizeof(D3DPRESENT_PARAMETERS));    d3dpp.Windowed   = FALSE;    d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;  	d3dpp.BackBufferCount = NumOfBackBuffers;    d3dpp.BackBufferWidth  = SizeX;    d3dpp.BackBufferHeight = SizeY;    d3dpp.FullScreen_RefreshRateInHz      = D3DPRESENT_RATE_DEFAULT;    d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE; // or D3DPRESENT_INTERVAL_DEFAULT or D3DPRESENT_INTERVAL_IMMEDIATE	//Bytes = GetFormat(d3ddm.Format);	switch(Bits)	{	case 32:		Fmt =D3DFMT_X8R8G8B8;		AltFmt =D3DFMT_X8R8G8B8;		break;	case 24:		Fmt =D3DFMT_R8G8B8;		AltFmt =D3DFMT_R8G8B8;		break;	case 16:		Fmt =D3DFMT_R5G6B5;		AltFmt =D3DFMT_X1R5G5B5;		break;	case 8:		Fmt =D3DFMT_P8;		AltFmt =D3DFMT_P8;		break;	default:		return FALSE;	}	if(FAILED(id3d8->CheckDeviceType(D3DADAPTER_DEFAULT,									 D3DDEVTYPE_HAL,									 Fmt,									 Fmt,									 FALSE)))	{				if(FAILED(id3d8->CheckDeviceType(D3DADAPTER_DEFAULT,									 D3DDEVTYPE_HAL,									 AltFmt,									 AltFmt,									 FALSE)))		{			Hal = FALSE;		}	}	if(!Hal)	if(FAILED(id3d8->CheckDeviceType(D3DADAPTER_DEFAULT,									 D3DDEVTYPE_REF,									 Fmt,									 Fmt,									 FALSE)))	{		if(FAILED(id3d8->CheckDeviceType(D3DADAPTER_DEFAULT,									 D3DDEVTYPE_REF,									 AltFmt,									 AltFmt,									 FALSE)))		{			MessageBox(NULL,"ERROR: COULD NOT INITIALIZE FORMAT","ERROR",NULL);			return FALSE;		}		else		{			Fmt = AltFmt;		}	}	d3dpp.BackBufferFormat = Fmt;	if(ZBuffer)	{				d3dpp.EnableAutoDepthStencil = TRUE;		d3dpp.AutoDepthStencilFormat = D3DFMT_D16;	}	else	{				d3dpp.EnableAutoDepthStencil = FALSE;	}		return TRUE;}

These are my functions for initializing windowed mode

//Initialize Windowed Display modeBOOL cls_GFX::InitDispModeWind(void){	ZBuffer = FALSE;	Hal = TRUE;	if(FAILED(id3d8->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm)))	{//if not able to get current display mode		return FALSE;			//return false	}	return TRUE;}


//Initialize Windowed presentation modeBOOL cls_GFX::InitPresentWind(int SizeX,int SizeY){	ZeroMemory(&d3dpp,sizeof(d3dpp));				//Zero the memory	d3dpp.Windowed = TRUE;							//Set windowed mode	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;		//Set the Swap effect  	d3dpp.BackBufferCount = NumOfBackBuffers;    d3dpp.BackBufferWidth  = SizeX;    d3dpp.BackBufferHeight = SizeY;	d3dpp.BackBufferFormat = d3ddm.Format;			//Set the back buffer format	return TRUE;}

Now the problem is that when I resize the display in fullscreen mode the joysticks reinitialize just fine but when I resize the display to windowed mode it isn't able to aquire the joysticks?



[Edited by - LagunaCloud on November 28, 2005 9:21:06 PM]
Laguna!!!
Better fix that and QUICK! The mod isn't going to be happy.
Read This: http://www.gamedev.net/community/forums/topic.asp?topic_id=355110

Use source tags for the code.
The order in which I re-initialize is as follows:
DeleteWindow();ResetDevice();CreateDevice();if(FullScreen){InitFullscreen();}else{InitWindowedMode();}LoadFiles();SetupInput();SetupKeyboard();SetupJoysticks();


Now that's not exactly how my code looks it just a summary of my code:
It finds the Joysticks when I first startup the program, but when I switch to a new windowed mode, it no longer is able to find em.
When I switch to a Fullscreen mode it finds them. It doesn't make any sense to me.
Laguna!!!
Can you tell us what portion of the code fails... Is it failing at EnumDevices, SetCoopeartiveLevel,SetDataFormat

If you start in windowed mode does it work?

Quote:
It did reset everything and such, but it doesn't reinitialize the Joystick when I switch to a new windowed mode

Are you creating a new window, because if you are then you would have to pass the new HWND to the joystick.

Try using
DISCL_EXCLUSIVE|DISCL_FOREGROUND

[Edited by - Aiursrage2k on November 30, 2005 10:39:24 PM]
Insufficent Information: we need more infromationhttp://staff.samods.org/aiursrage2k/
I tried both and it didn't make a difference, but what I did notice is that my keyboard and mouse were not polling and acquiring right away, so I took it out of my init joysticks function, and it worked. So Woo Hoo!
Laguna!!!

This topic is closed to new replies.

Advertisement