]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - fractalnoise.c
rewrote memory system entirely (hunk, cache, and zone are gone, memory pools replaced...
[xonotic/darkplaces.git] / fractalnoise.c
index 93622b14e4530f6f8f8223223bd79dfeda4353b3..31b140d518972459b866a85687df6722d056efa3 100644 (file)
@@ -17,8 +17,8 @@ void fractalnoise(byte *noise, int size, int startgrid)
 
        startgrid = bound(0, startgrid, size);
 
-       amplitude = 32767;
-       noisebuf = qmalloc(size*size*sizeof(int));
+       amplitude = 0xFFFF; // this gets halved before use
+       noisebuf = Mem_Alloc(tempmempool, size*size*sizeof(int));
        memset(noisebuf, 0, size*size*sizeof(int));
 
        for (g2 = startgrid;g2;g2 >>= 1)
@@ -55,10 +55,11 @@ void fractalnoise(byte *noise, int size, int startgrid)
                        if (n(x,y) > max) max = n(x,y);
                }
        max -= min;
+       max++;
        // normalize noise and copy to output
        for (y = 0;y < size;y++)
                for (x = 0;x < size;x++)
-                       *noise++ = (n(x,y) - min) * 255 / max;
-       qfree(noisebuf);
+                       *noise++ = (byte) (((n(x,y) - min) * 256) / max);
+       Mem_Free(noisebuf);
 #undef n
 }