Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public boolean step() {
WorldInfo worldInfo = verifyNotNull(gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD),
"Game manifest does not contain a MAIN_WORLD");
verify(worldInfo.getWorldGenerator().isValid(), "Game manifest did not specify world type.");
// Seed is carried by the GameManifest from the UI (GameManifestProvider).
// Generate a random fallback if the manifest doesn't specify one.
if (worldInfo.getSeed() == null || worldInfo.getSeed().isEmpty()) {
FastRandom random = new FastRandom();
worldInfo.setSeed(random.nextString(16));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

//TODO document this!

Check warning on line 37 in engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/JoinServer.java

View check run for this annotation

Terasology Jenkins.io / Open Tasks Scanner

TODO

NORMAL: document this!
public class JoinServer extends VariableStepLoadProcess {
private static final Logger logger = LoggerFactory.getLogger(JoinServer.class);

Expand All @@ -41,7 +43,7 @@
private GameManifest gameManifest;
private JoinStatus joinStatus;

private Thread applyModuleThread;
private FutureTask<Context> applyModuleTask;
private ModuleEnvironment oldEnvironment;

public JoinServer(Context context, GameManifest gameManifest, JoinStatus joinStatus) {
Expand All @@ -53,7 +55,7 @@

@Override
public String getMessage() {
if (applyModuleThread != null) {
if (applyModuleTask != null) {
return "${engine:menu#scanning-for-assets}";
} else {
return joinStatus.getCurrentActivity();
Expand All @@ -62,8 +64,21 @@

@Override
public boolean step() {
if (applyModuleThread != null) {
if (!applyModuleThread.isAlive()) {
if (applyModuleTask != null) {
if (applyModuleTask.isDone()) {
try {
Context gameContext = applyModuleTask.get();
CoreRegistry.setContext(gameContext);
} catch (ExecutionException e) {
logger.error("Failed to apply game environment", e.getCause());

Check warning on line 73 in engine/src/main/java/org/terasology/engine/core/modes/loadProcesses/JoinServer.java

View check run for this annotation

Terasology Jenkins.io / PMD

GuardLogStatementJavaUtil

HIGH: Logger calls should be surrounded by log level guards.
StateMainMenu mainMenu = new StateMainMenu("Failed to apply game environment: " + e.getCause().getMessage());
context.get(GameEngine.class).changeState(mainMenu);
networkSystem.shutdown();
return true;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
if (oldEnvironment != null) {
oldEnvironment.close();
}
Expand Down Expand Up @@ -120,15 +135,17 @@
context.get(Game.class).load(gameManifest);

EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
ContextImpl modulesContext = new ContextImpl(context,
moduleManager.getEnvironment().getBeans(BeanContext.class).stream().findFirst().get());
BeanContext moduleBeanContext = moduleManager.getEnvironment().getBeans(BeanContext.class).stream()
.findFirst()
.orElseThrow(() -> new IllegalStateException(
"Loaded module environment did not expose a BeanContext"));
ContextImpl modulesContext = new ContextImpl(context, moduleBeanContext);
ServiceRegistry gameContextRegistry = new ServiceRegistry();
applyModuleThread = new Thread(() -> {
applyModuleTask = new FutureTask<>(() -> {
environmentSwitchHandler.handleSwitchToGameEnvironment(modulesContext, gameContextRegistry);
Context gameContext = new ContextImpl(modulesContext, gameContextRegistry);
CoreRegistry.setContext(gameContext);
return new ContextImpl(modulesContext, gameContextRegistry);
});
applyModuleThread.start();
new Thread(applyModuleTask, "apply-module-environment").start();

return false;
} else if (joinStatus.getStatus() == JoinStatus.Status.FAILED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public final class ReadWriteStorageManager extends AbstractStorageManager
private final Game game;
private final BlockManager blockManager;

/**
* @deprecated Use the @Inject constructor instead. This constructor relies on CoreRegistry
* for implicit dependencies which conflicts with the DI migration.
*/
@Deprecated
public ReadWriteStorageManager(Path savePath, ModuleEnvironment environment, EngineEntityManager entityManager, BlockManager blockManager,
ExtraBlockDataManager extraDataManager, RecordAndReplaySerializer recordAndReplaySerializer,
RecordAndReplayUtils recordAndReplayUtils, RecordAndReplayCurrentStatus recordAndReplayCurrentStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.terasology.engine.context.Context;
import org.terasology.engine.context.internal.ContextImpl;
import org.terasology.engine.core.GameEngine;
import org.terasology.engine.registry.CoreRegistry;
import org.terasology.engine.core.modes.StateMainMenu;
import org.terasology.engine.core.module.ModuleManager;
import org.terasology.engine.core.module.rendering.RenderingModuleRegistry;
Expand Down Expand Up @@ -138,6 +139,13 @@ public void init() {
initRenderingSupport();
initRenderingModules();

// Make ScreenGrabber visible from the shared game context so that
// ReadWriteStorageManager.saveGamePreviewImage() can resolve it via CoreRegistry.
ScreenGrabber screenGrabber = context.get(ScreenGrabber.class);
if (screenGrabber != null) {
CoreRegistry.put(ScreenGrabber.class, screenGrabber);
}
Comment thread
agent-refr marked this conversation as resolved.
Outdated

console = context.get(Console.class);
MethodCommand.registerAvailable(this, console, context);
}
Expand Down
Loading