From: <tz...@us...> - 2008-06-22 09:34:44
|
Revision: 2601 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=2601&view=rev Author: tzlaine Date: 2008-06-21 19:48:12 -0700 (Sat, 21 Jun 2008) Log Message: ----------- Made some changes to use the new iterator-based portions of GG::ListBox and GG::DropDownList. Also added instrumentation to the list-building code in TechWnd. Modified Paths: -------------- trunk/FreeOrion/UI/DesignWnd.cpp trunk/FreeOrion/UI/FleetWnd.cpp trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp trunk/FreeOrion/UI/ProductionWnd.cpp trunk/FreeOrion/UI/ResearchWnd.cpp trunk/FreeOrion/UI/SidePanel.cpp trunk/FreeOrion/UI/TechTreeWnd.cpp Modified: trunk/FreeOrion/UI/DesignWnd.cpp =================================================================== --- trunk/FreeOrion/UI/DesignWnd.cpp 2008-06-22 02:19:00 UTC (rev 2600) +++ trunk/FreeOrion/UI/DesignWnd.cpp 2008-06-22 02:48:12 UTC (rev 2601) @@ -837,8 +837,9 @@ CUIListBox::SizeMove(ul, lr); if (old_size != Size()) { const GG::Pt row_size = ListRowSize(); - for (int i = 0; i < NumRows(); ++i) - GetRow(i).Resize(row_size); + for (GG::ListBox::iterator it = Begin(); it != End(); ++it) { + (*it)->Resize(row_size); + } } } Modified: trunk/FreeOrion/UI/FleetWnd.cpp =================================================================== --- trunk/FreeOrion/UI/FleetWnd.cpp 2008-06-22 02:19:00 UTC (rev 2600) +++ trunk/FreeOrion/UI/FleetWnd.cpp 2008-06-22 02:48:12 UTC (rev 2601) @@ -1017,8 +1017,9 @@ void FleetDetailPanel::ShipSelectionChanged(const std::set<int>& rows) { - for (int i = 0; i < m_ships_lb->NumRows(); ++i) { - ShipDataPanel* ship_panel = boost::polymorphic_downcast<ShipDataPanel*>(m_ships_lb->GetRow(i)[0]); + std::size_t i = 0; + for (GG::ListBox::iterator it = m_ships_lb->Begin(); it != m_ships_lb->End(); ++it, ++i) { + ShipDataPanel* ship_panel = boost::polymorphic_downcast<ShipDataPanel*>((**it)[0]); ship_panel->Select(rows.find(i) != rows.end()); } } @@ -1280,8 +1281,9 @@ void FleetWnd::SelectFleet(Fleet* fleet) { - for (int i = 0; i < m_fleets_lb->NumRows(); i++) { - FleetRow* row = dynamic_cast<FleetRow*>(&m_fleets_lb->GetRow(i)); + std::size_t i = 0; + for (GG::ListBox::iterator it = m_fleets_lb->Begin(); it != m_fleets_lb->End(); ++it, ++i) { + FleetRow* row = dynamic_cast<FleetRow*>(*it); if (row && row->m_fleet == fleet) { m_fleets_lb->DeselectAll(); m_fleets_lb->SelectRow(i); @@ -1338,8 +1340,9 @@ Fleet* fleet = 0 <= m_current_fleet ? FleetInRow(m_current_fleet) : 0; m_fleet_detail_panel->SetFleet(fleet); - for (int i = 0; i < m_fleets_lb->NumRows(); ++i) { - FleetDataPanel* fleet_panel = boost::polymorphic_downcast<FleetDataPanel*>(m_fleets_lb->GetRow(i)[0]); + std::size_t i = 0; + for (GG::ListBox::iterator it = m_fleets_lb->Begin(); it != m_fleets_lb->End(); ++it, ++i) { + FleetDataPanel* fleet_panel = boost::polymorphic_downcast<FleetDataPanel*>((**it)[0]); fleet_panel->Select(rows.find(i) != rows.end()); } } Modified: trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp 2008-06-22 02:19:00 UTC (rev 2600) +++ trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp 2008-06-22 02:48:12 UTC (rev 2601) @@ -18,6 +18,7 @@ # define BOOST_MSVC -1 #endif +#include <boost/cast.hpp> #include <boost/serialization/vector.hpp> #include <GG/Button.h> @@ -306,9 +307,9 @@ { std::string player_name = m_lobby_data.m_players[player_id].m_player_name; m_lobby_data.m_players.erase(player_id); - for (int i = 0; i < m_players_lb->NumRows(); ++i) { - if (player_name == m_players_lb->GetRow(i)[0]->WindowText()) { - delete m_players_lb->Erase(i); + for (GG::ListBox::iterator it = m_players_lb->Begin(); it != m_players_lb->End(); ++it) { + if (player_name == (**it)[0]->WindowText()) { + delete m_players_lb->Erase(it); break; } } @@ -363,9 +364,8 @@ void MultiplayerLobbyWnd::PlayerDataChanged() { m_lobby_data.m_players.clear(); - for (int i = 0; i < m_players_lb->NumRows(); ++i) { - const PlayerRow* row = dynamic_cast<const PlayerRow*>(&m_players_lb->GetRow(i)); - assert(row); + for (GG::ListBox::iterator it = m_players_lb->Begin(); it != m_players_lb->End(); ++it) { + const PlayerRow* row = boost::polymorphic_downcast<const PlayerRow*>(*it); m_lobby_data.m_players[row->m_player_data.m_player_id] = row->m_player_data; } if (m_host) @@ -431,8 +431,8 @@ { std::set<std::string> empire_names; std::set<unsigned int> empire_colors; - for (int i = 0; i < m_players_lb->NumRows(); ++i) { - const PlayerRow& row = dynamic_cast<const PlayerRow&>(m_players_lb->GetRow(i)); + for (GG::ListBox::iterator it = m_players_lb->Begin(); it != m_players_lb->End(); ++it) { + const PlayerRow& row = dynamic_cast<const PlayerRow&>(**it); if (row.m_player_data.m_empire_name.empty()) return false; empire_names.insert(row.m_player_data.m_empire_name); Modified: trunk/FreeOrion/UI/ProductionWnd.cpp =================================================================== --- trunk/FreeOrion/UI/ProductionWnd.cpp 2008-06-22 02:19:00 UTC (rev 2600) +++ trunk/FreeOrion/UI/ProductionWnd.cpp 2008-06-22 02:48:12 UTC (rev 2601) @@ -59,14 +59,7 @@ assert(wnds.size() == 1); assert((*wnds.begin())->DragDropDataType() == "PRODUCTION_QUEUE_ROW"); GG::ListBox::Row* row = boost::polymorphic_downcast<GG::ListBox::Row*>(*wnds.begin()); - int original_row_idx = -1; - for (int i = 0; i < NumRows(); ++i) { - if (&GetRow(i) == row) { - original_row_idx = i; - break; - } - } - assert(original_row_idx != -1); + assert(std::find(Begin(), End(), row) != End()); int row_idx = RowUnderPt(pt); if (row_idx < 0 || row_idx > NumRows()) row_idx = NumRows(); Modified: trunk/FreeOrion/UI/ResearchWnd.cpp =================================================================== --- trunk/FreeOrion/UI/ResearchWnd.cpp 2008-06-22 02:19:00 UTC (rev 2600) +++ trunk/FreeOrion/UI/ResearchWnd.cpp 2008-06-22 02:48:12 UTC (rev 2601) @@ -60,14 +60,7 @@ assert(wnds.size() == 1); GG::ListBox::Row* row = boost::polymorphic_downcast<GG::ListBox::Row*>(*wnds.begin()); - int original_row_idx = -1; - for (int i = 0; i < NumRows(); ++i) { - if (&GetRow(i) == row) { - original_row_idx = i; - break; - } - } - assert(original_row_idx != -1); + assert(std::find(Begin(), End(), row) != End()); int row_idx = RowUnderPt(pt); if (row_idx < 0 || row_idx > NumRows()) row_idx = NumRows(); Modified: trunk/FreeOrion/UI/SidePanel.cpp =================================================================== --- trunk/FreeOrion/UI/SidePanel.cpp 2008-06-22 02:19:00 UTC (rev 2600) +++ trunk/FreeOrion/UI/SidePanel.cpp 2008-06-22 02:48:12 UTC (rev 2601) @@ -1354,8 +1354,9 @@ int drop_height = std::min(TEXT_ROW_HEIGHT * system_names_in_droplist, MAX_DROPLIST_DROP_HEIGHT) + TOTAL_LISTBOX_MARGIN; m_system_name->SetDropHeight(drop_height); - for (int i = 0; i < m_system_name->NumRows(); i++) { - if (select_row == &m_system_name->GetRow(i)) { + std::size_t i = 0; + for (GG::ListBox::iterator it = m_system_name->Begin(); it != m_system_name->End(); ++it, ++i) { + if (select_row == *it) { m_system_name->Select(i); break; } Modified: trunk/FreeOrion/UI/TechTreeWnd.cpp =================================================================== --- trunk/FreeOrion/UI/TechTreeWnd.cpp 2008-06-22 02:19:00 UTC (rev 2600) +++ trunk/FreeOrion/UI/TechTreeWnd.cpp 2008-06-22 02:48:12 UTC (rev 2601) @@ -20,7 +20,9 @@ #include <boost/format.hpp> #include <algorithm> +#include <boost/timer.hpp> + namespace { // command-line options void AddOptions(OptionsDB& db) @@ -1030,8 +1032,8 @@ { m_lb->Resize(ClientSize() - GG::Pt(2*LB_MARGIN_X, 2*LB_MARGIN_Y)); - for (int i = 0; i < m_lb->NumRows(); ++i) { - GG::ListBox::Row& row = m_lb->GetRow(i); + for (GG::ListBox::iterator it = m_lb->Begin(); it != m_lb->End(); ++it) { + GG::ListBox::Row& row = **it; GG::Pt size = GG::Pt(m_lb->Width() - 4*LB_MARGIN_X, row.Height()); row.Resize(size); GG::Control* control = row.at(0); @@ -1894,6 +1896,8 @@ // default edge properties agedgeattr(graph, "tailclip", "false"); + Logger().debugStream() << "Tech Tree Layout Preparing Tech Data"; + std::map<std::string, Agnode_t*> name_to_node_map; TechManager& manager = GetTechManager(); for (TechManager::iterator it = manager.begin(); it != manager.end(); ++it) { @@ -1915,8 +1919,12 @@ } } + Logger().debugStream() << "Tech Tree Layout Doing Graph Layout"; + gvLayout(gvc, graph, "dot"); + Logger().debugStream() << "Tech Tree Layout Creating Panels"; + // create new tech panels and new dependency arcs m_dependency_arcs.clear(); //const std::set<const Tech*>& collapsed_subtree_techs = m_collapsed_subtree_techs_per_view[m_category_shown]; @@ -1968,6 +1976,8 @@ agclose(graph); + Logger().debugStream() << "Tech Tree Layout Done"; + if (keep_position) { m_vscroll->ScrollTo(final_position.y); m_hscroll->ScrollTo(final_position.x); @@ -2278,12 +2288,28 @@ // remove techs in listbox Clear(); + Logger().debugStream() << "Tech List Box Populating"; + TechManager& manager = GetTechManager(); + double creation_elapsed = 0.0; + double insertion_elapsed = 0.0; + boost::timer creation_timer; + boost::timer insertion_timer; for (TechManager::iterator it = manager.begin(); it != manager.end(); ++it) { const Tech* tech = *it; - if (TechVisible(tech)) - Insert(new TechRow(Width() - ClientUI::ScrollWidth() - 6, tech)); + if (TechVisible(tech)) { + creation_timer.restart(); + TechRow* tr = new TechRow(Width() - ClientUI::ScrollWidth() - 6, tech); + creation_elapsed += creation_timer.elapsed(); + insertion_timer.restart(); + Insert(tr); + insertion_elapsed += insertion_timer.elapsed(); + } } + + Logger().debugStream() << "Tech List Box Done Populating"; + Logger().debugStream() << " Creation time=" << (creation_elapsed * 1000); + Logger().debugStream() << " Insertion time=" << (insertion_elapsed * 1000); } void TechTreeWnd::TechListBox::ShowCategory(const std::string& category) |