← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug1503949 into lp:widelands

 

Jens Beyer has proposed merging lp:~widelands-dev/widelands/bug1503949 into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1503949 in widelands: "excessive CPU usage and loading time seemingly related to lenght of the game"
  https://bugs.launchpad.net/widelands/+bug/1503949

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug1503949/+merge/274157

do not launch workers separately when destroying the warehouse in the load-game sequence (performance issue when loading large savegames)

I use game->is_loaded() to find out if the game is running, is there a better approach?
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug1503949 into lp:widelands.
=== modified file 'src/logic/warehouse.cc'
--- src/logic/warehouse.cc	2015-10-02 18:23:52 +0000
+++ src/logic/warehouse.cc	2015-10-12 14:58:52 +0000
@@ -578,13 +578,28 @@
 	// This will empty the stock and launch all workers including incorporated
 	// ones.
 	if (upcast(Game, game, &egbase)) {
-		const WareList& workers = get_workers();
-		for (WareIndex id = 0; id < workers.get_nrwareids(); ++id) {
-			const uint32_t stock = workers.stock(id);
-			for (uint32_t i = 0; i < stock; ++i) {
-				launch_worker(*game, id, Requirements()).start_task_leavebuilding(*game, true);
-			}
-			assert(!m_incorporated_workers.count(id) || m_incorporated_workers[id].empty());
+		//separate behaviour for the case of loading the game
+		//(which does save/destroy/reload) and simply destroying ingame
+		if (game->is_loaded())
+		{
+			//this game is really running
+			const WareList& workers = get_workers();
+			for (WareIndex id = 0; id < workers.get_nrwareids(); ++id) {
+				const uint32_t stock = workers.stock(id);
+				for (uint32_t i = 0; i < stock; ++i) {
+					launch_worker(*game, id, Requirements()).start_task_leavebuilding(*game, true);
+				}
+				assert(!m_incorporated_workers.count(id) || m_incorporated_workers[id].empty());
+			}
+		}
+		else
+		{
+			//we are in the load-game sequence...
+			const WareList& workers = get_workers();
+			for (WareIndex id = 0; id < workers.get_nrwareids(); ++id) {
+				const uint32_t stock = workers.stock(id);
+				remove_workers(id, stock);
+			}
 		}
 	}
 	m_incorporated_workers.clear();


Follow ups