A dynamic array function Module

Started by ollj, Sat 01/08/2015 15:24:15

Previous topic - Next topic

ollj

//this is about ags 3.4.0.3 functionality; dynamic arrays and managed structs:

//i have been coding a lot in ags-script recently and feel the need to report some of the more usefull code i wrote:

//recently i have been writing on a module for static functions on n-dimensional arrays. the functions are all in a
autoptr managed struct NdF{// for "Ndimensional Float", and an instance of it only stores
int dimensions;
//...
}
for each static function there is also a non-static function that just calls its static-equivalent, but that non-static gives it (this.dimension) instead of requiring a specific (dimension) parameter.

the array functions usually take one or 2 float arrays
import (static) float[] ArrayFunction(float a[],float b[],...) as parameter and most of them return a a float[];

this all started when i wanted to compute an n-dimensional crossproduct of two n-dimensional with the same function, beecause why not compute a crossproduct in 1024 dimensions? i think my 1024 dimensional DOTproduct finds more use.

once the number of dimensions of input vectors is no longer an issue for the functions you use, you easily come up with more and more functions

I may give it an extension:
autoptr managed struct NdFa extends NdF{// for "Ndimensional Float", and an instance of it only stores
float a[];
//...
that has for each function that takes a float array, one equivalent function that instead takes (this.a) and a boolean (also overwite this.a wth the returned value)

i may wrap this managed struct in a struct, just so that i can access an instance of that within another function.


and i may also do the same for integer arrays as
managed struct NdI{//n dimensional integer array functions
}
but so far this project frew a bit out of proportions and i need to think about struturing it more.

of course there are many things you can do with one or more float arrays in n-dimensions ,
so far i wrote a lot of vector functions,  i define a circle by having the LAST value of the array set the circles radius.
I calculate circle intersections, calculate shortest distance of dot from line in 3d...
I move points around "wildly" using the same vector functions over and over within loops of loops.
I calculate means, averages

I also have functions for simplle physics simulations (gravity, acellerate, turn follow), ragdoll physics (verlet integration), Boids (swarm behavior) and what you need for more complex things like meshes of half-vectors, Delaunay-triangulation.

and they are all in the same struct.

needless to say, this grows on its own, and i am just glad i can not extend on the "float" type and my "Float" wrapper so far turned out to be pretty useless.


i think i need some help woth basic "extend"-inheritance. what struct should extend on what other struct, adding what functions while not including what other functions of another branch, and would that even be worth making different structs that i may need to write getters and setters to for non-statics just to get and set values from one struct type to another, even if its the very same inside of em?

well, ill release some of it after fiqing the worst errors of some basic testing.

but for testing my functions for errors really need a half decent "canvas" for ags. and so far just drawing on a drawsurface from the background image just didnt quite cut it.

i tried making a canvas of a sprite to a dynamicsprite, but working with dynamicsprite pointers is a bit messy in ags;
make a sprite for a "dot/sphere", and remember how often that dot is used, and only if its last use is removed, clear the dynamicsprite, that was my most recent plan. and its a bit flawed.

Monsieur OUXX

Quick answer: there are already modules that do multidimensional arrays.
 

SMF spam blocked by CleanTalk