Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Attempts to minimize bytes, some token golf as well #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sparr
Copy link

@sparr sparr commented Feb 17, 2020

This PR is a work in progress. I have not been able to fully test all of the changes yet, as I haven't re-explored the whole story. I will do so, but wanted to submit this for feedback beforehand.

before (minified): 6475 tokens, 32610 chars, 99.38% compressed
after (minified): 6350 tokens, 30032 chars, 97% compressed

The biggest savings came from altering the "JSON" syntax to not require quotes around most strings. This makes them harder to edit in other json-aware programs, but still pretty much entirely human readable and hand-editable.

Other savings came from inlining functions and typical token golf optimizations. I suspect there's another 50 tokens, 500 chars, and 1% compressed size to be saved through further more complicated efforts of this sort. I'd be happy to attempt more in that direction if you're interested.

I will comment a few places in the PR that stand out as notable and possibly objectionable, some of which are aesthetic in nature.

If these changes are welcome here, I would also be happy to port the relevant ones over to Minima.

@@ -784,7 +757,7 @@ function deductfood(amount)
end

function not_over_32767(num)
return min(num,32767)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem effective

Comment on lines 1168 to 1172
function delay(numofcycles)
for delaycount=0,numofcycles do
for delaycount=1,numofcycles do
flip()
end
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it intentional that the previous code would wait two frames for numofcycles==1, three frames for 2, etc?

Comment on lines +1190 to +1215
function print_r(str, x, ...)
print(str, x - 4 * #tostr(str), ...)
end

function draw_stats()
local linestart,midlinestart,longlinestart=106,110,119
local linestart,lineend=106,127
print("cond",linestart,0,5)
print(band(hero.st,1)==1 and 'p' or 'g',125,0,6)
print_r(band(hero.st,1)==1 and 'p' or 'g',lineend,0,6)
print("lvl",linestart,8,5)
print(hero.lvl,longlinestart,8,6)
print_r(hero. lvl,lineend,8,6)
print("hp",linestart,16,5)
print(hero.hp,linestart+8,16,6)
print_r(hero.hp,lineend,16,6)
print("ap",linestart,24,5)
print(hero.mp,linestart+8,24,6)
print_r(hero.mp,lineend,24,6)
print("$",linestart,32,5)
print(hero.gp,midlinestart,32,6)
print_r(hero.gp,lineend,32,6)
print("f",linestart,40,5)
print(hero.fd,midlinestart,40,6)
print_r(hero.fd,lineend,40,6)
print("exp",linestart,48,5)
print(hero.exp,linestart,55,6)
print_r(hero.exp,lineend,55,6)
print("dex",linestart,63,5)
print(hero.dex,longlinestart,63,6)
print_r(hero.dex,lineend,63,6)
print("int",linestart,71,5)
print(hero.int,longlinestart,71,6)
print_r(hero.int,lineend,71,6)
print("str",linestart,79,5)
print(hero.str,longlinestart,79,6)
print_r(hero.str,lineend,79,6)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a functional change, both aesthetic and code-simplifying. I can easily undo the right aligning and approach the code reduction here another way.

for linenum=1,numoflines do
print(lines[(curline-linenum)%numoflines+1],0,128-linenum*8)
print(lines[(curline-linenum)%numoflines+1],0,129-linenum*8)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is purely an aesthetic change, moving the always-blank row from the bottom of the screen to the top of the lines output, so there will be a gap between the map and the lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant