Skip to content

Commit

Permalink
minor code improvements and add lastOrb time to in-game top-left
Browse files Browse the repository at this point in the history
  • Loading branch information
XertroV committed Dec 14, 2021
1 parent 9eecd0e commit 4f4bef9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 24 deletions.
4 changes: 3 additions & 1 deletion ssol_cs/Assembly-CSharp/CollisionScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ private void OnCollisionEnter(Collision collision)
{
if (base.gameObject.tag == "Playermesh")
{
GameObject.FindGameObjectWithTag("Player").GetComponent<GameState>().PlayerVelocityVector *= 1f - (float)(0.98 * (double)Time.deltaTime);
var state = GameObject.FindGameObjectWithTag("Player").GetComponent<GameState>();
state.PlayerVelocityVector *= 1f - (float)(0.98 * (double)Time.deltaTime);
//Debug.Log($"Collision at {state.TotalTimePlayer}");
}
}

Expand Down
9 changes: 8 additions & 1 deletion ssol_cs/Assembly-CSharp/GUIScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,18 @@ private void OnGUI()
{
string timeStr = this.state.TotalTimePlayer.ToString("Time: 000.000");
string speedStr = this.state.playerVelocity.ToString("Speed: 00.00");
Vector2 vecTimerDs = GUI.skin.box.CalcSize(new GUIContent("Time: 000.000"));
Vector2 vecTimerDs = GUI.skin.box.CalcSize(new GUIContent("Time12: 000.000"));
var maxSpeed = state.MaxSpeed * state.PctOfSpdUsing;
var meshSpeed = GameObject.FindGameObjectWithTag("Playermesh").GetComponent<Rigidbody>().velocity.magnitude;
var lastOrb = state.lastOrb;
GUI.Box(new Rect(0f, 0f, vecTimerDs.x + 10f, vecTimerDs.y), new GUIContent(timeStr));
GUI.Box(new Rect(0f, vecTimerDs.y, vecTimerDs.x + 10f, vecTimerDs.y), new GUIContent(speedStr));
GUI.Box(new Rect(0f, vecTimerDs.y * 2, vecTimerDs.x + 10f, vecTimerDs.y), new GUIContent(maxSpeed.ToString("MaxSpd: 00.00")));
//GUI.Box(new Rect(0f, vecTimerDs.y * 3, vecTimerDs.x + 10f, vecTimerDs.y), new GUIContent(meshSpeed.ToString("MeshSpd: 00.00")));
GUI.Box(new Rect(0f, vecTimerDs.y * 3, vecTimerDs.x + 10f, vecTimerDs.y), new GUIContent(lastOrb.ToString("LastOrb: 00.00")));
//var pv = this.state.PlayerVelocityVector;
//Vector2 t = new Vector2(pv.x, pv.z);
//GUI.Box(new Rect(0f, vecTimerDs.y * 3, vecTimerDs.x + 10f, vecTimerDs.y), new GUIContent(t.magnitude.ToString("VelMag: 00.00")));
//GUI.Box(new Rect(0f, vecTimerDs.y * 2, vecTimerDs.x + 10f, vecTimerDs.y), new GUIContent(this.curFPS.ToString("FPS: 000.000")));

var offsetFromSide = 60f;
Expand Down
10 changes: 8 additions & 2 deletions ssol_cs/Assembly-CSharp/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,15 @@ public void reset()
// Token: 0x06000028 RID: 40
public void OrbPicked()
{
this.orbCounter = 2f;
this.orbCounter = ORB_SPEED_DUR;
// ORB_SPEED_INC -- note: below is commented in case it has an appreciable impact on speedrunning
// this.pctOfSpdUsing += ORB_SPEED_INC;
this.pctOfSpdUsing += 0.05000000074505806;
if (this.pctOfSpdUsing > (double)this.finalMaxSpeed)
{
this.pctOfSpdUsing = (double)this.finalMaxSpeed;
}
this.lastOrb = this.totalTimePlayer;
}

// Token: 0x06000029 RID: 41
Expand Down Expand Up @@ -320,7 +323,7 @@ public void LateUpdate()
Shader.SetGlobalVector("_playerOffset", new Vector4(this.playerTransform.position.x, this.playerTransform.position.y, this.playerTransform.position.z, 0f));
if (this.orbCounter <= 0f && this.pctOfSpdUsing > 0.625 && !this.GameWin)
{
this.pctOfSpdUsing -= (double)(0.6f * Time.deltaTime);
this.pctOfSpdUsing -= (double)(ORB_DECEL_RATE * Time.deltaTime);
if (this.pctOfSpdUsing < 0.625)
{
this.pctOfSpdUsing = 0.625;
Expand All @@ -345,6 +348,7 @@ public void LateUpdate()
}
Shader.SetGlobalVector("_vpc", new Vector4(-this.playerVelocityVector.x, -this.playerVelocityVector.y, -this.playerVelocityVector.z, 0f) / (float)this.c);
Shader.SetGlobalFloat("_wrldTime", (float)this.TotalTimeWorld);
// lorentz?
this.sqrtOneMinusVSquaredCWDividedByCSquared = Math.Sqrt(1.0 - Math.Pow(this.playerVelocity, 2.0) / this.cSqrd);
this.deltaTimePlayer = (double)Time.deltaTime;
if (this.keyHit)
Expand Down Expand Up @@ -637,4 +641,6 @@ public static int ConvertToUnixTimestamp(DateTime date)

public List<int> orbCollectionList = new List<int>();
public MenuComponentSelectSplits selectSplits;

public double lastOrb = 0f;
}
61 changes: 41 additions & 20 deletions ssol_cs/Assembly-CSharp/MovementScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,31 @@ private void LateUpdate()
{
this.invertKeyDown = false;
}
// NOTE: I reverse-engineered some of the logic to do some comments here and rename some vars -- forgetting that a lot of it is already in OpenRelativity -- check there before trying to read all this if you want to know what's going on.
Vector3 playerVelocityVector = this.state.PlayerVelocityVector;
// what is this angle?
// dot: angle between player's velocity and Right
// divided by magnitude (normalized-ish)
// acos: get angle
// 57.29578f = 180/pi => converts radians to degrees
// angle = angle between player and axis Right
float angle = 57.29578f * Mathf.Acos(Vector3.Dot(playerVelocityVector, Vector3.right) / playerVelocityVector.magnitude);
// rotate angle degrees around cross of velocity and axis Right
// rotate -angle degrees around cross of velocity and axis Right
Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.Cross(playerVelocityVector, Vector3.right).normalized);
Quaternion rotation2 = Quaternion.AngleAxis(angle, Vector3.Cross(Vector3.right, playerVelocityVector).normalized);
if (playerVelocityVector.sqrMagnitude == 0f)
{
rotation = Quaternion.identity;
rotation2 = Quaternion.identity;
}
Vector3 vector = Vector3.zero;
Quaternion rotation3 = Quaternion.AngleAxis(this.camTransform.eulerAngles.y, Vector3.up);
// Track acceleration input
Vector3 accelVector = Vector3.zero;
// rotate some degrees around y axis -- this is the rotation for the camera
Quaternion camRotation = Quaternion.AngleAxis(this.camTransform.eulerAngles.y, Vector3.up);
float axis;
vector += new Vector3(0f, 0f, (axis = Input.GetAxis("Vertical")) * 20f * Time.deltaTime);
// Add to z axis accel
accelVector += new Vector3(0f, 0f, (axis = Input.GetAxis("Vertical")) * ACCEL_RATE * Time.deltaTime);
if (axis != 0f)
{
if (Mathf.Abs(playerVelocityVector.magnitude) < 0.1f)
Expand All @@ -64,7 +76,8 @@ private void LateUpdate()
this.state.keyHit = true;
this.audioScripts.slowDown = true;
}
vector += new Vector3((axis = Input.GetAxis("Horizontal")) * 20f * Time.deltaTime, 0f, 0f);
// Add to x axis accel
accelVector += new Vector3((axis = Input.GetAxis("Horizontal")) * ACCEL_RATE * Time.deltaTime, 0f, 0f);
if (axis != 0f)
{
if (Mathf.Abs(playerVelocityVector.magnitude) < 0.1f)
Expand All @@ -74,25 +87,32 @@ private void LateUpdate()
this.state.keyHit = true;
this.audioScripts.slowDown = true;
}
vector = rotation3 * vector;
if (vector.x == 0f)
// rotate accel vector by camera rotation
accelVector = camRotation * accelVector;
if (accelVector.x == 0f)
{
vector += new Vector3(-2f * playerVelocityVector.x * Time.deltaTime, 0f, 0f);
accelVector += new Vector3(-SLOW_DOWN_RATE * playerVelocityVector.x * Time.deltaTime, 0f, 0f);
this.audioScripts.Decelerate();
}
if (vector.z == 0f)
if (accelVector.z == 0f)
{
vector += new Vector3(0f, 0f, -2f * playerVelocityVector.z * Time.deltaTime);
accelVector += new Vector3(0f, 0f, -SLOW_DOWN_RATE * playerVelocityVector.z * Time.deltaTime);
this.audioScripts.Decelerate();
}
if (vector.sqrMagnitude != 0f)
// if the acceleration vector has a magnitude
// I think this entire block just handles speed of light stuff??
if (accelVector.sqrMagnitude != 0f)
{
Vector3 vector2 = rotation * playerVelocityVector;
vector = rotation * vector;
// vector2 = rotate playerVelocity `angle` degrees around up/down
Vector3 vPlayerVel = rotation * playerVelocityVector;
// rotate accel vector `angle` degress around up/down
accelVector = rotation * accelVector;
// all velocity now in one direction????
//
float num = (float)this.state.SqrtOneMinusVSquaredCWDividedByCSquared;
vector2 = 1f / (1f + vector2.x * vector.x / (float)this.state.SpeedOfLightSqrd) * new Vector3(vector.x + vector2.x, vector.y * num, num * vector.z);
vector2 = rotation2 * vector2;
this.state.PlayerVelocityVector = vector2;
vPlayerVel = 1f / (1f + vPlayerVel.x * accelVector.x / (float)this.state.SpeedOfLightSqrd) * new Vector3(accelVector.x + vPlayerVel.x, accelVector.y * num, num * accelVector.z);
vPlayerVel = rotation2 * vPlayerVel;
this.state.PlayerVelocityVector = vPlayerVel;
}
if (this.speedOfLightTarget < 0)
{
Expand All @@ -110,10 +130,10 @@ private void LateUpdate()
{
this.state.SpeedOfLight = (double)this.speedOfLightTarget;
}
float num2 = -Input.GetAxisRaw("Mouse X");
float num3 = (float)this.inverted * Input.GetAxisRaw("Mouse Y");
float y = -num2 * Time.deltaTime * this.rotSpeed * this.mouseSensitivity;
float num4 = num3 * Time.deltaTime * this.rotSpeed * this.mouseSensitivity;
float mouseX = -Input.GetAxisRaw("Mouse X");
float mouseY = (float)this.inverted * Input.GetAxisRaw("Mouse Y");
float y = -mouseX * Time.deltaTime * this.rotSpeed * this.mouseSensitivity;
float num4 = mouseY * Time.deltaTime * this.rotSpeed * this.mouseSensitivity;
if (this.frames > 5)
{
this.camTransform.Rotate(new Vector3(0f, y, 0f), Space.World);
Expand All @@ -135,6 +155,7 @@ private void LateUpdate()
Camera.main.layerCullSpherical = true;
Camera.main.useOcclusionCulling = false;
}
//Debug.Log($"Camera FOV: {Camera.main.fieldOfView}");
if ((double)this.speedOfLightTarget == this.state.MaxSpeed && !this.state.GameWin)
{
this.state.GameWin = true;
Expand All @@ -154,7 +175,7 @@ public void returnGrowth()
this.speedOfLightTarget = (int)this.maxSpeed;
}
this.tStep++;
this.speedOfLightStep = Mathf.Abs((float)(this.state.SpeedOfLight - (double)this.speedOfLightTarget) / 20f);
this.speedOfLightStep = Mathf.Abs((float)(this.state.SpeedOfLight - (double)this.speedOfLightTarget) / ACCEL_RATE);
}

// Token: 0x040000C4 RID: 196
Expand Down

0 comments on commit 4f4bef9

Please sign in to comment.