Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2. # RGSS3 Plane v1.3.1
  3. # FenixFyreX
  4. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  5. # This is a rewrite of RGSS3's Plane class, mainly for use with custom resolution
  6. # alterations of RPG Maker VXAce. This allows Plane to function properly on
  7. # larger resolutions than the hard-coded 640px x 480px in the dll.
  8. #
  9. # It also correctly displays ox and oy offset and such, just like the original.
  10. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  11. # CHANGELOG
  12. #   - Added in caching of plane bitmaps, to stop the lag from persisting.
  13. #   - Fixed potential bug where when the viewport was set, the bitmap would
  14. #     retile incorrectly.
  15. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  16. # To remove any artifacts / conflicts with the original, we alias it then remove
  17. # the original tie.
  18. RGSS3Plane = Plane
  19. Object.send(:remove_const, :Plane)
  20.  
  21. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  22. # Bitmap
  23. #   Saves a bitmap's name, for future reference.
  24. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  25. class Bitmap
  26.     alias fyx_initialize_save_name initialize
  27.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  28.   # initialize
  29.   #   Instantiate a bitmap's name, if given one.
  30.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  31.     def initialize(*argv, &argb)
  32.     @name = ''
  33.         if name = argv.find {|arg| arg.is_a?(String) }
  34.             @name = name
  35.         end
  36.         fyx_initialize_save_name(*argv, &argb)
  37.     end
  38.   attr_reader :name
  39. end
  40.  
  41. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  42. # Cache
  43. #   Add in Plane caching, to speed up processing at the slight cost of memory.
  44. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  45. module Cache
  46.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  47.   # Cache::plane_cache
  48.   #   Convenience method, to not have to type it out in the below methods.
  49.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  50.   def self.plane_cache
  51.     @plane_cache ||= {}
  52.   end
  53.  
  54.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  55.   # Cache::plane
  56.   #   Get a cached plane bitmap.
  57.   #   key : Object  ( most likely an Array e.g. [Rect, String] )
  58.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  59.     def self.plane(key)
  60.     return plane_cache[key]
  61.   end
  62.  
  63.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  64.   # Cache::add_plane
  65.   #   Add a tiled plane bitmap to the cache.
  66.   #   key : Object ( see above )
  67.   #   bmp : Bitmap
  68.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  69.   def self.add_plane(key, bmp)
  70.     plane_cache[key] = bmp
  71.   end
  72.  
  73.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  74.   # Cache::has_plane?
  75.   #   Check for a cached plane bitmap.
  76.   #   key : Object ( see above )
  77.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  78.   def self.has_plane?(key)
  79.     plane_cache[key].is_a?(Bitmap)
  80.   end
  81.  
  82.   class << self; alias clear_b4_fyx_plane_cache clear; end
  83.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  84.   # Cache::clear
  85.   #   See original documentation.
  86.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  87.   def self.clear
  88.     plane_cache.each_value {|v| v.dispose unless v.nil? || v.disposed? }
  89.     plane_cache.clear
  90.     clear_b4_fyx_plane_cache
  91.   end
  92. end
  93.  
  94. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  95. # Plane
  96. #   Tiles a bitmap across either the window rect, or a given viewport's rect.
  97. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  98. class Plane
  99.  
  100.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  101.   # initialize
  102.   #   Setup an allocated instance of Plane.
  103.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  104.   def initialize(v = nil)
  105.     @sprite = Sprite.new(v)
  106.     @bitmap = nil
  107.   end
  108.  
  109.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  110.   # dispose
  111.   #   Free an instance of Plane.
  112.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  113.   def dispose
  114.     @sprite.bitmap.dispose unless bitmap_disposed?
  115.     @sprite.dispose unless disposed?
  116.     return nil
  117.   end
  118.  
  119.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  120.   # bitmap_disposed?
  121.   #   Check whether this instance of Plane's bitmap has been freed.
  122.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  123.   def bitmap_disposed?
  124.     disposed? || @sprite.bitmap.nil? || @sprite.bitmap.disposed?
  125.   end
  126.  
  127.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  128.   # disposed?
  129.   #   Check whether this instance of Plane has been freed.
  130.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  131.   def disposed?
  132.     @sprite.nil? || @sprite.disposed?
  133.   end
  134.  
  135.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  136.   # ox=
  137.   #   Set the offset x of this instance of Plane.
  138.   #   val : Integer
  139.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  140.   def ox=(val)
  141.     @sprite.ox = (val % (@bitmap.nil? ? 1 : @bitmap.width))
  142.   end
  143.  
  144.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  145.   # oy=
  146.   #   Set the offset y of this instance of Plane.
  147.   #   val : Integer
  148.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  149.   def oy=(val)
  150.     @sprite.oy = (val % (@bitmap.nil? ? 1 : @bitmap.height))
  151.   end
  152.  
  153.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  154.   # bitmap
  155.   #   Get the tile bitmap of this instance of Plane.
  156.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  157.   def bitmap
  158.     @bitmap
  159.   end
  160.  
  161.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  162.   # viewport=
  163.   #   Set the viewport, and refresh if the vrect has changed.
  164.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  165.   def viewport=(v)
  166.     r = v.nil? ? Rect.new(0, 0, Graphics.width, Graphics.height) : v.rect
  167.     b = r != vrect
  168.     ret = @sprite.viewport = v
  169.     self.bitmap = @bitmap if b
  170.     return ret
  171.   end
  172.  
  173.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  174.   # bitmap=
  175.   #   Set the tile bitmap of this instance of Plane.
  176.   #   bmp : Bitmap
  177.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  178.   def bitmap=(bmp)
  179.     w, h = vrect.width, vrect.height
  180.    
  181.     nw = bmp.width <= 100 ? 2 : 3
  182.     nh = bmp.height <= 100 ? 2 : 3
  183.    
  184.     dx = [(w / bmp.width).ceil, 1].max * nw
  185.     dy = [(h / bmp.height).ceil, 1].max * nh
  186.  
  187.     bw = dx * bmp.width
  188.     bh = dy * bmp.height
  189.  
  190.     @bitmap = bmp
  191.     key = [vrect.clone, bmp.name]
  192.     if Cache.has_plane?(key)
  193.       @sprite.bitmap = Cache.plane(key)
  194.     else
  195.       @sprite.bitmap = Bitmap.new(bw, bh)
  196.      
  197.       dx.times do |x|
  198.         dy.times do |y|
  199.           @sprite.bitmap.blt(x * bmp.width, y * bmp.height, @bitmap, @bitmap.rect)
  200.         end
  201.       end
  202.       Cache.add_plane(key, @sprite.bitmap)
  203.     end
  204.   end
  205.  
  206.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  207.   # method_missing
  208.   #   Here we let any methods not found in this class be redirected to our
  209.   #   underlying sprite.
  210.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  211.   def method_missing(sym, *argv, &argb)
  212.     if @sprite.respond_to?(sym)
  213.       return @sprite.send(sym, *argv, &argb)
  214.     end
  215.     super(sym, *argv, &argb)
  216.   end
  217.  
  218.   # private methods from here down
  219.   private
  220.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  221.   # vrect
  222.   #   Get the view rect of this instance of Plane, which depends on if the
  223.   #   viewport has been set or not.
  224.   #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  225.   def vrect
  226.     @sprite.viewport.nil? ? Rect.new(0, 0, Graphics.width, Graphics.height) :
  227.     @sprite.viewport.rect
  228.   end
  229. end
  230. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  231. # SCRIPT END
  232. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-