Merge pull request #35 from aaronfranke/formatting

Add formatting scripts for GitHub Actions
This commit is contained in:
Aaron Franke
2020-08-15 13:01:24 -05:00
committed by GitHub
27 changed files with 472 additions and 211 deletions

128
.clang-format Normal file
View File

@@ -0,0 +1,128 @@
# Commented out parameters are those with the same value as base LLVM style
# We can uncomment them if we want to change their value, or enforce the
# chosen value in case the base style changes (last sync: Clang 6.0.1).
---
### General config, applies to all languages ###
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
# AlignConsecutiveAssignments: false
# AlignConsecutiveDeclarations: false
# AlignEscapedNewlines: Right
# AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
# AllowShortBlocksOnASingleLine: false
# AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
# AllowShortIfStatementsOnASingleLine: false
# AllowShortLoopsOnASingleLine: false
# AlwaysBreakAfterDefinitionReturnType: None
# AlwaysBreakAfterReturnType: None
# AlwaysBreakBeforeMultilineStrings: false
# AlwaysBreakTemplateDeclarations: false
# BinPackArguments: true
# BinPackParameters: true
# BraceWrapping:
# AfterClass: false
# AfterControlStatement: false
# AfterEnum: false
# AfterFunction: false
# AfterNamespace: false
# AfterObjCDeclaration: false
# AfterStruct: false
# AfterUnion: false
# AfterExternBlock: false
# BeforeCatch: false
# BeforeElse: false
# IndentBraces: false
# SplitEmptyFunction: true
# SplitEmptyRecord: true
# SplitEmptyNamespace: true
# BreakBeforeBinaryOperators: None
# BreakBeforeBraces: Attach
# BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
# BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: AfterColon
# BreakStringLiterals: true
ColumnLimit: 0
# CommentPragmas: '^ IWYU pragma:'
# CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
Cpp11BracedListStyle: false
# DerivePointerAlignment: false
# DisableFormat: false
# ExperimentalAutoDetectBinPacking: false
# FixNamespaceComments: true
# ForEachMacros:
# - foreach
# - Q_FOREACH
# - BOOST_FOREACH
# IncludeBlocks: Preserve
IncludeCategories:
- Regex: '".*"'
Priority: 1
- Regex: '^<.*\.h>'
Priority: 2
- Regex: '^<.*'
Priority: 3
# IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
# IndentPPDirectives: None
IndentWidth: 4
# IndentWrappedFunctionNames: false
# JavaScriptQuotes: Leave
# JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
# MacroBlockBegin: ''
# MacroBlockEnd: ''
# MaxEmptyLinesToKeep: 1
# NamespaceIndentation: None
# PenaltyBreakAssignment: 2
# PenaltyBreakBeforeFirstCallParameter: 19
# PenaltyBreakComment: 300
# PenaltyBreakFirstLessLess: 120
# PenaltyBreakString: 1000
# PenaltyExcessCharacter: 1000000
# PenaltyReturnTypeOnItsOwnLine: 60
# PointerAlignment: Right
# RawStringFormats:
# - Delimiter: pb
# Language: TextProto
# BasedOnStyle: google
# ReflowComments: true
# SortIncludes: true
# SortUsingDeclarations: true
# SpaceAfterCStyleCast: false
# SpaceAfterTemplateKeyword: true
# SpaceBeforeAssignmentOperators: true
# SpaceBeforeParens: ControlStatements
# SpaceInEmptyParentheses: false
# SpacesBeforeTrailingComments: 1
# SpacesInAngles: false
# SpacesInContainerLiterals: true
# SpacesInCStyleCastParentheses: false
# SpacesInParentheses: false
# SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Always
---
### C++ specific config ###
Language: Cpp
Standard: Cpp11
---
### ObjC specific config ###
Language: ObjC
Standard: Cpp11
ObjCBlockIndentWidth: 4
# ObjCSpaceAfterProperty: false
# ObjCSpaceBeforeProtocolList: true
---
### Java specific config ###
Language: Java
# BreakAfterJavaFieldAnnotations: false
JavaImportGroups: ['org.godotengine', 'android', 'androidx', 'com.android', 'com.google', 'java', 'javax']
...

2
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,2 @@
patreon: godotengine
custom: https://godotengine.org/donate

32
.github/workflows/scripts/black_format.sh vendored Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# This script runs black on all Python files in the repo.
set -uo pipefail
# Apply black.
echo -e "Formatting Python files..."
PY_FILES=$(find \( -path "./.git" \
\) -prune \
-o \( -name "SConstruct" \
-o -name "SCsub" \
-o -name "*.py" \
\) -print)
black -l 120 $PY_FILES
git diff > patch.patch
# If no patch has been generated all is OK, clean up, and exit.
if [ ! -s patch.patch ] ; then
printf "Files in this commit comply with the black style rules.\n"
rm -f patch.patch
exit 0
fi
# A patch has been created, notify the user, clean up, and exit.
printf "\n*** The following differences were found between the code "
printf "and the formatting rules:\n\n"
cat patch.patch
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
rm -f patch.patch
exit 1

