Example #1
0
void Pokedex::UpdateLevelsMain(int stoneCode, int stoneFactor) {
	if (stoneCode <1 || stoneFactor < 1)
	{
		throw InvalidInput();
	}
	int numOfPokemons = mainIdTree.getSize();
	if (numOfPokemons < 1)
	{
		return;
	}
	Pokemon* notAffected = new Pokemon[numOfPokemons];
	Pokemon* affected = new Pokemon[numOfPokemons];
	Pokemon* currentArray = mainLevelTree.inOrder();
	int affectedIndex = 0, notIndex = 0;
	for (int i = 0; i < numOfPokemons; i++) {
		if (currentArray[i].getID() % stoneCode == 0) {
			Pokemon current(currentArray[i].getID(),
					currentArray[i].getTrainerId(),
					currentArray[i].getLevel() * stoneFactor);
			affected[affectedIndex] = current;
			affectedIndex++;
		} else {
			notAffected[notIndex] = currentArray[i];
			notIndex++;
		}
	}
	Pokemon* merged = mergeLevelMainArrays(affected, notAffected);
	mainLevelTree.clear();
	mainLevelTree.buildEmpty(numOfPokemons);
	int mergedIndex = 0;
	mainLevelTree.inOrderInsert(merged, &mergedIndex);


	updateMax();

	Pokemon* iDArray = mainIdTree.inOrder();
	for (int i = 0; i < numOfPokemons; i++) {
		if (iDArray[i].getID() % stoneCode == 0) {
			int newLevel = iDArray[i].getLevel() * stoneFactor;
			iDArray[i].setLevel(newLevel);
		}
	}
	int iDIndex = 0;
	mainIdTree.inOrderInsert(iDArray, &iDIndex);

	delete[] iDArray;
	delete[] notAffected;
	delete[] affected;
	delete[] currentArray;
	delete[] merged;

	Iterator<Trainer> trainerIt = trainers.begin();
	while (trainerIt != trainers.end()) {
		(*trainerIt).updateLevels(stoneCode, stoneFactor);
		++trainerIt;
	}
}
unsigned int UniqueIDManager::newUniqueID(unsigned int requestedId)
{
    if(!ids.contains(requestedId)){
        ids.insert(requestedId, nullptr);
        updateMax(requestedId);
        return requestedId;
    }
    else
        throw IDCollisionException();
}
Example #3
0
void Trainer::updateLevels(int stoneCode, int stoneFactor)
{
	int numOfPokemons = idTree.getSize();
	if (numOfPokemons < 1)
	{
		return;
	}
	Pokemon* notAffected = new Pokemon[numOfPokemons];
	Pokemon* affected = new Pokemon[numOfPokemons];
	Pokemon* currentArray = levelTree.inOrder();
	int affectedIndex = 0, notIndex = 0;
	for (int i = 0; i < numOfPokemons; i++) {
		if (currentArray[i].getID() % stoneCode == 0) {
			Pokemon current(currentArray[i].getID(),
				currentArray[i].getTrainerId(),
				currentArray[i].getLevel() * stoneFactor);
			affected[affectedIndex] = current;
			affectedIndex++;
		}
		else {
			notAffected[notIndex] = currentArray[i];
			notIndex++;
		}
	}
	Pokemon* merged = mergeLevelArrays(affected, notAffected);

	levelTree.clear();
	levelTree.buildEmpty(numOfPokemons);
	int mergedIndex = 0;
	levelTree.inOrderInsert(merged, &mergedIndex);


	updateMax();

	Pokemon* iDArray = idTree.inOrder();
	for (int i = 0; i < numOfPokemons; i++) {
		if (iDArray[i].getID() % stoneCode == 0) {
			int newLevel = iDArray[i].getLevel() * stoneFactor;
			iDArray[i].setLevel(newLevel);
		}
	}
	int iDIndex = 0;
	idTree.inOrderInsert(iDArray, &iDIndex);

	delete[] iDArray;
	delete[] notAffected;
	delete[] affected;
	delete[] currentArray;
	delete[] merged;

	}
Example #4
0
/**
 * Register data to the array, only launched if the line is valid.
 * @brief File::registerData
 * @param words_begin
 * @param words_end
 * @param i
 */
void File::registerData(std::sregex_iterator words_begin, std::sregex_iterator words_end, int i, bool skip, bool computeCenterTp){
    int j=0;
    if (!skip) {
        data_[i] = new double[dimension_];
        for (std::sregex_iterator it = words_begin; it != words_end; ++it) {
            std::smatch match = *it;
            std::string match_str = match.str();
            data_[i][j] = atof(match_str.c_str());
            j++;
        }
    }
    if (computeCenterTp) {
        updateMax(data_[i][age], i); // update maxTp_ if age is smaller.
    }
}
Example #5
0
MidiSliderBase::MidiSliderBase(MidiControllableBase &mcAble, Qt::Orientation orientation)
  : MidiGUIcomponent(mcAble)
  , slider(orientation)
{
  QVBoxLayout *sliderBox = new QVBoxLayout(this);
  sliderBox->setSpacing(0);
  sliderBox->setMargin(0);

  sliderBox->addWidget(&nameLabel, 0, Qt::AlignHCenter);
  QHBoxLayout *sliderLabels = new QHBoxLayout();
  sliderBox->addLayout(sliderLabels);
  sliderLabels->addWidget(&minLabel, 0);
  sliderLabels->addWidget(&valueLabel, 0, Qt::AlignHCenter);
  sliderLabels->addWidget(&maxLabel, 0, Qt::AlignRight);

  updateMin();
  updateMax();
  slider.setPageStep(mcAble.sliderStep());
  mcAbleChanged();
  QObject::connect(&slider, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
  sliderBox->addWidget(&slider);

  nameLabel.setBuddy(&slider);
}
Example #6
0
void caCamera::setup()
{
    deleteWidgets();
    initWidgets();
    // labels and texts for horizontal layout containing information of the image
    // image inside a scrollarea
    // zoom utilities

    // labels
    if(!thisSimpleView) {
        labelMaxText = new caLabel(this);
        labelMaxText->setText(" Max: ");
        labelMinText = new caLabel(this);
        labelMinText->setText(" Min: ");
        checkAutoText = new caLabel(this);
        checkAutoText->setText(" Auto: ");
        intensityText = new caLabel(this);
        intensityText->setText(" x/y/z: ");

        nbUpdatesText = new caLabel(this);

        // texts
        labelMax = new caLineEdit(this);
        labelMin = new caLineEdit(this);

        labelMax->newFocusPolicy(Qt::ClickFocus);
        labelMin->newFocusPolicy(Qt::ClickFocus);

        intensity = new caLabel(this);

        intensity->setAlignment(Qt::AlignVCenter | Qt::AlignLeft );
        labelMaxText->setScaleMode(caLabel::None);
        labelMinText->setScaleMode(caLabel::None);
        checkAutoText->setScaleMode(caLabel::None);
        intensity->setScaleMode(caLabel::None);
        intensityText->setScaleMode(caLabel::None);
        nbUpdatesText->setScaleMode(caLabel::None);
        QFont font = labelMaxText->font();
        font.setPointSize(10);
        labelMaxText->setFont(font);
        labelMinText->setFont(font);
        checkAutoText->setFont(font);
        intensity->setFont(font);
        intensityText->setFont(font);
        nbUpdatesText->setFont(font);
        labelMaxText->setBackground(QColor(0,0,0,0));
        labelMinText->setBackground(QColor(0,0,0,0));
        checkAutoText->setBackground(QColor(0,0,0,0));
        intensity->setBackground(QColor(0,0,0,0));
        intensityText->setBackground(QColor(0,0,0,0));
        nbUpdatesText->setBackground(QColor(0,0,0,0));

        // checkbox
        autoW = new QCheckBox(this);
        autoW->setChecked(true);

        // add everything to layout
        valuesLayout = new QHBoxLayout();
        valuesLayout->setMargin(0);
        valuesLayout->setSpacing(2);
        valuesLayout->addWidget(labelMinText, Qt::AlignLeft);
        valuesLayout->addWidget(labelMin, Qt::AlignLeft);
        valuesLayout->addWidget(labelMaxText, Qt::AlignLeft);
        valuesLayout->addWidget(labelMax, Qt::AlignLeft);
        valuesLayout->addWidget(checkAutoText, Qt::AlignLeft);
        valuesLayout->addWidget(autoW,    Qt::AlignLeft);
        valuesLayout->addWidget(intensityText, Qt::AlignLeft);
        valuesLayout->addWidget(intensity, Qt::AlignLeft);
        valuesLayout->addWidget(nbUpdatesText, Qt::AlignLeft);
        valuesLayout->addStretch(2);

        valuesWidget = new QWidget;
        valuesWidget->setLayout(valuesLayout);
        valuesWidget->show();

        // image inside a scrollarea
        imageW   = new ImageWidget();
        scrollArea = new QScrollArea;
        scrollArea->setBackgroundRole(QPalette::Dark);
        scrollArea->setWidget(imageW);
        scrollArea->setWidgetResizable(true);

        // add some zoom utilities to our widget
        int iconsize = style()->pixelMetric(QStyle::PM_ToolBarIconSize);
        QSize iconSize(iconsize, iconsize);

        zoomInIcon = new QToolButton;
        zoomInIcon->setIcon(QPixmap(":pixmaps/zoomin.png"));
        zoomInIcon->setIconSize(iconSize);

        zoomOutIcon = new QToolButton;
        zoomOutIcon->setIcon(QPixmap(":pixmaps/zoomout.png"));
        zoomOutIcon->setIconSize(iconSize);

        zoomSlider = new QSlider;
        zoomSlider->setMinimum(0);
        zoomSlider->setMaximum(120); // do not exceed 6*
        zoomSlider->setValue(52);
        zoomSlider->setTickPosition(QSlider::NoTicks);

        zoomValue = new QLabel("");
        zoomValue->setFixedWidth(60);

        colormapWidget = new QwtScaleWidget();
        colormapWidget->setColorBarEnabled(true);
        colormapWidget->setHidden(true);
#if QWT_VERSION >= 0x060100
        QwtScaleDiv *div = new QwtScaleDiv(0.0, 1.0);
        colormapWidget->setScaleDiv(*div);
#endif

        // add everything to layout
        zoomSliderLayout = new QGridLayout();
        zoomSliderLayout->setSpacing(0);
        zoomSliderLayout->addWidget(zoomInIcon, 0, 1);
        zoomSliderLayout->addWidget(zoomSlider, 1, 1);
        zoomSliderLayout->addWidget(zoomOutIcon, 2, 1);
        zoomSliderLayout->addWidget(zoomValue, 3, 1);
        zoomSliderLayout->addWidget(colormapWidget,0,0,4,1);

        zoomWidget = new QWidget;
        zoomWidget->setLayout(zoomSliderLayout);

        // connect buttons and slider
        connect(zoomInIcon, SIGNAL(clicked()), this, SLOT(zoomIn()));
        connect(zoomOutIcon, SIGNAL(clicked()), this, SLOT(zoomOut()));
        connect(zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(zoomNow()));

        // add everything to main layout
        mainLayout->addWidget(valuesWidget, 0, 0);
        mainLayout->addWidget(scrollArea, 1, 0);
        mainLayout->addWidget(zoomWidget, 1, 2);

        for(int i=0; i<4; i++) readvaluesPresent[i] = false;

        updateMin(0);
        updateMax(0);
    } else {
Example #7
0
void Mesh::buildGeometry()
{
	glBindVertexArray(mCubeVAO);
	glm::vec3 cubeVertices[8] = {glm::vec3(-1.0, -1.0, 1.0), glm::vec3(1.0, -1.0, 1.0),
								glm::vec3(1.0, 1.0, 1.0), glm::vec3(-1.0, 1.0, 1.0),
								glm::vec3(-1.0, -1.0, -1.0), glm::vec3(1.0, -1.0, -1.0),
								glm::vec3(1.0, 1.0, -1.0), glm::vec3(-1.0, 1.0, -1.0),};
	unsigned short cubeIndex[36] = {
		0, 1, 2, 0, 2, 3,
		1, 5, 6, 1, 6, 2,
		5, 4, 7, 5, 7, 6,
		4, 0, 3, 4, 3, 7,
		3, 2, 6, 3, 6, 7,
		4, 5, 1, 4, 1, 0
	};
	
	glBindBuffer(GL_ARRAY_BUFFER, mSkeletonBuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec3)*8, glm::value_ptr(cubeVertices[0]), GL_STATIC_DRAW);
	
	glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
	glEnableVertexAttribArray(0);

	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mSkeletonIndexBuffer);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short) * 36, &cubeIndex[0], GL_STATIC_DRAW);

	glBindVertexArray(mVAO);	
	VertexInfo* local_array = new VertexInfo[vertices.size()];
	for(int i = 0; i < vertices.size(); i++)
	{
		local_array[i].pos = vertices[i].position;
		local_array[i].normal = vertices[i].normal;
		local_array[i].texcoord = glm::vec2(vertices[i].texcoord.x, 1.0-vertices[i].texcoord.y);
		local_array[i].weights = glm::vec3(vertices[i].weight[0], vertices[i].weight[1], vertices[i].weight[2]);

		updateMin(local_array[i].pos);
		updateMax(local_array[i].pos);
	}
	glm::vec3 center = -(mMinPos + mMaxPos)/2.0f;
	
	/*
	for(int i = 0; i < vertices.size(); i++)
	{
		local_array[i].pos += center;
	}
	*/
	
	mViewPos = -(mMinPos + mMaxPos)/2.0f;
	mViewPos.z = -glm::max<float>((mMaxPos.y - mMinPos.y), ((mMaxPos.z-mMinPos.z)/2.0))*0.5;

	glm::vec3 VertexInfo::* ptr = &VertexInfo::normal;
	int offset = reinterpret_cast<int>(*(void**)(&ptr));
	std::cout << offset << std::endl;
	std::cout << sizeof(glm::vec3) + sizeof(glm::vec3) + sizeof(glm::vec2);
	
	int pervertex_size = sizeof(VertexInfo);

	glBindBuffer(GL_ARRAY_BUFFER, mBuffer);
	glBufferData(GL_ARRAY_BUFFER, vertices.size() * pervertex_size, glm::value_ptr(local_array[0].pos), GL_STATIC_DRAW);
	
	delete [] local_array;
	
	glVertexAttribPointer(0, 3, GL_FLOAT, false, pervertex_size, 0);
	glEnableVertexAttribArray(0);
	
	glVertexAttribPointer(1, 3, GL_FLOAT, false, pervertex_size, (void*)(offsetof(struct VertexInfo,normal)));

	glVertexAttribPointer(1, 3, GL_FLOAT, false, pervertex_size, (void*)(sizeof(glm::vec3)));
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(2, 2, GL_FLOAT, false, pervertex_size, (void*)(offsetof(struct VertexInfo, texcoord)));
	glEnableVertexAttribArray(2);
	glVertexAttribPointer(3, 3, GL_FLOAT, false, pervertex_size, (void*)(offsetof(struct VertexInfo, weights)));
	glEnableVertexAttribArray(3);
	
	
	glm::ivec3* id_array = new glm::ivec3[vertices.size()];
	for(int i = 0; i < vertices.size(); i++)
	{
		id_array[i] = glm::ivec3(vertices[i].boneindex[0], vertices[i].boneindex[1], vertices[i].boneindex[2]);
	}

	glGenBuffers(1, &mBoneBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, mBoneBuffer);
	glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(int) * 3, glm::value_ptr(id_array[0]), GL_STATIC_DRAW);
	glVertexAttribIPointer(4, 3, GL_INT, 0, 0);
	glEnableVertexAttribArray(4);
	delete [] id_array;

	unsigned int total_tri_number = 0;
	unsigned int start = 0;
	for (int i = 0; i < lod_meshes.size(); i++)
	{
		lod_meshes[i].start = start;
		start += lod_meshes[i].triangles.size()*3;
		total_tri_number += lod_meshes[i].triangles.size();
	}

	unsigned int* indexdata = new unsigned int[total_tri_number*3];
	unsigned int index = 0;
	for (int i = 0; i < lod_meshes.size(); i++)
	{	
		for(int j = 0; j < lod_meshes[i].triangles.size(); j++)
		{
			indexdata[index++] = lod_meshes[i].triangles[j].index[0];
			indexdata[index++] = lod_meshes[i].triangles[j].index[1];
			indexdata[index++] = lod_meshes[i].triangles[j].index[2];
		}
	}

	
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * 3 * total_tri_number, &indexdata[0], GL_STATIC_DRAW);
	delete [] indexdata;

	SubEntityInfo sei;
	for(int i = 0; i < lod_meshes.size(); i++)
	{
		for(int j = 0; j < lod_meshes[i].triangles.size(); j++)
		{
			if(j == 0)
			{
				sei.material = lod_meshes[i].triangles[j].material;
				sei.start = 0;
			}
			else
			{
				if(sei.material != lod_meshes[i].triangles[j].material)
				{
					sei.count = j*3 - sei.start;
					lod_meshes[i].m_subEntity.push_back(sei);
					sei.material = lod_meshes[i].triangles[j].material;
					sei.start = j*3;
				}
			}
		}

		sei.count = lod_meshes[i].triangles.size()*3 - sei.start;
		lod_meshes[i].m_subEntity.push_back(sei);
	}
	
}
Example #8
0
void BoundingRectangle::update(const Vector2F & p)
{
	updateMin(p);
	updateMax(p);
}
Example #9
0
void BoundingBox::update(const Vector3F & p)
{
	updateMin(p);
	updateMax(p);
}
Example #10
0
	bool updateRange(const Eval& l, const Eval& u)
	{	return updateMin(l) and updateMax(u);	}
Example #11
0
void Box::merge(const Box& box2)
{
    updateMin(box2.min);
    updateMax(box2.max);
}
Example #12
0
inline void Box::update(const Vector3f& p)
{
    updateMin(p);
    updateMax(p);
}
Example #13
0
TEST(UpdateMaxTest, LeavesOldWhenSmaller) {
	int a = 5;
	updateMax(a, 3);
	EXPECT_EQ(a, 5);
}
Example #14
0
TEST(UpdateMaxTest, UpdatesWhenGreater) {
	int a = 7;
	updateMax(a, 10);
	EXPECT_EQ(a, 10);
}