Skip to content

Commit

Permalink
Nicer, alternate workaround for rust-lang/rust#30905
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Jul 12, 2016
1 parent 5b3073c commit 4706af1
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 58 deletions.
8 changes: 4 additions & 4 deletions src/gamedata_io/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
use {GameDataRead, GameDataWrite, Code, CodeChunk};
use gamedata_io::{Chunk, get_chunk_header, ReadError, read_into_byte_vec, Tell};

pub fn write_offsets<W: GameDataWrite>(code: &Code,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
pub(crate) fn write_offsets<W: GameDataWrite>(code: &Code,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
// Skip num_codes + offset table
try!(writer.seek(io::SeekFrom::Current(code.code_chunks.len() as i64 * 4 + 4)));
for chunk in &code.code_chunks {
Expand Down
8 changes: 4 additions & 4 deletions src/gamedata_io/fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pub struct Offset {
pub font_name: u32,
}

pub fn write_offsets<W: GameDataWrite>(fonts: &Fonts,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
pub(crate) fn write_offsets<W: GameDataWrite>(fonts: &Fonts,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
try!(writer.seek(io::SeekFrom::Current(4 + fonts.fonts.len() as i64 * 4)));
for f in &fonts.fonts {
try!(writer.write_u32::<LittleEndian>(string_offsets[f.name_index]));
Expand Down
8 changes: 4 additions & 4 deletions src/gamedata_io/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
use {GameDataRead, GameDataWrite, Function, Functions};
use gamedata_io::{Chunk, get_chunk_header, ReadError};

pub fn write_offsets<W: GameDataWrite>(funs: &Functions,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
pub(crate) fn write_offsets<W: GameDataWrite>(funs: &Functions,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
for fun in &funs.functions {
try!(writer.write_u32::<LittleEndian>(string_offsets[fun.name_index]));
try!(writer.seek(io::SeekFrom::Current(2 * 4)));
Expand Down
8 changes: 4 additions & 4 deletions src/gamedata_io/meta_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ pub struct Offsets {
pub window_title: u32,
}

pub fn write_offsets<W: GameDataWrite>(meta_data: &MetaData,
writer: &mut W,
offsets: &[u32])
-> io::Result<()> {
pub(crate) fn write_offsets<W: GameDataWrite>(meta_data: &MetaData,
writer: &mut W,
offsets: &[u32])
-> io::Result<()> {
try!(writer.seek(io::SeekFrom::Current(4)));
trace!("Writing {} at offset {}",
offsets[meta_data.game_id_1_index],
Expand Down
10 changes: 5 additions & 5 deletions src/gamedata_io/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ pub struct Offsets {
pub const14_offset: u32,
}

pub fn write_offsets<W: GameDataWrite>(options: &Options,
writer: &mut W,
texture_data_offset: u32,
string_offsets: &[u32])
-> io::Result<()> {
pub(crate) fn write_offsets<W: GameDataWrite>(options: &Options,
writer: &mut W,
texture_data_offset: u32,
string_offsets: &[u32])
-> io::Result<()> {
try!(writer.seek(io::SeekFrom::Current(2 * 4)));
try!(writer.write_u32::<LittleEndian>(texture_data_offset + options.icon_offset));
try!(writer.seek(io::SeekFrom::Current(13 * 4)));
Expand Down
8 changes: 4 additions & 4 deletions src/gamedata_io/scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
use {GameDataRead, GameDataWrite, Script, Scripts};
use gamedata_io::{Chunk, get_chunk_header, ReadError, Tell};

pub fn write_offsets<W: GameDataWrite>(scripts: &Scripts,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
pub(crate) fn write_offsets<W: GameDataWrite>(scripts: &Scripts,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
try!(writer.seek(io::SeekFrom::Current(4 + (scripts.scripts.len() * 4) as i64)));
for s in &scripts.scripts {
try!(writer.write_u32::<LittleEndian>(string_offsets[s.name_index]));
Expand Down
8 changes: 4 additions & 4 deletions src/gamedata_io/sounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub struct Offsets {
pub filename_offset: u32,
}

pub fn write_offsets<W: GameDataWrite>(sounds: &Sounds,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
pub(crate) fn write_offsets<W: GameDataWrite>(sounds: &Sounds,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
try!(writer.seek(io::SeekFrom::Current((4 + (sounds.sounds.len() * 4) as i64))));
for s in &sounds.sounds {
try!(writer.write_u32::<LittleEndian>(string_offsets[s.name_index]));
Expand Down
8 changes: 4 additions & 4 deletions src/gamedata_io/sprites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
use {GameDataRead, GameDataWrite, Sprite, Sprites};
use gamedata_io::{Chunk, get_chunk_header, ReadError, read_into_byte_vec, Tell};

pub fn write_offsets<W: GameDataWrite>(sprites: &Sprites,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
pub(crate) fn write_offsets<W: GameDataWrite>(sprites: &Sprites,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
try!(writer.seek(io::SeekFrom::Current(4 + (sprites.sprites.len() as i64 * 4))));
for s in &sprites.sprites {
try!(writer.write_u32::<LittleEndian>(string_offsets[s.name_index]));
Expand Down
8 changes: 4 additions & 4 deletions src/gamedata_io/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LittleEndian};
use {GameDataRead, GameDataWrite, Variable, Variables};
use gamedata_io::{Chunk, get_chunk_header, ReadError};

pub fn write_offsets<W: GameDataWrite>(variables: &Variables,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
pub(crate) fn write_offsets<W: GameDataWrite>(variables: &Variables,
writer: &mut W,
string_offsets: &[u32])
-> io::Result<()> {
for var in &variables.variables {
try!(writer.write_u32::<LittleEndian>(string_offsets[var.name_index]));
try!(writer.seek(io::SeekFrom::Current(8)));
Expand Down
42 changes: 21 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! ```
//!

#![feature(associated_consts)]
#![feature(associated_consts, pub_restricted)]
#![warn(missing_docs, trivial_casts, trivial_numeric_casts)]

#[macro_use]
Expand Down Expand Up @@ -118,7 +118,7 @@ impl GameData {
}

/// Contains various metadata, for example, the window width/height/title.
pub struct MetaData {
struct MetaData {
// Possibly some kind of GEN8 version number. Unsure.
// But let's assume, since we need to take multiple versions into consideration, and
// this value seems to differ for different versions.
Expand Down Expand Up @@ -152,7 +152,7 @@ pub struct MetaData {
}

/// Game Maker project Options
pub struct Options {
struct Options {
unk1: u32, // Unknown
unk2: u32, // Unknown
icon_offset: u32, // Points to texture data (icon?)
Expand Down Expand Up @@ -186,7 +186,7 @@ pub struct Options {
}

/// Purpose unknown.
pub struct Extn {
struct Extn {
raw: Vec<u8>, // Data not analyzed yet
}

Expand Down Expand Up @@ -214,7 +214,7 @@ pub struct Sounds {
}

/// Collection of audio groups. Not present in all games.
pub struct AudioGroups {
struct AudioGroups {
raw: Vec<u8>, // Data not analyzed yet
}

Expand All @@ -237,30 +237,30 @@ pub struct Sprites {
}

/// A collection of backgrounds.
pub struct Backgrounds {
struct Backgrounds {
raw: Vec<u8>, // Data not analyzed yet
}

/// A collection of paths.
pub struct Paths {
struct Paths {
raw: Vec<u8>, // Data not analyzed yet
}

/// A game maker script.
pub struct Script {
struct Script {
/// Index of the name of the script in the string table
pub name_index: usize,
unknown: u32, // Unknown
}

/// A collection of scripts.
pub struct Scripts {
struct Scripts {
/// The scripts.
pub scripts: Vec<Script>,
}

/// A collection of shaders.
pub struct Shaders {
struct Shaders {
raw: Vec<u8>, // Data not analyzed yet
}

Expand All @@ -284,27 +284,27 @@ pub struct Fonts {
}

/// A collection of timelines.
pub struct Timelines {
struct Timelines {
raw: Vec<u8>, // Data not analyzed yet
}

/// A collection of objects.
pub struct Objects {
struct Objects {
raw: Vec<u8>, // Data not analyzed yet
}

/// A collection of rooms.
pub struct Rooms {
struct Rooms {
raw: Vec<u8>, // Data not analyzed yet
}

/// Purpose unknown.
pub struct Dafl {
struct Dafl {
raw: Vec<u8>, // Data not analyzed yet
}

/// Purpose unknown.
pub struct Tpag {
struct Tpag {
raw: Vec<u8>, // Data not analyzed yet
}

Expand All @@ -323,29 +323,29 @@ pub struct Code {
}

/// A game maker variable.
pub struct Variable {
struct Variable {
/// Index of the name of the variable in the strings section.
pub name_index: usize,
unknown: u32, // Purpose unknown. Ranges from 1 to a few thousand.
code_offset: u32, // Points into the code section
}

/// A collection of variables.
pub struct Variables {
struct Variables {
/// The variables.
pub variables: Vec<Variable>,
}

/// A game maker function.
pub struct Function {
struct Function {
/// Index of the name of the function in the strings section.
pub name_index: usize,
unknown: u32, // Purpose unknown. Ranges from 1 to a few thousand.
code_offset: u32, // Points into the code section.
}

/// A collection of functions.
pub struct Functions {
struct Functions {
/// The functions.
pub functions: Vec<Function>,
}
Expand Down Expand Up @@ -374,12 +374,12 @@ pub struct Textures {
}

/// Raw audio data.
pub struct AudioData {
struct AudioData {
data: Vec<u8>,
}

/// A collection of audio data.
pub struct Audio {
struct Audio {
audio: Vec<AudioData>,
offsets: Vec<u32>, // Audio data is not contiguous, so we need to store relative offsets
}

0 comments on commit 4706af1

Please sign in to comment.