| 07-22-2007, 10:58 AM | #1 |
Sup, I have a question for you Well, to whoever reads this thread... What does struct.create() and struct.destroy() really do? I really need to find that out, it determines if my system will work or fail miserably. And also, can I use a H2I call for struct indexes? Like for example JASS:function vJASS takes nothing returns nothing local unit u = GetTriggerUnit() local integer i = CS_H2I(u) local structdata dat = structdata(i) //I Still don't know what struct.create() really does |
| 07-22-2007, 12:02 PM | #2 |
This is the relevant generated code (with a few extra comments), if that helps you at all... JASS:globals integer array si__STRUCTNAME_V integer si__STRUCTNAME_F = 0 integer si__STRUCTNAME_I = 0 endglobals //pointer.destroy() function s__STRUCTNAME_destroy takes integer this returns nothing if this==null then return elseif (si__STRUCTNAME_V[this] != -1) then return endif set si__STRUCTNAME_V[this] = si__STRUCTNAME_F set si__STRUCTNAME_F = this endfunction //STRUCTNAME.create() function s__STRUCTNAME__allocate takes nothing returns integer local integer this = si__STRUCTNAME_F if (this != 0) then set si__STRUCTNAME_F = si__STRUCTNAME_V[this] else set si__STRUCTNAME_I = si__STRUCTNAME_I + 1 set this = si__STRUCTNAME_I endif if (this > 8190) then return 0 endif //ints all the variables in the struct, if you set them to something inside the struct set si__STRUCTNAME_V[this]= -1 return this endfunction function something takes nothing returns nothing local STRUCTNAME pointer = STRUCTNAME.create() //local integer pointer = s__STRUCTNAME__allocate() call pointer.destroy() //call s__STUCTNAME_destroy(pointer) endfunction |
| 07-22-2007, 12:05 PM | #3 |
You could make a blank file with a struct, save it and then export and open the map's .j file to see what kind of Jass got generated and how structs actualy work. Essentialy, a struct type is a bunch of paralel arrays and each index in those arrays is one struct. Whenever you call struct.create() it will alocate an index for you to use and whenever you call struct.destroy it will release that index, allowing it to be allocated again later. This is important because array only go up to index 8191 so if you didn't destroy structs which you no longer needed and kept creating new ones then you would eventualy run out of room for them. |
| 07-22-2007, 12:07 PM | #4 |
Thanks!!!!! So the first index of a struct is 1 not 0, that greatly helps. Reppy + <3 |
| 07-22-2007, 01:21 PM | #5 |
JASS:function vJASS takes nothing returns nothing local unit u = GetTriggerUnit() local integer i = CS_H2I(u) local structdata dat = structdata(i-0x100000) |
| 07-22-2007, 09:37 PM | #6 |
JASS:local structdata dat = structdata(ModuloInteger(i,8191)) |
| 07-23-2007, 04:15 AM | #7 |
I'd just love to see a world in which we don't have to face arbitrary array size limits and stuff like that. I am not sure if a collision is better than a thread crash, well let people decide between undefined code and crashing code! awesome. |
| 07-23-2007, 07:30 AM | #8 | |
Quote:
|
| 07-23-2007, 10:31 AM | #9 |
i will chop myself in half if i understand what u aliens talk about XD |
| 07-23-2007, 01:34 PM | #10 |
After so many C++ coding I found myself alergic to undefined code, although I guess that if there was a way to detect collisions it would be a good method... |
| 07-23-2007, 05:03 PM | #11 |
Vexorian well it can be used in linked arrays... so it will collide only after 32K for example... (4 arrays needed) and to 32K it's really hard ^^ in normal maps. + vJass preprocesor allows simple create such linked arrays in masses. so it's very cool =) |
