forked from pyrex/chameleonic
Assorted micro-optimizations. (#3)
Some of these are pure token optimizations, some spend tokens for performance. Function calls are particularly expensive in Pico-8, so using the table form of `pal` whenever changing multiple colors seems worth it. Also fixes a bug in palette swapping. Reviewed-on: pyrex/chameleonic#3 Co-authored-by: Kistaro Windrider <kistaro@gmail.com> Co-committed-by: Kistaro Windrider <kistaro@gmail.com>
This commit is contained in:
parent
823b3edc30
commit
db157b7952
@ -101,19 +101,13 @@ function _apply(x,ts,a)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function sgn0(x)
|
function sgn0(x)
|
||||||
if (x==0) return x
|
if (x==0) return x
|
||||||
return sgn(x)
|
return sgn(x)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _mnmx(x,y)
|
function _mnmx(x,y)
|
||||||
return min(x,y),max(x,y)
|
if (x>y)return y,x
|
||||||
end
|
return x,y
|
||||||
-->8
|
|
||||||
bg={}
|
|
||||||
add(modules,bg)
|
|
||||||
|
|
||||||
function bg:draw0()
|
|
||||||
cls(0)
|
|
||||||
end
|
end
|
||||||
-->8
|
-->8
|
||||||
level={}
|
level={}
|
||||||
@ -143,6 +137,7 @@ function level:advance()
|
|||||||
self:reinit(self.ix+1)
|
self:reinit(self.ix+1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pitpal = {[0]=1, [7]=0}
|
||||||
function level:draw()
|
function level:draw()
|
||||||
cls(1)
|
cls(1)
|
||||||
pal(1,0)
|
pal(1,0)
|
||||||
@ -154,11 +149,11 @@ function level:draw()
|
|||||||
for _,pit in pairs(self._pits) do
|
for _,pit in pairs(self._pits) do
|
||||||
spr(pit.s,pit.px,pit.py)
|
spr(pit.s,pit.px,pit.py)
|
||||||
if pit.contents then
|
if pit.contents then
|
||||||
pal(7,0)
|
pal(pitpal)
|
||||||
pal(0,1)
|
|
||||||
palt(0,false)
|
palt(0,false)
|
||||||
spr(pit.contents,pit.px,pit.py)
|
spr(pit.contents,pit.px,pit.py)
|
||||||
pal()
|
pal()
|
||||||
|
pal(1,0)
|
||||||
end
|
end
|
||||||
for _,crate in pairs(self._crates) do
|
for _,crate in pairs(self._crates) do
|
||||||
spr(crate.s,crate.px,crate.py)
|
spr(crate.s,crate.px,crate.py)
|
||||||
@ -183,7 +178,7 @@ function level:update()
|
|||||||
|
|
||||||
if #crate.todo==0 then
|
if #crate.todo==0 then
|
||||||
local pit=self._pits[_mix(crate.mx,crate.my)]
|
local pit=self._pits[_mix(crate.mx,crate.my)]
|
||||||
if pit!=nil and pit.contents==nil then
|
if pit and not pit.contents then
|
||||||
add(remove,cix)
|
add(remove,cix)
|
||||||
crate.dead=true
|
crate.dead=true
|
||||||
pit.contents=crate.s
|
pit.contents=crate.s
|
||||||
@ -209,7 +204,7 @@ function level:load_dynobjs()
|
|||||||
local px,py=mx*8,my*8
|
local px,py=mx*8,my*8
|
||||||
local s=self:_mget(mx,my)
|
local s=self:_mget(mx,my)
|
||||||
local def=self:_get_cratedef(s)
|
local def=self:_get_cratedef(s)
|
||||||
if def!=nil then
|
if def then
|
||||||
self._crates[mxy]={
|
self._crates[mxy]={
|
||||||
s=s,def=def,
|
s=s,def=def,
|
||||||
mx=mx,my=my,
|
mx=mx,my=my,
|
||||||
@ -232,8 +227,8 @@ end
|
|||||||
|
|
||||||
function level:recollide()
|
function level:recollide()
|
||||||
self._coll={}
|
self._coll={}
|
||||||
for mx=0,15,1 do
|
for mx=0,15 do
|
||||||
for my=0,15,1 do
|
for my=0,15 do
|
||||||
local mxy=_mix(mx,my)
|
local mxy=_mix(mx,my)
|
||||||
self._coll[mxy]=
|
self._coll[mxy]=
|
||||||
fget(self:_mget(mx,my),7) or
|
fget(self:_mget(mx,my),7) or
|
||||||
@ -243,16 +238,16 @@ function level:recollide()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function level:reanchor(remove)
|
function level:reanchor(remove)
|
||||||
if remove or self._anch==nil then
|
if remove or not self._anch then
|
||||||
self._anch={}
|
self._anch={}
|
||||||
end
|
end
|
||||||
|
|
||||||
for ax0=0,31,1 do
|
for ax0=0,31 do
|
||||||
for ay0=0,31,1 do
|
local ax1 = ax0-1+2*(ax0%2)
|
||||||
local ax1,ay1=ax0-1+2*(ax0%2),ay0-1+2*(ay0%2)
|
local mx0,mx1 = ax0\2,ax1\2
|
||||||
|
for ay0=0,31 do
|
||||||
local mx0,my0=ax0\2,ay0\2
|
local ay1=ay0-1+2*(ay0%2)
|
||||||
local mx1,my1=ax1\2,ay1\2
|
local my0,my1=ay0\2,ay1\2
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not self:mcoll(mx0,my0) and
|
not self:mcoll(mx0,my0) and
|
||||||
|
Loading…
Reference in New Issue
Block a user