Process feedback from code review

This commit is contained in:
Gymnasiast 2019-06-18 20:14:26 +02:00
parent 1265913bdb
commit 9de2819cef
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
3 changed files with 13 additions and 36 deletions

View File

@ -432,7 +432,7 @@ static void window_editor_inventions_list_scrollmousedown(rct_window* w, int32_t
return; return;
// Disallow picking up always-researched items // Disallow picking up always-researched items
if (researchItem->rawValue < RESEARCHED_ITEMS_END_2 || research_item_is_always_researched(researchItem)) if (research_item_is_always_researched(researchItem))
return; return;
w->Invalidate(); w->Invalidate();
@ -485,8 +485,7 @@ static void window_editor_inventions_list_cursor(
// Use the open hand as cursor for items that can be picked up // Use the open hand as cursor for items that can be picked up
researchItem = window_editor_inventions_list_get_item_from_scroll_y(scrollIndex, y); researchItem = window_editor_inventions_list_get_item_from_scroll_y(scrollIndex, y);
if (researchItem != nullptr && researchItem->rawValue >= RESEARCHED_ITEMS_END_2 if (researchItem != nullptr && !research_item_is_always_researched(researchItem))
&& !research_item_is_always_researched(researchItem))
{ {
*cursorId = CURSOR_HAND_OPEN; *cursorId = CURSOR_HAND_OPEN;
} }

View File

@ -759,7 +759,7 @@ void research_fix()
rct_ride_entry* rideEntry = get_ride_entry(researchItem.entryIndex); rct_ride_entry* rideEntry = get_ride_entry(researchItem.entryIndex);
if (rideEntry == nullptr) if (rideEntry == nullptr)
{ {
gResearchItemsInvented.erase(it); it = gResearchItemsInvented.erase(it);
} }
else else
{ {
@ -771,7 +771,7 @@ void research_fix()
rct_scenery_group_entry* sceneryGroupEntry = get_scenery_group_entry(researchItem.rawValue); rct_scenery_group_entry* sceneryGroupEntry = get_scenery_group_entry(researchItem.rawValue);
if (sceneryGroupEntry == nullptr) if (sceneryGroupEntry == nullptr)
{ {
gResearchItemsInvented.erase(it); it = gResearchItemsInvented.erase(it);
} }
else else
{ {
@ -787,7 +787,7 @@ void research_fix()
rct_ride_entry* rideEntry = get_ride_entry(researchItem.entryIndex); rct_ride_entry* rideEntry = get_ride_entry(researchItem.entryIndex);
if (rideEntry == nullptr) if (rideEntry == nullptr)
{ {
gResearchItemsUninvented.erase(it); it = gResearchItemsUninvented.erase(it);
} }
else else
{ {
@ -799,7 +799,7 @@ void research_fix()
rct_scenery_group_entry* sceneryGroupEntry = get_scenery_group_entry(researchItem.rawValue); rct_scenery_group_entry* sceneryGroupEntry = get_scenery_group_entry(researchItem.rawValue);
if (sceneryGroupEntry == nullptr) if (sceneryGroupEntry == nullptr)
{ {
gResearchItemsUninvented.erase(it); it = gResearchItemsUninvented.erase(it);
} }
else else
{ {
@ -849,22 +849,16 @@ void research_fix()
void research_items_make_all_unresearched() void research_items_make_all_unresearched()
{ {
for (auto it = gResearchItemsInvented.begin(); it != gResearchItemsInvented.end();) gResearchItemsUninvented.insert(
{ gResearchItemsUninvented.end(), std::make_move_iterator(gResearchItemsInvented.begin()),
auto& researchItem = *it; std::make_move_iterator(gResearchItemsInvented.end()));
gResearchItemsUninvented.push_back(researchItem);
gResearchItemsInvented.erase(it);
}
} }
void research_items_make_all_researched() void research_items_make_all_researched()
{ {
for (auto it = gResearchItemsUninvented.begin(); it != gResearchItemsUninvented.end();) gResearchItemsInvented.insert(
{ gResearchItemsInvented.end(), std::make_move_iterator(gResearchItemsUninvented.begin()),
auto& researchItem = *it; std::make_move_iterator(gResearchItemsUninvented.end()));
gResearchItemsInvented.push_back(researchItem);
gResearchItemsUninvented.erase(it);
}
} }
/** /**
@ -873,20 +867,7 @@ void research_items_make_all_researched()
*/ */
void research_items_shuffle() void research_items_shuffle()
{ {
// Count non pre-researched items std::shuffle(std::begin(gResearchItemsUninvented), std::end(gResearchItemsUninvented), std::default_random_engine{});
size_t numNonResearchedItems = gResearchItemsUninvented.size();
// Shuffle list
for (size_t i = 0; i < numNonResearchedItems; i++)
{
size_t ri = util_rand() % numNonResearchedItems;
if (ri == i)
continue;
ResearchItem researchItemTemp = gResearchItemsUninvented[i];
gResearchItemsUninvented[i] = gResearchItemsUninvented[ri];
gResearchItemsUninvented[ri] = researchItemTemp;
}
} }
bool research_item_is_always_researched(const ResearchItem* researchItem) bool research_item_is_always_researched(const ResearchItem* researchItem)

View File

@ -15,7 +15,6 @@
struct rct_ride_entry; struct rct_ride_entry;
#pragma pack(push, 1)
struct ResearchItem struct ResearchItem
{ {
// Bit 16 (0: scenery entry, 1: ride entry) // Bit 16 (0: scenery entry, 1: ride entry)
@ -36,8 +35,6 @@ struct ResearchItem
bool Equals(const ResearchItem* otherItem) const; bool Equals(const ResearchItem* otherItem) const;
bool Exists() const; bool Exists() const;
}; };
assert_struct_size(ResearchItem, 5);
#pragma pack(pop)
enum enum
{ {