<?xml version='1.0' encoding='ISO-8859-1'?>
     <rss version='2.0'>
      <channel>
       <title>waveeffect.lha demo/misc - Comments</title>
       <link>http://se.os4depot.net/?function=comments&amp;file=demo/misc/waveeffect.lha</link>
       <description>Simple Wave effect with source code</description>
       <language>en-gb</language>
       <lastBuildDate>Mon, 13 Apr 2026 06:19:41 +0200</lastBuildDate>
       <image>
        <title>OS4Depot.net</title>
        <url>http://se.os4depot.net/images/rss.gif</url>
        <link>http://se.os4depot.net</link>
       </image><item> <title>Capehill (82.128.191.210) @ 30 Jun 2005, 05:23.11</title> <link>http://se.os4depot.net/?function=comments&amp;file=demo/misc/waveeffect.lha</link> <description>&lt;STRONG&gt;By:&lt;/STRONG&gt;&amp;nbsp;Capehill (82.128.191.210)&lt;BR /&gt;&lt;pre&gt;After wondering why it's so slow, I optimized the loop a bit:

--

        for ( y = 0; y &amp;lt; height; y++ )
        {
            // Calculate modulo outside the inner loop
            const Uint32 y_offset = y * image-&amp;gt;pitch;

            // Uint32 _cos = (y + iter) % height;
            Uint32 _cos = y + iter;
            while ( _cos &amp;gt;= height )
             _cos -= height;

            // Source pixel's base address
            Uint8* src = (Uint8*)image-&amp;gt;pixels + y_offset;

            for ( x = 0; x &amp;lt; width; x++ )
            {
                //Uint32 _sin = (x + iter) % width;
                Uint32 _sin = x + iter;
                while ( _sin &amp;gt;= width )
                 _sin -= width;

                // Calculate wave effect. It depends on wave height and sin/cos
functions
                Sint32 _x = x + ( sin_lut[ _sin ] );
                Sint32 _y = y + ( cos_lut[ _cos ] );

                // Check dimensions
                if ( _x &amp;lt; 0 )
                 _x = width + _x;
                else if ( _x &amp;gt;= width )
                    _x = _x - width;

                if ( _y &amp;lt; 0 )
                 _y = height + _y;
                else if ( _y &amp;gt;= height )
                    _y = _y - height;

                // Destinations pixel's base address
                Uint8* dest = (Uint8*)screen-&amp;gt;pixels + _x * d_bpp + _y *
screen-&amp;gt;pitch;

                // Red
                *(dest + dr) = *( src + sr );

                // Green
                *(dest + dg) = *( src + sg );

                // Blue
                *(dest + db) = *( src + sb );

                src += s_bpp;

            } // x

        } // y  
--

Also MAX_X &amp;amp; MAX_Y multiplications were move to main() where sin_lut and
cos_lut are initialized.

Optimizations give &amp;gt; 30% better performance.
&lt;/pre&gt;</description> <guid isPermaLink='false'>1120144991</guid> <pubDate>Thu, 30 Jun 2005 17:23:11 +0200</pubDate></item></channel> </rss>