actionMap.cc 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "input/actionMap.h"
  23. #include "platform/event.h"
  24. #include "console/console.h"
  25. #include "platform/platform.h"
  26. #include "platform/platformInput.h"
  27. #include "platform/platformAssert.h"
  28. #include "io/fileStream.h"
  29. #include "io/resource/resourceManager.h"
  30. // Script bindings.
  31. #include "actionMap_ScriptBinding.h"
  32. #define CONST_E 2.7182818284590452353602874f
  33. IMPLEMENT_CONOBJECT(ActionMap);
  34. // This is used for determing keys that have ascii codes for the foreign keyboards. IsAlpha doesn't work on foreign keys.
  35. #define dIsDecentChar(c) (((char(0xa0) <= (c)) && ((c) <= char(0xff))) || (( char(0x21) <= (c)) && ((c) <= char(0x7e))) || (( char(0x91) <= (c)) && ((c) <= char(0x92))))
  36. struct CodeMapping
  37. {
  38. const char* pDescription;
  39. U8 type;
  40. U32 code;
  41. };
  42. struct AsciiMapping
  43. {
  44. const char* pDescription;
  45. U16 asciiCode;
  46. };
  47. extern CodeMapping gVirtualMap[];
  48. extern AsciiMapping gAsciiMap[];
  49. //------------------------------------------------------------------------------
  50. //-------------------------------------- Action maps
  51. //
  52. Vector<ActionMap::BreakEntry> ActionMap::smBreakTable(__FILE__, __LINE__);
  53. //------------------------------------------------------------------------------
  54. ActionMap::ActionMap()
  55. {
  56. VECTOR_SET_ASSOCIATION(mDeviceMaps);
  57. }
  58. //------------------------------------------------------------------------------
  59. ActionMap::~ActionMap()
  60. {
  61. for (U32 i = 0; i < (U32)mDeviceMaps.size(); i++)
  62. delete mDeviceMaps[i];
  63. mDeviceMaps.clear();
  64. }
  65. //------------------------------------------------------------------------------
  66. ActionMap::DeviceMap::~DeviceMap()
  67. {
  68. for(U32 i = 0; i < (U32)nodeMap.size(); i++)
  69. {
  70. dFree(nodeMap[i].makeConsoleCommand);
  71. dFree(nodeMap[i].breakConsoleCommand);
  72. }
  73. }
  74. //------------------------------------------------------------------------------
  75. bool ActionMap::onAdd()
  76. {
  77. if (Parent::onAdd() == false)
  78. return false;
  79. Sim::getActionMapGroup()->addObject(this);
  80. return true;
  81. }
  82. //--------------------------------------------------------------------------
  83. void ActionMap::dumpActionMap(const char* fileName, const bool append) const
  84. {
  85. if (fileName != NULL) {
  86. // Dump the deletion, and creation script commands, followed by all the binds
  87. // to a script.
  88. FileStream iostrm;
  89. if ( !ResourceManager->openFileForWrite( iostrm, fileName, append ? FileStream::WriteAppend : FileStream::Write ) )
  90. {
  91. Con::errorf( "Unable to open file '%s' for writing.", fileName );
  92. return;
  93. }
  94. char lineBuffer[1024];
  95. if ( append )
  96. iostrm.setPosition( iostrm.getStreamSize() );
  97. else
  98. {
  99. // IMPORTANT -- do NOT change the following line, it identifies the file as an input map file
  100. dStrcpy( lineBuffer, "// Torque Input Map File\n" );
  101. iostrm.write( dStrlen( lineBuffer ), lineBuffer );
  102. }
  103. dSprintf(lineBuffer, 1023, "if (isObject(%s)) %s.delete();\n"
  104. "new ActionMap(%s);\n", getName(), getName(), getName());
  105. iostrm.write(dStrlen(lineBuffer), lineBuffer);
  106. // Dump all the binds to the console...
  107. for (S32 i = 0; i < mDeviceMaps.size(); i++) {
  108. const DeviceMap* pDevMap = mDeviceMaps[i];
  109. char devbuffer[32];
  110. getDeviceName(pDevMap->deviceType, pDevMap->deviceInst, devbuffer);
  111. for (S32 j = 0; j < pDevMap->nodeMap.size(); j++) {
  112. const Node& rNode = pDevMap->nodeMap[j];
  113. const char* pModifierString = getModifierString(rNode.modifiers);
  114. char objectbuffer[64];
  115. if (getKeyString(rNode.action, objectbuffer) == false)
  116. continue;
  117. const char* command = (rNode.flags & Node::BindCmd) ? "bindCmd" : "bind";
  118. dSprintf(lineBuffer, 1023, "%s.%s(%s, \"%s%s\"",
  119. getName(),
  120. command,
  121. devbuffer,
  122. pModifierString, objectbuffer);
  123. if (rNode.flags & (Node::HasScale|Node::HasDeadZone|Node::Ranged|Node::Inverted)) {
  124. char buff[10];
  125. U32 curr = 0;
  126. buff[curr++] = ',';
  127. buff[curr++] = ' ';
  128. if (rNode.flags & Node::HasScale)
  129. buff[curr++] = 'S';
  130. if (rNode.flags & Node::Ranged)
  131. buff[curr++] = 'R';
  132. if (rNode.flags & Node::HasDeadZone)
  133. buff[curr++] = 'D';
  134. if (rNode.flags & Node::Inverted)
  135. buff[curr++] = 'I';
  136. buff[curr] = '\0';
  137. dStrcat(lineBuffer, buff);
  138. }
  139. if (rNode.flags & Node::HasDeadZone) {
  140. char buff[64];
  141. dSprintf(buff, 63, ", \"%g %g\"", rNode.deadZoneBegin, rNode.deadZoneEnd);
  142. dStrcat(lineBuffer, buff);
  143. }
  144. if (rNode.flags & Node::HasScale) {
  145. char buff[64];
  146. dSprintf(buff, 63, ", %g", rNode.scaleFactor);
  147. dStrcat(lineBuffer, buff);
  148. }
  149. if (rNode.flags & Node::BindCmd) {
  150. if (rNode.makeConsoleCommand) {
  151. dStrcat(lineBuffer, ", \"");
  152. U32 pos = dStrlen(lineBuffer);
  153. expandEscape(lineBuffer + pos, rNode.makeConsoleCommand);
  154. dStrcat(lineBuffer, "\"");
  155. } else {
  156. dStrcat(lineBuffer, ", \"\"");
  157. }
  158. if (rNode.breakConsoleCommand) {
  159. dStrcat(lineBuffer, ", \"");
  160. U32 pos = dStrlen(lineBuffer);
  161. expandEscape(lineBuffer + pos, rNode.breakConsoleCommand);
  162. dStrcat(lineBuffer, "\"");
  163. }
  164. else
  165. dStrcat(lineBuffer, ", \"\"");
  166. } else {
  167. dStrcat(lineBuffer, ", ");
  168. dStrcat(lineBuffer, rNode.consoleFunction);
  169. }
  170. dStrcat(lineBuffer, ");\n");
  171. iostrm.write(dStrlen(lineBuffer), lineBuffer);
  172. }
  173. }
  174. iostrm.close();
  175. }
  176. else {
  177. // Dump all the binds to the console...
  178. for (S32 i = 0; i < mDeviceMaps.size(); i++) {
  179. const DeviceMap* pDevMap = mDeviceMaps[i];
  180. char devbuffer[32];
  181. getDeviceName(pDevMap->deviceType, pDevMap->deviceInst, devbuffer);
  182. for (S32 j = 0; j < pDevMap->nodeMap.size(); j++) {
  183. const Node& rNode = pDevMap->nodeMap[j];
  184. const char* pModifierString = getModifierString(rNode.modifiers);
  185. char keybuffer[64];
  186. if (getKeyString(rNode.action, keybuffer) == false)
  187. continue;
  188. const char* command = (rNode.flags & Node::BindCmd) ? "bindCmd" : "bind";
  189. char finalBuffer[1024];
  190. dSprintf(finalBuffer, 1023, "%s.%s(%s, \"%s%s\"",
  191. getName(),
  192. command,
  193. devbuffer,
  194. pModifierString, keybuffer);
  195. if (rNode.flags & (Node::HasScale|Node::HasDeadZone|Node::Ranged|Node::Inverted)) {
  196. char buff[10];
  197. U32 curr = 0;
  198. buff[curr++] = ',';
  199. buff[curr++] = ' ';
  200. if (rNode.flags & Node::HasScale)
  201. buff[curr++] = 'S';
  202. if (rNode.flags & Node::Ranged)
  203. buff[curr++] = 'R';
  204. if (rNode.flags & Node::HasDeadZone)
  205. buff[curr++] = 'D';
  206. if (rNode.flags & Node::Inverted)
  207. buff[curr++] = 'I';
  208. buff[curr] = '\0';
  209. dStrcat(finalBuffer, buff);
  210. }
  211. if (rNode.flags & Node::HasDeadZone) {
  212. char buff[64];
  213. dSprintf(buff, 63, ", \"%g %g\"", rNode.deadZoneBegin, rNode.deadZoneEnd);
  214. dStrcat(finalBuffer, buff);
  215. }
  216. if (rNode.flags & Node::HasScale) {
  217. char buff[64];
  218. dSprintf(buff, 63, ", %g", rNode.scaleFactor);
  219. dStrcat(finalBuffer, buff);
  220. }
  221. if (rNode.flags & Node::BindCmd) {
  222. if (rNode.makeConsoleCommand) {
  223. dStrcat(finalBuffer, ", \"");
  224. dStrcat(finalBuffer, rNode.makeConsoleCommand);
  225. dStrcat(finalBuffer, "\"");
  226. } else {
  227. dStrcat(finalBuffer, ", \"\"");
  228. }
  229. if (rNode.breakConsoleCommand) {
  230. dStrcat(finalBuffer, ", \"");
  231. dStrcat(finalBuffer, rNode.breakConsoleCommand);
  232. dStrcat(finalBuffer, "\"");
  233. }
  234. else
  235. dStrcat(finalBuffer, ", \"\"");
  236. } else {
  237. dStrcat(finalBuffer, ", ");
  238. dStrcat(finalBuffer, rNode.consoleFunction);
  239. }
  240. dStrcat(finalBuffer, ");");
  241. Con::printf(finalBuffer);
  242. }
  243. }
  244. }
  245. }
  246. //--------------------------------------------------------------------------
  247. bool ActionMap::createEventDescriptor(const char* pEventString, EventDescriptor* pDescriptor)
  248. {
  249. char copyBuffer[256];
  250. dStrcpy(copyBuffer, pEventString);
  251. // Do we have modifiers?
  252. char* pSpace = dStrchr(copyBuffer, ' ');
  253. char* pObjectString;
  254. if (pSpace != NULL) {
  255. // Yes. Parse them out...
  256. //
  257. pDescriptor->flags = 0;
  258. pObjectString = pSpace + 1;
  259. pSpace[0] = '\0';
  260. char* pModifier = dStrtok(copyBuffer, "-");
  261. while (pModifier != NULL) {
  262. if (dStricmp(pModifier, "shift") == 0) {
  263. pDescriptor->flags |= SI_SHIFT;
  264. } else if (dStricmp(pModifier, "ctrl") == 0) {
  265. pDescriptor->flags |= SI_CTRL;
  266. } else if (dStricmp(pModifier, "alt") == 0) {
  267. pDescriptor->flags |= SI_ALT;
  268. } else if (dStricmp(pModifier, "cmd") == 0) {
  269. pDescriptor->flags |= SI_ALT;
  270. } else if (dStricmp(pModifier, "opt") == 0) {
  271. pDescriptor->flags |= SI_MAC_OPT;
  272. }
  273. pModifier = dStrtok(NULL, "-");
  274. }
  275. } else {
  276. // No.
  277. pDescriptor->flags = 0;
  278. pObjectString = copyBuffer;
  279. }
  280. // Now we need to map the key string to the proper KEY code from event.h
  281. //
  282. AssertFatal(dStrlen(pObjectString) != 0, "Error, no key was specified!");
  283. if (dStrlen(pObjectString) == 1)
  284. {
  285. if (dIsDecentChar(*pObjectString)) // includes foreign chars
  286. {
  287. U16 asciiCode = (*pObjectString);
  288. // clear out the FF in upper 8bits for foreign keys??
  289. asciiCode &= 0xFF;
  290. U16 keyCode = Input::getKeyCode(asciiCode);
  291. if ( keyCode >= KEY_0 )
  292. {
  293. pDescriptor->eventType = SI_KEY;
  294. pDescriptor->eventCode = keyCode;
  295. return true;
  296. }
  297. else if (dIsalpha(*pObjectString) == true)
  298. {
  299. pDescriptor->eventType = SI_KEY;
  300. pDescriptor->eventCode = KEY_A+dTolower(*pObjectString)-'a';
  301. return true;
  302. }
  303. else if (dIsdigit(*pObjectString) == true)
  304. {
  305. pDescriptor->eventType = SI_KEY;
  306. pDescriptor->eventCode = KEY_0+(*pObjectString)-'0';
  307. return true;
  308. }
  309. }
  310. return false;
  311. }
  312. else
  313. {
  314. pDescriptor->eventCode = 0;
  315. // Gotta search through the Ascii table...
  316. for (U16 i = 0; gAsciiMap[i].asciiCode != 0xFFFF; i++)
  317. {
  318. if (dStricmp(pObjectString, gAsciiMap[i].pDescription) == 0)
  319. {
  320. U16 asciiCode = gAsciiMap[i].asciiCode;
  321. U16 keyCode = Input::getKeyCode(asciiCode);
  322. if ( keyCode >= KEY_0 )
  323. {
  324. pDescriptor->eventType = SI_KEY;
  325. pDescriptor->eventCode = keyCode;
  326. return(true);
  327. }
  328. else
  329. {
  330. break;
  331. }
  332. }
  333. }
  334. // Didn't find an ascii match. Check the virtual map table
  335. for (U32 j = 0; gVirtualMap[j].code != 0xFFFFFFFF; j++)
  336. {
  337. if (dStricmp(pObjectString, gVirtualMap[j].pDescription) == 0)
  338. {
  339. pDescriptor->eventType = gVirtualMap[j].type;
  340. pDescriptor->eventCode = gVirtualMap[j].code;
  341. return true;
  342. }
  343. }
  344. }
  345. return false;
  346. }
  347. //------------------------------------------------------------------------------
  348. ActionMap::Node* ActionMap::getNode(const U32 inDeviceType, const U32 inDeviceInst,
  349. const U32 inModifiers, const U32 inAction,SimObject* object /*= NULL*/)
  350. {
  351. // DMMTODO - Slow INITIAL implementation. Replace with a faster version...
  352. //
  353. DeviceMap* pDeviceMap = NULL;
  354. U32 i;
  355. for (i = 0; i < (U32)mDeviceMaps.size(); i++)
  356. {
  357. if (mDeviceMaps[i]->deviceType == inDeviceType &&
  358. mDeviceMaps[i]->deviceInst == inDeviceInst) {
  359. pDeviceMap = mDeviceMaps[i];
  360. break;
  361. }
  362. }
  363. if (pDeviceMap == NULL)
  364. {
  365. mDeviceMaps.increment();
  366. mDeviceMaps.last() = new DeviceMap;
  367. pDeviceMap = mDeviceMaps.last();
  368. pDeviceMap->deviceInst = inDeviceInst;
  369. pDeviceMap->deviceType = inDeviceType;
  370. }
  371. for (i = 0; i < (U32)pDeviceMap->nodeMap.size(); i++)
  372. {
  373. if (pDeviceMap->nodeMap[i].modifiers == inModifiers &&
  374. pDeviceMap->nodeMap[i].action == inAction &&
  375. ( (object != NULL) ? object == pDeviceMap->nodeMap[i].object : true )) // Check for an object match if the object exists
  376. {
  377. return &pDeviceMap->nodeMap[i];
  378. }
  379. }
  380. // If we're here, the node doesn't exist. create it.
  381. pDeviceMap->nodeMap.increment();
  382. Node* pRetNode = &pDeviceMap->nodeMap.last();
  383. pRetNode->modifiers = inModifiers;
  384. pRetNode->action = inAction;
  385. pRetNode->flags = 0;
  386. pRetNode->deadZoneBegin = 0.0;
  387. pRetNode->deadZoneEnd = 0.0;
  388. pRetNode->scaleFactor = 1.0;
  389. pRetNode->consoleFunction = NULL;
  390. pRetNode->makeConsoleCommand = NULL;
  391. pRetNode->breakConsoleCommand = NULL;
  392. //[neob, 5/7/2007 - #2975]
  393. pRetNode->object = 0;
  394. return pRetNode;
  395. }
  396. //------------------------------------------------------------------------------
  397. void ActionMap::removeNode(const U32 inDeviceType, const U32 inDeviceInst, const U32 inModifiers, const U32 inAction, SimObject* object /*= NULL*/)
  398. {
  399. // DMMTODO - Slow INITIAL implementation. Replace with a faster version...
  400. //
  401. DeviceMap* pDeviceMap = NULL;
  402. U32 i;
  403. for (i = 0; i < (U32)mDeviceMaps.size(); i++) {
  404. if (mDeviceMaps[i]->deviceType == inDeviceType &&
  405. mDeviceMaps[i]->deviceInst == inDeviceInst) {
  406. pDeviceMap = mDeviceMaps[i];
  407. break;
  408. }
  409. }
  410. if (pDeviceMap == NULL)
  411. return;
  412. U32 realMods = inModifiers;
  413. if (realMods & SI_SHIFT)
  414. realMods |= SI_SHIFT;
  415. if (realMods & SI_CTRL)
  416. realMods |= SI_CTRL;
  417. if (realMods & SI_ALT)
  418. realMods |= SI_ALT;
  419. if (realMods & SI_MAC_OPT)
  420. realMods |= SI_MAC_OPT;
  421. for (i = 0; i < (U32)pDeviceMap->nodeMap.size(); i++) {
  422. if (pDeviceMap->nodeMap[i].modifiers == realMods &&
  423. pDeviceMap->nodeMap[i].action == inAction &&
  424. ( (object != NULL) ? object == pDeviceMap->nodeMap[i].object : true ))
  425. {
  426. dFree(pDeviceMap->nodeMap[i].makeConsoleCommand);
  427. dFree(pDeviceMap->nodeMap[i].breakConsoleCommand);
  428. pDeviceMap->nodeMap.erase(i);
  429. }
  430. }
  431. }
  432. //------------------------------------------------------------------------------
  433. const ActionMap::Node* ActionMap::findNode(const U32 inDeviceType, const U32 inDeviceInst,
  434. const U32 inModifiers, const U32 inAction)
  435. {
  436. // DMMTODO - Slow INITIAL implementation. Replace with a faster version...
  437. //
  438. DeviceMap* pDeviceMap = NULL;
  439. U32 i;
  440. for (i = 0; i < (U32)mDeviceMaps.size(); i++)
  441. {
  442. if (mDeviceMaps[i]->deviceType == inDeviceType && mDeviceMaps[i]->deviceInst == inDeviceInst)
  443. {
  444. pDeviceMap = mDeviceMaps[i];
  445. break;
  446. }
  447. }
  448. if (pDeviceMap == NULL)
  449. return NULL;
  450. U32 realMods = inModifiers;
  451. if (realMods & SI_SHIFT)
  452. realMods |= SI_SHIFT;
  453. if (realMods & SI_CTRL)
  454. realMods |= SI_CTRL;
  455. if (realMods & SI_ALT)
  456. realMods |= SI_ALT;
  457. if (realMods & SI_MAC_OPT)
  458. realMods |= SI_MAC_OPT;
  459. for (i = 0; i < (U32)pDeviceMap->nodeMap.size(); i++)
  460. {
  461. if (pDeviceMap->nodeMap[i].action == KEY_ANYKEY && pDeviceMap->nodeMap[i].modifiers == realMods && dIsDecentChar(inAction))
  462. return &pDeviceMap->nodeMap[i];
  463. else if (pDeviceMap->nodeMap[i].modifiers == realMods && pDeviceMap->nodeMap[i].action == inAction)
  464. return &pDeviceMap->nodeMap[i];
  465. }
  466. return NULL;
  467. }
  468. //------------------------------------------------------------------------------
  469. bool ActionMap::findBoundNode( const char* function, U32 &devMapIndex, U32 &nodeIndex )
  470. {
  471. devMapIndex = 0;
  472. nodeIndex = 0;
  473. return nextBoundNode( function, devMapIndex, nodeIndex );
  474. }
  475. bool ActionMap::nextBoundNode( const char* function, U32 &devMapIndex, U32 &nodeIndex )
  476. {
  477. // Loop through all of the existing nodes to find the one mapped to the
  478. // given function:
  479. for ( U32 i = devMapIndex; i < (U32)mDeviceMaps.size(); i++ )
  480. {
  481. const DeviceMap* dvcMap = mDeviceMaps[i];
  482. for ( U32 j = nodeIndex; j < (U32)dvcMap->nodeMap.size(); j++ )
  483. {
  484. const Node* node = &dvcMap->nodeMap[j];
  485. if ( !( node->flags & Node::BindCmd ) && ( dStricmp( function, node->consoleFunction ) == 0 ) )
  486. {
  487. devMapIndex = i;
  488. nodeIndex = j;
  489. return( true );
  490. }
  491. }
  492. nodeIndex = 0;
  493. }
  494. return( false );
  495. }
  496. //------------------------------------------------------------------------------
  497. bool ActionMap::processUnbind(const char *device, const char *action, SimObject* object /*= NULL*/)
  498. {
  499. U32 deviceType;
  500. U32 deviceInst;
  501. if(!getDeviceTypeAndInstance(device, deviceType, deviceInst))
  502. return false;
  503. EventDescriptor eventDescriptor;
  504. if (!createEventDescriptor(action, &eventDescriptor))
  505. return false;
  506. removeNode(deviceType, deviceInst, eventDescriptor.flags,eventDescriptor.eventCode, object);
  507. return true;
  508. }
  509. //------------------------------------------------------------------------------
  510. // This function is for the use of the control remapper.
  511. // It will only check against the console function (since all remappable commands are
  512. // bound using bind and not bindCmd).
  513. //
  514. const char* ActionMap::getBinding( const char* command )
  515. {
  516. char* returnString = Con::getReturnBuffer( 1024 );
  517. returnString[0] = 0;
  518. char buffer[256];
  519. char deviceBuffer[32];
  520. char keyBuffer[64];
  521. U32 devMapIndex = 0, nodeIndex = 0;
  522. while ( nextBoundNode( command, devMapIndex, nodeIndex ) )
  523. {
  524. const DeviceMap* deviceMap = mDeviceMaps[devMapIndex];
  525. if ( getDeviceName( deviceMap->deviceType, deviceMap->deviceInst, deviceBuffer ) )
  526. {
  527. const Node* node = &deviceMap->nodeMap[nodeIndex];
  528. const char* modifierString = getModifierString( node->modifiers );
  529. if ( getKeyString( node->action, keyBuffer ) )
  530. {
  531. dSprintf( buffer, sizeof( buffer ), "%s\t%s%s", deviceBuffer, modifierString, keyBuffer );
  532. if ( returnString[0] )
  533. dStrcat( returnString, "\t" );
  534. dStrcat( returnString, buffer );
  535. }
  536. }
  537. ++nodeIndex;
  538. }
  539. return returnString;
  540. }
  541. //------------------------------------------------------------------------------
  542. // This function is for the use of the control remapper.
  543. // The intent of this function is to determine if the given event descriptor is already
  544. // bound in this action map. If so, this function returns the command it is bound to.
  545. // If not, it returns NULL.
  546. //
  547. const char* ActionMap::getCommand( const char* device, const char* action )
  548. {
  549. U32 deviceType;
  550. U32 deviceInst;
  551. if ( getDeviceTypeAndInstance( device, deviceType, deviceInst ) )
  552. {
  553. EventDescriptor eventDescriptor;
  554. if ( createEventDescriptor( action, &eventDescriptor ) )
  555. {
  556. const ActionMap::Node* mapNode = findNode( deviceType, deviceInst, eventDescriptor.flags, eventDescriptor.eventCode );
  557. if ( mapNode )
  558. {
  559. if ( mapNode->flags & Node::BindCmd )
  560. {
  561. S32 bufferLen = dStrlen( mapNode->makeConsoleCommand ) + dStrlen( mapNode->breakConsoleCommand ) + 2;
  562. char* returnString = Con::getReturnBuffer( bufferLen );
  563. dSprintf( returnString, bufferLen, "%s\t%s",
  564. ( mapNode->makeConsoleCommand ? mapNode->makeConsoleCommand : "" ),
  565. ( mapNode->breakConsoleCommand ? mapNode->breakConsoleCommand : "" ) );
  566. return( returnString );
  567. }
  568. else
  569. return( mapNode->consoleFunction );
  570. }
  571. }
  572. }
  573. return( "" );
  574. }
  575. //------------------------------------------------------------------------------
  576. // This function returns whether or not the mapping specified is inverted.
  577. // Obviously, this should only be used for axes.
  578. bool ActionMap::isInverted( const char* device, const char* action )
  579. {
  580. U32 deviceType;
  581. U32 deviceInst;
  582. if ( getDeviceTypeAndInstance( device, deviceType, deviceInst ) )
  583. {
  584. EventDescriptor eventDescriptor;
  585. if ( createEventDescriptor( action, &eventDescriptor ) )
  586. {
  587. const ActionMap::Node* mapNode = findNode( deviceType, deviceInst, eventDescriptor.flags, eventDescriptor.eventCode );
  588. if ( mapNode )
  589. return( mapNode->flags & Node::Inverted );
  590. }
  591. }
  592. Con::errorf( "The input event specified by %s %s is not in this action map!", device, action );
  593. return( false );
  594. }
  595. //------------------------------------------------------------------------------
  596. F32 ActionMap::getScale( const char* device, const char* action )
  597. {
  598. U32 deviceType;
  599. U32 deviceInst;
  600. if ( getDeviceTypeAndInstance( device, deviceType, deviceInst ) )
  601. {
  602. EventDescriptor eventDescriptor;
  603. if ( createEventDescriptor( action, &eventDescriptor ) )
  604. {
  605. const ActionMap::Node* mapNode = findNode( deviceType, deviceInst, eventDescriptor.flags, eventDescriptor.eventCode );
  606. if ( mapNode )
  607. {
  608. if ( mapNode->flags & Node::HasScale )
  609. return( mapNode->scaleFactor );
  610. else
  611. return( 1.0f );
  612. }
  613. }
  614. }
  615. Con::errorf( "The input event specified by %s %s is not in this action map!", device, action );
  616. return( 1.0f );
  617. }
  618. //------------------------------------------------------------------------------
  619. const char* ActionMap::getDeadZone( const char* device, const char* action )
  620. {
  621. U32 deviceType;
  622. U32 deviceInst;
  623. if ( getDeviceTypeAndInstance( device, deviceType, deviceInst ) )
  624. {
  625. EventDescriptor eventDescriptor;
  626. if ( createEventDescriptor( action, &eventDescriptor ) )
  627. {
  628. const ActionMap::Node* mapNode = findNode( deviceType, deviceInst, eventDescriptor.flags, eventDescriptor.eventCode );
  629. if ( mapNode )
  630. {
  631. if ( mapNode->flags & Node::HasDeadZone )
  632. {
  633. char buf[64];
  634. dSprintf( buf, sizeof( buf ), "%g %g", mapNode->deadZoneBegin, mapNode->deadZoneEnd );
  635. char* returnString = Con::getReturnBuffer( dStrlen( buf ) + 1 );
  636. dStrcpy( returnString, buf );
  637. return( returnString );
  638. }
  639. else
  640. return( "0 0" );
  641. }
  642. }
  643. }
  644. Con::errorf( "The input event specified by %s %s is not in this action map!", device, action );
  645. return( "" );
  646. }
  647. //------------------------------------------------------------------------------
  648. const char* ActionMap::buildActionString( const InputEvent* event )
  649. {
  650. const char* modifierString = getModifierString( event->modifier );
  651. char objectBuffer[64];
  652. if ( !getKeyString( event->objInst, objectBuffer ) )
  653. return( "" );
  654. U32 returnLen = dStrlen( modifierString ) + dStrlen( objectBuffer ) + 2;
  655. char* returnString = Con::getReturnBuffer( returnLen );
  656. dSprintf( returnString, returnLen - 1, "%s%s", modifierString, objectBuffer );
  657. return( returnString );
  658. }
  659. //------------------------------------------------------------------------------
  660. bool ActionMap::getDeviceTypeAndInstance(const char *pDeviceName, U32 &deviceType, U32 &deviceInstance)
  661. {
  662. U32 offset = 0;
  663. if (dStrnicmp(pDeviceName, "keyboard", dStrlen("keyboard")) == 0)
  664. {
  665. deviceType = KeyboardDeviceType;
  666. offset = dStrlen("keyboard");
  667. }
  668. else if (dStrnicmp(pDeviceName, "mouse", dStrlen("mouse")) == 0)
  669. {
  670. deviceType = MouseDeviceType;
  671. offset = dStrlen("mouse");
  672. }
  673. else if (dStrnicmp(pDeviceName, "joystick", dStrlen("joystick")) == 0)
  674. {
  675. deviceType = JoystickDeviceType;
  676. offset = dStrlen("joystick");
  677. }
  678. else if (dStrnicmp(pDeviceName, "accelerometer", dStrlen("accelerometer")) == 0)
  679. {
  680. deviceType = AccelerometerDeviceType;
  681. offset = dStrlen("accelerometer");
  682. }
  683. else if (dStrnicmp(pDeviceName, "gyroscope", dStrlen("gyroscope")) == 0)
  684. {
  685. deviceType = GyroscopeDeviceType;
  686. offset = dStrlen("gyroscope");
  687. }
  688. else if (dStrnicmp(pDeviceName, "touchdevice", dStrlen("touchdevice")) == 0)
  689. {
  690. deviceType = ScreenTouchDeviceType;
  691. offset = dStrlen("touchdevice");
  692. }
  693. else if (dStrnicmp(pDeviceName, "gamepad", dStrlen("gamepad")) == 0)
  694. {
  695. deviceType = GamepadDeviceType;
  696. offset = dStrlen("gamepad");
  697. }
  698. else if (dStrnicmp(pDeviceName, "leapdevice", dStrlen("leapdevice")) == 0)
  699. {
  700. deviceType = LeapMotionDeviceType;
  701. offset = dStrlen("leapdevice");
  702. }
  703. else
  704. return false;
  705. if (dStrlen(pDeviceName) > offset)
  706. {
  707. const char* pInst = pDeviceName + offset;
  708. S32 instNum = dAtoi(pInst);
  709. if (instNum < 0)
  710. deviceInstance = 0;
  711. else
  712. deviceInstance = instNum;
  713. }
  714. else
  715. deviceInstance = 0;
  716. return true;
  717. }
  718. //------------------------------------------------------------------------------
  719. bool ActionMap::getDeviceName(const U32 deviceType, const U32 deviceInstance, char* buffer)
  720. {
  721. switch (deviceType)
  722. {
  723. case KeyboardDeviceType:
  724. dStrcpy(buffer, "keyboard");
  725. break;
  726. case MouseDeviceType:
  727. dSprintf(buffer, 16, "mouse%d", deviceInstance);
  728. break;
  729. case JoystickDeviceType:
  730. dSprintf(buffer, 16, "joystick%d", deviceInstance);
  731. break;
  732. case AccelerometerDeviceType:
  733. dStrcpy(buffer, "accelerometer");
  734. break;
  735. case GyroscopeDeviceType:
  736. dStrcpy(buffer, "gyroscope");
  737. break;
  738. case ScreenTouchDeviceType:
  739. dStrcpy(buffer, "touchdevice");
  740. break;
  741. case GamepadDeviceType:
  742. dSprintf(buffer, 16, "gamepad%d", deviceInstance);
  743. break;
  744. case LeapMotionDeviceType:
  745. dStrcpy(buffer, "leapdevice");
  746. break;
  747. default:
  748. Con::errorf( "ActionMap::getDeviceName: unknown device type specified, %d (inst: %d)", deviceType, deviceInstance);
  749. return false;
  750. }
  751. return true;
  752. }
  753. //------------------------------------------------------------------------------
  754. const char* ActionMap::getModifierString(const U32 modifiers)
  755. {
  756. U32 realModifiers = modifiers;
  757. if ( modifiers & SI_LSHIFT || modifiers & SI_RSHIFT )
  758. realModifiers |= SI_SHIFT;
  759. if ( modifiers & SI_LCTRL || modifiers & SI_RCTRL )
  760. realModifiers |= SI_CTRL;
  761. if ( modifiers & SI_LALT || modifiers & SI_RALT )
  762. realModifiers |= SI_ALT;
  763. if ( modifiers & SI_MAC_LOPT || modifiers & SI_MAC_ROPT )
  764. realModifiers |= SI_MAC_OPT;
  765. switch (realModifiers & (SI_SHIFT|SI_CTRL|SI_ALT|SI_MAC_OPT)) {
  766. #if defined(TORQUE_OS_OSX)
  767. // optional code, to output alt as cmd on mac.
  768. // interpreter sees them as the same...
  769. case (SI_SHIFT|SI_CTRL|SI_ALT):
  770. return "cmd-shift-ctrl ";
  771. case (SI_SHIFT|SI_ALT):
  772. return "cmd-shift ";
  773. case (SI_CTRL|SI_ALT):
  774. return "cmd-ctrl ";
  775. case (SI_ALT):
  776. return "cmd ";
  777. #else
  778. case (SI_SHIFT|SI_CTRL|SI_ALT):
  779. return "shift-ctrl-alt ";
  780. case (SI_SHIFT|SI_ALT):
  781. return "shift-alt ";
  782. case (SI_CTRL|SI_ALT):
  783. return "ctrl-alt ";
  784. case (SI_ALT):
  785. return "alt ";
  786. #endif
  787. case (SI_SHIFT|SI_CTRL):
  788. return "shift-ctrl ";
  789. case (SI_SHIFT):
  790. return "shift ";
  791. case (SI_CTRL):
  792. return "ctrl ";
  793. // plus new mac cases:
  794. case (SI_ALT|SI_SHIFT|SI_CTRL|SI_MAC_OPT):
  795. return "cmd-shift-ctrl-opt ";
  796. case (SI_ALT|SI_SHIFT|SI_MAC_OPT):
  797. return "cmd-shift-opt ";
  798. case (SI_ALT|SI_CTRL|SI_MAC_OPT):
  799. return "cmd-ctrl-opt ";
  800. case (SI_ALT|SI_MAC_OPT):
  801. return "cmd-opt ";
  802. case (SI_SHIFT|SI_CTRL|SI_MAC_OPT):
  803. return "shift-ctrl-opt ";
  804. case (SI_SHIFT|SI_MAC_OPT):
  805. return "shift-opt ";
  806. case (SI_CTRL|SI_MAC_OPT):
  807. return "ctrl-opt ";
  808. case (SI_MAC_OPT):
  809. return "opt ";
  810. case 0:
  811. return "";
  812. default:
  813. AssertFatal(false, "Error, should never reach the default case in getModifierString");
  814. return "";
  815. }
  816. }
  817. //------------------------------------------------------------------------------
  818. bool ActionMap::getKeyString(const U32 action, char* buffer)
  819. {
  820. U16 asciiCode = Input::getAscii(action, STATE_LOWER);
  821. // if (action >= KEY_A && action <= KEY_Z) {
  822. // buffer[0] = char(action - KEY_A + 'a');
  823. // buffer[1] = '\0';
  824. // return true;
  825. // } else if (action >= KEY_0 && action <= KEY_9) {
  826. // buffer[0] = char(action - KEY_0 + '0');
  827. // buffer[1] = '\0';
  828. if ( (asciiCode != 0) && dIsDecentChar((char)asciiCode))
  829. {
  830. for (U32 i = 0; gAsciiMap[i].asciiCode != 0xFFFF; i++) {
  831. if (gAsciiMap[i].asciiCode == asciiCode)
  832. {
  833. dStrcpy(buffer, gAsciiMap[i].pDescription);
  834. return true;
  835. }
  836. }
  837. // Must not have found a string for that ascii code just record the char
  838. buffer[0] = char(asciiCode);
  839. buffer[1] = '\0';
  840. return true;
  841. }
  842. else
  843. {
  844. if (action >= KEY_A && action <= KEY_Z)
  845. {
  846. buffer[0] = char(action - KEY_A + 'a');
  847. buffer[1] = '\0';
  848. return true;
  849. }
  850. else if (action >= KEY_0 && action <= KEY_9) {
  851. buffer[0] = char(action - KEY_0 + '0');
  852. buffer[1] = '\0';
  853. return true;
  854. }
  855. for (U32 i = 0; gVirtualMap[i].code != 0xFFFFFFFF; i++) {
  856. if (gVirtualMap[i].code == action) {
  857. dStrcpy(buffer, gVirtualMap[i].pDescription);
  858. return true;
  859. }
  860. }
  861. }
  862. Con::errorf( "ActionMap::getKeyString: no string for action %d", action );
  863. return false;
  864. }
  865. //--------------------------------------------------------------------------
  866. bool ActionMap::processBindCmd(const char *device, const char *action, const char *makeCmd, const char *breakCmd)
  867. {
  868. U32 deviceType;
  869. U32 deviceInst;
  870. if(!getDeviceTypeAndInstance(device, deviceType, deviceInst))
  871. {
  872. Con::printf("processBindCmd: unknown device: %s", device);
  873. return false;
  874. }
  875. // Ok, we now have the deviceType and instance. Create an event descriptor
  876. // for the bind...
  877. //
  878. EventDescriptor eventDescriptor;
  879. if (createEventDescriptor(action, &eventDescriptor) == false) {
  880. Con::printf("Could not create a description for binding: %s", action);
  881. return false;
  882. }
  883. // SI_POV == SI_MOVE, and the POV works fine with bindCmd, so we have to add these manually.
  884. if( ( eventDescriptor.eventCode == SI_XAXIS ) ||
  885. ( eventDescriptor.eventCode == SI_YAXIS ) ||
  886. ( eventDescriptor.eventCode == SI_ZAXIS ) ||
  887. ( eventDescriptor.eventCode == SI_RXAXIS ) ||
  888. ( eventDescriptor.eventCode == SI_RYAXIS ) ||
  889. ( eventDescriptor.eventCode == SI_RZAXIS ) ||
  890. ( eventDescriptor.eventCode == SI_SLIDER ) ||
  891. ( eventDescriptor.eventCode == SI_XPOV ) ||
  892. ( eventDescriptor.eventCode == SI_YPOV ) ||
  893. ( eventDescriptor.eventCode == SI_XPOV2 ) ||
  894. ( eventDescriptor.eventCode == SI_YPOV2 ) ||
  895. ( eventDescriptor.eventCode == SI_ACCELX ) ||
  896. ( eventDescriptor.eventCode == SI_ACCELY ) ||
  897. ( eventDescriptor.eventCode == SI_ACCELZ ) ||
  898. ( eventDescriptor.eventCode == SI_GRAVX ) ||
  899. ( eventDescriptor.eventCode == SI_GRAVY ) ||
  900. ( eventDescriptor.eventCode == SI_GRAVZ ) ||
  901. ( eventDescriptor.eventCode == SI_GYROX ) ||
  902. ( eventDescriptor.eventCode == SI_GYROY ) ||
  903. ( eventDescriptor.eventCode == SI_GYROZ ) ||
  904. ( eventDescriptor.eventCode == SI_YAW ) ||
  905. ( eventDescriptor.eventCode == SI_PITCH ) ||
  906. ( eventDescriptor.eventCode == SI_ROLL ) )
  907. {
  908. Con::warnf( "ActionMap::processBindCmd - Cannot use 'bindCmd' with a move event type. Use 'bind' instead." );
  909. return false;
  910. }
  911. // Create the full bind entry, and place it in the map
  912. //
  913. // DMMTODO
  914. Node* pBindNode = getNode(deviceType, deviceInst,
  915. eventDescriptor.flags,
  916. eventDescriptor.eventCode);
  917. pBindNode->flags = Node::BindCmd;
  918. pBindNode->deadZoneBegin = 0;
  919. pBindNode->deadZoneEnd = 0;
  920. pBindNode->scaleFactor = 1;
  921. if(makeCmd[0])
  922. pBindNode->makeConsoleCommand = dStrdup(makeCmd);
  923. else
  924. pBindNode->makeConsoleCommand = dStrdup("");
  925. if(breakCmd[0])
  926. pBindNode->breakConsoleCommand = dStrdup(breakCmd);
  927. else
  928. pBindNode->breakConsoleCommand = dStrdup("");
  929. return true;
  930. }
  931. //------------------------------------------------------------------------------
  932. bool ActionMap::processBind(const U32 argc, const char** argv, SimObject* object)
  933. {
  934. // Ok, the bind will come in the following format:
  935. // [device] [key or button] <[param spec] [param] ...> [fnName]
  936. //
  937. const char* pDeviceName = argv[0];
  938. const char* pEvent = argv[1];
  939. const char* pFnName = argv[argc - 1];
  940. // Determine the device
  941. U32 deviceType;
  942. U32 deviceInst;
  943. if(!getDeviceTypeAndInstance(argv[0], deviceType, deviceInst))
  944. {
  945. Con::printf("processBind: unknown device: %s", pDeviceName);
  946. return false;
  947. }
  948. // Ok, we now have the deviceType and instance. Create an event descriptor
  949. // for the bind...
  950. //
  951. EventDescriptor eventDescriptor;
  952. if (createEventDescriptor(pEvent, &eventDescriptor) == false) {
  953. Con::printf("Could not create a description for binding: %s", pEvent);
  954. return false;
  955. }
  956. // Event has now been described, and device determined. we need now to extract
  957. // any modifiers that the action map will apply to incoming events before
  958. // calling the bound function...
  959. //
  960. // DMMTODO
  961. U32 assignedFlags = 0;
  962. F32 deadZoneBegin = 0.0f;
  963. F32 deadZoneEnd = 0.0f;
  964. F32 scaleFactor = 1.0f;
  965. if (argc != 3) {
  966. // We have the following: "[DSIR]" [deadZone] [scale]
  967. //
  968. const char* pSpec = argv[2];
  969. for (U32 i = 0; pSpec[i] != '\0'; i++) {
  970. switch (pSpec[i]) {
  971. case 'r': case 'R':
  972. assignedFlags |= Node::HasScale;
  973. break;
  974. case 's': case 'S':
  975. assignedFlags |= Node::HasScale;
  976. break;
  977. case 'd': case 'D':
  978. assignedFlags |= Node::HasDeadZone;
  979. break;
  980. case 'i': case 'I':
  981. assignedFlags |= Node::Inverted;
  982. break;
  983. case 'n': case 'N':
  984. assignedFlags |= Node::NonLinear;
  985. break;
  986. default:
  987. AssertFatal(false, avar("Misunderstood specifier in bind (spec string: %s)",
  988. pSpec));
  989. }
  990. }
  991. // Ok, we have the flags. Scan the dead zone and scale, if any.
  992. //
  993. U32 curArg = 3;
  994. if (assignedFlags & Node::HasDeadZone) {
  995. dSscanf(argv[curArg], "%g %g", &deadZoneBegin, &deadZoneEnd);
  996. curArg++;
  997. }
  998. if (assignedFlags & Node::HasScale) {
  999. scaleFactor = dAtof(argv[curArg]);
  1000. curArg++;
  1001. }
  1002. if (curArg != (argc - 1)) {
  1003. AssertFatal(curArg == (argc - 1), "error in bind spec somewhere...");
  1004. Con::printf("Improperly specified bind for key: %s", argv[2]);
  1005. return false;
  1006. }
  1007. }
  1008. // Ensure that the console function is properly specified?
  1009. //
  1010. // DMMTODO
  1011. // Create the full bind entry, and place it in the map
  1012. //
  1013. // DMMTODO
  1014. Node* pBindNode = getNode(deviceType, deviceInst,
  1015. eventDescriptor.flags,
  1016. eventDescriptor.eventCode, object);
  1017. pBindNode->flags = assignedFlags;
  1018. pBindNode->deadZoneBegin = deadZoneBegin;
  1019. pBindNode->deadZoneEnd = deadZoneEnd;
  1020. pBindNode->scaleFactor = scaleFactor;
  1021. pBindNode->object = object;
  1022. pBindNode->consoleFunction = StringTable->insert(pFnName);
  1023. return true;
  1024. }
  1025. //------------------------------------------------------------------------------
  1026. bool ActionMap::processLeap(const InputEvent* pEvent)
  1027. {
  1028. static const char *argv[5];
  1029. char buffer[64];
  1030. const Node* pNode = findNode( pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objType );
  1031. if (pNode == NULL)
  1032. {
  1033. // Check to see if we clear the modifiers, do we find an action?
  1034. if (pEvent->modifier != 0)
  1035. pNode = findNode(pEvent->deviceType, pEvent->deviceInst, 0, pEvent->objInst);
  1036. if (pNode == NULL)
  1037. return false;
  1038. }
  1039. // "Do nothing" bind:
  1040. if ( !pNode->consoleFunction[0] )
  1041. return( true );
  1042. argv[0] = pNode->consoleFunction;
  1043. float values[3];
  1044. values[0] = pEvent->fValues[0];
  1045. values[1] = pEvent->fValues[1];
  1046. values[2] = pEvent->fValues[2];
  1047. if ( pNode->flags & Node::HasDeadZone )
  1048. {
  1049. if ( pEvent->fValues[0] >= pNode->deadZoneBegin && pEvent->fValues[0] <= pNode->deadZoneEnd )
  1050. values[0] = 0.0f;
  1051. if ( pEvent->fValues[1] >= pNode->deadZoneBegin && pEvent->fValues[1] <= pNode->deadZoneEnd )
  1052. values[1] = 0.0f;
  1053. if ( pEvent->fValues[2] >= pNode->deadZoneBegin && pEvent->fValues[2] <= pNode->deadZoneEnd )
  1054. values[2] = 0.0f;
  1055. // All values are all null, so don't bother executing the function
  1056. if (!values[0] && !values[1] && !values[2])
  1057. return true;
  1058. }
  1059. switch(pEvent->objType)
  1060. {
  1061. case LM_HANDPOS:
  1062. // ID
  1063. argv[1] = Con::getIntArg(pEvent->iValue);
  1064. // Position
  1065. dSprintf(buffer, sizeof(buffer), "%f %f %f", values[0], values[1], values[2]);
  1066. argv[2] = buffer;
  1067. if (pNode->object)
  1068. Con::executef(pNode->object, 3, argv[0], argv[1], argv[2]);
  1069. else
  1070. Con::execute(3, argv);
  1071. break;
  1072. case LM_HANDROT:
  1073. // ID
  1074. argv[1] = Con::getIntArg(pEvent->iValue);
  1075. // Rotation
  1076. dSprintf(buffer, sizeof(buffer), "%f %f %f", values[0], values[1], values[2]);
  1077. argv[2] = buffer;
  1078. if (pNode->object)
  1079. Con::executef(pNode->object, 3, argv[0], argv[1], argv[2]);
  1080. else
  1081. Con::execute(3, argv);
  1082. break;
  1083. case LM_FINGERPOS:
  1084. // IDs
  1085. argv[1] = pEvent->fingerIDs;
  1086. // X-coordinates
  1087. argv[2] = pEvent->fingersX;
  1088. // Y-coordinates
  1089. argv[3] = pEvent->fingersY;
  1090. // Z-coordinates
  1091. argv[4] = pEvent->fingersZ;
  1092. if (pNode->object)
  1093. Con::executef(pNode->object, 5, argv[0], argv[1], argv[2], argv[3], argv[4]);
  1094. else
  1095. Con::execute(5, argv);
  1096. break;
  1097. case LM_HANDAXIS:
  1098. default:
  1099. return false;
  1100. }
  1101. return true;
  1102. }
  1103. //------------------------------------------------------------------------------
  1104. bool ActionMap::processGesture(const InputEvent* pEvent)
  1105. {
  1106. static const char *argv[6];
  1107. char buffer[64];
  1108. const Node* pNode = findNode( pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objType );
  1109. if (pNode == NULL)
  1110. {
  1111. // Check to see if we clear the modifiers, do we find an action?
  1112. if (pEvent->modifier != 0)
  1113. pNode = findNode(pEvent->deviceType, pEvent->deviceInst, 0, pEvent->objInst);
  1114. if (pNode == NULL)
  1115. return false;
  1116. }
  1117. // "Do nothing" bind:
  1118. if ( !pNode->consoleFunction[0] )
  1119. return( true );
  1120. // Function
  1121. argv[0] = pNode->consoleFunction;
  1122. switch(pEvent->objType)
  1123. {
  1124. case SI_CIRCLE_GESTURE:
  1125. // ID
  1126. argv[1] = Con::getIntArg(pEvent->iValue);
  1127. // Progress
  1128. argv[2] = Con::getFloatArg(pEvent->fValues[0]);
  1129. // Radius
  1130. argv[3] = Con::getFloatArg(pEvent->fValues[1]);
  1131. // Direction (1 clockwise, 0 counter-clockwise)
  1132. argv[4] = Con::getFloatArg(pEvent->fValues[2]);
  1133. // State
  1134. argv[5] = Con::getFloatArg(pEvent->fValues[3]);
  1135. if (pNode->object)
  1136. Con::executef(pNode->object, 6, argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
  1137. else
  1138. Con::execute(6, argv);
  1139. break;
  1140. case SI_SWIPE_GESTURE:
  1141. // ID
  1142. argv[1] = Con::getIntArg(pEvent->iValue);
  1143. // State
  1144. argv[2] = Con::getFloatArg(pEvent->fValues[0]);
  1145. // Direction
  1146. dSprintf(buffer, sizeof(buffer), "%f %f %f", pEvent->fValues[1], pEvent->fValues[2], pEvent->fValues[3]);
  1147. argv[3] = buffer;
  1148. // Speed
  1149. argv[4] = Con::getFloatArg(pEvent->fValues[4]);
  1150. if (pNode->object)
  1151. Con::executef(pNode->object, 5, argv[0], argv[1], argv[2], argv[3], argv[4]);
  1152. else
  1153. Con::execute(5, argv);
  1154. break;
  1155. case SI_KEYTAP_GESTURE:
  1156. case SI_SCREENTAP_GESTURE:
  1157. // ID
  1158. argv[1] = Con::getIntArg(pEvent->iValue);
  1159. // Position
  1160. dSprintf(buffer, sizeof(buffer), "%f %f %f", pEvent->fValues[0], pEvent->fValues[1], pEvent->fValues[2]);
  1161. argv[2] = buffer;
  1162. // Direction
  1163. dSprintf(buffer, sizeof(buffer), "%f %f %f", pEvent->fValues[3], pEvent->fValues[4], pEvent->fValues[5]);
  1164. argv[3] = buffer;
  1165. if (pNode->object)
  1166. Con::executef(pNode->object, 4, argv[0], argv[1], argv[2], argv[3]);
  1167. else
  1168. Con::execute(5, argv);
  1169. break;
  1170. case SI_PINCH_GESTURE:
  1171. case SI_SCALE_GESTURE:
  1172. default:
  1173. return true;
  1174. }
  1175. return true;
  1176. }
  1177. //------------------------------------------------------------------------------
  1178. bool ActionMap::processTouch(const InputEvent* pEvent)
  1179. {
  1180. static const char *argv[4];
  1181. const Node* pNode = findNode(pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objInst);
  1182. if (pNode == NULL)
  1183. {
  1184. // Check to see if we clear the modifiers, do we find an action?
  1185. if (pEvent->modifier != 0)
  1186. pNode = findNode(pEvent->deviceType, pEvent->deviceInst, 0, pEvent->objInst);
  1187. if (pNode == NULL)
  1188. return false;
  1189. }
  1190. // "Do nothing" bind:
  1191. if ( !pNode->consoleFunction[0] )
  1192. return( true );
  1193. // Ok, we're all set up, call the function.
  1194. argv[0] = pNode->consoleFunction;
  1195. argv[1] = pEvent->fingerIDs;
  1196. argv[2] = pEvent->fingersX;
  1197. argv[3] = pEvent->fingersY;
  1198. if (pNode->object)
  1199. Con::executef(pNode->object, 4, argv[0], argv[1], argv[2], argv[3]);
  1200. else
  1201. Con::execute(4, argv);
  1202. return true;
  1203. }
  1204. //------------------------------------------------------------------------------
  1205. bool ActionMap::processButton(const InputEvent* pEvent)
  1206. {
  1207. static const char *argv[2];
  1208. const Node* pNode = findNode(pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objInst);
  1209. if (pNode == NULL)
  1210. {
  1211. // Check to see if we clear the modifiers, do we find an action?
  1212. if (pEvent->modifier != 0)
  1213. pNode = findNode(pEvent->deviceType, pEvent->deviceInst, 0, pEvent->objInst);
  1214. if (pNode == NULL)
  1215. return false;
  1216. }
  1217. // Whadda ya know, we have this bound. Set up, and call the console
  1218. // function associated with it...
  1219. //
  1220. F32 value = pEvent->fValues[0];
  1221. if (pNode->flags & Node::Ranged)
  1222. {
  1223. value = (value * 2.0f) - 1.0f;
  1224. if (pNode->flags & Node::Inverted)
  1225. value *= -1.0f;
  1226. }
  1227. else
  1228. {
  1229. if (pNode->flags & Node::Inverted)
  1230. value = 1.0f - value;
  1231. }
  1232. if (pNode->flags & Node::HasScale)
  1233. value *= pNode->scaleFactor;
  1234. if (pNode->flags & Node::HasDeadZone)
  1235. {
  1236. if (value >= pNode->deadZoneBegin && value <= pNode->deadZoneEnd)
  1237. value = 0.0f;
  1238. else
  1239. {
  1240. if( value > 0 )
  1241. value = ( value - pNode->deadZoneBegin ) * ( 1.f / ( 1.f - pNode->deadZoneBegin ) );
  1242. else
  1243. value = ( value + pNode->deadZoneBegin ) * ( 1.f / ( 1.f - pNode->deadZoneBegin ) );
  1244. }
  1245. }
  1246. if( pNode->flags & Node::NonLinear )
  1247. value = ( value < 0.f ? -1.f : 1.f ) * mPow( mFabs( value ), CONST_E );
  1248. // Ok, we're all set up, call the function.
  1249. if(pNode->flags & Node::BindCmd)
  1250. {
  1251. // it's a bind command
  1252. if(pNode->makeConsoleCommand)
  1253. Con::evaluate(pNode->makeConsoleCommand);
  1254. }
  1255. else if ( pNode->consoleFunction[0] )
  1256. {
  1257. argv[0] = pNode->consoleFunction;
  1258. argv[1] = Con::getFloatArg(value);
  1259. if (pNode->object)
  1260. Con::executef(pNode->object, 2, argv[0], argv[1]);
  1261. else
  1262. Con::execute(2, argv);
  1263. }
  1264. // [neo, 5/13/2007 - #3109]
  1265. // The execs/evaluate above could have called reentrant script code which made calls to
  1266. // bindCmd() etc, channging the node map underneath us. If enough nodes were added then
  1267. // the node map vector would realloc, with the result that pNode would then be pointing
  1268. // at garbage and cause a crash when passed to enterBreakEvent() below. So we just look
  1269. // it up again to be safe. This is not needed in the other cases below as we return right
  1270. // after the execs and don't use pNode again.
  1271. pNode = findNode( pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objInst );
  1272. if( pNode == NULL )
  1273. return true; // We already called any bound methods/functions so our job is done
  1274. //
  1275. // And enter the break into the table if this is a make event...
  1276. enterBreakEvent(pEvent, pNode);
  1277. return true;
  1278. }
  1279. //------------------------------------------------------------------------------
  1280. bool ActionMap::processMove(const InputEvent* pEvent)
  1281. {
  1282. static const char *argv[4];
  1283. if (pEvent->deviceType == MouseDeviceType)
  1284. {
  1285. const Node* pNode = findNode(pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objType);
  1286. if (pNode == NULL)
  1287. {
  1288. // Check to see if we clear the modifiers, do we find an action?
  1289. if (pEvent->modifier != 0)
  1290. pNode = findNode(pEvent->deviceType, pEvent->deviceInst, 0, pEvent->objType);
  1291. if (pNode == NULL)
  1292. return false;
  1293. }
  1294. // "Do nothing" bind:
  1295. if ( !pNode->consoleFunction[0] )
  1296. return( true );
  1297. // Whadda ya know, we have this bound. Set up, and call the console
  1298. // function associated with it. Mouse events ignore range and dead
  1299. // zone params.
  1300. //
  1301. F32 value = pEvent->fValues[0];
  1302. if (pNode->flags & Node::Inverted)
  1303. value *= -1.0f;
  1304. if (pNode->flags & Node::HasScale)
  1305. value *= pNode->scaleFactor;
  1306. // Ok, we're all set up, call the function.
  1307. argv[0] = pNode->consoleFunction;
  1308. argv[1] = Con::getFloatArg(value);
  1309. if (pNode->object)
  1310. Con::executef(pNode->object, 2, argv[0], argv[1]);
  1311. else
  1312. Con::execute(2, argv);
  1313. return true;
  1314. }
  1315. else if ( (pEvent->objType == XI_POS || pEvent->objType == XI_FLOAT || pEvent->objType == XI_ROT || pEvent->objType == XI_INT) )
  1316. {
  1317. const Node* pNode = findNode(pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objInst);
  1318. if( pNode == NULL )
  1319. return false;
  1320. // Ok, we're all set up, call the function.
  1321. argv[0] = pNode->consoleFunction;
  1322. S32 argc = 1;
  1323. if (pEvent->objType == XI_INT)
  1324. {
  1325. // Handle the integer as some sort of motion such as a
  1326. // single component to an absolute position
  1327. argv[1] = Con::getIntArg( pEvent->iValue );
  1328. argc += 1;
  1329. }
  1330. else if (pEvent->objType == XI_FLOAT)
  1331. {
  1332. // Handle float as some sort of motion such as a
  1333. // single component to an absolute position
  1334. argv[1] = Con::getFloatArg( pEvent->fValues[0] );
  1335. argc += 1;
  1336. }
  1337. else if (pEvent->objType == XI_POS)
  1338. {
  1339. // Handle Point3F type position
  1340. argv[1] = Con::getFloatArg( pEvent->fValues[0] );
  1341. argv[2] = Con::getFloatArg( pEvent->fValues[1] );
  1342. argv[3] = Con::getFloatArg( pEvent->fValues[2] );
  1343. argc += 3;
  1344. }
  1345. if (pNode->object)
  1346. {
  1347. Con::execute(pNode->object, argc, argv);
  1348. }
  1349. else
  1350. {
  1351. Con::execute(argc, argv);
  1352. }
  1353. return true;
  1354. }
  1355. else if ( pEvent->deviceType == JoystickDeviceType || pEvent->deviceType == GamepadDeviceType )
  1356. {
  1357. // Joystick events...
  1358. const Node* pNode = findNode( pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objInst );
  1359. if( pNode == NULL )
  1360. return false;
  1361. // "Do nothing" bind:
  1362. if ( !pNode->consoleFunction[0] )
  1363. return( true );
  1364. // Whadda ya know, we have this bound. Set up, and call the console
  1365. // function associated with it. Joystick move events are the same as mouse
  1366. // move events except that they don't ignore dead zone.
  1367. //
  1368. F32 value = pEvent->fValues[0];
  1369. if ( pNode->flags & Node::Inverted )
  1370. value *= -1.0f;
  1371. if ( pNode->flags & Node::HasScale )
  1372. value *= pNode->scaleFactor;
  1373. if ( pNode->flags & Node::HasDeadZone )
  1374. {
  1375. if ( value >= pNode->deadZoneBegin && value <= pNode->deadZoneEnd )
  1376. {
  1377. value = 0.0f;
  1378. }
  1379. else
  1380. {
  1381. if( value > 0 )
  1382. value = ( value - pNode->deadZoneBegin ) * ( 1.f / ( 1.f - pNode->deadZoneBegin ) );
  1383. else
  1384. value = ( value + pNode->deadZoneBegin ) * ( 1.f / ( 1.f - pNode->deadZoneBegin ) );
  1385. }
  1386. }
  1387. if( pNode->flags & Node::NonLinear )
  1388. value = ( value < 0.f ? -1.f : 1.f ) * mPow( mFabs( value ), CONST_E );
  1389. // Ok, we're all set up, call the function.
  1390. argv[0] = pNode->consoleFunction;
  1391. argv[1] = Con::getFloatArg( value );
  1392. if (pNode->object)
  1393. Con::executef(pNode->object, 2, argv[0], argv[1]);
  1394. else
  1395. Con::execute(2, argv);
  1396. return true;
  1397. }
  1398. return false;
  1399. }
  1400. //------------------------------------------------------------------------------
  1401. bool ActionMap::processMotion(const InputEvent* pEvent)
  1402. {
  1403. static const char *argv[2];
  1404. // iOS Accelerometer, Gyroscope and DeviceMotion processing
  1405. // Currently, this is identical to the joystick handling.
  1406. // This was copied over into its own section because this will
  1407. // give us a dedicated section to tweak processing based on iOS specific
  1408. // devices. No point in trying to mangle joystick code any further
  1409. const Node* pNode = findNode( pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objType );
  1410. if ( pNode == NULL )
  1411. {
  1412. // Check to see if we clear the modifiers, do we find an action?
  1413. if (pEvent->modifier != 0)
  1414. pNode = findNode( pEvent->deviceType, pEvent->deviceInst, 0, pEvent->objType );
  1415. if ( pNode == NULL )
  1416. return false;
  1417. }
  1418. // "Do nothing" bind:
  1419. if ( !pNode->consoleFunction[0] )
  1420. return( true );
  1421. F32 value = pEvent->fValues[0];
  1422. if ( pNode->flags & Node::Inverted )
  1423. value *= -1.0f;
  1424. if ( pNode->flags & Node::HasScale )
  1425. value *= pNode->scaleFactor;
  1426. if ( pNode->flags & Node::HasDeadZone )
  1427. {
  1428. if ( value >= pNode->deadZoneBegin && value <= pNode->deadZoneEnd )
  1429. value = 0.0f;
  1430. }
  1431. // Ok, we're all set up, call the function.
  1432. argv[0] = pNode->consoleFunction;
  1433. argv[1] = Con::getFloatArg( value );
  1434. if (pNode->object)
  1435. Con::executef(pNode->object, 2, argv[0], argv[1]);
  1436. else
  1437. Con::execute(2, argv);
  1438. return true;
  1439. }
  1440. //------------------------------------------------------------------------------
  1441. bool ActionMap::processXInput(const InputEvent* pEvent)
  1442. {
  1443. static const char *argv[2];
  1444. if ((pEvent->objType == XI_FLOAT || pEvent->objType == XI_INT))
  1445. {
  1446. const Node* pNode = findNode( pEvent->deviceType, pEvent->deviceInst, pEvent->modifier, pEvent->objType );
  1447. if (pNode == NULL )
  1448. return false;
  1449. // Ok, we're all set up, call the function.
  1450. argv[0] = pNode->consoleFunction;
  1451. S32 argc = 1;
  1452. if (pEvent->objType == XI_INT)
  1453. {
  1454. // Handle the integer as some sort of motion such as a
  1455. // single component to an absolute position
  1456. argv[1] = Con::getIntArg( pEvent->iValue );
  1457. argc += 1;
  1458. }
  1459. else if (pEvent->objType == XI_FLOAT)
  1460. {
  1461. // Handle float as some sort of motion such as a
  1462. // single component to an absolute position
  1463. argv[1] = Con::getFloatArg( pEvent->fValues[0] );
  1464. argc += 1;
  1465. }
  1466. if (pNode->object)
  1467. {
  1468. Con::execute(pNode->object, argc, argv);
  1469. }
  1470. else
  1471. {
  1472. Con::execute(argc, argv);
  1473. }
  1474. }
  1475. return true;
  1476. }
  1477. //------------------------------------------------------------------------------
  1478. bool ActionMap::processAction(const InputEvent* pEvent)
  1479. {
  1480. switch(pEvent->action)
  1481. {
  1482. case SI_LEAP:
  1483. return processLeap(pEvent);
  1484. break;
  1485. case SI_GESTURE:
  1486. return processGesture(pEvent);
  1487. break;
  1488. case SI_TOUCH:
  1489. return processTouch(pEvent);
  1490. break;
  1491. case SI_MAKE:
  1492. return processButton(pEvent);
  1493. break;
  1494. case SI_MOVE:
  1495. return processMove(pEvent);
  1496. break;
  1497. case SI_MOTION:
  1498. return processMotion(pEvent);
  1499. break;
  1500. case SI_BREAK:
  1501. return checkBreakTable(pEvent);
  1502. break;
  1503. case SI_VALUE:
  1504. return processXInput(pEvent);
  1505. }
  1506. return false;
  1507. }
  1508. //------------------------------------------------------------------------------
  1509. void ActionMap::enterBreakEvent(const InputEvent* pEvent, const Node* pNode)
  1510. {
  1511. // There aren't likely to be many breaks outstanding at any one given time,
  1512. // so a simple linear search is probably sufficient. Note that the break table
  1513. // is static to the class, all breaks are directed to the action map that received
  1514. // the make.
  1515. //
  1516. S32 entry = -1;
  1517. for (U32 i = 0; i < (U32)smBreakTable.size(); i++) {
  1518. if (smBreakTable[i].deviceType == U32(pEvent->deviceType) &&
  1519. smBreakTable[i].deviceInst == U32(pEvent->deviceInst) &&
  1520. smBreakTable[i].objInst == U32(pEvent->objInst)) {
  1521. // Match.
  1522. entry = i;
  1523. break;
  1524. }
  1525. }
  1526. if (entry == -1) {
  1527. smBreakTable.increment();
  1528. entry = smBreakTable.size() - 1;
  1529. smBreakTable[entry].deviceType = pEvent->deviceType;
  1530. smBreakTable[entry].deviceInst = pEvent->deviceInst;
  1531. smBreakTable[entry].objInst = pEvent->objInst;
  1532. }
  1533. // Ok, we now have the entry, and know that the device desc. and the objInst match.
  1534. // Copy out the node information...
  1535. //
  1536. smBreakTable[entry].object = pNode->object;
  1537. // [neo, 5/7/2007 - #2975]
  1538. // object above can be deleted in between a make/break and so object will point
  1539. // to turfed memory and crash. To keep things simple we just store id as well so
  1540. // we can look it up to validate object ref.
  1541. smBreakTable[entry].objectId = pNode->object ? pNode->object->getId() : 0;
  1542. smBreakTable[entry].consoleFunction = pNode->consoleFunction;
  1543. if(pNode->breakConsoleCommand)
  1544. smBreakTable[entry].breakConsoleCommand = dStrdup(pNode->breakConsoleCommand);
  1545. else
  1546. smBreakTable[entry].breakConsoleCommand = NULL;
  1547. smBreakTable[entry].flags = pNode->flags;
  1548. smBreakTable[entry].deadZoneBegin = pNode->deadZoneBegin;
  1549. smBreakTable[entry].deadZoneEnd = pNode->deadZoneEnd;
  1550. smBreakTable[entry].scaleFactor = pNode->scaleFactor;
  1551. }
  1552. //------------------------------------------------------------------------------
  1553. bool ActionMap::checkBreakTable(const InputEvent* pEvent)
  1554. {
  1555. for (U32 i = 0; i < (U32)smBreakTable.size(); i++) {
  1556. if (smBreakTable[i].deviceType == U32(pEvent->deviceType) &&
  1557. smBreakTable[i].deviceInst == U32(pEvent->deviceInst) &&
  1558. smBreakTable[i].objInst == U32(pEvent->objInst)) {
  1559. // Match. Issue the break event...
  1560. //
  1561. F32 value = pEvent->fValues[0];
  1562. if (smBreakTable[i].flags & Node::Ranged) {
  1563. value = (value * 2.0f) - 1.0f;
  1564. if (smBreakTable[i].flags & Node::Inverted)
  1565. value *= -1.0f;
  1566. } else {
  1567. if (smBreakTable[i].flags & Node::Inverted)
  1568. value = 1.0f - value;
  1569. }
  1570. if (smBreakTable[i].flags & Node::HasScale)
  1571. value *= smBreakTable[i].scaleFactor;
  1572. if (smBreakTable[i].flags & Node::HasDeadZone)
  1573. if (value >= smBreakTable[i].deadZoneBegin &&
  1574. value <= smBreakTable[i].deadZoneEnd)
  1575. value = 0.0f;
  1576. // Ok, we're all set up, call the function.
  1577. if(smBreakTable[i].consoleFunction)
  1578. {
  1579. if ( smBreakTable[i].consoleFunction[0] )
  1580. {
  1581. static const char *argv[2];
  1582. argv[0] = smBreakTable[i].consoleFunction;
  1583. argv[1] = Con::getFloatArg(value);
  1584. if( smBreakTable[i].object )
  1585. {
  1586. // [neo, 5/7/2007 - #2975]
  1587. // object above can be deleted in between a make/break and so object will point
  1588. // to turfed memory and crash. To keep things simple we just store id as well so
  1589. // we can look it up to validate object ref.
  1590. if( smBreakTable[i].objectId > 0 && Sim::findObject( smBreakTable[i].objectId ) )
  1591. Con::executef(smBreakTable[i].object, 2, argv[0], argv[1]);
  1592. }
  1593. else
  1594. Con::execute(2, argv);
  1595. }
  1596. }
  1597. else if(smBreakTable[i].breakConsoleCommand)
  1598. {
  1599. Con::evaluate(smBreakTable[i].breakConsoleCommand);
  1600. dFree(smBreakTable[i].breakConsoleCommand);
  1601. }
  1602. smBreakTable.erase(i);
  1603. return true;
  1604. }
  1605. }
  1606. return false;
  1607. }
  1608. //------------------------------------------------------------------------------
  1609. bool ActionMap::handleEvent(const InputEvent* pEvent)
  1610. {
  1611. // Interate through the ActionMapSet until we get a map that
  1612. // handles the event or we run out of maps...
  1613. //
  1614. SimSet* pActionMapSet = Sim::getActiveActionMapSet();
  1615. AssertFatal(pActionMapSet && pActionMapSet->size() != 0,
  1616. "error, no ActiveMapSet or no global action map...");
  1617. for (SimSet::iterator itr = pActionMapSet->end() - 1;
  1618. itr > pActionMapSet->begin(); itr--) {
  1619. ActionMap* pMap = static_cast<ActionMap*>(*itr);
  1620. if (pMap->processAction(pEvent) == true)
  1621. return true;
  1622. }
  1623. return false;
  1624. }
  1625. //------------------------------------------------------------------------------
  1626. bool ActionMap::handleEventGlobal(const InputEvent* pEvent)
  1627. {
  1628. // Interate through the ActionMapSet until we get a map that
  1629. // handles the event or we run out of maps...
  1630. //
  1631. SimSet* pActionMapSet = Sim::getActiveActionMapSet();
  1632. AssertFatal(pActionMapSet && pActionMapSet->size() != 0,
  1633. "error, no ActiveMapSet or no global action map...");
  1634. return ((ActionMap*)pActionMapSet->first())->processAction(pEvent);
  1635. }
  1636. //------------------------------------------------------------------------------
  1637. //-------------------------------------- Key code to string mapping
  1638. // TODO: Add most obvious aliases...
  1639. //
  1640. CodeMapping gVirtualMap[] =
  1641. {
  1642. //-------------------------------------- KEYBOARD EVENTS
  1643. //
  1644. { "backspace", SI_KEY, KEY_BACKSPACE },
  1645. { "tab", SI_KEY, KEY_TAB },
  1646. { "return", SI_KEY, KEY_RETURN },
  1647. { "enter", SI_KEY, KEY_RETURN },
  1648. { "shift", SI_KEY, KEY_SHIFT },
  1649. { "ctrl", SI_KEY, KEY_CONTROL },
  1650. { "alt", SI_KEY, KEY_ALT },
  1651. { "pause", SI_KEY, KEY_PAUSE },
  1652. { "capslock", SI_KEY, KEY_CAPSLOCK },
  1653. { "escape", SI_KEY, KEY_ESCAPE },
  1654. { "space", SI_KEY, KEY_SPACE },
  1655. { "pagedown", SI_KEY, KEY_PAGE_DOWN },
  1656. { "pageup", SI_KEY, KEY_PAGE_UP },
  1657. { "end", SI_KEY, KEY_END },
  1658. { "home", SI_KEY, KEY_HOME },
  1659. { "left", SI_KEY, KEY_LEFT },
  1660. { "up", SI_KEY, KEY_UP },
  1661. { "right", SI_KEY, KEY_RIGHT },
  1662. { "down", SI_KEY, KEY_DOWN },
  1663. { "print", SI_KEY, KEY_PRINT },
  1664. { "insert", SI_KEY, KEY_INSERT },
  1665. { "delete", SI_KEY, KEY_DELETE },
  1666. { "help", SI_KEY, KEY_HELP },
  1667. { "win_lwindow", SI_KEY, KEY_WIN_LWINDOW },
  1668. { "win_rwindow", SI_KEY, KEY_WIN_RWINDOW },
  1669. { "win_apps", SI_KEY, KEY_WIN_APPS },
  1670. { "cmd", SI_KEY, KEY_ALT },
  1671. { "opt", SI_KEY, KEY_MAC_OPT },
  1672. { "lopt", SI_KEY, KEY_MAC_LOPT },
  1673. { "ropt", SI_KEY, KEY_MAC_ROPT },
  1674. { "numpad0", SI_KEY, KEY_NUMPAD0 },
  1675. { "numpad1", SI_KEY, KEY_NUMPAD1 },
  1676. { "numpad2", SI_KEY, KEY_NUMPAD2 },
  1677. { "numpad3", SI_KEY, KEY_NUMPAD3 },
  1678. { "numpad4", SI_KEY, KEY_NUMPAD4 },
  1679. { "numpad5", SI_KEY, KEY_NUMPAD5 },
  1680. { "numpad6", SI_KEY, KEY_NUMPAD6 },
  1681. { "numpad7", SI_KEY, KEY_NUMPAD7 },
  1682. { "numpad8", SI_KEY, KEY_NUMPAD8 },
  1683. { "numpad9", SI_KEY, KEY_NUMPAD9 },
  1684. { "numpadmult", SI_KEY, KEY_MULTIPLY },
  1685. { "numpadadd", SI_KEY, KEY_ADD },
  1686. { "numpadsep", SI_KEY, KEY_SEPARATOR },
  1687. { "numpadminus", SI_KEY, KEY_SUBTRACT },
  1688. { "numpaddecimal", SI_KEY, KEY_DECIMAL },
  1689. { "numpaddivide", SI_KEY, KEY_DIVIDE },
  1690. { "numpadenter", SI_KEY, KEY_NUMPADENTER },
  1691. { "f1", SI_KEY, KEY_F1 },
  1692. { "f2", SI_KEY, KEY_F2 },
  1693. { "f3", SI_KEY, KEY_F3 },
  1694. { "f4", SI_KEY, KEY_F4 },
  1695. { "f5", SI_KEY, KEY_F5 },
  1696. { "f6", SI_KEY, KEY_F6 },
  1697. { "f7", SI_KEY, KEY_F7 },
  1698. { "f8", SI_KEY, KEY_F8 },
  1699. { "f9", SI_KEY, KEY_F9 },
  1700. { "f10", SI_KEY, KEY_F10 },
  1701. { "f11", SI_KEY, KEY_F11 },
  1702. { "f12", SI_KEY, KEY_F12 },
  1703. { "f13", SI_KEY, KEY_F13 },
  1704. { "f14", SI_KEY, KEY_F14 },
  1705. { "f15", SI_KEY, KEY_F15 },
  1706. { "f16", SI_KEY, KEY_F16 },
  1707. { "f17", SI_KEY, KEY_F17 },
  1708. { "f18", SI_KEY, KEY_F18 },
  1709. { "f19", SI_KEY, KEY_F19 },
  1710. { "f20", SI_KEY, KEY_F20 },
  1711. { "f21", SI_KEY, KEY_F21 },
  1712. { "f22", SI_KEY, KEY_F22 },
  1713. { "f23", SI_KEY, KEY_F23 },
  1714. { "f24", SI_KEY, KEY_F24 },
  1715. { "numlock", SI_KEY, KEY_NUMLOCK },
  1716. { "scrolllock", SI_KEY, KEY_SCROLLLOCK },
  1717. { "lshift", SI_KEY, KEY_LSHIFT },
  1718. { "rshift", SI_KEY, KEY_RSHIFT },
  1719. { "lcontrol", SI_KEY, KEY_LCONTROL },
  1720. { "rcontrol", SI_KEY, KEY_RCONTROL },
  1721. { "lalt", SI_KEY, KEY_LALT },
  1722. { "ralt", SI_KEY, KEY_RALT },
  1723. { "tilde", SI_KEY, KEY_TILDE },
  1724. { "minus", SI_KEY, KEY_MINUS },
  1725. { "equals", SI_KEY, KEY_EQUALS },
  1726. { "lbracket", SI_KEY, KEY_LBRACKET },
  1727. { "rbracket", SI_KEY, KEY_RBRACKET },
  1728. { "backslash", SI_KEY, KEY_BACKSLASH },
  1729. { "semicolon", SI_KEY, KEY_SEMICOLON },
  1730. { "apostrophe", SI_KEY, KEY_APOSTROPHE },
  1731. { "comma", SI_KEY, KEY_COMMA },
  1732. { "period", SI_KEY, KEY_PERIOD },
  1733. { "slash", SI_KEY, KEY_SLASH },
  1734. { "lessthan", SI_KEY, KEY_OEM_102 },
  1735. //-------------------------------------- BUTTON EVENTS
  1736. // Joystick/Mouse buttons
  1737. { "button0", SI_BUTTON, KEY_BUTTON0 },
  1738. { "button1", SI_BUTTON, KEY_BUTTON1 },
  1739. { "button2", SI_BUTTON, KEY_BUTTON2 },
  1740. { "button3", SI_BUTTON, KEY_BUTTON3 },
  1741. { "button4", SI_BUTTON, KEY_BUTTON4 },
  1742. { "button5", SI_BUTTON, KEY_BUTTON5 },
  1743. { "button6", SI_BUTTON, KEY_BUTTON6 },
  1744. { "button7", SI_BUTTON, KEY_BUTTON7 },
  1745. { "button8", SI_BUTTON, KEY_BUTTON8 },
  1746. { "button9", SI_BUTTON, KEY_BUTTON9 },
  1747. { "button10", SI_BUTTON, KEY_BUTTON10 },
  1748. { "button11", SI_BUTTON, KEY_BUTTON11 },
  1749. { "button12", SI_BUTTON, KEY_BUTTON12 },
  1750. { "button13", SI_BUTTON, KEY_BUTTON13 },
  1751. { "button14", SI_BUTTON, KEY_BUTTON14 },
  1752. { "button15", SI_BUTTON, KEY_BUTTON15 },
  1753. { "button16", SI_BUTTON, KEY_BUTTON16 },
  1754. { "button17", SI_BUTTON, KEY_BUTTON17 },
  1755. { "button18", SI_BUTTON, KEY_BUTTON18 },
  1756. { "button19", SI_BUTTON, KEY_BUTTON19 },
  1757. { "button20", SI_BUTTON, KEY_BUTTON20 },
  1758. { "button21", SI_BUTTON, KEY_BUTTON21 },
  1759. { "button22", SI_BUTTON, KEY_BUTTON22 },
  1760. { "button23", SI_BUTTON, KEY_BUTTON23 },
  1761. { "button24", SI_BUTTON, KEY_BUTTON24 },
  1762. { "button25", SI_BUTTON, KEY_BUTTON25 },
  1763. { "button26", SI_BUTTON, KEY_BUTTON26 },
  1764. { "button27", SI_BUTTON, KEY_BUTTON27 },
  1765. { "button28", SI_BUTTON, KEY_BUTTON28 },
  1766. { "button29", SI_BUTTON, KEY_BUTTON29 },
  1767. { "button30", SI_BUTTON, KEY_BUTTON30 },
  1768. { "button31", SI_BUTTON, KEY_BUTTON31 },
  1769. //-------------------------------------- MOVE EVENTS
  1770. // Mouse/Joystick axes:
  1771. { "xaxis", SI_MOVE, SI_XAXIS },
  1772. { "yaxis", SI_MOVE, SI_YAXIS },
  1773. { "zaxis", SI_MOVE, SI_ZAXIS },
  1774. { "rxaxis", SI_MOVE, SI_RXAXIS },
  1775. { "ryaxis", SI_MOVE, SI_RYAXIS },
  1776. { "rzaxis", SI_MOVE, SI_RZAXIS },
  1777. { "slider", SI_MOVE, SI_SLIDER },
  1778. //-------------------------------------- POV EVENTS
  1779. // Joystick POV:
  1780. { "xpov", SI_POV, SI_XPOV },
  1781. { "ypov", SI_POV, SI_YPOV },
  1782. { "upov", SI_POV, SI_UPOV },
  1783. { "dpov", SI_POV, SI_DPOV },
  1784. { "lpov", SI_POV, SI_LPOV },
  1785. { "rpov", SI_POV, SI_RPOV },
  1786. { "xpov2", SI_POV, SI_XPOV2 },
  1787. { "ypov2", SI_POV, SI_YPOV2 },
  1788. { "upov2", SI_POV, SI_UPOV2 },
  1789. { "dpov2", SI_POV, SI_DPOV2 },
  1790. { "lpov2", SI_POV, SI_LPOV2 },
  1791. { "rpov2", SI_POV, SI_RPOV2 },
  1792. #if defined( TORQUE_OS_WIN32 ) || defined( TORQUE_OS_XENON )
  1793. //-------------------------------------- XINPUT EVENTS
  1794. // Controller connect / disconnect:
  1795. { "connect", XI_BUTTON, XI_CONNECT },
  1796. // L & R Thumbsticks:
  1797. { "thumblx", XI_AXIS, XI_THUMBLX },
  1798. { "thumbly", XI_AXIS, XI_THUMBLY },
  1799. { "thumbrx", XI_AXIS, XI_THUMBRX },
  1800. { "thumbry", XI_AXIS, XI_THUMBRY },
  1801. // L & R Triggers:
  1802. { "triggerl", XI_AXIS, XI_LEFT_TRIGGER },
  1803. { "triggerr", XI_AXIS, XI_RIGHT_TRIGGER },
  1804. // DPAD Buttons:
  1805. { "dpadu", XI_BUTTON, SI_UPOV },
  1806. { "dpadd", XI_BUTTON, SI_DPOV },
  1807. { "dpadl", XI_BUTTON, SI_LPOV },
  1808. { "dpadr", XI_BUTTON, SI_RPOV },
  1809. // START & BACK Buttons:
  1810. { "btn_start", XI_BUTTON, XI_START },
  1811. { "btn_back", XI_BUTTON, XI_BACK },
  1812. // L & R Thumbstick Buttons:
  1813. { "btn_lt", XI_BUTTON, XI_LEFT_THUMB },
  1814. { "btn_rt", XI_BUTTON, XI_RIGHT_THUMB },
  1815. // L & R Shoulder Buttons:
  1816. { "btn_l", XI_BUTTON, XI_LEFT_SHOULDER },
  1817. { "btn_r", XI_BUTTON, XI_RIGHT_SHOULDER },
  1818. // Primary buttons:
  1819. { "btn_a", XI_BUTTON, XI_A },
  1820. { "btn_b", XI_BUTTON, XI_B },
  1821. { "btn_x", XI_BUTTON, XI_X },
  1822. { "btn_y", XI_BUTTON, XI_Y },
  1823. #endif
  1824. //-------------------------------------- MOTION EVENTS
  1825. // Accelerometer/Gyroscope axes:
  1826. { "accelx", SI_MOTION, SI_ACCELX },
  1827. { "accely", SI_MOTION, SI_ACCELY },
  1828. { "accelz", SI_MOTION, SI_ACCELZ },
  1829. { "gravityx", SI_MOTION, SI_GRAVX },
  1830. { "gravityy", SI_MOTION, SI_GRAVY },
  1831. { "gravityz", SI_MOTION, SI_GRAVZ },
  1832. { "gyrox", SI_MOTION, SI_GYROX },
  1833. { "gyroy", SI_MOTION, SI_GYROY },
  1834. { "gyroz", SI_MOTION, SI_GYROZ },
  1835. { "yaw", SI_MOTION, SI_YAW },
  1836. { "pitch", SI_MOTION, SI_PITCH },
  1837. { "roll", SI_MOTION, SI_ROLL },
  1838. //-------------------------------------- TOUCH EVENTS
  1839. // Touch events:
  1840. { "touchdown", SI_TOUCH, SI_TOUCHDOWN },
  1841. { "touchup", SI_TOUCH, SI_TOUCHUP },
  1842. { "touchmove", SI_TOUCH, SI_TOUCHMOVE },
  1843. //-------------------------------------- GESTURE EVENTS
  1844. // Preset gesture events:
  1845. { "circleGesture", SI_GESTURE, SI_CIRCLE_GESTURE },
  1846. { "swipeGesture", SI_GESTURE, SI_SWIPE_GESTURE },
  1847. { "screenTapGesture", SI_GESTURE, SI_SCREENTAP_GESTURE },
  1848. { "keyTapGesture", SI_GESTURE, SI_KEYTAP_GESTURE },
  1849. { "pinchGesture", SI_GESTURE, SI_PINCH_GESTURE },
  1850. { "scaleGesture", SI_GESTURE, SI_SCALE_GESTURE },
  1851. //-------------------------------------- GESTURE EVENTS
  1852. // Preset gesture events:
  1853. { "leapHandAxis", SI_LEAP, LM_HANDAXIS },
  1854. { "leapHandPos", SI_LEAP, LM_HANDPOS },
  1855. { "leapHandRot", SI_LEAP, LM_HANDROT },
  1856. { "leapFingerPos", SI_LEAP, LM_FINGERPOS },
  1857. //-------------------------------------- MISCELLANEOUS EVENTS
  1858. //
  1859. { "anykey", SI_KEY, KEY_ANYKEY },
  1860. { "nomatch", SI_UNKNOWN, 0xFFFFFFFF }
  1861. };
  1862. AsciiMapping gAsciiMap[] =
  1863. {
  1864. //--- KEYBOARD EVENTS
  1865. //
  1866. { "space", 0x0020 },
  1867. //{ "exclamation", 0x0021 },
  1868. { "doublequote", 0x0022 },
  1869. //{ "pound", 0x0023 },
  1870. //{ "ampersand", 0x0026 },
  1871. { "apostrophe", 0x0027 },
  1872. //{ "lparen", 0x0028 },
  1873. //{ "rparen", 0x0029 },
  1874. { "comma", 0x002c },
  1875. { "minus", 0x002d },
  1876. { "period", 0x002e },
  1877. //{ "slash", 0x002f },
  1878. //{ "colon", 0x003a },
  1879. //{ "semicolon", 0x003b },
  1880. //{ "lessthan", 0x003c },
  1881. //{ "equals", 0x003d },
  1882. //{ "morethan", 0x003e },
  1883. //{ "lbracket", 0x005b },
  1884. { "backslash", 0x005c },
  1885. //{ "rbracket", 0x005d },
  1886. //{ "circumflex", 0x005e },
  1887. //{ "underscore", 0x005f },
  1888. { "grave", 0x0060 },
  1889. //{ "tilde", 0x007e },
  1890. //{ "vertbar", 0x007c },
  1891. //{ "exclamdown", 0x00a1 },
  1892. //{ "cent", 0x00a2 },
  1893. //{ "sterling", 0x00a3 },
  1894. //{ "currency", 0x00a4 },
  1895. //{ "brokenbar", 0x00a6 },
  1896. //{ "ring", 0x00b0 },
  1897. //{ "plusminus", 0x00b1 },
  1898. { "super2", 0x00b2 },
  1899. { "super3", 0x00b3 },
  1900. { "acute", 0x00b4 },
  1901. //{ "mu", 0x00b5 },
  1902. //{ "ordmasculine", 0x00ba },
  1903. //{ "questiondown", 0x00bf },
  1904. //{ "gemandbls", 0x00df },
  1905. //{ "agrave", 0x00e0 },
  1906. //{ "aacute", 0x00e1 },
  1907. //{ "acircumflex", 0x00e2 },
  1908. //{ "atilde", 0x00e3 },
  1909. //{ "adieresis", 0x00e4 },
  1910. //{ "aring", 0x00e5 },
  1911. //{ "ae", 0x00e6 },
  1912. //{ "ccedille", 0x00e7 },
  1913. //{ "egrave", 0x00e8 },
  1914. //{ "eacute", 0x00e9 },
  1915. //{ "ecircumflex", 0x00ea },
  1916. //{ "edieresis", 0x00eb },
  1917. //{ "igrave", 0x00ec },
  1918. //{ "iacute", 0x00ed },
  1919. //{ "icircumflex", 0x00ee },
  1920. //{ "idieresis", 0x00ef },
  1921. //{ "ntilde", 0x00f1 },
  1922. //{ "ograve", 0x00f2 },
  1923. //{ "oacute", 0x00f3 },
  1924. //{ "ocircumflex", 0x00f4 },
  1925. //{ "otilde", 0x00f5 },
  1926. //{ "odieresis", 0x00f6 },
  1927. //{ "divide", 0x00f7 },
  1928. //{ "oslash", 0x00f8 },
  1929. //{ "ugrave", 0x00f9 },
  1930. //{ "uacute", 0x00fa },
  1931. //{ "ucircumflex", 0x00fb },
  1932. //{ "udieresis", 0x00fc },
  1933. //{ "ygrave", 0x00fd },
  1934. //{ "thorn", 0x00fe },
  1935. //{ "ydieresis", 0x00ff },
  1936. { "nomatch", 0xFFFF }
  1937. };
  1938. ////Device Event Types
  1939. //#define SI_UNKNOWN 0x01
  1940. //#define SI_BUTTON 0x02
  1941. //#define SI_POV 0x03
  1942. //#define SI_XPOV 0x04
  1943. //#define SI_YPOV 0x05
  1944. //#define SI_UPOV 0x06
  1945. //#define SI_DPOV 0x07
  1946. //#define SI_LPOV 0x08
  1947. //#define SI_RPOV 0x09
  1948. //#define SI_KEY 0x0A
  1949. //#define SI_XAXIS 0x0B
  1950. //#define SI_YAXIS 0x0C
  1951. //#define SI_ZAXIS 0x0D
  1952. //#define SI_RXAXIS 0x0E
  1953. //#define SI_RYAXIS 0x0F
  1954. //#define SI_RZAXIS 0x10
  1955. //#define SI_SLIDER 0x11