Dune-II---The-Maker
Dune-II---The-Maker copied to clipboard
Redo particle creation, logic and drawing code to make it possible to configure particle effects without having to change too much code.
I'm going through the Particle code and I really want to redo parts of it. It is very hard to grasp. And although it is not really required (from a functional standpoint) it annoys me quite a lot when I go through that code.
After going through the code I identify 3 kinds of behavior:
- Fade in particle
- Animate particle
- Fade out (keep animating, sometimes) particle
Sometimes 2 particles are spawned at once to imitated some kind of relationship. Ie 'smoke' and a 'smoke shadow' particle are combined. Or "explosion" and "bloom" particle. To give the nice explosion effects.
I want to generify this in such a way so that it becomes more easy to tweak and to introduce (if needed) new kinds of particles (explosions or effects you can think of).
TODO
- [x] introduce a
particleInfokind of thing to keep a bookkeeping of all kinds of particles we know - [x] decouple particle 'type' from 'thing to render/bmp' (now they are the same ID in the code)
- [x]
bmpproperty forparticleInfo - [x] all particle types have their own ID
- [x]
- [ ] introduce 3 states:
fadeIn,animating,fadeOut
These are generic properties of a particle:
type-> what kind of particle this isbmp-> the kind of bitmap to renderframeWidth/frameHeight-> assumes bitmap is a horizontal row where eachframeis a 'tile' on that row. UsingframeIndex(seeanimatingstate) it can render the appropriate piece of the bitmap
These are required properties I think per state to make it work as it is now:
FadeIn
fadeIn: boolean (iffalse, skip toanimatestate)fadeInFrame: theframeIndexto draw when fading infadeInTimeLimit: the time it takes to change the alpha (fading in part), the higher the slower it fades infadeInAlphaChange: the amount the Alpha should change for fading in.fadeInAlphaStart: initial value foralphachannel when fading infadeInAlphaLimit: the value after which state becomesanimating. Default255(fully opaque)
Animating
This is the part where the particle can animate. Which is basically going through the bitmap and animate it. Until a certain time limit has been reached (or animation is finished).
frameIndex-> the frame to draw of the bitmapframeStart-> what is the defaultframeIndexvalue when getting intoanimatingstate?frameTimeLimit-> the time it takes to change theframeIndexwith1(increasing)frameLoopAt-> whenframeIndexis higher than this value, it will be reset toframeStart. WhenframeLoopAtis <0then it will stop when last frame is animated (it can calculate the max amount of frames by doingbmpWidth / frameWidth.frameStopAtLastFrame: iftruethen it will be done animating when last frame is renderedframeAnimationTimeLimit: if >-1then this is the amount of time this animation will be kept, until this state is over
Depending on the fadeOut property it will either go to the fade out state (depending on the frameStopAtLastFrame or frameAnimationTimeLimit). Or the particle is done (dead).
FadeOut
fadeOut: boolean (iftrue, thenanimatingwill transition to this)fadeOutFrame: theframeIndexto draw when fading outfadeOutTimeLimit: the time it takes to change the alpha (fading out part), the higher the slower it fades outfadeOutAlphaChange: the amount the Alpha should change for fading out.fadeOutAlphaStart: initial value foralphachannel when fading out (if not specified (-1) then it will resume the current value)fadeOutAlphaLimit: the value after which the particle dies
Atm, I'll park this issue. It has been a while and I can't remember when/what annoyed me. So I am not motivated right now to refactor for the sake of refactoring.