Closed lainv0hndyrec closed 5 years ago
Great. I'm loving the idea (have been wanting to have a nice, generalized, and extensible 2D array myself.. Here are some suggestions:
It should probably be an object extending Reference
since that is what Array
and Dictionary
extend from.
For maximum generalization, I'd probably go with the Array2D
name personally, but I'm open to other suggestions if people are interested in Grid
or some other title.
Because scripts cannot directly extend either Array or Dictionary, we won't be able to automatically pick up the [] operator associated with them. We'll instead have to have actual functions for getter and setter at particular indices. My first thought would be to have at(int, int)
and atv(Vector2)
for getters with put(int, int, Variant)
and putv(Vector2, Variant)
for setters. For this same reason, we'll also likely have to make the actual ArrayArray2D
object that just isn't exposed to scripting, perhaps called _data
?
I would recommend adding a scripting-exposed member property called comparator
which will just rely on duck-typing to be any object with a .compare(Variant a, Variant b)
function. If set to null (the default value), the typical comparison operators will be used on the subjects of the Array. If a comparator
is given however, then it will be responsible for returning a negative, 0, or positive value from compare
to determine comparison resolution during any sorts.
it's probably better for the sort methods to allow the user to specify whatever range they want, so...
// Array2D.cpp Array2D& Array2D::sort_column(int p_start = 0, int p_end = -1, p_asc = true) { ... } Array2D& Array2D::sort_row(int p_start = 0, int p_end = -1, p_asc = true) { ... }
resize sounds fine. I don't think that would be too difficult to implement if the _data
is simply an Array of Arrays, we can just call their respective resize
functions.
I also think the shuffle methods are a good idea, although I would also use the same range specifier parameters I mentioned earlier for the sort methods. Great idea for the Rect2 concept! I hadn't thought of that possibility, but that would allow for some really cool manipulations...
Continuing on from that though, perhaps we should also have a function for sub_array2d
that could return a duplicate of the data within a Rect2 area. I imagine that could also be useful.
Note that I'm actually rather inexperienced with owning the repositories that people use to update things with, so bear with me. I believe that the work-in-progress content probably shouldn't be in the host repo, so you might want to fork the godot-data-structures repository and then use that location for the main development of this project. I'm busy spending my days on some other plugins at the moment, so I can't just implement the whole thing myself.
Are you familiar with GDNative and/or C++ at all?
hi sorry for the super late reply, just got homd from a "no technology" vacation
unfortunatly im am unexperienced with GD native nor C++, i tried to learn C++ back in my HS days and pretty much forgot every aspect of it.
but i do have C# experience.
i really like everything youve posted and i do agree that we cant instantiate the Array2D as just [].
btw before i used Godot, i used GameMaker Studio and they have this Grid Data Structure.
here is the like:
https://docs.yoyogames.com/source/dadiospice/002_reference/data%20structures/ds%20grids/index.html
almost all functionalityis pretty spot on in here.
having it as an extend from Reference makes much more sense and havinv it in godot will be super great.
btw ill try to learn GD native and learn the ropes from tutorials.
also just a side note i created a project that uses Array2D for collision checks and it was faster than using the engines collision checks. the only downside is that it needs all collisions shape to be the same or divisible by the smallest collision shape.
I think this repository is more or less obsolete since I've started creating non-Node types in my godot-next repository. In fact, there is already an Array2D implementation over there. I'm probably just going to delete this entire repository.
hi, i would like to propose the addition of 2D Array as an Object just like Array is
if it will be an Object in Godot, here are some of its functions that i would like to propose
Array2D.sort_column(int,bool) #int = number of column, 0 is the start. bool = true if ascending order sort the Array 2D accorring to the column selected
Array2D.sort_row(int,bool) #int = number of row, 0 is the start. bool = true if ascending order sort Array 2D accourding to the row selected
Array2D.resize(int width, int height, value optional) #int width = width of the array 2d 0 means none, int height = height of the array 2d 0 means none, value optional = optional input value which sets all cell to that value this resizes the 2d array, it the resize value is greater then cells are added, if lesser than the one created then it will delete some cells together with its values. if value optional has a value then it replaces all values in the cell with the inputed one
Array2D.shuffle(Rect2(optional)) #Rect2 is the extents of the grid that you want to shuffle shuffles all the content of 2d array
Array2D.shuffle_column(optional first,optional last) #optional first = where to start, optional last = the extent shuffles the column of 2d array
Array2D.shuffle_row(optional first,optional last) #optional first = where to start, optional last = the extent shuffles the row of 2d array
i do understand that some of these can be done via code or using sort_custom of Array Object but a little bit of QoL improvements wouldn't hurt Godot. here are just some. really love Godot and this is what i think it lacks (as well as Batching)