import 'dart:typed_data';

/// A 32-bit pixel buffer representing the raw screen output.
///
/// This buffer is intended to be filled by the raycaster and then
/// pushed to the GPU (via Texture) or displayed on a Canvas.
class FrameBuffer {
  /// Screen width in pixels.
  final int width;

  /// Screen height in pixels.
  final int height;

  /// A 1D array representing the 2D screen in ABGR/RGBA format.
  /// Length is always [width] * [height].
  final Uint32List pixels;

  FrameBuffer(this.width, this.height) : pixels = Uint32List(width * height);

  /// Clears the screen by painting the top half as the ceiling and the bottom half as the floor.
  ///
  /// [ceilingColor32] and [floorColor32] should be 32-bit hex colors (e.g., 0xFF383838).
  void clear(int ceilingColor32, int floorColor32) {
    int half = (width * height) ~/ 2;

    // Fill the ceiling (indices 0 to middle)
    pixels.fillRange(0, half, ceilingColor32);

    // Fill the floor (indices middle to end)
    pixels.fillRange(half, pixels.length, floorColor32);
  }
}
