Skip to content

Commit

Permalink
Merge pull request #885 from eksime/tweener-thread-safety
Browse files Browse the repository at this point in the history
thread safety changes for tweener class
  • Loading branch information
dlamkins authored Jul 4, 2023
2 parents 5324944 + 3faaf82 commit c8201e7
Show file tree
Hide file tree
Showing 4 changed files with 611 additions and 719 deletions.
43 changes: 17 additions & 26 deletions Blish HUD/Library/Glide/MemberAccessor.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
using System;
using System.Linq.Expressions;
using System.Reflection;
namespace Glide {
using System;
using System.Linq.Expressions;
using System.Reflection;

namespace Glide
{
internal class MemberAccessor
{
public object Target { get; private set; }
internal class MemberAccessor {
public string MemberName { get; private set; }
public Type MemberType { get; private set; }

public object Value
{
get { return getMethod(this.Target); }
set { setMethod(this.Target, value); }
public void SetValue(object target, object value) {
setMethod(target, value);
}

public MemberAccessor(object target, string name, bool writeRequired = true)
{
public object GetValue(object target) {
return getMethod(target);
}

public MemberAccessor(object target, string name, bool writeRequired = true) {
var T = target.GetType();
PropertyInfo propInfo = null;
FieldInfo fieldInfo = null;
this.Target = target;

if ((propInfo = T.GetProperty(name, flags)) != null)
{
if ((propInfo = T.GetProperty(name, flags)) != null) {
this.MemberType = propInfo.PropertyType;
this.MemberName = propInfo.Name;

Expand All @@ -35,8 +31,7 @@ public MemberAccessor(object target, string name, bool writeRequired = true)
getMethod = Expression.Lambda<Func<object, object>>(convert, param).Compile();
}

if (writeRequired)
{
if (writeRequired) {
var param = Expression.Parameter(typeof(object));
var argument = Expression.Parameter(typeof(object));
var setterCall = Expression.Call(
Expand All @@ -46,9 +41,7 @@ public MemberAccessor(object target, string name, bool writeRequired = true)

setMethod = Expression.Lambda<Action<object, object>>(setterCall, param, argument).Compile();
}
}
else if ((fieldInfo = T.GetField(name, flags)) != null)
{
} else if ((fieldInfo = T.GetField(name, flags)) != null) {
this.MemberType = fieldInfo.FieldType;
this.MemberName = fieldInfo.Name;

Expand All @@ -69,15 +62,13 @@ public MemberAccessor(object target, string name, bool writeRequired = true)

setMethod = Expression.Lambda<Action<object, object>>(assignExp, self, value).Compile();
}
}
else
{
} else {
throw new Exception(string.Format("Field or {0} property '{1}' not found on object of type {2}.",
writeRequired ? "read/write" : "readable",
name, T.FullName));
}
}

protected Func<object, object> getMethod;
protected Action<object, object> setMethod;
private static BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
Expand Down
41 changes: 19 additions & 22 deletions Blish HUD/Library/Glide/MemberLerper.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
using System;
namespace Glide {
using System;

namespace Glide
{
public abstract class MemberLerper
{
[Flags]
public enum Behavior
{
None = 0,
Reflect = 1,
Rotation = 2,
RotationRadians = 4,
RotationDegrees = 8,
Round = 16
}

protected const float DEG = 180f / (float) Math.PI;
protected const float RAD = (float) Math.PI / 180f;

public abstract void Initialize(Object fromValue, Object toValue, Behavior behavior);
public abstract object Interpolate(float t, object currentValue, Behavior behavior);
}
public abstract class MemberLerper {
[Flags]
public enum Behavior {
None = 0,
Reflect = 1,
Rotation = 2,
RotationRadians = 4,
RotationDegrees = 8,
Round = 16
}

protected const float DEG = 180f / (float)Math.PI;
protected const float RAD = (float)Math.PI / 180f;

public abstract void Initialize(Object fromValue, Object toValue, Behavior behavior);
public abstract object Interpolate(float t, object currentValue, Behavior behavior);
}
}
Loading

0 comments on commit c8201e7

Please sign in to comment.