From 99a739084bcbb0c62c99e38e5cbb6b3058ec5845 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Tue, 5 Jan 2021 05:03:38 +0100 Subject: [PATCH 1/5] Add Font fetching infrastructure --- .gitattributes | 1 + Cargo.lock | 719 ++++++++++++-------- rask-engine/Cargo.toml | 4 + rask-engine/src/engine/mod.rs | 1 + rask-engine/src/error.rs | 2 + rask-engine/src/network/protocol.rs | 1 + rask-engine/src/resources/font.rs | 54 ++ rask-engine/src/resources/mod.rs | 4 + rask-engine/src/resources/registry.rs | 2 + rask-engine/src/resources/resource_table.rs | 12 +- wasm/res/pixel.ttf | Bin 0 -> 30836 bytes wasm/src/logic/resource_parser.rs | 26 +- 12 files changed, 535 insertions(+), 291 deletions(-) create mode 100644 rask-engine/src/resources/font.rs create mode 100644 wasm/res/pixel.ttf diff --git a/.gitattributes b/.gitattributes index 6d974540..a5d7b9c2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13,6 +13,7 @@ *.png binary *.gif binary *.mp3 binary +*.ttf binary ############################################################################### # diff behavior for common document formats diff --git a/Cargo.lock b/Cargo.lock index 5ec807e0..7af165c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,18 +12,18 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c0929d69e78dd9bf5408269919fcbcaeb2e35e5d43e5815517cdc6a8e11a423" +checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7" dependencies = [ "gimli", ] [[package]] name = "adler" -version = "0.2.3" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "adler32" @@ -33,57 +33,56 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" [[package]] name = "aead" -version = "0.2.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cf01b9b56e767bb57b94ebf91a58b338002963785cdd7013e21c0d4679471e4" +checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" dependencies = [ - "generic-array", + "generic-array 0.14.4", ] [[package]] name = "aes" -version = "0.3.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54eb1d8fe354e5fc611daf4f2ea97dd45a765f4f1e4512306ec183ae2e8f20c9" +checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561" dependencies = [ "aes-soft", "aesni", - "block-cipher-trait", + "cipher", ] [[package]] name = "aes-gcm" -version = "0.5.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "834a6bda386024dbb7c8fc51322856c10ffe69559f972261c868485f5759c638" +checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da" dependencies = [ "aead", "aes", - "block-cipher-trait", + "cipher", + "ctr", "ghash", - "subtle 2.3.0", - "zeroize", + "subtle", ] [[package]] name = "aes-soft" -version = "0.3.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" +checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" dependencies = [ - "block-cipher-trait", - "byteorder", - "opaque-debug", + "cipher", + "opaque-debug 0.3.0", ] [[package]] name = "aesni" -version = "0.6.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" +checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" dependencies = [ - "block-cipher-trait", - "opaque-debug", + "cipher", + "opaque-debug 0.3.0", ] [[package]] @@ -147,14 +146,14 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.54" +version = "0.3.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2baad346b2d4e94a24347adeee9c7a93f412ee94b9cc26e5b59dea23848e9f28" +checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc" dependencies = [ "addr2line", "cfg-if 1.0.0", "libc", - "miniz_oxide 0.4.3", + "miniz_oxide 0.4.4", "object", "rustc-demangle", ] @@ -184,6 +183,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + [[package]] name = "bitflags" version = "1.2.1" @@ -199,16 +204,16 @@ dependencies = [ "block-padding", "byte-tools", "byteorder", - "generic-array", + "generic-array 0.12.4", ] [[package]] -name = "block-cipher-trait" -version = "0.6.2" +name = "block-buffer" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array", + "generic-array 0.14.4", ] [[package]] @@ -228,15 +233,15 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytemuck" -version = "1.4.1" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41aa2ec95ca3b5c54cf73c91acf06d24f4495d5f1b1c12506ae3483d646177ac" +checksum = "bed57e2090563b83ba8f83366628ce535a7584c9afa4c9fc0612a03925c6df58" [[package]] name = "byteorder" -version = "1.3.4" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" @@ -251,9 +256,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.61" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed67cbde08356238e75fc4656be4749481eeffb09e19f320a25237d5221c985d" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" [[package]] name = "cfg-if" @@ -280,6 +285,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "cipher" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +dependencies = [ + "generic-array 0.14.4", +] + [[package]] name = "clap" version = "2.33.3" @@ -322,24 +336,18 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "const_fn" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce90df4c658c62f12d78f7508cf92f9173e5184a539c10bfe54a3107b3ffd0f2" - [[package]] name = "cookie" -version = "0.11.3" +version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5795cda0897252e34380a27baf884c53aa7ad9990329cdad96d4c5d027015d44" +checksum = "80f6044740a4a516b8aac14c140cdf35c1a640b1bd6b98b6224e49143b2f1566" dependencies = [ "aes-gcm", - "base64 0.12.3", + "base64 0.13.0", "hkdf", "hmac", "percent-encoding 2.1.0", - "rand 0.7.3", + "rand 0.8.3", "sha2", "time", ] @@ -363,7 +371,7 @@ dependencies = [ "cookie 0.12.0", "failure", "idna 0.1.5", - "log 0.4.11", + "log 0.4.14", "publicsuffix", "serde", "serde_json", @@ -374,9 +382,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" dependencies = [ "core-foundation-sys", "libc", @@ -384,9 +392,21 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.7.0" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" + +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" + +[[package]] +name = "cpuid-bool" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" +checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" [[package]] name = "crc32fast" @@ -404,7 +424,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" dependencies = [ "cfg-if 1.0.0", - "crossbeam-utils 0.8.0", + "crossbeam-utils 0.8.3", ] [[package]] @@ -425,8 +445,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9" dependencies = [ "cfg-if 1.0.0", - "crossbeam-epoch 0.9.0", - "crossbeam-utils 0.8.0", + "crossbeam-epoch 0.9.3", + "crossbeam-utils 0.8.3", ] [[package]] @@ -440,21 +460,20 @@ dependencies = [ "crossbeam-utils 0.7.2", "lazy_static", "maybe-uninit", - "memoffset", + "memoffset 0.5.6", "scopeguard", ] [[package]] name = "crossbeam-epoch" -version = "0.9.0" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0f606a85340376eef0d6d8fec399e6d4a544d648386c6645eb6d0653b27d9f" +checksum = "2584f639eb95fea8c798496315b297cf81b9b58b6d30ab066a75455333cf4b12" dependencies = [ "cfg-if 1.0.0", - "const_fn", - "crossbeam-utils 0.8.0", + "crossbeam-utils 0.8.3", "lazy_static", - "memoffset", + "memoffset 0.6.1", "scopeguard", ] @@ -482,24 +501,32 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.0" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec91540d98355f690a86367e566ecad2e9e579f230230eb7c21398372be73ea5" +checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" dependencies = [ "autocfg 1.0.1", "cfg-if 1.0.0", - "const_fn", "lazy_static", ] [[package]] name = "crypto-mac" -version = "0.7.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6" dependencies = [ - "generic-array", - "subtle 1.0.0", + "generic-array 0.14.4", + "subtle", +] + +[[package]] +name = "ctr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f" +dependencies = [ + "cipher", ] [[package]] @@ -550,14 +577,23 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" dependencies = [ - "generic-array", + "generic-array 0.12.4", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array 0.14.4", ] [[package]] name = "dtoa" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" +checksum = "88d7ed2934d741c6b37e33e3832298e8850b53fd2d2bea03873375596c7cea4e" [[package]] name = "either" @@ -567,20 +603,11 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "encoding_rs" -version = "0.8.24" +version = "0.8.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a51b8cf747471cb9499b6d59e59b0444f4c90eba8968c4e44874e92b5b64ace2" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" dependencies = [ - "cfg-if 0.1.10", -] - -[[package]] -name = "error-chain" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" -dependencies = [ - "version_check 0.9.2", + "cfg-if 1.0.0", ] [[package]] @@ -618,31 +645,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e69ab0d5aca163e388c3a49d284fed6c3d0810700e77c5ae2756a50ec1a4daaa" dependencies = [ "chrono", - "log 0.4.11", + "log 0.4.14", ] [[package]] name = "filetime" -version = "0.2.12" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed85775dcc68644b5c950ac06a2b23768d3bc9390464151aaf27136998dcf9e" +checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", - "redox_syscall", + "redox_syscall 0.2.5", "winapi 0.3.9", ] [[package]] name = "flate2" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da80be589a72651dcda34d8b35bcdc9b7254ad06325611074d9cc0fbb19f60ee" +checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "crc32fast", "libc", - "miniz_oxide 0.4.3", + "miniz_oxide 0.4.4", ] [[package]] @@ -651,6 +678,16 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "fontdue" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3203e88e086474e56b0785255804a0c23542f76253584d3f43152cd2bb95d0b7" +dependencies = [ + "hashbrown 0.8.2", + "ttf-parser", +] + [[package]] name = "foreign-types" version = "0.3.2" @@ -666,6 +703,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding 2.1.0", +] + [[package]] name = "fsevent" version = "0.4.0" @@ -709,9 +756,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "futures" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7e4c2612746b0df8fed4ce0c69156021b704c9aefa360311c04e6e9e002eed" +checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" [[package]] name = "futures-cpupool" @@ -725,30 +772,52 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.12.3" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" dependencies = [ "typenum", + "version_check 0.9.3", ] [[package]] name = "getrandom" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] +[[package]] +name = "getrandom" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", +] + [[package]] name = "ghash" -version = "0.2.3" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f0930ed19a7184089ea46d2fedead2f6dc2b674c5db4276b7da336c7cd83252" +checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375" dependencies = [ + "opaque-debug 0.3.0", "polyval", ] @@ -776,7 +845,7 @@ dependencies = [ "futures", "http", "indexmap", - "log 0.4.11", + "log 0.4.14", "slab", "string", "tokio-io", @@ -792,6 +861,16 @@ dependencies = [ "autocfg 1.0.1", ] +[[package]] +name = "hashbrown" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25" +dependencies = [ + "ahash", + "autocfg 1.0.1", +] + [[package]] name = "hashbrown" version = "0.9.1" @@ -800,9 +879,9 @@ checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" [[package]] name = "hermit-abi" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] @@ -819,22 +898,22 @@ dependencies = [ [[package]] name = "hkdf" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fa08a006102488bd9cd5b8013aabe84955cf5ae22e304c2caf655b633aefae3" +checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" dependencies = [ - "digest", + "digest 0.9.0", "hmac", ] [[package]] name = "hmac" -version = "0.7.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" +checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" dependencies = [ "crypto-mac", - "digest", + "digest 0.9.0", ] [[package]] @@ -862,9 +941,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.3.4" +version = "1.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" [[package]] name = "hyper" @@ -887,9 +966,9 @@ dependencies = [ [[package]] name = "hyper" -version = "0.12.35" +version = "0.12.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6" +checksum = "5c843caf6296fc1f93444735205af9ed4e109a539005abb2564ae1d6fad34c52" dependencies = [ "bytes", "futures", @@ -900,7 +979,7 @@ dependencies = [ "httparse", "iovec", "itoa", - "log 0.4.11", + "log 0.4.14", "net2", "rustc_version", "time", @@ -923,7 +1002,7 @@ checksum = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" dependencies = [ "bytes", "futures", - "hyper 0.12.35", + "hyper 0.12.36", "native-tls", "tokio-io", ] @@ -941,9 +1020,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" dependencies = [ "matches", "unicode-bidi", @@ -952,9 +1031,9 @@ dependencies = [ [[package]] name = "image" -version = "0.23.11" +version = "0.23.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4f0a8345b33b082aedec2f4d7d4a926b845cee184cbe78b703413066564431b" +checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" dependencies = [ "bytemuck", "byteorder", @@ -967,9 +1046,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.0" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg 1.0.1", "hashbrown 0.9.1", @@ -988,9 +1067,9 @@ dependencies = [ [[package]] name = "inotify-sys" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e74a1aa87c59aeff6ef2cc2fa62d41bc43f54952f55652656b18a02fd5e356c0" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" dependencies = [ "libc", ] @@ -1006,9 +1085,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "kernel32-sys" @@ -1040,15 +1119,15 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.80" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" +checksum = "ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae" [[package]] name = "linked_list_allocator" -version = "0.8.6" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84565678e403453d1a27a0886882b3b271701e65146d972d9d7d9a4c4a0ff498" +checksum = "822add9edb1860698b79522510da17bef885171f75aa395cff099d770c609c24" dependencies = [ "spinning_top", ] @@ -1079,18 +1158,24 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" dependencies = [ - "log 0.4.11", + "log 0.4.14", ] [[package]] name = "log" -version = "0.4.11" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", ] +[[package]] +name = "lru" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f374d42cdfc1d7dbf3d3dec28afab2eb97ffbf43a3234d795b5986dbf4b90ba" + [[package]] name = "matches" version = "0.1.8" @@ -1118,6 +1203,15 @@ dependencies = [ "autocfg 1.0.1", ] +[[package]] +name = "memoffset" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87" +dependencies = [ + "autocfg 1.0.1", +] + [[package]] name = "mime" version = "0.2.6" @@ -1154,9 +1248,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" dependencies = [ "adler", "autocfg 1.0.1", @@ -1164,9 +1258,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.6.22" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fce347092656428bc8eaf6201042cb551b8d67855af7374542a92a0fbfcac430" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" dependencies = [ "cfg-if 0.1.10", "fuchsia-zircon", @@ -1174,7 +1268,7 @@ dependencies = [ "iovec", "kernel32-sys", "libc", - "log 0.4.11", + "log 0.4.14", "miow", "net2", "slab", @@ -1188,16 +1282,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" dependencies = [ "lazycell", - "log 0.4.11", + "log 0.4.14", "mio", "slab", ] [[package]] name = "miow" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" dependencies = [ "kernel32-sys", "net2", @@ -1213,13 +1307,13 @@ checksum = "a785740271256c230f57462d3b83e52f998433a7062fc18f96d5999474a9f915" [[package]] name = "native-tls" -version = "0.2.4" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d" +checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" dependencies = [ "lazy_static", "libc", - "log 0.4.11", + "log 0.4.14", "openssl", "openssl-probe", "openssl-sys", @@ -1231,9 +1325,9 @@ dependencies = [ [[package]] name = "net2" -version = "0.2.35" +version = "0.2.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ebc3ec692ed7c9a255596c67808dee269f64655d8baf7b4f0638e51ba1d6853" +checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" dependencies = [ "cfg-if 0.1.10", "libc", @@ -1246,7 +1340,7 @@ version = "0.3.3" source = "git+https://github.com/squirrel-labs/web_worker/?branch=feature/remove-wasm-bindgen#a1b20a4ef8710cd099237cb90c2814fa2895ffb9" dependencies = [ "futures", - "log 0.4.11", + "log 0.4.14", "rayon", "rayon-core", "spin", @@ -1259,7 +1353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" dependencies = [ "memchr", - "version_check 0.9.2", + "version_check 0.9.3", ] [[package]] @@ -1303,9 +1397,9 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5fa6d5f418879385b213d905f7cf5bf4aa553d4c380f0152d1d4f2749186fa9" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" dependencies = [ "autocfg 1.0.1", "num-integer", @@ -1333,9 +1427,15 @@ dependencies = [ [[package]] name = "object" -version = "0.22.0" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" + +[[package]] +name = "once_cell" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" [[package]] name = "opaque-debug" @@ -1343,17 +1443,23 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "openssl" -version = "0.10.30" +version = "0.10.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4" +checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577" dependencies = [ "bitflags", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "foreign-types", - "lazy_static", "libc", + "once_cell", "openssl-sys", ] @@ -1365,9 +1471,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-sys" -version = "0.9.58" +version = "0.9.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de" +checksum = "313752393519e876837e09e1fa183ddef0be7735868dced3196f4472d536277f" dependencies = [ "autocfg 1.0.1", "cc", @@ -1418,9 +1524,9 @@ dependencies = [ "cfg-if 0.1.10", "cloudabi", "libc", - "redox_syscall", + "redox_syscall 0.1.57", "rustc_version", - "smallvec 0.6.13", + "smallvec 0.6.14", "winapi 0.3.9", ] @@ -1442,7 +1548,7 @@ dependencies = [ "proc-macro2 0.4.30", "quote 0.6.13", "syn 0.15.44", - "version_check 0.9.2", + "version_check 0.9.3", "yansi", ] @@ -1466,9 +1572,9 @@ checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "png" -version = "0.16.7" +version = "0.16.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfe7f9f1c730833200b134370e1d5098964231af8450bce9b78ee3ab5278b970" +checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" dependencies = [ "bitflags", "crc32fast", @@ -1478,19 +1584,20 @@ dependencies = [ [[package]] name = "polyval" -version = "0.3.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ec3341498978de3bfd12d1b22f1af1de22818f5473a11e8a6ef997989e3a212" +checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd" dependencies = [ - "cfg-if 0.1.10", + "cpuid-bool 0.2.0", + "opaque-debug 0.3.0", "universal-hash", ] [[package]] name = "ppv-lite86" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" [[package]] name = "proc-macro2" @@ -1512,15 +1619,12 @@ dependencies = [ [[package]] name = "publicsuffix" -version = "1.5.4" +version = "1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bbaa49075179162b49acac1c6aa45fb4dafb5f13cf6794276d77bc7fd95757b" +checksum = "95b4ce31ff0a27d93c8de1849cf58162283752f065a90d508f1105fa6c9a213f" dependencies = [ - "error-chain", - "idna 0.2.0", - "lazy_static", - "regex", - "url 2.1.1", + "idna 0.2.2", + "url 2.2.1", ] [[package]] @@ -1566,13 +1670,25 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.16", "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", "rand_hc 0.2.0", ] +[[package]] +name = "rand" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +dependencies = [ + "libc", + "rand_chacha 0.3.0", + "rand_core 0.6.2", + "rand_hc 0.3.0", +] + [[package]] name = "rand_chacha" version = "0.1.1" @@ -1593,6 +1709,16 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_chacha" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.2", +] + [[package]] name = "rand_core" version = "0.3.1" @@ -1614,7 +1740,16 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom 0.2.2", ] [[package]] @@ -1635,6 +1770,15 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_hc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" +dependencies = [ + "rand_core 0.6.2", +] + [[package]] name = "rand_isaac" version = "0.1.1" @@ -1692,9 +1836,11 @@ dependencies = [ name = "rask-engine" version = "0.2.0" dependencies = [ + "fontdue", "image", "lazy_static", - "log 0.4.11", + "log 0.4.14", + "lru", "ouroboros", "rayon", "specs", @@ -1710,7 +1856,7 @@ dependencies = [ "clap", "colored", "fern", - "log 0.4.11", + "log 0.4.14", "rask-engine", "reqwest", "serde", @@ -1723,7 +1869,7 @@ version = "0.1.0" dependencies = [ "lazy_static", "linked_list_allocator", - "log 0.4.11", + "log 0.4.14", "nobg-web_worker", "rask-engine", "rayon", @@ -1752,7 +1898,7 @@ checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a" dependencies = [ "crossbeam-channel", "crossbeam-deque 0.8.0", - "crossbeam-utils 0.8.0", + "crossbeam-utils 0.8.3", "lazy_static", "num_cpus", ] @@ -1778,23 +1924,31 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "redox_syscall" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" -version = "1.4.1" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8963b85b8ce3074fecffde43b4b0dded83ce2f367dc8d363afc56679f3ee820b" +checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", ] [[package]] name = "regex-syntax" -version = "0.6.20" +version = "0.6.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cab7a364d15cde1e505267766a2d3c4e22a843e1a601f0fa7564c0f82ced11c" +checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] name = "remove_dir_all" @@ -1819,9 +1973,9 @@ dependencies = [ "flate2", "futures", "http", - "hyper 0.12.35", + "hyper 0.12.36", "hyper-tls", - "log 0.4.11", + "log 0.4.14", "mime 0.3.16", "mime_guess", "native-tls", @@ -1841,13 +1995,13 @@ dependencies = [ [[package]] name = "rocket" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6130967b369cfb8411b0b73e96fcba1229c32a9cc6f295d144f879bfced13c6e" +checksum = "7febfdfd4d43facfc7daba20349ebe2c310c6735bd6a2a9255ea8bc425b4cb13" dependencies = [ "atty", "base64 0.12.3", - "log 0.4.11", + "log 0.4.14", "memchr", "num_cpus", "pear", @@ -1856,32 +2010,32 @@ dependencies = [ "state", "time", "toml", - "version_check 0.9.2", + "version_check 0.9.3", "yansi", ] [[package]] name = "rocket_codegen" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb852e6da168fb948a8f2b798ba2e2f0e4fc860eae0efa9cf2bf0f5466bb0425" +checksum = "ceac2c55b2c8b1cdc53add64332defa5fc227f64263b86b4114d1386286d42a3" dependencies = [ "devise", "glob", "indexmap", "quote 0.6.13", "rocket_http", - "version_check 0.9.2", + "version_check 0.9.3", "yansi", ] [[package]] name = "rocket_contrib" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3946ca815127041d8f64455561031d058c22ae1b135251502c5ea523cf9e14b" +checksum = "d7954a707f9ca18aa74ca8c1f5d1f900f52a4dceb68e96e3112143f759cfd20e" dependencies = [ - "log 0.4.11", + "log 0.4.14", "notify", "rocket", "serde", @@ -1890,16 +2044,16 @@ dependencies = [ [[package]] name = "rocket_http" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aff5a5480175f2f553a876b251e9350c74196128806d176da3a51c82aab5428" +checksum = "ce364100ed7a1bf39257b69ebd014c1d5b4979b0d365d8c9ab0aa9c79645493d" dependencies = [ - "cookie 0.11.3", + "cookie 0.11.4", "hyper 0.10.16", "indexmap", "pear", "percent-encoding 1.0.1", - "smallvec 1.4.2", + "smallvec 1.6.1", "state", "time", "unicode-xid 0.1.0", @@ -1965,9 +2119,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "0.4.4" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64808902d7d99f78eaddd2b4e2509713babc3dc3c85ad6f4c447680f3c01e535" +checksum = "d493c5f39e02dfb062cd8f33301f90f9b13b650e8c1b1d0fd75c19dd64bff69d" dependencies = [ "bitflags", "core-foundation", @@ -1978,9 +2132,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "0.4.3" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17bf11d99252f512695eb468de5516e5cf75455521e69dfe343f3b74e4748405" +checksum = "dee48cdde5ed250b0d3252818f646e174ab414036edb884dde62d80a3ac6082d" dependencies = [ "core-foundation-sys", "libc", @@ -2003,18 +2157,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.117" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a" +checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.117" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e" +checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", @@ -2023,9 +2177,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.59" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "itoa", "ryu", @@ -2050,22 +2204,23 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" dependencies = [ - "block-buffer", - "digest", + "block-buffer 0.7.3", + "digest 0.8.1", "fake-simd", - "opaque-debug", + "opaque-debug 0.2.3", ] [[package]] name = "sha2" -version = "0.8.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de" dependencies = [ - "block-buffer", - "digest", - "fake-simd", - "opaque-debug", + "block-buffer 0.9.0", + "cfg-if 1.0.0", + "cpuid-bool 0.1.2", + "digest 0.9.0", + "opaque-debug 0.3.0", ] [[package]] @@ -2079,7 +2234,7 @@ dependencies = [ "mopa", "rayon", "shred-derive", - "smallvec 1.4.2", + "smallvec 1.6.1", "tynm", ] @@ -2108,18 +2263,18 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" +checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0" dependencies = [ "maybe-uninit", ] [[package]] name = "smallvec" -version = "1.4.2" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "specs" @@ -2130,7 +2285,7 @@ dependencies = [ "crossbeam-queue", "hashbrown 0.7.2", "hibitset", - "log 0.4.11", + "log 0.4.14", "rayon", "shred", "shrev", @@ -2215,15 +2370,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "subtle" -version = "1.0.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" - -[[package]] -name = "subtle" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" @@ -2261,14 +2410,14 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", - "rand 0.7.3", - "redox_syscall", + "rand 0.8.3", + "redox_syscall 0.2.5", "remove_dir_all", "winapi 0.3.9", ] @@ -2283,30 +2432,29 @@ dependencies = [ ] [[package]] -name = "thread_local" -version = "1.0.1" +name = "time" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ - "lazy_static", + "libc", + "winapi 0.3.9", ] [[package]] -name = "time" -version = "0.1.44" +name = "tinyvec" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi 0.3.9", + "tinyvec_macros", ] [[package]] -name = "tinyvec" -version = "0.3.4" +name = "tinyvec_macros" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "238ce071d267c5710f9d31451efec16c5ee22de34df17cc05e56cbc92e967117" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" @@ -2366,7 +2514,7 @@ checksum = "57fc868aae093479e3131e3d165c93b1c7474109d13c90ec0dda2a1bbfff0674" dependencies = [ "bytes", "futures", - "log 0.4.11", + "log 0.4.14", ] [[package]] @@ -2378,7 +2526,7 @@ dependencies = [ "crossbeam-utils 0.7.2", "futures", "lazy_static", - "log 0.4.11", + "log 0.4.14", "mio", "num_cpus", "parking_lot", @@ -2423,7 +2571,7 @@ dependencies = [ "crossbeam-utils 0.7.2", "futures", "lazy_static", - "log 0.4.11", + "log 0.4.14", "num_cpus", "slab", "tokio-executor", @@ -2471,6 +2619,12 @@ dependencies = [ "cfg-if 0.1.10", ] +[[package]] +name = "ttf-parser" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7622061403fd00f0820df288e5a580e87d3ce15a1c4313c59fd1ffb77129903f" + [[package]] name = "tuple_utils" version = "0.3.0" @@ -2494,9 +2648,9 @@ checksum = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" [[package]] name = "typenum" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" [[package]] name = "unicase" @@ -2513,7 +2667,7 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" dependencies = [ - "version_check 0.9.2", + "version_check 0.9.3", ] [[package]] @@ -2527,9 +2681,9 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.13" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" dependencies = [ "tinyvec", ] @@ -2554,12 +2708,12 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "universal-hash" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0c900f2f9b4116803415878ff48b63da9edb268668e08cf9292d7503114a01" +checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" dependencies = [ - "generic-array", - "subtle 2.3.0", + "generic-array 0.14.4", + "subtle", ] [[package]] @@ -2575,11 +2729,12 @@ dependencies = [ [[package]] name = "url" -version = "2.1.1" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" dependencies = [ - "idna 0.2.0", + "form_urlencoded", + "idna 0.2.2", "matches", "percent-encoding 2.1.0", ] @@ -2595,9 +2750,9 @@ dependencies = [ [[package]] name = "vcpkg" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" +checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" [[package]] name = "vec_map" @@ -2613,9 +2768,9 @@ checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" [[package]] name = "version_check" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" [[package]] name = "walkdir" @@ -2635,7 +2790,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" dependencies = [ "futures", - "log 0.4.11", + "log 0.4.14", "try-lock", ] @@ -2647,9 +2802,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-sync" @@ -2721,14 +2876,14 @@ dependencies = [ "byteorder", "bytes", "httparse", - "log 0.4.11", + "log 0.4.14", "mio", "mio-extras", "openssl", "rand 0.7.3", "sha-1", "slab", - "url 2.1.1", + "url 2.2.1", ] [[package]] @@ -2752,9 +2907,3 @@ name = "yansi" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fc79f4a1e39857fc00c3f662cbf2651c771f00e9c15fe2abc341806bd46bd71" - -[[package]] -name = "zeroize" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f33972566adbd2d3588b0491eb94b98b43695c4ef897903470ede4f3f5a28a" diff --git a/rask-engine/Cargo.toml b/rask-engine/Cargo.toml index eb1cb8d0..4fbaac39 100644 --- a/rask-engine/Cargo.toml +++ b/rask-engine/Cargo.toml @@ -21,6 +21,9 @@ git = "https://github.com/squirrel-labs/spine-rs" branch = "transitions" version = "=0.1.2" +[dependencies.lru] +version = "0.6" +default_features = false [dependencies] log = "0.4" @@ -28,4 +31,5 @@ rayon = "1.5" lazy_static = "1.4.0" ouroboros = "0.5" specs-hierarchy = "0.6" +fontdue = "0.4" spin = {version = "0.5", optional = false} diff --git a/rask-engine/src/engine/mod.rs b/rask-engine/src/engine/mod.rs index 134efb8e..df970456 100644 --- a/rask-engine/src/engine/mod.rs +++ b/rask-engine/src/engine/mod.rs @@ -39,6 +39,7 @@ impl GameEngine for RaskEngine { fn new(pool: std::sync::Arc, mut system: Box) -> Self { system.fetch_resource(registry::EMPTY).unwrap(); system.fetch_resource(registry::SOUND).unwrap(); + system.fetch_resource(registry::PIXELFONT).unwrap(); system.fetch_character_resource(registry::CHAR).unwrap(); let mut world: specs::World = specs::WorldExt::new(); diff --git a/rask-engine/src/error.rs b/rask-engine/src/error.rs index c55b9a9b..1c295707 100644 --- a/rask-engine/src/error.rs +++ b/rask-engine/src/error.rs @@ -10,6 +10,7 @@ pub enum EngineError { ResourceMissing(String), ResourceType(String), ResourceFetchConflict(String), + Font(String), MathError(String), Network(String), Misc(String), @@ -23,6 +24,7 @@ impl Display for EngineError { EngineError::ResourceFormat(e) => write!(f, "ResourceError: {}", e), EngineError::ResourceIndex(e) => write!(f, "ResourceError: {}", e), EngineError::ResourceMissing(e) => write!(f, "ResourceError: {}", e), + EngineError::Font(e) => write!(f, "Failed to parse font: {}", e), EngineError::ResourceType(e) => write!(f, "ResourceError: {}", e), EngineError::ResourceFetchConflict(e) => write!(f, "Resource fetching conflict: {}", e), EngineError::Misc(e) => write!(f, "EngineError: {}", e), diff --git a/rask-engine/src/network/protocol.rs b/rask-engine/src/network/protocol.rs index 9859ff8f..830a9bfe 100644 --- a/rask-engine/src/network/protocol.rs +++ b/rask-engine/src/network/protocol.rs @@ -4,5 +4,6 @@ pub mod resource_types { pub const TEXTURE: u32 = 2; pub const CHARACTER: u32 = 3; pub const SOUND: u32 = 4; + pub const FONT: u32 = 5; } pub mod op_codes; diff --git a/rask-engine/src/resources/font.rs b/rask-engine/src/resources/font.rs new file mode 100644 index 00000000..3fcdb5b2 --- /dev/null +++ b/rask-engine/src/resources/font.rs @@ -0,0 +1,54 @@ +use super::Texture; +use crate::error::EngineError; +use fontdue::{layout::GlyphPosition, Font as FFont, FontSettings, Metrics}; +use lru::LruCache; +use std::collections::hash_map::DefaultHasher; +use std::hash::{Hash, Hasher}; + +const FONTCACHESIZE: usize = 128; + +pub struct Font { + font: FFont, + cache: LruCache, +} + +impl Font { + pub fn new(data: &[u8]) -> Result { + let font = FFont::from_bytes(data, FontSettings::default())?; + + Ok(Self { + font, + cache: LruCache::new(FONTCACHESIZE), + }) + } + + /// Stores the glyph in the cache and return the texture subid + pub fn store_gyph(&mut self, glyph: GlyphPosition) -> u64 { + let mut s = DefaultHasher::new(); + glyph.key.hash(&mut s); + let key = s.finish(); + if !self.cache.contains(&key) { + let (metrics, data) = self.font.rasterize_config(glyph.key); + let tex = Texture::form_raw_parts( + data, + metrics.width as u32, + metrics.height as u32, + image::ColorType::L8, + ); + + self.cache.put(key, (metrics, tex)); + } + key + } + + pub fn get_glyph_metrics(&self, key: u64) -> Option<&Metrics> { + self.cache.peek(&key).map(|x| &x.0) + } + pub fn get_glyph_data(&self, key: u64) -> Option<&Texture> { + self.cache.peek(&key).map(|x| &x.1) + } + + pub fn cache(&self) -> &LruCache { + &self.cache + } +} diff --git a/rask-engine/src/resources/mod.rs b/rask-engine/src/resources/mod.rs index a5accf0f..773c65d6 100644 --- a/rask-engine/src/resources/mod.rs +++ b/rask-engine/src/resources/mod.rs @@ -21,6 +21,7 @@ fn test() { */ pub mod character; +pub mod font; pub mod registry; mod resource_table; pub mod sound; @@ -30,6 +31,8 @@ pub mod texture; #[doc(inline)] pub use character::Character; #[doc(inline)] +pub use font::Font; +#[doc(inline)] pub use registry::RESOURCE_COUNT; #[doc(inline)] pub use resource_table::{GetStore, GetTextures, ResourceTable}; @@ -57,4 +60,5 @@ pub enum Resource { Character(Box), Texture(Texture), Sound(Sound), + Font(Font), } diff --git a/rask-engine/src/resources/registry.rs b/rask-engine/src/resources/registry.rs index dff41d9d..eebea8d4 100644 --- a/rask-engine/src/resources/registry.rs +++ b/rask-engine/src/resources/registry.rs @@ -36,6 +36,7 @@ resources! { (EMPTY, Texture, "empty.png" ), (THIEF, Texture, "thief.png" ), (SOUND, Sound, "theme_song.mp3" ), + (PIXELFONT, Font, "pixel.ttf" ), (CHAR, Character, Character { texture: "Thief/Thief.png", atlas: "Thief/Thief.atlas", @@ -53,6 +54,7 @@ pub enum ResourceVariant { Texture = resource_types::TEXTURE, Character = resource_types::CHARACTER, Sound = resource_types::SOUND, + Font = resource_types::FONT, } #[derive(Debug, Clone, Copy)] diff --git a/rask-engine/src/resources/resource_table.rs b/rask-engine/src/resources/resource_table.rs index f1723259..eb8cf710 100644 --- a/rask-engine/src/resources/resource_table.rs +++ b/rask-engine/src/resources/resource_table.rs @@ -107,6 +107,7 @@ impl ResourceTable { get_store!(super::Texture, Texture); get_store!(super::Sound, Sound); get_store!(Box, Character); +get_store!(super::Font, Font); impl GetTextures for ResourceTable { fn get_textures + Debug + Copy>( @@ -119,6 +120,9 @@ impl GetTextures for ResourceTable { Resource::Character(value) => { Ok(value.atlas().iter().map(|(id, t)| (*id, t)).collect()) } + Resource::Font(value) => { + Ok(value.cache().iter().map(|(id, (_, t))| (*id, t)).collect()) + } Resource::None => Err(EngineError::ResourceMissing(format!( "Could not find requested resource #{}", id.into(), @@ -140,7 +144,13 @@ impl GetTextures for ResourceTable { Resource::Texture(value) => Ok(value), Resource::Character(value) => value.atlas().get(&sid).ok_or_else(|| { EngineError::ResourceIndex(format!( - "Invalid subtexture id #{} of texture #{:?}", + "Invalid subtexture id #{} of character #{:?}", + sid, id + )) + }), + Resource::Font(value) => value.get_glyph_data(sid).ok_or_else(|| { + EngineError::ResourceIndex(format!( + "Invalid subtexture id #{} of font #{:?}", sid, id )) }), diff --git a/wasm/res/pixel.ttf b/wasm/res/pixel.ttf new file mode 100644 index 0000000000000000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y%qfy$zbz@E};-Hw9?uEg^jQ9(&ZU0_j1fXykT%U@jaIZMMO%DrZw}>Ho zf&yTSLlA#sX4n)@h4FQvP!x5)SS)HhZQ)*VHy(AV?@-r(mk!B$;d}CCP3i!8ez}Ny z;nK8V6^_U0#0?xI7eWU_=$dkYgyUYe4JQbGz8$u0A80BJQ+UIuoUPp>jWpS1p06)Y&cfN;r-qF6`jd8FAXde_G>cC~AqPiX<>K zal%Z}4lb5R&=&6HWSm3>6Ry*}@Fp$>c8%C*JLHjs(u~@8KY(0JI%d1BxUl0!FmW60 z;C})&)Hn*6r4}dfi*Ps*N>QV6FWaUqT-VLw6=}BMRF=(QsA&ZAisD&>s-w=v^Q*=0faX4_FBFm2Jja;}{d_X@LIp57`GiXt*%(-bRE zFQJ$lMa3Vk?mCDaT9%WG-CpkAhZQ~Lxg+MmlcpJ8i&0kOdK@fHvN ziT!t ResourceParser::parse_char(data)?, _ => { return Err(EngineError::ResourceFormat( - "unknown ResourceType while parsing".into(), + "unknown ResourceType while parsing websocket packet".into(), )); } } @@ -151,7 +151,16 @@ impl ResourceParser { id )) })?; - ResourceParser::store_owned_texture(parent_id, data)? + ResourceParser::store_owned_texture(parent_id, data) + } + ResourceVariant::Font => { + let data = self.pop_buffer(id).ok_or_else(|| { + EngineError::ResourceFetchConflict(format!( + "Tried to parse resource id {} for wich no buffer is allocated", + id + )) + })?; + ResourceParser::store_owned_font(parent_id, data) } ResourceVariant::Character => { let parts = self.char_parts_table.get_mut(&parent_id).unwrap(); @@ -194,14 +203,21 @@ impl ResourceParser { Ok(()) } - fn store_owned_texture(id: u32, image: Vec) -> Result<(), EngineError> { + fn store_owned_texture(id: u32, image: Vec) { log::debug!("decoding texture {} len: {}", id, image.len()); rayon::spawn(move || { log::debug!("{}", image.len()); let img = Texture::from_memory(image.as_slice()).unwrap(); RESOURCE_TABLE.write().store(img, id as usize).unwrap(); }); - Ok(()) + } + + fn store_owned_font(id: u32, font: Vec) { + log::debug!("parsing font {} len: {}", id, font.len()); + rayon::spawn(move || { + let img = Font::new(font.as_slice()).unwrap(); + RESOURCE_TABLE.write().store(img, id as usize).unwrap(); + }); } fn parse_char(res: packet::NetworkResource) -> Result<(), EngineError> { From 8e8304c787925c56dbe4d26f5a3e334acb37b547 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Tue, 5 Jan 2021 18:38:42 +0100 Subject: [PATCH 2/5] Add TextRenderSystem --- rask-engine/src/engine/components.rs | 33 +++++ rask-engine/src/engine/mod.rs | 16 +++ rask-engine/src/engine/systems.rs | 172 +++++++++++++++++++++++++-- rask-engine/src/resources/font.rs | 13 +- wasm/src/graphics/renderer.rs | 1 + wasm/src/graphics/webgl/mod.rs | 11 +- 6 files changed, 235 insertions(+), 11 deletions(-) diff --git a/rask-engine/src/engine/components.rs b/rask-engine/src/engine/components.rs index 07353fdc..c791c434 100644 --- a/rask-engine/src/engine/components.rs +++ b/rask-engine/src/engine/components.rs @@ -61,14 +61,47 @@ pub struct Animation { pub animation: String, pub start: f32, } + #[derive(Debug, Clone, Component)] #[storage(VecStorage)] pub struct Scale(pub Vec2); +#[derive(Debug, Clone)] +pub struct TextBox { + pub font: ResourceInfo, + pub content: String, + pub fontsize: f32, + pub color: u32, + pub width: Option, + pub height: Option, +} + +impl Component for TextBox { + type Storage = FlaggedStorage>; +} + +impl Default for TextBox { + fn default() -> Self { + Self { + font: crate::resources::registry::PIXELFONT, + content: String::new(), + fontsize: 40.0, + color: core::u32::MAX, + width: None, + height: None, + } + } +} + +#[derive(Debug, Default, Clone, Copy, Component)] +#[storage(NullStorage)] +pub struct Glyph; + #[derive(Debug, Clone, Component)] #[storage(VecStorage)] pub struct Sprite { pub id: u32, + pub sub_id: u64, } #[derive(Debug, Default, Clone, Copy, Component)] diff --git a/rask-engine/src/engine/mod.rs b/rask-engine/src/engine/mod.rs index df970456..59570935 100644 --- a/rask-engine/src/engine/mod.rs +++ b/rask-engine/src/engine/mod.rs @@ -55,6 +55,7 @@ impl GameEngine for RaskEngine { .with(CheckPresentSystem, "check_present", &[]) // does not depend on anything, because resource parsing is handled asynchronously .with(HierarchySystem::::new(&mut world), "hierarchy", &[]) .with(UpdateAnimationSystem, "update_anim", &["check_present"]) + .with(TextRenderSystem::default(), "textbox", &["check_present"]) .with(MovementSystem, "movement", &["events"]) .with(GravitationSystem, "gravitation", &["movement"]) .with(VelocitySystem, "velocity", &["gravitation"]) @@ -67,10 +68,25 @@ impl GameEngine for RaskEngine { .with(Pos(Vec2::new(0.0, 0.0))) .with(Sprite { id: registry::EMPTY.id, + sub_id: 0, }) .with(Scale(Vec2::new(1.0, 1.0))) .with(Static) .build(); + let _text = world + .create_entity() + .with(Pos(Vec2::new(-0.7, 0.0))) + .with(TextBox { + font: registry::PIXELFONT, + content: String::from("Hallo Welt"), + fontsize: 40.0, + color: core::u32::MAX, + width: None, + height: None, + }) + .with(Scale(Vec2::new(0.1, -0.1))) + .with(Static) + .build(); let _char = world .create_entity() .with(Pos(Vec2::new(0.0, -0.8))) diff --git a/rask-engine/src/engine/systems.rs b/rask-engine/src/engine/systems.rs index 0e60c0fd..57d71f99 100644 --- a/rask-engine/src/engine/systems.rs +++ b/rask-engine/src/engine/systems.rs @@ -5,7 +5,12 @@ use crate::io; use crate::math::{Mat3, Vec2}; use crate::resources::{self, registry, GetStore}; use crate::EngineError; +use core::iter::FromIterator; +use fontdue::layout::{ + CoordinateSystem, HorizontalAlign, Layout, LayoutSettings, TextStyle, VerticalAlign, WrapStyle, +}; use specs::prelude::*; +use specs_hierarchy::Hierarchy; lazy_static::lazy_static! { pub static ref KEYBOARD: Keyboard = Keyboard::new(); @@ -19,6 +24,148 @@ pub struct MovementSystem; pub struct CheckPresentSystem; pub struct UpdateAnimationSystem; +#[derive(Default)] +pub struct TextRenderSystem { + pub modified: BitSet, + pub processed: BitSet, + pub reader_id: Option>, +} + +impl<'a> System<'a> for TextRenderSystem { + type SystemData = ( + ReadStorage<'a, TextBox>, + ReadStorage<'a, Present>, + WriteStorage<'a, Parent>, + WriteStorage<'a, Sprite>, + WriteStorage<'a, Pos>, + WriteStorage<'a, Scale>, + WriteStorage<'a, Glyph>, + ReadExpect<'a, Hierarchy>, + Entities<'a>, + ); + + fn run( + &mut self, + ( + textboxes, + present, + mut parent, + mut sprites, + mut pos, + mut scale, + mut glyps, + hierarchy, + entities, + ): Self::SystemData, + ) { + let events = textboxes.channel().read(self.reader_id.as_mut().unwrap()); + self.processed.clear(); + self.modified.clear(); + + for event in events { + match event { + ComponentEvent::Modified(id) | ComponentEvent::Inserted(id) => { + log::debug!("texbox modified: {}", id); + self.modified.add(*id); + } + ComponentEvent::Removed(_) => (), + } + } + + for (tex, entity, _) in (&textboxes, &self.modified, &present).join() { + let layout_settings = LayoutSettings { + x: 0.0, + y: 0.0, + max_width: tex.width, + max_height: tex.height, + horizontal_align: HorizontalAlign::Left, + vertical_align: VerticalAlign::Top, + wrap_style: WrapStyle::Word, + wrap_hard_breaks: true, + }; + let entity = entities.entity(entity); + let mut layout: Layout<()> = Layout::new(CoordinateSystem::PositiveYUp); + layout.reset(&layout_settings); + assert!(matches!(tex.font.variant, registry::ResourceVariant::Font)); + let res = &mut *resources::RESOURCE_TABLE.write(); + let font: Result<&mut resources::Font, EngineError> = res.get_mut(tex.font.id as usize); + let style = TextStyle::new(&tex.content, tex.fontsize, 0); + if let Ok(font) = font { + layout.append(&[font.font()], &style); + let mut ci = hierarchy.children(entity).iter(); + + let curr_pos = pos + .get(entity) + .expect("Every textbox has to have a position") + .0; + for glyph in layout.glyphs() { + if glyph.char_data.is_whitespace() + || glyph.char_data.is_control() + || glyph.char_data.is_missing() + { + continue; + } + let id = font.store_glyph(glyph); + let (npo, nsp, nsc) = ( + Pos(Vec2::new( + curr_pos.x() + glyph.x / tex.fontsize / 4.0, + curr_pos.y() + glyph.y / tex.fontsize / 4.0, + )), + Sprite { + id: tex.font.id, + sub_id: id, + }, + Scale(Vec2::new( + glyph.width as f32 / -400.0, + glyph.height as f32 / -400.0, + )), + ); + log::debug!("printing: {:?} pos: {:?}", glyph.key.c, npo); + match ci.next().cloned() { + None => { + entities + .build_entity() + .with(npo, &mut pos) + .with(nsp, &mut sprites) + .with(nsc, &mut scale) + .with(Glyph, &mut glyps) + .with(Parent { entity }, &mut parent) + .build(); + } + Some(c) => { + if let Some((pos_, sprite, scale_)) = + (&mut pos, &mut sprites, &mut scale) + .join() + .get(c, &entities) + { + *pos_ = npo; + *sprite = nsp; + *scale_ = nsc; + } else { + unreachable!() + } + } + } + } + for id in ci { + entities.delete(*id).unwrap(); + } + } + } + for (_, e) in (&glyps, &entities).join() { + if parent.get(e).is_none() { + entities.delete(e).unwrap(); + } + } + self.modified ^= &self.processed; + } + + fn setup(&mut self, world: &mut World) { + Self::SystemData::setup(world); + self.reader_id = Some(WriteStorage::::fetch(&world).register_reader()); + } +} + impl<'a> System<'a> for VelocitySystem { type SystemData = ( WriteStorage<'a, Pos>, @@ -97,7 +244,7 @@ impl<'a> System<'a> for RenderSystem { sprites.push(resources::Sprite::new( Mat3::translation(pos.0.x(), pos.0.y()) * Mat3::scaling(scale.0.x(), scale.0.y()), sprite.id, - 0, + sprite.sub_id, )) } let res = &*resources::RESOURCE_TABLE.read(); @@ -165,11 +312,12 @@ impl<'a> System<'a> for CheckPresentSystem { type SystemData = ( ReadStorage<'a, Animation>, ReadStorage<'a, Sprite>, + ReadStorage<'a, TextBox>, Entities<'a>, WriteStorage<'a, Present>, ); - fn run(&mut self, (anim, sprite, entities, mut present): Self::SystemData) { + fn run(&mut self, (anim, sprite, textbox, entities, mut present): Self::SystemData) { let res = &*resources::RESOURCE_TABLE.read(); let mut modified = Vec::new(); @@ -183,6 +331,11 @@ impl<'a> System<'a> for CheckPresentSystem { modified.push(entity); } } + for (textbox, entity, _) in (&textbox, &entities, !&present).join() { + if res.resource_present(textbox.font.id as usize) { + modified.push(entity); + } + } for item in modified { let _ = present .insert(item, Present) @@ -192,20 +345,20 @@ impl<'a> System<'a> for CheckPresentSystem { } impl<'a> System<'a> for EventSystem { - type SystemData = (Write<'a, SystemApi>,); + type SystemData = (Write<'a, SystemApi>, WriteStorage<'a, TextBox>); - fn run(&mut self, mut sys: Self::SystemData) { + fn run(&mut self, (mut sys, mut textboxes): Self::SystemData) { let sys = &mut *sys.0; loop { - let message = sys.0.poll_message().unwrap(); + let message = sys.poll_message().unwrap(); match message { io::Message::None => break, io::Message::SystemInternal => continue, io::Message::Event(event) => { log::trace!("event: {:?}", event); match event { - Event::KeyDown(_, Key::KEY_P) => sys.0.play_sound(registry::SOUND.id), - Event::KeyDown(_, Key::KEY_S) => sys.0.stop_sound(registry::SOUND.id), + Event::KeyDown(_, Key::KEY_P) => sys.play_sound(registry::SOUND.id), + Event::KeyDown(_, Key::KEY_S) => sys.stop_sound(registry::SOUND.id), Event::KeyDown(_, Key::DIGIT1) => { log::set_max_level(log::LevelFilter::Info) } @@ -215,6 +368,11 @@ impl<'a> System<'a> for EventSystem { Event::KeyDown(_, Key::DIGIT3) => { log::set_max_level(log::LevelFilter::Trace) } + Event::KeyDown(_, Key::KEY_A) => { + for t in (&mut textboxes).join() { + t.content += "a" + } + } Event::KeyDown(_, key) => KEYBOARD.set(key, true), Event::KeyUp(_, key) => KEYBOARD.set(key, false), _ => (), diff --git a/rask-engine/src/resources/font.rs b/rask-engine/src/resources/font.rs index 3fcdb5b2..e20fe8f5 100644 --- a/rask-engine/src/resources/font.rs +++ b/rask-engine/src/resources/font.rs @@ -23,17 +23,21 @@ impl Font { } /// Stores the glyph in the cache and return the texture subid - pub fn store_gyph(&mut self, glyph: GlyphPosition) -> u64 { + pub fn store_glyph(&mut self, glyph: &GlyphPosition) -> u64 { let mut s = DefaultHasher::new(); glyph.key.hash(&mut s); let key = s.finish(); if !self.cache.contains(&key) { let (metrics, data) = self.font.rasterize_config(glyph.key); + let mut new_data = Vec::new(); + for d in data { + new_data.append(&mut vec![d, d, d, d]); + } let tex = Texture::form_raw_parts( - data, + new_data, metrics.width as u32, metrics.height as u32, - image::ColorType::L8, + image::ColorType::Rgba8, ); self.cache.put(key, (metrics, tex)); @@ -51,4 +55,7 @@ impl Font { pub fn cache(&self) -> &LruCache { &self.cache } + pub fn font(&self) -> &FFont { + &self.font + } } diff --git a/wasm/src/graphics/renderer.rs b/wasm/src/graphics/renderer.rs index 81092536..68aefe2c 100644 --- a/wasm/src/graphics/renderer.rs +++ b/wasm/src/graphics/renderer.rs @@ -4,6 +4,7 @@ use crate::communication::{RESOURCE_TABLE, SYNCHRONIZATION_MEMORY}; use crate::error::ClientError; use rask_engine::resources::{GetTextures, Texture}; +const RENDER_RESOLUTION: (u32, u32) = (240, 135); type RenderBackend = WebGl2; static mut RENDERER: Option> = None; diff --git a/wasm/src/graphics/webgl/mod.rs b/wasm/src/graphics/webgl/mod.rs index e588b93b..91364539 100644 --- a/wasm/src/graphics/webgl/mod.rs +++ b/wasm/src/graphics/webgl/mod.rs @@ -210,6 +210,9 @@ impl GraphicsApi for WebGl2 { let prev_layer_index = self.layer_index; let empty = self.textures.is_empty(); for texture in textures { + if texture.2.width() == 0 || texture.2.height() == 0 { + continue; + } let rect = self .texture_packer .pack(texture.2.width() as i32, texture.2.height() as i32, false) @@ -223,7 +226,13 @@ impl GraphicsApi for WebGl2 { false, ) }) - .ok_or_else(|| ClientError::WebGlError("texture too large for GPU".to_string()))?; + .ok_or_else(|| { + ClientError::WebGlError(format!( + "texture w:{} h:{} too large for GPU", + texture.2.width(), + texture.2.height() + )) + })?; let tex = ( TextureRange::new( (rect.x as u32, rect.y as u32), From 4b7b1668bc5c061485edafc748a5effb44801517 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Wed, 6 Jan 2021 05:33:27 +0100 Subject: [PATCH 3/5] Fix RenderBuffer size calculation --- rask-engine/src/engine/components.rs | 3 +++ rask-engine/src/engine/mod.rs | 5 ++++- rask-engine/src/engine/systems.rs | 17 ++++++++++------- rask-engine/src/io.rs | 3 +++ rask-engine/src/resources/font.rs | 2 +- wasm/src/graphics/renderer.rs | 6 ++++-- wasm/src/graphics/webgl/mod.rs | 5 +---- wasm/src/logic/system.rs | 4 ++++ 8 files changed, 30 insertions(+), 15 deletions(-) diff --git a/rask-engine/src/engine/components.rs b/rask-engine/src/engine/components.rs index c791c434..7c5724f8 100644 --- a/rask-engine/src/engine/components.rs +++ b/rask-engine/src/engine/components.rs @@ -19,6 +19,9 @@ pub struct DeltaTime(pub std::time::Duration); #[derive(Debug, Default)] pub struct ElapsedTime(pub std::time::Duration); +#[derive(Debug, Default)] +pub struct RenderBufferDimensions(pub (u32, u32)); + pub struct SystemApi(pub(super) Box); impl Default for SystemApi { diff --git a/rask-engine/src/engine/mod.rs b/rask-engine/src/engine/mod.rs index 59570935..aed50cc4 100644 --- a/rask-engine/src/engine/mod.rs +++ b/rask-engine/src/engine/mod.rs @@ -47,6 +47,9 @@ impl GameEngine for RaskEngine { world.insert(DeltaTime(Duration::from_millis(10))); world.insert(ElapsedTime(Duration::from_millis(0))); world.insert(TextureIds(Vec::new())); + world.insert(RenderBufferDimensions( + system.get_render_buffer_dimensions(), + )); world.insert(SystemApi(system)); let mut tick_dispatcher = DispatcherBuilder::new() @@ -111,7 +114,7 @@ impl GameEngine for RaskEngine { fn tick(&mut self, dt: Duration, elapsed: Duration) -> Result<(), EngineError> { *self.world.write_resource::() = DeltaTime(dt); *self.world.write_resource::() = ElapsedTime(elapsed); - self.tick_dispatcher.dispatch(&mut self.world); + self.tick_dispatcher.dispatch(&self.world); self.world.maintain(); Ok(()) } diff --git a/rask-engine/src/engine/systems.rs b/rask-engine/src/engine/systems.rs index 57d71f99..b0c1e4b7 100644 --- a/rask-engine/src/engine/systems.rs +++ b/rask-engine/src/engine/systems.rs @@ -42,6 +42,7 @@ impl<'a> System<'a> for TextRenderSystem { WriteStorage<'a, Glyph>, ReadExpect<'a, Hierarchy>, Entities<'a>, + Read<'a, RenderBufferDimensions>, ); fn run( @@ -56,6 +57,7 @@ impl<'a> System<'a> for TextRenderSystem { mut glyps, hierarchy, entities, + buf_dim, ): Self::SystemData, ) { let events = textboxes.channel().read(self.reader_id.as_mut().unwrap()); @@ -106,21 +108,22 @@ impl<'a> System<'a> for TextRenderSystem { continue; } let id = font.store_glyph(glyph); + let nscale = ( + -(glyph.width as f32 / buf_dim.0 .0 as f32), + -(glyph.height as f32 / buf_dim.0 .1 as f32), + ); let (npo, nsp, nsc) = ( Pos(Vec2::new( - curr_pos.x() + glyph.x / tex.fontsize / 4.0, - curr_pos.y() + glyph.y / tex.fontsize / 4.0, + curr_pos.x() + glyph.x / buf_dim.0 .0 as f32 * 2.0 - nscale.0 / 2.0, + curr_pos.y() + glyph.y / buf_dim.0 .1 as f32 * 2.0 - nscale.1 / 2.0, )), Sprite { id: tex.font.id, sub_id: id, }, - Scale(Vec2::new( - glyph.width as f32 / -400.0, - glyph.height as f32 / -400.0, - )), + Scale(Vec2::new(nscale.0, nscale.1)), ); - log::debug!("printing: {:?} pos: {:?}", glyph.key.c, npo); + log::debug!("printing: {:?} pos: {:?}, scale: {:?}", glyph, npo, nsc); match ci.next().cloned() { None => { entities diff --git a/rask-engine/src/io.rs b/rask-engine/src/io.rs index ac16716c..cc8a76ca 100644 --- a/rask-engine/src/io.rs +++ b/rask-engine/src/io.rs @@ -44,6 +44,9 @@ pub trait SystemApi: Send + Sync { fn stop_sound(&mut self, _id: u32) { unimplemented!("stop_sound is not implemented for the system api"); } + fn get_render_buffer_dimensions(&mut self) -> (u32, u32) { + unimplemented!("get_render_buffer_dimensions is not implemented for the system api"); + } } #[derive(Debug, Default)] diff --git a/rask-engine/src/resources/font.rs b/rask-engine/src/resources/font.rs index e20fe8f5..7a7039b7 100644 --- a/rask-engine/src/resources/font.rs +++ b/rask-engine/src/resources/font.rs @@ -29,7 +29,7 @@ impl Font { let key = s.finish(); if !self.cache.contains(&key) { let (metrics, data) = self.font.rasterize_config(glyph.key); - let mut new_data = Vec::new(); + let mut new_data = Vec::new(); // TODO: Replace with color management for d in data { new_data.append(&mut vec![d, d, d, d]); } diff --git a/wasm/src/graphics/renderer.rs b/wasm/src/graphics/renderer.rs index 68aefe2c..264a0a22 100644 --- a/wasm/src/graphics/renderer.rs +++ b/wasm/src/graphics/renderer.rs @@ -4,7 +4,9 @@ use crate::communication::{RESOURCE_TABLE, SYNCHRONIZATION_MEMORY}; use crate::error::ClientError; use rask_engine::resources::{GetTextures, Texture}; -const RENDER_RESOLUTION: (u32, u32) = (240, 135); +/// Width of the internal render buffer +pub const RENDER_BUFFER_WIDTH: u32 = 240; +pub const RENDER_BUFFER_HEIGHT: u32 = RENDER_BUFFER_WIDTH / super::webgl::WORLD_ASPECT as u32; type RenderBackend = WebGl2; static mut RENDERER: Option> = None; @@ -33,7 +35,7 @@ impl Renderer { pub fn new() -> Result { // TODO: Do not hardcode pixelated framebuffer size log::debug!("Creating graphics buffer"); - T::new(240, 135).map(|api| Self { graphics: api }) + T::new(RENDER_BUFFER_WIDTH, RENDER_BUFFER_HEIGHT).map(|api| Self { graphics: api }) } pub fn render(&mut self) -> Result<(), ClientError> { diff --git a/wasm/src/graphics/webgl/mod.rs b/wasm/src/graphics/webgl/mod.rs index 91364539..e2a602b2 100644 --- a/wasm/src/graphics/webgl/mod.rs +++ b/wasm/src/graphics/webgl/mod.rs @@ -17,7 +17,7 @@ use rask_engine::{ use rect_packer::DensePacker; // The maximum visible aspect ratio (width / height) -const WORLD_ASPECT: f32 = 1.0; +pub const WORLD_ASPECT: f32 = 1.0; // Set the position to zoom towards const ZOOM_X: f32 = -0.0; const ZOOM_Y: f32 = -0.6; @@ -210,9 +210,6 @@ impl GraphicsApi for WebGl2 { let prev_layer_index = self.layer_index; let empty = self.textures.is_empty(); for texture in textures { - if texture.2.width() == 0 || texture.2.height() == 0 { - continue; - } let rect = self .texture_packer .pack(texture.2.width() as i32, texture.2.height() as i32, false) diff --git a/wasm/src/logic/system.rs b/wasm/src/logic/system.rs index b66e0350..27a7ea36 100644 --- a/wasm/src/logic/system.rs +++ b/wasm/src/logic/system.rs @@ -97,4 +97,8 @@ impl rask_engine::io::SystemApi for SystemIO { fn stop_sound(&mut self, id: u32) { Message::StopSound(id).send(); } + fn get_render_buffer_dimensions(&mut self) -> (u32, u32) { + use crate::graphics::renderer::*; + (RENDER_BUFFER_WIDTH, RENDER_BUFFER_HEIGHT) + } } From 65e0c0291d59f64c7206d586e5842556ccaf7b3e Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Wed, 6 Jan 2021 19:11:20 +0100 Subject: [PATCH 4/5] Update texture_ids on changes in fontcache --- rask-engine/src/engine/components.rs | 3 +- rask-engine/src/engine/mod.rs | 11 +++--- rask-engine/src/engine/systems.rs | 27 +++++++++---- rask-engine/src/resources/font.rs | 12 ++++-- wasm/src/communication/message_queue.rs | 2 +- wasm/src/graphics/webgl/mod.rs | 52 ++++++++++++++----------- 6 files changed, 66 insertions(+), 41 deletions(-) diff --git a/rask-engine/src/engine/components.rs b/rask-engine/src/engine/components.rs index 7c5724f8..091647cd 100644 --- a/rask-engine/src/engine/components.rs +++ b/rask-engine/src/engine/components.rs @@ -6,12 +6,13 @@ use crate::resources::{ }; use specs::{prelude::*, Component}; use specs_hierarchy::Parent as PParent; +use std::collections::HashSet; #[derive(Debug, Default)] pub struct Gravitation(pub Vec2); #[derive(Debug, Default)] -pub struct TextureIds(pub Vec); +pub struct TextureIds(pub HashSet<(u32, u64)>); #[derive(Debug, Default)] pub struct DeltaTime(pub std::time::Duration); diff --git a/rask-engine/src/engine/mod.rs b/rask-engine/src/engine/mod.rs index aed50cc4..a43f995d 100644 --- a/rask-engine/src/engine/mod.rs +++ b/rask-engine/src/engine/mod.rs @@ -5,7 +5,8 @@ use crate::EngineError; use core::time::Duration; use specs::prelude::*; use specs::WorldExt; -use specs_hierarchy::{Hierarchy, HierarchySystem}; +use specs_hierarchy::HierarchySystem; +use std::collections::HashSet; mod components; mod systems; @@ -46,7 +47,7 @@ impl GameEngine for RaskEngine { world.insert(Gravitation(GRAVITY)); world.insert(DeltaTime(Duration::from_millis(10))); world.insert(ElapsedTime(Duration::from_millis(0))); - world.insert(TextureIds(Vec::new())); + world.insert(TextureIds(HashSet::new())); world.insert(RenderBufferDimensions( system.get_render_buffer_dimensions(), )); @@ -78,13 +79,13 @@ impl GameEngine for RaskEngine { .build(); let _text = world .create_entity() - .with(Pos(Vec2::new(-0.7, 0.0))) + .with(Pos(Vec2::new(-0.9, 0.6))) .with(TextBox { font: registry::PIXELFONT, content: String::from("Hallo Welt"), - fontsize: 40.0, + fontsize: 20.0, color: core::u32::MAX, - width: None, + width: Some(220.0), height: None, }) .with(Scale(Vec2::new(0.1, -0.1))) diff --git a/rask-engine/src/engine/systems.rs b/rask-engine/src/engine/systems.rs index b0c1e4b7..d8c1b628 100644 --- a/rask-engine/src/engine/systems.rs +++ b/rask-engine/src/engine/systems.rs @@ -43,6 +43,7 @@ impl<'a> System<'a> for TextRenderSystem { ReadExpect<'a, Hierarchy>, Entities<'a>, Read<'a, RenderBufferDimensions>, + Write<'a, TextureIds>, ); fn run( @@ -58,6 +59,7 @@ impl<'a> System<'a> for TextRenderSystem { hierarchy, entities, buf_dim, + mut texture_ids, ): Self::SystemData, ) { let events = textboxes.channel().read(self.reader_id.as_mut().unwrap()); @@ -67,7 +69,7 @@ impl<'a> System<'a> for TextRenderSystem { for event in events { match event { ComponentEvent::Modified(id) | ComponentEvent::Inserted(id) => { - log::debug!("texbox modified: {}", id); + //log::debug!("texbox modified: {}", id); self.modified.add(*id); } ComponentEvent::Removed(_) => (), @@ -107,7 +109,10 @@ impl<'a> System<'a> for TextRenderSystem { { continue; } - let id = font.store_glyph(glyph); + let (id, modified) = font.store_glyph(glyph); + if modified { + texture_ids.0.remove(&(tex.font.id, id)); + } let nscale = ( -(glyph.width as f32 / buf_dim.0 .0 as f32), -(glyph.height as f32 / buf_dim.0 .1 as f32), @@ -123,7 +128,7 @@ impl<'a> System<'a> for TextRenderSystem { }, Scale(Vec2::new(nscale.0, nscale.1)), ); - log::debug!("printing: {:?} pos: {:?}, scale: {:?}", glyph, npo, nsc); + //log::debug!("printing: {:?} pos: {:?}, scale: {:?}", glyph, npo, nsc); match ci.next().cloned() { None => { entities @@ -273,13 +278,13 @@ impl<'a> System<'a> for RenderSystem { } let mut dirty = false; for sp in &sprites { - if !tex_ids.0.contains(&sp.tex_id) { - tex_ids.0.push(sp.tex_id); + if !tex_ids.0.contains(&(sp.tex_id, sp.tex_sub_id)) { + tex_ids.0.insert((sp.tex_id, sp.tex_sub_id)); dirty = true; } } if dirty { - sys.0.push_textures(tex_ids.0.clone()); + sys.0.push_textures(tex_ids.0.iter().map(|x| x.0).collect()); } sys.0.push_sprites(sprites); } @@ -290,11 +295,14 @@ impl<'a> System<'a> for MovementSystem { WriteStorage<'a, Animation>, WriteStorage<'a, Vel>, WriteStorage<'a, Scale>, + WriteStorage<'a, TextBox>, ReadStorage<'a, Speed>, + ReadStorage<'a, Pos>, ); - fn run(&mut self, (mut anim, mut vel, mut scale, speed): Self::SystemData) { - for (anim, vel, scale, speed) in (&mut anim, &mut vel, &mut scale, &speed).join() { + fn run(&mut self, (mut anim, mut vel, mut scale, mut textboxes, speed, pos): Self::SystemData) { + for (anim, vel, scale, speed, pos) in (&mut anim, &mut vel, &mut scale, &speed, &pos).join() + { anim.animation = if KEYBOARD.get(Key::ARROW_RIGHT) { scale.0 = Vec2::new(1.0, scale.0.y()); vel.0 = Vec2::new(speed.0, 0.0); @@ -307,6 +315,9 @@ impl<'a> System<'a> for MovementSystem { vel.0 = Vec2::new(0.0, 0.0); "standing".to_owned() }; + for tb in (&mut textboxes).join() { + tb.content = format!("pos: |{:.2}, {:.2}|", pos.0.x(), pos.0.y()) + } } } } diff --git a/rask-engine/src/resources/font.rs b/rask-engine/src/resources/font.rs index 7a7039b7..1e401f1e 100644 --- a/rask-engine/src/resources/font.rs +++ b/rask-engine/src/resources/font.rs @@ -5,7 +5,7 @@ use lru::LruCache; use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; -const FONTCACHESIZE: usize = 128; +const FONTCACHESIZE: usize = 256; pub struct Font { font: FFont, @@ -22,11 +22,13 @@ impl Font { }) } - /// Stores the glyph in the cache and return the texture subid - pub fn store_glyph(&mut self, glyph: &GlyphPosition) -> u64 { + /// Stores the glyph in the cache and return the texture subid and whether the it was already + /// present in the cache + pub fn store_glyph(&mut self, glyph: &GlyphPosition) -> (u64, bool) { let mut s = DefaultHasher::new(); glyph.key.hash(&mut s); let key = s.finish(); + //log::debug!("adding key: {}, glyph: {:?}", key, glyph); if !self.cache.contains(&key) { let (metrics, data) = self.font.rasterize_config(glyph.key); let mut new_data = Vec::new(); // TODO: Replace with color management @@ -41,8 +43,10 @@ impl Font { ); self.cache.put(key, (metrics, tex)); + (key, true) + } else { + (key, false) } - key } pub fn get_glyph_metrics(&self, key: u64) -> Option<&Metrics> { diff --git a/wasm/src/communication/message_queue.rs b/wasm/src/communication/message_queue.rs index 44b92ebe..eedbcf41 100644 --- a/wasm/src/communication/message_queue.rs +++ b/wasm/src/communication/message_queue.rs @@ -5,7 +5,7 @@ use std::sync::atomic::AtomicBool; use rask_engine::events::{Event, KeyModifier, MouseEvent}; use rask_engine::network::protocol::op_codes; -pub const MESSAGE_QUEUE_ELEMENT_COUNT: usize = 128; +pub const MESSAGE_QUEUE_ELEMENT_COUNT: usize = 512; #[repr(C, u32)] #[derive(Debug, Clone)] diff --git a/wasm/src/graphics/webgl/mod.rs b/wasm/src/graphics/webgl/mod.rs index e2a602b2..7b41fc79 100644 --- a/wasm/src/graphics/webgl/mod.rs +++ b/wasm/src/graphics/webgl/mod.rs @@ -110,21 +110,30 @@ impl WebGl2 { fn generate_texture_buffers( &mut self, sprites: &[Sprite], - ) -> Option<(Vec<[f32; 4]>, Vec)> { + ) -> Result<(Vec<[f32; 4]>, Vec), Vec> { self.sprite_textures = sprites.iter().map(|s| (s.tex_id, s.tex_sub_id)).collect(); - Some( - self.sprite_textures + let mapping = self + .sprite_textures + .iter() + .map(|i| { + self.textures + .get(i) + .map(|(range, layer)| (range.into_floats(), layer)) + }) + .collect::>>(); + if let Some(mapping) = mapping { + Ok(mapping.iter().cloned().unzip()) + } else { + Err(sprites .iter() - .map(|i| { + .filter_map(|t| { self.textures - .get(i) - .map(|(range, layer)| (range.into_floats(), layer)) + .get(&(t.tex_id, t.tex_sub_id)) + .map_or(Some(t), |_| None) }) - .collect::>>()? - .iter() .cloned() - .unzip(), - ) + .collect()) + } } } @@ -170,6 +179,15 @@ impl GraphicsApi for WebGl2 { if sprites.is_empty() { return Ok(()); } + + let fetch_texture_info = |sps, api: &mut Self| { + api.generate_texture_buffers(sps).map_err(|sprites| { + ClientError::ResourceError(format!( + "Tried to add sprite with non-existent texture. Missing sprites: {:#?}", + sprites + )) + }) + }; if sprites.len() == self.matrix_buffer.len() { let keep_textures = self .sprite_textures @@ -177,12 +195,7 @@ impl GraphicsApi for WebGl2 { .zip(sprites.iter()) .all(|(&t, s)| s.tex_id == t.0 && s.tex_sub_id == t.1); if !keep_textures { - let (texture_ranges, texture_layers) = - self.generate_texture_buffers(sprites).ok_or_else(|| { - ClientError::ResourceError( - "tried to set sprite texture to non-existent texture".to_string(), - ) - })?; + let (texture_ranges, texture_layers) = fetch_texture_info(sprites, self)?; self.gl .update_texture_buffer(&texture_ranges, &texture_layers); } @@ -193,12 +206,7 @@ impl GraphicsApi for WebGl2 { Ok(()) } else { self.matrix_buffer = sprites.iter().map(|s| s.transform).collect(); - let (texture_ranges, texture_layers) = - self.generate_texture_buffers(sprites).ok_or_else(|| { - ClientError::ResourceError( - "tried to add sprite with non-existent texture".to_string(), - ) - })?; + let (texture_ranges, texture_layers) = fetch_texture_info(sprites, self)?; self.gl .allocate_buffers(&self.matrix_buffer, &texture_ranges, &texture_layers) } From 9ac195d64aa50cc2d79bc749336763d3a8399471 Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Wed, 6 Jan 2021 20:57:00 +0100 Subject: [PATCH 5/5] Initialize font cache to avoid loading times --- rask-engine/src/engine/mod.rs | 9 ++++++++- rask-engine/src/engine/systems.rs | 23 ++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/rask-engine/src/engine/mod.rs b/rask-engine/src/engine/mod.rs index a43f995d..e6951f33 100644 --- a/rask-engine/src/engine/mod.rs +++ b/rask-engine/src/engine/mod.rs @@ -14,6 +14,13 @@ use components::*; use systems::*; const GRAVITY: Vec2 = Vec2::new(0.0, -9.807); +pub const INITIAL_CHARS: &str = ", !, \", #, $, %, &, ', (, ), *, +, + ,, -, ., /, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + :, ;, <, =, >, ?, @, A, B, C, D, E, F, G, + H, I, J, K, L, M, N, O, P, Q, R, S, T, U, + V, W, X, Y, Z, [, \\, ], ^, _, `, a, b, c, + d, e, f, g, h, i, j, k, l, m, n, o, p, q, + r, s, t, u, v, w, x, y, z, {, |, }, ~"; pub struct Level {} @@ -82,7 +89,7 @@ impl GameEngine for RaskEngine { .with(Pos(Vec2::new(-0.9, 0.6))) .with(TextBox { font: registry::PIXELFONT, - content: String::from("Hallo Welt"), + content: String::from(INITIAL_CHARS), fontsize: 20.0, color: core::u32::MAX, width: Some(220.0), diff --git a/rask-engine/src/engine/systems.rs b/rask-engine/src/engine/systems.rs index d8c1b628..12d049f1 100644 --- a/rask-engine/src/engine/systems.rs +++ b/rask-engine/src/engine/systems.rs @@ -33,7 +33,7 @@ pub struct TextRenderSystem { impl<'a> System<'a> for TextRenderSystem { type SystemData = ( - ReadStorage<'a, TextBox>, + WriteStorage<'a, TextBox>, ReadStorage<'a, Present>, WriteStorage<'a, Parent>, WriteStorage<'a, Sprite>, @@ -49,7 +49,7 @@ impl<'a> System<'a> for TextRenderSystem { fn run( &mut self, ( - textboxes, + mut textboxes, present, mut parent, mut sprites, @@ -76,7 +76,7 @@ impl<'a> System<'a> for TextRenderSystem { } } - for (tex, entity, _) in (&textboxes, &self.modified, &present).join() { + for (tex, entity, _) in (&mut textboxes, &self.modified, &present).join() { let layout_settings = LayoutSettings { x: 0.0, y: 0.0, @@ -97,6 +97,9 @@ impl<'a> System<'a> for TextRenderSystem { if let Ok(font) = font { layout.append(&[font.font()], &style); let mut ci = hierarchy.children(entity).iter(); + if tex.content == super::INITIAL_CHARS { + tex.content = String::new(); + } let curr_pos = pos .get(entity) @@ -126,7 +129,7 @@ impl<'a> System<'a> for TextRenderSystem { id: tex.font.id, sub_id: id, }, - Scale(Vec2::new(nscale.0, nscale.1)), + Scale(Vec2::new(nscale.0 * 0.9, nscale.1 * 0.9)), ); //log::debug!("printing: {:?} pos: {:?}, scale: {:?}", glyph, npo, nsc); match ci.next().cloned() { @@ -298,9 +301,13 @@ impl<'a> System<'a> for MovementSystem { WriteStorage<'a, TextBox>, ReadStorage<'a, Speed>, ReadStorage<'a, Pos>, + ReadStorage<'a, Present>, ); - fn run(&mut self, (mut anim, mut vel, mut scale, mut textboxes, speed, pos): Self::SystemData) { + fn run( + &mut self, + (mut anim, mut vel, mut scale, mut textboxes, speed, pos, present): Self::SystemData, + ) { for (anim, vel, scale, speed, pos) in (&mut anim, &mut vel, &mut scale, &speed, &pos).join() { anim.animation = if KEYBOARD.get(Key::ARROW_RIGHT) { @@ -315,8 +322,10 @@ impl<'a> System<'a> for MovementSystem { vel.0 = Vec2::new(0.0, 0.0); "standing".to_owned() }; - for tb in (&mut textboxes).join() { - tb.content = format!("pos: |{:.2}, {:.2}|", pos.0.x(), pos.0.y()) + for (tb, _) in (&mut textboxes, &present).join() { + if tb.content.is_empty() { + tb.content = format!("pos: |{:.2}, {:.2}|", pos.0.x(), pos.0.y()) + } } } }