• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Spell] Dynamic indexing, why is it better?

Status
Not open for further replies.
First of all I am pure gui coder, I avoid jass as much as possible, and use it only for some actions, not possible in gui.
So I was thinking that dynamic indexing is done with vJass and thats why I never used it, but now I see that it is also done in gui.

So can someone give me a bit detailed description why is better to use it for loop spells then classic indexing?
I want to learn this before I start my next map project.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
It's the idea of having blueprints for an object like a spell and then building from those blueprints, like a spell, every time you need one.

So rather than 1 constant static spell, you now have blueprints to make a spell and you just make that spell whenever you need it.

Hero A casts Meteor Shower, create a meteor shower then. Hero B casts meteor shower at the same time, create another meteor shower.

A unit is created, make a space for that unit to store data.

That's all it is =). To me, it makes more sense to create and destroy these things rather than to... i can't even fathom how you'd otherwise do it. 1 constant premade spell that is just inacted upon doesn't make much sense to me.
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
It doesn't have lesser action count => it's not as quick as a non-MUI spell (going by action count only); but I doubt it has any significant difference in speed.

Imo the most important aspect in speed is how efficiently you code it to make it MUI, as making spells MUI is probably the hardest part of the spell
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Making spells MUI is very easy. Although it may look a bit more difficult it is very easy. Assign a value to an array with the index of the maxIndex. That's how u store. To remove one remove and clean leaks. Then set the data of currentIndex or tempInt to the data of maxIndex. Then set the stuff at maxindex to null. Finally reduce tempInt and maxindex by one. It is rather an easy concept to grasp.

All spells are faster when they are instant spells because they use less processing. Less variables and don't need loops or a second trigger. But it's not a lot slower and if u want a cool spell it most likely wont be an instant spell.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Here are examples of dynamic and non dynamic indexing. They have similarities, both work like this.

When a spell is cast, the created instance is assinged a new index, always the last of the instance queue.
  • Set MaxIndex = (MaxIndex + 1)
  • Set Caster[MaxIndex] = (Triggering unit)

A spell is cast, no other instances are active:
Index1
Instance1

A spell is cast, while other instances are active:
Index12...MaxIndex
Instance12...MaxIndex

The indexes are looped through in the periodic trigger
  • For each (Integer CurrentIndex) from 1 to MaxIndex, do (Actions)

----

However, the deindexing differs.



When deindexing, a boolean is set to false to mark that the instance in inactive.
  • Set Boolean[CurrentIndex] = false

The loop checks each boolean before executing further actions
  • if Boolean[CurrentIndex] == true then
    • damage target
    • move unit
    • ...
  • endif

Here is what happens, example of four instances running
Index1234
Instance1234

Instance 2 expires for some reason, we mark it inactive, so basically it will not be run.
Index1234
Instance1x34

The max index is still 4, and the loop will go from 1 to 4, even though there are only three active instances.




When deindexing, the last instance is reassigned to the current index that we want to destroy
  • Set Caster[CurrentIndex] = Caster[MaxIndex]

The max index is decreased by one since one instance is now destroyed. We also decrease current index so the instance that was assigned for last to current is looped through next
  • Set MaxIndex = (MaxIndex - 1)
  • Set CurrentIndex = (CurrentIndex - 1)

Here is what happens, example of four instances running
Index1234
Instance1234

Instance 2 expires for some reason, we move instance from last index to the position of instance 2 and decrease the array size
Index123
Instance143

Current index is 2 at this point. Then current index is set to current - 1, which is 1. When the loop finishes, the loop index is increased by one, that happens in the background in GUI and does not need an extra action. The instance 4 in index 2 is run during the next loop.

There are some small issues with this, but nothing too major. The issue is that the order changes.

The instances run in order, 1-2-3-4 - 1-2-3-4..., but when an instance expires, the order changes. 1-2-3-4 - 1-2-3-4 - 1-4-3...

Instance 2 is destroyed, and at that point we see that instance 4 is run twice between two instance 3 runs.

So you see that even dynamic indexing isn't perfect. An even better way is to use a linked list.
 
Last edited:
Status
Not open for further replies.
Top