fissh

termios terminal aquarium. demo at ssh://fish@kloet.net
Download | Log | Files | Refs

commit d4871e8f36f9e8a828822530bdb7b19acc2c3433
parent b751d07d40e06857f8c2932fbf61546ca76b26a2
Author: amrfti <andrew@kloet.net>
Date:   Thu, 22 May 2025 20:30:51 -0400

decouple waterline from entity

Diffstat:
Msrc/Waterline.cpp | 21+++++++--------------
Msrc/Waterline.h | 5+++--
2 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/Waterline.cpp b/src/Waterline.cpp @@ -5,25 +5,21 @@ #include <algorithm> #include <ncurses.h> -Waterline::Waterline() { - std::vector<std::string> baseShape = { +Waterline::Waterline() : x(0), y(5) { + shape = { "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", "^^^^ ^^^ ^^^ ^^^ ^^^^ ", "^^^^ ^^^^ ^^^ ^^ ", "^^ ^^^^ ^^^ ^^^^^^ "}; - int seg_len = baseShape[0].size(); - int repeat = Aquarium::getInstance().getWidth() / seg_len + 1; - - for (auto &line : baseShape) { - std::string original = line; - while (line.size() < Aquarium::getInstance().getWidth()) { + const size_t width = Aquarium::getInstance().getWidth(); + for (auto &line : shape) { + const std::string original = line; + while (line.size() < width) { line += original; } } - shape = std::move(baseShape); - y = 5; } -void Waterline::draw() { +void Waterline::draw() const { for (size_t i = 0; i < shape.size(); ++i) { Aquarium::getInstance().drawToBackBuffer(i + y, x, 0, shape[i], std::string(shape[i].size(), 'c')); @@ -42,9 +38,6 @@ void Waterline::update() { } void Waterline::shiftString(std::string &str, int direction) { - if (str.empty() || (direction != 1 && direction != -1)) - return; - if (direction == 1) { std::rotate(str.rbegin(), str.rbegin() + 1, str.rend()); } else { diff --git a/src/Waterline.h b/src/Waterline.h @@ -1,13 +1,14 @@ #pragma once #include "Entity.h" -class Waterline : public Entity { +class Waterline { private: + size_t x, y; std::vector<std::string> shape; void shiftString(std::string &, int direction); public: Waterline(); - void draw(); + void draw() const; void update(); };