Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

호환성 중단 처리

그러면 메소드에 새 매개변수를 추가하고, 반환 유형을 변경하고, 매개변수 유형을 변경하거나, 기본값을 변경했는데 이제 자동화된 테스트에서 호환성 손상에 대해 불평하고 있습니까?

호환성 중단은 피해야 하지만 필요한 경우 전환을 최대한 원활하게 만드는 방식으로 이를 처리할 수 있는 시스템이 있습니다.

예:

이러한 변경 사항은 AStarGrid2D 및 기타 AStar 클래스에 새로운 경로 지정 옵션을 추가한 `풀 요청 #88047 <https://github.com/godotengine/godot/pull/88047>`_에서 가져왔습니다. 다른 변경 사항 중에서 ``core/math/a_star_grid_2d.h``에서는 다음 방법이 수정되었습니다.

Vector<Vector2> get_point_path(const Vector2i &p_from, const Vector2i &p_to);
TypedArray<Vector2i> get_id_path(const Vector2i &p_from, const Vector2i &p_to);

받는 사람:

Vector<Vector2> get_point_path(const Vector2i &p_from, const Vector2i &p_to, bool p_allow_partial_path = false);
TypedArray<Vector2i> get_id_path(const Vector2i &p_from, const Vector2i &p_to, bool p_allow_partial_path = false);

이는 일반적으로 _bind_methods() 옆에 배치되는 코드의 protected 섹션에 있어야 하는 파일에 새로운 호환성 메서드 바인딩을 추가하는 것을 의미합니다.

#ifndef DISABLE_DEPRECATED
    TypedArray<Vector2i> _get_id_path_bind_compat_88047(const Vector2i &p_from, const Vector2i &p_to);
    Vector<Vector2> _get_point_path_bind_compat_88047(const Vector2i &p_from, const Vector2i &p_to);
    static void _bind_compatibility_methods();
#endif

내부임을 나타내기 위해 _``로 시작하고 ``_bind_compat_``로 끝나야 하며 뒤에 변경 사항을 도입한 PR 번호(이 예에서는 ``88047)가 와야 합니다. 이러한 호환성 방법은 이 경우 ``core/math/a_star_grid_2d.compat.inc``와 같은 전용 파일에서 구현되어야 합니다.

core/math/a_star_grid_2d.compat.inc
/**************************************************************************/
/*  a_star_grid_2d.compat.inc                                             */
/**************************************************************************/
/*                         This file is part of:                          */
/*                             GODOT ENGINE                               */
/*                        https://godotengine.org                         */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */
/*                                                                        */
/* Permission is hereby granted, free of charge, to any person obtaining  */
/* a copy of this software and associated documentation files (the        */
/* "Software"), to deal in the Software without restriction, including    */
/* without limitation the rights to use, copy, modify, merge, publish,    */
/* distribute, sublicense, and/or sell copies of the Software, and to     */
/* permit persons to whom the Software is furnished to do so, subject to  */
/* the following conditions:                                              */
/*                                                                        */
/* The above copyright notice and this permission notice shall be         */
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

#ifndef DISABLE_DEPRECATED

#include "core/variant/typed_array.h"

TypedArray<Vector2i> AStarGrid2D::_get_id_path_bind_compat_88047(const Vector2i &p_from_id, const Vector2i &p_to_id) {
    return get_id_path(p_from_id, p_to_id, false);
}

Vector<Vector2> AStarGrid2D::_get_point_path_bind_compat_88047(const Vector2i &p_from_id, const Vector2i &p_to_id) {
    return get_point_path(p_from_id, p_to_id, false);
}

void AStarGrid2D::_bind_compatibility_methods() {
    ClassDB::bind_compatibility_method(D_METHOD("get_id_path", "from_id", "to_id"), &AStarGrid2D::_get_id_path_bind_compat_88047);
    ClassDB::bind_compatibility_method(D_METHOD("get_point_path", "from_id", "to_id"), &AStarGrid2D::_get_point_path_bind_compat_88047);
}

#endif // DISABLE_DEPRECATED

호환성 변경이 복잡하지 않은 한, 호환성 메서드는 해당 메서드를 복제하는 대신 수정된 메서드를 직접 호출해야 합니다. 해당 메소드의 기본 인수가 일치하는지 확인하십시오(위의 예에서는 ``false``임).

이 파일은 항상 원본 파일 옆에 배치되어야 하며 끝에 .cpp 또는 .h 대신 .compat.inc``가 있어야 합니다. 다음으로, 이는 호환성 메서드를 추가하는 ``.cpp 파일에 포함되어야 하므로 core/math/a_star_grid_2d.cpp:

