Browse Source

Remove assignment and declarations in if statements

After discussing with @reduz and @akien-mga it was decided that we do
not allow assignments or declarations in if statements. This PR removes
the instances of this I could find by automated means.
Hein-Pieter van Braam 8 years ago
parent
commit
8230bf0a2f

+ 2 - 1
core/map.h

@@ -453,8 +453,9 @@ private:
 		if (!rp)
 			rp = _data._nil;
 		Element *node = (rp->left == _data._nil) ? rp->right : rp->left;
+		node->parent = rp->parent;
 
-		if (_data._root == (node->parent = rp->parent)) {
+		if (_data._root == node->parent) {
 			_data._root->left = node;
 		} else {
 			if (rp == rp->parent->left) {

+ 2 - 1
core/set.h

@@ -438,8 +438,9 @@ private:
 		if (!rp)
 			rp = _data._nil;
 		Element *node = (rp->left == _data._nil) ? rp->right : rp->left;
+		node->parent = rp->parent;
 
-		if (_data._root == (node->parent = rp->parent)) {
+		if (_data._root == node->parent) {
 			_data._root->left = node;
 		} else {
 			if (rp == rp->parent->left) {

+ 2 - 1
drivers/windows/file_access_windows.cpp

@@ -159,7 +159,8 @@ void FileAccessWindows::seek_end(int64_t p_position) {
 size_t FileAccessWindows::get_pos() const {
 
 	size_t aux_position = 0;
-	if (!(aux_position = ftell(f))) {
+	aux_position = ftell(f);
+	if (!aux_position) {
 		check_errors();
 	};
 	return aux_position;

+ 2 - 2
editor/import/resource_importer_scene.cpp

@@ -230,8 +230,8 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array
 
 		if (isroot)
 			return p_node;
-
-		if (MeshInstance *mi = Object::cast_to<MeshInstance>(p_node)) {
+		MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
+		if (mi) {
 			Node *col = mi->create_trimesh_collision_node();
 			ERR_FAIL_COND_V(!col, NULL);
 

+ 10 - 7
editor/plugins/canvas_item_editor_plugin.cpp

@@ -580,7 +580,8 @@ void CanvasItemEditor::_key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE
 
 		} else { // p_move_mode==MOVE_LOCAL_BASE || p_move_mode==MOVE_LOCAL_WITH_ROT
 
-			if (Node2D *node_2d = Object::cast_to<Node2D>(canvas_item)) {
+			Node2D *node_2d = Object::cast_to<Node2D>(canvas_item);
+			if (node_2d) {
 
 				if (p_move_mode == MOVE_LOCAL_WITH_ROT) {
 					Transform2D m;
@@ -589,9 +590,10 @@ void CanvasItemEditor::_key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE
 				}
 				node_2d->set_position(node_2d->get_position() + drag);
 
-			} else if (Control *control = Object::cast_to<Control>(canvas_item)) {
-
-				control->set_position(control->get_position() + drag);
+			} else {
+				Control *control = Object::cast_to<Control>(canvas_item);
+				if (control)
+					control->set_position(control->get_position() + drag);
 			}
 		}
 	}
@@ -742,7 +744,8 @@ float CanvasItemEditor::_anchor_snap(float p_anchor, bool *p_snapped, float p_op
 	float radius = 0.05 / zoom;
 	float basic_anchors[3] = { 0.0, 0.5, 1.0 };
 	for (int i = 0; i < 3; i++) {
-		if ((dist = fabs(p_anchor - basic_anchors[i])) < radius) {
+		dist = fabs(p_anchor - basic_anchors[i]);
+		if (dist < radius) {
 			if (!snapped || dist <= dist_min) {
 				p_anchor = basic_anchors[i];
 				dist_min = dist;
@@ -750,7 +753,8 @@ float CanvasItemEditor::_anchor_snap(float p_anchor, bool *p_snapped, float p_op
 			}
 		}
 	}
-	if (p_opposite_anchor >= 0 && (dist = fabs(p_anchor - p_opposite_anchor)) < radius) {
+	dist = fabs(p_anchor - p_opposite_anchor);
+	if (p_opposite_anchor >= 0 && dist < radius) {
 		if (!snapped || dist <= dist_min) {
 			p_anchor = p_opposite_anchor;
 			dist_min = dist;
@@ -2269,7 +2273,6 @@ void CanvasItemEditor::_notification(int p_what) {
 
 	if (p_what == NOTIFICATION_FIXED_PROCESS) {
 
-
 		EditorNode::get_singleton()->get_scene_root()->set_snap_controls_to_pixels(GLOBAL_GET("gui/common/snap_controls_to_pixels"));
 
 		List<Node *> &selection = editor_selection->get_selected_node_list();

+ 28 - 17
editor/scene_tree_dock.cpp

@@ -582,13 +582,13 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
 
 			new_scene_from_dialog->popup_centered_ratio();
 			new_scene_from_dialog->set_title(TTR("Save New Scene As.."));
-
 		} break;
 		case TOOL_COPY_NODE_PATH: {
 			List<Node *> selection = editor_selection->get_selected_node_list();
-
-			if (List<Node *>::Element *e = selection.front()) {
-				if (Node *node = e->get()) {
+			List<Node *>::Element *e = selection.front();
+			if (e) {
+				Node *node = e->get();
+				if (node) {
 					Node *root = EditorNode::get_singleton()->get_edited_scene();
 					NodePath path = root->get_path().rel_path_to(node->get_path());
 					OS::get_singleton()->set_clipboard(path);
@@ -597,8 +597,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
 		} break;
 		case TOOL_SCENE_EDITABLE_CHILDREN: {
 			List<Node *> selection = editor_selection->get_selected_node_list();
-			if (List<Node *>::Element *e = selection.front()) {
-				if (Node *node = e->get()) {
+			List<Node *>::Element *e = selection.front();
+			if (e) {
+				Node *node = e->get();
+				if (node) {
 					bool editable = EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(node);
 					int editable_item_idx = menu->get_item_idx_from_text(TTR("Editable Children"));
 					int placeholder_item_idx = menu->get_item_idx_from_text(TTR("Load As Placeholder"));
@@ -617,8 +619,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
 		} break;
 		case TOOL_SCENE_USE_PLACEHOLDER: {
 			List<Node *> selection = editor_selection->get_selected_node_list();
-			if (List<Node *>::Element *e = selection.front()) {
-				if (Node *node = e->get()) {
+			List<Node *>::Element *e = selection.front();
+			if (e) {
+				Node *node = e->get();
+				if (node) {
 					bool placeholder = node->get_scene_instance_load_placeholder();
 					placeholder = !placeholder;
 					int editable_item_idx = menu->get_item_idx_from_text(TTR("Editable Children"));
@@ -635,15 +639,16 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
 		} break;
 		case TOOL_SCENE_CLEAR_INSTANCING: {
 			List<Node *> selection = editor_selection->get_selected_node_list();
-			if (List<Node *>::Element *e = selection.front()) {
-				if (Node *node = e->get()) {
+			List<Node *>::Element *e = selection.front();
+			if (e) {
+				Node *node = e->get();
+				if (node) {
 					Node *root = EditorNode::get_singleton()->get_edited_scene();
 					UndoRedo *undo_redo = &editor_data->get_undo_redo();
 					if (!root)
 						break;
 
 					ERR_FAIL_COND(node->get_filename() == String());
-
 					undo_redo->create_action(TTR("Discard Instancing"));
 					undo_redo->add_do_method(node, "set_filename", "");
 					undo_redo->add_undo_method(node, "set_filename", node->get_filename());
@@ -656,8 +661,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
 		} break;
 		case TOOL_SCENE_OPEN: {
 			List<Node *> selection = editor_selection->get_selected_node_list();
-			if (List<Node *>::Element *e = selection.front()) {
-				if (Node *node = e->get()) {
+			List<Node *>::Element *e = selection.front();
+			if (e) {
+				Node *node = e->get();
+				if (node) {
 					scene_tree->emit_signal("open", node->get_filename());
 				}
 			}
@@ -667,8 +674,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
 		} break;
 		case TOOL_SCENE_CLEAR_INHERITANCE_CONFIRM: {
 			List<Node *> selection = editor_selection->get_selected_node_list();
-			if (List<Node *>::Element *e = selection.front()) {
-				if (Node *node = e->get()) {
+			List<Node *>::Element *e = selection.front();
+			if (e) {
+				Node *node = e->get();
+				if (node) {
 					node->set_scene_inherited_state(Ref<SceneState>());
 					scene_tree->update_tree();
 					EditorNode::get_singleton()->get_property_editor()->update_tree();
@@ -677,8 +686,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
 		} break;
 		case TOOL_SCENE_OPEN_INHERITED: {
 			List<Node *> selection = editor_selection->get_selected_node_list();
-			if (List<Node *>::Element *e = selection.front()) {
-				if (Node *node = e->get()) {
+			List<Node *>::Element *e = selection.front();
+			if (e) {
+				Node *node = e->get();
+				if (node) {
 					if (node && node->get_scene_inherited_state().is_valid()) {
 						scene_tree->emit_signal("open", node->get_scene_inherited_state()->get_path());
 					}

+ 2 - 1
modules/theora/video_stream_theora.cpp

@@ -414,7 +414,8 @@ void VideoStreamPlaybackTheora::update(float p_delta) {
 			bool buffer_full = false;
 
 			/* if there's pending, decoded audio, grab it */
-			if ((ret = vorbis_synthesis_pcmout(&vd, &pcm)) > 0) {
+			ret = vorbis_synthesis_pcmout(&vd, &pcm);
+			if (ret > 0) {
 
 				const int AUXBUF_LEN = 4096;
 				int to_read = ret;

+ 10 - 6
platform/windows/context_gl_win.cpp

@@ -130,24 +130,28 @@ Error ContextGL_Win::initialize() {
 		0, 0, 0 // Layer Masks Ignored
 	};
 
-	if (!(hDC = GetDC(hWnd))) {
+	hDC = GetDC(hWnd);
+	if (!hDC) {
 		MessageBox(NULL, "Can't Create A GL Device Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
 		return ERR_CANT_CREATE; // Return FALSE
 	}
 
-	if (!(pixel_format = ChoosePixelFormat(hDC, &pfd))) // Did Windows Find A Matching Pixel Format?
+	pixel_format = ChoosePixelFormat(hDC, &pfd);
+	if (!pixel_format) // Did Windows Find A Matching Pixel Format?
 	{
 		MessageBox(NULL, "Can't Find A Suitable pixel_format.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
 		return ERR_CANT_CREATE; // Return FALSE
 	}
 
-	if (!SetPixelFormat(hDC, pixel_format, &pfd)) // Are We Able To Set The Pixel Format?
+	BOOL ret = SetPixelFormat(hDC, pixel_format, &pfd);
+	if (!ret) // Are We Able To Set The Pixel Format?
 	{
 		MessageBox(NULL, "Can't Set The pixel_format.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
 		return ERR_CANT_CREATE; // Return FALSE
 	}
 
-	if (!(hRC = wglCreateContext(hDC))) // Are We Able To Get A Rendering Context?
+	hRC = wglCreateContext(hDC);
+	if (!hRC) // Are We Able To Get A Rendering Context?
 	{
 		MessageBox(NULL, "Can't Create A Temporary GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
 		return ERR_CANT_CREATE; // Return FALSE
@@ -175,8 +179,8 @@ Error ContextGL_Win::initialize() {
 			return ERR_CANT_CREATE;
 		}
 
-		HGLRC new_hRC;
-		if (!(new_hRC = wglCreateContextAttribsARB(hDC, 0, attribs))) {
+		HGLRC new_hRC = wglCreateContextAttribsARB(hDC, 0, attribs);
+		if (!new_hRC) {
 			wglDeleteContext(hRC);
 			MessageBox(NULL, "Can't Create An OpenGL 3.3 Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
 			return ERR_CANT_CREATE; // Return false

+ 3 - 1
platform/windows/joypad.cpp

@@ -379,7 +379,9 @@ void JoypadWindows::process_joypads() {
 			IDirectInputDevice8_Acquire(joy->di_joy);
 			joy->di_joy->Poll();
 		}
-		if (FAILED(hr = joy->di_joy->GetDeviceState(sizeof(DIJOYSTATE2), &js))) {
+
+		hr = joy->di_joy->GetDeviceState(sizeof(DIJOYSTATE2), &js);
+		if (FAILED(hr)) {
 
 			//printf("failed to read joy #%d\n", i);
 			continue;

+ 10 - 1
platform/windows/os_windows.cpp

@@ -996,7 +996,16 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
 		video_mode.fullscreen = false;
 	} else {
 
-		if (!(hWnd = CreateWindowExW(dwExStyle, L"Engine", L"", dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, (GetSystemMetrics(SM_CXSCREEN) - WindowRect.right) / 2, (GetSystemMetrics(SM_CYSCREEN) - WindowRect.bottom) / 2, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, NULL, NULL, hInstance, NULL))) {
+		hWnd = CreateWindowExW(
+				dwExStyle,
+				L"Engine", L"",
+				dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+				(GetSystemMetrics(SM_CXSCREEN) - WindowRect.right) / 2,
+				(GetSystemMetrics(SM_CYSCREEN) - WindowRect.bottom) / 2,
+				WindowRect.right - WindowRect.left,
+				WindowRect.bottom - WindowRect.top,
+				NULL, NULL, hInstance, NULL);
+		if (!hWnd) {
 			MessageBoxW(NULL, L"Window Creation Error.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
 			return; // Return FALSE
 		}

+ 2 - 1
scene/2d/path_2d.cpp

@@ -137,7 +137,8 @@ void PathFollow2D::_notification(int p_what) {
 
 		case NOTIFICATION_ENTER_TREE: {
 
-			if ((path = Object::cast_to<Path2D>(get_parent()))) {
+			path = Object::cast_to<Path2D>(get_parent());
+			if (path) {
 				_update_transform();
 			}
 

+ 4 - 2
scene/3d/bone_attachment.cpp

@@ -71,7 +71,8 @@ void BoneAttachment::_get_property_list(List<PropertyInfo> *p_list) const {
 
 void BoneAttachment::_check_bind() {
 
-	if (Skeleton *sk = Object::cast_to<Skeleton>(get_parent())) {
+	Skeleton *sk = Object::cast_to<Skeleton>(get_parent());
+	if (sk) {
 
 		int idx = sk->find_bone(bone_name);
 		if (idx != -1) {
@@ -86,7 +87,8 @@ void BoneAttachment::_check_unbind() {
 
 	if (bound) {
 
-		if (Skeleton *sk = Object::cast_to<Skeleton>(get_parent())) {
+		Skeleton *sk = Object::cast_to<Skeleton>(get_parent());
+		if (sk) {
 
 			int idx = sk->find_bone(bone_name);
 			if (idx != -1) {

+ 2 - 1
scene/3d/collision_shape.cpp

@@ -50,7 +50,8 @@ void CollisionShape::make_convex_from_brothers() {
 	for (int i = 0; i < p->get_child_count(); i++) {
 
 		Node *n = p->get_child(i);
-		if (MeshInstance *mi = Object::cast_to<MeshInstance>(n)) {
+		MeshInstance *mi = Object::cast_to<MeshInstance>(n);
+		if (mi) {
 
 			Ref<Mesh> m = mi->get_mesh();
 			if (m.is_valid()) {

+ 2 - 1
scene/3d/gi_probe.cpp

@@ -1113,7 +1113,8 @@ void GIProbe::_find_meshes(Node *p_at_node, Baker *p_baker) {
 		}
 	}
 
-	if (Spatial *s = Object::cast_to<Spatial>(p_at_node)) {
+	Spatial *s = Object::cast_to<Spatial>(p_at_node);
+	if (s) {
 
 		if (s->is_visible_in_tree()) {
 

+ 2 - 2
scene/3d/interpolated_camera.cpp

@@ -55,8 +55,8 @@ void InterpolatedCamera::_notification(int p_what) {
 				Transform local_transform = get_global_transform();
 				local_transform = local_transform.interpolate_with(target_xform, delta);
 				set_global_transform(local_transform);
-
-				if (Camera *cam = Object::cast_to<Camera>(node)) {
+				Camera *cam = Object::cast_to<Camera>(node);
+				if (cam) {
 
 					if (cam->get_projection() == get_projection()) {
 

+ 2 - 2
scene/3d/path.cpp

@@ -155,8 +155,8 @@ void PathFollow::_notification(int p_what) {
 
 			Node *parent = get_parent();
 			if (parent) {
-
-				if ((path = Object::cast_to<Path>(parent))) {
+				path = Object::cast_to<Path>(parent);
+				if (path) {
 					_update_transform();
 				}
 			}

+ 2 - 2
scene/gui/file_dialog.cpp

@@ -183,8 +183,8 @@ void FileDialog::_action_pressed() {
 		String path = dir_access->get_current_dir();
 
 		path = path.replace("\\", "/");
-
-		if (TreeItem *item = tree->get_selected()) {
+		TreeItem *item = tree->get_selected();
+		if (item) {
 			Dictionary d = item->get_metadata(0);
 			if (d["dir"]) {
 				path = path.plus_file(d["name"]);