Skip to content

Commit c30ce55

Browse files
committed
Fix combining 3D shockwaves with framebuffer shockwaves.
If framebuffer shockwaves were enabled and a 3D shockwave was created, FSO would use a hardcoded reference to the second slot of the Shockwave_info vector to generate the framebuffer shockwave for it. This only makes sense if and only if: - the 3D shockwave command-line flag is also enabled - the default 3D shockwave and default 2D shockwave are both present and loaded - its the first mission of the session (because after that any shockwave not in the 0th index got unloaded) I've changed the code so that which index the default 2D shockwave got loaded into gets tracked and used instead of a hardcoded index... and if both default shockwaves are loaded, the first two Shockwave_info indices are both kept between missions instead of just the first. This should allow framebuffer shockwaves to work with 3D shockwaves, regardless of whether or not it's the first mission of the session and whether or not a custom 2D shockwave was loaded (and happened to wind up at index 1). Slight downside in that missing the default 2D shockwave file, but having a custom 2D shockwave loaded, will now result in framebuffer shockwaves not being drawn at all, rather than using the custom 2D shockwave by accident; not sure that's really all that much of a problem, though.
1 parent 9447d74 commit c30ce55

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

code/weapon/shockwave.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
static const char *Default_shockwave_2D_filename = "shockwave01";
3030
static const char *Default_shockwave_3D_filename = "shockwave.pof";
31+
static int Default_2D_shockwave_index = -1;
3132
static int Default_shockwave_loaded = 0;
3233

3334
SCP_vector<shockwave_info> Shockwave_info;
@@ -395,11 +396,11 @@ void shockwave_render(object *objp, model_draw_list *scene)
395396

396397
model_render_queue( &render_info, scene, sw->model_id, &Objects[sw->objnum].orient, &sw->pos);
397398

398-
if ( Cmdline_fb_explosions ) {
399+
if ( Cmdline_fb_explosions && Default_2D_shockwave_index > -1) {
399400
g3_transfer_vertex(&p, &sw->pos);
400401

401402
float intensity = ((sw->time_elapsed / sw->total_time) > 0.9f) ? (1.0f - (sw->time_elapsed / sw->total_time))*10.0f : 1.0f;
402-
batching_add_distortion_bitmap_rotated(Shockwave_info[1].bitmap_id + shockwave_get_framenum(objp->instance, Shockwave_info[1].bitmap_id), &p, fl_radians(sw->rot_angles.p), sw->radius, intensity);
403+
batching_add_distortion_bitmap_rotated(Shockwave_info[Default_2D_shockwave_index].bitmap_id + shockwave_get_framenum(objp->instance, Shockwave_info[Default_2D_shockwave_index].bitmap_id), &p, fl_radians(sw->rot_angles.p), sw->radius, intensity);
403404
}
404405
} else {
405406
g3_transfer_vertex(&p, &sw->pos);
@@ -493,6 +494,7 @@ void shockwave_level_init()
493494
mprintf(("SHOCKWAVE => Default model load: SUCCEEDED!!\n"));
494495
else
495496
mprintf(("SHOCKWAVE => Default model load: FAILED!! Falling back to 2D effect...\n"));
497+
Assertion(i <= 0, "Default 3D shockwave should be the first shockwave loaded, but instead got loaded into index %d; get a coder!\n", i);
496498
}
497499

498500
// next, try the 2d shockwave effect, unless the 3d effect was loaded
@@ -506,6 +508,8 @@ void shockwave_level_init()
506508
mprintf(("SHOCKWAVE => Default animation load: SUCCEEDED!!\n"));
507509
else
508510
mprintf(("SHOCKWAVE => Default animation load: FAILED!! Checking if 3d effect was already tried...\n"));
511+
Assertion(i <= 1, "Default 2D shockwave should be either the first or second shockwave loaded, but instead got loaded into index %d; get a coder!\n", i);
512+
Default_2D_shockwave_index = i;
509513
}
510514

511515
// chief1983 - The first patch broke mods that don't provide a 2d shockwave or define a specific shockwave for each model/weapon (shame on them)
@@ -520,6 +524,7 @@ void shockwave_level_init()
520524
mprintf(("SHOCKWAVE => Default model load: SUCCEEDED!!\n"));
521525
else
522526
mprintf(("SHOCKWAVE => Default model load: FAILED!! No effect loaded...\n"));
527+
Assertion(i <= 0, "Default 3D shockwave should be the first shockwave loaded, but instead got loaded into index %d; get a coder!\n", i);
523528
}
524529

525530
if (i < 0)
@@ -566,6 +571,12 @@ void shockwave_level_close()
566571
bm_unload( it->bitmap_id );
567572
else if (it->model_id >= 0)
568573
model_page_out_textures( it->model_id );
574+
if (Default_2D_shockwave_index == 1) {
575+
// 3D shockwaves and framebuffer shockwaves are both enabled and the default 2D shockwave is in the next slot of the vector
576+
++it;
577+
Assertion(it->bitmap_id >= 0, "Default 2D shockwave was loaded but is somehow missing its bitmap; get a coder!\n");
578+
bm_unload(it->bitmap_id);
579+
}
569580

570581
for (++it; it != Shockwave_info.end(); ++it) {
571582
if (it->bitmap_id >= 0)
@@ -576,7 +587,7 @@ void shockwave_level_close()
576587
}
577588

578589
// if there's no extra shockwaves, this is still fine (erasing from end() to end() is both valid and a no-op)
579-
Shockwave_info.erase( Shockwave_info.begin() + 1, Shockwave_info.end() );
590+
Shockwave_info.erase( Shockwave_info.begin() + (Default_2D_shockwave_index == 1 ? 2 : 1), Shockwave_info.end() );
580591

581592
Shockwave_inited = 0;
582593
}

0 commit comments

Comments
 (0)