Clarify basic pump-and-draw loop

This commit is contained in:
Tommy 2022-07-29 16:13:46 +12:00
parent b8d4f49858
commit c0990fd258
7 changed files with 25 additions and 33 deletions

View file

@ -391,7 +391,7 @@ void controller_base::play_slice(bool is_delay_enabled)
events::pump();
events::raise_process_event();
events::raise_draw_event();
events::draw();
// Update sound sources before scrolling
if(soundsource::manager* l = get_soundsource_man()) {

View file

@ -2065,7 +2065,7 @@ void display::scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_ty
if(scroll_type == WARP || scroll_type == ONSCREEN_WARP || turbo_speed() > 2.0 || preferences::scroll_speed() > 99) {
scroll(xmove,ymove,true);
redraw_minimap();
events::raise_draw_event();
events::draw();
return;
}
@ -2124,7 +2124,7 @@ void display::scroll_to_xy(int screenxpos, int screenypos, SCROLL_TYPE scroll_ty
y_old += dy;
redraw_minimap();
events::raise_draw_event();
events::draw();
}
}
@ -2355,8 +2355,7 @@ void display::fade_tod_mask(
tod_hex_alpha2 = p;
tod_hex_alpha1 = ~p;
draw_manager::invalidate_region(map_outside_area());
events::pump();
events::raise_draw_event();
events::pump_and_draw();
}
tod_hex_mask1.reset();
@ -2381,8 +2380,7 @@ void display::fade_to(const color_t& c, int duration)
uint8_t p = float_to_color(prop_f);
fade_color_ = fade_start.smooth_blend(c, p);
draw_manager::invalidate_region(map_outside_area());
events::pump();
events::raise_draw_event();
events::pump_and_draw();
}
fade_color_ = c;
}

View file

@ -718,6 +718,11 @@ void pump()
}
}
void draw()
{
draw_manager::sparkle();
}
void raise_process_event()
{
if(event_contexts.empty() == false) {
@ -742,11 +747,6 @@ void raise_resize_event()
raise_window_event(event);
}
void raise_draw_event()
{
draw_manager::sparkle();
}
void raise_help_string_event(int mousex, int mousey)
{
if(event_contexts.empty() == false) {

View file

@ -142,11 +142,15 @@ struct event_context
~event_context();
};
//causes events to be dispatched to all handler objects.
/** Process all events currently in the queue. */
void pump();
//look for resize events and update references to the screen area
void peek_for_resize();
/** Trigger a draw cycle. */
void draw();
/** pump() then immediately draw() */
inline void pump_and_draw() { pump(); draw(); }
// TODO: draw_manager - should this also raise_process_event? Some things do some don't
struct pump_info {
pump_info() : resize_dimensions(), ticks_(0) {}
@ -166,7 +170,6 @@ public:
void raise_process_event();
void raise_resize_event();
void raise_draw_event();
void raise_help_string_event(int mousex, int mousey);

View file

@ -121,9 +121,7 @@ void loading_screen::progress(loading_stage stage)
if(singleton_ && stage != loading_stage::none) {
singleton_->current_stage_.store(stage, std::memory_order_release);
// Allow display to update, close events to be handled, etc.
// TODO: draw_manager - draws should probably go after pumping
events::raise_draw_event();
events::pump();
events::pump_and_draw();
}
}
@ -142,8 +140,7 @@ void loading_screen::spin()
// Restrict actual update rate.
int elapsed = SDL_GetTicks() - last_spin_;
if (elapsed > 10 || elapsed < 0) {
events::raise_draw_event();
events::pump();
events::pump_and_draw();
last_spin_ = SDL_GetTicks();
}
}

View file

@ -464,8 +464,7 @@ void window::show_non_modal(/*const unsigned auto_close_timeout*/)
DBG_DP << "show non-modal queued to " << get_rectangle();
events::pump();
events::raise_draw_event();
events::pump_and_draw();
}
int window::show(const unsigned auto_close_timeout)
@ -494,8 +493,7 @@ int window::show(const unsigned auto_close_timeout)
queue_redraw();
// Make sure we display at least once in all cases.
// TODO: draw_manager - rename this so it's clear what's going on
events::raise_draw_event();
events::draw();
if(auto_close_timeout) {
SDL_Event event;
@ -512,10 +510,6 @@ int window::show(const unsigned auto_close_timeout)
// Start our loop drawing will happen here as well.
bool mouse_button_state_initialized = false;
for(status_ = status::SHOWING; status_ != status::CLOSED;) {
// process installed callback if valid, to allow e.g. network
// polling
events::pump();
if(!mouse_button_state_initialized) {
/*
* The state must be initialize when showing the dialog.
@ -536,7 +530,7 @@ int window::show(const unsigned auto_close_timeout)
}
// This will rate limit to vsync
events::raise_draw_event();
events::pump_and_draw();
}
}
catch(...)

View file

@ -23,7 +23,7 @@
#include "help/help.hpp"
#include "config.hpp" // for config, etc
#include "events.hpp" // for raise_draw_event, pump, etc
#include "events.hpp" // for draw, pump, etc
#include "font/constants.hpp" // for relative_size
#include "preferences/game.hpp"
#include "game_config_manager.hpp"
@ -243,7 +243,7 @@ void show_with_toplevel(const section &toplevel_sec,
hb.show_topic(default_show_topic);
}
hb.queue_redraw();
events::raise_draw_event();
events::draw();
CKey key;
for (;;) {
events::pump();
@ -260,7 +260,7 @@ void show_with_toplevel(const section &toplevel_sec,
}
}
// This also rate limits to vsync
events::raise_draw_event();
events::draw();
}
}
catch (const parse_error& e) {