feat: updated engine

This commit is contained in:
Sara Gerretsen 2026-07-10 17:04:34 +02:00
parent cbe99774ff
commit f4cf6b3999
6607 changed files with 910135 additions and 430025 deletions

View file

@ -31,12 +31,17 @@
#include "gpu_particles_2d.h"
#include "gpu_particles_2d.compat.inc"
#include "core/config/engine.h"
#include "core/object/callable_mp.h"
#include "core/object/class_db.h"
#include "core/os/os.h"
#include "scene/2d/cpu_particles_2d.h"
#include "scene/resources/atlas_texture.h"
#include "scene/resources/canvas_item_material.h"
#include "scene/resources/curve_texture.h"
#include "scene/resources/gradient_texture.h"
#include "scene/resources/particle_process_material.h"
#include "servers/rendering/rendering_server.h"
void GPUParticles2D::set_emitting(bool p_emitting) {
// Do not return even if `p_emitting == emitting` because `emitting` is just an approximation.
@ -181,7 +186,7 @@ void GPUParticles2D::set_trail_enabled(bool p_enabled) {
queue_redraw();
update_configuration_warnings();
RS::get_singleton()->particles_set_transform_align(particles, p_enabled ? RS::PARTICLES_TRANSFORM_ALIGN_Y_TO_VELOCITY : RS::PARTICLES_TRANSFORM_ALIGN_DISABLED);
RS::get_singleton()->particles_set_transform_align(particles, p_enabled ? RSE::PARTICLES_TRANSFORM_ALIGN_Y_TO_VELOCITY : RSE::PARTICLES_TRANSFORM_ALIGN_DISABLED);
}
void GPUParticles2D::set_trail_lifetime(double p_seconds) {
@ -307,7 +312,7 @@ double GPUParticles2D::get_speed_scale() const {
void GPUParticles2D::set_draw_order(DrawOrder p_order) {
draw_order = p_order;
RS::get_singleton()->particles_set_draw_order(particles, RS::ParticlesDrawOrder(p_order));
RS::get_singleton()->particles_set_draw_order(particles, RSE::ParticlesDrawOrder(p_order));
}
GPUParticles2D::DrawOrder GPUParticles2D::get_draw_order() const {
@ -366,8 +371,15 @@ uint32_t GPUParticles2D::get_seed() const {
return seed;
}
void GPUParticles2D::request_particles_process(real_t p_requested_process_time) {
RS::get_singleton()->particles_request_process_time(particles, p_requested_process_time);
void GPUParticles2D::request_particles_process(real_t p_requested_process_time, real_t p_request_process_time_residual) {
RS::get_singleton()->particles_request_process_time(particles, p_requested_process_time, p_request_process_time_residual);
if (p_requested_process_time > 0.0) {
emitting = true;
RS::get_singleton()->particles_set_emitting(particles, true);
}
if (p_request_process_time_residual > 0.0) {
emitting = false;
}
}
PackedStringArray GPUParticles2D::get_configuration_warnings() const {
@ -428,10 +440,11 @@ Ref<Texture2D> GPUParticles2D::get_texture() const {
}
void GPUParticles2D::_validate_property(PropertyInfo &p_property) const {
if (p_property.name == "seed" && !use_fixed_seed) {
p_property.usage = PROPERTY_USAGE_NONE;
}
if (Engine::get_singleton()->is_editor_hint() && p_property.name == "emitting") {
if (p_property.name == "seed") {
if (!use_fixed_seed) {
p_property.usage = PROPERTY_USAGE_NONE;
}
} else if (Engine::get_singleton()->is_editor_hint() && p_property.name == "emitting") {
p_property.hint = one_shot ? PROPERTY_HINT_ONESHOT : PROPERTY_HINT_NONE;
}
}
@ -574,16 +587,16 @@ void GPUParticles2D::convert_from_particles(Node *p_particles) {
proc_mat->set_gravity(Vector3(gravity.x, gravity.y, 0));
proc_mat->set_lifetime_randomness(cpu_particles->get_lifetime_randomness());
#define CONVERT_PARAM(m_param) \
#define CONVERT_PARAM(m_param) \
proc_mat->set_param_min(ParticleProcessMaterial::m_param, cpu_particles->get_param_min(CPUParticles2D::m_param)); \
{ \
Ref<Curve> curve = cpu_particles->get_param_curve(CPUParticles2D::m_param); \
if (curve.is_valid()) { \
Ref<CurveTexture> tex = memnew(CurveTexture); \
tex->set_curve(curve); \
proc_mat->set_param_texture(ParticleProcessMaterial::m_param, tex); \
} \
} \
{ \
Ref<Curve> curve = cpu_particles->get_param_curve(CPUParticles2D::m_param); \
if (curve.is_valid()) { \
Ref<CurveTexture> tex = memnew(CurveTexture); \
tex->set_curve(curve); \
proc_mat->set_param_texture(ParticleProcessMaterial::m_param, tex); \
} \
} \
proc_mat->set_param_max(ParticleProcessMaterial::m_param, cpu_particles->get_param_max(CPUParticles2D::m_param));
CONVERT_PARAM(PARAM_INITIAL_LINEAR_VELOCITY);
@ -668,14 +681,14 @@ void GPUParticles2D::_notification(int p_what) {
}
Array arr;
arr.resize(RS::ARRAY_MAX);
arr[RS::ARRAY_VERTEX] = points;
arr[RS::ARRAY_TEX_UV] = uvs;
arr[RS::ARRAY_BONES] = bone_indices;
arr[RS::ARRAY_WEIGHTS] = bone_weights;
arr[RS::ARRAY_INDEX] = indices;
arr.resize(RSE::ARRAY_MAX);
arr[RSE::ARRAY_VERTEX] = points;
arr[RSE::ARRAY_TEX_UV] = uvs;
arr[RSE::ARRAY_BONES] = bone_indices;
arr[RSE::ARRAY_WEIGHTS] = bone_weights;
arr[RSE::ARRAY_INDEX] = indices;
RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES);
RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RSE::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RSE::ARRAY_FLAG_USE_2D_VERTICES);
Vector<Transform3D> xforms;
for (int i = 0; i <= trail_sections; i++) {
@ -717,12 +730,12 @@ void GPUParticles2D::_notification(int p_what) {
Vector<int> indices = { 0, 1, 2, 0, 2, 3 };
Array arr;
arr.resize(RS::ARRAY_MAX);
arr[RS::ARRAY_VERTEX] = points;
arr[RS::ARRAY_TEX_UV] = uvs;
arr[RS::ARRAY_INDEX] = indices;
arr.resize(RSE::ARRAY_MAX);
arr[RSE::ARRAY_VERTEX] = points;
arr[RSE::ARRAY_TEX_UV] = uvs;
arr[RSE::ARRAY_INDEX] = indices;
RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES);
RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RSE::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RSE::ARRAY_FLAG_USE_2D_VERTICES);
RS::get_singleton()->particles_set_trail_bind_poses(particles, Vector<Transform3D>());
}
RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid);
@ -878,7 +891,7 @@ void GPUParticles2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collision_base_size", "size"), &GPUParticles2D::set_collision_base_size);
ClassDB::bind_method(D_METHOD("set_interp_to_end", "interp"), &GPUParticles2D::set_interp_to_end);
ClassDB::bind_method(D_METHOD("request_particles_process", "process_time"), &GPUParticles2D::request_particles_process);
ClassDB::bind_method(D_METHOD("request_particles_process", "process_time", "process_time_residual"), &GPUParticles2D::request_particles_process, DEFVAL(0));
ClassDB::bind_method(D_METHOD("is_emitting"), &GPUParticles2D::is_emitting);
ClassDB::bind_method(D_METHOD("get_amount"), &GPUParticles2D::get_amount);
@ -942,7 +955,7 @@ void GPUParticles2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "1,1000000,1,exp"), "set_amount", "get_amount"); // FIXME: Evaluate support for `exp` in integer properties, or remove this.
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "amount_ratio", PROPERTY_HINT_RANGE, "0,1,0.0001"), "set_amount_ratio", "get_amount_ratio");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "sub_emitter", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "GPUParticles2D"), "set_sub_emitter", "get_sub_emitter");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, Texture2D::get_class_static()), "set_texture", "get_texture");
ADD_GROUP("Time", "");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lifetime", PROPERTY_HINT_RANGE, "0.01,600.0,0.01,or_greater,exp,suffix:s"), "set_lifetime", "get_lifetime");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "interp_to_end", PROPERTY_HINT_RANGE, "0.00,1.0,0.001"), "set_interp_to_end", "get_interp_to_end");
@ -984,7 +997,7 @@ void GPUParticles2D::_bind_methods() {
GPUParticles2D::GPUParticles2D() {
particles = RS::get_singleton()->particles_create();
RS::get_singleton()->particles_set_mode(particles, RS::PARTICLES_MODE_2D);
RS::get_singleton()->particles_set_mode(particles, RSE::PARTICLES_MODE_2D);
mesh = RS::get_singleton()->mesh_create();
RS::get_singleton()->particles_set_draw_passes(particles, 1);