void Unset(Var x) { if(SymQ(x)) { OwnValues.erase(x); return; } if(VecQ(x)) { size_t n = Size(x); for(size_t i = 0; i < n; ++i) Unset(At(x,i)); return; } if(ExQ(x)) { var h = Eval(Head(x)); if(SymQ(h)) { var b = Body(x); if(h == TAG(Property)) { if(SymQ(At(b,0)) && SymQ(At(b,1))) { std::map<Var,map_t>::iterator iter = Properties.find(At(b,0)); if(iter != Properties.end()) iter->second.erase(At(b,1)); } return; } b = Eval(b); if(FixQ(b)) { std::map<Var,dict_t>::iterator iter = FactValues.find(h); if(iter != FactValues.end()) iter->second.erase(b); } else { std::map<Var,def_t>::iterator iter = DownValues.find(h); if(iter != DownValues.end()) iter->second.erase(b); } return; } else if(ExQ(h) && SymQ(Head(h))) { var b = Eval(Body(x)); var t = Vec(Body(h),b); std::map<Var,def_t>::iterator iter = SubValues.find(Head(h)); if(iter != SubValues.end()) iter->second.erase(t); return; } } }
var EvalEx(Var expression) { var head = Eval(Head(expression)); var body; var result; if(SymQ(head)) { std::map<Var,attr_t>::const_iterator iter = Attributes.find(head); if(iter != Attributes.end()) { if (HandleAttributes(result, expression, iter->second, head, body)) { return result; } } else { body = Eval(Body(expression)); } if (SearchFactValues(result, head, body)) { return result; } if (SearchDownValues(result, head, body)) { return result; } if (SearchCProcs(result, head, body)) { return result; } } else { body = Eval(Body(expression)); if(ExQ(head) && SymQ(Head(head))) { if (SearchSubValues(result, head, body)) { return result; } if (SearchCOpers(result, head, body)) { return result; } } } return Ex(head,body); }
void CSmtpClientMtm::GetBodyTextL(CImEmailMessage& aMessage, TMsvId aMsvId) { CRichText* messageText = CRichText::NewL(iParaFormatLayer, iCharFormatLayer); CleanupStack::PushL(messageText); aMessage.GetBodyTextL(aMsvId, CImEmailMessage::EThisMessageOnly, *messageText,*iParaFormatLayer,*iCharFormatLayer); Body().Reset(); Body().AppendTakingSolePictureOwnershipL(*messageText); CleanupStack::PopAndDestroy(); }
Player::Player(int x, int y): alive(true), currentDirection(Direction::RIGHT), nextDirection(Direction::RIGHT) { // The Snake's head this->body.push_back(Body(x, y)); // Initializing the snake with 2 body pieces // (plus the head) this->body.push_back(Body(x - 1, y)); this->body.push_back(Body(x - 1, y)); }
bool HandleAttributes(var &result, Var expression, const attr_t &attributes, var head, var &body) { if(attributes.count(SequenceHold)) { body = Body(expression); } else { body = FlattenSequence(Body(expression), false); } size_t n = Size(body); // FIXME: in mathematica, OneIdentity means "x == f[x]" only for PATTERN MATCHING purposes // if(n == 1 && attributes.count(OneIdentity)) // { // result = Eval(At(body,0)); // return true; // } if(!attributes.count(HoldAll)) { if(n > 0 && !attributes.count(HoldFirst)) At(body,0) = Eval(At(body,0)); if(n > 1 && !attributes.count(HoldRest)) for(size_t i = 1; i < n; ++i) At(body,i) = Eval(At(body,i)); } if(attributes.count(Listable)) { // TODO: handle the case where all list must be of same length, e.g. CoprimeQ var t = Thread(head,body); if(t) { result = Eval(t); return true; } } if(attributes.count(Flat)) { var t = body; body = Vec(); Reserve(body,n); Flatten(body,head,t); } if(attributes.count(Orderless)) Sort(body); return false; }
void BHTree::calculateForce(BHTree& node, Body& b, bool canCombineMass) { if(!node.isInternalNode) { if(node.hasBody && node.body != b) { //apply force of current node to body applyForceToBody(b, node.body, canCombineMass); } } else { float s = node.width; float d = Body::distance(node.cgX, node.cgY, node.cgZ, b.x, b.y, b.z); float ratio = s/d; if(s/d <= BH_THETA) { //apply force of current node to body applyForceToBody(b, Body(-1, node.mass, node.cgX, node.cgY, node.cgZ), false); } else { //recursively apply force of child nodes calculateForce(*node.fNW, b, canCombineMass); calculateForce(*node.fNE, b, canCombineMass); calculateForce(*node.fSW, b, canCombineMass); calculateForce(*node.fSE, b, canCombineMass); calculateForce(*node.bNW, b, canCombineMass); calculateForce(*node.bNE, b, canCombineMass); calculateForce(*node.bSW, b, canCombineMass); calculateForce(*node.bSE, b, canCombineMass); } } }
void Player::increase() { int lastx = this->body.back().x; int lasty = this->body.back().y; this->body.push_back(Body(lastx, lasty)); }
Body loadBody(std::string modelType, std::string solverType, std::string meshType) { Solver* solver; Model* model; Mesh* mesh; if (solverType == "defaultSolver") { solver = new DefaultSolver(); } else if (solverType == "customSolver") { solver = new CustomSolver(); } if (modelType == "modelOne") { model = new ModelOne(); } else if (modelType == "modelTwo") { model = new ModelTwo(); } else if (modelType == "modelThree") { model = new ModelThree(); } if (meshType == "tetrMesh") { mesh = new TetrMesh(); mesh->load(); } else if (meshType == "cubicMesh") { mesh = new CubicMesh(); mesh->load(); } else if (meshType == "myCustomTetrMesh") { mesh = new MyCustomTetrMesh(); mesh->load(); } return Body(mesh, solver, model); };
AmqpProcessor::Result AmqpProcessor::process_frame(const amqp_frame_t& frame) { Result result; if(is_deliver(frame)) { listener_->process_event(Deliver()); result = delivery_decoded(frame); } else if(is_header(frame)) { listener_->process_event(Header(body_size(frame))); result = properties(frame); } else if(is_body(frame)) { amqp_bytes_t fragment = get_body_fragment(frame); listener_->process_event(Body(fragment.len)); AmqpListener::Delivery& delivery = listener_->get_state<AmqpListener::Delivery&>(); bool last = delivery.is_flag_active<Delivered>(); result = std::make_pair(fragment, last); } else { std::cout << "unprocessed frame: " << frame.frame_type << std::endl; } return result; }
EntityPtr EntityFactory::createDefault() { EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY)); EntityPtr entity(GCC_NEW Entity()); entitySystem->addEntity(entity); PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS)); BodyPtr blockBody(GCC_NEW Body(0, 0, 16, 16)); physicsSystem->registerBody(entity->id, blockBody); PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody)); physicsComponent->setCollider(GCC_NEW Collider(0, 0, 16, 16)); GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS)); DrawablePtr blockDrawable(GCC_NEW BlockDrawable(16, 16, 255, 0, 0, 255)); graphicsSystem->registerDrawable(entity->id, blockDrawable); DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, blockDrawable)); InputSystemPtr inputSystem = makeShared(mSystemManager->getSystemByType<InputSystem>(SystemType::INPUT)); InputListenerPtr inputListener(GCC_NEW InputListener(entity->id)); inputSystem->registerEventListener(inputListener); InputComponentPtr inputComponent(GCC_NEW InputComponent(entity->id, inputListener)); entity->addComponent(ComponentPtr(physicsComponent)); entity->addComponent(ComponentPtr(drawableComponent)); entity->addComponent(ComponentPtr(inputComponent)); return entity; }
void Player::SpawnBody() { spawnsToBeMade++; if (spawnBodyParts && SpawnTimeElapsed >= SpawnRateInMilis && spawnsToBeMade%endHole < startHole) { if(spawnsToBeMade> endHole-2) { spawnsToBeMade = 0; endHole = rand()%50+80; startHole = endHole-rand()%20-10; } if (!(powerUppColideActive)) { canColide = true; } BodyParts.push_back(Body(texture,X,Y,color,size,Width,Height)); AmountOfBodyParts++; SpawnTimeElapsed = 0; } else { canColide = false; } }
UMaterialInterface* UPhATEdSkeletalMeshComponent::GetPrimitiveMaterial(int32 BodyIndex, EKCollisionPrimitiveType PrimitiveType, int32 PrimitiveIndex, bool bHitTest) { if (SharedData->bRunningSimulation || SharedData->EditingMode == FPhATSharedData::PEM_ConstraintEdit) { return bHitTest ? BoneMaterialHit : BoneUnselectedMaterial; } FPhATSharedData::FSelection Body(BodyIndex, PrimitiveType, PrimitiveIndex); for(int32 i=0; i< SharedData->SelectedBodies.Num(); ++i) { if (Body == SharedData->SelectedBodies[i] && !SharedData->bRunningSimulation) { return bHitTest ? BoneMaterialHit : ElemSelectedMaterial; } } // If there is no collision with this body, use 'no collision material'. if (SharedData->NoCollisionBodies.Find(BodyIndex) != INDEX_NONE && !SharedData->bRunningSimulation) { return bHitTest ? BoneMaterialHit : BoneNoCollisionMaterial; } else { return bHitTest ? BoneMaterialHit : BoneUnselectedMaterial; } }
EntityPtr EntityFactory::createAnimatedEntity(const string& path, float width, float height) { EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY)); EntityPtr entity(GCC_NEW Entity()); entitySystem->addEntity(entity); PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS)); BodyPtr blockBody(GCC_NEW Body(0.0f, 0.0f, width, height)); physicsSystem->registerBody(entity->id, blockBody); PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody)); GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS)); TexturePtr texture(GCC_NEW Texture("")); shared_ptr<TextureDrawable> textureDrawable(GCC_NEW TextureDrawable(texture)); graphicsSystem->registerDrawable(entity->id, textureDrawable); DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, textureDrawable)); AnimationSystemPtr animationSystem = makeShared(mSystemManager->getSystemByType<AnimationSystem>(SystemType::ANIMATION)); AnimationSetPtr animationSet = animationSystem->createAnimationSet(path); AnimationHandlerPtr animationHandler(GCC_NEW AnimationHandler(textureDrawable, animationSet, animationSet->fps)); animationSystem->registerAnimation(entity->id, animationHandler); AnimationComponentPtr animationComponent(GCC_NEW AnimationComponent(entity->id, animationHandler)); InputSystemPtr inputSystem(makeShared(mSystemManager->getSystemByType<InputSystem>(SystemType::INPUT))); InputListenerPtr inputListener(GCC_NEW InputListener(entity->id)); inputSystem->registerEventListener(inputListener); InputComponentPtr inputComponent(GCC_NEW InputComponent(entity->id, inputListener)); entity->addComponent(ComponentPtr(physicsComponent)); entity->addComponent(ComponentPtr(drawableComponent)); entity->addComponent(ComponentPtr(animationComponent)); entity->addComponent(ComponentPtr(inputComponent)); return entity; }
Door::Door(sf::Vector2f pos, sf::IntRect openS, sf::IntRect closedS, DoorState doorS, DoorDirection doorD) :GameObject(pos) { position = pos; if (doorDirection == DOWN || doorDirection == UP) body = Body(position, sf::Vector2f(0, 0), sf::Vector2f(0, 0), Body::DOOR, 100, 50, 2); else body = Body(position, sf::Vector2f(0, 0), sf::Vector2f(0, 0), Body::DOOR, 50, 100, 2); openSource = openS; closedSource = closedS; currentSource = closedSource; doorState = doorS; doorDirection = doorD; }
EntityPtr EntityFactory::createTexturedEntity(const string& assetTag, float tx, float ty, float w, float h) { EntitySystemPtr entitySystem = makeShared(mSystemManager->getSystemByType<EntitySystem>(SystemType::ENTITY)); EntityPtr entity(GCC_NEW Entity()); entitySystem->addEntity(entity); PhysicsSystemPtr physicsSystem = makeShared(mSystemManager->getSystemByType<PhysicsSystem>(SystemType::PHYSICS)); BodyPtr blockBody(GCC_NEW Body(0.0f, 0.0f, w, h)); physicsSystem->registerBody(entity->id, blockBody); PhysicsComponentPtr physicsComponent(GCC_NEW PhysicsComponent(entity->id, blockBody)); GraphicsSystemPtr graphicsSystem = makeShared(mSystemManager->getSystemByType<GraphicsSystem>(SystemType::GRAPHICS)); TexturePtr texture(GCC_NEW Texture(assetTag, tx, ty, w, h)); DrawablePtr textureDrawable(GCC_NEW TextureDrawable(texture)); graphicsSystem->registerDrawable(entity->id, textureDrawable); DrawableComponentPtr drawableComponent(GCC_NEW DrawableComponent(entity->id, textureDrawable)); InputSystemPtr inputSystem = makeShared(mSystemManager->getSystemByType<InputSystem>(SystemType::INPUT)); InputListenerPtr inputListener(GCC_NEW InputListener(entity->id)); inputSystem->registerEventListener(inputListener); InputComponentPtr inputComponent(GCC_NEW InputComponent(entity->id, inputListener)); entity->addComponent(ComponentPtr(physicsComponent)); entity->addComponent(ComponentPtr(drawableComponent)); entity->addComponent(ComponentPtr(inputComponent)); return entity; }
double Test::Run(size_t iters){ Setup(); reset(); for (uint i = 0; i < iters; i++) Body(); double measured = elapsed(); Cleanup(); return measured * 1000.f; }
GameObject::GameObject(sf::Vector2f pos, sf::Clock sfClock) { position = pos; clock = sfClock; flashTime = 0; color = sf::Color::White; body = Body(position, sf::Vector2f(0, 0), sf::Vector2f(0, 0), Body::PLAYER, 50, 50, 1); }
const char * BEmailMessage::BodyText() { if (Body() == NULL) return NULL; return _text_body->Text(); }
void Player::SpawnBody(float x,float y) { if (spawnBodyParts && SpawnTimeElapsed >= SpawnRateInMilis) { BodyParts.push_back(Body(texture,x,y,color,size,Width,Height)); AmountOfBodyParts++; SpawnTimeElapsed = 0; } }
var FlattenSequence(Var vector, bool evaluate) { size_t n = Size(vector); var r = Vec(); Reserve(r,n); for(size_t i = 0; i < n; ++i) { var c = evaluate ? Eval(At(vector, i)) : At(vector, i); if(ExQ(c,TAG(Sequence))) CVec(r).insert( CVec(r).end(), CVec(Body(c)).begin(), CVec(Body(c)).end()); else Push(r,c); } return r; }
Lifeform::Lifeform(float x_, float y_, float rad_, int lifeform_id_){ // create random dna vector dna = dU.randomizeVec(DNA_LEN); dna_translate(dna); body = Body(ofVec2f(x_,y_), body_dna); }
QuadTree::QuadTree(int num_bodies):bodies(new std::vector<Body*>()), node_b(Body(0.0)), northWest(nullptr), northEast(nullptr), southWest(nullptr), southEast(nullptr){ _remove_bodies_list = new Body*[num_bodies]; }
QuadTree::QuadTree(const Vector &upperRight, const Vector &lowerLeft): bodies(new std::vector<Body*>()), _remove_bodies_list(nullptr), boundary(upperRight, lowerLeft), node_b(Body(0.0)), northWest(nullptr), northEast(nullptr), southWest(nullptr), southEast(nullptr){}
/** x = number being decoded in base N max_lock = index of highest lock acquired so far mask = bit mask; ith bit set if lock i has been acquired. */ void Body( size_t x, int max_lock=-1, unsigned int mask=0 ) const { int i = (int) (x % RecurN); bool first = (mask&1U<<i)==0; if( first ) { // first time to acquire lock if( i<max_lock ) // out of order acquisition might lead to deadlock, so stop return; max_lock = i; } if( (i&1)!=0 ) { // acquire lock on location RecurArray[i] using explict acquire tbb::recursive_mutex::scoped_lock r_lock; r_lock.acquire( RecurMutex[i] ); int a = RecurArray[i]; ASSERT( (a==0)==first, "should be either a==0 if it is the first time to acquire the lock or a!=0 otherwise" ); ++RecurArray[i]; if( x ) Body( x/RecurN, max_lock, mask|1U<<i ); --RecurArray[i]; ASSERT( a==RecurArray[i], "a is not equal to RecurArray[i]" ); // release lock on location RecurArray[i] using explicit release; otherwise, use implicit one if( (i&2)!=0 ) r_lock.release(); } else { // acquire lock on location RecurArray[i] using implicit acquire tbb::recursive_mutex::scoped_lock r_lock( RecurMutex[i] ); int a = RecurArray[i]; ASSERT( (a==0)==first, "should be either a==0 if it is the first time to acquire the lock or a!=0 otherwise" ); ++RecurArray[i]; if( x ) Body( x/RecurN, max_lock, mask|1U<<i ); --RecurArray[i]; ASSERT( a==RecurArray[i], "a is not equal to RecurArray[i]" ); // release lock on location RecurArray[i] using explicit release; otherwise, use implicit one if( (i&2)!=0 ) r_lock.release(); } }
Player::Player(sf::Vector2f pos, sf::Clock sfClock) : GameObject(pos, sfClock) { position = pos; origin = sf::Vector2f(25, 25); assetDir = "assets/player/"; body = Body(position, sf::Vector2f(0, 0), sf::Vector2f(0, 0), Body::PLAYER, 40, 40, 0); //player's initial health maxHealth = 3; currentHealth = maxHealth; currentShield = currentHealth; //player's initial consumable values maxMana = 100; currentMana = maxMana; currentKeys = 1; currentXP = 0; hasBossKey = false; //player's initial stats currentAttackState = START; normalMoveSpeed = 4.75f; hasPoison = false; hasFire = false; hasIce = true; hasGhost = false; hasNecro = true; hasElectric = false; hasEarth = false; nextElementPos = sf::Vector2f(450, 5); nextKey = 0; isInvisible = false; invisibleTimer = sf::seconds(0); //set default values for gui Elements poisonPos = sf::Vector2f(450, 5); firePos = sf::Vector2f(490, 5); icePos = sf::Vector2f(530, 5); ghostPos = sf::Vector2f(570, 5); necroPos = sf::Vector2f(610, 5); elePos = sf::Vector2f(650, 5); earthPos = sf::Vector2f(690, 5); poisonKey = sf::Keyboard::Num1; fireKey = sf::Keyboard::Num2; iceKey = sf::Keyboard::Num3; ghostKey = sf::Keyboard::Num4; necroKey = sf::Keyboard::Num5; electricKey = sf::Keyboard::Num6; earthKey = sf::Keyboard::Num7;; }
var Evalf(Var x) { switch(Type(x)) { case TYPE(int): { var r = Flt(); F::SetZ(r,x); return r; } break; case TYPE(rat): { var r = Flt(); F::SetQ(r,x); return r; } break; case TYPE(flt): { var r = Flt(); F::Set(r,x); mpf_set_prec(CFlt(r),mpf_get_default_prec()); return r; } break; case TYPE(sym): { std::map<Var,attr_t>::const_iterator iter = Attributes.find(x); if(iter != Attributes.end() && iter->second.count(Constant)) return CProcs[x](0); } break; case TYPE(vec): { size_t n = Size(x); var r = Vec(n); for(size_t i = 0; i < n; ++i) At(r,i) = Evalf(At(x,i)); return r; } break; case TYPE(ex): { var b = Evalf(Body(x)); return Eval(Ex(Head(x),b)); } break; } return x; }
int _tmain(int argc, _TCHAR* argv[]) { Body(); Test(); while (true) { LoopBody(); Sleep(100); } return 0; }
Wall::Wall(sf::Vector2f pos, std::string assetName, bool isDestByPlayer, bool isDestByEnemy, sf::IntRect sourceRec) :GameObject(pos) { position = pos; body = Body(position, sf::Vector2f(0, 0), sf::Vector2f(0, 0), Body::WALL, 50, 50, 2); assetDir = assetName; isDestroyableByPlayer = isDestByPlayer; isDestroyableByEnemy = isDestByEnemy; sourceRect = sourceRec; killed = false; }
static void _getwd() { /* ( -- adr len ) */ char path[1024]; if ( getcwd(path, 1024) == 0 ) { fprintf( stderr, "Cannot find CWD.\n" ); /* This is a major error - probably want to jump to warm start?? */ ip = Body("warm"); return; } push( (Cell)path ); push( (Cell)strlen(path) ); }
bool SearchSubValues(var &result, var head, var body) { std::map<Var,def_t>::const_iterator iter = SubValues.find(Head(head)); if(iter != SubValues.end()) { const def_t &definitions = iter->second; if (definitions.is_vec()) { def_t::vec_t::const_iterator iter2 = definitions.vec->begin(); var t = Vec(Body(head),body); while(iter2 != definitions.vec->end()) { map_t m; if(MatchQ(m,iter2->second.first,t)) { result = Eval(Subs(m,iter2->second.second)); return true; } ++iter2; } } else { def_t::map_t::const_iterator iter2 = definitions.map->begin(); var t = Vec(Body(head),body); while(iter2 != definitions.map->end()) { map_t m; if(MatchQ(m,iter2->second.first,t)) { result = Eval(Subs(m,iter2->second.second)); return true; } ++iter2; } } } return false; }