/**************************************************************************/1/* animated_texture.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/resources/texture.h"3334class AnimatedTexture : public Texture2D {35GDCLASS(AnimatedTexture, Texture2D);3637// Use readers writers lock for this, since its far more times read than written to.38RWLock rw_lock;3940public:41enum {42MAX_FRAMES = 25643};4445private:46RID proxy_ph;47RID proxy;4849struct Frame {50Ref<Texture2D> texture;51float duration = 1.0;52};5354Frame frames[MAX_FRAMES];55int frame_count = 1.0;56int current_frame = 0;57bool pause = false;58bool one_shot = false;59float speed_scale = 1.0;6061float time = 0.0;6263uint64_t prev_ticks = 0;6465void _update_proxy();66void _finish_non_thread_safe_setup();6768protected:69static void _bind_methods();70void _validate_property(PropertyInfo &p_property) const;7172public:73void set_frames(int p_frames);74int get_frames() const;7576void set_current_frame(int p_frame);77int get_current_frame() const;7879void set_pause(bool p_pause);80bool get_pause() const;8182void set_one_shot(bool p_one_shot);83bool get_one_shot() const;8485void set_frame_texture(int p_frame, const Ref<Texture2D> &p_texture);86Ref<Texture2D> get_frame_texture(int p_frame) const;8788void set_frame_duration(int p_frame, float p_duration);89float get_frame_duration(int p_frame) const;9091void set_speed_scale(float p_scale);92float get_speed_scale() const;9394virtual int get_width() const override;95virtual int get_height() const override;96virtual RID get_rid() const override;9798virtual bool has_alpha() const override;99100virtual Ref<Image> get_image() const override;101102bool is_pixel_opaque(int p_x, int p_y) const override;103104AnimatedTexture();105~AnimatedTexture();106};107108109