<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title> Over mouse function</title>
		<link>http://www.allegro.cc/forums/view/616365</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 27 Jun 2016 14:40:15 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey</p><p>(I&#39;m sorry foy my english)</p><p>I have small problem, with function.<br />I made a function that checks whether the mouse cursor is in the field Bitmap.<br />eg. I want to function returns true, if mouse cursor is on alpha pixel.</p><p>In function check position cursor, if cursor is in the field Bitmap.<br />it then get pixel with Bitmap (before lock region bitmap and later unlock)</p><p>Function is play in ALLEGRO_EVENT_MOUSE_AXES</p><p>if I use functions this is delay big.<br />(without this function project is fast)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (00Andre)</author>
		<pubDate>Sun, 26 Jun 2016 13:52:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not sure if I got exactly what you problem is, but I assume it&#39;s that lock bitmap and unlock bitmap slow down your application?</p><p>When you use lock bitmap and unlock bitmap on a display bitmap, it&#39;s bound to be slow, because the bitmap first has to be read from the GPU into system memory and then wrote back to the GPU. Try creating the bitmap as a system memory bitmap. That way you can always directly access the pixels and no data has to be copied. If you also need to render the bitmap, then maybe you should make two versions of the same bitmap. One in system memory and one in display memory. You could then use the system memory bitmap for collision checking and the display bitmap for rendering.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Sun, 26 Jun 2016 16:58:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Mousemove is called A LOT. And locking / Unlocking can be costly if you do it a lot.</p><p>Here are a few suggestions:<br />-Create a bitfield. <a href="https://en.wikipedia.org/wiki/Bit_field">https://en.wikipedia.org/wiki/Bit_field</a> Only lock your bitmap once at the start, and calculate which pixels are alpha and which ones are not and put it in the bitfield. Then check the mouse position against the bitfield to see if it is a transparent or opaque area.</p><p>If that is too complex to understand, an easier version would be to allocate a [w][h] 2D array of char to do it.</p><p>The other option is to build simple polygon approximations of your bitmaps and check if the mouse point is inside the simple polygon.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Sun, 26 Jun 2016 17:00:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Before creating a bitmap. I set the flag and display options
