{"id":488,"date":"2010-11-29T03:25:25","date_gmt":"2010-11-28T23:55:25","guid":{"rendered":"http:\/\/www.blog.seganx.com\/?p=488"},"modified":"2024-03-18T16:48:01","modified_gmt":"2024-03-18T16:48:01","slug":"input-system","status":"publish","type":"post","link":"https:\/\/sajad-b.com\/?p=488","title":{"rendered":"Input System"},"content":{"rendered":"<p>The input system of the engine is completed. this system is composed of a main static input class which contains all input data including keyboard keys, mouse buttons, two analog data, and one cursor. these data are separated into four players and the engine&#8217;s parts can access these data from the main input class by specifying the player ID.<\/p>\n<div class=\"codecolorer-container cpp railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"cpp codecolorer\">myState <span class=\"sy1\">=<\/span> sx<span class=\"sy4\">::<\/span><span class=\"me2\">io<\/span><span class=\"sy4\">::<\/span><span class=\"me2\">Input<\/span><span class=\"sy4\">::<\/span><span class=\"me2\">GetAnalog_2<\/span><span class=\"br0\">&#40;<\/span>playerID<span class=\"br0\">&#41;<\/span><span class=\"sy2\">-<\/span><span class=\"sy1\">&gt;<\/span>state<span class=\"sy4\">;<\/span><br \/>\ncursorX <span class=\"sy1\">=<\/span> sx<span class=\"sy4\">::<\/span><span class=\"me2\">io<\/span><span class=\"sy4\">::<\/span><span class=\"me2\">Input<\/span><span class=\"sy4\">::<\/span><span class=\"me2\">GetCursor_ABS<\/span><span class=\"br0\">&#40;<\/span>playerID<span class=\"br0\">&#41;<\/span><span class=\"sy2\">-<\/span><span class=\"sy1\">&gt;<\/span>x<span class=\"sy4\">;<\/span><\/div><\/div>\n<p>each hardware input device &#8211; Keyboard, Mouse, Joystick, etc &#8211; can easily defined and attached to the main input class. for example, to define a new joystick for the engine we can write down a unique class for that joystick which is inherited from the standard input device interface of the engine, and attach that to the engine by a unique player ID.<\/p>\n<div class=\"codecolorer-container cpp railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"cpp codecolorer\"><span class=\"kw2\">class<\/span> MyJoystick <span class=\"sy4\">:<\/span> <span class=\"kw2\">public<\/span> sx<span class=\"sy4\">::<\/span><span class=\"me2\">io<\/span><span class=\"sy4\">::<\/span><span class=\"me2\">InputDeviceBase<\/span><br \/>\n<span class=\"br0\">&#123;<\/span><br \/>\n<span class=\"co1\">\/\/ ...<\/span><br \/>\n<span class=\"co1\">\/\/ .. define joystick<\/span><br \/>\n<span class=\"co1\">\/\/ .. change main input class data<\/span><br \/>\n<span class=\"co1\">\/\/ ...<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"sy4\">;<\/span><br \/>\n<br \/>\n<span class=\"co1\">\/\/ add joystick connectivity. specify player ID in the creation time<\/span><br \/>\nsx<span class=\"sy4\">::<\/span><span class=\"me2\">io<\/span><span class=\"sy4\">::<\/span><span class=\"me2\">PInputDeviceBase<\/span> newDevice <span class=\"sy1\">=<\/span> SEGAN_NEW<span class=\"br0\">&#40;<\/span> MyJoystick<span class=\"br0\">&#40;<\/span>new_playerID<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#41;<\/span><span class=\"sy4\">;<\/span><br \/>\nsx<span class=\"sy4\">::<\/span><span class=\"me2\">io<\/span><span class=\"sy4\">::<\/span><span class=\"me2\">Input<\/span><span class=\"sy4\">::<\/span><span class=\"me2\">Attach<\/span><span class=\"br0\">&#40;<\/span> newDevice <span class=\"br0\">&#41;<\/span><span class=\"sy4\">;<\/span><\/div><\/div>\n<p>Also, we can easily send signals to the player devices to change a value or use some new features of current joysticks. something like this:<\/p>\n<div class=\"codecolorer-container cpp railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"cpp codecolorer\"><span class=\"co1\">\/\/ send signal to the joystick to vibrate it<\/span><br \/>\nInput_Signal_Vibration isVibrate<span class=\"sy4\">;<\/span><br \/>\nisVibrate.<span class=\"me1\">wLeftMotorSpeed<\/span> <span class=\"sy1\">=<\/span> SX_INPUT_DEFAULT_VIBRATE<span class=\"sy4\">;<\/span><br \/>\nisVibrate.<span class=\"me1\">wRightMotorSpeed<\/span> <span class=\"sy1\">=<\/span> SX_INPUT_DEFAULT_VIBRATE<span class=\"sy4\">;<\/span><br \/>\nsx<span class=\"sy4\">::<\/span><span class=\"me2\">io<\/span><span class=\"sy4\">::<\/span><span class=\"me2\">Input<\/span><span class=\"sy4\">::<\/span><span class=\"me2\">SendSignal<\/span><span class=\"br0\">&#40;<\/span>playerID, IST_SHOCK, isVibrate<span class=\"br0\">&#41;<\/span><span class=\"sy4\">;<\/span><\/div><\/div>\n<p>And finally, all keys and buttons in this system will have one state from listed below:<\/p>\n<div class=\"codecolorer-container cpp railscasts\" style=\"overflow:auto;white-space:nowrap;width:100%;\"><div class=\"cpp codecolorer\"><span class=\"co1\">\/\/! input buttons state<\/span><br \/>\nSX_INPUT_STATE_NORMAL <span class=\"nu0\">0<\/span> <span class=\"co1\">\/\/This is the normal state of the key<\/span><br \/>\nSX_INPUT_STATE_DOWN_FIRST <span class=\"nu0\">1<\/span> <span class=\"co1\">\/\/The key is pressed in first time.<\/span><br \/>\nSX_INPUT_STATE_DOWN_HOLD <span class=\"nu0\">2<\/span> <span class=\"co1\">\/\/After the first down, the state will go to hold down<\/span><br \/>\nSX_INPUT_STATE_UP <span class=\"sy2\">-<\/span><span class=\"nu0\">1<\/span> <span class=\"co1\">\/\/ pressing finished.<\/span><br \/>\n<span class=\"co1\">\/\/This state will go back to normal in the next update<\/span><\/div><\/div>\n<p>So when we make our game just use one standard input class and don&#8217;t worry about devices anymore. easily find how many players are connected. after that according to the gameplay use the keys and data in the input system. For each player change input data or vibrate joystick sets.<\/p>\n<p>PS: The other part of the engine is currently under development. rendering parts, mesh, materials, HUD, AI, script contexts, particles, physics, logic objects, etc will come to gather in the core and will set on scene system and node structures.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The input system of the engine is completed. this system is composed of a main static input class which contains all input data including keyboard keys, mouse buttons, two analog data, and one cursor. these data are separated into four players and the engine&#8217;s parts can access these data from the main input class by [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[7],"tags":[24],"class_list":["post-488","post","type-post","status-publish","format-standard","hentry","category-engine","tag-input-system"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/sajad-b.com\/index.php?rest_route=\/wp\/v2\/posts\/488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sajad-b.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sajad-b.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sajad-b.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sajad-b.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=488"}],"version-history":[{"count":4,"href":"https:\/\/sajad-b.com\/index.php?rest_route=\/wp\/v2\/posts\/488\/revisions"}],"predecessor-version":[{"id":863,"href":"https:\/\/sajad-b.com\/index.php?rest_route=\/wp\/v2\/posts\/488\/revisions\/863"}],"wp:attachment":[{"href":"https:\/\/sajad-b.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sajad-b.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sajad-b.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}