Region* Palette::NewRegionNamed(std::string nm, int sid_low, int sid_high) { Region* r = newRegionNamed(nm); NosuchAssert(r); r->setTypeAndSid(Region::SURFACE,sid_low,sid_high); return r; }
void Outlines_SharedMemHeader::check_sanity() { int nused = 0; if (buff_inuse[0]) nused++; if (buff_inuse[1]) nused++; if (buff_inuse[2]) nused++; bool ptr_used[3]; ptr_used[0] = false; ptr_used[1] = false; ptr_used[2] = false; if (buff_being_constructed != BUFF_UNSET) { ptr_used[buff_being_constructed] = true; } if (buff_displayed_last_time != BUFF_UNSET) { ptr_used[buff_displayed_last_time] = true; } if (buff_to_display_next != BUFF_UNSET) { ptr_used[buff_to_display_next] = true; } int nptrused = 0; if (ptr_used[0]) nptrused++; if (ptr_used[1]) nptrused++; if (ptr_used[2]) nptrused++; NosuchAssert(nused != nptrused); }
Region* Palette::NewButtonNamed(std::string nm, int sid_low, int sid_high, std::string patch) { Region* r = newRegionNamed(nm); NosuchAssert(r); r->setTypeAndSid(Region::BUTTON,sid_low,sid_high); r->setButtonPatch(patch); return r; }
void Region::getCursors(std::list<Cursor*>& cursors ) { for ( std::list<Cursor*>::iterator i = _cursors.begin(); i!=_cursors.end(); i++ ) { Cursor* c = *i; NosuchAssert(c); cursors.push_back(c); } }
void Palette::changeSoundSet(int selected) { int sb = soundBank(); NosuchAssert(selected>=0 && selected<NUM_SOUNDSETS); NosuchAssert(sb>=0 && sb<=NUM_SOUNDSETS); if ( SoundBank[sb][selected][0] == "" ) { NosuchErrorOutput("No sounds in soundbank %d !?",sb); return; } setRegionSound(1,SoundBank[sb][selected][0]); setRegionSound(2,SoundBank[sb][selected][1]); setRegionSound(3,SoundBank[sb][selected][2]); setRegionSound(4,SoundBank[sb][selected][3]); NosuchDebug(1,"CHANGED SOUND SET to number %d",selected); CurrentSoundSet = selected; }
void Region::initSound() { if ( isSurface() ) { std::string snd = SoundBank[0][0][0]; NosuchAssert(snd!=""); params.sound = snd; UpdateSound(); } }
static cJSON* jsonGet(cJSON *j, std::string nm, int jtype) { NosuchAssert(j); cJSON *c = cJSON_GetObjectItem(j,nm.c_str()); if ( c && c->type == jtype ) { return c; } else { return NULL; } }
void Region::initSound() { if ( isRegion() ) { std::string snd = SoundBank[0][0][0]; NosuchAssert(snd!=""); _regionParams->sound.set(snd); UpdateSound(); } }
int Outlines_SharedMemHeader::addPoint(buff_index b, float x, float y, float z) { NosuchAssert(b != BUFF_UNSET); int pnum = numpoints[b]; PointMem* p = point(b, pnum); p->x = x; p->y = y; p->z = z; numpoints[b]++; return pnum; }
void Region::accumulateSpritesForCursor(Cursor* c) { spritelist_lock_write(); for ( std::list<Sprite*>::iterator i = sprites.begin(); i!=sprites.end(); i++) { Sprite* s = *i; NosuchAssert(s); if ( s->state.sidnum == c->sidnum() && s->state.sidsource == c->sidsource() ) { s->accumulate(c); } } spritelist_unlock(); }
double methodNeedDouble(std::string meth,cJSON *j,std::string nm) { NosuchAssert(j); cJSON *c = cJSON_GetObjectItem(j,nm.c_str()); if ( ! c ) { throw NosuchException("Missing %s argument on %s method",nm.c_str(),meth.c_str()); } if ( c->type != cJSON_Number ) { throw NosuchException("Unexpected type for %s argument to %s method, expecting double",nm.c_str(),meth.c_str()); } return (double)(c->valuedouble); }
std::string methodNeedString(std::string meth,cJSON *j,std::string nm) { NosuchAssert(j); cJSON *c = cJSON_GetObjectItem(j,nm.c_str()); if ( ! c ) { throw NosuchException("Missing %s argument on %s method",nm.c_str(),meth.c_str()); } if ( c->type != cJSON_String ) { throw NosuchException("Unexpected type for %s argument to %s method, expecting string",nm.c_str(),meth.c_str()); } return c->valuestring; }
double Region::MaxSpaceCursorDepth() { double maxval = 0; for ( std::list<SpaceCursor*>::iterator i = _palettecursors.begin(); i!=_palettecursors.end(); i++ ) { SpaceCursor* c = *i; NosuchAssert(c); double d = c->depth(); if ( d > maxval ) maxval = d; } return maxval; }
void Region::draw() { spritelist->draw(); #if 0 spritelist_lock_read(); for ( std::list<Sprite*>::iterator i = sprites.begin(); i!=sprites.end(); i++ ) { Sprite* s = *i; NosuchAssert(s); s->draw(b,this); } spritelist_unlock(); #endif }
SpaceCursor* Region::getSpaceCursor(int sidnum, std::string sidsource) { SpaceCursor* retc = NULL; for ( std::list<SpaceCursor*>::iterator i = _palettecursors.begin(); i!=_palettecursors.end(); i++ ) { SpaceCursor* c = *i; NosuchAssert(c); if (c->sid == sidnum && c->source == sidsource) { retc = c; break; } } return retc; }
double Region::AverageSpaceCursorDepth() { double totval = 0; int totnum = 0; for ( std::list<SpaceCursor*>::iterator i = _palettecursors.begin(); i!=_palettecursors.end(); i++ ) { SpaceCursor* c = *i; NosuchAssert(c); totval += c->depth(); totnum++; } if ( totnum == 0 ) { return -1; } else { return totval / totnum; } }
double Region::MaxCursorDepth() { double maxval = 0; if ( ! cursorlist_lock_read() ) { NosuchDebug("Region::MaxCursorDepth returns -1, unable to lock cursorlist"); return -1; } for ( std::list<Cursor*>::iterator i = _cursors.begin(); i!=_cursors.end(); i++ ) { Cursor* c = *i; NosuchAssert(c); double d = c->curr_depth; if ( d > maxval ) maxval = d; } cursorlist_unlock(); return maxval; }
NosuchDaemon::~NosuchDaemon() { daemon_shutting_down = true; if ( _network_thread_created ) { // pthread_detach(_network_thread); pthread_join(_network_thread,NULL); } NosuchAssert(_httpserver != NULL); delete _httpserver; _httpserver = NULL; if ( _oscinput ) { _oscinput->UnListen(); delete _oscinput; _oscinput = NULL; } }
double Region::AverageCursorDepth() { double totval = 0; int totnum = 0; if ( ! cursorlist_lock_read() ) { NosuchDebug("Region::AverageCursorDepth returns -1, unable to lock cursorlist"); return -1; } for ( std::list<Cursor*>::iterator i = _cursors.begin(); i!=_cursors.end(); i++ ) { Cursor* c = *i; NosuchAssert(c); totval += c->curr_depth; totnum++; } cursorlist_unlock(); if ( totnum == 0 ) { return -1; } else { return totval / totnum; } }
Cursor* Region::getCursor(int sidnum, std::string sidsource) { Cursor* retc = NULL; if ( ! cursorlist_lock_read() ) { NosuchDebug("Region::getCursor returns NULL, unable to lock cursorlist"); return NULL; } for ( std::list<Cursor*>::iterator i = _cursors.begin(); i!=_cursors.end(); i++ ) { Cursor* c = *i; NosuchAssert(c); if (c->sidnum() == sidnum && c->sidsource() == sidsource) { retc = c; break; } } cursorlist_unlock(); // if ( retc == NULL ) { // NosuchDebug("DIDN'T FIND getCursor for sid=%s",sid.c_str()); // } return retc; }
void Region::checkCursorUp(int millinow) { if ( ! cursorlist_lock_write() ) { NosuchDebug("Region::checkCursorUp, unable to lock cursorlist"); return; } for ( std::list<Cursor*>::iterator i = _cursors.begin(); i!=_cursors.end(); ) { Cursor* c = *i; NosuchAssert(c); int dt = millinow - c->touched(); if (dt > 4) { // NosuchDebug("checkCursorUp, dt>4 = %d",dt); cursorUp(c); i = _cursors.erase(i); // XXX - should c be deleted? delete c; } else { i++; } } cursorlist_unlock(); }
void Region::advanceTo(int tm) { spritelist->advanceTo(tm); #if 0 spritelist_lock_write(); for ( std::list<Sprite*>::iterator i = sprites.begin(); i!=sprites.end(); ) { Sprite* s = *i; NosuchAssert(s); s->advanceTo(tm); if ( s->state.killme ) { i = sprites.erase(i); // NosuchDebug("Should be deleting Sprite s=%d",(int)s); delete s; } else { i++; } } spritelist_unlock(); #endif if ( last_tm > 0 && isSurface() ) { int dt = leftover_tm + tm - last_tm; if ( dt > fire_period ) { // NosuchDebug("Region %d calling behave->periodicFire now=%d",this->id,Palette::now); if ( Palette::selector_check && (_graphicBehaviour->isSelectorDown() || _musicBehaviour->isSelectorDown()) ) { NosuchDebug(2,"NOT calling behaviour->advanceTo because Selector is down"); } else { _graphicBehaviour->advanceTo(tm); _musicBehaviour->advanceTo(tm); } dt -= fire_period; } leftover_tm = dt % fire_period; } last_tm = tm; }
int Outlines_SharedMemHeader::addOutline(buff_index b, int rid, int sid, float x, float y, float z, float area, int npoints) { NosuchAssert(b != BUFF_UNSET); int cnum = numoutlines[b]; OutlineMem* om = outline(b, cnum); // NOTE: region id's in the shared memory are shifted down by 1 om->region = rid - 1; om->sid = sid; om->x = x; om->y = y; om->z = z; om->area = area; om->npoints = npoints; om->index_of_firstpoint = numpoints[b]; numoutlines[b]++; return cnum; }
Channel::Channel(Palette* p, int i) { NosuchAssert( i >= 0 && i <= 15); // spritelist = new VizSpriteList(); id = i; _midiBehaviour = NULL; _midiBehaviourName = ""; _palette = p; #ifdef LOOPSTUFF _loop = NULL; _looping = false; #endif NosuchLockInit(&_channel_mutex,"channel"); // spritelist_rwlock = PTHREAD_RWLOCK_INITIALIZER; // int rc1 = pthread_rwlock_init(&spritelist_rwlock, NULL); // if ( rc1 ) { // NosuchDebug("Failure on pthread_rwlock_init!? rc=%d",rc1); // } // NosuchDebug(2,"spritelist_rwlock has been initialized"); }
void Outlines_SharedMemHeader::clear_lists(buff_index buffnum) { NosuchAssert(buffnum != BUFF_UNSET); numoutlines[buffnum] = 0; numpoints[buffnum] = 0; }
int Palette::setRegionSound(std::string region, std::string nm) { Region* r = GetRegionNamed(region); NosuchAssert(r); return setRegionSound(r,nm); }
int Palette::setRegionSound(int rid, std::string nm) { Region* r = getRegion(rid); NosuchAssert(r); return setRegionSound(r,nm); }