Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Look into the <code>nme.Memory</code> API. The idea is to create a <code>ByteArray</code> with the correct size (or get it from a <code>BitmapData</code>), select it as the current virtual memory space and manipulate its bytes directly.</p> <p>You'll get an approximately 10x speed boost with Flash and it should be way faster with the CPP target too. <strong>Don't forget to compile in Release mode</strong> or method inlining will be disabled and performances will suffer a lot.</p> <p>Basic usage example (untested code) :</p> <pre class="lang-hx prettyprint-override"><code>var rect:Rectangle = bitmapData.rect; // 32bits integer = 4 bytes var size:Int = bitmapData.width * bitmapData.height * 4; // The virtual memory space we'll use var pixels:ByteArray = new ByteArray(); // CPP does not support setting the length property directly #if (cpp) pixels.setLength(size); #else pixels.length = size; #end // Select the memory space (call it once, not every frame) Memory.select(pixels); // And in your loop set your color // Color is in BGRA mode, nme.Memory can only be used in little endian mode. Memory.setI32((y * width + x) * 4, color); // When you're done, render the BitmapData // (don't forget to reset the ByteArray position) pixels.position = 0; bitmapData.setPixels(rect, pixels); </code></pre> <p>Keep in mind this is a very basic code example. In your case, you'd need to adapt it and actually use a double sized <code>ByteArray</code> because you need to store the iteration count too. Nested loops can be optimized in your main loop and you can avoid a lot of extra index/address computations :</p> <pre class="lang-hx prettyprint-override"><code>// Note the size * 2 ! // First part of the ByteArray will be used to store the iteration count, // the second part to draw the pixels. #if (cpp) pixels.setLength(size * 2); #else pixels.length = size * 2; #end Memory.select(pixels); // First loop storing iteration count for (iy in 0...height) { for (ix in 0...width) { // ... do some stuff ... Memory.setI32((iy * width + ix) &lt;&lt; 2, iteration); } } // In your runLoop : for (i in 0...(height * width)) { // Get the iteration count var pixel:Int = Memory.getI32(i &lt;&lt; 2); r = pixel + colorModifier; g = pixel + colorModifier + r; b = pixel + colorModifier + g; // Note that we're writing the pixel in the second part of our ByteArray Memory.setI32(size + (i &lt;&lt; 2), r | g &lt;&lt; 8 | b &lt;&lt; 16); } // Sets the position to the second part of our ByteArray pixels.position = size; bitmapData.setPixels(rect, pixels); </code></pre> <p>And this is it. If you really don't want to use Alchemy Opcodes on the Flash target, the next fastest way to blit pixels is to use <code>getVector()</code> / <code>setVector()</code> from the <code>BitmapData</code> class. But it's really not as fast.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload