Skip to content

Commit 37ecbe4

Browse files
authored
Gate correct insignias behind flag / version (#7406)
* Gate correct insignias behind flag / version * Move flag to graphics settings
1 parent 3a556d9 commit 37ecbe4

5 files changed

Lines changed: 68 additions & 5 deletions

File tree

code/mod_table/mod_table.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ bool Disable_expensive_turret_target_check;
183183
float Shield_percent_skips_damage;
184184
float Min_radius_for_persistent_debris;
185185
bool Zero_radius_explosions_skip_fireballs;
186+
bool Render_insignias_as_decals;
186187

187188

188189
#ifdef WITH_DISCORD
@@ -1004,6 +1005,10 @@ void parse_mod_table(const char *filename)
10041005
stuff_boolean(&Disable_all_noncustom_generic_debris);
10051006
}
10061007

1008+
if (optional_string("$Render insignias as decals:")) {
1009+
stuff_boolean(&Render_insignias_as_decals);
1010+
}
1011+
10071012
optional_string("#NETWORK SETTINGS");
10081013

10091014
if (optional_string("$FS2NetD port:")) {
@@ -1891,6 +1896,7 @@ void mod_table_reset()
18911896
Shield_percent_skips_damage = 0.1f;
18921897
Min_radius_for_persistent_debris = 50.0f;
18931898
Zero_radius_explosions_skip_fireballs = false;
1899+
Render_insignias_as_decals = false;
18941900
}
18951901

18961902
void mod_table_set_version_flags()
@@ -1921,5 +1927,6 @@ void mod_table_set_version_flags()
19211927
}
19221928
if (mod_supports_version(26, 0, 0)) {
19231929
Zero_radius_explosions_skip_fireballs = true;
1930+
Render_insignias_as_decals = true;
19241931
}
19251932
}

code/mod_table/mod_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ extern bool Disable_expensive_turret_target_check;
205205
extern float Shield_percent_skips_damage;
206206
extern float Min_radius_for_persistent_debris;
207207
extern bool Zero_radius_explosions_skip_fireballs;
208+
extern bool Render_insignias_as_decals;
208209

209210
void mod_table_init();
210211
void mod_table_post_process();

code/model/model.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,11 @@ typedef struct insignia {
735735
vec3d vecs[MAX_INS_VECS]; // vertex list
736736
vec3d offset; // global position offset for this insignia
737737
vec3d norm[MAX_INS_VECS] ; //normal of the insignia-Bobboau
738+
739+
// Computed fields for decal rendering
740+
vec3d position;
741+
matrix orientation;
742+
float diameter;
738743
} insignia;
739744

740745
#define PM_FLAG_ALLOW_TILING (1<<0) // Allow texture tiling

