Skip to content
Snippets Groups Projects
Unverified Commit e05eda43 authored by Anti-Alias's avatar Anti-Alias Committed by GitHub
Browse files

Changed Rc<Tileset> to Arc<Tileset> (#156)

* Changed Rc to Arc

* Trying to trigger a rebuild

* Trying to trigger a rebuild

* Testing
parent 3c2f804b
No related branches found
No related tags found
No related merge requests found
use std::rc::Rc;
use std::sync::Arc;
use sfml::{
graphics::{FloatRect, Texture},
......@@ -9,12 +9,12 @@ use tiled::Tileset;
/// A container for a tileset and the texture it references.
pub struct Tilesheet {
texture: SfBox<Texture>,
tileset: Rc<Tileset>,
tileset: Arc<Tileset>,
}
impl Tilesheet {
/// Create a tilesheet from a Tiled tileset, loading its texture along the way.
pub fn from_tileset<'p>(tileset: Rc<Tileset>) -> Self {
pub fn from_tileset<'p>(tileset: Arc<Tileset>) -> Self {
let tileset_image = tileset.image.as_ref().unwrap();
let texture = {
......
use std::{
collections::HashMap,
path::{Path, PathBuf},
rc::Rc,
sync::Arc,
};
use crate::Tileset;
......@@ -10,19 +10,19 @@ pub type ResourcePath = Path;
pub type ResourcePathBuf = PathBuf;
pub trait ResourceCache {
fn get_tileset(&self, path: impl AsRef<ResourcePath>) -> Option<Rc<Tileset>>;
fn get_tileset(&self, path: impl AsRef<ResourcePath>) -> Option<Arc<Tileset>>;
fn get_or_try_insert_tileset_with<F, E>(
&mut self,
path: ResourcePathBuf,
f: F,
) -> Result<Rc<Tileset>, E>
) -> Result<Arc<Tileset>, E>
where
F: FnOnce() -> Result<Tileset, E>;
}
/// A cache that identifies resources by their path in the user's filesystem.
pub struct FilesystemResourceCache {
tilesets: HashMap<ResourcePathBuf, Rc<Tileset>>,
tilesets: HashMap<ResourcePathBuf, Arc<Tileset>>,
}
impl FilesystemResourceCache {
......@@ -34,7 +34,7 @@ impl FilesystemResourceCache {
}
impl ResourceCache for FilesystemResourceCache {
fn get_tileset(&self, path: impl AsRef<ResourcePath>) -> Option<Rc<Tileset>> {
fn get_tileset(&self, path: impl AsRef<ResourcePath>) -> Option<Arc<Tileset>> {
self.tilesets.get(path.as_ref()).map(Clone::clone)
}
......@@ -42,13 +42,13 @@ impl ResourceCache for FilesystemResourceCache {
&mut self,
path: ResourcePathBuf,
f: F,
) -> Result<Rc<Tileset>, E>
) -> Result<Arc<Tileset>, E>
where
F: FnOnce() -> Result<Tileset, E>,
{
Ok(match self.tilesets.entry(path) {
std::collections::hash_map::Entry::Occupied(o) => o.into_mut(),
std::collections::hash_map::Entry::Vacant(v) => v.insert(Rc::new(f()?)),
std::collections::hash_map::Entry::Vacant(v) => v.insert(Arc::new(f()?)),
}
.clone())
}
......
use std::{collections::HashMap, fmt, fs::File, io::Read, path::Path, rc::Rc, str::FromStr};
use std::{collections::HashMap, fmt, fs::File, io::Read, path::Path, sync::Arc, str::FromStr};
use xml::{attribute::OwnedAttribute, reader::XmlEvent, EventReader};
......@@ -13,7 +13,7 @@ use crate::{
pub(crate) struct MapTilesetGid {
pub first_gid: Gid,
pub tileset: Rc<Tileset>,
pub tileset: Arc<Tileset>,
}
/// All Tiled map files will be parsed into this. Holds all the layers and tilesets.
......@@ -31,7 +31,7 @@ pub struct Map {
/// Tile height, in pixels.
pub tile_height: u32,
/// The tilesets present on this map.
tilesets: Vec<Rc<Tileset>>,
tilesets: Vec<Arc<Tileset>>,
/// The layers present in this map.
layers: Vec<LayerData>,
/// The custom properties of this map.
......@@ -100,7 +100,7 @@ impl Map {
impl Map {
/// Get a reference to the map's tilesets.
pub fn tilesets(&self) -> &[Rc<Tileset>] {
pub fn tilesets(&self) -> &[Arc<Tileset>] {
self.tilesets.as_ref()
}
......@@ -186,7 +186,7 @@ impl Map {
tilesets.push(MapTilesetGid{first_gid: res.first_gid, tileset});
}
EmbeddedParseResultType::Embedded { tileset } => {
tilesets.push(MapTilesetGid{first_gid: res.first_gid, tileset: Rc::new(tileset)});
tilesets.push(MapTilesetGid{first_gid: res.first_gid, tileset: Arc::new(tileset)});
},
};
Ok(())
......
temp 0 → 100644
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment