void InteractionLoop::pyHandleCustomCtorArgs(python::tuple& t, python::dict& d) { if(python::len(t)==0) return; // nothing to do if(python::len(t)!=3) throw invalid_argument("Exactly 3 lists of functors must be given"); // parse custom arguments (3 lists) and do in-place modification of args typedef std::vector<shared_ptr<IGeomFunctor> > vecGeom; typedef std::vector<shared_ptr<IPhysFunctor> > vecPhys; typedef std::vector<shared_ptr<LawFunctor> > vecLaw; vecGeom vg=python::extract<vecGeom>(t[0])(); vecPhys vp=python::extract<vecPhys>(t[1])(); vecLaw vl=python::extract<vecLaw>(t[2])(); FOREACH(shared_ptr<IGeomFunctor> gf, vg) this->geomDispatcher->add(gf); FOREACH(shared_ptr<IPhysFunctor> pf, vp) this->physDispatcher->add(pf); FOREACH(shared_ptr<LawFunctor> cf, vl) this->lawDispatcher->add(cf); t=python::tuple(); // empty the args; not sure if this is OK, as there is some refcounting in raw_constructor code }
static void http_build_header_ptr(http_response_t * response) { int i, l1, l2; sprintf( response->header_ptr, "HTTP/%d.%d %d OK\r\n", response->http_major, response->http_minor, response->status ); i = strlen(response->header_ptr); FOREACH(response->headers, key, value) l1 = strlen(key); l2 = strlen(value); if (i + 3 + l1 + l2 >= 4098) break; strncat(response->header_ptr + i, key, l1); i += l1; strncat(response->header_ptr + i, ": ", 2); i += 2; strncat(response->header_ptr + i, value, l2); i += l2; strncat(response->header_ptr + i, "\r\n", 2); i += 2; END strncat(response->header_ptr + i, "\r\n", 2); response->header_len = i + 2; }
void World::update(sf::Time dt) { // Scroll the world, reset player velocity mWorldView.move(0.f, mScrollSpeed * dt.asSeconds() * mScrollSpeedCompensation); FOREACH(Aircraft* a, mPlayerAircrafts) a->setVelocity(0.f, 0.f); // Setup commands to destroy entities, and guide missiles destroyEntitiesOutsideView(); guideMissiles(); // Forward commands to scene graph, adapt velocity (scrolling, diagonal correction) while (!mCommandQueue.isEmpty()) mSceneGraph.onCommand(mCommandQueue.pop(), dt); adaptPlayerVelocity(); // Collision detection and response (may destroy entities) handleCollisions(); // Remove aircrafts that were destroyed (World::removeWrecks() only destroys the entities, not the pointers in mPlayerAircraft) auto firstToRemove = std::remove_if(mPlayerAircrafts.begin(), mPlayerAircrafts.end(), std::mem_fn(&Aircraft::isMarkedForRemoval)); mPlayerAircrafts.erase(firstToRemove, mPlayerAircrafts.end()); // Remove all destroyed entities, create new ones mSceneGraph.removeWrecks(); spawnEnemies(); // Regular update step, adapt position (correct if outside view) mSceneGraph.update(dt, mCommandQueue); adaptPlayerPosition(); updateSounds(); }
static void fromToSQL(StringInfo str, List *from) { appendStringInfoString(str, " FROM "); FOREACH(FromItem,f, from) fromItemToSQL(str, f); }
static PGresult * execPrepared(char *qName, List *values) { char **params; int i; int nParams = LIST_LENGTH(values); PGresult *res = NULL; params = CALLOC(sizeof(char*),LIST_LENGTH(values)); ASSERT(postgresIsInitialized()); i = 0; FOREACH(Constant,c,values) params[i++] = STRING_VALUE(c); DEBUG_LOG("run query %s with parameters <%s>", qName, exprToSQL((Node *) values)); res = PQexecPrepared(plugin->conn, qName, nParams, (const char *const *) params, NULL, NULL, 0); if (PQresultStatus(res) != PGRES_TUPLES_OK) CLOSE_RES_CONN_AND_FATAL(res, "query %s failed:\n%s", qName, PQresultErrorMessage(res)); return res; }
// #define __MCO //--------------------------------------------------------------------------------------- Box GetVxesBbox(vvector<v3d_t>& vxes) { Box b; FOREACH(vvector<v3d_t>, vxes, pv) b.AddPoint(*pv); return b; }
//----------------------------------------------------------------------------- void TRP(char* t, Poly& p) { TRACE(t); FOREACH(Vertexes, p._vtci,v) TRACE("[%.2f, %.2f, %.2f] ",v->_xyz.x,v->_xyz.y,v->_xyz.z ); TRACE("\r\n"); }
int picolCondition(picolInterp *i, char* str) { if(str) { char buf[MAXSTR], buf2[MAXSTR]; int rc; rc = picolSubst(i,str); if(rc != PICOL_OK) return rc; //mysnprintf(buf, MAXSTR, "Condi: (%s) ->(%s)\n",str,i->result); //dbg_send_str3(buf, 1); mystrncpy(buf2,i->result, MAXSTR); /* ------- try whether the format suits [expr]... */ mystrncpy(buf,"llength ", MAXSTR); LAPPEND(buf,i->result); //dbg_send_str3(buf, 1); rc = picolEval(i,buf); if(rc != PICOL_OK) return rc; #if 0 if(EQ(i->result,"3")) { FOREACH(buf,cp,buf2) argv[a++] = mystrdup(buf); if(picolGetCmd(i,argv[1])) { /* defined operator in center */ mystrncpy(buf,argv[1], MAXSTR); /* translate to Polish :) */ LAPPEND(buf,argv[0]); /* e.g. {1 > 2} -> {> 1 2} */ LAPPEND(buf,argv[2]); rc = picolEval(i, buf); return rc; } } /* .. otherwise, check for inequality to zero */ #endif if(*str == '!') {mystrncpy(buf, "== 0 ", MAXSTR); str++;} /* allow !$x */ else mystrncpy(buf, "!= 0 ", MAXSTR); mystrncat(buf, str, MAXSTR); return picolEval(i, buf); // todo: compare without eval } else return picolErr(i, "NULL condition"); }
void SceneNode::checkSceneCollision(SceneNode& sceneGraph, std::set<Pair>& collisionPairs) { checkNodeCollision(sceneGraph, collisionPairs); FOREACH(Ptr& child, sceneGraph.mChildren) checkSceneCollision(*child, collisionPairs); }
void AdjustSync::AutosyncTempo() { float fSlope = 0.0f; float fIntercept = 0.0f; if( !CalcLeastSquares( s_vAutosyncTempoData, fSlope, fIntercept, s_fAverageError ) ) { s_vAutosyncTempoData.clear(); return; } if( s_fAverageError < ERROR_TOO_HIGH ) { // Here we filter out any steps that are too far off. // // If it turns out that we want to be even more selective, we can // keep only a fraction of the data, such as the 80% with the lowest // error. However, throwing away the ones with high error should // be enough in most cases. float fFilteredError = 0.0; s_iStepsFiltered = s_vAutosyncTempoData.size(); FilterHighErrorPoints( s_vAutosyncTempoData, fSlope, fIntercept, ERROR_TOO_HIGH ); s_iStepsFiltered -= s_vAutosyncTempoData.size(); if( !CalcLeastSquares( s_vAutosyncTempoData, fSlope, fIntercept, fFilteredError ) ) return; GAMESTATE->m_pCurSong->m_Timing.m_fBeat0OffsetInSeconds += fIntercept; const float fScaleBPM = 1.0f/(1.0f - fSlope); FOREACH( BPMSegment, GAMESTATE->m_pCurSong->m_Timing.m_BPMSegments, i ) i->SetBPM( i->GetBPM() * fScaleBPM ); // We assume that the stops were measured as a number of beats. // Therefore, if we change the bpms, we need to make a similar // change to the stops. FOREACH( StopSegment, GAMESTATE->m_pCurSong->m_Timing.m_StopSegments, i ) i->m_fStopSeconds *= 1.0f - fSlope; SCREENMAN->SystemMessage( AUTOSYNC_CORRECTION_APPLIED.GetValue() ); } else { // deviation... error... close enough for an error message SCREENMAN->SystemMessage( AUTOSYNC_CORRECTION_NOT_APPLIED.GetValue() ); } s_vAutosyncTempoData.clear(); }
void file_list_print(FILE *f) { size_t idx; file_list_t *pfile; FOREACH(idx,pfile,_file_list) fprintf(f,"file '%s' referenced %i times\n", pfile->name, pfile->refcount); }
List * provRewriteQueryList (List *list) { FOREACH(QueryOperator,q,list) q_his_cell->data.ptr_value = provRewriteQuery(q); return list; }
void SceneNode::onCommand(const Command& command, sf::Time dt) { if(command.category & getCategory()) command.action(*this, dt); FOREACH(Ptr& child, children) child->onCommand(command, dt); }
void SceneNode::checkNodeCollision(SceneNode& node, std::set<Pair>& collisionPairs) { if (this != &node && collision(*this, node) && !isDestroyed() && !node.isDestroyed()) collisionPairs.insert(std::minmax(this, &node)); FOREACH(Ptr& child, mChildren) child->checkNodeCollision(node, collisionPairs); }
void SubWindow::close() { if(background == nullptr) delete background; FOREACH(queue, it) delete *it; queue.clear(); }
void SceneNode::onCommand(const Command& command, sf::Time dt) { // Command current node, if category matches if (command.category & getCategory()) command.action(*this, dt); // Command children FOREACH(Ptr& child, mChildren) child->onCommand(command, dt); }
void input_event_manager_update() { SDL_Event event; while( SDL_PollEvent(&event) ) { FOREACH(callbacks, InputEventCallback, callback) callback->invoke(&event); ENDFOREACH } }
void Ontology::normalize() { hierarchy.closure(); //reduce transitivity for universals set<const UniversalConcept *> s; FOREACH(u, positive_universals) FOREACH(i, transitive_roles) if (hierarchy(*i, (*u)->role()->ID())) { const Role *t = factory.role(*i); const UniversalConcept *c = factory.universal(t, factory.universal(t, (*u)->concept())); if (t != (*u)->role()) unary(Concept::concept_decompose(*u), Disjunction(Concept::concept_decompose(c))); s.insert(c); } FOREACH(u, s) { unary(Concept::concept_decompose((*u)->concept()), Disjunction(Concept::concept_decompose(*u))); positive_universals.insert(*u); positive_universals.insert((const UniversalConcept *) (*u)->concept()); }
QueryOperator * findProvenanceComputations (QueryOperator *op) { // is provenance computation? then rewrite if (isA(op, ProvenanceComputation)) return rewriteProvenanceComputation((ProvenanceComputation *) op); // else search for children with provenance FOREACH(QueryOperator, x, op->inputs) findProvenanceComputations(x); return op; }
void foreachTest::DoExecute() { int a[]={1, 2, 3}; /* std::for_each(a, a+_countof(a), foreachTestFunc); std::for_each(a, a+_countof(a), TestFunc()); */ FOREACH(a, foreachTestFunc); FOREACH(a, TestFunc()); BOOST_FOREACH(int iA, a) { if(iA > 1) break; std::cout << iA << std::endl; } return ; }
InputHandler_MacOSX_HID::~InputHandler_MacOSX_HID() { FOREACH( HIDDevice *, m_vDevices, i ) delete *i; if( PREFSMAN->m_bThreadedInput ) { CFRunLoopSourceSignal( m_SourceRef ); CFRunLoopWakeUp( m_LoopRef ); m_InputThread.Wait(); CFRelease( m_SourceRef ); CFRelease( m_LoopRef ); LOG->Trace( "Input handler thread shut down." ); } FOREACH( io_iterator_t, m_vIters, i ) IOObjectRelease( *i ); IONotificationPortDestroy( m_NotifyPort ); }
void Ontology::NegativeStructuralTransformation::conjunction(const ConjunctionConcept *c) { if (not_seen(c)) { vector<const Concept*> u, q(c->elements()); set<ConceptID, Concept::DecomposeLess> s; for (int i = 0; i < q.size(); i++) { if (q[i]->type() == 'C') { FOREACH(x, ((const ConjunctionConcept*) q[i])->elements()) q.push_back(*x); } else if (q[i]->type() == 'N') { const NegationConcept* x = (const NegationConcept*) q[i]; s.insert(Concept::concept_decompose(x->concept())); x->concept()->accept(*positive); } else if (q[i]->type() == 'U') { const UniversalConcept* y = (const UniversalConcept*) q[i]; const ExistentialConcept* x = factory.existential(y->role(), factory.negation(y->concept())); s.insert(Concept::concept_decompose(x)); x->accept(*positive); } else { u.push_back(q[i]); q[i]->accept(*this); } } s.insert(c->ID()); if (u.empty()) ontology->nullary(Disjunction(s)); else if (u.size() == 1) ontology->unary(u[0]->ID(), Disjunction(s)); else { const Concept *d = u[0]; vector<const Concept*> t; t.push_back(d); for (int i = 1; i < u.size()-1; i++) { t.push_back(u[i]); const Concept *conj = factory.conjunction(t); ontology->binary(d->ID(), u[i]->ID(), Disjunction(conj->ID())); d = conj; } ontology->binary(d->ID(), u.back()->ID(), Disjunction(s)); } } }
void parse_query_string(dict * args, char * query) { char * key = NULL, *value = NULL; char * skey, *svalue; while (*query) { if (key == NULL) { key = query; } switch (*query) { case '=': value = query+1; break; case '&': skey = strndup(key, value - key - 1); svalue = strndup(value, query - value); dictAdd(args, skey, svalue); zfree(skey); zfree(svalue); key = NULL; value = NULL; break; } query++; } if (key) { if (!value) value = query; skey = strndup(key, value - key - 1); svalue = strndup(value, query - value); dictAdd(args, skey, svalue); zfree(skey); zfree(svalue); } #if 0 FOREACH(args, skey, svalue) printf("%s => %s\n", skey, svalue); END #endif }
void SubWindow::show(void(* processPtr)(sf::Event)) { bool done = false; while(!done) { while(Window::instance()->getRW()->GetEvent(event)) { if(event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Key::Escape) done = true; Window::instance()->process(event); } Window::instance()->getRW()->Clear(); Window::instance()->getRW()->Draw(*background); Window::instance()->getRW()->Draw(window); FOREACH(queue, it) Window::instance()->getRW()->Draw(*(*it)); Window::instance()->getRW()->Display(); } close(); }
void OptionsList::Load( RString sType, PlayerNumber pn ) { TOP_MENU.Load( sType, "TopMenu" ); m_pn = pn; m_bStartIsDown = false; m_Codes.Load( sType ); m_Cursor.Load( THEME->GetPathG(sType, "cursor") ); m_Cursor->SetName( "Cursor" ); ActorUtil::LoadAllCommands( *m_Cursor, sType ); this->AddChild( m_Cursor ); vector<RString> asDirectLines; split( DIRECT_LINES, ",", asDirectLines, true ); FOREACH( RString, asDirectLines, s ) m_setDirectRows.insert( *s ); vector<RString> setToLoad; split( TOP_MENUS, ",", setToLoad ); m_setTopMenus.insert( setToLoad.begin(), setToLoad.end() ); while( !setToLoad.empty() ) { RString sLineName = *setToLoad.begin(); setToLoad.erase( setToLoad.begin() ); if( m_Rows.find(sLineName) != m_Rows.end() ) continue; RString sRowCommands = LINE(sLineName); Commands cmds; ParseCommands( sRowCommands, cmds, false ); OptionRowHandler *pHand = OptionRowHandlerUtil::Make( cmds ); if( pHand == NULL ) { LuaHelpers::ReportScriptErrorFmt("Invalid OptionRowHandler '%s' in %s::Line%s", cmds.GetOriginalCommandString().c_str(), m_sName.c_str(), sLineName.c_str()); continue; } m_Rows[sLineName] = pHand; m_asLoadedRows.push_back( sLineName ); for( size_t i = 0; i < pHand->m_Def.m_vsChoices.size(); ++i ) { RString sScreen = pHand->GetScreen(i); if( !sScreen.empty() ) setToLoad.push_back( sScreen ); } } for( int i = 0; i < 2; ++i ) { m_Row[i].SetName( "OptionsList" ); m_Row[i].Load( this, "OptionsList" ); ActorUtil::LoadAllCommands( m_Row[i], sType ); this->AddChild( &m_Row[i] ); } this->PlayCommand( "TweenOff" ); this->FinishTweening(); }
void StateStack::draw() { // Draw all active states from bottom to top FOREACH(State::Ptr& state, stack_) state->draw(); }
void PlayerState::EndActiveAttacks() { FOREACH( Attack, m_ActiveAttacks, a ) a->fSecsRemaining = 0; }
IterTest::IterTest() { CtrlLayout(*this, "Window title"); //generally, an iter interface needs its underlying container to live as long as interface is present. //no checks are performed to keep code small //an Iter interface will not modify the underlying container. //if container is changed while an Iter interface is bound to it, it may become undefined in behaviour (Vector i.e) //an Iter interface is always created on heap, so use means to delete it after usage, best is One<Iter<int > > foo, destroyed when scope is left //========================================================================================== //Vector or any common linear container Vector<int> vi; vi.SetCount(10); //use the explicit interface to do things One<Iter<int> > ii = IterCreator::GetIter(vi); while(ii->Next()) ii->Get() = Random(); //an iterator can be copied, without knowing its underlying type //and can be reinitiated One<Iter<int> > ii2 = ii->PartialCopy(); while(ii2->Next()) LOG(ii2->Get()); //the const variant of Iter, ConstIter One<ConstIter<int> > ii3 = IterCreator::GetIter((const Vector<int>&)vi); while(ii3->Next()) LOG(ii3->Get()); FOREACH(int, e, vi) LOG(e); //and the const version FOREACHC(int, e, (const Vector<int>&)vi) LOG(e); //helpers to define the scope safe iterators ITER(int) _ii = IterCreator::GetIter(vi); ITERC(int) _cii = IterCreator::GetIter((const Vector<int>&)vi); //a macro for usual containers only without using Iter interface //can speed up things because no virtual stuff involved FOREACHCONT(int, e, vi) LOG(e); //the const variant FOREACHCONTC(int, e, (const Vector<int>&)vi) LOG(e); //other 'containers' also yield a Iter interface //usual pointer int in = 123; int* inp = ∈ FOREACH(int, e, inp) LOG(e); FOREACHC(int, e, (const int*)inp) LOG(e); //Ptr EditInt ei; Ptr<Ctrl> eip(&ei); FOREACH(Ctrl, e, eip) e.SetData(123); FOREACHC(Ctrl, e, (const Ptr<Ctrl>&)eip) e.GetData(); //One One<Ctrl> oei; oei.Create<EditInt>(); FOREACH(Ctrl, e, oei) e.SetData(123); FOREACHC(Ctrl, e, (const One<Ctrl>&)oei) e.GetData(); //Any Any a; a.Create<int>() = 345; One<Iter<int> > ia = IterCreator::GetIter<int>(a); FOREACH(int, e, a) LOG(e); FOREACHC(int, e, (const Any&)a) LOG(e); //Value Value v = 789; One<Iter<int> > iv = IterCreator::GetIter<int>(v); FOREACH(int, e, v) LOG(e); FOREACHC(int, e, (const Value&)v) LOG(e); //Link LinkOwner<Foo> lf; for(int i = 0; i < 10; i++) lf.InsertPrev()->d = i; FOREACH(Foo, e, (Link<Foo>&)lf) LOG(e.d); FOREACHC(Foo, e, (const Link<Foo>&)lf) LOG(e.d); //all containers can be handled in a common interface ITER(int) iii; iii = IterCreator::GetIter(vi); CommonHandler(*iii); Array<int> ai; iii = IterCreator::GetIter(ai); CommonHandler(*iii); }
py::dict perThreadData() const { py::dict ret; std::vector<std::vector<Real> > dta=energies.getPerThreadData(); FOREACH(pairStringInt p,names) ret[p.first]=dta[p.second]; return ret; };
void SceneNode::updateChildren(sf::Time dt) { FOREACH(Ptr& child, mChildren) child->update(dt); }