PoLlama Forums  

Go Back   PoLlama Forums > WarCraft > Tutorials > Submit a Tutorial [World Editor]

Reply
 
LinkBack Thread Tools Rate Thread
Old 07-09-2007   #1
 
MrApples's Avatar
 
Join Date: Sep 2006
Location: Your Mom
Posts: 2,241
MrApples has a spectacular aura about
Reducing Lag

Reducing Lag
How to kill the anti-map, GUI version.

Introduction
The non-important, nice way to start a tutorial.
Lag, the anti-map. If you want to make a cool map, a ‘new’ map, something that makes the players go ‘wow’, your going to have to have a lot of nice triggers. However, there’s more to nice triggers then what they do, there’s rules, and if you don’t follow them, your going to get swamped with lag.

Disclaimer: The quality of this tutorial may not be as great as my others since I made it a long time ago(in 2005), and it was unfinished. Reducing lag is a big topic, and I didn’t know as nearly as much as I do now on the subject when I made this. I figured it could still help someone though, so I restored it some and re-released it.


Getting Started
Time to set out on your quest against the lag.

The 5 Rules of the Anti-Lag Association:
-If you’re not using it, throw it away.
-If you do something once, then don’t do it again unless you have to.
-Take the shortest route possible, while still keeping your triggers lag less.
-Streaming is better then shipping. It’s better to do things little by little then in big loads.
-If you have found what your looking for, stop looking.

If you’re not using it, throw it away
What this means is that, if you have something in your map that you will not need again, then why keep it? This goes from extra abilities/units you have saved to the floating text you created in game. See Memory Leaks, Quality over Quantity, , and .

If you do something once, then don’t do it again unless you have to.
Say you have the game go fetch a unit group, and you have a lot of actions for this same unit group. Why have the game fetch the unit group again, and again for each action, when you can just temporarily save it. See Using Variables.

Code:
Pick Every Unit in (All Units in (Playable Map Area)) and do stuff
Pick Every Unit in (All Units in (Playable Map Area)) and do stuff
Pick Every Unit in (All Units in (Playable Map Area)) and do stuff
Code:
 set UnitGroupVariable = (All Units in (Playable Map Area))
Pick Every Unit in UnitGroupVariable and do stuff
Pick Every Unit in UnitGroupVariable and do stuff
Pick Every Unit in UnitGroupVariable and do stuff
Take the shortest route possible, while still keeping your triggers lag less.
If you can do something the same way in faster time, then do it that way. Picking every player in Players that are Playing, will always be better then picking All Players, just because there is a much better chance that there will be less players playing, then there are in all. But, sometimes the way that seems shorter, isn’t the fastest way in the long run.

Code:
Display Game Message to (All Players) : Welcome!
Display Game Message to (All Players) : I’m bob, your game guide.
Code:
Display Game Message to (All Players matching ((Matching Player)’s slot status = (Is Playing))) : Welcome!
Display Game Message to (All Players matching ((Matching Player)’s slot status = (Is Playing))) : I’m bob, your game guide.

Streaming is better then shipping. It’s better to do things little by little then in big loads.
It’s true. If you can do little by little more often, instead of big loads not so often, then there’s a better chance that the player will not notice it. Remember that this is about making it smooth for the player. Creating 10 units every 20 seconds is better then creating 20 units, every 40 seconds, and they do the same thing.

Code:
Every 100 Seconds
Actions
Create 100 Units at SomePoint
Code:
Every 10 Seconds
Actions
Create 10 Units at SomePoint
Sometimes it’s the other way around…
Code:
Every 1 Second
Actions
Give 5 gold to Player 1 (Red)
Code:
Every 10 Seconds
Actions
Give 50 gold to Player 1 (Red)

Basics
All the big and small simple things.

Using Variables
One important thing to learn on the quest of making your map lag less is that variables are your friend. Variables are not going to hurt you, they are here to help. If you do not know what a variable is then read my tutorial on variables.

Ok, with anything in game from Triggers to Units, if you’re not using it, you might as well destroy it. By using it means you will use it in the future also.

With any Trigger, if you’re not going to use to again, destroy it by putting this action at the very end

Custom Script: call DestroyTrigger( GetTriggeringTrigger() )

With Units if you do not use Resurrected units and etc, edit the lasting time of the corpse in Advanced - Game Constants. Leave enough time for a Dying Animation (2 Seconds). Corpses are units too. If you do use Resurrected Units, then use conditions to check if it’s a unit that cannot be resurrected.

Code:
Anti Lag
  Events
    Unit - A unit Decays
  Conditions
    Or- Multiple Conditions
       ((Dying unit) is A structure) Equal to True
       ((Dying unit) is A flying unit) Equal to True
       ((Dying unit) is Mechanical) Equal to True
       ((Dying unit) is An Ancient) Equal to True
       ((Dying unit) is Summoned) Equal to True
  Actions
    Unit - Remove (Dying unit) from the game
If you’re not using it, your not going to use it, destroy it goes with anything. Make sure to especially destroy anything that was dynamically created which means you created it in game through triggers.



Efficent Triggering
Remember the less lines there are in a trigger, the better most likely. If there’s a way to make a trigger shorter that does the same thing then do it, sometimes taking the harder way in triggering instead of the easy way has many rewards.

Avoid using periodicals and triggers that run very often. If there’s a way to do the same thing without running as much then do that.

Avoid Periodicals at all costs (If necessary). This means Every # Second(s) Do This. If this unnecessary for the trigger to run that many times then don't do it!

When do things such as Creating mass quantities of Units, try to stream the units by making less more often instead of more less often.

(TIP: With Creating Units it is effective to have all units used in your game pre placed and then removed at Map Initiation. This gets rid of some initial lag.)


