Commit graph

61 commits

Author SHA1 Message Date
Aaron Franke 08a85352fb
Rename Variant TRANSFORM to TRANSFORM3D
Also _transform to _transform3d
2021-06-03 07:30:01 -04:00
Rémi Verschelde 2fcfc83da9
Merge pull request #48793 from vnen/gdscript-fix-temp-type-adjust
GDScript: Fix crash caused by uninitialized temp stack slots
2021-05-17 17:34:19 +02:00
George Marques 10a1f64968
GDScript: Fix crash caused by uninitialized temp stack slots
This adds initialization to every typed temporary stack slot at the
beginning of the function call instead of emitting instructions, since
those might be in a conditional branch and not be called.
2021-05-17 10:59:43 -03:00
George Marques ec783dd885
GDScript: Add support for builtin static method calls 2021-05-16 11:54:33 -03:00
George Marques c201b212c7
GDScript: Implement lambdas compilation and runtime 2021-04-28 11:09:38 -03:00
George Marques 9411bf05a4
GDScript: Adjust type of temporaries when needed 2021-04-16 12:04:08 -03:00
George Marques cf4079cb5f
Reduce number of addressing modes in GDScript VM
There's now only 3 addressing modes: stack, constant, and member.

Self, class, and nil are now present respectively in the first 3 stack
slots. Global and class constants are moved to local constants when
compiling. Named globals is only present on editor to use on tool
singletons, so its use now emits a new instruction to copy the global to
the stack.

This allow us to further optimize the VM later by embedding the
addressing modes in the instructions themselves, which is better done
with less permutations.
2021-04-08 14:29:55 -03:00
George Marques 35682d3079
GDScript: Properly validate return type
When the type cannot be validated at compile time, the runtime must do a
check to ensure type safety is kept, as the code might be assuming the
return type is correct in another place, leading to crashes if the
contract is broken.
2021-04-05 09:52:05 -03:00
George Marques 85e316a5d5
Add typed arrays to GDScript
- Use `Array[type]` for type-hints. e.g.:
  `var array: Array[int] = [1, 2, 3]`
- Array literals are typed if their storage is typed (variable
  asssignment of as argument in function all). Otherwise they are
  untyped.
2021-03-29 10:45:48 -03:00
Rafał Mikrut f7209b459b Initialize class/struct variables with default values in modules/ 2021-02-08 10:57:18 +01:00
Rémi Verschelde b5334d14f7
Update copyright statements to 2021
Happy new year to the wonderful Godot community!

2020 has been a tough year for most of us personally, but a good year for
Godot development nonetheless with a huge amount of work done towards Godot
4.0 and great improvements backported to the long-lived 3.2 branch.

