GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Re: Script Submission » rectangle_on_line » 2016-07-04 19:14:32

Not taking credits for myself but I had the need for a very optimised version of this once and someone gave me this, which seems pretty good. I'm not very good at maths so I'll just put it here and you guys can analyse it. I remember wanting as many early-outs as possible, but I don't know if it's the best approach to achieve best performance.

Expand///line_cross_rectangle(line_x1,line_y1,line_x2,line_y2,rect_x1,rect_y1,rect_x2,rect_y2)
var lx1, ly1, lx2, ly2, rx1, ry1, rx2, ry2, a, t;
// make sure it goes from low to high
lx1 = min(argument0, argument2);
ly1 = min(argument1, argument3);
lx2 = max(argument0, argument2);
ly2 = max(argument1, argument3);
rx1 = min(argument4, argument6);
ry1 = min(argument5, argument7);
rx2 = max(argument4, argument6);
ry2 = max(argument5, argument7);
// checks if the vertical projection overlaps
if(lx1 < rx1 && lx2 < rx1) {
    return 0;
}
if(lx1 > rx2 && lx2 > rx2) {
    return 0;
}
// collision check for a vertical line or point
if(lx1 == lx2) {
    return !((ly1 < ry1 && ly2 < ry1) || (ly1 > ry2 && ly2 > ry2));
}
// collision check for other lines
a = (ly1 - ly2) / (lx1 - lx2);
t = a * (max(lx1, rx1) - lx1) + ly1;
if(t > ry1 && t < ry2) {
    return 1;
}
t = a * (min(lx2, rx2) - lx1) + ly1;
if(t > ry1 && t < ry2) {
    return 1;
}
return 0;

#2 Script Submission » d3d_set_projection_view » 2015-08-05 14:47:54

iFredQC
Replies: 0

This script will setup the 3D projection to perfectly mimic GM's view system. It is mostly useful for people doing a 3D game that has 2D game mechanics.

This script does not require d3d_start() to work.

A useful feature of the script is that if you set zfar to a negative number, it will set zfar to the distance from the camera to the Z == 0 plane, multiplied by -zfar. So if the camera is 1000 units away from Z == 0 and zfar is set to -1, zfar will be set to 1000 * -(-1) or 1000.

Arguments:
view_id = Which view index to take the settings from
fov = Field of View of the camera
znear = znear of the camera
zfar = zfar of the camera (If zfar is smaller than 0, zfar is set to the calculated camera distance to the Z == 0 plane times -(zfar argument))

Expand///d3d_set_projection_view(view_id,fov,znear,zfar)
var vcx = view_xview[argument0] + view_wview[argument0] * 0.5;
var vcy = view_yview[argument0] + view_hview[argument0] * 0.5;
var h = view_hview[argument0] / (2 * dtan(argument1 * 0.5));
var zn = argument2;
var zf = argument3;
if(zf < 0) {
    zf = h * -zf;
}
d3d_set_projection_ext(vcx, vcy, h, vcx, vcy, 0, dcos(view_angle[argument0] - 90), dsin(view_angle[argument0] - 90), 0, argument1, view_wview[argument0] / view_hview[argument0], zn, zf);

I can't think of any optimization that could be done.

Edit: Removed someone from credits mention at his request.

#3 Re: Script Submission » ds_list_sort_array » 2015-08-05 14:36:35

I just had an idea. I can't confirm that it will work right now, but if we "write" the data using ds_list/grid_write and compare the two, we could find the differences and just do some string manipulation to quickly copy from one to the other. The data is most likely exported in the same way, it's probably just the headers and separators that change.

#4 Re: Script News & Announcements » Monthly Update for July » 2015-07-10 15:20:00

"veteran iFredQC" Hah, made my day.

Thank you!

#5 Script Submission » ds_list_sort_array » 2015-07-09 23:53:16

iFredQC
Replies: 2

This script is used to sort multiple ds_lists together in the same way ds_grids work.

array = An array of ds_lists
index = Which ds_list from the array should the sort be based on
ascending = If true, data will be sorted in ascending order

Expand///ds_list_sort_array(array,index,ascending)
var l = array_length_1d(argument0);
var s = ds_list_size(argument0[0]);
var g = ds_grid_create(l, s);
for(var a = 0; a < l; a += 1) {
    for(var b = 0; b < s; b += 1) {
        g[#a, b] = ds_list_find_value(argument0[a], b);
    }
}
ds_grid_sort(g, argument1, argument2);
for(a = 0; a < l; a += 1) {
    for(b = 0; b < s; b += 1) {
        ds_list_replace(argument0[a], b, g[#a, b]);
    }
}
ds_grid_destroy(g);

Optimization could be done by finding a faster way to copy data between a grid and a list.

#6 Script Submission » instance_nearest_notme » 2015-06-05 12:23:33

iFredQC
Replies: 1

It's as simple as it sounds. The script is short but often requested.

Expand///instance_nearest_notme(x,y,obj)
{
    instance_deactivate_object(self);
    var n = instance_nearest(argument0, argument1, argument2);
    instance_activate_object(self);
    return n;
}

It's tested and I don't think anything could break it.

Board footer

Powered by FluxBB