Skip to content

Commit

Permalink
Implement basic dynamic head prediction time value (auto mode) based …
Browse files Browse the repository at this point in the history
…on previous frame time.
  • Loading branch information
StellaArtois committed May 7, 2014
1 parent 265b7b9 commit 567e4a4
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .public_rev
Original file line number Diff line number Diff line change
@@ -1 +1 @@
52b34b662d19aa17bdd355794d401fa67605ff85
bcb746de04323c6f905307b1ca1bcb3738f3f1be
74 changes: 74 additions & 0 deletions patches/net/minecraft/src/RandomMobs.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
--- a/net/minecraft/src/RandomMobs.java
+++ b/net/minecraft/src/RandomMobs.java
@@ -99,7 +99,7 @@
}
else
{
- ResourceLocation entity;
+ ResourceLocation name;

try
{
@@ -110,45 +110,44 @@
initialize();
}

- if (renderGlobal != null)
+ if (renderGlobal == null)
{
- Entity entity1 = renderGlobal.renderedEntity;
- ResourceLocation name1;
+ ResourceLocation entity1 = loc;
+ return entity1;
+ }

- if (entity1 == null)
- {
- name1 = loc;
- return name1;
- }
+ Entity entity = renderGlobal.renderedEntity;

- if (!(entity1 instanceof EntityLiving))
- {
- name1 = loc;
- return name1;
- }
+ if (entity == null)
+ {
+ name = loc;
+ return name;
+ }

- String name = loc.getResourcePath();
+ if (entity instanceof EntityLiving)
+ {
+ String name1 = loc.getResourcePath();

- if (!name.startsWith("textures/entity/"))
+ if (!name1.startsWith("textures/entity/"))
{
ResourceLocation uuidLow1 = loc;
return uuidLow1;
}

- long uuidLow = entity1.getUniqueID().getLeastSignificantBits();
+ long uuidLow = entity.getUniqueID().getLeastSignificantBits();
int id = (int)(uuidLow & 2147483647L);
ResourceLocation var6 = getTextureLocation(loc, id);
return var6;
}

- entity = loc;
+ name = loc;
}
finally
{
working = false;
}

- return entity;
+ return name;
}
}

2 changes: 1 addition & 1 deletion src/com/mtbs3d/minecrift/MCController.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public boolean isInitialized() {
}

@Override
public void poll() {
public void poll(float delta) {
if(!loaded)
loadBindings();
JoystickAim.selectedJoystickMode = aimTypes[mc.vrSettings.joystickAimType];
Expand Down
2 changes: 1 addition & 1 deletion src/com/mtbs3d/minecrift/MCHydra.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public boolean isInitialized() {
}

@Override
public void poll()
public void poll(float delta)
{
if (!isInitialized())
return;
Expand Down
2 changes: 1 addition & 1 deletion src/com/mtbs3d/minecrift/MCMouse.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public boolean isInitialized() {
}

@Override
public void poll() {
public void poll(float delta) {
if(this.mc.currentScreen == null && Display.isActive())
{
this.mc.mouseHelper.mouseXYChange();
Expand Down
14 changes: 14 additions & 0 deletions src/com/mtbs3d/minecrift/MCOculus.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ private void processCalibration()
}
}

@Override
public void poll(float delta)
{
if (isInitialized())
{
if (delta != 0f)
{
_setPredictionEnabled(delta, true);
}
poll();
}
}


@Override
public float getHeadYawDegrees() {
return getYawDegrees_LH();
Expand Down
2 changes: 1 addition & 1 deletion src/com/mtbs3d/minecrift/NullCenterEyePosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean isInitialized() {
}

@Override
public void poll() {
public void poll(float delta) {
}

@Override
Expand Down
36 changes: 27 additions & 9 deletions src/com/mtbs3d/minecrift/VRRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
package com.mtbs3d.minecrift;

import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import com.mtbs3d.minecrift.api.PluginManager;
import com.mtbs3d.minecrift.render.DistortionParams;
Expand All @@ -21,7 +18,6 @@
import com.mtbs3d.minecrift.utils.Utils;
import de.fruitfly.ovr.EyeRenderParams;
import de.fruitfly.ovr.OculusRift;
import org.lwjgl.BufferUtils;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.*;

Expand Down Expand Up @@ -95,6 +91,12 @@ public class VRRenderer extends EntityRenderer
// Debug
double start = System.currentTimeMillis();

// Ghetto frame timing test
long startFrameTimeMicroSecs = 0;
long endFrameTimeNanoSecs = 0;
long frameTimeNanoSecs = 0;
long targetFrameTimeNanoSecs = 0;

/*
* MC: the minecraft world rendering code, below
* GUI: the guiFBO, with GUI rendered into it
Expand Down Expand Up @@ -524,18 +526,27 @@ public void updateCamera( float renderPartialTicks, boolean displayActive )
this.mc.vrSettings.posTrackResetPosition = false;
}

if (this.mc.gameSettings.ofSmoothFps)
// Get timing just before orient / position reading
startFrameTimeMicroSecs = System.nanoTime();

// Poll for position, orientation, setting prediction time
if (this.mc.vrSettings.useHeadTrackPrediction && this.mc.vrSettings.headTrackPredictionTimeSecs == 0)
{
float frameTimeSecs = ((float) frameTimeNanoSecs) / 1000000000f; // TODO: Take median over last n frames
//System.out.println("Frametime Secs: " + frameTimeSecs);
PluginManager.pollAll(frameTimeSecs);
}
else
{
GL11.glFinish();
PluginManager.pollAll(0.0f);
}

PluginManager.pollAll();
if(JoystickAim.selectedJoystickMode != null)
JoystickAim.selectedJoystickMode.update( renderPartialTicks );

float lookYawOffset = mc.lookaimController.getBodyYawDegrees();
float lookPitchOffset = mc.lookaimController.getBodyPitchDegrees();
float lookPitchOffset = mc.lookaimController.getBodyPitchDegrees();

if (mc.headTracker.isInitialized() && this.mc.vrSettings.useHeadTracking)
{
this.mc.mcProfiler.startSection("oculus");
Expand Down Expand Up @@ -1018,6 +1029,13 @@ else if (this.mc.vrSettings.useSupersample)
doDistortionAndSuperSample();
checkLatencyTester();

// Finish frame
GL11.glFinish();

// Get end frame timings
endFrameTimeNanoSecs = System.nanoTime();
frameTimeNanoSecs = endFrameTimeNanoSecs - startFrameTimeMicroSecs;

mc.checkGLError("After render world and GUI");
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/mtbs3d/minecrift/api/IBasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface IBasePlugin {

public boolean isInitialized();

public void poll();
public void poll(float delta);

public void destroy();

Expand Down
4 changes: 2 additions & 2 deletions src/com/mtbs3d/minecrift/api/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ public static void register( IBasePlugin that )
thePluginManager.allPlugins.add(that);
}

public static void pollAll()
public static void pollAll(float delta)
{
for( IBasePlugin p : thePluginManager.allPlugins )
{
if( p.isInitialized() )
p.poll();
p.poll(delta);
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/com/mtbs3d/minecrift/gui/GuiHeadOrientationSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void initGui()
}
else if (var8 == EnumOptions.HEAD_TRACK_PREDICTION_TIME)
{
minValue = 0.001f;
minValue = 0.000f;
maxValue = 0.100f;
increment = 0.001f;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ else if (par1GuiButton.id == 201)
if(this.mc.headTracker instanceof MCOculus)
{
this.mc.vrSettings.useHeadTrackPrediction = true;
this.mc.vrSettings.headTrackPredictionTimeSecs = 0.015f;
this.mc.vrSettings.headTrackPredictionTimeSecs = 0f;
mc.headTracker.setPrediction(this.mc.vrSettings.headTrackPredictionTimeSecs, this.mc.vrSettings.useHeadTrackPrediction);
}
this.mc.vrSettings.setHeadTrackSensitivity(1.0f);
Expand Down Expand Up @@ -187,7 +187,7 @@ protected String[] getTooltipLines(String displayString, int buttonId)
"For the Oculus Rift, enable Prediction?",
" OFF: Prediction disabled",
" ON: Prediction enabled",
" Recommended value: ON" } ;
" Recommended value: ON to reduce latency" } ;
case HEAD_TRACK_SENSITIVITY:
return new String[] {
"In-game camera orientation multiplied by this value.",
Expand All @@ -198,8 +198,9 @@ protected String[] getTooltipLines(String displayString, int buttonId)
return new String[] {
"Number of seconds to predict motion. Higher values will",
"enhance the perceived precision of slow movements, but ",
"cause issues with sudden movements",
" Recommended value: 0.015"};
"cause issues with sudden movements. Auto attempts to",
"dynamically set the value based on previous frame time.",
" Recommended value: AUTO (set to 0)"};
default:
return null;
}
Expand Down
7 changes: 5 additions & 2 deletions src/com/mtbs3d/minecrift/settings/VRSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class VRSettings {
public boolean loadMumbleLib = true;
public boolean useHeadTracking = true;
public boolean useHeadTrackPrediction = true;
public float headTrackPredictionTimeSecs = 0.015f;
public float headTrackPredictionTimeSecs = 0f;
protected float ipd = 0.0635F; // Use getIPD()
protected float oculusProfileIpd = ipd;
public String oculusProfileName;
Expand Down Expand Up @@ -629,7 +629,10 @@ public String getKeyBinding( EnumOptions par1EnumOptions )
case IPD:
return var4 + String.format("%.1fmm", new Object[] { Float.valueOf(getIPD() * 1000) });
case HEAD_TRACK_PREDICTION_TIME:
return var4 + String.format("%.0fms", new Object[] { Float.valueOf(this.headTrackPredictionTimeSecs * 1000) });
if (headTrackPredictionTimeSecs == 0.0f)
return var4 + "Auto";
else
return var4 + String.format("%.0fms", new Object[] { Float.valueOf(this.headTrackPredictionTimeSecs * 1000) });
case HUD_OPACITY:
if( this.hudOpacity > 0.99)
return var4 +" Opaque";
Expand Down

0 comments on commit 567e4a4

Please sign in to comment.