Compare commits

..

201 Commits

Author SHA1 Message Date
Hein-Pieter van Braam-Stewart
66baa3b633 Also bump Info.plist for MacOS 2019-04-26 16:43:03 +02:00
Hein-Pieter van Braam-Stewart
e4816a8b1c Bump to 3.1.1-stable
Thanks everyone! You're all stars <3
2019-04-26 16:39:11 +02:00
homer666
5b6ad923f0 AnimationPlayer FPS mode fixes
(cherry picked from commit e3b7f9e1ca)
2019-04-26 16:34:18 +02:00
Ignacio Etcheverry
1c77481d3e Fix invalid mono log file name on Windows
(cherry picked from commit d93c354807)
2019-04-26 16:31:01 +02:00
Rémi Verschelde
a24899ee25 Revert "Update freetype to 2.10.0"
This reverts commit 9e2cf9ef0b.

It caused this regression: 28335.
Fixes #28335.
2019-04-25 14:18:42 +02:00
Rémi Verschelde
f7d5bee636 Revert "C#: Add DynamicGodotObject class"
This reverts commit 4c10a322d1.
2019-04-25 14:08:14 +02:00
Rémi Verschelde
23cf9f3b6f i18n: Sync translation template with current source 2019-04-25 14:03:22 +02:00
Rémi Verschelde
348270df38 i18n: Sync translations with Weblate 2019-04-25 14:01:33 +02:00
Rémi Verschelde
a485d862f1 doc: Sync classref with current source 2019-04-25 14:00:31 +02:00
Juan Linietsky
fcbe50befa Added bindings for methods related to obtaining base an instance from VisualInstance
(cherry picked from commit 33a0011ab2)
2019-04-24 07:01:39 +02:00
Juan Linietsky
08113feb5f Expose visible instance count to multimesh
(cherry picked from commits f46899e922)
and 479649b5fb)
2019-04-24 07:01:04 +02:00
Rémi Verschelde
4764e17970 Revert "Added the ability to change the default cursor property for the RichTextLabel component."
This reverts commit 4fda05e15f.
2019-04-23 16:01:16 +02:00
Ignacio Etcheverry
39f1a110a1 Fix wrong method binds and registered class
(cherry picked from commit 2f3328a039)
2019-04-22 21:57:06 +02:00
Rémi Verschelde
cab4921477 Revert "GDScript: Don't allow built-in scripts to use class_name"
This reverts commit 42514bfd80.

There is still an unsolved regression from this commit (#28002)
which needs to be addressed before cherry-picking this one.
2019-04-21 14:06:06 +02:00
Hein-Pieter van Braam-Stewart
4aa7760c74 Revert "Ensure non-emitting particles not processed on entering tree"
This reverts commit 24b7f08892.

This causes a particles regression in tps-demo
2019-04-21 00:59:13 +02:00
Hein-Pieter van Braam-Stewart
4fefc0896d Delete <demos> tag from HeightMapShape xml 2019-04-21 00:11:01 +02:00
Juan Linietsky
d8cae6e7f6 Implement autokeying in Animation editor.
(cherry picked from commit 296c74072c)
2019-04-21 00:02:02 +02:00
Juan Linietsky
a7f0bfb7db Oops I missed a line, continuation to 0d41f8f.
(cherry picked from commit 8f762aefcd)
2019-04-21 00:01:44 +02:00
Juan Linietsky
5cc03473e0 Also show length in FPS when using FPS mode for AnimationPlayer editor
(cherry picked from commit caaa492133)
2019-04-21 00:01:32 +02:00
Juan Linietsky
6fac922bff Add support for FPS snap in Animation Editor.
(cherry picked from commit 4203266923)
2019-04-20 23:57:59 +02:00
Juan Linietsky
0064d26517 Some improvements to is_equal_approx, restored Quat operator.
(cherry picked from commit dee98d3b6d)
2019-04-20 23:52:19 +02:00
Juan Linietsky
c76c33fb50 Added generator audio stream, and spectrum analyzer audio effect
Made AudioFrame and Vector2 equivalent for casting.
Added ability to obtain the playback object from stream players.
Added ability to obtain effect instance from audio server.

(cherry picked from commit e33764744c)
2019-04-20 23:50:19 +02:00
Juan Linietsky
5e02d6d98a Avoid crash on changing snap mode when no animation exists, closes #28031
(cherry picked from commit 0d41f8fb00)
2019-04-20 23:49:20 +02:00
Chaosus
71753edeae Added normally distributed generation function to RNG
(cherry picked from commit 5f137925dc)
2019-04-20 23:39:04 +02:00
Martin Wallin
ff3987598e Ignore default ccls cache folder and compile commands jso
(cherry picked from commit 8be9fd83ad)
2019-04-20 23:38:00 +02:00
Bastiaan Olij
49df4b7a7a Added height map shape that implement heightmap collision shape
(cherry picked from commit 8627f1515b)
2019-04-20 23:33:50 +02:00
Chaosus
6ab01490f5 Added smoothstep built-in function
(cherry picked from commit 514a3fb96a)
2019-04-20 23:30:56 +02:00
Chaosus
340bf6e80c Added direction_to method to vectors
(cherry picked from commit 55f3bd97a2)
2019-04-20 23:24:35 +02:00
Chaosus
9535a6079e Added functions to AStar for disable/enable points
(cherry picked from commit cc71fb2308)
2019-04-20 23:21:06 +02:00
ShyRed
bb8f015595 Add converters / generators to Sprite
Adds the following menu options to the Sprite editor: "Convert to Mesh2D", "Convert to Polygon2D", "Create CollisionPolygon2D Sibling" and "Create LightOccluder2D Sibling"

(cherry picked from commit c218c631f6)
2019-04-20 23:19:55 +02:00
Michael Alexsander Silva Dias
94f6c3a810 Make AnimatedSprite able to play backwards
(cherry picked from commit 4a2c433028)
2019-04-20 23:17:21 +02:00
muiroc
42fa261563 Enable object decoding when serializing binary project settings
(cherry picked from commit 1f54b11da6)
2019-04-20 23:15:08 +02:00
Fabio Alessandrelli
e0fe795433 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).

(cherry picked from commit 393e62b98a)
2019-04-20 23:15:02 +02:00
Fabio Alessandrelli
a1ad05df86 Multiplayer API now respects allow_object_decoding
Add doc about allow_object_decoding in PacketPeer

(cherry picked from commit 53ab3a1ba9)
2019-04-20 23:14:54 +02:00
Fabio Alessandrelli
ffc47d6fbe Use same boolean for objects encode and decode.
In a very unintuitive move encode needed false to encode an object,
decode needed true to decode it.
They now need the same value: `true`.

(cherry picked from commit e61a074a8e)
2019-04-20 23:14:47 +02:00
Ignacio Etcheverry
9b65bd18bc Fix memory leak introduced in bb6814a
(cherry picked from commit 0338e55a6e)
2019-04-20 23:10:55 +02:00
Ignacio Etcheverry
4c10a322d1 C#: Add DynamicGodotObject class
Expands to Object.call, Object.set and Object.get for accessing members. This means it can also access members from scripts written in other languages, like GDScript.

(cherry picked from commit bb6814aef0)
2019-04-20 23:10:43 +02:00
Mariam Naiga
7851d828a2 Fix cursor color in Label/RTL in editor
Fixes #26246.

(cherry picked from commit d179cbc3c2)
2019-04-20 23:09:47 +02:00
Ignacio Etcheverry
17cb8878c7 Workaround for syntax highlighting issue in GitHub
(cherry picked from commit 7a4cf6339d)
2019-04-20 23:01:08 +02:00
ForLoveOfCats
24ac1439e8 Mono: Convert all items to string before printing
(cherry picked from commit 25f563c4c8)
2019-04-20 23:00:21 +02:00
Rémi Verschelde
1353c98279 FS dock: Allow deselecting items by clicking empty space
Fixes #27546.

(cherry picked from commit 3da2894d82)
2019-04-20 22:59:25 +02:00
Nuno Cardoso
fce901ce40 Fixes #17233 allowing C# to override _GetPropertyList
(cherry picked from commit d011c8e109)
2019-04-20 22:56:42 +02:00
Tomasz Chabora
a758b329d0 Save opened scenes when necessary
(cherry picked from commit 331f922359)
2019-04-20 22:50:16 +02:00
Ignacio Etcheverry
c7e5b371be Mono: Logging improvements
- The default log level in debug builds is now 'info' instead of 'debug'.
- Add option to specify a different log level with the 'GODOT_MONO_LOG_LEVEL' environment variable.
- The name of log files is now a readable date and time.
- Always print the log file path (previously it was printed only it in verbose mode).

(cherry picked from commit 20e5e2fec7)
2019-04-20 22:49:26 +02:00
Bastiaan Olij
edba82b940 Add camera permissions to android
(cherry picked from commit fab84c7dff)
2019-04-20 22:48:34 +02:00
volzhs
9e2cf9ef0b Update freetype to 2.10.0
(cherry picked from commit a6300b454d)
2019-04-20 22:42:45 +02:00
lupoDharkael
904bfa6a72 Validate scripts when they are loaded in the text editor
(cherry picked from commit f137166251)
2019-04-20 22:38:47 +02:00
Chaosus
aa78461ebd Added possibilty to delete multiple nodes in visual shaders via Delete key
(cherry picked from commit 24faddc211)
2019-04-20 22:37:56 +02:00
Tomasz Chabora
ab8ccee1da Focus SceneTree dock after creating new node
(cherry picked from commit 9432e06e05)
2019-04-20 22:37:13 +02:00
George Marques
42514bfd80 GDScript: Don't allow built-in scripts to use class_name
(cherry picked from commit e56f5d5c91)
2019-04-20 22:36:34 +02:00
Bojidar Marinov
667dc0b336 Check for subclasses when checking for name clashes
Fixes #27460

(cherry picked from commit ece09f9872)
2019-04-20 22:35:30 +02:00
Guilherme Felipe
40c2a5ff57 [AnimationNodeBlendTreeEditor] Usability improvements
- Add possibility to exclude multiple (selected) nodes.
- Add context menu (Right click) to add nodes.

(cherry picked from commit ccbf57611b)
2019-04-20 22:31:45 +02:00
Chaosus
d0bebee560 Fix File opened with READ_WRITE on Windows
To allows use read and write anytime and in any order

(cherry picked from commit 8d12dfa24d)
2019-04-20 22:25:02 +02:00
bruvzg
d9aa43e793 [macOS] Allow non-resizeable windows to enter fullscreen mode.
(cherry picked from commit 7c7182483f)
2019-04-20 22:23:25 +02:00
piyushdagar
a329f6fa0b Fixes Adding animation to AnimatedSprite doesn't update inspector immediately
(cherry picked from commit d86d7981cc)
2019-04-20 22:15:01 +02:00
Chaosus
4f3fc559bc Added method to clear all points in Line2D
(cherry picked from commit 61b22beeae)
2019-04-20 22:14:16 +02:00
Chaosus
759c1fb0b8 Added signal for Tween emitted at completion
(cherry picked from commit a19e99aacb)
2019-04-20 22:13:33 +02:00
LATRio
ae6d45b0f2 Fix TextureRegion margin bug introduced in #27122
(cherry picked from commit f38173fb19)
2019-04-20 22:09:57 +02:00
LATRio
2213a21ab3 Fixing zooming in TextureRegion
Fixes #20710

(cherry picked from commit 22030d4cc4)
2019-04-20 22:09:30 +02:00
Martin Wallin
b887d3f8e8 Display vertex number when hovering point in collision polygon
(cherry picked from commit ed06ed38fb)
2019-04-20 22:07:01 +02:00
marxin
c33a924c28 Fix new GCC 9 warnings: -Wdeprecated-copy.
(cherry picked from commit 6be77da7eb)
2019-04-20 22:04:25 +02:00
groud
4be1343f3c Enhance tree scrolling when dragging
(cherry picked from commit 14a901e88f)
2019-04-20 22:00:35 +02:00
Rémi Verschelde
34c2679506 Fix disable_3d=yes -Wunused-variable errors
(cherry picked from commit f25b057846)
2019-04-20 20:30:57 +02:00
Hein-Pieter van Braam-Stewart
650c8512cd Object::script may not be a valid Ref<Script>
It appears that Object::script may be a valid ScriptInstance but not be
castable to Ref<Script>. There were only 5 places in the code that made
this assumption. This commit fixes that.

(cherry picked from commit 20b0046945)
2019-04-20 20:30:30 +02:00
Ignacio Etcheverry
852997e446 Mono: Use exit(status) instead of abort() in exception hook
(cherry picked from commit 8759c0e31a)
2019-04-20 20:30:06 +02:00
Rémi Verschelde
01b39be9e6 Compression: Set Zstd max window size via public parameter
`ZSTD_DCtx_setMaxWindowSize` is still part of the experimental API
(thus unexposed in the shared library). Upstream examples seem to
use `ZSTD_d_windowLogSize` instead, so it's probably what we should
use too.

Fixes #17374.
Distro packagers can now unbundle Zstd.

(cherry picked from commit 20265879e2)
2019-04-20 20:29:45 +02:00
Rémi Verschelde
4298db56cf zstd: Update to upstream 1.4.0
One step towards fixing #17374 as most experimental APIs we use are now
part of the stable 1.4.0.

(cherry picked from commit 88cb9bd27f)
2019-04-20 20:29:34 +02:00
volzhs
3c635b4bdf Fix get_unique_id() on Android
(cherry picked from commit 5a4b2087a0)
2019-04-20 20:29:03 +02:00
James Buck
7b8e7d6514 Fix setting of PopupMenu item IDs in editor
(cherry picked from commit ae646261e3)
2019-04-20 20:28:23 +02:00
CatThingy
4da40c39f1 Removed unnecessary error from _area_inout
The error was previously removed from _body_inout
for the same reason. Fixes #28022.

(cherry picked from commit 8166f8d3c8)
2019-04-20 20:25:40 +02:00
Michael Alexsander Silva Dias
7ddd4f7232 Fix position of tile names in TileSet editor when zooming in/out
Fixes #27713.

(cherry picked from commit d2a7624687)
2019-04-20 20:25:09 +02:00
clayjohn
965b13d62a fixed bug in mip map sigma
(cherry picked from commit 670c1b10b2)
2019-04-20 20:24:44 +02:00
volzhs
20ffda695a Set initial value for autorestart_random_delay of AnimationNodeOneShot
(cherry picked from commit eea3bddd1d)
2019-04-20 20:24:27 +02:00
PouleyKetchoupp
367b371fdd Fixes caches_cleared signal discrepancies in AnimationTree (fixes #25460)
(cherry picked from commit 66e07a2ec6)
2019-04-20 20:23:10 +02:00
PouleyKetchoupp
d0c5dc77f3 EditorFolding ignores hidden properties for folded resources (fixes #26663)
(cherry picked from commit 790a78273f)
2019-04-20 20:22:47 +02:00
Andrea Catania
3d74b1e2ef Added No bone set state in the IK
The problem is that initially the root bone was not set, and you didn't know that because the "no set" state was missing. Now I've added it. https://github.com/godotengine/godot-docs/issues/2333

(cherry picked from commit f65fde73da)
2019-04-20 20:22:01 +02:00
Rémi Verschelde
320105ff05 Fix TTR string for class reference tooltip
Fixes #27852.

(cherry picked from commit 38104bb89d)
2019-04-20 20:21:30 +02:00
Bastiaan Olij
2020f43261 Added eye_height, changed description and fixed size of viewport issue
(cherry picked from commit e0b703e3fe)
2019-04-20 20:21:02 +02:00
Rémi Verschelde
95766f5a6a Fix condition in editor icons filtering logic
Fixes #27595.

(cherry picked from commit 5062b4a26b)
2019-04-20 20:20:48 +02:00
Fabio Alessandrelli
7434760380 Fix jump over uninitialized value in OS Unix/X11
(cherry picked from commit 0bcf0314f7)
2019-04-20 20:18:01 +02:00
PouleyKetchoupp
a028160522 Fixed uninitialized xfade in AnimationNodeTransition
(cherry picked from commit dafd7768ab)
2019-04-20 20:17:35 +02:00
JFonS
792beb4b83 Fix hint_range for GLES2 shader uniforms
(cherry picked from commit 059078f075)
2019-04-20 20:17:13 +02:00
Daniel Kulas
c6fa282fbb Fix "Show in File Manager" option
(cherry picked from commit 22b861ad97)
2019-04-20 20:16:35 +02:00
Hendrikto
456eb53439 Remove unused imports
(cherry picked from commit 49a81308c0)
2019-04-20 20:15:44 +02:00
Rémi Verschelde
782a6dcdde SCons: add methods.using_clang to check used compiler
Also rename `use_gcc` to `using_gcc` to make it clear that it returns
a config but does not alter it.

(cherry picked from commit e4a96164b6)
2019-04-20 20:14:43 +02:00
Hugo Locurcio
a1388dff7e Find the previous match in script editor when pressing Shift + Enter
This allows cycling through matches more efficiently.

(cherry picked from commit 8a1c5a8390)
2019-04-20 20:13:26 +02:00
Ignacio Etcheverry
3445984901 Replace a few #if/#elif with #ifdef and "#elif defined"
(cherry picked from commit ad2127a3e8)
2019-04-20 20:13:07 +02:00
Hugo Locurcio
bd2e707e2f Add support for type hints in non-default script editor templates
This also refactors template processing to avoid repetition.

This closes #27074.

(cherry picked from commit 00799fc8c2)
2019-04-20 20:12:53 +02:00
Michael Alexsander Silva Dias
72b4844d42 Fix crash when using the Tileset Editor when the given shape has no points
(cherry picked from commit 9501900e1b)
2019-04-20 20:10:54 +02:00
Robear Selwans
96222dedb5 Fixed an issue where changing the default_cursor on the RichTextLabel's meta_hover_ended caused the entire project to crash
(cherry picked from commit 84dfb3ff2d)
2019-04-20 20:09:57 +02:00
Guilherme Felipe
aedea36d0c Fix wrong blend of animation tree
Interpolation cannot use zero values, must use the values from the
animation to be blended.

(cherry picked from commit 45d97b9860)
2019-04-20 20:09:34 +02:00
Anish Bhobe
16097dd174 Added GLES2 RenderStorage Info calculations.
Proper counting code has been added to update info struct.

Extra: Added the render_info_capture calculations.
Fixes: #27273
(cherry picked from commit 4839b17f93)
2019-04-20 20:08:54 +02:00
Hugo Locurcio
afe6d654d5 Use the "warning" color for the "restart required" label
This makes the color match the warning icon placed besides the label.

(cherry picked from commit cca1fab1c4)
2019-04-20 20:08:37 +02:00
Vivatchai Kaveeta
59b2f02ac7 Fix import grayscale EXR
Fix #27299

(cherry picked from commit f0562a5ef6)
2019-04-20 20:08:09 +02:00
qarmin
8f537cfa19 Fix toggle visibility in SceneTreeDialog
(cherry picked from commit 2bc6ad670b)
2019-04-20 20:06:50 +02:00
Daniel Rakos
b439515d73 Fix skeleton reparenting to also work when the skeleton node is not a bone
Existing code only did the reparenting when the parent node was a bone. This
change fixes that, plus the reparenting code itself, which used the index of
the skin instead of the skin index itself to address the skeleton array.

(cherry picked from commit 1cf7ca87ce)
2019-04-20 20:06:03 +02:00
Timo Schwarzer
e31d6367ea Allow whitespaces in warning-ignore comments
(cherry picked from commit 7a0dfc04aa)
2019-04-20 20:05:25 +02:00
Will Nations
0e7de28b8d Add EditorInspector getter. Update Sub-Inspectors.
(cherry picked from commit c1b247e4d5)
2019-04-20 20:04:43 +02:00
qarmin
0f51f138b5 Fix perspective button hide when it should be actually disabled
(cherry picked from commit 2e5b6b5bde)
2019-04-20 20:04:21 +02:00
toasteater
511fb03e20 Respect keep_3d_linear when transparent_bg is on.
When transparent_bg is on, or the render target is too small,
Godot would skip postprocessing and disregard keep_3d_linear.

This fixes #26817.

(cherry picked from commit 7cbfce7a8c)
2019-04-20 20:03:16 +02:00
Andrii Doroshenko (Xrayez)
4574894e43 Reorder reverse caps characters table for string lower case conversion
The binary search algorithm used to lookup character codes in the table
relies that the data must be ordered. This fixes `to_lower()` string
method to convert upper case to lower case properly, so that the
algorithm doesn't terminate prematurely.

Co-authored-by: AndreevAndrei (avandrei) <avandrei@MacBookAAV.local>
(cherry picked from commit 34e6737413)
2019-04-20 20:02:45 +02:00
James Buck
f673bc1e3d Fix editor tooltip formatting
Removed unnecessary word wrap which caused broken tags and general
ugliness. Fixes #24926

(cherry picked from commit 8b1b2f6a4c)
2019-04-20 19:53:44 +02:00
Tomasz Chabora
7a94bac34e Document SceneTree.get_frame() and persistent in add_to_group
(cherry picked from commit 1e9128238e)
2019-04-19 13:12:30 +02:00
Rémi Verschelde
781b8a6c0f xatlas: Redo our custom changes, but properly documented
(cherry picked from commit 44f9a966e0)
2019-04-19 13:12:06 +02:00
Rémi Verschelde
a29700e034 xatlas: Revert to unmodified upstream code, add to COPYRIGHT
Imported by @reduz from b8ec29b6b6
Custom changes will be remade properly in the next commit.

(cherry picked from commit 1e39fee140)
2019-04-19 13:11:58 +02:00
Rémi Verschelde
def0820385 Drop unused thekla_atlas dependency
Since f12cb82 @reduz dropped the use of the thirdparty thekla_atlas
library, which is replaced by xatlas.

Fixes #28180.
Fixes #28182.

(cherry picked from commit 6640f397f1)
2019-04-19 13:11:13 +02:00
Rémi Verschelde
53d73f59eb doc: Drop unused <demos> tag
(cherry picked from commit 6af69f851a)
2019-04-19 13:10:25 +02:00
Soham Kar
aa0d4ffe51 Fixed copy&paste error #28117
Changed "left to right" in VSplitContainer to "top to bottom".

(cherry picked from commit aa8b2f4448)
2019-04-19 13:05:50 +02:00
Rémi Verschelde
af12b2d18b doc: Add note about VisibilityNotifier.is_on_screen after instantiation
Fixes #9430.

(cherry picked from commit 3fc1f7dfbe)
2019-04-19 13:05:36 +02:00
Siddharth
d99a0a5fba fixes #25707 documentation of v_scroll_speed
Fixes #25707

Update TextEdit.xml

(cherry picked from commit 3f2aac5e0a)
2019-04-19 13:05:20 +02:00
Michael Alexsander Silva Dias
f12848f9e1 Document String's 'is_valid_filename()'
(cherry picked from commit 70499faff8)
2019-04-19 13:05:06 +02:00
Tomasz Chabora
28f547a021 Added some documentation for Slider
(cherry picked from commit de4877e1fc)
2019-04-19 13:04:51 +02:00
Ryan Roden-Corrent
fd4a65df7b Fill out some of the AnimationNode docs.
The API docs for various animation nodes are pretty empty, yet the
tutorial at
https://docs.godotengine.org/en/latest/tutorials/animation/animation_tree.html
contains some details.

These details should be included in the API docs so looking up a
particular class actually provides some information rather than
requiring the user to hunt for a different tutorial.

This also links the AnimationTree tutorial and demo in the docs.
I've found the TPS demo to be the best resource so far for learning
how to use the AnimationTree. This should be easy to find if someone
looks up the AnimationTree API docs.

Finally, this fixes a param typo in AnimationNodeStateMachine.

(cherry picked from commit 584288a32c)
2019-04-19 13:04:22 +02:00
toasteater
8d87f624eb Improve RandomNumberGenerator docs.
Clarified behavior of a few methods. Added implementation notes so
that developers not familiar with RNGs are alerted to common pitfalls.

(cherry picked from commit ae1393acae)
2019-04-19 13:03:28 +02:00
Rémi Verschelde
a033640276 Merge pull request #27304 from hasahmed/patch-1
Added minimal documentation for _get_configuration_warning method
2019-04-12 12:47:54 +02:00
Hasan Yusuf Ahmed
0eeb1a7d0d Added minimal documentation for _get_configuration_warning method 2019-04-12 02:56:26 -04:00
Rémi Verschelde
b5d9099626 Revert "Properly setup seed in RNG"
This reverts commit 1dd72dca45.
As pointed out in #27171, it would break compatibility with 3.1.0.
2019-04-09 09:36:31 +02:00
Rémi Verschelde
6137387ede i18n: Sync translations with Weblate
(cherry picked from commit 3c4938d59a)
2019-04-08 12:38:15 +02:00
Rémi Verschelde
4243f8b32a Update AUTHORS and DONORS list
New contributors added to AUTHORS:
@pouleyKetchoupp, @qarmin

Thanks to all contributors and donors for making Godot possible!

(cherry picked from commit 4fad7608c4)
2019-04-07 21:48:00 +02:00
Rémi Verschelde
2fbc4219db Merge pull request #27754 from godotengine/fix_empty_types_in_json
Fix where json exported empty types
2019-04-07 11:54:23 +02:00
Bastiaan Olij
6226be9595 Fix where json exported empty types 2019-04-07 17:33:35 +10:00
Ignacio Etcheverry
b836420fd8 Mono: Buildsystem support for finding MSBuild from VS2019
(cherry picked from commit e82b2def8e)
2019-04-06 21:20:19 +02:00
ForLoveOfCats
37e62939e0 Mono: Make missing default constructor error more foolproof
(cherry picked from commit 444242a080)
2019-04-06 21:19:57 +02:00
ForLoveOfCats
276cd771f9 Mono: Makes GD.Convert take Variant.Type instead of int
(cherry picked from commit 46e79e6fad)
2019-04-06 21:19:36 +02:00
Marc Gilleron
c94e80a0a3 Fix wrong heights data used to compute min and max heights
(cherry picked from commit cdcdba704b)
2019-04-06 21:19:24 +02:00
Andrii Doroshenko (Xrayez)
948562261d Fix BitMap calculating incorrect true bit count
(cherry picked from commit b16946dea6)
2019-04-06 21:19:08 +02:00
Hugo Locurcio
67dc8cf252 Use the editor theme's accent color for 2D/3D selections and rotations
(cherry picked from commit d59b210aec)
2019-04-06 21:18:20 +02:00
Hugo Locurcio
93875a79bb Use the accent color to highlight selected text
This makes selections easier to see, while making them fit better
within the editor theme.

This closes #22552.

(cherry picked from commit 9ba6738719)
2019-04-06 21:18:06 +02:00
ShyRed
d538fb8d6c Remove hardcoded joint bias
Use user provided bias instead of hardcoded bias.

(cherry picked from commit 96093778ed)
2019-04-06 21:17:37 +02:00
qarmin
4ba90b9dda Show bones after creating
(cherry picked from commit 1b6e0d04f0)
2019-04-06 21:17:04 +02:00
qarmin
b5bd8e5f1b Fix deleting properties after deleting files
(cherry picked from commit 4cee053f7c)
2019-04-06 21:16:21 +02:00
shartte
a4610ca61e Clarify encoding used for text by the File class
(cherry picked from commit d1c095b30a)
2019-04-06 21:14:47 +02:00
PouleyKetchoupp
e8e57c49de Fixed Transform FLIP_Y and FLIP_Z set as identity transform
(cherry picked from commit 8828385792)
2019-04-06 21:14:04 +02:00
Rémi Verschelde
40ec89d24d GLES3: Fix regression in particles buffer initialization
Bug introduced in #26343 where `(float *)` was mistakenly converted
to `(uint8_t *)`, so we were getting `2` instead of `8`.

Fixes #27705.

(cherry picked from commit b182e038e7)
2019-04-06 21:13:07 +02:00
Rémi Verschelde
fd3845cdad Revert "Properly explain RPC/RSET mode failure."
This reverts commit 24b049ec9e.
It introduced regressions, see #27655.
2019-04-05 18:18:37 +02:00
Rémi Verschelde
2ad86122ac SCons: Fix OPUS_ARM_OPT flag applied for all android/iphone arches
The first 'if' always evaluated to true, as it evaluated values which are the default
ones for Android and iOS respectively, so even if one of them was overridden, the other
one would be true.

Fixes #27658.

(cherry picked from commit c2fb1c9f01)
2019-04-04 12:41:25 +02:00
Fabio Alessandrelli
24b049ec9e Properly explain RPC/RSET mode failure.
_can_call_mode used to call is_network_master/get_network_master
internally.
This would reset any potential last error set via ERR_EXPLAIN,
preventing it from being displayed correctly.
_can_call_mode now expects the node master ID to be passed instead.

(cherry picked from commit 95ad747dea)
2019-04-04 12:40:59 +02:00
Rémi Verschelde
c4ff65207d dist: Rename Linux mime type to follow system convention
Mime type definitions are usually named like the mime type they define,
i.e. x-godot-project in our case.
It was introduced with reverse DNS naming as that's what FlatHub favors,
so it will need to be renamed there.

(cherry picked from commit 7eabf4c8a3)
2019-04-03 17:02:46 +02:00
Rémi Verschelde
b502152195 SCons: Fix python3 compat for builtin_bullet=no
(cherry picked from commit 44f1b390a3)
2019-04-03 17:01:25 +02:00
marxin
4889c65922 Fix -Wnon-virtual-dtor warnings.
Example of the warning:
./core/script_language.h:198:7: warning: 'class ScriptCodeCompletionCache' has virtual functions and accessible non-virtual destructor [-Wnon-virtual-dtor]

(cherry picked from commit f9f2413e69)
2019-04-03 17:01:04 +02:00
Paulb23
4eefd2d581 Fixed not deselecting when clearing lineedit.
(cherry picked from commit bfba1e36bc)
2019-04-03 17:00:45 +02:00
clayjohn
2b3f2ee372 keep DEPTH from causing compile error in GLES2
(cherry picked from commit 5056b4a02c)
2019-04-03 17:00:21 +02:00
Leonard
929e3595c8 Apply proper offset to CSGMesh material and smooth group
(cherry picked from commit 209c2d2c80)
2019-04-03 16:59:48 +02:00
Daniel Rakos
dc928e6174 Fixed handling of depth texture so it's resolved and bound when needed
- Cleaned up and improved the code determining when we need to use a depth
  prepass (previously it wasn't executed in certain cases even if it was
  needed)
- Added code to prepare and bind the depth texture even when no depth prepass
  or MRTs (more precisely effect buffers) are used

Fixes #25870, #25535, and #25387.

(cherry picked from commit 849596c40c)
2019-04-03 16:56:11 +02:00
Allan Davis
38e5f94e19 Enable Mojave "dark mode" on the editor title bar
Enables "dark mode" in the editor and project selector title bars in macOS Mojave when selected in macOS System Preferences

(cherry picked from commit bba5716899)
2019-04-03 16:55:42 +02:00
ShyRed
dc259b95d8 Add Emission Mask to CPUParticle2D
Add ability to load emission masks to CPUParticle2D.

(cherry picked from commit dcd268e183)
2019-04-03 16:54:33 +02:00
Kanabenki
d59b97cca7 Keep binds for connected signals when changing node type
(cherry picked from commit a1e7febbb3)
2019-04-03 16:54:11 +02:00
Marcelo Fernandez
37c97d09e6 Fix MIDI Note Off missing on some devices
(cherry picked from commit ea0c398a19)
2019-04-03 16:53:47 +02:00
Chaosus
1dd72dca45 Properly setup seed in RNG
(cherry picked from commit 6280be46a6)
2019-04-03 16:53:30 +02:00
qarmin
29a6e7d306 Do not lose focus when moving through scene tree
(cherry picked from commit 138698e51f)
2019-04-03 16:52:27 +02:00
marxin
e3ae29e666 Enable warnings=extra on clang and GCC testers.
And remove 2 warnings from warnings=extra.

(cherry picked from commit e7f22ebdcd)
2019-04-03 16:52:01 +02:00
Daniel Spaniol
044ec35f62 Require return in all match branches
Before the parser only checked if the catch-all branch has a return in
order to determine if the entire match block has a return.

This code block was assumed to always return.

    match value:
        "test":
            print("test")
        _:
            return

Now as soon as one of the branches has no return, the entire match block
is marked to not have a return.

(cherry picked from commit 79176decd5)
2019-04-03 16:51:43 +02:00
Will Nations
8b1b8181b3 Fix inherited icons for script classes
(cherry picked from commit 2d106eb715)
2019-04-03 16:50:50 +02:00
Juan Linietsky
5ec63c62a1 Add documentation about nested YSort nodes.
(cherry picked from commit ed3586afa1)
2019-04-03 16:49:34 +02:00
Michael Alexsander Silva Dias
3ccb859711 Remove unused 'fav_rm' ToolButton in EditorFileDialog
(cherry picked from commit 579fffd97e)
2019-04-03 16:49:15 +02:00
Rémi Verschelde
7f691e8bb9 Merge pull request #27419 from GameCoderStudios/keep-custom-tracks-properties
Fix: Keep-custom-tracks option now keeps animation loop property and value track update mode.
2019-04-01 17:16:05 +02:00
Anish
f4578e1008 Prevents crash on loading unrecognized resources.
Editor crashes on trying to load resources with no loaders.
Simple check on the resource loader prevents using a null
resource loader.

Fixes: #27385
(cherry picked from commit 8ee31ace34)
2019-04-01 11:25:43 +02:00
Magnus Specht
1d05568aed Fixed unfinished max_lines handling for crash avoidance.
(cherry picked from commit 601acdf0e1)
2019-04-01 11:25:22 +02:00
Ignacio Etcheverry
e3e33daeb9 C#: Bindings generator now translates BBCode docs to XML comments
(cherry picked from commit 1ad16b3d4a)
2019-04-01 11:24:49 +02:00
thomas.herzog
3e0fc6906e [GDNative] fix NativeScript leak in editor
(cherry picked from commit 5fff7f741a)
2019-04-01 11:23:31 +02:00
thomas.herzog
cf8bd34941 [GDNative] remove spam at editor unfocus when using NativeScript
(cherry picked from commit 0e5b2b16ed)
2019-04-01 11:23:26 +02:00
Sebastian Hartte
08f3562fd1 Add support for new MSBuild directory naming introduced in VS 2019.
(cherry picked from commit 7440295ad1)
2019-04-01 11:22:47 +02:00
Sebastian Hartte
c7c8c0700f Fix parsing of generic type declarations in C# source files.
(cherry picked from commit 34366bc27f)
2019-04-01 11:21:07 +02:00
Daeil Kim
364aea1eff Ensure non-emitting particles not processed on entering tree
Also removed non-active CPUParticles(3d) from render list
Fixes #27066

(cherry picked from commit 24b7f08892)
2019-04-01 11:20:35 +02:00
Kanabenki
72433a35b1 Add missing check for 2d physics bounce and friction setters
The override check was already present for 3d physics but missing for 2d

(cherry picked from commit 3f64215a43)
2019-04-01 11:19:32 +02:00
piyushdagar
683c95ebdb Fixed CollisionObject signals do not trigger on Area
(cherry picked from commit d7387e8a68)
2019-04-01 11:19:13 +02:00
karroffel
03d00ca36b fix GDNative binding generation for object types
(cherry picked from commit 197d642014)
2019-04-01 11:18:51 +02:00
Vivatchai Kaveeta
dffc754a0a Fix order of transformation in GLTF import
From the gltf 2 spec, the order is R  * S. Previously we did S * R, which broke some mesh with non-uniform scale.

Fix #23356, Fix #14725

(cherry picked from commit 32dd9c67c6)
2019-04-01 11:18:23 +02:00
Paulb23
9ca440b763 Fix script editor attempting to set current line to -1 on script open
(cherry picked from commit 6f6d4a6c2e)
2019-04-01 11:17:58 +02:00
Guilherme Felipe
2f8362a2ab StateMachine: Fix sync mode
(cherry picked from commit d35eae166c)
2019-04-01 11:17:33 +02:00
Rémi Verschelde
2e9cf9829c Fix misplaced hint for interface/theme/accent_color
Supersedes #26992.

(cherry picked from commit b17c8c0396)
2019-04-01 11:17:08 +02:00
Michael Alexsander Silva Dias
1f9809032d Make bottom panel only try to hide editors when they're visible
(cherry picked from commit ebabb0ea65)
2019-04-01 11:15:57 +02:00
Fabio Alessandrelli
b2d13ba7b7 Enabled logging of failed image download.
(cherry picked from commit 37c0ac1d6d)
2019-04-01 11:15:30 +02:00
janglee123
9bd25ce7d2 fixed toggelling snap mode while transforming
(cherry picked from commit 05446e8b53)
2019-04-01 11:15:06 +02:00
K. S. Ernest (iFire) Lee
804b68c981 Fix scaling issue for texture button focus texture.
(cherry picked from commit 1971c09e5e)
2019-04-01 11:14:34 +02:00
Michael Alexsander Silva Dias
373e6aa17a Make size cache dirty when removing tiles in 'TileMap'
(cherry picked from commit be5f35dfa0)
2019-04-01 11:14:08 +02:00
Windy Darian
695f1a9185 Fix bone aabb calculation, which caused a skeletal mesh culling issue
There was a bug that could result in most bone aabb boxes ending up with
tiny size upon import and mess up with culling of skeletal meshes. This
fixes it.

(cherry picked from commit ff318d91ee)
2019-04-01 11:13:48 +02:00
qarmin
5650c1ecde Fix inspector update after changing anchor via buttons
(cherry picked from commit 8b391b9ab0)
2019-04-01 11:13:20 +02:00
bruvzg
754e1b073a [macOS] Fix hiDPI scaling support in OS.get_real_window_size and OS.set_window.size functions.
(cherry picked from commit 1b6330b125)
2019-04-01 11:11:50 +02:00
qarmin
ae3047d758 Show in tabs non default class icons
(cherry picked from commit 825a870f06)
2019-04-01 11:11:22 +02:00
Pedro Ciambra
f7f80b009b Implement source lookup for class_name defined classes
Previous to this, classes defined with class_name had no
behavior when ctrl-clicked in the editor.

Fixes #26882

(cherry picked from commit e8fe174616)
2019-04-01 11:10:32 +02:00
Robear Selwans
4fda05e15f Added the ability to change the default cursor property for the RichTextLabel component.
(cherry picked from commit b852a7a854)
2019-04-01 11:10:04 +02:00
Michael Alexsander Silva Dias
3d0dc81e9e Fix clearing scripts while multiple nodes are selected
(cherry picked from commit d3042d162d)
2019-04-01 11:09:32 +02:00
Paul Trojahn
0c3c4d61f7 Remove extraneous line breaks from text resources
Fixes #23539

(cherry picked from commit 9bbda4db2f)
2019-04-01 11:08:47 +02:00
Bojidar Marinov
08b685ab61 Add search box and size slider to GridMap (similar to TileMap's)
Closes #21536

(cherry picked from commit a9ac4c012c)
2019-04-01 11:07:50 +02:00
Bojidar Marinov
848bd54dae Fix renaming actions in the Project settings
Fixes #27113, a regression from 6daed7d122

(cherry picked from commit 699a3957ce)
2019-04-01 11:05:49 +02:00
Rémi Verschelde
d362e3eb11 i18n: Sync translations with Weblate
Also sync translation template.

(cherry picked from commit 472c8a7ba1)
2019-03-28 10:40:13 +01:00
Juan Linietsky
d26c3fca0c Add a "Request Docs" button to code editor.
(cherry picked from commit 6574c557c9)
2019-03-28 10:40:03 +01:00
Angeloss
589c5698a0 Fix: Keep custom tracks option now keeps animation loop property and value track update mode. 2019-03-27 11:32:41 -06:00
Jared
d02ee1ff0e Corrects small typo in atan2() documentation.
(cherry picked from commit 9838c4df7c)
2019-03-27 17:31:29 +01:00
Chris Bradfield
4740489a97 [DOC] Physics[2D]DirectBodyState updates
(cherry picked from commit bb2e6e3ed2)
2019-03-27 17:31:29 +01:00
Tomasz Chabora
e9796044ed Better documentation for some move_and_slide parameters
(cherry picked from commit 0e93714ff7)
2019-03-27 17:31:29 +01:00
homer666
f7ff3ec749 [DOCS] Add tutorial link to Particles2D
(cherry picked from commit bc8aa32593)
2019-03-27 17:31:29 +01:00
Sam Green
dbf2f0c31e Add logging around opengl es context creation. Ensure we can access project settings prior to creating our gl es context, so we can properly determine which driver to use.
(cherry picked from commit 440706814a)
2019-03-16 10:42:50 -07:00
Bojidar Marinov
0d8492cf9e Fix duplicated lines in GDScript bytecode
Fixes #26789

(cherry picked from commit b64f9f03f8)
2019-03-16 10:42:28 -07:00
Chris Bradfield
a51b2b8a82 [DOCS] minor classref updates
(cherry picked from commit 454b701e76)
2019-03-16 10:42:06 -07:00
Sebastian Hartte
d060cd4fef Don't crash when the saved editor state contains fewer viewports than currently supported.
(cherry picked from commit 7bab7fd777)
2019-03-16 10:41:45 -07:00
Andrettin
4023d52399 Made the tooltip position offset configurable
(cherry picked from commit 30c07c1ae1)
2019-03-16 10:41:08 -07:00
clayjohn
77c26d3260 linked tutorials in the classref
(cherry picked from commit 67446ff733)
2019-03-13 20:09:17 +01:00
Ignacio Etcheverry
57f19fd8ee C#: Update exports only in the editor
(cherry picked from commit 5e354162f1)
2019-03-13 20:07:29 +01:00
Rémi Verschelde
51e04c588b Bump version to 3.1.1-devel 2019-03-13 18:44:46 +01:00
6818 changed files with 529396 additions and 3991241 deletions

32
.appveyor.yml Normal file
View File

@@ -0,0 +1,32 @@
os: Visual Studio 2015
environment:
HOME: "%HOMEDRIVE%%HOMEPATH%"
PYTHON: C:\Python27
SCONS_CACHE_ROOT: "%HOME%\\scons_cache"
SCONS_CACHE_LIMIT: 1024
matrix:
- VS: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
GD_PLATFORM: windows
TOOLS: yes
TARGET: release_debug
ARCH: amd64
cache:
- "%SCONS_CACHE_ROOT%"
install:
- SET "PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
- pip install -U wheel # needed for pip install scons to work, otherwise a flag is missing
- pip install scons==3.0.1
- if defined VS call "%VS%" %ARCH% # if defined - so we can also use mingw
before_build:
- echo %GD_PLATFORM%
- python --version
- scons --version
- cl.exe
- SET "SCONS_CACHE=%SCONS_CACHE_ROOT%\master"
build_script:
- scons platform=%GD_PLATFORM% target=%TARGET% tools=%TOOLS% debug_symbols=no verbose=yes progress=no gdnative_wrapper=yes

View File

@@ -1,41 +1,31 @@
# Commented out parameters are those with the same value as base LLVM style.
# 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 13.0).
# 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
# AlignArrayOfStructures: None
# AlignConsecutiveMacros: None
# AlignConsecutiveAssignments: None
# AlignConsecutiveBitFields: None
# AlignConsecutiveDeclarations: None
# AlignConsecutiveAssignments: false
# AlignConsecutiveDeclarations: false
# AlignEscapedNewlines: Right
AlignOperands: DontAlign
# AlignOperands: true
AlignTrailingComments: false
# AllowAllArgumentsOnNextLine: true
# AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
# AllowShortEnumsOnASingleLine: true
# AllowShortBlocksOnASingleLine: Never
# AllowShortCaseLabelsOnASingleLine: false
# AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
# AllowShortLambdasOnASingleLine: All
# AllowShortIfStatementsOnASingleLine: Never
AllowShortIfStatementsOnASingleLine: true
# AllowShortLoopsOnASingleLine: false
# AlwaysBreakAfterDefinitionReturnType: None
# AlwaysBreakAfterReturnType: None
# AlwaysBreakBeforeMultilineStrings: false
# AlwaysBreakTemplateDeclarations: MultiLine
# AttributeMacros:
# - __capability
# AlwaysBreakTemplateDeclarations: false
# BinPackArguments: true
# BinPackParameters: true
# BraceWrapping:
# AfterCaseLabel: false
# AfterClass: false
# AfterControlStatement: Never
# AfterControlStatement: false
# AfterEnum: false
# AfterFunction: false
# AfterNamespace: false
@@ -45,18 +35,14 @@ AllowShortFunctionsOnASingleLine: Inline
# AfterExternBlock: false
# BeforeCatch: false
# BeforeElse: false
# BeforeLambdaBody: false
# BeforeWhile: false
# IndentBraces: false
# SplitEmptyFunction: true
# SplitEmptyRecord: true
# SplitEmptyNamespace: true
# BreakBeforeBinaryOperators: None
# BreakBeforeConceptDeclarations: true
# BreakBeforeBraces: Attach
# BreakBeforeInheritanceComma: false
# BreakInheritanceList: BeforeColon
# BreakBeforeTernaryOperators: true
BreakBeforeTernaryOperators: false
# BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: AfterColon
# BreakStringLiterals: true
@@ -67,19 +53,14 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
Cpp11BracedListStyle: false
# DeriveLineEnding: true
# DerivePointerAlignment: false
# DisableFormat: false
# EmptyLineAfterAccessModifier: Never
# EmptyLineBeforeAccessModifier: LogicalBlock
# ExperimentalAutoDetectBinPacking: false
# FixNamespaceComments: true
# ForEachMacros:
# - foreach
# - Q_FOREACH
# - BOOST_FOREACH
# IfMacros:
# - KJ_IF_MAYBE
# IncludeBlocks: Preserve
IncludeCategories:
- Regex: '".*"'
@@ -89,21 +70,13 @@ IncludeCategories:
- Regex: '^<.*'
Priority: 3
# IncludeIsMainRegex: '(Test)?$'
# IncludeIsMainSourceRegex: ''
# IndentAccessModifiers: false
IndentCaseLabels: true
# IndentCaseBlocks: false
# IndentGotoLabels: true
# IndentPPDirectives: None
# IndentExternBlock: AfterExternBlock
# IndentRequires: false
IndentWidth: 4
# IndentWrappedFunctionNames: false
# InsertTrailingCommas: None
# JavaScriptQuotes: Leave
# JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
# LambdaBodyIndentation: Signature
# KeepEmptyLinesAtTheStartOfBlocks: true
# MacroBlockBegin: ''
# MacroBlockEnd: ''
# MaxEmptyLinesToKeep: 1
@@ -113,77 +86,42 @@ KeepEmptyLinesAtTheStartOfBlocks: false
# PenaltyBreakComment: 300
# PenaltyBreakFirstLessLess: 120
# PenaltyBreakString: 1000
# PenaltyBreakTemplateDeclaration: 10
# PenaltyExcessCharacter: 1000000
# PenaltyReturnTypeOnItsOwnLine: 60
# PenaltyIndentedWhitespace: 0
# PointerAlignment: Right
# PPIndentWidth: -1
# ReferenceAlignment: Pointer
# RawStringFormats:
# - Delimiter: pb
# Language: TextProto
# BasedOnStyle: google
# ReflowComments: true
# ShortNamespaceLines: 1
# SortIncludes: CaseSensitive
# SortJavaStaticImport: Before
# SortIncludes: true
# SortUsingDeclarations: true
# SpaceAfterCStyleCast: false
# SpaceAfterLogicalNot: false
# SpaceAfterTemplateKeyword: true
# SpaceBeforeAssignmentOperators: true
# SpaceBeforeCaseColon: false
# SpaceBeforeCpp11BracedList: false
# SpaceBeforeCtorInitializerColon: true
# SpaceBeforeInheritanceColon: true
# SpaceBeforeParens: ControlStatements
# SpaceAroundPointerQualifiers: Default
# SpaceBeforeRangeBasedForLoopColon: true
# SpaceInEmptyParentheses: false
# SpacesBeforeTrailingComments: 1
# SpaceInEmptyBlock: false
# SpaceInEmptyParentheses: false
# SpacesBeforeTrailingComments: 1
# SpacesInAngles: Never
# SpacesInContainerLiterals: true
# SpacesInConditionalStatement: false
# SpacesInAngles: false
# SpacesInContainerLiterals: true
# SpacesInCStyleCastParentheses: false
## Godot TODO: We'll want to use a min of 1, but we need to see how to fix
## our comment capitalization at the same time.
SpacesInLineCommentPrefix:
Minimum: 0
Maximum: -1
# SpacesInParentheses: false
# SpacesInSquareBrackets: false
# SpaceBeforeSquareBrackets: false
# BitFieldColonSpacing: Both
# StatementAttributeLikeMacros:
# - Q_EMIT
# StatementMacros:
# - Q_UNUSED
# - QT_REQUIRE_VERSION
TabWidth: 4
# UseCRLF: false
UseTab: Always
# WhitespaceSensitiveMacros:
# - STRINGIZE
# - PP_STRINGIZE
# - BOOST_PP_STRINGIZE
# - NS_SWIFT_NAME
# - CF_SWIFT_NAME
---
### C++ specific config ###
Language: Cpp
Standard: c++14
Standard: Cpp03
---
### ObjC specific config ###
Language: ObjC
# ObjCBinPackProtocolList: Auto
Standard: Cpp03
ObjCBlockIndentWidth: 4
# ObjCBreakBeforeNestedBlockParam: true
# ObjCSpaceAfterProperty: false
# ObjCSpaceBeforeProtocolList: true
---
### Java specific config ###
Language: Java
# BreakAfterJavaFieldAnnotations: false
JavaImportGroups: ['org.godotengine', 'android', 'androidx', 'com.android', 'com.google', 'java', 'javax']
...

View File

@@ -1,44 +0,0 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-nullptr,readability-braces-around-statements'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: none
CheckOptions:
CheckOptions:
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: '1'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-bool-literals.IgnoreMacros
value: '0'
- key: modernize-use-default-member-init.IgnoreMacros
value: '0'
- key: modernize-use-default-member-init.UseAssignment
value: '1'
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
- key: readability-braces-around-statements.ShortStatementLines
value: '0'
...

View File

@@ -9,15 +9,10 @@ insert_final_newline = true
[*.{cpp,hpp,c,h,mm}]
trim_trailing_whitespace = true
[{*.gradle,AndroidManifest.xml}]
[{*.{py,cs},SCsub}]
indent_style = space
indent_size = 4
[{*.py,SConstruct,SCsub}]
indent_style = space
indent_size = 4
# YAML requires indentation with spaces instead of tabs.
[*.{yml,yaml}]
[.travis.yml]
indent_style = space
indent_size = 2

21
.gitattributes vendored
View File

@@ -1,17 +1,12 @@
# Properly detect languages on Github
*.h linguist-language=cpp
*.inc linguist-language=cpp
thirdparty/* linguist-vendored
drivers/* linguist-vendored
# Normalize EOL for all files that Git considers text files
* text=auto eol=lf
# Except for bat files, which are Windows only files
*.bat eol=crlf
# The above only works properly for Git 2.10+, so for older versions
# we need to manually list the binary files we don't want modified.
*.icns binary
*.ico binary
*.jar binary
*.png binary
*.ttf binary
*.cpp eol=lf
*.mm eol=lf
*.h eol=lf
*.py eol=lf
*.hpp eol=lf
*.xml eol=lf
*.natvis eol=lf

174
.github/CODEOWNERS vendored
View File

@@ -1,174 +0,0 @@
# Lines starting with '#' are comments.
# Each line is a file pattern followed by one or more owners.
# Owners can be @users, @org/teams or emails
# Buildsystem
.* @godotengine/buildsystem
.github/ @godotengine/buildsystem
*.py @godotengine/buildsystem
SConstruct @godotengine/buildsystem
SCsub @godotengine/buildsystem
# Core
/core/ @godotengine/core
/core/crypto/ @godotengine/network
/core/input*.* @godotengine/input
# Doc
/doc/ @godotengine/documentation
doc_classes/* @godotengine/documentation
# Drivers
## Audio
/drivers/alsa/ @godotengine/audio
/drivers/alsamidi/ @godotengine/audio
/drivers/coreaudio/ @godotengine/audio
/drivers/coremidi/ @godotengine/audio
/drivers/pulseaudio/ @godotengine/audio
/drivers/wasapi/ @godotengine/audio
/drivers/winmidi/ @godotengine/audio
/drivers/xaudio2/ @godotengine/audio
## Rendering
/drivers/dummy/ @godotengine/rendering
/drivers/gl_context/ @godotengine/rendering
/drivers/gles2/ @godotengine/rendering
/drivers/gles3/ @godotengine/rendering
/drivers/gles_common/ @godotengine/rendering
## OS
/drivers/unix/ @godotengine/_platforms
/drivers/windows/ @godotengine/windows
## Misc
/drivers/png/ @godotengine/import
# Editor
/editor/*debugger* @godotengine/debugger
/editor/icons/ @godotengine/usability
/editor/import/ @godotengine/import
/editor/plugins/*2d_*.* @godotengine/2d-editor
/editor/plugins/script_*.* @godotengine/script-editor
/editor/plugins/*shader*.* @godotengine/shaders
/editor/code_editor.* @godotengine/script-editor
/editor/*dock*.* @godotengine/docks
# Main
/main/ @godotengine/core
/main/tests/ @godotengine/tests
# Misc
/misc/ @godotengine/buildsystem
# Modules
## Audio (+ video)
/modules/minimp3/ @godotengine/audio
/modules/ogg/ @godotengine/audio
/modules/opus/ @godotengine/audio
/modules/stb_vorbis/ @godotengine/audio
/modules/theora/ @godotengine/audio
/modules/vorbis/ @godotengine/audio
/modules/webm/ @godotengine/audio
## Import
/modules/basis_universal/ @godotengine/import
/modules/bmp/ @godotengine/import
/modules/cvtt/ @godotengine/import
/modules/dds/ @godotengine/import
/modules/etc/ @godotengine/import
/modules/fbx/ @godotengine/import
/modules/gltf/ @godotengine/import
/modules/hdr/ @godotengine/import
/modules/jpg/ @godotengine/import
/modules/pvr/ @godotengine/import
/modules/squish/ @godotengine/import
/modules/svg/ @godotengine/import
/modules/tga/ @godotengine/import
/modules/tinyexr/ @godotengine/import
/modules/webp/ @godotengine/import
## Network
/modules/enet/ @godotengine/network
/modules/mbedtls/ @godotengine/network
/modules/upnp/ @godotengine/network
/modules/webrtc/ @godotengine/network
/modules/websocket/ @godotengine/network
## Rendering
/modules/denoise/ @godotengine/rendering
/modules/glslang/ @godotengine/rendering
/modules/lightmapper_cpu/ @godotengine/rendering
/modules/meshoptimizer/ @godotengine/rendering
/modules/raycast/ @godotengine/rendering
/modules/vhacd/ @godotengine/rendering
/modules/xatlas_unwrap/ @godotengine/rendering
## Scripting
/modules/gdnative/ @godotengine/gdnative
/modules/gdscript/ @godotengine/gdscript
/modules/jsonrpc/ @godotengine/gdscript
/modules/mono/ @godotengine/mono
/modules/visual_script/ @godotengine/visualscript
## Text
/modules/freetype/ @godotengine/buildsystem
/modules/gdnative/text/ @godotengine/gui-nodes
/modules/text_server_adv/ @godotengine/gui-nodes
/modules/text_server_fb/ @godotengine/gui-nodes
## XR
/modules/camera/ @godotengine/xr
/modules/gdnative/arvr/ @godotengine/xr
/modules/mobile_vr/ @godotengine/xr
/modules/webxr/ @godotengine/xr
## Misc
/modules/bullet/ @godotengine/physics
/modules/csg/ @godotengine/3d-nodes
/modules/gridmap/ @godotengine/3d-nodes
/modules/opensimplex/ @godotengine/3d-nodes
/modules/recast/ @godotengine/navigation
/modules/regex/ @godotengine/core
# Platform
/platform/android/ @godotengine/android
/platform/iphone/ @godotengine/ios
/platform/javascript/ @godotengine/html5
/platform/x11/ @godotengine/linux-bsd
/platform/osx/ @godotengine/macos
/platform/uwp/ @godotengine/uwp
/platform/windows/ @godotengine/windows
# Scene
/scene/2d/ @godotengine/2d-nodes
/scene/3d/ @godotengine/3d-nodes
/scene/animation/ @godotengine/animation
/scene/audio/ @godotengine/audio
/scene/debugger/ @godotengine/debugger
/scene/gui/ @godotengine/gui-nodes
/scene/main/ @godotengine/core
/scene/resources/default_theme/ @godotengine/gui-nodes
/scene/resources/font.* @godotengine/gui-nodes
/scene/resources/visual_shader*.* @godotengine/shaders
# Servers
/servers/arvr* @godotengine/xr
/servers/audio* @godotengine/audio
/servers/camera* @godotengine/xr
/servers/physics* @godotengine/physics
/servers/visual* @godotengine/rendering
# Thirdparty
/thirdparty/ @godotengine/buildsystem

View File

@@ -1,18 +0,0 @@
---
name: Bug report
about: Report a bug in Godot
title: ''
labels: ''
assignees: ''
---
**Godot version:**
**OS/device including version:**
**Issue description:**
**Steps to reproduce:**
**Minimal reproduction project:**

View File

@@ -1,19 +0,0 @@
---
name: Feature / Enhancement Request
about: Adding new features or improving existing ones.
title: 'IMPORTANT: This repository no longer accepts feature / enhancement requests.'
labels: ''
assignees: ''
---
**IMPORTANT, PLEASE READ**
Feature / Enhancement requests are no longer accepted in the main Godot repository.
Please open an item by filling the relevant fields in the *Proposals* repository:
https://github.com/godotengine/godot-proposals/issues/new/choose
Do not submit to this repository or your issue will be closed.
**IMPORTANT, PLEASE READ**

View File

@@ -1,36 +0,0 @@
name: Build Godot
description: Build Godot with the provided options.
inputs:
target:
description: The scons target (debug/release_debug/release).
default: "debug"
tools:
description: If tools are to be built.
default: false
tests:
description: If tests are to be built.
default: false
platform:
description: The Godot platform to build.
required: false
sconsflags:
default: ""
scons-cache:
description: The scons cache path.
default: "${{ github.workspace }}/.scons-cache/"
scons-cache-limit:
description: The scons cache size limit.
default: 4096
runs:
using: "composite"
steps:
- name: Scons Build
shell: sh
env:
SCONSFLAGS: ${{ inputs.sconsflags }}
SCONS_CACHE: ${{ inputs.scons-cache }}
SCONS_CACHE_LIMIT: ${{ inputs.scons-cache-limit }}
run: |
echo "Building with flags:" ${{ env.SCONSFLAGS }}
scons p=${{ inputs.platform }} target=${{ inputs.target }} tools=${{ inputs.tools }} tests=${{ inputs.tests }} --jobs=2 ${{ env.SCONSFLAGS }}
ls -l bin/

View File

@@ -1,22 +0,0 @@
name: Setup Godot build cache
description: Setup Godot build cache.
inputs:
cache-name:
description: The cache base name (job name by default).
default: "${{github.job}}"
scons-cache:
description: The scons cache path.
default: "${{github.workspace}}/.scons-cache/"
runs:
using: "composite"
steps:
# Upload cache on completion and check it out now
- name: Load .scons_cache directory
uses: actions/cache@v2
with:
path: ${{inputs.scons-cache}}
key: ${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}}
restore-keys: |
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}}
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}

View File

@@ -1,27 +0,0 @@
name: Setup python and scons
description: Setup python, install the pip version of scons.
inputs:
python-version:
description: The python version to use.
default: "3.x"
python-arch:
description: The python architecture.
default: "x64"
runs:
using: "composite"
steps:
# Use python 3.x release (works cross platform)
- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
# Semantic version range syntax or exact version of a Python version
python-version: ${{ inputs.python-version }}
# Optional - x64 or x86 architecture, defaults to x64
architecture: ${{ inputs.python-arch }}
- name: Setup scons
shell: bash
run: |
python -c "import sys; print(sys.version)"
python -m pip install scons
scons --version

View File

@@ -1,19 +0,0 @@
name: Upload Godot artifact
description: Upload the Godot artifact.
inputs:
name:
description: The artifact name.
default: "${{ github.job }}"
path:
description: The path to upload.
required: true
default: "bin/*"
runs:
using: "composite"
steps:
- name: Upload Godot Artifact
uses: actions/upload-artifact@v2
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}
retention-days: 14

View File

@@ -1,65 +0,0 @@
name: 🤖 Android Builds
on: [push, pull_request]
# Global Settings
env:
GODOT_BASE_BRANCH: 3.4
SCONSFLAGS: verbose=yes warnings=all werror=yes debug_symbols=no
concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-android
cancel-in-progress: true
jobs:
android-template:
runs-on: "ubuntu-20.04"
name: Template (target=release, tools=no)
steps:
- uses: actions/checkout@v2
# Azure repositories are not reliable, we need to prevent azure giving us packages.
- name: Make apt sources.list use the default Ubuntu repositories
run: |
sudo rm -f /etc/apt/sources.list.d/*
sudo cp -f misc/ci/sources.list /etc/apt/sources.list
sudo apt-get update
- name: Set up Java 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Setup Godot build cache
uses: ./.github/actions/godot-cache
continue-on-error: true
- name: Setup python and scons
uses: ./.github/actions/godot-deps
- name: Compilation (armv7)
uses: ./.github/actions/godot-build
with:
sconsflags: ${{ env.SCONSFLAGS }} android_arch=armv7
platform: android
target: release
tools: false
- name: Compilation (arm64v8)
uses: ./.github/actions/godot-build
with:
sconsflags: ${{ env.SCONSFLAGS }} android_arch=arm64v8
platform: android
target: release
tools: false
- name: Generate Godot templates
run: |
cd platform/android/java
./gradlew generateGodotTemplates
cd ../../..
ls -l bin/
- name: Upload artifact
uses: ./.github/actions/upload-artifact

View File

@@ -1,37 +0,0 @@
name: 🍏 iOS Builds
on: [push, pull_request]
# Global Settings
env:
GODOT_BASE_BRANCH: 3.4
SCONSFLAGS: verbose=yes warnings=all werror=yes debug_symbols=no
concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-ios
cancel-in-progress: true
jobs:
ios-template:
runs-on: "macos-latest"
name: Template (target=release, tools=no)
steps:
- uses: actions/checkout@v2
- name: Setup Godot build cache
uses: ./.github/actions/godot-cache
continue-on-error: true
- name: Setup python and scons
uses: ./.github/actions/godot-deps
- name: Compilation (armv7)
uses: ./.github/actions/godot-build
with:
sconsflags: ${{ env.SCONSFLAGS }}
platform: iphone
target: release
tools: false
- name: Upload artifact
uses: ./.github/actions/upload-artifact

View File

@@ -1,57 +0,0 @@
name: 🌐 JavaScript Builds
on: [push, pull_request]
# Global Settings
env:
GODOT_BASE_BRANCH: 3.4
SCONSFLAGS: verbose=yes warnings=all werror=yes debug_symbols=no
EM_VERSION: 2.0.25
EM_CACHE_FOLDER: "emsdk-cache"
concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-javascript
cancel-in-progress: true
jobs:
javascript-template:
runs-on: "ubuntu-20.04"
name: Template (target=release, tools=no)
steps:
- uses: actions/checkout@v2
# Additional cache for Emscripten generated system libraries
- name: Load Emscripten cache
id: javascript-template-emscripten-cache
uses: actions/cache@v2
with:
path: ${{env.EM_CACHE_FOLDER}}
key: ${{env.EM_VERSION}}-${{github.job}}
- name: Set up Emscripten latest
uses: mymindstorm/setup-emsdk@v10
with:
version: ${{env.EM_VERSION}}
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
- name: Verify Emscripten setup
run: |
emcc -v
- name: Setup Godot build cache
uses: ./.github/actions/godot-cache
continue-on-error: true
- name: Setup python and scons
uses: ./.github/actions/godot-deps
- name: Compilation
uses: ./.github/actions/godot-build
with:
sconsflags: ${{ env.SCONSFLAGS }}
platform: javascript
target: release
tools: false
- name: Upload artifact
uses: ./.github/actions/upload-artifact

View File

@@ -1,137 +0,0 @@
name: 🐧 Linux Builds
on: [push, pull_request]
# Global Settings
env:
GODOT_BASE_BRANCH: 3.4
SCONSFLAGS: verbose=yes warnings=all werror=yes
concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-linux
cancel-in-progress: true
jobs:
build-linux:
runs-on: "ubuntu-20.04"
name: ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- name: Editor w/ Mono (target=release_debug, tools=yes)
cache-name: linux-editor-mono
target: release_debug
tools: true
sconsflags: module_mono_enabled=yes mono_static=yes mono_glue=no
bin: "./bin/godot.x11.opt.tools.64.mono"
build-mono: true
artifact: true
- name: Editor and sanitizers (target=debug, tools=yes, use_asan=yes, use_ubsan=yes)
cache-name: linux-editor-sanitizers
target: debug
tools: true
sconsflags: use_asan=yes use_ubsan=yes
test: true
bin: "./bin/godot.x11.tools.64s"
build-mono: false
# Skip 2GiB artifact speeding up action.
artifact: false
- name: Template w/ Mono (target=release, tools=no)
cache-name: linux-template-mono
target: release
tools: false
sconsflags: module_mono_enabled=yes mono_static=yes mono_glue=no debug_symbols=no
build-mono: false
artifact: true
steps:
- uses: actions/checkout@v2
- name: Linux dependencies
shell: bash
run: |
# Azure repositories are not reliable, we need to prevent azure giving us packages.
sudo rm -f /etc/apt/sources.list.d/*
sudo cp -f misc/ci/sources.list /etc/apt/sources.list
sudo apt-get update
# The actual dependencies
sudo apt-get install build-essential pkg-config libx11-dev libxcursor-dev \
libxinerama-dev libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev \
libdbus-1-dev libudev-dev libxi-dev libxrandr-dev yasm xvfb wget unzip
- name: Setup Godot build cache
uses: ./.github/actions/godot-cache
with:
cache-name: ${{ matrix.cache-name }}
continue-on-error: true
- name: Setup python and scons
uses: ./.github/actions/godot-deps
- name: Compilation
uses: ./.github/actions/godot-build
with:
sconsflags: ${{ env.SCONSFLAGS }} ${{ matrix.sconsflags }}
platform: linuxbsd
target: ${{ matrix.target }}
tools: ${{ matrix.tools }}
# Generate mono glue
- name: Generate Mono glue code
if: ${{ matrix.build-mono }}
run: |
DRI_PRIME=0 xvfb-run ${{ matrix.bin }} --generate-mono-glue modules/mono/glue || true
# Rebuild with mono
- name: Compilation (mono_glue=yes)
uses: ./.github/actions/godot-build
if: ${{ matrix.build-mono }}
with:
sconsflags: ${{ env.SCONSFLAGS }} ${{ matrix.sconsflags }} mono_glue=yes
platform: linuxbsd
target: ${{ matrix.target }}
tools: ${{ matrix.tools }}
# Download and extract zip archive with project, folder is renamed to be able to easy change used project
- name: Download test project
if: ${{ matrix.test }}
run: |
wget https://github.com/godotengine/regression-test-project/archive/3.4.zip
unzip 3.4.zip
mv "regression-test-project-3.4" "test_project"
# Editor is quite complicated piece of software, so it is easy to introduce bug here
- name: Open and close editor
if: ${{ matrix.test }}
run: |
DRI_PRIME=0 xvfb-run ${{ matrix.bin }} --audio-driver Dummy -e -q --path test_project 2>&1 | tee sanitizers_log.txt || true
misc/scripts/check_ci_log.py sanitizers_log.txt
# Run test project
- name: Run project
if: ${{ matrix.test }}
run: |
DRI_PRIME=0 xvfb-run ${{ matrix.bin }} 30 --video-driver GLES3 --audio-driver Dummy --path test_project 2>&1 | tee sanitizers_log.txt || true
misc/scripts/check_ci_log.py sanitizers_log.txt
# Check class reference
- name: Check for class reference updates
if: ${{ matrix.test }}
run: |
echo "Running --doctool to see if this changes the public API without updating the documentation."
echo -e "If a diff is shown, it means that your code/doc changes are incomplete and you should update the class reference with --doctool.\n\n"
DRI_PRIME=0 xvfb-run ${{ matrix.bin }} --doctool . 2>&1 > /dev/null || true
git diff --color --exit-code && ! git ls-files --others --exclude-standard | sed -e 's/^/New doc file missing in PR: /' | grep 'xml$'
- name: Prepare artifact
if: ${{ matrix.artifact }}
run: |
strip bin/godot.*
- name: Upload artifact
uses: ./.github/actions/upload-artifact
if: ${{ matrix.artifact }}
with:
name: ${{ matrix.cache-name }}

View File

@@ -1,55 +0,0 @@
name: 🍎 macOS Builds
on: [push, pull_request]
# Global Settings
env:
GODOT_BASE_BRANCH: 3.4
SCONSFLAGS: verbose=yes warnings=all werror=yes debug_symbols=no
concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-macos
cancel-in-progress: true
jobs:
build-macos:
runs-on: "macos-latest"
name: ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- name: Editor (target=release_debug, tools=yes)
cache-name: macos-editor
target: release_debug
tools: true
bin: "./bin/godot.osx.opt.tools.64"
- name: Template (target=release, tools=no)
cache-name: macos-template
target: release
tools: false
steps:
- uses: actions/checkout@v2
- name: Setup Godot build cache
uses: ./.github/actions/godot-cache
with:
cache-name: ${{ matrix.cache-name }}
continue-on-error: true
- name: Setup python and scons
uses: ./.github/actions/godot-deps
- name: Compilation
uses: ./.github/actions/godot-build
with:
sconsflags: ${{ env.SCONSFLAGS }}
platform: osx
target: ${{ matrix.target }}
tools: ${{ matrix.tools }}
- name: Upload artifact
uses: ./.github/actions/upload-artifact
with:
name: ${{ matrix.cache-name }}

View File

@@ -1,61 +0,0 @@
name: ☁ Server Builds
on: [push, pull_request]
# Global Settings
env:
GODOT_BASE_BRANCH: 3.4
SCONSFLAGS: verbose=yes warnings=all werror=yes debug_symbols=no module_mono_enabled=yes mono_static=yes mono_glue=no
concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-server
cancel-in-progress: true
jobs:
build-server:
runs-on: "ubuntu-20.04"
name: ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- name: Linux Headless w/ Mono (target=release_debug, tools=yes)
cache-name: server-editor-mono
target: release_debug
tools: true
- name: Linux Server w/ Mono (target=release, tools=no)
cache-name: server-template-mono
target: release
tools: false
steps:
- uses: actions/checkout@v2
- name: Linux dependencies
shell: bash
run: |
# Azure repositories are not reliable, we need to prevent azure giving us packages.
sudo rm -f /etc/apt/sources.list.d/*
sudo cp -f misc/ci/sources.list /etc/apt/sources.list
sudo apt-get update
# The actual dependencies
sudo apt-get install build-essential pkg-config libx11-dev libxcursor-dev \
libxinerama-dev libgl1-mesa-dev libglu-dev libasound2-dev libpulse-dev \
libdbus-1-dev libudev-dev libxi-dev libxrandr-dev yasm xvfb wget unzip
- name: Setup Godot build cache
uses: ./.github/actions/godot-cache
with:
cache-name: ${{ matrix.cache-name }}
continue-on-error: true
- name: Setup python and scons
uses: ./.github/actions/godot-deps
- name: Compilation
uses: ./.github/actions/godot-build
with:
sconsflags: ${{ env.SCONSFLAGS }} ${{ matrix.sconsflags }}
platform: server
target: ${{ matrix.target }}
tools: ${{ matrix.tools }}

View File

@@ -1,49 +0,0 @@
name: 📊 Static Checks
on: [push, pull_request]
jobs:
static-checks:
name: Static Checks (clang-format, black format, file format, documentation checks)
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
# Azure repositories are not reliable, we need to prevent Azure giving us packages.
- name: Make apt sources.list use the default Ubuntu repositories
run: |
sudo rm -f /etc/apt/sources.list.d/*
sudo cp -f misc/ci/sources.list /etc/apt/sources.list
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main"
sudo apt-get update
- name: Install dependencies
run: |
sudo apt-get install -qq dos2unix recode clang-format-13
sudo update-alternatives --remove-all clang-format
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-13 100
sudo pip3 install black==21.10b0 pygments
- name: File formatting checks (file_format.sh)
run: |
bash ./misc/scripts/file_format.sh
- name: Style checks via clang-format (clang_format.sh)
run: |
bash ./misc/scripts/clang_format.sh
- name: Python style checks via black (black_format.sh)
run: |
bash ./misc/scripts/black_format.sh
- name: JavaScript style and documentation checks via ESLint and JSDoc
run: |
cd platform/javascript
npm ci
npm run lint
npm run docs -- -d dry-run
- name: Documentation checks
run: |
doc/tools/make_rst.py --dry-run doc/classes modules

View File

@@ -1,59 +0,0 @@
name: 🏁 Windows Builds
on: [push, pull_request]
# Global Settings
# SCONS_CACHE for windows must be set in the build environment
env:
GODOT_BASE_BRANCH: 3.4
SCONSFLAGS: verbose=yes warnings=all werror=yes debug_symbols=no
SCONS_CACHE_MSVC_CONFIG: true
concurrency:
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-windows
cancel-in-progress: true
jobs:
build-windows:
# Windows 10 with latest image
runs-on: "windows-latest"
name: ${{ matrix.name }}
strategy:
fail-fast: false
matrix:
include:
- name: Editor (target=release_debug, tools=yes)
cache-name: windows-editor
target: release_debug
tools: true
bin: "./bin/godot.windows.opt.tools.64.exe"
- name: Template (target=release, tools=no)
cache-name: windows-template
target: release
tools: false
steps:
- uses: actions/checkout@v2
- name: Setup Godot build cache
uses: ./.github/actions/godot-cache
with:
cache-name: ${{ matrix.cache-name }}
continue-on-error: true
- name: Setup python and scons
uses: ./.github/actions/godot-deps
- name: Compilation
uses: ./.github/actions/godot-build
with:
sconsflags: ${{ env.SCONSFLAGS }}
platform: windows
target: ${{ matrix.target }}
tools: ${{ matrix.tools }}
scons-cache-limit: 3072
- name: Upload artifact
uses: ./.github/actions/upload-artifact
with:
name: ${{ matrix.cache-name }}

81
.gitignore vendored
View File

@@ -1,6 +1,5 @@
# Godot auto generated files
*.gen.*
.import/
# Documentation generated by doxygen or from classes.xml
doc/_build/
@@ -8,20 +7,18 @@ doc/_build/
# Javascript specific
*.bc
# CLion
cmake-build-debug
# Android specific
.gradle
local.properties
*.iml
.idea
.gradletasknamecache
project.properties
platform/android/java/app/libs/*
platform/android/java/build.gradle
platform/android/java/.gradle
platform/android/java/.gradletasknamecache
platform/android/java/local.properties
platform/android/java/project.properties
platform/android/java/build.gradle
platform/android/java/AndroidManifest.xml
platform/android/java/libs/*
platform/android/java/lib/.cxx/
platform/android/java/nativeSrcsConfigs/.cxx/
platform/android/java/assets
platform/android/java/.idea/*
platform/android/java/*.iml
# General c++ generated files
*.lib
@@ -34,8 +31,6 @@ platform/android/java/nativeSrcsConfigs/.cxx/
*.os
*.Plo
*.lo
# Binutils tmp linker output of the form "stXXXXXX" where "X" is alphanumeric
st[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]
# Libs generated files
.deps/*
@@ -48,43 +43,31 @@ gmon.out
*.swo
*.swp
# Qt project files
# QT project files
*.config
*.creator
*.creator.*
*.files
*.includes
*.cflags
*.cxxflags
# Code::Blocks files
*.cbp
*.layout
*.depend
# Eclipse CDT files
.cproject
.settings/
*.pydevproject
*.launch
# Geany/geany-plugins files
*.geany
.geanyprj
# Jetbrains IDEs
.idea/
# Misc
.DS_Store
__MACOSX
logs/
# for projects that use SCons for building: http://http://www.scons.org/
.sconf_temp
.sconsign*.dblite
.sconsign.dblite
*.pyc
# https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
@@ -96,9 +79,6 @@ logs/
*.sln
*.vcxproj*
# Custom SCons configuration override
/custom.py
# Build results
[Dd]ebug/
[Dd]ebugPublic/
@@ -144,7 +124,6 @@ TestResult.xml
*.tlh
*.tmp
*.tmp_proj
*.bak
*.log
*.vspscc
*.vssscc
@@ -152,7 +131,6 @@ TestResult.xml
*.pidb
*.svclog
*.scc
*.nib
# Chutzpah Test files
_Chutzpah*
@@ -265,17 +243,11 @@ __pycache__/
# KDE
.directory
# Kdevelop project files
#Kdevelop project files
*.kdev4
# Kate swap files
*.kate-swp
# Xcode
xcuserdata/
*.xcscmblueprint
*.xccheckout
*.xcodeproj/*
# xCode
xcuserdata
# RIA/Silverlight projects
Generated_Code/
@@ -304,19 +276,11 @@ FakesAssemblies/
# =========================
# Windows image file caches
[Tt]humbs.db
[Tt]humbs.db:encryptable
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Windows stackdumps
*.stackdump
# Windows shortcuts
*.lnk
# Folder config file
[Dd]esktop.ini
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
@@ -350,9 +314,6 @@ platform/windows/godot_res.res
# Visual Studio Code workspace file
*.code-workspace
# Scons construction environment dump
.scons_env.json
# Scons progress indicator
.scons_node_count
@@ -362,9 +323,3 @@ platform/windows/godot_res.res
# compile commands (https://clang.llvm.org/docs/JSONCompilationDatabase.html)
compile_commands.json
# Cppcheck
*.cppcheck
# https://clangd.llvm.org/ cache folder
.clangd/
.cache/

View File

@@ -1,148 +1,69 @@
Aaron Record <aaronjrecord@gmail.com>
Alexander Holland <alexander.holland@live.de>
Alexander Holland <alexander.holland@live.de> <alexander.holland@haw-hamburg.de>
Alexander Holland <alexander.holland@live.de> <AlexHolly>
Andrea Catania <info@andreacatania.com>
Anish Bhobe <anishbhobe@hotmail.com>
Anutrix <numaanzaheerahmed@yahoo.com>
Aren Villanueva <arenvillanueva@yomogi-soft.com> <aren@displaysweet.com>
Andreas Haas <liu.gam3@gmail.com>
Andreas Haas <liu.gam3@gmail.com> <hinsbart@gmail.com>
Andreas Haas <liu.gam3@gmail.com> <hinsbart@users.noreply.github.com>
Andreas Haas <liu.gam3@gmail.com> <entenflugstuhl@gmail.com>
Ariel Manzur <ariel@godotengine.org>
Ariel Manzur <ariel@godotengine.org> <puntob@gmail.com>
Ariel Manzur <ariel@godotengine.org> <punto@godotengine.org>
Ariel Manzur <ariel@godotengine.org> <ariel@okamstudio.com>
Ariel Manzur <ariel@godotengine.org> <punto@Ariels-Mac-mini.local>
Ariel Manzur <ariel@godotengine.org> <punto@Ariels-Mac-mini-2.local>
Bastiaan Olij <mux213@gmail.com>
Benjamin <mafortion.benjamin@gmail.com>
Bernhard Liebl <Bernhard.Liebl@gmx.org> <poke1024@gmx.de>
Bernhard Liebl <Bernhard.Liebl@gmx.org> <poke1024@gmx.org>
Bruno Lourenço <madequa@users.noreply.github.com> <bmlourenco@gmail.com>
Chaosus <chaosus89@gmail.com>
Chris Bradfield <chris@kidscancode.org> <cb@scribe.net>
Clay John <claynjohn@gmail.com>
Clay John <claynjohn@gmail.com> <clayjohn@shaw.ca>
Dana Olson <dana@shineuponthee.com> <adolson@gmail.com>
dankan1890 <mewuidev2@gmail.com>
Daniel J. Ramirez <djrmuv@gmail.com>
David Cambré <david.cambre@gmail.com> <David.Cambre@gmail.com>
Dominik 'dreamsComeTrue' Jasiński <dominikjasinski@o2.pl>
Emmanuel Barroga <emmanuelbarroga@gmail.com>
Eric M <itsjusteza@gmail.com>
Eric Rybicki <info@ericrybicki.com> <stratos695@googlemail.com>
Erik Selecký <35656626+rxlecky@users.noreply.github.com>
Erik Selecký <35656626+rxlecky@users.noreply.github.com> <35656626+SeleckyErik@users.noreply.github.com>
Eveline Jarosz <marqin.pl@gmail.com>
Eveline Jarosz <marqin.pl@gmail.com> <marqin.pl+git@gmail.com>
Fabian <supagu@gmail.com>
Ferenc Arn <tagcup@yahoo.com>
Ferenc Arn <tagcup@yahoo.com> <tagcup@users.noreply.github.com>
foxydevloper <12120644+foxydevloper@users.noreply.github.com>
Fredia Huya-Kouadio <fhuyakou@gmail.com>
Fredia Huya-Kouadio <fhuyakou@gmail.com> <fhuya@google.com>
Geequlim <geequlim@gmail.com>
Gilles Roudiere <gilles.roudiere@gmail.com>
Gilles Roudiere <gilles.roudiere@gmail.com> <gilles.roudiere@laas.fr>
Gordon MacPherson <gordon@gordonite.tech>
Guilherme Felipe <guilhermefelipecgs@gmail.com>
Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
HaSa1002 <johawitt@outlook.de>
Hein-Pieter van Braam-Stewart <hp@tmm.cx>
Hugo Locurcio <hugo.locurcio@hugo.pro> <hugo.l@openmailbox.org>
Hugo Locurcio <hugo.locurcio@hugo.pro> <Calinou@users.noreply.github.com>
Hugo Locurcio <hugo.locurcio@hugo.pro> Calinou <calinou@opmbx.org>
Ian Bishop <ianb96@gmail.com>
Ignacio Etcheverry <ignalfonsore@gmail.com>
Ignacio Etcheverry <ignalfonsore@gmail.com> <neikeq@users.noreply.github.com>
Ilaria Cislaghi <cislaghi.ilaria@gmail.com>
Ilaria Cislaghi <cislaghi.ilaria@gmail.com> <ilaria.cislaghi@simedis.com>
Indah Sylvia <ISylvox@yahoo.com>
J08nY <johny@neuromancer.sk> <jancar.jj@gmail.com>
J08nY <johny@neuromancer.sk> <J08nY@users.noreply.github.com>
Jake Young <young9003@gmail.com>
Jakub Grzesik <kubecz3k@gmail.com>
janglee <merupatel123@gmail.com>
Jean-Michel Bernard <jmb462@gmail.com>
Jérôme Gully <jerome.gully0@gmail.com>
JFonS <joan.fonssanchez@gmail.com>
Juan Linietsky <reduzio@gmail.com>
Juan Linietsky <reduzio@gmail.com> <juan@godotengine.org>
Juan Linietsky <reduzio@gmail.com> <juan@okamstudio.com>
Juan Linietsky <reduzio@gmail.com> <reduz@Juans-MBP.fibertel.com.ar>
Juan Linietsky <reduzio@gmail.com> <red@kyoko>
Julian Murgia <the.straton@gmail.com>
Kanabenki <lucien.menassol@gmail.com> <18357657+Kanabenki@users.noreply.github.com>
karroffel <therzog@mail.de>
karroffel <therzog@mail.de> <thomas.herzog@mail.com>
karroffel <therzog@mail.de> <thomas.herzog@simedis.com>
Kelly Thomas <kelly.thomas@hotmail.com.au>
Kongfa Waroros <gongpha@hotmail.com>
K. S. Ernest (iFire) Lee <ernest.lee@chibifire.com>
kleonc <9283098+kleonc@users.noreply.github.com> <kleonc@users.noreply.github.com>
Leon Krause <lk@leonkrause.com> <eska@eska.me>
Leon Krause <lk@leonkrause.com> <eska014@users.noreply.github.com>
Liz Haas <27thLiz@gmail.com>
Liz Haas <27thLiz@gmail.com> <liu.gam3@gmail.com>
Liz Haas <27thLiz@gmail.com> <hinsbart@gmail.com>
Liz Haas <27thLiz@gmail.com> <hinsbart@users.noreply.github.com>
Liz Haas <27thLiz@gmail.com> <entenflugstuhl@gmail.com>
Manuele Finocchiaro <m4nu3lf@gmail.com>
Manuel Strey <manuel.strey@gmx.de>
Marcel Admiraal <madmiraal@users.noreply.github.com>
Marcelo Fernandez <marcelofg55@gmail.com>
Marcin Zawiejski <dragmz@gmail.com>
Marcus Elg <marcusaccounts@yahoo.se>
Mariano Javier Suligoy <marianognu.easyrpg@gmail.com>
Mario Schlack <m4r10.5ch14ck@gmail.com>
marxin <mliska@suse.cz>
marynate <mary.w.nate@gmail.com> <marynate@github.com>
Mateo Kuruk Miccino <mateomiccino@gmail.com>
Max Hilbrunner <m.hilbrunner@gmail.com>
Max Hilbrunner <m.hilbrunner@gmail.com> <mhilbrunner@users.noreply.github.com>
Michael Alexsander <michaelalexsander@protonmail.com>
Nathan Franke <natfra@pm.me> <nathanwfranke@gmail.com>
Nathan Lovato <nathan@gdquest.com>
Nathan Warden <nathan@nathanwarden.com> <nathanwardenlee@icloud.com>
Nicholas Huelin <62965063+SirQuartz@users.noreply.github.com>
Nils ANDRÉ-CHANG <nils@nilsand.re>
Nils ANDRÉ-CHANG <nils@nilsand.re> <nils.andre.chang@gmail.com>
Nuno Donato <nunodonato@gmail.com> <n.donato@estrelasustentavel.pt>
Pawel Kowal <pkowal1982@gmail.com>
Pedro J. Estébanez <pedrojrulez@gmail.com> <RandomShaper@users.noreply.github.com>
Paul Batty <p_batty@hotmail.co.uk>
Paul Batty <p_batty@hotmail.co.uk> <Paulb23@users.noreply.github.com>
Pawel Kowal <pkowal1982@gmail.com> <pawel.kowal@javart.eu>
Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Pieter-Jan Briers <pieterjan.briers+git@gmail.com> <pieterjan.briers@gmail.com>
Poommetee Ketson <poommetee@protonmail.com>
Przemysław Gołąb (n-pigeon) <golab.przemyslaw@gmail.com>
Rafał Mikrut <mikrutrafal@protonmail.com>
Rafał Mikrut <mikrutrafal@protonmail.com> <mikrutrafal54@gmail.com>
Ralf Hölzemer <r.hoelzemer@posteo.de> <rollenrolm@posteo.de>
Ralf Hölzemer <r.hoelzemer@posteo.de> <rollenrolm@users.noreply.github.com>
Ramesh Ravone <ramesh.maran443@gmail.com>
RaphaelHunter <raphael10241024@gmail.com>
RaphaelHunter <raphael10241024@gmail.com> <Raphael10241024@gmail.com>
RaphaelHunter <raphael10241024@gmail.com> <raphael20141024@gmail.com>
Rémi Verschelde <rverschelde@gmail.com> <remi@verschelde.fr>
Rhody Lugo <rhodylugo@gmail.com> <rhodylugo@me.com>
Ricardo Subtil <ricasubtil@gmail.com>
Robin Hübner <profan@prfn.se> <robinhubner@gmail.com>
romulox_x <romulox_x@yahoo.com>
Ruslan Mustakov <r.mustakov@gmail.com> <ruslan.mustakov@xored.com>
Saracen <SaracenOne@gmail.com>
sheepandshepherd <sheepandshepherd@hotmail.com> <sheepandshepherd@users.noreply.github.com>
Silc 'Tokage' Renew <tokage.it.lab@gmail.com>
Silc 'Tokage' Renew <tokage.it.lab@gmail.com> <61938263+TokageItLab@users.noreply.github.com>
Swarnim Arun <swarnimarun11@gmail.com>
Theo Hallenius <redsymbzone@hotmail.com>
Tomasz Chabora <kobewi4e@gmail.com>
Twarit <wtwarit@gmail.com>
V.VamsiKrishna <vk@bsb.in> <vamsikrishna.v@gmail.com>
Wilhem Barbier <nounoursheureux@openmailbox.org> <wilhem.b@free.fr>
Wilhem Barbier <nounoursheureux@openmailbox.org> <schtroumps31@gmail.com>
Will Nations <willnationsdev@gmail.com>
yg2f <yoann@terminajones.com>
Yuri Sizov <yuris@humnom.net> <pycbouh@users.noreply.github.com>
Zae <zaevi@live.com>
Zak Stam <zakscomputers@hotmail.com>
Thomas Herzog <therzog@mail.de>
Thomas Herzog <therzog@mail.de> <thomas.herzog@mail.com>
Thomas Herzog <therzog@mail.de> <thomas.herzog@simedis.com>
Zher Huei Lee <lee.zh.92@gmail.com>

120
.travis.yml Normal file
View File

@@ -0,0 +1,120 @@
language: cpp
# OS config, depends on actual 'os' in build matrix
dist: xenial
sudo: false
env:
global:
- SCONS_CACHE=$HOME/.scons_cache
- SCONS_CACHE_LIMIT=1024
- OPTIONS="debug_symbols=no verbose=yes progress=no"
- secure: "uch9QszCgsl1qVbuzY41P7S2hWL2IiNFV4SbAYRCdi0oJ9MIu+pVyrQdpf3+jG4rH6j4Rffl+sN17Zz4dIDDioFL1JwqyCqyCyswR8uACC0Rr8gr4Mi3+HIRbv+2s2P4cIQq41JM8FJe84k9jLEMGCGh69w+ibCWoWs74CokYVA="
cache:
directories:
- $SCONS_CACHE
matrix:
include:
- env: STATIC_CHECKS=yes
os: linux
compiler: gcc
addons:
apt:
sources:
- llvm-toolchain-xenial-6.0
packages:
- clang-format-6.0
- env: PLATFORM=x11 TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-mono-gcc-8 MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" EXTRA_ARGS="module_mono_enabled=yes mono_glue=no warnings=extra werror=yes"
os: linux
compiler: gcc-8
addons:
apt:
sources:
- mono
- ubuntu-toolchain-r-test
packages:
- &gcc8_deps [gcc-8, g++-8]
- &linux_deps [libasound2-dev, libfreetype6-dev, libgl1-mesa-dev, libglu1-mesa-dev, libx11-dev, libxcursor-dev, libxi-dev, libxinerama-dev, libxrandr-dev]
- &linux_mono_deps [mono-devel, msbuild, nuget]
coverity_scan:
project:
name: "godotengine/godot"
description: "Godot Engine Coverity scans"
notification_email: coverity@godotengine.org
build_command_prepend: ""
build_command: "scons p=x11 -j2 $OPTIONS"
branch_pattern: coverity_scan
- env: PLATFORM=x11 TOOLS=no TARGET=release CACHE_NAME=${PLATFORM}-clang EXTRA_ARGS="warnings=extra werror=yes"
os: linux
compiler: clang
addons:
apt:
packages:
- *linux_deps
- env: PLATFORM=android TOOLS=no TARGET=release_debug CACHE_NAME=${PLATFORM}-clang EXTRA_ARGS="warnings=extra werror=yes"
os: linux
compiler: clang
- env: PLATFORM=osx TOOLS=yes TARGET=debug CACHE_NAME=${PLATFORM}-tools-clang
os: osx
compiler: clang
- env: PLATFORM=iphone TOOLS=no TARGET=debug CACHE_NAME=${PLATFORM}-clang
os: osx
compiler: clang
- env: PLATFORM=server TOOLS=yes TARGET=release_debug CACHE_NAME=${PLATFORM}-tools-gcc-8 MATRIX_EVAL="CC=gcc-8 && CXX=g++-8" EXTRA_ARGS="warnings=extra werror=yes"
os: linux
compiler: gcc-8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- *gcc8_deps
- *linux_deps
- env: PLATFORM=x11 TOOLS=no TARGET=release_debug CACHE_NAME=${PLATFORM}-gcc-5
os: linux
compiler: gcc
addons:
apt:
packages:
- *linux_deps
before_install:
- eval "${MATRIX_EVAL}"
- if [ "$STATIC_CHECKS" = "yes" ]; then
unset SCONS_CACHE;
fi
install:
- pip install --user scons;
- if [ "$TRAVIS_OS_NAME" = "linux" ] && [ "$PLATFORM" = "android" ]; then
misc/travis/android-tools-linux.sh;
fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then
export PATH=${PATH}:/Users/travis/Library/Python/2.7/bin;
fi
- if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$PLATFORM" = "android" ]; then
misc/travis/android-tools-osx.sh;
fi
before_script:
- if [ "$PLATFORM" = "android" ]; then
export ANDROID_HOME=$TRAVIS_BUILD_DIR/godot-dev/build-tools/android-sdk;
export ANDROID_NDK_ROOT=$TRAVIS_BUILD_DIR/godot-dev/build-tools/android-ndk;
fi
script:
- if [ "$STATIC_CHECKS" = "yes" ]; then
sh ./misc/travis/clang-format.sh;
else
scons -j2 CC=$CC CXX=$CXX platform=$PLATFORM tools=$TOOLS target=$TARGET $OPTIONS $EXTRA_ARGS;
fi

View File

@@ -28,214 +28,120 @@ name is available.
(in alphabetical order, with over 10 commits excluding merges)
Aaron Franke (aaronfranke)
Aaron Record (LightningAA)
Alexander Holland (AlexHolly)
Alexey Khoroshavin (allkhor)
Alket Rexhepi (alketii)
Andrea Catania (AndreaCatania)
Andreas Haas (Hinsbart)
Andrii Doroshenko (Xrayez)
Andy Moss (MillionOstrich)
Angad Kambli (angad-k)
Anilforextra (AnilBK)
Anish Bhobe (KidRigger)
Anton Yabchinskiy (a12n)
Anutrix
Aren Villanueva (kurikaesu)
Ariel Manzur (punto-)
Bartłomiej T. Listwon (Listwon)
Bastiaan Olij (BastiaanOlij)
Ben Brookshire (sheepandshepherd)
Benjamin Larsson (Nallebeorn)
Bernhard Liebl (poke1024)
Bhuvan Vemula (Bhu1-V)
Benjamin (Nallebeorn)
Bernard Liebl (poke1024)
Błażej Szczygieł (zaps166)
Bojidar Marinov (bojidar-bg)
Brian Semrau (briansemrau)
Bruno Lourenço (MadEqua)
bruvzg
Cameron Reikes (creikey)
Camille Mohr-Daurat (pouleyKetchoupp)
Caner Demirer (cdemirer)
Carl Olsson (not-surt)
Carter Anderson (cart)
Chris Bradfield (cbscribe)
Clay John (clayjohn)
Dana Olson (adolson)
Daniel J. Ramirez (djrm)
Daniel Rakos (aqnuep)
dankan1890
Danil Alexeev (dalexeev)
David Cambré (Gallilus)
David Sichma (DavidSichma)
David Snopek (dsnopek)
Dharkael (lupoDharkael)
Dmitry Koteroff (Krakean)
Dominik Jasiński (dreamsComeTrue)
DualMatrix
Ellen Poe (ellenhp)
Emmanuel Barroga (codecustard)
Emmanuel Leblond (touilleMan)
Eoin O'Neill (Eoin-ONeill-Yokai)
Eric Lasota (elasota)
Eric M (EricEzaM)
Eric Rybicki (ericrybick)
Erik Selecký (rxlecky)
est31
Eveline Jarosz (Marqin)
Fabian Mathews (supagu)
Fabio Alessandrelli (Faless)
fabriceci
Ferenc Arn (tagcup)
follower
foxydevloper
François Belair (Razoric480)
Franklin Sobrinho (TheHX)
Fredia Huya-Kouadio (m4gr3d)
Geequlim
George Marques (vnen)
Gerrit Großkopf (Grosskopf)
Gilles Roudiere (groud)
Gordon MacPherson (RevoluPowered)
Guilherme Felipe de C. G. da Silva (guilhermefelipecgs)
Hanif Bin Ariffin (hbina)
Haoyu Qiu (timothyqiu)
Hein-Pieter van Braam-Stewart (hpvb)
Hendrik Brucker (Geometror)
hilfazer
Hein-Pieter van Braam (hpvb)
Hiroshi Ogawa (hi-ogawa)
homer666
hoontee
Hubert Jarosz (Marqin)
Hugo Locurcio (Calinou)
Ian Bishop (ianb96)
Ibrahn Sahir (ibrahn)
Ignacio Etcheverry (neikeq)
Ilaria Cislaghi (QbieShay)
Indah Sylvia (ISylvox)
J08nY
Jake Young (Duroxxigar)
Jakub Grzesik (kubecz3k)
James Buck (jbuck3)
Jean-Michel Bernard (jmb462)
Jérôme Gully (Nutriz)
Jia Jun Chai (SkyLucilfer)
Joan Fons Sanchez (JFonS)
Johannes Witt (HaSa1002)
Johan Manuel (29jm)
Jordan Schidlowsky (winterpixelgames)
Joshua Grams (JoshuaGrams)
Juan Linietsky (reduz)
Julian Murgia (StraToN)
Julien Nguyen (Blackiris)
Jummit
Justo Delgado (mrcdk)
karroffel
Kelly Thomas (KellyThomas)
kleonc
Kongfa Waroros (gongpha)
Kostadin Damyanov (Max-Might)
K. S. Ernest (iFire) Lee (fire)
lawnjelly
Leon Krause (leonkrause)
Liz Haas (27thLiz)
Lucien Menassol (Kanabenki)
Lyuma
Maganty Rushyendra (mrushyendra)
Manuele Finocchiaro (m4nu3lf)
Marcel Admiraal (madmiraal)
Leon Krause (eska014)
m4nu3lf
Marcelo Fernandez (marcelofg55)
Marc Gilleron (Zylann)
Marcin Zawiejski (dragmz)
Marcus Brummer (mbrlabs)
Marcus Elg (MCrafterzz)
Mariano Javier Suligoy (MarianoGnu)
Mario Schlack (hurikhan)
Marios Staikopoulos (marstaik)
Markus Sauermann (Sauermann)
Martin Capitanio (capnm)
Martin Liška (marxin)
Martin Sjursen (binbitten)
marynate
Masoud BH (masoudbh3)
Mateo Kuruk Miccino (kuruk-mm)
Matthew (skyace65)
Matthias Hölzl (hoelzl)
Max Hilbrunner (mhilbrunner)
merumelu
Meru Patel (Janglee123)
Michael Alexsander (YeldhamDev)
MichiRecRoom (LikeLakers2)
Morris "Tabor" Arroad (mortarroad)
Michael Alexsander Silva Dias (YeldhamDev)
mrezai
Muhammad Huri (CakHuri)
muiroc
Nathan Franke (nathanfranke)
Nathan Lovato (NathanLovato)
Nathan Warden (NathanWarden)
Nicholas Huelin (SirQuartz)
Nils André-Chang (NilsIrl)
Noah Beard (TwistedTwigleg)
Nuno Donato (nunodonato)
Omar El Sheikh (The-O-King)
Ovnuniarchos
Pascal Richter (ShyRed)
Patrick (firefly2442)
Paul Batty (Paulb23)
Paul Joannon (paulloz)
Paul Trojahn (ptrojahn)
Pawel Kowal (pkowal1982)
Pawel Lampe (Scony)
Pedro J. Estébanez (RandomShaper)
Pieter-Jan Briers (PJB3005)
Poommetee Ketson (Noshyaar)
Przemysław Gołąb (n-pigeon)
Rafael M. G. (rafallus)
Rafał Mikrut (qarmin)
Ralf Hölzemer (rollenrolm)
Ramesh Ravone (RameshRavone)
Raphael2048
Raul Santos (raulsntos)
Ray Koopa (RayKoopa)
Rémi Verschelde (akien-mga)
Rhody Lugo (rraallvv)
Ricardo Buring (rburing)
Ricardo Subtil (Ev1lbl0w)
Roberto F. Arroyo (robfram)
Robin Hübner (profan)
romulox-x
Ruslan Mustakov (endragor)
Ryan Roden-Corrent (rrcore)
Saniko (sanikoyes)
santouits
SaracenOne
Sergey Minakov (naithar)
sersoong
Shiqing (kawa-yoiko)
Silc 'Tokage' Renew (TokageItLab)
Simon Wenner (swenner)
Stijn Hinlopen (hinlopen)
Swarnim Arun (minraws)
TC (floppyhammer)
Thakee Nathees (ThakeeNathees)
thebestnom
Theo Hallenius (TheoXD)
Timo Schwarzer (timoschwarzer)
Thomas Herzog (karroffel)
Timo (toger5)
Tomasz Chabora (KoBeWi)
trollodel
Twarit Waikar (IronicallySerious)
Umang Kalra (theoway)
Timo Schwarzer (timoschwarzer)
Vinzenz Feenstra (vinzenz)
박한얼 (volzhs)
V. Vamsi Krishna (vkbsb)
Wilhem Barbier (nounoursheureux)
William Deurwaarder (williamd67)
Will Nations (willnationsdev)
Wilson E. Alvarez (Rubonnek)
Xavier Cho (mysticfall)
yg2f (SuperUserNameMan)
Yuri Rubinsky (Chaosus)
Yuri Sizov (pycbouh)
Zae Chao (zaevi)
Zak Stam (zaksnet)
Yuri Roubinski (Chaosus)
Zher Huei Lee (leezh)
ZuBsPaCe
Дмитрий Сальников (DmitriySalnikov)

File diff suppressed because it is too large Load Diff

57
CODEOWNERS Normal file
View File

@@ -0,0 +1,57 @@
# Lines starting with '#' are comments.
# Each line is a file pattern followed by one or more owners.
# Owners can be @users, @org/teams or emails
/core/ @reduz
/doc/ @godotengine/documentation
doc_classes/* @godotengine/documentation
# Rendering
/drivers/gl_context/ @reduz
/drivers/gles2/ @reduz
/drivers/gles3/ @reduz
# Audio
/drivers/alsa/ @marcelofg55
/drivers/alsamidi/ @marcelofg55
/drivers/coreaudio/ @marcelofg55
/drivers/coremidi/ @marcelofg55
/drivers/pulseaudio/ @marcelofg55
/drivers/wasapi/ @marcelofg55
/drivers/winmidi/ @marcelofg55
/drivers/xaudio2/ @marcelofg55
# Porting
/drivers/unix/ @reduz @hpvb
/drivers/windows/ @reduz @hpvb
/editor/icons/ @djrm
/main/ @reduz
/misc/ @akien-mga
/modules/bullet/ @AndreaCatania
/modules/csg/ @reduz @BastiaanOlij
/modules/enet/ @godotengine/network
/modules/gdnative/ @karroffel
/modules/gdnative/*arvr/ @BastiaanOlij
/modules/gdscript/ @reduz @vnen @bojidar-bg
/modules/mbedtls/ @godotengine/network
/modules/mobile_vr/ @BastiaanOlij
/modules/mono/ @neikeq
/modules/opensimplex/ @JFonS
/modules/regex/ @LeeZH
/modules/upnp/ @godotengine/network
/modules/websocket/ @godotengine/network
/platform/javascript/ @eska014
/platform/uwp/ @vnen
/scene/main/ @reduz
/server/physics*/ @reduz @AndreaCatania
/server/visual*/ @reduz @karroffel
/thirdparty/ @akien-mga

View File

@@ -1,108 +1,70 @@
# How to contribute efficiently
## Table of contents
Sections covered in this file:
- [Reporting bugs](#reporting-bugs)
- [Proposing features or improvements](#proposing-features-or-improvements)
- [Contributing pull requests](#contributing-pull-requests)
- [Contributing to Godot's translation](#contributing-to-godots-translation)
- [Communicating with developers](#communicating-with-developers)
* [Reporting bugs or proposing features](#reporting-bugs-or-proposing-features)
* [Contributing pull requests](#contributing-pull-requests)
* [Contributing to Godot's translation](#contributing-to-godots-translation)
* [Communicating with developers](#communicating-with-developers)
**Please read the first section before reporting a bug!**
## Reporting bugs
## Reporting bugs or proposing features
The golden rule is to **always open *one* issue for *one* bug**. If you notice
several bugs and want to report them, make sure to create one new issue for
each of them.
If you're reporting a new bug, you'll make our life simpler (and the
fix will come sooner) by following these guidelines:
Everything referred to hereafter as "bug" also applies for feature requests.
### Search first in the existing database
If you are reporting a new issue, you will make our life much simpler (and the
fix come much sooner) by following those guidelines:
Issues are often reported several times by various users. It's good practice to
**search first in the [issue tracker](https://github.com/godotengine/godot/issues)
before reporting your issue**. If you don't find a relevant match or if you're
unsure, don't hesitate to **open a new issue**. The bugsquad will handle it
from there if it's a duplicate.
#### Search first in the existing database
### Specify the platform
Issues are often reported several times by various users. It's a good practice
to **search first** in the issues database before reporting your issue. If you
don't find a relevant match or if you are unsure, don't hesitate to **open a
new issue**. The bugsquad will handle it from there if it's a duplicate.
#### Specify the platform
Godot runs on a large variety of platforms and operating systems and devices.
**In your bug reports, please always specify:**
If you believe your issue is device/platform dependent (for example if it is
related to the rendering, crashes or compilation errors), please specify:
* Operating system
* Device (including architecture, e.g. x86, x86_64, arm, etc.)
* GPU model (and driver in use if you know it)
- Operating system and version (e.g. Windows 10, macOS 10.15, Ubuntu 19.10)
- Godot version (e.g. 3.2, 3.1.2, or the Git commit hash if you're using a development branch)
For bugs that are likely OS-specific and/or graphics-related, please also specify:
- Device (CPU model including architecture, e.g. x86, x86_64, ARM, etc.)
- GPU model (and the driver version in use if you know it)
**Bug reports not including the required information may be closed at the
maintainers' discretion.** If in doubt, always include all the requested
information; it's better to include too much information than not enough
information.
### Specify steps to reproduce
#### Specify steps to reproduce
Many bugs can't be reproduced unless specific steps are taken. Please **specify
the exact steps** that must be taken to reproduce the condition, and try to
keep them as minimal as possible. If you're describing a procedure to follow
in the editor, don't hesitate to include screenshots.
keep them as minimal as possible.
Making your bug report easy to reproduce will make it easier for contributors
to fix the bug.
#### Provide a simple, example project
### Provide a simple, example project
Sometimes, unexpected behavior can happen in your project. In such case,
Sometimes an unexpected behavior happens in your project. In such case,
understand that:
- What happens to you may not happen to other users.
- We can't take the time to look at your project, understand how it is set up
* What happens to you may not happen to other users.
* We can't take the time to look at your project, understand how it is set up
and then figure out why it's failing.
To speed up our work, **please upload a minimal project** that isolates
and reproduces the issue. This is always the **best way for us to fix it**.
We recommend attaching a ZIP file with the minimal project directly to the bug report,
by drag and dropping the file in the GitHub edition field. This ensures the file
can remain available for a long period of time. Only use third-party file hosts
if your ZIP file isn't accepted by GitHub because it's too large.
We recommend always attaching a minimal reproduction project, even if the issue
may seem simple to reproduce manually.
**If you've been asked by a maintainer to upload a minimal reproduction project,
you *must* do so within 7 days.** Otherwise, your bug report will be closed as
it'll be considered too difficult to diagnose.
Now that you've read the guidelines, click the link below to create a
bug report:
- **[Report a bug](https://github.com/godotengine/godot/issues/new?assignees=&labels=&template=bug_report.yml)**
## Proposing features or improvements
**Since August 2019, the main issue tracker no longer accepts feature proposals.**
Instead, head to the [Godot Proposals repository](https://github.com/godotengine/godot-proposals)
and follow the instructions in the README file. High-quality feature proposals
are more likely to be well-received by the maintainers and community, so do
your best :)
See [this article](https://godotengine.org/article/introducing-godot-proposals-repository)
for detailed rationale on this change.
To speed up our work, please prepare for us **a simple project** that isolates
and reproduces the issue. This is always the **the best way for us to fix it**.
You can attach a zip file with the minimal project directly to the bug report,
by drag and dropping the file in the GitHub edition field.
## Contributing pull requests
If you want to add new engine features, please make sure that:
If you want to add new engine functionalities, please make sure that:
- This functionality is desired, which means that it solves a common use case
* This functionality is desired, which means that it solves a common use case
that several users will need in their real-life projects.
- You talked to other developers on how to implement it best. See also
[Proposing features or improvements](#proposing-features-or-improvements).
- Even if it doesn't get merged, your PR is useful for future work by another
* You talked to other developers on how to implement it best (on either
communication channel, and maybe in a GitHub issue first before making your
PR).
* Even if it does not get merged, your PR is useful for future work by another
developer.
Similar rules can be applied when contributing bug fixes - it's always best to
@@ -118,26 +80,10 @@ In addition to the following tips, also take a look at the
[Engine development guide](https://docs.godotengine.org/en/latest/development/cpp/)
for an introduction to developing on Godot.
The [Contributing docs](https://docs.godotengine.org/en/latest/community/contributing/index.html)
The [Contributing docs](http://docs.godotengine.org/en/latest/community/contributing/index.html)
also have important information on the PR workflow and the code style we use.
### Document your changes
If your pull request adds methods, properties or signals that are exposed to
scripting APIs, you **must** update the class reference to document those.
This is to ensure the documentation coverage doesn't decrease as contributions
are merged.
[Update the documentation template](https://docs.godotengine.org/en/latest/community/contributing/updating_the_class_reference.html#updating-the-documentation-template)
using your compiled binary, then fill in the descriptions.
Follow the style guide described in the
[Docs writing guidelines](https://docs.godotengine.org/en/latest/community/contributing/docs_writing_guidelines.html).
If your pull request modifies parts of the code in a non-obvious way, make sure
to add comments in the code as well. This helps other people understand the
change without having to look at `git blame`.
### Be nice to the Git history
#### Be nice to the git history
Try to make simple PRs that handle one specific topic. Just like for reporting
issues, it's better to open 3 different PRs that each address a different issue
@@ -153,31 +99,33 @@ commit, try to merge them together before making your pull request (see ``git
rebase -i`` and relevant help about rebasing or amending commits on the
Internet).
This [Git style guide](https://github.com/agis-/git-style-guide) has some
good practices to have in mind.
This git style guide has some good practices to have in mind:
[Git Style Guide](https://github.com/agis-/git-style-guide)
See our [PR workflow](https://docs.godotengine.org/en/latest/community/contributing/pr_workflow.html)
See our [PR workflow](http://docs.godotengine.org/en/latest/community/contributing/pr_workflow.html)
documentation for tips on using Git, amending commits and rebasing branches.
### Format your commit messages with readability in mind
#### Format your commit logs with readability in mind
The way you format your commit messages is quite important to ensure that the
commit history and changelog will be easy to read and understand. A Git commit
message is formatted as a short title (first line) and an extended description
The way you format your commit logs is quite important to ensure that the
commit history and changelog will be easy to read and understand. A git commit
log is formatted as a short title (first line) and an extended description
(everything after the first line and an empty separation line).
The short title is the most important part, as it is what will appear in the
`shortlog` changelog (one line per commit, so no description shown) or in the
GitHub interface unless you click the "expand" button. As the name says, try to
keep that first line under 72 characters. It should describe what the commit
does globally, while details would go in the description. Typically, if you
can't keep the title short because you have too much stuff to mention, it means
you should probably split your changes in several commits :)
GitHub interface unless you click the "expand" button. As the name tells it,
try to keep that first line relatively short (ideally <= 50 chars, though it's
rare to be able to tell enough in so few characters, so you can go a bit
higher) - it should describe what the commit does globally, while details would
go in the description. Typically, if you can't keep the title short because you
have too much stuff to mention, it means that you should probably split your
changes in several commits :)
Here's an example of a well-formatted commit message (note how the extended
Here's an example of a well-formatted commit log (note how the extended
description is also manually wrapped at 80 chars for readability):
```text
```
Prevent French fries carbonization by fixing heat regulation
When using the French fries frying module, Godot would not regulate the heat
@@ -191,9 +139,9 @@ of cooking oil under normal atmospheric conditions.
Fixes #1789, long live the Realm!
```
**Note:** When using the GitHub online editor or its drag-and-drop
feature, *please* edit the commit title to something meaningful. Commits named
"Update my_file.cpp" won't be accepted.
*Note:* When using the GitHub online editor (or worse, the drag and drop
feature), *please* edit the commit title to something meaningful. Commits named
"Update my_file.cpp" will not be accepted.
## Contributing to Godot's translation
@@ -214,23 +162,26 @@ discussions and support, others more for development discussions.
To communicate with developers (e.g. to discuss a feature you want to implement
or a bug you want to fix), the following channels can be used:
- [Godot Contributors Chat](https://chat.godotengine.org): You will
find most core developers there, so it's the go-to platform for direct chat
- [GitHub issues](https://github.com/godotengine/godot/issues): If there is an
existing issue about a topic you want to discuss, just add a comment to it -
all developers watch the repository and will get an email notification. You
can also create a new issue - please keep in mind to create issues only to
discuss quite specific points about the development, and not general user
feedback or support requests.
- [#godotengine-devel IRC channel on
Freenode](https://webchat.freenode.net/?channels=godotengine-devel): You will
find most core developers there, so it's the go-to channel for direct chat
about Godot Engine development. Feel free to start discussing something there
to get some early feedback before writing up a detailed proposal in a GitHub
issue.
- [Bug tracker](https://github.com/godotengine/godot/issues): If there is an
existing issue about a topic you want to discuss, just add a comment to it -
many developers watch the repository and will get a notification. You can
also create a new issue - please keep in mind to create issues only to
discuss quite specific points about the development, and not general user
feedback or support requests.
- [Feature proposals](https://github.com/godotengine/godot-proposals/issues):
To propose a new feature, we have a dedicated issue tracker for that. Don't
hesitate to start by talking about your idea on the Godot Contributors Chat
to make sure that it makes sense in Godot's context.
- [devel@godotengine.org mailing
list](https://listengine.tuxfamily.org/godotengine.org/devel/): Mailing list
for Godot developers, used primarily to announce developer meetings on IRC
and other important discussions that need to reach people directly in their
mailbox. See the [index
page](https://listengine.tuxfamily.org/godotengine.org/devel/) for
subscription instructions.
Thanks for your interest in contributing!
Thanks!
The Godot development team
The Godot development team

File diff suppressed because it is too large Load Diff

1010
DONORS.md

File diff suppressed because it is too large Load Diff

21
ISSUE_TEMPLATE.md Normal file
View File

@@ -0,0 +1,21 @@
<!-- Please search existing issues for potential duplicates before filing yours:
https://github.com/godotengine/godot/issues?q=is%3Aissue
-->
**Godot version:**
<!-- Specify commit hash if non-official. -->
**OS/device including version:**
<!-- Specify GPU model and drivers if graphics-related. -->
**Issue description:**
<!-- What happened, and what was expected. -->
**Steps to reproduce:**
**Minimal reproduction project:**
<!-- Recommended as it greatly speeds up debugging. Drag and drop a zip archive to upload it. -->

View File

@@ -1,5 +1,5 @@
Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.
Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).
Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur.
Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md)
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,5 +1,3 @@
Godot Engine Logo
Copyright (c) 2017 Andrea Calabró
This work is licensed under a Creative Commons Attribution 4.0 International
License (CC-BY-4.0 International) <https://creativecommons.org/licenses/by/4.0/>.
Godot Logo (C) Andrea Calabró
Distributed under the terms of the Creative Commons Attribution License
version 3.0 (CC-BY 3.0) <https://creativecommons.org/licenses/by/3.0/legalcode>.

View File

@@ -1,78 +1,71 @@
# Godot Engine
[![Godot Engine logo](/logo.png)](https://godotengine.org)
<p align="center">
<a href="https://godotengine.org">
<img src="logo_outlined.svg" width="400" alt="Godot Engine logo">
</a>
</p>
## Godot Engine
## 2D and 3D cross-platform game engine
Homepage: https://godotengine.org
**[Godot Engine](https://godotengine.org) is a feature-packed, cross-platform
game engine to create 2D and 3D games from a unified interface.** It provides a
comprehensive set of common tools, so that users can focus on making games
without having to reinvent the wheel. Games can be exported in one click to a
number of platforms, including the major desktop platforms (Linux, macOS,
Windows), mobile platforms (Android, iOS), as well as Web-based platforms
(HTML5) and
[consoles](https://docs.godotengine.org/en/latest/tutorials/platform/consoles.html).
#### 2D and 3D cross-platform game engine
## Free, open source and community-driven
Godot Engine is a feature-packed, cross-platform game engine to create 2D and
3D games from a unified interface. It provides a comprehensive set of common
tools, so that users can focus on making games without having to reinvent the
wheel. Games can be exported in one click to a number of platforms, including
the major desktop platforms (Linux, Mac OSX, Windows) as well as mobile
(Android, iOS) and web-based (HTML5) platforms.
#### Free, open source and community-driven
Godot is completely free and open source under the very permissive MIT license.
No strings attached, no royalties, nothing. The users' games are theirs, down
to the last line of engine code. Godot's development is fully independent and
community-driven, empowering users to help shape their engine to match their
expectations. It is supported by the [Software Freedom Conservancy](https://sfconservancy.org/)
expectations. It is supported by the Software Freedom Conservancy
not-for-profit.
Before being open sourced in February 2014, Godot had been developed by Juan
Linietsky and Ariel Manzur (both still maintaining the project) for several
years as an in-house engine, used to publish several work-for-hire titles.
![Screenshot of a 3D scene in Godot Engine](https://raw.githubusercontent.com/godotengine/godot-design/master/screenshots/editor_tps_demo_1920x1080.jpg)
![Screenshot of a 3D scene in Godot Engine](https://download.tuxfamily.org/godotengine/media/screenshots/editor_3d_fracteed.jpg)
## Getting the engine
### Getting the engine
### Binary downloads
#### Binary downloads
Official binaries for the Godot editor and the export templates can be found
[on the homepage](https://godotengine.org/download).
### Compiling from source
#### Compiling from source
[See the official docs](https://docs.godotengine.org/en/latest/development/compiling/)
for compilation instructions for every supported platform.
## Community and contributing
### Community and contributing
Godot is not only an engine but an ever-growing community of users and engine
developers. The main community channels are listed [on the homepage](https://godotengine.org/community).
To get in touch with the engine developers, the best way is to join the
[Godot Contributors Chat](https://chat.godotengine.org).
To get in touch with the developers, the best way is to join the
[#godotengine IRC channel](https://webchat.freenode.net/?channels=godotengine)
on Freenode.
To get started contributing to the project, see the [contributing guide](CONTRIBUTING.md).
## Documentation and demos
### Documentation and demos
The official documentation is hosted on [ReadTheDocs](https://docs.godotengine.org).
It is maintained by the Godot community in its own [GitHub repository](https://github.com/godotengine/godot-docs).
The [class reference](https://docs.godotengine.org/en/latest/classes/)
is also accessible from the Godot editor.
is also accessible from within the engine.
The official demos are maintained in their own [GitHub repository](https://github.com/godotengine/godot-demo-projects)
as well.
There are also a number of other
[learning resources](https://docs.godotengine.org/en/latest/community/tutorials.html)
provided by the community, such as text and video tutorials, demos, etc.
Consult the [community channels](https://godotengine.org/community)
for more information.
There are also a number of other learning resources provided by the community,
such as text and video tutorials, demos, etc. Consult the [community channels](https://godotengine.org/community)
for more info.
[![Actions Build Status](https://github.com/godotengine/godot/workflows/Godot/badge.svg?branch=master)](https://github.com/godotengine/godot/actions)
[![Travis Build Status](https://travis-ci.org/godotengine/godot.svg?branch=master)](https://travis-ci.org/godotengine/godot)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/bfiihqq6byxsjxxh/branch/master?svg=true)](https://ci.appveyor.com/project/akien-mga/godot)
[![Code Triagers Badge](https://www.codetriage.com/godotengine/godot/badges/users.svg)](https://www.codetriage.com/godotengine/godot)
[![Translate on Weblate](https://hosted.weblate.org/widgets/godot-engine/-/godot/svg-badge.svg)](https://hosted.weblate.org/engage/godot-engine/?utm_source=widget)
[![Total alerts on LGTM](https://img.shields.io/lgtm/alerts/g/godotengine/godot.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/godotengine/godot/alerts)
[![TODOs](https://badgen.net/https/api.tickgit.com/badgen/github.com/godotengine/godot)](https://www.tickgit.com/browse?repo=github.com/godotengine/godot)

File diff suppressed because it is too large Load Diff

View File

@@ -1,97 +1,68 @@
import sys
if sys.version_info < (3,):
def isbasestring(s):
return isinstance(s, basestring)
def open_utf8(filename, mode):
return open(filename, mode)
def byte_to_str(x):
return str(ord(x))
import cStringIO
def StringIO():
return cStringIO.StringIO()
def encode_utf8(x):
return x
def decode_utf8(x):
return x
def iteritems(d):
return d.iteritems()
def itervalues(d):
return d.itervalues()
def escape_string(s):
if isinstance(s, unicode):
s = s.encode("ascii")
result = ""
s = s.encode('ascii')
result = ''
for c in s:
if not (32 <= ord(c) < 127) or c in ("\\", '"'):
result += "\\%03o" % ord(c)
if not (32 <= ord(c) < 127) or c in ('\\', '"'):
result += '\\%03o' % ord(c)
else:
result += c
return result
def qualname(obj):
# Not properly equivalent to __qualname__ in py3, but it doesn't matter.
return obj.__name__
else:
def isbasestring(s):
return isinstance(s, (str, bytes))
def open_utf8(filename, mode):
return open(filename, mode, encoding="utf-8")
def byte_to_str(x):
return str(x)
import io
def StringIO():
return io.StringIO()
import codecs
def encode_utf8(x):
return codecs.utf_8_encode(x)[0]
def decode_utf8(x):
return codecs.utf_8_decode(x)[0]
def iteritems(d):
return iter(d.items())
def itervalues(d):
return iter(d.values())
def charcode_to_c_escapes(c):
rev_result = []
while c >= 256:
c, low = (c // 256, c % 256)
rev_result.append("\\%03o" % low)
rev_result.append("\\%03o" % c)
return "".join(reversed(rev_result))
rev_result.append('\\%03o' % low)
rev_result.append('\\%03o' % c)
return ''.join(reversed(rev_result))
def escape_string(s):
result = ""
result = ''
if isinstance(s, str):
s = s.encode("utf-8")
s = s.encode('utf-8')
for c in s:
if not (32 <= c < 127) or c in (ord("\\"), ord('"')):
if not(32 <= c < 127) or c in (ord('\\'), ord('"')):
result += charcode_to_c_escapes(c)
else:
result += chr(c)
return result
def qualname(obj):
return obj.__qualname__

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python
Import("env")
Import('env')
import core_builders
import make_binders
@@ -11,41 +11,34 @@ env.core_sources = []
# Generate AES256 script encryption key
import os
txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
if "SCRIPT_AES256_ENCRYPTION_KEY" in os.environ:
key = os.environ["SCRIPT_AES256_ENCRYPTION_KEY"]
if ("SCRIPT_AES256_ENCRYPTION_KEY" in os.environ):
e = os.environ["SCRIPT_AES256_ENCRYPTION_KEY"]
txt = ""
ec_valid = True
if len(key) != 64:
if (len(e) != 64):
ec_valid = False
else:
txt = ""
for i in range(len(key) >> 1):
if i > 0:
for i in range(len(e) >> 1):
if (i > 0):
txt += ","
txts = "0x" + key[i * 2 : i * 2 + 2]
txts = "0x" + e[i * 2:i * 2 + 2]
try:
int(txts, 16)
except Exception:
except:
ec_valid = False
txt += txts
if not ec_valid:
print("Error: Invalid AES256 encryption key, not 64 hexadecimal characters: '" + key + "'.")
print(
"Unset 'SCRIPT_AES256_ENCRYPTION_KEY' in your environment "
"or make sure that it contains exactly 64 hexadecimal characters."
)
Exit(255)
if (not ec_valid):
txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0"
print("Invalid AES256 encryption key, not 64 bits hex: " + e)
# NOTE: It is safe to generate this file here, since this is still executed serially
with open("script_encryption_key.gen.cpp", "w") as f:
f.write('#include "core/project_settings.h"\nuint8_t script_encryption_key[32]={' + txt + "};\n")
f.write("#include \"core/project_settings.h\"\nuint8_t script_encryption_key[32]={" + txt + "};\n")
# Add required thirdparty code.
thirdparty_obj = []
env_thirdparty = env.Clone()
env_thirdparty.disable_warnings()
@@ -54,42 +47,44 @@ env_thirdparty.disable_warnings()
thirdparty_misc_dir = "#thirdparty/misc/"
thirdparty_misc_sources = [
# C sources
"base64.c",
"fastlz.c",
"sha256.c",
"smaz.c",
# C++ sources
"aes256.cpp",
"hq2x.cpp",
"md5.cpp",
"pcg.cpp",
"triangulator.cpp",
"clipper.cpp",
]
thirdparty_misc_sources = [thirdparty_misc_dir + file for file in thirdparty_misc_sources]
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_misc_sources)
env_thirdparty.add_source_files(env.core_sources, thirdparty_misc_sources)
# Zlib library, can be unbundled
if env["builtin_zlib"]:
thirdparty_zlib_dir = "#thirdparty/zlib/"
thirdparty_zlib_sources = [
"adler32.c",
"compress.c",
"crc32.c",
"deflate.c",
"infback.c",
"inffast.c",
"inflate.c",
"inftrees.c",
"trees.c",
"uncompr.c",
"zutil.c",
]
thirdparty_zlib_sources = [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources]
if env['builtin_zlib']:
thirdparty_zlib_dir = "#thirdparty/zlib/"
thirdparty_zlib_sources = [
"adler32.c",
"compress.c",
"crc32.c",
"deflate.c",
"infback.c",
"inffast.c",
"inflate.c",
"inftrees.c",
"trees.c",
"uncompr.c",
"zutil.c",
]
thirdparty_zlib_sources = [thirdparty_zlib_dir + file for file in thirdparty_zlib_sources]
env_thirdparty.Prepend(CPPPATH=[thirdparty_zlib_dir])
# Needs to be available in main env too
env.Prepend(CPPPATH=[thirdparty_zlib_dir])
if env["target"] == "debug":
env_thirdparty.Append(CPPDEFINES=["ZLIB_DEBUG"])
env_thirdparty.Append(CPPPATH=[thirdparty_zlib_dir])
# Needs to be available in main env too
env.Append(CPPPATH=[thirdparty_zlib_dir])
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zlib_sources)
env_thirdparty.add_source_files(env.core_sources, thirdparty_zlib_sources)
# Minizip library, could be unbundled in theory
# However, our version has some custom modifications, so it won't compile with the system one
@@ -100,12 +95,12 @@ thirdparty_minizip_sources = [
"zip.c",
]
thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources]
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_minizip_sources)
env_thirdparty.add_source_files(env.core_sources, thirdparty_minizip_sources)
# Zstd library, can be unbundled in theory
# though we currently use some private symbols
# https://github.com/godotengine/godot/issues/17374
if env["builtin_zstd"]:
if env['builtin_zstd']:
thirdparty_zstd_dir = "#thirdparty/zstd/"
thirdparty_zstd_sources = [
"common/debug.c",
@@ -126,9 +121,6 @@ if env["builtin_zstd"]:
"compress/zstd_ldm.c",
"compress/zstd_opt.c",
"compress/zstdmt_compress.c",
"compress/zstd_compress_literals.c",
"compress/zstd_compress_sequences.c",
"compress/zstd_compress_superblock.c",
"decompress/huf_decompress.c",
"decompress/zstd_ddict.c",
"decompress/zstd_decompress_block.c",
@@ -136,66 +128,44 @@ if env["builtin_zstd"]:
]
thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources]
env_thirdparty.Prepend(CPPPATH=[thirdparty_zstd_dir, thirdparty_zstd_dir + "common"])
env_thirdparty.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
env.Prepend(CPPPATH=thirdparty_zstd_dir)
env_thirdparty.Append(CPPPATH=[thirdparty_zstd_dir, thirdparty_zstd_dir + "common"])
env_thirdparty.Append(CCFLAGS="-DZSTD_STATIC_LINKING_ONLY")
env.Append(CPPPATH=thirdparty_zstd_dir)
# Also needed in main env includes will trigger warnings
env.Append(CPPDEFINES=["ZSTD_STATIC_LINKING_ONLY"])
env.Append(CCFLAGS="-DZSTD_STATIC_LINKING_ONLY")
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_zstd_sources)
env_thirdparty.add_source_files(env.core_sources, thirdparty_zstd_sources)
env.core_sources += thirdparty_obj
# Godot source files
# Godot's own sources
env.add_source_files(env.core_sources, "*.cpp")
env.add_source_files(env.core_sources, "script_encryption_key.gen.cpp")
# Certificates
env.Depends(
"#core/io/certs_compressed.gen.h",
["#thirdparty/certs/ca-certificates.crt", env.Value(env["builtin_certs"]), env.Value(env["system_certs_path"])],
)
env.CommandNoCache(
"#core/io/certs_compressed.gen.h",
"#thirdparty/certs/ca-certificates.crt",
run_in_subprocess(core_builders.make_certs_header),
)
env.Depends("#core/io/certs_compressed.gen.h", ["#thirdparty/certs/ca-certificates.crt", env.Value(env['builtin_certs']), env.Value(env['system_certs_path'])])
env.CommandNoCache("#core/io/certs_compressed.gen.h", "#thirdparty/certs/ca-certificates.crt", run_in_subprocess(core_builders.make_certs_header))
# Make binders
env.CommandNoCache(
["method_bind.gen.inc", "method_bind_ext.gen.inc", "method_bind_free_func.gen.inc"],
"make_binders.py",
run_in_subprocess(make_binders.run),
)
env.CommandNoCache(['method_bind.gen.inc', 'method_bind_ext.gen.inc'], 'make_binders.py', run_in_subprocess(make_binders.run))
# Authors
env.Depends("#core/authors.gen.h", "../AUTHORS.md")
env.CommandNoCache("#core/authors.gen.h", "../AUTHORS.md", run_in_subprocess(core_builders.make_authors_header))
env.Depends('#core/authors.gen.h', "../AUTHORS.md")
env.CommandNoCache('#core/authors.gen.h', "../AUTHORS.md", run_in_subprocess(core_builders.make_authors_header))
# Donors
env.Depends("#core/donors.gen.h", "../DONORS.md")
env.CommandNoCache("#core/donors.gen.h", "../DONORS.md", run_in_subprocess(core_builders.make_donors_header))
env.Depends('#core/donors.gen.h', "../DONORS.md")
env.CommandNoCache('#core/donors.gen.h', "../DONORS.md", run_in_subprocess(core_builders.make_donors_header))
# License
env.Depends("#core/license.gen.h", ["../COPYRIGHT.txt", "../LICENSE.txt"])
env.CommandNoCache(
"#core/license.gen.h", ["../COPYRIGHT.txt", "../LICENSE.txt"], run_in_subprocess(core_builders.make_license_header)
)
env.Depends('#core/license.gen.h', ["../COPYRIGHT.txt", "../LICENSE.txt"])
env.CommandNoCache('#core/license.gen.h', ["../COPYRIGHT.txt", "../LICENSE.txt"], run_in_subprocess(core_builders.make_license_header))
# Chain load SCsubs
SConscript("os/SCsub")
SConscript("math/SCsub")
SConscript("crypto/SCsub")
SConscript("io/SCsub")
SConscript("bind/SCsub")
SConscript('os/SCsub')
SConscript('math/SCsub')
SConscript('io/SCsub')
SConscript('bind/SCsub')
# Build it all as a library
lib = env.add_library("core", env.core_sources)
env.Prepend(LIBS=[lib])
# Needed to force rebuilding the core files when the thirdparty code is updated.
env.Depends(lib, thirdparty_obj)

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -42,13 +42,13 @@ public:
};
void Array::_ref(const Array &p_from) const {
ArrayPrivate *_fp = p_from._p;
ERR_FAIL_COND(!_fp); // should NOT happen.
if (_fp == _p) {
if (_fp == _p)
return; // whatever it is, nothing to do here move along
}
bool success = _fp->refcount.ref();
@@ -60,87 +60,97 @@ void Array::_ref(const Array &p_from) const {
}
void Array::_unref() const {
if (!_p) {
if (!_p)
return;
}
if (_p->refcount.unref()) {
memdelete(_p);
}
_p = nullptr;
_p = NULL;
}
Variant &Array::operator[](int p_idx) {
return _p->array.write[p_idx];
}
const Variant &Array::operator[](int p_idx) const {
return _p->array[p_idx];
}
int Array::size() const {
return _p->array.size();
}
bool Array::empty() const {
return _p->array.empty();
}
void Array::clear() {
_p->array.clear();
}
bool Array::operator==(const Array &p_array) const {
return _p == p_array._p;
}
uint32_t Array::hash() const {
uint32_t h = hash_djb2_one_32(0);
for (int i = 0; i < _p->array.size(); i++) {
h = hash_djb2_one_32(_p->array[i].hash(), h);
}
return h;
}
void Array::operator=(const Array &p_array) {
_ref(p_array);
}
void Array::push_back(const Variant &p_value) {
_p->array.push_back(p_value);
}
void Array::append_array(const Array &p_array) {
_p->array.append_array(p_array._p->array);
}
Error Array::resize(int p_new_size) {
return _p->array.resize(p_new_size);
}
void Array::insert(int p_pos, const Variant &p_value) {
_p->array.insert(p_pos, p_value);
}
void Array::erase(const Variant &p_value) {
_p->array.erase(p_value);
}
Variant Array::front() const {
ERR_FAIL_COND_V_MSG(_p->array.size() == 0, Variant(), "Can't take value from empty array.");
ERR_FAIL_COND_V(_p->array.size() == 0, Variant());
return operator[](0);
}
Variant Array::back() const {
ERR_FAIL_COND_V_MSG(_p->array.size() == 0, Variant(), "Can't take value from empty array.");
ERR_FAIL_COND_V(_p->array.size() == 0, Variant());
return operator[](_p->array.size() - 1);
}
int Array::find(const Variant &p_value, int p_from) const {
return _p->array.find(p_value, p_from);
}
int Array::rfind(const Variant &p_value, int p_from) const {
if (_p->array.size() == 0) {
if (_p->array.size() == 0)
return -1;
}
if (p_from < 0) {
// Relative offset from the end
@@ -152,29 +162,32 @@ int Array::rfind(const Variant &p_value, int p_from) const {
}
for (int i = p_from; i >= 0; i--) {
if (_p->array[i] == p_value) {
return i;
}
}
};
};
return -1;
}
int Array::find_last(const Variant &p_value) const {
return rfind(p_value);
}
int Array::count(const Variant &p_value) const {
if (_p->array.size() == 0) {
if (_p->array.size() == 0)
return 0;
}
int amount = 0;
for (int i = 0; i < _p->array.size(); i++) {
if (_p->array[i] == p_value) {
amount++;
}
}
};
};
return amount;
}
@@ -184,18 +197,22 @@ bool Array::has(const Variant &p_value) const {
}
void Array::remove(int p_pos) {
_p->array.remove(p_pos);
}
void Array::set(int p_idx, const Variant &p_value) {
operator[](p_idx) = p_value;
}
const Variant &Array::get(int p_idx) const {
return operator[](p_idx);
}
Array Array::duplicate(bool p_deep) const {
Array new_arr;
int element_count = size();
new_arr.resize(element_count);
@@ -205,90 +222,41 @@ Array Array::duplicate(bool p_deep) const {
return new_arr;
}
int Array::_clamp_slice_index(int p_index) const {
int arr_size = size();
int fixed_index = CLAMP(p_index, -arr_size, arr_size - 1);
if (fixed_index < 0) {
fixed_index = arr_size + fixed_index;
}
return fixed_index;
}
Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // like python, but inclusive on upper bound
Array new_arr;
ERR_FAIL_COND_V_MSG(p_step == 0, new_arr, "Array slice step size cannot be zero.");
if (empty()) { // Don't try to slice empty arrays.
return new_arr;
}
if (p_step > 0) {
if (p_begin >= size() || p_end < -size()) {
return new_arr;
}
} else { // p_step < 0
if (p_begin < -size() || p_end >= size()) {
return new_arr;
}
}
int begin = _clamp_slice_index(p_begin);
int end = _clamp_slice_index(p_end);
int new_arr_size = MAX(((end - begin + p_step) / p_step), 0);
new_arr.resize(new_arr_size);
if (p_step > 0) {
int dest_idx = 0;
for (int idx = begin; idx <= end; idx += p_step) {
ERR_FAIL_COND_V_MSG(dest_idx < 0 || dest_idx >= new_arr_size, Array(), "Bug in Array slice()");
new_arr[dest_idx++] = p_deep ? get(idx).duplicate(p_deep) : get(idx);
}
} else { // p_step < 0
int dest_idx = 0;
for (int idx = begin; idx >= end; idx += p_step) {
ERR_FAIL_COND_V_MSG(dest_idx < 0 || dest_idx >= new_arr_size, Array(), "Bug in Array slice()");
new_arr[dest_idx++] = p_deep ? get(idx).duplicate(p_deep) : get(idx);
}
}
return new_arr;
}
struct _ArrayVariantSort {
_FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const {
bool valid = false;
Variant res;
Variant::evaluate(Variant::OP_LESS, p_l, p_r, res, valid);
if (!valid) {
if (!valid)
res = false;
}
return res;
}
};
Array &Array::sort() {
_p->array.sort_custom<_ArrayVariantSort>();
return *this;
}
struct _ArrayVariantSortCustom {
Object *obj;
StringName func;
_FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const {
const Variant *args[2] = { &p_l, &p_r };
Variant::CallError err;
bool res = obj->call(func, args, 2, err);
if (err.error != Variant::CallError::CALL_OK) {
if (err.error != Variant::CallError::CALL_OK)
res = false;
}
return res;
}
};
Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {
ERR_FAIL_NULL_V(p_obj, *this);
SortArray<Variant, _ArrayVariantSortCustom, true> avs;
@@ -299,10 +267,10 @@ Array &Array::sort_custom(Object *p_obj, const StringName &p_function) {
}
void Array::shuffle() {
const int n = _p->array.size();
if (n < 2) {
if (n < 2)
return;
}
Variant *data = _p->array.ptrw();
for (int i = n - 1; i >= 1; i--) {
const int j = Math::rand() % (i + 1);
@@ -314,6 +282,7 @@ void Array::shuffle() {
template <typename Less>
_FORCE_INLINE_ int bisect(const Vector<Variant> &p_array, const Variant &p_value, bool p_before, const Less &p_less) {
int lo = 0;
int hi = p_array.size();
if (p_before) {
@@ -339,10 +308,12 @@ _FORCE_INLINE_ int bisect(const Vector<Variant> &p_array, const Variant &p_value
}
int Array::bsearch(const Variant &p_value, bool p_before) {
return bisect(_p->array, p_value, p_before, _ArrayVariantSort());
}
int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringName &p_function, bool p_before) {
ERR_FAIL_NULL_V(p_obj, 0);
_ArrayVariantSortCustom less;
@@ -353,18 +324,21 @@ int Array::bsearch_custom(const Variant &p_value, Object *p_obj, const StringNam
}
Array &Array::invert() {
_p->array.invert();
return *this;
}
void Array::push_front(const Variant &p_value) {
_p->array.insert(0, p_value);
}
Variant Array::pop_back() {
if (!_p->array.empty()) {
const int n = _p->array.size() - 1;
const Variant ret = _p->array.get(n);
int n = _p->array.size() - 1;
Variant ret = _p->array.get(n);
_p->array.resize(n);
return ret;
}
@@ -372,40 +346,17 @@ Variant Array::pop_back() {
}
Variant Array::pop_front() {
if (!_p->array.empty()) {
const Variant ret = _p->array.get(0);
Variant ret = _p->array.get(0);
_p->array.remove(0);
return ret;
}
return Variant();
}
Variant Array::pop_at(int p_pos) {
if (_p->array.empty()) {
// Return `null` without printing an error to mimic `pop_back()` and `pop_front()` behavior.
return Variant();
}
if (p_pos < 0) {
// Relative offset from the end
p_pos = _p->array.size() + p_pos;
}
ERR_FAIL_INDEX_V_MSG(
p_pos,
_p->array.size(),
Variant(),
vformat(
"The calculated index %s is out of bounds (the array has %s elements). Leaving the array untouched and returning `null`.",
p_pos,
_p->array.size()));
const Variant ret = _p->array.get(p_pos);
_p->array.remove(p_pos);
return ret;
}
Variant Array::min() const {
Variant minval;
for (int i = 0; i < size(); i++) {
if (i == 0) {
@@ -428,6 +379,7 @@ Variant Array::min() const {
}
Variant Array::max() const {
Variant maxval;
for (int i = 0; i < size(); i++) {
if (i == 0) {
@@ -449,19 +401,18 @@ Variant Array::max() const {
return maxval;
}
const void *Array::id() const {
return _p->array.ptr();
}
Array::Array(const Array &p_from) {
_p = nullptr;
_p = NULL;
_ref(p_from);
}
Array::Array() {
_p = memnew(ArrayPrivate);
_p->refcount.init();
}
Array::~Array() {
_unref();
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -39,12 +39,11 @@ class Object;
class StringName;
class Array {
mutable ArrayPrivate *_p;
void _ref(const Array &p_from) const;
void _unref() const;
inline int _clamp_slice_index(int p_index) const;
public:
Variant &operator[](int p_idx);
const Variant &operator[](int p_idx) const;
@@ -63,7 +62,6 @@ public:
void push_back(const Variant &p_value);
_FORCE_INLINE_ void append(const Variant &p_value) { push_back(p_value); } //for python compatibility
void append_array(const Array &p_array);
Error resize(int p_new_size);
void insert(int p_pos, const Variant &p_value);
@@ -90,17 +88,12 @@ public:
void push_front(const Variant &p_value);
Variant pop_back();
Variant pop_front();
Variant pop_at(int p_pos);
Array duplicate(bool p_deep = false) const;
Array slice(int p_begin, int p_end, int p_step = 1, bool p_deep = false) const;
Variant min() const;
Variant max() const;
const void *id() const;
Array(const Array &p_from);
Array();
~Array();

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env python
Import("env")
Import('env')
env.add_source_files(env.core_sources, "*.cpp")

File diff suppressed because it is too large Load Diff

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -40,7 +40,6 @@
#include "core/os/os.h"
#include "core/os/semaphore.h"
#include "core/os/thread.h"
#include "core/safe_refcount.h"
class _ResourceLoader : public Object {
GDCLASS(_ResourceLoader, Object);
@@ -86,7 +85,7 @@ public:
static _ResourceSaver *get_singleton() { return singleton; }
Error save(const String &p_path, const RES &p_resource, SaverFlags p_flags);
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags);
PoolVector<String> get_recognized_extensions(const RES &p_resource);
_ResourceSaver();
@@ -110,11 +109,11 @@ public:
};
enum PowerState {
POWERSTATE_UNKNOWN, // Cannot determine power status.
POWERSTATE_ON_BATTERY, // Not plugged in, running on the battery.
POWERSTATE_NO_BATTERY, // Plugged in, no battery available.
POWERSTATE_CHARGING, // Plugged in, charging battery.
POWERSTATE_CHARGED // Plugged in, battery charged.
POWERSTATE_UNKNOWN, /**< cannot determine power status */
POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */
POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */
POWERSTATE_CHARGING, /**< Plugged in, charging battery */
POWERSTATE_CHARGED /**< Plugged in, battery charged */
};
enum Weekday {
@@ -128,8 +127,8 @@ public:
};
enum Month {
// Start at 1 to follow Windows SYSTEMTIME structure
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
/// Start at 1 to follow Windows SYSTEMTIME structure
/// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724950(v=vs.85).aspx
MONTH_JANUARY = 1,
MONTH_FEBRUARY,
MONTH_MARCH,
@@ -144,22 +143,8 @@ public:
MONTH_DECEMBER
};
enum HandleType {
APPLICATION_HANDLE, // HINSTANCE, NSApplication*, UIApplication*, JNIEnv* ...
DISPLAY_HANDLE, // X11::Display* ...
WINDOW_HANDLE, // HWND, X11::Window*, NSWindow*, UIWindow*, Android activity ...
WINDOW_VIEW, // HDC, NSView*, UIView*, Android surface ...
OPENGL_CONTEXT, // HGLRC, X11::GLXContext, NSOpenGLContext*, EGLContext* ...
};
void global_menu_add_item(const String &p_menu, const String &p_label, const Variant &p_signal, const Variant &p_meta);
void global_menu_add_separator(const String &p_menu);
void global_menu_remove_item(const String &p_menu, int p_idx);
void global_menu_clear(const String &p_menu);
Point2 get_mouse_position() const;
void set_window_title(const String &p_title);
void set_window_mouse_passthrough(const PoolVector2Array &p_region);
int get_mouse_button_state() const;
void set_clipboard(const String &p_text);
@@ -188,17 +173,11 @@ public:
virtual Point2 get_screen_position(int p_screen = -1) const;
virtual Size2 get_screen_size(int p_screen = -1) const;
virtual int get_screen_dpi(int p_screen = -1) const;
virtual float get_screen_scale(int p_screen = -1) const;
virtual float get_screen_max_scale() const;
virtual Point2 get_window_position() const;
virtual void set_window_position(const Point2 &p_position);
virtual Size2 get_max_window_size() const;
virtual Size2 get_min_window_size() const;
virtual Size2 get_window_size() const;
virtual Size2 get_real_window_size() const;
virtual Rect2 get_window_safe_area() const;
virtual void set_max_window_size(const Size2 &p_size);
virtual void set_min_window_size(const Size2 &p_size);
virtual void set_window_size(const Size2 &p_size);
virtual void set_window_fullscreen(bool p_enabled);
virtual bool is_window_fullscreen() const;
@@ -210,13 +189,10 @@ public:
virtual bool is_window_maximized() const;
virtual void set_window_always_on_top(bool p_enabled);
virtual bool is_window_always_on_top() const;
virtual bool is_window_focused() const;
virtual void request_attention();
virtual void center_window();
virtual void move_window_to_foreground();
virtual int64_t get_native_handle(HandleType p_handle_type);
virtual void set_borderless_window(bool p_borderless);
virtual bool get_borderless_window() const;
@@ -237,11 +213,8 @@ public:
void set_low_processor_usage_mode(bool p_enabled);
bool is_in_low_processor_usage_mode() const;
void set_low_processor_usage_mode_sleep_usec(int p_usec);
int get_low_processor_usage_mode_sleep_usec() const;
String get_executable_path() const;
int execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking = true, Array p_output = Array(), bool p_read_stderr = false);
int execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output = Array());
Error kill(int p_pid);
Error shell_open(String p_uri);
@@ -250,19 +223,12 @@ public:
bool has_environment(const String &p_var) const;
String get_environment(const String &p_var) const;
bool set_environment(const String &p_var, const String &p_value) const;
String get_name() const;
Vector<String> get_cmdline_args();
String get_locale() const;
String get_locale_language() const;
String get_latin_keyboard_variant() const;
int keyboard_get_layout_count() const;
int keyboard_get_current_layout() const;
void keyboard_set_current_layout(int p_index);
String keyboard_get_layout_language(int p_index) const;
String keyboard_get_layout_name(int p_index) const;
String get_model_name() const;
@@ -270,7 +236,7 @@ public:
void dump_resources_to_file(const String &p_file);
bool has_virtual_keyboard() const;
void show_virtual_keyboard(const String &p_existing_text = "", bool p_multiline = false);
void show_virtual_keyboard(const String &p_existing_text = "");
void hide_virtual_keyboard();
int get_virtual_keyboard_height();
@@ -289,9 +255,26 @@ public:
bool is_scancode_unicode(uint32_t p_unicode) const;
int find_scancode_from_string(const String &p_code) const;
/*
struct Date {
int year;
Month month;
int day;
Weekday weekday;
bool dst;
};
struct Time {
int hour;
int min;
int sec;
};
*/
void set_use_file_access_save_and_swap(bool p_enable);
void set_native_icon(const String &p_filename);
void set_icon(const Ref<Image> &p_icon);
int get_exit_code() const;
@@ -310,9 +293,9 @@ public:
uint64_t get_static_memory_peak_usage() const;
uint64_t get_dynamic_memory_usage() const;
void delay_usec(int p_usec) const;
void delay_msec(int p_msec) const;
uint64_t get_ticks_msec() const;
void delay_usec(uint32_t p_usec) const;
void delay_msec(uint32_t p_msec) const;
uint32_t get_ticks_msec() const;
uint64_t get_ticks_usec() const;
uint32_t get_splash_tick_msec() const;
@@ -348,12 +331,9 @@ public:
SCREEN_ORIENTATION_SENSOR,
};
String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const;
String get_system_dir(SystemDir p_dir) const;
String get_user_data_dir() const;
String get_config_dir() const;
String get_data_dir() const;
String get_cache_dir() const;
void alert(const String &p_alert, const String &p_title = "ALERT!");
@@ -366,17 +346,10 @@ public:
bool is_ok_left_and_cancel_right() const;
Error set_thread_name(const String &p_name);
Thread::ID get_thread_caller_id() const;
void set_use_vsync(bool p_enable);
bool is_vsync_enabled() const;
void set_vsync_via_compositor(bool p_enable);
bool is_vsync_via_compositor_enabled() const;
void set_delta_smoothing(bool p_enabled);
bool is_delta_smoothing_enabled() const;
PowerState get_power_state();
int get_power_seconds_left();
int get_power_percent_left();
@@ -384,13 +357,6 @@ public:
bool has_feature(const String &p_feature) const;
bool request_permission(const String &p_name);
bool request_permissions();
Vector<String> get_granted_permissions() const;
int get_tablet_driver_count() const;
String get_tablet_driver_name(int p_driver) const;
String get_current_tablet_driver() const;
void set_current_tablet_driver(const String &p_driver);
static _OS *get_singleton() { return singleton; }
@@ -403,9 +369,9 @@ VARIANT_ENUM_CAST(_OS::Weekday);
VARIANT_ENUM_CAST(_OS::Month);
VARIANT_ENUM_CAST(_OS::SystemDir);
VARIANT_ENUM_CAST(_OS::ScreenOrientation);
VARIANT_ENUM_CAST(_OS::HandleType);
class _Geometry : public Object {
GDCLASS(_Geometry, Object);
static _Geometry *singleton;
@@ -433,59 +399,20 @@ public:
PoolVector<Vector3> segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius);
PoolVector<Vector3> segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius);
PoolVector<Vector3> segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes);
bool is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius);
real_t segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius);
int get_uv84_normal_bit(const Vector3 &p_vector);
bool is_polygon_clockwise(const Vector<Vector2> &p_polygon);
bool is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon);
Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon);
Vector<int> triangulate_delaunay_2d(const Vector<Vector2> &p_points);
Vector<Point2> convex_hull_2d(const Vector<Point2> &p_points);
Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane);
enum PolyBooleanOperation {
OPERATION_UNION,
OPERATION_DIFFERENCE,
OPERATION_INTERSECTION,
OPERATION_XOR
};
// 2D polygon boolean operations.
Array merge_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Union (add).
Array clip_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Difference (subtract).
Array intersect_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // Common area (multiply).
Array exclude_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b); // All but common area (xor).
// 2D polyline vs polygon operations.
Array clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon); // Cut.
Array intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon); // Chop.
// 2D offset polygons/polylines.
enum PolyJoinType {
JOIN_SQUARE,
JOIN_ROUND,
JOIN_MITER
};
enum PolyEndType {
END_POLYGON,
END_JOINED,
END_BUTT,
END_SQUARE,
END_ROUND
};
Array offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type = JOIN_SQUARE);
Array offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type = JOIN_SQUARE, PolyEndType p_end_type = END_SQUARE);
Dictionary make_atlas(const Vector<Size2> &p_rects);
_Geometry();
};
VARIANT_ENUM_CAST(_Geometry::PolyBooleanOperation);
VARIANT_ENUM_CAST(_Geometry::PolyJoinType);
VARIANT_ENUM_CAST(_Geometry::PolyEndType);
class _File : public Reference {
GDCLASS(_File, Reference);
FileAccess *f;
bool eswap;
@@ -509,29 +436,28 @@ public:
COMPRESSION_GZIP = Compression::MODE_GZIP
};
Error open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key);
Error open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass);
Error open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode = COMPRESSION_FASTLZ);
Error open_encrypted(const String &p_path, int p_mode_flags, const Vector<uint8_t> &p_key);
Error open_encrypted_pass(const String &p_path, int p_mode_flags, const String &p_pass);
Error open_compressed(const String &p_path, int p_mode_flags, int p_compress_mode = 0);
Error open(const String &p_path, ModeFlags p_mode_flags); // open a file.
void flush(); // Flush a file (write its buffer to disk).
void close(); // Close a file.
bool is_open() const; // True when file is open.
Error open(const String &p_path, int p_mode_flags); ///< open a file
void close(); ///< close a file
bool is_open() const; ///< true when file is open
String get_path() const; // Returns the path for the current open file.
String get_path_absolute() const; // Returns the absolute path for the current open file.
String get_path() const; /// returns the path for the current open file
String get_path_absolute() const; /// returns the absolute path for the current open file
void seek(int64_t p_position); // Seek to a given position.
void seek_end(int64_t p_position = 0); // Seek from the end of file.
uint64_t get_position() const; // Get position in the file.
uint64_t get_len() const; // Get size of the file.
void seek(int64_t p_position); ///< seek to a given position
void seek_end(int64_t p_position = 0); ///< seek from the end of file
int64_t get_position() const; ///< get position in the file
int64_t get_len() const; ///< get size of the file
bool eof_reached() const; // Reading passed EOF.
bool eof_reached() const; ///< reading passed EOF
uint8_t get_8() const; // Get a byte.
uint16_t get_16() const; // Get 16 bits uint.
uint32_t get_32() const; // Get 32 bits uint.
uint64_t get_64() const; // Get 64 bits uint.
uint8_t get_8() const; ///< get a byte
uint16_t get_16() const; ///< get 16 bits uint
uint32_t get_32() const; ///< get 32 bits uint
uint64_t get_64() const; ///< get 64 bits uint
float get_float() const;
double get_double() const;
@@ -539,27 +465,27 @@ public:
Variant get_var(bool p_allow_objects = false) const;
PoolVector<uint8_t> get_buffer(int64_t p_length) const; // Get an array of bytes.
PoolVector<uint8_t> get_buffer(int p_length) const; ///< get an array of bytes
String get_line() const;
Vector<String> get_csv_line(const String &p_delim = ",") const;
String get_as_text() const;
String get_md5(const String &p_path) const;
String get_sha256(const String &p_path) const;
/* Use this for files WRITTEN in _big_ endian machines (ie, amiga/mac).
/**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
* It's not about the current CPU type but file formats.
* This flags get reset to false (little endian) on each open.
* this flags get reset to false (little endian) on each open
*/
void set_endian_swap(bool p_swap);
bool get_endian_swap();
Error get_error() const; // Get last error.
Error get_error() const; ///< get last error
void store_8(uint8_t p_dest); // Store a byte.
void store_16(uint16_t p_dest); // Store 16 bits uint.
void store_32(uint32_t p_dest); // Store 32 bits uint.
void store_64(uint64_t p_dest); // Store 64 bits uint.
void store_8(uint8_t p_dest); ///< store a byte
void store_16(uint16_t p_dest); ///< store 16 bits uint
void store_32(uint32_t p_dest); ///< store 32 bits uint
void store_64(uint64_t p_dest); ///< store 64 bits uint
void store_float(float p_dest);
void store_double(double p_dest);
@@ -572,11 +498,11 @@ public:
virtual void store_pascal_string(const String &p_string);
virtual String get_pascal_string();
void store_buffer(const PoolVector<uint8_t> &p_buffer); // Store an array of bytes.
void store_buffer(const PoolVector<uint8_t> &p_buffer); ///< store an array of bytes
void store_var(const Variant &p_var, bool p_full_objects = false);
bool file_exists(const String &p_name) const; // Return true if a file exists.
bool file_exists(const String &p_name) const; ///< return true if a file exists
uint64_t get_modified_time(const String &p_file) const;
@@ -588,6 +514,7 @@ VARIANT_ENUM_CAST(_File::ModeFlags);
VARIANT_ENUM_CAST(_File::CompressionMode);
class _Directory : public Reference {
GDCLASS(_Directory, Reference);
DirAccess *d;
@@ -597,18 +524,18 @@ protected:
public:
Error open(const String &p_path);
Error list_dir_begin(bool p_skip_navigational = false, bool p_skip_hidden = false); // This starts dir listing.
Error list_dir_begin(bool p_skip_navigational = false, bool p_skip_hidden = false); ///< This starts dir listing
String get_next();
bool current_is_dir() const;
void list_dir_end();
void list_dir_end(); ///<
int get_drive_count();
String get_drive(int p_drive);
int get_current_drive();
Error change_dir(String p_dir); // Can be relative or absolute, return false on success.
String get_current_dir(); // Return current dir location.
Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
String get_current_dir(); ///< return current dir location
Error make_dir(String p_dir);
Error make_dir_recursive(String p_dir);
@@ -616,7 +543,7 @@ public:
bool file_exists(String p_file);
bool dir_exists(String p_dir);
uint64_t get_space_left();
int get_space_left();
Error copy(String p_from, String p_to);
Error rename(String p_from, String p_to);
@@ -630,8 +557,9 @@ private:
bool _list_skip_hidden;
};
class _Marshalls : public Object {
GDCLASS(_Marshalls, Object);
class _Marshalls : public Reference {
GDCLASS(_Marshalls, Reference);
static _Marshalls *singleton;
@@ -651,12 +579,13 @@ public:
String base64_to_utf8(const String &p_str);
_Marshalls() { singleton = this; }
~_Marshalls() { singleton = nullptr; }
~_Marshalls() { singleton = NULL; }
};
class _Mutex : public Reference {
GDCLASS(_Mutex, Reference);
Mutex mutex;
Mutex *mutex;
static void _bind_methods();
@@ -664,29 +593,37 @@ public:
void lock();
Error try_lock();
void unlock();
_Mutex();
~_Mutex();
};
class _Semaphore : public Reference {
GDCLASS(_Semaphore, Reference);
Semaphore semaphore;
Semaphore *semaphore;
static void _bind_methods();
public:
Error wait();
Error post();
_Semaphore();
~_Semaphore();
};
class _Thread : public Reference {
GDCLASS(_Thread, Reference);
protected:
Variant ret;
Variant userdata;
SafeFlag running;
ObjectID target_instance_id;
volatile bool active;
Object *target_instance;
StringName target_method;
Thread thread;
Thread *thread;
static void _bind_methods();
static void _start_func(void *ud);
@@ -695,14 +632,12 @@ public:
PRIORITY_LOW,
PRIORITY_NORMAL,
PRIORITY_HIGH,
PRIORITY_MAX
PRIORITY_HIGH
};
Error start(Object *p_instance, const StringName &p_method, const Variant &p_userdata = Variant(), Priority p_priority = PRIORITY_NORMAL);
Error start(Object *p_instance, const StringName &p_method, const Variant &p_userdata = Variant(), int p_priority = PRIORITY_NORMAL);
String get_id() const;
bool is_active() const;
bool is_alive() const;
Variant wait_to_finish();
_Thread();
@@ -712,7 +647,8 @@ public:
VARIANT_ENUM_CAST(_Thread::Priority);
class _ClassDB : public Object {
GDCLASS(_ClassDB, Object);
GDCLASS(_ClassDB, Object)
protected:
static void _bind_methods();
@@ -743,11 +679,6 @@ public:
int get_integer_constant(const StringName &p_class, const StringName &p_name) const;
StringName get_category(const StringName &p_node) const;
bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false) const;
PoolStringArray get_enum_list(const StringName &p_class, bool p_no_inheritance = false) const;
PoolStringArray get_enum_constants(const StringName &p_class, const StringName &p_enum, bool p_no_inheritance = false) const;
StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false) const;
bool is_class_enabled(StringName p_class) const;
_ClassDB();
@@ -768,14 +699,11 @@ public:
void set_physics_jitter_fix(float p_threshold);
float get_physics_jitter_fix() const;
float get_physics_interpolation_fraction() const;
void set_target_fps(int p_fps);
int get_target_fps() const;
float get_frames_per_second() const;
uint64_t get_physics_frames() const;
uint64_t get_idle_frames() const;
int get_frames_drawn();
@@ -799,16 +727,13 @@ public:
void set_editor_hint(bool p_enabled);
bool is_editor_hint() const;
void set_print_error_messages(bool p_enabled);
bool is_printing_error_messages() const;
_Engine();
};
class _JSON;
class JSONParseResult : public Reference {
GDCLASS(JSONParseResult, Reference);
GDCLASS(JSONParseResult, Reference)
friend class _JSON;
@@ -833,13 +758,10 @@ public:
void set_result(const Variant &p_result);
Variant get_result() const;
JSONParseResult() :
error_line(-1) {}
};
class _JSON : public Object {
GDCLASS(_JSON, Object);
GDCLASS(_JSON, Object)
protected:
static void _bind_methods();

View File

@@ -1,79 +0,0 @@
/*************************************************************************/
/* bitfield_dynamic.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "bitfield_dynamic.h"
#include "core/os/memory.h"
#include <string.h>
void BitFieldDynamic::copy_from(const BitFieldDynamic &p_source) {
create(p_source.get_num_bits(), false);
memcpy(_data, p_source.get_data(), p_source.get_num_bytes());
}
void BitFieldDynamic::create(uint32_t p_num_bits, bool p_blank) {
// first delete any initial
destroy();
_num_bits = p_num_bits;
if (p_num_bits) {
_num_bytes = (p_num_bits / 8) + 1;
_data = (uint8_t *)memalloc(_num_bytes);
if (p_blank) {
blank(false);
}
}
}
void BitFieldDynamic::destroy() {
if (_data) {
memfree(_data);
_data = nullptr;
}
_num_bytes = 0;
_num_bits = 0;
}
void BitFieldDynamic::blank(bool p_set_or_zero) {
if (p_set_or_zero) {
memset(_data, 255, _num_bytes);
} else {
memset(_data, 0, _num_bytes);
}
}
void BitFieldDynamic::invert() {
for (uint32_t n = 0; n < _num_bytes; n++) {
_data[n] = ~_data[n];
}
}

View File

@@ -1,111 +0,0 @@
/*************************************************************************/
/* bitfield_dynamic.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef BITFIELD_DYNAMIC_H
#define BITFIELD_DYNAMIC_H
#include "core/error_macros.h"
class BitFieldDynamic {
public:
~BitFieldDynamic() { destroy(); }
private:
// prevent copying (see effective C++ scott meyers)
// there is no implementation for copy constructor, hence compiler will complain if you try to copy
// feel free to add one if needed...
BitFieldDynamic &operator=(const BitFieldDynamic &);
public:
// create automatically blanks
void create(uint32_t p_num_bits, bool p_blank = true);
void destroy();
// public funcs
uint32_t get_num_bits() const { return _num_bits; }
uint32_t get_bit(uint32_t p_bit) const;
void set_bit(uint32_t p_bit, uint32_t p_set);
bool check_and_set(uint32_t p_bit);
void blank(bool p_set_or_zero = false);
void invert();
void copy_from(const BitFieldDynamic &p_source);
// loading / saving
uint8_t *get_data() { return _data; }
const uint8_t *get_data() const { return _data; }
uint32_t get_num_bytes() const { return _num_bytes; }
protected:
// member vars
uint8_t *_data = nullptr;
uint32_t _num_bytes = 0;
uint32_t _num_bits = 0;
};
inline uint32_t BitFieldDynamic::get_bit(uint32_t p_bit) const {
DEV_ASSERT(_data);
uint32_t byte_number = p_bit >> 3; // divide by 8
DEV_ASSERT(byte_number < _num_bytes);
uint8_t uc = _data[byte_number];
uint32_t bit_set = uc & (1 << (p_bit & 7));
return bit_set;
}
inline bool BitFieldDynamic::check_and_set(uint32_t p_bit) {
DEV_ASSERT(_data);
uint32_t byte_number = p_bit >> 3; // divide by 8
DEV_ASSERT(byte_number < _num_bytes);
uint8_t &uc = _data[byte_number];
uint32_t mask = (1 << (p_bit & 7));
uint32_t bit_set = uc & mask;
if (bit_set) {
return false;
}
// set
uc = uc | mask;
return true;
}
inline void BitFieldDynamic::set_bit(uint32_t p_bit, uint32_t p_set) {
DEV_ASSERT(_data);
uint32_t byte_number = p_bit >> 3; // divide by 8
DEV_ASSERT(byte_number < _num_bytes);
uint8_t uc = _data[byte_number];
uint32_t mask = 1 << (p_bit & 7);
if (p_set) {
uc = uc | mask;
} else {
uc &= ~mask;
}
_data[byte_number] = uc;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -35,6 +35,10 @@
#include "core/object.h"
#include "core/print_string.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
/** To bind more then 6 parameters include this:
* #include "core/method_bind_ext.gen.inc"
*/
@@ -46,6 +50,7 @@
#ifdef DEBUG_METHODS_ENABLED
struct MethodDefinition {
StringName name;
Vector<StringName> args;
MethodDefinition() {}
@@ -100,6 +105,7 @@ public:
public:
struct PropertySetGet {
int index;
StringName setter;
StringName getter;
@@ -109,12 +115,12 @@ public:
};
struct ClassInfo {
APIType api;
ClassInfo *inherits_ptr;
void *class_ptr;
HashMap<StringName, MethodBind *> method_map;
HashMap<StringName, int> constant_map;
HashMap<StringName, List<StringName>> enum_map;
HashMap<StringName, List<StringName> > enum_map;
HashMap<StringName, MethodInfo> signal_map;
List<PropertyInfo> property_list;
#ifdef DEBUG_METHODS_ENABLED
@@ -140,7 +146,7 @@ public:
return memnew(T);
}
static RWLock lock;
static RWLock *lock;
static HashMap<StringName, ClassInfo> classes;
static HashMap<StringName, StringName> resource_base_extensions;
static HashMap<StringName, StringName> compat_classes;
@@ -155,64 +161,59 @@ public:
static void _add_class2(const StringName &p_class, const StringName &p_inherits);
static HashMap<StringName, HashMap<StringName, Variant>> default_values;
static Set<StringName> default_values_cached;
private:
// Non-locking variants of get_parent_class and is_parent_class.
static StringName _get_parent_class(const StringName &p_class);
static bool _is_parent_class(const StringName &p_class, const StringName &p_inherits);
static HashMap<StringName, HashMap<StringName, Variant> > default_values;
public:
// DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
template <class T>
static void _add_class() {
_add_class2(T::get_class_static(), T::get_parent_class_static());
}
template <class T>
static void register_class() {
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t);
t->creation_func = &creator<T>;
t->exposed = true;
t->class_ptr = T::get_class_ptr_static();
T::register_custom_data_to_otdb();
}
template <class T>
static void register_virtual_class() {
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t);
t->exposed = true;
t->class_ptr = T::get_class_ptr_static();
//nothing
}
template <class T>
static Object *_create_ptr_func() {
return T::create();
}
template <class T>
static void register_custom_instance_class() {
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t);
t->creation_func = &_create_ptr_func<T>;
t->exposed = true;
t->class_ptr = T::get_class_ptr_static();
T::register_custom_data_to_otdb();
}
static void get_class_list(List<StringName> *p_classes);
static void get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
static StringName get_parent_class_nocheck(const StringName &p_class);
static StringName get_parent_class(const StringName &p_class);
static bool class_exists(const StringName &p_class);
@@ -225,13 +226,15 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method) {
MethodBind *bind = create_method_bind(p_method);
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, nullptr, 0); //use static function, much smaller binary usage
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, NULL, 0); //use static function, much smaller binary usage
}
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[1] = { &p_def1 };
@@ -240,6 +243,7 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[2] = { &p_def1, &p_def2 };
@@ -248,6 +252,7 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[3] = { &p_def1, &p_def2, &p_def3 };
@@ -256,6 +261,7 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[4] = { &p_def1, &p_def2, &p_def3, &p_def4 };
@@ -264,6 +270,7 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[5] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5 };
@@ -272,34 +279,20 @@ public:
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[6] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6 };
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 6);
}
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[7] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7 };
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 7);
}
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7, const Variant &p_def8) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[8] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7, &p_def8 };
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 8);
}
template <class M>
static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>(), bool p_return_nil_is_variant = true) {
static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>()) {
GLOBAL_LOCK_FUNCTION;
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
ERR_FAIL_COND_V(!bind, nullptr);
MethodBind *bind = create_vararg_method_bind(p_method, p_info);
ERR_FAIL_COND_V(!bind, NULL);
bind->set_name(p_name);
bind->set_default_arguments(p_default_args);
@@ -309,13 +302,14 @@ public:
ClassInfo *type = classes.getptr(instance_type);
if (!type) {
memdelete(bind);
ERR_FAIL_COND_V(!type, nullptr);
ERR_FAIL_COND_V(!type, NULL);
}
if (type->method_map.has(p_name)) {
memdelete(bind);
// overloading not supported
ERR_FAIL_V_MSG(nullptr, "Method already bound: " + instance_type + "::" + p_name + ".");
ERR_EXPLAIN("Method already bound: " + instance_type + "::" + p_name);
ERR_FAIL_V(NULL);
}
type->method_map[p_name] = bind;
#ifdef DEBUG_METHODS_ENABLED
@@ -334,15 +328,14 @@ public:
static void add_property_group(StringName p_class, const String &p_name, const String &p_prefix = "");
static void add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
static void set_property_default_value(StringName p_class, const StringName &p_name, const Variant &p_default);
static void get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance = false, const Object *p_validator = nullptr);
static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = nullptr);
static void get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance = false, const Object *p_validator = NULL);
static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = NULL);
static bool get_property(Object *p_object, const StringName &p_property, Variant &r_value);
static bool has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance = false);
static int get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
static Variant::Type get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
static StringName get_property_setter(StringName p_class, const StringName &p_property);
static StringName get_property_getter(StringName p_class, const StringName &p_property);
static int get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid = NULL);
static Variant::Type get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid = NULL);
static StringName get_property_setter(StringName p_class, const StringName p_property);
static StringName get_property_getter(StringName p_class, const StringName p_property);
static bool has_method(StringName p_class, StringName p_method, bool p_no_inheritance = false);
static void set_method_flags(StringName p_class, StringName p_method, int p_flags);
@@ -355,14 +348,13 @@ public:
static void bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int p_constant);
static void get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance = false);
static int get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = nullptr);
static int get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = NULL);
static StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
static void get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance = false);
static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance = false);
static bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid = nullptr);
static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property);
static StringName get_category(const StringName &p_node);
@@ -376,10 +368,10 @@ public:
static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions);
static void add_compatibility_class(const StringName &p_class, const StringName &p_fallback);
static void init();
static void set_current_api(APIType p_api);
static APIType get_current_api();
static void cleanup_defaults();
static void cleanup();
};

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -36,6 +36,7 @@
#include "core/print_string.h"
uint32_t Color::to_argb32() const {
uint32_t c = (uint8_t)Math::round(a * 255);
c <<= 8;
c |= (uint8_t)Math::round(r * 255);
@@ -48,6 +49,7 @@ uint32_t Color::to_argb32() const {
}
uint32_t Color::to_abgr32() const {
uint32_t c = (uint8_t)Math::round(a * 255);
c <<= 8;
c |= (uint8_t)Math::round(b * 255);
@@ -60,6 +62,7 @@ uint32_t Color::to_abgr32() const {
}
uint32_t Color::to_rgba32() const {
uint32_t c = (uint8_t)Math::round(r * 255);
c <<= 8;
c |= (uint8_t)Math::round(g * 255);
@@ -72,6 +75,7 @@ uint32_t Color::to_rgba32() const {
}
uint64_t Color::to_abgr64() const {
uint64_t c = (uint16_t)Math::round(a * 65535);
c <<= 16;
c |= (uint16_t)Math::round(b * 65535);
@@ -84,6 +88,7 @@ uint64_t Color::to_abgr64() const {
}
uint64_t Color::to_argb64() const {
uint64_t c = (uint16_t)Math::round(a * 65535);
c <<= 16;
c |= (uint16_t)Math::round(r * 65535);
@@ -96,6 +101,7 @@ uint64_t Color::to_argb64() const {
}
uint64_t Color::to_rgba64() const {
uint64_t c = (uint16_t)Math::round(r * 65535);
c <<= 16;
c |= (uint16_t)Math::round(g * 65535);
@@ -108,6 +114,7 @@ uint64_t Color::to_rgba64() const {
}
float Color::get_h() const {
float min = MIN(r, g);
min = MIN(min, b);
float max = MAX(r, g);
@@ -115,28 +122,26 @@ float Color::get_h() const {
float delta = max - min;
if (delta == 0) {
if (delta == 0)
return 0;
}
float h;
if (r == max) {
if (r == max)
h = (g - b) / delta; // between yellow & magenta
} else if (g == max) {
else if (g == max)
h = 2 + (b - r) / delta; // between cyan & yellow
} else {
else
h = 4 + (r - g) / delta; // between magenta & cyan
}
h /= 6.0;
if (h < 0) {
if (h < 0)
h += 1.0;
}
return h;
}
float Color::get_s() const {
float min = MIN(r, g);
min = MIN(min, b);
float max = MAX(r, g);
@@ -148,12 +153,14 @@ float Color::get_s() 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) {
int i;
float f, p, q, t;
a = p_alpha;
@@ -207,22 +214,21 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
}
}
bool Color::is_equal_approx(const Color &p_color) const {
return Math::is_equal_approx(r, p_color.r) && Math::is_equal_approx(g, p_color.g) && Math::is_equal_approx(b, p_color.b) && Math::is_equal_approx(a, p_color.a);
}
void Color::invert() {
r = 1.0 - r;
g = 1.0 - g;
b = 1.0 - b;
}
void Color::contrast() {
r = Math::fmod(r + 0.5, 1.0);
g = Math::fmod(g + 0.5, 1.0);
b = Math::fmod(b + 0.5, 1.0);
}
Color Color::hex(uint32_t p_hex) {
float a = (p_hex & 0xFF) / 255.0;
p_hex >>= 8;
float b = (p_hex & 0xFF) / 255.0;
@@ -235,6 +241,7 @@ Color Color::hex(uint32_t p_hex) {
}
Color Color::hex64(uint64_t p_hex) {
float a = (p_hex & 0xFFFF) / 65535.0;
p_hex >>= 16;
float b = (p_hex & 0xFFFF) / 65535.0;
@@ -247,6 +254,7 @@ Color Color::hex64(uint64_t p_hex) {
}
Color Color::from_rgbe9995(uint32_t p_rgbe) {
float r = p_rgbe & 0x1ff;
float g = (p_rgbe >> 9) & 0x1ff;
float b = (p_rgbe >> 18) & 0x1ff;
@@ -261,9 +269,11 @@ Color Color::from_rgbe9995(uint32_t p_rgbe) {
}
static float _parse_col(const String &p_str, int p_ofs) {
int ig = 0;
for (int i = 0; i < 2; i++) {
int c = p_str[i + p_ofs];
int v = 0;
@@ -279,36 +289,36 @@ static float _parse_col(const String &p_str, int p_ofs) {
return -1;
}
if (i == 0) {
if (i == 0)
ig += v * 16;
} else {
else
ig += v;
}
}
return ig;
}
Color Color::inverted() const {
Color c = *this;
c.invert();
return c;
}
Color Color::contrasted() const {
Color c = *this;
c.contrast();
return c;
}
Color Color::html(const String &p_color) {
String color = p_color;
if (color.length() == 0) {
if (color.length() == 0)
return Color();
}
if (color[0] == '#') {
if (color[0] == '#')
color = color.substr(1, color.length() - 1);
}
if (color.length() == 3 || color.length() == 4) {
String exp_color;
for (int i = 0; i < color.length(); i++) {
@@ -325,36 +335,48 @@ Color Color::html(const String &p_color) {
} else if (color.length() == 6) {
alpha = false;
} else {
ERR_FAIL_V_MSG(Color(), "Invalid color code: " + p_color + ".");
ERR_EXPLAIN("Invalid Color Code: " + p_color);
ERR_FAIL_V(Color());
}
int a = 255;
if (alpha) {
a = _parse_col(color, 0);
ERR_FAIL_COND_V_MSG(a < 0, Color(), "Invalid color code: " + p_color + ".");
if (a < 0) {
ERR_EXPLAIN("Invalid Color Code: " + p_color);
ERR_FAIL_V(Color());
}
}
int from = alpha ? 2 : 0;
int r = _parse_col(color, from + 0);
ERR_FAIL_COND_V_MSG(r < 0, Color(), "Invalid color code: " + p_color + ".");
if (r < 0) {
ERR_EXPLAIN("Invalid Color Code: " + p_color);
ERR_FAIL_V(Color());
}
int g = _parse_col(color, from + 2);
ERR_FAIL_COND_V_MSG(g < 0, Color(), "Invalid color code: " + p_color + ".");
if (g < 0) {
ERR_EXPLAIN("Invalid Color Code: " + p_color);
ERR_FAIL_V(Color());
}
int b = _parse_col(color, from + 4);
ERR_FAIL_COND_V_MSG(b < 0, Color(), "Invalid color code: " + p_color + ".");
if (b < 0) {
ERR_EXPLAIN("Invalid Color Code: " + p_color);
ERR_FAIL_V(Color());
}
return Color(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
}
bool Color::html_is_valid(const String &p_color) {
String color = p_color;
if (color.length() == 0) {
if (color.length() == 0)
return false;
}
if (color[0] == '#') {
if (color[0] == '#')
color = color.substr(1, color.length() - 1);
}
bool alpha = false;
@@ -366,8 +388,9 @@ bool Color::html_is_valid(const String &p_color) {
return false;
}
int a = 255;
if (alpha) {
int a = _parse_col(color, 0);
a = _parse_col(color, 0);
if (a < 0) {
return false;
}
@@ -392,9 +415,7 @@ bool Color::html_is_valid(const String &p_color) {
}
Color Color::named(const String &p_name) {
if (_named_colors.empty()) {
_populate_named_colors(); // from color_names.inc
}
if (_named_colors.empty()) _populate_named_colors(); // from color_names.inc
String name = p_name;
// Normalize name
name = name.replace(" ", "");
@@ -405,23 +426,28 @@ Color Color::named(const String &p_name) {
name = name.to_lower();
const Map<String, Color>::Element *color = _named_colors.find(name);
ERR_FAIL_NULL_V_MSG(color, Color(), "Invalid color name: " + p_name + ".");
return color->value();
if (color) {
return color->value();
} else {
ERR_EXPLAIN("Invalid Color Name: " + p_name);
ERR_FAIL_V(Color());
}
}
String _to_hex(float p_val) {
int v = Math::round(p_val * 255);
v = CLAMP(v, 0, 255);
String ret;
for (int i = 0; i < 2; i++) {
CharType c[2] = { 0, 0 };
int lv = v & 0xF;
if (lv < 10) {
if (lv < 10)
c[0] = '0' + lv;
} else {
else
c[0] = 'a' + lv - 10;
}
v >>= 4;
String cs = (const CharType *)c;
@@ -432,33 +458,84 @@ String _to_hex(float p_val) {
}
String Color::to_html(bool p_alpha) const {
String txt;
txt += _to_hex(r);
txt += _to_hex(g);
txt += _to_hex(b);
if (p_alpha) {
if (p_alpha)
txt = _to_hex(a) + txt;
}
return txt;
}
Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const {
Color c;
c.set_hsv(p_h, p_s, p_v, p_a);
return c;
p_h = Math::fmod(p_h * 360.0f, 360.0f);
if (p_h < 0.0)
p_h += 360.0f;
const float h_ = p_h / 60.0f;
const float c = p_v * p_s;
const float x = c * (1.0f - Math::abs(Math::fmod(h_, 2.0f) - 1.0f));
float r, g, b;
switch ((int)h_) {
case 0: {
r = c;
g = x;
b = 0;
} break;
case 1: {
r = x;
g = c;
b = 0;
} break;
case 2: {
r = 0;
g = c;
b = x;
} break;
case 3: {
r = 0;
g = x;
b = c;
} break;
case 4: {
r = x;
g = 0;
b = c;
} break;
case 5: {
r = c;
g = 0;
b = x;
} break;
default: {
r = 0;
g = 0;
b = 0;
} break;
}
const float m = p_v - c;
return Color(m + r, m + g, m + b, p_a);
}
// FIXME: Remove once Godot 3.1 has been released
float Color::gray() const {
WARN_DEPRECATED_MSG("'Color.gray()' is deprecated and will be removed in a future version. Use 'Color.v' for a better grayscale approximation.");
ERR_EXPLAIN("Color.gray() is deprecated and will be removed in a future version. Use Color.get_v() for a better grayscale approximation.");
WARN_DEPRECATED
return (r + g + b) / 3.0;
}
Color::operator String() const {
return rtos(r) + ", " + rtos(g) + ", " + rtos(b) + ", " + rtos(a);
}
Color Color::operator+(const Color &p_color) const {
return Color(
r + p_color.r,
g + p_color.g,
@@ -467,6 +544,7 @@ Color Color::operator+(const Color &p_color) const {
}
void Color::operator+=(const Color &p_color) {
r = r + p_color.r;
g = g + p_color.g;
b = b + p_color.b;
@@ -474,6 +552,7 @@ void Color::operator+=(const Color &p_color) {
}
Color Color::operator-(const Color &p_color) const {
return Color(
r - p_color.r,
g - p_color.g,
@@ -482,6 +561,7 @@ Color Color::operator-(const Color &p_color) const {
}
void Color::operator-=(const Color &p_color) {
r = r - p_color.r;
g = g - p_color.g;
b = b - p_color.b;
@@ -489,6 +569,7 @@ void Color::operator-=(const Color &p_color) {
}
Color Color::operator*(const Color &p_color) const {
return Color(
r * p_color.r,
g * p_color.g,
@@ -497,6 +578,7 @@ Color Color::operator*(const Color &p_color) const {
}
Color Color::operator*(const real_t &rvalue) const {
return Color(
r * rvalue,
g * rvalue,
@@ -505,6 +587,7 @@ Color Color::operator*(const real_t &rvalue) const {
}
void Color::operator*=(const Color &p_color) {
r = r * p_color.r;
g = g * p_color.g;
b = b * p_color.b;
@@ -512,6 +595,7 @@ void Color::operator*=(const Color &p_color) {
}
void Color::operator*=(const real_t &rvalue) {
r = r * rvalue;
g = g * rvalue;
b = b * rvalue;
@@ -519,6 +603,7 @@ void Color::operator*=(const real_t &rvalue) {
}
Color Color::operator/(const Color &p_color) const {
return Color(
r / p_color.r,
g / p_color.g,
@@ -527,6 +612,7 @@ Color Color::operator/(const Color &p_color) const {
}
Color Color::operator/(const real_t &rvalue) const {
return Color(
r / rvalue,
g / rvalue,
@@ -535,6 +621,7 @@ Color Color::operator/(const real_t &rvalue) const {
}
void Color::operator/=(const Color &p_color) {
r = r / p_color.r;
g = g / p_color.g;
b = b / p_color.b;
@@ -542,6 +629,7 @@ void Color::operator/=(const Color &p_color) {
}
void Color::operator/=(const real_t &rvalue) {
if (rvalue == 0) {
r = 1.0;
g = 1.0;
@@ -556,6 +644,7 @@ void Color::operator/=(const real_t &rvalue) {
};
Color Color::operator-() const {
return Color(
1.0 - r,
1.0 - g,

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,9 +33,13 @@
#include "core/math/math_funcs.h"
#include "core/ustring.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
struct Color {
union {
struct {
float r;
float g;
@@ -84,25 +88,25 @@ struct Color {
void operator/=(const Color &p_color);
void operator/=(const real_t &rvalue);
bool is_equal_approx(const Color &p_color) const;
void invert();
void contrast();
Color inverted() const;
Color contrasted() const;
_FORCE_INLINE_ Color linear_interpolate(const Color &p_to, float p_weight) const {
_FORCE_INLINE_ Color linear_interpolate(const Color &p_b, float p_t) const {
Color res = *this;
res.r += (p_weight * (p_to.r - r));
res.g += (p_weight * (p_to.g - g));
res.b += (p_weight * (p_to.b - b));
res.a += (p_weight * (p_to.a - a));
res.r += (p_t * (p_b.r - r));
res.g += (p_t * (p_b.g - g));
res.b += (p_t * (p_b.b - b));
res.a += (p_t * (p_b.a - a));
return res;
}
_FORCE_INLINE_ Color darkened(float p_amount) const {
Color res = *this;
res.r = res.r * (1.0f - p_amount);
res.g = res.g * (1.0f - p_amount);
@@ -111,6 +115,7 @@ struct Color {
}
_FORCE_INLINE_ Color lightened(float p_amount) const {
Color res = *this;
res.r = res.r + (1.0f - res.r) * p_amount;
res.g = res.g + (1.0f - res.g) * p_amount;
@@ -119,6 +124,7 @@ struct Color {
}
_FORCE_INLINE_ uint32_t to_rgbe9995() const {
const float pow2to9 = 512.0f;
const float B = 15.0f;
//const float Emax = 31.0f;
@@ -152,6 +158,7 @@ struct Color {
}
_FORCE_INLINE_ Color blend(const Color &p_over) const {
Color res;
float sa = 1.0 - p_over.a;
res.a = a * sa + p_over.a;
@@ -166,6 +173,7 @@ struct Color {
}
_FORCE_INLINE_ Color to_linear() const {
return Color(
r < 0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4),
g < 0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4),
@@ -173,6 +181,7 @@ struct Color {
a);
}
_FORCE_INLINE_ Color to_srgb() const {
return Color(
r < 0.0031308 ? 12.92 * r : (1.0 + 0.055) * Math::pow(r, 1.0f / 2.4f) - 0.055,
g < 0.0031308 ? 12.92 * g : (1.0 + 0.055) * Math::pow(g, 1.0f / 2.4f) - 0.055,
@@ -186,7 +195,7 @@ struct Color {
static Color named(const String &p_name);
String to_html(bool p_alpha = true) const;
Color from_hsv(float p_h, float p_s, float p_v, float p_a) const;
static Color from_rgbe9995(uint32_t p_rgbe);
static Color from_rgbe9995(uint32_t p_color);
_FORCE_INLINE_ bool operator<(const Color &p_color) const; //used in set keys
operator String() const;
@@ -213,19 +222,17 @@ struct Color {
};
bool Color::operator<(const Color &p_color) const {
if (r == p_color.r) {
if (g == p_color.g) {
if (b == p_color.b) {
return (a < p_color.a);
} else {
} else
return (b < p_color.b);
}
} else {
} else
return g < p_color.g;
}
} else {
} else
return r < p_color.r;
}
}
#endif

View File

@@ -1,11 +1,9 @@
// Names from https://en.wikipedia.org/wiki/X11_color_names
// Names from https://en.wikipedia.org/wiki/List_of_colors (through https://raw.githubusercontent.com/SuperUserNameMan/color_to_name/616a7cddafefda91478b7bc26167de97fb5badb1/godot_version.gd), slightly edited and normalized
#include "core/map.h"
static Map<String, Color> _named_colors;
static void _populate_named_colors() {
if (!_named_colors.empty()) {
return;
}
if (!_named_colors.empty()) return;
_named_colors.insert("aliceblue", Color(0.94, 0.97, 1.00));
_named_colors.insert("antiquewhite", Color(0.98, 0.92, 0.84));
_named_colors.insert("aqua", Color(0.00, 1.00, 1.00));
@@ -145,7 +143,6 @@ static void _populate_named_colors() {
_named_colors.insert("thistle", Color(0.85, 0.75, 0.85));
_named_colors.insert("tomato", Color(1.00, 0.39, 0.28));
_named_colors.insert("turquoise", Color(0.25, 0.88, 0.82));
_named_colors.insert("transparent", Color(1.00, 1.00, 1.00, 0.00));
_named_colors.insert("violet", Color(0.93, 0.51, 0.93));
_named_colors.insert("wheat", Color(0.96, 0.87, 0.70));
_named_colors.insert("white", Color(1.00, 1.00, 1.00));

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,27 +31,34 @@
#include "command_queue_mt.h"
#include "core/os/os.h"
#include "core/project_settings.h"
void CommandQueueMT::lock() {
mutex.lock();
if (mutex)
mutex->lock();
}
void CommandQueueMT::unlock() {
mutex.unlock();
if (mutex)
mutex->unlock();
}
void CommandQueueMT::wait_for_flush() {
// wait one millisecond for a flush to happen
OS::get_singleton()->delay_usec(1000);
}
CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() {
int idx = -1;
while (true) {
lock();
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
if (!sync_sems[i].in_use) {
sync_sems[i].in_use = true;
idx = i;
@@ -72,7 +79,7 @@ CommandQueueMT::SyncSemaphore *CommandQueueMT::_alloc_sync_sem() {
bool CommandQueueMT::dealloc_one() {
tryagain:
if (dealloc_ptr == (write_ptr_and_epoch >> 1)) {
if (dealloc_ptr == write_ptr) {
// The queue is empty
return false;
}
@@ -95,28 +102,32 @@ tryagain:
}
CommandQueueMT::CommandQueueMT(bool p_sync) {
read_ptr_and_epoch = 0;
write_ptr_and_epoch = 0;
dealloc_ptr = 0;
command_mem_size = GLOBAL_DEF_RST("memory/limits/command_queue/multithreading_queue_size_kb", DEFAULT_COMMAND_MEM_SIZE_KB);
ProjectSettings::get_singleton()->set_custom_property_info("memory/limits/command_queue/multithreading_queue_size_kb", PropertyInfo(Variant::INT, "memory/limits/command_queue/multithreading_queue_size_kb", PROPERTY_HINT_RANGE, "1,4096,1,or_greater"));
command_mem_size *= 1024;
command_mem = (uint8_t *)memalloc(command_mem_size);
read_ptr = 0;
write_ptr = 0;
dealloc_ptr = 0;
mutex = Mutex::create();
command_mem = (uint8_t *)memalloc(COMMAND_MEM_SIZE);
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
sync_sems[i].sem = Semaphore::create();
sync_sems[i].in_use = false;
}
if (p_sync) {
sync = memnew(Semaphore);
} else {
sync = nullptr;
}
if (p_sync)
sync = Semaphore::create();
else
sync = NULL;
}
CommandQueueMT::~CommandQueueMT() {
if (sync) {
if (sync)
memdelete(sync);
memdelete(mutex);
for (int i = 0; i < SYNC_SEMAPHORES; i++) {
memdelete(sync_sems[i].sem);
}
memfree(command_mem);
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,6 +37,10 @@
#include "core/simple_type.h"
#include "core/typedefs.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
#define COMMA(N) _COMMA_##N
#define _COMMA_0
#define _COMMA_1 ,
@@ -233,8 +237,7 @@
cmd->method = p_method; \
SEMIC_SEP_LIST(CMD_ASSIGN_PARAM, N); \
unlock(); \
if (sync) \
sync->post(); \
if (sync) sync->post(); \
}
#define CMD_RET_TYPE(N) CommandRet##N<T, M, COMMA_SEP_LIST(TYPE_ARG, N) COMMA(N) R>
@@ -250,9 +253,8 @@
cmd->ret = r_ret; \
cmd->sync_sem = ss; \
unlock(); \
if (sync) \
sync->post(); \
ss->sem.wait(); \
if (sync) sync->post(); \
ss->sem->wait(); \
ss->in_use = false; \
}
@@ -268,31 +270,34 @@
SEMIC_SEP_LIST(CMD_ASSIGN_PARAM, N); \
cmd->sync_sem = ss; \
unlock(); \
if (sync) \
sync->post(); \
ss->sem.wait(); \
if (sync) sync->post(); \
ss->sem->wait(); \
ss->in_use = false; \
}
#define MAX_CMD_PARAMS 13
class CommandQueueMT {
struct SyncSemaphore {
Semaphore sem;
Semaphore *sem;
bool in_use;
};
struct CommandBase {
virtual void call() = 0;
virtual void post(){};
virtual ~CommandBase(){};
};
struct SyncCommand : public CommandBase {
SyncSemaphore *sync_sem;
virtual void post() {
sync_sem->sem.post();
sync_sem->sem->post();
}
};
@@ -310,43 +315,41 @@ class CommandQueueMT {
/***** BASE *******/
enum {
DEFAULT_COMMAND_MEM_SIZE_KB = 256,
COMMAND_MEM_SIZE_KB = 256,
COMMAND_MEM_SIZE = COMMAND_MEM_SIZE_KB * 1024,
SYNC_SEMAPHORES = 8
};
uint8_t *command_mem;
uint32_t read_ptr_and_epoch;
uint32_t write_ptr_and_epoch;
uint32_t read_ptr;
uint32_t write_ptr;
uint32_t dealloc_ptr;
uint32_t command_mem_size;
SyncSemaphore sync_sems[SYNC_SEMAPHORES];
Mutex mutex;
Mutex *mutex;
Semaphore *sync;
template <class T>
T *allocate() {
// alloc size is size+T+safeguard
uint32_t alloc_size = ((sizeof(T) + 8 - 1) & ~(8 - 1)) + 8;
// Assert that the buffer is big enough to hold at least two messages.
ERR_FAIL_COND_V(alloc_size * 2 + sizeof(uint32_t) > command_mem_size, nullptr);
tryagain:
uint32_t write_ptr = write_ptr_and_epoch >> 1;
if (write_ptr < dealloc_ptr) {
// behind dealloc_ptr, check that there is room
if ((dealloc_ptr - write_ptr) <= alloc_size) {
// There is no more room, try to deallocate something
if (dealloc_one()) {
goto tryagain;
}
return nullptr;
return NULL;
}
} else {
} else if (write_ptr >= dealloc_ptr) {
// ahead of dealloc_ptr, check that there is room
if ((command_mem_size - write_ptr) < alloc_size + sizeof(uint32_t)) {
if ((COMMAND_MEM_SIZE - write_ptr) < alloc_size + sizeof(uint32_t)) {
// no room at the end, wrap down;
if (dealloc_ptr == 0) { // don't want write_ptr to become dealloc_ptr
@@ -355,21 +358,16 @@ class CommandQueueMT {
if (dealloc_one()) {
goto tryagain;
}
return nullptr;
return NULL;
}
// if this happens, it's a bug
ERR_FAIL_COND_V((command_mem_size - write_ptr) < 8, nullptr);
ERR_FAIL_COND_V((COMMAND_MEM_SIZE - write_ptr) < 8, NULL);
// zero means, wrap to beginning
uint32_t *p = (uint32_t *)&command_mem[write_ptr];
*p = 1;
write_ptr_and_epoch = 0 | (1 & ~write_ptr_and_epoch); // Invert epoch.
// See if we can get the thread to run and clear up some more space while we wait.
// This is required if alloc_size * 2 + 4 > COMMAND_MEM_SIZE
if (sync) {
sync->post();
}
*p = 0;
write_ptr = 0;
goto tryagain;
}
}
@@ -383,16 +381,17 @@ class CommandQueueMT {
// allocate the command
T *cmd = memnew_placement(&command_mem[write_ptr], T);
write_ptr += size;
write_ptr_and_epoch = (write_ptr << 1) | (write_ptr_and_epoch & 1);
return cmd;
}
template <class T>
T *allocate_and_lock() {
lock();
T *ret;
while ((ret = allocate<T>()) == nullptr) {
while ((ret = allocate<T>()) == NULL) {
unlock();
// sleep a little until fetch happened and some room is made
wait_for_flush();
@@ -403,27 +402,19 @@ class CommandQueueMT {
}
bool flush_one(bool p_lock = true) {
if (p_lock) {
lock();
}
if (p_lock) lock();
tryagain:
// tried to read an empty queue
if (read_ptr_and_epoch == write_ptr_and_epoch) {
if (p_lock) {
unlock();
}
if (read_ptr == write_ptr)
return false;
}
uint32_t read_ptr = read_ptr_and_epoch >> 1;
uint32_t size_ptr = read_ptr;
uint32_t size = *(uint32_t *)&command_mem[read_ptr] >> 1;
if (size == 0) {
*(uint32_t *)&command_mem[read_ptr] = 0; // clear in-use bit.
//end of ringbuffer, wrap
read_ptr_and_epoch = 0 | (1 & ~read_ptr_and_epoch); // Invert epoch.
read_ptr = 0;
goto tryagain;
}
@@ -433,23 +424,15 @@ class CommandQueueMT {
read_ptr += size;
read_ptr_and_epoch = (read_ptr << 1) | (read_ptr_and_epoch & 1);
if (p_lock) {
unlock();
}
if (p_lock) unlock();
cmd->call();
if (p_lock) {
lock();
}
if (p_lock) lock();
cmd->post();
cmd->~CommandBase();
*(uint32_t *)&command_mem[size_ptr] &= ~1;
if (p_lock) {
unlock();
}
if (p_lock) unlock();
return true;
}
@@ -479,11 +462,11 @@ public:
}
void flush_all() {
//ERR_FAIL_COND(sync);
lock();
while (flush_one(false)) {
while (flush_one(false))
;
}
unlock();
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,6 +37,7 @@ extern "C" {
}
struct _PHashTranslationCmp {
int orig_len;
CharString compressed;
int offset;
@@ -44,14 +45,13 @@ struct _PHashTranslationCmp {
void PHashTranslation::generate(const Ref<Translation> &p_from) {
#ifdef TOOLS_ENABLED
ERR_FAIL_COND(p_from.is_null());
List<StringName> keys;
p_from->get_message_list(&keys);
int size = Math::larger_prime(keys.size());
Vector<Vector<Pair<int, CharString>>> buckets;
Vector<Map<uint32_t, int>> table;
Vector<Vector<Pair<int, CharString> > > buckets;
Vector<Map<uint32_t, int> > table;
Vector<uint32_t> hfunc_table;
Vector<_PHashTranslationCmp> compressed;
@@ -62,8 +62,10 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
int idx = 0;
int total_compression_size = 0;
int total_string_size = 0;
for (List<StringName>::Element *E = keys.front(); E; E = E->next()) {
//hash string
CharString cs = E->get().operator String().utf8();
uint32_t h = hash(0, cs.get_data());
@@ -99,25 +101,28 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
compressed.write[idx] = ps;
total_compression_size += ps.compressed.size();
total_string_size += src_s.size();
idx++;
}
int bucket_table_size = 0;
for (int i = 0; i < size; i++) {
const Vector<Pair<int, CharString>> &b = buckets[i];
const Vector<Pair<int, CharString> > &b = buckets[i];
Map<uint32_t, int> &t = table.write[i];
if (b.size() == 0) {
if (b.size() == 0)
continue;
}
int d = 1;
int item = 0;
while (item < b.size()) {
uint32_t slot = hash(d, b[item].second.get_data());
if (t.has(slot)) {
item = 0;
d++;
t.clear();
@@ -131,8 +136,6 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
bucket_table_size += 2 + b.size() * 4;
}
ERR_FAIL_COND(bucket_table_size == 0);
hash_table.resize(size);
bucket_table.resize(bucket_table_size);
@@ -143,12 +146,16 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
uint32_t *btw = (uint32_t *)&btwb[0];
int btindex = 0;
int collisions = 0;
for (int i = 0; i < size; i++) {
const Map<uint32_t, int> &t = table[i];
if (t.size() == 0) {
htw[i] = 0xFFFFFFFF; //nothing
continue;
} else if (t.size() > 1) {
collisions += t.size() - 1;
}
htw[i] = btindex;
@@ -156,6 +163,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
btw[btindex++] = hfunc_table[i];
for (Map<uint32_t, int>::Element *E = t.front(); E; E = E->next()) {
btw[btindex++] = E->key();
btw[btindex++] = compressed[E->get()].offset;
btw[btindex++] = compressed[E->get()].compressed.size();
@@ -177,6 +185,7 @@ void PHashTranslation::generate(const Ref<Translation> &p_from) {
}
bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name.operator String();
if (name == "hash_table") {
hash_table = p_value;
@@ -186,34 +195,33 @@ bool PHashTranslation::_set(const StringName &p_name, const Variant &p_value) {
strings = p_value;
} else if (name == "load_from") {
generate(p_value);
} else {
} else
return false;
}
return true;
}
bool PHashTranslation::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name.operator String();
if (name == "hash_table") {
if (name == "hash_table")
r_ret = hash_table;
} else if (name == "bucket_table") {
else if (name == "bucket_table")
r_ret = bucket_table;
} else if (name == "strings") {
else if (name == "strings")
r_ret = strings;
} else {
else
return false;
}
return true;
}
StringName PHashTranslation::get_message(const StringName &p_src_text) const {
int htsize = hash_table.size();
if (htsize == 0) {
if (htsize == 0)
return StringName();
}
CharString str = p_src_text.operator String().utf8();
uint32_t h = hash(0, str.get_data());
@@ -238,7 +246,9 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const {
int idx = -1;
for (int i = 0; i < bucket.size; i++) {
if (bucket.elem[i].key == h) {
idx = i;
break;
}
@@ -249,11 +259,13 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const {
}
if (bucket.elem[idx].comp_size == bucket.elem[idx].uncomp_size) {
String rstr;
rstr.parse_utf8(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].uncomp_size);
return rstr;
} else {
CharString uncomp;
uncomp.resize(bucket.elem[idx].uncomp_size + 1);
smaz_decompress(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].comp_size, uncomp.ptrw(), bucket.elem[idx].uncomp_size);
@@ -264,12 +276,14 @@ StringName PHashTranslation::get_message(const StringName &p_src_text) const {
}
void PHashTranslation::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::POOL_INT_ARRAY, "hash_table"));
p_list->push_back(PropertyInfo(Variant::POOL_INT_ARRAY, "bucket_table"));
p_list->push_back(PropertyInfo(Variant::POOL_BYTE_ARRAY, "strings"));
p_list->push_back(PropertyInfo(Variant::OBJECT, "load_from", PROPERTY_HINT_RESOURCE_TYPE, "Translation", PROPERTY_USAGE_EDITOR));
}
void PHashTranslation::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate", "from"), &PHashTranslation::generate);
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,6 +34,7 @@
#include "core/translation.h"
class PHashTranslation : public Translation {
GDCLASS(PHashTranslation, Translation);
//this translation uses a sort of modified perfect hash algorithm
@@ -47,10 +48,12 @@ class PHashTranslation : public Translation {
PoolVector<uint8_t> strings;
struct Bucket {
int size;
uint32_t func;
struct Elem {
uint32_t key;
uint32_t str_offset;
uint32_t comp_size;
@@ -61,10 +64,11 @@ class PHashTranslation : public Translation {
};
_FORCE_INLINE_ uint32_t hash(uint32_t d, const char *p_str) const {
if (d == 0) {
if (d == 0)
d = 0x1000193;
}
while (*p_str) {
d = (d * 0x1000193) ^ uint32_t(*p_str);
p_str++;
}

View File

@@ -1,8 +1,8 @@
"""Functions used to generate source files during build time
All such functions are invoked in a subprocess on Windows to prevent build flakiness.
"""
"""
from platform_methods import subprocess_main
from compat import iteritems, itervalues, open_utf8, escape_string, byte_to_str
@@ -16,7 +16,6 @@ def make_certs_header(target, source, env):
buf = f.read()
decomp_size = len(buf)
import zlib
buf = zlib.compress(buf)
g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
@@ -24,9 +23,9 @@ def make_certs_header(target, source, env):
g.write("#define _CERTS_RAW_H\n")
# System certs path. Editor will use them if defined. (for package maintainers)
path = env["system_certs_path"]
g.write('#define _SYSTEM_CERTS_PATH "%s"\n' % str(path))
if env["builtin_certs"]:
path = env['system_certs_path']
g.write("#define _SYSTEM_CERTS_PATH \"%s\"\n" % str(path))
if env['builtin_certs']:
# Defined here and not in env so changing it does not trigger a full rebuild.
g.write("#define BUILTIN_CERTS_ENABLED\n")
g.write("static const int _certs_compressed_size = " + str(len(buf)) + ";\n")
@@ -63,7 +62,7 @@ def make_authors_header(target, source, env):
for line in f:
if reading:
if line.startswith(" "):
g.write('\t"' + escape_string(line.strip()) + '",\n')
g.write("\t\"" + escape_string(line.strip()) + "\",\n")
continue
if line.startswith("## "):
if reading:
@@ -86,26 +85,10 @@ def make_authors_header(target, source, env):
def make_donors_header(target, source, env):
sections = [
"Platinum sponsors",
"Gold sponsors",
"Silver sponsors",
"Bronze sponsors",
"Mini sponsors",
"Gold donors",
"Silver donors",
"Bronze donors",
]
sections_id = [
"DONORS_SPONSOR_PLATINUM",
"DONORS_SPONSOR_GOLD",
"DONORS_SPONSOR_SILVER",
"DONORS_SPONSOR_BRONZE",
"DONORS_SPONSOR_MINI",
"DONORS_GOLD",
"DONORS_SILVER",
"DONORS_BRONZE",
]
sections = ["Platinum sponsors", "Gold sponsors", "Mini sponsors",
"Gold donors", "Silver donors", "Bronze donors"]
sections_id = ["DONORS_SPONSOR_PLAT", "DONORS_SPONSOR_GOLD", "DONORS_SPONSOR_MINI",
"DONORS_GOLD", "DONORS_SILVER", "DONORS_BRONZE"]
src = source[0]
dst = target[0]
@@ -125,7 +108,7 @@ def make_donors_header(target, source, env):
for line in f:
if reading >= 0:
if line.startswith(" "):
g.write('\t"' + escape_string(line.strip()) + '",\n')
g.write("\t\"" + escape_string(line.strip()) + "\",\n")
continue
if line.startswith("## "):
if reading:
@@ -168,8 +151,8 @@ def make_license_header(target, source, env):
return line
def next_tag(self):
if not ":" in self.current:
return ("", [])
if not ':' in self.current:
return ('', [])
tag, line = self.current.split(":", 1)
lines = [line.strip()]
while self.next_line() and self.current.startswith(" "):
@@ -177,7 +160,6 @@ def make_license_header(target, source, env):
return (tag, lines)
from collections import OrderedDict
projects = OrderedDict()
license_list = []
@@ -218,30 +200,26 @@ def make_license_header(target, source, env):
with open_utf8(src_license, "r") as license_file:
for line in license_file:
escaped_string = escape_string(line.strip())
f.write('\n\t\t"' + escaped_string + '\\n"')
f.write("\n\t\t\"" + escaped_string + "\\n\"")
f.write(";\n\n")
f.write(
"struct ComponentCopyrightPart {\n"
"\tconst char *license;\n"
"\tconst char *const *files;\n"
"\tconst char *const *copyright_statements;\n"
"\tint file_count;\n"
"\tint copyright_count;\n"
"};\n\n"
)
f.write("struct ComponentCopyrightPart {\n"
"\tconst char *license;\n"
"\tconst char *const *files;\n"
"\tconst char *const *copyright_statements;\n"
"\tint file_count;\n"
"\tint copyright_count;\n"
"};\n\n")
f.write(
"struct ComponentCopyright {\n"
"\tconst char *name;\n"
"\tconst ComponentCopyrightPart *parts;\n"
"\tint part_count;\n"
"};\n\n"
)
f.write("struct ComponentCopyright {\n"
"\tconst char *name;\n"
"\tconst ComponentCopyrightPart *parts;\n"
"\tint part_count;\n"
"};\n\n")
f.write("const char *const COPYRIGHT_INFO_DATA[] = {\n")
for line in data_list:
f.write('\t"' + escape_string(line) + '",\n')
f.write("\t\"" + escape_string(line) + "\",\n")
f.write("};\n\n")
f.write("const ComponentCopyrightPart COPYRIGHT_PROJECT_PARTS[] = {\n")
@@ -250,21 +228,11 @@ def make_license_header(target, source, env):
for project_name, project in iteritems(projects):
part_indexes[project_name] = part_index
for part in project:
f.write(
'\t{ "'
+ escape_string(part["License"][0])
+ '", '
+ "&COPYRIGHT_INFO_DATA["
+ str(part["file_index"])
+ "], "
+ "&COPYRIGHT_INFO_DATA["
+ str(part["copyright_index"])
+ "], "
+ str(len(part["Files"]))
+ ", "
+ str(len(part["Copyright"]))
+ " },\n"
)
f.write("\t{ \"" + escape_string(part["License"][0]) + "\", "
+ "&COPYRIGHT_INFO_DATA[" + str(part["file_index"]) + "], "
+ "&COPYRIGHT_INFO_DATA[" + str(part["copyright_index"]) + "], "
+ str(len(part["Files"])) + ", "
+ str(len(part["Copyright"])) + " },\n")
part_index += 1
f.write("};\n\n")
@@ -272,37 +240,30 @@ def make_license_header(target, source, env):
f.write("const ComponentCopyright COPYRIGHT_INFO[] = {\n")
for project_name, project in iteritems(projects):
f.write(
'\t{ "'
+ escape_string(project_name)
+ '", '
+ "&COPYRIGHT_PROJECT_PARTS["
+ str(part_indexes[project_name])
+ "], "
+ str(len(project))
+ " },\n"
)
f.write("\t{ \"" + escape_string(project_name) + "\", "
+ "&COPYRIGHT_PROJECT_PARTS[" + str(part_indexes[project_name]) + "], "
+ str(len(project)) + " },\n")
f.write("};\n\n")
f.write("const int LICENSE_COUNT = " + str(len(license_list)) + ";\n")
f.write("const char *const LICENSE_NAMES[] = {\n")
for l in license_list:
f.write('\t"' + escape_string(l[0]) + '",\n')
f.write("\t\"" + escape_string(l[0]) + "\",\n")
f.write("};\n\n")
f.write("const char *const LICENSE_BODIES[] = {\n\n")
for l in license_list:
for line in l[1:]:
if line == ".":
f.write('\t"\\n"\n')
f.write("\t\"\\n\"\n")
else:
f.write('\t"' + escape_string(line) + '\\n"\n')
f.write('\t"",\n\n')
f.write("\t\"" + escape_string(line) + "\\n\"\n")
f.write("\t\"\",\n\n")
f.write("};\n\n")
f.write("#endif\n")
if __name__ == "__main__":
if __name__ == '__main__':
subprocess_main(globals())

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,7 +30,7 @@
#include "core_string_names.h"
CoreStringNames *CoreStringNames::singleton = nullptr;
CoreStringNames *CoreStringNames::singleton = NULL;
CoreStringNames::CoreStringNames() :
_free(StaticCString::create("free")),
@@ -44,7 +44,6 @@ CoreStringNames::CoreStringNames() :
_iter_next(StaticCString::create("_iter_next")),
_iter_get(StaticCString::create("_iter_get")),
get_rid(StaticCString::create("get_rid")),
_to_string(StaticCString::create("_to_string")),
#ifdef TOOLS_ENABLED
_sections_unfolded(StaticCString::create("_sections_unfolded")),
#endif

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,13 +34,14 @@
#include "core/string_name.h"
class CoreStringNames {
friend void register_core_types();
friend void unregister_core_types();
static void create() { singleton = memnew(CoreStringNames); }
static void free() {
memdelete(singleton);
singleton = nullptr;
singleton = NULL;
}
CoreStringNames();
@@ -61,7 +62,6 @@ public:
StringName _iter_next;
StringName _iter_get;
StringName get_rid;
StringName _to_string;
#ifdef TOOLS_ENABLED
StringName _sections_unfolded;
#endif

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,7 +33,6 @@
#include <string.h>
#include "core/error_macros.h"
#include "core/os/memory.h"
#include "core/safe_refcount.h"
@@ -44,10 +43,6 @@ class CharString;
template <class T, class V>
class VMap;
#if !defined(NO_THREADS)
SAFE_NUMERIC_TYPE_PUN_GUARANTEES(uint32_t)
#endif
template <class T>
class CowData {
template <class TV>
@@ -62,26 +57,26 @@ private:
// internal helpers
_FORCE_INLINE_ SafeNumeric<uint32_t> *_get_refcount() const {
if (!_ptr) {
return nullptr;
}
_FORCE_INLINE_ uint32_t *_get_refcount() const {
return reinterpret_cast<SafeNumeric<uint32_t> *>(_ptr) - 2;
if (!_ptr)
return NULL;
return reinterpret_cast<uint32_t *>(_ptr) - 2;
}
_FORCE_INLINE_ uint32_t *_get_size() const {
if (!_ptr) {
return nullptr;
}
if (!_ptr)
return NULL;
return reinterpret_cast<uint32_t *>(_ptr) - 1;
}
_FORCE_INLINE_ T *_get_data() const {
if (!_ptr) {
return nullptr;
}
if (!_ptr)
return NULL;
return reinterpret_cast<T *>(_ptr);
}
@@ -99,9 +94,7 @@ private:
return false;
}
*out = next_power_of_2(o);
if (_add_overflow(o, static_cast<size_t>(32), &p)) {
return false; //no longer allocated here
}
if (_add_overflow(o, static_cast<size_t>(32), &p)) return false; //no longer allocated here
return true;
#else
// Speed is more important than correctness here, do the operations unchecked
@@ -114,7 +107,7 @@ private:
void _unref(void *p_data);
void _ref(const CowData *p_from);
void _ref(const CowData &p_from);
uint32_t _copy_on_write();
void _copy_on_write();
public:
void operator=(const CowData<T> &p_from) { _ref(p_from); }
@@ -130,29 +123,31 @@ public:
_FORCE_INLINE_ int size() const {
uint32_t *size = (uint32_t *)_get_size();
if (size) {
if (size)
return *size;
} else {
else
return 0;
}
}
_FORCE_INLINE_ void clear() { resize(0); }
_FORCE_INLINE_ bool empty() const { return _ptr == nullptr; }
_FORCE_INLINE_ bool empty() const { return _ptr == 0; }
_FORCE_INLINE_ void set(int p_index, const T &p_elem) {
CRASH_BAD_INDEX(p_index, size());
_copy_on_write();
_get_data()[p_index] = p_elem;
}
_FORCE_INLINE_ T &get_m(int p_index) {
CRASH_BAD_INDEX(p_index, size());
_copy_on_write();
return _get_data()[p_index];
}
_FORCE_INLINE_ const T &get(int p_index) const {
CRASH_BAD_INDEX(p_index, size());
return _get_data()[p_index];
@@ -161,10 +156,12 @@ public:
Error resize(int p_size);
_FORCE_INLINE_ void remove(int p_index) {
ERR_FAIL_INDEX(p_index, size());
T *p = ptrw();
int len = size();
for (int i = p_index; i < len - 1; i++) {
p[i] = p[i + 1];
};
@@ -172,11 +169,11 @@ public:
};
Error insert(int p_pos, const T &p_val) {
ERR_FAIL_INDEX_V(p_pos, size() + 1, ERR_INVALID_PARAMETER);
resize(size() + 1);
for (int i = (size() - 1); i > p_pos; i--) {
for (int i = (size() - 1); i > p_pos; i--)
set(i, get(i - 1));
}
set(p_pos, p_val);
return OK;
@@ -191,15 +188,14 @@ public:
template <class T>
void CowData<T>::_unref(void *p_data) {
if (!p_data) {
if (!p_data)
return;
}
SafeNumeric<uint32_t> *refc = _get_refcount();
uint32_t *refc = _get_refcount();
if (refc->decrement() > 0) {
if (atomic_decrement(refc) > 0)
return; // still in use
}
// clean up
if (!__has_trivial_destructor(T)) {
@@ -217,21 +213,20 @@ void CowData<T>::_unref(void *p_data) {
}
template <class T>
uint32_t CowData<T>::_copy_on_write() {
if (!_ptr) {
return 0;
}
void CowData<T>::_copy_on_write() {
SafeNumeric<uint32_t> *refc = _get_refcount();
if (!_ptr)
return;
uint32_t rc = refc->get();
if (likely(rc > 1)) {
uint32_t *refc = _get_refcount();
if (unlikely(*refc > 1)) {
/* in use by more than me */
uint32_t current_size = *_get_size();
uint32_t *mem_new = (uint32_t *)Memory::alloc_static(_get_alloc_size(current_size), true);
new (mem_new - 2, sizeof(uint32_t), "") SafeNumeric<uint32_t>(1); //refcount
*(mem_new - 2) = 1; //refcount
*(mem_new - 1) = current_size; //size
T *_data = (T *)(mem_new);
@@ -248,54 +243,45 @@ uint32_t CowData<T>::_copy_on_write() {
_unref(_ptr);
_ptr = _data;
rc = 1;
}
return rc;
}
template <class T>
Error CowData<T>::resize(int p_size) {
ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER);
int current_size = size();
if (p_size == current_size) {
if (p_size == size())
return OK;
}
if (p_size == 0) {
// wants to clean up
_unref(_ptr);
_ptr = nullptr;
_ptr = NULL;
return OK;
}
// possibly changing size, copy on write
uint32_t rc = _copy_on_write();
_copy_on_write();
size_t current_alloc_size = _get_alloc_size(current_size);
size_t alloc_size;
ERR_FAIL_COND_V(!_get_alloc_size_checked(p_size, &alloc_size), ERR_OUT_OF_MEMORY);
if (p_size > current_size) {
if (alloc_size != current_alloc_size) {
if (current_size == 0) {
// alloc from scratch
uint32_t *ptr = (uint32_t *)Memory::alloc_static(alloc_size, true);
ERR_FAIL_COND_V(!ptr, ERR_OUT_OF_MEMORY);
*(ptr - 1) = 0; //size, currently none
new (ptr - 2, sizeof(uint32_t), "") SafeNumeric<uint32_t>(1); //refcount
if (p_size > size()) {
_ptr = (T *)ptr;
if (size() == 0) {
// alloc from scratch
uint32_t *ptr = (uint32_t *)Memory::alloc_static(alloc_size, true);
ERR_FAIL_COND_V(!ptr, ERR_OUT_OF_MEMORY);
*(ptr - 1) = 0; //size, currently none
*(ptr - 2) = 1; //refcount
} else {
uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true);
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
new (_ptrnew - 2, sizeof(uint32_t), "") SafeNumeric<uint32_t>(rc); //refcount
_ptr = (T *)ptr;
_ptr = (T *)(_ptrnew);
}
} else {
void *_ptrnew = (T *)Memory::realloc_static(_ptr, alloc_size, true);
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
_ptr = (T *)(_ptrnew);
}
// construct the newly created elements
@@ -310,7 +296,8 @@ Error CowData<T>::resize(int p_size) {
*_get_size() = p_size;
} else if (p_size < current_size) {
} else if (p_size < size()) {
if (!__has_trivial_destructor(T)) {
// deinitialize no longer needed elements
for (uint32_t i = p_size; i < *_get_size(); i++) {
@@ -319,13 +306,10 @@ Error CowData<T>::resize(int p_size) {
}
}
if (alloc_size != current_alloc_size) {
uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true);
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
new (_ptrnew - 2, sizeof(uint32_t), "") SafeNumeric<uint32_t>(rc); //refcount
void *_ptrnew = (T *)Memory::realloc_static(_ptr, alloc_size, true);
ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY);
_ptr = (T *)(_ptrnew);
}
_ptr = (T *)(_ptrnew);
*_get_size() = p_size;
}
@@ -358,29 +342,30 @@ void CowData<T>::_ref(const CowData *p_from) {
template <class T>
void CowData<T>::_ref(const CowData &p_from) {
if (_ptr == p_from._ptr) {
if (_ptr == p_from._ptr)
return; // self assign, do nothing.
}
_unref(_ptr);
_ptr = nullptr;
_ptr = NULL;
if (!p_from._ptr) {
if (!p_from._ptr)
return; //nothing to do
}
if (p_from._get_refcount()->conditional_increment() > 0) { // could reference
if (atomic_conditional_increment(p_from._get_refcount()) > 0) { // could reference
_ptr = p_from._ptr;
}
}
template <class T>
CowData<T>::CowData() {
_ptr = nullptr;
_ptr = NULL;
}
template <class T>
CowData<T>::~CowData() {
_unref(_ptr);
}

View File

@@ -1,51 +0,0 @@
#!/usr/bin/env python
Import("env")
env_crypto = env.Clone()
is_builtin = env["builtin_mbedtls"]
has_module = env["module_mbedtls_enabled"]
thirdparty_obj = []
if is_builtin or not has_module:
# Use our headers for builtin or if the module is not going to be compiled.
# We decided not to depend on system mbedtls just for these few files that can
# be easily extracted.
env_crypto.Prepend(CPPPATH=["#thirdparty/mbedtls/include"])
# MbedTLS core functions (for CryptoCore).
# If the mbedtls module is compiled we don't need to add the .c files with our
# custom config since they will be built by the module itself.
# Only if the module is not enabled, we must compile here the required sources
# to make a "light" build with only the necessary mbedtls files.
if not has_module:
env_thirdparty = env_crypto.Clone()
env_thirdparty.disable_warnings()
# Custom config file
env_thirdparty.Append(
CPPDEFINES=[("MBEDTLS_CONFIG_FILE", '\\"thirdparty/mbedtls/include/godot_core_mbedtls_config.h\\"')]
)
thirdparty_mbedtls_dir = "#thirdparty/mbedtls/library/"
thirdparty_mbedtls_sources = [
"aes.c",
"base64.c",
"md5.c",
"sha1.c",
"sha256.c",
"godot_core_mbedtls_platform.c",
]
thirdparty_mbedtls_sources = [thirdparty_mbedtls_dir + file for file in thirdparty_mbedtls_sources]
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_mbedtls_sources)
env.core_sources += thirdparty_obj
# Godot source files
core_obj = []
env_crypto.add_source_files(core_obj, "*.cpp")
env.core_sources += core_obj
# Needed to force rebuilding the core files when the thirdparty library is updated.
env.Depends(core_obj, thirdparty_obj)

View File

@@ -1,116 +0,0 @@
/*************************************************************************/
/* aes_context.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "core/crypto/aes_context.h"
Error AESContext::start(Mode p_mode, PoolByteArray p_key, PoolByteArray p_iv) {
ERR_FAIL_COND_V_MSG(mode != MODE_MAX, ERR_ALREADY_IN_USE, "AESContext already started. Call 'finish' before starting a new one.");
ERR_FAIL_COND_V_MSG(p_mode < 0 || p_mode >= MODE_MAX, ERR_INVALID_PARAMETER, "Invalid mode requested.");
// Key check.
int key_bits = p_key.size() << 3;
ERR_FAIL_COND_V_MSG(key_bits != 128 && key_bits != 256, ERR_INVALID_PARAMETER, "AES key must be either 16 or 32 bytes");
// Initialization vector.
if (p_mode == MODE_CBC_ENCRYPT || p_mode == MODE_CBC_DECRYPT) {
ERR_FAIL_COND_V_MSG(p_iv.size() != 16, ERR_INVALID_PARAMETER, "The initialization vector (IV) must be exactly 16 bytes.");
iv.resize(0);
iv.append_array(p_iv);
}
// Encryption/decryption key.
if (p_mode == MODE_CBC_ENCRYPT || p_mode == MODE_ECB_ENCRYPT) {
ctx.set_encode_key(p_key.read().ptr(), key_bits);
} else {
ctx.set_decode_key(p_key.read().ptr(), key_bits);
}
mode = p_mode;
return OK;
}
PoolByteArray AESContext::update(PoolByteArray p_src) {
ERR_FAIL_COND_V_MSG(mode < 0 || mode >= MODE_MAX, PoolByteArray(), "AESContext not started. Call 'start' before calling 'update'.");
int len = p_src.size();
ERR_FAIL_COND_V_MSG(len % 16, PoolByteArray(), "The number of bytes to be encrypted must be multiple of 16. Add padding if needed");
PoolByteArray out;
out.resize(len);
const uint8_t *src_ptr = p_src.read().ptr();
uint8_t *out_ptr = out.write().ptr();
switch (mode) {
case MODE_ECB_ENCRYPT: {
for (int i = 0; i < len; i += 16) {
Error err = ctx.encrypt_ecb(src_ptr + i, out_ptr + i);
ERR_FAIL_COND_V(err != OK, PoolByteArray());
}
} break;
case MODE_ECB_DECRYPT: {
for (int i = 0; i < len; i += 16) {
Error err = ctx.decrypt_ecb(src_ptr + i, out_ptr + i);
ERR_FAIL_COND_V(err != OK, PoolByteArray());
}
} break;
case MODE_CBC_ENCRYPT: {
Error err = ctx.encrypt_cbc(len, iv.write().ptr(), p_src.read().ptr(), out.write().ptr());
ERR_FAIL_COND_V(err != OK, PoolByteArray());
} break;
case MODE_CBC_DECRYPT: {
Error err = ctx.decrypt_cbc(len, iv.write().ptr(), p_src.read().ptr(), out.write().ptr());
ERR_FAIL_COND_V(err != OK, PoolByteArray());
} break;
default:
ERR_FAIL_V_MSG(PoolByteArray(), "Bug!");
}
return out;
}
PoolByteArray AESContext::get_iv_state() {
ERR_FAIL_COND_V_MSG(mode != MODE_CBC_ENCRYPT && mode != MODE_CBC_DECRYPT, PoolByteArray(), "Calling 'get_iv_state' only makes sense when the context is started in CBC mode.");
PoolByteArray out;
out.append_array(iv);
return out;
}
void AESContext::finish() {
mode = MODE_MAX;
iv.resize(0);
}
void AESContext::_bind_methods() {
ClassDB::bind_method(D_METHOD("start", "mode", "key", "iv"), &AESContext::start, DEFVAL(PoolByteArray()));
ClassDB::bind_method(D_METHOD("update", "src"), &AESContext::update);
ClassDB::bind_method(D_METHOD("get_iv_state"), &AESContext::get_iv_state);
ClassDB::bind_method(D_METHOD("finish"), &AESContext::finish);
BIND_ENUM_CONSTANT(MODE_ECB_ENCRYPT);
BIND_ENUM_CONSTANT(MODE_ECB_DECRYPT);
BIND_ENUM_CONSTANT(MODE_CBC_ENCRYPT);
BIND_ENUM_CONSTANT(MODE_CBC_DECRYPT);
BIND_ENUM_CONSTANT(MODE_MAX);
}
AESContext::AESContext() {
mode = MODE_MAX;
}

View File

@@ -1,68 +0,0 @@
/*************************************************************************/
/* aes_context.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef AES_CONTEXT_H
#define AES_CONTEXT_H
#include "core/crypto/crypto_core.h"
#include "core/reference.h"
class AESContext : public Reference {
GDCLASS(AESContext, Reference);
public:
enum Mode {
MODE_ECB_ENCRYPT,
MODE_ECB_DECRYPT,
MODE_CBC_ENCRYPT,
MODE_CBC_DECRYPT,
MODE_MAX
};
private:
Mode mode;
CryptoCore::AESContext ctx;
PoolByteArray iv;
protected:
static void _bind_methods();
public:
Error start(Mode p_mode, PoolByteArray p_key, PoolByteArray p_iv = PoolByteArray());
PoolByteArray update(PoolByteArray p_src);
PoolByteArray get_iv_state();
void finish();
AESContext();
};
VARIANT_ENUM_CAST(AESContext::Mode);
#endif // AES_CONTEXT_H

View File

@@ -1,222 +0,0 @@
/*************************************************************************/
/* crypto.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "crypto.h"
#include "core/engine.h"
#include "core/io/certs_compressed.gen.h"
#include "core/io/compression.h"
/// Resources
CryptoKey *(*CryptoKey::_create)() = nullptr;
CryptoKey *CryptoKey::create() {
if (_create) {
return _create();
}
return nullptr;
}
void CryptoKey::_bind_methods() {
ClassDB::bind_method(D_METHOD("save", "path", "public_only"), &CryptoKey::save, DEFVAL(false));
ClassDB::bind_method(D_METHOD("load", "path", "public_only"), &CryptoKey::load, DEFVAL(false));
ClassDB::bind_method(D_METHOD("is_public_only"), &CryptoKey::is_public_only);
ClassDB::bind_method(D_METHOD("save_to_string", "public_only"), &CryptoKey::save_to_string, DEFVAL(false));
ClassDB::bind_method(D_METHOD("load_from_string", "string_key", "public_only"), &CryptoKey::load_from_string, DEFVAL(false));
}
X509Certificate *(*X509Certificate::_create)() = nullptr;
X509Certificate *X509Certificate::create() {
if (_create) {
return _create();
}
return nullptr;
}
void X509Certificate::_bind_methods() {
ClassDB::bind_method(D_METHOD("save", "path"), &X509Certificate::save);
ClassDB::bind_method(D_METHOD("load", "path"), &X509Certificate::load);
}
/// HMACContext
void HMACContext::_bind_methods() {
ClassDB::bind_method(D_METHOD("start", "hash_type", "key"), &HMACContext::start);
ClassDB::bind_method(D_METHOD("update", "data"), &HMACContext::update);
ClassDB::bind_method(D_METHOD("finish"), &HMACContext::finish);
}
HMACContext *(*HMACContext::_create)() = nullptr;
HMACContext *HMACContext::create() {
if (_create) {
return _create();
}
ERR_FAIL_V_MSG(nullptr, "HMACContext is not available when the mbedtls module is disabled.");
}
/// Crypto
void (*Crypto::_load_default_certificates)(String p_path) = nullptr;
Crypto *(*Crypto::_create)() = nullptr;
Crypto *Crypto::create() {
if (_create) {
return _create();
}
ERR_FAIL_V_MSG(nullptr, "Crypto is not available when the mbedtls module is disabled.");
}
void Crypto::load_default_certificates(String p_path) {
if (_load_default_certificates) {
_load_default_certificates(p_path);
}
}
PoolByteArray Crypto::hmac_digest(HashingContext::HashType p_hash_type, PoolByteArray p_key, PoolByteArray p_msg) {
Ref<HMACContext> ctx = Ref<HMACContext>(HMACContext::create());
ERR_FAIL_COND_V_MSG(ctx.is_null(), PoolByteArray(), "HMAC is not available without mbedtls module.");
Error err = ctx->start(p_hash_type, p_key);
ERR_FAIL_COND_V(err != OK, PoolByteArray());
err = ctx->update(p_msg);
ERR_FAIL_COND_V(err != OK, PoolByteArray());
return ctx->finish();
}
// Compares two HMACS for equality without leaking timing information in order to prevent timing attakcs.
// @see: https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy
bool Crypto::constant_time_compare(PoolByteArray p_trusted, PoolByteArray p_received) {
const uint8_t *t = p_trusted.read().ptr();
const uint8_t *r = p_received.read().ptr();
int tlen = p_trusted.size();
int rlen = p_received.size();
// If the lengths are different then nothing else matters.
if (tlen != rlen) {
return false;
}
uint8_t v = 0;
for (int i = 0; i < tlen; i++) {
v |= t[i] ^ r[i];
}
return v == 0;
}
void Crypto::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate_random_bytes", "size"), &Crypto::generate_random_bytes);
ClassDB::bind_method(D_METHOD("generate_rsa", "size"), &Crypto::generate_rsa);
ClassDB::bind_method(D_METHOD("generate_self_signed_certificate", "key", "issuer_name", "not_before", "not_after"), &Crypto::generate_self_signed_certificate, DEFVAL("CN=myserver,O=myorganisation,C=IT"), DEFVAL("20140101000000"), DEFVAL("20340101000000"));
ClassDB::bind_method(D_METHOD("sign", "hash_type", "hash", "key"), &Crypto::sign);
ClassDB::bind_method(D_METHOD("verify", "hash_type", "hash", "signature", "key"), &Crypto::verify);
ClassDB::bind_method(D_METHOD("encrypt", "key", "plaintext"), &Crypto::encrypt);
ClassDB::bind_method(D_METHOD("decrypt", "key", "ciphertext"), &Crypto::decrypt);
ClassDB::bind_method(D_METHOD("hmac_digest", "hash_type", "key", "msg"), &Crypto::hmac_digest);
ClassDB::bind_method(D_METHOD("constant_time_compare", "trusted", "received"), &Crypto::constant_time_compare);
}
Crypto::Crypto() {
}
/// Resource loader/saver
RES ResourceFormatLoaderCrypto::load(const String &p_path, const String &p_original_path, Error *r_error) {
String el = p_path.get_extension().to_lower();
if (el == "crt") {
X509Certificate *cert = X509Certificate::create();
if (cert) {
cert->load(p_path);
}
return cert;
} else if (el == "key") {
CryptoKey *key = CryptoKey::create();
if (key) {
key->load(p_path, false);
}
return key;
} else if (el == "pub") {
CryptoKey *key = CryptoKey::create();
if (key) {
key->load(p_path, true);
}
return key;
}
return nullptr;
}
void ResourceFormatLoaderCrypto::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("crt");
p_extensions->push_back("key");
p_extensions->push_back("pub");
}
bool ResourceFormatLoaderCrypto::handles_type(const String &p_type) const {
return p_type == "X509Certificate" || p_type == "CryptoKey";
}
String ResourceFormatLoaderCrypto::get_resource_type(const String &p_path) const {
String el = p_path.get_extension().to_lower();
if (el == "crt") {
return "X509Certificate";
} else if (el == "key" || el == "pub") {
return "CryptoKey";
}
return "";
}
Error ResourceFormatSaverCrypto::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
Error err;
Ref<X509Certificate> cert = p_resource;
Ref<CryptoKey> key = p_resource;
if (cert.is_valid()) {
err = cert->save(p_path);
} else if (key.is_valid()) {
String el = p_path.get_extension().to_lower();
err = key->save(p_path, el == "pub");
} else {
ERR_FAIL_V(ERR_INVALID_PARAMETER);
}
ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save Crypto resource to file '" + p_path + "'.");
return OK;
}
void ResourceFormatSaverCrypto::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
const X509Certificate *cert = Object::cast_to<X509Certificate>(*p_resource);
const CryptoKey *key = Object::cast_to<CryptoKey>(*p_resource);
if (cert) {
p_extensions->push_back("crt");
}
if (key) {
if (!key->is_public_only()) {
p_extensions->push_back("key");
}
p_extensions->push_back("pub");
}
}
bool ResourceFormatSaverCrypto::recognize(const RES &p_resource) const {
return Object::cast_to<X509Certificate>(*p_resource) || Object::cast_to<CryptoKey>(*p_resource);
}

View File

@@ -1,134 +0,0 @@
/*************************************************************************/
/* crypto.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef CRYPTO_H
#define CRYPTO_H
#include "core/crypto/hashing_context.h"
#include "core/reference.h"
#include "core/resource.h"
#include "core/io/resource_loader.h"
#include "core/io/resource_saver.h"
class CryptoKey : public Resource {
GDCLASS(CryptoKey, Resource);
protected:
static void _bind_methods();
static CryptoKey *(*_create)();
public:
static CryptoKey *create();
virtual Error load(String p_path, bool p_public_only = false) = 0;
virtual Error save(String p_path, bool p_public_only = false) = 0;
virtual String save_to_string(bool p_public_only = false) = 0;
virtual Error load_from_string(String p_string_key, bool p_public_only = false) = 0;
virtual bool is_public_only() const = 0;
};
class X509Certificate : public Resource {
GDCLASS(X509Certificate, Resource);
protected:
static void _bind_methods();
static X509Certificate *(*_create)();
public:
static X509Certificate *create();
virtual Error load(String p_path) = 0;
virtual Error load_from_memory(const uint8_t *p_buffer, int p_len) = 0;
virtual Error save(String p_path) = 0;
};
class HMACContext : public Reference {
GDCLASS(HMACContext, Reference);
protected:
static void _bind_methods();
static HMACContext *(*_create)();
public:
static HMACContext *create();
virtual Error start(HashingContext::HashType p_hash_type, PoolByteArray p_key) = 0;
virtual Error update(PoolByteArray p_data) = 0;
virtual PoolByteArray finish() = 0;
HMACContext() {}
virtual ~HMACContext() {}
};
class Crypto : public Reference {
GDCLASS(Crypto, Reference);
protected:
static void _bind_methods();
static Crypto *(*_create)();
static void (*_load_default_certificates)(String p_path);
public:
static Crypto *create();
static void load_default_certificates(String p_path);
virtual PoolByteArray generate_random_bytes(int p_bytes) = 0;
virtual Ref<CryptoKey> generate_rsa(int p_bytes) = 0;
virtual Ref<X509Certificate> generate_self_signed_certificate(Ref<CryptoKey> p_key, String p_issuer_name, String p_not_before, String p_not_after) = 0;
virtual Vector<uint8_t> sign(HashingContext::HashType p_hash_type, Vector<uint8_t> p_hash, Ref<CryptoKey> p_key) = 0;
virtual bool verify(HashingContext::HashType p_hash_type, Vector<uint8_t> p_hash, Vector<uint8_t> p_signature, Ref<CryptoKey> p_key) = 0;
virtual Vector<uint8_t> encrypt(Ref<CryptoKey> p_key, Vector<uint8_t> p_plaintext) = 0;
virtual Vector<uint8_t> decrypt(Ref<CryptoKey> p_key, Vector<uint8_t> p_ciphertext) = 0;
PoolByteArray hmac_digest(HashingContext::HashType p_hash_type, PoolByteArray p_key, PoolByteArray p_msg);
// Compares two PoolByteArrays for equality without leaking timing information in order to prevent timing attacks.
// @see: https://paragonie.com/blog/2015/11/preventing-timing-attacks-on-string-comparison-with-double-hmac-strategy
bool constant_time_compare(PoolByteArray p_trusted, PoolByteArray p_received);
Crypto();
};
class ResourceFormatLoaderCrypto : public ResourceFormatLoader {
public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};
class ResourceFormatSaverCrypto : public ResourceFormatSaver {
public:
virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0);
virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const;
virtual bool recognize(const RES &p_resource) const;
};
#endif // CRYPTO_H

View File

@@ -1,193 +0,0 @@
/*************************************************************************/
/* crypto_core.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "crypto_core.h"
#include <mbedtls/aes.h>
#include <mbedtls/base64.h>
#include <mbedtls/md5.h>
#include <mbedtls/sha1.h>
#include <mbedtls/sha256.h>
// MD5
CryptoCore::MD5Context::MD5Context() {
ctx = memalloc(sizeof(mbedtls_md5_context));
mbedtls_md5_init((mbedtls_md5_context *)ctx);
}
CryptoCore::MD5Context::~MD5Context() {
mbedtls_md5_free((mbedtls_md5_context *)ctx);
memfree((mbedtls_md5_context *)ctx);
}
Error CryptoCore::MD5Context::start() {
int ret = mbedtls_md5_starts_ret((mbedtls_md5_context *)ctx);
return ret ? FAILED : OK;
}
Error CryptoCore::MD5Context::update(const uint8_t *p_src, size_t p_len) {
int ret = mbedtls_md5_update_ret((mbedtls_md5_context *)ctx, p_src, p_len);
return ret ? FAILED : OK;
}
Error CryptoCore::MD5Context::finish(unsigned char r_hash[16]) {
int ret = mbedtls_md5_finish_ret((mbedtls_md5_context *)ctx, r_hash);
return ret ? FAILED : OK;
}
// SHA1
CryptoCore::SHA1Context::SHA1Context() {
ctx = memalloc(sizeof(mbedtls_sha1_context));
mbedtls_sha1_init((mbedtls_sha1_context *)ctx);
}
CryptoCore::SHA1Context::~SHA1Context() {
mbedtls_sha1_free((mbedtls_sha1_context *)ctx);
memfree((mbedtls_sha1_context *)ctx);
}
Error CryptoCore::SHA1Context::start() {
int ret = mbedtls_sha1_starts_ret((mbedtls_sha1_context *)ctx);
return ret ? FAILED : OK;
}
Error CryptoCore::SHA1Context::update(const uint8_t *p_src, size_t p_len) {
int ret = mbedtls_sha1_update_ret((mbedtls_sha1_context *)ctx, p_src, p_len);
return ret ? FAILED : OK;
}
Error CryptoCore::SHA1Context::finish(unsigned char r_hash[20]) {
int ret = mbedtls_sha1_finish_ret((mbedtls_sha1_context *)ctx, r_hash);
return ret ? FAILED : OK;
}
// SHA256
CryptoCore::SHA256Context::SHA256Context() {
ctx = memalloc(sizeof(mbedtls_sha256_context));
mbedtls_sha256_init((mbedtls_sha256_context *)ctx);
}
CryptoCore::SHA256Context::~SHA256Context() {
mbedtls_sha256_free((mbedtls_sha256_context *)ctx);
memfree((mbedtls_sha256_context *)ctx);
}
Error CryptoCore::SHA256Context::start() {
int ret = mbedtls_sha256_starts_ret((mbedtls_sha256_context *)ctx, 0);
return ret ? FAILED : OK;
}
Error CryptoCore::SHA256Context::update(const uint8_t *p_src, size_t p_len) {
int ret = mbedtls_sha256_update_ret((mbedtls_sha256_context *)ctx, p_src, p_len);
return ret ? FAILED : OK;
}
Error CryptoCore::SHA256Context::finish(unsigned char r_hash[32]) {
int ret = mbedtls_sha256_finish_ret((mbedtls_sha256_context *)ctx, r_hash);
return ret ? FAILED : OK;
}
// AES256
CryptoCore::AESContext::AESContext() {
ctx = memalloc(sizeof(mbedtls_aes_context));
mbedtls_aes_init((mbedtls_aes_context *)ctx);
}
CryptoCore::AESContext::~AESContext() {
mbedtls_aes_free((mbedtls_aes_context *)ctx);
memfree((mbedtls_aes_context *)ctx);
}
Error CryptoCore::AESContext::set_encode_key(const uint8_t *p_key, size_t p_bits) {
int ret = mbedtls_aes_setkey_enc((mbedtls_aes_context *)ctx, p_key, p_bits);
return ret ? FAILED : OK;
}
Error CryptoCore::AESContext::set_decode_key(const uint8_t *p_key, size_t p_bits) {
int ret = mbedtls_aes_setkey_dec((mbedtls_aes_context *)ctx, p_key, p_bits);
return ret ? FAILED : OK;
}
Error CryptoCore::AESContext::encrypt_ecb(const uint8_t p_src[16], uint8_t r_dst[16]) {
int ret = mbedtls_aes_crypt_ecb((mbedtls_aes_context *)ctx, MBEDTLS_AES_ENCRYPT, p_src, r_dst);
return ret ? FAILED : OK;
}
Error CryptoCore::AESContext::decrypt_ecb(const uint8_t p_src[16], uint8_t r_dst[16]) {
int ret = mbedtls_aes_crypt_ecb((mbedtls_aes_context *)ctx, MBEDTLS_AES_DECRYPT, p_src, r_dst);
return ret ? FAILED : OK;
}
Error CryptoCore::AESContext::encrypt_cbc(size_t p_length, uint8_t r_iv[16], const uint8_t *p_src, uint8_t *r_dst) {
int ret = mbedtls_aes_crypt_cbc((mbedtls_aes_context *)ctx, MBEDTLS_AES_ENCRYPT, p_length, r_iv, p_src, r_dst);
return ret ? FAILED : OK;
}
Error CryptoCore::AESContext::decrypt_cbc(size_t p_length, uint8_t r_iv[16], const uint8_t *p_src, uint8_t *r_dst) {
int ret = mbedtls_aes_crypt_cbc((mbedtls_aes_context *)ctx, MBEDTLS_AES_DECRYPT, p_length, r_iv, p_src, r_dst);
return ret ? FAILED : OK;
}
// CryptoCore
String CryptoCore::b64_encode_str(const uint8_t *p_src, int p_src_len) {
int b64len = p_src_len / 3 * 4 + 4 + 1;
PoolVector<uint8_t> b64buff;
b64buff.resize(b64len);
PoolVector<uint8_t>::Write w64 = b64buff.write();
size_t strlen = 0;
int ret = b64_encode(&w64[0], b64len, &strlen, p_src, p_src_len);
w64[strlen] = 0;
return ret ? String() : (const char *)&w64[0];
}
Error CryptoCore::b64_encode(uint8_t *r_dst, int p_dst_len, size_t *r_len, const uint8_t *p_src, int p_src_len) {
int ret = mbedtls_base64_encode(r_dst, p_dst_len, r_len, p_src, p_src_len);
return ret ? FAILED : OK;
}
Error CryptoCore::b64_decode(uint8_t *r_dst, int p_dst_len, size_t *r_len, const uint8_t *p_src, int p_src_len) {
int ret = mbedtls_base64_decode(r_dst, p_dst_len, r_len, p_src, p_src_len);
return ret ? FAILED : OK;
}
Error CryptoCore::md5(const uint8_t *p_src, int p_src_len, unsigned char r_hash[16]) {
int ret = mbedtls_md5_ret(p_src, p_src_len, r_hash);
return ret ? FAILED : OK;
}
Error CryptoCore::sha1(const uint8_t *p_src, int p_src_len, unsigned char r_hash[20]) {
int ret = mbedtls_sha1_ret(p_src, p_src_len, r_hash);
return ret ? FAILED : OK;
}
Error CryptoCore::sha256(const uint8_t *p_src, int p_src_len, unsigned char r_hash[32]) {
int ret = mbedtls_sha256_ret(p_src, p_src_len, r_hash, 0);
return ret ? FAILED : OK;
}

View File

@@ -1,101 +0,0 @@
/*************************************************************************/
/* crypto_core.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef CRYPTO_CORE_H
#define CRYPTO_CORE_H
#include "core/reference.h"
class CryptoCore {
public:
class MD5Context {
private:
void *ctx; // To include, or not to include...
public:
MD5Context();
~MD5Context();
Error start();
Error update(const uint8_t *p_src, size_t p_len);
Error finish(unsigned char r_hash[16]);
};
class SHA1Context {
private:
void *ctx; // To include, or not to include...
public:
SHA1Context();
~SHA1Context();
Error start();
Error update(const uint8_t *p_src, size_t p_len);
Error finish(unsigned char r_hash[20]);
};
class SHA256Context {
private:
void *ctx; // To include, or not to include...
public:
SHA256Context();
~SHA256Context();
Error start();
Error update(const uint8_t *p_src, size_t p_len);
Error finish(unsigned char r_hash[32]);
};
class AESContext {
private:
void *ctx; // To include, or not to include...
public:
AESContext();
~AESContext();
Error set_encode_key(const uint8_t *p_key, size_t p_bits);
Error set_decode_key(const uint8_t *p_key, size_t p_bits);
Error encrypt_ecb(const uint8_t p_src[16], uint8_t r_dst[16]);
Error decrypt_ecb(const uint8_t p_src[16], uint8_t r_dst[16]);
Error encrypt_cbc(size_t p_length, uint8_t r_iv[16], const uint8_t *p_src, uint8_t *r_dst);
Error decrypt_cbc(size_t p_length, uint8_t r_iv[16], const uint8_t *p_src, uint8_t *r_dst);
};
static String b64_encode_str(const uint8_t *p_src, int p_src_len);
static Error b64_encode(uint8_t *r_dst, int p_dst_len, size_t *r_len, const uint8_t *p_src, int p_src_len);
static Error b64_decode(uint8_t *r_dst, int p_dst_len, size_t *r_len, const uint8_t *p_src, int p_src_len);
static Error md5(const uint8_t *p_src, int p_src_len, unsigned char r_hash[16]);
static Error sha1(const uint8_t *p_src, int p_src_len, unsigned char r_hash[20]);
static Error sha256(const uint8_t *p_src, int p_src_len, unsigned char r_hash[32]);
};
#endif // CRYPTO_CORE_H

View File

@@ -1,138 +0,0 @@
/*************************************************************************/
/* hashing_context.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "hashing_context.h"
#include "core/crypto/crypto_core.h"
Error HashingContext::start(HashType p_type) {
ERR_FAIL_COND_V(ctx != nullptr, ERR_ALREADY_IN_USE);
_create_ctx(p_type);
ERR_FAIL_COND_V(ctx == nullptr, ERR_UNAVAILABLE);
switch (type) {
case HASH_MD5:
return ((CryptoCore::MD5Context *)ctx)->start();
case HASH_SHA1:
return ((CryptoCore::SHA1Context *)ctx)->start();
case HASH_SHA256:
return ((CryptoCore::SHA256Context *)ctx)->start();
}
return ERR_UNAVAILABLE;
}
Error HashingContext::update(PoolByteArray p_chunk) {
ERR_FAIL_COND_V(ctx == nullptr, ERR_UNCONFIGURED);
size_t len = p_chunk.size();
ERR_FAIL_COND_V(len == 0, FAILED);
PoolByteArray::Read r = p_chunk.read();
switch (type) {
case HASH_MD5:
return ((CryptoCore::MD5Context *)ctx)->update(&r[0], len);
case HASH_SHA1:
return ((CryptoCore::SHA1Context *)ctx)->update(&r[0], len);
case HASH_SHA256:
return ((CryptoCore::SHA256Context *)ctx)->update(&r[0], len);
}
return ERR_UNAVAILABLE;
}
PoolByteArray HashingContext::finish() {
ERR_FAIL_COND_V(ctx == nullptr, PoolByteArray());
PoolByteArray out;
Error err = FAILED;
switch (type) {
case HASH_MD5:
out.resize(16);
err = ((CryptoCore::MD5Context *)ctx)->finish(out.write().ptr());
break;
case HASH_SHA1:
out.resize(20);
err = ((CryptoCore::SHA1Context *)ctx)->finish(out.write().ptr());
break;
case HASH_SHA256:
out.resize(32);
err = ((CryptoCore::SHA256Context *)ctx)->finish(out.write().ptr());
break;
}
_delete_ctx();
ERR_FAIL_COND_V(err != OK, PoolByteArray());
return out;
}
void HashingContext::_create_ctx(HashType p_type) {
type = p_type;
switch (type) {
case HASH_MD5:
ctx = memnew(CryptoCore::MD5Context);
break;
case HASH_SHA1:
ctx = memnew(CryptoCore::SHA1Context);
break;
case HASH_SHA256:
ctx = memnew(CryptoCore::SHA256Context);
break;
default:
ctx = nullptr;
}
}
void HashingContext::_delete_ctx() {
switch (type) {
case HASH_MD5:
memdelete((CryptoCore::MD5Context *)ctx);
break;
case HASH_SHA1:
memdelete((CryptoCore::SHA1Context *)ctx);
break;
case HASH_SHA256:
memdelete((CryptoCore::SHA256Context *)ctx);
break;
}
ctx = nullptr;
}
void HashingContext::_bind_methods() {
ClassDB::bind_method(D_METHOD("start", "type"), &HashingContext::start);
ClassDB::bind_method(D_METHOD("update", "chunk"), &HashingContext::update);
ClassDB::bind_method(D_METHOD("finish"), &HashingContext::finish);
BIND_ENUM_CONSTANT(HASH_MD5);
BIND_ENUM_CONSTANT(HASH_SHA1);
BIND_ENUM_CONSTANT(HASH_SHA256);
}
HashingContext::HashingContext() {
ctx = nullptr;
}
HashingContext::~HashingContext() {
if (ctx != nullptr) {
_delete_ctx();
}
}

View File

@@ -1,66 +0,0 @@
/*************************************************************************/
/* hashing_context.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef HASHING_CONTEXT_H
#define HASHING_CONTEXT_H
#include "core/reference.h"
class HashingContext : public Reference {
GDCLASS(HashingContext, Reference);
public:
enum HashType {
HASH_MD5,
HASH_SHA1,
HASH_SHA256
};
private:
void *ctx;
HashType type;
protected:
static void _bind_methods();
void _create_ctx(HashType p_type);
void _delete_ctx();
public:
Error start(HashType p_type);
Error update(PoolByteArray p_chunk);
PoolByteArray finish();
HashingContext();
~HashingContext();
};
VARIANT_ENUM_CAST(HashingContext::HashType);
#endif // HASHING_CONTEXT_H

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -35,14 +35,15 @@
#include "core/variant.h"
struct DictionaryPrivate {
SafeRefCount refcount;
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> variant_map;
};
void Dictionary::get_key_list(List<Variant> *p_keys) const {
if (_p->variant_map.empty()) {
if (_p->variant_map.empty())
return;
}
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
p_keys->push_back(E.key());
@@ -50,6 +51,7 @@ void Dictionary::get_key_list(List<Variant> *p_keys) const {
}
Variant Dictionary::get_key_at_index(int p_index) const {
int index = 0;
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
if (index == p_index) {
@@ -62,6 +64,7 @@ Variant Dictionary::get_key_at_index(int p_index) const {
}
Variant Dictionary::get_value_at_index(int p_index) const {
int index = 0;
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
if (index == p_index) {
@@ -74,36 +77,38 @@ Variant Dictionary::get_value_at_index(int p_index) const {
}
Variant &Dictionary::operator[](const Variant &p_key) {
return _p->variant_map[p_key];
}
const Variant &Dictionary::operator[](const Variant &p_key) const {
return _p->variant_map[p_key];
}
const Variant *Dictionary::getptr(const Variant &p_key) const {
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key);
if (!E) {
return nullptr;
}
if (!E)
return NULL;
return &E.get();
}
Variant *Dictionary::getptr(const Variant &p_key) {
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(p_key);
if (!E) {
return nullptr;
}
if (!E)
return NULL;
return &E.get();
}
Variant Dictionary::get_valid(const Variant &p_key) const {
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::ConstElement E = ((const OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator> *)&_p->variant_map)->find(p_key);
if (!E) {
if (!E)
return Variant();
}
return E.get();
}
@@ -117,13 +122,16 @@ Variant Dictionary::get(const Variant &p_key, const Variant &p_default) const {
}
int Dictionary::size() const {
return _p->variant_map.size();
}
bool Dictionary::empty() const {
return !_p->variant_map.size();
}
bool Dictionary::has(const Variant &p_key) const {
return _p->variant_map.has(p_key);
}
@@ -137,63 +145,71 @@ bool Dictionary::has_all(const Array &p_keys) const {
}
bool Dictionary::erase(const Variant &p_key) {
return _p->variant_map.erase(p_key);
}
bool Dictionary::operator==(const Dictionary &p_dictionary) const {
return _p == p_dictionary._p;
}
bool Dictionary::operator!=(const Dictionary &p_dictionary) const {
return _p != p_dictionary._p;
}
void Dictionary::_ref(const Dictionary &p_from) const {
//make a copy first (thread safe)
if (!p_from._p->refcount.ref()) {
if (!p_from._p->refcount.ref())
return; // couldn't copy
}
//if this is the same, unreference the other one
if (p_from._p == _p) {
_p->refcount.unref();
return;
}
if (_p) {
if (_p)
_unref();
}
_p = p_from._p;
}
void Dictionary::clear() {
_p->variant_map.clear();
}
void Dictionary::_unref() const {
ERR_FAIL_COND(!_p);
if (_p->refcount.unref()) {
memdelete(_p);
}
_p = nullptr;
_p = NULL;
}
uint32_t Dictionary::hash() const {
uint32_t h = hash_djb2_one_32(Variant::DICTIONARY);
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
h = hash_djb2_one_32(E.key().hash(), h);
h = hash_djb2_one_32(E.value().hash(), h);
List<Variant> keys;
get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
h = hash_djb2_one_32(E->get().hash(), h);
h = hash_djb2_one_32(operator[](E->get()).hash(), h);
}
return h;
}
Array Dictionary::keys() const {
Array varr;
if (_p->variant_map.empty()) {
return varr;
}
Array varr;
varr.resize(size());
if (_p->variant_map.empty())
return varr;
int i = 0;
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
@@ -205,12 +221,11 @@ Array Dictionary::keys() const {
}
Array Dictionary::values() const {
Array varr;
if (_p->variant_map.empty()) {
return varr;
}
Array varr;
varr.resize(size());
if (_p->variant_map.empty())
return varr;
int i = 0;
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
@@ -222,48 +237,50 @@ Array Dictionary::values() const {
}
const Variant *Dictionary::next(const Variant *p_key) const {
if (p_key == nullptr) {
if (p_key == NULL) {
// caller wants to get the first element
if (_p->variant_map.front()) {
if (_p->variant_map.front())
return &_p->variant_map.front().key();
}
return nullptr;
return NULL;
}
OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.find(*p_key);
if (E && E.next()) {
if (E && E.next())
return &E.next().key();
}
return nullptr;
return NULL;
}
Dictionary Dictionary::duplicate(bool p_deep) const {
Dictionary n;
for (OrderedHashMap<Variant, Variant, VariantHasher, VariantComparator>::Element E = _p->variant_map.front(); E; E = E.next()) {
n[E.key()] = p_deep ? E.value().duplicate(true) : E.value();
List<Variant> keys;
get_key_list(&keys);
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
n[E->get()] = p_deep ? operator[](E->get()).duplicate(p_deep) : operator[](E->get());
}
return n;
}
void Dictionary::operator=(const Dictionary &p_dictionary) {
_ref(p_dictionary);
}
const void *Dictionary::id() const {
return _p->variant_map.id();
}
Dictionary::Dictionary(const Dictionary &p_from) {
_p = nullptr;
_p = NULL;
_ref(p_from);
}
Dictionary::Dictionary() {
_p = memnew(DictionaryPrivate);
_p->refcount.init();
}
Dictionary::~Dictionary() {
_unref();
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -40,6 +40,7 @@ class Variant;
struct DictionaryPrivate;
class Dictionary {
mutable DictionaryPrivate *_p;
void _ref(const Dictionary &p_from) const;
@@ -74,15 +75,13 @@ public:
uint32_t hash() const;
void operator=(const Dictionary &p_dictionary);
const Variant *next(const Variant *p_key = nullptr) const;
const Variant *next(const Variant *p_key = NULL) const;
Array keys() const;
Array values() const;
Dictionary duplicate(bool p_deep = false) const;
const void *id() const;
Dictionary(const Dictionary &p_from);
Dictionary();
~Dictionary();

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,17 +37,17 @@
#include "core/version_hash.gen.h"
void Engine::set_iterations_per_second(int p_ips) {
ERR_FAIL_COND_MSG(p_ips <= 0, "Engine iterations per second must be greater than 0.");
ips = p_ips;
}
int Engine::get_iterations_per_second() const {
return ips;
}
void Engine::set_physics_jitter_fix(float p_threshold) {
if (p_threshold < 0) {
if (p_threshold < 0)
p_threshold = 0;
}
physics_jitter_fix = p_threshold;
}
@@ -59,39 +59,45 @@ void Engine::set_target_fps(int p_fps) {
_target_fps = p_fps > 0 ? p_fps : 0;
}
int Engine::get_target_fps() const {
float Engine::get_target_fps() const {
return _target_fps;
}
uint64_t Engine::get_frames_drawn() {
return frames_drawn;
}
void Engine::set_frame_delay(uint32_t p_msec) {
_frame_delay = p_msec;
}
uint32_t Engine::get_frame_delay() const {
return _frame_delay;
}
void Engine::set_time_scale(float p_scale) {
_time_scale = p_scale;
}
float Engine::get_time_scale() const {
return _time_scale;
}
void Engine::set_portals_active(bool p_active) {
_portals_active = p_active;
}
Dictionary Engine::get_version_info() const {
Dictionary dict;
dict["major"] = VERSION_MAJOR;
dict["minor"] = VERSION_MINOR;
#ifdef VERSION_PATCH
dict["patch"] = VERSION_PATCH;
#else
dict["patch"] = 0;
#endif
dict["hex"] = VERSION_HEX;
dict["status"] = VERSION_STATUS;
dict["build"] = VERSION_BUILD;
@@ -101,9 +107,8 @@ Dictionary Engine::get_version_info() const {
dict["hash"] = hash.length() == 0 ? String("unknown") : hash;
String stringver = String(dict["major"]) + "." + String(dict["minor"]);
if ((int)dict["patch"] != 0) {
if ((int)dict["patch"] != 0)
stringver += "." + String(dict["patch"]);
}
stringver += "-" + String(dict["status"]) + " (" + String(dict["build"]) + ")";
dict["string"] = stringver;
@@ -112,8 +117,8 @@ Dictionary Engine::get_version_info() const {
static Array array_from_info(const char *const *info_list) {
Array arr;
for (int i = 0; info_list[i] != nullptr; i++) {
arr.push_back(String::utf8(info_list[i]));
for (int i = 0; info_list[i] != NULL; i++) {
arr.push_back(info_list[i]);
}
return arr;
}
@@ -121,7 +126,7 @@ static Array array_from_info(const char *const *info_list) {
static Array array_from_info_count(const char *const *info_list, int info_count) {
Array arr;
for (int i = 0; i < info_count; i++) {
arr.push_back(String::utf8(info_list[i]));
arr.push_back(info_list[i]);
}
return arr;
}
@@ -142,14 +147,14 @@ Array Engine::get_copyright_info() const {
for (int component_index = 0; component_index < COPYRIGHT_INFO_COUNT; component_index++) {
const ComponentCopyright &cp_info = COPYRIGHT_INFO[component_index];
Dictionary component_dict;
component_dict["name"] = String::utf8(cp_info.name);
component_dict["name"] = cp_info.name;
Array parts;
for (int i = 0; i < cp_info.part_count; i++) {
const ComponentCopyrightPart &cp_part = cp_info.parts[i];
Dictionary part_dict;
part_dict["files"] = array_from_info_count(cp_part.files, cp_part.file_count);
part_dict["copyright"] = array_from_info_count(cp_part.copyright_statements, cp_part.copyright_count);
part_dict["license"] = String::utf8(cp_part.license);
part_dict["license"] = cp_part.license;
parts.push_back(part_dict);
}
component_dict["parts"] = parts;
@@ -161,10 +166,8 @@ Array Engine::get_copyright_info() const {
Dictionary Engine::get_donor_info() const {
Dictionary donors;
donors["platinum_sponsors"] = array_from_info(DONORS_SPONSOR_PLATINUM);
donors["platinum_sponsors"] = array_from_info(DONORS_SPONSOR_PLAT);
donors["gold_sponsors"] = array_from_info(DONORS_SPONSOR_GOLD);
donors["silver_sponsors"] = array_from_info(DONORS_SPONSOR_SILVER);
donors["bronze_sponsors"] = array_from_info(DONORS_SPONSOR_BRONZE);
donors["mini_sponsors"] = array_from_info(DONORS_SPONSOR_MINI);
donors["gold_donors"] = array_from_info(DONORS_GOLD);
donors["silver_donors"] = array_from_info(DONORS_SILVER);
@@ -184,68 +187,52 @@ String Engine::get_license_text() const {
return String(GODOT_LICENSE_TEXT);
}
void Engine::set_print_error_messages(bool p_enabled) {
_print_error_enabled = p_enabled;
}
bool Engine::is_printing_error_messages() const {
return _print_error_enabled;
}
void Engine::add_singleton(const Singleton &p_singleton) {
singletons.push_back(p_singleton);
singleton_ptrs[p_singleton.name] = p_singleton.ptr;
}
Object *Engine::get_singleton_object(const String &p_name) const {
const Map<StringName, Object *>::Element *E = singleton_ptrs.find(p_name);
ERR_FAIL_COND_V_MSG(!E, nullptr, "Failed to retrieve non-existent singleton '" + p_name + "'.");
ERR_EXPLAIN("Failed to retrieve non-existent singleton '" + p_name + "'");
ERR_FAIL_COND_V(!E, NULL);
return E->get();
};
bool Engine::has_singleton(const String &p_name) const {
return singleton_ptrs.has(p_name);
};
void Engine::get_singletons(List<Singleton> *p_singletons) {
for (List<Singleton>::Element *E = singletons.front(); E; E = E->next()) {
for (List<Singleton>::Element *E = singletons.front(); E; E = E->next())
p_singletons->push_back(E->get());
}
}
Engine *Engine::singleton = nullptr;
Engine *Engine::singleton = NULL;
Engine *Engine::get_singleton() {
return singleton;
}
Engine::Engine() {
singleton = this;
frames_drawn = 0;
ips = 60;
physics_jitter_fix = 0.5;
_physics_interpolation_fraction = 0.0f;
_frame_delay = 0;
_fps = 1;
_target_fps = 0;
_time_scale = 1.0;
_gpu_pixel_snap = false;
_pixel_snap = false;
_physics_frames = 0;
_idle_frames = 0;
_in_physics = false;
_frame_ticks = 0;
_frame_step = 0;
editor_hint = false;
_portals_active = false;
}
Engine::Singleton::Singleton(const StringName &p_name, Object *p_ptr) :
name(p_name),
ptr(p_ptr) {
#ifdef DEBUG_ENABLED
Reference *ref = Object::cast_to<Reference>(p_ptr);
if (ref && !ref->is_referenced()) {
WARN_PRINT("You must use Ref<> to ensure the lifetime of a Reference object intended to be used as a singleton.");
}
#endif
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,11 +37,15 @@
#include "core/vector.h"
class Engine {
public:
struct Singleton {
StringName name;
Object *ptr;
Singleton(const StringName &p_name = StringName(), Object *p_ptr = nullptr);
Singleton(const StringName &p_name = StringName(), Object *p_ptr = NULL) :
name(p_name),
ptr(p_ptr) {
}
};
private:
@@ -57,11 +61,8 @@ private:
float _fps;
int _target_fps;
float _time_scale;
bool _gpu_pixel_snap;
bool _pixel_snap;
uint64_t _physics_frames;
float _physics_interpolation_fraction;
bool _portals_active;
bool _occlusion_culling_active;
uint64_t _idle_frames;
bool _in_physics;
@@ -83,7 +84,7 @@ public:
float get_physics_jitter_fix() const;
virtual void set_target_fps(int p_fps);
virtual int get_target_fps() const;
virtual float get_target_fps() const;
virtual float get_frames_per_second() const { return _fps; }
@@ -94,7 +95,6 @@ public:
bool is_in_physics_frame() const { return _in_physics; }
uint64_t get_idle_frame_ticks() const { return _frame_ticks; }
float get_idle_frame_step() const { return _frame_step; }
float get_physics_interpolation_fraction() const { return _physics_interpolation_fraction; }
void set_time_scale(float p_scale);
float get_time_scale() const;
@@ -102,17 +102,12 @@ public:
void set_frame_delay(uint32_t p_msec);
uint32_t get_frame_delay() const;
void set_print_error_messages(bool p_enabled);
bool is_printing_error_messages() const;
void add_singleton(const Singleton &p_singleton);
void get_singletons(List<Singleton> *p_singletons);
bool has_singleton(const String &p_name) const;
Object *get_singleton_object(const String &p_name) const;
_FORCE_INLINE_ bool get_use_gpu_pixel_snap() const { return _gpu_pixel_snap; }
bool are_portals_active() const { return _portals_active; }
void set_portals_active(bool p_active);
_FORCE_INLINE_ bool get_use_pixel_snap() const { return _pixel_snap; }
#ifdef TOOLS_ENABLED
_FORCE_INLINE_ void set_editor_hint(bool p_enabled) { editor_hint = p_enabled; }

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -39,7 +39,7 @@
*/
enum Error {
OK, // (0)
OK,
FAILED, ///< Generic fail error
ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable
ERR_UNCONFIGURED, ///< The object being used hasn't been properly set up yet
@@ -69,12 +69,12 @@ enum Error {
ERR_CONNECTION_ERROR,
ERR_CANT_ACQUIRE_RESOURCE,
ERR_CANT_FORK,
ERR_INVALID_DATA, ///< Data passed is invalid (30)
ERR_INVALID_DATA, ///< Data passed is invalid (30)
ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
ERR_ALREADY_EXISTS, ///< When adding, item already exists
ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, if item does not exist
ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
ERR_DATABASE_CANT_READ, ///< database is full
ERR_DATABASE_CANT_WRITE, ///< database is full (35)
ERR_DATABASE_CANT_WRITE, ///< database is full (35)
ERR_COMPILATION_FAILED,
ERR_METHOD_NOT_FOUND,
ERR_LINK_FAILED,

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,12 +31,24 @@
#include "error_macros.h"
#include "core/io/logger.h"
#include "core/ustring.h"
#include "os/os.h"
static ErrorHandlerList *error_handler_list = nullptr;
bool _err_error_exists = false;
static ErrorHandlerList *error_handler_list = NULL;
void _err_set_last_error(const char *p_err) {
OS::get_singleton()->set_last_error(p_err);
}
void _err_clear_last_error() {
OS::get_singleton()->clear_last_error();
}
void add_error_handler(ErrorHandlerList *p_handler) {
_global_lock();
p_handler->next = error_handler_list;
error_handler_list = p_handler;
@@ -44,18 +56,20 @@ void add_error_handler(ErrorHandlerList *p_handler) {
}
void remove_error_handler(ErrorHandlerList *p_handler) {
_global_lock();
ErrorHandlerList *prev = nullptr;
ErrorHandlerList *prev = NULL;
ErrorHandlerList *l = error_handler_list;
while (l) {
if (l == p_handler) {
if (prev) {
if (prev)
prev->next = l->next;
} else {
else
error_handler_list = l->next;
}
break;
}
prev = l;
@@ -66,48 +80,28 @@ void remove_error_handler(ErrorHandlerList *p_handler) {
}
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, ErrorHandlerType p_type) {
_err_print_error(p_function, p_file, p_line, p_error, "", p_type);
}
void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, ErrorHandlerType p_type) {
_err_print_error(p_function, p_file, p_line, p_error.utf8().get_data(), "", p_type);
}
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, ErrorHandlerType p_type) {
OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, p_message, (Logger::ErrorType)p_type);
OS::get_singleton()->print_error(p_function, p_file, p_line, p_error, _err_error_exists ? OS::get_singleton()->get_last_error() : "", (Logger::ErrorType)p_type);
_global_lock();
ErrorHandlerList *l = error_handler_list;
while (l) {
l->errfunc(l->userdata, p_function, p_file, p_line, p_error, p_message, p_type);
l->errfunc(l->userdata, p_function, p_file, p_line, p_error, _err_error_exists ? OS::get_singleton()->get_last_error() : "", p_type);
l = l->next;
}
_global_unlock();
if (_err_error_exists) {
OS::get_singleton()->clear_last_error();
_err_error_exists = false;
}
}
void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const char *p_message, ErrorHandlerType p_type) {
_err_print_error(p_function, p_file, p_line, p_error.utf8().get_data(), p_message, p_type);
}
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, bool fatal) {
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const String &p_message, ErrorHandlerType p_type) {
_err_print_error(p_function, p_file, p_line, p_error, p_message.utf8().get_data(), p_type);
}
void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const String &p_message, ErrorHandlerType p_type) {
_err_print_error(p_function, p_file, p_line, p_error.utf8().get_data(), p_message.utf8().get_data(), p_type);
}
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message, bool fatal) {
String fstr(fatal ? "FATAL: " : "");
String err(fstr + "Index " + p_index_str + " = " + itos(p_index) + " is out of bounds (" + p_size_str + " = " + itos(p_size) + ").");
_err_print_error(p_function, p_file, p_line, err.utf8().get_data(), p_message);
}
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool fatal) {
_err_print_index_error(p_function, p_file, p_line, p_index, p_size, p_index_str, p_size_str, p_message.utf8().get_data(), fatal);
}
void _err_flush_stdout() {
fflush(stdout);
String err(fstr + "Index " + p_index_str + "=" + itos(p_index) + " out of size (" + p_size_str + "=" + itos(p_size) + ")");
_err_print_error(p_function, p_file, p_line, err.utf8().get_data());
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,19 +31,17 @@
#ifndef ERROR_MACROS_H
#define ERROR_MACROS_H
#include "core/safe_refcount.h"
#include "core/typedefs.h"
/**
* Error macros. Unlike exceptions and asserts, these macros try to maintain consistency and stability
* inside the code. It is recommended to always return processable data, so in case of an error,
* the engine can keep working well.
* inside the code. It is recommended to always return processable data, so in case of an error, the
* engine can stay working well.
* In most cases, bugs and/or invalid data are not fatal and should never allow a perfectly running application
* to fail or crash.
*/
/**
* Pointer to the error macro printing function. Reassign to any function to have errors printed
* Pointer to the error macro priting function. Reassign to any function to have errors printed
*/
/** Function used by the error macros */
@@ -57,19 +55,21 @@ enum ErrorHandlerType {
ERR_HANDLER_SHADER,
};
class String;
typedef void (*ErrorHandlerFunc)(void *, const char *, const char *, int p_line, const char *, const char *, ErrorHandlerType p_type);
void _err_set_last_error(const char *p_err);
void _err_clear_last_error();
struct ErrorHandlerList {
ErrorHandlerFunc errfunc;
void *userdata;
ErrorHandlerList *next;
ErrorHandlerList() {
errfunc = nullptr;
next = nullptr;
userdata = nullptr;
errfunc = 0;
next = 0;
userdata = 0;
}
};
@@ -77,14 +77,7 @@ void add_error_handler(ErrorHandlerList *p_handler);
void remove_error_handler(ErrorHandlerList *p_handler);
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const char *p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const String &p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const String &p_message, ErrorHandlerType p_type = ERR_HANDLER_ERROR);
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message = "", bool fatal = false);
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool fatal = false);
void _err_flush_stdout();
void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, bool fatal = false);
#ifndef _STR
#define _STR(m_x) #m_x
@@ -93,7 +86,30 @@ void _err_flush_stdout();
#define _FNL __FILE__ ":"
/** An index has failed if m_index<0 or m_index >=m_size, the function exits */
/** An index has failed if m_index<0 or m_index >=m_size, the function exists */
extern bool _err_error_exists;
#ifdef DEBUG_ENABLED
/** Print a warning string.
*/
#define ERR_EXPLAINC(m_reason) \
{ \
_err_set_last_error(m_reason); \
_err_error_exists = true; \
}
#define ERR_EXPLAIN(m_string) \
{ \
_err_set_last_error(String(m_string).utf8().get_data()); \
_err_error_exists = true; \
}
#else
#define ERR_EXPLAIN(m_text)
#define ERR_EXPLAINC(m_text)
#endif
#ifdef __GNUC__
//#define FUNCTION_STR __PRETTY_FUNCTION__ - too annoying
@@ -115,442 +131,228 @@ void _err_flush_stdout();
// (*): See https://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for
/**
* If `m_index` is less than 0 or greater than or equal to `m_size`, prints a generic
* error message and returns from the function. This macro should be preferred to
* `ERR_FAIL_COND` for bounds checking.
*/
#define ERR_FAIL_INDEX(m_index, m_size) \
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return; \
} else \
((void)0)
#define ERR_FAIL_INDEX(m_index, m_size) \
do { \
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return; \
} else \
_err_error_exists = false; \
} while (0); // (*)
/**
* If `m_index` is less than 0 or greater than or equal to `m_size`, prints a custom
* error message and returns from the function. This macro should be preferred to
* `ERR_FAIL_COND_MSG` for bounds checking.
*/
#define ERR_FAIL_INDEX_MSG(m_index, m_size, m_msg) \
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
return; \
} else \
((void)0)
/** An index has failed if m_index<0 or m_index >=m_size, the function exists.
* This function returns an error value, if returning Error, please select the most
* appropriate error condition from error_macros.h
*/
/**
* If `m_index` is less than 0 or greater than or equal to `m_size`,
* prints a generic error message and returns the value specified in `m_retval`.
* This macro should be preferred to `ERR_FAIL_COND_V` for bounds checking.
*/
#define ERR_FAIL_INDEX_V(m_index, m_size, m_retval) \
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return m_retval; \
} else \
((void)0)
#define ERR_FAIL_INDEX_V(m_index, m_size, m_retval) \
do { \
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return m_retval; \
} else \
_err_error_exists = false; \
} while (0); // (*)
/**
* If `m_index` is less than 0 or greater than or equal to `m_size`,
* prints a custom error message and returns the value specified in `m_retval`.
* This macro should be preferred to `ERR_FAIL_COND_V_MSG` for bounds checking.
*/
#define ERR_FAIL_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
return m_retval; \
} else \
((void)0)
/** An index has failed if m_index >=m_size, the function exists.
* This function returns an error value, if returning Error, please select the most
* appropriate error condition from error_macros.h
*/
/**
* If `m_index` is greater than or equal to `m_size`,
* prints a generic error message and returns the value specified in `m_retval`.
* This macro should be preferred to `ERR_FAIL_COND_V` for unsigned bounds checking.
*/
#define ERR_FAIL_UNSIGNED_INDEX(m_index, m_size) \
if (unlikely((m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return; \
} else \
((void)0)
#define ERR_FAIL_UNSIGNED_INDEX_V(m_index, m_size, m_retval) \
do { \
if (unlikely((m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return m_retval; \
} else \
_err_error_exists = false; \
} while (0); // (*)
/**
* If `m_index` is greater than or equal to `m_size`,
* prints a generic error message and returns the value specified in `m_retval`.
* This macro should be preferred to `ERR_FAIL_COND_V` for unsigned bounds checking.
*/
#define ERR_FAIL_UNSIGNED_INDEX_V(m_index, m_size, m_retval) \
if (unlikely((m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size)); \
return m_retval; \
} else \
((void)0)
/**
* If `m_index` is greater than or equal to `m_size`,
* prints a custom error message and returns the value specified in `m_retval`.
* This macro should be preferred to `ERR_FAIL_COND_V_MSG` for unsigned bounds checking.
*/
#define ERR_FAIL_UNSIGNED_INDEX_V_MSG(m_index, m_size, m_retval, m_msg) \
if (unlikely((m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg); \
return m_retval; \
} else \
((void)0)
/**
* If `m_index` is less than 0 or greater than or equal to `m_size`,
* crashes the engine immediately with a generic error message.
* Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
* This macro should be preferred to `CRASH_COND` for bounds checking.
*/
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
* We'll return a null reference and try to keep running.
*/
#define CRASH_BAD_INDEX(m_index, m_size) \
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
GENERATE_TRAP \
} else \
((void)0)
do { \
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), true); \
GENERATE_TRAP \
} \
} while (0); // (*)
/**
* If `m_index` is less than 0 or greater than or equal to `m_size`,
* crashes the engine immediately with a custom error message.
* Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
* This macro should be preferred to `CRASH_COND` for bounds checking.
*/
#define CRASH_BAD_INDEX_MSG(m_index, m_size, m_msg) \
if (unlikely((m_index) < 0 || (m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), m_msg, true); \
GENERATE_TRAP \
} else \
((void)0)
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
* the function will exit.
*/
/**
* If `m_index` is greater than or equal to `m_size`,
* crashes the engine immediately with a generic error message.
* Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
* This macro should be preferred to `CRASH_COND` for bounds checking.
*/
#define CRASH_BAD_UNSIGNED_INDEX(m_index, m_size) \
if (unlikely((m_index) >= (m_size))) { \
_err_print_index_error(FUNCTION_STR, __FILE__, __LINE__, m_index, m_size, _STR(m_index), _STR(m_size), "", true); \
GENERATE_TRAP \
} else \
((void)0)
#define ERR_FAIL_NULL(m_param) \
{ \
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
return; \
} else \
_err_error_exists = false; \
}
/**
* If `m_param` is `null`, prints a generic error message and returns from the function.
*/
#define ERR_FAIL_NULL(m_param) \
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
return; \
} else \
((void)0)
#define ERR_FAIL_NULL_V(m_param, m_retval) \
{ \
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter ' " _STR(m_param) " ' is null."); \
return m_retval; \
} else \
_err_error_exists = false; \
}
/**
* If `m_param` is `null`, prints a custom error message and returns from the function.
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
* the function will exit.
*/
#define ERR_FAIL_NULL_MSG(m_param, m_msg) \
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", m_msg); \
return; \
} else \
((void)0)
/**
* If `m_param` is `null`, prints a generic error message and returns the value specified in `m_retval`.
*/
#define ERR_FAIL_NULL_V(m_param, m_retval) \
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null."); \
return m_retval; \
} else \
((void)0)
#define ERR_FAIL_COND(m_cond) \
{ \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true."); \
return; \
} else \
_err_error_exists = false; \
}
/**
* If `m_param` is `null`, prints a custom error message and returns the value specified in `m_retval`.
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
*/
#define ERR_FAIL_NULL_V_MSG(m_param, m_retval, m_msg) \
if (unlikely(!m_param)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Parameter \"" _STR(m_param) "\" is null.", m_msg); \
return m_retval; \
} else \
((void)0)
/**
* If `m_cond` evaluates to `true`, prints a generic error message and returns from the function.
*/
#define ERR_FAIL_COND(m_cond) \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true."); \
return; \
} else \
((void)0)
#define CRASH_COND(m_cond) \
{ \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition ' " _STR(m_cond) " ' is true."); \
GENERATE_TRAP \
} \
}
/**
* If `m_cond` evaluates to `true`, prints a custom error message and returns from the function.
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
* the function will exit.
* This function returns an error value, if returning Error, please select the most
* appropriate error condition from error_macros.h
*/
#define ERR_FAIL_COND_MSG(m_cond, m_msg) \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true.", m_msg); \
return; \
} else \
((void)0)
/**
* If `m_cond` evaluates to `true`, crashes the engine immediately with a generic error message.
* Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
*/
#define CRASH_COND(m_cond) \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true."); \
GENERATE_TRAP \
} else \
((void)0)
#define ERR_FAIL_COND_V(m_cond, m_retval) \
{ \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. returned: " _STR(m_retval)); \
return m_retval; \
} else \
_err_error_exists = false; \
}
/**
* If `m_cond` evaluates to `true`, crashes the engine immediately with a custom error message.
* Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
* the loop will skip to the next iteration.
*/
#define CRASH_COND_MSG(m_cond, m_msg) \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Condition \"" _STR(m_cond) "\" is true.", m_msg); \
GENERATE_TRAP \
} else \
((void)0)
/**
* If `m_cond` evaluates to `true`, prints a generic error message and returns the value specified in `m_retval`.
*/
#define ERR_FAIL_COND_V(m_cond, m_retval) \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Returned: " _STR(m_retval)); \
return m_retval; \
} else \
((void)0)
#define ERR_CONTINUE(m_cond) \
{ \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Continuing..:"); \
continue; \
} else \
_err_error_exists = false; \
}
/**
* If `m_cond` evaluates to `true`, prints a custom error message and returns the value specified in `m_retval`.
/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert().
* the loop will break
*/
#define ERR_FAIL_COND_V_MSG(m_cond, m_retval, m_msg) \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Returned: " _STR(m_retval), m_msg); \
return m_retval; \
} else \
((void)0)
/**
* If `m_cond` evaluates to `true`, prints a custom error message and continues the loop the macro is located in.
*/
#define ERR_CONTINUE(m_cond) \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing."); \
continue; \
} else \
((void)0)
#define ERR_BREAK(m_cond) \
{ \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition ' " _STR(m_cond) " ' is true. Breaking..:"); \
break; \
} else \
_err_error_exists = false; \
}
/**
* If `m_cond` evaluates to `true`, prints a custom error message and continues the loop the macro is located in.
/** Print an error string and return
*/
#define ERR_CONTINUE_MSG(m_cond, m_msg) \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Continuing.", m_msg); \
continue; \
} else \
((void)0)
/**
* If `m_cond` evaluates to `true`, prints a generic error message and breaks from the loop the macro is located in.
*/
#define ERR_BREAK(m_cond) \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking."); \
break; \
} else \
((void)0)
#define ERR_FAIL() \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed."); \
_err_error_exists = false; \
return; \
}
/**
* If `m_cond` evaluates to `true`, prints a custom error message and breaks from the loop the macro is located in.
/** Print an error string and return with value
*/
#define ERR_BREAK_MSG(m_cond, m_msg) \
if (unlikely(m_cond)) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Condition \"" _STR(m_cond) "\" is true. Breaking.", m_msg); \
break; \
} else \
((void)0)
/**
* Prints a generic error message and returns from the function.
*/
#define ERR_FAIL() \
if (true) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed."); \
return; \
} else \
((void)0)
#define ERR_FAIL_V(m_value) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method/Function Failed, returning: " __STR(m_value)); \
_err_error_exists = false; \
return m_value; \
}
/**
* Prints a custom error message and returns from the function.
/** Use this one if there is no sensible fallback, that is, the error is unrecoverable.
*/
#define ERR_FAIL_MSG(m_msg) \
if (true) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed.", m_msg); \
return; \
} else \
((void)0)
/**
* Prints a generic error message and returns the value specified in `m_retval`.
*/
#define ERR_FAIL_V(m_retval) \
if (true) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed. Returning: " __STR(m_retval)); \
return m_retval; \
} else \
((void)0)
#define CRASH_NOW() \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method/Function Failed."); \
GENERATE_TRAP \
}
/**
* Prints a custom error message and returns the value specified in `m_retval`.
/** Print an error string.
*/
#define ERR_FAIL_V_MSG(m_retval, m_msg) \
if (true) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "Method failed. Returning: " __STR(m_retval), m_msg); \
return m_retval; \
} else \
((void)0)
/**
* Crashes the engine immediately with a generic error message.
* Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
*/
#define CRASH_NOW() \
if (true) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method failed."); \
void _err_flush_stdout(); \
GENERATE_TRAP \
} else \
((void)0)
#define ERR_PRINT(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
_err_error_exists = false; \
}
/**
* Crashes the engine immediately with a custom error message.
* Only use this if there's no sensible fallback (i.e. the error is unrecoverable).
*/
#define CRASH_NOW_MSG(m_msg) \
if (true) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: Method failed.", m_msg); \
void _err_flush_stdout(); \
GENERATE_TRAP \
} else \
((void)0)
#define ERR_PRINTS(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, String(m_string).utf8().get_data()); \
_err_error_exists = false; \
}
/**
* Prints an error message without returning.
*/
#define ERR_PRINT(m_string) \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string)
/**
* Prints an error message without returning, but only do so once in the application lifecycle.
* This can be used to avoid spamming the console with error messages.
*/
#define ERR_PRINT_ONCE(m_string) \
if (true) { \
{ \
static bool first_print = true; \
if (first_print) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string); \
_err_error_exists = false; \
first_print = false; \
} \
} else \
((void)0)
}
/**
* Prints a warning message without returning. To warn about deprecated usage,
* use `WARN_DEPRECATED` or `WARN_DEPRECATED_MSG` instead.
/** Print a warning string.
*/
#define WARN_PRINT(m_string) \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING)
/**
* Prints a warning message without returning, but only do so once in the application lifecycle.
* This can be used to avoid spamming the console with warning messages.
*/
#define WARN_PRINT(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
_err_error_exists = false; \
}
#define WARN_PRINTS(m_string) \
{ \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, String(m_string).utf8().get_data(), ERR_HANDLER_WARNING); \
_err_error_exists = false; \
}
#define WARN_PRINT_ONCE(m_string) \
if (true) { \
{ \
static bool first_print = true; \
if (first_print) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, m_string, ERR_HANDLER_WARNING); \
_err_error_exists = false; \
first_print = false; \
} \
} else \
((void)0)
}
/**
* Prints a generic deprecation warning message without returning.
* This should be preferred to `WARN_PRINT` for deprecation warnings.
*/
#define WARN_DEPRECATED \
if (true) { \
static SafeFlag warning_shown; \
if (!warning_shown.is_set()) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future.", ERR_HANDLER_WARNING); \
warning_shown.set(); \
} \
} else \
((void)0)
/**
* Prints a custom deprecation warning message without returning.
* This should be preferred to `WARN_PRINT` for deprecation warnings.
*/
#define WARN_DEPRECATED_MSG(m_msg) \
if (true) { \
static SafeFlag warning_shown; \
if (!warning_shown.is_set()) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future.", m_msg, ERR_HANDLER_WARNING); \
warning_shown.set(); \
} \
} else \
((void)0)
#define WARN_DEPRECATED \
{ \
static volatile bool warning_shown = false; \
if (!warning_shown) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "This method has been deprecated and will be removed in the future", ERR_HANDLER_WARNING); \
_err_error_exists = false; \
warning_shown = true; \
} \
}
#endif
/**
* This should be a 'free' assert for program flow and should not be needed in any releases,
* only used in dev builds.
*/
#ifdef DEV_ENABLED
#define DEV_ASSERT(m_cond) \
if (unlikely(!(m_cond))) { \
_err_print_error(FUNCTION_STR, __FILE__, __LINE__, "FATAL: DEV_ASSERT failed \"" _STR(m_cond) "\" is false."); \
void _err_flush_stdout(); \
GENERATE_TRAP \
} else \
((void)0)
#else
#define DEV_ASSERT(m_cond)
#endif
/**
* These should be 'free' checks for program flow and should not be needed in any releases,
* only used in dev builds.
*/
#ifdef DEV_ENABLED
#define DEV_CHECK(m_cond) \
if (unlikely(!(m_cond))) { \
ERR_PRINT("DEV_CHECK failed \"" _STR(m_cond) "\" is false."); \
} else \
((void)0)
#else
#define DEV_CHECK(m_cond)
#endif
#ifdef DEV_ENABLED
#define DEV_CHECK_ONCE(m_cond) \
if (unlikely(!(m_cond))) { \
ERR_PRINT_ONCE("DEV_CHECK_ONCE failed \"" _STR(m_cond) "\" is false."); \
} else \
((void)0)
#else
#define DEV_CHECK_ONCE(m_cond)
#endif

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,6 +31,7 @@
#include "func_ref.h"
Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
if (id == 0) {
r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL;
return Variant();
@@ -45,43 +46,18 @@ Variant FuncRef::call_func(const Variant **p_args, int p_argcount, Variant::Call
return obj->call(function, p_args, p_argcount, r_error);
}
Variant FuncRef::call_funcv(const Array &p_args) {
ERR_FAIL_COND_V(id == 0, Variant());
Object *obj = ObjectDB::get_instance(id);
ERR_FAIL_COND_V(!obj, Variant());
return obj->callv(function, p_args);
}
void FuncRef::set_instance(Object *p_obj) {
ERR_FAIL_NULL(p_obj);
id = p_obj->get_instance_id();
}
void FuncRef::set_function(const StringName &p_func) {
function = p_func;
}
StringName FuncRef::get_function() {
return function;
}
bool FuncRef::is_valid() const {
if (id == 0) {
return false;
}
Object *obj = ObjectDB::get_instance(id);
if (!obj) {
return false;
}
return obj->has_method(function);
}
void FuncRef::_bind_methods() {
{
MethodInfo mi;
mi.name = "call_func";
@@ -89,15 +65,8 @@ void FuncRef::_bind_methods() {
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_func", &FuncRef::call_func, mi, defargs);
}
ClassDB::bind_method(D_METHOD("call_funcv", "arg_array"), &FuncRef::call_funcv);
ClassDB::bind_method(D_METHOD("set_instance", "instance"), &FuncRef::set_instance);
ClassDB::bind_method(D_METHOD("is_valid"), &FuncRef::is_valid);
ClassDB::bind_method(D_METHOD("set_function", "name"), &FuncRef::set_function);
ClassDB::bind_method(D_METHOD("get_function"), &FuncRef::get_function);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "function"), "set_function", "get_function");
}
FuncRef::FuncRef() :

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,6 +34,7 @@
#include "core/reference.h"
class FuncRef : public Reference {
GDCLASS(FuncRef, Reference);
ObjectID id;
StringName function;
@@ -43,11 +44,8 @@ protected:
public:
Variant call_func(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
Variant call_funcv(const Array &p_args);
void set_instance(Object *p_obj);
void set_function(const StringName &p_func);
StringName get_function();
bool is_valid() const;
FuncRef();
};

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -36,9 +36,9 @@
#include "core/variant.h"
struct _GlobalConstant {
#ifdef DEBUG_METHODS_ENABLED
StringName enum_name;
bool ignore_value_in_docs;
#endif
const char *name;
int value;
@@ -46,9 +46,8 @@ struct _GlobalConstant {
_GlobalConstant() {}
#ifdef DEBUG_METHODS_ENABLED
_GlobalConstant(const StringName &p_enum_name, const char *p_name, int p_value, bool p_ignore_value_in_docs = false) :
_GlobalConstant(const StringName &p_enum_name, const char *p_name, int p_value) :
enum_name(p_enum_name),
ignore_value_in_docs(p_ignore_value_in_docs),
name(p_name),
value(p_value) {
}
@@ -73,15 +72,6 @@ static Vector<_GlobalConstant> _global_constants;
#define BIND_GLOBAL_ENUM_CONSTANT_CUSTOM(m_custom_name, m_constant) \
_global_constants.push_back(_GlobalConstant(__constant_get_enum_name(m_constant, #m_constant), m_custom_name, m_constant));
#define BIND_GLOBAL_CONSTANT_NO_VAL(m_constant) \
_global_constants.push_back(_GlobalConstant(StringName(), #m_constant, m_constant, true));
#define BIND_GLOBAL_ENUM_CONSTANT_NO_VAL(m_constant) \
_global_constants.push_back(_GlobalConstant(__constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant, true));
#define BIND_GLOBAL_ENUM_CONSTANT_CUSTOM_NO_VAL(m_custom_name, m_constant) \
_global_constants.push_back(_GlobalConstant(__constant_get_enum_name(m_constant, #m_constant), m_custom_name, m_constant, true));
#else
#define BIND_GLOBAL_CONSTANT(m_constant) \
@@ -93,15 +83,6 @@ static Vector<_GlobalConstant> _global_constants;
#define BIND_GLOBAL_ENUM_CONSTANT_CUSTOM(m_custom_name, m_constant) \
_global_constants.push_back(_GlobalConstant(m_custom_name, m_constant));
#define BIND_GLOBAL_CONSTANT_NO_VAL(m_constant) \
_global_constants.push_back(_GlobalConstant(#m_constant, m_constant));
#define BIND_GLOBAL_ENUM_CONSTANT_NO_VAL(m_constant) \
_global_constants.push_back(_GlobalConstant(#m_constant, m_constant));
#define BIND_GLOBAL_ENUM_CONSTANT_CUSTOM_NO_VAL(m_custom_name, m_constant) \
_global_constants.push_back(_GlobalConstant(m_custom_name, m_constant));
#endif
VARIANT_ENUM_CAST(KeyList);
@@ -111,6 +92,7 @@ VARIANT_ENUM_CAST(JoystickList);
VARIANT_ENUM_CAST(MidiMessageList);
void register_global_constants() {
//{ KEY_BACKSPACE, VK_BACK },// (0x08) // backspace
BIND_GLOBAL_ENUM_CONSTANT(MARGIN_LEFT);
@@ -389,7 +371,7 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_ALT);
BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_META);
BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_CTRL);
BIND_GLOBAL_ENUM_CONSTANT_NO_VAL(KEY_MASK_CMD);
BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_CMD);
BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_KPAD);
BIND_GLOBAL_ENUM_CONSTANT(KEY_MASK_GROUP_SWITCH);
@@ -410,7 +392,6 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(BUTTON_MASK_XBUTTON2);
//joypads
BIND_GLOBAL_ENUM_CONSTANT(JOY_INVALID_OPTION);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_0);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_1);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_2);
@@ -427,13 +408,6 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_13);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_14);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_15);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_16);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_17);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_18);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_19);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_20);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_21);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_22);
BIND_GLOBAL_ENUM_CONSTANT(JOY_BUTTON_MAX);
BIND_GLOBAL_ENUM_CONSTANT(JOY_SONY_CIRCLE);
@@ -451,29 +425,12 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_X);
BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_Y);
BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_GRIP);
BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_PAD);
BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_TRIGGER);
BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_AX);
BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_BY);
BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_MENU);
BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_MENU);
BIND_GLOBAL_ENUM_CONSTANT(JOY_SELECT);
BIND_GLOBAL_ENUM_CONSTANT(JOY_START);
BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_UP);
BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_DOWN);
BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_LEFT);
BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_RIGHT);
BIND_GLOBAL_ENUM_CONSTANT(JOY_GUIDE);
BIND_GLOBAL_ENUM_CONSTANT(JOY_MISC1);
BIND_GLOBAL_ENUM_CONSTANT(JOY_PADDLE1);
BIND_GLOBAL_ENUM_CONSTANT(JOY_PADDLE2);
BIND_GLOBAL_ENUM_CONSTANT(JOY_PADDLE3);
BIND_GLOBAL_ENUM_CONSTANT(JOY_PADDLE4);
BIND_GLOBAL_ENUM_CONSTANT(JOY_TOUCHPAD);
BIND_GLOBAL_ENUM_CONSTANT(JOY_L);
BIND_GLOBAL_ENUM_CONSTANT(JOY_L2);
BIND_GLOBAL_ENUM_CONSTANT(JOY_L3);
@@ -502,12 +459,6 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_L2);
BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_R2);
BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_ANALOG_TRIGGER);
BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_ANALOG_GRIP);
BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_TOUCHPADX);
BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_TOUCHPADY);
// midi
BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_OFF);
BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_ON);
@@ -519,55 +470,47 @@ void register_global_constants() {
// error list
BIND_GLOBAL_ENUM_CONSTANT(OK); // (0)
BIND_GLOBAL_ENUM_CONSTANT(FAILED);
BIND_GLOBAL_ENUM_CONSTANT(ERR_UNAVAILABLE);
BIND_GLOBAL_ENUM_CONSTANT(ERR_UNCONFIGURED);
BIND_GLOBAL_ENUM_CONSTANT(ERR_UNAUTHORIZED);
BIND_GLOBAL_ENUM_CONSTANT(ERR_PARAMETER_RANGE_ERROR); // (5)
BIND_GLOBAL_ENUM_CONSTANT(ERR_OUT_OF_MEMORY);
BIND_GLOBAL_ENUM_CONSTANT(OK);
BIND_GLOBAL_ENUM_CONSTANT(FAILED); ///< Generic fail error
BIND_GLOBAL_ENUM_CONSTANT(ERR_UNAVAILABLE); ///< What is requested is unsupported/unavailable
BIND_GLOBAL_ENUM_CONSTANT(ERR_UNCONFIGURED); ///< The object being used hasn't been properly set up yet
BIND_GLOBAL_ENUM_CONSTANT(ERR_UNAUTHORIZED); ///< Missing credentials for requested resource
BIND_GLOBAL_ENUM_CONSTANT(ERR_PARAMETER_RANGE_ERROR); ///< Parameter given out of range
BIND_GLOBAL_ENUM_CONSTANT(ERR_OUT_OF_MEMORY); ///< Out of memory
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_NOT_FOUND);
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_BAD_DRIVE);
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_BAD_PATH);
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_NO_PERMISSION); // (10)
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_NO_PERMISSION);
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_ALREADY_IN_USE);
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CANT_OPEN);
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CANT_WRITE);
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CANT_READ);
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_UNRECOGNIZED); // (15)
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_UNRECOGNIZED);
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_CORRUPT);
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_MISSING_DEPENDENCIES);
BIND_GLOBAL_ENUM_CONSTANT(ERR_FILE_EOF);
BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_OPEN);
BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_CREATE); // (20)
BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_OPEN); ///< Can't open a resource/socket/file
BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_CREATE);
BIND_GLOBAL_ENUM_CONSTANT(ERR_PARSE_ERROR);
BIND_GLOBAL_ENUM_CONSTANT(ERR_QUERY_FAILED);
BIND_GLOBAL_ENUM_CONSTANT(ERR_ALREADY_IN_USE);
BIND_GLOBAL_ENUM_CONSTANT(ERR_LOCKED);
BIND_GLOBAL_ENUM_CONSTANT(ERR_LOCKED); ///< resource is locked
BIND_GLOBAL_ENUM_CONSTANT(ERR_TIMEOUT);
BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_CONNECT); // (25)
BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_RESOLVE);
BIND_GLOBAL_ENUM_CONSTANT(ERR_CONNECTION_ERROR);
BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_ACQUIRE_RESOURCE);
BIND_GLOBAL_ENUM_CONSTANT(ERR_CANT_FORK);
BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_DATA); // (30)
BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_PARAMETER);
BIND_GLOBAL_ENUM_CONSTANT(ERR_ALREADY_EXISTS);
BIND_GLOBAL_ENUM_CONSTANT(ERR_DOES_NOT_EXIST);
BIND_GLOBAL_ENUM_CONSTANT(ERR_DATABASE_CANT_READ);
BIND_GLOBAL_ENUM_CONSTANT(ERR_DATABASE_CANT_WRITE); // (35)
BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_DATA); ///< Data passed is invalid
BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_PARAMETER); ///< Parameter passed is invalid
BIND_GLOBAL_ENUM_CONSTANT(ERR_ALREADY_EXISTS); ///< When adding ), item already exists
BIND_GLOBAL_ENUM_CONSTANT(ERR_DOES_NOT_EXIST); ///< When retrieving/erasing ), it item does not exist
BIND_GLOBAL_ENUM_CONSTANT(ERR_DATABASE_CANT_READ); ///< database is full
BIND_GLOBAL_ENUM_CONSTANT(ERR_DATABASE_CANT_WRITE); ///< database is full
BIND_GLOBAL_ENUM_CONSTANT(ERR_COMPILATION_FAILED);
BIND_GLOBAL_ENUM_CONSTANT(ERR_METHOD_NOT_FOUND);
BIND_GLOBAL_ENUM_CONSTANT(ERR_LINK_FAILED);
BIND_GLOBAL_ENUM_CONSTANT(ERR_SCRIPT_FAILED);
BIND_GLOBAL_ENUM_CONSTANT(ERR_CYCLIC_LINK); // (40)
BIND_GLOBAL_ENUM_CONSTANT(ERR_INVALID_DECLARATION);
BIND_GLOBAL_ENUM_CONSTANT(ERR_DUPLICATE_SYMBOL);
BIND_GLOBAL_ENUM_CONSTANT(ERR_PARSE_ERROR);
BIND_GLOBAL_ENUM_CONSTANT(ERR_CYCLIC_LINK);
BIND_GLOBAL_ENUM_CONSTANT(ERR_BUSY);
BIND_GLOBAL_ENUM_CONSTANT(ERR_SKIP); // (45)
BIND_GLOBAL_ENUM_CONSTANT(ERR_HELP);
BIND_GLOBAL_ENUM_CONSTANT(ERR_BUG);
BIND_GLOBAL_ENUM_CONSTANT(ERR_PRINTER_ON_FIRE);
BIND_GLOBAL_ENUM_CONSTANT(ERR_HELP); ///< user requested help!!
BIND_GLOBAL_ENUM_CONSTANT(ERR_BUG); ///< a bug in the software certainly happened ), due to a double check failing or unexpected behavior.
BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_NONE);
BIND_GLOBAL_ENUM_CONSTANT(PROPERTY_HINT_RANGE);
@@ -687,35 +630,33 @@ void register_global_constants() {
}
void unregister_global_constants() {
_global_constants.clear();
}
int GlobalConstants::get_global_constant_count() {
return _global_constants.size();
}
#ifdef DEBUG_METHODS_ENABLED
StringName GlobalConstants::get_global_constant_enum(int p_idx) {
return _global_constants[p_idx].enum_name;
}
bool GlobalConstants::get_ignore_value_in_docs(int p_idx) {
return _global_constants[p_idx].ignore_value_in_docs;
return _global_constants[p_idx].enum_name;
}
#else
StringName GlobalConstants::get_global_constant_enum(int p_idx) {
return StringName();
}
bool GlobalConstants::get_ignore_value_in_docs(int p_idx) {
return false;
return StringName();
}
#endif
const char *GlobalConstants::get_global_constant_name(int p_idx) {
return _global_constants[p_idx].name;
}
int GlobalConstants::get_global_constant_value(int p_idx) {
return _global_constants[p_idx].value;
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -37,7 +37,6 @@ class GlobalConstants {
public:
static int get_global_constant_count();
static StringName get_global_constant_enum(int p_idx);
static bool get_ignore_value_in_docs(int p_idx);
static const char *get_global_constant_name(int p_idx);
static int get_global_constant_value(int p_idx);
};

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -53,12 +53,13 @@
* @param RELATIONSHIP Relationship at which the hash table is resized. if amount of elements is RELATIONSHIP
* times bigger than the hash table, table is resized to solve this condition. if RELATIONSHIP is zero, table is always MIN_HASH_TABLE_POWER.
*
*/
*/
template <class TKey, class TData, class Hasher = HashMapHasherDefault, class Comparator = HashMapComparatorDefault<TKey>, uint8_t MIN_HASH_TABLE_POWER = 3, uint8_t RELATIONSHIP = 8>
class HashMap {
public:
struct Pair {
TKey key;
TData data;
@@ -75,7 +76,7 @@ public:
uint32_t hash;
Element *next;
Element() { next = nullptr; }
Element() { next = 0; }
Pair pair;
public:
@@ -98,27 +99,29 @@ private:
uint32_t elements;
void make_hash_table() {
ERR_FAIL_COND(hash_table);
hash_table = memnew_arr(Element *, (1 << MIN_HASH_TABLE_POWER));
hash_table_power = MIN_HASH_TABLE_POWER;
elements = 0;
for (int i = 0; i < (1 << MIN_HASH_TABLE_POWER); i++) {
hash_table[i] = nullptr;
}
for (int i = 0; i < (1 << MIN_HASH_TABLE_POWER); i++)
hash_table[i] = 0;
}
void erase_hash_table() {
ERR_FAIL_COND_MSG(elements, "Cannot erase hash table if there are still elements inside.");
ERR_FAIL_COND(elements);
memdelete_arr(hash_table);
hash_table = nullptr;
hash_table = 0;
hash_table_power = 0;
elements = 0;
}
void check_hash_table() {
int new_hash_table_power = -1;
if ((int)elements > ((1 << hash_table_power) * RELATIONSHIP)) {
@@ -126,60 +129,70 @@ private:
new_hash_table_power = hash_table_power + 1;
while ((int)elements > ((1 << new_hash_table_power) * RELATIONSHIP)) {
new_hash_table_power++;
}
} else if ((hash_table_power > (int)MIN_HASH_TABLE_POWER) && ((int)elements < ((1 << (hash_table_power - 1)) * RELATIONSHIP))) {
/* rehash down */
new_hash_table_power = hash_table_power - 1;
while ((int)elements < ((1 << (new_hash_table_power - 1)) * RELATIONSHIP)) {
new_hash_table_power--;
}
if (new_hash_table_power < (int)MIN_HASH_TABLE_POWER) {
if (new_hash_table_power < (int)MIN_HASH_TABLE_POWER)
new_hash_table_power = MIN_HASH_TABLE_POWER;
}
}
if (new_hash_table_power == -1) {
if (new_hash_table_power == -1)
return;
Element **new_hash_table = memnew_arr(Element *, ((uint64_t)1 << new_hash_table_power));
if (!new_hash_table) {
ERR_PRINT("Out of Memory");
return;
}
Element **new_hash_table = memnew_arr(Element *, ((uint64_t)1 << new_hash_table_power));
ERR_FAIL_COND_MSG(!new_hash_table, "Out of memory.");
for (int i = 0; i < (1 << new_hash_table_power); i++) {
new_hash_table[i] = nullptr;
new_hash_table[i] = 0;
}
if (hash_table) {
for (int i = 0; i < (1 << hash_table_power); i++) {
while (hash_table[i]) {
Element *se = hash_table[i];
hash_table[i] = se->next;
int new_pos = se->hash & ((1 << new_hash_table_power) - 1);
se->next = new_hash_table[new_pos];
new_hash_table[new_pos] = se;
}
for (int i = 0; i < (1 << hash_table_power); i++) {
while (hash_table[i]) {
Element *se = hash_table[i];
hash_table[i] = se->next;
int new_pos = se->hash & ((1 << new_hash_table_power) - 1);
se->next = new_hash_table[new_pos];
new_hash_table[new_pos] = se;
}
memdelete_arr(hash_table);
}
if (hash_table)
memdelete_arr(hash_table);
hash_table = new_hash_table;
hash_table_power = new_hash_table_power;
}
/* I want to have only one function.. */
_FORCE_INLINE_ const Element *get_element(const TKey &p_key) const {
uint32_t hash = Hasher::hash(p_key);
uint32_t index = hash & ((1 << hash_table_power) - 1);
Element *e = hash_table[index];
while (e) {
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) {
/* the pair exists in this hashtable, so just update data */
return e;
}
@@ -187,19 +200,19 @@ private:
e = e->next;
}
return nullptr;
return NULL;
}
Element *create_element(const TKey &p_key) {
/* if element doesn't exist, create it */
Element *e = memnew(Element);
ERR_FAIL_COND_V_MSG(!e, nullptr, "Out of memory.");
ERR_FAIL_COND_V(!e, NULL); /* out of memory */
uint32_t hash = Hasher::hash(p_key);
uint32_t index = hash & ((1 << hash_table_power) - 1);
e->next = hash_table[index];
e->hash = hash;
e->pair.key = p_key;
e->pair.data = TData();
hash_table[index] = e;
elements++;
@@ -208,26 +221,27 @@ private:
}
void copy_from(const HashMap &p_t) {
if (&p_t == this) {
if (&p_t == this)
return; /* much less bother with that */
}
clear();
if (!p_t.hash_table || p_t.hash_table_power == 0) {
if (!p_t.hash_table || p_t.hash_table_power == 0)
return; /* not copying from empty table */
}
hash_table = memnew_arr(Element *, (uint64_t)1 << p_t.hash_table_power);
hash_table_power = p_t.hash_table_power;
elements = p_t.elements;
for (int i = 0; i < (1 << p_t.hash_table_power); i++) {
hash_table[i] = nullptr;
hash_table[i] = NULL;
const Element *e = p_t.hash_table[i];
while (e) {
Element *le = memnew(Element); /* local element */
*le = *e; /* copy data */
@@ -247,20 +261,20 @@ public:
}
Element *set(const Pair &p_pair) {
Element *e = nullptr;
if (!hash_table) {
Element *e = NULL;
if (!hash_table)
make_hash_table(); // if no table, make one
} else {
else
e = const_cast<Element *>(get_element(p_pair.key));
}
/* if we made it up to here, the pair doesn't exist, create and assign */
if (!e) {
e = create_element(p_pair.key);
if (!e) {
return nullptr;
}
if (!e)
return NULL;
check_hash_table(); // perform mantenience routine
}
@@ -269,7 +283,8 @@ public:
}
bool has(const TKey &p_key) const {
return getptr(p_key) != nullptr;
return getptr(p_key) != NULL;
}
/**
@@ -279,14 +294,16 @@ public:
*/
const TData &get(const TKey &p_key) const {
const TData *res = getptr(p_key);
CRASH_COND_MSG(!res, "Map key not found.");
ERR_FAIL_COND_V(!res, *res);
return *res;
}
TData &get(const TKey &p_key) {
TData *res = getptr(p_key);
CRASH_COND_MSG(!res, "Map key not found.");
ERR_FAIL_COND_V(!res, *res);
return *res;
}
@@ -296,31 +313,29 @@ public:
*/
_FORCE_INLINE_ TData *getptr(const TKey &p_key) {
if (unlikely(!hash_table)) {
return nullptr;
}
if (unlikely(!hash_table))
return NULL;
Element *e = const_cast<Element *>(get_element(p_key));
if (e) {
if (e)
return &e->pair.data;
}
return nullptr;
return NULL;
}
_FORCE_INLINE_ const TData *getptr(const TKey &p_key) const {
if (unlikely(!hash_table)) {
return nullptr;
}
if (unlikely(!hash_table))
return NULL;
const Element *e = const_cast<Element *>(get_element(p_key));
if (e) {
if (e)
return &e->pair.data;
}
return nullptr;
return NULL;
}
/**
@@ -330,9 +345,9 @@ public:
template <class C>
_FORCE_INLINE_ TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) {
if (unlikely(!hash_table)) {
return nullptr;
}
if (unlikely(!hash_table))
return NULL;
uint32_t hash = p_custom_hash;
uint32_t index = hash & ((1 << hash_table_power) - 1);
@@ -340,8 +355,10 @@ public:
Element *e = hash_table[index];
while (e) {
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) {
/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
}
@@ -349,14 +366,14 @@ public:
e = e->next;
}
return nullptr;
return NULL;
}
template <class C>
_FORCE_INLINE_ const TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) const {
if (unlikely(!hash_table)) {
if (unlikely(!hash_table))
return NULL;
}
uint32_t hash = p_custom_hash;
uint32_t index = hash & ((1 << hash_table_power) - 1);
@@ -364,8 +381,10 @@ public:
const Element *e = hash_table[index];
while (e) {
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_custom_key)) {
/* the pair exists in this hashtable, so just update data */
return &e->pair.data;
}
@@ -381,19 +400,22 @@ public:
*/
bool erase(const TKey &p_key) {
if (unlikely(!hash_table)) {
if (unlikely(!hash_table))
return false;
}
uint32_t hash = Hasher::hash(p_key);
uint32_t index = hash & ((1 << hash_table_power) - 1);
Element *e = hash_table[index];
Element *p = nullptr;
Element *p = NULL;
while (e) {
/* checking hash first avoids comparing key, which may take longer */
if (e->hash == hash && Comparator::compare(e->pair.key, p_key)) {
if (p) {
p->next = e->next;
} else {
//begin of list
@@ -403,11 +425,10 @@ public:
memdelete(e);
elements--;
if (elements == 0) {
if (elements == 0)
erase_hash_table();
} else {
else
check_hash_table();
}
return true;
}
@@ -424,15 +445,15 @@ public:
}
inline TData &operator[](const TKey &p_key) { //assignment
Element *e = nullptr;
if (!hash_table) {
Element *e = NULL;
if (!hash_table)
make_hash_table(); // if no table, make one
} else {
else
e = const_cast<Element *>(get_element(p_key));
}
/* if we made it up to here, the pair doesn't exist, create */
if (!e) {
e = create_element(p_key);
CRASH_COND(!e);
check_hash_table(); // perform mantenience routine
@@ -454,16 +475,17 @@ public:
*
* print( *k );
* }
*
*/
*
*/
const TKey *next(const TKey *p_key) const {
if (unlikely(!hash_table)) {
return nullptr;
}
if (unlikely(!hash_table))
return NULL;
if (!p_key) { /* get the first key */
for (int i = 0; i < (1 << hash_table_power); i++) {
if (hash_table[i]) {
return &hash_table[i]->pair.key;
}
@@ -472,7 +494,8 @@ public:
} else { /* get the next key */
const Element *e = get_element(*p_key);
ERR_FAIL_COND_V_MSG(!e, nullptr, "Invalid key supplied.");
ERR_FAIL_COND_V(!e, NULL); /* invalid key supplied */
if (e->next) {
/* if there is a "next" in the list, return that */
return &e->next->pair.key;
@@ -481,6 +504,7 @@ public:
uint32_t index = e->hash & ((1 << hash_table_power) - 1);
index++;
for (int i = index; i < (1 << hash_table_power); i++) {
if (hash_table[i]) {
return &hash_table[i]->pair.key;
}
@@ -490,22 +514,27 @@ public:
/* nothing found, was at end */
}
return nullptr; /* nothing found */
return NULL; /* nothing found */
}
inline unsigned int size() const {
return elements;
}
inline bool empty() const {
return elements == 0;
}
void clear() {
/* clean up */
if (hash_table) {
for (int i = 0; i < (1 << hash_table_power); i++) {
while (hash_table[i]) {
Element *e = hash_table[i];
hash_table[i] = e->next;
memdelete(e);
@@ -515,26 +544,27 @@ public:
memdelete_arr(hash_table);
}
hash_table = nullptr;
hash_table = 0;
hash_table_power = 0;
elements = 0;
}
void operator=(const HashMap &p_table) {
copy_from(p_table);
}
HashMap() {
hash_table = nullptr;
hash_table = NULL;
elements = 0;
hash_table_power = 0;
}
void get_key_value_ptr_array(const Pair **p_pairs) const {
if (unlikely(!hash_table)) {
if (unlikely(!hash_table))
return;
}
for (int i = 0; i < (1 << hash_table_power); i++) {
Element *e = hash_table[i];
while (e) {
*p_pairs = &e->pair;
@@ -545,10 +575,10 @@ public:
}
void get_key_list(List<TKey> *p_keys) const {
if (unlikely(!hash_table)) {
if (unlikely(!hash_table))
return;
}
for (int i = 0; i < (1 << hash_table_power); i++) {
Element *e = hash_table[i];
while (e) {
p_keys->push_back(e->pair.key);
@@ -558,7 +588,8 @@ public:
}
HashMap(const HashMap &p_table) {
hash_table = nullptr;
hash_table = NULL;
elements = 0;
hash_table_power = 0;
@@ -566,6 +597,7 @@ public:
}
~HashMap() {
clear();
}
};

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -48,28 +48,29 @@
* @return 32-bits hashcode
*/
static inline uint32_t hash_djb2(const char *p_cstr) {
const unsigned char *chr = (const unsigned char *)p_cstr;
uint32_t hash = 5381;
uint32_t c;
while ((c = *chr++)) {
while ((c = *chr++))
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
}
return hash;
}
static inline uint32_t hash_djb2_buffer(const uint8_t *p_buff, int p_len, uint32_t p_prev = 5381) {
uint32_t hash = p_prev;
for (int i = 0; i < p_len; i++) {
for (int i = 0; i < p_len; i++)
hash = ((hash << 5) + hash) + p_buff[i]; /* hash * 33 + c */
}
return hash;
}
static inline uint32_t hash_djb2_one_32(uint32_t p_in, uint32_t p_prev = 5381) {
return ((p_prev << 5) + p_prev) + p_in;
}
@@ -91,19 +92,19 @@ static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381)
} u;
// Normalize +/- 0.0 and NaN values so they hash the same.
if (p_in == 0.0f) {
if (p_in == 0.0f)
u.d = 0.0;
} else if (Math::is_nan(p_in)) {
else if (Math::is_nan(p_in))
u.d = Math_NAN;
} else {
else
u.d = p_in;
}
return ((p_prev << 5) + p_prev) + hash_one_uint64(u.i);
}
template <class T>
static inline uint32_t make_uint32_t(T p_in) {
union {
T t;
uint32_t _u32;
@@ -114,11 +115,13 @@ static inline uint32_t make_uint32_t(T p_in) {
}
static inline uint64_t hash_djb2_one_64(uint64_t p_in, uint64_t p_prev = 5381) {
return ((p_prev << 5) + p_prev) + p_in;
}
template <class T>
static inline uint64_t make_uint64_t(T p_in) {
union {
T t;
uint64_t _u64;
@@ -130,6 +133,7 @@ static inline uint64_t make_uint64_t(T p_in) {
}
struct HashMapHasherDefault {
static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); }
static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); }
static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); }

File diff suppressed because it is too large Load Diff

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -42,23 +42,18 @@
* Image storage class. This is used to store an image in user memory, as well as
* providing some basic methods for image manipulation.
* Images can be loaded from a file, or registered into the Render object as textures.
*/
*/
class Image;
typedef Error (*SavePNGFunc)(const String &p_path, const Ref<Image> &p_img);
typedef PoolVector<uint8_t> (*SavePNGBufferFunc)(const Ref<Image> &p_img);
typedef Ref<Image> (*ImageMemLoadFunc)(const uint8_t *p_png, int p_size);
typedef Error (*SaveEXRFunc)(const String &p_path, const Ref<Image> &p_img, bool p_grayscale);
class Image : public Resource {
GDCLASS(Image, Resource);
public:
static SavePNGFunc save_png_func;
static SaveEXRFunc save_exr_func;
static SavePNGBufferFunc save_png_buffer_func;
enum {
MAX_WIDTH = 16384, // force a limit somehow
@@ -114,7 +109,6 @@ public:
INTERPOLATE_BILINEAR,
INTERPOLATE_CUBIC,
INTERPOLATE_TRILINEAR,
INTERPOLATE_LANCZOS,
/* INTERPOLATE_TRICUBIC, */
/* INTERPOLATE GAUSS */
};
@@ -124,7 +118,6 @@ public:
COMPRESS_SOURCE_SRGB,
COMPRESS_SOURCE_NORMAL,
COMPRESS_SOURCE_LAYERED,
COMPRESS_SOURCE_MAX,
};
//some functions provided by something else
@@ -132,8 +125,6 @@ public:
static ImageMemLoadFunc _png_mem_loader_func;
static ImageMemLoadFunc _jpg_mem_loader_func;
static ImageMemLoadFunc _webp_mem_loader_func;
static ImageMemLoadFunc _tga_mem_loader_func;
static ImageMemLoadFunc _bmp_mem_loader_func;
static void (*_image_compress_bc_func)(Image *, float, CompressSource p_source);
static void (*_image_compress_bptc_func)(Image *, float p_lossy_quality, CompressSource p_source);
@@ -148,11 +139,10 @@ public:
static void (*_image_decompress_etc1)(Image *);
static void (*_image_decompress_etc2)(Image *);
static PoolVector<uint8_t> (*webp_lossy_packer)(const Ref<Image> &p_image, float p_quality);
static PoolVector<uint8_t> (*webp_lossless_packer)(const Ref<Image> &p_image);
static Ref<Image> (*webp_unpacker)(const PoolVector<uint8_t> &p_buffer);
static PoolVector<uint8_t> (*png_packer)(const Ref<Image> &p_image);
static Ref<Image> (*png_unpacker)(const PoolVector<uint8_t> &p_buffer);
static PoolVector<uint8_t> (*lossy_packer)(const Ref<Image> &p_image, float p_quality);
static Ref<Image> (*lossy_unpacker)(const PoolVector<uint8_t> &p_buffer);
static PoolVector<uint8_t> (*lossless_packer)(const Ref<Image> &p_image);
static Ref<Image> (*lossless_unpacker)(const PoolVector<uint8_t> &p_buffer);
PoolVector<uint8_t>::Write write_lock;
@@ -226,8 +216,10 @@ public:
/**
* Resize the image, using the preferred interpolation method.
* Indexed-Color images always use INTERPOLATE_NEAREST.
*/
void resize_to_po2(bool p_square = false, Interpolation p_interpolation = INTERPOLATE_BILINEAR);
void resize_to_po2(bool p_square = false);
void resize(int p_width, int p_height, Interpolation p_interpolation = INTERPOLATE_BILINEAR);
void shrink_x2();
void expand_x2_hq2x();
@@ -265,8 +257,6 @@ public:
Error load(const String &p_path);
Error save_png(const String &p_path) const;
PoolVector<uint8_t> save_png_to_buffer() const;
Error save_exr(const String &p_path, bool p_grayscale) const;
/**
* create an empty image
@@ -305,8 +295,7 @@ public:
COMPRESS_PVRTC4,
COMPRESS_ETC,
COMPRESS_ETC2,
COMPRESS_BPTC,
COMPRESS_MAX,
COMPRESS_BPTC
};
Error compress(CompressMode p_mode = COMPRESS_S3TC, CompressSource p_source = COMPRESS_SOURCE_GENERIC, float p_lossy_quality = 0.7);
@@ -336,8 +325,6 @@ public:
Error load_png_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_jpg_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_webp_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_tga_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_bmp_from_buffer(const PoolVector<uint8_t> &p_array);
Image(const uint8_t *p_mem_png_jpg, int p_len = -1);
Image(const char **p_xpm);
@@ -362,11 +349,11 @@ public:
Color get_pixelv(const Point2 &p_src) const;
Color get_pixel(int p_x, int p_y) const;
void set_pixelv(const Point2 &p_dst, const Color &p_color);
void set_pixelv(const Point2 &p_dest, const Color &p_color);
void set_pixel(int p_x, int p_y, const Color &p_color);
void copy_internals_from(const Ref<Image> &p_image) {
ERR_FAIL_COND_MSG(p_image.is_null(), "It's not a reference to a valid Image object.");
ERR_FAIL_COND(p_image.is_null());
format = p_image->format;
width = p_image->width;
height = p_image->height;

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,61 +30,33 @@
#include "input_map.h"
#include "core/os/input.h"
#include "core/os/keyboard.h"
#include "core/project_settings.h"
InputMap *InputMap::singleton = nullptr;
InputMap *InputMap::singleton = NULL;
int InputMap::ALL_DEVICES = -1;
void InputMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions);
ClassDB::bind_method(D_METHOD("add_action", "action", "deadzone"), &InputMap::add_action, DEFVAL(0.5f));
ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action);
ClassDB::bind_method(D_METHOD("action_set_deadzone", "action", "deadzone"), &InputMap::action_set_deadzone);
ClassDB::bind_method(D_METHOD("action_get_deadzone", "action"), &InputMap::action_get_deadzone);
ClassDB::bind_method(D_METHOD("action_add_event", "action", "event"), &InputMap::action_add_event);
ClassDB::bind_method(D_METHOD("action_has_event", "action", "event"), &InputMap::action_has_event);
ClassDB::bind_method(D_METHOD("action_erase_event", "action", "event"), &InputMap::action_erase_event);
ClassDB::bind_method(D_METHOD("action_erase_events", "action"), &InputMap::action_erase_events);
ClassDB::bind_method(D_METHOD("get_action_list", "action"), &InputMap::_get_action_list);
ClassDB::bind_method(D_METHOD("event_is_action", "event", "action", "exact_match"), &InputMap::event_is_action, DEFVAL(false));
ClassDB::bind_method(D_METHOD("event_is_action", "event", "action"), &InputMap::event_is_action);
ClassDB::bind_method(D_METHOD("load_from_globals"), &InputMap::load_from_globals);
}
/**
* Returns an nonexistent action error message with a suggestion of the closest
* matching action name (if possible).
*/
String InputMap::suggest_actions(const StringName &p_action) const {
List<StringName> actions = get_actions();
StringName closest_action;
float closest_similarity = 0.0;
// Find the most action with the most similar name.
for (List<StringName>::Element *E = actions.front(); E; E = E->next()) {
const float similarity = String(E->get()).similarity(p_action);
if (similarity > closest_similarity) {
closest_action = E->get();
closest_similarity = similarity;
}
}
String error_message = vformat("The InputMap action \"%s\" doesn't exist.", p_action);
if (closest_similarity >= 0.4) {
// Only include a suggestion in the error message if it's similar enough.
error_message += vformat(" Did you mean \"%s\"?", closest_action);
}
return error_message;
}
void InputMap::add_action(const StringName &p_action, float p_deadzone) {
ERR_FAIL_COND_MSG(input_map.has(p_action), "InputMap already has action \"" + String(p_action) + "\".");
ERR_FAIL_COND(input_map.has(p_action));
input_map[p_action] = Action();
static int last_id = 1;
input_map[p_action].id = last_id;
@@ -93,19 +65,20 @@ void InputMap::add_action(const StringName &p_action, float p_deadzone) {
}
void InputMap::erase_action(const StringName &p_action) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));
ERR_FAIL_COND(!input_map.has(p_action));
input_map.erase(p_action);
}
Array InputMap::_get_actions() {
Array ret;
List<StringName> actions = get_actions();
if (actions.empty()) {
if (actions.empty())
return ret;
}
for (const List<StringName>::Element *E = actions.front(); E; E = E->next()) {
ret.push_back(E->get());
}
@@ -113,6 +86,7 @@ Array InputMap::_get_actions() {
}
List<StringName> InputMap::get_actions() const {
List<StringName> actions = List<StringName>();
if (input_map.empty()) {
return actions;
@@ -125,10 +99,10 @@ List<StringName> InputMap::get_actions() const {
return actions;
}
List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength) const {
ERR_FAIL_COND_V(!p_event.is_valid(), nullptr);
List<Ref<InputEvent> >::Element *InputMap::_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength) const {
for (List<Ref<InputEvent> >::Element *E = p_action.inputs.front(); E; E = E->next()) {
for (List<Ref<InputEvent>>::Element *E = p_action.inputs.front(); E; E = E->next()) {
const Ref<InputEvent> e = E->get();
//if (e.type != Ref<InputEvent>::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here?
@@ -136,73 +110,66 @@ List<Ref<InputEvent>>::Element *InputMap::_find_event(Action &p_action, const Re
int device = e->get_device();
if (device == ALL_DEVICES || device == p_event->get_device()) {
if (p_exact_match && e->shortcut_match(p_event)) {
return E;
} else if (!p_exact_match && e->action_match(p_event, p_pressed, p_strength, p_raw_strength, p_action.deadzone)) {
if (e->action_match(p_event, p_pressed, p_strength, p_action.deadzone)) {
return E;
}
}
}
return nullptr;
return NULL;
}
bool InputMap::has_action(const StringName &p_action) const {
return input_map.has(p_action);
}
float InputMap::action_get_deadzone(const StringName &p_action) {
ERR_FAIL_COND_V_MSG(!input_map.has(p_action), 0.0f, suggest_actions(p_action));
return input_map[p_action].deadzone;
}
void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));
ERR_FAIL_COND(!input_map.has(p_action));
input_map[p_action].deadzone = p_deadzone;
}
void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object.");
ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));
if (_find_event(input_map[p_action], p_event, true)) {
return; // Already added.
}
ERR_FAIL_COND(p_event.is_null());
ERR_FAIL_COND(!input_map.has(p_action));
if (_find_event(input_map[p_action], p_event))
return; //already gots
input_map[p_action].inputs.push_back(p_event);
}
bool InputMap::action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, suggest_actions(p_action));
return (_find_event(input_map[p_action], p_event, true) != nullptr);
ERR_FAIL_COND_V(!input_map.has(p_action), false);
return (_find_event(input_map[p_action], p_event) != NULL);
}
void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));
List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event, true);
if (E) {
ERR_FAIL_COND(!input_map.has(p_action));
List<Ref<InputEvent> >::Element *E = _find_event(input_map[p_action], p_event);
if (E)
input_map[p_action].inputs.erase(E);
if (Input::get_singleton()->is_action_pressed(p_action)) {
Input::get_singleton()->action_release(p_action);
}
}
}
void InputMap::action_erase_events(const StringName &p_action) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));
ERR_FAIL_COND(!input_map.has(p_action));
input_map[p_action].inputs.clear();
}
Array InputMap::_get_action_list(const StringName &p_action) {
Array ret;
const List<Ref<InputEvent>> *al = get_action_list(p_action);
const List<Ref<InputEvent> > *al = get_action_list(p_action);
if (al) {
for (const List<Ref<InputEvent>>::Element *E = al->front(); E; E = E->next()) {
for (const List<Ref<InputEvent> >::Element *E = al->front(); E; E = E->next()) {
ret.push_back(E->get());
}
}
@@ -210,49 +177,43 @@ Array InputMap::_get_action_list(const StringName &p_action) {
return ret;
}
const List<Ref<InputEvent>> *InputMap::get_action_list(const StringName &p_action) {
const List<Ref<InputEvent> > *InputMap::get_action_list(const StringName &p_action) {
const Map<StringName, Action>::Element *E = input_map.find(p_action);
if (!E) {
return nullptr;
}
if (!E)
return NULL;
return &E->get().inputs;
}
bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match) const {
return event_get_action_status(p_event, p_action, p_exact_match);
bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action) const {
return event_get_action_status(p_event, p_action);
}
bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength) const {
bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed, float *p_strength) const {
Map<StringName, Action>::Element *E = input_map.find(p_action);
ERR_FAIL_COND_V_MSG(!E, false, suggest_actions(p_action));
if (!E) {
ERR_EXPLAIN("Request for nonexistent InputMap action: " + String(p_action));
ERR_FAIL_COND_V(!E, false);
}
Ref<InputEventAction> input_event_action = p_event;
if (input_event_action.is_valid()) {
bool pressed = input_event_action->is_pressed();
if (p_pressed != nullptr) {
*p_pressed = pressed;
}
if (p_strength != nullptr) {
*p_strength = pressed ? input_event_action->get_strength() : 0.0f;
}
if (p_pressed != NULL)
*p_pressed = input_event_action->is_pressed();
if (p_strength != NULL)
*p_strength = (*p_pressed) ? 1.0f : 0.0f;
return input_event_action->get_action() == p_action;
}
bool pressed;
float strength;
float raw_strength;
List<Ref<InputEvent>>::Element *event = _find_event(E->get(), p_event, p_exact_match, &pressed, &strength, &raw_strength);
if (event != nullptr) {
if (p_pressed != nullptr) {
List<Ref<InputEvent> >::Element *event = _find_event(E->get(), p_event, &pressed, &strength);
if (event != NULL) {
if (p_pressed != NULL)
*p_pressed = pressed;
}
if (p_strength != nullptr) {
if (p_strength != NULL)
*p_strength = strength;
}
if (p_raw_strength != nullptr) {
*p_raw_strength = raw_strength;
}
return true;
} else {
return false;
@@ -264,6 +225,7 @@ const Map<StringName, InputMap::Action> &InputMap::get_action_map() const {
}
void InputMap::load_from_globals() {
input_map.clear();
List<PropertyInfo> pinfo;
@@ -272,9 +234,8 @@ void InputMap::load_from_globals() {
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
if (!pi.name.begins_with("input/")) {
if (!pi.name.begins_with("input/"))
continue;
}
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
@@ -285,15 +246,15 @@ void InputMap::load_from_globals() {
add_action(name, deadzone);
for (int i = 0; i < events.size(); i++) {
Ref<InputEvent> event = events[i];
if (event.is_null()) {
if (event.is_null())
continue;
}
action_add_event(name, event);
}
}
}
void InputMap::load_default() {
Ref<InputEventKey> key;
add_action("ui_accept");
@@ -369,9 +330,12 @@ void InputMap::load_default() {
key.instance();
key->set_scancode(KEY_END);
action_add_event("ui_end", key);
//set("display/window/handheld/orientation", "landscape");
}
InputMap::InputMap() {
ERR_FAIL_COND_MSG(singleton, "Singleton in InputMap already exist.");
ERR_FAIL_COND(singleton);
singleton = this;
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -35,18 +35,19 @@
#include "core/os/input_event.h"
class InputMap : public Object {
GDCLASS(InputMap, Object);
public:
/**
* A special value used to signify that a given Action can be triggered by any device
*/
* A special value used to signify that a given Action can be triggered by any device
*/
static int ALL_DEVICES;
struct Action {
int id;
float deadzone;
List<Ref<InputEvent>> inputs;
List<Ref<InputEvent> > inputs;
};
private:
@@ -54,7 +55,7 @@ private:
mutable Map<StringName, Action> input_map;
List<Ref<InputEvent>>::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match = false, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const;
List<Ref<InputEvent> >::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool *p_pressed = NULL, float *p_strength = NULL) const;
Array _get_action_list(const StringName &p_action);
Array _get_actions();
@@ -70,23 +71,20 @@ public:
void add_action(const StringName &p_action, float p_deadzone = 0.5);
void erase_action(const StringName &p_action);
float action_get_deadzone(const StringName &p_action);
void action_set_deadzone(const StringName &p_action, float p_deadzone);
void action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event);
bool action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event);
void action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event);
void action_erase_events(const StringName &p_action);
const List<Ref<InputEvent>> *get_action_list(const StringName &p_action);
bool event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match = false) const;
bool event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match = false, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const;
const List<Ref<InputEvent> > *get_action_list(const StringName &p_action);
bool event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action) const;
bool event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool *p_pressed = NULL, float *p_strength = NULL) const;
const Map<StringName, Action> &get_action_map() const;
void load_from_globals();
void load_default();
String suggest_actions(const StringName &p_action) const;
InputMap();
};

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env python
Import("env")
Import('env')
env.add_source_files(env.core_sources, "*.cpp")

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,6 +31,7 @@
#include "compression.h"
#include "core/io/zip_io.h"
#include "core/os/copymem.h"
#include "core/project_settings.h"
#include "thirdparty/misc/fastlz.h"
@@ -39,12 +40,14 @@
#include <zstd.h>
int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode) {
switch (p_mode) {
case MODE_FASTLZ: {
if (p_src_size < 16) {
uint8_t src[16];
memset(&src[p_src_size], 0, 16 - p_src_size);
memcpy(src, p_src, p_src_size);
zeromem(&src[p_src_size], 16 - p_src_size);
copymem(src, p_src, p_src_size);
return fastlz_compress(src, 16, p_dst);
} else {
return fastlz_compress(p_src, p_src_size, p_dst);
@@ -53,6 +56,7 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
@@ -61,9 +65,8 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
strm.opaque = Z_NULL;
int level = p_mode == MODE_DEFLATE ? zlib_level : gzip_level;
int err = deflateInit2(&strm, level, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY);
if (err != Z_OK) {
if (err != Z_OK)
return -1;
}
strm.avail_in = p_src_size;
int aout = deflateBound(&strm, p_src_size);
@@ -94,17 +97,19 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size,
}
int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
switch (p_mode) {
case MODE_FASTLZ: {
int ss = p_src_size + p_src_size * 6 / 100;
if (ss < 66) {
if (ss < 66)
ss = 66;
}
return ss;
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
@@ -112,14 +117,14 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
strm.zfree = zipio_free;
strm.opaque = Z_NULL;
int err = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY);
if (err != Z_OK) {
if (err != Z_OK)
return -1;
}
int aout = deflateBound(&strm, p_src_size);
deflateEnd(&strm);
return aout;
} break;
case MODE_ZSTD: {
return ZSTD_compressBound(p_src_size);
} break;
}
@@ -128,15 +133,16 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) {
}
int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode) {
switch (p_mode) {
case MODE_FASTLZ: {
int ret_size = 0;
if (p_dst_max_size < 16) {
uint8_t dst[16];
fastlz_decompress(p_src, p_src_size, dst, 16);
memcpy(p_dst, dst, p_dst_max_size);
ret_size = p_dst_max_size;
ret_size = fastlz_decompress(p_src, p_src_size, dst, 16);
copymem(p_dst, dst, p_dst_max_size);
} else {
ret_size = fastlz_decompress(p_src, p_src_size, p_dst, p_dst_max_size);
}
@@ -144,6 +150,7 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p
} break;
case MODE_DEFLATE:
case MODE_GZIP: {
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
z_stream strm;
@@ -180,98 +187,8 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p
ERR_FAIL_V(-1);
}
/**
This will handle both Gzip and Deflat streams. It will automatically allocate the output buffer into the provided p_dst_vect Vector.
This is required for compressed data who's final uncompressed size is unknown, as is the case for HTTP response bodies.
This is much slower however than using Compression::decompress because it may result in multiple full copies of the output buffer.
*/
int Compression::decompress_dynamic(PoolVector<uint8_t> *p_dst, int p_max_dst_size, const uint8_t *p_src, int p_src_size, Mode p_mode) {
int ret;
uint8_t *dst = nullptr;
int out_mark = 0;
z_stream strm;
ERR_FAIL_COND_V(p_src_size <= 0, Z_DATA_ERROR);
// This function only supports GZip and Deflate
int window_bits = p_mode == MODE_DEFLATE ? 15 : 15 + 16;
ERR_FAIL_COND_V(p_mode != MODE_DEFLATE && p_mode != MODE_GZIP, Z_ERRNO);
// Initialize the stream
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
int err = inflateInit2(&strm, window_bits);
ERR_FAIL_COND_V(err != Z_OK, -1);
// Setup the stream inputs
strm.next_in = (Bytef *)p_src;
strm.avail_in = p_src_size;
// Ensure the destination buffer is empty
p_dst->resize(0);
// decompress until deflate stream ends or end of file
do {
// Add another chunk size to the output buffer
// This forces a copy of the whole buffer
p_dst->resize(p_dst->size() + gzip_chunk);
// Get pointer to the actual output buffer
dst = p_dst->write().ptr();
// Set the stream to the new output stream
// Since it was copied, we need to reset the stream to the new buffer
strm.next_out = &(dst[out_mark]);
strm.avail_out = gzip_chunk;
// run inflate() on input until output buffer is full and needs to be resized
// or input runs out
do {
ret = inflate(&strm, Z_SYNC_FLUSH);
switch (ret) {
case Z_NEED_DICT:
ret = Z_DATA_ERROR;
FALLTHROUGH;
case Z_DATA_ERROR:
case Z_MEM_ERROR:
case Z_STREAM_ERROR:
case Z_BUF_ERROR:
if (strm.msg) {
WARN_PRINT(strm.msg);
}
(void)inflateEnd(&strm);
p_dst->resize(0);
return ret;
}
} while (strm.avail_out > 0 && strm.avail_in > 0);
out_mark += gzip_chunk;
// Encorce max output size
if (p_max_dst_size > -1 && strm.total_out > (uint64_t)p_max_dst_size) {
(void)inflateEnd(&strm);
p_dst->resize(0);
return Z_BUF_ERROR;
}
} while (ret != Z_STREAM_END);
// If all done successfully, resize the output if it's larger than the actual output
if (ret == Z_STREAM_END && (unsigned long)p_dst->size() > strm.total_out) {
p_dst->resize(strm.total_out);
}
// clean up and return
(void)inflateEnd(&strm);
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
int Compression::zlib_level = Z_DEFAULT_COMPRESSION;
int Compression::gzip_level = Z_DEFAULT_COMPRESSION;
int Compression::zstd_level = 3;
bool Compression::zstd_long_distance_matching = false;
int Compression::zstd_window_log_size = 27; // ZSTD_WINDOWLOG_LIMIT_DEFAULT
int Compression::gzip_chunk = 16384;

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,17 +31,16 @@
#ifndef COMPRESSION_H
#define COMPRESSION_H
#include "core/pool_vector.h"
#include "core/typedefs.h"
class Compression {
public:
static int zlib_level;
static int gzip_level;
static int zstd_level;
static bool zstd_long_distance_matching;
static int zstd_window_log_size;
static int gzip_chunk;
enum Mode {
MODE_FASTLZ,
@@ -53,7 +52,6 @@ public:
static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_ZSTD);
static int get_max_compressed_buffer_size(int p_src_size, Mode p_mode = MODE_ZSTD);
static int decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_ZSTD);
static int decompress_dynamic(PoolVector<uint8_t> *p_dst, int p_max_dst_size, const uint8_t *p_src, int p_src_size, Mode p_mode);
Compression();
};

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,17 +30,19 @@
#include "config_file.h"
#include "core/io/file_access_encrypted.h"
#include "core/os/file_access.h"
#include "core/os/keyboard.h"
#include "core/variant_parser.h"
PoolStringArray ConfigFile::_get_sections() const {
List<String> s;
get_sections(&s);
PoolStringArray arr;
arr.resize(s.size());
int idx = 0;
for (const List<String>::Element *E = s.front(); E; E = E->next()) {
arr.set(idx++, E->get());
}
@@ -48,12 +50,14 @@ PoolStringArray ConfigFile::_get_sections() const {
}
PoolStringArray ConfigFile::_get_section_keys(const String &p_section) const {
List<String> s;
get_section_keys(p_section, &s);
PoolStringArray arr;
arr.resize(s.size());
int idx = 0;
for (const List<String>::Element *E = s.front(); E; E = E->next()) {
arr.set(idx++, E->get());
}
@@ -61,11 +65,11 @@ PoolStringArray ConfigFile::_get_section_keys(const String &p_section) const {
}
void ConfigFile::set_value(const String &p_section, const String &p_key, const Variant &p_value) {
if (p_value.get_type() == Variant::NIL) {
//erase
if (!values.has(p_section)) {
if (!values.has(p_section))
return; // ?
}
values[p_section].erase(p_key);
if (values[p_section].empty()) {
values.erase(p_section);
@@ -80,31 +84,37 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V
}
}
Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const {
if (!values.has(p_section) || !values[p_section].has(p_key)) {
ERR_FAIL_COND_V_MSG(p_default.get_type() == Variant::NIL, Variant(),
vformat("Couldn't find the given section \"%s\" and key \"%s\", and no default was given.", p_section, p_key));
if (p_default.get_type() == Variant::NIL) {
ERR_EXPLAIN("Couldn't find the given section/key and no default was given");
ERR_FAIL_V(p_default);
}
return p_default;
}
return values[p_section][p_key];
}
bool ConfigFile::has_section(const String &p_section) const {
return values.has(p_section);
}
bool ConfigFile::has_section_key(const String &p_section, const String &p_key) const {
if (!values.has(p_section)) {
if (!values.has(p_section))
return false;
}
return values[p_section].has(p_key);
}
void ConfigFile::get_sections(List<String> *r_sections) const {
for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::ConstElement E = values.front(); E; E = E.next()) {
for (OrderedHashMap<String, OrderedHashMap<String, Variant> >::ConstElement E = values.front(); E; E = E.next()) {
r_sections->push_back(E.key());
}
}
void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) const {
ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot get keys from nonexistent section \"%s\".", p_section));
ERR_FAIL_COND(!values.has(p_section));
for (OrderedHashMap<String, Variant>::ConstElement E = values[p_section].front(); E; E = E.next()) {
r_keys->push_back(E.key());
@@ -112,79 +122,32 @@ void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys)
}
void ConfigFile::erase_section(const String &p_section) {
ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase nonexistent section \"%s\".", p_section));
values.erase(p_section);
}
void ConfigFile::erase_section_key(const String &p_section, const String &p_key) {
ERR_FAIL_COND_MSG(!values.has(p_section), vformat("Cannot erase key \"%s\" from nonexistent section \"%s\".", p_key, p_section));
ERR_FAIL_COND_MSG(!values[p_section].has(p_key), vformat("Cannot erase nonexistent key \"%s\" from section \"%s\".", p_key, p_section));
values[p_section].erase(p_key);
}
Error ConfigFile::save(const String &p_path) {
Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
if (err) {
if (file) {
if (file)
memdelete(file);
}
return err;
}
return _internal_save(file);
}
for (OrderedHashMap<String, OrderedHashMap<String, Variant> >::Element E = values.front(); E; E = E.next()) {
Error ConfigFile::save_encrypted(const String &p_path, const Vector<uint8_t> &p_key) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
if (err) {
return err;
}
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_WRITE_AES256);
if (err) {
memdelete(fae);
memdelete(f);
return err;
}
return _internal_save(fae);
}
Error ConfigFile::save_encrypted_pass(const String &p_path, const String &p_pass) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::WRITE, &err);
if (err) {
return err;
}
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_WRITE_AES256);
if (err) {
memdelete(fae);
memdelete(f);
return err;
}
return _internal_save(fae);
}
Error ConfigFile::_internal_save(FileAccess *file) {
for (OrderedHashMap<String, OrderedHashMap<String, Variant>>::Element E = values.front(); E; E = E.next()) {
if (E != values.front()) {
if (E != values.front())
file->store_string("\n");
}
file->store_string("[" + E.key() + "]\n\n");
for (OrderedHashMap<String, Variant>::Element F = E.get().front(); F; F = F.next()) {
String vstr;
VariantWriter::write_to_string(F.get(), vstr);
file->store_string(F.key().property_name_encode() + "=" + vstr + "\n");
file->store_string(F.key() + "=" + vstr + "\n");
}
}
@@ -194,71 +157,16 @@ Error ConfigFile::_internal_save(FileAccess *file) {
}
Error ConfigFile::load(const String &p_path) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
if (!f) {
return err;
}
if (!f)
return ERR_CANT_OPEN;
return _internal_load(p_path, f);
}
Error ConfigFile::load_encrypted(const String &p_path, const Vector<uint8_t> &p_key) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
if (err) {
return err;
}
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse(f, p_key, FileAccessEncrypted::MODE_READ);
if (err) {
memdelete(fae);
memdelete(f);
return err;
}
return _internal_load(p_path, fae);
}
Error ConfigFile::load_encrypted_pass(const String &p_path, const String &p_pass) {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
if (err) {
return err;
}
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
err = fae->open_and_parse_password(f, p_pass, FileAccessEncrypted::MODE_READ);
if (err) {
memdelete(fae);
memdelete(f);
return err;
}
return _internal_load(p_path, fae);
}
Error ConfigFile::_internal_load(const String &p_path, FileAccess *f) {
VariantParser::StreamFile stream;
stream.f = f;
Error err = _parse(p_path, &stream);
memdelete(f);
return err;
}
Error ConfigFile::parse(const String &p_data) {
VariantParser::StreamString stream;
stream.s = p_data;
return _parse("<string>", &stream);
}
Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream) {
String assign;
Variant value;
VariantParser::Tag next_tag;
@@ -269,15 +177,18 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
String section;
while (true) {
assign = Variant();
next_tag.fields.clear();
next_tag.name = String();
Error err = VariantParser::parse_tag_assign_eof(p_stream, lines, error_text, next_tag, assign, value, nullptr, true);
err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true);
if (err == ERR_FILE_EOF) {
memdelete(f);
return OK;
} else if (err != OK) {
ERR_PRINT(vformat("ConfigFile parse error at %s:%d: %s.", p_path, lines, error_text));
ERR_PRINTS("ConfgFile::load - " + p_path + ":" + itos(lines) + " error: " + error_text);
memdelete(f);
return err;
}
@@ -288,13 +199,13 @@ Error ConfigFile::_parse(const String &p_path, VariantParser::Stream *p_stream)
}
}
memdelete(f);
return OK;
}
void ConfigFile::clear() {
values.clear();
}
void ConfigFile::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_value", "section", "key", "value"), &ConfigFile::set_value);
ClassDB::bind_method(D_METHOD("get_value", "section", "key", "default"), &ConfigFile::get_value, DEFVAL(Variant()));
@@ -305,17 +216,10 @@ void ConfigFile::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_section_keys", "section"), &ConfigFile::_get_section_keys);
ClassDB::bind_method(D_METHOD("erase_section", "section"), &ConfigFile::erase_section);
ClassDB::bind_method(D_METHOD("erase_section_key", "section", "key"), &ConfigFile::erase_section_key);
ClassDB::bind_method(D_METHOD("load", "path"), &ConfigFile::load);
ClassDB::bind_method(D_METHOD("parse", "data"), &ConfigFile::parse);
ClassDB::bind_method(D_METHOD("save", "path"), &ConfigFile::save);
ClassDB::bind_method(D_METHOD("load_encrypted", "path", "key"), &ConfigFile::load_encrypted);
ClassDB::bind_method(D_METHOD("load_encrypted_pass", "path", "password"), &ConfigFile::load_encrypted_pass);
ClassDB::bind_method(D_METHOD("save_encrypted", "path", "key"), &ConfigFile::save_encrypted);
ClassDB::bind_method(D_METHOD("save_encrypted_pass", "path", "password"), &ConfigFile::save_encrypted_pass);
ClassDB::bind_method(D_METHOD("clear"), &ConfigFile::clear);
}
ConfigFile::ConfigFile() {
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,21 +32,16 @@
#define CONFIG_FILE_H
#include "core/ordered_hash_map.h"
#include "core/os/file_access.h"
#include "core/reference.h"
#include "core/variant_parser.h"
class ConfigFile : public Reference {
GDCLASS(ConfigFile, Reference);
OrderedHashMap<String, OrderedHashMap<String, Variant>> values;
OrderedHashMap<String, OrderedHashMap<String, Variant> > values;
PoolStringArray _get_sections() const;
PoolStringArray _get_section_keys(const String &p_section) const;
Error _internal_load(const String &p_path, FileAccess *f);
Error _internal_save(FileAccess *file);
Error _parse(const String &p_path, VariantParser::Stream *p_stream);
protected:
static void _bind_methods();
@@ -62,19 +57,11 @@ public:
void get_section_keys(const String &p_section, List<String> *r_keys) const;
void erase_section(const String &p_section);
void erase_section_key(const String &p_section, const String &p_key);
Error save(const String &p_path);
Error load(const String &p_path);
Error parse(const String &p_data);
void clear();
Error load_encrypted(const String &p_path, const Vector<uint8_t> &p_key);
Error load_encrypted_pass(const String &p_path, const String &p_pass);
Error save_encrypted(const String &p_path, const Vector<uint8_t> &p_key);
Error save_encrypted_pass(const String &p_path, const String &p_pass);
ConfigFile();
};
#endif // CONFIG_FILE_H

View File

@@ -1,55 +0,0 @@
/*************************************************************************/
/* dtls_server.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "dtls_server.h"
#include "core/os/file_access.h"
#include "core/project_settings.h"
DTLSServer *(*DTLSServer::_create)() = nullptr;
bool DTLSServer::available = false;
DTLSServer *DTLSServer::create() {
if (_create) {
return _create();
}
return nullptr;
}
bool DTLSServer::is_available() {
return available;
}
void DTLSServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("setup", "key", "certificate", "chain"), &DTLSServer::setup, DEFVAL(Ref<X509Certificate>()));
ClassDB::bind_method(D_METHOD("take_connection", "udp_peer"), &DTLSServer::take_connection);
}
DTLSServer::DTLSServer() {
}

View File

@@ -1,57 +0,0 @@
/*************************************************************************/
/* dtls_server.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef DTLS_SERVER_H
#define DTLS_SERVER_H
#include "core/io/net_socket.h"
#include "core/io/packet_peer_dtls.h"
class DTLSServer : public Reference {
GDCLASS(DTLSServer, Reference);
protected:
static DTLSServer *(*_create)();
static void _bind_methods();
static bool available;
public:
static bool is_available();
static DTLSServer *create();
virtual Error setup(Ref<CryptoKey> p_key, Ref<X509Certificate> p_cert, Ref<X509Certificate> p_ca_chain = Ref<X509Certificate>()) = 0;
virtual void stop() = 0;
virtual Ref<PacketPeerDTLS> take_connection(Ref<PacketPeerUDP> p_peer) = 0;
DTLSServer();
};
#endif // DTLS_SERVER_H

View File

@@ -0,0 +1,182 @@
/*************************************************************************/
/* file_access_buffered.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "file_access_buffered.h"
#include "core/error_macros.h"
Error FileAccessBuffered::set_error(Error p_error) const {
return (last_error = p_error);
};
void FileAccessBuffered::set_cache_size(int p_size) {
cache_size = p_size;
};
int FileAccessBuffered::get_cache_size() {
return cache_size;
};
int FileAccessBuffered::cache_data_left() const {
if (file.offset >= file.size) {
return 0;
};
if (cache.offset == -1 || file.offset < cache.offset || file.offset >= cache.offset + cache.buffer.size()) {
return read_data_block(file.offset, cache_size);
} else {
return cache.buffer.size() - (file.offset - cache.offset);
};
return 0;
};
void FileAccessBuffered::seek(size_t p_position) {
file.offset = p_position;
};
void FileAccessBuffered::seek_end(int64_t p_position) {
file.offset = file.size + p_position;
};
size_t FileAccessBuffered::get_position() const {
return file.offset;
};
size_t FileAccessBuffered::get_len() const {
return file.size;
};
bool FileAccessBuffered::eof_reached() const {
return file.offset > file.size;
};
uint8_t FileAccessBuffered::get_8() const {
ERR_FAIL_COND_V(!file.open, 0);
uint8_t byte = 0;
if (cache_data_left() >= 1) {
byte = cache.buffer[file.offset - cache.offset];
};
++file.offset;
return byte;
};
int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const {
ERR_FAIL_COND_V(!file.open, -1);
if (p_length > cache_size) {
int total_read = 0;
if (!(cache.offset == -1 || file.offset < cache.offset || file.offset >= cache.offset + cache.buffer.size())) {
int size = (cache.buffer.size() - (file.offset - cache.offset));
size = size - (size % 4);
//PoolVector<uint8_t>::Read read = cache.buffer.read();
//memcpy(p_dest, read.ptr() + (file.offset - cache.offset), size);
memcpy(p_dest, cache.buffer.ptr() + (file.offset - cache.offset), size);
p_dest += size;
p_length -= size;
file.offset += size;
total_read += size;
};
int err = read_data_block(file.offset, p_length, p_dest);
if (err >= 0) {
total_read += err;
file.offset += err;
};
return total_read;
};
int to_read = p_length;
int total_read = 0;
while (to_read > 0) {
int left = cache_data_left();
if (left == 0) {
if (to_read > 0) {
file.offset += to_read;
};
return total_read;
};
if (left < 0) {
return left;
};
int r = MIN(left, to_read);
//PoolVector<uint8_t>::Read read = cache.buffer.read();
//memcpy(p_dest+total_read, &read.ptr()[file.offset - cache.offset], r);
memcpy(p_dest + total_read, cache.buffer.ptr() + (file.offset - cache.offset), r);
file.offset += r;
total_read += r;
to_read -= r;
};
return p_length;
};
bool FileAccessBuffered::is_open() const {
return file.open;
};
Error FileAccessBuffered::get_error() const {
return last_error;
};
FileAccessBuffered::FileAccessBuffered() {
cache_size = DEFAULT_CACHE_SIZE;
};
FileAccessBuffered::~FileAccessBuffered() {
}

View File

@@ -0,0 +1,94 @@
/*************************************************************************/
/* file_access_buffered.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef FILE_ACCESS_BUFFERED_H
#define FILE_ACCESS_BUFFERED_H
#include "core/os/file_access.h"
#include "core/pool_vector.h"
#include "core/ustring.h"
class FileAccessBuffered : public FileAccess {
public:
enum {
DEFAULT_CACHE_SIZE = 128 * 1024,
};
private:
int cache_size;
int cache_data_left() const;
mutable Error last_error;
protected:
Error set_error(Error p_error) const;
mutable struct File {
bool open;
int size;
int offset;
String name;
int access_flags;
} file;
mutable struct Cache {
Vector<uint8_t> buffer;
int offset;
} cache;
virtual int read_data_block(int p_offset, int p_size, uint8_t *p_dest = 0) const = 0;
void set_cache_size(int p_size);
int get_cache_size();
public:
virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual bool eof_reached() const;
virtual uint8_t get_8() const;
virtual int get_buffer(uint8_t *p_dest, int p_length) const; ///< get an array of bytes
virtual bool is_open() const;
virtual Error get_error() const;
FileAccessBuffered();
virtual ~FileAccessBuffered();
};
#endif

View File

@@ -0,0 +1,151 @@
/*************************************************************************/
/* file_access_buffered_fa.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef FILE_ACCESS_BUFFERED_FA_H
#define FILE_ACCESS_BUFFERED_FA_H
#include "core/io/file_access_buffered.h"
template <class T>
class FileAccessBufferedFA : public FileAccessBuffered {
T f;
int read_data_block(int p_offset, int p_size, uint8_t *p_dest = 0) const {
ERR_FAIL_COND_V(!f.is_open(), -1);
((T *)&f)->seek(p_offset);
if (p_dest) {
f.get_buffer(p_dest, p_size);
return p_size;
} else {
cache.offset = p_offset;
cache.buffer.resize(p_size);
// on PoolVector
//PoolVector<uint8_t>::Write write = cache.buffer.write();
//f.get_buffer(write.ptrw(), p_size);
// on vector
f.get_buffer(cache.buffer.ptrw(), p_size);
return p_size;
};
};
static FileAccess *create() {
return memnew(FileAccessBufferedFA<T>());
};
protected:
virtual void _set_access_type(AccessType p_access) {
f._set_access_type(p_access);
FileAccessBuffered::_set_access_type(p_access);
};
public:
void flush() {
f.flush();
};
void store_8(uint8_t p_dest) {
f.store_8(p_dest);
};
void store_buffer(const uint8_t *p_src, int p_length) {
f.store_buffer(p_src, p_length);
};
bool file_exists(const String &p_name) {
return f.file_exists(p_name);
};
Error _open(const String &p_path, int p_mode_flags) {
close();
Error ret = f._open(p_path, p_mode_flags);
if (ret != OK)
return ret;
//ERR_FAIL_COND_V( ret != OK, ret );
file.size = f.get_len();
file.offset = 0;
file.open = true;
file.name = p_path;
file.access_flags = p_mode_flags;
cache.buffer.resize(0);
cache.offset = 0;
return set_error(OK);
};
void close() {
f.close();
file.offset = 0;
file.size = 0;
file.open = false;
file.name = "";
cache.buffer.resize(0);
cache.offset = 0;
set_error(OK);
};
/*
static void make_default() {
FileAccess::create_func = FileAccessBufferedFA<T>::create;
};
*/
virtual uint64_t _get_modified_time(const String &p_file) {
return f._get_modified_time(p_file);
}
FileAccessBufferedFA(){
};
};
#endif // FILE_ACCESS_BUFFERED_FA_H

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -32,14 +32,14 @@
#include "core/print_string.h"
void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, uint32_t p_block_size) {
void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_mode, int p_block_size) {
magic = p_magic.ascii().get_data();
if (magic.length() > 4) {
if (magic.length() > 4)
magic = magic.substr(0, 4);
} else {
while (magic.length() < 4) {
else {
while (magic.length() < 4)
magic += " ";
}
}
cmode = p_mode;
@@ -59,18 +59,16 @@ void FileAccessCompressed::configure(const String &p_magic, Compression::Mode p_
}
Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
f = p_base;
cmode = (Compression::Mode)f->get_32();
block_size = f->get_32();
if (block_size == 0) {
f = nullptr; // Let the caller to handle the FileAccess object if failed to open as compressed file.
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Can't open compressed file '" + p_base->get_path() + "' with block size 0, it is corrupted.");
}
read_total = f->get_32();
uint32_t bc = (read_total / block_size) + 1;
uint64_t acc_ofs = f->get_position() + bc * 4;
uint32_t max_bs = 0;
for (uint32_t i = 0; i < bc; i++) {
int bc = (read_total / block_size) + 1;
int acc_ofs = f->get_position() + bc * 4;
int max_bs = 0;
for (int i = 0; i < bc; i++) {
ReadBlock rb;
rb.offset = acc_ofs;
rb.csize = f->get_32();
@@ -88,30 +86,31 @@ Error FileAccessCompressed::open_after_magic(FileAccess *p_base) {
read_block_count = bc;
read_block_size = read_blocks.size() == 1 ? read_total : block_size;
int ret = Compression::decompress(buffer.ptrw(), read_block_size, comp_buffer.ptr(), read_blocks[0].csize, cmode);
Compression::decompress(buffer.ptrw(), read_block_size, comp_buffer.ptr(), read_blocks[0].csize, cmode);
read_block = 0;
read_pos = 0;
return ret == -1 ? ERR_FILE_CORRUPT : OK;
return OK;
}
Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
ERR_FAIL_COND_V(p_mode_flags == READ_WRITE, ERR_UNAVAILABLE);
if (f) {
if (f)
close();
}
Error err;
f = FileAccess::open(p_path, p_mode_flags, &err);
if (err != OK) {
//not openable
f = nullptr;
f = NULL;
return err;
}
if (p_mode_flags & WRITE) {
buffer.clear();
writing = true;
write_pos = 0;
@@ -122,23 +121,25 @@ Error FileAccessCompressed::_open(const String &p_path, int p_mode_flags) {
//don't store anything else unless it's done saving!
} else {
char rmagic[5];
f->get_buffer((uint8_t *)rmagic, 4);
rmagic[4] = 0;
err = ERR_FILE_UNRECOGNIZED;
if (magic != rmagic || (err = open_after_magic(f)) != OK) {
if (magic != rmagic) {
memdelete(f);
f = nullptr;
return err;
f = NULL;
return ERR_FILE_UNRECOGNIZED;
}
open_after_magic(f);
}
return OK;
}
void FileAccessCompressed::close() {
if (!f) {
if (!f)
return;
}
if (writing) {
//save block table and all compressed blocks
@@ -148,15 +149,16 @@ void FileAccessCompressed::close() {
f->store_32(cmode); //write compression mode 4
f->store_32(block_size); //write block size 4
f->store_32(write_max); //max amount of data written 4
uint32_t bc = (write_max / block_size) + 1;
int bc = (write_max / block_size) + 1;
for (uint32_t i = 0; i < bc; i++) {
for (int i = 0; i < bc; i++) {
f->store_32(0); //compressed sizes, will update later
}
Vector<int> block_sizes;
for (uint32_t i = 0; i < bc; i++) {
uint32_t bl = i == (bc - 1) ? write_max % block_size : block_size;
for (int i = 0; i < bc; i++) {
int bl = i == (bc - 1) ? write_max % block_size : block_size;
uint8_t *bp = &write_ptr[i * block_size];
Vector<uint8_t> cblock;
@@ -168,50 +170,52 @@ void FileAccessCompressed::close() {
}
f->seek(16); //ok write block sizes
for (uint32_t i = 0; i < bc; i++) {
for (int i = 0; i < bc; i++)
f->store_32(block_sizes[i]);
}
f->seek_end();
f->store_buffer((const uint8_t *)mgc.get_data(), mgc.length()); //magic at the end too
buffer.clear();
} else {
comp_buffer.clear();
buffer.clear();
read_blocks.clear();
}
memdelete(f);
f = nullptr;
f = NULL;
}
bool FileAccessCompressed::is_open() const {
return f != nullptr;
return f != NULL;
}
void FileAccessCompressed::seek(uint64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
void FileAccessCompressed::seek(size_t p_position) {
ERR_FAIL_COND(!f);
if (writing) {
ERR_FAIL_COND(p_position > write_max);
write_pos = p_position;
} else {
ERR_FAIL_COND(p_position > read_total);
if (p_position == read_total) {
at_end = true;
} else {
at_end = false;
read_eof = false;
uint32_t block_idx = p_position / block_size;
int block_idx = p_position / block_size;
if (block_idx != read_block) {
read_block = block_idx;
f->seek(read_blocks[read_block].offset);
f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
int ret = Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
ERR_FAIL_COND_MSG(ret == -1, "Compressed file is corrupt.");
Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
read_block_size = read_block == read_block_count - 1 ? read_total % block_size : block_size;
}
@@ -221,26 +225,32 @@ void FileAccessCompressed::seek(uint64_t p_position) {
}
void FileAccessCompressed::seek_end(int64_t p_position) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
ERR_FAIL_COND(!f);
if (writing) {
seek(write_max + p_position);
} else {
seek(read_total + p_position);
}
}
size_t FileAccessCompressed::get_position() const {
uint64_t FileAccessCompressed::get_position() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
ERR_FAIL_COND_V(!f, 0);
if (writing) {
return write_pos;
} else {
return read_block * block_size + read_pos;
}
}
size_t FileAccessCompressed::get_len() const {
uint64_t FileAccessCompressed::get_len() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
ERR_FAIL_COND_V(!f, 0);
if (writing) {
return write_max;
} else {
return read_total;
@@ -248,7 +258,8 @@ uint64_t FileAccessCompressed::get_len() const {
}
bool FileAccessCompressed::eof_reached() const {
ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use.");
ERR_FAIL_COND_V(!f, false);
if (writing) {
return false;
} else {
@@ -257,8 +268,9 @@ bool FileAccessCompressed::eof_reached() const {
}
uint8_t FileAccessCompressed::get_8() const {
ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
ERR_FAIL_COND_V(writing, 0);
ERR_FAIL_COND_V(!f, 0);
if (at_end) {
read_eof = true;
@@ -274,8 +286,7 @@ uint8_t FileAccessCompressed::get_8() const {
if (read_block < read_block_count) {
//read another block of compressed data
f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
int total = Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
ERR_FAIL_COND_V_MSG(total == -1, 0, "Compressed file is corrupt.");
Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
read_block_size = read_block == read_block_count - 1 ? read_total % block_size : block_size;
read_pos = 0;
@@ -287,18 +298,18 @@ uint8_t FileAccessCompressed::get_8() const {
return ret;
}
int FileAccessCompressed::get_buffer(uint8_t *p_dst, int p_length) const {
uint64_t FileAccessCompressed::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
ERR_FAIL_COND_V_MSG(!f, -1, "File must be opened before use.");
ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode.");
ERR_FAIL_COND_V(writing, 0);
ERR_FAIL_COND_V(!f, 0);
if (at_end) {
read_eof = true;
return 0;
}
for (uint64_t i = 0; i < p_length; i++) {
for (int i = 0; i < p_length; i++) {
p_dst[i] = read_ptr[read_pos];
read_pos++;
if (read_pos >= read_block_size) {
@@ -307,17 +318,15 @@ uint64_t FileAccessCompressed::get_buffer(uint8_t *p_dst, uint64_t p_length) con
if (read_block < read_block_count) {
//read another block of compressed data
f->get_buffer(comp_buffer.ptrw(), read_blocks[read_block].csize);
int ret = Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
ERR_FAIL_COND_V_MSG(ret == -1, -1, "Compressed file is corrupt.");
Compression::decompress(buffer.ptrw(), read_blocks.size() == 1 ? read_total : block_size, comp_buffer.ptr(), read_blocks[read_block].csize, cmode);
read_block_size = read_block == read_block_count - 1 ? read_total % block_size : block_size;
read_pos = 0;
} else {
read_block--;
at_end = true;
if (i < p_length - 1) {
if (i < p_length - 1)
read_eof = true;
}
return i;
}
}
@@ -327,76 +336,64 @@ uint64_t FileAccessCompressed::get_buffer(uint8_t *p_dst, uint64_t p_length) con
}
Error FileAccessCompressed::get_error() const {
return read_eof ? ERR_FILE_EOF : OK;
}
void FileAccessCompressed::flush() {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
ERR_FAIL_COND(!f);
ERR_FAIL_COND(!writing);
// compressed files keep data in memory till close()
}
void FileAccessCompressed::store_8(uint8_t p_dest) {
ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
ERR_FAIL_COND(!f);
ERR_FAIL_COND(!writing);
WRITE_FIT(1);
write_ptr[write_pos++] = p_dest;
}
bool FileAccessCompressed::file_exists(const String &p_name) {
FileAccess *fa = FileAccess::open(p_name, FileAccess::READ);
if (!fa) {
if (!fa)
return false;
}
memdelete(fa);
return true;
}
uint64_t FileAccessCompressed::_get_modified_time(const String &p_file) {
if (f) {
if (f)
return f->get_modified_time(p_file);
} else {
else
return 0;
}
}
uint32_t FileAccessCompressed::_get_unix_permissions(const String &p_file) {
if (f) {
return f->_get_unix_permissions(p_file);
}
return 0;
}
Error FileAccessCompressed::_set_unix_permissions(const String &p_file, uint32_t p_permissions) {
if (f) {
return f->_set_unix_permissions(p_file, p_permissions);
}
return FAILED;
}
FileAccessCompressed::FileAccessCompressed() :
cmode(Compression::MODE_ZSTD),
writing(false),
write_ptr(nullptr),
write_ptr(0),
write_buffer_size(0),
write_max(0),
block_size(0),
read_eof(false),
at_end(false),
read_ptr(nullptr),
read_ptr(NULL),
read_block(0),
read_block_count(0),
read_block_size(0),
read_pos(0),
read_total(0),
magic("GCMP"),
f(nullptr) {
f(NULL) {
}
FileAccessCompressed::~FileAccessCompressed() {
if (f) {
if (f)
close();
}
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -35,36 +35,37 @@
#include "core/os/file_access.h"
class FileAccessCompressed : public FileAccess {
Compression::Mode cmode;
bool writing;
uint64_t write_pos;
uint32_t write_pos;
uint8_t *write_ptr;
uint32_t write_buffer_size;
uint64_t write_max;
uint32_t write_max;
uint32_t block_size;
mutable bool read_eof;
mutable bool at_end;
struct ReadBlock {
uint32_t csize;
uint64_t offset;
int csize;
int offset;
};
mutable Vector<uint8_t> comp_buffer;
uint8_t *read_ptr;
mutable uint32_t read_block;
uint32_t read_block_count;
mutable uint32_t read_block_size;
mutable uint64_t read_pos;
mutable int read_block;
int read_block_count;
mutable int read_block_size;
mutable int read_pos;
Vector<ReadBlock> read_blocks;
uint64_t read_total;
uint32_t read_total;
String magic;
mutable Vector<uint8_t> buffer;
FileAccess *f;
public:
void configure(const String &p_magic, Compression::Mode p_mode = Compression::MODE_ZSTD, uint32_t p_block_size = 4096);
void configure(const String &p_magic, Compression::Mode p_mode = Compression::MODE_ZSTD, int p_block_size = 4096);
Error open_after_magic(FileAccess *p_base);
@@ -72,15 +73,15 @@ public:
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual uint64_t get_position() const; ///< get position in the file
virtual uint64_t get_len() const; ///< get size of the file
virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte
virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const;
virtual int get_buffer(uint8_t *p_dst, int p_length) const;
virtual Error get_error() const; ///< get last error
@@ -90,8 +91,6 @@ public:
virtual bool file_exists(const String &p_name); ///< return true if a file exists
virtual uint64_t _get_modified_time(const String &p_file);
virtual uint32_t _get_unix_permissions(const String &p_file);
virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions);
FileAccessCompressed();
virtual ~FileAccessCompressed();

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -30,22 +30,27 @@
#include "file_access_encrypted.h"
#include "core/crypto/crypto_core.h"
#include "core/os/copymem.h"
#include "core/print_string.h"
#include "core/variant.h"
#include "thirdparty/misc/aes256.h"
#include "thirdparty/misc/md5.h"
#include <stdio.h>
#define COMP_MAGIC 0x43454447
Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8_t> &p_key, Mode p_mode) {
ERR_FAIL_COND_V_MSG(file != nullptr, ERR_ALREADY_IN_USE, "Can't open file while another file from path '" + file->get_path_absolute() + "' is open.");
ERR_FAIL_COND_V(file != NULL, ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(p_key.size() != 32, ERR_INVALID_PARAMETER);
pos = 0;
eofed = false;
if (p_mode == MODE_WRITE_AES256) {
data.clear();
writing = true;
file = p_base;
@@ -53,6 +58,7 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
key = p_key;
} else if (p_mode == MODE_READ) {
writing = false;
key = p_key;
uint32_t magic = p_base->get_32();
@@ -67,29 +73,34 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
length = p_base->get_64();
base = p_base->get_position();
ERR_FAIL_COND_V(p_base->get_len() < base + length, ERR_FILE_CORRUPT);
uint64_t ds = length;
uint32_t ds = length;
if (ds % 16) {
ds += 16 - (ds % 16);
}
data.resize(ds);
uint64_t blen = p_base->get_buffer(data.ptrw(), ds);
uint32_t blen = p_base->get_buffer(data.ptrw(), ds);
ERR_FAIL_COND_V(blen != ds, ERR_FILE_CORRUPT);
CryptoCore::AESContext ctx;
ctx.set_decode_key(key.ptrw(), 256);
aes256_context ctx;
aes256_init(&ctx, key.ptrw());
for (uint64_t i = 0; i < ds; i += 16) {
ctx.decrypt_ecb(&data.write[i], &data.write[i]);
for (size_t i = 0; i < ds; i += 16) {
aes256_decrypt_ecb(&ctx, &data.write[i]);
}
aes256_done(&ctx);
data.resize(length);
unsigned char hash[16];
ERR_FAIL_COND_V(CryptoCore::md5(data.ptr(), data.size(), hash) != OK, ERR_BUG);
MD5_CTX md5;
MD5Init(&md5);
MD5Update(&md5, (uint8_t *)data.ptr(), data.size());
MD5Final(&md5);
ERR_FAIL_COND_V_MSG(String::md5(hash) != String::md5(md5d), ERR_FILE_CORRUPT, "The MD5 sum of the decrypted file does not match the expected value. It could be that the file is corrupt, or that the provided decryption key is invalid.");
ERR_FAIL_COND_V(String::md5(md5.digest) != String::md5(md5d), ERR_FILE_CORRUPT);
file = p_base;
}
@@ -98,11 +109,13 @@ Error FileAccessEncrypted::open_and_parse(FileAccess *p_base, const Vector<uint8
}
Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const String &p_key, Mode p_mode) {
String cs = p_key.md5_text();
ERR_FAIL_COND_V(cs.length() != 32, ERR_INVALID_PARAMETER);
Vector<uint8_t> key;
key.resize(32);
for (int i = 0; i < 32; i++) {
key.write[i] = cs[i];
}
@@ -110,104 +123,100 @@ Error FileAccessEncrypted::open_and_parse_password(FileAccess *p_base, const Str
}
Error FileAccessEncrypted::_open(const String &p_path, int p_mode_flags) {
return OK;
}
void FileAccessEncrypted::close() {
if (!file) {
if (!file)
return;
}
if (writing) {
Vector<uint8_t> compressed;
uint64_t len = data.size();
size_t len = data.size();
if (len % 16) {
len += 16 - (len % 16);
}
unsigned char hash[16];
ERR_FAIL_COND(CryptoCore::md5(data.ptr(), data.size(), hash) != OK); // Bug?
MD5_CTX md5;
MD5Init(&md5);
MD5Update(&md5, (uint8_t *)data.ptr(), data.size());
MD5Final(&md5);
compressed.resize(len);
memset(compressed.ptrw(), 0, len);
zeromem(compressed.ptrw(), len);
for (int i = 0; i < data.size(); i++) {
compressed.write[i] = data[i];
}
CryptoCore::AESContext ctx;
ctx.set_encode_key(key.ptrw(), 256);
aes256_context ctx;
aes256_init(&ctx, key.ptrw());
for (uint64_t i = 0; i < len; i += 16) {
ctx.encrypt_ecb(&compressed.write[i], &compressed.write[i]);
for (size_t i = 0; i < len; i += 16) {
aes256_encrypt_ecb(&ctx, &compressed.write[i]);
}
aes256_done(&ctx);
file->store_32(COMP_MAGIC);
file->store_32(mode);
file->store_buffer(hash, 16);
file->store_buffer(md5.digest, 16);
file->store_64(data.size());
file->store_buffer(compressed.ptr(), compressed.size());
file->close();
memdelete(file);
file = nullptr;
file = NULL;
data.clear();
} else {
file->close();
memdelete(file);
data.clear();
file = nullptr;
file = NULL;
}
}
bool FileAccessEncrypted::is_open() const {
return file != nullptr;
return file != NULL;
}
String FileAccessEncrypted::get_path() const {
if (file) {
return file->get_path();
} else {
return "";
}
}
void FileAccessEncrypted::seek(size_t p_position) {
String FileAccessEncrypted::get_path_absolute() const {
if (file) {
return file->get_path_absolute();
} else {
return "";
}
}
void FileAccessEncrypted::seek(uint64_t p_position) {
if (p_position > get_len()) {
p_position = get_len();
}
if (p_position > (size_t)data.size())
p_position = data.size();
pos = p_position;
eofed = false;
}
void FileAccessEncrypted::seek_end(int64_t p_position) {
seek(get_len() + p_position);
}
uint64_t FileAccessEncrypted::get_position() const {
seek(data.size() + p_position);
}
size_t FileAccessEncrypted::get_position() const {
return pos;
}
size_t FileAccessEncrypted::get_len() const {
uint64_t FileAccessEncrypted::get_len() const {
return data.size();
}
bool FileAccessEncrypted::eof_reached() const {
return eofed;
}
uint8_t FileAccessEncrypted::get_8() const {
ERR_FAIL_COND_V_MSG(writing, 0, "File has not been opened in read mode.");
if (pos >= get_len()) {
ERR_FAIL_COND_V(writing, 0);
if (pos >= data.size()) {
eofed = true;
return 0;
}
@@ -216,13 +225,13 @@ uint8_t FileAccessEncrypted::get_8() const {
pos++;
return b;
}
int FileAccessEncrypted::get_buffer(uint8_t *p_dst, int p_length) const {
uint64_t FileAccessEncrypted::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
ERR_FAIL_COND_V_MSG(writing, -1, "File has not been opened in read mode.");
ERR_FAIL_COND_V(writing, 0);
int to_copy = MIN(p_length, data.size() - pos);
for (int i = 0; i < to_copy; i++) {
uint64_t to_copy = MIN(p_length, get_len() - pos);
for (uint64_t i = 0; i < to_copy; i++) {
p_dst[i] = data[pos++];
}
@@ -234,20 +243,25 @@ uint64_t FileAccessEncrypted::get_buffer(uint8_t *p_dst, uint64_t p_length) cons
}
Error FileAccessEncrypted::get_error() const {
return eofed ? ERR_FILE_EOF : OK;
}
void FileAccessEncrypted::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
ERR_FAIL_COND(!p_src && p_length > 0);
void FileAccessEncrypted::store_buffer(const uint8_t *p_src, int p_length) {
ERR_FAIL_COND(!writing);
if (pos < data.size()) {
for (int i = 0; i < p_length; i++) {
if (pos < get_len()) {
for (uint64_t i = 0; i < p_length; i++) {
store_8(p_src[i]);
}
} else if (pos == get_len()) {
} else if (pos == data.size()) {
data.resize(pos + p_length);
for (uint64_t i = 0; i < p_length; i++) {
for (int i = 0; i < p_length; i++) {
data.write[pos + i] = p_src[i];
}
pos += p_length;
@@ -255,47 +269,41 @@ void FileAccessEncrypted::store_buffer(const uint8_t *p_src, uint64_t p_length)
}
void FileAccessEncrypted::flush() {
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
ERR_FAIL_COND(!writing);
// encrypted files keep data in memory till close()
}
void FileAccessEncrypted::store_8(uint8_t p_dest) {
ERR_FAIL_COND_MSG(!writing, "File has not been opened in write mode.");
if (pos < get_len()) {
ERR_FAIL_COND(!writing);
if (pos < data.size()) {
data.write[pos] = p_dest;
pos++;
} else if (pos == get_len()) {
} else if (pos == data.size()) {
data.push_back(p_dest);
pos++;
}
}
bool FileAccessEncrypted::file_exists(const String &p_name) {
FileAccess *fa = FileAccess::open(p_name, FileAccess::READ);
if (!fa) {
if (!fa)
return false;
}
memdelete(fa);
return true;
}
uint64_t FileAccessEncrypted::_get_modified_time(const String &p_file) {
return 0;
}
uint32_t FileAccessEncrypted::_get_unix_permissions(const String &p_file) {
return 0;
}
Error FileAccessEncrypted::_set_unix_permissions(const String &p_file, uint32_t p_permissions) {
ERR_PRINT("Setting UNIX permissions on encrypted files is not implemented yet.");
return ERR_UNAVAILABLE;
}
FileAccessEncrypted::FileAccessEncrypted() {
file = nullptr;
file = NULL;
pos = 0;
eofed = false;
mode = MODE_MAX;
@@ -303,7 +311,7 @@ FileAccessEncrypted::FileAccessEncrypted() {
}
FileAccessEncrypted::~FileAccessEncrypted() {
if (file) {
if (file)
close();
}
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -46,10 +46,10 @@ private:
Vector<uint8_t> key;
bool writing;
FileAccess *file;
uint64_t base;
uint64_t length;
size_t base;
size_t length;
Vector<uint8_t> data;
mutable uint64_t pos;
mutable int pos;
mutable bool eofed;
public:
@@ -60,30 +60,25 @@ public:
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
virtual String get_path() const; /// returns the path for the current open file
virtual String get_path_absolute() const; /// returns the absolute path for the current open file
virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
virtual uint64_t get_position() const; ///< get position in the file
virtual uint64_t get_len() const; ///< get size of the file
virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte
virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const;
virtual int get_buffer(uint8_t *p_dst, int p_length) const;
virtual Error get_error() const; ///< get last error
virtual void flush();
virtual void store_8(uint8_t p_dest); ///< store a byte
virtual void store_buffer(const uint8_t *p_src, uint64_t p_length); ///< store an array of bytes
virtual void store_buffer(const uint8_t *p_src, int p_length); ///< store an array of bytes
virtual bool file_exists(const String &p_name); ///< return true if a file exists
virtual uint64_t _get_modified_time(const String &p_file);
virtual uint32_t _get_unix_permissions(const String &p_file);
virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions);
FileAccessEncrypted();
~FileAccessEncrypted();

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,47 +31,51 @@
#include "file_access_memory.h"
#include "core/map.h"
#include "core/os/copymem.h"
#include "core/os/dir_access.h"
#include "core/project_settings.h"
static Map<String, Vector<uint8_t>> *files = nullptr;
static Map<String, Vector<uint8_t> > *files = NULL;
void FileAccessMemory::register_file(String p_name, Vector<uint8_t> p_data) {
if (!files) {
files = memnew((Map<String, Vector<uint8_t>>));
files = memnew((Map<String, Vector<uint8_t> >));
}
String name;
if (ProjectSettings::get_singleton()) {
if (ProjectSettings::get_singleton())
name = ProjectSettings::get_singleton()->globalize_path(p_name);
} else {
else
name = p_name;
}
//name = DirAccess::normalize_path(name);
(*files)[name] = p_data;
}
void FileAccessMemory::cleanup() {
if (!files) {
if (!files)
return;
}
memdelete(files);
}
FileAccess *FileAccessMemory::create() {
return memnew(FileAccessMemory);
}
bool FileAccessMemory::file_exists(const String &p_name) {
String name = fix_path(p_name);
//name = DirAccess::normalize_path(name);
return files && (files->find(name) != nullptr);
return files && (files->find(name) != NULL);
}
Error FileAccessMemory::open_custom(const uint8_t *p_data, uint64_t p_len) {
Error FileAccessMemory::open_custom(const uint8_t *p_data, int p_len) {
data = (uint8_t *)p_data;
length = p_len;
pos = 0;
@@ -79,13 +83,14 @@ Error FileAccessMemory::open_custom(const uint8_t *p_data, uint64_t p_len) {
}
Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) {
ERR_FAIL_COND_V(!files, ERR_FILE_NOT_FOUND);
String name = fix_path(p_path);
//name = DirAccess::normalize_path(name);
Map<String, Vector<uint8_t>>::Element *E = files->find(name);
ERR_FAIL_COND_V_MSG(!E, ERR_FILE_NOT_FOUND, "Can't find file '" + p_path + "'.");
Map<String, Vector<uint8_t> >::Element *E = files->find(name);
ERR_FAIL_COND_V(!E, ERR_FILE_NOT_FOUND);
data = E->get().ptrw();
length = E->get().size();
@@ -95,38 +100,46 @@ Error FileAccessMemory::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessMemory::close() {
data = nullptr;
data = NULL;
}
bool FileAccessMemory::is_open() const {
return data != nullptr;
return data != NULL;
}
void FileAccessMemory::seek(uint64_t p_position) {
void FileAccessMemory::seek(size_t p_position) {
ERR_FAIL_COND(!data);
pos = p_position;
}
void FileAccessMemory::seek_end(int64_t p_position) {
ERR_FAIL_COND(!data);
pos = length + p_position;
}
uint64_t FileAccessMemory::get_position() const {
size_t FileAccessMemory::get_position() const {
ERR_FAIL_COND_V(!data, 0);
return pos;
}
uint64_t FileAccessMemory::get_len() const {
size_t FileAccessMemory::get_len() const {
ERR_FAIL_COND_V(!data, 0);
return length;
}
bool FileAccessMemory::eof_reached() const {
return pos > length;
}
uint8_t FileAccessMemory::get_8() const {
uint8_t ret = 0;
if (pos < length) {
ret = data[pos];
@@ -136,24 +149,25 @@ uint8_t FileAccessMemory::get_8() const {
return ret;
}
uint64_t FileAccessMemory::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const {
ERR_FAIL_COND_V(!data, -1);
uint64_t left = length - pos;
uint64_t read = MIN(p_length, left);
int left = length - pos;
int read = MIN(p_length, left);
if (read < p_length) {
WARN_PRINT("Reading less data than requested");
}
};
memcpy(p_dst, &data[pos], read);
copymem(p_dst, &data[pos], read);
pos += p_length;
return read;
}
Error FileAccessMemory::get_error() const {
return pos >= length ? ERR_FILE_EOF : OK;
}
@@ -162,23 +176,25 @@ void FileAccessMemory::flush() {
}
void FileAccessMemory::store_8(uint8_t p_byte) {
ERR_FAIL_COND(!data);
ERR_FAIL_COND(pos >= length);
data[pos++] = p_byte;
}
void FileAccessMemory::store_buffer(const uint8_t *p_src, uint64_t p_length) {
ERR_FAIL_COND(!p_src && p_length > 0);
uint64_t left = length - pos;
uint64_t write = MIN(p_length, left);
void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) {
int left = length - pos;
int write = MIN(p_length, left);
if (write < p_length) {
WARN_PRINT("Writing less data than requested");
}
memcpy(&data[pos], p_src, write);
copymem(&data[pos], p_src, write);
pos += p_length;
}
FileAccessMemory::FileAccessMemory() {
data = nullptr;
data = NULL;
}

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,9 +34,10 @@
#include "core/os/file_access.h"
class FileAccessMemory : public FileAccess {
uint8_t *data;
uint64_t length;
mutable uint64_t pos;
int length;
mutable int pos;
static FileAccess *create();
@@ -44,33 +45,31 @@ public:
static void register_file(String p_name, Vector<uint8_t> p_data);
static void cleanup();
virtual Error open_custom(const uint8_t *p_data, uint64_t p_len); ///< open a file
virtual Error open_custom(const uint8_t *p_data, int p_len); ///< open a file
virtual Error _open(const String &p_path, int p_mode_flags); ///< open a file
virtual void close(); ///< close a file
virtual bool is_open() const; ///< true when file is open
virtual void seek(uint64_t p_position); ///< seek to a given position
virtual void seek(size_t p_position); ///< seek to a given position
virtual void seek_end(int64_t p_position); ///< seek from the end of file
virtual uint64_t get_position() const; ///< get position in the file
virtual uint64_t get_len() const; ///< get size of the file
virtual size_t get_position() const; ///< get position in the file
virtual size_t get_len() const; ///< get size of the file
virtual bool eof_reached() const; ///< reading passed EOF
virtual uint8_t get_8() const; ///< get a byte
virtual uint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const; ///< get an array of bytes
virtual int get_buffer(uint8_t *p_dst, int p_length) const; ///< get an array of bytes
virtual Error get_error() const; ///< get last error
virtual void flush();
virtual void store_8(uint8_t p_byte); ///< store a byte
virtual void store_buffer(const uint8_t *p_src, uint64_t p_length); ///< store an array of bytes
virtual void store_buffer(const uint8_t *p_src, int p_length); ///< store an array of bytes
virtual bool file_exists(const String &p_name); ///< return true if a file exists
virtual uint64_t _get_modified_time(const String &p_file) { return 0; }
virtual uint32_t _get_unix_permissions(const String &p_file) { return 0; }
virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions) { return FAILED; }
FileAccessMemory();
};

View File

@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -41,16 +41,19 @@
#define DEBUG_TIME(m_what)
void FileAccessNetworkClient::lock_mutex() {
mutex.lock();
mutex->lock();
lockcount++;
}
void FileAccessNetworkClient::unlock_mutex() {
lockcount--;
mutex.unlock();
mutex->unlock();
}
void FileAccessNetworkClient::put_32(int p_32) {
uint8_t buf[4];
encode_uint32(p_32, buf);
client->put_data(buf, 4);
@@ -58,6 +61,7 @@ void FileAccessNetworkClient::put_32(int p_32) {
}
void FileAccessNetworkClient::put_64(int64_t p_64) {
uint8_t buf[8];
encode_uint64(p_64, buf);
client->put_data(buf, 8);
@@ -65,29 +69,35 @@ void FileAccessNetworkClient::put_64(int64_t p_64) {
}
int FileAccessNetworkClient::get_32() {
uint8_t buf[4];
client->get_data(buf, 4);
return decode_uint32(buf);
}
int64_t FileAccessNetworkClient::get_64() {
uint8_t buf[8];
client->get_data(buf, 8);
return decode_uint64(buf);
}
void FileAccessNetworkClient::_thread_func() {
client->set_no_delay(true);
while (!quit) {
DEBUG_PRINT("SEM WAIT - " + itos(sem->get()));
sem.wait();
Error err = sem->wait();
if (err != OK)
ERR_PRINT("sem->wait() failed");
DEBUG_TIME("sem_unlock");
//DEBUG_PRINT("semwait returned "+itos(werr));
DEBUG_PRINT("MUTEX LOCK " + itos(lockcount));
lock_mutex();
DEBUG_PRINT("MUTEX PASS");
blockrequest_mutex.lock();
blockrequest_mutex->lock();
while (block_requests.size()) {
put_32(block_requests.front()->get().id);
put_32(FileAccessNetwork::COMMAND_READ_BLOCK);
@@ -95,7 +105,7 @@ void FileAccessNetworkClient::_thread_func() {
put_32(block_requests.front()->get().size);
block_requests.pop_front();
}
blockrequest_mutex.unlock();
blockrequest_mutex->unlock();
DEBUG_PRINT("THREAD ITER");
@@ -105,56 +115,56 @@ void FileAccessNetworkClient::_thread_func() {
int response = get_32();
DEBUG_PRINT("GET RESPONSE: " + itos(response));
FileAccessNetwork *fa = nullptr;
FileAccessNetwork *fa = NULL;
if (response != FileAccessNetwork::RESPONSE_DATA) {
if (!accesses.has(id)) {
unlock_mutex();
ERR_FAIL_COND(!accesses.has(id));
}
ERR_FAIL_COND(!accesses.has(id));
}
if (accesses.has(id)) {
if (accesses.has(id))
fa = accesses[id];
}
switch (response) {
case FileAccessNetwork::RESPONSE_OPEN: {
DEBUG_TIME("sem_open");
int status = get_32();
if (status != OK) {
fa->_respond(0, Error(status));
} else {
int64_t len = get_64();
uint64_t len = get_64();
fa->_respond(len, Error(status));
}
fa->sem.post();
fa->sem->post();
} break;
case FileAccessNetwork::RESPONSE_DATA: {
int64_t offset = get_64();
int32_t len = get_32();
uint32_t len = get_32();
Vector<uint8_t> block;
block.resize(len);
client->get_data(block.ptrw(), len);
if (fa) { //may have been queued
if (fa) //may have been queued
fa->_set_block(offset, block);
}
} break;
case FileAccessNetwork::RESPONSE_FILE_EXISTS: {
int status = get_32();
fa->exists_modtime = status != 0;
fa->sem.post();
fa->sem->post();
} break;
case FileAccessNetwork::RESPONSE_GET_MODTIME: {
uint64_t status = get_64();
fa->exists_modtime = status;
fa->sem.post();
fa->sem->post();
} break;
}
@@ -164,12 +174,14 @@ void FileAccessNetworkClient::_thread_func() {
}
void FileAccessNetworkClient::_thread_func(void *s) {
FileAccessNetworkClient *self = (FileAccessNetworkClient *)s;
self->_thread_func();
}
Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const String &p_password) {
IP_Address ip;
if (p_host.is_valid_ip_address()) {
@@ -180,7 +192,7 @@ Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const S
DEBUG_PRINT("IP: " + String(ip) + " port " + itos(p_port));
Error err = client->connect_to_host(ip, p_port);
ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot connect to host with IP: " + String(ip) + " and port: " + itos(p_port));
ERR_FAIL_COND_V(err, err);
while (client->get_status() == StreamPeerTCP::STATUS_CONNECTING) {
//DEBUG_PRINT("trying to connect....");
OS::get_singleton()->delay_usec(1000);
@@ -200,66 +212,78 @@ Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const S
return ERR_INVALID_PARAMETER;
}
thread.start(_thread_func, this);
thread = Thread::create(_thread_func, this);
return OK;
}
FileAccessNetworkClient *FileAccessNetworkClient::singleton = nullptr;
FileAccessNetworkClient *FileAccessNetworkClient::singleton = NULL;
FileAccessNetworkClient::FileAccessNetworkClient() {
thread = NULL;
mutex = Mutex::create();
blockrequest_mutex = Mutex::create();
quit = false;
singleton = this;
last_id = 0;
client.instance();
sem = Semaphore::create();
lockcount = 0;
}
FileAccessNetworkClient::~FileAccessNetworkClient() {
if (thread.is_started()) {
if (thread) {
quit = true;
sem.post();
thread.wait_to_finish();
sem->post();
Thread::wait_to_finish(thread);
memdelete(thread);
}
memdelete(blockrequest_mutex);
memdelete(mutex);
memdelete(sem);
}
void FileAccessNetwork::_set_block(uint64_t p_offset, const Vector<uint8_t> &p_block) {
int32_t page = p_offset / page_size;
void FileAccessNetwork::_set_block(int p_offset, const Vector<uint8_t> &p_block) {
int page = p_offset / page_size;
ERR_FAIL_INDEX(page, pages.size());
if (page < pages.size() - 1) {
ERR_FAIL_COND(p_block.size() != page_size);
} else {
ERR_FAIL_COND((uint64_t)p_block.size() != total_size % page_size);
ERR_FAIL_COND((p_block.size() != (int)(total_size % page_size)));
}
buffer_mutex.lock();
buffer_mutex->lock();
pages.write[page].buffer = p_block;
pages.write[page].queued = false;
buffer_mutex.unlock();
buffer_mutex->unlock();
if (waiting_on_page == page) {
waiting_on_page = -1;
page_sem.post();
page_sem->post();
}
}
void FileAccessNetwork::_respond(uint64_t p_len, Error p_status) {
void FileAccessNetwork::_respond(size_t p_len, Error p_status) {
DEBUG_PRINT("GOT RESPONSE - len: " + itos(p_len) + " status: " + itos(p_status));
response = p_status;
if (response != OK) {
if (response != OK)
return;
}
opened = true;
total_size = p_len;
int32_t pc = ((total_size - 1) / page_size) + 1;
int pc = ((total_size - 1) / page_size) + 1;
pages.resize(pc);
}
Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
ERR_FAIL_COND_V(p_mode_flags != READ, ERR_UNAVAILABLE);
if (opened) {
if (opened)
close();
}
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
DEBUG_PRINT("open: " + p_path);
@@ -275,15 +299,15 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
pos = 0;
eof_flag = false;
last_page = -1;
last_page_buff = nullptr;
last_page_buff = NULL;
//buffers.clear();
nc->unlock_mutex();
DEBUG_PRINT("OPEN POST");
DEBUG_TIME("open_post");
nc->sem.post(); //awaiting answer
nc->sem->post(); //awaiting answer
DEBUG_PRINT("WAIT...");
sem.wait();
sem->wait();
DEBUG_TIME("open_end");
DEBUG_PRINT("WAIT ENDED...");
@@ -291,9 +315,9 @@ Error FileAccessNetwork::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessNetwork::close() {
if (!opened) {
if (!opened)
return;
}
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
@@ -306,12 +330,13 @@ void FileAccessNetwork::close() {
nc->unlock_mutex();
}
bool FileAccessNetwork::is_open() const {
return opened;
}
void FileAccessNetwork::seek(uint64_t p_position) {
ERR_FAIL_COND_MSG(!opened, "File must be opened before use.");
void FileAccessNetwork::seek(size_t p_position) {
ERR_FAIL_COND(!opened);
eof_flag = p_position > total_size;
if (p_position >= total_size) {
@@ -322,54 +347,58 @@ void FileAccessNetwork::seek(uint64_t p_position) {
}
void FileAccessNetwork::seek_end(int64_t p_position) {
seek(total_size + p_position);
}
size_t FileAccessNetwork::get_position() const {
uint64_t FileAccessNetwork::get_position() const {
ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use.");
ERR_FAIL_COND_V(!opened, 0);
return pos;
}
size_t FileAccessNetwork::get_len() const {
uint64_t FileAccessNetwork::get_len() const {
ERR_FAIL_COND_V_MSG(!opened, 0, "File must be opened before use.");
ERR_FAIL_COND_V(!opened, 0);
return total_size;
}
bool FileAccessNetwork::eof_reached() const {
ERR_FAIL_COND_V_MSG(!opened, false, "File must be opened before use.");
ERR_FAIL_COND_V(!opened, false);
return eof_flag;
}
uint8_t FileAccessNetwork::get_8() const {
uint8_t v;
get_buffer(&v, 1);
return v;
}
void FileAccessNetwork::_queue_page(int32_t p_page) const {
if (p_page >= pages.size()) {
void FileAccessNetwork::_queue_page(int p_page) const {
if (p_page >= pages.size())
return;
}
if (pages[p_page].buffer.empty() && !pages[p_page].queued) {
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->blockrequest_mutex.lock();
nc->blockrequest_mutex->lock();
FileAccessNetworkClient::BlockRequest br;
br.id = id;
br.offset = (uint64_t)p_page * page_size;
br.offset = size_t(p_page) * page_size;
br.size = page_size;
nc->block_requests.push_back(br);
pages.write[p_page].queued = true;
nc->blockrequest_mutex.unlock();
nc->blockrequest_mutex->unlock();
DEBUG_PRINT("QUEUE PAGE POST");
nc->sem.post();
nc->sem->post();
DEBUG_PRINT("queued " + itos(p_page));
}
}
uint64_t FileAccessNetwork::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
int FileAccessNetwork::get_buffer(uint8_t *p_dst, int p_length) const {
//bool eof=false;
if (pos + p_length > total_size) {
eof_flag = true;
}
@@ -377,27 +406,35 @@ uint64_t FileAccessNetwork::get_buffer(uint8_t *p_dst, uint64_t p_length) const
p_length = total_size - pos;
}
//FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
uint8_t *buff = last_page_buff;
for (uint64_t i = 0; i < p_length; i++) {
int32_t page = pos / page_size;
for (int i = 0; i < p_length; i++) {
int page = pos / page_size;
if (page != last_page) {
buffer_mutex.lock();
buffer_mutex->lock();
if (pages[page].buffer.empty()) {
waiting_on_page = page;
for (int32_t j = 0; j < read_ahead; j++) {
for (int j = 0; j < read_ahead; j++) {
_queue_page(page + j);
}
buffer_mutex.unlock();
buffer_mutex->unlock();
DEBUG_PRINT("wait");
page_sem.wait();
page_sem->wait();
DEBUG_PRINT("done");
} else {
for (int32_t j = 0; j < read_ahead; j++) {
for (int j = 0; j < read_ahead; j++) {
_queue_page(page + j);
}
buffer_mutex.unlock();
buff = pages.write[page].buffer.ptrw();
//queue pages
buffer_mutex->unlock();
}
buff = pages.write[page].buffer.ptrw();
@@ -413,6 +450,7 @@ uint64_t FileAccessNetwork::get_buffer(uint8_t *p_dst, uint64_t p_length) const
}
Error FileAccessNetwork::get_error() const {
return pos == total_size ? ERR_FILE_EOF : OK;
}
@@ -421,10 +459,12 @@ void FileAccessNetwork::flush() {
}
void FileAccessNetwork::store_8(uint8_t p_dest) {
ERR_FAIL();
}
bool FileAccessNetwork::file_exists(const String &p_path) {
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->lock_mutex();
nc->put_32(id);
@@ -434,13 +474,14 @@ bool FileAccessNetwork::file_exists(const String &p_path) {
nc->client->put_data((const uint8_t *)cs.ptr(), cs.length());
nc->unlock_mutex();
DEBUG_PRINT("FILE EXISTS POST");
nc->sem.post();
sem.wait();
nc->sem->post();
sem->wait();
return exists_modtime != 0;
}
uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) {
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->lock_mutex();
nc->put_32(id);
@@ -450,23 +491,14 @@ uint64_t FileAccessNetwork::_get_modified_time(const String &p_file) {
nc->client->put_data((const uint8_t *)cs.ptr(), cs.length());
nc->unlock_mutex();
DEBUG_PRINT("MODTIME POST");
nc->sem.post();
sem.wait();
nc->sem->post();
sem->wait();
return exists_modtime;
}
uint32_t FileAccessNetwork::_get_unix_permissions(const String &p_file) {
ERR_PRINT("Getting UNIX permissions from network drives is not implemented yet");
return 0;
}
Error FileAccessNetwork::_set_unix_permissions(const String &p_file, uint32_t p_permissions) {
ERR_PRINT("Setting UNIX permissions on network drives is not implemented yet");
return ERR_UNAVAILABLE;
}
void FileAccessNetwork::configure() {
GLOBAL_DEF("network/remote_fs/page_size", 65536);
ProjectSettings::get_singleton()->set_custom_property_info("network/remote_fs/page_size", PropertyInfo(Variant::INT, "network/remote_fs/page_size", PROPERTY_HINT_RANGE, "1,65536,1,or_greater")); //is used as denominator and can't be zero
GLOBAL_DEF("network/remote_fs/page_read_ahead", 4);
@@ -474,9 +506,13 @@ void FileAccessNetwork::configure() {
}
FileAccessNetwork::FileAccessNetwork() {
eof_flag = false;
opened = false;
pos = 0;
sem = Semaphore::create();
page_sem = Semaphore::create();
buffer_mutex = Mutex::create();
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->lock_mutex();
id = nc->last_id++;
@@ -484,12 +520,17 @@ FileAccessNetwork::FileAccessNetwork() {
nc->unlock_mutex();
page_size = GLOBAL_GET("network/remote_fs/page_size");
read_ahead = GLOBAL_GET("network/remote_fs/page_read_ahead");
last_activity_val = 0;
waiting_on_page = -1;
last_page = -1;
}
FileAccessNetwork::~FileAccessNetwork() {
close();
memdelete(sem);
memdelete(page_sem);
memdelete(buffer_mutex);
FileAccessNetworkClient *nc = FileAccessNetworkClient::singleton;
nc->lock_mutex();

Some files were not shown because too many files have changed in this diff Show More