Skip to content

Instantly share code, notes, and snippets.

@falconscript
Created May 10, 2018 16:20
Show Gist options
  • Select an option

  • Save falconscript/2e560ab86428948b1cb558c2f80b218c to your computer and use it in GitHub Desktop.

Select an option

Save falconscript/2e560ab86428948b1cb558c2f80b218c to your computer and use it in GitHub Desktop.
Reduce lag by running just before playing melee. Script turns off screen scaling to reduce GPU usage
#!/bin/bash
echo '
### ###
##### Melee screen resolution optimizer ##### falconscript
### ###
'
## How to use:
# Run each time just before you play melee
## What it does:
# Turns off retina screen interpolation/scaling (easily undo in System Preferences)
## Why that's good:
# Reduces the weird spikes/lag on mac by reducing GPU/CPU peaks
# If you're a mac user you know what I'm talking about. Retina macs have weird spikes man
# fix working dir to dir of script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIR"
# Download resolution changing tool if needed
if ! [ -e "./screen-resolution-switcher" ]; then
echo "[+] Downloading screen resolution switcher tool..."
git clone https://github.com/th507/screen-resolution-switcher.git > /dev/null 2>&1
cd screen-resolution-switcher
if ! [ -z "`which make`" ]; then
make > /dev/null 2>&1 # compile faster version if we can have it
fi
cd ..
fi
cd screen-resolution-switcher
# determine if we can use faster tool
if [ -e "./retina" ]; then
tool="./retina"
else
tool="./scres.swift"
fi
# Get current resolution width (used as ID for tool)
curWidth=$( "$tool" -l 0 | egrep -Eo "\d{2,}\ \*" | sed 's# \*##g' )
allWidths=$( "$tool" -m | egrep -Eo "\d{2,}\ \*" | sed 's# \*##g' | tr "\n" ',' )
# also swap newlines for commas ^
closestMatch () {
# $1 is needle and $2 is haystack
echo "$2" | awk -v "VAL=$1" -v RS="," '{
D=(VAL - $1) * (VAL - $1);
if((!SET) || (D < DIFF)) {
DIFF=D;
X=$1;
SET=1;
}
}
END { printf("%s", X); }'
}
# Always get the closest width to 1024 instead - optimizes rendered pixels
#targetRes=`closestMatch $curWidth "$allWidths"`
targetRes=`closestMatch 1024 "$allWidths"`
echo "[+] Setting display width to $targetRes"
# Change display to NON-SCALED version of this lower resolution
"$tool" set $targetRes
# no idea how to to change back via command line with scaling
# just use System Preferences -> Display and click the one you like
echo "[+] READY FOR MELEE. To revert resolution, Go to System Preferences -> Display"
echo "[+] You may close this window."
echo
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment