(svn r18088) -Codechange: remove CompareWidgetArrays

This commit is contained in:
rubidium 2009-11-15 10:38:04 +00:00
parent 9396a701fe
commit 884561f431
3 changed files with 3 additions and 61 deletions

View File

@ -2329,50 +2329,6 @@ static Widget *InitializeNWidgets(NWidgetBase *nwid, bool rtl, int biggest_index
return widgets; return widgets;
} }
/**
* Compare two widget arrays with each other, and report differences.
* @param orig Pointer to original widget array.
* @param gen Pointer to generated widget array (from the nested widgets).
* @param report Report differences to 'misc' debug stream.
* @return Both widget arrays are equal.
*/
bool CompareWidgetArrays(const Widget *orig, const Widget *gen, bool report)
{
#define CHECK(var, prn) \
if (ow->var != gw->var) { \
same = false; \
if (report) DEBUG(misc, 1, "index %d, \"" #var "\" field: original " prn ", generated " prn, idx, ow->var, gw->var); \
}
#define CHECK_COORD(var) \
if (ow->var != gw->var) { \
same = false; \
if (report) DEBUG(misc, 1, "index %d, \"" #var "\" field: original %d, generated %d, (difference %d)", idx, ow->var, gw->var, ow->var - gw->var); \
}
bool same = true;
for (int idx = 0; ; idx++) {
const Widget *ow = orig + idx;
const Widget *gw = gen + idx;
CHECK(type, "%d")
CHECK(display_flags, "0x%x")
CHECK(colour, "%d")
CHECK_COORD(left)
CHECK_COORD(right)
CHECK_COORD(top)
CHECK_COORD(bottom)
CHECK(data, "%u")
CHECK(tooltips, "%u")
if (ow->type == WWT_LAST || gw->type == WWT_LAST) break;
}
return same;
#undef CHECK
#undef CHECK_COORD
}
/* == Conversion code from NWidgetPart array to NWidgetBase* tree == */ /* == Conversion code from NWidgetPart array to NWidgetBase* tree == */
/** /**
@ -2592,14 +2548,13 @@ NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count, int *biggest
* Also cache the result and use the cache if possible. * Also cache the result and use the cache if possible.
* @param[in] parts Array with parts of the widgets. * @param[in] parts Array with parts of the widgets.
* @param parts_length Length of the \a parts array. * @param parts_length Length of the \a parts array.
* @param[in] orig_wid Pointer to original widget array.
* @param wid_cache Pointer to the cache for storing the generated widget array (use \c NULL to prevent caching). * @param wid_cache Pointer to the cache for storing the generated widget array (use \c NULL to prevent caching).
* @return Cached value if available, otherwise the generated widget array. If \a wid_cache is \c NULL, the caller should free the returned array. * @return Cached value if available, otherwise the generated widget array. If \a wid_cache is \c NULL, the caller should free the returned array.
* *
* @pre Before the first call, \c *wid_cache should be \c NULL. * @pre Before the first call, \c *wid_cache should be \c NULL.
* @post The widget array stored in the \c *wid_cache should be free-ed by the caller. * @post The widget array stored in the \c *wid_cache should be free-ed by the caller.
*/ */
const Widget *InitializeWidgetArrayFromNestedWidgets(const NWidgetPart *parts, int parts_length, const Widget *orig_wid, Widget **wid_cache) const Widget *InitializeWidgetArrayFromNestedWidgets(const NWidgetPart *parts, int parts_length, Widget **wid_cache)
{ {
const bool rtl = false; // Direction of the language is left-to-right const bool rtl = false; // Direction of the language is left-to-right
@ -2609,19 +2564,6 @@ const Widget *InitializeWidgetArrayFromNestedWidgets(const NWidgetPart *parts, i
int biggest_index = -1; int biggest_index = -1;
NWidgetContainer *nwid = MakeNWidgets(parts, parts_length, &biggest_index); NWidgetContainer *nwid = MakeNWidgets(parts, parts_length, &biggest_index);
Widget *gen_wid = InitializeNWidgets(nwid, rtl, biggest_index); Widget *gen_wid = InitializeNWidgets(nwid, rtl, biggest_index);
if (!rtl && orig_wid) {
/* There are two descriptions, compare them.
* Comparing only makes sense when using a left-to-right language.
*/
bool ok = CompareWidgetArrays(orig_wid, gen_wid, false);
if (ok) {
DEBUG(misc, 1, "Nested widgets are equal, min-size(%u, %u)", nwid->smallest_x, nwid->smallest_y);
} else {
DEBUG(misc, 0, "Nested widgets give different results");
CompareWidgetArrays(orig_wid, gen_wid, true);
}
}
delete nwid; delete nwid;
if (wid_cache != NULL) *wid_cache = gen_wid; if (wid_cache != NULL) *wid_cache = gen_wid;

View File

@ -829,6 +829,6 @@ static inline NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container = NULL); NWidgetContainer *MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container = NULL);
const Widget *InitializeWidgetArrayFromNestedWidgets(const NWidgetPart *parts, int parts_length, const Widget *orig_wid, Widget **wid_cache); const Widget *InitializeWidgetArrayFromNestedWidgets(const NWidgetPart *parts, int parts_length, Widget **wid_cache);
#endif /* WIDGET_TYPE_H */ #endif /* WIDGET_TYPE_H */

View File

@ -81,7 +81,7 @@ WindowDesc::WindowDesc(int16 left, int16 top, int16 min_width, int16 min_height,
const Widget *WindowDesc::GetWidgets() const const Widget *WindowDesc::GetWidgets() const
{ {
if (this->nwid_parts != NULL) { if (this->nwid_parts != NULL) {
InitializeWidgetArrayFromNestedWidgets(this->nwid_parts, this->nwid_length, NULL, &this->new_widgets); InitializeWidgetArrayFromNestedWidgets(this->nwid_parts, this->nwid_length, &this->new_widgets);
} }
const Widget *wids = this->new_widgets; const Widget *wids = this->new_widgets;
assert(wids != NULL); assert(wids != NULL);