moved update_lock stuff from display to video

This commit is contained in:
Yann Dirson 2005-03-16 21:49:37 +00:00
parent c211e3f3c1
commit a077c6c2ea
6 changed files with 64 additions and 60 deletions

View file

@ -74,7 +74,7 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
invalidateAll_(true), invalidateUnit_(true),
invalidateGameStatus_(true), panelsDrawn_(false),
currentTeam_(0), activeTeam_(0), hideEnergy_(false),
deadAmount_(ftofxp(0.0)), advancingAmount_(0.0), updatesLocked_(0),
deadAmount_(ftofxp(0.0)), advancingAmount_(0.0),
turbo_(false), grid_(false), sidebarScaling_(1.0),
theme_(theme_cfg,screen_area()), builder_(cfg, level, map),
first_turn_(true), in_game_(false), map_labels_(*this,map),
@ -82,7 +82,7 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
fps_handle_(0)
{
if(non_interactive())
updatesLocked_++;
screen_.lock_updates(true);
std::fill(reportRects_,reportRects_+reports::NUM_REPORTS,empty_rect);
@ -419,7 +419,7 @@ void display::default_zoom()
void display::scroll_to_tile(int x, int y, SCROLL_TYPE scroll_type, bool check_fogged)
{
if(update_locked() || (check_fogged && fogged(x,y)))
if(screen_.update_locked() || (check_fogged && fogged(x,y)))
return;
const gamemap::location loc(x,y);
@ -517,7 +517,7 @@ void display::bounds_check_position()
void display::redraw_everything()
{
if(update_locked() || teams_.empty())
if(screen_.update_locked() || teams_.empty())
return;
bounds_check_position();
@ -686,7 +686,7 @@ void display::draw(bool update,bool force)
void display::update_display()
{
if(updatesLocked_ > 0)
if(screen_.update_locked())
return;
if(preferences::show_fps()) {
@ -1118,7 +1118,7 @@ void display::draw_halo_on_tile(int x, int y)
void display::draw_unit_on_tile(int x, int y, surface unit_image_override,
fixed_t highlight_ratio, Uint32 blend_with)
{
if(updatesLocked_)
if(screen_.update_locked())
return;
const gamemap::location loc(x,y);
@ -1383,7 +1383,7 @@ void display::draw_terrain_on_tile(int x, int y, image::TYPE image_type, ADJACEN
void display::draw_tile(int x, int y, surface unit_image, fixed_t alpha, Uint32 blend_to)
{
if(updatesLocked_)
if(screen_.update_locked())
return;
draw_halo_on_tile(x,y);
@ -2041,19 +2041,6 @@ void display::set_advancing_unit(const gamemap::location& loc, double amount)
draw_tile(loc.x,loc.y);
}
void display::lock_updates(bool value)
{
if(value == true)
++updatesLocked_;
else
--updatesLocked_;
}
bool display::update_locked() const
{
return updatesLocked_ > 0;
}
bool display::turbo() const
{
bool res = turbo_;
@ -2162,7 +2149,7 @@ void display::create_buttons()
const std::vector<theme::menu>& buttons = theme_.menus();
for(std::vector<theme::menu>::const_iterator i = buttons.begin(); i != buttons.end(); ++i) {
gui::button b(*this,i->title(),gui::button::TYPE_PRESS,i->image());
gui::button b(screen_,i->title(),gui::button::TYPE_PRESS,i->image());
const SDL_Rect& loc = i->location(screen_area());
b.set_location(loc.x,loc.y);

View file

@ -265,13 +265,9 @@ public:
//by amount.
void set_advancing_unit(const gamemap::location& loc, double amount);
//function to stop the screen being redrawn. Anything that happens while
//the update is locked will be hidden from the user's view.
//note that this function is re-entrant, meaning that if lock_updates(true)
//is called twice, lock_updates(false) must be called twice to unlock
//updates.
void lock_updates(bool value);
bool update_locked() const;
//compat methods to be dropped after full migration
void lock_updates(bool value) {screen_.lock_updates(value); };
bool update_locked() const {return screen_.update_locked(); };
//functions to set/get whether 'turbo' mode is on. When turbo mode is on,
//everything moves much faster.
@ -451,8 +447,6 @@ private:
gamemap::location advancingUnit_;
double advancingAmount_;
int updatesLocked_;
bool turbo_, grid_;
double sidebarScaling_;
@ -503,31 +497,6 @@ private:
int fps_handle_;
};
//an object which will lock the display for the duration of its lifetime.
struct update_locker
{
update_locker(display& d, bool lock=true) : disp(d), unlock(lock) {
if(lock) {
disp.lock_updates(true);
}
}
~update_locker() {
unlock_update();
}
void unlock_update() {
if(unlock) {
disp.lock_updates(false);
unlock = false;
}
}
private:
display& disp;
bool unlock;
};
bool angle_is_northern(size_t n);
const std::string& get_angle_direction(size_t n);

View file

@ -480,7 +480,7 @@ LEVEL_RESULT play_level(game_data& gameinfo, const config& game_config,
const hotkey::basic_handler key_events_handler(&gui);
LOG_NG << "first_time..." << (recorder.skipping() ? "skipping" : "no skip") << "\n";
update_locker lock_display(gui,recorder.skipping());
update_locker lock_display(gui.video(),recorder.skipping());
events::raise_draw_event();
if(!loading_game) {
game_events::fire("start");
@ -706,7 +706,7 @@ redo_turn:
{
LOG_NG << "turn event..." << (recorder.skipping() ? "skipping" : "no skip") << "\n";
update_locker lock_display(gui,recorder.skipping());
update_locker lock_display(gui.video(),recorder.skipping());
const std::string turn_num = event_stream.str();
game_events::set_variable("turn_number",turn_num);
game_events::fire("turn " + turn_num);

View file

@ -624,7 +624,7 @@ bool do_replay(display& disp, const gamemap& map, const game_data& gameinfo,
const set_random_generator generator_setter(&replayer);
update_locker lock_update(disp,replayer.skipping());
update_locker lock_update(disp.video(),replayer.skipping());
//a list of units that have promoted from the last attack
std::deque<gamemap::location> advancing_units;

View file

@ -202,7 +202,7 @@ void update_whole_screen()
{
update_all = true;
}
CVideo::CVideo() : bpp(0), fake_screen(false), help_string_(0)
CVideo::CVideo() : bpp(0), fake_screen(false), help_string_(0), updatesLocked_(0)
{
const int res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
@ -213,7 +213,7 @@ CVideo::CVideo() : bpp(0), fake_screen(false), help_string_(0)
}
CVideo::CVideo( int x, int y, int bits_per_pixel, int flags)
: bpp(0), fake_screen(false), help_string_(0)
: bpp(0), fake_screen(false), help_string_(0), updatesLocked_(0)
{
const int res = SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
if(res < 0) {
@ -352,6 +352,19 @@ void CVideo::flip()
halo::unrender();
}
void CVideo::lock_updates(bool value)
{
if(value == true)
++updatesLocked_;
else
--updatesLocked_;
}
bool CVideo::update_locked() const
{
return updatesLocked_ > 0;
}
void CVideo::lock()
{
if( SDL_MUSTLOCK(frameBuffer) )

View file

@ -85,6 +85,14 @@ class CVideo {
void clear_help_string(int handle);
void clear_all_help_strings();
//function to stop the screen being redrawn. Anything that happens while
//the update is locked will be hidden from the user's view.
//note that this function is re-entrant, meaning that if lock_updates(true)
//is called twice, lock_updates(false) must be called twice to unlock
//updates.
void lock_updates(bool value);
bool update_locked() const;
private:
bool mode_changed_;
@ -96,6 +104,33 @@ private:
//variables for help strings
int help_string_;
int updatesLocked_;
};
//an object which will lock the display for the duration of its lifetime.
struct update_locker
{
update_locker(CVideo& v, bool lock=true) : video(v), unlock(lock) {
if(lock) {
video.lock_updates(true);
}
}
~update_locker() {
unlock_update();
}
void unlock_update() {
if(unlock) {
video.lock_updates(false);
unlock = false;
}
}
private:
CVideo& video;
bool unlock;
};
#endif