diff --git a/core/io/pck_packer.cpp b/core/io/pck_packer.cpp index ed5c9a84f292..68e2f1050bf2 100644 --- a/core/io/pck_packer.cpp +++ b/core/io/pck_packer.cpp @@ -154,13 +154,11 @@ Error PCKPacker::flush(bool p_verbose) { src->close(); memdelete(src); count += 1; - if (p_verbose && files.size() > 0) { - if (count % 100 == 0) { - printf("%i/%i (%.2f)\r", count, files.size(), float(count) / files.size() * 100); - fflush(stdout); - }; - }; - }; + const int file_num = files.size(); + if (p_verbose && (file_num > 0)) { + print_line(vformat("[%d/%d - %d%%] PCKPacker flush: %s -> %s", count, file_num, float(count) / file_num * 100, files[i].src_path, files[i].path)); + } + } if (p_verbose) { printf("\n"); diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index fdb6ece905dd..c9e1211ea554 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -33,6 +33,20 @@ #include "core/os/os.h" #include "core/resource.h" +void UndoRedo::Operation::delete_reference() { + if (type != Operation::TYPE_REFERENCE) { + return; + } + if (ref.is_valid()) { + ref.unref(); + } else { + Object *obj = ObjectDB::get_instance(object); + if (obj) { + memdelete(obj); + } + } +} + void UndoRedo::_discard_redo() { if (current_action == actions.size() - 1) { return; @@ -40,16 +54,7 @@ void UndoRedo::_discard_redo() { for (int i = current_action + 1; i < actions.size(); i++) { for (List::Element *E = actions.write[i].do_ops.front(); E; E = E->next()) { - if (E->get().type == Operation::TYPE_REFERENCE) { - if (E->get().ref.is_valid()) { - E->get().ref.unref(); - } else { - Object *obj = ObjectDB::get_instance(E->get().object); - if (obj) { - memdelete(obj); - } - } - } + E->get().delete_reference(); } //ERASE do data } @@ -72,14 +77,7 @@ void UndoRedo::create_action(const String &p_name, MergeMode p_mode) { List::Element *E = actions.write[current_action + 1].do_ops.front(); while (E) { - if (E->get().type == Operation::TYPE_REFERENCE) { - Object *obj = ObjectDB::get_instance(E->get().object); - - if (obj) { - memdelete(obj); - } - } - + E->get().delete_reference(); E = E->next(); actions.write[current_action + 1].do_ops.pop_front(); } @@ -224,16 +222,7 @@ void UndoRedo::_pop_history_tail() { } for (List::Element *E = actions.write[0].undo_ops.front(); E; E = E->next()) { - if (E->get().type == Operation::TYPE_REFERENCE) { - if (E->get().ref.is_valid()) { - E->get().ref.unref(); - } else { - Object *obj = ObjectDB::get_instance(E->get().object); - if (obj) { - memdelete(obj); - } - } - } + E->get().delete_reference(); } actions.remove(0); diff --git a/core/undo_redo.h b/core/undo_redo.h index 517f12b4a689..ae9cab1f187e 100644 --- a/core/undo_redo.h +++ b/core/undo_redo.h @@ -64,6 +64,8 @@ class UndoRedo : public Object { ObjectID object; String name; Variant args[VARIANT_ARG_MAX]; + + void delete_reference(); }; struct Action { diff --git a/doc/classes/String.xml b/doc/classes/String.xml index 1e2dfacd4aac..a7d59fd32c77 100644 --- a/doc/classes/String.xml +++ b/doc/classes/String.xml @@ -188,7 +188,10 @@ - Returns the bigrams (pairs of consecutive letters) of this string. + Returns an array containing the bigrams (pairs of consecutive letters) of this string. + [codeblock] + print("Bigrams".bigrams()) # Prints "[Bi, ig, gr, ra, am, ms]" + [/codeblock] @@ -447,7 +450,14 @@ - Returns [code]true[/code] if this string contains a valid float. + Returns [code]true[/code] if this string contains a valid float. This is inclusive of integers, and also supports exponents: + [codeblock] + print("1.7".is_valid_float()) # Prints "true" + print("24".is_valid_float()) # Prints "true" + print("7e3".is_valid_float()) # Prints "true" + print("24".is_valid_float()) # Prints "true" + print("Hello".is_valid_float()) # Prints "false" + [/codeblock] @@ -467,12 +477,24 @@ Returns [code]true[/code] if this string is a valid identifier. A valid identifier may contain only letters, digits and underscores ([code]_[/code]) and the first character may not be a digit. + [codeblock] + print("good_ident_1".is_valid_identifier()) # Prints "true" + print("1st_bad_ident".is_valid_identifier()) # Prints "false" + print("bad_ident_#2".is_valid_identifier()) # Prints "false" + [/codeblock] Returns [code]true[/code] if this string contains a valid integer. + [codeblock] + print("7".is_valid_int()) # Prints "true" + print("14.6".is_valid_int()) # Prints "false" + print("L".is_valid_int()) # Prints "false" + print("+3".is_valid_int()) # Prints "true" + print("-12".is_valid_int()) # Prints "true" + [/codeblock] @@ -523,14 +545,14 @@ - Does a simple case-sensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]). + Does a simple case-sensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]). An empty string or empty expression always evaluates to [code]false[/code]. - Does a simple case-insensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]). + Does a simple case-insensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]). An empty string or empty expression always evaluates to [code]false[/code]. @@ -707,7 +729,13 @@ - Returns the similarity index of the text compared to this string. 1 means totally similar and 0 means totally dissimilar. + Returns the similarity index ([url=https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient]Sorensen-Dice coefficient[/url]) this string compared to another. 1.0 means totally similar and 0.0 means totally dissimilar. + [codeblock] + print("ABC123".similarity("ABC123")) # Prints "1" + print("ABC123".similarity("XYZ456")) # Prints "0" + print("ABC123".similarity("123ABC")) # Prints "0.8" + print("ABC123".similarity("abc123")) # Prints "0.4" + [/codeblock] diff --git a/platform/iphone/godot_view.mm b/platform/iphone/godot_view.mm index dc6623cb5316..5cf914176d07 100644 --- a/platform/iphone/godot_view.mm +++ b/platform/iphone/godot_view.mm @@ -145,6 +145,8 @@ - (void)godot_commonInit { [self initTouches]; + self.multipleTouchEnabled = YES; + // Configure and start accelerometer if (!self.motionManager) { self.motionManager = [[CMMotionManager alloc] init]; diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index 2fb70038bfaa..f18265ba8d94 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -364,14 +364,14 @@ void AnimatedSprite::_notification(int p_what) { return; } - float speed = frames->get_animation_speed(animation) * speed_scale; - if (speed == 0) { - return; //do nothing - } - float remaining = get_process_delta_time(); while (remaining) { + float speed = frames->get_animation_speed(animation) * speed_scale; + if (speed == 0) { + return; //do nothing + } + if (timeout <= 0) { timeout = _get_frame_duration(); diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index f0fbcfd332b3..5633f9c4cd6f 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -980,14 +980,14 @@ void AnimatedSprite3D::_notification(int p_what) { return; } - float speed = frames->get_animation_speed(animation); - if (speed == 0) { - return; //do nothing - } - float remaining = get_process_delta_time(); while (remaining) { + float speed = frames->get_animation_speed(animation); + if (speed == 0) { + return; // Do nothing. + } + if (timeout <= 0) { timeout = 1.0 / speed; diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index c14b8eb48ff9..50a4b3135dfa 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -414,7 +414,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & cw = tab_size * font->get_char_size(' ').width; } - if (end > 0 && w + cw + begin > p_width) { + if (end > 0 && fw + cw + begin > p_width) { break; //don't allow lines longer than assigned width } @@ -437,13 +437,12 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & was_separatable = separatable; just_breaked_in_middle = false; - w += cw; fw += cw; end++; } CHECK_HEIGHT(fh); - ENSURE_WIDTH(w); + ENSURE_WIDTH(fw); line_ascent = MAX(line_ascent, ascent); line_descent = MAX(line_descent, descent); @@ -579,6 +578,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & if (visible) { line_is_blank = false; + w += font->get_char_size(c[i], c[i + 1]).x; } if (c[i] == '\t') { diff --git a/servers/audio/effects/audio_effect_pitch_shift.cpp b/servers/audio/effects/audio_effect_pitch_shift.cpp index 6e9f92c55132..f97d8ef22efb 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.cpp +++ b/servers/audio/effects/audio_effect_pitch_shift.cpp @@ -74,7 +74,7 @@ * *****************************************************************************/ -void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int64_t fftFrameSize, int64_t osamp, float sampleRate, float *indata, float *outdata,int stride) { +void SMBPitchShift::PitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata,int stride) { /* @@ -85,32 +85,19 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6 */ double magn, phase, tmp, window, real, imag; - double freqPerBin, expct, reciprocalFftFrameSize; - int64_t i,k, qpd, index, inFifoLatency, stepSize, fftFrameSize2; + double freqPerBin, expct; + long i,k, qpd, index, inFifoLatency, stepSize, fftFrameSize2; /* set up some handy variables */ fftFrameSize2 = fftFrameSize/2; - reciprocalFftFrameSize = 1./fftFrameSize; stepSize = fftFrameSize/osamp; - freqPerBin = reciprocalFftFrameSize * sampleRate; - expct = Math_TAU * reciprocalFftFrameSize * stepSize; + freqPerBin = sampleRate/(double)fftFrameSize; + expct = 2.*Math_PI*(double)stepSize/(double)fftFrameSize; inFifoLatency = fftFrameSize-stepSize; - if (gRover == 0) { - gRover = inFifoLatency; - } + if (gRover == 0) { gRover = inFifoLatency; +} - // If pitchShift changes clear arrays to prevent some artifacts and quality loss. - if (lastPitchShift != pitchShift) { - lastPitchShift = pitchShift; - memset(gInFIFO, 0, MAX_FRAME_LENGTH * sizeof(float)); - memset(gOutFIFO, 0, MAX_FRAME_LENGTH * sizeof(float)); - memset(gFFTworksp, 0, 2 * MAX_FRAME_LENGTH * sizeof(double)); - memset(gLastPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(double)); - memset(gSumPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(double)); - memset(gOutputAccum, 0, 2 * MAX_FRAME_LENGTH * sizeof(double)); - memset(gAnaFreq, 0, MAX_FRAME_LENGTH * sizeof(double)); - memset(gAnaMagn, 0, MAX_FRAME_LENGTH * sizeof(double)); - } + /* initialize our static arrays */ /* main processing loop */ for (i = 0; i < numSampsToProcess; i++){ @@ -126,7 +113,7 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6 /* do windowing and re,im interleave */ for (k = 0; k < fftFrameSize;k++) { - window = -.5*cos(Math_TAU * reciprocalFftFrameSize * k)+.5; + window = -.5*cos(2.*Math_PI*(double)k/(double)fftFrameSize)+.5; gFFTworksp[2*k] = gInFIFO[k] * window; gFFTworksp[2*k+1] = 0.; } @@ -138,7 +125,6 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6 /* this is the analysis step */ for (k = 0; k <= fftFrameSize2; k++) { - /* de-interlace FFT buffer */ real = gFFTworksp[2*k]; imag = gFFTworksp[2*k+1]; @@ -156,15 +142,13 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6 /* map delta phase into +/- Pi interval */ qpd = tmp/Math_PI; - if (qpd >= 0) { - qpd += qpd&1; - } else { - qpd -= qpd&1; - } + if (qpd >= 0) { qpd += qpd&1; + } else { qpd -= qpd&1; +} tmp -= Math_PI*(double)qpd; /* get deviation from bin frequency from the +/- Pi interval */ - tmp = osamp*tmp/Math_TAU; + tmp = osamp*tmp/(2.*Math_PI); /* compute the k-th partials' true frequency */ tmp = (double)k*freqPerBin + tmp*freqPerBin; @@ -177,8 +161,8 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6 /* ***************** PROCESSING ******************* */ /* this does the actual pitch shifting */ - memset(gSynMagn, 0, fftFrameSize*sizeof(double)); - memset(gSynFreq, 0, fftFrameSize*sizeof(double)); + memset(gSynMagn, 0, fftFrameSize*sizeof(float)); + memset(gSynFreq, 0, fftFrameSize*sizeof(float)); for (k = 0; k <= fftFrameSize2; k++) { index = k*pitchShift; if (index <= fftFrameSize2) { @@ -202,7 +186,7 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6 tmp /= freqPerBin; /* take osamp into account */ - tmp = Math_TAU*tmp/osamp; + tmp = 2.*Math_PI*tmp/osamp; /* add the overlap phase advance back in */ tmp += (double)k*expct; @@ -217,35 +201,33 @@ void SMBPitchShift::PitchShift(float pitchShift, int64_t numSampsToProcess, int6 } /* zero negative frequencies */ - for (k = fftFrameSize+2; k < 2*MAX_FRAME_LENGTH; k++) { - gFFTworksp[k] = 0.; - } + for (k = fftFrameSize+2; k < 2*fftFrameSize; k++) { gFFTworksp[k] = 0.; +} /* do inverse transform */ smbFft(gFFTworksp, fftFrameSize, 1); /* do windowing and add to output accumulator */ for(k=0; k < fftFrameSize; k++) { - window = -.5*cos(Math_TAU * reciprocalFftFrameSize * k)+.5; + window = -.5*cos(2.*Math_PI*(double)k/(double)fftFrameSize)+.5; gOutputAccum[k] += 2.*window*gFFTworksp[2*k]/(fftFrameSize2*osamp); } - for (k = 0; k < stepSize; k++) { - gOutFIFO[k] = gOutputAccum[k]; - } + for (k = 0; k < stepSize; k++) { gOutFIFO[k] = gOutputAccum[k]; +} /* shift accumulator */ - memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(double)); + memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(float)); /* move input FIFO */ - for (k = 0; k < inFifoLatency; k++) { - gInFIFO[k] = gInFIFO[k+stepSize]; - } + for (k = 0; k < inFifoLatency; k++) { gInFIFO[k] = gInFIFO[k+stepSize]; +} } } } -void SMBPitchShift::smbFft(double *fftBuffer, int64_t fftFrameSize, int64_t sign) + +void SMBPitchShift::smbFft(float *fftBuffer, long fftFrameSize, long sign) /* FFT routine, (C)1996 S.M.Bernsee. Sign = -1 is FFT, 1 is iFFT (inverse) Fills fftBuffer[0...2*fftFrameSize-1] with the Fourier transform of the @@ -258,16 +240,14 @@ void SMBPitchShift::smbFft(double *fftBuffer, int64_t fftFrameSize, int64_t sign of the frequencies of interest is in fftBuffer[0...fftFrameSize]. */ { - double wr, wi, arg, *p1, *p2, temp; - double tr, ti, ur, ui, *p1r, *p1i, *p2r, *p2i; - int64_t i, bitm, j, le, le2, k, logN; - logN = (int64_t)(log(fftFrameSize) / log(2.) + .5); + float wr, wi, arg, *p1, *p2, temp; + float tr, ti, ur, ui, *p1r, *p1i, *p2r, *p2i; + long i, bitm, j, le, le2, k; for (i = 2; i < 2*fftFrameSize-2; i += 2) { for (bitm = 2, j = 0; bitm < 2*fftFrameSize; bitm <<= 1) { - if (i & bitm) { - j++; - } + if (i & bitm) { j++; +} j <<= 1; } if (i < j) { @@ -277,8 +257,7 @@ void SMBPitchShift::smbFft(double *fftBuffer, int64_t fftFrameSize, int64_t sign *p1 = *p2; *p2 = temp; } } - - for (k = 0, le = 2; k < logN; k++) { + for (k = 0, le = 2; k < (long)(log((double)fftFrameSize)/log(2.)+.5); k++) { le <<= 1; le2 = le>>1; ur = 1.0; @@ -310,14 +289,6 @@ void SMBPitchShift::smbFft(double *fftBuffer, int64_t fftFrameSize, int64_t sign void AudioEffectPitchShiftInstance::process(const AudioFrame *p_src_frames, AudioFrame *p_dst_frames, int p_frame_count) { float sample_rate = AudioServer::get_singleton()->get_mix_rate(); - // For pitch_scale 1.0 it's cheaper to just pass samples without processing them. - if (Math::is_equal_approx(base->pitch_scale, 1.0f)) { - for (int i = 0; i < p_frame_count; i++) { - p_dst_frames[i] = p_src_frames[i]; - } - return; - } - float *in_l = (float *)p_src_frames; float *in_r = in_l + 1; @@ -391,4 +362,7 @@ AudioEffectPitchShift::AudioEffectPitchShift() { pitch_scale = 1.0; oversampling = 4; fft_size = FFT_SIZE_2048; + wet = 0.0; + dry = 0.0; + filter = false; } diff --git a/servers/audio/effects/audio_effect_pitch_shift.h b/servers/audio/effects/audio_effect_pitch_shift.h index 97207a30fe06..6559752e8a70 100644 --- a/servers/audio/effects/audio_effect_pitch_shift.h +++ b/servers/audio/effects/audio_effect_pitch_shift.h @@ -40,33 +40,31 @@ class SMBPitchShift { float gInFIFO[MAX_FRAME_LENGTH]; float gOutFIFO[MAX_FRAME_LENGTH]; - double gFFTworksp[2 * MAX_FRAME_LENGTH]; - double gLastPhase[MAX_FRAME_LENGTH / 2 + 1]; - double gSumPhase[MAX_FRAME_LENGTH / 2 + 1]; - double gOutputAccum[2 * MAX_FRAME_LENGTH]; - double gAnaFreq[MAX_FRAME_LENGTH]; - double gAnaMagn[MAX_FRAME_LENGTH]; - double gSynFreq[MAX_FRAME_LENGTH]; - double gSynMagn[MAX_FRAME_LENGTH]; - int64_t gRover; - float lastPitchShift; - - void smbFft(double *fftBuffer, int64_t fftFrameSize, int64_t sign); + float gFFTworksp[2 * MAX_FRAME_LENGTH]; + float gLastPhase[MAX_FRAME_LENGTH / 2 + 1]; + float gSumPhase[MAX_FRAME_LENGTH / 2 + 1]; + float gOutputAccum[2 * MAX_FRAME_LENGTH]; + float gAnaFreq[MAX_FRAME_LENGTH]; + float gAnaMagn[MAX_FRAME_LENGTH]; + float gSynFreq[MAX_FRAME_LENGTH]; + float gSynMagn[MAX_FRAME_LENGTH]; + long gRover; + + void smbFft(float *fftBuffer, long fftFrameSize, long sign); public: - void PitchShift(float pitchShift, int64_t numSampsToProcess, int64_t fftFrameSize, int64_t osamp, float sampleRate, float *indata, float *outdata, int stride); + void PitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata, int stride); SMBPitchShift() { gRover = 0; memset(gInFIFO, 0, MAX_FRAME_LENGTH * sizeof(float)); memset(gOutFIFO, 0, MAX_FRAME_LENGTH * sizeof(float)); - memset(gFFTworksp, 0, 2 * MAX_FRAME_LENGTH * sizeof(double)); - memset(gLastPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(double)); - memset(gSumPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(double)); - memset(gOutputAccum, 0, 2 * MAX_FRAME_LENGTH * sizeof(double)); - memset(gAnaFreq, 0, MAX_FRAME_LENGTH * sizeof(double)); - memset(gAnaMagn, 0, MAX_FRAME_LENGTH * sizeof(double)); - lastPitchShift = 1.0; + memset(gFFTworksp, 0, 2 * MAX_FRAME_LENGTH * sizeof(float)); + memset(gLastPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(float)); + memset(gSumPhase, 0, (MAX_FRAME_LENGTH / 2 + 1) * sizeof(float)); + memset(gOutputAccum, 0, 2 * MAX_FRAME_LENGTH * sizeof(float)); + memset(gAnaFreq, 0, MAX_FRAME_LENGTH * sizeof(float)); + memset(gAnaMagn, 0, MAX_FRAME_LENGTH * sizeof(float)); } }; @@ -103,6 +101,9 @@ class AudioEffectPitchShift : public AudioEffect { float pitch_scale; int oversampling; FFT_Size fft_size; + float wet; + float dry; + bool filter; protected: static void _bind_methods(); diff --git a/thirdparty/README.md b/thirdparty/README.md index fbd597c1e295..0d7c55c6e62a 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -364,8 +364,8 @@ Collection of single-file libraries used in Godot components. * Modifications: use `const char*` instead of `char*` for input string - `stb_rect_pack.h` * Upstream: https://github.com/nothings/stb - * Version: 1.00 - * License: Public Domain (Unlicense) or MIT + * Version: 1.01 (af1a5bc352164740c1cc1354942b1c6b72eacb8a, 2021) + * License: Public Domain or Unlicense or MIT - `stb_vorbis.c` * Upstream: https://github.com/nothings/stb * Version: 1.20 (314d0a6f9af5af27e585336eecea333e95c5a2d8, 2020) diff --git a/thirdparty/stb_rect_pack/stb_rect_pack.h b/thirdparty/stb_rect_pack/stb_rect_pack.h index 3336fe7395bb..4713661a44a7 100644 --- a/thirdparty/stb_rect_pack/stb_rect_pack.h +++ b/thirdparty/stb_rect_pack/stb_rect_pack.h @@ -1,9 +1,15 @@ -// stb_rect_pack.h - v1.00 - public domain - rectangle packing +// stb_rect_pack.h - v1.01 - public domain - rectangle packing // Sean Barrett 2014 // // Useful for e.g. packing rectangular textures into an atlas. // Does not do rotation. // +// Before #including, +// +// #define STB_RECT_PACK_IMPLEMENTATION +// +// in the file that you want to have the implementation. +// // Not necessarily the awesomest packing method, but better than // the totally naive one in stb_truetype (which is primarily what // this is meant to replace). @@ -35,6 +41,7 @@ // // Version history: // +// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section // 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles // 0.99 (2019-02-07) warning fixes // 0.11 (2017-03-03) return packing success/fail result @@ -75,11 +82,10 @@ typedef struct stbrp_context stbrp_context; typedef struct stbrp_node stbrp_node; typedef struct stbrp_rect stbrp_rect; -#ifdef STBRP_LARGE_RECTS typedef int stbrp_coord; -#else -typedef unsigned short stbrp_coord; -#endif + +#define STBRP__MAXVAL 0x7fffffff +// Mostly for internal use, but this is the maximum supported coordinate value. STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects); // Assign packed locations to rectangles. The rectangles are of type @@ -209,8 +215,10 @@ struct stbrp_context #ifdef _MSC_VER #define STBRP__NOTUSED(v) (void)(v) +#define STBRP__CDECL __cdecl #else #define STBRP__NOTUSED(v) (void)sizeof(v) +#define STBRP__CDECL #endif enum @@ -253,9 +261,6 @@ STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_ou STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes) { int i; -#ifndef STBRP_LARGE_RECTS - STBRP_ASSERT(width <= 0xffff && height <= 0xffff); -#endif for (i=0; i < num_nodes-1; ++i) nodes[i].next = &nodes[i+1]; @@ -274,11 +279,7 @@ STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, context->extra[0].y = 0; context->extra[0].next = &context->extra[1]; context->extra[1].x = (stbrp_coord) width; -#ifdef STBRP_LARGE_RECTS context->extra[1].y = (1<<30); -#else - context->extra[1].y = 65535; -#endif context->extra[1].next = NULL; } @@ -520,7 +521,7 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i return res; } -static int rect_height_compare(const void *a, const void *b) +static int STBRP__CDECL rect_height_compare(const void *a, const void *b) { const stbrp_rect *p = (const stbrp_rect *) a; const stbrp_rect *q = (const stbrp_rect *) b; @@ -531,19 +532,13 @@ static int rect_height_compare(const void *a, const void *b) return (p->w > q->w) ? -1 : (p->w < q->w); } -static int rect_original_order(const void *a, const void *b) +static int STBRP__CDECL rect_original_order(const void *a, const void *b) { const stbrp_rect *p = (const stbrp_rect *) a; const stbrp_rect *q = (const stbrp_rect *) b; return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); } -#ifdef STBRP_LARGE_RECTS -#define STBRP__MAXVAL 0xffffffff -#else -#define STBRP__MAXVAL 0xffff -#endif - STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects) { int i, all_rects_packed = 1;