Giter Club home page Giter Club logo

autobatch's Introduction

autobatch

A small LÖVE (0.10.x) module which automatically uses SpriteBatches when drawing the same image multiple times in a row.

Usage

The autobatch.lua file should be dropped into an existing project, and the following line put at the top of your main.lua file:

require "autobatch"

The module overrides love.graphics and should work automatically without any additional changes to your code.

License

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

autobatch's People

Contributors

oniietzschan avatar rxi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autobatch's Issues

2 Bugs Related to setColor()

I've created a small main.lua which demonstrates a couple of ways that the behaviour of this library deviates from the expected result in Love 0.10.2.

-- main.lua

local origLoveGraphics = love.graphics
require 'autobatch'

local catImage = love.graphics.newImage('demo/cats/cat.png')

function _helpDraw(label, lg, x)
  local startingDrawCalls = lg.getStats().drawcalls
  lg.print(label, x, 30)

  -- Demonstrate BUG 1: love.graphics.push('all') .pop()
  lg.setColor(255, 128, 128)
  lg.push('all')
  lg.setColor(128, 255, 128)
  lg.push('all')
  lg.setColor(128, 128, 255)
  lg.draw(catImage, x, 115) -- Should be BLUE
  lg.pop()
  lg.draw(catImage, x, 170) -- Should be GREEN
  lg.pop()
  lg.draw(catImage, x, 225) -- Should be RED

  -- Demonstrate BUG 2: love.graphics.setColor() values over 255
  local val = 255 * 1.5
  lg.setColor(val, val, val)
  lg.draw(catImage, x, 330) -- Should be BRIGHT
  val = 255 * 2
  lg.setColor(val, val, val)
  lg.draw(catImage, x, 385) -- Should be RIGHTER
  val = 255 * 2.5
  lg.setColor(val, val, val)
  lg.draw(catImage, x, 440) -- Should be BRIGHTEST

  -- Print all text.
  -- Note that we do this at the end so that drawcalls aren't affected by lg.print()
  lg.setColor(0, 0, 0)
  local drawCalls = lg.getStats().drawcalls - startingDrawCalls
  lg.print("drawcalls: " .. drawCalls, x, 50)
  lg.print("BUG 1: .push('all') and .pop()", x, 100)
  lg.print("BUG 2: .setColor() w/ val over 255", x, 315)
end

function love.draw()
  love.graphics.clear(200, 200, 200)
  _helpDraw('Untouched Love2d', origLoveGraphics, 30)
  _helpDraw('autobatch.lua', love.graphics, 330)
end

Here's the output.

image

One other thing to note is that autobatch.lua takes 3 draw calls in order to draw everything. I suspect that it's possible to get this down to just 1 draw call.

Love2D 11.0 compatibility

Even though 11.0 added automated sprite batching,your implementation appears faster -
86FPS vs 77FPS for cats demo.

I understand that it would not make a big difference in normal non-benchmark use-cases but better performance is always welcome.

However, it appears that in 11.0 setBufferSize (used here) no longer exists, so removing the whole 'increase spritebatch capacity if already reached' is needed for 11.0.

Are you only planning on maintaining autobatch for pre-11.0 versions of Love2D?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.