<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Joystick Event Injection</title>
		<link>http://www.allegro.cc/forums/view/615220</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 28 Mar 2015 21:03:07 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey, all.</p><p>I am toying with Allegro 5.0.x with which I am using several gamepads (joysticks, according to the API). I have all that working great (got my game loop checking events, ect).</p><p>For debug builds, which I work on while, say, on the bus, I do not have a gamepad with me. In the past to alleviate this issue I have created a thin &quot;conversation layer&quot; that maps keyboard inputs to gamepad buttons. The solution has worked wonders for my convenience but I can not seem to figure out how to implement it with Allegro.</p><p>Is there a way to inject custom events into the joystick queue? Going through the documentation I have tried playing with <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_event_source_data"><span class="a">al_set_event_source_data</span></a><span class="k2">(</span><span class="k2">)</span></span> (line looks like <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_event_source_data"><span class="a">al_set_event_source_data</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_joystick_event_source"><span class="a">al_get_joystick_event_source</span></a><span class="k2">(</span><span class="k2">)</span>, <span class="n">1</span><span class="k2">)</span></span>) but can not figure it out. On top of that looking through the source I see <span class="source-code">intptr_t</span> is just an int pointer of a specific size but with no indication as to what that should be pointing to?</p><p>This would only be for debugs builds. A handful of <span class="source-code"><span class="p">#define</span></span>&#39;s remove it from release builds.</p><p>I searched both Google and the forums but can not seem to find an answer. Any help-- or alternative suggestions-- would be welcomed.</p><p><b>Edit</b> 2015.03.25-01<br />Wait, <span class="source-code">intptr_t</span> is not a pointer. Name threw me.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (NickWebHA)</author>
		<pubDate>Thu, 26 Mar 2015 02:01:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, you can use <span class="source-code"><a href="http://www.allegro.cc/manual/al_init_user_event_source"><span class="a">al_init_user_event_source</span></a></span> and <span class="source-code"><a href="http://www.allegro.cc/manual/al_emit_user_event"><span class="a">al_emit_user_event</span></a></span> to emit an event with a type value of 1024 or greater. But you can&#39;t actually emit a standard allegro event and I&#39;m not quite sure what the reasoning for this is. It would be nice to be able to simulate events.</p><p>Then when you get a joystick event you emit a user event to match it. Then only take action on the user joystick events. That way you can emit one yourself, or forward one from the joystick event.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 26 Mar 2015 05:37:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615220/1011588#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>But you can&#39;t actually emit a standard allegro event and I&#39;m not quite sure what the reasoning for this is.</p></div></div><p>As you state, it would be nice to simulate events.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 26 Mar 2015 05:50:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Been a long time since I have been a part of this community. I need to figure out where I can submit such a request... for another day.</p><p>Thanks, guys. I was considering the user-defined events but they seemed a bit too round-about. However if that is the answer then that is the answer.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (NickWebHA)</author>
		<pubDate>Thu, 26 Mar 2015 05:58:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If it&#39;s for testing purposes, you could use a virtual joystick. The operating system reports to applications about a controller that only exists digitally. The virtual joystick is fed whatever input necessary through library functions.</p><p>For Windows, vJoy looks like a good option to create the virtual joystick. ppJoy can work but is a little bit of a pain to set up for Vista onward. If you don&#39;t want to feed the input from your program with library functions, you can feed with a control script program like AutoHotkey, FreePIE, or GlovePIE.</p><p>I know there&#39;s a nice program for Macs. And don&#39;t know about other OSes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ben Delacob)</author>
		<pubDate>Thu, 26 Mar 2015 15:23:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That is a great idea! Since I control the development machine and am not interested in keyboard controls in the release builds-- read: distributed builds-- a virtual joystick would work perfectly.</p><p>Why did I not think of that? I blame the democrats.</p><p><b>Edit</b> 2015.03.26-01<br />... and now to find one for Linux. Everything I am coming across is gamepad to keyboard, not the other way around. &quot;<a href="https://github.com/Ryochan7/antimicro#description">antimicro is a graphical program used to map keyboard keys and mouse controls to a gamepad</a>&quot; my <span class="cuss"><span>ass</span></span>!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (NickWebHA)</author>
		<pubDate>Thu, 26 Mar 2015 17:03:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615220/1011585#target">NickWebHA</a> said:</div><div class="quote"><p>
