Compare commits
4 Commits
overlay-te
...
avian
| Author | SHA1 | Date | |
|---|---|---|---|
| a266979fae | |||
| e83a839800 | |||
| 86a11e3af6 | |||
| eb00383d96 |
17
.vscode/launch.json
vendored
17
.vscode/launch.json
vendored
@@ -14,17 +14,12 @@
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}/game/main",
|
||||
"preLaunchTask": "Build",
|
||||
"environment": [
|
||||
// {
|
||||
// "name": "RUST_BACKTRACE",
|
||||
// "value": "1"
|
||||
// },
|
||||
{
|
||||
//Set Asset Folder
|
||||
"name": "CARGO_MANIFEST_DIR",
|
||||
"value": "${workspaceRoot}\\game\\main"
|
||||
}
|
||||
]
|
||||
// "environment": [
|
||||
// {
|
||||
// "name": "RUST_BACKTRACE",
|
||||
// "value": "1"
|
||||
// }
|
||||
// ]
|
||||
}
|
||||
]
|
||||
}
|
||||
420
Cargo.lock
generated
420
Cargo.lock
generated
@@ -264,16 +264,6 @@ dependencies = [
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "asset_loader_proc"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"ron",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-broadcast"
|
||||
version = "0.5.1"
|
||||
@@ -363,6 +353,36 @@ dependencies = [
|
||||
"v_frame",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avian3d"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "263f406c08c5ec296039ba06d7aa50e54f9ecd996f682aaa63eae25709e8935b"
|
||||
dependencies = [
|
||||
"avian_derive",
|
||||
"bevy",
|
||||
"bevy_math",
|
||||
"bitflags 2.6.0",
|
||||
"derive_more",
|
||||
"fxhash",
|
||||
"indexmap",
|
||||
"itertools 0.13.0",
|
||||
"nalgebra 0.32.6",
|
||||
"parry3d 0.15.1",
|
||||
"parry3d-f64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avian_derive"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4adeeecb6d4628d3ca11836ce9af8309f9552d4bd3e3f6e4368440d8163260c"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.86",
|
||||
"quote 1.0.36",
|
||||
"syn 2.0.70",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "avif-serialize"
|
||||
version = "0.8.1"
|
||||
@@ -386,9 +406,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "bevy"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "043c9ad4b6fc4ca52d779873a8ca792a4e37842d07fce95363c9e17e36a1d8a0"
|
||||
checksum = "8e938630e9f472b1899c78ef84aa907081b23bad8333140e2295c620485b6ee7"
|
||||
dependencies = [
|
||||
"bevy_internal",
|
||||
]
|
||||
@@ -439,9 +459,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_a11y"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae1a976cb539d6a5a3ff579cdb78187a6bcfbffa7e8224ea28f23d8b983d9389"
|
||||
checksum = "3e613f0e7d5a92637e59744f7185e374c9a59654ecc6d7575adcec9581db1363"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"bevy_app",
|
||||
@@ -451,9 +471,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_animation"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93aef7d21a0342c24b05059493aa31d58f1798d34a2236569a8789b74df5a475"
|
||||
checksum = "23aa4141df149b743e69c90244261c6372bafb70d9f115885de48a75fc28fd9b"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_asset",
|
||||
@@ -481,9 +501,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_app"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5361d0f8a8677a5d0102cfe7321a7ecd2a8b9a4f887ce0dde1059311cf9cd42"
|
||||
checksum = "6f548e9dab7d10c5f99e3b504c758c4bf87aa67df9bcb9cc8b317a0271770e72"
|
||||
dependencies = [
|
||||
"bevy_derive",
|
||||
"bevy_ecs",
|
||||
@@ -499,9 +519,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_asset"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60ec5ea257e1ebd3d411f669e29acf60beb715bebc7e1f374c17f49cd3aad46c"
|
||||
checksum = "f9d198e4c3419215de2ad981d4e734bbfab46469b7575e3b7150c912b9ec5175"
|
||||
dependencies = [
|
||||
"async-broadcast",
|
||||
"async-fs",
|
||||
@@ -557,9 +577,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_asset_macros"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9eb05ce838d282f09d83380b4d6432aec7519d421dee8c75cc20e6148237e6e"
|
||||
checksum = "11b2cbeba287a4b44e116c33dbaf37dce80a9d84477b2bb35ff459999d6c9e1b"
|
||||
dependencies = [
|
||||
"bevy_macro_utils",
|
||||
"proc-macro2 1.0.86",
|
||||
@@ -569,9 +589,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_audio"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ee31312a0e67f288fe12a1d9aa679dd0ba8a49e1e6fe5fcd2ba1aa1ea34e5ed"
|
||||
checksum = "e41ecf15d0aae31bdb6d2b5cc590f966451e9736ddfee634c8f1ca5af1ac4342"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_asset",
|
||||
@@ -588,9 +608,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_color"
|
||||
version = "0.14.3"
|
||||
version = "0.14.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04842e9d38a93f0c75ab46f7f404ea24ef57ad83dbd159e5b4b35318b02257bb"
|
||||
checksum = "5a933306f5c7dc9568209180f482b28b5f40d2f8d5b361bc1b270c0a588752c0"
|
||||
dependencies = [
|
||||
"bevy_math",
|
||||
"bevy_reflect",
|
||||
@@ -616,9 +636,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_core"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de706862871a1fe99ea619bff2f99d73e43ad82f19ef866a9e19a14c957c8537"
|
||||
checksum = "6ddeed5ebf2fa75a4d4f32e2da9c60f11037e36252695059a151c6685cd3d72b"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_ecs",
|
||||
@@ -630,9 +650,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_core_pipeline"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f6e1e122ada4cd811442e083fb5ad3e325c59a87271d5ef57193f1c2cad7f8c"
|
||||
checksum = "1b978220b5edc98f2c5cbbd14c118c74b3ec7216e5416d3c187c1097279b009b"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_asset",
|
||||
@@ -655,9 +675,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_derive"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fbfc33a4c6b80760bb8bf850a2cc65a1e031da62fd3ca8b552189104dc98514"
|
||||
checksum = "c8a8173bad3ed53fa158806b1beda147263337d6ef71a093780dd141b74386b1"
|
||||
dependencies = [
|
||||
"bevy_macro_utils",
|
||||
"quote 1.0.36",
|
||||
@@ -666,9 +686,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_diagnostic"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bebb154e0cc78e3bbfbfdb42fb502b14c1cd47e72f16e6d4228dfe6233ba6cbd"
|
||||
checksum = "0b7f82011fd70048be282526a99756d54bf00e874edafa9664ba0dc247678f03"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_core",
|
||||
@@ -682,9 +702,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_ecs"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ee4222406637f3c8e3991a99788cfcde76097bf997c311f1b6297364057483f"
|
||||
checksum = "2c77fdc3a7230eff2fcebe4bd17c155bd238c660a0089d0f98c39ba0d461b923"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bevy_ecs_macros",
|
||||
@@ -703,9 +723,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_ecs_macros"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36b573430b67aff7bde8292257494f39343401379bfbda64035ba4918bba7b20"
|
||||
checksum = "9272b511958525306cd141726d3ca59740f79fc0707c439b55a007bcc3497308"
|
||||
dependencies = [
|
||||
"bevy_macro_utils",
|
||||
"proc-macro2 1.0.86",
|
||||
@@ -737,9 +757,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_encase_derive"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d06c9693847a2a6ea61d6b86288dd4d8b6a79f05d4bf6e27b96d4f5c8d552fe4"
|
||||
checksum = "f0452d8254c8bfae4bff6caca2a8be3b0c1b2e1a72b93e9b9f6a21c8dff807e0"
|
||||
dependencies = [
|
||||
"bevy_macro_utils",
|
||||
"encase_derive_impl",
|
||||
@@ -747,9 +767,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_gilrs"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0422ccb3ce0f79b264100cf064fdc5ef65cef5c7d51bf6378058f9b96fea4183"
|
||||
checksum = "fbad8e59470c3d5cf25aa8c48462c4cf6f0c6314538c68ab2f5cf393146f0fc2"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_ecs",
|
||||
@@ -762,9 +782,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_gizmos"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfe32af0666d8d8a7fd6eb6b5e41eceefdc6f2e5441c74b812e8f0902a9d7f52"
|
||||
checksum = "bdbb0556f0c6e45f4a17aef9c708c06ebf15ae1bed4533d7eddb493409f9f025"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_asset",
|
||||
@@ -785,9 +805,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_gizmos_macros"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "906b052f8cf3f3983f0f6df625fb10cbd9b27d44e362a327dc1ed51300d362bc"
|
||||
checksum = "8ef351a4b6498c197d1317c62f46ba84b69fbde3dbeb57beb2e744bbe5b7c3e0"
|
||||
dependencies = [
|
||||
"bevy_macro_utils",
|
||||
"proc-macro2 1.0.86",
|
||||
@@ -797,9 +817,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_gltf"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6adbd325b90e3c700d0966b5404e226c7deec1b8bda8f36832788d7b435b9b8"
|
||||
checksum = "cfd7abeaf3f28afd1f8999c2169aa17b40a37ad11253cf7dd05017024b65adc6"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bevy_animation",
|
||||
@@ -828,9 +848,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_hierarchy"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a88b912b37e1bc4dbb2aa40723199f74c8b06c4fbb6da0bb4585131df28ef66e"
|
||||
checksum = "802eca6f341d19ade790ccfaba7044be4d823b708087eb5ac4c1f74e4ea0916a"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_core",
|
||||
@@ -842,9 +862,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_input"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8dd3a54e67cc3ba17971de7b1a7e64eda84493c1e7bb6bfa11c6cf8ac124377b"
|
||||
checksum = "2d050f1433f48ca23f1ea078734ebff119a3f76eb7d221725ab0f1fd9f81230b"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_ecs",
|
||||
@@ -857,9 +877,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_internal"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "45d435cac77c568f3aef65f786a5fee0e53c81950c5258182dd2c1d6cd6c4fec"
|
||||
checksum = "8ddd2b23e44d3a1f8ae547cbee5b6661f8135cc456c5de206e8648789944e7a1"
|
||||
dependencies = [
|
||||
"bevy_a11y",
|
||||
"bevy_animation",
|
||||
@@ -898,9 +918,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_log"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67240c7596c8f0653e50fce35a60196516817449235193246599facba9002e02"
|
||||
checksum = "bab641fd0de254915ab746165a07677465b2d89b72f5b49367d73b9197548a35"
|
||||
dependencies = [
|
||||
"android_log-sys",
|
||||
"bevy_app",
|
||||
@@ -915,9 +935,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_macro_utils"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfc65e570012e64a21f3546df68591aaede8349e6174fb500071677f54f06630"
|
||||
checksum = "c3ad860d35d74b35d4d6ae7f656d163b6f475aa2e64fc293ee86ac901977ddb7"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.86",
|
||||
"quote 1.0.36",
|
||||
@@ -927,32 +947,31 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_math"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5421792749dda753ab3718e77d27bfce38443daf1850b836b97530b6245a4581"
|
||||
checksum = "51bd6ce2174d3237d30e0ab5b2508480cc7593ca4d96ffb3a3095f9fc6bbc34c"
|
||||
dependencies = [
|
||||
"bevy_reflect",
|
||||
"glam",
|
||||
"rand 0.8.5",
|
||||
"serde",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_mikktspace"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "66cf695a264b043f2c4edb92dd5c742e6892180d2b30dac870012d153f8557ea"
|
||||
checksum = "b7ce4266293629a2d10459cc112dffe3b3e9229a4f2b8a4d20061b8dd53316d0"
|
||||
dependencies = [
|
||||
"glam",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_pbr"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dccaa3c945f19834dcf7cd8eb358236dbf0fc4000dacbc7710564e7856714db"
|
||||
checksum = "3effe8ff28899f14d250d0649ca9868dbe68b389d0f2b7af086759b8e16c6e3d"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_asset",
|
||||
@@ -977,9 +996,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_ptr"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61baa1bdc1f4a7ac2c18217570a7cc04e1cd54d38456e91782f0371c79afe0a8"
|
||||
checksum = "c115c97a5c8a263bd0aa7001b999772c744ac5ba797d07c86f25734ce381ea69"
|
||||
|
||||
[[package]]
|
||||
name = "bevy_rapier3d"
|
||||
@@ -990,15 +1009,15 @@ dependencies = [
|
||||
"bevy",
|
||||
"bitflags 2.6.0",
|
||||
"log",
|
||||
"nalgebra",
|
||||
"nalgebra 0.33.0",
|
||||
"rapier3d",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_reflect"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2508785a4a5809f25a237eec4fee2c91a4dbcf81324b2bbc2d6c52629e603781"
|
||||
checksum = "406ea0fce267169c2320c7302d97d09f605105686346762562c5f65960b5ca2f"
|
||||
dependencies = [
|
||||
"bevy_ptr",
|
||||
"bevy_reflect_derive",
|
||||
@@ -1016,9 +1035,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_reflect_derive"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "967d5da1882ec3bb3675353915d3da909cafac033cbf31e58727824a1ad2a288"
|
||||
checksum = "0427fdb4425fc72cc96d45e550df83ace6347f0503840de116c76a40843ba751"
|
||||
dependencies = [
|
||||
"bevy_macro_utils",
|
||||
"proc-macro2 1.0.86",
|
||||
@@ -1029,9 +1048,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_render"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "836cf8a513db013cbe7d55a331060088efd407e49fd5b05c8404700cd82e7619"
|
||||
checksum = "4c48acf1ff4267c231def4cbf573248d42ac60c9952108822d505019460bf36d"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"bevy_app",
|
||||
@@ -1078,9 +1097,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_render_macros"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbc24e0e95061a38a7744218b9c7e52e4c08b53f1499f33480e2b749f3864432"
|
||||
checksum = "72ddf4a96d71519c8eca3d74dabcb89a9c0d50ab5d9230638cb004145f46e9ed"
|
||||
dependencies = [
|
||||
"bevy_macro_utils",
|
||||
"proc-macro2 1.0.86",
|
||||
@@ -1090,9 +1109,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_scene"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ec57a72d75273bdbb6154390688fd07ba79ae9f6f99476d1937f799c736c2da"
|
||||
checksum = "b7a9f0388612a116f02ab6187aeab66e52c9e91abbc21f919b8b50230c4d83e7"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_asset",
|
||||
@@ -1110,9 +1129,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_sprite"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e045b4d8cc8e7422a4c29b1eadbe224f5cc42f170b88d43e7535892fcede3840"
|
||||
checksum = "d837e33ed27b9f2e5212eca4bdd5655a9ee64c52914112e6189c043cb25dd1ec"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_asset",
|
||||
@@ -1136,9 +1155,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_state"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25335bfa58cc22371182335c3b133017293bc9b6d3308402fd4d1f978b83f937"
|
||||
checksum = "0959984092d56885fd3b320ea84fb816821bad6bfa3040b9d4ee850d3273233d"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_ecs",
|
||||
@@ -1150,9 +1169,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_state_macros"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dee600b659c739f1911f997a81611fec0a1832cf731727956e5fa4e7532b4dd5"
|
||||
checksum = "887a98bfa268258377cd073f5bb839518d3a1cd6b96ed81418145485b69378e6"
|
||||
dependencies = [
|
||||
"bevy_macro_utils",
|
||||
"proc-macro2 1.0.86",
|
||||
@@ -1162,9 +1181,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_tasks"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77865f310b1fc48fb05b7c4adbe76607ec01d0c14f8ab4caba4d714c86439946"
|
||||
checksum = "5a8bfb8d484bdb1e9bec3789c75202adc5e608c4244347152e50fb31668a54f9"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-executor",
|
||||
@@ -1175,9 +1194,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_text"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b661db828fd423fc41a4ccf43aa4d1b8e50e75057ec40453317d0d761e8ad62d"
|
||||
checksum = "454fd29b7828244356b2e0ce782e6d0a6f26b47f521456accde3a7191b121727"
|
||||
dependencies = [
|
||||
"ab_glyph",
|
||||
"bevy_app",
|
||||
@@ -1198,9 +1217,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_time"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4e4d53ec32a1b16492396951d04de0d2d90e924bf9adcb8d1adacab5ab6c17c"
|
||||
checksum = "a6c3d3d14ee8b0dbe4819fd516cc75509b61946134d78e0ee89ad3d1835ffe6c"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_ecs",
|
||||
@@ -1212,9 +1231,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_transform"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5493dce84427d00a9266e8e4386d738a72ee8640423b62dfcecb6dfccbfe0d2"
|
||||
checksum = "97e8aa6b16be573277c6ceda30aebf1d78af7c6ede19b448dcb052fb8601d815"
|
||||
dependencies = [
|
||||
"bevy_app",
|
||||
"bevy_ecs",
|
||||
@@ -1226,9 +1245,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_ui"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56d2cba6603b39a3765f043212ae530e25550af168a7eec6b23b9b93c19bc5f7"
|
||||
checksum = "38d9f864c646f3742ff77f67bcd89a13a7ab024b68ca2f1bfbab8245bcb1c06c"
|
||||
dependencies = [
|
||||
"bevy_a11y",
|
||||
"bevy_app",
|
||||
@@ -1256,9 +1275,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_utils"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffb0ec333b5965771153bd746f92ffd8aeeb9d008a8620ffd9ed474859381a5e"
|
||||
checksum = "7fab364910e8f5839578aba9cfda00a8388e9ebe352ceb8491a742ce6af9ec6e"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bevy_utils_proc_macros",
|
||||
@@ -1271,9 +1290,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_utils_proc_macros"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38f1ab8f2f6f58439d260081d89a42b02690e5fdd64f814edc9417d33fcf2857"
|
||||
checksum = "ad9db261ab33a046e1f54b35f885a44f21fcc80aa2bc9050319466b88fe58fe3"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.86",
|
||||
"quote 1.0.36",
|
||||
@@ -1282,9 +1301,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_window"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c89e88a20db64ea8204540afb4699295947c454738fd50293f7b32ab8be857a6"
|
||||
checksum = "c9ea5777f933bf7ecaeb3af1a30845720ec730e007972ca7d4aba2d3512abe24"
|
||||
dependencies = [
|
||||
"bevy_a11y",
|
||||
"bevy_app",
|
||||
@@ -1298,9 +1317,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bevy_winit"
|
||||
version = "0.14.2"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0bef8ec3e4b45db943ad4d1c0bf59b09e382ce0651a706e2f33a70fa955303c"
|
||||
checksum = "f8c2213bbf14debe819ec8ad4913f233c596002d087bc6f1f20d533e2ebaf8c6"
|
||||
dependencies = [
|
||||
"accesskit_winit",
|
||||
"approx",
|
||||
@@ -1333,7 +1352,7 @@ dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"itertools",
|
||||
"itertools 0.12.1",
|
||||
"lazy_static",
|
||||
"lazycell",
|
||||
"proc-macro2 1.0.86",
|
||||
@@ -1711,6 +1730,12 @@ dependencies = [
|
||||
"const_soft_float",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "convert_case"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.4"
|
||||
@@ -1933,18 +1958,6 @@ version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2"
|
||||
|
||||
[[package]]
|
||||
name = "deprecate-until"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a3767f826efbbe5a5ae093920b58b43b01734202be697e1354914e862e8e704"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.86",
|
||||
"quote 1.0.36",
|
||||
"semver",
|
||||
"syn 2.0.70",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder"
|
||||
version = "0.7.2"
|
||||
@@ -1970,6 +1983,19 @@ dependencies = [
|
||||
"syn 0.15.44",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more"
|
||||
version = "0.99.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce"
|
||||
dependencies = [
|
||||
"convert_case",
|
||||
"proc-macro2 1.0.86",
|
||||
"quote 1.0.36",
|
||||
"rustc_version",
|
||||
"syn 2.0.70",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dispatch"
|
||||
version = "0.2.0"
|
||||
@@ -2326,6 +2352,15 @@ dependencies = [
|
||||
"thread_local",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fxhash"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generator"
|
||||
version = "0.8.1"
|
||||
@@ -2778,15 +2813,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "integer-sqrt"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "276ec31bcb4a9ee45f58bec6f9ec700ae4cf4f4f8f2fa7e06cb406bd5ffdd770"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "interpolate_name"
|
||||
version = "0.2.4"
|
||||
@@ -2817,6 +2843,15 @@ dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.11"
|
||||
@@ -3225,6 +3260,23 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nalgebra"
|
||||
version = "0.32.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b5c17de023a86f59ed79891b2e5d5a94c705dbe904a5b5c9c952ea6221b03e4"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"glam",
|
||||
"matrixmultiply",
|
||||
"nalgebra-macros",
|
||||
"num-complex 0.4.6",
|
||||
"num-rational 0.4.2",
|
||||
"num-traits",
|
||||
"simba 0.8.1",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nalgebra"
|
||||
version = "0.33.0"
|
||||
@@ -3238,7 +3290,7 @@ dependencies = [
|
||||
"num-complex 0.4.6",
|
||||
"num-rational 0.4.2",
|
||||
"num-traits",
|
||||
"simba",
|
||||
"simba 0.9.0",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
@@ -3840,9 +3892,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ordered-float"
|
||||
version = "4.3.0"
|
||||
version = "4.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44d501f1a72f71d3c063a6bbc8f7271fa73aa09fe5d6283b6571e2ed176a2537"
|
||||
checksum = "19ff2cf528c6c03d9ed653d6c4ce1dc0582dc4af309790ad92f07c1cd551b0be"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
@@ -3891,6 +3943,29 @@ dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parry3d"
|
||||
version = "0.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa342e0cdfc774fed0196714290ba2d85408b8ce9f295c40a0b1e05f3f8256ab"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"arrayvec",
|
||||
"bitflags 1.3.2",
|
||||
"downcast-rs",
|
||||
"either",
|
||||
"log",
|
||||
"nalgebra 0.32.6",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"rayon",
|
||||
"rustc-hash 1.1.0",
|
||||
"simba 0.8.1",
|
||||
"slab",
|
||||
"smallvec",
|
||||
"spade",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parry3d"
|
||||
version = "0.16.1"
|
||||
@@ -3903,18 +3978,41 @@ dependencies = [
|
||||
"downcast-rs",
|
||||
"either",
|
||||
"log",
|
||||
"nalgebra",
|
||||
"nalgebra 0.33.0",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"ordered-float",
|
||||
"rustc-hash 2.0.0",
|
||||
"simba",
|
||||
"simba 0.9.0",
|
||||
"slab",
|
||||
"smallvec",
|
||||
"spade",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parry3d-f64"
|
||||
version = "0.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fdc07fa374273eca29066d59d3ded520bf845ed582e38c0d60109459ea4ed76e"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"arrayvec",
|
||||
"bitflags 1.3.2",
|
||||
"downcast-rs",
|
||||
"either",
|
||||
"log",
|
||||
"nalgebra 0.32.6",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"rayon",
|
||||
"rustc-hash 1.1.0",
|
||||
"simba 0.8.1",
|
||||
"slab",
|
||||
"smallvec",
|
||||
"spade",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.15"
|
||||
@@ -3927,20 +4025,6 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e91099d4268b0e11973f036e885d652fb0b21fedcf69738c627f94db6a44f42"
|
||||
|
||||
[[package]]
|
||||
name = "pathfinding"
|
||||
version = "4.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1cff69f3ba9d0346c1dbe1248fc2ed4523567b683d1b6ff4144a6b3583369082"
|
||||
dependencies = [
|
||||
"deprecate-until",
|
||||
"indexmap",
|
||||
"integer-sqrt",
|
||||
"num-traits",
|
||||
"rustc-hash 2.0.0",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.1"
|
||||
@@ -3963,10 +4047,10 @@ dependencies = [
|
||||
name = "phos"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"avian3d",
|
||||
"bevy",
|
||||
"bevy-inspector-egui",
|
||||
"bevy_asset_loader",
|
||||
"bevy_rapier3d",
|
||||
"buildings",
|
||||
"image 0.25.2",
|
||||
"iyes_perf_ui",
|
||||
@@ -4289,16 +4373,14 @@ dependencies = [
|
||||
"crossbeam",
|
||||
"downcast-rs",
|
||||
"log",
|
||||
"nalgebra",
|
||||
"nalgebra 0.33.0",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"ordered-float",
|
||||
"parry3d",
|
||||
"rayon",
|
||||
"parry3d 0.16.1",
|
||||
"rustc-hash 2.0.0",
|
||||
"simba",
|
||||
"simba 0.9.0",
|
||||
"thiserror",
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4315,7 +4397,7 @@ dependencies = [
|
||||
"built",
|
||||
"cfg-if",
|
||||
"interpolate_name",
|
||||
"itertools",
|
||||
"itertools 0.12.1",
|
||||
"libc",
|
||||
"libfuzzer-sys",
|
||||
"log",
|
||||
@@ -4456,20 +4538,6 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
|
||||
|
||||
[[package]]
|
||||
name = "resources"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"asset_loader",
|
||||
"bevy",
|
||||
"bevy_asset_loader",
|
||||
"ron",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"shared",
|
||||
"world_generation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rgb"
|
||||
version = "0.8.47"
|
||||
@@ -4520,6 +4588,15 @@ version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
|
||||
dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.34"
|
||||
@@ -4674,6 +4751,19 @@ version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "simba"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "061507c94fc6ab4ba1c9a0305018408e312e17c041eb63bef8aa726fa33aceae"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"num-complex 0.4.6",
|
||||
"num-traits",
|
||||
"paste",
|
||||
"wide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simba"
|
||||
version = "0.9.0"
|
||||
@@ -5222,8 +5312,6 @@ dependencies = [
|
||||
"bevy",
|
||||
"bevy_asset_loader",
|
||||
"bevy_rapier3d",
|
||||
"ordered-float",
|
||||
"pathfinding",
|
||||
"quadtree_rs",
|
||||
"ron",
|
||||
"serde",
|
||||
|
||||
@@ -5,7 +5,7 @@ members = [
|
||||
"game/buildings",
|
||||
"game/shared",
|
||||
"engine/world_generation",
|
||||
"engine/asset_loader", "game/buildings", "game/shared", "game/units", "engine/data", "game/resources", "engine/asset_loader_proc"]
|
||||
"engine/asset_loader", "game/buildings", "game/shared", "game/units", "engine/data"]
|
||||
|
||||
# Enable a small amount of optimization in debug mode
|
||||
[profile.dev]
|
||||
|
||||
@@ -3,11 +3,10 @@ name = "asset_loader"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = "1.0.204"
|
||||
serde_json = "1.0.120"
|
||||
bevy = "0.14.2"
|
||||
bevy = "0.14.0"
|
||||
ron = "0.8.1"
|
||||
|
||||
@@ -1 +1,69 @@
|
||||
pub mod macros;
|
||||
pub mod macros {
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! create_asset_loader {
|
||||
(
|
||||
$plugin_name: ident,
|
||||
$loader_name: ident,
|
||||
$asset_type: ident,
|
||||
$extensions: expr,
|
||||
$($string_name: ident -> $handle_name: ident)* ;
|
||||
$($string_array_name: ident -> $handle_array_name: ident)* ?
|
||||
) => {
|
||||
use bevy::prelude::*;
|
||||
use bevy::asset::{AssetLoader, AssetEvent, AssetEvents, LoadContext, LoadState, AsyncReadExt, io::Reader};
|
||||
use bevy::utils::BoxedFuture;
|
||||
pub struct $plugin_name;
|
||||
impl Plugin for $plugin_name {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_asset::<$asset_type>()
|
||||
.init_asset_loader::<$loader_name>();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct $loader_name;
|
||||
|
||||
impl AssetLoader for $loader_name {
|
||||
type Asset = $asset_type;
|
||||
|
||||
type Settings = ();
|
||||
|
||||
type Error = String;
|
||||
|
||||
async fn load<'a>(
|
||||
&'a self,
|
||||
reader: &'a mut Reader<'_>,
|
||||
_settings: &'a Self::Settings,
|
||||
load_context: &'a mut LoadContext<'_>,
|
||||
) -> Result<Self::Asset, Self::Error> {
|
||||
let mut bytes = Vec::new();
|
||||
let read_result = reader.read_to_end(&mut bytes).await;
|
||||
if read_result.is_err() {
|
||||
return Err(read_result.err().unwrap().to_string());
|
||||
}
|
||||
let serialized: Result<Self::Asset, _> =
|
||||
ron::de::from_bytes::<Self::Asset>(&bytes);
|
||||
if serialized.is_err() {
|
||||
return Err(serialized.err().unwrap().to_string());
|
||||
}
|
||||
let mut asset = serialized.unwrap();
|
||||
$(
|
||||
|
||||
asset.$handle_name = load_context.load(&asset.$string_name);
|
||||
)*
|
||||
$(
|
||||
for i in 0..asset.$string_array_name.len(){
|
||||
asset.$handle_array_name.push(load_context.load(&asset.$string_array_name[i]));
|
||||
}
|
||||
)?
|
||||
return Ok(asset);
|
||||
}
|
||||
|
||||
fn extensions(&self) -> &[&str] {
|
||||
$extensions
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
#[macro_export]
|
||||
macro_rules! create_asset_loader {
|
||||
(
|
||||
$plugin_name: ident,
|
||||
$loader_name: ident,
|
||||
$asset_type: ident,
|
||||
$extensions: expr,
|
||||
$($string_name: ident -> $handle_name: ident)* ;
|
||||
$($string_array_name: ident -> $handle_array_name: ident)* ?
|
||||
) => {
|
||||
use bevy::prelude::*;
|
||||
use bevy::asset::{AssetLoader, AssetEvent, AssetEvents, LoadContext, LoadState, AsyncReadExt, io::Reader};
|
||||
use bevy::utils::BoxedFuture;
|
||||
pub struct $plugin_name;
|
||||
impl Plugin for $plugin_name {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_asset::<$asset_type>()
|
||||
.init_asset_loader::<$loader_name>();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct $loader_name;
|
||||
|
||||
impl AssetLoader for $loader_name {
|
||||
type Asset = $asset_type;
|
||||
|
||||
type Settings = ();
|
||||
|
||||
type Error = String;
|
||||
|
||||
async fn load<'a>(
|
||||
&'a self,
|
||||
reader: &'a mut Reader<'_>,
|
||||
_settings: &'a Self::Settings,
|
||||
load_context: &'a mut LoadContext<'_>,
|
||||
) -> Result<Self::Asset, Self::Error> {
|
||||
let mut bytes = Vec::new();
|
||||
let read_result = reader.read_to_end(&mut bytes).await;
|
||||
if read_result.is_err() {
|
||||
return Err(read_result.err().unwrap().to_string());
|
||||
}
|
||||
let serialized: Result<Self::Asset, _> =
|
||||
ron::de::from_bytes::<Self::Asset>(&bytes);
|
||||
if serialized.is_err() {
|
||||
return Err(serialized.err().unwrap().to_string());
|
||||
}
|
||||
let mut asset = serialized.unwrap();
|
||||
$(
|
||||
|
||||
asset.$handle_name = load_context.load(&asset.$string_name);
|
||||
)*
|
||||
$(
|
||||
for i in 0..asset.$string_array_name.len(){
|
||||
asset.$handle_array_name.push(load_context.load(&asset.$string_array_name[i]));
|
||||
}
|
||||
)?
|
||||
return Ok(asset);
|
||||
}
|
||||
|
||||
fn extensions(&self) -> &[&str] {
|
||||
$extensions
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
[package]
|
||||
name = "asset_loader_proc"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
serde = "1.0.204"
|
||||
serde_json = "1.0.120"
|
||||
bevy = "0.14.2"
|
||||
ron = "0.8.1"
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -6,7 +6,7 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.14.2"
|
||||
bevy = "0.14.0"
|
||||
noise = "0.9.0"
|
||||
serde = { version = "1.0.203", features = ["derive"] }
|
||||
serde_json = "1.0.115"
|
||||
|
||||
@@ -16,21 +16,6 @@ pub const HEX_CORNERS: [Vec3; 6] = [
|
||||
Vec3::new(-INNER_RADIUS, 0., 0.5 * OUTER_RADIUS),
|
||||
];
|
||||
|
||||
pub const WATER_HEX_CORNERS: [Vec3; 12] = [
|
||||
Vec3::new(0., 0., OUTER_RADIUS),
|
||||
Vec3::new(INNER_RADIUS / 2.0, 0., 0.75 * OUTER_RADIUS),
|
||||
Vec3::new(INNER_RADIUS, 0., 0.5 * OUTER_RADIUS),
|
||||
Vec3::new(INNER_RADIUS, 0., 0.),
|
||||
Vec3::new(INNER_RADIUS, 0., -0.5 * OUTER_RADIUS),
|
||||
Vec3::new(INNER_RADIUS / 2.0, 0., -0.75 * OUTER_RADIUS),
|
||||
Vec3::new(0., 0., -OUTER_RADIUS),
|
||||
Vec3::new(-INNER_RADIUS / 2.0, 0., -0.75 * OUTER_RADIUS),
|
||||
Vec3::new(-INNER_RADIUS, 0., -0.5 * OUTER_RADIUS),
|
||||
Vec3::new(-INNER_RADIUS, 0., 0.),
|
||||
Vec3::new(-INNER_RADIUS, 0., 0.5 * OUTER_RADIUS),
|
||||
Vec3::new(-INNER_RADIUS / 2.0, 0., 0.75 * OUTER_RADIUS),
|
||||
];
|
||||
|
||||
pub const HEX_NORMALS: [Vec3; 6] = [
|
||||
Vec3::new(INNER_RADIUS / 2., 0., (OUTER_RADIUS + 0.5 * OUTER_RADIUS) / 2.),
|
||||
Vec3::Z,
|
||||
|
||||
@@ -39,7 +39,6 @@ pub fn generate_chunk_mesh(chunk: &MeshChunkData) -> Mesh {
|
||||
// &mut tex,
|
||||
chunk.textures[idx][0],
|
||||
chunk.textures[idx][1],
|
||||
chunk.overlay_textures[idx],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -64,14 +63,10 @@ fn create_tile(
|
||||
normals: &mut Vec<Vec3>,
|
||||
texture_index: u32,
|
||||
side_texture_index: u32,
|
||||
side_overlay_texture_index: Option<u32>,
|
||||
) {
|
||||
let uv_offset = Vec2::splat(0.5);
|
||||
let tex_off = Vec2::new(texture_index as f32, 0.);
|
||||
let side_tex_off = Vec2::new(
|
||||
pack_texture_data(side_texture_index, side_overlay_texture_index) as f32,
|
||||
0.,
|
||||
);
|
||||
let side_tex_off = Vec2::new(side_texture_index as f32, 0.);
|
||||
|
||||
let idx = verts.len() as u32;
|
||||
for i in 0..6 {
|
||||
@@ -99,148 +94,6 @@ fn create_tile(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_chunk_water_mesh(chunk: &MeshChunkData, sealevel: f32, map_width: usize, map_height: usize) -> Mesh {
|
||||
#[cfg(feature = "tracing")]
|
||||
let _gen_mesh = info_span!("Generate Water Surface Mesh").entered();
|
||||
let vertex_count: usize = Chunk::SIZE * Chunk::SIZE * 7;
|
||||
let mut verts = Vec::with_capacity(vertex_count);
|
||||
let mut uvs = Vec::with_capacity(vertex_count);
|
||||
let mut indices = Vec::with_capacity(vertex_count);
|
||||
let mut normals = Vec::with_capacity(vertex_count);
|
||||
|
||||
for z in 0..Chunk::SIZE {
|
||||
for x in 0..Chunk::SIZE {
|
||||
let idx = x + z * Chunk::SIZE;
|
||||
let height = chunk.heights[idx];
|
||||
if height > sealevel {
|
||||
continue;
|
||||
}
|
||||
let off_pos = Vec3::new(x as f32, sealevel, z as f32);
|
||||
let tile_pos = offset3d_to_world(off_pos);
|
||||
let coord = HexCoord::from_grid_pos(x, z);
|
||||
let (n, neighbor_has_land) = chunk.get_neighbors_with_water_info(&coord);
|
||||
|
||||
create_tile_water_surface(
|
||||
tile_pos,
|
||||
chunk.distance_to_land[idx],
|
||||
&n,
|
||||
neighbor_has_land,
|
||||
&mut verts,
|
||||
&mut uvs,
|
||||
&mut indices,
|
||||
&mut normals,
|
||||
);
|
||||
}
|
||||
}
|
||||
let mesh = Mesh::new(
|
||||
PrimitiveTopology::TriangleList,
|
||||
RenderAssetUsages::MAIN_WORLD | RenderAssetUsages::RENDER_WORLD,
|
||||
)
|
||||
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, verts)
|
||||
.with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, uvs)
|
||||
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals)
|
||||
.with_inserted_indices(Indices::U32(indices));
|
||||
return mesh;
|
||||
}
|
||||
|
||||
fn create_tile_water_surface(
|
||||
pos: Vec3,
|
||||
dist_to_land: f32,
|
||||
neighbors: &[(f32, Option<f32>); 6],
|
||||
neighbor_has_land: bool,
|
||||
verts: &mut Vec<Vec3>,
|
||||
uvs: &mut Vec<Vec2>,
|
||||
indices: &mut Vec<u32>,
|
||||
normals: &mut Vec<Vec3>,
|
||||
) {
|
||||
if !neighbor_has_land {
|
||||
crate_tile_water_inner_surface(pos, dist_to_land, neighbors, verts, uvs, indices, normals);
|
||||
return;
|
||||
}
|
||||
crate_tile_water_shore_surface(pos, dist_to_land, neighbors, verts, uvs, indices, normals);
|
||||
}
|
||||
|
||||
fn crate_tile_water_inner_surface(
|
||||
pos: Vec3,
|
||||
dist_to_land: f32,
|
||||
neighbors: &[(f32, Option<f32>); 6],
|
||||
verts: &mut Vec<Vec3>,
|
||||
uvs: &mut Vec<Vec2>,
|
||||
indices: &mut Vec<u32>,
|
||||
normals: &mut Vec<Vec3>,
|
||||
) {
|
||||
//todo: share verts
|
||||
let idx = verts.len() as u32;
|
||||
for i in 0..6 {
|
||||
let p = pos + HEX_CORNERS[i];
|
||||
verts.push(p);
|
||||
let n1 = if let Some(v) = neighbors[i].1 { v } else { dist_to_land };
|
||||
let n2 = if let Some(v) = neighbors[(i + 5) % 6].1 {
|
||||
v
|
||||
} else {
|
||||
dist_to_land
|
||||
};
|
||||
let d = (n1 + n2 + dist_to_land) / 3.0;
|
||||
uvs.push(Vec2::new(0.0, d.remap(0., 4., 1.0, 0.0)));
|
||||
normals.push(Vec3::Y);
|
||||
}
|
||||
for i in 0..3 {
|
||||
let off = i * 2;
|
||||
indices.push(off + idx);
|
||||
indices.push(((off + 1) % 6) + idx);
|
||||
indices.push(((off + 2) % 6) + idx);
|
||||
}
|
||||
indices.push(idx);
|
||||
indices.push(idx + 2);
|
||||
indices.push(idx + 4);
|
||||
}
|
||||
|
||||
fn crate_tile_water_shore_surface(
|
||||
pos: Vec3,
|
||||
dist_to_land: f32,
|
||||
neighbors: &[(f32, Option<f32>); 6],
|
||||
verts: &mut Vec<Vec3>,
|
||||
uvs: &mut Vec<Vec2>,
|
||||
indices: &mut Vec<u32>,
|
||||
normals: &mut Vec<Vec3>,
|
||||
) {
|
||||
let idx = verts.len() as u32;
|
||||
//todo: only use triangle fan when on shoreline
|
||||
verts.push(pos);
|
||||
uvs.push(Vec2::new(0.0, dist_to_land.remap(0., 4., 1.0, 0.0)));
|
||||
normals.push(Vec3::Y);
|
||||
for i in 0..12 {
|
||||
let p = pos + WATER_HEX_CORNERS[i];
|
||||
verts.push(p);
|
||||
let ni = i / 2;
|
||||
let n = neighbors[ni];
|
||||
let nn = neighbors[(ni + 5) % 6];
|
||||
let mut uv = Vec2::new(0.0, dist_to_land.remap(0., 4., 1.0, 0.0));
|
||||
|
||||
if nn.0 > pos.y || n.0 > pos.y {
|
||||
uv.x = 1.0;
|
||||
}
|
||||
if ni * 2 != i {
|
||||
if n.0 <= pos.y {
|
||||
uv.x = 0.0;
|
||||
}
|
||||
let d = if let Some(v) = n.1 { v } else { dist_to_land };
|
||||
uv.y = ((d + dist_to_land) / 2.0).remap(0., 4., 1.0, 0.0);
|
||||
} else {
|
||||
let d = if let Some(v) = n.1 { v } else { dist_to_land };
|
||||
let d2 = if let Some(v) = nn.1 { v } else { dist_to_land };
|
||||
uv.y = ((d + d2 + dist_to_land) / 3.0).remap(0., 4., 1.0, 0.0);
|
||||
}
|
||||
|
||||
indices.push(idx);
|
||||
indices.push(idx + 1 + i as u32);
|
||||
indices.push(idx + 1 + ((i as u32 + 1) % 12));
|
||||
|
||||
uvs.push(uv);
|
||||
normals.push(Vec3::Y);
|
||||
}
|
||||
}
|
||||
|
||||
fn create_tile_wall(
|
||||
pos: Vec3,
|
||||
dir: usize,
|
||||
@@ -283,13 +136,6 @@ fn create_tile_wall(
|
||||
uvs.push((Vec2::new(1., pos.y - height) / TEX_MULTI) + tex_off);
|
||||
}
|
||||
|
||||
fn pack_texture_data(texture: u32, overlay: Option<u32>) -> u32 {
|
||||
if let Some(ovr) = overlay {
|
||||
return texture + (ovr << 5);
|
||||
}
|
||||
return texture + (texture << 5);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
@@ -332,17 +178,7 @@ mod tests {
|
||||
//4 side faces
|
||||
let nbors = [2.0, 2.0, 0.0, 0.0, 0.0, 0.0];
|
||||
|
||||
create_tile(
|
||||
Vec3::Y,
|
||||
&nbors,
|
||||
&mut verts,
|
||||
&mut uvs,
|
||||
&mut indices,
|
||||
&mut normals,
|
||||
3,
|
||||
7,
|
||||
None,
|
||||
);
|
||||
create_tile(Vec3::Y, &nbors, &mut verts, &mut uvs, &mut indices, &mut normals, 3, 7);
|
||||
|
||||
assert!(verts.len() == (6 + 4 * 4), "Number of verts don't match");
|
||||
assert!(uvs.len() == (6 + 4 * 4), "Number of uvs don't match");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::hex_utils::HexCoord;
|
||||
use crate::map::biome_map::BiomeChunk;
|
||||
use crate::map::biome_map::{self, BiomeChunk, BiomeMap};
|
||||
use crate::prelude::*;
|
||||
use crate::tile_manager::TileAsset;
|
||||
use crate::tile_mapper::TileMapperAsset;
|
||||
|
||||
@@ -8,7 +8,7 @@ use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||
|
||||
use crate::biome_painter::BiomePainter;
|
||||
use crate::map::biome_map::{BiomeChunk, BiomeData, BiomeMap};
|
||||
use crate::prelude::*;
|
||||
use crate::{map, prelude::*};
|
||||
|
||||
pub fn generate_heightmap(cfg: &GenerationConfig, seed: u32, painter: &BiomePainter) -> (Map, BiomeMap) {
|
||||
let biomes = generate_biomes(cfg, seed, painter);
|
||||
@@ -39,7 +39,7 @@ pub fn generate_heightmap(cfg: &GenerationConfig, seed: u32, painter: &BiomePain
|
||||
chunks,
|
||||
height: cfg.size.y as usize,
|
||||
width: cfg.size.x as usize,
|
||||
sealevel: cfg.sea_level as f32,
|
||||
sea_level: cfg.sea_level as f32,
|
||||
min_level: min,
|
||||
max_level: max,
|
||||
biome_count: painter.biomes.len(),
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use num::{PrimInt, Saturating};
|
||||
use std::fmt::Display;
|
||||
|
||||
use crate::prelude::Chunk;
|
||||
@@ -55,11 +56,11 @@ pub fn tile_to_world_distance(dist: u32) -> f32 {
|
||||
return dist as f32 * (2. * INNER_RADIUS);
|
||||
}
|
||||
|
||||
pub fn get_tile_count_in_range(radius: usize) -> usize {
|
||||
pub fn get_tile_count(radius: usize) -> usize {
|
||||
return 1 + 3 * (radius + 1) * radius;
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Hash)]
|
||||
#[derive(Default, Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct HexCoord {
|
||||
pub hex: IVec3,
|
||||
}
|
||||
@@ -239,7 +240,7 @@ impl HexCoord {
|
||||
|
||||
pub fn hex_select(&self, radius: usize, include_center: bool) -> Vec<HexCoord> {
|
||||
assert!(radius != 0, "Radius cannot be zero");
|
||||
let mut result = Vec::with_capacity(get_tile_count_in_range(radius));
|
||||
let mut result = Vec::with_capacity(get_tile_count(radius));
|
||||
|
||||
if include_center {
|
||||
result.push(*self);
|
||||
@@ -266,7 +267,7 @@ impl HexCoord {
|
||||
width: usize,
|
||||
) -> Vec<HexCoord> {
|
||||
assert!(radius != 0, "Radius cannot be zero");
|
||||
let mut result = Vec::with_capacity(get_tile_count_in_range(radius));
|
||||
let mut result = Vec::with_capacity(get_tile_count(radius));
|
||||
|
||||
if include_center {
|
||||
if self.is_in_bounds(height, width) {
|
||||
@@ -295,10 +296,10 @@ impl HexCoord {
|
||||
|
||||
let mut p = self.scale(4, radius);
|
||||
|
||||
// if radius == 1 {
|
||||
// result.push(*self);
|
||||
// return result;
|
||||
// }
|
||||
if radius == 1 {
|
||||
result.push(*self);
|
||||
return result;
|
||||
}
|
||||
|
||||
for i in 0..6 {
|
||||
for _j in 0..radius {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
use crate::hex_utils::SHORT_DIAGONAL;
|
||||
use bevy::prelude::*;
|
||||
|
||||
use super::biome_map::BiomeData;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Chunk {
|
||||
pub heights: [f32; Chunk::AREA],
|
||||
pub textures: [[u32; 2]; Chunk::AREA],
|
||||
pub overlay_textures: [Option<u32>; Chunk::AREA],
|
||||
// pub biome_data: [BiomeData; Chunk::AREA],
|
||||
pub biome_id: [usize; Chunk::AREA],
|
||||
pub chunk_offset: IVec2,
|
||||
@@ -18,7 +19,6 @@ impl Default for Chunk {
|
||||
Self {
|
||||
heights: [0.; Chunk::AREA],
|
||||
textures: [[0; 2]; Chunk::AREA],
|
||||
overlay_textures: [None; Chunk::AREA],
|
||||
// biome_data: [BiomeData::default(); Chunk::AREA],
|
||||
biome_id: [0; Chunk::AREA],
|
||||
chunk_offset: Default::default(),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_asset_loader::asset_collection::AssetCollection;
|
||||
use bevy_inspector_egui::InspectorOptions;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
@@ -2,32 +2,24 @@ use bevy::prelude::*;
|
||||
|
||||
use crate::hex_utils::*;
|
||||
|
||||
use super::{chunk::Chunk, mesh_chunk::MeshChunkData};
|
||||
use super::{
|
||||
biome_map::{BiomeData, BiomeMap},
|
||||
chunk::Chunk,
|
||||
mesh_chunk::MeshChunkData,
|
||||
};
|
||||
|
||||
#[derive(Resource, Clone)]
|
||||
pub struct Map {
|
||||
pub chunks: Vec<Chunk>,
|
||||
pub height: usize,
|
||||
pub width: usize,
|
||||
pub sealevel: f32,
|
||||
pub sea_level: f32,
|
||||
pub min_level: f32,
|
||||
pub max_level: f32,
|
||||
pub biome_count: usize,
|
||||
}
|
||||
|
||||
impl Map {
|
||||
pub fn get_tile_count(&self) -> usize {
|
||||
return self.get_tile_width() * self.get_tile_height();
|
||||
}
|
||||
|
||||
pub fn get_tile_width(&self) -> usize {
|
||||
return self.width * Chunk::SIZE;
|
||||
}
|
||||
|
||||
pub fn get_tile_height(&self) -> usize {
|
||||
return self.height * Chunk::SIZE;
|
||||
}
|
||||
|
||||
pub fn get_chunk_mesh_data(&self, chunk_index: usize) -> MeshChunkData {
|
||||
#[cfg(feature = "tracing")]
|
||||
let _spawn_span = info_span!("Chunk Mesh Data").entered();
|
||||
@@ -35,51 +27,11 @@ impl Map {
|
||||
|
||||
return MeshChunkData {
|
||||
min_height: self.min_level,
|
||||
sealevel: self.sealevel,
|
||||
heights: chunk.heights.clone(),
|
||||
textures: chunk.textures.clone(),
|
||||
overlay_textures: chunk.overlay_textures.clone(),
|
||||
distance_to_land: self.get_distance_from_land(chunk.chunk_offset, 4),
|
||||
};
|
||||
}
|
||||
|
||||
fn get_distance_from_land(&self, chunk_offset: IVec2, range: usize) -> [f32; Chunk::AREA] {
|
||||
#[cfg(feature = "tracing")]
|
||||
let _spawn_span = info_span!("Chunk Land Dist Data").entered();
|
||||
let mut dists = [0.0; Chunk::AREA];
|
||||
let cx = chunk_offset.x as usize * Chunk::SIZE;
|
||||
let cz = chunk_offset.y as usize * Chunk::SIZE;
|
||||
for z in 0..Chunk::SIZE {
|
||||
for x in 0..Chunk::SIZE {
|
||||
let coord = HexCoord::from_grid_pos(x + cx, z + cz);
|
||||
let index = coord.to_chunk_local_index();
|
||||
|
||||
if !self.is_in_bounds(&coord) {
|
||||
warn!("Coord is not in bounds!?");
|
||||
}
|
||||
|
||||
//Current tile is land tile
|
||||
if self.sample_height(&coord) > self.sealevel {
|
||||
dists[index] = 0.0;
|
||||
continue;
|
||||
}
|
||||
|
||||
//Find closest land tile
|
||||
if let Some(d) = self.hex_select_first(&coord, range, false, |_t, h, r| {
|
||||
if h > self.sealevel {
|
||||
return Some(r as f32);
|
||||
}
|
||||
return None;
|
||||
}) {
|
||||
dists[index] = d;
|
||||
} else {
|
||||
dists[index] = range as f32;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dists;
|
||||
}
|
||||
|
||||
pub fn get_neighbors(&self, pos: &HexCoord) -> [Option<f32>; 6] {
|
||||
let mut results: [Option<f32>; 6] = [None; 6];
|
||||
let w = self.width * Chunk::SIZE;
|
||||
@@ -131,19 +83,52 @@ impl Map {
|
||||
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
|
||||
return chunk.biome_id[pos.to_chunk_local_index()];
|
||||
}
|
||||
/*
|
||||
pub fn get_biome_noise(&self, pos: &HexCoord) -> &BiomeData {
|
||||
assert!(
|
||||
self.is_in_bounds(pos),
|
||||
"The provided coordinate is not within the map bounds"
|
||||
);
|
||||
|
||||
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
|
||||
return &chunk.biome_data[pos.to_chunk_local_index()];
|
||||
}
|
||||
|
||||
pub fn get_moisture(&self, pos: &HexCoord) -> f32 {
|
||||
assert!(
|
||||
self.is_in_bounds(pos),
|
||||
"The provided coordinate is not within the map bounds"
|
||||
);
|
||||
|
||||
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
|
||||
return chunk.biome_data[pos.to_chunk_local_index()].moisture;
|
||||
}
|
||||
|
||||
pub fn get_tempurature(&self, pos: &HexCoord) -> f32 {
|
||||
assert!(
|
||||
self.is_in_bounds(pos),
|
||||
"The provided coordinate is not within the map bounds"
|
||||
);
|
||||
|
||||
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
|
||||
return chunk.biome_data[pos.to_chunk_local_index()].temperature;
|
||||
}
|
||||
|
||||
pub fn get_continentality(&self, pos: &HexCoord) -> f32 {
|
||||
assert!(
|
||||
self.is_in_bounds(pos),
|
||||
"The provided coordinate is not within the map bounds"
|
||||
);
|
||||
|
||||
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
|
||||
return chunk.biome_data[pos.to_chunk_local_index()].continentality;
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn get_center(&self) -> Vec3 {
|
||||
let w = self.get_world_width();
|
||||
let h = self.get_world_height();
|
||||
return Vec3::new(w / 2., self.sealevel, h / 2.);
|
||||
}
|
||||
|
||||
pub fn get_center_with_height(&self) -> Vec3 {
|
||||
let w = self.get_world_width();
|
||||
let h = self.get_world_height();
|
||||
let mut pos = Vec3::new(w / 2., self.sealevel, h / 2.);
|
||||
pos.y = self.sample_height(&HexCoord::from_world_pos(pos));
|
||||
return pos;
|
||||
return Vec3::new(w / 2., self.sea_level, h / 2.);
|
||||
}
|
||||
|
||||
pub fn get_world_width(&self) -> f32 {
|
||||
@@ -183,9 +168,9 @@ impl Map {
|
||||
assert!(radius != 0, "Radius cannot be zero");
|
||||
|
||||
let mut result = if include_center {
|
||||
Vec::with_capacity(get_tile_count_in_range(radius) + 1)
|
||||
Vec::with_capacity(get_tile_count(radius) + 1)
|
||||
} else {
|
||||
Vec::with_capacity(get_tile_count_in_range(radius))
|
||||
Vec::with_capacity(get_tile_count(radius))
|
||||
};
|
||||
if include_center {
|
||||
let h = self.sample_height(¢er);
|
||||
@@ -208,80 +193,6 @@ impl Map {
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn hex_select_first<OP, Ret>(
|
||||
&self,
|
||||
center: &HexCoord,
|
||||
radius: usize,
|
||||
include_center: bool,
|
||||
op: OP,
|
||||
) -> Option<Ret>
|
||||
where
|
||||
OP: (Fn(&HexCoord, f32, usize) -> Option<Ret>) + Sync + Send,
|
||||
{
|
||||
assert!(radius != 0, "Radius cannot be zero");
|
||||
|
||||
if include_center {
|
||||
let h = self.sample_height(¢er);
|
||||
let r = (op)(center, h, 0);
|
||||
if r.is_some() {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
for k in 0..(radius + 1) {
|
||||
let mut p = center.scale(4, k);
|
||||
for i in 0..6 {
|
||||
for _j in 0..k {
|
||||
p = p.get_neighbor(i);
|
||||
if self.is_in_bounds(&p) {
|
||||
let h = self.sample_height(&p);
|
||||
let r = (op)(&p, h, k);
|
||||
if r.is_some() {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
pub fn ring_select_first<OP, Ret>(
|
||||
&self,
|
||||
center: &HexCoord,
|
||||
start_radius: usize,
|
||||
end_radius: usize,
|
||||
op: OP,
|
||||
) -> Option<Ret>
|
||||
where
|
||||
OP: (Fn(&HexCoord, f32, usize) -> Option<Ret>) + Sync + Send,
|
||||
{
|
||||
assert!(start_radius != 0, "Start radius cannot be zero");
|
||||
assert!(
|
||||
start_radius > end_radius,
|
||||
"Start radius cannot be lower than end radius"
|
||||
);
|
||||
|
||||
for k in start_radius..(end_radius + 1) {
|
||||
let mut p = center.scale(4, k);
|
||||
for i in 0..6 {
|
||||
for _j in 0..k {
|
||||
p = p.get_neighbor(i);
|
||||
if self.is_in_bounds(&p) {
|
||||
let h = self.sample_height(&p);
|
||||
let r = (op)(&p, h, k);
|
||||
if r.is_some() {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
pub fn hex_select_mut<OP, Ret>(
|
||||
&mut self,
|
||||
center: &HexCoord,
|
||||
@@ -295,9 +206,9 @@ impl Map {
|
||||
assert!(radius != 0, "Radius cannot be zero");
|
||||
|
||||
let mut result = if include_center {
|
||||
Vec::with_capacity(get_tile_count_in_range(radius) + 1)
|
||||
Vec::with_capacity(get_tile_count(radius) + 1)
|
||||
} else {
|
||||
Vec::with_capacity(get_tile_count_in_range(radius))
|
||||
Vec::with_capacity(get_tile_count(radius))
|
||||
};
|
||||
if include_center {
|
||||
let h = self.sample_height_mut(¢er);
|
||||
|
||||
@@ -4,10 +4,10 @@ use bevy::{math::VectorSpace, prelude::*};
|
||||
use image::ImageBuffer;
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::hex_utils::HexCoord;
|
||||
use crate::{biome_painter::BiomePainter, hex_utils::HexCoord};
|
||||
|
||||
use super::{
|
||||
biome_map::BiomeMap,
|
||||
biome_map::{self, BiomeMap},
|
||||
chunk::Chunk,
|
||||
map::Map,
|
||||
};
|
||||
@@ -68,7 +68,7 @@ pub fn update_map(map: &Map, smooth: f32, image: &mut ImageBuffer<image::Rgba<u8
|
||||
let height = map.sample_height(&coord);
|
||||
|
||||
let mut color = Hsla::hsl(138.0, 1.0, 0.4);
|
||||
if height < map.sealevel {
|
||||
if height < map.sea_level {
|
||||
color.hue = 217.0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use bevy::math::IVec2;
|
||||
|
||||
use crate::hex_utils::HexCoord;
|
||||
|
||||
use super::chunk::Chunk;
|
||||
@@ -9,10 +5,7 @@ use super::chunk::Chunk;
|
||||
pub struct MeshChunkData {
|
||||
pub heights: [f32; Chunk::AREA],
|
||||
pub textures: [[u32; 2]; Chunk::AREA],
|
||||
pub overlay_textures: [Option<u32>; Chunk::AREA],
|
||||
pub min_height: f32,
|
||||
pub sealevel: f32,
|
||||
pub distance_to_land: [f32; Chunk::AREA],
|
||||
}
|
||||
|
||||
impl MeshChunkData {
|
||||
@@ -29,58 +22,4 @@ impl MeshChunkData {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
pub fn get_neighbors_with_water_info(&self, coord: &HexCoord) -> ([(f32, Option<f32>); 6], bool) {
|
||||
let mut has_land = false;
|
||||
let mut data = [(self.min_height, None); 6];
|
||||
let n_tiles = coord.get_neighbors();
|
||||
for i in 0..6 {
|
||||
let n = n_tiles[i];
|
||||
if !n.is_in_bounds(Chunk::SIZE, Chunk::SIZE) {
|
||||
continue;
|
||||
}
|
||||
let idx = n.to_index(Chunk::SIZE);
|
||||
data[i] = (self.heights[idx], Some(self.distance_to_land[idx]));
|
||||
if data[i].0 > self.sealevel {
|
||||
has_land = true;
|
||||
}
|
||||
}
|
||||
return (data, has_land);
|
||||
}
|
||||
|
||||
pub fn caluclate_water_distances(data: &mut Vec<MeshChunkData>, height: usize, width: usize, range: usize) {
|
||||
let mut open: VecDeque<(HexCoord, f32, usize)> = VecDeque::new();
|
||||
let mut closed: Vec<(HexCoord, f32)> = Vec::new();
|
||||
for z in 0..height {
|
||||
for x in 0..width {
|
||||
let chunk = &mut data[z * height + x];
|
||||
chunk.prepare_chunk_open(x * Chunk::SIZE, z * Chunk::SIZE, &mut open);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_chunk_open(&mut self, offset_x: usize, offset_z: usize, open: &mut VecDeque<(HexCoord, f32, usize)>) {
|
||||
for z in 0..Chunk::SIZE {
|
||||
for x in 0..Chunk::SIZE {
|
||||
let coord = HexCoord::from_grid_pos(x + offset_x, z + offset_z);
|
||||
let idx = coord.to_chunk_local_index();
|
||||
let h = self.heights[idx];
|
||||
self.distance_to_land[idx] = if h > self.sealevel { 0.0 } else { 4.0 };
|
||||
if h > self.sealevel {
|
||||
open.push_back((coord, h, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fill_chunk_borders(
|
||||
&mut self,
|
||||
chunks: &Vec<MeshChunkData>,
|
||||
offset: IVec2,
|
||||
open: &mut VecDeque<(HexCoord, f32, usize)>,
|
||||
closed: &mut Vec<(HexCoord, f32)>,
|
||||
) {
|
||||
self.prepare_chunk_open(offset.x as usize * Chunk::SIZE, offset.y as usize * Chunk::SIZE, open);
|
||||
todo!("Fill closed list with bordering tiles")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ pub struct TileAsset {
|
||||
#[serde(skip)]
|
||||
pub texture: String,
|
||||
pub side_texture_id: u32,
|
||||
pub side_overlay_id: Option<u32>,
|
||||
#[serde(skip)]
|
||||
pub side_texture: String,
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.14.2"
|
||||
bevy = "0.14.0"
|
||||
world_generation = { path = "../../engine/world_generation" }
|
||||
shared = { path = "../shared" }
|
||||
bevy_rapier3d = "0.27.0"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use std::path::Display;
|
||||
|
||||
use bevy::prelude::Resource;
|
||||
use shared::building::BuildingIdentifier;
|
||||
|
||||
@@ -7,16 +7,11 @@ build = "build.rs"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = { version = "0.14.2", features = ["file_watcher"] }
|
||||
bevy = { version = "0.14.0", features = ["file_watcher"] }
|
||||
bevy-inspector-egui = "0.25.0"
|
||||
iyes_perf_ui = "0.3.0"
|
||||
noise = "0.8.2"
|
||||
world_generation = { path = "../../engine/world_generation" }
|
||||
bevy_rapier3d = { version = "0.27.0", features = [
|
||||
"simd-stable",
|
||||
"parallel",
|
||||
"debug-render-3d",
|
||||
] }
|
||||
rayon = "1.10.0"
|
||||
buildings = { path = "../buildings" }
|
||||
units = { path = "../units" }
|
||||
@@ -26,13 +21,8 @@ bevy_asset_loader = { version = "0.21.0", features = [
|
||||
"3d",
|
||||
] }
|
||||
ron = "0.8.1"
|
||||
avian3d = { version = "0.1.2" }
|
||||
image = "0.25.2"
|
||||
|
||||
[features]
|
||||
tracing = [
|
||||
"bevy/trace_tracy",
|
||||
"world_generation/tracing",
|
||||
"buildings/tracing",
|
||||
"units/tracing",
|
||||
"shared/tracing",
|
||||
]
|
||||
tracing = ["bevy/trace_tracy", "world_generation/tracing", "buildings/tracing"]
|
||||
|
||||
Submodule game/main/assets updated: 67cf2d46ce...d9e7ec8297
@@ -2,12 +2,11 @@ use bevy::core_pipeline::experimental::taa::{TemporalAntiAliasBundle, TemporalAn
|
||||
use bevy::core_pipeline::prepass::DepthPrepass;
|
||||
use bevy::input::mouse::{MouseMotion, MouseScrollUnit, MouseWheel};
|
||||
use bevy::prelude::*;
|
||||
use bevy::window::{CursorGrabMode, PrimaryWindow};
|
||||
use shared::sets::GameplaySet;
|
||||
use bevy::window::CursorGrabMode;
|
||||
use shared::states::MenuState;
|
||||
use shared::tags::MainCamera;
|
||||
use world_generation::hex_utils::HexCoord;
|
||||
use world_generation::prelude::Map;
|
||||
use world_generation::states::GeneratorState;
|
||||
|
||||
use super::components::*;
|
||||
|
||||
@@ -16,15 +15,11 @@ pub struct PhosCameraPlugin;
|
||||
impl Plugin for PhosCameraPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.register_type::<PhosCamera>();
|
||||
app.register_type::<PhosOrbitCamera>();
|
||||
|
||||
app.add_systems(PreStartup, setup);
|
||||
|
||||
// app.add_systems(Update, rts_camera_system.in_set(GameplaySet));
|
||||
// app.add_systems(PostUpdate, limit_camera_bounds.in_set(GameplaySet));
|
||||
app.add_systems(Update, orbit_camera_upate.in_set(GameplaySet));
|
||||
|
||||
app.add_systems(Update, init_bounds.run_if(in_state(GeneratorState::SpawnMap)));
|
||||
app.add_systems(Update, rts_camera_system.run_if(in_state(MenuState::InGame)));
|
||||
app.add_systems(PostUpdate, limit_camera_bounds.run_if(in_state(MenuState::InGame)));
|
||||
//Free Cam
|
||||
//app.add_systems(Update, (grab_mouse, (update_camera, update_camera_mouse).chain()));
|
||||
|
||||
@@ -32,22 +27,6 @@ impl Plugin for PhosCameraPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
fn init_bounds(
|
||||
mut commands: Commands,
|
||||
mut cam: Query<(&mut Transform, Entity), With<PhosCamera>>,
|
||||
heightmap: Res<Map>,
|
||||
) {
|
||||
let (mut cam_t, cam_entity) = cam.single_mut();
|
||||
cam_t.translation = heightmap.get_center();
|
||||
commands
|
||||
.entity(cam_entity)
|
||||
.insert(CameraBounds::from_size(heightmap.get_world_size()))
|
||||
.insert(PhosOrbitCamera {
|
||||
target: heightmap.get_center_with_height(),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands, mut msaa: ResMut<Msaa>) {
|
||||
commands
|
||||
.spawn((
|
||||
@@ -58,94 +37,126 @@ fn setup(mut commands: Commands, mut msaa: ResMut<Msaa>) {
|
||||
PhosCamera::default(),
|
||||
MainCamera,
|
||||
DepthPrepass,
|
||||
PhosOrbitCamera::default(),
|
||||
PhosCameraTargets::default(),
|
||||
))
|
||||
.insert(TemporalAntiAliasBundle::default());
|
||||
|
||||
*msaa = Msaa::Off;
|
||||
}
|
||||
fn update_camera(
|
||||
mut cam_query: Query<(&PhosCamera, &mut Transform)>,
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
time: Res<Time>,
|
||||
windows: Query<&Window>,
|
||||
) {
|
||||
let window = windows.single();
|
||||
if window.cursor.grab_mode != CursorGrabMode::Locked {
|
||||
return;
|
||||
}
|
||||
let (cam, mut transform) = cam_query.single_mut();
|
||||
|
||||
fn orbit_camera_upate(
|
||||
mut cam_query: Query<(&mut Transform, &PhosCamera, &mut PhosOrbitCamera, &CameraBounds)>,
|
||||
let mut move_vec = Vec3::ZERO;
|
||||
if keyboard_input.pressed(KeyCode::KeyA) {
|
||||
move_vec += Vec3::NEG_X;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::KeyD) {
|
||||
move_vec += Vec3::X;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::KeyW) {
|
||||
move_vec += Vec3::NEG_Z;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::KeyS) {
|
||||
move_vec += Vec3::Z;
|
||||
}
|
||||
|
||||
let rot = transform.rotation;
|
||||
move_vec = (rot * move_vec.normalize_or_zero()) * cam.speed * time.delta_seconds();
|
||||
|
||||
if keyboard_input.pressed(KeyCode::ShiftLeft) {
|
||||
move_vec += Vec3::from(transform.down());
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::Space) {
|
||||
move_vec += Vec3::from(transform.up());
|
||||
}
|
||||
|
||||
transform.translation += move_vec.normalize_or_zero() * cam.speed * time.delta_seconds();
|
||||
}
|
||||
|
||||
fn update_camera_mouse(
|
||||
mut cam_query: Query<&mut Transform, With<PhosCamera>>,
|
||||
mut mouse_move: EventReader<MouseMotion>,
|
||||
time: Res<Time>,
|
||||
windows: Query<&Window>,
|
||||
) {
|
||||
let window = windows.single();
|
||||
if window.cursor.grab_mode != CursorGrabMode::Locked {
|
||||
return;
|
||||
}
|
||||
let mut transform = cam_query.single_mut();
|
||||
|
||||
for ev in mouse_move.read() {
|
||||
let (mut yaw, mut pitch, _) = transform.rotation.to_euler(EulerRot::YXZ);
|
||||
match window.cursor.grab_mode {
|
||||
CursorGrabMode::None => (),
|
||||
_ => {
|
||||
// Using smallest of height or width ensures equal vertical and horizontal sensitivity
|
||||
pitch -= ev.delta.y.to_radians() * time.delta_seconds() * 5.;
|
||||
yaw -= ev.delta.x.to_radians() * time.delta_seconds() * 5.;
|
||||
}
|
||||
}
|
||||
|
||||
pitch = pitch.clamp(-1.54, 1.54);
|
||||
|
||||
// Order is important to prevent unintended roll
|
||||
transform.rotation = Quat::from_axis_angle(Vec3::Y, yaw) * Quat::from_axis_angle(Vec3::X, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
fn grab_mouse(mut windows: Query<&mut Window>, mouse: Res<ButtonInput<MouseButton>>, key: Res<ButtonInput<KeyCode>>) {
|
||||
let mut window = windows.single_mut();
|
||||
|
||||
if mouse.just_pressed(MouseButton::Middle) {
|
||||
window.cursor.visible = false;
|
||||
window.cursor.grab_mode = CursorGrabMode::Locked;
|
||||
}
|
||||
|
||||
if key.just_pressed(KeyCode::Escape) {
|
||||
window.cursor.visible = true;
|
||||
window.cursor.grab_mode = CursorGrabMode::None;
|
||||
}
|
||||
}
|
||||
|
||||
fn rts_camera_system(
|
||||
mut cam_query: Query<(&mut Transform, &PhosCamera, &mut PhosCameraTargets)>,
|
||||
mut wheel: EventReader<MouseWheel>,
|
||||
mut mouse_motion: EventReader<MouseMotion>,
|
||||
mouse: Res<ButtonInput<MouseButton>>,
|
||||
mut window_query: Query<&mut Window, With<PrimaryWindow>>,
|
||||
key: Res<ButtonInput<KeyCode>>,
|
||||
time: Res<Time>,
|
||||
map: Res<Map>,
|
||||
#[cfg(debug_assertions)] mut gizmos: Gizmos,
|
||||
heightmap: Res<Map>,
|
||||
) {
|
||||
let (mut transform, config, mut orbit, bounds) = cam_query.single_mut();
|
||||
let mut window = window_query.single_mut();
|
||||
|
||||
let target = orbit.target;
|
||||
let mut cam_pos = target;
|
||||
|
||||
//Apply Camera Dist
|
||||
cam_pos -= orbit.forward * orbit.distance;
|
||||
|
||||
if mouse.pressed(MouseButton::Middle) {
|
||||
let mut orbit_move = Vec2::ZERO;
|
||||
for e in mouse_motion.read() {
|
||||
orbit_move += e.delta;
|
||||
}
|
||||
orbit_move *= config.pan_speed * time.delta_seconds() * -1.0;
|
||||
let rot_y = Quat::from_axis_angle(Vec3::Y, orbit_move.x);
|
||||
let right = orbit.forward.cross(Vec3::Y).normalize();
|
||||
let rot_x = Quat::from_axis_angle(right, orbit_move.y);
|
||||
orbit.forward = rot_x * rot_y * orbit.forward;
|
||||
// orbit.forward.y = orbit.forward.y.clamp(-0.9, 0.0);
|
||||
orbit.forward = orbit.forward.normalize();
|
||||
window.cursor.grab_mode = CursorGrabMode::Locked;
|
||||
window.cursor.visible = false;
|
||||
} else {
|
||||
window.cursor.grab_mode = CursorGrabMode::None;
|
||||
window.cursor.visible = true;
|
||||
}
|
||||
if key.pressed(KeyCode::KeyE) {
|
||||
let rot = Quat::from_axis_angle(Vec3::Y, f32::to_radians(config.speed) * time.delta_seconds());
|
||||
orbit.forward = rot * orbit.forward;
|
||||
} else if key.pressed(KeyCode::KeyQ) {
|
||||
let rot = Quat::from_axis_angle(Vec3::Y, f32::to_radians(-config.speed) * time.delta_seconds());
|
||||
orbit.forward = rot * orbit.forward;
|
||||
}
|
||||
|
||||
let (mut cam, cam_cfg, mut cam_targets) = cam_query.single_mut();
|
||||
let mut cam_move = Vec3::ZERO;
|
||||
let mut cam_pos = cam.translation;
|
||||
|
||||
if key.pressed(KeyCode::KeyA) {
|
||||
cam_move.x = 1.;
|
||||
} else if key.pressed(KeyCode::KeyD) {
|
||||
cam_move.x = -1.;
|
||||
} else if key.pressed(KeyCode::KeyD) {
|
||||
cam_move.x = 1.;
|
||||
}
|
||||
|
||||
if key.pressed(KeyCode::KeyW) {
|
||||
cam_move.z = 1.;
|
||||
} else if key.pressed(KeyCode::KeyS) {
|
||||
cam_move.z = -1.;
|
||||
} else if key.pressed(KeyCode::KeyS) {
|
||||
cam_move.z = 1.;
|
||||
}
|
||||
|
||||
let move_speed = if key.pressed(KeyCode::ShiftLeft) {
|
||||
config.speed * 2.0
|
||||
cam_cfg.speed * 2.
|
||||
} else {
|
||||
config.speed
|
||||
cam_cfg.speed
|
||||
};
|
||||
|
||||
if cam_move != Vec3::ZERO {
|
||||
cam_move = cam_move.normalize();
|
||||
let move_fwd = Vec3::new(orbit.forward.x, 0., orbit.forward.z).normalize();
|
||||
let move_rot = Quat::from_rotation_arc(Vec3::NEG_Z, move_fwd);
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
gizmos.arrow(orbit.target, orbit.target + move_fwd, LinearRgba::WHITE.with_alpha(0.5));
|
||||
gizmos.arrow(orbit.target, orbit.target - (move_rot * cam_move), LinearRgba::BLUE);
|
||||
}
|
||||
orbit.target -= (move_rot * cam_move) * move_speed * time.delta_seconds();
|
||||
orbit.target.y = sample_ground(orbit.target, &map);
|
||||
|
||||
orbit.target.x = orbit.target.x.clamp(bounds.min.x, bounds.max.x);
|
||||
orbit.target.z = orbit.target.z.clamp(bounds.min.y, bounds.max.y);
|
||||
}
|
||||
cam_move = cam_move.normalize_or_zero() * move_speed * time.delta_seconds();
|
||||
cam_pos += cam_move;
|
||||
|
||||
let mut scroll = 0.0;
|
||||
for e in wheel.read() {
|
||||
@@ -155,20 +166,56 @@ fn orbit_camera_upate(
|
||||
}
|
||||
}
|
||||
|
||||
orbit.distance -= scroll * time.delta_seconds() * config.zoom_speed;
|
||||
orbit.distance = orbit.distance.clamp(config.min_height, config.max_height);
|
||||
let ground_height = sample_ground(cam.translation, &heightmap);
|
||||
|
||||
// let ground_below_cam = sample_ground(cam_pos, &map) + config.min_height;
|
||||
// if cam_pos.y <= ground_below_cam {
|
||||
// cam_pos.y = ground_below_cam;
|
||||
// }
|
||||
cam_targets.height -= scroll;
|
||||
if cam_targets.height > cam_cfg.max_height {
|
||||
cam_targets.height = cam_cfg.max_height;
|
||||
}
|
||||
|
||||
// if cam_pos.y < target.y {
|
||||
// cam_pos.y = target.y;
|
||||
// }
|
||||
let min_height = ground_height + cam_cfg.min_height;
|
||||
|
||||
transform.translation = cam_pos;
|
||||
transform.look_at(target, Vec3::Y);
|
||||
if min_height != cam_targets.last_height {
|
||||
cam_targets.last_height = min_height;
|
||||
cam_targets.anim_time = 0.;
|
||||
cam_targets.rotate_time = 0.;
|
||||
}
|
||||
|
||||
if scroll != 0. {
|
||||
cam_targets.anim_time = 0.;
|
||||
cam_targets.rotate_time = 0.;
|
||||
if cam_targets.height < min_height {
|
||||
cam_targets.height = min_height;
|
||||
}
|
||||
}
|
||||
|
||||
let desired_height = if cam_targets.height < min_height {
|
||||
min_height
|
||||
} else {
|
||||
cam_targets.height
|
||||
};
|
||||
if cam_targets.anim_time < 1. {
|
||||
cam_targets.anim_time += time.delta_seconds() * cam_cfg.zoom_speed;
|
||||
cam_targets.anim_time = cam_targets.anim_time.min(1.);
|
||||
}
|
||||
cam_pos.y = f32::lerp(cam_pos.y, desired_height, cam_targets.anim_time);
|
||||
if cam_pos.y < min_height {
|
||||
cam_pos.y = min_height;
|
||||
}
|
||||
let t = cam_pos.y.remap(cam_cfg.min_height, cam_cfg.max_height, 0., 1.);
|
||||
|
||||
if cam_targets.rotate_time < 1. {
|
||||
cam_targets.rotate_time += time.delta_seconds();
|
||||
cam_targets.rotate_time = cam_targets.rotate_time.min(1.);
|
||||
}
|
||||
let angle = cam_cfg.min_angle.lerp(cam_cfg.max_angle, t);
|
||||
let mut rot = cam.rotation.to_euler(EulerRot::XYZ);
|
||||
rot.0 = -angle;
|
||||
cam.rotation = Quat::from_euler(EulerRot::XYZ, rot.0, rot.1, rot.2);
|
||||
// let rot = Quat::from_axis_angle(Vec3::X, -angle);
|
||||
// cam.rotation = rot;
|
||||
|
||||
cam.translation = cam_pos;
|
||||
}
|
||||
|
||||
fn sample_ground(pos: Vec3, heightmap: &Map) -> f32 {
|
||||
@@ -177,7 +224,7 @@ fn sample_ground(pos: Vec3, heightmap: &Map) -> f32 {
|
||||
let mut ground_height = if heightmap.is_in_bounds(&tile_under) {
|
||||
heightmap.sample_height(&tile_under)
|
||||
} else {
|
||||
heightmap.sealevel
|
||||
heightmap.sea_level
|
||||
};
|
||||
|
||||
for n in neighbors {
|
||||
@@ -187,8 +234,19 @@ fn sample_ground(pos: Vec3, heightmap: &Map) -> f32 {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ground_height < heightmap.sealevel {
|
||||
ground_height = heightmap.sealevel;
|
||||
if ground_height < heightmap.sea_level {
|
||||
ground_height = heightmap.sea_level;
|
||||
}
|
||||
return ground_height;
|
||||
}
|
||||
|
||||
fn limit_camera_bounds(mut cam_query: Query<(&mut Transform, &CameraBounds)>) {
|
||||
let (mut tranform, bounds) = cam_query.single_mut();
|
||||
|
||||
let mut pos = tranform.translation;
|
||||
|
||||
pos.x = pos.x.clamp(bounds.min.x, bounds.max.x);
|
||||
pos.z = pos.z.clamp(bounds.min.y, bounds.max.y);
|
||||
|
||||
tranform.translation = pos;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use bevy::{math::Direction3d, prelude::*};
|
||||
use rayon::str;
|
||||
use bevy::prelude::*;
|
||||
use world_generation::{hex_utils::SHORT_DIAGONAL, prelude::Chunk};
|
||||
|
||||
#[derive(Component, Reflect)]
|
||||
@@ -9,7 +8,6 @@ pub struct PhosCamera {
|
||||
pub max_height: f32,
|
||||
pub speed: f32,
|
||||
pub zoom_speed: f32,
|
||||
pub pan_speed: Vec2,
|
||||
pub min_angle: f32,
|
||||
pub max_angle: f32,
|
||||
}
|
||||
@@ -20,26 +18,30 @@ impl Default for PhosCamera {
|
||||
min_height: 10.,
|
||||
max_height: 420.,
|
||||
speed: 100.,
|
||||
pan_speed: Vec2::new(0.8, 0.5),
|
||||
zoom_speed: 200.,
|
||||
zoom_speed: 0.3,
|
||||
min_angle: (20. as f32).to_radians(),
|
||||
max_angle: 1.,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Component, Reflect)]
|
||||
pub struct PhosOrbitCamera {
|
||||
pub target: Vec3,
|
||||
pub distance: f32,
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct PhosCameraTargets {
|
||||
pub height: f32,
|
||||
pub forward: Vec3,
|
||||
pub last_height: f32,
|
||||
pub anim_time: f32,
|
||||
pub rotate_time: f32,
|
||||
}
|
||||
|
||||
impl Default for PhosOrbitCamera {
|
||||
impl Default for PhosCameraTargets {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
target: Default::default(),
|
||||
distance: 40.0,
|
||||
forward: Vec3::new(0.0, -0.5, 0.5).normalize(),
|
||||
height: Default::default(),
|
||||
forward: Vec3::NEG_Z,
|
||||
last_height: Default::default(),
|
||||
anim_time: Default::default(),
|
||||
rotate_time: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,11 +53,14 @@ pub struct CameraBounds {
|
||||
}
|
||||
|
||||
impl CameraBounds {
|
||||
pub fn from_size(world_size: Vec2) -> Self {
|
||||
pub fn from_size(size: UVec2) -> Self {
|
||||
let padding = Chunk::WORLD_SIZE;
|
||||
return Self {
|
||||
min: Vec2::ZERO - padding,
|
||||
max: world_size + padding,
|
||||
max: Vec2::new(
|
||||
(size.x as usize * Chunk::SIZE) as f32 * SHORT_DIAGONAL,
|
||||
(size.y * Chunk::SIZE as u32) as f32 * 1.5,
|
||||
) + padding,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ mod phos;
|
||||
mod prelude;
|
||||
mod shader_extensions;
|
||||
mod utlis;
|
||||
mod ui;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use avian3d::prelude::*;
|
||||
use bevy::ecs::world::CommandQueue;
|
||||
use bevy::prelude::*;
|
||||
use bevy::tasks::*;
|
||||
use bevy::utils::futures;
|
||||
use bevy_rapier3d::geometry::Collider;
|
||||
use bevy_rapier3d::geometry::TriMeshFlags;
|
||||
use shared::events::ChunkModifiedEvent;
|
||||
use shared::events::TileModifiedEvent;
|
||||
use world_generation::prelude::Map;
|
||||
@@ -33,7 +32,6 @@ fn chunk_rebuilder(
|
||||
heightmap: Res<Map>,
|
||||
) {
|
||||
let pool = AsyncComputeTaskPool::get();
|
||||
let map_size = UVec2::new(heightmap.width as u32, heightmap.height as u32);
|
||||
|
||||
for (chunk_entity, idx) in &chunk_query {
|
||||
#[cfg(feature = "tracing")]
|
||||
@@ -47,15 +45,10 @@ fn chunk_rebuilder(
|
||||
#[cfg(feature = "tracing")]
|
||||
let _spawn_span = info_span!("Rebuild Task").entered();
|
||||
let mut queue = CommandQueue::default();
|
||||
let (mesh, water_mesh, collider_data, _, _) =
|
||||
prepare_chunk_mesh(&chunk_data, chunk_data.sealevel, chunk_offset, chunk_index, map_size);
|
||||
let (mesh, collider_data, _, _) = prepare_chunk_mesh(&chunk_data, chunk_offset, chunk_index);
|
||||
#[cfg(feature = "tracing")]
|
||||
let trimesh_span = info_span!("Chunk Trimesh").entered();
|
||||
let c = Collider::trimesh_with_flags(
|
||||
collider_data.0,
|
||||
collider_data.1,
|
||||
TriMeshFlags::DELETE_DUPLICATE_TRIANGLES,
|
||||
);
|
||||
let c = Collider::trimesh(collider_data.0, collider_data.1);
|
||||
#[cfg(feature = "tracing")]
|
||||
drop(trimesh_span);
|
||||
queue.push(move |world: &mut World| {
|
||||
|
||||
@@ -3,10 +3,12 @@ use bevy::log::*;
|
||||
use bevy::{
|
||||
pbr::{ExtendedMaterial, NotShadowCaster},
|
||||
prelude::*,
|
||||
render::texture::ImageFormat,
|
||||
};
|
||||
use bevy_asset_loader::prelude::*;
|
||||
|
||||
use bevy_inspector_egui::quick::ResourceInspectorPlugin;
|
||||
use image::DynamicImage;
|
||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||
use shared::states::{AssetLoadState, GameplayState, MenuState};
|
||||
use world_generation::{
|
||||
@@ -14,22 +16,29 @@ use world_generation::{
|
||||
biome_painter::*,
|
||||
heightmap::generate_heightmap,
|
||||
hex_utils::{offset_to_index, SHORT_DIAGONAL},
|
||||
map::biome_map::BiomeMap,
|
||||
map::{
|
||||
biome_map::{self, BiomeMap},
|
||||
map_utils::{render_biome_noise_map, render_map},
|
||||
},
|
||||
prelude::*,
|
||||
tile_manager::*,
|
||||
tile_mapper::*,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
camera_system::components::*,
|
||||
prelude::{PhosAssets, PhosChunk, PhosChunkRegistry},
|
||||
shader_extensions::{
|
||||
chunk_material::ChunkMaterial,
|
||||
water_material::{WaterMaterial, WaterSettings},
|
||||
},
|
||||
utlis::chunk_utils::{paint_map, prepare_chunk_mesh_with_collider},
|
||||
utlis::{
|
||||
chunk_utils::{paint_map, prepare_chunk_mesh_with_collider},
|
||||
render_distance_system::RenderDistanceVisibility,
|
||||
},
|
||||
};
|
||||
|
||||
use super::{chunk_rebuild::ChunkRebuildPlugin, render_distance_system::RenderDistanceVisibility};
|
||||
use super::{chunk_rebuild::ChunkRebuildPlugin, terraforming_test::TerraFormingTestPlugin};
|
||||
|
||||
pub struct MapInitPlugin;
|
||||
|
||||
@@ -44,6 +53,7 @@ impl Plugin for MapInitPlugin {
|
||||
app.add_plugins(BiomeAssetPlugin);
|
||||
|
||||
app.add_plugins(ResourceInspectorPlugin::<GenerationConfig>::default());
|
||||
app.add_plugins(ResourceInspectorPlugin::<WaterInspect>::default());
|
||||
app.register_type::<ExtendedMaterial<StandardMaterial, WaterMaterial>>();
|
||||
app.register_asset_reflect::<ExtendedMaterial<StandardMaterial, WaterMaterial>>();
|
||||
app.add_plugins((
|
||||
@@ -84,7 +94,12 @@ impl Plugin for MapInitPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Reflect, Default)]
|
||||
#[reflect(Resource)]
|
||||
struct WaterInspect(Handle<ExtendedMaterial<StandardMaterial, WaterMaterial>>);
|
||||
|
||||
fn setup_materials(
|
||||
mut commands: Commands,
|
||||
mut phos_assets: ResMut<PhosAssets>,
|
||||
mut water_materials: ResMut<Assets<ExtendedMaterial<StandardMaterial, WaterMaterial>>>,
|
||||
) {
|
||||
@@ -105,6 +120,7 @@ fn setup_materials(
|
||||
..default()
|
||||
},
|
||||
});
|
||||
commands.insert_resource(WaterInspect(water_material.clone()));
|
||||
phos_assets.water_material = water_material;
|
||||
}
|
||||
|
||||
@@ -143,6 +159,7 @@ fn finalize_texture(
|
||||
|
||||
fn create_heightmap(
|
||||
mut commands: Commands,
|
||||
mut cam: Query<(&mut Transform, Entity), With<PhosCamera>>,
|
||||
mut next_state: ResMut<NextState<GeneratorState>>,
|
||||
biome_painter: Res<BiomePainter>,
|
||||
) {
|
||||
@@ -198,6 +215,10 @@ fn create_heightmap(
|
||||
};
|
||||
let (heightmap, biome_map) = generate_heightmap(&config, 42069, &biome_painter);
|
||||
|
||||
let (mut cam_t, cam_entity) = cam.single_mut();
|
||||
cam_t.translation = heightmap.get_center();
|
||||
|
||||
commands.entity(cam_entity).insert(CameraBounds::from_size(config.size));
|
||||
commands.insert_resource(heightmap);
|
||||
commands.insert_resource(biome_map);
|
||||
commands.insert_resource(config);
|
||||
@@ -219,19 +240,12 @@ fn spawn_map(
|
||||
) {
|
||||
paint_map(&mut heightmap, &biome_painter, &tile_assets, &tile_mappers);
|
||||
|
||||
let map_size = UVec2::new(heightmap.width as u32, heightmap.height as u32);
|
||||
let chunk_meshes: Vec<_> = heightmap
|
||||
.chunks
|
||||
.par_iter()
|
||||
.map(|chunk: &Chunk| {
|
||||
let index = offset_to_index(chunk.chunk_offset, heightmap.width);
|
||||
return prepare_chunk_mesh_with_collider(
|
||||
&heightmap.get_chunk_mesh_data(index),
|
||||
heightmap.sealevel,
|
||||
chunk.chunk_offset,
|
||||
index,
|
||||
map_size,
|
||||
);
|
||||
return prepare_chunk_mesh_with_collider(&heightmap.get_chunk_mesh_data(index), chunk.chunk_offset, index);
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -244,52 +258,36 @@ fn spawn_map(
|
||||
0.,
|
||||
(Chunk::SIZE / 2) as f32 * 1.5,
|
||||
);
|
||||
for (chunk_mesh, water_mesh, collider, pos, index) in chunk_meshes {
|
||||
for (mesh, collider, pos, index) in chunk_meshes {
|
||||
// let mesh_handle = meshes.a
|
||||
let chunk = commands
|
||||
.spawn((
|
||||
MaterialMeshBundle {
|
||||
mesh: meshes.add(chunk_mesh),
|
||||
material: atlas.chunk_material_handle.clone(),
|
||||
transform: Transform::from_translation(pos),
|
||||
..default()
|
||||
},
|
||||
PhosChunk::new(index),
|
||||
RenderDistanceVisibility::default().with_offset(visibility_offset),
|
||||
collider,
|
||||
))
|
||||
.id();
|
||||
let water = commands
|
||||
.spawn((
|
||||
MaterialMeshBundle {
|
||||
mesh: meshes.add(water_mesh),
|
||||
material: atlas.water_material.clone(),
|
||||
transform: Transform::from_translation(pos),
|
||||
..default()
|
||||
},
|
||||
PhosChunk::new(index),
|
||||
NotShadowCaster,
|
||||
RenderDistanceVisibility::default().with_offset(visibility_offset),
|
||||
))
|
||||
.id();
|
||||
registry.chunks.push(chunk);
|
||||
registry.waters.push(water);
|
||||
let chunk = commands.spawn((
|
||||
MaterialMeshBundle {
|
||||
mesh: meshes.add(mesh),
|
||||
material: atlas.chunk_material_handle.clone(),
|
||||
transform: Transform::from_translation(pos),
|
||||
..default()
|
||||
},
|
||||
PhosChunk::new(index),
|
||||
RenderDistanceVisibility::default().with_offset(visibility_offset),
|
||||
collider,
|
||||
));
|
||||
registry.chunks.push(chunk.id());
|
||||
}
|
||||
}
|
||||
|
||||
// commands.spawn((
|
||||
// MaterialMeshBundle {
|
||||
// transform: Transform::from_translation(heightmap.get_center()),
|
||||
// mesh: meshes.add(
|
||||
// Plane3d::default()
|
||||
// .mesh()
|
||||
// .size(heightmap.get_world_width(), heightmap.get_world_height()),
|
||||
// ),
|
||||
// material: atlas.water_material.clone(),
|
||||
// ..default()
|
||||
// },
|
||||
// NotShadowCaster,
|
||||
// ));
|
||||
commands.spawn((
|
||||
MaterialMeshBundle {
|
||||
transform: Transform::from_translation(heightmap.get_center()),
|
||||
mesh: meshes.add(
|
||||
Plane3d::default()
|
||||
.mesh()
|
||||
.size(heightmap.get_world_width(), heightmap.get_world_height()),
|
||||
),
|
||||
material: atlas.water_material.clone(),
|
||||
..default()
|
||||
},
|
||||
NotShadowCaster,
|
||||
));
|
||||
|
||||
commands.insert_resource(registry);
|
||||
generator_state.set(GeneratorState::Idle);
|
||||
|
||||
@@ -2,4 +2,3 @@ pub mod chunk_rebuild;
|
||||
pub mod map_init;
|
||||
pub mod prelude;
|
||||
pub mod terraforming_test;
|
||||
pub mod render_distance_system;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use avian3d::prelude::*;
|
||||
use bevy::{prelude::*, utils::hashbrown::HashSet, window::PrimaryWindow};
|
||||
use bevy_rapier3d::{pipeline::QueryFilter, plugin::RapierContext};
|
||||
use shared::{
|
||||
events::{ChunkModifiedEvent, TileModifiedEvent},
|
||||
resources::TileUnderCursor,
|
||||
@@ -28,6 +28,7 @@ impl Plugin for TerraFormingTestPlugin {
|
||||
fn deform(
|
||||
mut commands: Commands,
|
||||
mouse: Res<ButtonInput<MouseButton>>,
|
||||
spatial_query: SpatialQuery,
|
||||
mut heightmap: ResMut<Map>,
|
||||
chunks: Res<PhosChunkRegistry>,
|
||||
tile_under_cursor: Res<TileUnderCursor>,
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
use crate::camera_system::components::PhosCamera;
|
||||
use crate::map_rendering::map_init::MapInitPlugin;
|
||||
use crate::map_rendering::render_distance_system::RenderDistancePlugin;
|
||||
use crate::utlis::editor_plugin::EditorPlugin;
|
||||
use crate::utlis::render_distance_system::RenderDistancePlugin;
|
||||
use crate::utlis::tile_selection_plugin::TileSelectionPlugin;
|
||||
use crate::{camera_system::camera_plugin::PhosCameraPlugin, utlis::debug_plugin::DebugPlugin};
|
||||
use avian3d::{math::*, prelude::*};
|
||||
use bevy::{
|
||||
pbr::{wireframe::WireframeConfig, CascadeShadowConfig},
|
||||
prelude::*,
|
||||
};
|
||||
use bevy_asset_loader::prelude::*;
|
||||
use bevy_rapier3d::dynamics::{Ccd, RigidBody, Velocity};
|
||||
use bevy_rapier3d::geometry::Collider;
|
||||
use bevy_rapier3d::plugin::{NoUserData, RapierPhysicsPlugin};
|
||||
use buildings::BuildingPugin;
|
||||
use iyes_perf_ui::prelude::*;
|
||||
use shared::sets::GameplaySet;
|
||||
@@ -61,7 +59,7 @@ impl Plugin for PhosGamePlugin {
|
||||
.add_plugins(PerfUiPlugin);
|
||||
|
||||
//Physics
|
||||
app.add_plugins(RapierPhysicsPlugin::<NoUserData>::default());
|
||||
app.add_plugins(PhysicsPlugins::default());
|
||||
// app.add_plugins(RapierDebugRenderPlugin::default());
|
||||
|
||||
app.insert_resource(WireframeConfig {
|
||||
@@ -148,10 +146,9 @@ fn spawn_sphere(
|
||||
transform: Transform::from_translation(cam_transform.translation),
|
||||
..default()
|
||||
},
|
||||
Collider::ball(0.3),
|
||||
Collider::sphere(0.3),
|
||||
RigidBody::Dynamic,
|
||||
Ccd::enabled(),
|
||||
Velocity::linear(cam_transform.forward() * 50.),
|
||||
LinearVelocity(cam_transform.forward() * 50.),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,14 +30,12 @@ impl PhosChunk {
|
||||
#[derive(Resource, Default)]
|
||||
pub struct PhosChunkRegistry {
|
||||
pub chunks: Vec<Entity>,
|
||||
pub waters: Vec<Entity>,
|
||||
}
|
||||
|
||||
impl PhosChunkRegistry {
|
||||
pub fn new(size: usize) -> Self {
|
||||
return Self {
|
||||
chunks: Vec::with_capacity(size),
|
||||
waters: Vec::with_capacity(size),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub struct BuildUiPlugin;
|
||||
|
||||
impl Plugin for BuildUiPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(PostStartup, setup);
|
||||
}
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands) {}
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
pub mod build_ui;
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
pub mod game;
|
||||
@@ -1,19 +1,16 @@
|
||||
use avian3d::prelude::*;
|
||||
#[cfg(feature = "tracing")]
|
||||
use bevy::log::*;
|
||||
use bevy::{
|
||||
asset::Assets,
|
||||
ecs::system::Res,
|
||||
math::{IVec2, UVec2, Vec3},
|
||||
math::{IVec2, Vec3},
|
||||
render::mesh::Mesh,
|
||||
};
|
||||
use bevy_rapier3d::geometry::{Collider, TriMeshFlags};
|
||||
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
|
||||
use world_generation::{
|
||||
biome_painter::BiomePainter,
|
||||
generators::{
|
||||
chunk_colliders::generate_chunk_collider,
|
||||
mesh_generator::{generate_chunk_mesh, generate_chunk_water_mesh},
|
||||
},
|
||||
generators::{chunk_colliders::generate_chunk_collider, mesh_generator::generate_chunk_mesh},
|
||||
hex_utils::offset_to_world,
|
||||
prelude::{Chunk, Map, MeshChunkData},
|
||||
tile_manager::TileAsset,
|
||||
@@ -47,27 +44,22 @@ pub fn paint_chunk(
|
||||
let tile_handle = mapper.unwrap().sample_tile(height);
|
||||
let tile = tiles.get(tile_handle).unwrap();
|
||||
chunk.textures[idx] = [tile.texture_id, tile.side_texture_id];
|
||||
chunk.overlay_textures[idx] = tile.side_overlay_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prepare_chunk_mesh(
|
||||
chunk: &MeshChunkData,
|
||||
sealevel: f32,
|
||||
chunk_offset: IVec2,
|
||||
chunk_index: usize,
|
||||
map_size: UVec2,
|
||||
) -> (Mesh, Mesh, (Vec<Vec3>, Vec<[u32; 3]>), Vec3, usize) {
|
||||
) -> (Mesh, (Vec<Vec3>, Vec<[u32; 3]>), Vec3, usize) {
|
||||
#[cfg(feature = "tracing")]
|
||||
let _gen_mesh = info_span!("Generate Chunk").entered();
|
||||
let chunk_mesh = generate_chunk_mesh(chunk);
|
||||
let water_mesh = generate_chunk_water_mesh(chunk, sealevel, map_size.x as usize, map_size.y as usize);
|
||||
let mesh = generate_chunk_mesh(chunk);
|
||||
let col_data = generate_chunk_collider(chunk);
|
||||
|
||||
return (
|
||||
chunk_mesh,
|
||||
water_mesh,
|
||||
mesh,
|
||||
col_data,
|
||||
offset_to_world(chunk_offset * Chunk::SIZE as i32, 0.),
|
||||
chunk_index,
|
||||
@@ -76,18 +68,15 @@ pub fn prepare_chunk_mesh(
|
||||
|
||||
pub fn prepare_chunk_mesh_with_collider(
|
||||
chunk: &MeshChunkData,
|
||||
sealevel: f32,
|
||||
chunk_offset: IVec2,
|
||||
chunk_index: usize,
|
||||
map_size: UVec2,
|
||||
) -> (Mesh, Mesh, Collider, Vec3, usize) {
|
||||
let (chunk_mesh, water_mesh, (col_verts, col_indicies), pos, index) =
|
||||
prepare_chunk_mesh(chunk, sealevel, chunk_offset, chunk_index, map_size);
|
||||
) -> (Mesh, Collider, Vec3, usize) {
|
||||
let (mesh, (col_verts, col_indicies), pos, index) = prepare_chunk_mesh(chunk, chunk_offset, chunk_index);
|
||||
let collider: Collider;
|
||||
{
|
||||
#[cfg(feature = "tracing")]
|
||||
let _collider_span = info_span!("Create Collider Trimesh").entered();
|
||||
collider = Collider::trimesh_with_flags(col_verts, col_indicies, TriMeshFlags::DELETE_DUPLICATE_TRIANGLES);
|
||||
collider = Collider::trimesh(col_verts, col_indicies);
|
||||
}
|
||||
return (chunk_mesh, water_mesh, collider, pos, index);
|
||||
return (mesh, collider, pos, index);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
use bevy::{gizmos::gizmos, prelude::*};
|
||||
use bevy::{prelude::*, window::PrimaryWindow};
|
||||
use bevy_inspector_egui::bevy_egui::{systems::InputEvents, EguiContexts};
|
||||
use bevy_inspector_egui::egui;
|
||||
use shared::resources::TileUnderCursor;
|
||||
use shared::states::GameplayState;
|
||||
use shared::{resources::TileUnderCursor, sets::GameplaySet};
|
||||
use shared::tags::MainCamera;
|
||||
use world_generation::{
|
||||
consts::{HEX_CORNERS, WATER_HEX_CORNERS},
|
||||
consts::HEX_CORNERS,
|
||||
hex_utils::{HexCoord, INNER_RADIUS},
|
||||
prelude::Map,
|
||||
states::GeneratorState,
|
||||
};
|
||||
|
||||
use crate::camera_system::components::{PhosCamera, PhosOrbitCamera};
|
||||
|
||||
pub struct DebugPlugin;
|
||||
|
||||
impl Plugin for DebugPlugin {
|
||||
@@ -29,7 +31,6 @@ impl Plugin for DebugPlugin {
|
||||
.run_if(in_state(DebugState::Verbose)),
|
||||
);
|
||||
|
||||
app.add_systems(Update, camera_debug.in_set(GameplaySet));
|
||||
app.add_systems(Update, regenerate_map.run_if(in_state(GeneratorState::Idle)));
|
||||
|
||||
app.insert_resource(Shape(Polyline3d::new([
|
||||
@@ -74,32 +75,25 @@ fn show_tile_heights(map: Res<Map>, mut gizmos: Gizmos, shape: Res<Shape>, tile_
|
||||
Quat::IDENTITY,
|
||||
Color::WHITE,
|
||||
);
|
||||
let nbors = map.get_neighbors(&contact.tile);
|
||||
let contact_tile_pos = contact.tile.to_world(map.sample_height(&contact.tile));
|
||||
|
||||
// for i in 0..6 {
|
||||
// if let Some(s) = nbors[i] {
|
||||
// let coord = contact.tile.get_neighbor(i);
|
||||
// let p = coord.to_world(s);
|
||||
// gizmos.arrow(p, p + Vec3::Y * (i as f32 + 1.0), Color::WHITE);
|
||||
// }
|
||||
|
||||
// let p = HEX_CORNERS[i] + contact_tile_pos;
|
||||
// gizmos.arrow(p, p + Vec3::Y * (i as f32 + 1.0), LinearRgba::rgb(1.0, 0.0, 0.5));
|
||||
// }
|
||||
|
||||
gizmos.line(contact.point, contact.point + Vec3::X, LinearRgba::RED);
|
||||
gizmos.line(contact.point, contact.point + Vec3::Y, LinearRgba::GREEN);
|
||||
gizmos.line(contact.point, contact.point + Vec3::Z, LinearRgba::BLUE);
|
||||
|
||||
// show_water_corners(contact.tile.to_world(height + 1.0), &mut gizmos);
|
||||
//gizmos.sphere(contact_point, Quat::IDENTITY, 0.1, LinearRgba::rgb(1., 0., 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
fn show_water_corners(pos: Vec3, gizmos: &mut Gizmos) {
|
||||
for i in 0..WATER_HEX_CORNERS.len() {
|
||||
let p = pos + WATER_HEX_CORNERS[i];
|
||||
let p2 = pos + WATER_HEX_CORNERS[(i + 1) % WATER_HEX_CORNERS.len()];
|
||||
|
||||
gizmos.line(p, p2, LinearRgba::RED);
|
||||
}
|
||||
}
|
||||
|
||||
fn camera_debug(mut cam_query: Query<(&PhosCamera, &PhosOrbitCamera)>, mut gizmos: Gizmos) {
|
||||
let (config, orbit) = cam_query.single();
|
||||
|
||||
gizmos.sphere(orbit.target, Quat::IDENTITY, 0.3, LinearRgba::RED);
|
||||
let cam_proxy = orbit.target - (orbit.forward * 10.0);
|
||||
gizmos.ray(orbit.target, orbit.forward * 10.0, LinearRgba::rgb(1.0, 0.0, 1.0));
|
||||
|
||||
gizmos.circle(cam_proxy, Dir3::Y, 0.3, LinearRgba::rgb(1.0, 1.0, 0.0));
|
||||
}
|
||||
|
||||
fn verbose_data() {}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod chunk_utils;
|
||||
pub mod render_distance_system;
|
||||
pub mod debug_plugin;
|
||||
pub mod editor_plugin;
|
||||
pub mod tile_selection_plugin;
|
||||
|
||||
@@ -9,6 +9,9 @@ impl Plugin for RenderDistancePlugin {
|
||||
app.register_type::<RenderDistanceSettings>();
|
||||
app.add_systems(PostUpdate, render_distance_system)
|
||||
.insert_resource(RenderDistanceSettings::default());
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
app.insert_resource(RenderDistanceSettings::new(f32::MAX));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use avian3d::prelude::{SpatialQuery, SpatialQueryFilter};
|
||||
use bevy::{prelude::*, window::PrimaryWindow};
|
||||
use bevy_rapier3d::{plugin::RapierContext, prelude::QueryFilter};
|
||||
use shared::{
|
||||
resources::{TileContact, TileUnderCursor},
|
||||
tags::MainCamera,
|
||||
@@ -20,16 +20,11 @@ impl Plugin for TileSelectionPlugin {
|
||||
fn update_tile_under_cursor(
|
||||
cam_query: Query<(&GlobalTransform, &Camera), With<MainCamera>>,
|
||||
window: Query<&Window, With<PrimaryWindow>>,
|
||||
rapier_context: Res<RapierContext>,
|
||||
spatial_query: SpatialQuery,
|
||||
map: Res<Map>,
|
||||
mut tile_under_cursor: ResMut<TileUnderCursor>,
|
||||
) {
|
||||
let win_r = window.get_single();
|
||||
if win_r.is_err() {
|
||||
return;
|
||||
}
|
||||
let win = win_r.unwrap();
|
||||
|
||||
let win = window.single();
|
||||
let (cam_transform, camera) = cam_query.single();
|
||||
let Some(cursor_pos) = win.cursor_position() else {
|
||||
return;
|
||||
@@ -39,15 +34,16 @@ fn update_tile_under_cursor(
|
||||
return;
|
||||
};
|
||||
|
||||
let collision = rapier_context.cast_ray(
|
||||
let collision = spatial_query.cast_ray(
|
||||
cam_ray.origin,
|
||||
cam_ray.direction.into(),
|
||||
500.,
|
||||
true,
|
||||
QueryFilter::only_fixed(),
|
||||
SpatialQueryFilter::default(),
|
||||
);
|
||||
|
||||
if let Some((_e, dist)) = collision {
|
||||
if let Some(data) = collision {
|
||||
let dist = data.time_of_impact;
|
||||
let contact_point = cam_ray.get_point(dist);
|
||||
let contact_coord = HexCoord::from_world_pos(contact_point);
|
||||
//todo: handle correct tile detection when contacting a tile from the side
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
[package]
|
||||
name = "resources"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.14.2"
|
||||
world_generation = { path = "../../engine/world_generation" }
|
||||
shared = { path = "../shared" }
|
||||
serde = { version = "1.0.204", features = ["derive"] }
|
||||
asset_loader = { path = "../../engine/asset_loader" }
|
||||
serde_json = "1.0.120"
|
||||
ron = "0.8.1"
|
||||
bevy_asset_loader = { version = "0.21.0", features = [
|
||||
"standard_dynamic_assets",
|
||||
"3d",
|
||||
] }
|
||||
|
||||
[features]
|
||||
tracing = []
|
||||
@@ -1,16 +0,0 @@
|
||||
pub mod resource_asset;
|
||||
|
||||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let result = add(2, 2);
|
||||
assert_eq!(result, 4);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
use asset_loader::create_asset_loader;
|
||||
use bevy::prelude::*;
|
||||
use bevy_asset_loader::asset_collection::AssetCollection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use shared::Tier;
|
||||
|
||||
#[derive(Asset, TypePath, Debug, Serialize, Deserialize)]
|
||||
pub struct ResourceAsset {
|
||||
pub identifier: String,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub sprite_id: usize,
|
||||
pub tier: Tier,
|
||||
}
|
||||
|
||||
create_asset_loader!(
|
||||
ResourceAssetPlugin,
|
||||
ResourceAssetLoader,
|
||||
ResourceAsset,
|
||||
&["res", "res.ron"],
|
||||
;?
|
||||
);
|
||||
|
||||
#[derive(Resource, AssetCollection)]
|
||||
pub struct ResourceDatabase {
|
||||
#[asset(key = "resources", collection(typed))]
|
||||
pub units: Vec<Handle<ResourceAsset>>,
|
||||
}
|
||||
|
||||
impl ResourceDatabase {
|
||||
pub fn create_lookup(&self, assets: &Assets<ResourceAsset>) -> ResourceLookup {
|
||||
let mut identifiers = Vec::with_capacity(self.units.len());
|
||||
for handle in &self.units {
|
||||
if let Some(asset) = assets.get(handle.id()) {
|
||||
identifiers.push(asset.identifier.clone());
|
||||
}
|
||||
}
|
||||
return ResourceLookup {
|
||||
handles: self.units.clone(),
|
||||
identifiers,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct ResourceLookup {
|
||||
pub handles: Vec<Handle<ResourceAsset>>,
|
||||
pub identifiers: Vec<String>,
|
||||
}
|
||||
@@ -6,7 +6,7 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.14.2"
|
||||
bevy = "0.14.0"
|
||||
serde = { version = "1.0.204", features = ["derive"] }
|
||||
world_generation = { path = "../../engine/world_generation" }
|
||||
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub mod building;
|
||||
pub mod despawn;
|
||||
pub mod events;
|
||||
pub mod identifiers;
|
||||
pub mod resources;
|
||||
pub mod sets;
|
||||
pub mod states;
|
||||
pub mod tags;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum Tier {
|
||||
Zero,
|
||||
One,
|
||||
Two,
|
||||
Three,
|
||||
Superior,
|
||||
}
|
||||
pub mod events;
|
||||
pub mod sets;
|
||||
pub mod resources;
|
||||
|
||||
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.14.2"
|
||||
bevy = "0.14.0"
|
||||
world_generation = { path = "../../engine/world_generation" }
|
||||
shared = { path = "../shared" }
|
||||
bevy_rapier3d = "0.27.0"
|
||||
@@ -17,8 +17,6 @@ bevy_asset_loader = { version = "0.21.0", features = [
|
||||
"3d",
|
||||
] }
|
||||
quadtree_rs = "0.1.3"
|
||||
pathfinding = "4.11.0"
|
||||
ordered-float = "4.3.0"
|
||||
|
||||
[features]
|
||||
tracing = ["bevy/trace_tracy"]
|
||||
tracing = []
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use bevy::{ecs::world::CommandQueue, prelude::*, tasks::Task};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use world_generation::hex_utils::HexCoord;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Unit;
|
||||
@@ -20,12 +19,10 @@ pub enum UnitDomain {
|
||||
}
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Target(pub HexCoord);
|
||||
pub struct Target(pub Vec3);
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct Path(pub Vec<Vec3>, pub usize);
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
pub struct PathTask(pub Task<Option<CommandQueue>>);
|
||||
#[derive(Component, Debug)]
|
||||
pub struct PathTaskPending(pub usize);
|
||||
pub struct PathTask(pub Task<CommandQueue>);
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
|
||||
pub mod assets;
|
||||
pub mod components;
|
||||
pub mod nav_data;
|
||||
pub mod resources;
|
||||
#[cfg(debug_assertions)]
|
||||
pub mod units_debug_plugin;
|
||||
pub mod units_plugin;
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
use bevy::prelude::*;
|
||||
use ordered_float::OrderedFloat;
|
||||
use world_generation::{hex_utils::HexCoord, prelude::Map};
|
||||
|
||||
#[derive(Clone, Resource)]
|
||||
pub struct NavData {
|
||||
pub tiles: Vec<NavTile>,
|
||||
pub map_height: usize,
|
||||
pub map_width: usize,
|
||||
}
|
||||
|
||||
impl NavData {
|
||||
pub fn get_neighbors(&self, coord: &HexCoord) -> Vec<(HexCoord, OrderedFloat<f32>)> {
|
||||
let mut neighbors = Vec::with_capacity(6);
|
||||
let cur_height = self.get_height(coord);
|
||||
for i in 0..6 {
|
||||
let n = coord.get_neighbor(i);
|
||||
if !self.is_in_bounds(&n) {
|
||||
continue;
|
||||
}
|
||||
let n_height = self.get_height(&n);
|
||||
neighbors.push((n, OrderedFloat((cur_height - n_height).abs().powi(2))));
|
||||
}
|
||||
return neighbors;
|
||||
}
|
||||
pub fn get(&self, coord: &HexCoord) -> &NavTile {
|
||||
return &self.tiles[coord.to_index(self.map_width)];
|
||||
}
|
||||
|
||||
pub fn get_height(&self, coord: &HexCoord) -> f32 {
|
||||
return self.tiles[coord.to_index(self.map_width)].height;
|
||||
}
|
||||
|
||||
pub fn is_in_bounds(&self, pos: &HexCoord) -> bool {
|
||||
return pos.is_in_bounds(self.map_height, self.map_width);
|
||||
}
|
||||
|
||||
pub fn build(map: &Map) -> NavData {
|
||||
#[cfg(feature = "tracing")]
|
||||
let _path_span = info_span!("Build Nav Data").entered();
|
||||
let mut tiles = Vec::with_capacity(map.get_tile_count());
|
||||
let h = map.get_tile_height();
|
||||
let w = map.get_tile_width();
|
||||
for y in 0..h {
|
||||
for x in 0..w {
|
||||
let coord = HexCoord::from_grid_pos(x, y);
|
||||
let height = map.sample_height(&coord);
|
||||
let tile = NavTile {
|
||||
coord,
|
||||
height,
|
||||
move_cost: 1.0,
|
||||
};
|
||||
tiles.push(tile);
|
||||
}
|
||||
}
|
||||
|
||||
return NavData {
|
||||
tiles,
|
||||
map_width: w,
|
||||
map_height: h,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn update(&mut self, map: &Map) {
|
||||
#[cfg(feature = "tracing")]
|
||||
let _path_span = info_span!("Update Nav Data").entered();
|
||||
let h = map.get_tile_height();
|
||||
let w = map.get_tile_width();
|
||||
for y in 0..h {
|
||||
for x in 0..w {
|
||||
let coord = HexCoord::from_grid_pos(x, y);
|
||||
let height = map.sample_height(&coord);
|
||||
let tile = NavTile {
|
||||
coord,
|
||||
height,
|
||||
move_cost: 1.0,
|
||||
};
|
||||
self.tiles[y * w + x] = tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn update_tile(&mut self, coord: &HexCoord, height: f32, move_cost: f32) {
|
||||
let tile = &mut self.tiles[coord.to_index(self.map_width)];
|
||||
tile.move_cost = move_cost;
|
||||
tile.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NavTile {
|
||||
pub height: f32,
|
||||
pub move_cost: f32,
|
||||
pub coord: HexCoord,
|
||||
}
|
||||
|
||||
impl NavTile {
|
||||
pub fn calculate_heuristic(&self, to: &HexCoord) -> OrderedFloat<f32> {
|
||||
return (self.coord.distance(to) as f32).into();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(Resource, Debug, Default)]
|
||||
pub struct PathBatchId(pub usize);
|
||||
@@ -1,7 +1,10 @@
|
||||
use std::f32::consts::E;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use shared::{resources::TileUnderCursor, sets::GameplaySet, states::AssetLoadState};
|
||||
use world_generation::{heightmap, prelude::Map};
|
||||
|
||||
use crate::components::{LandUnit, Path, Target, Unit};
|
||||
use crate::components::{LandUnit, Target, Unit};
|
||||
|
||||
pub struct UnitsDebugPlugin;
|
||||
|
||||
@@ -10,7 +13,6 @@ impl Plugin for UnitsDebugPlugin {
|
||||
app.add_systems(Update, init.run_if(in_state(AssetLoadState::Loading)));
|
||||
|
||||
app.add_systems(Update, (spawn_test_unit, set_unit_target).in_set(GameplaySet));
|
||||
app.add_systems(FixedUpdate, (visualize_paths).in_set(GameplaySet));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,25 +60,7 @@ fn set_unit_target(
|
||||
for e in units.iter() {
|
||||
info!("Setting Target");
|
||||
let mut e = commands.entity(e);
|
||||
e.insert(Target(contact.tile));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visualize_paths(units: Query<&Path, With<Unit>>, mut gizmos: Gizmos) {
|
||||
for path in units.iter() {
|
||||
if path.1 > path.0.len() {
|
||||
continue;
|
||||
}
|
||||
for node in 1..path.0.len() {
|
||||
let from = path.0[node];
|
||||
let to = path.0[node - 1];
|
||||
let color = if node > path.1 {
|
||||
LinearRgba::rgb(1.0, 0.5, 0.0)
|
||||
} else {
|
||||
LinearRgba::rgb(1.0, 0.5, 1.5)
|
||||
};
|
||||
gizmos.line(from + Vec3::Y * 0.1, to + Vec3::Y * 0.1, color);
|
||||
e.insert(Target(contact.surface));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,54 +1,34 @@
|
||||
use std::collections::HashMap;
|
||||
use bevy::{
|
||||
ecs::world::CommandQueue, prelude::*, tasks::AsyncComputeTaskPool, transform::commands, utils::futures,
|
||||
window::PrimaryWindow,
|
||||
};
|
||||
use bevy_asset_loader::loading_state::{
|
||||
config::{ConfigureLoadingState, LoadingStateConfig},
|
||||
LoadingStateAppExt,
|
||||
};
|
||||
use shared::{resources::TileUnderCursor, sets::GameplaySet, states::AssetLoadState};
|
||||
use world_generation::{hex_utils::HexCoord, prelude::Map};
|
||||
|
||||
use bevy::{ecs::world::CommandQueue, prelude::*, tasks::AsyncComputeTaskPool, utils::futures};
|
||||
use pathfinding::prelude::astar;
|
||||
use shared::{events::TileModifiedEvent, resources::TileUnderCursor, sets::GameplaySet};
|
||||
use world_generation::{hex_utils::HexCoord, prelude::Map, states::GeneratorState};
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
use crate::units_debug_plugin::UnitsDebugPlugin;
|
||||
use crate::{
|
||||
assets::unit_asset::UnitAssetPlugin,
|
||||
components::{Path, PathTask, PathTaskPending, Target, Unit},
|
||||
nav_data::NavData,
|
||||
resources::PathBatchId,
|
||||
assets::{unit_asset::UnitAssetPlugin, unit_database::UnitDatabase},
|
||||
components::{Path, PathTask, Target, Unit},
|
||||
units_debug_plugin::UnitsDebugPlugin,
|
||||
};
|
||||
|
||||
pub struct UnitsPlugin;
|
||||
|
||||
impl Plugin for UnitsPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<PathBatchId>();
|
||||
app.add_plugins(UnitAssetPlugin);
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
app.add_plugins(UnitsDebugPlugin);
|
||||
|
||||
// app.configure_loading_state(LoadingStateConfig::new(AssetLoadState::Loading).load_collection::<UnitDatabase>());
|
||||
app.add_systems(PostUpdate, build_navdata.run_if(in_state(GeneratorState::SpawnMap)));
|
||||
|
||||
app.add_systems(Update, units_control.in_set(GameplaySet));
|
||||
app.add_systems(Update, (move_unit, update_navdata).in_set(GameplaySet));
|
||||
app.add_systems(
|
||||
FixedPreUpdate,
|
||||
(dispatch_path_requests, resolve_path_task).in_set(GameplaySet),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn build_navdata(mut commands: Commands, map: Res<Map>) {
|
||||
let nav_data = NavData::build(&map);
|
||||
commands.insert_resource(nav_data);
|
||||
}
|
||||
|
||||
fn update_navdata(mut tile_updates: EventReader<TileModifiedEvent>, mut nav_data: ResMut<NavData>) {
|
||||
for event in tile_updates.read() {
|
||||
match event {
|
||||
TileModifiedEvent::HeightChanged(coord, new_height) => {
|
||||
nav_data.update_tile(coord, *new_height, 1.0);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
app.add_systems(Update, move_unit.in_set(GameplaySet));
|
||||
app.add_systems(FixedPreUpdate, (calculate_path, resolve_path_task).in_set(GameplaySet));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,155 +60,35 @@ fn move_unit(
|
||||
}
|
||||
}
|
||||
|
||||
fn dispatch_path_requests(
|
||||
units: Query<(&Transform, &Target, Entity), With<Unit>>,
|
||||
fn calculate_path(
|
||||
units: Query<(&Transform, &Target, Entity), (With<Unit>, Without<PathTask>)>,
|
||||
map: Res<Map>,
|
||||
nav_data: Res<NavData>,
|
||||
mut batch_id: ResMut<PathBatchId>,
|
||||
mut commands: Commands,
|
||||
) {
|
||||
if units.is_empty() {
|
||||
return;
|
||||
}
|
||||
let mut groups: HashMap<HexCoord, Vec<PathRequest>> = HashMap::new();
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
let _group_span = info_span!("Grouping").entered();
|
||||
for (transform, target, entity) in units.iter() {
|
||||
let req = PathRequest {
|
||||
entity,
|
||||
from: HexCoord::from_world_pos(transform.translation),
|
||||
};
|
||||
if let Some(group) = groups.get_mut(&target.0) {
|
||||
group.push(req);
|
||||
} else {
|
||||
groups.insert(target.0, vec![req]);
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "tracing")]
|
||||
drop(_group_span);
|
||||
|
||||
let pool = AsyncComputeTaskPool::get();
|
||||
for (target, units) in groups {
|
||||
let id = batch_id.0;
|
||||
batch_id.0 += 1;
|
||||
for (transform, target, entity) in units.iter() {
|
||||
let from = transform.translation;
|
||||
let to = target.0;
|
||||
|
||||
for req in &units {
|
||||
commands
|
||||
.entity(req.entity)
|
||||
.insert(PathTaskPending(id))
|
||||
.remove::<Target>();
|
||||
}
|
||||
|
||||
let destinations = get_end_points(&target, units.len(), &map);
|
||||
let req = BatchPathRequest::new(units, destinations);
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
let _clone_span = info_span!("Nav Data Clone").entered();
|
||||
let local_nav_data = nav_data.clone();
|
||||
#[cfg(feature = "tracing")]
|
||||
drop(_clone_span);
|
||||
|
||||
let batch_task = pool.spawn(async move {
|
||||
let mut i = 0;
|
||||
let task = pool.spawn(async move {
|
||||
let mut queue = CommandQueue::default();
|
||||
for entitiy_req in req.entities {
|
||||
let dst = req.destination[i];
|
||||
i += 1;
|
||||
#[cfg(feature = "tracing")]
|
||||
let _path_span = info_span!("Path Finding").entered();
|
||||
if let Some(path) = calculate_path(&entitiy_req.from, &dst, &local_nav_data) {
|
||||
queue.push(move |world: &mut World| {
|
||||
let mut unit_e = world.entity_mut(entitiy_req.entity);
|
||||
|
||||
if let Some(pending_task) = unit_e.get::<PathTaskPending>() {
|
||||
if pending_task.0 == id {
|
||||
unit_e.insert(path);
|
||||
unit_e.remove::<PathTaskPending>();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if queue.is_empty() {
|
||||
return None;
|
||||
}
|
||||
return Some(queue);
|
||||
queue.push(move |world: &mut World| {
|
||||
//todo: calculate path
|
||||
world.entity_mut(entity).insert(Path(vec![from, to], 0));
|
||||
});
|
||||
return queue;
|
||||
});
|
||||
commands.spawn(PathTask(batch_task));
|
||||
|
||||
commands.entity(entity).insert(PathTask(task)).remove::<Target>();
|
||||
}
|
||||
}
|
||||
|
||||
fn get_end_points(coord: &HexCoord, count: usize, map: &Map) -> Vec<HexCoord> {
|
||||
let mut result = Vec::with_capacity(count);
|
||||
if count == 1 {
|
||||
return vec![*coord];
|
||||
}
|
||||
result.push(*coord);
|
||||
let mut r = 1;
|
||||
while result.len() < count {
|
||||
let tiles = HexCoord::select_ring(coord, r);
|
||||
let needed = count - result.len();
|
||||
if needed >= tiles.len() {
|
||||
for t in tiles {
|
||||
if map.is_in_bounds(&t) {
|
||||
result.push(t);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for i in 0..needed {
|
||||
let t = tiles[i];
|
||||
if map.is_in_bounds(&t) {
|
||||
result.push(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
r += 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
fn resolve_path_task(mut tasks: Query<(&mut PathTask, Entity)>, mut commands: Commands) {
|
||||
fn resolve_path_task(mut tasks: Query<(&mut PathTask, Entity), With<Unit>>, mut commands: Commands) {
|
||||
for (mut task, entity) in tasks.iter_mut() {
|
||||
if let Some(c) = futures::check_ready(&mut task.0) {
|
||||
if let Some(mut queue) = c {
|
||||
commands.append(&mut queue);
|
||||
}
|
||||
commands.entity(entity).despawn();
|
||||
if let Some(mut c) = futures::check_ready(&mut task.0) {
|
||||
commands.append(&mut c);
|
||||
commands.entity(entity).remove::<PathTask>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn calculate_path(from: &HexCoord, to: &HexCoord, nav: &NavData) -> Option<Path> {
|
||||
let path = astar(
|
||||
from,
|
||||
|n| nav.get_neighbors(n),
|
||||
|n| nav.get(n).calculate_heuristic(to),
|
||||
|n| n == to,
|
||||
);
|
||||
if let Some((nodes, _cost)) = path {
|
||||
let result: Vec<_> = nodes.iter().map(|f| f.to_world(nav.get_height(f))).collect();
|
||||
return Some(Path(result, 1));
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
struct PathRequest {
|
||||
pub entity: Entity,
|
||||
pub from: HexCoord,
|
||||
}
|
||||
|
||||
struct BatchPathRequest {
|
||||
pub entities: Vec<PathRequest>,
|
||||
pub destination: Vec<HexCoord>,
|
||||
}
|
||||
|
||||
impl BatchPathRequest {
|
||||
pub fn new(entities: Vec<PathRequest>, dst: Vec<HexCoord>) -> Self {
|
||||
return Self {
|
||||
destination: dst,
|
||||
entities,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user