try to remove some "flickering" by using setActive(false)/setActive() and adding

a glFlush...
This commit is contained in:
ALONSO Laurent
2022-07-13 14:00:17 +02:00
committed by Celtic Minstrel
parent ba435bdfd3
commit f2584f4133
7 changed files with 40 additions and 17 deletions

View File

@@ -1026,7 +1026,7 @@ xBadVal::~xBadVal() throw(){
bool cDialog::doAnimations = false;
void cDialog::draw(){
win.setActive();
win.setActive(false);
tileImage(win,winRect,::bg[bg]);
if(doAnimations && animTimer.getElapsedTime().asMilliseconds() >= 500) {
cPict::advanceAnim();
@@ -1039,6 +1039,7 @@ void cDialog::draw(){
iter++;
}
win.setActive();
win.display();
}

View File

@@ -51,7 +51,7 @@ bool cButton::isScrollable(){
void cButton::draw(){
rectangle from_rect, to_rect;
inWindow->setActive();
inWindow->setActive(false);
if(visible){
TextStyle style;
@@ -86,6 +86,7 @@ void cButton::draw(){
// frame default button, to provide a visual cue that it's the default
if(key.spec && key.k == key_enter) drawFrame(2,frameStyle);
}
inWindow->setActive();
}
bool cButton::manageFormat(eFormat prop, bool set, boost::any* val) {

View File

@@ -89,7 +89,7 @@ bool cLed::manageFormat(eFormat prop, bool set, boost::any* val) {
void cLed::draw(){
rectangle from_rect, to_rect;
inWindow->setActive();
inWindow->setActive(false);
if(visible){
TextStyle style;
@@ -106,6 +106,8 @@ void cLed::draw(){
to_rect.left = frame.left + 18; // Possibly could be 20
win_draw_string(*inWindow,to_rect,lbl,wrapLabel ? eTextMode::WRAP : eTextMode::LEFT_TOP,style);
}
inWindow->setActive();
}
cControl::storage_t cLed::store() {

View File

@@ -621,7 +621,7 @@ void draw_text_bar() {
}
void put_text_bar(std::string str) {
text_bar_gworld.setActive();
text_bar_gworld.setActive(false);
auto& bar_gw = *ResMgr::graphics.get("textbar");
rect_draw_some_item(bar_gw, rectangle(bar_gw), text_bar_gworld, rectangle(bar_gw));
TextStyle style;
@@ -658,12 +658,14 @@ void put_text_bar(std::string str) {
}
}
text_bar_gworld.setActive();
text_bar_gworld.display();
}
void refresh_text_bar() {
mainPtr.setActive();
mainPtr.setActive(false);
rect_draw_some_item(text_bar_gworld.getTexture(), rectangle(text_bar_gworld), mainPtr, win_to_rects[WINRECT_STATUS]);
mainPtr.setActive();
}
// this is used for determinign whether to round off walkway corners
@@ -1561,7 +1563,7 @@ void draw_targeting_line(location where_curs) {
if((can_see_light(from_loc,which_space,sight_obscurity) < 5)
&& (dist(from_loc,which_space) <= current_spell_range)) {
mainPtr.setActive();
mainPtr.setActive(false);
clip_rect(mainPtr, on_screen_terrain_area);
draw_line(mainPtr, where_curs, location(xBound, yBound), 2, {128,128,128}, sf::BlendAdd);
redraw_rect.left = min(where_curs.x,xBound) - 4;
@@ -1602,6 +1604,7 @@ void draw_targeting_line(location where_curs) {
}
redraw_rect2.inset(-5,-5);
mainPtr.setActive();
undo_clip(mainPtr);
}
}

View File

@@ -164,8 +164,9 @@ void apply_light_mask(bool onWindow) {
return;
if(onWindow) {
mainPtr.setActive();
mainPtr.setActive(false);
fill_region(mainPtr, dark_mask_region, sf::Color::Black);
mainPtr.setActive();
return;
}
@@ -355,7 +356,7 @@ void do_missile_anim(short num_steps,location missile_origin,short sound_num) {
to_rect.offset(current_terrain_ul);
rect_draw_some_item(terrain_screen_gworld.getTexture(),oldBounds,mainPtr,to_rect);
mainPtr.setActive();
mainPtr.setActive(false);
// init missile paths
@@ -437,6 +438,7 @@ void do_missile_anim(short num_steps,location missile_origin,short sound_num) {
rect_draw_some_item(*from_gw,from_rect, mainPtr,temp_rect,sf::BlendAlpha);
}
}
mainPtr.setActive();
mainPtr.display();
sf::sleep(sf::milliseconds(2 + 5 * get_int_pref("GameSpeed")));
}
@@ -520,7 +522,7 @@ void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) {
style.font = FONT_BOLD;
style.pointSize = 10;
style.lineHeight = 10;
mainPtr.setActive();
mainPtr.setActive(false);
// init missile paths
screen_ul.x = center.x - 4; screen_ul.y = center.y - 4;
@@ -585,6 +587,7 @@ void do_explosion_anim(short /*sound_num*/,short special_draw, short snd) {
}
}
//if(((PSD[SDF_GAME_SPEED] == 1) && (t % 3 == 0)) || ((PSD[SDF_GAME_SPEED] == 2) && (t % 2 == 0)))
mainPtr.setActive();
mainPtr.display();
sf::sleep(time_in_ticks(2 * (1 + get_int_pref("GameSpeed"))));
}
@@ -639,12 +642,11 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) {
return;
}
talk_gworld.setActive();
TextStyle style;
style.font = FONT_DUNGEON;
style.pointSize = 18;
talk_gworld.setActive();
talk_gworld.setActive(false);
if(pressed) {
clip_rect(talk_gworld, clip_area_rect);
}
@@ -786,6 +788,7 @@ void draw_shop_graphics(bool pressed,rectangle clip_area_rect) {
win_draw_string(talk_gworld,bottom_help_rects[3],"'I' button brings up description.",eTextMode::WRAP,style);
undo_clip(talk_gworld);
talk_gworld.setActive();
talk_gworld.display();
refresh_shopping();
@@ -906,14 +909,14 @@ void place_talk_str(std::string str_to_place,std::string str_to_place2,short col
rectangle dest_rect,help_from = {46,60,59,76};
sf::Text str_to_draw;
talk_gworld.setActive();
talk_gworld.setActive(false);
TextStyle style;
style.font = FONT_DUNGEON;
style.pointSize = 18;
if(c_rect.right > 0) {
mainPtr.setActive();
mainPtr.setActive(false);
c_rect.offset(talk_area_rect.topLeft());
clip_rect(mainPtr, c_rect);
}
@@ -1010,6 +1013,7 @@ void place_talk_str(std::string str_to_place,std::string str_to_place2,short col
}
}
talk_gworld.setActive();
rectangle oldRect(talk_gworld);
undo_clip(talk_gworld);
talk_gworld.display();

View File

@@ -93,7 +93,7 @@ void put_pc_screen() {
rectangle bottom_bar_rect = {99,0,116,271};
rectangle info_from = {0,1,12,13}, switch_from = {0, 13, 12, 25};
pc_stats_gworld.setActive();
pc_stats_gworld.setActive(false);
// First clean up gworld with pretty patterns
sf::Texture& orig = *ResMgr::graphics.get("statarea");
@@ -195,6 +195,7 @@ void put_pc_screen() {
to_draw_rect = {101,251,114,267};
rect_draw_some_item(invenbtn_gworld, help_from_rect, pc_stats_gworld, to_draw_rect, sf::BlendAlpha);
pc_stats_gworld.setActive();
pc_stats_gworld.display();
// Sometimes this gets called when character is slain. when that happens, if items for
@@ -214,7 +215,7 @@ void put_item_screen(eItemWinMode screen_num) {
rectangle erase_rect = {17,2,122,255},dest_rect;
rectangle upper_frame_rect = {3,3,15,268};
item_stats_gworld.setActive();
item_stats_gworld.setActive(false);
// First clean up gworld with pretty patterns
sf::Texture& orig = *ResMgr::graphics.get("inventory");
@@ -360,6 +361,7 @@ void put_item_screen(eItemWinMode screen_num) {
undo_clip(item_stats_gworld);
place_item_bottom_buttons();
item_stats_gworld.setActive();
item_stats_gworld.display();
}
@@ -1052,7 +1054,7 @@ void print_buf () {
bool end_loop = false;
rectangle store_text_rect,dest_rect,erase_rect = {2,2,136,255};
text_area_gworld.setActive();
text_area_gworld.setActive(false);
// First clean up gworld with pretty patterns
tileImage(text_area_gworld, erase_rect,bg[6]);
@@ -1083,6 +1085,7 @@ void print_buf () {
}
text_area_gworld.setActive();
text_area_gworld.display();
}

View File

@@ -1,3 +1,4 @@
#include <SFML/OpenGL.hpp>
#include <cstdio>
#include <queue>
@@ -1388,6 +1389,11 @@ void draw_map(bool need_refresh) {
canMap = false;
}
else if(need_refresh) {
// CHECKME: unsure, but on osx, if mainPtr.setActive() is not called,
// the following code does not update the gworld texture if we are
// called just after closing a dialog
mainPtr.setActive();
map_gworld.setActive();
fill_rect(map_gworld, map_world_rect, sf::Color::Black);
@@ -1472,9 +1478,11 @@ void draw_map(bool need_refresh) {
}
map_gworld.display();
// this stops flickering if the display time is too long
glFlush();
}
mini_map.setActive();
mini_map.setActive(false);
// Now place terrain map gworld
TextStyle style;
@@ -1529,6 +1537,7 @@ void draw_map(bool need_refresh) {
}
}
mini_map.setActive(false);
mini_map.display();
// Now exit gracefully