Optimisation of tilemap

This commit is contained in:
Maruno17
2021-01-14 20:11:25 +00:00
parent 386396cdf6
commit 9364a543e7

View File

@@ -112,9 +112,9 @@ class CustomTilemap
@flash = nil @flash = nil
@oxFlash = 0 @oxFlash = 0
@oyFlash = 0 @oyFlash = 0
@priotiles = [] @priotiles = {}
@priotilesfast = [] @priotilesfast = []
@prioautotiles = [] @prioautotiles = {}
@autosprites = [] @autosprites = []
@framecount = [0,0,0,0,0,0,0,0] # For autotiles @framecount = [0,0,0,0,0,0,0,0] # For autotiles
@tilesetChanged = true @tilesetChanged = true
@@ -376,7 +376,7 @@ class CustomTilemap
def addTile(tiles,count,xpos,ypos,id) def addTile(tiles,count,xpos,ypos,id)
terrain = @terrain_tags[id] terrain = @terrain_tags[id]
priority = @priorities[id] priority = @priorities[id]
if id>=384 if id >= 384 # Tileset tile
if count>=tiles.length if count>=tiles.length
sprite = CustomTilemapSprite.new(@viewport) sprite = CustomTilemapSprite.new(@viewport)
tiles.push(sprite,0) tiles.push(sprite,0)
@@ -390,7 +390,7 @@ class CustomTilemap
sprite.tone = @tone sprite.tone = @tone
sprite.color = @color sprite.color = @color
getRegularTile(sprite,id) getRegularTile(sprite,id)
else else # Autotile
if count>=tiles.length if count>=tiles.length
sprite = CustomTilemapSprite.new(@viewport) sprite = CustomTilemapSprite.new(@viewport)
tiles.push(sprite,1) tiles.push(sprite,1)
@@ -491,8 +491,9 @@ class CustomTilemap
end end
def refresh_tileset def refresh_tileset
i = 0; len = @regularTileInfo.length i = 0
while i<len len = @regularTileInfo.length
while i < len
if @regularTileInfo[i] if @regularTileInfo[i]
@regularTileInfo[i].dispose @regularTileInfo[i].dispose
@regularTileInfo[i] = nil @regularTileInfo[i] = nil
@@ -504,16 +505,17 @@ class CustomTilemap
ysize = @map_data.ysize ysize = @map_data.ysize
xsize = @map_data.xsize xsize = @map_data.xsize
zsize = @map_data.zsize zsize = @map_data.zsize
if xsize>100 || ysize>100 if xsize > 100 || ysize > 100
@fullyrefreshed = false @fullyrefreshed = false
else else
for z in 0...zsize for z in 0...zsize
for y in 0...ysize for y in 0...ysize
for x in 0...xsize for x in 0...xsize
id = @map_data[x, y, z] id = @map_data[x, y, z]
next if id==0 next if id == 0
next if @priorities[id]==0 && !PBTerrain.hasReflections?(@terrain_tags[id]) next if @priorities[id] == 0 && !PBTerrain.hasReflections?(@terrain_tags[id])
@priotiles.push([x,y,z,id]) @priotiles[[x, y]] = [] if !@priotiles[[x, y]]
@priotiles[[x, y]].push([z, id])
end end
end end
end end
@@ -522,16 +524,18 @@ class CustomTilemap
end end
def refresh_autotiles def refresh_autotiles
i = 0; len = @autotileInfo.length i = 0
while i<len len = @autotileInfo.length
while i < len
if @autotileInfo[i] if @autotileInfo[i]
@autotileInfo[i].dispose @autotileInfo[i].dispose
@autotileInfo[i] = nil @autotileInfo[i] = nil
end end
i += 1 i += 1
end end
i = 0; len = @autosprites.length i = 0
while i<len len = @autosprites.length
while i < len
if @autosprites[i] if @autosprites[i]
@autosprites[i].dispose @autosprites[i].dispose
@autosprites[i] = nil @autosprites[i] = nil
@@ -545,29 +549,27 @@ class CustomTilemap
@priorectautos = nil @priorectautos = nil
hasanimated = false hasanimated = false
for i in 0...7 for i in 0...7
numframes = autotileNumFrames(48*(i+1)) numframes = autotileNumFrames(48 * (i + 1))
hasanimated = true if numframes>=2 hasanimated = true if numframes >= 2
@framecount[i] = numframes @framecount[i] = numframes
end end
if hasanimated if hasanimated
ysize = @map_data.ysize ysize = @map_data.ysize
xsize = @map_data.xsize xsize = @map_data.xsize
zsize = @map_data.zsize zsize = @map_data.zsize
if xsize>100 || ysize>100 if xsize > 100 || ysize > 100
@fullyrefreshedautos = false @fullyrefreshedautos = false
else else
for y in 0...ysize for y in 0...ysize
for x in 0...xsize for x in 0...xsize
haveautotile = false
for z in 0...zsize for z in 0...zsize
id = @map_data[x, y, z] id = @map_data[x, y, z]
next if id==0 || id>=384 next if id == 0 || id >= 384 # Skip non-autotiles
next if @priorities[id]!=0 || PBTerrain.hasReflections?(@terrain_tags[id]) next if @priorities[id] != 0 || PBTerrain.hasReflections?(@terrain_tags[id])
next if @framecount[id/48-1]<2 next if @framecount[id / 48 - 1] < 2
haveautotile = true @prioautotiles[[x, y]] = true
break break
end end
@prioautotiles.push([x,y]) if haveautotile
end end
end end
@fullyrefreshedautos = true @fullyrefreshedautos = true
@@ -577,22 +579,21 @@ class CustomTilemap
end end
end end
def refreshLayer0(autotiles=false) def refreshLayer0(autotiles = false)
return true if autotiles && !shown? return true if autotiles && !shown?
ptX = @ox-@oxLayer0 ptX = @ox - @oxLayer0
ptY = @oy-@oyLayer0 ptY = @oy - @oyLayer0
if !autotiles && !@firsttime && !@usedsprites && if !autotiles && !@firsttime && !@usedsprites &&
ptX>=0 && ptX+@viewport.rect.width<=@layer0.bitmap.width && ptX >= 0 && ptX + @viewport.rect.width <= @layer0.bitmap.width &&
ptY>=0 && ptY+@viewport.rect.height<=@layer0.bitmap.height ptY >= 0 && ptY + @viewport.rect.height <= @layer0.bitmap.height
if @layer0clip && @viewport.ox==0 && @viewport.oy==0 if @layer0clip && @viewport.ox == 0 && @viewport.oy == 0
@layer0.ox = 0 @layer0.ox = 0
@layer0.oy = 0 @layer0.oy = 0
@layer0.src_rect.set(ptX.round,ptY.round, @layer0.src_rect.set(ptX.round, ptY.round, @viewport.rect.width, @viewport.rect.height)
@viewport.rect.width,@viewport.rect.height)
else else
@layer0.ox = ptX.round @layer0.ox = ptX.round
@layer0.oy = ptY.round @layer0.oy = ptY.round
@layer0.src_rect.set(0,0,@layer0.bitmap.width,@layer0.bitmap.height) @layer0.src_rect.set(0, 0, @layer0.bitmap.width, @layer0.bitmap.height)
end end
return true return true
end end
@@ -606,74 +607,70 @@ class CustomTilemap
theight = @tileHeight theight = @tileHeight
mapdata = @map_data mapdata = @map_data
if autotiles if autotiles
return true if @fullyrefreshedautos && @prioautotiles.length==0 return true if @fullyrefreshedautos && @prioautotiles.length == 0
xStart = @oxLayer0/twidth xStart = @oxLayer0 / twidth
xStart = 0 if xStart<0 xStart = 0 if xStart < 0
yStart = @oyLayer0/theight yStart = @oyLayer0 / theight
yStart = 0 if yStart<0 yStart = 0 if yStart < 0
xEnd = xStart+(width/twidth)+1 xEnd = xStart + (width / twidth) + 1
yEnd = yStart+(height/theight)+1 xEnd = xsize if xEnd > xsize
xEnd = xsize if xEnd>xsize yEnd = yStart + (height / theight) + 1
yEnd = ysize if yEnd>ysize yEnd = ysize if yEnd > ysize
return true if xStart>=xEnd || yStart>=yEnd return true if xStart >= xEnd || yStart >= yEnd
trans = Color.new(0,0,0,0) trans = Color.new(0, 0, 0, 0)
temprect = Rect.new(0,0,0,0) temprect = Rect.new(0, 0, 0, 0)
tilerect = Rect.new(0,0,twidth,theight) tilerect = Rect.new(0, 0, twidth, theight)
zrange = 0...zsize zrange = 0...zsize
overallcount = 0 overallcount = 0
count = 0 count = 0
if !@fullyrefreshedautos if !@fullyrefreshedautos
for y in yStart..yEnd for y in yStart..yEnd
for x in xStart..xEnd for x in xStart..xEnd
haveautotile = false
for z in zrange for z in zrange
id = mapdata[x, y, z] id = mapdata[x, y, z]
next if !id || id<48 || id>=384 next if !id || id < 48 || id >= 384 # Skip non-autotiles
prioid = @priorities[id] prioid = @priorities[id]
next if prioid!=0 || PBTerrain.hasReflections?(@terrain_tags[id]) next if prioid != 0 || PBTerrain.hasReflections?(@terrain_tags[id])
fcount = @framecount[id/48-1] fcount = @framecount[id / 48 - 1]
next if !fcount || fcount<2 next if !fcount || fcount < 2
if !haveautotile overallcount += 1
haveautotile = true xpos = (x * twidth) - @oxLayer0
overallcount += 1 ypos = (y * theight) - @oyLayer0
xpos = (x*twidth)-@oxLayer0 bitmap.fill_rect(xpos, ypos, twidth, theight, trans) if overallcount <= 2000
ypos = (y*theight)-@oyLayer0 break
bitmap.fill_rect(xpos,ypos,twidth,theight,trans) if overallcount<=2000
break
end
end end
for z in zrange for z in zrange
id = mapdata[x,y,z] id = mapdata[x, y, z]
next if !id || id<48 next if !id || id < 48
prioid = @priorities[id] prioid = @priorities[id]
next if prioid!=0 || PBTerrain.hasReflections?(@terrain_tags[id]) next if prioid != 0 || PBTerrain.hasReflections?(@terrain_tags[id])
if overallcount>2000 if overallcount > 2000
xpos = (x*twidth)-@oxLayer0 xpos = (x * twidth) - @oxLayer0
ypos = (y*theight)-@oyLayer0 ypos = (y * theight) - @oyLayer0
count = addTile(@autosprites,count,xpos,ypos,id) count = addTile(@autosprites, count, xpos, ypos, id)
next elsif id >= 384 # Tileset tiles
elsif id>=384 temprect.set(((id - 384) & 7) * @tileSrcWidth,
temprect.set(((id - 384)&7)*@tileSrcWidth,((id - 384)>>3)*@tileSrcHeight, ((id - 384) >> 3) * @tileSrcHeight,
@tileSrcWidth,@tileSrcHeight) @tileSrcWidth, @tileSrcHeight)
xpos = (x*twidth)-@oxLayer0 xpos = (x * twidth) - @oxLayer0
ypos = (y*theight)-@oyLayer0 ypos = (y * theight) - @oyLayer0
if @diffsizes if @diffsizes
bitmap.stretch_blt(Rect.new(xpos,ypos,twidth,theight),@tileset,temprect) bitmap.stretch_blt(Rect.new(xpos, ypos, twidth, theight), @tileset, temprect)
else else
bitmap.blt(xpos,ypos,@tileset,temprect) bitmap.blt(xpos, ypos, @tileset, temprect)
end end
else else # Autotiles
tilebitmap = @autotileInfo[id] tilebitmap = @autotileInfo[id]
if !tilebitmap if !tilebitmap
anim = autotileFrame(id) anim = autotileFrame(id)
next if anim<0 next if anim < 0
tilebitmap = Bitmap.new(twidth,theight) tilebitmap = Bitmap.new(twidth, theight)
bltAutotile(tilebitmap,0,0,id,anim) bltAutotile(tilebitmap, 0, 0, id, anim)
@autotileInfo[id] = tilebitmap @autotileInfo[id] = tilebitmap
end end
xpos = (x*twidth)-@oxLayer0 xpos = (x * twidth) - @oxLayer0
ypos = (y*theight)-@oyLayer0 ypos = (y * theight) - @oyLayer0
bitmap.blt(xpos,ypos,tilebitmap,tilerect) bitmap.blt(xpos, ypos, tilebitmap, tilerect)
end end
end end
end end
@@ -681,108 +678,108 @@ class CustomTilemap
Graphics.frame_reset Graphics.frame_reset
else else
if !@priorect || !@priorectautos || if !@priorect || !@priorectautos ||
@priorect[0]!=xStart || @priorect[1]!=yStart || @priorect[0] != xStart || @priorect[1] != yStart ||
@priorect[2]!=xEnd || @priorect[3]!=yEnd @priorect[2] != xEnd || @priorect[3] != yEnd
@priorectautos = @prioautotiles.find_all { |tile| @priorect = [xStart, yStart, xEnd, yEnd]
x = tile[0] @priorectautos = []
y = tile[1] for y in yStart..yEnd
# "next" means "return" here for x in xStart..xEnd
next !(x<xStart || x>xEnd || y<yStart || y>yEnd) @priorectautos.push([x, y]) if @prioautotiles[[x, y]]
}
@priorect = [xStart,yStart,xEnd,yEnd]
end
# echoln ["autos",@priorect,@priorectautos.length,@prioautotiles.length]
for tile in @priorectautos
x = tile[0]
y = tile[1]
overallcount+=1
xpos = (x*twidth)-@oxLayer0
ypos = (y*theight)-@oyLayer0
bitmap.fill_rect(xpos,ypos,twidth,theight,trans)
z = 0
while z<zsize
id = mapdata[x,y,z]
z += 1
next if !id || id<48
prioid = @priorities[id]
next if prioid!=0 || PBTerrain.hasReflections?(@terrain_tags[id])
if id>=384
temprect.set(((id - 384)&7)*@tileSrcWidth,((id - 384)>>3)*@tileSrcHeight,
@tileSrcWidth,@tileSrcHeight)
if @diffsizes
bitmap.stretch_blt(Rect.new(xpos,ypos,twidth,theight),@tileset,temprect)
else
bitmap.blt(xpos,ypos,@tileset,temprect)
end
else
tilebitmap = @autotileInfo[id]
if !tilebitmap
anim = autotileFrame(id)
next if anim<0
tilebitmap = Bitmap.new(twidth,theight)
bltAutotile(tilebitmap,0,0,id,anim)
@autotileInfo[id] = tilebitmap
end
bitmap.blt(xpos,ypos,tilebitmap,tilerect)
end end
end end
end end
Graphics.frame_reset if overallcount>500 for tile in @priorectautos
x = tile[0]
y = tile[1]
overallcount += 1
xpos = (x * twidth) - @oxLayer0
ypos = (y * theight) - @oyLayer0
bitmap.fill_rect(xpos, ypos, twidth, theight, trans)
z = 0
while z < zsize
id = mapdata[x, y, z]
z += 1
next if !id || id < 48
prioid = @priorities[id]
next if prioid != 0 || PBTerrain.hasReflections?(@terrain_tags[id])
if id >= 384 # Tileset tiles
temprect.set(((id - 384) & 7) * @tileSrcWidth,
((id - 384) >> 3) * @tileSrcHeight,
@tileSrcWidth, @tileSrcHeight)
if @diffsizes
bitmap.stretch_blt(Rect.new(xpos, ypos, twidth, theight), @tileset, temprect)
else
bitmap.blt(xpos, ypos, @tileset, temprect)
end
else # Autotiles
tilebitmap = @autotileInfo[id]
if !tilebitmap
anim = autotileFrame(id)
next if anim < 0
tilebitmap = Bitmap.new(twidth, theight)
bltAutotile(tilebitmap, 0, 0, id, anim)
@autotileInfo[id] = tilebitmap
end
bitmap.blt(xpos, ypos, tilebitmap, tilerect)
end
end
end
Graphics.frame_reset if overallcount > 500
end end
@usedsprites = false @usedsprites = false
return true return true
end end
return false if @usedsprites return false if @usedsprites
@firsttime = false @firsttime = false
@oxLayer0 = @ox-(width>>2) @oxLayer0 = @ox - (width >> 2)
@oyLayer0 = @oy-(height>>2) @oyLayer0 = @oy - (height >> 2)
if @layer0clip if @layer0clip
@layer0.ox = 0 @layer0.ox = 0
@layer0.oy = 0 @layer0.oy = 0
@layer0.src_rect.set(width>>2,height>>2, @layer0.src_rect.set(width >> 2, height >> 2, @viewport.rect.width, @viewport.rect.height)
@viewport.rect.width,@viewport.rect.height)
else else
@layer0.ox = (width>>2) @layer0.ox = (width >> 2)
@layer0.oy = (height>>2) @layer0.oy = (height >> 2)
end end
@layer0.bitmap.clear @layer0.bitmap.clear
@oxLayer0 = @oxLayer0.round @oxLayer0 = @oxLayer0.round
@oyLayer0 = @oyLayer0.round @oyLayer0 = @oyLayer0.round
xStart = @oxLayer0/twidth xStart = @oxLayer0 / twidth
xStart = 0 if xStart<0 xStart = 0 if xStart < 0
yStart = @oyLayer0/theight yStart = @oyLayer0 / theight
yStart = 0 if yStart<0 yStart = 0 if yStart < 0
xEnd = xStart+(width/twidth)+1 xEnd = xStart + (width / twidth) + 1
yEnd = yStart+(height/theight)+1 xEnd = xsize if xEnd >= xsize
xEnd = xsize if xEnd>=xsize yEnd = yStart + (height / theight) + 1
yEnd = ysize if yEnd>=ysize yEnd = ysize if yEnd >= ysize
if xStart<xEnd && yStart<yEnd if xStart < xEnd && yStart < yEnd
tmprect = Rect.new(0,0,0,0) tmprect = Rect.new(0, 0, 0, 0)
yrange = yStart...yEnd yrange = yStart...yEnd
xrange = xStart...xEnd xrange = xStart...xEnd
for z in 0...zsize for z in 0...zsize
for y in yrange for y in yrange
ypos = (y*theight)-@oyLayer0 ypos = (y * theight) - @oyLayer0
for x in xrange for x in xrange
xpos = (x*twidth)-@oxLayer0 xpos = (x * twidth) - @oxLayer0
id = mapdata[x, y, z] id = mapdata[x, y, z]
next if id==0 || @priorities[id]!=0 || PBTerrain.hasReflections?(@terrain_tags[id]) next if id == 0 || @priorities[id] != 0 || PBTerrain.hasReflections?(@terrain_tags[id])
if id>=384 if id >= 384 # Tileset tiles
tmprect.set( ((id - 384)&7)*@tileSrcWidth,((id - 384)>>3)*@tileSrcHeight, tmprect.set(((id - 384) & 7) * @tileSrcWidth,
@tileSrcWidth,@tileSrcHeight) ((id - 384) >> 3) * @tileSrcHeight,
@tileSrcWidth, @tileSrcHeight)
if @diffsizes if @diffsizes
bitmap.stretch_blt(Rect.new(xpos,ypos,twidth,theight),@tileset,tmprect) bitmap.stretch_blt(Rect.new(xpos, ypos, twidth, theight), @tileset, tmprect)
else else
bitmap.blt(xpos,ypos,@tileset,tmprect) bitmap.blt(xpos, ypos, @tileset, tmprect)
end end
else else # Autotiles
frames = @framecount[id/48-1] frames = @framecount[id / 48 - 1]
if frames<=1 if frames <= 1
frame = 0 frame = 0
else else
frame = (Graphics.frame_count/Animated_Autotiles_Frames)%frames frame = (Graphics.frame_count / Animated_Autotiles_Frames) % frames
end end
bltAutotile(bitmap,xpos,ypos,id,frame) bltAutotile(bitmap, xpos, ypos, id, frame)
end end
end end
end end
@@ -792,7 +789,7 @@ class CustomTilemap
return true return true
end end
def refresh(autotiles=false) def refresh(autotiles = false)
@oldOx = @ox @oldOx = @ox
@oldOy = @oy @oldOy = @oy
usesprites = false usesprites = false
@@ -806,80 +803,60 @@ class CustomTilemap
refreshFlashSprite refreshFlashSprite
xsize = @map_data.xsize xsize = @map_data.xsize
ysize = @map_data.ysize ysize = @map_data.ysize
minX = (@ox/@tileWidth)-1 minX = (@ox / @tileWidth) - 1
minX = 0 if minX<0 minX.clamp(0, xsize - 1)
minX = xsize-1 if minX>=xsize maxX = ((@ox + @viewport.rect.width) / @tileWidth) + 1
maxX = ((@ox+@viewport.rect.width)/@tileWidth)+1 maxX.clamp(0, xsize - 1)
maxX = 0 if maxX<0 minY = (@oy / @tileHeight) - 1
maxX = xsize-1 if maxX>=xsize minY.clamp(0, ysize - 1)
minY = (@oy/@tileHeight)-1 maxY = ((@oy + @viewport.rect.height) / @tileHeight) + 1
minY = 0 if minY<0 maxY.clamp(0, ysize - 1)
minY = ysize-1 if minY>=ysize
maxY = ((@oy+@viewport.rect.height)/@tileHeight)+1
maxY = 0 if maxY<0
maxY = ysize-1 if maxY>=ysize
count = 0 count = 0
if minX<maxX && minY<maxY if minX < maxX && minY < maxY
@usedsprites = usesprites || @usedsprites @usedsprites = usesprites || @usedsprites
if @layer0 @layer0.visible = false if usesprites && @layer0
@layer0.visible = false if usesprites if !@priotilesrect || !@priotilesfast ||
end @priotilesrect[0] != minX || @priotilesrect[1] != minY ||
if @fullyrefreshed @priotilesrect[2] != maxX || @priotilesrect[3] != maxY
if !@priotilesrect || !@priotilesfast || @priotilesrect = [minX, minY, maxX, maxY]
@priotilesrect[0]!=minX || @priotilesfast = []
@priotilesrect[1]!=minY || if @fullyrefreshed
@priotilesrect[2]!=maxX || for y in minY..maxY
@priotilesrect[3]!=maxY for x in minX..maxX
@priotilesfast = @priotiles.find_all { |tile| next if !@priotiles[[x, y]]
x = tile[0] @priotiles[[x, y]].each { |tile| @priotilesfast.push([x, y, tile[0], tile[1]]) }
y = tile[1] end
# "next" means "return" here end
next !(x<minX || x>maxX || y<minY || y>maxY) else
}
@priotilesrect = [minX,minY,maxX,maxY]
end
# echoln [minX,minY,maxX,maxY,@priotilesfast.length,@priotiles.length]
for prio in @priotilesfast
xpos = (prio[0]*@tileWidth)-@ox
ypos = (prio[1]*@tileHeight)-@oy
count = addTile(@tiles,count,xpos,ypos,prio[3])
end
else
if !@priotilesrect || !@priotilesfast ||
@priotilesrect[0]!=minX ||
@priotilesrect[1]!=minY ||
@priotilesrect[2]!=maxX ||
@priotilesrect[3]!=maxY
@priotilesfast=[]
for z in 0...@map_data.zsize for z in 0...@map_data.zsize
for y in minY..maxY for y in minY..maxY
for x in minX..maxX for x in minX..maxX
id = @map_data[x, y, z] id = @map_data[x, y, z]
next if id==0 next if id == 0
next if @priorities[id]==0 && !PBTerrain.hasReflections?(@terrain_tags[id]) next if @priorities[id] == 0 && !PBTerrain.hasReflections?(@terrain_tags[id])
@priotilesfast.push([x,y,z,id]) @priotilesfast.push([x, y, z, id])
end end
end end
end end
@priotilesrect = [minX,minY,maxX,maxY]
end
for prio in @priotilesfast
xpos = (prio[0]*@tileWidth)-@ox
ypos = (prio[1]*@tileHeight)-@oy
count = addTile(@tiles,count,xpos,ypos,prio[3])
end end
end end
for prio in @priotilesfast
xpos = (prio[0] * @tileWidth) - @ox
ypos = (prio[1] * @tileHeight) - @oy
count = addTile(@tiles, count, xpos, ypos, prio[3])
end
end end
if count<@tiles.length if count < @tiles.length
bigchange = (count<=(@tiles.length*2/3)) && (@tiles.length*2/3)>25 bigchange = (count <= (@tiles.length * 2 / 3)) && @tiles.length > 40
j = count; len = @tiles.length j = count
while j<len len = @tiles.length
while j < len
sprite = @tiles[j] sprite = @tiles[j]
@tiles[j+1] = -1 @tiles[j + 1] = -1
if bigchange if bigchange
sprite.dispose sprite.dispose
@tiles[j] = nil @tiles[j] = nil
@tiles[j+1] = nil @tiles[j + 1] = nil
elsif !@tiles[j].disposed? elsif !@tiles[j].disposed?
sprite.visible = false if sprite.visible sprite.visible = false if sprite.visible
end end
@@ -895,7 +872,7 @@ class CustomTilemap
@graphicsHeight = Graphics.height @graphicsHeight = Graphics.height
end end
# Update tone # Update tone
if @oldtone!=@tone if @oldtone != @tone
@layer0.tone = @tone @layer0.tone = @tone
@flash.tone = @tone if @flash @flash.tone = @tone if @flash
for sprite in @autosprites for sprite in @autosprites
@@ -907,7 +884,7 @@ class CustomTilemap
@oldtone = @tone.clone @oldtone = @tone.clone
end end
# Update color # Update color
if @oldcolor!=@color if @oldcolor != @color
@layer0.color = @color @layer0.color = @color
@flash.color = @color if @flash @flash.color = @color if @flash
for sprite in @autosprites for sprite in @autosprites
@@ -923,23 +900,17 @@ class CustomTilemap
refresh_autotiles refresh_autotiles
repaintAutotiles repaintAutotiles
end end
if @flashChanged refresh_flash if @flashChanged
refresh_flash refresh_tileset if @tilesetChanged
end @flash.opacity = FlashOpacity[(Graphics.frame_count / 2) % 6] if @flash
if @tilesetChanged mustrefresh = (@oldOx != @ox || @oldOy != @oy || @tilesetChanged || @autotiles.changed)
refresh_tileset if @viewport.ox != @oldViewportOx || @viewport.oy != @oldViewportOy
end
if @flash
@flash.opacity = FlashOpacity[(Graphics.frame_count/2) % 6]
end
mustrefresh = (@oldOx!=@ox || @oldOy!=@oy || @tilesetChanged || @autotiles.changed)
if @viewport.ox!=@oldViewportOx || @viewport.oy!=@oldViewportOy
mustrefresh = true mustrefresh = true
@oldViewportOx = @viewport.ox @oldViewportOx = @viewport.ox
@oldViewportOy = @viewport.oy @oldViewportOy = @viewport.oy
end end
refresh if mustrefresh refresh if mustrefresh
if (Graphics.frame_count % Animated_Autotiles_Frames == 0) || @nowshown if (Graphics.frame_count % Animated_Autotiles_Frames) == 0 || @nowshown
repaintAutotiles repaintAutotiles
refresh(true) refresh(true)
end end