Compare commits

..

36 Commits

Author SHA1 Message Date
Bastiaan Olij
783016677e Merge pull request #190 from lupoDharkael/vector3
Vector3: add missing methods
2018-11-22 22:02:09 +11:00
Thomas Herzog
3a64f81cb7 Merge pull request #191 from clayjohn/nativescript-1.1
Fix Vector3.distance_to
2018-10-26 08:51:08 +02:00
clayjohn
db29a85102 update vector3::distance_to 2018-10-25 09:50:53 -07:00
lupoDharkael
04637d8697 Vector3: add missing methods 2018-10-18 18:32:38 +02:00
Thomas Herzog
b4ab2d2d9b Merge pull request #186 from xfxdev/nativescript-1.1
Fix compile error of 'WARN_PRINT' and 'ERR_PRINT'.
2018-10-06 14:34:11 +02:00
xfx
e909f800d0 Fix compile error of 'WARN_PRINT' and 'ERR_PRINT'.
cannot pass non-trivial object of type 'godot::String' to variadic function; expected type from format string was 'char *' [-Wnon-pod-varargs]
2018-10-06 07:33:05 +08:00
Bastiaan Olij
c6da2c0abe Merge pull request #179 from BastiaanOlij/improve_platform_check
Improved platform checks
2018-09-01 21:51:50 +10:00
Bastiaan Olij
37fabf7e92 Improved platform checks 2018-09-01 21:46:18 +10:00
Thomas Herzog
f7fafbbba4 Merge pull request #170 from mundusnine/patch-1
Adds needed include <typeinfo>
2018-08-15 08:58:03 +02:00
mundusnine
d7236d3504 Adds needed include <typeinfo>
Solves this issue #168 due to not having the include of typeinfo
2018-08-14 16:00:46 -04:00
Thomas Herzog
12aeafd083 Merge pull request #165 from BastiaanOlij/check_nullptr_on_bindingdata
Preventing crash when function returned null ptr
2018-08-05 08:43:35 +02:00
Bastiaan Olij
7c5a1eab11 Preventing crash when function returned null ptr 2018-08-05 14:22:19 +10:00
Thomas Herzog
6d48282187 Merge pull request #162 from BastiaanOlij/fix_subclass
Fixed GODOT_SUBCLASS macro
2018-07-30 14:59:49 +02:00
Bastiaan Olij
0a3fb023d5 Fixed GODOT_SUBCLASS macro 2018-07-30 21:44:24 +10:00
Bastiaan Olij
40a8b38149 Merge pull request #157 from BastiaanOlij/empty_gen
Change gitignore so we get our gen folders
2018-07-29 16:00:28 +10:00
Thomas Herzog
915bc295bd Merge pull request #158 from BastiaanOlij/new_docs
New documentation based on nativescript 1.1
2018-07-28 18:55:25 +02:00
Bastiaan Olij
895dd3a581 New documentation based on nativescript 1.1 2018-07-28 23:48:56 +10:00
Bastiaan Olij
4e74c6373b Change gitignore so we get our gen folders 2018-07-28 22:56:15 +10:00
Thomas Herzog
b2c4d91f4b Merge pull request #150 from Faless/fix_crashes
Fix String::split[_floats] crashes, better error macros
2018-07-26 16:46:13 +02:00
Fabio Alessandrelli
e37b186b57 Better warning/error macros 2018-07-26 15:45:14 +02:00
Fabio Alessandrelli
ec2a9345bd Fix crash when calling String::split/split_floats
Was casting to the wrong object type.
Also adds parse_ints function to String with the same logic
2018-07-26 15:45:14 +02:00
Bastiaan Olij
2ed8e3e217 Merge pull request #155 from BastiaanOlij/fix_register_tool
Fixed up registering tool and updated godot_headers
2018-07-26 22:00:44 +10:00
Bastiaan Olij
75036c5f05 Fixed up registering tool and updated godot_headers 2018-07-26 21:46:59 +10:00
karroffel
b4c7a98d31 fix gitignore 2018-07-25 14:32:27 +02:00
karroffel
7044f45409 remove accidentally added files 2018-07-25 14:29:53 +02:00
karroffel
7fc6a8b98d fix indentation in bindings generator 2018-07-25 14:29:17 +02:00
karroffel
38da87fc0b use typeid() for type tags now 2018-07-25 14:11:40 +02:00
karroffel
1a2afca8af updated .gitignore 2018-07-25 14:11:19 +02:00
karroffel
982e77620c changed build system to be more self contained 2018-07-25 14:10:30 +02:00
karroffel
d420613bd2 fix cast_to 2018-07-25 14:06:34 +02:00
karroffel
b3d705c898 fix global type registration order 2018-07-25 14:06:34 +02:00
karroffel
dabc96ebd9 added type tags and safe object casting 2018-07-25 14:06:34 +02:00
karroffel
37abbe0c09 fix free() crash with custom resources 2018-07-25 14:06:34 +02:00
karroffel
cff59a572e fix exporting of non-object types 2018-07-25 14:06:34 +02:00
karroffel
a4a9a16001 new and free change, custom free will crash engine, be wary 2018-07-25 14:06:34 +02:00
karroffel
e9517a7b3b implemented instance binding data usage
This commit changes the way C++ wrapper classes work.
Previously, wrapper classes were merely wrapper *interfaces*.
They used the `this` pointer to store the actual foreign Godot
Object.

With the NativeScript 1.1 extension it is now possible to have
low-overhead language binding data attached to Objects.

The C++ bindings use that feature to implement *proper* wrappers
and enable regular C++ inheritance usage that way.

Some things might still be buggy and untested, but the C++
SimpleDemo works with those changes.
2018-07-25 14:06:08 +02:00
58 changed files with 144014 additions and 3329 deletions

View File

@@ -1,126 +0,0 @@
# 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: true
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
# 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: true
# 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: Cpp03
---
### ObjC specific config ###
Language: ObjC
ObjCBlockIndentWidth: 4
# ObjCSpaceAfterProperty: false
# ObjCSpaceBeforeProtocolList: true
---
### Java specific config ###
Language: Java
# BreakAfterJavaFieldAnnotations: false
...

2
.gitmodules vendored
View File

@@ -1,3 +1,3 @@
[submodule "godot_headers"]
path = godot_headers
url = https://github.com/godotengine/godot-headers
url = https://github.com/GodotNativeTools/godot_headers

View File

@@ -1,181 +0,0 @@
# cmake arguments
# CMAKE_BUILD_TYPE: Compilation target (Debug or Release defaults to Debug)
#
# godot-cpp cmake arguments
# GODOT_HEADERS_DIR: This is where the gdnative include folder is (godot_source/modules/gdnative/include)
# GODOT_CUSTOM_API_FILE: This is if you have another path for the godot_api.json
#
# Android cmake arguments
# CMAKE_TOOLCHAIN_FILE: The path to the android cmake toolchain ($ANDROID_NDK/build/cmake/android.toolchain.cmake)
# ANDROID_NDK: The path to the android ndk root folder
# ANDROID_TOOLCHAIN_NAME: The android toolchain (arm-linux-androideabi-4.9 or aarch64-linux-android-4.9 or x86-4.9 or x86_64-4.9)
# ANDROID_PLATFORM: The android platform version (android-23)
# More info here: https://godot.readthedocs.io/en/latest/development/compiling/compiling_for_android.html
#
# Examples
#
# Builds a debug version:
# cmake .
# cmake --build .
#
# Builds a release version with clang
# CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" .
# cmake --build .
#
# Builds an android armeabi-v7a debug version:
# cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_NDK=$ANDROID_NDK \
# -DANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 -DANDROID_PLATFORM=android-23 -DCMAKE_BUILD_TYPE=Debug .
# cmake --build .
#
# Protip
# Generate the buildfiles in a sub directory to not clutter the root directory with build files:
# mkdir build && cd build && cmake -G "Unix Makefiles" .. && cmake --build .
#
# Todo
# Test build for Windows, Mac and mingw.
project(godot-cpp)
cmake_minimum_required(VERSION 3.6)
# Change the output directory to the bin directory
set(BUILD_PATH ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BUILD_PATH}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BUILD_PATH}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_PATH}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}")
# Default build type is Debug in the SConstruct
if(CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE Debug)
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
add_definitions(-D_DEBUG)
else()
add_definitions(-DNDEBUG)
endif(CMAKE_BUILD_TYPE MATCHES Debug)
# Set the c++ standard to c++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Input from user for godot headers and the api file
set(GODOT_HEADERS_DIR "godot_headers" CACHE STRING "")
set(GODOT_CUSTOM_API_FILE "godot_headers/api.json" CACHE STRING "")
set(GODOT_COMPILE_FLAGS )
set(GODOT_LINKER_FLAGS )
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# using Visual Studio C++
set(GODOT_COMPILE_FLAGS "/EHsc /WX") # /GF /MP
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MDd") # /Od /RTC1 /Zi
else()
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MD /O2") # /Oy /GL /Gy
STRING(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
endif(CMAKE_BUILD_TYPE MATCHES Debug)
# Disable conversion warning, trunkation, unreferenced var, signed missmatch
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /wd4244 /wd4305 /wd4101 /wd4018 /wd4267")
# Todo: Check if needed.
add_definitions(-DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS)
# Unkomment for warning level 4
#if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
# string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
#endif()
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} -Wlong-long -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")
else()
set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -O3")
endif(CMAKE_BUILD_TYPE MATCHES Debug)
endif()
# Generate source from the bindings file
message(STATUS "Generating Bindings")
execute_process(COMMAND "python" "-c" "import binding_generator; binding_generator.generate_bindings(\"${GODOT_CUSTOM_API_FILE}\")"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GENERATION_RESULT
OUTPUT_VARIABLE GENERATION_OUTPUT)
message(STATUS ${GENERATION_RESULT} ${GENERATION_OUTPUT})
# Get Sources
file(GLOB_RECURSE SOURCES src/*.c**)
file(GLOB_RECURSE HEADERS include/*.h**)
# Define our godot-cpp library
add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS})
target_include_directories(${PROJECT_NAME}
PUBLIC
include
include/core
include/gen
)
# Put godot headers as SYSTEM PUBLIC to exclude warnings from irrelevant headers
target_include_directories(${PROJECT_NAME}
SYSTEM PUBLIC
${GODOT_HEADERS_DIR}
)
# Add the compile flags
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS})
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS ${GODOT_LINKER_FLAGS})
# Create the correct name (godot.os.build_type.system_bits)
set(BITS 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITS 64)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME)
string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
if(ANDROID)
# Added the android abi after system name
set(SYSTEM_NAME ${SYSTEM_NAME}.${ANDROID_ABI})
# Android does not have the bits at the end if you look at the main godot repo build
set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_NAME "godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}")
else()
set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_NAME "godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}.${BITS}")
endif()

View File

@@ -1,6 +1,6 @@
# MIT License
MIT License
Copyright (c) 2017-2019 GodotNativeTools
Copyright (c) 2017 GodotNativeTools
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,12 +1,13 @@
GENERATE_BINDINGS = no
HEADERS = godot_headers
TARGET = debug
NAME = godot-cpp
USE_CLANG = no
BASE = scons use_llvm=$(USE_CLANG) generate_bindings=$(GENERATE_BINDINGS) target=$(TARGET) headers=$(HEADERS) -j4
LINUX = $(BASE) platform=linux
WINDOWS = $(BASE) platform=windows
OSX = $(BASE) platform=osx
BASE = scons n=$(NAME) use_llvm=$(USE_CLANG) generate_bindings=$(GENERATE_BINDINGS) target=$(TARGET) headers=$(HEADERS) -j4
LINUX = $(BASE) p=linux
WINDOWS = $(BASE) p=windows
OSX = $(BASE) p=osx
all:
@@ -19,10 +20,10 @@ linux:
make linux64
linux32: SConstruct
$(LINUX) bits=32
$(LINUX) a=32
linux64: SConstruct
$(LINUX) bits=64
$(LINUX) a=64
windows:
@@ -30,10 +31,10 @@ windows:
make windows64
windows32: SConstruct
$(WINDOWS) bits=32
$(WINDOWS) a=32
windows64: SConstruct
$(WINDOWS) bits=64
$(WINDOWS) a=64
osx:
@@ -41,7 +42,7 @@ osx:
make osx64
osx32: SConstruct
$(OSX) bits=32
$(OSX) a=32
osx64: SConstruct
$(OSX) bits=64
$(OSX) a=64

View File

@@ -1,26 +1,14 @@
# godot-cpp
C++ bindings for the Godot script API
The instructions below feature the new NativeScript 1.1 class structure and will only work for modules created for Godot 3.1 and later. Use the following branches for older implementations:
Note that the master branch in this repository is for use with Godot build from its latest master.
If you need to support older versions of Godot use the relevant branch for that version in this repository.
Version | Branch
--- | ---
**Godot 3.0 Nativescript 1.0** | [3.0](https://github.com/GodotNativeTools/godot-cpp/tree/3.0)
**Godot 3.1 Nativescript 1.0** | [nativescript-1.0](https://github.com/GodotNativeTools/godot-cpp/tree/nativescript-1.0)
The instructions below feature the new NativeScript 1.1 class structure and will only work for modules created for Godot 3.1 and later.
Index:
- [**Contributing**](#contributing)
- [**Getting Started**](#getting-started)
- [**Creating a simple class**](#creating-a-simple-class)
## Contributing
We greatly appreciate help in maintaining and extending this project.
If you wish to help out ensure you have an account on Github and create a "fork" of the this repo.
Rémi "Akien" Verschelde wrote an excellent bit of documentation for the main Godot project on this:
https://docs.godotengine.org/en/3.0/community/contributing/pr_workflow.html
It is advisible to also install clang-format and copy the files in `misc/hooks` into `.git/hooks` so format checking is done before your changes are submitted.
## Getting Started
| **Build latest version of Godot** | [**GitHub**](https://github.com/godotengine/godot) | [**Docs**](https://godot.readthedocs.io/en/latest/development/compiling/index.html) |
@@ -43,12 +31,6 @@ Note that if you wish to use a specific branch, add the -b option to the clone c
$ git clone --recursive https://github.com/GodotNativeTools/godot-cpp -b 3.0
```
If your project is an existing repository, use git submodule instead:
```
$ git submodule add https://github.com/GodotNativeTools/godot-cpp
$ git submodule update --init --recursive
```
Right now our directory structure should look like this:
```
SimpleLibrary/
@@ -61,13 +43,13 @@ SimpleLibrary/
### 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.
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:
A file is supplied in our 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:
```
$ godot --gdnative-generate-json-api api.json
```
Now copy the api.json file into your folder structure so its easy to access. **Note** the remark below for the extra ```custom_api_file``` command line parameter needed to tell scons where to find your file.
Now copy the api.json file into your folder structure so its easy to access.
### Compiling the cpp bindings library
The final step is to compile our cpp bindings library:

View File

@@ -8,133 +8,109 @@ def add_sources(sources, dir, extension):
if f.endswith('.' + extension):
sources.append(dir + '/' + f)
# Try to detect the host platform automatically
# This is used if no `platform` argument is passed
if sys.platform.startswith('linux'):
host_platform = 'linux'
elif sys.platform == 'darwin':
host_platform = 'osx'
elif sys.platform == 'win32':
host_platform = 'windows'
else:
raise ValueError('Could not detect platform automatically, please specify with platform=<platform>')
opts = Variables([], ARGUMENTS)
opts.Add(EnumVariable('platform', 'Target platform', host_platform,
allowed_values=('linux', 'osx', 'windows'),
ignorecase=2))
opts.Add(EnumVariable('bits', 'Target platform bits', 'default', ('default', '32', '64')))
opts.Add(BoolVariable('use_llvm', 'Use the LLVM compiler - only effective when targeting Linux', False))
opts.Add(BoolVariable('use_mingw', 'Use the MinGW compiler - only effective on Windows', False))
# Must be the same setting as used for cpp_bindings
opts.Add(EnumVariable('target', 'Compilation target', 'debug',
allowed_values=('debug', 'release'),
ignorecase=2))
opts.Add(PathVariable('headers_dir', 'Path to the directory containing Godot headers', 'godot_headers', PathVariable.PathIsDir))
opts.Add(BoolVariable('use_custom_api_file', 'Use a custom JSON API file', False))
opts.Add(PathVariable('custom_api_file', 'Path to the custom JSON API file', None, PathVariable.PathIsFile))
opts.Add(BoolVariable('generate_bindings', 'Generate GDNative API bindings', False))
unknown = opts.UnknownVariables()
if unknown:
print("Unknown variables:" + unknown.keys())
Exit(1)
env = Environment()
opts.Update(env)
Help(opts.GenerateHelpText(env))
host_platform = platform.system()
target_platform = ARGUMENTS.get('p', ARGUMENTS.get('platform', 'linux'))
target_arch = ARGUMENTS.get('a', ARGUMENTS.get('arch', '64'))
# default to debug build, must be same setting as used for cpp_bindings
target = ARGUMENTS.get('target', 'debug')
# Local dependency paths, adapt them to your setup
godot_headers = ARGUMENTS.get('headers', 'godot_headers')
result_path = 'bin'
result_name = ARGUMENTS.get('n', ARGUMENTS.get('name', os.path.relpath('.', '..')))
# This makes sure to keep the session environment variables on Windows
# This way, you can run SCons in a Visual Studio 2017 prompt and it will find all the required tools
if env['platform'] == 'windows':
if env['bits'] == '64':
env = Environment(TARGET_ARCH='amd64')
elif env['bits'] == '32':
env = Environment(TARGET_ARCH='x86')
else:
print("Warning: bits argument not specified, target arch is=" + env['TARGET_ARCH'])
opts.Update(env)
is64 = False
if (env['platform'] == 'osx' or env['TARGET_ARCH'] == 'amd64' or env['TARGET_ARCH'] == 'emt64' or env['TARGET_ARCH'] == 'x86_64'):
is64 = True
if env['bits'] == 'default':
env['bits'] = '64' if is64 else '32'
if target_platform == 'linux' or platform == "x11":
result_name += '.linux.' + target_arch
if env['platform'] == 'linux':
if env['use_llvm']:
env['CXX']='g++'
if ARGUMENTS.get('use_llvm', 'no') == 'yes':
env['CXX'] = 'clang++'
env.Append(CCFLAGS=['-fPIC', '-g', '-std=c++14', '-Wwrite-strings'])
env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
env.Append(CCFLAGS = [ '-fPIC', '-g', '-Og', '-std=c++14', '-Wwrite-strings' ])
env.Append(LINKFLAGS = [ '-Wl,-R,\'$$ORIGIN\'' ])
if env['target'] == 'debug':
if target == 'debug':
env.Append(CCFLAGS = ['-Og'])
elif env['target'] == 'release':
else:
env.Append(CCFLAGS = ['-O3'])
if env['bits'] == '64':
env.Append(CCFLAGS=['-m64'])
env.Append(LINKFLAGS=['-m64'])
elif env['bits'] == '32':
if target_arch == '32':
env.Append(CCFLAGS = [ '-m32' ])
env.Append(LINKFLAGS = [ '-m32' ])
elif target_arch == '64':
env.Append(CCFLAGS = [ '-m64' ])
env.Append(LINKFLAGS = [ '-m64' ])
elif env['platform'] == 'osx':
if env['bits'] == '32':
raise ValueError('Only 64-bit builds are supported for the macOS target.')
elif target_platform == '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
if (target_arch == '64'):
env = Environment(ENV = os.environ, TARGET_ARCH='amd64')
else:
env = Environment(ENV = os.environ, TARGET_ARCH='x86')
env.Append(CCFLAGS=['-g', '-std=c++14', '-arch', 'x86_64'])
env.Append(LINKFLAGS=['-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup'])
result_name += '.windows.' + target_arch
if env['target'] == 'debug':
env.Append(CCFLAGS=['-Og'])
elif env['target'] == 'release':
env.Append(CCFLAGS=['-O3'])
if host_platform == 'Windows':
result_name += '.lib'
elif env['platform'] == 'windows':
if host_platform == 'windows' and not env['use_mingw']:
# MSVC
env.Append(LINKFLAGS = [ '/WX' ])
if env['target'] == 'debug':
if target == 'debug':
env.Append(CCFLAGS = ['/EHsc', '/D_DEBUG', '/MDd' ])
elif env['target'] == 'release':
else:
env.Append(CCFLAGS = ['/O2', '/EHsc', '/DNDEBUG', '/MD' ])
else:
# MinGW
if env['bits'] == '64':
env['CXX'] = 'x86_64-w64-mingw32-g++'
elif env['bits'] == '32':
if target_arch == '32':
env['CXX']='i686-w64-mingw32-g++'
elif target_arch == '64':
env['CXX']='x86_64-w64-mingw32-g++'
env.Append(CCFLAGS = [ '-g', '-O3', '-std=c++14', '-Wwrite-strings' ])
env.Append(LINKFLAGS = [ '--static', '-Wl,--no-undefined', '-static-libgcc', '-static-libstdc++' ])
elif target_platform == 'osx':
if ARGUMENTS.get('use_llvm', 'no') == 'yes':
env['CXX'] = 'clang++'
env.Append(CPPPATH=['.', env['headers_dir'], 'include', 'include/gen', 'include/core'])
# Only 64-bits is supported for OS X
target_arch = '64'
result_name += '.osx.' + target_arch
env.Append(CCFLAGS = [ '-g','-O3', '-std=c++14', '-arch', 'x86_64' ])
env.Append(LINKFLAGS = [ '-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup' ])
else:
print("The only supported targets are 'osx', 'linux' and 'windows'.")
sys.exit(255)
env.Append(CPPPATH=['.', godot_headers, 'include', 'include/gen', 'include/core'])
# Generate bindings?
json_api_file = ''
if env['use_custom_api_file']:
json_api_file = env['custom_api_file']
# Generate bindings?
json_api_file = ''
if ARGUMENTS.get('use_custom_api_file', 'no') == 'yes':
json_api_file = ARGUMENTS.get('custom_api_file', '')
else:
json_api_file = os.path.join(os.getcwd(), 'godot_headers', 'api.json')
if env['generate_bindings']:
# Actually create the bindings here
if ARGUMENTS.get('generate_bindings', 'no') == 'yes':
# actually create the bindings here
import binding_generator
binding_generator.generate_bindings(json_api_file)
# source to compile
sources = []
add_sources(sources, 'src/core', 'cpp')
add_sources(sources, 'src/gen', 'cpp')
library = env.StaticLibrary(
target='bin/' + 'libgodot-cpp.{}.{}.{}'.format(env['platform'], env['target'], env['bits']), source=sources
)
library = env.StaticLibrary(target=result_path + '/' + result_name, source=sources)
Default(library)

View File

@@ -155,7 +155,7 @@ def generate_class_header(used_classes, c):
# ___get_class_name
source.append("\tstatic inline const char *___get_class_name() { return (const char *) \"" + strip_name(c["name"]) + "\"; }")
source.append("\tstatic inline Object *___get_from_variant(Variant a) { godot_object *o = (godot_object*) a; return (o) ? (Object *) godot::nativescript_1_1_api->godot_nativescript_get_instance_binding_data(godot::_RegisterState::language_index, o) : nullptr; }")
source.append("\tstatic inline Object *___get_from_variant(Variant a) { godot_object *o = (godot_object*) a; return (Object *) godot::nativescript_1_1_api->godot_nativescript_get_instance_binding_data(godot::_RegisterState::language_index, o); }")
enum_values = []
@@ -541,8 +541,6 @@ def generate_icall_header(icalls):
if is_core_type(arg):
method_signature += arg + "&"
elif arg == "int":
method_signature += "int64_t "
elif arg == "float":
method_signature += "double "
elif is_primitive(arg):
@@ -596,8 +594,6 @@ def generate_icall_implementation(icalls):
if is_core_type(arg):
method_signature += arg + "& "
elif arg == "int":
method_signature += "int64_t "
elif arg == "float":
method_signature += "double "
elif is_primitive(arg):
@@ -625,7 +621,7 @@ def generate_icall_implementation(icalls):
if is_primitive(arg) or is_core_type(arg):
wrapped_argument += "(void *) &arg" + str(i)
else:
wrapped_argument += "(void *) (arg" + str(i) + ") ? arg" + str(i) + "->_owner : nullptr"
wrapped_argument += "(void *) arg" + str(i) + "->_owner"
wrapped_argument += ","
source.append(wrapped_argument)
@@ -684,7 +680,7 @@ def generate_type_registry(classes):
if base_class_name == "":
base_class_type_hash = "0"
source.append("\tgodot::_TagDB::register_global_type(\"" + c["name"] + "\", " + class_type_hash + ", " + base_class_type_hash + ");")
source.append("\tgodot::_TagDB::register_global_type(\"" + class_name + "\", " + class_type_hash + ", " + base_class_type_hash + ");")
source.append("}")
@@ -824,8 +820,7 @@ def escape_cpp(name):
"export": "_export",
"template": "_template",
"new": "new_",
"operator": "_operator",
"typename": "_typename"
"operator": "_operator"
}
if name in escapes:
return escapes[name]

140717
godot_api.json Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -30,6 +30,7 @@ public:
inline const Vector3& get_size() const { return size; }
inline void set_size(const Vector3& p_size) { size=p_size; }
bool operator==(const AABB& p_rval) const;
bool operator!=(const AABB& p_rval) const;
@@ -50,6 +51,7 @@ public:
bool has_point(const Vector3& p_point) const;
Vector3 get_support(const Vector3& p_normal) const;
Vector3 get_longest_axis() const;
int get_longest_axis_index() const;
real_t get_longest_axis_size() const;
@@ -71,12 +73,11 @@ public:
operator String() const;
inline AABB() {}
inline AABB(const Vector3 &p_pos, const Vector3 &p_size) {
position = p_pos;
size = p_size;
}
inline AABB(const Vector3 &p_pos,const Vector3& p_size) { position=p_pos; size=p_size; }
};
} // namespace godot
}
#endif // RECT3_H

View File

@@ -21,7 +21,6 @@ class Object;
class Array {
godot_array _godot_array;
public:
Array();
Array(const Array & other);
@@ -99,8 +98,9 @@ public:
void sort_custom(Object *obj, const String& func);
~Array();
};
} // namespace godot
}
#endif // ARRAY_H

View File

@@ -26,6 +26,10 @@ public:
Basis();
const Vector3& operator[](int axis) const;
Vector3& operator[](int axis);
@@ -33,6 +37,7 @@ public:
bool isequal_approx(const Basis& a, const Basis& b) const;
bool is_orthogonal() const;
bool is_rotation() const;
@@ -83,6 +88,7 @@ public:
Basis operator*(const Basis& p_matrix) const;
void operator+=(const Basis& p_matrix);
Basis operator+(const Basis& p_matrix) const;
@@ -99,12 +105,14 @@ public:
void set_orthogonal_index(int p_index); // down below
operator String() const;
void get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const;
/* create / set */
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz);
Vector3 get_column(int i) const;
@@ -125,8 +133,10 @@ public:
Basis diagonalize();
operator Quat() const;
};
} // namespace godot
}
#endif // BASIS_H

