Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - ollj

#2
//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.
#3
this problem keeps following me.
i make a struct that has some parameters;

struct IStoreStuff{
int x;
ins y;
String s;
}

IStoreStuff IstoreStufInstance;

and that struct has one or more instances in a scripts header, and silly me expects that, if i read or write any value of any instance (of the very same label) of that struct from anywhere, that it addresses the very same instance. but somehow this is not the case.

simple question. why is my struct not global?
the "export" syntax also seems to do nothing, and is poorly documented.
managed structs in alpha versions? dont get me started, coded so much, just to notice all the limits on managed structs on runtime make them nearly useless.

specifically:
I write a value in the global-scripts-"on_game_start"-function , and silly me expects that any ROOM-script can read from it, addressing the same instance (of the same struct) by the same name, assuming it would get the same prefiously stored parameters.
but no, it reads only zeroes, or even null pointer crashes in array instances of structs as if the array-pointer for the structs instance is a null pointer. otherwise it reads "null/void" values where it clearly should either tell me that this instance is not the same, and just give me the same values i stored from somehwere else in my source code, or that this instance no longer exists. but instead it happily addresses the "shaddow of an instance", and it is possible to write and read from that, and later read from the other instance, both happily sharing the very same instance name of the very same struct (in source code), only being called from different locations/wscripts/functions in source code.
like painting an infinite amount of individual shadows instead of painting the object itself.
#4
i made the misttake to just assume that this, and things like this. would also work in version 3.4.0.5. without a null pointer on runtime, but they dont, leaving this to v 3.4.0.3 i guess. so, what went bad in 3.4.0.5, throwing null pointers on managed structs beiing read or written in in any other structs function?

possibly i initialized it wrongly? no, i tested my own minimal basic managed structs and very simple getter functions, and keep getting null pointers. maybe i am missing someting essential with managed structs?

stuff as simple as
Code: ags

managed struct Managedstruct{ 
int x;
}
struct containsmanagedstruct{
  Managedstruct value;
import ManagedstructGet();
}

void containsmanagedstruct::ManagedstructGet(){
  ms; ms= new Managedstruc;
  int i = this.Managedstruct.x; //gets me a null pointer
}

#5
I have 2 different Structs, they contain (non-writeprotected) parameters/integers, getter and setter functions for them.
Now the second struct wants to access the value stored in one INSTANCE of the fist struct struct, that exists globally and that was instanced before the second struct is defined.

The second struct does that by not using "this." but instead directly addressing an instance of the first Struct (that exists before the second struct is defined). This however does create a new instance of that struct during runtime, and the addressed instance is NOT the same instance as the global instance of the first struct.
The instance referred to from the second Struct's function is instead a new instance that confusingly has the very same name/label in source code but (on runtime) has different memory addresses, without any warning about this during compilation. that second instance with the same label is of course  initialized with 0-vallues and null-pointers, and the (second) struct can use all its functions , change the values of the struct...

Intuitively you would think it would both point at the same single global instance of the struct.

Actually this can easily be confusing and make debugging unnecessarily complicated, since auto-complete does not care and no warning is given.

---

I tested this, and so far my only workaround to have one struct (and any of its instances) access the parameters/values/integers of another Struct- instances ... is to give Structs the ability to copy/load their data to a global array. I already made a struct for that (one for "int) and one for "Character*" (with v3.4alpha-dynamic array in the struct) and any other struct may "extend" on that struct to inherit the ability to copy its values to a global array, so that other Structs can read from it (and copy the data to their instances).
#6
i may possibly miss a function or struct to do this:

- i want to create or remove characters via script (i think that's possible, but pointless if views are as static as i think they are)
- i want to create or remove a view via script, to be addressed similar to a DynamicSprite*
- i want to be able to add or remove an animation from a view via script.
- i want to be able to add or remove a frame from a view via script.

sadly a lot of view-parameters are read-only and so far i can only change the sprite of a views animations frame.

so, unless i am missing something, my resort is to make views that only have 1 frame and 1 animation, and to "repeatedly execute" 40 frames per second for each visible character, calculate and memorie in custom made structs, what sprite to load in that one frame.
i would like do do that, giving me more creative control over animating, and the maths and cases and array-pointers are not THAT complex, but is there not a better solution to change views via script to make them more dynamic?
SMF spam blocked by CleanTalk