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 > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 06-05-2009, 09:30 PM   #1
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

Quote:
Originally Posted by Vexorian
I plan to make onDestroy get called at the moment the index is recycled, though I need to make some changes to jasshelper first...

How about instead of making unnecessary hacks to jasshelper in order to implement a feature that noone needs and noone asked for you do something usefull.

For example find a way for me to declare properties without using textmacros.

Collapse JASS:
//===========================================================================
//  Allowed PII_PROPERTY TYPES are: item, integer, real, boolean, string
//  Do NOT put handles that need to be destroyed here (timer, trigger, ...)
//  Instead put them in a struct and use PII textmacro
//===========================================================================
//! textmacro PII_PROPERTY takes VISIBILITY, TYPE, NAME, DEFAULT
$VISIBILITY$ struct $NAME$
    private static item   array pii_item
    private static $TYPE$ array pii_data
    
    //-----------------------------------------------------------------------
    //  Returns default value when first time used
    //-----------------------------------------------------------------------
    static method operator[] takes item whichItem returns $TYPE$
        local integer pii = GetItemIndex(whichItem)
        if .pii_item[pii] != whichItem then
            set .pii_item[pii] = whichItem
            set .pii_data[pii] = $DEFAULT$
        endif
        return .pii_data[pii]
    endmethod
    
    //-----------------------------------------------------------------------
    static method operator[]= takes item whichItem, $TYPE$ whichData returns nothing
        local integer pii = GetItemIndex(whichItem)
        set .pii_item[pii] = whichItem
        set .pii_data[pii] = whichData
    endmethod
endstruct
//! endtextmacro

Note that property is a pure static struct with parameters, basically a verbatim text copy without side effects, so it should be easier than full struct parameter support.

And it would be much more useful than a stupid module.
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 06-05-2009, 11:29 PM   #2
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

I can't find any good use for properties. For attaching stuff to units or items, you need two things, either simple tagging or things that requires managing. For simple tags, just GetItemId and indexing is more than enough. For complicated things, being able to do cleanup (onDestroy) is better. With this logic, properties become a hybrid that is too costly (textmacros) for simple stuff, and still costly (textmacros + a whole new struct per 'property' ) yet insufficient (lack of onDestroy) for complex things.

Calling onDestroy at the second it is removed is not that necessary (as it will be called when necessary and is enough to prevent leaks), but being able to use this as a remove event listener would be cool, not a priority though. I don't remember what change to jasshelper I needed for it to work, I'll probably need to do the change eventually.

If people need that stuff they can always use that PII stuff. This system does not need to monopolize UserData, so it is perfectly possible to have both things in the same place.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 06-06-2009, 01:22 AM   #3
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

I was not talking only in terms of PUI and PII.

Lets analize what property really is:
It is a static structs only because structs provide operator overloading for [] and []=
So creating a struct is not really needed, just a language construct that is able to:

1. declare arrays
2. declare functions that work with those arrays

And being able to declare arrays is the key feature here, lets face it, the whole reason we have bizzare language constructs like modules and properties is because jass has no dynamic memory.

So basically I am asking for a general memory allocation problem solution.
Collapse JASS:
public property PII
    private item array pii_item
    private TYPE array pii_data
    
    //-----------------------------------------------------------------------
    public operator[] takes item whichItem returns TYPE
        local integer pii = GetItemIndex(whichItem)
        if .pii_item[pii] != whichItem then
            set .pii_item[pii] = whichItem
            set .pii_data[pii] = DEFAULT
        endif
        return .pii_data[pii]
    endoperator
    
    //-----------------------------------------------------------------------
    public operator[]= takes item whichItem, TYPE whichData returns nothing
        local integer pii = GetItemIndex(whichItem)
        set .pii_item[pii] = whichItem
        set .pii_data[pii] = whichData
    endoperator

    //-----------------------------------------------------------------------
    public function SomeFunc takes trigger trig, TYPE whichData returns boolean
        // add something here
    endfunction
        
endproperty

So TYPE and DEFAULT are reserved words inside property but you need to specify only one because DEFAULT can be deducted from TYPE
0 for integer, 0.0 for real, null for handles
(NULL would be a better name for DEFAULT i think)

And the best thing is you would declare it like this:
Collapse JASS:
declare PII as killCounter<integer>
So as you can see the only parameter is TYPE which is great because you can check at compile time if user specified an actuall jass type, no raw text formatting here.
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.

Last edited by cohadar : 06-06-2009 at 01:26 AM.
cohadar is offline   Reply With Quote
Old 06-06-2009, 04:11 AM   #4
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

Well, I was reading this from a netbook so I applied pattern matching on your post and assumed its contents...

Now I am at a real computer. Is this really necessary? Seems a little too specific in application right now and the syntax varies too much...

Reusing an old idea, which I think you've seen before:
Collapse JASS:
struct PII takes type T

     static method operator []= takes item it returns T
             //do stuff
     endmethod

endstruct

type goo extends PII(integer)
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 06-06-2009, 09:15 AM   #5
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

Yes much better, reusing parts of syntax tree = always good idea.

With one small addition:
Collapse JASS:
static struct PII takes type T

     static method operator []= takes item it returns T
             //do stuff
     endmethod

endstruct

type goo extends PII(integer)


Maybe the functioning of this can be best described through error messages:
Code:
* static structs must have type parameter
* static structs can have only static variables
* static structs can have only static methods
* static structs cannot be created/destroyed
* cannot use static struct directly, must instantiate it first

The only thing that is not clear to me is should you be able to do things like this:
Collapse JASS:
static struct PII takes type T

     static method operator []= takes item it returns T
             //do stuff
     endmethod

endstruct

type goo extends PII(integer)

// Data would be responsible for creating it's own maintainance arrays
// but would have the ability to use goo's static variables and methods
struct Data extends goo
endstruct

But when you thing about it, it is just unnecessary complication,
static structs have no use for extending into normal structs because you can simply use them directly from normal struct. (has a in this case is the same as is a)

EDIT:
actually when you think about it, the support for normal static structs should be added first and then the support for parametrized ones.
static struct & static type ?
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.

Last edited by cohadar : 06-06-2009 at 09:23 AM.
cohadar 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 08:41 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