MCode Tutorial (Compiled Code in AHK)

Helpful script writing tricks and HowTo's
Alibaba
Posts: 473
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

03 Oct 2013, 06:32

Maybe you should also advert to the possibility of using C.
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

03 Oct 2013, 08:12

Of C and ASM.
Recommends AHK Studio
Alibaba
Posts: 473
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

03 Oct 2013, 08:38

Yes, right.
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
Gio
Posts: 504
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: MCode Tutorial (Compiled Code in AHK)

03 Oct 2013, 09:19

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.
"What is suitable automation? Whatever saves your day for the greater matters."
Barcoder - Create QR Codes and other Barcodes using only Autohotkey !!
Alibaba
Posts: 473
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

03 Oct 2013, 20:35

Thanks for this great Tutorial and translating it into german and posting it twice also!
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

04 Oct 2013, 02:20

Thanks back.
But there is still a part that's missing.
Bentschi said he also had some problems with something similar.
Recommends AHK Studio
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

10 Nov 2013, 10:10

Finally found out what the problem was.
Now I'm working on some additional stuff again.
Recommends AHK Studio
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

20 Nov 2013, 05:29

Fuck some part has gone missing :O
Recommends AHK Studio
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

03 Dec 2013, 12:42

I added it again.
Recommends AHK Studio
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

05 Dec 2013, 07:37

Also feel free to share any MCode function you've created here.
I might need some good examples for further chapters.
Recommends AHK Studio
Bentschi
Posts: 18
Joined: 02 Oct 2013, 18:45

Re: MCode Tutorial (Compiled Code in AHK)

05 Dec 2013, 08:26

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)
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

05 Dec 2013, 11:38

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.
Recommends AHK Studio
Bentschi
Posts: 18
Joined: 02 Oct 2013, 18:45

Re: MCode Tutorial (Compiled Code in AHK)

05 Dec 2013, 13:04

I'll PM you a new version of the generator...
Bentschi
Posts: 18
Joined: 02 Oct 2013, 18:45

Re: MCode Tutorial (Compiled Code in AHK)

06 Dec 2013, 07:20

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.
GeekDude
Posts: 847
Joined: 02 Oct 2013, 22:13

Re: MCode Tutorial (Compiled Code in AHK)

11 Mar 2014, 15:03

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.
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

11 Mar 2014, 16:21

I thought that was obvious.
Recommends AHK Studio
User avatar
joedf
Posts: 6689
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

16 Mar 2014, 12:07

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
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
nnnik
Posts: 3527
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: MCode Tutorial (Compiled Code in AHK)

16 Mar 2014, 13:30

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.
Recommends AHK Studio
User avatar
joedf
Posts: 6689
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

04 May 2014, 13:31

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
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
joedf
Posts: 6689
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: MCode Tutorial (Compiled Code in AHK)

16 Sep 2014, 11:15

Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 10 guests