message: begin stubbing out
diff: @@ -30,14 +30,23 @@ use GameResult;
  // For now though, let's mess around with the gfx bits rather than the ggez bits.
  // We need to be able to, essentially, have an array of RectProperties.
  +
  /// A SpriteBatch draws a number of copies of the same image, using a single draw call.
  #[derive(Debug)]
  pub struct SpriteBatch {
  image: graphics::Image,
  - sprites: Vec<graphics::DrawParam>,
  + sprites: Vec<SpriteInfo>,
  + quads: Vec<graphics::Rect>
  }
  pub type SpriteIdx = usize;
  +pub type QuadIdx = usize;
  +
  +#[derive(Debug)]
  +pub struct SpriteInfo {
  + param: graphics::DrawParam,
  + quad_handle: Option<QuadIdx>
  +}
  impl SpriteBatch {
  /// Creates a new `SpriteBatch`, drawing with the given image.
  @@ -45,6 +54,7 @@ impl SpriteBatch {
  Self {
  image: image,
  sprites: vec![],
  + quads: vec![]
  }
  }
  @@ -52,13 +62,56 @@ impl SpriteBatch {
  ///
  /// Returns a handle with which to modify the sprite using `set()`
  pub fn add(&mut self, param: graphics::DrawParam) -> SpriteIdx {
  - self.sprites.push(param);
  + self.sprites.push(
  + SpriteInfo{
  + param,
  + quad_handle: None
  + }
  + );
  + self.sprites.len() - 1
  + }
  +
  + /// Adds a new quad defining a region of the source image to use
  + /// when drawing a sprite. Allows use of a texture atlas to batch
  + /// multiple types of tiles etc at once.
  + ///
  + /// Returns a handle with which to modify the quad or reference it
  + /// when adding a new sprite.
  + pub fn add_quad(&mut self, quad: graphics::Rect) -> QuadIdx {
  + self.quads.push(quad);
  + self.quads.len() - 1
  + }
  +
  + /// Adds a new sprite to the batch using the given quad handle.
  + ///
  + /// Returns a handle with which to modify the sprite using `set()`
  + pub fn add_with_quad(
  + &mut self,
  + param: graphics::DrawParam,
  + quad_handle: QuadIdx
  + ) -> SpriteIdx {
  + self.sprites.push(
  + SpriteInfo {
  + param,
  + quad_handle: Some(quad_handle)
  + }
  + );
  self.sprites.len() - 1
  }
  - /// Alters a sprite in the batch to use the given draw params.
  + /// Alters a sprite in the batch to use the given draw params
  pub fn set(&mut self, handle: SpriteIdx, param: graphics::DrawParam) {
  - self.sprites[handle] = param;
  + self.sprites[handle].param = param;
  + }
  +
  + /// Alters a sprite in the batch to use the given `SpriteInfo`
  + pub fn set_ex(&mut self, handle: SpriteIdx, info: SpriteInfo) {
  + self.sprites[handle] = info;
  + }
  +
  + /// Alters a quad in the batch to use the given Rect instead
  + pub fn set_quad(&mut self, handle: QuadIdx, quad: graphics::Rect) {
  + self.quads[handle] = quad;
  }
  /// Immediately sends all data in the batch to the graphics card.
  @@ -67,7 +120,7 @@ impl SpriteBatch {
  /// will do this automatically.
  pub fn flush(&self, ctx: &mut Context) {
  for s in &self.sprites {
  - graphics::draw_ex(ctx, &self.image, *s);
  + graphics::draw_ex(ctx, &self.image, s.param);
  }
  }
  