Skip to content

Commit 2c34acc

Browse files
committed
Merge pull request sirkut#14 from ZiwKerman/develop
Changes: Preset KSPActions are more event-like now, API refined, GUI memory usage optimisations and fixes
2 parents 1dee9c7 + 8d71d4f commit 2c34acc

File tree

5 files changed

+189
-134
lines changed

5 files changed

+189
-134
lines changed

InfernalRobotics/InfernalRobotics/API/IRWrapper.cs

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,15 @@ internal IRServo(Object s)
339339
MinConfigPositionProperty = IRServoMechanismType.GetProperty("MinPosition");
340340
MaxConfigPositionProperty = IRServoMechanismType.GetProperty("MaxPosition");
341341

342-
PositionProperty = IRServoMechanismType.GetProperty("Position");
343342
SpeedProperty = IRServoMechanismType.GetProperty("SpeedLimit");
344343
ConfigSpeedProperty = IRServoMechanismType.GetProperty("DefaultSpeed");
344+
CurrentSpeedProperty = IRServoMechanismType.GetProperty("CurrentSpeed");
345345
AccelerationProperty = IRServoMechanismType.GetProperty("AccelerationLimit");
346-
346+
IsMovingProperty = IRServoMechanismType.GetProperty("IsMoving");
347+
IsFreeMovingProperty = IRServoMechanismType.GetProperty("IsFreeMoving");
348+
IsLockedProperty = IRServoMechanismType.GetProperty("IsLocked");
349+
IsAxisInvertedProperty = IRServoMechanismType.GetProperty("IsAxisInverted");
350+
347351
MoveRightMethod = IRServoMechanismType.GetMethod("MoveRight", BindingFlags.Public | BindingFlags.Instance);
348352
MoveLeftMethod = IRServoMechanismType.GetMethod("MoveLeft", BindingFlags.Public | BindingFlags.Instance);
349353
MoveCenterMethod = IRServoMechanismType.GetMethod("MoveCenter", BindingFlags.Public | BindingFlags.Instance);
@@ -368,7 +372,7 @@ public String Name
368372
private PropertyInfo HighlightProperty;
369373
public bool Highlight
370374
{
371-
get { return (bool)HighlightProperty.GetValue(actualServo, null); }
375+
//get { return (bool)HighlightProperty.GetValue(actualServo, null); }
372376
set { HighlightProperty.SetValue(actualServo, value, null); }
373377
}
374378

@@ -417,13 +421,46 @@ public float Speed
417421
set { SpeedProperty.SetValue(actualServoMechanism, value, null); }
418422
}
419423

424+
private PropertyInfo CurrentSpeedProperty;
425+
public float CurrentSpeed
426+
{
427+
get { return (float)CurrentSpeedProperty.GetValue(actualServoMechanism, null); }
428+
set { CurrentSpeedProperty.SetValue(actualServoMechanism, value, null); }
429+
}
430+
420431
private PropertyInfo AccelerationProperty;
421432
public float Acceleration
422433
{
423434
get { return (float)AccelerationProperty.GetValue(actualServoMechanism, null); }
424435
set { AccelerationProperty.SetValue(actualServoMechanism, value, null); }
425436
}
426437

438+
private PropertyInfo IsMovingProperty;
439+
public bool IsMoving
440+
{
441+
get { return (bool)IsMovingProperty.GetValue(actualServoMechanism, null); }
442+
}
443+
444+
private PropertyInfo IsFreeMovingProperty;
445+
public bool IsFreeMoving
446+
{
447+
get { return (bool)IsFreeMovingProperty.GetValue(actualServoMechanism, null); }
448+
}
449+
450+
private PropertyInfo IsLockedProperty;
451+
public bool IsLocked
452+
{
453+
get { return (bool)IsLockedProperty.GetValue(actualServoMechanism, null); }
454+
set { IsLockedProperty.SetValue(actualServoMechanism, value, null); }
455+
}
456+
457+
private PropertyInfo IsAxisInvertedProperty;
458+
public bool IsAxisInverted
459+
{
460+
get { return (bool)IsAxisInvertedProperty.GetValue(actualServoMechanism, null); }
461+
set { IsAxisInvertedProperty.SetValue(actualServoMechanism, value, null); }
462+
}
463+
427464
private MethodInfo MoveRightMethod;
428465
internal void MoveRight()
429466
{
@@ -465,6 +502,32 @@ internal void Stop()
465502
{
466503
StopMethod.Invoke(actualServoMechanism, new System.Object[] { });
467504
}
505+
506+
public override bool Equals(object o)
507+
{
508+
var servo = o as IRServo;
509+
return servo != null && actualServo.Equals(servo.actualServo);
510+
}
511+
512+
public override int GetHashCode()
513+
{
514+
return (actualServo != null ? actualServo.GetHashCode() : 0);
515+
}
516+
517+
public static bool operator ==(IRServo left, IRServo right)
518+
{
519+
return Equals(left, right);
520+
}
521+
522+
public static bool operator !=(IRServo left, IRServo right)
523+
{
524+
return !Equals(left, right);
525+
}
526+
527+
protected bool Equals(IRServo other)
528+
{
529+
return Equals(actualServo, other.actualServo);
530+
}
468531
}
469532

470533
public class IRServoGroupsList : List<IRControlGroup>

InfernalRobotics/InfernalRobotics/Control/Servo/MechanismBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public float Position
2828
/// </summary>
2929
public float DefaultPosition
3030
{
31-
get { return RawServo.defaultPosition; }
32-
set { RawServo.defaultPosition = Math.Min(Math.Max(value, RawServo.minTweak), RawServo.maxTweak); }
31+
get { return RawServo.Translator.ToExternalPos(RawServo.defaultPosition); }
32+
set { RawServo.defaultPosition = Math.Min(Math.Max(RawServo.Translator.ToInternalPos(value), RawServo.minTweak), RawServo.maxTweak); }
3333
}
3434

3535
protected MuMechToggle RawServo
@@ -55,7 +55,7 @@ public bool IsLocked
5555

5656
public float CurrentSpeed
5757
{
58-
get { return RawServo.Translator.GetSpeedUnit(); }
58+
get { return RawServo.Interpolator.Velocity; }
5959
}
6060

6161
public float MaxSpeed

InfernalRobotics/InfernalRobotics/Control/Servo/ServoPreset.cs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,6 @@ public void MoveNext()
3030
rawServo.MoveNextPreset();
3131
}
3232

33-
public void MoveToIndex(int presetIndex)
34-
{
35-
if (rawServo.PresetPositions == null || rawServo.PresetPositions.Count == 0
36-
|| presetIndex < 0 || presetIndex >= rawServo.PresetPositions.Count)
37-
return;
38-
39-
float nextPosition = rawServo.PresetPositions[presetIndex];
40-
41-
if (HighLogic.LoadedSceneIsEditor)
42-
{
43-
var deltaPosition = nextPosition - (rawServo.Position);
44-
rawServo.ApplyDeltaPos(deltaPosition);
45-
}
46-
else
47-
{
48-
//because Translator expects position in external coordinates
49-
nextPosition = rawServo.Translator.ToExternalPos(nextPosition);
50-
rawServo.Translator.Move(nextPosition, rawServo.customSpeed * rawServo.speedTweak);
51-
}
52-
53-
Logger.Log("[Action] MoveToPreset, index=" + presetIndex + " currentPos = " + rawServo.Position + ", nextPosition=" + nextPosition, Logger.Level.Debug);
54-
}
55-
5633
public void Save(bool symmetry = false)
5734
{
5835
Sort();

0 commit comments

Comments
 (0)