I still want the ability to edit documents in the game's folder from within the api - maybe after setting a special mode or something to avoid mistakes? (One practical use is the ability to change the game's default screen res you ought to be able to edit the game's manifest to do that, but there are a stack of other uses too)
Anyhow, for now the graphics speed issue, I've cleaned up my script so you can run and it see what you think. couple of notes: I switched the v1 function from transformBlit to transformBlitMask and now it's speed is closer to the v2 implementations - though it's still slightly faster conversely the v2 versions don't seem to have any speed difference for having a custom shader that does masking vs not having one.
Sorry about some of the variable names, was in an odd mood when writing this, also I used tab and space interchangeably so some of the indenting is a bit weird, should look normal if pasted into the sphere editor or any text editor where tab = 2 spaces.
Change the values set to the variables at the top to try out the different options, note I think modes 1 and 2 are just bad ideas and that the comparison should be between modes 0 and 3.
//what mode
//0 = shape + model per deformation, with 4 vertices per shape and one texture shared by all
//1 = one shape + model only but with 4 vertices and a texture
//2 = one shape + model only but with points (variable below) number of vertices and no texture
//3 = v1 .transformBlitMask
var mode =0;
var points = 1000; // how many points on a ring
var num_rings = 1000; //how many rings to draw
var speed_limit = false; //true to use screen.flip (60 FPS limt) false to use FlipScreen - no limit
//load shader - set to Shader.Default if you don't have shaders to use
//note script below will pass shader 4 floats m_r, m_g, m_b and m_a for color masking
//tests show that using the Default shader (and hence no colours in modes 0,1 and 2 has no noticeable speed impact vs using custom vertex shader that masks
var shades = new Shader({vertex: "shaders/customised.vert.glsl", fragment: "shaders/customised.frag.glsl"});
//function to set up rings
function generate_rings(how_many,min_x,max_x,min_y,max_y)
{
var rings = new Array();
for(var i = 0; i < how_many; ++i)
{
rings[i] = new Object();
rings[i].x = Math.floor(Math.random()*(max_x-min_x))+ min_x;
rings[i].y = Math.floor(Math.random()*(max_y-min_y))+ min_y;
rings[i].z = 0.6 - (2 * Math.random() / 5);
rings[i].t = Math.floor(Math.random()*100);
rings[i].dx = Math.round(10 * (Math.random() - 0.5));
rings[i].dy = Math.round(7 * (Math.random() - 0.5));
rings[i].dz = 0.1 * (Math.random() - 0.5);
rings[i].dt = 5 - Math.ceil(10 * Math.random());
rings[i].col = [1,1,1,0.9];
rings[i].dc = [(1-Math.round(Math.random()))*Math.random()*0.01,(1-Math.round(Math.random()))*Math.random()*0.01,(1-Math.round(Math.random()))*Math.random()*0.01,(1-Math.round(Math.random()))*Math.random()*0.01];
}
return rings;
}
//function to update and draw the rings
function update_random_rings(rings,update,min_x,max_x,min_y,max_y)
{
for(var i = 0; i < rings.length; ++i)
{
if(update)
{
if(rings[i].t + rings[i].dt > 99)
{
rings[i].t = 0;
}
else if(rings[i].t + rings[i].dt <0)
{
rings[i].t = 99;
}
else
{
rings[i].t += rings[i].dt;
}
rings[i].x += rings[i].dx;
rings[i].y += rings[i].dy;
rings[i].z += rings[i].dz;
if (rings[i].x > max_x)
{
rings[i].dx = - Math.round(4 * Math.random());
}
else if (rings[i].x < min_x)
{
rings[i].dx = Math.round(4 * Math.random());
}
else if(Math.random() > 0.99)
{
rings[i].dx -= Math.round(3 * (Math.random() - 0.5));
}
if (rings[i].y > max_y)
{
rings[i].dy = - Math.round(3 * Math.random());
}
else if (rings[i].y < min_y)
{
rings[i].dy = Math.round(1.5 * Math.random());
}
else if (Math.random() > 0.99)
{
rings[i].dy -= Math.round(1.5 * (Math.random() - 0.5));
}
if (rings[i].z <0.2)
{
rings[i].dz = 0.02 * (Math.random());
}
else if (rings[i].z > 1.7)
{
rings[i].dz = - 0.02 * (Math.random());
}
else if (Math.random() > 0.99)
{
rings[i].dz -= 0.005 * (Math.random() - 0.5);
}
if(rings[i].dt > 4)
{
rings [i].dt = 2;
}
else if(rings[i].dt <-4)
{
rings [i].dt = -2;
}
else if(Math.random() >0.95)
{
rings[i].dt += 1 - Math.ceil(Math.random()*2)
}
rings[i].col[0] = (rings[i].col[0] + rings[i].dc[0]) % 1;
rings[i].col[1] = (rings[i].col[1] + rings[i].dc[1]) % 1;
rings[i].col[2] = (rings[i].col[2] + rings[i].dc[2]) % 1;
rings[i].col[3] = (rings[i].col[3] + rings[i].dc[3]) % 1;
}
if(mode < 3)
{
foo.identity();
if(mode > 0)
{
foo.matrix[1][0] = 3 * (Math.sin(rings[i].t * Math.PI/45) - Math.cos(rings[i].t * Math.PI/45)) / 8;
foo.matrix[1][1] = 0.5 - Math.sin(rings[i].t * Math.PI/45) - Math.cos(rings[i].t * Math.PI/45);
foo.matrix[1][2] = 3 * Math.cos(rings[i].t * Math.PI/45);
model_.setFloat("m_r", rings[i].col[0]);
model_.setFloat("m_g", rings[i].col[1]);
model_.setFloat("m_b", rings[i].col[2]);
model_.setFloat("m_a", rings[i].col[3]);
}
else
{
models[rings[i].t].setFloat("m_r", rings[i].col[0]);
models[rings[i].t].setFloat("m_g", rings[i].col[1]);
models[rings[i].t].setFloat("m_b", rings[i].col[2]);
models[rings[i].t].setFloat("m_a", rings[i].col[3]);
}
foo.scale(rings[i].z / 2,rings[i].z /1.5);
foo.translate(rings[i].x, rings[i].y);
if(mode > 0)
{
foo.translate(0, 50 * Math.cos(rings[i].t * Math.PI/100));
model_.draw(screen);
}
else
{
models[rings[i].t].draw(screen);
}
}
else
{
jeff.transformBlitMask(rings[i].x ,
rings[i].y + (rings[i].z * 25) * Math.cos(rings[i].t * Math.PI/50),
rings[i].x + rings[i].z * 80,
rings[i].y + (rings[i].z * 25) * Math.sin(rings[i].t * Math.PI/50),
rings[i].x + rings[i].z * 80,
rings[i].y + rings[i].z * 12.5 - rings[i].z * 25 * Math.cos(rings[i].t * Math.PI/50),
rings[i].x,
rings[i].y + rings[i].z * 12.5 - rings[i].z * 25 * Math.sin(rings[i].t * Math.PI/50),CreateColor(rings[i].col[0]*255,rings[i].col[1]*255,rings[i].col[2]*255,rings[i].col[3]*255));
}
}
}
//create the ring image
function ring(colour_a, colour_b, a, b)
{
if(mode < 3)
{
var output = new Surface(2*a + 2, 2*b + 2, new Color(0,0,0,0));
}
else
{
var output = CreateSurface(2*a+2,2*b+2,CreateColor(0,0,0,0));
}
var _vertices = [];
for(var i = 0, t_x = 0, t_y = 0; i < (points/5); ++i)
{
t_x = a * Math.cos(i*Math.PI/(points/10)) + 1;
t_y = b * Math.sin(i*Math.PI/(points/10)) + 1;
_vertices.push({x:t_x,y:t_y,color:colour_a});
_vertices.push({x:t_x + 1,y:t_y,color:colour_b});
_vertices.push({x:t_x,y:t_y + 1,color:colour_b});
_vertices.push({x:t_x -1,y:t_y,color:colour_b});
_vertices.push({x:t_x,y:t_y-1,color:colour_b});
}
if(mode <3)
{
foo.translate(a,b);
var temp = new Shape(_vertices,null,ShapeType.LineLoop);
temp.draw(output,foo);
if(mode < 2)
{
return output.toTexture();
}
else
{
return new Model([temp],shades);
}
}
else
{
for(i = 0; i < _vertices.length; ++i)
{
output.setPixel(_vertices[i].x + a, _vertices[i].y + b, CreateColor(_vertices[i].color.r*255,_vertices[i].color.g*255,_vertices[i].color.b*255));
}
return output.createImage();
}
}
var fun_rings =[];
fun_rings[0] = generate_rings(Math.floor(num_rings/4),0,400,0,357);
fun_rings[1] = generate_rings(Math.floor(num_rings/4),0,400,377,748);
fun_rings[2] = generate_rings(Math.floor(num_rings/4),600,1024,0,357);
fun_rings[3] = generate_rings(Math.floor(num_rings/4),600,1024,377,748);
var coords = [[50,400,20,357],[50,400,377,730],[500,1000,377,730],[500,1000,0,357]];
var foo = new Transform();
var jeff = ring(new Color(1,1,1,1),new Color(0.9,0.9,0.9,1),65,30);
//create the models for the rings type of model determined by mode
if (mode == 0)
{
var shapes = [];
var models = [];
var y_s =[];
var v_s = [];
for (var inc = 0; inc < 100; ++inc)
{
y_s[0] = Math.round(Math.cos(inc * Math.PI/50) * 30);
y_s[1] = Math.round(Math.sin(inc * Math.PI/50) * 30);
y_s[2] = Math.round(15 - Math.sin(inc * Math.PI/50) * 30);
y_s[3] = Math.round(15 - Math.cos(inc * Math.PI/50) * 30);
shapes[inc] = new Shape([{x:0, y:y_s[0],u:0,v:0,color:Color.White},
{x:80,y:y_s[1],u:1,v:0,color:Color.White},
{x:0, y:y_s[2],u:0,v:1,color:Color.White},
{x:80,y:y_s[3],u:1,v:1,color:Color.White}],jeff,ShapeType.TriStrip);
models[inc] = new Model([shapes[inc]],shades);
models[inc].setInt("mask_mode", 1);
models[inc].transform = foo;
}
}
else if (mode == 1)
{
var shape_ = new Shape([{x:0,y:0,u:0,v:0,color:Color.White},
{x:80,y:0,u:1,v:0,color:Color.White},
{x:0,y:30,u:0,v:1,color:Color.White},
{x:80,y:30,u:1,v:1,color:Color.White}],jeff,ShapeType.TriStrip);
var model_ = new Model([shape_],shades);
model_.setInt("mask_mode", 1);
model_.transform = foo;
}
else if(mode == 2)
{
model_ = jeff;
model_.setInt("mask_mode", 1);
model_.transform = foo;
}
//loop to draw rings etc
var time = GetTime();
var time1 = GetTime();
var flag = false;
var ticker = 0;
while(!IsKeyPressed(KEY_ESCAPE))
{
if(time + 25 < GetTime())
{
time = GetTime();
flag = true;
}
if(time1 + 2000 < GetTime())
{
time1 = GetTime();
if(Math.random() > 0.7)
{
++ticker;
}
}
for(i=0;i<4;++i)
{
update_random_rings(fun_rings[i],flag,coords[(ticker + i) % 4][0],coords[(ticker + i) % 4][1],coords[(ticker + i) % 4][2],coords[(ticker + i) % 4][3])
}
flag = false;
while(IsAnyKeyPressed()&&(!IsKeyPressed(KEY_ESCAPE)));
if(speed_limit)
{
screen.flip();
}
else
{
FlipScreen();
}
}