Login
Register
Menu
Home
Forum
JassDoc
Types
Functions
Variables
Help
Chat
Media
Search
Search posts
WC3 JASS.com
"The Jass Vault" plus vJASS and Zinc
WC3 Modding Information Center
Forum
Warcraft (WC3) Modding
Warcraft III Resources
Warcraft III Spells and Systems
Codes & Snippets
TimedLoop
Warcraft III:
Maps
Models
Skins
Icons
Spells / Systems
Tools
Tutorials
Snippets
JASS vJASS Spells and Systems
Tutorials
Chat @Discord
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation
-
Zinc documentation
-
WC3 Optimizer documentation
TimedLoop
Codes & Snippets
Started by
moyack
Views
1418
Replies
0
Users
1
1
Pages:
1
Go Down
0 Members and 1 Guest are viewing this topic.
Vexorian
Recognized User
Posts:
5
WC3 Models: 0
WC3 Tutorials: 0
WC3 Tools: 0
WC3 Maps: 0
WC3 Skins: 0
WC3 Icons: 0
WC3 Spells: 0
Reputation:
100
Free Software Terrorist
TimedLoop
on:
February 18, 2012, 05:59:47 AM
Category:
Execution
Language:
vJASS
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.
Usage sample
Code: jass
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..
The code:
Code: jass
library
TimedLoop
//********************************************************
//* TimedLoop
//* ---------
//*
//* Requires jasshelper 0.9.G.1 or greater.
//*
//* A library + module that are meant to make those
//* array + timer loops easy, yet still faster than
//* other alternatives meant to be easy (In other words
//* no TriggerEvaluate is involved).
//*
//* The OOPness is interesting.
//*
//* Before implementing TimedLoop
//* your struct needs an onTimedLoop method that takes
//* nothing and returns boolean, if the method
//* returns false, the instance will get removed
//* from the loop and destroyed, else it will continue,
//* think of it as if the call asks the method a
//* question: "Should I continue the loop afterwards?"
//*
//* Alternatively, if you are not convinced, you may
//* use the TimedLoop_CONTINUE and TimedLoop_STOP
//* constants in the method's returns.
//*
//* After implementing TimedLoop, you can call
//* the startTimedLoop method to add the periodic event
//* to that instance, only call it once per instance.
//*
//* I recommend to call implement just bellow the
//* declaration of the onLoop method, else it will
//* actually use TriggerEvaluate, which is lame. Remind
//* me to implement a topsort in jasshelper.
//*
//* If you feel the need to destroy the struct outside
//* the loop, well, you'll have to add a flag to it so
//* you send a message to onLoop to make it return false.
//* A more complicated module to allow that easily would
//* come later.
//*
//********************************************************
//========================================================
// config:
globals
public
constant
real
PERIOD = 0.025
// A lower value and everything using the module will
// look better, yet performance will drop.
endglobals
//========================================================
// implementation:
//
globals
public
constant
boolean
STOP =
false
public
constant
boolean
CONTINUE =
true
endglobals
//===========================
module
TimedLoop
// god bless private module members.
//
private
static
thistype
array
V
// The array
private
static
integer
N = 0
// The count
private
static
timer
T =
null
// the timer, one per
// struct that implements this
private
static
method
onExpire
takes
nothing
returns
nothing
local
integer
n = 0
local
thistype
this
// yay for odd-sounding syntax constructs
local
integer
i = 0
loop
exitwhen
(i==
thistype
.N)
set
this
= .V[i]
if
(
this
.onTimedLoop() == CONTINUE )
then
set
.V[n] =
this
set
n=n+1
else
call
this
.destroy()
endif
set
i=i+1
endloop
set
thistype
.N = n
if
(n== 0)
then
call
PauseTimer
(.T)
endif
endmethod
public
method
startTimedLoop
takes
nothing
returns
nothing
set
.V[.N] =
this
set
.N=.N + 1
if
(.N == 1)
then
if
(.T ==
null
)
then
set
.T =
CreateTimer
()
endif
call
TimerStart
(.T, PERIOD,
true
,
function
thistype
.onExpire)
endif
endmethod
endmodule
endlibrary
«
Last Edit: December 23, 2017, 12:55:19 PM by moyack
»
Print
Pages:
1
Go Up
« previous
next »
WC3 Modding Information Center
Forum
Warcraft (WC3) Modding
Warcraft III Resources
Warcraft III Spells and Systems
Codes & Snippets
TimedLoop
PortaMx-SEF 1.54
|
PortaMx © 2008-2015
,
PortaMx corp.
Search
Username
Password
Always stay logged in
Forgot your password?