Waterline.h (1073B)
1 #pragma once 2 #include "Entity.h" 3 #include <array> 4 5 class Waterline : public Entity { 6 private: 7 static constexpr int WATERLINE_Y = 5; 8 static constexpr char WATERLINE_COLOR = 'c'; 9 static constexpr size_t NUM_WAVE_LAYERS = 4; 10 11 // Use arrays instead of vectors for fixed-size data 12 std::array<std::string, NUM_WAVE_LAYERS> shape; 13 std::array<std::string, NUM_WAVE_LAYERS> colorLines; 14 15 // Pre-compute shift operations 16 void shiftStringLeft(std::string &str); 17 void shiftStringRight(std::string &str); 18 19 public: 20 Waterline(); 21 22 void update() noexcept override; 23 const std::vector<std::string> &getImage() const override; 24 const std::vector<std::string> &getMask() const override; 25 char getDefaultColor() const noexcept override { return WATERLINE_COLOR; } 26 27 std::unique_ptr<Entity> createReplacement() const override { return nullptr; } 28 int getPreferredLayer() const noexcept override { return 0; } 29 30 private: 31 // Cache vectors to avoid allocation each frame 32 mutable std::vector<std::string> cached_image; 33 mutable std::vector<std::string> cached_mask; 34 };