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 04-16-2009, 01:39 PM   #1
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 TimedLoop

All right, after the PeriodicLoopModule failure, this is a simpler version that is less flexible but should work, it is for structs that are exclusive for looping and will conflict with stuff that require you not to call .destroy but another method.

It is a module you implement in a struct to do the whole array+loop thing that we always do in spells. Only that this time you won't have to code it all the time... an example:

Only disadvantage against doing the loop manually is that it will do a function call (not TriggerEvaluate) for each instance in the loop. Differences with things like TT is the OOPness and the lack of TriggerEvaluate, though it uses a timer per struct type, wonder if that's important.


Collapse Usage Sample:
struct moveUnit

    unit u

    //=====================================================
    // You need to code an onTimedLoop method before
    // implementing the module.
    //
    private method onTimedLoop takes nothing returns boolean
        //instance's timer expired:
        // This will just move a unit's x coordinate with
        // a speed of 100 until it reaches 5000.0

        call SetUnitX(u, GetUnitX(u) + 100.0* TimedLoop_PERIOD )
        // notice the use of the TimedLoop_PERIOD constant
        // since it may be tweaked by the user...


        if ( GetUnitX(u) >= 5000) then
            return TimedLoop_STOP
        endif

     return TimedLoop_CONTINUE

     //You are free to/should use false and true instead of the
     //constants.
    endmethod

    implement TimedLoop //This does the module magic

    static method create takes unit u returns moveUnit
     local moveUnit m= moveUnit.allocate()
        set m.u = u
        call m.startTimedLoop() //The module works by
        // creating a startTimedLoop method that will
        // do all the dirty work and end up calling
        // .onTimedLoop...
        //
     return m
    endmethod

endstruct
//call moveUnit.create(GetTriggerUnit()) and see...

Names are now finished..

Expand thecode:
__________________
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
Sponsored Links - Login to hide this ad!
Old 04-16-2009, 03:06 PM   #2
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

Function calls with no parameters are pretty fast, I have heard around as fast as using trig functions, and my physics engine has managed to use hundreds of them per second without lagging. People should get over the fear of using something like this for spell development.

You could get around the one timer per struct-type problem by using a single public timer in the library. You would also need a new integer in the library that keeps track of the total instances using the timer so you know when to start/stop it. I did something like that in UnitList with a public trigger that each struct-type just adds an action to.

I vote "LoopModule" for the name; everyone is naming their module libraries SomethingModule, just like when every new game for the Nintendo 64 ended with "64".
grim001 is offline   Reply With Quote
Old 04-16-2009, 03:12 PM   #3
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

The function call actually has a single "this" argument.

PeriodicModule ? LoopModule sounds like a way to make it easy to loop through the instances of a struct anywhere. This is focused on timers.
__________________
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 04-16-2009, 03:18 PM   #4
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

OK, it compiles to have one argument (I am sleepy), it's still very fast.

Since your main function name is "startLoop," LoopModule kind of fits, but it would make more sense to call it PeriodicModule and rename the method to startPeriodic.
grim001 is offline   Reply With Quote
Old 04-16-2009, 06:09 PM   #5
C2H3NaO2
User
 
Join Date: May 2008
Posts: 80

C2H3NaO2 is on a distinguished road (17)

Default

I don't like having a fixed period. In my opinion it would be the better choice, to force the user to define a static constant real in ever struct using this.
In movement stuff your constant may be the right choice, but for example in my buff system 0.25 is enough or sometimes it want to move something not i a smooth way.
A feature for optimal overwriting of something from modules would be nice :)
C2H3NaO2 is offline   Reply With Quote
Old 04-16-2009, 06:17 PM   #6
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

What's NOT_IN_LOOP for?

It would help understanding if the post better conveyed which part is the module and which part is the example. Perhaps add some @@ highlights to the example?

The module is very specific. I could see other uses for a list of all structs besides looping through them periodically (although that is the most common use and doing that alone is certainly justification enough for a module), could perhaps the list be one module and the timerloop another module that uses the list?
__________________
Anitarf is offline   Reply With Quote
Old 04-16-2009, 08:32 PM   #7
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

Quote:
could perhaps the list be one module and the timerloop another module that uses the list?
a general purpose list is complicated to implement and requires a lot more code than that and safe guards. Yet such list module already exists and grim made two of them.

I like this module because of being so specific, most of my spells really only need a single loop.
__________________
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 04-16-2009, 09:47 PM   #8
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

Collapse JASS:
//* nothing and returns boolean, if the method
//* returns false, the instance will get removed
//* from the loop and destroyed.
Do you have to be an ass?
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.

Last edited by cohadar : 04-16-2009 at 09:48 PM.
cohadar is offline   Reply With Quote
Old 04-20-2009, 02:10 PM   #9
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

Quote:
Originally Posted by cohadar
Collapse JASS:
//* nothing and returns boolean, if the method
//* returns false, the instance will get removed
//* from the loop and destroyed.
Do you have to be an ass?
????? Not sure why are you being so aggressive against those comments.

Ok, grim onLoop is a bad name for that method anyway. will have to think of a new name for the method and module.
__________________
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 04-21-2009, 10:37 AM   #10
dead_or_alivex
User
 
Join Date: Jun 2008
Posts: 72

dead_or_alivex has little to show at this moment (3)

Default

I remember cohadar saying something about how a true return signaling that an instance should be removed from a loop has become a standard. Also, a true return is what you use in TT.

Personally I've always used false returns, in my own systems. Somehow it seems more intuitive. But yeah, it's a minor thing...
dead_or_alivex is offline   Reply With Quote
Old 04-21-2009, 11:21 AM   #11
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 say that the boolean is for whether the loop should keep running. False = remove it from the loop.
grim001 is offline   Reply With Quote
Old 04-21-2009, 11:39 AM   #12
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,375

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

Periodic - True
Not - False

Standard established by Blizzard has been there far longer and used by everyone who uses timers directly.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 04-21-2009, 11:51 AM   #13
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

The boolean that's returned isn't an argument for starting a timer, it's an argument for whether it should continue or not.
grim001 is offline   Reply With Quote
Old 04-21-2009, 05:10 PM   #14
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,375

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

Quote:
Originally Posted by grim001
The boolean that's returned isn't an argument for starting a timer, it's an argument for whether it should continue or not.

It's the same principle, so it makes no sense to flip it, as you could have it as a return as to whether to stop it or not, but stopping it is more negative than positive.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 04-22-2009, 10:42 PM   #15
Strilanc
User
 
Strilanc's Avatar
 
Join Date: Jun 2007
Posts: 917

Submissions (4)

Strilanc has a spectacular aura about (131)

2008 Spell olympics - Fire - Gold

Default

You should return an enum (an integer, with some public constants). Nobody disagrees about what RET_REMOVE and RET_KEEP mean.
__________________
Don't pay attention to this signature, it's self-contradictory.
Strilanc 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 04:25 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