Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/merge-universe-into-world-pregen…
Browse files Browse the repository at this point in the history
…-screen
  • Loading branch information
jdrueckert authored Nov 13, 2023
2 parents d48ae6d + 1b286a6 commit 3ff1e7c
Show file tree
Hide file tree
Showing 151 changed files with 508 additions and 805 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

<h3 align="center"><b>
<a href="#community">Community</a> |
<a href="#knowledge-base">Knowledge Base</a> |
<a href="#installation">Installation</a> |
<a href="#development">Development</a> |
<a href="#license">License</a>
Expand Down Expand Up @@ -69,6 +70,11 @@ We are present in nearly the complete round-up of social networks. Follow/friend
</p>


## Knowledge Base

Find documentation, instructions, and helpful references in our [Terasology Knowledge Base](http://terasology.org/Terasology/#/), formerly known as the Terasology Engine wiki.


## Installation

<table>
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ class Environment {
Environment(Name... moduleNames) {
try {
reset(Sets.newHashSet(moduleNames));
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException(e);
}
throw new RuntimeException(e);
}
}

protected void reset(Set<Name> moduleNames) throws Exception {
protected void reset(Set<Name> moduleNames) throws IOException {
this.context = new ContextImpl();
RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = new RecordAndReplayCurrentStatus();
context.put(RecordAndReplayCurrentStatus.class, recordAndReplayCurrentStatus);
Expand Down Expand Up @@ -99,7 +97,7 @@ protected void setupPathManager() throws IOException {
PathManager.getInstance();
}

protected void setupModuleManager(Set<Name> moduleNames) throws Exception {
protected void setupModuleManager(Set<Name> moduleNames) {
// empty
}

Expand Down Expand Up @@ -160,9 +158,9 @@ protected void setupCelestialSystem() {
/**
* Cleans up all resources (similar to AutoCloseable)
*
* @throws Exception if something goes wrong
* @throws RuntimeException if something goes wrong
*/
public void close() throws Exception {
public void close() {
CoreRegistry.setContext(null);
context = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ protected void setupConfig() {
}

@Override
protected void setupModuleManager(Set<Name> moduleNames) throws Exception {
protected void setupModuleManager(Set<Name> moduleNames) throws RuntimeException {
TypeRegistry.WHITELISTED_CLASSES = ExternalApiWhitelist.CLASSES.stream().map(Class::getName).collect(Collectors.toSet());

ModuleManager moduleManager = ModuleManagerFactory.create();
Expand Down Expand Up @@ -320,7 +320,7 @@ protected void loadPrefabs() {
}

@Override
public void close() throws Exception {
public void close() throws RuntimeException {
// it would be nice, if elements in the context implemented (Auto)Closeable

// The StorageManager creates a thread pool (through TaskMaster)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.terasology.reflection.ModuleTypeRegistry;
import org.terasology.reflection.TypeRegistry;

import java.io.IOException;
import java.nio.file.Path;
import java.util.stream.Collectors;

Expand All @@ -21,7 +22,7 @@ public abstract class ModuleEnvironmentTest {
protected ModuleTypeRegistry typeRegistry;

@BeforeEach
public void before(@TempDir Path tempHome) throws Exception {
public void before(@TempDir Path tempHome) throws IOException {
PathManager.getInstance().useOverrideHomePath(tempHome);

moduleManager = ModuleManagerFactory.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class ModuleManagerFactory {
private ModuleManagerFactory() {
}

public static ModuleManager create() throws Exception {
public static ModuleManager create() {
// Loading screens, among other things, break when NUI classes are not added to engine.
ModuleManager moduleManager = new ModuleManager("", ImmutableList.of(UIWidget.class));
Module unittestModule = moduleManager.registerPackageModule("org.terasology.unittest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@
import org.joml.Vector3i;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.context.Context;
import org.terasology.engine.core.Time;
import org.terasology.engine.entitySystem.entity.EntityManager;
import org.terasology.engine.integrationenvironment.jupiter.IntegrationEnvironment;
import org.terasology.engine.logic.players.LocalPlayer;
import org.terasology.engine.logic.players.event.ResetCameraEvent;
import org.terasology.engine.network.ClientComponent;
import org.terasology.engine.network.NetworkMode;
import org.terasology.engine.registry.In;
import org.terasology.engine.world.WorldProvider;
import org.terasology.engine.world.block.BlockManager;
import org.terasology.unittest.stubs.DummyEvent;

import java.io.IOException;

@IntegrationEnvironment(networkMode = NetworkMode.LISTEN_SERVER)
public class ExampleTest {
private static final Logger logger = LoggerFactory.getLogger(ExampleTest.class);

@In
private WorldProvider worldProvider;
Expand All @@ -34,6 +37,13 @@ public class ExampleTest {
@In
private ModuleTestingHelper helper;

@Test
public void testClientCreation() {
logger.info("Starting test 'testClientCreation'");
Assertions.assertDoesNotThrow(helper::createClient);
logger.info("Done with test 'testClientCreation'");
}

@Test
public void testClientConnection() throws IOException {
int currentClients = Lists.newArrayList(entityManager.getEntitiesWith(ClientComponent.class)).size();
Expand Down Expand Up @@ -65,7 +75,7 @@ public void testSendEvent() throws IOException {
Context clientContext = helper.createClient();

// send an event to a client's local player just for fun
clientContext.get(LocalPlayer.class).getClientEntity().send(new ResetCameraEvent());
clientContext.get(LocalPlayer.class).getClientEntity().send(new DummyEvent());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public long skip(long n) throws IOException {
/**
* Initalizes the vorbis stream. Reads the stream until info and comment are read.
*/
private void initVorbis() throws Exception {
private void initVorbis() throws IOException {
// Now we can read pages
syncState.init();

Expand All @@ -283,7 +283,7 @@ private void initVorbis() throws Exception {
return; //break;
}
// error case. Must not be Vorbis data
throw new Exception("Input does not appear to be an Ogg bitstream.");
throw new IOException("Input does not appear to be an Ogg bitstream.");
}

// Get the serial number and set up the rest of decode.
Expand All @@ -302,15 +302,15 @@ private void initVorbis() throws Exception {
comment.init();
if (streamState.pagein(page) < 0) {
// error; stream version mismatch perhaps
throw new Exception("Error reading first page of Ogg bitstream data.");
throw new IOException("Error reading first page of Ogg bitstream data.");
}
if (streamState.packetout(packet) != 1) {
// no page? must not be vorbis
throw new Exception("Error reading initial header packet.");
throw new IOException("Error reading initial header packet.");
}
if (info.synthesis_headerin(comment, packet) < 0) {
// error case; not a vorbis header
throw new Exception("This Ogg bitstream does not contain Vorbis audio data.");
throw new IOException("This Ogg bitstream does not contain Vorbis audio data.");
}

// At this point, we're sure we're Vorbis. We've set up the logical
Expand Down Expand Up @@ -346,7 +346,7 @@ private void initVorbis() throws Exception {
if (result == -1) {
// Uh oh; data at some point was corrupted or missing!
// We can't tolerate that in a header. Die.
throw new Exception("Corrupt secondary header. Exiting.");
throw new IOException("Corrupt secondary header. Exiting.");
}
info.synthesis_headerin(comment, packet);
i++;
Expand All @@ -364,7 +364,7 @@ private void initVorbis() throws Exception {
bytes = 0;
}
if (bytes == 0 && i < 2) {
throw new Exception("End of file before finding all Vorbis headers!");
throw new IOException("End of file before finding all Vorbis headers!");
}
syncState.wrote(bytes);
}
Expand All @@ -386,7 +386,7 @@ private void initVorbis() throws Exception {
*/
private int decodePacket() {
// check the endianes of the computer.
final boolean bigEndian = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
final boolean bigEndian = ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN);

if (block.synthesis(packet) == 0) {
dspState.synthesis_blockin(block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ public BaseSoundPool() {

public SOURCE getLockedSource() {
for (SOURCE source : soundSources.keySet()) {
if (!isActive(source)) {
if (lock(source)) {
return source;
}
if (!isActive(source) && lock(source)) {
return source;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
import org.terasology.engine.config.flexible.constraints.LocaleConstraint;
import org.terasology.engine.config.flexible.constraints.NumberRangeConstraint;

import java.util.Arrays;
import java.util.Locale;
import java.util.Locale.Category;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.lang.Math.max;
import static org.terasology.engine.config.flexible.SettingArgument.constraint;
Expand Down Expand Up @@ -81,13 +86,34 @@ public class SystemConfig extends AutoConfig {

public final Setting<Locale> locale = setting(
type(Locale.class),
defaultValue(Locale.getDefault(Category.DISPLAY)),
defaultValue(getAdjustedLocale()),
name("${engine:menu#settings-language}"),
constraint(new LocaleConstraint(Locale.getAvailableLocales())) // TODO provide translate project's locales (Pirate lang don't works)
constraint(new LocaleConstraint(
// Locale.getAvailableLocales() + non-standard "pr" (pirate) tag
Stream.concat(Arrays.stream(Locale.getAvailableLocales()), Stream.of(Locale.forLanguageTag("pr")))
.collect(Collectors.toSet())))
);

@Override
public String getName() {
return "${engine:menu#system-settings-title}";
}

private static Locale getAdjustedLocale() {
Locale systemLocale = Locale.getDefault(Category.DISPLAY);

// Matches unusual locales on Mac OS created from the user's language and location, e.g. en_UA
if (!Arrays.asList(Locale.getAvailableLocales()).contains(systemLocale)) {
final Pattern langRegionPattern = Pattern.compile("[a-z]{2}_[A-Z]{2}");

String input = systemLocale.toString();
Matcher matcher = langRegionPattern.matcher(input);

// If the locale is like that, convert it to just the language, e.g. en_UA -> en
if (matcher.find()) {
systemLocale = Locale.forLanguageTag(systemLocale.getLanguage());
}
}
return systemLocale;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public Optional<AutoConfig> deserialize(PersistedData data) {
}
return Optional.of(config);
} catch (InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
logger.error("Cannot create type [" + typeInfo + "] for deserialization", e);
logger.error("Cannot create type [{}] for deserialization", typeInfo, e);
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public boolean set(T newValue) {
Preconditions.checkNotNull(newValue, "The value of a setting cannot be null.");

if (override.get().isPresent()) {
LOGGER.warn("An attempt was made to overwrite the value specified in the System property." +
" This will give nothing while the System Property value is supplied");
LOGGER.warn("An attempt was made to overwrite the value specified in the System property."
+ " This will give nothing while the System Property value is supplied");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ private float findClosestIndex(Color color) {

private Color findClosestColor(float findex) {
int index = DoubleMath.roundToInt(findex * (double) (colors.size() - 1), RoundingMode.HALF_UP);
Color color = colors.get(index);
return color;
return colors.get(index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void register(ComponentSystem object) {
context.get(EntityManager.class).getEventSystem().registerEventHandler(object);

if (initialised) {
logger.warn("System " + object.getClass().getName() + " registered post-init.");
logger.warn("System {} registered post-init.", object.getClass().getName());
initialiseSystem(object);
}
}
Expand Down
10 changes: 5 additions & 5 deletions engine/src/main/java/org/terasology/engine/core/GameThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private GameThread() {
* @return Whether the currentThread is the gameThread.
*/
public static boolean isCurrentThread() {
return Thread.currentThread() == gameThread;
return Thread.currentThread().equals(gameThread);
}

/**
Expand All @@ -41,7 +41,7 @@ public static boolean isCurrentThread() {
* @param process
*/
public static void asynch(Runnable process) {
if (Thread.currentThread() != gameThread) {
if (!Thread.currentThread().equals(gameThread)) {
pendingRunnables.push(process);
} else {
process.run();
Expand All @@ -56,7 +56,7 @@ public static void asynch(Runnable process) {
* @param process
*/
public static void synch(Runnable process) throws InterruptedException {
if (Thread.currentThread() != gameThread) {
if (!Thread.currentThread().equals(gameThread)) {
BlockingProcess blockingProcess = new BlockingProcess(process);
pendingRunnables.push(blockingProcess);
blockingProcess.waitForCompletion();
Expand All @@ -69,7 +69,7 @@ public static void synch(Runnable process) throws InterruptedException {
* Runs all pending processes submitted from other threads
*/
public static void processWaitingProcesses() {
if (Thread.currentThread() == gameThread) {
if (Thread.currentThread().equals(gameThread)) {
List<Runnable> processes = Lists.newArrayList();
pendingRunnables.drainTo(processes);
processes.forEach(Runnable::run);
Expand All @@ -80,7 +80,7 @@ public static void processWaitingProcesses() {
* Removes all pending processes without running them
*/
public static void clearWaitingProcesses() {
if (gameThread == Thread.currentThread()) {
if (gameThread.equals(Thread.currentThread())) {
pendingRunnables.clear();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public AbstractEventSystemDecorator(EventSystem eventSystem) {
}

public boolean currentThreadIsMain() {
return mainThread == Thread.currentThread();
return mainThread.equals(Thread.currentThread());
}

@Override
Expand Down
Loading

0 comments on commit 3ff1e7c

Please sign in to comment.