Compare commits

...

16 Commits

Author SHA1 Message Date
Haoyu Qiu d918439258
Merge 7e4a811b2c into 1c19d627aa 2023-12-23 13:55:05 +03:00
David Snopek 1c19d627aa
Merge pull request #1340 from aaronfranke/really-packed
Add PackedRealArray as an alias for PackedFloat(32/64)Array
2023-12-20 08:25:42 -06:00
Aaron Franke 646c71c277
Add PackedRealArray as an alias for PackedFloat(32/64)Array 2023-12-19 04:44:05 -06:00
Rémi Verschelde 48afa82f29
Merge pull request #1329 from godotengine/dependabot/github_actions/actions/setup-python-5
Bump actions/setup-python from 4 to 5
2023-12-07 08:58:31 +01:00
Rémi Verschelde 39ca745d0d
Merge pull request #1324 from akien-mga/cmake-remove-hardcoded-warnings
CMake: Remove hardcoded warnings list and forcing -Werror on library builds
2023-12-07 08:57:52 +01:00
dependabot[bot] a7becb43e6
Bump actions/setup-python from 4 to 5
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-06 19:33:16 +00:00
Rémi Verschelde 41517eacb1
CMake: Remove hardcoded warnings list and forcing -Werror on library builds
The CMake buildsystem should be completely reviewed to properly match
what is done by SCons, instead of making its own arbitrary decisions on
how godot-cpp should be compiled.

Currently the SCons setup doesn't include warning options, so CMake
shouldn't either. Options similar to upstream Godot's SCons setup could
be added, and then replicated for CMake.
2023-12-01 10:45:07 +01:00
Rémi Verschelde 17137b2e2e
Merge pull request #1323 from dsnopek/gcc-type-limits-error
Prevent `-Wtype-limits` warning on GCC 11 due to unsigned comparison
2023-12-01 10:36:59 +01:00
David Snopek cad5be53b1 Avoid error from -Werror=type-limits on GCC 11 2023-11-30 17:52:33 -06:00
Rémi Verschelde 54136ee835
Add 4.2 branch to README 2023-11-30 10:02:53 +01:00
Rémi Verschelde 0f78fc45bd
gdextension: Sync with upstream commit 46dc277917a93cbf601bbcf0d27d00f6feeec0d5 (4.2-stable) 2023-11-30 10:01:44 +01:00
Rémi Verschelde 11b2700b23
Merge pull request #1321 from dsnopek/postinitialize
Send NOTIFICATION_POSTINITIALIZE to extension classes
2023-11-30 09:55:30 +01:00
David Snopek 20c4e843b0 Send NOTIFICATION_POSTINITIALIZE to extension classes 2023-11-29 12:00:43 -06:00
Rémi Verschelde f3143c7a9c
Merge pull request #1320 from mihe/bit-field-size
Change bit field enums to use `uint64_t` as underlying type
2023-11-28 15:05:41 +01:00
Mikael Hermansson 943d1c8cdf Change bit field enums to use `uint64_t` as underlying type 2023-11-28 01:03:41 +01:00
Haoyu Qiu 7e4a811b2c Fix header generation for global constants 2022-11-22 21:34:32 +08:00
12 changed files with 69 additions and 40 deletions

View File

@ -104,7 +104,7 @@ jobs:
continue-on-error: true
- name: Set up Python (for SCons)
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.x'

View File

