Skip to content

Instantly share code, notes, and snippets.

View pcornier's full-sized avatar

Pierco pcornier

View GitHub Profile
@pcornier
pcornier / install.md
Last active December 6, 2021 16:33
Verilator on Termux
curl -fsSL https://its-pointless.github.io/setup-pointless-repo.sh | bash -
apt install git clang binutils make autoconf flex bison python3
git clone http://git.veripool.org/git/verilator
cd verilator
autoconf
./configure --prefix=${PREFIX}
make
make install
if [ -f main.lua ]; then
DATA=`grep -zoP "(?s)(-- <TILES>.+)" main.lua`
rm main.lua
fi
cat src/_meta.lua > main.lua
find src/libs/ -name '*.lua' -exec cat {} \; >> main.lua
find src/objs/ -name '*.lua' -exec cat {} \; >> main.lua
cat src/main.lua >> main.lua
echo "\n$DATA" >> main.lua
@pcornier
pcornier / FlowVF.lua
Created May 8, 2018 09:24
A not very optimized vector field path finding
local FlowVF = {}
-- getWeight: callback (x, y) and should return a weight between 0 and 1
-- setvector: callback (x, y, angle) called on each cell
-- the function returns the weight table
function FlowVF:createVectors(px, py, w, h, getWeight, setVector)
local neighbors = {{0, -1}, {-1, 0}, {1, 0}, {0, 1}}
local done = {}
@pcornier
pcornier / colors.lua
Last active May 4, 2018 06:11
Love2d v11 color compatibility adapter
local major, minor, revision, codename = love.getVersion()
local color = love.graphics.setColor
love.graphics.setColor = function(r, g, b, a)
if type(r) == 'table' then r, g, b, a = unpack(r) end
a = a or 1
if r <= 1 and g <= 1 and b <= 1 and a <= 1 then
if major >= 11 then
color(r, g, b, a)
@pcornier
pcornier / goap.js
Last active April 27, 2018 18:59
GOAP
const Action = (...args) => {
[name, effects = {}, conditions = {}, weight = 1] = args
return { name, effects, conditions, weight }
}
const Planner = (...args) => {
let actions = args
@pcornier
pcornier / nodes.js
Last active April 8, 2020 15:37
very basic Node tree system
const Node = function(...nodes) {
let children = nodes
let node = {
addChild: n => children.push(n),
register: (name, callback) => {
this[name] = callback
return node
},
call: (name, ...args) => {
@pcornier
pcornier / ecs.js
Last active December 3, 2018 08:31
very minimal ECS (static)
const World = function() {
let entities = []
let systems = []
return {
addEntity: function(e) {
entities.push(e)
systems.forEach(s => {
if (s.require.every(p => p in e)) s.entities.push(e)
})
},
@pcornier
pcornier / love&droidEdit.txt
Last active November 12, 2022 10:27
External command for DroidEdit that runs a project w/ Löve. Termux & Löve2D are required.
- project directory in /storage/emulated/0/Download/projects/...
- sshd is running in termux and storage mounted
- files are edited with DroidEdit through ssh: ~/storage/downloads/projects/...
- external Löve command:
cd ${path} && zip -r test.love * -x test.love && am start -t org.love2d.android -a android.intent.action.VIEW -d "file://${path}/test.love"
@pcornier
pcornier / test.js
Last active February 7, 2018 13:56
running ordered async tests
tests = []
running = false
done = function() {
test = tests.shift()
if (test) test(done)
}
const it = function(name, test) {
tests.push(test)
@pcornier
pcornier / package.json
Last active November 9, 2018 11:39
JS Static Typing with Flow and Webpack
{
"name": "test",
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"flow-bin": "^0.86.0",
"flow-webpack-plugin": "^1.2.0",
"remove-flow-types-loader": "^1.1.0",
"webpack": "^4.25.1",
"webpack-cli": "^2.1.4"