mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
Removed old map renderer, tidied up
This commit is contained in:
@@ -33,7 +33,6 @@ end
|
||||
|
||||
class Spriteset_Map
|
||||
attr_reader :map
|
||||
attr_accessor :tilemap
|
||||
@@viewport0 = Viewport.new(0, 0, Settings::SCREEN_WIDTH, Settings::SCREEN_HEIGHT) # Panorama
|
||||
@@viewport0.z = -100
|
||||
@@viewport1 = Viewport.new(0, 0, Settings::SCREEN_WIDTH, Settings::SCREEN_HEIGHT) # Map, events, player, fog
|
||||
@@ -49,15 +48,6 @@ class Spriteset_Map
|
||||
@map = (map) ? map : $game_map
|
||||
$scene.map_renderer.add_tileset(@map.tileset_name)
|
||||
@map.autotile_names.each { |filename| $scene.map_renderer.add_autotile(filename) }
|
||||
# @tilemap = TilemapLoader.new(@@viewport1)
|
||||
# @tilemap.tileset = pbGetTileset(@map.tileset_name)
|
||||
# for i in 0...7
|
||||
# autotile_name = @map.autotile_names[i]
|
||||
# @tilemap.autotiles[i] = pbGetAutotile(autotile_name)
|
||||
# end
|
||||
# @tilemap.map_data = @map.data
|
||||
# @tilemap.priorities = @map.priorities
|
||||
# @tilemap.terrain_tags = @map.terrain_tags
|
||||
@panorama = AnimatedPlane.new(@@viewport0)
|
||||
@fog = AnimatedPlane.new(@@viewport1)
|
||||
@fog.z = 3000
|
||||
@@ -72,11 +62,6 @@ class Spriteset_Map
|
||||
end
|
||||
|
||||
def dispose
|
||||
# @tilemap.tileset.dispose
|
||||
# for i in 0...7
|
||||
# @tilemap.autotiles[i].dispose
|
||||
# end
|
||||
# @tilemap.dispose
|
||||
$scene.map_renderer.remove_tileset(@map.tileset_name)
|
||||
@map.autotile_names.each { |filename| $scene.map_renderer.remove_autotile(filename) }
|
||||
@panorama.dispose
|
||||
@@ -85,7 +70,6 @@ class Spriteset_Map
|
||||
sprite.dispose
|
||||
end
|
||||
@weather.dispose
|
||||
# @tilemap = nil
|
||||
@panorama = nil
|
||||
@fog = nil
|
||||
@character_sprites.clear
|
||||
@@ -117,13 +101,10 @@ class Spriteset_Map
|
||||
end
|
||||
tmox = (@map.display_x/Game_Map::X_SUBPIXELS).round
|
||||
tmoy = (@map.display_y/Game_Map::Y_SUBPIXELS).round
|
||||
# @tilemap.ox = tmox
|
||||
# @tilemap.oy = tmoy
|
||||
@@viewport1.rect.set(0,0,Graphics.width,Graphics.height)
|
||||
@@viewport1.ox = 0
|
||||
@@viewport1.oy = 0
|
||||
@@viewport1.ox += $game_screen.shake
|
||||
# @tilemap.update
|
||||
@panorama.ox = tmox/2
|
||||
@panorama.oy = tmoy/2
|
||||
@fog.ox = tmox+@map.fog_ox
|
||||
|
||||
@@ -75,8 +75,6 @@ class Spriteset_Map
|
||||
end
|
||||
|
||||
def update
|
||||
# return if @tilemap.disposed?
|
||||
# pbDayNightTint(@tilemap)
|
||||
@@viewport3.tone.set(0,0,0,0)
|
||||
_animationSprite_update
|
||||
for i in 0...@usersprites.length
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
class TilemapLoader
|
||||
def initialize(viewport)
|
||||
@viewport = viewport
|
||||
@tilemap = nil
|
||||
@color = Color.new(0,0,0,0)
|
||||
@tone = Tone.new(0,0,0,0)
|
||||
updateClass
|
||||
end
|
||||
|
||||
def updateClass
|
||||
setClass(CustomTilemap)
|
||||
end
|
||||
|
||||
def setClass(cls)
|
||||
newtilemap = cls.new(@viewport)
|
||||
if @tilemap
|
||||
newtilemap.tileset = @tilemap.tileset
|
||||
newtilemap.map_data = @tilemap.map_data
|
||||
newtilemap.flash_data = @tilemap.flash_data
|
||||
newtilemap.priorities = @tilemap.priorities
|
||||
newtilemap.terrain_tags = @tilemap.terrain_tags
|
||||
newtilemap.visible = @tilemap.visible
|
||||
newtilemap.ox = @tilemap.ox
|
||||
newtilemap.oy = @tilemap.oy
|
||||
for i in 0...7
|
||||
newtilemap.autotiles[i] = @tilemap.autotiles[i]
|
||||
end
|
||||
@tilemap.dispose
|
||||
@tilemap = newtilemap
|
||||
newtilemap.update
|
||||
else
|
||||
@tilemap = newtilemap
|
||||
end
|
||||
end
|
||||
|
||||
def dispose; @tilemap.dispose; end
|
||||
def disposed?; @tilemap && @tilemap.disposed?; end
|
||||
def update; @tilemap.update; end
|
||||
def viewport; @tilemap.viewport; end
|
||||
def autotiles; @tilemap.autotiles; end
|
||||
def tileset; @tilemap.tileset; end
|
||||
def tileset=(v); @tilemap.tileset = v; end
|
||||
def map_data; @tilemap.map_data; end
|
||||
def map_data=(v); @tilemap.map_data = v; end
|
||||
def flash_data; @tilemap.flash_data; end
|
||||
def flash_data=(v); @tilemap.flash_data = v; end
|
||||
def priorities; @tilemap.priorities; end
|
||||
def priorities=(v); @tilemap.priorities = v; end
|
||||
def terrain_tags; (@tilemap.terrain_tags rescue nil); end
|
||||
def terrain_tags=(v); (@tilemap.terrain_tags = v rescue nil); end
|
||||
def visible; @tilemap.visible; end
|
||||
def visible=(v); @tilemap.visible = v; end
|
||||
def tone; (@tilemap.tone rescue @tone); end
|
||||
def tone=(value); (@tilemap.tone = value rescue nil); end
|
||||
def ox; @tilemap.ox; end
|
||||
def ox=(v); @tilemap.ox = v; end
|
||||
def oy; @tilemap.oy; end
|
||||
def oy=(v); @tilemap.oy = v; end
|
||||
end
|
||||
@@ -1,47 +1,27 @@
|
||||
# NOTES
|
||||
# - @tiles has the extra tile hanging off the left/top of the screen, because
|
||||
# the pixel offset values are positive and added to the coordinates.
|
||||
|
||||
# - An alternative to rearranging @tiles in def check_if_screen_moved would
|
||||
# be to have extra variables that determine how much the @tiles array has
|
||||
# wrapped around (e.g. 1 means the tile sprites should be 1 tile further right
|
||||
# or down than their indices in the array would suggest). This would be more
|
||||
# convenient if I also have an array of x/y/layer triplets marking tile
|
||||
# sprites using autotiles with 2+ frames.
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class TilemapRenderer
|
||||
attr_reader :tilesets
|
||||
attr_reader :autotiles
|
||||
attr_reader :graphics_width
|
||||
attr_reader :graphics_height
|
||||
attr_accessor :tone
|
||||
attr_accessor :color
|
||||
attr_reader :viewport
|
||||
# TODO: ox, oy and visible don't do anything. Should they?
|
||||
attr_accessor :ox
|
||||
attr_accessor :oy
|
||||
attr_accessor :visible
|
||||
attr_accessor :ox # Does nothing
|
||||
attr_accessor :oy # Does nothing
|
||||
attr_accessor :visible # Does nothing
|
||||
|
||||
DISPLAY_TILE_WIDTH = Game_Map::TILE_WIDTH rescue 32
|
||||
DISPLAY_TILE_HEIGHT = Game_Map::TILE_HEIGHT rescue 32
|
||||
SOURCE_TILE_WIDTH = 32
|
||||
SOURCE_TILE_HEIGHT = 32
|
||||
|
||||
# If an autotile's filename ends with [x], its frame duration will be x/20
|
||||
# seconds instead.
|
||||
AUTOTILE_FRAME_DURATION = 5 # In 1/20ths of a second
|
||||
|
||||
TILESET_TILES_PER_ROW = 8
|
||||
AUTOTILES_COUNT = 8 # Counting the blank tile as an autotile
|
||||
TILES_PER_AUTOTILE = 48
|
||||
TILESET_START_ID = AUTOTILES_COUNT * TILES_PER_AUTOTILE
|
||||
|
||||
# TODO: Flash duration is hardcoded to 0.05 seconds per "frame". However, this
|
||||
# kind of flash is unused, but it should be supported anyway.
|
||||
FLASH_OPACITY = [100, 90, 80, 70, 80, 90]
|
||||
# If an autotile's filename ends with "[x]", its frame duration will be x/20
|
||||
# seconds instead.
|
||||
AUTOTILE_FRAME_DURATION = 5 # In 1/20ths of a second
|
||||
|
||||
#=============================================================================
|
||||
#
|
||||
@@ -77,7 +57,7 @@ class TilemapRenderer
|
||||
bitmap = pbGetTileset(filename)
|
||||
@bitmap_wraps[filename] = false
|
||||
if bitmap.mega?
|
||||
self[filename] = TileWrap::wrapTileset(bitmap)
|
||||
self[filename] = TilemapRenderer::TilesetWrapper.wrapTileset(bitmap)
|
||||
@bitmap_wraps[filename] = true
|
||||
bitmap.dispose
|
||||
else
|
||||
@@ -263,29 +243,19 @@ class TilemapRenderer
|
||||
def initialize(viewport)
|
||||
@tilesets = TilesetBitmaps.new
|
||||
@autotiles = AutotileBitmaps.new
|
||||
|
||||
@can_query_graphics_size = (Graphics.width != nil rescue false)
|
||||
if @can_query_graphics_size
|
||||
@graphics_width = Graphics.width
|
||||
@graphics_height = Graphics.height
|
||||
else
|
||||
@graphics_width = 640
|
||||
@graphics_height = 480
|
||||
end
|
||||
|
||||
@tiles_horizontal_count = (@graphics_width.to_f / DISPLAY_TILE_WIDTH).ceil + 1
|
||||
@tiles_vertical_count = (@graphics_height.to_f / DISPLAY_TILE_HEIGHT).ceil + 1
|
||||
|
||||
@tiles_horizontal_count = (Graphics.width.to_f / DISPLAY_TILE_WIDTH).ceil + 1
|
||||
@tiles_vertical_count = (Graphics.height.to_f / DISPLAY_TILE_HEIGHT).ceil + 1
|
||||
@tone = Tone.new(0, 0, 0, 0)
|
||||
@old_tone = Tone.new(0, 0, 0, 0)
|
||||
@color = Color.new(0, 0, 0, 0)
|
||||
@old_color = Color.new(0, 0, 0, 0)
|
||||
|
||||
@self_viewport = Viewport.new(0, 0, graphics_width, graphics_height)
|
||||
@self_viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
|
||||
@viewport = (viewport) ? viewport : @self_viewport
|
||||
@old_viewport_ox = 0
|
||||
@old_viewport_oy = 0
|
||||
|
||||
# NOTE: The extra tiles horizontally/vertically hang off the left and top
|
||||
# edges of the screen, because the pixel_offset values are positive
|
||||
# and are added to the tile sprite coordinates.
|
||||
@tiles = []
|
||||
@tiles_horizontal_count.times do |i|
|
||||
@tiles[i] = []
|
||||
@@ -293,24 +263,14 @@ class TilemapRenderer
|
||||
@tiles[i][j] = Array.new(3) { TileSprite.new(@viewport) }
|
||||
end
|
||||
end
|
||||
|
||||
@current_map_id = 0
|
||||
@tile_offset_x = 0
|
||||
@tile_offset_y = 0
|
||||
@pixel_offset_x = 0
|
||||
@pixel_offset_y = 0
|
||||
|
||||
@ox = 0 # Bitmap Offsets
|
||||
@oy = 0 # Bitmap Offsets
|
||||
|
||||
@ox = 0
|
||||
@oy = 0
|
||||
@visible = true
|
||||
|
||||
@flash = nil
|
||||
@oxFlash = 0
|
||||
@oyFlash = 0
|
||||
@flashChanged = false
|
||||
@firsttimeflash = true
|
||||
|
||||
@disposed = false
|
||||
end
|
||||
|
||||
@@ -321,12 +281,6 @@ class TilemapRenderer
|
||||
coord.each { |tile| tile.dispose }
|
||||
end
|
||||
end
|
||||
if @flash
|
||||
@flash.bitmap.dispose if !@flash.disposed?
|
||||
@flash.bitmap = nil if !@flash.disposed?
|
||||
@flash.dispose
|
||||
@flash = nil
|
||||
end
|
||||
@tilesets.bitmaps.each_value { |bitmap| bitmap.dispose }
|
||||
@autotiles.bitmaps.each_value { |bitmap| bitmap.dispose }
|
||||
@self_viewport.dispose
|
||||
@@ -358,87 +312,7 @@ class TilemapRenderer
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# TODO: Flash stuff, including usage of flash_data.
|
||||
def refresh_flash
|
||||
if @flash_data && !@flash
|
||||
@flash = TileSprite.new(viewport)
|
||||
@flash.visible = true
|
||||
@flash.z = 1
|
||||
@flash.tone = tone
|
||||
@flash.color = color
|
||||
@flash.blend_type = 1
|
||||
@flash.bitmap = Bitmap.new([graphics_width * 2, 1].max, [graphics_height * 2, 1].max)
|
||||
@firsttimeflash = true
|
||||
elsif !@flash_data && @flash
|
||||
@flash.bitmap.dispose if @flash.bitmap
|
||||
@flash.dispose
|
||||
@flash = nil
|
||||
@firsttimeflash = false
|
||||
end
|
||||
end
|
||||
|
||||
def refreshFlashSprite
|
||||
return if !@flash || @flash_data.nil?
|
||||
ptX = @ox-@oxFlash
|
||||
ptY = @oy-@oyFlash
|
||||
if !@firsttimeflash &&
|
||||
ptX>=0 && ptX+@viewport.rect.width<=@flash.bitmap.width &&
|
||||
ptY>=0 && ptY+@viewport.rect.height<=@flash.bitmap.height
|
||||
@flash.ox = 0
|
||||
@flash.oy = 0
|
||||
@flash.src_rect.set(ptX.round,ptY.round,
|
||||
@viewport.rect.width,@viewport.rect.height)
|
||||
return
|
||||
end
|
||||
width = @flash.bitmap.width
|
||||
height = @flash.bitmap.height
|
||||
bitmap = @flash.bitmap
|
||||
ysize = @map_data.ysize
|
||||
xsize = @map_data.xsize
|
||||
@firsttimeflash = false
|
||||
@oxFlash = @ox-(width>>2)
|
||||
@oyFlash = @oy-(height>>2)
|
||||
@flash.ox = 0
|
||||
@flash.oy = 0
|
||||
@flash.src_rect.set(width>>2,height>>2,
|
||||
@viewport.rect.width,@viewport.rect.height)
|
||||
@flash.bitmap.clear
|
||||
@oxFlash = @oxFlash.floor
|
||||
@oyFlash = @oyFlash.floor
|
||||
xStart = @oxFlash / DISPLAY_TILE_WIDTH
|
||||
xStart = 0 if xStart<0
|
||||
yStart = @oyFlash / DISPLAY_TILE_HEIGHT
|
||||
yStart = 0 if yStart<0
|
||||
xEnd = xStart + (width / DISPLAY_TILE_WIDTH) + 1
|
||||
yEnd = yStart + (height / DISPLAY_TILE_HEIGHT) + 1
|
||||
xEnd = xsize if xEnd>=xsize
|
||||
yEnd = ysize if yEnd>=ysize
|
||||
if xStart<xEnd && yStart<yEnd
|
||||
yrange = yStart...yEnd
|
||||
xrange = xStart...xEnd
|
||||
tmpcolor = Color.new(0,0,0,0)
|
||||
for y in yrange
|
||||
ypos = (y * DISPLAY_TILE_HEIGHT) - @oyFlash
|
||||
for x in xrange
|
||||
xpos = (x * DISPLAY_TILE_WIDTH) - @oxFlash
|
||||
id = @flash_data[x, y, 0]
|
||||
r = (id>>8)&15
|
||||
g = (id>>4)&15
|
||||
b = (id)&15
|
||||
tmpcolor.set(r<<4,g<<4,b<<4)
|
||||
bitmap.fill_rect(xpos, ypos, DISPLAY_TILE_WIDTH, DISPLAY_TILE_HEIGHT, tmpcolor)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
|
||||
def refresh(autotiles = false)
|
||||
refreshFlashSprite
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
def refresh; end
|
||||
|
||||
def refresh_tile_bitmap(tile, map, tile_id)
|
||||
if tile_id < TILES_PER_AUTOTILE
|
||||
@@ -519,7 +393,6 @@ class TilemapRenderer
|
||||
@current_map_id = $game_map.map_id
|
||||
ret = true
|
||||
end
|
||||
|
||||
# Check for tile movement
|
||||
current_map_display_x = ($game_map.display_x.to_f / Game_Map::X_SUBPIXELS).round
|
||||
current_map_display_y = ($game_map.display_y.to_f / Game_Map::Y_SUBPIXELS).round
|
||||
@@ -572,7 +445,6 @@ class TilemapRenderer
|
||||
@screen_moved_vertically = true
|
||||
@tile_offset_y = new_tile_offset_y
|
||||
end
|
||||
|
||||
# Check for pixel movement
|
||||
new_pixel_offset_x = current_map_display_x % SOURCE_TILE_WIDTH
|
||||
new_pixel_offset_y = current_map_display_y % SOURCE_TILE_HEIGHT
|
||||
@@ -591,16 +463,8 @@ class TilemapRenderer
|
||||
#=============================================================================
|
||||
|
||||
def update
|
||||
# Check if screen was resized
|
||||
# TODO: If it was resized, change how many TileSprites there are.
|
||||
# CustomTilemap only uses this for the flash graphic.
|
||||
if @can_query_graphics_size
|
||||
@graphics_width = Graphics.width
|
||||
@graphics_height = Graphics.height
|
||||
end
|
||||
# Update tone
|
||||
if @old_tone != @tone
|
||||
@flash.tone = @tone if @flash
|
||||
@tiles.each do |col|
|
||||
col.each do |coord|
|
||||
coord.each { |tile| tile.tone = @tone }
|
||||
@@ -610,7 +474,6 @@ class TilemapRenderer
|
||||
end
|
||||
# Update color
|
||||
if @old_color != @color
|
||||
@flash.color = @color if @flash
|
||||
@tiles.each do |col|
|
||||
col.each do |coord|
|
||||
coord.each { |tile| tile.color = @tone }
|
||||
@@ -621,30 +484,22 @@ class TilemapRenderer
|
||||
# Recalculate autotile frames
|
||||
@tilesets.update
|
||||
@autotiles.update
|
||||
|
||||
# Update flash
|
||||
refresh_flash if @flashChanged
|
||||
@flash.opacity = FLASH_OPACITY[(Graphics.frame_count / 2) % 6] if @flash
|
||||
|
||||
do_full_refresh = false
|
||||
if @viewport.ox != @old_viewport_ox || @viewport.oy != @old_viewport_oy
|
||||
@old_viewport_ox = @viewport.ox
|
||||
@old_viewport_oy = @viewport.oy
|
||||
do_full_refresh = true
|
||||
end
|
||||
|
||||
# Check whether the screen has moved since the last update
|
||||
@screen_moved = false
|
||||
@screen_moved_vertically = false
|
||||
do_full_refresh = true if check_if_screen_moved
|
||||
|
||||
# Update all tile sprites
|
||||
visited = []
|
||||
@tiles_horizontal_count.times do |i|
|
||||
visited[i] = []
|
||||
@tiles_vertical_count.times { |j| visited[i][j] = false }
|
||||
end
|
||||
|
||||
$MapFactory.maps.each do |map|
|
||||
# Calculate x/y ranges of tile sprites that represent them
|
||||
map_display_x = (map.display_x.to_f / Game_Map::X_SUBPIXELS).round
|
||||
@@ -658,7 +513,6 @@ class TilemapRenderer
|
||||
end_y = @tiles_vertical_count - 1
|
||||
end_y = [end_y, map.height - map_display_y_tile - 1].min
|
||||
next if start_x > end_x || start_y > end_y || end_x < 0 || end_y < 0
|
||||
|
||||
# Update all tile sprites representing this map
|
||||
for i in start_x..end_x
|
||||
tile_x = i + map_display_x_tile
|
||||
@@ -681,7 +535,6 @@ class TilemapRenderer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Clear all unvisited tile sprites
|
||||
@tiles.each_with_index do |col, i|
|
||||
col.each_with_index do |coord, j|
|
||||
@@ -693,7 +546,6 @@ class TilemapRenderer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@autotiles.changed = false
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
96
Data/Scripts/006_Map renderer/002_TilesetWrapper.rb
Normal file
96
Data/Scripts/006_Map renderer/002_TilesetWrapper.rb
Normal file
@@ -0,0 +1,96 @@
|
||||
#=======================================================================
|
||||
# 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
|
||||
#=======================================================================
|
||||
class TilemapRenderer
|
||||
module TilesetWrapper
|
||||
TILESET_WIDTH = SOURCE_TILE_WIDTH * TILESET_TILES_PER_ROW
|
||||
# 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
|
||||
|
||||
module_function
|
||||
|
||||
def 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 "Tileset 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 do |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)
|
||||
end
|
||||
return bmp
|
||||
end
|
||||
return originalbmp
|
||||
end
|
||||
|
||||
def 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 + src_rect.x.clamp(0, TILESET_WIDTH)
|
||||
ret.y = src_rect.y % MAX_TEX_SIZE
|
||||
ret.width = src_rect.width.clamp(0, TILESET_WIDTH - src_rect.x)
|
||||
ret.height = src_rect.height.clamp(0, MAX_TEX_SIZE)
|
||||
return ret
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def 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
|
||||
# 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]))
|
||||
else
|
||||
dest.blt(destX, destY, src, srcrect_mod)
|
||||
end
|
||||
end
|
||||
|
||||
def 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
|
||||
end
|
||||
@@ -1,24 +1,12 @@
|
||||
class TilemapRenderer
|
||||
module AutotileExpander
|
||||
MAX_TEXTURE_SIZE = (Bitmap.max_size / 1024) * 1024
|
||||
AUTOTILE_PATTERNS = [
|
||||
[ [27, 28, 33, 34], [ 5, 28, 33, 34], [27, 6, 33, 34], [ 5, 6, 33, 34],
|
||||
[27, 28, 33, 12], [ 5, 28, 33, 12], [27, 6, 33, 12], [ 5, 6, 33, 12] ],
|
||||
[ [27, 28, 11, 34], [ 5, 28, 11, 34], [27, 6, 11, 34], [ 5, 6, 11, 34],
|
||||
[27, 28, 11, 12], [ 5, 28, 11, 12], [27, 6, 11, 12], [ 5, 6, 11, 12] ],
|
||||
[ [25, 26, 31, 32], [25, 6, 31, 32], [25, 26, 31, 12], [25, 6, 31, 12],
|
||||
[15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],
|
||||
[ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
|
||||
[39, 40, 45, 46], [ 5, 40, 45, 46], [39, 6, 45, 46], [ 5, 6, 45, 46] ],
|
||||
[ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
|
||||
[17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],
|
||||
[ [37, 38, 43, 44], [37, 6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
|
||||
[37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1, 2, 7, 8] ]
|
||||
]
|
||||
|
||||
module_function
|
||||
|
||||
# This doesn't allow for cache sizes smaller than 768, but if that applies
|
||||
# to you, you've got bigger problems.
|
||||
def self.expand(bitmap)
|
||||
def expand(bitmap)
|
||||
return bitmap if bitmap.height == SOURCE_TILE_HEIGHT
|
||||
expanded_format = (bitmap.height == SOURCE_TILE_HEIGHT * 6)
|
||||
wrap = false
|
||||
@@ -30,7 +18,7 @@ class TilemapRenderer
|
||||
TILES_PER_AUTOTILE * SOURCE_TILE_HEIGHT / (wrap ? 2 : 1))
|
||||
rect = Rect.new(0, 0, SOURCE_TILE_WIDTH / 2, SOURCE_TILE_HEIGHT / 2)
|
||||
TILES_PER_AUTOTILE.times do |id|
|
||||
pattern = AUTOTILE_PATTERNS[id >> 3][id % TILESET_TILES_PER_ROW]
|
||||
pattern = TileDrawingHelper::AUTOTILE_PATTERNS[id >> 3][id % TILESET_TILES_PER_ROW]
|
||||
wrap_offset_x = (wrap && id >= TILES_PER_AUTOTILE / 2) ? SOURCE_TILE_WIDTH : 0
|
||||
wrap_offset_y = (wrap && id >= TILES_PER_AUTOTILE / 2) ? (TILES_PER_AUTOTILE / 2) * SOURCE_TILE_HEIGHT : 0
|
||||
frames_count.times do |frame|
|
||||
@@ -2,7 +2,7 @@ class TileDrawingHelper
|
||||
attr_accessor :tileset
|
||||
attr_accessor :autotiles
|
||||
|
||||
Autotiles = [
|
||||
AUTOTILE_PATTERNS = [
|
||||
[ [27, 28, 33, 34], [ 5, 28, 33, 34], [27, 6, 33, 34], [ 5, 6, 33, 34],
|
||||
[27, 28, 33, 12], [ 5, 28, 33, 12], [27, 6, 33, 12], [ 5, 6, 33, 12] ],
|
||||
[ [27, 28, 11, 34], [ 5, 28, 11, 34], [27, 6, 11, 34], [ 5, 6, 11, 34],
|
||||
@@ -18,7 +18,7 @@ class TileDrawingHelper
|
||||
]
|
||||
|
||||
# converts neighbors returned from tableNeighbors to tile indexes
|
||||
NeighborsToTiles = [
|
||||
NEIGHBORS_TO_AUTOTILE_INDEX = [
|
||||
46, 44, 46, 44, 43, 41, 43, 40, 46, 44, 46, 44, 43, 41, 43, 40,
|
||||
42, 32, 42, 32, 35, 19, 35, 18, 42, 32, 42, 32, 34, 17, 34, 16,
|
||||
46, 44, 46, 44, 43, 41, 43, 40, 46, 44, 46, 44, 43, 41, 43, 40,
|
||||
@@ -68,7 +68,7 @@ class TileDrawingHelper
|
||||
|
||||
def initialize(tileset, autotiles)
|
||||
if tileset.mega?
|
||||
@tileset = TileWrap::wrapTileset(tileset)
|
||||
@tileset = TilemapRenderer::TilesetWrapper.wrapTileset(tileset)
|
||||
tileset.dispose
|
||||
@shouldWrap = true
|
||||
else
|
||||
@@ -100,7 +100,7 @@ class TileDrawingHelper
|
||||
else
|
||||
anim = frame * 96
|
||||
id %= 48
|
||||
tiles = TileDrawingHelper::Autotiles[id >> 3][id & 7]
|
||||
tiles = AUTOTILE_PATTERNS[id >> 3][id & 7]
|
||||
src = Rect.new(0, 0, 0, 0)
|
||||
for i in 0...4
|
||||
tile_position = tiles[i] - 1
|
||||
@@ -114,7 +114,7 @@ class TileDrawingHelper
|
||||
def bltSmallRegularTile(bitmap,x,y,cxTile,cyTile,id)
|
||||
return if id < 384 || !@tileset || @tileset.disposed?
|
||||
rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32)
|
||||
rect = TileWrap::getWrappedRect(rect) if @shouldWrap
|
||||
rect = TilemapRenderer::TilesetWrapper.getWrappedRect(rect) if @shouldWrap
|
||||
bitmap.stretch_blt(Rect.new(x, y, cxTile, cyTile), @tileset, rect)
|
||||
end
|
||||
|
||||
@@ -176,7 +176,7 @@ def bltMinimapAutotile(dstBitmap,x,y,srcBitmap,id)
|
||||
anim=0
|
||||
cxTile=3
|
||||
cyTile=3
|
||||
tiles = TileDrawingHelper::Autotiles[id>>3][id&7]
|
||||
tiles = TileDrawingHelper::AUTOTILE_PATTERNS[id>>3][id&7]
|
||||
src=Rect.new(0,0,0,0)
|
||||
for i in 0...4
|
||||
tile_position = tiles[i] - 1
|
||||
@@ -213,7 +213,7 @@ def getPassabilityMinimap(mapid)
|
||||
passtable[i,j]=pass ? 1 : 0
|
||||
end
|
||||
end
|
||||
neighbors=TileDrawingHelper::NeighborsToTiles
|
||||
neighbors=TileDrawingHelper::NEIGHBORS_TO_AUTOTILE_INDEX
|
||||
for i in 0...map.width
|
||||
for j in 0...map.height
|
||||
if passtable[i,j]==0
|
||||
@@ -1,100 +0,0 @@
|
||||
#=======================================================================
|
||||
# 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
|
||||
@@ -602,7 +602,7 @@ module RandomDungeonGenerator
|
||||
for i in 0...map.width
|
||||
for j in 0...map.height
|
||||
nb = TileDrawingHelper.tableNeighbors(tbl, i, j)
|
||||
tile = TileDrawingHelper::NeighborsToTiles[nb]
|
||||
tile = TileDrawingHelper::NEIGHBORS_TO_AUTOTILE_INDEX[nb]
|
||||
map.data[i, j, 0] = tile + 48 * (tbl[i, j])
|
||||
map.data[i, j, 1] = 0
|
||||
map.data[i, j, 2] = 0
|
||||
|
||||
Reference in New Issue
Block a user