Merge pull request #2106 from archiecarrot123/master

Reduce calls to System.currentTimeMillis
This commit is contained in:
HbmMods 2025-04-25 10:10:34 +02:00 committed by GitHub
commit c1d3aad937
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 63 additions and 34 deletions

View File

@ -133,7 +133,7 @@ public class ModEventHandlerClient {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
/// NUKE FLASH ///
if(event.type == ElementType.CROSSHAIRS && (flashTimestamp + flashDuration - System.currentTimeMillis()) > 0 && ClientConfig.NUKE_HUD_FLASH.get()) {
if(event.type == ElementType.CROSSHAIRS && (flashTimestamp + flashDuration - Clock.get_ms()) > 0 && ClientConfig.NUKE_HUD_FLASH.get()) {
int width = event.resolution.getScaledWidth();
int height = event.resolution.getScaledHeight();
Tessellator tess = Tessellator.instance;
@ -143,7 +143,7 @@ public class ModEventHandlerClient {
GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.0F);
GL11.glDepthMask(false);
tess.startDrawingQuads();
float brightness = (flashTimestamp + flashDuration - System.currentTimeMillis()) / (float) flashDuration;
float brightness = (flashTimestamp + flashDuration - Clock.get_ms()) / (float) flashDuration;
tess.setColorRGBA_F(1F, 1F, 1F, brightness * 1F);
tess.addVertex(width, 0, 0);
tess.addVertex(0, 0, 0);
@ -333,7 +333,7 @@ public class ModEventHandlerClient {
if(animation.holdLastFrame)
continue;
long time = System.currentTimeMillis() - animation.startMillis;
long time = Clock.get_ms() - animation.startMillis;
if(time > animation.animation.getDuration())
HbmAnimations.hotbar[i][j] = null;
@ -804,7 +804,7 @@ public class ModEventHandlerClient {
if(cannery != null) {
list.add(EnumChatFormatting.GREEN + I18nUtil.resolveKey("cannery.f1"));
lastCannery = comp;
canneryTimestamp = System.currentTimeMillis();
canneryTimestamp = Clock.get_ms();
}
} catch(Exception ex) {
list.add(EnumChatFormatting.RED + "Error loading cannery: " + ex.getLocalizedMessage());
@ -849,7 +849,7 @@ public class ModEventHandlerClient {
int w = resolution.getScaledWidth();
int h = resolution.getScaledHeight();
double off = System.currentTimeMillis() / -10000D % 10000D;
double off = Clock.get_ms() / -10000D % 10000D;
double aw = 25;
Tessellator tessellator = Tessellator.instance;
@ -938,7 +938,7 @@ public class ModEventHandlerClient {
if(Keyboard.isKeyDown(Keyboard.KEY_F1) && Minecraft.getMinecraft().currentScreen != null) {
ComparableStack comp = canneryTimestamp > System.currentTimeMillis() - 100 ? lastCannery : null;
ComparableStack comp = canneryTimestamp > Clock.get_ms() - 100 ? lastCannery : null;
if(comp == null) {
ItemStack stack = getMouseOverStack();
@ -1114,7 +1114,7 @@ public class ModEventHandlerClient {
}
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
long millis = System.currentTimeMillis();
long millis = Clock.get_ms();
if(lastStarCheck + 200 < millis) {
renderLodeStar = false; // GENUINELY shut the fuck up i'm not kidding
@ -1222,6 +1222,8 @@ public class ModEventHandlerClient {
@SubscribeEvent
public void onRenderWorldLastEvent(RenderWorldLastEvent event) {
Clock.update();
GL11.glPushMatrix();
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
@ -1248,8 +1250,8 @@ public class ModEventHandlerClient {
GL11.glRotated(80, 0, 0, 1);
GL11.glRotated(30, 0, 1, 0);
double sine = Math.sin(System.currentTimeMillis() * 0.0005) * 5;
double sin3 = Math.sin(System.currentTimeMillis() * 0.0005 + Math.PI * 0.5) * 5;
double sine = Math.sin(Clock.get_ms() * 0.0005) * 5;
double sin3 = Math.sin(Clock.get_ms() * 0.0005 + Math.PI * 0.5) * 5;
GL11.glRotated(sine, 0, 0, 1);
GL11.glRotated(sin3, 1, 0, 0);
@ -1257,7 +1259,7 @@ public class ModEventHandlerClient {
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 6500F, 30F);
SoyuzPronter.prontCapsule();
GL11.glRotated(System.currentTimeMillis() * 0.025 % 360, 0, -1, 0);
GL11.glRotated(Clock.get_ms() * 0.025 % 360, 0, -1, 0);
int rand = new Random(MainRegistry.startupTime).nextInt(HTTPHandler.capsule.size());
String msg = HTTPHandler.capsule.get(rand);

View File

@ -10,6 +10,7 @@ import com.hbm.items.weapon.sedna.ItemGunBaseNT;
import com.hbm.packet.PermaSyncHandler;
import com.hbm.render.item.weapon.sedna.ItemRenderWeaponBase;
import com.hbm.render.model.ModelMan;
import com.hbm.util.Clock;
import com.hbm.world.biome.BiomeGenCraterBase;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
@ -544,11 +545,11 @@ public class ModEventHandlerRenderer {
/** Same procedure as getting the blended sky color but for fog */
public static Vec3 getFogBlendColor(World world, int playerX, int playerZ, float red, float green, float blue, double partialTicks) {
long millis = System.currentTimeMillis() - fogTimer;
long millis = Clock.get_ms() - fogTimer;
if(playerX == fogX && playerZ == fogZ && fogInit && millis < 3000) return fogRGBMultiplier;
fogInit = true;
fogTimer = System.currentTimeMillis();
fogTimer = Clock.get_ms();
GameSettings settings = Minecraft.getMinecraft().gameSettings;
int[] ranges = ForgeModContainer.blendRanges;
int distance = 0;

View File

@ -1,5 +1,6 @@
package com.hbm.render.anim;
import com.hbm.util.Clock;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -98,7 +99,7 @@ public class HbmAnimations {
if(anim != null) {
BusAnimation buses = anim.animation;
int millis = (int)(System.currentTimeMillis() - anim.startMillis);
int millis = (int)(Clock.get_ms() - anim.startMillis);
BusAnimationSequence seq = buses.getBus(bus);

View File

@ -14,13 +14,13 @@ public class HbmFace {
public TextureCoordinate[] textureCoordinates;
@SideOnly(Side.CLIENT)
public void addFaceForRender(Tessellator tessellator)
public void addFaceForRender(float currentTime, Tessellator tessellator)
{
addFaceForRender(tessellator, 0.0005F);
addFaceForRender(currentTime, tessellator, 0.0005F);
}
@SideOnly(Side.CLIENT)
public void addFaceForRender(Tessellator tessellator, float textureOffset)
public void addFaceForRender(float currentTime, Tessellator tessellator, float textureOffset)
{
if (faceNormal == null)
{
@ -31,6 +31,7 @@ public class HbmFace {
float averageU = 0F;
float averageV = 0F;
float animOffset = 0F;
if ((textureCoordinates != null) && (textureCoordinates.length > 0))
{
@ -42,6 +43,7 @@ public class HbmFace {
averageU = averageU / textureCoordinates.length;
averageV = averageV / textureCoordinates.length;
animOffset = (float)(((double)currentTime % HmfController.modoloMod) / HmfController.quotientMod);
}
float offsetU, offsetV;
@ -63,7 +65,7 @@ public class HbmFace {
offsetV = -offsetV;
}
tessellator.addVertexWithUV(vertices[i].x, vertices[i].y, vertices[i].z, textureCoordinates[i].u + offsetU, textureCoordinates[i].v + offsetV + (((double)System.currentTimeMillis() % HmfController.modoloMod) / HmfController.quotientMod));
tessellator.addVertexWithUV(vertices[i].x, vertices[i].y, vertices[i].z, textureCoordinates[i].u + offsetU, textureCoordinates[i].v + offsetV + animOffset);
}
else
{

View File

@ -29,25 +29,25 @@ public class HbmGroupObject {
}
@SideOnly(Side.CLIENT)
public void render()
public void render(float currentTime)
{
if (faces.size() > 0)
{
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawing(glDrawingMode);
render(tessellator);
render(currentTime, tessellator);
tessellator.draw();
}
}
@SideOnly(Side.CLIENT)
public void render(Tessellator tessellator)
public void render(float currentTime, Tessellator tessellator)
{
if (faces.size() > 0)
{
for (HbmFace face : faces)
{
face.addFaceForRender(tessellator);
face.addFaceForRender(currentTime, tessellator);
}
}
}

View File

@ -21,6 +21,8 @@ import net.minecraftforge.client.model.ModelFormatException;
import net.minecraftforge.client.model.obj.TextureCoordinate;
import net.minecraftforge.client.model.obj.Vertex;
import com.hbm.util.Clock;
public class HbmModelObject implements IModelCustom {
private static Pattern vertexPattern = Pattern.compile("(v( (\\-){0,1}\\d+(\\.\\d+)?){3,4} *\\n)|(v( (\\-){0,1}\\d+(\\.\\d+)?){3,4} *$)");
private static Pattern vertexNormalPattern = Pattern.compile("(vn( (\\-){0,1}\\d+(\\.\\d+)?){3,4} *\\n)|(vn( (\\-){0,1}\\d+(\\.\\d+)?){3,4} *$)");
@ -188,9 +190,10 @@ public class HbmModelObject implements IModelCustom {
@SideOnly(Side.CLIENT)
public void tessellateAll(Tessellator tessellator)
{
float currentTime = Clock.get_ms();
for (HbmGroupObject groupObject : groupObjects)
{
groupObject.render(tessellator);
groupObject.render(currentTime, tessellator);
}
}
@ -198,13 +201,14 @@ public class HbmModelObject implements IModelCustom {
@SideOnly(Side.CLIENT)
public void renderOnly(String... groupNames)
{
float currentTime = Clock.get_ms();
for (HbmGroupObject groupObject : groupObjects)
{
for (String groupName : groupNames)
{
if (groupName.equalsIgnoreCase(groupObject.name))
{
groupObject.render();
groupObject.render(currentTime);
}
}
}
@ -212,13 +216,14 @@ public class HbmModelObject implements IModelCustom {
@SideOnly(Side.CLIENT)
public void tessellateOnly(Tessellator tessellator, String... groupNames) {
float currentTime = Clock.get_ms();
for (HbmGroupObject groupObject : groupObjects)
{
for (String groupName : groupNames)
{
if (groupName.equalsIgnoreCase(groupObject.name))
{
groupObject.render(tessellator);
groupObject.render(currentTime, tessellator);
}
}
}
@ -228,22 +233,24 @@ public class HbmModelObject implements IModelCustom {
@SideOnly(Side.CLIENT)
public void renderPart(String partName)
{
float currentTime = Clock.get_ms();
for (HbmGroupObject groupObject : groupObjects)
{
if (partName.equalsIgnoreCase(groupObject.name))
{
groupObject.render();
groupObject.render(currentTime);
}
}
}
@SideOnly(Side.CLIENT)
public void tessellatePart(Tessellator tessellator, String partName) {
float currentTime = Clock.get_ms();
for (HbmGroupObject groupObject : groupObjects)
{
if (partName.equalsIgnoreCase(groupObject.name))
{
groupObject.render(tessellator);
groupObject.render(currentTime, tessellator);
}
}
}
@ -252,6 +259,7 @@ public class HbmModelObject implements IModelCustom {
@SideOnly(Side.CLIENT)
public void renderAllExcept(String... excludedGroupNames)
{
float currentTime = Clock.get_ms();
for (HbmGroupObject groupObject : groupObjects)
{
boolean skipPart=false;
@ -264,7 +272,7 @@ public class HbmModelObject implements IModelCustom {
}
if(!skipPart)
{
groupObject.render();
groupObject.render(currentTime);
}
}
}
@ -272,6 +280,7 @@ public class HbmModelObject implements IModelCustom {
@SideOnly(Side.CLIENT)
public void tessellateAllExcept(Tessellator tessellator, String... excludedGroupNames)
{
float currentTime = Clock.get_ms();
boolean exclude;
for (HbmGroupObject groupObject : groupObjects)
{
@ -285,7 +294,7 @@ public class HbmModelObject implements IModelCustom {
}
if(!exclude)
{
groupObject.render(tessellator);
groupObject.render(currentTime, tessellator);
}
}
}

View File

@ -5,6 +5,7 @@ import org.lwjgl.opengl.GL11;
import com.hbm.blocks.BlockDummyable;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.main.ResourceManager;
import com.hbm.util.Clock;
import com.hbm.render.loader.HmfController;
import com.hbm.tileentity.machine.TileEntityMachineChemplant;
@ -77,7 +78,7 @@ public class RenderChemplant extends TileEntitySpecialRenderer {
bindTexture(ResourceManager.chemplant_spinner_tex);
int rotation = (int) (System.currentTimeMillis() % (360 * 5)) / 5;
int rotation = (int) (Clock.get_ms() % (360 * 5)) / 5;
GL11.glPushMatrix();
GL11.glTranslated(-0.625, 0, 0.625);
@ -101,7 +102,7 @@ public class RenderChemplant extends TileEntitySpecialRenderer {
ResourceManager.chemplant_spinner.renderAll();
GL11.glPopMatrix();
double push = Math.sin((System.currentTimeMillis() % 2000) / 1000D * Math.PI) * 0.25 - 0.25;
double push = Math.sin((Clock.get_ms() % 2000) / 1000D * Math.PI) * 0.25 - 0.25;
bindTexture(ResourceManager.chemplant_piston_tex);

View File

@ -10,6 +10,7 @@ import org.lwjgl.opengl.GL11;
import com.hbm.util.fauxpointtwelve.BlockPos;
import com.hbm.wiaj.WorldInAJar;
import com.hbm.util.Clock;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
@ -272,7 +273,7 @@ public class RenderOverhead {
tagList.add(entry);
if(marker.expire > 0 && System.currentTimeMillis() > marker.expire) {
if(marker.expire > 0 && Clock.get_ms() > marker.expire) {
it.remove();
} else if(marker.maxDist > 0) {
double aX = pX + (maxX - minX) / 2D;

View File

@ -10,6 +10,7 @@ import com.hbm.interfaces.Untested;
import com.hbm.items.weapon.sedna.Crosshair;
import com.hbm.items.weapon.sedna.impl.ItemGunStinger;
import com.hbm.lib.RefStrings;
import com.hbm.util.Clock;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
@ -47,8 +48,8 @@ public class RenderScreenOverlay {
radiation = lastResult - prevResult;
if(System.currentTimeMillis() >= lastSurvey + 1000) {
lastSurvey = System.currentTimeMillis();
if(Clock.get_ms() >= lastSurvey + 1000) {
lastSurvey = Clock.get_ms();
prevResult = lastResult;
lastResult = in;
}

View File

@ -173,7 +173,7 @@ public class TileEntityMachineChemplant extends TileEntityMachineBase implements
if(isProgressing && volume > 0) {
if(audio == null) {
audio = this.createAudioLoop();
audio = createAudioLoop();
audio.updateVolume(volume);
audio.startSound();
} else if(!audio.isPlaying()) {

View File

@ -0,0 +1,11 @@
package com.hbm.util;
public class Clock {
private static long time_ms;
public static void update(){
time_ms = System.currentTimeMillis();
}
public static long get_ms(){
return time_ms;
}
}