separate binaries

This commit is contained in:
Alex Janka 2023-11-26 13:15:31 +11:00
parent e456e24f06
commit 451c4f0fde
19 changed files with 108 additions and 74 deletions

68
Cargo.lock generated
View file

@ -648,6 +648,16 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]]
name = "cli"
version = "0.1.0"
dependencies = [
"clap",
"ctrlc",
"frontend-common",
"gb-emu-lib",
]
[[package]] [[package]]
name = "cmake" name = "cmake"
version = "0.1.50" version = "0.1.50"
@ -1322,6 +1332,25 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "frontend-common"
version = "0.5.0"
dependencies = [
"bytemuck",
"chrono",
"cpal",
"futures",
"gb-emu-lib",
"gilrs",
"image",
"nokhwa",
"raw-window-handle 0.5.2",
"send_wrapper",
"serde",
"winit",
"winit_input_helper",
]
[[package]] [[package]]
name = "futures" name = "futures"
version = "0.3.29" version = "0.3.29"
@ -1420,31 +1449,6 @@ dependencies = [
"byteorder", "byteorder",
] ]
[[package]]
name = "gb-emu"
version = "0.5.0"
dependencies = [
"bytemuck",
"cacao",
"chrono",
"clap",
"cpal",
"ctrlc",
"futures",
"gb-emu-lib",
"gilrs",
"image",
"nokhwa",
"objc2 0.3.0-beta.3",
"raw-window-handle 0.5.2",
"send_wrapper",
"serde",
"twinc_emu_vst",
"uuid 1.6.1",
"winit",
"winit_input_helper",
]
[[package]] [[package]]
name = "gb-emu-lib" name = "gb-emu-lib"
version = "0.5.0" version = "0.5.0"
@ -1624,6 +1628,20 @@ dependencies = [
"bitflags 2.4.1", "bitflags 2.4.1",
] ]
[[package]]
name = "gui"
version = "0.1.0"
dependencies = [
"cacao",
"cpal",
"frontend-common",
"gb-emu-lib",
"objc2 0.3.0-beta.3",
"raw-window-handle 0.5.2",
"twinc_emu_vst",
"uuid 1.6.1",
]
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.12.3" version = "0.12.3"

View file

@ -1,10 +1,11 @@
[workspace] [workspace]
members = ["lib", "gb-emu", "gb-vst", "gb-vst/xtask"] members = ["lib", "frontend-common", "gb-vst", "gb-vst/xtask", "gui", "cli"]
default-members = ["gb-emu"] default-members = ["cli"]
resolver = "2" resolver = "2"
[workspace.dependencies] [workspace.dependencies]
gb-emu-lib = { path = "./lib", features = ["config"] } gb-emu-lib = { path = "./lib", features = ["config"] }
frontend-common = { path = "./frontend-common" }
baseview = { git = "https://github.com/italicsjenga/baseview" } baseview = { git = "https://github.com/italicsjenga/baseview" }
nih_plug = { git = "https://github.com/italicsjenga/nih-plug", branch = "raw-window-handle-0.5.0" } nih_plug = { git = "https://github.com/italicsjenga/nih-plug", branch = "raw-window-handle-0.5.0" }
nih_plug_xtask = { git = "https://github.com/italicsjenga/nih-plug", branch = "raw-window-handle-0.5.0" } nih_plug_xtask = { git = "https://github.com/italicsjenga/nih-plug", branch = "raw-window-handle-0.5.0" }

13
cli/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "cli"
version = "0.1.0"
edition = "2021"
[package.metadata.bundle]
identifier = "com.alexjanka.TWINC.cli"
[dependencies]
frontend-common = { workspace = true }
gb-emu-lib = { workspace = true }
clap = { version = "4.4", features = ["derive"] }
ctrlc = "3.4"

View file

