├── 2d_array_vectors.lua ├── README.md ├── cool-repos.md ├── external-tools.md ├── love2d-and-zerobrane.md ├── luajit-debugger.md ├── scratch.md └── smaller_rectangles.lua /2d_array_vectors.lua: -------------------------------------------------------------------------------- 1 | -- [17:06] 2d we just do map[x][y] but for 1d its complicated you would have to find a way to store the coords in there along with the data. 2 | -- [17:12] like for example map[x][y] returns {x,y} 3 | -- [17:12] so rewriting that would be difficult. 4 | -- [17:10] <+slime> instead of having {{x,y}, {x,y}, {x,y}, {x,y}, ...}, you could have {x,y, x,y, x,y, x,y, ...} 5 | -- [17:12] <+slime> intead you could have it be map[x][y*2+0] returns x, and map[x][y*2+1] returns y 6 | -- [17:18] <+slime> a basic test of a single table-of-1024-vectors saved 50% of the space by doing that 7 | 8 | --[[ 9 | My results (OS X with 64-bit LuaJIT 2.0.3): 10 | 11 | 2D array of table vectors: 64.05 MB 12 | 2D array of loose vector components: 32.05 MB 13 | linear array of table vectors: 64.00 MB 14 | linear array of loose vector components: 16.00 MB 15 | 2D array of struct double vectors: 32.05 MB 16 | 2D array of struct float vectors: 24.05 MB 17 | FFI linear array of struct double vectors: 31.69 MB 18 | FFI linear array of struct float vectors: 15.08 MB 19 | ]] 20 | 21 | local ffi = require("ffi") 22 | 23 | ffi.cdef[[ 24 | struct DoubleVector { double x, y; }; 25 | struct FloatVector { float x, y; }; 26 | ]] 27 | 28 | local newDoubleVector = ffi.typeof("struct DoubleVector") 29 | local newFloatVector = ffi.typeof("struct FloatVector") 30 | 31 | local WIDTH = 1024 32 | local HEIGHT = 1024 33 | 34 | local function test(name, func) 35 | collectgarbage("collect") 36 | collectgarbage("collect") 37 | 38 | local memcount = collectgarbage("count") 39 | func() 40 | local diff = collectgarbage("count") - memcount 41 | print(string.format("%s: %.2f MB", name, diff/1024)) 42 | 43 | collectgarbage("collect") 44 | end 45 | 46 | test("2D array of table vectors", function() 47 | local t = {} 48 | for y=1, HEIGHT do 49 | t[y] = {} 50 | for x=1, WIDTH do 51 | t[y][x] = {love.math.random(), love.math.random()} 52 | end 53 | end 54 | end) 55 | 56 | test("2D array of loose vector components", function() 57 | local t = {} 58 | for y=1, HEIGHT do 59 | t[y] = {} 60 | for x=1, WIDTH*2, 2 do 61 | t[y][x*2 + 0] = love.math.random() 62 | t[y][x*2 + 1] = love.math.random() 63 | end 64 | end 65 | end) 66 | 67 | test("linear array of table vectors", function() 68 | local t = {} 69 | for i=0, HEIGHT*WIDTH - 1 do 70 | t[i] = {love.math.random(), love.math.random()} 71 | end 72 | 73 | -- index using: vec = t[((y - 1) * WIDTH) + (x - 1)] 74 | end) 75 | 76 | 77 | test("linear array of loose vector components", function() 78 | local t = {} 79 | for i=0, HEIGHT*WIDTH*2 - 1, 2 do 80 | t[i+0] = love.math.random() 81 | t[i+1] = love.math.random() 82 | end 83 | 84 | -- index using: 85 | -- x_component = t[(((y - 1) * WIDTH) + (x - 1)) * 2 + 0] 86 | -- y_component = t[(((y - 1) * WIDTH) + (x - 1)) * 2 + 1] 87 | end) 88 | 89 | test("2D array of struct double vectors", function() 90 | local t = {} 91 | for y=1, HEIGHT do 92 | t[y] = {} 93 | for x=1, WIDTH do 94 | t[y][x] = newDoubleVector(love.math.random(), love.math.random()) 95 | end 96 | end 97 | end) 98 | 99 | test("2D array of struct float vectors", function() 100 | local t = {} 101 | for y=1, HEIGHT do 102 | t[y] = {} 103 | for x=1, WIDTH do 104 | t[y][x] = newFloatVector(love.math.random(), love.math.random()) 105 | end 106 | end 107 | end) 108 | 109 | test("FFI linear array of struct double vectors", function() 110 | local array = ffi.new("struct DoubleVector[?]", HEIGHT*WIDTH) 111 | for y=0, HEIGHT-1 do 112 | for x=0, WIDTH-1 do 113 | array[y*WIDTH + x].x = love.math.random() 114 | array[y*WIDTH + x].y = love.math.random() 115 | end 116 | end 117 | end) 118 | 119 | test("FFI linear array of struct float vectors", function() 120 | local array = ffi.new("struct FloatVector[?]", HEIGHT*WIDTH) 121 | for y=0, HEIGHT-1 do 122 | for x=0, WIDTH-1 do 123 | array[y*WIDTH + x].x = love.math.random() 124 | array[y*WIDTH + x].y = love.math.random() 125 | end 126 | end 127 | end) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # love-notes 2 | A repo brimming with information I see about love2d and lua. 3 | -------------------------------------------------------------------------------- /cool-repos.md: -------------------------------------------------------------------------------- 1 | # Cool Repos 2 | I love repos. You should, too! 3 | 4 | ## Other Master Lists 5 | * [awesome-lua](https://github.com/LewisJEllis/awesome-lua) contains tons of libraries, some not love specific. 6 | 7 | ## Templates 8 | * [love2d_gametemplate](https://github.com/SiENcE/love2d_gametemplate) -------------------------------------------------------------------------------- /external-tools.md: -------------------------------------------------------------------------------- 1 | # External Tools 2 | 3 | ## Animation 4 | * [shoebox](http://renderhjs.net/shoebox/) 5 | 6 | ## Texture Packing 7 | * [TexturePacker](https://www.codeandweb.com/texturepacker) 8 | * [Fudge](https://github.com/Bradshaw/Fudge) 9 | 10 | ## Map Editors 11 | * [RUBE](https://www.iforce2d.net/rube/) box2d physics maps. 12 | * [Tiled](http://www.mapeditor.org/) orthogonal and isometric editor. -------------------------------------------------------------------------------- /love2d-and-zerobrane.md: -------------------------------------------------------------------------------- 1 | # Love2D and ZeroBrane 2 | 3 | ## Getting output when you run from ZeroBrane 4 | Put this at the head of your `main.lua`, or before a particularly important print. 5 | ```lua 6 | io.stdout:setvbuf("no") 7 | ``` 8 | 9 | ### Note 10 | If you're using windows, love 0.9.2, and ZeroBrane Studio < 0.95 you might have issues doing the above. 11 | * Ensure `t.console = true` isn't in your `conf.lua`. 12 | * Don't use `love._openConsole()` in your code. 13 | 14 | ## Getting the debugger to work. 15 | You do not need this to get a console to open. 16 | Make sure the beginning of your `love.load()` looks like this: 17 | ```lua 18 | love.load(arg) 19 | if arg[#arg] == "-debug" then 20 | -- if your game is invoked with "-debug" (zerobrane does this by default) 21 | -- invoke the debugger 22 | require("mobdebug").start() 23 | end 24 | -- ... your code here ... 25 | end 26 | ``` 27 | If you ever need to delay your debugger or only invoke it at a given point, you can use: 28 | ``` 29 | local mobdebug = require("mobdebug") 30 | mobdebug.start() 31 | -- your code here 32 | mobdebug.stop() 33 | ``` 34 | [Read More](http://notebook.kulchenko.com/zerobrane/love2d-debugging) 35 | 36 | ## Live Updating 37 | Use `Ctrl+F6` to run your game in a way that allows you to modify variables on the fly. Might not work for complex games. -------------------------------------------------------------------------------- /luajit-debugger.md: -------------------------------------------------------------------------------- 1 | # Chat 2 | * [17:14] <~billiam> Asked yesterday, but what are the steps for using the luajit profiler in a love game? 3 | * [17:15] <+slime> replace luajit 2.0 with 2.1-alpha, and then http://repo.or.cz/w/luajit-2.0.git/blob_plain/refs/heads/v2.1:/doc/ext_profiler.html 4 | * [17:15] <+slime> (require("jit.p").start(options) instead of luajit -jp) 5 | * [17:16] <~billiam> slime: where 'replacing luajit' looks something like: https://love2d.org/wiki/Building_L%C3%96VE ? 6 | * [17:17] <+slime> well, you can just build luajit separately and then replace the library 7 | * [17:17] <+slime> depending on the OS 8 | * [17:17] <+slime> (without rebuilding all of love) 9 | * [17:17] <+slime> replacing luajit would be http://repo.or.cz/w/luajit-2.0.git/blob_plain/refs/heads/v2.1:/doc/install.html 10 | * [17:18] <+slime> (after getting the latest 2.1-alpha source from the git repository) 11 | * [17:18] <+slime> MiuStar: love uses luajit 2.0, but the luajit profiler is only available in luajit 2.1-alpha 12 | * [17:19] <~billiam> Thanks, I'll give that a shot. I don't have a lot of faith in my ability to successfully build under windows. I don't suppose there are any love builds floating around with 2.1a? 13 | 14 | # Code 15 | ```lua 16 | require("jit.p").start(options) 17 | ``` 18 | -------------------------------------------------------------------------------- /scratch.md: -------------------------------------------------------------------------------- 1 | # Scratch 2 | I don't know what's happening so I'm just gonna put stuff here. 3 | 4 | ## Speed up your mapPixel functions with FFI 5 | You should probably use a shader for this. 6 | * [link](https://github.com/slime73/love-snippets/blob/master/ImageData-FFI/imagedata-ffi.lua) 7 | 8 | ## sapper's grayscale shader colorizer 9 | ```lua 10 | pDraw = love.graphics.newShader([[ 11 | extern Image pal; 12 | extern number size; 13 | vec4 effect(vec4 c,Image tex,vec2 tx,vec2 pc){ 14 | vec4 cr = Texel(tex,tx); 15 | vec4 r = Texel(pal,vec2(cr.r+(.5 / size),.5)); 16 | return vec4(r.r,r.g,r.b,cr.a); 17 | } 18 | ]]) 19 | ``` 20 | 21 | ```lua 22 | function palConvert(image,palette) 23 | local img,pal = image:getData(),palette:getData() 24 | img:mapPixel(function(x,y,r,g,b,a) 25 | local wid = pal:getWidth() 26 | for i=1,wid do 27 | local pix = {pal:getPixel(i-1,0)} 28 | if tEqual(pix,{r,g,b,a}) then 29 | local n = math.max(((i-1) * wid)-1,0) 30 | return n,n,n,255 31 | end 32 | end 33 | return 0,0,0,0 34 | end) 35 | return love.graphics.newImage(img) 36 | end 37 | ``` 38 | 39 | ## A Palette Shader 40 | * [link](http://kpulv.com/368/Index_Palette_Shader/) 41 | 42 | ## Simple Conway Implementations 43 | * [link](https://love2d.org/forums/viewtopic.php?f=5&t=40669) 44 | 45 | ## Rectangular Decomposition 46 | Turn a bunch of rectangles into smaller rectangles. 47 | * [node.js implementation](https://github.com/mikolalysenko/rectangle-decomposition) 48 | * [lua implementation](https://love2d.org/forums/viewtopic.php?p=179044#p179044) -------------------------------------------------------------------------------- /smaller_rectangles.lua: -------------------------------------------------------------------------------- 1 | -- from: https://love2d.org/forums/viewtopic.php?p=179044#p179044 2 | for a = 1, #boxSizeList do 3 | local bw, bh = boxSizeList[a][1], boxSizeList[a][2] 4 | local count = bw * bh 5 | for x = 0, #tempColMap-bw+1 do 6 | for y = 0, #tempColMap[1]-bh+1 do 7 | local _count = 0 8 | for bx = x, x + (bw-1) do 9 | for by = y, y + (bh-1) do 10 | if not markedGrid[bx][by] then 11 | if tempColMap[bx][by] == currentTileType then 12 | _count = _count + 1 13 | end 14 | end 15 | end 16 | end 17 | if _count == count then 18 | local n = "solidWall_" .. x+1 .. "_" .. y+1 19 | local wallType = currentTileType 20 | 21 | -- Add the newly created collision box to a table that will later be used to generate the Bump collision blocks 22 | self.level.boxList[n] = { x = x * TILESIZE, y = y * TILESIZE, w = bw * TILESIZE, h = bh * TILESIZE, id = n, solid = true } 23 | 24 | for bx = x, x + (bw-1) do 25 | for by = y, y + (bh-1) do 26 | markedGrid[bx][by] = true 27 | end 28 | end 29 | end 30 | end 31 | end 32 | end --------------------------------------------------------------------------------