Frame Level Language for controlling DUALSHOCK2

Dependents:   koibumi2000

Files at this revision

API Documentation at this revision

Comitter:
amutake
Date:
Thu Feb 19 13:47:15 2015 +0000
Parent:
0:a436e2063a3d
Commit message:
Change logic of EasySource

Changed in this revision

fllaux.cpp Show annotated file Show diff for this revision Revisions of this file
fllaux.h Show annotated file Show diff for this revision Revisions of this file
diff -r a436e2063a3d -r 905fe1a0ca5a fllaux.cpp
--- a/fllaux.cpp	Thu Feb 19 06:59:49 2015 +0000
+++ b/fllaux.cpp	Thu Feb 19 13:47:15 2015 +0000
@@ -65,13 +65,42 @@
 // ----------
 // EasySource
 // ----------
+button_time single(button_t btn)
+{
+    button_time bt = { btn, FRAME * 2 };
+    return bt;
+}
+
+button_time hold(button_t btn, float sec)
+{
+    button_time bt = { btn, sec };
+    return bt;
+}
+
+button_time space(float sec)
+{
+    button_time bt = { 0, sec };
+    return bt;
+}
+
 EasySource::EasySource(button_time* seq, int size)
 {
     bt_seq = seq;
     bt_size = size;
     index = 0;
     frame_i = 0;
-    lag = 0;
+    spacing = false;
+    space_frame = 2;
+}
+
+EasySource::EasySource(button_time* seq, int size, int spacer)
+{
+    bt_seq = seq;
+    bt_size = size;
+    index = 0;
+    frame_i = 0;
+    spacing = false;
+    space_frame = spacer;
 }
 
 button_t EasySource::await()
@@ -80,20 +109,27 @@
         return 0;
     }
 
-    button_time bt = bt_seq[index];
-    float passing = frame_i * FRAME; // passing time since the begining of this note (sec)
-
-    frame_i++;
+    if (spacing) {
+        if (frame_i + 1 >= space_frame) { // final frame of spacer
+            spacing = false;
+            frame_i = 0;
+            index++;
+        } else {
+            frame_i++;
+        }
+        return 0;
+    } else {
+        button_time bt = bt_seq[index];
+        float passing = frame_i * FRAME; // passing time since the begining of this note (sec)
 
-    button_t btn = 0;
-    if (passing + FRAME >= bt.sec - lag) { // final frame
-        frame_i = 0;
-        index++;
-        lag = passing + FRAME - (bt.sec - lag);
-    } else if (frame_i < 4) { // pressing time
-        btn = bt.button;
+        if (passing + FRAME >= bt.sec) { // final frame
+            frame_i = 0;
+            spacing = true;
+        } else {
+            frame_i++;
+        }
+        return bt.button;
     }
-    return btn;
 }
 
 bool EasySource::is_finished()
@@ -105,7 +141,7 @@
 {
     index = 0;
     frame_i = 0;
-    lag = 0;
+    spacing = false;
 }
 
 // --------
diff -r a436e2063a3d -r 905fe1a0ca5a fllaux.h
--- a/fllaux.h	Thu Feb 19 06:59:49 2015 +0000
+++ b/fllaux.h	Thu Feb 19 13:47:15 2015 +0000
@@ -42,6 +42,10 @@
     float sec;
 } button_time; // TODO: rename
 
+button_time single(button_t btn);
+button_time hold(button_t btn, float sec);
+button_time space(float sec);
+
 // human friendly source
 class EasySource : public Producer
 {
@@ -50,9 +54,11 @@
     int bt_size;
     int index;
     int frame_i;
-    float lag;
+    bool spacing;
+    int space_frame;
 public:
     EasySource(button_time* seq, int size);
+    EasySource(button_time* seq, int size, int spacer); // spacer is the number of frame
     virtual button_t await();
     virtual bool is_finished();
     virtual void reset();