Skip to content

Commit

Permalink
Merge pull request godotengine#35 from lawnjelly/plus_sync
Browse files Browse the repository at this point in the history
Plus sync
  • Loading branch information
lawnjelly authored May 14, 2023
2 parents d8de7a7 + 6f871c1 commit f84239c
Show file tree
Hide file tree
Showing 58 changed files with 1,445 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/javascript_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v3

- name: Set up Emscripten latest
uses: mymindstorm/setup-emsdk@v11
uses: mymindstorm/setup-emsdk@v12
with:
version: ${{env.EM_VERSION}}
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
Expand Down
1 change: 1 addition & 0 deletions core/math/basis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
// as we have reached here there are no singularities so we can handle normally
real_t s = Math::sqrt((elements[1][2] - elements[2][1]) * (elements[1][2] - elements[2][1]) + (elements[2][0] - elements[0][2]) * (elements[2][0] - elements[0][2]) + (elements[0][1] - elements[1][0]) * (elements[0][1] - elements[1][0])); // s=|axis||sin(angle)|, used to normalise

// acos does clamping.
angle = Math::acos((elements[0][0] + elements[1][1] + elements[2][2] - 1) / 2);
if (angle < 0) {
s = -s;
Expand Down
10 changes: 6 additions & 4 deletions core/math/math_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ class Math {
static _ALWAYS_INLINE_ double tanh(double p_x) { return ::tanh(p_x); }
static _ALWAYS_INLINE_ float tanh(float p_x) { return ::tanhf(p_x); }

static _ALWAYS_INLINE_ double asin(double p_x) { return ::asin(p_x); }
static _ALWAYS_INLINE_ float asin(float p_x) { return ::asinf(p_x); }
// Always does clamping so always safe to use.
static _ALWAYS_INLINE_ double asin(double p_x) { return p_x < -1 ? (-Math_PI / 2) : (p_x > 1 ? (Math_PI / 2) : ::asin(p_x)); }
static _ALWAYS_INLINE_ float asin(float p_x) { return p_x < -1 ? (-Math_PI / 2) : (p_x > 1 ? (Math_PI / 2) : ::asinf(p_x)); }

static _ALWAYS_INLINE_ double acos(double p_x) { return ::acos(p_x); }
static _ALWAYS_INLINE_ float acos(float p_x) { return ::acosf(p_x); }
// Always does clamping so always safe to use.
static _ALWAYS_INLINE_ double acos(double p_x) { return p_x < -1 ? Math_PI : (p_x > 1 ? 0 : ::acos(p_x)); }
static _ALWAYS_INLINE_ float acos(float p_x) { return p_x < -1 ? Math_PI : (p_x > 1 ? 0 : ::acosf(p_x)); }

static _ALWAYS_INLINE_ double atan(double p_x) { return ::atan(p_x); }
static _ALWAYS_INLINE_ float atan(float p_x) { return ::atanf(p_x); }
Expand Down
4 changes: 3 additions & 1 deletion core/math/quat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@

real_t Quat::angle_to(const Quat &p_to) const {
real_t d = dot(p_to);
return Math::acos(CLAMP(d * d * 2 - 1, -1, 1));

// acos does clamping.
return Math::acos(d * d * 2 - 1);
}

// set_euler_xyz expects a vector containing the Euler angles in the format
Expand Down
6 changes: 3 additions & 3 deletions core/math/transform_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Transform2D Transform2D::inverse() const {
}

void Transform2D::affine_invert() {
real_t det = basis_determinant();
real_t det = determinant();
#ifdef MATH_CHECKS
ERR_FAIL_COND(det == 0);
#endif
Expand Down Expand Up @@ -93,7 +93,7 @@ Transform2D::Transform2D(real_t p_rot, const Vector2 &p_pos) {
}

Size2 Transform2D::get_scale() const {
real_t det_sign = SGN(basis_determinant());
real_t det_sign = SGN(determinant());
return Size2(elements[0].length(), det_sign * elements[1].length());
}

Expand Down Expand Up @@ -217,7 +217,7 @@ Transform2D Transform2D::rotated(real_t p_angle) const {
return copy;
}

real_t Transform2D::basis_determinant() const {
real_t Transform2D::determinant() const {
return elements[0].x * elements[1].y - elements[0].y * elements[1].x;
}

Expand Down
2 changes: 1 addition & 1 deletion core/math/transform_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct _NO_DISCARD_CLASS_ Transform2D {
void translate(real_t p_tx, real_t p_ty);
void translate(const Vector2 &p_translation);

real_t basis_determinant() const;
real_t determinant() const;

Size2 get_scale() const;
void set_scale(const Size2 &p_scale);
Expand Down
2 changes: 1 addition & 1 deletion core/math/transform_interpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void TransformInterpolator::interpolate_transform2D(const Transform2D &p_prev, c

// Special case for physics interpolation, if flipping, don't interpolate basis.
// If the determinant polarity changes, the handedness of the coordinate system changes.
if (_sign(p_prev.basis_determinant()) != _sign(p_curr.basis_determinant())) {
if (_sign(p_prev.determinant()) != _sign(p_curr.determinant())) {
r_result.elements[0] = p_curr.elements[0];
r_result.elements[1] = p_curr.elements[1];
r_result.set_origin(Vector2::linear_interpolate(p1, p2, p_fraction));
Expand Down
4 changes: 2 additions & 2 deletions core/message_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ void MessageQueue::statistics() {
}

int MessageQueue::get_max_buffer_usage() const {
// Note this may be better read_buffer, or a combination, depending when this is read.
return buffers[write_buffer].data.size();
return _buffer_size_monitor.max_size_overall;
}

void MessageQueue::_call_function(Object *p_target, const StringName &p_func, const Variant *p_args, int p_argcount, bool p_show_error) {
Expand Down Expand Up @@ -392,6 +391,7 @@ void MessageQueue::flush() {
_THREAD_SAFE_LOCK_
// keep track of the maximum used size, so we can downsize buffers when appropriate
_buffer_size_monitor.max_size = MAX(buffer_data_size, _buffer_size_monitor.max_size);
_buffer_size_monitor.max_size_overall = MAX(buffer_data_size, _buffer_size_monitor.max_size_overall);

// flip buffers, this is the only part that requires a lock
SWAP(read_buffer, write_buffer);
Expand Down
4 changes: 4 additions & 0 deletions core/message_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class MessageQueue {
struct BufferSizeMonitor {
uint32_t max_size = 0;
uint32_t flush_count = 0;

// Only used for performance statistics.
uint32_t max_size_overall = 0;
} _buffer_size_monitor;

void _call_function(Object *p_target, const StringName &p_func, const Variant *p_args, int p_argcount, bool p_show_error);
Expand Down Expand Up @@ -97,6 +100,7 @@ class MessageQueue {
bool is_flushing() const;

int get_max_buffer_usage() const;
int get_current_buffer_usage() const;

MessageQueue();
~MessageQueue();
Expand Down
2 changes: 2 additions & 0 deletions core/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ struct _VariantCall {
VCALL_PTR1R(Transform2D, translated);
VCALL_PTR2R(Transform2D, interpolate_with);
VCALL_PTR1R(Transform2D, is_equal_approx);
VCALL_PTR0R(Transform2D, determinant);

static void _call_Transform2D_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) {
switch (p_args[0]->type) {
Expand Down Expand Up @@ -2151,6 +2152,7 @@ void register_variant_methods() {
ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, translated, VECTOR2, "offset", varray());
ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform, NIL, "v", varray());
ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform_inv, NIL, "v", varray());
ADDFUNC0R(TRANSFORM2D, REAL, Transform2D, determinant, varray());
ADDFUNC1R(TRANSFORM2D, VECTOR2, Transform2D, basis_xform, VECTOR2, "v", varray());
ADDFUNC1R(TRANSFORM2D, VECTOR2, Transform2D, basis_xform_inv, VECTOR2, "v", varray());
ADDFUNC2R(TRANSFORM2D, TRANSFORM2D, Transform2D, interpolate_with, TRANSFORM2D, "transform", REAL, "weight", varray());
Expand Down
6 changes: 5 additions & 1 deletion doc/classes/CPUParticles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,16 @@
Animation speed randomness ratio.
</member>
<member name="color" type="Color" setter="set_color" getter="get_color" default="Color( 1, 1, 1, 1 )">
Each particle's initial color. To have particle display color in a [SpatialMaterial] make sure to set [member SpatialMaterial.vertex_color_use_as_albedo] to [code]true[/code].
Each particle's initial color.
[b]Note:[/b] [member color] multiplies the particle mesh's vertex colors. To have a visible effect on a [SpatialMaterial], [member SpatialMaterial.vertex_color_use_as_albedo] [i]must[/i] be [code]true[/code]. For a [ShaderMaterial], [code]ALBEDO *= COLOR.rgb;[/code] must be inserted in the shader's [code]fragment()[/code] function. Otherwise, [member color] will have no visible effect.
</member>
<member name="color_initial_ramp" type="Gradient" setter="set_color_initial_ramp" getter="get_color_initial_ramp">
Each particle's initial color will vary along this [GradientTexture] (multiplied with [member color]).
[b]Note:[/b] [member color_initial_ramp] multiplies the particle mesh's vertex colors. To have a visible effect on a [SpatialMaterial], [member SpatialMaterial.vertex_color_use_as_albedo] [i]must[/i] be [code]true[/code]. For a [ShaderMaterial], [code]ALBEDO *= COLOR.rgb;[/code] must be inserted in the shader's [code]fragment()[/code] function. Otherwise, [member color_initial_ramp] will have no visible effect.
</member>
<member name="color_ramp" type="Gradient" setter="set_color_ramp" getter="get_color_ramp">
Each particle's color will vary along this [GradientTexture] over its lifetime (multiplied with [member color]).
[b]Note:[/b] [member color_ramp] multiplies the particle mesh's vertex colors. To have a visible effect on a [SpatialMaterial], [member SpatialMaterial.vertex_color_use_as_albedo] [i]must[/i] be [code]true[/code]. For a [ShaderMaterial], [code]ALBEDO *= COLOR.rgb;[/code] must be inserted in the shader's [code]fragment()[/code] function. Otherwise, [member color_ramp] will have no visible effect.
</member>
<member name="damping" type="float" setter="set_param" getter="get_param" default="0.0">
The rate at which particles lose velocity.
Expand All @@ -155,6 +158,7 @@
</member>
<member name="emission_colors" type="PoolColorArray" setter="set_emission_colors" getter="get_emission_colors">
Sets the [Color]s to modulate particles by when using [constant EMISSION_SHAPE_POINTS] or [constant EMISSION_SHAPE_DIRECTED_POINTS].
[b]Note:[/b] [member emission_colors] multiplies the particle mesh's vertex colors. To have a visible effect on a [SpatialMaterial], [member SpatialMaterial.vertex_color_use_as_albedo] [i]must[/i] be [code]true[/code]. For a [ShaderMaterial], [code]ALBEDO *= COLOR.rgb;[/code] must be inserted in the shader's [code]fragment()[/code] function. Otherwise, [member emission_colors] will have no visible effect.
</member>
<member name="emission_normals" type="PoolVector3Array" setter="set_emission_normals" getter="get_emission_normals">
Sets the direction the particles will be emitted in when using [constant EMISSION_SHAPE_DIRECTED_POINTS].
Expand Down
20 changes: 16 additions & 4 deletions doc/classes/EditorSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,6 @@
<member name="interface/theme/custom_theme" type="String" setter="" getter="">
The custom theme resource to use for the editor. Must be a Godot theme resource in [code].tres[/code] or [code].res[/code] format.
</member>
<member name="interface/theme/enable_touchscreen_touch_area" type="bool" setter="" getter="">
If [code]true[/code], increases the touch area for the UI elements to improve usability on touchscreen devices.
[b]Note:[/b] Defaults to [code]true[/code] on touchscreen devices.
</member>
<member name="interface/theme/highlight_tabs" type="bool" setter="" getter="">
If [code]true[/code], makes the background of selected tabs more contrasted in the editor theme (brighter on dark themes, darker on light themes).
</member>
Expand All @@ -532,6 +528,22 @@
<member name="interface/theme/use_graph_node_headers" type="bool" setter="" getter="">
If [code]true[/code], use colored header backgrounds for individual [GraphNode]s in the visual script and visual shader editors. This can improve usability when frequently using these editors at low zoom levels.
</member>
<member name="interface/touchscreen/enable_long_press_as_right_click" type="bool" setter="" getter="">
If [code]true[/code], long press on touchscreen is treated as right click.
[b]Note:[/b] Defaults to [code]true[/code] on touchscreen devices.
</member>
<member name="interface/touchscreen/enable_pan_and_scale_gestures" type="bool" setter="" getter="">
If [code]true[/code], enable two finger pan and scale gestures on touchscreen devices.
[b]Note:[/b] Defaults to [code]true[/code] on touchscreen devices.
</member>
<member name="interface/touchscreen/increase_scrollbar_touch_area" type="bool" setter="" getter="">
If [code]true[/code], increases the scrollbar touch area to improve usability on touchscreen devices.
[b]Note:[/b] Defaults to [code]true[/code] on touchscreen devices.
</member>
<member name="interface/touchscreen/scale_gizmo_handles" type="float" setter="" getter="">
Specify the multiplier to apply to the scale for the editor gizmo handles to improve usability on touchscreen devices.
[b]Note:[/b] Defaults to [code]1[/code] on non-touchscreen devices.
</member>
<member name="network/debug/remote_host" type="String" setter="" getter="">
The address to listen to when starting the remote debugger. This can be set to [code]0.0.0.0[/code] to allow external clients to connect to the remote debugger (instead of restricting the remote debugger to connections from [code]localhost[/code]).
</member>
Expand Down
6 changes: 5 additions & 1 deletion doc/classes/ParticlesMaterial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,16 @@
Animation speed randomness ratio.
</member>
<member name="color" type="Color" setter="set_color" getter="get_color" default="Color( 1, 1, 1, 1 )">
Each particle's initial color. If the [Particles2D]'s [code]texture[/code] is defined, it will be multiplied by this color. To have particle display color in a [SpatialMaterial] make sure to set [member SpatialMaterial.vertex_color_use_as_albedo] to [code]true[/code].
Each particle's initial color. If the [Particles2D]'s or [Particles]'s [code]texture[/code] is defined, it will be multiplied by this color.
[b]Note:[/b] [member color] multiplies the particle mesh's vertex colors. To have a visible effect on a [SpatialMaterial], [member SpatialMaterial.vertex_color_use_as_albedo] [i]must[/i] be [code]true[/code]. For a [ShaderMaterial], [code]ALBEDO *= COLOR.rgb;[/code] must be inserted in the shader's [code]fragment()[/code] function. Otherwise, [member color] will have no visible effect.
</member>
<member name="color_initial_ramp" type="Texture" setter="set_color_initial_ramp" getter="get_color_initial_ramp">
Each particle's initial color will vary along this [GradientTexture] (multiplied with [member color]).
[b]Note:[/b] [member color_initial_ramp] multiplies the particle mesh's vertex colors. To have a visible effect on a [SpatialMaterial], [member SpatialMaterial.vertex_color_use_as_albedo] [i]must[/i] be [code]true[/code]. For a [ShaderMaterial], [code]ALBEDO *= COLOR.rgb;[/code] must be inserted in the shader's [code]fragment()[/code] function. Otherwise, [member color_initial_ramp] will have no visible effect.
</member>
<member name="color_ramp" type="Texture" setter="set_color_ramp" getter="get_color_ramp">
Each particle's color will vary along this [GradientTexture] over its lifetime (multiplied with [member color]).
[b]Note:[/b] [member color_ramp] multiplies the particle mesh's vertex colors. To have a visible effect on a [SpatialMaterial], [member SpatialMaterial.vertex_color_use_as_albedo] [i]must[/i] be [code]true[/code]. For a [ShaderMaterial], [code]ALBEDO *= COLOR.rgb;[/code] must be inserted in the shader's [code]fragment()[/code] function. Otherwise, [member color_ramp] will have no visible effect.
</member>
<member name="damping" type="float" setter="set_param" getter="get_param" default="0.0">
The rate at which particles lose velocity.
Expand All @@ -137,6 +140,7 @@
</member>
<member name="emission_color_texture" type="Texture" setter="set_emission_color_texture" getter="get_emission_color_texture">
Particle color will be modulated by color determined by sampling this texture at the same point as the [member emission_point_texture].
[b]Note:[/b] [member emission_color_texture] multiplies the particle mesh's vertex colors. To have a visible effect on a [SpatialMaterial], [member SpatialMaterial.vertex_color_use_as_albedo] [i]must[/i] be [code]true[/code]. For a [ShaderMaterial], [code]ALBEDO *= COLOR.rgb;[/code] must be inserted in the shader's [code]fragment()[/code] function. Otherwise, [member emission_color_texture] will have no visible effect.
</member>
<member name="emission_normal_texture" type="Texture" setter="set_emission_normal_texture" getter="get_emission_normal_texture">
Particle velocity and rotation will be set by sampling this texture at the same point as the [member emission_point_texture]. Used only in [constant EMISSION_SHAPE_DIRECTED_POINTS]. Can be created automatically from mesh or node by selecting "Create Emission Points from Mesh/Node" under the "Particles" tool in the toolbar.
Expand Down
3 changes: 2 additions & 1 deletion doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1584,9 +1584,10 @@
<member name="rendering/gles3/shaders/shader_compilation_mode" type="int" setter="" getter="" default="0">
If set to [code]Asynchronous[/code] and available on the target device, asynchronous compilation of shaders is enabled (in contrast to [code]Asynchronous[/code]).
That means that when a shader is first used under some new rendering situation, the game won't stall while such shader is being compiled. Instead, a fallback will be used and the real shader will be compiled in the background. Once the actual shader is compiled, it will be used the next times it's used to draw a frame.
Depending on the async mode configured for a given material/shader, the fallback will be an "ubershader" (the default) or just skip rendering any item it is applied to.
Depending on the [member SpatialMaterial.async_mode] mode configured for a given material, the fallback will be an "ubershader" (the default) or just skip rendering any item it is applied to. In custom [ShaderMaterial]s, the async mode is set using [code]render_mode async_visible;[/code] (default) or [code]render_mode async_hidden;[/code] at the top of the shader.
An ubershader is a very complex shader, slow but suited to any rendering situation, that the engine generates internally so it can be used from the beginning while the traditional conditioned, optimized version of it is being compiled.
To reduce loading times after the project has been launched at least once, you can use [code]Asynchronous + Cache[/code]. This also causes the ubershaders to be cached into storage so they can be ready faster next time they are used (provided the platform provides support for it).
[b]Note:[/b] Asynchronous compilation requires driver support for the [code]GL_ARB_get_program_binary[/code] OpenGL extension. This extension is supported by all hardware that supports OpenGL 4.1 or higher as well as most hardware that supports OpenGL 3.3 or higher.
[b]Note:[/b] Asynchronous compilation is currently only supported for spatial (3D) and particle materials/shaders. CanvasItem (2D) shaders will not use asynchronous compilation even if this setting is set to [code]Asynchronous[/code] or [code]Asynchronous + Cache[/code].
</member>
<member name="rendering/gles3/shaders/shader_compilation_mode.mobile" type="int" setter="" getter="" default="0">
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/Transform2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
This method does not account for translation (the origin vector).
</description>
</method>
<method name="determinant">
<return type="float" />
<description>
Returns the determinant of the basis matrix. If the basis is uniformly scaled, then its determinant equals the square of the scale factor.
A negative determinant means the basis was flipped, so one part of the scale is negative. A zero determinant means the basis isn't invertible, and is usually considered invalid.
</description>
</method>
<method name="get_origin">
<return type="Vector2" />
<description>
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles2/rasterizer_canvas_base_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ void RasterizerCanvasBaseGLES2::canvas_light_shadow_buffer_update(RID p_buffer,
VS::CanvasOccluderPolygonCullMode transformed_cull_cache = instance->cull_cache;

if (transformed_cull_cache != VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED &&
(p_light_xform.basis_determinant() * instance->xform_cache.basis_determinant()) < 0) {
(p_light_xform.determinant() * instance->xform_cache.determinant()) < 0) {
transformed_cull_cache = (transformed_cull_cache == VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE)
? VS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE
: VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/rasterizer_canvas_base_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ void RasterizerCanvasBaseGLES3::canvas_light_shadow_buffer_update(RID p_buffer,
VS::CanvasOccluderPolygonCullMode transformed_cull_cache = instance->cull_cache;

if (transformed_cull_cache != VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED &&
(p_light_xform.basis_determinant() * instance->xform_cache.basis_determinant()) < 0) {
(p_light_xform.determinant() * instance->xform_cache.determinant()) < 0) {
transformed_cull_cache = (transformed_cull_cache == VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE)
? VS::CANVAS_OCCLUDER_POLYGON_CULL_COUNTER_CLOCKWISE
: VS::CANVAS_OCCLUDER_POLYGON_CULL_CLOCKWISE;
Expand Down
Loading

0 comments on commit f84239c

Please sign in to comment.