# HG changeset patch # User Darkvater # Date 1168995064 0 # Node ID 039b96c813b350d9855f6c9e8d43e8dedc45139e # Parent 0ac1952764c7c034d5889225eb164595e2b8cd89 (svn r8178) -Backport from turnk (r8049, r8079, r8080, r8135): - oe more news-window fix and fix up ShowLastNewsMessage (r8049) - float division by 0 in YAPF code on Win9x (r8079, r8080) - do not assert when removing duplicates would remove non-static grf (r8135) diff -r 0ac1952764c7 -r 039b96c813b3 newgrf_config.c --- a/newgrf_config.c Wed Jan 17 00:38:51 2007 +0000 +++ b/newgrf_config.c Wed Jan 17 00:51:04 2007 +0000 @@ -158,7 +158,7 @@ for (prev = list, cur = list->next; cur != NULL; prev = cur, cur = cur->next) { if (cur->grfid != list->grfid) continue; - assert(HASBIT(cur->flags, GCF_STATIC)); + prev->next = cur->next; ClearGRFConfig(&cur); cur = prev; // Just go back one so it continues as normal later on diff -r 0ac1952764c7 -r 039b96c813b3 news_gui.c --- a/news_gui.c Wed Jan 17 00:38:51 2007 +0000 +++ b/news_gui.c Wed Jan 17 00:51:04 2007 +0000 @@ -272,7 +272,6 @@ if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news)) MoveToNextItem(); - _forced_news = INVALID_NEWS; if (_total_news < MAX_NEWS) _total_news++; /* Increase _latest_news. If we have no news yet, use _oldest news as an @@ -555,16 +554,17 @@ void ShowLastNewsMessage(void) { - switch (_forced_news) { - case INVALID_NEWS: // Not forced any news yet, show the current one - ShowNewsMessage(_current_news); - break; - case 0: // - ShowNewsMessage(_total_news != MAX_NEWS ? _latest_news : MAX_NEWS - 1); - break; - default: // 'Scrolling' through news history show each one in turn - ShowNewsMessage(_forced_news - 1); - break; + if (_forced_news == INVALID_NEWS) { + /* Not forced any news yet, show the current one, unless a news window is + * open (which can only be the current one), then show the previous item */ + const Window *w = FindWindowById(WC_NEWS_WINDOW, 0); + ShowNewsMessage((w == NULL) ? _current_news : decreaseIndex(_current_news)); + } else if (_forced_news == _oldest_news) { + /* We have reached the oldest news, start anew with the latest */ + ShowNewsMessage(_latest_news); + } else { + /* 'Scrolling' through news history show each one in turn */ + ShowNewsMessage(decreaseIndex(_forced_news)); } } @@ -889,7 +889,10 @@ (news == INVALID_STRING_ID || ni->string_id == news)) { Window *w; - if (_forced_news == n || _current_news == n) MoveToNextItem(); + /* If we delete a forced news and it is just before the current news + * then we need to advance to the next news (if any) */ + if (_forced_news == n) MoveToNextItem(); + if (_forced_news == INVALID_NEWS && _current_news == n) MoveToNextItem(); _total_news--; /* If this is the last news item, invalidate _latest_news */ @@ -908,7 +911,7 @@ * We also need an update of the current, forced and visible (open window) * news's as this shifting could change the items they were pointing to */ if (_total_news != 0) { - NewsID i, visible_news; + NewsID visible_news, i; w = FindWindowById(WC_NEWS_WINDOW, 0); visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS; diff -r 0ac1952764c7 -r 039b96c813b3 yapf/yapf_base.hpp --- a/yapf/yapf_base.hpp Wed Jan 17 00:38:51 2007 +0000 +++ b/yapf/yapf_base.hpp Wed Jan 17 00:51:04 2007 +0000 @@ -106,19 +106,21 @@ * - or the open list is empty (no route to destination). * - or the maximum amount of loops reached - m_max_search_nodes (default = 10000) * @return true if the path was found */ - inline bool FindPath(const Vehicle* v) + inline bool FindPath(const Vehicle *v) { m_veh = v; +#ifndef NO_DEBUG_MESSAGES CPerformanceTimer perf; perf.Start(); +#endif /* !NO_DEBUG_MESSAGES */ + Yapf().PfSetStartupNodes(); while (true) { m_num_steps++; - Node* n = m_nodes.GetBestOpenNode(); - if (n == NULL) - break; + Node *n = m_nodes.GetBestOpenNode(); + if (n == NULL) break; // if the best open node was worse than the best path found, we can finish if (m_pBestDestNode != NULL && m_pBestDestNode->GetCost() < n->GetCostEstimate()) @@ -135,18 +137,25 @@ } bool bDestFound = (m_pBestDestNode != NULL); - int16 veh_idx = (m_veh != NULL) ? m_veh->unitnumber : 0; - -// if (veh_idx != 433) return bDestFound; - +#ifndef NO_DEBUG_MESSAGES perf.Stop(); - int t = perf.Get(1000000); - _total_pf_time_us += t; - char ttc = Yapf().TransportTypeChar(); - float cache_hit_ratio = (float)m_stats_cache_hits / (float)(m_stats_cache_hits + m_stats_cost_calcs) * 100.0f; - int cost = bDestFound ? m_pBestDestNode->m_cost : -1; - int dist = bDestFound ? m_pBestDestNode->m_estimate - m_pBestDestNode->m_cost : -1; - DEBUG(yapf, 3)("[YAPF][YAPF%c]%c%4d- %d us - %d rounds - %d open - %d closed - CHR %4.1f%% - c%d(sc%d, ts%d, o%d) -- ", ttc, bDestFound ? '-' : '!', veh_idx, t, m_num_steps, m_nodes.OpenCount(), m_nodes.ClosedCount(), cache_hit_ratio, cost, dist, m_perf_cost.Get(1000000), m_perf_slope_cost.Get(1000000), m_perf_ts_cost.Get(1000000), m_perf_other_cost.Get(1000000)); + if (_debug_yapf_level >= 3) { + int t = perf.Get(1000000); + _total_pf_time_us += t; + + UnitID veh_idx = (m_veh != NULL) ? m_veh->unitnumber : 0; + char ttc = Yapf().TransportTypeChar(); + float cache_hit_ratio = (m_stats_cache_hits == 0) ? 0.0f : ((float)m_stats_cache_hits / (float)(m_stats_cache_hits + m_stats_cost_calcs) * 100.0f); + int cost = bDestFound ? m_pBestDestNode->m_cost : -1; + int dist = bDestFound ? m_pBestDestNode->m_estimate - m_pBestDestNode->m_cost : -1; + + DEBUG(yapf, 3) ("[YAPF%c]%c%4d- %d us - %d rounds - %d open - %d closed - CHR %4.1f%% - c%d(sc%d, ts%d, o%d) -- ", + ttc, bDestFound ? '-' : '!', veh_idx, t, m_num_steps, m_nodes.OpenCount(), m_nodes.ClosedCount(), + cache_hit_ratio, cost, dist, m_perf_cost.Get(1000000), m_perf_slope_cost.Get(1000000), + m_perf_ts_cost.Get(1000000), m_perf_other_cost.Get(1000000) + ); + } +#endif /* !NO_DEBUG_MESSAGES */ return bDestFound; }