예제 #1
0
void getLayers(std::vector<LinkedList*>& lists, Node* thisNode, int layer)
{
    if(thisNode == nullptr)
    {
        return;
    }
    else
    {
        LinkedList* listItem = new LinkedList();
        if(lists.size() == layer)
        {
            listItem->thisNode = thisNode;
            std::cout << "Layer: " << layer << " Item: " << *listItem->thisNode->getValue() << " PUSH" <<std::endl;

            lists.push_back(listItem);
        }
        else
        {
            listItem->thisNode = thisNode;
            std::cout << "Layer: " << layer << " Item: " << *listItem->thisNode->getValue() << std::endl;

            listItem->next = lists[layer];
            lists[layer] = listItem;
        }
        getLayers(lists, thisNode->getRight(), layer + 1);
        getLayers(lists, thisNode->getLeft(), layer + 1);
    }
}
예제 #2
0
파일: main.c 프로젝트: PeterHuang2015/NNEye
void initNetWork(struct SimpleNet *nn, int inputSize, int layerNum, int *layerSizes)
{
    nn->inputSize = inputSize;
    nn->input = (double *)malloc(sizeof(double)*inputSize);
    nn->layerNum = layerNum;
    nn->layerSizes = layerSizes; // Better use memcopy, need enhancing
    // Get layers prepared
    getLayers(&(nn->hdls), nn->layerNum, nn->layerSizes);
    getLayers(&(nn->dls), nn->layerNum, nn->layerSizes);
    nn->output = (double *)malloc(sizeof(double)*layerSizes[layerNum-1]);

    // Get matrices, no bias introduced
    getParamMats(&(nn->hdms), nn->layerNum, nn->inputSize, nn->layerSizes);
    getParamMats(&(nn->dlms), nn->layerNum, nn->inputSize, nn->layerSizes);
}
예제 #3
0
파일: thing.cpp 프로젝트: Cayan/otclient
void Thing::internalDraw(const Point& dest, float scaleFactor, int xPattern, int yPattern, int zPattern, int animationPhase)
{
    for(int l = 0; l < getLayers(); ++l)
        for(int w = 0; w < getDimensionWidth(); ++w)
            for(int h = 0; h < getDimensionHeight(); ++h)
                internalDraw(dest - Point(w,h)*Otc::TILE_PIXELS*scaleFactor, scaleFactor, w, h, xPattern, yPattern, zPattern, l, animationPhase);
}
예제 #4
0
int Creature::getExactSize(int layer, int xPattern, int yPattern, int zPattern, int animationPhase)
{
    int exactSize = 0;

    animationPhase = m_walkAnimationPhase;

    if(m_direction == Otc::NorthEast || m_direction == Otc::SouthEast)
        xPattern = Otc::East;
    else if(m_direction == Otc::NorthWest || m_direction == Otc::SouthWest)
        xPattern = Otc::West;
    else
        xPattern = m_direction;

    zPattern = 0;
    if(m_outfit.getMount() != 0)
        zPattern = 1;

    for(yPattern = 0; yPattern < getNumPatternY(); yPattern++) {
        if(yPattern > 0 && !(m_outfit.getAddons() & (1 << (yPattern-1))))
            continue;

        for(layer = 0; layer < getLayers(); ++layer)
            exactSize = std::max(exactSize, Thing::getExactSize(layer, xPattern, yPattern, zPattern, animationPhase));
    }

    return exactSize;
}
예제 #5
0
QList<ObjectItem *> ObjectItem::getLayers(ObjectItem *pObj)
{
	QList<ObjectItem *> ret ;
	for ( int i = 0 ; i < pObj->childCount() ; i ++ ) {
		ret << pObj->child(i) ;
		ret << getLayers(pObj->child(i)) ;
	}
	return ret ;
}
예제 #6
0
파일: item.cpp 프로젝트: HeberPcL/otclient
int Item::getExactSize(int layer, int xPattern, int yPattern, int zPattern, int animationPhase)
{
    int exactSize = 0;
    calculatePatterns(xPattern, yPattern, zPattern);
    animationPhase = calculateAnimationPhase(true);
    for(layer = 0; layer < getLayers(); ++layer)
        exactSize = std::max(exactSize, Thing::getExactSize(layer, xPattern, yPattern, zPattern, animationPhase));
    return exactSize;
}
예제 #7
0
int main(){

    std::array<int, TREE_SIZE> valueArray;
    
    for(int i = 0; i< valueArray.size(); i++)
    {
        valueArray[i] = i;
    }

    Node* rootNode = buildTree(valueArray, 0, TREE_SIZE - 1);


    // printTree(rootNode);
    // std::cout << std::endl << std::endl;
    printPathTo(rootNode, &valueArray[7]);
    std::cout << std::endl;

    std::vector<LinkedList*> lists;

    bool unbalance = 0;

    int extra1 = 10;
    int extra2 = 11;

    if(unbalance)
    {
        Node* extraN1 = new Node();
        extraN1->setValue(&extra1);
        Node* extraN2 = new Node();
        extraN2->setValue(&extra2);
        extraN1->setRight(extraN2);
        rootNode->getRight()->getRight()->getRight()->setRight(extraN1);

    }

    getLayers(lists, rootNode, 0);

    for(int i = 0; i < lists.size(); i++)
    {
        printLL(lists.at(i));
        std::cout << std::endl;
    }

    std::pair<bool, int> balanceResultPair = isBalanced(rootNode);
    bool balanceResult = balanceResultPair.first;

    std::cout << std::endl << "Balanced? " << balanceResult << " Height: " << balanceResultPair.second << std::endl;
}
예제 #8
0
void ObjectItem::flat()
{
	QList<ObjectItem *> layers = getLayers(this) ;
	QList<ObjectItem *>	children ;

	for ( int i = 0 ; i < layers.size() ; i ++ ) {
		ObjectItem *p = new ObjectItem(layers[i]->getName(), layers[i]->parent()) ;
		p->copy(layers[i]) ;
		p->applyFrameDataFromParent() ;
		p->m_pParent = this ;

		children.append(p) ;
	}
	for ( int i = 0 ; i < children.size() ; i ++ ) {
		qDeleteAll(children[i]->m_children) ;
		children[i]->m_children.clear() ;
	}

	qDeleteAll(m_children) ;
	m_children = children ;
}
예제 #9
0
int Creature::getExactSize(int layer, int xPattern, int yPattern, int zPattern, int animationPhase)
{
    int exactSize = 0;

    animationPhase = 0;
    xPattern = Otc::South;

    zPattern = 0;
    if(m_outfit.getMount() != 0)
        zPattern = 1;

    for(yPattern = 0; yPattern < getNumPatternY(); yPattern++) {
        if(yPattern > 0 && !(m_outfit.getAddons() & (1 << (yPattern-1))))
            continue;

        for(layer = 0; layer < getLayers(); ++layer)
            exactSize = std::max<int>(exactSize, Thing::getExactSize(layer, xPattern, yPattern, zPattern, animationPhase));
    }

    return exactSize;
}
예제 #10
0
void Creature::internalDrawOutfit(Point dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction)
{
    // outfit is a real creature
    if(m_outfit.getCategory() == ThingCategoryCreature) {
        int animationPhase = animateWalk ? m_walkAnimationPhase : 0;

        if(isAnimateAlways() && animateIdle) {
            int ticksPerFrame = 1000 / getAnimationPhases();
            animationPhase = (g_clock.millis() % (ticksPerFrame * getAnimationPhases())) / ticksPerFrame;
        }

        // xPattern => creature direction
        int xPattern;
        if(direction == Otc::NorthEast || direction == Otc::SouthEast)
            xPattern = Otc::East;
        else if(direction == Otc::NorthWest || direction == Otc::SouthWest)
            xPattern = Otc::West;
        else
            xPattern = direction;

        int zPattern = 0;
        if(m_outfit.getMount() != 0) {
            auto datType = g_things.rawGetThingType(m_outfit.getMount(), ThingCategoryCreature);
            dest -= datType->getDisplacement() * scaleFactor;
            datType->draw(dest, scaleFactor, 0, xPattern, 0, 0, animationPhase);
            dest += getDisplacement() * scaleFactor;
            zPattern = 1;
        }

        // yPattern => creature addon
        for(int yPattern = 0; yPattern < getNumPatternY(); yPattern++) {

            // continue if we dont have this addon
            if(yPattern > 0 && !(m_outfit.getAddons() & (1 << (yPattern-1))))
                continue;

            auto datType = rawGetThingType();
            datType->draw(dest, scaleFactor, 0, xPattern, yPattern, zPattern, animationPhase);

            if(getLayers() > 1) {
                Color oldColor = g_painter->getColor();
                Painter::CompositionMode oldComposition = g_painter->getCompositionMode();
                g_painter->setCompositionMode(Painter::CompositionMode_Multiply);
                g_painter->setColor(m_outfit.getHeadColor());
                datType->draw(dest, scaleFactor, SpriteMaskYellow, xPattern, yPattern, zPattern, animationPhase);
                g_painter->setColor(m_outfit.getBodyColor());
                datType->draw(dest, scaleFactor, SpriteMaskRed, xPattern, yPattern, zPattern, animationPhase);
                g_painter->setColor(m_outfit.getLegsColor());
                datType->draw(dest, scaleFactor, SpriteMaskGreen, xPattern, yPattern, zPattern, animationPhase);
                g_painter->setColor(m_outfit.getFeetColor());
                datType->draw(dest, scaleFactor, SpriteMaskBlue, xPattern, yPattern, zPattern, animationPhase);
                g_painter->setColor(oldColor);
                g_painter->setCompositionMode(oldComposition);
            }
        }
    // outfit is a creature imitating an item or the invisible effect
    } else  {
        ThingType *type = g_things.rawGetThingType(m_outfit.getAuxId(), m_outfit.getCategory());

        int animationPhase = 0;
        int animationPhases = type->getAnimationPhases();
        int animateTicks = Otc::ITEM_TICKS_PER_FRAME;

        // when creature is an effect we cant render the first and last animation phase,
        // instead we should loop in the phases between
        if(m_outfit.getCategory() == ThingCategoryEffect) {
            animationPhases = std::max(1, animationPhases-2);
            animateTicks = Otc::INVISIBLE_TICKS_PER_FRAME;
        }

        if(animationPhases > 1) {
            if(animateIdle)
                animationPhase = (g_clock.millis() % (animateTicks * animationPhases)) / animateTicks;
            else
                animationPhase = animationPhases-1;
        }

        if(m_outfit.getCategory() == ThingCategoryEffect)
            animationPhase = std::min(animationPhase+1, animationPhases);

        type->draw(dest - (getDisplacement() * scaleFactor), scaleFactor, 0, 0, 0, 0, animationPhase);
    }
}