// extended event class ballEvent extends Event { int newball; string type; int owner; int id; float x; float y; float z; int target; int bounce; int explode; } // declare constants 8 => int SPEAKERCOUNT; 32 => int CLIENTCOUNT; 1000 => int PROJECTILECOUNT; 2 => int LISTENERCOUNT; "plasma" => string PLASMA; "bfg" => string BFG; "rocket" => string ROCKET; "chaingun" => string CHAINGUN; JCRev gReverbfromjohnchowning => dac; .5 => gReverbfromjohnchowning.gain; .075 => gReverbfromjohnchowning.mix; // declare "global" vars int gClients; int gProjectiles; // fake enumerated type (better way?) ["plasma", "bfg", "rocket", "chaingun"] @=> string PTYPES[]; // array declarations float worldcoordinates[3]; //Client clients[CLIENTCOUNT]; //Projectile projectiles[PROJECTILECOUNT]; // OSC // create our OSC receiver OscRecv recv; 6662 => recv.port; recv.listen(); recv.event( "/projectile, s i i f f f i i i" ) @=> OscEvent oeProjectile; string type; int owner; int id; float X; float Y; float Z; int target; int bounce; int explode; int projectiles[PROJECTILECOUNT]; int temp; 0=>int inc; // Client methods fun int addCLient(int id) { // mark client position in array active gClients++; return 0; } fun int removeClient(int id){ // mark client position in array inactive gClients--; return 0; } // method to listen to broadcast OSC messages for a given ball id //--------------------------------------------------------------- fun void ball(ballEvent e) { SinOsc s => ADSR bob => gReverbfromjohnchowning; 0 =>s.gain; bob.set(10::ms, 5::ms, .5, 200::ms); e.id => int id; while ( true ) { // wait on event e e => now; if(e.id != id) continue; // listen if (e.explode == 1) { // if explode message, kill sound <<<"explode: ball_num = ", e.id>>>; // let decay 3::second => now; break; } if (e.bounce == 1) { // if bounce, play bounce sound <<<"bounce: ball_num = ", e.id>>>; // note number 20 => float note; .5 =>s.gain; bob.keyOn(); // convert MIDI note to hz //Std.mtof( note ) => s.freq; e.x => s.freq; // advance time 15::ms => now; bob.keyOff(); } } bob =< gReverbfromjohnchowning; } ballEvent e; while ( true ) { oeProjectile => now; while ( oeProjectile.nextMsg() != 0 ) { <<< "type:", oeProjectile.getString()>>>; oeProjectile.getString() => type => e.type; oeProjectile.getInt() => owner => e.owner; oeProjectile.getInt() => id => e.id; oeProjectile.getFloat() => X =>e.x; oeProjectile.getFloat() => Y => e.y; oeProjectile.getFloat() => Z =>e.z; oeProjectile.getInt() => target => e.target; oeProjectile.getInt() => bounce => e.bounce; oeProjectile.getInt() => explode => e.explode; if(explode==1){ 0 => projectiles[id]; inc--; <<<"removed projectile: ", id, " - size: ", inc >>>; <<<"value at: ", id, " = ", projectiles[id]>>>; } if(projectiles[id]==0) { 1 => projectiles[id]; inc++; <<<"added projectile: ", id, " - size: ", inc >>>; <<<"value at: ", id, " = ", projectiles[id]>>>; 1 => e.newball; spork ~ ball( e ); me.yield(); } else { -1 => e.newball; // e.signal(); } e.broadcast(); } }