Skip to content

Commit

Permalink
Terasology engine (#5192)
Browse files Browse the repository at this point in the history
* performance benchmark qa. drop class?

checkstyle and pmd warnings handled. drop the whole class as it seems not to be used?

* engine audio qa.

fix checkstyle and pmd warnings.

* engine logic qa.

fix checkstyle, pmd warnings.

* engine network qa.

fix checkstyle, pmd warnings.

* engine world qa.

fix checkstyle, pmd warnings, like "unchecked assignment" of TeraArray.Factory<? extends TeraArray>[] slotFactories;

* engine rendering qa.

fix checkstyle, pmd warnings.

* engine telemetry qa.

fix checkstyle, pmd warnings.

* engine utilities qa.

fix checkstyle, pmd warnings.

* engine world qa, unused v0 in graph creation.

* unused constants removed from operationgsystemmemory.

* qa engine, BenjaminAmos feedback, valid warning here.

* qa engine, BenjaminAmos feedback.
  • Loading branch information
soloturn authored Dec 24, 2023
1 parent bf78a58 commit 14937d2
Show file tree
Hide file tree
Showing 22 changed files with 151 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@
@Measurement(iterations = 1)
public class IterateComponentsBenchmark {

@Benchmark
public void iterateMultipleComponent(StateObject state) {
for (EntityRef entity : state.entityManager.getEntitiesWith(MeshComponent.class, LocationComponent.class)) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
// benchmark, nothing to be done with result at the momment.
@SuppressWarnings("PMD.UnusedLocalVariable")
MeshComponent meshComp = entity.getComponent(MeshComponent.class);
loc.getLocalPosition();
}
}

@Benchmark
public void iterateSingleComponent(StateObject state) {
for (EntityRef entity : state.entityManager.getEntitiesWith(LocationComponent.class)) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
loc.getLocalPosition();
}
}

@State(Scope.Benchmark)
public static class StateObject {
private final PojoEntityManager entityManager = new PojoEntityManager();
Expand All @@ -50,22 +69,5 @@ public void setup() {
}
}
}

@Benchmark
public void iterateMultipleComponent(StateObject state) {
for (EntityRef entity : state.entityManager.getEntitiesWith(MeshComponent.class, LocationComponent.class)) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
MeshComponent meshComp = entity.getComponent(MeshComponent.class);
loc.getLocalPosition();
}
}

@Benchmark
public void iterateSingleComponent(StateObject state) {
for (EntityRef entity : state.entityManager.getEntitiesWith(LocationComponent.class)) {
LocationComponent loc = entity.getComponent(LocationComponent.class);
loc.getLocalPosition();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,38 @@ public class OggReader extends FilterInputStream {
private static int convsize = 4096 * 2;

// Conversion buffer
private static byte[] convbuffer = new byte[convsize];
private static final byte[] CONVBUFFER = new byte[convsize];

// temp vars
private float[][][] pcm = new float[1][][];
private final float[][][] pcm = new float[1][][];
private int[] index;

// end of stream
private boolean eos;

// sync and verify incoming physical bitstream
private SyncState syncState = new SyncState();
private final SyncState syncState = new SyncState();

// take physical pages, weld into a logical stream of packets
private StreamState streamState = new StreamState();
private final StreamState streamState = new StreamState();

// one Ogg bitstream page. Vorbis packets are inside
private Page page = new Page();
private final Page page = new Page();

// one raw packet of data for decode
private Packet packet = new Packet();
private final Packet packet = new Packet();

// struct that stores all the static vorbis bitstream settings
private Info info = new Info();
private final Info info = new Info();

// struct that stores all the bitstream user comments
private Comment comment = new Comment();
private final Comment comment = new Comment();

// central working state for the packet->PCM decoder
private DspState dspState = new DspState();
private final DspState dspState = new DspState();

// local working space for packet->PCM decode
private Block block = new Block(dspState);
private final Block block = new Block(dspState);

// where we are in the convbuffer
private int convbufferOff;
Expand All @@ -88,7 +88,7 @@ public class OggReader extends FilterInputStream {
private int convbufferSize;

// a dummy used by read() to read 1 byte.
private byte[] readDummy = new byte[1];
private final byte[] readDummy = new byte[1];

/**
* Creates an OggInputStream that decompressed the specified ogg file.
Expand Down Expand Up @@ -154,7 +154,7 @@ public int read(byte[] b, int off, int len) throws IOException {
fillConvbuffer();
if (!eos) {
int bytesToCopy = Math.min(bytesRemaining, convbufferSize - convbufferOff);
System.arraycopy(convbuffer, convbufferOff, b, offset, bytesToCopy);
System.arraycopy(CONVBUFFER, convbufferOff, b, offset, bytesToCopy);
convbufferOff += bytesToCopy;
bytesRead += bytesToCopy;
bytesRemaining -= bytesToCopy;
Expand Down Expand Up @@ -184,7 +184,7 @@ public int read(ByteBuffer b, int off, int len) throws IOException {
fillConvbuffer();
if (!eos) {
int bytesToCopy = Math.min(bytesRemaining, convbufferSize - convbufferOff);
b.put(convbuffer, convbufferOff, bytesToCopy);
b.put(CONVBUFFER, convbufferOff, bytesToCopy);
convbufferOff += bytesToCopy;
bytesRead += bytesToCopy;
bytesRemaining -= bytesToCopy;
Expand Down Expand Up @@ -400,7 +400,7 @@ private int decodePacket() {
int samples;
while ((samples = dspState.synthesis_pcmout(pcm, index)) > 0) {
float[][] localPcm = this.pcm[0];
int bout = (samples < convsize ? samples : convsize);
int bout = (Math.min(samples, convsize));

// convert floats to 16 bit signed ints (host order) and interleave
for (int i = 0; i < info.channels; i++) {
Expand All @@ -416,8 +416,8 @@ private int decodePacket() {
val = Math.max(-32768, Math.min(32767, val));
val |= (val < 0 ? 0x8000 : 0);

convbuffer[ptr + 0] = (byte) (bigEndian ? val >>> 8 : val);
convbuffer[ptr + 1] = (byte) (bigEndian ? val : val >>> 8);
CONVBUFFER[ptr + 0] = (byte) (bigEndian ? val >>> 8 : val);
CONVBUFFER[ptr + 1] = (byte) (bigEndian ? val : val >>> 8);

ptr += (info.channels) << 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.lwjgl.openal.ALC10;
import org.lwjgl.openal.ALC11;
import org.lwjgl.openal.ALCCapabilities;
import org.lwjgl.openal.ALCapabilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.audio.AudioEndListener;
Expand Down Expand Up @@ -51,7 +50,7 @@ public class OpenALManager implements AudioManager {

private final Vector3f listenerPosition = new Vector3f();

private Map<SoundSource<?>, AudioEndListener> endListeners = Maps.newHashMap();
private final Map<SoundSource<?>, AudioEndListener> endListeners = Maps.newHashMap();

public OpenALManager(AudioConfig config) throws OpenALException {
logger.info("Initializing OpenAL audio manager");
Expand All @@ -63,7 +62,7 @@ public OpenALManager(AudioConfig config) throws OpenALException {
long context = ALC10.alcCreateContext(device, (int[]) null);
ALC10.alcMakeContextCurrent(context);
ALCCapabilities alcCapabilities = ALC.createCapabilities(device);
ALCapabilities alCapabilities = AL.createCapabilities(alcCapabilities);
AL.createCapabilities(alcCapabilities);

logger.info("OpenAL {} initialized!", AL10.alGetString(AL10.AL_VERSION));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
import org.terasology.input.ButtonState;
import org.terasology.nui.FontColor;

import java.util.Arrays;

import static java.util.stream.Collectors.joining;

@RegisterSystem
public class ChatSystem extends BaseComponentSystem {
private static final Logger logger = LoggerFactory.getLogger(ChatSystem.class);
Expand Down Expand Up @@ -72,9 +68,11 @@ public void onMessage(MessageEvent event, EntityRef entity) {
ClientComponent client = entity.getComponent(ClientComponent.class);
if (client.local) {
Message message = event.getFormattedMessage();
if (message.getType() == CoreMessageType.CHAT || message.getType() == CoreMessageType.NOTIFICATION
&& !nuiManager.isOpen(CHAT_UI) && !nuiManager.isOpen(CONSOLE_UI)) {
// show overlay only if chat and console are hidden
// show overlay only if chat and console are hidden
if ((message.getType() == CoreMessageType.CHAT
|| message.getType() == CoreMessageType.NOTIFICATION)
&& !nuiManager.isOpen(CHAT_UI)
&& !nuiManager.isOpen(CONSOLE_UI)) {
overlay.setVisible(true);
}
}
Expand All @@ -85,9 +83,9 @@ public void onMessage(MessageEvent event, EntityRef entity) {
shortDescription = "Sends a message to all other players")
public String say(
@Sender EntityRef sender,
@CommandParam(value = "message") String[] message
@CommandParam("message") String[] message
) {
String messageToString = join(message, " ");
String messageToString = joinWithWhitespace(message);

logger.debug("Received chat message from {} : '{}'", sender, messageToString);

Expand All @@ -98,8 +96,8 @@ public String say(
return "Message sent";
}

private String join(String[] words, String sep) {
return Arrays.stream(words).collect(joining(sep));
private String joinWithWhitespace(String[] words) {
return String.join(" ", words);
}

@Command(runOnServer = true,
Expand All @@ -110,7 +108,7 @@ public String whisper(
@CommandParam(value = "user", suggester = OnlineUsernameSuggester.class) String username,
@CommandParam("message") String[] message
) {
String messageToString = join(message, " ");
String messageToString = joinWithWhitespace(message);

Iterable<EntityRef> clients = entityManager.getEntitiesWith(ClientComponent.class);
EntityRef targetClient = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public class ConsoleImpl implements Console {
private final Map<Name, ConsoleCommand> commandRegistry = Maps.newHashMap();
private final Set<ConsoleSubscriber> messageSubscribers = Sets.newHashSet();

private NetworkSystem networkSystem;
private Context context;
private final NetworkSystem networkSystem;
private final Context context;

public ConsoleImpl(Context context) {
this.networkSystem = context.get(NetworkSystem.class);
Expand Down Expand Up @@ -231,7 +231,8 @@ public boolean execute(Name commandName, List<String> params, EntityRef callingC
String requiredPermission = cmd.getRequiredPermission();

if (!clientHasPermission(callingClient, requiredPermission)) {
callingClient.send(new ErrorMessageEvent("You do not have enough permissions to execute this command (" + requiredPermission + ")."));
callingClient.send(
new ErrorMessageEvent("You do not have enough permissions to execute this command (" + requiredPermission + ")."));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public void initialise() {
if (nuiManager != null) {
overlay = nuiManager.addOverlay(NotificationOverlay.ASSET_URI, NotificationOverlay.class);
console.subscribe((Message message) -> {
if (!nuiManager.isOpen("engine:console") && message.getType() != CoreMessageType.CHAT
&& message.getType() != CoreMessageType.NOTIFICATION || !nuiManager.isOpen("engine:chat")) {
// make sure the message isn't already shown in the chat overlay
// make sure the message isn't already shown in the chat overlay
if (!nuiManager.isOpen("engine:console")
&& (message.getType() != CoreMessageType.CHAT
&& message.getType() != CoreMessageType.NOTIFICATION
|| !nuiManager.isOpen("engine:chat"))) {
overlay.setVisible(true);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class ClientConnectionHandler extends ChannelInboundHandlerAdapter {

private static final Logger logger = LoggerFactory.getLogger(ClientConnectionHandler.class);
private static final long timeoutThreshold = 120000;
private static final long TIMEOUT_THRESHOLD = 120000;

private final Config config;
private final Context context;
Expand Down Expand Up @@ -74,7 +74,7 @@ public ClientConnectionHandler(JoinStatusImpl joinStatus, Config config, Context
*/
private void scheduleTimeout(Channel inputChannel) {
channel = inputChannel;
timeoutPoint = System.currentTimeMillis() + timeoutThreshold;
timeoutPoint = System.currentTimeMillis() + TIMEOUT_THRESHOLD;
timeoutTimer.schedule(new java.util.TimerTask() {
@Override
public void run() {
Expand All @@ -84,12 +84,12 @@ public void run() {
&& joinStatus.getStatus() != JoinStatus.Status.FAILED) {
joinStatus.setErrorMessage("Server stopped responding.");
channel.close();
logger.error("Server timeout threshold of {} ms exceeded.", timeoutThreshold);
logger.error("Server timeout threshold of {} ms exceeded.", TIMEOUT_THRESHOLD);
}
}
Thread.currentThread().stop();
}
}, timeoutThreshold + 200);
}, TIMEOUT_THRESHOLD + 200);
}

@Override
Expand Down Expand Up @@ -118,7 +118,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
}

synchronized (joinStatus) {
timeoutPoint = System.currentTimeMillis() + timeoutThreshold;
timeoutPoint = System.currentTimeMillis() + TIMEOUT_THRESHOLD;
if (message.hasServerInfo()) {
receivedServerInfo(ctx, message.getServerInfo());
} else if (message.hasModuleDataHeader()) {
Expand Down
Loading

0 comments on commit 14937d2

Please sign in to comment.