MCPcopy Create free account
hub / github.com/OSSystems/EasySplash / run

Method run

src/event_loop.cpp:116–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114
115
116void event_loop::run(animation &p_animation)
117{
118 if (m_fifo_fd == -1)
119 return;
120
121 animation_position anim_pos;
122 bool stop_loop_requested = false;
123
124 // Calculate coordinates based on the output width specified
125 // by the desc.txt file in the animation.
126 // The coordinates display the frames in the center of the screen.
127 long dx1 = (m_display.get_width() - p_animation.get_output_width()) / 2;
128 long dy1 = (m_display.get_height() - p_animation.get_output_height()) / 2;
129 long dx2 = dx1 + p_animation.get_output_width() - 1;
130 long dy2 = dy1 + p_animation.get_output_height() - 1;
131
132 // Setup pollfd structure to check for bytes to read from the FIFO fd
133 struct pollfd fds[2];
134 std::memset(fds, 0, sizeof(fds));
135 int num_poll_fds = 0;
136
137 fds[0].fd = m_fifo_fd;
138 fds[0].events = POLLIN;
139 ++num_poll_fds;
140
141 if (sigint_fd != -1)
142 {
143 fds[1].fd = m_sigint_fds[0];
144 fds[1].events = POLLIN;
145 ++num_poll_fds;
146 }
147
148 // Defines how many milliseconds poll() shall wait for bytes to read.
149 // Initially, this value is 0, causing poll() to return immediately.
150 // This is desirable, since then, it will always paint the first frame
151 // immediately, meaning the first frame will appear as soon as the
152 // event loop starts. In non-realtime mode, however, set this to -1,
153 // since then, no timeouts shall occur (animation advances only when
154 // requested by a FIFO message).
155 int wait_period = m_non_realtime_mode ? -1 : 0;
156
157 // Define period of one frame
158 std::chrono::steady_clock::duration const frame_dur = std::chrono::nanoseconds(1000000000) / p_animation.get_fps();
159
160 // Frame drawing function
161 auto draw_frame = [&](){
162 display::image_handle cur_image_handle = p_animation.get_image_handle_at(anim_pos);
163 if (cur_image_handle != display::invalid_image_handle)
164 {
165 m_display.draw_image(cur_image_handle, dx1, dy1, dx2, dy2);
166 m_display.swap_buffers();
167 }
168 };
169
170 unsigned int old_abs_frame_pos = 0;
171
172 while (true)
173 {

Callers 1

mainFunction · 0.80

Calls 12

update_positionFunction · 0.85
get_output_widthMethod · 0.80
get_output_heightMethod · 0.80
get_fpsMethod · 0.80
get_image_handle_atMethod · 0.80
get_num_partsMethod · 0.80
get_partMethod · 0.80
get_total_num_framesMethod · 0.80
get_widthMethod · 0.45
get_heightMethod · 0.45
draw_imageMethod · 0.45
swap_buffersMethod · 0.45

Tested by

no test coverage detected