summaryrefslogtreecommitdiff
path: root/vfg/src
diff options
context:
space:
mode:
Diffstat (limited to 'vfg/src')
-rwxr-xr-xvfg/src/Asterisk.cpp86
-rwxr-xr-xvfg/src/Asterisk.h22
-rwxr-xr-xvfg/src/music.cpp9
-rwxr-xr-xvfg/src/testApp.cpp35
-rwxr-xr-xvfg/src/testApp.h24
5 files changed, 102 insertions, 74 deletions
diff --git a/vfg/src/Asterisk.cpp b/vfg/src/Asterisk.cpp
index 12b3d92..b78678e 100755
--- a/vfg/src/Asterisk.cpp
+++ b/vfg/src/Asterisk.cpp
@@ -14,17 +14,58 @@ std::vector<std::string> &split(const std::string &s, char delim, std::vector<st
}
-Asterisk::Asterisk()
+Asterisk::~Asterisk()
{
+ stopThread();
+ pclose(file);
+}
+
+/*
+Use a thread to track status with a blocking popen()
+
+
+gameQ has 1 calls (max unlimited) in 'rrmemory' strategy (8s holdtime, 50s talktime), W:0, C:38, A:26, SL:36.8% within 0s
+ Members:
+ Game AGI (Local/9999@default) with penalty 1 (In use) has taken 31 calls (last was 5333 secs ago)
+ Callers:
+ 1. SIP/sip_proxy-00000045 (wait: 0:06, prio: 0)
+*/
+
+
+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);
+ }
+
+ ofSleepMillis(statusPollMillis);
+ }
}
-void Asterisk::setup(string passcode){
+void Asterisk::setup(string passcode,int millis){
udpConnection.Create();
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;
+ statusPollMillis=millis;
+ if (statusPollMillis>0) startThread(true, false); // blocking, verbose
}
void Asterisk::startGame(){
if (!isPlaying&&queued) {
@@ -45,57 +86,39 @@ void Asterisk::endGame(string score){
}
}
void Asterisk::cmd(string s) {
+ //non blocking command for anync messages
file = popen(s.c_str(), "re");
filenum=fileno(file);
- fcntl(filenum, F_SETFL, O_NONBLOCK);
-}
-
-/*
-gameQ has 1 calls (max unlimited) in 'rrmemory' strategy (8s holdtime, 50s talktime), W:0, C:38, A:26, SL:36.8% within 0s
- Members:
- Game AGI (Local/9999@default) with penalty 1 (In use) has taken 31 calls (last was 5333 secs ago)
- Callers:
- 1. SIP/sip_proxy-00000045 (wait: 0:06, prio: 0)
-*/
-
-void Asterisk::requestStatus(){
- cmd("ssh 80.93.22.22 'sudo /usr/sbin/asterisk -rx \"queue show gameQ\"'");
- state=WAITING;
+ fcntl(filenum, F_SETFL, O_NONBLOCK);
}
int Asterisk::update(){
//capture stdin response from popen
- if (state==WAITING||state==STARTING||state==IDLE) {
- char buf[1000];
+ if (state==WAITING||state==STARTING) {
+ char buf[100];
ssize_t r = read(filenum, buf, 1000);
//if (r == -1 && errno == EAGAIN)
//no data yet
- //else
+ //else
if (r > 0) {
pclose(file);
string msg=string(buf);
state=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;
}
- else 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("stdin says: %s\n",buf);
-
+
}
}
}
-
+
//check udp messages, return new keypresses
char udpMessage[10000];
udpConnection.Receive(udpMessage,10000);
@@ -119,8 +142,3 @@ int Asterisk::update(){
else return 0;
}
-Asterisk::~Asterisk()
-{
- pclose(file);
- //dtor
-}
diff --git a/vfg/src/Asterisk.h b/vfg/src/Asterisk.h
index 0640c4b..5033a5c 100755
--- a/vfg/src/Asterisk.h
+++ b/vfg/src/Asterisk.h
@@ -10,28 +10,40 @@
#define PLAYING 3
-class Asterisk
+class Asterisk: public ofThread
{
public:
- Asterisk();
- void setup(string passcode="1111");
+ Asterisk(){
+ }
+
+ void start(){
+
+ }
+ void stop(){
+ stopThread();
+ }
+
+ //--------------------------
+
+ void setup(string passcode="1111",int millis=1000);
virtual ~Asterisk();
void startGame();
void endGame(string score);
int update();
- void requestStatus();
int state;
bool isPlaying;
int queued;
protected:
- void cmd(string s);
+ void cmd(string s);
+ void threadedFunction();
private:
int startTime;
FILE *file;
int filenum;
ofxUDPManager udpConnection;
string playerCode;
+ int statusPollMillis;
};
diff --git a/vfg/src/music.cpp b/vfg/src/music.cpp
index 8f3b767..e715892 100755
--- a/vfg/src/music.cpp
+++ b/vfg/src/music.cpp
@@ -4,7 +4,7 @@
int notemap(int n) {
//nonlinear mapping of notes to 3 columns - space 5,4,7 - trying 5,5,6
- //note drawing 46h - 52h
+ //note drawing 46h - 52h
int numnotes=16;
int firstnote=70;
int note=n-firstnote;
@@ -153,8 +153,9 @@ void musicscore::makeFlakes(int threshStart,int threshEnd,levelscore *levels){
flakes[notes.begin()->first]=new flake(notes.begin()->second->num,notes.begin()->second->velocity,notes.begin()->second->duration);
flakes[notes.begin()->first]->puppet=snowflakes[notemap(lastNote->num)];
for (iter = notes.begin(); iter != notes.end(); iter++) {
- float songPos=((float)iter->first)/songDuration;
- if ((levels->nextLevelTime(iter->first)>2000)&&((notemap(iter->second->num)!=notemap(lastNote->num))||(iter->first-lastTime>((songPos*threshEnd)+((1.0f-songPos)*threshStart))))) {
+ float songPos=((float)iter->first)/songDuration;
+ //((notemap(iter->second->num)!=notemap(lastNote->num))||
+ if ((levels->nextLevelTime(iter->first)>2000)&&(iter->first-lastTime>((songPos*threshEnd)+((1.0f-songPos)*threshStart)))) {
flakes[iter->first]=new flake(iter->second->num,iter->second->velocity,iter->second->duration);
flakes[iter->first]->puppet=snowflakes[notemap(iter->second->num)];
lastNote=iter->second;
@@ -235,7 +236,7 @@ void musicscore::drawFlakes(float hOffs,levelscore *levels,float scale) {
missedLast=!iter->second->activated;
}
//at this point missed points to the latest unactivated flake in the level if there is one or else flakes.end()
-
+
if ((missed!=flakes.end())&&(missedFlake!=missed)) {
missedFlake=missed;
missedNote=notemap(missed->second->num);
diff --git a/vfg/src/testApp.cpp b/vfg/src/testApp.cpp
index 7c596d0..986673c 100755
--- a/vfg/src/testApp.cpp
+++ b/vfg/src/testApp.cpp
@@ -32,9 +32,8 @@ void guiWindow::windowMoved(int x,int y){
//----------------------------------------------------------------------
void testApp::setup(){
-
- game.setup("1122");
- gamepoll=0;
+
+ 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_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"));
@@ -52,7 +51,7 @@ void testApp::setup(){
penguins[1].load("Penguin-Purple.xml");
penguins[2].load("Penguin-Green.xml");
-
+
// temp save time
for (int i=0;i<3;i++) raccoons.push_back(Animal());
raccoons[0].load("Raccoon-Blue.xml");
@@ -65,7 +64,7 @@ void testApp::setup(){
tags.push_back(new Tag("Tags/TAG_Level-2.png",3000,0.5,0));
tags.push_back(new Tag("Tags/TAG_Level-3.png",3000,0.5,0));
tags.push_back(new Tag("Tags/TAG_Level-4.png",3000,0.5,0));
- tags.push_back(new Tag("Tags/PreGame-Practice.png",3000,0.5,0));
+ tags.push_back(new Tag("Tags/PreGame-Practice.png",6000,0.5,0.16667));
tags.push_back(new Tag("Tags/Game-Over.png",3000,0.5,0));
tags.push_back(new Tag("Tags/Thanks-NEW.png",3000,0.5,0));
@@ -79,7 +78,7 @@ void testApp::setup(){
banner.setAnchorPercent(0.5,0.0);
banner.setFrameRate(50);
banner.play();
-
+
wirebirds.load("Birds-with-Wire/Birds-with-Wire_%05i.png",125);
wirebirds.setAnchorPercent(0.5,0.5);
wirebirds.setFrameRate(50);
@@ -94,7 +93,7 @@ void testApp::setup(){
//release: commented out: 436m 256m
//508fr 1.4s load in use: 836m 443m
-
+
//cd /home/tim/workspace/VFxmas/vfg/bin/data
//mount -t tmpfs -o size=64M tmpfs /RAM
//cp *.m* RAM
@@ -110,7 +109,7 @@ void testApp::setup(){
background.loadMovie("RAM/Background_v3.mp4");
background.setLoopState(OF_LOOP_NORMAL);
background.play();
-
+
backgroundmusic.loadSound("VODA_MUS_Pre-Game-Music_v.1.1.mp3");
backgroundmusic.setLoop(true);
backgroundmusic.play();
@@ -139,6 +138,7 @@ void testApp::setup(){
gui.add(ts.setup("timescale",timescale,0,10000,255));
keyThresh=1500;
gui.add(kT.setup("keythresh",keyThresh,0,4000,255));
+ gui.add(showWire.setup("birdwire",true));
ofxFenster* win=ofxFensterManager::get()->createFenster(0, 0, 200, 400, OF_WINDOW);
win->setWindowTitle("config");
@@ -176,10 +176,6 @@ void testApp::exit(){
//--------------------------------------------------------------
void testApp::update(){
int ret=game.update();
- if (ofGetElapsedTimeMillis()-gamepoll>5000) {
- game.requestStatus();
- gamepoll=ofGetElapsedTimeMillis();
- }
if (ret==1000) {
activatePractice();
}
@@ -262,7 +258,7 @@ void testApp::draw(){
float scale=ofGetHeight()/1080.0f;
float bannerscale,aspect,wOffs; //this old chestnut
float segamt=((float)(ofGetElapsedTimeMillis()-segmentStartTime)*2.0f)/fadelength; //same variable used in all segments
-
+
switch(gamestate) {
case GAME_STARTINGINTRO:
case GAME_INTRO:
@@ -335,11 +331,11 @@ void testApp::draw(){
wOffs=(ofGetHeight()-(ofGetWidth()*aspect))*0.5;
advert.draw(0,wOffs,ofGetWidth(),ofGetWidth()*aspect);
ofDisableAlphaBlending(); //may have been turned on during intro
-
+
break;
-
+
}
-
+
//draw game action
switch(gamestate) {
case GAME_STARTINGADVERT:
@@ -376,7 +372,7 @@ void testApp::draw(){
if (missed>-1) (*playanimal)[missed].playNow("Shudder");
int hit=practiceSong.hitNote();
if (hit>-1) (*playanimal)[hit].play("Catch");
-
+
}
for (int i=0;i<3;i++) (*playanimal)[i].draw(hOffs+(gridX[i+1]*ofGetHeight()),gridY[0]*ofGetHeight(),scale);
if (songs[currentsong]->isPlaying) {
@@ -423,7 +419,7 @@ void testApp::draw(){
case GAME_PRACTICE:
ofEnableAlphaBlending();
bannerscale=scale*(1.0f-(max(0.0,min(((float)(ofGetElapsedTimeMillis()-segmentStartTime))*.002,1.0))*0.325));
- wirebirds.draw(ofGetWidth()/2,ofGetHeight()*0.65,scale);
+ wirebirds.draw(ofGetWidth()/2,ofGetHeight()*0.6,scale);
segamt=1.0;
ofEnableAlphaBlending();
banner.draw(ofGetWidth()*0.5,0,bannerscale);
@@ -446,6 +442,7 @@ void testApp::draw(){
break;
case GAME_STARTPLAYING:
case GAME_PLAYING:
+ if (showWire) wirebirds.draw(ofGetWidth()/2,ofGetHeight()*0.6,scale);
bannerscale=scale*0.675;
ofEnableAlphaBlending();
banner.draw(ofGetWidth()*0.5,0,bannerscale);
@@ -530,7 +527,7 @@ void testApp::activatePractice(){
practiceSong.setTimeframe(timescale);
practiceSong.setFlakeThresh(threshStart,threshEnd);
practiceSong.setKeyThresh(keyThresh);
- practiceSong.play();
+ practiceSong.preRoll(5000);
tags[5]->play();
}
void testApp::switchAnimals(){
diff --git a/vfg/src/testApp.h b/vfg/src/testApp.h
index 4852073..d4a9627 100755
--- a/vfg/src/testApp.h
+++ b/vfg/src/testApp.h
@@ -71,12 +71,12 @@ class testApp : public ofxFensterListener{
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
-
+
void drawBackgroundLayers();
void activateGame();
void activatePractice();
void switchAnimals();
-
+
ofVideoPlayer intro;
ofVideoPlayer advert;
ofSoundPlayer backgroundmusic;
@@ -87,38 +87,37 @@ class testApp : public ofxFensterListener{
vector<song*> songs;
song practiceSong;
-
+
vector<Animal> penguins;
vector<Animal> raccoons;
-
+
//vector<vector<Animal> > animals;
-
+
//vector<Animal> playanimals;
vector<Animal>* playanimal;
vector<Tag*> tags;
-
+
vector<Billboard*> logos;
-
+
puppetSprite banner;
puppetSprite wirebirds;
-
+
Billboard* lyricspanel;
Puppet testpenguin;
int currentlevel;
Asterisk game;
- int gamepoll;
bool showFPS;
bool showVis;
bool fullscreenoutput;
-
+
int currentsong,nextsong,gamestate,segmentStartTime;
-
+
float fadelength;
-
+
guiWindow *guiWin;
ofxPanel gui;
ofxIntSlider tS;
@@ -129,6 +128,7 @@ class testApp : public ofxFensterListener{
ofxParameter<int> timescale;
ofxIntSlider kT;
ofxParameter<int> keyThresh;
+ ofxToggle showWire;
};