- Joined
- Apr 24, 2012
- Messages
- 5,111
JASS:
library Particle/* v1.0.0
*************************************************************************************
*
* 1.29 Effect API Handling and Wrappers
*
*************************************************************************************
*
* struct Particle extends array
* readonly string model
*
* static method create takes string mdx, real tx, real ty, real tz returns thistype
* method destroy takes nothing returns nothing
*
* Position API
*
* method operator x= takes real r returns nothing
* method operator x takes nothing returns real
*
* method operator y= takes real r returns nothing
* method operator y takes nothing returns real
*
* method operator z= takes real r returns nothing
* method operator z takes nothing returns real
*
* Orientation API
*
* method operator yaw= takes real r returns nothing
* method operator yaw takes nothing returns real
*
* method operator pitch= takes real r returns nothing
* method operator pitch takes nothing returns real
*
* method operator roll= takes real r returns nothing
* method operator roll takes nothing returns real
*
* Appearance API
*
* method operator scale= takes real r returns nothing
* method operator scale takes nothing returns real
*
* method operator alpha= takes integer r returns nothing
* method operator alpha takes nothing returns integer
*
* method setColor takes integer r, integer g, integer b returns nothing
*
* method operator red takes nothing returns integer
* method operator green takes nothing returns integer
* method operator blue takes nothing returns integer
*
*************************************************************************************/
private module I
private static method onInit takes nothing returns nothing
call init()
endmethod
endmodule
struct Particle extends array
readonly string model
private effect effect
private integer t__a
private integer t__r
private integer t__g
private integer t__b
private real t__x
private real t__y
private real t__z
private real t__yaw
private real t__pitch
private real t__roll
private real t__scale
private static thistype array recycler
static method create takes string mdx, real tx, real ty, real tz returns thistype
local thistype this = recycler[0]
if(recycler[this] == 0) then
set recycler[0] = this + 1
else
set recycler[0] = recycler[this]
endif
debug set recycler[this] = -1
set model = mdx
set t__x = tx
set t__y = ty
set t__z = tz
set effect = AddSpecialEffect(mdx, tx, ty)
call BlzSetSpecialEffectZ(effect, tz)
set t__yaw = 0.
set t__pitch = 0.
set t__roll = 0.
set t__scale = 1.
set t__a = 255
set t__r = 255
set t__g = 255
set t__b = 255
return this
endmethod
method destroy takes nothing returns nothing
debug if (recycler[this] == -1) then
set recycler[this] = recycler[0]
set recycler[0] = this
call DestroyEffect(effect)
set effect = null
set model = ""
set t__x = 0
set t__y = 0
set t__z = 0
set t__yaw = 0.
set t__pitch = 0.
set t__roll = 0.
set t__scale = 0.
set t__a = 0
set t__r = 0
set t__g = 0
set t__b = 0
debug endif
endmethod
/*
*
* Position API
*
*/
method operator x= takes real r returns nothing
set t__x = r
call BlzSetSpecialEffectX(effect, r)
endmethod
method operator x takes nothing returns real
return t__x
endmethod
method operator y= takes real r returns nothing
set t__y = r
call BlzSetSpecialEffectY(effect, r)
endmethod
method operator y takes nothing returns real
return t__y
endmethod
method operator z= takes real r returns nothing
set t__z = r
call BlzSetSpecialEffectZ(effect, r)
endmethod
method operator z takes nothing returns real
return t__z
endmethod
/**
*
* Orientation API
*
*/
method operator yaw= takes real r returns nothing
set t__yaw = r
call BlzSetSpecialEffectYaw(effect, r)
endmethod
method operator yaw takes nothing returns real
return t__yaw
endmethod
method operator pitch= takes real r returns nothing
/*
* As of 1.29, changing the effect's pitch over time
* (at least on 32 frames per second) will cause it
* not to render correctly, as if it was trying to turn
* on the opposite direction and then tries to correct
* it on the next frame.
*
* we have to reapply the previous orientation before
* applying the new one
*/
call BlzSetSpecialEffectPitch(effect, t__pitch)
set t__pitch = r
call BlzSetSpecialEffectPitch(effect, r)
endmethod
method operator pitch takes nothing returns real
return t__pitch
endmethod
method operator roll= takes real r returns nothing
set t__roll = r
call BlzSetSpecialEffectRoll(effect, r)
endmethod
method operator roll takes nothing returns real
return t__roll
endmethod
/*
*
* Appearance API
*
*/
method operator scale= takes real r returns nothing
set t__scale = r
call BlzSetSpecialEffectScale(effect, r)
endmethod
method operator scale takes nothing returns real
return t__scale
endmethod
method operator alpha= takes integer r returns nothing
set t__a = r
call BlzSetSpecialEffectAlpha(effect, r)
endmethod
method operator alpha takes nothing returns integer
return t__a
endmethod
method setColor takes integer r, integer g, integer b returns nothing
set t__r = r
set t__g = g
set t__b = b
call BlzSetSpecialEffectColor(effect, r, g, b)
endmethod
method operator red takes nothing returns integer
return t__r
endmethod
method operator green takes nothing returns integer
return t__g
endmethod
method operator blue takes nothing returns integer
return t__b
endmethod
private static method init takes nothing returns nothing
set recycler[0] = 1
endmethod
implement I
endstruct
endlibrary
Pitch per frame demo:
JASS:
library Tests requires Particle
private module I
private static method onInit takes nothing returns nothing
call init()
endmethod
endmodule
private struct T extends array
private static constant timer timer = CreateTimer()
private static Particle effect
private static integer state
private static real r
private static method u takes nothing returns nothing
set r = r + (bj_PI/4)*0.03125
if(r > bj_PI*2) then
set r = 0.
set state = state + 1
if(state > 2) then
set state = 0
endif
endif
if(state == 0) then
call BJDebugMsg("yaw")
set effect.yaw = r
elseif(state == 1) then
call BJDebugMsg("pitch")
set effect.pitch = r
elseif(state == 2) then
call BJDebugMsg("roll")
set effect.roll = r
endif
endmethod
private static method init takes nothing returns nothing
set effect = Particle.create("units\\human\\Knight\\Knight.mdl", 0, 0, 64.)
set effect.scale = 5
set state = 0
set r = 0
call TimerStart(timer, 0.03125, true, function thistype.u)
endmethod
implement I
endstruct
endlibrary
Last edited: