1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
|
#include "particle/ParticleManager.h"
#include "particle/ParticleEffect.h"
#include "particle/volumes/ConeVolume.h"
#include "particle/volumes/PointVolume.h"
#include "particle/volumes/RingVolume.h"
#include "particle/volumes/SpheroidVolume.h"
#include <anl.h>
namespace particle {
//
// ------------ INDIVIDUAL FIELD PARSERS ------------
//
struct ParticleParse {
static void parseBitmaps(ParticleEffect &effect) {
if (internal::required_string_if_new("+Filename:", false)) {
effect.m_bitmap_list = internal::parseAnimationList(true);
if (effect.m_bitmap_list.empty()) {
error_display(1, "No bitmap defined for particle effect!");
} else {
effect.m_bitmap_range = ::util::UniformRange<size_t>(0, effect.m_bitmap_list.size() - 1);
}
}
}
static void parseBitmapReversed(ParticleEffect &effect) {
if (optional_string("+Animation Reversed:")) {
stuff_boolean(&effect.m_reverseAnimation);
}
}
template<bool modern = true> static void parseRadius(ParticleEffect &effect) {
if (optional_string(modern ? "+Radius:" : "+Size:")) {
effect.m_radius = ::util::ParsedRandomFloatRange::parseRandomRange();
} else if (optional_string(modern ? "+Parent Radius Factor:" : "+Parent Size Factor:")) {
effect.m_radius = ::util::ParsedRandomFloatRange::parseRandomRange();
effect.m_parentScale = true;
} else {
error_display(1, modern ? "Missing +Radius or +Parent Radius Factor" : "Missing +Size or +Parent Size Factor");
}
}
static void parseLength(ParticleEffect &effect) {
if (optional_string("+Length:")) {
effect.m_length = ::util::ParsedRandomFloatRange::parseRandomRange();
}
}
static void parseLifetime(ParticleEffect &effect) {
if (optional_string("+Lifetime:")) {
if (optional_string("<none>")) {
// Use lifetime of effect
effect.m_hasLifetime = false;
} else {
effect.m_hasLifetime = true;
effect.m_lifetime = ::util::ParsedRandomFloatRange::parseRandomRange();
}
} else if (optional_string("+Parent Lifetime Factor:")) {
effect.m_hasLifetime = true;
effect.m_parentLifetime = true;
effect.m_lifetime = ::util::ParsedRandomFloatRange::parseRandomRange();
}
}
template<bool modern = true> static void parseRotationType(ParticleEffect &effect) {
if (optional_string(modern ? "+Bitmap Alignment:" : "+Rotation:")) {
char buf[NAME_LENGTH];
stuff_string(buf, F_NAME, NAME_LENGTH);
if (!stricmp(buf, "DEFAULT")) {
effect.m_rotation_type = ParticleEffect::RotationType::DEFAULT;
} else if (!stricmp(buf, "RANDOM")) {
effect.m_rotation_type = ParticleEffect::RotationType::RANDOM;
} else if (!stricmp(buf, "SCREEN_ALIGNED") || !stricmp(buf, "SCREEN-ALIGNED") || !stricmp(buf, "SCREEN ALIGNED")) {
effect.m_rotation_type = ParticleEffect::RotationType::SCREEN_ALIGNED;
} else {
// in the future we may want to support additional types, or even a specific angle, but that is TBD
error_display(0, "Rotation Type %s not supported", buf);
}
}
}
template<bool modern = true> static void parseOffset(ParticleEffect& effect) {
if (optional_string(modern ? "+Position Offset:" : "+Offset:")) {
stuff_vec3d(&effect.m_manual_offset.emplace());
}
if (optional_string("+Velocity Offset:")) {
stuff_vec3d(&effect.m_manual_velocity_offset.emplace());
}
}
static void parseParentLocal(ParticleEffect& effect) {
if (optional_string("+Remain local to parent:")) {
stuff_boolean(&effect.m_parent_local);
}
}
template<bool modern = true> static void parseParticleNumber(ParticleEffect &effect) {
if (internal::required_string_if_new(modern ? "+Particle Count Per Spawn:" : "+Number:", false)) {
effect.m_particleNum = ::util::ParsedRandomFloatRange::parseRandomRange();
}
}
static void parseDirection(ParticleEffect &effect) {
if (optional_string("+Direction:")) {
SCP_string dirStr;
stuff_string(dirStr, F_NAME);
if (!stricmp(dirStr.c_str(), "Incoming") || !stricmp(dirStr.c_str(), "Aligned")) {
effect.m_direction = ParticleEffect::ShapeDirection::ALIGNED;
} else if (!stricmp(dirStr.c_str(), "Normal") || !stricmp(dirStr.c_str(), "HitNormal")) {
effect.m_direction = ParticleEffect::ShapeDirection::HIT_NORMAL;
} else if (!stricmp(dirStr.c_str(), "Reflected")) {
effect.m_direction = ParticleEffect::ShapeDirection::REFLECTED;
} else if (!stricmp(dirStr.c_str(), "Reverse")) {
effect.m_direction = ParticleEffect::ShapeDirection::REVERSE;
} else {
error_display(0, "Unknown direction name '%s'!", dirStr.c_str());
}
}
}
static std::shared_ptr<ParticleVolume> parseVolume() {
int type = required_string_one_of(4, "Spheroid", "Cone", "Ring", "Point"); //... and future volumes
std::shared_ptr<ParticleVolume> volume;
switch (type) {
case 0:
required_string("Spheroid"); //Because required string one of, for some reason, does not advance parsing.
volume = std::make_shared<SpheroidVolume>();
break;
case 1:
required_string("Cone");
volume = std::make_shared<ConeVolume>();
break;
case 2:
required_string("Ring");
volume = std::make_shared<RingVolume>();
break;
case 3:
required_string("Point");
volume = std::make_shared<PointVolume>();
break;
default:
UNREACHABLE("Invalid volume type specified!");
}
volume->parse();
return volume;
}
template<bool modern = true> static void parseVelocityInherit(ParticleEffect &effect) {
if (optional_string(modern ? "+Velocity Inherit:" : "+Parent Velocity Factor:")) {
effect.m_vel_inherit = ::util::ParsedRandomFloatRange::parseRandomRange();
}
else if (optional_string("+Absolute Velocity Inherit:")) {
effect.m_vel_inherit = ::util::ParsedRandomFloatRange::parseRandomRange();
effect.m_vel_inherit_absolute = true;
}
if (optional_string("+Ignore Velocity Inherit If Parented:")) {
stuff_boolean(&effect.m_ignore_velocity_inherit_if_has_parent);
}
}
static void parseVelocityVolume(ParticleEffect &effect) {
if (optional_string("+Velocity Volume:")) {
effect.m_velocityVolume = parseVolume();
}
}
static void parseVelocityNoise(ParticleEffect &effect) {
if (optional_string("+Velocity Noise:")) {
SCP_string func;
stuff_string(func, F_RAW);
anl::CKernel kernel;
anl::CExpressionBuilder builder(kernel);
anl::CInstructionIndex instruction = builder.eval(func);
effect.m_velocityNoise = std::make_shared<std::pair<anl::CKernel, anl::CInstructionIndex>>(std::move(kernel), std::move(instruction));
}
if (optional_string("+Velocity Noise Scale:")) {
effect.m_velocity_noise_scaling = ::util::ParsedRandomFloatRange::parseRandomRange();
}
}
template<bool modern = true> static void parseVelocityVolumeScale(ParticleEffect &effect) {
if constexpr (modern) {
if (optional_string("+Velocity Volume Scale:")) {
effect.m_velocity_scaling = ::util::ParsedRandomFloatRange::parseRandomRange();
}
}
else {
if (internal::required_string_if_new("+Velocity:", false)) {
effect.m_velocity_scaling = ::util::ParsedRandomFloatRange::parseRandomRange();
}
}
}
static void parseVelocityDirectionScale(ParticleEffect &effect) {
if (optional_string("+Velocity Direction Scale:")) {
SCP_string dirStr;
stuff_string(dirStr, F_NAME);
if (!stricmp(dirStr.c_str(), "None") || !stricmp(dirStr.c_str(), "Normal")) {
effect.m_velocity_directional_scaling = ParticleEffect::VelocityScaling::NONE;
} else if (!stricmp(dirStr.c_str(), "Dot")) {
effect.m_velocity_directional_scaling = ParticleEffect::VelocityScaling::DOT;
} else if (!stricmp(dirStr.c_str(), "Inverse Dot")) {
effect.m_velocity_directional_scaling = ParticleEffect::VelocityScaling::DOT_INVERSE;
} else {
error_display(0, "Unknown velocity direction scaling name '%s'!", dirStr.c_str());
}
}
}
static void parsePositionVolume(ParticleEffect &effect) {
if (optional_string("+Spawn Position Volume:")) {
effect.m_spawnVolume = parseVolume();
}
}
static void parsePositionNoise(ParticleEffect &effect) {
if (optional_string("+Spawn Position Noise:")) {
SCP_string func;
stuff_string(func, F_RAW);
anl::CKernel kernel;
anl::CExpressionBuilder builder(kernel);
anl::CInstructionIndex instruction = builder.eval(func);
effect.m_spawnNoise = std::make_shared<std::pair<anl::CKernel, anl::CInstructionIndex>>(std::move(kernel), std::move(instruction));
}
if (optional_string("+Spawn Position Noise Scale:")) {
effect.m_position_noise_scaling = ::util::ParsedRandomFloatRange::parseRandomRange();
}
}
static void parseVelocityInheritFromPosition(ParticleEffect &effect) {
if (optional_string("+Velocity From Position:")) {
effect.m_vel_inherit_from_position.emplace(::util::ParsedRandomFloatRange::parseRandomRange());
}
else if (optional_string("+Absolute Velocity From Position:")) {
effect.m_vel_inherit_from_position.emplace(::util::ParsedRandomFloatRange::parseRandomRange());
effect.m_vel_inherit_from_position_absolute = true;
}
}
static void parseVelocityInheritFromOrientation(ParticleEffect &effect) {
if (optional_string("+Velocity From Orientation:")) {
effect.m_vel_inherit_from_orientation.emplace(::util::ParsedRandomFloatRange::parseRandomRange());
}
}
template<bool modern = true> static void parseTiming(ParticleEffect &effect) {
if (optional_string("+Duration:")) {
if (optional_string("ONETIME")) {
effect.m_duration = ParticleEffect::Duration::ONETIME;
}
else if (optional_string("Always")) {
effect.m_duration = ParticleEffect::Duration::ALWAYS;
}
else {
effect.m_duration = ParticleEffect::Duration::RANGE;
effect.m_durationRange = ::util::ParsedRandomFloatRange::parseRandomRange(0.0f);
}
}
if (optional_string("+Delay:")) {
effect.m_delayRange = ::util::ParsedRandomFloatRange::parseRandomRange(0.0f);
}
if (optional_string(modern ? "+Spawns per Second:" : "+Effects per second:")) {
effect.m_particlesPerSecond = ::util::ParsedRandomFloatRange::parseRandomRange();
if (effect.m_particlesPerSecond.min() < 0.001f) {
error_display(0, "Invalid effects per second minimum %f. Setting was disabled.", effect.m_particlesPerSecond.min());
effect.m_particlesPerSecond = ::util::UniformFloatRange(-1.f);
}
if (effect.m_particlesPerSecond.max() > 1000.0f) {
error_display(0, "Effects per second maximum %f is above 1000. Delay between effects will be clamped to 1 millisecond.", effect.m_particlesPerSecond.max());
}
}
}
static void parseLightEmissionSettings(ParticleEffect& effect) {
if (optional_string("$Emits Light:")) {
ParticleEffect::LightInformation& light = effect.m_light_source.emplace();
required_string("+Type:");
switch(required_string_one_of(4, "Point", "As Particle", "To Last Position", "Cone")) {
case 0:
Mp += 5;
light.light_source_mode = ParticleEffect::LightInformation::LightSourceMode::POINT;
break;
case 1:
Mp += 11;
light.light_source_mode = ParticleEffect::LightInformation::LightSourceMode::AS_PARTICLE;
break;
case 2:
Mp += 16;
light.light_source_mode = ParticleEffect::LightInformation::LightSourceMode::TO_LAST_POS;
break;
case 3:
Mp+=4;
light.light_source_mode = ParticleEffect::LightInformation::LightSourceMode::CONE;
break;
}
required_string("+Light Radius:");
stuff_float(&light.light_radius);
if (optional_string("+Light Source Radius:")) {
stuff_float(&light.source_radius);
}
required_string("+Intensity:");
stuff_float(&light.intensity);
required_string("+Color:");
stuff_float(&light.r);
stuff_float(&light.g);
stuff_float(&light.b);
if (optional_string("+Cone Angle:")) {
stuff_float(&light.cone_angle);
}
if (optional_string("+Cone Inner Angle:")) {
stuff_float(&light.cone_inner_angle);
}
}
}
static void parseModularCurvesLifetime(ParticleEffect& effect) {
effect.m_lifetime_curves.parse("$Particle Lifetime Curve:");
}
static void parseModularCurvesSource(ParticleEffect& effect) {
effect.m_modular_curves.parse("$Particle Source Curve:");
}
//
// ------------ MODERN TABLES CODE ------------
//
static void parseModernTrail(ParticleEffect& effect, bool top_layer) {
if (optional_string("$Trail Effect:")) {
SCP_string name;
stuff_string(name, F_NAME);
effect.m_particleTrail = ParticleManager::get()->getEffectByName(name);
}
else if (top_layer && optional_string("$Trail Inline Effect:")) {
SCP_string name;
stuff_string(name, F_NAME);
SCP_vector<ParticleEffect> trail {constructModernEffect(name, false)};
while (optional_string("$Continue Trail Effect:"))
trail.emplace_back(constructModernEffect(name));
effect.m_particleTrail = ParticleManager::get()->addEffect(std::move(trail));
}
}
static ParticleEffect constructModernEffect(const SCP_string& name, bool top_layer = true) {
ParticleEffect effect(name);
//Particle Settings
parseBitmaps(effect);
parseBitmapReversed(effect);
parseRotationType(effect);
parseRadius(effect);
parseLength(effect);
parseLifetime(effect);
parseParentLocal(effect);
parseLightEmissionSettings(effect);
//Spawner Settings
parseTiming(effect);
parseParticleNumber(effect);
parseDirection(effect);
parseOffset(effect);
parsePositionVolume(effect);
parsePositionNoise(effect);
parseVelocityVolume(effect);
parseVelocityVolumeScale(effect);
parseVelocityNoise(effect);
parseVelocityDirectionScale(effect);
parseVelocityInheritFromPosition(effect);
parseVelocityInheritFromOrientation(effect);
parseVelocityInherit(effect);
//Curves
parseModularCurvesLifetime(effect);
parseModularCurvesSource(effect);
parseModernTrail(effect, top_layer);
return effect;
}
//
// ------------ LEGACY TABLES CODE ------------
//
static void parseSizeLifetimeCurve(ParticleEffect &effect) {
if (optional_string("+Size over lifetime curve:")) {
effect.m_lifetime_curves.add_curve("Lifetime", ParticleEffect::ParticleLifetimeCurvesOutput::RADIUS_MULT, modular_curves_entry{curve_parse("")});
}
}
static void parseVelocityLifetimeCurve(ParticleEffect &effect) {
if (optional_string("+Velocity scalar over lifetime curve:")) {
effect.m_lifetime_curves.add_curve("Lifetime", ParticleEffect::ParticleLifetimeCurvesOutput::VELOCITY_MULT, modular_curves_entry{curve_parse("")});
}
}
static void parseParticleProperties(ParticleEffect &effect) {
//Emulates parsing in the legacy order, analogous to the old particle properties
parseBitmaps(effect);
parseRadius<false>(effect);
parseLength(effect);
parseLifetime(effect);
parseSizeLifetimeCurve(effect);
parseVelocityLifetimeCurve(effect);
parseRotationType<false>(effect);
parseOffset<false>(effect);
parseParentLocal(effect);
}
enum class ParticleEffectLegacyType: int8_t {
Invalid = -1,
Single,
Composite,
Cone,
Sphere,
Volume,
MAX,
};
static constexpr size_t legacyEffectTypeNamesMax = static_cast<size_t>(ParticleEffectLegacyType::MAX);
static std::array<const char*, legacyEffectTypeNamesMax> legacyEffectTypeNames;
static ParticleEffectLegacyType parseLegacyEffectType() {
if(!optional_string("$Type:"))
return ParticleEffectLegacyType::Invalid;
SCP_string type;
stuff_string(type, F_NAME);
int i = string_lookup(type.c_str(), legacyEffectTypeNames, legacyEffectTypeNamesMax, "ParticleEffectLegacyType", true);
if (i >= 0)
return static_cast<ParticleEffectLegacyType>(i);
else
return ParticleEffectLegacyType::Invalid;
}
static SCP_vector<ParticleEffect> parseLegacyCompositeElement(const SCP_string &name) {
if (!optional_string("$New Effect")) {
SCP_string newName;
stuff_string(newName, F_NAME);
auto index = ParticleManager::get()->getEffectByName(newName);
if (!index.isValid()) {
error_display(0, "Unknown particle effect name '%s' encountered!", newName.c_str());
}
auto effect = ParticleManager::get()->getEffect(index);
if (!effect.empty()) {
effect.front().m_name = name;
}
return effect;
}
ParticleEffectLegacyType type = parseLegacyEffectType();
if (type == ParticleEffectLegacyType::Invalid) {
error_display(0, "Legacy inline particle effect only accepts inline sub-effects with a legacy type!");
}
return constructLegacyEffect(name, type);
}
static ParticleEffectHandle parseLegacyCompositeElementByID(const SCP_string &name) {
if (!optional_string("$New Effect")) {
SCP_string newName;
stuff_string(newName, F_NAME);
auto index = ParticleManager::get()->getEffectByName(newName);
if (!index.isValid()) {
error_display(0, "Unknown particle effect name '%s' encountered!", newName.c_str());
}
return index;
}
ParticleEffectLegacyType type = parseLegacyEffectType();
if (type == ParticleEffectLegacyType::Invalid) {
error_display(0, "Legacy inline particle effect only accepts inline sub-effects with a legacy type!");
}
return ParticleManager::get()->addEffect(constructLegacyEffect(name, type));
}
static void parseLegacyChance(ParticleEffect& effect) {
if (optional_string("+Chance:")) {
float chance;
stuff_float(&chance);
if (chance <= 0.0f) {
error_display(0, "Particle %s tried to set +Chance: %f\nChances below 0 would result in no particles.", effect.m_name.c_str(), chance);
} else if (chance > 1.0f) {
error_display(0, "Particle %s tried to set +Chance: %f\nChances above 1 are ignored, please use +Number: (min,max) to spawn multiple particles.", effect.m_name.c_str(), chance);
chance = 1.0f;
}
effect.m_particleChance = chance;
}
}
static SCP_vector<ParticleEffect> constructLegacyEffect(const SCP_string& name, ParticleEffectLegacyType type) {
SCP_vector<ParticleEffect> result;
result.emplace_back(name);
ParticleEffect& effect = result.back();
switch (type) {
case ParticleEffectLegacyType::Single:
parseParticleProperties(effect);
parseVelocityInherit<false>(effect);
parseTiming<false>(effect);
break;
case ParticleEffectLegacyType::Composite: {
bool first = true;
result.pop_back();
while (optional_string("+Child effect:")) {
const auto& child_effects = parseLegacyCompositeElement(first ? name : "");
result.insert(result.end(), std::make_move_iterator(child_effects.begin()), std::make_move_iterator(child_effects.end()));
first = false;
}
if (result.empty()) {
error_display(0, "Composite effect %s must have at least one child effect!", name.c_str());
}
break;
}
case ParticleEffectLegacyType::Cone: {
parseParticleProperties(effect);
effect.m_velocity_directional_scaling = ParticleEffect::VelocityScaling::DOT;
if (required_string("+Deviation:")) {
float deviation;
stuff_float(&deviation);
if (deviation < 0.001f) {
error_display(0, "A standard deviation of %f is not valid. Must be greater than 0. Defaulting to 1.", deviation);
deviation = 1.0f;
}
effect.m_velocityVolume = std::make_shared<ConeVolume>(::util::BoundedNormalFloatRange(::util::BoundedNormalDistribution::param_type{ std::normal_distribution<float>::param_type(0.f, fl_radians(deviation)), -PI, PI }), 1.f);
}
parseVelocityVolumeScale<false>(effect);
parseParticleNumber<false>(effect);
parseLegacyChance(effect);
parseDirection(effect);
bool saw_deprecated_effect_location = false;
if (optional_string("+Trail effect:")) {
// This is the deprecated location since this introduces ambiguities in the parsing process
effect.m_particleTrail = parseLegacyCompositeElementByID("");
saw_deprecated_effect_location = true;
}
parseVelocityInherit<false>(effect);
parseTiming<false>(effect);
if (optional_string("+Trail effect:")) {
// This is the new and correct location. This might create duplicate effects but the warning should be clear
// enough to avoid that
if (saw_deprecated_effect_location) {
error_display(0, "Found two trail effect options! Specifying '+Trail effect:' before '+Duration:' is "
"deprecated since that can cause issues with conflicting effect options.");
}
effect.m_particleTrail = parseLegacyCompositeElementByID("");
}
break;
}
case ParticleEffectLegacyType::Sphere: {
parseParticleProperties(effect);
effect.m_velocityVolume = make_shared<SpheroidVolume>(1.f, 1.f, 1.f);
parseVelocityVolumeScale<false>(effect);
parseParticleNumber<false>(effect);
parseLegacyChance(effect);
parseDirection(effect);
bool saw_deprecated_effect_location = false;
if (optional_string("+Trail effect:")) {
// This is the deprecated location since this introduces ambiguities in the parsing process
effect.m_particleTrail = parseLegacyCompositeElementByID("");
saw_deprecated_effect_location = true;
}
parseVelocityInherit<false>(effect);
parseTiming<false>(effect);
if (optional_string("+Trail effect:")) {
// This is the new and correct location. This might create duplicate effects but the warning should be clear
// enough to avoid that
if (saw_deprecated_effect_location) {
error_display(0, "Found two trail effect options! Specifying '+Trail effect:' before '+Duration:' is "
"deprecated since that can cause issues with conflicting effect options.");
}
effect.m_particleTrail = parseLegacyCompositeElementByID("");
}
break;
}
case ParticleEffectLegacyType::Volume: {
parseParticleProperties(effect);
effect.m_vel_inherit_from_position_absolute = true;
//This is, unfortunately, not semantically identical to the other velocity, so this is handled manually
if (required_string("+Velocity:")) {
effect.m_vel_inherit_from_position.emplace(::util::ParsedRandomFloatRange::parseRandomRange());
}
parseParticleNumber<false>(effect);
parseLegacyChance(effect);
float radius = 10.f;
if (required_string("+Volume radius:")) {
stuff_float(&radius);
if (radius < 0.001f) {
error_display(0, "A volume radius of %f is not valid. Must be greater than 0. Defaulting to 10.", radius);
radius = 10.0f;
}
}
float bias = 1.f;
if (optional_string("+Bias:")) {
stuff_float(&bias);
if (bias < 0.001f) {
error_display(0, "A volume bias value of %f is not valid. Must be greater than 0.", bias);
bias = 1.0f;
}
}
float stretch = 1.f;
if (optional_string("+Stretch:")) {
stuff_float(&stretch);
if (stretch < 0.001f) {
error_display(0, "A volume stretch value of %f is not valid. Must be greater than 0.", stretch);
stretch = 1.0f;
}
}
effect.m_spawnVolume = make_shared<SpheroidVolume>(bias, stretch, radius);
parseVelocityInherit<false>(effect);
parseTiming<false>(effect);
break;
}
default: {
Error(LOCATION, "Unimplemented effect type %d encountered! Get a coder!", static_cast<int>(type));
throw std::runtime_error("Unimplemented effect type encountered!");
}
}
return result;
}
//
// ------------ MAIN CALLBACK ------------
//
static void parseCallback(const char* fileName) {
using namespace particle;
try {
read_file_text(fileName, CF_TYPE_TABLES);
reset_parse();
required_string("#Particle Effects");
while (optional_string("$Effect:")) {
SCP_string name;
stuff_string(name, F_NAME);
auto type = parseLegacyEffectType();
if (type == ParticleEffectLegacyType::Invalid) {
SCP_vector<ParticleEffect> effect {constructModernEffect(name)};
while (optional_string("$Continue Effect:"))
effect.emplace_back(constructModernEffect(name));
ParticleManager::get()->addEffect(std::move(effect));
}
else
ParticleManager::get()->addEffect(constructLegacyEffect(name, type));
}
required_string("#End");
}
catch (const parse::ParseException& e)
{
mprintf(("TABLES: Unable to parse '%s'! Error message = %s.\n", fileName, e.what()));
return;
}
}
};
void ParticleManager::parseConfigFiles() {
parse_modular_table("*-part.tbm", ParticleParse::parseCallback);
}
std::array<const char*, ParticleParse::legacyEffectTypeNamesMax> ParticleParse::legacyEffectTypeNames = {
"Single",
"Composite",
"Cone",
"Sphere",
"Volume"
};
}
|