TEST_F(AnimationInterpolationEffectTest, MultipleInterpolations)
{
    InterpolationEffect interpolationEffect;
    interpolationEffect.addInterpolation(SampleInterpolation::create(InterpolableNumber::create(10), InterpolableNumber::create(15)),
        RefPtr<TimingFunction>(), 1, 2, 1, 3);
    interpolationEffect.addInterpolation(SampleInterpolation::create(InterpolableNumber::create(0), InterpolableNumber::create(1)),
        LinearTimingFunction::shared(), 0, 1, 0, 1);
    interpolationEffect.addInterpolation(SampleInterpolation::create(InterpolableNumber::create(1), InterpolableNumber::create(6)),
        CubicBezierTimingFunction::preset(CubicBezierTimingFunction::Ease), 0.5, 1.5, 0.5, 1.5);

    Vector<RefPtr<Interpolation>> activeInterpolations;
    interpolationEffect.getActiveInterpolations(-0.5, duration, activeInterpolations);
    EXPECT_EQ(0ul, activeInterpolations.size());

    interpolationEffect.getActiveInterpolations(0, duration, activeInterpolations);
    EXPECT_EQ(1ul, activeInterpolations.size());
    EXPECT_FLOAT_EQ(0, getInterpolableNumber(activeInterpolations.at(0)));

    interpolationEffect.getActiveInterpolations(0.5, duration, activeInterpolations);
    EXPECT_EQ(2ul, activeInterpolations.size());
    EXPECT_FLOAT_EQ(0.5f, getInterpolableNumber(activeInterpolations.at(0)));
    EXPECT_FLOAT_EQ(1, getInterpolableNumber(activeInterpolations.at(1)));

    interpolationEffect.getActiveInterpolations(1, duration, activeInterpolations);
    EXPECT_EQ(2ul, activeInterpolations.size());
    EXPECT_FLOAT_EQ(10, getInterpolableNumber(activeInterpolations.at(0)));
    EXPECT_FLOAT_EQ(5.0282884f, getInterpolableNumber(activeInterpolations.at(1)));

    interpolationEffect.getActiveInterpolations(1, duration * 1000, activeInterpolations);
    EXPECT_EQ(2ul, activeInterpolations.size());
    EXPECT_FLOAT_EQ(10, getInterpolableNumber(activeInterpolations.at(0)));
    EXPECT_FLOAT_EQ(5.0120168f, getInterpolableNumber(activeInterpolations.at(1)));

    interpolationEffect.getActiveInterpolations(1.5, duration, activeInterpolations);
    EXPECT_EQ(1ul, activeInterpolations.size());
    EXPECT_FLOAT_EQ(12.5f, getInterpolableNumber(activeInterpolations.at(0)));

    interpolationEffect.getActiveInterpolations(2, duration, activeInterpolations);
    EXPECT_EQ(1ul, activeInterpolations.size());
    EXPECT_FLOAT_EQ(15, getInterpolableNumber(activeInterpolations.at(0)));
}
// FIXME: Re-enable this test once compositing of CompositeAdd is supported.
TEST(AnimationKeyframeEffectModel, DISABLED_PerKeyframeComposite)
{
    AnimatableValueKeyframeVector keyframes(2);
    keyframes[0] = AnimatableValueKeyframe::create();
    keyframes[0]->setOffset(0.0);
    keyframes[0]->setPropertyValue(CSSPropertyLeft, pixelAnimatableValue(3.0).get());
    keyframes[1] = AnimatableValueKeyframe::create();
    keyframes[1]->setOffset(1.0);
    keyframes[1]->setPropertyValue(CSSPropertyLeft, pixelAnimatableValue(5.0).get());
    keyframes[1]->setComposite(EffectModel::CompositeAdd);

    AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectModel::create(keyframes);
    Vector<RefPtr<Interpolation>> values;
    effect->sample(0, 0.6, duration, values);
    expectDoubleValue(3.0 * 0.4 + (7.0 + 5.0) * 0.6, values.at(0));
}
Example #3
0
bool CircleMenu::init(Vector<Node*> vet, Size contentSize)
{
	this->setContentSize(contentSize);
	int length = vet.size();
	for (int i = 0; i < length; i++)
	{
		Node *node = vet.at(i);
		float angel = (i + 1) * (360 / length);
		node->setUserData(new float(angel));
		this->addChild(node);
	}

	unscheduleUpdate();
	scheduleUpdate();
	return true;
}	
Example #4
0
static String getCookieString(const Vector<RefPtr<ParsedCookie> >& cookies)
{
    double curTime = currentTime();
    StringBuilder cookieBuilder;

    size_t count = cookies.size();
    for (size_t i = 0; i < count; ++i) {
        RefPtr<ParsedCookie> current = cookies.at(i);
        if (i > 0)
            cookieBuilder.append("; ");
        current->setLastAccessed(curTime);
        cookieBuilder.append(current->toNameValuePair());
    }

    return cookieBuilder.toString();
}
Example #5
0
static v8::Handle<v8::Value> getNamedItems(HTMLCollection* collection, AtomicString name, v8::Isolate* isolate)
{
    Vector<RefPtr<Node> > namedItems;
    collection->namedItems(name, namedItems);

    if (!namedItems.size())
        return v8::Handle<v8::Value>();

    if (namedItems.size() == 1)
        return toV8(namedItems.at(0).release(), isolate);

    if (collection->type() == FormControls)
        return toV8(collection->base()->radioNodeList(name).get());

    return toV8(V8NamedNodesCollection::create(namedItems), isolate);
}
void AsyncScrollingCoordinator::syncChildPositions(const LayoutRect& viewportRect)
{
    if (!m_scrollingStateTree->rootStateNode())
        return;

    Vector<OwnPtr<ScrollingStateNode>>* children = m_scrollingStateTree->rootStateNode()->children();
    if (!children)
        return;

    // FIXME: We'll have to traverse deeper into the tree at some point.
    size_t size = children->size();
    for (size_t i = 0; i < size; ++i) {
        ScrollingStateNode* child = children->at(i).get();
        child->syncLayerPositionForViewportRect(viewportRect);
    }
}
Example #7
0
void Transform::performTransform(data::Value &value, Vector<data::Value *> &stack, const Pair<String, Vector<String>> &it) const {
	if (value.hasValue(it.first)) {
		if (it.second.empty()) {
			value.erase(it.first);
		} else if (it.second.size() == 1) {
			if (it.second.front().empty()) {
				value.erase(it.first);
			} else if (it.first != it.second.front()) {
				value.setValue(std::move(value.getValue(it.first)), it.second.front());
				value.erase(it.first);
			}
		} else {
			if (it.first != it.second.front()) {
				data::Value *target = &value;
				size_t size = it.second.size();
				size_t stackLevel = 0;
				size_t i = 0;
				while (i < size && it.second.at(i).empty()) {
					++ stackLevel;
					++ i;
				}
				if (stackLevel <= stack.size() && i < size) {
					if (stackLevel > 0) {
						target = stack.at(stack.size() - stackLevel);
					}

					auto &key = it.second.at(i);
					for (; i < size - 1; i++) {
						auto &val = target->getValue(key);
						if (val.isDictionary()) {
							target = &val;
						} else if (val.isNull()) {
							target = &target->setValue(Value(Value::Type::DICTIONARY), key);
						} else {
							break;
						}
					}

					if (i == size - 1) {
						target->setValue(std::move(value.getValue(it.first)), it.second.back());
						value.erase(it.first);
					}
				}
			}
		}
	}
}
Example #8
0
void ScrollingTree::updateTreeFromStateNode(ScrollingStateNode* stateNode)
{
    // This fuction recurses through the ScrollingStateTree and updates the corresponding ScrollingTreeNodes.
    // Find the ScrollingTreeNode associated with the current stateNode using the shared ID and our HashMap.
    ScrollingTreeNodeMap::const_iterator it = m_nodeMap.find(stateNode->scrollingNodeID());

    if (it != m_nodeMap.end()) {
        ScrollingTreeNode* node = it->value;
        node->update(stateNode);
    } else {
        // If the node isn't found, it's either new and needs to be added to the tree, or there is a new ID for our
        // root node.
        if (!stateNode->parent()) {
            // This is the root node.
            m_rootNode->setScrollingNodeID(stateNode->scrollingNodeID());
            m_nodeMap.set(stateNode->scrollingNodeID(), m_rootNode.get());
            m_rootNode->update(stateNode);
        } else {
            OwnPtr<ScrollingTreeNode> newNode;
            if (stateNode->isScrollingNode())
                newNode = ScrollingTreeScrollingNode::create(this);
            else if (stateNode->isFixedNode())
                newNode = ScrollingTreeFixedNode::create(this);
            else
                ASSERT_NOT_REACHED();
            ScrollingTreeNode* newNodeRawPtr = newNode.get();
            m_nodeMap.set(stateNode->scrollingNodeID(), newNodeRawPtr);
            ScrollingTreeNodeMap::const_iterator it = m_nodeMap.find(stateNode->parent()->scrollingNodeID());
            ASSERT(it != m_nodeMap.end());
            if (it != m_nodeMap.end()) {
                ScrollingTreeNode* parent = it->value;
                newNode->setParent(parent);
                parent->appendChild(newNode.release());
            }
            newNodeRawPtr->update(stateNode);
        }
    }

    // Now update the children if we have any.
    Vector<OwnPtr<ScrollingStateNode> >* stateNodeChildren = stateNode->children();
    if (!stateNodeChildren)
        return;

    size_t size = stateNodeChildren->size();
    for (size_t i = 0; i < size; ++i)
        updateTreeFromStateNode(stateNodeChildren->at(i).get());
}
/** 幅優先探索 */
void BoardLayer::breadthFirstSearch(int sId, int gId) {
    // 全ノードの探索情報リセット
    for (auto node: allNode) {
        node->dataInit();
    }
    // ゴールノードの探索情報リセット
    allNode.at(gId)->setComeNode(allNode.at(gId));
    allNode.at(gId)->setCost(0);
    allNode.at(gId)->setDepth(0);
    
    Vector<NodeLayer*> searchList;
    searchList.pushBack(allNode.at(gId)); // スタート位置(ゴール)の登録
    while (!searchList.empty()) {
        NodeLayer* searchNode = searchList.at(0);
//        log("%dの隣探索", searchNode->getId());
        // 探索リストの先頭の隣のノード一覧
        int count = 0;
        for (auto neighborNode: searchNode->getNeighborNode()) {
            // 未探索の場合探索リストに追加(depth付ける)
            if (neighborNode->getDepth() == -1) {
                // 壁の場合探索リストに追加しない
                if (neighborNode->getKind() == 1) {
                    //                    continue;
                }else {
                    searchList.pushBack(neighborNode);
                    neighborNode->setDepth(searchNode->getDepth()+1);
                }
//                if (neighborNode->getKind() == 0) {
//                    searchList.pushBack(neighborNode);
//                    neighborNode->setDepth(searchNode->getDepth()+1);
//                }
            }
            // ここまで+隣nodeまでの距離
            int cost = searchNode->getCost() + searchNode->getNeighborNodeDist().at(count);
            // 新規(1000)もしくは,最短なら登録
            if (neighborNode->getCost() > cost) {
//            log("隣の設定コスト%d", neighborNode->getCost());
//            log("新規コスト%d", cost);
                neighborNode->setCost(cost);
                neighborNode->setComeNode(searchNode);
//                log("  %dnodeは%dからきたとセット",neighborNode->getId(), searchNode->getId());
            }
            count ++;
        }
        searchList.erase(0);
    }
}
static void getNamedItems(HTMLOptionsCollection* collection, const AtomicString& name, const CallbackInfo& info)
{
    Vector<RefPtr<Node> > namedItems;
    collection->namedItems(name, namedItems);

    if (!namedItems.size()) {
        v8SetReturnValueNull(info);
        return;
    }

    if (namedItems.size() == 1) {
        v8SetReturnValueFast(info, namedItems.at(0).release(), collection);
        return;
    }

    v8SetReturnValueFast(info, NamedNodesCollection::create(namedItems), collection);
}
Example #11
0
const Size TDDHelper::alignMenuItem(Menu *menu, int parentWidth, int numCol, int lineSpace)
{
	Vector<Node *> childrenNode = menu->getChildren();
	
	int width = parentWidth;
	int colWidth = width/numCol;
	
	int x;
	int y = 0;
	int maxH = 0;
	int spacing = lineSpace;
	int totalH = 0;
	int firstX = colWidth/2 + (numCol - 1) * colWidth;
	
	int count = (int) childrenNode.size();
	int remain = (count - 1) % numCol;
	x = remain * colWidth + colWidth/2;
	
	for(int i=(count-1); i>=0; i--) {
		Node *node = childrenNode.at(i);
		MenuItem *item = dynamic_cast<MenuItem *>(node);
		if(item == NULL) {
			continue;
		}
		
		Size itemSize = item->getContentSize();
		// log("menuItem: %f x %f", itemSize.width, itemSize.height);
		
		item->setAnchorPoint(Point(0.5, 0));
		item->setPosition(Point(x, y));
		
		// log("menuItem: %f x %f pos: x=%d y=%d", itemSize.width, itemSize.height, x, y);
		
		x -= colWidth;
		maxH = MAX(maxH, itemSize.height);
		
		if(x < 0) {
			totalH += maxH + spacing;
			y += (maxH + spacing);
			x = firstX;
		}
	}
	
	
	return Size(width, totalH);
}
Example #12
0
void HTMLFormControlsCollection::namedGetter(const AtomicString& name, bool& returnValue0Enabled, RefPtr<RadioNodeList>& returnValue0, bool& returnValue1Enabled, RefPtr<Node>& returnValue1)
{
    Vector<RefPtr<Node> > namedItems;
    this->namedItems(name, namedItems);

    if (!namedItems.size())
        return;

    if (namedItems.size() == 1) {
        returnValue1Enabled = true;
        returnValue1 = namedItems.at(0);
        return;
    }

    returnValue0Enabled = true;
    returnValue0 = this->ownerNode()->radioNodeList(name);
}
static void getNamedItems(HTMLOptionsCollection* collection, const AtomicString& name, const HolderContainer& holder)
{
    Vector<RefPtr<Node> > namedItems;
    collection->namedItems(name, namedItems);

    if (!namedItems.size()) {
        v8SetReturnValueNull(holder);
        return;
    }

    if (namedItems.size() == 1) {
        v8SetReturnValue(holder, toV8Fast(namedItems.at(0).release(), holder, collection));
        return;
    }

    v8SetReturnValue(holder, toV8Fast(NamedNodesCollection::create(namedItems), holder, collection));
}
Example #14
0
void Entity::onEnter()
{
    Node::onEnter();

    this->setHp(this->entityParameter.initialHp);

    Vector<Node*> children = this->getChildren();

    for (int i = 0, last = (int)children.size(); i < last; ++i) {
        Sprite* sprite = dynamic_cast<Sprite*>(children.at(i));

        if (! sprite) {
            continue;
        }
        sprite->setCascadeColorEnabled(false);
    }
}
Example #15
0
void HTMLOptionsCollection::anonymousNamedGetter(const AtomicString& name, bool& returnValue0Enabled, RefPtr<NodeList>& returnValue0, bool& returnValue1Enabled, RefPtr<Node>& returnValue1)
{
    Vector<RefPtr<Node> > namedItems;
    this->namedItems(name, namedItems);

    if (!namedItems.size())
        return;

    if (namedItems.size() == 1) {
        returnValue1Enabled = true;
        returnValue1 = namedItems.at(0);
        return;
    }

    returnValue0Enabled = true;
    returnValue0 = NamedNodesCollection::create(namedItems);
}
TEST(AnimationKeyframeEffectModel, MultipleKeyframesWithSameOffset)
{
    AnimatableValueKeyframeVector keyframes(9);
    keyframes[0] = AnimatableValueKeyframe::create();
    keyframes[0]->setOffset(0.0);
    keyframes[0]->setPropertyValue(CSSPropertyLeft, unknownAnimatableValue(0.0).get());
    keyframes[1] = AnimatableValueKeyframe::create();
    keyframes[1]->setOffset(0.1);
    keyframes[1]->setPropertyValue(CSSPropertyLeft, unknownAnimatableValue(1.0).get());
    keyframes[2] = AnimatableValueKeyframe::create();
    keyframes[2]->setOffset(0.1);
    keyframes[2]->setPropertyValue(CSSPropertyLeft, unknownAnimatableValue(2.0).get());
    keyframes[3] = AnimatableValueKeyframe::create();
    keyframes[3]->setOffset(0.5);
    keyframes[3]->setPropertyValue(CSSPropertyLeft, unknownAnimatableValue(3.0).get());
    keyframes[4] = AnimatableValueKeyframe::create();
    keyframes[4]->setOffset(0.5);
    keyframes[4]->setPropertyValue(CSSPropertyLeft, unknownAnimatableValue(4.0).get());
    keyframes[5] = AnimatableValueKeyframe::create();
    keyframes[5]->setOffset(0.5);
    keyframes[5]->setPropertyValue(CSSPropertyLeft, unknownAnimatableValue(5.0).get());
    keyframes[6] = AnimatableValueKeyframe::create();
    keyframes[6]->setOffset(0.9);
    keyframes[6]->setPropertyValue(CSSPropertyLeft, unknownAnimatableValue(6.0).get());
    keyframes[7] = AnimatableValueKeyframe::create();
    keyframes[7]->setOffset(0.9);
    keyframes[7]->setPropertyValue(CSSPropertyLeft, unknownAnimatableValue(7.0).get());
    keyframes[8] = AnimatableValueKeyframe::create();
    keyframes[8]->setOffset(1.0);
    keyframes[8]->setPropertyValue(CSSPropertyLeft, unknownAnimatableValue(7.0).get());

    AnimatableValueKeyframeEffectModel* effect = AnimatableValueKeyframeEffectModel::create(keyframes);
    Vector<RefPtr<Interpolation>> values;
    effect->sample(0, 0.0, duration, values);
    expectDoubleValue(0.0, values.at(0));
    effect->sample(0, 0.2, duration, values);
    expectDoubleValue(2.0, values.at(0));
    effect->sample(0, 0.4, duration, values);
    expectDoubleValue(3.0, values.at(0));
    effect->sample(0, 0.5, duration, values);
    expectDoubleValue(5.0, values.at(0));
    effect->sample(0, 0.6, duration, values);
    expectDoubleValue(5.0, values.at(0));
    effect->sample(0, 0.8, duration, values);
    expectDoubleValue(6.0, values.at(0));
    effect->sample(0, 1.0, duration, values);
    expectDoubleValue(7.0, values.at(0));
}
Example #17
0
void RefsGroup::fillSbgp(SampleToGroupBox& sbgp)
{
    sbgp.setGroupingType(mGroupingType);

    std::uint32_t sampleIdx = 0;
    Vector<std::uint32_t> entryIdx;
    for (auto sample : mRefsList)
    {
        Vector<std::uint32_t> v = sample;
        for (std::uint32_t& refIdx : v)
        {
            refIdx += 1;
        }
        RefsEntry element = std::make_tuple(mSampleId.at(sampleIdx), v);
        entryIdx.push_back(
            static_cast<uint32_t>(std::find(mIdxEntry.begin(), mIdxEntry.end(), element) - mIdxEntry.begin() + 1));
        sampleIdx += 1;
    }

    Vector<std::tuple<std::uint32_t, std::uint32_t>> runsList;
    std::uint32_t prevIdx = entryIdx.at(0);
    std::uint32_t idxRuns = 0;
    for (auto currIdx : entryIdx)
    {
        if (currIdx == prevIdx)
        {
            idxRuns += 1;
        }
        else
        {
            runsList.push_back(std::make_tuple(prevIdx, idxRuns));
            prevIdx = currIdx;
            idxRuns = 1;
        }
    }
    runsList.push_back(std::make_tuple(prevIdx, idxRuns));

    for (auto entry : runsList)
    {
        std::uint32_t idx;
        std::uint32_t run;
        std::tie(idx, run) = entry;
        sbgp.addSampleRun(run, idx);
    }
}
Example #18
0
void LoadCount::update(float dt)
{
	//挨个加载,加载完一个后隔一帧后再加载...
	//if(this->mLoadCount >0 )
	//{
	//	if(this->mIsNextStart)
	//	{
	//		if(this->mIsDelayOneFrame)
	//		{
	//			this->mIsNextStart = false;
	//			this->mIsDelayOneFrame = false;

	//			CCArray *tempResArray = this->mResArray;
	//			int currLoadIndex = this->mLoadResTotalCount - this->mLoadCount;
	//			IRes* tempRes= dynamic_cast<IRes*>(tempResArray->objectAtIndex(currLoadIndex));
	//			tempRes->loadResAsyn(this);
	//		} else 
	//		{
	//				this->mIsDelayOneFrame = true;
	//		}
	//	} 
	//
	//}
	Vector<IRes*> *tempOneByOneLoadResArray = this->mOneByOneLoadResArray;
	if(mOneByOneLoadCount > 0 )
	{
		if(this->mIsNextStart)
		{
				//==========================
				//依靠引擎的计数功能判断游戏是否已经运行了一帧
			if (this->mFrameCheckObj->getReferenceCount()==1)
				{
					this->mIsNextStart = false;

					
					int currLoadIndex = this->mOneByOneLoadResTotalCount - this->mOneByOneLoadCount;
					IRes* tempRes= dynamic_cast<IRes*>(tempOneByOneLoadResArray->at(currLoadIndex));
					tempRes->loadResAsyn(this);
				}
				//==========================
		}
	
	}

}
Example #19
0
void MenuBoxManager::setBoxWithList(Vector<ImageInfoParser*> imgInfo)
{
    if(_vButton.size() > 0)
    {
        log("ButtonVector has data will be remove");
        _vButton.clear();
    }
    if(getChildByTag(TAG_MENUBOXLIST))
    {
        getChildByTag(TAG_MENUBOXLIST)->removeFromParent();
    }
    for(int i = 0 ; i < imgInfo.size() ; i++)
    {
        ImageInfoParser* info = static_cast<ImageInfoParser*>(imgInfo.at(i));

        auto button = ui::Button::create("Main_BoxUp-hd.png", "Main_BoxDown-hd.png", "Main_BoxDown-hd.png");
        //        button->setTitleText("text");
        button->setTag(TAG_MAIN_BOX + info->getidx()->intValue());
        button->addTouchEventListener([&](Ref* sender, ui::Widget::TouchEventType type) {
            switch (type)
            {
            case ui::Widget::TouchEventType::BEGAN:

                break;
            case ui::Widget::TouchEventType::ENDED:

                buttonCallBack(sender);
                break;
            default:
                break;
            }
        });




        setTypeTitle(button, info->gettitle()->getCString());
        setTypeInfo(button, __String::createWithFormat("%s / %s",info->getspace()->getCString(),info->getair()->getCString())->getCString());
        setPrice(button, __String::createWithFormat("%s", info->getprice()->getCString())->intValue());
        setImageWithName(button, __String::createWithFormat("%s", info->getimgName()->getCString())->getCString());

        _vButton.pushBack(button);
    }
    setListView();
}
Example #20
0
Sprite* CommonLayer::createBird()
{
    auto cache = SpriteFrameCache::getInstance();
    int randomIndex = rand()%3;
    std::string frameName = "";
    Vector<SpriteFrame*> birdFrame;
    for (int i = 0; i < 3; i++) {
        frameName = "bird" + std::to_string(randomIndex) + "_" + std::to_string(i) + ".png";
        auto frame = cache->getSpriteFrameByName(frameName);
        birdFrame.pushBack(frame);
    }
    auto bird = Sprite::createWithSpriteFrame(birdFrame.at(1));
    auto animation = Animation::createWithSpriteFrames(birdFrame);
    animation->setDelayPerUnit(0.1);
    auto animate = Animate::create(animation);
    bird->runAction(RepeatForever::create(animate));
    return bird;
}
Example #21
0
void HTMLOptionsCollection::namedGetter(const AtomicString& name, bool& returnValue0Enabled, RefPtr<NodeList>& returnValue0, bool& returnValue1Enabled, RefPtr<Element>& returnValue1)
{
    Vector<RefPtr<Element> > namedItems;
    this->namedItems(name, namedItems);

    if (!namedItems.size())
        return;

    if (namedItems.size() == 1) {
        returnValue1Enabled = true;
        returnValue1 = namedItems.at(0);
        return;
    }

    // FIXME: The spec and Firefox do not return a NodeList. They always return the first matching Element.
    returnValue0Enabled = true;
    returnValue0 = NamedNodesCollection::create(namedItems);
}
Example #22
0
void GameLayer::CheckWin()
{
	int iWin = 0;
	TouchSprite* Card;
	for (int k = 0; k< spCard.size(); k++)
	{
		Card = (TouchSprite*)spCard.at(k);
		if (Card->getTag() == 999){
			iWin++;
		}
	}
	if (iWin == spCard.size())
	{
		//well , you win
		//Card->GameWinJump();
		Card->unschedule(schedule_selector(GameLayer::updateTimeLabel));
		Card->scheduleOnce(schedule_selector(TouchSprite::GameWinJump), 1.0f);
	}
}
Example #23
0
    int main() {
        Vector v;

        for (int i = 0; i < 12; ++i) {
            v.push_back(i);
            cout << "push " << v.size() << "/" << v.alloc() << endl;
        }

        for (int i = 0; i < 9; ++i) {
            cout << "pop " << v.size() << "/" << v.alloc() << endl;
            v.pop_back();
        }

        for (int i = 0; i < v.size(); ++i) {
            cout << v.at(i) << endl;
        }

        return 0;
    }