Fewer Doodads
Sometimes using a lot of those Doodads are a bad thing. Avoid using Doodads with excessive animation such as lightning, can really lag up the game.


3rd Party Tools
Using such tools as Vexorian’s Map Optimizer (the shortest variables names action) Can also help your map. Get it at ().com!


Memory Leaks
They’re overrated. Just kidding!

What They Are
The King of Lag, Tyrant of Troubles, the Memory Leaks. Memory Leaks are things that cause lag, can even put your map to the point of freezing. How do they happen? Whenever you use Groups, Points, and other Dynamically Created Stuff, they are saved in memory, so the game can access them quicker, and the game does not know on its own when to get rid of them.

Just to Clarify, Groups mean any Unit Group, Player Group, etc you use. Points are Locations like Center of Region, or Position of Unit. Dynamically Created Stuff can be special effects, regions(non premade), and even units can be considered such.

Targeting Them
Enough of what they are, I bet your wondering how to kill them, well I'll tell you how! The way to kill them for Groups and Points is instead of using the Groups and Points in the actions; you set them to a Variable, and then use the Variable in the action.

You first will need to create a variable for each.
-Create a Point Variable, name it TempPoint
-Create a Unit Group Variable, name it TempGroup
-Create a Player group Variable, name it TempForce

Then set the Group/Point in question, and use the Variable in the Action instead.
Example
Before
Code:
Pick Every Player in All Players Matching (Matching Player) is Playing = True
Loop Actions
   Pick Every Unit in Units Owned by Picked Player
        Loop Actions
            Order Picked Unit to Move to Position of Juice Box
            Order Picked Unit to Dance
After
Code:
Set TempForce = All Players Matching (Matching Player) is Playing = True 
Pick Every Player in TempForce
Loop Actions
     Set TempGroup = Units Owned by Picked Player 
    Pick Every Unit in TempGroup
        Loop Actions
            Set TempPoint = Postion of JuiceBox
            Order Picked Unit to Move to TempPoint
            Order Picked Unit to Dance


Destroying Them
Ok, you have those Memory Leaks locked on Target, but you’re not done yet. You still have to destroy them.

You Destroy the Memory Leaks by adding some Custom Script.

CustomScript: call FUNCTION(udg_VARIABLE)

(((TIP: Custom Script (JASS) is Case Sensitive)))

You change the VARIABLE Part to whatever is the name of the Variable you want to kill.

What you change the COMMAND Part to depends on what you are destroying.

Replace DESTROY with whatever command suits your variable.

[code=Functions]
Main Memory Leaks Destroy Functions
Point- RemoveLocation
Player Group- DestroyForce
Unit Group- DestroyGroup


Other Memory Leaks Destroy Functions
[b]Region- RemoveRect
Floating Text- DestroyTextTag
Timer- DestroyTimer
Lightning - DestroyLightning
[/quote]

So now the Actions above should now look like:
Code:
Set TempForce = All Players Matching (Matching Player) is Playing = True
Pick Every Player in TempForce
Loop Actions
    Set TempGroup = Units Owned by Picked Player
    Pick Every Unit in TempGroup
        Loop Actions
            Set TempPoint = Postion of JuiceBox
            Order Picked Unit to Move to TempPoint
            Order Picked Unit to Dance
            Custom Script: call RemoveLocation (udg_TempPoint) Custom Script: call DestroyGroup (udg_TempGroup) Custom Script: call DestroyForce (udg_TempForce)
(((TIP: Try to Keep the Destroy Action closest as possible to after your done with it. With Pick every Unit and Pick Every Player in Group what its actually doing is running the actions once for every player/unit in that group. If you just put the CustomScript: call DestroyGroup(udg_TempGroup) action at the end of your trigger it would leak once for every unit except the last one.)))

Yay, now its memory leak free!

For Dynamically Created Stuff (Anything you create in-game, Units, Regions, etc. the only way to get rid of the leak is to destroy them. Use Action- Add a Generic Expiration Timer on Unit.

(((TIP: Conditions leak too, so in order to set a variable for a condition you must use If/Then/Else Action instead of the Conditions part.)))

Now you know how to make your map less laggy, yay!

[b]Please comment on how this tutorial can be improved, if you find anything that you find confusing, or may be confusing to others, please let me know![b][/code]
MrApples is offline   Reply With Quote
Old 07-09-2007   #2
 
MrOrange's Avatar
 
Join Date: Dec 2006
Posts: 2,948
MrOrange has a reputation beyond reputeMrOrange has a reputation beyond reputeMrOrange has a reputation beyond reputeMrOrange has a reputation beyond reputeMrOrange has a reputation beyond reputeMrOrange has a reputation beyond reputeMrOrange has a reputation beyond reputeMrOrange has a reputation beyond reputeMrOrange has a reputation beyond reputeMrOrange has a reputation beyond reputeMrOrange has a reputation beyond repute
Re: Reducing Lag

The only thing you should try to fix is the code tags. Color codes don't work in code tags here. And it really makes it hard to see.
MrOrange is offline   Reply With Quote
Reply

Tags
None

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may post replies
You may post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Download Footmen Frenzy XV ShadowDestroyer Footmen Frenzy XV 0 01-21-2008 12:14 AM
Leak Check V2(reducing lag in you maps) tylord Tools 5 08-22-2007 05:26 PM
Terms of super smash bros meele luigi_fan64 Super Smash Brothers 1 07-19-2007 09:47 PM
[HERO] Skeletal Mage Killzor2 New Feature Requests 2 05-15-2007 08:08 PM
[Tutorial] Reducing Lag MrApples World Editor Help 5 04-27-2007 03:34 AM


All times are GMT -5. The time now is 08:24 AM.

A friend of Wc3Happy
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165