- Use Flywheel.rl and Flywheel.ID where ever possible
- Rename Flywheel.log to LOGGER
- Don't add namespace to network channel version
- Use counter for packet IDs
This commit is contained in:
PepperCode1 2021-12-24 23:26:18 -08:00
parent e16b32e116
commit ec6e07f59e
15 changed files with 31 additions and 28 deletions

View file

@ -18,11 +18,11 @@ import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@Mod("flywheel")
@Mod(Flywheel.ID)
public class Flywheel {
public static final String ID = "flywheel";
public static final Logger log = LogManager.getLogger(Flywheel.class);
public static final Logger LOGGER = LogManager.getLogger(Flywheel.class);
public Flywheel() {
FMLJavaModLoadingContext.get()
@ -42,6 +42,6 @@ public class Flywheel {
private void setup(final FMLCommonSetupEvent event) {
FlwPackets.registerPackets();
ArgumentTypes.register("flywheel:engine", EngineArgument.class, new EmptyArgumentSerializer<>(EngineArgument::getInstance));
ArgumentTypes.register(rl("engine").toString(), EngineArgument.class, new EmptyArgumentSerializer<>(EngineArgument::getInstance));
}
}

View file

@ -33,6 +33,6 @@ public class FlywheelClient {
// Only thing I've seen that's close to a fix is to force the class to load before trying to use it.
// From the SpongePowered discord:
// https://discord.com/channels/142425412096491520/626802111455297538/675007581168599041
Flywheel.log.info("Successfully loaded {}", PausedPartialTickAccessor.class.getName());
Flywheel.LOGGER.info("Successfully loaded {}", PausedPartialTickAccessor.class.getName());
}
}

View file

@ -44,7 +44,7 @@ public enum GlError {
// TODO: build flag? to enable or disable this function
GlError err = GlError.poll();
if (err != null) {
Flywheel.log.error("{}: {}", err.name(), context.get());
Flywheel.LOGGER.error("{}: {}", err.name(), context.get());
}
}
}

View file

@ -139,7 +139,7 @@ public class ParallelTaskEngine implements TaskEngine {
try {
job.run();
} catch (Exception e) {
Flywheel.log.error(e);
Flywheel.LOGGER.error(e);
} finally {
ParallelTaskEngine.this.wg.done();
}

View file

@ -137,7 +137,7 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
try (MappedBuffer buf = instanceVBO.getBuffer(offset, length)) {
MemoryUtil.memSet(MemoryUtil.memAddress(buf.unwrap()), 0, length);
} catch (Exception e) {
Flywheel.log.error("Error clearing buffer tail:", e);
Flywheel.LOGGER.error("Error clearing buffer tail:", e);
}
}
}
@ -159,7 +159,7 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
}
}
} catch (Exception e) {
Flywheel.log.error("Error updating GPUInstancer:", e);
Flywheel.LOGGER.error("Error updating GPUInstancer:", e);
}
}
@ -175,7 +175,7 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
writer.write(datum);
}
} catch (Exception e) {
Flywheel.log.error("Error reallocating GPUInstancer:", e);
Flywheel.LOGGER.error("Error reallocating GPUInstancer:", e);
}
glInstanceCount = size;

View file

@ -121,7 +121,7 @@ public class ModelPool implements ModelAllocator {
}
} catch (Exception e) {
Flywheel.log.error("Error uploading pooled models:", e);
Flywheel.LOGGER.error("Error uploading pooled models:", e);
}
}
@ -133,7 +133,7 @@ public class ModelPool implements ModelAllocator {
}
pendingUpload.clear();
} catch (Exception e) {
Flywheel.log.error("Error uploading pooled models:", e);
Flywheel.LOGGER.error("Error uploading pooled models:", e);
}
}

View file