Example #24
0
void MovieView::playFrame(int index)
{
	for (Sprite *s : this->m_sprites){
		s->setVisible(false);
	}
	for (auto i = 0; i < this->m_layerFrames.size(); i++) {
		Sprite *sprite = NULL;
		if (this->m_sprites.size() > i) {
			sprite = this->m_sprites.at(i);
		}
		else {
			sprite = Sprite::create();
			this->addChild(sprite);
			this->m_sprites.pushBack(sprite);
		}

		Vector<FrameInfo*> frames = this->m_layerFrames.at(i);
		FrameInfo* frameInfo;
		if (frames.size() > index) {
			frameInfo = frames.at(index);
			if (frameInfo != 0 && frameInfo->url != "") 
			{
				auto sf = SpriteFrameCache::getInstance()->getSpriteFrameByName(frameInfo->url);
				sprite->setSpriteFrame(sf);
				sprite->setVisible(true);
				sprite->setFlippedX(this->m_isFlip);
				sprite->setFlippedY(this->m_isFlip);
				sprite->setPosition(Vec2(frameInfo->x, frameInfo->y));
				sprite->setScaleX(frameInfo->scaleX);
				sprite->setScaleY(frameInfo->scaleY);
				sprite->setOpacity((GLubyte)255 * frameInfo->alpha);
				sprite->setRotation(frameInfo->rotate);
			}
			else {
				sprite->setVisible(false);
			}
		}
		else {
			sprite->setVisible(false);
		}
	}
}
Example #25
0
Action* Face::createState(const std::string& patternName, int startFrame, int endFrame, float frameDuration, bool forever, bool reverse) {
    Vector<SpriteFrame*> *framesVector = this->createFrameVector(patternName,startFrame,endFrame);
	if (reverse) {
		int framesSize = framesVector->size();
		for(int i = framesSize - 1; i >= 0; i--) {
			framesVector->pushBack(framesVector->at(i));
		}
	}
    
    float delay = frameDuration / framesVector->size();
    Animation* animation = Animation::createWithSpriteFrames(*framesVector, delay);
	Animate* animate = Animate::create(animation);
	Action* action = NULL;
	if (forever) {
		action = RepeatForever::create(animate);
	} else {
		action = (Action*) animate;
	}
	return action;
}
Example #26
0
void Vector<V>::swap(Vector v2)
{
	//swaps the values
	V temp[50];
	int tempSize = v2.size();
	for (int i = 0; i < v2.size(); i++) {
		temp[i] = v2.at(i);
	}

	//clears the content in v2
	v2.clear();
	for (int i = 0; i < size(); i++) {
		v2.push_back(at(i));
	}
	//the clear() is used to set the vector size back to 0,
	clear();
	for (int i = 0; i < tempSize; i++) {
		push_back(temp[i]);
	}
}
Example #27
0
Vector Matrix :: operator*(Vector &v)
{
  
  Vector result;
  result.resize( this->nColumns);
  int size = v.giveNumberOfRows();
  double sum=0.0;
  for ( int i = 1; i<=this->nRows; i++){
    for ( int j = 1; j<=size; j++){
      
      sum += this->at(i,j) * v.at(j);
    }
    result.setValues(sum, i);
    sum = 0.0;
    
    //return *this;
  }
  return result;
  
}
Example #28
0
void CrazyScratch::updateFrame( float delta ) {
    if( !_should_recycle ) {
        _elapse += delta;
        if( _elapse > _interval ) {
            _elapse = 0;
            if( _excluded_targets.size() >= _count ) {
                this->end();
            }
            else {
                Vector<UnitNode*> candidates = _owner->getBattleLayer()->getAliveOpponentsInRange( _owner->getTargetCamp(), _last_pos, _range );
                int count = (int)candidates.size();
                if( count <= 0 ) {
                    this->end();
                }
                else {
                    bool found_target = false;
                    while( count > 0 ) {
                        int rand = Utils::randomNumber( count ) - 1;
                        UnitNode* unit = candidates.at( rand );
                        int unit_id = unit->getDeployId();
                        if( _excluded_targets.find( unit_id ) == _excluded_targets.end() ) {
                            _excluded_targets.insert( unit_id, unit );
                            _last_pos = unit->getPosition();
                            _skeleton->setPosition( _last_pos );
                            _skeleton->setLocalZOrder( _owner->getBattleLayer()->zorderForPositionOnObjectLayer( _last_pos ) );
                            found_target = true;
                            break;
                        }
                        else {
                            candidates.erase( rand );
                            count--;
                        }
                    }
                    if( !found_target ) {
                        this->end();
                    }
                }
            }
        }
    }
}
HashMap<long, SourceRange> InspectorCSSStore::getRuleRangesForStyleSheet(CSSStyleSheet* styleSheet)
{
    if (!styleSheet)
        return HashMap<long, SourceRange>();
    RefPtr<CSSRuleList> originalRuleList = CSSRuleList::create(styleSheet, false);
    StyleSheetToOffsetsMap::iterator it = m_styleSheetToOffsets.find(styleSheet);
    HashMap<long, SourceRange> result;
    Vector<SourceRange>* offsetVector = 0;
    if (it == m_styleSheetToOffsets.end()) {
        InspectorResource* resource = m_inspectorController->resourceForURL(styleSheet->finalURL().string());
        if (resource) {
            offsetVector = new Vector<SourceRange>;
            RefPtr<CSSStyleSheet> newStyleSheet = CSSStyleSheet::create(styleSheet->ownerNode());
            CSSParser p;
            CSSParser::StyleRuleRanges ruleRangeMap;
            p.parseSheet(newStyleSheet.get(), resource->sourceString(), &ruleRangeMap);
            for (unsigned i = 0, length = newStyleSheet->length(); i < length; ++i) {
                CSSStyleRule* rule = asCSSStyleRule(newStyleSheet->item(i));
                if (!rule)
                    continue;
                HashMap<CSSStyleRule*, std::pair<unsigned, unsigned> >::iterator it = ruleRangeMap.find(rule);
                if (it != ruleRangeMap.end())
                    offsetVector->append(it->second);
            }
            m_styleSheetToOffsets.set(styleSheet, offsetVector);
        }
    } else
        offsetVector = it->second;
    if (!offsetVector)
        return HashMap<long, SourceRange>();
    unsigned ruleIndex = 0;
    for (unsigned i = 0, length = styleSheet->length(); i < length; ++i) {
        ASSERT(ruleIndex < offsetVector->size());
        CSSStyleRule* rule = asCSSStyleRule(styleSheet->item(i));
        if (!rule)
            continue;
        result.set(bindRule(rule), offsetVector->at(ruleIndex));
        ruleIndex++;
    }
    return result;
}
Example #30
0
Vector Vector :: operator*(Matrix &m)
{
  
  Vector result;
  int size = m.giveNumberOfRows();
  result.resize(size);

  double sum=0.0;
  for ( int i = 1; i<=size; i++){
    for ( int j = 1; j<=this->nRows; j++){
      
      sum += m.at(i,j) * this->at(j);
    }
    result.at(i) = sum;
    sum = 0.0;
    
    //return *this;
  }
  return result;
  
}