TEST(GLObject, Value) {
    setFlag = false;

    auto object = std::make_unique<mbgl::gl::State<MockGLObject>>();
    EXPECT_EQ(object->getCurrentValue(), false);
    EXPECT_FALSE(object->isDirty());
    EXPECT_FALSE(setFlag);

    object->setDirty();
    EXPECT_TRUE(object->isDirty());

    *object = false;
    EXPECT_EQ(object->getCurrentValue(), false);
    EXPECT_FALSE(object->isDirty());
    EXPECT_TRUE(setFlag);

    setFlag = false;
    *object = true;
    EXPECT_EQ(object->getCurrentValue(), true);
    EXPECT_FALSE(object->isDirty());
    EXPECT_TRUE(setFlag);

    object->reset();
    EXPECT_EQ(object->getCurrentValue(), false);
    EXPECT_FALSE(object->isDirty());
    EXPECT_TRUE(setFlag);
}
void CGridDlg::OnBnClickedButtonDiagram() {
  if(!validate()) return;

  windowToValue();
  const GridParameters v = getCurrentValue();
  PearlDiagram diagram;
  PixRect *tmp = v.calculateImage(getImage(), &diagram);
  SAFEDELETE(tmp);

  const String dumpFileName = createTempFileName(_T("txt"));
  FILE *f = NULL;
  try {
    const String dstr = diagram.toString();
    f = MKFOPEN(dumpFileName,_T("w"));

    _ftprintf(f, _T("%s"), dstr.cstr());
    fclose(f); f = NULL;

    ExternProcess::run(false, _T("c:\\windows\\system32\\notepad.exe"), dumpFileName.cstr(), NULL);
    UNLINK(dumpFileName);
  } catch (Exception e) {
    if(f) { fclose(f); f = NULL; }
    showException(e);
  }
}
void FilledSlider::paintEvent(QPaintEvent *e) {
	Painter p(this);
	PainterHighQualityEnabler hq(p);

	p.setPen(Qt::NoPen);

	auto masterOpacity = fadeOpacity();
	auto ms = getms();
	auto disabled = isDisabled();
	auto over = getCurrentOverFactor(ms);
	auto lineWidth = _st.lineWidth + ((_st.fullWidth - _st.lineWidth) * over);
	auto lineWidthRounded = qFloor(lineWidth);
	auto lineWidthPartial = lineWidth - lineWidthRounded;
	auto seekRect = getSeekRect();
	auto value = getCurrentValue(ms);
	auto from = seekRect.x(), mid = qRound(from + value * seekRect.width()), end = from + seekRect.width();
	if (mid > from) {
		p.setOpacity(masterOpacity);
		p.fillRect(from, height() - lineWidthRounded, (mid - from), lineWidthRounded, disabled ? _st.disabledFg : _st.activeFg);
		if (lineWidthPartial > 0.01) {
			p.setOpacity(masterOpacity * lineWidthPartial);
			p.fillRect(from, height() - lineWidthRounded - 1, (mid - from), 1, disabled ? _st.disabledFg : _st.activeFg);
		}
	}
	if (end > mid && over > 0) {
		p.setOpacity(masterOpacity * over);
		p.fillRect(mid, height() - lineWidthRounded, (end - mid), lineWidthRounded, _st.inactiveFg);
		if (lineWidthPartial > 0.01) {
			p.setOpacity(masterOpacity * over * lineWidthPartial);
			p.fillRect(mid, height() - lineWidthRounded - 1, (end - mid), 1, _st.inactiveFg);
		}
	}
}
card32 Timer::getDeltaValue()
{
	card32 t = getCurrentValue();
	card32 result = t - lastTime;
	lastTime = t;
	return result;
}
void MediaSlider::paintEvent(QPaintEvent *e) {
	Painter p(this);
	PainterHighQualityEnabler hq(p);

	p.setPen(Qt::NoPen);
	p.setOpacity(fadeOpacity());

	auto horizontal = isHorizontal();
	auto ms = getms();
	auto radius = _st.width / 2;
	auto disabled = isDisabled();
	auto over = getCurrentOverFactor(ms);
	auto seekRect = getSeekRect();
	auto value = getCurrentValue(ms);

	// invert colors and value for vertical
	if (!horizontal) value = 1. - value;

	auto markerFrom = (horizontal ? seekRect.x() : seekRect.y());
	auto markerLength = (horizontal ? seekRect.width() : seekRect.height());
	auto from = _alwaysDisplayMarker ? 0 : markerFrom;
	auto length = _alwaysDisplayMarker ? (horizontal ? width() : height()) : markerLength;
	auto mid = qRound(from + value * length);
	auto end = from + length;
	auto activeFg = disabled ? _st.activeFgDisabled : anim::brush(_st.activeFg, _st.activeFgOver, over);
	auto inactiveFg = disabled ? _st.inactiveFgDisabled : anim::brush(_st.inactiveFg, _st.inactiveFgOver, over);
	if (mid > from) {
		auto fromClipRect = horizontal ? QRect(0, 0, mid, height()) : QRect(0, 0, width(), mid);
		auto fromRect = horizontal
			? QRect(from, (height() - _st.width) / 2, mid + radius - from, _st.width)
			: QRect((width() - _st.width) / 2, from, _st.width, mid + radius - from);
		p.setClipRect(fromClipRect);
		p.setBrush(horizontal ? activeFg : inactiveFg);
		p.drawRoundedRect(fromRect, radius, radius);
	}
	if (end > mid) {
		auto endClipRect = horizontal ? QRect(mid, 0, width() - mid, height()) : QRect(0, mid, width(), height() - mid);
		auto endRect = horizontal
			? QRect(mid - radius, (height() - _st.width) / 2, end - (mid - radius), _st.width)
			: QRect((width() - _st.width) / 2, mid - radius, _st.width, end - (mid - radius));
		p.setClipRect(endClipRect);
		p.setBrush(horizontal ? inactiveFg : activeFg);
		p.drawRoundedRect(endRect, radius, radius);
	}
	auto markerSizeRatio = disabled ? 0. : (_alwaysDisplayMarker ? 1. : over);
	if (markerSizeRatio > 0) {
		auto position = qRound(markerFrom + value * markerLength) - (horizontal ? seekRect.x() : seekRect.y());
		auto seekButton = horizontal
			? QRect(position, (height() - _st.seekSize.height()) / 2, _st.seekSize.width(), _st.seekSize.height())
			: QRect((width() - _st.seekSize.width()) / 2, position, _st.seekSize.width(), _st.seekSize.height());
		auto size = horizontal ? _st.seekSize.width() : _st.seekSize.height();
		auto remove = static_cast<int>(((1. - markerSizeRatio) * size) / 2.);
		if (remove * 2 < size) {
			p.setClipRect(rect());
			p.setBrush(activeFg);
			p.drawEllipse(seekButton.marginsRemoved(QMargins(remove, remove, remove, remove)));
		}
	}
}
void CGridDlg::calculate() {
  if (!validate()) return;

  setNotifyEnabled(false);
  windowToValue();
  const GridParameters v = getCurrentValue();
  GridParameters v1 = v;
  v1.m_colorCount++;
  setCurrentValue(v1);
  setNotifyEnabled(true);
  setCurrentValue(v);
}
void ContinuousSlider::setMoveByWheel(bool move) {
	if (move != moveByWheel()) {
		if (move) {
			_byWheelFinished = std_::make_unique<SingleTimer>();
			_byWheelFinished->setTimeoutHandler([this] {
				if (_changeFinishedCallback) {
					_changeFinishedCallback(getCurrentValue(getms()));
				}
			});
		} else {
			_byWheelFinished.reset();
		}
	}
}
void liveAutoLane::update(int beat, int step) {
	// Output current value to param
	float current_val = getCurrentValue(beat, step);
//	cout << "Beat: " << beat << ", Step: " << step << endl;
	int current_val_percent = current_val * 100;
	int new_val_percent = val * 100;
	if (new_val_percent != current_val_percent) {
		
		val = current_val;
		
		cout << "getCurrentValue: " << current_val_percent << endl;
		
		if (name == "crossfader") {
			sequencer->current_set->setCrossfader(current_val);
		} else if (name == "0_gain_low") {
			sequencer->current_set->getParamByName("GainLo", 0)->setVal(current_val);
		} else if (name == "1_gain_low") {
			sequencer->current_set->getParamByName("GainLo", 1)->setVal(current_val);
		}
	}
}
Exemple #9
0
 int NumberDie::roll(long r)
 {
     _currentFace = _faces.size() == 0 ? 0 : r % _faces.size() ;
     return getCurrentValue();
 }
