Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Closed TopicStart new topic
> Super Simple Anti-Lag Script (Updated to 2.0)
amaranth
post Dec 21 2008, 07:22 PM
Post #1


Level 6
Group Icon

Group: Member
Posts: 78
Type: Developer
RM Skill: Masterful




Introduction
If you are looking for an anti-lag script that will keep your FPS at 100% most of the time, this is the script for you.

Revisions in Version 2.0 (March 22, 2009)
-Moved code into one simple script.
-Fixed an important bug which reduced an additional 50% of lag.
-Added ability to turn off/on Anti-Lag anywhere in the game at any time (thanks Shaz)
-Added ability to turn off Anti-Lag for specific events (thanks Angelix)
-Two levels of anti-lag added: map lag, event lag
-Better documentation.
-Now extremely easy to increase/decrease anti-lag window for graphic drawing and event animation.
-Added demo!
-Cleaner, smaller code for less mess and script complications. Should work with your other custom scripts.


Download Demo
Download Super Simple Anti-Lag Demo Here

Super Simple Anti-Lag Script V2.0
Place this script above Main:

CODE

#####################################################
#Super Simple Anti-Lag System 2.0 By Amaranth
#Last updated March 22, 2009
#####################################################
# Additional Credits:
# Angelix, Shaz, Near Fantastica
####################################################
# Usage: Free for all to use.
####################################################

#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# SET YOUR ANTI-LAG PERAMETERS
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------

# 1. Set anti-lag for drawing events
# -----------------------
# Only draw event GRAPHIC if within this horizontal # of tiles from player
# Note: if event is outside of this range, and this range is within screen
# width, the event will appear to "drag" across the screen because the
# game is not updating the graphic.
PLAYER_RANGE_WIDTH = 20

# Only draw event GRAPHIC if within this vertical # of tiles from player
# Note: if event is outside of this range, and this range is within screen
# height, the event will appear to "drag" across the screen because the
# game is not updating the graphic.
PLAYER_RANGE_HEIGHT = 15


# 2. Set anti-lag for moving events
# -----------------------
# Only process event movement if within this horizontal # of tiles from player
# Note: if event is outside of this range, and this range is within screen
# width, the event will stop moving.
MAP_RANGE_WIDTH = 20

# Only process event movement if within this vertical # of tiles from player
# Note: if event is outside of this range, and this range is within screen
# height, the event will stop moving.
MAP_RANGE_HEIGHT = 15

# 3. Set anti-lag movement for specific events
# -----------------------
# You can stop the game from updating specific events. This is
# helpful if you have several events on screen. Only use this on events
# that are invisible or don't move around.
# To Use: Create an event on a map and change the name of the event to the
# value below (by default, this is IGNORE). The name of an event
# is in the upper-left side of the event dialog box)
ANTI_LAG_EVENT_NAME = "IGNORE"


# 4. Turn anti-lag on and off in the game while playing the game
# ------------------------
# On some maps in your game, you may not want to use the anti-lag system,
# or you may want to turn it off during some scenes in your game.
# To Use: Use a switch to turn anti-lag off and on. (by default this is Switch 1)
ANTI_LAG_SWITCH = 1



#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
class Game_Character
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
attr_accessor :inrange_char # event near player? (stop draw)
attr_accessor :inrange_map # event on map? (stop movement)
attr_reader :event
end

#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
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

# Update map event
for event in @events.values
# ANTI LAG CHECK START---------------------------------------------
if ((event.inrange_map == 1) && (event.event.name != ANTI_LAG_EVENT_NAME)) or [3,4].include?event.trigger
event.update
end
# ANTI LAG CHECK END-----------------------------------------------
end

# 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

end

#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# ��€”� Spriteset_Map
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
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

# Update character sprites
for sprite in @character_sprites
# ANTI LAG CHECK START---------------------------------------------
if in_range?(sprite.character)
sprite.update
end
# ANTI LAG CHECK END---------------------------------------------
end

# 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


#--------------------------------------------------------------------------
# ��€”� Check if events are in range (ANTI-LAG)
#--------------------------------------------------------------------------
def in_range?(event)

diff_x = ($game_player.real_x - event.real_x).abs # absolute value
diff_y = ($game_player.real_y - event.real_y).abs # absolute value

# update the graphic for the event in this range
player_width = 128 * PLAYER_RANGE_WIDTH
player_height = 128 * PLAYER_RANGE_HEIGHT

# update actions being performed by the event in this range
screen_width = 128 * MAP_RANGE_WIDTH
screen_height = 128 * MAP_RANGE_HEIGHT

# stop an event from performing actions if outside of this range on the map
# note: if range is small, event will stop moving and performing tasks on screen
if ((diff_x < screen_width && diff_y < screen_height) or $game_switches[ANTI_LAG_SWITCH])
event.inrange_map = 1
else
event.inrange_map = 0
end

# stop an event's graphic from updating if outside of the range around player
# note: if range is small, event graphic will appear to "drag" across screen
# this happens because the graphic is not updating.
if ((diff_x < player_width && diff_y < player_height) or $game_switches[ANTI_LAG_SWITCH])
event.inrange_char = 1
return true
else
event.inrange_char = 0
return false
end

end
end



Credits
Amaranth, Near Fantastica, Shaz, Angelix