37
.github/workflows/scripts/clang_format.sh vendored Executable file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# This script runs clang-format on all relevant files in the repo.
# This is the primary script responsible for fixing style violations.
set -uo pipefail
IFS=$'\n\t'
CLANG_FORMAT_FILE_EXTS=(".c" ".h" ".cpp" ".hpp" ".cc" ".hh" ".cxx" ".m" ".mm" ".inc" ".java" ".glsl")
# Loops through all text files tracked by Git.
git grep -zIl '' |
while IFS= read -rd '' f; do
for extension in ${CLANG_FORMAT_FILE_EXTS[@]}; do
if [[ "$f" == *"$extension" ]]; then
# Run clang-format.
clang-format -i "$f"
fi
done
done
git diff > patch.patch
# If no patch has been generated all is OK, clean up, and exit.
if [ ! -s patch.patch ] ; then
printf "Files in this commit comply with the clang-format style rules.\n"
rm -f patch.patch
exit 0
fi
# A patch has been created, notify the user, clean up, and exit.
printf "\n*** The following differences were found between the code "
printf "and the formatting rules:\n\n"
cat patch.patch
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
rm -f patch.patch
exit 1

57
.github/workflows/scripts/file_format.sh vendored Executable file
View File

@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# This script ensures proper POSIX text file formatting and a few other things.
# This is supplementary to clang_format.sh and black_format.sh, but should be
# run before them.
# We need dos2unix and recode.
if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v recode)" ]; then
printf "Install 'dos2unix' and 'recode' to use this script.\n"
fi
set -uo pipefail
IFS=$'\n\t'
# Loops through all text files tracked by Git.
git grep -zIl '' |
while IFS= read -rd '' f; do
# Ensure that files are UTF-8 formatted.
recode UTF-8 "$f" 2> /dev/null
# Ensure that files have LF line endings and do not contain a BOM.
dos2unix "$f" 2> /dev/null
# Remove trailing space characters and ensures that files end
# with newline characters. -l option handles newlines conveniently.
perl -i -ple 's/\s*$//g' "$f"
# Remove the character sequence "== true" if it has a leading space.
perl -i -pe 's/\x20== true//g' "$f"
# We don't want to change lines around braces in godot/tscn files.
if [[ "$f" == *"godot" ]]; then
continue
elif [[ "$f" == *"tscn" ]]; then
continue
fi
if [[ $(uname) == "Linux" ]] && [[ "$f" != *"xml" ]]; then
# Remove empty lines after the opening brace of indented blocks.
sed -z -i 's/\x7B\x0A\x0A\x09/\x7B\x0A\x09/g' "$f"
# Remove empty lines before the closing brace (in some cases).
sed -z -i 's/\x0A\x0A\x7D/\x0A\x7D/g' "$f"
fi
done
git diff > patch.patch
# If no patch has been generated all is OK, clean up, and exit.
if [ ! -s patch.patch ] ; then
printf "Files in this commit comply with the formatting rules.\n"
rm -f patch.patch
exit 0
fi
# A patch has been created, notify the user, clean up, and exit.
printf "\n*** The following differences were found between the code "
printf "and the formatting rules:\n\n"
cat patch.patch
printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
rm -f patch.patch
exit 1

28
.github/workflows/static_checks.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: Static Checks
on: [push, pull_request]
jobs:
static-checks:
name: Formatting (clang-format, black format, file format)
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -qq dos2unix recode clang-format
sudo pip3 install git+https://github.com/psf/black@master
- name: File formatting checks (file_format.sh)
run: |
bash ./.github/workflows/scripts/file_format.sh
- name: C/C++ style checks via clang-format (clang_format.sh)
run: |
bash ./.github/workflows/scripts/clang_format.sh
- name: Python style checks via black (black_format.sh)
run: |
bash ./.github/workflows/scripts/black_format.sh

View File

@@ -10,7 +10,7 @@ git clone --recursive https://github.com/GodotNativeTools/godot-cpp
### Updating the api.json
Our api.json file contains meta data of all the classes that are part of the Godot core and are needed to generate the C++ binding classes for use in GDNative modules.
Our api.json file contains meta data of all the classes that are part of the Godot core and are needed to generate the C++ binding classes for use in GDNative modules.
This file is supplied with our godot_headers repository for your convinience but if you are running a custom build of Godot and need access to classes that have recent changes a new api.json file must be generated. You do this by starting your Godot executable with the following parameters:

View File

