-
-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logic for upgrade-relevant models #5110
Conversation
Appearance tab has problems with updating though... |
1bfbcba
to
cc5ee47
Compare
It's ready for review. |
@@ -35,6 +35,12 @@ public class AvailableUpgrade : IRegistryType | |||
[JsonProperty] | |||
public string IconPath { get; private set; } = string.Empty; | |||
|
|||
/// <summary> | |||
/// Optional model scene for upgrade |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Optional model scene for upgrade | |
/// Optional model scene for upgrade which is used instead of the primary organelle graphics when this upgrade is applied |
{ | ||
foreach (var availableUpgrade in definition.AvailableUpgrades) | ||
{ | ||
if (availableUpgrade.Value.ModelPath != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String null comparisons should instead use string.IsNullOrEmpty
.
var visualsInstance = placedOrganelle.Definition.LoadedScene.Instantiate<Node3D>(); | ||
Node3D? visualsInstance = null; | ||
|
||
if (placedOrganelle.Upgrades != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very similar code than in CellEditorComponent
so I think this should be put into a helper method into the upgrades class. Or actually probably better to put into OrganelleDefinition as a method like GetEffectiveVisuals
or named something similar.
{ | ||
if (placedOrganelle.Upgrades.UnlockedFeatures.Contains(availableUpgrade.Key)) | ||
{ | ||
var upgradeRelevantScene = GD.Load<PackedScene>(availableUpgrade.Value.ModelPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These upgrade scenes should be loaded early in the same place organelle scenes in general are loaded (so added to OrganelleDefinition.Resolve
).
I renamed ModelPath to ScenePath because model path now is model inside the scene. |
I think that is a good change to make this more uniformly named compared to how the organelle definition is setup. If I had had futuresight when designing the organelle visuals system, I would have made a struct that holds the scene path, model path, and animation player path all in one as they are very closely related. |
I changed it now that upgrades' model/animation paths naming are the same as organelles' so it can be related easier (I hope it won't conflict) Now, for example, to make slime jet visuals for pilus you have to add What I am concerned about though, is the second commit (4e8c7d7), I don't know if it's good to do it the way like I did, but it worked for me and I am open for criticism. |
08724fc
to
bb820d2
Compare
I don't know why you added that second part of that commit. It seems overtly complicated and I don't even understand why that code is necessary (this is a case where comments are really necessary to explain the reasoning behind the code). |
Actually on second read that code now always creates a new node visuals for an organelle, even when it already had visuals. This creates a bunch of nodes that are never attached to the scene tree causing a resource leak, not to mention the performance impact of re-creating a ton of unnecessary organelle visuals. |
This should now be easier to finish with this being merged: #5128 |
bb820d2
to
152b7eb
Compare
It is now quite different (and simpler) from previous implementation thanks to #5128 |
Could someone help with CI check failure though? |
@@ -1861,7 +1861,7 @@ private void RenderHighlightedOrganelle(int q, int r, int rotation, OrganelleDef | |||
bool showModel = !hadDuplicate; | |||
|
|||
// Model | |||
if (showModel && shownOrganelle.TryGetGraphicsScene(out var modelInfo)) | |||
if (showModel && shownOrganelle.TryGetGraphicsScene(null, out var modelInfo)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When moving an organelle, shouldn't this method take in a parameter specifying the organelle upgrades so that the visuals are consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upgrades are available from PlacedOrganelle and there is not much of it available for this line (shownOrganelle
is OrganelleDefinition)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When moving an organelle, the variable MovingPlacedHex
is of type OrganelleTemplate
which contains upgrade data. That's why I made that comment. So updating this method to allow passing in upgrade data would hopefully make it relatively simple to pass those upgrades in when moving a hex.
// UpdateAlreadyPlacedVisuals(); | ||
microbeVisualizationOrganellePositionsAreDirty = true; | ||
|
||
OnOrganellesChanged(); | ||
|
||
UpdateStats(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line for StartAutoEvoPrediction
should be deleted as OnOrganellesChanged
already calls that. This same thing is in the undo method.
@@ -657,6 +657,30 @@ private Vector3 CalculateCenterOffset() | |||
return offset; | |||
} | |||
|
|||
private LoadedSceneWithModelInfo? TryGetGraphicsForUpgrade(OrganelleUpgrades? upgrades) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has the boxing problem as well.
@@ -657,6 +657,30 @@ private Vector3 CalculateCenterOffset() | |||
return offset; | |||
} | |||
|
|||
private LoadedSceneWithModelInfo? TryGetGraphicsForUpgrade(OrganelleUpgrades? upgrades) | |||
{ | |||
if (upgrades != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd swap this the otherway around to early return if upgrades is null.
var upgradeGraphics = availableUpgrade.Value.TryGetGraphicsScene(); | ||
|
||
if (upgradeGraphics != null) | ||
{ | ||
if (upgrades.UnlockedFeatures.Contains(availableUpgrade.Key)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd write this the other way around: check if an upgrade is present before doing the logic for fetching its scene.
if (availableUpgrade.Value.TryGetGraphicsScene().HasValue) | ||
{ | ||
return availableUpgrade.Value.TryGetGraphicsScene(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, refactoring the TryGet method in the upgrade to directly return the data like TryGetGraphicsScene would allow simplifying this and removing the duplicate method call (or actually considering line 666 there's actually 3 calls to the same method here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now only the thing I commented on somewhere above and this (if it's necesary) yet to go.
#pragma warning disable 169,649 // Used through reflection | ||
/// <summary> | ||
/// A path to a scene to override organelle's display scene. If empty won't have a display model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If empty won't have a display model.
Isn't this wrong or very annoying? Because upgrades that don't specify visual changes should just use the normal organelle graphics.
} | ||
} | ||
|
||
public LoadedSceneWithModelInfo TryGetGraphicsScene() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public LoadedSceneWithModelInfo TryGetGraphicsScene() | |
public bool TryGetGraphicsScene(out LoadedSceneWithModelInfo overrideGraphics) |
The signature should be like this to match the other TryGet methods I added, and also to follow the convention set by the C# standard library with its TryGet methods.
@@ -275,10 +275,19 @@ public enum OrganelleGroup | |||
/// The model info returned like this (as it may be a struct type this can't return a nullable reference without | |||
/// boxing) | |||
/// </para> | |||
/// <para cref="upgrades"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <para cref="upgrades"> | |
/// <param cref="upgrades"> |
Typo in the XML tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I do as you suggested, my IDE complains that it is lacking a name. I tried replacing cref= with name=, it stopped complaining but nothing really changed when I hovered my mouse above the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The right syntax is:
/// <param name="useDefaults">If true default checks are added automatically</param>
(just a random example I grabbed from Thrive).
bfbd337
to
ae7bb13
Compare
Might be good now. |
ae7bb13
to
1a61474
Compare
/// <param name="upgrades"> | ||
/// Some upgrades alter organelle visuals | ||
/// </param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <param name="upgrades"> | |
/// Some upgrades alter organelle visuals | |
/// </param> | |
/// <param name="upgrades">Some upgrades alter organelle visuals</param> |
This fits on a single line.
{ | ||
// TODO: allow this to be affected by upgrades (add as a first parameter to this method) | ||
var hasUpgradeGraphics = TryGetGraphicsForUpgrade(upgrades, out var upgradeGraphics); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var hasUpgradeGraphics = TryGetGraphicsForUpgrade(upgrades, out var upgradeGraphics); | |
var hasUpgradeGraphics = TryGetGraphicsForUpgrade(upgrades, out modelInfo); |
This can directly write to the out variable of this method to save one data copy.
// TODO: allow this to be affected by upgrades (add as a first parameter to this method) | ||
var hasUpgradeGraphics = TryGetGraphicsForUpgrade(upgrades, out var upgradeGraphics); | ||
|
||
if (hasUpgradeGraphics) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need a separate bool so I'd recommend something like:
if (TryGetGraphicsForUpgrade(upgrades, out modelInfo)
{
return true;
}
then also the line modelInfo = default(LoadedSceneWithModelInfo);
should be removable to avoid one more data copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How removable? Do I put it in else
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, just remove the line entirely, it should compile without it.
{ | ||
// TODO: allow this to be affected by upgrades (add as a first parameter to this method) | ||
var hasUpgradeGraphics = TryGetGraphicsForUpgrade(upgrades, out var upgradeGraphics); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of this method should have the changes applied I mentioned above for the very similar block of code.
bool hasUpgradeScene = availableUpgrade.Value.TryGetGraphicsScene(out var upgradeGraphicsScene); | ||
if (hasUpgradeScene) | ||
{ | ||
upgradeScene = upgradeGraphicsScene; | ||
|
||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool hasUpgradeScene = availableUpgrade.Value.TryGetGraphicsScene(out var upgradeGraphicsScene); | |
if (hasUpgradeScene) | |
{ | |
upgradeScene = upgradeGraphicsScene; | |
return true; | |
} | |
if (availableUpgrade.Value.TryGetGraphicsScene(out upgradeScene)) | |
{ | |
return true; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the architecture approach and other code is good now, I just want some improvements still to the struct data copy handling and removing some unnecessary intermediate bool values.
If it's still to be tested, here's example object you can insert into upgrade in
Edit: Corrected it for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did ever so slight changes and verified my last comments require no further actions. I didn't test the actual override graphics feature, but that can wait until we have a completed model and are adding it in a PR.
Brief Description of What This PR Does
Now upgrades can have
"ScenePath":
in organelles.json to have upgrade-specific models.Related Issues
Closes #4106
Progress Checklist
Note: before starting this checklist the PR should be marked as non-draft.
break existing features:
https://wiki.revolutionarygamesstudio.com/wiki/Testing_Checklist
(this is important as to not waste the time of Thrive team
members reviewing this PR)
styleguide.
Before merging all CI jobs should finish on this PR without errors, if
there are automatically detected style issues they should be fixed by
the PR author. Merging must follow our
styleguide.