Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add projectile tracking #534

Merged
merged 10 commits into from
Jan 4, 2017
Merged

Add projectile tracking #534

merged 10 commits into from
Jan 4, 2017

Conversation

bux
Copy link
Contributor

@bux bux commented Oct 25, 2016

When merged this pull request will:

  • add a function to track projectiles as colored lines
    • uses hashes and PFHs and should be performing better than BIS_fnc_traceBullets
    • works with vehicles
    • color gradients for projectile speed (normalized for one projectile; green: fast, red: slow)


Why CBA?:

  • Useful for testing/diagnostics for a wider audience (mod makers, mission makers, communities)

TODO:

  • make line counts variable

drawLine3D [_prevProjectileData select 0, _currentProjectileData select 0, [_red, _green, 0, 1]];

_i = _i + 1;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while is pretty slow in SQF due to having to execute two code blocks each cycle. Maybe use forEach _projectileData with _currentProjectileData == _x.

};

// using 0.1 to improve performance, we don't need that many bullet position to draw a line
[FUNC(projectileTracking_trackProjectile), 0.1, [_projectile, _index]] call EFUNC(common,addPerFrameHandler);
Copy link
Contributor

@commy2 commy2 Oct 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CBA_fnc_addPerFrameHandler
CBA_fnc_hashGet
CBA_fnc_hashRem

@commy2
Copy link
Contributor

commy2 commented Oct 25, 2016

I think the slowest part about the BI functions is that it uses a too small resolution / too many lines per traced bullet.

@bux
Copy link
Contributor Author

bux commented Oct 28, 2016

I'm done. Testing local MP with two instances was working very well.

@bux bux changed the title WIP: Add projectile tracking Add projectile tracking Oct 28, 2016
@bux
Copy link
Contributor Author

bux commented Oct 28, 2016

20161028201111_1

20161028201206_1

@commy2
Copy link
Contributor

commy2 commented Oct 29, 2016

FPS VA, no tracked bullets: 99
FPS VA, 30 tracked bullets via CBA: 24
FPS VA, 30 tracked bullets via BIS fnc: 11

used:
player call cba_fnc_projectileTracking_addUnit
and
[player, 30] call BIS_fnc_traceBullets
and emptied one MX mag

So this is a >100% improvement. Very good.
But 99>24 is still bad. I'm wondering if we can't push this further?

@commy2
Copy link
Contributor

commy2 commented Oct 29, 2016

BIS_fnc_traceBullets has an optional parameter to limit the number of drawn projectiles. It defaults to 10.
Even when only 10 bullets are drawn, the FPS dips to 27 (so your function can basically draw thrice as many lines with the same cost)

  • CBA_fnc_projectileTracking_addUnit should be able to use this optional parameter too imo
  • We should somehow integrate this into this standard VA mission you can access from the main menu (we should also add a debug console to it)
  • I think the name is clumsy compared to the BI name "traceBullets". There is a rather nice naming convention with some new BI SQF commands that use setUnitX. CBA_fnc_setUnitTraceBullets with boolean parameter to turn it on and off? Or maybe CBA_fnc_addUnitTraceBullets, CBA_fnc_removeUnitTraceBullets?

@commy2 commy2 added the Feature label Oct 29, 2016
@commy2 commy2 added this to the 3.2 milestone Oct 29, 2016
@commy2 commy2 self-assigned this Oct 29, 2016

for "_index" from 0 to _maxLines do {

if ( ([GVAR(projectileData), _index] call CBA_fnc_hashHasKey) ) then {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are going for performance, we are doing an in and a find with hashHasKey and hashGet. We can probably skip one of them and just do a hashGet followed by a !isNil check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not convinced that we need CBA hashes for this in the first place. I mean, this should be possible simply by iterating through an array, shouldn't it be?

@bux
Copy link
Contributor Author

bux commented Oct 31, 2016

CBA_fnc_projectileTracking_addUnit should be able to use this optional parameter too imo

I've decided against using an optional parameter:

  1. Too much hassle
  2. It doesn't make sense for the "addUnit" function because the amount of paths drawn is not per unit but globally. Imo it's easier to just set a global variable to a different number.
  3. I've set the function to max draw 20 paths even if a user enters e.g. 150

We should somehow integrate this into this standard VA mission you can access from the main menu (we should also add a debug console to it)

?

I think the name is clumsy compared to the BI name "traceBullets". There is a rather nice naming convention with some new BI SQF commands that use setUnitX. CBA_fnc_setUnitTraceBullets with boolean parameter to turn it on and off? Or maybe CBA_fnc_addUnitTraceBullets, CBA_fnc_removeUnitTraceBullets?

The thing is, you don't only track bullets. Everything that triggers the "Fired" EH. That's why I went with "projectile".
I could change the public function names to cba_fnc_addUnitTraceProjectiles

Not convinced that we need CBA hashes for this in the first place. I mean, this should be possible simply by iterating through an array, shouldn't it be?

I've started this thing as an exercise for me to get to know PFHs and hashes more. That's why I used hashes in the first place. I'll look into changing it into a standard array.

@bux
Copy link
Contributor Author

bux commented Nov 6, 2016

@commy2 I've committed some of your requested changes.

No Tracking
         CBA   BI   
    FPS: 180 / 180

3 Projectiles
    FPS: 155 / 138

4 Projectiles
    FPS: 132 / 125

10 Projectiles
    FPS: 85 / 82

15 Projectiles
    FPS: 67 / 60

20 Projectiles
    FPS: 50 / 40

@Killswitch00 Killswitch00 merged commit f9b572d into CBATeam:master Jan 4, 2017
@bux bux deleted the projectileTracking branch January 14, 2017 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants