mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-10-31 19:44:20 +00:00
fix windows builds
This commit is contained in:
parent
d1d188ac77
commit
fe9fb06b5a
27
Cargo.toml
27
Cargo.toml
|
@ -5,7 +5,23 @@ name = "doukutsu-rs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
crate-type = ["lib", "cdylib"]
|
#crate-type = ["lib", "cdylib"]
|
||||||
|
crate-type = ["lib"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "doukutsu-rs"
|
||||||
|
path = "src/main.rs"
|
||||||
|
test = false
|
||||||
|
bench = false
|
||||||
|
required-features = ["exe"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "drsandroid"
|
||||||
|
path = "src/main_android.rs"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
test = false
|
||||||
|
bench = false
|
||||||
|
required-features = ["android"]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = 'thin'
|
lto = 'thin'
|
||||||
|
@ -21,14 +37,16 @@ opt-level = 1
|
||||||
opt-level = 1
|
opt-level = 1
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["scripting", "backend-sdl", "ogg-playback", "netplay"]
|
default = ["scripting", "backend-sdl", "ogg-playback", "netplay", "exe"]
|
||||||
ogg-playback = ["lewton"]
|
ogg-playback = ["lewton"]
|
||||||
backend-sdl = ["sdl2"]
|
backend-sdl = ["sdl2", "sdl2-sys"]
|
||||||
#backend-sokol = ["sokol"]
|
#backend-sokol = ["sokol"]
|
||||||
backend-glutin = ["winit", "glutin"]
|
backend-glutin = ["winit", "glutin"]
|
||||||
scripting = ["lua-ffi"]
|
scripting = ["lua-ffi"]
|
||||||
netplay = []
|
netplay = []
|
||||||
editor = []
|
editor = []
|
||||||
|
exe = []
|
||||||
|
android = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
#cpal = { path = "./3rdparty/cpal" }
|
#cpal = { path = "./3rdparty/cpal" }
|
||||||
|
@ -53,7 +71,8 @@ num-derive = "0.3.2"
|
||||||
num-traits = "0.2.12"
|
num-traits = "0.2.12"
|
||||||
paste = "1.0.0"
|
paste = "1.0.0"
|
||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
sdl2 = { version = "0.34", optional = true, features = ["unsafe_textures", "bundled", "static-link"] }
|
sdl2 = { version = "=0.34.2", optional = true, features = ["unsafe_textures", "bundled", "static-link"] }
|
||||||
|
sdl2-sys = { version = "=0.34.2", optional = true, features = ["bundled", "static-link"] }
|
||||||
#sokol = { git = "https://github.com/doukutsu-rs/sokol-rs.git", rev = "", optional = true }
|
#sokol = { git = "https://github.com/doukutsu-rs/sokol-rs.git", rev = "", optional = true }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_derive = "1"
|
serde_derive = "1"
|
||||||
|
|
|
@ -71,7 +71,7 @@ cargoNdk {
|
||||||
"x86",
|
"x86",
|
||||||
"arm64"
|
"arm64"
|
||||||
]
|
]
|
||||||
librariesNames = ["libdoukutsu_rs.so"]
|
librariesNames = ["libdrsembedded.so"]
|
||||||
//targetDirectory = "${project.buildDir.getAbsolutePath()}/rust-target"
|
//targetDirectory = "${project.buildDir.getAbsolutePath()}/rust-target"
|
||||||
module = "../"
|
module = "../"
|
||||||
extraCargoEnv = ["ANDROID_NDK_HOME": android.ndkDirectory]
|
extraCargoEnv = ["ANDROID_NDK_HOME": android.ndkDirectory]
|
||||||
|
|
|
@ -57,14 +57,23 @@ impl GlutinEventLoop {
|
||||||
let mut refs = unsafe { &mut *self.refs.get() };
|
let mut refs = unsafe { &mut *self.refs.get() };
|
||||||
|
|
||||||
if refs.is_none() {
|
if refs.is_none() {
|
||||||
let window = WindowBuilder::new();
|
let mut window = WindowBuilder::new();
|
||||||
let windowed_context = ContextBuilder::new()
|
let windowed_context = ContextBuilder::new()
|
||||||
.with_gl(GlRequest::Specific(Api::OpenGlEs, (2, 0)))
|
.with_gl(GlRequest::Specific(Api::OpenGlEs, (2, 0)))
|
||||||
.with_gl_profile(GlProfile::Core)
|
.with_gl_profile(GlProfile::Core)
|
||||||
.with_gl_debug_flag(false)
|
.with_gl_debug_flag(false)
|
||||||
.with_pixel_format(24, 8)
|
.with_pixel_format(24, 8)
|
||||||
.with_vsync(true)
|
.with_vsync(true);
|
||||||
.build_windowed(window, event_loop)
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
use glutin::platform::windows::WindowBuilderExtWindows;
|
||||||
|
window = window.with_drag_and_drop(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
window = window.with_title("doukutsu-rs");
|
||||||
|
|
||||||
|
let windowed_context = windowed_context.build_windowed(window, event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let windowed_context = unsafe { windowed_context.make_current().unwrap() };
|
let windowed_context = unsafe { windowed_context.make_current().unwrap() };
|
||||||
|
|
|
@ -185,12 +185,6 @@ impl Game {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
#[cfg_attr(target_os = "android", ndk_glue::main())]
|
|
||||||
pub fn android_main() {
|
|
||||||
init().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn init() -> GameResult {
|
pub fn init() -> GameResult {
|
||||||
pretty_env_logger::env_logger::from_env(Env::default().default_filter_or("info"))
|
pretty_env_logger::env_logger::from_env(Env::default().default_filter_or("info"))
|
||||||
//.filter(Some("ndk_glue"), LevelFilter::Trace)
|
//.filter(Some("ndk_glue"), LevelFilter::Trace)
|
||||||
|
|
5
src/main_android.rs
Normal file
5
src/main_android.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
#[cfg_attr(target_os = "android", ndk_glue::main())]
|
||||||
|
pub fn android_main() {
|
||||||
|
doukutsu_rs::init().unwrap();
|
||||||
|
}
|
|
@ -627,10 +627,10 @@ impl NPC {
|
||||||
leg.direction = self.direction;
|
leg.direction = self.direction;
|
||||||
leg.parent_id = self.id;
|
leg.parent_id = self.id;
|
||||||
|
|
||||||
npc_list.spawn(256, leg.clone());
|
let _ = npc_list.spawn(256, leg.clone());
|
||||||
|
|
||||||
leg.vel_x = 0x80;
|
leg.vel_x = 0x80;
|
||||||
npc_list.spawn(0, leg);
|
let _ = npc_list.spawn(0, leg);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.vel_y2 += self.direction.vector_x() * 6;
|
self.vel_y2 += self.direction.vector_x() * 6;
|
||||||
|
|
|
@ -598,7 +598,7 @@ impl GameScene {
|
||||||
|
|
||||||
let canvas = canvas.unwrap();
|
let canvas = canvas.unwrap();
|
||||||
|
|
||||||
graphics::set_render_target(ctx, Some(canvas));
|
graphics::set_render_target(ctx, Some(canvas))?;
|
||||||
graphics::set_blend_mode(ctx, BlendMode::Add)?;
|
graphics::set_blend_mode(ctx, BlendMode::Add)?;
|
||||||
|
|
||||||
graphics::clear(ctx, Color::from_rgb(100, 100, 110));
|
graphics::clear(ctx, Color::from_rgb(100, 100, 110));
|
||||||
|
|
|
@ -4,6 +4,7 @@ use std::time::Duration;
|
||||||
|
|
||||||
use cpal::Sample;
|
use cpal::Sample;
|
||||||
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
use lewton::inside_ogg::OggStreamReader;
|
use lewton::inside_ogg::OggStreamReader;
|
||||||
use num_traits::clamp;
|
use num_traits::clamp;
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ use crate::framework::error::GameError::{AudioError, InvalidValue};
|
||||||
use crate::framework::filesystem;
|
use crate::framework::filesystem;
|
||||||
use crate::framework::filesystem::File;
|
use crate::framework::filesystem::File;
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
use crate::sound::ogg_playback::{OggPlaybackEngine, SavedOggPlaybackState};
|
use crate::sound::ogg_playback::{OggPlaybackEngine, SavedOggPlaybackState};
|
||||||
use crate::sound::org_playback::{OrgPlaybackEngine, SavedOrganyaPlaybackState};
|
use crate::sound::org_playback::{OrgPlaybackEngine, SavedOrganyaPlaybackState};
|
||||||
use crate::sound::organya::Song;
|
use crate::sound::organya::Song;
|
||||||
|
@ -21,6 +23,7 @@ use crate::sound::pixtone::PixTonePlayback;
|
||||||
use crate::sound::wave_bank::SoundBank;
|
use crate::sound::wave_bank::SoundBank;
|
||||||
use crate::str;
|
use crate::str;
|
||||||
|
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
mod ogg_playback;
|
mod ogg_playback;
|
||||||
mod org_playback;
|
mod org_playback;
|
||||||
mod organya;
|
mod organya;
|
||||||
|
@ -38,7 +41,9 @@ pub struct SoundManager {
|
||||||
|
|
||||||
enum SongFormat {
|
enum SongFormat {
|
||||||
Organya,
|
Organya,
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
OggSinglePart,
|
OggSinglePart,
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
OggMultiPart,
|
OggMultiPart,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +98,9 @@ impl SoundManager {
|
||||||
|
|
||||||
let songs_paths = paths.iter().map(|prefix| {
|
let songs_paths = paths.iter().map(|prefix| {
|
||||||
[
|
[
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
(SongFormat::OggMultiPart, vec![format!("{}{}_intro.ogg", prefix, song_name), format!("{}{}_loop.ogg", prefix, song_name)]),
|
(SongFormat::OggMultiPart, vec![format!("{}{}_intro.ogg", prefix, song_name), format!("{}{}_loop.ogg", prefix, song_name)]),
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
(SongFormat::OggSinglePart, vec![format!("{}{}.ogg", prefix, song_name)]),
|
(SongFormat::OggSinglePart, vec![format!("{}{}.ogg", prefix, song_name)]),
|
||||||
(SongFormat::Organya, vec![format!("{}{}.org", prefix, song_name)]),
|
(SongFormat::Organya, vec![format!("{}{}.org", prefix, song_name)]),
|
||||||
]
|
]
|
||||||
|
@ -122,6 +129,7 @@ impl SoundManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
SongFormat::OggSinglePart => {
|
SongFormat::OggSinglePart => {
|
||||||
// we're sure that there's one element
|
// we're sure that there's one element
|
||||||
let path = unsafe { paths.get_unchecked(0) };
|
let path = unsafe { paths.get_unchecked(0) };
|
||||||
|
@ -142,6 +150,7 @@ impl SoundManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
SongFormat::OggMultiPart => {
|
SongFormat::OggMultiPart => {
|
||||||
// we're sure that there are two elements
|
// we're sure that there are two elements
|
||||||
let path_intro = unsafe { paths.get_unchecked(0) };
|
let path_intro = unsafe { paths.get_unchecked(0) };
|
||||||
|
@ -205,7 +214,9 @@ impl SoundManager {
|
||||||
enum PlaybackMessage {
|
enum PlaybackMessage {
|
||||||
Stop,
|
Stop,
|
||||||
PlayOrganyaSong(Box<Song>),
|
PlayOrganyaSong(Box<Song>),
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
PlayOggSongSinglePart(Box<OggStreamReader<File>>),
|
PlayOggSongSinglePart(Box<OggStreamReader<File>>),
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
PlayOggSongMultiPart(Box<OggStreamReader<File>>, Box<OggStreamReader<File>>),
|
PlayOggSongMultiPart(Box<OggStreamReader<File>>, Box<OggStreamReader<File>>),
|
||||||
PlaySample(u8),
|
PlaySample(u8),
|
||||||
SetSpeed(f32),
|
SetSpeed(f32),
|
||||||
|
@ -217,12 +228,14 @@ enum PlaybackMessage {
|
||||||
enum PlaybackState {
|
enum PlaybackState {
|
||||||
Stopped,
|
Stopped,
|
||||||
PlayingOrg,
|
PlayingOrg,
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
PlayingOgg,
|
PlayingOgg,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PlaybackStateType {
|
enum PlaybackStateType {
|
||||||
None,
|
None,
|
||||||
Organya(SavedOrganyaPlaybackState),
|
Organya(SavedOrganyaPlaybackState),
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
Ogg(SavedOggPlaybackState),
|
Ogg(SavedOggPlaybackState),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,14 +249,18 @@ where
|
||||||
let mut saved_state: PlaybackStateType = PlaybackStateType::None;
|
let mut saved_state: PlaybackStateType = PlaybackStateType::None;
|
||||||
let mut speed = 1.0;
|
let mut speed = 1.0;
|
||||||
let mut org_engine = OrgPlaybackEngine::new(&bank);
|
let mut org_engine = OrgPlaybackEngine::new(&bank);
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
let mut ogg_engine = OggPlaybackEngine::new();
|
let mut ogg_engine = OggPlaybackEngine::new();
|
||||||
let mut pixtone = PixTonePlayback::new();
|
let mut pixtone = PixTonePlayback::new();
|
||||||
pixtone.create_samples();
|
pixtone.create_samples();
|
||||||
|
|
||||||
log::info!("Audio format: {} {}", sample_rate, channels);
|
log::info!("Audio format: {} {}", sample_rate, channels);
|
||||||
org_engine.set_sample_rate(sample_rate as usize);
|
org_engine.set_sample_rate(sample_rate as usize);
|
||||||
org_engine.loops = usize::MAX;
|
#[cfg(feature = "ogg-playback")]
|
||||||
ogg_engine.set_sample_rate(sample_rate as usize);
|
{
|
||||||
|
org_engine.loops = usize::MAX;
|
||||||
|
ogg_engine.set_sample_rate(sample_rate as usize);
|
||||||
|
}
|
||||||
|
|
||||||
let buf_size = sample_rate as usize * 10 / 1000;
|
let buf_size = sample_rate as usize * 10 / 1000;
|
||||||
let mut bgm_buf = vec![0x8080; buf_size * 2];
|
let mut bgm_buf = vec![0x8080; buf_size * 2];
|
||||||
|
@ -275,6 +292,7 @@ where
|
||||||
|
|
||||||
state = PlaybackState::PlayingOrg;
|
state = PlaybackState::PlayingOrg;
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
Ok(PlaybackMessage::PlayOggSongSinglePart(data)) => {
|
Ok(PlaybackMessage::PlayOggSongSinglePart(data)) => {
|
||||||
if state == PlaybackState::Stopped {
|
if state == PlaybackState::Stopped {
|
||||||
saved_state = PlaybackStateType::None;
|
saved_state = PlaybackStateType::None;
|
||||||
|
@ -290,6 +308,7 @@ where
|
||||||
|
|
||||||
state = PlaybackState::PlayingOgg;
|
state = PlaybackState::PlayingOgg;
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
Ok(PlaybackMessage::PlayOggSongMultiPart(data_intro, data_loop)) => {
|
Ok(PlaybackMessage::PlayOggSongMultiPart(data_intro, data_loop)) => {
|
||||||
if state == PlaybackState::Stopped {
|
if state == PlaybackState::Stopped {
|
||||||
saved_state = PlaybackStateType::None;
|
saved_state = PlaybackStateType::None;
|
||||||
|
@ -318,6 +337,7 @@ where
|
||||||
Ok(PlaybackMessage::SetSpeed(new_speed)) => {
|
Ok(PlaybackMessage::SetSpeed(new_speed)) => {
|
||||||
assert!(new_speed > 0.0);
|
assert!(new_speed > 0.0);
|
||||||
speed = new_speed;
|
speed = new_speed;
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
ogg_engine.set_sample_rate((sample_rate / new_speed) as usize);
|
ogg_engine.set_sample_rate((sample_rate / new_speed) as usize);
|
||||||
org_engine.set_sample_rate((sample_rate / new_speed) as usize);
|
org_engine.set_sample_rate((sample_rate / new_speed) as usize);
|
||||||
}
|
}
|
||||||
|
@ -325,6 +345,7 @@ where
|
||||||
saved_state = match state {
|
saved_state = match state {
|
||||||
PlaybackState::Stopped => PlaybackStateType::None,
|
PlaybackState::Stopped => PlaybackStateType::None,
|
||||||
PlaybackState::PlayingOrg => PlaybackStateType::Organya(org_engine.get_state()),
|
PlaybackState::PlayingOrg => PlaybackStateType::Organya(org_engine.get_state()),
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
PlaybackState::PlayingOgg => PlaybackStateType::Ogg(ogg_engine.get_state()),
|
PlaybackState::PlayingOgg => PlaybackStateType::Ogg(ogg_engine.get_state()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -349,6 +370,7 @@ where
|
||||||
|
|
||||||
state = PlaybackState::PlayingOrg;
|
state = PlaybackState::PlayingOrg;
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
PlaybackStateType::Ogg(playback_state) => {
|
PlaybackStateType::Ogg(playback_state) => {
|
||||||
ogg_engine.set_state(playback_state);
|
ogg_engine.set_state(playback_state);
|
||||||
|
|
||||||
|
@ -383,6 +405,7 @@ where
|
||||||
bgm_index += 1;
|
bgm_index += 1;
|
||||||
((sample & 0xff) << 8, sample & 0xff00)
|
((sample & 0xff) << 8, sample & 0xff00)
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
PlaybackState::PlayingOgg => {
|
PlaybackState::PlayingOgg => {
|
||||||
let samples = (bgm_buf[bgm_index], bgm_buf[bgm_index + 1]);
|
let samples = (bgm_buf[bgm_index], bgm_buf[bgm_index + 1]);
|
||||||
bgm_index += 2;
|
bgm_index += 2;
|
||||||
|
@ -402,6 +425,7 @@ where
|
||||||
let sample = bgm_buf[0];
|
let sample = bgm_buf[0];
|
||||||
((sample & 0xff) << 8, sample & 0xff00)
|
((sample & 0xff) << 8, sample & 0xff00)
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "ogg-playback")]
|
||||||
PlaybackState::PlayingOgg => {
|
PlaybackState::PlayingOgg => {
|
||||||
samples = ogg_engine.render_to(&mut bgm_buf);
|
samples = ogg_engine.render_to(&mut bgm_buf);
|
||||||
bgm_index = 2;
|
bgm_index = 2;
|
||||||
|
|
Loading…
Reference in a new issue