Advertisement
agmike

ControlWire interface proposal

Dec 9th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. final class SPWireState
  2. {
  3.     // State < 0: ошибка (несколько контроллеров)
  4.     // State == 0: нейтральное состояние (такой ControllerState игнорируется)
  5.     // State > 0: активное состояние (ControllerState распространяется по всему проводу)
  6.     public int State;
  7.     public float Voltage; // Current = Voltage * InvResistance
  8.    
  9.     public int ControllerState;
  10.     public float ControllerVoltage;
  11.    
  12.     public int ActiveCount = 0;
  13.     public float TotalInvResistance = 0.0f;
  14.    
  15.     public bool Active = false;
  16.     public float InvResistance = 0.0f;
  17.    
  18.     public SPIntMap ControlWires;
  19. };
  20.  
  21.  
  22. final class SPVehicle
  23. {
  24.  
  25.     /* ... */
  26.  
  27.     public SPIntMap GetControlWires(string name)
  28.     {
  29.         AssertNotDisposed();
  30.         SPWireState wire = GetWire(name);
  31.         if (wire)
  32.             return wire.ControlWires;
  33.         return null;
  34.     }
  35.    
  36.     public SPIntMap GetControlWires(string name, bool neighbourDir)
  37.     {
  38.         AssertNotDisposed();
  39.         int index = GetConnectionIndex(name);
  40.         if (GetWireState(index, neighbourDir) == SPConnector.StateConnected)
  41.             return GetNeighbour(neighbourDir).GetWire(name).ControlWires;
  42.         return null;
  43.     }
  44.    
  45.     public int GetCWState(string name, string wireName)
  46.     {
  47.         AssertNotDisposed();
  48.         SPWireState wire = GetWire(name);
  49.         if (wire and wire.ControlWires)
  50.             return wire.ControlWires.Get(wireName, 0);
  51.         return 0;
  52.     }
  53.    
  54.     public void SetCWState(string name, string wireName, int value)
  55.     {
  56.         AssertNotDisposed();
  57.         SPWireState wire = GetWire(name);
  58.         if (wire and wire.ControlWires)
  59.             wire.ControlWires.Set(wireName, value);
  60.     }
  61.    
  62.     public SPIntMap GetNeighbourCWState(string wireName, bool neighbourDir, string wireName)
  63.     {
  64.         AssertNotDisposed();
  65.         int index = GetConnectionIndex(name);
  66.         if (GetWireState(index, neighbourDir) == SPConnector.StateConnected) {
  67.             SPIntMap controlWires = GetNeighbour(neighbourDir).GetWire(name).ControlWires;
  68.             if (controlWires)
  69.                 return controlWires.Get(wireName, 0);
  70.         }
  71.         return 0;
  72.     }
  73.  
  74.     /* ... */
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement