Commit graph

422 commits

Author SHA1 Message Date
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
Fabio Alessandrelli bd04ede5ad AudioDriverJavascript uses IDHandler.
This makes closure compiler happy, avoiding globals and potentially
undefined variables.
2020-03-11 11:34:32 +01:00
Fabio Alessandrelli aa8c825855 OS_Javascript temporarly uses dummy rasterizer. 2020-03-08 03:35:13 +01:00
Fabio Alessandrelli fd035c931d Fix Javascript platform after PoolVector removal.
Eval should be rechecked.
2020-03-08 03:35:13 +01:00
Fabio Alessandrelli 80582ffa66
Merge pull request #36557 from Schroedi/fix_html_touch
Fixes touch events for HTML
2020-03-03 16:08:18 +01:00
Rémi Verschelde e2b66cacf7
Merge pull request #18020 from bruvzg/input_fix_non_latin_and_add_hw_scancodes
Fix non-latin layout scancodes on Linux, adds access to physical scancodes.
2020-03-01 23:00:42 +01:00
Pedro J. Estébanez 18fbdbb456 Reimplement Mutex with C++'s <mutex>
Main:
- It's now implemented thanks to `<mutex>`. No more platform-specific implementations.
- `BinaryMutex` (non-recursive) is added, as an alternative for special cases.
- Doesn't need allocation/deallocation anymore. It can live in the stack and be part of other classes.
- Because of that, it's methods are now `const` and the inner mutex is `mutable` so it can be easily used in `const` contexts.
- A no-op implementation is provided if `NO_THREADS` is defined. No more need to add `#ifdef NO_THREADS` just for this.
- `MutexLock` now takes a reference. At this point the cases of null `Mutex`es are rare. If you ever need that, just don't use `MutexLock`.
- Thread-safe utilities are therefore simpler now.

Misc.:
- `ScopedMutexLock` is dropped and replaced by `MutexLock`, because they were pretty much the same.
- Every case of lock, do-something, unlock is replaced by `MutexLock` (complex cases where it's not straightfoward are kept as as explicit lock and unlock).
- `ShaderRD` contained an `std::mutex`, which has been replaced by `Mutex`.
2020-02-26 20:40:10 +01:00
Christoph Schroeder 5134317afc Fixes touch events for HTML
Without this patch, the following exception is thrown when the touch
screen is used: TypeError: e.getBoundingClientRect is not a function.
No touch events arrive in the engine.

From my testing, this PR fixes the issue and behaves as expected.

Tested with godot-demo-projects/misc/multitouch_view/, emscripten 1.39.8
and Firefox mobile emulator as well as FF on Android
2020-02-26 12:04:18 +01:00
Juan Linietsky 33b5c57199 Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.

Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.

For Variant, the float datatype is always 64 bits, and exposed as `float`.

We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.

Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-25 12:55:53 +01:00
bruvzg 1af06d3d46
Rename scancode to keycode.
Add `physical_keycode` (keyboard layout independent keycodes) to InputEventKey and InputMap.
Fix non-latin keyboard layout keycodes on Linux/X11 (fallback to physical keycodes).
2020-02-25 12:30:33 +02:00