Exemplo n.º 1
0
void Automator::update(const ds::UpdateParams& up){

	if(!mActive) return;

	// If the client has installed actions, use those, otherwise use the defaults.
	// Probably, the defaults should be actions that are installed at construction,
	// and then removed if the client installs their own.
	if(!mFactory.empty()){
		mActioner.update(up.getDeltaTime());

		mTotal += up.getDeltaTime();

		if(mTotal >= mPeriod){
			mTotal = 0.0f;

			if(!mFreeList.empty()){
				float percent = ci::randFloat(0.0f, 1.0f);
				for(auto it = mFactory.begin(), end = mFactory.end(); it != end; ++it) {
					Factory&	f = *it;
					if(percent >= f.mMin && percent <= f.mMax && f.mFactory.get() != nullptr) {
						std::shared_ptr<BaseAction>		a = f.addAction(mFreeList, mEngine, mFrame);
						if(a != nullptr) mActioner.add(a);
						break;
					}
				}
			}
		}

		for(auto it = mSingletonList.begin(); it < mSingletonList.end(); ++it){
			(*it).get()->update(up.getDeltaTime());
		}
	}
}
Exemplo n.º 2
0
void mcafee::TickerView::updateServer( const ds::UpdateParams& p){
	inherited::updateServer(p);
	float dp = p.getDeltaTime() * mSpeed;
	std::vector<TickerItem*> finishedItems;
	float xp = 0.0f;
	for (auto it = mItems.begin(); it < mItems.end(); ++it){
		(*it)->move(-dp, 0.0f);
		xp = (*it)->getPosition().x + (*it)->getItemWidth();
		if(xp < 0.0f){
			finishedItems.push_back((*it));
		}
	}

	for (auto it = finishedItems.begin(); it < finishedItems.end(); ++it){
		for (auto tit = mItems.begin(); tit < mItems.end(); ++tit){
			if((*it) == (*tit)){
				mItems.erase(tit);
				mItems.push_back((*it));
				break;
			}
		}

		(*it)->setPosition(xp, 0.0f);
		xp += (*it)->getItemWidth();
	}
	
}
Exemplo n.º 3
0
void World::update(const ds::UpdateParams& p)
{
	mContactListener.clear();
	
	if(mFixedStep){
		mWorld->Step(mFixedStepAmount, mVelocityIterations, mPositionIterations);
	} else {
		mWorld->Step(p.getDeltaTime(), mVelocityIterations, mPositionIterations);
	}
	
	// Update all objects
	for ( b2Body* b = mWorld->GetBodyList(); b; b = b->GetNext() )
	{
		if ( b->GetType() != b2_dynamicBody )
			continue;
		if ( b->IsAwake() )
		{
			ds::ui::Sprite*	sprite = reinterpret_cast<ds::ui::Sprite*>( b->GetUserData() );
			if (sprite)
			{
				auto pos = box2CiTranslation(b->GetPosition(), sprite);
				sprite->setPosition(pos);
				sprite->setRotation(ci::toDegrees(b->GetAngle()));
			}
		}
	}
#if 0
	for ( b2Joint *j = mWorld->GetJointList(); j; j = j->GetNext() )
	{
		if ( j->IsActive() )
		{
			JointView *joint_view = reinterpret_cast<JointView *>( j->GetUserData() );
			if ( joint_view )
			{
				joint_view->updateJoint();
			}
		}
	}
	///// Sort the nodes
	//mNodeWindow->getSpriteListRef().sort( [](BaseSprite *a, BaseSprite *b)
	//{
	//	return ( a->getPosition().y < b->getPosition().y );
	//});

	//auto slist = mNodeWindow->getSpriteList();
	//for ( auto i = slist.begin(), tend = slist.end(); i != tend; i++ ) {
	//	(*i)->sendToFront();
	//}
#endif

	mContactListener.report();
}
Exemplo n.º 4
0
void GlobeView::onUpdateServer(const ds::UpdateParams& updateParams){
	setRotation(ci::vec3(getRotation().x + mXMomentum.getDelta(), getRotation().y + 5.0f * updateParams.getDeltaTime() + mYMomentum.getDelta(), 0.0f));
	mTouchGrabber.setRotation(-getRotation());
}