• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Streamlining my movement system

Status
Not open for further replies.
Level 14
Joined
Aug 30, 2004
Messages
909
On some advice I received here, I am trying to streamline my movement system for a dogfighting map I'm making. I would like some advice on how to use a list.

Here is the situation:

I have ships, missiles and lasers stored in a unit array. Their position in the array is stored in their custom value. Arrays of other interesting variables relating to the units are also stored that way, so the ship whose custom value is 5, for example, is moving at: MoveSpeed[5], toward MovePoint[5], with LaserStrength[5].

Ship movement is caused by a "For every Integer A 1 to 100 loop" that counts through the whole list moving each ship, missile and laser in turn. This is inefficient, though, as at any time there is likely only 20 units in that array. I was told to make the loop from 1 to "the number of units in the array" so the computer doesn't have to loop 100 times every .02 seconds when it really only has to loop 20 times.

Here's my problem. The units die at different times, so the array will rarely look like this:

1- Xwing Fighter
2- Tie Fighter
3- Laser
4- Laser
5- Concussion Missile
6- no unit
7- no unit

etc.

Usually it will look like this:

1- Xwing
2- Tie Fighter
3- no unit
4- no unit
5- Concussion Missile
6- no unit
7- Ywing

This means that the total number of units I have is 4, but I can't just loop from 1 to 4 because the concussion missile in slot 5 and Ywing in slot 7 will never move.

Here are two solutions I thought of, please let me know if one is best or if there is one I haven't thought of. I know how to use Custom Scripts to remove leaks and such, and to move units, but I don't know JASS proper.

Solution 1: Keep track of the total number of units in the list. Then, when a unit dies, if it is not the highest number, copy the highest numbered unit into the new slot. In other words, when unit 3 dies, copy unit 5 into slot three. This involves storing about 12 variables (e.g., set LaserStrength[3] = LaserStrength[5]) every time a unit dies.

Solution 2: Keep all the units in a unit group. So FliersUnitGroup would equal: Xwing, Tie, laser, laser, and concussion missile. Then, instead of looping from 1-100, I would pick every unit in FliersUnitGroup and move it. This unitgroup would vary in size from about 10 to 80.

Thank you.

Darwin
 
Level 2
Joined
Jul 1, 2010
Messages
14
Another solution could be to replace a dying unit with a dummy unit in the array, but on the other hand, that would just cause even more problems.

I think your second solution is the best. You need a dynamical datastructure, which adjust according to the data you store in it, and for that purpose, a unit group is in my opinion the best choice, when you're using GUI.
 
Level 14
Joined
Aug 30, 2004
Messages
909
I think your second solution is the best. You need a dynamical datastructure, which adjust according to the data you store in it, and for that purpose, a unit group is in my opinion the best choice, when you're using GUI.

Thank you, I'll give that a shot. +rep

UPDATE: Worked great. My FPS went up from 38-40 to about 48.
 
Last edited:
Status
Not open for further replies.
Top