06-26-2013, 04:28 AM
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:
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.
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.