Skip to content

Instantly share code, notes, and snippets.

View EngineerSmith's full-sized avatar
🔧
🦆

Engineer Smith EngineerSmith

🔧
🦆
View GitHub Profile
@EngineerSmith
EngineerSmith / anchor.lua
Last active April 12, 2020 19:31
Script used to reposition GUI elements when window resizes
local floor = math.floor
local point = {
Center = 0,
North = 1,
NorthWest = 2,
West = 3,
SouthWest = 4,
South = 5,
SouthEast = 6,
@EngineerSmith
EngineerSmith / train.lua
Last active January 2, 2020 21:54
Simple scrolling "mountain range" for Löve2d
local train = {}
train.__index = train
local lg, lm = love.graphics, love.math
local MAXY = 1000
-- We use the previous value so that it doesn't get too crazy looking
-- Will need better generation which min and max so it doesn't go up or down forever
local function generateValue(previous) return (lm.random(20)-10)*2+previous*0.25 end
@EngineerSmith
EngineerSmith / main.lua
Last active January 30, 2020 21:32
Love2d, drawing an animated line
local lg = love.graphics
local floor = math.floor
local insert = table.insert
local image = lg.newImage("Line.png") --I used a 64x64 image to test
image:setWrap("repeat","repeat")
local iw, ih = image:getDimensions()
--Options
local frames = 20 -- Frames per line section
local appleCake = require("AppleCake")(true) -- False will disable AppleCake for your project
appleCake.setBuffer(true) -- Buffer data, and only send it to be saved when appleCake.flush is called
appleCake.beginSession()
appleCake.mark("Begin") -- Add markers for timeless events
local r = 0
function love.update(dt)
local profileUpdate = appleCake.profileFunc({radian=r}) -- Auto-generates a name for the function, "update@main.lua#6", and records the arguments
r = r + 0.5 * dt
profileUpdate:stop()
[{"cat":"mark","name":"Begin","ph":"i","pid":0,"tid":1074326280,"s":"p","ts":38635820939.5},{"cat":"function","dur":2.3000030517578,"name":"update@main.lua#6","ph":"X","pid":0,"tid":1074326280,"ts":38635828316.2,"args":{"radian":0}},{"cat":"function","dur":108.59999847412,"name":"Draw","ph":"X","pid":0,"tid":1074326280,"ts":38635857022,"args":{"canvases":0,"images":0,"drawcalls":1,"drawcallsbatched":0,"fonts":0,"canvasswitches":0,"shaderswitches":7,"texturememory":0}},{"cat":"function","dur":2.0999908447266,"name":"update@main.lua#6","ph":"X","pid":0,"tid":1074326280,"ts":38635941464.7,"args":{"radian":0.0036259999978938}},{"cat":"function","dur":26.5,"name":"Draw","ph":"X","pid":0,"tid":1074326280,"ts":38635944332.1,"args":{"canvases":0,"images":0,"drawcalls":1,"drawcallsbatched":0,"fonts":0,"canvasswitches":0,"shaderswitches":0,"texturememory":0}},{"cat":"function","dur":2.2999954223633,"name":"update@main.lua#6","ph":"X","pid":0,"tid":1074326280,"ts":38635952094.9,"args":{"radian":0.060212149997824}},{"cat
/*!
* Bootstrap v4.3.1 (https://getbootstrap.com/)
* Copyright 2011-2019 The Bootstrap Authors
* Copyright 2011-2019 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/:root{--blue: #007bff;--indigo: #6610f2;--purple: #6f42c1;--pink: #e83e8c;--red: #dc3545;--orange: #fd7e14;--yellow: #ffc107;--green: #28a745;--teal: #20c997;--cyan: #17a2b8;--white: #fff;--gray: #adb4c0;--gray-dark: #747f94;--primary: #28b76b;--secondary: #5d6778;--success: #5cb377;--info: #5b99ea;--warning: #EEBF41;--danger: #d26d69;--light: #fff;--dark: #747f94;--breakpoint-xs: 0;--breakpoint-sm: 576px;--breakpoint-md: 768px;--breakpoint-lg: 992px;--breakpoint-xl: 1200px;--font-family-sans-serif: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-family-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace}*,*::before,
local appleCake = require("AppleCake")() -- Will be disabled if the main thread set AppleCake to false
-- Note we don't set buffering so everything is pushed to the save thread as soon as it can be
local function foo() -- "foo@TestThread.lua#3"
local profile = appleCake.profileFunc()
local n = 0
for i=0, 100000 do
n = n + i
end
profile:stop()
appleCake.beginSession() -- Default "profile.json" in the save direcotry
appleCake.beginSession("profile.json")
appleCake.beginSession("/profiles/profile.json")
appleCake.beginSession(nil, "Best Project")
appleCake.beginSession("profile.json", "Game4000")
if love.filesystem.isFused() then
local dir = love.filesystem.getSourceBaseDirectory()
love.filesystem.mount(dir, "gameSource")
appleCake.endSession()
function love.quit()
appleCake.endSession()
end
local _profile = appleCake.profile("love.update")
local function bar()
local _profileBar = appleCake.profile("bar", {}) -- Initalizing args to an empty table as it's nil by default
--...
local _profileBarSet = appleCake.profile("bar set") -- Example of nested profiling
_profileBar.args.value = 12
_profileBarSet:stop() -- This could stop after _profileBar:stop() if you wanted
--...
_profileBar:stop()