Page 2 of 4

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 03 Oct 2013, 06:32
by Alibaba
Maybe you should also advert to the possibility of using C.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 03 Oct 2013, 08:12
by nnnik
Of C and ASM.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 03 Oct 2013, 08:38
by Alibaba
Yes, right.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 03 Oct 2013, 09:19
by Gio
This is a great tutorial. Thanks Nnnik.

I wonder how many people in the AHK community have moderate to deep assembly knowledge. There is yet a lot to be achieved with it. Comercial security and a true compiler are long awaited news.

My knowledge may be on the moderate level, though i've mostly studied concepts and debugged code. Not that much coding done by myself atm.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 03 Oct 2013, 20:35
by Alibaba
Thanks for this great Tutorial and translating it into german and posting it twice also!

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 04 Oct 2013, 02:20
by nnnik
Thanks back.
But there is still a part that's missing.
Bentschi said he also had some problems with something similar.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 10 Nov 2013, 10:10
by nnnik
Finally found out what the problem was.
Now I'm working on some additional stuff again.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 20 Nov 2013, 05:29
by nnnik
Fuck some part has gone missing :O

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 03 Dec 2013, 12:42
by nnnik
I added it again.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 05 Dec 2013, 07:37
by nnnik
Also feel free to share any MCode function you've created here.
I might need some good examples for further chapters.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 05 Dec 2013, 08:26
by Bentschi
How about perlin noise?

Code: Select all

double findnoise2(double x, double y)
{
    int n = (int)x+(int)y*57;
    n = (n<<13)^n;
    int nn = (n*(n*n*60493+19990303)+1376312589)&0x7fffffff;
    return 1.0-((double)nn/1073741824.0);
}

double interpolate(double a, double b, double x)
{
    double ft = x * 3.1415927;
    double f = (1.0-cos(ft))* 0.5;
    return a*(1.0-f)+b*f;
}

double noise(double x, double y)
{
	double floorx = (double)((int)x);
	double floory = (double)((int)y);
	double s,t,u,v;
	s = findnoise2(floorx, floory);
	t = findnoise2(floorx+1, floory);
	u = findnoise2(floorx, floory+1);
	v = findnoise2(floorx+1, floory+1);
	double int1 = interpolate(s, t, x-floorx);
	double int2 = interpolate(u, v, x-floorx);
	return interpolate(int1, int2, y-floory);
}

GLuint renderCloud(int w, int h, double zoom, double p)
{
    int octaves = 2;
    GLuint tex = 0;
    glGenTextures(1, &tex);
    glBindTexture(GL_TEXTURE_2D, tex);
    unsigned char *pixels = (unsigned char *)malloc(w*h*sizeof(unsigned char));
	for(int y=0; y<h; y++)
	{
        for(int x=0; x<w; x++)
        {
            double getnoise = 0;
            for(int a=0; a<octaves-1; a++)
            {
                double frequency = pow(2, a);
                double amplitude = pow(p, a);
                getnoise += noise(((double)x)*frequency/zoom, ((double)y)/zoom*frequency)*amplitude;
            }
            int color = (int)((getnoise*128.0)+128.0);
            if(color>255)
                color = 255;
            if(color<0)
                color = 0;
            pixels[(h*y)+x] = color;
        }
	}

    glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, w, h, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    return tex;
}
Good example:
GLuint tex = renderCloud(512, 512, 75, 0.5);

This is the best perlin noise function i've found on the net.
Maybe you want to change the code into GDI/GDI+
Also try to change the octaves variable to 3 (makes a nice effect)

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 05 Dec 2013, 11:38
by nnnik
Thanks that's exactly what I'm searching for.
But float/double to int conversion wont work unless you add the /Qifist option with the compiler.
I already suggested to use it.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 05 Dec 2013, 13:04
by Bentschi
I'll PM you a new version of the generator...

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 06 Dec 2013, 07:20
by Bentschi
I've done some tests on the newer version on the generator, and QIfist works fine.
QIfist is now also in the older version until the new version comes.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 11 Mar 2014, 15:03
by geek
First off, a great example of using machine code to extend AHK's functionality is this long-integer library http://www.autohotkey.com/board/topic/1 ... c-library/

Second off, why not actually call it what it is: machine code? You say MCode *everywhere*, but never actually explain it stands for machine code.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 11 Mar 2014, 16:21
by nnnik
I thought that was obvious.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 16 Mar 2014, 12:07
by joedf
maybe could host the generator also??? because i still dont get how to do it with GCC :P
also, you wrote "beispiele", nicht alle leute hier sprechen deutsch :P

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 16 Mar 2014, 13:30
by nnnik
Well I didn't manage to make Visual C++ compile 64 bit code.
But I can make the GCC thing once im finished with my finals next week.

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 04 May 2014, 13:31
by joedf
For reference : Information on converting C functions to machine code using Microsoft's free Visual C++ Express compilers
http://www.autohotkey.com/board/topic/1 ... ntry161667

Re: MCode Tutorial (Compiled Code in AHK)

Posted: 16 Sep 2014, 11:15
by joedf