Advertisement
LiTTleDRAgo

[RGSS3] Unlimited Resolution (unedited)

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