forked from StrafesNET/roblox-bot-player
Compare commits
78 Commits
playback-i
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
102dd7fa6f
|
|||
|
f8996c958c
|
|||
|
f91fcf6b6f
|
|||
|
4593514954
|
|||
|
31a3e31e70
|
|||
|
4873e0298c
|
|||
|
637fb38131
|
|||
|
ae624f90dc
|
|||
|
1d17e6acf0
|
|||
|
a53cf8a8c7
|
|||
|
9007de1a2d
|
|||
|
6df057de17
|
|||
|
4fe2eed922
|
|||
|
e83d0e5ff9
|
|||
|
4587d8161d
|
|||
|
7b56dacb73
|
|||
|
f19e846e0f
|
|||
|
6240b0ae86
|
|||
|
8d1ec94ac2
|
|||
|
f82d860822
|
|||
|
c8eb2f7878
|
|||
|
66cb1fc5ff
|
|||
|
0cb0f6a423
|
|||
|
890e5c1905
|
|||
|
3d8b5a0dfe
|
|||
|
495092f79f
|
|||
|
e0a8175355
|
|||
|
006a70a18b
|
|||
|
7ce2ca8b0a
|
|||
|
6ef6c67703
|
|||
|
8dfb5f5094
|
|||
|
9e0e9a62e7
|
|||
|
6fbeba94ae
|
|||
|
01916e0682
|
|||
|
2af2134f72
|
|||
|
a3e7b5ff99
|
|||
|
58f9a70e16
|
|||
|
3b218856c9
|
|||
|
00393490a0
|
|||
|
f96891dcbc
|
|||
|
35a90f28ae
|
|||
|
c3676349b0
|
|||
|
299a2b8051
|
|||
|
a4c4f20bad
|
|||
|
3644dd7f15
|
|||
|
197f840246
|
|||
|
c3cca22839
|
|||
|
81a158d08f
|
|||
|
7a421d1eab
|
|||
|
e821fb6982
|
|||
|
cb71fa7257
|
|||
|
51fdc72e0e
|
|||
|
29e49587ff
|
|||
|
d03f84c893
|
|||
|
48a7b06b71
|
|||
|
43cc9b6416
|
|||
|
e4433cf06c
|
|||
|
54beb3e9df
|
|||
|
aa0a333431
|
|||
|
cb7474522f
|
|||
|
87fa1220c6
|
|||
|
4fb2e6c800
|
|||
|
b1ebd01463
|
|||
|
de8ef7fae2
|
|||
|
dd55987403
|
|||
|
e4f6f8490d
|
|||
|
db634247ac
|
|||
|
c5cd25c27a
|
|||
|
57c545efa6
|
|||
|
8ecb79a0b4
|
|||
|
98f56d0608
|
|||
|
cf59852468
|
|||
|
2f584744c7
|
|||
|
c33daaf0c6
|
|||
|
3dea810a50
|
|||
|
a238793cdc
|
|||
|
d9610901cb
|
|||
|
dd9cf502f1
|
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[registries.strafesnet]
|
||||||
|
index = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
||||||
662
Cargo.lock
generated
662
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
18
Cargo.toml
18
Cargo.toml
@@ -1,7 +1,9 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
|
"integration-tests",
|
||||||
"lib",
|
"lib",
|
||||||
"native-player",
|
"native-player",
|
||||||
|
"video-encoder",
|
||||||
"wasm-module"
|
"wasm-module"
|
||||||
]
|
]
|
||||||
resolver = "3"
|
resolver = "3"
|
||||||
@@ -12,7 +14,17 @@ strip = true
|
|||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
strafesnet_common = { version = "0.8.0", registry = "strafesnet" }
|
glam = "0.32.0"
|
||||||
strafesnet_graphics = { version = "0.0.2", registry = "strafesnet" }
|
wgpu = "28.0.0"
|
||||||
strafesnet_roblox_bot_file = { version = "0.8.1", registry = "strafesnet" }
|
|
||||||
|
strafesnet_common = { version = "0.8.6", registry = "strafesnet" }
|
||||||
|
strafesnet_graphics = { version = "0.0.7", registry = "strafesnet" }
|
||||||
|
strafesnet_roblox_bot_file = { version = "0.9.3", registry = "strafesnet" }
|
||||||
strafesnet_snf = { version = "0.3.2", registry = "strafesnet" }
|
strafesnet_snf = { version = "0.3.2", registry = "strafesnet" }
|
||||||
|
|
||||||
|
strafesnet_roblox_bot_player = { version = "0.2.0", path = "lib" }
|
||||||
|
|
||||||
|
# strafesnet_common = { path = "../strafe-project/lib/common" }
|
||||||
|
# strafesnet_graphics = { path = "../strafe-project/engine/graphics" }
|
||||||
|
# strafesnet_roblox_bot_file = { path = "../roblox_bot_file" }
|
||||||
|
# strafesnet_snf = { path = "../strafe-project/lib/snf" }
|
||||||
|
|||||||
176
LICENSE-APACHE
Normal file
176
LICENSE-APACHE
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
23
LICENSE-MIT
Normal file
23
LICENSE-MIT
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
Permission is hereby granted, free of charge, to any
|
||||||
|
person obtaining a copy of this software and associated
|
||||||
|
documentation files (the "Software"), to deal in the
|
||||||
|
Software without restriction, including without
|
||||||
|
limitation the rights to use, copy, modify, merge,
|
||||||
|
publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software
|
||||||
|
is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice
|
||||||
|
shall be included in all copies or substantial portions
|
||||||
|
of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||||
|
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||||
|
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||||
|
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
41
README.md
41
README.md
@@ -1,17 +1,50 @@
|
|||||||
How to build the wasm module:
|
### How to clone this repository:
|
||||||
|
- Install git
|
||||||
|
- Install git lfs (for test files)
|
||||||
|
```
|
||||||
|
git clone https://git.itzana.me/StrafesNET/roblox-bot-player
|
||||||
|
cd roblox-bot-player
|
||||||
|
git lfs pull
|
||||||
|
```
|
||||||
|
|
||||||
|
### How to build the wasm module:
|
||||||
|
- Install rust
|
||||||
|
- Install wasm-pack
|
||||||
```
|
```
|
||||||
cd wasm-module
|
cd wasm-module
|
||||||
wasm-pack build --target web --out-dir ../web-demo/pkg
|
wasm-pack build --target web --out-dir ../web-demo/pkg
|
||||||
```
|
```
|
||||||
|
|
||||||
How to serve the web demo (requires wasm module):
|
### How to serve the web demo (requires wasm module):
|
||||||
|
- Install python3 or use your favourite http server
|
||||||
```
|
```
|
||||||
cd web-demo
|
cd web-demo
|
||||||
python3 -m http.server
|
python3 -m http.server
|
||||||
```
|
```
|
||||||
|
|
||||||
How to run the native player:
|
### How to run the native player:
|
||||||
|
- Install rust
|
||||||
```
|
```
|
||||||
cd native-player
|
cd native-player
|
||||||
cargo run --release
|
cargo run --release -- ../web-demo/bhop_marble_5692093612.snfm ../web-demo/bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d.qbot
|
||||||
```
|
```
|
||||||
|
You can drag and drop map files and bot files to load them.
|
||||||
|
|
||||||
|
#### License
|
||||||
|
|
||||||
|
This code depends on a proprietary module, [strafesnet_graphics](https://git.itzana.me/StrafesNET/strafe-project/src/branch/master/engine/graphics). The resulting binary is
|
||||||
|
not redistributable without the express permission of Rhys Lloyd. The code in this repository
|
||||||
|
is MIT & Apache 2.0 dual licensed, and is free to use.
|
||||||
|
|
||||||
|
<sup>
|
||||||
|
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
|
||||||
|
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
|
||||||
|
</sup>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<sub>
|
||||||
|
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||||
|
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
|
||||||
|
be dual licensed as above, without any additional terms or conditions.
|
||||||
|
</sub>
|
||||||
|
|||||||
9
integration-tests/Cargo.toml
Normal file
9
integration-tests/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "integration-tests"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
strafesnet_common.workspace = true
|
||||||
|
strafesnet_roblox_bot_file.workspace = true
|
||||||
|
strafesnet_roblox_bot_player.workspace = true
|
||||||
25
integration-tests/src/main.rs
Normal file
25
integration-tests/src/main.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
use strafesnet_roblox_bot_file::v0;
|
||||||
|
use strafesnet_roblox_bot_player::{bot,bvh,head};
|
||||||
|
use head::Time as PlaybackTime;
|
||||||
|
use strafesnet_common::session::Time as SessionTime;
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
let bot=include_bytes!("../../web-demo/bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d.qbot");
|
||||||
|
let timelines=v0::read_all_to_block(std::io::Cursor::new(bot)).unwrap();
|
||||||
|
let bot=bot::CompleteBot::new(timelines);
|
||||||
|
let bvh=bvh::Bvh::new(&bot);
|
||||||
|
|
||||||
|
// sample the position at 0.24s
|
||||||
|
let mut playback0=head::PlaybackHead::new(&bot,SessionTime::ZERO);
|
||||||
|
for i in 0..10{
|
||||||
|
let sample_time=PlaybackTime::from_millis(6543+1*i);
|
||||||
|
playback0.set_time(&bot,SessionTime::ZERO,sample_time);
|
||||||
|
let pos=playback0.get_position(&bot,SessionTime::ZERO);
|
||||||
|
|
||||||
|
// get the closest time on the timeline (convert to PlaybackTime which starts at 0)
|
||||||
|
let closest_time=bot.playback_time(bvh.closest_time_to_point(&bot,pos).unwrap());
|
||||||
|
println!("time={sample_time} closest_time={closest_time}");
|
||||||
|
}
|
||||||
|
// let mut playback1=head::PlaybackHead::new(&bot,SessionTime::ZERO);
|
||||||
|
// playback1.set_time(&bot,SessionTime::ZERO,sample_time);
|
||||||
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "strafesnet_roblox_bot_player"
|
name = "strafesnet_roblox_bot_player"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
glam = "0.31.0"
|
glam.workspace = true
|
||||||
|
wgpu.workspace = true
|
||||||
strafesnet_common.workspace = true
|
strafesnet_common.workspace = true
|
||||||
strafesnet_graphics.workspace = true
|
strafesnet_graphics.workspace = true
|
||||||
strafesnet_roblox_bot_file.workspace = true
|
strafesnet_roblox_bot_file.workspace = true
|
||||||
strafesnet_snf.workspace = true
|
|
||||||
wgpu = "28.0.0"
|
|
||||||
|
|||||||
@@ -1,31 +1,64 @@
|
|||||||
|
use strafesnet_common::timer::{TimerFixed,Realtime,Unpaused};
|
||||||
|
use strafesnet_common::run::{Time as RunTime};
|
||||||
|
use strafesnet_common::physics::{Time as PhysicsTime,TimeInner as PhysicsTimeInner};
|
||||||
|
use strafesnet_roblox_bot_file::v0;
|
||||||
|
|
||||||
|
use crate::head::{Time as PlaybackTime,TimeInner as PlaybackTimeInner};
|
||||||
|
|
||||||
/// A loaded bot file.
|
/// A loaded bot file.
|
||||||
pub struct CompleteBot{
|
pub struct CompleteBot{
|
||||||
//Instructions
|
//Instructions
|
||||||
timelines:strafesnet_roblox_bot_file::v0::Block,
|
timelines:v0::Block,
|
||||||
offset:f64,
|
timer:TimerFixed<Realtime<PlaybackTimeInner,PhysicsTimeInner>,Unpaused>,
|
||||||
duration:f64,
|
duration:PhysicsTime,
|
||||||
|
world_offset:glam::Vec3,
|
||||||
}
|
}
|
||||||
impl CompleteBot{
|
impl CompleteBot{
|
||||||
pub(crate) const CAMERA_OFFSET:glam::Vec3=glam::vec3(0.0,2.0,0.0);
|
pub(crate) const CAMERA_OFFSET:glam::Vec3=glam::vec3(0.0,2.0,0.0);
|
||||||
pub fn new(
|
pub fn new(
|
||||||
data:&[u8],
|
timelines:v0::Block,
|
||||||
)->Result<Self,strafesnet_roblox_bot_file::v0::Error>{
|
)->Self{
|
||||||
let timelines=strafesnet_roblox_bot_file::v0::read_all_to_block(std::io::Cursor::new(data))?;
|
let start=crate::time::from_float(timelines.output_events.first().unwrap().time).unwrap();
|
||||||
let first=timelines.output_events.first().unwrap();
|
let end=crate::time::from_float(timelines.output_events.last().unwrap().time).unwrap();
|
||||||
let last=timelines.output_events.last().unwrap();
|
let world_position=timelines.world_events.iter().find_map(|event|match &event.event{
|
||||||
Ok(Self{
|
v0::WorldEvent::Reset(world_reset_event)=>Some(world_reset_event.position),
|
||||||
offset:first.time,
|
_=>None,
|
||||||
duration:last.time-first.time,
|
}).expect("Map must contain a WorldReset event");
|
||||||
|
Self{
|
||||||
|
timer:TimerFixed::new(PlaybackTime::ZERO,start),
|
||||||
|
duration:end-start,
|
||||||
timelines,
|
timelines,
|
||||||
})
|
world_offset:glam::vec3(world_position.x,world_position.y,world_position.z),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub const fn offset(&self)->f64{
|
pub fn time(&self,time:PlaybackTime)->PhysicsTime{
|
||||||
self.offset
|
self.timer.time(time)
|
||||||
}
|
}
|
||||||
pub const fn duration(&self)->f64{
|
pub fn playback_time(&self,time:PhysicsTime)->PlaybackTime{
|
||||||
|
use strafesnet_common::timer::TimerState;
|
||||||
|
time.coerce()-self.timer.clone().into_state().get_offset().coerce()
|
||||||
|
}
|
||||||
|
pub const fn duration(&self)->PhysicsTime{
|
||||||
self.duration
|
self.duration
|
||||||
}
|
}
|
||||||
pub const fn timelines(&self)->&strafesnet_roblox_bot_file::v0::Block{
|
pub const fn world_offset(&self)->glam::Vec3{
|
||||||
|
self.world_offset
|
||||||
|
}
|
||||||
|
pub const fn timelines(&self)->&v0::Block{
|
||||||
&self.timelines
|
&self.timelines
|
||||||
}
|
}
|
||||||
|
pub fn run_duration(&self,mode_id:v0::ModeID)->Option<RunTime>{
|
||||||
|
let mut it=self.timelines.run_events.iter().rev();
|
||||||
|
let end=it.find_map(|event|match &event.event{
|
||||||
|
v0::RunEvent::Finish(run_start_event) if run_start_event.mode==mode_id=>Some(event.time),
|
||||||
|
_=>None,
|
||||||
|
})?;
|
||||||
|
let start=it.find_map(|event|match &event.event{
|
||||||
|
v0::RunEvent::Start(run_start_event) if run_start_event.mode==mode_id=>Some(event.time),
|
||||||
|
_=>None,
|
||||||
|
})?;
|
||||||
|
let start=crate::time::from_float(start).unwrap();
|
||||||
|
let end=crate::time::from_float(end).unwrap();
|
||||||
|
Some(end-start)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
162
lib/src/bvh.rs
Normal file
162
lib/src/bvh.rs
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
use core::ops::Range;
|
||||||
|
use strafesnet_common::aabb::Aabb;
|
||||||
|
use strafesnet_common::bvh::generate_bvh;
|
||||||
|
use strafesnet_common::integer::vec3;
|
||||||
|
use strafesnet_common::integer::{Fixed,Planar64};
|
||||||
|
use strafesnet_common::physics::Time as PhysicsTime;
|
||||||
|
use crate::bot::CompleteBot;
|
||||||
|
use strafesnet_roblox_bot_file::v0;
|
||||||
|
|
||||||
|
const MAX_SLICE_LEN:usize=16;
|
||||||
|
struct EventSlice{
|
||||||
|
slice:Range<usize>,
|
||||||
|
inclusive:bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Bvh{
|
||||||
|
bvh:strafesnet_common::bvh::BvhNode<EventSlice>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Bvh{
|
||||||
|
pub fn new(bot:&CompleteBot)->Self{
|
||||||
|
let output_events=&bot.timelines().output_events;
|
||||||
|
// iterator over the event timeline and capture slices of contiguous output events.
|
||||||
|
// create an Aabb for each slice and then generate a BVH.
|
||||||
|
let mut bvh_nodes=Vec::new();
|
||||||
|
let it=output_events
|
||||||
|
.array_windows()
|
||||||
|
.enumerate()
|
||||||
|
// find discontinuities
|
||||||
|
.filter(|&(_,[event0,event1])|
|
||||||
|
event0.time==event1.time&&!(
|
||||||
|
event0.event.position.x==event1.event.position.x
|
||||||
|
&&event0.event.position.y==event1.event.position.y
|
||||||
|
&&event0.event.position.z==event1.event.position.z
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut last_index=0;
|
||||||
|
let mut push_slices=|index:usize|{
|
||||||
|
let len=index-last_index;
|
||||||
|
let count=len.div_ceil(MAX_SLICE_LEN);
|
||||||
|
let slice_len=MAX_SLICE_LEN;
|
||||||
|
bvh_nodes.reserve(count);
|
||||||
|
// 0123456789
|
||||||
|
// split into groups of MAX_SLICE_LEN=4
|
||||||
|
// [0123][4567][89]
|
||||||
|
let mut push_slice=|slice:Range<usize>,inclusive:bool|{
|
||||||
|
let mut aabb=Aabb::default();
|
||||||
|
for event in &output_events[slice.start..slice.end]{
|
||||||
|
aabb.grow(vec3::try_from_f32_array([event.event.position.x,event.event.position.y,event.event.position.z]).unwrap());
|
||||||
|
}
|
||||||
|
if inclusive{
|
||||||
|
let event=&output_events[slice.end];
|
||||||
|
aabb.grow(vec3::try_from_f32_array([event.event.position.x,event.event.position.y,event.event.position.z]).unwrap());
|
||||||
|
}
|
||||||
|
bvh_nodes.push((EventSlice{slice,inclusive},aabb));
|
||||||
|
};
|
||||||
|
// push fixed-size groups
|
||||||
|
for i in 0..count-1{
|
||||||
|
push_slice((last_index+i*slice_len)..(last_index+(i+1)*slice_len),true);
|
||||||
|
}
|
||||||
|
// push last group which may be shorter
|
||||||
|
push_slice((last_index+(count-1)*slice_len)..index,false);
|
||||||
|
last_index=index;
|
||||||
|
};
|
||||||
|
// find discontinuities (teleports) and avoid forming a bvh node across them
|
||||||
|
for (split_index,_) in it{
|
||||||
|
// we want to use the index of event1
|
||||||
|
push_slices(split_index+1);
|
||||||
|
}
|
||||||
|
// there are no more discontinuities, push the remaining slices
|
||||||
|
push_slices(output_events.len());
|
||||||
|
let bvh=generate_bvh(bvh_nodes);
|
||||||
|
Self{bvh}
|
||||||
|
}
|
||||||
|
/// Find the exact timestamp on the bot timeline that is closest to the given point.
|
||||||
|
pub fn closest_time_to_point<'a>(&self,bot:&'a CompleteBot,point:glam::Vec3)->Option<PhysicsTime>{
|
||||||
|
let point=point+bot.world_offset();
|
||||||
|
let start_point=vec3::try_from_f32_array(point.to_array()).unwrap();
|
||||||
|
let output_events=&bot.timelines().output_events;
|
||||||
|
// grow a sphere starting at start_point until we find the closest point on the bot output events
|
||||||
|
let intersect_leaf=|event_slice:&EventSlice|{
|
||||||
|
// calculate the distance to the leaf contents
|
||||||
|
let mut best_distance=output_events[event_slice.slice.start..event_slice.slice.end].iter().map(|event|{
|
||||||
|
let p=event.event.position;
|
||||||
|
let p=vec3::try_from_f32_array([p.x,p.y,p.z]).unwrap();
|
||||||
|
(start_point-p).length_squared()
|
||||||
|
}).min()?;
|
||||||
|
let mut prev_event=&output_events[event_slice.slice.start];
|
||||||
|
let mut f=|event:&'a v0::Timed<v0::OutputEvent>|{
|
||||||
|
let p0=vec3::try_from_f32_array([prev_event.event.position.x,prev_event.event.position.y,prev_event.event.position.z]).unwrap();
|
||||||
|
let p1=vec3::try_from_f32_array([event.event.position.x,event.event.position.y,event.event.position.z]).unwrap();
|
||||||
|
let d=p1-p0;
|
||||||
|
let d0=p0.dot(d);
|
||||||
|
let d1=p1.dot(d);
|
||||||
|
let sp_d=start_point.dot(d);
|
||||||
|
// must be on the segment
|
||||||
|
if d0<sp_d&&sp_d<d1{
|
||||||
|
let t0=d1-sp_d;
|
||||||
|
let t1=sp_d-d0;
|
||||||
|
let dt=d1-d0;
|
||||||
|
let distance=(((p0*t0+p1*t1)/dt).divide().wrap_1()-start_point).length_squared();
|
||||||
|
if distance<best_distance{
|
||||||
|
best_distance=distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev_event=event;
|
||||||
|
};
|
||||||
|
for event in &output_events[event_slice.slice.start+1..event_slice.slice.end]{
|
||||||
|
f(event);
|
||||||
|
}
|
||||||
|
if event_slice.inclusive{
|
||||||
|
f(&output_events[event_slice.slice.end]);
|
||||||
|
}
|
||||||
|
Some(best_distance)
|
||||||
|
};
|
||||||
|
let intersect_aabb=|aabb:&Aabb|{
|
||||||
|
// calculate the distance to the aabb
|
||||||
|
let clamped_point=start_point.min(aabb.max()).max(aabb.min());
|
||||||
|
Some((start_point-clamped_point).length_squared())
|
||||||
|
};
|
||||||
|
let (_,event_slice)=self.bvh.traverse(start_point,Fixed::ZERO,Fixed::MAX,intersect_leaf,intersect_aabb)?;
|
||||||
|
|
||||||
|
// find time at the closest point
|
||||||
|
let (best_time,mut best_distance)=output_events[event_slice.slice.start..event_slice.slice.end].iter().map(|event|{
|
||||||
|
let p=event.event.position;
|
||||||
|
let p=vec3::try_from_f32_array([p.x,p.y,p.z]).unwrap();
|
||||||
|
(event.time,(start_point-p).length_squared())
|
||||||
|
}).min_by_key(|&(_,distance)|distance)?;
|
||||||
|
let mut best_time=crate::time::from_float(best_time).unwrap();
|
||||||
|
let mut prev_event=&output_events[event_slice.slice.start];
|
||||||
|
let mut f=|event:&'a v0::Timed<v0::OutputEvent>|{
|
||||||
|
let p0=vec3::try_from_f32_array([prev_event.event.position.x,prev_event.event.position.y,prev_event.event.position.z]).unwrap();
|
||||||
|
let p1=vec3::try_from_f32_array([event.event.position.x,event.event.position.y,event.event.position.z]).unwrap();
|
||||||
|
let d=p1-p0;
|
||||||
|
let d0=p0.dot(d);
|
||||||
|
let d1=p1.dot(d);
|
||||||
|
let sp_d=start_point.dot(d);
|
||||||
|
// must be on the segment
|
||||||
|
if d0<sp_d&&sp_d<d1{
|
||||||
|
let t0=d1-sp_d;
|
||||||
|
let t1=sp_d-d0;
|
||||||
|
let dt=d1-d0;
|
||||||
|
let distance=(((p0*t0+p1*t1)/dt).divide().wrap_1()-start_point).length_squared();
|
||||||
|
if distance<best_distance{
|
||||||
|
best_distance=distance;
|
||||||
|
let p0:Planar64=prev_event.time.try_into().unwrap();
|
||||||
|
let p1:Planar64=event.time.try_into().unwrap();
|
||||||
|
best_time=((p0*t0+p1*t1)/dt).into();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prev_event=event;
|
||||||
|
};
|
||||||
|
for event in &output_events[event_slice.slice.start+1..event_slice.slice.end]{
|
||||||
|
f(event);
|
||||||
|
}
|
||||||
|
if event_slice.inclusive{
|
||||||
|
f(&output_events[event_slice.slice.end]);
|
||||||
|
}
|
||||||
|
Some(best_time)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,49 +3,28 @@ use strafesnet_graphics::graphics::GraphicsState;
|
|||||||
/// The graphics state, essentially a handle to all the information on the GPU.
|
/// The graphics state, essentially a handle to all the information on the GPU.
|
||||||
pub struct Graphics{
|
pub struct Graphics{
|
||||||
graphics:GraphicsState,
|
graphics:GraphicsState,
|
||||||
config:wgpu::SurfaceConfiguration,
|
start_offset:glam::Vec3,
|
||||||
device:wgpu::Device,
|
|
||||||
queue:wgpu::Queue,
|
|
||||||
}
|
}
|
||||||
impl Graphics{
|
impl Graphics{
|
||||||
pub fn new(device:wgpu::Device,queue:wgpu::Queue,config:wgpu::SurfaceConfiguration)->Self{
|
pub fn new(device:&wgpu::Device,queue:&wgpu::Queue,size:glam::UVec2,view_format:wgpu::TextureFormat)->Self{
|
||||||
let mut graphics=strafesnet_graphics::graphics::GraphicsState::new(&device,&queue,&config);
|
let graphics=strafesnet_graphics::graphics::GraphicsState::new(device,queue,size,view_format);
|
||||||
graphics.resize(&device,&config,glam::Vec2::ONE);
|
|
||||||
Self{
|
Self{
|
||||||
graphics,
|
graphics,
|
||||||
device,
|
start_offset:glam::Vec3::ZERO,
|
||||||
queue,
|
|
||||||
config,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn change_map(&mut self,map:&crate::map::CompleteMap){
|
pub fn change_map(&mut self,device:&wgpu::Device,queue:&wgpu::Queue,map:&strafesnet_common::map::CompleteMap){
|
||||||
self.graphics.clear();
|
self.graphics.clear();
|
||||||
self.graphics.generate_models(&self.device,&self.queue,map.map());
|
self.graphics.generate_models(device,queue,map);
|
||||||
|
let modes=map.modes.clone().denormalize();
|
||||||
|
let mode=modes.get_mode(strafesnet_common::gameplay_modes::ModeId::MAIN).expect("Map does not have a main mode");
|
||||||
|
let start_zone=map.models.get(mode.get_start().get() as usize).expect("Map does not have a start zone");
|
||||||
|
self.start_offset=glam::Vec3::from_array(start_zone.transform.translation.map(|f|f.into()).to_array());
|
||||||
}
|
}
|
||||||
pub fn resize(&mut self,surface:&wgpu::Surface<'_>,size:glam::UVec2){
|
pub fn resize(&mut self,device:&wgpu::Device,size:glam::UVec2,fov:glam::Vec2){
|
||||||
self.config.width=size.x.max(1);
|
self.graphics.resize(device,size,fov);
|
||||||
self.config.height=size.y.max(1);
|
|
||||||
surface.configure(&self.device,&self.config);
|
|
||||||
self.graphics.resize(&self.device,&self.config,glam::Vec2::ONE);
|
|
||||||
}
|
}
|
||||||
pub fn render(&mut self,surface:&wgpu::Surface<'_>,pos:glam::Vec3,angles:glam::Vec2){
|
pub fn encode_commands(&mut self,encoder:&mut wgpu::CommandEncoder,view:&wgpu::TextureView,pos:glam::Vec3,angles:glam::Vec2){
|
||||||
//this has to go deeper somehow
|
self.graphics.encode_commands(encoder,view,strafesnet_graphics::graphics::view_inv(pos+self.start_offset,angles));
|
||||||
let frame=match surface.get_current_texture(){
|
|
||||||
Ok(frame)=>frame,
|
|
||||||
Err(_)=>{
|
|
||||||
surface.configure(&self.device,&self.config);
|
|
||||||
surface
|
|
||||||
.get_current_texture()
|
|
||||||
.expect("Failed to acquire next surface texture!")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let view=frame.texture.create_view(&wgpu::TextureViewDescriptor{
|
|
||||||
format:Some(self.config.view_formats[0]),
|
|
||||||
..wgpu::TextureViewDescriptor::default()
|
|
||||||
});
|
|
||||||
|
|
||||||
self.graphics.render(&view,&self.device,&self.queue,strafesnet_graphics::graphics::view_inv(pos,angles));
|
|
||||||
|
|
||||||
frame.present();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
168
lib/src/head.rs
168
lib/src/head.rs
@@ -1,81 +1,157 @@
|
|||||||
use glam::Vec3Swizzles;
|
use glam::Vec3Swizzles;
|
||||||
use strafesnet_common::timer::{Timer,Scaled};
|
use strafesnet_common::timer::{Scaled,Timer,TimerState};
|
||||||
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
|
use strafesnet_common::session::{Time as SessionTime,TimeInner as SessionTimeInner};
|
||||||
use strafesnet_common::physics::{Time as PhysicsTime,TimeInner as PhysicsTimeInner};
|
use strafesnet_roblox_bot_file::v0::{EventType,Head,Timed};
|
||||||
|
|
||||||
pub enum PlaybackInstructionInternal{
|
use crate::bot::CompleteBot;
|
||||||
Sound
|
use crate::state::PlaybackState;
|
||||||
}
|
|
||||||
pub enum PlaybackInstructionExternal{
|
|
||||||
SetPaused(bool),
|
|
||||||
Idle,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vector3_to_glam(v:&strafesnet_roblox_bot_file::v0::Vector3)->glam::Vec3{
|
fn vector3_to_glam(v:&strafesnet_roblox_bot_file::v0::Vector3)->glam::Vec3{
|
||||||
glam::vec3(v.x,v.y,v.z)
|
glam::vec3(v.x,v.y,v.z)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone,Copy,Hash,Eq,PartialEq,Ord,PartialOrd,Debug)]
|
||||||
|
pub enum TimeInner{}
|
||||||
|
pub type Time=strafesnet_common::integer::Time<TimeInner>;
|
||||||
|
|
||||||
/// A playback context. Advance time and then generate a camera position to pass to the renderer.
|
/// A playback context. Advance time and then generate a camera position to pass to the renderer.
|
||||||
pub struct PlaybackHead{
|
pub struct PlaybackHead{
|
||||||
//"Simulation"
|
head:Head,
|
||||||
event_id:usize,
|
timer:Timer<Scaled<SessionTimeInner,TimeInner>>,
|
||||||
offset:f64,
|
state:PlaybackState,
|
||||||
timer:Timer<Scaled<SessionTimeInner,PhysicsTimeInner>>,
|
|
||||||
}
|
}
|
||||||
impl PlaybackHead{
|
impl PlaybackHead{
|
||||||
pub fn new(time:SessionTime)->Self{
|
pub fn new(bot:&CompleteBot,time:SessionTime)->Self{
|
||||||
let timer=Timer::unpaused(time,PhysicsTime::ZERO);
|
let timer=Timer::unpaused(time,Time::ZERO);
|
||||||
|
let head=Head::after_time(bot.timelines(),bot.time(Time::ZERO).into());
|
||||||
|
let mut state=PlaybackState::new();
|
||||||
|
state.process_head(bot.timelines(),&head);
|
||||||
Self{
|
Self{
|
||||||
event_id:0,
|
head,
|
||||||
offset:0.0,
|
|
||||||
timer,
|
timer,
|
||||||
|
state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn advance_time(&mut self,bot:&crate::bot::CompleteBot,time:SessionTime){
|
pub const fn state(&self)->&PlaybackState{
|
||||||
let simulation_time=self.timer.time(time);
|
&self.state
|
||||||
let mut time_float=simulation_time.get() as f64/PhysicsTime::ONE_SECOND.get() as f64+self.offset+bot.offset();
|
}
|
||||||
|
pub fn time(&self,time:SessionTime)->Time{
|
||||||
|
self.timer.time(time)
|
||||||
|
}
|
||||||
|
pub fn timer(&self)->&Timer<Scaled<SessionTimeInner,TimeInner>>{
|
||||||
|
&self.timer
|
||||||
|
}
|
||||||
|
pub fn set_paused(&mut self,time:SessionTime,paused:bool){
|
||||||
|
_=self.timer.set_paused(time,paused);
|
||||||
|
}
|
||||||
|
pub fn set_time(&mut self,bot:&CompleteBot,time:SessionTime,new_time:Time){
|
||||||
|
let new_time=new_time.rem_euclid(bot.duration().coerce());
|
||||||
|
self.timer.set_time(time,new_time);
|
||||||
|
// reset head
|
||||||
|
self.head=Head::after_time(bot.timelines(),bot.time(new_time).into());
|
||||||
|
|
||||||
|
self.state=PlaybackState::new();
|
||||||
|
self.state.process_head(bot.timelines(),&self.head);
|
||||||
|
}
|
||||||
|
pub fn get_scale(&self)->strafesnet_common::integer::Ratio64{
|
||||||
|
self.timer.get_scale()
|
||||||
|
}
|
||||||
|
pub fn set_scale(&mut self,time:SessionTime,new_scale:strafesnet_common::integer::Ratio64){
|
||||||
|
self.timer.set_scale(time,new_scale);
|
||||||
|
}
|
||||||
|
pub fn next_event(&self,bot:&CompleteBot)->Option<Timed<EventType>>{
|
||||||
|
self.head.next_event(bot.timelines())
|
||||||
|
}
|
||||||
|
pub fn process_event(&mut self,bot:&CompleteBot,event_type:EventType){
|
||||||
|
self.state.process_event(bot.timelines(),event_type,self.head.get_event_index(event_type));
|
||||||
|
self.head.push(event_type);
|
||||||
|
}
|
||||||
|
pub fn advance_time(&mut self,bot:&CompleteBot,time:SessionTime){
|
||||||
|
let mut simulation_time=bot.time(self.time(time));
|
||||||
|
let mut time_float=simulation_time.into();
|
||||||
loop{
|
loop{
|
||||||
match bot.timelines().output_events.get(self.event_id+1){
|
match self.next_event(bot){
|
||||||
Some(next_event)=>{
|
Some(next_event)=>{
|
||||||
if next_event.time<time_float{
|
if next_event.time<time_float{
|
||||||
self.event_id+=1;
|
self.process_event(bot,next_event.event);
|
||||||
}else{
|
}else{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None=>{
|
None=>{
|
||||||
//reset playback
|
//reset playback
|
||||||
self.event_id=0;
|
self.head=Head::after_time(bot.timelines(),bot.time(Time::ZERO).into());
|
||||||
self.offset-=bot.duration();
|
self.state=PlaybackState::new();
|
||||||
time_float-=bot.duration();
|
self.state.process_head(bot.timelines(),&self.head);
|
||||||
|
|
||||||
|
// hack to wind back timer offset without precise session timestamp
|
||||||
|
let (mut state,paused)=self.timer.clone().into_state();
|
||||||
|
let offset=state.get_offset()-bot.duration().coerce();
|
||||||
|
state.set_offset(offset);
|
||||||
|
self.timer=Timer::from_state(state,paused);
|
||||||
|
|
||||||
|
// update loop variables
|
||||||
|
simulation_time-=bot.duration();
|
||||||
|
time_float=simulation_time.into();
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn get_position_angles(&self,bot:&crate::bot::CompleteBot,time:SessionTime)->(glam::Vec3,glam::Vec2){
|
fn interpolate_output<'a>(&self,bot:&'a CompleteBot,time:SessionTime)->InterpolateOutput<'a>{
|
||||||
let time=self.timer.time(time);
|
let time=bot.time(self.time(time));
|
||||||
let event0=&bot.timelines().output_events[self.event_id];
|
let event0=&bot.timelines().output_events[self.head.get_event_index(EventType::Output)-1];
|
||||||
let event1=&bot.timelines().output_events[self.event_id+1];
|
let event1=&bot.timelines().output_events[self.head.get_event_index(EventType::Output)];
|
||||||
let p0=vector3_to_glam(&event0.event.position);
|
|
||||||
let p1=vector3_to_glam(&event1.event.position);
|
|
||||||
// let v0=vector3_to_glam(&event0.event.velocity);
|
|
||||||
// let v1=vector3_to_glam(&event1.event.velocity);
|
|
||||||
// let a0=vector3_to_glam(&event0.event.acceleration);
|
|
||||||
// let a1=vector3_to_glam(&event1.event.acceleration);
|
|
||||||
let t0=event0.time;
|
let t0=event0.time;
|
||||||
let t1=event1.time;
|
let t1=event1.time;
|
||||||
let time_float=time.get() as f64/PhysicsTime::ONE_SECOND.get() as f64;
|
let time_float:f64=time.into();
|
||||||
let t=((time_float+self.offset+bot.offset()-t0)/(t1-t0)) as f32;
|
let t=((time_float-t0)/(t1-t0)) as f32;
|
||||||
let p=p0.lerp(p1,t);
|
InterpolateOutput{
|
||||||
// let v=v0.lerp(v1,t);
|
event0:&event0.event,
|
||||||
// let a=a0.lerp(a1,t);
|
event1:&event1.event,
|
||||||
|
t:t,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn get_position_angles(&self,bot:&CompleteBot,time:SessionTime)->(glam::Vec3,glam::Vec2){
|
||||||
|
let interp=self.interpolate_output(bot,time);
|
||||||
|
|
||||||
//println!("position={:?}",p);
|
let p=interp.position();
|
||||||
|
let a=interp.angles();
|
||||||
|
|
||||||
let angles0=vector3_to_glam(&event0.event.angles);
|
(p-bot.world_offset()+CompleteBot::CAMERA_OFFSET,a.yx())
|
||||||
let angles1=vector3_to_glam(&event1.event.angles);
|
}
|
||||||
let angles=angles0.lerp(angles1,t);
|
pub fn get_position(&self,bot:&CompleteBot,time:SessionTime)->glam::Vec3{
|
||||||
|
let interp=self.interpolate_output(bot,time);
|
||||||
(p+crate::bot::CompleteBot::CAMERA_OFFSET,angles.yx())
|
interp.position()-bot.world_offset()
|
||||||
|
}
|
||||||
|
pub fn get_velocity(&self,bot:&CompleteBot,time:SessionTime)->glam::Vec3{
|
||||||
|
let interp=self.interpolate_output(bot,time);
|
||||||
|
interp.velocity()
|
||||||
|
}
|
||||||
|
pub fn get_angles(&self,bot:&CompleteBot,time:SessionTime)->glam::Vec3{
|
||||||
|
let interp=self.interpolate_output(bot,time);
|
||||||
|
interp.angles()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct InterpolateOutput<'a>{
|
||||||
|
event0:&'a strafesnet_roblox_bot_file::v0::OutputEvent,
|
||||||
|
event1:&'a strafesnet_roblox_bot_file::v0::OutputEvent,
|
||||||
|
t:f32,
|
||||||
|
}
|
||||||
|
impl InterpolateOutput<'_>{
|
||||||
|
fn position(&self)->glam::Vec3{
|
||||||
|
let p0=vector3_to_glam(&self.event0.position);
|
||||||
|
let p1=vector3_to_glam(&self.event1.position);
|
||||||
|
p0.lerp(p1,self.t)
|
||||||
|
}
|
||||||
|
fn velocity(&self)->glam::Vec3{
|
||||||
|
let v0=vector3_to_glam(&self.event0.velocity);
|
||||||
|
let v1=vector3_to_glam(&self.event1.velocity);
|
||||||
|
v0.lerp(v1,self.t)
|
||||||
|
}
|
||||||
|
fn angles(&self)->glam::Vec3{
|
||||||
|
let a0=vector3_to_glam(&self.event0.angles);
|
||||||
|
let a1=vector3_to_glam(&self.event1.angles);
|
||||||
|
a0.lerp(a1,self.t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,6 @@
|
|||||||
pub mod bot;
|
pub mod bot;
|
||||||
pub mod map;
|
pub mod bvh;
|
||||||
pub mod head;
|
pub mod head;
|
||||||
// pub mod surface;
|
pub mod time;
|
||||||
|
pub mod state;
|
||||||
pub mod graphics;
|
pub mod graphics;
|
||||||
|
|
||||||
// Create Surface
|
|
||||||
// Create Graphics from map file and with surface as sample
|
|
||||||
// Create bot from bot file
|
|
||||||
// Create playback head
|
|
||||||
// loop{
|
|
||||||
// advance head
|
|
||||||
// render frame
|
|
||||||
// }
|
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
#[derive(Debug)]
|
|
||||||
pub enum Error{
|
|
||||||
File(strafesnet_snf::Error),
|
|
||||||
Map(strafesnet_snf::map::Error),
|
|
||||||
}
|
|
||||||
impl std::fmt::Display for Error{
|
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
||||||
write!(f,"{self:?}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl std::error::Error for Error{}
|
|
||||||
|
|
||||||
pub struct CompleteMap{
|
|
||||||
complete_map:strafesnet_common::map::CompleteMap,
|
|
||||||
}
|
|
||||||
impl CompleteMap{
|
|
||||||
pub fn new(
|
|
||||||
data:&[u8],
|
|
||||||
)->Result<Self,Error>{
|
|
||||||
let complete_map=strafesnet_snf::read_map(std::io::Cursor::new(data))
|
|
||||||
.map_err(Error::File)?
|
|
||||||
.into_complete_map()
|
|
||||||
.map_err(Error::Map)?;
|
|
||||||
Ok(Self{complete_map})
|
|
||||||
}
|
|
||||||
pub const fn map(&self)->&strafesnet_common::map::CompleteMap{
|
|
||||||
&self.complete_map
|
|
||||||
}
|
|
||||||
}
|
|
||||||
292
lib/src/state.rs
Normal file
292
lib/src/state.rs
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use strafesnet_common::run;
|
||||||
|
use strafesnet_common::physics::Time as PhysicsTime;
|
||||||
|
use strafesnet_roblox_bot_file::v0;
|
||||||
|
|
||||||
|
pub struct Run{
|
||||||
|
run:run::RunState,
|
||||||
|
flag_reason:Option<v0::FlagReason>,
|
||||||
|
}
|
||||||
|
impl Run{
|
||||||
|
fn new()->Self{
|
||||||
|
Self{
|
||||||
|
run:run::RunState::Created,
|
||||||
|
flag_reason:None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn flag(&mut self,flag_reason:v0::FlagReason){
|
||||||
|
if self.flag_reason.is_none(){
|
||||||
|
self.flag_reason=Some(flag_reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn time(&self,time:PhysicsTime)->run::Time{
|
||||||
|
self.run.time(time)
|
||||||
|
}
|
||||||
|
pub fn is_invalid(&self)->bool{
|
||||||
|
self.flag_reason.is_some()
|
||||||
|
}
|
||||||
|
pub fn is_in_progress(&self)->bool{
|
||||||
|
matches!(&self.run,run::RunState::Started{..})
|
||||||
|
}
|
||||||
|
pub fn is_finished(&self)->bool{
|
||||||
|
matches!(&self.run,run::RunState::Finished{..})
|
||||||
|
}
|
||||||
|
pub fn get_flag_reason_text(&self)->Option<&'static str>{
|
||||||
|
Some(match self.flag_reason{
|
||||||
|
Some(v0::FlagReason::Anticheat)=>"Passed through anticheat zone.",
|
||||||
|
Some(v0::FlagReason::StyleChange)=>"Changed style.",
|
||||||
|
Some(v0::FlagReason::Clock)=>"Incorrect clock. (This can be caused by internet hiccups)",
|
||||||
|
Some(v0::FlagReason::Pause)=>"Pausing is not allowed in this style.",
|
||||||
|
Some(v0::FlagReason::Flying)=>"Flying is not allowed in this style.",
|
||||||
|
Some(v0::FlagReason::Gravity)=>"Gravity modification is not allowed in this style.",
|
||||||
|
Some(v0::FlagReason::Timescale)=>"Timescale is not allowed in this style.",
|
||||||
|
Some(v0::FlagReason::Timetravel)=>"Time travel is not allowed in this style.",
|
||||||
|
Some(v0::FlagReason::Teleport)=>"Illegal teleport.",
|
||||||
|
Some(v0::FlagReason::Practice)=>"Practice mode triggers invalidation.",
|
||||||
|
None=>return None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PlaybackState{
|
||||||
|
// EventType::Input
|
||||||
|
game_controls:v0::GameControls,
|
||||||
|
mouse_pos:v0::Vector2,
|
||||||
|
// EventType::Output
|
||||||
|
jump_count:u32,
|
||||||
|
angles:v0::Vector3,
|
||||||
|
angles_delta:glam::Vec3,
|
||||||
|
// EventType::Sound
|
||||||
|
// EventType::World
|
||||||
|
// EventType::Gravity
|
||||||
|
gravity:v0::Vector3,
|
||||||
|
// EventType::Run
|
||||||
|
runs:HashMap<v0::ModeID,Run>,
|
||||||
|
style:v0::Style,
|
||||||
|
// EventType::Camera
|
||||||
|
// TODO: camera punch
|
||||||
|
// EventType::Setting
|
||||||
|
absolute_sensitivity_enabled:bool,
|
||||||
|
fov_y:f64,
|
||||||
|
sens_x:f64,
|
||||||
|
vertical_sensitivity_multipler:f64,
|
||||||
|
turn_speed:f64,
|
||||||
|
}
|
||||||
|
impl PlaybackState{
|
||||||
|
pub fn new()->Self{
|
||||||
|
Self{
|
||||||
|
game_controls:v0::GameControls::empty(),
|
||||||
|
mouse_pos:v0::Vector2{x:0.0,y:0.0},
|
||||||
|
jump_count:0,
|
||||||
|
angles:v0::Vector3{x:0.0,y:0.0,z:0.0},
|
||||||
|
angles_delta:glam::Vec3::ZERO,
|
||||||
|
gravity:v0::Vector3{x:0.0,y:0.0,z:0.0},
|
||||||
|
runs:HashMap::new(),
|
||||||
|
style:v0::Style::Autohop,
|
||||||
|
absolute_sensitivity_enabled:false,
|
||||||
|
fov_y:1.0,
|
||||||
|
sens_x:0.3,
|
||||||
|
vertical_sensitivity_multipler:1.0,
|
||||||
|
turn_speed:core::f64::consts::TAU/0.715588,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn get_run(&self,mode:v0::ModeID)->Option<&Run>{
|
||||||
|
self.runs.get(&mode)
|
||||||
|
}
|
||||||
|
fn push_output(&mut self,event:&v0::OutputEvent){
|
||||||
|
// Jumps may occur during a substep
|
||||||
|
if event.tick_info.contains(v0::TickInfo::Jump){
|
||||||
|
self.jump_count+=1;
|
||||||
|
}
|
||||||
|
// Game tick "end", i.e. not a sub-step
|
||||||
|
if event.tick_info.contains(v0::TickInfo::TickEnd){
|
||||||
|
self.angles_delta=glam::vec3(event.angles.x,event.angles.y,event.angles.z)-glam::vec3(self.angles.x,self.angles.y,self.angles.z);
|
||||||
|
self.angles=event.angles;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn push_input(&mut self,event:&v0::InputEvent){
|
||||||
|
self.game_controls=event.game_controls;
|
||||||
|
self.mouse_pos=event.mouse_pos;
|
||||||
|
}
|
||||||
|
fn push_gravity(&mut self,event:&v0::GravityEvent){
|
||||||
|
self.gravity=event.gravity;
|
||||||
|
}
|
||||||
|
fn push_run(&mut self,event:&v0::Timed<v0::RunEvent>){
|
||||||
|
match &event.event{
|
||||||
|
v0::RunEvent::Prepare(run_event_prepare)=>{
|
||||||
|
self.runs.insert(run_event_prepare.mode,Run::new());
|
||||||
|
self.style=run_event_prepare.style;
|
||||||
|
},
|
||||||
|
v0::RunEvent::Start(run_event_zone)=>{
|
||||||
|
let time=crate::time::from_float(event.time).unwrap();
|
||||||
|
if let Some(run)=self.runs.get_mut(&run_event_zone.mode){
|
||||||
|
_=run.run.start(time);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
v0::RunEvent::Finish(run_event_zone)=>{
|
||||||
|
let time=crate::time::from_float(event.time).unwrap();
|
||||||
|
if let Some(run)=self.runs.get_mut(&run_event_zone.mode){
|
||||||
|
_=run.run.finish(time);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
v0::RunEvent::Clear(run_event_clear)=>{
|
||||||
|
match run_event_clear.mode{
|
||||||
|
v0::ModeSpec::Exactly(mode_id)=>{
|
||||||
|
self.runs.remove(&mode_id);
|
||||||
|
},
|
||||||
|
v0::ModeSpec::All=>{
|
||||||
|
self.runs.clear();
|
||||||
|
},
|
||||||
|
v0::ModeSpec::Invalid=>{
|
||||||
|
self.runs.retain(|_,run|!run.is_invalid());
|
||||||
|
},
|
||||||
|
v0::ModeSpec::InProgress=>{
|
||||||
|
self.runs.retain(|_,run|!run.is_in_progress());
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
v0::RunEvent::Flag(run_event_flag)=>{
|
||||||
|
match run_event_flag.mode{
|
||||||
|
v0::ModeSpec::Exactly(mode_id)=>{
|
||||||
|
if let Some(run)=self.runs.get_mut(&mode_id){
|
||||||
|
run.flag(run_event_flag.flag_reason);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
v0::ModeSpec::All=>{
|
||||||
|
for run in self.runs.values_mut(){
|
||||||
|
run.flag(run_event_flag.flag_reason);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
v0::ModeSpec::Invalid=>{
|
||||||
|
for run in self.runs.values_mut(){
|
||||||
|
if run.is_invalid(){
|
||||||
|
run.flag(run_event_flag.flag_reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
v0::ModeSpec::InProgress=>{
|
||||||
|
for run in self.runs.values_mut(){
|
||||||
|
if run.is_in_progress(){
|
||||||
|
run.flag(run_event_flag.flag_reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// these should never appear in a uploaded bot file,
|
||||||
|
// they are just part of the network protocol for spectating
|
||||||
|
// someone in practice mode.
|
||||||
|
//
|
||||||
|
// Yes, this is a design mistake.
|
||||||
|
// I didn't understand Session vs Simulation when I rewrote bhop in 2022
|
||||||
|
v0::RunEvent::LoadState(_run_event_practice)=>{},
|
||||||
|
v0::RunEvent::SaveState(_run_event_practice)=>{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn push_setting(&mut self,event:&v0::SettingEvent){
|
||||||
|
match event{
|
||||||
|
v0::SettingEvent::FieldOfView(setting_event_field_of_view)=>{
|
||||||
|
self.fov_y=(setting_event_field_of_view.fov*0.5).to_radians().tan();
|
||||||
|
},
|
||||||
|
v0::SettingEvent::Sensitivity(setting_event_sensitivity)=>{
|
||||||
|
self.sens_x=setting_event_sensitivity.sensitivity;
|
||||||
|
},
|
||||||
|
v0::SettingEvent::VerticalSensitivityMultiplier(setting_event_vertical_sensitivity_multiplier)=>{
|
||||||
|
self.vertical_sensitivity_multipler=setting_event_vertical_sensitivity_multiplier.multiplier;
|
||||||
|
},
|
||||||
|
v0::SettingEvent::AbsoluteSensitivity(setting_event_absolute_sensitivity)=>{
|
||||||
|
self.absolute_sensitivity_enabled=setting_event_absolute_sensitivity.enabled;
|
||||||
|
},
|
||||||
|
v0::SettingEvent::TurnSpeed(setting_event_turn_speed)=>{
|
||||||
|
self.turn_speed=setting_event_turn_speed.turn_speed;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub(crate) fn process_head(&mut self,block:&v0::Block,head:&v0::Head){
|
||||||
|
// Avoid running the realtime events from the beginning.
|
||||||
|
// Run the preceding input event to initialize the state.
|
||||||
|
if let Some(index)=head.get_event_index(v0::EventType::Input).checked_sub(1)
|
||||||
|
&&let Some(event)=block.input_events.get(index)
|
||||||
|
{
|
||||||
|
self.push_input(&event.event);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function
|
||||||
|
fn is_output_tick_end(&(_,event):&(usize,&v0::Timed<v0::OutputEvent>))->bool{
|
||||||
|
event.event.tick_info.contains(v0::TickInfo::TickEnd)
|
||||||
|
}
|
||||||
|
// Run two preceding output events to flush out the default state.
|
||||||
|
let output_end_index=head.get_event_index(v0::EventType::Output);
|
||||||
|
let mut it=block.output_events[..output_end_index].iter().enumerate().rev();
|
||||||
|
// Find two TickEnd events before output_end_index
|
||||||
|
let _first=it.find(is_output_tick_end);
|
||||||
|
let second=it.find(is_output_tick_end);
|
||||||
|
// Get the index at the second event, if two TickEnd events don't exist then start at 0
|
||||||
|
let output_start_index=second.map_or(0,|(i,_)|i);
|
||||||
|
for event in &block.output_events[output_start_index..output_end_index]{
|
||||||
|
self.push_output(&event.event);
|
||||||
|
}
|
||||||
|
|
||||||
|
// for event in &bot.sound_events[0..head.get_event_index(v0::EventType::Sound)]{
|
||||||
|
// self.push_sound(&event.event);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Offline events have to be run from the beginning because they contain cumulative state.
|
||||||
|
// for event in &bot.world_events[0..head.get_event_index(v0::EventType::World)]{
|
||||||
|
// self.push_world(&event.event);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Except for gravity, only the most recent event is relevant.
|
||||||
|
if let Some(index)=head.get_event_index(v0::EventType::Gravity).checked_sub(1)
|
||||||
|
&&let Some(event)=block.gravity_events.get(index)
|
||||||
|
{
|
||||||
|
self.push_gravity(&event.event);
|
||||||
|
}
|
||||||
|
for event in &block.run_events[0..head.get_event_index(v0::EventType::Run)]{
|
||||||
|
self.push_run(event);
|
||||||
|
}
|
||||||
|
// for event in &bot.camera_events[0..head.get_event_index(v0::EventType::Camera)]{
|
||||||
|
// self.push_camera(&event.event);
|
||||||
|
// }
|
||||||
|
for event in &block.setting_events[0..head.get_event_index(v0::EventType::Setting)]{
|
||||||
|
self.push_setting(&event.event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub(crate) fn process_event(&mut self,block:&v0::Block,event_type:v0::EventType,event_index:usize){
|
||||||
|
match event_type{
|
||||||
|
v0::EventType::Input=>self.push_input(&block.input_events[event_index].event),
|
||||||
|
v0::EventType::Output=>self.push_output(&block.output_events[event_index].event),
|
||||||
|
v0::EventType::Sound=>{},
|
||||||
|
v0::EventType::World=>{},
|
||||||
|
v0::EventType::Gravity=>self.push_gravity(&block.gravity_events[event_index].event),
|
||||||
|
v0::EventType::Run=>self.push_run(&block.run_events[event_index]),
|
||||||
|
v0::EventType::Camera=>{},
|
||||||
|
v0::EventType::Setting=>self.push_setting(&block.setting_events[event_index].event),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub const fn get_fov_y(&self)->f64{
|
||||||
|
let zoom_enabled=self.game_controls.contains(v0::GameControls::Zoom);
|
||||||
|
if zoom_enabled{self.fov_y*0.2}else{self.fov_y}
|
||||||
|
}
|
||||||
|
pub const fn get_sensitivity(&self)->glam::DVec2{
|
||||||
|
if self.absolute_sensitivity_enabled{
|
||||||
|
glam::dvec2(self.sens_x,self.sens_x*self.vertical_sensitivity_multipler)
|
||||||
|
}else{
|
||||||
|
let sens_x=self.sens_x*self.get_fov_y()/128.0;
|
||||||
|
glam::dvec2(sens_x,sens_x*self.vertical_sensitivity_multipler)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub const fn get_controls(&self)->v0::GameControls{
|
||||||
|
self.game_controls
|
||||||
|
}
|
||||||
|
pub const fn get_jump_count(&self)->u32{
|
||||||
|
self.jump_count
|
||||||
|
}
|
||||||
|
pub const fn get_gravity(&self)->v0::Vector3{
|
||||||
|
self.gravity
|
||||||
|
}
|
||||||
|
pub const fn get_angles_delta(&self)->glam::Vec3{
|
||||||
|
self.angles_delta
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
/// A render surface configuration, containing information such as resolution and pixel format
|
|
||||||
pub struct Surface{}
|
|
||||||
32
lib/src/time.rs
Normal file
32
lib/src/time.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
use strafesnet_common::integer::Time;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Error{
|
||||||
|
Underflow,
|
||||||
|
Overflow,
|
||||||
|
Nan,
|
||||||
|
}
|
||||||
|
impl std::fmt::Display for Error{
|
||||||
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
|
write!(f,"{self:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::error::Error for Error{}
|
||||||
|
|
||||||
|
pub fn from_float<T>(time:f64)->Result<Time<T>,Error>{
|
||||||
|
match time.classify(){
|
||||||
|
core::num::FpCategory::Nan=>Err(Error::Nan),
|
||||||
|
core::num::FpCategory::Zero=>Ok(Time::ZERO),
|
||||||
|
core::num::FpCategory::Infinite
|
||||||
|
|core::num::FpCategory::Subnormal
|
||||||
|
|core::num::FpCategory::Normal=>{
|
||||||
|
if time<Time::<T>::MIN.get() as f64{
|
||||||
|
return Err(Error::Underflow);
|
||||||
|
}
|
||||||
|
if (Time::<T>::MAX.get() as f64)<time{
|
||||||
|
return Err(Error::Overflow);
|
||||||
|
}
|
||||||
|
Ok(Time::raw((time*Time::<T>::ONE_SECOND.get() as f64) as i64))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,11 +5,11 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pollster = "0.4.0"
|
pollster = "0.4.0"
|
||||||
strafesnet_roblox_bot_player = { version = "0.1.0", path = "../lib" }
|
|
||||||
wgpu = "28.0.0"
|
|
||||||
winit = "0.30.12"
|
winit = "0.30.12"
|
||||||
|
glam.workspace = true
|
||||||
|
wgpu.workspace = true
|
||||||
|
strafesnet_roblox_bot_player.workspace = true
|
||||||
strafesnet_common.workspace = true
|
strafesnet_common.workspace = true
|
||||||
strafesnet_graphics.workspace = true
|
strafesnet_graphics.workspace = true
|
||||||
strafesnet_roblox_bot_file.workspace = true
|
strafesnet_roblox_bot_file.workspace = true
|
||||||
strafesnet_snf.workspace = true
|
strafesnet_snf.workspace = true
|
||||||
glam = "0.31.0"
|
|
||||||
|
|||||||
@@ -1,21 +1,11 @@
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
#[cfg(any(feature="roblox",feature="source"))]
|
|
||||||
use strafesnet_deferred_loader::deferred_loader::LoadFailureMode;
|
|
||||||
|
|
||||||
#[expect(dead_code)]
|
#[expect(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ReadError{
|
pub enum ReadError{
|
||||||
#[cfg(feature="roblox")]
|
|
||||||
Roblox(strafesnet_rbx_loader::ReadError),
|
|
||||||
#[cfg(feature="source")]
|
|
||||||
Source(strafesnet_bsp_loader::ReadError),
|
|
||||||
#[cfg(feature="snf")]
|
|
||||||
StrafesNET(strafesnet_snf::Error),
|
StrafesNET(strafesnet_snf::Error),
|
||||||
#[cfg(feature="snf")]
|
|
||||||
StrafesNETMap(strafesnet_snf::map::Error),
|
StrafesNETMap(strafesnet_snf::map::Error),
|
||||||
#[cfg(feature="snf")]
|
RobloxBot(strafesnet_roblox_bot_file::v0::Error),
|
||||||
StrafesNETBot(strafesnet_snf::bot::Error),
|
|
||||||
Io(std::io::Error),
|
Io(std::io::Error),
|
||||||
UnknownFileFormat,
|
UnknownFileFormat,
|
||||||
}
|
}
|
||||||
@@ -27,14 +17,8 @@ impl std::fmt::Display for ReadError{
|
|||||||
impl std::error::Error for ReadError{}
|
impl std::error::Error for ReadError{}
|
||||||
|
|
||||||
pub enum ReadFormat{
|
pub enum ReadFormat{
|
||||||
#[cfg(feature="roblox")]
|
|
||||||
Roblox(strafesnet_rbx_loader::Model),
|
|
||||||
#[cfg(feature="source")]
|
|
||||||
Source(strafesnet_bsp_loader::Bsp),
|
|
||||||
#[cfg(feature="snf")]
|
|
||||||
SNFM(strafesnet_common::map::CompleteMap),
|
SNFM(strafesnet_common::map::CompleteMap),
|
||||||
#[cfg(feature="snf")]
|
QBOT(strafesnet_roblox_bot_file::v0::Block),
|
||||||
SNFB(strafesnet_snf::bot::Segment),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read<R:Read+std::io::Seek>(input:R)->Result<ReadFormat,ReadError>{
|
pub fn read<R:Read+std::io::Seek>(input:R)->Result<ReadFormat,ReadError>{
|
||||||
@@ -45,19 +29,12 @@ pub fn read<R:Read+std::io::Seek>(input:R)->Result<ReadFormat,ReadError>{
|
|||||||
buf.read_to_end(&mut entire_file).map_err(ReadError::Io)?;
|
buf.read_to_end(&mut entire_file).map_err(ReadError::Io)?;
|
||||||
let cursor=std::io::Cursor::new(entire_file);
|
let cursor=std::io::Cursor::new(entire_file);
|
||||||
match peek.as_slice(){
|
match peek.as_slice(){
|
||||||
#[cfg(feature="roblox")]
|
|
||||||
b"<rob"=>Ok(ReadFormat::Roblox(strafesnet_rbx_loader::read(cursor).map_err(ReadError::Roblox)?)),
|
|
||||||
#[cfg(feature="source")]
|
|
||||||
b"VBSP"=>Ok(ReadFormat::Source(strafesnet_bsp_loader::read(cursor).map_err(ReadError::Source)?)),
|
|
||||||
#[cfg(feature="snf")]
|
|
||||||
b"SNFM"=>Ok(ReadFormat::SNFM(
|
b"SNFM"=>Ok(ReadFormat::SNFM(
|
||||||
strafesnet_snf::read_map(cursor).map_err(ReadError::StrafesNET)?
|
strafesnet_snf::read_map(cursor).map_err(ReadError::StrafesNET)?
|
||||||
.into_complete_map().map_err(ReadError::StrafesNETMap)?
|
.into_complete_map().map_err(ReadError::StrafesNETMap)?
|
||||||
)),
|
)),
|
||||||
#[cfg(feature="snf")]
|
b"qbot"=>Ok(ReadFormat::QBOT(
|
||||||
b"SNFB"=>Ok(ReadFormat::SNFB(
|
strafesnet_roblox_bot_file::v0::read_all_to_block(cursor).map_err(ReadError::RobloxBot)?
|
||||||
strafesnet_snf::read_bot(cursor).map_err(ReadError::StrafesNET)?
|
|
||||||
.read_all().map_err(ReadError::StrafesNETBot)?
|
|
||||||
)),
|
)),
|
||||||
_=>Err(ReadError::UnknownFileFormat),
|
_=>Err(ReadError::UnknownFileFormat),
|
||||||
}
|
}
|
||||||
@@ -68,10 +45,6 @@ pub fn read<R:Read+std::io::Seek>(input:R)->Result<ReadFormat,ReadError>{
|
|||||||
pub enum LoadError{
|
pub enum LoadError{
|
||||||
ReadError(ReadError),
|
ReadError(ReadError),
|
||||||
File(std::io::Error),
|
File(std::io::Error),
|
||||||
#[cfg(feature="roblox")]
|
|
||||||
LoadRoblox(strafesnet_rbx_loader::LoadError),
|
|
||||||
#[cfg(feature="source")]
|
|
||||||
LoadSource(strafesnet_bsp_loader::LoadError),
|
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for LoadError{
|
impl std::fmt::Display for LoadError{
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
@@ -81,36 +54,15 @@ impl std::fmt::Display for LoadError{
|
|||||||
impl std::error::Error for LoadError{}
|
impl std::error::Error for LoadError{}
|
||||||
|
|
||||||
pub enum LoadFormat{
|
pub enum LoadFormat{
|
||||||
#[cfg(any(feature="snf",feature="roblox",feature="source"))]
|
|
||||||
Map(strafesnet_common::map::CompleteMap),
|
Map(strafesnet_common::map::CompleteMap),
|
||||||
#[cfg(feature="snf")]
|
Bot(strafesnet_roblox_bot_file::v0::Block),
|
||||||
Bot(strafesnet_snf::bot::Segment),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<LoadFormat,LoadError>{
|
pub fn load<P:AsRef<std::path::Path>>(path:P)->Result<LoadFormat,LoadError>{
|
||||||
//blocking because it's simpler...
|
//blocking because it's simpler...
|
||||||
let file=std::fs::File::open(path).map_err(LoadError::File)?;
|
let file=std::fs::File::open(path).map_err(LoadError::File)?;
|
||||||
match read(file).map_err(LoadError::ReadError)?{
|
match read(file).map_err(LoadError::ReadError)?{
|
||||||
#[cfg(feature="snf")]
|
ReadFormat::QBOT(bot)=>Ok(LoadFormat::Bot(bot)),
|
||||||
ReadFormat::SNFB(bot)=>Ok(LoadFormat::Bot(bot)),
|
|
||||||
#[cfg(feature="snf")]
|
|
||||||
ReadFormat::SNFM(map)=>Ok(LoadFormat::Map(map)),
|
ReadFormat::SNFM(map)=>Ok(LoadFormat::Map(map)),
|
||||||
#[cfg(feature="roblox")]
|
|
||||||
ReadFormat::Roblox(model)=>{
|
|
||||||
let mut place=strafesnet_rbx_loader::Place::from(model);
|
|
||||||
let script_errors=place.run_scripts().unwrap();
|
|
||||||
for error in script_errors{
|
|
||||||
println!("Script error: {error}");
|
|
||||||
}
|
|
||||||
let (map,errors)=place.to_snf(LoadFailureMode::DefaultToNone).map_err(LoadError::LoadRoblox)?;
|
|
||||||
if errors.count()!=0{
|
|
||||||
print!("Errors encountered while loading the map:\n{}",errors);
|
|
||||||
}
|
|
||||||
Ok(LoadFormat::Map(map))
|
|
||||||
},
|
|
||||||
#[cfg(feature="source")]
|
|
||||||
ReadFormat::Source(bsp)=>Ok(LoadFormat::Map(
|
|
||||||
bsp.to_snf(LoadFailureMode::DefaultToNone,&[]).map_err(LoadError::LoadSource)?
|
|
||||||
)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
use strafesnet_common::instruction::TimedInstruction;
|
use strafesnet_common::instruction::TimedInstruction;
|
||||||
use strafesnet_common::session::Time as SessionTime;
|
use strafesnet_common::session::Time as SessionTime;
|
||||||
use strafesnet_roblox_bot_player::{bot::CompleteBot,graphics::Graphics,head::PlaybackHead};
|
use strafesnet_common::timer::TimerState;
|
||||||
|
use strafesnet_roblox_bot_player::{bot::CompleteBot,graphics::Graphics,head::{PlaybackHead,Time as PlaybackTime}};
|
||||||
|
use strafesnet_graphics::surface::Surface;
|
||||||
|
|
||||||
pub enum SessionControlInstruction{
|
pub enum SessionControlInstruction{
|
||||||
SetPaused(bool),
|
SetPaused(bool),
|
||||||
}
|
Restart,
|
||||||
pub enum SessionPlaybackInstruction{
|
|
||||||
SkipForward,
|
SkipForward,
|
||||||
SkipBack,
|
SkipBack,
|
||||||
DecreaseTimescale,
|
DecreaseTimescale,
|
||||||
@@ -14,42 +15,100 @@ pub enum SessionPlaybackInstruction{
|
|||||||
|
|
||||||
pub enum Instruction{
|
pub enum Instruction{
|
||||||
SessionControl(SessionControlInstruction),
|
SessionControl(SessionControlInstruction),
|
||||||
SessionPlayback(SessionPlaybackInstruction),
|
|
||||||
Render,
|
Render,
|
||||||
Resize(winit::dpi::PhysicalSize<u32>),
|
Resize(winit::dpi::PhysicalSize<u32>),
|
||||||
|
ChangeMap(strafesnet_common::map::CompleteMap),
|
||||||
|
LoadReplay(strafesnet_roblox_bot_file::v0::Block),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn speed_ratio(speed:i8)->strafesnet_common::integer::Ratio64{
|
||||||
|
if speed.is_negative(){
|
||||||
|
strafesnet_common::integer::Ratio64::new(4i64.pow(-speed as u32),5u64.pow(-speed as u32)).unwrap()
|
||||||
|
}else{
|
||||||
|
strafesnet_common::integer::Ratio64::new(5i64.pow(speed as u32),4u64.pow(speed as u32)).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Playback{
|
||||||
|
bot:CompleteBot,
|
||||||
|
playback_head:PlaybackHead,
|
||||||
|
playback_speed:i8,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PlayerWorker<'a>{
|
pub struct PlayerWorker<'a>{
|
||||||
surface:wgpu::Surface<'a>,
|
|
||||||
graphics_thread:Graphics,
|
graphics_thread:Graphics,
|
||||||
bot:CompleteBot,
|
surface:Surface<'a>,
|
||||||
playback_head:PlaybackHead,
|
playback:Option<Playback>,
|
||||||
}
|
}
|
||||||
impl<'a> PlayerWorker<'a>{
|
impl<'a> PlayerWorker<'a>{
|
||||||
pub fn new(
|
pub fn new(
|
||||||
surface:wgpu::Surface<'a>,
|
|
||||||
bot:CompleteBot,
|
|
||||||
graphics_thread:Graphics,
|
graphics_thread:Graphics,
|
||||||
|
surface:Surface<'a>,
|
||||||
)->Self{
|
)->Self{
|
||||||
let playback_head=PlaybackHead::new(SessionTime::ZERO);
|
|
||||||
Self{
|
Self{
|
||||||
surface,
|
|
||||||
graphics_thread,
|
graphics_thread,
|
||||||
bot,
|
surface,
|
||||||
playback_head,
|
playback:None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn send(&mut self,ins:TimedInstruction<Instruction,SessionTime>){
|
pub fn send(&mut self,device:&wgpu::Device,queue:&wgpu::Queue,ins:TimedInstruction<Instruction,SessionTime>){
|
||||||
match ins.instruction{
|
match ins.instruction{
|
||||||
Instruction::SessionControl(session_control_instruction)=>{},
|
Instruction::SessionControl(SessionControlInstruction::SetPaused(paused))=>if let Some(playback)=&mut self.playback{
|
||||||
Instruction::SessionPlayback(session_playback_instruction)=>{},
|
playback.playback_head.set_paused(ins.time,paused);
|
||||||
Instruction::Render=>{
|
|
||||||
self.playback_head.advance_time(&self.bot,ins.time);
|
|
||||||
let (pos,angles)=self.playback_head.get_position_angles(&self.bot,ins.time);
|
|
||||||
self.graphics_thread.render(&self.surface,pos,angles);
|
|
||||||
},
|
},
|
||||||
Instruction::Resize(physical_size)=>{
|
Instruction::SessionControl(SessionControlInstruction::Restart)=>if let Some(playback)=&mut self.playback{
|
||||||
self.graphics_thread.resize(&self.surface,glam::uvec2(physical_size.width,physical_size.height));
|
playback.playback_head.set_time(&playback.bot,ins.time,PlaybackTime::ZERO);
|
||||||
|
},
|
||||||
|
Instruction::SessionControl(SessionControlInstruction::SkipForward)=>if let Some(playback)=&mut self.playback{
|
||||||
|
let head_time=playback.playback_head.timer().clone().into_state().0.get_time(ins.time+SessionTime::from_secs(2));
|
||||||
|
playback.playback_head.set_time(&playback.bot,ins.time,head_time);
|
||||||
|
},
|
||||||
|
Instruction::SessionControl(SessionControlInstruction::SkipBack)=>if let Some(playback)=&mut self.playback{
|
||||||
|
let head_time=playback.playback_head.timer().clone().into_state().0.get_time(ins.time-SessionTime::from_secs(2));
|
||||||
|
playback.playback_head.set_time(&playback.bot,ins.time,head_time);
|
||||||
|
},
|
||||||
|
Instruction::SessionControl(SessionControlInstruction::DecreaseTimescale)=>if let Some(playback)=&mut self.playback{
|
||||||
|
playback.playback_speed=playback.playback_speed.saturating_sub(1).max(-27);
|
||||||
|
playback.playback_head.set_scale(ins.time,speed_ratio(playback.playback_speed));
|
||||||
|
},
|
||||||
|
Instruction::SessionControl(SessionControlInstruction::IncreaseTimescale)=>if let Some(playback)=&mut self.playback{
|
||||||
|
playback.playback_speed=playback.playback_speed.saturating_add(1).min(27);
|
||||||
|
playback.playback_head.set_scale(ins.time,speed_ratio(playback.playback_speed));
|
||||||
|
},
|
||||||
|
Instruction::Render=>if let Some(playback)=&mut self.playback{
|
||||||
|
playback.playback_head.advance_time(&playback.bot,ins.time);
|
||||||
|
let (pos,angles)=playback.playback_head.get_position_angles(&playback.bot,ins.time);
|
||||||
|
|
||||||
|
//this has to go deeper somehow
|
||||||
|
let frame=self.surface.new_frame(device);
|
||||||
|
|
||||||
|
let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None});
|
||||||
|
|
||||||
|
self.graphics_thread.encode_commands(&mut encoder,frame.view(),pos,angles);
|
||||||
|
|
||||||
|
queue.submit([encoder.finish()]);
|
||||||
|
|
||||||
|
frame.present();
|
||||||
|
},
|
||||||
|
Instruction::Resize(physical_size)=>if let Some(playback)=&self.playback{
|
||||||
|
let fov_y=playback.playback_head.state().get_fov_y();
|
||||||
|
let fov_x=fov_y*physical_size.width as f64/physical_size.height as f64;
|
||||||
|
let fov=glam::vec2(fov_x as f32,fov_y as f32);
|
||||||
|
let size=glam::uvec2(physical_size.width,physical_size.height);
|
||||||
|
self.surface.configure(device,size);
|
||||||
|
self.graphics_thread.resize(device,size,fov);
|
||||||
|
},
|
||||||
|
Instruction::ChangeMap(complete_map)=>{
|
||||||
|
self.graphics_thread.change_map(device,queue,&complete_map);
|
||||||
|
},
|
||||||
|
Instruction::LoadReplay(bot)=>{
|
||||||
|
let bot=CompleteBot::new(bot);
|
||||||
|
let playback_head=PlaybackHead::new(&bot,SessionTime::ZERO);
|
||||||
|
self.playback=Some(Playback{
|
||||||
|
bot,
|
||||||
|
playback_head,
|
||||||
|
playback_speed:0,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ pub async fn setup_and_start(title:&str){
|
|||||||
|
|
||||||
let adapter=setup::step3::pick_adapter(&instance,&surface).await.expect("No suitable GPU adapters found on the system!");
|
let adapter=setup::step3::pick_adapter(&instance,&surface).await.expect("No suitable GPU adapters found on the system!");
|
||||||
|
|
||||||
let (device,queue)=setup::step4::request_device(&adapter).await;
|
let (device,queue)=setup::step4::request_device(&adapter).await.unwrap();
|
||||||
|
|
||||||
let size=window.inner_size();
|
let size=window.inner_size();
|
||||||
let config=setup::step5::configure_surface(&adapter,&device,&surface,(size.width,size.height));
|
let surface=setup::step5::configure_surface(&adapter,&device,surface,(size.width,size.height)).unwrap();
|
||||||
|
|
||||||
//dedicated thread to ping request redraw back and resize the window doesn't seem logical
|
//dedicated thread to ping request redraw back and resize the window doesn't seem logical
|
||||||
|
|
||||||
@@ -32,7 +32,6 @@ pub async fn setup_and_start(title:&str){
|
|||||||
device,
|
device,
|
||||||
queue,
|
queue,
|
||||||
surface,
|
surface,
|
||||||
config,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
for arg in std::env::args().skip(1){
|
for arg in std::env::args().skip(1){
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
use strafesnet_common::instruction::TimedInstruction;
|
use strafesnet_common::instruction::TimedInstruction;
|
||||||
use strafesnet_common::session::Time as SessionTime;
|
use strafesnet_common::session::Time as SessionTime;
|
||||||
use strafesnet_common::physics::{MiscInstruction,SetControlInstruction};
|
|
||||||
use crate::file::LoadFormat;
|
use crate::file::LoadFormat;
|
||||||
use crate::player::{PlayerWorker,Instruction as PhysicsWorkerInstruction,SessionControlInstruction,SessionPlaybackInstruction};
|
use crate::player::{PlayerWorker,Instruction as PhysicsWorkerInstruction,SessionControlInstruction};
|
||||||
|
|
||||||
pub enum Instruction{
|
pub enum Instruction{
|
||||||
WindowEvent(winit::event::WindowEvent),
|
WindowEvent(winit::event::WindowEvent),
|
||||||
@@ -11,53 +10,23 @@ pub enum Instruction{
|
|||||||
|
|
||||||
//holds thread handles to dispatch to
|
//holds thread handles to dispatch to
|
||||||
pub struct WindowContext<'a>{
|
pub struct WindowContext<'a>{
|
||||||
manual_mouse_lock:bool,
|
|
||||||
mouse_pos:glam::DVec2,
|
|
||||||
simulation_paused:bool,
|
simulation_paused:bool,
|
||||||
screen_size:glam::UVec2,
|
|
||||||
window:&'a winit::window::Window,
|
window:&'a winit::window::Window,
|
||||||
physics_thread:PlayerWorker<'a>,
|
physics_thread:PlayerWorker<'a>,
|
||||||
|
device:wgpu::Device,
|
||||||
|
queue:wgpu::Queue,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowContext<'_>{
|
impl WindowContext<'_>{
|
||||||
fn get_middle_of_screen(&self)->winit::dpi::PhysicalPosition<u32>{
|
fn phys(&mut self,ins:TimedInstruction<crate::player::Instruction,strafesnet_common::session::Time>){
|
||||||
winit::dpi::PhysicalPosition::new(self.screen_size.x/2,self.screen_size.y/2)
|
self.physics_thread.send(&self.device,&self.queue,ins);
|
||||||
}
|
|
||||||
fn free_mouse(&mut self){
|
|
||||||
self.manual_mouse_lock=false;
|
|
||||||
match self.window.set_cursor_position(self.get_middle_of_screen()){
|
|
||||||
Ok(())=>(),
|
|
||||||
Err(e)=>println!("Could not set cursor position: {:?}",e),
|
|
||||||
}
|
|
||||||
match self.window.set_cursor_grab(winit::window::CursorGrabMode::None){
|
|
||||||
Ok(())=>(),
|
|
||||||
Err(e)=>println!("Could not release cursor: {:?}",e),
|
|
||||||
}
|
|
||||||
self.window.set_cursor_visible(true);
|
|
||||||
}
|
|
||||||
fn lock_mouse(&mut self){
|
|
||||||
//if cursor is outside window don't lock but apparently there's no get pos function
|
|
||||||
//let pos=window.get_cursor_pos();
|
|
||||||
match self.window.set_cursor_grab(winit::window::CursorGrabMode::Locked){
|
|
||||||
Ok(())=>(),
|
|
||||||
Err(_)=>{
|
|
||||||
match self.window.set_cursor_grab(winit::window::CursorGrabMode::Confined){
|
|
||||||
Ok(())=>(),
|
|
||||||
Err(e)=>{
|
|
||||||
self.manual_mouse_lock=true;
|
|
||||||
println!("Could not confine cursor: {:?}",e)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.window.set_cursor_visible(false);
|
|
||||||
}
|
}
|
||||||
fn window_event(&mut self,time:SessionTime,event:winit::event::WindowEvent){
|
fn window_event(&mut self,time:SessionTime,event:winit::event::WindowEvent){
|
||||||
match event{
|
match event{
|
||||||
winit::event::WindowEvent::DroppedFile(path)=>{
|
winit::event::WindowEvent::DroppedFile(path)=>{
|
||||||
match crate::file::load(path.as_path()){
|
match crate::file::load(path.as_path()){
|
||||||
// Ok(LoadFormat::Map(map))=>self.physics_thread.send(TimedInstruction{time,instruction:PhysicsWorkerInstruction::ChangeMap(map)}),
|
Ok(LoadFormat::Map(map))=>self.phys(TimedInstruction{time,instruction:PhysicsWorkerInstruction::ChangeMap(map)}),
|
||||||
// Ok(LoadFormat::Bot(bot))=>self.physics_thread.send(TimedInstruction{time,instruction:PhysicsWorkerInstruction::LoadReplay(bot)}),
|
Ok(LoadFormat::Bot(bot))=>self.phys(TimedInstruction{time,instruction:PhysicsWorkerInstruction::LoadReplay(bot)}),
|
||||||
Err(e)=>println!("Failed to load file: {e}"),
|
Err(e)=>println!("Failed to load file: {e}"),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -67,7 +36,7 @@ impl WindowContext<'_>{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//pause unpause
|
//pause unpause
|
||||||
self.physics_thread.send(TimedInstruction{
|
self.phys(TimedInstruction{
|
||||||
time,
|
time,
|
||||||
instruction:PhysicsWorkerInstruction::SessionControl(SessionControlInstruction::SetPaused(!state)),
|
instruction:PhysicsWorkerInstruction::SessionControl(SessionControlInstruction::SetPaused(!state)),
|
||||||
});
|
});
|
||||||
@@ -78,8 +47,6 @@ impl WindowContext<'_>{
|
|||||||
..
|
..
|
||||||
}=>{
|
}=>{
|
||||||
match (logical_key,state){
|
match (logical_key,state){
|
||||||
(winit::keyboard::Key::Named(winit::keyboard::NamedKey::Tab),winit::event::ElementState::Pressed)=>self.free_mouse(),
|
|
||||||
(winit::keyboard::Key::Named(winit::keyboard::NamedKey::Tab),winit::event::ElementState::Released)=>self.lock_mouse(),
|
|
||||||
(winit::keyboard::Key::Named(winit::keyboard::NamedKey::F11),winit::event::ElementState::Pressed)=>{
|
(winit::keyboard::Key::Named(winit::keyboard::NamedKey::F11),winit::event::ElementState::Pressed)=>{
|
||||||
if self.window.fullscreen().is_some(){
|
if self.window.fullscreen().is_some(){
|
||||||
self.window.set_fullscreen(None);
|
self.window.set_fullscreen(None);
|
||||||
@@ -87,77 +54,41 @@ impl WindowContext<'_>{
|
|||||||
self.window.set_fullscreen(Some(winit::window::Fullscreen::Borderless(None)));
|
self.window.set_fullscreen(Some(winit::window::Fullscreen::Borderless(None)));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape),winit::event::ElementState::Pressed)=>{
|
|
||||||
self.manual_mouse_lock=false;
|
|
||||||
match self.window.set_cursor_grab(winit::window::CursorGrabMode::None){
|
|
||||||
Ok(())=>(),
|
|
||||||
Err(e)=>println!("Could not release cursor: {:?}",e),
|
|
||||||
}
|
|
||||||
self.window.set_cursor_visible(true);
|
|
||||||
},
|
|
||||||
(keycode,state)=>{
|
(keycode,state)=>{
|
||||||
let s=state.is_pressed();
|
let s=state.is_pressed();
|
||||||
|
|
||||||
// internal variants for this scope
|
|
||||||
enum SessionInstructionSubset{
|
|
||||||
Control(SessionControlInstruction),
|
|
||||||
Playback(SessionPlaybackInstruction),
|
|
||||||
}
|
|
||||||
macro_rules! session_ctrl{
|
macro_rules! session_ctrl{
|
||||||
($variant:ident,$state:expr)=>{
|
($variant:ident,$state:expr)=>{
|
||||||
s.then_some(SessionInstructionSubset::Control(SessionControlInstruction::$variant))
|
s.then_some(PhysicsWorkerInstruction::SessionControl(SessionControlInstruction::$variant))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
macro_rules! session_playback{
|
|
||||||
($variant:ident,$state:expr)=>{
|
|
||||||
s.then_some(SessionInstructionSubset::Playback(SessionPlaybackInstruction::$variant))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
impl From<SessionInstructionSubset> for PhysicsWorkerInstruction{
|
|
||||||
fn from(value:SessionInstructionSubset)->Self{
|
|
||||||
match value{
|
|
||||||
SessionInstructionSubset::Control(session_control_instruction)=>PhysicsWorkerInstruction::SessionControl(session_control_instruction),
|
|
||||||
SessionInstructionSubset::Playback(session_playback_instruction)=>PhysicsWorkerInstruction::SessionPlayback(session_playback_instruction),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(session_instruction)=match keycode{
|
if let Some(instruction)=match keycode{
|
||||||
// TODO: bind system so playback pausing can use spacebar
|
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Space)=>if s{
|
||||||
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Enter)=>if s{
|
|
||||||
let paused=!self.simulation_paused;
|
let paused=!self.simulation_paused;
|
||||||
self.simulation_paused=paused;
|
self.simulation_paused=paused;
|
||||||
if paused{
|
Some(PhysicsWorkerInstruction::SessionControl(SessionControlInstruction::SetPaused(paused)))
|
||||||
self.free_mouse();
|
|
||||||
}else{
|
|
||||||
self.lock_mouse();
|
|
||||||
}
|
|
||||||
Some(SessionInstructionSubset::Control(SessionControlInstruction::SetPaused(paused)))
|
|
||||||
}else{None},
|
}else{None},
|
||||||
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowUp)=>session_playback!(IncreaseTimescale,s),
|
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowUp)=>session_ctrl!(IncreaseTimescale,s),
|
||||||
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowDown)=>session_playback!(DecreaseTimescale,s),
|
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowDown)=>session_ctrl!(DecreaseTimescale,s),
|
||||||
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowLeft)=>session_playback!(SkipBack,s),
|
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowLeft)=>session_ctrl!(SkipBack,s),
|
||||||
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowRight)=>session_playback!(SkipForward,s),
|
winit::keyboard::Key::Named(winit::keyboard::NamedKey::ArrowRight)=>session_ctrl!(SkipForward,s),
|
||||||
winit::keyboard::Key::Character(key)=>match key.as_str(){
|
winit::keyboard::Key::Character(key)=>match key.as_str(){
|
||||||
// "R"|"r"=>s.then(||{
|
"R"|"r"=>session_ctrl!(Restart,s),
|
||||||
// //mouse needs to be reset since the position is absolute
|
|
||||||
// self.mouse_pos=glam::DVec2::ZERO;
|
|
||||||
// SessionInstructionSubset::Input(SessionInputInstruction::Mode(session::ImplicitModeInstruction::ResetAndRestart))
|
|
||||||
// }),
|
|
||||||
_=>None,
|
_=>None,
|
||||||
},
|
},
|
||||||
_=>None,
|
_=>None,
|
||||||
}{
|
}{
|
||||||
self.physics_thread.send(TimedInstruction{
|
self.phys(TimedInstruction{
|
||||||
time,
|
time,
|
||||||
instruction:session_instruction.into(),
|
instruction,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
winit::event::WindowEvent::Resized(size)=>{
|
winit::event::WindowEvent::Resized(size)=>{
|
||||||
self.physics_thread.send(
|
self.phys(
|
||||||
TimedInstruction{
|
TimedInstruction{
|
||||||
time,
|
time,
|
||||||
instruction:PhysicsWorkerInstruction::Resize(size)
|
instruction:PhysicsWorkerInstruction::Resize(size)
|
||||||
@@ -166,7 +97,7 @@ impl WindowContext<'_>{
|
|||||||
},
|
},
|
||||||
winit::event::WindowEvent::RedrawRequested=>{
|
winit::event::WindowEvent::RedrawRequested=>{
|
||||||
self.window.request_redraw();
|
self.window.request_redraw();
|
||||||
self.physics_thread.send(
|
self.phys(
|
||||||
TimedInstruction{
|
TimedInstruction{
|
||||||
time,
|
time,
|
||||||
instruction:PhysicsWorkerInstruction::Render
|
instruction:PhysicsWorkerInstruction::Render
|
||||||
@@ -177,7 +108,7 @@ impl WindowContext<'_>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn device_event(&mut self,time:SessionTime,event:winit::event::DeviceEvent){
|
fn device_event(&mut self,_time:SessionTime,_event:winit::event::DeviceEvent){
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(&mut self,ins:TimedInstruction<Instruction,SessionTime>){
|
pub fn send(&mut self,ins:TimedInstruction<Instruction,SessionTime>){
|
||||||
@@ -195,28 +126,19 @@ impl WindowContext<'_>{
|
|||||||
window:&'a winit::window::Window,
|
window:&'a winit::window::Window,
|
||||||
device:wgpu::Device,
|
device:wgpu::Device,
|
||||||
queue:wgpu::Queue,
|
queue:wgpu::Queue,
|
||||||
surface:wgpu::Surface<'a>,
|
surface:strafesnet_graphics::surface::Surface<'a>,
|
||||||
config:wgpu::SurfaceConfiguration,
|
|
||||||
)->WindowContext<'a>{
|
)->WindowContext<'a>{
|
||||||
let screen_size=glam::uvec2(config.width,config.height);
|
let size=surface.size();
|
||||||
let bot=include_bytes!("../../web-demo/bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d.qbot");
|
let graphics=strafesnet_roblox_bot_player::graphics::Graphics::new(&device,&queue,size,surface.view_format());
|
||||||
let map=include_bytes!("../../web-demo/bhop_marble_5692093612.snfm");
|
|
||||||
let bot=strafesnet_roblox_bot_player::bot::CompleteBot::new(bot).unwrap();
|
|
||||||
let map=strafesnet_roblox_bot_player::map::CompleteMap::new(map).unwrap();
|
|
||||||
let mut graphics=strafesnet_roblox_bot_player::graphics::Graphics::new(device,queue,config);
|
|
||||||
graphics.change_map(&map);
|
|
||||||
WindowContext{
|
WindowContext{
|
||||||
manual_mouse_lock:false,
|
|
||||||
mouse_pos:glam::DVec2::ZERO,
|
|
||||||
simulation_paused:false,
|
simulation_paused:false,
|
||||||
//make sure to update this!!!!!
|
|
||||||
screen_size,
|
|
||||||
window,
|
window,
|
||||||
physics_thread:crate::player::PlayerWorker::new(
|
physics_thread:crate::player::PlayerWorker::new(
|
||||||
surface,
|
|
||||||
bot,
|
|
||||||
graphics,
|
graphics,
|
||||||
|
surface,
|
||||||
),
|
),
|
||||||
|
device,
|
||||||
|
queue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
video-encoder/Cargo.toml
Normal file
16
video-encoder/Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[package]
|
||||||
|
name = "video-encoder"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
glam.workspace = true
|
||||||
|
wgpu.workspace = true
|
||||||
|
strafesnet_roblox_bot_player.workspace = true
|
||||||
|
strafesnet_common.workspace = true
|
||||||
|
strafesnet_graphics.workspace = true
|
||||||
|
strafesnet_roblox_bot_file.workspace = true
|
||||||
|
strafesnet_snf.workspace = true
|
||||||
|
vk-video = "0.2.0"
|
||||||
|
clap = { version = "4.5.60", features = ["derive"] }
|
||||||
|
mp4 = "0.14.0"
|
||||||
4
video-encoder/README.md
Normal file
4
video-encoder/README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
### How it works
|
||||||
|
- Render RGB to graphics_texture
|
||||||
|
- Convert RGB to YUV on video_texture
|
||||||
|
- Encode video frame
|
||||||
55
video-encoder/shaders/rgb_to_yuv.wgsl
Normal file
55
video-encoder/shaders/rgb_to_yuv.wgsl
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
struct VertexOutput {
|
||||||
|
@builtin(position) position: vec4<f32>,
|
||||||
|
@location(1) uv: vec2<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
@vertex
|
||||||
|
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
|
||||||
|
// hacky way to draw a large triangle
|
||||||
|
let tmp1 = i32(vertex_index) / 2;
|
||||||
|
let tmp2 = i32(vertex_index) & 1;
|
||||||
|
var result:VertexOutput;
|
||||||
|
result.position=vec4<f32>(
|
||||||
|
f32(tmp1) * 4.0 - 1.0,
|
||||||
|
f32(tmp2) * 4.0 - 1.0,
|
||||||
|
1.0,
|
||||||
|
1.0
|
||||||
|
);
|
||||||
|
result.uv=vec2<f32>(
|
||||||
|
f32(tmp1) * 2.0,
|
||||||
|
1.0 - f32(tmp2) * 2.0
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@group(0)
|
||||||
|
@binding(0)
|
||||||
|
var texture: texture_2d<f32>;
|
||||||
|
@group(0)
|
||||||
|
@binding(1)
|
||||||
|
var texture_sampler: sampler;
|
||||||
|
|
||||||
|
const RGB_TO_Y:vec3<f32> =
|
||||||
|
vec3(0.2126,0.7152,0.0722);
|
||||||
|
const RGB_TO_UV:mat3x2<f32> = mat3x2<f32>(
|
||||||
|
-0.09991,0.615,
|
||||||
|
-0.33609,-0.55861,
|
||||||
|
0.436,-0.05639
|
||||||
|
);
|
||||||
|
const BIAS:vec2<f32> = vec2<f32>(0.5, 0.5);
|
||||||
|
|
||||||
|
@fragment
|
||||||
|
fn fs_main_y(input: VertexOutput) -> @location(0) f32 {
|
||||||
|
let color = textureSample(texture, texture_sampler, input.uv).rgb;
|
||||||
|
let y = dot(RGB_TO_Y,color);
|
||||||
|
let y_limited = mix(16.0/255.0,240.0/255.0,y);
|
||||||
|
return clamp(y_limited, 0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@fragment
|
||||||
|
fn fs_main_uv(input: VertexOutput) -> @location(0) vec2<f32> {
|
||||||
|
let color = textureSample(texture, texture_sampler, input.uv).rgb;
|
||||||
|
let uv = RGB_TO_UV * color + BIAS;
|
||||||
|
let uv_limited = mix(vec2(16.0/255.0),vec2(240.0/255.0),uv);
|
||||||
|
return clamp(uv_limited, vec2(0.0, 0.0), vec2(1.0, 1.0));
|
||||||
|
}
|
||||||
509
video-encoder/src/encode.rs
Normal file
509
video-encoder/src/encode.rs
Normal file
@@ -0,0 +1,509 @@
|
|||||||
|
use std::num::NonZeroU32;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use strafesnet_common::session::Time as SessionTime;
|
||||||
|
|
||||||
|
#[derive(clap::Subcommand)]
|
||||||
|
pub enum Commands{
|
||||||
|
Encode(EncodeSubcommand),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Commands{
|
||||||
|
pub fn run(self){
|
||||||
|
match self{
|
||||||
|
Commands::Encode(command)=>command.run().unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(clap::Args)]
|
||||||
|
pub struct EncodeSubcommand{
|
||||||
|
#[arg(long,short)]
|
||||||
|
map:PathBuf,
|
||||||
|
#[arg(long,short)]
|
||||||
|
bot:PathBuf,
|
||||||
|
#[arg(long,short)]
|
||||||
|
output_file:Option<PathBuf>,
|
||||||
|
#[arg(long,short)]
|
||||||
|
width:Option<NonZeroU32>,
|
||||||
|
#[arg(long,short)]
|
||||||
|
height:Option<NonZeroU32>,
|
||||||
|
#[arg(long)]
|
||||||
|
fps:Option<u32>,
|
||||||
|
#[arg(long)]
|
||||||
|
target_bitrate:Option<u64>,
|
||||||
|
#[arg(long)]
|
||||||
|
max_bitrate:Option<u64>,
|
||||||
|
#[arg(long)]
|
||||||
|
device:Option<String>,
|
||||||
|
}
|
||||||
|
impl EncodeSubcommand{
|
||||||
|
fn run(self)->Result<(),EncodeError>{
|
||||||
|
encode(EncodeParams{
|
||||||
|
width:self.width.unwrap_or(NonZeroU32::new(1920).unwrap()),
|
||||||
|
height:self.width.unwrap_or(NonZeroU32::new(1080).unwrap()),
|
||||||
|
target_framerate:self.fps.unwrap_or(60),
|
||||||
|
average_bitrate:self.target_bitrate.unwrap_or(6_000_000),
|
||||||
|
max_bitrate:self.max_bitrate.unwrap_or(6_000_000),
|
||||||
|
device:self.device,
|
||||||
|
output_file:self.output_file.unwrap_or_else(||{
|
||||||
|
let mut output_file:PathBuf=self.bot.file_stem().unwrap().into();
|
||||||
|
output_file.set_extension("mp4");
|
||||||
|
output_file
|
||||||
|
}),
|
||||||
|
map:self.map,
|
||||||
|
bot:self.bot,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[expect(dead_code)]
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum EncodeError{
|
||||||
|
ReadMap(std::io::Error),
|
||||||
|
ReadBot(std::io::Error),
|
||||||
|
DecodeSNF(strafesnet_snf::Error),
|
||||||
|
DecodeMap(strafesnet_snf::map::Error),
|
||||||
|
DecodeBot(strafesnet_roblox_bot_file::v0::Error),
|
||||||
|
CreateInstance(vk_video::VulkanInitError),
|
||||||
|
CreateAdapter(vk_video::VulkanInitError),
|
||||||
|
NoAdapter,
|
||||||
|
CreateDevice(vk_video::VulkanInitError),
|
||||||
|
VideoEncodeParams(vk_video::VulkanEncoderError),
|
||||||
|
VideoCreateTextures(vk_video::VulkanEncoderError),
|
||||||
|
VideoEncodeFrame(vk_video::VulkanEncoderError),
|
||||||
|
OutputCreateFile(std::io::Error),
|
||||||
|
OutputMp4Start(mp4::Error),
|
||||||
|
OutputMp4AddTrack(mp4::Error),
|
||||||
|
OutputMp4WriteSample(mp4::Error),
|
||||||
|
OutputMp4End(mp4::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
struct EncodeParams{
|
||||||
|
width:NonZeroU32,
|
||||||
|
height:NonZeroU32,
|
||||||
|
target_framerate:u32,
|
||||||
|
average_bitrate:u64,
|
||||||
|
max_bitrate:u64,
|
||||||
|
device:Option<String>,
|
||||||
|
map:PathBuf,
|
||||||
|
bot:PathBuf,
|
||||||
|
output_file:PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn encode(params:EncodeParams)->Result<(),EncodeError>{
|
||||||
|
let size = glam::uvec2(params.width.get(),params.height.get());
|
||||||
|
let target_framerate = params.target_framerate;
|
||||||
|
let average_bitrate = params.average_bitrate;
|
||||||
|
let max_bitrate = params.max_bitrate;
|
||||||
|
|
||||||
|
let map_file=std::fs::read(params.map).map_err(EncodeError::ReadMap)?;
|
||||||
|
let bot_file=std::fs::read(params.bot).map_err(EncodeError::ReadBot)?;
|
||||||
|
|
||||||
|
// read files
|
||||||
|
let map=strafesnet_snf::read_map(std::io::Cursor::new(map_file))
|
||||||
|
.map_err(EncodeError::DecodeSNF)?
|
||||||
|
.into_complete_map()
|
||||||
|
.map_err(EncodeError::DecodeMap)?;
|
||||||
|
let timelines=strafesnet_roblox_bot_file::v0::read_all_to_block(std::io::Cursor::new(bot_file))
|
||||||
|
.map_err(EncodeError::DecodeBot)?;
|
||||||
|
|
||||||
|
// vulkan init
|
||||||
|
let vulkan_instance = vk_video::VulkanInstance::new().map_err(EncodeError::CreateInstance)?;
|
||||||
|
let vulkan_adapter = if let Some(filter)=params.device.as_deref(){
|
||||||
|
vulkan_instance.iter_adapters(None)
|
||||||
|
.map_err(EncodeError::CreateAdapter)?
|
||||||
|
.find(|adapter|adapter.info().name.contains(filter))
|
||||||
|
.ok_or(EncodeError::NoAdapter)?
|
||||||
|
}else{
|
||||||
|
vulkan_instance.create_adapter(None).map_err(EncodeError::CreateAdapter)?
|
||||||
|
};
|
||||||
|
let vulkan_device = vulkan_adapter
|
||||||
|
.create_device(
|
||||||
|
wgpu::Features::TEXTURE_COMPRESSION_BC,
|
||||||
|
wgpu::ExperimentalFeatures::disabled(),
|
||||||
|
wgpu::Limits::defaults(),
|
||||||
|
)
|
||||||
|
.map_err(EncodeError::CreateDevice)?;
|
||||||
|
|
||||||
|
// playback
|
||||||
|
let bot=strafesnet_roblox_bot_player::bot::CompleteBot::new(timelines);
|
||||||
|
let mut playback_head=strafesnet_roblox_bot_player::head::PlaybackHead::new(&bot,SessionTime::ZERO);
|
||||||
|
|
||||||
|
let mut wgpu_state = WgpuState::new(
|
||||||
|
vulkan_device.wgpu_device(),
|
||||||
|
vulkan_device.wgpu_queue(),
|
||||||
|
size,
|
||||||
|
);
|
||||||
|
|
||||||
|
wgpu_state.change_map(&map);
|
||||||
|
|
||||||
|
let mut encoder = vulkan_device
|
||||||
|
.create_wgpu_textures_encoder(
|
||||||
|
vulkan_device
|
||||||
|
.encoder_parameters_high_quality(
|
||||||
|
vk_video::parameters::VideoParameters {
|
||||||
|
width:params.width,
|
||||||
|
height:params.height,
|
||||||
|
target_framerate:target_framerate.into(),
|
||||||
|
},
|
||||||
|
vk_video::parameters::RateControl::VariableBitrate {
|
||||||
|
average_bitrate,
|
||||||
|
max_bitrate,
|
||||||
|
virtual_buffer_size: std::time::Duration::from_secs(2),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.map_err(EncodeError::VideoEncodeParams)?,
|
||||||
|
)
|
||||||
|
.map_err(EncodeError::VideoCreateTextures)?;
|
||||||
|
|
||||||
|
let output_file=std::fs::File::create(params.output_file)
|
||||||
|
.map_err(EncodeError::OutputCreateFile)?;
|
||||||
|
|
||||||
|
let mp4_config=mp4::Mp4Config{
|
||||||
|
major_brand: str::parse("isom").unwrap(),
|
||||||
|
minor_version: 512,
|
||||||
|
compatible_brands: vec![
|
||||||
|
str::parse("isom").unwrap(),
|
||||||
|
str::parse("iso2").unwrap(),
|
||||||
|
str::parse("avc1").unwrap(),
|
||||||
|
str::parse("mp41").unwrap(),
|
||||||
|
],
|
||||||
|
timescale:target_framerate,
|
||||||
|
};
|
||||||
|
let mut mp4=mp4::Mp4Writer::write_start(output_file,&mp4_config)
|
||||||
|
.map_err(EncodeError::OutputMp4Start)?;
|
||||||
|
|
||||||
|
let avc_config=mp4::AvcConfig{
|
||||||
|
width:params.width.get() as u16,
|
||||||
|
height:params.height.get() as u16,
|
||||||
|
// make up some data to prevent this underdeveloped library from crashing
|
||||||
|
seq_param_set:vec![0,0,0,0],
|
||||||
|
pic_param_set:vec![],
|
||||||
|
};
|
||||||
|
let track_config=mp4::TrackConfig{
|
||||||
|
track_type:mp4::TrackType::Video,
|
||||||
|
timescale:target_framerate,
|
||||||
|
language:"eng".to_owned(),
|
||||||
|
media_conf:mp4::MediaConfig::AvcConfig(avc_config),
|
||||||
|
};
|
||||||
|
|
||||||
|
const TRACK_ID:u32=1;
|
||||||
|
mp4.add_track(&track_config)
|
||||||
|
.map_err(EncodeError::OutputMp4AddTrack)?;
|
||||||
|
|
||||||
|
let duration = bot.duration();
|
||||||
|
for i in 0..duration.get()*target_framerate as i64/SessionTime::ONE_SECOND.get() {
|
||||||
|
let time=SessionTime::raw(i*SessionTime::ONE_SECOND.get()/target_framerate as i64);
|
||||||
|
playback_head.advance_time(&bot,time);
|
||||||
|
let (pos,angles)=playback_head.get_position_angles(&bot,time);
|
||||||
|
wgpu_state.render(pos,angles);
|
||||||
|
|
||||||
|
let frame=vk_video::Frame{
|
||||||
|
data:wgpu_state.video_texture.clone(),
|
||||||
|
pts:None,
|
||||||
|
};
|
||||||
|
let res=unsafe{encoder.encode(frame,false)}
|
||||||
|
.map_err(EncodeError::VideoEncodeFrame)?;
|
||||||
|
|
||||||
|
let mp4_sample=mp4::Mp4Sample{
|
||||||
|
start_time:i as u64,
|
||||||
|
duration:1,
|
||||||
|
rendering_offset:0,
|
||||||
|
is_sync:false,
|
||||||
|
bytes:res.data.into(),
|
||||||
|
};
|
||||||
|
mp4.write_sample(TRACK_ID,&mp4_sample)
|
||||||
|
.map_err(EncodeError::OutputMp4WriteSample)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
mp4.write_end()
|
||||||
|
.map_err(EncodeError::OutputMp4End)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
struct WgpuState {
|
||||||
|
device: wgpu::Device,
|
||||||
|
queue: wgpu::Queue,
|
||||||
|
// graphics output
|
||||||
|
graphics:strafesnet_roblox_bot_player::graphics::Graphics,
|
||||||
|
// not sure if this needs to stay bound to keep the TextureView valid
|
||||||
|
#[expect(unused)]
|
||||||
|
graphics_texture: wgpu::Texture,
|
||||||
|
graphics_texture_view: wgpu::TextureView,
|
||||||
|
// video output
|
||||||
|
video_texture: wgpu::Texture,
|
||||||
|
y_renderer: PlaneRenderer,
|
||||||
|
uv_renderer: PlaneRenderer,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WgpuState {
|
||||||
|
fn new(
|
||||||
|
device: wgpu::Device,
|
||||||
|
queue: wgpu::Queue,
|
||||||
|
size: glam::UVec2,
|
||||||
|
) -> WgpuState {
|
||||||
|
const FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
|
||||||
|
let graphics = strafesnet_roblox_bot_player::graphics::Graphics::new(&device,&queue,size,FORMAT);
|
||||||
|
|
||||||
|
let shader = wgpu::include_wgsl!("../shaders/rgb_to_yuv.wgsl");
|
||||||
|
let shader = device.create_shader_module(shader);
|
||||||
|
|
||||||
|
let graphics_texture_bind_group_layout=device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor{
|
||||||
|
label:Some("RGB Bind Group Layout"),
|
||||||
|
entries:&[
|
||||||
|
wgpu::BindGroupLayoutEntry{
|
||||||
|
binding:0,
|
||||||
|
visibility:wgpu::ShaderStages::FRAGMENT,
|
||||||
|
ty:wgpu::BindingType::Texture{
|
||||||
|
sample_type:wgpu::TextureSampleType::Float{filterable:true},
|
||||||
|
multisampled:false,
|
||||||
|
view_dimension:wgpu::TextureViewDimension::D2,
|
||||||
|
},
|
||||||
|
count:None,
|
||||||
|
},
|
||||||
|
wgpu::BindGroupLayoutEntry{
|
||||||
|
binding:1,
|
||||||
|
visibility:wgpu::ShaderStages::FRAGMENT,
|
||||||
|
ty:wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
||||||
|
count:None,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
let graphics_texture=device.create_texture(&wgpu::TextureDescriptor{
|
||||||
|
label:Some("RGB texture"),
|
||||||
|
format:FORMAT,
|
||||||
|
size:wgpu::Extent3d{
|
||||||
|
width:size.x,
|
||||||
|
height:size.y,
|
||||||
|
depth_or_array_layers:1,
|
||||||
|
},
|
||||||
|
mip_level_count:1,
|
||||||
|
sample_count:1,
|
||||||
|
dimension:wgpu::TextureDimension::D2,
|
||||||
|
usage:wgpu::TextureUsages::RENDER_ATTACHMENT|wgpu::TextureUsages::TEXTURE_BINDING,
|
||||||
|
view_formats:&[],
|
||||||
|
});
|
||||||
|
let graphics_texture_view = graphics_texture.create_view(&wgpu::TextureViewDescriptor {
|
||||||
|
label: Some("RGB texture view"),
|
||||||
|
aspect: wgpu::TextureAspect::All,
|
||||||
|
usage: Some(wgpu::TextureUsages::RENDER_ATTACHMENT|wgpu::TextureUsages::TEXTURE_BINDING),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
let clamp_sampler=device.create_sampler(&wgpu::SamplerDescriptor{
|
||||||
|
label:Some("Clamp Sampler"),
|
||||||
|
address_mode_u:wgpu::AddressMode::ClampToEdge,
|
||||||
|
address_mode_v:wgpu::AddressMode::ClampToEdge,
|
||||||
|
address_mode_w:wgpu::AddressMode::ClampToEdge,
|
||||||
|
mag_filter:wgpu::FilterMode::Linear,
|
||||||
|
min_filter:wgpu::FilterMode::Linear,
|
||||||
|
mipmap_filter:wgpu::MipmapFilterMode::Linear,
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
let graphics_texture_bind_group=device.create_bind_group(&wgpu::BindGroupDescriptor{
|
||||||
|
layout:&graphics_texture_bind_group_layout,
|
||||||
|
entries:&[
|
||||||
|
wgpu::BindGroupEntry{
|
||||||
|
binding:0,
|
||||||
|
resource:wgpu::BindingResource::TextureView(&graphics_texture_view),
|
||||||
|
},
|
||||||
|
wgpu::BindGroupEntry{
|
||||||
|
binding:1,
|
||||||
|
resource:wgpu::BindingResource::Sampler(&clamp_sampler),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
label:Some("Graphics Texture"),
|
||||||
|
});
|
||||||
|
|
||||||
|
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||||
|
label: Some("wgpu pipeline layout"),
|
||||||
|
bind_group_layouts: &[
|
||||||
|
&graphics_texture_bind_group_layout
|
||||||
|
],
|
||||||
|
immediate_size: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
let video_texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||||
|
label: Some("wgpu render target"),
|
||||||
|
format: wgpu::TextureFormat::NV12,
|
||||||
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC,
|
||||||
|
dimension: wgpu::TextureDimension::D2,
|
||||||
|
sample_count: 1,
|
||||||
|
view_formats: &[],
|
||||||
|
mip_level_count: 1,
|
||||||
|
size: wgpu::Extent3d {
|
||||||
|
width: size.x,
|
||||||
|
height: size.y,
|
||||||
|
depth_or_array_layers: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
let y_renderer = PlaneRenderer::new(
|
||||||
|
&device,
|
||||||
|
&pipeline_layout,
|
||||||
|
&shader,
|
||||||
|
"fs_main_y",
|
||||||
|
&video_texture,
|
||||||
|
wgpu::TextureAspect::Plane0,
|
||||||
|
graphics_texture_bind_group.clone(),
|
||||||
|
);
|
||||||
|
let uv_renderer = PlaneRenderer::new(
|
||||||
|
&device,
|
||||||
|
&pipeline_layout,
|
||||||
|
&shader,
|
||||||
|
"fs_main_uv",
|
||||||
|
&video_texture,
|
||||||
|
wgpu::TextureAspect::Plane1,
|
||||||
|
graphics_texture_bind_group,
|
||||||
|
);
|
||||||
|
|
||||||
|
WgpuState {
|
||||||
|
device,
|
||||||
|
queue,
|
||||||
|
graphics,
|
||||||
|
graphics_texture,
|
||||||
|
graphics_texture_view,
|
||||||
|
video_texture,
|
||||||
|
y_renderer,
|
||||||
|
uv_renderer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn change_map(&mut self,map:&strafesnet_common::map::CompleteMap){
|
||||||
|
self.graphics.change_map(&self.device,&self.queue,map);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self,pos:glam::Vec3,angles:glam::Vec2) {
|
||||||
|
let mut encoder = self
|
||||||
|
.device
|
||||||
|
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||||
|
label: Some("wgpu encoder"),
|
||||||
|
});
|
||||||
|
|
||||||
|
self.graphics.encode_commands(&mut encoder,&self.graphics_texture_view,pos,angles);
|
||||||
|
|
||||||
|
self.y_renderer.render(&mut encoder);
|
||||||
|
self.uv_renderer.render(&mut encoder);
|
||||||
|
|
||||||
|
encoder.transition_resources(
|
||||||
|
[].into_iter(),
|
||||||
|
[wgpu::TextureTransition {
|
||||||
|
texture: &self.video_texture,
|
||||||
|
state: wgpu::TextureUses::COPY_SRC,
|
||||||
|
selector: None,
|
||||||
|
}]
|
||||||
|
.into_iter(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let buffer = encoder.finish();
|
||||||
|
|
||||||
|
self.queue.submit([buffer]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PlaneRenderer {
|
||||||
|
graphics_texture_bind_group: wgpu::BindGroup,
|
||||||
|
pipeline: wgpu::RenderPipeline,
|
||||||
|
plane: wgpu::TextureAspect,
|
||||||
|
plane_view: wgpu::TextureView,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlaneRenderer {
|
||||||
|
fn new(
|
||||||
|
device: &wgpu::Device,
|
||||||
|
pipeline_layout: &wgpu::PipelineLayout,
|
||||||
|
shader: &wgpu::ShaderModule,
|
||||||
|
fragment_entry_point: &str,
|
||||||
|
texture: &wgpu::Texture,
|
||||||
|
plane: wgpu::TextureAspect,
|
||||||
|
graphics_texture_bind_group: wgpu::BindGroup,
|
||||||
|
) -> Self {
|
||||||
|
let format = texture.format().aspect_specific_format(plane).unwrap();
|
||||||
|
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
|
label: Some("wgpu pipeline"),
|
||||||
|
layout: Some(pipeline_layout),
|
||||||
|
cache: None,
|
||||||
|
vertex: wgpu::VertexState {
|
||||||
|
module: shader,
|
||||||
|
buffers: &[],
|
||||||
|
entry_point: None,
|
||||||
|
compilation_options: Default::default(),
|
||||||
|
},
|
||||||
|
fragment: Some(wgpu::FragmentState {
|
||||||
|
module: shader,
|
||||||
|
entry_point: Some(fragment_entry_point),
|
||||||
|
compilation_options: Default::default(),
|
||||||
|
targets: &[Some(wgpu::ColorTargetState {
|
||||||
|
blend: None,
|
||||||
|
format,
|
||||||
|
write_mask: wgpu::ColorWrites::ALL,
|
||||||
|
})],
|
||||||
|
}),
|
||||||
|
primitive: wgpu::PrimitiveState {
|
||||||
|
topology: wgpu::PrimitiveTopology::TriangleList,
|
||||||
|
cull_mode: Some(wgpu::Face::Back),
|
||||||
|
polygon_mode: wgpu::PolygonMode::Fill,
|
||||||
|
front_face: wgpu::FrontFace::Cw,
|
||||||
|
conservative: false,
|
||||||
|
unclipped_depth: false,
|
||||||
|
strip_index_format: None,
|
||||||
|
},
|
||||||
|
multiview_mask: None,
|
||||||
|
multisample: wgpu::MultisampleState {
|
||||||
|
count: 1,
|
||||||
|
mask: !0,
|
||||||
|
alpha_to_coverage_enabled: false,
|
||||||
|
},
|
||||||
|
depth_stencil: None,
|
||||||
|
});
|
||||||
|
|
||||||
|
let plane_view = texture.create_view(&wgpu::TextureViewDescriptor {
|
||||||
|
label: Some("wgpu render target plane view"),
|
||||||
|
aspect: plane,
|
||||||
|
usage: Some(wgpu::TextureUsages::RENDER_ATTACHMENT),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
|
||||||
|
Self {
|
||||||
|
graphics_texture_bind_group,
|
||||||
|
pipeline,
|
||||||
|
plane,
|
||||||
|
plane_view,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&self, encoder: &mut wgpu::CommandEncoder) {
|
||||||
|
let clear_color = match self.plane {
|
||||||
|
wgpu::TextureAspect::Plane0 => wgpu::Color::BLACK,
|
||||||
|
wgpu::TextureAspect::Plane1 => wgpu::Color {
|
||||||
|
r: 0.5,
|
||||||
|
g: 0.5,
|
||||||
|
b: 0.0,
|
||||||
|
a: 1.0,
|
||||||
|
},
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
|
label: Some("wgpu render pass"),
|
||||||
|
timestamp_writes: None,
|
||||||
|
occlusion_query_set: None,
|
||||||
|
depth_stencil_attachment: None,
|
||||||
|
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||||
|
view: &self.plane_view,
|
||||||
|
ops: wgpu::Operations {
|
||||||
|
load: wgpu::LoadOp::Clear(clear_color),
|
||||||
|
store: wgpu::StoreOp::Store,
|
||||||
|
},
|
||||||
|
resolve_target: None,
|
||||||
|
depth_slice: None,
|
||||||
|
})],
|
||||||
|
multiview_mask: None,
|
||||||
|
});
|
||||||
|
|
||||||
|
render_pass.set_bind_group(0,&self.graphics_texture_bind_group,&[]);
|
||||||
|
render_pass.set_pipeline(&self.pipeline);
|
||||||
|
render_pass.draw(0..3, 0..1);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
video-encoder/src/main.rs
Normal file
24
video-encoder/src/main.rs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
use clap::{Parser,Subcommand};
|
||||||
|
|
||||||
|
mod encode;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[command(author,version,about,long_about=None)]
|
||||||
|
#[command(propagate_version=true)]
|
||||||
|
struct Cli{
|
||||||
|
#[command(subcommand)]
|
||||||
|
command:Commands,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
enum Commands{
|
||||||
|
#[command(flatten)]
|
||||||
|
Encode(encode::Commands),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main(){
|
||||||
|
let cli=Cli::parse();
|
||||||
|
match cli.command{
|
||||||
|
Commands::Encode(commands)=>commands.run(),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,15 +6,21 @@ edition = "2024"
|
|||||||
[lib]
|
[lib]
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
webgl = ["wgpu/webgl"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
strafesnet_roblox_bot_player = { version = "0.1.0", path = "../lib" }
|
glam.workspace = true
|
||||||
|
wgpu.workspace = true
|
||||||
|
strafesnet_roblox_bot_player.workspace = true
|
||||||
strafesnet_common.workspace = true
|
strafesnet_common.workspace = true
|
||||||
strafesnet_graphics.workspace = true
|
strafesnet_graphics.workspace = true
|
||||||
strafesnet_roblox_bot_file.workspace = true
|
strafesnet_roblox_bot_file.workspace = true
|
||||||
|
strafesnet_snf.workspace = true
|
||||||
wasm-bindgen = "0.2.108"
|
wasm-bindgen = "0.2.108"
|
||||||
wasm-bindgen-futures = "0.4.58"
|
wasm-bindgen-futures = "0.4.58"
|
||||||
web-sys = { version = "0.3.85", features = ["HtmlCanvasElement"] }
|
web-sys = { version = "0.3.85", features = ["HtmlCanvasElement"] }
|
||||||
wgpu = "28.0.0"
|
|
||||||
|
|
||||||
[package.metadata.wasm-pack.profile.release]
|
[package.metadata.wasm-pack.profile.release]
|
||||||
wasm-opt = ["-Oz", "--enable-bulk-memory","--enable-nontrapping-float-to-int"]
|
wasm-opt = ["-Oz", "--enable-bulk-memory","--enable-nontrapping-float-to-int"]
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use wasm_bindgen::prelude::wasm_bindgen;
|
use wasm_bindgen::prelude::wasm_bindgen;
|
||||||
use wasm_bindgen::JsValue;
|
use wasm_bindgen::JsError;
|
||||||
use strafesnet_roblox_bot_player::{bot,map,head,graphics};
|
use strafesnet_roblox_bot_file::v0;
|
||||||
use strafesnet_graphics::setup;
|
use strafesnet_roblox_bot_player::{bot,bvh,head,time,graphics};
|
||||||
use strafesnet_common::session::Time as SessionTime;
|
use strafesnet_graphics::{setup,surface};
|
||||||
|
|
||||||
// Hack to keep the code compiling,
|
// Hack to keep the code compiling,
|
||||||
// SurfaceTarget::Canvas is not available in IDE for whatever reason.
|
// SurfaceTarget::Canvas is not available in IDE for whatever reason.
|
||||||
@@ -22,38 +22,52 @@ impl From<ToSurfaceTarget> for wgpu::SurfaceTarget<'static>{
|
|||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub struct Graphics{
|
pub struct Graphics{
|
||||||
graphics:graphics::Graphics,
|
graphics:graphics::Graphics,
|
||||||
surface:wgpu::Surface<'static>,
|
surface:surface::Surface<'static>,
|
||||||
|
device:wgpu::Device,
|
||||||
|
queue:wgpu::Queue,
|
||||||
}
|
}
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub async fn setup_graphics(canvas:web_sys::HtmlCanvasElement)->Graphics{
|
pub async fn setup_graphics(canvas:web_sys::HtmlCanvasElement)->Result<Graphics,JsError>{
|
||||||
let size=(canvas.width(),canvas.height());
|
let size=glam::uvec2(canvas.width(),canvas.height());
|
||||||
|
|
||||||
let instance=setup::step1::create_instance();
|
let instance_desc=wgpu::InstanceDescriptor::from_env_or_default();
|
||||||
let surface=setup::step2::create_surface(&instance,ToSurfaceTarget(canvas)).unwrap();
|
let instance=wgpu::util::new_instance_with_webgpu_detection(&instance_desc).await;
|
||||||
let adapter=setup::step3::pick_adapter(&instance,&surface).await.expect("No suitable GPU adapters found on the system!");
|
let surface=setup::step2::create_surface(&instance,ToSurfaceTarget(canvas)).map_err(|e|JsError::new(&e.to_string()))?;
|
||||||
let (device,queue)=setup::step4::request_device(&adapter).await;
|
let adapter=instance.request_adapter(&wgpu::RequestAdapterOptions{
|
||||||
let config=setup::step5::configure_surface(&adapter,&device,&surface,size);
|
power_preference:wgpu::PowerPreference::HighPerformance,
|
||||||
Graphics{
|
force_fallback_adapter:false,
|
||||||
graphics:graphics::Graphics::new(device,queue,config),
|
compatible_surface:Some(&surface),
|
||||||
surface:surface,
|
}).await.map_err(|e|JsError::new(&e.to_string()))?;
|
||||||
}
|
let (device,queue)=setup::step4::request_device(&adapter).await.map_err(|e|JsError::new(&e.to_string()))?;
|
||||||
|
let surface=setup::step5::configure_surface(&adapter,&device,surface,(size.x,size.y)).map_err(|e|JsError::new(&e.to_string()))?;
|
||||||
|
Ok(Graphics{
|
||||||
|
graphics:graphics::Graphics::new(&device,&queue,size,surface.view_format()),
|
||||||
|
surface,
|
||||||
|
device,
|
||||||
|
queue,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl Graphics{
|
impl Graphics{
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn render(&mut self,bot:&CompleteBot,head:&PlaybackHead,time:f64){
|
pub fn render(&mut self,bot:&CompleteBot,head:&PlaybackHead,time:f64){
|
||||||
// TODO: check f64 range
|
let time=time::from_float(time).unwrap();
|
||||||
let time=SessionTime::raw((time*SessionTime::ONE_SECOND.get() as f64) as i64);
|
|
||||||
let (pos,angles)=head.head.get_position_angles(&bot.bot,time);
|
let (pos,angles)=head.head.get_position_angles(&bot.bot,time);
|
||||||
self.graphics.render(&self.surface,pos,angles);
|
let frame=self.surface.new_frame(&self.device);
|
||||||
|
let mut encoder=self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None});
|
||||||
|
self.graphics.encode_commands(&mut encoder,frame.view(),pos,angles);
|
||||||
|
self.queue.submit([encoder.finish()]);
|
||||||
|
frame.present();
|
||||||
}
|
}
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn resize(&mut self,width:u32,height:u32){
|
pub fn resize(&mut self,width:u32,height:u32,fov_slope_x:f32,fov_slope_y:f32){
|
||||||
self.graphics.resize(&self.surface,[width,height].into());
|
let size=[width,height].into();
|
||||||
|
self.surface.configure(&self.device,size);
|
||||||
|
self.graphics.resize(&self.device,size,[fov_slope_x as f32,fov_slope_y as f32].into());
|
||||||
}
|
}
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn change_map(&mut self,map:&CompleteMap){
|
pub fn change_map(&mut self,map:&CompleteMap){
|
||||||
self.graphics.change_map(&map.map);
|
self.graphics.change_map(&self.device,&self.queue,&map.map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,23 +78,37 @@ pub struct CompleteBot{
|
|||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl CompleteBot{
|
impl CompleteBot{
|
||||||
#[wasm_bindgen(constructor)]
|
#[wasm_bindgen(constructor)]
|
||||||
pub fn new(data:&[u8])->Result<Self,JsValue>{
|
pub fn new(data:&[u8])->Result<Self,JsError>{
|
||||||
|
let timelines=v0::read_all_to_block(std::io::Cursor::new(data)).map_err(|e|JsError::new(&e.to_string()))?;
|
||||||
Ok(Self{
|
Ok(Self{
|
||||||
bot:bot::CompleteBot::new(data).map_err(|e|JsValue::from_str(&e.to_string()))?,
|
bot:bot::CompleteBot::new(timelines),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn duration(&self)->f64{
|
||||||
|
self.bot.duration().into()
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn run_duration(&self,mode_id:u32)->Option<f64>{
|
||||||
|
let mode=v0::ModeID(mode_id);
|
||||||
|
Some(self.bot.run_duration(mode)?.into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub struct CompleteMap{
|
pub struct CompleteMap{
|
||||||
map:map::CompleteMap,
|
map:strafesnet_common::map::CompleteMap,
|
||||||
}
|
}
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl CompleteMap{
|
impl CompleteMap{
|
||||||
#[wasm_bindgen(constructor)]
|
#[wasm_bindgen(constructor)]
|
||||||
pub fn new(data:&[u8])->Result<Self,JsValue>{
|
pub fn new(data:&[u8])->Result<Self,JsError>{
|
||||||
|
let map=strafesnet_snf::read_map(std::io::Cursor::new(data))
|
||||||
|
.map_err(|e|JsError::new(&e.to_string()))?
|
||||||
|
.into_complete_map()
|
||||||
|
.map_err(|e|JsError::new(&e.to_string()))?;
|
||||||
Ok(Self{
|
Ok(Self{
|
||||||
map:map::CompleteMap::new(data).map_err(|e|JsValue::from_str(&e.to_string()))?,
|
map,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,17 +120,116 @@ pub struct PlaybackHead{
|
|||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl PlaybackHead{
|
impl PlaybackHead{
|
||||||
#[wasm_bindgen(constructor)]
|
#[wasm_bindgen(constructor)]
|
||||||
pub fn new(time:f64)->Result<Self,JsValue>{
|
pub fn new(bot:&CompleteBot,time:f64)->Self{
|
||||||
// TODO: check f64 range
|
let time=time::from_float(time).unwrap();
|
||||||
let time=SessionTime::raw((time*SessionTime::ONE_SECOND.get() as f64) as i64);
|
Self{
|
||||||
Ok(Self{
|
head:head::PlaybackHead::new(&bot.bot,time),
|
||||||
head:head::PlaybackHead::new(time),
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn advance_time(&mut self,bot:&CompleteBot,time:f64){
|
pub fn advance_time(&mut self,bot:&CompleteBot,time:f64){
|
||||||
// TODO: check f64 range
|
let time=time::from_float(time).unwrap();
|
||||||
let time=SessionTime::raw((time*SessionTime::ONE_SECOND.get() as f64) as i64);
|
|
||||||
self.head.advance_time(&bot.bot,time);
|
self.head.advance_time(&bot.bot,time);
|
||||||
}
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn set_paused(&mut self,time:f64,paused:bool){
|
||||||
|
let time=time::from_float(time).unwrap();
|
||||||
|
self.head.set_paused(time,paused);
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn get_scale(&mut self)->f64{
|
||||||
|
let scale=self.head.get_scale();
|
||||||
|
scale.num() as f64/scale.den() as f64
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn set_scale(&mut self,time:f64,scale:f64){
|
||||||
|
let time=time::from_float(time).unwrap();
|
||||||
|
self.head.set_scale(time,scale.try_into().unwrap());
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn get_head_time(&self,time:f64)->f64{
|
||||||
|
let time=time::from_float(time).unwrap();
|
||||||
|
let time=self.head.time(time);
|
||||||
|
time.into()
|
||||||
|
}
|
||||||
|
/// Set the playback head position to new_time.
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn set_head_time(&mut self,bot:&CompleteBot,time:f64,new_time:f64){
|
||||||
|
let time=time::from_float(time).unwrap();
|
||||||
|
let new_time=time::from_float(new_time).unwrap();
|
||||||
|
self.head.set_time(&bot.bot,time,new_time);
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn get_run_time(&self,bot:&CompleteBot,time:f64,mode_id:u32)->Option<f64>{
|
||||||
|
let time=time::from_float(time).unwrap();
|
||||||
|
let time=bot.bot.time(self.head.time(time));
|
||||||
|
let mode=v0::ModeID(mode_id);
|
||||||
|
let run_time=self.head.state().get_run(mode)?.time(time);
|
||||||
|
Some(run_time.into())
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn is_run_in_progress(&self,mode_id:u32)->Option<bool>{
|
||||||
|
let mode=v0::ModeID(mode_id);
|
||||||
|
Some(self.head.state().get_run(mode)?.is_in_progress())
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn is_run_finished(&self,mode_id:u32)->Option<bool>{
|
||||||
|
let mode=v0::ModeID(mode_id);
|
||||||
|
Some(self.head.state().get_run(mode)?.is_finished())
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn get_fov_slope_y(&self)->f64{
|
||||||
|
self.head.state().get_fov_y()
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn get_speed(&self,bot:&CompleteBot,time:f64)->f32{
|
||||||
|
let time=time::from_float(time).unwrap();
|
||||||
|
let velocity=self.head.get_velocity(&bot.bot,time);
|
||||||
|
|
||||||
|
use glam::Vec3Swizzles;
|
||||||
|
velocity.xz().length()
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn get_game_controls(&self)->u32{
|
||||||
|
self.head.state().get_controls().bits()
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn get_position(&self,bot:&CompleteBot,time:f64)->Vector3{
|
||||||
|
let time=time::from_float(time).unwrap();
|
||||||
|
let position=self.head.get_position(&bot.bot,time);
|
||||||
|
Vector3(position)
|
||||||
|
}
|
||||||
|
/// Returns the camera angles yaw delta between the last game tick and the most recent game tick.
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn get_angles_yaw_delta(&self)->f32{
|
||||||
|
self.head.state().get_angles_delta().y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub struct Vector3(glam::Vec3);
|
||||||
|
#[wasm_bindgen]
|
||||||
|
impl Vector3{
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn to_array(&self)->Vec<f32>{
|
||||||
|
self.0.to_array().to_vec()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub struct Bvh{
|
||||||
|
bvh:bvh::Bvh,
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
impl Bvh{
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new(bot:&CompleteBot)->Self{
|
||||||
|
Self{
|
||||||
|
bvh:bvh::Bvh::new(&bot.bot),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn closest_time_to_point(&self,bot:&CompleteBot,point:&Vector3)->Option<f64>{
|
||||||
|
Some(bot.bot.playback_time(self.bvh.closest_time_to_point(&bot.bot,point.0)?).into())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,52 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
.hud {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 10px;
|
||||||
|
left: 10px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column; /* stack vertically */
|
||||||
|
gap: 4px; /* space between timers */
|
||||||
|
}
|
||||||
|
|
||||||
|
.timer {
|
||||||
|
background: #000;
|
||||||
|
color: #fff;
|
||||||
|
padding: 4px 8px;
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.controls {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 10px;
|
||||||
|
left: 120px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row; /* stack horizontally */
|
||||||
|
gap: 4px; /* space between timers */
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<script defer src="player.js" type="module"></script>
|
<script defer src="player.js" type="module"></script>
|
||||||
<script defer type="module" src="iframe-helper.js"></script>
|
<script defer type="module" src="iframe-helper.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<canvas></canvas>
|
<canvas id="viewport"> </canvas>
|
||||||
|
<div class="hud">
|
||||||
|
<div id="hud_duration" class="timer">00:00:00</div>
|
||||||
|
<div id="hud_timer" class="timer">00:00:00</div>
|
||||||
|
<div id="diff_velocity" class="timer">-0.000 u/s</div>
|
||||||
|
<div id="diff_time" class="timer">-0.000s</div>
|
||||||
|
</div>
|
||||||
|
<div class="controls">
|
||||||
|
<button id="control_reset">↪️</button>
|
||||||
|
<button id="control_pause">⏯</button>
|
||||||
|
<button id="control_backward">⬅️</button>
|
||||||
|
<button id="control_forward">➡️</button>
|
||||||
|
<button id="control_slower">⏪</button>
|
||||||
|
<input type="text" id="control_speed" value="1.00x"></>
|
||||||
|
<button id="control_faster">⏩</button>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -3,24 +3,103 @@ import init, {
|
|||||||
CompleteBot,
|
CompleteBot,
|
||||||
CompleteMap,
|
CompleteMap,
|
||||||
PlaybackHead,
|
PlaybackHead,
|
||||||
|
Bvh,
|
||||||
} from "./pkg/strafesnet_roblox_bot_player_wasm_module.js";
|
} from "./pkg/strafesnet_roblox_bot_player_wasm_module.js";
|
||||||
|
|
||||||
|
// Loading
|
||||||
await init(); // load the wasm module
|
await init(); // load the wasm module
|
||||||
|
|
||||||
const b = await fetch("bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d.qbot");
|
const b = await fetch("bhop_marble_7cf33a64-7120-4514-b9fa-4fe29d9523d.qbot");
|
||||||
const m = await fetch("bhop_marble_5692093612.snfm");
|
const m = await fetch("bhop_marble_5692093612.snfm");
|
||||||
|
|
||||||
const canvas = document.querySelector("canvas");
|
const canvas = document.getElementById("viewport");
|
||||||
|
|
||||||
const graphics = await setup_graphics(canvas);
|
const graphics = await setup_graphics(canvas);
|
||||||
const bot = new CompleteBot(new Uint8Array(await b.arrayBuffer()));
|
const bot = new CompleteBot(new Uint8Array(await b.arrayBuffer()));
|
||||||
const map = new CompleteMap(new Uint8Array(await m.arrayBuffer()));
|
const map = new CompleteMap(new Uint8Array(await m.arrayBuffer()));
|
||||||
const playback = new PlaybackHead(0);
|
const playback = new PlaybackHead(bot, 0);
|
||||||
|
const bvh_wr = new Bvh(bot);
|
||||||
|
const playback_wr = new PlaybackHead(bot, 0);
|
||||||
|
|
||||||
graphics.change_map(map);
|
graphics.change_map(map);
|
||||||
|
|
||||||
const startTime = performance.now();
|
// HUD
|
||||||
|
const hud_timer = document.getElementById("hud_timer");
|
||||||
|
const hud_duration = document.getElementById("hud_duration");
|
||||||
|
const diff_velocity = document.getElementById("diff_velocity");
|
||||||
|
const diff_time = document.getElementById("diff_time");
|
||||||
|
const MODE_MAIN = 0;
|
||||||
|
|
||||||
|
function timer_text(t) {
|
||||||
|
const h = Math.floor(t / 3600);
|
||||||
|
const m = Math.floor((t % 3600) / 60);
|
||||||
|
const s = Math.floor(t % 60);
|
||||||
|
const ms = Math.floor((t % 1) * 1000);
|
||||||
|
return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}.${String(ms).padStart(3, "0")}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
hud_duration.textContent = timer_text(bot.run_duration(MODE_MAIN));
|
||||||
|
|
||||||
|
// Stuff
|
||||||
|
const startTime = document.timeline.currentTime;
|
||||||
|
function elapsed() {
|
||||||
|
return (document.timeline.currentTime - startTime) / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
const control_speed = document.getElementById("control_speed");
|
||||||
|
|
||||||
|
var paused = false;
|
||||||
|
var scale = 1;
|
||||||
|
function set_scale(new_scale) {
|
||||||
|
scale = new_scale;
|
||||||
|
playback.set_scale(elapsed(), scale);
|
||||||
|
control_speed.value = `${scale.toPrecision(3)}x`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SEEK_DURATION = 1.0;
|
||||||
|
|
||||||
|
// Controls
|
||||||
|
document.getElementById("control_reset").addEventListener("click", (e) => {
|
||||||
|
playback.set_head_time(bot, elapsed(), 0.0);
|
||||||
|
});
|
||||||
|
document.getElementById("control_pause").addEventListener("click", (e) => {
|
||||||
|
paused = !paused;
|
||||||
|
playback.set_paused(elapsed(), paused);
|
||||||
|
});
|
||||||
|
document.getElementById("control_forward").addEventListener("click", (e) => {
|
||||||
|
const time_now = elapsed();
|
||||||
|
const playback_time = playback.get_head_time(time_now);
|
||||||
|
const time_offset = playback.get_scale() * SEEK_DURATION;
|
||||||
|
playback.set_head_time(bot, time_now, playback_time + time_offset);
|
||||||
|
});
|
||||||
|
document.getElementById("control_backward").addEventListener("click", (e) => {
|
||||||
|
const time_now = elapsed();
|
||||||
|
const playback_time = playback.get_head_time(time_now);
|
||||||
|
const time_offset = playback.get_scale() * SEEK_DURATION;
|
||||||
|
playback.set_head_time(bot, time_now, playback_time - time_offset);
|
||||||
|
});
|
||||||
|
document.getElementById("control_slower").addEventListener("click", (e) => {
|
||||||
|
set_scale((scale * 4) / 5);
|
||||||
|
});
|
||||||
|
const regex = new RegExp("^([^x]*)x?$");
|
||||||
|
control_speed.addEventListener("change", (e) => {
|
||||||
|
const parsed = regex.exec(e.target.value);
|
||||||
|
if (!parsed) {
|
||||||
|
set_scale(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const input = Number(parsed.at(1));
|
||||||
|
if (Number.isNaN(input)) {
|
||||||
|
set_scale(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
set_scale(input);
|
||||||
|
});
|
||||||
|
document.getElementById("control_faster").addEventListener("click", (e) => {
|
||||||
|
set_scale((scale * 5) / 4);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Rendering
|
||||||
function animate(now) {
|
function animate(now) {
|
||||||
const elapsedMs = now - startTime;
|
const elapsedMs = now - startTime;
|
||||||
const elapsedSec = elapsedMs / 1000; // wasm expects seconds
|
const elapsedSec = elapsedMs / 1000; // wasm expects seconds
|
||||||
@@ -28,6 +107,26 @@ function animate(now) {
|
|||||||
// Advance the playback head to the current time
|
// Advance the playback head to the current time
|
||||||
playback.advance_time(bot, elapsedSec);
|
playback.advance_time(bot, elapsedSec);
|
||||||
|
|
||||||
|
// update the timer text
|
||||||
|
const time = playback.get_run_time(bot, elapsedSec, MODE_MAIN);
|
||||||
|
hud_timer.textContent = timer_text(time);
|
||||||
|
|
||||||
|
// show diff
|
||||||
|
const pos = playback.get_position(bot, elapsedSec);
|
||||||
|
const wr_playback_time = bvh_wr.closest_time_to_point(bot, pos);
|
||||||
|
playback_wr.set_head_time(bot, elapsedSec, wr_playback_time);
|
||||||
|
const wr_time = playback_wr.get_run_time(bot, elapsedSec, MODE_MAIN);
|
||||||
|
const run_speed = playback.get_speed(bot, elapsedSec);
|
||||||
|
const wr_speed = playback_wr.get_speed(bot, elapsedSec);
|
||||||
|
const v_diff = run_speed - wr_speed;
|
||||||
|
const wholespeed = Math.floor(Math.abs(v_diff));
|
||||||
|
const millispeed = Math.floor((Math.abs(v_diff) % 1) * 1000);
|
||||||
|
diff_velocity.textContent = `${v_diff<0?"-":"+"}${String(wholespeed)}.${String(millispeed).padStart(3, "0")} u/s`;
|
||||||
|
const t_diff = time - wr_time;
|
||||||
|
const s = Math.floor(Math.abs(t_diff));
|
||||||
|
const ms = Math.floor((Math.abs(t_diff) % 1) * 1000);
|
||||||
|
diff_time.textContent = `${t_diff<0?"-":"+"}${String(s)}.${String(ms).padStart(3, "0")}s`;
|
||||||
|
|
||||||
// Render the frame that the bot is at that time
|
// Render the frame that the bot is at that time
|
||||||
graphics.render(bot, playback, elapsedSec);
|
graphics.render(bot, playback, elapsedSec);
|
||||||
|
|
||||||
@@ -37,10 +136,13 @@ function animate(now) {
|
|||||||
|
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
|
|
||||||
|
// Resizing
|
||||||
function resize() {
|
function resize() {
|
||||||
canvas.width = canvas.clientWidth;
|
canvas.width = canvas.clientWidth;
|
||||||
canvas.height = canvas.clientHeight;
|
canvas.height = canvas.clientHeight;
|
||||||
graphics.resize(canvas.width, canvas.height);
|
const fov_y = playback.get_fov_slope_y();
|
||||||
|
const fov_x = (fov_y * canvas.width) / canvas.height;
|
||||||
|
graphics.resize(canvas.width, canvas.height, fov_x, fov_y);
|
||||||
}
|
}
|
||||||
window.addEventListener("resize", resize);
|
window.addEventListener("resize", resize);
|
||||||
resize();
|
resize();
|
||||||
|
|||||||
Reference in New Issue
Block a user