Thraka / SadConsole

A .NET ascii/ansi console engine written in C# for MonoGame and XNA. Create your own text roguelike (or other) games!
MIT License
1.23k stars 120 forks source link

Improvements to Renderer #316

Closed Thraka closed 1 year ago

Thraka commented 1 year ago

Right now, only the SurfaceRenderer exists, which is very basic and doesn't do anything specialized. The steps it takes to render are:

  1. Create the final output texture object
  2. Populate the CachedRenderRects collection based on the IScreenObject.Font
  3. Runs Refresh on each render step.
  4. If any render step signaled it was dirty, runs Compose on each render step (which generally draws the render step to the final output texture)
  5. Runs Render on each render step to create draw calls that draws the object as a whole to the screen.

Specialized screen surfaces have different render steps, which may include removing the SurfaceRenderStep, but always includes adding another render step, such as the ControlsHostRenderStep or the WindowRenderStep (which draws the tinted background on modal windows).

Specialized renderers would make it easier for someone to create, for example, their own "Window" class that didn't inherit from SadConsole's version. But it would also mean that there would need to be some sort of IWindowRenderParameters interface the renderer could use, which would include things like the whole screen tint color.

Secondly, if say ScreenSurface used a new specialized renderer named ScreenSurfaceRenderer, the renderer could do all the steps required for rendering directly and avoid the RenderSteps collection completely. But this makes it incompatible with say Cursor or ControlsHost which inject their own render steps.

A new ComposedRenderer would be created that did exactly what the current SurfaceRenderer does. IComposedRenderParameters would be created which had a boolean for "seed the renderer with what screen surface does" which sets up the render steps exactly the same as SadConsole currently does. This allows someone to request the composed renderer but leave it blank for them to craft.

The parameters for the renderer could be sent on the Host.GetRenderer method and could be reset via a Renderer.SetParameters method.


Also, both Renderer and RenderSteps are part of IScreenSurface. However, RenderSteps is useless on its own and requires the Renderer. Should it be moved to Renderer? This would let the renderer validate it's a compatible step, or at least reject non-compatible steps?