mirror of https://github.com/OpenTTD/OpenTTD
Codechange: explicitly initialise StoryPage and StoryPageElement member variables
parent
8a4493f990
commit
6327fa4623
|
@ -37,6 +37,15 @@ StoryPagePool _story_page_pool("StoryPage");
|
||||||
INSTANTIATE_POOL_METHODS(StoryPageElement)
|
INSTANTIATE_POOL_METHODS(StoryPageElement)
|
||||||
INSTANTIATE_POOL_METHODS(StoryPage)
|
INSTANTIATE_POOL_METHODS(StoryPage)
|
||||||
|
|
||||||
|
StoryPage::~StoryPage()
|
||||||
|
{
|
||||||
|
if (!this->CleaningPool()) {
|
||||||
|
for (StoryPageElement *spe : StoryPageElement::Iterate()) {
|
||||||
|
if (spe->page == this->index) delete spe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This helper for Create/Update PageElement Cmd procedure verifies if the page
|
* This helper for Create/Update PageElement Cmd procedure verifies if the page
|
||||||
* element parameters are correct for the given page element type.
|
* element parameters are correct for the given page element type.
|
||||||
|
@ -219,11 +228,7 @@ std::tuple<CommandCost, StoryPageID> CmdCreateStoryPage(DoCommandFlags flags, Co
|
||||||
_story_page_next_sort_value = 0;
|
_story_page_next_sort_value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
StoryPage *s = new StoryPage();
|
StoryPage *s = new StoryPage(_story_page_next_sort_value, TimerGameCalendar::date, company, text);
|
||||||
s->sort_value = _story_page_next_sort_value;
|
|
||||||
s->date = TimerGameCalendar::date;
|
|
||||||
s->company = company;
|
|
||||||
s->title = text;
|
|
||||||
|
|
||||||
InvalidateWindowClassesData(WC_STORY_BOOK, -1);
|
InvalidateWindowClassesData(WC_STORY_BOOK, -1);
|
||||||
if (StoryPage::GetNumItems() == 1) InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
|
if (StoryPage::GetNumItems() == 1) InvalidateWindowData(WC_MAIN_TOOLBAR, 0);
|
||||||
|
@ -267,10 +272,7 @@ std::tuple<CommandCost, StoryPageElementID> CmdCreateStoryPageElement(DoCommandF
|
||||||
_story_page_element_next_sort_value = 0;
|
_story_page_element_next_sort_value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
StoryPageElement *pe = new StoryPageElement();
|
StoryPageElement *pe = new StoryPageElement(_story_page_element_next_sort_value, type, page_id);
|
||||||
pe->sort_value = _story_page_element_next_sort_value;
|
|
||||||
pe->type = type;
|
|
||||||
pe->page = page_id;
|
|
||||||
UpdateElement(*pe, tile, reference, text);
|
UpdateElement(*pe, tile, reference, text);
|
||||||
|
|
||||||
InvalidateWindowClassesData(WC_STORY_BOOK, page_id);
|
InvalidateWindowClassesData(WC_STORY_BOOK, page_id);
|
||||||
|
|
|
@ -120,7 +120,7 @@ inline bool IsValidStoryPageButtonCursor(StoryPageButtonCursor cursor)
|
||||||
|
|
||||||
/** Helper to construct packed "id" values for button-type StoryPageElement */
|
/** Helper to construct packed "id" values for button-type StoryPageElement */
|
||||||
struct StoryPageButtonData {
|
struct StoryPageButtonData {
|
||||||
uint32_t referenced_id;
|
uint32_t referenced_id = 0;
|
||||||
|
|
||||||
void SetColour(Colours button_colour);
|
void SetColour(Colours button_colour);
|
||||||
void SetFlags(StoryPageButtonFlags flags);
|
void SetFlags(StoryPageButtonFlags flags);
|
||||||
|
@ -152,38 +152,32 @@ struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_po
|
||||||
/**
|
/**
|
||||||
* We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
|
* We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
|
||||||
*/
|
*/
|
||||||
inline StoryPageElement() { }
|
StoryPageElement() { }
|
||||||
|
StoryPageElement(uint32_t sort_value, StoryPageElementType type, StoryPageID page) :
|
||||||
|
sort_value(sort_value), page(page), type(type) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
|
* (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
|
||||||
*/
|
*/
|
||||||
inline ~StoryPageElement() { }
|
~StoryPageElement() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Struct about stories, current and completed */
|
/** Struct about stories, current and completed */
|
||||||
struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
|
struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
|
||||||
uint32_t sort_value; ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index.
|
uint32_t sort_value = 0; ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index.
|
||||||
TimerGameCalendar::Date date; ///< Date when the page was created.
|
TimerGameCalendar::Date date{}; ///< Date when the page was created.
|
||||||
CompanyID company; ///< StoryPage is for a specific company; CompanyID::Invalid() if it is global
|
CompanyID company = CompanyID::Invalid(); ///< StoryPage is for a specific company; CompanyID::Invalid() if it is global
|
||||||
|
|
||||||
std::string title; ///< Title of story page
|
std::string title; ///< Title of story page
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
|
* We need an (empty) constructor so struct isn't zeroed (as C++ standard states)
|
||||||
*/
|
*/
|
||||||
inline StoryPage() { }
|
StoryPage() { }
|
||||||
|
StoryPage(uint32_t sort_value, TimerGameCalendar::Date date, CompanyID company, const std::string &title) :
|
||||||
|
sort_value(sort_value), date(date), company(company), title(title) {}
|
||||||
|
|
||||||
/**
|
~StoryPage();
|
||||||
* (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
|
|
||||||
*/
|
|
||||||
inline ~StoryPage()
|
|
||||||
{
|
|
||||||
if (!this->CleaningPool()) {
|
|
||||||
for (StoryPageElement *spe : StoryPageElement::Iterate()) {
|
|
||||||
if (spe->page == this->index) delete spe;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* STORY_BASE_H */
|
#endif /* STORY_BASE_H */
|
||||||
|
|
Loading…
Reference in New Issue