CrowMakerVX

Untitled

Jan 29th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.35 KB | None | 0 0
  1. ################################################################################
  2. #                       TARRIS HOLD ANTILAG
  3. #                          By: Ixfuru
  4. #                  For: Tarris Hold; By: neosky
  5. ################################################################################
  6. module IxTh
  7.   module AntiLag
  8.    
  9.     #===========================================================================
  10.     # THE ISSUES
  11.     #===========================================================================
  12.     # The lag in Tarris Hold is coming from several things.  First of all, there
  13.     # are maps with over 60 events.  Whenever that occurs, there are more
  14.     # events to update than there are frames per second, and it causes lag.  
  15.     # In 'Section 1' below I tackle that issue.
  16.     #
  17.     # Secondly, there is lag because the 'update' method of Scene_Map is just
  18.     # having to do too much.  Also, there are some extraordinarily long checks
  19.     # being made that don't really need to be checked all the time.  I tackled
  20.     # this issue by consolidating the scripts that were using Scene_Map's update
  21.     # method, or were creating instances that slowed things down.  For instance,
  22.     # I found three different call_shop methods, so I turned them all into
  23.     # one method.  Another example is the dart throwing and the overlay map
  24.     # scripts, they both had their own Scene_Map update method, so I created
  25.     # a single Scene_Map update method and put what was required of both into one.
  26.     # This should speed the code up a bit, because it won't have to alias
  27.     # all those methods and recheck things it already did the first time through.
  28.     #
  29.     # Lastly, and probably most importantly, there is a tremendous amount of lag
  30.     # coming from the ever-present images that are having to be drawn on to the
  31.     # screen every frame.  This is being done with a heavy amount of common events
  32.     # that are set to run via parallel processing.  This is still an issue, even
  33.     # after I implemented my work in Section 2.
  34.     #=============================================================================
  35.    
  36.     #===========================================================================
  37.     # SECTION 1
  38.     #
  39.     # Stifling Events from Updating
  40.     #===========================================================================
  41.     #
  42.     # There are effectively two ways to keep an event from updating using this
  43.     # script.  I had to do it this way because there was so much already created.
  44.     # And I wanted to give you a way to go through and fix some of the maps
  45.     # without having to redo all the events on each map.  
  46.     #
  47.     # The First Way:
  48.     #
  49.     # In the hash below, called 'MAP_NO_UPDATE_EVENTS', you can make a reference
  50.     # to any map in the project and then link it to all the IDs of the events you
  51.     # don't want to update.  This way will be the fastest way to take care of
  52.     # already-existing maps.  Here's an entry example:
  53.     #
  54.     #                     14 => [65, 68, 73, 90],
  55.     #
  56.     # In the above example, on map number 14, the system would not update events
  57.     # numbered 65, 68, 73, and 90.
  58.     #
  59.     #---------------------------------------------------------------------------
  60.     #
  61.     # The Second Way:
  62.     #
  63.     # The second way requires you to go into the event, and add the following
  64.     # tag in each one that you don't want to update:
  65.     #
  66.     #                                 <X>
  67.     #
  68.     # That's pretty much all you have to do.  If the system finds <X> in the name
  69.     # of the event, it will not update it.
  70.     #===========================================================================
  71.     MAP_NO_UPDATE_EVENTS = {
  72.    
  73.     # mapID => [eventIDs]
  74.    
  75.     }
  76.    
  77.     #===========================================================================
  78.     # SECTION 3.
  79.     #
  80.     # Parallel Lag from Common Events
  81.     #===========================================================================
  82.     #
  83.     # In order to fix the heavy lag being caused by parallel operating common
  84.     # events, I tried to make a system that linked each common event to a counter.
  85.     # The counter would count each frame, but would not update until it reached
  86.     # the value it was supposed to.  Those values are stored in the hash below
  87.     # called 'PARALLEL COMMON_EVENT_COUNTERS'.  In the hash, you reference the
  88.     # common event by ID as the key, and then you link it to the amount of
  89.     # frames that should be allowed to pass prior to calling for that specific
  90.     # event's update method.  Take a look at this example hash entry:
  91.     #
  92.     #                            71 => 45,
  93.     #
  94.     # In the example above, the number 71 common event would only update every
  95.     # 45 frames.  Keep in mind that there are 60 frames per second, so this is still
  96.     # updating in less than a second each time.  
  97.     #
  98.     #****************************************************************************
  99.     #                          NOTE
  100.     #****************************************************************************
  101.     # Neo, I tried to set them up the best I could.  You can see that I set the
  102.     # clock HUD to only update every second.  Also, the 'lures' event seemed
  103.     # like it wasn't something that was required every second of the game, because
  104.     # it is only accessed when someone goes fishing, so I backed off the update
  105.     # time on that.  I didn't playtest enough after implementing this to see if it
  106.     # made a real difference, but try it out, adjust the numbers, and let me
  107.     # know what you think.  
  108.     #
  109.     # Ixfuru
  110.     #
  111.     #****************************************************************************
  112.     #=============================================================================
  113.     PARALLEL_COMMON_EVENT_COUNTERS = {
  114.    
  115.     # common_eventID => frames_between_updates
  116.    
  117.     # LANTERN EVENT
  118.     1 => 3,
  119.     # LURES EVENT
  120.     10 => 90,
  121.     # MINI-MAP
  122.     12 => 5,
  123.     # HUD GAUGE
  124.     17 => 7,
  125.     # HUD GAUGE TIME
  126.     18 => 60,
  127.     # HUD GAUGE GEMS
  128.     19 => 2,
  129.     # HUD G EVENTS
  130.     42 => 12,
  131.    
  132.     }
  133.    
  134.    
  135.    
  136.   end
  137. end
  138.  
  139. #===============================================================================
  140. # GAME MAP
  141. #===============================================================================
  142. class Game_Map
  143.  
  144.   NO_UPDATE_MARK = "<X>"
  145.  
  146.   #-----------------------------------------------------------------------------
  147.   # Initialize * Aliased *
  148.   #-----------------------------------------------------------------------------
  149.   alias thal_gmmp_ini initialize unless $@
  150.   def initialize
  151.     thal_gmmp_ini
  152.     @parallel_ce_counters = {}
  153.   end
  154.  
  155.   #--------------------------------------------------------------------------
  156.   # * Update Events
  157.   #--------------------------------------------------------------------------
  158.   def update_events
  159. #~     p "UPDATING EVENTS"
  160.     ale = antilag_events
  161.     if ale.has_key?(@map_id)
  162.       for event in @events.values
  163.         next if event.name.include?(NO_UPDATE_MARK)
  164.         next if ale[@map_id].include?(event.id)
  165.         event.update
  166.       end
  167.     else
  168.       for event in @events.values
  169.         next if event.name.include?(NO_UPDATE_MARK)
  170.         event.update
  171.       end
  172.     end
  173.     @parallel_ce_counters = {} if @parallel_ce_counters.nil?
  174.     for common_event in @common_events.values
  175.       next if common_event.nil?
  176.       ceid = common_event.id
  177.       pcec = parallel_common_event_counters
  178.       if pcec.include?(common_event.id)
  179.         if @parallel_ce_counters.include?(common_event.id)
  180.           @parallel_ce_counters[common_event.id] += 1
  181.           if @parallel_ce_counters[common_event.id] > pcec[common_event.id]
  182.             common_event.update
  183.             @parallel_ce_counters[common_event.id] = 0
  184.           end
  185.         else
  186.           @parallel_ce_counters[common_event.id] = 0
  187.         end
  188.       else
  189.         common_event.update
  190.       end
  191.     end
  192.   end
  193.  
  194.   #------------------------------------------------------------------------------
  195.   # Parallel Common Event Counters
  196.   #----------------------------------------------------------------------------
  197.   def parallel_common_event_counters
  198.     return IxTh::AntiLag::PARALLEL_COMMON_EVENT_COUNTERS
  199.   end
  200.  
  201.   #----------------------------------------------------------------------------
  202.   # Antilag Events
  203.   #----------------------------------------------------------------------------
  204.   def antilag_events
  205.     return IxTh::AntiLag::MAP_NO_UPDATE_EVENTS
  206.   end
  207.  
  208. end
  209.  
  210. #===============================================================================
  211. # SPRITESET VARPIC
  212. #===============================================================================
  213. class Spriteset_VarPic
  214.  
  215.   #-----------------------------------------------------------------------------
  216.   # Update
  217.   #-----------------------------------------------------------------------------
  218.   alias thal_ssvp_upd update unless $@
  219.   def update
  220.     return if @sprites.empty?
  221.     thal_ssvp_upd
  222.   end
  223.  
  224. end
  225.  
  226. #===============================================================================
  227. # SCENE MAP
  228. #===============================================================================
  229. class Scene_Map < Scene_Base
  230.  
  231.   #-----------------------------------------------------------------------------
  232.   # Update
  233.   #-----------------------------------------------------------------------------
  234.   def update
  235.     super
  236.     $game_map.interpreter.update
  237.     $game_map.update
  238.     $game_player.update
  239.     $game_system.update
  240.     @spriteset.update
  241.     @message_window.update
  242.     update_dart_trigger
  243.     if $game_temp.transition_processing
  244.       process_transition
  245.     end
  246.     $OverlayMap.update
  247.     unless $game_message.visible
  248.       update_transfer_player
  249.       update_encounter
  250.       update_call_menu
  251.       update_call_debug
  252.       update_scene_change
  253.     end
  254.   end
  255.  
  256.   #-----------------------------------------------------------------------------
  257.   # Call Shop
  258.   #-----------------------------------------------------------------------------
  259.   def call_shop
  260.     $game_temp.next_scene = nil
  261.     if $game_switches[YE::SYNTH::SYNTH_SWITCH]
  262.       $game_switches[YE::SYNTH::SYNTH_SWITCH] = false
  263.       $scene = Scene_Synthesis.new
  264.     elsif meet_ceshop_conditions
  265.       $scene = Scene_Common_Event_Shop.new
  266.     else
  267.       $scene = Scene_Shop.new
  268.     end
  269.   end
  270.  
  271. end
Advertisement
Add Comment
Please, Sign In to add comment