Sign in to follow this  
  • entries
    56
  • comments
    80
  • views
    41683

Keyboard input, scripting and binding complete

Sign in to follow this  

111 views

Woo!

After many stressful hour's of debugging I have finally gotten the Cold Haven Scripting Language(Designed by Renato) working well with the engine.
So far the actual language is stupidly simple here's the syntax.

Command Var1 Var2 Var3 Var4 etc...


Really all it is does receive a bunch of data and bundles it into an array to be parsed.

I also got binding to work pretty well.

Here's an example of how you would bind some keys from a .chs(Cold Haven Script) file.


Bind DIK_UP MForwards
Bind DIK_DOWN MBackwards
Bind DIK_LEFT MLeft
Bind DIK_RIGHT MRight
Bind DIK_W MLeft
Bind DIK_S MBackwards
Bind DIK_A MLeft
Bind DIK_D MRight


Here's a code snippet that actually binds the keys, and checks if they have been pressed.


/// Script.cpp

bool CScript::ParseLine(string szCurLine)
{
std::vector arSplitVars;
arSplitVars = Split(" ", szCurLine,10);

if (arSplitVars[COMMAND]=="Bind")
{
if(g_pInput->BindKey(arSplitVars[1], arSplitVars[2]))
{
return true;
} else {
return false;
}
}
else
{
return false;
}
}

///Input.cpp


#define KEYPUSHED 0x80

bool CInput::BindKey(std::string szKey, std::string szAction)
{
g_pLogging->WriteToLog("CHS:\tBinding key [%s] to action [%s]", szKey.c_str(), szAction.c_str());

Key[nBindNum] = szKey;
Action[nBindNum] = szAction;

nBindNum++;
return true;
}

void CInput::ReadKeyboardData()
{
if(FAILED(m_pKeyboard->GetDeviceState(sizeof(KeyData),(LPVOID)&KeyData)))
{
return;
}

for (int i = 0; i <= nBindNum - 1; i++)
{
for (int j = 0; j <= 145; j++)
{
if(Key == szConvString[j])
{
if(KeyTrigger(KeyData, nConvNum[j]))
{
g_pLogging->WriteToLog("\tKey [%s] Pressed! Action binded [%s] executed!", Key.c_str(), Action.c_str());
}
}
}
}
}

bool CInput::KeyTrigger(unsigned char * KeyData, int Key)
{
if(KeyData[Key] && KEYPUSHED)
{
return true;
}
else
{
return false;
}
}







I would post the whole input class, but it's quite large, and I don't think that's acceptable to post here. [smile]

Here's some stats.



I know its very....sad isn't it? [sad]

Anyways, that's all for now. Comments appreciated!
Sign in to follow this  


2 Comments


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now