Skip to content

Commit

Permalink
fix #6060
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Oct 30, 2018
1 parent 4cfc937 commit 7d65ea5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc/changelog.txt
Expand Up @@ -117,6 +117,7 @@ Misc:
- use SHA2 content hashes rather than CRC32

Fixes:
- fix #6060 (Max{Nano}Particles=0 still allowing 1 {nano}particle to spawn)
- fix #6059 (units with high turnRate/brakeRate/acceleration moving unexpectedly)
- fix #4268 (add Spring.AddObjectDecal)
- fix #4755 (wrong usage of addr2line on FreeBSD)
Expand Down
10 changes: 7 additions & 3 deletions rts/Sim/Projectiles/ProjectileHandler.cpp
Expand Up @@ -37,8 +37,8 @@
#define HIGH_NANO_PRIO 1.0f


CONFIG(int, MaxParticles).defaultValue(10000).headlessValue(1).minimumValue(1);
CONFIG(int, MaxNanoParticles).defaultValue(2000).headlessValue(1).minimumValue(1);
CONFIG(int, MaxParticles).defaultValue(10000).headlessValue(0).minimumValue(0);
CONFIG(int, MaxNanoParticles).defaultValue(2000).headlessValue(0).minimumValue(0);


CR_BIND(CProjectileHandler, )
Expand Down Expand Up @@ -786,7 +786,11 @@ float CProjectileHandler::GetParticleSaturation(bool randomized) const
// use the random mult to weaken the max limit a little
// so the chance is better spread when being close to the limit
// i.e. when there are rockets that spam CEGs this gives smaller CEGs still a chance
return (GetCurrentParticles() / float(maxParticles)) * (1.0f + int(randomized) * 0.3f * guRNG.NextFloat());
const float total = std::max(1.0f, maxParticles * 1.0f);
const float fract = GetCurrentParticles() / total;
const float rmult = 1.0f + (int(randomized) * 0.3f * guRNG.NextFloat());

return (fract * rmult);
}

int CProjectileHandler::GetCurrentParticles() const
Expand Down
13 changes: 9 additions & 4 deletions rts/Sim/Projectiles/ProjectileHandler.h
Expand Up @@ -48,13 +48,18 @@ class CProjectileHandler
void CheckGroundCollisions(ProjectileContainer&);
void CheckCollisions();

void SetMaxParticles(int value) { maxParticles = value; }
void SetMaxNanoParticles(int value) { maxNanoParticles = value; }
void SetMaxParticles(int value) { maxParticles = std::max(0, value); }
void SetMaxNanoParticles(int value) { maxNanoParticles = std::max(0, value); }

void Update();

float GetNanoParticleSaturation(float priority) const { return std::min(1.0f, (currentNanoParticles / (maxNanoParticles * priority))); }
float GetParticleSaturation(bool randomized = true) const;
float GetNanoParticleSaturation(float priority) const {
const float total = std::max(1.0f, maxNanoParticles * priority);
const float fract = currentNanoParticles / total;
return std::min(1.0f, fract);
}

int GetCurrentParticles() const;

void AddProjectile(CProjectile* p);
Expand All @@ -72,7 +77,7 @@ class CProjectileHandler
void AddNanoParticle(const float3, const float3, const UnitDef*, int team, float radius, bool inverse, bool highPriority);

public:
int maxParticles = 0; // different effects should start to cut down on unnececary(unsynced) particles when this number is reached
int maxParticles = 0;
int maxNanoParticles = 0;
int currentNanoParticles = 0;

Expand Down

0 comments on commit 7d65ea5

Please sign in to comment.