Skip to content
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

refactor: merge universe setup into world pregen screen #5122

Merged
merged 45 commits into from
Nov 13, 2023

Conversation

jdrueckert
Copy link
Member

@jdrueckert jdrueckert commented Jul 17, 2023

Contains

Merging UniverseSetupScreen and WorldPreGenerationScreen incl.

  • merging .ui representations
  • merging .java classes
  • using UniverseWrapper for persisting state
  • binding UI widgets to persisted state

How to test

  1. Start Terasology
  2. Create World via Advanced Game Setup
  3. Play around with world setup screen elements

Outstanding before merging

Based on #5118.

  • merge UI elements
  • merge widget bindings and screen logic
  • use UniverseWrapper instead of local copies of target world and seed
  • use universe seed and properly randomize seed on re-roll
  • fix initial world generator dropdown binding
  • remove worlds element in lower right screen section
  • update preview on changing seed field content
  • memorize modified (manually or via re-roll) seed field content (currently reset always to initial seed)

Follow-Ups

@jdrueckert jdrueckert changed the title Refactor/merge universe into world pregen screen refactor: merge universe setup into world pregen screen Jul 17, 2023
@jdrueckert jdrueckert added Topic: UI/UX Requests, Issues and Changes related to screens, artwork, sound and overall user experience Type: Refactoring Request for or implementation of pure and automatic refactorings, e.g. renaming, to improve clarity labels Jul 17, 2023
@jdrueckert jdrueckert added this to the 2023 Revive - Milestone 1 milestone Jul 17, 2023
@skaldarnar skaldarnar force-pushed the refactor/merge-universe-into-world-pregen-screen branch from 22fe085 to 06217b5 Compare July 18, 2023 16:45
@skaldarnar skaldarnar changed the base branch from develop to refactor/merge-advanced-world-setup-screens July 18, 2023 16:46
@jdrueckert
Copy link
Member Author

@skaldarnar with bb7fab6 I run into the OOM issue again during preview generation:

java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
	at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
	at org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview.render(FacetLayerPreview.java:130)
	at org.terasology.engine.rendering.nui.layers.mainMenu.UniverseSetupScreen.lambda$updatePreview$7(UniverseSetupScreen.java:416)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.OutOfMemoryError: Java heap space

Without it I don't, but I don't get how the changes in that commit would result in running into this kind of a loop there 🤔 any ideas?

@@ -162,7 +159,7 @@ public WorldGeneratorInfo get() {
@Override
public void set(WorldGeneratorInfo value) {
if (value != null) {
if (universeWrapper.getTargetWorld() == null || !value.getUri().equals(universeWrapper.getTargetWorld().getWorldGenerator().getUri())) {
if (universeWrapper.getWorldConfigurator() == null || !value.getUri().equals(universeWrapper.getWorldGenerator().getUri())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why configurator here?

Base automatically changed from refactor/merge-advanced-world-setup-screens to develop July 20, 2023 21:05
public void setUniverseWrapper(UniverseWrapper wrapper) {
universeWrapper = wrapper;
public void setEnvironment(UniverseWrapper wrapper) {
CoreRegistry.put(UniverseWrapper.class, wrapper);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, the idea was to do the following:

context.put(UniverseWrapper.class, wrapper);
CoreRegistry.setContext(context);

However, this does not work and leads to an NPE in UniverseSetupScreen.java:182 when attempting to access UniverseWrapper from a context that it's not in. At this moment, it's unclear, why this does not work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to persist this information in the code as comment instead of just here on this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jdrueckert jdrueckert requested a review from skaldarnar October 16, 2023 22:15
@jdrueckert jdrueckert marked this pull request as ready for review October 16, 2023 22:16
@jdrueckert
Copy link
Member Author

@skaldarnar from my side this would be ready for review

skaldarnar
skaldarnar previously approved these changes Oct 27, 2023
public void setWorld(Context subContext, WorldSetupWrapper worldSelected)
throws UnresolvedWorldGeneratorException {
world = worldSelected;
public void setWorld(Context subContext, UniverseWrapper universe) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm annoyed by these HiddenFieldChecks - I'd like to have an overview in how many places this would actually cause trouble right now, and if we find none, disable this check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had it run on a iota workspace and it came back with more than 2k findings for hidden fields.
I think most of them are constructors or setters, but it's hard to filter those out.

} else {
worldGenerator = world.getWorldGenerator();
}
worldGenerator = universe.getWorldGenerator();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The world generator in the universe can no longer be null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

world generator is set at initialize time (see UniverseSetupScreen#168)
I'd say it not being set is sufficiently unlikely that we don't need the null check anymore.
if you disagree I can re-add it of course

super.onScreenOpened();

final UIText seed = find("seed", UIText.class);
if (seed != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, if we need to check for null here, should we at least log a warning or something in case the seed text widget could not be found? I mean, it should be there when the screen is opened, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I'm not sure, why we need the null check(s) (there's one in AdvancedGameSetupScreen::initialise, too)... I would agree that the text widget should be there when the screen is opened and it should even already be there when it is initialized...
I don't see a valid reason why it should ever not be, so I'll remove the null checks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main reason is that we don't have automated tests that spot NPEs like this. For instance, they can appear if we rename the UI control in the some .ui file but not here, or vice versa, move UI controls around but forget about the code, etc.

It will be pretty apparent while testing locally, but we don't have automated tests that "click through all the screens" that would catch that...

public void setUniverseWrapper(UniverseWrapper wrapper) {
universeWrapper = wrapper;
public void setEnvironment(UniverseWrapper wrapper) {
CoreRegistry.put(UniverseWrapper.class, wrapper);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to persist this information in the code as comment instead of just here on this PR?


DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
if (result.isSuccess()) {
environment = moduleManager.loadEnvironment(result.getModules(), false);
//BlockFamilyLibrary library = new BlockFamilyLibrary(environment, context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was originally part of initAssets but library was never used afterwards.
IIRC I commented it out to see if it breaks anything and wanted to check on possible side-effects it might've been needed for. During my manual tests I didn't see any indicators that commenting it out broke anything.
I can either remove it entirely or replace it with a comment stating that this used to be done in case we see weird behavior in the future that might be related... Which would you prefer?

@jdrueckert jdrueckert merged commit c237660 into develop Nov 13, 2023
8 checks passed
@jdrueckert jdrueckert deleted the refactor/merge-universe-into-world-pregen-screen branch November 13, 2023 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Topic: UI/UX Requests, Issues and Changes related to screens, artwork, sound and overall user experience Type: Refactoring Request for or implementation of pure and automatic refactorings, e.g. renaming, to improve clarity
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants