20 Commits

Author SHA1 Message Date
a8763ae98a Update mesh_generator.rs 2024-04-27 19:19:41 -04:00
a65848fac8 biome mapping 2024-04-24 21:18:47 -04:00
54d0f762d2 fixed texture index packing 2024-04-24 20:25:39 -04:00
985523a1cb Update assets 2024-04-24 20:08:43 -04:00
b365a9d835 Update assets 2024-04-24 19:38:27 -04:00
1ce46df23c Update assets 2024-04-23 21:40:02 -04:00
7c770af89c resource load states
use biome painter
2024-04-23 21:39:35 -04:00
d3b5893294 temp(WIP) and moisture generation 2024-04-21 14:55:53 -04:00
377707e689 Updated Assets 2024-04-21 00:24:41 -04:00
f302636a98 use tile mapper to render chunks 2024-04-21 00:23:17 -04:00
d31f1501eb Merge branch 'master' of https://github.com/Amatsugu/phos-neo 2024-04-19 23:05:26 -04:00
d40c35e891 Resource Loading, Tile Mapper, and Biome Painter implementation 2024-04-19 23:05:07 -04:00
2acbc3039f Resource Loading, Tile Mapper, and Biome Painter implementation 2024-04-19 23:04:29 -04:00
b1dc3b9aef tile mapper asset 2024-04-18 22:19:26 -04:00
df76dc7169 updated asset loader
prep for adding biomes
2024-04-18 22:09:50 -04:00
9fb305a887 add submodule 2024-04-18 14:15:35 -04:00
e9dca330c0 move assets to submodule 2024-04-18 14:15:14 -04:00
b2b95937cc tile manager 2024-04-17 23:01:57 -04:00
70a5d64d16 asset loader
added rapier
2024-04-14 22:40:24 -04:00
27193adf15 tile manager 2024-04-09 21:06:45 -04:00
30 changed files with 869 additions and 313 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "game/main/assets"]
path = game/main/assets
url = git@github.com:Amatsugu/phos-assets.git

4
.vscode/launch.json vendored
View File

@@ -12,8 +12,8 @@
"name": "Debug",
"program": "${workspaceRoot}/target/debug/phos.exe",
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": "Build",
"cwd": "${workspaceRoot}/target/debug",
"preLaunchTask": "Build"
}
]
}

View File

@@ -1,3 +1,6 @@
{
"cmake.configureOnOpen": false
"cmake.configureOnOpen": false,
"rust-analyzer.linkedProjects": [
"Cargo.toml",
]
}

6
.vscode/tasks.json vendored
View File