code/model/modelread.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,6 +2742,11 @@ modelread_status read_model_file_no_subsys(polymodel * pm, const char* filename,
27422742
// read in world offset
27432743
cfread_vector(&pm->ins[idx].offset, fp);
27442744

2745+
vec3d min = {{{FLT_MAX, FLT_MAX, FLT_MAX}}};
2746+
vec3d max = {{{-FLT_MAX, -FLT_MAX, -FLT_MAX}}};
2747+
vec3d avg_total = ZERO_VECTOR;
2748+
vec3d avg_normal = ZERO_VECTOR;
2749+
27452750
// read in all the faces
27462751
for(idx2=0; idx2<pm->ins[idx].num_faces; idx2++){
27472752
// read in 3 vertices
@@ -2753,18 +2758,37 @@ modelread_status read_model_file_no_subsys(polymodel * pm, const char* filename,
27532758
vec3d tempv;
27542759

27552760
//get three points (rotated) and compute normal
2761+
const vec3d& v1 = pm->ins[idx].vecs[pm->ins[idx].faces[idx2][0]];
2762+
const vec3d& v2 = pm->ins[idx].vecs[pm->ins[idx].faces[idx2][1]];
2763+
const vec3d& v3 = pm->ins[idx].vecs[pm->ins[idx].faces[idx2][2]];
27562764

27572765
vm_vec_perp(&tempv,
2758-
&pm->ins[idx].vecs[pm->ins[idx].faces[idx2][0]],
2759-
&pm->ins[idx].vecs[pm->ins[idx].faces[idx2][1]],
2760-
&pm->ins[idx].vecs[pm->ins[idx].faces[idx2][2]]);
2766+
&v1,
2767+
&v2,
2768+
&v3);
27612769

27622770
vm_vec_normalize_safe(&tempv);
27632771

27642772
pm->ins[idx].norm[idx2] = tempv;
2765-
// mprintf(("insignorm %.2f %.2f %.2f\n",pm->ins[idx].norm[idx2].xyz.x, pm->ins[idx].norm[idx2].xyz.y, pm->ins[idx].norm[idx2].xyz.z));
2773+
// mprintf(("insignorm %.2f %.2f %.2f\n",pm->ins[idx].norm[idx2].xyz.x, pm->ins[idx].norm[idx2].xyz.y, pm->ins[idx].norm[idx2].xyz.z));
2774+
27662775

2776+
vm_vec_min(&min, &min, &v1);
2777+
vm_vec_min(&min, &min, &v2);
2778+
vm_vec_min(&min, &min, &v3);
2779+
vm_vec_max(&max, &max, &v1);
2780+
vm_vec_max(&max, &max, &v2);
2781+
vm_vec_max(&max, &max, &v3);
2782+
2783+
vec3d avg = (v1 + v2 + v3) * (1.0f / 3.0f);
2784+
avg_total += avg;
2785+
avg_normal += tempv;
27672786
}
2787+
2788+
pm->ins[idx].position = avg_total / static_cast<float>(num_faces) + pm->ins[idx].offset;
2789+
vec3d bb = max - min;
2790+
pm->ins[idx].diameter = std::max({bb.xyz.x, bb.xyz.y, bb.xyz.z});
2791+
vm_vector_2_matrix(&pm->ins[idx].orientation, &avg_normal, &vmd_z_vector);
27682792
}
27692793
break;
27702794

code/model/modelrender.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212
#include "asteroid/asteroid.h"
1313
#include "cmdline/cmdline.h"
14+
#include "decals/decals.h"
1415
#include "gamesequence/gamesequence.h"
16+
#include "globalincs/systemvars.h"
17+
#include "math/floating.h"
1518
#include "graphics/light.h"
1619
#include "graphics/matrix.h"
1720
#include "graphics/shadows.h"
@@ -2984,7 +2987,30 @@ void model_render_queue(const model_render_params* interp, model_draw_list* scen
29842987

29852988
// MARKED!
29862989
if ( !( model_flags & MR_NO_TEXTURING ) && !( model_flags & MR_NO_INSIGNIA) ) {
2987-
scene->add_insignia(interp, pm, detail_level, interp->get_insignia_bitmap());
2990+
int bitmap_num = interp->get_insignia_bitmap();
2991+
if ( Render_insignias_as_decals && objnum >= 0 && (pm->num_ins > 0) && (bitmap_num >= 0) ) {
2992+
for (int ins_idx = 0; ins_idx < pm->num_ins; ins_idx++) {
2993+
const insignia& ins = pm->ins[ins_idx];
2994+
// skip insignias not on our detail level
2995+
if (ins.detail_level != detail_level) {
2996+
continue;
2997+
}
2998+
2999+
decals::Decal decal;
3000+
decal.object = &Objects[objnum];
3001+
decal.position = ins.position;
3002+
decal.submodel = -1;
3003+
decal.scale = vec3d{{{ins.diameter, ins.diameter, ins.diameter}}};
3004+
decal.orig_obj_type = OBJ_SHIP;
3005+
decal.creation_time = f2fl(Missiontime);
3006+
decal.lifetime = 1.0f;
3007+
decal.orientation = ins.orientation;
3008+
decal.definition_handle = std::make_tuple(bitmap_num, -1, -1);
3009+
decals::addSingleFrameDecal(std::move(decal));
3010+
}
3011+
} else {
3012+
scene->add_insignia(interp, pm, detail_level, bitmap_num);
3013+
}
29883014
}
29893015

29903016
if ( (model_flags & MR_AUTOCENTER) && (set_autocen) ) {

0 commit comments

Comments
 (0)