View Full Version : input on gdk
protomor
02-01-2004, 01:40 PM
I try to follow the guide but its barely and help.. what do i do?
http://triplebuffer.devmaster.net/projects...nput_object.php (http://triplebuffer.devmaster.net/projects/gdk/input_object.php)
thats the guide
bladder
02-01-2004, 01:55 PM
I try to follow the guide but its barely and help.. what do i do?
Well what's the problem. The guide shows you how to create an input object and then qupdate its state (by calling InputObject.Process()) and then how to check if keys or mouse buttons are pressed.
Are you having troubles with creating input objects or using them? What's the problem exactly?
protomor
02-01-2004, 01:58 PM
Where do I put any of that code? :-/
anubis
02-01-2004, 02:00 PM
/* stupid remark deleted by author */
bladder
02-01-2004, 02:01 PM
the initialization code would go where ever you are initializing you application. After the window has been created because it needs the window handle. Then the Process function would be called each frame to update the objects state. And then when you are done with it and dont need to use it you just call Kill().
anubis
02-01-2004, 02:03 PM
also be sure to update the input before you update things like your game objects or whatever you are doing
protomor
02-01-2004, 02:11 PM
When I do all of that in run() it runs fine but whenever I close the application (hitting esc or the X) the thing crashes.
if i comment out the .process functions it doesnt crash...
anubis
02-01-2004, 02:20 PM
code ?
protomor
02-01-2004, 02:25 PM
void Core::Run( HINSTANCE hInstance )
{
// Initialize COM
if( SUCCEEDED( CoInitialize(NULL) ) )
{
if( this->Init() )
{
//////////////////////////////////////////////////////////
// TODO: Check that this exe is not already open
//////////////////////////////////////////////////////////
// Set window properties
mWndClass.cbSize = sizeof(WNDCLASSEX);
mWndClass.style = CS_CLASSDC;
mWndClass.lpfnWndProc = YGlobalMessageHandler;
mWndClass.cbClsExtra = 4;
mWndClass.cbWndExtra = 4;
mWndClass.hInstance = mhInstance;
mWndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
mWndClass.hbrBackground = NULL;
mWndClass.hIcon = LoadIcon( mhInstance, "IDI_MAIN_ICON" );
mWndClass.hIconSm = LoadIcon( mhInstance, "IDI_MAIN_ICON" );
mWndClass.lpszClassName = mszClassName;
mWndClass.lpszMenuName = NULL;
RegisterClassEx( &mWndClass );
// Create the window
mhWnd = CreateWindow( mszClassName,
mszTitleName,
WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
0, 0,
( mbWindowed ? mWidth : GetSystemMetrics( SM_CXFULLSCREEN ) ),
( mbWindowed ? mHeight : GetSystemMetrics( SM_CYFULLSCREEN ) ),
NULL,
NULL,
mhInstance,
NULL );
Y::InputDevice input;
if( !input.Init( mhWnd, hInstance ) )
{
// Something went wrong
}
Y::Keyboard keyboard;
Y::Mouse mouse;
if( !keyboard.Init( &input ) )
{
g.errFile<< "keyboard init failed\n";
}
if( !mouse.Init( &input ) )
{
g.errFile<< "mouse init failed\n";
}
if( mhWnd )
{
if( !mbWindowed )
{
if( !mbFullscreenCursor )
ShowCursor( false );
SetWindowLong( mhWnd, GWL_STYLE, WS_POPUPWINDOW );
}
ShowWindow( mhWnd, SW_SHOW );
UpdateWindow( mhWnd );
if( mInput.Init( mhWnd, hInstance ) )
{
if( mAudio.Init( mhWnd ) )
{
if( mGraphics.Init( mhWnd,
mbWindowed,
mWidth,
mHeight,
mBits,
mZBufferBits,
mStencilBits,
mbVSync,
mVSVersion,
mPSVersion,
mbForceSW ) )
{
g.pGfx = &mGraphics;
g.pInput = &mInput;
g.pAudio = &mAudio;
g.hWnd = mhWnd;
if( this->CreateManagedResources() )
{
if( this->CreateUnmanagedResources() )
{
this->Loop();
keyboard.Process();
// mouse.Process();
/* if( keyboard.Down( Y::K_Enter ) )
{
PostQuitMessage(0);
mbAlive = false;
}
*/
this->KillUnmanagedResources();
}
this->KillManagedResources();
}
mGraphics.Kill();
}
AudioDevice::KillAll();
mAudio.Kill();
}
InputBase::KillAll();
mInput.Kill();
}
// Clean up window stuff
DestroyWindow( mhWnd );
UnregisterClass( mszClassName, mhInstance );
mhWnd = 0;
}
keyboard.Kill();
mouse.Kill();
input.Kill();
this->Kill();
}
CoUninitialize();
}
}
anubis
02-01-2004, 02:36 PM
i take it that this is what happens in your Loop() method ???
keyboard.Process();
// mouse.Process();
/* if( keyboard.Down( Y::K_Enter ) )
anubis
02-01-2004, 02:40 PM
if it is why don't you simply return from your loop and clean everything up ?
btw, imo it is a horrible style to nest init code like you do...
bladder
02-01-2004, 02:45 PM
:nervous: You should not mess with the internals of the Core class. It's meant to be derived from only. What you want to do, is derive a class for yourself from the Core. So like this:
class Main : public TB::Core
{
TB::Keyboard keyboard;
TB::Mouse mouse;
bool CreateManagedResources()
{
keyboard.Init( GetInputPtr() );
mouse.Init( GetInputPtr() );
return true;
}
void KillManagedResources()
{
keyboard.Kill();
mouse.Kill();
}
bool Update()
{
if( keyboard.Down( TB::K_Enter ) )
return false;
return true;
}
};
Create a that class and run it from WinMain and you'll get the "exit on enter" program you're trying to make.
You are supposed to derive your application from the Core class. Think of the Core as a protected area. You overload the CreateManagedResources() function and create your stuff in there. Then you destroy teh stuff you created in the KillManagedResource() function which is also virtual. In the update function you check if enter was pressed, and if it was, you return false so that the Core knows that the pplication must exit.
see: http://triplebuffer.devmaster.net/projects...e_functions.php (http://triplebuffer.devmaster.net/projects/gdk/overridable_functions.php)
for a list of overridable functions and what you should be doing and what you shouldnt be doing in each function.
bladder
02-01-2004, 02:50 PM
btw, imo it is a horrible style to nest init code like you do...
That Init code nesting is mine ctually. It's from the Core class. I do agree, it isnt really a very neat style, but for now it works. And besides the users are not supposed to see what the Core looks like. :/ Just use it people, dont open it up and see how ugly she is :P
anubis
02-01-2004, 02:53 PM
no offence :D
i didn't even realize that he was fiddling with your code...
bladder
02-01-2004, 03:13 PM
:) no offence taken. After all, I *do* agree with what you said.
anubis
02-01-2004, 06:12 PM
no harm done then
protomor
02-01-2004, 08:09 PM
ya I know i shouldnt mess with the core but Im trying to learn myself and just using something wont cut it. plus I didnt really know how I should go about starting this. thanks alot
anubis
02-02-2004, 12:33 AM
maybe you should have used his lib then to write up your own input code ?
protomor
02-02-2004, 12:58 AM
libs too confusing for me. i got a better grasp looking at this code. im gonna unclass it and make my own version. I dont like classes much :-p im more of a C guy than a C++ guy.
anubis
02-02-2004, 04:18 AM
actually direct input is kept so simple that you should have no problem writing up your own code with the directx doc which can be found online as well as in the directx sdk. the sdk also includes a few examples ( written in c ) that should get you going
vBulletin, Copyright ©2000-2009, Jelsoft Enterprises Ltd.