コード例 #1
0
ファイル: continfo.cpp プロジェクト: svn2github/ncbi_tk
void CContainerTypeInfo::Assign(TObjectPtr dst, TConstObjectPtr src,
                                ESerialRecursionMode how) const
{
    if (how == eShallowChildless) {
        SetDefault(dst); // clear destination container
        return;
    }
    CIterator idst;
    CConstIterator isrc;
    bool old_element = InitIterator(idst,dst);
    if ( InitIterator(isrc, src) ) {
        TTypeInfo elementType = GetElementType();
        do {
            TConstObjectPtr elementPtr = GetElementPtr(isrc);
            if (old_element) {
                elementType->Assign(GetElementPtr(idst), elementPtr, how);
                old_element = NextElement(idst);
            } else {
                AddElement(dst, elementPtr, how);
            }
        } while ( NextElement(isrc) );
    }
    if (old_element) {
        EraseAllElements(idst);
    }
}
コード例 #2
0
ファイル: continfo.cpp プロジェクト: svn2github/ncbi_tk
bool CContainerTypeInfo::Equals(TConstObjectPtr object1, TConstObjectPtr object2,
                                ESerialRecursionMode how) const
{
    if (how == eShallowChildless) {
        return true;
    }
    TTypeInfo elementType = GetElementType();
    CConstIterator i1, i2;
    if ( InitIterator(i1, object1) ) {
        if ( !InitIterator(i2, object2) )
            return false;
        if ( !elementType->Equals(GetElementPtr(i1),
                                  GetElementPtr(i2), how) )
            return false;
        while ( NextElement(i1) ) {
            if ( !NextElement(i2) )
                return false;
            if ( !elementType->Equals(GetElementPtr(i1),
                                      GetElementPtr(i2), how) )
                return false;
        }
        return !NextElement(i2);
    }
    else {
        return !InitIterator(i2, object2);
    }
}
コード例 #3
0
ファイル: PRead.c プロジェクト: aosm/X11
/* seek next PARAM element content: "<PARAM ... >" (delimiters excluded)
   and return next trailing stream */
