wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 12-14-2009, 12:48 AM   #151
Kueken
User
 
Join Date: Mar 2009
Posts: 149

Kueken will become famous soon enough (41)Kueken will become famous soon enough (41)

Default

Well, there was not any code :P. I did not use any instance of GetUnitId in the map at all, just implemented some systems.
However I wanted to reproduce this, and now this does not happen anymore, so most likely there was another error in the map I did not notice...
Kueken is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 01-01-2010, 11:42 PM   #152
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Updated.
  • Earth-Fury convinced me to bring back IsUnitIndexed, since it is useful to detect dummy units (assuming you filter out all dummy units in your map using the UnitFilter). The new description of the function indicates that this is the intended usage of it.
  • Improved encapsulation by utilizing "private keyword" to prevent calling most of the non-private methods from outside of the library. Also made setIndex private, as it should have been.

Has anyone used AutoStruct yet? It's fun.

Last edited by grim001 : 01-01-2010 at 11:44 PM.
grim001 is offline   Reply With Quote
Old 01-02-2010, 01:18 PM   #153
weaaddar
User


Respected User
 
Join Date: Apr 2002
Posts: 2,372

Submissions (3)

weaaddar has a spectacular aura about (131)

Default

Grim, I looked over the autostruct, and I believe you don't need the thistype data array.

If I understand correctly AutoStruct is automatically created when you create a unit [right?], therefore you can always use use typecast abuse to save array instances [which you should do, as leaner is meaner!].

This abuse saves creating an array, and because of the way this will remove array look ups and sets. As thistype(whatever) actually doesn't translate into any code. It just works.
Collapse JASS:
module AutoStruct
    unit me //The unit that "owns" this struct instance is referred to as "me".
    
    static method operator [] takes unit u returns thistype
        return thistype(GetUnitId(u)) //Return the struct instance associated with the unit.
    endmethod
    
    private static method create takes unit u returns thistype
        local thistype this
            static if thistype.createFilter.exists then //If the createFiler exists...
                if not createFilter(u) then //If the unit fails the createFilter...
                    return 0 //Don't allocate a struct for this unit.
                endif
            endif
            set this = allocate() //Allocate the struct.
            set me = u //Assign the "me" unit of this struct to the entering unit.
            static if thistype.onCreate.exists then //If onCreate exists...
                call onCreate() //Call the onCreate() method for this struct.
            endif
        return this
    endmethod
    //create is private; the user doesn't create AutoStructs. They are created
    //automatically when a unit enters the game and passes the createFilter.
    
    private method destroy takes nothing returns nothing
    endmethod
    //destroy is private; the user doesn't destroy AutoStructs. They are destroyed
    //automatically when their corresponding units leave the game.
    
    private static method destroyer takes unit u returns nothing
        local thistype this = thistype[u] //Get the instance of the struct for this unit.
            if this != 0 then //If it has an instance...
                call deallocate() //Deallocate it, calling onDestroy.
                //set .data[GetUnitId(me)] = 0 since this method is private it can't be called by the outside world. So this line is unneeded.
                set me = null //Null the unit reference.
            endif
    endmethod
    
    private static method onInit takes nothing returns nothing
        call AutoIndex.addAutoStruct(thistype.create, thistype.destroyer)
        //Pass pointers to the create and destroyer functions to AutoIndex, so
        //that it can create/destroy instances as units are indexed/deindexed.
    endmethod
endmodule


At some point I'll sift through AutoIndex and try to find other minor tweaks to do.

edit:: NVM you would have to guarantee that the allocate gives the same value as the index. It should probably, but I don't know if you can gtd that. (you might be able to, or just get rid of allocate and roll your own, as that is what the index is for, you shouldn't need to allocate as you already know the index you want).

Edit 2: Yeah, just do what I do in dictionary, and use the index you get from GetUnitId, avoiding the allocator isn't a bad thing since you explicitly are calling the onCreate and onDestroy methods.

Last edited by weaaddar : 01-02-2010 at 01:31 PM.
weaaddar is offline   Reply With Quote
Old 01-02-2010, 02:55 PM   #154
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by weaaddar
Edit 2: Yeah, just do what I do in dictionary, and use the index you get from GetUnitId, avoiding the allocator isn't a bad thing since you explicitly are calling the onCreate and onDestroy methods.
I can't do it because struct default values won't be initialized for the instance unless I actually call allocate. Also, it's not guaranteed that an instance of the struct exists for that unit due to the createFilter, so it might be nice for it to return 0 in the case that it doesn't...

Quote:
Originally Posted by weaaddar
since this method is private it can't be called by the outside world. So this line is unneeded.
I need to set it to 0. After that unit is removed from the game, it would be possible for another unit to be assigned the same ID by AutoIndex. If the user attempted to retrieve an instance from that unit, it would return the value associated with the previous unit if it were not set to 0 first.

Last edited by grim001 : 01-02-2010 at 03:14 PM.
grim001 is offline   Reply With Quote
Old 01-02-2010, 04:27 PM   #155
weaaddar
User


Respected User
 
Join Date: Apr 2002
Posts: 2,372

Submissions (3)

weaaddar has a spectacular aura about (131)

Default

Are you sure? I thought once a unit was removed GetUnitUserData returned 0 always. I suppose for the HT version that might make sense.