</p><div class="source-code"><div class="toolbar"><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"> 2</span><a href="http://www.allegro.cc/manual/al_set_new_bitmap_flags"><span class="a">al_set_new_bitmap_flags</span></a><span class="k2">(</span>ALLEGRO_CONVERT_BITMAP <span class="k3">|</span> ALLEGRO_VIDEO_BITMAP <span class="k3">|</span>
<span class="number"> 3</span>                        ALLEGRO_MIN_LINEAR <span class="k3">|</span>  ALLEGRO_MAG_LINEAR<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 4</span><a href="http://www.allegro.cc/manual/al_set_new_bitmap_format"><span class="a">al_set_new_bitmap_format</span></a><span class="k2">(</span>ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 5</span><a href="http://www.allegro.cc/manual/al_set_new_display_option"><span class="a">al_set_new_display_option</span></a><span class="k2">(</span>ALLEGRO_VSYNC, <span class="n">1</span>, ALLEGRO_REQUIRE<span class="k2">)</span>
</div></div><p>


I removed the lock and unlock bitmaps and are smaller delay.</p><div class="source-code"><div class="toolbar"><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">  1</span><span class="k1">if</span><span class="k2">(</span>mouse.x <span class="k3">&gt;</span> width <span class="k3">&amp;</span><span class="k3">&amp;</span> mouse.x <span class="k3">&lt;</span> x<span class="k3">+</span>width <span class="k3">&amp;</span><span class="k3">&amp;</span> mouse.y <span class="k3">&gt;</span> height <span class="k3">&amp;</span><span class="k3">&amp;</span> mouse.y <span class="k3">&lt;</span> y<span class="k3">+</span>height<span class="k2">)</span>
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>  <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> pxg <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_pixel"><span class="a">al_get_pixel</span></a><span class="k2">(</span>bitmap, <a href="http://www.delorie.com/djgpp/doc/libc/libc_38.html" target="_blank">abs</a><span class="k2">(</span>mouse.x-x<span class="k2">)</span>, <a href="http://www.delorie.com/djgpp/doc/libc/libc_38.html" target="_blank">abs</a><span class="k2">(</span>mouse.y-y<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  4</span>
<span class="number">  5</span>  <span class="k1">if</span><span class="k2">(</span>pxg.a <span class="k3">=</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span> <span class="c">// NORMAL</span>
<span class="number">  6</span>  <span class="k2">{</span>
<span class="number">  7</span>   <span class="k1">return</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number">  8</span>  <span class="k2">}</span>
<span class="number">  9</span>  <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span>pxg.a <span class="k3">!</span><span class="k3">=</span> <span class="n">0</span><span class="k2">)</span> <span class="c">// ALPHA</span>
<span class="number"> 10</span>  <span class="k2">{</span>
<span class="number"> 11</span>   <span class="k1">return</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number"> 12</span>  <span class="k2">}</span>
<span class="number"> 13</span>  <span class="k1">else</span> <span class="k1">if</span><span class="k2">(</span>pxg <span class="k3">=</span><span class="k3">=</span> color<span class="k2">)</span> <span class="c">// COLOR  // operator==</span>
<span class="number"> 14</span>  <span class="k2">{</span>
<span class="number"> 15</span>   <span class="k1">return</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number"> 16</span>  <span class="k2">}</span>
<span class="number"> 17</span>  <span class="k1">else</span> <span class="k1">return</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number"> 18</span><span class="k2">}</span>
</div></div><p>


but are still delays, but smaller
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (00Andre)</author>
		<pubDate>Sun, 26 Jun 2016 17:52:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Try replacing ALLEGRO_VIDEO_BITMAP with ALLEGRO_MEMORY_BITMAP.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Sun, 26 Jun 2016 19:07:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How swapped for the Allegro BITMAP MEMORY is even worse
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (00Andre)</author>
		<pubDate>Sun, 26 Jun 2016 19:52:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>And what if you do as suggested in my first post? Create two versions of that bitmap. One with ALLEGRO_VIDEO_BITMAP and one with ALLEGRO_MEMORY_BITMAP. Use the ALLEGRO_VIDEO_BITMAP one for rendering, while you use the ALLEGRO_MEMORY_BITMAP one for your alpha checks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Sun, 26 Jun 2016 20:12:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m just curious, <b>1)</b> how many bitmaps are you checking and <b>2)</b> what are the sizes of these bitmaps?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sun, 26 Jun 2016 22:11:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>RPG Marker</b> <br />It works ! and it very quickly . I did like you said <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /><img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /><img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /><img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /></p><p>I have one questions.</p><p>If it is eg . 200 bitmaps is 200 * 2 is equal to 400 bitmaps.<br />it will not be problems with optimization ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (00Andre)</author>
		<pubDate>Mon, 27 Jun 2016 10:36:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The game will, of course, use addtional memroy in system RAM for each copy of a bitmap that you use for mouse collision detection, but depending on the number of bitmaps you need mouse detection for, the size of each bitmap and the hardware you are targeting for your game, it hopefully shouldn&#39;t bee too much of a problem. Nowadays most machines have at least 4 to 8 GB of system RAM, which don&#39;t exceed to quickly.</p><p>If this RAM usage is still too much for you, you&#39;ll most likely have to try a different solution, like one of the solutions jmasterx suggested or maybe even just simple box collisions (depending on what you need this for in the first place). So yeah, the best solution really always depends on what exactly you&#39;re trying to do and for what purpose.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (RPG Hacker)</author>
		<pubDate>Mon, 27 Jun 2016 12:02:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you very much. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>does not want create new thread, So here write</p><p>i often use al_clone_bitmap in project.<br />i tried use recording
</p><div class="source-code"><div class="toolbar"><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"> 1</span> <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bt1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"bt.png"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 2</span> <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bt2 <span class="k3">=</span> bt1<span class="k2">;</span>
</div></div><p>

only if drew on <b>bt2</b> that <b>bt1</b> also changed.</p><p>Why don&#39;t use al_clone_bitmap ? because if used clone_bitmap a lot, that is delay<br />and i tried solve a problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (00Andre)</author>
		<pubDate>Mon, 27 Jun 2016 12:43:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_clone_bitmap"><span class="a">al_clone_bitmap</span></a></span> will create and allocate in memory a whole new bitmap (based on the previous). Any time you allocate something new in memory, it is usually much slower than other things.</p><p>But if you do it like you showed:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bt1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"bt.png"</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bt2 <span class="k3">=</span> bt1<span class="k2">;</span>
</pre></div></div><p>
Here you are just creating a new pointer. Now you have two variables that point to the same bitmap in memory, so no copying and allocation for a new bitmap has to happen.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 27 Jun 2016 14:40:15 +0000</pubDate>
	</item>
</rss>
