SHARE
TWEET

[RMXP] Custom Resolution 0.93

ForeverZer0 May 21st, 2011 269 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #===============================================================================
  2. # Custom Resolution
  3. # Author: ForeverZer0
  4. # Version: 0.93
  5. # Date: 12.18.2010
  6. #===============================================================================
  7. #
  8. # Introduction:
  9. #
  10. #   My goal in creating this script was to create a system that allowed the user
  11. #   to set the screen size to something other than 640 x 480, but not have make
  12. #   huge sacrifices in compatibility and performance. Although the script is
  13. #   not simply Plug-and-Play, it is about as close as one can achieve with a
  14. #   script of this nature.
  15. #
  16. # Instructions:
  17. #
  18. #  - Place the "screenshot.dll" from Fantasist's Transition Pack script, which
  19. #    can be found here: http://www.sendspace.com/file/yjd54h in your game folder
  20. #  - Place this script above main, below default scripts.
  21. #  - In my experience, unchecking "Reduce Screen Flickering" actually helps the
  22. #    screen not to flicker. Open menu with F1 while playing and set this to what
  23. #    you get the best results with.
  24. #
  25. # Features:
  26. #  
  27. #  - Totally re-written Tilemap and Plane class. Both classes were written to
  28. #    display the map across any screen size automatically. The Tilemap class
  29. #    is probably even more efficient than the original, which will help offset
  30. #    any increased lag due to using a larger screen size with more sprites
  31. #    being displayed.
  32. #  - Every possible autotile graphic (48 per autotile) will be cached for the
  33. #    next time that tile is used.
  34. #  - Autotile animation has been made as efficient as possible, with a system
  35. #    that stores their coodinates, but only if they change. This greatly reduces
  36. #    the number of iterations at each update.
  37. #  - System creates an external file to save pre-cached data priorities and
  38. #    autotiles. This will decrease any loading times even more, and only takes a
  39. #    second, depending on the number of maps you have.
  40. #  - User defined autotile animation speed. Can change with script calls.
  41. #  - Automatic re-sizing of Bitmaps and Viewports that are 640 x 480 to the
  42. #    defined resolution, unless explicitely over-ridden in the method call.
  43. #    The graphics themselves will not be resized, but any existing scripts that
  44. #    use the normal screen size will already be configured to display different
  45. #    sizes of graphics for transitions, battlebacks, pictures, fogs, etc.
  46. #  - Option to have a log file ouput each time the game is ran, which can alert
  47. #    you to possible errors with map sizes, etc.
  48. #
  49. # Issues/Bugs/Possible Bugs:
  50. #
  51. #   - Graphic related scripts and your graphics will need to be customized to
  52. #     fit the new screen size, so this script is not for everyone.
  53. #   - The Z-axis for the Plane class, which is used for Fogs and Panoramas has
  54. #     been altered. It is now multiplied by 1000. This will likely be a minor
  55. #     issue for most, since this class is very rarely used except for Fogs and
  56. #     Panoramas, which are already far above and below respectfully.
  57. #   - Normal transitions using graphics cannot be used. With the exception of
  58. #     a standard fade, like that used when no graphic is defined will be used.
  59. #     Aside from that, only special transitions from Transition Pack can be
  60. #     used.
  61. #
  62. #  Credits/Thanks:
  63. #    - ForeverZer0, for script.
  64. #    - Creators of the Transition Pack and Screenshot.dll
  65. #    - Selwyn, for base resolution script
  66. #
  67. #===============================================================================
  68. #                             CONFIGURATION
  69. #===============================================================================
  70.  
  71.   SCREEN = [1024, 576]
  72.   # Define the resolution of the game screen. These values can be anything
  73.   # within reason. Centering, viewports, etc. will all be taken care of, but it
  74.   # is recommended that you use values divisible by 32 for best results.
  75.  
  76.   UPDATE_COUNT = 8
  77.   # Define the number of frames between autotile updates. The lower the number,
  78.   # the faster the animations cycle. This can be changed in-game with the
  79.   # following script call: $game_map.autotile_speed = SPEED
  80.  
  81.   PRE_CACHE_DATA = true
  82.   # The pre-cached file is mandatory for the script to work. As long as this is
  83.   # true, the data will be created each time the game is test-played. This is
  84.   # not always neccessary, only when maps are altered, so you can disable it to
  85.   # help speed up game start-up, and it will use the last created file.
  86.  
  87.   RESOLUTION_LOG = true
  88.   # This will create a log in the Game directory each time the game is ran in
  89.   # DEBUG mode, which will list possible errors with map sizes, etc.
  90.  
  91. #===============================================================================
  92. # ** Resolution
  93. #===============================================================================
  94.  
  95. class Resolution
  96.  
  97.   attr_reader :version
  98.  
  99.   def initialize
  100.     # Define version.
  101.     @version = 0.93
  102.     # Set instance variables for calling basic Win32 functions.
  103.     ini = Win32API.new('kernel32', 'GetPrivateProfileString','PPPPLP', 'L')
  104.     title = "\0" * 256
  105.     ini.call('Game', 'Title', '', title, 256, '.\\Game.ini')
  106.     title.delete!("\0")
  107.     @window = Win32API.new('user32', 'FindWindow', 'PP', 'I').call('RGSS Player', title)
  108.     set_window_long = Win32API.new('user32', 'SetWindowLong', 'LIL', 'L')
  109.     set_window_pos  = Win32API.new('user32', 'SetWindowPos', 'LLIIIII', 'I')
  110.     @metrics         = Win32API.new('user32', 'GetSystemMetrics', 'I', 'I')
  111.     # Set default size, displaying error if size is larger than the hardware.
  112.     default_size = self.size
  113.     if default_size[0] < SCREEN[0] || default_size[1] < SCREEN[1]
  114.       print("\"#{title}\" requires a minimum screen resolution of [#{SCREEN[0]} x #{SCREEN[1]}]\r\n\r\n" +
  115.             "\tYour Resolution: [#{default_size[0]} x #{default_size[1]}]")
  116.       exit
  117.     end
  118.     # Apply resolution change.
  119.     x = (@metrics.call(0) - SCREEN[0]) / 2
  120.     y = (@metrics.call(1) - SCREEN[1]) / 2
  121.     set_window_long.call(@window, -16, 0x14CA0000)
  122.     set_window_pos.call(@window, 0, x, y, SCREEN[0] + 6, SCREEN[1] + 26, 0)
  123.     @window = Win32API.new('user32', 'FindWindow', 'PP', 'I').call('RGSS Player', title)
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   def size
  127.     # Returns the screen size of the machine.
  128.     return [@metrics.call(0), @metrics.call(1)]
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   def snapshot(filename = 'Data/snap', quality = 0)
  132.     # FILENAME =   Filename that the picture will be saved as.
  133.     # FILETYPE =   0 = High Quality   1 = Low Quality
  134.     @screen = Win32API.new('screenshot.dll', 'Screenshot', 'LLLLPLL', '')
  135.     @screen.call(0, 0, SCREEN[0], SCREEN[1], filename, @window, quality)
  136.   end
  137.   #--------------------------------------------------------------------------
  138. end
  139.  
  140. #===============================================================================
  141. # ** Integer
  142. #===============================================================================
  143.  
  144. class Integer
  145.    
  146.   def gcd(num)
  147.     # Returns the greatest common denominator of self and num.
  148.     min, max = self.abs, num.abs
  149.     while min > 0
  150.       tmp = min
  151.       min = max % min
  152.       max = tmp
  153.     end
  154.     return max
  155.   end
  156.  
  157.   def lcm(num)
  158.     # Returns the lowest common multiple of self and num.
  159.     return [self, num].include?(0) ? 0 : (self / self.gcd(num) * num).abs
  160.   end
  161. end
  162.  
  163. #===============================================================================
  164. # ** Graphics
  165. #===============================================================================
  166.  
  167. module Graphics
  168.  
  169.   class << self
  170.     alias zer0_graphics_transition transition
  171.   end
  172.  
  173.   def self.transition(duration = 8, *args)
  174.     # Call default transition if no instance of the resolution is defined.
  175.     if $resolution == nil
  176.       zer0_graphics_transition(duration, *args)
  177.     else
  178.       # Skip this section and instantly transition graphics if duration is 0.
  179.       if duration > 0
  180.         # Take a snapshot of the the screen, overlaying screen with graphic.
  181.         $resolution.snapshot
  182.         zer0_graphics_transition(0)
  183.         # Create screen instance
  184.         sprite = Sprite.new(Viewport.new(0, 0, SCREEN[0], SCREEN[1]))
  185.         sprite.bitmap = Bitmap.new('Data/snap')
  186.         # Use a simple fade if transition is not defined.
  187.         fade = 255 / duration
  188.         duration.times { sprite.opacity -= fade ; update }
  189.         # Dispose sprite and delete snapshot file.
  190.         [sprite, sprite.bitmap].each {|obj| obj.dispose }
  191.         File.delete('Data/snap')
  192.       end
  193.      zer0_graphics_transition(0)
  194.    end
  195.  end
  196. end  
  197.  
  198. #===============================================================================
  199. # ** RPG::Cache
  200. #===============================================================================
  201.  
  202. module RPG::Cache
  203.  
  204.   AUTO_INDEX = [
  205.  
  206.   [27,28,33,34],  [5,28,33,34],  [27,6,33,34],  [5,6,33,34],
  207.   [27,28,33,12],  [5,28,33,12],  [27,6,33,12],  [5,6,33,12],
  208.   [27,28,11,34],  [5,28,11,34],  [27,6,11,34],  [5,6,11,34],
  209.   [27,28,11,12],  [5,28,11,12],  [27,6,11,12],  [5,6,11,12],
  210.   [25,26,31,32],  [25,6,31,32],  [25,26,31,12], [25,6,31,12],
  211.   [15,16,21,22],  [15,16,21,12], [15,16,11,22], [15,16,11,12],
  212.   [29,30,35,36],  [29,30,11,36], [5,30,35,36],  [5,30,11,36],
  213.   [39,40,45,46],  [5,40,45,46],  [39,6,45,46],  [5,6,45,46],
  214.   [25,30,31,36],  [15,16,45,46], [13,14,19,20], [13,14,19,12],
  215.   [17,18,23,24],  [17,18,11,24], [41,42,47,48], [5,42,47,48],
  216.   [37,38,43,44],  [37,6,43,44],  [13,18,19,24], [13,14,43,44],
  217.   [37,42,43,48],  [17,18,47,48], [13,18,43,48], [13,18,43,48]
  218.    
  219.   ]
  220.  
  221.   def self.autotile(filename)
  222.     key = "Graphics/Autotiles/#{filename}"
  223.     if !@cache.include?(key) || @cache[key].disposed?
  224.       # Cache the autotile graphic.
  225.       @cache[key] = (filename == '') ? Bitmap.new(128, 96) : Bitmap.new(key)
  226.       # Cache each configuration of this autotile.
  227.       self.format_autotiles(@cache[key], filename)
  228.     end
  229.     return @cache[key]
  230.   end
  231.  
  232.   def self.format_autotiles(bitmap, filename)
  233.     # Iterate all 48 combinations using the INDEX, and save copy to cache.
  234.     (0...(bitmap.width / 96)).each {|frame|
  235.       # Iterate for each frame in the autotile. (Only for animated ones)
  236.       template = Bitmap.new(256, 192)
  237.       # Create a bitmap to use as a template for creation.
  238.       (0...6).each {|i| (0...8).each {|j| AUTO_INDEX[8*i+j].each {|number|
  239.         number -= 1
  240.         x, y = 16 * (number % 6), 16 * (number / 6)
  241.         rect = Rect.new(x + (frame * 96), y, 16, 16)
  242.         template.blt(32 * j + x % 32, 32 * i + y % 32, bitmap, rect)
  243.       }
  244.       # Use the above created template to create individual tiles.
  245.       index = 8*i+j
  246.       tile = Bitmap.new(32, 32)
  247.       sx, sy = 32 * (index % 8), 32 * (index / 8)
  248.       rect = Rect.new(sx, sy, 32, 32)
  249.       tile.blt(0, 0, template, rect)
  250.       @cache[[filename, index, frame]] = tile
  251.     }}
  252.     # Dispose the template since it will not be used again.
  253.     template.dispose }
  254.   end
  255.  
  256.   def self.load_autotile(name, tile_id, frame = 0)
  257.     # Returns the autotile for the current map with TILE_ID and FRAME.
  258.     return @cache[[name, tile_id % 48, frame]]
  259.   end
  260. end
  261.  
  262. #===============================================================================
  263. # ** Tilemap
  264. #===============================================================================
  265.  
  266. class Tilemap
  267.  
  268.   attr_reader   :map_data, :ox, :oy, :viewport
  269.   attr_accessor :tileset, :autotiles, :priorities
  270.  
  271.   def initialize(viewport)
  272.     # Initialize instance variables to store required data.
  273.     @viewport, @autotiles, @layers, @ox, @oy = viewport, [], [], 0, 0
  274.     # Get priority and autotile data for this tileset from instance of Game_Map.
  275.     @priorities, @animated = $game_map.priorities, $game_map.autotile_data
  276.     # Create a sprite and viewport to use for each priority level.
  277.     (0..5).each {|i|
  278.       @layers[i] = Sprite.new(viewport)
  279.       @layers[i].z = i * 32
  280.     }
  281.   end
  282.    
  283.   def ox=(ox)
  284.     # Set the origin of the X-axis for all the sprites.
  285.     @ox = ox
  286.     @layers.each {|sprite| sprite.ox = @ox }
  287.   end
  288.  
  289.   def oy=(oy)
  290.     # Set the origin of the y-axis for all the sprites.
  291.     @oy = oy
  292.     @layers.each {|sprite| sprite.oy = @oy }
  293.   end
  294.  
  295.   def dispose
  296.     # Dispose all of the sprites and viewports.
  297.     @layers.each {|layer| layer.dispose }
  298.   end
  299.  
  300.   def map_data=(data)
  301.     # Set the map data to an instance variable.
  302.     @map_data = data
  303.     # Clear any sprites' bitmaps if it exists, or create new ones.
  304.     @layers.each_index {|i|
  305.       if @layers[i].bitmap != nil
  306.         # Dispose bitmap and set to nil.
  307.         @layers[i].bitmap = @layers[i].bitmap.dispose
  308.       end
  309.       # Create new bitmap, whose size is the same as the game map.
  310.       @layers[i].bitmap = Bitmap.new($game_map.width*32, $game_map.height*32)
  311.     }
  312.     # Draw bitmaps accordingly.
  313.     refresh
  314.   end
  315.  
  316.   def refresh    
  317.     # Set the animation data from the file if it exists, or create it now.
  318.     @animated = $game_map.autotile_data
  319.     # Iterate through all map layers, starting with the bottom.
  320.     [0,1,2].each {|z| (0...@map_data.ysize).each {|y| (0...@map_data.xsize).each {|x|
  321.       tile_id = @map_data[x, y, z]
  322.       # Go to the next iteration if no bitmap is defined for this tile.
  323.       if tile_id == 0 # No tile
  324.         next
  325.       elsif tile_id < 384 # Autotile
  326.         name = $game_map.autotile_names[(tile_id / 48) - 1]
  327.         bitmap = RPG::Cache.load_autotile(name, tile_id)
  328.       else # Normal Tile
  329.         bitmap = RPG::Cache.tile($game_map.tileset_name, tile_id, 0)
  330.       end
  331.       # Determine what the layer to draw tile, based off priority.
  332.       layer = @priorities[tile_id]
  333.       # Perform a block transfer from the created bitmap to the sprite bitmap.
  334.       @layers[layer].bitmap.blt(x*32, y*32, bitmap, Rect.new(0, 0, 32, 32))
  335.     }}}
  336.   end
  337.  
  338.   def update
  339.     # Update the sprites.
  340.     if Graphics.frame_count % $game_map.autotile_speed == 0
  341.       # Increase current frame of tile by one, looping by width.
  342.       @animated[0].each_index {|i|
  343.         @animated[2][i] = (@animated[2][i] + 1) % @animated[1][i]
  344.         @animated[3][i].each {|data|
  345.           # Gather data using the stored coordinates from the map data.
  346.           tile_id, x, y = @map_data[data[0], data[1], data[2]], data[0], data[1]
  347.           name, layer = @animated[0][i], @priorities[tile_id]
  348.           # Load the next frame of the autotile and set it to the map.
  349.           bitmap = RPG::Cache.load_autotile(name, tile_id, @animated[2][i])
  350.           @layers[layer].bitmap.blt(x*32, y*32, bitmap, Rect.new(0, 0, 32, 32))
  351.         }
  352.       }
  353.     end
  354.   end
  355. end
  356.  
  357. #===============================================================================
  358. # Game_Map
  359. #===============================================================================
  360.  
  361. class Game_Map
  362.  
  363.   attr_reader :tile_size, :autotile_speed, :autotile_data, :priority_data
  364.  
  365.   alias zer0_load_autotile_data_init initialize
  366.   def initialize
  367.     # Load pre-cached data hashes. They will be referenced during setup.
  368.     file = File.open('Data/PreCacheMapData.rxdata', 'rb')
  369.     @cached_priorities = Marshal.load(file)
  370.     @cached_autotiles = Marshal.load(file)
  371.     file.close
  372.     # Call original method.
  373.     zer0_load_autotile_data_init
  374.     # Store the screen dimensions in tiles to save on calculations later.
  375.     @tile_size = [SCREEN[0], SCREEN[1]].collect {|n| (n / 32.0).ceil }
  376.     @autotile_speed = UPDATE_COUNT
  377.   end
  378.  
  379.   alias zer0_map_edge_setup setup
  380.   def setup(map_id)
  381.     @priority_data = @cached_priorities[map_id]
  382.     @autotile_data = @cached_autotiles[map_id]
  383.     # Call original method.
  384.     zer0_map_edge_setup(map_id)
  385.     # Find the displayed area of the map in tiles. No calcualting every step.
  386.     @map_edge = [self.width - @tile_size[0], self.height - @tile_size[1]]
  387.     @map_edge.collect! {|size| size * 128 }
  388.   end
  389.  
  390.   def scroll_down(distance)
  391.     # Find point that the map edge meets the screen edge, using custom size.
  392.     @display_y = [@display_y + distance, @map_edge[1]].min
  393.   end
  394.  
  395.   def scroll_right(distance)
  396.     # Find point that the map edge meets the screen edge, using custom size.
  397.     @display_x = [@display_x + distance, @map_edge[0]].min
  398.   end
  399.  
  400.   def autotile_speed=(speed)
  401.     # Keep the speed above 0 to prevent the ZeroDivision Error.
  402.     @autotile_speed = speed
  403.     @autotile_speed = 1 if @autotile_speed < 1
  404.   end
  405. end
  406.  
  407. #===============================================================================
  408. # ** Game_Character
  409. #===============================================================================
  410.  
  411. class Game_Character
  412.  
  413.   def screen_z(height = 0)
  414.     if @always_on_top
  415.       # Return high Z value if always on top flag is present.
  416.       return 999
  417.     elsif height != nil && height > 32
  418.       # Iterate through map characters to their positions relative to this one.
  419.       characters = $game_map.events.values
  420.       characters += [$game_player] unless self.is_a?(Game_Player)
  421.       # Find and set any character that is one tile above this one.
  422.       above, z = characters.find {|chr| chr.x == @x && chr.y == @y - 1 }, 0
  423.       if above != nil
  424.         # If found, adjust value by this one's Z, and the other's.
  425.         z = (above.screen_z(48) >= 32 ? 33 : 31)
  426.       end
  427.       # Check for Blizz-ABS and adjust coordinates for the pixel-rate.
  428.       if $BlizzABS
  429.         x = ((@x / $game_system.pixel_rate) / 2.0).to_i
  430.         y = ((@y / $game_system.pixel_rate) / 2.0).to_i
  431.         return $game_map.priority_data[x, y] + z
  432.       else
  433.         return $game_map.priority_data[@x, @y] + z
  434.       end
  435.     end
  436.     return 0
  437.   end
  438. end
  439.  
  440. #===============================================================================
  441. # ** Game_Player
  442. #===============================================================================
  443.  
  444. class Game_Player
  445.  
  446.   CENTER_X = ((SCREEN[0] / 2) - 16) * 4    # Center screen x-coordinate * 4
  447.   CENTER_Y = ((SCREEN[1] / 2) - 16) * 4    # Center screen y-coordinate * 4
  448.  
  449.   def center(x, y)
  450.     # Recalculate the screen center based on the new resolution.
  451.     max_x = ($game_map.width - $game_map.tile_size[0]) * 128
  452.     max_y = ($game_map.height - $game_map.tile_size[1]) * 128
  453.     $game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max
  454.     $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max
  455.   end  
  456. end
  457.  
  458. #===============================================================================
  459. # ** Sprite
  460. #===============================================================================
  461.  
  462. class Sprite
  463.  
  464.   alias zer0_sprite_resize_init initialize
  465.   def initialize(view = nil)
  466.     # Unless viewport is defined, use the new default viewport size.
  467.     view = Viewport.new(0, 0, SCREEN[0], SCREEN[1]) if view == nil
  468.     # Call original method.
  469.     zer0_sprite_resize_init(view)
  470.   end
  471. end
  472.  
  473. #===============================================================================
  474. # ** Viewport
  475. #===============================================================================
  476.  
  477. class Viewport
  478.  
  479.   alias zer0_viewport_resize_init initialize
  480.   def initialize(x=0, y=0, width=SCREEN[0], height=SCREEN[1], override=false)
  481.     if x.is_a?(Rect)
  482.       # If first argument is a Rectangle, just use it as the argument.
  483.       zer0_viewport_resize_init(x)
  484.     elsif [x, y, width, height] == [0, 0, 640, 480] && !override
  485.       # Resize fullscreen viewport, unless explicitly overridden.
  486.       zer0_viewport_resize_init(Rect.new(0, 0, SCREEN[0], SCREEN[1]))
  487.     else
  488.       # Call method normally.
  489.       zer0_viewport_resize_init(Rect.new(x, y, width, height))
  490.     end
  491.   end
  492.  
  493.   def resize(*args)
  494.     # Resize the viewport. Can call with (X, Y, WIDTH, HEIGHT) or (RECT).
  495.     self.rect = args[0].is_a?(Rect) ? args[0] : Rect.new(*args)
  496.   end
  497. end
  498.  
  499. #===============================================================================
  500. # ** Bitmap
  501. #===============================================================================
  502.  
  503. class Bitmap
  504.  
  505.   alias zer0_resolution_resize_init initialize
  506.   def initialize(width = 32, height = 32, override = false)
  507.     if width.is_a?(String)
  508.       # Call the filename if the first argument is a String.
  509.       zer0_resolution_resize_init(width)
  510.     elsif [width, height] == [640, 480] && !override
  511.       # Resize fullscreen bitmap unless explicitly overridden.
  512.       zer0_resolution_resize_init(SCREEN[0], SCREEN[1])
  513.     else
  514.       # Call method normally.
  515.       zer0_resolution_resize_init(width, height)
  516.     end
  517.   end
  518. end
  519.  
  520. #===============================================================================
  521. # ** Plane
  522. #===============================================================================
  523.  
  524. class Plane < Sprite
  525.  
  526.   def z=(z)
  527.     # Change the Z value of the viewport, not the sprite.
  528.     super(z * 1000)
  529.   end
  530.  
  531.   def ox=(ox)
  532.     return if @bitmap == nil
  533.     # Have viewport stay in loop on X-axis.
  534.     super(ox % @bitmap.width)
  535.   end
  536.  
  537.   def oy=(oy)
  538.     return if @bitmap == nil
  539.     # Have viewport stay in loop on Y-axis.
  540.     super(oy % @bitmap.height)
  541.   end
  542.  
  543.   def bitmap
  544.     # Return the single bitmap, before it was tiled.
  545.     return @bitmap
  546.   end
  547.  
  548.   def bitmap=(tile)
  549.     @bitmap = tile
  550.     # Calculate the number of tiles it takes to span screen in both directions.
  551.     xx = 1 + (SCREEN[0].to_f / tile.width).ceil
  552.     yy = 1 + (SCREEN[1].to_f / tile.height).ceil
  553.     # Create appropriately sized bitmap, then tile across it with source image.
  554.     plane = Bitmap.new(@bitmap.width * xx, @bitmap.height * yy)
  555.     (0..xx).each {|x| (0..yy).each {|y|
  556.       plane.blt(x * @bitmap.width, y * @bitmap.height, @bitmap, @bitmap.rect)
  557.     }}
  558.     # Set the bitmap to the sprite through its super class (Sprite).
  559.     super(plane)
  560.   end
  561.  
  562.   # Redefine methods dealing with coordinates (defined in super) to do nothing.
  563.   def x; end
  564.   def y; end
  565.   def x=(x); end
  566.   def y=(y); end
  567. end
  568.  
  569. #===============================================================================
  570. # DEBUG Mode
  571. #===============================================================================
  572.  
  573. if $DEBUG
  574.   if PRE_CACHE_DATA
  575.     tilesets = load_data('Data/Tilesets.rxdata')
  576.     maps, priority_data, autotile_data = load_data('Data/MapInfos.rxdata'), {}, {}
  577.     maps.each_key {|map_id|
  578.       map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
  579.       data = map.data
  580.       tileset = tilesets[map.tileset_id]
  581.       priorities = tileset.priorities
  582.       autotiles = tileset.autotile_names.collect {|name| RPG::Cache.autotile(name) }
  583.       animated = [[], [], [], []]
  584.       autotiles.each_index {|i|
  585.         width = autotiles[i].width
  586.         next unless width > 96
  587.         parameters = [tileset.autotile_names[i], width / 96, 0, []]
  588.         [0, 1, 2, 3].each {|j| animated[j].push(parameters[j]) }
  589.       }
  590.       [0, 1, 2].each {|z| (0...data.ysize).each {|y| (0...data.xsize).each {|x|
  591.         tile_id = data[x, y, z]
  592.         next if tile_id == 0
  593.         if tile_id < 384
  594.           name = tileset.autotile_names[(tile_id / 48) - 1]
  595.           index = animated[0].index(name)
  596.           next if index == nil
  597.           above = []
  598.           ((z+1)...data.zsize).each {|zz| above.push(data[x, y, zz]) }
  599.           animated[3][index].push([x, y, z]) if above.all? {|id| id == 0 }
  600.         end
  601.       }}}
  602.       table = Table.new(data.xsize, data.ysize)
  603.       (0...table.xsize).each {|x| (0...table.ysize).each {|y|
  604.         above = [0, 1, 2].collect {|z| data[x, y-1, z] }
  605.         above = above.compact.collect {|p| priorities[p] }
  606.         table[x, y] = above.include?(1) ? 32 : 0
  607.       }}
  608.       priority_data[map_id], autotile_data[map_id] = table, animated
  609.     }
  610.     file = File.open('Data/PreCacheMapData.rxdata', 'wb')
  611.     Marshal.dump(priority_data, file)
  612.     Marshal.dump(autotile_data, file)
  613.     file.close
  614.     RPG::Cache.clear
  615.   end
  616.  
  617.   if RESOLUTION_LOG
  618.     undersize, mapinfo = [], load_data('Data/MapInfos.rxdata')
  619.     file = File.open('Data/PreCacheMapData.rxdata', 'rb')
  620.     cached_data = Marshal.load(file)
  621.     file.close
  622.     # Create a text file and write the header.
  623.     file = File.open('Resolution Log.txt', 'wb')
  624.     file.write("[RESOLUTION LOG]\r\n\r\n")
  625.     time = Time.now.strftime("%x at %I:%M:%S %p")
  626.     file.write("  Logged on #{time}\r\n\r\n")
  627.     lcm = SCREEN[0].lcm(SCREEN[1]).to_f
  628.     aspect = [(lcm / SCREEN[1]), (lcm / SCREEN[0])].collect {|num| num.round }
  629.     file.write("RESOLUTION:\r\n  #{SCREEN[0].to_i} x #{SCREEN[1].to_i}\r\n")
  630.     file.write("ASPECT RATIO:\r\n  #{aspect[0]}:#{aspect[1]}\r\n")
  631.     file.write("MINIMUM MAP SIZE:\r\n  #{(SCREEN[0] / 32).ceil} x #{(SCREEN[1] / 32).ceil}\r\n\r\n")
  632.     file.write("UNDERSIZED MAPS:\r\n")
  633.     mapinfo.keys.each {|key|
  634.       map = load_data(sprintf("Data/Map%03d.rxdata", key))
  635.       next if map.width*32 >= SCREEN[0] && map.height*32 >= SCREEN[1]
  636.       undersize.push(key)
  637.     }
  638.     unless undersize.empty?
  639.       file.write("The following maps are too small for the defined resolution. They should be adjusted to prevent graphical errors.\r\n\r\n")
  640.       undersize.sort.each {|id| file.write("    MAP[#{id}]:  #{mapinfo[id].name}\r\n") }
  641.       file.write("\r\n")
  642.     else
  643.       file.write('    All maps are sized correctly.')
  644.     end
  645.     file.close
  646.   end
  647. end
  648.  
  649. # Call the resolution, setting it to a global variable for plug-ins.
  650. $resolution = Resolution.new
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top