Exemple #10
0
ReturnValue alphaBeta(Configuration v, int alpha, int beta, int depth){
// 	int counter=0;
	if (DEBUG_STACK){
		printstack();
		printf("alphabeta a=%d b=%d d=%d\n", alpha, beta, depth);
// 		printBoardNonBlock(v);
	}
	++stackcount;
	HashRetVal s;
	s=retrieve(v);
	ReturnValue ret;
	ReturnValue temp;
	ret.alpha=alpha;
	ret.beta=beta;
	if (s!=NULL) {
		switch (s->type){
			case EXACT:
				if (s->lowerbound>=beta) {
					ret.value=s->lowerbound;
					ret.move=s->mv;
					--stackcount;
					if (DEBUG_STACK){
						printstack();
						printf("hit exact 1\n");
					}
					return ret;
				}
				if (s->upperbound<=alpha) {
					ret.value=s->upperbound;
					ret.move=s->mv;
					--stackcount;
					if (DEBUG_STACK){
						printstack();
						printf("hit exact 2\n");
					}
					return ret;
				}
				ret.alpha=max(alpha, s->lowerbound);
				ret.beta=min(beta, s->upperbound);
				ret.move=s->mv;
				break;
			case FAIL_LOW:
				if (s->upperbound<=alpha) {
					ret.value=s->upperbound;
					ret.move=s->mv;
					--stackcount;
					if (DEBUG_STACK){
						printstack();
						printf("hit fail low\n");
					}
					return ret;
				}
				break;
			case FAIL_HIGH:
				if (s->lowerbound>=beta) {
					ret.value=s->lowerbound;
					ret.move=s->mv;
					--stackcount;
					if (DEBUG_STACK){
						printstack();
						printf("hit fail high\n");
					}
					return ret;
				}
				break;
			default:
				break;
		}
		free(s);
	}
	if (depth==0) {
		ChildIterator itr=getExpansion(v);
		ret.value=getCurrentValue(itr);
		ret.move=getCurrent(itr);
		releaseChildIterator(itr);
		if (getType(v)==MAXNODE)
			updateMoveHeuristic(v, ret.move.x, ret.move.y, ret.value);
		else
			updateMoveHeuristic(v, ret.move.x, ret.move.y, -ret.value);
		if (DEBUG_STACK){
			printBoardNonBlock(v);
			printstack();
			printf("eval %d\n", ret.value);
			printstack();
			printf("(%d, %d)\n", ret.move.x, ret.move.y);
		}
	}
	else if (getType(v)==MAXNODE) {
//		printf("*\n");
		ChildIterator itr=getExpansion(v);
//		printf("e: %d %d %d\n", getCurrent(itr).x, getCurrent(itr).y, depth);
		int a=alpha;
		ret.value=-FIVE_SCORE;
		ret.move=getCurrent(itr);
		if (getCurrentValue(itr)>=FIVE_SCORE){
			ret.value=FIVE_SCORE;
		}
		else {
			while (itr!=NULL && ret.value<beta) {
	//			printf("depth=%d, move=%d %d\n",
	//				depth, getCurrent(itr).x, 
	//				getCurrent(itr).y);
				if (tickTimer()==0)
					break;
				applyMove(v, getCurrent(itr));
	//			printBoardNonBlock(v);
				
				if (DEBUG_STACK){
					printstack();
					printf("black trying %d %d\n", 
						getCurrent(itr).x, getCurrent(itr).y);
				}
				
				switch (getChildrenCount(itr)){
// 					case 1:
/*						++quadcount;
						temp=alphaBeta(v, a, beta, 
								depth-((doublecount & 3)==0));*/
					case 1:
// 					case 2:
						++doublecount;
						temp=alphaBeta(v, a, beta,
								depth-1);
						--doublecount;
						break;
					default:
						temp=alphaBeta(v, a, beta, depth-1);
						break;
				}
				updateMoveHeuristic(v, temp.move.x,
									temp.move.y, temp.value);
				if (DEBUG_STACK){
					printstack();
					printf("black try %d %d, result=%d\n", 
						getCurrent(itr).x, getCurrent(itr).y,
									temp.value);
				}
				
				if (temp.value>ret.value) {
					ret.value=temp.value;
					ret.move=getCurrent(itr);
	//				printf("current black move = %d %d\n", ret.move.x, ret.move.y);
				}
				undoMove(v, getCurrent(itr));
	//			printBoard(v);
				if (a<ret.value){
					a=ret.value;
				}
	//			printf("a=%d ret.value=%d\n", a, ret.value);
				// TODO to be verified
	/*			if (temp.value<=-INFINITY){
					++counter;
				}
				if (counter>2)
					break;*/
				getNext(&itr);
	//			printf("e: %d %d\n", itr->current.x, itr->current.y);
			}
			if (DEBUG_STACK){
				if (ret.value>=beta){
					printstack();
					printf("pruned\n");
				}
			}
		}
		releaseChildIterator(itr);
	}
	else {
//		printf("-\n");
		ChildIterator itr=getExpansion(v);
//		printf("n: %d %d %d\n", getCurrent(itr).x, getCurrent(itr).y, depth);
		int b=beta;
		ret.value=FIVE_SCORE;
		ret.move=getCurrent(itr);
		if (getCurrentValue(itr)<=-FIVE_SCORE){
			ret.value=-FIVE_SCORE;
		}
		else {
			while (itr!=NULL && ret.value>alpha) {
				if (tickTimer()==0)
					break;
				applyMove(v, getCurrent(itr));
				
				if (DEBUG_STACK){
					printstack();
					printf("white trying %d %d\n", 
						getCurrent(itr).x, getCurrent(itr).y);
				}
				
				if (getChildrenCount(itr)<=1){
					++doublecount;
					temp=alphaBeta(v, alpha, b, 
							depth-1);
					--doublecount;
				}
				else {
					temp=alphaBeta(v, alpha, b, depth-1);
				}
				updateMoveHeuristic(v, temp.move.x,
									temp.move.y, -temp.value);
				
				if (DEBUG_STACK){
					printstack();
					printf("white try %d %d, result=%d\n", 
						getCurrent(itr).x, getCurrent(itr).y,
									temp.value);
					printf("retval=%d\n", ret.value);
				}
				
				if (temp.value<ret.value){
					ret.value=temp.value;
					ret.move=getCurrent(itr);
		//			printf("current white move = %d %d\n", ret.move.x, ret.move.y);
				}
				undoMove(v, getCurrent(itr));
				if (b>ret.value){
					b=ret.value;
				}
	//			printf("a=%d ret.value=%d\n", b, ret.value);
/*				if (ret.value<=-INFINITY-10)
					break;*/
				// TODO to be verified
	/*			if (temp.value>=INFINITY){
					++counter;
				}
				if (counter>2)
					break;*/
				getNext(&itr);
			}
			if (DEBUG_STACK){
				if (ret.value<=alpha){
					printstack();
					printf("pruned\n");
				}
			}
		}
		releaseChildIterator(itr);
	}

	if (ret.value<=alpha && getType(v)==MINNODE) {
		/* fail low */
		v->upperbound=ret.value;
		
		if (depth>0)
			store(v, ret.move, FAIL_LOW);
		
		/* Fail low result implies an upper bound */
	}
	else if (ret.value>alpha && ret.value<beta) {
		/* accurate window */
		v->upperbound=v->lowerbound=ret.value;
		if (depth>0)
			store(v, ret.move, EXACT);
	}
	else if (getType(v)==MINNODE && ret.value>=MAXNODE){
		/* fail high */
		v->lowerbound=ret.value;
		
		if (depth>0)
			store(v, ret.move, FAIL_HIGH);
		
	}
/*	printstack();
	printf("ab return %d (%d,%d))\n", ret.value, ret.move.x,
		  ret.move.y);*/
//	getchar();
	--stackcount;
	return ret;
}
card32 Timer::getDeltaValue(card32 lastValue)
{
	return getCurrentValue() - lastValue;
}
Timer::Timer()
{
	lastTime = getCurrentValue();
}