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

feature: migrate to gestaltv7 #4593

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e55b7f0
feature: migrate to gestaltv7
pollend Mar 21, 2021
f9ce52f
bugfix: correct copy strategy
pollend Mar 28, 2021
46c29ee
chore: remove copy strategy
pollend Mar 28, 2021
5504449
fix formatting
pollend Mar 28, 2021
9afe704
refactor(handleSwitchToGameEnvironment): these are all one copy strategy
keturn Apr 1, 2021
850ee40
build: no dependency on gestalt-entity-system yet
keturn Apr 1, 2021
911110a
Merge branch 'nui-gestalt-separation' into feature/migrate-gestalt-v7
keturn Apr 2, 2021
d9af0ba
chore(ComponentSystem): debugging logs
keturn Apr 2, 2021
0a175af
chore(UISkinWithUrn): update for gestalt 7
keturn Apr 2, 2021
8e26159
chore: revert move of jmh sources
keturn Apr 2, 2021
7b1bd17
fixup! chore: revert move of jmh sources
keturn Apr 2, 2021
cba8ef5
core(EntitySystemSetup): null checking
keturn Apr 2, 2021
3986c4d
refactor(ModuleManager): restore some organization from the develop b…
keturn Apr 2, 2021
b874418
test: reduce duplicate exception logs and wrapping
keturn Apr 2, 2021
bfb1a8e
test: add mockito-inline to empower mockito to do more invasive things
keturn Apr 2, 2021
6412aab
test(ModuleEnvironmentTest): assert, don't `assume`!
keturn Apr 2, 2021
a7e2fb3
test(TerasologyTestingEnvironment): avoid NPE on tearDown (the result…
keturn Apr 2, 2021
f3711c3
test(InputSystemTest): do not always include TestEventButton in the r…
keturn Apr 2, 2021
442d2fd
feat(ModuleManager): add method for creating an environment with reso…
keturn Apr 2, 2021
31715d2
test(BindsSubsystemTest): update for gestalt-v7
keturn Apr 2, 2021
1c48c86
test(TypeSerializerTest): lint
keturn Apr 2, 2021
42ffb8e
chore: bump version to 4.4.1-SNAPSHOT
keturn Apr 2, 2021
2f9d4af
Merge remote-tracking branch 'origin/nui-gestalt-separation' into fea…
keturn Apr 2, 2021
20546f1
fix(ModuleManager): loosen auto-generated dependency version
keturn Apr 2, 2021
c69a87f
feature: migrate gestalt v7 discord subsystem (#4613)
pollend Apr 4, 2021
d8de0d3
Merge remote-tracking branch 'origin/develop' into feature/migrate-ge…
pollend Apr 4, 2021
3c5ff6e
bugfix: correct newGameScreen
pollend Apr 4, 2021
873dec8
move discord to engine namespace
pollend Apr 4, 2021
ccec83d
Merge branch 'develop' into feature/migrate-gestalt-v7
pollend Apr 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 7 additions & 3 deletions build-logic/src/main/kotlin/terasology-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.gradle.plugins.ide.idea.model.IdeaModel
import org.reflections.Reflections
import org.reflections.scanners.SubTypesScanner
import org.reflections.scanners.TypeAnnotationsScanner
import org.reflections.serializers.JsonSerializer
import org.reflections.util.ConfigurationBuilder
import org.reflections.util.FilterBuilder
import org.terasology.gradology.ModuleMetadataForGradle
Expand Down Expand Up @@ -124,7 +125,7 @@ val mainSourceSet: SourceSet = sourceSets[SourceSet.MAIN_SOURCE_SET_NAME]
tasks.register("cacheReflections") {
description = "Caches reflection output to make regular startup faster. May go stale and need cleanup at times."
inputs.files(mainSourceSet.output.classesDirs)
outputs.file(File(mainSourceSet.output.classesDirs.first(), "reflections.cache"))
outputs.file(File(mainSourceSet.output.classesDirs.first(), "manifest.json"))
dependsOn(tasks.named("classes"))

outputs.upToDateWhen { tasks.named("classes").get().state.upToDate }
Expand All @@ -135,7 +136,7 @@ tasks.register("cacheReflections") {
.filterInputsBy(FilterBuilder.parsePackages("+org"))
.addUrls(inputs.getFiles().getSingleFile().toURI().toURL())
.setScanners(TypeAnnotationsScanner(), SubTypesScanner()))
reflections.save(outputs.getFiles().getAsPath())
reflections.save(outputs.getFiles().getAsPath(), JsonSerializer())
} catch (e: java.net.MalformedURLException) {
logger.error("Cannot parse input to url", e)
}
Expand Down Expand Up @@ -163,6 +164,10 @@ tasks.register<Sync>("syncDeltas") {
into("${mainSourceSet.output.classesDirs.first()}/deltas")
}

tasks.named("compileJava") {
finalizedBy("cacheReflections")
}

// Instructions for packaging a jar file - is a manifest even needed for modules?
tasks.named("jar") {
// Make sure the assets directory is included
Expand All @@ -179,7 +184,6 @@ tasks.named("jar") {
}
}

finalizedBy("cleanReflections")
}

tasks.named<Test>("test") {
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ buildscript {
// External libs - jcenter is Bintray and is supposed to be a superset of Maven Central, but do both just in case
jcenter()
mavenCentral()
google()
gradlePluginPortal()

maven {
Expand Down Expand Up @@ -78,6 +79,7 @@ repositories {
// External libs - jcenter is Bintray and is supposed to be a superset of Maven Central, but do both just in case
jcenter()
mavenCentral()
google()

// MovingBlocks Artifactory instance for libs not readily available elsewhere plus our own libs
maven {
Expand Down
8 changes: 7 additions & 1 deletion engine-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ext {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Read the internal version out of the engine-tests module.txt
def moduleFile = file('src/main/resources/module.txt')
def moduleFile = file('src/main/resources/org/terasology/unittest/module.txt')

if (!moduleFile.exists()) {
println "Failed to find module.txt for engine-tests"
Expand All @@ -48,6 +48,11 @@ sourceSets {
test.java.outputDir = new File("$buildDir/testClasses")
}

// umm need for android dependencies
repositories {
google()
}

// Primary dependencies definition
dependencies {
// Dependency on the engine itself
Expand All @@ -68,6 +73,7 @@ dependencies {
implementation("org.junit.jupiter:junit-jupiter-api")
implementation("org.junit.jupiter:junit-jupiter-params")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation("org.mockito:mockito-inline:3.7.7")

implementation("org.mockito:mockito-junit-jupiter:3.7.7")

Expand Down
32 changes: 11 additions & 21 deletions engine-tests/src/main/java/org/terasology/engine/Environment.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License"){ }
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.engine;

import com.badlogic.gdx.physics.bullet.Bullet;
import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.assets.management.AssetManager;
import org.terasology.engine.context.Context;
import org.terasology.engine.context.internal.ContextImpl;
import org.terasology.engine.core.paths.PathManager;
import org.terasology.engine.recording.RecordAndReplayCurrentStatus;
import org.terasology.engine.registry.CoreRegistry;
import org.terasology.naming.Name;
import org.terasology.gestalt.assets.management.AssetManager;
import org.terasology.gestalt.naming.Name;

import java.io.IOException;
import java.util.Set;
Expand All @@ -50,8 +37,11 @@ public Environment(Name... moduleNames) {
try {
reset(Sets.newHashSet(moduleNames));
} catch (Exception e) {
logger.error("Error", e);
throw new RuntimeException(e);
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
}
}

Expand All @@ -76,7 +66,7 @@ protected void reset(Set<Name> moduleNames) throws Exception {
AssetManager assetManager = setupAssetManager();

setupBlockManager(assetManager);

setupExtraDataManager(context);

setupCollisionManager();
Expand Down Expand Up @@ -137,7 +127,7 @@ protected AssetManager setupEmptyAssetManager() {
protected void setupBlockManager(AssetManager assetManager) {
// empty
}

protected void setupExtraDataManager(Context context) {
// empty
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.assets.management.AssetManager;
import org.terasology.assets.module.ModuleAwareAssetTypeManager;
import org.terasology.engine.audio.AudioManager;
import org.terasology.engine.audio.StaticSound;
import org.terasology.engine.audio.StreamingSound;
Expand Down Expand Up @@ -54,6 +52,7 @@
import org.terasology.engine.rendering.assets.skeletalmesh.SkeletalMesh;
import org.terasology.engine.rendering.assets.texture.PNGTextureFormat;
import org.terasology.engine.rendering.assets.texture.Texture;
import org.terasology.engine.rendering.assets.texture.TextureData;
import org.terasology.engine.rendering.assets.texture.subtexture.Subtexture;
import org.terasology.engine.testUtil.ModuleManagerFactory;
import org.terasology.engine.world.WorldProvider;
Expand All @@ -63,6 +62,7 @@
import org.terasology.engine.world.block.family.BlockFamilyLibrary;
import org.terasology.engine.world.block.internal.BlockManagerImpl;
import org.terasology.engine.world.block.loader.BlockFamilyDefinition;
import org.terasology.engine.world.block.loader.BlockFamilyDefinitionData;
import org.terasology.engine.world.block.loader.BlockFamilyDefinitionFormat;
import org.terasology.engine.world.block.shapes.BlockShape;
import org.terasology.engine.world.block.shapes.BlockShapeImpl;
Expand All @@ -77,11 +77,12 @@
import org.terasology.engine.world.sun.DefaultCelestialSystem;
import org.terasology.engine.world.time.WorldTime;
import org.terasology.engine.world.time.WorldTimeImpl;
import org.terasology.module.DependencyResolver;
import org.terasology.module.ModuleEnvironment;
import org.terasology.module.ModuleRegistry;
import org.terasology.module.ResolutionResult;
import org.terasology.naming.Name;
import org.terasology.gestalt.assets.AssetType;
import org.terasology.gestalt.assets.management.AssetManager;
import org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager;
import org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManagerImpl;
import org.terasology.gestalt.module.ModuleEnvironment;
import org.terasology.gestalt.naming.Name;
import org.terasology.nui.asset.UIElement;
import org.terasology.nui.skin.UISkinAsset;
import org.terasology.persistence.typeHandling.TypeHandlerLibrary;
Expand Down Expand Up @@ -128,7 +129,7 @@ protected void setupStorageManager() throws IOException {

ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
context.put(BlockFamilyLibrary.class, new BlockFamilyLibrary(environment,context));

ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);

context.put(StorageManager.class, new ReadWriteStorageManager(savePath, moduleManager.getEnvironment(),
Expand Down Expand Up @@ -164,15 +165,15 @@ protected void setupBlockManager(AssetManager assetManager) {
typeHandlerLibrary.addTypeHandler(BlockFamily.class, new BlockFamilyTypeHandler(blockManager));
typeHandlerLibrary.addTypeHandler(Block.class, new BlockTypeHandler(blockManager));
}

@Override
protected void setupExtraDataManager(Context context) {
context.put(ExtraBlockDataManager.class, new ExtraBlockDataManager(context));
}

@Override
protected AssetManager setupEmptyAssetManager() {
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();
assetTypeManager.switchEnvironment(context.get(ModuleManager.class).getEnvironment());

context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
Expand All @@ -182,54 +183,59 @@ protected AssetManager setupEmptyAssetManager() {

@Override
protected AssetManager setupAssetManager() {
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManagerImpl();

// cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
assetTypeManager.registerCoreAssetType(Prefab.class,
PojoPrefab::new, false, "prefabs");
assetTypeManager.registerCoreAssetType(BlockShape.class,
assetTypeManager.createAssetType(Prefab.class,
PojoPrefab::new, "prefabs");
assetTypeManager.createAssetType(BlockShape.class,
BlockShapeImpl::new, "shapes");
assetTypeManager.registerCoreAssetType(BlockSounds.class,
assetTypeManager.createAssetType(BlockSounds.class,
BlockSounds::new, "blockSounds");
assetTypeManager.registerCoreAssetType(BlockTile.class,
assetTypeManager.createAssetType(BlockTile.class,
BlockTile::new, "blockTiles");
assetTypeManager.registerCoreAssetType(BlockFamilyDefinition.class,
BlockFamilyDefinition::new, "blocks");
AssetType<BlockFamilyDefinition, BlockFamilyDefinitionData> blockFamilyDefinitionDataAssetType =
assetTypeManager.createAssetType(BlockFamilyDefinition.class,
BlockFamilyDefinition::new, "blocks");

assetTypeManager.registerCoreAssetType(StaticSound.class, NullSound::new, "sounds");
assetTypeManager.registerCoreAssetType(StreamingSound.class, NullStreamingSound::new, "music");

assetTypeManager.registerCoreFormat(BlockFamilyDefinition.class,
assetTypeManager.getAssetFileDataProducer(blockFamilyDefinitionDataAssetType).addAssetFormat(
new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager()));

assetTypeManager.registerCoreAssetType(UISkinAsset.class,
assetTypeManager.createAssetType(StaticSound.class, NullSound::new, "sounds");
assetTypeManager.createAssetType(StreamingSound.class, NullStreamingSound::new, "music");

assetTypeManager.createAssetType(UISkinAsset.class,
UISkinAsset::new, "skins");
assetTypeManager.registerCoreAssetType(BehaviorTree.class,
BehaviorTree::new, false, "behaviors");
assetTypeManager.registerCoreAssetType(UIElement.class,
assetTypeManager.createAssetType(BehaviorTree.class,
BehaviorTree::new, "behaviors");
assetTypeManager.createAssetType(UIElement.class,
UIElement::new, "ui");
assetTypeManager.registerCoreAssetType(Font.class,
assetTypeManager.createAssetType(Font.class,
FontImpl::new, "fonts");
assetTypeManager.registerCoreAssetType(Texture.class,
HeadlessTexture::new, "textures", "fonts");
assetTypeManager.registerCoreFormat(Texture.class,
new PNGTextureFormat(Texture.FilterMode.NEAREST, path -> path.getName(2).toString().equals("textures")));
assetTypeManager.registerCoreFormat(Texture.class,
new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> path.getName(2).toString().equals("fonts")));

assetTypeManager.registerCoreAssetType(Shader.class,
AssetType<Texture, TextureData> textureDataAssetType = assetTypeManager.createAssetType(Texture.class,
HeadlessTexture::create, "textures", "fonts");
assetTypeManager.getAssetFileDataProducer(textureDataAssetType).addAssetFormat(
new PNGTextureFormat(Texture.FilterMode.NEAREST,
path -> path.getPath().get(1).equals("textures")));
assetTypeManager.getAssetFileDataProducer(textureDataAssetType).addAssetFormat(
new PNGTextureFormat(Texture.FilterMode.LINEAR, path -> path.getPath().get(1).equals("fonts")));

assetTypeManager.createAssetType(Shader.class,
HeadlessShader::new, "shaders");
assetTypeManager.registerCoreAssetType(Material.class,
assetTypeManager.createAssetType(Material.class,
HeadlessMaterial::new, "materials");
assetTypeManager.registerCoreAssetType(Mesh.class,
assetTypeManager.createAssetType(Mesh.class,
HeadlessMesh::new, "mesh");
assetTypeManager.registerCoreAssetType(SkeletalMesh.class,
assetTypeManager.createAssetType(SkeletalMesh.class,
HeadlessSkeletalMesh::new, "skeletalMesh");
assetTypeManager.registerCoreAssetType(MeshAnimation.class, MeshAnimationImpl::new, "animations");
assetTypeManager.createAssetType(MeshAnimation.class,
MeshAnimationImpl::new, "animations");

assetTypeManager.registerCoreAssetType(Atlas.class,
assetTypeManager.createAssetType(Atlas.class,
Atlas::new, "atlas");
assetTypeManager.registerCoreAssetType(Subtexture.class, Subtexture::new);
assetTypeManager.createAssetType(Subtexture.class,
Subtexture::new);

assetTypeManager.switchEnvironment(context.get(ModuleManager.class).getEnvironment());

Expand All @@ -253,24 +259,15 @@ protected void setupConfig() {

@Override
protected void setupModuleManager(Set<Name> moduleNames) throws Exception {
ModuleTypeRegistry typeRegistry = new ModuleTypeRegistry();
TypeRegistry.WHITELISTED_CLASSES = ExternalApiWhitelist.CLASSES.stream().map(Class::getName).collect(Collectors.toSet());
context.put(TypeRegistry.class, typeRegistry);
context.put(ModuleTypeRegistry.class, typeRegistry);

ModuleManager moduleManager = ModuleManagerFactory.create(true);
ModuleRegistry registry = moduleManager.getRegistry();
ModuleManager moduleManager = ModuleManagerFactory.create();
ModuleTypeRegistry typeRegistry = new ModuleTypeRegistry(moduleManager.getEnvironment());

DependencyResolver resolver = new DependencyResolver(registry);
ResolutionResult result = resolver.resolve(moduleNames);
context.put(TypeRegistry.class, typeRegistry);
context.put(ModuleTypeRegistry.class, typeRegistry);

if (result.isSuccess()) {
ModuleEnvironment modEnv = moduleManager.loadEnvironment(result.getModules(), true);
typeRegistry.reload(modEnv);
logger.debug("Loaded modules: " + modEnv.getModuleIdsOrderedByDependencies());
} else {
logger.error("Could not resolve module dependencies for " + moduleNames);
}
moduleManager.resolveAndLoadEnvironment(moduleNames);

context.put(ModuleManager.class, moduleManager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import org.junit.jupiter.api.io.TempDir;
import org.terasology.engine.core.module.ModuleManager;
import org.terasology.engine.core.paths.PathManager;
import org.terasology.module.DependencyResolver;
import org.terasology.module.ModuleEnvironment;
import org.terasology.module.ResolutionResult;
import org.terasology.reflection.ModuleTypeRegistry;
import org.terasology.engine.testUtil.ModuleManagerFactory;
import org.terasology.gestalt.module.ModuleEnvironment;
import org.terasology.gestalt.module.dependencyresolution.DependencyResolver;
import org.terasology.gestalt.module.dependencyresolution.ResolutionResult;
import org.terasology.reflection.ModuleTypeRegistry;

import java.nio.file.Path;

import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

public abstract class ModuleEnvironmentTest {
protected ModuleManager moduleManager;
Expand All @@ -29,7 +29,7 @@ public void before(@TempDir Path tempHome) throws Exception {
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(moduleManager.getRegistry().getModuleIds());

assumeTrue(result.isSuccess());
assertTrue(result.isSuccess());

ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), true);
typeRegistry = new ModuleTypeRegistry(environment);
Expand Down
Loading