@ -3,7 +3,7 @@
#[cfg(feature = "camera")] #[cfg(feature = "camera")]
use camera::Webcam; use camera::Webcam;
use clap::{ArgGroup, Parser, Subcommand, ValueEnum}; use clap::{ArgGroup, Parser, Subcommand, ValueEnum};
use gb_emu::{audio, debug::Debugger, window::winit_manager::WinitWindowManager}; use frontend_common::{audio, debug::Debugger, window::winit_manager::WinitWindowManager};
use gb_emu_lib::{ use gb_emu_lib::{
config::ConfigManager, config::ConfigManager,
connect::{EmulatorCoreTrait, EmulatorMessage, SerialTarget, SramType, StdoutType}, connect::{EmulatorCoreTrait, EmulatorMessage, SerialTarget, SramType, StdoutType},
@ -15,11 +15,6 @@ use std::{
time::{Duration, Instant}, time::{Duration, Instant},
}; };
#[cfg(all(feature = "vulkan", feature = "pixels"))]
compile_error!("select only one rendering backend!");
#[cfg(all(not(feature = "vulkan"), not(feature = "pixels")))]
compile_error!("select one rendering backend!");
#[derive(Subcommand, Debug, Clone, Copy)] #[derive(Subcommand, Debug, Clone, Copy)]
enum Commands { enum Commands {
PrintConfig { PrintConfig {
@ -104,7 +99,7 @@ struct Args {
record: bool, record: bool,
} }
impl From<Args> for gb_emu::RunOptions { impl From<Args> for frontend_common::RunOptions {
fn from(value: Args) -> Self { fn from(value: Args) -> Self {
Self { Self {
rom: value rom: value
@ -143,7 +138,7 @@ fn main() {
) )
.ok(), .ok(),
ConfigType::Standalone => config_manager ConfigType::Standalone => config_manager
.load_custom_config::<gb_emu::StandaloneConfig>() .load_custom_config::<frontend_common::StandaloneConfig>()
.and_then(|v| ConfigManager::get_custom_config_string(v).ok()), .and_then(|v| ConfigManager::get_custom_config_string(v).ok()),
} }
} else { } else {
@ -153,7 +148,7 @@ fn main() {
) )
.ok(), .ok(),
ConfigType::Standalone => ConfigManager::get_custom_config_string( ConfigType::Standalone => ConfigManager::get_custom_config_string(
gb_emu::StandaloneConfig::default(), frontend_common::StandaloneConfig::default(),
) )
.ok(), .ok(),
} }
@ -175,10 +170,10 @@ fn main() {
.unwrap(); .unwrap();
} }
let (record, mute, debug) = (args.record, args.mute, args.debug); let (record, mute, debug) = (args.record, args.mute, args.debug);
let prepared = gb_emu::prepare(args.into(), receiver); let prepared = frontend_common::prepare(args.into(), receiver);
let (output, stream) = audio::create_output(mute); let (output, stream) = audio::create_output(mute);
let mut window_manager = WinitWindowManager::new(sender, stream, record); let mut window_manager = WinitWindowManager::new(sender, stream, record);
let mut core = gb_emu::run(prepared, &mut window_manager, output); let mut core = frontend_common::run(prepared, &mut window_manager, output);
if debug { if debug {
let mut debugger = Debugger::new(Box::new(core)); let mut debugger = Debugger::new(Box::new(core));
let mut since = Instant::now(); let mut since = Instant::now();

View file

@ -1,15 +1,11 @@
[package] [package]
name = "gb-emu" name = "frontend-common"
version = "0.5.0" version = "0.5.0"
edition = "2021" edition = "2021"
description = "TWINC Game Boy (CGB/DMG) emulator" description = "Frontend common library for TWINC Game Boy (CGB/DMG) emulator"
[package.metadata.bundle] [package.metadata.bundle]
identifier = "com.alexjanka.TWINC" identifier = "com.alexjanka.TWINC"
[package.metadata.bundle.bin.cli]
identifier = "com.alexjanka.TWINC.cli"
[package.metadata.bundle.bin.gui]
identifier = "com.alexjanka.TWINC.gui"
[features] [features]
default = ["vulkan-static"] default = ["vulkan-static"]
@ -25,11 +21,9 @@ force-crossplatform-ui = []
[dependencies] [dependencies]
gb-emu-lib = { workspace = true } gb-emu-lib = { workspace = true }
clap = { version = "4.4", features = ["derive"] }
gilrs = "0.10" gilrs = "0.10"
cpal = "0.15" cpal = "0.15"
futures = "0.3" futures = "0.3"
ctrlc = "3.4"
nokhwa = { version = "0.10", features = [ nokhwa = { version = "0.10", features = [
"input-avfoundation", "input-avfoundation",
], optional = true } ], optional = true }
@ -41,9 +35,3 @@ serde = { version = "1.0", features = ["derive"] }
image = { version = "0.24", default-features = false, features = ["png"] } image = { version = "0.24", default-features = false, features = ["png"] }
bytemuck = "1.14" bytemuck = "1.14"
chrono = "0.4" chrono = "0.4"
twinc_emu_vst = { path = "../gb-vst", default-features = false }
uuid = { version = "1.6", features = ["v4", "fast-rng"] }
[target.'cfg(any(target_os = "macos"))'.dependencies]
cacao = { git = "https://github.com/italicsjenga/cacao" }
objc = { version = "=0.3.0-beta.3", package = "objc2" }

View file

@ -133,7 +133,8 @@ pub fn prepare(
let will_be_cgb = rom.rom_type == CgbRomType::CgbOnly || config.prefer_cgb; let will_be_cgb = rom.rom_type == CgbRomType::CgbOnly || config.prefer_cgb;
let shader_path = if will_be_cgb { let shader_path =
if will_be_cgb {
config.vulkan_config.cgb_shader_path.as_ref() config.vulkan_config.cgb_shader_path.as_ref()
} else { } else {
config.vulkan_config.dmg_shader_path.as_ref() config.vulkan_config.dmg_shader_path.as_ref()
@ -180,7 +181,8 @@ where
{ {
let configs = access_config(); let configs = access_config();
let window = window_manager.add_main( let window =
window_manager.add_main(
prepared.scale_override, prepared.scale_override,
prepared.shader_path, prepared.shader_path,
prepared.resizable, prepared.resizable,

19
gui/Cargo.toml Normal file
View file

@ -0,0 +1,19 @@
[package]
name = "gui"
version = "0.1.0"
edition = "2021"
[package.metadata.bundle]
identifier = "com.alexjanka.TWINC.gui"
[dependencies]
frontend-common = { workspace = true }
gb-emu-lib = { workspace = true }
twinc_emu_vst = { path = "../gb-vst", default-features = false }
[target.'cfg(any(target_os = "macos"))'.dependencies]
cacao = { git = "https://github.com/italicsjenga/cacao" }
objc = { version = "=0.3.0-beta.3", package = "objc2" }
uuid = { version = "1.6", features = ["v4", "fast-rng"] }
raw-window-handle = { version = "0.5" }
cpal = "0.15"

View file

@ -13,7 +13,7 @@ use cacao::{
core_foundation::base::TCFTypeRef, core_foundation::base::TCFTypeRef,
}; };
use cpal::Stream; use cpal::Stream;
use gb_emu::window::{RendererChannel, WindowManager}; use frontend_common::window::{RendererChannel, WindowManager};
use gb_emu_lib::{ use gb_emu_lib::{
connect::{EmulatorMessage, RendererMessage, ResolutionData}, connect::{EmulatorMessage, RendererMessage, ResolutionData},
renderer::{RendererBackend, RendererBackendManager, WindowOptions}, renderer::{RendererBackend, RendererBackendManager, WindowOptions},
@ -279,12 +279,9 @@ impl WindowDelegate for CacaoWindow {
const NAME: &'static str = "EmulatorWindow"; const NAME: &'static str = "EmulatorWindow";
fn did_load(&mut self, window: Window) { fn did_load(&mut self, window: Window) {
#[cfg(feature = "vulkan")]
let options = WindowOptions { let options = WindowOptions {
shader_path: self.shader_path.clone(), shader_path: self.shader_path.clone(),
}; };
#[cfg(feature = "pixels")]
let options = WindowOptions {};
self.backend = Some(RendererBackend::new( self.backend = Some(RendererBackend::new(
self.resolutions, self.resolutions,

View file

@ -7,7 +7,7 @@ use cacao::appkit::window::{Window, WindowConfig, WindowStyle, WindowToolbarStyl
use cacao::appkit::{App, AppDelegate}; use cacao::appkit::{App, AppDelegate};
use cacao::filesystem::FileSelectPanel; use cacao::filesystem::FileSelectPanel;
use cacao::notification_center::Dispatcher; use cacao::notification_center::Dispatcher;
use gb_emu::audio; use frontend_common::audio;
use gb_emu_lib::connect::{EmulatorCoreTrait, EmulatorMessage}; use gb_emu_lib::connect::{EmulatorCoreTrait, EmulatorMessage};
use raw_window_handle::{AppKitDisplayHandle, RawDisplayHandle}; use raw_window_handle::{AppKitDisplayHandle, RawDisplayHandle};
use uuid::Uuid; use uuid::Uuid;
@ -73,9 +73,9 @@ impl Default for TwincUiApp {
}, },
PreferencesUi::new(), PreferencesUi::new(),
)), )),
current_game: RwLock::new(CacaoWindowManager::new(RawDisplayHandle::AppKit( current_game: RwLock::new(
AppKitDisplayHandle::empty(), CacaoWindowManager::new(RawDisplayHandle::AppKit(AppKitDisplayHandle::empty()))
))), ),
} }
} }
} }
@ -99,11 +99,12 @@ impl Dispatcher for TwincUiApp {
AppMessage::Core(CoreMessage::OpenRom(path)) => { AppMessage::Core(CoreMessage::OpenRom(path)) => {
let (sender, receiver) = channel::<EmulatorMessage>(); let (sender, receiver) = channel::<EmulatorMessage>();
sender.send(EmulatorMessage::Start).unwrap(); sender.send(EmulatorMessage::Start).unwrap();
let prepared = gb_emu::prepare(gb_emu::RunOptions::new(path), receiver); let prepared =
frontend_common::prepare(frontend_common::RunOptions::new(path), receiver);
let (output, stream) = audio::create_output(false); let (output, stream) = audio::create_output(false);
let mut window_manager = self.current_game.write().unwrap(); let mut window_manager = self.current_game.write().unwrap();
window_manager.update_handles(sender, stream); window_manager.update_handles(sender, stream);
let mut core = gb_emu::run(prepared, &mut *window_manager, output); let mut core = frontend_common::run(prepared, &mut *window_manager, output);
let handle = std::thread::Builder::new() let handle = std::thread::Builder::new()
.name(String::from("EmuCore")) .name(String::from("EmuCore"))
.spawn(move || loop { .spawn(move || loop {

View file

@ -4,7 +4,7 @@ use cacao::{
layout::Layout, layout::Layout,
view::{View, ViewDelegate}, view::{View, ViewDelegate},
}; };
use gb_emu::StandaloneConfig; use frontend_common::StandaloneConfig;
use gb_emu_lib::config::{Config, ConfigManager, ResolutionOverride}; use gb_emu_lib::config::{Config, ConfigManager, ResolutionOverride};
use crate::macos::dispatch; use crate::macos::dispatch;