{"id":133,"date":"2011-01-12T14:05:10","date_gmt":"2011-01-12T20:05:10","guid":{"rendered":"http:\/\/www.ancor.ch\/schoebey\/?p=133"},"modified":"2011-01-12T14:35:51","modified_gmt":"2011-01-12T20:35:51","slug":"actionstriggers-local-and-global-ids","status":"publish","type":"post","link":"https:\/\/www.ancor.ch\/schoebey\/?p=133","title":{"rendered":"actions&#038;triggers: local and global IDs"},"content":{"rendered":"<p>an action needs to be able to reference any action or trigger that has been created in order to manipulate it.<\/p>\n<p>For example:<\/p>\n<p>if the player is standing in front of a door and presses X, the door should open.<\/p>\n<p>If he presses X again, the door shouldn&#8217;t open again but close instead.<\/p>\n<p>This means the &#8216;open&#8217; action, once triggered, needs to deactivate itself and activate its sibling action instead.<\/p>\n<p>In order to allow actions such a behaviour, each action needs a global unique identifier.<\/p>\n<p>The action manager manages those IDs and is able to find the according pointer when queried with an ID.<\/p>\n<h2>Problem<\/h2>\n<p>This is all fine and well if an action wants to manipulate a very specific action or trigger in the global context. But what if the action wants to manipulate a local action?<\/p>\n<p>The above example works fine with global IDs, but imagine what happens when the object containing the &#8216;open&#8217; and &#8216;close&#8217; actions gets copied and moved elsewhere.<\/p>\n<p>If the player approaches the copied door and presses X, the door opens. That&#8217;s ok so far. The just triggered &#8216;open&#8217; action deactivates itself as expected, but instead of activating its sibling action, it activates the &#8216;close&#8217; action of the original door object.<\/p>\n<p>Why? Because the just triggered &#8216;open&#8217; action references the &#8216;close&#8217; action by its global ID, which got copied along with the rest of the object.<\/p>\n<h2><strong>Introducing Local IDs<\/strong><\/h2>\n<p>In order to prevent exactly this problem from happening, aside from its <strong>global ID<\/strong>, each action also contains a &#8216;<strong>local ID<\/strong>&#8216;.<\/p>\n<p>This ID identifies the action <em><strong>within its parent object<\/strong>.<\/em><\/p>\n<p>So if the door object&#8217;s &#8216;open&#8217;-action references its sibling action by its local ID,\u00c2\u00a0<em> <\/em>copying the object would be no problem, the copied action would enable the correct sibling action.<\/p>\n<p>The same system will be implemented for triggers.<\/p>\n<h2>technical details<\/h2>\n<p>the actionmanager class contains a map: &#8220;id &lt;-&gt; action pointer&#8221; for global IDs<\/p>\n<p>the parent object contains a map: &#8220;id &lt;-&gt; action pointer&#8221; for local IDs<\/p>\n<p>Whenever a local or global ID changes, the actionmanager or parent object gets notified.<\/p>\n<p>If an action changes objects from one parent to another, the old parent gets notified and deregisters the action, before the new parent registers it.<\/p>\n<p>both actionmanager and object get new methods that return the action pointer corresponding to a certain ID.<\/p>\n<p>in addition to these changes, actions and triggers get the ability to reference target object not by their global ID but by using a constant or string telling them to use their parent object as their target.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>an action needs to be able to reference any action or trigger that has been created in order to manipulate it. For example: if the player is standing in front of a door and presses X, the door should open. If he presses X again, the door shouldn&#8217;t open again but close instead. This means [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-133","post","type-post","status-publish","format-standard","hentry","category-code","category-p407"],"_links":{"self":[{"href":"https:\/\/www.ancor.ch\/schoebey\/index.php?rest_route=\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ancor.ch\/schoebey\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ancor.ch\/schoebey\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ancor.ch\/schoebey\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ancor.ch\/schoebey\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=133"}],"version-history":[{"count":6,"href":"https:\/\/www.ancor.ch\/schoebey\/index.php?rest_route=\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":140,"href":"https:\/\/www.ancor.ch\/schoebey\/index.php?rest_route=\/wp\/v2\/posts\/133\/revisions\/140"}],"wp:attachment":[{"href":"https:\/\/www.ancor.ch\/schoebey\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ancor.ch\/schoebey\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ancor.ch\/schoebey\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}