@ -35,7 +35,7 @@ public class VBOModel implements BufferedModel {
try (MappedBuffer buffer = vbo.getBuffer()) {
model.writeInto(buffer.unwrap());
} catch (Exception e) {
Flywheel.log.error(String.format("Error uploading model '%s':", model.name()), e);
Flywheel.LOGGER.error(String.format("Error uploading model '%s':", model.name()), e);
}
vbo.unbind();

View file

@ -8,8 +8,8 @@ import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;
public class FlwPackets {
public static final ResourceLocation CHANNEL_NAME = new ResourceLocation(Flywheel.ID, "network");
public static final String NETWORK_VERSION = new ResourceLocation(Flywheel.ID, "1").toString();
public static final ResourceLocation CHANNEL_NAME = Flywheel.rl("main");
public static final String NETWORK_VERSION = String.valueOf(1);
public static SimpleChannel channel;
public static void registerPackets() {
@ -19,13 +19,15 @@ public class FlwPackets {
.networkProtocolVersion(() -> NETWORK_VERSION)
.simpleChannel();
channel.messageBuilder(SConfigureBooleanPacket.class, 0, NetworkDirection.PLAY_TO_CLIENT)
int id = 0;
channel.messageBuilder(SConfigureBooleanPacket.class, id++, NetworkDirection.PLAY_TO_CLIENT)
.decoder(SConfigureBooleanPacket::new)
.encoder(SConfigureBooleanPacket::encode)
.consumer(SConfigureBooleanPacket::execute)
.add();
channel.messageBuilder(SConfigureEnginePacket.class, 1, NetworkDirection.PLAY_TO_CLIENT)
channel.messageBuilder(SConfigureEnginePacket.class, id++, NetworkDirection.PLAY_TO_CLIENT)
.decoder(SConfigureEnginePacket::new)
.encoder(SConfigureEnginePacket::encode)
.consumer(SConfigureEnginePacket::execute)

View file

@ -40,7 +40,7 @@ public class Contexts {
}
public static class Names {
public static final ResourceLocation CRUMBLING = new ResourceLocation(Flywheel.ID, "context/crumbling");
public static final ResourceLocation WORLD = new ResourceLocation(Flywheel.ID, "context/world");
public static final ResourceLocation CRUMBLING = Flywheel.rl("context/crumbling");
public static final ResourceLocation WORLD = Flywheel.rl("context/world");
}
}

View file

@ -36,7 +36,7 @@ public class FullscreenQuad {
try (MappedBuffer buffer = vbo.getBuffer()) {
buffer.putFloatArray(vertices);
} catch (Exception e) {
Flywheel.log.error("Could not create fullscreen quad.", e);
Flywheel.LOGGER.error("Could not create fullscreen quad.", e);
}
vao = new GlVertexArray();

View file

@ -1,5 +1,6 @@
package com.jozufozu.flywheel.core;
import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.api.struct.StructType;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.core.materials.model.ModelData;
@ -25,7 +26,7 @@ public class Materials {
}
public static class Names {
public static final ResourceLocation MODEL = new ResourceLocation("create", "model");
public static final ResourceLocation ORIENTED = new ResourceLocation("create", "oriented");
public static final ResourceLocation MODEL = Flywheel.rl("model");
public static final ResourceLocation ORIENTED = Flywheel.rl("oriented");
}
}

View file

@ -5,6 +5,6 @@ import com.jozufozu.flywheel.Flywheel;
import net.minecraft.resources.ResourceLocation;
public class Programs {
public static final ResourceLocation TRANSFORMED = new ResourceLocation(Flywheel.ID, "model");
public static final ResourceLocation ORIENTED = new ResourceLocation(Flywheel.ID, "oriented");
public static final ResourceLocation TRANSFORMED = Flywheel.rl("model");
public static final ResourceLocation ORIENTED = Flywheel.rl("oriented");
}

View file

@ -7,7 +7,7 @@ import net.minecraft.resources.ResourceLocation;
public class UnitExtensionInstance implements IExtensionInstance {
public static final ResourceLocation NAME = new ResourceLocation(Flywheel.ID, "unit");
public static final ResourceLocation NAME = Flywheel.rl("unit");
public UnitExtensionInstance(GlProgram program) {
}

View file

@ -10,7 +10,7 @@ import net.minecraft.resources.ResourceLocation;
public class WorldFog implements IExtensionInstance {
public static final ResourceLocation NAME = new ResourceLocation(Flywheel.ID, "fog");
public static final ResourceLocation NAME = Flywheel.rl("fog");
private final int uFogColor;
private final int uFogRange;

View file

@ -9,7 +9,7 @@ import net.minecraft.resources.ResourceLocation;
public class NormalDebugStateProvider implements IBooleanStateProvider {
public static final NormalDebugStateProvider INSTANCE = new NormalDebugStateProvider();
public static final ResourceLocation NAME = new ResourceLocation(Flywheel.ID, "normal_debug");
public static final ResourceLocation NAME = Flywheel.rl("normal_debug");
protected NormalDebugStateProvider() {