static char *
NextParam(char *stream, NString *param)
{
    NString element, word;

    do {
	stream = NextElement(stream, &element);

	if (element.length)
	    /* get element name */
	    (void) NextWord(element.ptr + 1, element.ptr + element.length - 1,
			    &word);
	else {
	    /* no more elements stop here */
	    param->ptr = 0;
	    param->length = 0;

	    return stream;
	}

	/* check if it's a PARAM element */
    } while(word.length != 5 && memcmp("PARAM", word.ptr, 5) != 0 && *stream);

    param->ptr = word.ptr + word.length;
    param->length = element.length - word.length - 1; /* delimiters excluded */

    return stream;
}
コード例 #4
0
ファイル: pci_openfirmware.cpp プロジェクト: AmirAbrams/haiku
bool
StringArrayPropertyValue::ContainsElement(const char *value) const
{
	int cookie = 0;
	while (char *checkValue = NextElement(cookie)) {
		if (strcmp(checkValue, value) == 0)
			return true;
	}

	return false;
}
コード例 #5
0
TMemberIndex CObjectIStreamJson::BeginClassMember(const CClassTypeInfo* classType,
                                      TMemberIndex pos)
{
    TMemberIndex first = classType->GetMembers().FirstIndex();
    TMemberIndex last = classType->GetMembers().LastIndex();
    if (m_RejectedTag.empty()) {
        if (pos == first) {
            if (classType->GetMemberInfo(first)->GetId().IsAttlist()) {
                TopFrame().SetNotag();
                return first;
            }
        }
    }

    if ( !NextElement() ) {
        if (pos == last &&
            classType->GetMemberInfo(pos)->GetId().HasNotag() &&
            classType->GetMemberInfo(pos)->GetTypeInfo()->GetTypeFamily() == eTypeFamilyPrimitive) {
            TopFrame().SetNotag();
            return pos;
        }
        return kInvalidMember;
    }
    char c = PeekChar();
    if (m_RejectedTag.empty() && (c == '[' || c == '{')) {
        for (TMemberIndex i = pos; i <= last; ++i) {
            if (classType->GetMemberInfo(i)->GetId().HasNotag()) {
                TopFrame().SetNotag();
                return i;
            }
        }
    }
    string tagName = ReadKey();
    if (tagName[0] == '#') {
        tagName = tagName.substr(1);
        TopFrame().SetNotag();
    }
    bool deep = false;
    TMemberIndex ind = FindDeep(classType->GetMembers(), tagName, deep);
    if (deep) {
        if (ind != kInvalidMember) {
            TopFrame().SetNotag();
        }
        UndoClassMember();
    } else if (ind != kInvalidMember) {
        if (classType->GetMembers().GetItemInfo(ind)->GetId().HasAnyContent()) {
            UndoClassMember();
        }
    }
    return ind;
}
コード例 #6
0
TMemberIndex CObjectIStreamJson::BeginClassMember(const CClassTypeInfo* classType)
{
    if ( !NextElement() )
        return kInvalidMember;
    string tagName = ReadKey();
    bool deep = false;
    TMemberIndex ind = FindDeep(classType->GetMembers(), tagName, deep);
    if (deep) {
        if (ind != kInvalidMember) {
            TopFrame().SetNotag();
        }
        UndoClassMember();
    }
    return ind;
}
コード例 #7
0
Simplex* FindContainingSimplex(DelaunayTriangulation* dt, Vertex* point)
{
  ListNode* iter = TopOfLinkedList(dt->m_Simplices);
  Simplex* simplex = (Simplex*)NextElement(dt->m_Simplices,&iter); 
  Vertex* v1,* v2,* v3,* v4;
  
  int i;
  for (i = 0; i < 4; i++)
  {
    GetFaceVerticies(simplex, i, &v1, &v2, &v3, &v4);
    
    if ((orient3dfast(v1->m_Point, v2->m_Point, v3->m_Point, point->m_Point) < 0) && simplex->m_NeighbourSimplices[i])
    {
      simplex = simplex->m_NeighbourSimplices[i];
      i = -1;
    }
  }
    
  return simplex;
}
コード例 #8
0
//moves onto the next list in the current node's list. If the current
//element is a list, it will be searched through recursively. Calling this continually
//will iterate through all lists in the tree. Returns NULL if no more
CLTANode* CLTANodeIterator::NextList()
{
	//just run through the elements until we hit a list one
	do
	{
		CLTANode* pCurr = NextElement();

		//see if we hit the end
		if(pCurr == NULL)
		{
			return NULL;
		}

		//otherwise, see if it is a list
		if(pCurr->IsList())
		{
			return pCurr;
		}

	}while(1); //keep going til we have to bail or find a list
}
コード例 #9
0
//moves onto the next element (either a value or list). If the current
//element is a list, it will be searched through recursively. Calling this continually
//will iterate through all elements in the tree. Returns NULL if no more
CLTANode* CLTANodeIterator::NextElement()
{
	//sanity checks
	ASSERT(GetHead());

	//get the current element

	CLTANode* pCurr = NULL;

	if(GetElementIndex() < GetHead()->GetNumElements())
	{
		pCurr = GetHead()->GetElement(GetElementIndex());
	}
	else
	{
		//pop the stack if we can
		if(m_nStackPos == 0)
		{
			//we can't pop!
			return NULL;
		}

		//pop the node
		PopNode();

		return NextElement();
	}

	//okay, we have successfully found an item, we need to move onto the next one

	SetElementIndex(GetElementIndex() + 1);

	//if the current is a list, we need to pop into it
	if(pCurr->IsList())
	{
		PushNode(pCurr);
	}

	return pCurr;
}
コード例 #10
0
TMemberIndex CObjectIStreamJson::BeginChoiceVariant(const CChoiceTypeInfo* choiceType)
{
    if ( !NextElement() )
        return kInvalidMember;
    string tagName = ReadKey();
    bool deep = false;
    TMemberIndex ind = FindDeep(choiceType->GetVariants(), tagName, deep);
    if (deep) {
        if (ind == kInvalidMember) {
            const CItemsInfo& items = choiceType->GetItems();
            TMemberIndex first = items.FirstIndex();
            if (items.GetItemInfo(first)->GetId().IsAttlist()) {
                ind = first;
            }
        }
        if (ind != kInvalidMember) {
            TopFrame().SetNotag();
        }
        UndoClassMember();
    }
    return ind;
}
コード例 #11
0
void CObjectIStreamJson::ReadAnyContentObject(CAnyContentObject& obj)
{
    obj.Reset();
    string value;
    string name = ReadKey();
    obj.SetName(name);
    if (PeekChar(true) == '{') {
        StartBlock('{');        
        while (NextElement()) {
            name = ReadKey();
            value = ReadValue();
            if (name[0] != '#') {
                obj.AddAttribute(name,kEmptyStr,value);
            } else {
                obj.SetValue(value);
            }
        }
        EndBlock('}');
        return;
    }
    value = ReadValue();
    obj.SetValue(value);
}
コード例 #12
0
ファイル: PlayerObject.cpp プロジェクト: Picopic/Possession
void PlayerObject::Update(float deltatime)
{
	changed_element = false;

	destroy_fire = 0;
	destroy_water = 0;
	destroy_wood = 0;
	add_fire = 0;
	add_water = 0;
	add_wood = 0;
	add_element = false;

	current_animation->Update(deltatime);

	add_element = false;

	if(!dead)
	{
		//collision timer
		if(!can_collide)
		{
			collision_refresh_timer += deltatime;
			
			position.x += deltatime * knockback_speed * collision_direction.x;
			position.y += deltatime * knockback_speed * collision_direction.y;

			//can collide again
			if(collision_refresh_timer > knockback_time)
			{
				can_collide = true;
				collision_refresh_timer = 0.0f;
			}
		}
		else
		{
			//Shooting
			if(created_projectile)
			{
				shooting_delay += deltatime;
			}
			if(shooting_delay == 0.001f || shooting_delay > 0.2)
			{
				//If you are not shooting, then you are able to move
				Movement(deltatime);
				//If you are not shooting, then you are able to use souls
				Souls();

				//Elemental swap
				if(sf::Keyboard::isKeyPressed(sf::Keyboard::R) && !element_changed && CanChangeElement())
				{
					element_changed = true;

					NextElement();
				}
				if(element_changed)
				{
					element_changed_delay += deltatime;
					if(element_changed_delay > 0.5f)
					{
						element_changed = false;
						element_changed_delay = 0.0f;
					}
				}
			}

			if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && !created_projectile)
			{
				create_projectile = true;
				created_projectile = true;
				if(direction.x == 1)
				{
					SetCurrentAnimation(ATTACKRIGHT);
				}
				else
				{
					SetCurrentAnimation(ATTACKLEFT);
				}

			}
			else
			{
				create_projectile = false;
			}

			if(shooting_delay > delay)
			{
				shooting_delay = 0.001f;
				created_projectile = false;
			}

			//end of shooting

			//timern till lost souls
			if(used_lost_souls)
			{
				lost_souls_counter += deltatime;
				if(lost_souls_counter > 0.3)
				{
					used_lost_souls = false;
					lost_souls_counter = 0.0f;
				}
			}
		}
	}

	//death
	else
	{
		if(collider != nullptr)
		{
			delete collider;
			collider = nullptr;
		}
		death_animation_time += deltatime;
		if(death_animation_time > current_animation->GetNumberOfFrames() * current_animation->GetFrameDuration())
		{
			flagged_for_death = true;
		}
	}

	//Lastly update the collider and the sprites position
	if(hasCollider())
	{
		collider->position.x = position.x + entity_offset_x;
		collider->position.y = position.y + entity_offset_y;
		hitbox.setPosition(sf::Vector2f(collider->position.x, collider->position.y));
	}
	current_animation->getSprite()->setPosition(position.x, position.y);
}
コード例 #13
0
/* accumulate the residual force on the specified node */
void FSDielectricElastomer2DT::AddNodalForce(const FieldT& field, int node, dArrayT& force)
{
	/* not my field */
//	if (&field != &(Field())) return;

	/* quick exit */
	bool hasnode = false;
	for (int i=0; i < fBlockData.Length() && !hasnode; i++)
		if (fConnectivities[i]->HasValue(node)) hasnode = true;
	if (!hasnode) return;

	/* set components and weights */
	double constMa = 0.0;
	double constKd = 0.0;

	/* components dicated by the algorithm */
	int formMa = fIntegrator->FormMa(constMa);
	int formKd = fIntegrator->FormKd(constKd);

	/* body forces */
	int formBody = 0;
	if (fMassType != kNoMass &&
	   (fBodySchedule && fBody.Magnitude() > kSmall))
	{
		cout << "\nWarning: Body forces not yet implemented in DielectricElastomer2DT";
		if (!formMa) constMa = 1.0; /* override */
	}

	/* override controller */
	if (fMassType == kNoMass) formMa = 0;

	/* temp for nodal force */
	dArrayT nodalforce;

	bool axisymmetric = Axisymmetric();
	Top();
	while (NextElement())
	{
		int nodeposition;
		const iArrayT& nodes_u = CurrentElement().NodesU();
		if (nodes_u.HasValue(node, nodeposition))
		{
			/* initialize */
			fRHS = 0.0;

			/* global shape function values */
			SetGlobalShape();

			/* internal force contribution */
			if (formKd) FormKd(constKd);

			/* inertia forces */
			if (formMa)
			{
				SetLocalU(fLocAcc);
				FormMa(fMassType, constMa*fCurrMaterial->Density(), axisymmetric, &fLocAcc, NULL, NULL);
			}
	
			/* mechanical and electrical reaction forces */
			double mr1, mr2, er1;
			dArrayT react(2);
			
			/* loop over nodes (double-noding OK) */
			int dex = 0;
			int dex2 = 0;
			for (int i = 0; i < nodes_u.Length(); i++)
			{
				if (nodes_u[i] == node)
				{
					/* not my field - electrical */
					if (&field != &(Field()))
					{
						er1 = fRHS[dex2+2*NumElementNodes()];
						react[0] = er1;
					}
					else	// otherwise do mechanical
					{
						mr1 = fRHS[dex];
						mr2 = fRHS[dex+1];	
						react[0] = mr1;
						react[1] = mr2;
					}
					
					/* components for node - mechanical + electrical DOFs */
					nodalforce.Set(TotalNumDOF(), react.Pointer(0));

					/* accumulate */
					force += nodalforce;
				}
				dex += NumDOF();
				dex2 += 1;
			}
		}
	}
}
コード例 #14
0
bool CObjectIStreamJson::BeginContainerElement(TTypeInfo elementType)
{
    return NextElement();
}
コード例 #15
0
  //
  // extrapolate from integration points and compute output nodal/element
  // values
  //
  void FSDielectricElastomer2DT::ComputeOutput(const iArrayT& n_codes,
      dArray2DT& n_values, const iArrayT& e_codes, dArray2DT& e_values)
  {
    //
    // number of output values
    //
    int n_out = n_codes.Sum();
    int e_out = e_codes.Sum();

    // nothing to output
    if (n_out == 0 && e_out == 0) return;

    // dimensions
    int nsd = NumSD();
    int ndof = NumDOF();
    int nen = NumElementNodes();
    int nnd = ElementSupport().NumNodes();

    // reset averaging work space
    ElementSupport().ResetAverage(n_out);

    // allocate element results space
    e_values.Dimension(NumElements(), e_out);

    // nodal work arrays
    dArray2DT nodal_space(nen, n_out);
    dArray2DT nodal_all(nen, n_out);
    dArray2DT coords, disp;
    dArray2DT nodalstress, princstress, matdat;
    dArray2DT energy, speed;
    dArray2DT ndElectricScalarPotential;
    dArray2DT ndElectricDisplacement;
    dArray2DT ndElectricField;

    // ip values
    dArrayT ipmat(n_codes[iMaterialData]), ipenergy(1);
    dArrayT ipspeed(nsd), ipprincipal(nsd);
    dMatrixT ippvector(nsd);

    // set shallow copies
    double* pall = nodal_space.Pointer();
    coords.Alias(nen, n_codes[iNodalCoord], pall);
    pall += coords.Length();
    disp.Alias(nen, n_codes[iNodalDisp], pall);
    pall += disp.Length();

    nodalstress.Alias(nen, n_codes[iNodalStress], pall);
    pall += nodalstress.Length();
    princstress.Alias(nen, n_codes[iPrincipal], pall);
    pall += princstress.Length();
    energy.Alias(nen, n_codes[iEnergyDensity], pall);
    pall += energy.Length();
    speed.Alias(nen, n_codes[iWaveSpeeds], pall);
    pall += speed.Length();
    matdat.Alias(nen, n_codes[iMaterialData], pall);
    pall += matdat.Length();

    ndElectricDisplacement.Alias(nen, n_codes[ND_ELEC_DISP], pall);
    pall += ndElectricDisplacement.Length();

    ndElectricField.Alias(nen, n_codes[ND_ELEC_FLD], pall);
    pall += ndElectricField.Length();
    
    ndElectricScalarPotential.Alias(nen, n_codes[ND_ELEC_POT_SCALAR], pall);
    pall += ndElectricScalarPotential.Length();

    // element work arrays
    dArrayT element_values(e_values.MinorDim());
    pall = element_values.Pointer();
    dArrayT centroid, ip_centroid, ip_mass;
    dArrayT ip_coords(nsd);
    if (e_codes[iCentroid]) {
      centroid.Alias(nsd, pall);
      pall += nsd;
      ip_centroid.Dimension(nsd);
    }
    if (e_codes[iMass]) {
      ip_mass.Alias(NumIP(), pall);
      pall += NumIP();
    }
    double w_tmp, ke_tmp;
    double mass;
    double& strain_energy = (e_codes[iStrainEnergy])
        ? *pall++
        : w_tmp;
    double& kinetic_energy = (e_codes[iKineticEnergy])
        ? *pall++
        : ke_tmp;
    dArrayT linear_momentum, ip_velocity;

    if (e_codes[iLinearMomentum]) {
      linear_momentum.Alias(ndof, pall);
      pall += ndof;
      ip_velocity.Dimension(ndof);
    } else if (e_codes[iKineticEnergy]) ip_velocity.Dimension(ndof);

    dArray2DT ip_stress;
    if (e_codes[iIPStress]) {
      ip_stress.Alias(NumIP(), e_codes[iIPStress] / NumIP(), pall);
      pall += ip_stress.Length();
    }
    dArray2DT ip_material_data;
    if (e_codes[iIPMaterialData]) {
      ip_material_data.Alias(NumIP(), e_codes[iIPMaterialData] / NumIP(), pall);
      pall += ip_material_data.Length();
      ipmat.Dimension(ip_material_data.MinorDim());
    }

    dArray2DT ipElectricDisplacement;
    if (e_codes[IP_ELEC_DISP]) {
      ipElectricDisplacement.Alias(NumIP(), NumSD(), pall);
      pall += NumIP() * NumSD();
    }

    dArray2DT ipElectricField;
    if (e_codes[IP_ELEC_FLD]) {
      ipElectricField.Alias(NumIP(), NumSD(), pall);
      pall += NumIP() * NumSD();
    }

    // check that degrees are displacements
    int interpolant_DOF = InterpolantDOFs();

    Top();
    while (NextElement()) {

      if (CurrentElement().Flag() == ElementCardT::kOFF) continue;

      // initialize
      nodal_space = 0.0;

      // global shape function values
      SetGlobalShape();

      // collect nodal values
      if (e_codes[iKineticEnergy] || e_codes[iLinearMomentum]) {
        if (fLocVel.IsRegistered())
          SetLocalU(fLocVel);
        else
          fLocVel = 0.0;
      }

      // coordinates and displacements all at once
      if (n_codes[iNodalCoord]) fLocInitCoords.ReturnTranspose(coords);
      if (n_codes[iNodalDisp]) {
        if (interpolant_DOF)
          fLocDisp.ReturnTranspose(disp);
        else
          NodalDOFs(CurrentElement().NodesX(), disp);
      }

      if (n_codes[ND_ELEC_POT_SCALAR]) {
        if (interpolant_DOF) {
          fLocScalarPotential.ReturnTranspose(ndElectricScalarPotential);
        } else {
          NodalDOFs(CurrentElement().NodesX(), ndElectricScalarPotential);
        }
      }

      // initialize element values
      mass = strain_energy = kinetic_energy = 0;
      if (e_codes[iCentroid]) centroid = 0.0;
      if (e_codes[iLinearMomentum]) linear_momentum = 0.0;
      const double* j = fShapes->IPDets();
      const double* w = fShapes->IPWeights();

      // integrate
      dArray2DT Na_X_ip_w;
      fShapes->TopIP();
      while (fShapes->NextIP() != 0) {

        // density may change with integration point
        double density = fCurrMaterial->Density();

        // element integration weight
        double ip_w = (*j++) * (*w++);

        if (qNoExtrap) {
          Na_X_ip_w.Dimension(nen, 1);
          for (int k = 0; k < nen; k++) {
            Na_X_ip_w(k, 0) = 1.;
          }
        }

        // get Cauchy stress
        const dSymMatrixT& stress = fCurrMaterial->s_ij();
        dSymMatrixT strain;

        // stresses
        if (n_codes[iNodalStress]) {
          if (qNoExtrap) {
            for (int k = 0; k < nen; k++) {
              nodalstress.AddToRowScaled(k, Na_X_ip_w(k, 0), stress);
            }
          } else {
            fShapes->Extrapolate(stress, nodalstress);
          }
        }

        if (e_codes[iIPStress]) {
          double* row = ip_stress(fShapes->CurrIP());
          strain.Set(nsd, row);
          strain = stress;
          row += stress.Length();
          strain.Set(nsd, row);
          fCurrMaterial->Strain(strain);
        }

        // wave speeds
        if (n_codes[iWaveSpeeds]) {
          // acoustic wave speeds
          fCurrMaterial->WaveSpeeds(fNormal, ipspeed);
          if (qNoExtrap) {
            for (int k = 0; k < nen; k++) {
              speed.AddToRowScaled(k, Na_X_ip_w(k, 0), ipspeed);
            }
          } else {
            fShapes->Extrapolate(ipspeed, speed);
          }
        }

        // principal values - compute principal before smoothing
        if (n_codes[iPrincipal]) {
          // compute eigenvalues
          stress.PrincipalValues(ipprincipal);

          if (qNoExtrap) {
            for (int k = 0; k < nen; k++) {
              princstress.AddToRowScaled(k, Na_X_ip_w(k, 0), ipprincipal);
            }
          } else {
            fShapes->Extrapolate(ipprincipal, princstress);
          }
        }

        // strain energy density
        if (n_codes[iEnergyDensity] || e_codes[iStrainEnergy]) {
          double ip_strain_energy = fCurrMaterial->StrainEnergyDensity();

          // nodal average
          if (n_codes[iEnergyDensity]) {
            ipenergy[0] = ip_strain_energy;
            if (qNoExtrap) {
              for (int k = 0; k < nen; k++) {
                energy.AddToRowScaled(k, Na_X_ip_w(k, 0), ipenergy);
              }
            } else {
              fShapes->Extrapolate(ipenergy, energy);
            }
          }

          // integrate over element
          if (e_codes[iStrainEnergy]) {
            strain_energy += ip_w * ip_strain_energy;
          }

        }

        // material stuff
        if (n_codes[iMaterialData] || e_codes[iIPMaterialData]) {
          // compute material output
          fCurrMaterial->ComputeOutput(ipmat);

          // store nodal data
          if (n_codes[iMaterialData]) {
            if (qNoExtrap) {
              for (int k = 0; k < nen; k++) {
                matdat.AddToRowScaled(k, Na_X_ip_w(k, 0), ipmat);
              }
            } else {
              fShapes->Extrapolate(ipmat, matdat);
            }
          }

          // store element data
          if (e_codes[iIPMaterialData]) {
            ip_material_data.SetRow(fShapes->CurrIP(), ipmat);
          }
        }

        // mass averaged centroid
        if (e_codes[iCentroid] || e_codes[iMass]) {
          // mass
          mass += ip_w * density;

          // integration point mass
          if (e_codes[iMass]) ip_mass[fShapes->CurrIP()] = ip_w * density;

          // moment
          if (e_codes[iCentroid]) {
            fShapes->IPCoords(ip_centroid);
            centroid.AddScaled(ip_w * density, ip_centroid);
          }
        }

        // kinetic energy/linear momentum
        if (e_codes[iKineticEnergy] || e_codes[iLinearMomentum]) {
          // velocity at integration point
          fShapes->InterpolateU(fLocVel, ip_velocity);
          double ke_density = 0.5 * density * dArrayT::Dot(ip_velocity,
              ip_velocity);

          // kinetic energy
          if (e_codes[iKineticEnergy]) {
            kinetic_energy += ip_w * ke_density;
          }

          // linear momentum
          if (e_codes[iLinearMomentum]) {
            linear_momentum.AddScaled(ip_w * density, ip_velocity);
          }

        }

        // electric displacements
        const dArrayT& D = fCurrMaterial->D_I();
        if (n_codes[ND_ELEC_DISP]) {
          if (qNoExtrap) {
            for (int k = 0; k < nen; k++) {
              ndElectricDisplacement.AddToRowScaled(k, Na_X_ip_w(k, 0), D);
            }
          } else {
            fShapes->Extrapolate(D, ndElectricDisplacement);
          }
        }

        // electric field
        const dArrayT& E = fCurrMaterial->E_I();
        if (n_codes[ND_ELEC_FLD]) {
          if (qNoExtrap) {
            for (int k = 0; k < nen; k++) {
              ndElectricField.AddToRowScaled(k, Na_X_ip_w(k, 0), E);
            }
          } else {
            fShapes->Extrapolate(E, ndElectricField);
          }
        }

      }

      // copy in the cols
      int colcount = 0;
      nodal_all.BlockColumnCopyAt(disp, colcount);
      colcount += disp.MinorDim();

      nodal_all.BlockColumnCopyAt(coords, colcount);
      colcount += coords.MinorDim();

      if (qNoExtrap) {
        double nip(fShapes->NumIP());
        nodalstress /= nip;
        princstress /= nip;
        energy /= nip;
        speed /= nip;
        matdat /= nip;
        ndElectricDisplacement /= nip;
        ndElectricField /= nip;
        ndElectricScalarPotential /= nip;
      }
      nodal_all.BlockColumnCopyAt(nodalstress, colcount);
      colcount += nodalstress.MinorDim();

      nodal_all.BlockColumnCopyAt(princstress, colcount);
      colcount += princstress.MinorDim();

      nodal_all.BlockColumnCopyAt(energy, colcount);
      colcount += energy.MinorDim();

      nodal_all.BlockColumnCopyAt(speed, colcount);
      colcount += speed.MinorDim();

      nodal_all.BlockColumnCopyAt(matdat, colcount);
      colcount += matdat.MinorDim();

      nodal_all.BlockColumnCopyAt(ndElectricDisplacement, colcount);
      colcount += ndElectricDisplacement.MinorDim();

      nodal_all.BlockColumnCopyAt(ndElectricField, colcount);
      colcount += ndElectricField.MinorDim();

      nodal_all.BlockColumnCopyAt(ndElectricScalarPotential, colcount);
      colcount += ndElectricScalarPotential.MinorDim();

      // accumulate - extrapolation done from ip's to corners => X nodes
      ElementSupport().AssembleAverage(CurrentElement().NodesX(), nodal_all);

      // element values
      if (e_codes[iCentroid]) centroid /= mass;

      // store results
      e_values.SetRow(CurrElementNumber(), element_values);

    }

    // get nodally averaged values
    const OutputSetT& output_set = ElementSupport().OutputSet(fOutputID);
    const iArrayT& nodes_used = output_set.NodesUsed();
    dArray2DT extrap_values(nodes_used.Length(), n_out);
    extrap_values.RowCollect(nodes_used, ElementSupport().OutputAverage());

    int tmpDim = extrap_values.MajorDim();
    n_values.Dimension(tmpDim, n_out);
    n_values.BlockColumnCopyAt(extrap_values, 0);
   }
