Commit graph

59 commits

Author SHA1 Message Date
Pedro J. Estébanez
26edc6cd41 Promote object validity checks to release builds
Extra:
- Optimized the debug-only check about why the object is null to determine if it's because it has been deleted (the RC is enough; no need to check the ObjectDB).
- Because of the previous point. the debugger being attached is not required anymore for giving the "Object was deleted" error; from now, it only matters that it's a debug build.
- `is_instance_valid()` is now trustworthy. It will return `true` if, and only if, the last object assigned to a `Variant` is still alive (and not if a new object happened to be created at the same memory address of the old one).
- Replacements of `instance_validate()` are used where possible `Variant::is_invalid_object()` is introduced to help with that. (GDScript's `is_instance_valid()` is good.)
2021-09-21 10:39:04 +02:00
Marcel Admiraal
7e03bd1671 Remove duplicate WARN_PRINTS macro 2021-06-18 12:57:59 +01:00
Marcel Admiraal
5a58516231 Remove duplicate ERR_PRINTS macro 2021-06-16 11:56:25 +01:00
Rémi Verschelde
140350d767
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
2021-05-05 15:02:01 +02:00
Rémi Verschelde
a828398655
Style: Replaces uses of 0/NULL by nullptr (C++11)
Using clang-tidy's `modernize-use-nullptr`.
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
2021-05-04 16:30:23 +02:00
Rémi Verschelde
b5e1e05ef2
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks 2021-05-04 14:45:16 +02:00
kleonc
f04a964627 Make posmod use int64_t instead of int 2021-05-03 22:03:16 +02:00
Meriipu
347a9df0a1
GDScript: Clarified/fixed inaccuracies in the built-in function docs.
The input to smoothstep is not actually a weight, and the decscription
of smoothstep was pretty hard to understand and easy to misinterpret.

Clarified what it means to be approximately equal.

nearest_po2 does not do what the descriptions says it does. For one,
it returns the same power if the input is a power of 2. Second, it
returns 0 if the input is negative or 0, while the smallest possible
integral power of 2 actually is 1 (2^0 = 1). Due to the implementation
and how it is used in a lot of places, it does not seem wise to change
such a core function however, and I decided it is better to alter the
description of the built-in.

Added a few examples/clarifications/edge-cases.

(cherry picked from commit 7f9bfee0ac)
2021-02-11 13:12:06 +01:00
Rémi Verschelde
49646383f1
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 🎆

(cherry picked from commit b5334d14f7)
2021-01-13 16:17:06 +01:00
Aaron Franke
1bb81488bb
Minor clamp and float fixes
(cherry picked from commit ee79fc627c)
2020-11-11 15:30:57 +01:00
Thakee Nathees
e417528f67 fix: dict2inst crash when constructor has arguments
(cherry picked from commit 9f6b20936e)
2020-05-11 11:01:12 +02:00
George Marques
d26414f9fe
GDScript: enable type checks on release mode
Also make builtin GDScript functions report return type as Variant in
release so type is converted when needed.
2020-01-08 12:38:18 -03: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
Haoyu Qiu
468fcd80bb Updates docs for GDScript built-in functions
* Adds description for `ord()`
* Adds relationship description between `char()` and `ord()`
* Describes the argument of `char()` as Unicode code point instead of ASCII code
* Fixes wrong interval notation in `randi()` description
2019-12-15 19:06:29 +08:00
Rémi Verschelde
df2e3e3f7f
Merge pull request #33018 from Xrayez/fix-inst2dict-getters
Fix `inst2dict` calling to getters to retrieve value
2019-12-11 15:06:38 +01:00
Andrii Doroshenko (Xrayez)
7f40b69022 Use GDScript resource path over script path for inst2dict
The resource path holds the original path which can be used to convert
a dictionary to instance consistently both within editor and exported projects
as the original path is automatically remapped from `gd` to `gdc` or `gde` in
exported projects.
2019-11-02 15:11:52 +02:00
Andrii Doroshenko (Xrayez)
56925b9c28 Provide and print error messages for JSON parsing
Core is not touched, only for binding and scripting.
2019-10-31 13:15:44 +02:00
PouleyKetchoupp
bcbe5b5850 Fixed leak in gdscript when creating empty WeakRef
Fixes #33150
2019-10-29 23:53:56 +01:00
Andrii Doroshenko (Xrayez)
1b9a7e1c21 Fix inst2dict calling to getters to retrieve value
Use `GDScriptInstance` to iterate through all members directly instead.
This is similar to how `dict2inst` works and makes the serialization
behaviour more consistent.
2019-10-24 14:45:04 +03:00
Windy Darian
628f467605 Allow weakref(null) in gdscript
Tiny addition I personally found useful - this allows us to `var my_ref := weakref(null)` for nullable weak ref (with type hint!). When trying to test if `my_ref` is holding valid reference, we can just `if my_ref.get_ref():` instead of `if my_ref and my_ref.get_ref():` everywhere.
2019-09-16 23:15:34 -04:00
Masoud Montazeri
5565f5591f Add ord() function to return Unicode code point of a string of length one 2019-08-28 16:14:11 +02:00
Robin Hübner
6ab118c464 Replace 'ERR_EXPLAIN' with 'ERR_FAIL_*_MSG' in "platform", "modules/gdnative", "modules/gdscript" directories. 2019-08-09 11:13:24 +02:00
Chaosus
6694c119d0 Added lerp_angles built-in function
Co-authored-by: Xrayez <https://github.com/Xrayez>
Co-authored-by: DleanJeans <https://github.com/DleanJeans>
2019-07-20 12:59:41 +03:00
Aaron Franke
a60f242982 Add integer posmod and rename default arg names
"posmod" is the integer version of "fposmod". We do not need a "mod" because of the % operator.

I changed the default arg names from "x" and "y" to "a" and "b" because they are not coordinates. I also changed pow's arg names to "base" and "exp". Also, I reorganized the code in the VS built-in funcs switch statement.
2019-07-18 16:33:43 -04:00
Rémi Verschelde
6d16f2f053 Fix error macro calls not ending with semicolon
It's not necessary, but the vast majority of calls of error macros
do have an ending semicolon, so it's best to be consistent.
Most WARN_DEPRECATED calls did *not* have a semicolon, but there's
no reason for them to be treated differently.
2019-06-11 14:49:34 +02:00
Giacom
c00427add3 Added move_toward functions for float, Vector2 and Vector3 2019-05-28 11:39:35 +01:00
Aaron Franke
620ec4703f
Make "decimal" functions more consistent
In GDScript, rename "decimals" to "step_decimals". In C#, add "StepDecimals", but keep the old functionality in a method called "DecimalCount".
2019-04-30 13:49:17 -04:00
Aaron Franke
7f7d97f536
[Core] Expose approximate equality methods to GDScript 2019-04-25 13:20:29 -04:00
Rémi Verschelde
d211aff777
Merge pull request #27231 from Chaosus/smoothstep
Added smoothstep built-in function
2019-04-08 10:03:42 +02:00
Chaosus
514a3fb96a Added smoothstep built-in function 2019-04-07 14:11:26 +03:00
Fabio Alessandrelli
393e62b98a Add object encoding param to serialization methods
Network peers get_var/put_var
File get_var/store_var
GDScript/Mono/VisualScript bytes2var/var2bytes
Add MultiplayerAPI.allow_object_decoding member which deprecates PacketPeer.allow_object_decoding.

Break ABI compatibaility (API compatibility for GDNative).
2019-04-01 15:53:19 +02:00
Rémi Verschelde
d024979e84 GDScript: Fix return value of "lerp" builtin
Fixes #25082, fixes #24709.
2019-01-18 10:47:04 +01: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
Rémi Verschelde
17c3c64a80 i18n: Sync translation template with current source
Also French translation update and misc fixes to source strings.
2018-12-13 14:47:24 +01:00
Rémi Verschelde
19f2a188bb
Merge pull request #22934 from SeleckyErik/issue-11457
GDscript function str2var now returns null on invalid input
2018-12-07 15:43:47 +01:00
Erik
78c9677816 GDscript function str2var now returns input string on invalid input
str2var used to raise a blocking error when  invalid input was passed. Now it logs an error message and
returns the input string. This solution was proposed in #13021.

Closes #11457 and #13021.
2018-11-28 14:47:40 +01:00
Michael Alexsander Silva Dias
1ca61a35d8 Add new "push_*()" functions to GDScript 2018-10-31 15:40:19 -03:00
DualMatrix
4bad2beeed Fixed argument names being swapped for atan2
The arguments of atan2() should be y,x instead of x,y This was just wrong since the internal atan2 already had y,x as parameters, so if you followed the autocomplete the result would just be wrong.
2018-09-16 21:27:54 +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
WiggleWizard
d227a9ae12 Fixed return type for get_stack() function call 2018-09-05 11:29:06 +01:00
Rémi Verschelde
52466d57e9 Make some debug prints verbose-only, remove others 2018-08-24 14:59:01 +02:00
George Marques
a62f4af7ba
GDScript: Enable built-in function introspection in non-tools
Only for debug builds. Fix problems in non-tools targets.
2018-07-25 20:50:12 -03:00
Hein-Pieter van Braam
0e29f7974b Reduce unnecessary COW on Vector by make writing explicit
This commit makes operator[] on Vector const and adds a write proxy to it.  From
now on writes to Vectors need to happen through the .write proxy. So for
instance:

Vector<int> vec;
vec.push_back(10);
std::cout << vec[0] << std::endl;
vec.write[0] = 20;

Failing to use the .write proxy will cause a compilation error.

In addition COWable datatypes can now embed a CowData pointer to their data.
This means that String, CharString, and VMap no longer use or derive from
Vector.

_ALWAYS_INLINE_ and _FORCE_INLINE_ are now equivalent for debug and non-debug
builds. This is a lot faster for Vector in the editor and while running tests.
The reason why this difference used to exist is because force-inlined methods
used to give a bad debugging experience. After extensive testing with modern
compilers this is no longer the case.
2018-07-26 00:54:16 +02:00
George Marques
743053734f
Add static type checks in the parser
- Resolve types for all identifiers.
- Error when identifier is not found.
- Match return type and error when not returning a value when it should.
- Check unreachable code (code after sure return).
- Match argument count and types for function calls.
- Determine if return type of function call matches the assignment.
- Do static type check with match statement when possible.
- Use type hints to determine export type.
- Check compatibility between type hint and explicit export type.
2018-07-20 21:55:16 -03:00
Max Hilbrunner
d988d188ad
Merge pull request #18966 from chanon/new-debug-print
Add new debug print method that shows line number where the print came from
2018-07-04 23:50:45 +02:00
chanon
3ea6d9f37d add new print_debug method which shows source and line number 2018-05-28 18:37:07 +07:00
chanon
a56d6ff35f add new get_stack function to get GDScript stack trace as array 2018-05-17 21:06:30 +07:00
Juan Linietsky
299d8a80ba
Merge pull request #16106 from poke1024/gdscript-lerp
GDScript: generalize lerp
2018-05-07 20:36:31 -03:00
Juan Linietsky
ff1e7cfbf4 Add is_instance_valid() method to GDScript, ending more than a decade of pain. 2018-05-07 17:30:03 -03:00
Rémi Verschelde
aeed774fef
Merge pull request #16173 from vnen/gdscript-arguments
Add argument count check for some GDScript functions
2018-02-19 21:35:53 +01:00