Skip to content

Commit 0edb67e

Browse files
committed
Added ParticleCount to Emissions, which sets how many particles they spawn per emission, and made Emissions with InheritsVel inherit velocity and angular velocity from the spin of its root parent.
1 parent c9859e9 commit 0edb67e

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5252

5353
- Allow lua scripts to use LuaJIT's BitOp module (see https://bitop.luajit.org/api.html)
5454

55+
- New `Emission` INI and Lua (R/W) property `ParticleCount` which sets how many particles the Emission spawns per emission.
56+
5557
</details>
5658

5759
<details><summary><b>Changed</b></summary>
@@ -83,6 +85,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8385

8486
- Almost all ctrl+* special inputs functionality (i.e restarting activity, world dumps, showing performance stats) are now mapped to right alt, to not interfere with default crouching inputs. The only exception is ctrl+arrow keys for changing console size.
8587

88+
- `Emissions` with `InheritsVel` now also inherit velocity and angular velocity derived from the angular velocity of the parent.
89+
8690
</details>
8791

8892
<details><summary><b>Fixed</b></summary>

Source/Entities/AEmitter.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,14 @@ void AEmitter::Update() {
446446
scale = m_BurstScale;
447447
}
448448
emissionCountTotal += emissionCount;
449+
if (emissionCount > 0) {
450+
int extraEmissions = emission.GetParticleCount() - 1;
451+
emissionCount += extraEmissions;
452+
}
449453
pParticle = 0;
450454
emitVel.Reset();
451455
parentVel = pRootParent->GetVel() * emission.InheritsVelocity();
456+
Vector rotationalVel = (((RotateOffset(emission.GetOffset()) + (m_Pos - pRootParent->GetPos())) * pRootParent->GetAngularVel()).GetPerpendicular() / c_PPM) * emission.InheritsVelocity();
452457

453458
for (int i = 0; i < emissionCount; ++i) {
454459
velMin = emission.GetMinVelocity() * scale;
@@ -472,8 +477,9 @@ void AEmitter::Update() {
472477
emitVel.SetXY(velMin + RandomNum(0.0F, velRange), 0.0F);
473478
emitVel.RadRotate(m_EmitAngle.GetRadAngle() + spread * RandomNormalNum());
474479
emitVel = RotateOffset(emitVel);
475-
pParticle->SetVel(parentVel + emitVel);
480+
pParticle->SetVel(parentVel + rotationalVel + emitVel);
476481
pParticle->SetRotAngle(emitVel.GetAbsRadAngle() + (m_HFlipped ? -c_PI : 0));
482+
pParticle->SetAngularVel(pRootParent->GetAngularVel() * emission.InheritsVelocity());
477483
pParticle->SetHFlipped(m_HFlipped);
478484

479485
// Scale the particle's lifetime based on life variation and throttle, as long as it's not 0

Source/Entities/Emission.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void Emission::Clear() {
2323
m_StopTimer.SetSimTimeLimitMS(1000000);
2424
m_StopTimer.Reset();
2525
m_Offset.Reset();
26+
m_ParticleCount = 1;
2627
}
2728

2829
/*
@@ -49,6 +50,7 @@ int Emission::Create(const Emission& reference) {
4950
m_StartTimer = reference.m_StartTimer;
5051
m_StopTimer = reference.m_StopTimer;
5152
m_Offset = reference.m_Offset;
53+
m_ParticleCount = reference.m_ParticleCount;
5254

5355
return 0;
5456
}
@@ -69,6 +71,7 @@ int Emission::ReadProperty(const std::string_view& propName, Reader& reader) {
6971
MatchProperty("LifeVariation", { reader >> m_LifeVariation; });
7072
MatchProperty("PushesEmitter", { reader >> m_PushesEmitter; });
7173
MatchProperty("Offset", { reader >> m_Offset; });
74+
MatchProperty("ParticleCount", { reader >> m_ParticleCount; });
7275
MatchProperty("InheritsVel",
7376
{
7477
reader >> m_InheritsVel;
@@ -117,6 +120,8 @@ int Emission::Save(Writer& writer) const {
117120
writer << m_StartTimer.GetSimTimeLimitMS();
118121
writer.NewProperty("StopTimeMS");
119122
writer << m_StopTimer.GetSimTimeLimitMS();
123+
writer.NewProperty("ParticleCount");
124+
writer << m_ParticleCount;
120125

121126
return 0;
122127
}

Source/Entities/Emission.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ namespace RTE {
126126
/// @param offset New offset value.
127127
void SetOffset(Vector offset) { m_Offset = offset; }
128128

129+
/// Returns number of particles emitted per emission.
130+
/// @return Number of particles emitted per emission.
131+
int GetParticleCount() const { return m_ParticleCount; }
132+
133+
/// Sets number of particles emitted per emission.
134+
/// @param newParticleCount The new number of particles emitted per emission.
135+
void SetParticleCount(int newParticleCount) { m_ParticleCount = newParticleCount; }
136+
129137
/// Protected member variable and method declarations
130138
protected:
131139
// Member variables
@@ -162,6 +170,8 @@ namespace RTE {
162170
Timer m_StopTimer;
163171
// Offset of the emission point from Emitter's sprite center, which gets rotated with owner Emitter
164172
Vector m_Offset;
173+
// The number of particles emitted per emission
174+
int m_ParticleCount;
165175

166176
/// Private member variable and method declarations
167177
private:

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, Emission) {
580580
.property("BurstSize", &Emission::GetBurstSize, &Emission::SetBurstSize)
581581
.property("Spread", &Emission::GetSpread, &Emission::SetSpread)
582582
.property("Offset", &Emission::GetOffset, &Emission::SetOffset)
583+
.property("ParticleCount", &Emission::GetParticleCount, &Emission::SetParticleCount)
583584

584585
.def("ResetEmissionTimers", &Emission::ResetEmissionTimers);
585586
}

0 commit comments

Comments
 (0)