Commit graph

431 commits

Author SHA1 Message Date
Fabio Alessandrelli dccd71c7a3 JS synchronous start, better persistent FS sync.
The engine now expects to emscripten FS to be setup and sync-ed before
main is called. This is exposed via `Module["initFS"]` which also allows
to setup multiple persistence paths (internal use only for now).

Additionally, FS syncing is done **once** for every loop if at least one
file in a persistent path was open for writing and closed, and if the FS
is not syncing already.

This should potentially fix issues reported by users where "autosave"
would not work on the web (never calling `syncfs` because of too many
writes).
2020-09-23 09:51:06 +02:00
Fabio Alessandrelli 53f04aa1b9 Make canvas resize optional in HTML5. 2020-09-23 09:51:06 +02:00
Fabio Alessandrelli 806edcae5b Better HiDPI support in HTML5. 2020-09-23 09:51:06 +02:00
Fabio Alessandrelli 7d0896e763 Window event listener do not use capture. 2020-09-23 09:51:06 +02:00
Fabio Alessandrelli 48aa0b5b03 Small refactor to JavaScript handlers.
Crated helper class in native/utils.js.
Simplify code in OS/DisplayServer.
2020-09-23 09:51:06 +02:00
Fabio Alessandrelli 7d045b8543 Expose request_quit method to JS in HTML5 export. 2020-09-23 09:51:06 +02:00
Fabio Alessandrelli 27ab97501b [HTML5] Add override keyword, cleanup methods. 2020-09-18 18:48:59 +02:00
Rémi Verschelde 3e78963bb9
Fix typos with codespell
Using codespell 1.17.1.

Method:
```
$ cat > ../godot-word-whitelist.txt << EOF
ang
curvelinear
dof
doubleclick
fave
findn
leapyear
lod
merchantibility
nd
numer
ois
ony
que
seeked
synching
te
uint
unselect
webp
EOF

$ codespell -w -q 3 -I ../godot-word-whitelist.txt --skip="./thirdparty,*.po"
$ git diff // undo unwanted changes
```
2020-09-18 13:44:25 +02:00
Marcel Admiraal 64095245ee Explicitly add implicitly added semicolons. 2020-09-09 15:30:57 +01:00
Rémi Verschelde 6e577a5b80
Merge pull request #40755 from Faless/js/fix_and_cancel_swap
Cancel/OK swap on HTML5 platform, small fixes.
2020-07-27 14:32:48 +02:00
Fabio Alessandrelli 0b286a287c Implement HTML5 cancel/ok button swap on Windows.
Platform is detected on init via the `navigator.platform` string.
2020-07-27 14:17:10 +02:00
Fabio Alessandrelli 3e96ba220e Correctly include <stdlib.h> in javascript main.
Already fixed in 3.2, this header is needed since it's where setenv
is declared and we should not assume it to be already included.
2020-07-27 14:17:10 +02:00
Fabio Alessandrelli 757af6a69f Properly set HTML5 DisplayServer init error value.
Checked in main.cpp, would cause the engine to not load.
2020-07-27 14:17:10 +02:00
RevoluPowered 579342810f t Add unit testing to Godot using DocTest and added to GitHub Actions CI
Implements exit codes into the engine so tests can return their statuses.
Ideally we don't do this, and we use FIXUP logic to 'begin' and 'end' the engine execution for tests specifically.

Since realistically we're initialising the engine here we don't want to do that, since String should not require an engine startup to test a single header.

