Thraka/SadConsole

Improve Effects design

Thraka opened this issue · 1 comments

The effects system is complex and hard to get working if there is a bug or problem. Many areas of SadConsole have their own toggles for processing effects. It becomes hard to understand what prevents an effect from being applied. For example, these settings apply to creating/using effects:

  1. CommandStack.TurnOnEffects
  2. ColoredString.IgnoreEffect
  3. Cursor.UsePrintEffect

String processor

When a command is added to the string processor which adds effects to the string, the ParseCommandStacks.TurnOnEffects boolean must be set to true. This really isn't needed. The only thing it does is cause the ColoredString.IgnoreEffects to be set appropriately after the parser creates the string.

One thing that could be done to remove this complication is have the parser scan through each glyph in the string and check if the Effect is set, if it is, disable the ignore.

Cursor printing effects

Cursors are considered an extra object that works on a surface, providing a terminal cursor that you can move and print with. The cursor should be designed in a simple way that allows the following capabilities (related to printing) with a goal of simplifying the amount of customization available:

  1. Print with the default fore/back of the surface, clearing the effect on the surface.
  2. Set the fore/back/effect of the cursor, and print with it.
  3. Use a colored string to determine fore/back/effect of the glyph being printed.

ColoredString

Effects are set on each glyph of the colored string.

The Ignore* properties on a colored string control how something reads the colored string when printing. It provides the ultimate control of how your string is used.

I don't believe there is anything to change here related to effects.

Overall design of effects

Effects are set through the surface method SetEffect, which calls into the EffectsManager attached to the surface. The manager is in charge of managing the effects and cell associates, as well as processing the effect and applying it to the target cells.

Effects are added/removed from the manager through the cell index. This is fragile due to the fact that is possible to rearrange the cells within the backing array. Also, if a surface is resized, the cell positions are adjusted, desyncing the effects. Adding/removing effects should also work by passing the cell you want to manage the effect.

When the parent surface does something like clear/fill a rect area on the surface, they'll need to keep track of the index of each cell processed and then send that data to the effects manager to clear them. This doesn't currently happen.

This was completed in 9.2.0