Dune-II---The-Maker icon indicating copy to clipboard operation
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.

Open stefanhendriks opened this issue 4 years ago • 1 comments

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:

  1. Fade in particle
  2. Animate particle
  3. 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 particleInfo kind 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] bmp property for particleInfo
    • [x] all particle types have their own ID
  • [ ] introduce 3 states: fadeIn, animating, fadeOut

These are generic properties of a particle:

  • type -> what kind of particle this is
  • bmp -> the kind of bitmap to render
  • frameWidth / frameHeight -> assumes bitmap is a horizontal row where each frame is a 'tile' on that row. Using frameIndex (see animating state) 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 (if false, skip to animate state)
  • fadeInFrame : the frameIndex to draw when fading in
  • fadeInTimeLimit : the time it takes to change the alpha (fading in part), the higher the slower it fades in
  • fadeInAlphaChange : the amount the Alpha should change for fading in.
  • fadeInAlphaStart : initial value for alpha channel when fading in
  • fadeInAlphaLimit : the value after which state becomes animating. Default 255 (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 bitmap
  • frameStart -> what is the default frameIndex value when getting into animating state?
  • frameTimeLimit -> the time it takes to change the frameIndex with 1 (increasing)
  • frameLoopAt -> when frameIndex is higher than this value, it will be reset to frameStart. When frameLoopAt is < 0 then it will stop when last frame is animated (it can calculate the max amount of frames by doing bmpWidth / frameWidth.
  • frameStopAtLastFrame : if true then it will be done animating when last frame is rendered
  • frameAnimationTimeLimit: if > -1 then 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 (if true, then animating will transition to this)
  • fadeOutFrame : the frameIndex to draw when fading out
  • fadeOutTimeLimit : the time it takes to change the alpha (fading out part), the higher the slower it fades out
  • fadeOutAlphaChange : the amount the Alpha should change for fading out.
  • fadeOutAlphaStart : initial value for alpha channel when fading out (if not specified (-1) then it will resume the current value)
  • fadeOutAlphaLimit : the value after which the particle dies

stefanhendriks avatar Sep 20 '21 14:09 stefanhendriks

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.

stefanhendriks avatar Nov 24 '21 14:11 stefanhendriks