Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Paladin__

Programming RPG Book Core Question.

This topic is 5852 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have the following code below that I've written. I'm going thru chapter 10 and I'm trying to establish a good understanding of the core. Since the graphics section is so big, I thought I'd try to initialize DirectInput with the core classes and exit on escape. Since there aren't any examples for Chapter 10 that I can find, (even though the book says there are) I've had to wing it. I error out on the .Create line, and in the core, the Acquire() call returns false. I just don't know why it does. Any ideas?
  
//Direct Input Declarations

	cInput			g_Input;
	cInputDevice	g_Keyboard;
	HWND			z_hWnd;
	HINSTANCE		g_hInst;

	//get the handle and instance of the window

	z_hWnd  = GethWnd();
    g_hInst = GethInst();

	//Initialize the input system

	if(!g_Input.Init(z_hWnd, g_hInst))
	{
		MessageBox(NULL, "input Init() failed", "DOH!", MB_OK);
		return FALSE;
	}

	if(!g_Keyboard.Create(&g_Input, KEYBOARD))
	{
		MessageBox(NULL, "input Keyboard.Create() failed", "DOH!", MB_OK);
		return FALSE;
	}

	//read in device

	g_Keyboard.Read();

	//check to see if escape was pressed.

	if(g_Keyboard.GetKeyState(KEY_ESC) == TRUE)
	{
		MessageBox(NULL, "ESCAPE WAS PRESSED! ! !   WOOT IT WORKED! ! ! ", "YAHOO", MB_OK);
		g_Keyboard.Free();
		g_Input.Shutdown();
		return FALSE;
  
Core Code Sniplet for input. Get's to last line..
  
DIDATAFORMAT *DataFormat;
  DIPROPRANGE   DIprg;
  DIPROPDWORD   DIpdw;

  // Free a prior device

  Free();

  // Check for a valid parent cInput class

  if((m_Input = Input) == NULL)
    return FALSE;

  // Create the device and remember device data format

  switch(Type) {
    case KEYBOARD:
           if(FAILED(m_Input->GetDirectInputCOM()->CreateDevice(GUID_SysKeyboard, &m_pDIDevice, NULL))) 
             return FALSE;
           DataFormat = (DIDATAFORMAT*)&c_dfDIKeyboard;
           break;

    case MOUSE:
           if(FAILED(m_Input->GetDirectInputCOM()->CreateDevice(GUID_SysMouse, &m_pDIDevice, NULL))) 
             return FALSE;
           DataFormat = (DIDATAFORMAT*)&c_dfDIMouse;
           break;

    case JOYSTICK:
           [...joystick stuff]
           break;

    default: return FALSE;
  }

  // Set the windowed usage

  m_Windowed = Windowed;

  // Set the data format of keyboard

  if(FAILED(m_pDIDevice->SetDataFormat(DataFormat)))
    return FALSE;

  // Set the cooperative level - Foreground & Nonexclusive

  if(FAILED(m_pDIDevice->SetCooperativeLevel(m_Input->GethWnd(), DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))
    return FALSE;

  // Set the special properties if it's a joystick

  if(Type == JOYSTICK) {
    [..more joystick stuff..]  }

  // Acquire the device for use

  if(FAILED(m_pDIDevice->Acquire()))
  {
      return FALSE;
  }
   
*Edit: tags - Jim [edited by - Jim Adams on September 11, 2002 12:36:06 AM]

Share this post


Link to post
Share on other sites
Advertisement
Just about every demo past chapter 10 shows the input core in use. I thought I included a core demo in the chapter 10 directory?

First of all, make sure you are using the /J compiler switch in your settings. Secondly, make sure the window handle and instance handle are valid. Next, make sure the call to cInputDevice::Read is in your message pump. As it is, you just might not be fast enough to hit the ESC key for it to register (the call to Read doesn''t wait for you to hit a key).




Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
and Focus On: Advanced Animation with DirectX

Share this post


Link to post
Share on other sites
Hey Jim,

I did have a valid hWnd and hInst. (my hWnd was 0x00050100 and my hInst was 0x00400000, so I guess that's valid) The only thing I have in my Chapter 10 directory from the book is the GameCore. My friend who has another copy of your book also has the same dilemna of no examples in Chapter 10. Even in your Bookcode81 update from your website, you only have a GameCore folder as far as I can tell. Is there another directory I'm not looking at?

I am blonde, so I didn't think to look for an example in future chapters of cInput/cInputDevice in another example .

I typed almost verbatum from your example of "Using the Input Core" on page 440 of the book without the mouse device since I just want to hit a key and exit. For the System_Core, I used the example in the book on page 402 in the Using the cApplication Core Object. I was combining these two examples to make something new and try to use what I've read.

My goal was to use the System and Input together, then add in graphics basically. I used the Core_System functions GethWnd() and GethInst(), and they passed the same values that I listed above to the core_input as far as I can tell from debugging.

In the Input Core, the Init() is successful, the SetDataFormat is successful and the cooperativeLevel call is successful, but then it always returns false on the Acquire(). Thus my problem. I'm going to also check a few other chapters to see if I'm missing something. Any other ideas would be appreciated.

[edited by - Paladin__ on September 12, 2002 6:46:21 AM]

[edited by - Paladin__ on September 12, 2002 6:51:33 AM]

Share this post


Link to post
Share on other sites
Just to clarify something, what is the "/J" setting in the compiler options specific to? I''ll add it to the project tonight, but I''m not sure what it does.

Share this post


Link to post
Share on other sites
The only time the cInputDevice::Acquire function will return FALSE is when there is no DI device object assigned (via the call to Create). You might want to double check the call to Create and see what the return code is.

The /J switch forces char to be extended to unsigned char.

Jim Adams
home.att.net/~rpgbook
Author, Programming Role-Playing Games with DirectX
and Focus On: Advanced Animation with DirectX

Share this post


Link to post
Share on other sites
Ok, the program works now. Alot of it had to do with me putting my code in the wrong place, but one thing still puzzles me:

I took the conditional off my .Create() function. The create function on the Acquire() in the function returns false, but I still have access to the keyboard thru directInput. If Acquire is so important, (which I'm sure it is), why does the keyboard work for me when the create function returns false? Just curious. Tired now, must sleep... I will be on this in the A.M.

Fini: Well, since I made the stoopid mistake of putting my init code in the Frame() area, that was the basis for my problem. Acquire() returns true now. I was getting a DIERR_OTHERAPPHASPRIO return since it was being initialized more than once. Oh well, live and learn.

[edited by - Paladin__ on September 14, 2002 9:12:01 AM]

Share this post


Link to post
Share on other sites
Ok, I have found out what's been bugging me. After fixing MY code, I realized that Acquire() in Input_Core.cpp was returning true like I wanted, but the function itself was returning false. Since I want to understand everything, I investigated further. At the bottom of the code I saw this:


...end of function:

// Set the device type
m_Type = Type;

// Clear the device information
Clear();

// Return a success
return FALSE;


So basically, no matter what I do, it returns FALSE for a success. Is it supposed to be that way?

[edited by - Paladin__ on September 14, 2002 10:19:28 AM]

Share this post


Link to post
Share on other sites
Heh - another bug bites the dust! That code is located in the ::Create function. Thanks for pointing it out - that''ll make the next update.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!