Skip to content

Commit

Permalink
WIP: First batch of code brought over from code doodle.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rene Damm [email protected] authored and Rene Damm [email protected] committed Oct 1, 2017
0 parents commit b19ef3d
Show file tree
Hide file tree
Showing 110 changed files with 4,834 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Assets/InputSystem.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/InputSystem/Actions.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/InputSystem/Actions/Modifiers.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/InputSystem/Controls.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions Assets/InputSystem/Controls/AxisControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using UnityEngine;

namespace InputSystem
{
// A float axis control.
// Can optionally be configured to perform normalization.
public class AxisControl : InputControl<float>
{
// These can be added as processors but they are so common that we
// build the functionality right into AxisControl.
public bool clamp; // If true, force clamping to [min..max]
public float clampMin;
public float clampMax;
public bool invert;

private float Preprocess(float value)
{
if (invert)
value *= -1.0f;
if (clamp)
value = Mathf.Clamp(value, clampMin, clampMax);
return value;
}

public AxisControl(string name)
: base(name)
{
stateBlock.sizeInBits = sizeof(float)*8;
}

public override float value
{
get
{
unsafe
{
var buffer = (byte*) currentStatePtr;
return Process(Preprocess(*((float*) &buffer[stateBlock.byteOffset])));
}
}
}
}
}
3 changes: 3 additions & 0 deletions Assets/InputSystem/Controls/AxisControl.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions Assets/InputSystem/Controls/ButtonControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace InputSystem
{
////REVIEW: shouldn't this still have a float value type?
public class ButtonControl : InputControl<bool>
{
public ButtonControl(string name)
: base(name)
{
}

protected unsafe bool GetValue(IntPtr statePtr)
{
var buffer = (byte*) statePtr;
return Process((buffer[stateBlock.byteOffset] & (1 << (int)stateBlock.bitOffset)) == (byte) (1 << (int)stateBlock.bitOffset));
}

public override bool value
{
get { return GetValue(currentStatePtr); }
}

public bool wasPressedThisFrame
{
get { return value != GetValue(previousStatePtr); }
}
}
}
3 changes: 3 additions & 0 deletions Assets/InputSystem/Controls/ButtonControl.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Assets/InputSystem/Controls/DiscreteControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace InputSystem
{
public class DiscreteControl : InputControl<int>
{
public DiscreteControl(string name)
: base(name)
{
stateBlock.sizeInBits = sizeof(int)*8;
}

public override int value
{
get
{
unsafe
{
var buffer = (byte*) currentStatePtr;
return Process(*((int*) &buffer[stateBlock.byteOffset]));
}
}
}
}
}
3 changes: 3 additions & 0 deletions Assets/InputSystem/Controls/DiscreteControl.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions Assets/InputSystem/Controls/DpadControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using UnityEngine;

namespace InputSystem
{
// A control made up of four discrete, directional buttons. Forms a vector
// but can also be addressed as individual buttons.
public class DpadControl : InputControl<Vector2>
{
public enum ButtonBits
{
Up,
Down,
Left,
Right,
}

[InputControl(bit = (int)ButtonBits.Up)]
public ButtonControl up { get; private set; }
[InputControl(bit = (int)ButtonBits.Down)]
public ButtonControl down { get; private set; }
[InputControl(bit = (int)ButtonBits.Left)]
public ButtonControl left { get; private set; }
[InputControl(bit = (int)ButtonBits.Right)]
public ButtonControl right { get; private set; }

public DpadControl(string name)
: base(name)
{
}

public override Vector2 value
{
get
{
unsafe
{
var upValue = up.value ? 1.0f : 0.0f;
var downValue = down.value ? -1.0f : 0.0f;
var leftValue = left.value ? -1.0f : 0.0f;
var rightValue = right.value ? 1.0f : 0.0f;

return Process(new Vector2(leftValue + rightValue, upValue + downValue));
}
}
}

protected override void FinishSetup(InputControlSetup setup)
{
up = setup.GetControl<ButtonControl>(this, "up");
down = setup.GetControl<ButtonControl>(this, "down");
left = setup.GetControl<ButtonControl>(this, "left");
right = setup.GetControl<ButtonControl>(this, "right");
base.FinishSetup(setup);
}
}
}
3 changes: 3 additions & 0 deletions Assets/InputSystem/Controls/DpadControl.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b19ef3d

Please sign in to comment.