summaryrefslogtreecommitdiff
path: root/depot_gui.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-10-05 12:59:28 +0000
committerbjarni <bjarni@openttd.org>2006-10-05 12:59:28 +0000
commitea075f78e04cc5675e890f82e181276ebc6b6f00 (patch)
tree4a3d21fb89f88716ad9e908b35bbfc8df30e3ed2 /depot_gui.c
parenta9478f810cb260c5f180ece9e38b2d6b4bbc94fe (diff)
downloadopenttd-ea075f78e04cc5675e890f82e181276ebc6b6f00.tar.xz
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
This gives the ability to invalidate some window data and recalculate as needed instead of doing it for each WE_PAINT This event is called right away when using InvalidateWindowData(), so it may be a good idea to set a bool or similar in the window or similar and then act on that bool in WE_PAINT instead of doing a lot of stuff in WE_INVALIDATE_DATA as it might be called more than once before WE_PAINT is called InvalidateWindowData() will not automatically repaint the window, so if you want to repaint it as well, you need to mark it dirty as well. Made the depot windows use WE_INVALIDATE_DATA to set when to generate the engine and wagon lists instead of at each redraw It makes no sense to regenerate the list when say using the scrollbar if we know that no vehicle have entered or left the list NOTE: currently there is a piece of code to generate the list when it's not needed and compare it to the stored list and assert if they mismatch This check is somewhat slow and kills the whole idea of WE_INVALIDATE_DATA, so it's a short lived one to verify that InvalidateWindowData() is used everywhere where it's needed
Diffstat (limited to 'depot_gui.c')
-rw-r--r--depot_gui.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/depot_gui.c b/depot_gui.c
index d4dab78af..bf3472509 100644
--- a/depot_gui.c
+++ b/depot_gui.c
@@ -618,18 +618,43 @@ static void DepotWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_CREATE:
- WP(w, depot_d).vehicle_list = NULL;
- WP(w, depot_d).wagon_list = NULL;
- WP(w, depot_d).engine_count = 0;
- WP(w, depot_d).wagon_count = 0;
+ WP(w, depot_d).vehicle_list = NULL;
+ WP(w, depot_d).wagon_list = NULL;
+ WP(w, depot_d).engine_count = 0;
+ WP(w, depot_d).wagon_count = 0;
+ WP(w, depot_d).generate_list = true;
+ break;
+
+ case WE_INVALIDATE_DATA:
+ WP(w, depot_d).generate_list = true;
break;
case WE_PAINT:
- /* Generate the vehicle list
- * It's ok to use the wagon pointers for non-trains as they will be ignored */
- BuildDepotVehicleList(WP(w, depot_d).type, w->window_number,
- &WP(w, depot_d).vehicle_list, &WP(w, depot_d).engine_list_length, &WP(w, depot_d).engine_count,
- &WP(w, depot_d).wagon_list, &WP(w, depot_d).wagon_list_length, &WP(w, depot_d).wagon_count);
+ if (WP(w, depot_d).generate_list) {
+ /* Generate the vehicle list
+ * It's ok to use the wagon pointers for non-trains as they will be ignored */
+ BuildDepotVehicleList(WP(w, depot_d).type, w->window_number,
+ &WP(w, depot_d).vehicle_list, &WP(w, depot_d).engine_list_length, &WP(w, depot_d).engine_count,
+ &WP(w, depot_d).wagon_list, &WP(w, depot_d).wagon_list_length, &WP(w, depot_d).wagon_count);
+ WP(w, depot_d).generate_list = false;
+#ifndef NDEBUG
+ } else {
+ /* Here we got a piece of code, that only checks if we got a different number of vehicles in the depot list and the number of vehicles actually being in the depot.
+ * IF they aren't the same, then WE_INVALIDATE_DATA should have been called somewhere, but it wasn't and we got a bug
+ * Since this is a time consuming check and not nice to memory fragmentation, it may not stay for long, but it's a good way to check this
+ * We can turn it on/off by switching between #ifndef NDEBUG and #if 0 */
+ Vehicle **engines = NULL, **wagons = NULL;
+ uint16 engine_count = 0, engine_length = 0;
+ uint16 wagon_count = 0, wagon_length = 0;
+ BuildDepotVehicleList(WP(w, depot_d).type, w->window_number, &engines, &engine_length, &engine_count,
+ &wagons, &wagon_length, &wagon_count);
+
+ assert(engine_count == WP(w, depot_d).engine_count);
+ assert(wagon_count == WP(w, depot_d).wagon_count);
+ free((void*)engines);
+ free((void*)wagons);
+#endif
+ }
DrawDepotWindow(w);
break;