{"id":108,"date":"2009-08-20T18:57:29","date_gmt":"2009-08-20T18:57:29","guid":{"rendered":"https:\/\/blogs.scummvm.org\/upthorn\/?p=108"},"modified":"2022-05-25T19:03:05","modified_gmt":"2022-05-25T19:03:05","slug":"hope-and-change","status":"publish","type":"post","link":"https:\/\/blogs.scummvm.org\/upthorn\/2009\/08\/20\/hope-and-change\/","title":{"rendered":"Hope and change"},"content":{"rendered":"<p>So, as I suggested in my prior blog post, I\u2019ve been working on totally redesigning the Common::Action and Common::Keymap structures.<\/p>\n<p>I\u2019ve been at work on this for a few days now, but because I\u2019m totally redesigning the way they interact with each other, and interface with the rest of the code at large, I\u2019m not done yet, and the code won\u2019t compile until I finish, so I can\u2019t commit it yet.<\/p>\n<p>So, to show what I\u2019ve been working at, I\u2019m posting what I\u2019ve gotten done here.<\/p>\n<p>So far, all the actual rewritten code has been going into the Action struct and related enums.<\/p>\n<blockquote>\n<p style=\"padding-left: 30px;\">enum ActionType {<\/p>\n<p style=\"padding-left: 60px;\">\/\/Emulate a hardware event in the engine<br \/>\nkSingleKeyPressActionType,<br \/>\nkMultiKeyPressType,<br \/>\nkMouseClickType,<br \/>\nkMouseWheelType,<\/p>\n<p style=\"padding-left: 60px;\">\/\/Interface directly with the VM<br \/>\nkSaveActionType,<br \/>\nkMenuActionType,<br \/>\nkQuitActionType,<br \/>\nkVirtualKeyboardActionType,<br \/>\nkKeyRemapActionType,<br \/>\nkVolumeUpActionType,<br \/>\nkVolumeDownActionType,<\/p>\n<p style=\"padding-left: 60px;\">\/\/This is the total number of types currently defined in this enum<br \/>\nkActionTypeMax<\/p>\n<p style=\"padding-left: 30px;\">};<\/p>\n<p style=\"padding-left: 30px;\">enum ClickType {<\/p>\n<p style=\"padding-left: 60px;\">kLeftClickType,<br \/>\nkMiddleClickType,<br \/>\nkRightClickType<\/p>\n<p style=\"padding-left: 30px;\">};<\/p>\n<p style=\"padding-left: 30px;\">enum KeyType {<\/p>\n<p style=\"padding-left: 60px;\">\/\/Direction keys<br \/>\nkDirUpKeyType,<br \/>\nkDirDownKeyType,<br \/>\nkDirLeftKeyType,<br \/>\nkDirRightKeyType,<\/p>\n<p style=\"padding-left: 60px;\">\/\/Keyboard keys<br \/>\nkTextKeyType, \/\/Letters, numbers, symbols, whitespace<br \/>\nkModifierKeyType, \/\/Ctrl, Alt, Shift<\/p>\n<p style=\"padding-left: 60px;\">\/\/Gamepad buttons<br \/>\nkFaceButtonKeyType, \/\/A, B, C, X, Y, Z, and the like<br \/>\nkShoulderButtonKeyType, \/\/Separated from FaceButtons because they can be used as pseudo-modifier keys.<\/p>\n<p style=\"padding-left: 60px;\">\/\/System key types<br \/>\nkPauseKeyType, \/\/Start, Pause, etc..<br \/>\nkMenuKeyType, \/\/Select, Escape, etc\u2026<br \/>\nkSystemActionKeyType, \/\/F1-F12, volume sliders, and so forth<\/p>\n<p style=\"padding-left: 60px;\">\/\/This is the total number of types currently defined in this enum<br \/>\nkKeyTypeMax<\/p>\n<p style=\"padding-left: 30px;\">};<\/p>\n<p style=\"padding-left: 30px;\">struct Action {<\/p>\n<p style=\"padding-left: 60px;\">char id[ACTION_ID_SIZE];<\/p>\n<p style=\"padding-left: 60px;\">ActionType type;<br \/>\nKeyType preferredKey;<\/p>\n<p style=\"padding-left: 30px;\">private:<\/p>\n<p style=\"padding-left: 60px;\">List&lt;Event&gt; _events;<br \/>\nHardwareKey *_mappedKey;<\/p>\n<p style=\"padding-left: 30px;\">public:<\/p>\n<p style=\"padding-left: 60px;\">void mapKey (const HardwareKey *key);<\/p>\n<p style=\"padding-left: 60px;\">void addKeyPressEvent(KeyCode code, byte modifiers) {<\/p>\n<p style=\"padding-left: 90px;\">KeyState key = KeyState(code);<br \/>\nkey.flags = modifiers;<\/p>\n<p style=\"padding-left: 90px;\">Event keyPress;<br \/>\nkeyPress.type = EVENT_KEYDOWN;<br \/>\nkeyPress.kbd = key;<\/p>\n<p style=\"padding-left: 90px;\">_events.push_back(keyPress);<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">void addMouseClickEvent(ClickType t) {<\/p>\n<p style=\"padding-left: 90px;\">Event mouseClick;<br \/>\nif (t == kLeftClickType)<\/p>\n<p style=\"padding-left: 120px;\">mouseClick.type = EVENT_LBUTTONDOWN;<\/p>\n<p style=\"padding-left: 90px;\">else if (t == kRightClickType)<\/p>\n<p style=\"padding-left: 120px;\">mouseClick.type = EVENT_RBUTTONDOWN;<\/p>\n<p style=\"padding-left: 90px;\">else<\/p>\n<p style=\"padding-left: 120px;\">mouseClick.type = EVENT_MBUTTONDOWN;<\/p>\n<p style=\"padding-left: 90px;\">_events.push_back(mouseClick);<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">template &lt;ActonType t&gt;;<br \/>\nAction&lt;kSingleKeyPressActionType&gt; (char *i, KeyType k, KeyCode c, byte m) {<\/p>\n<p style=\"padding-left: 90px;\">memcpy(id,i,ACTION_ID_SIZE);<\/p>\n<p style=\"padding-left: 90px;\">type = t;<br \/>\npreferredKey = k;<\/p>\n<p style=\"padding-left: 90px;\">addKeyPressEvent(c,m);<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">Action&lt;kMultiKeyPressType&gt; (char *i, KeyType k, List&lt;KeyCode&gt; cs, byte m) {<\/p>\n<p style=\"padding-left: 90px;\">memcpy(id,i,ACTION_ID_SIZE);<\/p>\n<p style=\"padding-left: 90px;\">type = t;<br \/>\npreferredKey = k;<\/p>\n<p style=\"padding-left: 90px;\">List&lt;KeyCode&gt;::iterator it;<br \/>\nfor (it = cs.begin(); it != cs.end(); it++) {<\/p>\n<p style=\"padding-left: 120px;\">KeyCode c = *it;<br \/>\naddKeyPressEvent(c,m);<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">Action&lt;kMouseClickType&gt; (char *i, bool l = true, bool m = false, bool r = false) {<\/p>\n<p style=\"padding-left: 90px;\">memcpy(id,i,ACTION_ID_SIZE);<\/p>\n<p style=\"padding-left: 90px;\">type = t;<br \/>\npreferredKey = k;<\/p>\n<p style=\"padding-left: 90px;\">if (l)<\/p>\n<p style=\"padding-left: 120px;\">addMouseClickEvent(kLeftClickType);<\/p>\n<p style=\"padding-left: 90px;\">if (m)<\/p>\n<p style=\"padding-left: 120px;\">addMouseClickEvent(kMiddleClickType);<\/p>\n<p style=\"padding-left: 90px;\">if (r)<\/p>\n<p style=\"padding-left: 120px;\">addMouseClickEvent(kRightClickType);<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">Action&lt;kMouseWheelType&gt; (char *i, bool up = false) {<\/p>\n<p style=\"padding-left: 90px;\">memcpy(id,i,ACTION_ID_SIZE);<\/p>\n<p style=\"padding-left: 90px;\">Event evt;<br \/>\nif (up)<\/p>\n<p style=\"padding-left: 120px;\">evt.type = EVENT_WHEELUP;<\/p>\n<p style=\"padding-left: 90px;\">else<\/p>\n<p style=\"padding-left: 120px;\">evt.type = EVENT_WHEELDOWN;<\/p>\n<p style=\"padding-left: 90px;\">_events.push_back(evt);<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">Action (char *i) {<\/p>\n<p style=\"padding-left: 90px;\">memcpy(id,i,ACTION_ID_SIZE);<br \/>\ntype = t;<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 30px;\">};<\/p>\n<\/blockquote>\n<p>There\u2019s more about how this is going to work which is still in my head, but a lot of initialization stuff that was previously done by Action methods is going to be moved into the Keymap, so there will no longer be any need for an Action to know anything about the set that it is in, except to have a HardwareKey pointer provided to it (and even that will only be so that the Keymap can do effective data-management when an action gets remapped.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, as I suggested in my prior blog post, I\u2019ve been working on totally redesigning the Common::Action and Common::Keymap structures. I\u2019ve been at work on this for a few days now, but because I\u2019m totally redesigning the way they interact with each other, and interface with the rest of the code at large, I\u2019m not [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.scummvm.org\/upthorn\/wp-json\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.scummvm.org\/upthorn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.scummvm.org\/upthorn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/upthorn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.scummvm.org\/upthorn\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":4,"href":"https:\/\/blogs.scummvm.org\/upthorn\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":112,"href":"https:\/\/blogs.scummvm.org\/upthorn\/wp-json\/wp\/v2\/posts\/108\/revisions\/112"}],"wp:attachment":[{"href":"https:\/\/blogs.scummvm.org\/upthorn\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/upthorn\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.scummvm.org\/upthorn\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}