Yesterday, 09:50 PM (This post was last modified: Today, 05:20 AM by DerVVulfman.)
Anyone with RMXP wanna give this anti-lag a try?
Part1 - The mostly Custom Code
Code:
module AntiLag
# The dimensions of you game window, useful if a resolution script in use
TILES_HORIZONTAL = 20
TILES_VERTICAL = 15
# How far out (in tiles) beyond the viewport to permit activity
BUFFER_SIZE = 2
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles the map. It includes scrolling and passable determining
# functions. Refer to "$game_map" for the instance of this class.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Gets the minimmum and maximum x/y map coordinates for updating events
#--------------------------------------------------------------------------
def get_antilag_tile_area
#
# Gets the upper left x and y tile-coordinate
x = $game_map.display_x / 128
y = $game_map.display_y / 128
#
# Get configurable buffer and ensure it isn't negative or invalid
al_buffer_size = AntiLag::BUFFER_SIZE
al_buffer_size = 0 if al_buffer_size.nil?
al_buffer_size = 0 if !al_buffer_size.is_a?(Integer)
al_buffer_size = 0 if al_buffer_size < 0
#
# Computes the min and max coordinates when considering the buffer-size
min_x = x - al_buffer_size
min_y = y - al_buffer_size
max_x = x + AntiLag::TILES_HORIZONTAL + al_buffer_size
max_y = y + AntiLag::TILES_VERTICAL + al_buffer_size
#
# Makes sure the min and max coordinates are within the map
min_x = 0 if min_x < 0
min_y = 0 if min_y < 0
max_x = $game_map.width - 1 if max_x >= $game_map.width
max_y = $game_map.height - 1 if max_y >= $game_map.height
#
# Returns the result as the min and max coordinates
return min_x, max_x, min_y, max_y
#
end
#--------------------------------------------------------------------------
# * Update the antilag tile coordinates for tile area testing
#--------------------------------------------------------------------------
def update_antilag_tile_area
#
# Don't bother updating if the player hasn't even moved
return unless antilag_player_moved?
#
# Since the player HAS moved, update the new antilag coordinates
@al_min_x, @al_max_x, @al_min_y, @al_max_y = get_antilag_tile_area
#
end
#--------------------------------------------------------------------------
# * Determine if an object is in the viable viewport
#--------------------------------------------------------------------------
def antilag_tile_area?(object)
#
# Exit false if the player is not within the x/y boundaries
return false if object.x < @al_min_x || object.x > @al_max_x
return false if object.y < @al_min_y || object.y > @al_max_y
#
# Exit true if the player is within the area
return true
#
end
#--------------------------------------------------------------------------
# * Determine if the player moved enough to require updating the tile area
#--------------------------------------------------------------------------
def antilag_player_moved?
#
# If the player moved even a single tile, let alone to a new map
if @antilag_old_x != $game_player.x ||
@antilag_old_y != $game_player.y ||
@antilag_old_id != $game_map.map_id
# Update the player's current coordinates
@antilag_old_x = $game_player.x
@antilag_old_y = $game_player.y
@antilag_old_id = $game_map.map_id
# And exit true that the player moved
return true
end
#
# Exit false if there's no change
return false
#
end
end
Part2 - Mainly Game_Map's update edited
Code:
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles the map. It includes scrolling and passable determining
# functions. Refer to "$game_map" for the instance of this class.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Refresh map if necessary
if $game_map.need_refresh
refresh
end
# If scrolling
if @scroll_rest > 0
# Change from scroll speed to distance in map coordinates
distance = 2 ** @scroll_speed
# Execute scrolling
case @scroll_direction
when 2 # Down
scroll_down(distance)
when 4 # Left
scroll_left(distance)
when 6 # Right
scroll_right(distance)
when 8 # Up
scroll_up(distance)
end
# Subtract distance scrolled
@scroll_rest -= distance
end
#------------------------------------------------------------------------
# >> EDITED AREA (contents below)<<
update_events # Update all map events
#------------------------------------------------------------------------
# Update common event
for common_event in @common_events.values
common_event.update
end
# Manage fog scrolling
@fog_ox -= @fog_sx / 8.0
@fog_oy -= @fog_sy / 8.0
# Manage change in fog color tone
if @fog_tone_duration >= 1
d = @fog_tone_duration
target = @fog_tone_target
@fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
@fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
@fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
@fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
@fog_tone_duration -= 1
end
# Manage change in fog opacity level
if @fog_opacity_duration >= 1
d = @fog_opacity_duration
@fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
@fog_opacity_duration -= 1
end
end
#--------------------------------------------------------------------------
# * Frame Update (when handling map events) an SDK derived method
#--------------------------------------------------------------------------
def update_events
#
update_antilag_tile_area # Update tile area coords if needed
for event in @events.values # Cycle through all events
next unless antilag_tile_area?(event) # Skip if not in the viewport
event.update # Update the event
end
end
end
Part 3 - Mainly Spriteset_Map's update edited
Code:
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# This class brings together map screen sprites, tilemaps, etc.
# It's used within the Scene_Map class.
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# If panorama is different from current one
if @panorama_name != $game_map.panorama_name or
@panorama_hue != $game_map.panorama_hue
@panorama_name = $game_map.panorama_name
@panorama_hue = $game_map.panorama_hue
if @panorama.bitmap != nil
@panorama.bitmap.dispose
@panorama.bitmap = nil
end
if @panorama_name != ""
@panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
end
Graphics.frame_reset
end
# If fog is different than current fog
if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
@fog_name = $game_map.fog_name
@fog_hue = $game_map.fog_hue
if @fog.bitmap != nil
@fog.bitmap.dispose
@fog.bitmap = nil
end
if @fog_name != ""
@fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
end
Graphics.frame_reset
end
# Update tilemap
@tilemap.ox = $game_map.display_x / 4
@tilemap.oy = $game_map.display_y / 4
@tilemap.update
# Update panorama plane
@panorama.ox = $game_map.display_x / 8
@panorama.oy = $game_map.display_y / 8
# Update fog plane
@fog.zoom_x = $game_map.fog_zoom / 100.0
@fog.zoom_y = $game_map.fog_zoom / 100.0
@fog.opacity = $game_map.fog_opacity
@fog.blend_type = $game_map.fog_blend_type
@fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
@fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
@fog.tone = $game_map.fog_tone
#------------------------------------------------------------------------
# >> EDITED AREA (contents below)<<
update_sprites # Update all character sprites
#------------------------------------------------------------------------
# Update weather graphic
@weather.type = $game_screen.weather_type
@weather.max = $game_screen.weather_max
@weather.ox = $game_map.display_x / 4
@weather.oy = $game_map.display_y / 4
@weather.update
# Update picture sprites
for sprite in @picture_sprites
sprite.update
end
# Update timer sprite
@timer_sprite.update
# Set screen color tone and shake position
@viewport1.tone = $game_screen.tone
@viewport1.ox = $game_screen.shake
# Set screen flash color
@viewport3.color = $game_screen.flash_color
# Update viewports
@viewport1.update
@viewport3.update
end
#--------------------------------------------------------------------------
# * Frame Update (when handling map sprites) an SDK derived method
#--------------------------------------------------------------------------
def update_sprites
#
# Cycle through all character sprites
for sprite in @character_sprites
# Skip if the sprite is not in the viewport ares
next unless $game_map.antilag_tile_area?(sprite.character)
# Update the sprite
sprite.update
end
#
end
end
Just tinkering with it, but I personally get at least a FPS of 38 out of 40 with the 900+ events in the anti-lag demo I cobbled together for the Zeriab posts. Faster than Near Fantastica's or Amaranth's too it seems.
It doesn't have all the bells and whistles (ie defining certain events that are always/never updated, enable/disable antilag).... But its a start, and its pretty much not altering the RMXP game variables.
DO NOTE: It does rewrite the update methods for "Game_Map" and "Spriteset_Map". But I sure as heck identified where the changes are made. And I kept with RMXP SDK names for the methods that cycle through and update the events/characters.
Rather than repeatedly re-acquire the minimum and maximum x/y coordinates where your player character is standing (typical with 'in_range?' like methods), it only grabs the coordinates IF you moved. So instead of it performing a dozen calculations just for the boundaries before even testing if the event(s) are in/outside the area, it runs a test to see if the player's X, Y and/or Map had changed... much less processing if you're not moving at all.
I kept values marginally unique with prefixes of @antilag of al (short for anti-lag) in variable names.
EDIT: Oh, gawd. I added two lines so I could have an RMXP switch to turn on/off anti-lag; one simple line in the config system, and one line for the simple 'if its on' bypass.
Turning the Anti-Lag off in that ridiculous 900+ map dropped the 38Frame rate down to 23!!! Yeah, I know without a DOUBT the anti-lag is working.
EDIT 2: Oof. Well, I added a sort of name tag for events so they can always be active on the map even outside your view when all others are limited by the anti-lag system. It seems to start dropping the FPS when you hit 200 events. Quite confusing to me. But... 200 events being fully active no matter when when everyone else is limited by the anti-lag is still a lot.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)