diff --git a/.cargo/config.toml b/.cargo/config.toml index 87fa444..7d7cf07 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ -[target.armv7-unknown-linux-musleabihf] -linker = "arm-linux-gnueabihf-ld" +[target.x86_64-unknown-linux-musl] +linker = "x86_64-linux-musl-gcc" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 73b7357..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: Release - -on: - push: - tags: - - "v*" - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: true - - name: update apt - run: sudo apt-get update - - name: Install libudev - run: sudo apt-get install -y libudev-dev - - name: Stable with rustfmt and clippy - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - components: rustfmt, clippy - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose - - name: Install cargo-make - run: cargo install cargo-make --verbose - - name: Install wasm-pack - uses: jetli/wasm-pack-action@v0.3.0 - - name: Create ignore.env - run: touch infra/ignore.env - - name: Run wasm test - run: cargo make wasm-test - - - name: Install diesel_cli - run: cargo install diesel_cli --no-default-features --features sqlite - - name: Build release - run: cargo build --verbose --release - - name: Archive bin - run: cargo make bin-pack - - name: Build wasm - run: cargo make wasm-pack - - name: Archive wasm - run: cargo make archive-wasm - - name: Archive static - run: cargo make archive-static - - name: Create release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - draft: false - prerelease: false - - name: Upload bin - id: upload-bin - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./bin.tar.gz - asset_name: bin.tar.gz - asset_content_type: application/octet-stream - - name: Upload pkg - id: upload-pkg - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./pkg.tar.gz - asset_name: pkg.tar.gz - asset_content_type: application/octet-stream - - name: Upload static - id: upload-static - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./static.tar.gz - asset_name: static.tar.gz - asset_content_type: application/octet-stream diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0d767b1..49e6937 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,5 @@ jobs: run: cargo install cargo-make --verbose - name: Install wasm-pack uses: jetli/wasm-pack-action@v0.3.0 - - name: Create ignore.env - run: touch infra/ignore.env - name: Run wasm test run: cargo make wasm-test diff --git a/.gitignore b/.gitignore index 9ecade0..aeacc74 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ pkg/ *.sqlite *.tar.gz stream/ -data/ \ No newline at end of file +data/ +bundle.tar \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 8fc44aa..f88ae3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1811,10 +1811,11 @@ checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673" [[package]] name = "libsqlite3-sys" -version = "0.22.2" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290b64917f8b0cb885d9de0f9959fe1f775d7fa12f1da2db9001c1c8ab60f89d" +checksum = "0e9eb7b8e152b6a01be6a4a2917248381875758250dc3df5d46caf9250341dda" dependencies = [ + "cc", "pkg-config", "vcpkg", ] @@ -2174,33 +2175,55 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.37" +version = "0.10.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc6b9e4403633698352880b22cbe2f0e45dd0177f6fabe4585536e56a3e4f75" +checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e" dependencies = [ "bitflags", "cfg-if 1.0.0", "foreign-types", "libc", "once_cell", + "openssl-macros", "openssl-sys", ] +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "openssl-probe" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" +[[package]] +name = "openssl-src" +version = "111.20.0+1.1.1o" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92892c4f87d56e376e469ace79f1128fdaded07646ddf73aa0be4706ff712dec" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" -version = "0.9.68" +version = "0.9.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c571f25d3f66dd427e417cebf73dbe2361d6125cf6e3a70d143fdf97c9f5150" +checksum = "835363342df5fba8354c5b453325b110ffd54044e588c539cf2f20a8014e4cb1" dependencies = [ "autocfg", "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] @@ -2865,8 +2888,10 @@ dependencies = [ "futures", "futures-util", "lazy_static", + "libsqlite3-sys", "log", "notify", + "openssl", "r2d2", "rand 0.8.4", "ring", diff --git a/Makefile.toml b/Makefile.toml index c9be7c9..21a4e93 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,4 +1,4 @@ -env_files = ["infra/ignore.env", "infra/const.env"] +env_files = ["scripts/ignore.env", "scripts/const.env"] [config] default_to_workspace = false @@ -28,17 +28,13 @@ script = [ "cargo run --bin openvgdb" ] -[tasks.wasm-pack] -script = "wasm-pack build wasm --target no-modules --out-dir ../pkg" - -[tasks.bin-pack] -script = ["cargo build --release", "tar -czvf bin.tar.gz -T infra/bin.txt"] - -[tasks.archive-wasm] -script = "tar -czvf pkg.tar.gz pkg" +[tasks.wasm] +command = "wasm-pack" +args = ["build", "wasm", "--target", "no-modules", "--out-dir", "../pkg"] -[tasks.archive-static] -script = "tar -czvf static.tar.gz static" +[tasks.release] +command = "cargo" +args = ["build", "--release", "--target", "x86_64-unknown-linux-musl"] [tasks.watch-wasm] run_task = { name = ["wasm-pack"] } @@ -46,10 +42,10 @@ watch = { postpone = true, watch = ["./wasm", "./msg", "./consts", "./nes"] } [tasks.watch-server] script = "cargo watch -w server -w msg -w consts -x 'run --bin rustgym-server'" -dependencies = ["wasm-pack"] +dependencies = ["wasm"] [tasks.sonic] -script = "sonic -c infra/sonic.cfg" +script = "sonic -c config/sonic.cfg" [tasks.dev] run_task = { name = ["sonic", "watch-server", "watch-wasm"], parallel = true } @@ -58,30 +54,39 @@ run_task = { name = ["sonic", "watch-server", "watch-wasm"], parallel = true } command = "wasm-pack" args = ["test", "--chrome", "--headless", "wasm"] -[tasks.build-mini] -command = "cargo" +[tasks.create-instance] +command = "gcloud" args = [ - "build", - "--release", - "--target", - "aarch64-apple-darwin", - "--bin", - "${APP_NAME}" + "compute", + "instances", + "create", + "${VM_NAME}", + "--machine-type", + "${MACHINE_TYPE}", + "--zone", + "${ZONE}", + "--tags", + "http-server,https-server,stun-server" ] -[tasks.copy-mini] +[tasks.ssh] +command = "ssh" +args = ["${VM_NAME}.us-central1-a.${PROJECT}"] + +[tasks.bundle] +command = "tar" +args = ["-cvvf", "bundle.tar", "-T", "bundle.txt"] +dependencies = ["release", "wasm"] + +[tasks.deploy] command = "scp" -args = [ - "./target/aarch64-apple-darwin/release/${APP_NAME}", - "mini:~/${APP_NAME}" -] -dependencies = ["build-mini"] +args = ["bundle.tar", "${VM_NAME}.us-central1-a.${PROJECT}:~"] +dependencies = ["bundle"] -[tasks.run-mini] -command = "ssh" -args = ["mini", "./${APP_NAME}"] -dependencies = ["copy-mini"] +[tasks.copy-scripts] +command = "scp" +args = ["-r", "scripts", "${VM_NAME}.us-central1-a.${PROJECT}:~"] -[tasks.run-local] -command = "cargo" -args = ["run", "--release", "--bin", "${APP_NAME}"] +[tasks.copy-config] +command = "scp" +args = ["-r", "config", "${VM_NAME}.us-central1-a.${PROJECT}:~"] diff --git a/bundle.txt b/bundle.txt new file mode 100644 index 0000000..61defe8 --- /dev/null +++ b/bundle.txt @@ -0,0 +1,9 @@ +target/x86_64-unknown-linux-musl/release/openvgdb +target/x86_64-unknown-linux-musl/release/rustgym-server +target/x86_64-unknown-linux-musl/release/rustgym-readme +target/x86_64-unknown-linux-musl/release/rustgym-ingest +config/ +scripts/ +pkg/ +data/ +static/ \ No newline at end of file diff --git a/config/envoy.yaml b/config/envoy.yaml new file mode 100644 index 0000000..674b6be --- /dev/null +++ b/config/envoy.yaml @@ -0,0 +1,55 @@ +admin: + address: + socket_address: { address: 127.0.0.1, port_value: 9901 } + +static_resources: + listeners: + - name: listener_0 + address: + socket_address: { address: 0.0.0.0, port_value: 443 } + filter_chains: + - filters: + - name: envoy.filters.network.http_connection_manager + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager + stat_prefix: ingress_http + codec_type: AUTO + route_config: + name: local_route + virtual_hosts: + - name: local_service + domains: ["*"] + routes: + - match: { prefix: "/" } + route: { cluster: some_service } + http_filters: + - name: envoy.filters.http.router + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router + upgrade_configs: + - upgrade_type: websocket + transport_socket: + name: envoy.transport_sockets.tls + typed_config: + "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext + common_tls_context: + tls_certificates: + - certificate_chain: + filename: /etc/letsencrypt/live/rustgym.com/fullchain.pem + private_key: + filename: /etc/letsencrypt/live/rustgym.com/privkey.pem + + clusters: + - name: some_service + connect_timeout: 0.25s + type: STATIC + lb_policy: ROUND_ROBIN + load_assignment: + cluster_name: some_service + endpoints: + - lb_endpoints: + - endpoint: + address: + socket_address: + address: 127.0.0.1 + port_value: 8080 diff --git a/infra/sonic.cfg b/config/sonic.cfg similarity index 100% rename from infra/sonic.cfg rename to config/sonic.cfg diff --git a/infra/bin.txt b/infra/bin.txt deleted file mode 100644 index 904d827..0000000 --- a/infra/bin.txt +++ /dev/null @@ -1,4 +0,0 @@ -target/release/openvgdb -target/release/rustgym-server -target/release/rustgym-readme -target/release/rustgym-ingest \ No newline at end of file diff --git a/infra/create_instance.sh b/infra/create_instance.sh deleted file mode 100755 index 0df6ff6..0000000 --- a/infra/create_instance.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/bin/bash -source infra/ignore.env -source infra/const.env - -echo $VM_NAME $TAG - -#escape keys -HTTP_UPGRADE='$http_upgrade' -HOST='$host' - -gcloud compute instances create $VM_NAME \ - --machine-type $MACHINE_TYPE \ - --zone $ZONE \ - --tags http-server,https-server,stun-server \ - --metadata startup-script="#!/bin/bash -apt update -apt -y install nginx sqlite3 certbot python-certbot-nginx telnet build-essential git coturn -cd $WORK_DIR -mkdir script -mkdir data -mkdir log -mkdir config - -gsutil -m cp -r gs://rustgym.appspot.com/data/sqlite/ gs://rustgym.appspot.com/data/nes/ data/ - -cat < script/certbot.sh -#!/bin/bash -certbot --nginx --redirect --non-interactive --agree-tos -m $EMAIL -d $SERVER_NAME -EOF -chmod u+x script/certbot.sh - -cat < script/coturn.sh -#!/bin/bash -turnserver -n --verbose --use-auth-secret --static-auth-secret=$TURN_STATIC_AUTH_SECRET --fingerprint --realm=$TURN_REALM --external-ip=$TURN_EXTERNAL_IP --cert=$TURN_CERT --pkey=$TURN_PKEY --cli-password=$TURN_CLI_PASSWORD 1> turnserver.log 2> turnserver.error.log & -EOF -chmod u+x script/coturn.sh - -curl -LJO $SONIC_DOWNLOAD/$SONIC_TAG/$SONIC_TAG-x86_64.tar.gz -tar -xzf $SONIC_TAG-x86_64.tar.gz -mv sonic/sonic sonic-server -mv sonic/config.cfg config/sonic.cfg -rm $SONIC_TAG-x86_64.tar.gz -rmdir sonic -mkdir -p data/store/kv -mkdir -p data/store/fst -./sonic-server -c config/sonic.cfg 1> log/sonic.log 2> log/sonic.error.log & - -curl -LJO $RUSTGYM_DOWNLOAD/$TAG/pkg.tar.gz -tar -xzf pkg.tar.gz -rm pkg.tar.gz -curl -LJO $RUSTGYM_DOWNLOAD/$TAG/static.tar.gz -tar -xzf static.tar.gz -rm static.tar.gz -curl -LJO $RUSTGYM_DOWNLOAD/$TAG/bin.tar.gz -tar -xzf bin.tar.gz -rm bin.tar.gz -chmod u+x target/release/rustgym-ingest -./target/release/rustgym-ingest 1> log/ingest.log 2> log/ingest.error.log & -chmod u+x target/release/rustgym-server -git clone https://github.com/ua-parser/uap-core.git -TAG=$TAG TURN_STATIC_AUTH_SECRET=$TURN_STATIC_AUTH_SECRET ./target/release/rustgym-server 1> log/server.log 2> log/server.error.log & - -cat <<\EOF > /etc/nginx/sites-available/rustgym-nginx.cfg -server { - listen 80 default_server; - listen [::]:80 default_server; - server_name $SERVER_NAME; - location / { - proxy_pass http://127.0.0.1:8080; - proxy_http_version 1.1; - proxy_set_header Upgrade $HTTP_UPGRADE; - proxy_set_header Connection \"upgrade\"; - proxy_set_header Host $HOST; - } -} -EOF -rm /etc/nginx/sites-enabled/default -ln -s /etc/nginx/sites-available/rustgym-nginx.cfg /etc/nginx/sites-enabled/default -systemctl restart nginx -echo FINISHED -" diff --git a/ingest/Cargo.toml b/ingest/Cargo.toml index 98326c6..c94fc72 100644 --- a/ingest/Cargo.toml +++ b/ingest/Cargo.toml @@ -8,7 +8,12 @@ edition = "2018" [dependencies] sonic-channel = { version = "0.4.0", features = ["ingest", "control"] } anyhow = "1.0.38" -diesel = { version = "1.4.5", features = ["sqlite"] } +diesel = { version = "1.4.8", features = [ + "sqlite", + "r2d2", + "chrono", + "uuidv07" +] } rustgym-schema = { path = "../schema" } rustgym-consts = { path = "../consts" } html2text = "0.2.1" diff --git a/nes/src/console.rs b/nes/src/console.rs index e62a6d4..1e23492 100644 --- a/nes/src/console.rs +++ b/nes/src/console.rs @@ -74,10 +74,10 @@ impl Console { let mut this = Console::default(); this.mapper = ::new(rom_file); this.cpu = Cpu::new(); - this.ppu = Ppu::new(); + this.ppu = Ppu::new(EmulationFlags::default()); this.emulation_settings = EmulationSettings::new(); this.video_renderer = VideoRenderer::new(renderer); - this.video_decoder = VideoDecoder::new(); + this.video_decoder = VideoDecoder::new(EmulationFlags::default()); this.rewind_manager = RewindManager::new(); Ppu::reset(&mut this); Cpu::reset(&mut this, false); diff --git a/nes/src/control_manager.rs b/nes/src/control_manager.rs index 1df7699..e4447ef 100644 --- a/nes/src/control_manager.rs +++ b/nes/src/control_manager.rs @@ -25,13 +25,15 @@ impl Default for ControllerType { #[derive(Default)] pub struct ControlManager { + settings: EmulationFlags, control_devices: HashMap, input_poll: Option Vec>>, } impl ControlManager { - pub fn new(input_poll: impl Fn() -> Vec + 'static) -> Self { + pub fn new(settings: EmulationFlags, input_poll: impl Fn() -> Vec + 'static) -> Self { let mut this = ControlManager::default(); + this.settings = settings; this.input_poll = Some(Box::new(input_poll)); this } @@ -70,8 +72,8 @@ impl ControlManager { match console.emulation_settings.console_type { ConsoleType::Nes => { if console - .emulation_settings - .flags + .control_manager + .settings .contains(EmulationFlags::UseNes101Hvc101Behavior) { if port == 0 { diff --git a/nes/src/device/base_device.rs b/nes/src/device/base_device.rs deleted file mode 100644 index 7f57e63..0000000 --- a/nes/src/device/base_device.rs +++ /dev/null @@ -1,20 +0,0 @@ -use crate::*; - -#[derive(Default, Clone)] -pub struct ControlDeviceState(Vec); - -#[derive(Default)] -pub struct BaseDevice { - state: ControlDeviceState, - pub strobe: bool, -} - -impl BaseDevice { - pub fn get_raw_state(&self) -> ControlDeviceState { - self.state.clone() - } - - pub fn clear_state(&mut self) { - self.state = ControlDeviceState::default(); - } -} diff --git a/nes/src/device/mod.rs b/nes/src/device/mod.rs index 2afdf43..d488c74 100644 --- a/nes/src/device/mod.rs +++ b/nes/src/device/mod.rs @@ -1,10 +1,8 @@ use crate::*; use std::any::Any; -mod base_device; mod standard_controler; -pub use base_device::*; pub use standard_controler::*; pub trait Device: MemoryHandler { @@ -38,3 +36,22 @@ pub trait Device: MemoryHandler { fn as_any(&mut self) -> &mut dyn Any; } + +#[derive(Default, Clone)] +pub struct ControlDeviceState(Vec); + +#[derive(Default)] +pub struct BaseDevice { + state: ControlDeviceState, + pub strobe: bool, +} + +impl BaseDevice { + pub fn get_raw_state(&self) -> ControlDeviceState { + self.state.clone() + } + + pub fn clear_state(&mut self) { + self.state = ControlDeviceState::default(); + } +} diff --git a/nes/src/emulation_settings.rs b/nes/src/emulation_settings.rs index 3796cd4..ad7654e 100644 --- a/nes/src/emulation_settings.rs +++ b/nes/src/emulation_settings.rs @@ -151,6 +151,7 @@ impl OverscanDimensions { } } +#[derive(Clone, Copy)] pub enum VideoFilterType { None, Ntsc, @@ -318,7 +319,7 @@ pub struct EmulationSettings { need_controller_update: bool, controller_deadzone_size: u32, pub ppu_palette_argb: Palette, - pub flags: EmulationFlags, + flags: EmulationFlags, pub display_language: Language, pub nes_model: NesModel, pub ppu_model: PpuModel, diff --git a/nes/src/mapper/base_mapper.rs b/nes/src/mapper/base_mapper.rs deleted file mode 100644 index f4b27a3..0000000 --- a/nes/src/mapper/base_mapper.rs +++ /dev/null @@ -1,280 +0,0 @@ -use crate::*; -use log::info; - -#[derive(Default)] -pub struct BaseMapper { - nametable_ram: Vec, - only_chr_ram: bool, - allow_register_read: bool, - prg_memory_access: Vec, - chr_memory_access: Vec, - prg_memory_offset: Vec, - prg_memory_type: Vec, - chr_memory_offset: Vec, - chr_memory_type: Vec, - original_prg_rom: Vec, - original_chr_rom: Vec, - chr_ram: Vec, - save_ram: Vec, - work_ram: Vec, - vram_open_bus_value: i16, - pub prg_rom: Vec, - pub chr_rom: Vec, - pub is_read_register_addr: Vec, - pub is_write_register_addr: Vec, - pub rom_info: RomInfo, - pub prg_pages: Vec, - pub chr_pages: Vec, - pub prg_mask: u16, - pub chr_mask: u16, -} - -impl BaseMapper { - fn force_chr_battery(&self) -> bool { - todo!() - } - - fn force_save_ram_size(&self) -> bool { - todo!() - } - - fn force_work_ram_size(&self) -> bool { - todo!() - } - - fn get_save_ram_page_size(&self) -> usize { - todo!() - } - - fn get_chr_ram_page_size(&self) -> usize { - todo!() - } - - fn validate_address_range(&self, start_addr: u16, end_addr: u16) -> bool { - todo!() - } - - fn get_work_ram_page_size(&self) -> usize { - todo!() - } - - fn register_start_address(&self) -> u16 { - 0x8000 - } - - fn register_end_address(&self) -> u16 { - 0xFFFF - } - - fn get_dip_switch_count(&self) -> usize { - todo!() - } - - fn write_register(&mut self, addr: usize, byte: u8) { - todo!() - } - - fn read_register(&mut self, addr: u16) -> u8 { - todo!() - } - - fn set_cpu_memory_mapping( - start_addr: u16, - end_addr: u16, - page_number: u16, - prg_memory_type: PrgMemoryType, - access_type: i8, - ) { - todo!() - } - - fn remove_cpu_memory_mapping(&mut self, start_addr: u16, end_addr: u16) { - todo!() - } - - fn set_ppu_memory_mapping( - start_addr: u16, - end_addr: u16, - page_number: u16, - chr_memory_type: ChrMemoryType, - ) { - todo!() - } - - fn remove_ppu_memory_mapping(&mut self, start_addr: u16, end_addr: u16) { - todo!() - } - - fn has_battery(&self) -> bool { - todo!() - } - - fn load_battery(&mut self) { - todo!() - } - - fn get_power_on_byte(&self, default_value: u8) -> u8 { - todo!() - } - - fn get_dip_switches(&self) -> u32 { - todo!() - } - - fn setup_default_work_ram() { - todo!() - } - - fn initialize_chr_ram(&mut self, chr_ram_size: usize) { - todo!() - } - - fn add_register_range( - &mut self, - start_addr: u16, - end_addr: u16, - memory_operation: MemoryOperation, - ) { - todo!() - } - - fn remove_register_range(start_addr: u16, end_addr: u16, memory_operation: MemoryOperation) { - todo!() - } - - fn restore_prg_chr_state(&mut self) { - todo!() - } - - fn get_nametable(&self, nametable_index: u8) -> &Vec { - todo!() - } - - fn set_nametable(&mut self, index: usize, nametable_index: u8) { - todo!() - } - - fn set_mirroring_type(&mut self, mirroring_type: MirroringType) { - todo!() - } - - fn get_mirroring_type(&self) -> MirroringType { - todo!() - } - - pub fn new(rom_data: &RomData) -> Self { - let mut this = BaseMapper::default(); - this.rom_info = rom_data.info.clone(); - this.is_read_register_addr = vec![false; RAM_SIZE]; - this.is_write_register_addr = vec![false; RAM_SIZE]; - this.prg_rom = rom_data.prg_rom.clone(); - this.chr_rom = rom_data.chr_rom.clone(); - this.prg_mask = (this.prg_rom.len() - 1) as u16; - this.chr_mask = (this.chr_rom.len() - 1) as u16; - this.original_prg_rom = rom_data.prg_rom.clone(); - this.original_chr_rom = rom_data.chr_rom.clone(); - info!( - "prg_rom 0x{:04X} 0x{:04X}", - this.prg_rom.len(), - this.prg_mask - ); - info!( - "chr_rom 0x{:04X} 0x{:04X}", - this.chr_rom.len(), - this.chr_mask - ); - this.prg_pages = vec![0; 0x100]; - this.chr_pages = vec![0; 0x100]; - this - } - - pub fn reset(&mut self, soft_reset: bool) { - todo!() - } - - pub fn get_available_features(&self) -> ConsoleFeatures { - todo!() - } - - pub fn set_nes_model(&mut self, model: NesModel) { - todo!() - } - - pub fn process_cpu_clock(console: &mut Console) {} - - pub fn notify_vram_address_change(addr: u16) { - todo!() - } - - pub fn save_battery(&self) { - todo!() - } - - pub fn apply_samples(&mut self, buffer: Vec, volume: f64) { - todo!() - } - - pub fn read_ram(&mut self, addr: usize) { - todo!() - } - - pub fn write_ram(&mut self, addr: u16, byte: u8) { - todo!() - } - - pub fn write_prg_ram(&mut self, addr: u16, byte: u8) { - todo!() - } - - pub fn read_vram(&mut self, addr: u16) -> u8 { - todo!() - } - - pub fn write_vram(&mut self, addr: u16, byte: u8) { - todo!() - } - - pub fn copy_chr_tile(&self, addr: u32, dest: &mut Vec) { - todo!() - } - - pub fn has_chr_ram(&self) -> bool { - todo!() - } - - pub fn has_chr_rom(&self) -> bool { - todo!() - } - - pub fn get_cartridge_state(&self) -> CartridgeState { - todo!() - } - - pub fn get_memory_value(&mut self, memory_type: DebugMemoryType, addr: u16) -> u8 { - todo!() - } - - pub fn set_memory_value(&mut self, memory_type: DebugMemoryType, addr: u16, byte: u8) { - todo!() - } - - pub fn get_memory_size(&self, memory_type: DebugMemoryType) -> usize { - todo!() - } - - pub fn copy_memory(&self, debug_memory: DebugMemoryType, buffer: &mut Vec) { - todo!() - } - - pub fn get_cpu_absolute_address_and_type(&self, relative_addr: u32) -> CpuAddressInfo { - todo!() - } - - pub fn get_ppu_absolute_address_and_type(&self, relative_addr: u32) -> PpuAddressInfo { - todo!() - } - - pub fn to_absolute_address(&self, addr: u16) -> usize { - todo!() - } -} diff --git a/nes/src/mapper/mod.rs b/nes/src/mapper/mod.rs index 809aea3..274196b 100644 --- a/nes/src/mapper/mod.rs +++ b/nes/src/mapper/mod.rs @@ -23,10 +23,12 @@ Supported mappers: |240|241|242|243|244|245|246|===|===|249|250|===|252|253|254|255| ----------------------------------------------------------------- */ - use crate::*; use log::{debug, info}; -use std::ops::RangeInclusive; + +mod nrom; + +pub use nrom::*; bitflags! { pub struct MemoryAccessType: i8 { @@ -179,8 +181,280 @@ impl dyn Mapper { } } -mod base_mapper; -mod nrom; +#[derive(Default)] +pub struct BaseMapper { + nametable_ram: Vec, + only_chr_ram: bool, + allow_register_read: bool, + prg_memory_access: Vec, + chr_memory_access: Vec, + prg_memory_offset: Vec, + prg_memory_type: Vec, + chr_memory_offset: Vec, + chr_memory_type: Vec, + original_prg_rom: Vec, + original_chr_rom: Vec, + chr_ram: Vec, + save_ram: Vec, + work_ram: Vec, + vram_open_bus_value: i16, + pub prg_rom: Vec, + pub chr_rom: Vec, + pub is_read_register_addr: Vec, + pub is_write_register_addr: Vec, + pub rom_info: RomInfo, + pub prg_pages: Vec, + pub chr_pages: Vec, + pub prg_mask: u16, + pub chr_mask: u16, +} -pub use base_mapper::*; -pub use nrom::*; +impl BaseMapper { + fn force_chr_battery(&self) -> bool { + todo!() + } + + fn force_save_ram_size(&self) -> bool { + todo!() + } + + fn force_work_ram_size(&self) -> bool { + todo!() + } + + fn get_save_ram_page_size(&self) -> usize { + todo!() + } + + fn get_chr_ram_page_size(&self) -> usize { + todo!() + } + + fn validate_address_range(&self, start_addr: u16, end_addr: u16) -> bool { + todo!() + } + + fn get_work_ram_page_size(&self) -> usize { + todo!() + } + + fn register_start_address(&self) -> u16 { + 0x8000 + } + + fn register_end_address(&self) -> u16 { + 0xFFFF + } + + fn get_dip_switch_count(&self) -> usize { + todo!() + } + + fn write_register(&mut self, addr: usize, byte: u8) { + todo!() + } + + fn read_register(&mut self, addr: u16) -> u8 { + todo!() + } + + fn set_cpu_memory_mapping( + start_addr: u16, + end_addr: u16, + page_number: u16, + prg_memory_type: PrgMemoryType, + access_type: i8, + ) { + todo!() + } + + fn remove_cpu_memory_mapping(&mut self, start_addr: u16, end_addr: u16) { + todo!() + } + + fn set_ppu_memory_mapping( + start_addr: u16, + end_addr: u16, + page_number: u16, + chr_memory_type: ChrMemoryType, + ) { + todo!() + } + + fn remove_ppu_memory_mapping(&mut self, start_addr: u16, end_addr: u16) { + todo!() + } + + fn has_battery(&self) -> bool { + todo!() + } + + fn load_battery(&mut self) { + todo!() + } + + fn get_power_on_byte(&self, default_value: u8) -> u8 { + todo!() + } + + fn get_dip_switches(&self) -> u32 { + todo!() + } + + fn setup_default_work_ram() { + todo!() + } + + fn initialize_chr_ram(&mut self, chr_ram_size: usize) { + todo!() + } + + fn add_register_range( + &mut self, + start_addr: u16, + end_addr: u16, + memory_operation: MemoryOperation, + ) { + todo!() + } + + fn remove_register_range(start_addr: u16, end_addr: u16, memory_operation: MemoryOperation) { + todo!() + } + + fn restore_prg_chr_state(&mut self) { + todo!() + } + + fn get_nametable(&self, nametable_index: u8) -> &Vec { + todo!() + } + + fn set_nametable(&mut self, index: usize, nametable_index: u8) { + todo!() + } + + fn set_mirroring_type(&mut self, mirroring_type: MirroringType) { + todo!() + } + + fn get_mirroring_type(&self) -> MirroringType { + todo!() + } + + pub fn new(rom_data: &RomData) -> Self { + let mut this = BaseMapper::default(); + this.rom_info = rom_data.info.clone(); + this.is_read_register_addr = vec![false; RAM_SIZE]; + this.is_write_register_addr = vec![false; RAM_SIZE]; + this.prg_rom = rom_data.prg_rom.clone(); + this.chr_rom = rom_data.chr_rom.clone(); + this.prg_mask = (this.prg_rom.len() - 1) as u16; + this.chr_mask = (this.chr_rom.len() - 1) as u16; + this.original_prg_rom = rom_data.prg_rom.clone(); + this.original_chr_rom = rom_data.chr_rom.clone(); + info!( + "prg_rom 0x{:04X} 0x{:04X}", + this.prg_rom.len(), + this.prg_mask + ); + info!( + "chr_rom 0x{:04X} 0x{:04X}", + this.chr_rom.len(), + this.chr_mask + ); + this.prg_pages = vec![0; 0x100]; + this.chr_pages = vec![0; 0x100]; + this + } + + pub fn reset(&mut self, soft_reset: bool) { + todo!() + } + + pub fn get_available_features(&self) -> ConsoleFeatures { + todo!() + } + + pub fn set_nes_model(&mut self, model: NesModel) { + todo!() + } + + pub fn process_cpu_clock(console: &mut Console) {} + + pub fn notify_vram_address_change(addr: u16) { + todo!() + } + + pub fn save_battery(&self) { + todo!() + } + + pub fn apply_samples(&mut self, buffer: Vec, volume: f64) { + todo!() + } + + pub fn read_ram(&mut self, addr: usize) { + todo!() + } + + pub fn write_ram(&mut self, addr: u16, byte: u8) { + todo!() + } + + pub fn write_prg_ram(&mut self, addr: u16, byte: u8) { + todo!() + } + + pub fn read_vram(&mut self, addr: u16) -> u8 { + todo!() + } + + pub fn write_vram(&mut self, addr: u16, byte: u8) { + todo!() + } + + pub fn copy_chr_tile(&self, addr: u32, dest: &mut Vec) { + todo!() + } + + pub fn has_chr_ram(&self) -> bool { + todo!() + } + + pub fn has_chr_rom(&self) -> bool { + todo!() + } + + pub fn get_cartridge_state(&self) -> CartridgeState { + todo!() + } + + pub fn get_memory_value(&mut self, memory_type: DebugMemoryType, addr: u16) -> u8 { + todo!() + } + + pub fn set_memory_value(&mut self, memory_type: DebugMemoryType, addr: u16, byte: u8) { + todo!() + } + + pub fn get_memory_size(&self, memory_type: DebugMemoryType) -> usize { + todo!() + } + + pub fn copy_memory(&self, debug_memory: DebugMemoryType, buffer: &mut Vec) { + todo!() + } + + pub fn get_cpu_absolute_address_and_type(&self, relative_addr: u32) -> CpuAddressInfo { + todo!() + } + + pub fn get_ppu_absolute_address_and_type(&self, relative_addr: u32) -> PpuAddressInfo { + todo!() + } + + pub fn to_absolute_address(&self, addr: u16) -> usize { + todo!() + } +} diff --git a/nes/src/ppu.rs b/nes/src/ppu.rs index a45417d..5f05e79 100644 --- a/nes/src/ppu.rs +++ b/nes/src/ppu.rs @@ -192,6 +192,7 @@ pub struct Ppu { pub frame_count: u32, pub scanline: i32, pub secondary_sprite_ram: Vec, + pub settings: EmulationFlags, } impl Ppu { @@ -355,10 +356,7 @@ impl Ppu { } if ppu.sprite_ram_addr >= 0x08 && ppu.rendering_enabled - && console - .emulation_settings - .flags - .contains(EmulationFlags::DisableOamAddrBug) + && ppu.settings.contains(EmulationFlags::DisableOamAddrBug) { let addr = ppu.sprite_ram_addr & 0xF8 + (ppu.cycle - 1) as u8; let byte = ppu.read_sprite_ram(addr); @@ -587,8 +585,8 @@ impl Ppu { fn process_oam_corruption(console: &mut Console) { if !console - .emulation_settings - .flags + .ppu + .settings .contains(EmulationFlags::EnablePpuOamRowCorruption) { return; @@ -604,13 +602,11 @@ impl Ppu { } } - fn update_minimum_draw_cycles(console: &mut Console) { - let ppu = &mut console.ppu; - ppu.minimum_draw_bg_cycle = if ppu.mask_flags.contains(PpuMaskFlags::BackgroundEnabled) { - if ppu.mask_flags.contains(PpuMaskFlags::BackgroundMask) - || console - .emulation_settings - .flags + fn update_minimum_draw_cycles(&mut self) { + self.minimum_draw_bg_cycle = if self.mask_flags.contains(PpuMaskFlags::BackgroundEnabled) { + if self.mask_flags.contains(PpuMaskFlags::BackgroundMask) + || self + .settings .contains(EmulationFlags::ForceBackgroundFirstColumn) { 0 @@ -678,7 +674,7 @@ impl Ppu { tile.palette_offset + background_color } - fn current_output_buffer(&mut self) -> &mut Vec { + pub fn current_output_buffer(&mut self) -> &mut Vec { &mut self.output_buffers[self.current_output_buffer_index as usize] } @@ -699,8 +695,8 @@ impl Ppu { fn send_frame(console: &mut Console) { VideoDecoder::update_frame_sync(console); console.ppu.enable_oam_decay = console - .emulation_settings - .flags + .ppu + .settings .contains(EmulationFlags::EnableOamDecay); } @@ -725,8 +721,9 @@ impl Ppu { todo!() } - pub fn new() -> Self { + pub fn new(settings: EmulationFlags) -> Self { let mut this = Ppu::default(); + this.settings = settings; this.master_clock = 0; this.output_buffers = vec![vec![0; 256 * 240]; 2]; this.open_bus_decay_stamp = vec![0; 8]; @@ -783,7 +780,7 @@ impl Ppu { ppu.update_vram_addr_delay = 0; ppu.update_vram_addr = 0; ppu.oam_decay_cycles = vec![0; 0x40]; - Ppu::update_minimum_draw_cycles(console); + ppu.update_minimum_draw_cycles(); } pub fn debug_send_frame(&mut self) { @@ -862,7 +859,8 @@ impl Ppu { if ppu.rendering_enabled { Ppu::process_oam_corruption(console); } - Ppu::update_minimum_draw_cycles(console); + let ppu = &mut console.ppu; + ppu.update_minimum_draw_cycles(); } let ppu = &mut console.ppu; if ppu.scanline == console.emulation_settings.input_poll_scanline { @@ -945,8 +943,8 @@ impl Ppu { } SpriteData => { if console - .emulation_settings - .flags + .ppu + .settings .contains(EmulationFlags::DisablePpu2004Reads) { let ppu = &mut console.ppu; @@ -974,10 +972,11 @@ impl Ppu { ppu.memory_read_buffer = ppu.read_vram(ppu.bus_address & 0x3FFF); if ppu.bus_address & 0x3FFF >= 0x3F00 && !console - .emulation_settings - .flags + .ppu + .settings .contains(EmulationFlags::DisablePaletteRead) { + let ppu = &mut console.ppu; return_value = ppu.read_palette_ram(ppu.bus_address) | ppu.open_bus & 0xC0; open_bus_mask = 0xC0; } else { diff --git a/nes/src/renderer/base_renderer.rs b/nes/src/renderer/base_renderer.rs deleted file mode 100644 index 5647b1d..0000000 --- a/nes/src/renderer/base_renderer.rs +++ /dev/null @@ -1,84 +0,0 @@ -use crate::*; - -#[derive(Default)] -pub struct BaseRenderer { - fps_timer: Timer, - last_frame_count: u32, - last_rendered_frame_count: u32, - current_fps: u32, - current_rendered_fps: u32, -} - -impl RenderingDevice for BaseRenderer { - fn update_frame(&self, framebuffer: &mut [u8], width: usize, height: usize) { - todo!(); - } - fn render(&self) { - todo!(); - } - fn reset(&mut self) { - todo!(); - } - fn set_fullscreen_mode( - &mut self, - fullscreen: bool, - monitor_width: usize, - monitor_height: usize, - ) { - todo!(); - } -} - -impl BaseRenderer { - fn remove_old_toasts(&self) { - todo!(); - } - - fn wrap_text(utf8_text: String, max_line_width: f64, line_count: u32) -> String { - todo!() - } - - fn measure_string(&self, text: String) -> f64 { - todo!() - } - - fn contains_character(&self, character: char) -> bool { - todo!() - } - - fn is_message_shown(&self) -> bool { - todo!() - } - - fn display_message(&self, title: String, message: String) { - todo!() - } - - fn draw_toast(&self) { - todo!(); - } - - fn draw_string(&self, message: String, x: i32, y: i32, r: u8, g: u8, b: u8, opacity: u8) { - todo!(); - } - - fn show_fps_counter(console: &mut Console, line_number: i32) { - todo!(); - } - - fn show_lag_counter(console: &mut Console, line_number: i32) { - todo!(); - } - - fn show_frame_counter(console: &mut Console, line_number: i32) { - todo!(); - } - - fn show_game_counter(console: &mut Console, line_number: i32) { - todo!(); - } - - fn show_counters(console: &mut Console) { - todo!(); - } -} diff --git a/nes/src/renderer/mod.rs b/nes/src/renderer/mod.rs index b1d49f9..4efc90a 100644 --- a/nes/src/renderer/mod.rs +++ b/nes/src/renderer/mod.rs @@ -1,7 +1,7 @@ -mod base_renderer; +use crate::*; + mod webgl_renderer; -pub use base_renderer::*; pub use webgl_renderer::*; pub trait RenderingDevice { fn update_frame(&self, framebuffer: &mut [u8], width: usize, height: usize); @@ -14,3 +14,86 @@ pub trait RenderingDevice { monitor_height: usize, ); } + +#[derive(Default)] +pub struct BaseRenderer { + fps_timer: Timer, + last_frame_count: u32, + last_rendered_frame_count: u32, + current_fps: u32, + current_rendered_fps: u32, +} + +impl RenderingDevice for BaseRenderer { + fn update_frame(&self, framebuffer: &mut [u8], width: usize, height: usize) { + todo!(); + } + fn render(&self) { + todo!(); + } + fn reset(&mut self) { + todo!(); + } + fn set_fullscreen_mode( + &mut self, + fullscreen: bool, + monitor_width: usize, + monitor_height: usize, + ) { + todo!(); + } +} + +impl BaseRenderer { + fn remove_old_toasts(&self) { + todo!(); + } + + fn wrap_text(utf8_text: String, max_line_width: f64, line_count: u32) -> String { + todo!() + } + + fn measure_string(&self, text: String) -> f64 { + todo!() + } + + fn contains_character(&self, character: char) -> bool { + todo!() + } + + fn is_message_shown(&self) -> bool { + todo!() + } + + fn display_message(&self, title: String, message: String) { + todo!() + } + + fn draw_toast(&self) { + todo!(); + } + + fn draw_string(&self, message: String, x: i32, y: i32, r: u8, g: u8, b: u8, opacity: u8) { + todo!(); + } + + fn show_fps_counter(console: &mut Console, line_number: i32) { + todo!(); + } + + fn show_lag_counter(console: &mut Console, line_number: i32) { + todo!(); + } + + fn show_frame_counter(console: &mut Console, line_number: i32) { + todo!(); + } + + fn show_game_counter(console: &mut Console, line_number: i32) { + todo!(); + } + + fn show_counters(console: &mut Console) { + todo!(); + } +} diff --git a/nes/src/rewind_manager.rs b/nes/src/rewind_manager.rs index bf0365b..35beaf2 100644 --- a/nes/src/rewind_manager.rs +++ b/nes/src/rewind_manager.rs @@ -8,4 +8,8 @@ impl RewindManager { let this = RewindManager::default(); this } + + pub fn send_frame(&mut self, ppu_output_buffer: &mut Vec, synchronous: bool) { + todo!() + } } diff --git a/nes/src/video_decoder.rs b/nes/src/video_decoder.rs index 185fae5..40a5fba 100644 --- a/nes/src/video_decoder.rs +++ b/nes/src/video_decoder.rs @@ -9,6 +9,7 @@ pub struct ScreenSize { #[derive(Default)] pub struct VideoDecoder { + settings: EmulationFlags, frame_number: u32, hud: VideoHud, pub frame_count: u32, @@ -22,22 +23,34 @@ pub struct VideoDecoder { } impl VideoDecoder { - fn update_video_filter(&mut self) { - todo!() - } - fn decode_thread(&mut self) { todo!() } - pub fn new() -> Self { - let this = VideoDecoder::default(); + pub fn new(settings: EmulationFlags) -> Self { + let mut this = VideoDecoder::default(); + this.settings = settings; this } fn decode_frame(console: &mut Console, synchronous: bool) { - todo!() - // console.rewind_manager.send_frame(); + let video_filter_type = console.emulation_settings.video_filter_type; + console.video_decoder.video_filter = match video_filter_type { + VideoFilterType::None => None, + _ => None, + }; + + if let Some(video_filter) = console.video_decoder.video_filter.as_ref() { + video_filter.send_frame( + &mut console.ppu.current_output_buffer(), + console.video_decoder.frame_number, + ); + } + let screen_size = console.video_decoder.get_screen_size(true); + + console + .rewind_manager + .send_frame(console.ppu.current_output_buffer(), synchronous); } fn take_screenshot(&mut self) { @@ -52,7 +65,6 @@ impl VideoDecoder { if console.emulation_settings.is_run_ahead_frame { return; } - console.video_decoder.frame_number = console.ppu.frame_count; VideoDecoder::decode_frame(console, true); console.video_decoder.frame_count += 1; diff --git a/nes/src/video_filter/default_video_filter.rs b/nes/src/video_filter/default_video_filter.rs new file mode 100644 index 0000000..4ed77e4 --- /dev/null +++ b/nes/src/video_filter/default_video_filter.rs @@ -0,0 +1,14 @@ +use crate::*; +pub struct DefaultVideoFilter { + base_video_filter: BaseVideoFilter, +} + +impl VideoFilter for DefaultVideoFilter { + fn base_video_filter(&self) -> &BaseVideoFilter { + &self.base_video_filter + } + + fn base_video_filter_mut(&mut self) -> &mut BaseVideoFilter { + &mut self.base_video_filter + } +} diff --git a/nes/src/video_filter/mod.rs b/nes/src/video_filter/mod.rs index a3d08f6..4d5d5b0 100644 --- a/nes/src/video_filter/mod.rs +++ b/nes/src/video_filter/mod.rs @@ -1 +1,44 @@ -pub trait VideoFilter {} +use crate::*; + +mod default_video_filter; + +pub use default_video_filter::*; + +pub trait VideoFilter { + fn base_video_filter_mut(&mut self) -> &mut BaseVideoFilter; + fn base_video_filter(&self) -> &BaseVideoFilter; + + fn apply_filter(&self, ppu_output_buffer: &mut Vec) { + todo!() + } + + fn on_before_apply_filter(&self) { + todo!() + } + + fn is_odd_frame(&self) -> bool { + todo!() + } + + fn send_frame(&self, ppu_output_buffer: &mut Vec, frame_number: u32) { + todo!() + } + + fn take_screenshot(&self, rom_name: String, filter_type: VideoFilterType) { + todo!() + } + + fn get_overscan_dimensions(&self) -> OverscanDimensions { + todo!() + } + + fn get_frame_info(&self) -> FrameInfo { + todo!() + } +} + +pub struct BaseVideoFilter { + pub buffer_size: usize, + pub overscan: OverscanDimensions, + pub is_odd_frame: bool, +} diff --git a/openvgdb/Cargo.toml b/openvgdb/Cargo.toml index f5ecb52..1c88eb7 100644 --- a/openvgdb/Cargo.toml +++ b/openvgdb/Cargo.toml @@ -6,6 +6,11 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] md5 = "0.7.0" -diesel = { version = "1.4.5", features = ["sqlite"] } +diesel = { version = "1.4.8", features = [ + "sqlite", + "r2d2", + "chrono", + "uuidv07" +] } rustgym-consts = { path = "../consts" } rustgym-schema = { path = "../schema" } diff --git a/readme/Cargo.toml b/readme/Cargo.toml index 10105f2..f027bae 100644 --- a/readme/Cargo.toml +++ b/readme/Cargo.toml @@ -6,14 +6,19 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -reqwest = { version = "0.10.7", features = ["blocking", "json"] } -serde_json = "1.0.60" anyhow = "1.0.35" -diesel = { version = "1.4.5", features = ["sqlite"] } -rustgym-util = { path = "../util" } -rustgym-schema = { path = "../schema" } -rustgym-consts = { path = "../consts" } -walkdir = "2.3.1" -regex = "1.4.2" askama = "0.10.5" derive-new = "0.5.8" +regex = "1.4.2" +reqwest = { version = "0.10.7", features = ["blocking", "json"] } +rustgym-consts = { path = "../consts" } +rustgym-schema = { path = "../schema" } +rustgym-util = { path = "../util" } +serde_json = "1.0.60" +walkdir = "2.3.1" +diesel = { version = "1.4.8", features = [ + "sqlite", + "r2d2", + "chrono", + "uuidv07" +] } diff --git a/schema/Cargo.toml b/schema/Cargo.toml index 6b6cdd4..61dbaad 100644 --- a/schema/Cargo.toml +++ b/schema/Cargo.toml @@ -6,7 +6,12 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -diesel = { version = "1.4.5", features = ["sqlite"] } +diesel = { version = "1.4.8", features = [ + "sqlite", + "r2d2", + "chrono", + "uuidv07" +] } rustgym-consts = { path = "../consts" } serde = "1.0.118" derive-new = "0.5.8" diff --git a/infra/.gitignore b/scripts/.gitignore similarity index 100% rename from infra/.gitignore rename to scripts/.gitignore diff --git a/scripts/certbot.sh b/scripts/certbot.sh new file mode 100755 index 0000000..1c414c4 --- /dev/null +++ b/scripts/certbot.sh @@ -0,0 +1,2 @@ +#!/bin/bash +certbot certonly --register-unsafely-without-email --standalone \ No newline at end of file diff --git a/infra/const.env b/scripts/const.env old mode 100644 new mode 100755 similarity index 97% rename from infra/const.env rename to scripts/const.env index d6d0188..749074b --- a/infra/const.env +++ b/scripts/const.env @@ -1,5 +1,4 @@ SERVER_NAME=rustgym.com -WORK_DIR=/root EMAIL=larry.fantasy@gmail.com RUSTGYM_DOWNLOAD=https://github.com/warycat/rustgym/releases/download SONIC_DOWNLOAD=https://github.com/valeriansaliou/sonic/releases/download @@ -11,6 +10,7 @@ IMAGE=debian-10-buster-v20201216 IMAGE_FAMILY=debian-10 MACHINE_TYPE=e2-micro ZONE=us-central1-a +PROJECT=rustgym TURN_EXTERNAL_IP=35.188.52.69 TURN_LISTENING_PORT=3478 diff --git a/scripts/coturn.sh b/scripts/coturn.sh new file mode 100755 index 0000000..43738c9 --- /dev/null +++ b/scripts/coturn.sh @@ -0,0 +1,9 @@ +#!/bin/bash +turnserver -n --verbose --use-auth-secret --fingerprint \ + --static-auth-secret=$TURN_STATIC_AUTH_SECRET \ + --realm=$TURN_REALM \ + --external-ip=$TURN_EXTERNAL_IP \ + --cert=$TURN_CERT \ + --pkey=$TURN_PKEY \ + --cli-password=$TURN_CLI_PASSWORD \ + 2>&1 >> log/turnserver.log & \ No newline at end of file diff --git a/infra/create_stun_firewall_rule.sh b/scripts/create_stun_firewall_rule.sh similarity index 100% rename from infra/create_stun_firewall_rule.sh rename to scripts/create_stun_firewall_rule.sh diff --git a/scripts/envoy.sh b/scripts/envoy.sh new file mode 100755 index 0000000..41f43d3 --- /dev/null +++ b/scripts/envoy.sh @@ -0,0 +1,2 @@ +#!/bin/bash +envoy -c config/envoy.yaml 2>&1 >> log/envoy.log & \ No newline at end of file diff --git a/scripts/ingest.sh b/scripts/ingest.sh new file mode 100755 index 0000000..118d095 --- /dev/null +++ b/scripts/ingest.sh @@ -0,0 +1,2 @@ +#!/bin/bash +./rustgym-ingest 2>&1 >> log/ingest.log & diff --git a/scripts/server.sh b/scripts/server.sh new file mode 100755 index 0000000..c428de2 --- /dev/null +++ b/scripts/server.sh @@ -0,0 +1,3 @@ +#!/bin/bash +echo "starting rustgym server" +TAG=$TAG TURN_STATIC_AUTH_SECRET=$TURN_STATIC_AUTH_SECRET RUST_LOG=INFO ./rustgym-server 2>&1 >> log/server.log & diff --git a/scripts/sonic.sh b/scripts/sonic.sh new file mode 100755 index 0000000..86ab565 --- /dev/null +++ b/scripts/sonic.sh @@ -0,0 +1,3 @@ +#!/bin/bash +echo "starting sonic server" +./sonic-server -c config/sonic.cfg 2>&1 >> log/sonic.log & \ No newline at end of file diff --git a/scripts/startup.sh b/scripts/startup.sh new file mode 100755 index 0000000..09a01ae --- /dev/null +++ b/scripts/startup.sh @@ -0,0 +1,32 @@ +#!/bin/bash +source scripts/ignore.env +source scripts/const.env + +apt update +apt install -y screen git telnet certbot coturn debian-keyring debian-archive-keyring apt-transport-https curl lsb-release +if [ ! -f /usr/share/keyrings/getenvoy-keyring.gpg ] +then + curl -sL 'https://deb.dl.getenvoy.io/public/gpg.8115BA8E629CC074.key' | sudo gpg --dearmor -o /usr/share/keyrings/getenvoy-keyring.gpg +fi +echo a077cb587a1b622e03aa4bf2f3689de14658a9497a9af2c427bba5f4cc3c4723 /usr/share/keyrings/getenvoy-keyring.gpg | sha256sum --check +echo "deb [arch=amd64 signed-by=/usr/share/keyrings/getenvoy-keyring.gpg] https://deb.dl.getenvoy.io/public/deb/debian $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/getenvoy.list +apt update +apt install -y getenvoy-envoy + +curl -LJO $SONIC_DOWNLOAD/$SONIC_TAG/$SONIC_TAG-x86_64.tar.gz +tar -xzf $SONIC_TAG-x86_64.tar.gz +mv sonic/sonic sonic-server +rm $SONIC_TAG-x86_64.tar.gz +rmdir sonic + +mkdir -p data/store/kv +mkdir -p data/store/fst +mkdir -p log +mv ./target/x86_64-unknown-linux-musl/release/* . + +git clone https://github.com/ua-parser/uap-core.git + +source scripts/sonic.sh +source scripts/ingest.sh +source scripts/coturn.sh +source scripts/server.sh diff --git a/server/Cargo.toml b/server/Cargo.toml index 1bb6189..99b9a0c 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -16,12 +16,6 @@ anyhow = "1.0.38" askama = "0.10.5" chrono = "0.4.19" derive-new = "0.5.8" -diesel = { version = "1.4.5", features = [ - "sqlite", - "r2d2", - "chrono", - "uuidv07" -] } env_logger = "0.8.2" failure = "0.1.8" futures = "0.3.8" @@ -36,11 +30,19 @@ rustgym-msg = { path = "../msg" } rustgym-schema = { path = "../schema" } serde = "1.0.118" serde_json = "1.0.61" -uuid = { version = "0.8", features = ["serde", "v4"] } sonic-channel = "0.4.0" +uuid = { version = "0.8", features = ["serde", "v4"] } tokio = { version = "0.2", features = ["full"] } uaparser = "0.4.0" notify = "4.0.16" bincode = "1.3.3" ring = "0.16.20" data-encoding = "2.3.2" +openssl = { version = "0.10.40", features = ["vendored"] } +libsqlite3-sys = { version = "0.9.1", features = ["bundled"] } +diesel = { version = "1.4.8", features = [ + "sqlite", + "r2d2", + "chrono", + "uuidv07" +] } diff --git a/wasm/src/nes_emulator.rs b/wasm/src/nes_emulator.rs index 51dbf85..a6de56e 100644 --- a/wasm/src/nes_emulator.rs +++ b/wasm/src/nes_emulator.rs @@ -120,7 +120,7 @@ impl NesEmulator { let queue_size = 100; let mut console = self.console.take().unwrap(); - console.control_manager = ControlManager::new(|| get_gamepads()); + console.control_manager = ControlManager::new(EmulationFlags::default(), || get_gamepads()); let mut bytes = [0; 256 * 256 * 4]; *g.borrow_mut() = Some(Closure::wrap(Box::new(move || { PAUSED.with(|value| {