Compare commits

...

2 Commits

Author SHA1 Message Date
an 892efbdb13 rozinante 2019-03-03 00:45:04 -05:00
an 1d057d66af some minor things 2019-03-03 00:44:45 -05:00
14 changed files with 92 additions and 59 deletions

View File

@ -206,7 +206,7 @@ pub fn rd_ofstable<T, F>(b: &[u8],
mut p: usize,
num: usize,
read: F)
-> ResultS<Vec<T>>
-> ResultS<Vec<T>>
where T: Sized,
F: Fn(&[u8]) -> ResultS<T>
{

View File

@ -13,7 +13,7 @@ fn crc_init() -> [u32; 256]
{
let mut t = [0; 256];
for (n, v) in t.iter_mut().enumerate() {
*v = (0..8).fold(u32::from(n), crc_accum);
*v = (0..8).fold(n as u32, crc_accum);
}
t
}

View File

@ -77,7 +77,7 @@ impl Sound16
/// Creates a new `Sound16` from an unsigned 8-bit stream.
pub fn new_from_8(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8])
-> Self
-> Self
{
let mut snd = Self::new(rate, lp_beg, lp_end, b.len());
@ -90,7 +90,7 @@ impl Sound16
/// Creates a new `Sound16` from a signed 16-bit stream.
pub fn new_from_16(rate: u16, lp_beg: usize, lp_end: usize, b: &[u8])
-> Self
-> Self
{
let mut snd = Self::new(rate, lp_beg, lp_end, b.len() / 2);

View File

@ -52,5 +52,6 @@
#[macro_use]
pub mod durandal;
pub mod marathon;
pub mod rozinante;
// EOF

View File

@ -136,13 +136,12 @@ pub fn read_sids(b: &[u8]) -> ResultS<(Side, usize)>
/// Reads an old `SIDS` chunk.
pub fn read_old_sids(b: &[u8]) -> ResultS<(Side, usize)>
{
let (mut side, siz) = read_sids(b)?;
let (side, siz) = read_sids(b)?;
side.tex_tra.tex_id = OptU16::none();
side.shade = Fixed::from_int(0);
side.flags.insert(SideFlags::ItemOpt);
Ok((side, siz))
Ok((Side{tex_tra: SideTex{tex_id: OptU16::none(), ..side.tex_tra},
shade: 0.into(),
flags: side.flags | SideFlags::ItemOpt,
..side}, siz))
}
/// Reads a `POLY` chunk.
@ -181,26 +180,24 @@ pub fn read_poly(b: &[u8]) -> ResultS<(Polygon, usize)>
/// Reads an old `POLY` chunk.
pub fn read_old_poly(b: &[u8]) -> ResultS<(Polygon, usize)>
{
let (mut poly, siz) = read_poly(b)?;
let (poly, siz) = read_poly(b)?;
poly.ptype = match poly.ptype {
PolyType::Hill => PolyType::OuchMinor,
PolyType::Base => PolyType::OuchMajor,
PolyType::ZoneBorder => PolyType::Glue,
PolyType::Goal => PolyType::GlueTrigger,
PolyType::TrigMonsVis => PolyType::GlueSuper,
PolyType::TrigMonsInv => PolyType::MustExplore,
PolyType::TrigMonsDual => PolyType::AutoExit,
ptype => ptype,
};
poly.ori_flr = Point{x: Unit::from_int(0), y: Unit::from_int(0)};
poly.ori_cei = Point{x: Unit::from_int(0), y: Unit::from_int(0)};
poly.med_ind = OptU16::none();
poly.snd_amb = OptU16::none();
poly.snd_rnd = OptU16::none();
Ok((poly, siz))
Ok((Polygon{ptype: match poly.ptype {
PolyType::Hill => PolyType::OuchMinor,
PolyType::Base => PolyType::OuchMajor,
PolyType::ZoneBorder => PolyType::Glue,
PolyType::Goal => PolyType::GlueTrigger,
PolyType::TrigMonsVis => PolyType::GlueSuper,
PolyType::TrigMonsInv => PolyType::MustExplore,
PolyType::TrigMonsDual => PolyType::AutoExit,
ptype => ptype,
},
ori_flr: Point{x: 0.into(), y: 0.into()},
ori_cei: Point{x: 0.into(), y: 0.into()},
med_ind: OptU16::none(),
snd_amb: OptU16::none(),
snd_rnd: OptU16::none(),
..poly}, siz))
}
/// Reads a `LITE` chunk.
@ -254,12 +251,11 @@ pub fn read_old_lite(b: &[u8]) -> ResultS<(Light, usize)>
LightFunc{ftype: func.ftype,
prd_nrm: if strobe {prd / 4 + 1} else {func.prd_nrm},
prd_dta: func.prd_dta,
val_nrm: if func.val_nrm > Fixed::from_int(0) {max} else {min},
val_nrm: if func.val_nrm > 0.into() {max} else {min},
val_dta: func.val_dta}
};
Ok((Light{ltype: lite.ltype,
flags,
Ok((Light{flags,
phase,
act_pri: old_lfun(&lite.act_pri),
act_sec: old_lfun(&lite.act_sec),
@ -267,7 +263,8 @@ pub fn read_old_lite(b: &[u8]) -> ResultS<(Light, usize)>
ina_pri: old_lfun(&lite.ina_pri),
ina_sec: old_lfun(&lite.ina_sec),
ina_mid: old_lfun(&lite.ina_mid),
tag: 0}, 32))
tag: 0,
..*lite}, 32))
}
/// Reads an `OBJS` chunk.
@ -595,7 +592,7 @@ pub struct Note
}
/// Static map information.
#[derive(Debug, PartialEq, serde::Serialize)]
#[derive(Debug, Default, PartialEq, serde::Serialize)]
pub struct Minf
{
pub env_code: u16,
@ -639,7 +636,7 @@ bitflags! {
bitflags! {
/// Static environment flags.
#[derive(serde::Serialize)]
#[derive(Default, serde::Serialize)]
pub struct EnvFlags: u16
{
const Vacuum = 1;
@ -660,7 +657,7 @@ bitflags! {
bitflags! {
/// Static entry point flags.
#[derive(serde::Serialize)]
#[derive(Default, serde::Serialize)]
pub struct EntFlags: u32
{
const Solo = 1;
@ -676,7 +673,7 @@ bitflags! {
bitflags! {
/// Static mission flags.
#[derive(serde::Serialize)]
#[derive(Default, serde::Serialize)]
pub struct MsnFlags: u16
{
const Extermination = 1;

View File

@ -7,7 +7,7 @@ fn read_pm_header<'a>(b: &'a [u8],
pack: bool,
clip: bool,
im: &Image8)
-> ResultS<(&'a [u8], Header)>
-> ResultS<(&'a [u8], Header)>
{
read_data! {
36, BE in b =>
@ -185,7 +185,7 @@ fn read_pm_32(mut im: Image8, b: &[u8], hdr: Header) -> ResultS<Image8>
/// Process a `CopyBits` operation.
fn read_pm_area(im: Image8, b: &[u8], pack: bool, clip: bool)
-> ResultS<Image8>
-> ResultS<Image8>
{
let p = if pack {0} else {4};
let (b, hdr) = read_pm_header(&b[p..], pack, clip, &im)?;

View File

@ -32,7 +32,7 @@ pub fn color_tables(b: &[u8],
tab_ofs: usize,
tab_num: usize,
clr_num: usize)
-> ResultS<Vec<Vec<ColorShp>>>
-> ResultS<Vec<Vec<ColorShp>>>
{
let end = tab_num * clr_num * 8;

View File

@ -65,7 +65,7 @@ pub fn read_entries(b: &[u8],
siz_app: usize,
siz_ent: usize,
siz_cnk: usize)
-> ResultS<BTreeMap<u16, Entry>>
-> ResultS<BTreeMap<u16, Entry>>
{
read_data! {
128, BE in b =>

View File

@ -0,0 +1,8 @@
//! Color presets.
use crate::durandal::image::Color16;
pub const CR_RED: Color16 = Color16::new(0xFFFF, 0, 0);
pub const CR_DARK_RED: Color16 = Color16::new(0x4700, 0, 0);
// EOF

View File

@ -1,4 +1,6 @@
use maraiah::durandal::image::*;
//! GUI drawing capabilities.
use crate::durandal::image::Color;
pub trait CacheImage
{
@ -15,7 +17,7 @@ pub trait DrawArea
fn clear(&self, cr: impl Color);
fn rect(&self, rect: Rect, cr: impl Color);
fn text(&self, pos: Point, cr: impl Color, text: &str);
fn text(&self, pos: Point, text: &str, cr: impl Color);
fn image(&self, pos: Point, im: &Self::NativeImage);
}
@ -25,7 +27,4 @@ pub type Point = (Coord, Coord);
#[derive(Copy, Clone, Debug)]
pub struct Rect {pub x: Coord, pub y: Coord, pub w: Coord, pub h: Coord}
pub const CR_RED: Color16 = Color16::new(0xFFFF, 0, 0);
pub const CR_DARK_RED: Color16 = Color16::new(0x4700, 0, 0);
// EOF

6
source/rozinante/mod.rs Normal file
View File

@ -0,0 +1,6 @@
//! Library for GUI programs.
pub mod color;
pub mod draw;
// EOF

View File

@ -1,5 +1,6 @@
use crate::stoneage::*;
use maraiah::durandal::image::*;
use maraiah::marathon::*;
use maraiah::rozinante::{color::*, draw::*};
pub fn draw_map_none<D, I>(d: &D, im: &I)
where D: DrawArea<NativeImage = I>,
@ -10,10 +11,30 @@ pub fn draw_map_none<D, I>(d: &D, im: &I)
d.image((d.w() / 2 - im.w() / 2, d.h() / 2 - im.h() / 2), im);
d.rect(Rect{x: 0, y: 0, w: d.w(), h: 18}, CR_DARK_RED);
d.text((4, 14), CR_RED, "Map Required To Proceed");
d.text((4, 14), "Map Required To Proceed", CR_RED);
d.rect(Rect{x: 0, y: d.h() - 18, w: d.w(), h: 18}, CR_DARK_RED);
d.text((4, d.h() - 4), CR_RED, "CAS.qterm//CyberAcme Systems Inc.");
d.text((4, d.h() - 4), "CAS.qterm//CyberAcme Systems Inc.", CR_RED);
}
pub fn new_map() -> MapState
{
let info = Default::default();
let ed = EditorState{};
let ma = MapState{ed, info};
ma
}
pub struct EditorState
{
}
pub struct MapState
{
ed: EditorState,
info: map::Minf,
}
// EOF

View File

@ -1,6 +1,5 @@
mod hiddenprotocol;
mod noroom;
mod stoneage;
use crate::hiddenprotocol::*;
use crate::noroom::*;
@ -21,7 +20,7 @@ fn mk_draw_area(b: &gtk::Builder)
let ax: gtk::Adjustment = get_obj(b, "adj-map-horz");
let ay: gtk::Adjustment = get_obj(b, "adj-map-vert");
let im = load_img("/net/greyserv/maraiah/tycho/tycho1");
let im = CairoPixbuf(load_img("/net/greyserv/maraiah/tycho/tycho1"));
area.connect_draw(move |area, cr| {
let w = f64::from(area.get_allocated_width());
@ -90,7 +89,7 @@ fn get_obj<T>(b: &gtk::Builder, name: &str) -> T
fn main() -> ResultS<()>
{
// get jacked, punk. opaque data structures are for nerds.
const RESOURCE_DATA: &'static [u8] = include_bytes!("data/tycho.res");
const RESOURCE_DATA: &[u8] = include_bytes!("data/tycho.res");
let mut static_resource =
gio_sys::GStaticResource{data: RESOURCE_DATA.as_ptr(),

View File

@ -1,4 +1,4 @@
use crate::stoneage::*;
use maraiah::rozinante::draw::*;
use maraiah::durandal::image::*;
fn flt_color(cr: impl Color) -> (f64, f64, f64)
@ -8,10 +8,10 @@ fn flt_color(cr: impl Color) -> (f64, f64, f64)
(flt_color(cr.r()), flt_color(cr.g()), flt_color(cr.b()))
}
impl CacheImage for gdk_pixbuf::Pixbuf
impl CacheImage for CairoPixbuf
{
fn w(&self) -> Coord {self.get_width() as Coord}
fn h(&self) -> Coord {self.get_height() as Coord}
fn w(&self) -> Coord {self.0.get_width() as Coord}
fn h(&self) -> Coord {self.0.get_height() as Coord}
}
impl CairoDrawArea
@ -24,7 +24,7 @@ impl CairoDrawArea
impl DrawArea for CairoDrawArea
{
type NativeImage = gdk_pixbuf::Pixbuf;
type NativeImage = CairoPixbuf;
fn w(&self) -> Coord {self.w}
fn h(&self) -> Coord {self.h}
@ -53,7 +53,7 @@ impl DrawArea for CairoDrawArea
self.ctx.fill();
}
fn text(&self, pos: Point, cr: impl Color, text: &str)
fn text(&self, pos: Point, text: &str, cr: impl Color)
{
let (r, g, b) = flt_color(cr);
@ -65,11 +65,13 @@ impl DrawArea for CairoDrawArea
fn image(&self, pos: Point, im: &Self::NativeImage)
{
use gdk::prelude::*;
self.ctx.set_source_pixbuf(im, f64::from(pos.0), f64::from(pos.1));
self.ctx.set_source_pixbuf(&im.0, f64::from(pos.0), f64::from(pos.1));
self.ctx.paint();
}
}
pub struct CairoPixbuf(pub gdk_pixbuf::Pixbuf);
pub struct CairoDrawArea
{
ctx: cairo::Context,