コード例 #16
0
int XmppMessageReciveTask::ProcessStart(void)
{
    static buzz::StaticQName QN_DELAY = { "urn:xmpp:delay", "delay" };

    // 获取下一个stanza
    const auto stanza = NextStanza();
    if (stanza == nullptr)
    {
        return STATE_BLOCKED;
    }

    // 获取消息体
    const auto body = stanza->FirstNamed(buzz::QN_BODY);
    if (body == nullptr)
    {
        return STATE_BLOCKED;
    }

    XmppMessageInfo message;

    // 消息id
    message.SetUid(Utf8ToWStr(stanza->Attr(buzz::QN_ID)));
    // 消息类型
    message.SetType(Utf8ToWStr(stanza->Attr(buzz::QN_TYPE)));

    // 获取发送人
    std::wstring from(Utf8ToWStr(stanza->Attr(buzz::QN_FROM)));
    message.SetFrom(from);
    message.SetFromResource(from);

    // 获取接收人
    message.SetTo(Utf8ToWStr(stanza->Attr(buzz::QN_TO)));
    message.SetToResource(Utf8ToWStr(stanza->Attr(buzz::QN_TO)));

    // 获取消息
    message.SetContent(conv.from_bytes(body->BodyText()));

    // 获取时间
    const auto delay = stanza->FirstNamed(QN_DELAY);
    if (delay != nullptr)
    {
        message.SetTime(Utf8ToWStr(delay->Attr(buzz::kQnStamp)));
    }

    // 是否离线消息
    message.SetIsOfflineMsg(delay != nullptr);

    // 获取主题
    const auto subject = stanza->FirstNamed(buzz::QN_SUBJECT);
    if (subject != nullptr)
    {
        message.SetSubject(Utf8ToWStr(subject->BodyText()));

        // 主题数据
        if (subject->HasAttr(buzz::QN_VALUE))
        {
            message.SetSubjectValue(Utf8ToWStr(subject->Attr(buzz::QN_VALUE)));
        }
    }

    // 获取扩展数据
    auto extention = stanza->FirstNamed(QN_EXTENTION);
    if (extention != nullptr)
    {
        std::map<std::wstring, std::wstring> mapValue;

        auto elChild = extention->FirstElement();
        while (elChild != nullptr)
        {
            auto name = elChild->Name().LocalPart();
            mapValue.emplace(Utf8ToWStr(name), Utf8ToWStr(elChild->BodyText().c_str()));

            elChild = elChild->NextElement();
        }

        message.SetExtention(mapValue);
    }

    MessageReceived(message);

    return STATE_START;
}
コード例 #17
0
ファイル: PlayerObject.cpp プロジェクト: Picopic/Possession
//COLLISION
void PlayerObject::OnCollision(Entity* collision_entity, Type collision_type, Vector2 offset, Alignment collision_alignment)
{
	if(collision_alignment == LOSTSOUL)
	{
		collectedSouls++;
		hasLostSoul = true;
	}
	else if(collision_alignment == ALTAR)
	{
		add_element = true;
		if(fire_elements <= 0)
		{
			fire_elements += 1;
			add_fire = 1;
		}
		if(water_elements <= 0)
		{
			water_elements += 1;
			add_water = 1;
		}
		if(wood_elements <= 0)
		{
			wood_elements += 1;		
			add_wood = 1;
		}
	}
	else if(collision_alignment == WALL)
	{
		can_collide = false;
	}
	else
	{
		can_collide = false;
		switch (collision_type)
		{
		case FIRE:
			
			if(type == FIRE)
			{
				fire_elements -= 2;
				destroy_fire = 2;
				
				if(fire_elements <= 0)
				{
					NextElement();
					fire_elements = 0;
				}
			}
			else if(type == WATER)
			{
				water_elements--;
				destroy_water = 1;

				if(water_elements <= 0)
				{
					NextElement();
					water_elements = 0;
				}
			}
			else if(type == WOOD)
			{
				wood_elements -= 3;
				destroy_wood = 3;
				if(wood_elements <= 0)
				{
					NextElement();
					wood_elements = 0;
				}
			}

			break;
		case WATER:

			if(type == FIRE)
			{
				fire_elements -= 3;
				destroy_fire = 3;

				if(fire_elements <= 0)
				{
					NextElement();
					fire_elements = 0;
				}
			}
			else if(type == WATER)
			{
				water_elements -= 2;
				destroy_water = 2;

				if(water_elements <= 0)
				{
					NextElement();
					water_elements = 0;
				}
			}
			else if(type == WOOD)
			{
				wood_elements--;
				destroy_wood = 1;

				if(wood_elements <= 0)
				{
					NextElement();
					wood_elements = 0;
				}
			}

			break;
		case WOOD:

			if(type == FIRE)
			{
				fire_elements--;
				destroy_fire = 1;

				if(fire_elements <= 0)
				{
					NextElement();
					fire_elements = 0;
				}
			}
			else if(type == WATER)
			{
				water_elements -= 3;
				destroy_water = 3;

				if(water_elements <= 0)
				{
					NextElement();
					water_elements = 0;
				}
			}
			else if(type == WOOD)
			{
				wood_elements -= 2;
				destroy_wood = 2;

				if(wood_elements <= 0)
				{
					NextElement();
					wood_elements = 0;
				}
			}

			break;
		}
	}
	if(collision_alignment == FIREFOEBULLET || collision_alignment == WATERFOEBULLET || collision_alignment == WOODFOEBULLET)
	{
		collision_direction = collision_entity->getDirection();
	}
	else
	{
		collision_direction.x = -direction.x;
		collision_direction.y = -direction.y;
	}
	
	
	
	std::cout << "Fire: " << fire_elements << std::endl;
	std::cout << "Water: " << water_elements << std::endl;
	std::cout << "Wood: " << wood_elements << std::endl;
	std::cout << "Souls: " << collectedSouls << "\n" << std::endl;

}