@@ -3,10 +3,8 @@
"tasks": [
{
"type": "cargo",
"command": "",
"args": [
"build"
],
"command": "build",
"args": [],
"problemMatcher": [
"$rustc"
],

419
Cargo.lock generated
View File

@@ -224,6 +224,15 @@ dependencies = [
"libloading 0.7.4",
]
[[package]]
name = "asset_loader"
version = "0.1.0"
dependencies = [
"bevy",
"serde",
"serde_json",
]
[[package]]
name = "async-broadcast"
version = "0.5.1"
@@ -309,9 +318,9 @@ checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
[[package]]
name = "bevy"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea370412c322af887c9115442d8f2ec991b652f163a1d8920ecaf08cae63f2bc"
checksum = "65b9eadaacf8fe971331bc3f250f35c18bc9dace3f96b483062f38ac07e3a1b4"
dependencies = [
"bevy_internal",
]
@@ -358,9 +367,9 @@ dependencies = [
[[package]]
name = "bevy_a11y"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6192db480a04d4a0ad5d89a2fbd78ccca5ce902829a49ec2d1dbc213222ed8b1"
checksum = "cd8ef2795f7f5c816a4eda04834083eb5a92e8fef603bc21d2091c6e3b63621a"
dependencies = [
"accesskit",
"bevy_app",
@@ -370,9 +379,9 @@ dependencies = [
[[package]]
name = "bevy_animation"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef3bbaf9233c428d8dd4b66a41b5381e41c67da860d9dc2118a8e6610ec874c"
checksum = "e553d68bc937586010ed2194ac66b751bc6238cf622b3ed5a86f4e1581e94509"
dependencies = [
"bevy_app",
"bevy_asset",
@@ -389,9 +398,9 @@ dependencies = [
[[package]]
name = "bevy_app"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b508824497f3a3a2fab8398dc3944a4d4adddcc30ee25cd6d45b0a57336549ce"
checksum = "ab348a32e46d21c5d61794294a92d415a770d26c7ba8951830b127b40b53ccc4"
dependencies = [
"bevy_derive",
"bevy_ecs",
@@ -405,9 +414,9 @@ dependencies = [
[[package]]
name = "bevy_asset"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccf224b57fb65e1cde921afe0b343c2d595531dbf882c41abad01bbc665a05c4"
checksum = "50028e0d4f28a9f6aab48f61b688ba2793141188f88cdc9aa6c2bca2cc02ad35"
dependencies = [
"async-broadcast",
"async-fs",
@@ -437,9 +446,9 @@ dependencies = [
[[package]]
name = "bevy_asset_macros"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "684c855651e7734740b76ada0e7daed116c46d393f9031cc45c4fe9ad5829548"
checksum = "6617475908368418d815360148fdbb82f879dc255a70d2d7baa3766f0cd4bfd7"
dependencies = [
"bevy_macro_utils",
"proc-macro2",
@@ -449,9 +458,9 @@ dependencies = [
[[package]]
name = "bevy_audio"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0af1796b7e56c2f49de5be72fb2aadb8f9310d6173d70040fd2eff1c7cb29009"
checksum = "b0f12495e230cd5cf59c6051cdd820c97d7fe4f0597d4d9c3240c62e9c65b485"
dependencies = [
"bevy_app",
"bevy_asset",
@@ -467,9 +476,9 @@ dependencies = [
[[package]]
name = "bevy_core"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1a8f4722fb978d308b6311f3dd61f6885165055ad05ce3dfc1b2fd001bb017e"
checksum = "12b0042f241ba7cd61487aadd8addfb56f7eeb662d713ac1577026704508fc6c"
dependencies = [
"bevy_app",
"bevy_ecs",
@@ -482,9 +491,9 @@ dependencies = [
[[package]]
name = "bevy_core_pipeline"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "568659c43c8f1805f434b5fc0f8e700c263391403f899312bb0e4bc8d8b9ca70"
checksum = "48b7a471cb8ba665f12f7a167faa5566c11386f5bfc77d2e10bfde22b179f7b3"
dependencies = [
"bevy_app",
"bevy_asset",
@@ -504,9 +513,9 @@ dependencies = [
[[package]]
name = "bevy_derive"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7de77523d154e220a740e568a89f52fac7de481374bdecbbbeb283a37580ba34"
checksum = "f0e01f8343f391e2d6a63b368b82fb5b252ed43c8713fc87f9a8f2d59407dd00"
dependencies = [
"bevy_macro_utils",
"quote",
@@ -515,9 +524,9 @@ dependencies = [
[[package]]
name = "bevy_diagnostic"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b5b031eeafc17bed997313ca15c8e4ed8b97fe2e9ef48e980833e4bf5cfa0e7"
checksum = "e1401cdccec7e49378d013dfb0ff62c251f85b3be19dcdf04cfd827f793d1ee9"
dependencies = [
"bevy_app",
"bevy_core",
@@ -531,9 +540,9 @@ dependencies = [
[[package]]
name = "bevy_ecs"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a027175613f630a51273c0f8ae909dd54ea3ce72eb573f456056553f79918ac"
checksum = "98e612a8e7962ead849e370f3a7e972b88df879ced05cd9dad6a0286d14650cf"
dependencies = [
"async-channel",
"bevy_ecs_macros",
@@ -551,9 +560,9 @@ dependencies = [
[[package]]
name = "bevy_ecs_macros"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55dbbb6300f08cef5983497970db8545d3cbda6ee4f410a6c6742b7b6bbfd3af"
checksum = "807b5106c3410e58f4f523b55ea3c071e2a09e31e9510f3c22021c6a04732b5b"
dependencies = [
"bevy_macro_utils",
"proc-macro2",
@@ -577,9 +586,9 @@ dependencies = [
[[package]]
name = "bevy_encase_derive"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df72ac1273fcdb8105736c42815442ae1291f1f577e34cb7e9d18f732103e2f0"
checksum = "887087a5e522d9f20733a84dd7e6e9ca04cd8fdfac659220ed87d675eebc83a7"
dependencies = [
"bevy_macro_utils",
"encase_derive_impl",
@@ -587,9 +596,9 @@ dependencies = [
[[package]]
name = "bevy_gilrs"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02146d8a92ac322717185005a17b488e74b2ec08ca3f9eb8a7cadb7f0486cb70"
checksum = "7d133c65ab756f130c65cf00f37dc293fb9a9336c891802baf006c63e300d0e2"
dependencies = [
"bevy_app",
"bevy_ecs",
@@ -603,9 +612,9 @@ dependencies = [
[[package]]
name = "bevy_gizmos"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66e9965860d505e2ea4144850904cefd8b528f59477061df8563194dc954ad58"
checksum = "054df3550a9d423a961de65b459946ff23304f97f25af8a62c23f4259db8506d"
dependencies = [
"bevy_app",
"bevy_asset",
@@ -625,9 +634,9 @@ dependencies = [
[[package]]
name = "bevy_gizmos_macros"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e689be764256a5a0d1f01c5f1dbaa3439e98a1338bf88b496db184d28e00c9"
checksum = "abdcaf74d8cd34aa5c3293527e7a012826840886ad3496c1b963ed8b66b1619f"
dependencies = [
"bevy_macro_utils",
"proc-macro2",
@@ -637,9 +646,9 @@ dependencies = [
[[package]]
name = "bevy_gltf"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d0cd8fd1c1ce3a57ca96eaee05f406ad65865efd02606e5f288b5f7767d8c6f"
checksum = "21ecf404295055deb7fe037495891bc135ca10d46bc5b6c55f9ab7b7ebc61d31"
dependencies = [
"base64",
"bevy_animation",
@@ -667,9 +676,9 @@ dependencies = [
[[package]]
name = "bevy_hierarchy"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b2999d1e5bb877b475c9b2d17643d5fb47fc4cc49ea48ba3ab5a6b00ed850a6"
checksum = "bbb3dfad24866a6713dafa3065a91c5cf5e355f6e1b191c25d704ae54185246c"
dependencies = [
"bevy_app",
"bevy_core",
@@ -681,9 +690,9 @@ dependencies = [
[[package]]
name = "bevy_input"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c22481e4290e2eca68b0c1f5f0a826f185d8f5e40e05c86bb6044dcfe3a04b3"
checksum = "47f2b2b3df168c6ef661d25e09abf5bd4fecaacd400f27e5db650df1c3fa3a3b"
dependencies = [
"bevy_app",
"bevy_ecs",
@@ -696,9 +705,9 @@ dependencies = [
[[package]]
name = "bevy_internal"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ac9275cc7f4bce41dff1e62b853933e242f9e5c076d89f06156cf743097d6a0"
checksum = "f58ec0ce77603df9474cde61f429126bfe06eb79094440e9141afb4217751c79"
dependencies = [
"bevy_a11y",
"bevy_animation",
@@ -735,9 +744,9 @@ dependencies = [
[[package]]
name = "bevy_log"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20c7b4e2443654d68b6f8c54e5f1ce3a16c8a9af10f4832390dcae36c1323307"
checksum = "a5eea6c527fd828b7fef8d0f518167f27f405b904a16f227b644687d3f46a809"
dependencies = [
"android_log-sys",
"bevy_app",
@@ -751,9 +760,9 @@ dependencies = [
[[package]]
name = "bevy_macro_utils"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bbbf88fc577a21ee9994feed2253ee9838b63fb976783b7a549edfbe07c6764"
checksum = "eb270c98a96243b29465139ed10bda2f675d00a11904f6588a5f7fc4774119c7"
dependencies = [
"proc-macro2",
"quote",
@@ -764,9 +773,9 @@ dependencies = [
[[package]]
name = "bevy_math"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d30721f36a0b5f9ad39deb140c50b85cbbaefebab8d10bd20d9de1c9572f968"
checksum = "f06daa26ffb82d90ba772256c0ba286f6c305c392f6976c9822717974805837c"
dependencies = [
"glam",
"serde",
@@ -774,18 +783,18 @@ dependencies = [
[[package]]
name = "bevy_mikktspace"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc081a695c3513f09fdc640bf7f66cd73c47eb479da50312bf9710ee6927729d"
checksum = "a0d7ef7f2a826d0b19f059035831ce00a5e930435cc53c61e045773d0483f67a"
dependencies = [
"glam",
]
[[package]]
name = "bevy_pbr"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d90401eb58acb1c9627f11f75b076bfdeab2af9a4aea4540cb525efc5782b613"
checksum = "75b29c80269fa6db55c9e33701edd3ecb73d8866ca8cb814d49a9d3fb72531b6"
dependencies = [
"bevy_app",
"bevy_asset",
@@ -808,15 +817,28 @@ dependencies = [
[[package]]
name = "bevy_ptr"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea003584000ef02b73800cc7cb62ee74792fff431e6a8df36863c43bf56fb491"
checksum = "8050e2869fe341db6874203b5a01ff12673807a2c7c80cb829f6c7bea6997268"
[[package]]
name = "bevy_rapier3d"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ac2b344d110e8aff2dab7ca6ed428dfcbbfeeb8f20827825996538f24e7fcdf"
dependencies = [
"bevy",
"bitflags 2.5.0",
"log",
"nalgebra",
"rapier3d",
]
[[package]]
name = "bevy_reflect"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1101dbd44ae35e5c66802e46cfba1182e49f6163c824bee380d4acab5b2f640"
checksum = "ccbd7de21d586457a340a0962ad0747dc5098ff925eb6b27a918c4bdd8252f7b"
dependencies = [
"bevy_math",
"bevy_ptr",
@@ -832,9 +854,9 @@ dependencies = [
[[package]]
name = "bevy_reflect_derive"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2a8791d5841a6db862571f709d7ee70c2a5eb1634c3a4329817d04f0e307c2d"
checksum = "3ce33051bd49036d4a5a62aa3f2068672ec55f3ebe92aa0d003a341f15cc37ac"
dependencies = [
"bevy_macro_utils",
"proc-macro2",
@@ -845,9 +867,9 @@ dependencies = [
[[package]]
name = "bevy_render"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75bbb48471f8cd06f5253e271f9b793695f5b821fc9d39a875497905578d9867"
checksum = "88b2c4b644c739c0b474b6f8f7b0bc68ac13d83b59688781e9a7753c52780177"
dependencies = [
"async-channel",
"bevy_app",
@@ -890,9 +912,9 @@ dependencies = [
[[package]]
name = "bevy_render_macros"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffd61a89e7a1b55c78a0aef1fcadd0247fe74a101c00f831791db73d63465051"
checksum = "720b88406e786e378829b7d43c1ffb5300186912b99904d0d4d8ec6698a4f210"
dependencies = [
"bevy_macro_utils",
"proc-macro2",
@@ -902,9 +924,9 @@ dependencies = [
[[package]]
name = "bevy_scene"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "368b989251241efb590976e309e4778ed9d04eb896c37ea6b874a374432a0b3e"
checksum = "1f3d2caa1bfe7542dbe2c62e1bcc10791ba181fb744d2fe6711d1d373354da7c"
dependencies = [
"bevy_app",
"bevy_asset",
@@ -922,9 +944,9 @@ dependencies = [
[[package]]
name = "bevy_sprite"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f52d807086d2c92bc37ee770aa6dbb442b62cdc5665b9c6dd32629b8fae05e4"
checksum = "8cad1b555161f50e5d62b7fdf7ebeef1b24338aae7a88e51985da9553cd60ddf"
dependencies = [
"bevy_app",
"bevy_asset",
@@ -948,9 +970,9 @@ dependencies = [
[[package]]
name = "bevy_tasks"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40be36aeec06b8f0eb87894922c6a7fbd8f2a5c8e77dcb9dcbf77641046988c0"
checksum = "f07fcc4969b357de143509925b39c9a2c56eaa8750828d97f319ca9ed41897cb"
dependencies = [
"async-channel",
"async-executor",
@@ -962,9 +984,9 @@ dependencies = [
[[package]]
name = "bevy_text"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48f0e51919e13c0c39ecdffcf843e8a8d95fd8861023b02b3ee486d3fa4b6003"
checksum = "c4e8456ae0bea7d6b7621e42c1c12bf66c0891381e62c948ab23920673ce611c"
dependencies = [
"ab_glyph",
"bevy_app",
@@ -984,9 +1006,9 @@ dependencies = [
[[package]]
name = "bevy_time"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06fc48cf59acd2b1c52e61787b5bb3db1a0f923cc6ccc68c0d8ab2b5894cfd28"
checksum = "38ea5ae9fe7f56f555dbb05a88d34931907873e3f0c7dc426591839eef72fe3e"
dependencies = [
"bevy_app",
"bevy_ecs",
@@ -998,9 +1020,9 @@ dependencies = [
[[package]]
name = "bevy_transform"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b962ae4253f5413b64a839ab8e8d63bc3e3db45f41d06b6ddc7886acdcb5d0f5"
checksum = "a0d51a1f332cc00939d2f19ed6b909e5ed7037e39c7e25cc86930d79d432163e"
dependencies = [
"bevy_app",
"bevy_ecs",
@@ -1012,9 +1034,9 @@ dependencies = [
[[package]]
name = "bevy_ui"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3449b963573a56b484cf4f8883f1b5b8eaccaaeda8f28a70c006e3291450f77"
checksum = "b6bbc30be39cfbfa3a073b541d22aea43ab14452dea12d7411ce201df17ff7b1"
dependencies = [
"bevy_a11y",
"bevy_app",
@@ -1040,9 +1062,9 @@ dependencies = [
[[package]]
name = "bevy_utils"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac758c2e8509a4a260b7a91f920be3beee6ab9e76e388494240ac5d672779159"
checksum = "5a9f845a985c00e0ee8dc2d8af3f417be925fb52aad4bda5b96e2e58a2b4d2eb"
dependencies = [
"ahash",
"bevy_utils_proc_macros",
@@ -1059,9 +1081,9 @@ dependencies = [
[[package]]
name = "bevy_utils_proc_macros"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "014c80f466ed01821a2e602d63cd5076915c1af5de5fa3c074cc4a9ca898ada7"
checksum = "bef158627f30503d5c18c20c60b444829f698d343516eeaf6eeee078c9a45163"
dependencies = [
"proc-macro2",
"quote",
@@ -1070,9 +1092,9 @@ dependencies = [
[[package]]
name = "bevy_window"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa0c2a1e580b3b0ad0c928a5e250c8375c6a8a70d8b0f483b23d3bf5b670cc1a"
checksum = "976202d2ed838176595b550ac654b15ae236e0178a6f19a94ca6d58f2a96ca60"
dependencies = [
"bevy_a11y",
"bevy_app",
@@ -1087,9 +1109,9 @@ dependencies = [
[[package]]
name = "bevy_winit"
version = "0.13.1"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c408d459172758a4cfa37e3452d4ea0898101ec2b6d92aa3eb698511bef389"
checksum = "aa66539aa93d8522b146bf82de429714ea6370a6061fc1f1ff7bcacd4e64c6c4"
dependencies = [
"accesskit_winit",
"approx",
@@ -1550,6 +1572,19 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-epoch",
"crossbeam-queue",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.12"
@@ -1559,6 +1594,34 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-queue"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.19"
@@ -1959,7 +2022,7 @@ dependencies = [
"vec_map",
"wasm-bindgen",
"web-sys",
"windows 0.54.0",
"windows 0.48.0",
]
[[package]]
@@ -2408,6 +2471,12 @@ dependencies = [
"windows-targets 0.52.4",
]
[[package]]
name = "libm"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
[[package]]
name = "libredox"
version = "0.0.2"
@@ -2478,6 +2547,16 @@ dependencies = [
"regex-automata 0.1.10",
]
[[package]]
name = "matrixmultiply"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7574c1cf36da4798ab73da5b215bbf444f50718207754cb522201d78d1cd0ff2"
dependencies = [
"autocfg",
"rawpointer",
]
[[package]]
name = "memchr"
version = "2.7.1"
@@ -2556,6 +2635,34 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "nalgebra"
version = "0.32.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ea4908d4f23254adda3daa60ffef0f1ac7b8c3e9a864cf3cc154b251908a2ef"
dependencies = [
"approx",
"glam",
"matrixmultiply",
"nalgebra-macros",
"num-complex",
"num-rational",
"num-traits",
"simba",
"typenum",
]
[[package]]
name = "nalgebra-macros"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91761aed67d03ad966ef783ae962ef9bbaca728d2dd7ceb7939ec110fffad998"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "ndk"
version = "0.8.0"
@@ -2661,6 +2768,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "num-complex"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6"
dependencies = [
"num-traits",
]
[[package]]
name = "num-derive"
version = "0.4.2"
@@ -2672,6 +2788,26 @@ dependencies = [
"syn 2.0.55",
]
[[package]]
name = "num-integer"
version = "0.1.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
dependencies = [
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.18"
@@ -2679,6 +2815,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
dependencies = [
"autocfg",
"libm",
]
[[package]]
@@ -2880,6 +3017,27 @@ dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "parry3d"
version = "0.13.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ccba18a65dba56c08dadfa936e0c9efbc883b3a26dc77d2685f78be10f7667c"
dependencies = [
"approx",
"arrayvec",
"bitflags 1.3.2",
"downcast-rs",
"either",
"nalgebra",
"num-derive",
"num-traits",
"rustc-hash",
"simba",
"slab",
"smallvec",
"spade",
]
[[package]]
name = "paste"
version = "1.0.14"
@@ -2908,6 +3066,7 @@ version = "0.1.0"
dependencies = [
"bevy",
"bevy-inspector-egui",
"bevy_rapier3d",
"camera_system",
"iyes_perf_ui",
"noise 0.8.2",
@@ -3111,6 +3270,27 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8a99fddc9f0ba0a85884b8d14e3592853e787d581ca1816c91349b10e4eeab"
[[package]]
name = "rapier3d"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d07a833e0aa3bc57010caaa50bf75fa78afc03a74207607db740da4e4579a1"
dependencies = [
"approx",
"arrayvec",
"bit-vec",
"bitflags 1.3.2",
"crossbeam",
"downcast-rs",
"nalgebra",
"num-derive",
"num-traits",
"parry3d",
"rustc-hash",
"simba",
"vec_map",
]
[[package]]
name = "raw-window-handle"
version = "0.5.2"
@@ -3123,6 +3303,12 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42a9830a0e1b9fb145ebb365b8bc4ccd75f290f98c0247deafbbe2c75cefb544"
[[package]]
name = "rawpointer"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
[[package]]
name = "rectangle-pack"
version = "0.4.2"
@@ -3197,6 +3383,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
[[package]]
name = "robust"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbf4a6aa5f6d6888f39e980649f3ad6b666acdce1d78e95b8a2cb076e687ae30"
[[package]]
name = "rodio"
version = "0.17.3"
@@ -3255,6 +3447,15 @@ version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
[[package]]
name = "safe_arch"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f398075ce1e6a179b46f51bd88d0598b92b00d3551f1a2d4ac49e771b56ac354"
dependencies = [
"bytemuck",
]
[[package]]
name = "same-file"
version = "1.0.6"
@@ -3292,9 +3493,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.114"
version = "1.0.115"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0"
checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd"
dependencies = [
"itoa",
"ryu",
@@ -3316,6 +3517,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",
"num-traits",
"paste",
"wide",
]
[[package]]
name = "simd-adler32"
version = "0.3.7"
@@ -3358,6 +3572,18 @@ dependencies = [
"serde",
]
[[package]]
name = "spade"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61addf9117b11d1f5b4bf6fe94242ba25f59d2d4b2080544b771bd647024fd00"
dependencies = [
"hashbrown",
"num-traits",
"robust",
"smallvec",
]
[[package]]
name = "spirv"
version = "0.3.0+sdk-1.3.268.0"
@@ -3608,6 +3834,12 @@ dependencies = [
"static_assertions",
]
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "unicode-bidi"
version = "0.3.15"
@@ -3924,6 +4156,16 @@ dependencies = [
"web-sys",
]
[[package]]
name = "wide"
version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89beec544f246e679fc25490e3f8e08003bc4bf612068f325120dad4cea02c1c"
dependencies = [
"bytemuck",
"safe_arch",
]
[[package]]
name = "widestring"
version = "1.0.2"
@@ -4293,8 +4535,11 @@ dependencies = [
name = "world_generation"
version = "0.1.0"
dependencies = [
"asset_loader",
"bevy",
"noise 0.9.0",
"serde",
"serde_json",
]
[[package]]

View File

@@ -1,14 +1,14 @@
[workspace]
resolver = "2"
members = [
"game/main",
"engine/world_generation"
, "game/camera_system"]
resolver = "2"
"engine/world_generation",
"game/camera_system"
, "engine/asset_loader"]
# Enable a small amount of optimization in debug mode
#[profile.dev]
#opt-level = 1
[profile.dev]
opt-level = 1
# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]

View File

@@ -0,0 +1,11 @@
[package]
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.197"
serde_json = "1.0.115"
bevy = "0.13.2"

View File

@@ -0,0 +1,106 @@
pub mod macros {
#[macro_export]
macro_rules! create_asset_loader {
(
$plugin_name: ident,
$loader_name: ident,
$asset_type: ident,
$asset_loadstate_name: 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, LoadContext, 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>()
.insert_resource($asset_loadstate_name::default())
.add_systems(Update, finalize);
}
}
fn finalize(
mut asset_events: EventReader<AssetEvent<$asset_type>>,
mut assets: ResMut<Assets<$asset_type>>,
mut load_state: ResMut<$asset_loadstate_name>,
asset_server: Res<AssetServer>
) {
for event in asset_events.read() {
match event {
AssetEvent::Added { id } => load_state.added += 1,
AssetEvent::LoadedWithDependencies { id } => {
let asset = assets.get_mut(id.clone()).unwrap();
$(
asset.$handle_name = asset_server.load(&asset.$string_name);
)*
$(
for i in 0..asset.$string_array_name.len(){
asset.$handle_array_name.push(asset_server.load(&asset.$string_array_name[i]));
}
)?
load_state.loaded += 1;
},
_ => (),
}
}
}
#[derive(Resource, Debug, Default)]
pub struct $asset_loadstate_name{
pub loaded: u32,
pub added: u32,
}
impl $asset_loadstate_name{
pub fn is_all_loaded(&self) -> bool{
if self.added == 0{
return false;
}
return self.loaded >= self.added;
}
}
#[derive(Default)]
pub struct $loader_name;
impl AssetLoader for $loader_name {
type Asset = $asset_type;
type Settings = ();
type Error = String;
fn load<'a>(
&'a self,
reader: &'a mut Reader,
_settings: &'a Self::Settings,
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
return Box::pin(async move {
let mut data: String = String::new();
let read_result = reader.read_to_string(&mut data).await;
if read_result.is_err() {
return Err(read_result.err().unwrap().to_string());
}
let serialized: Result<Self::Asset, serde_json::Error> =
serde_json::from_str(&data);
if serialized.is_err() {
return Err(serialized.err().unwrap().to_string());
}
return Ok(serialized.unwrap());
});
}
fn extensions(&self) -> &[&str] {
$extensions
}
}
};
}
}

View File

@@ -6,5 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = "0.13.1"
bevy = "0.13.2"
noise = "0.9.0"
serde = {version="1.0.197", features=["derive"]}
serde_json = "1.0.115"
asset_loader = {path = "../asset_loader"}

View File

@@ -0,0 +1,34 @@
use asset_loader::create_asset_loader;
use bevy::{
asset::{Asset, Handle},
reflect::TypePath,
};
use serde::{Deserialize, Serialize};
use crate::tile_mapper::TileMapperAsset;
#[derive(Serialize, Deserialize, Debug, TypePath, Asset)]
pub struct BiomePainterAsset {
#[serde(skip)]
pub biomes: Vec<Handle<TileMapperAsset>>,
pub biomes_path: [String; 16],
}
impl BiomePainterAsset {
pub fn sample_biome(&self, moisture: f32, temperature: f32) -> Handle<TileMapperAsset> {
let x = (moisture.clamp(0., 1.) * 3.).ceil() as usize;
let y = (temperature.clamp(0., 1.) * 3.).ceil() as usize;
return self.biomes[x + y * 4].clone();
}
}
create_asset_loader!(
BiomePainterPlugin,
BiomePainterLoader,
BiomePainterAsset,
BiomePainterLoadState,
&["bimoes.json"],
;
biomes_path -> biomes
?
);

View File

@@ -20,6 +20,8 @@ pub fn generate_heightmap(cfg: &GenerationConfig, seed: u32) -> Map {
pub fn generate_chunk(chunk_x: f64, chunk_z: f64, cfg: &GenerationConfig, seed: u32) -> Chunk {
let mut result: [f32; Chunk::SIZE * Chunk::SIZE] = [0.; Chunk::SIZE * Chunk::SIZE];
let mut moisture = [0.; Chunk::SIZE * Chunk::SIZE];
let mut temp = [0.; Chunk::SIZE * Chunk::SIZE];
let noise = SuperSimplex::new(seed);
for z in 0..Chunk::SIZE {
for x in 0..Chunk::SIZE {
@@ -30,15 +32,36 @@ pub fn generate_chunk(chunk_x: f64, chunk_z: f64, cfg: &GenerationConfig, seed:
&noise,
);
result[x + z * Chunk::SIZE] = sample;
moisture[x + z * Chunk::SIZE] = noise.get([
(x as f64 + chunk_x * Chunk::SIZE as f64) / &cfg.noise_scale,
(z as f64 + chunk_z * Chunk::SIZE as f64) / &cfg.noise_scale,
]) as f32;
temp[x + z * Chunk::SIZE] = sample_tempurature(
z as f32 + chunk_z as f32 * Chunk::SIZE as f32,
sample,
&cfg,
100.,
);
}
}
return Chunk {
points: result,
heights: result,
moisture: moisture,
temperature: temp,
chunk_offset: IVec2::new(chunk_x as i32, chunk_z as i32),
};
}
fn sample_point(x: f64, z: f64, cfg: &GenerationConfig, noise: &SuperSimplex) -> f32 {
fn sample_tempurature(z: f32, height: f32, cfg: &GenerationConfig, equator: f32) -> f32 {
let d = (equator - z).abs();
let max_d = equator.max(cfg.get_total_height() as f32 - equator);
let t_mod = d.remap(0., max_d, 0., 1.).clamp(0., 1.);
// let max_d = d.max()
return (height.remap(0., 50., 0., 1.).clamp(0., 1.) + t_mod) / 2.;
}
fn sample_point(x: f64, z: f64, cfg: &GenerationConfig, noise: &impl NoiseFn<f64, 2>) -> f32 {
let x_s = x / cfg.noise_scale;
let z_s = z / cfg.noise_scale;
@@ -81,7 +104,7 @@ fn mask(mask: f64, value: f64, sea_level: f64) -> f64 {
return value * m;
}
fn sample_simple(x: f64, z: f64, cfg: &GeneratorLayer, noise: &SuperSimplex) -> f64 {
fn sample_simple(x: f64, z: f64, cfg: &GeneratorLayer, noise: &impl NoiseFn<f64, 2>) -> f64 {
let mut freq: f64 = cfg.base_roughness;
let mut amp: f64 = 1.;
let mut value = 0.;
@@ -95,7 +118,7 @@ fn sample_simple(x: f64, z: f64, cfg: &GeneratorLayer, noise: &SuperSimplex) ->
value -= cfg.min_value;
return value * cfg.strength;
}
fn sample_rigid(x: f64, z: f64, cfg: &GeneratorLayer, noise: &SuperSimplex) -> f64 {
fn sample_rigid(x: f64, z: f64, cfg: &GeneratorLayer, noise: &impl NoiseFn<f64, 2>) -> f64 {
let mut freq: f64 = cfg.base_roughness;
let mut amp: f64 = 1.;
let mut value = 0.;

View File

@@ -128,15 +128,15 @@ impl HexCoord {
return IVec2::new(self.hex.x + (self.hex.y / 2), self.hex.y);
}
pub fn to_index(&self, width: usize) -> i32 {
return (self.hex.x + self.hex.y * width as i32) + (self.hex.y / 2);
pub fn to_index(&self, width: usize) -> usize {
return ((self.hex.x + self.hex.y * width as i32) + (self.hex.y / 2)) as usize;
}
pub fn to_chunk_index(&self, width: usize) -> i32 {
pub fn to_chunk_index(&self, width: usize) -> usize {
let pos = self.to_chunk_pos();
return pos.x + pos.y * width as i32;
return (pos.x + pos.y * width as i32) as usize;
}
pub fn to_chunk_local_index(&self) -> i32 {
pub fn to_chunk_local_index(&self) -> usize {
return self.to_chunk().to_index(Chunk::SIZE);
}

View File

@@ -1,3 +1,10 @@
pub mod biome_painter;
pub mod heightmap;
pub mod hex_utils;
pub mod mesh_generator;
pub mod tile_manager;
pub mod tile_mapper;
pub mod prelude {
use crate::hex_utils::HexCoord;
use bevy::math::{IVec2, UVec2};
@@ -13,6 +20,15 @@ pub mod prelude {
pub layers: Vec<GeneratorLayer>,
}
impl GenerationConfig {
pub fn get_total_width(&self) -> usize {
return self.size.x as usize * Chunk::SIZE;
}
pub fn get_total_height(&self) -> usize {
return self.size.y as usize * Chunk::SIZE;
}
}
pub struct GeneratorLayer {
pub strength: f64,
pub min_value: f64,
@@ -27,7 +43,9 @@ pub mod prelude {
}
pub struct Chunk {
pub points: [f32; Chunk::SIZE * Chunk::SIZE],
pub heights: [f32; Chunk::SIZE * Chunk::SIZE],
pub moisture: [f32; Chunk::SIZE * Chunk::SIZE],
pub temperature: [f32; Chunk::SIZE * Chunk::SIZE],
pub chunk_offset: IVec2,
}
@@ -54,18 +72,29 @@ pub mod prelude {
continue;
}
let c_idx = n_tile.to_chunk_index(self.width);
let chunk = &self.chunks[c_idx as usize];
let chunk = &self.chunks[c_idx];
let local = n_tile.to_chunk_local_index();
results[i] = Some(chunk.points[local as usize]);
results[i] = Some(chunk.heights[local]);
}
return results;
}
pub fn get_height(&self, pos: &HexCoord) -> f32 {
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
return chunk.heights[pos.to_chunk_local_index()];
}
pub fn get_moisture(&self, pos: &HexCoord) -> f32 {
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
return chunk.moisture[pos.to_chunk_local_index()];
}
pub fn get_tempurature(&self, pos: &HexCoord) -> f32 {
let chunk = &self.chunks[pos.to_chunk_index(self.width)];
return chunk.temperature[pos.to_chunk_local_index()];
}
}
pub const ATTRIBUTE_TEXTURE_INDEX: MeshVertexAttribute =
MeshVertexAttribute::new("TextureIndex", 988540917, VertexFormat::Uint32);
}
pub mod heightmap;
pub mod hex_utils;
pub mod mesh_generator;

View File

@@ -1,4 +1,7 @@
use crate::biome_painter::BiomePainterAsset;
use crate::hex_utils::HexCoord;
use crate::tile_manager::TileAsset;
use crate::tile_mapper::TileMapperAsset;
use crate::{
hex_utils::{offset3d_to_world, INNER_RADIUS, OUTER_RADIUS},
prelude::*,
@@ -11,8 +14,6 @@ use bevy::{
},
};
use std::vec::Vec;
use bevy::render::mesh::MeshVertexAttribute;
use bevy::render::render_resource::VertexFormat;
const HEX_CORNERS: [Vec3; 6] = [
Vec3::new(0., 0., OUTER_RADIUS),
@@ -23,30 +24,69 @@ const HEX_CORNERS: [Vec3; 6] = [
Vec3::new(-INNER_RADIUS, 0., 0.5 * OUTER_RADIUS),
];
const HEX_NORMALS: [Vec3; 6] = [
Vec3::new(
INNER_RADIUS / 2.,
0.,
(OUTER_RADIUS + 0.5 * OUTER_RADIUS) / 2.,
),
Vec3::Z,
Vec3::new(
INNER_RADIUS / -2.,
0.,
(OUTER_RADIUS + 0.5 * OUTER_RADIUS) / 2.,
),
Vec3::new(
INNER_RADIUS / -2.,
0.,
(OUTER_RADIUS + 0.5 * OUTER_RADIUS) / -2.,
),
Vec3::NEG_Z,
Vec3::new(
INNER_RADIUS / 2.,
0.,
(OUTER_RADIUS + 0.5 * OUTER_RADIUS) / -2.,
),
];
pub fn generate_chunk_mesh(chunk: &Chunk, map: &Map) -> Mesh {
pub fn generate_chunk_mesh(
chunk: &Chunk,
map: &Map,
painter: &BiomePainterAsset,
tiles: &Res<Assets<TileAsset>>,
mappers: &Res<Assets<TileMapperAsset>>,
) -> Mesh {
let vertex_count: usize = Chunk::SIZE * Chunk::SIZE * 6;
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 height = chunk.points[x + z * Chunk::SIZE];
let height = chunk.heights[x + z * Chunk::SIZE];
let moisture = chunk.moisture[x + z * Chunk::SIZE];
let temperature = chunk.temperature[x + z * Chunk::SIZE];
let off_pos = Vec3::new(x as f32, height, z as f32);
let tile_pos = offset3d_to_world(off_pos);
let coord = HexCoord::from_offset(
IVec2::new(x as i32, z as i32) + (chunk.chunk_offset * Chunk::SIZE as i32),
);
let n = map.get_neighbors(&coord);
let biome = mappers.get(painter.sample_biome(moisture, temperature));
let tile_handle = biome.unwrap().sample_tile(height);
let tile = tiles.get(tile_handle).unwrap();
create_tile(
tile_pos,
&n,
&mut verts,
&mut uvs,
&mut indices,
&mut normals,
// &mut tex,
(height % 7.) as u32,
tile.texture_id,
tile.side_texture_id,
);
}
}
@@ -55,36 +95,41 @@ pub fn generate_chunk_mesh(chunk: &Chunk, map: &Map) -> Mesh {
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_indices(Indices::U32(indices))
.with_duplicated_vertices()
.with_computed_flat_normals();
.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;
}
const TEX_MULTI: Vec2 = Vec2::new(1000., 1.);
fn create_tile(
pos: Vec3,
neighbors: &[Option<f32>; 6],
verts: &mut Vec<Vec3>,
uvs: &mut Vec<Vec2>,
indices: &mut Vec<u32>,
normals: &mut Vec<Vec3>,
texture_index: u32,
side_texture_index: u32,
) {
let uv_offset = Vec2::splat(0.5);
let tex_off = Vec2::new(texture_index as f32, 0.);
let side_tex_off = Vec2::new(side_texture_index as f32, 0.);
let idx = verts.len() as u32;
uvs.push(uv_offset + tex_off);
uvs.push((uv_offset / TEX_MULTI) + tex_off);
verts.push(pos);
normals.push(Vec3::Y);
for i in 0..6 {
let p = pos + HEX_CORNERS[i];
verts.push(p);
let uv = (HEX_CORNERS[i].xz() / 2.) + uv_offset;
uvs.push(uv + tex_off);
uvs.push((uv / TEX_MULTI) + tex_off);
indices.push(idx);
indices.push(idx + 1 + i as u32);
indices.push(idx + 1 + ((i as u32 + 1) % 6));
normals.push(Vec3::Y);
}
for i in 0..neighbors.len() {
@@ -92,7 +137,7 @@ fn create_tile(
match cur_n {
Some(n_height) => {
if n_height < pos.y {
create_tile_wall(pos, i, n_height, verts, uvs, indices, tex_off);
create_tile_wall(pos, i, n_height, verts, uvs, indices, normals, side_tex_off);
}
}
_ => {}
@@ -107,6 +152,7 @@ fn create_tile_wall(
verts: &mut Vec<Vec3>,
uvs: &mut Vec<Vec2>,
indices: &mut Vec<u32>,
normals: &mut Vec<Vec3>,
tex_off: Vec2,
) {
let p1 = HEX_CORNERS[(dir) % 6] + pos;
@@ -121,6 +167,12 @@ fn create_tile_wall(
verts.push(p3);
verts.push(p4);
let n = HEX_NORMALS[dir].normalize();
normals.push(n);
normals.push(n);
normals.push(n);
normals.push(n);
indices.push(idx);
indices.push(idx + 2);
indices.push(idx + 1);
@@ -130,7 +182,7 @@ fn create_tile_wall(
indices.push(idx + 3);
uvs.push(Vec2::ZERO + tex_off);
uvs.push(Vec2::new(1., 0.) + tex_off);
uvs.push(Vec2::new(0., pos.y - height) + tex_off);
uvs.push(Vec2::new(1., pos.y - height) + tex_off);
uvs.push((Vec2::new(1., 0.) / TEX_MULTI) + tex_off);
uvs.push((Vec2::new(0., pos.y - height) / TEX_MULTI) + tex_off);
uvs.push((Vec2::new(1., pos.y - height) / TEX_MULTI) + tex_off);
}

View File

@@ -0,0 +1,40 @@
use asset_loader::create_asset_loader;
use bevy::{
asset::{Asset, Handle},
ecs::system::Resource,
reflect::TypePath,
};
use serde::{Deserialize, Serialize};
#[derive(Resource, Debug)]
pub struct TileManager {
pub tiles: Vec<Handle<TileAsset>>,
}
impl Default for TileManager {
fn default() -> Self {
Self { tiles: vec![] }
}
}
impl TileManager {
pub fn register_tile(&mut self, tile: Handle<TileAsset>) -> usize {
let id = self.tiles.len();
self.tiles.push(tile);
return id;
}
}
#[derive(Serialize, Deserialize, Debug, TypePath, Asset)]
pub struct TileAsset {
#[serde(skip)]
pub id: usize,
pub name: String,
pub texture_id: u32,
#[serde(skip)]
pub texture: String,
pub side_texture_id: u32,
#[serde(skip)]
pub side_texture: String,
}
create_asset_loader!(TileAssetPlugin, TileAssetLoader, TileAsset, TileAssetLoadState, &["tile.json"],;?);

View File

@@ -0,0 +1,41 @@
use asset_loader::create_asset_loader;
use bevy::prelude::*;
use bevy::{
asset::{Asset, Handle},
reflect::TypePath,
};
use serde::{Deserialize, Serialize};
use crate::tile_manager::TileAsset;
pub struct TileMapper;
#[derive(Serialize, Deserialize, Debug, TypePath, Asset)]
pub struct TileMapperAsset {
#[serde(skip)]
pub tiles: Vec<Handle<TileAsset>>,
pub tiles_path: Vec<String>,
pub thresholds: Vec<f32>,
}
impl TileMapperAsset {
pub fn sample_tile(&self, height: f32) -> Handle<TileAsset> {
for i in 0..self.thresholds.len() {
let t = self.thresholds[i];
if t >= height {
return self.tiles[i].clone();
}
}
return self.tiles.last().unwrap().clone();
}
}
create_asset_loader!(
TileMapperAssetPlugin,
TileMapperAssetLoader,
TileMapperAsset,
TileMapperLoadState,
&["mapper.json"],;
tiles_path -> tiles
?
);

View File

@@ -42,7 +42,12 @@ 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();
let mut move_vec = Vec3::ZERO;

View File

@@ -2,13 +2,15 @@
name = "phos"
version = "0.1.0"
edition = "2021"
build = "build.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = "0.13.1"
bevy = "0.13.2"
bevy-inspector-egui = "0.23.4"
iyes_perf_ui = "0.2.3"
noise = "0.8.2"
world_generation ={path="../../engine/world_generation"}
camera_system={path = "../camera_system"}
bevy_rapier3d = { version = "0.25.0", features = [ "simd-stable", "debug-render-3d" ] }

1
game/main/assets Submodule

Submodule game/main/assets added at 256b49cc29

View File

@@ -1,91 +0,0 @@
#import bevy_pbr::{
pbr_fragment::pbr_input_from_standard_material,
pbr_functions::alpha_discard,
}
#import bevy_pbr::mesh_functions::{mesh_position_local_to_world,get_model_matrix,mesh_normal_local_to_world}
#import bevy_pbr::view_transformations::position_world_to_clip;
#ifdef PREPASS_PIPELINE
#import bevy_pbr::{
prepass_io::{VertexOutput, FragmentOutput},
pbr_deferred_functions::deferred_output,
}
#else
#import bevy_pbr::{
forward_io::{VertexOutput, FragmentOutput},
pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing},
}
#endif
@group(2) @binding(100) var array_texture: texture_2d_array<f32>;
@group(2) @binding(101) var array_texture_sampler: sampler;
@fragment
fn fragment(
in: VertexOutput,
@builtin(front_facing) is_front: bool,
) -> FragmentOutput {
// var vin : VertexOutput;
// vin.position = in.position;
// vin.world_position = in.world_position;
// vin.world_normal = in.world_normal;
// vin.uv = in.uv;
// generate a PbrInput struct from the StandardMaterial bindings
var pbr_input = pbr_input_from_standard_material(in, is_front);
// alpha discard
pbr_input.material.base_color = alpha_discard(pbr_input.material, pbr_input.material.base_color);
#ifdef PREPASS_PIPELINE
// in deferred mode we can't modify anything after that, as lighting is run in a separate fullscreen shader.
let out = deferred_output(in, pbr_input);
#else
var out: FragmentOutput;
// apply lighting
let index = floor(in.uv.x - 1) + 1;
var uv = in.uv;
uv.x = in.uv.x - index;
out.color = textureSample(array_texture, array_texture_sampler, uv, u32(index));
out.color *= apply_pbr_lighting(pbr_input);
// apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr)
// note this does not include fullscreen postprocessing effects like bloom.
out.color = main_pass_post_lighting_processing(pbr_input, out.color);
#endif
return out;
}
//struct Vertex {
// @builtin(instance_index) instance_index: u32,
// @location(0) position: vec3<f32>,
// @location(1) uv: vec2<f32>,
// @location(2) normal: vec3<f32>,
// @location(3) texture_index: u32,
//};
//
//struct VOut {
// @builtin(position) position: vec4<f32>,
// @location(0) world_position: vec4<f32>,
// @location(1) world_normal: vec3<f32>,
// @location(2) uv: vec2<f32>,
//// @location(7) @interpolate(flat) texture_index: u32,
//};
//
//@vertex
//fn vertex(vertex: Vertex) -> VOut {
// var out: VOut;
// out.world_position = mesh_position_local_to_world(get_model_matrix(vertex.instance_index), vec4<f32>(vertex.position, 1.0));
// out.position = position_world_to_clip(out.world_position.xyz);
//// out.texture_index = vertex.texture_index;
// out.uv = vertex.uv;
// out.world_normal = mesh_normal_local_to_world(vertex.normal, vertex.instance_index);
// return out;
//}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 740 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

48
game/main/build.rs Normal file
View File

@@ -0,0 +1,48 @@
use std::{
env, fs,
path::{Path, PathBuf},
};
/// A helper function for recursively copying a directory.
fn copy_dir<P, Q>(from: P, to: Q)
where
P: AsRef<Path>,
Q: AsRef<Path>,
{
let to = to.as_ref().to_path_buf();
for path in fs::read_dir(from).unwrap() {
let path = path.unwrap().path();
let to = to.clone().join(path.file_name().unwrap());
if path.is_file() {
fs::copy(&path, to).unwrap();
} else if path.is_dir() {
if !to.exists() {
fs::create_dir(&to).unwrap();
}
copy_dir(&path, to);
} else { /* Skip other content */
}
}
}
const COPY_DIR: &'static str = "assets";
fn main() {
// Request the output directory
let out = env::var("PROFILE").unwrap();
let out = PathBuf::from(format!("../../target/{}/{}", out, COPY_DIR));
// If it is already in the output directory, delete it and start over
if out.exists() {
fs::remove_dir_all(&out).unwrap();
}
// Create the out directory
fs::create_dir(&out).unwrap();
// Copy the directory
copy_dir(COPY_DIR, &out);
}

1
game/main/src/macros.rs Normal file
View File

@@ -0,0 +1 @@

View File

@@ -5,7 +5,7 @@ use bevy_inspector_egui::quick::WorldInspectorPlugin;
mod phos;
mod prelude;
mod shader_extensions;
use phos::PhosGamePlugin;
fn main() {

View File

@@ -1,28 +1,52 @@
use crate::prelude::*;
use crate::shader_extensions::chunk_material::ChunkMaterial;
use bevy::asset::LoadState;
use bevy::pbr::{ExtendedMaterial};
use bevy::core_pipeline::experimental::taa::TemporalAntiAliasPlugin;
use bevy::pbr::ExtendedMaterial;
use bevy::{pbr::CascadeShadowConfig, prelude::*};
use bevy_rapier3d::plugin::{NoUserData, RapierPhysicsPlugin};
use bevy_rapier3d::render::RapierDebugRenderPlugin;
use camera_system::PhosCameraPlugin;
use iyes_perf_ui::prelude::*;
use world_generation::hex_utils::{offset_to_world, HexCoord};
use world_generation::biome_painter::{
BiomePainterAsset, BiomePainterLoadState, BiomePainterPlugin,
};
use world_generation::hex_utils::offset_to_world;
use world_generation::tile_manager::{TileAsset, TileAssetLoadState, TileAssetPlugin, TileManager};
use world_generation::tile_mapper::{TileMapperAsset, TileMapperAssetPlugin, TileMapperLoadState};
use world_generation::{
heightmap::generate_heightmap, mesh_generator::generate_chunk_mesh, prelude::*,
};
use crate::prelude::*;
pub struct PhosGamePlugin;
impl Plugin for PhosGamePlugin {
fn build(&self, app: &mut App) {
app.add_plugins(PhosCameraPlugin).add_plugins(MaterialPlugin::<
ExtendedMaterial<StandardMaterial, ChunkMaterial>,
>::default());
app.add_plugins(PhosCameraPlugin)
.add_plugins(MaterialPlugin::<
ExtendedMaterial<StandardMaterial, ChunkMaterial>,
>::default())
.add_plugins(TemporalAntiAliasPlugin);
//Systems - Startup
app.add_systems(Startup, init_game)
.add_systems(Startup, (load_textures, create_map).chain());
app.add_systems(Update, (check_texture, spawn_map));
.add_systems(Startup, (load_textures, load_tiles, create_map).chain());
//Systems - Update
app.add_systems(Update, (finalize_texture, spawn_map));
//Perf UI
app.add_plugins(bevy::diagnostic::FrameTimeDiagnosticsPlugin)
.add_plugins(bevy::diagnostic::EntityCountDiagnosticsPlugin)
.add_plugins(bevy::diagnostic::SystemInformationDiagnosticsPlugin)
.add_plugins(PerfUiPlugin);
//Assets
app.add_plugins(TileAssetPlugin);
app.add_plugins(TileMapperAssetPlugin);
app.add_plugins(BiomePainterPlugin);
//Physics
app.add_plugins(RapierPhysicsPlugin::<NoUserData>::default())
.add_plugins(RapierDebugRenderPlugin::default());
}
}
@@ -49,73 +73,58 @@ fn init_game(mut commands: Commands) {
});
commands.insert_resource(PhosMap::default());
commands.insert_resource(TileManager::default());
}
fn load_textures(
mut commands: Commands,
asset_server: Res<AssetServer>,
) {
fn load_textures(mut commands: Commands, asset_server: Res<AssetServer>) {
let main_tex = asset_server.load("textures/world/stack.png");
commands.insert_resource(ChunkAtlas {
handle: main_tex.clone(),
is_loaded: false,
});
}
#[derive(Resource)]
struct Painter(Handle<BiomePainterAsset>);
fn check_texture(
fn load_tiles(mut commands: Commands, asset_server: Res<AssetServer>) {
let handle: Handle<BiomePainterAsset> = asset_server.load("biome_painters/terra.biomes.json");
commands.insert_resource(Painter(handle));
}
fn finalize_texture(
asset_server: Res<AssetServer>,
mut atlas: ResMut<ChunkAtlas>,
mut map: ResMut<PhosMap>,
mut images: ResMut<Assets<Image>>,
painter: Res<Painter>,
painter_load: Res<BiomePainterLoadState>,
tile_load: Res<TileAssetLoadState>,
mapper_load: Res<TileMapperLoadState>,
) {
if atlas.is_loaded {
return;
}
if !painter_load.is_all_loaded() || !tile_load.is_all_loaded() || !mapper_load.is_all_loaded() {
return;
}
if asset_server.load_state(atlas.handle.clone()) != LoadState::Loaded {
return;
}
if asset_server.load_state(painter.0.clone()) != LoadState::Loaded {
return;
}
let image = images.get_mut(&atlas.handle).unwrap();
let array_layers = 7;
let array_layers = 14;
image.reinterpret_stacked_2d_as_array(array_layers);
atlas.is_loaded = true;
map.ready = true;
map.regenerate = true;
}
fn draw_gizmos(mut gizmos: Gizmos, hm: Res<Map>) {
gizmos.arrow(Vec3::ZERO, Vec3::Y * 1.5, Color::GREEN);
gizmos.arrow(Vec3::ZERO, Vec3::Z * 1.5, Color::BLUE);
gizmos.arrow(Vec3::ZERO, Vec3::X * 1.5, Color::RED);
let coord = HexCoord::from_grid_pos(64, 14);
let ch = &hm.chunks[coord.to_chunk_index(hm.width) as usize];
let h = ch.points[coord.to_chunk_local_index() as usize];
gizmos.ray(coord.to_world(h), Vec3::Y, Color::RED);
gizmos.ray(coord.to_world(h), Vec3::Z * 1.5, Color::BLUE);
// let t = coord.get_neighbor(5);
// let h = ch.points[t.to_chunk_local_index() as usize];
// gizmos.ray(t.to_world(h), Vec3::Y * 1., Color::PINK);
let n = coord.get_neighbors();
let nh = hm.get_neighbors(&coord);
for i in 0..6 {
let t = n[i];
let h = nh[i];
if h.is_none() {
continue;
}
gizmos.ray(
t.to_world(h.unwrap()),
Vec3::Y * (i + 1) as f32,
Color::CYAN,
);
}
}
fn create_map(mut commands: Commands) {
let heightmap = generate_heightmap(
&GenerationConfig {
@@ -187,23 +196,31 @@ fn spawn_map(
mut meshes: ResMut<Assets<Mesh>>,
atlas: Res<ChunkAtlas>,
mut map: ResMut<PhosMap>,
tile_assets: Res<Assets<TileAsset>>,
tile_mappers: Res<Assets<TileMapperAsset>>,
biome_painters: Res<Assets<BiomePainterAsset>>,
painter: Res<Painter>,
) {
if !map.ready || !map.regenerate {
return;
}
let b_painter = biome_painters.get(painter.0.clone());
map.regenerate = false;
let chunk_material = materials.add(ExtendedMaterial {
base: StandardMaterial {
base_color: Color::WHITE,
..default()
},
base: StandardMaterial::default(),
extension: ChunkMaterial {
array_texture: atlas.handle.clone(),
},
});
for chunk in &heightmap.chunks {
let mesh = generate_chunk_mesh(&chunk, &heightmap);
let mesh = generate_chunk_mesh(
&chunk,
&heightmap,
b_painter.unwrap(),
&tile_assets,
&tile_mappers,
);
let pos = offset_to_world(chunk.chunk_offset * Chunk::SIZE as i32, 0.);
commands.spawn((
MaterialMeshBundle {
@@ -216,4 +233,3 @@ fn spawn_map(
));
}
}

View File

@@ -1,9 +1,6 @@
use bevy::asset::{Asset, Handle};
use bevy::pbr::{MaterialExtension, MaterialExtensionKey, MaterialExtensionPipeline, MaterialPipeline, MaterialPipelineKey};
use bevy::prelude::{Component, Image, Mesh, Resource, TypePath};
use bevy::render::mesh::{Indices, MeshVertexBufferLayout};
use bevy::render::render_resource::{AsBindGroup, RenderPipelineDescriptor, ShaderRef, SpecializedMeshPipelineError};
use world_generation::prelude::ATTRIBUTE_TEXTURE_INDEX;
use bevy::asset::Handle;
use bevy::prelude::{Component, Image, Resource};
#[derive(Resource)]
pub struct ChunkAtlas {
@@ -19,33 +16,3 @@ pub struct PhosMap {
#[derive(Component)]
pub struct PhosChunk;
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
pub struct ChunkMaterial {
#[texture(100, dimension = "2d_array")]
#[sampler(101)]
pub array_texture: Handle<Image>,
}
impl MaterialExtension for ChunkMaterial {
fn fragment_shader() -> ShaderRef {
"shaders/world/chunk.wgsl".into()
}
// fn specialize(
// _pipeline: &MaterialExtensionPipeline,
// descriptor: &mut RenderPipelineDescriptor,
// layout: &MeshVertexBufferLayout,
// _key: MaterialExtensionKey<Self>,
// ) -> Result<(), SpecializedMeshPipelineError> {
// let vertex_layout = layout.get_layout(&[
// Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
// Mesh::ATTRIBUTE_UV_0.at_shader_location(1),
// Mesh::ATTRIBUTE_NORMAL.at_shader_location(2),
// ATTRIBUTE_TEXTURE_INDEX.at_shader_location(3),
// ])?;
// descriptor.vertex.buffers = vec![vertex_layout];
// Ok(())
// }
}

View File

@@ -0,0 +1,18 @@
use bevy::asset::{Asset, Handle};
use bevy::pbr::MaterialExtension;
use bevy::reflect::TypePath;
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
use bevy::render::texture::Image;
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
pub struct ChunkMaterial {
#[texture(100, dimension = "2d_array")]
#[sampler(101)]
pub array_texture: Handle<Image>,
}
impl MaterialExtension for ChunkMaterial {
fn fragment_shader() -> ShaderRef {
"shaders/world/chunk.wgsl".into()
}
}

View File

@@ -0,0 +1 @@
pub mod chunk_material;