Simulant  21.12-1292
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
screen.h
1 #pragma once
2 
3 #include <vector>
4 
5 #include "generic/managed.h"
6 #include "generic/data_carrier.h"
7 #include "threads/mutex.h"
8 
9 namespace smlt {
10 
11 class Window;
12 
13 enum ScreenFormat {
14  SCREEN_FORMAT_G1, /* 1 grey bit per pixel */
15  SCREEN_FORMAT_MAX
16 };
17 
18 class Screen:
19  public RefCounted<Screen>,
20  public generic::DataCarrier {
21 
22 public:
23  Screen(Window* window, const std::string& name, uint16_t w, uint16_t h, ScreenFormat format=SCREEN_FORMAT_G1, uint16_t refresh=60);
24 
25  /* Render image data. data must be of size width x height x bits where bits
26  * is defined by the ScreenFormat. Data should be arranged from top-left.
27  *
28  * Rendering is not instantaneous, submitting images too quickly could result
29  * in some images being skipped.
30  *
31  * refresh_rate will give you some indication of the rate to submit images,
32  * but if you experience frame skipping then reduce the update time.
33  *
34  * You can use a Scene fixed_update, a Behaviour or window->idle->add_timeout
35  * to update with a regular frequency.
36  */
37  void render(const uint8_t* data);
38 
39  uint16_t height() const {
40  return height_;
41  }
42 
43  uint16_t width() const {
44  return width_;
45  }
46 
47  ScreenFormat format() const {
48  return format_;
49  }
50 
51  uint16_t refresh_rate() const {
52  return refresh_rate_;
53  }
54 
55  /*
56  * If this is greater than one, then
57  * all data sent via render is integer scaled
58  */
59  uint16_t integer_scale() const {
60  return integer_scale_;
61  }
62 
63  /* Private API, should only be called by the window
64  * class that knows how to handle it */
65  void _set_integer_scale(uint8_t scale) {
66  integer_scale_ = scale;
67  }
68 
69  std::string name() const;
70 
71  void update(float dt);
72 
73 private:
74  Window* window_;
75  std::string name_;
76 
77  uint16_t width_ = 0;
78  uint16_t height_ = 0;
79  uint16_t row_stride_ = 0;
80  ScreenFormat format_ = SCREEN_FORMAT_G1;
81  uint16_t refresh_rate_ = 15;
82  uint8_t integer_scale_ = 1;
83  float time_till_next_refresh_ = 0.0f;
84  bool buffer_dirty_ = false;
85 
86  std::vector<uint8_t> buffer_;
87  thread::Mutex buffer_mutex_;
88 
89  friend class Window;
90 };
91 
92 }
smlt::RefCounted
Definition: managed.h:71
smlt
Definition: animation.cpp:25
smlt::Window
Definition: window.h:68
smlt::Screen
Definition: screen.h:20
smlt::generic::DataCarrier
Definition: data_carrier.h:37
smlt::thread::Mutex
Definition: mutex.h:35