summaryrefslogtreecommitdiff
path: root/src/engine_gui.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2008-05-27 12:24:23 +0000
committerpeter1138 <peter1138@openttd.org>2008-05-27 12:24:23 +0000
commitf7a9c4f522ed0b929627f68012484a501677546d (patch)
tree598591d68e4b9ad6ce1e2e56259ba09418a15ecd /src/engine_gui.cpp
parent6d46851b61e482965412d2e4b74d1846efefe21d (diff)
downloadopenttd-f7a9c4f522ed0b929627f68012484a501677546d.tar.xz
(svn r13287) -Codechange: move engine list gui code away from engine.cpp (and its headers) to engine_gui.cpp
Diffstat (limited to 'src/engine_gui.cpp')
-rw-r--r--src/engine_gui.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index a67d23fcb..bd48d778a 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -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 @@ void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
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 @ <begin, begin+num_items-1>)
+ * @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);
+}
+