We've had close to 400 contributors to engine code this year, authoring near
7,000 commit! (And that's only for the `master` branch and for the engine code,
there's a lot more when counting docs, demos and other first-party repos.)

Here's to a great year 2021 for all Godot users 🎆
2021-01-01 20:19:21 +01:00
Rémi Verschelde abfc528439
Merge pull request #43890 from vnen/gdscript-builtin-functions-refactor
GDScript: Refactor builtin functions
2020-12-15 20:51:38 +01:00
Thakee Nathees d0e7d9b62f Documentation generation for GDScript
- ClassDoc added to GDScript and property reflection data were extracted
from parse tree

- GDScript comments are collected from tokenizer for documentation and
applied to the ClassDoc by the GDScript compiler

- private docs were excluded (name with underscore prefix and doesn't
have any doc comments)

- default values (of non exported vars), arguments are extraced from the
parser

- Integrated with GDScript 2.0 and new enums were added.

- merge conflicts fixed
2020-11-29 19:45:36 +05:30
George Marques c7b6a7adcc
GDScript: Refactor builtin functions
They are now called "utility functions" to avoid confusion with methods
of builtin types, and be consistent with the naming in Variant.

Core utility functions are now available in GDScript. The ones missing
in core are added specifically to GDScript as helpers for convenience.

Some functions were remove when there are better ways to do, reducing
redundancy and cleaning up the global scope.
2020-11-26 12:05:42 -03:00
George Marques 5518e2a68e
GDScript: Add faster instruction for validated constructor
Only for built-in types.
2020-11-21 13:30:17 -03:00
George Marques e0dca3c6b6
GDScript: Add typed iterate instructions 2020-11-21 13:24:50 -03:00
George Marques 52ab64db69
GDScript: Add faster call instructions for builtin methods
Methods from builtin types can be called by using the function pointer
when the argument and base types are known at compile time.
2020-11-21 13:24:50 -03:00
George Marques d8b22097f2
GDScript: Add faster call instructions for native methods 2020-11-21 13:24:50 -03:00
George Marques 5aeb390cd7
GDScript: Add speficic set/get instructions
When the base type is known at compile-time, we can get a direct
function pointer that is faster than the regular set/get paths.
2020-11-21 13:24:49 -03:00
George Marques 1ad5c926dc
GDScript: Add faster operator for known types
It now uses the direct operator function pointer, which increases
performance in evaluation.
2020-11-21 13:24:49 -03:00
George Marques c707d6fe71
GDScript: Gather instructions arguments beforehand
Almost all instructions need variant arguments. With this change they
are loaded in an array before each instruction call. This makes the
addressing code be localized to less places, improving compilation
overhead and binary size by a small margin.

This should not affect performance.
2020-11-21 13:24:49 -03:00
reduz 127458ed17 Reorganized core/ directory, it was too fatty already
-Removed FuncRef, since Callable makes it obsolete
-Removed int_types.h as its obsolete in c++11+
-Changed color names code
2020-11-07 20:17:12 -03:00
Pedro J. Estébanez 95828161d4 Prevent cyclic reference between script and its members 2020-09-10 01:26:07 +02:00
George Marques 635c6a0a18
Add GDScript disassembler 2020-09-01 14:36:30 -03:00
George Marques 82273ebc01
Add GDScript code generation interface
Implement the abstraction by targeting the current VM.
2020-09-01 14:27:19 -03:00
George Marques 5d6e853806
New GDScript tokenizer and parser
Sometimes to fix something you have to break it first.

This get GDScript mostly working with the new tokenizer and parser but
a lot of things isn't working yet. It compiles and it's usable, and that
should be enough for now.

Don't worry: other huge commits will come after this.
2020-07-20 11:38:39 -03:00
Rémi Verschelde 0ee0fa42e6 Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
2020-05-14 21:57:34 +02:00
Rémi Verschelde 0be6d925dc Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks
Which means that reduz' beloved style which we all became used to
will now be changed automatically to remove the first empty line.

This makes us lean closer to 1TBS (the one true brace style) instead
of hybridating it with some Allman-inspired spacing.

There's still the case of braces around single-statement blocks that
needs to be addressed (but clang-format can't help with that, but
clang-tidy may if we agree about it).

Part of #33027.
2020-05-14 16:54:55 +02:00
Rémi Verschelde 1f6f364a56 Port member initialization from constructor to declaration (C++11)
Using `clang-tidy`'s `modernize-use-default-member-init` check and
manual review of the changes, and some extra manual changes that
`clang-tidy` failed to do.

Also went manually through all of `core` to find occurrences that
`clang-tidy` couldn't handle, especially all initializations done
in a constructor without using initializer lists.
2020-05-14 10:01:56 +02:00
Rémi Verschelde e956e80c1f Style: clang-format: Disable AllowShortIfStatementsOnASingleLine
Part of #33027, also discussed in #29848.

Enforcing the use of brackets even on single line statements would be
preferred, but `clang-format` doesn't have this functionality yet.
2020-05-10 13:12:16 +02:00
Pedro J. Estébanez 46bfe4452f Fix object leaks caused by unfulfilled yields
Now the stack saved in a `GDScriptFunctionState` is cleared as soon as the `yield()` operation is known not to be resumed because either the script, the instance or both are deleted.

This clears problems like leaked objects by eliminating cases of circular references between `GDScriptFunctionState`s preventing them and the objects they refer to in their saved stacks from being released. As an example, this makes using `SceneTreeTimer` safer.

Furthermore, with this change it's now possible to print early warnings about `yield()`s to released script/instances, as now we know they won't be successfully resumed as the condition for that happens. However, this PR doesn't add such messages, to keep the observed behavior the same for the time being.

Also, now a backup of the function name in `GDScriptFunctionState` is used, since the script may not be valid by the time the function name is needed for the resume-after-yield error messages.
2020-05-05 17:54:15 +02:00
Pedro J. Estébanez c427334393 Fix leaked objects when game ends with yields in progress 2020-04-29 13:55:10 +02:00
lupoDharkael 95a1400a2a Replace NULL with nullptr 2020-04-02 13:38:00 +02:00
Rémi Verschelde cb282c6ef0 Style: Set clang-format Standard to Cpp11
For us, it practically only changes the fact that `A<A<int>>` is now
used instead of the C++03 compatible `A<A<int> >`.

Note: clang-format 10+ changed the `Standard` arguments to fully
specified `c++11`, `c++14`, etc. versions, but we can't use `c++17`
now if we want to preserve compatibility with clang-format 8 and 9.
`Cpp11` is still supported as deprecated alias for `Latest`.
2020-03-17 07:36:24 +01:00
Juan Linietsky 69c95f4b4c Reworked signal connection system, added support for Callable and Signal objects and made them default. 2020-02-20 08:24:50 +01:00
George Marques 4d960efafc
GDScript: Remove self static reference and create one on calls
This is needed because of the new changes to Variant. The reference
counter is increased by adding it to a Variant, which means no GDScript
will be freed (or will be double freed if manually freed somewhere).
2020-02-19 09:15:16 -03:00
Juan Linietsky 867d073b98 Changed logic and optimized ObjectID in ObjectDB and Variant, removed RefPtr. 2020-02-15 08:36:04 -03:00
Bojidar Marinov dc4455d819
Validate instances of objects before trying to check their type in GDScript
Fixes #27582
2020-01-16 16:39:59 +02:00
Rémi Verschelde a7f49ac9a1 Update copyright statements to 2020
Happy new year to the wonderful Godot community!

We're starting a new decade with a well-established, non-profit, free
and open source game engine, and tons of further improvements in the
pipeline from hundreds of contributors.

Godot will keep getting better, and we're looking forward to all the
games that the community will keep developing and releasing with it.
2020-01-01 11:16:22 +01:00
Rémi Verschelde 425ec6914c
Revert "Forbid implicit type conversion in GDScript" 2019-03-04 12:25:59 +01:00
George Marques d0b08342b8
GDScript: Forbid implicit type conversion
Since types are not present in release builds, this could cause issues
where a variable does not have the exact defined type.
2019-03-03 22:25:22 -03:00
Rémi Verschelde b7cc2bb1e2 Core: Ensure classes match their header filename
Also drop some unused files.

Renamed:
- `core/dvector.h` -> `pool_vector.h`
- `core/io/resource_import.h` -> `resource_importer.h`
- `core/sort.h` -> `sort_array.h`
- `core/string_db.h` -> `string_name.h`

Dropped:
- `core/allocators.h`
- `core/os/shell.h`
- `core/variant_construct_string.cpp`
2019-02-12 13:34:25 +01:00
Hein-Pieter van Braam d308eb091a Fix many asan and ubsan reported issues
This allows most demos to run without any ubsan or asan errors. There
are still some things in thirdpart/ and some things in AudioServer that
needs a look but this fixes a lot of issues. This should help debug less
obvious issues, hopefully.

This fixes #25217 and fixes #25218
2019-01-30 06:43:56 +01:00
George Marques 31433ae8e4 GDScript: check for underscore prefix when type-checking
Some classes are represented internally with an underscore prefix, so we
need to make sure we match this representation when type-checking,
otherwise the check might fail on a valid scenario.
2019-01-15 19:50:48 -02:00
Rémi Verschelde b16c309f82 Update copyright statements to 2019
Happy new year to the wonderful Godot community!
2019-01-01 12:58:10 +01:00
Pedro J. Estébanez 06b6cea62e Fix crash on signal/resume to dangling target 2018-11-25 13:16:45 +01:00
Pedro J. Estébanez b499537e68 Revert "Fix crash on signal/resume to dangling target"
This reverts commit 54bdc1e1f6.
2018-11-24 23:46:13 +01:00
Pedro J. Estébanez 54bdc1e1f6 Fix crash on signal/resume to dangling target
Fixes #22443.
2018-10-17 20:44:47 +02:00
Rémi Verschelde 277b24dfb7 Make core/ includes absolute, remove subfolders from include path
This allows more consistency in the manner we include core headers,
where previously there would be a mix of absolute, relative and
include path-dependent includes.
2018-09-12 09:52:22 +02:00
George Marques 4b974a36b7
GDScript: Allow is operator to test built-in types 2018-08-26 13:31:23 -03:00