@@ -9,12 +9,12 @@ onready var window = preload(\"res://GLFW.gdns\").new()
func _ready():
# create a 200x200 px window
# create a 200x200 px window
window.create(200, 200, \"Hello from Godot!\")
# connect the \"closed\" signal
window.connect(\"closed\", self, \"on_window_close\")
func on_window_close():
# the window emits a signal when the users requests
# to close it. So let's close it :D

View File

@@ -10,8 +10,7 @@ struct glfw {
const godot_gdnative_core_api_struct *api = NULL;
const godot_gdnative_ext_nativescript_api_struct *nativescript_api = NULL;
void window_close_callback(GLFWwindow* window)
{
void window_close_callback(GLFWwindow *window) {
godot_object *instance = glfwGetWindowUserPointer(window);
// emit a signal
@@ -61,25 +60,22 @@ void *glfw_constructor(godot_object *instance, void *method_data);
void glfw_destructor(godot_object *instance, void *method_data, struct glfw *user_data);
godot_variant glfw_create_window(godot_object *instance, void *method_data,
struct glfw *user_data,
int num_args, godot_variant **args);
struct glfw *user_data,
int num_args, godot_variant **args);
godot_variant glfw_close(godot_object *instance, void *method_data,
struct glfw *user_data,
int num_args, godot_variant **args);
struct glfw *user_data,
int num_args, godot_variant **args);
godot_variant glfw_poll_events(godot_object *instance, void *method_data,
struct glfw *user_data,
int num_args, godot_variant **args);
struct glfw *user_data,
int num_args, godot_variant **args);
godot_variant glfw_is_closed(godot_object *instance, void *method_data,
struct glfw *user_data,
int num_args, godot_variant **args);
struct glfw *user_data,
int num_args, godot_variant **args);
void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *p_options)
{
void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *p_options) {
api = p_options->api_struct;
// now find our extensions
@@ -88,13 +84,13 @@ void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *p_options)
case GDNATIVE_EXT_NATIVESCRIPT: {
nativescript_api = (godot_gdnative_ext_nativescript_api_struct *)api->extensions[i];
}; break;
default: break;
default:
break;
};
};
}
void GDN_EXPORT godot_nativescript_init(void *p_handle)
{
void GDN_EXPORT godot_nativescript_init(void *p_handle) {
if (!glfwInit()) {
fprintf(stderr, "can't initialize GLFW\n");
return;
@@ -128,7 +124,6 @@ void GDN_EXPORT godot_nativescript_init(void *p_handle)
nativescript_api->godot_nativescript_register_method(p_handle, "GLFW", "close", attributes, close_window);
}
{
godot_instance_method poll_events = {};
poll_events.method = &glfw_poll_events;
@@ -162,15 +157,13 @@ void GDN_EXPORT godot_nativescript_init(void *p_handle)
}
}
void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *options)
{
void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *options) {
glfwTerminate();
}
godot_variant glfw_create_window(godot_object *instance, void *method_data,
struct glfw *user_data,
int num_args, godot_variant **args)
{
struct glfw *user_data,
int num_args, godot_variant **args) {
godot_variant ret;
api->godot_variant_new_nil(&ret);
@@ -197,12 +190,9 @@ godot_variant glfw_create_window(godot_object *instance, void *method_data,
return ret;
}
godot_variant glfw_close(godot_object *instance, void *method_data,
struct glfw *user_data,
int num_args, godot_variant **args)
{
struct glfw *user_data,
int num_args, godot_variant **args) {
godot_variant ret;
api->godot_variant_new_nil(&ret);
@@ -214,22 +204,18 @@ godot_variant glfw_close(godot_object *instance, void *method_data,
return ret;
}
godot_variant glfw_is_closed(godot_object *instance, void *method_data,
struct glfw *user_data,
int num_args, godot_variant **args)
{
struct glfw *user_data,
int num_args, godot_variant **args) {
godot_variant ret;
api->godot_variant_new_bool(&ret, user_data->window == NULL);
return ret;
}
godot_variant glfw_poll_events(godot_object *instance, void *method_data,
struct glfw *user_data,
int num_args, godot_variant **args)
{
struct glfw *user_data,
int num_args, godot_variant **args) {
godot_variant ret;
api->godot_variant_new_nil(&ret);
@@ -238,12 +224,7 @@ godot_variant glfw_poll_events(godot_object *instance, void *method_data,
return ret;
}
void *glfw_constructor(godot_object *instance, void *method_data)
{
void *glfw_constructor(godot_object *instance, void *method_data) {
printf("GLFW._init()\n");
struct glfw *user_data = api->godot_alloc(sizeof(struct glfw));
@@ -252,8 +233,7 @@ void *glfw_constructor(godot_object *instance, void *method_data)
return user_data;
}
void glfw_destructor(godot_object *instance, void *method_data, struct glfw *user_data)
{
void glfw_destructor(godot_object *instance, void *method_data, struct glfw *user_data) {
// destroy window
if (user_data->window) {

View File

@@ -10,38 +10,40 @@ target = ARGUMENTS.get("target", "debug")
platform = ARGUMENTS.get("p", "linux")
platform = ARGUMENTS.get("platform", platform)
# This makes sure to keep the session environment variables on windows,
# This makes sure to keep the session environment variables on windows,
# that way you can run scons in a vs 2017 prompt and it will find all the required tools
env = Environment()
if platform == "windows":
env = Environment(ENV = os.environ)
env = Environment(ENV=os.environ)
if ARGUMENTS.get("use_llvm", "no") == "yes":
env["CC"] = "clang"
def add_sources(sources, directory):
for file in os.listdir(directory):
if file.endswith('.c'):
sources.append(directory + '/' + file)
if file.endswith(".c"):
sources.append(directory + "/" + file)
if platform == "osx":
env.Append(CCFLAGS = ['-g','-O3', '-arch', 'x86_64'])
env.Append(LINKFLAGS = ['-arch', 'x86_64'])
env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
if platform == "linux":
env.Append(CCFLAGS = ['-fPIC', '-g','-O3', '-std=c11'])
env.Append(CCFLAGS=["-fPIC", "-g", "-O3", "-std=c11"])
if platform == "windows":
if target == "debug":
env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '/MDd'])
env.Append(CCFLAGS=["-EHsc", "-D_DEBUG", "/MDd"])
else:
env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '/MD'])
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "/MD"])
# , 'include', 'include/core'
env.Append(CPPPATH=['.', godot_headers_path])
env.Append(CPPPATH=[".", godot_headers_path])
sources = []
add_sources(sources, "src")
library = env.SharedLibrary(target='bin/instance_binding_demo', source=sources)
library = env.SharedLibrary(target="bin/instance_binding_demo", source=sources)
Default(library)

View File

@@ -6,5 +6,5 @@ onready var data = InstanceBindingDemo.new()
func _on_Button_pressed():
# do the test here
pass
pass

View File

@@ -3,7 +3,6 @@
#include <stdlib.h>
#include <string.h>
const godot_gdnative_core_api_struct *api = NULL;
const godot_gdnative_ext_nativescript_api_struct *nativescript_api = NULL;
const godot_gdnative_ext_nativescript_1_1_api_struct *nativescript_1_1_api = NULL;
@@ -24,8 +23,7 @@ typedef struct wrapper_object {
char *message;
} wrapper_object;
void *create_wrapper_object(void *data, godot_object *object)
{
void *create_wrapper_object(void *data, godot_object *object) {
printf("we are now creating a wrapper object...\n");
fflush(stdout);
@@ -38,17 +36,14 @@ void *create_wrapper_object(void *data, godot_object *object)
return wrapper;
}
void destroy_wrapper_object(void *data, void *wrapper)
{
void destroy_wrapper_object(void *data, void *wrapper) {
api->godot_free(wrapper);
printf("the wrapper object got destroyed.\n");
fflush(stdout);
}
void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *options)
{
void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *options) {
api = options->api_struct;
// now find our extensions
@@ -61,26 +56,22 @@ void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *options)
break;
if (nativescript_api->next->version.major == 1 && nativescript_api->next->version.minor == 1) {
nativescript_1_1_api = (const godot_gdnative_ext_nativescript_1_1_api_struct *) nativescript_api->next;
nativescript_1_1_api = (const godot_gdnative_ext_nativescript_1_1_api_struct *)nativescript_api->next;
}
}; break;
default: break;
default:
break;
};
};
}
void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *options)
{
void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *options) {
api = NULL;
nativescript_api = NULL;
nativescript_1_1_api = NULL;
}
void GDN_EXPORT godot_nativescript_init(void *handle)
{
void GDN_EXPORT godot_nativescript_init(void *handle) {
printf("nativescript_init\n");
fflush(stdout);
@@ -103,17 +94,14 @@ void GDN_EXPORT godot_nativescript_init(void *handle)
destructor.destroy_func = &ibd_destructor;
nativescript_api->godot_nativescript_register_class(handle, "InstanceBindingDemo", "Reference", constructor, destructor);
}
}
void GDN_EXPORT godot_nativescript_terminate(void *handle)
{
void GDN_EXPORT godot_nativescript_terminate(void *handle) {
nativescript_1_1_api->godot_nativescript_unregister_instance_binding_data_functions(language_binding_index);
}
GDCALLINGCONV void *ibd_constructor(godot_object *instance, void *method_data)
{
GDCALLINGCONV void *ibd_constructor(godot_object *instance, void *method_data) {
wrapper_object *wrapper = nativescript_1_1_api->godot_nativescript_get_instance_binding_data(language_binding_index, instance);
printf("message is: %s\n", wrapper->message);
@@ -122,6 +110,5 @@ GDCALLINGCONV void *ibd_constructor(godot_object *instance, void *method_data)
return NULL;
}
GDCALLINGCONV void ibd_destructor(godot_object *instance, void *method_data, void *user_data)
{
GDCALLINGCONV void ibd_destructor(godot_object *instance, void *method_data, void *user_data) {
}

View File

@@ -7,12 +7,12 @@ opts = Variables([], ARGUMENTS)
env = DefaultEnvironment()
# Define our options
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release']))
opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx']))
opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['', 'windows', 'x11', 'linux', 'osx']))
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'demo/bin/'))
opts.Add(PathVariable('target_name', 'The library name.', 'libsimple', PathVariable.PathAccept))
opts.Add(EnumVariable("target", "Compilation target", "debug", ["d", "debug", "r", "release"]))
opts.Add(EnumVariable("platform", "Compilation platform", "", ["", "windows", "x11", "linux", "osx"]))
opts.Add(EnumVariable("p", "Compilation target, alias for 'platform'", "", ["", "windows", "x11", "linux", "osx"]))
opts.Add(BoolVariable("use_llvm", "Use the LLVM / Clang compiler", "no"))
opts.Add(PathVariable("target_path", "The path where the lib is installed.", "demo/bin/"))
opts.Add(PathVariable("target_name", "The library name.", "libsimple", PathVariable.PathAccept))
# Local dependency paths, adapt them to your setup
godot_headers_path = "godot_headers/"
@@ -24,54 +24,54 @@ bits = 64
opts.Update(env)
# Process some arguments
if env['use_llvm']:
env['CC'] = 'clang'
env['CXX'] = 'clang++'
if env["use_llvm"]:
env["CC"] = "clang"
env["CXX"] = "clang++"
if env['p'] != '':
env['platform'] = env['p']
if env["p"] != "":
env["platform"] = env["p"]
if env['platform'] == '':
if env["platform"] == "":
print("No valid target platform selected.")
quit();
quit()
# Check our platform specifics
if env['platform'] == "osx":
env['target_path'] += 'osx/'
if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-g','-O2', '-arch', 'x86_64'])
env.Append(LINKFLAGS = ['-arch', 'x86_64'])
if env["platform"] == "osx":
env["target_path"] += "osx/"
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-g", "-O2", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
else:
env.Append(CCFLAGS = ['-g','-O3', '-arch', 'x86_64'])
env.Append(LINKFLAGS = ['-arch', 'x86_64'])
env.Append(CCFLAGS=["-g", "-O3", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64"])
elif env['platform'] in ('x11', 'linux'):
env['target_path'] += 'x11/'
if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-fPIC', '-g3','-Og', '-std=c++17'])
elif env["platform"] in ("x11", "linux"):
env["target_path"] += "x11/"
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-fPIC", "-g3", "-Og", "-std=c++17"])
else:
env.Append(CCFLAGS = ['-fPIC', '-g','-O3', '-std=c++17'])
env.Append(CCFLAGS=["-fPIC", "-g", "-O3", "-std=c++17"])
elif env['platform'] == "windows":
env['target_path'] += 'win64/'
elif env["platform"] == "windows":
env["target_path"] += "win64/"
# This makes sure to keep the session environment variables on windows,
# that way you can run scons in a vs 2017 prompt and it will find all the required tools
env.Append(ENV = os.environ)
env.Append(ENV=os.environ)
env.Append(CCFLAGS = ['-DWIN32', '-D_WIN32', '-D_WINDOWS', '-W3', '-GR', '-D_CRT_SECURE_NO_WARNINGS'])
if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '-MDd'])
env.Append(CCFLAGS=["-DWIN32", "-D_WIN32", "-D_WINDOWS", "-W3", "-GR", "-D_CRT_SECURE_NO_WARNINGS"])
if env["target"] in ("debug", "d"):
env.Append(CCFLAGS=["-EHsc", "-D_DEBUG", "-MDd"])
else:
env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '-MD'])
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "-MD"])
# make sure our binding library is properly includes
env.Append(CPPPATH=['.', godot_headers_path])
env.Append(CPPPATH=[".", godot_headers_path])
# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=['src/'])
sources = Glob('src/*.c')
env.Append(CPPPATH=["src/"])
sources = Glob("src/*.c")
library = env.SharedLibrary(target=env['target_path'] + env['target_name'] , source=sources)
library = env.SharedLibrary(target=env["target_path"] + env["target_name"], source=sources)
Default(library)

