From 5834e970ebb50edc95cb5b5dbc6dd772f99c366f Mon Sep 17 00:00:00 2001 From: Kenta <106167071+Its-Kenta@users.noreply.github.com> Date: Tue, 27 Jun 2023 21:03:42 +0100 Subject: [PATCH 01/40] Update BINDINGS.md (#3138) Change C3 to Zlib Update Raylib-nelua's name as Raylib.nelua to reflect repo change. Update Raylib.nelua licence to Zlib --- BINDINGS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BINDINGS.md b/BINDINGS.md index 272bc2da5..f040599ca 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -15,7 +15,7 @@ Some people ported raylib to other languages in form of bindings or wrappers to | chez-raylib | **auto** | [Chez Scheme](https://cisco.github.io/ChezScheme/) | GPLv3 | https://github.com/Yunoinsky/chez-raylib | | raylib-cr | **4.6-dev (5e1a81)** | [Crystal](https://crystal-lang.org/) | Apache-2.0 | https://github.com/sol-vin/raylib-cr | | ray-cyber | 4.5 | [Cyber](https://cyberscript.dev) | MIT | https://github.com/fubark/ray-cyber | -| raylib-c3 | **4.5** | [C3](https://c3-lang.org/) | MIT | https://github.com/Its-Kenta/Raylib-C3 | +| raylib-c3 | **4.5** | [C3](https://c3-lang.org/) | Zlib | https://github.com/Its-Kenta/Raylib-C3 | | dart-raylib | 4.0 | [Dart](https://dart.dev/) | MIT | https://gitlab.com/wolfenrain/dart-raylib | | bindbc-raylib3 | 4.0 | [D](https://dlang.org/) | BSL-1.0 | https://github.com/o3o/bindbc-raylib3 | | dray | 4.2 | [D](https://dlang.org/) | Apache-2.0 | https://github.com/redthing1/dray | @@ -40,7 +40,7 @@ Some people ported raylib to other languages in form of bindings or wrappers to | raylib-lua | **4.5** | [Lua](http://www.lua.org/) | ISC | https://github.com/TSnake41/raylib-lua | | raylua | 4.0 | [Lua](http://www.lua.org/) | MIT | https://github.com/Rabios/raylua | | nelua-raylib | 4.0 | [nelua](https://nelua.io/) | MIT | https://github.com/AKDev21/nelua-raylib | -| Raylib-Nelua | **4.5-dev** | [nelua](https://nelua.io/) | MIT | https://github.com/Its-Kenta/Raylib-Nelua | +| Raylib.nelua | **4.5** | [nelua](https://nelua.io/) | Zlib | https://github.com/Its-Kenta/Raylib-Nelua | | NimraylibNow! | 4.2 | [Nim](https://nim-lang.org/) | MIT | https://github.com/greenfork/nimraylib_now | | raylib-Forever | auto | [Nim](https://nim-lang.org/) | ? | https://github.com/Guevara-chan/Raylib-Forever | | naylib | auto | [Nim](https://nim-lang.org/) | MIT | https://github.com/planetis-m/naylib | From ceafbcf9d2d722886c40d0ba12eaad2f232a2782 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 28 Jun 2023 00:37:24 +0200 Subject: [PATCH 02/40] REVIEWED: `SetShapesTexture()`, allow reseting --- src/rshapes.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/rshapes.c b/src/rshapes.c index 278886423..d726ff0e8 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -80,7 +80,7 @@ //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- -Texture2D texShapes = { 1, 1, 1, 1, 7 }; // Texture used on shapes drawing (usually a white pixel) +Texture2D texShapes = { 1, 1, 1, 1, 7 }; // Texture used on shapes drawing (white pixel loaded by rlgl) Rectangle texShapesRec = { 0.0f, 0.0f, 1.0f, 1.0f }; // Texture source rectangle used on shapes drawing //---------------------------------------------------------------------------------- @@ -97,8 +97,19 @@ static float EaseCubicInOut(float t, float b, float c, float d); // Cubic eas // defining a font char white rectangle would allow drawing everything in a single draw call void SetShapesTexture(Texture2D texture, Rectangle source) { - texShapes = texture; - texShapesRec = source; + // Reset texture to default pixel if required + // WARNING: Shapes texture should be probably better validated, + // it can break the rendering of all shapes if missused + if ((texture.id == 0) || (source.width == 0) || (source.height == 0)) + { + texShapes = (Texture2D){ 1, 1, 1, 1, 7 }; + texShapesRec = (Rectangle){ 0.0f, 0.0f, 1.0f, 1.0f }; + } + else + { + texShapes = texture; + texShapesRec = source; + } } // Draw a pixel From e190b7eee9199b681a8c50fb69f2fce07e92c7af Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 30 Jun 2023 09:47:16 +0200 Subject: [PATCH 03/40] UPDATED: `sdefl` and `sinfl` compression libraries --- src/external/sdefl.h | 195 ++++++++++++++++++++++++++++++------------- src/external/sinfl.h | 28 ++++--- 2 files changed, 155 insertions(+), 68 deletions(-) diff --git a/src/external/sdefl.h b/src/external/sdefl.h index 56539a56e..36015b95b 100644 --- a/src/external/sdefl.h +++ b/src/external/sdefl.h @@ -71,7 +71,7 @@ Results on the [Silesia compression corpus](http://sun.aei.polsl.pl/~sdeor/index This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------ ALTERNATIVE A - MIT License -Copyright (c) 2020 Micha Mettke +Copyright (c) 2020-2023 Micha Mettke 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 @@ -125,7 +125,7 @@ extern "C" { #define SDEFL_MIN_MATCH 4 #define SDEFL_BLK_MAX (256*1024) -#define SDEFL_SEQ_SIZ ((SDEFL_BLK_MAX + SDEFL_MIN_MATCH)/SDEFL_MIN_MATCH) +#define SDEFL_SEQ_SIZ ((SDEFL_BLK_MAX+2)/3) #define SDEFL_SYM_MAX (288) #define SDEFL_OFF_MAX (32) @@ -185,6 +185,7 @@ extern int zsdeflate(struct sdefl *s, void *o, const void *i, int n, int lvl); #define SDEFL_MAX_CODE_LEN (15) #define SDEFL_SYM_BITS (10u) #define SDEFL_SYM_MSK ((1u << SDEFL_SYM_BITS)-1u) +#define SDEFL_RAW_BLK_SIZE (65535) #define SDEFL_LIT_LEN_CODES (14) #define SDEFL_OFF_CODES (15) #define SDEFL_PRE_CODES (7) @@ -192,6 +193,7 @@ extern int zsdeflate(struct sdefl *s, void *o, const void *i, int n, int lvl); #define SDEFL_EOB (256) #define sdefl_npow2(n) (1 << (sdefl_ilog2((n)-1) + 1)) +#define sdefl_div_round_up(n,d) (((n)+((d)-1))/(d)) static int sdefl_ilog2(int n) { @@ -438,12 +440,12 @@ sdefl_precode(struct sdefl_symcnt *cnt, unsigned *freqs, unsigned *items, } while (run_start != total); cnt->items = (int)(at - items); } -struct sdefl_match_codes { +struct sdefl_match_codest { int ls, lc; int dc, dx; }; static void -sdefl_match_codes(struct sdefl_match_codes *cod, int dist, int len) { +sdefl_match_codes(struct sdefl_match_codest *cod, int dist, int len) { static const short dxmax[] = {0,6,12,24,48,96,192,384,768,1536,3072,6144,12288,24576}; static const unsigned char lslot[258+1] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, @@ -471,6 +473,44 @@ sdefl_match_codes(struct sdefl_match_codes *cod, int dist, int len) { cod->dx = sdefl_ilog2(sdefl_npow2(dist) >> 2); cod->dc = cod->dx ? ((cod->dx + 1) << 1) + (dist > dxmax[cod->dx]) : dist-1; } +enum sdefl_blk_type { + SDEFL_BLK_UCOMPR, + SDEFL_BLK_DYN +}; +static enum sdefl_blk_type +sdefl_blk_type(const struct sdefl *s, int blk_len, int pre_item_len, + const unsigned *pre_freq, const unsigned char *pre_len) { + static const unsigned char x_pre_bits[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; + static const unsigned char x_len_bits[] = {0,0,0,0,0,0,0,0, 1,1,1,1,2,2,2,2, + 3,3,3,3,4,4,4,4, 5,5,5,5,0}; + static const unsigned char x_off_bits[] = {0,0,0,0,1,1,2,2, 3,3,4,4,5,5,6,6, + 7,7,8,8,9,9,10,10, 11,11,12,12,13,13}; + + int dyn_cost = 0; + int fix_cost = 0; + int sym = 0; + + dyn_cost += 5 + 5 + 4 + (3 * pre_item_len); + for (sym = 0; sym < SDEFL_PRE_MAX; sym++) + dyn_cost += pre_freq[sym] * (x_pre_bits[sym] + pre_len[sym]); + for (sym = 0; sym < 256; sym++) + dyn_cost += s->freq.lit[sym] * s->cod.len.lit[sym]; + dyn_cost += s->cod.len.lit[SDEFL_EOB]; + for (sym = 257; sym < 286; sym++) + dyn_cost += s->freq.lit[sym] * (x_len_bits[sym - 257] + s->cod.len.lit[sym]); + for (sym = 0; sym < 30; sym++) + dyn_cost += s->freq.off[sym] * (x_off_bits[sym] + s->cod.len.off[sym]); + + fix_cost += 8*(5 * sdefl_div_round_up(blk_len, SDEFL_RAW_BLK_SIZE) + blk_len + 1 + 2); + return (dyn_cost < fix_cost) ? SDEFL_BLK_DYN : SDEFL_BLK_UCOMPR; +} +static void +sdefl_put16(unsigned char **dst, unsigned short x) { + unsigned char *val = *dst; + val[0] = (unsigned char)(x & 0xff); + val[1] = (unsigned char)(x >> 8); + *dst = val + 2; +} static void sdefl_match(unsigned char **dst, struct sdefl *s, int dist, int len) { static const char lxn[] = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; @@ -479,7 +519,7 @@ sdefl_match(unsigned char **dst, struct sdefl *s, int dist, int len) { static const short dmin[] = {1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257, 385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577}; - struct sdefl_match_codes cod; + struct sdefl_match_codest cod; sdefl_match_codes(&cod, dist, len); sdefl_put(dst, s, (int)s->cod.word.lit[cod.lc], s->cod.len.lit[cod.lc]); sdefl_put(dst, s, len - lmin[cod.ls], lxn[cod.ls]); @@ -488,7 +528,8 @@ sdefl_match(unsigned char **dst, struct sdefl *s, int dist, int len) { } static void sdefl_flush(unsigned char **dst, struct sdefl *s, int is_last, - const unsigned char *in) { + const unsigned char *in, int blk_begin, int blk_end) { + int blk_len = blk_end - blk_begin; int j, i = 0, item_cnt = 0; struct sdefl_symcnt symcnt = {0}; unsigned codes[SDEFL_PRE_MAX]; @@ -498,7 +539,7 @@ sdefl_flush(unsigned char **dst, struct sdefl *s, int is_last, static const unsigned char perm[SDEFL_PRE_MAX] = {16,17,18,0,8,7,9,6,10,5,11, 4,12,3,13,2,14,1,15}; - /* huffman codes */ + /* calculate huffman codes */ s->freq.lit[SDEFL_EOB]++; sdefl_huff(s->cod.len.lit, s->cod.word.lit, s->freq.lit, SDEFL_SYM_MAX, SDEFL_LIT_LEN_CODES); sdefl_huff(s->cod.len.off, s->cod.word.off, s->freq.off, SDEFL_OFF_MAX, SDEFL_OFF_CODES); @@ -509,35 +550,58 @@ sdefl_flush(unsigned char **dst, struct sdefl *s, int is_last, break; } } - /* block header */ - sdefl_put(dst, s, is_last ? 0x01 : 0x00, 1); /* block */ - sdefl_put(dst, s, 0x02, 2); /* dynamic huffman */ - sdefl_put(dst, s, symcnt.lit - 257, 5); - sdefl_put(dst, s, symcnt.off - 1, 5); - sdefl_put(dst, s, item_cnt - 4, 4); - for (i = 0; i < item_cnt; ++i) { - sdefl_put(dst, s, lens[perm[i]], 3); - } - for (i = 0; i < symcnt.items; ++i) { - unsigned sym = items[i] & 0x1F; - sdefl_put(dst, s, (int)codes[sym], lens[sym]); - if (sym < 16) continue; - if (sym == 16) sdefl_put(dst, s, items[i] >> 5, 2); - else if(sym == 17) sdefl_put(dst, s, items[i] >> 5, 3); - else sdefl_put(dst, s, items[i] >> 5, 7); - } - /* block sequences */ - for (i = 0; i < s->seq_cnt; ++i) { - if (s->seq[i].off >= 0) { - for (j = 0; j < s->seq[i].len; ++j) { - int c = in[s->seq[i].off + j]; - sdefl_put(dst, s, (int)s->cod.word.lit[c], s->cod.len.lit[c]); + /* write block */ + switch (sdefl_blk_type(s, blk_len, item_cnt, freqs, lens)) { + case SDEFL_BLK_UCOMPR: { + /* uncompressed blocks */ + int n = sdefl_div_round_up(blk_len, SDEFL_RAW_BLK_SIZE); + for (i = 0; i < n; ++i) { + int fin = is_last && (i + 1 == n); + int amount = blk_len < SDEFL_RAW_BLK_SIZE ? blk_len : SDEFL_RAW_BLK_SIZE; + sdefl_put(dst, s, !!fin, 1); /* block */ + sdefl_put(dst, s, 0x00, 2); /* stored block */ + if (s->bitcnt) { + sdefl_put(dst, s, 0x00, 8 - s->bitcnt); } - } else { - sdefl_match(dst, s, -s->seq[i].off, s->seq[i].len); + assert(s->bitcnt == 0); + sdefl_put16(dst, (unsigned short)amount); + sdefl_put16(dst, ~(unsigned short)amount); + memcpy(*dst, in + blk_begin + i * SDEFL_RAW_BLK_SIZE, amount); + *dst = *dst + amount; + blk_len -= amount; } - } - sdefl_put(dst, s, (int)(s)->cod.word.lit[SDEFL_EOB], (s)->cod.len.lit[SDEFL_EOB]); + } break; + case SDEFL_BLK_DYN: { + /* dynamic huffman block */ + sdefl_put(dst, s, !!is_last, 1); /* block */ + sdefl_put(dst, s, 0x02, 2); /* dynamic huffman */ + sdefl_put(dst, s, symcnt.lit - 257, 5); + sdefl_put(dst, s, symcnt.off - 1, 5); + sdefl_put(dst, s, item_cnt - 4, 4); + for (i = 0; i < item_cnt; ++i) { + sdefl_put(dst, s, lens[perm[i]], 3); + } + for (i = 0; i < symcnt.items; ++i) { + unsigned sym = items[i] & 0x1F; + sdefl_put(dst, s, (int)codes[sym], lens[sym]); + if (sym < 16) continue; + if (sym == 16) sdefl_put(dst, s, items[i] >> 5, 2); + else if(sym == 17) sdefl_put(dst, s, items[i] >> 5, 3); + else sdefl_put(dst, s, items[i] >> 5, 7); + } + /* block sequences */ + for (i = 0; i < s->seq_cnt; ++i) { + if (s->seq[i].off >= 0) { + for (j = 0; j < s->seq[i].len; ++j) { + int c = in[s->seq[i].off + j]; + sdefl_put(dst, s, (int)s->cod.word.lit[c], s->cod.len.lit[c]); + } + } else { + sdefl_match(dst, s, -s->seq[i].off, s->seq[i].len); + } + } + sdefl_put(dst, s, (int)(s)->cod.word.lit[SDEFL_EOB], (s)->cod.len.lit[SDEFL_EOB]); + } break;} memset(&s->freq, 0, sizeof(s->freq)); s->seq_cnt = 0; } @@ -550,8 +614,12 @@ sdefl_seq(struct sdefl *s, int off, int len) { } static void sdefl_reg_match(struct sdefl *s, int off, int len) { - struct sdefl_match_codes cod; + struct sdefl_match_codest cod; sdefl_match_codes(&cod, off, len); + + assert(cod.lc < SDEFL_SYM_MAX); + assert(cod.dc < SDEFL_OFF_MAX); + s->freq.lit[cod.lc]++; s->freq.off[cod.dc]++; } @@ -560,22 +628,35 @@ struct sdefl_match { int len; }; static void -sdefl_fnd(struct sdefl_match *m, const struct sdefl *s, - int chain_len, int max_match, const unsigned char *in, int p) { - int i = s->tbl[sdefl_hash32(&in[p])]; - int limit = ((p-SDEFL_WIN_SIZ)tbl[sdefl_hash32(in + p)]; + int limit = ((p - SDEFL_WIN_SIZ) < SDEFL_NIL) ? SDEFL_NIL : (p-SDEFL_WIN_SIZ); + + assert(p < e); + assert(p + max_match <= e); while (i > limit) { - if (in[i+m->len] == in[p+m->len] && - (sdefl_uload32(&in[i]) == sdefl_uload32(&in[p]))){ + assert(i + m->len < e); + assert(p + m->len < e); + assert(i + SDEFL_MIN_MATCH < e); + assert(p + SDEFL_MIN_MATCH < e); + + if (in[i + m->len] == in[p + m->len] && + (sdefl_uload32(&in[i]) == sdefl_uload32(&in[p]))) { int n = SDEFL_MIN_MATCH; - while (n < max_match && in[i+n] == in[p+n]) n++; + while (n < max_match && in[i + n] == in[p + n]) { + assert(i + n < e); + assert(p + n < e); + n++; + } if (n > m->len) { m->len = n, m->off = p - i; - if (n == max_match) break; + if (n == max_match) + break; } } if (!(--chain_len)) break; - i = s->prv[i&SDEFL_WIN_MSK]; + i = s->prv[i & SDEFL_WIN_MSK]; } } static int @@ -588,19 +669,20 @@ sdefl_compr(struct sdefl *s, unsigned char *out, const unsigned char *in, for (n = 0; n < SDEFL_HASH_SIZ; ++n) { s->tbl[n] = SDEFL_NIL; } - do {int blk_end = ((i + SDEFL_BLK_MAX) < in_len) ? (i + SDEFL_BLK_MAX) : in_len; + do {int blk_begin = i; + int blk_end = ((i + SDEFL_BLK_MAX) < in_len) ? (i + SDEFL_BLK_MAX) : in_len; while (i < blk_end) { struct sdefl_match m = {0}; int left = blk_end - i; - int max_match = (left >= SDEFL_MAX_MATCH) ? SDEFL_MAX_MATCH : left; + int max_match = (left > SDEFL_MAX_MATCH) ? SDEFL_MAX_MATCH : left; int nice_match = pref[lvl] < max_match ? pref[lvl] : max_match; int run = 1, inc = 1, run_inc = 0; if (max_match > SDEFL_MIN_MATCH) { - sdefl_fnd(&m, s, max_chain, max_match, in, i); + sdefl_fnd(&m, s, max_chain, max_match, in, i, in_len); } - if (lvl >= 5 && m.len >= SDEFL_MIN_MATCH && m.len < nice_match){ + if (lvl >= 5 && m.len >= SDEFL_MIN_MATCH && m.len + 1 < nice_match){ struct sdefl_match m2 = {0}; - sdefl_fnd(&m2, s, max_chain, m.len+1, in, i+1); + sdefl_fnd(&m2, s, max_chain, m.len + 1, in, i + 1, in_len); m.len = (m2.len > m.len) ? 0 : m.len; } if (m.len >= SDEFL_MIN_MATCH) { @@ -636,12 +718,12 @@ sdefl_compr(struct sdefl *s, unsigned char *out, const unsigned char *in, sdefl_seq(s, i - litlen, litlen); litlen = 0; } - sdefl_flush(&q, s, blk_end == in_len, in); + sdefl_flush(&q, s, blk_end == in_len, in, blk_begin, blk_end); } while (i < in_len); - - if (s->bitcnt > 0) + if (s->bitcnt) { sdefl_put(&q, s, 0x00, 8 - s->bitcnt); - + } + assert(s->bitcnt == 0); return (int)(q - out); } extern int @@ -701,9 +783,8 @@ zsdeflate(struct sdefl *s, void *out, const void *in, int n, int lvl) { } extern int sdefl_bound(int len) { - int a = 128 + (len * 110) / 100; - int b = 128 + len + ((len / (31 * 1024)) + 1) * 5; - return (a > b) ? a : b; + int max_blocks = 1 + sdefl_div_round_up(len, SDEFL_RAW_BLK_SIZE); + int bound = 5 * max_blocks + len + 1 + 4 + 8; + return bound; } #endif /* SDEFL_IMPLEMENTATION */ - diff --git a/src/external/sinfl.h b/src/external/sinfl.h index 915da9d23..8979fcd7f 100644 --- a/src/external/sinfl.h +++ b/src/external/sinfl.h @@ -72,7 +72,7 @@ Results on the [Silesia compression corpus](http://sun.aei.polsl.pl/~sdeor/index This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------ ALTERNATIVE A - MIT License -Copyright (c) 2020 Micha Mettke +Copyright (c) 2020-2023 Micha Mettke 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 @@ -400,17 +400,21 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size) } break; case stored: { /* uncompressed block */ - int len, nlen; - sinfl_refill(&s); + unsigned len, nlen; sinfl__get(&s,s.bitcnt & 7); - len = sinfl__get(&s,16); - nlen = sinfl__get(&s,16); - in -= 2; s.bitcnt = 0; + len = (unsigned short)sinfl__get(&s,16); + nlen = (unsigned short)sinfl__get(&s,16); + s.bitptr -= s.bitcnt / 8; + s.bitbuf = s.bitcnt = 0; - if (len > (e-in) || !len) + if ((unsigned short)len != (unsigned short)~nlen) return (int)(out-o); - memcpy(out, in, (size_t)len); - in += len, out += len; + if (len > (e - s.bitptr) || !len) + return (int)(out-o); + + memcpy(out, s.bitptr, (size_t)len); + s.bitptr += len, out += len; + if (last) return (int)(out-o); state = hdr; } break; case fixed: { @@ -443,8 +447,9 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size) /* decode code lengths */ for (n = 0; n < nlit + ndist;) { + int sym = 0; sinfl_refill(&s); - int sym = sinfl_decode(&s, hlens, 7); + sym = sinfl_decode(&s, hlens, 7); switch (sym) {default: lens[n++] = (unsigned char)sym; break; case 16: for (i=3+sinfl_get(&s,2);i;i--,n++) lens[n]=lens[n-1]; break; case 17: for (i=3+sinfl_get(&s,3);i;i--,n++) lens[n]=0; break; @@ -458,8 +463,9 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size) case blk: { /* decompress block */ while (1) { + int sym; sinfl_refill(&s); - int sym = sinfl_decode(&s, s.lits, 10); + sym = sinfl_decode(&s, s.lits, 10); if (sym < 256) { /* literal */ if (sinfl_unlikely(out >= oe)) { From df90da0b3750b654c1ec660f83e461aae03a3b6b Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 2 Jul 2023 10:50:40 +0200 Subject: [PATCH 04/40] Update rcore.c --- src/rcore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rcore.c b/src/rcore.c index d02ea2b9b..bba8f5efe 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -3219,7 +3219,7 @@ const char *GetApplicationDirectory(void) #if defined(_WIN32) int len = 0; -#if defined (UNICODE) +#if defined(UNICODE) unsigned short widePath[MAX_PATH]; len = GetModuleFileNameW(NULL, widePath, MAX_PATH); len = WideCharToMultiByte(0, 0, widePath, len, appDir, MAX_PATH, NULL, NULL); From 48e2663d03a74b26d86e06057d659ddc9b1b7693 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 2 Jul 2023 10:51:39 +0200 Subject: [PATCH 05/40] REVIEWED: Issue #3105 --- src/rtext.c | 2 +- src/rtextures.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/rtext.c b/src/rtext.c index dce838c29..61f2e04cb 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1227,7 +1227,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing if (tempTextWidth < textWidth) tempTextWidth = textWidth; - textSize.x = tempTextWidth*scaleFactor + (float)((tempByteCounter - 1)*spacing); // Adds chars spacing to measure + textSize.x = (tempTextWidth + (float)((tempByteCounter - 1)*spacing))*scaleFactor; textSize.y = textHeight*scaleFactor; return textSize; diff --git a/src/rtextures.c b/src/rtextures.c index 2d422b179..bc53e1cec 100644 --- a/src/rtextures.c +++ b/src/rtextures.c @@ -3290,8 +3290,7 @@ void ImageDrawText(Image *dst, const char *text, int posX, int posY, int fontSiz if (GetFontDefault().texture.id == 0) LoadFontDefault(); Vector2 position = { (float)posX, (float)posY }; - // NOTE: For default font, spacing is set to desired font size / default font size (10) - ImageDrawTextEx(dst, GetFontDefault(), text, position, (float)fontSize, (float)fontSize/10, color); // WARNING: Module required: rtext + ImageDrawTextEx(dst, GetFontDefault(), text, position, (float)fontSize, 1.0f, color); // WARNING: Module required: rtext #else TRACELOG(LOG_WARNING, "IMAGE: ImageDrawText() requires module: rtext"); #endif From 3e4e4b32fdcaa2cff8854e11ff2179af4ff2afe9 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 2 Jul 2023 10:52:20 +0200 Subject: [PATCH 06/40] WARNING: BREAKING: ADDED: `SetTextLineSpacing()` --- src/raylib.h | 1 + src/rtext.c | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/raylib.h b/src/raylib.h index cceaa2101..539a31355 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1381,6 +1381,7 @@ RLAPI void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float f RLAPI void DrawTextCodepoints(Font font, const int *codepoints, int count, Vector2 position, float fontSize, float spacing, Color tint); // Draw multiple character (codepoint) // Text font info functions +RLAPI void SetTextLineSpacing(int spacing); // Set vertical line spacing when drawing with line-breaks RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font RLAPI int GetGlyphIndex(Font font, int codepoint); // Get glyph index position in font for a codepoint (unicode character), fallback to '?' if not found diff --git a/src/rtext.c b/src/rtext.c index 61f2e04cb..cb609cf62 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -111,7 +111,8 @@ static Font defaultFont = { 0 }; // Module specific Functions Declaration //---------------------------------------------------------------------------------- #if defined(SUPPORT_FILEFORMAT_FNT) -static Font LoadBMFont(const char *fileName); // Load a BMFont file (AngelCode font file) +static Font LoadBMFont(const char *fileName); // Load a BMFont file (AngelCode font file) +static int textLineSpacing = 15; // Text vertical line spacing in pixels #endif #if defined(SUPPORT_DEFAULT_FONT) @@ -123,7 +124,6 @@ extern void UnloadFontDefault(void); // Module Functions Definition //---------------------------------------------------------------------------------- #if defined(SUPPORT_DEFAULT_FONT) - // Load raylib default font extern void LoadFontDefault(void) { @@ -702,6 +702,8 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC totalWidth += chars[i].image.width + 2*padding; } +//#define SUPPORT_FONT_ATLAS_SIZE_CONSERVATIVE +#if defined(SUPPORT_FONT_ATLAS_SIZE_CONSERVATIVE) int rowCount = 0; int imageSize = 64; // Define minimum starting value to avoid unnecessary calculation steps for very small images @@ -711,6 +713,12 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC imageSize *= 2; // Double the size of image (to keep POT) rowCount = imageSize/(fontSize + 2*padding); // Calculate new row count for the new image size } +#else + // No need for a so-conservative atlas generation + float totalArea = totalWidth*fontSize*1.3f; + float imageMinSize = sqrtf(totalArea); + int imageSize = (int)powf(2, ceilf(logf(imageMinSize)/logf(2))); +#endif atlas.width = imageSize; // Atlas bitmap width atlas.height = imageSize; // Atlas bitmap height @@ -1071,9 +1079,8 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f if (codepoint == '\n') { - // NOTE: Fixed line spacing of 1.5 line-height - // TODO: Support custom line spacing defined by user - textOffsetY += (int)((font.baseSize + font.baseSize/2.0f)*scaleFactor); + // NOTE: Line spacing is a global variable, use SetTextLineSpacing() to setup + textOffsetY += textLineSpacing; textOffsetX = 0.0f; } else @@ -1143,9 +1150,8 @@ void DrawTextCodepoints(Font font, const int *codepoints, int count, Vector2 pos if (codepoints[i] == '\n') { - // NOTE: Fixed line spacing of 1.5 line-height - // TODO: Support custom line spacing defined by user - textOffsetY += (int)((font.baseSize + font.baseSize/2.0f)*scaleFactor); + // NOTE: Line spacing is a global variable, use SetTextLineSpacing() to setup + textOffsetY += textLineSpacing; textOffsetX = 0.0f; } else @@ -1161,6 +1167,12 @@ void DrawTextCodepoints(Font font, const int *codepoints, int count, Vector2 pos } } +// Set vertical line spacing when drawing with line-breaks +void SetTextLineSpacing(int spacing) +{ + textLineSpacing = spacing; +} + // Measure string width for default font int MeasureText(const char *text, int fontSize) { @@ -1219,7 +1231,9 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing if (tempTextWidth < textWidth) tempTextWidth = textWidth; byteCounter = 0; textWidth = 0; - textHeight += ((float)font.baseSize*1.5f); // NOTE: Fixed line spacing of 1.5 lines + + // NOTE: Line spacing is a global variable, use SetTextLineSpacing() to setup + textHeight += (float)textLineSpacing; } if (tempByteCounter < byteCounter) tempByteCounter = byteCounter; From 4fc5e82e3087b5a9df21db86f6dc4588e5d629b4 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 2 Jul 2023 11:10:42 +0200 Subject: [PATCH 07/40] REVIEWED: `TextToUpper()`, `TextToLower()`, `TextToPascal()` --- src/rtext.c | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/src/rtext.c b/src/rtext.c index cb609cf62..0cdac6d10 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1588,7 +1588,8 @@ int TextFindIndex(const char *text, const char *find) } // Get upper case version of provided string -// REQUIRES: toupper() +// WARNING: Limited functionality, only basic characters set +// TODO: Support UTF-8 diacritics to upper-case, check codepoints const char *TextToUpper(const char *text) { static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 }; @@ -1596,17 +1597,10 @@ const char *TextToUpper(const char *text) if (text != NULL) { - for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++) + for (int i = 0; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[i] != '\0'); i++) { - if (text[i] != '\0') - { - buffer[i] = (char)toupper(text[i]); - //if ((text[i] >= 'a') && (text[i] <= 'z')) buffer[i] = text[i] - 32; - - // TODO: Support UTF-8 diacritics to upper-case - //if ((text[i] >= 'à') && (text[i] <= 'ý')) buffer[i] = text[i] - 32; - } - else { buffer[i] = '\0'; break; } + if ((text[i] >= 'a') && (text[i] <= 'z')) buffer[i] = text[i] - 32; + else buffer[i] = text[i]; } } @@ -1614,7 +1608,7 @@ const char *TextToUpper(const char *text) } // Get lower case version of provided string -// REQUIRES: tolower() +// WARNING: Limited functionality, only basic characters set const char *TextToLower(const char *text) { static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 }; @@ -1622,14 +1616,10 @@ const char *TextToLower(const char *text) if (text != NULL) { - for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++) + for (int i = 0; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[i] != '\0'); i++) { - if (text[i] != '\0') - { - buffer[i] = (char)tolower(text[i]); - //if ((text[i] >= 'A') && (text[i] <= 'Z')) buffer[i] = text[i] + 32; - } - else { buffer[i] = '\0'; break; } + if ((text[i] >= 'A') && (text[i] <= 'Z')) buffer[i] = text[i] + 32; + else buffer[i] = text[i]; } } @@ -1637,7 +1627,7 @@ const char *TextToLower(const char *text) } // Get Pascal case notation version of provided string -// REQUIRES: toupper() +// WARNING: Limited functionality, only basic characters set const char *TextToPascal(const char *text) { static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 }; @@ -1645,20 +1635,18 @@ const char *TextToPascal(const char *text) if (text != NULL) { - buffer[0] = (char)toupper(text[0]); + // Upper case first character + if ((text[0] >= 'a') && (text[0] <= 'z')) buffer[0] = text[0] - 32; - for (int i = 1, j = 1; i < MAX_TEXT_BUFFER_LENGTH; i++, j++) + // Check for next separator to upper case another character + for (int i = 1, j = 1; (i < MAX_TEXT_BUFFER_LENGTH - 1) && (text[j] != '\0'); i++, j++) { - if (text[j] != '\0') + if (text[j] != '_') buffer[i] = text[j]; + else { - if (text[j] != '_') buffer[i] = text[j]; - else - { - j++; - buffer[i] = (char)toupper(text[j]); - } + j++; + if ((text[j] >= 'a') && (text[j] <= 'z')) buffer[i] = text[j] - 32; } - else { buffer[i] = '\0'; break; } } } From 5361d498c33deeb1e1ad44aed24a53a4f9e97618 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 2 Jul 2023 17:27:38 +0200 Subject: [PATCH 08/40] WARNING: REDESIGN: `Vector2Angle()`<-->`Vector2LineAngle()` #2887 --- examples/others/raymath_vector_angle.c | 106 +++++++++++++++++++++++ examples/others/raymath_vector_angle.png | Bin 0 -> 16339 bytes src/raymath.h | 27 +++--- 3 files changed, 120 insertions(+), 13 deletions(-) create mode 100644 examples/others/raymath_vector_angle.c create mode 100644 examples/others/raymath_vector_angle.png diff --git a/examples/others/raymath_vector_angle.c b/examples/others/raymath_vector_angle.c new file mode 100644 index 000000000..86cd91a93 --- /dev/null +++ b/examples/others/raymath_vector_angle.c @@ -0,0 +1,106 @@ +/******************************************************************************************* +* +* raylib [shapes] example - Vector Angle +* +* Example originally created with raylib 1.0, last time updated with raylib 4.2 +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2023 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include "raymath.h" + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [math] example - vector angle"); + + Vector2 v0 = { screenWidth/2, screenHeight/2 }; + Vector2 v1 = { 100.0f, 80.0f }; + Vector2 v2 = { 0 }; // Updated with mouse position + + float angle = 0.0f; // Angle in degrees + int angleMode = 0; // 0-Vector2Angle(), 1-Vector2LineAngle() + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyPressed(KEY_SPACE)) angleMode = !angleMode; + + if (angleMode == 0) + { + // Calculate angle between two vectors, considering a common origin (v0) + v1 = Vector2Add(v0, (Vector2){ 100.0f, 80.0f }); + v2 = GetMousePosition(); + angle = Vector2Angle(Vector2Normalize(Vector2Subtract(v1, v0)), Vector2Normalize(Vector2Subtract(v2, v0)))*RAD2DEG; + } + else if (angleMode == 1) + { + // Calculate angle defined by a two vectors line, in reference to horizontal line + v1 = (Vector2){ screenWidth/2, screenHeight/2 }; + v2 = GetMousePosition(); + angle = Vector2LineAngle(v1, v2)*RAD2DEG; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (angleMode == 0) DrawText("v0", v0.x, v0.y, 10, DARKGRAY); + DrawText("v1", v1.x, v1.y, 10, DARKGRAY); + DrawText("v2", v2.x, v2.y, 10, DARKGRAY); + + if (angleMode == 0) + { + DrawText("MODE: Angle between V1 and V2", 10, 10, 20, BLACK); + + DrawLineEx(v0, v1, 2.0f, BLACK); + DrawLineEx(v0, v2, 2.0f, RED); + + // TODO: Properly draw circle sector + DrawCircleSector(v0, 40.0f, Vector2LineAngle(v0, v1)*RAD2DEG, angle, 32, Fade(GREEN, 0.6f)); + } + else if (angleMode == 1) + { + DrawText("MODE: Angle formed by line V1 to V2", 10, 10, 20, BLACK); + + DrawLine(0, screenHeight/2, screenWidth, screenHeight/2, LIGHTGRAY); + DrawLineEx(v1, v2, 2.0f, RED); + + DrawCircleSector(v1, 40.0f, 90.0f, 180 - angle - 90, 32, Fade(GREEN, 0.6f)); + } + + DrawText("Press SPACE to change MODE", 460, 10, 20, DARKGRAY); + DrawText(TextFormat("ANGLE: %2.2f", angle), 10, 40, 20, LIME); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/others/raymath_vector_angle.png b/examples/others/raymath_vector_angle.png new file mode 100644 index 0000000000000000000000000000000000000000..29995e002f283e5bd9a1960085dc25da31d5e9eb GIT binary patch literal 16339 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 N8#8hAQNQ5m{{X8kT3rAD literal 0 HcmV?d00001 diff --git a/src/raymath.h b/src/raymath.h index 47728ff69..6a929cf6e 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -314,8 +314,19 @@ RMAPI float Vector2DistanceSqr(Vector2 v1, Vector2 v2) // NOTE: Angle is calculated from origin point (0, 0) RMAPI float Vector2Angle(Vector2 v1, Vector2 v2) { - float result = atan2f(v2.y - v1.y, v2.x - v1.x); + float result = 0.0f; + + float dot = v1.x*v2.x + v1.y*v2.y; // Dot product + float dotClamp = (dot < -1.0f)? -1.0f : dot; // Clamp + if (dotClamp > 1.0f) dotClamp = 1.0f; + result = acosf(dotClamp); + + // Alternative implementation, more costly + //float v1Length = sqrtf((v1.x*v1.x) + (v1.y*v1.y)); + //float v2Length = sqrtf((v2.x*v2.x) + (v2.y*v2.y)); + //float result = -acosf((v1.x*v2.x + v1.y*v2.y)/(v1Length*v2Length)); + return result; } @@ -325,18 +336,8 @@ RMAPI float Vector2Angle(Vector2 v1, Vector2 v2) RMAPI float Vector2LineAngle(Vector2 start, Vector2 end) { float result = 0.0f; - - float dot = start.x*end.x + start.y*end.y; // Dot product - - float dotClamp = (dot < -1.0f)? -1.0f : dot; // Clamp - if (dotClamp > 1.0f) dotClamp = 1.0f; - - result = acosf(dotClamp); - - // Alternative implementation, more costly - //float v1Length = sqrtf((start.x*start.x) + (start.y*start.y)); - //float v2Length = sqrtf((end.x*end.x) + (end.y*end.y)); - //float result = -acosf((start.x*end.x + start.y*end.y)/(v1Length*v2Length)); + + result = atan2f(end.y - start.y, end.x - start.x); return result; } From d1ab031a273f6d012c81f3ed637771b7f3c72ef4 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 2 Jul 2023 17:48:00 +0200 Subject: [PATCH 09/40] ADDED: `SetWindowFocused()` #3142 --- src/raylib.h | 1 + src/rcore.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/raylib.h b/src/raylib.h index 539a31355..f9f36626e 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -958,6 +958,7 @@ RLAPI void SetWindowMonitor(int monitor); // Set monitor RLAPI void SetWindowMinSize(int width, int height); // Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE) RLAPI void SetWindowSize(int width, int height); // Set window dimensions RLAPI void SetWindowOpacity(float opacity); // Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP) +RLAPI void SetWindowFocused(void); // Set window focused (only PLATFORM_DESKTOP) RLAPI void *GetWindowHandle(void); // Get native window handle RLAPI int GetScreenWidth(void); // Get current screen width RLAPI int GetScreenHeight(void); // Get current screen height diff --git a/src/rcore.c b/src/rcore.c index bba8f5efe..135ccb6cc 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -1705,6 +1705,14 @@ void SetWindowOpacity(float opacity) #endif } +// Set window focused +void SetWindowFocused(void) +{ +#if defined(PLATFORM_DESKTOP) + glfwFocusWindow(CORE.Window.handle); +#endif +} + // Get current screen width int GetScreenWidth(void) { From 64bb2fe3ec4994037467e44525c85abadce892e5 Mon Sep 17 00:00:00 2001 From: Gisteron <56622101+Gisteron@users.noreply.github.com> Date: Sun, 2 Jul 2023 18:51:27 +0200 Subject: [PATCH 10/40] fix vector angle example mode 0 circle segment drawing (#3150) --- examples/Makefile | 11 ++++++++++- examples/others/raymath_vector_angle.c | 7 +++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/Makefile b/examples/Makefile index c2ea35bf4..15edf1b36 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -536,12 +536,20 @@ AUDIO = \ audio/audio_stream_effects \ audio/audio_mixed_processor +OTHERS = \ + others/easings_testbed \ + others/embedded_files_loading \ + others/raylib_opengl_interop \ + others/raymath_vector_angle \ + others/rlgl_compute_shader \ + others/rlgl_standalone + CURRENT_MAKEFILE = $(lastword $(MAKEFILE_LIST)) # Define processes to execute #------------------------------------------------------------------------------------------------ # Default target entry -all: $(CORE) $(SHAPES) $(TEXT) $(TEXTURES) $(MODELS) $(SHADERS) $(AUDIO) +all: $(CORE) $(SHAPES) $(TEXT) $(TEXTURES) $(MODELS) $(SHADERS) $(AUDIO) $(OTHERS) core: $(CORE) shapes: $(SHAPES) @@ -550,6 +558,7 @@ text: $(TEXT) models: $(MODELS) shaders: $(SHADERS) audio: $(AUDIO) +others: $(OTHERS) # Generic compilation pattern # NOTE: Examples must be ready for Android compilation! diff --git a/examples/others/raymath_vector_angle.c b/examples/others/raymath_vector_angle.c index 86cd91a93..56db373cd 100644 --- a/examples/others/raymath_vector_angle.c +++ b/examples/others/raymath_vector_angle.c @@ -49,14 +49,14 @@ int main(void) // Calculate angle between two vectors, considering a common origin (v0) v1 = Vector2Add(v0, (Vector2){ 100.0f, 80.0f }); v2 = GetMousePosition(); - angle = Vector2Angle(Vector2Normalize(Vector2Subtract(v1, v0)), Vector2Normalize(Vector2Subtract(v2, v0)))*RAD2DEG; + angle = 90 - Vector2LineAngle(v0, v2) * RAD2DEG; } else if (angleMode == 1) { // Calculate angle defined by a two vectors line, in reference to horizontal line v1 = (Vector2){ screenWidth/2, screenHeight/2 }; v2 = GetMousePosition(); - angle = Vector2LineAngle(v1, v2)*RAD2DEG; + angle = Vector2LineAngle(v1, v2) * RAD2DEG; } //---------------------------------------------------------------------------------- @@ -77,8 +77,7 @@ int main(void) DrawLineEx(v0, v1, 2.0f, BLACK); DrawLineEx(v0, v2, 2.0f, RED); - // TODO: Properly draw circle sector - DrawCircleSector(v0, 40.0f, Vector2LineAngle(v0, v1)*RAD2DEG, angle, 32, Fade(GREEN, 0.6f)); + DrawCircleSector(v0, 40.0f, 90 - Vector2LineAngle(v0, v1) * RAD2DEG, angle, 32, Fade(GREEN, 0.6f)); } else if (angleMode == 1) { From e8af87575639d27fa5486ffe88458596d067c21a Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 2 Jul 2023 18:54:50 +0200 Subject: [PATCH 11/40] Minor format tweak, another issue introduced... --- examples/others/raymath_vector_angle.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/others/raymath_vector_angle.c b/examples/others/raymath_vector_angle.c index 56db373cd..457d69dc3 100644 --- a/examples/others/raymath_vector_angle.c +++ b/examples/others/raymath_vector_angle.c @@ -49,14 +49,14 @@ int main(void) // Calculate angle between two vectors, considering a common origin (v0) v1 = Vector2Add(v0, (Vector2){ 100.0f, 80.0f }); v2 = GetMousePosition(); - angle = 90 - Vector2LineAngle(v0, v2) * RAD2DEG; + angle = 90 - Vector2LineAngle(v0, v2)*RAD2DEG; } else if (angleMode == 1) { // Calculate angle defined by a two vectors line, in reference to horizontal line v1 = (Vector2){ screenWidth/2, screenHeight/2 }; v2 = GetMousePosition(); - angle = Vector2LineAngle(v1, v2) * RAD2DEG; + angle = Vector2LineAngle(v1, v2)*RAD2DEG; } //---------------------------------------------------------------------------------- @@ -77,7 +77,7 @@ int main(void) DrawLineEx(v0, v1, 2.0f, BLACK); DrawLineEx(v0, v2, 2.0f, RED); - DrawCircleSector(v0, 40.0f, 90 - Vector2LineAngle(v0, v1) * RAD2DEG, angle, 32, Fade(GREEN, 0.6f)); + DrawCircleSector(v0, 40.0f, 90 - Vector2LineAngle(v0, v1)*RAD2DEG, angle, 32, Fade(GREEN, 0.6f)); } else if (angleMode == 1) { From fdc28fce80d6e9ae04e900079beba7d79673b25d Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 2 Jul 2023 20:05:15 +0200 Subject: [PATCH 12/40] Reviewed vector2angle example --- examples/others/raymath_vector_angle.c | 7 +++++-- src/raymath.h | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/others/raymath_vector_angle.c b/examples/others/raymath_vector_angle.c index 457d69dc3..5de6116f2 100644 --- a/examples/others/raymath_vector_angle.c +++ b/examples/others/raymath_vector_angle.c @@ -49,7 +49,7 @@ int main(void) // Calculate angle between two vectors, considering a common origin (v0) v1 = Vector2Add(v0, (Vector2){ 100.0f, 80.0f }); v2 = GetMousePosition(); - angle = 90 - Vector2LineAngle(v0, v2)*RAD2DEG; + angle = Vector2Angle(Vector2Normalize(Vector2Subtract(v1, v0)), Vector2Normalize(Vector2Subtract(v2, v0)))*RAD2DEG; } else if (angleMode == 1) { @@ -77,7 +77,10 @@ int main(void) DrawLineEx(v0, v1, 2.0f, BLACK); DrawLineEx(v0, v2, 2.0f, RED); - DrawCircleSector(v0, 40.0f, 90 - Vector2LineAngle(v0, v1)*RAD2DEG, angle, 32, Fade(GREEN, 0.6f)); + float startangle = 90 - Vector2LineAngle(v0, v1)*RAD2DEG; + DrawCircleSector(v0, 40.0f, startangle, angle + startangle, 32, Fade(GREEN, 0.6f)); + + //DrawCircleSector(v0, 40.0f, 90 - Vector2LineAngle(v0, v1)*RAD2DEG, angle, 32, Fade(GREEN, 0.6f)); } else if (angleMode == 1) { diff --git a/src/raymath.h b/src/raymath.h index 6a929cf6e..087410ef3 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -316,16 +316,15 @@ RMAPI float Vector2Angle(Vector2 v1, Vector2 v2) { float result = 0.0f; - float dot = v1.x*v2.x + v1.y*v2.y; // Dot product + float dot = v1.x*v2.x + v1.y*v2.y; // Dot product float dotClamp = (dot < -1.0f)? -1.0f : dot; // Clamp if (dotClamp > 1.0f) dotClamp = 1.0f; - result = acosf(dotClamp); // Alternative implementation, more costly //float v1Length = sqrtf((v1.x*v1.x) + (v1.y*v1.y)); //float v2Length = sqrtf((v2.x*v2.x) + (v2.y*v2.y)); - //float result = -acosf((v1.x*v2.x + v1.y*v2.y)/(v1Length*v2Length)); + //result = -acosf((v1.x*v2.x + v1.y*v2.y)/(v1Length*v2Length)); return result; } From ffe4d36e0af86ee2d72abe7607b0525e1ffcf61f Mon Sep 17 00:00:00 2001 From: ubkp <118854183+ubkp@users.noreply.github.com> Date: Mon, 3 Jul 2023 04:29:26 -0300 Subject: [PATCH 13/40] Fix swipe gestures for web (#3151) --- src/rcore.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rcore.c b/src/rcore.c index 135ccb6cc..6ef25c0bf 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -6131,6 +6131,10 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent { gestureEvent.pointId[i] = CORE.Input.Touch.pointId[i]; gestureEvent.position[i] = CORE.Input.Touch.position[i]; + + // Normalize gestureEvent.position[i] + gestureEvent.position[i].x /= (float)GetScreenWidth(); + gestureEvent.position[i].y /= (float)GetScreenHeight(); } // Gesture data is sent to gestures system for processing From dd2d64e05804e749d470a9d252cea48b8b1d7e17 Mon Sep 17 00:00:00 2001 From: ubkp <118854183+ubkp@users.noreply.github.com> Date: Tue, 4 Jul 2023 06:08:58 -0300 Subject: [PATCH 14/40] Fix pinch gestures for web (#3153) --- src/rgestures.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/rgestures.h b/src/rgestures.h index 0be2fbb5c..1461a1114 100644 --- a/src/rgestures.h +++ b/src/rgestures.h @@ -203,6 +203,8 @@ typedef struct { Vector2 downDragPosition; // Touch drag position Vector2 moveDownPositionA; // First touch down position on move Vector2 moveDownPositionB; // Second touch down position on move + Vector2 previousPositionA; // Previous position A to compare for pinch gestures + Vector2 previousPositionB; // Previous position B to compare for pinch gestures int tapCounter; // TAP counter (one tap implies TOUCH_ACTION_DOWN and TOUCH_ACTION_UP actions) } Touch; struct { @@ -364,6 +366,9 @@ void ProcessGestureEvent(GestureEvent event) GESTURES.Touch.downPositionA = event.position[0]; GESTURES.Touch.downPositionB = event.position[1]; + GESTURES.Touch.previousPositionA = GESTURES.Touch.downPositionA; + GESTURES.Touch.previousPositionB = GESTURES.Touch.downPositionB; + //GESTURES.Pinch.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.downPositionB); GESTURES.Pinch.vector.x = GESTURES.Touch.downPositionB.x - GESTURES.Touch.downPositionA.x; @@ -376,18 +381,15 @@ void ProcessGestureEvent(GestureEvent event) { GESTURES.Pinch.distance = rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB); - GESTURES.Touch.downPositionA = GESTURES.Touch.moveDownPositionA; - GESTURES.Touch.downPositionB = GESTURES.Touch.moveDownPositionB; - GESTURES.Touch.moveDownPositionA = event.position[0]; GESTURES.Touch.moveDownPositionB = event.position[1]; GESTURES.Pinch.vector.x = GESTURES.Touch.moveDownPositionB.x - GESTURES.Touch.moveDownPositionA.x; GESTURES.Pinch.vector.y = GESTURES.Touch.moveDownPositionB.y - GESTURES.Touch.moveDownPositionA.y; - if ((rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_PINCH) || (rgVector2Distance(GESTURES.Touch.downPositionB, GESTURES.Touch.moveDownPositionB) >= MINIMUM_PINCH)) + if ((rgVector2Distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_PINCH) || (rgVector2Distance(GESTURES.Touch.previousPositionB, GESTURES.Touch.moveDownPositionB) >= MINIMUM_PINCH)) { - if ((rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) - GESTURES.Pinch.distance) < 0) GESTURES.current = GESTURE_PINCH_IN; + if ( rgVector2Distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.previousPositionB) > rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) ) GESTURES.current = GESTURE_PINCH_IN; else GESTURES.current = GESTURE_PINCH_OUT; } else From 225b4fb3e2503d97a53d3aa746ddac3648cfebd8 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 4 Jul 2023 16:58:43 +0200 Subject: [PATCH 15/40] REVIEWED: `Vector2Angle()` --- examples/others/raymath_vector_angle.c | 4 +--- src/raymath.h | 12 +++--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/examples/others/raymath_vector_angle.c b/examples/others/raymath_vector_angle.c index 5de6116f2..b193648fe 100644 --- a/examples/others/raymath_vector_angle.c +++ b/examples/others/raymath_vector_angle.c @@ -78,9 +78,7 @@ int main(void) DrawLineEx(v0, v2, 2.0f, RED); float startangle = 90 - Vector2LineAngle(v0, v1)*RAD2DEG; - DrawCircleSector(v0, 40.0f, startangle, angle + startangle, 32, Fade(GREEN, 0.6f)); - - //DrawCircleSector(v0, 40.0f, 90 - Vector2LineAngle(v0, v1)*RAD2DEG, angle, 32, Fade(GREEN, 0.6f)); + DrawCircleSector(v0, 40.0f, startangle, startangle + angle - 360.0f*(angle > 180.0f), 32, Fade(GREEN, 0.6f)); } else if (angleMode == 1) { diff --git a/src/raymath.h b/src/raymath.h index 087410ef3..d7ec1d252 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -316,15 +316,9 @@ RMAPI float Vector2Angle(Vector2 v1, Vector2 v2) { float result = 0.0f; - float dot = v1.x*v2.x + v1.y*v2.y; // Dot product - float dotClamp = (dot < -1.0f)? -1.0f : dot; // Clamp - if (dotClamp > 1.0f) dotClamp = 1.0f; - result = acosf(dotClamp); - - // Alternative implementation, more costly - //float v1Length = sqrtf((v1.x*v1.x) + (v1.y*v1.y)); - //float v2Length = sqrtf((v2.x*v2.x) + (v2.y*v2.y)); - //result = -acosf((v1.x*v2.x + v1.y*v2.y)/(v1Length*v2Length)); + float dot = v1.x*v2.x + v1.y*v2.y; + float det = v1.x*v2.y - v1.y*v2.x; + result = -atan2f(det, dot); return result; } From 3c4ce9c99b74475cfc651ddc4db482a4ee86d57f Mon Sep 17 00:00:00 2001 From: Wytek01 <101928745+Wytekol@users.noreply.github.com> Date: Wed, 5 Jul 2023 16:39:38 +0200 Subject: [PATCH 16/40] Update examples_template.c to raylib 4.5 (#3156) --- examples/examples_template.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/examples_template.c b/examples/examples_template.c index 3d8332e67..2b962d319 100644 --- a/examples/examples_template.c +++ b/examples/examples_template.c @@ -41,7 +41,7 @@ * * raylib [core] example - Basic window * -* Example originally created with raylib 4.2, last time updated with raylib 4.2 +* Example originally created with raylib 4.5, last time updated with raylib 4.5 * * Example contributed by (@) and reviewed by Ramon Santamaria (@raysan5) * From 13a26a0fa238b50621091ff686a6edf7014ab75f Mon Sep 17 00:00:00 2001 From: ubkp <118854183+ubkp@users.noreply.github.com> Date: Wed, 5 Jul 2023 11:43:00 -0300 Subject: [PATCH 17/40] Fix degrees of swipe gestures for web (#3155) --- src/rgestures.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rgestures.h b/src/rgestures.h index 1461a1114..35cd7a602 100644 --- a/src/rgestures.h +++ b/src/rgestures.h @@ -311,10 +311,10 @@ void ProcessGestureEvent(GestureEvent event) // NOTE: Angle should be inverted in Y GESTURES.Drag.angle = 360.0f - rgVector2Angle(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition); - if ((GESTURES.Drag.angle < 30) || (GESTURES.Drag.angle > 330)) GESTURES.current = GESTURE_SWIPE_RIGHT; // Right - else if ((GESTURES.Drag.angle > 30) && (GESTURES.Drag.angle < 120)) GESTURES.current = GESTURE_SWIPE_UP; // Up - else if ((GESTURES.Drag.angle > 120) && (GESTURES.Drag.angle < 210)) GESTURES.current = GESTURE_SWIPE_LEFT; // Left - else if ((GESTURES.Drag.angle > 210) && (GESTURES.Drag.angle < 300)) GESTURES.current = GESTURE_SWIPE_DOWN; // Down + if ((GESTURES.Drag.angle < 30) || (GESTURES.Drag.angle > 330)) GESTURES.current = GESTURE_SWIPE_RIGHT; // Right + else if ((GESTURES.Drag.angle >= 30) && (GESTURES.Drag.angle <= 150)) GESTURES.current = GESTURE_SWIPE_UP; // Up + else if ((GESTURES.Drag.angle > 150) && (GESTURES.Drag.angle < 210)) GESTURES.current = GESTURE_SWIPE_LEFT; // Left + else if ((GESTURES.Drag.angle >= 210) && (GESTURES.Drag.angle <= 330)) GESTURES.current = GESTURE_SWIPE_DOWN; // Down else GESTURES.current = GESTURE_NONE; } else From 58bd10edb27e0e5dd8d835e2222239390c804d5e Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 5 Jul 2023 18:36:54 +0200 Subject: [PATCH 18/40] Update rtext.c --- src/rtext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rtext.c b/src/rtext.c index 0cdac6d10..396275a8d 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -112,8 +112,8 @@ static Font defaultFont = { 0 }; //---------------------------------------------------------------------------------- #if defined(SUPPORT_FILEFORMAT_FNT) static Font LoadBMFont(const char *fileName); // Load a BMFont file (AngelCode font file) -static int textLineSpacing = 15; // Text vertical line spacing in pixels #endif +static int textLineSpacing = 15; // Text vertical line spacing in pixels #if defined(SUPPORT_DEFAULT_FONT) extern void LoadFontDefault(void); From 668b37e1113c653c38ce50757984b8fc074ea9b3 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 6 Jul 2023 12:29:28 +0200 Subject: [PATCH 19/40] REVIEWED: `GenImageFontAtlas()`, make atlas size less conservative --- src/rtext.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/rtext.c b/src/rtext.c index 396275a8d..eb3ad5514 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -699,7 +699,7 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC for (int i = 0; i < glyphCount; i++) { if (chars[i].image.width > maxGlyphWidth) maxGlyphWidth = chars[i].image.width; - totalWidth += chars[i].image.width + 2*padding; + totalWidth += chars[i].image.width + 4*padding; } //#define SUPPORT_FONT_ATLAS_SIZE_CONSERVATIVE @@ -713,15 +713,28 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC imageSize *= 2; // Double the size of image (to keep POT) rowCount = imageSize/(fontSize + 2*padding); // Calculate new row count for the new image size } -#else - // No need for a so-conservative atlas generation - float totalArea = totalWidth*fontSize*1.3f; - float imageMinSize = sqrtf(totalArea); - int imageSize = (int)powf(2, ceilf(logf(imageMinSize)/logf(2))); -#endif atlas.width = imageSize; // Atlas bitmap width atlas.height = imageSize; // Atlas bitmap height +#else + // No need for a so-conservative atlas generation + float totalArea = totalWidth*fontSize*1.2f; + float imageMinSize = sqrtf(totalArea); + int imageSize = (int)powf(2, ceilf(logf(imageMinSize)/logf(2))); + + if (totalArea < ((imageSize*imageSize)/2)) + { + atlas.width = imageSize; // Atlas bitmap width + atlas.height = imageSize/2; // Atlas bitmap height + } + else + { + atlas.width = imageSize; // Atlas bitmap width + atlas.height = imageSize; // Atlas bitmap height + } +#endif + + atlas.data = (unsigned char *)RL_CALLOC(1, atlas.width*atlas.height); // Create a bitmap to store characters (8 bpp) atlas.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE; atlas.mipmaps = 1; From 685d47938bf97ef5cb2ec094bfebd7de9bd9bef8 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 6 Jul 2023 12:31:01 +0200 Subject: [PATCH 20/40] Reverted `MeasureTextEx()` change #3105 --- src/rtext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rtext.c b/src/rtext.c index eb3ad5514..e7bea9a00 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1254,7 +1254,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing if (tempTextWidth < textWidth) tempTextWidth = textWidth; - textSize.x = (tempTextWidth + (float)((tempByteCounter - 1)*spacing))*scaleFactor; + textSize.x = tempTextWidth*scaleFactor + (float)((tempByteCounter - 1)*spacing); textSize.y = textHeight*scaleFactor; return textSize; From 334e96d470c5cb09d154e1c849d04adb721a7a8c Mon Sep 17 00:00:00 2001 From: o3o Date: Thu, 6 Jul 2023 12:32:02 +0200 Subject: [PATCH 21/40] update bindbd-raylib3 to raylib 4.5 (#3157) --- BINDINGS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BINDINGS.md b/BINDINGS.md index f040599ca..bb73d73aa 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -17,7 +17,7 @@ Some people ported raylib to other languages in form of bindings or wrappers to | ray-cyber | 4.5 | [Cyber](https://cyberscript.dev) | MIT | https://github.com/fubark/ray-cyber | | raylib-c3 | **4.5** | [C3](https://c3-lang.org/) | Zlib | https://github.com/Its-Kenta/Raylib-C3 | | dart-raylib | 4.0 | [Dart](https://dart.dev/) | MIT | https://gitlab.com/wolfenrain/dart-raylib | -| bindbc-raylib3 | 4.0 | [D](https://dlang.org/) | BSL-1.0 | https://github.com/o3o/bindbc-raylib3 | +| bindbc-raylib3 | **4.5** | [D](https://dlang.org/) | BSL-1.0 | https://github.com/o3o/bindbc-raylib3 | | dray | 4.2 | [D](https://dlang.org/) | Apache-2.0 | https://github.com/redthing1/dray | | raylib-d | **4.5** | [D](https://dlang.org/) | Zlib | https://github.com/schveiguy/raylib-d | | dlang_raylib | 4.0 | [D](https://dlang.org) | MPL-2.0 |https://github.com/rc-05/dlang_raylib | From 91e4eea52d1b92e1408fd129ca7b638f9cd4531d Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Mon, 10 Jul 2023 12:58:10 -0400 Subject: [PATCH 22/40] Add raylib-ffi to bindings list (#3164) --- BINDINGS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/BINDINGS.md b/BINDINGS.md index bb73d73aa..8c5c8396b 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -59,6 +59,7 @@ Some people ported raylib to other languages in form of bindings or wrappers to | raylib-php | 3.5 | [PHP](https://en.wikipedia.org/wiki/PHP) | Zlib | https://github.com/joseph-montanez/raylib-php | | raylib-phpcpp | 3.5 | [PHP](https://en.wikipedia.org/wiki/PHP) | Zlib | https://github.com/oraoto/raylib-phpcpp | | raylibr | 4.0 | [R](https://www.r-project.org) | MIT | https://github.com/jeroenjanssens/raylibr | +| raylib-ffi | 4.5 | [Rust](https://www.rust-lang.org/) | GPLv3 | https://github.com/ewpratten/raylib-ffi | | raylib-rs | 3.5 | [Rust](https://www.rust-lang.org/) | Zlib | https://github.com/deltaphc/raylib-rs | | Relib | 3.5 | [ReCT](https://github.com/RedCubeDev-ByteSpace/ReCT) | ? | https://github.com/RedCubeDev-ByteSpace/Relib | | racket-raylib | 4.0 | [Racket](https://racket-lang.org/) | MIT/Apache-2.0 | https://github.com/eutro/racket-raylib | From 4b6cbd234040312091e24085ee929a7cec60faac Mon Sep 17 00:00:00 2001 From: ubkp <118854183+ubkp@users.noreply.github.com> Date: Mon, 10 Jul 2023 13:58:56 -0300 Subject: [PATCH 23/40] Fix Touch pointCount for web (#3163) --- src/rcore.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rcore.c b/src/rcore.c index 6ef25c0bf..833400fcf 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -6139,6 +6139,9 @@ static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent // Gesture data is sent to gestures system for processing ProcessGestureEvent(gestureEvent); + + // Reset the pointCount for web, if it was the last Touch End event + if (eventType == EMSCRIPTEN_EVENT_TOUCHEND && CORE.Input.Touch.pointCount == 1) CORE.Input.Touch.pointCount = 0; #endif return 1; // The event was consumed by the callback handler From 0b9fae3c539161e850db9092ac7294f889583e82 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 10 Jul 2023 19:13:44 +0200 Subject: [PATCH 24/40] Reviewed `rcamera`/`rgestures` file-macros for consistency #3161 --- src/rcamera.h | 20 ++++++++++---------- src/rcore.c | 4 ++-- src/rgestures.h | 22 +++++++++++----------- src/rtext.c | 2 +- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/rcamera.h b/src/rcamera.h index 2a20d5814..4e99c3e8c 100644 --- a/src/rcamera.h +++ b/src/rcamera.h @@ -3,12 +3,12 @@ * rcamera - Basic camera system with support for multiple camera modes * * CONFIGURATION: -* #define CAMERA_IMPLEMENTATION +* #define RCAMERA_IMPLEMENTATION * Generates the implementation of the library into the included file. * If not defined, the library is in header only mode and can be included in other headers * or source files without problems. But only ONE file should hold the implementation. * -* #define CAMERA_STANDALONE +* #define RCAMERA_STANDALONE * If defined, the library can be used as standalone as a camera system but some * functions must be redefined to manage inputs accordingly. * @@ -50,7 +50,7 @@ #define RLAPI // Functions defined as 'extern' by default (implicit specifiers) #endif -#if defined(CAMERA_STANDALONE) +#if defined(RCAMERA_STANDALONE) #define CAMERA_CULL_DISTANCE_NEAR 0.01 #define CAMERA_CULL_DISTANCE_FAR 1000.0 #else @@ -60,9 +60,9 @@ //---------------------------------------------------------------------------------- // Types and Structures Definition -// NOTE: Below types are required for CAMERA_STANDALONE usage +// NOTE: Below types are required for standalone usage //---------------------------------------------------------------------------------- -#if defined(CAMERA_STANDALONE) +#if defined(RCAMERA_STANDALONE) // Vector2, 2 components typedef struct Vector2 { float x; // Vector x component @@ -138,7 +138,7 @@ RLAPI Matrix GetCameraProjectionMatrix(Camera* camera, float aspect); } #endif -#endif // CAMERA_H +#endif // RCAMERA_H /*********************************************************************************** @@ -147,7 +147,7 @@ RLAPI Matrix GetCameraProjectionMatrix(Camera* camera, float aspect); * ************************************************************************************/ -#if defined(CAMERA_IMPLEMENTATION) +#if defined(RCAMERA_IMPLEMENTATION) #include "raymath.h" // Required for vector maths: // Vector3Add() @@ -417,7 +417,7 @@ Matrix GetCameraProjectionMatrix(Camera *camera, float aspect) return MatrixIdentity(); } -#ifndef CAMERA_STANDALONE +#if !defined(RCAMERA_STANDALONE) // Update camera position for selected mode // Camera mode: CAMERA_FREE, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON, CAMERA_ORBITAL or CUSTOM void UpdateCamera(Camera *camera, int mode) @@ -483,7 +483,7 @@ void UpdateCamera(Camera *camera, int mode) if (IsKeyPressed(KEY_KP_ADD)) CameraMoveToTarget(camera, -2.0f); } } -#endif // !CAMERA_STANDALONE +#endif // !RCAMERA_STANDALONE // Update camera movement, movement/rotation values should be provided by user void UpdateCameraPro(Camera *camera, Vector3 movement, Vector3 rotation, float zoom) @@ -516,4 +516,4 @@ void UpdateCameraPro(Camera *camera, Vector3 movement, Vector3 rotation, float z CameraMoveToTarget(camera, zoom); } -#endif // CAMERA_IMPLEMENTATION +#endif // RCAMERA_IMPLEMENTATION diff --git a/src/rcore.c b/src/rcore.c index 6ef25c0bf..e98734ada 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -124,12 +124,12 @@ #include "raymath.h" // Vector3, Quaternion and Matrix functionality #if defined(SUPPORT_GESTURES_SYSTEM) - #define GESTURES_IMPLEMENTATION + #define RGESTURES_IMPLEMENTATION #include "rgestures.h" // Gestures detection functionality #endif #if defined(SUPPORT_CAMERA_SYSTEM) - #define CAMERA_IMPLEMENTATION + #define RCAMERA_IMPLEMENTATION #include "rcamera.h" // Camera system functionality #endif diff --git a/src/rgestures.h b/src/rgestures.h index 35cd7a602..749f440aa 100644 --- a/src/rgestures.h +++ b/src/rgestures.h @@ -3,12 +3,12 @@ * rgestures - Gestures system, gestures processing based on input events (touch/mouse) * * CONFIGURATION: -* #define GESTURES_IMPLEMENTATION +* #define RGESTURES_IMPLEMENTATION * Generates the implementation of the library into the included file. * If not defined, the library is in header only mode and can be included in other headers * or source files without problems. But only ONE file should hold the implementation. * -* #define GESTURES_STANDALONE +* #define RGESTURES_STANDALONE * If defined, the library can be used as standalone to process gesture events with * no external dependencies. * @@ -56,7 +56,7 @@ //---------------------------------------------------------------------------------- // Types and Structures Definition -// NOTE: Below types are required for GESTURES_STANDALONE usage +// NOTE: Below types are required for standalone usage //---------------------------------------------------------------------------------- // Boolean type #if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800) @@ -73,7 +73,7 @@ typedef struct Vector2 { } Vector2; #endif -#if defined(GESTURES_STANDALONE) +#if defined(RGESTURES_STANDALONE) // Gestures type // NOTE: It could be used as flags to enable only some gestures typedef enum { @@ -122,7 +122,7 @@ extern "C" { // Prevents name mangling of functions void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures void UpdateGestures(void); // Update gestures detected (must be called every frame) -#if defined(GESTURES_STANDALONE) +#if defined(RGESTURES_STANDALONE) void SetGesturesEnabled(unsigned int flags); // Enable a set of gestures using flags bool IsGestureDetected(int gesture); // Check if a gesture have been detected int GetGestureDetected(void); // Get latest detected gesture @@ -138,17 +138,17 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang } #endif -#endif // GESTURES_H +#endif // RGESTURES_H /*********************************************************************************** * -* GESTURES IMPLEMENTATION +* RGESTURES IMPLEMENTATION * ************************************************************************************/ -#if defined(GESTURES_IMPLEMENTATION) +#if defined(RGESTURES_IMPLEMENTATION) -#if defined(GESTURES_STANDALONE) +#if defined(RGESTURES_STANDALONE) #if defined(_WIN32) #if defined(__cplusplus) extern "C" { // Prevents name mangling of functions @@ -527,7 +527,7 @@ static double rgGetCurrentTime(void) { double time = 0; -#if !defined(GESTURES_STANDALONE) +#if !defined(RGESTURES_STANDALONE) time = GetTime(); #else #if defined(_WIN32) @@ -568,4 +568,4 @@ static double rgGetCurrentTime(void) return time; } -#endif // GESTURES_IMPLEMENTATION +#endif // RGESTURES_IMPLEMENTATION diff --git a/src/rtext.c b/src/rtext.c index e7bea9a00..3b21a93c9 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -1244,7 +1244,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing if (tempTextWidth < textWidth) tempTextWidth = textWidth; byteCounter = 0; textWidth = 0; - + // NOTE: Line spacing is a global variable, use SetTextLineSpacing() to setup textHeight += (float)textLineSpacing; } From bc40012ca3d719ece17f8ba28865ccb6cdf8bbcf Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 10 Jul 2023 19:15:55 +0200 Subject: [PATCH 25/40] Added missing structure on standalone mode #3160 --- src/rcamera.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/rcamera.h b/src/rcamera.h index 4e99c3e8c..c5382684e 100644 --- a/src/rcamera.h +++ b/src/rcamera.h @@ -76,6 +76,14 @@ float z; // Vector z component } Vector3; + // Matrix, 4x4 components, column major, OpenGL style, right-handed + typedef struct Matrix { + float m0, m4, m8, m12; // Matrix first row (4 components) + float m1, m5, m9, m13; // Matrix second row (4 components) + float m2, m6, m10, m14; // Matrix third row (4 components) + float m3, m7, m11, m15; // Matrix fourth row (4 components) + } Matrix; + // Camera type, defines a camera position/orientation in 3d space typedef struct Camera3D { Vector3 position; // Camera position From 2061bfc5e814dd4e2b5ff629cb02bef4c972e9f8 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 10 Jul 2023 19:29:10 +0200 Subject: [PATCH 26/40] Reviewed parameter names to avoid issues #3159 --- src/raymath.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/raymath.h b/src/raymath.h index d7ec1d252..9281691fa 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -1509,11 +1509,11 @@ RMAPI Matrix MatrixFrustum(double left, double right, double bottom, double top, // Get perspective projection matrix // NOTE: Fovy angle must be provided in radians -RMAPI Matrix MatrixPerspective(double fovy, double aspect, double near, double far) +RMAPI Matrix MatrixPerspective(double fovY, double aspect, double nearPlane, double farPlane) { Matrix result = { 0 }; - double top = near*tan(fovy*0.5); + double top = nearPlane*tan(fovY*0.5); double bottom = -top; double right = top*aspect; double left = -right; @@ -1521,27 +1521,27 @@ RMAPI Matrix MatrixPerspective(double fovy, double aspect, double near, double f // MatrixFrustum(-right, right, -top, top, near, far); float rl = (float)(right - left); float tb = (float)(top - bottom); - float fn = (float)(far - near); + float fn = (float)(farPlane - nearPlane); - result.m0 = ((float)near*2.0f)/rl; - result.m5 = ((float)near*2.0f)/tb; + result.m0 = ((float)nearPlane*2.0f)/rl; + result.m5 = ((float)nearPlane*2.0f)/tb; result.m8 = ((float)right + (float)left)/rl; result.m9 = ((float)top + (float)bottom)/tb; - result.m10 = -((float)far + (float)near)/fn; + result.m10 = -((float)farPlane + (float)nearPlane)/fn; result.m11 = -1.0f; - result.m14 = -((float)far*(float)near*2.0f)/fn; + result.m14 = -((float)farPlane*(float)nearPlane*2.0f)/fn; return result; } // Get orthographic projection matrix -RMAPI Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far) +RMAPI Matrix MatrixOrtho(double left, double right, double bottom, double top, double nearPlane, double farPlane) { Matrix result = { 0 }; float rl = (float)(right - left); float tb = (float)(top - bottom); - float fn = (float)(far - near); + float fn = (float)(farPlane - nearPlane); result.m0 = 2.0f/rl; result.m1 = 0.0f; @@ -1557,7 +1557,7 @@ RMAPI Matrix MatrixOrtho(double left, double right, double bottom, double top, d result.m11 = 0.0f; result.m12 = -((float)left + (float)right)/rl; result.m13 = -((float)top + (float)bottom)/tb; - result.m14 = -((float)far + (float)near)/fn; + result.m14 = -((float)farPlane + (float)nearPlane)/fn; result.m15 = 1.0f; return result; From e8181a5ddf22cb6c4b3dd530b5b60e5c4bd24c86 Mon Sep 17 00:00:00 2001 From: Anand Swaroop <72886192+Anut-py@users.noreply.github.com> Date: Tue, 11 Jul 2023 09:21:49 -0400 Subject: [PATCH 27/40] Update latest h-raylib version (#3166) --- BINDINGS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BINDINGS.md b/BINDINGS.md index 8c5c8396b..7fc88113e 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -28,7 +28,7 @@ Some people ported raylib to other languages in form of bindings or wrappers to | raylib-go | 4.5 | [Go](https://golang.org/) | Zlib | https://github.com/gen2brain/raylib-go | | raylib-guile | **auto** | [Guile](https://www.gnu.org/software/guile/) | Zlib | https://github.com/petelliott/raylib-guile | | gforth-raylib | 3.5 | [Gforth](https://gforth.org/) | MIT | https://github.com/ArnautDaniel/gforth-raylib | -| h-raylib | **4.5** | [Haskell](https://haskell.org/) | Apache-2.0 | https://github.com/Anut-py/h-raylib | +| h-raylib | **4.6-dev** | [Haskell](https://haskell.org/) | Apache-2.0 | https://github.com/Anut-py/h-raylib | | raylib-hx | 4.2 | [Haxe](https://haxe.org/) | Zlib | https://github.com/foreignsasquatch/raylib-hx | | hb-raylib | 3.5 | [Harbour](https://harbour.github.io) | MIT | https://github.com/MarcosLeonardoMendezGerencir/hb-raylib | | jaylib | 4.5 | [Janet](https://janet-lang.org/) | MIT | https://github.com/janet-lang/jaylib | From 7f21cf1dcf17225949cbfb0bdeb4677182e5564b Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 12 Jul 2023 10:37:10 +0200 Subject: [PATCH 28/40] Revert "UPDATED: `sdefl` and `sinfl` compression libraries" This reverts commit e190b7eee9199b681a8c50fb69f2fce07e92c7af. --- src/external/sdefl.h | 195 +++++++++++++------------------------------ src/external/sinfl.h | 28 +++---- 2 files changed, 68 insertions(+), 155 deletions(-) diff --git a/src/external/sdefl.h b/src/external/sdefl.h index 36015b95b..56539a56e 100644 --- a/src/external/sdefl.h +++ b/src/external/sdefl.h @@ -71,7 +71,7 @@ Results on the [Silesia compression corpus](http://sun.aei.polsl.pl/~sdeor/index This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------ ALTERNATIVE A - MIT License -Copyright (c) 2020-2023 Micha Mettke +Copyright (c) 2020 Micha Mettke 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 @@ -125,7 +125,7 @@ extern "C" { #define SDEFL_MIN_MATCH 4 #define SDEFL_BLK_MAX (256*1024) -#define SDEFL_SEQ_SIZ ((SDEFL_BLK_MAX+2)/3) +#define SDEFL_SEQ_SIZ ((SDEFL_BLK_MAX + SDEFL_MIN_MATCH)/SDEFL_MIN_MATCH) #define SDEFL_SYM_MAX (288) #define SDEFL_OFF_MAX (32) @@ -185,7 +185,6 @@ extern int zsdeflate(struct sdefl *s, void *o, const void *i, int n, int lvl); #define SDEFL_MAX_CODE_LEN (15) #define SDEFL_SYM_BITS (10u) #define SDEFL_SYM_MSK ((1u << SDEFL_SYM_BITS)-1u) -#define SDEFL_RAW_BLK_SIZE (65535) #define SDEFL_LIT_LEN_CODES (14) #define SDEFL_OFF_CODES (15) #define SDEFL_PRE_CODES (7) @@ -193,7 +192,6 @@ extern int zsdeflate(struct sdefl *s, void *o, const void *i, int n, int lvl); #define SDEFL_EOB (256) #define sdefl_npow2(n) (1 << (sdefl_ilog2((n)-1) + 1)) -#define sdefl_div_round_up(n,d) (((n)+((d)-1))/(d)) static int sdefl_ilog2(int n) { @@ -440,12 +438,12 @@ sdefl_precode(struct sdefl_symcnt *cnt, unsigned *freqs, unsigned *items, } while (run_start != total); cnt->items = (int)(at - items); } -struct sdefl_match_codest { +struct sdefl_match_codes { int ls, lc; int dc, dx; }; static void -sdefl_match_codes(struct sdefl_match_codest *cod, int dist, int len) { +sdefl_match_codes(struct sdefl_match_codes *cod, int dist, int len) { static const short dxmax[] = {0,6,12,24,48,96,192,384,768,1536,3072,6144,12288,24576}; static const unsigned char lslot[258+1] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, @@ -473,44 +471,6 @@ sdefl_match_codes(struct sdefl_match_codest *cod, int dist, int len) { cod->dx = sdefl_ilog2(sdefl_npow2(dist) >> 2); cod->dc = cod->dx ? ((cod->dx + 1) << 1) + (dist > dxmax[cod->dx]) : dist-1; } -enum sdefl_blk_type { - SDEFL_BLK_UCOMPR, - SDEFL_BLK_DYN -}; -static enum sdefl_blk_type -sdefl_blk_type(const struct sdefl *s, int blk_len, int pre_item_len, - const unsigned *pre_freq, const unsigned char *pre_len) { - static const unsigned char x_pre_bits[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; - static const unsigned char x_len_bits[] = {0,0,0,0,0,0,0,0, 1,1,1,1,2,2,2,2, - 3,3,3,3,4,4,4,4, 5,5,5,5,0}; - static const unsigned char x_off_bits[] = {0,0,0,0,1,1,2,2, 3,3,4,4,5,5,6,6, - 7,7,8,8,9,9,10,10, 11,11,12,12,13,13}; - - int dyn_cost = 0; - int fix_cost = 0; - int sym = 0; - - dyn_cost += 5 + 5 + 4 + (3 * pre_item_len); - for (sym = 0; sym < SDEFL_PRE_MAX; sym++) - dyn_cost += pre_freq[sym] * (x_pre_bits[sym] + pre_len[sym]); - for (sym = 0; sym < 256; sym++) - dyn_cost += s->freq.lit[sym] * s->cod.len.lit[sym]; - dyn_cost += s->cod.len.lit[SDEFL_EOB]; - for (sym = 257; sym < 286; sym++) - dyn_cost += s->freq.lit[sym] * (x_len_bits[sym - 257] + s->cod.len.lit[sym]); - for (sym = 0; sym < 30; sym++) - dyn_cost += s->freq.off[sym] * (x_off_bits[sym] + s->cod.len.off[sym]); - - fix_cost += 8*(5 * sdefl_div_round_up(blk_len, SDEFL_RAW_BLK_SIZE) + blk_len + 1 + 2); - return (dyn_cost < fix_cost) ? SDEFL_BLK_DYN : SDEFL_BLK_UCOMPR; -} -static void -sdefl_put16(unsigned char **dst, unsigned short x) { - unsigned char *val = *dst; - val[0] = (unsigned char)(x & 0xff); - val[1] = (unsigned char)(x >> 8); - *dst = val + 2; -} static void sdefl_match(unsigned char **dst, struct sdefl *s, int dist, int len) { static const char lxn[] = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; @@ -519,7 +479,7 @@ sdefl_match(unsigned char **dst, struct sdefl *s, int dist, int len) { static const short dmin[] = {1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257, 385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577}; - struct sdefl_match_codest cod; + struct sdefl_match_codes cod; sdefl_match_codes(&cod, dist, len); sdefl_put(dst, s, (int)s->cod.word.lit[cod.lc], s->cod.len.lit[cod.lc]); sdefl_put(dst, s, len - lmin[cod.ls], lxn[cod.ls]); @@ -528,8 +488,7 @@ sdefl_match(unsigned char **dst, struct sdefl *s, int dist, int len) { } static void sdefl_flush(unsigned char **dst, struct sdefl *s, int is_last, - const unsigned char *in, int blk_begin, int blk_end) { - int blk_len = blk_end - blk_begin; + const unsigned char *in) { int j, i = 0, item_cnt = 0; struct sdefl_symcnt symcnt = {0}; unsigned codes[SDEFL_PRE_MAX]; @@ -539,7 +498,7 @@ sdefl_flush(unsigned char **dst, struct sdefl *s, int is_last, static const unsigned char perm[SDEFL_PRE_MAX] = {16,17,18,0,8,7,9,6,10,5,11, 4,12,3,13,2,14,1,15}; - /* calculate huffman codes */ + /* huffman codes */ s->freq.lit[SDEFL_EOB]++; sdefl_huff(s->cod.len.lit, s->cod.word.lit, s->freq.lit, SDEFL_SYM_MAX, SDEFL_LIT_LEN_CODES); sdefl_huff(s->cod.len.off, s->cod.word.off, s->freq.off, SDEFL_OFF_MAX, SDEFL_OFF_CODES); @@ -550,58 +509,35 @@ sdefl_flush(unsigned char **dst, struct sdefl *s, int is_last, break; } } - /* write block */ - switch (sdefl_blk_type(s, blk_len, item_cnt, freqs, lens)) { - case SDEFL_BLK_UCOMPR: { - /* uncompressed blocks */ - int n = sdefl_div_round_up(blk_len, SDEFL_RAW_BLK_SIZE); - for (i = 0; i < n; ++i) { - int fin = is_last && (i + 1 == n); - int amount = blk_len < SDEFL_RAW_BLK_SIZE ? blk_len : SDEFL_RAW_BLK_SIZE; - sdefl_put(dst, s, !!fin, 1); /* block */ - sdefl_put(dst, s, 0x00, 2); /* stored block */ - if (s->bitcnt) { - sdefl_put(dst, s, 0x00, 8 - s->bitcnt); + /* block header */ + sdefl_put(dst, s, is_last ? 0x01 : 0x00, 1); /* block */ + sdefl_put(dst, s, 0x02, 2); /* dynamic huffman */ + sdefl_put(dst, s, symcnt.lit - 257, 5); + sdefl_put(dst, s, symcnt.off - 1, 5); + sdefl_put(dst, s, item_cnt - 4, 4); + for (i = 0; i < item_cnt; ++i) { + sdefl_put(dst, s, lens[perm[i]], 3); + } + for (i = 0; i < symcnt.items; ++i) { + unsigned sym = items[i] & 0x1F; + sdefl_put(dst, s, (int)codes[sym], lens[sym]); + if (sym < 16) continue; + if (sym == 16) sdefl_put(dst, s, items[i] >> 5, 2); + else if(sym == 17) sdefl_put(dst, s, items[i] >> 5, 3); + else sdefl_put(dst, s, items[i] >> 5, 7); + } + /* block sequences */ + for (i = 0; i < s->seq_cnt; ++i) { + if (s->seq[i].off >= 0) { + for (j = 0; j < s->seq[i].len; ++j) { + int c = in[s->seq[i].off + j]; + sdefl_put(dst, s, (int)s->cod.word.lit[c], s->cod.len.lit[c]); } - assert(s->bitcnt == 0); - sdefl_put16(dst, (unsigned short)amount); - sdefl_put16(dst, ~(unsigned short)amount); - memcpy(*dst, in + blk_begin + i * SDEFL_RAW_BLK_SIZE, amount); - *dst = *dst + amount; - blk_len -= amount; + } else { + sdefl_match(dst, s, -s->seq[i].off, s->seq[i].len); } - } break; - case SDEFL_BLK_DYN: { - /* dynamic huffman block */ - sdefl_put(dst, s, !!is_last, 1); /* block */ - sdefl_put(dst, s, 0x02, 2); /* dynamic huffman */ - sdefl_put(dst, s, symcnt.lit - 257, 5); - sdefl_put(dst, s, symcnt.off - 1, 5); - sdefl_put(dst, s, item_cnt - 4, 4); - for (i = 0; i < item_cnt; ++i) { - sdefl_put(dst, s, lens[perm[i]], 3); - } - for (i = 0; i < symcnt.items; ++i) { - unsigned sym = items[i] & 0x1F; - sdefl_put(dst, s, (int)codes[sym], lens[sym]); - if (sym < 16) continue; - if (sym == 16) sdefl_put(dst, s, items[i] >> 5, 2); - else if(sym == 17) sdefl_put(dst, s, items[i] >> 5, 3); - else sdefl_put(dst, s, items[i] >> 5, 7); - } - /* block sequences */ - for (i = 0; i < s->seq_cnt; ++i) { - if (s->seq[i].off >= 0) { - for (j = 0; j < s->seq[i].len; ++j) { - int c = in[s->seq[i].off + j]; - sdefl_put(dst, s, (int)s->cod.word.lit[c], s->cod.len.lit[c]); - } - } else { - sdefl_match(dst, s, -s->seq[i].off, s->seq[i].len); - } - } - sdefl_put(dst, s, (int)(s)->cod.word.lit[SDEFL_EOB], (s)->cod.len.lit[SDEFL_EOB]); - } break;} + } + sdefl_put(dst, s, (int)(s)->cod.word.lit[SDEFL_EOB], (s)->cod.len.lit[SDEFL_EOB]); memset(&s->freq, 0, sizeof(s->freq)); s->seq_cnt = 0; } @@ -614,12 +550,8 @@ sdefl_seq(struct sdefl *s, int off, int len) { } static void sdefl_reg_match(struct sdefl *s, int off, int len) { - struct sdefl_match_codest cod; + struct sdefl_match_codes cod; sdefl_match_codes(&cod, off, len); - - assert(cod.lc < SDEFL_SYM_MAX); - assert(cod.dc < SDEFL_OFF_MAX); - s->freq.lit[cod.lc]++; s->freq.off[cod.dc]++; } @@ -628,35 +560,22 @@ struct sdefl_match { int len; }; static void -sdefl_fnd(struct sdefl_match *m, const struct sdefl *s, int chain_len, - int max_match, const unsigned char *in, int p, int e) { - int i = s->tbl[sdefl_hash32(in + p)]; - int limit = ((p - SDEFL_WIN_SIZ) < SDEFL_NIL) ? SDEFL_NIL : (p-SDEFL_WIN_SIZ); - - assert(p < e); - assert(p + max_match <= e); +sdefl_fnd(struct sdefl_match *m, const struct sdefl *s, + int chain_len, int max_match, const unsigned char *in, int p) { + int i = s->tbl[sdefl_hash32(&in[p])]; + int limit = ((p-SDEFL_WIN_SIZ) limit) { - assert(i + m->len < e); - assert(p + m->len < e); - assert(i + SDEFL_MIN_MATCH < e); - assert(p + SDEFL_MIN_MATCH < e); - - if (in[i + m->len] == in[p + m->len] && - (sdefl_uload32(&in[i]) == sdefl_uload32(&in[p]))) { + if (in[i+m->len] == in[p+m->len] && + (sdefl_uload32(&in[i]) == sdefl_uload32(&in[p]))){ int n = SDEFL_MIN_MATCH; - while (n < max_match && in[i + n] == in[p + n]) { - assert(i + n < e); - assert(p + n < e); - n++; - } + while (n < max_match && in[i+n] == in[p+n]) n++; if (n > m->len) { m->len = n, m->off = p - i; - if (n == max_match) - break; + if (n == max_match) break; } } if (!(--chain_len)) break; - i = s->prv[i & SDEFL_WIN_MSK]; + i = s->prv[i&SDEFL_WIN_MSK]; } } static int @@ -669,20 +588,19 @@ sdefl_compr(struct sdefl *s, unsigned char *out, const unsigned char *in, for (n = 0; n < SDEFL_HASH_SIZ; ++n) { s->tbl[n] = SDEFL_NIL; } - do {int blk_begin = i; - int blk_end = ((i + SDEFL_BLK_MAX) < in_len) ? (i + SDEFL_BLK_MAX) : in_len; + do {int blk_end = ((i + SDEFL_BLK_MAX) < in_len) ? (i + SDEFL_BLK_MAX) : in_len; while (i < blk_end) { struct sdefl_match m = {0}; int left = blk_end - i; - int max_match = (left > SDEFL_MAX_MATCH) ? SDEFL_MAX_MATCH : left; + int max_match = (left >= SDEFL_MAX_MATCH) ? SDEFL_MAX_MATCH : left; int nice_match = pref[lvl] < max_match ? pref[lvl] : max_match; int run = 1, inc = 1, run_inc = 0; if (max_match > SDEFL_MIN_MATCH) { - sdefl_fnd(&m, s, max_chain, max_match, in, i, in_len); + sdefl_fnd(&m, s, max_chain, max_match, in, i); } - if (lvl >= 5 && m.len >= SDEFL_MIN_MATCH && m.len + 1 < nice_match){ + if (lvl >= 5 && m.len >= SDEFL_MIN_MATCH && m.len < nice_match){ struct sdefl_match m2 = {0}; - sdefl_fnd(&m2, s, max_chain, m.len + 1, in, i + 1, in_len); + sdefl_fnd(&m2, s, max_chain, m.len+1, in, i+1); m.len = (m2.len > m.len) ? 0 : m.len; } if (m.len >= SDEFL_MIN_MATCH) { @@ -718,12 +636,12 @@ sdefl_compr(struct sdefl *s, unsigned char *out, const unsigned char *in, sdefl_seq(s, i - litlen, litlen); litlen = 0; } - sdefl_flush(&q, s, blk_end == in_len, in, blk_begin, blk_end); + sdefl_flush(&q, s, blk_end == in_len, in); } while (i < in_len); - if (s->bitcnt) { + + if (s->bitcnt > 0) sdefl_put(&q, s, 0x00, 8 - s->bitcnt); - } - assert(s->bitcnt == 0); + return (int)(q - out); } extern int @@ -783,8 +701,9 @@ zsdeflate(struct sdefl *s, void *out, const void *in, int n, int lvl) { } extern int sdefl_bound(int len) { - int max_blocks = 1 + sdefl_div_round_up(len, SDEFL_RAW_BLK_SIZE); - int bound = 5 * max_blocks + len + 1 + 4 + 8; - return bound; + int a = 128 + (len * 110) / 100; + int b = 128 + len + ((len / (31 * 1024)) + 1) * 5; + return (a > b) ? a : b; } #endif /* SDEFL_IMPLEMENTATION */ + diff --git a/src/external/sinfl.h b/src/external/sinfl.h index 8979fcd7f..915da9d23 100644 --- a/src/external/sinfl.h +++ b/src/external/sinfl.h @@ -72,7 +72,7 @@ Results on the [Silesia compression corpus](http://sun.aei.polsl.pl/~sdeor/index This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------ ALTERNATIVE A - MIT License -Copyright (c) 2020-2023 Micha Mettke +Copyright (c) 2020 Micha Mettke 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 @@ -400,21 +400,17 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size) } break; case stored: { /* uncompressed block */ - unsigned len, nlen; + int len, nlen; + sinfl_refill(&s); sinfl__get(&s,s.bitcnt & 7); - len = (unsigned short)sinfl__get(&s,16); - nlen = (unsigned short)sinfl__get(&s,16); - s.bitptr -= s.bitcnt / 8; - s.bitbuf = s.bitcnt = 0; + len = sinfl__get(&s,16); + nlen = sinfl__get(&s,16); + in -= 2; s.bitcnt = 0; - if ((unsigned short)len != (unsigned short)~nlen) + if (len > (e-in) || !len) return (int)(out-o); - if (len > (e - s.bitptr) || !len) - return (int)(out-o); - - memcpy(out, s.bitptr, (size_t)len); - s.bitptr += len, out += len; - if (last) return (int)(out-o); + memcpy(out, in, (size_t)len); + in += len, out += len; state = hdr; } break; case fixed: { @@ -447,9 +443,8 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size) /* decode code lengths */ for (n = 0; n < nlit + ndist;) { - int sym = 0; sinfl_refill(&s); - sym = sinfl_decode(&s, hlens, 7); + int sym = sinfl_decode(&s, hlens, 7); switch (sym) {default: lens[n++] = (unsigned char)sym; break; case 16: for (i=3+sinfl_get(&s,2);i;i--,n++) lens[n]=lens[n-1]; break; case 17: for (i=3+sinfl_get(&s,3);i;i--,n++) lens[n]=0; break; @@ -463,9 +458,8 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size) case blk: { /* decompress block */ while (1) { - int sym; sinfl_refill(&s); - sym = sinfl_decode(&s, s.lits, 10); + int sym = sinfl_decode(&s, s.lits, 10); if (sym < 256) { /* literal */ if (sinfl_unlikely(out >= oe)) { From 8096f142ecc9607df6b37a924b56202f8eb31657 Mon Sep 17 00:00:00 2001 From: ubkp <118854183+ubkp@users.noreply.github.com> Date: Wed, 12 Jul 2023 07:02:33 -0300 Subject: [PATCH 29/40] Add a new task the issue template about checking the wiki (#3169) --- .github/ISSUE_TEMPLATE/new-issue-template.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE/new-issue-template.md b/.github/ISSUE_TEMPLATE/new-issue-template.md index 096eb28cb..4bac86e82 100644 --- a/.github/ISSUE_TEMPLATE/new-issue-template.md +++ b/.github/ISSUE_TEMPLATE/new-issue-template.md @@ -21,6 +21,7 @@ Please, before submitting a new issue verify and check: - [ ] I tested it on latest raylib version from master branch - [ ] I checked there is no similar issue already reported + - [ ] I checked the documentation on the [wiki](https://github.com/raysan5/raylib/wiki) - [ ] My code has no errors or misuse of raylib ### Issue description From bc9c06325481c0b4b5a2db3b2a8281465569ba3e Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 12 Jul 2023 15:49:38 +0200 Subject: [PATCH 30/40] Update external sdefl and sinfl --- src/external/sdefl.h | 195 ++++++++++++++++++++++++++++++------------- src/external/sinfl.h | 28 ++++--- 2 files changed, 155 insertions(+), 68 deletions(-) diff --git a/src/external/sdefl.h b/src/external/sdefl.h index 56539a56e..36015b95b 100644 --- a/src/external/sdefl.h +++ b/src/external/sdefl.h @@ -71,7 +71,7 @@ Results on the [Silesia compression corpus](http://sun.aei.polsl.pl/~sdeor/index This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------ ALTERNATIVE A - MIT License -Copyright (c) 2020 Micha Mettke +Copyright (c) 2020-2023 Micha Mettke 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 @@ -125,7 +125,7 @@ extern "C" { #define SDEFL_MIN_MATCH 4 #define SDEFL_BLK_MAX (256*1024) -#define SDEFL_SEQ_SIZ ((SDEFL_BLK_MAX + SDEFL_MIN_MATCH)/SDEFL_MIN_MATCH) +#define SDEFL_SEQ_SIZ ((SDEFL_BLK_MAX+2)/3) #define SDEFL_SYM_MAX (288) #define SDEFL_OFF_MAX (32) @@ -185,6 +185,7 @@ extern int zsdeflate(struct sdefl *s, void *o, const void *i, int n, int lvl); #define SDEFL_MAX_CODE_LEN (15) #define SDEFL_SYM_BITS (10u) #define SDEFL_SYM_MSK ((1u << SDEFL_SYM_BITS)-1u) +#define SDEFL_RAW_BLK_SIZE (65535) #define SDEFL_LIT_LEN_CODES (14) #define SDEFL_OFF_CODES (15) #define SDEFL_PRE_CODES (7) @@ -192,6 +193,7 @@ extern int zsdeflate(struct sdefl *s, void *o, const void *i, int n, int lvl); #define SDEFL_EOB (256) #define sdefl_npow2(n) (1 << (sdefl_ilog2((n)-1) + 1)) +#define sdefl_div_round_up(n,d) (((n)+((d)-1))/(d)) static int sdefl_ilog2(int n) { @@ -438,12 +440,12 @@ sdefl_precode(struct sdefl_symcnt *cnt, unsigned *freqs, unsigned *items, } while (run_start != total); cnt->items = (int)(at - items); } -struct sdefl_match_codes { +struct sdefl_match_codest { int ls, lc; int dc, dx; }; static void -sdefl_match_codes(struct sdefl_match_codes *cod, int dist, int len) { +sdefl_match_codes(struct sdefl_match_codest *cod, int dist, int len) { static const short dxmax[] = {0,6,12,24,48,96,192,384,768,1536,3072,6144,12288,24576}; static const unsigned char lslot[258+1] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, @@ -471,6 +473,44 @@ sdefl_match_codes(struct sdefl_match_codes *cod, int dist, int len) { cod->dx = sdefl_ilog2(sdefl_npow2(dist) >> 2); cod->dc = cod->dx ? ((cod->dx + 1) << 1) + (dist > dxmax[cod->dx]) : dist-1; } +enum sdefl_blk_type { + SDEFL_BLK_UCOMPR, + SDEFL_BLK_DYN +}; +static enum sdefl_blk_type +sdefl_blk_type(const struct sdefl *s, int blk_len, int pre_item_len, + const unsigned *pre_freq, const unsigned char *pre_len) { + static const unsigned char x_pre_bits[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; + static const unsigned char x_len_bits[] = {0,0,0,0,0,0,0,0, 1,1,1,1,2,2,2,2, + 3,3,3,3,4,4,4,4, 5,5,5,5,0}; + static const unsigned char x_off_bits[] = {0,0,0,0,1,1,2,2, 3,3,4,4,5,5,6,6, + 7,7,8,8,9,9,10,10, 11,11,12,12,13,13}; + + int dyn_cost = 0; + int fix_cost = 0; + int sym = 0; + + dyn_cost += 5 + 5 + 4 + (3 * pre_item_len); + for (sym = 0; sym < SDEFL_PRE_MAX; sym++) + dyn_cost += pre_freq[sym] * (x_pre_bits[sym] + pre_len[sym]); + for (sym = 0; sym < 256; sym++) + dyn_cost += s->freq.lit[sym] * s->cod.len.lit[sym]; + dyn_cost += s->cod.len.lit[SDEFL_EOB]; + for (sym = 257; sym < 286; sym++) + dyn_cost += s->freq.lit[sym] * (x_len_bits[sym - 257] + s->cod.len.lit[sym]); + for (sym = 0; sym < 30; sym++) + dyn_cost += s->freq.off[sym] * (x_off_bits[sym] + s->cod.len.off[sym]); + + fix_cost += 8*(5 * sdefl_div_round_up(blk_len, SDEFL_RAW_BLK_SIZE) + blk_len + 1 + 2); + return (dyn_cost < fix_cost) ? SDEFL_BLK_DYN : SDEFL_BLK_UCOMPR; +} +static void +sdefl_put16(unsigned char **dst, unsigned short x) { + unsigned char *val = *dst; + val[0] = (unsigned char)(x & 0xff); + val[1] = (unsigned char)(x >> 8); + *dst = val + 2; +} static void sdefl_match(unsigned char **dst, struct sdefl *s, int dist, int len) { static const char lxn[] = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; @@ -479,7 +519,7 @@ sdefl_match(unsigned char **dst, struct sdefl *s, int dist, int len) { static const short dmin[] = {1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257, 385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577}; - struct sdefl_match_codes cod; + struct sdefl_match_codest cod; sdefl_match_codes(&cod, dist, len); sdefl_put(dst, s, (int)s->cod.word.lit[cod.lc], s->cod.len.lit[cod.lc]); sdefl_put(dst, s, len - lmin[cod.ls], lxn[cod.ls]); @@ -488,7 +528,8 @@ sdefl_match(unsigned char **dst, struct sdefl *s, int dist, int len) { } static void sdefl_flush(unsigned char **dst, struct sdefl *s, int is_last, - const unsigned char *in) { + const unsigned char *in, int blk_begin, int blk_end) { + int blk_len = blk_end - blk_begin; int j, i = 0, item_cnt = 0; struct sdefl_symcnt symcnt = {0}; unsigned codes[SDEFL_PRE_MAX]; @@ -498,7 +539,7 @@ sdefl_flush(unsigned char **dst, struct sdefl *s, int is_last, static const unsigned char perm[SDEFL_PRE_MAX] = {16,17,18,0,8,7,9,6,10,5,11, 4,12,3,13,2,14,1,15}; - /* huffman codes */ + /* calculate huffman codes */ s->freq.lit[SDEFL_EOB]++; sdefl_huff(s->cod.len.lit, s->cod.word.lit, s->freq.lit, SDEFL_SYM_MAX, SDEFL_LIT_LEN_CODES); sdefl_huff(s->cod.len.off, s->cod.word.off, s->freq.off, SDEFL_OFF_MAX, SDEFL_OFF_CODES); @@ -509,35 +550,58 @@ sdefl_flush(unsigned char **dst, struct sdefl *s, int is_last, break; } } - /* block header */ - sdefl_put(dst, s, is_last ? 0x01 : 0x00, 1); /* block */ - sdefl_put(dst, s, 0x02, 2); /* dynamic huffman */ - sdefl_put(dst, s, symcnt.lit - 257, 5); - sdefl_put(dst, s, symcnt.off - 1, 5); - sdefl_put(dst, s, item_cnt - 4, 4); - for (i = 0; i < item_cnt; ++i) { - sdefl_put(dst, s, lens[perm[i]], 3); - } - for (i = 0; i < symcnt.items; ++i) { - unsigned sym = items[i] & 0x1F; - sdefl_put(dst, s, (int)codes[sym], lens[sym]); - if (sym < 16) continue; - if (sym == 16) sdefl_put(dst, s, items[i] >> 5, 2); - else if(sym == 17) sdefl_put(dst, s, items[i] >> 5, 3); - else sdefl_put(dst, s, items[i] >> 5, 7); - } - /* block sequences */ - for (i = 0; i < s->seq_cnt; ++i) { - if (s->seq[i].off >= 0) { - for (j = 0; j < s->seq[i].len; ++j) { - int c = in[s->seq[i].off + j]; - sdefl_put(dst, s, (int)s->cod.word.lit[c], s->cod.len.lit[c]); + /* write block */ + switch (sdefl_blk_type(s, blk_len, item_cnt, freqs, lens)) { + case SDEFL_BLK_UCOMPR: { + /* uncompressed blocks */ + int n = sdefl_div_round_up(blk_len, SDEFL_RAW_BLK_SIZE); + for (i = 0; i < n; ++i) { + int fin = is_last && (i + 1 == n); + int amount = blk_len < SDEFL_RAW_BLK_SIZE ? blk_len : SDEFL_RAW_BLK_SIZE; + sdefl_put(dst, s, !!fin, 1); /* block */ + sdefl_put(dst, s, 0x00, 2); /* stored block */ + if (s->bitcnt) { + sdefl_put(dst, s, 0x00, 8 - s->bitcnt); } - } else { - sdefl_match(dst, s, -s->seq[i].off, s->seq[i].len); + assert(s->bitcnt == 0); + sdefl_put16(dst, (unsigned short)amount); + sdefl_put16(dst, ~(unsigned short)amount); + memcpy(*dst, in + blk_begin + i * SDEFL_RAW_BLK_SIZE, amount); + *dst = *dst + amount; + blk_len -= amount; } - } - sdefl_put(dst, s, (int)(s)->cod.word.lit[SDEFL_EOB], (s)->cod.len.lit[SDEFL_EOB]); + } break; + case SDEFL_BLK_DYN: { + /* dynamic huffman block */ + sdefl_put(dst, s, !!is_last, 1); /* block */ + sdefl_put(dst, s, 0x02, 2); /* dynamic huffman */ + sdefl_put(dst, s, symcnt.lit - 257, 5); + sdefl_put(dst, s, symcnt.off - 1, 5); + sdefl_put(dst, s, item_cnt - 4, 4); + for (i = 0; i < item_cnt; ++i) { + sdefl_put(dst, s, lens[perm[i]], 3); + } + for (i = 0; i < symcnt.items; ++i) { + unsigned sym = items[i] & 0x1F; + sdefl_put(dst, s, (int)codes[sym], lens[sym]); + if (sym < 16) continue; + if (sym == 16) sdefl_put(dst, s, items[i] >> 5, 2); + else if(sym == 17) sdefl_put(dst, s, items[i] >> 5, 3); + else sdefl_put(dst, s, items[i] >> 5, 7); + } + /* block sequences */ + for (i = 0; i < s->seq_cnt; ++i) { + if (s->seq[i].off >= 0) { + for (j = 0; j < s->seq[i].len; ++j) { + int c = in[s->seq[i].off + j]; + sdefl_put(dst, s, (int)s->cod.word.lit[c], s->cod.len.lit[c]); + } + } else { + sdefl_match(dst, s, -s->seq[i].off, s->seq[i].len); + } + } + sdefl_put(dst, s, (int)(s)->cod.word.lit[SDEFL_EOB], (s)->cod.len.lit[SDEFL_EOB]); + } break;} memset(&s->freq, 0, sizeof(s->freq)); s->seq_cnt = 0; } @@ -550,8 +614,12 @@ sdefl_seq(struct sdefl *s, int off, int len) { } static void sdefl_reg_match(struct sdefl *s, int off, int len) { - struct sdefl_match_codes cod; + struct sdefl_match_codest cod; sdefl_match_codes(&cod, off, len); + + assert(cod.lc < SDEFL_SYM_MAX); + assert(cod.dc < SDEFL_OFF_MAX); + s->freq.lit[cod.lc]++; s->freq.off[cod.dc]++; } @@ -560,22 +628,35 @@ struct sdefl_match { int len; }; static void -sdefl_fnd(struct sdefl_match *m, const struct sdefl *s, - int chain_len, int max_match, const unsigned char *in, int p) { - int i = s->tbl[sdefl_hash32(&in[p])]; - int limit = ((p-SDEFL_WIN_SIZ)tbl[sdefl_hash32(in + p)]; + int limit = ((p - SDEFL_WIN_SIZ) < SDEFL_NIL) ? SDEFL_NIL : (p-SDEFL_WIN_SIZ); + + assert(p < e); + assert(p + max_match <= e); while (i > limit) { - if (in[i+m->len] == in[p+m->len] && - (sdefl_uload32(&in[i]) == sdefl_uload32(&in[p]))){ + assert(i + m->len < e); + assert(p + m->len < e); + assert(i + SDEFL_MIN_MATCH < e); + assert(p + SDEFL_MIN_MATCH < e); + + if (in[i + m->len] == in[p + m->len] && + (sdefl_uload32(&in[i]) == sdefl_uload32(&in[p]))) { int n = SDEFL_MIN_MATCH; - while (n < max_match && in[i+n] == in[p+n]) n++; + while (n < max_match && in[i + n] == in[p + n]) { + assert(i + n < e); + assert(p + n < e); + n++; + } if (n > m->len) { m->len = n, m->off = p - i; - if (n == max_match) break; + if (n == max_match) + break; } } if (!(--chain_len)) break; - i = s->prv[i&SDEFL_WIN_MSK]; + i = s->prv[i & SDEFL_WIN_MSK]; } } static int @@ -588,19 +669,20 @@ sdefl_compr(struct sdefl *s, unsigned char *out, const unsigned char *in, for (n = 0; n < SDEFL_HASH_SIZ; ++n) { s->tbl[n] = SDEFL_NIL; } - do {int blk_end = ((i + SDEFL_BLK_MAX) < in_len) ? (i + SDEFL_BLK_MAX) : in_len; + do {int blk_begin = i; + int blk_end = ((i + SDEFL_BLK_MAX) < in_len) ? (i + SDEFL_BLK_MAX) : in_len; while (i < blk_end) { struct sdefl_match m = {0}; int left = blk_end - i; - int max_match = (left >= SDEFL_MAX_MATCH) ? SDEFL_MAX_MATCH : left; + int max_match = (left > SDEFL_MAX_MATCH) ? SDEFL_MAX_MATCH : left; int nice_match = pref[lvl] < max_match ? pref[lvl] : max_match; int run = 1, inc = 1, run_inc = 0; if (max_match > SDEFL_MIN_MATCH) { - sdefl_fnd(&m, s, max_chain, max_match, in, i); + sdefl_fnd(&m, s, max_chain, max_match, in, i, in_len); } - if (lvl >= 5 && m.len >= SDEFL_MIN_MATCH && m.len < nice_match){ + if (lvl >= 5 && m.len >= SDEFL_MIN_MATCH && m.len + 1 < nice_match){ struct sdefl_match m2 = {0}; - sdefl_fnd(&m2, s, max_chain, m.len+1, in, i+1); + sdefl_fnd(&m2, s, max_chain, m.len + 1, in, i + 1, in_len); m.len = (m2.len > m.len) ? 0 : m.len; } if (m.len >= SDEFL_MIN_MATCH) { @@ -636,12 +718,12 @@ sdefl_compr(struct sdefl *s, unsigned char *out, const unsigned char *in, sdefl_seq(s, i - litlen, litlen); litlen = 0; } - sdefl_flush(&q, s, blk_end == in_len, in); + sdefl_flush(&q, s, blk_end == in_len, in, blk_begin, blk_end); } while (i < in_len); - - if (s->bitcnt > 0) + if (s->bitcnt) { sdefl_put(&q, s, 0x00, 8 - s->bitcnt); - + } + assert(s->bitcnt == 0); return (int)(q - out); } extern int @@ -701,9 +783,8 @@ zsdeflate(struct sdefl *s, void *out, const void *in, int n, int lvl) { } extern int sdefl_bound(int len) { - int a = 128 + (len * 110) / 100; - int b = 128 + len + ((len / (31 * 1024)) + 1) * 5; - return (a > b) ? a : b; + int max_blocks = 1 + sdefl_div_round_up(len, SDEFL_RAW_BLK_SIZE); + int bound = 5 * max_blocks + len + 1 + 4 + 8; + return bound; } #endif /* SDEFL_IMPLEMENTATION */ - diff --git a/src/external/sinfl.h b/src/external/sinfl.h index 915da9d23..8979fcd7f 100644 --- a/src/external/sinfl.h +++ b/src/external/sinfl.h @@ -72,7 +72,7 @@ Results on the [Silesia compression corpus](http://sun.aei.polsl.pl/~sdeor/index This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------ ALTERNATIVE A - MIT License -Copyright (c) 2020 Micha Mettke +Copyright (c) 2020-2023 Micha Mettke 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 @@ -400,17 +400,21 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size) } break; case stored: { /* uncompressed block */ - int len, nlen; - sinfl_refill(&s); + unsigned len, nlen; sinfl__get(&s,s.bitcnt & 7); - len = sinfl__get(&s,16); - nlen = sinfl__get(&s,16); - in -= 2; s.bitcnt = 0; + len = (unsigned short)sinfl__get(&s,16); + nlen = (unsigned short)sinfl__get(&s,16); + s.bitptr -= s.bitcnt / 8; + s.bitbuf = s.bitcnt = 0; - if (len > (e-in) || !len) + if ((unsigned short)len != (unsigned short)~nlen) return (int)(out-o); - memcpy(out, in, (size_t)len); - in += len, out += len; + if (len > (e - s.bitptr) || !len) + return (int)(out-o); + + memcpy(out, s.bitptr, (size_t)len); + s.bitptr += len, out += len; + if (last) return (int)(out-o); state = hdr; } break; case fixed: { @@ -443,8 +447,9 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size) /* decode code lengths */ for (n = 0; n < nlit + ndist;) { + int sym = 0; sinfl_refill(&s); - int sym = sinfl_decode(&s, hlens, 7); + sym = sinfl_decode(&s, hlens, 7); switch (sym) {default: lens[n++] = (unsigned char)sym; break; case 16: for (i=3+sinfl_get(&s,2);i;i--,n++) lens[n]=lens[n-1]; break; case 17: for (i=3+sinfl_get(&s,3);i;i--,n++) lens[n]=0; break; @@ -458,8 +463,9 @@ sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size) case blk: { /* decompress block */ while (1) { + int sym; sinfl_refill(&s); - int sym = sinfl_decode(&s, s.lits, 10); + sym = sinfl_decode(&s, s.lits, 10); if (sym < 256) { /* literal */ if (sinfl_unlikely(out >= oe)) { From 22895ba14fab982ca74ec1526b48b924d1174e60 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 14 Jul 2023 03:20:06 +0800 Subject: [PATCH 31/40] fix: cmake option "OPENGL_VERSION" doesn't work (#3170) --- cmake/LibraryConfigurations.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/LibraryConfigurations.cmake b/cmake/LibraryConfigurations.cmake index e9eee630a..d12df3a00 100644 --- a/cmake/LibraryConfigurations.cmake +++ b/cmake/LibraryConfigurations.cmake @@ -106,7 +106,7 @@ elseif ("${PLATFORM}" MATCHES "DRM") endif () -if (NOT ${OPENGL_VERSION}) +if (NOT ${OPENGL_VERSION} MATCHES "OFF") set(${SUGGESTED_GRAPHICS} "${GRAPHICS}") if (${OPENGL_VERSION} MATCHES "4.3") set(GRAPHICS "GRAPHICS_API_OPENGL_43") From b980268ba7fd1fb5083546ca3f0b20f3390fe128 Mon Sep 17 00:00:00 2001 From: ubkp <118854183+ubkp@users.noreply.github.com> Date: Sun, 16 Jul 2023 08:07:29 -0300 Subject: [PATCH 32/40] [example] Core Input Gestures for Web (#3172) * [example] Core Input Gestures for Web * Fix Doubletap for web * Changes TAP_TIMEOUT and rgGetCurrentTime to seconds --- examples/Makefile | 1 + examples/Makefile.Web | 26 +- examples/core/core_input_gestures_web.c | 330 ++++++++++++++++++++++ examples/core/core_input_gestures_web.png | Bin 0 -> 8937 bytes src/rcore.c | 6 + src/rgestures.h | 16 +- 6 files changed, 360 insertions(+), 19 deletions(-) create mode 100644 examples/core/core_input_gestures_web.c create mode 100644 examples/core/core_input_gestures_web.png diff --git a/examples/Makefile b/examples/Makefile index 15edf1b36..1a4d5f06c 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -405,6 +405,7 @@ CORE = \ core/core_input_gamepad \ core/core_input_multitouch \ core/core_input_gestures \ + core/core_input_gestures_web \ core/core_2d_camera \ core/core_2d_camera_platformer \ core/core_2d_camera_mouse_zoom \ diff --git a/examples/Makefile.Web b/examples/Makefile.Web index 499eb3eaa..e65351e07 100644 --- a/examples/Makefile.Web +++ b/examples/Makefile.Web @@ -386,6 +386,7 @@ CORE = \ core/core_input_gamepad \ core/core_input_multitouch \ core/core_input_gestures \ + core/core_input_gestures_web \ core/core_2d_camera \ core/core_2d_camera_platformer \ core/core_2d_camera_mouse_zoom \ @@ -558,12 +559,15 @@ core/core_input_multitouch: core/core_input_multitouch.c core/core_input_gestures: core/core_input_gestures.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) +core/core_input_gestures_web: core/core_input_gestures_web.c + $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) + core/core_2d_camera: core/core_2d_camera.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) core/core_2d_camera_platformer: core/core_2d_camera_platformer.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) - + core/core_2d_camera_mouse_zoom: core/core_2d_camera_mouse_zoom.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) @@ -618,10 +622,10 @@ core/core_custom_frame_control: core/core_custom_frame_control.c core/core_window_should_close: core/core_window_should_close.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) - + # NOTE: To use multi-threading raylib must be compiled with multi-theading support (-s USE_PTHREADS=1) # WARNING: For security reasons multi-threading is not supported on browsers, it requires cross-origin isolation (Oct.2021) -# WARNING: It requires raylib to be compiled using -pthread, so atomic operations and thread-local data (if any) +# WARNING: It requires raylib to be compiled using -pthread, so atomic operations and thread-local data (if any) # in its source were transformed to non-atomic operations and non-thread-local data core/core_loading_thread: core/core_loading_thread.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -s USE_PTHREADS=1 @@ -745,7 +749,7 @@ textures/textures_sprite_explosion: textures/textures_sprite_explosion.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \ --preload-file textures/resources/explosion.png@resources/explosion.png \ --preload-file textures/resources/boom.wav@resources/boom.wav - + textures/textures_textured_curve: textures/textures_textured_curve.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \ --preload-file textures/resources/road.png@resources/road.png @@ -857,8 +861,8 @@ models/models_cubicmap: models/models_cubicmap.c models/models_draw_cube_texture: models/models_draw_cube_texture.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \ - --preload-file models/resources/cubicmap_atlas.png@resources/cubicmap_atlas.png - + --preload-file models/resources/cubicmap_atlas.png@resources/cubicmap_atlas.png + models/models_first_person_maze: models/models_first_person_maze.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \ --preload-file models/resources/cubicmap.png@resources/cubicmap.png \ @@ -889,7 +893,7 @@ models/models_loading_vox: models/models_loading_vox.c models/models_loading_gltf: models/models_loading_gltf.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -s TOTAL_MEMORY=67108864 \ --preload-file models/resources/models/gltf/robot.glb@resources/models/gltf/robot.glb - + models/models_loading_m3d: models/models_loading_m3d.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -s TOTAL_MEMORY=67108864 \ --preload-file models/resources/models/m3d/cesium_man.m3d@resources/models/m3d/cesium_man.m3d @@ -1010,16 +1014,16 @@ shaders/shaders_texture_outline: shaders/shaders_texture_outline.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \ --preload-file shaders/resources/shaders/glsl100/outline.fs@resources/shaders/glsl100/outline.fs \ --preload-file shaders/resources/fudesumi.png@resources/fudesumi.png - + shaders/shaders_write_depth: shaders/shaders_write_depth.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \ --preload-file shaders/resources/shaders/glsl100/write_depth.fs@resources/shaders/glsl100/write_depth.fs - + shaders/shaders_hybrid_render: shaders/shaders_hybrid_render.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \ --preload-file shaders/resources/shaders/glsl100/hybrid_raymarch.fs@resources/shaders/glsl100/hybrid_raymarch.fs \ --preload-file shaders/resources/shaders/glsl100/hybrid_raster.fs@resources/shaders/glsl100/hybrid_raster.fs - + # Compile AUDIO examples audio/audio_module_playing: audio/audio_module_playing.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \ @@ -1040,7 +1044,7 @@ audio/audio_sound_loading: audio/audio_sound_loading.c audio/audio_stream_effects: audio/audio_stream_effects.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -s TOTAL_MEMORY=67108864 \ --preload-file audio/resources/country.mp3@resources/country.mp3 - + audio/audio_mixed_processor: audio/audio_mixed_processor.c $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) -s TOTAL_MEMORY=67108864 \ --preload-file audio/resources/country.mp3@resources/country.mp3 \ diff --git a/examples/core/core_input_gestures_web.c b/examples/core/core_input_gestures_web.c new file mode 100644 index 000000000..0ee3d1c5e --- /dev/null +++ b/examples/core/core_input_gestures_web.c @@ -0,0 +1,330 @@ +/******************************************************************************************* +* +* raylib [core] example - Input Gestures for Web +* +* Example originally created with raylib 4.6-dev, last time updated with raylib 4.6-dev +* +* Example contributed by ubkp (@ubkp) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2023 ubkp (@ubkp) +* +********************************************************************************************/ + +#include "raylib.h" +#include "math.h" // Required for the protractor angle graphic drawing + +#if defined(PLATFORM_WEB) + #include // Required for the Web/HTML5 +#endif + +//-------------------------------------------------------------------------------------- +// Global definitions and declarations +//-------------------------------------------------------------------------------------- + +// Common variables definitions +//-------------------------------------------------------------------------------------- +int screenWidth = 800; +const int screenHeight = 450; +Vector2 messagePosition = {160, 7}; + +// Last gesture variables definitions +//-------------------------------------------------------------------------------------- +int lastGesture = 0; +Vector2 lastGesturePosition = {165, 130}; + +// Gesture log variables definitions and functions declarations +//-------------------------------------------------------------------------------------- +#define GESTURE_LOG_SIZE 20 +char gestureLog[GESTURE_LOG_SIZE][12] = { "" }; // The gesture log uses an array (as an inverted circular queue) to store the performed gestures +int gestureLogIndex = GESTURE_LOG_SIZE; // The index for the inverted circular queue (moving from last to first direction, then looping around) +int previousGesture = 0; +char const *GetGestureName(int i) +{ + switch (i) { + case 0: return "None"; break; + case 1: return "Tap"; break; + case 2: return "Double Tap"; break; + case 4: return "Hold"; break; + case 8: return "Drag"; break; + case 16: return "Swipe Right"; break; + case 32: return "Swipe Left"; break; + case 64: return "Swipe Up"; break; + case 128: return "Swipe Down"; break; + case 256: return "Pinch In"; break; + case 512: return "Pinch Out"; break; + default: return "Unknown"; break; + } +} +Color GetGestureColor(int i) +{ + switch (i) { + case 0: return BLACK; break; + case 1: return BLUE; break; + case 2: return SKYBLUE; break; + case 4: return BLACK; break; + case 8: return LIME; break; + case 16: return RED; break; + case 32: return RED; break; + case 64: return RED; break; + case 128: return RED; break; + case 256: return VIOLET; break; + case 512: return ORANGE; break; + default: return BLACK; break; + } +} +Color gestureColor = BLACK; +int logMode = 1; // Log mode values: 0 shows repeated events; 1 hides repeated events; 2 shows repeated events but hide hold events; 3 hides repeated events and hide hold events +Rectangle logButton1 = {53, 7, 48, 26}; +Rectangle logButton2 = {108, 7, 36, 26}; +Vector2 gestureLogPosition = {10, 10}; + +// Protractor variables definitions +//-------------------------------------------------------------------------------------- +float angleLength = 90.0f; +float currentAngleDegrees = 0.0f; +Vector2 finalVector = {0.0f, 0.0f}; +char currentAngleStr[7] = ""; +Vector2 protractorPosition = {266.0f, 315.0f}; + +// Update +//-------------------------------------------------------------------------------------- +void Update(void) +{ + // Handle common + //-------------------------------------------------------------------------------------- + int i, ii; // Iterators that will be reused by all for loops + const int currentGesture = GetGestureDetected(); + const float currentDragDegrees = GetGestureDragAngle(); + const float currentPitchDegrees = GetGesturePinchAngle(); + const int touchCount = GetTouchPointCount(); + + // Handle last gesture + //-------------------------------------------------------------------------------------- + if ( currentGesture != 0 && currentGesture != 4 && currentGesture != previousGesture ) lastGesture = currentGesture; // Filter the meaningful gestures (1, 2, 8 to 512) for the display + + // Handle gesture log + //-------------------------------------------------------------------------------------- + if ( IsMouseButtonReleased(MOUSE_BUTTON_LEFT) ) + { + if ( CheckCollisionPointRec(GetMousePosition(), logButton1 ) ) + { + switch (logMode) + { + case 3: logMode=2; break; + case 2: logMode=3; break; + case 1: logMode=0; break; + default: logMode=1; break; + } + } + else if ( CheckCollisionPointRec(GetMousePosition(), logButton2) ) + { + switch (logMode) + { + case 3: logMode=1; break; + case 2: logMode=0; break; + case 1: logMode=3; break; + default: logMode=2; break; + } + } + } + int fillLog = 0; // Gate variable to be used to allow or not the gesture log to be filled + if (currentGesture !=0) + { + if (logMode == 3) // 3 hides repeated events and hide hold events + { + if ( ( currentGesture != 4 && currentGesture != previousGesture ) || currentGesture < 3 ) fillLog = 1; + } + else if (logMode == 2) // 2 shows repeated events but hide hold events + { + if (currentGesture != 4) fillLog = 1; + } + else if (logMode == 1) // 1 hides repeated events + { + if (currentGesture != previousGesture) fillLog = 1; + } + else // 0 shows repeated events + { + fillLog = 1; + } + } + if (fillLog) // If one of the conditions from logMode was met, fill the gesture log + { + previousGesture = currentGesture; + gestureColor = GetGestureColor(currentGesture); + if (gestureLogIndex <= 0) gestureLogIndex = GESTURE_LOG_SIZE; + gestureLogIndex--; + TextCopy( gestureLog[gestureLogIndex], GetGestureName(currentGesture) ); // Copy the gesture respective name to the gesture log array + } + + // Handle protractor + //-------------------------------------------------------------------------------------- + if (currentGesture > 255) // aka Pinch In and Pinch Out + { + currentAngleDegrees = currentPitchDegrees; + } + else if (currentGesture > 15) // aka Swipe Right, Swipe Left, Swipe Up and Swipe Down + { + currentAngleDegrees = currentDragDegrees; + } + else if (currentGesture > 0) // aka Tap, Doubletap, Hold and Grab + { + currentAngleDegrees = 0.0f; + } + float currentAngleRadians = ( (currentAngleDegrees +90.0f)*PI/180 ); // Convert the current angle to Radians + finalVector = (Vector2){ ( angleLength*sinf(currentAngleRadians) ) + protractorPosition.x, ( angleLength*cosf(currentAngleRadians) ) + protractorPosition.y }; // Calculate the final vector for display + + // Handle touch and mouse pointer points + //-------------------------------------------------------------------------------------- + Vector2 touchPosition[touchCount]; + Vector2 mousePosition = {0, 0}; + if (currentGesture != GESTURE_NONE) + { + if (touchCount != 0) + { + for (i = 0; i < touchCount; i++) touchPosition[i] = GetTouchPosition(i); // Fill the touch positions + } + else + { + mousePosition = GetMousePosition(); + } + } + + // Draw + //-------------------------------------------------------------------------------------- + BeginDrawing(); + ClearBackground(RAYWHITE); + + // Draw common + //-------------------------------------------------------------------------------------- + DrawText("*", messagePosition.x + 5, messagePosition.y + 5, 10, BLACK); + DrawText("Example optimized for Web/HTML5\non Smartphones with Touch Screen.", messagePosition.x + 15, messagePosition.y + 5, 10, BLACK); + DrawText("*", messagePosition.x + 5, messagePosition.y + 35, 10, BLACK); + DrawText("While running on Desktop Web Browsers,\ninspect and turn on Touch Emulation.", messagePosition.x + 15, messagePosition.y + 35, 10, BLACK); + + // Draw last gesture + //-------------------------------------------------------------------------------------- + DrawText("Last gesture", lastGesturePosition.x + 33, lastGesturePosition.y - 47, 20, BLACK); + DrawText("Swipe Tap Pinch Touch", lastGesturePosition.x + 17, lastGesturePosition.y - 18, 10, BLACK); + DrawRectangle(lastGesturePosition.x + 20, lastGesturePosition.y, 20, 20, lastGesture == GESTURE_SWIPE_UP ? RED : LIGHTGRAY); + DrawRectangle(lastGesturePosition.x, lastGesturePosition.y + 20, 20, 20, lastGesture == GESTURE_SWIPE_LEFT ? RED : LIGHTGRAY); + DrawRectangle(lastGesturePosition.x + 40, lastGesturePosition.y + 20, 20, 20, lastGesture == GESTURE_SWIPE_RIGHT ? RED : LIGHTGRAY); + DrawRectangle(lastGesturePosition.x + 20, lastGesturePosition.y + 40, 20, 20, lastGesture == GESTURE_SWIPE_DOWN ? RED : LIGHTGRAY); + DrawCircle(lastGesturePosition.x + 80, lastGesturePosition.y + 16, 10, lastGesture == GESTURE_TAP ? BLUE : LIGHTGRAY); + DrawRing( (Vector2){lastGesturePosition.x + 103, lastGesturePosition.y + 16}, 6.0f, 11.0f, 0.0f, 360.0f, 0, lastGesture == GESTURE_DRAG ? LIME : LIGHTGRAY); + DrawCircle(lastGesturePosition.x + 80, lastGesturePosition.y + 43, 10, lastGesture == GESTURE_DOUBLETAP ? SKYBLUE : LIGHTGRAY); + DrawCircle(lastGesturePosition.x + 103, lastGesturePosition.y + 43, 10, lastGesture == GESTURE_DOUBLETAP ? SKYBLUE : LIGHTGRAY); + DrawTriangle( (Vector2){lastGesturePosition.x + 122, lastGesturePosition.y + 16}, (Vector2){lastGesturePosition.x + 137, lastGesturePosition.y + 26}, (Vector2){lastGesturePosition.x + 137, lastGesturePosition.y + 6}, lastGesture == GESTURE_PINCH_OUT ? ORANGE : LIGHTGRAY); + DrawTriangle( (Vector2){lastGesturePosition.x + 147, lastGesturePosition.y + 6}, (Vector2){lastGesturePosition.x + 147, lastGesturePosition.y + 26}, (Vector2){lastGesturePosition.x + 162, lastGesturePosition.y + 16}, lastGesture == GESTURE_PINCH_OUT ? ORANGE : LIGHTGRAY); + DrawTriangle( (Vector2){lastGesturePosition.x + 125, lastGesturePosition.y + 33}, (Vector2){lastGesturePosition.x + 125, lastGesturePosition.y + 53}, (Vector2){lastGesturePosition.x + 140, lastGesturePosition.y + 43}, lastGesture == GESTURE_PINCH_IN ? VIOLET : LIGHTGRAY); + DrawTriangle( (Vector2){lastGesturePosition.x + 144, lastGesturePosition.y + 43}, (Vector2){lastGesturePosition.x + 159, lastGesturePosition.y + 53}, (Vector2){lastGesturePosition.x + 159, lastGesturePosition.y + 33}, lastGesture == GESTURE_PINCH_IN ? VIOLET : LIGHTGRAY); + for ( i = 0; i < 4; i++ ) DrawCircle(lastGesturePosition.x + 180, lastGesturePosition.y + 7 + i*15, 5, touchCount <= i ? LIGHTGRAY : gestureColor); + + // Draw gesture log + //-------------------------------------------------------------------------------------- + DrawText("Log", gestureLogPosition.x, gestureLogPosition.y, 20, BLACK); + // Loop in both directions to print the gesture log array in the inverted order (and looping around if the index started somewhere in the middle) + for (i = 0, ii = gestureLogIndex; i < GESTURE_LOG_SIZE; i++, ii = (ii + 1) % GESTURE_LOG_SIZE) DrawText(gestureLog[ii], gestureLogPosition.x, gestureLogPosition.y + 410 - i*20, 20, (i == 0 ? gestureColor : LIGHTGRAY)); + Color logButton1Color, logButton2Color; + switch (logMode) + { + case 3: logButton1Color=MAROON; logButton2Color=MAROON; break; + case 2: logButton1Color=GRAY; logButton2Color=MAROON; break; + case 1: logButton1Color=MAROON; logButton2Color=GRAY; break; + default: logButton1Color=GRAY; logButton2Color=GRAY; break; + } + DrawRectangleRec( logButton1, logButton1Color); + DrawText("Hide", logButton1.x + 7, logButton1.y + 3, 10, WHITE); + DrawText("Repeat", logButton1.x + 7, logButton1.y + 13, 10, WHITE); + DrawRectangleRec( logButton2, logButton2Color); + DrawText("Hide", logButton1.x + 62, logButton1.y + 3, 10, WHITE); + DrawText("Hold", logButton1.x + 62, logButton1.y + 13, 10, WHITE); + + // Draw protractor + //-------------------------------------------------------------------------------------- + DrawText("Angle", protractorPosition.x + 55, protractorPosition.y + 76, 10, BLACK); + const char *angleString = TextFormat("%f", currentAngleDegrees); + const int angleStringDot = TextFindIndex(angleString, "."); + const char *angleStringTrim = TextSubtext(angleString, 0, angleStringDot + 3); + DrawText( angleStringTrim, protractorPosition.x + 55, protractorPosition.y + 92, 20, gestureColor); + DrawCircle(protractorPosition.x, protractorPosition.y, 80.0f, WHITE); + DrawLineEx( (Vector2){protractorPosition.x - 90, protractorPosition.y}, (Vector2){protractorPosition.x + 90, protractorPosition.y}, 3.0f, LIGHTGRAY); + DrawLineEx( (Vector2){protractorPosition.x, protractorPosition.y - 90}, (Vector2){protractorPosition.x, protractorPosition.y + 90}, 3.0f, LIGHTGRAY); + DrawLineEx( (Vector2){protractorPosition.x - 80, protractorPosition.y - 45}, (Vector2){protractorPosition.x + 80, protractorPosition.y + 45}, 3.0f, GREEN); + DrawLineEx( (Vector2){protractorPosition.x - 80, protractorPosition.y + 45}, (Vector2){protractorPosition.x + 80, protractorPosition.y - 45}, 3.0f, GREEN); + DrawText("0", protractorPosition.x + 96, protractorPosition.y - 9, 20, BLACK); + DrawText("30", protractorPosition.x + 74, protractorPosition.y - 68, 20, BLACK); + DrawText("90", protractorPosition.x - 11, protractorPosition.y - 110, 20, BLACK); + DrawText("150", protractorPosition.x - 100, protractorPosition.y - 68, 20, BLACK); + DrawText("180", protractorPosition.x - 124, protractorPosition.y - 9, 20, BLACK); + DrawText("210", protractorPosition.x - 100, protractorPosition.y + 50, 20, BLACK); + DrawText("270", protractorPosition.x - 18, protractorPosition.y + 92, 20, BLACK); + DrawText("330", protractorPosition.x + 72, protractorPosition.y + 50, 20, BLACK); + if ( currentAngleDegrees != 0.0f ) DrawLineEx( protractorPosition, finalVector, 3.0f, gestureColor); + + // Draw touch and mouse pointer points + //-------------------------------------------------------------------------------------- + if (currentGesture != GESTURE_NONE) + { + if ( touchCount != 0 ) + { + for (i = 0; i < touchCount; i++) + { + DrawCircleV(touchPosition[i], 50.0f, Fade(gestureColor, 0.5f)); + DrawCircleV(touchPosition[i], 5.0f, gestureColor); + } + if (touchCount == 2) DrawLineEx( touchPosition[0], touchPosition[1], (currentGesture == 512 ? 8 : 12), gestureColor); + } + else + { + DrawCircleV(mousePosition, 35.0f, Fade(gestureColor, 0.5f)); + DrawCircleV(mousePosition, 5.0f, gestureColor); + } + } + + EndDrawing(); + //-------------------------------------------------------------------------------------- + +} + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + #if defined( PLATFORM_WEB ) + const int canvasWidth = EM_ASM_INT( return document.getElementById('canvas').getBoundingClientRect().width; ); // Using Emscripten EM_ASM_INT macro, get the page canvas width + if (canvasWidth > 400) + { + screenWidth = canvasWidth; + } + else + { + screenWidth = 400; // Set a minimum width for the screen + } + #endif + + InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures web"); + //-------------------------------------------------------------------------------------- + + // Main game loop + //-------------------------------------------------------------------------------------- + #if defined(PLATFORM_WEB) + emscripten_set_main_loop(Update, 0, 1); + #else + SetTargetFPS(60); + while (!WindowShouldClose()) Update(); // Detect window close button or ESC key + #endif + //-------------------------------------------------------------------------------------- + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/core/core_input_gestures_web.png b/examples/core/core_input_gestures_web.png new file mode 100644 index 0000000000000000000000000000000000000000..dd604e84b9c831d32229a8bdefc81d4ae161189a GIT binary patch literal 8937 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 literal 0 HcmV?d00001 diff --git a/src/rcore.c b/src/rcore.c index 6fd7a4fe1..45495bb15 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -5593,8 +5593,14 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int gestureEvent.position[0].y /= (float)GetScreenHeight(); // Gesture data is sent to gestures-system for processing +#if defined(PLATFORM_WEB) + // Prevent calling ProcessGestureEvent() when Emscripten is present and there's a touch gesture, so EmscriptenTouchCallback() can handle it itself + if (GetMouseX() != 0 || GetMouseY() != 0) ProcessGestureEvent(gestureEvent); +#else ProcessGestureEvent(gestureEvent); #endif + +#endif } // GLFW3 Cursor Position Callback, runs on mouse move diff --git a/src/rgestures.h b/src/rgestures.h index 749f440aa..78dde76ee 100644 --- a/src/rgestures.h +++ b/src/rgestures.h @@ -127,7 +127,7 @@ void SetGesturesEnabled(unsigned int flags); // Enable a set of gestu bool IsGestureDetected(int gesture); // Check if a gesture have been detected int GetGestureDetected(void); // Get latest detected gesture -float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds +float GetGestureHoldDuration(void); // Get gesture hold time in seconds Vector2 GetGestureDragVector(void); // Get gesture drag vector float GetGestureDragAngle(void); // Get gesture drag angle Vector2 GetGesturePinchVector(void); // Get gesture pinch delta @@ -181,8 +181,8 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang #define FORCE_TO_SWIPE 0.0005f // Swipe force, measured in normalized screen units/time #define MINIMUM_DRAG 0.015f // Drag minimum force, measured in normalized screen units (0.0f to 1.0f) #define MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f) -#define TAP_TIMEOUT 300 // Tap minimum time, measured in milliseconds -#define PINCH_TIMEOUT 300 // Pinch minimum time, measured in milliseconds +#define TAP_TIMEOUT 0.3f // Tap minimum time, measured in seconds +#define PINCH_TIMEOUT 0.3f // Pinch minimum time, measured in seconds #define DOUBLETAP_RANGE 0.03f // DoubleTap range, measured in normalized screen units (0.0f to 1.0f) //---------------------------------------------------------------------------------- @@ -209,7 +209,7 @@ typedef struct { } Touch; struct { bool resetRequired; // HOLD reset to get first touch point again - double timeDuration; // HOLD duration in milliseconds + double timeDuration; // HOLD duration in seconds } Hold; struct { Vector2 vector; // DRAG vector (between initial and current position) @@ -522,7 +522,7 @@ static float rgVector2Distance(Vector2 v1, Vector2 v2) return result; } -// Time measure returned are milliseconds +// Time measure returned are seconds static double rgGetCurrentTime(void) { double time = 0; @@ -536,7 +536,7 @@ static double rgGetCurrentTime(void) QueryPerformanceFrequency(&clockFrequency); // BE CAREFUL: Costly operation! QueryPerformanceCounter(¤tTime); - time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds + time = (double)currentTime/clockFrequency; // Time in seconds #endif #if defined(__linux__) @@ -545,7 +545,7 @@ static double rgGetCurrentTime(void) clock_gettime(CLOCK_MONOTONIC, &now); unsigned long long int nowTime = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; // Time in nanoseconds - time = ((double)nowTime/1000000.0); // Time in miliseconds + time = ((double)nowTime*1e-9); // Time in seconds #endif #if defined(__APPLE__) @@ -561,7 +561,7 @@ static double rgGetCurrentTime(void) mach_port_deallocate(mach_task_self(), cclock); unsigned long long int nowTime = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; // Time in nanoseconds - time = ((double)nowTime/1000000.0); // Time in miliseconds + time = ((double)nowTime*1e-9); // Time in seconds #endif #endif From 70286c7cdc6d972c63704ad957c18065f6a44cfe Mon Sep 17 00:00:00 2001 From: Michael Anghelone Date: Sun, 16 Jul 2023 07:08:55 -0400 Subject: [PATCH 33/40] Makefile change for cross compiling. (#3176) Working from wsl and compiling for windows this change makes it much easier to compile a static library for windows on arm. To compile a static library for windows on arm: ``` make PLATFORM=PLATFORM_DESKTOP TARGET_OS=WINDOWS CROSS_CC=/llvm/bin/aarch64-w64-mingw32-gcc CROSS_AR=/llvm/bin/aarch64-w64-mingw32-ar ``` This does not work to compile a shared library yet, only static. --- src/Makefile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Makefile b/src/Makefile index fc4c5b0c7..30ac232f8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -308,6 +308,17 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID) AR = $(ANDROID_TOOLCHAIN)/bin/llvm-ar endif +# This section is here to help handle cross compilation. eg build on Linux for Windows. If you are doing this, you better know what you are doing! +ifdef TARGET_OS + ifdef CROSS_CC + CC = ${CROSS_CC} + endif + ifdef CROSS_AR + AR = ${CROSS_AR} + endif + PLATFORM_OS = ${TARGET_OS} +endif + # Define compiler flags: CFLAGS #------------------------------------------------------------------------------------------------ # -O1 defines optimization level From 86f95d71502bb6099dca0490aa8216b1684acf0f Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 16 Jul 2023 13:24:49 +0200 Subject: [PATCH 34/40] Reviewed C compilation issues and formatting --- examples/core/core_input_gestures_web.c | 124 +++++++++++++----------- 1 file changed, 66 insertions(+), 58 deletions(-) diff --git a/examples/core/core_input_gestures_web.c b/examples/core/core_input_gestures_web.c index 0ee3d1c5e..0129a983b 100644 --- a/examples/core/core_input_gestures_web.c +++ b/examples/core/core_input_gestures_web.c @@ -14,7 +14,8 @@ ********************************************************************************************/ #include "raylib.h" -#include "math.h" // Required for the protractor angle graphic drawing + +#include "math.h" // Required for the protractor angle graphic drawing #if defined(PLATFORM_WEB) #include // Required for the Web/HTML5 @@ -26,14 +27,14 @@ // Common variables definitions //-------------------------------------------------------------------------------------- -int screenWidth = 800; +int screenWidth = 800; // Update depending on web canvas const int screenHeight = 450; -Vector2 messagePosition = {160, 7}; +Vector2 messagePosition = { 160, 7 }; // Last gesture variables definitions //-------------------------------------------------------------------------------------- int lastGesture = 0; -Vector2 lastGesturePosition = {165, 130}; +Vector2 lastGesturePosition = { 165, 130 }; // Gesture log variables definitions and functions declarations //-------------------------------------------------------------------------------------- @@ -41,6 +42,7 @@ Vector2 lastGesturePosition = {165, 130}; char gestureLog[GESTURE_LOG_SIZE][12] = { "" }; // The gesture log uses an array (as an inverted circular queue) to store the performed gestures int gestureLogIndex = GESTURE_LOG_SIZE; // The index for the inverted circular queue (moving from last to first direction, then looping around) int previousGesture = 0; + char const *GetGestureName(int i) { switch (i) { @@ -58,6 +60,7 @@ char const *GetGestureName(int i) default: return "Unknown"; break; } } + Color GetGestureColor(int i) { switch (i) { @@ -75,19 +78,21 @@ Color GetGestureColor(int i) default: return BLACK; break; } } -Color gestureColor = BLACK; + int logMode = 1; // Log mode values: 0 shows repeated events; 1 hides repeated events; 2 shows repeated events but hide hold events; 3 hides repeated events and hide hold events -Rectangle logButton1 = {53, 7, 48, 26}; -Rectangle logButton2 = {108, 7, 36, 26}; -Vector2 gestureLogPosition = {10, 10}; + +Color gestureColor = { 0, 0, 0, 255 }; +Rectangle logButton1 = { 53, 7, 48, 26 }; +Rectangle logButton2 = { 108, 7, 36, 26 }; +Vector2 gestureLogPosition = { 10, 10 }; // Protractor variables definitions //-------------------------------------------------------------------------------------- float angleLength = 90.0f; float currentAngleDegrees = 0.0f; -Vector2 finalVector = {0.0f, 0.0f}; +Vector2 finalVector = { 0.0f, 0.0f }; char currentAngleStr[7] = ""; -Vector2 protractorPosition = {266.0f, 315.0f}; +Vector2 protractorPosition = { 266.0f, 315.0f }; // Update //-------------------------------------------------------------------------------------- @@ -103,39 +108,40 @@ void Update(void) // Handle last gesture //-------------------------------------------------------------------------------------- - if ( currentGesture != 0 && currentGesture != 4 && currentGesture != previousGesture ) lastGesture = currentGesture; // Filter the meaningful gestures (1, 2, 8 to 512) for the display + if ((currentGesture != 0) && (currentGesture != 4) && (currentGesture != previousGesture)) lastGesture = currentGesture; // Filter the meaningful gestures (1, 2, 8 to 512) for the display // Handle gesture log //-------------------------------------------------------------------------------------- - if ( IsMouseButtonReleased(MOUSE_BUTTON_LEFT) ) + if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) { - if ( CheckCollisionPointRec(GetMousePosition(), logButton1 ) ) + if (CheckCollisionPointRec(GetMousePosition(), logButton1)) { switch (logMode) { - case 3: logMode=2; break; - case 2: logMode=3; break; - case 1: logMode=0; break; - default: logMode=1; break; + case 3: logMode=2; break; + case 2: logMode=3; break; + case 1: logMode=0; break; + default: logMode=1; break; } } - else if ( CheckCollisionPointRec(GetMousePosition(), logButton2) ) + else if (CheckCollisionPointRec(GetMousePosition(), logButton2)) { switch (logMode) { - case 3: logMode=1; break; - case 2: logMode=0; break; - case 1: logMode=3; break; - default: logMode=2; break; + case 3: logMode=1; break; + case 2: logMode=0; break; + case 1: logMode=3; break; + default: logMode=2; break; } } } + int fillLog = 0; // Gate variable to be used to allow or not the gesture log to be filled if (currentGesture !=0) { if (logMode == 3) // 3 hides repeated events and hide hold events { - if ( ( currentGesture != 4 && currentGesture != previousGesture ) || currentGesture < 3 ) fillLog = 1; + if (((currentGesture != 4) && (currentGesture != previousGesture)) || (currentGesture < 3)) fillLog = 1; } else if (logMode == 2) // 2 shows repeated events but hide hold events { @@ -150,13 +156,16 @@ void Update(void) fillLog = 1; } } + if (fillLog) // If one of the conditions from logMode was met, fill the gesture log { previousGesture = currentGesture; gestureColor = GetGestureColor(currentGesture); if (gestureLogIndex <= 0) gestureLogIndex = GESTURE_LOG_SIZE; gestureLogIndex--; - TextCopy( gestureLog[gestureLogIndex], GetGestureName(currentGesture) ); // Copy the gesture respective name to the gesture log array + + // Copy the gesture respective name to the gesture log array + TextCopy(gestureLog[gestureLogIndex], GetGestureName(currentGesture)); } // Handle protractor @@ -173,12 +182,15 @@ void Update(void) { currentAngleDegrees = 0.0f; } - float currentAngleRadians = ( (currentAngleDegrees +90.0f)*PI/180 ); // Convert the current angle to Radians - finalVector = (Vector2){ ( angleLength*sinf(currentAngleRadians) ) + protractorPosition.x, ( angleLength*cosf(currentAngleRadians) ) + protractorPosition.y }; // Calculate the final vector for display + + float currentAngleRadians = ((currentAngleDegrees +90.0f)*PI/180); // Convert the current angle to Radians + finalVector = (Vector2){ (angleLength*sinf(currentAngleRadians)) + protractorPosition.x, (angleLength*cosf(currentAngleRadians)) + protractorPosition.y }; // Calculate the final vector for display // Handle touch and mouse pointer points //-------------------------------------------------------------------------------------- - Vector2 touchPosition[touchCount]; + #define MAX_TOUCH_COUNT 32 + + Vector2 touchPosition[MAX_TOUCH_COUNT] = { 0 }; Vector2 mousePosition = {0, 0}; if (currentGesture != GESTURE_NONE) { @@ -186,16 +198,14 @@ void Update(void) { for (i = 0; i < touchCount; i++) touchPosition[i] = GetTouchPosition(i); // Fill the touch positions } - else - { - mousePosition = GetMousePosition(); - } + else mousePosition = GetMousePosition(); } // Draw //-------------------------------------------------------------------------------------- BeginDrawing(); - ClearBackground(RAYWHITE); + + ClearBackground(RAYWHITE); // Draw common //-------------------------------------------------------------------------------------- @@ -216,29 +226,30 @@ void Update(void) DrawRing( (Vector2){lastGesturePosition.x + 103, lastGesturePosition.y + 16}, 6.0f, 11.0f, 0.0f, 360.0f, 0, lastGesture == GESTURE_DRAG ? LIME : LIGHTGRAY); DrawCircle(lastGesturePosition.x + 80, lastGesturePosition.y + 43, 10, lastGesture == GESTURE_DOUBLETAP ? SKYBLUE : LIGHTGRAY); DrawCircle(lastGesturePosition.x + 103, lastGesturePosition.y + 43, 10, lastGesture == GESTURE_DOUBLETAP ? SKYBLUE : LIGHTGRAY); - DrawTriangle( (Vector2){lastGesturePosition.x + 122, lastGesturePosition.y + 16}, (Vector2){lastGesturePosition.x + 137, lastGesturePosition.y + 26}, (Vector2){lastGesturePosition.x + 137, lastGesturePosition.y + 6}, lastGesture == GESTURE_PINCH_OUT ? ORANGE : LIGHTGRAY); - DrawTriangle( (Vector2){lastGesturePosition.x + 147, lastGesturePosition.y + 6}, (Vector2){lastGesturePosition.x + 147, lastGesturePosition.y + 26}, (Vector2){lastGesturePosition.x + 162, lastGesturePosition.y + 16}, lastGesture == GESTURE_PINCH_OUT ? ORANGE : LIGHTGRAY); - DrawTriangle( (Vector2){lastGesturePosition.x + 125, lastGesturePosition.y + 33}, (Vector2){lastGesturePosition.x + 125, lastGesturePosition.y + 53}, (Vector2){lastGesturePosition.x + 140, lastGesturePosition.y + 43}, lastGesture == GESTURE_PINCH_IN ? VIOLET : LIGHTGRAY); - DrawTriangle( (Vector2){lastGesturePosition.x + 144, lastGesturePosition.y + 43}, (Vector2){lastGesturePosition.x + 159, lastGesturePosition.y + 53}, (Vector2){lastGesturePosition.x + 159, lastGesturePosition.y + 33}, lastGesture == GESTURE_PINCH_IN ? VIOLET : LIGHTGRAY); - for ( i = 0; i < 4; i++ ) DrawCircle(lastGesturePosition.x + 180, lastGesturePosition.y + 7 + i*15, 5, touchCount <= i ? LIGHTGRAY : gestureColor); + DrawTriangle((Vector2){ lastGesturePosition.x + 122, lastGesturePosition.y + 16 }, (Vector2){ lastGesturePosition.x + 137, lastGesturePosition.y + 26 }, (Vector2){ lastGesturePosition.x + 137, lastGesturePosition.y + 6 }, lastGesture == GESTURE_PINCH_OUT? ORANGE : LIGHTGRAY); + DrawTriangle((Vector2){ lastGesturePosition.x + 147, lastGesturePosition.y + 6 }, (Vector2){ lastGesturePosition.x + 147, lastGesturePosition.y + 26 }, (Vector2){ lastGesturePosition.x + 162, lastGesturePosition.y + 16 }, lastGesture == GESTURE_PINCH_OUT? ORANGE : LIGHTGRAY); + DrawTriangle((Vector2){ lastGesturePosition.x + 125, lastGesturePosition.y + 33 }, (Vector2){ lastGesturePosition.x + 125, lastGesturePosition.y + 53 }, (Vector2){ lastGesturePosition.x + 140, lastGesturePosition.y + 43 }, lastGesture == GESTURE_PINCH_IN? VIOLET : LIGHTGRAY); + DrawTriangle((Vector2){ lastGesturePosition.x + 144, lastGesturePosition.y + 43 }, (Vector2){ lastGesturePosition.x + 159, lastGesturePosition.y + 53 }, (Vector2){ lastGesturePosition.x + 159, lastGesturePosition.y + 33 }, lastGesture == GESTURE_PINCH_IN? VIOLET : LIGHTGRAY); + for (i = 0; i < 4; i++) DrawCircle(lastGesturePosition.x + 180, lastGesturePosition.y + 7 + i*15, 5, touchCount <= i? LIGHTGRAY : gestureColor); // Draw gesture log //-------------------------------------------------------------------------------------- DrawText("Log", gestureLogPosition.x, gestureLogPosition.y, 20, BLACK); + // Loop in both directions to print the gesture log array in the inverted order (and looping around if the index started somewhere in the middle) for (i = 0, ii = gestureLogIndex; i < GESTURE_LOG_SIZE; i++, ii = (ii + 1) % GESTURE_LOG_SIZE) DrawText(gestureLog[ii], gestureLogPosition.x, gestureLogPosition.y + 410 - i*20, 20, (i == 0 ? gestureColor : LIGHTGRAY)); Color logButton1Color, logButton2Color; switch (logMode) { - case 3: logButton1Color=MAROON; logButton2Color=MAROON; break; - case 2: logButton1Color=GRAY; logButton2Color=MAROON; break; - case 1: logButton1Color=MAROON; logButton2Color=GRAY; break; - default: logButton1Color=GRAY; logButton2Color=GRAY; break; + case 3: logButton1Color=MAROON; logButton2Color=MAROON; break; + case 2: logButton1Color=GRAY; logButton2Color=MAROON; break; + case 1: logButton1Color=MAROON; logButton2Color=GRAY; break; + default: logButton1Color=GRAY; logButton2Color=GRAY; break; } - DrawRectangleRec( logButton1, logButton1Color); + DrawRectangleRec(logButton1, logButton1Color); DrawText("Hide", logButton1.x + 7, logButton1.y + 3, 10, WHITE); DrawText("Repeat", logButton1.x + 7, logButton1.y + 13, 10, WHITE); - DrawRectangleRec( logButton2, logButton2Color); + DrawRectangleRec(logButton2, logButton2Color); DrawText("Hide", logButton1.x + 62, logButton1.y + 3, 10, WHITE); DrawText("Hold", logButton1.x + 62, logButton1.y + 13, 10, WHITE); @@ -250,10 +261,10 @@ void Update(void) const char *angleStringTrim = TextSubtext(angleString, 0, angleStringDot + 3); DrawText( angleStringTrim, protractorPosition.x + 55, protractorPosition.y + 92, 20, gestureColor); DrawCircle(protractorPosition.x, protractorPosition.y, 80.0f, WHITE); - DrawLineEx( (Vector2){protractorPosition.x - 90, protractorPosition.y}, (Vector2){protractorPosition.x + 90, protractorPosition.y}, 3.0f, LIGHTGRAY); - DrawLineEx( (Vector2){protractorPosition.x, protractorPosition.y - 90}, (Vector2){protractorPosition.x, protractorPosition.y + 90}, 3.0f, LIGHTGRAY); - DrawLineEx( (Vector2){protractorPosition.x - 80, protractorPosition.y - 45}, (Vector2){protractorPosition.x + 80, protractorPosition.y + 45}, 3.0f, GREEN); - DrawLineEx( (Vector2){protractorPosition.x - 80, protractorPosition.y + 45}, (Vector2){protractorPosition.x + 80, protractorPosition.y - 45}, 3.0f, GREEN); + DrawLineEx((Vector2){ protractorPosition.x - 90, protractorPosition.y }, (Vector2){ protractorPosition.x + 90, protractorPosition.y }, 3.0f, LIGHTGRAY); + DrawLineEx((Vector2){ protractorPosition.x, protractorPosition.y - 90 }, (Vector2){ protractorPosition.x, protractorPosition.y + 90 }, 3.0f, LIGHTGRAY); + DrawLineEx((Vector2){ protractorPosition.x - 80, protractorPosition.y - 45 }, (Vector2){ protractorPosition.x + 80, protractorPosition.y + 45 }, 3.0f, GREEN); + DrawLineEx((Vector2){ protractorPosition.x - 80, protractorPosition.y + 45 }, (Vector2){ protractorPosition.x + 80, protractorPosition.y - 45 }, 3.0f, GREEN); DrawText("0", protractorPosition.x + 96, protractorPosition.y - 9, 20, BLACK); DrawText("30", protractorPosition.x + 74, protractorPosition.y - 68, 20, BLACK); DrawText("90", protractorPosition.x - 11, protractorPosition.y - 110, 20, BLACK); @@ -262,7 +273,7 @@ void Update(void) DrawText("210", protractorPosition.x - 100, protractorPosition.y + 50, 20, BLACK); DrawText("270", protractorPosition.x - 18, protractorPosition.y + 92, 20, BLACK); DrawText("330", protractorPosition.x + 72, protractorPosition.y + 50, 20, BLACK); - if ( currentAngleDegrees != 0.0f ) DrawLineEx( protractorPosition, finalVector, 3.0f, gestureColor); + if (currentAngleDegrees != 0.0f) DrawLineEx(protractorPosition, finalVector, 3.0f, gestureColor); // Draw touch and mouse pointer points //-------------------------------------------------------------------------------------- @@ -275,7 +286,8 @@ void Update(void) DrawCircleV(touchPosition[i], 50.0f, Fade(gestureColor, 0.5f)); DrawCircleV(touchPosition[i], 5.0f, gestureColor); } - if (touchCount == 2) DrawLineEx( touchPosition[0], touchPosition[1], (currentGesture == 512 ? 8 : 12), gestureColor); + + if (touchCount == 2) DrawLineEx(touchPosition[0], touchPosition[1], ((currentGesture == 512)? 8 : 12), gestureColor); } else { @@ -297,15 +309,11 @@ int main(void) // Initialization //-------------------------------------------------------------------------------------- #if defined( PLATFORM_WEB ) - const int canvasWidth = EM_ASM_INT( return document.getElementById('canvas').getBoundingClientRect().width; ); // Using Emscripten EM_ASM_INT macro, get the page canvas width - if (canvasWidth > 400) - { - screenWidth = canvasWidth; - } - else - { - screenWidth = 400; // Set a minimum width for the screen - } + // Using Emscripten EM_ASM_INT macro, get the page canvas width + const int canvasWidth = EM_ASM_INT( return document.getElementById('canvas').getBoundingClientRect().width; ); + + if (canvasWidth > 400) screenWidth = canvasWidth; + else screenWidth = 400; // Set a minimum width for the screen #endif InitWindow(screenWidth, screenHeight, "raylib [core] example - input gestures web"); From e0c80f5ddd9543a6f086f3871f886e275c331a53 Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 16 Jul 2023 20:18:38 +0200 Subject: [PATCH 35/40] Revert "Makefile change for cross compiling. (#3176)" This reverts commit 70286c7cdc6d972c63704ad957c18065f6a44cfe. --- src/Makefile | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Makefile b/src/Makefile index 30ac232f8..fc4c5b0c7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -308,17 +308,6 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID) AR = $(ANDROID_TOOLCHAIN)/bin/llvm-ar endif -# This section is here to help handle cross compilation. eg build on Linux for Windows. If you are doing this, you better know what you are doing! -ifdef TARGET_OS - ifdef CROSS_CC - CC = ${CROSS_CC} - endif - ifdef CROSS_AR - AR = ${CROSS_AR} - endif - PLATFORM_OS = ${TARGET_OS} -endif - # Define compiler flags: CFLAGS #------------------------------------------------------------------------------------------------ # -O1 defines optimization level From 52541b4a1fb04d66de30c2a1e5f44358b2c1aee7 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 18 Jul 2023 17:57:10 +0200 Subject: [PATCH 36/40] ADDED: `SUPPORT_FONT_ATLAS_WHITE_REC` Support creating a 3x3 pixels white rectangle at the bottom-right corner of the generated font atlas image, useful for shapes+text drawing in a single draw call! --- CMakeOptions.txt | 1 + src/config.h | 5 +++++ src/rtext.c | 27 ++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CMakeOptions.txt b/CMakeOptions.txt index 326ed44e6..a239f1143 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -73,6 +73,7 @@ cmake_dependent_option(SUPPORT_FILEFORMAT_PVR "Support loading PVR as textures" cmake_dependent_option(SUPPORT_FILEFORMAT_FNT "Support loading fonts in FNT format" ON CUSTOMIZE_BUILD ON) cmake_dependent_option(SUPPORT_FILEFORMAT_TTF "Support loading font in TTF/OTF format" ON CUSTOMIZE_BUILD ON) cmake_dependent_option(SUPPORT_TEXT_MANIPULATION "Support text manipulation functions" ON CUSTOMIZE_BUILD ON) +cmake_dependent_option(#define SUPPORT_FONT_ATLAS_WHITE_REC "Support white rec on font atlas bottom-right corner" ON CUSTOMIZE_BUILD ON) # rmodels.c cmake_dependent_option(SUPPORT_MESH_GENERATION "Support procedural mesh generation functions, uses external par_shapes.h library. NOTE: Some generated meshes DO NOT include generated texture coordinates" ON CUSTOMIZE_BUILD ON) diff --git a/src/config.h b/src/config.h index fbc7a5b47..67c6060b8 100644 --- a/src/config.h +++ b/src/config.h @@ -181,6 +181,11 @@ // If not defined, still some functions are supported: TextLength(), TextFormat() #define SUPPORT_TEXT_MANIPULATION 1 +// On font atlas image generation [GenImageFontAtlas()], add a 3x3 pixels white rectangle +// at the bottom-right corner of the atlas. It can be useful to for shapes drawing, to allow +// drawing text and shapes with a single draw call [SetShapesTexture()]. +#define SUPPORT_FONT_ATLAS_WHITE_REC 1 + // rtext: Configuration values //------------------------------------------------------------------------------------ #define MAX_TEXT_BUFFER_LENGTH 1024 // Size of internal static buffers used on some functions: diff --git a/src/rtext.c b/src/rtext.c index 3b21a93c9..a7d9903a8 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -6,14 +6,19 @@ * #define SUPPORT_MODULE_RTEXT * rtext module is included in the build * +* #define SUPPORT_DEFAULT_FONT +* Load default raylib font on initialization to be used by DrawText() and MeasureText(). +* If no default font loaded, DrawTextEx() and MeasureTextEx() are required. +* * #define SUPPORT_FILEFORMAT_FNT * #define SUPPORT_FILEFORMAT_TTF * Selected desired fileformats to be supported for loading. Some of those formats are * supported by default, to remove support, just comment unrequired #define in this module * -* #define SUPPORT_DEFAULT_FONT -* Load default raylib font on initialization to be used by DrawText() and MeasureText(). -* If no default font loaded, DrawTextEx() and MeasureTextEx() are required. +* #define SUPPORT_FONT_ATLAS_WHITE_REC +* On font atlas image generation [GenImageFontAtlas()], add a 3x3 pixels white rectangle +* at the bottom-right corner of the atlas. It can be useful to for shapes drawing, to allow +* drawing text and shapes with a single draw call [SetShapesTexture()]. * * #define TEXTSPLIT_MAX_TEXT_BUFFER_LENGTH * TextSplit() function static buffer max size @@ -734,7 +739,6 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC } #endif - atlas.data = (unsigned char *)RL_CALLOC(1, atlas.width*atlas.height); // Create a bitmap to store characters (8 bpp) atlas.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE; atlas.mipmaps = 1; @@ -839,7 +843,20 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphC RL_FREE(nodes); RL_FREE(context); } - + +#if defined(SUPPORT_FONT_ATLAS_WHITE_REC) + // Add a 3x3 white rectangle at the bottom-right corner of the generated atlas, + // useful to use as the white texture to draw shapes with raylib, using this rectangle + // shapes and text can be backed into a single draw call: SetShapesTexture() + for (int i = 0, k = atlas.width*atlas.height - 1; i < 3; i++) + { + ((unsigned char *)atlas.data)[k - 0] = 255; + ((unsigned char *)atlas.data)[k - 1] = 255; + ((unsigned char *)atlas.data)[k - 2] = 255; + k -= atlas.width; + } +#endif + // Convert image data from GRAYSCALE to GRAY_ALPHA unsigned char *dataGrayAlpha = (unsigned char *)RL_MALLOC(atlas.width*atlas.height*sizeof(unsigned char)*2); // Two channels From a9ff13a367b7bd166436b12b741b8c8199f1c85f Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 18 Jul 2023 18:07:49 +0200 Subject: [PATCH 37/40] Update CMakeOptions.txt --- CMakeOptions.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeOptions.txt b/CMakeOptions.txt index a239f1143..c643427c6 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -73,7 +73,7 @@ cmake_dependent_option(SUPPORT_FILEFORMAT_PVR "Support loading PVR as textures" cmake_dependent_option(SUPPORT_FILEFORMAT_FNT "Support loading fonts in FNT format" ON CUSTOMIZE_BUILD ON) cmake_dependent_option(SUPPORT_FILEFORMAT_TTF "Support loading font in TTF/OTF format" ON CUSTOMIZE_BUILD ON) cmake_dependent_option(SUPPORT_TEXT_MANIPULATION "Support text manipulation functions" ON CUSTOMIZE_BUILD ON) -cmake_dependent_option(#define SUPPORT_FONT_ATLAS_WHITE_REC "Support white rec on font atlas bottom-right corner" ON CUSTOMIZE_BUILD ON) +cmake_dependent_option(SUPPORT_FONT_ATLAS_WHITE_REC "Support white rec on font atlas bottom-right corner" ON CUSTOMIZE_BUILD ON) # rmodels.c cmake_dependent_option(SUPPORT_MESH_GENERATION "Support procedural mesh generation functions, uses external par_shapes.h library. NOTE: Some generated meshes DO NOT include generated texture coordinates" ON CUSTOMIZE_BUILD ON) From 954c60100f2411dcfb6b57a3a39e96c71e4d2e52 Mon Sep 17 00:00:00 2001 From: ubkp <118854183+ubkp@users.noreply.github.com> Date: Wed, 19 Jul 2023 06:33:10 -0300 Subject: [PATCH 38/40] Fix GESTURE_DRAG and GESTURE_SWIPE_* issues (mostly) for web (#3183) --- src/rgestures.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/rgestures.h b/src/rgestures.h index 78dde76ee..d8bb3b1d9 100644 --- a/src/rgestures.h +++ b/src/rgestures.h @@ -178,8 +178,9 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang //---------------------------------------------------------------------------------- // Defines and Macros //---------------------------------------------------------------------------------- -#define FORCE_TO_SWIPE 0.0005f // Swipe force, measured in normalized screen units/time +#define FORCE_TO_SWIPE 0.2f // Swipe force, measured in normalized screen units/time #define MINIMUM_DRAG 0.015f // Drag minimum force, measured in normalized screen units (0.0f to 1.0f) +#define DRAG_TIMEOUT 0.2f // Drag minimum time for web, measured in seconds #define MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f) #define TAP_TIMEOUT 0.3f // Tap minimum time, measured in seconds #define PINCH_TIMEOUT 0.3f // Pinch minimum time, measured in seconds @@ -297,7 +298,8 @@ void ProcessGestureEvent(GestureEvent event) } else if (event.touchAction == TOUCH_ACTION_UP) { - if (GESTURES.current == GESTURE_DRAG) GESTURES.Touch.upPosition = event.position[0]; + // A swipe can happen while the current gesture is drag, but (specially for web) also hold, so set upPosition for both cases + if (GESTURES.current == GESTURE_DRAG || GESTURES.current == GESTURE_HOLD) GESTURES.Touch.upPosition = event.position[0]; // NOTE: GESTURES.Drag.intensity dependent on the resolution of the screen GESTURES.Drag.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition); @@ -348,7 +350,12 @@ void ProcessGestureEvent(GestureEvent event) GESTURES.Hold.resetRequired = false; // Detect GESTURE_DRAG +#if defined(PLATFORM_WEB) + // An alternative check to detect gesture drag is necessary since moveDownPositionA on touch for web is always zero, causing the distance calculation to be inaccurate + if ((rgGetCurrentTime() - GESTURES.Touch.eventTime) > DRAG_TIMEOUT) +#else if (rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_DRAG) +#endif { GESTURES.Touch.eventTime = rgGetCurrentTime(); GESTURES.current = GESTURE_DRAG; From d6f16b76649944f65491633a75ad648a6ddfdacf Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Wed, 19 Jul 2023 14:46:14 +0300 Subject: [PATCH 39/40] Update usage of 'sinf()' and 'cosf()' to be correct (#3181) * Update usage of 'sinf()' and 'cosf()' to be correct * Update formatting of arithmetic operations --- src/rshapes.c | 216 +++++++++++++++++++++++++++----------------------- 1 file changed, 117 insertions(+), 99 deletions(-) diff --git a/src/rshapes.c b/src/rshapes.c index d726ff0e8..86e998a6d 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -393,14 +393,14 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); rlVertex2f(center.x, center.y); - rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*radius, center.y + cosf(DEG2RAD*angle)*radius); + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength*2))*radius, center.y + sinf(DEG2RAD*(angle + stepLength*2))*radius); rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*radius, center.y + cosf(DEG2RAD*(angle + stepLength))*radius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*radius, center.y + sinf(DEG2RAD*(angle + stepLength))*radius); - rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength*2))*radius, center.y + cosf(DEG2RAD*(angle + stepLength*2))*radius); + rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*radius, center.y + sinf(DEG2RAD*angle)*radius); angle += (stepLength*2); } @@ -413,11 +413,11 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); rlVertex2f(center.x, center.y); - rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*radius, center.y + cosf(DEG2RAD*angle)*radius); - rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*radius, center.y + cosf(DEG2RAD*(angle + stepLength))*radius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*radius, center.y + sinf(DEG2RAD*(angle + stepLength))*radius); + + rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*radius, center.y + sinf(DEG2RAD*angle)*radius); rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); rlVertex2f(center.x, center.y); @@ -432,8 +432,8 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2f(center.x, center.y); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*radius, center.y + cosf(DEG2RAD*angle)*radius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*radius, center.y + cosf(DEG2RAD*(angle + stepLength))*radius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*radius, center.y + sinf(DEG2RAD*(angle + stepLength))*radius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*radius, center.y + sinf(DEG2RAD*angle)*radius); angle += stepLength; } @@ -475,15 +475,15 @@ void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float { rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2f(center.x, center.y); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*radius, center.y + cosf(DEG2RAD*angle)*radius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*radius, center.y + sinf(DEG2RAD*angle)*radius); } for (int i = 0; i < segments; i++) { rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*radius, center.y + cosf(DEG2RAD*angle)*radius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*radius, center.y + cosf(DEG2RAD*(angle + stepLength))*radius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*radius, center.y + sinf(DEG2RAD*angle)*radius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*radius, center.y + sinf(DEG2RAD*(angle + stepLength))*radius); angle += stepLength; } @@ -492,7 +492,7 @@ void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float { rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2f(center.x, center.y); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*radius, center.y + cosf(DEG2RAD*angle)*radius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*radius, center.y + sinf(DEG2RAD*angle)*radius); } rlEnd(); } @@ -507,9 +507,9 @@ void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Co rlColor4ub(color1.r, color1.g, color1.b, color1.a); rlVertex2f((float)centerX, (float)centerY); rlColor4ub(color2.r, color2.g, color2.b, color2.a); - rlVertex2f((float)centerX + sinf(DEG2RAD*i)*radius, (float)centerY + cosf(DEG2RAD*i)*radius); + rlVertex2f((float)centerX + cosf(DEG2RAD*(i + 10))*radius, (float)centerY + sinf(DEG2RAD*(i + 10))*radius); rlColor4ub(color2.r, color2.g, color2.b, color2.a); - rlVertex2f((float)centerX + sinf(DEG2RAD*(i + 10))*radius, (float)centerY + cosf(DEG2RAD*(i + 10))*radius); + rlVertex2f((float)centerX + cosf(DEG2RAD*i)*radius, (float)centerY + sinf(DEG2RAD*i)*radius); } rlEnd(); } @@ -530,8 +530,8 @@ void DrawCircleLines(int centerX, int centerY, float radius, Color color) // NOTE: Circle outline is drawn pixel by pixel every degree (0 to 360) for (int i = 0; i < 360; i += 10) { - rlVertex2f(centerX + sinf(DEG2RAD*i)*radius, centerY + cosf(DEG2RAD*i)*radius); - rlVertex2f(centerX + sinf(DEG2RAD*(i + 10))*radius, centerY + cosf(DEG2RAD*(i + 10))*radius); + rlVertex2f(centerX + cosf(DEG2RAD*i)*radius, centerY + sinf(DEG2RAD*i)*radius); + rlVertex2f(centerX + cosf(DEG2RAD*(i + 10))*radius, centerY + sinf(DEG2RAD*(i + 10))*radius); } rlEnd(); } @@ -544,8 +544,8 @@ void DrawEllipse(int centerX, int centerY, float radiusH, float radiusV, Color c { rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2f((float)centerX, (float)centerY); - rlVertex2f((float)centerX + sinf(DEG2RAD*i)*radiusH, (float)centerY + cosf(DEG2RAD*i)*radiusV); - rlVertex2f((float)centerX + sinf(DEG2RAD*(i + 10))*radiusH, (float)centerY + cosf(DEG2RAD*(i + 10))*radiusV); + rlVertex2f((float)centerX + cosf(DEG2RAD*(i + 10))*radiusH, (float)centerY + sinf(DEG2RAD*(i + 10))*radiusV); + rlVertex2f((float)centerX + cosf(DEG2RAD*i)*radiusH, (float)centerY + sinf(DEG2RAD*i)*radiusV); } rlEnd(); } @@ -557,8 +557,8 @@ void DrawEllipseLines(int centerX, int centerY, float radiusH, float radiusV, Co for (int i = 0; i < 360; i += 10) { rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(centerX + sinf(DEG2RAD*i)*radiusH, centerY + cosf(DEG2RAD*i)*radiusV); - rlVertex2f(centerX + sinf(DEG2RAD*(i + 10))*radiusH, centerY + cosf(DEG2RAD*(i + 10))*radiusV); + rlVertex2f(centerX + cosf(DEG2RAD*(i + 10))*radiusH, centerY + sinf(DEG2RAD*(i + 10))*radiusV); + rlVertex2f(centerX + cosf(DEG2RAD*i)*radiusH, centerY + sinf(DEG2RAD*i)*radiusV); } rlEnd(); } @@ -616,17 +616,17 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startA { rlColor4ub(color.r, color.g, color.b, color.a); - rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*innerRadius, center.y + cosf(DEG2RAD*angle)*innerRadius); - rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*outerRadius, center.y + sinf(DEG2RAD*angle)*outerRadius); - rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*outerRadius); + rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*innerRadius, center.y + sinf(DEG2RAD*angle)*innerRadius); rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*innerRadius); + + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*outerRadius); angle += stepLength; } @@ -639,13 +639,13 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startA { rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*innerRadius, center.y + cosf(DEG2RAD*angle)*innerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*innerRadius, center.y + sinf(DEG2RAD*angle)*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*outerRadius, center.y + sinf(DEG2RAD*angle)*outerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*innerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*outerRadius, center.y + sinf(DEG2RAD*angle)*outerRadius); angle += stepLength; } @@ -702,19 +702,19 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float s if (showCapLines) { rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*innerRadius, center.y + cosf(DEG2RAD*angle)*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*outerRadius, center.y + sinf(DEG2RAD*angle)*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*innerRadius, center.y + sinf(DEG2RAD*angle)*innerRadius); } for (int i = 0; i < segments; i++) { rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*outerRadius, center.y + sinf(DEG2RAD*angle)*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*outerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*innerRadius, center.y + cosf(DEG2RAD*angle)*innerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*innerRadius, center.y + sinf(DEG2RAD*angle)*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*innerRadius); angle += stepLength; } @@ -722,8 +722,8 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float s if (showCapLines) { rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*innerRadius, center.y + cosf(DEG2RAD*angle)*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*outerRadius, center.y + sinf(DEG2RAD*angle)*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*innerRadius, center.y + sinf(DEG2RAD*angle)*innerRadius); } rlEnd(); } @@ -982,7 +982,7 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co }; const Vector2 centers[4] = { point[8], point[9], point[10], point[11] }; - const float angles[4] = { 180.0f, 90.0f, 0.0f, 270.0f }; + const float angles[4] = { 180.0f, 270.0f, 0.0f, 90.0f }; #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(texShapes.id); @@ -1000,12 +1000,16 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co rlColor4ub(color.r, color.g, color.b, color.a); rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); rlVertex2f(center.x, center.y); - rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*radius, center.y + cosf(DEG2RAD*angle)*radius); - rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*radius, center.y + cosf(DEG2RAD*(angle + stepLength))*radius); + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength*2))*radius, center.y + cosf(DEG2RAD*(angle + stepLength*2))*radius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength*2))*radius, center.y + sinf(DEG2RAD*(angle + stepLength*2))*radius); + + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*radius, center.y + sinf(DEG2RAD*(angle + stepLength))*radius); + + rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*radius, center.y + sinf(DEG2RAD*angle)*radius); + angle += (stepLength*2); } @@ -1015,10 +1019,13 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co rlColor4ub(color.r, color.g, color.b, color.a); rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); rlVertex2f(center.x, center.y); - rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*radius, center.y + cosf(DEG2RAD*angle)*radius); + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*radius, center.y + cosf(DEG2RAD*(angle + stepLength))*radius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*radius, center.y + sinf(DEG2RAD*(angle + stepLength))*radius); + + rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*radius, center.y + sinf(DEG2RAD*angle)*radius); + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); rlVertex2f(center.x, center.y); } @@ -1093,8 +1100,8 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co { rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2f(center.x, center.y); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*radius, center.y + cosf(DEG2RAD*angle)*radius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*radius, center.y + cosf(DEG2RAD*(angle + stepLength))*radius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*radius, center.y + sinf(DEG2RAD*(angle + stepLength))*radius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*radius, center.y + sinf(DEG2RAD*angle)*radius); angle += stepLength; } } @@ -1208,7 +1215,7 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo {(float)(rec.x + rec.width) - innerRadius, (float)(rec.y + rec.height) - innerRadius}, {(float)rec.x + innerRadius, (float)(rec.y + rec.height) - innerRadius} // P18, P19 }; - const float angles[4] = { 180.0f, 90.0f, 0.0f, 270.0f }; + const float angles[4] = { 180.0f, 270.0f, 0.0f, 90.0f }; if (lineThick > 1) { @@ -1225,14 +1232,18 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo for (int i = 0; i < segments; i++) { rlColor4ub(color.r, color.g, color.b, color.a); + rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*innerRadius, center.y + cosf(DEG2RAD*angle)*innerRadius); - rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius); - rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*innerRadius, center.y + sinf(DEG2RAD*angle)*innerRadius); + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*innerRadius); + + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*outerRadius); + + rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*outerRadius, center.y + sinf(DEG2RAD*angle)*outerRadius); angle += stepLength; } @@ -1297,13 +1308,13 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo { rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*innerRadius, center.y + cosf(DEG2RAD*angle)*innerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*innerRadius, center.y + sinf(DEG2RAD*angle)*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*outerRadius, center.y + sinf(DEG2RAD*angle)*outerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*innerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*innerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*innerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*outerRadius, center.y + sinf(DEG2RAD*angle)*outerRadius); angle += stepLength; } @@ -1361,8 +1372,8 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo for (int i = 0; i < segments; i++) { rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(center.x + sinf(DEG2RAD*angle)*outerRadius, center.y + cosf(DEG2RAD*angle)*outerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + cosf(DEG2RAD*(angle + stepLength))*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*angle)*outerRadius, center.y + sinf(DEG2RAD*angle)*outerRadius); + rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*outerRadius, center.y + sinf(DEG2RAD*(angle + stepLength))*outerRadius); angle += stepLength; } } @@ -1492,7 +1503,8 @@ void DrawTriangleStrip(Vector2 *points, int pointCount, Color color) void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color) { if (sides < 3) sides = 3; - float centralAngle = rotation; + float centralAngle = rotation*DEG2RAD; + float angleStep = 360.0f/(float)sides*DEG2RAD; #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(texShapes.id); @@ -1501,19 +1513,21 @@ void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color col for (int i = 0; i < sides; i++) { rlColor4ub(color.r, color.g, color.b, color.a); + float nextAngle = centralAngle + angleStep; rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); rlVertex2f(center.x, center.y); rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + rlVertex2f(center.x + cosf(centralAngle)*radius, center.y + sinf(centralAngle)*radius); + + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); + rlVertex2f(center.x + cosf(nextAngle)*radius, center.y + sinf(nextAngle)*radius); rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + rlVertex2f(center.x + cosf(centralAngle)*radius, center.y + sinf(centralAngle)*radius); - centralAngle += 360.0f/(float)sides; - rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + centralAngle = nextAngle; } rlEnd(); rlSetTexture(0); @@ -1524,10 +1538,10 @@ void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color col rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2f(center.x, center.y); - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + rlVertex2f(center.x + cosf(centralAngle + angleStep)*radius, center.y + sinf(centralAngle + angleStep)*radius); + rlVertex2f(center.x + cosf(centralAngle)*radius, center.y + sinf(centralAngle)*radius); - centralAngle += 360.0f/(float)sides; - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + centralAngle += angleStep; } rlEnd(); #endif @@ -1537,16 +1551,18 @@ void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color col void DrawPolyLines(Vector2 center, int sides, float radius, float rotation, Color color) { if (sides < 3) sides = 3; - float centralAngle = rotation; + float centralAngle = rotation*DEG2RAD; + float angleStep = 360.0f/(float)sides*DEG2RAD; rlBegin(RL_LINES); for (int i = 0; i < sides; i++) { rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); - centralAngle += 360.0f/(float)sides; - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + rlVertex2f(center.x + cosf(centralAngle)*radius, center.y + sinf(centralAngle)*radius); + rlVertex2f(center.x + cosf(centralAngle + angleStep)*radius, center.y + sinf(centralAngle + angleStep)*radius); + + centralAngle += angleStep; } rlEnd(); } @@ -1554,8 +1570,8 @@ void DrawPolyLines(Vector2 center, int sides, float radius, float rotation, Colo void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, float lineThick, Color color) { if (sides < 3) sides = 3; - float centralAngle = rotation; - float exteriorAngle = 360.0f/(float)sides; + float centralAngle = rotation*DEG2RAD; + float exteriorAngle = 360.0f/(float)sides*DEG2RAD; float innerRadius = radius - (lineThick*cosf(DEG2RAD*exteriorAngle/2.0f)); #if defined(SUPPORT_QUADS_DRAW_MODE) @@ -1565,19 +1581,21 @@ void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, fl for (int i = 0; i < sides; i++) { rlColor4ub(color.r, color.g, color.b, color.a); - - rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*innerRadius, center.y + cosf(DEG2RAD*centralAngle)*innerRadius); + float nextAngle = centralAngle + exteriorAngle; rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + rlVertex2f(center.x + cosf(centralAngle)*radius, center.y + sinf(centralAngle)*radius); - centralAngle += exteriorAngle; - rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); + rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); + rlVertex2f(center.x + cosf(centralAngle)*innerRadius, center.y + sinf(centralAngle)*innerRadius); rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height); - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*innerRadius, center.y + cosf(DEG2RAD*centralAngle)*innerRadius); + rlVertex2f(center.x + cosf(nextAngle)*innerRadius, center.y + sinf(nextAngle)*innerRadius); + + rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height); + rlVertex2f(center.x + cosf(nextAngle)*radius, center.y + sinf(nextAngle)*radius); + + centralAngle = nextAngle; } rlEnd(); rlSetTexture(0); @@ -1588,13 +1606,13 @@ void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, fl rlColor4ub(color.r, color.g, color.b, color.a); float nextAngle = centralAngle + exteriorAngle; - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*radius, center.y + cosf(DEG2RAD*centralAngle)*radius); - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*innerRadius, center.y + cosf(DEG2RAD*centralAngle)*innerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*nextAngle)*radius, center.y + cosf(DEG2RAD*nextAngle)*radius); + rlVertex2f(center.x + cosf(nextAngle)*radius, center.y + sinf(nextAngle)*radius); + rlVertex2f(center.x + cosf(centralAngle)*radius, center.y + sinf(centralAngle)*radius); + rlVertex2f(center.x + cosf(centralAngle)*innerRadius, center.y + sinf(centralAngle)*innerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*centralAngle)*innerRadius, center.y + cosf(DEG2RAD*centralAngle)*innerRadius); - rlVertex2f(center.x + sinf(DEG2RAD*nextAngle)*radius, center.y + cosf(DEG2RAD*nextAngle)*radius); - rlVertex2f(center.x + sinf(DEG2RAD*nextAngle)*innerRadius, center.y + cosf(DEG2RAD*nextAngle)*innerRadius); + rlVertex2f(center.x + cosf(centralAngle)*innerRadius, center.y + sinf(centralAngle)*innerRadius); + rlVertex2f(center.x + cosf(nextAngle)*innerRadius, center.y + sinf(nextAngle)*innerRadius); + rlVertex2f(center.x + cosf(nextAngle)*radius, center.y + sinf(nextAngle)*radius); centralAngle = nextAngle; } From 7124a14a60a4bf7e4357030395750e03a1b976b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Gonz=C3=A1lez=20Palomo?= Date: Wed, 19 Jul 2023 23:11:29 +0200 Subject: [PATCH 40/40] Document buffer format for audio processors. (#3186) --- src/raylib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raylib.h b/src/raylib.h index f9f36626e..c20a69d2b 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1591,7 +1591,7 @@ RLAPI void SetAudioStreamCallback(AudioStream stream, AudioCallback callback); RLAPI void AttachAudioStreamProcessor(AudioStream stream, AudioCallback processor); // Attach audio stream processor to stream RLAPI void DetachAudioStreamProcessor(AudioStream stream, AudioCallback processor); // Detach audio stream processor from stream -RLAPI void AttachAudioMixedProcessor(AudioCallback processor); // Attach audio stream processor to the entire audio pipeline +RLAPI void AttachAudioMixedProcessor(AudioCallback processor); // Attach audio stream processor to the entire audio pipeline, receives the samples as s RLAPI void DetachAudioMixedProcessor(AudioCallback processor); // Detach audio stream processor from the entire audio pipeline #if defined(__cplusplus)