mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-06 13:15:47 -06:00
refactor: use 'unsafe_textures' sdl2 feature to hide lifetimes & obscure leaks into upstream
This commit is contained in:
14
Cargo.toml
14
Cargo.toml
@@ -42,16 +42,14 @@ windows-sys = { version = "0.60.2", features = ["Win32_System_Console"] }
|
||||
[target.'cfg(not(target_os = "windows"))'.dependencies]
|
||||
libc = "0.2"
|
||||
|
||||
|
||||
[target.'cfg(target_os = "emscripten")'.dependencies.sdl2]
|
||||
version = "0.38"
|
||||
default-features = false
|
||||
features = ["ttf","image","gfx","mixer"]
|
||||
|
||||
[target.'cfg(not(target_os = "emscripten"))'.dependencies.sdl2]
|
||||
version = "0.38"
|
||||
default-features = false
|
||||
features = ["ttf","image","gfx","mixer","static-link","use-vcpkg"]
|
||||
features = ["image", "ttf", "gfx", "mixer", "unsafe_textures", "static-link", "use-vcpkg"]
|
||||
|
||||
[target.'cfg(target_os = "emscripten")'.dependencies]
|
||||
sdl2 = { version = "0.38", default-features = false, features = ["image", "ttf", "gfx", "mixer", "unsafe_textures"] }
|
||||
libc = "0.2.175" # TODO: Describe why this is required.
|
||||
|
||||
[package.metadata.vcpkg]
|
||||
dependencies = ["sdl2", "sdl2-image", "sdl2-ttf", "sdl2-gfx", "sdl2-mixer"]
|
||||
@@ -64,8 +62,6 @@ x86_64-unknown-linux-gnu = { triplet = "x64-linux" }
|
||||
x86_64-apple-darwin = { triplet = "x64-osx" }
|
||||
aarch64-apple-darwin = { triplet = "arm64-osx" }
|
||||
|
||||
[target.'cfg(target_os = "emscripten")'.dependencies]
|
||||
libc = "0.2.175"
|
||||
|
||||
[build-dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
@@ -23,7 +23,7 @@ fn f32_to_u8(value: f32) -> u8 {
|
||||
}
|
||||
|
||||
/// Resource to hold the debug texture for persistent rendering
|
||||
pub struct DebugTextureResource(pub Texture<'static>);
|
||||
pub struct DebugTextureResource(pub Texture);
|
||||
|
||||
/// Resource to hold the debug font
|
||||
pub struct DebugFontResource(pub Font<'static, 'static>);
|
||||
|
||||
@@ -100,10 +100,10 @@ pub fn linear_render_system(dt: Res<DeltaTime>, mut query: Query<(&mut LinearAni
|
||||
}
|
||||
|
||||
/// A non-send resource for the map texture. This just wraps the texture with a type so it can be differentiated when exposed as a resource.
|
||||
pub struct MapTextureResource(pub Texture<'static>);
|
||||
pub struct MapTextureResource(pub Texture);
|
||||
|
||||
/// A non-send resource for the backbuffer texture. This just wraps the texture with a type so it can be differentiated when exposed as a resource.
|
||||
pub struct BackbufferResource(pub Texture<'static>);
|
||||
pub struct BackbufferResource(pub Texture);
|
||||
|
||||
/// Renders the HUD (score, lives, etc.) on top of the game.
|
||||
pub fn hud_render_system(
|
||||
|
||||
@@ -79,7 +79,7 @@ impl AtlasTile {
|
||||
/// and optional default color modulation configuration.
|
||||
pub struct SpriteAtlas {
|
||||
/// The combined texture containing all sprite frames
|
||||
texture: Texture<'static>,
|
||||
texture: Texture,
|
||||
/// Mapping from sprite names to their pixel coordinates within the texture
|
||||
tiles: HashMap<String, MapperFrame>,
|
||||
default_color: Option<Color>,
|
||||
@@ -88,7 +88,7 @@ pub struct SpriteAtlas {
|
||||
}
|
||||
|
||||
impl SpriteAtlas {
|
||||
pub fn new(texture: Texture<'static>, mapper: AtlasMapper) -> Self {
|
||||
pub fn new(texture: Texture, mapper: AtlasMapper) -> Self {
|
||||
Self {
|
||||
texture,
|
||||
tiles: mapper.frames,
|
||||
@@ -117,7 +117,7 @@ impl SpriteAtlas {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn texture(&self) -> &Texture<'static> {
|
||||
pub fn texture(&self) -> &Texture {
|
||||
&self.texture
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use pacman::{
|
||||
};
|
||||
use sdl2::{
|
||||
image::LoadTexture,
|
||||
render::{Canvas, Texture, TextureCreator},
|
||||
render::{Canvas, TextureCreator},
|
||||
video::{Window, WindowContext},
|
||||
Sdl,
|
||||
};
|
||||
@@ -31,7 +31,6 @@ pub fn create_atlas(canvas: &mut sdl2::render::Canvas<sdl2::video::Window>) -> S
|
||||
let atlas_bytes = get_asset_bytes(Asset::AtlasImage).unwrap();
|
||||
|
||||
let texture = texture_creator.load_texture_bytes(&atlas_bytes).unwrap();
|
||||
let texture: Texture<'static> = unsafe { std::mem::transmute(texture) };
|
||||
|
||||
let atlas_mapper = AtlasMapper {
|
||||
frames: ATLAS_FRAMES.into_iter().map(|(k, v)| (k.to_string(), *v)).collect(),
|
||||
|
||||
@@ -3,7 +3,7 @@ use pacman::texture::sprite::{AtlasMapper, AtlasTile, MapperFrame, SpriteAtlas};
|
||||
use sdl2::pixels::Color;
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn mock_texture() -> sdl2::render::Texture<'static> {
|
||||
fn mock_texture() -> sdl2::render::Texture {
|
||||
unsafe { std::mem::transmute(0usize) }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user