This lowers the complexity of running the unit tests and even for
physics should be possible to implement such a fix.
2020-07-24 13:05:33 +01:00
Marcel Admiraal 26fcf2b04c Add override keywords. 2020-07-10 13:56:54 +01:00
Fabio Alessandrelli 7a5e10b8a9 Use dummy driver when JS AudioContext is unavailable. 2020-07-01 17:16:13 +02:00
Fabio Alessandrelli 1a637b07b1 Limit FPS in JS by skipping iterations. 2020-07-01 17:16:13 +02:00
Fabio Alessandrelli 07d4513886 [JS] Check canvas size each loop, force redraw.
Fix compatibility issues, achieve smoother resizing.
2020-07-01 17:16:13 +02:00
Fabio Alessandrelli a1c4c1d318 More static methods in DisplayServerJavaScript.
Were static functions in cpp file, polluting global namespace.
2020-07-01 17:16:03 +02:00
Fabio Alessandrelli fd92270b0a Refactor canvas ID and locale handling. 2020-07-01 13:10:05 +02:00
Fabio Alessandrelli 5b1cc2d1fc Fix FS error on JS startup due to existing folder. 2020-07-01 13:10:05 +02:00
Fabio Alessandrelli 5c75cb0133 Immediately run first iteration after JS FS sync.
Which is now run inside an animation frame.
This avoid a 1 frame black screen when setting up the canvas.
2020-06-14 16:04:45 +02:00
Fabio Alessandrelli 0a35b97b62 Swtich HTML5 key detection from keyCode to code.
The value of this, does not include the layout.
The code has extra logic to map the unicode value to our keylist,
supporting ASCII and Latin-1.
Also add support for `physical_keycode` in HTML5 platform.
2020-06-04 21:15:05 +02:00
Fabio Alessandrelli 57bdb4cc35 Fix JS audioContext parameters.
Were not passed along correctly.
`latencyHint` is supposed to be in seconds, not milliseconds.
2020-05-25 15:33:19 +02:00
Fabio Alessandrelli 90c7102b51 Move mix_rate, ouput_latency to AudioDriverManager
Each driver used to define the (same) project settings values
`audio/mix_rate` and `audio/output_latency`, but the setting names are
not driver specific.
Overriding is still possible via platform tags.
2020-05-18 13:02:06 +02:00
Fabio Alessandrelli 245c179bd3 AudioDriverJavaScript now compute buffer size.
Based on mix rate and expected latency.
2020-05-18 13:02:06 +02:00
Rémi Verschelde 0ee0fa42e6 Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
2020-05-14 21:57:34 +02:00
Rémi Verschelde 07bc4e2f96 Style: Enforce separation line between function definitions
I couldn't find a tool that enforces it, so I went the manual route:
```
find -name "thirdparty" -prune \
  -o -name "*.cpp" -o -name "*.h" -o -name "*.m" -o -name "*.mm" \
  -o -name "*.glsl" > files
perl -0777 -pi -e 's/\n}\n([^#])/\n}\n\n\1/g' $(cat files)
misc/scripts/fix_style.sh -c
```

This adds a newline after all `}` on the first column, unless they
are followed by `#` (typically `#endif`). This leads to having lots
of places with two lines between function/class definitions, but
clang-format then fixes it as we enforce max one line of separation.

This doesn't fix potential occurrences of function definitions which
are indented (e.g. for a helper class defined in a .cpp), but it's
better than nothing. Also can't be made to run easily on CI/hooks so
we'll have to be careful with new code.

Part of #33027.
2020-05-14 16:54:55 +02:00
Rémi Verschelde 0be6d925dc Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks
Which means that reduz' beloved style which we all became used to
will now be changed automatically to remove the first empty line.

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

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

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

Also went manually through all of `core` to find occurrences that
`clang-tidy` couldn't handle, especially all initializations done
in a constructor without using initializer lists.
2020-05-14 10:01:56 +02:00
Marcel Admiraal e7fee711b3 Update game controller enums. 2020-05-13 10:33:32 +01:00
Fabio Alessandrelli 3097c2da96 Add WebSocket debugger, use it for Javascript. 2020-05-12 15:09:13 +02:00
Fabio Alessandrelli 6a49b83e39 Add drop files function 2020-05-10 18:22:48 +02:00
Fabio Alessandrelli d2eef39731 Fix Closure compiler build, python style.
Move copyToFS into utils.js library included with '--pre-js'.
2020-05-10 18:22:48 +02:00
Fabio Alessandrelli 7411e7fd37 DisplayServerJavaScript implementation. 2020-05-10 18:22:48 +02:00
Fabio Alessandrelli ee99cd42d5 [HTML5] Locale, input fix, context, exit.
Add missing semicolumns in engine.js
Add optional extra args to JS Engine.startGame
Remove loader.js, explicit noExitRuntime.
Also add onExit callback (undocumented in emscripten)
2020-05-10 18:19:23 +02:00
Rémi Verschelde 69de7ce38c Style: clang-format: Disable AllowShortCaseLabelsOnASingleLine
Part of #33027.
2020-05-10 13:13:54 +02:00
Fabio Alessandrelli c7e662199f
Merge pull request #37414 from Schroedi/fix_html_mouse_input
Move wheel handlers from window to canvas element in HTML
2020-05-01 12:51:35 +02:00
Rémi Verschelde fdf58a5858 Rename InputFilter back to Input
It changed name as part of the DisplayServer and input refactoring
in #37317, with the rationale that input no longer goes through the
main loop, so the previous Input singleton now only does filtering.

