| 11-24-2003, 09:05 PM | #1 |
I've encountered a severe performance issue on the map I'm working on. I currently have assigned to every unit on the map a happiness value (along with a bunch of other values, but those aren't called up every interval for most units). I have it set up so that every interval, each unit checks to see if it's near to a a certain type of building. For each one that it's in range of, its happiness goes up by a little. Now, when I'm running a "for every unit in group" function, for the buildings, within another "for every unit in group" function every ten seconds to check which units are in range of one another, with one group being as large as a thousand units and the other having potentially several dozen, I get a significant drop in performance. I scaled back my original unit cap after the lag started popping up, and it's still going to be a mess. I intend to have many of these "happiness boosters" by the end of my map, so this problem is only going to get MUCH worse as time goes on. Can anyone suggest some good methods for trimming down my functions to improve performance? I do a lot of organizing of my variables, constantly reassigning preassigned variables to my own ones to keep it better organized. How much of a boost would I get by cutting out some of those reassignments? If I continue at this pace, deep blue will be the one everyone yells at for lagging while playing my map. |
| 11-24-2003, 09:53 PM | #2 |
Do you have any spell casters? If you don't, you can have the hapieness boosters add to thier mana, and have them start with a negitive manna regen, so they sadden if away from home. Hope I could help [glow=2,strength=3,color=red]:guns: :guns: :guns: :thrust:[/glow] |
| 11-24-2003, 10:35 PM | #3 |
Unfortunately, that wouldn't help much. I do have casters so I can't use it, but even if I didn't I would still have to manipulate the mana variable, which is just one step away from manipulating the happiness array I already have. Basically I want unit happiness for each each interval dependent on three things: unit health, proximity to certain types of buildings, and total population. The second one is the real kick in the teeth, though. What I need is an efficient method for setting up groups and quickly determining which members of one group affect the members in another? I suppose I could set up some conditions based on if a unit is in an area, but that would only save performance at certain times, and would make it worse the more things are flying around. At this point, I can get the triggers to do everything I want them to do, I just can't get them to do it efficiently. |
| 11-24-2003, 10:37 PM | #4 |
Happiness could also be a custom unit value, but I like Hunter's idea about mana regen. What does happiness do to a unit? If they're happy, does it make them better at something? If they're unhappy, does it make them die? You could always tie happiness to life regen, as well. |
| 11-24-2003, 11:10 PM | #5 |
Custom value is no good becase I use that to set the unit's ID for identifying things in the happiness array. A units happiness is given by "Happiness(Custom value of unit)." Like I said, I have my system working, the problem is that it causes an unacceptable performance hit. It's not so much the setting or the calling up of the happiness variable that causes the hit rather than the loops within the loops to detect specific nearby buildings. For every single unit, I have to have it look at every single important building and check the distance between each of them. In a single interval, which is ten seconds right now, this can be tens of thousands of triggers being run. And that's just in my simplified map I'm using before developing content. In the completed map, if I continued this way, there would be hundreds of thousands of triggers running every interval. The only idea that occurs to me is to try and space these functions out, run the triggers for half the units, wait 5 seconds, and then run the triggers for the other half. It would require more triggers, but it would be spaced out more evenly. I really need an expert at optimization to help me out on this. Oh, sorry, forgot to say what happiness does. Depending on a unit's happiness, it gets either a bonus or penalty to it's movement speed and attack speed. Thus, if your peasants are happy, they'll be more productive, and if your army is happy they'll be more effective. I Have this working using a modified version of Grater's custom aura system. I just have the groups based on happiness value rather than distandce from a specific unit. |
| 11-24-2003, 11:13 PM | #6 |
Since you're evading answering what happiness actually does for a unit, I'm guessing you're not looking for alternate solutions. Might I suggest an aura? You could base the "important buildings"s' auras on different types, so that they could overlap. It would have the downside of being a yes/no radius thing instead of a gradual decrease, but without any real information on what you're trying to do... |
| 11-24-2003, 11:18 PM | #7 | |
Quote:
He said what it does, read more thouroughly. |
| 11-24-2003, 11:22 PM | #8 | |
Quote:
He said what they do ;) Just out of curiosity why cant you give aroura's to the buildings that increase what every you want done? Than you already have the others solved so that would decrease lag. |
| 11-24-2003, 11:24 PM | #9 | |
Quote:
Thanks for the cheap shot, Hunter; he edited while I was posting. :nono: Hrm - I see a simple way to do this if you make similar but not exact auras. Make 3 aura casters around the building - one for long range, low powered effect, one for medium range, medium powered effect, and one for close range, high powered effect. Since a unit can only have a single copy of a skill, the three units will each have a version of it (the building could have one, and you need only make 2 support aura casters). Now, the trick is, I'm not sure if the game will give highest priority to the best aura. But it's worth a shot, no? |
| 11-24-2003, 11:40 PM | #10 |
Thanks for the suggestions, but I'm not quite sure the aura idea will work for what I'm trying to do. Actually, is there a condition to detect if a unit is under the effect of an aura? I might be able to make an efficient workaround with them if there is. Also, is it possible to change the description of the aura as it appears in the little stats screen for units? If not, then this method might be too aesthetically unappealing to be worthwhile (I'm trying to make as few rough edges as possible). I suppose I should elaborate on my map a bit. Basically, it's sort of like a fusion of sim city and warcraft. Each player focuses most of his energy on building up his own city, while trying to hinder the progress of the other players. The reason auras wouldn't work for buildings is because I don't want to have players rely on a quick fix for everything. Each unit is supposed to get slowly happier or unhappier based on his conditions. If he's in a comfortable region, constantly in good health, surrounded by happiness producing buildings, he slowly becomes happier and more productive. If he's in poor health, the city is crowded, and he's around pollution (another system I'm currently working on) he slowly becomes unhappy. I want these units to be able to move around without suddenly jumping from "very happy" to "massively unhappy" in .2 seconds. Also, auras would cause severe overlapping problems, since the only factors happiness affects are movement speed and attack speed. Now, if I could detect which auras are affecting a unit, and change aura descriptions appropriately, I could maintain my system and have it work much more efficiently. Now that I've elaborated, anyone have any advice? And sorry about the edit, Biflspud, I remembered to add it the second after I posted. |
| 11-24-2003, 11:47 PM | #11 | |
Quote:
He did? Oops sorry about that thenemote_sweat Hmm, what about haveing hidden abilitys that reresent differnt levels of hapieness, then use custon values to set these abilitys? I think that would cool down your lagg issue a little? |
| 11-25-2003, 12:18 AM | #12 |
I'm not quite sure what you're suggesting, Hunter, but if it is what I think it is that's pretty much what I'm doing. I have four modified "Item Attack Speed Bonus" abilities, for four levels of happiness. During the periodic happiness update, I cancel the previous ability assigned to the unit and give give it a new ability based on its happiness, as stored in the happiness array, of which I use the unit's custom value to pull out the right item in the array. I simply use the set movement speed action to modify unit sppeds appropriately. That much is working fine, and isn't really the cause of my lag. Sorry to sound like a broken record, but the lag causer is the method I use to determine which buildings are in range of which unit. I have to check the distance from every unit to every building I consider. That's total units in game * total happiness modifying buildings controlled by the player. If I have five players, and each player has 200 units and 50 buildings, that's 50,000 checks every ten seconds and the source of my problem. Considering the scale I want, this will make the map unplayable, not to mention buggy as hell. Now, if I could make each happiness affecting building give off a dummy aura, and then simply check which auras each unit is under the effect of, that would keep the number of triggers running under around 10,000 in the most performance intensive points. It would also be a lot easier to space these out, maybe having 1,000 checks per second instead of all of them at once. Unfortunately, there's no easy way to check which auras a unit is currently affected by, as far as I can tell. The other problem is that I don't want a unit to walk near a park and have a vampiric aura with the regular description pop up in his status box, when that would clealry be inappropriate for the map. Another small problem would be that buildings of the same type couldn't "stack" happiness bonuses, a problem but one I could live with. So, now that I think I've laid down my situation pretty clearly, can anyone help out? On a side not, I'm new to these forums, is there a section reserved for classifieds or is there a place I should go if I want to recruit help? Thanks in advance. |
| 11-25-2003, 01:11 AM | #13 |
Wait for warcraft 3 frozen throne patch 1.13 It gives you a buff editor, and then problem solved ;) |
| 11-25-2003, 01:12 AM | #14 |
Yeah, when is that being realised anyways? |
| 11-25-2003, 01:40 AM | #15 |
stop flooding the mans thread about a new WE that will come in "a few weeks" *scoff* anyway, heres what i did when i did something very much like this (a detection system for boats getting close to a dock...) what u need to do is get COMPLETELY rid of interval triggers (i.e every x seconds do THIS) u must make them a unit gets within, or a unit SOMETHING. in this way you will ONLY target that specific unit (or those 10-20 specific units), at any given second. now heres the catch, of corse you dont want the unit to go from Very happy to Very sad, so make another array (i assume your useing 1 for the happiness, using some kind of integer to represent each 1) just make this 1 another integer 1 named last_ten_seconds (or something like that) and make it start out at 0, set it to 10 for the unit that enters the region, and make 1 AND ONLY 1 trigger that runs every second, and loops through howver many units there are and says last_ten_seconds[x]=last_ten_seconds[x]-1, and finally add an if condition to the happyness check thing, that is now only run when unit does something (like walk within x pixels of a preplaced unit maybe?) that says if last_ten_seconds[x]=0 do everything else, do nothin. hope this helped, rate my bogus attachement if it did :P |
