Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thread safety changes for tweener class #885

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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