In case you guys don't know, I like to find solutions to strange problems. In Warcraft 3 I was developing a library to that used psuedo-units that linked to unit-groups to provide theoretically unlimited selection sizes. It worked in theory, but there was no way to detect units in the selection box so I had to give up the project.
This time I want to tackle local dynamic arrays. Global dynamic arrays are essentially impossible, but I theorize I could create local dynamic arrays using functions to control array declarations and strings of variables linked together, but I'm not sure. What it would consist of is a bunch of single variables that get linked together in a chain then get passed into an array with the defined size (or if thats not possible, the arrays would be controlled by functions entirely). When the size gets changed, the old array would be scrapped and a new array would have the data fed into it (if the arrays are not controlled by functions).
What do you guys think about this? Is it possible? Useful? Already implemented? (I haven't checked)
If people think that this is actually an achievable goal, then I'll start working on it as soon as next week to complement the Generation System I am working on. However, I am notorious of starting projects and leaving them unfinished, but I'll see what I can do. I also have college classes starting monday, but I'd really like to tackle this problem. I believe vJASS for Warcraft 3 tackled this problem so I'm hoping I can tackle this problem.
@TheSecretArts: Go
I'll assume you're talking about actual code here and not galaxy editor macros since you posted this in the galaxy scripting section.
Global dynamic arrays wouldn't be any less feasible than local arrays, the issue is just implementation and performance.
We can only allocate arrays using a constant size, so doing it the old fashioned way allocating an array with capacity and position then growing that array as elements are added beyond it's capacity is not possible.
So that leaves using something like a CVS to hold the values, which is defiantly not optimal for performance.
So yes it is possible altough the backend will have to be implemented as a completely different type of data store, in which case you might want to expose the semantics of that data store instead.
If it is useful, well I can't say that I've come across a scenario where I actually needed it. When I do, I go back and check what would be local to implement as game objects (units, behaviours etc) which in most cases works out better than it would be when handled by triggers.
That's just my opinion tho, If someone can bring a scenario to the table where dynamic allocation is needed, please do :)
I'm not too sure about global dynamic arrays just because I haven't really flushed out the idea on how it would even work. Globals have to be declared at the beginning of code and cannot initially be set by a function as I know it.
local dynamic arrays just seem to be a more easier problem to tackle due to the simple nature of declaring globals.
I'll see what I can do, it's just a fun challenge for me.
There is no difference between how you declare a local variable vs a global, only the scope differs.
Even with a local array, you need a constant size, i.e a literal value or a constant defined as a literal value.
You can use the bank as a dynamic allocation, thats the only collection of variable size that i'm aware of. It is essentially a dictionary that is saved to a file, when you say to.
But you need to be careful when using banks for dynamic storage to not save them or you junk up the bank directory like crazy. If the map saves and loads data from previous plays, and you also want to use a bank as a form of "Session" dictionary, then set the banks to a global variable at map init.
Going from memory here, So correct me if I'm wrong but in Andromeda you actually allocate a large pool which defeats the whole purpose of having dynamic allocation.
But please, feel free to specify the implementation details.
@caspersc:
That is the way any program works. It allocates a large pool, called the heap, and then allocates from there. This is true of C, Java, etc... The size of the pool can be set at compile-time by the user to meet the program's needs.
What exactly do you mean by dynamic arrays? Do you mean an array that you can resize such as array[0-10] and instead resize its dimensions to array[0-3] at run time?
From my understanding you cant really do this but why bother. Just set the array for the max size you ever intend to use and leave it be.
That may not be very good on memory, but whats it matter. SC2 aready runs at 2gig of ram on my box at home. Good thing I have 8gigs of ram huh.
Or you can also store arrays in strings. Since an array is basically a string(or a string is an array meh). There is support in the built in string operations for "Get Word From String" I have made use of this and it works very well.
I see up above people talking about Local VS Global arrrays. If you want the data available out side your current scope make a global.... other wise use a local.
If you really need a dynamic array at run time I suggest using String manipulation at run time you might be supprised by what you can do.
He doesn't search for a way to reduce the memory requirements of SC2 by a mb or two - but SC2 has a maximum allocation limit of about 2.5 MB. If the amount of variables in your map exceed that.. well you're fked.
Theres actually like a 2 mb limit on the combined size of a maps scripts and variables or something like that.
The purpose of this is just to make memory allocation more effective for maps and systems that need to store unpredictable amounts of data effectively.
Edit: Plus the use of game caches doesn't count towards the variable limit which allows for storing larger arrays in theory.
What the hell are you doing to exeed 2.5 MB of data.... In variables?
So Say I have a whole bunch of data i need explosed globally
and i Make a StringArray[0-20][0-100] and you can basically make inner array within the string variable indexs in this array. Your telling me you cant do this and keep your data under 2md.
How could you possibly have that much data for a map...?
Does anybody know what max string size is ?
Does anybody know how many strings with max string size it takes to crash the game?
I also make use of splitting strings with the word functionality, but its probably one of the slower ways of accessing data. You're parsing a string everytime you're fetching a value, and in that its only a very slow 1d array.
Just use the bank for dynamic sizes. Its a data table / dictionary, they're fast and, I think, more powerful because you can access values by name.
You can also technically pass a collection of values by section name now that I think about it...
edit: bolded a profound realization.. iit i might be able to pass collections and objects by using section names, accessible in a way similar to how you access attributes in jQuery...
Considering the Trigger system is slow in any real time situation what does it matter if it takes a bit more power to parse a string then getting a variable from an array. IMO CPU's handle all the heavy lifting and its hardly noticable to the end user.
So far ive found that any attempt to run a trigger in Real time bassically Lags teh hell outta the game. ie, this is why everybody complains about wasd movement.
So considering your fetching data on a non-realtime basis. what does it matter if it takes .00001 seconds longer?
Can you possibly give us a screen shot of accessing and manipulationg the Bank From triggers? I mean with out the GE scripting stuff I mean just the actions available.
In case you guys don't know, I like to find solutions to strange problems. In Warcraft 3 I was developing a library to that used psuedo-units that linked to unit-groups to provide theoretically unlimited selection sizes. It worked in theory, but there was no way to detect units in the selection box so I had to give up the project.
This time I want to tackle local dynamic arrays. Global dynamic arrays are essentially impossible, but I theorize I could create local dynamic arrays using functions to control array declarations and strings of variables linked together, but I'm not sure. What it would consist of is a bunch of single variables that get linked together in a chain then get passed into an array with the defined size (or if thats not possible, the arrays would be controlled by functions entirely). When the size gets changed, the old array would be scrapped and a new array would have the data fed into it (if the arrays are not controlled by functions).
What do you guys think about this? Is it possible? Useful? Already implemented? (I haven't checked)
If people think that this is actually an achievable goal, then I'll start working on it as soon as next week to complement the Generation System I am working on. However, I am notorious of starting projects and leaving them unfinished, but I'll see what I can do. I also have college classes starting monday, but I'd really like to tackle this problem. I believe vJASS for Warcraft 3 tackled this problem so I'm hoping I can tackle this problem.
@TheSecretArts: Go
I think you can do it. And with the custom grammar feature in GUI, it can be imitated as close to the array there as possible
@TheSecretArts: Go I'll assume you're talking about actual code here and not galaxy editor macros since you posted this in the galaxy scripting section.
Global dynamic arrays wouldn't be any less feasible than local arrays, the issue is just implementation and performance. We can only allocate arrays using a constant size, so doing it the old fashioned way allocating an array with capacity and position then growing that array as elements are added beyond it's capacity is not possible.
So that leaves using something like a CVS to hold the values, which is defiantly not optimal for performance.
So yes it is possible altough the backend will have to be implemented as a completely different type of data store, in which case you might want to expose the semantics of that data store instead.
If it is useful, well I can't say that I've come across a scenario where I actually needed it. When I do, I go back and check what would be local to implement as game objects (units, behaviours etc) which in most cases works out better than it would be when handled by triggers.
That's just my opinion tho, If someone can bring a scenario to the table where dynamic allocation is needed, please do :)
OK, I'll see what I can do.
I'm not too sure about global dynamic arrays just because I haven't really flushed out the idea on how it would even work. Globals have to be declared at the beginning of code and cannot initially be set by a function as I know it. local dynamic arrays just seem to be a more easier problem to tackle due to the simple nature of declaring globals.
I'll see what I can do, it's just a fun challenge for me.
There is no difference between how you declare a local variable vs a global, only the scope differs. Even with a local array, you need a constant size, i.e a literal value or a constant defined as a literal value.
I guess. I just wish that blizzard would allow us to create custom types or structs. That would make everything a lot easier.
@TheSecretArts: Go
structs are available in galaxy, syntax is the same as in C.
@caspersc: Go
oh damn. Did not know that! Show how much I pay attention. Thank you very much. Now I just gotta brush on a C syntax.
By any chance do you know if methods are supported?
You can use the bank as a dynamic allocation, thats the only collection of variable size that i'm aware of. It is essentially a dictionary that is saved to a file, when you say to.
But you need to be careful when using banks for dynamic storage to not save them or you junk up the bank directory like crazy. If the map saves and loads data from previous plays, and you also want to use a bank as a form of "Session" dictionary, then set the banks to a global variable at map init.
Then instead of using (Last opened bank) for everything, use the variables.
Now make some accessor methods for your "Session" bank and use it like an asp.net Session data dictionary.
Unfortunately theres no overloading a function in galaxy so you have to specify the type to store and get data back.
I figured I would have to use the bank, it's the most logical choice for storing data at will with a random size.
I have already implemented dynamic arrays in Andromeda, a Galaxy language extension made by geX. To learn more, go to http://sc2mod.com/board/index.php?page=Thread&threadID=13.
Also, structs are useless, since they cannot be passed as arguments or returned. Before, you could use pointers, but those were removed.
@XPilot: Go
Going from memory here, So correct me if I'm wrong but in Andromeda you actually allocate a large pool which defeats the whole purpose of having dynamic allocation.
But please, feel free to specify the implementation details.
@caspersc:
That is the way any program works. It allocates a large pool, called the heap, and then allocates from there. This is true of C, Java, etc... The size of the pool can be set at compile-time by the user to meet the program's needs.
What exactly do you mean by dynamic arrays? Do you mean an array that you can resize such as array[0-10] and instead resize its dimensions to array[0-3] at run time?
From my understanding you cant really do this but why bother. Just set the array for the max size you ever intend to use and leave it be.
That may not be very good on memory, but whats it matter. SC2 aready runs at 2gig of ram on my box at home. Good thing I have 8gigs of ram huh.
Or you can also store arrays in strings. Since an array is basically a string(or a string is an array meh). There is support in the built in string operations for "Get Word From String" I have made use of this and it works very well.
I see up above people talking about Local VS Global arrrays. If you want the data available out side your current scope make a global.... other wise use a local.
If you really need a dynamic array at run time I suggest using String manipulation at run time you might be supprised by what you can do.
@TheSecretArts: Go
I think your best bet is to use a Data Table or, if you want, a bank.
PS: we can also declare custom types in Galaxy (typedef <type> <name>).
PPS: Structs don't allow methods.
@SouLCarveRR: Go
He doesn't search for a way to reduce the memory requirements of SC2 by a mb or two - but SC2 has a maximum allocation limit of about 2.5 MB. If the amount of variables in your map exceed that.. well you're fked.
@SouLCarveRR: Go
Theres actually like a 2 mb limit on the combined size of a maps scripts and variables or something like that.
The purpose of this is just to make memory allocation more effective for maps and systems that need to store unpredictable amounts of data effectively.
Edit: Plus the use of game caches doesn't count towards the variable limit which allows for storing larger arrays in theory.
@s3rius: Go
What the hell are you doing to exeed 2.5 MB of data.... In variables?
So Say I have a whole bunch of data i need explosed globally
and i Make a StringArray[0-20][0-100] and you can basically make inner array within the string variable indexs in this array. Your telling me you cant do this and keep your data under 2md.
How could you possibly have that much data for a map...?
Does anybody know what max string size is ?
Does anybody know how many strings with max string size it takes to crash the game?
Well it starts becoming a problem when you start using large parallel arrays and complicated maps with a lot of data and scripting.
@SouLCarveRR: Go
I also make use of splitting strings with the word functionality, but its probably one of the slower ways of accessing data. You're parsing a string everytime you're fetching a value, and in that its only a very slow 1d array.
Just use the bank for dynamic sizes. Its a data table / dictionary, they're fast and, I think, more powerful because you can access values by name.
You can also technically pass a collection of values by section name now that I think about it...
edit: bolded a profound realization.. iit i might be able to pass collections and objects by using section names, accessible in a way similar to how you access attributes in jQuery...
@Hokibukisa: Go
Considering the Trigger system is slow in any real time situation what does it matter if it takes a bit more power to parse a string then getting a variable from an array. IMO CPU's handle all the heavy lifting and its hardly noticable to the end user.
So far ive found that any attempt to run a trigger in Real time bassically Lags teh hell outta the game. ie, this is why everybody complains about wasd movement.
So considering your fetching data on a non-realtime basis. what does it matter if it takes .00001 seconds longer?
Can you possibly give us a screen shot of accessing and manipulationg the Bank From triggers? I mean with out the GE scripting stuff I mean just the actions available.