diff options
| author | Comment <tim@gray.(none)> | 2012-12-10 19:30:27 +0000 |
|---|---|---|
| committer | Comment <tim@gray.(none)> | 2012-12-10 19:30:27 +0000 |
| commit | dba01ce870165fd8d8a5fea921cb31f7c4e8c25f (patch) | |
| tree | bc7f877edaeb2047eac9606c9bf869bbe9f7776a | |
| parent | 0bb92ced351b7fbba6e2e7036eae92037d08facf (diff) | |
fixed race condition in asterisk driver
| -rwxr-xr-x | ofAsterisk/src/Asterisk.cpp | 121 | ||||
| -rwxr-xr-x | ofAsterisk/src/Asterisk.h | 25 | ||||
| -rwxr-xr-x | vfg/bin/data/Penguin-Blue.xml | 6 | ||||
| -rwxr-xr-x | vfg/bin/data/Penguin-Green.xml | 6 | ||||
| -rwxr-xr-x | vfg/bin/data/Penguin-Purple.xml | 6 | ||||
| -rwxr-xr-x | vfg/bin/data/Raccoon-Blue.xml | 6 | ||||
| -rwxr-xr-x | vfg/bin/data/Raccoon-Green.xml | 6 | ||||
| -rwxr-xr-x | vfg/bin/data/Raccoon-Purple.xml | 6 | ||||
| -rwxr-xr-x | vfg/src/Asterisk.cpp | 97 | ||||
| -rwxr-xr-x | vfg/src/Asterisk.h | 14 | ||||
| -rwxr-xr-x | vfg/src/Puppet.cpp | 33 | ||||
| -rwxr-xr-x | vfg/src/Puppet.h | 15 | ||||
| -rwxr-xr-x | vfg/src/music.cpp | 49 | ||||
| -rwxr-xr-x | vfg/src/music.h | 7 | ||||
| -rwxr-xr-x | vfg/src/testApp.cpp | 110 | ||||
| -rwxr-xr-x | vfg/src/testApp.h | 2 | ||||
| -rw-r--r-- | vfg/vfg.layout | 26 |
17 files changed, 341 insertions, 194 deletions
diff --git a/ofAsterisk/src/Asterisk.cpp b/ofAsterisk/src/Asterisk.cpp index b78678e..fc9dc7a 100755 --- a/ofAsterisk/src/Asterisk.cpp +++ b/ofAsterisk/src/Asterisk.cpp @@ -33,25 +33,28 @@ gameQ has 1 calls (max unlimited) in 'rrmemory' strategy (8s holdtime, 50s talkt void Asterisk::threadedFunction(){
- while( isThreadRunning() != 0 ){
- FILE *f = popen("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"queue show gameQ\"'", "re");
- int fn=fileno(f);
- char buf[1000];
- ssize_t r = read(fn, buf, 1000);
- pclose(f);
- string msg=string(buf);
- //received data is always a command ACKNOWLEDGEMENT
- if (msg.compare(0,5,"gameQ")==0) {
- vector<std::string> lines;
- split(msg,'\n',lines);
- queued=0;
- for (int i=4;i<lines.size();i++) {
- if (lines[i].compare(0,6," ")==0&&lines[i].compare(7,1,".")==0) queued++;
- }
- }
- else {
- printf("status err: %s\n",buf);
- }
+ while( isThreadRunning() != 0 ){ + //if (lock()) {
+ FILE *f = popen("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"queue show gameQ\"'", "re"); //e ??
+ int fn=fileno(f);
+ char buf[1000];
+ ssize_t r = read(fn, buf, 1000);
+ pclose(f);
+ string msg=string(buf);
+ //received data is always a command ACKNOWLEDGEMENT
+ if (msg.compare(0,5,"gameQ")==0) {
+ vector<std::string> lines;
+ split(msg,'\n',lines);
+ queued=0;
+ for (int i=4;i<lines.size();i++) {
+ if (lines[i].compare(0,6," ")==0&&lines[i].compare(7,1,".")==0) queued++;
+ }
+ }
+ else {
+ printf("status err: %s\n",buf);
+ } + //unlock(); + //}
ofSleepMillis(statusPollMillis);
}
@@ -62,55 +65,78 @@ void Asterisk::setup(string passcode,int millis){ udpConnection.Bind(5000);
udpConnection.SetNonBlocking(true);
cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME passcode "+passcode+"\"'");
- state=WAITING; //for acknowledge
- isPlaying=false;
+ state=ASTERISK_WAITING; //for acknowledge
statusPollMillis=millis;
- if (statusPollMillis>0) startThread(true, false); // blocking, verbose
+ if (statusPollMillis>0) startThread(false, false); // blocking, verbose
}
-void Asterisk::startGame(){
- if (!isPlaying&&queued) {
- cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"devstate change Custom:GAME NOT_INUSE\"'");
- printf("Asterisk: attempting to dequeue\n");
- state=WAITING;
- }
+void Asterisk::startGame(){ + //if (lock()) {
+ if (state==ASTERISK_IDLE&&queued) {
+ cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"devstate change Custom:GAME NOT_INUSE\"'");
+ printf("Asterisk: attempting to dequeue\n");
+ } + //unlock(); + //}
}
void Asterisk::endGame(string score){
printf("Asterisk: request hangup %s\n",playerCode.c_str());
- if (isPlaying) {
- cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME statuscode "+score+"\"'");
+ if (state==ASTERISK_PLAYING) {
+ //cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME statuscode "+score+"\"'");
string emsg="ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"hangup request "+playerCode+"\"'";
- cmd(emsg);
+ scmd(emsg);
printf("Asterisk: hanging up %s\n",playerCode.c_str());
- state=WAITING;
- isPlaying=false;
+ state=ASTERISK_IDLE;
}
}
void Asterisk::cmd(string s) {
- //non blocking command for anync messages
- file = popen(s.c_str(), "re");
+ //non blocking command for anync messages + //pclose(file); always closing before open crashes + printf("open file\n");
+ file = popen(s.c_str(), "re"); //"e" seems necessary for non blocking but with it getting crash when dequeuing. can't seem to trace it
filenum=fileno(file);
- fcntl(filenum, F_SETFL, O_NONBLOCK);
-}
+ fcntl(filenum, F_SETFL, O_NONBLOCK); + state=ASTERISK_WAITING;
+} + +void Asterisk::scmd(string s) {
+ //non blocking command for anync messages + //pclose(file); always closing before open crashes + printf("open file\n");
+ file = popen(s.c_str(), "re"); //"e" seems necessary for non blocking but with it getting crash when dequeuing. can't seem to trace it
+ filenum=fileno(file);
+ fcntl(filenum, F_SETFL, O_NONBLOCK); + printf("close file\n");
+ pclose(file);
+} + + +/*Child process PID: 4265 +Program received signal SIGABRT, Aborted. +In __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64 () +Cannot open file: /home/tim/workspace/VFxmas/vfg/iofclose.c +*/ +
int Asterisk::update(){
//capture stdin response from popen
- if (state==WAITING||state==STARTING) {
+ if (state==ASTERISK_WAITING) {
char buf[100];
ssize_t r = read(filenum, buf, 1000);
//if (r == -1 && errno == EAGAIN)
//no data yet
//else
- if (r > 0) {
+ if (r > 0) { + //is it here? + printf("close file\n");
pclose(file);
string msg=string(buf);
- state=IDLE;
+ state=ASTERISK_IDLE;
//received data is always a command ACKNOWLEDGEMENT
//can never issue a new one until last one returns?
if (msg.compare(0,8,"Changing")==0) {
printf("player dequeued\n");
- state==PLAYING;
- isPlaying=true;
+ state=ASTERISK_STARTING;
}
else {
printf("stdin says: %s\n",buf);
@@ -127,15 +153,20 @@ int Asterisk::update(){ //printf("Asterisk: %s\n",msg.c_str());
if (msg.length()>3) {
//printf("status msg: %s\n",msg.c_str());
- if (msg.substr(0,5)=="Local") {
- state=PLAYING;
+ if (msg.substr(0,6)=="Hangup") {
+ state=ASTERISK_IDLE;
+ return ASTERISK_GAMEOVER;
+ }
+ if (msg.substr(0,5)=="Local"&&state==ASTERISK_STARTING) {
+ state=ASTERISK_PLAYING;
playerCode=msg.substr(0,msg.length()-1);
printf("Asterisk: game started: code %s\n",playerCode.c_str());
- return 1000;
+ return ASTERISK_GAMESTARTED;
}
return 0;
}
else {
+ //message length of <3 is a key
return ofToInt(msg);
}
}
diff --git a/ofAsterisk/src/Asterisk.h b/ofAsterisk/src/Asterisk.h index 5033a5c..fb6097c 100755 --- a/ofAsterisk/src/Asterisk.h +++ b/ofAsterisk/src/Asterisk.h @@ -4,10 +4,12 @@ #include "ofMain.h"
#include "ofxNetwork.h"
-#define IDLE 0
-#define WAITING 1
-#define STARTING 2
-#define PLAYING 3
+#define ASTERISK_IDLE 0
+#define ASTERISK_WAITING 1
+#define ASTERISK_STARTING 2
+#define ASTERISK_PLAYING 3
+#define ASTERISK_GAMESTARTED 1000
+#define ASTERISK_GAMEOVER 1001
class Asterisk: public ofThread
@@ -15,27 +17,27 @@ class Asterisk: public ofThread public:
Asterisk(){
}
-
+
void start(){
-
+
}
void stop(){
stopThread();
}
//--------------------------
-
+
void setup(string passcode="1111",int millis=1000);
virtual ~Asterisk();
void startGame();
void endGame(string score);
int update();
int state;
- bool isPlaying;
int queued;
protected:
- void cmd(string s);
+ void cmd(string s); + void scmd(string s);
void threadedFunction();
private:
int startTime;
@@ -43,8 +45,9 @@ class Asterisk: public ofThread int filenum;
ofxUDPManager udpConnection;
string playerCode;
- int statusPollMillis;
-
+ int statusPollMillis; +
+
};
#endif // ASTERISK_H
diff --git a/vfg/bin/data/Penguin-Blue.xml b/vfg/bin/data/Penguin-Blue.xml index 494140e..d1be26d 100755 --- a/vfg/bin/data/Penguin-Blue.xml +++ b/vfg/bin/data/Penguin-Blue.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Penguin/Penguin-Blue.png" frames="1"/>
- <Clip name="Clap" files="Penguin2/Clap-Blue2/Penguin-Clap-Blue2_%05i.png" rate="50" frames="30"/>
- <Clip name="Catch" files="Penguin2/Catch-Blue2/Catch-Blue2_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Penguin/Clap-Blue2/Penguin-Clap-Blue2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Catch" files="Penguin/Catch-Blue2/Catch-Blue2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Penguin/Penguin-Happy-Blue/Penguin-Happy-Blue_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Penguin/Penguin-Jump-Blue/Penguin-Jump-Blue_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Penguin2/Shudder-Blue2/Shudder-Blue2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Penguin/Shudder-Blue2/Shudder-Blue2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Penguin/Penguin-ShuffleShort-Blue/Penguin-ShuffleShort-Blue_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Penguin/Penguin-WalkingStart-Blue/Penguin-WalkingStart-Blue_%05i.png" rate="50" frames="11"/>
<Clip name="Walking" files="Penguin/Penguin-WalkingLoop-Blue/Penguin-WalkLoop-Blue_%05i.png" rate="50" frames="35"/>
diff --git a/vfg/bin/data/Penguin-Green.xml b/vfg/bin/data/Penguin-Green.xml index f7c4f20..959f7c7 100755 --- a/vfg/bin/data/Penguin-Green.xml +++ b/vfg/bin/data/Penguin-Green.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Penguin/Penguin-Green.png" frames="1"/>
- <Clip name="Clap" files="Penguin2/Clap-Green2/Penguin-Clap-Green2_%05i.png" rate="50" frames="30"/>
- <Clip name="Catch" files="Penguin2/Catch-Green2/Catch-Green2_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Penguin/Clap-Green2/Penguin-Clap-Green2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Catch" files="Penguin/Catch-Green2/Catch-Green2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Penguin/Penguin-Happy-Green/Penguin-Happy-Green_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Penguin/Penguin-Jump-Green/Penguin-Jump-Green_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Penguin2/Shudder-Green2/Shudder-Green2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Penguin/Shudder-Green2/Shudder-Green2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Penguin/Penguin-ShuffleShort-Green/Penguin-ShuffleShort-Green_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Penguin/Penguin-WalkingStart-Green/Penguin-WalkingStart-Green_%05i.png" rate="50" frames="11"/>
<Clip name="Walking" files="Penguin/Penguin-WalkingLoop-Green/Penguin-WalkLoop-Green_%05i.png" rate="50" frames="35"/>
diff --git a/vfg/bin/data/Penguin-Purple.xml b/vfg/bin/data/Penguin-Purple.xml index 2d5aa4c..4b9faf9 100755 --- a/vfg/bin/data/Penguin-Purple.xml +++ b/vfg/bin/data/Penguin-Purple.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Penguin/Penguin-Purple.png" frames="1"/>
- <Clip name="Clap" files="Penguin2/Clap-Purple2/Penguin-Clap-Purple2_%05i.png" rate="50" frames="30"/>
- <Clip name="Catch" files="Penguin2/Catch-Purple2/Catch-Purple2_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Penguin/Clap-Purple2/Penguin-Clap-Purple2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Catch" files="Penguin/Catch-Purple2/Catch-Purple2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Penguin/Penguin-Happy-Purple/Penguin-Happy-Purple_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Penguin/Penguin-Jump-Purple/Penguin-Jump-Purple_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Penguin2/Shudder-Purple2/Shudder-Purple2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Penguin/Shudder-Purple2/Shudder-Purple2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Penguin/Penguin-ShuffleShort-Purple/Penguin-ShuffleShort-Purple_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Penguin/Penguin-WalkingStart-Purple/Penguin-WalkingStart-Purple_%05i.png" rate="50" frames="11"/>
<Clip name="Walking" files="Penguin/Penguin-WalkingLoop-Purple/Penguin-WalkLoop-Purple_%05i.png" rate="50" frames="35"/>
diff --git a/vfg/bin/data/Raccoon-Blue.xml b/vfg/bin/data/Raccoon-Blue.xml index 98366d8..9a3043b 100755 --- a/vfg/bin/data/Raccoon-Blue.xml +++ b/vfg/bin/data/Raccoon-Blue.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Raccoon/Raccoon-Blue.png" frames="1"/>
- <Clip name="Clap" files="Raccoon2/Clap-Blue2/Raccoon-Clap2_%05i.png" rate="50" frames="20"/>
- <Clip name="Catch" files="Raccoon2/Catch-Blue2/Raccoon-Catch-Blue2_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Raccoon/Clap-Blue2/Raccoon-Clap2_%05i.png" rate="50" frames="20"/>
+ <Clip name="Catch" files="Raccoon/Catch-Blue2/Raccoon-Catch-Blue2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Raccoon/Raccoon-Happy-Blue/Raccoon-Happy-Blue_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Raccoon/Raccoon-Jump-Blue/Raccoon-Jump-Blue_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Raccoon2/Shudder-Blue2/Raccoon-Shudder-Blue2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Raccoon/Shudder-Blue2/Raccoon-Shudder-Blue2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Raccoon/Raccoon-Shuffle-Blue/Raccoon-Shuffle-Blue_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Raccoon/Raccoon-StandDown-Blue/Raccoon-StandDown-Blue_%05i.png" rate="50" frames="20"/>
<Clip name="Walking" files="Raccoon/Raccoon-WalkLoop-Blue/Raccoon-WalkLoop-Blue_%05i.png" rate="50" start="20" frames="39"/>
diff --git a/vfg/bin/data/Raccoon-Green.xml b/vfg/bin/data/Raccoon-Green.xml index 7c4961b..89fcd56 100755 --- a/vfg/bin/data/Raccoon-Green.xml +++ b/vfg/bin/data/Raccoon-Green.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Raccoon/Raccoon-Green.png" frames="1"/>
- <Clip name="Clap" files="Raccoon2/Clap-Green2/Raccoon-Clap-Purple2_%05i.png" rate="50" frames="20"/>
- <Clip name="Catch" files="Raccoon2/Catch-Green2/Raccoon-Catch-Green2_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Raccoon/Clap-Green2/Raccoon-Clap-Purple2_%05i.png" rate="50" frames="20"/>
+ <Clip name="Catch" files="Raccoon/Catch-Green2/Raccoon-Catch-Green2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Raccoon/Raccoon-Happy-Green/Raccoon-Happy-Green_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Raccoon/Raccoon-Jump-Green/Raccoon-Jump-Green_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Raccoon2/Shudder-Green2/Raccoon-Shudder-Green2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Raccoon/Shudder-Green2/Raccoon-Shudder-Green2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Raccoon/Raccoon-Shuffle-Green/Raccoon-Shuffle-Green_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Raccoon/Raccoon-StandDown-Green/Raccoon-StandDown-Green_%05i.png" rate="50" frames="20"/>
<Clip name="Walking" files="Raccoon/Raccoon-WalkLoop-Green/Raccoon-WalkLoop-Green_%05i.png" rate="50" start="20" frames="39"/>
diff --git a/vfg/bin/data/Raccoon-Purple.xml b/vfg/bin/data/Raccoon-Purple.xml index 7887a16..e4fc596 100755 --- a/vfg/bin/data/Raccoon-Purple.xml +++ b/vfg/bin/data/Raccoon-Purple.xml @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="ISO-8859-1"?>
<VFxmas> <Clip name="base" files="Raccoon/Raccoon-Purple.png" frames="1"/>
- <Clip name="Clap" files="Raccoon2/Clap-Purple2/Raccoon-Clap-Purple2_%05i.png" rate="50" frames="20"/>
- <Clip name="Catch" files="Raccoon2/Catch-Purple2/Raccoon-Catch-Purple2_%05i.png" rate="50" frames="34"/>
+ <Clip name="Clap" files="Raccoon/Clap-Purple2/Raccoon-Clap-Purple2_%05i.png" rate="50" frames="20"/>
+ <Clip name="Catch" files="Raccoon/Catch-Purple2/Raccoon-Catch-Purple2_%05i.png" rate="50" frames="34"/>
<Clip name="Happy" files="Raccoon/Raccoon-Happy-Purple/Raccoon-Happy-Purple_%05i.png" rate="50" frames="100"/>
<Clip name="Jump" files="Raccoon/Raccoon-Jump-Purple/Raccoon-Jump-Purple_%05i.png" rate="50" frames="49"/>
- <Clip name="Shudder" files="Raccoon2/Shudder-Purple2/Raccoon-Shudder-Purple2_%05i.png" rate="50" frames="30"/>
+ <Clip name="Shudder" files="Raccoon/Shudder-Purple2/Raccoon-Shudder-Purple2_%05i.png" rate="50" frames="30"/>
<Clip name="Shuffle" files="Raccoon/Raccoon-Shuffle-Purple/Raccoon-Shuffle-Purple_%05i.png" rate="50" frames="101"/>
<Clip name="Walk_start" files="Raccoon/Raccoon-StandDown-Purple/Raccoon-StandDown-Purple_%05i.png" rate="50" frames="20"/>
<Clip name="Walking" files="Raccoon/Raccoon-WalkLoop-Purple/Raccoon-WalkLoop-Purple_%05i.png" rate="50" start="20" frames="39"/>
diff --git a/vfg/src/Asterisk.cpp b/vfg/src/Asterisk.cpp index 98ffd9d..55a77e0 100755 --- a/vfg/src/Asterisk.cpp +++ b/vfg/src/Asterisk.cpp @@ -33,25 +33,28 @@ gameQ has 1 calls (max unlimited) in 'rrmemory' strategy (8s holdtime, 50s talkt void Asterisk::threadedFunction(){
- while( isThreadRunning() != 0 ){
- FILE *f = popen("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"queue show gameQ\"'", "re");
- int fn=fileno(f);
- char buf[1000];
- ssize_t r = read(fn, buf, 1000);
- pclose(f);
- string msg=string(buf);
- //received data is always a command ACKNOWLEDGEMENT
- if (msg.compare(0,5,"gameQ")==0) {
- vector<std::string> lines;
- split(msg,'\n',lines);
- queued=0;
- for (int i=4;i<lines.size();i++) {
- if (lines[i].compare(0,6," ")==0&&lines[i].compare(7,1,".")==0) queued++;
- }
- }
- else {
- printf("status err: %s\n",buf);
- }
+ while( isThreadRunning() != 0 ){ + //if (lock()) {
+ FILE *f = popen("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"queue show gameQ\"'", "re"); //e ??
+ int fn=fileno(f);
+ char buf[1000];
+ ssize_t r = read(fn, buf, 1000);
+ pclose(f);
+ string msg=string(buf);
+ //received data is always a command ACKNOWLEDGEMENT
+ if (msg.compare(0,5,"gameQ")==0) {
+ vector<std::string> lines;
+ split(msg,'\n',lines);
+ queued=0;
+ for (int i=4;i<lines.size();i++) {
+ if (lines[i].compare(0,6," ")==0&&lines[i].compare(7,1,".")==0) queued++;
+ }
+ }
+ else {
+ printf("status err: %s\n",buf);
+ } + //unlock(); + //}
ofSleepMillis(statusPollMillis);
}
@@ -64,42 +67,68 @@ void Asterisk::setup(string passcode,int millis){ cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME passcode "+passcode+"\"'");
state=ASTERISK_WAITING; //for acknowledge
statusPollMillis=millis;
- if (statusPollMillis>0) startThread(true, false); // blocking, verbose
+ if (statusPollMillis>0) startThread(false, false); // blocking, verbose
}
-void Asterisk::startGame(){
- if (state==ASTERISK_IDLE&&queued) {
- cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"devstate change Custom:GAME NOT_INUSE\"'");
- printf("Asterisk: attempting to dequeue\n");
- state=ASTERISK_WAITING;
- }
+void Asterisk::startGame(){ + //if (lock()) {
+ if (state==ASTERISK_IDLE&&queued) {
+ cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"devstate change Custom:GAME NOT_INUSE\"'");
+ printf("Asterisk: attempting to dequeue\n");
+ } + //unlock(); + //}
}
void Asterisk::endGame(string score){
printf("Asterisk: request hangup %s\n",playerCode.c_str());
if (state==ASTERISK_PLAYING) {
- cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME statuscode "+score+"\"'");
+ //cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"database put GAME statuscode "+score+"\"'");
string emsg="ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"hangup request "+playerCode+"\"'";
- cmd(emsg);
+ scmd(emsg);
printf("Asterisk: hanging up %s\n",playerCode.c_str());
state=ASTERISK_IDLE;
}
}
void Asterisk::cmd(string s) {
- //non blocking command for anync messages
- file = popen(s.c_str(), "re");
+ //non blocking command for anync messages + //pclose(file); always closing before open crashes + //printf("open file\n");
+ file = popen(s.c_str(), "re"); //"e" seems necessary for non blocking but with it getting crash when dequeuing. can't seem to trace it
filenum=fileno(file);
- fcntl(filenum, F_SETFL, O_NONBLOCK);
-}
+ fcntl(filenum, F_SETFL, O_NONBLOCK); + state=ASTERISK_WAITING;
+} + +void Asterisk::scmd(string s) {
+ //non blocking command for anync messages + //pclose(file); always closing before open crashes + //printf("open file\n");
+ file = popen(s.c_str(), "re"); //"e" seems necessary for non blocking but with it getting crash when dequeuing. can't seem to trace it
+ filenum=fileno(file);
+ fcntl(filenum, F_SETFL, O_NONBLOCK); + //printf("close file\n");
+ pclose(file);
+} + + +/*Child process PID: 4265 +Program received signal SIGABRT, Aborted. +In __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64 () +Cannot open file: /home/tim/workspace/VFxmas/vfg/iofclose.c +*/ +
int Asterisk::update(){
//capture stdin response from popen
- if (state==ASTERISK_WAITING||state==ASTERISK_STARTING) {
+ if (state==ASTERISK_WAITING) {
char buf[100];
ssize_t r = read(filenum, buf, 1000);
//if (r == -1 && errno == EAGAIN)
//no data yet
//else
- if (r > 0) {
+ if (r > 0) { + //is it here? + //printf("close file\n");
pclose(file);
string msg=string(buf);
state=ASTERISK_IDLE;
diff --git a/vfg/src/Asterisk.h b/vfg/src/Asterisk.h index 8093213..fb6097c 100755 --- a/vfg/src/Asterisk.h +++ b/vfg/src/Asterisk.h @@ -17,16 +17,16 @@ class Asterisk: public ofThread public:
Asterisk(){
}
-
+
void start(){
-
+
}
void stop(){
stopThread();
}
//--------------------------
-
+
void setup(string passcode="1111",int millis=1000);
virtual ~Asterisk();
void startGame();
@@ -36,7 +36,8 @@ class Asterisk: public ofThread int queued;
protected:
- void cmd(string s);
+ void cmd(string s); + void scmd(string s);
void threadedFunction();
private:
int startTime;
@@ -44,8 +45,9 @@ class Asterisk: public ofThread int filenum;
ofxUDPManager udpConnection;
string playerCode;
- int statusPollMillis;
-
+ int statusPollMillis; +
+
};
#endif // ASTERISK_H
diff --git a/vfg/src/Puppet.cpp b/vfg/src/Puppet.cpp index 90ba137..9d9a11e 100755 --- a/vfg/src/Puppet.cpp +++ b/vfg/src/Puppet.cpp @@ -36,38 +36,45 @@ void Puppet::load(string filename) { void Puppet::draw(float x, float y, float scale) {
if (playlist.size()>0) {
- if (!clips[playlist[0]].getIsPlaying()) {
- playlist.erase(playlist.begin());
- if (playlist.size()>0) {
- clips[playlist[0]].play();
+ if (!clips[playlist[0].second].getIsPlaying()) { + if (ofGetElapsedTimeMillis()-playlist[0].first>clips[playlist[0].second].getDuration()) { + playlist.erase(playlist.begin()); + }
+ if (playlist.size()>0) { + if (playlist[0].first<ofGetElapsedTimeMillis())
+ clips[playlist[0].second].play();
}
}
}
if (playlist.size()==0) {
if (clips.find("base") != clips.end()) clips["base"].draw(x,y,scale);
}
- else {
- clips[playlist[0]].update();
- clips[playlist[0]].draw(x,y,scale);
+ else if (clips[playlist[0].second].getIsPlaying()){
+ clips[playlist[0].second].update();
+ clips[playlist[0].second].draw(x,y,scale);
}
}
-void Puppet::play(string clip){
+void Puppet::play(string clip,int time){
if (clips.find(clip) != clips.end()) {
- playlist.push_back(clip);
- if (playlist.size()==1) clips[playlist[0]].play();
+ playlist.push_back(make_pair(time,clip));
+ if (playlist.size()==1&&time<ofGetElapsedTimeMillis()) clips[playlist[0].second].play();
//printf("playing %s, %i, %s\n",playlist[0].c_str(),playlist.size(),clips[playlist[0]].getIsPlaying()?"true":"false");
}
} -void Puppet::playNow(string clip){ +void Puppet::playNow(string clip,int time){ if (playlist.size()>0) { - clips[playlist[0]].stop(); + clips[playlist[0].second].stop(); playlist.clear(); } play(clip); }
bool Puppet::isPlaying(){
- if (playlist.size()>0) return clips[playlist[0]].getIsPlaying();
+ if (playlist.size()>0) return clips[playlist[0].second].getIsPlaying();
else return false;
} + +void Puppet::clear(){ + playlist.clear(); +} diff --git a/vfg/src/Puppet.h b/vfg/src/Puppet.h index 1f6d90a..d685a76 100755 --- a/vfg/src/Puppet.h +++ b/vfg/src/Puppet.h @@ -19,6 +19,9 @@ class puppetSprite: public ofxSprite { public:
void draw(float x, float y, float scale) {
getCurrentImage().draw(x-(anchorPoint.x*scale),y-(anchorPoint.y*scale),getWidth()*scale,getHeight()*scale);
+ } + int getDuration() { + return totalFrames*(1000/frameRate); }
};
@@ -28,14 +31,18 @@ class Puppet Puppet();
virtual ~Puppet();
void load(string filename);
- void play(string clip); - void playNow(string clip);
+ void play(string clip,int time=0); + void playNow(string clip,int time=0);
void draw(float x, float y, float scale=1.0f);
- bool isPlaying();
+ bool isPlaying(); + void clear();
protected:
private:
map<string,puppetSprite> clips;
- deque<string> playlist;
+ //deque<string> playlist; + deque< pair<int,string> > playlist; //time,clip = when it comes to play, pause until time, or just leave at 0 to play immediate + //time absolute + //need a clear method? should never be called really
};
#endif // PUPPET_H
diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp index c920a02..4cddab9 100755 --- a/vfg/src/music.cpp +++ b/vfg/src/music.cpp @@ -213,8 +213,8 @@ void musicscore::drawFlakes(float hOffs,levelscore *levels,float scale) { //else ofSetColor(ofColor::fromHsb(((float)thisnote*255)/numnotes,200,255));
//if (iter->second->activated&&(!iter->second->disintegrated)) iter->second->disintegrate();
+ //ofSetColor(255,255,255); //allow external fading
- ofSetColor(255,255,255);
iter->second->draw((gridX[notemap(iter->second->num)+1]*ofGetHeight())+hOffs,ofGetHeight()-(thisstart*heightStep),scale);
//todo - make all drawing resolution independent
@@ -269,7 +269,8 @@ song::song(string backfile,string melfile,string musfile,string lyricfile,string lyrics.load(lyricfile);
levels.load(levelfile);
isPlaying=false;
- isPractice=false;
+ isPractice=false; + fademillis=1000;
}
void song::setTimeframe(int millis) {notes.setTimeframe(millis);}
void song::setKeyThresh(int millis) {notes.keyThresh=millis;}
@@ -286,7 +287,8 @@ void song::play() { void song::stop() {
backing.stop();
melody.stop();
- isPlaying=false;
+ isPlaying=false; + printf("stoppping song: %i (%i)\n",ofGetElapsedTimeMillis()-startTime,levels.length);
}
void song::preRoll(long preroll) {
startTime=ofGetElapsedTimeMillis()+preroll;
@@ -318,12 +320,18 @@ int song::getLength(){ } bool song::isGameover(){ return gameover; +} +void song::gameOver(){ +
+ gameover=true; + gameoverTime=ofGetElapsedTimeMillis(); }
bool song::isFinished(){
return (ofGetElapsedTimeMillis()-startTime>=levels.length);
}
void song::draw(float hOffs,float scale){
- int songTime=ofGetElapsedTimeMillis()-startTime;
+ int songTime=ofGetElapsedTimeMillis()-startTime; + int fadeout=(gameover?max(0,255-((int)((((float)ofGetElapsedTimeMillis()-gameoverTime)/fademillis)*255))):255);
if (isPlaying) {
if (isPreroll&&(!isPractice)) {
if (startTime<ofGetElapsedTimeMillis()) {
@@ -331,29 +339,36 @@ void song::draw(float hOffs,float scale){ melody.play();
isPreroll=false;
}
- }
+ } + ofSetColor(255,255,255,fadeout);
notes.drawFlakes(hOffs,&levels,scale);
if (notes.missedLast) {
melody.setVolume(0.0f);
if (levels.getLives(songTime)) {
- if (notes.missedFlakes>levels.getLives(songTime)) {
+ if (notes.missedFlakes>levels.getLives(songTime)&&!gameover) {
//work out score
- //stop();
- gameover=true;
+ //stop(); + printf("game over! %i (%i)\n",songTime,levels.length); + gameOver();
}
}
}
- else melody.setVolume(1.0f); - if (!isPractice) lyrics.draw(hOffs);
- if (songTime>levels.length) {
- printf("stopping: %i (%i)\n",songTime,levels.length);
+ if (!notes.missedLast&&!gameover) melody.setVolume(1.0f); + if (!isPractice&&!gameover) lyrics.draw(hOffs);
+ if (songTime>levels.length&&!gameover) {
+ printf("finished! %i (%i)\n",songTime,levels.length); + //this played loads of times
//stop();
- gameover=true;
- }
- }
- else {
- //fade out song + melody :: clean up
+ gameOver(); + } + ofSetColor(255,255,255); + if (gameover) { + melody.setVolume(notes.missedLast?0.0f:((float)fadeout)/255.0f); + backing.setVolume(((float)fadeout)/255.0f); + if (fadeout==0) stop(); + }
}
+
}
void song::playerControl(int key){
notes.playerControl(key);
diff --git a/vfg/src/music.h b/vfg/src/music.h index 60a35f2..c4a26ca 100755 --- a/vfg/src/music.h +++ b/vfg/src/music.h @@ -210,7 +210,8 @@ class song { string getScoreString(); string getName(); int getLength(); - bool isGameover();
+ bool isGameover(); + void gameOver();
bool isFinished();
bool gameover;
@@ -221,10 +222,10 @@ class song { lyricscore lyrics;
levelscore levels;
- int startTime;
+ int startTime,gameoverTime;
bool isPreroll,isPractice;
- int fThreshStart,fThreshEnd;
+ int fThreshStart,fThreshEnd,fademillis;
};
//---------------------------------------------------------------------------------------------------------------------------------------------
/*
diff --git a/vfg/src/testApp.cpp b/vfg/src/testApp.cpp index 8c701b2..3e711f2 100755 --- a/vfg/src/testApp.cpp +++ b/vfg/src/testApp.cpp @@ -16,11 +16,23 @@ void guiWindow::draw(){ parent->gui.draw(); ofSetColor(255,255,255); ofDrawBitmapString(ofToString(parent->game.queued)+" in queue", 10,ofGetHeight()-15); - char buf[8]; + char buf[200]; sprintf(buf,"%.1f",ofGetFrameRate()); ofDrawBitmapString(buf, ofGetWidth()-43,ofGetHeight()-15); ofDrawBitmapString(levelnames[parent->gamestate-1], 10,ofGetHeight()-35); - if (parent->gamestate==GAME_PLAYING) ofDrawBitmapString(parent->songs[parent->currentsong]->getScoreString(),10,ofGetHeight()-55); + switch (parent->gamestate) { + case GAME_PLAYING: + ofDrawBitmapString(parent->songs[parent->currentsong]->getScoreString(),10,ofGetHeight()-55); + break; + case GAME_INTRO: + sprintf(buf,"%f %i of %i",parent->intro.getPosition(),parent->intro.getCurrentFrame(),parent->intro.getTotalNumFrames()); + ofDrawBitmapString(buf,10,ofGetHeight()-55); + break; + case GAME_ADVERT: + sprintf(buf,"%f %i of %i",parent->advert.getPosition(),parent->advert.getCurrentFrame(),parent->advert.getTotalNumFrames()); + ofDrawBitmapString(buf,10,ofGetHeight()-55); + break; + } } void guiWindow::dragEvent(ofDragInfo dragInfo, ofxFenster* win){ @@ -35,6 +47,9 @@ void testApp::setup(){ game.setup("1122",2000); //Asterisk.cpp thread polls server every 2000ms +//songs.push_back(new song("WeWishYouAMerryChistmas_v.2.1/VODA_MUS_WEWISHU_Backing_v.2.1.mp3","WeWishYouAMerryChistmas_v.2.1/VODA_MUS_WEWISHU_Lead_v.2.1.mp3","VODA_MUS_WEWISHU_Midi_v.2.2.xml","Lyrics_WeWishYou.2.1.xml","Levels_test.xml")); + + songs.push_back(new song("SilentNight/VODA_SilentNight_Backing_v.1.1.1.mp3","SilentNight/VODA_SilentNight_Melody_v.1.1.1.mp3","VODA_SilentNight_Midi_v.1.1.1.xml","Lyrics_WeWishYou.2.1.xml","Levels_WeWishYou.2.1.xml")); songs.push_back(new song("WeWishYouAMerryChistmas_v.2.1/VODA_MUS_WEWISHU_Backing_v.2.1.mp3","WeWishYouAMerryChistmas_v.2.1/VODA_MUS_WEWISHU_Lead_v.2.1.mp3","VODA_MUS_WEWISHU_Midi_v.2.2.xml","Lyrics_WeWishYou.2.1.xml","Levels_WeWishYou.2.1.xml")); songs.push_back(new song("DeckTheHalls_v.4.0/VODA_MUS_DeckTheHalls-Backing_v.4.0.mp3","DeckTheHalls_v.4.0/VODA_MUS_DeckTheHalls-Lead_v.4.0.mp3","VODA_MIDI_DeckTheHalls-v.4.0.xml","Lyrics_DeckTheHalls.4.0.xml","Levels_DeckTheHalls.4.0.xml")); songs.push_back(new song("DingDong.v.2.2/VODA_MUS_DingDong_Backing_v.2.2.mp3","DingDong.v.2.2/VODA_MUS_DingDong_Melody_v.2.2.mp3","VODA_MIDI_DingDong_v.2.2.xml","Lyrics_DingDong.2.2.xml","Levels_DingDong.2.2.xml")); @@ -74,7 +89,7 @@ void testApp::setup(){ lyricspanel=new Billboard("Lyrics-panel.png",0.5,0.703); - banner.load("Ribbon/Dublin/Ribbon-Dublin_%05i.png",500); + banner.load("Ribbon/Dublin/Ribbon_%05i.png",500); banner.setAnchorPercent(0.5,0.0); banner.setFrameRate(50); banner.play(); @@ -98,11 +113,11 @@ void testApp::setup(){ //mount -t tmpfs -o size=64M tmpfs /RAM //cp *.m* RAM - intro.loadMovie("RAM/Game-Demo_v5.mp4"); + intro.loadMovie("RAM/Game-Demo_v6_DUBLIN.mp4"); intro.setLoopState(OF_LOOP_NONE); intro.setVolume(0.0); - advert.loadMovie("RAM/GW2003761_GRY-VFBR055-060_MPEG_hi.mov"); + advert.loadMovie("RAM/VFxmasAD.mov"); advert.setLoopState(OF_LOOP_NONE); advert.setVolume(1.0); @@ -182,6 +197,8 @@ void testApp::update(){ activatePractice(); } else if (ret==ASTERISK_GAMEOVER) { + printf("player hung up!\n"); + songs[currentsong]->gameOver(); endGame(); } else if (ret>48&&ret<52) { @@ -212,6 +229,7 @@ void testApp::update(){ case GAME_ENDPLAYING: case GAME_ENDINGINTRO: case GAME_PRACTICE: + case GAME_WALKON: background.update(); banner.update(); wirebirds.update(); @@ -259,7 +277,7 @@ void testApp::draw(){ float hOffs=(ofGetWidth()-ofGetHeight())/2; float scale=ofGetHeight()/1080.0f; float bannerscale,aspect,wOffs,seg; //this old chestnut - float segamt=((float)(ofGetElapsedTimeMillis()-segmentStartTime)*2.0f)/fadelength; //same variable used in all segments + float segamt=min(1.0f,((float)(ofGetElapsedTimeMillis()-segmentStartTime)*2.0f)/fadelength); //same variable used in all segments int hit,missed; switch(gamestate) { case GAME_STARTINGINTRO: @@ -282,9 +300,6 @@ void testApp::draw(){ case GAME_INTRO: case GAME_ENDINGINTRO: intro.draw(hOffs,0,ofGetHeight(),ofGetHeight()); - if (intro.getCurrentFrame()==intro.getTotalNumFrames()) { - gamestate=GAME_READY; - } break; case GAME_READY: case GAME_STARTPLAYING: @@ -301,9 +316,6 @@ void testApp::draw(){ drawBackgroundLayers(); break; } - else if (segamt>1.0) { - gamestate=GAME_ADVERT; - } else { //if (!advert.isPlaying()) advert.play(); ofEnableAlphaBlending(); @@ -388,21 +400,21 @@ void testApp::draw(){ //penguin: 11,35,11 //raccoon: 20,39,43r ofEnableAlphaBlending(); - seg=((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001; + seg=(((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001)/6; wOffs=hOffs+(0.7*ofGetWidth()*seg); for (int i=0;i<3;i++) (*playanimal)[i].draw(wOffs+(gridX[i+1]*ofGetHeight()),gridY[0]*ofGetHeight(),scale); - songs[currentsong]->draw(hOffs,scale);//allows the song to fade its volume out and stop playing + songs[currentsong]->draw(hOffs,scale);//allows the song to fade its volume out and stop playing, last notes to play out break; case GAME_WALKON: - ofEnableAlphaBlending(); - seg=((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001; - wOffs=hOffs+(0.7*ofGetWidth()*(1.0f-seg)); - for (int i=0;i<3;i++) (*playanimal)[i].draw(wOffs+(gridX[i+1]*ofGetHeight()),gridY[0]*ofGetHeight(),scale); - break; - } - - - //draw tags and logos + ofEnableAlphaBlending(); + seg=(((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001)/6; + wOffs=hOffs-(0.7*ofGetWidth()*(1.0f-seg)); + for (int i=0;i<3;i++) (*playanimal)[i].draw(wOffs+(gridX[i+1]*ofGetHeight()),gridY[0]*ofGetHeight(),scale); + break; + } + + + //draw tags and VF logo switch(gamestate) { case GAME_STARTINGADVERT: if (segamt<0.5) { @@ -429,7 +441,7 @@ void testApp::draw(){ } logos[0]->draw((gridX[0]*ofGetHeight())+hOffs,0,scale); break; - } + } //draw banner, DCC logo and wirebirds bannerscale=scale; ofSetColor(255,255,255); @@ -460,12 +472,16 @@ void testApp::draw(){ break; case GAME_STARTPLAYING: case GAME_PLAYING: - if (showWire) wirebirds.draw(ofGetWidth()/2,ofGetHeight()*birdpoint,scale); + if (showWire) wirebirds.draw(ofGetWidth()/2,ofGetHeight()*birdpoint,scale); bannerscale=scale*0.675; ofEnableAlphaBlending(); banner.draw(ofGetWidth()*0.5,0,bannerscale); break; case GAME_ENDPLAYING: + bannerscale=scale*0.675; + ofEnableAlphaBlending(); + banner.draw(ofGetWidth()*0.5,0,bannerscale); + break; case GAME_WALKON: //DCC LOGO logos[1]->draw((gridX[0]*ofGetHeight())+hOffs,gridY[1]*ofGetHeight(),scale); @@ -479,18 +495,27 @@ void testApp::draw(){ case GAME_STARTINGINTRO: case GAME_INTRO: case GAME_ENDINGINTRO: + if (intro.getCurrentFrame()==intro.getTotalNumFrames()-1) { + gamestate=GAME_READY; + } + break; case GAME_READY: break; case GAME_STARTINGADVERT: backgroundmusic.setVolume(max(0.0,1.0-(segamt*2.0))); + if (segamt==1.0) { + gamestate=GAME_ADVERT; + } case GAME_ADVERT: - if (advert.getCurrentFrame()==advert.getTotalNumFrames()&&gamestate==GAME_ADVERT) { + if (advert.getCurrentFrame()==advert.getTotalNumFrames()-1) { gamestate=GAME_ENDINGADVERT; segmentStartTime=ofGetElapsedTimeMillis(); } break; case GAME_ENDINGADVERT: backgroundmusic.setVolume(max(0.0,(segamt-0.5)*2.0)); + if (segamt==1.0) gamestate=GAME_READY; + break; case GAME_STARTPLAYING: case GAME_PRACTICE: break; @@ -501,17 +526,41 @@ void testApp::draw(){ } break; case GAME_ENDPLAYING: - backgroundmusic.setVolume(max(0.0,(segamt-0.5)*2.0)); - if (((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001>6.0) { + if ((((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001)>6.0) { gamestate=GAME_WALKON; + segmentStartTime=ofGetElapsedTimeMillis(); switchAnimals(); + //work out offet and schedule transition to finish at the end of 6 seconds + //6 seconds to walk in / out -> 12 seconds turnaround + //frames to start/cycle/stop walking + //penguin: 11,35,11 + //raccoon: 20,39,43 + + //penguins: 8 cycles + end = 291, diff 180ms (+ 1 frame per cycle? 0ms) + //raccoons: 6 cycles + end = diff 230ms (+1 fr/cyc? 90ms) + for (int i=0;i<3;i++) { + (*playanimal)[i].clear(); + int numcycles,start; + if (playanimal==&penguins) { + start=400; //(of 700 cycle) + numcycles=7; + } + else { + start=400; //of 780 + numcycles=5; + } + (*playanimal)[i].play("Walking",ofGetElapsedTimeMillis()+start); + for (int j=0;j<numcycles;j++) (*playanimal)[i].play("Walking"); + (*playanimal)[i].play("Walk_end"); + } } break; case GAME_WALKON: + backgroundmusic.setVolume(max(0.0,(segamt-0.5)*2.0)); if (((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.001>6.0) { gamestate=GAME_READY; segmentStartTime=ofGetElapsedTimeMillis(); - } + } break; } } @@ -573,7 +622,8 @@ void testApp::endGame(){ //penguins: start + 289 = 8.25 //raccoons: start + 280 = 7.17 for (int i=0;i<3;i++) { - (*playanimal)[i].play("Walk_start"); + + (*playanimal)[i].playNow("Walk_start"); for (int j=0;j<9;j++) (*playanimal)[i].play("Walking"); } } diff --git a/vfg/src/testApp.h b/vfg/src/testApp.h index 4b369bf..82b25a5 100755 --- a/vfg/src/testApp.h +++ b/vfg/src/testApp.h @@ -34,6 +34,8 @@ break clap movements practice mode ramdisk for movies +the 2nd time you play , if you 'die' it doesn't trigger 'end of game', the music keeps playing and the tags keep coming up even when state is 'ready' + */ #define GAME_STARTINGINTRO 1 diff --git a/vfg/vfg.layout b/vfg/vfg.layout index 06595b0..c534f02 100644 --- a/vfg/vfg.layout +++ b/vfg/vfg.layout @@ -1,20 +1,20 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_layout_file> <ActiveTarget name="Debug" /> - <File name="addons.make" open="1" top="0" tabpos="2"> + <File name="addons.make" open="1" top="0" tabpos="1"> <Cursor position="80" topLine="0" /> </File> - <File name="src/Asterisk.cpp" open="1" top="0" tabpos="5"> + <File name="src/Asterisk.cpp" open="1" top="0" tabpos="4"> <Cursor position="484" topLine="21" /> </File> <File name="src/Asterisk.h" open="0" top="0" tabpos="3"> <Cursor position="106" topLine="23" /> </File> - <File name="src/Puppet.cpp" open="1" top="0" tabpos="1"> - <Cursor position="502" topLine="0" /> + <File name="src/Puppet.cpp" open="1" top="1" tabpos="8"> + <Cursor position="1376" topLine="28" /> </File> - <File name="src/Puppet.h" open="1" top="0" tabpos="6"> - <Cursor position="312" topLine="7" /> + <File name="src/Puppet.h" open="1" top="0" tabpos="7"> + <Cursor position="789" topLine="14" /> </File> <File name="src/Tag.h" open="0" top="0" tabpos="5"> <Cursor position="551" topLine="0" /> @@ -22,16 +22,16 @@ <File name="src/main.cpp" open="0" top="0" tabpos="1"> <Cursor position="219" topLine="0" /> </File> - <File name="src/music.cpp" open="0" top="0" tabpos="5"> - <Cursor position="10158" topLine="241" /> + <File name="src/music.cpp" open="1" top="0" tabpos="6"> + <Cursor position="10249" topLine="255" /> </File> - <File name="src/music.h" open="1" top="0" tabpos="8"> - <Cursor position="4738" topLine="0" /> + <File name="src/music.h" open="1" top="0" tabpos="5"> + <Cursor position="6912" topLine="197" /> </File> - <File name="src/testApp.cpp" open="1" top="1" tabpos="4"> - <Cursor position="15897" topLine="484" /> + <File name="src/testApp.cpp" open="1" top="0" tabpos="3"> + <Cursor position="8311" topLine="218" /> </File> - <File name="src/testApp.h" open="1" top="0" tabpos="3"> + <File name="src/testApp.h" open="1" top="0" tabpos="2"> <Cursor position="1353" topLine="23" /> </File> </CodeBlocks_layout_file> |