As for the default values can you ask people pretty please to do that in the Create/onCreate methods?
weaaddar is offline   Reply With Quote
Old 01-02-2010, 10:19 PM   #156
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by weaaddar
I thought once a unit was removed GetUnitUserData returned 0 always.
It does, but we're talking about another unit being assigned the same value that the leaving one had. For example:

A unit enters the game. It is assigned ID 8 by AutoIndex. It allocates instance 5 of MyStruct as an AutoStruct and associates it with this unit. Now the unit leaves the game, and instance 8 is destroyed, however, we don't null the association between ID 5 for a unit and instance 8 for MyStruct. Now a new unit enters the game, and gets assigned the ID of 8 by AutoIndex. It doesn't match the createFilter for MyStruct, so an instance is not allocated for it. Now we use MyStruct[newunit] and it would return 8, a destroyed instance of MyStruct, since that was never nulled.

Quote:
Originally Posted by weaaddar
As for the default values can you ask people pretty please to do that in the Create/onCreate methods?
The whole point is that you can treat an AutoStruct just like a normal struct. Making it not call allocate() would also remove the possibility of it working with structs that extend something.
grim001 is offline   Reply With Quote
Old 01-02-2010, 10:21 PM   #157
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

The auto destroy is indeed great, but i can't figure a case where we should allocate a struct on unit creation, i mean imho it would be much more usefull if the user could choice that, with a static constant boolean.
So we could allocate a struct later in the game and don't need to care about unit removing.
Troll-Brain is offline   Reply With Quote
Old 01-02-2010, 10:46 PM   #158
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by Troll-Brain
The auto destroy is indeed great, but i can't figure a case where we should allocate a struct on unit creation, i mean imho it would be much more usefull if the user could choice that, with a static constant boolean.
So we could allocate a struct later in the game and don't need to care about unit removing.

Why worry about creating it if you don't want to worry about destroying it? The struct does not hurt anything by being there before you try to access it. It just means that the retrieval method can be inlined.

If you want to dynamically add or remove instances from the unit during its lifetime, you're looking for UnitListModule. It has auto-destroy, too. AutoStruct is for situations where there is always a 1-to-1 correspondence between the unit and the struct, whereas UnitList is for situations where you might attach many instances to the same unit.
grim001 is offline   Reply With Quote
Old 01-03-2010, 10:11 AM   #159
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

Quote:
Originally Posted by grim001
Why worry about creating it if you don't want to worry about destroying it? The struct does not hurt anything by being there before you try to access it. It just means that the retrieval method can be inlined.
No i worry about destroying, but it's annoying to also manually handle the removing of unit.

Quote:
If you want to dynamically add or remove instances from the unit during its lifetime, you're looking for UnitListModule. It has auto-destroy, too. AutoStruct is for situations where there is always a 1-to-1 correspondence between the unit and the struct, whereas UnitList is for situations where you might attach many instances to the same unit.
I will take a look of it later, but i've understood it must be 1-to-1 here, though.
Troll-Brain is offline   Reply With Quote
Old 01-03-2010, 12:04 PM   #160
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by Troll-Brain
No i worry about destroying, but it's annoying to also manually handle the removing of unit.
I don't understand what this reply means.

Quote:
Originally Posted by Troll-Brain
I will take a look of it later, but i've understood it must be 1-to-1 here, though.
There is no advantage to manually handling creation when the struct instances exist in 1-to-1 correspondence with units. It is just saving you code and hassle, as well as speeding up the retrieval method.
grim001 is offline   Reply With Quote
Old 01-08-2010, 09:36 AM   #161
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

As you know, module initializers are running before ANY OTHER initializer, no matter library requirements.
Even if it's silly to use a TriggerRegisterEnterRegion boolexpr inside a such initializer, you should use it, you already use a struct initializer, so.
The code will just get few extra lines.

Last edited by Troll-Brain : 01-08-2010 at 09:36 AM.
Troll-Brain is offline   Reply With Quote
Old 01-08-2010, 10:56 AM   #162
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

I specifically requested it to be that way so that AutoStruct modules would be able to give their function pointers before AutoIndex's struct initializer runs and creates the auto-structs.

Now I think different priority levels are a bad idea, and I posted this thread to show how I think it should be done.

Of course, if that change went through I would need to make some changes to AutoStruct, but it will still be possible for it to work properly.
grim001 is offline   Reply With Quote
Old 01-08-2010, 03:45 PM   #163
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

Personal note : Never suggest something about grim001's code
Troll-Brain is offline   Reply With Quote
Old 01-16-2010, 11:17 AM   #164
Troll-Brain
User
 
Join Date: Oct 2006
Posts: 1,490

Submissions (1)

Troll-Brain has a spectacular aura about (134)

Default

Plz put the object merger call at the begin of the comment block i'm bored to use search each time i implement AutoIndex on a new map.
Troll-Brain is offline   Reply With Quote
Old 01-20-2010, 04:00 AM   #165
Sinnergy
User
 
Sinnergy's Avatar
 
Join Date: Apr 2009
Posts: 173

Sinnergy has little to show at this moment (8)

Default

I get this message "AutoIndex error: Removed or decayed unit passed to GetUnitId." even my map isn't running in debug mode (I even optimized my map, and played it with warcraft 3 not in new gen).
__________________
Current Project:
Rise of Sinnergy v1.00
Sinnergy is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 09:48 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services