120 lines
4.0 KiB
Rust
120 lines
4.0 KiB
Rust
use ega;
|
|
|
|
use ::std;
|
|
use std::io::Read;
|
|
use std::path::Path;
|
|
|
|
use gfx::{self, texture, CommandBuffer};
|
|
use gfx::memory::Typed;
|
|
|
|
const TILEDIM: u16 = 16;
|
|
|
|
#[repr(C)]
|
|
#[derive(Clone, Copy)]
|
|
pub struct Tile {
|
|
pub val: u8,
|
|
}
|
|
|
|
pub fn get_tiles<D, F, T>(device: &mut D,
|
|
factory: &mut F,
|
|
command: &mut <D as gfx::Device>::CommandBuffer)
|
|
-> gfx::handle::ShaderResourceView<D::Resources, T::View>
|
|
where D: gfx::Device,
|
|
F: gfx::Factory<D::Resources>,
|
|
T: gfx::format::TextureFormat {
|
|
let filename = "data/SHAPES.EGA";
|
|
let mut file = std::fs::File::open(Path::new(filename))
|
|
.expect(&format!("failed opening tiles file: {}", filename));
|
|
let mut ega_bytes = Vec::new();
|
|
file.read_to_end(&mut ega_bytes).expect("Read tiles file");
|
|
let ega_page = ega::decode(&ega_bytes, ega::Compression::Uncompressed, ega::Tiling::Tiled(TILEDIM));
|
|
let mipmap = ega_page.mipmap(2);
|
|
|
|
let tex = factory.create_texture_immutable_u8::<T>(texture::Kind::D2Array(mipmap.dim as u16,
|
|
mipmap.dim as u16,
|
|
mipmap.len as u16,
|
|
texture::AaMode::Single),
|
|
texture::Mipmap::Provided,
|
|
&mipmap.slices())
|
|
.expect("create tile texture");
|
|
|
|
{
|
|
let mut manager = gfx::handle::Manager::<D::Resources>::new();
|
|
// XXX: Find out if Textures need to be/can be fenced like Buffers,
|
|
// Seems like I should mark tex.1 as being read/written, but it's not a Buffer?
|
|
let access = gfx::pso::AccessInfo::new();
|
|
let view = manager.ref_srv(tex.1.raw());
|
|
command.generate_mipmap(*view);
|
|
device.submit(command, &access).expect("generate tile mipmaps");
|
|
}
|
|
tex.1
|
|
}
|
|
|
|
|
|
|
|
impl Tile {
|
|
pub fn as_char(&self) -> char {
|
|
match self.val {
|
|
0 => '~', // deep water '🌊'
|
|
1 => '≈', // medium water
|
|
2 => '≋', // shallow water
|
|
3 => ',', // swamp
|
|
4 => '⢊', // plain '░'
|
|
5 => '🌿', // scrub 'წ'
|
|
6 => '🌳', // forest
|
|
7 => '⌓', // hill '∩'
|
|
8 => '⨇', // mountain '△'
|
|
9 => '☗', // dungeon
|
|
10 => '⍟', // city
|
|
11 | 13..=15 => '⛫', // castle
|
|
12 => '❖', // village
|
|
22 => '⎔', // tile floor
|
|
23 => '⟗', // bridge
|
|
24 => '⧬', // balloon
|
|
25 => '≃', // bridge top
|
|
26 => '≂', // bridge bottom
|
|
27 => '⍐', // ladder up
|
|
28 => '⍗', // ladder down
|
|
29 => 'v', // ruin
|
|
30 => '◌', // shrine
|
|
31 => '😇', // avatar
|
|
48 => '◯', // column
|
|
49 => '◣', // SW
|
|
50 => '◢', // SE
|
|
51 => '◤', // NW
|
|
52 => '◥', // NE
|
|
53 => '◉', // Mast
|
|
54 => '⎈', // ship's wheel
|
|
55 => 'ფ', // rocks '❍'
|
|
56 => '/', // Lyin down
|
|
57 => '⬛', // stone wall
|
|
58 => '⧯', // '🔒', // locked door
|
|
59 => '⧮', // '🔓', // unlocked door
|
|
60 => '💰', // chest
|
|
61 => '☥', // ankh
|
|
62 => '⨳', // brick floor '⌗'
|
|
63 => '▤', // wood planks '⧻'
|
|
68 => '🌫', // poison field
|
|
69 => '⚡', // energy field
|
|
70 => '🔥', // fire field
|
|
71 => '💤', // sleep field
|
|
72 => '▣', // solid barrier
|
|
73 => '▒', // hidden passage
|
|
75 => '🍖', // spit (rotisserie) '🍳'
|
|
76 => '⌘', // lava
|
|
// 79 => '💥', // attack flash
|
|
// 88 | 89 => 'ጿ', // beggar
|
|
96..=121 => ::std::char::from_u32((self.val - 31) as u32).unwrap(),
|
|
122 => '=', // space
|
|
123 => '⊐', // right ''
|
|
124 => '⊏', // left '⊨'
|
|
125 => '▢', // window
|
|
126 => '✨', // space
|
|
127 => '▓', // brick wall
|
|
// 140 | 141 => '🌀', // whirlpool
|
|
189 => '⚔', // phantom 2
|
|
_ => panic!("{0}", self.val)
|
|
}
|
|
}
|
|
}
|