Skip to content

Commit ade9b57

Browse files
committed
Add flag to limit particles during animation to a direction
1 parent 60203b6 commit ade9b57

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

code/model/animation/modelanimation_segments.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,8 +1387,8 @@ namespace animation {
13871387
}
13881388

13891389

1390-
ModelAnimationSegmentParticlesDuring::ModelAnimationSegmentParticlesDuring(std::shared_ptr<ModelAnimationSegment> segment, particle::ParticleEffectHandle effect, float atTime, std::shared_ptr<ModelAnimationSubmodel> submodel, std::optional<vec3d> position, std::optional<matrix> orientation) :
1391-
m_segment(std::move(segment)), m_submodel(std::move(submodel)), m_position(std::move(position)), m_orientation(std::move(orientation)), m_effect(effect), m_atTime(atTime) { }
1390+
ModelAnimationSegmentParticlesDuring::ModelAnimationSegmentParticlesDuring(std::shared_ptr<ModelAnimationSegment> segment, particle::ParticleEffectHandle effect, float atTime, std::shared_ptr<ModelAnimationSubmodel> submodel, std::optional<vec3d> position, std::optional<matrix> orientation, std::optional<ModelAnimationDirection> limitDirection) :
1391+
m_segment(std::move(segment)), m_submodel(std::move(submodel)), m_position(std::move(position)), m_orientation(std::move(orientation)), m_limitDirection(std::move(limitDirection)), m_effect(effect), m_atTime(atTime) { }
13921392

13931393
ModelAnimationSegment* ModelAnimationSegmentParticlesDuring::copy() const {
13941394
auto newCopy = new ModelAnimationSegmentParticlesDuring(*this);
@@ -1407,8 +1407,8 @@ namespace animation {
14071407

14081408
void ModelAnimationSegmentParticlesDuring::executeAnimation(const ModelAnimationSubmodelBuffer& state, float timeboundLower, float timeboundUpper, ModelAnimationDirection direction, int pmi_id) {
14091409
float atTime = fminf(fmaxf(m_atTime, 0.0f), m_duration.at(pmi_id));
1410-
if (timeboundLower <= atTime && atTime <= timeboundUpper) {
1411-
createParticleSource(model_get_instance(pmi_id));
1410+
if (timeboundLower <= atTime && atTime <= timeboundUpper && (!m_limitDirection || direction == *m_limitDirection)) {
1411+
createParticleSource(model_get_instance(pmi_id));
14121412
}
14131413
m_segment->executeAnimation(state, timeboundLower, timeboundUpper, direction, pmi_id);
14141414
}
@@ -1483,7 +1483,17 @@ namespace animation {
14831483
orientation = std::move(mat);
14841484
}
14851485

1486-
auto segment = std::make_shared<ModelAnimationSegmentParticlesDuring>(data->parseSegment(), effect, atTime, submodel, position, orientation);
1486+
std::optional<ModelAnimationDirection> limitDirection = std::nullopt;
1487+
if (optional_string("+Limit Direction:")) {
1488+
SCP_string buf;
1489+
stuff_string(buf, F_NAME);
1490+
if (!stricmp(buf.c_str(), "FWD"))
1491+
limitDirection = ModelAnimationDirection::FWD;
1492+
else if (!stricmp(buf.c_str(), "RWD"))
1493+
limitDirection = ModelAnimationDirection::RWD;
1494+
}
1495+
1496+
auto segment = std::make_shared<ModelAnimationSegmentParticlesDuring>(data->parseSegment(), effect, atTime, submodel, position, orientation, limitDirection);
14871497

14881498
return segment;
14891499
}

code/model/animation/modelanimation_segments.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ namespace animation {
297297
std::shared_ptr<ModelAnimationSubmodel> m_submodel;
298298
std::optional<vec3d> m_position;
299299
std::optional<matrix> m_orientation;
300+
std::optional<ModelAnimationDirection> m_limitDirection;
300301

301302
//configurables:
302303
public:
@@ -315,7 +316,7 @@ namespace animation {
315316

316317
public:
317318
static std::shared_ptr<ModelAnimationSegment> parser(ModelAnimationParseHelper* data);
318-
ModelAnimationSegmentParticlesDuring(std::shared_ptr<ModelAnimationSegment> segment, particle::ParticleEffectHandle effect, float atTime, std::shared_ptr<ModelAnimationSubmodel> submodel = nullptr, std::optional<vec3d> position = std::nullopt, std::optional<matrix> orientation = std::nullopt);
319+
ModelAnimationSegmentParticlesDuring(std::shared_ptr<ModelAnimationSegment> segment, particle::ParticleEffectHandle effect, float atTime, std::shared_ptr<ModelAnimationSubmodel> submodel = nullptr, std::optional<vec3d> position = std::nullopt, std::optional<matrix> orientation = std::nullopt, std::optional<ModelAnimationDirection> limitDirection = std::nullopt);
319320

320321
};
321322

0 commit comments

Comments
 (0)