Jump to content
  • Advertisement

Archived

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

nes8bit

bind DIKEYS "Quake Style"

This topic is 6781 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

Does anyone know of a simple/fast way of being able to bind a command to a key using Direct Input? I already have a simple scripting language(if that''s what you want to call it) already implemented. The reason that I ask is because I thought parsing strings in a fps in realtime would be a bad idea. If you can think of a better idea, then i''d like to read about it.

Share this post


Link to post
Share on other sites
Advertisement

You can do the parsing on startup, or when the user binds a new command. There is no need to continously parse strings in real time.

The simplest way to have commands bound to keys would be a keep an array of functions pointers which are intialized to null. When a function is bound, simply parse the string entered to see if its a bindable command, and parse the key entered to see if its a valid key. Then in your input event handler function, check to see if you have a nonzero pointer for the key pressed in the array and call it.

Here''s some psuedocode. I''m just typing it up so don''t take to a compiler =)

typedef void (*PCOMMAND)();
PCOMMANDS fnCommands[TOTAL_KEYS];

void MoveForward()
{ ........ }

void BindCommand(const char * string)
{
int key;
char * command;

//parse string for command and key here

if(key < 0 // key > TOTAL_KEYS)
error bad key index, return

if command == "+forward"
fnCommands[key] = &MoveForward;
}

void HandleKeyEvent(const KeyEvent &key)
{
if(!fnCommands[key.id])
return;
if(key.state == BUTTONDOWN)
(fnCommands)();
}

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!