core/math/a_star_grid_2d.cpp
#include "a_star_grid_2d.h"
#include "a_star_grid_2d.compat.inc"

#include "core/variant/typed_array.h"

마지막으로 GDExtension API 변경 사항을 기록해야 합니다. 이렇게 하려면 먼저 master 브랜치에서 Godot를 컴파일한 다음 --dump-extension-api 플래그를 사용하여 실행하세요:

git switch master
scons
godot --dump-extension-api

그러면 현재 디렉터리에 extension_api.json``라는 파일이 생성됩니다. 기능 브랜치로 전환하고 Godot를 다시 컴파일한 다음 ``--validate-extension-api 플래그와 방금 생성한 extension_api.json 파일의 경로를 사용하여 실행하세요.

git switch my-feature-branch
scons
godot --validate-extension-api /path/to/extension_api.json

그러면 다음과 같이 ``Validate extension JSON``로 시작하는 일부 줄이 생성됩니다.

Validate extension JSON: Error: Field 'classes/AStar2D/methods/get_id_path/arguments': size changed value in new API, from 2 to 3.
Validate extension JSON: Error: Field 'classes/AStar2D/methods/get_point_path/arguments': size changed value in new API, from 2 to 3.
Validate extension JSON: Error: Field 'classes/AStar3D/methods/get_id_path/arguments': size changed value in new API, from 2 to 3.
Validate extension JSON: Error: Field 'classes/AStar3D/methods/get_point_path/arguments': size changed value in new API, from 2 to 3.
Validate extension JSON: Error: Field 'classes/AStarGrid2D/methods/get_id_path/arguments': size changed value in new API, from 2 to 3.
Validate extension JSON: Error: Field 'classes/AStarGrid2D/methods/get_point_path/arguments': size changed value in new API, from 2 to 3.

주의

메소드에 대해 Hash changed 오류가 발생하는 경우 호환성 바인딩이 누락되었거나 올바르지 않음을 의미합니다. 이러한 줄은 유효성 검사 파일에 추가하면 안 되지만 적절한 호환성 방법을 바인딩하여 수정해야 합니다. 다음 사항을 다시 확인하세요.

  • 호환성 메서드(이름이 PR 번호로 끝나는 메서드)의 경우 인수 유형, 이름 및 기본값은 변경 전 메서드 버전과 동일해야 합니다.

  • _bind_compatibility_methods()``에서 ``ClassDB::bind_compatibility_method()``의 ``D_METHOD() 매크로에 제공된 인수 이름은 원래 메서드에 대한 ClassDB::bind_method() 호출의 인수 이름과 동일해야 합니다.

API 변경 사항과 파손을 방지하기 위해 취한 조치를 설명하는 주석을 GitHub 끌어오기 요청 ID의 이름을 딴 유효성 검사 파일에 추가하고 호환성이 손상될 Godot 버전의 폴더에 배치합니다.

이 예제는 PR #88047에 대한 것이므로 해당 파일 이름은 GH-88047.txt``가 되며 작업은 4.3 개발 중에 수행되었으므로(따라서 4.2에서 변경됨) 파일은 ``misc/extension_api_validation/4.2-stable/ 폴더에 있습니다.

이 PR에 대한 파일의 전체 예는 아래를 참조하세요.

misc/extension_api_validation/4.2-stable/GH-88047.txt
GH-88047
--------
Validate extension JSON: Error: Field 'classes/AStar2D/methods/get_id_path/arguments': size changed value in new API, from 2 to 3.
Validate extension JSON: Error: Field 'classes/AStar2D/methods/get_point_path/arguments': size changed value in new API, from 2 to 3.
Validate extension JSON: Error: Field 'classes/AStar3D/methods/get_id_path/arguments': size changed value in new API, from 2 to 3.
Validate extension JSON: Error: Field 'classes/AStar3D/methods/get_point_path/arguments': size changed value in new API, from 2 to 3.
Validate extension JSON: Error: Field 'classes/AStarGrid2D/methods/get_id_path/arguments': size changed value in new API, from 2 to 3.
Validate extension JSON: Error: Field 'classes/AStarGrid2D/methods/get_point_path/arguments': size changed value in new API, from 2 to 3.

Added optional "allow_partial_path" argument to get_id_path and get_point_path methods in AStar classes.
Compatibility methods registered.

그리고 그게 다야! 인수 재배열, 반환 유형 변경 등과 같은 좀 더 복잡한 경우에 직면할 수 있지만 여기서는 이 시스템을 사용하는 방법에 대한 기본 사항을 다룹니다.

자세한 정보는 풀 리퀘스트 #76446을 참조하세요.