mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
Remove Win32API calls & upgrade to modern Ruby (#96)
* Win32API removal + Ruby 3 updates * Update binaries to match mkxp-z 2.1
This commit is contained in:
@@ -1,3 +1,104 @@
|
||||
#=======================================================================
|
||||
# This module is a little fix that works around PC hardware limitations.
|
||||
# Since Essentials isn't working with software rendering anymore, it now
|
||||
# has to deal with the limits of the GPU. For the most part this is no
|
||||
# big deal, but people do have some really big tilesets.
|
||||
#
|
||||
# The fix is simple enough: If your tileset is too big, a new
|
||||
# bitmap will be constructed with all the excess pixels sent to the
|
||||
# image's right side. This basically means that you now have a limit
|
||||
# far higher than you should ever actually need.
|
||||
#
|
||||
# Hardware limit -> max tileset length:
|
||||
# 1024px -> 4096px
|
||||
# 2048px -> 16384px (enough to get the normal limit)
|
||||
# 4096px -> 65536px (enough to load pretty much any tileset)
|
||||
# 8192px -> 262144px
|
||||
# 16384px -> 1048576px (what most people have at this point)
|
||||
|
||||
# ~Roza/Zoroark
|
||||
#=======================================================================
|
||||
|
||||
module TileWrap
|
||||
|
||||
TILESET_WIDTH = 0x100
|
||||
# Looks useless, but covers weird numbers given to mkxp.json or a funky driver
|
||||
MAX_TEX_SIZE = (Bitmap.max_size / 1024) * 1024
|
||||
MAX_TEX_SIZE_BOOSTED = MAX_TEX_SIZE**2/TILESET_WIDTH
|
||||
|
||||
def self.clamp(val, min, max)
|
||||
val = max if val > max
|
||||
val = min if val < min
|
||||
return val
|
||||
end
|
||||
|
||||
def self.wrapTileset(originalbmp)
|
||||
width = originalbmp.width
|
||||
height = originalbmp.height
|
||||
if width == TILESET_WIDTH && originalbmp.mega?
|
||||
columns = (height / MAX_TEX_SIZE.to_f).ceil
|
||||
|
||||
if columns * TILESET_WIDTH > MAX_TEX_SIZE
|
||||
raise "Tilemap is too long!\n\nSIZE: #{originalbmp.height}px\nHARDWARE LIMIT: #{MAX_TEX_SIZE}px\nBOOSTED LIMIT: #{MAX_TEX_SIZE_BOOSTED}px"
|
||||
end
|
||||
bmp = Bitmap.new(TILESET_WIDTH*columns, MAX_TEX_SIZE)
|
||||
remainder = height % MAX_TEX_SIZE
|
||||
|
||||
columns.times{|col|
|
||||
srcrect = Rect.new(0, col * MAX_TEX_SIZE, width, (col + 1 == columns) ? remainder : MAX_TEX_SIZE)
|
||||
bmp.blt(col*TILESET_WIDTH, 0, originalbmp, srcrect)
|
||||
}
|
||||
return bmp
|
||||
end
|
||||
|
||||
return originalbmp
|
||||
end
|
||||
|
||||
def self.getWrappedRect(src_rect)
|
||||
ret = Rect.new(0,0,0,0)
|
||||
col = (src_rect.y / MAX_TEX_SIZE.to_f).floor
|
||||
ret.x = col * TILESET_WIDTH + clamp(src_rect.x,0,TILESET_WIDTH)
|
||||
ret.y = src_rect.y % MAX_TEX_SIZE
|
||||
ret.width = clamp(src_rect.width, 0, TILESET_WIDTH - src_rect.x)
|
||||
ret.height = clamp(src_rect.height, 0, MAX_TEX_SIZE)
|
||||
return ret
|
||||
end
|
||||
|
||||
def self.blitWrappedPixels(destX, destY, dest, src, srcrect)
|
||||
if (srcrect.y + srcrect.width < MAX_TEX_SIZE)
|
||||
# Save the processing power
|
||||
dest.blt(destX, destY, src, srcrect)
|
||||
return
|
||||
end
|
||||
merge = (srcrect.y % MAX_TEX_SIZE) > ((srcrect.y + srcrect.height) % MAX_TEX_SIZE)
|
||||
|
||||
srcrect_mod = getWrappedRect(srcrect)
|
||||
|
||||
if !merge
|
||||
dest.blt(destX, destY, src, srcrect_mod)
|
||||
else
|
||||
#FIXME won't work on heights longer than two columns, but nobody should need
|
||||
# more than 32k pixels high at once anyway
|
||||
side = {:a => MAX_TEX_SIZE - srcrect_mod.y, :b => srcrect_mod.height - (MAX_TEX_SIZE - srcrect_mod.y)}
|
||||
dest.blt(destX, destY, src, Rect.new(srcrect_mod.x, srcrect_mod.y, srcrect_mod.width, side[:a]))
|
||||
dest.blt(destX, destY + side[:a], src, Rect.new(srcrect_mod.x + TILESET_WIDTH, 0, srcrect_mod.width, side[:b]))
|
||||
end
|
||||
end
|
||||
|
||||
def self.stretchBlitWrappedPixels(destrect, dest, src, srcrect)
|
||||
if (srcrect.y + srcrect.width < MAX_TEX_SIZE)
|
||||
# Save the processing power
|
||||
dest.stretch_blt(destrect, src, srcrect)
|
||||
return
|
||||
end
|
||||
# Does a regular blit to a non-megasurface, then stretch_blts that to
|
||||
# the destination. Yes it is slow
|
||||
tmp = Bitmap.new(srcrect.width, srcrect.height)
|
||||
blitWrappedPixels(0,0,tmp,src,srcrect)
|
||||
dest.stretch_blt(destrect, tmp, Rect.new(0,0,srcrect.width,srcrect.height))
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
@@ -126,6 +227,7 @@ class CustomTilemap
|
||||
@firsttimeflash = true
|
||||
@fullyrefreshed = false
|
||||
@fullyrefreshedautos = false
|
||||
@shouldWrap = false
|
||||
end
|
||||
|
||||
def dispose
|
||||
@@ -212,7 +314,14 @@ class CustomTilemap
|
||||
end
|
||||
|
||||
def tileset=(value)
|
||||
@tileset = value
|
||||
if value.mega?
|
||||
@tileset = TileWrap::wrapTileset(value)
|
||||
@shouldWrap = true
|
||||
value.dispose
|
||||
else
|
||||
@tileset = value
|
||||
@shouldWrap = false
|
||||
end
|
||||
@tilesetChanged = true
|
||||
end
|
||||
|
||||
@@ -348,14 +457,16 @@ class CustomTilemap
|
||||
bitmap = Bitmap.new(@tileWidth,@tileHeight)
|
||||
rect = Rect.new(((id - 384)&7)*@tileSrcWidth,((id - 384)>>3)*@tileSrcHeight,
|
||||
@tileSrcWidth,@tileSrcHeight)
|
||||
bitmap.stretch_blt(Rect.new(0,0,@tileWidth,@tileHeight),@tileset,rect)
|
||||
TileWrap::stretchBlitWrappedPixels(Rect.new(0,0,@tileWidth,@tileHeight), bitmap, @tileset, rect)
|
||||
@regularTileInfo[id] = bitmap
|
||||
end
|
||||
sprite.bitmap = bitmap if sprite.bitmap!=bitmap
|
||||
else
|
||||
sprite.bitmap = @tileset if sprite.bitmap!=@tileset
|
||||
sprite.src_rect.set(((id - 384)&7)*@tileSrcWidth,((id - 384)>>3)*@tileSrcHeight,
|
||||
@tileSrcWidth,@tileSrcHeight)
|
||||
rect = Rect.new(((id - 384)&7)*@tileSrcWidth,((id - 384)>>3)*@tileSrcHeight,
|
||||
@tileSrcWidth,@tileSrcHeight)
|
||||
rect = TileWrap::getWrappedRect(rect) if @shouldWrap
|
||||
sprite.src_rect = rect
|
||||
end
|
||||
end
|
||||
|
||||
@@ -641,9 +752,9 @@ class CustomTilemap
|
||||
xpos = (x * twidth) - @oxLayer0
|
||||
ypos = (y * theight) - @oyLayer0
|
||||
if @diffsizes
|
||||
bitmap.stretch_blt(Rect.new(xpos, ypos, twidth, theight), @tileset, temprect)
|
||||
TileWrap::stretchBlitWrappedPixels(Rect.new(xpos, ypos, twidth, theight), bitmap, @tileset, temprect)
|
||||
else
|
||||
bitmap.blt(xpos, ypos, @tileset, temprect)
|
||||
TileWrap::blitWrappedPixels(xpos,ypos, bitmap, @tileset, temprect)
|
||||
end
|
||||
else # Autotiles
|
||||
tilebitmap = @autotileInfo[id]
|
||||
@@ -693,9 +804,9 @@ class CustomTilemap
|
||||
((id - 384) >> 3) * @tileSrcHeight,
|
||||
@tileSrcWidth, @tileSrcHeight)
|
||||
if @diffsizes
|
||||
bitmap.stretch_blt(Rect.new(xpos, ypos, twidth, theight), @tileset, temprect)
|
||||
TileWrap::stretchBlitWrappedPixels(Rect.new(xpos, ypos, twidth, theight), bitmap, @tileset, temprect)
|
||||
else
|
||||
bitmap.blt(xpos, ypos, @tileset, temprect)
|
||||
TileWrap::blitWrappedPixels(xpos,ypos, bitmap, @tileset, temprect)
|
||||
end
|
||||
else # Autotiles
|
||||
tilebitmap = @autotileInfo[id]
|
||||
@@ -754,9 +865,9 @@ class CustomTilemap
|
||||
((id - 384) >> 3) * @tileSrcHeight,
|
||||
@tileSrcWidth, @tileSrcHeight)
|
||||
if @diffsizes
|
||||
bitmap.stretch_blt(Rect.new(xpos, ypos, twidth, theight), @tileset, tmprect)
|
||||
TileWrap::stretchBlitWrappedPixels(Rect.new(xpos, ypos, twidth, theight), bitmap, @tileset, tmprect)
|
||||
else
|
||||
bitmap.blt(xpos, ypos, @tileset, tmprect)
|
||||
TileWrap::blitWrappedPixels(xpos,ypos, bitmap, @tileset, tmprect)
|
||||
end
|
||||
else # Autotiles
|
||||
frames = @framecount[id / 48 - 1]
|
||||
|
||||
Reference in New Issue
Block a user