Advertisement
biward

Résolution Ace

Jun 22nd, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.12 KB | None | 0 0
  1. =begin
  2. #===============================================================================
  3.  Title: Unlimited Resolution
  4.  Date: Apr 20, 2014
  5. --------------------------------------------------------------------------------
  6.  ** Change log
  7.  Apr 20, 2014
  8.    - added Kaelan's suggestion for disposing the viewport when done with it
  9.  Nov 6, 2013
  10.    - added some plane modifications to fix parallax images
  11.  Oct 24, 2013
  12.    - Initial release
  13. --------------------------------------------------------------------------------  
  14.  ** Terms of Use
  15.  * Free
  16. --------------------------------------------------------------------------------
  17.  ** Description
  18.  
  19.  This script modifies Graphics.resize_screen to overcome the 640x480 limitation.
  20.  It also includes some code to properly display maps that are smaller than the
  21.  screen size.
  22.  
  23.  Now you can have arbitrarily large game resolutions.
  24.  
  25. --------------------------------------------------------------------------------
  26.  ** Installation
  27.  
  28.  You should place this script above all custom scripts
  29.  
  30. --------------------------------------------------------------------------------
  31.  ** Usage
  32.  
  33.  As usual, simply resize your screen using the script call
  34.  
  35.    Graphics.resize_screen(width, height)
  36.  
  37. --------------------------------------------------------------------------------
  38.  ** Credits
  39.  
  40.  Unknown author for overcoming the 640x480 limitation
  41.  Lantier, from RMW forums for posting the snippet above
  42.  Esrever for handling the viewport
  43.  Jet, for the custom Graphics code
  44.  
  45. #===============================================================================
  46. =end
  47. $imported = {} if $imported.nil?
  48. $imported["TH_UnlimitedResolution"] = true
  49. #===============================================================================
  50. # ** Configuration
  51. #===============================================================================
  52. class << SceneManager
  53.  
  54.   alias resolution_run run
  55.   def run(*args, &block)
  56.     Graphics.ensure_sprite
  57.     resolution_run(*args, &block)
  58.   end
  59. end
  60.  
  61. module Graphics
  62.  
  63.   @@super_sprite = Sprite.new
  64.   @@super_sprite.z = (2 ** (0.size * 8 - 2) - 1)
  65.  
  66.   class << self
  67.     alias :th_large_screen_resize_screen :resize_screen
  68.    
  69.     def freeze(*args, &block)
  70.       @@super_sprite.bitmap = snap_to_bitmap
  71.     end
  72.    
  73.     def transition(time = 10, filename = nil, vague = nil)
  74.       if filename
  75.         @@super_sprite.bitmap = Bitmap.new(filename)
  76.       end
  77.       @@super_sprite.opacity = 255
  78.       incs = 255.0 / time
  79.       time.times do |i|
  80.         @@super_sprite.opacity = 255.0 - incs * i
  81.         Graphics.wait(1)
  82.       end
  83.       @@super_sprite.bitmap.dispose if @@super_sprite.bitmap
  84.       reform_sprite_bitmap
  85.       Graphics.brightness = 255
  86.     end
  87.    
  88.     def reform_sprite_bitmap
  89.       @@super_sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  90.       @@super_sprite.bitmap.fill_rect(@@super_sprite.bitmap.rect, Color.new(0, 0, 0, 255))
  91.     end
  92.    
  93.     def fadeout(frames)
  94.       incs = 255.0 / frames
  95.       frames.times do |i|
  96.         i += 1
  97.         Graphics.brightness = 255 - incs * i
  98.         Graphics.wait(1)
  99.       end
  100.     end
  101.    
  102.     def fadein(frames)
  103.       incs = 255.0 / frames
  104.       frames.times do |i|
  105.         Graphics.brightness = incs * i
  106.         Graphics.wait(1)
  107.       end
  108.     end
  109.  
  110.     def brightness=(i)
  111.       @@super_sprite.opacity = 255.0 - i
  112.     end
  113.    
  114.     def brightness
  115.       255 - @@super_sprite.opacity
  116.     end
  117.    
  118.     def ensure_sprite
  119.       if @@super_sprite.disposed?
  120.         @@super_sprite = Sprite.new
  121.         @@super_sprite.z = (2 ** (0.size * 8 - 2) - 1)
  122.         reform_sprite_bitmap
  123.       end
  124.     end
  125.   end
  126.  
  127.   #-----------------------------------------------------------------------------
  128.   # Unknown Scripter. Copied from http://pastebin.com/sM2MNJZj
  129.   #-----------------------------------------------------------------------------
  130.   def self.resize_screen(width, height)
  131.     wt, ht = width.divmod(32), height.divmod(32)
  132.     #wt.last + ht.last == 0 || fail('Incorrect width or height')
  133.     wh = -> w, h, off = 0 { [w + off, h + off].pack('l2').scan /.{4}/ }
  134.     w, h = wh.(width, height)
  135.     ww, hh = wh.(width, height, 32)
  136.     www, hhh = wh.(wt.first.succ, ht.first.succ)
  137.     base = 0x10000000  # fixed?
  138.     mod = -> adr, val { DL::CPtr.new(base + adr)[0, val.size] = val }
  139.     mod.(0x195F, "\x90" * 5)  # ???
  140.     mod.(0x19A4, h)
  141.     mod.(0x19A9, w)
  142.     mod.(0x1A56, h)
  143.     mod.(0x1A5B, w)
  144.     mod.(0x20F6, w)
  145.     mod.(0x20FF, w)
  146.     mod.(0x2106, h)
  147.     mod.(0x210F, h)
  148.     # speed up y?
  149.     #mod.(0x1C5E3, h)
  150.     #mod.(0x1C5E8, w)
  151.     zero = [0].pack ?l
  152.     mod.(0x1C5E3, zero)
  153.     mod.(0x1C5E8, zero)
  154.     mod.(0x1F477, h)
  155.     mod.(0x1F47C, w)
  156.     mod.(0x211FF, hh)
  157.     mod.(0x21204, ww)
  158.     mod.(0x21D7D, hhh[0])
  159.     mod.(0x21E01, www[0])
  160.     mod.(0x10DEA8, h)
  161.     mod.(0x10DEAD, w)
  162.     mod.(0x10DEDF, h)
  163.     mod.(0x10DEF0, w)
  164.     mod.(0x10DF14, h)
  165.     mod.(0x10DF18, w)
  166.     mod.(0x10DF48, h)
  167.     mod.(0x10DF4C, w)
  168.     mod.(0x10E6A7, w)
  169.     mod.(0x10E6C3, h)
  170.     mod.(0x10EEA9, w)
  171.     mod.(0x10EEB9, h)
  172.     th_large_screen_resize_screen(width, height)
  173.   end
  174. end
  175.  
  176. #===============================================================================
  177. # Esrever's code from
  178. # http://www.rpgmakervxace.net/topic/100-any-chance-of-higher-resolution-or-larger-sprite-support/page-2#entry7997
  179. #===============================================================================
  180. class Game_Map
  181.  
  182.   #--------------------------------------------------------------------------
  183.   # overwrite method: scroll_down
  184.   #--------------------------------------------------------------------------
  185.   def scroll_down(distance)
  186.     if loop_vertical?
  187.       @display_y += distance
  188.       @display_y %= @map.height * 256
  189.       @parallax_y += distance
  190.     else
  191.       last_y = @display_y
  192.       dh = Graphics.height > height * 32 ? height : screen_tile_y
  193.       @display_y = [@display_y + distance, height - dh].min
  194.       @parallax_y += @display_y - last_y
  195.     end
  196.   end
  197.  
  198.   #--------------------------------------------------------------------------
  199.   # overwrite method: scroll_right
  200.   #--------------------------------------------------------------------------
  201.   def scroll_right(distance)
  202.     if loop_horizontal?
  203.       @display_x += distance
  204.       @display_x %= @map.width * 256
  205.       @parallax_x += distance
  206.     else
  207.       last_x = @display_x
  208.       dw = Graphics.width > width * 32 ? width : screen_tile_x
  209.       @display_x = [@display_x + distance, width - dw].min
  210.       @parallax_x += @display_x - last_x
  211.     end
  212.   end
  213.  
  214. end # Game_Map
  215.  
  216. #==============================================================================
  217. # â–  Spriteset_Map
  218. #==============================================================================
  219.  
  220. class Spriteset_Map
  221.  
  222.   #--------------------------------------------------------------------------
  223.   # overwrite method: create_viewports
  224.   #--------------------------------------------------------------------------
  225.   def create_viewports
  226.     if Graphics.width > $game_map.width * 32 && !$game_map.loop_horizontal?
  227.       dx = (Graphics.width - $game_map.width * 32) / 2
  228.     else
  229.       dx = 0
  230.     end
  231.     dw = [Graphics.width, $game_map.width * 32].min
  232.     dw = Graphics.width if $game_map.loop_horizontal?
  233.     if Graphics.height > $game_map.height * 32 && !$game_map.loop_vertical?
  234.       dy = (Graphics.height - $game_map.height * 32) / 2
  235.     else
  236.       dy = 0
  237.     end
  238.     dh = [Graphics.height, $game_map.height * 32].min
  239.     dh = Graphics.height if $game_map.loop_vertical?
  240.     @viewport1 = Viewport.new(dx, dy, dw, dh)
  241.     @viewport2 = Viewport.new(dx, dy, dw, dh)
  242.     @viewport3 = Viewport.new(dx, dy, dw, dh)
  243.     @viewport2.z = 50
  244.     @viewport3.z = 100
  245.   end
  246.  
  247.   #--------------------------------------------------------------------------
  248.   # new method: update_viewport_sizes
  249.   #--------------------------------------------------------------------------
  250.   def update_viewport_sizes
  251.     if Graphics.width > $game_map.width * 32 && !$game_map.loop_horizontal?
  252.       dx = (Graphics.width - $game_map.width * 32) / 2
  253.     else
  254.       dx = 0
  255.     end
  256.     dw = [Graphics.width, $game_map.width * 32].min
  257.     dw = Graphics.width if $game_map.loop_horizontal?
  258.     if Graphics.height > $game_map.height * 32 && !$game_map.loop_vertical?
  259.       dy = (Graphics.height - $game_map.height * 32) / 2
  260.     else
  261.       dy = 0
  262.     end
  263.     dh = [Graphics.height, $game_map.height * 32].min
  264.     dh = Graphics.height if $game_map.loop_vertical?
  265.     rect = Rect.new(dx, dy, dw, dh)
  266.     for viewport in [@viewport1, @viewport2, @viewport3]
  267.       viewport.rect = rect
  268.     end
  269.   end
  270.  
  271. end # Spriteset_Map
  272.  
  273. #-------------------------------------------------------------------------------
  274. # FenixFyre's custom Plane, simply drawing a sprite. Needs to do something about
  275. # the y-axis
  276. #-------------------------------------------------------------------------------
  277. class Plane
  278.   attr_reader :ox, :oy
  279.  
  280.   alias :th_unlimited_resolution_initialize :initialize
  281.   def initialize(viewport = nil)
  282.     th_unlimited_resolution_initialize(viewport)
  283.     @sprite = Sprite.new(viewport)
  284.     @bitmap = nil
  285.     @ox = 0
  286.     @oy = 0
  287.   end
  288.    
  289.     alias :th_unlimited_resolution_dispose :dispose
  290.   def dispose
  291.     th_unlimited_resolution_dispose
  292.     @sprite.dispose if @sprite
  293.     @sprite = nil
  294.   end
  295.  
  296.   def method_missing(symbol, *args)
  297.     @sprite.method(symbol).call(*args)
  298.   end
  299.  
  300.   def bitmap=(bitmap)
  301.     @bitmap = bitmap
  302.     refresh
  303.   end
  304.  
  305.   def bitmap
  306.     @sprite.bitmap
  307.   end
  308.  
  309.   def ox=(ox)
  310.     w = @sprite.viewport != nil ? @sprite.viewport.rect.width : Graphics.width
  311.     @ox = ox % w
  312.     @sprite.ox = @ox
  313.   end
  314.  
  315.   def oy=(oy)
  316.     h = @sprite.viewport != nil ? @sprite.viewport.rect.height : Graphics.height
  317.     @oy = oy % h
  318.     @sprite.oy = @oy
  319.   end
  320.  
  321.   def refresh
  322.     return if @bitmap.nil?
  323.     w = @sprite.viewport != nil ? @sprite.viewport.rect.width : Graphics.width
  324.     h = @sprite.viewport != nil ? @sprite.viewport.rect.height : Graphics.height
  325.     if @sprite.bitmap != nil
  326.       @sprite.bitmap.dispose
  327.     end
  328.     @sprite.bitmap = Bitmap.new(w * 2, h * 2)
  329.    
  330.     max_x = w / @bitmap.width
  331.     max_y = h / @bitmap.height
  332.     for x in 0..max_x
  333.       for y in 0..max_y
  334.         @sprite.bitmap.blt(x * @bitmap.width, y * @bitmap.height,
  335.          @bitmap, Rect.new(0, 0, @bitmap.width, @bitmap.height))
  336.       end
  337.     end
  338.     for i in 1...4
  339.       x = i % 2 * w
  340.       y = i / 2 * h
  341.       @sprite.bitmap.blt(x, y, @sprite.bitmap, Rect.new(0, 0, w, h))
  342.     end
  343.   end
  344. end
  345.  
  346. #==============================================================================
  347. # â–  Scene_Map
  348. #==============================================================================
  349.  
  350. class Scene_Map < Scene_Base
  351.  
  352.   #--------------------------------------------------------------------------
  353.   # alias method: post_transfer
  354.   #--------------------------------------------------------------------------
  355.   alias scene_map_post_transfer_ace post_transfer
  356.   def post_transfer
  357.     @spriteset.update_viewport_sizes
  358.     scene_map_post_transfer_ace
  359.   end
  360.  
  361. end # Scene_Map
  362.  
  363.  
  364. Graphics.resize_screen(1280, 736)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement