Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e2fc0ad
feat: expirmental work for gestalt-DI
pollend Feb 28, 2021
ea7a02b
tweak implementation
pollend Mar 1, 2021
735bd6a
start basic implementation for SolGame
pollend Mar 1, 2021
3729443
fix(DI): resolve Circular reference between `OggSoundManager` and `So…
DarkWeird Mar 2, 2021
c38a3c9
fix(DI): inject `DisplayDimensions` in some classes. main menu works.
DarkWeird Mar 3, 2021
fde7aa9
fix(DI): fix running game.
DarkWeird Mar 3, 2021
fcef6ae
refactor(DI): move Game services to `SolGameServiceRegistry`
DarkWeird Mar 4, 2021
818c5c6
fix(DI): fix game savings. Make `SerialisationManager` as normal serv…
DarkWeird Mar 4, 2021
50cf9c9
fix(DI): Minor fix resolving deps for `SerialisationManager`
DarkWeird Mar 4, 2021
65c694d
fix(DI): Remove unused store
DarkWeird Mar 4, 2021
e36b67b
remove intrpsection since beandefintioins are now driven by the prese…
pollend Mar 13, 2021
53f47bf
Merge remote-tracking branch 'origin/develop' into feat/experimental-…
pollend Mar 14, 2021
217003a
fix(DI): Integrate `gestalt-di` with `gestalt-module` and removes `Re…
DarkWeird Mar 19, 2021
fd12eac
fix(DI): update tests for working with `gestalt-di`
DarkWeird Mar 19, 2021
d68ddf7
fix(DI): fix tests with events
DarkWeird Mar 19, 2021
b44b963
Merge remote-tracking branch 'origin/develop' into feat/experimental-…
pollend Apr 26, 2021
6e7c60c
update gestalt version
pollend Apr 26, 2021
fdefafb
Merge branch 'develop' into feat/experimental-DI-gestalt
pollend Apr 26, 2021
6e9f56a
update with 3d1 snapshot
pollend May 22, 2021
5672d6c
update packages
pollend May 23, 2021
935766e
update for 4.0.0 snapshot
pollend Jun 17, 2021
1164f5e
Added FacadeModuleConfig for Android compatibility.
BenjaminAmos Jul 6, 2021
fa44ec2
fix: add missing indexing attributes to types
BenjaminAmos Jul 6, 2021
435b5eb
fix: fix tutorial from not running
BenjaminAmos Jul 6, 2021
157ff97
Merge branch 'develop' of github.com:MovingBlocks/DestinationSol into…
pollend Aug 4, 2021
ca9eb18
chore: remove mavenLocal()
pollend Aug 4, 2021
57a5e50
bugfix: resolve tutorialManager
pollend Aug 4, 2021
7b36517
Merge branch 'feat/experimental-DI-gestalt' into di-android-fixes
pollend Aug 5, 2021
efc7df6
Merge pull request #599 from BenjaminAmos/di-android-fixes
pollend Aug 5, 2021
2f3325b
chore: fix compiling errors
pollend Aug 5, 2021
76db920
bugfix: remove duplicate registration for TutorialManager
pollend Aug 5, 2021
595f73b
chore: fix Component
pollend Sep 12, 2021
dd1921e
chore: merged in changes from master
pollend Oct 1, 2021
5fe068c
Merge branch 'develop' of github.com:MovingBlocks/DestinationSol into…
pollend Nov 8, 2021
44cc049
resolve build problems with service registry
pollend Nov 20, 2021
9e013e8
test: fix RubbleTest race condition
BenjaminAmos Nov 22, 2021
a22b061
chore: address changes
pollend Nov 23, 2021
4181b09
fix(android): fix the game running on Android
BenjaminAmos Nov 25, 2021
46a8738
Merge pull request #640 from MovingBlocks/android/gestalt-di-fix-android
pollend Nov 27, 2021
eea3ef6
chore: implement workaround for preBegin
pollend Nov 27, 2021
9990d4e
chore: resolve preBegin
pollend Nov 27, 2021
e524ce2
Merge remote-tracking branch 'origin/develop' into feat/experimental-…
DarkWeird Apr 6, 2022
5a2416c
fix(di): restore playable state for desktop
DarkWeird Apr 26, 2022
cbbf328
chore: remove mavenLocal and empty lines
DarkWeird Apr 27, 2022
ecc3f19
fix: fix engine tests compilation
BenjaminAmos Apr 28, 2022
008d74c
fix: add ECS `EventReceiver` injection and fix associated tests
BenjaminAmos May 9, 2022
660fa7b
feature: make FocusManager as Injectable service and inject it in Nui.
DarkWeird May 24, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ engine/src/main/resources/entity_store.dat

