2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* particles_2d.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* 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 "particles_2d.h"
|
2017-02-25 14:06:00 +00:00
|
|
|
#include "scene/scene_string_names.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void ParticleAttractor2D::_notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_what) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_update_owner();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
if (!get_tree()->is_editor_hint())
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Vector2 pv;
|
2017-03-05 15:44:50 +00:00
|
|
|
float dr = MIN(disable_radius, radius);
|
|
|
|
for (int i = 0; i <= 32; i++) {
|
|
|
|
Vector2 v(Math::sin(i / 32.0 * Math_PI * 2), Math::cos(i / 32.0 * Math_PI * 2));
|
|
|
|
if (i > 0) {
|
|
|
|
draw_line(pv * radius, v * radius, Color(0, 0, 0.5, 0.9));
|
|
|
|
if (dr > 0) {
|
|
|
|
draw_line(pv * dr, v * dr, Color(0.5, 0, 0.0, 0.9));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
pv = v;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2014-11-06 00:20:42 +00:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2014-02-10 01:10:30 +00:00
|
|
|
if (owner) {
|
|
|
|
_set_owner(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleAttractor2D::_owner_exited() {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!owner);
|
|
|
|
owner->attractors.erase(this);
|
2017-03-05 15:44:50 +00:00
|
|
|
owner = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleAttractor2D::_update_owner() {
|
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
if (!is_inside_tree() || !has_node(path)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
_set_owner(NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *n = get_node(path);
|
|
|
|
ERR_FAIL_COND(!n);
|
|
|
|
Particles2D *pn = n->cast_to<Particles2D>();
|
|
|
|
if (!pn) {
|
|
|
|
_set_owner(NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_set_owner(pn);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ParticleAttractor2D::_set_owner(Particles2D *p_owner) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (owner == p_owner)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (owner) {
|
2017-03-05 15:44:50 +00:00
|
|
|
owner->disconnect("tree_exited", this, "_owner_exited");
|
2014-02-10 01:10:30 +00:00
|
|
|
owner->attractors.erase(this);
|
2017-03-05 15:44:50 +00:00
|
|
|
owner = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
owner = p_owner;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (owner) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
owner->connect("tree_exited", this, "_owner_exited", varray(), CONNECT_ONESHOT);
|
2014-02-10 01:10:30 +00:00
|
|
|
owner->attractors.insert(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleAttractor2D::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &ParticleAttractor2D::set_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_enabled"), &ParticleAttractor2D::is_enabled);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_radius", "radius"), &ParticleAttractor2D::set_radius);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_radius"), &ParticleAttractor2D::get_radius);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_disable_radius", "radius"), &ParticleAttractor2D::set_disable_radius);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_disable_radius"), &ParticleAttractor2D::get_disable_radius);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &ParticleAttractor2D::set_gravity);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_gravity"), &ParticleAttractor2D::get_gravity);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_absorption", "absorption"), &ParticleAttractor2D::set_absorption);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_absorption"), &ParticleAttractor2D::get_absorption);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_particles_path", "path"), &ParticleAttractor2D::set_particles_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_particles_path"), &ParticleAttractor2D::get_particles_path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius", PROPERTY_HINT_RANGE, "0.1,16000,0.1"), "set_radius", "get_radius");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "disable_radius", PROPERTY_HINT_RANGE, "0.1,16000,0.1"), "set_disable_radius", "get_disable_radius");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "gravity", PROPERTY_HINT_RANGE, "-512,512,0.01"), "set_gravity", "get_gravity");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "absorption", PROPERTY_HINT_RANGE, "0,512,0.01"), "set_absorption", "get_absorption");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "particles_path", PROPERTY_HINT_RESOURCE_TYPE, "Particles2D"), "set_particles_path", "get_particles_path");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleAttractor2D::set_enabled(bool p_enabled) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
enabled = p_enabled;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool ParticleAttractor2D::is_enabled() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleAttractor2D::set_radius(float p_radius) {
|
|
|
|
|
|
|
|
radius = p_radius;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
float ParticleAttractor2D::get_radius() const {
|
|
|
|
|
|
|
|
return radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleAttractor2D::set_disable_radius(float p_disable_radius) {
|
|
|
|
|
|
|
|
disable_radius = p_disable_radius;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
float ParticleAttractor2D::get_disable_radius() const {
|
|
|
|
|
|
|
|
return disable_radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleAttractor2D::set_gravity(float p_gravity) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
gravity = p_gravity;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
float ParticleAttractor2D::get_gravity() const {
|
|
|
|
|
|
|
|
return gravity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleAttractor2D::set_absorption(float p_absorption) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
absorption = p_absorption;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
float ParticleAttractor2D::get_absorption() const {
|
|
|
|
|
|
|
|
return absorption;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleAttractor2D::set_particles_path(NodePath p_path) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
path = p_path;
|
2014-02-10 01:10:30 +00:00
|
|
|
_update_owner();
|
2016-05-17 21:27:15 +00:00
|
|
|
update_configuration_warning();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
NodePath ParticleAttractor2D::get_particles_path() const {
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2016-05-17 21:27:15 +00:00
|
|
|
String ParticleAttractor2D::get_configuration_warning() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-17 21:27:15 +00:00
|
|
|
if (!has_node(path) || !get_node(path) || !get_node(path)->cast_to<Particles2D>()) {
|
|
|
|
return TTR("Path property must point to a valid Particles2D node to work.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return String();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ParticleAttractor2D::ParticleAttractor2D() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
owner = NULL;
|
|
|
|
radius = 50;
|
|
|
|
disable_radius = 0;
|
|
|
|
gravity = 100;
|
|
|
|
absorption = 0;
|
|
|
|
path = String("..");
|
|
|
|
enabled = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************/
|
|
|
|
|
2017-02-27 21:12:58 +00:00
|
|
|
_FORCE_INLINE_ static float _rand_from_seed(uint64_t *seed) {
|
2017-02-23 08:28:09 +00:00
|
|
|
|
2017-02-27 21:12:58 +00:00
|
|
|
uint32_t r = Math::rand_from_seed(seed);
|
|
|
|
return 2.0f * (float)r / (float)Math::RANDOM_MAX - 1.0f;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Particles2D::_process_particles(float p_delta) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (particles.size() == 0 || lifetime == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p_delta *= time_scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float frame_time = p_delta;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (emit_timeout > 0) {
|
|
|
|
time_to_live -= frame_time;
|
|
|
|
if (time_to_live < 0) {
|
|
|
|
|
|
|
|
emitting = false;
|
2015-04-25 13:36:37 +00:00
|
|
|
_change_notify("config/emitting");
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float next_time = time + frame_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (next_time > lifetime)
|
2017-03-05 15:44:50 +00:00
|
|
|
next_time = Math::fmod(next_time, lifetime);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Particle *pdata = &particles[0];
|
|
|
|
int particle_count = particles.size();
|
2017-01-11 03:52:51 +00:00
|
|
|
Transform2D xform;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!local_space)
|
2017-03-05 15:44:50 +00:00
|
|
|
xform = get_global_transform();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
active_count = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-07 21:25:37 +00:00
|
|
|
PoolVector<Point2>::Read r;
|
2017-03-05 15:44:50 +00:00
|
|
|
int emission_point_count = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (emission_points.size()) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
emission_point_count = emission_points.size();
|
|
|
|
r = emission_points.read();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int attractor_count = 0;
|
|
|
|
AttractorCache *attractor_ptr = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (attractors.size()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (attractors.size() != attractor_cache.size()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
attractor_cache.resize(attractors.size());
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = 0;
|
2017-01-11 03:52:51 +00:00
|
|
|
Transform2D m;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (local_space) {
|
2017-03-05 15:44:50 +00:00
|
|
|
m = get_global_transform().affine_inverse();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Set<ParticleAttractor2D *>::Element *E = attractors.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
attractor_cache[idx].pos = m.xform(E->get()->get_global_position());
|
|
|
|
attractor_cache[idx].attractor = E->get();
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
attractor_ptr = attractor_cache.ptr();
|
|
|
|
attractor_count = attractor_cache.size();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < particle_count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Particle &p = pdata[i];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
float restart_time = (i * lifetime / particle_count) * explosiveness;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool restart = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (next_time < time) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (restart_time > time || restart_time < next_time)
|
|
|
|
restart = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (restart_time > time && restart_time < next_time) {
|
|
|
|
restart = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (restart) {
|
|
|
|
|
|
|
|
if (emitting) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p.pos = emissor_offset;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (emission_point_count) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 ep = r[Math::rand() % emission_point_count];
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!local_space) {
|
2017-03-05 15:44:50 +00:00
|
|
|
p.pos = xform.xform(p.pos + ep * extents);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
p.pos += ep * extents;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!local_space) {
|
2017-03-05 15:44:50 +00:00
|
|
|
p.pos = xform.xform(p.pos + Vector2(Math::random(-extents.x, extents.x), Math::random(-extents.y, extents.y)));
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
p.pos += Vector2(Math::random(-extents.x, extents.x), Math::random(-extents.y, extents.y));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
p.seed = Math::rand() % 12345678;
|
|
|
|
uint64_t rand_seed = p.seed * (i + 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float angle = Math::deg2rad(param[PARAM_DIRECTION] + _rand_from_seed(&rand_seed) * param[PARAM_SPREAD]);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p.velocity = Vector2(Math::sin(angle), Math::cos(angle));
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!local_space) {
|
|
|
|
|
|
|
|
p.velocity = xform.basis_xform(p.velocity).normalized();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p.velocity *= param[PARAM_LINEAR_VELOCITY] + param[PARAM_LINEAR_VELOCITY] * _rand_from_seed(&rand_seed) * randomness[PARAM_LINEAR_VELOCITY];
|
|
|
|
p.velocity += initial_velocity;
|
|
|
|
p.active = true;
|
|
|
|
p.rot = Math::deg2rad(param[PARAM_INITIAL_ANGLE] + param[PARAM_INITIAL_ANGLE] * randomness[PARAM_INITIAL_ANGLE] * _rand_from_seed(&rand_seed));
|
2014-02-10 01:10:30 +00:00
|
|
|
active_count++;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p.frame = Math::fmod(param[PARAM_ANIM_INITIAL_POS] + randomness[PARAM_ANIM_INITIAL_POS] * _rand_from_seed(&rand_seed), 1.0f);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p.active = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (!p.active)
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
uint64_t rand_seed = p.seed * (i + 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector2 force;
|
|
|
|
|
|
|
|
//apply gravity
|
2017-03-05 15:44:50 +00:00
|
|
|
float gravity_dir = Math::deg2rad(param[PARAM_GRAVITY_DIRECTION] + 180 * randomness[PARAM_GRAVITY_DIRECTION] * _rand_from_seed(&rand_seed));
|
|
|
|
force += Vector2(Math::sin(gravity_dir), Math::cos(gravity_dir)) * (param[PARAM_GRAVITY_STRENGTH] + param[PARAM_GRAVITY_STRENGTH] * randomness[PARAM_GRAVITY_STRENGTH] * _rand_from_seed(&rand_seed));
|
2014-02-10 01:10:30 +00:00
|
|
|
//apply radial
|
|
|
|
Vector2 rvec = (p.pos - emissor_offset).normalized();
|
2017-03-05 15:44:50 +00:00
|
|
|
force += rvec * (param[PARAM_RADIAL_ACCEL] + param[PARAM_RADIAL_ACCEL] * randomness[PARAM_RADIAL_ACCEL] * _rand_from_seed(&rand_seed));
|
2014-02-10 01:10:30 +00:00
|
|
|
//apply orbit
|
2017-03-05 15:44:50 +00:00
|
|
|
float orbitvel = (param[PARAM_ORBIT_VELOCITY] + param[PARAM_ORBIT_VELOCITY] * randomness[PARAM_ORBIT_VELOCITY] * _rand_from_seed(&rand_seed));
|
|
|
|
if (orbitvel != 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector2 rel = p.pos - xform.elements[2];
|
2017-03-05 15:44:50 +00:00
|
|
|
Transform2D rot(orbitvel * frame_time, Vector2());
|
2014-02-10 01:10:30 +00:00
|
|
|
p.pos = rot.xform(rel) + xform.elements[2];
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 tvec = rvec.tangent();
|
|
|
|
force += tvec * (param[PARAM_TANGENTIAL_ACCEL] + param[PARAM_TANGENTIAL_ACCEL] * randomness[PARAM_TANGENTIAL_ACCEL] * _rand_from_seed(&rand_seed));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int j = 0; j < attractor_count; j++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector2 vec = (attractor_ptr[j].pos - p.pos);
|
|
|
|
float vl = vec.length();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (!attractor_ptr[j].attractor->enabled || vl == 0 || vl > attractor_ptr[j].attractor->radius)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
force += vec * attractor_ptr[j].attractor->gravity;
|
2014-02-10 01:10:30 +00:00
|
|
|
float fvl = p.velocity.length();
|
|
|
|
if (fvl && attractor_ptr[j].attractor->absorption) {
|
|
|
|
Vector2 target = vec.normalized();
|
2017-03-05 15:44:50 +00:00
|
|
|
p.velocity = p.velocity.normalized().linear_interpolate(target, MIN(frame_time * attractor_ptr[j].attractor->absorption, 1)) * fvl;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attractor_ptr[j].attractor->disable_radius && vl < attractor_ptr[j].attractor->disable_radius) {
|
2017-03-05 15:44:50 +00:00
|
|
|
p.active = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p.velocity += force * frame_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (param[PARAM_DAMPING]) {
|
2017-03-05 15:44:50 +00:00
|
|
|
float dmp = param[PARAM_DAMPING] + param[PARAM_DAMPING] * randomness[PARAM_DAMPING] * _rand_from_seed(&rand_seed);
|
2014-02-10 01:10:30 +00:00
|
|
|
float v = p.velocity.length();
|
|
|
|
v -= dmp * frame_time;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (v <= 0) {
|
|
|
|
p.velocity = Vector2();
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
p.velocity = p.velocity.normalized() * v;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p.pos += p.velocity * frame_time;
|
|
|
|
p.rot += Math::lerp(param[PARAM_SPIN_VELOCITY], param[PARAM_SPIN_VELOCITY] * randomness[PARAM_SPIN_VELOCITY] * _rand_from_seed(&rand_seed), randomness[PARAM_SPIN_VELOCITY]) * frame_time;
|
|
|
|
float anim_spd = param[PARAM_ANIM_SPEED_SCALE] + param[PARAM_ANIM_SPEED_SCALE] * randomness[PARAM_ANIM_SPEED_SCALE] * _rand_from_seed(&rand_seed);
|
|
|
|
p.frame = Math::fposmod(p.frame + (frame_time / lifetime) * anim_spd, 1.0f);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
active_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
time = Math::fmod(time + frame_time, lifetime);
|
|
|
|
if (!emitting && active_count == 0) {
|
2017-02-25 14:06:00 +00:00
|
|
|
emit_signal(SceneStringNames::get_singleton()->emission_finished);
|
2014-02-10 01:10:30 +00:00
|
|
|
set_process(false);
|
2017-02-27 09:47:28 +00:00
|
|
|
set_fixed_process(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Particles2D::_notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_what) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case NOTIFICATION_PROCESS: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_process_particles(get_process_delta_time());
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
|
2017-02-27 09:47:28 +00:00
|
|
|
case NOTIFICATION_FIXED_PROCESS: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_process_particles(get_fixed_process_delta_time());
|
2017-02-27 09:47:28 +00:00
|
|
|
} break;
|
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float ppt = preprocess;
|
|
|
|
while (ppt > 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
_process_particles(0.1);
|
2017-03-05 15:44:50 +00:00
|
|
|
ppt -= 0.1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (particles.size() == 0 || lifetime == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
RID ci = get_canvas_item();
|
|
|
|
Size2 size(1, 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
Point2 center;
|
2017-03-05 15:44:50 +00:00
|
|
|
int total_frames = 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!texture.is_null()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
size = texture->get_size();
|
|
|
|
size.x /= h_frames;
|
|
|
|
size.y /= v_frames;
|
|
|
|
total_frames = h_frames * v_frames;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float time_pos = (time / lifetime);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Particle *pdata = &particles[0];
|
|
|
|
int particle_count = particles.size();
|
2014-09-21 04:43:42 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
RID texrid;
|
|
|
|
|
|
|
|
if (texture.is_valid())
|
|
|
|
texrid = texture->get_rid();
|
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
Transform2D invxform;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!local_space)
|
2017-03-05 15:44:50 +00:00
|
|
|
invxform = get_global_transform().affine_inverse();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-10-13 03:20:56 +00:00
|
|
|
int start_particle = (int)(time * (float)particle_count / lifetime);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int id = 0; id < particle_count; ++id) {
|
2014-10-13 03:20:56 +00:00
|
|
|
int i = start_particle + id;
|
|
|
|
if (i >= particle_count) {
|
|
|
|
i -= particle_count;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Particle &p = pdata[i];
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!p.active)
|
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float ptime = ((float)i / particle_count) * explosiveness;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (ptime < time_pos)
|
|
|
|
ptime = time_pos - ptime;
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-05 15:44:50 +00:00
|
|
|
ptime = (1.0 - ptime) + time_pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
uint64_t rand_seed = p.seed * (i + 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-24 18:18:52 +00:00
|
|
|
Color color;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (color_ramp.is_valid()) {
|
2015-05-26 19:17:54 +00:00
|
|
|
color = color_ramp->get_color_at_offset(ptime);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else {
|
2015-05-24 18:18:52 +00:00
|
|
|
color = default_color;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2017-03-05 15:44:50 +00:00
|
|
|
float huerand = _rand_from_seed(&rand_seed);
|
2014-02-10 01:10:30 +00:00
|
|
|
float huerot = param[PARAM_HUE_VARIATION] + randomness[PARAM_HUE_VARIATION] * huerand;
|
|
|
|
|
|
|
|
if (Math::abs(huerot) > CMP_EPSILON) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float h = color.get_h();
|
|
|
|
float s = color.get_s();
|
|
|
|
float v = color.get_v();
|
|
|
|
float a = color.a;
|
2014-02-10 01:10:30 +00:00
|
|
|
//float preh=h;
|
2017-03-05 15:44:50 +00:00
|
|
|
h += huerot;
|
|
|
|
h = Math::abs(Math::fposmod(h, 1.0f));
|
2014-02-10 01:10:30 +00:00
|
|
|
//print_line("rand: "+rtos(randomness[PARAM_HUE_VARIATION])+" rand: "+rtos(huerand));
|
|
|
|
//print_line(itos(i)+":hue: "+rtos(preh)+" + "+rtos(huerot)+" = "+rtos(h));
|
2017-03-05 15:44:50 +00:00
|
|
|
color.set_hsv(h, s, v);
|
|
|
|
color.a = a;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float initial_size = param[PARAM_INITIAL_SIZE] + param[PARAM_INITIAL_SIZE] * _rand_from_seed(&rand_seed) * randomness[PARAM_INITIAL_SIZE];
|
|
|
|
float final_size = param[PARAM_FINAL_SIZE] + param[PARAM_FINAL_SIZE] * _rand_from_seed(&rand_seed) * randomness[PARAM_FINAL_SIZE];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float size_mult = initial_size * (1.0 - ptime) + final_size * ptime;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//Size2 rectsize=size * size_mult;
|
|
|
|
//rectsize=rectsize.floor();
|
|
|
|
|
|
|
|
//Rect2 r = Rect2(Vecto,rectsize);
|
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
Transform2D xform;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (p.rot) {
|
|
|
|
|
|
|
|
xform.set_rotation(p.rot);
|
2017-03-05 15:44:50 +00:00
|
|
|
xform.translate(-size * size_mult / 2.0);
|
|
|
|
xform.elements[2] += p.pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
xform.elements[2] = -size * size_mult / 2.0;
|
|
|
|
xform.elements[2] += p.pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!local_space) {
|
|
|
|
xform = invxform * xform;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
xform.scale_basis(Size2(size_mult, size_mult));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_set_transform(ci, xform);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (texrid.is_valid()) {
|
|
|
|
|
2014-11-17 10:46:11 +00:00
|
|
|
Rect2 src_rect;
|
2017-03-05 15:44:50 +00:00
|
|
|
src_rect.size = size;
|
2014-11-17 10:46:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (total_frames > 1) {
|
|
|
|
int frame = Math::fast_ftoi(Math::floor(p.frame * total_frames)) % total_frames;
|
|
|
|
src_rect.pos.x = size.x * (frame % h_frames);
|
|
|
|
src_rect.pos.y = size.y * (frame / h_frames);
|
2014-11-17 10:46:11 +00:00
|
|
|
}
|
2017-04-08 23:15:37 +00:00
|
|
|
Rect2 dst_rect(Point2(), size);
|
2017-02-09 23:48:38 +00:00
|
|
|
if (flip_h)
|
2017-04-08 23:15:37 +00:00
|
|
|
dst_rect.size.x = -dst_rect.size.x;
|
2017-02-09 23:48:38 +00:00
|
|
|
if (flip_v)
|
2017-04-08 23:15:37 +00:00
|
|
|
dst_rect.size.y = -dst_rect.size.y;
|
2014-11-17 10:46:11 +00:00
|
|
|
|
2017-04-08 23:15:37 +00:00
|
|
|
texture->draw_rect_region(ci, dst_rect, src_rect, color);
|
2014-09-21 04:43:42 +00:00
|
|
|
//VisualServer::get_singleton()->canvas_item_add_texture_rect(ci,r,texrid,false,color);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(), size), color);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *_particlesframe_property_names[Particles2D::PARAM_MAX] = {
|
2014-02-10 01:10:30 +00:00
|
|
|
"params/direction",
|
|
|
|
"params/spread",
|
|
|
|
"params/linear_velocity",
|
|
|
|
"params/spin_velocity",
|
|
|
|
"params/orbit_velocity",
|
|
|
|
"params/gravity_direction",
|
|
|
|
"params/gravity_strength",
|
|
|
|
"params/radial_accel",
|
|
|
|
"params/tangential_accel",
|
|
|
|
"params/damping",
|
2014-09-19 21:39:50 +00:00
|
|
|
"params/initial_angle",
|
2014-02-10 01:10:30 +00:00
|
|
|
"params/initial_size",
|
|
|
|
"params/final_size",
|
2014-11-17 10:46:11 +00:00
|
|
|
"params/hue_variation",
|
|
|
|
"params/anim_speed_scale",
|
|
|
|
"params/anim_initial_pos",
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *_particlesframe_property_rnames[Particles2D::PARAM_MAX] = {
|
2014-02-10 01:10:30 +00:00
|
|
|
"randomness/direction",
|
|
|
|
"randomness/spread",
|
|
|
|
"randomness/linear_velocity",
|
|
|
|
"randomness/spin_velocity",
|
|
|
|
"randomness/orbit_velocity",
|
|
|
|
"randomness/gravity_direction",
|
|
|
|
"randomness/gravity_strength",
|
|
|
|
"randomness/radial_accel",
|
|
|
|
"randomness/tangential_accel",
|
2016-03-08 23:00:52 +00:00
|
|
|
"randomness/damping",
|
2014-09-19 21:39:50 +00:00
|
|
|
"randomness/initial_angle",
|
2014-02-10 01:10:30 +00:00
|
|
|
"randomness/initial_size",
|
|
|
|
"randomness/final_size",
|
2014-11-17 10:46:11 +00:00
|
|
|
"randomness/hue_variation",
|
|
|
|
"randomness/anim_speed_scale",
|
|
|
|
"randomness/anim_initial_pos",
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static const char *_particlesframe_property_ranges[Particles2D::PARAM_MAX] = {
|
2014-02-10 01:10:30 +00:00
|
|
|
"0,360,0.01",
|
|
|
|
"0,180,0.01",
|
|
|
|
"-1024,1024,0.01",
|
|
|
|
"-1024,1024,0.01",
|
|
|
|
"-1024,1024,0.01",
|
|
|
|
"0,360,0.01",
|
|
|
|
"0,1024,0.01",
|
|
|
|
"-128,128,0.01",
|
|
|
|
"-128,128,0.01",
|
|
|
|
"0,1024,0.001",
|
2014-09-19 21:39:50 +00:00
|
|
|
"0,360,0.01",
|
2014-02-10 01:10:30 +00:00
|
|
|
"0,1024,0.01",
|
|
|
|
"0,1024,0.01",
|
2014-11-17 10:46:11 +00:00
|
|
|
"0,1,0.01",
|
|
|
|
"0,128,0.01",
|
|
|
|
"0,1,0.01",
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void Particles2D::set_emitting(bool p_emitting) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (emitting == p_emitting)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (p_emitting) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (active_count == 0)
|
|
|
|
time = 0;
|
|
|
|
set_process(process_mode == PROCESS_IDLE);
|
|
|
|
set_fixed_process(process_mode == PROCESS_FIXED);
|
2014-02-10 01:10:30 +00:00
|
|
|
time_to_live = emit_timeout;
|
|
|
|
};
|
2017-03-05 15:44:50 +00:00
|
|
|
emitting = p_emitting;
|
2015-04-25 13:36:37 +00:00
|
|
|
_change_notify("config/emitting");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Particles2D::is_emitting() const {
|
|
|
|
|
|
|
|
return emitting;
|
|
|
|
}
|
|
|
|
|
2017-02-27 09:47:28 +00:00
|
|
|
void Particles2D::set_process_mode(ProcessMode p_mode) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
process_mode = p_mode;
|
|
|
|
const bool should_process = emitting || active_count != 0;
|
|
|
|
set_process(should_process && process_mode == PROCESS_IDLE);
|
|
|
|
set_fixed_process(should_process && process_mode == PROCESS_FIXED);
|
2017-02-27 09:47:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Particles2D::ProcessMode Particles2D::get_process_mode() const {
|
|
|
|
|
|
|
|
return process_mode;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void Particles2D::set_amount(int p_amount) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_amount, 1024 + 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
particles.resize(p_amount);
|
|
|
|
}
|
|
|
|
int Particles2D::get_amount() const {
|
|
|
|
|
|
|
|
return particles.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Particles2D::set_emit_timeout(float p_timeout) {
|
|
|
|
|
|
|
|
emit_timeout = p_timeout;
|
|
|
|
time_to_live = p_timeout;
|
|
|
|
};
|
|
|
|
|
|
|
|
float Particles2D::get_emit_timeout() const {
|
|
|
|
|
|
|
|
return emit_timeout;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Particles2D::set_lifetime(float p_lifetime) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_lifetime, 3600 + 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
lifetime = p_lifetime;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
float Particles2D::get_lifetime() const {
|
|
|
|
|
|
|
|
return lifetime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Particles2D::set_time_scale(float p_time_scale) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
time_scale = p_time_scale;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
float Particles2D::get_time_scale() const {
|
|
|
|
|
|
|
|
return time_scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Particles2D::set_pre_process_time(float p_pre_process_time) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
preprocess = p_pre_process_time;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float Particles2D::get_pre_process_time() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return preprocess;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Particles2D::set_param(Parameter p_param, float p_value) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_param, PARAM_MAX);
|
|
|
|
param[p_param] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
float Particles2D::get_param(Parameter p_param) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return param[p_param];
|
|
|
|
}
|
|
|
|
|
|
|
|
void Particles2D::set_randomness(Parameter p_param, float p_value) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_param, PARAM_MAX);
|
|
|
|
randomness[p_param] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
float Particles2D::get_randomness(Parameter p_param) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
return randomness[p_param];
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Particles2D::set_texture(const Ref<Texture> &p_texture) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
texture = p_texture;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Texture> Particles2D::get_texture() const {
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Particles2D::set_color(const Color &p_color) {
|
2015-05-24 18:18:52 +00:00
|
|
|
|
|
|
|
default_color = p_color;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color Particles2D::get_color() const {
|
|
|
|
|
|
|
|
return default_color;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Particles2D::set_color_ramp(const Ref<ColorRamp> &p_color_ramp) {
|
2015-05-24 18:18:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
color_ramp = p_color_ramp;
|
2015-05-24 18:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<ColorRamp> Particles2D::get_color_ramp() const {
|
|
|
|
|
|
|
|
return color_ramp;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Particles2D::set_emissor_offset(const Point2 &p_offset) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
emissor_offset = p_offset;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Point2 Particles2D::get_emissor_offset() const {
|
|
|
|
|
|
|
|
return emissor_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Particles2D::set_use_local_space(bool p_use) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
local_space = p_use;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Particles2D::is_using_local_space() const {
|
|
|
|
|
|
|
|
return local_space;
|
|
|
|
}
|
|
|
|
|
2015-05-24 18:18:52 +00:00
|
|
|
//Deprecated. Converts color phases to color ramp
|
2014-02-10 01:10:30 +00:00
|
|
|
void Particles2D::set_color_phases(int p_phases) {
|
|
|
|
|
2015-05-24 18:18:52 +00:00
|
|
|
//Create color ramp if we have 2 or more phases.
|
|
|
|
//Otherwise first phase phase will be assigned to default color.
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_phases > 1 && color_ramp.is_null()) {
|
|
|
|
color_ramp = Ref<ColorRamp>(memnew(ColorRamp()));
|
2015-05-24 18:18:52 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (color_ramp.is_valid()) {
|
2015-05-24 18:18:52 +00:00
|
|
|
color_ramp->get_points().resize(p_phases);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-24 18:18:52 +00:00
|
|
|
//Deprecated.
|
2014-02-10 01:10:30 +00:00
|
|
|
int Particles2D::get_color_phases() const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (color_ramp.is_valid()) {
|
2015-05-24 18:18:52 +00:00
|
|
|
return color_ramp->get_points_count();
|
|
|
|
}
|
|
|
|
return 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-24 18:18:52 +00:00
|
|
|
//Deprecated. Converts color phases to color ramp
|
2017-03-05 15:44:50 +00:00
|
|
|
void Particles2D::set_color_phase_color(int p_phase, const Color &p_color) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX(p_phase, MAX_COLOR_PHASES);
|
|
|
|
if (color_ramp.is_valid()) {
|
|
|
|
if (color_ramp->get_points_count() > p_phase)
|
2015-05-24 18:18:52 +00:00
|
|
|
color_ramp->set_color(p_phase, p_color);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else {
|
|
|
|
if (p_phase == 0)
|
2015-05-24 18:18:52 +00:00
|
|
|
default_color = p_color;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-05-24 18:18:52 +00:00
|
|
|
|
|
|
|
//Deprecated.
|
2014-02-10 01:10:30 +00:00
|
|
|
Color Particles2D::get_color_phase_color(int p_phase) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_phase, MAX_COLOR_PHASES, Color());
|
|
|
|
if (color_ramp.is_valid()) {
|
2015-05-24 18:18:52 +00:00
|
|
|
return color_ramp->get_color(p_phase);
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
return Color(0, 0, 0, 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-24 18:18:52 +00:00
|
|
|
//Deprecated. Converts color phases to color ramp
|
2017-03-05 15:44:50 +00:00
|
|
|
void Particles2D::set_color_phase_pos(int p_phase, float p_pos) {
|
|
|
|
ERR_FAIL_INDEX(p_phase, MAX_COLOR_PHASES);
|
|
|
|
ERR_FAIL_COND(p_pos < 0.0 || p_pos > 1.0);
|
|
|
|
if (color_ramp.is_valid() && color_ramp->get_points_count() > p_phase) {
|
2015-05-24 18:18:52 +00:00
|
|
|
return color_ramp->set_offset(p_phase, p_pos);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2015-05-24 18:18:52 +00:00
|
|
|
|
|
|
|
//Deprecated.
|
2014-02-10 01:10:30 +00:00
|
|
|
float Particles2D::get_color_phase_pos(int p_phase) const {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_phase, MAX_COLOR_PHASES, 0);
|
|
|
|
if (color_ramp.is_valid()) {
|
2015-05-24 18:18:52 +00:00
|
|
|
return color_ramp->get_offset(p_phase);
|
|
|
|
}
|
|
|
|
return 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Particles2D::set_emission_half_extents(const Vector2 &p_extents) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
extents = p_extents;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 Particles2D::get_emission_half_extents() const {
|
|
|
|
|
|
|
|
return extents;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Particles2D::set_initial_velocity(const Vector2 &p_velocity) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
initial_velocity = p_velocity;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector2 Particles2D::get_initial_velocity() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return initial_velocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Particles2D::pre_process(float p_delta) {
|
|
|
|
|
|
|
|
_process_particles(p_delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Particles2D::set_explosiveness(float p_value) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
explosiveness = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float Particles2D::get_explosiveness() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return explosiveness;
|
|
|
|
}
|
|
|
|
|
2014-02-13 21:03:28 +00:00
|
|
|
void Particles2D::set_flip_h(bool p_flip) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
flip_h = p_flip;
|
2014-02-13 21:03:28 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool Particles2D::is_flipped_h() const {
|
2014-02-13 21:03:28 +00:00
|
|
|
|
|
|
|
return flip_h;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Particles2D::set_flip_v(bool p_flip) {
|
2014-02-13 21:03:28 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
flip_v = p_flip;
|
2014-02-13 21:03:28 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
bool Particles2D::is_flipped_v() const {
|
2014-02-13 21:03:28 +00:00
|
|
|
|
|
|
|
return flip_v;
|
|
|
|
}
|
|
|
|
|
2014-11-17 10:46:11 +00:00
|
|
|
void Particles2D::set_h_frames(int p_frames) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_frames < 1);
|
|
|
|
h_frames = p_frames;
|
2014-11-17 10:46:11 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int Particles2D::get_h_frames() const {
|
2014-11-17 10:46:11 +00:00
|
|
|
|
|
|
|
return h_frames;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Particles2D::set_v_frames(int p_frames) {
|
2014-11-17 10:46:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(p_frames < 1);
|
|
|
|
v_frames = p_frames;
|
2014-11-17 10:46:11 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
int Particles2D::get_v_frames() const {
|
2014-11-17 10:46:11 +00:00
|
|
|
|
|
|
|
return v_frames;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Particles2D::set_emission_points(const PoolVector<Vector2> &p_points) {
|
2014-11-17 10:46:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
emission_points = p_points;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
PoolVector<Vector2> Particles2D::get_emission_points() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return emission_points;
|
|
|
|
}
|
|
|
|
|
2015-12-29 21:53:45 +00:00
|
|
|
void Particles2D::reset() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < particles.size(); i++) {
|
|
|
|
particles[i].active = false;
|
2015-12-29 21:53:45 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
time = 0;
|
|
|
|
active_count = 0;
|
2015-12-29 21:53:45 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void Particles2D::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_emitting", "active"), &Particles2D::set_emitting);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_emitting"), &Particles2D::is_emitting);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Particles2D::set_process_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_process_mode"), &Particles2D::get_process_mode);
|
2017-02-27 09:47:28 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_amount", "amount"), &Particles2D::set_amount);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_amount"), &Particles2D::get_amount);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_lifetime", "lifetime"), &Particles2D::set_lifetime);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_lifetime"), &Particles2D::get_lifetime);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &Particles2D::set_time_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_time_scale"), &Particles2D::get_time_scale);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_pre_process_time", "time"), &Particles2D::set_pre_process_time);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_pre_process_time"), &Particles2D::get_pre_process_time);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_emit_timeout", "value"), &Particles2D::set_emit_timeout);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_emit_timeout"), &Particles2D::get_emit_timeout);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &Particles2D::set_param);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_param", "param"), &Particles2D::get_param);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_randomness", "param", "value"), &Particles2D::set_randomness);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_randomness", "param"), &Particles2D::get_randomness);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_texture:Texture", "texture"), &Particles2D::set_texture);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_texture:Texture"), &Particles2D::get_texture);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_color", "color"), &Particles2D::set_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color"), &Particles2D::get_color);
|
2015-05-24 18:18:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_color_ramp:ColorRamp", "color_ramp"), &Particles2D::set_color_ramp);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color_ramp:ColorRamp"), &Particles2D::get_color_ramp);
|
2015-05-24 18:18:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_emissor_offset", "offset"), &Particles2D::set_emissor_offset);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_emissor_offset"), &Particles2D::get_emissor_offset);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_flip_h", "enable"), &Particles2D::set_flip_h);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_flipped_h"), &Particles2D::is_flipped_h);
|
2014-02-13 21:03:28 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_flip_v", "enable"), &Particles2D::set_flip_v);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_flipped_v"), &Particles2D::is_flipped_v);
|
2014-02-13 21:03:28 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_h_frames", "enable"), &Particles2D::set_h_frames);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_h_frames"), &Particles2D::get_h_frames);
|
2014-11-17 10:46:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_v_frames", "enable"), &Particles2D::set_v_frames);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_v_frames"), &Particles2D::get_v_frames);
|
2014-11-17 10:46:11 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_emission_half_extents", "extents"), &Particles2D::set_emission_half_extents);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_emission_half_extents"), &Particles2D::get_emission_half_extents);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_color_phases", "phases"), &Particles2D::set_color_phases);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color_phases"), &Particles2D::get_color_phases);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_color_phase_color", "phase", "color"), &Particles2D::set_color_phase_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color_phase_color", "phase"), &Particles2D::get_color_phase_color);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_color_phase_pos", "phase", "pos"), &Particles2D::set_color_phase_pos);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_color_phase_pos", "phase"), &Particles2D::get_color_phase_pos);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("pre_process", "time"), &Particles2D::pre_process);
|
|
|
|
ClassDB::bind_method(D_METHOD("reset"), &Particles2D::reset);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_use_local_space", "enable"), &Particles2D::set_use_local_space);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_using_local_space"), &Particles2D::is_using_local_space);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_initial_velocity", "velocity"), &Particles2D::set_initial_velocity);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_initial_velocity"), &Particles2D::get_initial_velocity);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_explosiveness", "amount"), &Particles2D::set_explosiveness);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_explosiveness"), &Particles2D::get_explosiveness);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_emission_points", "points"), &Particles2D::set_emission_points);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_emission_points"), &Particles2D::get_emission_points);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-02-25 14:06:00 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("emission_finished"));
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "config/amount", PROPERTY_HINT_EXP_RANGE, "1,1024"), "set_amount", "get_amount");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "config/lifetime", PROPERTY_HINT_EXP_RANGE, "0.1,3600,0.1"), "set_lifetime", "get_lifetime");
|
|
|
|
ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "config/time_scale", PROPERTY_HINT_EXP_RANGE, "0.01,128,0.01"), "set_time_scale", "get_time_scale");
|
2017-04-08 18:04:06 +00:00
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "config/preprocess", PROPERTY_HINT_EXP_RANGE, "0,3600,0.1"), "set_pre_process_time", "get_pre_process_time");
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "config/emit_timeout", PROPERTY_HINT_RANGE, "0,3600,0.1"), "set_emit_timeout", "get_emit_timeout");
|
|
|
|
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "config/emitting"), "set_emitting", "is_emitting");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "config/process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_process_mode", "get_process_mode");
|
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "config/offset"), "set_emissor_offset", "get_emissor_offset");
|
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "config/half_extents"), "set_emission_half_extents", "get_emission_half_extents");
|
|
|
|
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "config/local_space"), "set_use_local_space", "is_using_local_space");
|
|
|
|
ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "config/explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness", "get_explosiveness");
|
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "config/flip_h"), "set_flip_h", "is_flipped_h");
|
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "config/flip_v"), "set_flip_v", "is_flipped_v");
|
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "config/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
|
|
|
|
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "config/h_frames", PROPERTY_HINT_RANGE, "1,512,1"), "set_h_frames", "get_h_frames");
|
|
|
|
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "config/v_frames", PROPERTY_HINT_RANGE, "1,512,1"), "set_v_frames", "get_v_frames");
|
|
|
|
|
|
|
|
for (int i = 0; i < PARAM_MAX; i++) {
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, _particlesframe_property_names[i], PROPERTY_HINT_RANGE, _particlesframe_property_ranges[i]), "set_param", "get_param", i);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < PARAM_MAX; i++) {
|
|
|
|
ADD_PROPERTYINZ(PropertyInfo(Variant::REAL, _particlesframe_property_rnames[i], PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_randomness", "get_randomness", i);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "color_phases/count", PROPERTY_HINT_RANGE, "0,4,1", 0), "set_color_phases", "get_color_phases");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-24 18:18:52 +00:00
|
|
|
//Backward compatibility. They will be converted to color ramp
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < MAX_COLOR_PHASES; i++) {
|
|
|
|
String phase = "phase_" + itos(i) + "/";
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::REAL, phase + "pos", PROPERTY_HINT_RANGE, "0,1,0.01", 0), "set_color_phase_pos", "get_color_phase_pos", i);
|
|
|
|
ADD_PROPERTYI(PropertyInfo(Variant::COLOR, phase + "color", PROPERTY_HINT_NONE, "", 0), "set_color_phase_color", "get_color_phase_color", i);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTYNO(PropertyInfo(Variant::COLOR, "color/color"), "set_color", "get_color");
|
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "color/color_ramp", PROPERTY_HINT_RESOURCE_TYPE, "ColorRamp"), "set_color_ramp", "get_color_ramp");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "emission_points", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_emission_points", "get_emission_points");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
BIND_CONSTANT(PARAM_DIRECTION);
|
|
|
|
BIND_CONSTANT(PARAM_SPREAD);
|
|
|
|
BIND_CONSTANT(PARAM_LINEAR_VELOCITY);
|
|
|
|
BIND_CONSTANT(PARAM_SPIN_VELOCITY);
|
|
|
|
BIND_CONSTANT(PARAM_ORBIT_VELOCITY);
|
|
|
|
BIND_CONSTANT(PARAM_GRAVITY_DIRECTION);
|
|
|
|
BIND_CONSTANT(PARAM_GRAVITY_STRENGTH);
|
|
|
|
BIND_CONSTANT(PARAM_RADIAL_ACCEL);
|
|
|
|
BIND_CONSTANT(PARAM_TANGENTIAL_ACCEL);
|
|
|
|
BIND_CONSTANT(PARAM_DAMPING);
|
|
|
|
BIND_CONSTANT(PARAM_INITIAL_ANGLE);
|
|
|
|
BIND_CONSTANT(PARAM_INITIAL_SIZE);
|
|
|
|
BIND_CONSTANT(PARAM_FINAL_SIZE);
|
|
|
|
BIND_CONSTANT(PARAM_HUE_VARIATION);
|
|
|
|
BIND_CONSTANT(PARAM_ANIM_SPEED_SCALE);
|
|
|
|
BIND_CONSTANT(PARAM_ANIM_INITIAL_POS);
|
|
|
|
BIND_CONSTANT(PARAM_MAX);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
BIND_CONSTANT(MAX_COLOR_PHASES);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Particles2D::Particles2D() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < PARAM_MAX; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
param[i] = 0;
|
|
|
|
randomness[i] = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
set_param(PARAM_SPREAD, 10);
|
|
|
|
set_param(PARAM_LINEAR_VELOCITY, 20);
|
|
|
|
set_param(PARAM_GRAVITY_STRENGTH, 9.8);
|
|
|
|
set_param(PARAM_RADIAL_ACCEL, 0);
|
|
|
|
set_param(PARAM_TANGENTIAL_ACCEL, 0);
|
|
|
|
set_param(PARAM_INITIAL_ANGLE, 0.0);
|
|
|
|
set_param(PARAM_INITIAL_SIZE, 1.0);
|
|
|
|
set_param(PARAM_FINAL_SIZE, 1.0);
|
|
|
|
set_param(PARAM_ANIM_SPEED_SCALE, 1.0);
|
|
|
|
|
|
|
|
set_color(Color(1, 1, 1, 1));
|
|
|
|
|
|
|
|
time = 0;
|
|
|
|
lifetime = 2;
|
|
|
|
emitting = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
particles.resize(32);
|
2017-03-05 15:44:50 +00:00
|
|
|
active_count = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
set_emitting(true);
|
2017-03-05 15:44:50 +00:00
|
|
|
process_mode = PROCESS_IDLE;
|
|
|
|
local_space = true;
|
|
|
|
preprocess = 0;
|
|
|
|
time_scale = 1.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
flip_h = false;
|
|
|
|
flip_v = false;
|
2014-02-13 21:03:28 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
v_frames = 1;
|
|
|
|
h_frames = 1;
|
2014-02-13 21:03:28 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
emit_timeout = 0;
|
|
|
|
time_to_live = 0;
|
2017-03-05 15:44:50 +00:00
|
|
|
explosiveness = 1.0;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|