• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Deindexing Partial Loops

Status
Not open for further replies.
Hello! I'm working on something and will post the answer here if I find it - but someone else may already have it. Does anyone know how I would structure a loop that tracks a spell ( Spell[spells_total] ) but also tracks a variable number of special effects ( 4 ) that are attached to said spell? I believe I know how to write it, but I'm having trouble deindexing it (More specifically: Handling items in the subloop).

For Each LoopCount from 1 - Spelltotal
Deal damage of spell
|> For each Subloopcount from LoopCount to (LoopCount + Subloopcount)
|> Destroy Special Effect [LoopCount +SubLoopCount]
|> Exit when (LoopCount + SubLoopCount) = (LoopCount + EffectsOnThisSpell[LoopCount])

That's my basic idea, if that's even readable to anyone. I only listed the special effect since that's the only thing having problems in my current iteration. Thanks for checking in!
 
Well I fixed it by reversing the deindexing on the anchorpoint variable to deindex from Anchor [total spells] = Anchor [loop count].
The anchor point told each spell where to start from in the index. If anchor is 14 and total effects for this spell is 4 it will check effects 15-18. The normal deindexing would replace your current number with [total spells] but the anchor would still have the number associated with it being in the last position, so reversing it allowed the anchor to inherit the anchor point for the spell that just got deindexed.

Normally I'm very eloquent but I'm so tired today. hopefully that makes sense to someone.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
There are two approaches to solve this problem.
  • Give each spell a reference to a special effect list dynamic data structure backed by a different set of arrays. This could be a linked list for example and could be shared between multiple systems. The reference could be the index of the list head or tail and the list itself could hold any reasonable number of elements. Manging your spell indices is trivial since the reference is stored in an integer array at the spell index as part of the spell array set.
  • Add a 2D array member to the spell array set. Using some simple maths one can divide a continuous integer number space into equal length chunks of a fixed size, which can each act as their own array. Since at most 4 special effects can occur, this is a viable solution for your problem. The special effects would be stored at {SpellIndex x 4 + SpecialEffectIndex}. Each SpellIndex has a set of 4 special effect storage locations which together with SpecialEffectIndex can uniquely store a special effect. The result is often called a multi dimensional array such as a 2D array in this case, but there is no real limit to the number of dimensions one could create like this. The disadvantage is that the maximum value of SpellIndex is decreased due to JASS arrays having a maximum size, but this is of no concern for this case.
I would recommend the 2D array approach. The logic is a lot simpler than trying to dynamically allocate array space for the effects using the same spell index and does not have to deal with fragmentation or any such problems. Yes it will always allocate space for 4 special effects for every spell index even if not required, but this is of no concern. If you plan to move index data around, one can bulk copy all 4 special effect indices for the spell index which is trivial.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Yes I presently have a functioning 2d one, but I am trying to make it dynamic as I would prefer that if I am capable of actually creating it.
The linked list approach could then work. I still recommend avoiding continuous allocation since that is very complicated for something that does not really need it.

If using Lua one can trivially use a table as a list. This is a native dynamic data structure and likely the highest performance of the options.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
@Dr Super Good , I'm not terribly versed in lua. Would you consider Lua a more powerful language overall to write a map with? Or are there some things jass can do that Lua can't?
Generally Lua has fewer limits than JASS. The main issue with it is that it is currently less stable than JASS. Hopefully 1.32 or future versions fix this.
 
Good to know, browsing the forums seemed to indicate that was kind of what was going on.

Another question if you don't mind. (sorry im so asky lately, normally I can spend more time researching, but I'm trying to use this in a contest I've entered)

The main problem with the trigger is that having spells with a different number of effects run through the same system will cause the effect references to be split when deindexed during a resolution that had more or less effects than the next iteration. Which is what would necessitate the Linked List (which im still trying to learn how to make). Alternatively could you: Choose not to deindex certain elements such as the effect iteration position until TotalCasters = 0 (or in other words clean it up at the very end?) Or is that a bad idea.

Lastly, I believe in general people say 3d arrays are a bad idea unless achieved via the pseudo-3d array style you listed earlier. Is this true?
 
Level 39
Joined
Feb 27, 2007
Messages
5,031
Set a maximum number of effects (4 I believe you said above) and always allocate slots for that many effects in each instance regardless of how many you actually need. It will then be easy to swap instances when one ends like normal dynamic indexing. Again, Bone Armor has a good example of this where he uses BAmr_SegCValue.
 
@Pyrogasm Sorry, I poorly worded my initial post. The limit on effects is not 4, but potentially up to 100 per spell (boss spell). This is why I am trying to build a dynamic system so that a spell that only uses 2 effects won't occupy 100 slots. I can clean up the trigger and post the actual thing if you think that would help, but it's a handful.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
@Pyrogasm Sorry, I poorly worded my initial post. The limit on effects is not 4, but potentially up to 100 per spell (boss spell). This is why I am trying to build a dynamic system so that a spell that only uses 2 effects won't occupy 100 slots. I can clean up the trigger and post the actual thing if you think that would help, but it's a handful.
100 slots per cast is not a concern. Even 200 casts of the ability should still work.
 
Status
Not open for further replies.
Top