# Ignore donwloaded JREs
jre/**
engine/src/main/generated/
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ allprojects {
// See https://github.com/libgdx/gdx-controllers/wiki/Compatibility for compatible versions.
gdxControllersVersion = '2.1.0'
roboVMVersion = '2.3.3'
nuiVersion = '3.1.0'
gestaltVersion = '8.0.0-SNAPSHOT'
nuiVersion = '4.0.0-SNAPSHOT'
}
}

repositories {
mavenLocal()

// Good ole Maven central
mavenCentral()
Expand Down
3 changes: 1 addition & 2 deletions config/gradle/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenLocal()

// Good ole Maven central
mavenCentral()
Expand Down Expand Up @@ -110,4 +109,4 @@ tasks.withType(Pmd) {
// Make sure our config file for code analytics get extracted (vulnerability: non-IDE execution of single analytic)
ideaModule.dependsOn rootProject.extractConfig
tasks.eclipse.dependsOn rootProject.extractConfig
check.dependsOn rootProject.extractConfig
check.dependsOn rootProject.extractConfig
65 changes: 44 additions & 21 deletions desktop/src/main/java/org/destinationsol/desktop/SolDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,29 @@
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics;
import org.destinationsol.GameOptions;
import org.destinationsol.modules.FacadeModuleConfig;
import org.destinationsol.modules.ModuleManager;
import org.destinationsol.SolApplication;
import org.destinationsol.SolFileReader;
import org.destinationsol.game.DebugOptions;
import org.destinationsol.ui.ResizeSubscriber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.context.Lifetime;
import org.terasology.crashreporter.CrashReporter;
import org.terasology.gestalt.di.ServiceRegistry;
import org.terasology.gestalt.module.Module;
import org.terasology.gestalt.module.ModuleEnvironment;
import org.terasology.gestalt.module.ModuleFactory;
import org.terasology.gestalt.module.ModulePathScanner;
import org.terasology.gestalt.module.sandbox.JavaModuleClassLoader;

import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.SplashScreen;
import java.awt.Rectangle;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
Expand All @@ -57,8 +66,6 @@
public final class SolDesktop {

private static Logger logger = LoggerFactory.getLogger(SolDesktop.class);
private static boolean initFinished;
private static ModuleManager moduleManager;

/**
* Specifies the commandline option to pass to the application for it to generate no crash reports.
Expand Down Expand Up @@ -119,31 +126,13 @@ public static void main(String[] argv) {
}

handleCrashReporting(argv);
new Thread(new Runnable() {
@Override
public void run() {
try {
moduleManager = new ModuleManager();
moduleManager.init();
} catch (Exception ignore) {
}
initFinished = true;
}
}).start();

while (!initFinished) {
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
}

if (useSplash) {
splash.close();
}
// Everything is set up correctly, launch the application
SolApplication application = new SolApplication(moduleManager, 100);
SolApplication application = new SolApplication(100, new DesktopServices());
SolApplication.addResizeSubscriber(new SolDesktop.FullScreenWindowPositionAdjustment(!options.fullscreen));
// Everything is set up correctly, launch the application
new Lwjgl3Application(application, applicationConfig);
Expand Down Expand Up @@ -231,6 +220,40 @@ private static void setScreenDimensions(Lwjgl3ApplicationConfiguration applicati
}
}

private static class DesktopServices extends ServiceRegistry {
public DesktopServices() {
this.with(FacadeModuleConfig.class).lifetime(Lifetime.Singleton).use(DesktopModuleConfig::new);
this.with(ModulePathScanner.class).lifetime(Lifetime.Singleton);
}
}

private static class DesktopModuleConfig implements FacadeModuleConfig {
@Override
public File getModulesPath() {
return Paths.get(".").resolve("modules").toFile();
}

@Override
public boolean useSecurityManager() {
return true;
}

@Override
public ModuleEnvironment.ClassLoaderSupplier getClassLoaderSupplier() {
return JavaModuleClassLoader::create;
}

@Override
public Module createEngineModule() {
return new ModuleFactory().createPackageModule("org.destinationsol");
}

@Override
public Class<?>[] getAPIClasses() {
return new Class<?>[0];
}
}

/**
* Provides the implementation of SolFileReader used by this class.
*/
Expand Down
68 changes: 25 additions & 43 deletions engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,46 @@ apply from: '../config/gradle/common.gradle'
apply plugin: 'java-library'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.scanners.TypeAnnotationsScanner;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.ClasspathHelper;

