• 0

    posted a message on Galaxy++ editor

    Yeah.. I see that the obfuscation feature is broken at the moment.. I really need to rewrite it completely, since it's implemented rather bad right now. Anyway, I fixed some of the bugs, and released a new version.

    Posted in: Third Party Tools
  • 0

    posted a message on Galaxy++ editor

    I got a couple of deadlines comming up for some school projects, which is why I haven't been very active the last couple of days.

    @Slarti: Go Hmm.. wouldn't really call it a bug. It's meant to overload binary operators, and it's not syntactically correct to write 2*3; Still, I might be able to relax that for custom operators.

    @Kueken531: Go Good point with the mod files.. Ill look into that when I have the time. Although, you will probably need to give the compiler the script explicitly, since, if I remember correctly, you can't get the .SC2Mod file from the dependencies.

    class Foo
    {
        static Foo*[10] fooList;
        static int fooCount=0;
        Foo()
        {
            fooList[fooCount++]=this;
        }
    }
    

    Doesn't give me any errors.. Did you forget the * in the type?

    In terms of output script, it doesn't really matter if you write

    Foo* f = new Foo();
    

    or

    new Foo();
    

    Although the latter is not possible. If f in the first one is not used, it will be removed when optimizing. To be honest, if I were to make the latter possible, I would probably just insert "Foo* f =" during compilation.

    Posted in: Third Party Tools
  • 0

    posted a message on [Solved] Detecting a shape from a set of points

    Yeah, it won't do horizontal or vertical lines very well due to clamping it to [-1, 1]. But they are rather simple shapes that you can test for before clamping.. There are some room for optimizations and improvements in this code.
    Also, the "probably not a match" thingy is just testing if the distance pr point is greater than 0.04, so you can tweak that.. Anyway, you might find better ways of doing it, but there's my go at it :)

    Initializer
    {
        shapes[(int)Shape.Circle] = new point[16]();
        for (int i = 0; i < 16; i++)
        {
            fixed angle = i * 360.0/16.0;
            shapes[(int)Shape.Circle][i] = Point(Cos(angle), Sin(angle));
        }
        shapes[(int)Shape.PositiveLine] = new point[16]();
        for (int i = 0; i < 16; i++)
        {
            shapes[(int)Shape.PositiveLine][i] = Point(i/8.0 - 1, i/8.0 - 1);
        }
        shapes[(int)Shape.NegativeLine] = new point[16]();
        for (int i = 0; i < 16; i++)
        {
            shapes[(int)Shape.NegativeLine][i] = Point(i/8.0 - 1, 1 - i/8.0);
        }
        userPoints = new point[0]();
    }
    
    
    point[] userPoints;
    point[][3] shapes;
    enum Shape
    {
        Circle,
        PositiveLine,
        NegativeLine
    }
    
    
    Trigger MouseDown
    {
        events
        {
            TriggerAddEventMouseClicked(MouseDown, c_playerAny, c_mouseButtonLeft, true);
        }
        actions
        {
            userPoints->Resize(0);
            TriggerEnable(TrackMouse, true);
        }
    }
    
    Trigger TrackMouse
    {
        events
        {
            TriggerAddEventMouseMoved(TrackMouse, c_playerAny);
            TriggerEnable(TrackMouse, false);
        }
        actions
        {
            //Might be able to optimize this - you probably dont need as many points
            int length = userPoints->length;
            userPoints->Resize(length + 1);
            userPoints[length] = Point(EventMouseMovedPosXUI(), EventMouseMovedPosYUI());
        }
    }
    
    Trigger MouseUp
    {
        events
        {
            TriggerAddEventMouseClicked(MouseUp, c_playerAny, c_mouseButtonLeft, false);
        }
        actions
        {
            TriggerEnable(TrackMouse, false);
            if (IsHorizontalLine(userPoints))
            {
                UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, "Horizontal line");
                return;
            }
            if (IsVerticalLine(userPoints))
            {
                UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, "Vertical line");
                return;
            }
            ClampPoints(userPoints);
            int bestMatch = -1;
            fixed bestMatchDist = -1;
            for (int i = 0; i < shapes.length; i++)
            {
                fixed dist = DistanceTo(i, userPoints);
                if (bestMatch == -1 || dist < bestMatchDist)
                {
                    bestMatch = i;
                    bestMatchDist = dist;
                }
            }
            UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, "Best match was " + (string)(Shape)bestMatch + " with a distance of " + bestMatchDist + ".");
            UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, "Distance pr point: " + bestMatchDist/userPoints->length);
            if (bestMatchDist/userPoints->length > 0.2)
                UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, "Probably not a match");
            
        }
    }
    
    bool IsHorizontalLine(point[] points)
    {
        fixed minY = points[0].y;
        fixed maxY = minY;
        fixed x = points[0].x;
        int index = points->length - 1;
        bool positiveDir = points[index].x > x;
        int count = points->length;
        for (int i = 1; i < count; i++)
        {
            if (x != points[i].x && positiveDir != (x <= points[i].x))
                return false;
            x = points[i].x;
            fixed y = points[i].y;
            if (y < minY)
                minY = y;
            if (y > maxY)
                maxY = y;
            if ((maxY - minY) > 50)
                return false;
        }
        return true;
    }
    
    bool IsVerticalLine(point[] points)
    {
        fixed minX = points[0].x;
        fixed maxX = minX;
        fixed y = points[0].y;
        int index = points->length - 1;
        bool positiveDir = points[index].y >= y;
        int count = points->length;
        for (int i = 1; i < count; i++)
        {
            if (y != points[i].y && positiveDir != (y <= points[i].y))
                return false;
            y = points[i].y;
            fixed x = points[i].x;
            if (x < minX)
                minX = x;
            if (x > maxX)
                maxX = x;
            if ((maxX - minX) > 50)
                return false;
        }
        return true;
    }
    
    fixed DistanceTo(int shape, point[] userPoints)
    {
        //You will be able to optimize this if the shape points is saved in a specific way, for instance sorted by x or y
        //Also, you can terminate early if you send the current min dist with
        fixed totDist = 0;
        for (int i = userPoints->length - 1; i >= 0; i--)
        {
            fixed minDist = 10;//Since it's clamped, 8 is max distance in calculations
            for (int j = shapes[shape]->length - 1; j >= 0; j--)
            {
                fixed x = userPoints[i].x - shapes[shape][j].x;
                fixed y = userPoints[i].y - shapes[shape][j].y;
                fixed dist = x*x + y*y;
                if (dist < minDist*minDist)
                    minDist = SquareRoot(dist);
            }
            totDist += minDist;
        }
        return totDist;
    }
    
    void ClampPoints(point[] points)
    {
        //Make points within [-1, 1]
        fixed maxX = points[0].x;
        fixed maxY = points[0].y;
        fixed minX = maxX;
        fixed minY = maxY;
        for (int i = points->length - 1; i>0; i--)
        {
            fixed x = points[i].x;
            fixed y = points[i].y;
            if (x < minX)
                minX = x;
            if (x > maxX)
                maxX = x;
            if (y < minY)
                minY = y;
            if (y > maxY)
                maxY = y;
        }
        fixed midX = (maxX + minX)/2;
        fixed midY = (maxY + minY)/2;
        fixed sizeX = (maxX - minX)/2;
        fixed sizeY = (maxY - minY)/2;
        for (int i = points->length - 1; i>=0; i--)
        {
            points[i].x = (points[i].x - midX)/sizeX;
            points[i].y = (points[i].y - midY)/sizeY;
        }
    }
    
    
    enrich point
    {
        fixed x
        {
            get
            {
                return PointGetX(this);
            }
            set
            {
                this = Point(value, this.y);
            }
        }
        fixed y
        {
            get
            {
                return PointGetY(this);
            }
            set
            {
                this = Point(this.x, value);
            }
        }
    }
    
    Posted in: Galaxy Scripting
  • 0

    posted a message on [Solved] Detecting a shape from a set of points

    I decided to try making something to do this, when I saw the post.. I save some arrays of points for each shape. Then, for each shape I measure for each point from the users dawing, the distance to the closest point int the shape and sum them up. That is the distance to a shape. The shape with the smallest distance is probably what he was trying to draw.

    I tested it, with the shapes circle and line, and it seems to work.

    Initializer
    {
        shapes[(int)Shape.Circle] = new point[16]();
        for (int i = 0; i < 16; i++)
        {
            fixed angle = i * 360.0/16.0;
            shapes[(int)Shape.Circle][i] = Point(Cos(angle), Sin(angle));
        }
        shapes[(int)Shape.PositiveLine] = new point[16]();
        for (int i = 0; i < 16; i++)
        {
            shapes[(int)Shape.PositiveLine][i] = Point(i/8.0 - 1, i/8.0 - 1);
        }
        shapes[(int)Shape.NegativeLine] = new point[16]();
        for (int i = 0; i < 16; i++)
        {
            shapes[(int)Shape.NegativeLine][i] = Point(i/8.0 - 1, 1 - i/8.0);
        }
        userPoints = new point[0]();
    }
    
    
    point[] userPoints;
    
    Trigger MouseDown
    {
        events
        {
            TriggerAddEventMouseClicked(MouseDown, c_playerAny, c_mouseButtonLeft, true);
        }
        actions
        {
            userPoints->Resize(0);
            TriggerEnable(TrackMouse, true);
        }
    }
    
    Trigger TrackMouse
    {
        events
        {
            TriggerAddEventMouseMoved(TrackMouse, c_playerAny);
            TriggerEnable(TrackMouse, false);
        }
        actions
        {
            //Might be able to optimize this - you probably dont need that many points
            int length = userPoints->length;
            userPoints->Resize(length + 1);
            userPoints[length] = Point(EventMouseMovedPosXUI(), EventMouseMovedPosYUI());
        }
    }
    
    Trigger MouseUp
    {
        events
        {
            TriggerAddEventMouseClicked(MouseUp, c_playerAny, c_mouseButtonLeft, false);
        }
        actions
        {
            TriggerEnable(TrackMouse, false);
            ClampPoints(userPoints);
            int bestMatch = -1;
            fixed bestMatchDist = -1;
            for (int i = 0; i < shapes.length; i++)
            {
                fixed dist = DistanceTo(i, userPoints);
                if (bestMatch == -1 || dist < bestMatchDist)
                {
                    bestMatch = i;
                    bestMatchDist = dist;
                }
            }
            UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, "Best match was " + (string)(Shape)bestMatch + " with a distance of " + bestMatchDist + ".");
            UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, "Distance pr point: " + bestMatchDist/userPoints->length);
            if (bestMatchDist/userPoints->length > 0.04)
                UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, "Probably not a match");
            
        }
    }
    
    
    point[][3] shapes;
    enum Shape
    {
        Circle,
        PositiveLine,
        NegativeLine
    }
    
    fixed DistanceTo(int shape, point[] userPoints)
    {
        //You will be able to optimize this if the shape points is saved in a specific way, for instance sorted by x or y
        fixed totDist = 0;
        for (int i = userPoints->length - 1; i >= 0; i--)
        {
            fixed minDist = 10;//Since it's clamped, 8 is max distance in calculations
            for (int j = shapes[shape]->length - 1; j >= 0; j--)
            {
                fixed x = userPoints[i].x - shapes[shape][j].x;
                fixed y = userPoints[i].y - shapes[shape][j].y;
                fixed dist = x*x + y*y;
                if (dist < minDist)
                    minDist = dist;
            }
            totDist += minDist;
        }
        return totDist;
    }
    
    void ClampPoints(point[] points)
    {
        //Make points within [-1, 1]
        fixed maxX = points[0].x;
        fixed maxY = points[0].y;
        fixed minX = maxX;
        fixed minY = maxY;
        for (int i = points->length - 1; i>0; i--)
        {
            fixed x = points[i].x;
            fixed y = points[i].y;
            if (x < minX)
                minX = x;
            if (x > maxX)
                maxX = x;
            if (y < minY)
                minY = y;
            if (y > maxY)
                maxY = y;
        }
        fixed midX = (maxX + minX)/2;
        fixed midY = (maxY + minY)/2;
        fixed sizeX = (maxX - minX)/2;
        fixed sizeY = (maxY - minY)/2;
        for (int i = points->length - 1; i>=0; i--)
        {
            points[i].x = (points[i].x - midX)/sizeX;
            points[i].y = (points[i].y - midY)/sizeY;
        }
    }
    
    
    enrich point
    {
        fixed x
        {
            get
            {
                return PointGetX(this);
            }
            set
            {
                this = Point(value, this.y);
            }
        }
        fixed y
        {
            get
            {
                return PointGetY(this);
            }
            set
            {
                this = Point(this.x, value);
            }
        }
    }
    
    Posted in: Galaxy Scripting
  • 0

    posted a message on Show us your cool custom UI-s!

    Although I didn't use sc layout files much, I thought I would post some pictures of a project of mine :)

    I'm not really developing much on it anymore... got this compiler thingy taking up time, but I did use it to test many of the features of the compiler.

    Posted in: UI Development
  • 0

    posted a message on Galaxy++ editor

    Hmm.. seems I for some reason commented the call to the code that fixes value refs :s Shame on me for only testing if my projects could compile

    Posted in: Third Party Tools
  • 0

    posted a message on Intro videos to Galaxy++

    Well, I kindda feel like it's about time to get new versions up, but on the other hand - they will be outdated as soon as I implement a new feature.. I think I will wait a bit, and work on the compiler instead.

    Posted in: Galaxy Scripting
  • 0

    posted a message on Intro videos to Galaxy++

    I probably should get these videos update to a newer version of the editor. They are currently 8 months old. Although I don't think anyone really watches them..

    Posted in: Galaxy Scripting
  • 0

    posted a message on Galaxy++ editor

    You can use the initializer library functionally.. Any dependancies will be run before the current initializer. It will be faster to write with a simple integer, but harder to maintain if you share code with multiple people, like if you use libraries that use initializers.

    Initializer(
        LibraryName = "Run me last",
        LibraryVersion = "1",
        RequiredLibraries = "Run me first:1"
    )
    {
        
    }
    
    Initializer(
        LibraryName = "Run me first",
        LibraryVersion = "1"
    )
    {
        
    }
    
    Posted in: Third Party Tools
  • 0

    posted a message on Galaxy++ editor

    @Kueken531: Go

    Are you sure the int[0] i; presists to galaxy code? It should be removed.
    Also, it's impossible check at compile time if you create a dynamic array of size 0 - You could use the returned value of a function, and well.. Rice's theorem.

    Posted in: Third Party Tools
  • 0

    posted a message on Galaxy++ editor

    Thanks guys, Ill get to work on fixing them.

    Quote from Kueken531: Go

    And a question: Is implicit resizing supported? I cannot test the result right now, but writing

    int[] i=new int[5]();
    i[10]=5;
    

    throws no error for me.

    No. It is not supported, though it will work. The only issue with it is that when you delete i, it will only remove elements up to the specified length of the array.

    Edit:

    Quote from Kueken531: Go

    Others haven't changed (like replace and undo issue, 0 size array), but you are probably aware of that and consider them lower priority.

    How exactly do you define this 0 sized array? I thought I fixed that one.

    Quote from Mexaprone: Go

    There's also an issue that you can't "right-click" warnings such as "unused struct: MyStruct", as that activates the error box which says it is unable to open the file. The label stating where the struct is declared seems to not be set properly either, as it says "Library file[1, 8]: Unused struct: MyStruct" when my struct isn't originating from any library.

    I can't replicate this one : / you got some code?

    Posted in: Third Party Tools
  • 0

    posted a message on Galaxy++ editor

    Hell, it's about time - Version 3.0.0 is finally here :)

    I don't think that it is bug free though. So much code as been written, so there are likely to still be bugs lurking around.. If it's horrible, remember that you can downgrade in Help->Change to another version.

    Posted in: Third Party Tools
  • 0

    posted a message on Galaxy++ editor

    @Kueken531: Go

    I just had a look at your bug. It is caused by an incorrect update to my control flow graph, after removing an unused local assignment. I will fix it for next version of course, but you should be able to fix it by removing your unused local assignments.

        if (id==0){
            k=350;
        }
        else {
            k=150;
        }
        //In your code, this value of i is not being read.
        i=libNtve_gf_CreateDialogItemLabel(d,400,k, c_anchorTopLeft,75,95,GetUnitTooltip(id), Color(100,100,100), false, 2.0);
    
    Posted in: Third Party Tools
  • 0

    posted a message on Galaxy++ editor

    So far, I should have the compiler part done, and about half of the suggestion list done. But once I get that done, there will be some time with bug fixing.

    @Wyatt124: Go

    The compiler is written in c#. It's probably not be a bad idea to bring others aboard for faster updates - although there are a lot of code for someone to wrap his head around - and that's probably even harder right now where the code won't compile.

    @Kueken531: Go

    What I meant was to use global fields instead of local variables. It won't merge a field with a local variable.

    int k;
    void foo()
    {
       ...
       if (id==0){
            k=350;
        }
        else {
            k=150;
        }
        i=libNtve_gf_CreateDialogItemLabel(d,400,k, c_anchorTopLeft,75,95,GetUnitTooltip(id), Color(100,100,100), false, 2.0);
    }
    

    If the g++ compiler can generate invalid code, then that is a bug, so arrays of size 0 should be reported as an error, or removed by the compiler.

    Posted in: Third Party Tools
  • 0

    posted a message on Galaxy++ editor

    Hmm.. that looks weird.. I'm still working on the big rewrite and fixing its bugs though. Before I get that done, I can't really release any bug fixes, because the program is too unstable - at this point I got error reports popping up all the time :).
    I know it's been a while, but changing the naming really has ramifications everywhere.. Also, as I said earlier, I do have other things to do apart from this project.

    Anyway.. only advice I can really give right now is to use fields when it bugs on you like that.. It shouldn't join them.

    Posted in: Third Party Tools
  • To post a comment, please or register a new account.