View File

@@ -23,9 +23,10 @@ void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *p_options) {
case GDNATIVE_EXT_NATIVESCRIPT: {
nativescript_api = (godot_gdnative_ext_nativescript_api_struct *)api->extensions[i];
}; break;
default: break;
default:
break;
};
};
};
}
void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *p_options) {
@@ -52,7 +53,7 @@ void GDN_EXPORT godot_nativescript_init(void *p_handle) {
GDCALLINGCONV void *simple_constructor(godot_object *p_instance, void *p_method_data) {
printf("SIMPLE._init()\n");
user_data_struct *user_data = api->godot_alloc(sizeof(user_data_struct));
strcpy(user_data->data, "World from GDNative!");
@@ -68,7 +69,7 @@ GDCALLINGCONV void simple_destructor(godot_object *p_instance, void *p_method_da
godot_variant simple_get_data(godot_object *p_instance, void *p_method_data, void *p_user_data, int p_num_args, godot_variant **p_args) {
godot_string data;
godot_variant ret;
user_data_struct * user_data = (user_data_struct *) p_user_data;
user_data_struct *user_data = (user_data_struct *)p_user_data;
api->godot_string_new(&data);
api->godot_string_parse_utf8(&data, user_data->data);

View File

@@ -5,11 +5,11 @@ import os
platform = ARGUMENTS.get("p", "linux")
platform = ARGUMENTS.get("platform", platform)
# This makes sure to keep the session environment variables on windows,
# This makes sure to keep the session environment variables on windows,
# that way you can run scons in a vs 2017 prompt and it will find all the required tools
env = Environment()
if platform == "windows":
env = Environment(ENV = os.environ)
env = Environment(ENV=os.environ)
godot_headers_path = ARGUMENTS.get("headers", os.getenv("GODOT_HEADERS", "godot-cpp/godot_headers"))
godot_bindings_path = ARGUMENTS.get("cpp_bindings", os.getenv("CPP_BINDINGS", "godot-cpp"))
@@ -21,38 +21,46 @@ target = ARGUMENTS.get("target", "debug")
if ARGUMENTS.get("use_llvm", "no") == "yes":
env["CXX"] = "clang++"
# put stuff that is the same for all first, saves duplication
# put stuff that is the same for all first, saves duplication
if platform == "osx":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-arch', 'x86_64'])
env.Append(LINKFLAGS = ['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup'])
env.Append(CCFLAGS=["-g", "-O3", "-std=c++14", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64", "-framework", "Cocoa", "-Wl,-undefined,dynamic_lookup"])
elif platform == "linux":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-Wno-writable-strings'])
env.Append(LINKFLAGS = ['-Wl,-R,\'$$ORIGIN\''])
env.Append(CCFLAGS=["-g", "-O3", "-std=c++14", "-Wno-writable-strings"])
env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
elif platform == "windows":
# need to add detection of msvc vs mingw, this is for msvc...
env.Append(LINKFLAGS = ['/WX'])
env.Append(LINKFLAGS=["/WX"])
if target == "debug":
env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '/MDd'])
env.Append(CCFLAGS=["-EHsc", "-D_DEBUG", "/MDd"])
else:
env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '/MD'])
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "/MD"])
def add_sources(sources, dir):
for f in os.listdir(dir):
if f.endswith(".cpp"):
sources.append(dir + "/" + f)
env.Append(CPPPATH=[godot_headers_path, godot_bindings_path + '/include', godot_bindings_path + '/include/gen/', godot_bindings_path + '/include/core/'])
env.Append(
CPPPATH=[
godot_headers_path,
godot_bindings_path + "/include",
godot_bindings_path + "/include/gen/",
godot_bindings_path + "/include/core/",
]
)
if target == "debug":
env.Append(LIBS=['libgodot-cpp.linux.debug.64'])
env.Append(LIBS=["libgodot-cpp.linux.debug.64"])
else:
env.Append(LIBS=['libgodot-cpp.linux.release.64'])
env.Append(LIBS=["libgodot-cpp.linux.release.64"])
env.Append(LIBPATH=[ godot_bindings_path + '/bin/' ])
env.Append(LIBPATH=[godot_bindings_path + "/bin/"])
sources = []
add_sources(sources, "src")
library = env.SharedLibrary(target='bin/libsimple', source=sources)
library = env.SharedLibrary(target="bin/libsimple", source=sources)
Default(library)

View File

@@ -6,4 +6,4 @@ onready var simple_instance = Simple.new()
func _on_Button_pressed():
$Label.text = "C++ code says: " + simple_instance.get_data()
$Label.text = "C++ code says: " + simple_instance.get_data()

View File

@@ -2,33 +2,27 @@
#include "Input.hpp"
void Simple::_register_methods()
{
void Simple::_register_methods() {
godot::register_method("get_data", &Simple::get_data);
}
void Simple::_init()
{
void Simple::_init() {
data = "Hello World from C++";
}
godot::String Simple::get_data() const
{
godot::String Simple::get_data() const {
return data;
}
void SimpleSprite::_register_methods()
{
void SimpleSprite::_register_methods() {
godot::register_method("_process", &SimpleSprite::_process);
}
void SimpleSprite::_init()
{
void SimpleSprite::_init() {
godot::Godot::print("Wheeeeey");
}
void SimpleSprite::_process(double delta)
{
void SimpleSprite::_process(double delta) {
godot::Vector2 input_dir(0, 0);
if (godot::Input::get_singleton()->is_action_pressed("ui_right")) {

View File

@@ -5,10 +5,10 @@
class Simple : public godot::Reference {
GODOT_CLASS(Simple, godot::Reference)
godot::String data;
public:
godot::String data;
public:
static void _register_methods();
void _init();

View File

@@ -2,21 +2,17 @@
#include "Simple.hpp"
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o)
{
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
godot::Godot::gdnative_init(o);
}
extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o)
{
extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o) {
godot::Godot::gdnative_terminate(o);
}
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
{
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) {
godot::Godot::nativescript_init(handle);
godot::register_class<Simple>();
godot::register_class<SimpleSprite>();
}

View File

@@ -5,11 +5,11 @@ import os
platform = ARGUMENTS.get("p", "linux")
platform = ARGUMENTS.get("platform", platform)
# This makes sure to keep the session environment variables on windows,
# This makes sure to keep the session environment variables on windows,
# that way you can run scons in a vs 2017 prompt and it will find all the required tools
env = Environment()
if platform == "windows":
env = Environment(ENV = os.environ)
env = Environment(ENV=os.environ)
godot_headers_path = ARGUMENTS.get("headers", os.getenv("GODOT_HEADERS", "godot-cpp/godot_headers"))
godot_bindings_path = ARGUMENTS.get("cpp_bindings", os.getenv("CPP_BINDINGS", "godot-cpp"))
@@ -21,37 +21,45 @@ target = ARGUMENTS.get("target", "debug")
if ARGUMENTS.get("use_llvm", "no") == "yes":
env["CXX"] = "clang++"
# put stuff that is the same for all first, saves duplication
# put stuff that is the same for all first, saves duplication
if platform == "osx":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-arch', 'x86_64'])
env.Append(LINKFLAGS = ['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup'])
env.Append(CCFLAGS=["-g", "-O3", "-std=c++14", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64", "-framework", "Cocoa", "-Wl,-undefined,dynamic_lookup"])
elif platform == "linux":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-Wno-writable-strings'])
env.Append(LINKFLAGS = ['-Wl,-R,\'$$ORIGIN\''])
env.Append(CCFLAGS=["-g", "-O3", "-std=c++14", "-Wno-writable-strings"])
env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
elif platform == "windows":
# need to add detection of msvc vs mingw, this is for msvc...
env.Append(LINKFLAGS = ['/WX'])
env.Append(LINKFLAGS=["/WX"])
if target == "debug":
env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '/MDd'])
env.Append(CCFLAGS=["-EHsc", "-D_DEBUG", "/MDd"])
else:
env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '/MD'])
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "/MD"])
def add_sources(sources, dir):
for f in os.listdir(dir):
if f.endswith(".cpp"):
sources.append(dir + "/" + f)
env.Append(CPPPATH=[godot_headers_path, godot_bindings_path + '/include', godot_bindings_path + '/include/gen/', godot_bindings_path + '/include/core/'])
env.Append(
CPPPATH=[
godot_headers_path,
godot_bindings_path + "/include",
godot_bindings_path + "/include/gen/",
godot_bindings_path + "/include/core/",
]
)
if target == "debug":
env.Append(LIBS=['libgodot-cpp.linux.debug.64'])
env.Append(LIBS=["libgodot-cpp.linux.debug.64"])
else:
env.Append(LIBS=['libgodot-cpp.linux.release.64'])
env.Append(LIBPATH=[ godot_bindings_path + '/bin/' ])
env.Append(LIBS=["libgodot-cpp.linux.release.64"])
env.Append(LIBPATH=[godot_bindings_path + "/bin/"])
sources = []
add_sources(sources, "src")
library = env.SharedLibrary(target='bin/libconstructor', source=sources)
library = env.SharedLibrary(target="bin/libconstructor", source=sources)
Default(library)

View File

@@ -1,10 +1,9 @@
#include <File.hpp>
#include <Reference.hpp>
#include <Timer.hpp>
#include <File.hpp>
#include <Ref.hpp>
#include <stdio.h>
using namespace godot;
@@ -15,13 +14,11 @@ class TestClass : public Reference {
int count;
public:
void _init() {
count = 34;
}
int test_method(String s) {
Godot::print(s);
count++;
@@ -49,4 +46,4 @@ public:
static void _register_methods() {
register_method("test_method", &TestClass::test_method);
}
};
};

View File

@@ -2,18 +2,15 @@
#include "TestClass.hpp"
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o)
{
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
godot::Godot::gdnative_init(o);
}
extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o)
{
extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o) {
godot::Godot::gdnative_terminate(o);
}
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle)
{
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) {
godot::Godot::nativescript_init(handle);
godot::register_class<TestClass>();

View File

@@ -1,6 +1,6 @@
# GDNative example of a kinematic character
This is a demo showing how to use GDNative together with the cpp_bindings layer to implement a couple of new nodes.
This is a demo showing how to use GDNative together with the cpp_bindings layer to implement a couple of new nodes.
This demo was originally created by Ramesh Ravone.
Before compiling this module you must clone https://github.com/GodotNativeTools/godot_headers and https://github.com/GodotNativeTools/godot-cpp

View File

@@ -5,11 +5,11 @@ import os
platform = ARGUMENTS.get("p", "linux")
platform = ARGUMENTS.get("platform", platform)
# This makes sure to keep the session environment variables on windows,
# This makes sure to keep the session environment variables on windows,
# that way you can run scons in a vs 2017 prompt and it will find all the required tools
env = Environment()
if platform == "windows":
env = Environment(ENV = os.environ)
env = Environment(ENV=os.environ)
godot_headers_path = ARGUMENTS.get("headers", os.getenv("GODOT_HEADERS", "godot-cpp/godot_headers"))
godot_bindings_path = ARGUMENTS.get("cpp_bindings", os.getenv("CPP_BINDINGS", "godot-cpp"))
@@ -21,37 +21,45 @@ target = ARGUMENTS.get("target", "debug")
if ARGUMENTS.get("use_llvm", "no") == "yes":
env["CXX"] = "clang++"
# put stuff that is the same for all first, saves duplication
# put stuff that is the same for all first, saves duplication
if platform == "osx":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-arch', 'x86_64'])
env.Append(LINKFLAGS = ['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup'])
env.Append(CCFLAGS=["-g", "-O3", "-std=c++14", "-arch", "x86_64"])
env.Append(LINKFLAGS=["-arch", "x86_64", "-framework", "Cocoa", "-Wl,-undefined,dynamic_lookup"])
elif platform == "linux":
env.Append(CCFLAGS = ['-g','-O3', '-std=c++14', '-Wno-writable-strings'])
env.Append(LINKFLAGS = ['-Wl,-R,\'$$ORIGIN\''])
env.Append(CCFLAGS=["-g", "-O3", "-std=c++14", "-Wno-writable-strings"])
env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
elif platform == "windows":
# need to add detection of msvc vs mingw, this is for msvc...
env.Append(LINKFLAGS = ['/WX'])
env.Append(LINKFLAGS=["/WX"])
if target == "debug":
env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '/MDd'])
env.Append(CCFLAGS=["-EHsc", "-D_DEBUG", "/MDd"])
else:
env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '/MD'])
env.Append(CCFLAGS=["-O2", "-EHsc", "-DNDEBUG", "/MD"])
def add_sources(sources, dir):
for f in os.listdir(dir):
if f.endswith(".cpp"):
sources.append(dir + "/" + f)
env.Append(CPPPATH=[godot_headers_path, godot_bindings_path + '/include/gen/', godot_bindings_path + '/include/core/', godot_bindings_path + '/include/'])
env.Append(
CPPPATH=[
godot_headers_path,
godot_bindings_path + "/include/gen/",
godot_bindings_path + "/include/core/",
godot_bindings_path + "/include/",
]
)
if target == "debug":
env.Append(LIBS=['libgodot-cpp.linux.debug.64'])
env.Append(LIBS=["libgodot-cpp.linux.debug.64"])
else:
env.Append(LIBS=['libgodot-cpp.linux.release.64'])
env.Append(LIBPATH=[ godot_bindings_path + '/bin/' ])
env.Append(LIBS=["libgodot-cpp.linux.release.64"])
env.Append(LIBPATH=[godot_bindings_path + "/bin/"])
sources = []
add_sources(sources, "src")
library = env.SharedLibrary(target='bin/libkinematic_char', source=sources)
library = env.SharedLibrary(target="bin/libkinematic_char", source=sources)
Default(library)

View File

@@ -14,4 +14,4 @@ OSX.64="res://Script/bin/libkinematic_char.dylib"
X11.64=[]
Windows.64=[]
OSX.64=[]
OSX.64=[]

View File

@@ -36,6 +36,6 @@ public:
static void _register_methods();
};
}
} // namespace godot
#endif // COLWORLD_H

View File

@@ -30,7 +30,6 @@ extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_opt
}
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) {
Godot::nativescript_init(handle);
register_class<GDPlayer>();