- Joined
- Aug 3, 2008
- Messages
- 2,345
I dunno if this is useful to anyone - it's basically a system which does the indexing of structs, in order to make MUI spells, for you. Anyway, here it is:
To use it, you simply run the textmacro above your spell scope with the name of your spell and whatever FPS you want, for example:
Now you need a data struct which extends TimerLoop and contains a method called "Loop", for example:
To start the spell, you simply do:
I hope this helps some people. The difference in efficiency between using this system and coding the entire indexing system yourself should be menial. I personally think that this system is by far easier to use and more logical than coding the system yourself.
JASS:
library TimerSystem
struct TimerLoop
boolean stop = false
stub method Loop takes nothing returns nothing
endmethod
endstruct
endlibrary
//! textmacro TimerSystem takes NAME, FPS
library TimerSystem_$NAME$ uses TimerSystem
private keyword Data
globals
private real FPS = $FPS$
private timer tim = CreateTimer()
private Data array dat
private integer index = 0
endglobals
private function Execute takes nothing returns nothing
local integer i = 0
loop
exitwhen i >= index
call dat[i].ac.Loop
if dat[i].ac.stop then
call dat[i].destroy()
endif
set i = i + 1
endloop
endfunction
private struct Data
TimerLoop ac
integer ID
method create takes TimerLoop ac returns Data
local Data d = Data.allocate()
set d.ac = ac
set dat[index] = d
set d.ID = index
if index == 0 then
call TimerStart(tim, 1./FPS, true, function Execute)
endif
set index = index + 1
return d
endmethod
method onDestroy takes nothing returns nothing
call ac.destroy()
set index = index - 1
set dat[.ID] = dat[index]
set dat[.ID].ID = .ID
if index == 0 then
call PauseTimer(tim)
endif
endmethod
endstruct
function $NAME$_Start takes TimerLoop ac returns nothing
call Data.create(ac)
endmethod
endlibrary
//! endtextmacro
To use it, you simply run the textmacro above your spell scope with the name of your spell and whatever FPS you want, for example:
JASS:
//60 FPS for smooth movement
//! runtextmacro TimerSystem ("StormBolt", "60")
Now you need a data struct which extends TimerLoop and contains a method called "Loop", for example:
JASS:
private struct Data extends TimerLoop
//you can store whatever data you want in the struct
unit missile
real x
real y
//the loop method
method Loop takes nothing returns nothing
set .x = .x + 10.
set .y = .y + 10.
call SetUnitPosition(.missile, .x, .y)
if .x > 1000 and .y > 1000 then
set .stop = true //set this.stop to true to destroy the struct and stop the spell
endif
endmethod
//your struct may contain any number of other methods, including static methods
static method create takes unit missile, real x, real y returns Data
local Data d = Data.allocate()
set d.missile = missile
set d.x = x
set d.y = y
return d
endmethod
endstruct
To start the spell, you simply do:
JASS:
//function name is $NAME$_Start ($NAME$ is the first textmacro parameter)
call StormBolt_Start(Data.create(u, 0., 0.) //you need to pass the data to the function.
I hope this helps some people. The difference in efficiency between using this system and coding the entire indexing system yourself should be menial. I personally think that this system is by far easier to use and more logical than coding the system yourself.