mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-09-10 03:52:55 +02:00
Fix Essentials layer0 with BEEG tilesets
This commit is contained in:
parent
6f1542ecf9
commit
83631ca31b
1 changed files with 232 additions and 1 deletions
|
@ -29,7 +29,7 @@
|
|||
|
||||
module VWrap
|
||||
|
||||
MAX_TEX_SIZE = Bitmap.max_size()
|
||||
MAX_TEX_SIZE = Bitmap.max_size
|
||||
TILESET_WIDTH = 0x100
|
||||
|
||||
def self.clamp(val, min, max)
|
||||
|
@ -59,6 +59,10 @@ module VWrap
|
|||
end
|
||||
|
||||
def self.blitVWrappedPixels(destX, destY, dest, src, srcrect)
|
||||
if (srcrect.y + srcrect.width < MAX_TEX_SIZE)
|
||||
# Save the processing power
|
||||
return dest.blt(destX, destY, src, srcrect)
|
||||
end
|
||||
merge = (srcrect.y % MAX_TEX_SIZE) > ((srcrect.y + srcrect.height) % MAX_TEX_SIZE)
|
||||
|
||||
srcrect.x = clamp(srcrect.x, 0,TILESET_WIDTH)
|
||||
|
@ -101,10 +105,237 @@ if $MKXP == true
|
|||
rect=Rect.new(((id - 384)&7)*@tileSrcWidth,((id - 384)>>3)*@tileSrcHeight,
|
||||
@tileSrcWidth,@tileSrcHeight)
|
||||
VWrap::blitVWrappedPixels(0,0, bitmap, @tileset, rect)
|
||||
|
||||
@regularTileInfo[id]=bitmap
|
||||
end
|
||||
sprite.bitmap = bitmap if sprite.bitmap != bitmap
|
||||
end
|
||||
|
||||
def refreshLayer0(autotiles=false)
|
||||
if autotiles
|
||||
return true if !shown?
|
||||
end
|
||||
ptX=@ox-@oxLayer0
|
||||
ptY=@oy-@oyLayer0
|
||||
if !autotiles && !@firsttime && !@usedsprites &&
|
||||
ptX>=0 && ptX+@viewport.rect.width<=@layer0.bitmap.width &&
|
||||
ptY>=0 && ptY+@viewport.rect.height<=@layer0.bitmap.height
|
||||
if @layer0clip && @viewport.ox==0 && @viewport.oy==0
|
||||
@layer0.ox=0
|
||||
@layer0.oy=0
|
||||
@layer0.src_rect.set(ptX.round,ptY.round,
|
||||
@viewport.rect.width,@viewport.rect.height)
|
||||
else
|
||||
@layer0.ox=ptX.round
|
||||
@layer0.oy=ptY.round
|
||||
@layer0.src_rect.set(0,0,@layer0.bitmap.width,@layer0.bitmap.height)
|
||||
end
|
||||
return true
|
||||
end
|
||||
width=@layer0.bitmap.width
|
||||
height=@layer0.bitmap.height
|
||||
bitmap=@layer0.bitmap
|
||||
ysize=@map_data.ysize
|
||||
xsize=@map_data.xsize
|
||||
zsize=@map_data.zsize
|
||||
twidth=@tileWidth
|
||||
theight=@tileHeight
|
||||
mapdata=@map_data
|
||||
if autotiles
|
||||
return true if @fullyrefreshedautos && @prioautotiles.length==0
|
||||
xStart=(@oxLayer0/twidth)
|
||||
xStart=0 if xStart<0
|
||||
yStart=(@oyLayer0/theight)
|
||||
yStart=0 if yStart<0
|
||||
xEnd=xStart+(width/twidth)+1
|
||||
yEnd=yStart+(height/theight)+1
|
||||
xEnd=xsize if xEnd>xsize
|
||||
yEnd=ysize if yEnd>ysize
|
||||
return true if xStart>=xEnd || yStart>=yEnd
|
||||
trans=Color.new(0,0,0,0)
|
||||
temprect=Rect.new(0,0,0,0)
|
||||
tilerect=Rect.new(0,0,twidth,theight)
|
||||
zrange=0...zsize
|
||||
overallcount=0
|
||||
count=0
|
||||
if !@fullyrefreshedautos
|
||||
for y in yStart..yEnd
|
||||
for x in xStart..xEnd
|
||||
haveautotile=false
|
||||
for z in zrange
|
||||
id = mapdata[x, y, z]
|
||||
next if !id || id<48 || id>=384
|
||||
prioid=@priorities[id]
|
||||
next if prioid!=0 || !prioid
|
||||
fcount=@framecount[id/48-1]
|
||||
next if !fcount || fcount<2
|
||||
if !haveautotile
|
||||
haveautotile=true
|
||||
overallcount+=1
|
||||
xpos=(x*twidth)-@oxLayer0
|
||||
ypos=(y*theight)-@oyLayer0
|
||||
bitmap.fill_rect(xpos,ypos,twidth,theight,trans) if overallcount<=2000
|
||||
break
|
||||
end
|
||||
end
|
||||
for z in zrange
|
||||
id = mapdata[x,y,z]
|
||||
next if !id || id<48
|
||||
prioid=@priorities[id]
|
||||
next if prioid!=0 || !prioid
|
||||
if overallcount>2000
|
||||
xpos=(x*twidth)-@oxLayer0
|
||||
ypos=(y*theight)-@oyLayer0
|
||||
count=addTile(@autosprites,count,xpos,ypos,id)
|
||||
next
|
||||
elsif id>=384
|
||||
temprect.set(((id - 384)&7)*@tileSrcWidth,((id - 384)>>3)*@tileSrcHeight,
|
||||
@tileSrcWidth,@tileSrcHeight)
|
||||
xpos=(x*twidth)-@oxLayer0
|
||||
ypos=(y*theight)-@oyLayer0
|
||||
if @tileset.width <= VWrap::TILESET_WIDTH
|
||||
if @diffsizes
|
||||
bitmap.stretch_blt(Rect.new(xpos,ypos,twidth,theight),@tileset,temprect)
|
||||
else
|
||||
bitmap.blt(xpos,ypos,@tileset,temprect)
|
||||
end
|
||||
else
|
||||
VWrap::blitVWrappedPixels(xpos,ypos, bitmap, @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
|
||||
xpos=(x*twidth)-@oxLayer0
|
||||
ypos=(y*theight)-@oyLayer0
|
||||
bitmap.blt(xpos,ypos,tilebitmap,tilerect)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Graphics.frame_reset
|
||||
else
|
||||
if !@priorect || !@priorectautos || @priorect[0]!=xStart ||
|
||||
@priorect[1]!=yStart ||
|
||||
@priorect[2]!=xEnd ||
|
||||
@priorect[3]!=yEnd
|
||||
@priorectautos=@prioautotiles.find_all{|tile|
|
||||
x=tile[0]
|
||||
y=tile[1]
|
||||
# "next" means "return" here
|
||||
next !(x<xStart||x>xEnd||y<yStart||y>yEnd)
|
||||
}
|
||||
@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 || !prioid
|
||||
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
|
||||
Graphics.frame_reset if overallcount>500
|
||||
end
|
||||
@usedsprites=false
|
||||
return true
|
||||
end
|
||||
return false if @usedsprites
|
||||
@firsttime=false
|
||||
@oxLayer0=@ox-(width>>2)
|
||||
@oyLayer0=@oy-(height>>2)
|
||||
if @layer0clip
|
||||
@layer0.ox=0
|
||||
@layer0.oy=0
|
||||
@layer0.src_rect.set(width>>2,height>>2,
|
||||
@viewport.rect.width,@viewport.rect.height)
|
||||
else
|
||||
@layer0.ox=(width>>2)
|
||||
@layer0.oy=(height>>2)
|
||||
end
|
||||
@layer0.bitmap.clear
|
||||
@oxLayer0=@oxLayer0.floor
|
||||
@oyLayer0=@oyLayer0.floor
|
||||
xStart=(@oxLayer0/twidth)
|
||||
xStart=0 if xStart<0
|
||||
yStart=(@oyLayer0/theight)
|
||||
yStart=0 if yStart<0
|
||||
xEnd=xStart+(width/twidth)+1
|
||||
yEnd=yStart+(height/theight)+1
|
||||
xEnd=xsize if xEnd>=xsize
|
||||
yEnd=ysize if yEnd>=ysize
|
||||
if xStart<xEnd && yStart<yEnd
|
||||
tmprect=Rect.new(0,0,0,0)
|
||||
yrange=yStart...yEnd
|
||||
xrange=xStart...xEnd
|
||||
for z in 0...zsize
|
||||
for y in yrange
|
||||
ypos=(y*theight)-@oyLayer0
|
||||
for x in xrange
|
||||
xpos=(x*twidth)-@oxLayer0
|
||||
id = mapdata[x, y, z]
|
||||
next if id==0 || @priorities[id]!=0 || !@priorities[id]
|
||||
if id>=384
|
||||
tmprect.set( ((id - 384)&7)*@tileSrcWidth,((id - 384)>>3)*@tileSrcHeight,
|
||||
@tileSrcWidth,@tileSrcHeight)
|
||||
if @tileset.width <= VWrap::TILESET_WIDTH
|
||||
if @diffsizes
|
||||
bitmap.stretch_blt(Rect.new(xpos,ypos,twidth,theight),@tileset,tmprect)
|
||||
else
|
||||
bitmap.blt(xpos,ypos,@tileset,tmprect)
|
||||
end
|
||||
else
|
||||
VWrap::blitVWrappedPixels(xpos,ypos, bitmap, @tileset, tmprect)
|
||||
end
|
||||
else
|
||||
frames=@framecount[id/48-1]
|
||||
if frames<=1
|
||||
frame=0
|
||||
else
|
||||
frame=(Graphics.frame_count/Animated_Autotiles_Frames)%frames
|
||||
end
|
||||
bltAutotile(bitmap,xpos,ypos,id,frame)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Graphics.frame_reset
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue