Skip to content

Commit

Permalink
Merge branch 'develop' into chore/split-ChunkMesh-into-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend committed Oct 3, 2021
2 parents 63dd02e + 3f2e51f commit 09b552a
Show file tree
Hide file tree
Showing 33 changed files with 441 additions and 112 deletions.
13 changes: 8 additions & 5 deletions build-logic/src/main/kotlin/terasology-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ dependencies {

testRuntimeOnly("org.slf4j:jul-to-slf4j:1.7.21")

add("testImplementation", platform("org.junit:junit-bom:5.7.1"))
add("testImplementation", platform("org.junit:junit-bom:5.8.1"))
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")

testImplementation("org.mockito:mockito-inline:3.11.2")
testImplementation("org.mockito:mockito-junit-jupiter:3.11.2")
testImplementation("org.mockito:mockito-inline:3.12.4")
testImplementation("org.mockito:mockito-junit-jupiter:3.12.4")

testImplementation("com.google.truth:truth:1.1.3")
testImplementation("com.google.truth.extensions:truth-java8-extension:1.1.3")
}


Expand All @@ -86,9 +89,9 @@ if (project.name == "ModuleTestingEnvironment") {
runtimeOnly("org.codehaus.janino:janino:3.1.3") {
because("logback filters")
}
add("implementation", platform("org.junit:junit-bom:5.7.1"))
add("implementation", platform("org.junit:junit-bom:5.8.1"))
implementation("org.junit.jupiter:junit-jupiter-api")
implementation("org.mockito:mockito-junit-jupiter:3.11.2")
implementation("org.mockito:mockito-junit-jupiter:3.12.4")
}
}

Expand Down
10 changes: 5 additions & 5 deletions engine-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ dependencies {
implementation "org.terasology:reflections:0.9.12-MB"

// Test lib dependencies
implementation(platform("org.junit:junit-bom:5.7.1")) {
implementation(platform("org.junit:junit-bom:5.8.1")) {
// junit-bom will set version numbers for the other org.junit 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.11.2")
testImplementation('org.mockito:mockito-inline:3.12.4')

implementation("org.mockito:mockito-junit-jupiter:3.11.2")
implementation('org.mockito:mockito-junit-jupiter:3.12.4')

implementation("org.terasology.joml-ext:joml-test:0.1.0")

testImplementation("com.google.truth:truth:1.1.2")
testImplementation("com.google.truth.extensions:truth-java8-extension:1.1.2")
testImplementation('com.google.truth:truth:1.1.3')
testImplementation('com.google.truth.extensions:truth-java8-extension:1.1.3')
}

task copyResourcesToClasses(type:Copy) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.engine.rendering.assets.mesh;

import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.junit.Test;
import org.terasology.engine.rendering.assets.mesh.resource.GLAttributes;
import org.terasology.engine.rendering.assets.mesh.resource.VertexAttributeBinding;
import org.terasology.engine.rendering.assets.mesh.resource.VertexFloatAttributeBinding;
import org.terasology.engine.rendering.assets.mesh.resource.VertexIntegerAttributeBinding;
import org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder;
import org.terasology.joml.test.VectorAssert;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class VertexAttributeBindingTest {
@Test
public void testPutAllBindingVector() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
builder.build();

a1.put(new Vector3fc[]{
new Vector3f(10, 5, 2),
new Vector3f(2, 15, 2),
new Vector3f(1, 5, 13),
new Vector3f(1, 1, 1)
});

VectorAssert.assertEquals(new Vector3f(10, 5, 2), a1.get(0, new Vector3f()), 0.001f);
VectorAssert.assertEquals(new Vector3f(2, 15, 2), a1.get(1, new Vector3f()), 0.001f);
VectorAssert.assertEquals(new Vector3f(1, 5, 13), a1.get(2, new Vector3f()), 0.001f);
VectorAssert.assertEquals(new Vector3f(1, 1, 1), a1.get(3, new Vector3f()), 0.001f);
}

@Test
public void testPutAllBindingFloat() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexFloatAttributeBinding a1 = builder.add(0, GLAttributes.FLOAT_1_VERTEX_ATTRIBUTE);
builder.build();

a1.put(new float[]{10f, .5f, 12.5f, 13.5f});

assertEquals(10f, a1.get(0), 0.001f);
assertEquals(.5f, a1.get(1), 0.001f);
assertEquals(12.5f, a1.get(2), 0.001f);
assertEquals(13.5f, a1.get(3), 0.001f);
}

@Test
public void testPutAllBindingInt() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexIntegerAttributeBinding a1 = builder.add(0, GLAttributes.INT_1_VERTEX_ATTRIBUTE);
builder.build();

a1.put(new int[]{10, 2, 1, 1});

assertEquals(10, a1.get(0));
assertEquals(2, a1.get(1));
assertEquals(1, a1.get(2));
assertEquals(1, a1.get(3));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import org.junit.Test;
import org.terasology.engine.rendering.assets.mesh.resource.GLAttributes;
import org.terasology.engine.rendering.assets.mesh.resource.VertexAttributeBinding;
import org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding;
import org.terasology.engine.rendering.assets.mesh.resource.VertexFloatAttributeBinding;
import org.terasology.engine.rendering.assets.mesh.resource.VertexIntegerAttributeBinding;
import org.terasology.engine.rendering.assets.mesh.resource.VertexResource;
import org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder;
import org.terasology.engine.rendering.assets.mesh.resource.VertexShortAttributeBinding;
import org.terasology.nui.Color;
import org.terasology.nui.Colorc;

Expand Down Expand Up @@ -74,25 +76,47 @@ public void testIntBinding() {
@Test
public void testByteBinding() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexIntegerAttributeBinding a1 = builder.add(0, GLAttributes.BYTE_1_VERTEX_ATTRIBUTE);
VertexByteAttributeBinding a1 = builder.add(0, GLAttributes.BYTE_1_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();

a1.put(10);
a1.put(150);
a1.put(300);
a1.put(100);
a1.put((byte) 10);
a1.put((byte) 150);
a1.put((byte) 100);
a1.put((byte) 100);

assertEquals(4, a1.getPosition());
resource.writeBuffer(buffer -> {
assertEquals(4 * Byte.BYTES, buffer.limit());

assertEquals(10, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 0)));
assertEquals(150, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 1)));
assertEquals(255, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 2)));
assertEquals(100, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 2)));
assertEquals(100, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 3)));
});
}

