Customizer

Struct Customizer 

Source
pub struct Customizer<'cls> { /* private fields */ }
Expand description

Customize the output for each Gfx macro, and extract data from each macro.

This allows extending or replacing the normal functionality of gfxd by registering callbacks for each specific situation.

Each callback is passed a reference of either MacroInfo, Printer, and/or MacroPrinter which allows to inspect the contents of the current macro or write output to the output buffer.

There are 3 major groups for the registered callbacks:

  • before_after_execution_callback: Callbacks that will be called before and after the current gfxd execution.
  • macro_fn: Replace or extend the behavior for each specific macro.
  • Argument callbacks: Callbacks that will be executed when certain types of macros are encountered.

Implementations§

Source§

impl Customizer<'_>

Source

pub fn new() -> Self

Create a new instance of the customizer.

Source§

impl<'cls> Customizer<'cls>

Source

pub fn before_after_execution_callback<B, A>( &mut self, before: &'cls mut B, after: &'cls mut A, ) -> &mut Self
where B: FnMut(&mut Printer), A: FnMut(&mut Printer),

Register callbacks that are called before and after the execution of gfxd.

Allows to do some setup work for the output buffer, like writing opening and closing braces.

before is called before gfxd starts executing, so the output buffer will be empty at this point. after is called once gfxd finishes running, and it is the very last code that is run before returning the disassembled output to the user.

Both callbacks are called only once.

§Examples
use gfxd_rs::{Customizer, Printer};

let mut before = |printer: &mut Printer| {
    printer.write_str("{\n");
};
let mut after = |printer: &mut Printer| {
    printer.write_str("}\n");
};

let mut customizer = Customizer::new();
customizer.before_after_execution_callback(&mut before, &mut after);
Source§

impl<'cls> Customizer<'cls>

Source

pub fn macro_fn<F>(&mut self, callback: &'cls mut F) -> &mut Self
where F: FnMut(&mut MacroPrinter, &mut MacroInfo) -> MacroFnRet,

Replace the default macro handler.

The user-defined macro handler may decide to extend the default behavior by writing custom output with write_str and calling the original macro handler by calling macro_dflt.

§Example

Make the output pretier

use gfxd_rs::{Customizer, MacroPrinter};

let mut macro_fn = |printer: &mut MacroPrinter, _info: &mut _| {
    /* Print 4 spaces before each macro, and a comma and newline after each macro */
    printer.write_str("    ");
    let ret = printer.macro_dflt(); /* Execute the default macro handler */
    printer.write_str(",\n");
    ret
};

let mut customizer = Customizer::new();
customizer.macro_fn(&mut macro_fn);
Source

pub fn arg_fn<F>(&mut self, callback: &'cls mut F) -> &mut Self
where F: FnMut(&mut MacroPrinter, &mut MacroInfo, i32),

Replace the default argument handler.

The registered callback will be called by macro_dflt for each argument in the current macro, not counting the dynamic display list pointer if one has been specified.

If the user has overriden the macro handler function and does not call macro_dflt in the replacement, then the given callback will never be called.

Source§

impl<'cls> Customizer<'cls>

Source

pub fn tlut_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self

Register a callback for TLUTs (Texture Look Up Table), a.k.a. palettes.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the tlut address,
  • the palette index and
  • the number of colors.
Source

pub fn timg_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self

Register a callback for textures of any kind.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the texture address,
  • the texture format,
  • the texture siz,
  • the width,
  • the height and
  • the palette index.
Source

pub fn cimg_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self

Register a callback for framebuffers.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the framebuffer address,
  • the framebuffer format,
  • the framebuffer siz and
  • the width.
Source

pub fn zimg_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self
where F: FnMut(&mut Printer, &mut MacroInfo, Address) -> DoDefaultOutput,

Register a callback for depthbuffers.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the depthbuffer address.
Source

pub fn dl_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self
where F: FnMut(&mut Printer, &mut MacroInfo, Address) -> DoDefaultOutput,

Register a callback for display lists.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the display list address.
Source

pub fn mtx_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self
where F: FnMut(&mut Printer, &mut MacroInfo, Address) -> DoDefaultOutput,

Register a callback for matrices.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the matrix address.
Source

pub fn lookat_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self

Register a callback for lookat arrays.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the lookat array address and
  • the number of lookat structures.
Source

pub fn light_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self
where F: FnMut(&mut Printer, &mut MacroInfo, Address) -> DoDefaultOutput,

Register a callback for lights.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the light address.
Source

pub fn lightsn_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self

Register a callback for lights N.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the light address and
  • the number of diffuse lights.
Source

pub fn seg_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self
where F: FnMut(&mut Printer, &mut MacroInfo, Address, u8) -> DoDefaultOutput,

Register a callback for segments.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the segment address.
Source

pub fn vtx_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self
where F: FnMut(&mut Printer, &mut MacroInfo, Address, i32) -> DoDefaultOutput,

Register a callback for vertices.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the vertex address.
Source

pub fn vp_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self
where F: FnMut(&mut Printer, &mut MacroInfo, Address) -> DoDefaultOutput,

Register a callback for viewports.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the viewport address.
Source

pub fn uctext_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self

Register a callback for microcode text.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the microcode text address and
  • the microcode text size.
Source

pub fn ucdata_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self

Register a callback for microcode data.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the microcode data address and
  • the microcode data size.
Source

pub fn dram_callback<F>(&mut self, callback: &'cls mut F) -> &mut Self

Register a callback for generic pointers.

The callback may return DoDefaultOutput::DoDefault to make gfxd to emit the default output for this argument, or DoDefaultOutput::Override to avoid emitting the default one and just use whatever the user printed.

Emit any desired output by using the Printer argument, and inspect information about the current macro with the MacroInfo argument.

The other arguments are:

  • the generic pointer and
  • the data size.

Trait Implementations§

Source§

impl Default for Customizer<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'cls> Freeze for Customizer<'cls>

§

impl<'cls> !RefUnwindSafe for Customizer<'cls>

§

impl<'cls> !Send for Customizer<'cls>

§

impl<'cls> !Sync for Customizer<'cls>

§

impl<'cls> Unpin for Customizer<'cls>

§

impl<'cls> !UnwindSafe for Customizer<'cls>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.