From 79c033641301371897bdc76dec5a802adb280f38 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 24 Jul 2021 20:24:43 -0700 Subject: [PATCH 01/14] bugfix: resolved loading issue when attempting to start a world twice --- .../engine/core/TerasologyEngine.java | 6 +- .../bootstrap/EnvironmentSwitchHandler.java | 20 +++++- .../engine/core/modes/StateLoading.java | 2 + .../loadProcesses/InitializeRendering.java | 33 +++++++++ .../rendering/ModuleRenderingSubsystem.java | 70 ------------------- .../engine/rendering/opengl/GLSLMaterial.java | 1 + .../loader/BlockFamilyDefinitionFormat.java | 9 ++- 7 files changed, 62 insertions(+), 79 deletions(-) create mode 100644 engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitializeRendering.java delete mode 100644 engine/src/main/java/org/terasology/engine/core/subsystem/rendering/ModuleRenderingSubsystem.java diff --git a/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java b/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java index ffeeaf41560..5239c024344 100644 --- a/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java +++ b/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java @@ -29,7 +29,6 @@ import org.terasology.engine.core.subsystem.common.ThreadManagerSubsystem; import org.terasology.engine.core.subsystem.common.TimeSubsystem; import org.terasology.engine.core.subsystem.common.WorldGenerationSubsystem; -import org.terasology.engine.core.subsystem.rendering.ModuleRenderingSubsystem; import org.terasology.engine.entitySystem.prefab.Prefab; import org.terasology.engine.entitySystem.prefab.internal.PojoPrefab; import org.terasology.engine.i18n.I18nSubsystem; @@ -175,7 +174,7 @@ public TerasologyEngine(TimeSubsystem timeSubsystem, Collection this.allSubsystems.add(new GameSubsystem()); this.allSubsystems.add(new I18nSubsystem()); this.allSubsystems.add(new TelemetrySubSystem()); - this.allSubsystems.add(new ModuleRenderingSubsystem()); +// this.allSubsystems.add(new ModuleRenderingSubsystem()); // add all subsystem as engine module part. (needs for ECS classes loaded from external subsystems) allSubsystems.stream().map(Object::getClass).forEach(this::addToClassesOnClasspathsToAddToEngine); @@ -489,7 +488,7 @@ public boolean tick() { } Iterator updateCycles = timeSubsystem.getEngineTime().tick(); - CoreRegistry.setContext(currentState.getContext()); +// CoreRegistry.setContext(currentState.getContext()); rootContext.get(NetworkSystem.class).setContext(currentState.getContext()); for (EngineSubsystem subsystem : allSubsystems) { @@ -586,6 +585,7 @@ private void switchState(GameState newState) { if (currentState != null) { currentState.dispose(); } + CoreRegistry.setContext(newState.getContext()); currentState = newState; LoggingContext.setGameState(newState); newState.init(this); diff --git a/engine/src/main/java/org/terasology/engine/core/bootstrap/EnvironmentSwitchHandler.java b/engine/src/main/java/org/terasology/engine/core/bootstrap/EnvironmentSwitchHandler.java index d24027b9322..3432dafc731 100644 --- a/engine/src/main/java/org/terasology/engine/core/bootstrap/EnvironmentSwitchHandler.java +++ b/engine/src/main/java/org/terasology/engine/core/bootstrap/EnvironmentSwitchHandler.java @@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory; import org.terasology.engine.config.flexible.AutoConfigManager; import org.terasology.engine.context.Context; +import org.terasology.engine.core.TerasologyConstants; import org.terasology.engine.core.module.ModuleManager; import org.terasology.engine.entitySystem.metadata.ComponentLibrary; import org.terasology.engine.entitySystem.metadata.EntitySystemLibrary; @@ -28,6 +29,13 @@ import org.terasology.engine.physics.CollisionGroup; import org.terasology.engine.physics.CollisionGroupManager; import org.terasology.engine.registry.InjectionHelper; +import org.terasology.engine.rendering.assets.atlas.Atlas; +import org.terasology.engine.rendering.assets.texture.Texture; +import org.terasology.engine.rendering.assets.texture.TextureRegionAsset; +import org.terasology.engine.world.block.loader.BlockFamilyDefinition; +import org.terasology.gestalt.assets.Asset; +import org.terasology.gestalt.assets.AssetType; +import org.terasology.gestalt.assets.ResourceUrn; import org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager; import org.terasology.gestalt.module.ModuleEnvironment; import org.terasology.gestalt.util.reflection.GenericsUtil; @@ -99,6 +107,7 @@ public void handleSwitchToGameEnvironment(Context context) { context.put(EventLibrary.class, library.getEventLibrary()); context.put(ClassMetaLibrary.class, new ClassMetaLibraryImpl(context)); + registerComponents(componentLibrary, environment); registerTypeHandlers(context, typeHandlerLibrary, environment); @@ -107,7 +116,6 @@ public void handleSwitchToGameEnvironment(Context context) { autoConfigManager.loadConfigsIn(context); ModuleAwareAssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class); - /* * The registering of the prefab formats is done in this method, because it needs to be done before * the environment of the asset manager gets changed. @@ -116,6 +124,16 @@ public void handleSwitchToGameEnvironment(Context context) { * existing then yet. */ unregisterPrefabFormats(assetTypeManager); + assetTypeManager.getAssetTypes().forEach(k -> { + for (ResourceUrn urn : k.getLoadedAssetUrns()) { + if (!urn.getModuleName().equals(TerasologyConstants.ENGINE_MODULE)) { + k.getAsset(urn).ifPresent(Asset::dispose); + } + } + }); + assetTypeManager.getAssetType(BlockFamilyDefinition.class).ifPresent(AssetType::disposeAll); + assetTypeManager.getAssetType(Prefab.class).ifPresent(AssetType::disposeAll); + registeredPrefabFormat = new PrefabFormat(componentLibrary, typeHandlerLibrary); assetTypeManager.getAssetFileDataProducer(assetTypeManager .getAssetType(Prefab.class) diff --git a/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java b/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java index f93ba8ec005..db59e1b2ca6 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java @@ -29,6 +29,7 @@ import org.terasology.engine.core.modes.loadProcesses.InitialiseSystems; import org.terasology.engine.core.modes.loadProcesses.InitialiseWorld; import org.terasology.engine.core.modes.loadProcesses.InitialiseWorldGenerator; +import org.terasology.engine.core.modes.loadProcesses.InitializeRendering; import org.terasology.engine.core.modes.loadProcesses.JoinServer; import org.terasology.engine.core.modes.loadProcesses.LoadEntities; import org.terasology.engine.core.modes.loadProcesses.LoadExtraBlockData; @@ -165,6 +166,7 @@ private void initClient() { private void initHost() { loadProcesses.add(new RegisterMods(context, gameManifest)); + loadProcesses.add(new InitializeRendering(context)); loadProcesses.add(new InitialiseEntitySystem(context)); loadProcesses.add(new RegisterBlocks(context, gameManifest)); loadProcesses.add(new InitialiseGraphics(context)); diff --git a/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitializeRendering.java b/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitializeRendering.java new file mode 100644 index 00000000000..43887cdb889 --- /dev/null +++ b/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitializeRendering.java @@ -0,0 +1,33 @@ +// Copyright 2021 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 + +package org.terasology.engine.core.modes.loadProcesses; + +import org.terasology.engine.context.Context; +import org.terasology.engine.core.modes.SingleStepLoadProcess; +import org.terasology.engine.core.module.rendering.RenderingModuleRegistry; + +public class InitializeRendering extends SingleStepLoadProcess { + private final Context context; + + public InitializeRendering(Context context) { + this.context = context; + } + + + @Override + public String getMessage() { + return "Initialising Rendering System..."; + } + + @Override + public boolean step() { + context.put(RenderingModuleRegistry.class, new RenderingModuleRegistry()); + return true; + } + + @Override + public int getExpectedCost() { + return 1; + } +} diff --git a/engine/src/main/java/org/terasology/engine/core/subsystem/rendering/ModuleRenderingSubsystem.java b/engine/src/main/java/org/terasology/engine/core/subsystem/rendering/ModuleRenderingSubsystem.java deleted file mode 100644 index d300558d5e8..00000000000 --- a/engine/src/main/java/org/terasology/engine/core/subsystem/rendering/ModuleRenderingSubsystem.java +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2021 The Terasology Foundation -// SPDX-License-Identifier: Apache-2.0 -package org.terasology.engine.core.subsystem.rendering; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.terasology.engine.context.Context; -import org.terasology.engine.core.ComponentSystemManager; -import org.terasology.engine.core.GameEngine; -import org.terasology.engine.core.modes.GameState; -import org.terasology.engine.core.module.rendering.RenderingModuleRegistry; -import org.terasology.engine.core.subsystem.EngineSubsystem; -import org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager; - -public class ModuleRenderingSubsystem implements EngineSubsystem { - private static final Logger logger = LoggerFactory.getLogger(ModuleRenderingSubsystem.class); - - private RenderingModuleRegistry renderingModuleRegistry; - - @Override - public String getName() { - return "ModuleRendering"; - } - - @Override - public void preInitialise(Context rootContext) { - - } - - @Override - public void initialise(GameEngine engine, Context rootContext) { - this.renderingModuleRegistry = new RenderingModuleRegistry(); - rootContext.put(RenderingModuleRegistry.class, this.renderingModuleRegistry); - } - - @Override - public void registerCoreAssetTypes(ModuleAwareAssetTypeManager assetTypeManager) { - - } - - @Override - public void postInitialise(Context context) { - - } - - @Override - public void preUpdate(GameState currentState, float delta) { - - } - - @Override - public void postUpdate(GameState currentState, float delta) { - - } - - @Override - public void preShutdown() { - - } - - @Override - public void shutdown() { - - } - - @Override - public void registerSystems(ComponentSystemManager componentSystemManager) { - - } -} diff --git a/engine/src/main/java/org/terasology/engine/rendering/opengl/GLSLMaterial.java b/engine/src/main/java/org/terasology/engine/rendering/opengl/GLSLMaterial.java index bc5123eca44..3a65a2d0bc3 100644 --- a/engine/src/main/java/org/terasology/engine/rendering/opengl/GLSLMaterial.java +++ b/engine/src/main/java/org/terasology/engine/rendering/opengl/GLSLMaterial.java @@ -103,6 +103,7 @@ public void bindTextures() { for (int slot : textureMap.keys()) { Texture texture = textureMap.get(slot); if (texture.isDisposed()) { + textureMap.remove(slot); logger.error("Attempted to bind disposed texture {}", texture); } else { shaderManager.bindTexture(slot, texture); diff --git a/engine/src/main/java/org/terasology/engine/world/block/loader/BlockFamilyDefinitionFormat.java b/engine/src/main/java/org/terasology/engine/world/block/loader/BlockFamilyDefinitionFormat.java index 2bdcfd44a1a..a778b62fc82 100644 --- a/engine/src/main/java/org/terasology/engine/world/block/loader/BlockFamilyDefinitionFormat.java +++ b/engine/src/main/java/org/terasology/engine/world/block/loader/BlockFamilyDefinitionFormat.java @@ -19,12 +19,8 @@ import com.google.gson.stream.JsonWriter; import org.joml.Vector3f; import org.joml.Vector4f; -import org.terasology.gestalt.assets.Asset; -import org.terasology.gestalt.assets.ResourceUrn; import org.terasology.engine.entitySystem.prefab.Prefab; import org.terasology.engine.registry.CoreRegistry; -import org.terasology.engine.world.block.shapes.BlockShape; -import org.terasology.engine.world.block.sounds.BlockSounds; import org.terasology.engine.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory; import org.terasology.engine.utilities.gson.Vector3fTypeAdapter; import org.terasology.engine.utilities.gson.Vector4fTypeAdapter; @@ -35,7 +31,11 @@ import org.terasology.engine.world.block.family.HorizontalFamily; import org.terasology.engine.world.block.family.MultiSection; import org.terasology.engine.world.block.family.SymmetricFamily; +import org.terasology.engine.world.block.shapes.BlockShape; +import org.terasology.engine.world.block.sounds.BlockSounds; import org.terasology.engine.world.block.tiles.BlockTile; +import org.terasology.gestalt.assets.Asset; +import org.terasology.gestalt.assets.ResourceUrn; import org.terasology.gestalt.assets.format.AbstractAssetFileFormat; import org.terasology.gestalt.assets.format.AssetDataFile; import org.terasology.gestalt.assets.management.AssetManager; @@ -315,7 +315,6 @@ private static class BlockFamilyHandler implements JsonDeserializer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - BlockFamilyLibrary library = CoreRegistry.get(BlockFamilyLibrary.class); return library.getBlockFamily(json.getAsString()); } From ff8608ae2610e15f4ab61181c010b8d315273c78 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 24 Jul 2021 20:32:07 -0700 Subject: [PATCH 02/14] chore: cleanup --- .../main/java/org/terasology/engine/core/TerasologyEngine.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java b/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java index 5239c024344..bb7c5d36cf6 100644 --- a/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java +++ b/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java @@ -174,7 +174,6 @@ public TerasologyEngine(TimeSubsystem timeSubsystem, Collection this.allSubsystems.add(new GameSubsystem()); this.allSubsystems.add(new I18nSubsystem()); this.allSubsystems.add(new TelemetrySubSystem()); -// this.allSubsystems.add(new ModuleRenderingSubsystem()); // add all subsystem as engine module part. (needs for ECS classes loaded from external subsystems) allSubsystems.stream().map(Object::getClass).forEach(this::addToClassesOnClasspathsToAddToEngine); @@ -488,7 +487,6 @@ public boolean tick() { } Iterator updateCycles = timeSubsystem.getEngineTime().tick(); -// CoreRegistry.setContext(currentState.getContext()); rootContext.get(NetworkSystem.class).setContext(currentState.getContext()); for (EngineSubsystem subsystem : allSubsystems) { From da58e0c834a29bf7888f11fd6be007d10f2af08d Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 24 Jul 2021 21:12:40 -0700 Subject: [PATCH 03/14] chore: add InitialiseRendering --- .../java/org/terasology/engine/core/modes/StateLoading.java | 4 ++-- .../{InitializeRendering.java => InitialiseRendering.java} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/{InitializeRendering.java => InitialiseRendering.java} (86%) diff --git a/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java b/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java index db59e1b2ca6..18d9453f029 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java @@ -29,7 +29,7 @@ import org.terasology.engine.core.modes.loadProcesses.InitialiseSystems; import org.terasology.engine.core.modes.loadProcesses.InitialiseWorld; import org.terasology.engine.core.modes.loadProcesses.InitialiseWorldGenerator; -import org.terasology.engine.core.modes.loadProcesses.InitializeRendering; +import org.terasology.engine.core.modes.loadProcesses.InitialiseRendering; import org.terasology.engine.core.modes.loadProcesses.JoinServer; import org.terasology.engine.core.modes.loadProcesses.LoadEntities; import org.terasology.engine.core.modes.loadProcesses.LoadExtraBlockData; @@ -166,7 +166,7 @@ private void initClient() { private void initHost() { loadProcesses.add(new RegisterMods(context, gameManifest)); - loadProcesses.add(new InitializeRendering(context)); + loadProcesses.add(new InitialiseRendering(context)); loadProcesses.add(new InitialiseEntitySystem(context)); loadProcesses.add(new RegisterBlocks(context, gameManifest)); loadProcesses.add(new InitialiseGraphics(context)); diff --git a/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitializeRendering.java b/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java similarity index 86% rename from engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitializeRendering.java rename to engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java index 43887cdb889..f5e4ea2edc3 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitializeRendering.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java @@ -7,10 +7,10 @@ import org.terasology.engine.core.modes.SingleStepLoadProcess; import org.terasology.engine.core.module.rendering.RenderingModuleRegistry; -public class InitializeRendering extends SingleStepLoadProcess { +public class InitialiseRendering extends SingleStepLoadProcess { private final Context context; - public InitializeRendering(Context context) { + public InitialiseRendering(Context context) { this.context = context; } From d69a0d75f1d9c24524e8855e91c59b56fd209863 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Mon, 26 Jul 2021 21:16:08 -0700 Subject: [PATCH 04/14] chore: add rendering to client and only how with a local client --- .../java/org/terasology/engine/core/modes/StateLoading.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java b/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java index 18d9453f029..f303a955e5b 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/StateLoading.java @@ -142,6 +142,7 @@ public void init(GameEngine engine) { private void initClient() { loadProcesses.add(new JoinServer(context, gameManifest, joinStatus)); + loadProcesses.add(new InitialiseRendering(context)); loadProcesses.add(new InitialiseEntitySystem(context)); loadProcesses.add(new RegisterBlocks(context, gameManifest)); loadProcesses.add(new InitialiseGraphics(context)); @@ -166,7 +167,9 @@ private void initClient() { private void initHost() { loadProcesses.add(new RegisterMods(context, gameManifest)); - loadProcesses.add(new InitialiseRendering(context)); + if(netMode.hasLocalClient()) { + loadProcesses.add(new InitialiseRendering(context)); + } loadProcesses.add(new InitialiseEntitySystem(context)); loadProcesses.add(new RegisterBlocks(context, gameManifest)); loadProcesses.add(new InitialiseGraphics(context)); From c2403f43b4da1ba2e647c464cf7b32cc64d5e479 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Wed, 4 Aug 2021 20:52:05 -0700 Subject: [PATCH 05/14] chore: remove caching from DefaultColorSource --- .../engine/world/block/DefaultColorSource.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/engine/src/main/java/org/terasology/engine/world/block/DefaultColorSource.java b/engine/src/main/java/org/terasology/engine/world/block/DefaultColorSource.java index 1d5ca12e2fa..593f683ecaf 100644 --- a/engine/src/main/java/org/terasology/engine/world/block/DefaultColorSource.java +++ b/engine/src/main/java/org/terasology/engine/world/block/DefaultColorSource.java @@ -17,12 +17,10 @@ public Colorc calcColor(int x, int y, int z) { COLOR_LUT { @Override public Colorc calcColor(int x, int y, int z) { + ColorProvider colorProvider = CoreRegistry.get(ColorProvider.class); + // Return white as default if there aren't any color providers if (colorProvider == null) { - colorProvider = CoreRegistry.get(ColorProvider.class); - // Return white as default if there aren't any color providers - if (colorProvider == null) { - return Color.white; - } + return Color.white; } return colorProvider.colorLut(x, y, z); } @@ -30,16 +28,12 @@ public Colorc calcColor(int x, int y, int z) { FOLIAGE_LUT { @Override public Colorc calcColor(int x, int y, int z) { + ColorProvider colorProvider = CoreRegistry.get(ColorProvider.class); + // Return white as default if there aren't any color providers if (colorProvider == null) { - colorProvider = CoreRegistry.get(ColorProvider.class); - // Return white as default if there aren't any color providers - if (colorProvider == null) { - return Color.white; - } + return Color.white; } return colorProvider.foliageLut(x, y, z); } }; - - private static ColorProvider colorProvider; } From 029062fb2029b9ff97be74ea9c75a89a9960b8da Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 7 Aug 2021 09:10:26 -0700 Subject: [PATCH 06/14] Update engine/src/main/java/org/terasology/engine/core/bootstrap/EnvironmentSwitchHandler.java Co-authored-by: Tobias Nett --- .../engine/core/bootstrap/EnvironmentSwitchHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/engine/src/main/java/org/terasology/engine/core/bootstrap/EnvironmentSwitchHandler.java b/engine/src/main/java/org/terasology/engine/core/bootstrap/EnvironmentSwitchHandler.java index 28d358e5663..152a3ab6862 100644 --- a/engine/src/main/java/org/terasology/engine/core/bootstrap/EnvironmentSwitchHandler.java +++ b/engine/src/main/java/org/terasology/engine/core/bootstrap/EnvironmentSwitchHandler.java @@ -99,7 +99,6 @@ public void handleSwitchToGameEnvironment(Context context) { context.put(EventLibrary.class, library.getEventLibrary()); context.put(ClassMetaLibrary.class, new ClassMetaLibraryImpl(context)); - registerComponents(componentLibrary, environment); registerTypeHandlers(context, typeHandlerLibrary, environment); From 5be727a3b97e0d0408bd622675cd448c0eb0ab55 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 7 Aug 2021 09:10:41 -0700 Subject: [PATCH 07/14] Update engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java Co-authored-by: Tobias Nett --- .../main/java/org/terasology/engine/core/modes/StateIngame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java index cf60fadc631..5bc7ccfb605 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java @@ -109,9 +109,9 @@ public Boolean get() { @Override public void dispose(boolean shuttingDown) { ChunkProvider chunkProvider = context.get(ChunkProvider.class); - AssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class); chunkProvider.dispose(); + AssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class); assetTypeManager.getAssetTypes().forEach(k -> { for (ResourceUrn urn : k.getLoadedAssetUrns()) { if (!urn.getModuleName().equals(TerasologyConstants.ENGINE_MODULE)) { From 892bc70b8e5408eebec8ad22435ffce6623afe43 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 7 Aug 2021 09:10:48 -0700 Subject: [PATCH 08/14] Update engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java Co-authored-by: Tobias Nett --- .../main/java/org/terasology/engine/core/modes/StateIngame.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java index 5bc7ccfb605..2525783be18 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java @@ -121,8 +121,6 @@ public void dispose(boolean shuttingDown) { }); assetTypeManager.getAssetType(BlockFamilyDefinition.class).ifPresent(AssetType::disposeAll); assetTypeManager.getAssetType(Prefab.class).ifPresent(AssetType::disposeAll); - - boolean save = networkSystem.getMode().isAuthority(); if (save) { storageManager.waitForCompletionOfPreviousSaveAndStartSaving(); From d5b173f1c8347304a2cd92e09bbe618f8b244d72 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 7 Aug 2021 09:10:56 -0700 Subject: [PATCH 09/14] Update engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java Co-authored-by: Tobias Nett --- .../main/java/org/terasology/engine/core/modes/StateIngame.java | 1 - 1 file changed, 1 deletion(-) diff --git a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java index 2525783be18..9fbd98515fa 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java @@ -159,7 +159,6 @@ public void dispose(boolean shuttingDown) { console.dispose(); GameThread.clearWaitingProcesses(); - /* * Clear the binding as otherwise the complete ingame state would be * referenced. From d0a3f46f2a9b1945c8b2f0697eec789ef3d5f95d Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 7 Aug 2021 11:21:14 -0700 Subject: [PATCH 10/14] chore: apply suggestion --- .../core/modes/loadProcesses/InitialiseRendering.java | 3 +++ .../block/loader/BlockFamilyDefinitionFormat.java | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java b/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java index f5e4ea2edc3..53d7c8c3884 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java @@ -7,6 +7,9 @@ import org.terasology.engine.core.modes.SingleStepLoadProcess; import org.terasology.engine.core.module.rendering.RenderingModuleRegistry; +/** + * Add {@link RenderingModuleRegistry} to the game {@link Context}. + */ public class InitialiseRendering extends SingleStepLoadProcess { private final Context context; diff --git a/engine/src/main/java/org/terasology/engine/world/block/loader/BlockFamilyDefinitionFormat.java b/engine/src/main/java/org/terasology/engine/world/block/loader/BlockFamilyDefinitionFormat.java index 206ed36bfd8..6ffd487c2ff 100644 --- a/engine/src/main/java/org/terasology/engine/world/block/loader/BlockFamilyDefinitionFormat.java +++ b/engine/src/main/java/org/terasology/engine/world/block/loader/BlockFamilyDefinitionFormat.java @@ -19,24 +19,24 @@ import com.google.gson.stream.JsonWriter; import org.joml.Vector3f; import org.joml.Vector4f; +import org.terasology.engine.world.block.DefaultColorSource; +import org.terasology.gestalt.assets.Asset; +import org.terasology.gestalt.assets.ResourceUrn; import org.terasology.engine.entitySystem.prefab.Prefab; import org.terasology.engine.registry.CoreRegistry; +import org.terasology.engine.world.block.shapes.BlockShape; +import org.terasology.engine.world.block.sounds.BlockSounds; import org.terasology.engine.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory; import org.terasology.engine.utilities.gson.Vector3fTypeAdapter; import org.terasology.engine.utilities.gson.Vector4fTypeAdapter; import org.terasology.engine.world.block.BlockPart; -import org.terasology.engine.world.block.DefaultColorSource; import org.terasology.engine.world.block.family.BlockFamily; import org.terasology.engine.world.block.family.BlockFamilyLibrary; import org.terasology.engine.world.block.family.FreeformFamily; import org.terasology.engine.world.block.family.HorizontalFamily; import org.terasology.engine.world.block.family.MultiSection; import org.terasology.engine.world.block.family.SymmetricFamily; -import org.terasology.engine.world.block.shapes.BlockShape; -import org.terasology.engine.world.block.sounds.BlockSounds; import org.terasology.engine.world.block.tiles.BlockTile; -import org.terasology.gestalt.assets.Asset; -import org.terasology.gestalt.assets.ResourceUrn; import org.terasology.gestalt.assets.format.AbstractAssetFileFormat; import org.terasology.gestalt.assets.format.AssetDataFile; import org.terasology.gestalt.assets.management.AssetManager; @@ -318,6 +318,7 @@ private static class BlockFamilyHandler implements JsonDeserializer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + BlockFamilyLibrary library = CoreRegistry.get(BlockFamilyLibrary.class); return library.getBlockFamily(json.getAsString()); } From 9bac248ef37df6d1817e54de611e3aebe6ede485 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 7 Aug 2021 15:30:23 -0700 Subject: [PATCH 11/14] Update engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java Co-authored-by: Tobias Nett --- .../main/java/org/terasology/engine/core/modes/StateIngame.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java index 9fbd98515fa..8a4c1f34c51 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java @@ -119,8 +119,10 @@ public void dispose(boolean shuttingDown) { } } }); + // dispose engine assets that should not be kept when switching game states assetTypeManager.getAssetType(BlockFamilyDefinition.class).ifPresent(AssetType::disposeAll); assetTypeManager.getAssetType(Prefab.class).ifPresent(AssetType::disposeAll); + boolean save = networkSystem.getMode().isAuthority(); if (save) { storageManager.waitForCompletionOfPreviousSaveAndStartSaving(); From 48ee146c1b397b8b8e207c4ab952ae2a8c00ab3a Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 7 Aug 2021 15:30:29 -0700 Subject: [PATCH 12/14] Update engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java Co-authored-by: Tobias Nett --- .../java/org/terasology/engine/core/modes/StateIngame.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java index 8a4c1f34c51..73d37cca56c 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java @@ -112,10 +112,10 @@ public void dispose(boolean shuttingDown) { chunkProvider.dispose(); AssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class); - assetTypeManager.getAssetTypes().forEach(k -> { - for (ResourceUrn urn : k.getLoadedAssetUrns()) { + assetTypeManager.getAssetTypes().forEach(assetType -> { + for (ResourceUrn urn : assetType.getLoadedAssetUrns()) { if (!urn.getModuleName().equals(TerasologyConstants.ENGINE_MODULE)) { - k.getAsset(urn).ifPresent(Asset::dispose); + assetType.getAsset(urn).ifPresent(Asset::dispose); } } }); From e890e22ad88bcdfb81c6993cc89f1eac407d3813 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 7 Aug 2021 15:30:37 -0700 Subject: [PATCH 13/14] Update engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java Co-authored-by: Tobias Nett --- .../core/modes/loadProcesses/InitialiseRendering.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java b/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java index 53d7c8c3884..eb3a7394799 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/InitialiseRendering.java @@ -9,6 +9,12 @@ /** * Add {@link RenderingModuleRegistry} to the game {@link Context}. + * + * The rendering system is required whenever a client starts or joins a game. As rendering may fail to re-initialise + * correctly when it has previously been constructed, this loading process will populate the {@link Context} with a + * freshly created rendering system. + * + * When switching the game state, the rendering system can just be disposed with the old state. */ public class InitialiseRendering extends SingleStepLoadProcess { private final Context context; From 6d97df37648b9c9c782b2d5472e58ad9152b7421 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sat, 7 Aug 2021 15:50:53 -0700 Subject: [PATCH 14/14] chore: add missing comment --- .../main/java/org/terasology/engine/core/modes/StateIngame.java | 1 + 1 file changed, 1 insertion(+) diff --git a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java index 73d37cca56c..0c3bf91a4a2 100644 --- a/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java +++ b/engine/src/main/java/org/terasology/engine/core/modes/StateIngame.java @@ -112,6 +112,7 @@ public void dispose(boolean shuttingDown) { chunkProvider.dispose(); AssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class); + // dispose all module assets assetTypeManager.getAssetTypes().forEach(assetType -> { for (ResourceUrn urn : assetType.getLoadedAssetUrns()) { if (!urn.getModuleName().equals(TerasologyConstants.ENGINE_MODULE)) {