1
0
Fork 0

(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)
release/0.5
Darkvater 2007-01-17 00:51:04 +00:00
parent 8576c2cc40
commit c73bbe531e
3 changed files with 41 additions and 29 deletions

View File

@ -158,7 +158,7 @@ static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list)
for (prev = list, cur = list->next; cur != NULL; prev = cur, cur = cur->next) { for (prev = list, cur = list->next; cur != NULL; prev = cur, cur = cur->next) {
if (cur->grfid != list->grfid) continue; if (cur->grfid != list->grfid) continue;
assert(HASBIT(cur->flags, GCF_STATIC));
prev->next = cur->next; prev->next = cur->next;
ClearGRFConfig(&cur); ClearGRFConfig(&cur);
cur = prev; // Just go back one so it continues as normal later on cur = prev; // Just go back one so it continues as normal later on

View File

@ -272,7 +272,6 @@ void AddNewsItem(StringID string, uint32 flags, uint data_a, uint data_b)
if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news)) if (_total_news == MAX_NEWS && (_oldest_news == _current_news || _oldest_news == _forced_news))
MoveToNextItem(); MoveToNextItem();
_forced_news = INVALID_NEWS;
if (_total_news < MAX_NEWS) _total_news++; if (_total_news < MAX_NEWS) _total_news++;
/* Increase _latest_news. If we have no news yet, use _oldest news as an /* Increase _latest_news. If we have no news yet, use _oldest news as an
@ -555,16 +554,17 @@ static void ShowNewsMessage(NewsID i)
void ShowLastNewsMessage(void) void ShowLastNewsMessage(void)
{ {
switch (_forced_news) { if (_forced_news == INVALID_NEWS) {
case INVALID_NEWS: // Not forced any news yet, show the current one /* Not forced any news yet, show the current one, unless a news window is
ShowNewsMessage(_current_news); * open (which can only be the current one), then show the previous item */
break; const Window *w = FindWindowById(WC_NEWS_WINDOW, 0);
case 0: // ShowNewsMessage((w == NULL) ? _current_news : decreaseIndex(_current_news));
ShowNewsMessage(_total_news != MAX_NEWS ? _latest_news : MAX_NEWS - 1); } else if (_forced_news == _oldest_news) {
break; /* We have reached the oldest news, start anew with the latest */
default: // 'Scrolling' through news history show each one in turn ShowNewsMessage(_latest_news);
ShowNewsMessage(_forced_news - 1); } else {
break; /* 'Scrolling' through news history show each one in turn */
ShowNewsMessage(decreaseIndex(_forced_news));
} }
} }
@ -889,7 +889,10 @@ void DeleteVehicleNews(VehicleID vid, StringID news)
(news == INVALID_STRING_ID || ni->string_id == news)) { (news == INVALID_STRING_ID || ni->string_id == news)) {
Window *w; 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--; _total_news--;
/* If this is the last news item, invalidate _latest_news */ /* If this is the last news item, invalidate _latest_news */
@ -908,7 +911,7 @@ void DeleteVehicleNews(VehicleID vid, StringID news)
* We also need an update of the current, forced and visible (open window) * 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 */ * news's as this shifting could change the items they were pointing to */
if (_total_news != 0) { if (_total_news != 0) {
NewsID i, visible_news; NewsID visible_news, i;
w = FindWindowById(WC_NEWS_WINDOW, 0); w = FindWindowById(WC_NEWS_WINDOW, 0);
visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS; visible_news = (w != NULL) ? (NewsID)(WP(w, news_d).ni - _news_items) : INVALID_NEWS;

View File

@ -106,19 +106,21 @@ public:
* - or the open list is empty (no route to destination). * - or the open list is empty (no route to destination).
* - or the maximum amount of loops reached - m_max_search_nodes (default = 10000) * - or the maximum amount of loops reached - m_max_search_nodes (default = 10000)
* @return true if the path was found */ * @return true if the path was found */
inline bool FindPath(const Vehicle* v) inline bool FindPath(const Vehicle *v)
{ {
m_veh = v; m_veh = v;
#ifndef NO_DEBUG_MESSAGES
CPerformanceTimer perf; CPerformanceTimer perf;
perf.Start(); perf.Start();
#endif /* !NO_DEBUG_MESSAGES */
Yapf().PfSetStartupNodes(); Yapf().PfSetStartupNodes();
while (true) { while (true) {
m_num_steps++; m_num_steps++;
Node* n = m_nodes.GetBestOpenNode(); Node *n = m_nodes.GetBestOpenNode();
if (n == NULL) if (n == NULL) break;
break;
// if the best open node was worse than the best path found, we can finish // if the best open node was worse than the best path found, we can finish
if (m_pBestDestNode != NULL && m_pBestDestNode->GetCost() < n->GetCostEstimate()) if (m_pBestDestNode != NULL && m_pBestDestNode->GetCost() < n->GetCostEstimate())
@ -135,18 +137,25 @@ public:
} }
bool bDestFound = (m_pBestDestNode != NULL); bool bDestFound = (m_pBestDestNode != NULL);
int16 veh_idx = (m_veh != NULL) ? m_veh->unitnumber : 0; #ifndef NO_DEBUG_MESSAGES
// if (veh_idx != 433) return bDestFound;
perf.Stop(); perf.Stop();
if (_debug_yapf_level >= 3) {
int t = perf.Get(1000000); int t = perf.Get(1000000);
_total_pf_time_us += t; _total_pf_time_us += t;
UnitID veh_idx = (m_veh != NULL) ? m_veh->unitnumber : 0;
char ttc = Yapf().TransportTypeChar(); char ttc = Yapf().TransportTypeChar();
float cache_hit_ratio = (float)m_stats_cache_hits / (float)(m_stats_cache_hits + m_stats_cost_calcs) * 100.0f; 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 cost = bDestFound ? m_pBestDestNode->m_cost : -1;
int dist = bDestFound ? m_pBestDestNode->m_estimate - 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));
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; return bDestFound;
} }