add method

void add(
  1. Perception perception
)

Adds a Perception to the buffer.

If the buffer is at capacity, the oldest perception is displaced.

Implementation

void add(Perception perception) {
  _pruneExpired();

  if (_buffer.length >= capacity) {
    final dropped = _buffer.removeFirst();
    _totalDropped++;
    _logger.debug(
        'Buffer overflow — dropped: '
        '"${_trunc(dropped.perception.rawInput)}"');
  }

  _buffer.addLast(_BufferedPercept(
    perception: perception,
    arrivedAt: DateTime.now(),
  ));
  _totalAdded++;

  _logger.debug(
      'Buffered [${perception.modality.name}]: '
      '"${_trunc(perception.rawInput)}" '
      '(buffer: ${_buffer.length}/$capacity)');
}