AERA
video_screen.h
1 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
2 //_/_/
3 //_/_/ AERA
4 //_/_/ Autocatalytic Endogenous Reflective Architecture
5 //_/_/
6 //_/_/ Copyright (c) 2022-2025 Jeff Thompson
7 //_/_/ Copyright (c) 2022-2025 Icelandic Institute for Intelligent Machines
8 //_/_/ http://www.iiim.is
9 //_/_/
10 //_/_/ --- Open-Source BSD License, with CADIA Clause v 1.0 ---
11 //_/_/
12 //_/_/ Redistribution and use in source and binary forms, with or without
13 //_/_/ modification, is permitted provided that the following conditions
14 //_/_/ are met:
15 //_/_/ - Redistributions of source code must retain the above copyright
16 //_/_/ and collaboration notice, this list of conditions and the
17 //_/_/ following disclaimer.
18 //_/_/ - Redistributions in binary form must reproduce the above copyright
19 //_/_/ notice, this list of conditions and the following disclaimer
20 //_/_/ in the documentation and/or other materials provided with
21 //_/_/ the distribution.
22 //_/_/
23 //_/_/ - Neither the name of its copyright holders nor the names of its
24 //_/_/ contributors may be used to endorse or promote products
25 //_/_/ derived from this software without specific prior
26 //_/_/ written permission.
27 //_/_/
28 //_/_/ - CADIA Clause: The license granted in and to the software
29 //_/_/ under this agreement is a limited-use license.
30 //_/_/ The software may not be used in furtherance of:
31 //_/_/ (i) intentionally causing bodily injury or severe emotional
32 //_/_/ distress to any person;
33 //_/_/ (ii) invading the personal privacy or violating the human
34 //_/_/ rights of any person; or
35 //_/_/ (iii) committing or preparing for any act of war.
36 //_/_/
37 //_/_/ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
38 //_/_/ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
39 //_/_/ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
40 //_/_/ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 //_/_/ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
42 //_/_/ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 //_/_/ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44 //_/_/ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
45 //_/_/ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46 //_/_/ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
47 //_/_/ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
48 //_/_/ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49 //_/_/ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
50 //_/_/ OF SUCH DAMAGE.
51 //_/_/
52 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
53 
54 #ifndef video_screen_h
55 #define video_screen_h
56 
57 #include "../r_code/object.h"
58 
59 namespace video_screen {
60 
61 class VideoScreen {
62 public:
68  VideoScreen(int width, int height);
69 
70  ~VideoScreen() {
71  delete screen_;
72  if (fovea_patterns_)
73  delete fovea_patterns_;
74  }
75 
81  bool load(const std::vector<r_code::Code *> *objects);
82 
92  void move_eye(int delta_x, int delta_y, int& actual_delta_x, int& actual_delta_y);
93 
98 
99 private:
103  void clear_screen() {
104  for (size_t i = 0; i < width_ * height_; ++i)
105  screen_[i] = false;
106  }
107 
114  bool get_screen(int x, int y) const {
115  if (x < 0 || x >= width_ || y < 0 || y >= height_)
116  return false;
117 
118  return screen_[y * width_ + x];
119  }
120 
127  void set_screen(int x, int y, bool value) {
128  if (x < 0 || x >= width_ || y < 0 || y >= height_)
129  return;
130 
131  screen_[y * width_ + x] = value;
132  }
133 
137  void draw_paddle(int x, int y) {
138  set_screen(x, y - 1, true);
139  set_screen(x, y, true);
140  set_screen(x, y + 1, true);
141  }
142 
146  void draw_ball(int x, int y) {
147  // A ball is just a dot for now.
148  set_screen(x, y, true);
149  }
150 
151  int width_;
152  int height_;
153  bool* screen_;
154  int fovea_x_;
155  int fovea_y_;
156  r_code::Code** fovea_patterns_;
157 };
158 
159 }
160 #endif
video_screen::VideoScreen::VideoScreen
VideoScreen(int width, int height)
Definition: video_screen.cpp:65
video_screen::VideoScreen
Definition: video_screen.h:61
video_screen::VideoScreen::get_fovea_pattern
r_code::Code * get_fovea_pattern() const
Definition: video_screen.cpp:620
r_code::Code
Definition: r_code/object.h:224
video_screen::VideoScreen::move_eye
void move_eye(int delta_x, int delta_y, int &actual_delta_x, int &actual_delta_y)
Definition: video_screen.cpp:608
video_screen::VideoScreen::load
bool load(const std::vector< r_code::Code * > *objects)
Definition: video_screen.cpp:75