mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-22 20:06:49 +01:00
Reworked RendetingServer's canvas_item_add_texture_rect_animation's last parameter. Now instead of bool randomize_start_time it's real start_time. This should make it more versatile.
This commit is contained in:
parent
105115dbb3
commit
053b283c47
@ -273,7 +273,7 @@
|
|||||||
<return type="void" />
|
<return type="void" />
|
||||||
<argument index="0" name="item" type="RID" />
|
<argument index="0" name="item" type="RID" />
|
||||||
<argument index="1" name="animation_data" type="Array" />
|
<argument index="1" name="animation_data" type="Array" />
|
||||||
<argument index="2" name="randomize_start_time" type="bool" default="false" />
|
<argument index="2" name="start_time" type="float" default="0.0" />
|
||||||
<description>
|
<description>
|
||||||
Add texture rect regions as an animation to the [CanvasItem]'s draw commands.
|
Add texture rect regions as an animation to the [CanvasItem]'s draw commands.
|
||||||
You need to pass an Array of Arrays, the inner Arrays are the frames. The 0th argument is the frame time, the rest are the arguments of [member canvas_item_add_texture_rect_region] in order.
|
You need to pass an Array of Arrays, the inner Arrays are the frames. The 0th argument is the frame time, the rest are the arguments of [member canvas_item_add_texture_rect_region] in order.
|
||||||
|
@ -185,6 +185,8 @@ void LayeredTileMap::draw_tile(RID p_canvas_item, const Vector2 &p_position, con
|
|||||||
|
|
||||||
Array anim_data;
|
Array anim_data;
|
||||||
|
|
||||||
|
real_t total_animation_time = 0;
|
||||||
|
|
||||||
for (int frame = 0; frame < atlas_source->get_tile_animation_frames_count(p_atlas_coords); frame++) {
|
for (int frame = 0; frame < atlas_source->get_tile_animation_frames_count(p_atlas_coords); frame++) {
|
||||||
real_t frame_duration_scaled = atlas_source->get_tile_animation_frame_duration(p_atlas_coords, frame) * speed;
|
real_t frame_duration_scaled = atlas_source->get_tile_animation_frame_duration(p_atlas_coords, frame) * speed;
|
||||||
|
|
||||||
@ -209,6 +211,7 @@ void LayeredTileMap::draw_tile(RID p_canvas_item, const Vector2 &p_position, con
|
|||||||
//bool clip_uv = d[7]; //bool p_clip_uv = false
|
//bool clip_uv = d[7]; //bool p_clip_uv = false
|
||||||
|
|
||||||
d[0] = frame_duration_scaled;
|
d[0] = frame_duration_scaled;
|
||||||
|
total_animation_time += frame_duration_scaled;
|
||||||
d[1] = dest_rect;
|
d[1] = dest_rect;
|
||||||
d[2] = tex_rid;
|
d[2] = tex_rid;
|
||||||
d[3] = source_rect;
|
d[3] = source_rect;
|
||||||
@ -220,9 +223,7 @@ void LayeredTileMap::draw_tile(RID p_canvas_item, const Vector2 &p_position, con
|
|||||||
anim_data.push_back(d);
|
anim_data.push_back(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool random_start_time = atlas_source->get_tile_animation_mode(p_atlas_coords) == LayeredTileSetAtlasSource::TILE_ANIMATION_MODE_RANDOM_START_TIMES;
|
RenderingServer::get_singleton()->canvas_item_add_texture_rect_animation(p_canvas_item, anim_data, total_animation_time * p_normalized_animation_offset);
|
||||||
|
|
||||||
RenderingServer::get_singleton()->canvas_item_add_texture_rect_animation(p_canvas_item, anim_data, random_start_time);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1514,7 +1514,7 @@ void RenderingServerCanvas::canvas_item_add_multimesh(RID p_item, RID p_mesh, RI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingServerCanvas::canvas_item_add_texture_rect_animation(RID p_item, const Array &p_animation_data, const bool p_randomize_start_time) {
|
void RenderingServerCanvas::canvas_item_add_texture_rect_animation(RID p_item, const Array &p_animation_data, const real_t p_start_time) {
|
||||||
// Important!
|
// Important!
|
||||||
if (p_animation_data.size() == 0) {
|
if (p_animation_data.size() == 0) {
|
||||||
return;
|
return;
|
||||||
@ -1529,7 +1529,7 @@ void RenderingServerCanvas::canvas_item_add_texture_rect_animation(RID p_item, c
|
|||||||
|
|
||||||
//void canvas_item_add_texture_rect_region(RID p_item, const Rect2 &p_rect, RID p_texture, const Rect2 &p_src_rect,
|
//void canvas_item_add_texture_rect_region(RID p_item, const Rect2 &p_rect, RID p_texture, const Rect2 &p_src_rect,
|
||||||
//const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, RID p_normal_map = RID(), bool p_clip_uv = false);
|
//const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, RID p_normal_map = RID(), bool p_clip_uv = false);
|
||||||
|
|
||||||
real_t total_frame_time = 0;
|
real_t total_frame_time = 0;
|
||||||
|
|
||||||
for (int i = 0; i < p_animation_data.size(); ++i) {
|
for (int i = 0; i < p_animation_data.size(); ++i) {
|
||||||
@ -1547,7 +1547,7 @@ void RenderingServerCanvas::canvas_item_add_texture_rect_animation(RID p_item, c
|
|||||||
|
|
||||||
Item::CommandRect *rect = memnew(Item::CommandRect);
|
Item::CommandRect *rect = memnew(Item::CommandRect);
|
||||||
ERR_FAIL_COND(!rect);
|
ERR_FAIL_COND(!rect);
|
||||||
|
|
||||||
real_t frame_time = d[0];
|
real_t frame_time = d[0];
|
||||||
total_frame_time += frame_time;
|
total_frame_time += frame_time;
|
||||||
Rect2 tex_rect = d[1]; //const Rect2 &p_rect
|
Rect2 tex_rect = d[1]; //const Rect2 &p_rect
|
||||||
@ -1587,18 +1587,13 @@ void RenderingServerCanvas::canvas_item_add_texture_rect_animation(RID p_item, c
|
|||||||
if (clip_uv) {
|
if (clip_uv) {
|
||||||
rect->flags |= RasterizerCanvas::CANVAS_RECT_CLIP_UV;
|
rect->flags |= RasterizerCanvas::CANVAS_RECT_CLIP_UV;
|
||||||
}
|
}
|
||||||
|
|
||||||
ra->rects.push_back(rect);
|
ra->rects.push_back(rect);
|
||||||
ra->times.push_back(frame_time);
|
ra->times.push_back(frame_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
ra->total_time = total_frame_time;
|
ra->total_time = total_frame_time;
|
||||||
|
ra->time_elapsed = p_start_time;
|
||||||
if (p_randomize_start_time) {
|
|
||||||
RandomPCG r;
|
|
||||||
r.randomize();
|
|
||||||
ra->time_elapsed = r.randf() * ra->total_time;
|
|
||||||
}
|
|
||||||
|
|
||||||
canvas_item->rect_dirty = true;
|
canvas_item->rect_dirty = true;
|
||||||
canvas_item->commands.push_back(ra);
|
canvas_item->commands.push_back(ra);
|
||||||
|
@ -247,7 +247,7 @@ public:
|
|||||||
void canvas_item_add_triangle_array(RID p_item, const Vector<int> &p_indices, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), const Vector<int> &p_bones = Vector<int>(), const Vector<float> &p_weights = Vector<float>(), RID p_texture = RID(), int p_count = -1, RID p_normal_map = RID(), bool p_antialiased = false, bool p_antialiasing_use_indices = false);
|
void canvas_item_add_triangle_array(RID p_item, const Vector<int> &p_indices, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), const Vector<int> &p_bones = Vector<int>(), const Vector<float> &p_weights = Vector<float>(), RID p_texture = RID(), int p_count = -1, RID p_normal_map = RID(), bool p_antialiased = false, bool p_antialiasing_use_indices = false);
|
||||||
void canvas_item_add_mesh(RID p_item, const RID &p_mesh, const Transform2D &p_transform = Transform2D(), const Color &p_modulate = Color(1, 1, 1), RID p_texture = RID(), RID p_normal_map = RID());
|
void canvas_item_add_mesh(RID p_item, const RID &p_mesh, const Transform2D &p_transform = Transform2D(), const Color &p_modulate = Color(1, 1, 1), RID p_texture = RID(), RID p_normal_map = RID());
|
||||||
void canvas_item_add_multimesh(RID p_item, RID p_mesh, RID p_texture = RID(), RID p_normal_map = RID());
|
void canvas_item_add_multimesh(RID p_item, RID p_mesh, RID p_texture = RID(), RID p_normal_map = RID());
|
||||||
void canvas_item_add_texture_rect_animation(RID p_item, const Array &p_animation_data, const bool p_randomize_start_time = false);
|
void canvas_item_add_texture_rect_animation(RID p_item, const Array &p_animation_data, const real_t p_start_time = 0.0);
|
||||||
|
|
||||||
void canvas_item_add_set_transform(RID p_item, const Transform2D &p_transform);
|
void canvas_item_add_set_transform(RID p_item, const Transform2D &p_transform);
|
||||||
void canvas_item_add_clip_ignore(RID p_item, bool p_ignore);
|
void canvas_item_add_clip_ignore(RID p_item, bool p_ignore);
|
||||||
|
@ -612,7 +612,7 @@ public:
|
|||||||
BIND12(canvas_item_add_triangle_array, RID, const Vector<int> &, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, const Vector<int> &, const Vector<float> &, RID, int, RID, bool, bool)
|
BIND12(canvas_item_add_triangle_array, RID, const Vector<int> &, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, const Vector<int> &, const Vector<float> &, RID, int, RID, bool, bool)
|
||||||
BIND6(canvas_item_add_mesh, RID, const RID &, const Transform2D &, const Color &, RID, RID)
|
BIND6(canvas_item_add_mesh, RID, const RID &, const Transform2D &, const Color &, RID, RID)
|
||||||
BIND4(canvas_item_add_multimesh, RID, RID, RID, RID)
|
BIND4(canvas_item_add_multimesh, RID, RID, RID, RID)
|
||||||
BIND3(canvas_item_add_texture_rect_animation, RID, const Array &, const bool)
|
BIND3(canvas_item_add_texture_rect_animation, RID, const Array &, const real_t)
|
||||||
|
|
||||||
BIND2(canvas_item_add_set_transform, RID, const Transform2D &)
|
BIND2(canvas_item_add_set_transform, RID, const Transform2D &)
|
||||||
BIND2(canvas_item_add_clip_ignore, RID, bool)
|
BIND2(canvas_item_add_clip_ignore, RID, bool)
|
||||||
|
@ -514,7 +514,7 @@ public:
|
|||||||
FUNC7(canvas_item_add_texture_rect, RID, const Rect2 &, RID, bool, const Color &, bool, RID)
|
FUNC7(canvas_item_add_texture_rect, RID, const Rect2 &, RID, bool, const Color &, bool, RID)
|
||||||
FUNC8(canvas_item_add_texture_rect_region, RID, const Rect2 &, RID, const Rect2 &, const Color &, bool, RID, bool)
|
FUNC8(canvas_item_add_texture_rect_region, RID, const Rect2 &, RID, const Rect2 &, const Color &, bool, RID, bool)
|
||||||
FUNC7(canvas_item_add_texture_multirect_region, RID, const Vector<Rect2> &, RID, const Vector<Rect2> &, const Color &, uint32_t, RID)
|
FUNC7(canvas_item_add_texture_multirect_region, RID, const Vector<Rect2> &, RID, const Vector<Rect2> &, const Color &, uint32_t, RID)
|
||||||
FUNC3(canvas_item_add_texture_rect_animation, RID, const Array &, const bool)
|
FUNC3(canvas_item_add_texture_rect_animation, RID, const Array &, const real_t)
|
||||||
FUNC11(canvas_item_add_nine_patch, RID, const Rect2 &, const Rect2 &, RID, const Vector2 &, const Vector2 &, NinePatchAxisMode, NinePatchAxisMode, bool, const Color &, RID)
|
FUNC11(canvas_item_add_nine_patch, RID, const Rect2 &, const Rect2 &, RID, const Vector2 &, const Vector2 &, NinePatchAxisMode, NinePatchAxisMode, bool, const Color &, RID)
|
||||||
FUNC7(canvas_item_add_primitive, RID, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, RID, float, RID)
|
FUNC7(canvas_item_add_primitive, RID, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, RID, float, RID)
|
||||||
FUNC7(canvas_item_add_polygon, RID, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, RID, RID, bool)
|
FUNC7(canvas_item_add_polygon, RID, const Vector<Point2> &, const Vector<Color> &, const Vector<Point2> &, RID, RID, bool)
|
||||||
|
@ -2155,7 +2155,7 @@ void RenderingServer::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_triangle_array", "item", "indices", "points", "colors", "uvs", "bones", "weights", "texture", "count", "normal_map", "antialiased", "antialiasing_use_indices"), &RenderingServer::canvas_item_add_triangle_array, DEFVAL(Vector<Point2>()), DEFVAL(Vector<int>()), DEFVAL(Vector<float>()), DEFVAL(RID()), DEFVAL(-1), DEFVAL(RID()), DEFVAL(false), DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("canvas_item_add_triangle_array", "item", "indices", "points", "colors", "uvs", "bones", "weights", "texture", "count", "normal_map", "antialiased", "antialiasing_use_indices"), &RenderingServer::canvas_item_add_triangle_array, DEFVAL(Vector<Point2>()), DEFVAL(Vector<int>()), DEFVAL(Vector<float>()), DEFVAL(RID()), DEFVAL(-1), DEFVAL(RID()), DEFVAL(false), DEFVAL(false));
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_mesh", "item", "mesh", "transform", "modulate", "texture", "normal_map"), &RenderingServer::canvas_item_add_mesh, DEFVAL(Transform2D()), DEFVAL(Color(1, 1, 1)), DEFVAL(RID()), DEFVAL(RID()));
|
ClassDB::bind_method(D_METHOD("canvas_item_add_mesh", "item", "mesh", "transform", "modulate", "texture", "normal_map"), &RenderingServer::canvas_item_add_mesh, DEFVAL(Transform2D()), DEFVAL(Color(1, 1, 1)), DEFVAL(RID()), DEFVAL(RID()));
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_multimesh", "item", "mesh", "texture", "normal_map"), &RenderingServer::canvas_item_add_multimesh, DEFVAL(RID()));
|
ClassDB::bind_method(D_METHOD("canvas_item_add_multimesh", "item", "mesh", "texture", "normal_map"), &RenderingServer::canvas_item_add_multimesh, DEFVAL(RID()));
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect_animation", "item", "animation_data", "randomize_start_time"), &RenderingServer::canvas_item_add_texture_rect_animation, DEFVAL(false));
|
ClassDB::bind_method(D_METHOD("canvas_item_add_texture_rect_animation", "item", "animation_data", "start_time"), &RenderingServer::canvas_item_add_texture_rect_animation, DEFVAL(0.0));
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_set_transform", "item", "transform"), &RenderingServer::canvas_item_add_set_transform);
|
ClassDB::bind_method(D_METHOD("canvas_item_add_set_transform", "item", "transform"), &RenderingServer::canvas_item_add_set_transform);
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_add_clip_ignore", "item", "ignore"), &RenderingServer::canvas_item_add_clip_ignore);
|
ClassDB::bind_method(D_METHOD("canvas_item_add_clip_ignore", "item", "ignore"), &RenderingServer::canvas_item_add_clip_ignore);
|
||||||
ClassDB::bind_method(D_METHOD("canvas_item_set_sort_children_by_y", "item", "enabled"), &RenderingServer::canvas_item_set_sort_children_by_y);
|
ClassDB::bind_method(D_METHOD("canvas_item_set_sort_children_by_y", "item", "enabled"), &RenderingServer::canvas_item_set_sort_children_by_y);
|
||||||
|
@ -943,7 +943,7 @@ public:
|
|||||||
virtual void canvas_item_add_triangle_array(RID p_item, const Vector<int> &p_indices, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), const Vector<int> &p_bones = Vector<int>(), const Vector<float> &p_weights = Vector<float>(), RID p_texture = RID(), int p_count = -1, RID p_normal_map = RID(), bool p_antialiased = false, bool p_antialiasing_use_indices = false) = 0;
|
virtual void canvas_item_add_triangle_array(RID p_item, const Vector<int> &p_indices, const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), const Vector<int> &p_bones = Vector<int>(), const Vector<float> &p_weights = Vector<float>(), RID p_texture = RID(), int p_count = -1, RID p_normal_map = RID(), bool p_antialiased = false, bool p_antialiasing_use_indices = false) = 0;
|
||||||
virtual void canvas_item_add_mesh(RID p_item, const RID &p_mesh, const Transform2D &p_transform = Transform2D(), const Color &p_modulate = Color(1, 1, 1), RID p_texture = RID(), RID p_normal_map = RID()) = 0;
|
virtual void canvas_item_add_mesh(RID p_item, const RID &p_mesh, const Transform2D &p_transform = Transform2D(), const Color &p_modulate = Color(1, 1, 1), RID p_texture = RID(), RID p_normal_map = RID()) = 0;
|
||||||
virtual void canvas_item_add_multimesh(RID p_item, RID p_mesh, RID p_texture = RID(), RID p_normal_map = RID()) = 0;
|
virtual void canvas_item_add_multimesh(RID p_item, RID p_mesh, RID p_texture = RID(), RID p_normal_map = RID()) = 0;
|
||||||
virtual void canvas_item_add_texture_rect_animation(RID p_item, const Array &p_animation_data, const bool p_randomize_start_time = false) = 0;
|
virtual void canvas_item_add_texture_rect_animation(RID p_item, const Array &p_animation_data, const real_t p_start_time = 0.0) = 0;
|
||||||
|
|
||||||
virtual void canvas_item_add_set_transform(RID p_item, const Transform2D &p_transform) = 0;
|
virtual void canvas_item_add_set_transform(RID p_item, const Transform2D &p_transform) = 0;
|
||||||
virtual void canvas_item_add_clip_ignore(RID p_item, bool p_ignore) = 0;
|
virtual void canvas_item_add_clip_ignore(RID p_item, bool p_ignore) = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user