Skip to content

Instantly share code, notes, and snippets.

View wolf81's full-sized avatar
🎯
Focusing

Wolfgang Schreurs wolf81

🎯
Focusing
View GitHub Profile
@wolf81
wolf81 / buffer.lua
Created May 8, 2021 14:48
Simple (jitter) buffer
local buffer = Class {}
function buffer:init(size, sort)
assert(size ~= nil, "a size is required to create a buffer")
self._size = math.max(size or DEFAULT_BUFFER_SIZE, 1)
self._items = {}
self._sort = sort or function(left, right) return true end
end
@wolf81
wolf81 / game.lua
Last active May 8, 2021 15:10
fixed timestep, state interpolation, client-side prediction, apply player input without lag
local game = Class {}
-- the index of the current player, which is always 1, regardless of how many clients are in array
local CURRENT_CLIENT_INDEX = 1
local TICK_RATE = 1/60
local function exitTo(game, nextState) --[[ exit to other scenes ]] end
function game:init()
@wolf81
wolf81 / connect.lua
Last active May 8, 2021 14:51
local client / server for singleplayer; use only client when joining a game, use server with 2 clients for hosting a game
local connect = Class { __includes = Scene }
function connect:init()
Scene.init(self, "CONNECT", textures['background-menu'])
end
function connect:enter(previous, gameMode, host, port)
self.gameMode = gameMode
self.clients = {}
@wolf81
wolf81 / Peer.lua
Created April 26, 2021 19:18
Class to make integrating sock.lua into a Lgame even easier
local sock = require '../lib/sock/sock'
local bitser = require '../lib/bitser/bitser'
PEER_MODE_CLIENT = 'client'
PEER_MODE_SERVER = 'server'
local peer = Class {}
function peer:init(host, port, mode)
self.host = host or NET_DEFAULT_HOST
@wolf81
wolf81 / script-template.sh
Created December 15, 2020 13:02 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
trap cleanup SIGINT SIGTERM ERR EXIT
usage() {
cat <<EOF
# turn off special handling of ._* files in tar, etc.
export COPYFILE_DISABLE=1;
@wolf81
wolf81 / .bash_profile
Last active March 9, 2020 01:36
My macOS .bash_profile
# Read .bashrc file if it exists
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
# Add syntax coloring for less, relies on the source-highlight homebrew formula
LESSPIPE=`which src-hilite-lesspipe.sh`
export LESSOPEN="| ${LESSPIPE} %s"
export LESS=' -R -X -F '
# Include system wide settings which are ignored
# by default if one has their own .inputrc
$include /etc/inputrc
# do not make noise. Also visible can cause delays.
set bell-style none
# make bash auto–complete case insensitive
set completion-ignore-case on