Skip to content

Commit

Permalink
Try gdextension compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Oct 20, 2024
1 parent e35c98b commit eaa1464
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 115 deletions.
1 change: 0 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Run the following command to download godot-cpp:
sys.exit(1)

env = SConscript("godot-cpp/SConstruct", {"env": env, "customs": customs})

env.Append(CPPPATH=["src/"])
sources = Glob("src/*.cpp")

Expand Down
2 changes: 1 addition & 1 deletion SCsub
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Import("env")

env.add_source_files(env.modules_sources, "*.cpp")
env.add_source_files(env.modules_sources, "src/*.cpp")
21 changes: 13 additions & 8 deletions godot-cpp/binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,31 +1570,36 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
def generate_compat_includes(godot_repo: Path, target_dir: Path):
file_types_mapping_godot_cpp_gen = map_header_files(target_dir / "include")
file_types_mapping_godot = map_header_files(godot_repo)
# Match the headers

file_types_mapping = match_headers(file_types_mapping_godot_cpp_gen, file_types_mapping_godot)

include_gen_folder = Path(target_dir) / "include"
include_gen_folder = (Path(target_dir) / "include").as_posix()
for file_godot_cpp_name, file_godot_names in file_types_mapping.items():
header_filename = file_godot_cpp_name.replace("godot_cpp", "godot_compat")
header_filepath = include_gen_folder / header_filename
Path(os.path.dirname(header_filepath)).mkdir(parents=True, exist_ok=True)
header_filepath = Path(include_gen_folder) / header_filename

Path(os.path.dirname(header_filepath.as_posix())).mkdir(parents=True, exist_ok=True)

result = []
snake_header_name = camel_to_snake(header_filename)
add_header(f"{snake_header_name}.hpp", result)

header_guard = f"GODOT_COMPAT_{os.path.splitext(os.path.basename(header_filepath).upper())[0]}_HPP"
header_guard = f"GODOT_COMPAT_{os.path.splitext(os.path.basename(header_filepath.as_posix()).upper())[0]}_HPP"
result.append(f"#ifndef {header_guard}")
result.append(f"#define {header_guard}")
result.append("")
result.append(f"#ifdef GODOT_MODULE_COMPAT")

for file_godot_name in file_godot_names:
result.append(f"#include <{file_godot_name}>")
result.append(f"#include <{Path(file_godot_name).as_posix()}>")

result.append(f"#else")
result.append(f"#include <{file_godot_cpp_name}>")
result.append(f"#include <{Path(file_godot_cpp_name).as_posix()}>")
result.append(f"#endif")
result.append("")
result.append(f"#endif // ! {header_guard}")
with header_filepath.open("w+", encoding="utf-8") as header_file:

with open(header_filepath.as_posix(), "w+", encoding="utf-8") as header_file:
header_file.write("\n".join(result))


Expand Down
2 changes: 1 addition & 1 deletion godot-cpp/header_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def match_headers(mapping1, mapping2):
# Load the two header mappings
with open("output_header_mapping_godot.json", "r") as file:
mapping_godot = json.load(file)
file_types_mapping_godot_cpp_gen = map_header_files(os.getcwd() / "gen" / "include")
file_types_mapping_godot_cpp_gen = map_header_files(os.path.join(os.getcwd(), "gen", "include"))
matches = match_headers(file_types_mapping_godot_cpp_gen, mapping_godot)

# Optionally, you can save the matches to a file
Expand Down
54 changes: 0 additions & 54 deletions register_types.cpp

This file was deleted.

39 changes: 0 additions & 39 deletions register_types.h

This file was deleted.

4 changes: 2 additions & 2 deletions domain.cpp → src/domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

#include "domain.h"

#include "modules/goal_task_planner/multigoal.h"
#include "modules/goal_task_planner/plan.h"
#include "multigoal.h"
#include "plan.h"

void Domain::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_multigoal_methods", "methods"), &Domain::add_multigoal_methods);
Expand Down
4 changes: 3 additions & 1 deletion domain.h → src/domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@

#include "multigoal.h"

#include "core/variant/typed_array.h"
#include <godot_compat/variant/array.hpp>
#include <godot_compat/variant/dictionary.hpp>
#include <godot_compat/classes/resource.hpp>

class Plan;
class Domain : public Resource {
Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions multigoal.h → src/multigoal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
// Author: Dana Nau <[email protected]>, July 7, 2021

#include "core/io/resource.h"
#include "core/variant/dictionary.h"

#include "domain.h"
#include <godot_compat/variant/dictionary.hpp>
#include <godot_compat/classes/resource.hpp>

class Domain;
class Multigoal : public Resource {
GDCLASS(Multigoal, Resource);

Expand Down
2 changes: 2 additions & 0 deletions plan.cpp → src/plan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "modules/goal_task_planner/domain.h"
#include "modules/goal_task_planner/multigoal.h"

using namespace godot;

int Plan::get_verbose() const { return verbose; }

TypedArray<Domain> Plan::get_domains() const { return domains; }
Expand Down
6 changes: 3 additions & 3 deletions plan.h → src/plan.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear
// Author: Dana Nau <[email protected]>, July 7, 2021

#include "core/io/resource.h"
#include "core/variant/typed_array.h"
#include <godot_compat/variant/array.hpp>
#include <godot_compat/classes/resource.hpp>

#include "modules/goal_task_planner/multigoal.h"
#include "multigoal.h"

class Domain;
class Plan : public Resource {
Expand Down
8 changes: 7 additions & 1 deletion src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>

#include "plan.h"
#include "domain.h"
#include "multigoal.h"

using namespace godot;

void initialize_gdextension_types(ModuleInitializationLevel p_level)
{
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
//GDREGISTER_CLASS(YourClass);
ClassDB::register_class<Domain>();
ClassDB::register_class<Multigoal>();
ClassDB::register_class<Plan>();
}

void uninitialize_gdextension_types(ModuleInitializationLevel p_level) {
Expand Down

0 comments on commit eaa1464

Please sign in to comment.