Skip to content

Commit eb16512

Browse files
authored
Merge pull request #1371 from MageKing17/bugfix/3d-framebuffer-shockwaves
Fix combining 3D shockwaves with framebuffer shockwaves.
2 parents 9447d74 + c30ce55 commit eb16512

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)