Is there a way to inject custom events into the joystick queue? Going through the documentation I have tried playing with al_set_event_source_data() (line looks like al_set_event_source_data(al_get_joystick_event_source(), 1)) but can not figure it out. On top of that looking through the source I see intptr_t is just an int pointer of a specific size but with no indication as to what that should be pointing to?
</p></div></div><p>
If you&#39;re doing custom mapping, inject your conversion layer inbetween your game and the allegro routines, not the allegro routines and the OS.</p><p>Instead of using some form of &quot;is_allegro_joystick_pressed()&quot; in your logic routines you do &quot;is_control_pressed()&quot; and let your code do the linking between whether Allegro has a joystick, mouse, or keyboard present. Your game shouldn&#39;t know whats behind is_control_pressed() at all.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Fri, 27 Mar 2015 22:58:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>AutoHotKey is really powerful.</p><p>And 2, being able to emit allegro events of any type would be very useful.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sat, 28 Mar 2015 05:20:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
I think all that needs to be done is to remove this ASSERT and then I believe you should be able to emit regular allegro events using <span class="source-code"><a href="http://www.allegro.cc/manual/al_emit_user_event"><span class="a">al_emit_user_event</span></a></span>.</p><div class="source-code"><div class="toolbar"><span class="name">evtsrc.c</span><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 215</span><span class="c">/* Function: al_emit_user_event</span>
<span class="number"> 216</span><span class="c"> */</span>
<span class="number"> 217</span><span class="k1">bool</span> <a href="http://www.allegro.cc/manual/al_emit_user_event"><span class="a">al_emit_user_event</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_SOURCE"><span class="a">ALLEGRO_EVENT_SOURCE</span></a> <span class="k3">*</span>src,
<span class="number"> 218</span>   <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> <span class="k3">*</span>event, <span class="k1">void</span> <span class="k2">(</span><span class="k3">*</span>dtor<span class="k2">)</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_USER_EVENT"><span class="a">ALLEGRO_USER_EVENT</span></a> <span class="k3">*</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 219</span><span class="k2">{</span>
<span class="number"> 220</span>   <span class="k1">size_t</span> num_queues<span class="k2">;</span>
<span class="number"> 221</span>   <span class="k1">bool</span> rc<span class="k2">;</span>
<span class="number"> 222</span>
<span class="number"> 223</span>   <a href="http://www.allegro.cc/manual/ASSERT"><span class="a">ASSERT</span></a><span class="k2">(</span>src<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 224</span>   <a href="http://www.allegro.cc/manual/ASSERT"><span class="a">ASSERT</span></a><span class="k2">(</span>event<span class="k2">)</span><span class="k2">;</span>
<div class="highlight"><span class="number"> 225</span>   <a href="http://www.allegro.cc/manual/ASSERT"><span class="a">ASSERT</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_TYPE_IS_USER"><span class="a">ALLEGRO_EVENT_TYPE_IS_USER</span></a><span class="k2">(</span>event-&gt;any.type<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></div><span class="number"> 226</span>
<span class="number"> 227</span>   <span class="k1">if</span> <span class="k2">(</span>dtor<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 228</span>      ALLEGRO_USER_EVENT_DESCRIPTOR <span class="k3">*</span>descr <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_malloc"><span class="a">al_malloc</span></a><span class="k2">(</span><span class="k1">sizeof</span><span class="k2">(</span><span class="k3">*</span>descr<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 229</span>      descr-&gt;refcount <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 230</span>      descr-&gt;dtor <span class="k3">=</span> dtor<span class="k2">;</span>
<span class="number"> 231</span>      event-&gt;user.__internal__descr <span class="k3">=</span> descr<span class="k2">;</span>
<span class="number"> 232</span>   <span class="k2">}</span>
<span class="number"> 233</span>   <span class="k1">else</span> <span class="k2">{</span>
<span class="number"> 234</span>      event-&gt;user.__internal__descr <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number"> 235</span>   <span class="k2">}</span>
<span class="number"> 236</span>
<span class="number"> 237</span>   _al_event_source_lock<span class="k2">(</span>src<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 238</span>   <span class="k2">{</span>
<span class="number"> 239</span>      ALLEGRO_EVENT_SOURCE_REAL <span class="k3">*</span>rsrc <span class="k3">=</span> <span class="k2">(</span>ALLEGRO_EVENT_SOURCE_REAL <span class="k3">*</span><span class="k2">)</span>src<span class="k2">;</span>
<span class="number"> 240</span>
<span class="number"> 241</span>      num_queues <span class="k3">=</span> _al_vector_size<span class="k2">(</span><span class="k3">&amp;</span>rsrc-&gt;queues<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 242</span>      <span class="k1">if</span> <span class="k2">(</span>num_queues <span class="k3">&gt;</span> <span class="n">0</span><span class="k2">)</span> <span class="k2">{</span>
<div class="highlight"><span class="number"> 243</span>         event-&gt;user.timestamp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_time"><span class="a">al_get_time</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></div><span class="number"> 244</span>         _al_event_source_emit_event<span class="k2">(</span>src, event<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 245</span>         rc <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number"> 246</span>      <span class="k2">}</span>
<span class="number"> 247</span>      <span class="k1">else</span> <span class="k2">{</span>
<span class="number"> 248</span>         rc <span class="k3">=</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number"> 249</span>      <span class="k2">}</span>
<span class="number"> 250</span>   <span class="k2">}</span>
<span class="number"> 251</span>   _al_event_source_unlock<span class="k2">(</span>src<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 252</span>
<span class="number"> 253</span>   <span class="k1">if</span> <span class="k2">(</span>dtor <span class="k3">&amp;</span><span class="k3">&amp;</span> <span class="k3">!</span>rc<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 254</span>      dtor<span class="k2">(</span><span class="k3">&amp;</span>event-&gt;user<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 255</span>      <a href="http://www.allegro.cc/manual/al_free"><span class="a">al_free</span></a><span class="k2">(</span>event-&gt;user.__internal__descr<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 256</span>   <span class="k2">}</span>
<span class="number"> 257</span>
<span class="number"> 258</span>   <span class="k1">return</span> rc<span class="k2">;</span>
<span class="number"> 259</span><span class="k2">}</span>
</div></div><p>
The other highlighted line should probably be changed to <span class="source-code">event-&gt;any.timestamp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_time"><span class="a">al_get_time</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></span> to make it more suitable for any event in general.</p><p>The actual nitty gritty function that allegro uses behind the scenes is <span class="source-code">_al_event_source_emit_event</span>, which needs to have the event source locked first, and which uses <span class="source-code">_al_event_queue_push_event</span> internally.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 28 Mar 2015 10:25:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not 100% clear on the implications, but I think being able to emit core events would be great. Another related thing is that it would be great to create event constructor functions (like al_emit_key_event or whatnot). It&#39;d make the internals somewhat cleaner (pretty much every backend has a version of these constructor functions).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sat, 28 Mar 2015 12:59:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/615220/1011630#target">SiegeLord</a> said:</div><div class="quote"><p>
I&#39;m not 100% clear on the implications, but I think being able to emit core events would be great. 
</p></div></div><p>
I agree. I was initially hesitant, but the more I think about it the more I like it. I already do plenty of sending XEvents in XLib in the same vein.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Sat, 28 Mar 2015 21:03:07 +0000</pubDate>
	</item>
</rss>
