wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > Code Resources > Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-24-2009, 07:23 PM   #1
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default AutoIndex

Optional add-on library: AutoEvents

AutoIndex is a very simple script to utilize. Just call GetUnitId(unit) to get get the unique value assigned to a particular unit. The GetUnitId function is extremely fast because it inlines directly to a GetUnitUserData call. AutoIndex automatically assigns an ID to each unit as it enters the map, and instantly frees that ID as the unit leaves the map. Detection of leaving units is accomplished in constant time without a periodic scan.

AutoIndex uses UnitUserData by default. If something else in your map would conflict with that, you can set the UseUnitUserData configuration constant to false, and a hashtable will be used instead. Note that hashtables are about 60% slower.

If you turn on debug mode, AutoIndex will be able to display several helpful error messages. The following issues will be detected:
  • Passing a removed or decayed unit to GetUnitId
  • Code outside of AutoIndex has overwritten a unit's UserData value.
  • GetUnitId was used on a filtered unit (a unit you don't want indexed).

AutoIndex provides events upon indexing or deindexing units. This effectively allows you to notice when units enter or leave the game. Also included are the AutoData, AutoCreate, and AutoDestroy modules, which allow you to fully utilize AutoIndex's enter/leave detection capabilities in conjunction with your structs.

Expand JASS:

Last edited by grim001 : 02-06-2010 at 01:58 PM.
grim001 is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-24-2009, 07:41 PM   #2
moyack
Evil Emoticon
 
moyack's Avatar


Respected User
Project Leader: PoC
 
Join Date: Jan 2006
Posts: 3,263

Submissions (17)

moyack is a splendid one to behold (661)moyack is a splendid one to behold (661)moyack is a splendid one to behold (661)moyack is a splendid one to behold (661)

AI Tournament #2 - 2nd PlaceHero Contest - Second place

Send a message via MSN to moyack
Default

Lol, your comments are longer that the code itself.... that's what I call a good code. Seriously. :)
moyack is offline   Reply With Quote
Old 04-24-2009, 07:59 PM   #3
akolyt0r
In Flames
 
akolyt0r's Avatar
 
Join Date: Jan 2006
Posts: 1,153

Submissions (3)

akolyt0r has a spectacular aura about (120)

Default

CON: you can only have 8190 units totally in your map, with regular unit-indexing, you can have 8190 indexed units in your map.

This will for example index dummy units aswell, and if you got really many triggered spells in a 12 player map with lots of units/heros/whatsoever this might hit the limit...

maybe this system shouldnt index dummy units (+= one dummy unitid constant ..), dunno...
I would add this as an optional condition ...
__________________
akolyt0r is offline   Reply With Quote
Old 04-24-2009, 08:00 PM   #4
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

CON: Warcraft 3 crashed a long time before you had 8000 units in your map.
grim001 is offline   Reply With Quote
Old 04-25-2009, 02:32 AM   #5
Magissia
User
 
Magissia's Avatar
 
Join Date: Mar 2009
Posts: 72

Magissia has little to show at this moment (4)

Default

In this map (look attachments)

A trigger spawn 8000 footmans, my computer don't crashed, just had some strange polys' that go away

So the game don't crash before 8000 units please
Attached Images
File Type: png screen.PNG (2.64 MB, 379 views)
Attached Files
File Type: w3x 8000 footman.w3x (275.2 KB, 27 views)
__________________
1337 0\/// )4 \/021)

F**k patch 3.1.0 and 3.1.1
Magissia is offline   Reply With Quote
Old 04-25-2009, 03:08 AM   #6
akolyt0r
In Flames
 
akolyt0r's Avatar
 
Join Date: Jan 2006
Posts: 1,153

Submissions (3)

akolyt0r has a spectacular aura about (120)

Default

no problem to have 8000 dummy units ...
Attached Images
File Type: jpg WC3ScrnShot_042509_050340_01.jpg (56.1 KB, 267 views)
__________________
akolyt0r is offline   Reply With Quote
Old 04-25-2009, 03:13 AM   #7
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

The answer is: no.
grim001 is offline   Reply With Quote
Old 04-25-2009, 03:14 AM   #8
dead_or_alivex
User
 
Join Date: Jun 2008
Posts: 72

dead_or_alivex has little to show at this moment (3)

Default

^ His point was that most maps don't reach the limit so easily. In any case, couldn't struct storage space simply be increased to handle more than 8190 units? (Edit: Oops, posted a bit late. I was responding to Magissia.)

Amazingly concise for something so elaborate - great job.

Quote:
I am tired of the issues associated with H2I(u)-0x100000
What issues are these? (I use that method quite a bit.)

Last edited by dead_or_alivex : 04-25-2009 at 03:14 AM.
dead_or_alivex is offline   Reply With Quote
Old 04-25-2009, 03:35 AM   #9
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Increasing storage space would have no effect on performance except when allocating or freeing an ID. All you would have to do is add [size] next to the AutoIndex struct declaration. So it would be a great idea, except that no real map has ever, or will ever, be created that uses more than 8000 units at the same time. I'm not going to respond to any more stuff about that since it is so outlandish that it doesn't warrant discussion.

dead_or_alivex, before this I used H2I(u)-0x100000 all the time, so I think it is the next best option. But here are the downsides compared to automatic unit indexing:
1.) It is slower.
2.) It is possible to break it if handles get too high (rarely a problem in practice)
3.) It forces you to type a lot of code in every system (arrays, set/get functions, MaxHandles constant).
4.) It generates even mode code once compiled because of bigarrays.
5.) You are obligated to include a note explaining how the user should deal with the MaxHandles constant in every system.
grim001 is offline   Reply With Quote
Old 04-25-2009, 11:45 AM   #10
Captain Griffen
Dread Lord of the Cookies
 
