Forged Alliance Forever Forged Alliance Forever Forums 2014-06-14T17:40:38+02:00 /feed.php?f=42&t=7603 2014-06-14T17:40:38+02:00 2014-06-14T17:40:38+02:00 /viewtopic.php?t=7603&p=75356#p75356 <![CDATA[Re: Shield damage transfer rework]]>
There is a slight optimization we could do though.

Right now we spawn n * k threads to wait 1 tick, where n is the shields hit by the AoE and k are the shields affected by overspill.

We could do with just n threads instead, doing the double-damage check on the shield that does the overspill rather than on the shield that receives it.

Statistics: Posted by Sheeo — 14 Jun 2014, 17:40


]]>
2014-06-14T16:57:36+02:00 2014-06-14T16:57:36+02:00 /viewtopic.php?t=7603&p=75350#p75350 <![CDATA[Re: Shield damage transfer rework]]> Statistics: Posted by IceDreamer — 14 Jun 2014, 16:57


]]>
2014-06-14T16:07:36+02:00 2014-06-14T16:07:36+02:00 /viewtopic.php?t=7603&p=75346#p75346 <![CDATA[Re: Shield damage transfer rework]]> Can someone else test if he gets performance issues with this mod?

Whatever the solution is, it should fix the issue of course, but also be efficient in terms of computations to prevent multiplayer games to become a slide show when shields and AOE are involved.

EDIT: false alarm, further testing didn't produce slowdowns (probably a lua cache update on my end) so that's promising.

Statistics: Posted by pip — 14 Jun 2014, 16:07


]]>
2014-06-14T15:48:59+02:00 2014-06-14T15:48:59+02:00 /viewtopic.php?t=7603&p=75345#p75345 <![CDATA[Re: Shield damage transfer rework]]>
Brute51 wrote:
Good one about the floating point thing. In Supcom it happens quite often that it is "almost" a round number, especially in the UI code. I'll try to remember it for future things. Its not straight forward when you have to use it because variable types are implicitely defined.


Yeah, there are probably a few subtle bugs around this elsewhere in the codebase :) It's a tricky thing to remember when you don't have the types right there.

Brute51 wrote:
The registering thing does not always return false. It actually seems to work ok in most cases. But given that there's a floating point comparison like you mentioned it is partially "luck" that it returns true.

The absorbion is used to take advantage of the shield absorbtion logic in the game and because we only want to spill over the actual damage done to the shield, not the projectile damage. For example when the shield has less HP than the damage the projectile deals you still want to spill over the damage to the shield, not the projectile damage. You're right that in the current code this could damage the shield twice for the same projectile, but changing "absorbed" to "projectile damage" is not the way to fix it. It may work in many layered shield situations but it is more complex than that.


True, but we need to pass on the absorbed damage along with the actual damage given. This way, we can check whether we took the original damage, or spillover from it, and still apply proper absorbed damage from the first shield.

It's still not perfect, since whichever shield has its OnDamage function called first, gets to decide how much damage is spilled over. This is an implementation detail of the DamageArea C-function defined in Projectile, so there's going to be a bit of 'randomness' when multiple, different-hp shields are hit by the same projectile.

The only way I see around this is to rework the DamageArea function in lua, but I'm not too keen on that, and don't think a little randomness like this is a big deal.

I suppose you could wait an extra tick and have all the shields propagate spillover values without applying, and then finally just applying the smallest one. This seems like a bad idea though, especially with many shields.

Brute51 wrote:
Adding a GetAdjacentShields function seems like a good change.

We both have a fix, nice. I'll have a look at your code but what do we do now?


IceDreamer uploaded a new version of the spillover mod. Take a look at that, perhaps post your own code -- and we can discuss here what needs to be done?

I definitely think this fix is top priority.

Statistics: Posted by Sheeo — 14 Jun 2014, 15:48


]]>
2014-06-14T11:24:37+02:00 2014-06-14T11:24:37+02:00 /viewtopic.php?t=7603&p=75330#p75330 <![CDATA[Re: Shield damage transfer rework]]>
As you'll see when you look at the mod, we've solved the internal reflection and all the problems with absorbed damage vs original damage by taking the shield HP modification code out of OnDamage and creating a new ApplyDamage function containing it, which we call from OnDamage and the spillover damage application function. Works a charm.

Statistics: Posted by IceDreamer — 14 Jun 2014, 11:24


]]>
2014-06-14T10:51:01+02:00 2014-06-14T10:51:01+02:00 /viewtopic.php?t=7603&p=75328#p75328 <![CDATA[Re: Shield damage transfer rework]]>
Sheeo wrote:
Brute51 wrote:Not yet, was watching the football game just now. We won :-)

There's no errors here at all. My code seems quite good still, given the complexity of the whole feature (don't under estimate it). Are you sure its not your set up that's causing problems?



The registrering/prevention of overspill from the same instigator wasn't working (Always returned false).

Aside from that, it wouldn't work even if it were in the right place. It was storing the absorbed shield damage, and using that to test for incoming overspill.

Say an ahwassa directly hits shield 1 (1000 hp) and 2 (2000 hp). These shields overlap with 3 and 4.

3 and 4 would take 0.15*1000hp and 0.15*2000hp in overspill, because they both stored the absorbed value which differ.

You had a floating point comparison using ==, which is fragile -- floating points chould always be compared using an epsilon value. I.e.
Code:
if math.abs(f1 - f2) < 0.01 then ... end
, never
Code:
if f1 == f2 then ...
.


Don't worry, I haven't rewritten the whole thing and the idea in the algorithm is fine.

