← Back to team overview

widelands-dev team mailing list archive

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

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/remove_reference_player_tribe into lp:widelands.

Commit message:
Removed obsolete PlayerReferences from EditorInteractive. map_io no longer depends on wui.

Requested reviews:
  Widelands Developers (widelands-dev)

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

Since we got rid of the infrastructure tool, no need to reference the tribes in the editor any more. This probably already became obsolete with one_tribe.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/remove_reference_player_tribe into lp:widelands.
=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc	2017-08-28 12:44:08 +0000
+++ src/editor/editorinteractive.cc	2017-08-30 10:32:08 +0000
@@ -577,58 +577,6 @@
 	set_sel_triangles(primary.operates_on_triangles());
 }
 
-/**
- * Reference functions
- *
- *  data is a pointer to a tribe (for buildings)
- */
-void EditorInteractive::reference_player_tribe(Widelands::PlayerNumber player,
-                                               void const* const data) {
-	assert(0 < player);
-	assert(player <= egbase().map().get_nrplayers());
-
-	PlayerReferences r;
-	r.player = player;
-	r.object = data;
-
-	player_tribe_references_.push_back(r);
-}
-
-/// Unreference !once!, if referenced many times, this will leak a reference.
-void EditorInteractive::unreference_player_tribe(Widelands::PlayerNumber const player,
-                                                 void const* const data) {
-	assert(player <= egbase().map().get_nrplayers());
-	assert(data);
-
-	std::vector<PlayerReferences>& references = player_tribe_references_;
-	std::vector<PlayerReferences>::iterator it = references.begin();
-	std::vector<PlayerReferences>::const_iterator references_end = references.end();
-	if (player) {
-		for (; it < references_end; ++it)
-			if (it->player == player && it->object == data) {
-				references.erase(it);
-				break;
-			}
-	} else  //  Player is invalid. Remove all references from this object.
-		while (it < references_end)
-			if (it->object == data) {
-				it = references.erase(it);
-				references_end = references.end();
-			} else
-				++it;
-}
-
-bool EditorInteractive::is_player_tribe_referenced(Widelands::PlayerNumber const player) {
-	assert(0 < player);
-	assert(player <= egbase().map().get_nrplayers());
-
-	for (uint32_t i = 0; i < player_tribe_references_.size(); ++i)
-		if (player_tribe_references_[i].player == player)
-			return true;
-
-	return false;
-}
-
 void EditorInteractive::run_editor(const std::string& filename, const std::string& script_to_run) {
 	Widelands::EditorGameBase egbase(nullptr);
 	EditorInteractive& eia = *new EditorInteractive(egbase);

=== modified file 'src/editor/editorinteractive.h'
--- src/editor/editorinteractive.h	2017-08-20 16:12:28 +0000
+++ src/editor/editorinteractive.h	2017-08-30 10:32:08 +0000
@@ -118,10 +118,6 @@
 	// action functions
 	void exit();
 
-	//  reference functions
-	void reference_player_tribe(Widelands::PlayerNumber, void const* const) override;
-	void unreference_player_tribe(Widelands::PlayerNumber, void const* const);
-	bool is_player_tribe_referenced(Widelands::PlayerNumber);
 	void set_need_save(bool const t) {
 		need_save_ = t;
 	}
@@ -145,11 +141,6 @@
 private:
 	friend struct EditorToolMenu;
 
-	struct PlayerReferences {
-		int32_t player;
-		void const* object;
-	};
-
 	// Registers the overlays for player starting positions.
 	void register_overlays();
 
@@ -161,7 +152,6 @@
 
 	//  state variables
 	bool need_save_;
-	std::vector<PlayerReferences> player_tribe_references_;
 	uint32_t realtime_;
 	bool is_painting_;
 

=== modified file 'src/editor/ui_menus/player_menu.cc'
--- src/editor/ui_menus/player_menu.cc	2017-08-19 22:22:20 +0000
+++ src/editor/ui_menus/player_menu.cc	2017-08-30 10:32:08 +0000
@@ -220,24 +220,22 @@
 	Widelands::PlayerNumber const nr_players = old_nr_players - 1;
 	assert(1 <= nr_players);
 
-	if (!menu.is_player_tribe_referenced(old_nr_players)) {
-		if (const Widelands::Coords sp = map->get_starting_pos(old_nr_players)) {
-			//  Remove starting position marker.
-			const Image* player_image =
-			   playercolor_image(old_nr_players - 1, "images/players/player_position.png");
-			assert(player_image);
-			menu.mutable_field_overlay_manager()->remove_overlay(sp, player_image);
-		}
-		// if removed player was selected switch to the next highest player
-		if (old_nr_players == menu.tools()->set_starting_pos.get_current_player())
-			set_starting_pos_clicked(nr_players);
-	}
+	if (const Widelands::Coords sp = map->get_starting_pos(old_nr_players)) {
+		//  Remove starting position marker.
+		const Image* player_image =
+			playercolor_image(old_nr_players - 1, "images/players/player_position.png");
+		assert(player_image);
+		menu.mutable_field_overlay_manager()->remove_overlay(sp, player_image);
+	}
+	// if removed player was selected switch to the next highest player
+	if (old_nr_players == menu.tools()->set_starting_pos.get_current_player()) {
+		set_starting_pos_clicked(nr_players);
+	}
+
 	map->set_nrplayers(nr_players);
 	add_player_.set_enabled(nr_players < kMaxPlayers);
 	remove_last_player_.set_enabled(1 < nr_players);
 	update();
-	// TODO(SirVer): Take steps when the player is referenced someplace. Not
-	// TODO(SirVer): currently possible in the editor though.
 }
 
 /**
@@ -245,27 +243,19 @@
  */
 void EditorPlayerMenu::player_tribe_clicked(uint8_t n) {
 	EditorInteractive& menu = eia();
-	if (!menu.is_player_tribe_referenced(n + 1)) {
-		if (!Widelands::tribe_exists(selected_tribes_[n])) {
-			throw wexception(
-			   "Map defines tribe %s, but it does not exist!", selected_tribes_[n].c_str());
-		}
-		uint32_t i;
-		for (i = 0; i < tribenames_.size(); ++i) {
-			if (tribenames_[i] == selected_tribes_[n]) {
-				break;
-			}
-		}
-		selected_tribes_[n] = i == tribenames_.size() - 1 ? tribenames_[0] : tribenames_[++i];
-		menu.egbase().mutable_map()->set_scenario_player_tribe(n + 1, selected_tribes_[n]);
-		menu.set_need_save(true);
-	} else {
-		UI::WLMessageBox mmb(&menu, _("Error!"),
-		                     _("Cannot remove player. It is referenced someplace. Remove all"
-		                       " buildings and animals that depend on this player and try again."),
-		                     UI::WLMessageBox::MBoxType::kOk);
-		mmb.run<UI::Panel::Returncodes>();
-	}
+	if (!Widelands::tribe_exists(selected_tribes_[n])) {
+		throw wexception(
+			"Map defines tribe %s, but it does not exist!", selected_tribes_[n].c_str());
+	}
+	uint32_t i;
+	for (i = 0; i < tribenames_.size(); ++i) {
+		if (tribenames_[i] == selected_tribes_[n]) {
+			break;
+		}
+	}
+	selected_tribes_[n] = i == tribenames_.size() - 1 ? tribenames_[0] : tribenames_[++i];
+	menu.egbase().mutable_map()->set_scenario_player_tribe(n + 1, selected_tribes_[n]);
+	menu.set_need_save(true);
 	update();
 }
 