View File

@@ -9,11 +9,14 @@
namespace godot {
struct Color {
private:
// static float _parse_col(const String& p_str, int p_ofs);
public:
union {
struct {
@@ -79,23 +82,15 @@ public:
* No construct parameters, r=0, g=0, b=0. a=255
*/
inline Color() {
r = 0;
g = 0;
b = 0;
a = 1.0;
r=0; g=0; b=0; a=1.0;
}
/**
* RGB / RGBA construct parameters. Alpha is optional, but defaults to 1.0
*/
inline Color(float p_r, float p_g, float p_b, float p_a = 1.0) {
r = p_r;
g = p_g;
b = p_b;
a = p_a;
}
inline Color(float p_r,float p_g,float p_b,float p_a=1.0) { r=p_r; g=p_g; b=p_b; a=p_a; }
};
} // namespace godot
}
#endif // COLOR_H

View File

@@ -12,8 +12,8 @@
#include "Plane.hpp"
#include "PoolArrays.hpp"
#include "Quat.hpp"
#include "RID.hpp"
#include "Rect2.hpp"
#include "RID.hpp"
#include "String.hpp"
#include "Transform.hpp"
#include "Transform2D.hpp"
@@ -23,4 +23,5 @@
#include "Wrapped.hpp"
#endif // CORETYPES_H

View File

@@ -1,6 +1,7 @@
#ifndef DEFS_H
#define DEFS_H
namespace godot {
enum class Error {
@@ -91,9 +92,9 @@ template <typename KV>
KV add_all (KV kv) {
return kv;
}
} // namespace helpers
}
} // namespace godot
}
#include <stdio.h>
@@ -108,9 +109,7 @@ typedef float real_t;
// ERR/WARN macros
#ifndef WARN_PRINT
#define WARN_PRINT(msg) \
fprintf(stdout, "ERROR: %s\n", msg); \
fflush(stdout)
#define WARN_PRINT(msg) fprintf(stdout, "ERROR: %s\n", msg); fflush(stdout)
#endif
#ifndef WARN_PRINTS
@@ -130,51 +129,24 @@ typedef float real_t;
#endif
#ifndef ERR_FAIL_V
#define ERR_FAIL_V(a) \
{ \
ERR_FAIL(); \
return a; \
}
#define ERR_FAIL_V(a) { ERR_FAIL(); return a; }
#endif
#ifndef ERR_FAIL_COND
#define ERR_FAIL_COND(a) \
do { \
if (a) { \
ERR_PRINT(#a); \
return; \
} \
} while (0)
#define ERR_FAIL_COND(a) do { if (a) { ERR_PRINT(#a); return; } } while(0)
#endif
#ifndef ERR_FAIL_COND_V
#define ERR_FAIL_COND_V(cond, ret) \
do { \
if (cond) { \
ERR_PRINT(#cond); \
return ret; \
} \
} while (0)
#define ERR_FAIL_COND_V(cond, ret) do { if (cond) { ERR_PRINT(#cond); return ret; } } while(0)
#endif
#ifndef ERR_FAIL_INDEX
#define ERR_FAIL_INDEX(a, b) \
do { \
if (a < 0 || a >= b) { \
ERR_FAIL(); \
return; \
} \
} while (0)
#define ERR_FAIL_INDEX(a, b) do { if (a < 0 || a >= b) { ERR_FAIL(); return; } } while(0)
#endif
#ifndef ERR_FAIL_INDEX_V
#define ERR_FAIL_INDEX_V(a, b, c) \
do { \
if (a < 0 || a >= b) { \
ERR_FAIL(); \
return c; \
} \
} while (0)
#define ERR_FAIL_INDEX_V(a, b, c) do { if (a < 0 || a >= b) { ERR_FAIL(); return c; } } while(0)
#endif
#endif // DEFS_H

View File

@@ -11,7 +11,6 @@ namespace godot {
class Dictionary {
godot_dictionary _godot_dictionary;
public:
Dictionary();
Dictionary(const Dictionary & other);
@@ -47,8 +46,9 @@ public:
Array values() const;
~Dictionary();
};
} // namespace godot
}
#endif // DICTIONARY_H

View File

@@ -9,94 +9,82 @@
#include <typeinfo>
#include "CoreTypes.hpp"
#include "Variant.hpp"
#include "Ref.hpp"
#include "TagDB.hpp"
#include "Variant.hpp"
#include "Object.hpp"
#include "GodotGlobal.hpp"
#include <GDNativeLibrary.hpp>
#include <NativeScript.hpp>
#include <GDNativeLibrary.hpp>
namespace godot {
template<class T>
T *as(const Object *obj) {
return (obj) ? (T *)godot::nativescript_api->godot_nativescript_get_userdata(obj->_owner) : nullptr;
T *as(const Object *obj)
{
return (T *) godot::nativescript_api->godot_nativescript_get_userdata(obj->_owner);
}
template<class T>
T *get_wrapper(godot_object *obj) {
T *get_wrapper(godot_object *obj)
{
return (T *) godot::nativescript_1_1_api->godot_nativescript_get_instance_binding_data(godot::_RegisterState::language_index, obj);
}
#define GODOT_CLASS(Name, Base) \
\
public: \
inline static const char *___get_type_name() { return static_cast<const char *>(#Name); } \
enum { ___CLASS_IS_SCRIPT = 1, \
}; \
inline static Name *_new() { \
godot::NativeScript *script = godot::NativeScript::_new(); \
script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib)); \
script->set_class_name(#Name); \
Name *instance = godot::as<Name>(script->new_()); \
return instance; \
} \
inline static size_t ___get_id() { return typeid(Name).hash_code(); }; \
inline static size_t ___get_base_id() { return typeid(Base).hash_code(); }; \
public: inline static const char *___get_type_name() { return static_cast<const char *>(#Name); } \
enum { ___CLASS_IS_SCRIPT = 1, }; \
inline static Name *_new() { godot::NativeScript *script = godot::NativeScript::_new(); script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *) godot::gdnlib)); script->set_class_name(#Name); Name *instance = godot::as<Name>(script->new_()); return instance; } \
inline static const char *___get_base_type_name() { return Base::___get_class_name(); } \
inline static Object *___get_from_variant(godot::Variant a) { return (godot::Object *) godot::as<Name>(godot::Object::___get_from_variant(a)); } \
\
private:
#define GODOT_SUBCLASS(Name, Base) \
\
public: \
inline static const char *___get_type_name() { return static_cast<const char *>(#Name); } \
enum { ___CLASS_IS_SCRIPT = 1, \
}; \
inline static Name *_new() { \
godot::NativeScript *script = godot::NativeScript::_new(); \
script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib)); \
script->set_class_name(#Name); \
Name *instance = godot::as<Name>(script->new_()); \
return instance; \
} \
inline static size_t ___get_id() { return typeid(Name).hash_code(); }; \
inline static size_t ___get_base_id() { return typeid(Base).hash_code(); }; \
public: inline static const char *___get_type_name() { return static_cast<const char *>(#Name); } \
enum { ___CLASS_IS_SCRIPT = 1, }; \
inline static Name *_new() { godot::NativeScript *script = godot::NativeScript::_new(); script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *) godot::gdnlib)); script->set_class_name(#Name); Name *instance = godot::as<Name>(script->new_()); return instance; } \
inline static const char *___get_base_type_name() { return #Base; } \
inline static Object *___get_from_variant(godot::Variant a) { return (godot::Object *) godot::as<Name>(godot::Object::___get_from_variant(a)); } \
\
private:
template<class T>
struct _ArgCast {
static T _arg_cast(Variant a) {
static T _arg_cast(Variant a)
{
return a;
}
};
template<class T>
struct _ArgCast<T*> {
static T *_arg_cast(Variant a) {
static T *_arg_cast(Variant a)
{
return (T *) T::___get_from_variant(a);
}
};
template<>
struct _ArgCast<Variant> {
static Variant _arg_cast(Variant a) {
static Variant _arg_cast(Variant a)
{
return a;
}
};
// instance and destroy funcs
template<class T>
void *_godot_class_instance_func(godot_object *p, void *method_data) {
void *_godot_class_instance_func(godot_object *p, void *method_data)
{
T *d = new T();
d->_owner = p;
d->_type_tag = typeid(T).hash_code();
@@ -105,20 +93,23 @@ void *_godot_class_instance_func(godot_object *p, void *method_data) {
}
template<class T>
void _godot_class_destroy_func(godot_object *p, void *method_data, void *data) {
void _godot_class_destroy_func(godot_object *p, void *method_data, void *data)
{
T *d = (T *) data;
delete d;
}
template<class T>
void register_class() {
void register_class()
{
godot_instance_create_func create = {};
create.create_func = _godot_class_instance_func<T>;
godot_instance_destroy_func destroy = {};
destroy.destroy_func = _godot_class_destroy_func<T>;
_TagDB::register_type(T::___get_id(), T::___get_base_id());
_TagDB::register_type(typeid(T).hash_code(), typeid(T).hash_code());
godot::nativescript_api->godot_nativescript_register_class(godot::_RegisterState::nativescript_handle, T::___get_type_name(), T::___get_base_type_name(), create, destroy);
godot::nativescript_1_1_api->godot_nativescript_set_type_tag(godot::_RegisterState::nativescript_handle, T::___get_type_name(), (const void *) typeid(T).hash_code());
@@ -126,37 +117,59 @@ void register_class() {
}
template<class T>
void register_tool_class() {
void register_tool_class()
{
godot_instance_create_func create = {};
create.create_func = _godot_class_instance_func<T>;
godot_instance_destroy_func destroy = {};
destroy.destroy_func = _godot_class_destroy_func<T>;
_TagDB::register_type(T::___get_id(), T::___get_base_id());
_TagDB::register_type(typeid(T).hash_code(), typeid(T).hash_code());
godot::nativescript_api->godot_nativescript_register_tool_class(godot::_RegisterState::nativescript_handle, T::___get_type_name(), T::___get_base_type_name(), create, destroy);
godot::nativescript_1_1_api->godot_nativescript_set_type_tag(godot::_RegisterState::nativescript_handle, T::___get_type_name(), (const void *) typeid(T).hash_code());
T::_register_methods();
}
// method registering
typedef godot_variant (*__godot_wrapper_method)(godot_object *, void *, void *, int, godot_variant **);
template<class T, class R, class ...args>
const char *___get_method_class_name(R (T::*p)(args... a)) {
const char *___get_method_class_name(R (T::*p)(args... a))
{
return T::___get_type_name();
}
template<class T, class R, class ...args>
const char *___get_method_class_name(R (T::*p)(args... a) const) {
const char *___get_method_class_name(R (T::*p)(args... a) const)
{
return T::___get_type_name();
}
// Okay, time for some template magic.
// Many thanks to manpat from the GDL Discord Server.
// This is stuff that's available in C++14 I think, but whatever.
template<int... I>
@@ -172,11 +185,11 @@ struct __construct_sequence<0, I...> {
using type = __Sequence<I...>;
};
// Now the wrapping part.
template<class T, class R, class... As>
struct _WrappedMethod {
R(T::*f)
(As...);
R (T::*f)(As...);
template<int... I>
void apply(Variant* ret, T* obj, Variant** args, __Sequence<I...>) {
@@ -194,8 +207,10 @@ struct _WrappedMethod<T, void, As...> {
}
};
template<class T, class R, class... As>
godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args) {
godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args)
{
godot_variant v;
godot::api->godot_variant_new_nil(&v);
@@ -211,7 +226,8 @@ godot_variant __wrapped_method(godot_object *, void *method_data, void *user_dat
}
template<class T, class R, class... As>
void *___make_wrapper_function(R (T::*f)(As...)) {
void *___make_wrapper_function(R (T::*f)(As...))
{
using MethodType = _WrappedMethod<T, R, As...>;
MethodType *p = (MethodType *) godot::api->godot_alloc(sizeof(MethodType));
p->f = f;
@@ -219,37 +235,62 @@ void *___make_wrapper_function(R (T::*f)(As...)) {
}
template<class T, class R, class... As>
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(As...)) {
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(As...))
{
return (__godot_wrapper_method) &__wrapped_method<T, R, As...>;
}
template<class T, class R, class ...A>
void *___make_wrapper_function(R (T::*f)(A...) const) {
void *___make_wrapper_function(R (T::*f)(A...) const)
{
return ___make_wrapper_function((R (T::*)(A...)) f);
}
template<class T, class R, class ...A>
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(A...) const) {
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(A...) const)
{
return ___get_wrapper_function((R (T::*)(A...)) f);
}
template<class M>
void register_method(const char *name, M method_ptr, godot_method_rpc_mode rpc_type = GODOT_METHOD_RPC_MODE_DISABLED) {
void register_method(const char *name, M method_ptr, godot_method_rpc_mode rpc_type = GODOT_METHOD_RPC_MODE_DISABLED)
{
godot_instance_method method = {};
method.method_data = ___make_wrapper_function(method_ptr);
method.free_func = godot::api->godot_free;
method.method = (__godot_wrapper_method) ___get_wrapper_function(method_ptr);
godot_method_attributes attr = {};
attr.rpc_type = rpc_type;
godot::nativescript_api->godot_nativescript_register_method(godot::_RegisterState::nativescript_handle, ___get_method_class_name(method_ptr), name, attr, method);
}
template<class T, class P>
struct _PropertySetFunc {
void (T::*f)(P);
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value) {
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value)
{
_PropertySetFunc<T, P> *set_func = (_PropertySetFunc<T, P> *) method_data;
T *obj = (T *) user_data;
@@ -261,9 +302,9 @@ struct _PropertySetFunc {
template<class T, class P>
struct _PropertyGetFunc {
P(T::*f)
();
static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data) {
P (T::*f)();
static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data)
{
_PropertyGetFunc<T, P> *get_func = (_PropertyGetFunc<T, P> *) method_data;
T *obj = (T *) user_data;
@@ -278,10 +319,16 @@ struct _PropertyGetFunc {
}
};
template<class T, class P>
struct _PropertyDefaultSetFunc {
P (T::*f);
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value) {
static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value)
{
_PropertyDefaultSetFunc<T, P> *set_func = (_PropertyDefaultSetFunc<T, P> *) method_data;
T *obj = (T *) user_data;
@@ -294,7 +341,8 @@ struct _PropertyDefaultSetFunc {
template<class T, class P>
struct _PropertyDefaultGetFunc {
P (T::*f);
static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data) {
static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data)
{
_PropertyDefaultGetFunc<T, P> *get_func = (_PropertyDefaultGetFunc<T, P> *) method_data;
T *obj = (T *) user_data;
@@ -309,8 +357,10 @@ struct _PropertyDefaultGetFunc {
}
};
template<class T, class P>
void register_property(const char *name, P(T::*var), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
void register_property(const char *name, P (T::*var), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "")
{
Variant def_val = default_value;
usage = (godot_property_usage_flags) ((int) usage | GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE);
@@ -352,8 +402,12 @@ void register_property(const char *name, P(T::*var), P default_value, godot_meth
godot::nativescript_api->godot_nativescript_register_property(godot::_RegisterState::nativescript_handle, T::___get_type_name(), name, &attr, set_func, get_func);
}
template<class T, class P>
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "")
{
Variant def_val = default_value;
godot_property_attributes attr = {};
@@ -380,15 +434,18 @@ void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(),
get_func.get_func = &_PropertyGetFunc<T, P>::_wrapped_getter;
godot::nativescript_api->godot_nativescript_register_property(godot::_RegisterState::nativescript_handle, T::___get_type_name(), name, &attr, set_func, get_func);
}
template<class T, class P>
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)() const, P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)() const, P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "")
{
register_property(name, setter, (P (T::*)()) getter, default_value, rpc_mode, usage, hint, hint_string);
}
template<class T>
void register_signal(String name, Dictionary args = Dictionary()) {
void register_signal(String name, Dictionary args = Dictionary())
{
godot_signal signal = {};
signal.name = *(godot_string *)&name;
signal.num_args = args.size();
@@ -425,16 +482,19 @@ void register_signal(String name, Dictionary args = Dictionary()) {
}
template<class T, class... Args>
void register_signal(String name, Args... varargs) {
void register_signal(String name, Args... varargs)
{
register_signal<T>(name, Dictionary::make(varargs...));
}
#ifndef GODOT_CPP_NO_OBJECT_CAST
template<class T>
T *Object::cast_to(const Object *obj) {
if (!obj)
return nullptr;
T *Object::cast_to(const Object *obj)
{
size_t have_tag = (size_t) godot::nativescript_1_1_api->godot_nativescript_get_type_tag(obj->_owner);
if (have_tag) {
@@ -455,6 +515,7 @@ T *Object::cast_to(const Object *obj) {
}
#endif
} // namespace godot
}
#endif // GODOT_H

View File

@@ -1,9 +1,9 @@
#ifndef GODOT_GLOBAL_HPP
#define GODOT_GLOBAL_HPP
#include "Array.hpp"
#include "String.hpp"
#include <gdnative_api_struct.gen.h>
#include "String.hpp"
#include "Array.hpp"
namespace godot {
@@ -25,19 +25,19 @@ public:
static void nativescript_init(void *handle);
static void nativescript_terminate(void *handle);
static void gdnative_profiling_add_data(const char *p_signature, uint64_t p_time);
template <class... Args>
static void print(const String& fmt, Args... values) {
print(fmt.format(Array::make(values...)));
}
};
struct _RegisterState {
static void *nativescript_handle;
static int language_index;
};
} // namespace godot
}
#endif

View File

@@ -1,34 +0,0 @@
#ifndef GODOT_PROFILING_HPP
#define GODOT_PROFILING_HPP
#include "OS.hpp"
namespace godot {
class FunctionProfiling {
char signature[1024];
uint64_t ticks;
public:
FunctionProfiling(const char *p_function, const int p_line) {
snprintf(signature, 1024, "::%d::%s", p_line, p_function);
ticks = OS::get_singleton()->get_ticks_usec();
}
~FunctionProfiling() {
uint64_t t = OS::get_singleton()->get_ticks_usec() - ticks;
if (t > 0) {
Godot::gdnative_profiling_add_data(signature, t);
}
}
};
}
#ifdef DEBUG_ENABLED
#define GODOT_PROFILING_FUNCTION FunctionProfiling __function_profiling(__FUNCTION__, __LINE__);
#else
#define GODOT_PROFILING_FUNCTION
#endif
#endif

View File

@@ -7,9 +7,10 @@
namespace godot {
class NodePath {
godot_node_path _node_path;
class NodePath
{
godot_node_path _node_path;
public:
NodePath();
@@ -40,6 +41,8 @@ public:
~NodePath();
};
} // namespace godot
}
#endif // NODEPATH_H

View File

@@ -5,8 +5,10 @@
#include <cmath>
namespace godot {
enum ClockDirection {
CLOCKWISE,
@@ -54,15 +56,14 @@ public:
operator String() const;
inline Plane() { d=0; }
inline Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d) :
normal(p_a, p_b, p_c),
d(p_d) {}
inline Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d) : normal(p_a,p_b,p_c), d(p_d) { }
Plane(const Vector3 &p_normal, real_t p_d);
Plane(const Vector3 &p_point, const Vector3& p_normal);
Plane(const Vector3 &p_point1, const Vector3 &p_point2,const Vector3 &p_point3,ClockDirection p_dir = CLOCKWISE);
};
} // namespace godot
}
#endif // PLANE_H

View File

@@ -3,11 +3,11 @@
#include "Defs.hpp"
#include "Color.hpp"
#include "GodotGlobal.hpp"
#include "String.hpp"
#include "Color.hpp"
#include "Vector2.hpp"
#include "Vector3.hpp"
#include "GodotGlobal.hpp"
#include <gdnative/pool_arrays.h>
@@ -17,13 +17,12 @@ class Array;
class PoolByteArray {
godot_pool_byte_array _godot_array;
public:
class Read {
friend class PoolByteArray;
godot_pool_byte_array_read_access *_read_access;
public:
inline Read() {
_read_access = nullptr;
@@ -53,7 +52,6 @@ public:
class Write {
friend class PoolByteArray;
godot_pool_byte_array_write_access *_write_access;
public:
inline Write() {
_write_access = nullptr;
@@ -113,14 +111,14 @@ public:
~PoolByteArray();
};
class PoolIntArray {
godot_pool_int_array _godot_array;
public:
class Read {
friend class PoolIntArray;
godot_pool_int_array_read_access *_read_access;
public:
inline Read() {
_read_access = nullptr;
@@ -150,7 +148,6 @@ public:
class Write {
friend class PoolIntArray;
godot_pool_int_array_write_access *_write_access;
public:
inline Write() {
_write_access = nullptr;
@@ -210,14 +207,14 @@ public:
~PoolIntArray();
};
class PoolRealArray {
godot_pool_real_array _godot_array;
public:
class Read {
friend class PoolRealArray;
godot_pool_real_array_read_access *_read_access;
public:
inline Read() {
_read_access = nullptr;
@@ -247,7 +244,6 @@ public:
class Write {
friend class PoolRealArray;
godot_pool_real_array_write_access *_write_access;
public:
inline Write() {
_write_access = nullptr;
@@ -307,14 +303,14 @@ public:
~PoolRealArray();
};
class PoolStringArray {
godot_pool_string_array _godot_array;
public:
class Read {
friend class PoolStringArray;
godot_pool_string_array_read_access *_read_access;
public:
inline Read() {
_read_access = nullptr;
@@ -344,7 +340,6 @@ public:
class Write {
friend class PoolStringArray;
godot_pool_string_array_write_access *_write_access;
public:
inline Write() {
_write_access = nullptr;
@@ -404,14 +399,15 @@ public:
~PoolStringArray();
};
class PoolVector2Array {
godot_pool_vector2_array _godot_array;
public:
class Read {
friend class PoolVector2Array;
godot_pool_vector2_array_read_access *_read_access;
public:
inline Read() {
_read_access = nullptr;
@@ -441,7 +437,6 @@ public:
class Write {
friend class PoolVector2Array;
godot_pool_vector2_array_write_access *_write_access;
public:
inline Write() {
_write_access = nullptr;
@@ -501,14 +496,14 @@ public:
~PoolVector2Array();
};
class PoolVector3Array {
godot_pool_vector3_array _godot_array;
public:
class Read {
friend class PoolVector3Array;
godot_pool_vector3_array_read_access *_read_access;
public:
inline Read() {
_read_access = nullptr;
@@ -538,7 +533,6 @@ public:
class Write {
friend class PoolVector3Array;
godot_pool_vector3_array_write_access *_write_access;
public:
inline Write() {
_write_access = nullptr;
@@ -598,14 +592,14 @@ public:
~PoolVector3Array();
};
class PoolColorArray {
godot_pool_color_array _godot_array;
public:
class Read {
friend class PoolColorArray;
godot_pool_color_array_read_access *_read_access;
public:
inline Read() {
_read_access = nullptr;
@@ -635,7 +629,6 @@ public:
class Write {
friend class PoolColorArray;
godot_pool_color_array_write_access *_write_access;
public:
inline Write() {
_write_access = nullptr;
@@ -695,6 +688,9 @@ public:
~PoolColorArray();
};
} // namespace godot
}
#endif // POOLARRAYS_H

View File

@@ -11,6 +11,7 @@ namespace godot {
class Quat{
public:
real_t x,y,z,w;
real_t length_squared() const;
@@ -43,10 +44,13 @@ public:
void operator*=(const Quat& q);
Quat operator*(const Quat& q) const;
Quat operator*(const Vector3& v) const;
Vector3 xform(const Vector3& v) const;
void operator+=(const Quat& q);
void operator-=(const Quat& q);
void operator*=(const real_t& s);
@@ -57,33 +61,27 @@ public:
Quat operator*(const real_t& s) const;
Quat operator/(const real_t& s) const;
bool operator==(const Quat& p_quat) const;
bool operator!=(const Quat& p_quat) const;
operator String() const;
inline void set( real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
x = p_x;
y = p_y;
z = p_z;
w = p_w;
x=p_x; y=p_y; z=p_z; w=p_w;
}
inline Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
x = p_x;
y = p_y;
z = p_z;
w = p_w;
x=p_x; y=p_y; z=p_z; w=p_w;
}
Quat(const Vector3& axis, const real_t& angle);
Quat(const Vector3& v0, const Vector3& v1) ;
inline Quat() {
x = y = z = 0;
w = 1;
}
inline Quat() {x=y=z=0; w=1; }
};
} // namespace godot
}
#endif // QUAT_H

View File

@@ -9,8 +9,8 @@ class Object;
class RID {
godot_rid _godot_rid;
public:
RID();
RID(Object *p);
@@ -28,8 +28,9 @@ public:
bool operator>(const RID & p_other) const;
bool operator<=(const RID & p_other) const;
bool operator>=(const RID & p_other) const;
};
} // namespace godot
}
#endif // RID_H

View File

@@ -18,24 +18,24 @@ struct Transform2D;
struct Rect2 {
Point2 position;
Point2 pos;
Size2 size;
inline const Vector2 &get_position() const { return position; }
inline void set_position(const Vector2 &p_position) { position = p_position; }
inline const Vector2& get_pos() const { return pos; }
inline void set_pos(const Vector2& p_pos) { pos=p_pos; }
inline const Vector2& get_size() const { return size; }
inline void set_size(const Vector2& p_size) { size=p_size; }
inline real_t get_area() const { return size.width*size.height; }
inline bool intersects(const Rect2& p_rect) const {
if (position.x >= (p_rect.position.x + p_rect.size.width))
if ( pos.x >= (p_rect.pos.x + p_rect.size.width) )
return false;
if ((position.x + size.width) <= p_rect.position.x)
if ( (pos.x+size.width) <= p_rect.pos.x )
return false;
if (position.y >= (p_rect.position.y + p_rect.size.height))
if ( pos.y >= (p_rect.pos.y + p_rect.size.height) )
return false;
if ((position.y + size.height) <= p_rect.position.y)
if ( (pos.y+size.height) <= p_rect.pos.y )
return false;
return true;
@@ -45,32 +45,34 @@ struct Rect2 {
bool intersects_transformed(const Transform2D& p_xform, const Rect2& p_rect) const;
bool intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_position = nullptr, Point2 *r_normal = nullptr) const;
bool intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos=nullptr, Point2* r_normal=nullptr) const;
inline bool encloses(const Rect2& p_rect) const {
return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) &&
((p_rect.position.x + p_rect.size.x) < (position.x + size.x)) &&
((p_rect.position.y + p_rect.size.y) < (position.y + size.y));
return (p_rect.pos.x>=pos.x) && (p_rect.pos.y>=pos.y) &&
((p_rect.pos.x+p_rect.size.x)<(pos.x+size.x)) &&
((p_rect.pos.y+p_rect.size.y)<(pos.y+size.y));
}
inline bool has_no_area() const {
return (size.x<=0 || size.y<=0);
}
Rect2 clip(const Rect2& p_rect) const;
Rect2 merge(const Rect2& p_rect) const;
inline bool has_point(const Point2& p_point) const {
if (p_point.x < position.x)
if (p_point.x < pos.x)
return false;
if (p_point.y < position.y)
if (p_point.y < pos.y)
return false;
if (p_point.x >= (position.x + size.x))
if (p_point.x >= (pos.x+size.x) )
return false;
if (p_point.y >= (position.y + size.y))
if (p_point.y >= (pos.y+size.y) )
return false;
return true;
@@ -78,14 +80,14 @@ struct Rect2 {
inline bool no_area() const { return (size.width<=0 || size.height<=0 ); }
inline bool operator==(const Rect2 &p_rect) const { return position == p_rect.position && size == p_rect.size; }
inline bool operator!=(const Rect2 &p_rect) const { return position != p_rect.position || size != p_rect.size; }
inline bool operator==(const Rect2& p_rect) const { return pos==p_rect.pos && size==p_rect.size; }
inline bool operator!=(const Rect2& p_rect) const { return pos!=p_rect.pos || size!=p_rect.size; }
inline Rect2 grow(real_t p_by) const {
Rect2 g=*this;
g.position.x -= p_by;
g.position.y -= p_by;
g.pos.x-=p_by;
g.pos.y-=p_by;
g.size.width+=p_by*2;
g.size.height+=p_by*2;
return g;
@@ -100,8 +102,8 @@ struct Rect2 {
inline void expand_to(const Vector2& p_vector) { //in place function for speed
Vector2 begin = position;
Vector2 end = position + size;
Vector2 begin=pos;
Vector2 end=pos+size;
if (p_vector.x<begin.x)
begin.x=p_vector.x;
@@ -113,23 +115,19 @@ struct Rect2 {
if (p_vector.y>end.y)
end.y=p_vector.y;
position = begin;
pos=begin;
size=end-begin;
}
operator String() const;
inline Rect2() {}
inline Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) {
position = Point2(p_x, p_y);
size = Size2(p_width, p_height);
}
inline Rect2(const Point2 &p_position, const Size2 &p_size) {
position = p_position;
size = p_size;
}
inline Rect2( real_t p_x, real_t p_y, real_t p_width, real_t p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); }
inline Rect2( const Point2& p_pos, const Size2& p_size ) { pos=p_pos; size=p_size; }
};
} // namespace godot
}
#endif // RECT2_H

View File

@@ -1,9 +1,9 @@
#ifndef REF_H
#define REF_H
#include "Variant.hpp"
#include "GodotGlobal.hpp"
#include "Reference.hpp"
#include "Variant.hpp"
namespace godot {
@@ -202,13 +202,14 @@ public:
// Used exclusively in the bindings to recreate the Ref Godot encapsulates in return values,
// without adding to the refcount.
inline static Ref<T> __internal_constructor(Object *obj) {
inline static Ref<T> __internal_constructor(Object *obj)
{
Ref<T> r;
r.reference = (T*)obj;
return r;
}
};
} // namespace godot
}
#endif

View File

@@ -68,6 +68,8 @@ public:
CharString utf8() const;
CharString ascii(bool p_extended = false) const;
int64_t find(String p_what) const;
int64_t find_from(String p_what, int64_t p_from) const;
bool begins_with(String &s) const;
bool begins_with_char_array(const char *p_char_array) const;
PoolStringArray bigrams() const;
@@ -129,14 +131,12 @@ public:
String to_upper() const;
String xml_escape() const;
String xml_unescape() const;
signed char casecmp_to(String p_str) const;
signed char nocasecmp_to(String p_str) const;
signed char naturalnocasecmp_to(String p_str) const;
};
String operator+(const char *a, const String &b);
String operator+(const wchar_t *a, const String &b);
} // namespace godot
}
#endif // STRING_H

View File

@@ -12,8 +12,8 @@ bool is_type_known(size_t type_tag);
void register_global_type(const char *name, size_t type_tag, size_t base_type_tag);
bool is_type_compatible(size_t type_tag, size_t base_type_tag);
} // namespace _TagDB
}
} // namespace godot
}
#endif // TAGDB_HPP

View File

@@ -3,13 +3,14 @@
#include "Basis.hpp"
#include "AABB.hpp"
#include "Plane.hpp"
#include "AABB.hpp"
namespace godot {
class Transform {
public:
Basis basis;
Vector3 origin;
@@ -72,8 +73,9 @@ public:
Transform(const Basis& p_basis, const Vector3& p_origin=Vector3());
inline Transform() {}
};
} // namespace godot
}
#endif // TRANSFORM_H

View File

@@ -3,6 +3,7 @@
#include "Vector2.hpp"
namespace godot {
typedef Vector2 Size2;
@@ -29,14 +30,8 @@ struct Transform2D {
inline const Vector2& operator[](int p_idx) const { return elements[p_idx]; }
inline Vector2& operator[](int p_idx) { return elements[p_idx]; }
inline Vector2 get_axis(int p_axis) const {
ERR_FAIL_INDEX_V(p_axis, 3, Vector2());
return elements[p_axis];
}
inline void set_axis(int p_axis, const Vector2 &p_vec) {
ERR_FAIL_INDEX(p_axis, 3);
elements[p_axis] = p_vec;
}
inline Vector2 get_axis(int p_axis) const { ERR_FAIL_INDEX_V(p_axis,3,Vector2()); return elements[p_axis]; }
inline void set_axis(int p_axis,const Vector2& p_vec) { ERR_FAIL_INDEX(p_axis,3); elements[p_axis]=p_vec; }
void invert();
Transform2D inverse() const;
@@ -91,12 +86,9 @@ struct Transform2D {
Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy);
Transform2D(real_t p_rot, const Vector2& p_pos);
inline Transform2D() {
elements[0][0] = 1.0;
elements[1][1] = 1.0;
}
inline Transform2D() { elements[0][0]=1.0; elements[1][1]=1.0; }
};
} // namespace godot
}
#endif // TRANSFORM2D_H

View File

@@ -12,8 +12,8 @@
#include "Plane.hpp"
#include "PoolArrays.hpp"
#include "Quat.hpp"
#include "RID.hpp"
#include "Rect2.hpp"
#include "RID.hpp"
#include "String.hpp"
#include "Transform.hpp"
#include "Transform2D.hpp"
@@ -30,7 +30,6 @@ class Array;
class Variant {
godot_variant _godot_variant;
public:
enum Type {
@@ -127,14 +126,11 @@ public:
Variant(signed short p_short);
inline Variant(unsigned short p_short) :
Variant((unsigned int)p_short) {}
inline Variant(unsigned short p_short) : Variant((unsigned int) p_short) {}
inline Variant(signed char p_char) :
Variant((signed int)p_char) {}
inline Variant(signed char p_char) : Variant((signed int) p_char) {}
inline Variant(unsigned char p_char) :
Variant((unsigned int)p_char) {}
inline Variant(unsigned char p_char) : Variant((unsigned int) p_char) {}
Variant(int64_t p_char);
Variant(uint64_t p_char);
@@ -157,6 +153,7 @@ public:
Variant(const Plane& p_plane);
Variant(const AABB& p_aabb);
Variant(const Quat& p_quat);
@@ -193,8 +190,10 @@ public:
Variant(const PoolColorArray& p_color_array);
Variant &operator =(const Variant& v);
operator bool() const;
operator signed int() const;
operator unsigned int() const ;
@@ -205,6 +204,7 @@ public:
operator int64_t() const;
operator uint64_t() const;
operator wchar_t() const;
operator float() const;
@@ -240,6 +240,7 @@ public:
Type get_type() const;
Variant call(const String& method, const Variant **args, const int arg_count);
bool has_method(const String& method);
@@ -261,8 +262,10 @@ public:
bool booleanize() const;
~Variant();
};
} // namespace godot
}
#endif // VARIANT_H

View File

@@ -20,6 +20,7 @@ struct Vector2 {
real_t height;
};
inline real_t& operator[](int p_idx) {
return p_idx?y:x;
}
@@ -58,6 +59,7 @@ struct Vector2 {
inline bool operator<(const Vector2& p_vec2) const { return (x==p_vec2.x)?(y<p_vec2.y):(x<p_vec2.x); }
inline bool operator<=(const Vector2& p_vec2) const { return (x==p_vec2.x)?(y<=p_vec2.y):(x<=p_vec2.x); }
void normalize();
Vector2 normalized() const;
@@ -87,6 +89,7 @@ struct Vector2 {
Vector2 linear_interpolate(const Vector2& p_b,real_t p_t) const;
Vector2 cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,real_t p_t) const;
Vector2 slide(const Vector2& p_vec) const;
Vector2 reflect(const Vector2& p_vec) const;
@@ -105,22 +108,21 @@ struct Vector2 {
Vector2 snapped(const Vector2& p_by) const;
inline real_t aspect() const { return width/height; }
operator String() const;
inline Vector2(real_t p_x, real_t p_y) {
x = p_x;
y = p_y;
}
inline Vector2() {
x = 0;
y = 0;
}
inline Vector2(real_t p_x,real_t p_y) { x=p_x; y=p_y; }
inline Vector2() { x=0; y=0; }
};
inline Vector2 operator*(real_t p_scalar, const Vector2 &p_vec) {
inline Vector2 operator*(real_t p_scalar, const Vector2& p_vec)
{
return p_vec*p_scalar;
}
} // namespace godot
}
#endif // VECTOR2_H

View File

@@ -51,6 +51,7 @@ struct Vector3 {
Vector3 operator/(const Vector3& p_v) const;
Vector3& operator*=(real_t p_scalar);
Vector3 operator*(real_t p_scalar) const;
@@ -101,6 +102,7 @@ struct Vector3 {
Basis outer(const Vector3& b) const;
int max_axis() const;
int min_axis() const;
@@ -124,7 +126,8 @@ struct Vector3 {
operator String() const;
};
inline Vector3 operator*(real_t p_scalar, const Vector3 &p_vec) {
inline Vector3 operator*(real_t p_scalar, const Vector3& p_vec)
{
return p_vec * p_scalar;
}
@@ -133,6 +136,6 @@ inline Vector3 vec3_cross(const Vector3 &p_a, const Vector3 &p_b) {
return p_a.cross(p_b);
}
} // namespace godot
}
#endif // VECTOR3_H

View File

@@ -11,6 +11,6 @@ public:
size_t _type_tag;
};
} // namespace godot
}
#endif // WRAPPED_HPP

View File

@@ -1,18 +0,0 @@
# Git hooks for Godot Engine
This folder contains git hooks meant to be installed locally by Godot Engine
contributors to make sure they comply with our requirements.
## List of hooks
- Pre-commit hook for clang-format: Applies clang-format to the staged files
before accepting a commit; blocks the commit and generates a patch if the
style is not respected.
Should work on Linux and macOS. You may need to edit the file if your
clang-format binary is not in the $PATH, or if you want to enable colored
output with pygmentize.
## Installation
Copy all the files from this folder into your .git/hooks folder, and make sure
the hooks and helper scripts are executable.

View File

@@ -1,48 +0,0 @@
#!/bin/sh
# Provide the canonicalize filename (physical filename with out any symlinks)
# like the GNU version readlink with the -f option regardless of the version of
# readlink (GNU or BSD).
# This file is part of a set of unofficial pre-commit hooks available
# at github.
# Link: https://github.com/githubbrowser/Pre-commit-hooks
# Contact: David Martin, david.martin.mailbox@googlemail.com
###########################################################
# There should be no need to change anything below this line.
# Canonicalize by recursively following every symlink in every component of the
# specified filename. This should reproduce the results of the GNU version of
# readlink with the -f option.
#
# Reference: http://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac
canonicalize_filename () {
local target_file="$1"
local physical_directory=""
local result=""
# Need to restore the working directory after work.
local working_dir="`pwd`"
cd -- "$(dirname -- "$target_file")"
target_file="$(basename -- "$target_file")"
# Iterate down a (possible) chain of symlinks
while [ -L "$target_file" ]
do
target_file="$(readlink -- "$target_file")"
cd -- "$(dirname -- "$target_file")"
target_file="$(basename -- "$target_file")"
done
# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
physical_directory="`pwd -P`"
result="$physical_directory/$target_file"
# restore the working directory after work.
cd -- "$working_dir"
echo "$result"
}

View File

@@ -1,50 +0,0 @@
#!/bin/sh
# Git pre-commit hook that runs multiple hooks specified in $HOOKS.
# Make sure this script is executable. Bypass hooks with git commit --no-verify.
# This file is part of a set of unofficial pre-commit hooks available
# at github.
# Link: https://github.com/githubbrowser/Pre-commit-hooks
# Contact: David Martin, david.martin.mailbox@googlemail.com
###########################################################
# CONFIGURATION:
# pre-commit hooks to be executed. They should be in the same .git/hooks/ folder
# as this script. Hooks should return 0 if successful and nonzero to cancel the
# commit. They are executed in the order in which they are listed.
#HOOKS="pre-commit-compile pre-commit-uncrustify"
HOOKS="pre-commit-clang-format"
###########################################################
# There should be no need to change anything below this line.
. "$(dirname -- "$0")/canonicalize_filename.sh"
# exit on error
set -e
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT="$(canonicalize_filename "$0")"
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH="$(dirname -- "$SCRIPT")"
for hook in $HOOKS
do
echo "Running hook: $hook"
# run hook if it exists
# if it returns with nonzero exit with 1 and thus abort the commit
if [ -f "$SCRIPTPATH/$hook" ]; then
"$SCRIPTPATH/$hook"
if [ $? != 0 ]; then
exit 1
fi
else
echo "Error: file $hook not found."
echo "Aborting commit. Make sure the hook is in $SCRIPTPATH and executable."
echo "You can disable it by removing it from the list in $SCRIPT."
echo "You can skip all pre-commit hooks with --no-verify (not recommended)."
exit 1
fi
done

View File

@@ -1,147 +0,0 @@
#!/usr/bin/env bash
# git pre-commit hook that runs a clang-format stylecheck.
# Features:
# - abort commit when commit does not comply with the style guidelines
# - create a patch of the proposed style changes
# Modifications for clang-format by rene.milk@wwu.de
# This file is part of a set of unofficial pre-commit hooks available
# at github.
# Link: https://github.com/githubbrowser/Pre-commit-hooks
# Contact: David Martin, david.martin.mailbox@googlemail.com
# Some quality of life modifications made for Godot Engine.
##################################################################
# SETTINGS
# Set path to clang-format binary
# CLANG_FORMAT="/usr/bin/clang-format"
CLANG_FORMAT=`which clang-format`
# Remove any older patches from previous commits. Set to true or false.
# DELETE_OLD_PATCHES=false
DELETE_OLD_PATCHES=false
# Only parse files with the extensions in FILE_EXTS. Set to true or false.
# If false every changed file in the commit will be parsed with clang-format.
# If true only files matching one of the extensions are parsed with clang-format.
# PARSE_EXTS=true
PARSE_EXTS=true
# File types to parse. Only effective when PARSE_EXTS is true.
# FILE_EXTS=".c .h .cpp .hpp"
FILE_EXTS=".c .h .cpp .hpp .cc .hh .cxx .m .mm .inc .java .glsl"
# Use pygmentize instead of cat to parse diff with highlighting.
# Install it with `pip install pygments` (Linux) or `easy_install Pygments` (Mac)
# READER="pygmentize -l diff"
READER=cat
##################################################################
# There should be no need to change anything below this line.
. "$(dirname -- "$0")/canonicalize_filename.sh"
# exit on error
set -e
# check whether the given file matches any of the set extensions
matches_extension() {
local filename=$(basename "$1")
local extension=".${filename##*.}"
local ext
for ext in $FILE_EXTS; do [[ "$ext" == "$extension" ]] && return 0; done
return 1
}
# necessary check for initial commit
if git rev-parse --verify HEAD >/dev/null 2>&1 ; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
if [ ! -x "$CLANG_FORMAT" ] ; then
printf "Error: clang-format executable not found.\n"
printf "Set the correct path in $(canonicalize_filename "$0").\n"
exit 1
fi
# create a random filename to store our generated patch
prefix="pre-commit-clang-format"
suffix="$(date +%s)"
patch="/tmp/$prefix-$suffix.patch"
# clean up any older clang-format patches
$DELETE_OLD_PATCHES && rm -f /tmp/$prefix*.patch
# create one patch containing all changes to the files
git diff-index --cached --diff-filter=ACMR --name-only $against -- | while read file;
do
# ignore thirdparty files
if grep -q "thirdparty" <<< $file; then
continue;
fi
# ignore file if we do check for file extensions and the file
# does not match any of the extensions specified in $FILE_EXTS
if $PARSE_EXTS && ! matches_extension "$file"; then
continue;
fi
# clang-format our sourcefile, create a patch with diff and append it to our $patch
# The sed call is necessary to transform the patch from
# --- $file timestamp
# +++ - timestamp
# to both lines working on the same file and having a/ and b/ prefix.
# Else it can not be applied with 'git apply'.
"$CLANG_FORMAT" -style=file "$file" | \
diff -u "$file" - | \
sed -e "1s|--- |--- a/|" -e "2s|+++ -|+++ b/$file|" >> "$patch"
done
# if no patch has been generated all is ok, clean up the file stub and exit
if [ ! -s "$patch" ] ; then
printf "Files in this commit comply with the clang-format rules.\n"
rm -f "$patch"
exit 0
fi
# a patch has been created, notify the user and exit
printf "\nThe following differences were found between the code to commit "
printf "and the clang-format rules:\n\n"
$READER "$patch"
printf "\n"
# Allows us to read user input below, assigns stdin to keyboard
exec < /dev/tty
while true; do
read -p "Do you want to apply that patch (Y - Apply, N - Do not apply, S - Apply and stage files)? [Y/N/S] " yn
case $yn in
[Yy] ) git apply $patch;
printf "The patch was applied. You can now stage the changes and commit again.\n\n";
break
;;
[Nn] ) printf "\nYou can apply these changes with:\n git apply $patch\n";
printf "(may need to be called from the root directory of your repository)\n";
printf "Aborting commit. Apply changes and commit again or skip checking with";
printf " --no-verify (not recommended).\n\n";
break
;;
[Ss] ) git apply $patch;
git diff-index --cached --diff-filter=ACMR --name-only $against -- | while read file;
do git add $file;
done
printf "The patch was applied and the changed files staged. You can now commit.\n\n";
break
;;
* ) echo "Please answer yes or no."
;;
esac
done
exit 1 # we don't commit in any case

View File

@@ -1,6 +1,6 @@
#include "AABB.hpp"
#include "Plane.hpp"
#include "Vector3.hpp"
#include "Plane.hpp"
#include <algorithm>
@@ -56,6 +56,7 @@ bool AABB::encloses(const AABB &p_aabb) const {
(src_max.y > dst_max.y) &&
(src_min.z <= dst_min.z) &&
(src_max.z > dst_max.z) );
}
Vector3 AABB::get_support(const Vector3& p_normal) const {
@@ -66,10 +67,11 @@ Vector3 AABB::get_support(const Vector3 &p_normal) const {
return Vector3(
(p_normal.x>0) ? -half_extents.x : half_extents.x,
(p_normal.y>0) ? -half_extents.y : half_extents.y,
(p_normal.z > 0) ? -half_extents.z : half_extents.z) +
ofs;
(p_normal.z>0) ? -half_extents.z : half_extents.z
)+ofs;
}
Vector3 AABB::get_endpoint(int p_point) const {
switch(p_point) {
@@ -96,7 +98,8 @@ bool AABB::intersects_convex_shape(const Plane *p_planes, int p_plane_count) con
Vector3 point(
(p.normal.x>0) ? -half_extents.x : half_extents.x,
(p.normal.y>0) ? -half_extents.y : half_extents.y,
(p.normal.z > 0) ? -half_extents.z : half_extents.z);
(p.normal.z>0) ? -half_extents.z : half_extents.z
);
point+=ofs;
if (p.is_point_over(point))
return false;
@@ -123,6 +126,7 @@ bool AABB::has_point(const Vector3 &p_point) const {
return true;
}
void AABB::expand_to(const Vector3& p_vector) {
Vector3 begin=position;
@@ -198,14 +202,16 @@ bool AABB::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t t
if (dir.x >= 0) {
tmin = (position.x - from.x) * divx;
tmax = (upbound.x - from.x) * divx;
} else {
}
else {
tmin = (upbound.x - from.x) * divx;
tmax = (position.x - from.x) * divx;
}
if (dir.y >= 0) {
tymin = (position.y - from.y) * divy;
tymax = (upbound.y - from.y) * divy;
} else {
}
else {
tymin = (upbound.y - from.y) * divy;
tymax = (position.y - from.y) * divy;
}
@@ -218,7 +224,8 @@ bool AABB::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t t
if (dir.z >= 0) {
tzmin = (position.z - from.z) * divz;
tzmax = (upbound.z - from.z) * divz;
} else {
}
else {
tzmin = (upbound.z - from.z) * divz;
tzmax = (position.z - from.z) * divz;
}
@@ -241,18 +248,22 @@ void AABB::grow_by(real_t p_amount) {
size.z+=2.0*p_amount;
}
real_t AABB::get_area() const {
return size.x*size.y*size.z;
}
bool AABB::operator==(const AABB& p_rval) const {
return ((position==p_rval.position) && (size==p_rval.size));
}
bool AABB::operator!=(const AABB& p_rval) const {
return ((position!=p_rval.position) || (size!=p_rval.size));
}
void AABB::merge_with(const AABB& p_aabb) {
@@ -293,6 +304,7 @@ AABB AABB::intersection(const AABB &p_aabb) const {
min.x= ( src_min.x > dst_min.x ) ? src_min.x :dst_min.x;
max.x= ( src_max.x < dst_max.x ) ? src_max.x :dst_max.x;
}
if (src_min.y > dst_max.y || src_max.y < dst_min.y )
@@ -301,6 +313,7 @@ AABB AABB::intersection(const AABB &p_aabb) const {
min.y= ( src_min.y > dst_min.y ) ? src_min.y :dst_min.y;
max.y= ( src_max.y < dst_max.y ) ? src_max.y :dst_max.y;
}
if (src_min.z > dst_max.z || src_max.z < dst_min.z )
@@ -309,8 +322,10 @@ AABB AABB::intersection(const AABB &p_aabb) const {
min.z= ( src_min.z > dst_min.z ) ? src_min.z :dst_min.z;
max.z= ( src_max.z < dst_max.z ) ? src_max.z :dst_max.z;
}
return AABB( min, max-min );
}
@@ -355,8 +370,10 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *
}
return true;
}
bool AABB::intersects_segment(const Vector3& p_from, const Vector3& p_to,Vector3* r_clip,Vector3* r_normal) const {
real_t min=0,max=1;
@@ -401,6 +418,7 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
return false;
}
Vector3 rel=p_to-p_from;
if (r_normal) {
@@ -413,8 +431,10 @@ bool AABB::intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector
*r_clip=p_from+rel*min;
return true;
}
bool AABB::intersects_plane(const Plane &p_plane) const {
Vector3 points[8] = {
@@ -437,11 +457,14 @@ bool AABB::intersects_plane(const Plane &p_plane) const {
over=true;
else
under=true;
}
return under && over;
}
Vector3 AABB::get_longest_axis() const {
Vector3 axis(1,0,0);
@@ -477,6 +500,7 @@ int AABB::get_longest_axis_index() const {
return axis;
}
Vector3 AABB::get_shortest_axis() const {
Vector3 axis(1,0,0);
@@ -522,6 +546,7 @@ AABB AABB::expand(const Vector3 &p_vector) const {
AABB aabb=*this;
aabb.expand_to(p_vector);
return aabb;
}
AABB AABB::grow(real_t p_by) const {
@@ -601,7 +626,9 @@ void AABB::get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const {
r_to=Vector3( position.x+size.x , position.y+size.y , position.z+size.z );
} break;
}
}
AABB::operator String() const {
@@ -609,4 +636,4 @@ AABB::operator String() const {
return String() + position + " - " + size;
}
} // namespace godot
}

View File

@@ -1,6 +1,6 @@
#include "Array.hpp"
#include "GodotGlobal.hpp"
#include "Variant.hpp"
#include "GodotGlobal.hpp"
#include <cstdlib>
@@ -8,158 +8,194 @@ namespace godot {
class Object;
Array::Array() {
Array::Array()
{
godot::api->godot_array_new(&_godot_array);
}
Array::Array(const Array &other) {
Array::Array(const Array & other)
{
godot::api->godot_array_new_copy(&_godot_array, &other._godot_array);
}
Array &Array::operator=(const Array &other) {
Array & Array::operator=(const Array & other)
{
godot::api->godot_array_destroy(&_godot_array);
godot::api->godot_array_new_copy(&_godot_array, &other._godot_array);
return *this;
}
Array::Array(const PoolByteArray &a) {
Array::Array(const PoolByteArray& a)
{
godot::api->godot_array_new_pool_byte_array(&_godot_array, (godot_pool_byte_array *) &a);
}
Array::Array(const PoolIntArray &a) {
Array::Array(const PoolIntArray& a)
{
godot::api->godot_array_new_pool_int_array(&_godot_array, (godot_pool_int_array *) &a);
}
Array::Array(const PoolRealArray &a) {
Array::Array(const PoolRealArray& a)
{
godot::api->godot_array_new_pool_real_array(&_godot_array, (godot_pool_real_array *) &a);
}
Array::Array(const PoolStringArray &a) {
Array::Array(const PoolStringArray& a)
{
godot::api->godot_array_new_pool_string_array(&_godot_array, (godot_pool_string_array *) &a);
}
Array::Array(const PoolVector2Array &a) {
Array::Array(const PoolVector2Array& a)
{
godot::api->godot_array_new_pool_vector2_array(&_godot_array, (godot_pool_vector2_array *) &a);
}
Array::Array(const PoolVector3Array &a) {
Array::Array(const PoolVector3Array& a)
{
godot::api->godot_array_new_pool_vector3_array(&_godot_array, (godot_pool_vector3_array *) &a);
}
Array::Array(const PoolColorArray &a) {
Array::Array(const PoolColorArray& a)
{
godot::api->godot_array_new_pool_color_array(&_godot_array, (godot_pool_color_array *) &a);
}
Variant &Array::operator[](const int idx) {
Variant& Array::operator [](const int idx)
{
godot_variant *v = godot::api->godot_array_operator_index(&_godot_array, idx);
return *(Variant *) v;
}
Variant Array::operator[](const int idx) const {
Variant Array::operator [](const int idx) const
{
// Yes, I'm casting away the const... you can hate me now.
// since the result is
godot_variant *v = godot::api->godot_array_operator_index((godot_array *) &_godot_array, idx);
return *(Variant *) v;
}
void Array::append(const Variant &v) {
void Array::append(const Variant& v)
{
godot::api->godot_array_append(&_godot_array, (godot_variant *) &v);
}
void Array::clear() {
void Array::clear()
{
godot::api->godot_array_clear(&_godot_array);
}
int Array::count(const Variant &v) {
int Array::count(const Variant& v)
{
return godot::api->godot_array_count(&_godot_array, (godot_variant *) &v);
}
bool Array::empty() const {
bool Array::empty() const
{
return godot::api->godot_array_empty(&_godot_array);
}
void Array::erase(const Variant &v) {
void Array::erase(const Variant& v)
{
godot::api->godot_array_erase(&_godot_array, (godot_variant *) &v);
}
Variant Array::front() const {
Variant Array::front() const
{
godot_variant v = godot::api->godot_array_front(&_godot_array);
return *(Variant *) &v;
}
Variant Array::back() const {
Variant Array::back() const
{
godot_variant v = godot::api->godot_array_back(&_godot_array);
return *(Variant *) &v;
}
int Array::find(const Variant &what, const int from) {
int Array::find(const Variant& what, const int from)
{
return godot::api->godot_array_find(&_godot_array, (godot_variant *) &what, from);
}
int Array::find_last(const Variant &what) {
int Array::find_last(const Variant& what)
{
return godot::api->godot_array_find_last(&_godot_array, (godot_variant *) &what);
}
bool Array::has(const Variant &what) const {
bool Array::has(const Variant& what) const
{
return godot::api->godot_array_has(&_godot_array, (godot_variant *) &what);
}
uint32_t Array::hash() const {
uint32_t Array::hash() const
{
return godot::api->godot_array_hash(&_godot_array);
}
void Array::insert(const int pos, const Variant &value) {
void Array::insert(const int pos, const Variant& value)
{
godot::api->godot_array_insert(&_godot_array, pos, (godot_variant *) &value);
}
void Array::invert() {
void Array::invert()
{
godot::api->godot_array_invert(&_godot_array);
}
Variant Array::pop_back() {
Variant Array::pop_back()
{
godot_variant v = godot::api->godot_array_pop_back(&_godot_array);
return *(Variant *) &v;
}
Variant Array::pop_front() {
Variant Array::pop_front()
{
godot_variant v = godot::api->godot_array_pop_front(&_godot_array);
return *(Variant *) &v;
}
void Array::push_back(const Variant &v) {
void Array::push_back(const Variant& v)
{
godot::api->godot_array_push_back(&_godot_array, (godot_variant *) &v);
}
void Array::push_front(const Variant &v) {
void Array::push_front(const Variant& v)
{
godot::api->godot_array_push_front(&_godot_array, (godot_variant *) &v);
}
void Array::remove(const int idx) {
void Array::remove(const int idx)
{
godot::api->godot_array_remove(&_godot_array, idx);
}
int Array::size() const {
int Array::size() const
{
return godot::api->godot_array_size(&_godot_array);
}
void Array::resize(const int size) {
void Array::resize(const int size)
{
godot::api->godot_array_resize(&_godot_array, size);
}
int Array::rfind(const Variant &what, const int from) {
int Array::rfind(const Variant& what, const int from)
{
return godot::api->godot_array_rfind(&_godot_array, (godot_variant *) &what, from);
}
void Array::sort() {
void Array::sort()
{
godot::api->godot_array_sort(&_godot_array);
}
void Array::sort_custom(Object *obj, const String &func) {
void Array::sort_custom(Object *obj, const String& func)
{
godot::api->godot_array_sort_custom(&_godot_array, (godot_object *) obj, (godot_string *) &func);
}
Array::~Array() {
Array::~Array()
{
godot::api->godot_array_destroy(&_godot_array);
}
} // namespace godot
}

View File

@@ -1,13 +1,15 @@
#include "Basis.hpp"
#include "Defs.hpp"
#include "Quat.hpp"
#include "Vector3.hpp"
#include "Quat.hpp"
#include <algorithm>
namespace godot {
Basis::Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2) {
Basis::Basis(const Vector3& row0, const Vector3& row1, const Vector3& row2)
{
elements[0]=row0;
elements[1]=row1;
elements[2]=row2;
@@ -31,6 +33,10 @@ Basis::Basis() {
elements[2][2]=1;
}
const Vector3& Basis::operator[](int axis) const {
return elements[axis];
@@ -43,7 +49,8 @@ Vector3 &Basis::operator[](int axis) {
#define cofac(row1,col1, row2, col2)\
(elements[row1][col1] * elements[row2][col2] - elements[row1][col2] * elements[row2][col1])
void Basis::invert() {
void Basis::invert()
{
real_t co[3]={
cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1)
};
@@ -51,6 +58,7 @@ void Basis::invert() {
elements[0][1] * co[1]+
elements[0][2] * co[2];
ERR_FAIL_COND(det == 0);
real_t s = 1.0/det;
@@ -73,36 +81,43 @@ bool Basis::isequal_approx(const Basis &a, const Basis &b) const {
return true;
}
bool Basis::is_orthogonal() const {
bool Basis::is_orthogonal() const
{
Basis id;
Basis m = (*this)*transposed();
return isequal_approx(id,m);
}
bool Basis::is_rotation() const {
bool Basis::is_rotation() const
{
return ::fabs(determinant()-1) < CMP_EPSILON && is_orthogonal();
}
void Basis::transpose() {
void Basis::transpose()
{
std::swap(elements[0][1],elements[1][0]);
std::swap(elements[0][2],elements[2][0]);
std::swap(elements[1][2],elements[2][1]);
}
Basis Basis::inverse() const {
Basis Basis::inverse() const
{
Basis b = *this;
b.invert();
return b;
}
Basis Basis::transposed() const {
Basis Basis::transposed() const
{
Basis b = *this;
b.transpose();
return b;
}
real_t Basis::determinant() const {
real_t Basis::determinant() const
{
return elements[0][0]*(elements[1][1]*elements[2][2] - elements[2][1]*elements[1][2]) -
elements[1][0]*(elements[0][1]*elements[2][2] - elements[2][1]*elements[0][2]) +
elements[2][0]*(elements[0][1]*elements[1][2] - elements[1][1]*elements[0][2]);
@@ -119,15 +134,18 @@ void Basis::set_axis(int p_axis, const Vector3 &p_value) {
elements[2][p_axis]=p_value.z;
}
void Basis::rotate(const Vector3 &p_axis, real_t p_phi) {
void Basis::rotate(const Vector3& p_axis, real_t p_phi)
{
*this = rotated(p_axis, p_phi);
}
Basis Basis::rotated(const Vector3 &p_axis, real_t p_phi) const {
Basis Basis::rotated(const Vector3& p_axis, real_t p_phi) const
{
return Basis(p_axis, p_phi) * (*this);
}
void Basis::scale(const Vector3 &p_scale) {
void Basis::scale( const Vector3& p_scale )
{
elements[0][0]*=p_scale.x;
elements[0][1]*=p_scale.x;
elements[0][2]*=p_scale.x;
@@ -139,13 +157,15 @@ void Basis::scale(const Vector3 &p_scale) {
elements[2][2]*=p_scale.z;
}
Basis Basis::scaled(const Vector3 &p_scale) const {
Basis Basis::scaled( const Vector3& p_scale ) const
{
Basis b = *this;
b.scale(p_scale);
return b;
}
Vector3 Basis::get_scale() const {
Vector3 Basis::get_scale() const
{
// We are assuming M = R.S, and performing a polar decomposition to extract R and S.
// FIXME: We eventually need a proper polar decomposition.
// As a cheap workaround until then, to ensure that R is a proper rotation matrix with determinant +1
@@ -155,7 +175,8 @@ Vector3 Basis::get_scale() const {
return det_sign*Vector3(
Vector3(elements[0][0],elements[1][0],elements[2][0]).length(),
Vector3(elements[0][1],elements[1][1],elements[2][1]).length(),
Vector3(elements[0][2], elements[1][2], elements[2][2]).length());
Vector3(elements[0][2],elements[1][2],elements[2][2]).length()
);
}
// get_euler_xyz returns a vector containing the Euler angles in the format
@@ -301,6 +322,8 @@ void Basis::set_euler_yxz(const Vector3 &p_euler) {
*this = ymat * xmat * zmat;
}
// transposed dot products
real_t Basis::tdotx(const Vector3& v) const {
return elements[0][0] * v[0] + elements[1][0] * v[1] + elements[2][0] * v[2];
@@ -312,7 +335,8 @@ real_t Basis::tdotz(const Vector3 &v) const {
return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2];
}
bool Basis::operator==(const Basis &p_matrix) const {
bool Basis::operator==(const Basis& p_matrix) const
{
for (int i=0;i<3;i++) {
for (int j=0;j<3;j++) {
if (elements[i][j] != p_matrix.elements[i][j])
@@ -323,7 +347,8 @@ bool Basis::operator==(const Basis &p_matrix) const {
return true;
}
bool Basis::operator!=(const Basis &p_matrix) const {
bool Basis::operator!=(const Basis& p_matrix) const
{
return (!(*this==p_matrix));
}
@@ -332,7 +357,8 @@ Vector3 Basis::xform(const Vector3 &p_vector) const {
return Vector3(
elements[0].dot(p_vector),
elements[1].dot(p_vector),
elements[2].dot(p_vector));
elements[2].dot(p_vector)
);
}
Vector3 Basis::xform_inv(const Vector3& p_vector) const {
@@ -340,22 +366,28 @@ Vector3 Basis::xform_inv(const Vector3 &p_vector) const {
return Vector3(
(elements[0][0]*p_vector.x ) + ( elements[1][0]*p_vector.y ) + ( elements[2][0]*p_vector.z ),
(elements[0][1]*p_vector.x ) + ( elements[1][1]*p_vector.y ) + ( elements[2][1]*p_vector.z ),
(elements[0][2] * p_vector.x) + (elements[1][2] * p_vector.y) + (elements[2][2] * p_vector.z));
(elements[0][2]*p_vector.x ) + ( elements[1][2]*p_vector.y ) + ( elements[2][2]*p_vector.z )
);
}
void Basis::operator*=(const Basis &p_matrix) {
void Basis::operator*=(const Basis& p_matrix)
{
set(
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]),
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]),
p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2]));
}
Basis Basis::operator*(const Basis &p_matrix) const {
Basis Basis::operator*(const Basis& p_matrix) const
{
return Basis(
p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]),
p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]),
p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2]) );
}
void Basis::operator+=(const Basis& p_matrix) {
elements[0] += p_matrix.elements[0];
@@ -398,7 +430,9 @@ Basis Basis::operator*(real_t p_val) const {
return ret;
}
Basis::operator String() const {
Basis::operator String() const
{
String s;
for (int i = 0; i < 3; i++) {
@@ -415,6 +449,7 @@ Basis::operator String() const {
/* create / set */
void Basis::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) {
elements[0][0]=xx;
@@ -446,7 +481,8 @@ void Basis::set_row(int i, const Vector3 &p_row) {
elements[i][2]=p_row.z;
}
Basis Basis::transpose_xform(const Basis &m) const {
Basis Basis::transpose_xform(const Basis& m) const
{
return Basis(
elements[0].x * m[0].x + elements[1].x * m[1].x + elements[2].x * m[2].x,
elements[0].x * m[0].y + elements[1].x * m[1].y + elements[2].x * m[2].y,
@@ -459,7 +495,8 @@ Basis Basis::transpose_xform(const Basis &m) const {
elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z);
}
void Basis::orthonormalize() {
void Basis::orthonormalize()
{
ERR_FAIL_COND(determinant() == 0);
// Gram-Schmidt Process
@@ -479,13 +516,15 @@ void Basis::orthonormalize() {
set_axis(2,z);
}
Basis Basis::orthonormalized() const {
Basis Basis::orthonormalized() const
{
Basis b = *this;
b.orthonormalize();
return b;
}
bool Basis::is_symmetric() const {
bool Basis::is_symmetric() const
{
if (::fabs(elements[0][1] - elements[1][0]) > CMP_EPSILON)
return false;
if (::fabs(elements[0][2] - elements[2][0]) > CMP_EPSILON)
@@ -496,7 +535,8 @@ bool Basis::is_symmetric() const {
return true;
}
Basis Basis::diagonalize() {
Basis Basis::diagonalize()
{
// I love copy paste
if (!is_symmetric())
@@ -556,6 +596,7 @@ Basis Basis::diagonalize() {
return acc_rot;
}
static const Basis _ortho_bases[24]={
Basis(1, 0, 0, 0, 1, 0, 0, 0, 1),
Basis(0, -1, 0, 1, 0, 0, 0, 0, 1),
@@ -583,7 +624,9 @@ static const Basis _ortho_bases[24] = {
Basis(0, -1, 0, 0, 0, -1, 1, 0, 0)
};
int Basis::get_orthogonal_index() const {
int Basis::get_orthogonal_index() const
{
//could be sped up if i come up with a way
Basis orth=*this;
for(int i=0;i<3;i++) {
@@ -605,25 +648,32 @@ int Basis::get_orthogonal_index() const {
if (_ortho_bases[i]==orth)
return i;
}
return 0;
}
void Basis::set_orthogonal_index(int p_index){
//there only exist 24 orthogonal bases in r3
ERR_FAIL_COND(p_index >= 24);
*this=_ortho_bases[p_index];
}
Basis::Basis(const Vector3& p_euler) {
set_euler( p_euler );
}
} // namespace godot
}
#include "Quat.hpp"
@@ -640,6 +690,7 @@ Basis::Basis(const Quat &p_quat) {
set( 1.0 - (yy + zz), xy - wz, xz + wy,
xy + wz, 1.0 - (xx + zz), yz - wx,
xz - wy, yz + wx, 1.0 - (xx + yy)) ;
}
Basis::Basis(const Vector3& p_axis, real_t p_phi) {
@@ -661,6 +712,7 @@ Basis::Basis(const Vector3 &p_axis, real_t p_phi) {
elements[2][0] = p_axis.z * p_axis.x * ( 1.0 - cosine ) - p_axis.y * sine;
elements[2][1] = p_axis.y * p_axis.z * ( 1.0 - cosine ) + p_axis.x * sine;
elements[2][2] = axis_sq.z + cosine * ( 1.0 - axis_sq.z );
}
Basis::operator Quat() const {
@@ -670,7 +722,8 @@ Basis::operator Quat() const {
real_t trace = elements[0][0] + elements[1][1] + elements[2][2];
real_t temp[4];
if (trace > 0.0) {
if (trace > 0.0)
{
real_t s = ::sqrt(trace + 1.0);
temp[3]=(s * 0.5);
s = 0.5 / s;
@@ -678,7 +731,9 @@ Basis::operator Quat() const {
temp[0]=((elements[2][1] - elements[1][2]) * s);
temp[1]=((elements[0][2] - elements[2][0]) * s);
temp[2]=((elements[1][0] - elements[0][1]) * s);
} else {
}
else
{
int i = elements[0][0] < elements[1][1] ?
(elements[1][1] < elements[2][2] ? 2 : 1) :
(elements[0][0] < elements[2][2] ? 2 : 0);
@@ -695,6 +750,10 @@ Basis::operator Quat() const {
}
return Quat(temp[0],temp[1],temp[2],temp[3]);
}
} // namespace godot
}

View File

@@ -37,12 +37,15 @@ static float _parse_col(const String &p_str, int p_ofs) {
ig+=v*16;
else
ig+=v;
}
return ig;
}
uint32_t Color::to_32() const {
uint32_t Color::to_32() const
{
uint32_t c=(uint8_t)(a*255);
c<<=8;
@@ -55,7 +58,8 @@ uint32_t Color::to_32() const {
return c;
}
uint32_t Color::to_ARGB32() const {
uint32_t Color::to_ARGB32() const
{
uint32_t c=(uint8_t)(a*255);
c<<=8;
c|=(uint8_t)(r*255);
@@ -67,11 +71,13 @@ uint32_t Color::to_ARGB32() const {
return c;
}
float Color::gray() const {
float Color::gray() const
{
return (r+g+b)/3.0;
}
float Color::get_h() const {
float Color::get_h() const
{
float min = MIN( r, g );
min = MIN( min, b );
@@ -98,22 +104,26 @@ float Color::get_h() const {
return h;
}
float Color::get_s() const {
float Color::get_s() const
{
float min = MIN( r, g );
min = MIN( min, b );
float max = MAX( r, g );
max = MAX( max, b );
float delta = max - min;
return (max!=0) ? (delta / max) : 0;
}
float Color::get_v() const {
float Color::get_v() const
{
float max = MAX( r, g );
max = MAX( max, b );
return max;
}
void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha)
{
int i;
float f, p, q, t;
a=p_alpha;
@@ -167,23 +177,27 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
}
}
void Color::invert() {
void Color::invert()
{
r=1.0-r;
g=1.0-g;
b=1.0-b;
}
void Color::contrast() {
void Color::contrast()
{
r=::fmod(r+0.5,1.0);
g=::fmod(g+0.5,1.0);
b=::fmod(b+0.5,1.0);
}
Color Color::inverted() const {
Color Color::inverted() const
{
Color c=*this;
c.invert();
return c;
}
Color Color::contrasted() const {
Color Color::contrasted() const
{
Color c=*this;
c.contrast();
return c;
@@ -203,6 +217,7 @@ Color Color::linear_interpolate(const Color &p_b, float p_t) const {
Color Color::blend(const Color& p_over) const {
Color res;
float sa = 1.0 - p_over.a;
res.a = a*sa+p_over.a;
@@ -222,10 +237,12 @@ Color Color::to_linear() const {
r<0.04045 ? r * (1.0 / 12.92) : ::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4),
g<0.04045 ? g * (1.0 / 12.92) : ::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4),
b<0.04045 ? b * (1.0 / 12.92) : ::pow((b + 0.055) * (1.0 / (1 + 0.055)), 2.4),
a);
a
);
}
Color Color::hex(uint32_t p_hex) {
Color Color::hex(uint32_t p_hex)
{
float a = (p_hex&0xFF)/255.0;
p_hex>>=8;
float b = (p_hex&0xFF)/255.0;
@@ -237,7 +254,8 @@ Color Color::hex(uint32_t p_hex) {
return Color(r,g,b,a);
}
Color Color::html(const String &p_color) {
Color Color::html(const String& p_color)
{
String color = p_color;
if (color.length()==0)
return Color();
@@ -285,7 +303,8 @@ Color Color::html(const String &p_color) {
return Color(r/255.0,g/255.0,b/255.0,a/255.0);
}
bool Color::html_is_valid(const String &p_color) {
bool Color::html_is_valid(const String& p_color)
{
String color = p_color;
if (color.length()==0)
@@ -353,9 +372,11 @@ static String _to_hex(float p_val) {
}
return ret;
}
String Color::to_html(bool p_alpha) const {
String Color::to_html(bool p_alpha) const
{
String txt;
txt+=_to_hex(r);
txt+=_to_hex(g);
@@ -365,10 +386,12 @@ String Color::to_html(bool p_alpha) const {
return txt;
}
Color::operator String() const {
Color::operator String() const
{
return String::num(r) + ", " + String::num(g) + ", " + String::num(b) + ", " + String::num(a);
}
bool Color::operator<(const Color& p_color) const {
if (r==p_color.r) {
@@ -381,6 +404,7 @@ bool Color::operator<(const Color &p_color) const {
return g<p_color.g;
} else
return r<p_color.r;
}
} // namespace godot
}

View File

@@ -1,78 +1,95 @@
#include "Dictionary.hpp"
#include "Variant.hpp"
#include "Array.hpp"
#include "GodotGlobal.hpp"
#include "Variant.hpp"
namespace godot {
Dictionary::Dictionary() {
Dictionary::Dictionary()
{
godot::api->godot_dictionary_new(&_godot_dictionary);
}
Dictionary::Dictionary(const Dictionary &other) {
Dictionary::Dictionary(const Dictionary & other)
{
godot::api->godot_dictionary_new_copy(&_godot_dictionary, &other._godot_dictionary);
}
Dictionary &Dictionary::operator=(const Dictionary &other) {
Dictionary & Dictionary::operator=(const Dictionary & other)
{
godot::api->godot_dictionary_destroy(&_godot_dictionary);
godot::api->godot_dictionary_new_copy(&_godot_dictionary, &other._godot_dictionary);
return *this;
}
void Dictionary::clear() {
void Dictionary::clear()
{
godot::api->godot_dictionary_clear(&_godot_dictionary);
}
bool Dictionary::empty() const {
bool Dictionary::empty() const
{
return godot::api->godot_dictionary_empty(&_godot_dictionary);
}
void Dictionary::erase(const Variant &key) {
void Dictionary::erase(const Variant& key)
{
godot::api->godot_dictionary_erase(&_godot_dictionary, (godot_variant *) &key);
}
bool Dictionary::has(const Variant &key) const {
bool Dictionary::has(const Variant& key) const
{
return godot::api->godot_dictionary_has(&_godot_dictionary, (godot_variant *) &key);
}
bool Dictionary::has_all(const Array &keys) const {
bool Dictionary::has_all(const Array& keys) const
{
return godot::api->godot_dictionary_has_all(&_godot_dictionary, (godot_array *) &keys);
}
uint32_t Dictionary::hash() const {
uint32_t Dictionary::hash() const
{
return godot::api->godot_dictionary_hash(&_godot_dictionary);
}
Array Dictionary::keys() const {
Array Dictionary::keys() const
{
godot_array a = godot::api->godot_dictionary_keys(&_godot_dictionary);
return *(Array *) &a;
}
Variant &Dictionary::operator[](const Variant &key) {
Variant &Dictionary::operator [](const Variant& key)
{
return *(Variant *) godot::api->godot_dictionary_operator_index(&_godot_dictionary, (godot_variant *) &key);
}
const Variant &Dictionary::operator[](const Variant &key) const {
const Variant &Dictionary::operator [](const Variant& key) const
{
// oops I did it again
return *(Variant *) godot::api->godot_dictionary_operator_index((godot_dictionary *) &_godot_dictionary, (godot_variant *) &key);
}
int Dictionary::size() const {
int Dictionary::size() const
{
return godot::api->godot_dictionary_size(&_godot_dictionary);
}
String Dictionary::to_json() const {
String Dictionary::to_json() const
{
godot_string s = godot::api->godot_dictionary_to_json(&_godot_dictionary);
return *(String *) &s;
}
Array Dictionary::values() const {
Array Dictionary::values() const
{
godot_array a = godot::api->godot_dictionary_values(&_godot_dictionary);
return *(Array *) &a;
}
Dictionary::~Dictionary() {
Dictionary::~Dictionary()
{
godot::api->godot_dictionary_destroy(&_godot_dictionary);
}
} // namespace godot
}

View File

@@ -4,7 +4,8 @@
#include "Wrapped.hpp"
static GDCALLINGCONV void *wrapper_create(void *data, const void *type_tag, godot_object *instance) {
static GDCALLINGCONV void *wrapper_create(void *data, const void *type_tag, godot_object *instance)
{
godot::_Wrapped *wrapper_memory = (godot::_Wrapped *) godot::api->godot_alloc(sizeof(godot::_Wrapped));
if (!wrapper_memory)
@@ -15,7 +16,8 @@ static GDCALLINGCONV void *wrapper_create(void *data, const void *type_tag, godo
return (void *) wrapper_memory;
}
static GDCALLINGCONV void wrapper_destroy(void *data, void *wrapper) {
static GDCALLINGCONV void wrapper_destroy(void *data, void *wrapper)
{
if (wrapper)
godot::api->godot_free(wrapper);
}
@@ -30,11 +32,13 @@ const godot_gdnative_ext_nativescript_1_1_api_struct *nativescript_1_1_api = nul
const void *gdnlib = NULL;
void Godot::print(const String &message) {
void Godot::print(const String& message)
{
godot::api->godot_print((godot_string *) &message);
}
void Godot::print_warning(const String &description, const String &function, const String &file, int line) {
void Godot::print_warning(const String& description, const String& function, const String& file, int line)
{
int len;
char * c_desc = description.alloc_c_string();
@@ -50,7 +54,8 @@ void Godot::print_warning(const String &description, const String &function, con
if (c_file != nullptr) godot::api->godot_free(c_file);
}
void Godot::print_error(const String &description, const String &function, const String &file, int line) {
void Godot::print_error(const String& description, const String& function, const String& file, int line)
{
int len;
char * c_desc = description.alloc_c_string();
@@ -68,7 +73,8 @@ void Godot::print_error(const String &description, const String &function, const
void ___register_types();
void Godot::gdnative_init(godot_gdnative_init_options *options) {
void Godot::gdnative_init(godot_gdnative_init_options *options)
{
godot::api = options->api_struct;
godot::gdnlib = options->gd_native_library;
@@ -91,17 +97,16 @@ void Godot::gdnative_init(godot_gdnative_init_options *options) {
default: break;
}
}
}
void Godot::gdnative_terminate(godot_gdnative_terminate_options *options) {
void Godot::gdnative_terminate(godot_gdnative_terminate_options *options)
{
// reserved for future use.
}
void Godot::gdnative_profiling_add_data(const char *p_signature, uint64_t p_time) {
godot::nativescript_1_1_api->godot_nativescript_profiling_add_data(p_signature, p_time);
}
void Godot::nativescript_init(void *handle) {
void Godot::nativescript_init(void *handle)
{
godot::_RegisterState::nativescript_handle = handle;
godot_instance_binding_functions binding_funcs = {};
@@ -113,8 +118,9 @@ void Godot::nativescript_init(void *handle) {
___register_types();
}
void Godot::nativescript_terminate(void *handle) {
void Godot::nativescript_terminate(void *handle)
{
godot::nativescript_1_1_api->godot_nativescript_unregister_instance_binding_data_functions(godot::_RegisterState::language_index);
}
} // namespace godot
}

View File

@@ -1,68 +1,82 @@
#include "NodePath.hpp"
#include "GodotGlobal.hpp"
#include "String.hpp"
#include "GodotGlobal.hpp"
#include <gdnative/node_path.h>
namespace godot {
NodePath::NodePath() {
NodePath::NodePath()
{
String from = "";
godot::api->godot_node_path_new(&_node_path, (godot_string *) &from);
}
NodePath::NodePath(const NodePath &other) {
NodePath::NodePath(const NodePath &other)
{
String from = other;
godot::api->godot_node_path_new(&_node_path, (godot_string *) &from);
}
NodePath::NodePath(const String &from) {
NodePath::NodePath(const String &from)
{
godot::api->godot_node_path_new(&_node_path, (godot_string *) &from);
}
NodePath::NodePath(const char *contents) {
NodePath::NodePath(const char *contents)
{
String from = contents;
godot::api->godot_node_path_new(&_node_path, (godot_string *) &from);
}
String NodePath::get_name(const int idx) const {
String NodePath::get_name(const int idx) const
{
godot_string str = godot::api->godot_node_path_get_name(&_node_path, idx);
return *(String *) &str;
}
int NodePath::get_name_count() const {
int NodePath::get_name_count() const
{
return godot::api->godot_node_path_get_name_count(&_node_path);
}
String NodePath::get_subname(const int idx) const {
String NodePath::get_subname(const int idx) const
{
godot_string str = godot::api->godot_node_path_get_subname(&_node_path, idx);
return *(String *) &str;
}
int NodePath::get_subname_count() const {
int NodePath::get_subname_count() const
{
return godot::api->godot_node_path_get_subname_count(&_node_path);
}
bool NodePath::is_absolute() const {
bool NodePath::is_absolute() const
{
return godot::api->godot_node_path_is_absolute(&_node_path);
}
bool NodePath::is_empty() const {
bool NodePath::is_empty() const
{
return godot::api->godot_node_path_is_empty(&_node_path);
}
NodePath::operator String() const {
NodePath::operator String() const
{
godot_string str = godot::api->godot_node_path_as_string(&_node_path);
return *(String *) &str;
}
bool NodePath::operator==(const NodePath &other) {
bool NodePath::operator ==(const NodePath& other)
{
return godot::api->godot_node_path_operator_equal(&_node_path, &other._node_path);
}
void NodePath::operator=(const NodePath &other) {
void NodePath::operator =(const NodePath& other)
{
godot::api->godot_node_path_destroy(&_node_path);
String other_string = (String) other;
@@ -70,8 +84,11 @@ void NodePath::operator=(const NodePath &other) {
godot::api->godot_node_path_new(&_node_path, (godot_string *) &other_string);
}
NodePath::~NodePath() {
NodePath::~NodePath()
{
godot::api->godot_node_path_destroy(&_node_path);
}
} // namespace godot
}

View File

@@ -5,7 +5,9 @@
namespace godot {
void Plane::set_normal(const Vector3 &p_normal) {
void Plane::set_normal(const Vector3& p_normal)
{
this->normal = p_normal;
}
@@ -14,6 +16,7 @@ Vector3 Plane::project(const Vector3 &p_point) const {
return p_point - normal * distance_to(p_point);
}
void Plane::normalize() {
real_t l = normal.length();
@@ -54,6 +57,7 @@ Vector3 Plane::get_any_perpendicular_normal() const {
return p;
}
/* intersections */
bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result) const {
@@ -71,13 +75,13 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r
if (r_result) {
*r_result = ( (vec3_cross(normal1, normal2) * p_plane0.d) +
(vec3_cross(normal2, normal0) * p_plane1.d) +
(vec3_cross(normal0, normal1) * p_plane2.d)) /
denom;
(vec3_cross(normal0, normal1) * p_plane2.d) )/denom;
}
return true;
}
bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3* p_intersection) const {
Vector3 segment=p_dir;
@@ -135,12 +139,15 @@ bool Plane::is_almost_like(const Plane &p_plane) const {
return (normal.dot( p_plane.normal ) > _PLANE_EQ_DOT_EPSILON && ::fabs(d-p_plane.d) < _PLANE_EQ_D_EPSILON);
}
Plane::operator String() const {
// return normal.operator String() + ", " + rtos(d);
return String(); // @Todo
}
bool Plane::is_point_over(const Vector3 &p_point) const {
return (normal.dot(p_point) > d);
@@ -156,6 +163,7 @@ bool Plane::has_point(const Vector3 &p_point, real_t _epsilon) const {
real_t dist=normal.dot(p_point) - d;
dist=::fabs(dist);
return ( dist <= _epsilon);
}
Plane::Plane(const Vector3 &p_normal, real_t p_d) {
@@ -177,8 +185,11 @@ Plane::Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_
else
normal=(p_point1-p_point2).cross(p_point1-p_point3);
normal.normalize();
d = normal.dot(p_point1);
}
bool Plane::operator==(const Plane& p_plane) const {
@@ -189,6 +200,10 @@ bool Plane::operator==(const Plane &p_plane) const {
bool Plane::operator!=(const Plane& p_plane) const {
return normal!=p_plane.normal || d != p_plane.d;
}
} // namespace godot
}

View File

@@ -1,300 +1,374 @@
#include "PoolArrays.hpp"
#include "Color.hpp"
#include "Defs.hpp"
#include "GodotGlobal.hpp"
#include "String.hpp"
#include "Color.hpp"
#include "Vector2.hpp"
#include "Vector3.hpp"
#include "GodotGlobal.hpp"
#include <gdnative/pool_arrays.h>
namespace godot {
PoolByteArray::PoolByteArray() {
PoolByteArray::PoolByteArray()
{
godot::api->godot_pool_byte_array_new(&_godot_array);
}
PoolByteArray::PoolByteArray(const PoolByteArray &p_other) {
PoolByteArray::PoolByteArray(const PoolByteArray &p_other)
{
godot::api->godot_pool_byte_array_new_copy(&_godot_array, &p_other._godot_array);
}
PoolByteArray &PoolByteArray::operator=(const PoolByteArray &p_other) {
PoolByteArray &PoolByteArray::operator=(const PoolByteArray & p_other)
{
godot::api->godot_pool_byte_array_destroy(&_godot_array);
godot::api->godot_pool_byte_array_new_copy(&_godot_array, &p_other._godot_array);
return *this;
}
PoolByteArray::PoolByteArray(const Array &array) {
PoolByteArray::PoolByteArray(const Array& array)
{
godot::api->godot_pool_byte_array_new_with_array(&_godot_array, (godot_array *) &array);
}
PoolByteArray::Read PoolByteArray::read() const {
PoolByteArray::Read PoolByteArray::read() const
{
Read read;
read._read_access = godot::api->godot_pool_byte_array_read(&_godot_array);
return read;
}
PoolByteArray::Write PoolByteArray::write() {
PoolByteArray::Write PoolByteArray::write()
{
Write write;
write._write_access = godot::api->godot_pool_byte_array_write(&_godot_array);
return write;
}
void PoolByteArray::append(const uint8_t data) {
void PoolByteArray::append(const uint8_t data)
{
godot::api->godot_pool_byte_array_append(&_godot_array, data);
}
void PoolByteArray::append_array(const PoolByteArray &array) {
void PoolByteArray::append_array(const PoolByteArray& array)
{
godot::api->godot_pool_byte_array_append_array(&_godot_array, &array._godot_array);
}
int PoolByteArray::insert(const int idx, const uint8_t data) {
int PoolByteArray::insert(const int idx, const uint8_t data)
{
return godot::api->godot_pool_byte_array_insert(&_godot_array, idx, data);
}
void PoolByteArray::invert() {
void PoolByteArray::invert()
{
godot::api->godot_pool_byte_array_invert(&_godot_array);
}
void PoolByteArray::push_back(const uint8_t data) {
void PoolByteArray::push_back(const uint8_t data)
{
godot::api->godot_pool_byte_array_push_back(&_godot_array, data);
}
void PoolByteArray::remove(const int idx) {
void PoolByteArray::remove(const int idx)
{
godot::api->godot_pool_byte_array_remove(&_godot_array, idx);
}
void PoolByteArray::resize(const int size) {
void PoolByteArray::resize(const int size)
{
godot::api->godot_pool_byte_array_resize(&_godot_array, size);
}
void PoolByteArray::set(const int idx, const uint8_t data) {
void PoolByteArray::set(const int idx, const uint8_t data)
{
godot::api->godot_pool_byte_array_set(&_godot_array, idx, data);
}
uint8_t PoolByteArray::operator[](const int idx) {
uint8_t PoolByteArray::operator [](const int idx)
{
return godot::api->godot_pool_byte_array_get(&_godot_array, idx);
}
int PoolByteArray::size() const {
int PoolByteArray::size() const
{
return godot::api->godot_pool_byte_array_size(&_godot_array);
}
PoolByteArray::~PoolByteArray() {
PoolByteArray::~PoolByteArray()
{
godot::api->godot_pool_byte_array_destroy(&_godot_array);
}
PoolIntArray::PoolIntArray() {
PoolIntArray::PoolIntArray()
{
godot::api->godot_pool_int_array_new(&_godot_array);
}
PoolIntArray::PoolIntArray(const PoolIntArray &p_other) {
PoolIntArray::PoolIntArray(const PoolIntArray &p_other)
{
godot::api->godot_pool_int_array_new_copy(&_godot_array, &p_other._godot_array);
}
PoolIntArray &PoolIntArray::operator=(const PoolIntArray &p_other) {
PoolIntArray &PoolIntArray::operator=(const PoolIntArray &p_other)
{
godot::api->godot_pool_int_array_destroy(&_godot_array);
godot::api->godot_pool_int_array_new_copy(&_godot_array, &p_other._godot_array);
return *this;
}
PoolIntArray::PoolIntArray(const Array &array) {
PoolIntArray::PoolIntArray(const Array& array)
{
godot::api->godot_pool_int_array_new_with_array(&_godot_array, (godot_array *) &array);
}
PoolIntArray::Read PoolIntArray::read() const {
PoolIntArray::Read PoolIntArray::read() const
{
Read read;
read._read_access = godot::api->godot_pool_int_array_read(&_godot_array);
return read;
}
PoolIntArray::Write PoolIntArray::write() {
PoolIntArray::Write PoolIntArray::write()
{
Write write;
write._write_access = godot::api->godot_pool_int_array_write(&_godot_array);
return write;
}
void PoolIntArray::append(const int data) {
void PoolIntArray::append(const int data)
{
godot::api->godot_pool_int_array_append(&_godot_array, data);
}
void PoolIntArray::append_array(const PoolIntArray &array) {
void PoolIntArray::append_array(const PoolIntArray& array)
{
godot::api->godot_pool_int_array_append_array(&_godot_array, &array._godot_array);
}
int PoolIntArray::insert(const int idx, const int data) {
int PoolIntArray::insert(const int idx, const int data)
{
return godot::api->godot_pool_int_array_insert(&_godot_array, idx, data);
}
void PoolIntArray::invert() {
void PoolIntArray::invert()
{
godot::api->godot_pool_int_array_invert(&_godot_array);
}
void PoolIntArray::push_back(const int data) {
void PoolIntArray::push_back(const int data)
{
godot::api->godot_pool_int_array_push_back(&_godot_array, data);
}
void PoolIntArray::remove(const int idx) {
void PoolIntArray::remove(const int idx)
{
godot::api->godot_pool_int_array_remove(&_godot_array, idx);
}
void PoolIntArray::resize(const int size) {
void PoolIntArray::resize(const int size)
{
godot::api->godot_pool_int_array_resize(&_godot_array, size);
}
void PoolIntArray::set(const int idx, const int data) {
void PoolIntArray::set(const int idx, const int data)
{
godot::api->godot_pool_int_array_set(&_godot_array, idx, data);
}
int PoolIntArray::operator[](const int idx) {
int PoolIntArray::operator [](const int idx)
{
return godot::api->godot_pool_int_array_get(&_godot_array, idx);
}
int PoolIntArray::size() const {
int PoolIntArray::size() const
{
return godot::api->godot_pool_int_array_size(&_godot_array);
}
PoolIntArray::~PoolIntArray() {
PoolIntArray::~PoolIntArray()
{
godot::api->godot_pool_int_array_destroy(&_godot_array);
}
PoolRealArray::PoolRealArray() {
PoolRealArray::PoolRealArray()
{
godot::api->godot_pool_real_array_new(&_godot_array);
}
PoolRealArray::PoolRealArray(const PoolRealArray &p_other) {
PoolRealArray::PoolRealArray(const PoolRealArray &p_other)
{
godot::api->godot_pool_real_array_new_copy(&_godot_array, &p_other._godot_array);
}
PoolRealArray &PoolRealArray::operator=(const PoolRealArray &p_other) {
PoolRealArray &PoolRealArray::operator=(const PoolRealArray &p_other)
{
godot::api->godot_pool_real_array_destroy(&_godot_array);
godot::api->godot_pool_real_array_new_copy(&_godot_array, &p_other._godot_array);
return *this;
}
PoolRealArray::Read PoolRealArray::read() const {
PoolRealArray::Read PoolRealArray::read() const
{
Read read;
read._read_access = godot::api->godot_pool_real_array_read(&_godot_array);
return read;
}
PoolRealArray::Write PoolRealArray::write() {
PoolRealArray::Write PoolRealArray::write()
{
Write write;
write._write_access = godot::api->godot_pool_real_array_write(&_godot_array);
return write;
}
PoolRealArray::PoolRealArray(const Array &array) {
PoolRealArray::PoolRealArray(const Array& array)
{
godot::api->godot_pool_real_array_new_with_array(&_godot_array, (godot_array *) &array);
}
void PoolRealArray::append(const real_t data) {
void PoolRealArray::append(const real_t data)
{
godot::api->godot_pool_real_array_append(&_godot_array, data);
}
void PoolRealArray::append_array(const PoolRealArray &array) {
void PoolRealArray::append_array(const PoolRealArray& array)
{
godot::api->godot_pool_real_array_append_array(&_godot_array, &array._godot_array);
}
int PoolRealArray::insert(const int idx, const real_t data) {
int PoolRealArray::insert(const int idx, const real_t data)
{
return godot::api->godot_pool_real_array_insert(&_godot_array, idx, data);
}
void PoolRealArray::invert() {
void PoolRealArray::invert()
{
godot::api->godot_pool_real_array_invert(&_godot_array);
}
void PoolRealArray::push_back(const real_t data) {
void PoolRealArray::push_back(const real_t data)
{
godot::api->godot_pool_real_array_push_back(&_godot_array, data);
}
void PoolRealArray::remove(const int idx) {
void PoolRealArray::remove(const int idx)
{
godot::api->godot_pool_real_array_remove(&_godot_array, idx);
}
void PoolRealArray::resize(const int size) {
void PoolRealArray::resize(const int size)
{
godot::api->godot_pool_real_array_resize(&_godot_array, size);
}
void PoolRealArray::set(const int idx, const real_t data) {
void PoolRealArray::set(const int idx, const real_t data)
{
godot::api->godot_pool_real_array_set(&_godot_array, idx, data);
}
real_t PoolRealArray::operator[](const int idx) {
real_t PoolRealArray::operator [](const int idx)
{
return godot::api->godot_pool_real_array_get(&_godot_array, idx);
}
int PoolRealArray::size() const {
int PoolRealArray::size() const
{
return godot::api->godot_pool_real_array_size(&_godot_array);
}
PoolRealArray::~PoolRealArray() {
PoolRealArray::~PoolRealArray()
{
godot::api->godot_pool_real_array_destroy(&_godot_array);
}
PoolStringArray::PoolStringArray() {
PoolStringArray::PoolStringArray()
{
godot::api->godot_pool_string_array_new(&_godot_array);
}
PoolStringArray::PoolStringArray(const PoolStringArray &p_other) {
PoolStringArray::PoolStringArray(const PoolStringArray &p_other)
{
godot::api->godot_pool_string_array_new_copy(&_godot_array, &p_other._godot_array);
}
PoolStringArray &PoolStringArray::operator=(const PoolStringArray &p_other) {
PoolStringArray &PoolStringArray::operator=(const PoolStringArray &p_other)
{
godot::api->godot_pool_string_array_destroy(&_godot_array);
godot::api->godot_pool_string_array_new_copy(&_godot_array, &p_other._godot_array);
return *this;
}
PoolStringArray::PoolStringArray(const Array &array) {
PoolStringArray::PoolStringArray(const Array& array)
{
godot::api->godot_pool_string_array_new_with_array(&_godot_array, (godot_array *) &array);
}
PoolStringArray::Read PoolStringArray::read() const {
PoolStringArray::Read PoolStringArray::read() const
{
Read read;
read._read_access = godot::api->godot_pool_string_array_read(&_godot_array);
return read;
}
PoolStringArray::Write PoolStringArray::write() {
PoolStringArray::Write PoolStringArray::write()
{
Write write;
write._write_access = godot::api->godot_pool_string_array_write(&_godot_array);
return write;
}
void PoolStringArray::append(const String &data) {
void PoolStringArray::append(const String& data)
{
godot::api->godot_pool_string_array_append(&_godot_array, (godot_string *) &data);
}
void PoolStringArray::append_array(const PoolStringArray &array) {
void PoolStringArray::append_array(const PoolStringArray& array)
{
godot::api->godot_pool_string_array_append_array(&_godot_array, &array._godot_array);
}
int PoolStringArray::insert(const int idx, const String &data) {
int PoolStringArray::insert(const int idx, const String& data)
{
return godot::api->godot_pool_string_array_insert(&_godot_array, idx, (godot_string *) &data);
}
void PoolStringArray::invert() {
void PoolStringArray::invert()
{
godot::api->godot_pool_string_array_invert(&_godot_array);
}
void PoolStringArray::push_back(const String &data) {
void PoolStringArray::push_back(const String& data)
{
godot::api->godot_pool_string_array_push_back(&_godot_array, (godot_string *) &data);
}
void PoolStringArray::remove(const int idx) {
void PoolStringArray::remove(const int idx)
{
godot::api->godot_pool_string_array_remove(&_godot_array, idx);
}
void PoolStringArray::resize(const int size) {
void PoolStringArray::resize(const int size)
{
godot::api->godot_pool_string_array_resize(&_godot_array, size);
}
void PoolStringArray::set(const int idx, const String &data) {
void PoolStringArray::set(const int idx, const String& data)
{
godot::api->godot_pool_string_array_set(&_godot_array, idx, (godot_string *) &data);
}
const String PoolStringArray::operator[](const int idx) {
const String PoolStringArray::operator [](const int idx)
{
String s;
godot_string str = godot::api->godot_pool_string_array_get(&_godot_array, idx);
godot::api->godot_string_new_copy((godot_string *) &s, &str);
@@ -302,240 +376,304 @@ const String PoolStringArray::operator[](const int idx) {
return s;
}
int PoolStringArray::size() const {
int PoolStringArray::size() const
{
return godot::api->godot_pool_string_array_size(&_godot_array);
}
PoolStringArray::~PoolStringArray() {
PoolStringArray::~PoolStringArray()
{
godot::api->godot_pool_string_array_destroy(&_godot_array);
}
PoolVector2Array::PoolVector2Array() {
PoolVector2Array::PoolVector2Array()
{
godot::api->godot_pool_vector2_array_new(&_godot_array);
}
PoolVector2Array::PoolVector2Array(const PoolVector2Array &p_other) {
PoolVector2Array::PoolVector2Array(const PoolVector2Array &p_other)
{
godot::api->godot_pool_vector2_array_new_copy(&_godot_array, &p_other._godot_array);
}
PoolVector2Array &PoolVector2Array::operator=(const PoolVector2Array &p_other) {
PoolVector2Array &PoolVector2Array::operator=(const PoolVector2Array &p_other)
{
godot::api->godot_pool_vector2_array_destroy(&_godot_array);
godot::api->godot_pool_vector2_array_new_copy(&_godot_array, &p_other._godot_array);
return *this;
}
PoolVector2Array::PoolVector2Array(const Array &array) {
PoolVector2Array::PoolVector2Array(const Array& array)
{
godot::api->godot_pool_vector2_array_new_with_array(&_godot_array, (godot_array *) &array);
}
PoolVector2Array::Read PoolVector2Array::read() const {
PoolVector2Array::Read PoolVector2Array::read() const
{
Read read;
read._read_access = godot::api->godot_pool_vector2_array_read(&_godot_array);
return read;
}
PoolVector2Array::Write PoolVector2Array::write() {
PoolVector2Array::Write PoolVector2Array::write()
{
Write write;
write._write_access = godot::api->godot_pool_vector2_array_write(&_godot_array);
return write;
}
void PoolVector2Array::append(const Vector2 &data) {
void PoolVector2Array::append(const Vector2& data)
{
godot::api->godot_pool_vector2_array_append(&_godot_array, (godot_vector2 *) &data);
}
void PoolVector2Array::append_array(const PoolVector2Array &array) {
void PoolVector2Array::append_array(const PoolVector2Array& array)
{
godot::api->godot_pool_vector2_array_append_array(&_godot_array, &array._godot_array);
}
int PoolVector2Array::insert(const int idx, const Vector2 &data) {
int PoolVector2Array::insert(const int idx, const Vector2& data)
{
return godot::api->godot_pool_vector2_array_insert(&_godot_array, idx, (godot_vector2 *) &data);
}
void PoolVector2Array::invert() {
void PoolVector2Array::invert()
{
godot::api->godot_pool_vector2_array_invert(&_godot_array);
}
void PoolVector2Array::push_back(const Vector2 &data) {
void PoolVector2Array::push_back(const Vector2& data)
{
godot::api->godot_pool_vector2_array_push_back(&_godot_array, (godot_vector2 *) &data);
}
void PoolVector2Array::remove(const int idx) {
void PoolVector2Array::remove(const int idx)
{
godot::api->godot_pool_vector2_array_remove(&_godot_array, idx);
}
void PoolVector2Array::resize(const int size) {
void PoolVector2Array::resize(const int size)
{
godot::api->godot_pool_vector2_array_resize(&_godot_array, size);
}
void PoolVector2Array::set(const int idx, const Vector2 &data) {
void PoolVector2Array::set(const int idx, const Vector2& data)
{
godot::api->godot_pool_vector2_array_set(&_godot_array, idx, (godot_vector2 *) &data);
}
const Vector2 PoolVector2Array::operator[](const int idx) {
const Vector2 PoolVector2Array::operator [](const int idx)
{
Vector2 v;
*(godot_vector2 *) &v = godot::api->godot_pool_vector2_array_get(&_godot_array, idx);
return v;
}
int PoolVector2Array::size() const {
int PoolVector2Array::size() const
{
return godot::api->godot_pool_vector2_array_size(&_godot_array);
}
PoolVector2Array::~PoolVector2Array() {
PoolVector2Array::~PoolVector2Array()
{
godot::api->godot_pool_vector2_array_destroy(&_godot_array);
}
PoolVector3Array::PoolVector3Array() {
PoolVector3Array::PoolVector3Array()
{
godot::api->godot_pool_vector3_array_new(&_godot_array);
}
PoolVector3Array::PoolVector3Array(const PoolVector3Array &p_other) {
PoolVector3Array::PoolVector3Array(const PoolVector3Array &p_other)
{
godot::api->godot_pool_vector3_array_new_copy(&_godot_array, &p_other._godot_array);
}
PoolVector3Array &PoolVector3Array::operator=(const PoolVector3Array &p_other) {
PoolVector3Array &PoolVector3Array::operator=(const PoolVector3Array &p_other)
{
godot::api->godot_pool_vector3_array_destroy(&_godot_array);
godot::api->godot_pool_vector3_array_new_copy(&_godot_array, &p_other._godot_array);
return *this;
}
PoolVector3Array::PoolVector3Array(const Array &array) {
PoolVector3Array::PoolVector3Array(const Array& array)
{
godot::api->godot_pool_vector3_array_new_with_array(&_godot_array, (godot_array *) &array);
}
PoolVector3Array::Read PoolVector3Array::read() const {
PoolVector3Array::Read PoolVector3Array::read() const
{
Read read;
read._read_access = godot::api->godot_pool_vector3_array_read(&_godot_array);
return read;
}
PoolVector3Array::Write PoolVector3Array::write() {
PoolVector3Array::Write PoolVector3Array::write()
{
Write write;
write._write_access = godot::api->godot_pool_vector3_array_write(&_godot_array);
return write;
}
void PoolVector3Array::append(const Vector3 &data) {
void PoolVector3Array::append(const Vector3& data)
{
godot::api->godot_pool_vector3_array_append(&_godot_array, (godot_vector3 *) &data);
}
void PoolVector3Array::append_array(const PoolVector3Array &array) {
void PoolVector3Array::append_array(const PoolVector3Array& array)
{
godot::api->godot_pool_vector3_array_append_array(&_godot_array, &array._godot_array);
}
int PoolVector3Array::insert(const int idx, const Vector3 &data) {
int PoolVector3Array::insert(const int idx, const Vector3& data)
{
return godot::api->godot_pool_vector3_array_insert(&_godot_array, idx, (godot_vector3 *) &data);
}
void PoolVector3Array::invert() {
void PoolVector3Array::invert()
{
godot::api->godot_pool_vector3_array_invert(&_godot_array);
}
void PoolVector3Array::push_back(const Vector3 &data) {
void PoolVector3Array::push_back(const Vector3& data)
{
godot::api->godot_pool_vector3_array_push_back(&_godot_array, (godot_vector3 *) &data);
}
void PoolVector3Array::remove(const int idx) {
void PoolVector3Array::remove(const int idx)
{
godot::api->godot_pool_vector3_array_remove(&_godot_array, idx);
}
void PoolVector3Array::resize(const int size) {
void PoolVector3Array::resize(const int size)
{
godot::api->godot_pool_vector3_array_resize(&_godot_array, size);
}
void PoolVector3Array::set(const int idx, const Vector3 &data) {
void PoolVector3Array::set(const int idx, const Vector3& data)
{
godot::api->godot_pool_vector3_array_set(&_godot_array, idx, (godot_vector3 *) &data);
}
const Vector3 PoolVector3Array::operator[](const int idx) {
const Vector3 PoolVector3Array::operator [](const int idx)
{
Vector3 v;
*(godot_vector3 *) &v = godot::api->godot_pool_vector3_array_get(&_godot_array, idx);
return v;
}
int PoolVector3Array::size() const {
int PoolVector3Array::size() const
{
return godot::api->godot_pool_vector3_array_size(&_godot_array);
}
PoolVector3Array::~PoolVector3Array() {
PoolVector3Array::~PoolVector3Array()
{
godot::api->godot_pool_vector3_array_destroy(&_godot_array);
}
PoolColorArray::PoolColorArray() {
PoolColorArray::PoolColorArray()
{
godot::api->godot_pool_color_array_new(&_godot_array);
}
PoolColorArray::PoolColorArray(const PoolColorArray &p_other) {
PoolColorArray::PoolColorArray(const PoolColorArray &p_other)
{
godot::api->godot_pool_color_array_new_copy(&_godot_array, &p_other._godot_array);
}
PoolColorArray &PoolColorArray::operator=(const PoolColorArray &p_other) {
PoolColorArray &PoolColorArray::operator=(const PoolColorArray &p_other)
{
godot::api->godot_pool_color_array_destroy(&_godot_array);
godot::api->godot_pool_color_array_new_copy(&_godot_array, &p_other._godot_array);
return *this;
}
PoolColorArray::PoolColorArray(const Array &array) {
PoolColorArray::PoolColorArray(const Array& array)
{
godot::api->godot_pool_color_array_new_with_array(&_godot_array, (godot_array *) &array);
}
PoolColorArray::Read PoolColorArray::read() const {
PoolColorArray::Read PoolColorArray::read() const
{
Read read;
read._read_access = godot::api->godot_pool_color_array_read(&_godot_array);
return read;
}
PoolColorArray::Write PoolColorArray::write() {
PoolColorArray::Write PoolColorArray::write()
{
Write write;
write._write_access = godot::api->godot_pool_color_array_write(&_godot_array);
return write;
}
void PoolColorArray::append(const Color &data) {
void PoolColorArray::append(const Color& data)
{
godot::api->godot_pool_color_array_append(&_godot_array, (godot_color *) &data);
}
void PoolColorArray::append_array(const PoolColorArray &array) {
void PoolColorArray::append_array(const PoolColorArray& array)
{
godot::api->godot_pool_color_array_append_array(&_godot_array, &array._godot_array);
}
int PoolColorArray::insert(const int idx, const Color &data) {
int PoolColorArray::insert(const int idx, const Color& data)
{
return godot::api->godot_pool_color_array_insert(&_godot_array, idx, (godot_color *) &data);
}
void PoolColorArray::invert() {
void PoolColorArray::invert()
{
godot::api->godot_pool_color_array_invert(&_godot_array);
}
void PoolColorArray::push_back(const Color &data) {
void PoolColorArray::push_back(const Color& data)
{
godot::api->godot_pool_color_array_push_back(&_godot_array, (godot_color *) &data);
}
void PoolColorArray::remove(const int idx) {
void PoolColorArray::remove(const int idx)
{
godot::api->godot_pool_color_array_remove(&_godot_array, idx);
}
void PoolColorArray::resize(const int size) {
void PoolColorArray::resize(const int size)
{
godot::api->godot_pool_color_array_resize(&_godot_array, size);
}
void PoolColorArray::set(const int idx, const Color &data) {
void PoolColorArray::set(const int idx, const Color& data)
{
godot::api->godot_pool_color_array_set(&_godot_array, idx, (godot_color *) &data);
}
const Color PoolColorArray::operator[](const int idx) {
const Color PoolColorArray::operator [](const int idx)
{
Color v;
*(godot_color *) &v = godot::api->godot_pool_color_array_get(&_godot_array, idx);
return v;
}
int PoolColorArray::size() const {
int PoolColorArray::size() const
{
return godot::api->godot_pool_color_array_size(&_godot_array);
}
PoolColorArray::~PoolColorArray() {
PoolColorArray::~PoolColorArray()
{
godot::api->godot_pool_color_array_destroy(&_godot_array);
}
} // namespace godot
}

View File

@@ -1,7 +1,7 @@
#include "Quat.hpp"
#include "Basis.hpp"
#include "Defs.hpp"
#include "Vector3.hpp"
#include "Basis.hpp"
#include <cmath>
@@ -77,19 +77,23 @@ Vector3 Quat::get_euler_yxz() const {
return m.get_euler_yxz();
}
real_t Quat::length() const {
real_t Quat::length() const
{
return ::sqrt(length_squared());
}
void Quat::normalize() {
void Quat::normalize()
{
*this /= length();
}
Quat Quat::normalized() const {
Quat Quat::normalized() const
{
return *this / length();
}
Quat Quat::inverse() const {
Quat Quat::inverse() const
{
return Quat( -x, -y, -z, w );
}
@@ -98,6 +102,7 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
Quat to1;
real_t omega, cosom, sinom, scale0, scale1;
// calc cosine
cosom = dot(q);
@@ -115,6 +120,7 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
to1.w = q.w;
}
// calculate coefficients
if ( (1.0 - cosom) > CMP_EPSILON ) {
@@ -134,7 +140,8 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const {
scale0 * x + scale1 * to1.x,
scale0 * y + scale1 * to1.y,
scale0 * z + scale1 * to1.z,
scale0 * w + scale1 * to1.w);
scale0 * w + scale1 * to1.w
);
}
Quat Quat::slerpni(const Quat& q, const real_t& t) const {
@@ -156,7 +163,8 @@ Quat Quat::slerpni(const Quat &q, const real_t &t) const {
invFactor * from.w + newFactor * q.w);
}
Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const {
Quat Quat::cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const real_t& t) const
{
//the only way to do slerp :|
real_t t2 = (1.0-t)*t*2;
Quat sp = this->slerp(q,t);
@@ -171,7 +179,10 @@ void Quat::get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const {
r_axis.z = z / ::sqrt(1-w*w);
}
Quat Quat::operator*(const Vector3 &v) const {
Quat Quat::operator*(const Vector3& v) const
{
return Quat( w * v.x + y * v.z - z * v.y,
w * v.y + z * v.x - x * v.z,
w * v.z + x * v.y - y * v.x,
@@ -185,11 +196,15 @@ Vector3 Quat::xform(const Vector3 &v) const {
return Vector3(q.x,q.y,q.z);
}
Quat::operator String() const {
Quat::operator String() const
{
return String(); // @Todo
}
Quat::Quat(const Vector3 &axis, const real_t &angle) {
Quat::Quat(const Vector3& axis, const real_t& angle)
{
real_t d = axis.length();
if (d==0)
set(0,0,0,0);
@@ -224,6 +239,7 @@ Quat::Quat(const Vector3 &v0, const Vector3 &v1) // shortest arc
}
}
real_t Quat::dot(const Quat& q) const {
return x * q.x+y * q.y+z * q.z+w * q.w;
}
@@ -233,33 +249,23 @@ real_t Quat::length_squared() const {
}
void Quat::operator+=(const Quat& q) {
x += q.x;
y += q.y;
z += q.z;
w += q.w;
x += q.x; y += q.y; z += q.z; w += q.w;
}
void Quat::operator-=(const Quat& q) {
x -= q.x;
y -= q.y;
z -= q.z;
w -= q.w;
x -= q.x; y -= q.y; z -= q.z; w -= q.w;
}
void Quat::operator*=(const Quat& q) {
x *= q.x;
y *= q.y;
z *= q.z;
w *= q.w;
x *= q.x; y *= q.y; z *= q.z; w *= q.w;
}
void Quat::operator*=(const real_t& s) {
x *= s;
y *= s;
z *= s;
w *= s;
x *= s; y *= s; z *= s; w *= s;
}
void Quat::operator/=(const real_t& s) {
*this *= 1.0 / s;
@@ -281,6 +287,7 @@ Quat Quat::operator*(const Quat &q2) const {
return q1;
}
Quat Quat::operator-() const {
const Quat& q2 = *this;
return Quat( -q2.x, -q2.y, -q2.z, -q2.w);
@@ -294,6 +301,7 @@ Quat Quat::operator/(const real_t &s) const {
return *this * (1.0 / s);
}
bool Quat::operator==(const Quat& p_quat) const {
return x==p_quat.x && y==p_quat.y && z==p_quat.z && w==p_quat.w;
}
@@ -302,4 +310,4 @@ bool Quat::operator!=(const Quat &p_quat) const {
return x!=p_quat.x || y!=p_quat.y || z!=p_quat.z || w!=p_quat.w;
}
} // namespace godot
}

View File

@@ -6,40 +6,50 @@
namespace godot {
RID::RID() {
RID::RID()
{
godot::api->godot_rid_new(&_godot_rid);
}
RID::RID(Object *p) {
RID::RID(Object *p)
{
godot::api->godot_rid_new_with_resource(&_godot_rid, (const godot_object *) p);
}
int32_t RID::get_rid() const {
int32_t RID::get_rid() const
{
return godot::api->godot_rid_get_id(&_godot_rid);
}
bool RID::operator==(const RID &p_other) const {
bool RID::operator==(const RID & p_other) const
{
return godot::api->godot_rid_operator_equal(&_godot_rid, &p_other._godot_rid);
}
bool RID::operator!=(const RID &p_other) const {
bool RID::operator!=(const RID & p_other) const
{
return !(*this == p_other);
}
bool RID::operator<(const RID &p_other) const {
bool RID::operator<(const RID & p_other) const
{
return godot::api->godot_rid_operator_less(&_godot_rid, &p_other._godot_rid);
}
bool RID::operator>(const RID &p_other) const {
bool RID::operator>(const RID & p_other) const
{
return !(*this < p_other) && *this != p_other;
}
bool RID::operator<=(const RID &p_other) const {
bool RID::operator<=(const RID & p_other) const
{
return (*this < p_other) || *this == p_other;
}
bool RID::operator>=(const RID &p_other) const {
bool RID::operator>=(const RID & p_other) const
{
return !(*this < p_other);
}
} // namespace godot
}

View File

@@ -1,7 +1,7 @@
#include "Rect2.hpp"
#include "Vector2.hpp"
#include "String.hpp"
#include "Transform2D.hpp"
#include "Vector2.hpp"
#include <cmath>
@@ -15,21 +15,22 @@ namespace godot {
#define MIN(a, b) (a < b ? a : b)
#endif
real_t Rect2::distance_to(const Vector2& p_point) const {
real_t dist = 1e20;
if (p_point.x < position.x) {
dist = MIN(dist, position.x - p_point.x);
if (p_point.x < pos.x) {
dist=MIN(dist,pos.x-p_point.x);
}
if (p_point.y < position.y) {
dist = MIN(dist, position.y - p_point.y);
if (p_point.y < pos.y) {
dist=MIN(dist,pos.y-p_point.y);
}
if (p_point.x >= (position.x + size.x)) {
dist = MIN(p_point.x - (position.x + size.x), dist);
if (p_point.x >= (pos.x+size.x) ) {
dist=MIN(p_point.x-(pos.x+size.x),dist);
}
if (p_point.y >= (position.y + size.y)) {
dist = MIN(p_point.y - (position.y + size.y), dist);
if (p_point.y >= (pos.y+size.y) ) {
dist=MIN(p_point.y-(pos.y+size.y),dist);
}
if (dist==1e20)
@@ -45,14 +46,14 @@ Rect2 Rect2::clip(const Rect2 &p_rect) const { /// return a clipped rect
if (!intersects( new_rect ))
return Rect2();
new_rect.position.x = MAX(p_rect.position.x, position.x);
new_rect.position.y = MAX(p_rect.position.y, position.y);
new_rect.pos.x = MAX( p_rect.pos.x , pos.x );
new_rect.pos.y = MAX( p_rect.pos.y , pos.y );
Point2 p_rect_end = p_rect.position + p_rect.size;
Point2 end = position + size;
Point2 p_rect_end=p_rect.pos+p_rect.size;
Point2 end=pos+size;
new_rect.size.x = MIN(p_rect_end.x, end.x) - new_rect.position.x;
new_rect.size.y = MIN(p_rect_end.y, end.y) - new_rect.position.y;
new_rect.size.x=MIN(p_rect_end.x,end.x) - new_rect.pos.x;
new_rect.size.y=MIN(p_rect_end.y,end.y) - new_rect.pos.y;
return new_rect;
}
@@ -61,22 +62,27 @@ Rect2 Rect2::merge(const Rect2 &p_rect) const { ///< return a merged rect
Rect2 new_rect;
new_rect.position.x = MIN(p_rect.position.x, position.x);
new_rect.position.y = MIN(p_rect.position.y, position.y);
new_rect.pos.x=MIN( p_rect.pos.x , pos.x );
new_rect.pos.y=MIN( p_rect.pos.y , pos.y );
new_rect.size.x = MAX(p_rect.position.x + p_rect.size.x, position.x + size.x);
new_rect.size.y = MAX(p_rect.position.y + p_rect.size.y, position.y + size.y);
new_rect.size = new_rect.size - new_rect.position; //make relative again
new_rect.size.x = MAX( p_rect.pos.x+p_rect.size.x , pos.x+size.x );
new_rect.size.y = MAX( p_rect.pos.y+p_rect.size.y , pos.y+size.y );
new_rect.size = new_rect.size - new_rect.pos; //make relative again
return new_rect;
}
Rect2::operator String() const {
return String(position) + ", " + String(size);
Rect2::operator String() const
{
return String(pos)+", "+String(size);
}
bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_position, Point2 *r_normal) const {
bool Rect2::intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos,Point2* r_normal) const {
real_t min=0,max=1;
int axis=0;
@@ -85,7 +91,7 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
for(int i=0;i<2;i++) {
real_t seg_from=p_from[i];
real_t seg_to=p_to[i];
real_t box_begin = position[i];
real_t box_begin=pos[i];
real_t box_end=box_begin+size[i];
real_t cmin,cmax;
real_t csign;
@@ -120,6 +126,7 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
return false;
}
Vector2 rel=p_to-p_from;
if (r_normal) {
@@ -128,41 +135,42 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2
*r_normal=normal;
}
if (r_position)
*r_position = p_from + rel * min;
if (r_pos)
*r_pos=p_from+rel*min;
return true;
}
bool Rect2::intersects_transformed(const Transform2D& p_xform, const Rect2& p_rect) const {
//SAT intersection between local and transformed rect2
Vector2 xf_points[4]={
p_xform.xform(p_rect.position),
p_xform.xform(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y)),
p_xform.xform(Vector2(p_rect.position.x, p_rect.position.y + p_rect.size.y)),
p_xform.xform(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y + p_rect.size.y)),
p_xform.xform(p_rect.pos),
p_xform.xform(Vector2(p_rect.pos.x+p_rect.size.x,p_rect.pos.y)),
p_xform.xform(Vector2(p_rect.pos.x,p_rect.pos.y+p_rect.size.y)),
p_xform.xform(Vector2(p_rect.pos.x+p_rect.size.x,p_rect.pos.y+p_rect.size.y)),
};
real_t low_limit;
//base rect2 first (faster)
if (xf_points[0].y > position.y)
if (xf_points[0].y>pos.y)
goto next1;
if (xf_points[1].y > position.y)
if (xf_points[1].y>pos.y)
goto next1;
if (xf_points[2].y > position.y)
if (xf_points[2].y>pos.y)
goto next1;
if (xf_points[3].y > position.y)
if (xf_points[3].y>pos.y)
goto next1;
return false;
next1:
low_limit = position.y + size.y;
low_limit=pos.y+size.y;
if (xf_points[0].y<low_limit)
goto next2;
@@ -177,20 +185,20 @@ next1:
next2:
if (xf_points[0].x > position.x)
if (xf_points[0].x>pos.x)
goto next3;
if (xf_points[1].x > position.x)
if (xf_points[1].x>pos.x)
goto next3;
if (xf_points[2].x > position.x)
if (xf_points[2].x>pos.x)
goto next3;
if (xf_points[3].x > position.x)
if (xf_points[3].x>pos.x)
goto next3;
return false;
next3:
low_limit = position.x + size.x;
low_limit=pos.x+size.x;
if (xf_points[0].x<low_limit)
goto next4;
@@ -206,10 +214,10 @@ next3:
next4:
Vector2 xf_points2[4]={
position,
Vector2(position.x + size.x, position.y),
Vector2(position.x, position.y + size.y),
Vector2(position.x + size.x, position.y + size.y),
pos,
Vector2(pos.x+size.x,pos.y),
Vector2(pos.x,pos.y+size.y),
Vector2(pos.x+size.x,pos.y+size.y),
};
real_t maxa=p_xform.elements[0].dot(xf_points2[0]);
@@ -242,6 +250,7 @@ next4:
maxb=MAX(dp,maxb);
minb=MIN(dp,minb);
if ( mina > maxb )
return false;
if ( minb > maxa )
@@ -277,12 +286,15 @@ next4:
maxb=MAX(dp,maxb);
minb=MIN(dp,minb);
if ( mina > maxb )
return false;
if ( minb > maxa )
return false;
return true;
}
} // namespace godot
}

View File

@@ -1,10 +1,10 @@
#include "String.hpp"
#include "Array.hpp"
#include "GodotGlobal.hpp"
#include "NodePath.hpp"
#include "PoolArrays.hpp"
#include "Variant.hpp"
#include "GodotGlobal.hpp"
#include <gdnative/string.h>
@@ -99,7 +99,7 @@ String::~String() {
}
wchar_t &String::operator[](const int idx) {
return *const_cast<wchar_t *>(godot::api->godot_string_operator_index(&_godot_string, idx));
return *godot::api->godot_string_operator_index(&_godot_string, idx);
}
wchar_t String::operator[](const int idx) const {
@@ -256,15 +256,15 @@ void String::erase(int position, int chars) {
}
int String::find(String p_what, int p_from) const {
return godot::api->godot_string_find_from(&_godot_string, p_what._godot_string, p_from);
return godot::api->godot_string_find(&_godot_string, p_what._godot_string);
}
int String::find_last(String p_what) const {
return godot::api->godot_string_find_last(&_godot_string, p_what._godot_string);
int String::find_last(String what) const {
return godot::api->godot_string_find_last(&_godot_string, what._godot_string);
}
int String::findn(String p_what, int p_from) const {
return godot::api->godot_string_findn_from(&_godot_string, p_what._godot_string, p_from);
int String::findn(String what, int from) const {
return godot::api->godot_string_findn(&_godot_string, what._godot_string);
}
String String::format(Variant values) const {
@@ -443,12 +443,13 @@ String String::replacen(String what, String forwhat) const {
return new_string;
}
int String::rfind(String p_what, int p_from) const {
return godot::api->godot_string_rfind_from(&_godot_string, p_what._godot_string, p_from);
int String::rfind(String what, int from) const {
return godot::api->godot_string_rfind(&_godot_string, what._godot_string);
}
int String::rfindn(String p_what, int p_from) const {
return godot::api->godot_string_rfindn_from(&_godot_string, p_what._godot_string, p_from);
int String::rfindn(String what, int from) const {
// From -1
return godot::api->godot_string_rfindn(&_godot_string, what._godot_string);
}
String String::right(int position) const {
@@ -542,17 +543,4 @@ String String::xml_unescape() const {
return new_string;
}
signed char String::casecmp_to(String p_str) const {
return godot::api->godot_string_casecmp_to(&_godot_string, &p_str._godot_string);
}
signed char String::nocasecmp_to(String p_str) const {
return godot::api->godot_string_nocasecmp_to(&_godot_string, &p_str._godot_string);
}
signed char String::naturalnocasecmp_to(String p_str) const {
return godot::api->godot_string_naturalnocasecmp_to(&_godot_string, &p_str._godot_string);
}
} // namespace godot

View File

@@ -10,25 +10,29 @@ namespace _TagDB {
std::unordered_map<size_t, size_t> parent_to;
void register_type(size_t type_tag, size_t base_type_tag) {
void register_type(size_t type_tag, size_t base_type_tag)
{
if (type_tag == base_type_tag) {
return;
}
parent_to[type_tag] = base_type_tag;
}
bool is_type_known(size_t type_tag) {
bool is_type_known(size_t type_tag)
{
return parent_to.find(type_tag) != parent_to.end();
}
void register_global_type(const char *name, size_t type_tag, size_t base_type_tag) {
void register_global_type(const char *name, size_t type_tag, size_t base_type_tag)
{
godot::nativescript_1_1_api->godot_nativescript_set_global_type_tag(godot::_RegisterState::language_index, name, (const void *) type_tag);
register_type(type_tag, base_type_tag);
}
bool is_type_compatible(size_t ask_tag, size_t have_tag) {
bool is_type_compatible(size_t ask_tag, size_t have_tag)
{
if (have_tag == 0)
return false;
@@ -45,6 +49,7 @@ bool is_type_compatible(size_t ask_tag, size_t have_tag) {
return false;
}
} // namespace _TagDB
}
} // namespace godot
}

View File

@@ -2,13 +2,15 @@
#include "Basis.hpp"
#include "AABB.hpp"
#include "Plane.hpp"
#include "AABB.hpp"
#include "Quat.hpp"
namespace godot {
Transform Transform::inverse_xform(const Transform& t) const {
Vector3 v = t.origin - origin;
@@ -32,12 +34,15 @@ void Transform::set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_
origin.z=tz;
}
Vector3 Transform::xform(const Vector3& p_vector) const {
return Vector3(
basis[0].dot(p_vector)+origin.x,
basis[1].dot(p_vector)+origin.y,
basis[2].dot(p_vector) + origin.z);
basis[2].dot(p_vector)+origin.z
);
}
Vector3 Transform::xform_inv(const Vector3& p_vector) const {
@@ -46,11 +51,13 @@ Vector3 Transform::xform_inv(const Vector3 &p_vector) const {
return Vector3(
(basis.elements[0][0]*v.x ) + ( basis.elements[1][0]*v.y ) + ( basis.elements[2][0]*v.z ),
(basis.elements[0][1]*v.x ) + ( basis.elements[1][1]*v.y ) + ( basis.elements[2][1]*v.z ),
(basis.elements[0][2] * v.x) + (basis.elements[1][2] * v.y) + (basis.elements[2][2] * v.z));
(basis.elements[0][2]*v.x ) + ( basis.elements[1][2]*v.y ) + ( basis.elements[2][2]*v.z )
);
}
Plane Transform::xform(const Plane& p_plane) const {
Vector3 point=p_plane.normal*p_plane.d;
Vector3 point_dir=point+p_plane.normal;
point=xform(point);
@@ -61,19 +68,21 @@ Plane Transform::xform(const Plane &p_plane) const {
real_t d=normal.dot(point);
return Plane(normal,d);
}
Plane Transform::xform_inv(const Plane& p_plane) const {
Vector3 point=p_plane.normal*p_plane.d;
Vector3 point_dir=point+p_plane.normal;
point = xform_inv(point);
point_dir = xform_inv(point_dir);
xform_inv(point);
xform_inv(point_dir);
Vector3 normal=point_dir-point;
normal.normalize();
real_t d=normal.dot(point);
return Plane(normal,d);
}
AABB Transform::xform(const AABB& p_aabb) const {
@@ -93,6 +102,7 @@ AABB Transform::xform(const AABB &p_aabb) const {
new_aabb.expand_to( pos+y+z );
new_aabb.expand_to( pos+x+y+z );
return new_aabb;
}
AABB Transform::xform_inv(const AABB& p_aabb) const {
@@ -108,6 +118,7 @@ AABB Transform::xform_inv(const AABB &p_aabb) const {
Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z)
};
AABB ret;
ret.position=xform_inv(vertices[0]);
@@ -118,6 +129,7 @@ AABB Transform::xform_inv(const AABB &p_aabb) const {
}
return ret;
}
void Transform::affine_invert() {
@@ -131,8 +143,10 @@ Transform Transform::affine_inverse() const {
Transform ret=*this;
ret.affine_invert();
return ret;
}
void Transform::invert() {
basis.transpose();
@@ -147,6 +161,7 @@ Transform Transform::inverse() const {
return ret;
}
void Transform::rotate(const Vector3& p_axis,real_t p_phi) {
*this = rotated(p_axis, p_phi);
@@ -183,6 +198,7 @@ void Transform::set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const
v_y = p_up;
v_x=v_y.cross(v_z);
/* Recompute Y = Z cross X */
@@ -195,6 +211,7 @@ void Transform::set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const
basis.set_axis(1,v_y);
basis.set_axis(2,v_z);
origin=p_eye;
}
Transform Transform::interpolate_with(const Transform& p_transform, real_t p_c) const {
@@ -237,6 +254,7 @@ void Transform::scale_basis(const Vector3 &p_scale) {
void Transform::translate( real_t p_tx, real_t p_ty, real_t p_tz) {
translate( Vector3(p_tx,p_ty,p_tz) );
}
void Transform::translate( const Vector3& p_translation ) {
@@ -291,10 +309,11 @@ Transform::operator String() const {
return basis.operator String() + " - " + origin.operator String();
}
Transform::Transform(const Basis& p_basis, const Vector3& p_origin) {
basis=p_basis;
origin=p_origin;
}
} // namespace godot
}

View File

@@ -1,7 +1,7 @@
#include "Transform2D.hpp"
#include "Rect2.hpp"
#include "String.hpp"
#include "Vector2.hpp"
#include "String.hpp"
#include "Rect2.hpp"
#include <algorithm>
@@ -17,26 +17,30 @@ Transform2D::Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox,
elements[2][1] = oy;
}
Vector2 Transform2D::basis_xform(const Vector2& v) const {
return Vector2(
tdotx(v),
tdoty(v));
tdoty(v)
);
}
Vector2 Transform2D::basis_xform_inv(const Vector2& v) const{
return Vector2(
elements[0].dot(v),
elements[1].dot(v));
elements[1].dot(v)
);
}
Vector2 Transform2D::xform(const Vector2& v) const {
return Vector2(
tdotx(v),
tdoty(v)) +
elements[2];
tdoty(v)
) + elements[2];
}
Vector2 Transform2D::xform_inv(const Vector2& p_vec) const {
@@ -44,19 +48,21 @@ Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const {
return Vector2(
elements[0].dot(v),
elements[1].dot(v));
elements[1].dot(v)
);
}
Rect2 Transform2D::xform(const Rect2& p_rect) const {
Vector2 x=elements[0]*p_rect.size.x;
Vector2 y=elements[1]*p_rect.size.y;
Vector2 position = xform(p_rect.position);
Vector2 pos = xform( p_rect.pos );
Rect2 new_rect;
new_rect.position = position;
new_rect.expand_to(position + x);
new_rect.expand_to(position + y);
new_rect.expand_to(position + x + y);
new_rect.pos=pos;
new_rect.expand_to( pos+x );
new_rect.expand_to( pos+y );
new_rect.expand_to( pos+x+y );
return new_rect;
}
@@ -66,19 +72,20 @@ void Transform2D::set_rotation_and_scale(real_t p_rot, const Size2 &p_scale) {
elements[1][1]=::cos(p_rot)*p_scale.y;
elements[1][0]=-::sin(p_rot)*p_scale.y;
elements[0][1]=::sin(p_rot)*p_scale.x;
}
Rect2 Transform2D::xform_inv(const Rect2& p_rect) const {
Vector2 ends[4]={
xform_inv(p_rect.position),
xform_inv(Vector2(p_rect.position.x, p_rect.position.y + p_rect.size.y)),
xform_inv(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y + p_rect.size.y)),
xform_inv(Vector2(p_rect.position.x + p_rect.size.x, p_rect.position.y))
xform_inv( p_rect.pos ),
xform_inv( Vector2(p_rect.pos.x,p_rect.pos.y+p_rect.size.y ) ),
xform_inv( Vector2(p_rect.pos.x+p_rect.size.x,p_rect.pos.y+p_rect.size.y ) ),
xform_inv( Vector2(p_rect.pos.x+p_rect.size.x,p_rect.pos.y ) )
};
Rect2 new_rect;
new_rect.position = ends[0];
new_rect.pos=ends[0];
new_rect.expand_to(ends[1]);
new_rect.expand_to(ends[2]);
new_rect.expand_to(ends[3]);
@@ -98,6 +105,7 @@ Transform2D Transform2D::inverse() const {
Transform2D inv=*this;
inv.invert();
return inv;
}
void Transform2D::affine_invert() {
@@ -111,6 +119,7 @@ void Transform2D::affine_invert() {
elements[1]*=Vector2(-idet,idet);
elements[2] = basis_xform(-elements[2]);
}
Transform2D Transform2D::affine_inverse() const {
@@ -143,7 +152,7 @@ void Transform2D::set_rotation(real_t p_rot) {
elements[1][1]=cr;
}
Transform2D::Transform2D(real_t p_rot, const Vector2 &p_position) {
Transform2D::Transform2D(real_t p_rot, const Vector2& p_pos) {
real_t cr = ::cos(p_rot);
real_t sr = ::sin(p_rot);
@@ -151,7 +160,7 @@ Transform2D::Transform2D(real_t p_rot, const Vector2 &p_position) {
elements[0][1]=sr;
elements[1][0]=-sr;
elements[1][1]=cr;
elements[2] = p_position;
elements[2]=p_pos;
}
Size2 Transform2D::get_scale() const {
@@ -169,6 +178,7 @@ void Transform2D::scale_basis(const Size2 &p_scale) {
elements[0][1]*=p_scale.y;
elements[1][0]*=p_scale.x;
elements[1][1]*=p_scale.y;
}
void Transform2D::translate( real_t p_tx, real_t p_ty) {
@@ -198,6 +208,7 @@ Transform2D Transform2D::orthonormalized() const {
Transform2D on=*this;
on.orthonormalize();
return on;
}
bool Transform2D::operator==(const Transform2D& p_transform) const {
@@ -218,6 +229,7 @@ bool Transform2D::operator!=(const Transform2D &p_transform) const {
}
return false;
}
void Transform2D::operator*=(const Transform2D& p_transform) {
@@ -237,11 +249,13 @@ void Transform2D::operator*=(const Transform2D &p_transform) {
elements[1][1]=y1;
}
Transform2D Transform2D::operator*(const Transform2D& p_transform) const {
Transform2D t = *this;
t*=p_transform;
return t;
}
Transform2D Transform2D::scaled(const Size2& p_scale) const {
@@ -249,6 +263,7 @@ Transform2D Transform2D::scaled(const Size2 &p_scale) const {
Transform2D copy=*this;
copy.scale(p_scale);
return copy;
}
Transform2D Transform2D::basis_scaled(const Size2& p_scale) const {
@@ -256,6 +271,7 @@ Transform2D Transform2D::basis_scaled(const Size2 &p_scale) const {
Transform2D copy=*this;
copy.scale_basis(p_scale);
return copy;
}
Transform2D Transform2D::untranslated() const {
@@ -270,6 +286,7 @@ Transform2D Transform2D::translated(const Vector2 &p_offset) const {
Transform2D copy=*this;
copy.translate(p_offset);
return copy;
}
Transform2D Transform2D::rotated(real_t p_phi) const {
@@ -277,6 +294,7 @@ Transform2D Transform2D::rotated(real_t p_phi) const {
Transform2D copy=*this;
copy.rotate(p_phi);
return copy;
}
real_t Transform2D::basis_determinant() const {
@@ -325,4 +343,4 @@ Transform2D::operator String() const {
return String(String() + elements[0] + ", " + elements[1] + ", " + elements[2]);
}
} // namespace godot
}

View File

@@ -2,8 +2,8 @@
#include <gdnative/variant.h>
#include "CoreTypes.hpp"
#include "Defs.hpp"
#include "CoreTypes.hpp"
#include "GodotGlobal.hpp"
#include "Object.hpp"
@@ -11,15 +11,18 @@
namespace godot {
Variant::Variant() {
Variant::Variant()
{
godot::api->godot_variant_new_nil(&_godot_variant);
}
Variant::Variant(const Variant &v) {
Variant::Variant(const Variant& v)
{
godot::api->godot_variant_new_copy(&_godot_variant, &v._godot_variant);
}
Variant::Variant(bool p_bool) {
Variant::Variant(bool p_bool)
{
godot::api->godot_variant_new_bool(&_godot_variant, p_bool);
}
@@ -28,7 +31,8 @@ Variant::Variant(signed int p_int) // real one
godot::api->godot_variant_new_int(&_godot_variant, p_int);
}
Variant::Variant(unsigned int p_int) {
Variant::Variant(unsigned int p_int)
{
godot::api->godot_variant_new_uint(&_godot_variant, p_int);
}
@@ -37,262 +41,326 @@ Variant::Variant(signed short p_short) // real one
godot::api->godot_variant_new_int(&_godot_variant, (int) p_short);
}
Variant::Variant(int64_t p_char) // real one
{
godot::api->godot_variant_new_int(&_godot_variant, p_char);
}
Variant::Variant(uint64_t p_char) {
Variant::Variant(uint64_t p_char)
{
godot::api->godot_variant_new_uint(&_godot_variant, p_char);
}
Variant::Variant(float p_float) {
Variant::Variant(float p_float)
{
godot::api->godot_variant_new_real(&_godot_variant, p_float);
}
Variant::Variant(double p_double) {
Variant::Variant(double p_double)
{
godot::api->godot_variant_new_real(&_godot_variant, p_double);
}
Variant::Variant(const String &p_string) {
Variant::Variant(const String& p_string)
{
godot::api->godot_variant_new_string(&_godot_variant, (godot_string *) &p_string);
}
Variant::Variant(const char *const p_cstring) {
Variant::Variant(const char * const p_cstring)
{
String s = String(p_cstring);
godot::api->godot_variant_new_string(&_godot_variant, (godot_string *) &s);
}
Variant::Variant(const wchar_t *p_wstring) {
Variant::Variant(const wchar_t * p_wstring)
{
String s = p_wstring;
godot::api->godot_variant_new_string(&_godot_variant, (godot_string *) &s);
}
Variant::Variant(const Vector2 &p_vector2) {
Variant::Variant(const Vector2& p_vector2)
{
godot::api->godot_variant_new_vector2(&_godot_variant, (godot_vector2 *) &p_vector2);
}
Variant::Variant(const Rect2 &p_rect2) {
Variant::Variant(const Rect2& p_rect2)
{
godot::api->godot_variant_new_rect2(&_godot_variant, (godot_rect2 *) &p_rect2);
}
Variant::Variant(const Vector3 &p_vector3) {
Variant::Variant(const Vector3& p_vector3)
{
godot::api->godot_variant_new_vector3(&_godot_variant, (godot_vector3 *) &p_vector3);
}
Variant::Variant(const Plane &p_plane) {
Variant::Variant(const Plane& p_plane)
{
godot::api->godot_variant_new_plane(&_godot_variant, (godot_plane *) &p_plane);
}
Variant::Variant(const AABB &p_aabb) {
Variant::Variant(const AABB& p_aabb)
{
godot::api->godot_variant_new_aabb(&_godot_variant, (godot_aabb *) &p_aabb);
}
Variant::Variant(const Quat &p_quat) {
Variant::Variant(const Quat& p_quat)
{
godot::api->godot_variant_new_quat(&_godot_variant, (godot_quat *) &p_quat);
}
Variant::Variant(const Basis &p_transform) {
Variant::Variant(const Basis& p_transform)
{
godot::api->godot_variant_new_basis(&_godot_variant, (godot_basis *) &p_transform);
}
Variant::Variant(const Transform2D &p_transform) {
Variant::Variant(const Transform2D& p_transform)
{
godot::api->godot_variant_new_transform2d(&_godot_variant, (godot_transform2d *) &p_transform);
}
Variant::Variant(const Transform &p_transform) {
Variant::Variant(const Transform& p_transform)
{
godot::api->godot_variant_new_transform(&_godot_variant, (godot_transform *) &p_transform);
}
Variant::Variant(const Color &p_color) {
Variant::Variant(const Color& p_color)
{
godot::api->godot_variant_new_color(&_godot_variant, (godot_color *) &p_color);
}
Variant::Variant(const NodePath &p_path) {
Variant::Variant(const NodePath& p_path)
{
godot::api->godot_variant_new_node_path(&_godot_variant, (godot_node_path *) &p_path);
}
Variant::Variant(const RID &p_rid) {
Variant::Variant(const RID& p_rid)
{
godot::api->godot_variant_new_rid(&_godot_variant, (godot_rid *) &p_rid);
}
Variant::Variant(const Object *p_object) {
if (p_object)
Variant::Variant(const Object* p_object)
{
godot::api->godot_variant_new_object(&_godot_variant, p_object->_owner);
else
godot::api->godot_variant_new_nil(&_godot_variant);
}
Variant::Variant(const Dictionary &p_dictionary) {
Variant::Variant(const Dictionary& p_dictionary)
{
godot::api->godot_variant_new_dictionary(&_godot_variant, (godot_dictionary *) &p_dictionary);
}
Variant::Variant(const Array &p_array) {
Variant::Variant(const Array& p_array)
{
godot::api->godot_variant_new_array(&_godot_variant, (godot_array *) &p_array);
}
Variant::Variant(const PoolByteArray &p_raw_array) {
Variant::Variant(const PoolByteArray& p_raw_array)
{
godot::api->godot_variant_new_pool_byte_array(&_godot_variant, (godot_pool_byte_array *) &p_raw_array);
}
Variant::Variant(const PoolIntArray &p_int_array) {
Variant::Variant(const PoolIntArray& p_int_array)
{
godot::api->godot_variant_new_pool_int_array(&_godot_variant, (godot_pool_int_array *) &p_int_array);
}
Variant::Variant(const PoolRealArray &p_real_array) {
Variant::Variant(const PoolRealArray& p_real_array)
{
godot::api->godot_variant_new_pool_real_array(&_godot_variant, (godot_pool_real_array *) &p_real_array);
}
Variant::Variant(const PoolStringArray &p_string_array) {
Variant::Variant(const PoolStringArray& p_string_array)
{
godot::api->godot_variant_new_pool_string_array(&_godot_variant, (godot_pool_string_array *) &p_string_array);
}
Variant::Variant(const PoolVector2Array &p_vector2_array) {
Variant::Variant(const PoolVector2Array& p_vector2_array)
{
godot::api->godot_variant_new_pool_vector2_array(&_godot_variant, (godot_pool_vector2_array *) &p_vector2_array);
}
Variant::Variant(const PoolVector3Array &p_vector3_array) {
Variant::Variant(const PoolVector3Array& p_vector3_array)
{
godot::api->godot_variant_new_pool_vector3_array(&_godot_variant, (godot_pool_vector3_array *) &p_vector3_array);
}
Variant::Variant(const PoolColorArray &p_color_array) {
Variant::Variant(const PoolColorArray& p_color_array)
{
godot::api->godot_variant_new_pool_color_array(&_godot_variant, (godot_pool_color_array *) &p_color_array);
}
Variant &Variant::operator=(const Variant &v) {
Variant &Variant::operator =(const Variant& v)
{
godot::api->godot_variant_new_copy(&_godot_variant, &v._godot_variant);
return *this;
}
Variant::operator bool() const {
Variant::operator bool() const
{
return booleanize();
}
Variant::operator signed int() const {
Variant::operator signed int() const
{
return godot::api->godot_variant_as_int(&_godot_variant);
}
Variant::operator unsigned int() const // this is the real one
{
return godot::api->godot_variant_as_uint(&_godot_variant);
}
Variant::operator signed short() const {
Variant::operator signed short() const
{
return godot::api->godot_variant_as_int(&_godot_variant);
}
Variant::operator unsigned short() const {
Variant::operator unsigned short() const
{
return godot::api->godot_variant_as_uint(&_godot_variant);
}
Variant::operator signed char() const {
Variant::operator signed char() const
{
return godot::api->godot_variant_as_int(&_godot_variant);
}
Variant::operator unsigned char() const {
Variant::operator unsigned char() const
{
return godot::api->godot_variant_as_uint(&_godot_variant);
}
Variant::operator int64_t() const {
Variant::operator int64_t() const
{
return godot::api->godot_variant_as_int(&_godot_variant);
}
Variant::operator uint64_t() const {
Variant::operator uint64_t() const
{
return godot::api->godot_variant_as_uint(&_godot_variant);
}
Variant::operator wchar_t() const {
Variant::operator wchar_t() const
{
return godot::api->godot_variant_as_int(&_godot_variant);
}
Variant::operator float() const {
Variant::operator float() const
{
return godot::api->godot_variant_as_real(&_godot_variant);
}
Variant::operator double() const {
Variant::operator double() const
{
return godot::api->godot_variant_as_real(&_godot_variant);
}
Variant::operator String() const {
Variant::operator String() const
{
godot_string s = godot::api->godot_variant_as_string(&_godot_variant);
return *(String *) &s;
}
Variant::operator Vector2() const {
Variant::operator Vector2() const
{
godot_vector2 s = godot::api->godot_variant_as_vector2(&_godot_variant);
return *(Vector2 *) &s;
}
Variant::operator Rect2() const {
Variant::operator Rect2() const
{
godot_rect2 s = godot::api->godot_variant_as_rect2(&_godot_variant);
return *(Rect2 *) &s;
}
Variant::operator Vector3() const {
Variant::operator Vector3() const
{
godot_vector3 s = godot::api->godot_variant_as_vector3(&_godot_variant);
return *(Vector3 *) &s;
}
Variant::operator Plane() const {
Variant::operator Plane() const
{
godot_plane s = godot::api->godot_variant_as_plane(&_godot_variant);
return *(Plane *) &s;
}
Variant::operator AABB() const {
Variant::operator AABB() const
{
godot_aabb s = godot::api->godot_variant_as_aabb(&_godot_variant);
return *(AABB *) &s;
}
Variant::operator Quat() const {
Variant::operator Quat() const
{
godot_quat s = godot::api->godot_variant_as_quat(&_godot_variant);
return *(Quat *) &s;
}
Variant::operator Basis() const {
Variant::operator Basis() const
{
godot_basis s = godot::api->godot_variant_as_basis(&_godot_variant);
return *(Basis *) &s;
}
Variant::operator Transform() const {
Variant::operator Transform() const
{
godot_transform s = godot::api->godot_variant_as_transform(&_godot_variant);
return *(Transform *) &s;
}
Variant::operator Transform2D() const {
Variant::operator Transform2D() const
{
godot_transform2d s = godot::api->godot_variant_as_transform2d(&_godot_variant);
return *(Transform2D *) &s;
}
Variant::operator Color() const {
Variant::operator Color() const
{
godot_color s = godot::api->godot_variant_as_color(&_godot_variant);
return *(Color *) &s;
}
Variant::operator NodePath() const {
Variant::operator NodePath() const
{
godot_node_path s = godot::api->godot_variant_as_node_path(&_godot_variant);
return *(NodePath *) &s;
}
Variant::operator RID() const {
Variant::operator RID() const
{
godot_rid s = godot::api->godot_variant_as_rid(&_godot_variant);
return *(RID *) &s;
}
Variant::operator Dictionary() const {
Variant::operator Dictionary() const
{
godot_dictionary d = godot::api->godot_variant_as_dictionary(&_godot_variant);
return *(Dictionary *) &d;
}
Variant::operator Array() const {
Variant::operator Array() const
{
godot_array s = godot::api->godot_variant_as_array(&_godot_variant);
return *(Array *) &s;
}
Variant::operator PoolByteArray() const {
Variant::operator PoolByteArray() const
{
godot_pool_byte_array s = godot::api->godot_variant_as_pool_byte_array(&_godot_variant);
return *(PoolByteArray *) &s;
}
Variant::operator PoolIntArray() const {
Variant::operator PoolIntArray() const
{
godot_pool_int_array s = godot::api->godot_variant_as_pool_int_array(&_godot_variant);
return *(PoolIntArray *) &s;
}
Variant::operator PoolRealArray() const {
Variant::operator PoolRealArray() const
{
godot_pool_real_array s = godot::api->godot_variant_as_pool_real_array(&_godot_variant);
return *(PoolRealArray *) &s;
}
Variant::operator PoolStringArray() const {
Variant::operator PoolStringArray() const
{
godot_pool_string_array s = godot::api->godot_variant_as_pool_string_array(&_godot_variant);
return *(PoolStringArray *) &s;
}
Variant::operator PoolVector2Array() const {
Variant::operator PoolVector2Array() const
{
godot_pool_vector2_array s = godot::api->godot_variant_as_pool_vector2_array(&_godot_variant);
return *(PoolVector2Array *) &s;
}
Variant::operator PoolVector3Array() const {
Variant::operator PoolVector3Array() const
{
godot_pool_vector3_array s = godot::api->godot_variant_as_pool_vector3_array(&_godot_variant);
return *(PoolVector3Array *) &s;
}
Variant::operator PoolColorArray() const {
Variant::operator PoolColorArray() const
{
godot_pool_color_array s = godot::api->godot_variant_as_pool_color_array(&_godot_variant);
return *(PoolColorArray *) &s;
}
@@ -300,54 +368,70 @@ Variant::operator godot_object *() const {
return godot::api->godot_variant_as_object(&_godot_variant);
}
Variant::Type Variant::get_type() const {
Variant::Type Variant::get_type() const
{
return (Type) godot::api->godot_variant_get_type(&_godot_variant);
}
Variant Variant::call(const String &method, const Variant **args, const int arg_count) {
Variant Variant::call(const String& method, const Variant **args, const int arg_count)
{
Variant v;
*(godot_variant *) &v = godot::api->godot_variant_call(&_godot_variant, (godot_string *) &method, (const godot_variant **)args, arg_count, nullptr);
return v;
}
bool Variant::has_method(const String &method) {
bool Variant::has_method(const String& method)
{
return godot::api->godot_variant_has_method(&_godot_variant, (godot_string *) &method);
}
bool Variant::operator==(const Variant &b) const {
bool Variant::operator ==(const Variant& b) const
{
return godot::api->godot_variant_operator_equal(&_godot_variant, &b._godot_variant);
}
bool Variant::operator!=(const Variant &b) const {
bool Variant::operator !=(const Variant& b) const
{
return !(*this == b);
}
bool Variant::operator<(const Variant &b) const {
bool Variant::operator <(const Variant& b) const
{
return godot::api->godot_variant_operator_less(&_godot_variant, &b._godot_variant);
}
bool Variant::operator<=(const Variant &b) const {
bool Variant::operator <=(const Variant& b) const
{
return (*this < b) || (*this == b);
}
bool Variant::operator>(const Variant &b) const {
bool Variant::operator >(const Variant& b) const
{
return !(*this <= b);
}
bool Variant::operator>=(const Variant &b) const {
bool Variant::operator >=(const Variant& b) const
{
return !(*this < b);
}
bool Variant::hash_compare(const Variant &b) const {
bool Variant::hash_compare(const Variant& b) const
{
return godot::api->godot_variant_hash_compare(&_godot_variant, &b._godot_variant);
}
bool Variant::booleanize() const {
bool Variant::booleanize() const
{
return godot::api->godot_variant_booleanize(&_godot_variant);
}
Variant::~Variant() {
Variant::~Variant()
{
godot::api->godot_variant_destroy(&_godot_variant);
}
} // namespace godot
}

View File

@@ -8,123 +8,150 @@
namespace godot {
Vector2 Vector2::operator+(const Vector2 &p_v) const {
Vector2 Vector2::operator+(const Vector2& p_v) const
{
return Vector2(x + p_v.x, y + p_v.y);
}
void Vector2::operator+=(const Vector2 &p_v) {
void Vector2::operator+=(const Vector2& p_v)
{
x += p_v.x;
y += p_v.y;
}
Vector2 Vector2::operator-(const Vector2 &p_v) const {
Vector2 Vector2::operator-(const Vector2& p_v) const
{
return Vector2(x - p_v.x, y - p_v.y);
}
void Vector2::operator-=(const Vector2 &p_v) {
void Vector2::operator-=(const Vector2& p_v)
{
x -= p_v.x;
y -= p_v.y;
}
Vector2 Vector2::operator*(const Vector2 &p_v1) const {
Vector2 Vector2::operator*(const Vector2 &p_v1) const
{
return Vector2(x * p_v1.x, y * p_v1.y);
}
Vector2 Vector2::operator*(const real_t &rvalue) const {
Vector2 Vector2::operator*(const real_t &rvalue) const
{
return Vector2(x * rvalue, y * rvalue);
}
void Vector2::operator*=(const real_t &rvalue) {
void Vector2::operator*=(const real_t &rvalue)
{
x *= rvalue;
y *= rvalue;
}
Vector2 Vector2::operator/(const Vector2 &p_v1) const {
Vector2 Vector2::operator/(const Vector2 &p_v1) const
{
return Vector2(x / p_v1.x, y / p_v1.y);
}
Vector2 Vector2::operator/(const real_t &rvalue) const {
Vector2 Vector2::operator/(const real_t &rvalue) const
{
return Vector2(x / rvalue, y / rvalue);
}
void Vector2::operator/=(const real_t &rvalue) {
void Vector2::operator/=(const real_t &rvalue)
{
x /= rvalue;
y /= rvalue;
}
Vector2 Vector2::operator-() const {
Vector2 Vector2::operator-() const
{
return Vector2(-x, -y);
}
bool Vector2::operator==(const Vector2 &p_vec2) const {
bool Vector2::operator==(const Vector2& p_vec2) const
{
return x == p_vec2.x && y == p_vec2.y;
}
bool Vector2::operator!=(const Vector2 &p_vec2) const {
bool Vector2::operator!=(const Vector2& p_vec2) const
{
return x != p_vec2.x || y != p_vec2.y;
}
void Vector2::normalize() {
void Vector2::normalize()
{
real_t l = x*x + y*y;
if (l != 0) {
l = sqrt(l);
l = (l);
x /= l;
y /= l;
}
}
Vector2 Vector2::normalized() const {
Vector2 Vector2::normalized() const
{
Vector2 v = *this;
v.normalize();
return v;
}
real_t Vector2::length() const {
real_t Vector2::length() const
{
return sqrt(x*x + y*y);
}
real_t Vector2::length_squared() const {
real_t Vector2::length_squared() const
{
return x*x + y*y;
}
real_t Vector2::distance_to(const Vector2 &p_vector2) const {
real_t Vector2::distance_to(const Vector2& p_vector2) const
{
return sqrt((x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y));
}
real_t Vector2::distance_squared_to(const Vector2 &p_vector2) const {
real_t Vector2::distance_squared_to(const Vector2& p_vector2) const
{
return (x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y);
}
real_t Vector2::angle_to(const Vector2 &p_vector2) const {
real_t Vector2::angle_to(const Vector2& p_vector2) const
{
return atan2(cross(p_vector2), dot(p_vector2));
}
real_t Vector2::angle_to_point(const Vector2 &p_vector2) const {
real_t Vector2::angle_to_point(const Vector2& p_vector2) const
{
return atan2(y - p_vector2.y, x-p_vector2.x);
}
real_t Vector2::dot(const Vector2 &p_other) const {
real_t Vector2::dot(const Vector2& p_other) const
{
return x * p_other.x + y * p_other.y;
}
real_t Vector2::cross(const Vector2 &p_other) const {
real_t Vector2::cross(const Vector2& p_other) const
{
return x * p_other.y - y * p_other.x;
}
Vector2 Vector2::cross(real_t p_other) const {
Vector2 Vector2::cross(real_t p_other) const
{
return Vector2(p_other * y, -p_other * x);
}
Vector2 Vector2::project(const Vector2 &p_vec) const {
Vector2 Vector2::project(const Vector2& p_vec) const
{
Vector2 v1 = p_vec;
Vector2 v2 = *this;
return v2 * (v1.dot(v2) / v2.dot(v2));
}
Vector2 Vector2::plane_project(real_t p_d, const Vector2 &p_vec) const {
Vector2 Vector2::plane_project(real_t p_d, const Vector2& p_vec) const
{
return p_vec - *this * ( dot(p_vec) -p_d);
}
Vector2 Vector2::clamped(real_t p_len) const {
Vector2 Vector2::clamped(real_t p_len) const
{
real_t l = length();
Vector2 v = *this;
if (l > 0 && p_len < l) {
@@ -134,20 +161,24 @@ Vector2 Vector2::clamped(real_t p_len) const {
return v;
}
Vector2 Vector2::linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t) {
Vector2 Vector2::linear_interpolate(const Vector2& p_a, const Vector2& p_b,real_t p_t)
{
Vector2 res=p_a;
res.x+= (p_t * (p_b.x-p_a.x));
res.y+= (p_t * (p_b.y-p_a.y));
return res;
}
Vector2 Vector2::linear_interpolate(const Vector2 &p_b, real_t p_t) const {
Vector2 Vector2::linear_interpolate(const Vector2& p_b,real_t p_t) const
{
Vector2 res=*this;
res.x+= (p_t * (p_b.x-x));
res.y+= (p_t * (p_b.y-y));
return res;
}
Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const {
Vector2 Vector2::cubic_interpolate(const Vector2& p_b,const Vector2& p_pre_a, const Vector2& p_post_b,real_t p_t) const
{
Vector2 p0=p_pre_a;
Vector2 p1=*this;
Vector2 p2=p_b;
@@ -161,21 +192,24 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c
out = ( ( p1 * 2.0) +
( -p0 + p2 ) * t +
( p0 * 2.0 - p1 * 5.0 + p2 * 4 - p3 ) * t2 +
(-p0 + p1 * 3.0 - p2 * 3.0 + p3) * t3) *
0.5;
( -p0 + p1 * 3.0 - p2 * 3.0 + p3 ) * t3 ) * 0.5;
return out;
}
Vector2 Vector2::slide(const Vector2 &p_vec) const {
Vector2 Vector2::slide(const Vector2& p_vec) const
{
return p_vec - *this * this->dot(p_vec);
}
Vector2 Vector2::reflect(const Vector2 &p_vec) const {
Vector2 Vector2::reflect(const Vector2& p_vec) const
{
return p_vec - *this * this->dot(p_vec) * 2.0;
}
real_t Vector2::angle() const {
real_t Vector2::angle() const
{
return atan2(y, x);
}
@@ -190,7 +224,8 @@ Vector2 Vector2::abs() const {
return Vector2( fabs(x), fabs(y) );
}
Vector2 Vector2::rotated(real_t p_by) const {
Vector2 Vector2::rotated(real_t p_by) const
{
Vector2 v;
v.set_rotation(angle() + p_by);
v *= length();
@@ -202,18 +237,23 @@ Vector2 Vector2::tangent() const {
return Vector2(y,-x);
}
Vector2 Vector2::floor() const {
Vector2 Vector2::floor() const
{
return Vector2(::floor(x), ::floor(y));
}
Vector2 Vector2::snapped(const Vector2 &p_by) const {
Vector2 Vector2::snapped(const Vector2& p_by) const
{
return Vector2(
p_by.x != 0 ? ::floor(x / p_by.x + 0.5) * p_by.x : x,
p_by.y != 0 ? ::floor(y / p_by.y + 0.5) * p_by.y : y);
p_by.y != 0 ? ::floor(y / p_by.y + 0.5) * p_by.y : y
);
}
Vector2::operator String() const {
Vector2::operator String() const
{
return String::num(x) + ", " + String::num(y);
}
} // namespace godot
}

View File

@@ -2,121 +2,143 @@
#include "String.hpp"
#include "Basis.hpp"
#include <stdlib.h>
#include <cmath>
#include "Basis.hpp"
namespace godot {
Vector3::Vector3(real_t x, real_t y, real_t z) {
Vector3::Vector3(real_t x, real_t y, real_t z)
{
this->x = x;
this->y = y;
this->z = z;
}
Vector3::Vector3() {
Vector3::Vector3()
{
this->x = 0;
this->y = 0;
this->z = 0;
}
const real_t &Vector3::operator[](int p_axis) const {
const real_t& Vector3::operator[](int p_axis) const
{
return coord[p_axis];
}
real_t &Vector3::operator[](int p_axis) {
real_t& Vector3::operator[](int p_axis)
{
return coord[p_axis];
}
Vector3 &Vector3::operator+=(const Vector3 &p_v) {
Vector3& Vector3::operator+=(const Vector3& p_v)
{
x += p_v.x;
y += p_v.y;
z += p_v.z;
return *this;
}
Vector3 Vector3::operator+(const Vector3 &p_v) const {
Vector3 Vector3::operator+(const Vector3& p_v) const
{
Vector3 v = *this;
v += p_v;
return v;
}
Vector3 &Vector3::operator-=(const Vector3 &p_v) {
Vector3& Vector3::operator-=(const Vector3& p_v)
{
x -= p_v.x;
y -= p_v.y;
z -= p_v.z;
return *this;
}
Vector3 Vector3::operator-(const Vector3 &p_v) const {
Vector3 Vector3::operator-(const Vector3& p_v) const
{
Vector3 v = *this;
v -= p_v;
return v;
}
Vector3 &Vector3::operator*=(const Vector3 &p_v) {
Vector3& Vector3::operator*=(const Vector3& p_v)
{
x *= p_v.x;
y *= p_v.y;
z *= p_v.z;
return *this;
}
Vector3 Vector3::operator*(const Vector3 &p_v) const {
Vector3 Vector3::operator*(const Vector3& p_v) const
{
Vector3 v = *this;
v *= p_v;
return v;
}
Vector3 &Vector3::operator/=(const Vector3 &p_v) {
Vector3& Vector3::operator/=(const Vector3& p_v)
{
x /= p_v.x;
y /= p_v.y;
z /= p_v.z;
return *this;
}
Vector3 Vector3::operator/(const Vector3 &p_v) const {
Vector3 Vector3::operator/(const Vector3& p_v) const
{
Vector3 v = *this;
v /= p_v;
return v;
}
Vector3 &Vector3::operator*=(real_t p_scalar) {
Vector3& Vector3::operator*=(real_t p_scalar)
{
*this *= Vector3(p_scalar, p_scalar, p_scalar);
return *this;
}
Vector3 Vector3::operator*(real_t p_scalar) const {
Vector3 Vector3::operator*(real_t p_scalar) const
{
Vector3 v = *this;
v *= p_scalar;
return v;
}
Vector3 &Vector3::operator/=(real_t p_scalar) {
Vector3& Vector3::operator/=(real_t p_scalar)
{
*this /= Vector3(p_scalar, p_scalar, p_scalar);
return *this;
}
Vector3 Vector3::operator/(real_t p_scalar) const {
Vector3 Vector3::operator/(real_t p_scalar) const
{
Vector3 v = *this;
v /= p_scalar;
return v;
}
Vector3 Vector3::operator-() const {
Vector3 Vector3::operator-() const
{
return Vector3(-x, -y, -z);
}
bool Vector3::operator==(const Vector3 &p_v) const {
bool Vector3::operator==(const Vector3& p_v) const
{
return (x==p_v.x && y==p_v.y && z==p_v.z);
}
bool Vector3::operator!=(const Vector3 &p_v) const {
bool Vector3::operator!=(const Vector3& p_v) const
{
return (x!=p_v.x || y!=p_v.y || z!=p_v.z);
}
bool Vector3::operator<(const Vector3 &p_v) const {
bool Vector3::operator<(const Vector3& p_v) const
{
if (x==p_v.x) {
if (y==p_v.y)
return z<p_v.z;
@@ -127,7 +149,8 @@ bool Vector3::operator<(const Vector3 &p_v) const {
}
}
bool Vector3::operator<=(const Vector3 &p_v) const {
bool Vector3::operator<=(const Vector3& p_v) const
{
if (x==p_v.x) {
if (y==p_v.y)
return z<=p_v.z;
@@ -138,31 +161,38 @@ bool Vector3::operator<=(const Vector3 &p_v) const {
}
}
Vector3 Vector3::abs() const {
Vector3 Vector3::abs() const
{
return Vector3(::fabs(x), ::fabs(y), ::fabs(z));
}
Vector3 Vector3::ceil() const {
Vector3 Vector3::ceil() const
{
return Vector3(::ceil(x), ::ceil(y), ::ceil(z));
}
Vector3 Vector3::cross(const Vector3 &b) const {
Vector3 Vector3::cross(const Vector3& b) const
{
Vector3 ret (
(y * b.z) - (z * b.y),
(z * b.x) - (x * b.z),
(x * b.y) - (y * b.x));
(x * b.y) - (y * b.x)
);
return ret;
}
Vector3 Vector3::linear_interpolate(const Vector3 &p_b, real_t p_t) const {
Vector3 Vector3::linear_interpolate(const Vector3& p_b,real_t p_t) const
{
return Vector3(
x+(p_t * (p_b.x-x)),
y+(p_t * (p_b.y-y)),
z + (p_t * (p_b.z - z)));
z+(p_t * (p_b.z-z))
);
}
Vector3 Vector3::cubic_interpolate(const Vector3 &b, const Vector3 &pre_a, const Vector3 &post_b, const real_t t) const {
Vector3 Vector3::cubic_interpolate(const Vector3& b, const Vector3& pre_a, const Vector3& post_b, const real_t t) const
{
Vector3 p0=pre_a;
Vector3 p1=*this;
Vector3 p2=b;
@@ -175,16 +205,17 @@ Vector3 Vector3::cubic_interpolate(const Vector3 &b, const Vector3 &pre_a, const
out = ( ( p1 * 2.0) +
( -p0 + p2 ) * t +
( p0 * 2.0 - p1 * 5.0 + p2 * 4 - p3 ) * t2 +
(-p0 + p1 * 3.0 - p2 * 3.0 + p3) * t3) *
0.5;
( -p0 + p1 * 3.0 - p2 * 3.0 + p3 ) * t3 ) * 0.5;
return out;
}
Vector3 Vector3::bounce(const Vector3 &p_normal) const {
Vector3 Vector3::bounce(const Vector3& p_normal) const
{
return -reflect(p_normal);
}
real_t Vector3::length() const {
real_t Vector3::length() const
{
real_t x2=x*x;
real_t y2=y*y;
real_t z2=z*z;
@@ -192,7 +223,8 @@ real_t Vector3::length() const {
return ::sqrt(x2+y2+z2);
}
real_t Vector3::length_squared() const {
real_t Vector3::length_squared() const
{
real_t x2=x*x;
real_t y2=y*y;
real_t z2=z*z;
@@ -200,50 +232,63 @@ real_t Vector3::length_squared() const {
return x2+y2+z2;
}
real_t Vector3::distance_squared_to(const Vector3 &b) const {
real_t Vector3::distance_squared_to(const Vector3& b) const
{
return (b-*this).length_squared();
}
real_t Vector3::distance_to(const Vector3 &b) const {
real_t Vector3::distance_to(const Vector3& b) const
{
return (b-*this).length();
}
real_t Vector3::dot(const Vector3 &b) const {
real_t Vector3::dot(const Vector3& b) const
{
return x*b.x + y*b.y + z*b.z;
}
real_t Vector3::angle_to(const Vector3 &b) const {
real_t Vector3::angle_to(const Vector3& b) const
{
return std::atan2(cross(b).length(), dot(b));
}
Vector3 Vector3::floor() const {
Vector3 Vector3::floor() const
{
return Vector3(::floor(x), ::floor(y), ::floor(z));
}
Vector3 Vector3::inverse() const {
Vector3 Vector3::inverse() const
{
return Vector3( 1.0/x, 1.0/y, 1.0/z );
}
bool Vector3::is_normalized() const {
bool Vector3::is_normalized() const
{
return std::abs(length_squared() - 1.0) < 0.00001;
}
Basis Vector3::outer(const Vector3 &b) const {
Basis Vector3::outer(const Vector3& b) const
{
Vector3 row0(x * b.x, x * b.y, x * b.z);
Vector3 row1(y * b.x, y * b.y, y * b.z);
Vector3 row2(z * b.x, z * b.y, z * b.z);
return Basis(row0, row1, row2);
}
int Vector3::max_axis() const {
int Vector3::max_axis() const
{
return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0);
}
int Vector3::min_axis() const {
int Vector3::min_axis() const
{
return x < y ? (x < z ? 0 : 2) : (y < z ? 1 : 2);
}
void Vector3::normalize() {
void Vector3::normalize()
{
real_t l=length();
if (l==0) {
x=y=z=0;
@@ -254,34 +299,40 @@ void Vector3::normalize() {
}
}
Vector3 Vector3::normalized() const {
Vector3 Vector3::normalized() const
{
Vector3 v = *this;
v.normalize();
return v;
}
Vector3 Vector3::reflect(const Vector3 &by) const {
Vector3 Vector3::reflect(const Vector3& by) const
{
return by - *this * this->dot(by) * 2.0;
}
Vector3 Vector3::rotated(const Vector3 &axis, const real_t phi) const {
Vector3 Vector3::rotated(const Vector3& axis, const real_t phi) const
{
Vector3 v = *this;
v.rotate(axis, phi);
return v;
}
void Vector3::rotate(const Vector3 &p_axis, real_t p_phi) {
void Vector3::rotate(const Vector3& p_axis,real_t p_phi)
{
*this=Basis(p_axis,p_phi).xform(*this);
}
Vector3 Vector3::slide(const Vector3 &by) const {
Vector3 Vector3::slide(const Vector3& by) const
{
return by - *this * this->dot(by);
}
// this is ugly as well, but hey, I'm a simple man
#define _ugly_stepify(val, step) (step != 0 ? ::floor(val / step + 0.5) * step : val)
void Vector3::snap(real_t p_val) {
void Vector3::snap(real_t p_val)
{
x = _ugly_stepify(x,p_val);
y = _ugly_stepify(y,p_val);
z = _ugly_stepify(z,p_val);
@@ -289,14 +340,18 @@ void Vector3::snap(real_t p_val) {
#undef _ugly_stepify
Vector3 Vector3::snapped(const float by) {
Vector3 Vector3::snapped(const float by)
{
Vector3 v = *this;
v.snap(by);
return v;
}
Vector3::operator String() const {
Vector3::operator String() const
{
return String::num(x) + ", " + String::num(y) + ", " + String::num(z);
}
} // namespace godot
}