@ -47,11 +47,6 @@ option(GODOT_CPP_WARNING_AS_ERROR "Treat warnings as errors" OFF)
# Add path to modules
list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" )
# Check if we are building ourself or being included
if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME})
set(GODOT_CPP_BUILDING_SELF ON)
endif()
# Set some helper variables for readability
set( compiler_is_clang "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>" )
set( compiler_is_gnu "$<CXX_COMPILER_ID:GNU>" )
@ -158,12 +153,6 @@ add_library(godot::cpp ALIAS ${PROJECT_NAME})
include(GodotCompilerWarnings)
# Treat warnings as errors if we are building ourself
if(GODOT_CPP_BUILDING_SELF)
unset( GODOT_CPP_WARNING_AS_ERROR CACHE )
set_warning_as_error()
endif()
target_compile_features(${PROJECT_NAME}
PRIVATE
cxx_std_17

View File

@ -7,8 +7,9 @@
> from Godot's `master` branch.
>
> For users of stable branches, switch to the branch matching your target Godot version:
> - [`4.0`](https://github.com/godotengine/godot-cpp/tree/4.0)
> - [`4.2`](https://github.com/godotengine/godot-cpp/tree/4.2)
> - [`4.1`](https://github.com/godotengine/godot-cpp/tree/4.1)
> - [`4.0`](https://github.com/godotengine/godot-cpp/tree/4.0)
>
> Or check out the Git tag matching your Godot version (e.g. `godot-4.1.1-stable`).
>

View File

@ -1329,7 +1329,11 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
if "enums" in class_api:
for enum_api in class_api["enums"]:
result.append(f'\tenum {enum_api["name"]} {{')
if enum_api["is_bitfield"]:
result.append(f'\tenum {enum_api["name"]} : uint64_t {{')
else:
result.append(f'\tenum {enum_api["name"]} {{')
for value in enum_api["values"]:
result.append(f'\t\t{value["name"]} = {value["value"]},')
result.append("\t};")
@ -1686,11 +1690,18 @@ def generate_global_constants(api, output_dir):
header.append(f"#ifndef {header_guard}")
header.append(f"#define {header_guard}")
header.append("")
header.append("#include <cstdint>")
header.append("")
header.append("namespace godot {")
header.append("")
for constant in api["global_constants"]:
header.append(f'\tconst int {escape_identifier(constant["name"])} = {constant["value"]};')
if constant["value"] == -9223372036854775808:
# INT64_MIN is an special case here. In C++ it has to be specified like this to avoid warnings
# because 9223372036854775808 can't fit inside a `long long`, so it'll be turned into a `uint64_t`.
header.append(f'\tconst int64_t {escape_identifier(constant["name"])} = -9223372036854775807 - 1;')
else:
header.append(f'\tconst int64_t {escape_identifier(constant["name"])} = {constant["value"]};')
header.append("")
@ -1698,7 +1709,11 @@ def generate_global_constants(api, output_dir):
if enum_def["name"].startswith("Variant."):
continue
header.append(f'\tenum {enum_def["name"]} {{')
if enum_def["is_bitfield"]:
header.append(f'\tenum {enum_def["name"]} : uint64_t {{')
else:
header.append(f'\tenum {enum_def["name"]} {{')
for value in enum_def["values"]:
header.append(f'\t\t{value["name"]} = {value["value"]},')
header.append("\t};")
@ -2405,6 +2420,8 @@ def escape_identifier(id):
}
if id in cpp_keywords_map:
return cpp_keywords_map[id]
if re.match(r"U?INT\d*_(MIN|MAX)", id):
return "_" + id
return id

View File

@ -3,9 +3,9 @@
"version_major": 4,
"version_minor": 2,
"version_patch": 0,
"version_status": "rc2",
"version_status": "stable",
"version_build": "official",
"version_full_name": "Godot Engine v4.2.rc2.official"
"version_full_name": "Godot Engine v4.2.stable.official"
},
"builtin_class_sizes": [
{

View File

@ -356,6 +356,12 @@ String vformat(const String &p_text, const VarArgs... p_args) {
#include <godot_cpp/variant/builtin_vararg_methods.hpp>
#ifdef REAL_T_IS_DOUBLE
using PackedRealArray = PackedFloat64Array;
#else
using PackedRealArray = PackedFloat32Array;
#endif // REAL_T_IS_DOUBLE
} // namespace godot
#endif // GODOT_VARIANT_HPP

View File

@ -50,6 +50,12 @@ void Wrapped::_postinitialize() {
godot::internal::gdextension_interface_object_set_instance(_owner, reinterpret_cast<GDExtensionConstStringNamePtr>(extension_class), this);
}
godot::internal::gdextension_interface_object_set_instance_binding(_owner, godot::internal::token, this, _get_bindings_callbacks());
if (extension_class) {
Object *obj = dynamic_cast<Object *>(this);
if (obj) {
obj->notification(Object::NOTIFICATION_POSTINITIALIZE);
}
}
}
Wrapped::Wrapped(const StringName p_godot_class) {

View File

@ -271,7 +271,12 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge
} else if (internal::godot_version.minor != GODOT_VERSION_MINOR) {
compatible = internal::godot_version.minor > GODOT_VERSION_MINOR;
} else {
#if GODOT_VERSION_PATCH > 0
compatible = internal::godot_version.patch >= GODOT_VERSION_PATCH;
#else
// Prevent -Wtype-limits warning due to unsigned comparison.
compatible = true;
#endif
}
if (!compatible) {
// We need to use snprintf() here because vformat() uses Variant, and we haven't loaded

View File

@ -59,31 +59,9 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
else()
#elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# using Clang
#elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# using GCC and maybe MinGW?
set(GODOT_LINKER_FLAGS "-static-libgcc -static-libstdc++ -Wl,-R,'$$ORIGIN'")
# Hmm.. maybe to strikt?
set(GODOT_COMPILE_FLAGS "-fPIC -g -Wwrite-strings")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wchar-subscripts -Wcomment -Wdisabled-optimization")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wformat -Wformat=2 -Wformat-security -Wformat-y2k")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wimport -Winit-self -Winline -Winvalid-pch -Werror")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wmissing-braces -Wmissing-format-attribute")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wpointer-arith")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wredundant-decls -Wreturn-type -Wsequence-point")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wswitch -Wswitch-enum -Wtrigraphs")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunused-label")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wunused-value -Wvariadic-macros -Wvolatile-register-var -Wno-error=attributes")
# -Wshadow -Wextra -Wall -Weffc++ -Wfloat-equal -Wstack-protector -Wunused-parameter -Wsign-compare -Wunused-variable -Wcast-align
# -Wunused-function -Wstrict-aliasing -Wstrict-aliasing=2 -Wmissing-field-initializers
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wno-ignored-attributes")
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0")

View File

@ -236,6 +236,11 @@ func _ready():
get_viewport().push_input(event)
assert_equal(custom_signal_emitted, ["_input: H", 72])
# Check NOTIFICATION_POST_INITIALIZED, both when created from GDScript and godot-cpp.
var new_example_ref = ExampleRef.new()
assert_equal(new_example_ref.was_post_initialized(), true)
assert_equal(example.test_post_initialize(), true)
exit_with_status()
func _on_Example_custom_signal(signal_name, value):

View File

@ -63,10 +63,18 @@ int ExampleRef::get_id() const {
return id;
}
void ExampleRef::_notification(int p_what) {
if (p_what == NOTIFICATION_POSTINITIALIZE) {
post_initialized = true;
}
}
void ExampleRef::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_id", "id"), &ExampleRef::set_id);
ClassDB::bind_method(D_METHOD("get_id"), &ExampleRef::get_id);
ClassDB::bind_method(D_METHOD("was_post_initialized"), &ExampleRef::was_post_initialized);
ADD_PROPERTY(PropertyInfo(Variant::INT, "id"), "set_id", "get_id");
}
@ -220,6 +228,7 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("def_args", "a", "b"), &Example::def_args, DEFVAL(100), DEFVAL(200));
ClassDB::bind_method(D_METHOD("callable_bind"), &Example::callable_bind);
ClassDB::bind_method(D_METHOD("test_post_initialize"), &Example::test_post_initialize);
ClassDB::bind_static_method("Example", D_METHOD("test_static", "a", "b"), &Example::test_static);
ClassDB::bind_static_method("Example", D_METHOD("test_static2"), &Example::test_static2);
@ -597,6 +606,12 @@ Vector4 Example::get_v4() const {
return Vector4(1.2, 3.4, 5.6, 7.8);
}
bool Example::test_post_initialize() const {
Ref<ExampleRef> new_example_ref;
new_example_ref.instantiate();
return new_example_ref->was_post_initialized();
}
// Virtual function override.
bool Example::_has_point(const Vector2 &point) const {
Label *label = get_node<Label>("Label");

View File

@ -35,16 +35,21 @@ private:
static int last_id;
int id;
bool post_initialized = false;
protected:
static void _bind_methods();
void _notification(int p_what);
public:
ExampleRef();
~ExampleRef();
void set_id(int p_id);
int get_id() const;
bool was_post_initialized() const { return post_initialized; }
};
class ExampleMin : public Control {
@ -167,6 +172,8 @@ public:
Vector2 get_custom_position() const;
Vector4 get_v4() const;
bool test_post_initialize() const;
// Static method.
static int test_static(int p_a, int p_b);
static void test_static2();