| 12-02-2007, 06:27 AM | #1 |
Alright, I'm working on a class called DummyEffect. The purpose is to expand the usage of special effects. An invisible dummy unit with a special effect attached allows one to scale, fade, and "attach" the dummy effect to units. I've never used struct inheritance before so I'm posting the design of this here before I start coding it for feedback. This is what the parent class will look like (of course methods are empty for now because I haven't coded it yet): JASS:struct DummyEffect //Config variables that the user can redeclare in a child struct: string ModelPath //The special effect model that will be used real XOffset //Adjust the relative position of an effect attached to a unit real YOffSet real ZOffset real DeathDuration //When an effect is killed, this amount of time shall pass //before the effect/dummy unit is removed and struct is //deallocated, to give time to play the death animation. method create(x, y, height) //Creates a dummy effect at a given x,y,h position, calls onCreate method createOn(unit) //Creates a dummy effect at the position of a unit //and attaches it to that unit, calls onCreate method attach(unit) //Attaches a dummy effect to a unit method unattach() //Unattaches a dummy effect from whatever it's attached to method scale(xscale, yscale, zscale) //Scales a dummy effect method scaleTimed(xscale, yscale, zscale, time) //Scales a dummy effect over time method fade(red, green, blue, alpha) //Sets a dummy effect's vertex colors method fadeTimed(red, green, blue, alpha, time) //Fades a dummy effect's vertex colors over time method addExpiration(time) //Starts a one-shot timer that calls onExpire when done method kill() //Kills the effect, playing its death animation, calls onKill, then //waits DeathDuration and calls .destroy() method destroy() //Deallocates struct, and can be used to instantly remove //an effect without playing its death animation //"Event" methods that can be redeclared in the child struct: method onCreate() //Called when a dummy effect is created, defaults empty method onKill() //Called when a dummy effect is killed, defaults empty method onExpire() //Called when a dummy effect's expiration timer expires, defaults to call .kill() endstruct Example of a typical effect: JASS:struct Glow extends DummyEffect string ModelPath = "glow//glow.mdl" real ZOffset = 16 //turns out the thing was a bit off-center real DeathDuration = 1.33 //turns out this model takes 1.33 seconds to play death anim method onCreate takes nothing returns nothing call .scale(2, 2, 2) call .scaleTimed(3, 3, 3, 0.5) //Starts out at scale 2 and scales to size 3 over 0.5 sec call .fade(1, 1, 1, 0.5) call .fadeTimed(1, 1, 1, 1, 0.5) //Starts out at 50% alpha and fades to 100% alpha over 0.5 sec call .addExpiration(2) //Effect expires in 2 sec. I could redeclare onExpire endmethod //and assign some custom behavior; it will simply kill the effect by default method onKill takes nothing returns nothing call .scaleTimed(0.5, 0.5, 0.5, 0.5) //Shrinks to 0.5 scale in 0.5 sec when killed call .fadeTimed(1, 1, 1, 0.5, 0.5) //Fades to 0.5 alpha in 0.5 sec when killed endmethod endstruct So now we have this complex special effect all encapsulated in a neat struct. It is effectively a new special effect, based off of the original model, but now altered to follow certain behaviors. It grows and fades in when created, and shrinks and fades out on death. Of course more complex behaviors could be created as well. The point is that it's all swept away inside a struct for each unique special effect and can be easily called within your spells. Example of using the Glow effect: JASS:call Glow.createOn(target) Anyway I want feedback about this design and whether anyone who reads this believes it should be implemented differently. Ideas for extra features are welcome as well. |
| 12-02-2007, 06:40 AM | #2 |
Nice idea. I don't think there is a better or cleaner way of doing this, other than modifying the models itself. I guess the only issue is that the effects would revolve around a periodic timer(fading and movement), which means lots of effects could be costly. I would also include an exponential fade as well as the current linear fade. p.s. I hope you are still working on your physics system. |
| 12-02-2007, 06:53 AM | #3 |
You'd have to get into 100+ simultaneous effects before it could really cost noticeable performance. If used in any reasonable way performance shouldn't be an issue. I don't really see the point of exponential fade, want to include an example of when it's useful? Physics engine is still "almost done" like the past year or so. Finishing this is a prerequisite since they work together. |
| 12-02-2007, 07:08 AM | #4 |
It can be used as a decay starting at a min and then expanding to infinity. Usually exponential fades (and S fades) are used a lot in film and audio transitions since it appears to blend more naturally. Having an effect that just starts to fade versus one that gradually fades, one is more appealing. http://www.transom.org/tools/editing...adetricks.html is what I mean, although their idea sound samples are rather stupid. |
| 12-02-2007, 08:06 AM | #5 |
Why aren't there .setX(newX), .setY(newY), and .setZOffset(offsetZ) methods? I suppose one could attach the dummy effect to another unit... but why create another unit when you could do it in methods. Also, a . setZOffsetTimed(offsetZ, Time) might be useful. Additionally, it seems you forgot to say anything about .setXOffset(offsetX) and .setYOffset(offsetY). Oh, and you put your model path's slashes backwards in your example code; they go like this: \\. |
| 12-02-2007, 08:59 AM | #6 | |
OK, I guess it needs some methods to support moving the effect. Offsets aren't really meant to be manipulated; they're meant to correct for the fact that the graphic often won't be centered over the target since it's not truly attached. If you're doing some thing where you manipulate the offsets over time then it can just be coded manually. JASS:local DummyEffect de = Glow.createOn(someunit) set de.XOffset = de.XOffset + 1 Quote:
|
| 12-02-2007, 09:06 AM | #7 |
I care. |