The only refactoring I've done is created a GetAdjacentShields function and passed the absorbed damage around to the threadfunction, for debugging purposes.


So after a little more work with IceDreamer we finally have a working fix.




Good one about the floating point thing. In Supcom it happens quite often that it is "almost" a round number, especially in the UI code. I'll try to remember it for future things. Its not straight forward when you have to use it because variable types are implicitely defined.

The registering thing does not always return false. It actually seems to work ok in most cases. But given that there's a floating point comparison like you mentioned it is partially "luck" that it returns true.

The absorbion is used to take advantage of the shield absorbtion logic in the game and because we only want to spill over the actual damage done to the shield, not the projectile damage. For example when the shield has less HP than the damage the projectile deals you still want to spill over the damage to the shield, not the projectile damage. You're right that in the current code this could damage the shield twice for the same projectile, but changing "absorbed" to "projectile damage" is not the way to fix it. It may work in many layered shield situations but it is more complex than that.

Adding a GetAdjacentShields function seems like a good change.



We both have a fix, nice. I'll have a look at your code but what do we do now?

Statistics: Posted by Brute51 — 14 Jun 2014, 10:51


]]>
2014-06-14T07:27:02+02:00 2014-06-14T07:27:02+02:00 /viewtopic.php?t=7603&p=75323#p75323 <![CDATA[Re: Shield damage transfer rework]]> Statistics: Posted by IceDreamer — 14 Jun 2014, 07:27


]]>
2014-06-14T00:36:12+02:00 2014-06-14T00:36:12+02:00 /viewtopic.php?t=7603&p=75309#p75309 <![CDATA[Re: Shield damage transfer rework]]>
Brute51 wrote:
Not yet, was watching the football game just now. We won :-)

There's no errors here at all. My code seems quite good still, given the complexity of the whole feature (don't under estimate it). Are you sure its not your set up that's causing problems?



The registrering/prevention of overspill from the same instigator wasn't working (Always returned false).

Aside from that, it wouldn't work even if it were in the right place. It was storing the absorbed shield damage, and using that to test for incoming overspill.

Say an ahwassa directly hits shield 1 (1000 hp) and 2 (2000 hp). These shields overlap with 3 and 4.

3 and 4 would take 0.15*1000hp and 0.15*2000hp in overspill, because they both stored the absorbed value which differ.

You had a floating point comparison using ==, which is fragile -- floating points chould always be compared using an epsilon value. I.e.
Code:
if math.abs(f1 - f2) < 0.01 then ... end
, never
Code:
if f1 == f2 then ...
.


Don't worry, I haven't rewritten the whole thing and the idea in the algorithm is fine.

The only refactoring I've done is created a GetAdjacentShields function and passed the absorbed damage around to the threadfunction, for debugging purposes.


So after a little more work with IceDreamer we finally have a working fix.

Statistics: Posted by Sheeo — 14 Jun 2014, 00:36


]]>
2014-06-14T00:08:37+02:00 2014-06-14T00:08:37+02:00 /viewtopic.php?t=7603&p=75307#p75307 <![CDATA[Re: Shield damage transfer rework]]> http://s356.photobucket.com/user/aeoncl ... 7.jpg.html

As for the rest of it, the code and what's being done to it is a bit beyond me.

Statistics: Posted by IceDreamer — 14 Jun 2014, 00:08


]]>
2014-06-14T00:05:56+02:00 2014-06-14T00:05:56+02:00 /viewtopic.php?t=7603&p=75306#p75306 <![CDATA[Re: Shield damage transfer rework]]>
Brute51 wrote:
Not yet, was watching the football game just now. We won :-)

There's no errors here at all. My code seems quite good still, given the complexity of the whole feature (don't under estimate it). Are you sure its not your set up that's causing problems?


It was very quiet in the public transport yeah :mrgreen:

Statistics: Posted by E8400-CV — 14 Jun 2014, 00:05


]]>
2014-06-13T23:39:08+02:00 2014-06-13T23:39:08+02:00 /viewtopic.php?t=7603&p=75305#p75305 <![CDATA[Re: Shield damage transfer rework]]>
I think i've identified the cause of the problem.

Statistics: Posted by Brute51 — 13 Jun 2014, 23:39


]]>
2014-06-13T23:25:47+02:00 2014-06-13T23:25:47+02:00 /viewtopic.php?t=7603&p=75304#p75304 <![CDATA[Re: Shield damage transfer rework]]> Statistics: Posted by IceDreamer — 13 Jun 2014, 23:25


]]>
2014-06-13T23:06:06+02:00 2014-06-13T23:06:06+02:00 /viewtopic.php?t=7603&p=75302#p75302 <![CDATA[Re: Shield damage transfer rework]]>

There's no errors here at all. My code seems quite good still, given the complexity of the whole feature (don't under estimate it). Are you sure its not your set up that's causing problems?

Statistics: Posted by Brute51 — 13 Jun 2014, 23:06


]]>
2014-06-13T22:53:07+02:00 2014-06-13T22:53:07+02:00 /viewtopic.php?t=7603&p=75301#p75301 <![CDATA[Re: Shield damage transfer rework]]> Statistics: Posted by pip — 13 Jun 2014, 22:53


]]>
2014-06-13T22:47:23+02:00 2014-06-13T22:47:23+02:00 /viewtopic.php?t=7603&p=75300#p75300 <![CDATA[Re: Shield damage transfer rework]]> Statistics: Posted by IceDreamer — 13 Jun 2014, 22:47


]]>