public void Set(BBInputSnapshot snapshot) { mHead = snapshot; mCurrent = mHead; mCurrentTime = 0; mCurrentDelay = mCurrent.delay; }
private bool IsNiceSnapshot(BBInputSnapshot snapshot) { bool ret = false; if (BBUtil.IsStrokeInputType(snapshot.type)) { if (snapshot.type == BBInputType.Move || snapshot.type == BBInputType.Wheel) { if (mRecordButtons > 0) { ret = true; } } else if ((mRecordButtons & snapshot.button) > 0) { ret = true; } } else if (BBUtil.IsKeyboardInputType(snapshot.type) && mRecordKeyboard) { ret = true; } return(ret); }
public void StartRecord(BBInputButton buttons, bool keyboard) { mIsRecording = true; mRecordButtons = buttons; mRecordKeyboard = keyboard; mRecordTime = 0; mRecordHead = null; mRecordCurrent = null; mInputProxy.OnRecordStart(); }
public void Update(float deltaTime) { mEmulator.Update(deltaTime); BBInputSnapshot current = mEmulator.recordHead; while (current != null) { if (current.type == BBInputType.Release || current.type == BBInputType.KeyUp) { mCaptureResult = StopCapture(); break; } current = current.next; } }
private BBMacro Parse(List <BBInputSnapshot> snapshots) { BBMacro head = null; BBMacro current = null; for (int i = 0; i < snapshots.Count; i++) { BBInputSnapshot snapshot = snapshots[i]; BBMacro macro = new BBMacro(); macro.button = snapshot.button; macro.code = BBUtil.InputType2OpCode(snapshot.type); macro.key = snapshot.key; if (BBUtil.IsStrokeInputType(snapshot.type)) { var coord = mConfig.Screen2Axis(snapshot.inputPosition); if (snapshot.type == BBInputType.Wheel) { macro.data = new float[] { coord[0], coord[1], snapshot.delta }; } else { macro.data = coord; } } if (head == null) { head = macro; current = head; } else { current.next = macro; current = current.next; } } return(head); }
public BBMacro StopRecord() { if (!isRecording) { throw new System.InvalidOperationException(); } mEmulator.StopRecord(); BBMacro head = null; BBMacro current = null; BBInputSnapshot snapTail = null; bool parted = false; var elements = new List <BBInputSnapshot>(); var currentSnap = mEmulator.recordHead; while (currentSnap != null) { parted = false; elements.Add(currentSnap); if (elements.Count == 1) { if (currentSnap.type == BBInputType.Press || currentSnap.type == BBInputType.KeyDown) { // Wait to merge } else { parted = true; } } if (elements.Count > 1) { if (currentSnap.type == BBInputType.Move) { // Wait to merge } else if ((currentSnap.type == BBInputType.Release && currentSnap.button == elements[0].button) || currentSnap.type == BBInputType.KeyUp) { var fusion = Merge(elements); if (head == null) { head = fusion; current = head; } else { current.next = fusion; current = current.next; current.delay = elements[0].timeStamp - snapTail.timeStamp; } snapTail = currentSnap; elements.Clear(); } else { parted = true; } } if (parted) { BBMacro fragment = Parse(elements); if (head == null) { head = fragment; current = head; } else { current.next = fragment; current = current.next; } for (int i = 0; i < elements.Count; i++) { if (snapTail != null) { current.delay = elements[i].timeStamp - snapTail.timeStamp; } snapTail = elements[i]; if (i != elements.Count - 1) { current = current.next; } } elements.Clear(); } currentSnap = currentSnap.next; } return(head); }
private BBInputSnapshot Expand(BBMacro macro) { BBInputSnapshot expand = new BBInputSnapshot(); expand.button = macro.button; switch (macro.code) { case BBMacroOpCode.Press: { expand.type = BBInputType.Press; expand.inputPosition = mConfig.Axis2Screen(new float[] { macro.data[0], macro.data[1] }); expand.duration = macro.duration; break; } case BBMacroOpCode.Release: { expand.type = BBInputType.Release; expand.inputPosition = mConfig.Axis2Screen(new float[] { macro.data[0], macro.data[1] }); expand.duration = macro.duration; break; } case BBMacroOpCode.Move: { expand.type = BBInputType.Move; expand.inputPosition = mConfig.Axis2Screen(new float[] { macro.data[0], macro.data[1] }); expand.duration = macro.duration; break; } case BBMacroOpCode.Click: { float[] inputPosition = mConfig.Axis2Screen(new float[] { macro.data[0], macro.data[1] }); expand.type = BBInputType.Press; expand.inputPosition = inputPosition; expand.duration = macro.duration; expand.next = new BBInputSnapshot() { button = expand.button, type = BBInputType.Release, inputPosition = inputPosition, }; break; } case BBMacroOpCode.Drag: { expand.type = BBInputType.Press; expand.inputPosition = mConfig.Axis2Screen(new float[] { macro.data[0], macro.data[1] }); int dataLen2 = macro.data.Length / 2; float duration = macro.duration / dataLen2; BBInputSnapshot current = expand; for (int i = 0; i < dataLen2; i++) { current.next = new BBInputSnapshot() { button = current.button, type = BBInputType.Move, inputPosition = mConfig.Axis2Screen(new float[] { macro.data[i * 2], macro.data[i * 2 + 1] }), duration = duration, }; current = current.next; } current.next = new BBInputSnapshot() { button = current.button, type = BBInputType.Release, inputPosition = current.inputPosition, }; break; } case BBMacroOpCode.Wheel: { expand.type = BBInputType.Wheel; expand.inputPosition = mConfig.Axis2Screen(new float[] { macro.data[0], macro.data[1] }); expand.delta = (int)macro.data[2]; expand.duration = macro.duration; break; } case BBMacroOpCode.KeyDown: { expand.type = BBInputType.KeyDown; expand.key = macro.key; expand.duration = macro.duration; break; } case BBMacroOpCode.KeyUp: { expand.type = BBInputType.KeyUp; expand.key = macro.key; expand.duration = macro.duration; break; } case BBMacroOpCode.KeyPress: { expand.type = BBInputType.KeyDown; expand.key = macro.key; expand.duration = macro.duration; expand.next = new BBInputSnapshot() { type = BBInputType.KeyUp, key = macro.key }; break; } } return(expand); }
public void Clear() { mCurrent = null; mRecordHead = null; mRecordCurrent = null; }
public void Update(float deltaTime) { if (mCurrent != null) { if (mCurrentTime > 0) { mCurrentTime -= deltaTime; } else { mCurrentDelay -= deltaTime; } while (mCurrentDelay < 0 || mCurrentTime < 0) { if (mCurrentTime < 0) { mCurrent = mCurrent.next; if (mCurrent != null) { mCurrentDelay += mCurrent.delay; mCurrentDelay += mCurrentTime; mCurrentTime = 0; } else { break; } } if (mCurrentDelay < 0) { Execute(mCurrent); mCurrentTime += mCurrent.duration; mCurrentTime += mCurrentDelay; mCurrentDelay = 0; } } } if (mIsRecording) { mRecordTime += deltaTime; BBInputSnapshot snapshot = mInputProxy.TakeSnapshot(); while (snapshot != null) { if (IsNiceSnapshot(snapshot)) { snapshot.timeStamp = mRecordTime; if (mRecordHead == null) { mRecordHead = snapshot; mRecordCurrent = mRecordHead; } else { mRecordCurrent.next = snapshot; mRecordCurrent = snapshot; } } snapshot = mInputProxy.TakeSnapshot(); } } }
public void Execute(BBInputSnapshot snapshot) { mInputProxy.ProcessInput(snapshot); }