fix windows builds

This commit is contained in:
Alula 2021-03-23 04:40:02 +01:00
parent d1d188ac77
commit fe9fb06b5a
8 changed files with 70 additions and 19 deletions

View File

@ -5,7 +5,23 @@ name = "doukutsu-rs"
version = "0.1.0"
[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]
lto = 'thin'
@ -21,14 +37,16 @@ opt-level = 1
opt-level = 1
[features]
default = ["scripting", "backend-sdl", "ogg-playback", "netplay"]
default = ["scripting", "backend-sdl", "ogg-playback", "netplay", "exe"]
ogg-playback = ["lewton"]
backend-sdl = ["sdl2"]
backend-sdl = ["sdl2", "sdl2-sys"]
#backend-sokol = ["sokol"]
backend-glutin = ["winit", "glutin"]
scripting = ["lua-ffi"]
netplay = []
editor = []
exe = []
android = []
[dependencies]
#cpal = { path = "./3rdparty/cpal" }
@ -53,7 +71,8 @@ num-derive = "0.3.2"
num-traits = "0.2.12"
paste = "1.0.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 }
serde = { version = "1", features = ["derive"] }
serde_derive = "1"

View File

@ -71,7 +71,7 @@ cargoNdk {
"x86",
"arm64"
]
librariesNames = ["libdoukutsu_rs.so"]
librariesNames = ["libdrsembedded.so"]
//targetDirectory = "${project.buildDir.getAbsolutePath()}/rust-target"
module = "../"
extraCargoEnv = ["ANDROID_NDK_HOME": android.ndkDirectory]

View File

