Beispiel #1
0
void
MaterialPropertyStorage::initStatefulProps(MaterialData & material_data,
                                           const std::vector<std::shared_ptr<Material>> & mats,
                                           unsigned int n_qpoints,
                                           const Elem & elem,
                                           unsigned int side /* = 0*/)
{
  // NOTE: since materials are storing their computed properties in MaterialData class, we need to
  // juggle the memory between MaterialData and MaterialProperyStorage classes

  initProps(material_data, elem, side, n_qpoints);

  // copy from storage to material data
  swap(material_data, elem, side);
  // run custom init on properties
  for (const auto & mat : mats)
    mat->initStatefulProperties(n_qpoints);

  swapBack(material_data, elem, side);

  if (!hasStatefulProperties())
    return;

  // This second call to initProps covers cases where code in
  // "init[Qp]StatefulProperties" may have called a get/declare for a stateful
  // property affecting the _stateful_prop_id_to_prop_id vector among other
  // things.  This is necessary because a call to
  // getMaterialProperty[Old/Older] can potentially trigger a material to
  // become stateful that previously wasn't.  This needs to go after the
  // swapBack.
  initProps(material_data, elem, side, n_qpoints);

  // Copy the properties to Old and Older as needed
  for (unsigned int i = 0; i < _stateful_prop_id_to_prop_id.size(); ++i)
  {
    auto curr = props(&elem, side)[i];
    auto old = propsOld(&elem, side)[i];
    auto older = propsOlder(&elem, side)[i];
    for (unsigned int qp = 0; qp < n_qpoints; ++qp)
    {
      old->qpCopy(qp, curr, qp);
      if (hasOlderProperties())
        older->qpCopy(qp, curr, qp);
    }
  }
}
Beispiel #2
0
void
MaterialPropertyStorage::restrictStatefulProps(
    const std::vector<std::pair<unsigned int, QpMap>> & coarsening_map,
    const std::vector<const Elem *> & coarsened_element_children,
    QBase & qrule,
    QBase & qrule_face,
    MaterialData & material_data,
    const Elem & elem,
    int input_side)
{
  unsigned int side;

  bool doing_a_side = input_side != -1;

  unsigned int n_qpoints = 0;

  if (!doing_a_side)
  {
    side = 0; // Use 0 for the elem
    n_qpoints = qrule.n_points();
  }
  else
  {
    side = input_side;
    n_qpoints = qrule_face.n_points();
  }

  initProps(material_data, elem, side, n_qpoints);

  // Copy from the child stateful properties
  for (unsigned int qp = 0; qp < coarsening_map.size(); qp++)
  {
    const std::pair<unsigned int, QpMap> & qp_pair = coarsening_map[qp];
    unsigned int child = qp_pair.first;

    mooseAssert(child < coarsened_element_children.size(),
                "Coarsened element children vector not initialized");
    const Elem * child_elem = coarsened_element_children[child];
    const QpMap & qp_map = qp_pair.second;

    for (unsigned int i = 0; i < _stateful_prop_id_to_prop_id.size(); ++i)
    {
      mooseAssert(props().contains(child_elem),
                  "Child element pointer is not in the MaterialProps data structure");

      PropertyValue * child_property = props(child_elem, side)[i];
      PropertyValue * parent_property = props(&elem, side)[i];

      parent_property->qpCopy(qp, child_property, qp_map._to);

      propsOld(&elem, side)[i]->qpCopy(qp, propsOld(child_elem, side)[i], qp_map._to);
      if (hasOlderProperties())
        propsOlder(&elem, side)[i]->qpCopy(qp, propsOlder(child_elem, side)[i], qp_map._to);
    }
  }
}
/**
 * Initializes the configuration sub-system.
 *
 * @return <tt>0</tt> for success, otherwise a non-zero value
 */
