Compare commits
No commits in common. "multiplayer" and "main" have entirely different histories.
multiplaye
...
main
|
@ -42,9 +42,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "allocator-api2"
|
||||
version = "0.2.20"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9"
|
||||
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
|
||||
|
||||
[[package]]
|
||||
name = "alsa"
|
||||
|
@ -106,9 +106,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.18"
|
||||
version = "0.6.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
|
||||
checksum = "23a1e53f0f5d86382dafe1cf314783b2044280f406e7e1506368220ad11b1338"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
|
@ -155,9 +155,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.93"
|
||||
version = "1.0.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
|
||||
checksum = "74f37166d7d48a0284b99dd824694c26119c700b53bf0d1540cdb147dbdaaf13"
|
||||
|
||||
[[package]]
|
||||
name = "arrayref"
|
||||
|
@ -219,23 +219,23 @@ dependencies = [
|
|||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-set"
|
||||
version = "0.8.0"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3"
|
||||
checksum = "f0481a0e032742109b1133a095184ee93d88f3dc9e0d28a5d033dc77a073f44f"
|
||||
dependencies = [
|
||||
"bit-vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit-vec"
|
||||
version = "0.8.0"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7"
|
||||
checksum = "d2c54ff287cfc0a34f38a6b832ea1bd8e448a330b3e40a50859e6488bee07f22"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
|
@ -287,7 +287,7 @@ checksum = "bcfcc3cd946cb52f0bbfdbbcfa2f4e24f75ebb6c0e1002f7c25904fada18b9ec"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -324,9 +324,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.1"
|
||||
version = "1.1.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47"
|
||||
checksum = "67b9470d453346108f93a59222a9a1a5724db32d0a4727b7ab7ace4b4d822dc9"
|
||||
dependencies = [
|
||||
"jobserver",
|
||||
"libc",
|
||||
|
@ -385,9 +385,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.21"
|
||||
version = "4.5.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f"
|
||||
checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
|
@ -395,9 +395,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.21"
|
||||
version = "4.5.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec"
|
||||
checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
|
@ -414,14 +414,14 @@ dependencies = [
|
|||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.3"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7"
|
||||
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
|
||||
|
||||
[[package]]
|
||||
name = "cocoa"
|
||||
|
@ -432,7 +432,7 @@ dependencies = [
|
|||
"bitflags 1.3.2",
|
||||
"block",
|
||||
"cocoa-foundation",
|
||||
"core-foundation 0.9.4",
|
||||
"core-foundation",
|
||||
"core-graphics",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
|
@ -447,7 +447,7 @@ checksum = "8c6234cbb2e4c785b456c0644748b1ac416dd045799740356f8363dfe00c93f7"
|
|||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"block",
|
||||
"core-foundation 0.9.4",
|
||||
"core-foundation",
|
||||
"core-graphics-types",
|
||||
"libc",
|
||||
"objc",
|
||||
|
@ -469,6 +469,37 @@ version = "1.0.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
|
||||
|
||||
[[package]]
|
||||
name = "com"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e17887fd17353b65b1b2ef1c526c83e26cd72e74f598a8dc1bee13a48f3d9f6"
|
||||
dependencies = [
|
||||
"com_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "com_macros"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d375883580a668c7481ea6631fc1a8863e33cc335bf56bfad8d7e6d4b04b13a5"
|
||||
dependencies = [
|
||||
"com_macros_support",
|
||||
"proc-macro2",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "com_macros_support"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad899a1087a9296d5644792d7cb72b8e34c1bec8e7d4fbc002230169a6e8710c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "combine"
|
||||
version = "4.6.7"
|
||||
|
@ -498,16 +529,6 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation-sys"
|
||||
version = "0.8.7"
|
||||
|
@ -521,7 +542,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"core-foundation 0.9.4",
|
||||
"core-foundation",
|
||||
"core-graphics-types",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
|
@ -534,7 +555,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"core-foundation 0.9.4",
|
||||
"core-foundation",
|
||||
"libc",
|
||||
]
|
||||
|
||||
|
@ -593,6 +614,17 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991"
|
||||
|
||||
[[package]]
|
||||
name = "d3d12"
|
||||
version = "22.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bdbd1f579714e3c809ebd822c81ef148b1ceaeb3d535352afc73fd0c4c6a0017"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"libloading",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dasp_sample"
|
||||
version = "0.11.0"
|
||||
|
@ -678,12 +710,6 @@ dependencies = [
|
|||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types"
|
||||
version = "0.5.0"
|
||||
|
@ -702,7 +728,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -732,40 +758,6 @@ dependencies = [
|
|||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gilrs"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbb2c998745a3c1ac90f64f4f7b3a54219fd3612d7705e7798212935641ed18f"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"gilrs-core",
|
||||
"log",
|
||||
"uuid",
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gilrs-core"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "495af945e45efd6386227613cd9fb7bd7c43d3c095040e30c5304c489e6abed5"
|
||||
dependencies = [
|
||||
"core-foundation 0.10.0",
|
||||
"inotify",
|
||||
"io-kit-sys",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"libudev-sys",
|
||||
"log",
|
||||
"nix",
|
||||
"uuid",
|
||||
"vec_map",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
"windows 0.58.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gl_generator"
|
||||
version = "0.14.0"
|
||||
|
@ -785,9 +777,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
|||
|
||||
[[package]]
|
||||
name = "glow"
|
||||
version = "0.14.2"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d51fa363f025f5c111e03f13eda21162faeacb6911fe8caa0c0349f9cf0c4483"
|
||||
checksum = "bd348e04c43b32574f2de31c8bb397d96c9fcfa1371bd4ca6d8bdc464ab121b1"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"slotmap",
|
||||
|
@ -825,14 +817,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "gpu-allocator"
|
||||
version = "0.27.0"
|
||||
version = "0.26.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c151a2a5ef800297b4e79efa4f4bec035c5f51d5ae587287c9b952bdf734cacd"
|
||||
checksum = "fdd4240fc91d3433d5e5b0fc5b67672d771850dc19bbee03c1381e19322803d7"
|
||||
dependencies = [
|
||||
"log",
|
||||
"presser",
|
||||
"thiserror",
|
||||
"windows 0.58.0",
|
||||
"winapi",
|
||||
"windows 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -867,9 +860,24 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.15.1"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3"
|
||||
checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
|
||||
|
||||
[[package]]
|
||||
name = "hassle-rs"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af2a7e73e1f34c48da31fb668a907f250794837e08faa144fd24f0b8b741e890"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"com",
|
||||
"libc",
|
||||
"libloading",
|
||||
"thiserror",
|
||||
"widestring",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
|
@ -926,7 +934,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "imgui-wgpu"
|
||||
version = "0.25.0"
|
||||
source = "git+https://github.com/SupernaviX/imgui-wgpu-rs?rev=5bb8673#5bb8673e256b6b5ad497a3baa2dc151545025f12"
|
||||
source = "git+https://github.com/Yatekii/imgui-wgpu-rs?rev=2edd348#2edd348a0fc11e9e72f19060c34a6e45c760b116"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"imgui",
|
||||
|
@ -952,37 +960,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.15.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inotify"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"inotify-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inotify-sys"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-kit-sys"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "617ee6cf8e3f66f3b4ea67a4058564628cde41901316e19f559e14c7c72c5e7b"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"mach2",
|
||||
"hashbrown 0.15.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1068,9 +1046,9 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.162"
|
||||
version = "0.2.161"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398"
|
||||
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
|
@ -1093,16 +1071,6 @@ dependencies = [
|
|||
"redox_syscall 0.5.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libudev-sys"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.14"
|
||||
|
@ -1193,9 +1161,9 @@ checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff"
|
|||
|
||||
[[package]]
|
||||
name = "naga"
|
||||
version = "23.0.0"
|
||||
version = "22.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d5941e45a15b53aad4375eedf02033adb7a28931eedc31117faffa52e6a857e"
|
||||
checksum = "8bd5a652b6faf21496f2cfd88fc49989c8db0825d1f6746b1a71a6ede24a63ad"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bit-set",
|
||||
|
@ -1221,7 +1189,7 @@ dependencies = [
|
|||
"ascii",
|
||||
"block",
|
||||
"cocoa",
|
||||
"core-foundation 0.9.4",
|
||||
"core-foundation",
|
||||
"dirs-next",
|
||||
"objc",
|
||||
"objc-foundation",
|
||||
|
@ -1288,18 +1256,6 @@ dependencies = [
|
|||
"jni-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.29.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"cfg-if",
|
||||
"cfg_aliases 0.2.1",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
|
@ -1327,7 +1283,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1366,7 +1322,7 @@ dependencies = [
|
|||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1700,7 +1656,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1717,9 +1673,9 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
|
|||
|
||||
[[package]]
|
||||
name = "polling"
|
||||
version = "3.7.4"
|
||||
version = "3.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a604568c3202727d1507653cb121dbd627a58684eb09a820fd746bee38b4442f"
|
||||
checksum = "cc2790cd301dec6cd3b7a025e4815cf825724a51c98dccfe6a3e55f05ffb6511"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"concurrent-queue",
|
||||
|
@ -1863,9 +1819,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.9"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||
checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
|
@ -1925,9 +1881,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.40"
|
||||
version = "0.38.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0"
|
||||
checksum = "aa260229e6538e52293eeb577aabd09945a09d6d9cc0fc550ed7529056c2e32a"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"errno",
|
||||
|
@ -1978,22 +1934,22 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.215"
|
||||
version = "1.0.214"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
|
||||
checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.215"
|
||||
version = "1.0.214"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
|
||||
checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2012,7 +1968,6 @@ dependencies = [
|
|||
"cc",
|
||||
"clap",
|
||||
"cpal",
|
||||
"gilrs",
|
||||
"imgui",
|
||||
"imgui-wgpu",
|
||||
"imgui-winit-support",
|
||||
|
@ -2025,7 +1980,6 @@ dependencies = [
|
|||
"rubato",
|
||||
"thread-priority",
|
||||
"wgpu",
|
||||
"windows 0.58.0",
|
||||
"winit",
|
||||
]
|
||||
|
||||
|
@ -2120,6 +2074,17 @@ version = "0.11.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.87"
|
||||
|
@ -2142,22 +2107,22 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.69"
|
||||
version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||
checksum = "5d171f59dbaa811dbbb1aee1e73db92ec2b122911a48e1390dfe327a821ddede"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.69"
|
||||
version = "1.0.66"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||
checksum = "b08be0f17bd307950653ce45db00cd31200d82b624b36e181337d9c7d92765b5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2278,18 +2243,6 @@ version = "0.2.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a"
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
|
@ -2344,7 +2297,7 @@ dependencies = [
|
|||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
|
@ -2378,7 +2331,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
@ -2530,9 +2483,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wgpu"
|
||||
version = "23.0.0"
|
||||
version = "22.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76ab52f2d3d18b70d5ab8dd270a1cff3ebe6dbe4a7d13c1cc2557138a9777fdc"
|
||||
checksum = "e1d1c4ba43f80542cf63a0a6ed3134629ae73e8ab51e4b765a67f3aa062eb433"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"cfg_aliases 0.1.1",
|
||||
|
@ -2555,9 +2508,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wgpu-core"
|
||||
version = "23.0.0"
|
||||
version = "22.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e0c68e7b6322a03ee5b83fcd92caeac5c2a932f6457818179f4652ad2a9c065"
|
||||
checksum = "0348c840d1051b8e86c3bcd31206080c5e71e5933dabd79be1ce732b0b2f089a"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bit-vec",
|
||||
|
@ -2580,9 +2533,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "wgpu-hal"
|
||||
version = "23.0.0"
|
||||
version = "22.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de6e7266b869de56c7e3ed72a954899f71d14fec6cc81c102b7530b92947601b"
|
||||
checksum = "f6bbf4b4de8b2a83c0401d9e5ae0080a2792055f25859a02bf9be97952bbed4f"
|
||||
dependencies = [
|
||||
"android_system_properties",
|
||||
"arrayvec",
|
||||
|
@ -2590,14 +2543,15 @@ dependencies = [
|
|||
"bit-set",
|
||||
"bitflags 2.6.0",
|
||||
"block",
|
||||
"bytemuck",
|
||||
"cfg_aliases 0.1.1",
|
||||
"core-graphics-types",
|
||||
"d3d12",
|
||||
"glow",
|
||||
"glutin_wgl_sys",
|
||||
"gpu-alloc",
|
||||
"gpu-allocator",
|
||||
"gpu-descriptor",
|
||||
"hassle-rs",
|
||||
"js-sys",
|
||||
"khronos-egl",
|
||||
"libc",
|
||||
|
@ -2619,15 +2573,14 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
"wgpu-types",
|
||||
"windows 0.58.0",
|
||||
"windows-core 0.58.0",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wgpu-types"
|
||||
version = "23.0.0"
|
||||
version = "22.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "610f6ff27778148c31093f3b03abc4840f9636d58d597ca2f5977433acfe0068"
|
||||
checksum = "bc9d91f0e2c4b51434dfa6db77846f2793149d8e73f800fa2e41f52b8eac3c5d"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"js-sys",
|
||||
|
@ -2646,6 +2599,12 @@ dependencies = [
|
|||
"rustix",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "widestring"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
|
@ -2677,6 +2636,16 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
|
||||
dependencies = [
|
||||
"windows-core 0.52.0",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.54.0"
|
||||
|
@ -2688,12 +2657,11 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.58.0"
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6"
|
||||
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
|
||||
dependencies = [
|
||||
"windows-core 0.58.0",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
|
@ -2703,45 +2671,10 @@ version = "0.54.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65"
|
||||
dependencies = [
|
||||
"windows-result 0.1.2",
|
||||
"windows-result",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.58.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-result 0.2.0",
|
||||
"windows-strings",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.58.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.58.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.1.2"
|
||||
|
@ -2751,25 +2684,6 @@ dependencies = [
|
|||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-strings"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10"
|
||||
dependencies = [
|
||||
"windows-result 0.2.0",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.45.0"
|
||||
|
@ -2990,7 +2904,7 @@ dependencies = [
|
|||
"calloop",
|
||||
"cfg_aliases 0.2.1",
|
||||
"concurrent-queue",
|
||||
"core-foundation 0.9.4",
|
||||
"core-foundation",
|
||||
"core-graphics",
|
||||
"cursor-icon",
|
||||
"dpi",
|
||||
|
@ -3095,9 +3009,9 @@ checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56"
|
|||
|
||||
[[package]]
|
||||
name = "xml-rs"
|
||||
version = "0.8.23"
|
||||
version = "0.8.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af310deaae937e48a26602b730250b4949e125f468f11e6990be3e5304ddd96f"
|
||||
checksum = "af4e2e2f7cba5a093896c1e150fbfe177d1883e7448200efb81d40b9d339ef26"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
|
@ -3116,5 +3030,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
|
|
@ -9,9 +9,8 @@ bitflags = "2"
|
|||
bytemuck = { version = "1", features = ["derive"] }
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
cpal = "0.15"
|
||||
gilrs = "0.11"
|
||||
imgui = { version = "0.12", features = ["tables-api"] }
|
||||
imgui-wgpu = { git = "https://github.com/SupernaviX/imgui-wgpu-rs", rev = "5bb8673" }
|
||||
imgui-wgpu = { git = "https://github.com/Yatekii/imgui-wgpu-rs", rev = "2edd348" }
|
||||
imgui-winit-support = "0.13"
|
||||
itertools = "0.13"
|
||||
native-dialog = "0.7"
|
||||
|
@ -21,12 +20,9 @@ pollster = "0.4"
|
|||
rtrb = "0.3"
|
||||
rubato = "0.16"
|
||||
thread-priority = "1"
|
||||
wgpu = "23.0"
|
||||
wgpu = "22.1"
|
||||
winit = "0.30"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows = { version = "0.58", features = ["Win32_System_Threading"] }
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1"
|
||||
|
||||
|
|
4
build.rs
4
build.rs
|
@ -5,10 +5,8 @@ fn main() {
|
|||
cc::Build::new()
|
||||
.include(Path::new("shrooms-vb-core/core"))
|
||||
.opt_level(2)
|
||||
.flag_if_supported("-flto")
|
||||
.flag_if_supported("-fno-strict-aliasing")
|
||||
.define("VB_LITTLE_ENDIAN", None)
|
||||
.define("VB_SIGNED_PROPAGATE", None)
|
||||
.define("VB_DIV_GENERIC", None)
|
||||
.file(Path::new("shrooms-vb-core/core/vb.c"))
|
||||
.compile("vb");
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit f45636a491a50c5847b92a51912e6e19f21af98f
|
||||
Subproject commit ae22c95dbee3d0b338168bfdf98143e6eddc6c70
|
101
src/app.rs
101
src/app.rs
|
@ -1,8 +1,10 @@
|
|||
use std::{collections::HashMap, fmt::Debug, thread};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::Debug,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
|
||||
use game::GameWindow;
|
||||
use gilrs::{EventType, Gilrs};
|
||||
use input::InputWindow;
|
||||
use winit::{
|
||||
application::ApplicationHandler,
|
||||
event::{Event, WindowEvent},
|
||||
|
@ -11,9 +13,9 @@ use winit::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
controller::ControllerManager,
|
||||
emulator::{EmulatorClient, SimId},
|
||||
input::MappingProvider,
|
||||
controller::ControllerState,
|
||||
emulator::{EmulatorClient, EmulatorCommand},
|
||||
input::InputMapper,
|
||||
};
|
||||
|
||||
mod common;
|
||||
|
@ -23,40 +25,34 @@ mod input;
|
|||
pub struct App {
|
||||
windows: HashMap<WindowId, Box<dyn AppWindow>>,
|
||||
client: EmulatorClient,
|
||||
mappings: MappingProvider,
|
||||
controllers: ControllerManager,
|
||||
input_mapper: Arc<RwLock<InputMapper>>,
|
||||
controller: ControllerState,
|
||||
proxy: EventLoopProxy<UserEvent>,
|
||||
player_2_window: Option<WindowId>,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new(client: EmulatorClient, proxy: EventLoopProxy<UserEvent>) -> Self {
|
||||
let mappings = MappingProvider::new();
|
||||
let controllers = ControllerManager::new(client.clone(), &mappings);
|
||||
{
|
||||
let mappings = mappings.clone();
|
||||
let proxy = proxy.clone();
|
||||
thread::spawn(|| process_gamepad_input(mappings, proxy));
|
||||
}
|
||||
let input_mapper = Arc::new(RwLock::new(InputMapper::new()));
|
||||
let controller = ControllerState::new(input_mapper.clone());
|
||||
Self {
|
||||
windows: HashMap::new(),
|
||||
client,
|
||||
mappings,
|
||||
controllers,
|
||||
input_mapper,
|
||||
controller,
|
||||
proxy,
|
||||
player_2_window: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ApplicationHandler<UserEvent> for App {
|
||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let window = GameWindow::new(
|
||||
let mut window = GameWindow::new(
|
||||
event_loop,
|
||||
SimId::Player1,
|
||||
self.client.clone(),
|
||||
self.input_mapper.clone(),
|
||||
self.proxy.clone(),
|
||||
);
|
||||
window.init();
|
||||
self.windows.insert(window.id(), Box::new(window));
|
||||
}
|
||||
|
||||
|
@ -67,7 +63,10 @@ impl ApplicationHandler<UserEvent> for App {
|
|||
event: WindowEvent,
|
||||
) {
|
||||
if let WindowEvent::KeyboardInput { event, .. } = &event {
|
||||
self.controllers.handle_key_event(event);
|
||||
if self.controller.key_event(event) {
|
||||
self.client
|
||||
.send_command(EmulatorCommand::SetKeys(self.controller.pressed()));
|
||||
}
|
||||
}
|
||||
let Some(window) = self.windows.get_mut(&window_id) else {
|
||||
return;
|
||||
|
@ -75,35 +74,15 @@ impl ApplicationHandler<UserEvent> for App {
|
|||
window.handle_event(event_loop, &Event::WindowEvent { window_id, event });
|
||||
}
|
||||
|
||||
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: UserEvent) {
|
||||
fn user_event(&mut self, _event_loop: &ActiveEventLoop, event: UserEvent) {
|
||||
match event {
|
||||
UserEvent::OpenInputWindow => {
|
||||
let window =
|
||||
InputWindow::new(event_loop, self.mappings.clone(), self.proxy.clone());
|
||||
self.windows.insert(window.id(), Box::new(window));
|
||||
UserEvent::OpenWindow(mut window) => {
|
||||
window.init();
|
||||
self.windows.insert(window.id(), window);
|
||||
}
|
||||
UserEvent::OpenPlayer2Window => {
|
||||
if self.player_2_window.is_some() {
|
||||
return;
|
||||
}
|
||||
let window = GameWindow::new(
|
||||
event_loop,
|
||||
SimId::Player2,
|
||||
self.client.clone(),
|
||||
self.proxy.clone(),
|
||||
);
|
||||
self.player_2_window = Some(window.id());
|
||||
self.windows.insert(window.id(), Box::new(window));
|
||||
}
|
||||
UserEvent::Close(window_id) => {
|
||||
if self.player_2_window == Some(window_id) {
|
||||
self.player_2_window.take();
|
||||
}
|
||||
UserEvent::CloseWindow(window_id) => {
|
||||
self.windows.remove(&window_id);
|
||||
}
|
||||
UserEvent::GamepadEvent(event) => {
|
||||
self.controllers.handle_gamepad_event(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,32 +112,20 @@ impl ApplicationHandler<UserEvent> for App {
|
|||
|
||||
pub trait AppWindow {
|
||||
fn id(&self) -> WindowId;
|
||||
fn init(&mut self);
|
||||
fn handle_event(&mut self, event_loop: &ActiveEventLoop, event: &Event<UserEvent>);
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum UserEvent {
|
||||
OpenInputWindow,
|
||||
OpenPlayer2Window,
|
||||
Close(WindowId),
|
||||
GamepadEvent(gilrs::Event),
|
||||
OpenWindow(Box<dyn AppWindow>),
|
||||
CloseWindow(WindowId),
|
||||
}
|
||||
|
||||
fn process_gamepad_input(mappings: MappingProvider, proxy: EventLoopProxy<UserEvent>) {
|
||||
let Ok(mut gilrs) = Gilrs::new() else {
|
||||
eprintln!("could not connect gamepad listener");
|
||||
return;
|
||||
};
|
||||
while let Some(event) = gilrs.next_event_blocking(None) {
|
||||
if event.event == EventType::Connected {
|
||||
let Some(gamepad) = gilrs.connected_gamepad(event.id) else {
|
||||
continue;
|
||||
};
|
||||
mappings.map_gamepad(SimId::Player1, &gamepad);
|
||||
}
|
||||
if proxy.send_event(UserEvent::GamepadEvent(event)).is_err() {
|
||||
// main thread has closed! we done
|
||||
return;
|
||||
impl Debug for UserEvent {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::OpenWindow(window) => f.debug_tuple("OpenWindow").field(&window.id()).finish(),
|
||||
Self::CloseWindow(window_id) => f.debug_tuple("CloseWindow").field(window_id).finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
104
src/app/game.rs
104
src/app/game.rs
|
@ -1,4 +1,7 @@
|
|||
use std::time::Instant;
|
||||
use std::{
|
||||
sync::{Arc, RwLock},
|
||||
time::Instant,
|
||||
};
|
||||
use wgpu::util::DeviceExt as _;
|
||||
use winit::{
|
||||
dpi::LogicalSize,
|
||||
|
@ -8,22 +11,24 @@ use winit::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
emulator::{EmulatorClient, EmulatorCommand, SimId},
|
||||
graphics::TextureSink,
|
||||
emulator::{EmulatorClient, EmulatorCommand},
|
||||
input::InputMapper,
|
||||
renderer::GameRenderer,
|
||||
};
|
||||
|
||||
use super::{
|
||||
common::{ImguiState, WindowState, WindowStateBuilder},
|
||||
input::InputWindow,
|
||||
AppWindow, UserEvent,
|
||||
};
|
||||
|
||||
pub struct GameWindow {
|
||||
window: WindowState,
|
||||
imgui: ImguiState,
|
||||
imgui: Option<ImguiState>,
|
||||
pipeline: wgpu::RenderPipeline,
|
||||
bind_group: wgpu::BindGroup,
|
||||
sim_id: SimId,
|
||||
client: EmulatorClient,
|
||||
input_mapper: Arc<RwLock<InputMapper>>,
|
||||
proxy: EventLoopProxy<UserEvent>,
|
||||
paused_due_to_minimize: bool,
|
||||
}
|
||||
|
@ -31,23 +36,22 @@ pub struct GameWindow {
|
|||
impl GameWindow {
|
||||
pub fn new(
|
||||
event_loop: &ActiveEventLoop,
|
||||
sim_id: SimId,
|
||||
client: EmulatorClient,
|
||||
input_mapper: Arc<RwLock<InputMapper>>,
|
||||
proxy: EventLoopProxy<UserEvent>,
|
||||
) -> Self {
|
||||
let title = if sim_id == SimId::Player2 {
|
||||
"Shrooms VB (Player 2)"
|
||||
} else {
|
||||
"Shrooms VB"
|
||||
};
|
||||
let window = WindowStateBuilder::new(event_loop)
|
||||
.with_title(title)
|
||||
.with_title("Shrooms VB")
|
||||
.with_inner_size(LogicalSize::new(384, 244))
|
||||
.build();
|
||||
let device = &window.device;
|
||||
|
||||
let (sink, texture_view) = TextureSink::new(device, window.queue.clone());
|
||||
client.send_command(EmulatorCommand::SetRenderer(sim_id, sink));
|
||||
let eyes = Arc::new(GameRenderer::create_texture(device, "eye"));
|
||||
client.send_command(EmulatorCommand::SetRenderer(GameRenderer {
|
||||
queue: window.queue.clone(),
|
||||
eyes: eyes.clone(),
|
||||
}));
|
||||
let eyes = eyes.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor::default());
|
||||
let colors = Colors {
|
||||
left: [1.0, 0.0, 0.0, 1.0],
|
||||
|
@ -96,7 +100,7 @@ impl GameWindow {
|
|||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::TextureView(&texture_view),
|
||||
resource: wgpu::BindingResource::TextureView(&eyes),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
|
@ -121,13 +125,13 @@ impl GameWindow {
|
|||
layout: Some(&render_pipeline_layout),
|
||||
vertex: wgpu::VertexState {
|
||||
module: &shader,
|
||||
entry_point: Some("vs_main"),
|
||||
entry_point: "vs_main",
|
||||
buffers: &[],
|
||||
compilation_options: wgpu::PipelineCompilationOptions::default(),
|
||||
},
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
module: &shader,
|
||||
entry_point: Some("fs_main"),
|
||||
entry_point: "fs_main",
|
||||
targets: &[Some(wgpu::ColorTargetState {
|
||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||
blend: Some(wgpu::BlendState::REPLACE),
|
||||
|
@ -154,15 +158,13 @@ impl GameWindow {
|
|||
cache: None,
|
||||
});
|
||||
|
||||
let imgui = ImguiState::new(&window);
|
||||
|
||||
Self {
|
||||
window,
|
||||
imgui,
|
||||
imgui: None,
|
||||
pipeline: render_pipeline,
|
||||
bind_group,
|
||||
sim_id,
|
||||
client,
|
||||
input_mapper,
|
||||
proxy,
|
||||
paused_due_to_minimize: false,
|
||||
}
|
||||
|
@ -170,7 +172,7 @@ impl GameWindow {
|
|||
|
||||
fn draw(&mut self, event_loop: &ActiveEventLoop) {
|
||||
let window = &mut self.window;
|
||||
let imgui = &mut self.imgui;
|
||||
let imgui = self.imgui.as_mut().unwrap();
|
||||
let mut context = imgui.context.lock().unwrap();
|
||||
let mut new_size = None;
|
||||
|
||||
|
@ -202,8 +204,7 @@ impl GameWindow {
|
|||
.show_open_single_file()
|
||||
.unwrap();
|
||||
if let Some(path) = rom {
|
||||
self.client
|
||||
.send_command(EmulatorCommand::LoadGame(self.sim_id, path));
|
||||
self.client.send_command(EmulatorCommand::LoadGame(path));
|
||||
}
|
||||
}
|
||||
if ui.menu_item("Quit") {
|
||||
|
@ -211,8 +212,8 @@ impl GameWindow {
|
|||
}
|
||||
});
|
||||
ui.menu("Emulation", || {
|
||||
let has_game = self.client.has_game(self.sim_id);
|
||||
if self.client.is_running(self.sim_id) {
|
||||
let has_game = self.client.has_game();
|
||||
if self.client.is_running() {
|
||||
if ui.menu_item_config("Pause").enabled(has_game).build() {
|
||||
self.client.send_command(EmulatorCommand::Pause);
|
||||
}
|
||||
|
@ -220,8 +221,7 @@ impl GameWindow {
|
|||
self.client.send_command(EmulatorCommand::Resume);
|
||||
}
|
||||
if ui.menu_item_config("Reset").enabled(has_game).build() {
|
||||
self.client
|
||||
.send_command(EmulatorCommand::Reset(self.sim_id));
|
||||
self.client.send_command(EmulatorCommand::Reset);
|
||||
}
|
||||
});
|
||||
ui.menu("Video", || {
|
||||
|
@ -240,26 +240,14 @@ impl GameWindow {
|
|||
});
|
||||
ui.menu("Input", || {
|
||||
if ui.menu_item("Bind Inputs") {
|
||||
self.proxy.send_event(UserEvent::OpenInputWindow).unwrap();
|
||||
}
|
||||
});
|
||||
ui.menu("Multiplayer", || {
|
||||
if self.sim_id == SimId::Player1
|
||||
&& !self.client.has_player_2()
|
||||
&& ui.menu_item("Open Player 2")
|
||||
{
|
||||
self.client
|
||||
.send_command(EmulatorCommand::StartSecondSim(None));
|
||||
self.proxy.send_event(UserEvent::OpenPlayer2Window).unwrap();
|
||||
}
|
||||
if self.client.has_player_2() {
|
||||
let linked = self.client.are_sims_linked();
|
||||
if linked && ui.menu_item("Unlink") {
|
||||
self.client.send_command(EmulatorCommand::Unlink);
|
||||
}
|
||||
if !linked && ui.menu_item("Link") {
|
||||
self.client.send_command(EmulatorCommand::Link);
|
||||
}
|
||||
let input_window = Box::new(InputWindow::new(
|
||||
event_loop,
|
||||
self.input_mapper.clone(),
|
||||
self.proxy.clone(),
|
||||
));
|
||||
self.proxy
|
||||
.send_event(UserEvent::OpenWindow(input_window))
|
||||
.unwrap();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -333,13 +321,18 @@ impl AppWindow for GameWindow {
|
|||
self.window.window.id()
|
||||
}
|
||||
|
||||
fn init(&mut self) {
|
||||
self.imgui = Some(ImguiState::new(&self.window));
|
||||
self.window.window.request_redraw();
|
||||
}
|
||||
|
||||
fn handle_event(&mut self, event_loop: &ActiveEventLoop, event: &Event<UserEvent>) {
|
||||
match event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::Resized(size) => {
|
||||
self.window.handle_resize(size);
|
||||
if self.window.minimized {
|
||||
if self.client.is_running(self.sim_id) {
|
||||
if self.client.is_running() {
|
||||
self.client.send_command(EmulatorCommand::Pause);
|
||||
self.paused_due_to_minimize = true;
|
||||
}
|
||||
|
@ -348,14 +341,7 @@ impl AppWindow for GameWindow {
|
|||
self.paused_due_to_minimize = false;
|
||||
}
|
||||
}
|
||||
WindowEvent::CloseRequested => {
|
||||
if self.sim_id == SimId::Player2 {
|
||||
self.client.send_command(EmulatorCommand::StopSecondSim);
|
||||
self.proxy.send_event(UserEvent::Close(self.id())).unwrap();
|
||||
} else {
|
||||
event_loop.exit();
|
||||
}
|
||||
}
|
||||
WindowEvent::CloseRequested => event_loop.exit(),
|
||||
WindowEvent::RedrawRequested => self.draw(event_loop),
|
||||
_ => (),
|
||||
},
|
||||
|
@ -365,7 +351,9 @@ impl AppWindow for GameWindow {
|
|||
_ => (),
|
||||
}
|
||||
let window = &self.window;
|
||||
let imgui = &mut self.imgui;
|
||||
let Some(imgui) = self.imgui.as_mut() else {
|
||||
return;
|
||||
};
|
||||
let mut context = imgui.context.lock().unwrap();
|
||||
imgui
|
||||
.platform
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
use std::time::Instant;
|
||||
use std::{
|
||||
sync::{Arc, RwLock},
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use winit::{
|
||||
dpi::LogicalSize,
|
||||
event::{Event, KeyEvent, WindowEvent},
|
||||
event_loop::{ActiveEventLoop, EventLoopProxy},
|
||||
platform::modifier_supplement::KeyEventExtModifierSupplement,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
emulator::{SimId, VBKey},
|
||||
input::MappingProvider,
|
||||
};
|
||||
use crate::{input::InputMapper, shrooms_vb_core::VBKey};
|
||||
|
||||
use super::{
|
||||
common::{ImguiState, UiExt, WindowState, WindowStateBuilder},
|
||||
|
@ -18,10 +19,10 @@ use super::{
|
|||
|
||||
pub struct InputWindow {
|
||||
window: WindowState,
|
||||
imgui: ImguiState,
|
||||
mappings: MappingProvider,
|
||||
imgui: Option<ImguiState>,
|
||||
input_mapper: Arc<RwLock<InputMapper>>,
|
||||
proxy: EventLoopProxy<UserEvent>,
|
||||
now_binding: Option<(SimId, VBKey)>,
|
||||
now_binding: Option<VBKey>,
|
||||
}
|
||||
|
||||
const KEY_NAMES: [(VBKey, &str); 14] = [
|
||||
|
@ -44,18 +45,17 @@ const KEY_NAMES: [(VBKey, &str); 14] = [
|
|||
impl InputWindow {
|
||||
pub fn new(
|
||||
event_loop: &ActiveEventLoop,
|
||||
mappings: MappingProvider,
|
||||
input_mapper: Arc<RwLock<InputMapper>>,
|
||||
proxy: EventLoopProxy<UserEvent>,
|
||||
) -> Self {
|
||||
let window = WindowStateBuilder::new(event_loop)
|
||||
.with_title("Bind Inputs")
|
||||
.with_inner_size(LogicalSize::new(600, 400))
|
||||
.build();
|
||||
let imgui = ImguiState::new(&window);
|
||||
Self {
|
||||
window,
|
||||
imgui,
|
||||
mappings,
|
||||
imgui: None,
|
||||
input_mapper,
|
||||
now_binding: None,
|
||||
proxy,
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ impl InputWindow {
|
|||
|
||||
fn draw(&mut self) {
|
||||
let window = &mut self.window;
|
||||
let imgui = &mut self.imgui;
|
||||
let imgui = self.imgui.as_mut().unwrap();
|
||||
let mut context = imgui.context.lock().unwrap();
|
||||
|
||||
let now = Instant::now();
|
||||
|
@ -85,12 +85,11 @@ impl InputWindow {
|
|||
.expect("Failed to prepare frame");
|
||||
let ui = context.new_frame();
|
||||
|
||||
let mut render_key_bindings = |sim_id: SimId| {
|
||||
let mappings = self.mappings.for_sim(sim_id);
|
||||
let mut render_key_bindings = || {
|
||||
if let Some(table) = ui.begin_table("controls", 2) {
|
||||
let binding_names = {
|
||||
let mapping = mappings.read().unwrap();
|
||||
mapping.keyboard_mapping_names()
|
||||
let mapper = self.input_mapper.read().unwrap();
|
||||
mapper.binding_names()
|
||||
};
|
||||
ui.table_next_row();
|
||||
|
||||
|
@ -101,20 +100,20 @@ impl InputWindow {
|
|||
ui.group(|| {
|
||||
ui.right_align_text(name, space * 0.20);
|
||||
ui.same_line();
|
||||
let label_text = if self.now_binding == Some((sim_id, key)) {
|
||||
let label_text = if self.now_binding == Some(key) {
|
||||
"Press any input"
|
||||
} else {
|
||||
binding.unwrap_or("")
|
||||
};
|
||||
let label = format!("{}##{}", label_text, name);
|
||||
if ui.button_with_size(label, [space * 0.60, 0.0]) {
|
||||
self.now_binding = Some((sim_id, key));
|
||||
self.now_binding = Some(key);
|
||||
}
|
||||
});
|
||||
ui.same_line();
|
||||
if ui.button(format!("Clear##{name}")) {
|
||||
let mut mapping = mappings.write().unwrap();
|
||||
mapping.clear_keyboard_mappings(key);
|
||||
let mut mapper = self.input_mapper.write().unwrap();
|
||||
mapper.clear_binding(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,11 +124,7 @@ impl InputWindow {
|
|||
if let Some(window) = ui.fullscreen_window() {
|
||||
if let Some(tabs) = ui.tab_bar("tabs") {
|
||||
if let Some(tab) = ui.tab_item("Player 1") {
|
||||
render_key_bindings(SimId::Player1);
|
||||
tab.end();
|
||||
}
|
||||
if let Some(tab) = ui.tab_item("Player 2") {
|
||||
render_key_bindings(SimId::Player2);
|
||||
render_key_bindings();
|
||||
tab.end();
|
||||
}
|
||||
tabs.end();
|
||||
|
@ -180,11 +175,11 @@ impl InputWindow {
|
|||
if !event.state.is_pressed() {
|
||||
return;
|
||||
}
|
||||
let Some((sim_id, vb)) = self.now_binding.take() else {
|
||||
let Some(vb) = self.now_binding.take() else {
|
||||
return;
|
||||
};
|
||||
let mut mappings = self.mappings.for_sim(sim_id).write().unwrap();
|
||||
mappings.add_keyboard_mapping(vb, event.physical_key);
|
||||
let mut mapper = self.input_mapper.write().unwrap();
|
||||
mapper.bind_key(vb, event.key_without_modifiers());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,13 +188,19 @@ impl AppWindow for InputWindow {
|
|||
self.window.window.id()
|
||||
}
|
||||
|
||||
fn init(&mut self) {
|
||||
self.imgui = Some(ImguiState::new(&self.window));
|
||||
self.window.window.request_redraw();
|
||||
}
|
||||
|
||||
fn handle_event(&mut self, _: &ActiveEventLoop, event: &Event<UserEvent>) {
|
||||
match event {
|
||||
Event::WindowEvent { event, .. } => match event {
|
||||
WindowEvent::Resized(size) => self.window.handle_resize(size),
|
||||
WindowEvent::CloseRequested => {
|
||||
self.proxy.send_event(UserEvent::Close(self.id())).unwrap()
|
||||
}
|
||||
WindowEvent::CloseRequested => self
|
||||
.proxy
|
||||
.send_event(UserEvent::CloseWindow(self.id()))
|
||||
.unwrap(),
|
||||
WindowEvent::KeyboardInput { event, .. } => self.try_bind_key(event),
|
||||
WindowEvent::RedrawRequested => self.draw(),
|
||||
_ => (),
|
||||
|
@ -211,7 +212,9 @@ impl AppWindow for InputWindow {
|
|||
}
|
||||
|
||||
let window = &self.window;
|
||||
let imgui = &mut self.imgui;
|
||||
let Some(imgui) = self.imgui.as_mut() else {
|
||||
return;
|
||||
};
|
||||
let mut context = imgui.context.lock().unwrap();
|
||||
imgui
|
||||
.platform
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||
use itertools::Itertools;
|
||||
|
@ -97,7 +95,7 @@ impl Audio {
|
|||
}
|
||||
|
||||
while self.sample_sink.slots() < self.sampler.output_frames_max() * 2 {
|
||||
std::thread::sleep(Duration::from_micros(500));
|
||||
std::hint::spin_loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,128 +1,50 @@
|
|||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use gilrs::{ev::Code, Event as GamepadEvent, EventType, GamepadId};
|
||||
use winit::{
|
||||
event::{ElementState, KeyEvent},
|
||||
keyboard::PhysicalKey,
|
||||
};
|
||||
use winit::event::{ElementState, KeyEvent};
|
||||
|
||||
use crate::{
|
||||
emulator::{EmulatorClient, EmulatorCommand, SimId, VBKey},
|
||||
input::{InputMapping, MappingProvider},
|
||||
};
|
||||
use crate::{input::InputMapper, shrooms_vb_core::VBKey};
|
||||
|
||||
pub struct Controller {
|
||||
pub sim_id: SimId,
|
||||
state: VBKey,
|
||||
mapping: Arc<RwLock<InputMapping>>,
|
||||
pub struct ControllerState {
|
||||
input_mapper: Arc<RwLock<InputMapper>>,
|
||||
pressed: VBKey,
|
||||
}
|
||||
|
||||
impl Controller {
|
||||
pub fn new(sim_id: SimId, mappings: &MappingProvider) -> Self {
|
||||
impl ControllerState {
|
||||
pub fn new(input_mapper: Arc<RwLock<InputMapper>>) -> Self {
|
||||
Self {
|
||||
sim_id,
|
||||
state: VBKey::SGN,
|
||||
mapping: mappings.for_sim(sim_id).clone(),
|
||||
input_mapper,
|
||||
pressed: VBKey::SGN,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn key_event(&mut self, event: &KeyEvent) -> Option<VBKey> {
|
||||
let keys = self.map_keys(&event.physical_key)?;
|
||||
match event.state {
|
||||
ElementState::Pressed => self.update_state(keys, VBKey::empty()),
|
||||
ElementState::Released => self.update_state(VBKey::empty(), keys),
|
||||
}
|
||||
pub fn pressed(&self) -> VBKey {
|
||||
self.pressed
|
||||
}
|
||||
|
||||
pub fn gamepad_event(&mut self, event: &GamepadEvent) -> Option<VBKey> {
|
||||
let (pressed, released) = match event.event {
|
||||
EventType::ButtonPressed(_, code) => {
|
||||
let mappings = self.map_button(&event.id, &code)?;
|
||||
(mappings, VBKey::empty())
|
||||
}
|
||||
EventType::ButtonReleased(_, code) => {
|
||||
let mappings = self.map_button(&event.id, &code)?;
|
||||
(VBKey::empty(), mappings)
|
||||
}
|
||||
EventType::AxisChanged(_, value, code) => {
|
||||
let (neg, pos) = self.map_axis(&event.id, &code)?;
|
||||
let mut pressed = VBKey::empty();
|
||||
let mut released = VBKey::empty();
|
||||
if value < -0.75 {
|
||||
pressed = pressed.union(neg);
|
||||
}
|
||||
if value > 0.75 {
|
||||
pressed = pressed.union(pos);
|
||||
}
|
||||
if value > -0.65 {
|
||||
released = released.union(neg);
|
||||
}
|
||||
if value < 0.65 {
|
||||
released = released.union(pos);
|
||||
}
|
||||
(pressed, released)
|
||||
}
|
||||
_ => {
|
||||
return None;
|
||||
}
|
||||
pub fn key_event(&mut self, event: &KeyEvent) -> bool {
|
||||
let Some(input) = self.key_event_to_input(event) else {
|
||||
return false;
|
||||
};
|
||||
self.update_state(pressed, released)
|
||||
}
|
||||
|
||||
fn update_state(&mut self, pressed: VBKey, released: VBKey) -> Option<VBKey> {
|
||||
let old_state = self.state;
|
||||
self.state = self.state.union(pressed).difference(released);
|
||||
if self.state != old_state {
|
||||
Some(self.state)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn map_keys(&self, key: &PhysicalKey) -> Option<VBKey> {
|
||||
self.mapping.read().unwrap().map_keyboard(key)
|
||||
}
|
||||
|
||||
fn map_button(&self, id: &GamepadId, code: &Code) -> Option<VBKey> {
|
||||
self.mapping.read().unwrap().map_button(id, code)
|
||||
}
|
||||
|
||||
fn map_axis(&self, id: &GamepadId, code: &Code) -> Option<(VBKey, VBKey)> {
|
||||
self.mapping.read().unwrap().map_axis(id, code)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ControllerManager {
|
||||
client: EmulatorClient,
|
||||
controllers: [Controller; 2],
|
||||
}
|
||||
|
||||
impl ControllerManager {
|
||||
pub fn new(client: EmulatorClient, mappings: &MappingProvider) -> Self {
|
||||
Self {
|
||||
client,
|
||||
controllers: [
|
||||
Controller::new(SimId::Player1, mappings),
|
||||
Controller::new(SimId::Player2, mappings),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_key_event(&mut self, event: &KeyEvent) {
|
||||
for controller in &mut self.controllers {
|
||||
if let Some(pressed) = controller.key_event(event) {
|
||||
self.client
|
||||
.send_command(EmulatorCommand::SetKeys(controller.sim_id, pressed));
|
||||
match event.state {
|
||||
ElementState::Pressed => {
|
||||
if self.pressed.contains(input) {
|
||||
return false;
|
||||
}
|
||||
self.pressed.insert(input);
|
||||
true
|
||||
}
|
||||
ElementState::Released => {
|
||||
if !self.pressed.contains(input) {
|
||||
return false;
|
||||
}
|
||||
self.pressed.remove(input);
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_gamepad_event(&mut self, event: &GamepadEvent) {
|
||||
for controller in &mut self.controllers {
|
||||
if let Some(pressed) = controller.gamepad_event(event) {
|
||||
self.client
|
||||
.send_command(EmulatorCommand::SetKeys(controller.sim_id, pressed));
|
||||
}
|
||||
}
|
||||
fn key_event_to_input(&self, event: &KeyEvent) -> Option<VBKey> {
|
||||
let mapper = self.input_mapper.read().unwrap();
|
||||
mapper.key_event(event)
|
||||
}
|
||||
}
|
||||
|
|
252
src/emulator.rs
252
src/emulator.rs
|
@ -1,9 +1,8 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
sync::{
|
||||
atomic::{AtomicBool, AtomicUsize, Ordering},
|
||||
atomic::{AtomicBool, Ordering},
|
||||
mpsc::{self, RecvError, TryRecvError},
|
||||
Arc,
|
||||
},
|
||||
|
@ -11,36 +10,17 @@ use std::{
|
|||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::{audio::Audio, graphics::TextureSink};
|
||||
use shrooms_vb_core::Sim;
|
||||
pub use shrooms_vb_core::VBKey;
|
||||
|
||||
mod shrooms_vb_core;
|
||||
use crate::{
|
||||
audio::Audio,
|
||||
renderer::GameRenderer,
|
||||
shrooms_vb_core::{CoreVB, VBKey},
|
||||
};
|
||||
|
||||
pub struct EmulatorBuilder {
|
||||
rom: Option<PathBuf>,
|
||||
commands: mpsc::Receiver<EmulatorCommand>,
|
||||
sim_count: Arc<AtomicUsize>,
|
||||
running: Arc<[AtomicBool; 2]>,
|
||||
has_game: Arc<[AtomicBool; 2]>,
|
||||
linked: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||
pub enum SimId {
|
||||
Player1,
|
||||
Player2,
|
||||
}
|
||||
impl SimId {
|
||||
pub const fn values() -> [Self; 2] {
|
||||
[Self::Player1, Self::Player2]
|
||||
}
|
||||
pub const fn to_index(self) -> usize {
|
||||
match self {
|
||||
Self::Player1 => 0,
|
||||
Self::Player2 => 1,
|
||||
}
|
||||
}
|
||||
running: Arc<AtomicBool>,
|
||||
has_game: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl EmulatorBuilder {
|
||||
|
@ -49,17 +29,13 @@ impl EmulatorBuilder {
|
|||
let builder = Self {
|
||||
rom: None,
|
||||
commands,
|
||||
sim_count: Arc::new(AtomicUsize::new(0)),
|
||||
running: Arc::new([AtomicBool::new(false), AtomicBool::new(false)]),
|
||||
has_game: Arc::new([AtomicBool::new(false), AtomicBool::new(false)]),
|
||||
linked: Arc::new(AtomicBool::new(false)),
|
||||
running: Arc::new(AtomicBool::new(false)),
|
||||
has_game: Arc::new(AtomicBool::new(false)),
|
||||
};
|
||||
let client = EmulatorClient {
|
||||
queue,
|
||||
sim_count: builder.sim_count.clone(),
|
||||
running: builder.running.clone(),
|
||||
has_game: builder.has_game.clone(),
|
||||
linked: builder.linked.clone(),
|
||||
};
|
||||
(builder, client)
|
||||
}
|
||||
|
@ -72,148 +48,64 @@ impl EmulatorBuilder {
|
|||
}
|
||||
|
||||
pub fn build(self) -> Result<Emulator> {
|
||||
let mut emulator = Emulator::new(
|
||||
self.commands,
|
||||
self.sim_count,
|
||||
self.running,
|
||||
self.has_game,
|
||||
self.linked,
|
||||
)?;
|
||||
let mut emulator = Emulator::new(self.commands, self.running, self.has_game)?;
|
||||
if let Some(path) = self.rom {
|
||||
emulator.load_rom(SimId::Player1, &path)?;
|
||||
emulator.load_rom(&path)?;
|
||||
}
|
||||
Ok(emulator)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Emulator {
|
||||
sims: Vec<Sim>,
|
||||
sim: CoreVB,
|
||||
audio: Audio,
|
||||
commands: mpsc::Receiver<EmulatorCommand>,
|
||||
sim_count: Arc<AtomicUsize>,
|
||||
running: Arc<[AtomicBool; 2]>,
|
||||
has_game: Arc<[AtomicBool; 2]>,
|
||||
linked: Arc<AtomicBool>,
|
||||
renderers: HashMap<SimId, TextureSink>,
|
||||
renderer: Option<GameRenderer>,
|
||||
running: Arc<AtomicBool>,
|
||||
has_game: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl Emulator {
|
||||
fn new(
|
||||
commands: mpsc::Receiver<EmulatorCommand>,
|
||||
sim_count: Arc<AtomicUsize>,
|
||||
running: Arc<[AtomicBool; 2]>,
|
||||
has_game: Arc<[AtomicBool; 2]>,
|
||||
linked: Arc<AtomicBool>,
|
||||
running: Arc<AtomicBool>,
|
||||
has_game: Arc<AtomicBool>,
|
||||
) -> Result<Self> {
|
||||
Ok(Self {
|
||||
sims: vec![],
|
||||
sim: CoreVB::new(),
|
||||
audio: Audio::init()?,
|
||||
commands,
|
||||
sim_count,
|
||||
renderer: None,
|
||||
running,
|
||||
has_game,
|
||||
linked,
|
||||
renderers: HashMap::new(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn load_rom(&mut self, sim_id: SimId, path: &Path) -> Result<()> {
|
||||
pub fn load_rom(&mut self, path: &Path) -> Result<()> {
|
||||
let bytes = fs::read(path)?;
|
||||
self.reset_sim(sim_id, Some(bytes))?;
|
||||
self.sim.reset();
|
||||
self.sim.load_rom(bytes)?;
|
||||
self.has_game.store(true, Ordering::Release);
|
||||
self.running.store(true, Ordering::Release);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn start_second_sim(&mut self, rom: Option<PathBuf>) -> Result<()> {
|
||||
let bytes = if let Some(path) = rom {
|
||||
Some(fs::read(path)?)
|
||||
} else {
|
||||
self.sims.first().and_then(|s| s.clone_rom())
|
||||
};
|
||||
self.reset_sim(SimId::Player2, bytes)?;
|
||||
self.link_sims();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn reset_sim(&mut self, sim_id: SimId, new_rom: Option<Vec<u8>>) -> Result<()> {
|
||||
let index = sim_id.to_index();
|
||||
while self.sims.len() <= index {
|
||||
self.sims.push(Sim::new());
|
||||
}
|
||||
self.sim_count.store(self.sims.len(), Ordering::Relaxed);
|
||||
let sim = &mut self.sims[index];
|
||||
sim.reset();
|
||||
if let Some(bytes) = new_rom {
|
||||
sim.load_rom(bytes)?;
|
||||
self.has_game[index].store(true, Ordering::Release);
|
||||
}
|
||||
if self.has_game[index].load(Ordering::Acquire) {
|
||||
self.running[index].store(true, Ordering::Release);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn link_sims(&mut self) {
|
||||
let (first, second) = self.sims.split_at_mut(1);
|
||||
let Some(first) = first.first_mut() else {
|
||||
return;
|
||||
};
|
||||
let Some(second) = second.first_mut() else {
|
||||
return;
|
||||
};
|
||||
first.link(second);
|
||||
self.linked.store(true, Ordering::Release);
|
||||
}
|
||||
|
||||
fn unlink_sims(&mut self) {
|
||||
let Some(first) = self.sims.first_mut() else {
|
||||
return;
|
||||
};
|
||||
first.unlink();
|
||||
self.linked.store(false, Ordering::Release);
|
||||
}
|
||||
|
||||
pub fn stop_second_sim(&mut self) {
|
||||
self.renderers.remove(&SimId::Player2);
|
||||
self.sims.truncate(1);
|
||||
self.sim_count.store(self.sims.len(), Ordering::Relaxed);
|
||||
self.running[SimId::Player2.to_index()].store(false, Ordering::Release);
|
||||
self.has_game[SimId::Player2.to_index()].store(false, Ordering::Release);
|
||||
self.linked.store(false, Ordering::Release);
|
||||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
let mut eye_contents = vec![0u8; 384 * 224 * 2];
|
||||
let mut audio_samples = vec![];
|
||||
loop {
|
||||
let p1_running = self.running[SimId::Player1.to_index()].load(Ordering::Acquire);
|
||||
let p2_running = self.running[SimId::Player2.to_index()].load(Ordering::Acquire);
|
||||
let mut idle = p1_running || p2_running;
|
||||
if p1_running && p2_running {
|
||||
Sim::emulate_many(&mut self.sims);
|
||||
} else if p1_running {
|
||||
self.sims[SimId::Player1.to_index()].emulate();
|
||||
} else if p2_running {
|
||||
self.sims[SimId::Player2.to_index()].emulate();
|
||||
let mut idle = true;
|
||||
if self.running.load(Ordering::Acquire) {
|
||||
idle = false;
|
||||
self.sim.emulate_frame();
|
||||
}
|
||||
|
||||
for sim_id in SimId::values() {
|
||||
let Some(renderer) = self.renderers.get_mut(&sim_id) else {
|
||||
continue;
|
||||
};
|
||||
let Some(sim) = self.sims.get_mut(sim_id.to_index()) else {
|
||||
continue;
|
||||
};
|
||||
if sim.read_pixels(&mut eye_contents) {
|
||||
if let Some(renderer) = &mut self.renderer {
|
||||
if self.sim.read_pixels(&mut eye_contents) {
|
||||
idle = false;
|
||||
if renderer.queue_render(&eye_contents).is_err() {
|
||||
self.renderers.remove(&sim_id);
|
||||
}
|
||||
renderer.render(&eye_contents);
|
||||
}
|
||||
}
|
||||
let weight = 1.0 / self.sims.len() as f32;
|
||||
for sim in self.sims.iter_mut() {
|
||||
sim.read_samples(&mut audio_samples, weight);
|
||||
}
|
||||
self.sim.read_samples(&mut audio_samples);
|
||||
if !audio_samples.is_empty() {
|
||||
idle = false;
|
||||
self.audio.update(&audio_samples);
|
||||
|
@ -245,50 +137,28 @@ impl Emulator {
|
|||
|
||||
fn handle_command(&mut self, command: EmulatorCommand) {
|
||||
match command {
|
||||
EmulatorCommand::SetRenderer(sim_id, renderer) => {
|
||||
self.renderers.insert(sim_id, renderer);
|
||||
EmulatorCommand::SetRenderer(renderer) => {
|
||||
self.renderer = Some(renderer);
|
||||
}
|
||||
EmulatorCommand::LoadGame(sim_id, path) => {
|
||||
if let Err(error) = self.load_rom(sim_id, &path) {
|
||||
EmulatorCommand::LoadGame(path) => {
|
||||
if let Err(error) = self.load_rom(&path) {
|
||||
eprintln!("error loading rom: {}", error);
|
||||
}
|
||||
}
|
||||
EmulatorCommand::StartSecondSim(path) => {
|
||||
if let Err(error) = self.start_second_sim(path) {
|
||||
eprintln!("error starting second sim: {}", error);
|
||||
}
|
||||
}
|
||||
EmulatorCommand::StopSecondSim => {
|
||||
self.stop_second_sim();
|
||||
}
|
||||
EmulatorCommand::Pause => {
|
||||
for sim in SimId::values() {
|
||||
self.running[sim.to_index()].store(false, Ordering::Release);
|
||||
}
|
||||
self.running.store(false, Ordering::Release);
|
||||
}
|
||||
EmulatorCommand::Resume => {
|
||||
for sim_id in SimId::values() {
|
||||
let index = sim_id.to_index();
|
||||
if self.has_game[index].load(Ordering::Acquire) {
|
||||
self.running[index].store(true, Ordering::Relaxed);
|
||||
}
|
||||
if self.has_game.load(Ordering::Acquire) {
|
||||
self.running.store(true, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
EmulatorCommand::Link => {
|
||||
self.link_sims();
|
||||
EmulatorCommand::Reset => {
|
||||
self.sim.reset();
|
||||
self.running.store(true, Ordering::Release);
|
||||
}
|
||||
EmulatorCommand::Unlink => {
|
||||
self.unlink_sims();
|
||||
}
|
||||
EmulatorCommand::Reset(sim_id) => {
|
||||
if let Err(error) = self.reset_sim(sim_id, None) {
|
||||
eprintln!("error resetting sim: {}", error);
|
||||
}
|
||||
}
|
||||
EmulatorCommand::SetKeys(sim_id, keys) => {
|
||||
if let Some(sim) = self.sims.get_mut(sim_id.to_index()) {
|
||||
sim.set_keys(keys);
|
||||
}
|
||||
EmulatorCommand::SetKeys(keys) => {
|
||||
self.sim.set_keys(keys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -296,39 +166,27 @@ impl Emulator {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum EmulatorCommand {
|
||||
SetRenderer(SimId, TextureSink),
|
||||
LoadGame(SimId, PathBuf),
|
||||
StartSecondSim(Option<PathBuf>),
|
||||
StopSecondSim,
|
||||
SetRenderer(GameRenderer),
|
||||
LoadGame(PathBuf),
|
||||
Pause,
|
||||
Resume,
|
||||
Link,
|
||||
Unlink,
|
||||
Reset(SimId),
|
||||
SetKeys(SimId, VBKey),
|
||||
Reset,
|
||||
SetKeys(VBKey),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct EmulatorClient {
|
||||
queue: mpsc::Sender<EmulatorCommand>,
|
||||
sim_count: Arc<AtomicUsize>,
|
||||
running: Arc<[AtomicBool; 2]>,
|
||||
has_game: Arc<[AtomicBool; 2]>,
|
||||
linked: Arc<AtomicBool>,
|
||||
running: Arc<AtomicBool>,
|
||||
has_game: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl EmulatorClient {
|
||||
pub fn has_player_2(&self) -> bool {
|
||||
self.sim_count.load(Ordering::Acquire) == 2
|
||||
pub fn is_running(&self) -> bool {
|
||||
self.running.load(Ordering::Acquire)
|
||||
}
|
||||
pub fn is_running(&self, sim_id: SimId) -> bool {
|
||||
self.running[sim_id.to_index()].load(Ordering::Acquire)
|
||||
}
|
||||
pub fn has_game(&self, sim_id: SimId) -> bool {
|
||||
self.has_game[sim_id.to_index()].load(Ordering::Acquire)
|
||||
}
|
||||
pub fn are_sims_linked(&self) -> bool {
|
||||
self.linked.load(Ordering::Acquire)
|
||||
pub fn has_game(&self) -> bool {
|
||||
self.has_game.load(Ordering::Acquire)
|
||||
}
|
||||
pub fn send_command(&self, command: EmulatorCommand) {
|
||||
if let Err(err) = self.queue.send(command) {
|
||||
|
|
143
src/graphics.rs
143
src/graphics.rs
|
@ -1,143 +0,0 @@
|
|||
use std::{
|
||||
sync::{
|
||||
atomic::{AtomicU64, Ordering},
|
||||
mpsc, Arc, Mutex, MutexGuard,
|
||||
},
|
||||
thread,
|
||||
};
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use itertools::Itertools as _;
|
||||
use wgpu::{
|
||||
Device, Extent3d, ImageCopyTexture, ImageDataLayout, Origin3d, Queue, Texture,
|
||||
TextureDescriptor, TextureFormat, TextureUsages, TextureView, TextureViewDescriptor,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TextureSink {
|
||||
buffers: Arc<BufferPool>,
|
||||
sink: mpsc::Sender<u64>,
|
||||
}
|
||||
|
||||
impl TextureSink {
|
||||
pub fn new(device: &Device, queue: Arc<Queue>) -> (Self, TextureView) {
|
||||
let texture = Self::create_texture(device);
|
||||
let view = texture.create_view(&TextureViewDescriptor::default());
|
||||
let buffers = Arc::new(BufferPool::new());
|
||||
let (sink, source) = mpsc::channel();
|
||||
let bufs = buffers.clone();
|
||||
thread::spawn(move || {
|
||||
let mut local_buf = vec![0; 384 * 224 * 2];
|
||||
while let Ok(id) = source.recv() {
|
||||
{
|
||||
let Some(bytes) = bufs.read(id) else {
|
||||
continue;
|
||||
};
|
||||
local_buf.copy_from_slice(bytes.as_slice());
|
||||
}
|
||||
Self::write_texture(&queue, &texture, local_buf.as_slice());
|
||||
}
|
||||
});
|
||||
let sink = Self { buffers, sink };
|
||||
(sink, view)
|
||||
}
|
||||
|
||||
pub fn queue_render(&mut self, bytes: &[u8]) -> Result<()> {
|
||||
let id = {
|
||||
let (mut buf, id) = self.buffers.write()?;
|
||||
buf.copy_from_slice(bytes);
|
||||
id
|
||||
};
|
||||
self.sink.send(id)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_texture(device: &Device) -> Texture {
|
||||
let desc = TextureDescriptor {
|
||||
label: Some("eyes"),
|
||||
size: Extent3d {
|
||||
width: 384,
|
||||
height: 224,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: TextureFormat::Rg8Unorm,
|
||||
usage: TextureUsages::COPY_SRC
|
||||
| TextureUsages::COPY_DST
|
||||
| TextureUsages::TEXTURE_BINDING,
|
||||
view_formats: &[TextureFormat::Rg8Unorm],
|
||||
};
|
||||
device.create_texture(&desc)
|
||||
}
|
||||
|
||||
fn write_texture(queue: &Queue, texture: &Texture, bytes: &[u8]) {
|
||||
let texture = ImageCopyTexture {
|
||||
texture,
|
||||
mip_level: 0,
|
||||
origin: Origin3d::ZERO,
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
};
|
||||
let size = Extent3d {
|
||||
width: 384,
|
||||
height: 224,
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
let data_layout = ImageDataLayout {
|
||||
offset: 0,
|
||||
bytes_per_row: Some(384 * 2),
|
||||
rows_per_image: Some(224),
|
||||
};
|
||||
queue.write_texture(texture, bytes, data_layout, size);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct BufferPool {
|
||||
buffers: [Buffer; 3],
|
||||
}
|
||||
impl BufferPool {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
buffers: std::array::from_fn(|i| Buffer::new(i as u64)),
|
||||
}
|
||||
}
|
||||
|
||||
fn read(&self, id: u64) -> Option<MutexGuard<'_, Vec<u8>>> {
|
||||
let buf = self
|
||||
.buffers
|
||||
.iter()
|
||||
.find(|buf| buf.id.load(Ordering::Acquire) == id)?;
|
||||
buf.data.lock().ok()
|
||||
}
|
||||
|
||||
fn write(&self) -> Result<(MutexGuard<'_, Vec<u8>>, u64)> {
|
||||
let (min, max) = self
|
||||
.buffers
|
||||
.iter()
|
||||
.minmax_by_key(|buf| buf.id.load(Ordering::Acquire))
|
||||
.into_option()
|
||||
.unwrap();
|
||||
let Ok(lock) = min.data.lock() else {
|
||||
bail!("lock was poisoned")
|
||||
};
|
||||
let id = max.id.load(Ordering::Acquire) + 1;
|
||||
min.id.store(id, Ordering::Release);
|
||||
Ok((lock, id))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Buffer {
|
||||
data: Mutex<Vec<u8>>,
|
||||
id: AtomicU64,
|
||||
}
|
||||
impl Buffer {
|
||||
fn new(id: u64) -> Self {
|
||||
Self {
|
||||
data: Mutex::new(vec![0; 384 * 224 * 2]),
|
||||
id: AtomicU64::new(id),
|
||||
}
|
||||
}
|
||||
}
|
202
src/input.rs
202
src/input.rs
|
@ -1,167 +1,71 @@
|
|||
use std::{
|
||||
collections::{hash_map::Entry, HashMap},
|
||||
sync::{Arc, RwLock},
|
||||
use std::collections::HashMap;
|
||||
|
||||
use winit::{
|
||||
event::KeyEvent,
|
||||
keyboard::{Key, NamedKey},
|
||||
platform::modifier_supplement::KeyEventExtModifierSupplement,
|
||||
};
|
||||
|
||||
use gilrs::{ev::Code, Axis, Button, Gamepad, GamepadId};
|
||||
use winit::keyboard::{KeyCode, PhysicalKey};
|
||||
use crate::shrooms_vb_core::VBKey;
|
||||
|
||||
use crate::emulator::{SimId, VBKey};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
||||
struct DeviceId(u16, u16);
|
||||
|
||||
pub struct GamepadMapping {
|
||||
buttons: HashMap<Code, VBKey>,
|
||||
axes: HashMap<Code, (VBKey, VBKey)>,
|
||||
pub struct InputMapper {
|
||||
vb_bindings: HashMap<VBKey, Key>,
|
||||
key_bindings: HashMap<Key, VBKey>,
|
||||
}
|
||||
|
||||
impl GamepadMapping {
|
||||
fn for_gamepad(gamepad: &Gamepad) -> Self {
|
||||
let mut buttons = HashMap::new();
|
||||
let mut default_button = |btn: Button, key: VBKey| {
|
||||
if let Some(code) = gamepad.button_code(btn) {
|
||||
buttons.insert(code, key);
|
||||
}
|
||||
impl InputMapper {
|
||||
pub fn new() -> Self {
|
||||
let mut mapper = Self {
|
||||
vb_bindings: HashMap::new(),
|
||||
key_bindings: HashMap::new(),
|
||||
};
|
||||
default_button(Button::South, VBKey::A);
|
||||
default_button(Button::West, VBKey::B);
|
||||
default_button(Button::RightTrigger, VBKey::RT);
|
||||
default_button(Button::LeftTrigger, VBKey::LT);
|
||||
default_button(Button::Start, VBKey::STA);
|
||||
default_button(Button::Select, VBKey::SEL);
|
||||
|
||||
let mut axes = HashMap::new();
|
||||
let mut default_axis = |axis: Axis, neg: VBKey, pos: VBKey| {
|
||||
if let Some(code) = gamepad.axis_code(axis) {
|
||||
axes.insert(code, (neg, pos));
|
||||
}
|
||||
};
|
||||
default_axis(Axis::LeftStickX, VBKey::LL, VBKey::LR);
|
||||
default_axis(Axis::LeftStickY, VBKey::LD, VBKey::LU);
|
||||
default_axis(Axis::RightStickX, VBKey::RL, VBKey::RR);
|
||||
default_axis(Axis::RightStickY, VBKey::RD, VBKey::RU);
|
||||
default_axis(Axis::DPadX, VBKey::LL, VBKey::LR);
|
||||
default_axis(Axis::DPadY, VBKey::LD, VBKey::LU);
|
||||
|
||||
Self { buttons, axes }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct InputMapping {
|
||||
keys: HashMap<PhysicalKey, VBKey>,
|
||||
gamepads: HashMap<GamepadId, Arc<RwLock<GamepadMapping>>>,
|
||||
}
|
||||
|
||||
impl InputMapping {
|
||||
pub fn map_keyboard(&self, key: &PhysicalKey) -> Option<VBKey> {
|
||||
self.keys.get(key).copied()
|
||||
mapper.bind_key(VBKey::SEL, Key::Character("a".into()));
|
||||
mapper.bind_key(VBKey::STA, Key::Character("s".into()));
|
||||
mapper.bind_key(VBKey::B, Key::Character("d".into()));
|
||||
mapper.bind_key(VBKey::A, Key::Character("f".into()));
|
||||
mapper.bind_key(VBKey::LT, Key::Character("e".into()));
|
||||
mapper.bind_key(VBKey::RT, Key::Character("r".into()));
|
||||
mapper.bind_key(VBKey::RU, Key::Character("i".into()));
|
||||
mapper.bind_key(VBKey::RL, Key::Character("j".into()));
|
||||
mapper.bind_key(VBKey::RD, Key::Character("k".into()));
|
||||
mapper.bind_key(VBKey::RR, Key::Character("l".into()));
|
||||
mapper.bind_key(VBKey::LU, Key::Named(NamedKey::ArrowUp));
|
||||
mapper.bind_key(VBKey::LL, Key::Named(NamedKey::ArrowLeft));
|
||||
mapper.bind_key(VBKey::LD, Key::Named(NamedKey::ArrowDown));
|
||||
mapper.bind_key(VBKey::LR, Key::Named(NamedKey::ArrowRight));
|
||||
mapper
|
||||
}
|
||||
|
||||
pub fn map_button(&self, id: &GamepadId, code: &Code) -> Option<VBKey> {
|
||||
let mappings = self.gamepads.get(id)?.read().unwrap();
|
||||
mappings.buttons.get(code).copied()
|
||||
}
|
||||
|
||||
pub fn map_axis(&self, id: &GamepadId, code: &Code) -> Option<(VBKey, VBKey)> {
|
||||
let mappings = self.gamepads.get(id)?.read().unwrap();
|
||||
mappings.axes.get(code).copied()
|
||||
}
|
||||
|
||||
pub fn add_keyboard_mapping(&mut self, key: VBKey, keyboard_key: PhysicalKey) {
|
||||
let entry = self.keys.entry(keyboard_key).or_insert(VBKey::empty());
|
||||
*entry = entry.union(key);
|
||||
}
|
||||
|
||||
pub fn clear_keyboard_mappings(&mut self, key: VBKey) {
|
||||
self.keys.retain(|_, keys| {
|
||||
*keys = keys.difference(key);
|
||||
*keys != VBKey::empty()
|
||||
});
|
||||
}
|
||||
|
||||
pub fn keyboard_mapping_names(&self) -> HashMap<VBKey, String> {
|
||||
let mut results: HashMap<VBKey, Vec<String>> = HashMap::new();
|
||||
for (keyboard_key, keys) in &self.keys {
|
||||
let name = match keyboard_key {
|
||||
PhysicalKey::Code(code) => format!("{code:?}"),
|
||||
k => format!("{:?}", k),
|
||||
};
|
||||
for key in keys.iter() {
|
||||
results.entry(key).or_default().push(name.clone());
|
||||
}
|
||||
}
|
||||
results
|
||||
.into_iter()
|
||||
.map(|(k, mut v)| {
|
||||
v.sort();
|
||||
(k, v.join(", "))
|
||||
pub fn binding_names(&self) -> HashMap<VBKey, String> {
|
||||
self.vb_bindings
|
||||
.iter()
|
||||
.map(|(k, v)| {
|
||||
let name = match v {
|
||||
Key::Character(char) => char.to_string(),
|
||||
Key::Named(key) => format!("{:?}", key),
|
||||
k => format!("{:?}", k),
|
||||
};
|
||||
(*k, name)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MappingProvider {
|
||||
device_mappings: Arc<RwLock<HashMap<DeviceId, Arc<RwLock<GamepadMapping>>>>>,
|
||||
sim_mappings: HashMap<SimId, Arc<RwLock<InputMapping>>>,
|
||||
}
|
||||
pub fn bind_key(&mut self, vb: VBKey, key: Key) {
|
||||
if let Some(old) = self.vb_bindings.insert(vb, key.clone()) {
|
||||
self.key_bindings.remove(&old);
|
||||
}
|
||||
self.key_bindings.insert(key, vb);
|
||||
}
|
||||
|
||||
impl MappingProvider {
|
||||
pub fn new() -> Self {
|
||||
let mut mappings = HashMap::new();
|
||||
|
||||
let mut p1_mappings = InputMapping::default();
|
||||
let p2_mappings = InputMapping::default();
|
||||
let mut default_key = |code, key| {
|
||||
p1_mappings.add_keyboard_mapping(key, PhysicalKey::Code(code));
|
||||
};
|
||||
default_key(KeyCode::KeyA, VBKey::SEL);
|
||||
default_key(KeyCode::KeyS, VBKey::STA);
|
||||
default_key(KeyCode::KeyD, VBKey::B);
|
||||
default_key(KeyCode::KeyF, VBKey::A);
|
||||
default_key(KeyCode::KeyE, VBKey::LT);
|
||||
default_key(KeyCode::KeyR, VBKey::RT);
|
||||
default_key(KeyCode::KeyI, VBKey::RU);
|
||||
default_key(KeyCode::KeyJ, VBKey::RL);
|
||||
default_key(KeyCode::KeyK, VBKey::RD);
|
||||
default_key(KeyCode::KeyL, VBKey::RR);
|
||||
default_key(KeyCode::ArrowUp, VBKey::LU);
|
||||
default_key(KeyCode::ArrowLeft, VBKey::LL);
|
||||
default_key(KeyCode::ArrowDown, VBKey::LD);
|
||||
default_key(KeyCode::ArrowRight, VBKey::LR);
|
||||
|
||||
mappings.insert(SimId::Player1, Arc::new(RwLock::new(p1_mappings)));
|
||||
mappings.insert(SimId::Player2, Arc::new(RwLock::new(p2_mappings)));
|
||||
Self {
|
||||
device_mappings: Arc::new(RwLock::new(HashMap::new())),
|
||||
sim_mappings: mappings,
|
||||
pub fn clear_binding(&mut self, vb: VBKey) {
|
||||
if let Some(old) = self.vb_bindings.remove(&vb) {
|
||||
self.key_bindings.remove(&old);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn for_sim(&self, sim_id: SimId) -> &Arc<RwLock<InputMapping>> {
|
||||
self.sim_mappings.get(&sim_id).unwrap()
|
||||
}
|
||||
|
||||
pub fn map_gamepad(&self, sim_id: SimId, gamepad: &Gamepad) {
|
||||
let device_id = DeviceId(
|
||||
gamepad.vendor_id().unwrap_or_default(),
|
||||
gamepad.product_id().unwrap_or_default(),
|
||||
);
|
||||
let mut lock = self.device_mappings.write().unwrap();
|
||||
let gamepad_mapping = match lock.entry(device_id) {
|
||||
Entry::Occupied(entry) => entry.get().clone(),
|
||||
Entry::Vacant(entry) => {
|
||||
let mappings = GamepadMapping::for_gamepad(gamepad);
|
||||
entry.insert(Arc::new(RwLock::new(mappings))).clone()
|
||||
}
|
||||
};
|
||||
drop(lock);
|
||||
self.for_sim(sim_id)
|
||||
.write()
|
||||
.unwrap()
|
||||
.gamepads
|
||||
.insert(gamepad.id(), gamepad_mapping);
|
||||
pub fn key_event(&self, event: &KeyEvent) -> Option<VBKey> {
|
||||
self.key_bindings
|
||||
.get(&event.key_without_modifiers())
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -11,27 +11,16 @@ mod app;
|
|||
mod audio;
|
||||
mod controller;
|
||||
mod emulator;
|
||||
mod graphics;
|
||||
mod input;
|
||||
mod renderer;
|
||||
mod shrooms_vb_core;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
rom: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn set_process_priority_to_high() -> Result<()> {
|
||||
use windows::Win32::{Foundation, System::Threading};
|
||||
let process = unsafe { Threading::GetCurrentProcess() };
|
||||
unsafe { Threading::SetPriorityClass(process, Threading::HIGH_PRIORITY_CLASS)? };
|
||||
unsafe { Foundation::CloseHandle(process)? };
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
#[cfg(windows)]
|
||||
set_process_priority_to_high()?;
|
||||
|
||||
let args = Args::parse();
|
||||
|
||||
let (mut builder, client) = EmulatorBuilder::new();
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use wgpu::{
|
||||
Extent3d, ImageCopyTexture, ImageDataLayout, Origin3d, Queue, Texture, TextureDescriptor,
|
||||
TextureFormat, TextureUsages,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GameRenderer {
|
||||
pub queue: Arc<Queue>,
|
||||
pub eyes: Arc<Texture>,
|
||||
}
|
||||
|
||||
impl GameRenderer {
|
||||
pub fn render(&self, buffer: &[u8]) {
|
||||
let texture = ImageCopyTexture {
|
||||
texture: &self.eyes,
|
||||
mip_level: 0,
|
||||
origin: Origin3d::ZERO,
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
};
|
||||
let size = Extent3d {
|
||||
width: 384,
|
||||
height: 224,
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
let data_layout = ImageDataLayout {
|
||||
offset: 0,
|
||||
bytes_per_row: Some(384 * 2),
|
||||
rows_per_image: Some(224),
|
||||
};
|
||||
self.queue.write_texture(texture, buffer, data_layout, size);
|
||||
}
|
||||
pub fn create_texture(device: &wgpu::Device, name: &str) -> Texture {
|
||||
let desc = TextureDescriptor {
|
||||
label: Some(name),
|
||||
size: Extent3d {
|
||||
width: 384,
|
||||
height: 224,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: TextureFormat::Rg8Unorm,
|
||||
usage: TextureUsages::COPY_SRC
|
||||
| TextureUsages::COPY_DST
|
||||
| TextureUsages::TEXTURE_BINDING,
|
||||
view_formats: &[TextureFormat::Rg8Unorm],
|
||||
};
|
||||
device.create_texture(&desc)
|
||||
}
|
||||
}
|
|
@ -25,12 +25,6 @@ enum VBDataType {
|
|||
F32 = 5,
|
||||
}
|
||||
|
||||
#[repr(i32)]
|
||||
#[derive(FromPrimitive, ToPrimitive)]
|
||||
enum VBOption {
|
||||
PseudoHalt = 0,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
|
@ -60,8 +54,6 @@ type OnFrame = extern "C" fn(sim: *mut VB) -> c_int;
|
|||
extern "C" {
|
||||
#[link_name = "vbEmulate"]
|
||||
fn vb_emulate(sim: *mut VB, cycles: *mut u32) -> c_int;
|
||||
#[link_name = "vbEmulateEx"]
|
||||
fn vb_emulate_ex(sims: *mut *mut VB, count: c_uint, cycles: *mut u32) -> c_int;
|
||||
#[link_name = "vbGetCartROM"]
|
||||
fn vb_get_cart_rom(sim: *mut VB, size: *mut u32) -> *mut c_void;
|
||||
#[link_name = "vbGetPixels"]
|
||||
|
@ -89,14 +81,10 @@ extern "C" {
|
|||
fn vb_reset(sim: *mut VB);
|
||||
#[link_name = "vbSetCartROM"]
|
||||
fn vb_set_cart_rom(sim: *mut VB, rom: *mut c_void, size: u32) -> c_int;
|
||||
#[link_name = "vbSetFrameCallback"]
|
||||
fn vb_set_frame_callback(sim: *mut VB, on_frame: OnFrame);
|
||||
#[link_name = "vbSetKeys"]
|
||||
fn vb_set_keys(sim: *mut VB, keys: u16) -> u16;
|
||||
#[link_name = "vbSetOption"]
|
||||
fn vb_set_option(sim: *mut VB, key: VBOption, value: c_int);
|
||||
#[link_name = "vbSetPeer"]
|
||||
fn vb_set_peer(sim: *mut VB, peer: *mut VB);
|
||||
#[link_name = "vbSetFrameCallback"]
|
||||
fn vb_set_frame_callback(sim: *mut VB, on_frame: OnFrame);
|
||||
#[link_name = "vbSetSamples"]
|
||||
fn vb_set_samples(
|
||||
sim: *mut VB,
|
||||
|
@ -125,15 +113,14 @@ struct VBState {
|
|||
frame_seen: bool,
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct Sim {
|
||||
pub struct CoreVB {
|
||||
sim: *mut VB,
|
||||
}
|
||||
|
||||
// SAFETY: the memory pointed to by sim is valid
|
||||
unsafe impl Send for Sim {}
|
||||
unsafe impl Send for CoreVB {}
|
||||
|
||||
impl Sim {
|
||||
impl CoreVB {
|
||||
pub fn new() -> Self {
|
||||
// init the VB instance itself
|
||||
let size = unsafe { vb_size_of() };
|
||||
|
@ -141,7 +128,6 @@ impl Sim {
|
|||
let memory = vec![0u64; size.div_ceil(4)];
|
||||
let sim: *mut VB = Box::into_raw(memory.into_boxed_slice()).cast();
|
||||
unsafe { vb_init(sim) };
|
||||
unsafe { vb_set_option(sim, VBOption::PseudoHalt, 1) };
|
||||
unsafe { vb_reset(sim) };
|
||||
|
||||
// set up userdata
|
||||
|
@ -154,7 +140,7 @@ impl Sim {
|
|||
let samples: *mut c_void = Box::into_raw(audio_buffer.into_boxed_slice()).cast();
|
||||
unsafe { vb_set_samples(sim, samples, VBDataType::F32, AUDIO_CAPACITY_SAMPLES as u32) };
|
||||
|
||||
Sim { sim }
|
||||
CoreVB { sim }
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
|
@ -176,17 +162,6 @@ impl Sim {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn clone_rom(&self) -> Option<Vec<u8>> {
|
||||
let mut size = 0;
|
||||
let rom = unsafe { vb_get_cart_rom(self.sim, &mut size) };
|
||||
if rom.is_null() {
|
||||
return None;
|
||||
}
|
||||
// SAFETY: rom definitely points to a valid array of `size` bytes
|
||||
let slice: &[u8] = unsafe { slice::from_raw_parts(rom.cast(), size as usize) };
|
||||
Some(slice.to_vec())
|
||||
}
|
||||
|
||||
fn unload_rom(&mut self) -> Option<Vec<u8>> {
|
||||
let mut size = 0;
|
||||
let rom = unsafe { vb_get_cart_rom(self.sim, &mut size) };
|
||||
|
@ -198,26 +173,11 @@ impl Sim {
|
|||
Some(vec)
|
||||
}
|
||||
|
||||
pub fn link(&mut self, peer: &mut Sim) {
|
||||
unsafe { vb_set_peer(self.sim, peer.sim) };
|
||||
}
|
||||
|
||||
pub fn unlink(&mut self) {
|
||||
unsafe { vb_set_peer(self.sim, ptr::null_mut()) };
|
||||
}
|
||||
|
||||
pub fn emulate(&mut self) {
|
||||
pub fn emulate_frame(&mut self) {
|
||||
let mut cycles = 20_000_000;
|
||||
unsafe { vb_emulate(self.sim, &mut cycles) };
|
||||
}
|
||||
|
||||
pub fn emulate_many(sims: &mut [Sim]) {
|
||||
let mut cycles = 20_000_000;
|
||||
let count = sims.len() as c_uint;
|
||||
let sims = sims.as_mut_ptr().cast();
|
||||
unsafe { vb_emulate_ex(sims, count, &mut cycles) };
|
||||
}
|
||||
|
||||
pub fn read_pixels(&mut self, buffers: &mut [u8]) -> bool {
|
||||
// SAFETY: the *mut VB owns its userdata.
|
||||
// There is no way for the userdata to be null or otherwise invalid.
|
||||
|
@ -243,17 +203,14 @@ impl Sim {
|
|||
true
|
||||
}
|
||||
|
||||
pub fn read_samples(&mut self, samples: &mut Vec<f32>, weight: f32) {
|
||||
pub fn read_samples(&mut self, samples: &mut Vec<f32>) {
|
||||
let mut position = 0;
|
||||
let ptr =
|
||||
unsafe { vb_get_samples(self.sim, ptr::null_mut(), ptr::null_mut(), &mut position) };
|
||||
// SAFETY: position is an offset in a buffer of (f32, f32). so, position * 2 is an offset in a buffer of f32.
|
||||
let read_samples: &[f32] =
|
||||
unsafe { slice::from_raw_parts(ptr.cast(), position as usize * 2) };
|
||||
samples.resize(read_samples.len(), 0.0);
|
||||
for (index, sample) in read_samples.iter().enumerate() {
|
||||
samples[index] += sample * weight;
|
||||
}
|
||||
let read_samples: &mut [f32] =
|
||||
unsafe { slice::from_raw_parts_mut(ptr.cast(), position as usize * 2) };
|
||||
samples.extend_from_slice(read_samples);
|
||||
|
||||
unsafe {
|
||||
vb_set_samples(
|
||||
|
@ -270,7 +227,7 @@ impl Sim {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drop for Sim {
|
||||
impl Drop for CoreVB {
|
||||
fn drop(&mut self) {
|
||||
let ptr =
|
||||
unsafe { vb_get_samples(self.sim, ptr::null_mut(), ptr::null_mut(), ptr::null_mut()) };
|
||||
|
@ -286,9 +243,6 @@ impl Drop for Sim {
|
|||
// SAFETY: we made this pointer ourselves, we can for sure free it
|
||||
unsafe { drop(Box::from_raw(ptr)) };
|
||||
|
||||
// If we're linked to another sim, unlink from them.
|
||||
unsafe { vb_set_peer(self.sim, ptr::null_mut()) };
|
||||
|
||||
let len = unsafe { vb_size_of() }.div_ceil(4);
|
||||
// SAFETY: the sim's memory originally came from a Vec<u64>
|
||||
let bytes: Vec<u64> = unsafe { Vec::from_raw_parts(self.sim.cast(), len, len) };
|
Loading…
Reference in New Issue