=== modified file 'src/map_io/CMakeLists.txt'
--- src/map_io/CMakeLists.txt	2017-02-28 12:59:39 +0000
+++ src/map_io/CMakeLists.txt	2017-08-30 10:32:08 +0000
@@ -106,5 +106,4 @@
     logic_widelands_geometry
     profile
     scripting_logic
-    wui
 )

=== modified file 'src/map_io/map_building_packet.cc'
--- src/map_io/map_building_packet.cc	2017-08-19 22:22:20 +0000
+++ src/map_io/map_building_packet.cc	2017-08-30 10:32:08 +0000
@@ -33,7 +33,6 @@
 #include "logic/player.h"
 #include "map_io/map_object_loader.h"
 #include "map_io/map_object_saver.h"
-#include "wui/interactive_base.h"
 
 namespace Widelands {
 
@@ -101,9 +100,6 @@
 
 							mol.register_object<Building>(serial, *building);
 							read_priorities(*building, fr);
-
-							//  Reference the players tribe if in editor.
-							ibase.reference_player_tribe(p, &tribe);
 						} else
 							throw GameDataError("player %u does not exist", p);
 					}

=== modified file 'src/wui/fieldaction.cc'
--- src/wui/fieldaction.cc	2017-08-20 15:45:50 +0000
+++ src/wui/fieldaction.cc	2017-08-30 10:32:08 +0000
@@ -680,7 +680,6 @@
 	upcast(InteractivePlayer, iaplayer, &ibase());
 
 	game->send_player_build(iaplayer->player_number(), node_, Widelands::DescriptionIndex(idx));
-	ibase().reference_player_tribe(player_->player_number(), &player_->tribe());
 	iaplayer->set_flag_to_connect(game->map().br_n(node_));
 	reset_mouse_and_die();
 }

=== modified file 'src/wui/interactive_base.h'
--- src/wui/interactive_base.h	2017-08-20 16:12:28 +0000
+++ src/wui/interactive_base.h	2017-08-30 10:32:08 +0000
@@ -72,8 +72,6 @@
 	Widelands::EditorGameBase& egbase() const {
 		return egbase_;
 	}
-	virtual void reference_player_tribe(Widelands::PlayerNumber, const void* const) {
-	}
 
 	// TODO(sirver): This should be private.
 	bool show_workarea_preview_;


Follow ups