@ -57,14 +57,23 @@ impl GlutinEventLoop {
let mut refs = unsafe { &mut *self.refs.get() };
if refs.is_none() {
let window = WindowBuilder::new();
let mut window = WindowBuilder::new();
let windowed_context = ContextBuilder::new()
.with_gl(GlRequest::Specific(Api::OpenGlEs, (2, 0)))
.with_gl_profile(GlProfile::Core)
.with_gl_debug_flag(false)
.with_pixel_format(24, 8)
.with_vsync(true)
.build_windowed(window, event_loop)
.with_vsync(true);
#[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();
let windowed_context = unsafe { windowed_context.make_current().unwrap() };

View File

@ -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 {
pretty_env_logger::env_logger::from_env(Env::default().default_filter_or("info"))
//.filter(Some("ndk_glue"), LevelFilter::Trace)

5
src/main_android.rs Normal file
View 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();
}

View File

@ -627,10 +627,10 @@ impl NPC {
leg.direction = self.direction;
leg.parent_id = self.id;
npc_list.spawn(256, leg.clone());
let _ = npc_list.spawn(256, leg.clone());
leg.vel_x = 0x80;
npc_list.spawn(0, leg);
let _ = npc_list.spawn(0, leg);
}
self.vel_y2 += self.direction.vector_x() * 6;

View File

@ -598,7 +598,7 @@ impl GameScene {
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::clear(ctx, Color::from_rgb(100, 100, 110));

View File

@ -4,6 +4,7 @@ use std::time::Duration;
use cpal::Sample;
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
#[cfg(feature = "ogg-playback")]
use lewton::inside_ogg::OggStreamReader;
use num_traits::clamp;
@ -14,6 +15,7 @@ use crate::framework::error::GameError::{AudioError, InvalidValue};
use crate::framework::filesystem;
use crate::framework::filesystem::File;
use crate::settings::Settings;
#[cfg(feature = "ogg-playback")]
use crate::sound::ogg_playback::{OggPlaybackEngine, SavedOggPlaybackState};
use crate::sound::org_playback::{OrgPlaybackEngine, SavedOrganyaPlaybackState};
use crate::sound::organya::Song;
@ -21,6 +23,7 @@ use crate::sound::pixtone::PixTonePlayback;
use crate::sound::wave_bank::SoundBank;
use crate::str;
#[cfg(feature = "ogg-playback")]
mod ogg_playback;
mod org_playback;
mod organya;
@ -38,7 +41,9 @@ pub struct SoundManager {
enum SongFormat {
Organya,
#[cfg(feature = "ogg-playback")]
OggSinglePart,
#[cfg(feature = "ogg-playback")]
OggMultiPart,
}
@ -93,7 +98,9 @@ impl SoundManager {
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)]),
#[cfg(feature = "ogg-playback")]
(SongFormat::OggSinglePart, vec![format!("{}{}.ogg", prefix, song_name)]),
(SongFormat::Organya, vec![format!("{}{}.org", prefix, song_name)]),
]
@ -122,6 +129,7 @@ impl SoundManager {
}
}
}
#[cfg(feature = "ogg-playback")]
SongFormat::OggSinglePart => {
// we're sure that there's one element
let path = unsafe { paths.get_unchecked(0) };
@ -142,6 +150,7 @@ impl SoundManager {
}
}
}
#[cfg(feature = "ogg-playback")]
SongFormat::OggMultiPart => {
// we're sure that there are two elements
let path_intro = unsafe { paths.get_unchecked(0) };
@ -205,7 +214,9 @@ impl SoundManager {
enum PlaybackMessage {
Stop,
PlayOrganyaSong(Box<Song>),
#[cfg(feature = "ogg-playback")]
PlayOggSongSinglePart(Box<OggStreamReader<File>>),
#[cfg(feature = "ogg-playback")]
PlayOggSongMultiPart(Box<OggStreamReader<File>>, Box<OggStreamReader<File>>),
PlaySample(u8),
SetSpeed(f32),
@ -217,12 +228,14 @@ enum PlaybackMessage {
enum PlaybackState {
Stopped,
PlayingOrg,
#[cfg(feature = "ogg-playback")]
PlayingOgg,
}
enum PlaybackStateType {
None,
Organya(SavedOrganyaPlaybackState),
#[cfg(feature = "ogg-playback")]
Ogg(SavedOggPlaybackState),
}
@ -236,14 +249,18 @@ where
let mut saved_state: PlaybackStateType = PlaybackStateType::None;
let mut speed = 1.0;
let mut org_engine = OrgPlaybackEngine::new(&bank);
#[cfg(feature = "ogg-playback")]
let mut ogg_engine = OggPlaybackEngine::new();
let mut pixtone = PixTonePlayback::new();
pixtone.create_samples();
log::info!("Audio format: {} {}", sample_rate, channels);
org_engine.set_sample_rate(sample_rate as usize);
org_engine.loops = usize::MAX;
ogg_engine.set_sample_rate(sample_rate as usize);
#[cfg(feature = "ogg-playback")]
{
org_engine.loops = usize::MAX;
ogg_engine.set_sample_rate(sample_rate as usize);
}
let buf_size = sample_rate as usize * 10 / 1000;
let mut bgm_buf = vec![0x8080; buf_size * 2];
@ -275,6 +292,7 @@ where
state = PlaybackState::PlayingOrg;
}
#[cfg(feature = "ogg-playback")]
Ok(PlaybackMessage::PlayOggSongSinglePart(data)) => {
if state == PlaybackState::Stopped {
saved_state = PlaybackStateType::None;
@ -290,6 +308,7 @@ where
state = PlaybackState::PlayingOgg;
}
#[cfg(feature = "ogg-playback")]
Ok(PlaybackMessage::PlayOggSongMultiPart(data_intro, data_loop)) => {
if state == PlaybackState::Stopped {
saved_state = PlaybackStateType::None;
@ -318,6 +337,7 @@ where
Ok(PlaybackMessage::SetSpeed(new_speed)) => {
assert!(new_speed > 0.0);
speed = new_speed;
#[cfg(feature = "ogg-playback")]
ogg_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 {
PlaybackState::Stopped => PlaybackStateType::None,
PlaybackState::PlayingOrg => PlaybackStateType::Organya(org_engine.get_state()),
#[cfg(feature = "ogg-playback")]
PlaybackState::PlayingOgg => PlaybackStateType::Ogg(ogg_engine.get_state()),
};
}
@ -349,6 +370,7 @@ where
state = PlaybackState::PlayingOrg;
}
#[cfg(feature = "ogg-playback")]
PlaybackStateType::Ogg(playback_state) => {
ogg_engine.set_state(playback_state);
@ -383,6 +405,7 @@ where
bgm_index += 1;
((sample & 0xff) << 8, sample & 0xff00)
}
#[cfg(feature = "ogg-playback")]
PlaybackState::PlayingOgg => {
let samples = (bgm_buf[bgm_index], bgm_buf[bgm_index + 1]);
bgm_index += 2;
@ -402,6 +425,7 @@ where
let sample = bgm_buf[0];
((sample & 0xff) << 8, sample & 0xff00)
}
#[cfg(feature = "ogg-playback")]
PlaybackState::PlayingOgg => {
samples = ogg_engine.render_to(&mut bgm_buf);
bgm_index = 2;