// Dependencies needed for what our Gradle scripts themselves use. It cannot be included via an external Gradle file :-(
buildscript {
repositories {
mavenCentral()

// HACK: Needed for NUI and gestalt entity-component reflections
mavenLocal()
google()
maven { url "http://artifactory.terasology.org/artifactory/virtual-repo-live" }
// Needed for Jsemver, which is a gestalt dependency
maven { url = 'https://heisluft.de/maven/' }
}

dependencies {
// Needed for caching reflected data during builds
classpath 'org.reflections:reflections:0.9.12'
classpath 'dom4j:dom4j:1.6.1'

// HACK: Needed for NUI and gestalt entity-component reflections
classpath group: 'org.terasology.nui', name: 'nui', version: nuiVersion
classpath group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
classpath group: 'org.terasology.gestalt', name: 'gestalt-entity-system', version: '7.2.0-SNAPSHOT'
}
}

dependencies {
api group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
api group: 'com.google.code.gson', name: 'gson', version: '2.6.2'
api group: 'com.google.guava', name: 'guava', version: '30.1-jre'

api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
api "com.badlogicgames.gdx-controllers:gdx-controllers-core:$gdxControllersVersion"

api(group: 'org.terasology.gestalt', name: 'gestalt-asset-core', version: '7.2.0-SNAPSHOT')
api(group: 'org.terasology.gestalt', name: 'gestalt-entity-system', version: '7.2.0-SNAPSHOT')
api(group: 'org.terasology.gestalt', name: 'gestalt-module', version: '7.2.0-SNAPSHOT')
api(group: 'org.terasology.gestalt', name: 'gestalt-util', version: '7.2.0-SNAPSHOT')
api "org.terasology.gestalt:gestalt-asset-core:$gestaltVersion"
api "org.terasology.gestalt:gestalt-entity-system:$gestaltVersion"
api "org.terasology.gestalt:gestalt-module:$gestaltVersion"
api "org.terasology.gestalt:gestalt-util:$gestaltVersion"

api "org.terasology.gestalt:gestalt-di:$gestaltVersion"
api "org.terasology.gestalt:gestalt-inject:$gestaltVersion"
annotationProcessor "org.terasology.gestalt:gestalt-inject-java:$gestaltVersion"

implementation "net.jcip:jcip-annotations:1.0"

api group: 'org.terasology.nui', name: 'nui', version: nuiVersion
api group: 'org.terasology.nui', name: 'nui-libgdx', version: nuiVersion
api group: 'org.terasology.nui', name: 'nui-gestalt7', version: nuiVersion
api "org.terasology.nui:nui:$nuiVersion"
api "org.terasology.nui:nui-libgdx:$nuiVersion"
api "org.terasology.nui:nui-gestalt:$nuiVersion"
api "org.terasology.nui:nui-reflect:$nuiVersion"

implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.4.0'

Expand All @@ -73,30 +66,19 @@ dependencies {
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.9.0'
}

task cacheReflections {
description = 'Caches reflection output to make regular startup faster. May go stale and need cleanup at times.'
inputs.files sourceSets.main.output.classesDirs,
// getClassesDir from all sourceSets (for any jvm (seems) language)
configurations."${sourceSets.main.runtimeClasspathConfigurationName}"

outputs.upToDateWhen {classes.state.upToDate}
outputs.file("$buildDir/resources/main/org/destinationsol/reflections.cache")
dependsOn classes

doLast {
// Without the .mkdirs() we might hit a scenario where the classes dir doesn't exist yet
Reflections reflections = new Reflections(new ConfigurationBuilder()
.addUrls(inputs.files.collect { it.toURI().toURL() })
.filterInputsBy({ it.startsWith("org.destinationsol") || it.startsWith("org.terasology.nui") })
.setScanners(new TypeAnnotationsScanner(), new SubTypesScanner()))
reflections.save("$buildDir/resources/main/org/destinationsol/reflections.cache")
}
// Adds Resources as parameter for AnnotationProcessor (gather ResourceIndex,
// also add resource as input for compilejava, for re-gathering ResourceIndex, when resource was changed.
compileJava {
inputs.files sourceSets.main.resources.srcDirs
options.compilerArgs = ["-Aresource=${sourceSets.main.resources.srcDirs.join(File.pathSeparator)}"]
}
compileTestJava {
inputs.files sourceSets.test.resources.srcDirs
options.compilerArgs = ["-Aresource=${sourceSets.test.resources.srcDirs.join(File.pathSeparator)}"]
}

jar {
// This prevents the assets from being scanned as code files
dependsOn cacheReflections

jar {
archiveName = "sol.jar"

doFirst {
Expand Down
20 changes: 20 additions & 0 deletions engine/src/main/java/org/destinationsol/BeanClassFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.destinationsol;

import org.terasology.gestalt.di.BeanContext;
import org.terasology.gestalt.util.reflection.ClassFactory;

import javax.inject.Provider;
import java.util.Optional;

public class BeanClassFactory implements ClassFactory {
private final Provider<BeanContext> beanContext;

public BeanClassFactory(Provider<BeanContext> beanContext) {
this.beanContext = beanContext;
}

@Override
public <T> Optional<T> instantiateClass(Class<? extends T> type) {
return (Optional<T>) beanContext.get().findBean(type);
}
}
7 changes: 5 additions & 2 deletions engine/src/main/java/org/destinationsol/CommonDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.destinationsol.ui.ResizeSubscriber;
import org.destinationsol.ui.UiDrawer;

import javax.inject.Inject;

public class CommonDrawer implements ResizeSubscriber {
private final SpriteBatch spriteBatch;
private final BitmapFont font;
Expand All @@ -44,8 +46,9 @@ public class CommonDrawer implements ResizeSubscriber {

private DisplayDimensions displayDimensions;

CommonDrawer() {
displayDimensions = SolApplication.displayDimensions;
@Inject
CommonDrawer(DisplayDimensions displayDimensions) {
this.displayDimensions = displayDimensions;

spriteBatch = new SpriteBatch();

Expand Down
56 changes: 56 additions & 0 deletions engine/src/main/java/org/destinationsol/ContextWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2021 The Terasology Foundation
*
* 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.
*/
package org.destinationsol;

import org.destinationsol.game.context.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.gestalt.di.BeanContext;
import org.terasology.gestalt.di.exceptions.BeanResolutionException;

import javax.inject.Inject;

@Deprecated
public class ContextWrapper implements Context {

private static final Logger logger = LoggerFactory.getLogger(ContextWrapper.class);
protected BeanContext context;

@Inject
public ContextWrapper(BeanContext beanContext) {
this.context = beanContext;
}

@Override
public <T> T get(Class<? extends T> type) {
try {
return (T) context.getBean(type);
} catch (BeanResolutionException e){
logger.warn("Bean [{}] not found",type);
return null;
}
}

@Override
public <T, U extends T> void put(Class<T> type, U object) {
throw new RuntimeException("Cannot insert values into wrapped context: please use the BeanContext directly");
}

@Override
public <T, U extends T> void remove(Class<T> type, U object) {
throw new RuntimeException("Cannot insert values into wrapped context: please use the BeanContext directly");
}
}
27 changes: 27 additions & 0 deletions engine/src/main/java/org/destinationsol/ContextWrapperService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2020 The Terasology Foundation
*
* 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.
*/
package org.destinationsol;


import org.destinationsol.game.context.Context;
import org.terasology.context.Lifetime;
import org.terasology.gestalt.di.ServiceRegistry;

public class ContextWrapperService extends ServiceRegistry {
public ContextWrapperService() {
this.with(Context.class).use(ContextWrapper.class).lifetime(Lifetime.Singleton);
}
}
Loading