Nuke UpdateTexture

• It never gets called except with UpdateMaterial, and UpdateMaterial isnt very heavy
• Also add a check for if the text changed in ModuleTextDecal to avoid calling a bunch of code unnecessarily. Only really affects editor performance when adjusting sliders but nice to have anyways
feature-better-tweakables
Andrew Cassidy 2 years ago
parent 39555d92d1
commit 5a7f101155

@ -134,8 +134,7 @@ namespace ConformalDecals {
if (materialProperties == null) { if (materialProperties == null) {
materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>(); materialProperties = ScriptableObject.CreateInstance<MaterialPropertyCollection>();
} } else {
else {
materialProperties = ScriptableObject.Instantiate(materialProperties); materialProperties = ScriptableObject.Instantiate(materialProperties);
} }
@ -149,24 +148,21 @@ namespace ConformalDecals {
// Load // Load
try { try {
LoadDecal(node); LoadDecal(node);
} } catch (Exception e) {
catch (Exception e) {
this.LogException("Error loading decal", e); this.LogException("Error loading decal", e);
} }
// Setup // Setup
try { try {
SetupDecal(); SetupDecal();
} } catch (Exception e) {
catch (Exception e) {
this.LogException("Error setting up decal", e); this.LogException("Error setting up decal", e);
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public override void OnIconCreate() { public override void OnIconCreate() {
UpdateTextures(); UpdateAll();
UpdateProjection();
} }
/// <inheritdoc /> /// <inheritdoc />
@ -188,13 +184,11 @@ namespace ConformalDecals {
/// This is mostly used to make sure all B9 variants are already in place for the rest of the vessel /// This is mostly used to make sure all B9 variants are already in place for the rest of the vessel
public override void OnStartFinished(StartState state) { public override void OnStartFinished(StartState state) {
// handle game events // handle game events
UpdateTextures();
if (HighLogic.LoadedSceneIsGame) { if (HighLogic.LoadedSceneIsGame) {
// set initial attachment state // set initial attachment state
if (part.parent == null) { if (part.parent == null) {
OnDetach(); OnDetach();
} } else {
else {
OnAttach(); OnAttach();
} }
} }
@ -285,8 +279,7 @@ namespace ConformalDecals {
if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) { if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) {
// if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this // if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this
UpdateProjection(); UpdateProjection();
} } else if (_isAttached) {
else if (_isAttached) {
UpdatePartTarget(eventPart, _boundsRenderer.bounds); UpdatePartTarget(eventPart, _boundsRenderer.bounds);
// recursively call for child parts // recursively call for child parts
foreach (var child in eventPart.children) { foreach (var child in eventPart.children) {
@ -300,8 +293,7 @@ namespace ConformalDecals {
if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) { if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) {
// if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this // if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this
OnAttach(); OnAttach();
} } else {
else {
UpdatePartTarget(eventPart, _boundsRenderer.bounds); UpdatePartTarget(eventPart, _boundsRenderer.bounds);
// recursively call for child parts // recursively call for child parts
foreach (var child in eventPart.children) { foreach (var child in eventPart.children) {
@ -315,8 +307,7 @@ namespace ConformalDecals {
if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) { if (part == eventPart || (firstcall && part.symmetryCounterparts.Contains(eventPart))) {
// if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this // if this is the top-level call (original event part is a decal) then update symmetry counterparts, otherwise just update this
OnDetach(); OnDetach();
} } else if (_isAttached) {
else if (_isAttached) {
_targets.Remove(eventPart); _targets.Remove(eventPart);
// recursively call for child parts // recursively call for child parts
foreach (var child in eventPart.children) { foreach (var child in eventPart.children) {
@ -330,8 +321,7 @@ namespace ConformalDecals {
if (willDie == part.parent && willDie != null) { if (willDie == part.parent && willDie != null) {
this.Log("Parent part about to be destroyed! Killing decal part."); this.Log("Parent part about to be destroyed! Killing decal part.");
part.Die(); part.Die();
} } else if (_isAttached && projectMultiple) {
else if (_isAttached && projectMultiple) {
_targets.Remove(willDie); _targets.Remove(willDie);
} }
} }
@ -406,14 +396,12 @@ namespace ConformalDecals {
if (backRenderer == null) { if (backRenderer == null) {
this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false."); this.LogError($"Specified decalBack transform {decalBack} has no renderer attached! Setting updateBackScale to false.");
updateBackScale = false; updateBackScale = false;
} } else {
else {
backMaterial = backRenderer.material; backMaterial = backRenderer.material;
if (backMaterial == null) { if (backMaterial == null) {
this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false."); this.LogError($"Specified decalBack transform {decalBack} has a renderer but no material! Setting updateBackScale to false.");
updateBackScale = false; updateBackScale = false;
} } else {
else {
if (backTextureBaseScale == default) backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex); if (backTextureBaseScale == default) backTextureBaseScale = backMaterial.GetTextureScale(PropertyIDs._MainTex);
} }
} }
@ -435,8 +423,7 @@ namespace ConformalDecals {
if (tileRect.x >= 0) { if (tileRect.x >= 0) {
materialProperties.UpdateTile(tileRect); materialProperties.UpdateTile(tileRect);
} } else if (tileIndex >= 0) {
else if (tileIndex >= 0) {
materialProperties.UpdateTile(tileIndex, tileSize); materialProperties.UpdateTile(tileIndex, tileSize);
} }
} }
@ -450,8 +437,7 @@ namespace ConformalDecals {
if (HighLogic.LoadedSceneIsGame) { if (HighLogic.LoadedSceneIsGame) {
UpdateAll(); UpdateAll();
} } else {
else {
scale = defaultScale; scale = defaultScale;
depth = defaultDepth; depth = defaultDepth;
opacity = defaultOpacity; opacity = defaultOpacity;
@ -544,16 +530,12 @@ namespace ConformalDecals {
multiprojectEditor.onFieldChanged = OnProjectionTweakEvent; multiprojectEditor.onFieldChanged = OnProjectionTweakEvent;
} }
/// Updates textures, materials, scale and targets /// Updates materials, scale and targets
protected virtual void UpdateAll() { protected virtual void UpdateAll() {
UpdateTextures();
UpdateMaterials(); UpdateMaterials();
UpdateProjection(); UpdateProjection();
} }
/// Update decal textures
protected virtual void UpdateTextures() { }
/// Update decal materials /// Update decal materials
protected virtual void UpdateMaterials() { protected virtual void UpdateMaterials() {
_opacityProperty.value = opacity; _opacityProperty.value = opacity;
@ -623,16 +605,14 @@ namespace ConformalDecals {
IEnumerable<Part> targetParts; IEnumerable<Part> targetParts;
if (projectMultiple) { if (projectMultiple) {
targetParts = HighLogic.LoadedSceneIsFlight ? part.vessel.parts : EditorLogic.fetch.ship.parts; targetParts = HighLogic.LoadedSceneIsFlight ? part.vessel.parts : EditorLogic.fetch.ship.parts;
} } else {
else {
targetParts = new[] {part.parent}; targetParts = new[] {part.parent};
} }
foreach (var targetPart in targetParts) { foreach (var targetPart in targetParts) {
UpdatePartTarget(targetPart, projectionBounds); UpdatePartTarget(targetPart, projectionBounds);
} }
} } else {
else {
// rescale preview model // rescale preview model
decalModelTransform.localScale = new Vector3(size.x, size.y, (size.x + size.y) / 2); decalModelTransform.localScale = new Vector3(size.x, size.y, (size.x + size.y) / 2);
@ -652,8 +632,7 @@ namespace ConformalDecals {
if (rendererList.Any(o => projectionBounds.Intersects(o.bounds))) { if (rendererList.Any(o => projectionBounds.Intersects(o.bounds))) {
target = new ProjectionPartTarget(targetPart, useBaseNormal); target = new ProjectionPartTarget(targetPart, useBaseNormal);
_targets.Add(targetPart, target); _targets.Add(targetPart, target);
} } else {
else {
return; return;
} }
} }

@ -256,9 +256,10 @@ namespace ConformalDecals {
UpdateAll(); UpdateAll();
} }
protected override void UpdateTextures() { protected override void UpdateMaterials() {
// Render text // Render text
var newText = new DecalText(text, font, style, vertical, lineSpacing, charSpacing); var newText = new DecalText(text, font, style, vertical, lineSpacing, charSpacing);
if (newText != _currentText) {
var output = TextRenderer.UpdateText(_currentText, newText); var output = TextRenderer.UpdateText(_currentText, newText);
// update the _currentText state variable // update the _currentText state variable
@ -269,7 +270,6 @@ namespace ConformalDecals {
_decalTextureProperty.SetTile(output.Window); _decalTextureProperty.SetTile(output.Window);
} }
protected override void UpdateMaterials() {
_fillEnabledProperty.value = fillEnabled; _fillEnabledProperty.value = fillEnabled;
_fillColorProperty.color = fillColor; _fillColorProperty.color = fillColor;

Loading…
Cancel
Save