diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/audio_stream.cpp | 61 | ||||
-rw-r--r-- | scene/resources/audio_stream.h | 83 | ||||
-rw-r--r-- | scene/resources/audio_stream_resampled.h | 2 | ||||
-rw-r--r-- | scene/resources/audio_stream_sample.cpp | 557 | ||||
-rw-r--r-- | scene/resources/audio_stream_sample.h | 128 | ||||
-rw-r--r-- | scene/resources/capsule_shape.cpp | 4 | ||||
-rw-r--r-- | scene/resources/color_ramp.cpp | 8 | ||||
-rw-r--r-- | scene/resources/curve.cpp | 6 | ||||
-rw-r--r-- | scene/resources/default_theme/theme_data.h | 6 | ||||
-rw-r--r-- | scene/resources/default_theme/vslider_grabber.png | bin | 554 -> 394 bytes | |||
-rw-r--r-- | scene/resources/default_theme/vslider_grabber_hl.png | bin | 701 -> 439 bytes | |||
-rw-r--r-- | scene/resources/scene_format_text.cpp | 13 | ||||
-rw-r--r-- | scene/resources/sphere_shape.cpp | 4 | ||||
-rw-r--r-- | scene/resources/texture.cpp | 373 | ||||
-rw-r--r-- | scene/resources/texture.h | 81 |
15 files changed, 1164 insertions, 162 deletions
diff --git a/scene/resources/audio_stream.cpp b/scene/resources/audio_stream.cpp deleted file mode 100644 index 7c269de007..0000000000 --- a/scene/resources/audio_stream.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************/ -/* audio_stream.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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 "audio_stream.h" - -////////////////////////////// - - -void AudioStreamPlayback::_bind_methods() { - - ClassDB::bind_method(_MD("play","from_pos_sec"),&AudioStreamPlayback::play,DEFVAL(0)); - ClassDB::bind_method(_MD("stop"),&AudioStreamPlayback::stop); - ClassDB::bind_method(_MD("is_playing"),&AudioStreamPlayback::is_playing); - - ClassDB::bind_method(_MD("set_loop","enabled"),&AudioStreamPlayback::set_loop); - ClassDB::bind_method(_MD("has_loop"),&AudioStreamPlayback::has_loop); - - ClassDB::bind_method(_MD("get_loop_count"),&AudioStreamPlayback::get_loop_count); - - ClassDB::bind_method(_MD("seek_pos","pos"),&AudioStreamPlayback::seek_pos); - ClassDB::bind_method(_MD("get_pos"),&AudioStreamPlayback::get_pos); - - ClassDB::bind_method(_MD("get_length"),&AudioStreamPlayback::get_length); - ClassDB::bind_method(_MD("get_channels"),&AudioStreamPlayback::get_channels); - ClassDB::bind_method(_MD("get_mix_rate"),&AudioStreamPlayback::get_mix_rate); - ClassDB::bind_method(_MD("get_minimum_buffer_size"),&AudioStreamPlayback::get_minimum_buffer_size); - - -} - - -void AudioStream::_bind_methods() { - - -} - diff --git a/scene/resources/audio_stream.h b/scene/resources/audio_stream.h deleted file mode 100644 index b79707cd32..0000000000 --- a/scene/resources/audio_stream.h +++ /dev/null @@ -1,83 +0,0 @@ -/*************************************************************************/ -/* audio_stream.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#ifndef AUDIO_STREAM_H -#define AUDIO_STREAM_H - -#include "resource.h" -#include "servers/audio_server.h" - -class AudioStreamPlayback : public Reference { - - GDCLASS( AudioStreamPlayback, Reference ); -protected: - static void _bind_methods(); -public: - - - virtual void play(float p_from_pos=0)=0; - virtual void stop()=0; - virtual bool is_playing() const=0; - - virtual void set_loop(bool p_enable)=0; - virtual bool has_loop() const=0; - - virtual void set_loop_restart_time(float p_time)=0; - - virtual int get_loop_count() const=0; - - virtual float get_pos() const=0; - virtual void seek_pos(float p_time)=0; - - virtual int mix(int16_t* p_bufer,int p_frames)=0; - - virtual float get_length() const=0; - virtual String get_stream_name() const=0; - - virtual int get_channels() const=0; - virtual int get_mix_rate() const=0; - virtual int get_minimum_buffer_size() const=0; - -}; - -class AudioStream : public Resource { - - GDCLASS( AudioStream, Resource ); - OBJ_SAVE_TYPE( AudioStream ); //children are all saved as AudioStream, so they can be exchanged - -protected: - static void _bind_methods(); -public: - - virtual Ref<AudioStreamPlayback> instance_playback()=0; - - -}; - - -#endif // AUDIO_STREAM_H diff --git a/scene/resources/audio_stream_resampled.h b/scene/resources/audio_stream_resampled.h index 761643b027..7ceb6cef84 100644 --- a/scene/resources/audio_stream_resampled.h +++ b/scene/resources/audio_stream_resampled.h @@ -29,7 +29,7 @@ #ifndef AUDIO_STREAM_RESAMPLED_H #define AUDIO_STREAM_RESAMPLED_H -#include "scene/resources/audio_stream.h" +//#include "scene/resources/audio_stream.h" #if 0 diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp new file mode 100644 index 0000000000..21339cb90b --- /dev/null +++ b/scene/resources/audio_stream_sample.cpp @@ -0,0 +1,557 @@ +#include "audio_stream_sample.h" + +void AudioStreamPlaybackSample::start(float p_from_pos) { + + for(int i=0;i<2;i++) { + ima_adpcm[i].step_index=0; + ima_adpcm[i].predictor=0; + ima_adpcm[i].loop_step_index=0; + ima_adpcm[i].loop_predictor=0; + ima_adpcm[i].last_nibble=-1; + ima_adpcm[i].loop_pos=0x7FFFFFFF; + ima_adpcm[i].window_ofs=0; + ima_adpcm[i].ptr=(const uint8_t*)base->data; + ima_adpcm[i].ptr+=AudioStreamSample::DATA_PAD; + } + + seek_pos(p_from_pos); + sign=1; + active=true; +} + +void AudioStreamPlaybackSample::stop() { + + active=false; +} + +bool AudioStreamPlaybackSample::is_playing() const { + + return active; +} + +int AudioStreamPlaybackSample::get_loop_count() const { + + return 0; +} + +float AudioStreamPlaybackSample::get_pos() const { + + return float(offset>>MIX_FRAC_BITS)/base->mix_rate; +} +void AudioStreamPlaybackSample::seek_pos(float p_time) { + + if (base->format==AudioStreamSample::FORMAT_IMA_ADPCM) + return; //no seeking in ima-adpcm + + float max=get_length(); + if (p_time<0) { + p_time=0; + } else if (p_time>=max) { + p_time=max-0.001; + } + + offset = uint64_t(p_time * base->mix_rate)<<MIX_FRAC_BITS; +} + + +template<class Depth,bool is_stereo,bool is_ima_adpcm> +void AudioStreamPlaybackSample::do_resample(const Depth* p_src, AudioFrame *p_dst,int64_t &offset,int32_t &increment,uint32_t amount,IMA_ADPCM_State *ima_adpcm) { + + // this function will be compiled branchless by any decent compiler + + int32_t final,final_r,next,next_r; + while (amount--) { + + int64_t pos=offset >> MIX_FRAC_BITS; + if (is_stereo && !is_ima_adpcm) + pos<<=1; + + if (is_ima_adpcm) { + + int64_t sample_pos = pos + ima_adpcm[0].window_ofs; + + while(sample_pos>ima_adpcm[0].last_nibble) { + + + static const int16_t _ima_adpcm_step_table[89] = { + 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, + 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, + 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, + 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, + 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, + 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, + 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, + 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, + 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 + }; + + static const int8_t _ima_adpcm_index_table[16] = { + -1, -1, -1, -1, 2, 4, 6, 8, + -1, -1, -1, -1, 2, 4, 6, 8 + }; + + for(int i=0;i<(is_stereo?2:1);i++) { + + + int16_t nibble,diff,step; + + ima_adpcm[i].last_nibble++; + const uint8_t *src_ptr=ima_adpcm[i].ptr; + + + uint8_t nbb = src_ptr[ (ima_adpcm[i].last_nibble>>1) * (is_stereo?2:1) + i ]; + nibble = (ima_adpcm[i].last_nibble&1)?(nbb>>4):(nbb&0xF); + step=_ima_adpcm_step_table[ima_adpcm[i].step_index]; + + + ima_adpcm[i].step_index += _ima_adpcm_index_table[nibble]; + if (ima_adpcm[i].step_index<0) + ima_adpcm[i].step_index=0; + if (ima_adpcm[i].step_index>88) + ima_adpcm[i].step_index=88; + + diff = step >> 3 ; + if (nibble & 1) + diff += step >> 2 ; + if (nibble & 2) + diff += step >> 1 ; + if (nibble & 4) + diff += step ; + if (nibble & 8) + diff = -diff ; + + ima_adpcm[i].predictor+=diff; + if (ima_adpcm[i].predictor<-0x8000) + ima_adpcm[i].predictor=-0x8000; + else if (ima_adpcm[i].predictor>0x7FFF) + ima_adpcm[i].predictor=0x7FFF; + + + /* store loop if there */ + if (ima_adpcm[i].last_nibble==ima_adpcm[i].loop_pos) { + + ima_adpcm[i].loop_step_index = ima_adpcm[i].step_index; + ima_adpcm[i].loop_predictor = ima_adpcm[i].predictor; + } + + //printf("%i - %i - pred %i\n",int(ima_adpcm[i].last_nibble),int(nibble),int(ima_adpcm[i].predictor)); + + } + + } + + final=ima_adpcm[0].predictor; + if (is_stereo) { + final_r=ima_adpcm[1].predictor; + } + + } else { + final=p_src[pos]; + if (is_stereo) + final_r=p_src[pos+1]; + + if (sizeof(Depth)==1) { /* conditions will not exist anymore when compiled! */ + final<<=8; + if (is_stereo) + final_r<<=8; + } + + if (is_stereo) { + + next=p_src[pos+2]; + next_r=p_src[pos+3]; + } else { + next=p_src[pos+1]; + } + + if (sizeof(Depth)==1) { + next<<=8; + if (is_stereo) + next_r<<=8; + } + + int32_t frac=int64_t(offset&MIX_FRAC_MASK); + + final=final+((next-final)*frac >> MIX_FRAC_BITS); + if (is_stereo) + final_r=final_r+((next_r-final_r)*frac >> MIX_FRAC_BITS); + + } + + + if (!is_stereo) { + final_r=final; //copy to right channel if stereo + } + + p_dst->l=final/32767.0; + p_dst->r=final_r/32767.0; + p_dst++; + + offset+=increment; + } +} + +void AudioStreamPlaybackSample::mix(AudioFrame* p_buffer,float p_rate_scale,int p_frames) { + + if (!base->data || !active) { + for(int i=0;i<p_frames;i++) { + p_buffer[i]=AudioFrame(0,0); + } + return; + } + + int len = base->data_bytes; + switch(base->format) { + case AudioStreamSample::FORMAT_8_BITS: len/=1; break; + case AudioStreamSample::FORMAT_16_BITS: len/=2; break; + case AudioStreamSample::FORMAT_IMA_ADPCM: len*=2; break; + } + + if (base->stereo) { + len/=2; + } + + /* some 64-bit fixed point precaches */ + + int64_t loop_begin_fp=((int64_t)len<< MIX_FRAC_BITS); + int64_t loop_end_fp=((int64_t)base->loop_end << MIX_FRAC_BITS); + int64_t length_fp=((int64_t)len << MIX_FRAC_BITS); + int64_t begin_limit=(base->loop_mode!=AudioStreamSample::LOOP_DISABLED)?loop_begin_fp:0; + int64_t end_limit=(base->loop_mode!=AudioStreamSample::LOOP_DISABLED)?loop_end_fp:length_fp; + bool is_stereo=base->stereo; + + int32_t todo=p_frames; + + float base_rate = AudioServer::get_singleton()->get_mix_rate(); + float srate = base->mix_rate; + srate*=p_rate_scale; + float fincrement = srate / base_rate; + int32_t increment = int32_t(fincrement * MIX_FRAC_LEN); + increment*=sign; + + + //looping + + AudioStreamSample::LoopMode loop_format=base->loop_mode; + AudioStreamSample::Format format = base->format; + + + /* audio data */ + + uint8_t *dataptr=(uint8_t*)base->data; + const void *data=dataptr+AudioStreamSample::DATA_PAD; + AudioFrame *dst_buff=p_buffer; + + + if (format==AudioStreamSample::FORMAT_IMA_ADPCM) { + + if (loop_format!=AudioStreamSample::LOOP_DISABLED) { + ima_adpcm[0].loop_pos=loop_begin_fp>>MIX_FRAC_BITS; + ima_adpcm[1].loop_pos=loop_begin_fp>>MIX_FRAC_BITS; + loop_format=AudioStreamSample::LOOP_FORWARD; + } + } + + while (todo>0) { + + int64_t limit=0; + int32_t target=0,aux=0; + + /** LOOP CHECKING **/ + + if ( increment < 0 ) { + /* going backwards */ + + if ( loop_format!=AudioStreamSample::LOOP_DISABLED && offset < loop_begin_fp ) { + /* loopstart reached */ + if ( loop_format==AudioStreamSample::LOOP_PING_PONG ) { + /* bounce ping pong */ + offset= loop_begin_fp + ( loop_begin_fp-offset ); + increment=-increment; + sign*=-1; + } else { + /* go to loop-end */ + offset=loop_end_fp-(loop_begin_fp-offset); + } + } else { + /* check for sample not reaching begining */ + if(offset < 0) { + + active=false; + break; + } + } + } else { + /* going forward */ + if( loop_format!=AudioStreamSample::LOOP_DISABLED && offset >= loop_end_fp ) { + /* loopend reached */ + + if ( loop_format==AudioStreamSample::LOOP_PING_PONG ) { + /* bounce ping pong */ + offset=loop_end_fp-(offset-loop_end_fp); + increment=-increment; + sign*=-1; + } else { + /* go to loop-begin */ + + if (format==AudioStreamSample::FORMAT_IMA_ADPCM) { + for(int i=0;i<2;i++) { + ima_adpcm[i].step_index=ima_adpcm[i].loop_step_index; + ima_adpcm[i].predictor=ima_adpcm[i].loop_predictor; + ima_adpcm[i].last_nibble=loop_begin_fp>>MIX_FRAC_BITS; + } + offset=loop_begin_fp; + } else { + offset=loop_begin_fp+(offset-loop_end_fp); + } + + } + } else { + /* no loop, check for end of sample */ + if(offset >= length_fp) { + + active=false; + break; + } + } + } + + /** MIXCOUNT COMPUTING **/ + + /* next possible limit (looppoints or sample begin/end */ + limit=(increment < 0) ?begin_limit:end_limit; + + /* compute what is shorter, the todo or the limit? */ + aux=(limit-offset)/increment+1; + target=(aux<todo)?aux:todo; /* mix target is the shorter buffer */ + + /* check just in case */ + if ( target<=0 ) { + active=false; + break; + } + + todo-=target; + + switch(base->format) { + case AudioStreamSample::FORMAT_8_BITS: { + + if (is_stereo) + do_resample<int8_t,true,false>((int8_t*)data,dst_buff,offset,increment,target,ima_adpcm); + else + do_resample<int8_t,false,false>((int8_t*)data,dst_buff,offset,increment,target,ima_adpcm); + } break; + case AudioStreamSample::FORMAT_16_BITS: { + if (is_stereo) + do_resample<int16_t,true,false>((int16_t*)data,dst_buff,offset,increment,target,ima_adpcm); + else + do_resample<int16_t,false,false>((int16_t*)data,dst_buff,offset,increment,target,ima_adpcm); + + } break; + case AudioStreamSample::FORMAT_IMA_ADPCM: { + if (is_stereo) + do_resample<int8_t,true,true>((int8_t*)data,dst_buff,offset,increment,target,ima_adpcm); + else + do_resample<int8_t,false,true>((int8_t*)data,dst_buff,offset,increment,target,ima_adpcm); + + } break; + } + + dst_buff+=target; + + } + + +} + +float AudioStreamPlaybackSample::get_length() const { + + int len = base->data_bytes; + switch(base->format) { + case AudioStreamSample::FORMAT_8_BITS: len/=1; break; + case AudioStreamSample::FORMAT_16_BITS: len/=2; break; + case AudioStreamSample::FORMAT_IMA_ADPCM: len*=2; break; + } + + if (base->stereo) { + len/=2; + } + + + return float(len)/base->mix_rate; +} + + +AudioStreamPlaybackSample::AudioStreamPlaybackSample() { + + active=false; + offset=0; + sign=1; +} + + +///////////////////// + + +void AudioStreamSample::set_format(Format p_format) { + + format=p_format; +} + +AudioStreamSample::Format AudioStreamSample::get_format() const{ + + return format; +} + +void AudioStreamSample::set_loop_mode(LoopMode p_loop_mode){ + + loop_mode=p_loop_mode; +} +AudioStreamSample::LoopMode AudioStreamSample::get_loop_mode() const{ + + return loop_mode; +} + +void AudioStreamSample::set_loop_begin(int p_frame){ + + loop_begin=p_frame; +} +int AudioStreamSample::get_loop_begin() const{ + + return loop_begin; +} + +void AudioStreamSample::set_loop_end(int p_frame){ + + loop_end=p_frame; +} +int AudioStreamSample::get_loop_end() const{ + + return loop_end; +} + + +void AudioStreamSample::set_mix_rate(int p_hz){ + + mix_rate=p_hz; +} +int AudioStreamSample::get_mix_rate() const{ + + return mix_rate; +} +void AudioStreamSample::set_stereo(bool p_enable){ + + stereo=p_enable; +} +bool AudioStreamSample::is_stereo() const{ + + return stereo; +} + +void AudioStreamSample::set_data(const PoolVector<uint8_t>& p_data) { + + AudioServer::get_singleton()->lock(); + if (data) { + AudioServer::get_singleton()->audio_data_free(data); + data=NULL; + data_bytes=0; + } + + int datalen = p_data.size(); + if (datalen) { + + PoolVector<uint8_t>::Read r = p_data.read(); + int alloc_len = datalen+DATA_PAD*2; + data = AudioServer::get_singleton()->audio_data_alloc(alloc_len); //alloc with some padding for interpolation + zeromem(data,alloc_len); + uint8_t *dataptr=(uint8_t*)data; + copymem(dataptr+DATA_PAD,r.ptr(),datalen); + data_bytes=datalen; + } + + AudioServer::get_singleton()->unlock(); + +} +PoolVector<uint8_t> AudioStreamSample::get_data() const{ + + PoolVector<uint8_t> pv; + + if (data) { + pv.resize(data_bytes); + { + + PoolVector<uint8_t>::Write w =pv.write(); + copymem(w.ptr(),data,data_bytes); + } + } + + return pv; +} + + +Ref<AudioStreamPlayback> AudioStreamSample::instance_playback() { + + Ref<AudioStreamPlaybackSample> sample; + sample.instance(); + sample->base=Ref<AudioStreamSample>(this); + return sample; +} + +String AudioStreamSample::get_stream_name() const { + + return ""; +} + +void AudioStreamSample::_bind_methods() { + + ClassDB::bind_method(_MD("set_format","format"),&AudioStreamSample::set_format); + ClassDB::bind_method(_MD("get_format"),&AudioStreamSample::get_format); + + ClassDB::bind_method(_MD("set_loop_mode","loop_mode"),&AudioStreamSample::set_loop_mode); + ClassDB::bind_method(_MD("get_loop_mode"),&AudioStreamSample::get_loop_mode); + + ClassDB::bind_method(_MD("set_loop_begin","loop_begin"),&AudioStreamSample::set_loop_begin); + ClassDB::bind_method(_MD("get_loop_begin"),&AudioStreamSample::get_loop_begin); + + ClassDB::bind_method(_MD("set_loop_end","loop_end"),&AudioStreamSample::set_loop_end); + ClassDB::bind_method(_MD("get_loop_end"),&AudioStreamSample::get_loop_end); + + ClassDB::bind_method(_MD("set_mix_rate","mix_rate"),&AudioStreamSample::set_mix_rate); + ClassDB::bind_method(_MD("get_mix_rate"),&AudioStreamSample::get_mix_rate); + + ClassDB::bind_method(_MD("set_stereo","stereo"),&AudioStreamSample::set_stereo); + ClassDB::bind_method(_MD("is_stereo"),&AudioStreamSample::is_stereo); + + ClassDB::bind_method(_MD("set_data","data"),&AudioStreamSample::set_data); + ClassDB::bind_method(_MD("get_data"),&AudioStreamSample::get_data); + + ADD_PROPERTY(PropertyInfo(Variant::INT,"format",PROPERTY_HINT_ENUM,"8-Bit,16-Bit,IMA-ADPCM"),_SCS("set_format"),_SCS("get_format")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"loop_mode",PROPERTY_HINT_ENUM,"Disabled,Forward,Ping-Pong"),_SCS("set_loop_mode"),_SCS("get_loop_mode")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"loop_begin"),_SCS("set_loop_begin"),_SCS("get_loop_begin")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"loop_end"),_SCS("set_loop_end"),_SCS("get_loop_end")); + ADD_PROPERTY(PropertyInfo(Variant::INT,"mix_rate"),_SCS("set_mix_rate"),_SCS("get_mix_rate")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL,"stereo"),_SCS("set_stereo"),_SCS("is_stereo")); + ADD_PROPERTY(PropertyInfo(Variant::POOL_BYTE_ARRAY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_data"),_SCS("get_data")); + +} + +AudioStreamSample::AudioStreamSample() +{ + format=FORMAT_8_BITS; + loop_mode=LOOP_DISABLED; + stereo=false; + loop_begin=0; + loop_end=0; + mix_rate=44100; + data=NULL; + data_bytes=0; +} +AudioStreamSample::~AudioStreamSample() { + + + if (data) { + AudioServer::get_singleton()->audio_data_free(data); + data=NULL; + data_bytes=0; + } +} diff --git a/scene/resources/audio_stream_sample.h b/scene/resources/audio_stream_sample.h new file mode 100644 index 0000000000..8c1e74608b --- /dev/null +++ b/scene/resources/audio_stream_sample.h @@ -0,0 +1,128 @@ +#ifndef AUDIOSTREAMSAMPLE_H +#define AUDIOSTREAMSAMPLE_H + +#include "servers/audio/audio_stream.h" + + +class AudioStreamSample; + +class AudioStreamPlaybackSample : public AudioStreamPlayback { + + GDCLASS( AudioStreamPlaybackSample, AudioStreamPlayback ) + enum { + MIX_FRAC_BITS=13, + MIX_FRAC_LEN=(1<<MIX_FRAC_BITS), + MIX_FRAC_MASK=MIX_FRAC_LEN-1, + }; + + struct IMA_ADPCM_State { + + int16_t step_index; + int32_t predictor; + /* values at loop point */ + int16_t loop_step_index; + int32_t loop_predictor; + int32_t last_nibble; + int32_t loop_pos; + int32_t window_ofs; + const uint8_t *ptr; + } ima_adpcm[2]; + + int64_t offset; + int sign; + bool active; +friend class AudioStreamSample; + Ref<AudioStreamSample> base; + + template<class Depth,bool is_stereo,bool is_ima_adpcm> + void do_resample(const Depth* p_src, AudioFrame *p_dst,int64_t &offset,int32_t &increment,uint32_t amount,IMA_ADPCM_State *ima_adpcm); +public: + + virtual void start(float p_from_pos=0.0); + virtual void stop(); + virtual bool is_playing() const; + + virtual int get_loop_count() const; //times it looped + + virtual float get_pos() const; + virtual void seek_pos(float p_time); + + virtual void mix(AudioFrame* p_buffer,float p_rate_scale,int p_frames); + + virtual float get_length() const; //if supported, otherwise return 0 + + + AudioStreamPlaybackSample(); +}; + +class AudioStreamSample : public AudioStream { + GDCLASS(AudioStreamSample,AudioStream) + RES_BASE_EXTENSION("smp") + +public: + + enum Format { + FORMAT_8_BITS, + FORMAT_16_BITS, + FORMAT_IMA_ADPCM + }; + + enum LoopMode { + LOOP_DISABLED, + LOOP_FORWARD, + LOOP_PING_PONG + }; + + +private: +friend class AudioStreamPlaybackSample; + + enum { + DATA_PAD=16 //padding for interpolation + }; + + Format format; + LoopMode loop_mode; + bool stereo; + int loop_begin; + int loop_end; + int mix_rate; + void *data; + uint32_t data_bytes; +protected: + + static void _bind_methods(); +public: + void set_format(Format p_format); + Format get_format() const; + + void set_loop_mode(LoopMode p_loop_mode); + LoopMode get_loop_mode() const; + + void set_loop_begin(int p_frame); + int get_loop_begin() const; + + void set_loop_end(int p_frame); + int get_loop_end() const; + + void set_mix_rate(int p_hz); + int get_mix_rate() const; + + void set_stereo(bool p_enable); + bool is_stereo() const; + + void set_data(const PoolVector<uint8_t>& p_data); + PoolVector<uint8_t> get_data() const; + + + virtual Ref<AudioStreamPlayback> instance_playback(); + virtual String get_stream_name() const; + + AudioStreamSample(); + ~AudioStreamSample(); +}; + +VARIANT_ENUM_CAST(AudioStreamSample::Format) +VARIANT_ENUM_CAST(AudioStreamSample::LoopMode) + +#endif // AUDIOSTREAMSample_H diff --git a/scene/resources/capsule_shape.cpp b/scene/resources/capsule_shape.cpp index db83a20f38..23538c1957 100644 --- a/scene/resources/capsule_shape.cpp +++ b/scene/resources/capsule_shape.cpp @@ -42,8 +42,8 @@ Vector<Vector3> CapsuleShape::_gen_debug_mesh_lines() { Vector3 d(0,0,height*0.5); for(int i=0;i<360;i++) { - float ra=Math::deg2rad(i); - float rb=Math::deg2rad(i+1); + float ra=Math::deg2rad((float)i); + float rb=Math::deg2rad((float)i+1); Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*radius; Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*radius; diff --git a/scene/resources/color_ramp.cpp b/scene/resources/color_ramp.cpp index 1144ea41f1..c577e3e444 100644 --- a/scene/resources/color_ramp.cpp +++ b/scene/resources/color_ramp.cpp @@ -27,6 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "color_ramp.h" +#include "core_string_names.h" //setter and getter names for property serialization #define COLOR_RAMP_GET_OFFSETS "get_offsets" @@ -104,6 +105,7 @@ void ColorRamp::set_offsets(const Vector<float>& p_offsets) { points[i].offset = p_offsets[i]; } is_sorted = false; + emit_signal(CoreStringNames::get_singleton()->changed); } void ColorRamp::set_colors(const Vector<Color>& p_colors) { @@ -114,6 +116,7 @@ void ColorRamp::set_colors(const Vector<Color>& p_colors) { { points[i].color = p_colors[i]; } + emit_signal(CoreStringNames::get_singleton()->changed); } Vector<ColorRamp::Point>& ColorRamp::get_points() { @@ -128,6 +131,7 @@ void ColorRamp::add_point(float p_offset, const Color& p_color) { is_sorted=false; points.push_back(p); + emit_signal(CoreStringNames::get_singleton()->changed); } void ColorRamp::remove_point(int p_index) { @@ -135,11 +139,13 @@ void ColorRamp::remove_point(int p_index) { ERR_FAIL_INDEX(p_index,points.size()); ERR_FAIL_COND(points.size()<=2); points.remove(p_index); + emit_signal(CoreStringNames::get_singleton()->changed); } void ColorRamp::set_points(Vector<ColorRamp::Point>& p_points) { points = p_points; is_sorted = false; + emit_signal(CoreStringNames::get_singleton()->changed); } void ColorRamp::set_offset(int pos, const float offset) { @@ -147,6 +153,7 @@ void ColorRamp::set_offset(int pos, const float offset) { points.resize(pos + 1); points[pos].offset = offset; is_sorted = false; + emit_signal(CoreStringNames::get_singleton()->changed); } float ColorRamp::get_offset(int pos) const { @@ -162,6 +169,7 @@ void ColorRamp::set_color(int pos, const Color& color) { is_sorted = false; } points[pos].color = color; + emit_signal(CoreStringNames::get_singleton()->changed); } Color ColorRamp::get_color(int pos) const { diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index e201cb16ac..3392c68e75 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -498,7 +498,7 @@ Vector2 Curve2D::interpolatef(real_t p_findex) const { else if (p_findex>=points.size()) p_findex=points.size(); - return interpolate((int)p_findex,Math::fmod(p_findex,1.0)); + return interpolate((int)p_findex,Math::fmod(p_findex,(real_t)1.0)); } @@ -653,7 +653,7 @@ Vector2 Curve2D::interpolate_baked(float p_offset,bool p_cubic) const{ return r[bpc-1]; int idx = Math::floor((double)p_offset/(double)bake_interval); - float frac = Math::fmod(p_offset,bake_interval); + float frac = Math::fmod(p_offset,(float)bake_interval); if (idx>=bpc-1) { return r[bpc-1]; @@ -974,7 +974,7 @@ Vector3 Curve3D::interpolatef(real_t p_findex) const { else if (p_findex>=points.size()) p_findex=points.size(); - return interpolate((int)p_findex,Math::fmod(p_findex,1.0)); + return interpolate((int)p_findex,Math::fmod(p_findex,(real_t)1.0)); } diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h index 46fd770a27..5b5868ba14 100644 --- a/scene/resources/default_theme/theme_data.h +++ b/scene/resources/default_theme/theme_data.h @@ -45,7 +45,7 @@ static const unsigned char button_normal_png[]={ static const unsigned char button_pressed_png[]={ -0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x3,0x0,0x0,0x0,0x28,0x2d,0xf,0x53,0x0,0x0,0x0,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x20,0x63,0x48,0x52,0x4d,0x0,0x0,0x7a,0x26,0x0,0x0,0x80,0x84,0x0,0x0,0xfa,0x0,0x0,0x0,0x80,0xe8,0x0,0x0,0x75,0x30,0x0,0x0,0xea,0x60,0x0,0x0,0x3a,0x98,0x0,0x0,0x17,0x70,0x9c,0xba,0x51,0x3c,0x0,0x0,0x0,0x93,0x50,0x4c,0x54,0x45,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x31,0x2f,0x37,0x46,0x43,0x4f,0x47,0x44,0x50,0x55,0x52,0x5f,0x55,0x52,0x60,0x3d,0x3a,0x45,0x56,0x52,0x60,0x56,0x52,0x60,0x43,0x40,0x4c,0x42,0x40,0x4b,0x3a,0x38,0x41,0x36,0x34,0x3d,0x44,0x42,0x4e,0x36,0x34,0x3e,0x46,0x42,0x4f,0x38,0x35,0x3f,0x47,0x45,0x50,0x39,0x37,0x40,0x49,0x46,0x53,0x3a,0x38,0x42,0x4a,0x47,0x54,0x3b,0x39,0x43,0x4b,0x49,0x55,0x3c,0x3a,0x44,0x4e,0x4a,0x58,0x3e,0x3b,0x46,0x50,0x4d,0x5a,0x3f,0x3d,0x48,0x3f,0x3d,0x47,0x45,0x42,0x4d,0x41,0x3e,0x49,0x40,0x3e,0x48,0x52,0x4e,0x5c,0x51,0x4e,0x5b,0xff,0xff,0xff,0x32,0xd2,0xb4,0xc,0x0,0x0,0x0,0x16,0x74,0x52,0x4e,0x53,0x4,0xa,0x11,0x19,0x1f,0x22,0x24,0x15,0x25,0x34,0x3f,0x46,0x47,0x48,0x77,0xef,0xef,0xef,0xef,0x77,0xef,0xed,0x6b,0x28,0x52,0x7a,0x0,0x0,0x0,0x1,0x62,0x4b,0x47,0x44,0x30,0xae,0xdc,0x2d,0xe4,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x6,0x16,0x12,0x2b,0x5,0x39,0x1a,0x32,0x39,0x0,0x0,0x0,0x95,0x49,0x44,0x41,0x54,0x18,0xd3,0x65,0xcf,0xdb,0x12,0x42,0x50,0x14,0x6,0xe0,0xb5,0x8f,0xf6,0x11,0xa5,0x24,0x9,0x49,0x22,0xd2,0xfb,0xbf,0x5d,0x9b,0x31,0xfb,0xa2,0xbe,0xcb,0x7f,0x66,0x1d,0x7e,0x0,0x84,0x9,0x65,0xdc,0x61,0x94,0x60,0x4,0x80,0x2,0x21,0x95,0x36,0xd6,0x1a,0xad,0xa4,0x8,0x10,0x60,0x11,0x46,0xe9,0x69,0x95,0x46,0xa1,0xc0,0x40,0x64,0x9c,0x9d,0x37,0x59,0x2c,0x9,0x50,0x95,0x5f,0xbc,0x5c,0x51,0x60,0xba,0xb8,0x7a,0x85,0x66,0xc0,0x4d,0x59,0x79,0xa5,0xe1,0xc0,0x6d,0x7d,0xf3,0x6a,0xbb,0x4,0xcd,0xdd,0x6b,0x96,0xc0,0xb4,0xf,0xaf,0x75,0x23,0x4c,0x77,0x4f,0xaf,0x73,0x4b,0xa9,0xea,0x87,0xd7,0x66,0xe8,0xdd,0x59,0x22,0x77,0xe3,0xf4,0x5e,0x4d,0xe3,0xde,0x3d,0x86,0x45,0x72,0x98,0x3f,0xab,0xf9,0x98,0xb8,0xd7,0xff,0xca,0xfd,0xd6,0xff,0x2,0x86,0xd,0x15,0x51,0x39,0x7d,0xa8,0x8e,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x63,0x72,0x65,0x61,0x74,0x65,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xc9,0xad,0xc8,0x52,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x6d,0x6f,0x64,0x69,0x66,0x79,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xb8,0xf0,0x70,0xee,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x7,0x1c,0xc,0x14,0x2b,0xf9,0x77,0x52,0x64,0x0,0x0,0x1,0x92,0x49,0x44,0x41,0x54,0x38,0xcb,0x8d,0x93,0x4d,0x4e,0x1b,0x41,0x10,0x85,0xbf,0xea,0xaa,0x1e,0x20,0x83,0xf9,0x9,0x36,0xb2,0x85,0x72,0x84,0x8,0x65,0x11,0xe5,0xc,0x9c,0x80,0x73,0x10,0xee,0xc1,0x41,0x38,0x1,0xab,0xec,0xa3,0x2c,0x2,0x8a,0xe0,0x2,0x51,0xc2,0x48,0x46,0x42,0x64,0xc6,0x91,0x21,0xf4,0x74,0x16,0x2e,0xb0,0x71,0x2,0xf2,0x93,0x9e,0xba,0x16,0xdd,0xaf,0x5e,0xa9,0x5f,0x9,0x60,0x40,0x1,0x2c,0x1,0xcb,0x5e,0x2b,0x10,0x78,0x8a,0x16,0x48,0xc0,0x1d,0x30,0x6,0x6e,0x81,0x3b,0xf3,0x87,0x25,0xb0,0x9,0xac,0x7b,0xbd,0xc,0x88,0x13,0x20,0x3b,0xc7,0xc0,0x8,0xb8,0x1,0xae,0x81,0x91,0xf9,0xe5,0xad,0x77,0xbb,0x1f,0xf6,0x7b,0xdd,0xfe,0x41,0x4a,0x69,0x2d,0x93,0xf9,0x1f,0x4,0x41,0x55,0x7f,0xd,0xaf,0xaa,0xa3,0xaf,0x67,0x9f,0x8f,0x81,0x64,0xde,0xb1,0xbb,0xdd,0x1b,0x7c,0xac,0x9b,0x9b,0xce,0xd9,0xb7,0x2f,0xfc,0xf3,0x5e,0xa6,0xe5,0xee,0xdb,0xf7,0x6b,0xdb,0xbd,0xc1,0x21,0xf0,0x9,0x18,0x5,0x60,0x5,0xd8,0x48,0x6d,0xdb,0x39,0xbf,0x38,0xc5,0x34,0x62,0x36,0x47,0x9d,0xf2,0xfc,0xe2,0x94,0xd4,0xb6,0x1d,0x60,0x3,0x58,0x31,0x20,0x2,0x65,0x40,0x88,0x31,0x92,0xbd,0xbb,0x8,0xe4,0x3c,0x39,0x67,0x91,0x33,0x84,0x89,0xa5,0x12,0x88,0xf,0x3f,0x10,0x45,0x5,0xb3,0xc8,0x73,0x10,0x11,0xb2,0xab,0x8b,0xa,0xde,0xb8,0x30,0x9f,0xb0,0x8,0xa2,0xc4,0x58,0xb0,0x8,0x82,0x28,0xde,0x58,0xcc,0xff,0x5c,0x45,0x64,0x61,0x1,0x99,0xcc,0xa5,0x80,0x4e,0x5,0xc2,0xcb,0x2,0xe2,0x41,0x10,0x40,0xc2,0x53,0x81,0xc,0xa8,0x8a,0x52,0x2c,0xe8,0x40,0x27,0x23,0x28,0x90,0xcd,0xe3,0x79,0x1b,0x34,0x50,0x14,0x4b,0xf0,0x4c,0x88,0x66,0xbd,0x4,0xd,0x78,0x94,0x93,0x79,0x3c,0x9b,0x18,0x63,0x7a,0xbd,0xb9,0xa5,0xcd,0xa8,0x7e,0xb4,0x3a,0x2f,0x15,0x10,0xca,0x72,0x95,0x18,0x8b,0x4,0x34,0xc0,0xd8,0x80,0x1a,0x18,0x56,0xd5,0xcf,0x93,0x41,0x7f,0x67,0xaf,0xb3,0xba,0x1e,0x5e,0x8a,0xb2,0x99,0xb5,0x97,0xd5,0x8f,0x13,0x60,0x8,0xd4,0x2,0x74,0x9d,0x6f,0x80,0xbe,0x2f,0x55,0xe9,0x26,0xc2,0xcc,0x26,0x66,0x5f,0xa4,0x6b,0xa0,0x2,0xbe,0x3,0x57,0xe6,0x56,0x1e,0x66,0x1a,0x2,0xaf,0x3c,0x24,0x36,0x67,0xe0,0x1e,0xf8,0x3,0xfc,0xf6,0x6d,0xac,0x81,0xe6,0x2f,0x7c,0x22,0x6d,0x74,0x25,0xb,0xb3,0xa2,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; @@ -540,12 +540,12 @@ static const unsigned char vslider_bg_png[]={ static const unsigned char vslider_grabber_png[]={ -0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x4,0x0,0x0,0x0,0xb5,0xfa,0x37,0xea,0x0,0x0,0x0,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x20,0x63,0x48,0x52,0x4d,0x0,0x0,0x7a,0x26,0x0,0x0,0x80,0x84,0x0,0x0,0xfa,0x0,0x0,0x0,0x80,0xe8,0x0,0x0,0x75,0x30,0x0,0x0,0xea,0x60,0x0,0x0,0x3a,0x98,0x0,0x0,0x17,0x70,0x9c,0xba,0x51,0x3c,0x0,0x0,0x0,0x2,0x62,0x4b,0x47,0x44,0x0,0xff,0x87,0x8f,0xcc,0xbf,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x6,0x16,0x12,0x2b,0x5,0x39,0x1a,0x32,0x39,0x0,0x0,0x0,0xf8,0x49,0x44,0x41,0x54,0x28,0xcf,0xbd,0x90,0xaf,0x4b,0x43,0x51,0x18,0x86,0x9f,0xf3,0x43,0xcf,0x76,0xae,0xde,0xb9,0xc9,0x1c,0x82,0x86,0xa1,0x16,0x15,0x87,0xc3,0x20,0x68,0x30,0x58,0xb4,0x5a,0x6c,0x62,0x37,0x88,0xff,0x81,0xc5,0xe4,0x5f,0x70,0x8b,0x75,0x45,0xb3,0xc1,0xa6,0x41,0x4,0x19,0xc,0x19,0x18,0x4,0x8d,0xb,0x82,0xdb,0xd8,0x81,0x29,0xf7,0x1e,0x8b,0x6e,0x43,0x30,0xea,0x93,0x5e,0xf8,0x5e,0x5e,0x78,0x3e,0xf8,0x73,0xc4,0x40,0x92,0x18,0x46,0x9,0x18,0xc6,0xd3,0xa1,0x89,0x23,0xee,0x17,0x86,0xc8,0x14,0xa7,0x97,0x57,0x4a,0xdb,0xe1,0xa2,0xc9,0x4b,0xdf,0xac,0x3d,0x9d,0x47,0x15,0x5e,0x89,0x5,0x20,0xb0,0x23,0xc5,0x83,0xc3,0xc2,0xa6,0x99,0xea,0xaa,0xf,0x62,0xc0,0xa0,0x1b,0xf,0x27,0xd1,0x19,0x6d,0x8d,0x66,0x6c,0x75,0x6d,0xf7,0x54,0xcd,0x3a,0x1c,0xc9,0xd7,0x60,0x8c,0x2d,0xcc,0xec,0x70,0x41,0x5b,0x63,0x8e,0xf6,0xe6,0x8f,0xdf,0x82,0x4e,0xef,0x8,0xe0,0xe9,0x92,0x5d,0x22,0x0,0x89,0x48,0x59,0xd4,0xef,0x16,0x8a,0xe4,0xba,0xde,0xaa,0x2e,0x94,0x53,0xb9,0x4,0x8f,0xef,0x29,0xa5,0x71,0x77,0x57,0x15,0x5a,0x8a,0x4,0xf7,0xfc,0x72,0x73,0x39,0xc7,0xf8,0x44,0x90,0x11,0x2,0x24,0x92,0x34,0xba,0xf1,0x18,0xdd,0xdf,0xf2,0xde,0xd7,0xc,0x75,0x7e,0x6b,0x7d,0x63,0x5f,0x4c,0x9a,0x9c,0xfa,0xa1,0xf9,0x8d,0xc4,0x12,0x62,0xd1,0x83,0x8f,0xfa,0x7,0x3e,0x1,0x87,0xd0,0x4a,0x12,0xcf,0xee,0xfb,0xd8,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x63,0x72,0x65,0x61,0x74,0x65,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xc9,0xad,0xc8,0x52,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x6d,0x6f,0x64,0x69,0x66,0x79,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xb8,0xf0,0x70,0xee,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x4,0x0,0x0,0x0,0xb5,0xfa,0x37,0xea,0x0,0x0,0x0,0x2,0x62,0x4b,0x47,0x44,0x0,0xb7,0xff,0x88,0x5,0x1d,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe1,0x1,0x12,0x1,0x36,0x8,0x50,0xb9,0xa7,0x53,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0xf6,0x49,0x44,0x41,0x54,0x28,0xcf,0xbd,0x90,0xb1,0x4a,0x42,0x51,0x0,0x86,0xbf,0x73,0x8e,0x71,0xe5,0x9a,0x5c,0x41,0xd0,0x66,0x6b,0x33,0x1c,0x7c,0x80,0xa0,0xa5,0x17,0x8,0xa2,0x2d,0x84,0xf0,0x1,0xa2,0x25,0xf1,0x9,0x9a,0x1c,0xda,0x5b,0xb2,0x47,0xa8,0xa5,0xc1,0xa0,0x51,0x88,0xa2,0x29,0xa,0xc1,0x84,0x8,0x43,0xf4,0x96,0x17,0xcf,0xed,0xde,0x73,0x9c,0xcc,0x5c,0xda,0xea,0x9f,0x3f,0xfe,0x9f,0xef,0x87,0x3f,0x8f,0x0,0x40,0xe1,0xe2,0x91,0x42,0x10,0x32,0xe6,0x3,0x8d,0xc1,0xce,0x1,0x45,0xb6,0xba,0xbb,0xba,0xed,0x95,0x8c,0xd0,0x7d,0xff,0xe1,0xee,0xe2,0xb6,0xdd,0x79,0x61,0xc4,0xd7,0xc,0x48,0x57,0x2b,0xeb,0xb5,0x28,0xaf,0x1,0xc5,0x12,0x4e,0xac,0x7b,0x6f,0x57,0x27,0x8d,0xcf,0xe,0x1,0x56,0x1,0xb9,0x9d,0xba,0x28,0x6,0x18,0xc,0x31,0x21,0x5a,0xda,0x4c,0xb6,0xbc,0xb9,0x35,0x7c,0xea,0xbd,0x13,0x4a,0x20,0xe5,0x95,0xf4,0x6c,0x12,0x30,0x84,0xf8,0x44,0x6b,0xfb,0xcd,0x83,0x3d,0x1c,0xf9,0x8b,0x80,0x4a,0xba,0x88,0x4,0x30,0x1e,0xdd,0x3b,0x1b,0xf1,0x77,0x87,0x24,0x81,0x8b,0x79,0x3e,0x3b,0x6a,0x5d,0x33,0x51,0x80,0x2d,0x38,0x2b,0x65,0xb5,0x6c,0x91,0x28,0x92,0xa4,0xad,0xec,0x76,0xcf,0x8f,0xf,0x1f,0xdb,0xc,0x31,0xb,0x9a,0xb1,0xd0,0x3,0xfb,0xda,0x3a,0xbd,0xbc,0x89,0xfa,0xf8,0x73,0xcd,0x9f,0x47,0x45,0x4,0xf8,0x4,0x18,0xfe,0x2f,0x53,0x8,0x62,0x5c,0xcf,0x1f,0x5f,0xcb,0x2c,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; static const unsigned char vslider_grabber_hl_png[]={ -0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x3,0x0,0x0,0x0,0x28,0x2d,0xf,0x53,0x0,0x0,0x0,0x4,0x67,0x41,0x4d,0x41,0x0,0x0,0xb1,0x8f,0xb,0xfc,0x61,0x5,0x0,0x0,0x0,0x20,0x63,0x48,0x52,0x4d,0x0,0x0,0x7a,0x26,0x0,0x0,0x80,0x84,0x0,0x0,0xfa,0x0,0x0,0x0,0x80,0xe8,0x0,0x0,0x75,0x30,0x0,0x0,0xea,0x60,0x0,0x0,0x3a,0x98,0x0,0x0,0x17,0x70,0x9c,0xba,0x51,0x3c,0x0,0x0,0x0,0xc6,0x50,0x4c,0x54,0x45,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x17,0x2a,0x29,0x3a,0x69,0x69,0x5b,0xa6,0xa5,0x61,0xb3,0xbc,0x63,0xb7,0xc8,0x65,0xbb,0xca,0x60,0xaf,0xb1,0x48,0x83,0x83,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0xf,0xf,0x55,0x9b,0x9a,0x60,0xb2,0xbd,0x5e,0xb1,0xcd,0x61,0xb3,0xc2,0x0,0x0,0x0,0x27,0x48,0x47,0x62,0xb4,0xbd,0x51,0x93,0x92,0x68,0xc0,0xcf,0x0,0x0,0x0,0x56,0x9d,0x9c,0x68,0xc1,0xcf,0x2d,0x52,0x52,0x63,0xb7,0xbf,0x52,0x96,0x95,0x62,0xb3,0xbf,0x5e,0xb0,0xcd,0x0,0x0,0x0,0x3,0x5,0x5,0x36,0x63,0x63,0x63,0xb4,0xb6,0x60,0xb1,0xbc,0x63,0xb7,0xc7,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x55,0xa3,0xc8,0x4f,0x98,0xc4,0x4b,0x93,0xc2,0x4c,0x94,0xc2,0x54,0xa2,0xc8,0x5a,0xab,0xcb,0x4e,0x97,0xc4,0x49,0x8f,0xc0,0x47,0x8c,0xbf,0x48,0x8e,0xc0,0x52,0x9e,0xc6,0x51,0x9d,0xc6,0x5a,0xac,0xcc,0x53,0x9f,0xc7,0x4d,0x96,0xc3,0x4b,0x92,0xc2,0xff,0xff,0xff,0xec,0x37,0x7,0xf6,0x0,0x0,0x0,0x31,0x74,0x52,0x4e,0x53,0x0,0x1,0x3,0xa,0x17,0x22,0x28,0x27,0x1c,0xd,0x5,0x14,0x31,0x65,0xaf,0xdb,0xf0,0xef,0xc1,0x6e,0x16,0xb,0x2c,0x9c,0xe0,0xfc,0xe8,0x4,0x4f,0xdb,0x73,0xf4,0xc,0x7d,0xf7,0x55,0xdc,0x95,0xe0,0xfe,0x13,0x28,0x64,0xc5,0xde,0xf0,0x2,0x1a,0x24,0x77,0x58,0x79,0x88,0x0,0x0,0x0,0x1,0x62,0x4b,0x47,0x44,0x41,0x89,0xde,0x6c,0x4e,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe0,0x6,0x16,0x12,0x2b,0x5,0x39,0x1a,0x32,0x39,0x0,0x0,0x0,0x7d,0x49,0x44,0x41,0x54,0x18,0xd3,0x63,0x60,0x20,0xf,0x30,0x32,0x31,0xb3,0xb0,0xb2,0xb1,0x73,0x70,0x32,0x41,0xf8,0x5c,0xdc,0x3c,0xbc,0x7c,0xfc,0x2,0x82,0x42,0xc2,0x22,0x20,0x11,0x46,0x51,0x31,0x71,0x9,0x49,0x43,0x23,0x63,0x13,0x53,0x29,0x61,0x4e,0x6,0x6,0x69,0x6e,0x19,0x59,0x33,0x73,0xb,0x4b,0x20,0xb0,0x32,0x15,0xe2,0x60,0x60,0x10,0x95,0x93,0xb7,0x6,0x73,0x81,0xc0,0x44,0x90,0x9d,0x81,0x41,0x41,0x51,0xc9,0x6,0x45,0x40,0x5a,0x44,0x59,0xc5,0x16,0x59,0xb,0x3,0xa3,0x82,0x98,0xaa,0x9a,0xba,0x9d,0xbd,0x3,0xd4,0x50,0x90,0xb5,0x1a,0x9a,0x5a,0xda,0x3a,0xba,0x30,0x6b,0x41,0x40,0x4f,0x41,0xdf,0x0,0xc9,0x61,0x24,0x2,0x0,0x9d,0x96,0x10,0xf9,0x6,0xb2,0x58,0x28,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x63,0x72,0x65,0x61,0x74,0x65,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xc9,0xad,0xc8,0x52,0x0,0x0,0x0,0x25,0x74,0x45,0x58,0x74,0x64,0x61,0x74,0x65,0x3a,0x6d,0x6f,0x64,0x69,0x66,0x79,0x0,0x32,0x30,0x31,0x36,0x2d,0x30,0x36,0x2d,0x32,0x32,0x54,0x32,0x30,0x3a,0x33,0x39,0x3a,0x32,0x36,0x2b,0x30,0x32,0x3a,0x30,0x30,0xb8,0xf0,0x70,0xee,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x3,0x0,0x0,0x0,0x28,0x2d,0xf,0x53,0x0,0x0,0x0,0xc3,0x50,0x4c,0x54,0x45,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x17,0x2a,0x29,0x3a,0x69,0x69,0x5b,0xa6,0xa5,0x61,0xb3,0xbc,0x63,0xb7,0xc8,0x65,0xbb,0xca,0x60,0xaf,0xb1,0x48,0x83,0x83,0x0,0x0,0x0,0x0,0x0,0x0,0x8,0xf,0xf,0x55,0x9b,0x9a,0x60,0xb2,0xbd,0x5e,0xb1,0xcd,0x61,0xb3,0xc2,0x0,0x0,0x0,0x27,0x48,0x47,0x62,0xb4,0xbd,0x51,0x93,0x92,0x68,0xc0,0xcf,0x0,0x0,0x0,0x56,0x9d,0x9c,0x68,0xc1,0xcf,0x2d,0x52,0x52,0x63,0xb7,0xbf,0x52,0x96,0x95,0x62,0xb3,0xbf,0x5e,0xb0,0xcd,0x0,0x0,0x0,0x3,0x5,0x5,0x36,0x63,0x63,0x63,0xb4,0xb6,0x60,0xb1,0xbc,0x63,0xb7,0xc7,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x55,0xa3,0xc8,0x4f,0x98,0xc4,0x4b,0x93,0xc2,0x4c,0x94,0xc2,0x54,0xa2,0xc8,0x5a,0xab,0xcb,0x4e,0x97,0xc4,0x49,0x8f,0xc0,0x47,0x8c,0xbf,0x48,0x8e,0xc0,0x52,0x9e,0xc6,0x51,0x9d,0xc6,0x5a,0xac,0xcc,0x53,0x9f,0xc7,0x4d,0x96,0xc3,0x4b,0x92,0xc2,0xff,0xff,0xff,0x76,0xbd,0x27,0x7a,0x0,0x0,0x0,0x1,0x74,0x52,0x4e,0x53,0x0,0x40,0xe6,0xd8,0x66,0x0,0x0,0x0,0x1,0x62,0x4b,0x47,0x44,0x0,0x88,0x5,0x1d,0x48,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xe1,0x1,0x12,0x1,0x36,0x11,0x34,0xd2,0xf,0x93,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0x48,0x49,0x44,0x41,0x54,0x18,0xd3,0x63,0x60,0xa0,0x12,0x10,0x14,0xe0,0xe7,0xe3,0x45,0xe2,0x4b,0x9a,0x18,0x1b,0x19,0x1a,0x48,0x88,0x8b,0xc1,0xe4,0x4d,0x2c,0x2d,0x80,0xc0,0xdc,0xcc,0x54,0x6,0x22,0x20,0x60,0x6c,0x1,0x1,0xe6,0x56,0x72,0x68,0x2,0xd6,0x8a,0xa8,0x5a,0x6c,0x94,0x11,0x86,0xda,0xdb,0xd9,0xaa,0xa9,0xaa,0x20,0x59,0xab,0xa3,0xad,0xc5,0x40,0x3d,0x0,0x0,0xbf,0x8e,0xc,0xed,0xed,0xc7,0x67,0x72,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; diff --git a/scene/resources/default_theme/vslider_grabber.png b/scene/resources/default_theme/vslider_grabber.png Binary files differindex a61a6a57c9..afc490be45 100644 --- a/scene/resources/default_theme/vslider_grabber.png +++ b/scene/resources/default_theme/vslider_grabber.png diff --git a/scene/resources/default_theme/vslider_grabber_hl.png b/scene/resources/default_theme/vslider_grabber_hl.png Binary files differindex 548dbbbff8..548972e115 100644 --- a/scene/resources/default_theme/vslider_grabber_hl.png +++ b/scene/resources/default_theme/vslider_grabber_hl.png diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp index a913687e7f..9719f321d6 100644 --- a/scene/resources/scene_format_text.cpp +++ b/scene/resources/scene_format_text.cpp @@ -32,7 +32,8 @@ #include "version.h" #include "os/dir_access.h" -#define FORMAT_VERSION 1 +//version 2: changed names for basis, rect3, poolvectors, etc. +#define FORMAT_VERSION 2 #include "version.h" #include "os/dir_access.h" @@ -1158,7 +1159,7 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant& p_variant,b static String _valprop(const String& p_name) { if (p_name.find("\"")!=-1 || p_name.find("=")!=-1 || p_name.find(" ")!=-1) - return "\""+p_name.c_escape()+"\""; + return "\""+p_name.c_escape_multiline()+"\""; return p_name; } @@ -1360,13 +1361,11 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re } if (groups.size()) { - String sgroups=" groups=[ "; + String sgroups=" groups=[\n"; for(int j=0;j<groups.size();j++) { - if (j>0) - sgroups+=", "; - sgroups+="\""+groups[j].operator String().c_escape()+"\""; + sgroups+="\""+String(groups[j]).c_escape()+"\",\n"; } - sgroups+=" ]"; + sgroups+="]"; header+=sgroups; } diff --git a/scene/resources/sphere_shape.cpp b/scene/resources/sphere_shape.cpp index bcfb164b4c..c7c4d94aad 100644 --- a/scene/resources/sphere_shape.cpp +++ b/scene/resources/sphere_shape.cpp @@ -37,8 +37,8 @@ Vector<Vector3> SphereShape::_gen_debug_mesh_lines() { for(int i=0;i<=360;i++) { - float ra=Math::deg2rad(i); - float rb=Math::deg2rad(i+1); + float ra=Math::deg2rad((float)i); + float rb=Math::deg2rad((float)i+1); Point2 a = Vector2(Math::sin(ra),Math::cos(ra))*r; Point2 b = Vector2(Math::sin(rb),Math::cos(rb))*r; diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index a1ad5d8237..fa89b7ba00 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -453,6 +453,379 @@ ImageTexture::~ImageTexture() { VisualServer::get_singleton()->free( texture ); } +////////////////////////////////////////// + + +void StreamTexture::_requested_3d(void* p_ud) { + + StreamTexture *st = (StreamTexture *)p_ud; + Ref<StreamTexture> stex(st); + ERR_FAIL_COND(!request_3d_callback); + request_3d_callback(stex); +} + +void StreamTexture::_requested_srgb(void* p_ud) { + + StreamTexture *st = (StreamTexture *)p_ud; + Ref<StreamTexture> stex(st); + ERR_FAIL_COND(!request_srgb_callback); + request_srgb_callback(stex); + +} + +StreamTexture::TextureFormatRequestCallback StreamTexture::request_3d_callback=NULL; +StreamTexture::TextureFormatRequestCallback StreamTexture::request_srgb_callback=NULL; + + +uint32_t StreamTexture::get_flags() const { + + return flags; +} +Image::Format StreamTexture::get_format() const { + + return format; +} + + +Error StreamTexture::_load_data(const String& p_path,int &tw,int &th,int& flags,Image& image,int p_size_limit) { + + + FileAccess *f = FileAccess::open(p_path,FileAccess::READ); + ERR_FAIL_COND_V(!f,ERR_CANT_OPEN); + + uint8_t header[4]; + f->get_buffer(header,4); + if (header[0]!='G' || header[1]!='D' || header[2]!='S' || header[3]!='T') { + memdelete(f); + ERR_FAIL_COND_V(header[0]!='G' || header[1]!='D' || header[2]!='S' || header[3]!='T',ERR_FILE_CORRUPT); + } + + tw = f->get_32(); + th = f->get_32(); + flags= f->get_32(); //texture flags! + uint32_t df = f->get_32(); //data format + + print_line("width: "+itos(tw)); + print_line("height: "+itos(th)); + print_line("flags: "+itos(flags)); + print_line("df: "+itos(df)); + + + if (request_3d_callback && df&FORMAT_BIT_DETECT_3D) { + print_line("request detect 3D at "+p_path); + VS::get_singleton()->texture_set_detect_3d_callback(texture,_requested_3d,this); + } else { + print_line("not requesting detect 3D at "+p_path); + VS::get_singleton()->texture_set_detect_3d_callback(texture,NULL,NULL); + } + + if (request_srgb_callback && df&FORMAT_BIT_DETECT_SRGB) { + print_line("request detect srgb at "+p_path); + VS::get_singleton()->texture_set_detect_srgb_callback(texture,_requested_srgb,this); + } else { + VS::get_singleton()->texture_set_detect_srgb_callback(texture,NULL,NULL); + print_line("not requesting detect srgb at "+p_path); + } + + if (!(df&FORMAT_BIT_STREAM)) { + p_size_limit=0; + } + + + if (df&FORMAT_BIT_LOSSLESS || df&FORMAT_BIT_LOSSY) { + //look for a PNG or WEBP file inside + + int sw=tw; + int sh=th; + + uint32_t mipmaps = f->get_32(); + uint32_t size = f->get_32(); + + print_line("mipmaps: "+itos(mipmaps)); + + while(mipmaps>1 && p_size_limit>0 && (sw>p_size_limit || sh>p_size_limit)) { + + f->seek(f->get_pos()+size); + mipmaps = f->get_32(); + size = f->get_32(); + + sw=MAX(sw>>1,1); + sh=MAX(sh>>1,1); + mipmaps--; + } + + //mipmaps need to be read independently, they will be later combined + Vector<Image> mipmap_images; + int total_size=0; + + for(int i=0;i<mipmaps;i++) { + PoolVector<uint8_t> pv; + pv.resize(size); + { + PoolVector<uint8_t>::Write w = pv.write(); + f->get_buffer(w.ptr(),size); + } + + Image img; + if (df&FORMAT_BIT_LOSSLESS) { + img = Image::lossless_unpacker(pv); + } else { + img = Image::lossy_unpacker(pv); + } + + if (img.empty()) { + memdelete(f); + ERR_FAIL_COND_V(img.empty(),ERR_FILE_CORRUPT); + } + total_size+=img.get_data().size(); + + mipmap_images.push_back(img); + } + + print_line("mipmap read total: "+itos(mipmap_images.size())); + + + memdelete(f); //no longer needed + + if (mipmap_images.size()==1) { + + image=mipmap_images[0]; + return OK; + + } else { + PoolVector<uint8_t> img_data; + img_data.resize(total_size); + + { + PoolVector<uint8_t>::Write w=img_data.write(); + + int ofs=0; + for(int i=0;i<mipmap_images.size();i++) { + + PoolVector<uint8_t> id = mipmap_images[i].get_data(); + int len = id.size(); + PoolVector<uint8_t>::Read r = id.read(); + copymem(&w[ofs],r.ptr(),len); + ofs+=len; + } + } + + image = Image(sw,sh,true,mipmap_images[0].get_format(),img_data); + return OK; + } + + } else { + + //look for regular format + Image::Format format = (Image::Format)(df&FORMAT_MASK_IMAGE_FORMAT); + bool mipmaps = df&FORMAT_BIT_HAS_MIPMAPS; + + if (!mipmaps) { + int size = Image::get_image_data_size(tw,th,format,0); + + PoolVector<uint8_t> img_data; + img_data.resize(size); + + { + PoolVector<uint8_t>::Write w=img_data.write(); + f->get_buffer(w.ptr(),size); + } + + memdelete(f); + + image = Image(tw,th,false,format,img_data); + return OK; + } else { + + int sw=tw; + int sh=th; + + int mipmaps = Image::get_image_required_mipmaps(tw,th,format); + int total_size = Image::get_image_data_size(tw,th,format,mipmaps); + int idx=0; + int ofs=0; + + + while(mipmaps>1 && p_size_limit>0 && (sw>p_size_limit || sh>p_size_limit)) { + + sw=MAX(sw>>1,1); + sh=MAX(sh>>1,1); + mipmaps--; + idx++; + } + + if (idx>0) { + ofs=Image::get_image_data_size(tw,th,format,idx-1); + } + + if (total_size - ofs <=0) { + memdelete(f); + ERR_FAIL_V(ERR_FILE_CORRUPT); + } + + f->seek(f->get_pos()+ofs); + + + PoolVector<uint8_t> img_data; + img_data.resize(total_size - ofs); + + { + PoolVector<uint8_t>::Write w=img_data.write(); + int bytes = f->get_buffer(w.ptr(),total_size - ofs); + print_line("requested read: "+itos(total_size - ofs)+" but got: "+itos(bytes)); + + memdelete(f); + + if (bytes != total_size - ofs) { + ERR_FAIL_V(ERR_FILE_CORRUPT); + } + } + + image = Image(sw,sh,true,format,img_data); + + return OK; + } + } + + return ERR_BUG; //unreachable +} + +Error StreamTexture::load(const String& p_path) { + + + int lw,lh,lflags; + Image image; + Error err = _load_data(p_path,lw,lh,lflags,image); + if (err) + return err; + + VS::get_singleton()->texture_allocate(texture,image.get_width(),image.get_height(),image.get_format(),lflags); + VS::get_singleton()->texture_set_data(texture,image); + + w=lw; + h=lh; + flags=lflags; + path_to_file=p_path; + format=image.get_format(); + + return OK; +} +String StreamTexture::get_load_path() const { + + return path_to_file; +} + +int StreamTexture::get_width() const { + + return w; +} +int StreamTexture::get_height() const { + + return h; +} +RID StreamTexture::get_rid() const { + + return texture; +} + + +void StreamTexture::draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate, bool p_transpose) const { + + if ((w|h)==0) + return; + VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item,Rect2( p_pos, Size2(w,h)),texture,false,p_modulate,p_transpose); + +} +void StreamTexture::draw_rect(RID p_canvas_item,const Rect2& p_rect, bool p_tile,const Color& p_modulate, bool p_transpose) const { + + if ((w|h)==0) + return; + VisualServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item,p_rect,texture,p_tile,p_modulate,p_transpose); + +} +void StreamTexture::draw_rect_region(RID p_canvas_item,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate, bool p_transpose) const{ + + if ((w|h)==0) + return; + VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item,p_rect,texture,p_src_rect,p_modulate,p_transpose); +} + +bool StreamTexture::has_alpha() const { + + return false; +} +void StreamTexture::set_flags(uint32_t p_flags){ + +} + +void StreamTexture::reload_from_file() { + +#ifdef TOOLS_ENABLED + String ipath = get_import_path(); + if (ipath.is_resource_file() && ipath!=path_to_file) { + path_to_file=ipath; + } +#endif + load(path_to_file); +} + +void StreamTexture::_bind_methods() { + + ClassDB::bind_method(_MD("load","path"),&StreamTexture::load); + ClassDB::bind_method(_MD("get_load_path"),&StreamTexture::get_load_path); + + ADD_PROPERTY( PropertyInfo(Variant::STRING,"load_path",PROPERTY_HINT_FILE,"*.stex"),_SCS("load"),_SCS("get_load_path")); +} + + +StreamTexture::StreamTexture() { + + format=Image::FORMAT_MAX; + flags=0; + w=0; + h=0; + + texture = VS::get_singleton()->texture_create(); +} + +StreamTexture::~StreamTexture() { + + VS::get_singleton()->free(texture); +} + + + +RES ResourceFormatLoaderStreamTexture::load(const String &p_path,const String& p_original_path,Error *r_error) { + + Ref<StreamTexture> st; + st.instance(); + Error err = st->load(p_path); + if (r_error) + *r_error=err; + if (err!=OK) + return RES(); + + return st; +} + +void ResourceFormatLoaderStreamTexture::get_recognized_extensions(List<String> *p_extensions) const{ + + p_extensions->push_back("stex"); +} +bool ResourceFormatLoaderStreamTexture::handles_type(const String& p_type) const{ + return p_type=="StreamTexture"; + +} +String ResourceFormatLoaderStreamTexture::get_resource_type(const String &p_path) const{ + + if (p_path.get_extension().to_lower()=="stex") + return "StreamTexture"; + return ""; +} + + + + ////////////////////////////////////////// diff --git a/scene/resources/texture.h b/scene/resources/texture.h index aac3514af3..f684aeb658 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -31,6 +31,7 @@ #include "resource.h" #include "servers/visual_server.h" +#include "io/resource_loader.h" #include "math_2d.h" /** @@ -160,6 +161,86 @@ public: }; + +class StreamTexture : public Texture { + + GDCLASS( StreamTexture, Texture ); +public: + enum DataFormat { + DATA_FORMAT_IMAGE, + DATA_FORMAT_LOSSLESS, + DATA_FORMAT_LOSSY + }; + + enum FormatBits { + FORMAT_MASK_IMAGE_FORMAT=(1<<20)-1, + FORMAT_BIT_LOSSLESS=1<<20, + FORMAT_BIT_LOSSY=1<<21, + FORMAT_BIT_STREAM=1<<22, + FORMAT_BIT_HAS_MIPMAPS=1<<23, + FORMAT_BIT_DETECT_3D=1<<24, + FORMAT_BIT_DETECT_SRGB=1<<25, + }; + +private: + + Error _load_data(const String &p_path, int &tw, int &th, int& flags, Image& image, int p_size_limit=0); + String path_to_file; + RID texture; + Image::Format format; + uint32_t flags; + int w,h; + + virtual void reload_from_file(); + + static void _requested_3d(void* p_ud); + static void _requested_srgb(void* p_ud); + +protected: + + static void _bind_methods(); + +public: + + + typedef void (*TextureFormatRequestCallback)(const Ref<StreamTexture>&); + + static TextureFormatRequestCallback request_3d_callback; + static TextureFormatRequestCallback request_srgb_callback; + + uint32_t get_flags() const; + Image::Format get_format() const; + Error load(const String& p_path); + String get_load_path() const; + + int get_width() const; + int get_height() const; + virtual RID get_rid() const; + + virtual void draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const; + virtual void draw_rect(RID p_canvas_item,const Rect2& p_rect, bool p_tile=false,const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const; + virtual void draw_rect_region(RID p_canvas_item,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const; + + virtual bool has_alpha() const; + virtual void set_flags(uint32_t p_flags); + + StreamTexture(); + ~StreamTexture(); + +}; + + +class ResourceFormatLoaderStreamTexture : public ResourceFormatLoader { +public: + virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual bool handles_type(const String& p_type) const; + virtual String get_resource_type(const String &p_path) const; + +}; + + + VARIANT_ENUM_CAST( ImageTexture::Storage ); class AtlasTexture : public Texture { |