Skip to content

Commit

Permalink
Fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
SiegeLordEx authored and SiegeLord committed Dec 25, 2024
1 parent 05f1c5f commit ec8167d
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 110 deletions.
16 changes: 16 additions & 0 deletions allegro/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ impl Bitmap
}
}

pub fn load_indexed(_: &Core, filename: &str) -> Result<Bitmap, ()>
{
unsafe {
let filename = CString::new(filename.as_bytes()).unwrap();
let b = al_load_bitmap_flags(filename.as_ptr(), ALLEGRO_KEEP_INDEX as i32);
if b.is_null()
{
Err(())
}
else
{
Ok(Bitmap::wrap(b, true))
}
}
}

/// Wraps an Allegro bitmap.
pub unsafe fn wrap(bmp: *mut ALLEGRO_BITMAP, own: bool) -> Bitmap
{
Expand Down
48 changes: 23 additions & 25 deletions allegro/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,32 +206,30 @@ impl Core
pub fn init_with_config(system_config: &Config) -> Result<Core, String>
{
use std::sync::Once;
static mut RUN_ONCE: Once = Once::new();
static RUN_ONCE: Once = Once::new();

let mut res = Err("Already initialized.".to_string());
unsafe {
RUN_ONCE.call_once(|| {
res = if al_install_system(ALLEGRO_VERSION_INT as c_int, None) != 0
{
al_merge_config_into(al_get_system_config(), system_config.get_allegro_config() as *const _);
let config = Config::wrap(al_get_system_config(), false);
Ok(Core { system_config: config })
}
else
{
let version = al_get_allegro_version();
let major = version >> 24;
let minor = (version >> 16) & 255;
let revision = (version >> 8) & 255;
let release = version & 255;

Err(format!(
"The system Allegro version ({}.{}.{}.{}) does not match the version of this binding ({}.{}.{}.{})",
major, minor, revision, release, ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION, ALLEGRO_RELEASE_NUMBER
))
};
});
}
RUN_ONCE.call_once(|| unsafe {
res = if al_install_system(ALLEGRO_VERSION_INT as c_int, None) != 0
{
al_merge_config_into(al_get_system_config(), system_config.get_allegro_config() as *const _);
let config = Config::wrap(al_get_system_config(), false);
Ok(Core { system_config: config })
}
else
{
let version = al_get_allegro_version();
let major = version >> 24;
let minor = (version >> 16) & 255;
let revision = (version >> 8) & 255;
let release = version & 255;

Err(format!(
"The system Allegro version ({}.{}.{}.{}) does not match the version of this binding ({}.{}.{}.{})",
major, minor, revision, release, ALLEGRO_VERSION, ALLEGRO_SUB_VERSION, ALLEGRO_WIP_VERSION, ALLEGRO_RELEASE_NUMBER
))
}
});
res
}

Expand Down Expand Up @@ -1074,7 +1072,7 @@ impl Core
/// Pass None to bmp to clear the sampler.
#[cfg(any(allegro_5_2_0, allegro_5_1_0))]
pub fn set_shader_sampler<T: BitmapLike>(
&mut self, name: &str, bmp: &T, unit: i32,
&self, name: &str, bmp: &T, unit: i32,
) -> Result<(), ()>
{
let c_name = CString::new(name.as_bytes()).unwrap();
Expand Down
1 change: 1 addition & 0 deletions allegro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#![crate_name = "allegro"]
#![crate_type = "lib"]
#![allow(unexpected_cfgs)]

extern crate allegro_sys as ffi;
extern crate libc;
Expand Down
24 changes: 11 additions & 13 deletions allegro_acodec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,19 @@ impl AcodecAddon
pub fn init(_: &AudioAddon) -> Result<AcodecAddon, String>
{
use std::sync::Once;
static mut RUN_ONCE: Once = Once::new();
static RUN_ONCE: Once = Once::new();

let mut res = Err("The acodec addon already initialized.".into());
unsafe {
RUN_ONCE.call_once(|| {
res = if al_init_acodec_addon() != 0
{
Ok(AcodecAddon { _dummy: () })
}
else
{
Err("Could not initialize the acodec addon.".into())
}
})
}
RUN_ONCE.call_once(|| unsafe {
res = if al_init_acodec_addon() != 0
{
Ok(AcodecAddon { _dummy: () })
}
else
{
Err("Could not initialize the acodec addon.".into())
}
});
res
}

Expand Down
24 changes: 11 additions & 13 deletions allegro_audio/src/addon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@ impl AudioAddon
pub fn init(_: &Core) -> Result<AudioAddon, String>
{
use std::sync::Once;
static mut RUN_ONCE: Once = Once::new();
static RUN_ONCE: Once = Once::new();

let mut res = Err("The audio addon already initialized.".into());
unsafe {
RUN_ONCE.call_once(|| {
res = if al_install_audio() != 0
{
Ok(AudioAddon { _dummy: () })
}
else
{
Err("Could not initialize the audio addon.".into())
}
})
}
RUN_ONCE.call_once(|| unsafe {
res = if al_install_audio() != 0
{
Ok(AudioAddon { _dummy: () })
}
else
{
Err("Could not initialize the audio addon.".into())
}
});
res
}

Expand Down
24 changes: 11 additions & 13 deletions allegro_dialog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,19 @@ impl DialogAddon
pub fn init(_: &Core) -> Result<DialogAddon, String>
{
use std::sync::Once;
static mut RUN_ONCE: Once = Once::new();
static RUN_ONCE: Once = Once::new();

let mut res = Err("The dialog addon already initialized.".into());
unsafe {
RUN_ONCE.call_once(|| {
res = if al_init_native_dialog_addon() != 0
{
Ok(DialogAddon { _dummy: () })
}
else
{
Err("Could not initialize the dialog addon.".into())
}
})
}
RUN_ONCE.call_once(|| unsafe {
res = if al_init_native_dialog_addon() != 0
{
Ok(DialogAddon { _dummy: () })
}
else
{
Err("Could not initialize the dialog addon.".into())
}
});
res
}

Expand Down
12 changes: 5 additions & 7 deletions allegro_font/src/addon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ impl FontAddon
pub fn init(_: &Core) -> Result<FontAddon, String>
{
use std::sync::Once;
static mut RUN_ONCE: Once = Once::new();
static RUN_ONCE: Once = Once::new();

let mut res = Err("The font addon already initialized.".into());
unsafe {
RUN_ONCE.call_once(|| {
al_init_font_addon();
res = Ok(FontAddon { _dummy: () });
})
}
RUN_ONCE.call_once(|| unsafe {
al_init_font_addon();
res = Ok(FontAddon { _dummy: () });
});
res
}

Expand Down
24 changes: 11 additions & 13 deletions allegro_image/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@ impl ImageAddon
pub fn init(_: &Core) -> Result<ImageAddon, String>
{
use std::sync::Once;
static mut RUN_ONCE: Once = Once::new();
static RUN_ONCE: Once = Once::new();

let mut res = Err("The image addon already initialized.".into());
unsafe {
RUN_ONCE.call_once(|| {
res = if al_init_image_addon() != 0
{
Ok(ImageAddon { _dummy: () })
}
else
{
Err("Could not initialize the image addon.".into())
}
})
}
RUN_ONCE.call_once(|| unsafe {
res = if al_init_image_addon() != 0
{
Ok(ImageAddon { _dummy: () })
}
else
{
Err("Could not initialize the image addon.".into())
}
});
res
}

Expand Down
25 changes: 12 additions & 13 deletions allegro_primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#![crate_name = "allegro_primitives"]
#![crate_type = "lib"]
#![allow(unexpected_cfgs)]

extern crate allegro;
extern crate allegro_primitives_sys;
Expand Down Expand Up @@ -73,21 +74,19 @@ impl PrimitivesAddon
pub fn init(_: &Core) -> Result<PrimitivesAddon, String>
{
use std::sync::Once;
static mut RUN_ONCE: Once = Once::new();
static RUN_ONCE: Once = Once::new();

let mut res = Err("The primitives addon already initialized.".into());
unsafe {
RUN_ONCE.call_once(|| {
res = if al_init_primitives_addon() != 0
{
Ok(PrimitivesAddon { _dummy: () })
}
else
{
Err("Could not initialize the primitives addon.".into())
};
})
}
RUN_ONCE.call_once(|| unsafe {
res = if al_init_primitives_addon() != 0
{
Ok(PrimitivesAddon { _dummy: () })
}
else
{
Err("Could not initialize the primitives addon.".into())
};
});
res
}

Expand Down
24 changes: 11 additions & 13 deletions allegro_ttf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,19 @@ impl TtfAddon
pub fn init(_: &FontAddon) -> Result<TtfAddon, String>
{
use std::sync::Once;
static mut RUN_ONCE: Once = Once::new();
static RUN_ONCE: Once = Once::new();

let mut res = Err("The TTF addon already initialized.".into());
unsafe {
RUN_ONCE.call_once(|| {
res = if al_init_ttf_addon() != 0
{
Ok(TtfAddon { _dummy: () })
}
else
{
Err("Could not initialize the TTF addon.".into())
}
})
}
RUN_ONCE.call_once(|| unsafe {
res = if al_init_ttf_addon() != 0
{
Ok(TtfAddon { _dummy: () })
}
else
{
Err("Could not initialize the TTF addon.".into())
}
});
res
}

Expand Down

0 comments on commit ec8167d

Please sign in to comment.