# HG changeset patch # User peter1138 # Date 1211891063 0 # Node ID 0f704b9afd931c69877ea696db823da789e66715 # Parent e3111a03f9c2e265ae084b826f19d36d69bb4f9b (svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp diff -r e3111a03f9c2 -r 0f704b9afd93 projects/openttd_vs80.vcproj --- a/projects/openttd_vs80.vcproj Tue May 27 10:27:30 2008 +0000 +++ b/projects/openttd_vs80.vcproj Tue May 27 12:24:23 2008 +0000 @@ -1000,6 +1000,10 @@ > + + diff -r e3111a03f9c2 -r 0f704b9afd93 projects/openttd_vs90.vcproj --- a/projects/openttd_vs90.vcproj Tue May 27 10:27:30 2008 +0000 +++ b/projects/openttd_vs90.vcproj Tue May 27 12:24:23 2008 +0000 @@ -997,6 +997,10 @@ > + + diff -r e3111a03f9c2 -r 0f704b9afd93 source.list --- a/source.list Tue May 27 10:27:30 2008 +0000 +++ b/source.list Tue May 27 12:24:23 2008 +0000 @@ -175,6 +175,7 @@ core/endian_func.hpp engine_base.h engine_func.h +engine_gui.h engine_type.h core/enum_type.hpp fiber.hpp diff -r e3111a03f9c2 -r 0f704b9afd93 src/autoreplace_gui.cpp --- a/src/autoreplace_gui.cpp Tue May 27 10:27:30 2008 +0000 +++ b/src/autoreplace_gui.cpp Tue May 27 12:24:23 2008 +0000 @@ -22,6 +22,7 @@ #include "engine_func.h" #include "engine_base.h" #include "window_gui.h" +#include "engine_gui.h" #include "table/sprites.h" #include "table/strings.h" diff -r e3111a03f9c2 -r 0f704b9afd93 src/build_vehicle_gui.cpp --- a/src/build_vehicle_gui.cpp Tue May 27 10:27:30 2008 +0000 +++ b/src/build_vehicle_gui.cpp Tue May 27 12:24:23 2008 +0000 @@ -29,6 +29,7 @@ #include "widgets/dropdown_func.h" #include "string_func.h" #include "window_gui.h" +#include "engine_gui.h" #include "table/sprites.h" #include "table/strings.h" diff -r e3111a03f9c2 -r 0f704b9afd93 src/engine.cpp --- a/src/engine.cpp Tue May 27 10:27:30 2008 +0000 +++ b/src/engine.cpp Tue May 27 12:24:23 2008 +0000 @@ -115,34 +115,6 @@ free(this->name); } -/** Sort all items using qsort() and given 'CompareItems' function - * @param el list to be sorted - * @param compare function for evaluation of the quicksort - */ -void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare) -{ - size_t size = el->size(); - /* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems) - * generally, do not sort if there are less than 2 items */ - if (size < 2) return; - qsort(&((*el)[0]), size, sizeof(EngineID), compare); // MorphOS doesn't know vector::at(int) ... -} - -/** Sort selected range of items (on indices @ ) - * @param el list to be sorted - * @param compare function for evaluation of the quicksort - * @param begin start of sorting - * @param num_items count of items to be sorted - */ -void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items) -{ - assert(begin <= (uint)el->size()); - assert(begin + num_items <= (uint)el->size()); - if (num_items < 2) return; - qsort(&((*el)[begin]), num_items, sizeof(EngineID), compare); -} - - /** Sets cached values in Player::num_vehicles and Group::num_vehicles */ void SetCachedEngineCounts() diff -r e3111a03f9c2 -r 0f704b9afd93 src/engine_func.h --- a/src/engine_func.h Tue May 27 10:27:30 2008 +0000 +++ b/src/engine_func.h Tue May 27 12:24:23 2008 +0000 @@ -29,8 +29,4 @@ CargoID GetEngineCargoType(EngineID engine); void SetCachedEngineCounts(); -typedef int CDECL EngList_SortTypeFunction(const void*, const void*); ///< argument type for EngList_Sort() -void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare); ///< qsort of the engine list -void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); ///< qsort of specified portion of the engine list - #endif /* ENGINE_H */ diff -r e3111a03f9c2 -r 0f704b9afd93 src/engine_gui.cpp --- a/src/engine_gui.cpp Tue May 27 10:27:30 2008 +0000 +++ b/src/engine_gui.cpp Tue May 27 12:24:23 2008 +0000 @@ -15,6 +15,7 @@ #include "variables.h" #include "newgrf_engine.h" #include "strings_func.h" +#include "engine_gui.h" #include "table/strings.h" #include "table/sprites.h" @@ -190,3 +191,32 @@ GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY | (1 << USE_COLORTABLE)); dei->info_proc(engine, w->width >> 1, 129, w->width - 52); } + + +/** Sort all items using qsort() and given 'CompareItems' function + * @param el list to be sorted + * @param compare function for evaluation of the quicksort + */ +void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare) +{ + size_t size = el->size(); + /* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems) + * generally, do not sort if there are less than 2 items */ + if (size < 2) return; + qsort(&((*el)[0]), size, sizeof(EngineID), compare); // MorphOS doesn't know vector::at(int) ... +} + +/** Sort selected range of items (on indices @ ) + * @param el list to be sorted + * @param compare function for evaluation of the quicksort + * @param begin start of sorting + * @param num_items count of items to be sorted + */ +void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items) +{ + assert(begin <= (uint)el->size()); + assert(begin + num_items <= (uint)el->size()); + if (num_items < 2) return; + qsort(&((*el)[begin]), num_items, sizeof(EngineID), compare); +} + diff -r e3111a03f9c2 -r 0f704b9afd93 src/engine_gui.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/engine_gui.h Tue May 27 12:24:23 2008 +0000 @@ -0,0 +1,16 @@ +/* $Id$ */ + +/** @file engine_gui.h Engine GUI functions, used by build_vehicle_gui and autoreplace_gui */ + +#ifndef ENGINE_GUI_H +#define ENGINE_GUI_H + +#include + +typedef std::vector EngineList; + +typedef int CDECL EngList_SortTypeFunction(const void*, const void*); ///< argument type for EngList_Sort() +void EngList_Sort(EngineList *el, EngList_SortTypeFunction compare); ///< qsort of the engine list +void EngList_SortPartial(EngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items); ///< qsort of specified portion of the engine list + +#endif /* ENGINE_GUI_H */ diff -r e3111a03f9c2 -r 0f704b9afd93 src/engine_type.h --- a/src/engine_type.h Tue May 27 10:27:30 2008 +0000 +++ b/src/engine_type.h Tue May 27 12:24:23 2008 +0000 @@ -14,11 +14,8 @@ #include "player_type.h" #include "strings_type.h" -#include - typedef uint16 EngineID; typedef uint16 EngineRenewID; -typedef std::vector EngineList; ///< engine list type struct Engine;