int
initializeConfig(void) {
    if (implementationProperties != NULL) {
        /* Already initialized. */
        return 0;
    }

    if (initProps(&implementationProperties, &IMPL_PROPERTY_FILE,
                  storage_get_config_root(INTERNAL_STORAGE_ID)) != 0) {
        return -1;
    }

    if (initProps(&applicationProperties, &APPL_PROPERTY_FILE,
                  storage_get_config_root(INTERNAL_STORAGE_ID)) != 0) {
        finalizeConfig();
        return -1;
    }

    /*
     * Make sure the configuration was specified, because
     * some older code requires it in the CLDC classes.
     */
    if (getSystemProperty(DEFAULT_CONFIGURATION) == NULL) {
        setSystemProperty(DEFAULT_CONFIGURATION, DEFAULT_CLDC);
    }

    if (getSystemProperty(PROFILES_PROP_NAME) == NULL) {
        setSystemProperty(PROFILES_PROP_NAME, DEFAULT_PROFILE);
    }

    if (getSystemProperty(ENCODING_PROP_NAME) == NULL) {
        setSystemProperty(ENCODING_PROP_NAME, DEFAULT_CHARACTER_ENCODING);
    }

    return 0;
}
Beispiel #4
0
void
MaterialPropertyStorage::copy(MaterialData & material_data,
                              const Elem & elem_to,
                              const Elem & elem_from,
                              unsigned int side,
                              unsigned int n_qpoints)
{
  initProps(material_data, elem_to, side, n_qpoints);
  for (unsigned int i = 0; i < _stateful_prop_id_to_prop_id.size(); ++i)
  {
    for (unsigned int qp = 0; qp < n_qpoints; ++qp)
    {
      props(&elem_to, side)[i]->qpCopy(qp, props(&elem_from, side)[i], qp);
      propsOld(&elem_to, side)[i]->qpCopy(qp, propsOld(&elem_from, side)[i], qp);
      if (hasOlderProperties())
        propsOlder(&elem_to, side)[i]->qpCopy(qp, propsOlder(&elem_from, side)[i], qp);
    }
  }
}
Beispiel #5
0
SSATmp* allocObjFast(HTS& env, const Class* cls) {
  auto registerObj = [&] (SSATmp* obj) {
    if (RuntimeOption::EnableObjDestructCall && cls->getDtor()) {
      gen(env, RegisterLiveObj, obj);
    }
    return obj;
  };

  // If it's an extension class with a custom instance initializer,
  // that init function does all the work.
  if (cls->instanceCtor()) {
    auto const obj = gen(env, ConstructInstance, ClassData(cls));
    return registerObj(obj);
  }

  // Make sure our property init vectors are all set up.
  const bool props = cls->pinitVec().size() > 0;
  const bool sprops = cls->numStaticProperties() > 0;
  assert((props || sprops) == cls->needInitialization());
  if (cls->needInitialization()) {
    if (props) initProps(env, cls);
    if (sprops) initSProps(env, cls);
  }

  /*
   * Allocate the object.  This must happen after we do sinits for consistency
   * with the interpreter about o_id assignments.  Also, the prop
   * initialization above can throw, so we don't want to have the object
   * allocated already.
   */
  auto const ssaObj = gen(env, NewInstanceRaw, ClassData(cls));

  // Initialize the properties
  gen(env, InitObjProps, ClassData(cls), ssaObj);

  // Call a custom initializer if one exists
  if (cls->callsCustomInstanceInit()) {
    return registerObj(gen(env, CustomInstanceInit, ssaObj));
  }

  return registerObj(ssaObj);
}
Beispiel #6
0
bool DrmPlane::init()
{
    qCDebug(KWIN_DRM) << "Initialize plane" << m_id;
    ScopedDrmPointer<_drmModePlane, &drmModeFreePlane> p(drmModeGetPlane(m_fd, m_id));

    if (!p) {
        qCWarning(KWIN_DRM) << "Failed to get kernel plane" << m_id;
        return false;
    }

    m_possibleCrtcs = p->possible_crtcs;

    m_formats.resize(p->count_formats);
    for (int i = 0; i < p->count_formats; i++) {
        m_formats[i] = p->formats[i];
    }

    if (!initProps()) {
        return false;
    }
    return true;
}
Beispiel #7
0
bool GameScene::init(){
	bool bRet = false;
	do{
		CC_BREAK_IF(!CCLayer::init());
		setTouchEnabled(true);

		initBgItems(GameData::getLevel());

		//scrollBg1 = CCSprite::createWithTexture(scrollBg->getTexture());

		overText = CCLabelTTF::create("Game OVer!!!\nTouch screen to replay,Let's go","黑体",30);
		overText->setColor(ccc3(255,0,0));
		overText->setPosition(ccp(425,240));
		overText->setVisible(false);

		//CC_BREAK_IF(!scrollBg1);

		addChild(overText,1);
		//addChild(scrollBg1);
		//scrollBg1->setAnchorPoint(ccp(0,0));

		//scrollBg1->setPosition(ccp(scrollBg->getContentSize().width,0));
		//初始化地图
		map = new Map(1,this);
		//生成主角
		hero = new Role(this);

		CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("game.plist","game.png");
		CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("prop_effect.plist","prop_effect.png");
		initProps(200);

		CCSprite* scorePeach = CCSprite::createWithSpriteFrameName("score_peach.png");
		SETANCHPOS(scorePeach,600,420,0,0);
		addChild(scorePeach,10);


		CCSprite* distance = CCSprite::createWithSpriteFrameName("distance.png");
		SETANCHPOS(distance,0,430,0,0);
		addChild(distance,10);

		CCSprite* best = CCSprite::createWithSpriteFrameName("best.png");
		SETANCHPOS(best,20,390,0,0);
		addChild(best,10);

		scoreValue = CCLabelAtlas::create("0","num/num_green.png",28,40,'0');
		SETANCHPOS(scoreValue,680,420,0,0);
		addChild(scoreValue,10);

		distanceValue = CCLabelAtlas::create("0","num/num_yellow.png",28,40,'0');
		SETANCHPOS(distanceValue,170,430,0,0);
		addChild(distanceValue,10);

		char b[20];
		sprintf(b,"%d",GameData::getBest());
		bestValue = CCLabelAtlas::create(b,"num/num_red.png",28,40,'0');
		SETANCHPOS(bestValue,140,390,0,0);
		addChild(bestValue,10);

		progressBg = CCSprite::createWithSpriteFrameName("progress.png");
		SETANCHPOS(progressBg,200,0,0,0);
		addChild(progressBg,14);

		progressLeaf = CCSprite::createWithSpriteFrameName("thumb_leaf.png");
		SETANCHPOS(progressLeaf,200,0,0,0);
		addChild(progressLeaf,14);

		CCMenu* menu = CCMenu::create();
		SETANCHPOS(menu,20,0,0,0);
		menu->setTag(99);
		addChild(menu,12);

		CCMenuItemSprite* pause = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("pause.png"),
			CCSprite::createWithSpriteFrameName("pause.png"),this,menu_selector(GameScene::btnCallback));
		SETANCHPOS(pause,0,0,0,0);
		pause->setTag(1);
		menu->addChild(pause);


		schedule(schedule_selector(GameScene::bgMove));
		bRet = true;
	}while(0);
	return bRet;
}
Beispiel #8
0
void GameScene::bgMove(float dt){
	//游戏数据存储,根据移动的速度计算得分和距离
	if(over){
		return;
	}

	srand(time(0));
	GameData::addLoop();
	if(GameData::getLoop() % 5 == 0){
		GameData::addDistance(getSpeed() * 2);
		GameData::addScore(getSpeed() * 5);
	}
	char v[20];
	sprintf(v,"%d",GameData::getDistance());
	distanceValue->setString(v);
	sprintf(v,"%d",GameData::getScore());
	scoreValue->setString(v);

	//地图移动
	map->mapMove(this,hero);

	//判断是否碰到道具
	for(int j = 0; j < 2; j++){
		for(int i = 0;i < props[j]->count(); i++){
			Prop* temp =  (Prop*)props[j]->objectAtIndex(i);
			temp->move(map->getSpeed());
			if(temp->collision(hero->getSprite())){
				if(temp->getType() == Prop::PROP){
					changeIndex = rand() % 3 + 4;
					hero->hideSprite();
					CCSprite* temp = CCSprite::create();
					SETANCHPOS(temp, hero->getSprite()->getPositionX(),hero->getSprite()->getPositionY(),0.5,0.5);
					addChild(temp,20);
					temp->runAction(CCSequence::create(createAni("change",5,0.05f),CCCallFuncN::create(this,callfuncN_selector(GameScene::tempCallback)),NULL));

				}else{
					GameData::addScore(temp->getScore());
				}
				temp->setCollision(this);
			}
		}
	}

	if(((Prop*)(props[propIndex]->lastObject()))->getPosX() < 0){
		for(int i = 0;i < props[propIndex]->count();i++){
			props[propIndex]->objectAtIndex(i)->release();
		}

		props[propIndex]->removeAllObjects();
		if(++propIndex > 1){
			propIndex = 0;
		}

		if(map->getPercent() > 0.7){
			initProps(2200);
		}else{
			initProps(854);
		}

	}

	if(hero->getState() != Role::ATTACK){
		/*	map->clearChange();
		clearChange();*/

		if(hero->getSprite()->getPositionY() < 130){
			if(map->onLand(hero->getSprite())){
				if(hero->getState() != Role::FALL && hero->getState() != Role::ATTACK){
					hero->changeState(Role::NORMAL);
				}else if(hero->getState() == Role::ATTACK){
					hero->hold();
				}
			}else{
				if(!hero->isProtected() && hero->getState() != Role::ATTACK && hero->getState() != Role::HOLD){

					hero->fall();
				}else if(hero->isProtected()){
					hero->changeState(Role::NORMAL);
				}
			}
		}else if(hero->getSprite()->getPositionY() == 130){
			if(!map->onLand(hero->getSprite()) && !hero->isProtected()) {
				hero->fall();
			}else if(hero->getState() == Role::FALL && hero->isProtected()){
				hero->changeState(Role::NORMAL);
			}
		}
	}else{
		/*	map->tempChange(SPEEDUP);
		tempChange(SPEEDUP);*/
	}

	//武器是否否使用
	if(map->weaponOn(hero)){
		hero->weaponDone(map,dt);
	}

	if(hero->isDie()){
		over = true;	
		hero->setDie(this);
		CCSprite* temp = hero->getSprite();
		temp->runAction(CCSequence::create(CCJumpTo::create(0.8, ccp(temp->getPositionX(),-200),300,1),CCCallFunc::create(this, callfunc_selector(GameScene::gameOver)),NULL));
		//gameOver();
	}else if(strcmp(hero->getChange(), "") != 0){  //变身状态
		totalTime += dt;
		if(totalTime > 8){
			hero->resumeNormal();
			totalTime = 0;
			map->clearChange();
			clearChange();
		}
	}

	if(items->getPositionX() > -items->getContentSize().width){
		items->setPositionX(items->getPositionX() - getSpeed() / 2);
	}else{
		if(rand() % 10 == 5){
			items->setPositionX(854);
		}
	}
}
Beispiel #9
0
void
MaterialPropertyStorage::prolongStatefulProps(
    const std::vector<std::vector<QpMap>> & refinement_map,
    QBase & qrule,
    QBase & qrule_face,
    MaterialPropertyStorage & parent_material_props,
    MaterialData & child_material_data,
    const Elem & elem,
    const int input_parent_side,
    const int input_child,
    const int input_child_side)
{
  mooseAssert(input_child != -1 || input_parent_side == input_child_side, "Invalid inputs!");

  unsigned int n_qpoints = 0;

  // If we passed in -1 for these then we really need to store properties at 0
  unsigned int parent_side = input_parent_side == -1 ? 0 : input_parent_side;
  unsigned int child_side = input_child_side == -1 ? 0 : input_child_side;

  if (input_child_side == -1) // Not doing side projection (ie, doing volume projection)
    n_qpoints = qrule.n_points();
  else
    n_qpoints = qrule_face.n_points();

  child_material_data.resize(n_qpoints);

  unsigned int n_children = elem.n_children();

  std::vector<unsigned int> children;

  if (input_child != -1) // Passed in a child explicitly
    children.push_back(input_child);
  else
  {
    children.resize(n_children);
    for (unsigned int child = 0; child < n_children; child++)
      children[child] = child;
  }

  for (const auto & child : children)
  {
    // If we're not projecting an internal child side, but we are projecting sides, see if this
    // child is on that side
    if (input_child == -1 && input_child_side != -1 && !elem.is_child_on_side(child, parent_side))
      continue;

    const Elem * child_elem = elem.child_ptr(child);

    mooseAssert(child < refinement_map.size(), "Refinement_map vector not initialized");
    const std::vector<QpMap> & child_map = refinement_map[child];

    initProps(child_material_data, *child_elem, child_side, n_qpoints);

    for (unsigned int i = 0; i < _stateful_prop_id_to_prop_id.size(); ++i)
    {
      // Copy from the parent stateful properties
      for (unsigned int qp = 0; qp < refinement_map[child].size(); qp++)
      {
        PropertyValue * child_property = props(child_elem, child_side)[i];
        mooseAssert(props().contains(&elem),
                    "Parent pointer is not in the MaterialProps data structure");
        PropertyValue * parent_property = parent_material_props.props(&elem, parent_side)[i];

        child_property->qpCopy(qp, parent_property, child_map[qp]._to);
        propsOld(child_elem, child_side)[i]->qpCopy(
            qp, parent_material_props.propsOld(&elem, parent_side)[i], child_map[qp]._to);
        if (hasOlderProperties())
          propsOlder(child_elem, child_side)[i]->qpCopy(
              qp, parent_material_props.propsOlder(&elem, parent_side)[i], child_map[qp]._to);
      }
    }
  }
}
Beispiel #10
0
int
main (int ac, char *av[])
{
	FILE *fp;

	/* save our name for usage() */
	me = av[0];

	/* crack args */
	while (--ac && **++av == '-') {
	    char *s = *av;
	    while (*++s) {
		switch (*s) {
		case 'b':	/* beep when true */
		    bflag++;
		    break;
		case 'd':
		    if (ac < 2) {
			fprintf (stderr, "-d requires open fileno\n");
			usage();
		    }
		    directfd = atoi(*++av);
		    ac--;
		    break;
		case 'e':	/* print each updated expression value */
		    eflag++;
		    break;
		case 'f':	/* print final expression value */
		    fflag++;
		    break;
		case 'h':
		    if (directfd >= 0) {
			fprintf (stderr, "Can not combine -d and -h\n");
			usage();
		    }
		    if (ac < 2) {
			fprintf (stderr, "-h requires host name\n");
			usage();
		    }
		    host = *++av;
		    ac--;
		    break;
		case 'i':	/* read expression from stdin */
		    iflag++;
		    break;
		case 'o':	/* print operands as they change */
		    oflag++;
		    break;
		case 'p':
		    if (directfd >= 0) {
			fprintf (stderr, "Can not combine -d and -p\n");
			usage();
		    }
		    if (ac < 2) {
			fprintf (stderr, "-p requires tcp port number\n");
			usage();
		    }
		    port = atoi(*++av);
		    ac--;
		    break;
		case 't':
		    if (ac < 2) {
			fprintf (stderr, "-t requires timeout\n");
			usage();
		    }
		    timeout = atoi(*++av);
		    ac--;
		    break;
		case 'v':	/* verbose */
		    verbose++;
		    break;
		case 'w':	/* wait for expression to be true */
		    wflag++;
		    break;
		default:
		    fprintf (stderr, "Unknown flag: %c\n", *s);
		    usage();
		}
	    }
	}

	/* now there are ac args starting with av[0] */

	/* compile expression from av[0] or stdin */
	if (ac == 0)
	    compile (NULL);
	else if (ac == 1)
	    compile (av[0]);
	else
	    usage();

        /* open connection */
	if (directfd >= 0) {
	    fp = fdopen (directfd, "r+");
	    setbuf (fp, NULL);		/* don't absorb next guy's stuff */
	    if (!fp) {
		fprintf (stderr, "Direct fd %d: %s\n",directfd,strerror(errno));
		exit(1);
	    }
	    if (verbose)
		fprintf (stderr, "Using direct fd %d\n", directfd);
	} else {
	    fp = openINDIServer();
	    if (verbose)
		fprintf (stderr, "Connected to %s on port %d\n", host, port);
	}

	/* build a parser context for cracking XML responses */
	lillp = newLilXML();

	/* set up to catch an io timeout function */
	signal (SIGALRM, onAlarm);

	/* send getProperties */
	getProps(fp);

	/* initialize all properties */
	initProps(fp);

	/* evaluate expression, return depending on flags */
	return (runEval(fp));
}