Skip to content

Instantly share code, notes, and snippets.

@pzol
Created January 18, 2014 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pzol/8489002 to your computer and use it in GitHub Desktop.
Save pzol/8489002 to your computer and use it in GitHub Desktop.
ICE on 3d vector
enum TileSet {
Empty,
Dirt
}
type XYZ = (uint, uint, uint);
static MAXX: uint = 10;
static MAXY: uint = 10;
static MAXZ: uint = 1;
struct Map {
tiles: [[[TileSet, ..MAXX], ..MAXY], ..MAXZ]
}
impl Map {
fn new() -> Map {
Map { tiles: [[[Empty, ..MAXX], ..MAXY], ..MAXZ] }
}
fn set(&mut self, index: &XYZ, tile: TileSet) -> Result<TileSet, ~str> {
let (x, y, z) = *index;
self.tiles[z][y][x] = tile;
Ok(tile)
}
}
impl Index<(uint, uint, uint), Option<TileSet>> for Map {
fn index(&self, index: &XYZ) -> Option<TileSet> {
let (x, y, z) = *index;
println!("{}", self.tiles.len());
Some(self.tiles[z][y][x])
}
}
#[test]
fn test_3d_array(){
let mut map = Map::new();
map[(0, 0, 0)] = Some(Dirt);
let tile = map[(0, 0, 0)];
println!("{:?}", map);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment