summaryrefslogtreecommitdiff
path: root/starts/meaning-vm
diff options
context:
space:
mode:
authorolpc user <olpc@xo-5d-f7-86.localdomain>2019-12-07 07:59:22 -0800
committerolpc user <olpc@xo-5d-f7-86.localdomain>2019-12-07 07:59:22 -0800
commite2172c95cc550544723d374b990f4cae00ee7531 (patch)
treece81f056cbe062a1cc11f07c87bb8dc5cbc8eb51 /starts/meaning-vm
parentc0e8df8bb1afb686eeacdf3a7cfb1986e71749a3 (diff)
downloadstandingwithresilience-e2172c95cc550544723d374b990f4cae00ee7531.tar.gz
standingwithresilience-e2172c95cc550544723d374b990f4cae00ee7531.zip
add 200ms limit to rhythm
Diffstat (limited to 'starts/meaning-vm')
-rw-r--r--starts/meaning-vm/.gitignore4
-rw-r--r--starts/meaning-vm/habit-starts/rhythm.cpp12
2 files changed, 15 insertions, 1 deletions
diff --git a/starts/meaning-vm/.gitignore b/starts/meaning-vm/.gitignore
new file mode 100644
index 0000000..1859903
--- /dev/null
+++ b/starts/meaning-vm/.gitignore
@@ -0,0 +1,4 @@
+*.o
+*.a
+level?
+habit-starts/rhythm
diff --git a/starts/meaning-vm/habit-starts/rhythm.cpp b/starts/meaning-vm/habit-starts/rhythm.cpp
index 20085be..a89723c 100644
--- a/starts/meaning-vm/habit-starts/rhythm.cpp
+++ b/starts/meaning-vm/habit-starts/rhythm.cpp
@@ -13,11 +13,15 @@
using namespace intellect::level1;
+#define habitdelay \
+ static int thisdelay = (double(rand()) / RAND_MAX * 400000 + 200000); \
+ usleep(thisdelay); \
+
int main()
{
srand(time(0));
- int micros = 900000 + double(rand()) / RAND_MAX * 200000;
+ int micros = 400000 + double(rand()) / RAND_MAX * 400000;
// do something, wait a constant (secret) time, and do it again.
// the time things take is usually not known in advance, especially
@@ -40,6 +44,7 @@ int main()
(next-habit).fun((std::function<ref(ref)>)
[=](ref self)
{
+ habitdelay;
ref ctx = self.get(context);
ref n = self.get(next);
n.set(context, ctx);
@@ -50,6 +55,7 @@ int main()
(start-habit).fun((std::function<ref(ref)>)
[=](ref self)
{
+ habitdelay;
ref ctx = self.get(context);
ref s = ctx.get(start);
ctx.set(active-habit, s);
@@ -60,6 +66,7 @@ int main()
(keep-doing-habit).fun((std::function<void(ref)>)
[=](ref self)
{
+ habitdelay;
ref ctx = self.get(context);
ref(start-habit)(self);
@@ -72,6 +79,7 @@ int main()
(beat-habit).fun((std::function<void(ref)>)
[=](ref self)
{
+ habitdelay;
int & b = self.get(context).vget<int>(beat);
char const * beats[] = {
"A one!",
@@ -132,6 +140,7 @@ int main()
(wait-habit).fun((std::function<void(ref)>)
[=](ref self)
{
+ habitdelay;
usleep(micros);
});
@@ -140,6 +149,7 @@ int main()
(start-beat).fun((std::function<void(ref)>)
[=](ref self)
{
+ habitdelay;
self.get(context).vset(beat, int(0));
self.set(next, wait-habit);
(beat-habit).set(next, wait-habit);