Captain Griffen's Avatar


Content Director
 
Join Date: Sep 2003
Posts: 5,367

Submissions (2)

Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)Captain Griffen is a glorious beacon of light (497)

Approved Map: Warlords[Quicksilver #2] - 1st Place

Default

If you're using 8000 units in a map, you're doing it wrong.

Anyway...I think you should have a GetUnitId function. It'll get inlined, but it'll make it far more implementation independant, and make systems much more interoperable (which, given you can only have one unit indexing system in a map using GetUnitUserData...is incredibly important). Not using a wrapper function because you think it's cooler really doesn't cut it now that they have no performance hit and provide potentially important forward/backward compatability.
__________________
Quote:
Originally Posted by Earth-Fury
Griffen is correct, you are not.
Quote:
[13:32] <Akolyt0r> hmm.. stil i want to have some unused women
Captain Griffen is offline   Reply With Quote
Old 04-25-2009, 03:05 PM   #11
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

Quote:
2.) It is possible to break it if handles get too high (rarely a problem in practice)
Not that rare.

It requires a very messed up map, but for some reason those maps are not rare.

Like Griffen said, Make a GetUnit**** function thingy. Guys wanting speed can make it dependent on the UserData implementation (Err, not really, it'll get inlined) but if there was a GetUnit*** function you wouldn't have to make it dependent.

You can make an AutoIndex that uses handle table, Table's only problem was the lack of auto destruction, this effectively fixes it . People that already use UserData in one of those zillion other systems could just use the Table version if they had to implement a system/spell requiring it. The rest, would still see the UserData native inlined anyway. Sounds like win-win to me...

Quote:
Increasing storage space would have no effect on performance except when allocating or freeing an ID.
In order to actually be able to use the index, you would need to also enlarge the arrays to which this is used as index.

Could just have an exceptions list/hash for typeids - assuming this problem is actually important.
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 04-25-2009, 04:59 PM   #12
Mr.Malte
User
 
Mr.Malte's Avatar
 
Join Date: Apr 2008
Posts: 286

Submissions (2)

Mr.Malte is on a distinguished road (11)

Default

I think it could make some maps really slower.
In my map for example, I've got a spell which creates 45 units per second.
If you implement this library, that spell would lag, wouldn't it.
Also if you don't use this a lot, it could be slower than other systems. Anyways, I am gonna do speed tests with this.
Mr.Malte is offline   Reply With Quote
Old 04-25-2009, 05:21 PM   #13
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,905

Submissions (37)

Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)Vexorian has a reputation beyond repute (1060)

Hero Contest #3 - 2nd Place

Default

Quote:
I think it could make some maps really slower.
In my map for example, I've got a spell which creates 45 units per second.
If you implement this library, that spell would lag, wouldn't it.
no?

Quote:
Also if you don't use this a lot, it could be slower than other systems. .

???
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote
Old 04-25-2009, 05:49 PM   #14
Mr.Malte
User
 
Mr.Malte's Avatar
 
Join Date: Apr 2008
Posts: 286

Submissions (2)

Mr.Malte is on a distinguished road (11)

Default

Ok. Then I'll test this.
This seems great.
Mr.Malte is offline   Reply With Quote
Old 04-25-2009, 07:04 PM   #15
grim001
requires vJass
 
grim001's Avatar


Code Moderator
 
Join Date: Nov 2006
Posts: 1,540

Submissions (10)

grim001 is just really nice (277)grim001 is just really nice (277)

Send a message via AIM to grim001
Default

Quote:
Originally Posted by Captain Griffen
I think you should have a GetUnitId function.
Done.

Quote:
Originally Posted by Vexorian
You can make an AutoIndex that uses handle table
Pretty good idea, handle table would not have been possible if you are relying on the UnitUserData becomes 0 trick for removal detection, but with this, any storage method is possible.

So I'll make it as soon as you make Table initialize its gamecache in a struct init, otherwise it would fail on every unit entering the map or created from a a unitEntersMap method.

Quote:
Originally Posted by Mr.Malte
I think it could make some maps really slower.
In my map for example, I've got a spell which creates 45 units per second.
Seriously, creasing 45 units per second will lag your map. If you need to do something like that, you should recycle those units. Indexing an entering unit is like 0.001% of the cost of actually creating a unit.

Last edited by grim001 : 04-25-2009 at 07:27 PM.
grim001 is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 06:19 PM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services