Skip to content

Commit 82dfdbc

Browse files
authored
Cleanup of Level 0 Particles (#6808)
* Make scripting use the full-blown particle system * Add reverse option * Add animation reversal as an option to modern particles * Start implementation of beam particles * Add multi-emission particle source API for legacy particles * Attach beam muzzle particles to the correct host * Reorder code in order to facilitate apparent visual size as modular curve input for particles * fix lua api * Typo * Fix scripting and beam muzzle particles * Remove muzzleflash code, prepare to replace with particles * Begin mflash effect conversion * Pass final parameters to mflashes and fix curve * Remove deprecated particle function * Add debris flame particles * remove weapon_explosion table * Convert shield explosion particles * Fix modular curve full inputs and convert particle curve inputs accordingly * Allow particle volume offset and rotation with curve-based rot around fvec * Add Ring and Point Volumes * Convert PSPEW to new system * Make particle curve timing aware of interp * Update todos * get rid of performance waste * Add last parameter for converted pspews * Fix pspew bugs * Fix direction for default pspew * Fix order for voluem rotation * particle vel interp * particle vel interp 2 * Make beam muzzle stay parented to the firing ship, as it's likely the more commonly intended variamnt * fix scripting particle lifetime * Allow beam muzzle particle override * Skip invalid pspews * remove pspew dcf code * Fix sparkler stretch * Correct sparkler bia * General sparkler weirdness * Tune distribution of sparklers * Convert Asteroid particles * Fix conversion warning * Fix conversion warning again * Fix conversion warning again again * Really clang?
1 parent 220ff67 commit 82dfdbc

39 files changed

Lines changed: 1249 additions & 1494 deletions

code/ai/aiturret.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,9 +2043,6 @@ bool turret_fire_weapon(int weapon_num,
20432043
particleSource->setTriggerVelocity(vm_vec_mag_quick(&objp->phys_info.vel));
20442044
particleSource->finishCreation();
20452045
}
2046-
else if (wip->muzzle_flash >= 0) {
2047-
mflash_create(firing_pos, firing_vec, &Objects[parent_ship->objnum].phys_info, wip->muzzle_flash);
2048-
}
20492046

20502047
// in multiplayer (and the master), then send a turret fired packet.
20512048
if ( MULTIPLAYER_MASTER && (weapon_objnum != -1) ) {
@@ -2166,9 +2163,6 @@ void turret_swarm_fire_from_turret(turret_swarm_info *tsi)
21662163
particleSource->setTriggerRadius(Objects[weapon_objnum].radius);
21672164
particleSource->finishCreation();
21682165
}
2169-
else if (Weapon_info[tsi->weapon_class].muzzle_flash >= 0) {
2170-
mflash_create(&turret_pos, &turret_fvec, &Objects[tsi->parent_objnum].phys_info, Weapon_info[tsi->weapon_class].muzzle_flash);
2171-
}
21722166

21732167
// maybe sound
21742168
if ( Weapon_info[tsi->weapon_class].launch_snd.isValid() ) {

code/asteroid/asteroid.cpp

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "object/object.h"
3434
#include "parse/parselo.h"
3535
#include "scripting/global_hooks.h"
36-
#include "particle/particle.h"
36+
#include "particle/hosts/EffectHostVector.h"
3737
#include "render/3d.h"
3838
#include "ship/ship.h"
3939
#include "ship/shipfx.h"
@@ -63,8 +63,7 @@ asteroid Asteroids[MAX_ASTEROIDS];
6363
asteroid_field Asteroid_field;
6464

6565

66-
static int Asteroid_impact_explosion_ani;
67-
static float Asteroid_impact_explosion_radius;
66+
static particle::ParticleEffectHandle Asteroid_impact_explosion_ani;
6867
char Asteroid_icon_closeup_model[NAME_LENGTH];
6968
vec3d Asteroid_icon_closeup_position;
7069
float Asteroid_icon_closeup_zoom;
@@ -1752,7 +1751,9 @@ void asteroid_hit( object * pasteroid_obj, object * other_obj, vec3d * hitpos, f
17521751
wip = &Weapon_info[Weapons[other_obj->instance].weapon_info_index];
17531752
// If the weapon didn't play any impact animation, play custom asteroid impact animation
17541753
if (!wip->impact_weapon_expl_effect.isValid()) {
1755-
particle::create( hitpos, &vmd_zero_vector, 0.0f, Asteroid_impact_explosion_radius, Asteroid_impact_explosion_ani );
1754+
auto source = particle::ParticleManager::get()->createSource(Asteroid_impact_explosion_ani);
1755+
source->setHost(std::make_unique<EffectHostVector>(*hitpos, vmd_identity_matrix, vmd_zero_vector));
1756+
source->finishCreation();
17561757
}
17571758
}
17581759
}
@@ -2461,18 +2462,52 @@ static void asteroid_parse_tbl(const char* filename)
24612462

24622463
required_string("#End");
24632464

2464-
if (optional_string("$Impact Explosion:")) {
2465+
if (optional_string("$Impact Explosion Effect:")) {
2466+
Asteroid_impact_explosion_ani = particle::util::parseEffect();
2467+
}
2468+
else {
24652469
char impact_ani_file[MAX_FILENAME_LEN];
2466-
stuff_string(impact_ani_file, F_NAME, MAX_FILENAME_LEN);
2470+
float Asteroid_impact_explosion_radius;
2471+
int num_frames;
24672472

2468-
if (VALID_FNAME(impact_ani_file)) {
2469-
int num_frames;
2470-
Asteroid_impact_explosion_ani = bm_load_animation(impact_ani_file, &num_frames, nullptr, nullptr, nullptr, true);
2473+
if (optional_string("$Impact Explosion:")) {
2474+
stuff_string(impact_ani_file, F_NAME, MAX_FILENAME_LEN);
2475+
}
2476+
if (optional_string("$Impact Explosion Radius:")) {
2477+
stuff_float(&Asteroid_impact_explosion_radius);
24712478
}
2472-
}
24732479

2474-
if (optional_string("$Impact Explosion Radius:")) {
2475-
stuff_float(&Asteroid_impact_explosion_radius);
2480+
if(VALID_FNAME(impact_ani_file)) {
2481+
Asteroid_impact_explosion_ani = particle::ParticleManager::get()->addEffect(particle::ParticleEffect(
2482+
"", //Name
2483+
::util::UniformFloatRange(1.f), //Particle num
2484+
particle::ParticleEffect::Duration::ONETIME, //Single Particle Emission
2485+
::util::UniformFloatRange(), //No duration
2486+
::util::UniformFloatRange(-1.f), //Single particle only
2487+
particle::ParticleEffect::ShapeDirection::ALIGNED, //Particle direction
2488+
::util::UniformFloatRange(), //Velocity Inherit
2489+
false, //Velocity Inherit absolute?
2490+
nullptr, //Velocity volume
2491+
::util::UniformFloatRange(), //Velocity volume multiplier
2492+
particle::ParticleEffect::VelocityScaling::NONE, //Velocity directional scaling
2493+
std::nullopt, //Orientation-based velocity
2494+
std::nullopt, //Position-based velocity
2495+
nullptr, //Position volume
2496+
particle::ParticleEffectHandle::invalid(), //Trail
2497+
1.f, //Chance
2498+
false, //Affected by detail
2499+
-1.f, //Culling range multiplier
2500+
false, //Disregard Animation Length. Must be true for everything using particle::Anim_bitmap_X
2501+
false, //Don't reverse animation
2502+
false, //parent local
2503+
false, //ignore velocity inherit if parented
2504+
false, //position velocity inherit absolute?
2505+
std::nullopt, //Local velocity offset
2506+
std::nullopt, //Local offset
2507+
::util::UniformFloatRange(-1.f), //Lifetime
2508+
::util::UniformFloatRange(Asteroid_impact_explosion_radius), //Radius
2509+
bm_load_animation(impact_ani_file, &num_frames, nullptr, nullptr, nullptr, true))); //Bitmap
2510+
}
24762511
}
24772512

24782513
if (optional_string("$Briefing Icon Closeup Model:")) {
@@ -2622,8 +2657,7 @@ static void verify_asteroid_list()
26222657
*/
26232658
void asteroid_init()
26242659
{
2625-
Asteroid_impact_explosion_ani = -1;
2626-
Asteroid_impact_explosion_radius = 20.0; // retail value
2660+
Asteroid_impact_explosion_ani = particle::ParticleEffectHandle::invalid();
26272661
Asteroid_icon_closeup_model[0] = '\0';
26282662
vm_vec_make(&Asteroid_icon_closeup_position, 0.0f, 0.0f, -334.0f); // magic numbers from retail
26292663
Asteroid_icon_closeup_zoom = 0.5f; // magic number from retail
@@ -2644,7 +2678,7 @@ void asteroid_init()
26442678
// now that Asteroid_info is filled in we can verify the asteroid splits and set their indecies
26452679
verify_asteroid_splits();
26462680

2647-
if (Asteroid_impact_explosion_ani == -1) {
2681+
if (!Asteroid_impact_explosion_ani.isValid()) {
26482682
Error(LOCATION, "Missing valid asteroid impact explosion definition in asteroid.tbl!");
26492683
}
26502684

code/debris/debris.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ void debris_init()
121121
Debris_hit_particle = particle::ParticleManager::get()->addEffect(particle::ParticleEffect(
122122
"", //Name
123123
::util::UniformFloatRange(10.f), //Particle num
124+
particle::ParticleEffect::Duration::ONETIME, //Single Particle Emission
125+
::util::UniformFloatRange(), //No duration
126+
::util::UniformFloatRange (-1.f), //Single particle only
124127
particle::ParticleEffect::ShapeDirection::ALIGNED, //Particle direction
125128
::util::UniformFloatRange(1.f), //Velocity Inherit
126129
false, //Velocity Inherit absolute?
@@ -135,6 +138,12 @@ void debris_init()
135138
true, //Affected by detail
136139
1.f, //Culling range multiplier
137140
true, //Disregard Animation Length. Must be true for everything using particle::Anim_bitmap_X
141+
false, //Don't reverse animation
142+
false, //parent local
143+
false, //ignore velocity inherit if parented
144+
false, //position velocity inherit absolute?
145+
std::nullopt, //Local velocity offset
146+
std::nullopt, //Local offset
138147
::util::UniformFloatRange(0.25f, 0.75f), //Lifetime
139148
::util::UniformFloatRange(0.2f, 0.4f), //Radius
140149
particle::Anim_bitmap_id_fire)); //Bitmap
@@ -418,6 +427,14 @@ object *debris_create(object *source_obj, int model_num, int submodel_num, const
418427
{
419428
debris_create_set_velocity(&Debris[obj->instance], shipp, exp_center, exp_force, source_subsys);
420429
debris_create_fire_hook(obj, source_obj);
430+
const auto& sip = Ship_info[Ships[source_obj->instance].ship_info_index];
431+
if (sip.debris_flame_particles.isValid()) {
432+
auto source = particle::ParticleManager::get()->createSource(sip.debris_flame_particles);
433+
source->setHost(std::make_unique<EffectHostObject>(obj, vmd_zero_vector));
434+
source->setTriggerRadius(source_obj->radius);
435+
source->setTriggerVelocity(vm_vec_mag_quick(&source_obj->phys_info.vel));
436+
source->finishCreation();
437+
}
421438
}
422439

423440
return obj;

code/globalincs/pstypes.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,6 @@ const size_t INVALID_SIZE = static_cast<size_t>(-1);
397397
// the trailing underscores are to avoid conflicts with previously #define'd tokens
398398
enum class TriStateBool : int { FALSE_ = 0, TRUE_ = 1, UNKNOWN_ = -1 };
399399

400-
401-
// lod checker for (modular) table parsing
402-
typedef struct lod_checker {
403-
char filename[MAX_FILENAME_LEN];
404-
int num_lods;
405-
int override;
406-
} lod_checker;
407-
408-
409400
// Callback Loading function.
410401
// If you pass a function to this, that function will get called
411402
// around 10x per second, so you can update the screen.

code/lab/manager/lab_manager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ LabManager::LabManager() {
4848
shockwave_level_init();
4949
ship_level_init();
5050
shipfx_flash_init();
51-
mflash_page_in(true);
5251
weapon_level_init();
5352
beam_level_init();
5453
particle::init();

code/network/multimsgs.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8770,15 +8770,30 @@ void process_flak_fired_packet(ubyte *data, header *hinfo)
87708770
// create the weapon object
87718771
weapon_objnum = weapon_create( &pos, &orient, wid, OBJ_INDEX(objp), -1, true, false, 0.0f, ssp, launch_curve_data);
87728772
if (weapon_objnum != -1) {
8773-
if ( Weapon_info[wid].launch_snd.isValid() ) {
8773+
const weapon_info& wip = Weapon_info[wid];
8774+
if ( wip.launch_snd.isValid() ) {
87748775
snd_play_3d( gamesnd_get_game_sound(Weapon_info[wid].launch_snd), &pos, &View_position );
87758776
}
87768777

8777-
// create a muzzle flash from a flak gun based upon firing position and weapon type
8778-
mflash_create(&pos, &dir, &objp->phys_info, Weapon_info[wid].muzzle_flash);
8778+
object& wp_obj = Objects[weapon_objnum];
8779+
const weapon& wp = Weapons[wp_obj.instance];
8780+
8781+
if (wip.muzzle_effect.isValid()) {
8782+
float radius_mult = 1.f;
8783+
if (wip.render_type == WRT_LASER) {
8784+
radius_mult = wip.weapon_curves.get_output(weapon_info::WeaponCurveOutputs::LASER_RADIUS_MULT, wp, &wp.modular_curves_instance);
8785+
}
8786+
//spawn particle effect
8787+
auto particleSource = particle::ParticleManager::get()->createSource(wip.muzzle_effect);
8788+
//This could potentially be attached to the ship, but might look weird if the spawn position of the weapon is ever interpolated away from the ship's barrel.
8789+
particleSource->setHost(make_unique<EffectHostVector>(pos, orient, objp->phys_info.vel));
8790+
particleSource->setTriggerRadius(wp_obj.radius * radius_mult);
8791+
particleSource->setTriggerVelocity(vm_vec_mag_quick(&wp_obj.phys_info.vel));
8792+
particleSource->finishCreation();
8793+
}
87798794

87808795
// set its range explicitly - make it long enough so that it's guaranteed to still exist when the server tells us it blew up
8781-
flak_set_range(&Objects[weapon_objnum], (float)flak_range);
8796+
flak_set_range(&wp_obj, (float)flak_range);
87828797
}
87838798
}
87848799

code/object/collideshipweapon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,8 @@ static int ship_weapon_check_collision(object *ship_objp, object *weapon_objp, f
527527

528528
if(!ship_override && !weapon_override) {
529529
if (shield_collision && quadrant_num >= 0) {
530-
if ((sip->shield_impact_explosion_anim > -1) && (wip->shield_impact_explosion_radius > 0)) {
531-
shield_impact_explosion(&mc->hit_point, ship_objp, wip->shield_impact_explosion_radius, sip->shield_impact_explosion_anim);
530+
if ((sip->shield_impact_explosion_anim.isValid()) && (wip->shield_impact_explosion_radius > 0)) {
531+
shield_impact_explosion(mc->hit_point, mc->hit_normal, ship_objp, weapon_objp, wip->shield_impact_explosion_radius, sip->shield_impact_explosion_anim);
532532
}
533533
}
534534
ship_weapon_do_hit_stuff(ship_objp, weapon_objp, &mc->hit_point_world, &mc->hit_point, quadrant_num, mc->hit_submodel, &mc->hit_normal);

0 commit comments

Comments
 (0)