This post has been edited by amaranth: Mar 22 2009, 01:05 PM


__________________________
Go to the top of the page
 
+Quote Post
   
Blizzard
post Dec 22 2008, 03:18 AM
Post #2


Where am I?
Group Icon

Group: Revolutionary
Posts: 613
Type: Scripter
RM Skill: Masterful




Have you thought about making a script that aliases the necessary methods rather than letting people edit the scripts themselves? Also, those Anti-Lag Systems always lacked one thing. Sure, sprites don't get updated when they are not visible, but they are still there and just the presence of sprites causes lag. You might wanna take a look at how I did my Anti-Lag, I solved that problem. http://forum.chaos-project.com/index.php?topic=104.0


__________________________


Please keep in mind that I have retired from RMXP and that I am not active here anymore! If you can't get any support for my scripts here, try at Chaos Project.
Go to the top of the page
 
+Quote Post
   
amaranth
post Dec 22 2008, 11:39 AM
Post #3


Level 6
Group Icon

Group: Member
Posts: 78
Type: Developer
RM Skill: Masterful




Ooo, goodie, thanks Blizzard! smile.gif


__________________________
Go to the top of the page
 
+Quote Post
   
Blizzard
post Dec 26 2008, 03:52 PM
Post #4


Where am I?
Group Icon

Group: Revolutionary
Posts: 613
Type: Scripter
RM Skill: Masterful




You'll love what I did in the demo to demonstrate how it works. xD


__________________________


Please keep in mind that I have retired from RMXP and that I am not active here anymore! If you can't get any support for my scripts here, try at Chaos Project.
Go to the top of the page
 
+Quote Post
   
amaranth
post Mar 22 2009, 01:01 PM
Post #5


Level 6
Group Icon

Group: Member
Posts: 78
Type: Developer
RM Skill: Masterful




Hi everyone, I've updated this script and it is FASTER THAN EVER!!!! banana.gif

If you would like a simple script for anti-lag that touches very little of your code, this is the script for you. It's elegant, simple, and fast!

Revisions in Version 2.0
-Moved code into one simple script.
-Fixed an important bug which reduced an additional 50% of lag.
-Added ability to turn off/on Anti-Lag anywhere in the game at any time (thanks Shaz)
-Added ability to turn off Anti-Lag for specific events (thanks Angelix)
-Two levels of anti-lag added: map lag, event lag
-Better documentation.
-Now extremely easy to increase/decrease anti-lag window for graphic drawing and event animation.
-Added demo!
-Cleaner, smaller code for less mess and script complications. Should work with your other custom scripts.

Download New Demo
Download Super Simple Anti-Lag Demo Here


__________________________
Go to the top of the page
 
+Quote Post
   
Redd
post Apr 4 2009, 11:33 PM
Post #6


:<
Group Icon

Group: Revolutionary
Posts: 2,328
Type: Developer
RM Skill: Advanced




Many thanks... i was looking for this smile.gif


__________________________
Go to the top of the page
 
+Quote Post
   
Zeriab
post Apr 5 2009, 01:12 AM
Post #7


Level 12
Group Icon

Group: Revolutionary
Posts: 196
Type: Event Designer
RM Skill: Skilled




What a sweet little script happy.gif

I would suggest adding the option to never update common event with trigger 0 (none). I.e. only update common events with trigger 1 (autorun) and 2 (parallel).
The reason is that there never is any need to update a common event with trigger 0 since another interpreter will manage all necessary updates should it be called.
Only with custom script could there be any reason to update common events with trigger 0. (I haven't seen any such script)
Note that since common events don't have pages their triggers won't change and thus you can create an array for the autorun and parallel common events once and only update those. This array is typically significantly smaller.

I would also suggest documenting the side-effects of the scripts. I mean how is the functionality of the events different from the eventer's point of view.
It can for example be used to give the feeling that enemies keep coming at you as you move around the map. Since the events only are updated when seen you can put them all on approaching the player. It can work out pretty well.

*hugs*
- Zeriab


__________________________
Go to the top of the page
 
+Quote Post
   
Blizzard
post Apr 5 2009, 04:02 AM
Post #8


Where am I?
Group Icon

Group: Revolutionary
Posts: 613
Type: Scripter
RM Skill: Masterful




I agree with Z. I remember how my unofficial map slicer would alter the coordinates of events so "Change Event Location" commands would behave differently. I had to mention it in the instructions since it was quite s serious side effect.


__________________________


Please keep in mind that I have retired from RMXP and that I am not active here anymore! If you can't get any support for my scripts here, try at Chaos Project.
Go to the top of the page
 
+Quote Post
   
darkhalo
post Apr 9 2009, 10:38 AM
Post #9


The RM Warlock
Group Icon

Group: +Gold Member
Posts: 2,181
Type: Developer
RM Skill: Advanced




Latest project was lagging so much I almost gave it up just for that reason alone. Despite trying out others, this has to be the best anti lag script yet. Thanks thumbsup.gif


__________________________

Go to the top of the page
 
+Quote Post
   
hkoz
post Dec 9 2011, 08:16 AM
Post #10



Group Icon

Group: Member
Posts: 3
Type: Developer
RM Skill: Beginner




Thaaaaaaaaank u so much this will really help me biggrin.gif
Go to the top of the page
 
+Quote Post
   

Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th June 2013 - 10:25 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker