ZScript dynamic array suggestions

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

ZScript dynamic array suggestions

Post by Nash »

1) Pass arrays into functions directly.

2) Array sorting (preferably a fast algorithm that's not bubble sort cuz that's quite slow when dealing with thousands of items).

3) Count how many occurrences of something specific is in the array.

Thanks!
User avatar
Sarah
Posts: 551
Joined: Wed Sep 06, 2006 12:36 pm
Preferred Pronouns: She/Her
Operating System Version (Optional): Debian 11 (bullseye), Windows 10
Location: Middle of Nowheresville Il.
Contact:

Re: ZScript dynamic array suggestions

Post by Sarah »

For suggestion 1, I'm a bit surprised this isn't already possible. If I'm stuck with just arrays, Z-Windows will need this in order to process groups of elements; from reading the page on pointers it doesn't appear I can create linked lists which is a bit of a downer. Be nice to have this and actual *pointers.

This page gives a nice overview of the various sorting methods out there. My vote would be on a merge sort as the time complexity seems to remain fairly constant with large arrays. Basically sorting often results in O(n^2) for a worst case scenario regardless of algorithm. I think what I would do, if I knew my arrays were likely to contain thousands of items, I would implement some sort of pre-sorting as part of array insertion.

Counting occurrences is probably doomed to be a linear method. If you could pass the array into a method it wouldn't be hard to implement in your own code.
User avatar
Nash
 
 
Posts: 17433
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: ZScript dynamic array suggestions

Post by Nash »

Passing dynamic arrays around is currently VERY hacky; you make a "wrapper" class declaring your dynamic array in there, then pass the array by doing

Code: Select all

class WrapperClass
{
    Array<someType> contents;
}

let arr = new("WrapperClass");
arr.contents[i] = whatever;
 
I mean, do-able but as I said, hacky and makes code harder to read and maintain.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript dynamic array suggestions

Post by Graf Zahl »

It's a known issue biut not easy to fix because the VM doesn't know anything about array references.
Post Reply

Return to “Feature Suggestions [GZDoom]”