@Test
public void testShortBinding() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexShortAttributeBinding a1 = builder.add(0, GLAttributes.SHORT_1_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();

a1.put((short) 10);
a1.put((short) 150);
a1.put((short) 100);
a1.put((short) 100);

assertEquals(4, a1.getPosition());
resource.writeBuffer(buffer -> {
assertEquals(4 * Short.BYTES, buffer.limit());

assertEquals(10, Short.toUnsignedInt(buffer.getShort(Short.BYTES * 0)));
assertEquals(150, Short.toUnsignedInt(buffer.getShort(Short.BYTES * 1)));
assertEquals(100, Short.toUnsignedInt(buffer.getShort(Short.BYTES * 2)));
assertEquals(100, Short.toUnsignedInt(buffer.getShort(Short.BYTES * 3)));
});
}

@Test
public void testVector3fBinding() {
VertexResourceBuilder builder = new VertexResourceBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

package org.terasology.engine.rendering.assets.mesh;

import com.google.common.primitives.UnsignedBytes;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.junit.Test;
import org.terasology.engine.rendering.assets.mesh.resource.GLAttributes;
import org.terasology.engine.rendering.assets.mesh.resource.VertexAttributeBinding;
import org.terasology.engine.rendering.assets.mesh.resource.VertexByteAttributeBinding;
import org.terasology.engine.rendering.assets.mesh.resource.VertexIntegerAttributeBinding;
import org.terasology.engine.rendering.assets.mesh.resource.VertexResource;
import org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder;
Expand Down Expand Up @@ -53,7 +55,7 @@ public void testReserveVertexResource() {
public void testAllocation() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
VertexIntegerAttributeBinding a2 = builder.add(0, GLAttributes.BYTE_1_VERTEX_ATTRIBUTE);
VertexByteAttributeBinding a2 = builder.add(0, GLAttributes.BYTE_1_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();
a1.allocate(10);
int stride = (Float.BYTES * 3) + Byte.BYTES;
Expand All @@ -67,12 +69,12 @@ public void testAllocation() {
public void testInterleave() {
VertexResourceBuilder builder = new VertexResourceBuilder();
VertexAttributeBinding<Vector3fc, Vector3f> a1 = builder.add(0, GLAttributes.VECTOR_3_F_VERTEX_ATTRIBUTE);
VertexIntegerAttributeBinding a2 = builder.add(0, GLAttributes.BYTE_1_VERTEX_ATTRIBUTE);
VertexByteAttributeBinding a2 = builder.add(0, GLAttributes.BYTE_1_VERTEX_ATTRIBUTE);
VertexResource resource = builder.build();

a1.put(new Vector3f(10, 0, -4));
a2.put(2);
a2.put(10);
a2.put(UnsignedBytes.checkedCast(2));
a2.put(UnsignedBytes.checkedCast(10));

assertEquals(2, a2.getPosition());
assertEquals(1, a1.getPosition());
Expand Down
2 changes: 1 addition & 1 deletion engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ configurations.all {
// Primary dependencies definition
dependencies {
// Storage and networking
api group: 'com.google.guava', name: 'guava', version: '30.1-jre'
api group: 'com.google.guava', name: 'guava', version: '31.0-jre'
api group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
api group: 'net.sf.trove4j', name: 'trove4j', version: '3.0.3'
implementation group: 'io.netty', name: 'netty-all', version: '4.1.65.Final'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ private void verifyInitialisation() {
verifyRequiredSystemIsRegistered(Time.class);
verifyRequiredSystemIsRegistered(DisplayDevice.class);
verifyRequiredSystemIsRegistered(RenderingSubsystemFactory.class);
verifyRequiredSystemIsRegistered(InputSystem.class);
}

/**
Expand Down Expand Up @@ -588,7 +587,9 @@ private void switchState(GameState newState) {
newState.init(this);
stateChangeSubscribers.forEach(StateChangeSubscriber::onStateChange);
InputSystem inputSystem = rootContext.get(InputSystem.class);
inputSystem.drainQueues();
if (inputSystem != null) {
inputSystem.drainQueues();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public abstract class AbstractState implements GameState {
protected EventSystem eventSystem;
protected ComponentSystemManager componentSystemManager;

protected void initEntityAndComponentManagers() {
protected void initEntityAndComponentManagers(boolean isHeadless) {
verifyNotNull(context);
CoreRegistry.setContext(context);

Expand All @@ -41,9 +41,10 @@ protected void initEntityAndComponentManagers() {

eventSystem = context.get(EventSystem.class);
context.put(Console.class, new ConsoleImpl(context));

NUIManager nuiManager = new NUIManagerInternal((TerasologyCanvasRenderer) context.get(CanvasRenderer.class), context);
context.put(NUIManager.class, nuiManager);
if (!isHeadless) {
NUIManager nuiManager = new NUIManagerInternal((TerasologyCanvasRenderer) context.get(CanvasRenderer.class), context);
context.put(NUIManager.class, nuiManager);
}

componentSystemManager = new ComponentSystemManager(context);
context.put(ComponentSystemManager.class, componentSystemManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,28 @@ public void init(GameEngine engine) {
componentSystemManager = context.get(ComponentSystemManager.class);
entityManager = context.get(EngineEntityManager.class);
cameraTargetSystem = context.get(CameraTargetSystem.class);
inputSystem = context.get(InputSystem.class);
eventSystem.registerEventHandler(nuiManager);
if (nuiManager != null) {
inputSystem = context.get(InputSystem.class);
eventSystem.registerEventHandler(nuiManager);
}
networkSystem = context.get(NetworkSystem.class);
storageManager = context.get(StorageManager.class);
storageServiceWorker = context.get(StorageServiceWorker.class);
console = context.get(Console.class);

// Show or hide the HUD according to the settings
nuiManager.getHUD().bindVisible(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return !context.get(Config.class).getRendering().getDebug().isHudHidden();
}
});
if (nuiManager != null) {
// Show or hide the HUD according to the settings
nuiManager.getHUD().bindVisible(new ReadOnlyBinding<Boolean>() {
@Override
public Boolean get() {
return !context.get(Config.class).getRendering().getDebug().isHudHidden();
}
});
}

if (networkSystem.getMode() == NetworkMode.CLIENT) {
String motd = networkSystem.getServer().getInfo().getMOTD();
if (motd != null && motd.length() != 0) {
if (nuiManager != null && motd != null && motd.length() != 0) {
nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Server MOTD", motd);
}
}
Expand Down Expand Up @@ -133,7 +137,9 @@ public void dispose(boolean shuttingDown) {
// TODO: Shutdown background threads
eventSystem.process();
GameThread.processWaitingProcesses();
nuiManager.clear();
if (nuiManager != null) {
nuiManager.clear();
}

context.get(AudioManager.class).stopAllSounds();

Expand Down Expand Up @@ -162,11 +168,13 @@ public void dispose(boolean shuttingDown) {
console.dispose();
GameThread.clearWaitingProcesses();

/*
* Clear the binding as otherwise the complete ingame state would be
* referenced.
*/
nuiManager.getHUD().clearVisibleBinding();
if (nuiManager != null) {
/*
* Clear the binding as otherwise the complete ingame state would be
* referenced.
*/
nuiManager.getHUD().clearVisibleBinding();
}
}

@Override
Expand All @@ -187,8 +195,9 @@ public void update(float delta) {
storageManager.update();
}


updateUserInterface(delta);
if (nuiManager != null) {
updateUserInterface(delta);
}

storageServiceWorker.flushNotificationsToConsole(console);
}
Expand Down
Loading

0 comments on commit 09b552a

Please sign in to comment.