Custom Game_Event code lags too much!
#1
I've been bolting on custom features (party members follow the player as events, and enemy line of sight detection) and now my game lags! Anyone good at improving performance, or have any suggestions on how to move the code into the events themselves? I hadn't tried that option because I want the player to still be able to talk to these events so I can't run it as 'Parallel Process"

Here is the update method giving me trouble:
Code:
    #------------------------------------------------------------------------
    # * Update Movement
    #------------------------------------------------------------------------
    def update      
      # Interrupt if not stopping
      no_move = jumping? or moving?
      # Update
      pen_default_caterpillar_game_event_update
      #do enemy stuff
      if  @view_range != nil && !no_move && @view_range > tiles_from_player
        if can_see_player? &&
            $game_self_switches[[$game_map.map_id, self.id, "A"]] != true &&
            $game_self_switches[[$game_map.map_id, self.id, "B"]] != true &&
            $game_self_switches[[$game_map.map_id, self.id, "C"]] != true &&
            $game_self_switches[[$game_map.map_id, self.id, "D"]] != true
          $game_self_switches[[$game_map.map_id, self.id, "A"]] = true
          self.refresh
          return
        end
      end
      # Check if we need to do speical caterpillar handling
      if $game_system.caterpillar.active? && @caterpillar_actor != nil &&
         !no_move && !$game_system.caterpillar.actors.empty? && !@erased
        #debug distances printing
        if $DEBUG and Input.press?(Input::SHIFT) and !$game_player.moving?
          p "My distance from player is: " + (distance).to_s
          p "My prefered distance is : " + (@caterpillar_actor).to_s
        end
        #end debug
        range = @caterpillar_actor
        distance = tiles_from_player
        #if event is pathing
        if $game_self_switches[[$game_map.map_id, self.id, "A"]] == true
          #check to make sure pathing hasn't failed
          if distance >= range+9
            moveto($game_player.x, $game_player.y)
            @move_speed = 4
            self.clear_path_target
            $game_self_switches[[$game_map.map_id, self.id, "A"]] = false
            self.refresh
          end
          return
        end
        #should we do close movement?
        #different moves based on distance.
        if distance >= range+3
          $game_self_switches[[$game_map.map_id, self.id, "A"]] = true
          self.refresh
          return
        elsif distance >= range+1
          move_toward_player
          return
        elsif distance >= range && ($game_player.moving? || $game_player.jumping?)
          move_toward_player
          return
        end
      end
    end

EDIT: So, I feel silly. It turned out my lag issues were caused by a runaway HUD window updating every frame. So instead maybe you guys have tips on how to profile RGSS code or tips on how to prevent lag.
Reply }
#2
Reading...
"It turns out my lag ussues were caused by a runaway HUD window updating every frame."......

Basically, You can find what I'm describing in the hud script for my Lycan ABS

In the main hud window...
1) I Have a master update routine that:
a) First does a check routine that only performs updates after x frames ( if Graphics.frame_count % 30 != 0)
b) Same check routine sees if the current HP is the same as the last checked hp
c) Same check routine sees if the current SP is the same as the .... Oh, you get the idea)
2) ONLY if the check routine says something is different.... refresh and update the rest of the window with the new data
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#3
I was doing all of that except a). I also had some malfunctioning code meant to refresh it after a message_window is closed (because 19 year old me thought that since the message window overlapped the HUD, it would overwrite its pixels). But the HUD was redrawing whenever the message window wasn't visible, instead of when it was closed.

It must have been like that since the very beginning of my project, but I only really noticed it when I tried adding text shadows to the HUD (Twice as many draw_text calls, twice as many lags)
Reply }
#4
"But the HUD was redrawing whenever the message window wasn't visible, instead of when it was closed."

Redrawing even when invisible.... Hmm... Didn't think about that in my hud code, though I did incorporate something to handle that in some other features. Have you thought about adding this BEFORE 'A' in my example?
Code:
return unless self.visible
Haven't tried that personally, and I don't have XP up right now. Laughing Could be fun.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply }
#5
No, the HUD was redrawing when the MESSAGE WINDOW was invisible. Which is nearly all the time in a typical RPG Maker game. Either way it is fixed now, but I should look into Ruby profiling tools. They are built right into the language!
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   ForeverZer0 Custom Resolution + Littledrago's Zoom Solitaire 20 1,204 10-27-2024, 09:32 PM
Last Post: Solitaire
   Possible means to speed up Bitmap TONE code? DerVVulfman 7 3,098 06-11-2023, 08:22 PM
Last Post: kyonides
   ACBS - Atoa Custom Battle System and TP System zlsl 2 4,568 10-20-2021, 05:09 AM
Last Post: zlsl
   I want to add an Atoa Custom Battle System command cut-in. zlsl 11 13,891 11-11-2019, 08:55 PM
Last Post: DerVVulfman
   Question about ACBS (Atoa Custom Battle System) aeliath 10 12,764 08-08-2019, 02:50 PM
Last Post: aeliath
   Problems with counteraatack addon of Atoa Custom Battle System Djigit 22 35,466 01-05-2017, 08:05 PM
Last Post: Noctis
   Custom Message by Hodgeelmf, need to make it above picture LunarBerry 6 11,012 05-09-2016, 01:15 AM
Last Post: LunarBerry
   Atoa Custom Battle System: Popup when status change Noctis 6 10,630 02-01-2016, 12:52 AM
Last Post: Noctis
   Atoa Custom Battle System CTB animation while cast Noctis 6 10,719 01-04-2016, 03:05 PM
Last Post: Noctis
   Weird error when using a custom save script. Steel Beast 6Beets 8 11,425 06-27-2015, 05:54 PM
Last Post: Steel Beast 6Beets



Users browsing this thread: 3 Guest(s)