But the gains in consistency are quite limited in the renaming, and
it breaks compatibility for all scripts and tutorials that access
the Input singleton via the scripting language. A temporary option
was suggested to keep the scripting singleton named `Input` even if
its type is `InputFilter`, but that adds inconsistency and breaks C#.

Fixes godotengine/godot-proposals#639.
Fixes #37319.
Fixes #37690.
2020-04-28 15:19:49 +02:00
Christoph Schröder b1e8ac7b08 Move mouse wheel handler from window to canvas element in HTML
Similar to https://github.com/godotengine/godot/pull/36557

At least in chrome, the following error is printed for each mouse wheel
rotation:
[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/6662647093133312

This PR moves the handler to the canvas and thereby fixes the error.

Tested on: Chrome and Firefox (MacOS), Firefox, Chrome(Android), Safari (IPad + MacOS)
2020-04-28 08:42:41 +02:00
Hugo Locurcio eecce139ea Set the title tag in the HTML5 export immediately
This makes the project title display without having to wait for
the project to finish loading.
2020-04-22 11:31:14 +02:00
lupoDharkael 95a1400a2a Replace NULL with nullptr 2020-04-02 13:38:00 +02:00
Rémi Verschelde cd4e46ee65 SCons: Format buildsystem files with psf/black
Configured for a max line length of 120 characters.

psf/black is very opinionated and purposely doesn't leave much room for
configuration. The output is mostly OK so that should be fine for us,
but some things worth noting:

- Manually wrapped strings will be reflowed, so by using a line length
  of 120 for the sake of preserving readability for our long command
  calls, it also means that some manually wrapped strings are back on
  the same line and should be manually merged again.

- Code generators using string concatenation extensively look awful,
  since black puts each operand on a single line. We need to refactor
  these generators to use more pythonic string formatting, for which
  many options are available (`%`, `format` or f-strings).

- CI checks and a pre-commit hook will be added to ensure that future
  buildsystem changes are well-formatted.
2020-03-30 09:05:53 +02:00
Juan Linietsky a6f3bc7c69 Renaming of servers for coherency.
VisualServer -> RenderingServer
PhysicsServer -> PhysicsServer3D
Physics2DServer -> PhysicsServer2D
NavigationServer -> NavigationServer3D
Navigation2DServer -> NavigationServer2D

Also renamed corresponding files.
2020-03-27 15:21:27 -03:00
Juan Linietsky 8e6960a69e Refactored input, goes all via windows now.
Also renamed Input to InputFilter because all it does is filter events.
2020-03-26 15:49:39 +01:00
Juan Linietsky 4396e98834 Refactored Input, create DisplayServer and DisplayServerX11 2020-03-26 15:49:32 +01:00
Rajat Goswami 2ecf928ae3 Adding missing include guards to header files identified by LGTM.
This addresses the issue godotengine/godot#37143
2020-03-23 04:52:36 -04:00
Rémi Verschelde cb282c6ef0 Style: Set clang-format Standard to Cpp11
For us, it practically only changes the fact that `A<A<int>>` is now
used instead of the C++03 compatible `A<A<int> >`.

Note: clang-format 10+ changed the `Standard` arguments to fully
specified `c++11`, `c++14`, etc. versions, but we can't use `c++17`
now if we want to preserve compatibility with clang-format 8 and 9.
`Cpp11` is still supported as deprecated alias for `Latest`.
2020-03-17 07:36:24 +01:00
Fabio Alessandrelli 919bbf8077 [HTML5] Refactor JS, threads support, closures.
- Refactored the Engine code, splitted across files.
- Use MODULARIZE option to build emscripten code into it's own closure.
- Enable lto support (saves ~2MiB in release).
- Enable optional closure compiler pass for JS and generated code.
- Enable optional pthreads support.
- Can now build with tools=yes (not much to see yet).
- Dropped some deprecated code for older toolchains.
2020-03-11 16:09:31 +01:00